From b3d53a7cd8ee4f46ef0efa83738fc3be8e6fb0d5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 10 Nov 2022 21:57:55 +1100 Subject: [PATCH] Line item tax amounts --- app/DataMapper/InvoiceItem.php | 4 ++-- app/Helpers/Invoice/InvoiceItemSum.php | 4 ++-- .../Invoice/InvoiceItemSumInclusive.php | 4 ++-- app/Jobs/Bank/MatchBankTransactions.php | 11 +++++++---- app/Models/BankTransaction.php | 19 +++++++++++++++++++ .../BankTransactionRepository.php | 7 +++++++ app/Utils/HtmlEngine.php | 2 +- app/Utils/Traits/MakesInvoiceValues.php | 8 ++++---- app/Utils/VendorHtmlEngine.php | 2 +- 9 files changed, 45 insertions(+), 16 deletions(-) diff --git a/app/DataMapper/InvoiceItem.php b/app/DataMapper/InvoiceItem.php index 7f80d86eb9b3..7b668f309072 100644 --- a/app/DataMapper/InvoiceItem.php +++ b/app/DataMapper/InvoiceItem.php @@ -45,7 +45,7 @@ class InvoiceItem public $gross_line_total = 0; - public $gross_tax_total = 0; + public $tax_amount = 0; public $date = ''; @@ -77,7 +77,7 @@ class InvoiceItem 'sort_id' => 'string', 'line_total' => 'float', 'gross_line_total' => 'float', - 'gross_tax_total' => 'float', + 'tax_amount' => 'float', 'date' => 'string', 'custom_value1' => 'string', 'custom_value2' => 'string', diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index d77f9a30c895..47ce395e4191 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -30,7 +30,7 @@ class InvoiceItemSum private $gross_line_total; - private $gross_tax_total; + private $tax_amount; private $currency; @@ -158,7 +158,7 @@ class InvoiceItemSum $this->item->gross_line_total = $this->getLineTotal() + $item_tax; - $this->item->gross_tax_total = $item_tax; + $this->item->tax_amount = $item_tax; return $this; } diff --git a/app/Helpers/Invoice/InvoiceItemSumInclusive.php b/app/Helpers/Invoice/InvoiceItemSumInclusive.php index 6985c72ef42e..e7332021b379 100644 --- a/app/Helpers/Invoice/InvoiceItemSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceItemSumInclusive.php @@ -40,7 +40,7 @@ class InvoiceItemSumInclusive private $tax_collection; - private $gross_tax_total; + private $tax_amount; public function __construct($invoice) { @@ -146,7 +146,7 @@ class InvoiceItemSumInclusive $this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total); } - $this->item->gross_tax_total = $this->formatValue($item_tax, $this->currency->precision); + $this->item->tax_amount = $this->formatValue($item_tax, $this->currency->precision); $this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision)); diff --git a/app/Jobs/Bank/MatchBankTransactions.php b/app/Jobs/Bank/MatchBankTransactions.php index 84f3c0f8879f..14ec163292ca 100644 --- a/app/Jobs/Bank/MatchBankTransactions.php +++ b/app/Jobs/Bank/MatchBankTransactions.php @@ -92,11 +92,14 @@ class MatchBankTransactions implements ShouldQueue $this->company = Company::find($this->company_id); - $yodlee = new Yodlee($this->company->account->bank_integration_account_id); + if($this->company->account->bank_integration_account_id) + $yodlee = new Yodlee($this->company->account->bank_integration_account_id); + else + $yodlee = false; $bank_categories = Cache::get('bank_categories'); - if(!$bank_categories){ + if(!$bank_categories && $yodlee){ $_categories = $yodlee->getTransactionCategories(); $this->categories = collect($_categories->transactionCategory); Cache::forever('bank_categories', $this->categories); @@ -159,7 +162,7 @@ class MatchBankTransactions implements ShouldQueue $_invoices = Invoice::withTrashed()->find($this->getInvoices($input['invoice_ids'])); - $amount = $this->bt->amount; + $amount = $this->bt->amount; if($_invoices && $this->checkPayable($_invoices)){ @@ -220,7 +223,7 @@ class MatchBankTransactions implements ShouldQueue $this->applied_amount += $this->invoice->balance; $this->available_balance = $this->available_balance - $this->invoice->balance; } - elseif(floatval($this->invoice->balance) > floatval($this->available_balance) && $this->available_balance > 0) + elseif(floatval($this->invoice->balance) >= floatval($this->available_balance) && $this->available_balance > 0) { $_amount = $this->available_balance; $this->applied_amount += $this->available_balance; diff --git a/app/Models/BankTransaction.php b/app/Models/BankTransaction.php index c603fae0b089..ece2263542df 100644 --- a/app/Models/BankTransaction.php +++ b/app/Models/BankTransaction.php @@ -11,6 +11,7 @@ namespace App\Models; +use App\Models\Invoice; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\SoftDeletes; @@ -95,4 +96,22 @@ class BankTransaction extends BaseModel return $this->belongsTo(Account::class)->withTrashed(); } + + public function matchInvoiceNumber() + { + + if(strlen($this->description) > 1) + { + + $i = Invoice::where('company_id', $this->company_id) + ->whereIn('status_id', [1,2,3]) + ->where('is_deleted', 0) + ->where('number', 'LIKE', '%'.$this->description.'%') + ->first(); + + return $i ?: false; + } + + return false; + } } \ No newline at end of file diff --git a/app/Repositories/BankTransactionRepository.php b/app/Repositories/BankTransactionRepository.php index 0d48177101a0..ac53b4aee437 100644 --- a/app/Repositories/BankTransactionRepository.php +++ b/app/Repositories/BankTransactionRepository.php @@ -31,6 +31,13 @@ class BankTransactionRepository extends BaseRepository $bank_transaction->save(); + if($bank_transaction->base_type == 'CREDIT' && $invoice = $bank_transaction->matchInvoiceNumber()) + { + $bank_transaction->invoice_ids = $invoice->hashed_id; + $bank_transaction->status_id = BankTransaction::STATUS_MATCHED; + $bank_transaction->save(); + } + return $bank_transaction; } diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 443c1b377229..f800b6db41a5 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -485,7 +485,7 @@ class HtmlEngine $data['$product.tax_name3'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$product.line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')]; $data['$product.gross_line_total'] = ['value' => '', 'label' => ctrans('texts.gross_line_total')]; - $data['$product.gross_tax_total'] = ['value' => '', 'label' => ctrans('texts.tax')]; + $data['$product.tax_amount'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$product.description'] = ['value' => '', 'label' => ctrans('texts.description')]; $data['$product.unit_cost'] = ['value' => '', 'label' => ctrans('texts.unit_cost')]; $data['$product.product1'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'product1')]; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index 5bc4b3fccc1a..aa265cb749ee 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -206,7 +206,7 @@ trait MakesInvoiceValues 'tax_name1', 'tax_name2', 'tax_name3', - 'gross_tax_total', + 'tax_amount', ], [ 'tax', @@ -327,10 +327,10 @@ trait MakesInvoiceValues $data[$key][$table_type.'.gross_line_total'] = ''; } - if (property_exists($item, 'gross_tax_total')) { - $data[$key][$table_type.'.gross_tax_total'] = ($item->gross_tax_total == 0) ? '' : Number::formatMoney($item->gross_tax_total, $entity); + if (property_exists($item, 'tax_amount')) { + $data[$key][$table_type.'.tax_amount'] = ($item->tax_amount == 0) ? '' : Number::formatMoney($item->tax_amount, $entity); } else { - $data[$key][$table_type.'.gross_tax_total'] = ''; + $data[$key][$table_type.'.tax_amount'] = ''; } if (isset($item->discount) && $item->discount > 0) { diff --git a/app/Utils/VendorHtmlEngine.php b/app/Utils/VendorHtmlEngine.php index 2b14951499c2..3cdb0c4ac9dd 100644 --- a/app/Utils/VendorHtmlEngine.php +++ b/app/Utils/VendorHtmlEngine.php @@ -355,7 +355,7 @@ class VendorHtmlEngine $data['$product.tax_name3'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$product.line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')]; $data['$product.gross_line_total'] = ['value' => '', 'label' => ctrans('texts.gross_line_total')]; - $data['$product.gross_tax_total'] = ['value' => '', 'label' => ctrans('texts.tax')]; + $data['$product.tax_amount'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$product.description'] = ['value' => '', 'label' => ctrans('texts.description')]; $data['$product.unit_cost'] = ['value' => '', 'label' => ctrans('texts.unit_cost')]; $data['$product.product1'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'product1')];