Merge pull request #2203 from cuneytsenturk/master
Transfer page currency rate enhancement
This commit is contained in:
		| @@ -56,15 +56,7 @@ class Transfers extends Controller | ||||
|  | ||||
|         $currency = Currency::where('code', setting('default.currency'))->first(); | ||||
|  | ||||
|         $file_type_mimes = explode(',', config('filesystems.mimes')); | ||||
|  | ||||
|         $file_types = []; | ||||
|  | ||||
|         foreach ($file_type_mimes as $mime) { | ||||
|             $file_types[] = '.' . $mime; | ||||
|         } | ||||
|  | ||||
|         $file_types = implode(',', $file_types); | ||||
|         $file_types = $this->prepeareFileTypes(); | ||||
|  | ||||
|         return view('banking.transfers.create', compact('accounts', 'payment_methods', 'currency', 'file_types')); | ||||
|     } | ||||
| @@ -148,18 +140,6 @@ class Transfers extends Controller | ||||
|      */ | ||||
|     public function edit(Transfer $transfer) | ||||
|     { | ||||
|         $transfer['from_account_id'] = $transfer->expense_transaction->account_id; | ||||
|         $transfer['from_currency_code'] = $transfer->expense_transaction->currency_code; | ||||
|         $transfer['from_account_rate'] = $transfer->expense_transaction->currency_rate; | ||||
|         $transfer['to_account_id'] = $transfer->income_transaction->account_id; | ||||
|         $transfer['to_currency_code'] = $transfer->income_transaction->currency_code; | ||||
|         $transfer['to_account_rate'] = $transfer->income_transaction->currency_rate; | ||||
|         $transfer['transferred_at'] = Date::parse($transfer->expense_transaction->paid_at)->format('Y-m-d'); | ||||
|         $transfer['description'] = $transfer->expense_transaction->description; | ||||
|         $transfer['amount'] = $transfer->expense_transaction->amount; | ||||
|         $transfer['payment_method'] = $transfer->expense_transaction->payment_method; | ||||
|         $transfer['reference'] = $transfer->expense_transaction->reference; | ||||
|  | ||||
|         $accounts = Account::enabled()->orderBy('name')->pluck('name', 'id'); | ||||
|  | ||||
|         $payment_methods = Modules::getPaymentMethods(); | ||||
| @@ -168,15 +148,7 @@ class Transfers extends Controller | ||||
|  | ||||
|         $currency = Currency::where('code', $account->currency_code)->first(); | ||||
|  | ||||
|         $file_type_mimes = explode(',', config('filesystems.mimes')); | ||||
|  | ||||
|         $file_types = []; | ||||
|  | ||||
|         foreach ($file_type_mimes as $mime) { | ||||
|             $file_types[] = '.' . $mime; | ||||
|         } | ||||
|  | ||||
|         $file_types = implode(',', $file_types); | ||||
|         $file_types = $this->prepeareFileTypes(); | ||||
|  | ||||
|         return view('banking.transfers.edit', compact('transfer', 'accounts', 'payment_methods', 'currency', 'file_types')); | ||||
|     } | ||||
| @@ -287,4 +259,19 @@ class Transfers extends Controller | ||||
|  | ||||
|         return $pdf->download($file_name); | ||||
|     } | ||||
|  | ||||
|     protected function prepeareFileTypes() | ||||
|     { | ||||
|         $file_type_mimes = explode(',', config('filesystems.mimes')); | ||||
|  | ||||
|         $file_types = []; | ||||
|  | ||||
|         foreach ($file_type_mimes as $mime) { | ||||
|             $file_types[] = '.' . $mime; | ||||
|         } | ||||
|  | ||||
|         $file_types = implode(',', $file_types); | ||||
|  | ||||
|         return $file_types; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -16,7 +16,20 @@ class Transfer extends Model | ||||
|  | ||||
|     protected $table = 'transfers'; | ||||
|  | ||||
|     protected $appends = ['attachment']; | ||||
|     protected $appends = [ | ||||
|         'attachment', | ||||
|         'from_account_id', | ||||
|         'from_currency_code', | ||||
|         'from_account_rate', | ||||
|         'to_account_id', | ||||
|         'to_currency_code', | ||||
|         'to_account_rate', | ||||
|         'transferred_at', | ||||
|         'description', | ||||
|         'amount', | ||||
|         'payment_method', | ||||
|         'reference', | ||||
|     ]; | ||||
|  | ||||
|     /** | ||||
|      * Attributes that should be mass-assignable. | ||||
| @@ -101,6 +114,116 @@ class Transfer extends Model | ||||
|         return $value ?: 'banking.transfers.print_' . setting('transfer.template'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return int | ||||
|      */ | ||||
|     public function getFromAccountIdAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->expense_transaction->account_id; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getFromCurrencyCodeAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->expense_transaction->currency_code; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getFromAccountRateAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->expense_transaction->currency_rate; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return int | ||||
|      */ | ||||
|     public function getToAccountIdAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->income_transaction->account_id; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getToCurrencyCodeAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->income_transaction->currency_code; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getToAccountRateAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->income_transaction->currency_rate; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return date | ||||
|      */ | ||||
|     public function getTransferredAtAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->expense_transaction->paid_at; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getDescriptionAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->expense_transaction->description; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return float | ||||
|      */ | ||||
|     public function getAmountAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->expense_transaction->amount; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getPaymentMethodAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->expense_transaction->payment_method; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get the current balance. | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getReferenceAttribute($value = null) | ||||
|     { | ||||
|         return $value ?: $this->expense_transaction->reference; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Create a new factory instance for the model. | ||||
|      * | ||||
|   | ||||
		Reference in New Issue
	
	Block a user