From e27ccfa46c97c3f7e4715e77f950d393046026c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20=C3=87ak=C4=B1rel?= Date: Fri, 25 Dec 2020 18:19:16 +0300 Subject: [PATCH] Add Income/Expense type for document transactions --- app/Abstracts/Http/PaymentController.php | 1 + app/BulkActions/Purchases/Bills.php | 2 +- app/BulkActions/Sales/Invoices.php | 2 +- app/Http/Controllers/Purchases/Bills.php | 2 +- app/Http/Controllers/Sales/Invoices.php | 2 +- app/Jobs/Banking/CreateBankingDocumentTransaction.php | 1 - app/Scopes/Document.php | 2 +- database/factories/Document.php | 1 + .../BC21/Jobs/Banking/CreateDocumentTransaction.php | 11 +++++++++++ .../OfflinePayments/Resources/views/show.blade.php | 1 + modules/PaypalStandard/Http/Controllers/Payment.php | 2 +- 11 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 modules/BC21/Jobs/Banking/CreateDocumentTransaction.php diff --git a/app/Abstracts/Http/PaymentController.php b/app/Abstracts/Http/PaymentController.php index 0b3e6c03d..20296d60e 100644 --- a/app/Abstracts/Http/PaymentController.php +++ b/app/Abstracts/Http/PaymentController.php @@ -164,6 +164,7 @@ abstract class PaymentController extends BaseController $request['amount'] = $invoice->amount; $request['payment_method'] = $this->alias; $request['reference'] = $this->getReference($invoice); + $request['type'] = 'income'; event(new PaymentReceived($invoice, $request)); } diff --git a/app/BulkActions/Purchases/Bills.php b/app/BulkActions/Purchases/Bills.php index e70680ab3..3bef3de6a 100644 --- a/app/BulkActions/Purchases/Bills.php +++ b/app/BulkActions/Purchases/Bills.php @@ -48,7 +48,7 @@ class Bills extends BulkAction $bills = $this->getSelectedRecords($request); foreach ($bills as $bill) { - $this->dispatch(new CreateBankingDocumentTransaction($bill, [])); + $this->dispatch(new CreateBankingDocumentTransaction($bill, ['type' => 'expense'])); } } diff --git a/app/BulkActions/Sales/Invoices.php b/app/BulkActions/Sales/Invoices.php index 6b2662100..2e5b0d652 100644 --- a/app/BulkActions/Sales/Invoices.php +++ b/app/BulkActions/Sales/Invoices.php @@ -48,7 +48,7 @@ class Invoices extends BulkAction $invoices = $this->getSelectedRecords($request); foreach ($invoices as $invoice) { - event(new PaymentReceived($invoice)); + event(new PaymentReceived($invoice, ['type' => 'income'])); } } diff --git a/app/Http/Controllers/Purchases/Bills.php b/app/Http/Controllers/Purchases/Bills.php index 789e8876f..7e112b21b 100644 --- a/app/Http/Controllers/Purchases/Bills.php +++ b/app/Http/Controllers/Purchases/Bills.php @@ -308,7 +308,7 @@ class Bills extends Controller public function markPaid(Document $bill) { try { - $this->dispatch(new CreateBankingDocumentTransaction($bill, [])); + $this->dispatch(new CreateBankingDocumentTransaction($bill, ['type' => 'expense'])); $message = trans('bills.messages.marked_paid'); diff --git a/app/Http/Controllers/Sales/Invoices.php b/app/Http/Controllers/Sales/Invoices.php index 513349680..48b982fa4 100644 --- a/app/Http/Controllers/Sales/Invoices.php +++ b/app/Http/Controllers/Sales/Invoices.php @@ -358,7 +358,7 @@ class Invoices extends Controller public function markPaid(Document $invoice) { try { - event(new \App\Events\Document\PaymentReceived($invoice)); + event(new \App\Events\Document\PaymentReceived($invoice, ['type' => 'income'])); $message = trans('invoices.messages.marked_paid'); diff --git a/app/Jobs/Banking/CreateBankingDocumentTransaction.php b/app/Jobs/Banking/CreateBankingDocumentTransaction.php index cc1b89a47..ee7aa29cd 100644 --- a/app/Jobs/Banking/CreateBankingDocumentTransaction.php +++ b/app/Jobs/Banking/CreateBankingDocumentTransaction.php @@ -73,7 +73,6 @@ class CreateBankingDocumentTransaction extends Job $this->request['company_id'] = $this->model->company_id; $this->request['currency_code'] = isset($this->request['currency_code']) ? $this->request['currency_code'] : $this->model->currency_code; - $this->request['type'] = ($this->model->type === Document::INVOICE_TYPE) ? 'income' : 'expense'; $this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->format('Y-m-d'); $this->request['currency_rate'] = config('money.' . $this->request['currency_code'] . '.rate'); $this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account'); diff --git a/app/Scopes/Document.php b/app/Scopes/Document.php index 140ce306a..59515e5f0 100644 --- a/app/Scopes/Document.php +++ b/app/Scopes/Document.php @@ -23,7 +23,7 @@ class Document implements Scope return; } - $type = request()->get('type') ?: Str::singular(request()->segment(2, '')); + $type = Str::singular(request()->segment(2, '')); // Apply document scope $builder->where($model->getTable() . '.type', '=', $type); diff --git a/database/factories/Document.php b/database/factories/Document.php index 0edc65bd8..05aff0323 100644 --- a/database/factories/Document.php +++ b/database/factories/Document.php @@ -327,6 +327,7 @@ class Document extends AbstractFactory case 'paid': $payment_request = [ 'paid_at' => $updated_document->due_at, + 'type' => 'income', ]; if ($init_status === 'partial') { diff --git a/modules/BC21/Jobs/Banking/CreateDocumentTransaction.php b/modules/BC21/Jobs/Banking/CreateDocumentTransaction.php new file mode 100644 index 000000000..f55660a6a --- /dev/null +++ b/modules/BC21/Jobs/Banking/CreateDocumentTransaction.php @@ -0,0 +1,11 @@ + {!! Form::hidden('payment_method', $setting['code'], ['v-model' => 'form.payment_method']) !!} + {!! Form::hidden('type', 'income', ['v-model' => 'form.type']) !!} {!! Form::close() !!} diff --git a/modules/PaypalStandard/Http/Controllers/Payment.php b/modules/PaypalStandard/Http/Controllers/Payment.php index db28ac9c3..af7c6083d 100644 --- a/modules/PaypalStandard/Http/Controllers/Payment.php +++ b/modules/PaypalStandard/Http/Controllers/Payment.php @@ -118,7 +118,7 @@ class Payment extends PaymentController $total_paid_match = ((double) $request['mc_gross'] == $document->amount); if ($receiver_match && $total_paid_match) { - event(new PaymentReceived($document, $request)); + event(new PaymentReceived($document, $request->merge(['type' => 'income']))); } if (!$receiver_match) {