Update payment display screen in Client Portal.

This commit is contained in:
David Bomba 2023-03-16 16:45:40 +11:00
parent 67d6edfcd0
commit c213e8705d
7 changed files with 64 additions and 22 deletions

View File

@ -174,8 +174,10 @@ class CheckData extends Command
CompanyUser::query()->cursor()->each(function ($cu) {
if (CompanyToken::where('user_id', $cu->user_id)->where('company_id', $cu->company_id)->where('is_system', 1)->doesntExist()) {
$this->logMessage("Creating missing company token for user # {$cu->user->id} for company id # {$cu->company->id}");
(new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle();
$this->logMessage("Creating missing company token for user # {$cu->user_id} for company id # {$cu->company_id}");
if($cu->company && $cu->user)
(new CreateCompanyToken($cu->company, $cu->user, 'System'))->handle();
}
});

View File

@ -46,8 +46,6 @@ class PrePaymentController extends Controller
public function process(StorePrePaymentRequest $request)
{
$invoices = collect();
$invoice = InvoiceFactory::create(auth()->guard('contact')->user()->company_id, auth()->guard('contact')->user()->user_id);
$invoice->due_date = now()->format('Y-m-d');
@ -55,11 +53,11 @@ class PrePaymentController extends Controller
$invoice->client_id = auth()->guard('contact')->user()->client_id;
$line_item = new InvoiceItem();
$line_item->cost = $request->amount;
$line_item->cost = (float)$request->amount;
$line_item->quantity = 1;
$line_item->product_key = ctrans('texts.pre_payment');
$line_item->notes = $request->notes;
$line_item->type_id = 1;
$line_item->type_id = '1';
$items = [];
$items[] = $line_item;
@ -80,25 +78,33 @@ class PrePaymentController extends Controller
->fillDefaults()
->save();
$total = $invoice->balance;
//format totals
$formatted_total = Number::formatMoney($request->amount, auth()->guard('contact')->user()->client);
$formatted_total = Number::formatMoney($invoice->amount, auth()->guard('contact')->user()->client);
$payment_methods = auth()->guard('contact')->user()->client->service()->getPaymentMethods($request->amount);
//if there is only one payment method -> lets return straight to the payment page
$invoices = collect();
$invoices->push($invoice);
$invoices->map(function ($invoice) {
$invoice->balance = Number::formatValue($invoice->balance, $invoice->client->currency());
return $invoice;
});
$data = [
'settings' => auth()->guard('contact')->user()->client->getMergedSettings(),
'invoices' => $invoices,
'formatted_total' => $formatted_total,
'payment_methods' => $payment_methods,
'hashed_ids' => $invoices->pluck('hashed_id'),
'total' => $request->amount,
'total' => $total,
'pre_payment' => true,
];
nlog($data);
return $this->render('invoices.payment', $data);
}

View File

@ -83,6 +83,9 @@ class InvoiceRepository extends BaseRepository
*/
public function restore($invoice) :Invoice
{
if($invoice->is_proforma)
return $invoice;
//if we have just archived, only perform a soft restore
if (! $invoice->is_deleted) {
parent::restore($invoice);

View File

@ -214,7 +214,7 @@ class InstantPayment
$credit_totals = 0;
}
$hash_data = ['invoices' => $payable_invoices->toArray(), 'credits' => $credit_totals, 'amount_with_fee' => max(0, (($invoice_totals + $fee_totals) - $credit_totals))];
$hash_data = ['invoices' => $payable_invoices->toArray(), 'credits' => $credit_totals, 'amount_with_fee' => max(0, (($invoice_totals + $fee_totals) - $credit_totals)), 'pre_payment' => $this->request->pre_payment];
if ($this->request->query('hash')) {
$hash_data['billing_context'] = Cache::get($this->request->query('hash'));

View File

@ -82,10 +82,22 @@ class UpdateInvoicePayment
->save();
if ($invoice->is_proforma) {
if (strlen($invoice->number) > 1 && str_starts_with($invoice->number, "####")) {
$invoice->number = '';
//keep proforma's hidden
if(property_exists($this->payment_hash->data, 'pre_payment') && $this->payment_hash->data->pre_payment == "1"){
$invoice->payments()->each(function ($p) {
$p->pivot->forceDelete();
});
$invoice->is_deleted = true;
$invoice->deleted_at = now();
$invoice->saveQuietly();
return;
}
if (strlen($invoice->number) > 1 && str_starts_with($invoice->number, "####"))
$invoice->number = '';
$invoice->is_proforma = false;

View File

@ -13,6 +13,7 @@
<input type="hidden" name="company_gateway_id" id="company_gateway_id">
<input type="hidden" name="payment_method_id" id="payment_method_id">
<input type="hidden" name="signature">
<input type="hidden" name="pre_payment" value="{{ isset($pre_payment) ? $pre_payment : false }}">
<div class="container mx-auto">
<div class="grid grid-cols-6 gap-4">

View File

@ -14,6 +14,18 @@
</div>
<div>
<dl>
@if(!empty($payment->status_id) && !is_null($payment->status_id))
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.status') }}
</dt>
<div class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{!! \App\Models\Payment::badgeForStatus($payment->status_id) !!}
</div>
</div>
@endif
@if(!empty($payment->clientPaymentDate()) && !is_null($payment->clientPaymentDate()))
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium leading-5 text-gray-500">
@ -72,14 +84,6 @@
@endif
@if(!empty($payment->status_id) && !is_null($payment->status_id))
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.status') }}
</dt>
<div class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{!! \App\Models\Payment::badgeForStatus($payment->status_id) !!}
</div>
</div>
@if($payment->refunded > 0)
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
@ -91,6 +95,18 @@
</div>
</div>
@endif
@if($payment->applied != $payment->amount)
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.remaining') }}
</dt>
<div class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ \App\Utils\Number::formatMoney($payment->amount - $payment->applied, $payment->client) }}
</div>
</div>
@endif
@endif
</dl>
</div>
@ -107,6 +123,7 @@
<div>
<dl>
@foreach($payment->invoices as $invoice)
@if(!$invoice->is_proforma)
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.invoice_number') }}
@ -119,6 +136,7 @@
- {{ \App\Utils\Number::formatMoney($payment->invoices->where('id', $invoice->id)->sum('pivot.amount') - $payment->invoices->where('id', $invoice->id)->sum('pivot.refunded'), $payment->client) }}
</div>
</div>
@endif
@endforeach
</dl>
</div>