mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for Client Portal Download a single invoice
This commit is contained in:
parent
452808116a
commit
f93aab5697
@ -168,7 +168,8 @@ class InvoiceController extends Controller
|
||||
if ($invoices->count() == 1) {
|
||||
$invoice = $invoices->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);;
|
||||
|
||||
}
|
||||
|
@ -214,6 +214,8 @@ class Import implements ShouldQueue
|
||||
// if(Ninja::isHosted() && array_key_exists('ninja_tokens', $data))
|
||||
$this->processNinjaTokens($data['ninja_tokens']);
|
||||
|
||||
$this->fixData();
|
||||
|
||||
$this->setInitialCompanyLedgerBalances();
|
||||
|
||||
// $this->fixClientBalances();
|
||||
@ -245,6 +247,41 @@ class Import implements ShouldQueue
|
||||
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()
|
||||
{
|
||||
Client::cursor()->each(function ($client) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user