Allow invoice PDFs to download via interface

This commit is contained in:
David Bomba 2024-09-06 13:58:39 +10:00
parent 6a5b559983
commit 9c8afcd434
4 changed files with 84 additions and 15 deletions

View File

@ -128,6 +128,8 @@ class InvoicePay extends Component
public function payableAmount($payable_amount)
{
// $this->setContext('payable_invoices.0.amount', Number::parseFloat($payable_amount)); // $this->context['payable_invoices'][0]['amount'] = Number::parseFloat($payable_amount); //TODO DB: check parseFloat()
$this->setContext('amount', $payable_amount);
$this->under_over_payment = false;
}
@ -272,11 +274,14 @@ class InvoicePay extends Component
'invoice_id' => $i->hashed_id,
'amount' => $i->partial > 0 ? $i->partial : $i->balance,
'formatted_amount' => Number::formatValue($i->partial > 0 ? $i->partial : $i->balance, $i->client->currency()),
'formatted_currency' => Number::formatMoney($i->partial > 0 ? $i->partial : $i->balance, $i->client),
'number' => $i->number,
'date' => $i->translateDate($i->date, $i->client->date_format(), $i->client->locale())
'date' => $i->translateDate($i->date, $i->client->date_format(), $i->client->locale()),
'due_date' => $i->translateDate($i->due_date, $i->client->date_format(), $i->client->locale())
];
})->toArray();
$this->setContext('amount', array_sum(array_column($payable_invoices, 'amount')));
$this->setContext('payable_invoices', $payable_invoices);
}

View File

@ -12,9 +12,10 @@
namespace App\Livewire\Flow2;
use App\Utils\Traits\WithSecureContext;
use Livewire\Attributes\On;
use App\Utils\Number;
use Livewire\Component;
use Livewire\Attributes\On;
use App\Utils\Traits\WithSecureContext;
class InvoiceSummary extends Component
{
@ -22,25 +23,63 @@ class InvoiceSummary extends Component
public $invoices;
public $amount;
public function mount()
{
//@TODO for a single invoice - show all details, for multi-invoices, only show the summaries
$this->invoices = $this->getContext()['invoices']; // $this->context['invitation']->invoice;
// $this->invoices = $this->getContext()['invoices']; // $this->context['invitation']->invoice;
$contact = $this->getContext()['contact'];
$this->invoices = $this->getContext()['payable_invoices'];
$this->amount = Number::formatMoney($this->getContext()['amount'], $contact->client);
}
#[On(self::CONTEXT_UPDATE)]
public function onContextUpdate(): void
{
// refactor logic for updating the price for eg if it changes with under/over pay
$contact = $this->getContext()['contact'];
$this->invoices = $this->getContext()['payable_invoices'];
$this->amount = Number::formatMoney($this->getContext()['amount'], $contact->client);
// $this->invoices = $this->getContext()['invoices'];
}
public function downloadDocument($invoice_hashed_id)
{
nlog("here");
$contact = $this->getContext()['contact'];
$_invoices = $this->getContext()['invoices'];
$i = $_invoices->first(function ($i) use($invoice_hashed_id){
return $i->hashed_id == $invoice_hashed_id;
});
$file_name = $i->numberFormatter().'.pdf';
$file = (new \App\Jobs\Entity\CreateRawPdf($i->invitations()->where('client_contact_id', $contact->id)->first()))->handle();
nlog("here");
nlog($file);
$headers = ['Content-Type' => 'application/pdf'];
return response()->streamDownload(function () use ($file) {
echo $file;
}, $file_name, $headers);
$this->invoices = $this->getContext()['invoices'];
}
public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$contact = $this->getContext()['contact'];
return render('flow2.invoices-summary', [
'invoice' => $this->invoices,
'client' => $this->invoices->first()->client,
'client' => $contact->client,
]);
}

View File

@ -47,6 +47,7 @@ class UnderOverPayment extends Component
foreach($payableInvoices as $key => $invoice){
$payableInvoices[$key]['amount'] = Number::parseFloat($invoice['formatted_amount']);
$payableInvoices[$key]['formatted_currency'] = Number::FormatMoney($payableInvoices[$key]['amount'], $this->getContext()['invitation']->contact->client);
}
$input_amount = collect($payableInvoices)->sum('amount');

File diff suppressed because one or more lines are too long