Changeset View
Changeset View
Standalone View
Standalone View
src/app/Documents/Receipt.php
Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | protected function build() | ||||
$start = Carbon::create($this->year, $this->month, 1, 0, 0, 0); | $start = Carbon::create($this->year, $this->month, 1, 0, 0, 0); | ||||
$end = $start->copy()->endOfMonth(); | $end = $start->copy()->endOfMonth(); | ||||
$month = \trans('documents.month' . intval($this->month)); | $month = \trans('documents.month' . intval($this->month)); | ||||
$title = \trans('documents.receipt-title', ['year' => $this->year, 'month' => $month]); | $title = \trans('documents.receipt-title', ['year' => $this->year, 'month' => $month]); | ||||
$company = $this->companyData(); | $company = $this->companyData(); | ||||
if (self::$fakeMode) { | if (self::$fakeMode) { | ||||
$country = 'CH'; | |||||
$customer = [ | $customer = [ | ||||
'id' => $this->wallet->owner->id, | 'id' => $this->wallet->owner->id, | ||||
'wallet_id' => $this->wallet->id, | 'wallet_id' => $this->wallet->id, | ||||
'customer' => 'Freddie Krüger<br>7252 Westminster Lane<br>Forest Hills, NY 11375', | 'customer' => 'Freddie Krüger<br>7252 Westminster Lane<br>Forest Hills, NY 11375', | ||||
mollekopf: Not related, but is this expected in here?. | |||||
Done Inline ActionsFake data is here so we can produce a test output of a receipt, using template:render command machniak: Fake data is here so we can produce a test output of a receipt, using template:render command | |||||
]; | ]; | ||||
$items = collect([ | $items = collect([ | ||||
(object) [ | (object) [ | ||||
'amount' => 1234, | 'amount' => 1234, | ||||
'updated_at' => $start->copy()->next(Carbon::MONDAY), | 'updated_at' => $start->copy()->next(Carbon::MONDAY), | ||||
], | ], | ||||
(object) [ | (object) [ | ||||
'amount' => 10000, | 'amount' => 10000, | ||||
'updated_at' => $start->copy()->next()->next(), | 'updated_at' => $start->copy()->next()->next(), | ||||
], | ], | ||||
(object) [ | (object) [ | ||||
'amount' => 1234, | 'amount' => 1234, | ||||
'updated_at' => $start->copy()->next()->next()->next(Carbon::MONDAY), | 'updated_at' => $start->copy()->next()->next()->next(Carbon::MONDAY), | ||||
], | ], | ||||
(object) [ | (object) [ | ||||
'amount' => 99, | 'amount' => 99, | ||||
'updated_at' => $start->copy()->next()->next()->next(), | 'updated_at' => $start->copy()->next()->next()->next(), | ||||
], | ], | ||||
]); | ]); | ||||
$items = $items->map(function ($payment) { | |||||
$payment->vatRate = new \App\VatRate(); | |||||
Not Done Inline ActionsShould the rate be hardcoded here? mollekopf: Should the rate be hardcoded here? | |||||
$payment->vatRate->rate = 7.7; | |||||
Not Done Inline ActionsUse ceil here as well. I would create a a function in Payment to calculate the amount (and potentially not store base_amount at all, unless necessary). mollekopf: Use ceil here as well. I would create a a function in Payment to calculate the amount (and… | |||||
$payment->credit_amount = $payment->amount + round($payment->amount * $payment->vatRate->rate / 100); | |||||
return $payment; | |||||
}); | |||||
} else { | } else { | ||||
$customer = $this->customerData(); | $customer = $this->customerData(); | ||||
$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'); | |||||
$vatCountries = explode(',', \config('app.vat.countries')); | |||||
$vatCountries = array_map('strtoupper', array_map('trim', $vatCountries)); | |||||
if (!$country || !in_array(strtoupper($country), $vatCountries)) { | |||||
$vatRate = 0; | $vatRate = 0; | ||||
} | |||||
$totalVat = 0; | $totalVat = 0; | ||||
$total = 0; | $total = 0; // excluding VAT | ||||
$items = $items->map(function ($item) use (&$total, &$totalVat, $appName, $vatRate) { | |||||
$items = $items->map(function ($item) use (&$total, &$totalVat, &$vatRate, $appName) { | |||||
$amount = $item->amount; | $amount = $item->amount; | ||||
if ($vatRate > 0) { | if ($item->vatRate && $item->vatRate->rate > 0) { | ||||
$amount = round($amount * ((100 - $vatRate) / 100)); | $vat = round($item->credit_amount * $item->vatRate->rate / 100); | ||||
Not Done Inline Actionsuse ceil mollekopf: use ceil | |||||
$totalVat += $item->amount - $amount; | $amount -= $vat; | ||||
$totalVat += $vat; | |||||
$vatRate = $item->vatRate->rate; // TODO: Multiple rates | |||||
} | } | ||||
$total += $amount; | $total += $amount; | ||||
$type = $item->type ?? null; | $type = $item->type ?? null; | ||||
if ($type == PaymentProvider::TYPE_REFUND) { | if ($type == PaymentProvider::TYPE_REFUND) { | ||||
$description = \trans('documents.receipt-refund'); | $description = \trans('documents.receipt-refund'); | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |
Not related, but is this expected in here?.