Fixes for Client Portal Download a single invoice

This commit is contained in:
David Bomba 2021-06-21 12:58:52 +10:00
parent 452808116a
commit f93aab5697
2 changed files with 39 additions and 1 deletions

View File

@ -168,7 +168,8 @@ class InvoiceController extends Controller
if ($invoices->count() == 1) { if ($invoices->count() == 1) {
$invoice = $invoices->first(); $invoice = $invoices->first();
$invitation = $invoice->invitations->first(); $invitation = $invoice->invitations->first();
$file = $invoice->pdf_file_path($invitation); //$file = $invoice->pdf_file_path($invitation);
$file = $invoice->service()->getInvoicePdf(auth()->user());
return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);; return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);;
} }

View File

@ -214,6 +214,8 @@ class Import implements ShouldQueue
// if(Ninja::isHosted() && array_key_exists('ninja_tokens', $data)) // if(Ninja::isHosted() && array_key_exists('ninja_tokens', $data))
$this->processNinjaTokens($data['ninja_tokens']); $this->processNinjaTokens($data['ninja_tokens']);
$this->fixData();
$this->setInitialCompanyLedgerBalances(); $this->setInitialCompanyLedgerBalances();
// $this->fixClientBalances(); // $this->fixClientBalances();
@ -245,6 +247,41 @@ class Import implements ShouldQueue
unlink($this->file_path); unlink($this->file_path);
} }
private function fixData()
{
$this->company->clients()->withTrashed()->where('is_deleted', 0)->cursor()->each(function ($client) {
$total_invoice_payments = 0;
$credit_total_applied = 0;
foreach ($client->invoices()->where('is_deleted', false)->where('status_id', '>', 1)->get() as $invoice) {
$total_amount = $invoice->payments()->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->get()->sum('pivot.amount');
$total_refund = $invoice->payments()->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])->get()->sum('pivot.refunded');
$total_invoice_payments += ($total_amount - $total_refund);
}
// 10/02/21
foreach ($client->payments as $payment) {
$credit_total_applied += $payment->paymentables()->where('paymentable_type', App\Models\Credit::class)->get()->sum(\DB::raw('amount'));
}
if ($credit_total_applied < 0) {
$total_invoice_payments += $credit_total_applied;
}
if (round($total_invoice_payments, 2) != round($client->paid_to_date, 2)) {
$client->paid_to_date = $total_invoice_payments;
$client->save();
}
});
}
private function setInitialCompanyLedgerBalances() private function setInitialCompanyLedgerBalances()
{ {
Client::cursor()->each(function ($client) { Client::cursor()->each(function ($client) {