Changeset View
Changeset View
Standalone View
Standalone View
src/app/Documents/Receipt.php
Show First 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | protected function build() | ||||
} else { | } else { | ||||
$customer = $this->customerData(); | $customer = $this->customerData(); | ||||
$country = $this->wallet->owner->getSetting('country'); | $country = $this->wallet->owner->getSetting('country'); | ||||
$items = $this->wallet->payments() | $items = $this->wallet->payments() | ||||
->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'); | $vatRate = \config('app.vat.rate'); | ||||
$vatCountries = explode(',', \config('app.vat.countries')); | $vatCountries = explode(',', \config('app.vat.countries')); | ||||
$vatCountries = array_map('strtoupper', array_map('trim', $vatCountries)); | $vatCountries = array_map('strtoupper', array_map('trim', $vatCountries)); | ||||
if (!$country || !in_array(strtoupper($country), $vatCountries)) { | if (!$country || !in_array(strtoupper($country), $vatCountries)) { | ||||
$vatRate = 0; | $vatRate = 0; | ||||
} | } | ||||
$totalVat = 0; | $totalVat = 0; | ||||
$total = 0; | $total = 0; | ||||
$items = $items->map(function ($item) use (&$total, &$totalVat, $appName, $vatRate) { | $items = $items->map(function ($item) use (&$total, &$totalVat, $appName, $vatRate) { | ||||
$amount = $item->amount; | $amount = $item->amount; | ||||
if ($vatRate > 0) { | if ($vatRate > 0) { | ||||
$amount = round($amount * ((100 - $vatRate) / 100)); | $amount = round($amount * ((100 - $vatRate) / 100)); | ||||
$totalVat += $item->amount - $amount; | $totalVat += $item->amount - $amount; | ||||
} | } | ||||
$total += $amount; | $total += $amount; | ||||
if ($item->type == PaymentProvider::TYPE_REFUND) { | |||||
$description = \trans('documents.receipt-refund'); | |||||
} elseif ($item->type == PaymentProvider::TYPE_CHARGEBACK) { | |||||
$description = \trans('documents.receipt-chargeback'); | |||||
} else { | |||||
$description = \trans('documents.receipt-item-desc', ['site' => $appName]); | |||||
} | |||||
return [ | return [ | ||||
'amount' => $this->wallet->money($amount), | 'amount' => $this->wallet->money($amount), | ||||
'description' => \trans('documents.receipt-item-desc', ['site' => $appName]), | 'description' => $description, | ||||
'date' => $item->updated_at->toDateString(), | 'date' => $item->updated_at->toDateString(), | ||||
]; | ]; | ||||
}); | }); | ||||
// Load the template | // Load the template | ||||
$view = view('documents.receipt') | $view = view('documents.receipt') | ||||
->with([ | ->with([ | ||||
'site' => $appName, | 'site' => $appName, | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |