Merge for templates

This commit is contained in:
David Bomba 2023-11-14 09:09:49 +11:00
commit f8cab32e53
3 changed files with 28 additions and 45 deletions

View File

@ -56,7 +56,10 @@ class StoreTaskRequest extends Request
$rules['time_log'] = ['bail',function ($attribute, $values, $fail) { $rules['time_log'] = ['bail',function ($attribute, $values, $fail) {
if(!is_array(json_decode($values, true))) { if(is_string($values))
$values = json_decode($values, true);
if(!is_array($values)) {
$fail('The '.$attribute.' must be a valid array.'); $fail('The '.$attribute.' must be a valid array.');
return; return;
} }

View File

@ -38,9 +38,6 @@ class UpdateTaskRequest extends Request
/** @var \App\Models\User $user */ /** @var \App\Models\User $user */
$user = auth()->user(); $user = auth()->user();
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->can('edit', $this->task); return $user->can('edit', $this->task);
} }
@ -65,7 +62,11 @@ class UpdateTaskRequest extends Request
$rules['time_log'] = ['bail', function ($attribute, $values, $fail) { $rules['time_log'] = ['bail', function ($attribute, $values, $fail) {
if(!is_array(json_decode($values, true))) { if(is_string($values)) {
$values = json_decode($values, true);
}
if(!is_array($values)) {
$fail('The '.$attribute.' must be a valid array.'); $fail('The '.$attribute.' must be a valid array.');
return; return;
} }

View File

@ -18,6 +18,7 @@ use App\Models\Quote;
use App\Utils\Number; use App\Utils\Number;
use Twig\Error\Error; use Twig\Error\Error;
use App\Models\Client; use App\Models\Client;
use App\Models\Company;
use App\Models\Credit; use App\Models\Credit;
use App\Models\Design; use App\Models\Design;
use App\Models\Vendor; use App\Models\Vendor;
@ -40,17 +41,12 @@ use App\Utils\PaymentHtmlEngine;
use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesDates;
use App\Utils\Traits\Pdf\PdfMaker; use App\Utils\Traits\Pdf\PdfMaker;
use App\Utils\VendorHtmlEngine; use App\Utils\VendorHtmlEngine;
use League\Fractal\Manager; use League\CommonMark\CommonMarkConverter;
use League\Fractal\Serializer\ArraySerializer;
use Twig\Environment;
use Twig\Error\Error; use Twig\Error\Error;
use Twig\Error\LoaderError; use Twig\Error\LoaderError;
use Twig\Error\RuntimeError; use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError; use Twig\Error\SyntaxError;
use Twig\Extension\DebugExtension;
use Twig\Extension\StringLoaderExtension;
use Twig\Extra\Intl\IntlExtension; use Twig\Extra\Intl\IntlExtension;
use Twig\Loader\FilesystemLoader;
use Twig\Sandbox\SecurityError; use Twig\Sandbox\SecurityError;
use Twig\TwigFilter; use Twig\TwigFilter;
use Twig\TwigFunction; use Twig\TwigFunction;
@ -78,7 +74,7 @@ class TemplateService
private \DomDocument $document; private \DomDocument $document;
public Environment $twig; public \Twig\Environment $twig;
private string $compiled_html = ''; private string $compiled_html = '';
@ -122,8 +118,7 @@ class TemplateService
$this->twig = new Environment($loader, [ $this->twig = new Environment($loader, [
'debug' => true, 'debug' => true,
]); ]);
$string_extension = new \Twig\Extension\StringLoaderExtension();
$string_extension = new StringLoaderExtension();
$this->twig->addExtension($string_extension); $this->twig->addExtension($string_extension);
$this->twig->addExtension(new IntlExtension()); $this->twig->addExtension(new IntlExtension());
$this->twig->addExtension(new DebugExtension()); $this->twig->addExtension(new DebugExtension());
@ -133,7 +128,7 @@ class TemplateService
}); });
$this->twig->addFunction($function); $this->twig->addFunction($function);
$filter = new TwigFilter('sum', function (array $array, string $column) { $filter = new \Twig\TwigFilter('sum', function (array $array, string $column) {
return array_sum(array_column($array, $column)); return array_sum(array_column($array, $column));
}); });
@ -292,7 +287,7 @@ class TemplateService
>>>>>>> support_for_custom_statement_designs >>>>>>> support_for_custom_statement_designs
} catch(SecurityError $e) { } catch(SecurityError $e) {
nlog("security = " . $e->getMessage()); nlog("security = " . $e->getMessage());
continue; throw ($e);
} }
$template = $template->render($this->data); $template = $template->render($this->data);
@ -630,11 +625,7 @@ class TemplateService
*/ */
public function padLineItems(array $items, Vendor | Client $client_or_vendor): array public function padLineItems(array $items, Vendor | Client $client_or_vendor): array
{ {
<<<<<<< HEAD
return collect($items)->map(function ($item) use ($client) {
=======
return collect($items)->map(function ($item) use ($client_or_vendor) { return collect($items)->map(function ($item) use ($client_or_vendor) {
>>>>>>> support_for_custom_statement_designs
$item->cost_raw = $item->cost ?? 0; $item->cost_raw = $item->cost ?? 0;
$item->discount_raw = $item->discount ?? 0; $item->discount_raw = $item->discount ?? 0;
@ -643,18 +634,6 @@ class TemplateService
$item->tax_amount_raw = $item->tax_amount ?? 0; $item->tax_amount_raw = $item->tax_amount ?? 0;
$item->product_cost_raw = $item->product_cost ?? 0; $item->product_cost_raw = $item->product_cost ?? 0;
<<<<<<< HEAD
$item->cost = Number::formatMoney($item->cost_raw, $client);
if($item->is_amount_discount) {
$item->discount = Number::formatMoney($item->discount_raw, $client);
}
$item->line_total = Number::formatMoney($item->line_total_raw, $client);
$item->gross_line_total = Number::formatMoney($item->gross_line_total_raw, $client);
$item->tax_amount = Number::formatMoney($item->tax_amount_raw, $client);
$item->product_cost = Number::formatMoney($item->product_cost_raw, $client);
=======
$item->cost = Number::formatMoney($item->cost_raw, $client_or_vendor); $item->cost = Number::formatMoney($item->cost_raw, $client_or_vendor);
if($item->is_amount_discount) { if($item->is_amount_discount) {
@ -665,7 +644,6 @@ class TemplateService
$item->gross_line_total = Number::formatMoney($item->gross_line_total_raw, $client_or_vendor); $item->gross_line_total = Number::formatMoney($item->gross_line_total_raw, $client_or_vendor);
$item->tax_amount = Number::formatMoney($item->tax_amount_raw, $client_or_vendor); $item->tax_amount = Number::formatMoney($item->tax_amount_raw, $client_or_vendor);
$item->product_cost = Number::formatMoney($item->product_cost_raw, $client_or_vendor); $item->product_cost = Number::formatMoney($item->product_cost_raw, $client_or_vendor);
>>>>>>> support_for_custom_statement_designs
return $item; return $item;
@ -732,7 +710,7 @@ class TemplateService
'balance_raw' => ($payment->amount - $payment->refunded - $payment->applied), 'balance_raw' => ($payment->amount - $payment->refunded - $payment->applied),
'date' => $this->translateDate($payment->date, $payment->client->date_format(), $payment->client->locale()), 'date' => $this->translateDate($payment->date, $payment->client->date_format(), $payment->client->locale()),
'method' => $payment->translatedType(), 'method' => $payment->translatedType(),
'currency' => $payment->currency->code ?? $payment->company->currency()->code, 'currency' => $payment->currency->code,
'exchange_rate' => $payment->exchange_rate, 'exchange_rate' => $payment->exchange_rate,
'transaction_reference' => $payment->transaction_reference, 'transaction_reference' => $payment->transaction_reference,
'is_manual' => $payment->is_manual, 'is_manual' => $payment->is_manual,
@ -888,7 +866,8 @@ class TemplateService
$credits = collect($credits) $credits = collect($credits)
->map(function ($credit) { ->map(function ($credit) {
<<<<<<< HEAD $this->entity = $credit;
return [ return [
'amount' => Number::formatMoney($credit->amount, $credit->client), 'amount' => Number::formatMoney($credit->amount, $credit->client),
'balance' => Number::formatMoney($credit->balance, $credit->client), 'balance' => Number::formatMoney($credit->balance, $credit->client),