From 575a3b3190b47fa3e65870a7d540341717ba0067 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 14 Feb 2021 20:25:19 +1100 Subject: [PATCH] Improve quote document imports --- app/Console/Commands/CheckData.php | 4 ++-- app/Jobs/Util/Import.php | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 8b4ab13175..eae52b925e 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -389,8 +389,8 @@ class CheckData extends Command $invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); $credit_balance = $client->credits->where('is_deleted', false)->sum('balance'); - if($client->balance != $invoice_balance) - $invoice_balance -= $credit_balance;//doesn't make sense to remove the credit amount + // if($client->balance != $invoice_balance) + // $invoice_balance -= $credit_balance;//doesn't make sense to remove the credit amount $ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first(); diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index a5b6d61954..d71080a4c1 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -1029,10 +1029,33 @@ class Import implements ShouldQueue } if (array_key_exists('invoice_id', $resource) && $resource['invoice_id'] && array_key_exists('invoices', $this->ids)) { - $invoice_id = $this->transformId('invoices', $resource['invoice_id']); - $entity = Invoice::where('id', $invoice_id)->withTrashed()->first(); + + $try_quote = false; + $exception = null; + try{ + $invoice_id = $this->transformId('invoices', $resource['invoice_id']); + $entity = Invoice::where('id', $invoice_id)->withTrashed()->first(); + } + catch(\Exception $e){ + + $try_quote = true; + } + + if($try_quote) { + + $quote_id = $this->transformId('quotes', $resource['invoice_id']); + $entity = Quote::where('id', $quote_id)->withTrashed()->first(); + $exception = $e; + + } + + if($exception) + throw new Exception("Resource invoice/quote document not available."); + + } + if (array_key_exists('expense_id', $resource) && $resource['expense_id'] && array_key_exists('expenses', $this->ids)) { $expense_id = $this->transformId('expenses', $resource['expense_id']); $entity = Expense::where('id', $expense_id)->withTrashed()->first();