diff --git a/app/Livewire/Flow2/InvoicePay.php b/app/Livewire/Flow2/InvoicePay.php index 575317c750a9..811b16838567 100644 --- a/app/Livewire/Flow2/InvoicePay.php +++ b/app/Livewire/Flow2/InvoicePay.php @@ -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); } diff --git a/app/Livewire/Flow2/InvoiceSummary.php b/app/Livewire/Flow2/InvoiceSummary.php index 51681737b240..af21a26894a6 100644 --- a/app/Livewire/Flow2/InvoiceSummary.php +++ b/app/Livewire/Flow2/InvoiceSummary.php @@ -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, ]); } diff --git a/app/Livewire/Flow2/UnderOverPayment.php b/app/Livewire/Flow2/UnderOverPayment.php index 31ec54cb6932..52c257deb315 100644 --- a/app/Livewire/Flow2/UnderOverPayment.php +++ b/app/Livewire/Flow2/UnderOverPayment.php @@ -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'); diff --git a/resources/views/portal/ninja2020/flow2/invoices-summary.blade.php b/resources/views/portal/ninja2020/flow2/invoices-summary.blade.php index 96d3252d0c83..e7dd811c0f78 100644 --- a/resources/views/portal/ninja2020/flow2/invoices-summary.blade.php +++ b/resources/views/portal/ninja2020/flow2/invoices-summary.blade.php @@ -16,30 +16,54 @@