Fixes for Twig upgrades

This commit is contained in:
David Bomba 2024-11-11 07:23:17 +11:00
parent adbb225633
commit 07414dee48
6 changed files with 66 additions and 52 deletions

View File

@ -1 +1 @@
5.10.44
5.10.45

View File

@ -73,24 +73,24 @@ class EmailController extends BaseController
$company = $entity_obj->company;
//@todo - need to resolve if this entity is email only
//Only handle Peppol Invoices for now. //double check if the identifier here was
if($entity_obj instanceof Invoice && !isset($entity_obj->sync->email)){
// if($entity_obj instanceof Invoice && $company->isPeppolSender()){
//Only handle Peppol Invoices for now. //double check if the identifier here was found in discovery otherwise email route!
// if($entity_obj instanceof Invoice && !isset($entity_obj->sync->email)){
// // if($entity_obj instanceof Invoice && $company->isPeppolSender()){
$sync = $entity_obj->sync ?? new InvoiceSync();
$sync->email->body = strlen($body) > 3 ? $body : null;
$sync->email->subject = strlen($subject) > 3 ? $subject : null;
$sync->email->template = $request->input('template');
$sync->email->entity = $request->input('entity');
$sync->email->entity_id = $request->input('entity_id');
$sync->email->cc_email = $request->cc_email;
$entity_obj->sync = $sync;
$entity_obj->saveQuietly();
$entity_obj->service()->markSent()->save();
// $sync = $entity_obj->sync ?? new InvoiceSync();
// $sync->email->body = strlen($body) > 3 ? $body : null;
// $sync->email->subject = strlen($subject) > 3 ? $subject : null;
// $sync->email->template = $request->input('template');
// $sync->email->entity = $request->input('entity');
// $sync->email->entity_id = $request->input('entity_id');
// $sync->email->cc_email = $request->cc_email;
// $entity_obj->sync = $sync;
// $entity_obj->saveQuietly();
// $entity_obj->service()->markSent()->save();
\App\Services\EDocument\Jobs\SendEDocument::dispatch(get_class($entity_obj), $entity_obj->id, $company->db);
return;
}
// \App\Services\EDocument\Jobs\SendEDocument::dispatch(get_class($entity_obj), $entity_obj->id, $company->db);
// return;
// }
if ($request->cc_email && (Ninja::isSelfHost() || $user->account->isPremium())) {

View File

@ -577,30 +577,39 @@ class Mutator implements MutatorInterface
return "peppol_invoice_{$this->invoice->id}_{$this->invoice->company->db}@mail.invoicing.co";
}
private function getClientPublicIdentifier(string $code): string
{
if($this->invoice->client->classification == 'individual' && strlen($this->invoice->client->id_number ?? '') > 2)
return $this->invoice->client->id_number;
// elseif($this->invoice->client->classification == 'business')
return $this->invoice->client->vat_number;
}
public function setClientRoutingCode(): self
{
$code = $this->getClientRoutingCode();
if($this->invoice->client->classification == 'government'){
$this->setEmailRouting("peppol_invoice_{$this->invoice->id}_{$this->invoice->company->db}_storeonly@mail.invoicing.co");
}
else if($this->invoice->client->classification == 'individual' || (strlen($this->invoice->client->vat_number ?? '') < 2 && strlen($this->invoice->client->id_number ?? '') < 2)){
if($this->invoice->client->classification == 'individual' || (strlen($this->invoice->client->vat_number ?? '') < 2 && strlen($this->invoice->client->id_number ?? '') < 2)){
return $this->setEmailRouting($this->getIndividualEmailRoute());
}
else {
$this->setEmailRouting("peppol_invoice_{$this->invoice->id}_{$this->invoice->company->db}_storeonly@mail.invoicing.co");
}
$code = $this->getClientRoutingCode();
$identifier = false;
if($this->invoice->client->country->iso_3166_2 == 'FR')
$vat = $this->invoice->client->id_number;
$identifier = $this->invoice->client->id_number;
else
$vat = $this->invoice->client->vat_number;
$identifier = $this->invoice->client->vat_number;
if($this->invoice->client->country->iso_3166_2 == 'DE' && $this->invoice->client->classification == 'government')
$vat = $this->invoice->client->routing_id;
$identifier = $this->invoice->client->routing_id;
if(!$identifier)
$identifier = $this->getClientPublicIdentifier($code);
$this->setStorecoveMeta($this->buildRouting([
["scheme" => $code, "id" => $vat]
["scheme" => $code, "id" => $identifier]
]));
return $this;

View File

@ -106,12 +106,9 @@ class StorecoveRouter
/**
* Return the routing code based on country and entity classification
*
* ** note ** Individuals routing to their email address will
* not hit this code path.
*
*
* @param string $country
* @param ?string $classification
* @param ?string $classification DE:STNR
* @return string
*/
public function resolveRouting(string $country, ?string $classification = 'business'): string
@ -127,6 +124,7 @@ class StorecoveRouter
default => $code = "B",
};
//France determine routing scheme
if ($this->invoice && $country == 'FR') {
if ($code == 'B' && strlen($this->invoice->client->id_number) == 9) {
@ -139,10 +137,17 @@ class StorecoveRouter
}
//DE we can route via Steurnummer
if($this->invoice && $country = "DE" && $classification == 'individual' && strlen($this->invoice->client->id_number ?? '') > 4){
return 'DE:STNR';
}
//Single array
if (is_array($rules) && !is_array($rules[0])) {
return $rules[3];
}
//Multi Array - iterate
foreach($rules as $rule) {
if(stripos($rule[0], $code) !== false) {
return $rule[3];

View File

@ -103,35 +103,35 @@ class TemplateService
$this->twig->addExtension(new IntlExtension());
$this->twig->addExtension(new \Twig\Extension\DebugExtension());
$function = new \Twig\TwigFunction('img', function ($string, $style = '') {
return '<img src="' . $string . '" style="' . $style . '"></img>';
});
$function = new \Twig\TwigFunction('img', \Closure::fromCallable(function (string $image_src, string $image_style = '') {
return '<img src="' . $image_src . '" style="' . $image_style . '"></img>';
}));
$this->twig->addFunction($function);
$function = new \Twig\TwigFunction('t', function ($string) {
return ctrans("texts.{$string}");
});
$function = new \Twig\TwigFunction('t', \Closure::fromCallable(function (string $text_key) {
return ctrans("texts.{$text_key}");
}));
$this->twig->addFunction($function);
$filter = new \Twig\TwigFilter('sum', function (?array $array, ?string $column) {
if(!is_array($array)) {
$filter = new \Twig\TwigFilter('sum', \Closure::fromCallable(function (?array $array, ?string $column) {
if (!is_array($array)) {
return 0;
}
return array_sum(array_column($array, $column));
});
}));
$this->twig->addFilter($filter);
$allowedTags = ['if', 'for', 'set', 'filter'];
$allowedFilters = ['replace', 'escape', 'e', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency', 'format_number','format_percent_number','map', 'join', 'first', 'date', 'sum', 'number_format','nl2br','striptags'];
$allowedFunctions = ['range', 'cycle', 'constant', 'date',];
$allowedFunctions = ['range', 'cycle', 'constant', 'date','img','t'];
$allowedProperties = ['type_id'];
$allowedMethods = ['img','t'];
// $allowedMethods = ['img','t'];
$allowedMethods = [
'Illuminate\Support\Collection' => ['__toString'],
];
$policy = new \Twig\Sandbox\SecurityPolicy($allowedTags, $allowedFilters, $allowedFunctions, $allowedProperties, $allowedMethods);
$policy = new \Twig\Sandbox\SecurityPolicy($allowedTags, $allowedFilters, $allowedMethods, $allowedProperties, $allowedFunctions);
$this->twig->addExtension(new \Twig\Extension\SandboxExtension($policy, true));
return $this;

View File

@ -17,8 +17,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => env('APP_VERSION', '5.10.44'),
'app_tag' => env('APP_TAG', '5.10.44'),
'app_version' => env('APP_VERSION', '5.10.45'),
'app_tag' => env('APP_TAG', '5.10.45'),
'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', false),