Changeset View
Changeset View
Standalone View
Standalone View
src/app/Documents/Receipt.php
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | protected function build() | ||||
->where('status', PaymentProvider::STATUS_PAID) | ->where('status', PaymentProvider::STATUS_PAID) | ||||
->where('updated_at', '>=', $start) | ->where('updated_at', '>=', $start) | ||||
->where('updated_at', '<', $end) | ->where('updated_at', '<', $end) | ||||
->where('amount', '>', 0) | ->where('amount', '>', 0) | ||||
->orderBy('updated_at') | ->orderBy('updated_at') | ||||
->get(); | ->get(); | ||||
} | } | ||||
$vatRate = \config('app.vat.rate'); | |||||
$vatCountries = explode(',', \config('app.vat.countries')); | |||||
$vatCountries = array_map('strtoupper', array_map('trim', $vatCountries)); | |||||
$country = $this->wallet->owner->getSetting('country'); | |||||
if (!$country || !in_array(strtoupper($country), $vatCountries)) { | |||||
$vatRate = 0; | |||||
} | |||||
$totalVat = 0; | |||||
$total = 0; | $total = 0; | ||||
$items = $items->map(function ($item) use (&$total, $appName) { | $items = $items->map(function ($item) use (&$total, &$totalVat, $appName, $vatRate) { | ||||
$total += $item->amount; | $amount = $item->amount; | ||||
if ($vatRate > 0) { | |||||
$amount = round($amount * ((100 - $vatRate) / 100)); | |||||
$totalVat += $item->amount - $amount; | |||||
} | |||||
$total += $amount; | |||||
return [ | return [ | ||||
'amount' => sprintf('%.2f %s', $item->amount / 100, $this->wallet->currency), | 'amount' => $this->wallet->money($amount), | ||||
'description' => \trans('documents.receipt-item-desc', ['site' => $appName]), | 'description' => \trans('documents.receipt-item-desc', ['site' => $appName]), | ||||
'date' => $item->updated_at->toDateString(), | 'date' => $item->updated_at->toDateString(), | ||||
]; | ]; | ||||
}); | }); | ||||
$total = sprintf('%.2f %s', $total / 100, $this->wallet->currency); | |||||
// Load the template | // Load the template | ||||
$view = view('documents.receipt') | $view = view('documents.receipt') | ||||
->with([ | ->with([ | ||||
'site' => $appName, | 'site' => $appName, | ||||
'title' => $title, | 'title' => $title, | ||||
'company' => $company, | 'company' => $company, | ||||
'customer' => $customer, | 'customer' => $customer, | ||||
'items' => $items, | 'items' => $items, | ||||
'total' => $total, | 'subTotal' => $this->wallet->money($total), | ||||
'total' => $this->wallet->money($total + $totalVat), | |||||
'totalVat' => $this->wallet->money($totalVat), | |||||
'vatRate' => preg_replace('/([.,]00|0|[.,])$/', '', sprintf('%.2f', $vatRate)), | |||||
'vat' => $vatRate > 0, | |||||
]); | ]); | ||||
return $view; | return $view; | ||||
} | } | ||||
/** | /** | ||||
* Prepare customer data for the template | * Prepare customer data for the template | ||||
* | * | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |