Skip to content

Commit

Permalink
Merge pull request invoiceninja#10560 from turbo124/v5-develop
Browse files Browse the repository at this point in the history
v5.11.28
  • Loading branch information
turbo124 authored Jan 21, 2025
2 parents 18d20c3 + a0cab6c commit cbd4827
Show file tree
Hide file tree
Showing 89 changed files with 37,369 additions and 25 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.11.27
5.11.28
2 changes: 1 addition & 1 deletion app/Helpers/Bank/Nordigen/Nordigen.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function (array $eua) use ($institutionId, $requiredScopes, $accessDays, $txDays
* access_valid_for_days: int,
* access_scope: string[],
* accepted: string
* }|null Agreement details
* } Agreement details
*/
public function createAgreement(array $institution, int $accessDays, int $transactionDays): array
{
Expand Down
6 changes: 5 additions & 1 deletion app/Helpers/Invoice/InvoiceItemSum.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private function calcTaxes()
private function getPeppolSurchargeTaxes(): self
{

if (!($this->client->getSetting('e_invoice_type') == 'PEPPOL')) {
if (!$this->client->getSetting('enable_e_invoice')) {
return $this;
}

Expand Down Expand Up @@ -400,6 +400,10 @@ private function groupTax($tax_name, $tax_rate, $tax_total, $amount, $tax_id = '

$key = str_replace(' ', '', $tax_name.$tax_rate);

//Handles an edge case where a blank line is entered.
if($tax_rate > 0 && $amount == 0)
return;

$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name.' '.Number::formatValueNoTrailingZeroes(floatval($tax_rate), $this->client).'%', 'tax_id' => $tax_id, 'tax_rate' => $tax_rate, 'base_amount' => $amount];

$this->tax_collection->push(collect($group_tax));
Expand Down
89 changes: 86 additions & 3 deletions app/Helpers/Invoice/InvoiceItemSumInclusive.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class InvoiceItemSumInclusive

private $tax_collection;

private $custom_surcharge_map;

private bool $calc_tax = false;

private $total_discount;
Expand All @@ -120,6 +122,8 @@ class InvoiceItemSumInclusive
public function __construct(RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice)
{
$this->tax_collection = collect([]);
$this->custom_surcharge_map = collect([]);

$this->total_discount = 0;

$this->invoice = $invoice;
Expand All @@ -141,7 +145,7 @@ public function process()
return $this;
}

$this->calcLineItems();
$this->calcLineItems()->getPeppolSurchargeTaxes();

return $this;
}
Expand Down Expand Up @@ -288,13 +292,91 @@ private function calcTaxes()
return $this;
}

private function getPeppolSurchargeTaxes(): self
{

if (!$this->client->getSetting('enable_e_invoice')) {
return $this;
}

$this->custom_surcharge_map = collect([]);

collect($this->invoice->line_items)
->flatMap(function ($item) {
return collect([1, 2, 3])
->map(fn ($i) => [
'name' => $item->{"tax_name{$i}"} ?? '',
'percentage' => $item->{"tax_rate{$i}"} ?? 0,
'tax_id' => $item->tax_id ?? '1',
])
->filter(fn ($tax) => strlen($tax['name']) > 1);
})
->unique(fn ($tax) => $tax['percentage'] . '_' . $tax['name'])
->values()
->each(function ($tax) {

$tax_component = 0;

if ($this->invoice->custom_surcharge1) {
$tax_component += round($this->invoice->custom_surcharge1 - ($this->invoice->custom_surcharge1 / (1 + ($tax['percentage'] / 100))), 2);
$this->setCustomSurchargeNetMap(['custom_surcharge1' => round($this->invoice->custom_surcharge1 / (1 + ($tax['percentage'] / 100)),2)]);
}

if ($this->invoice->custom_surcharge2) {
$tax_component += round($this->invoice->custom_surcharge2 - ($this->invoice->custom_surcharge2 / (1 + ($tax['percentage'] / 100))), 2);
$this->setCustomSurchargeNetMap(['custom_surcharge2' => round($this->invoice->custom_surcharge2 / (1 + ($tax['percentage'] / 100)),2)]);
}

if ($this->invoice->custom_surcharge3) {
$tax_component += round($this->invoice->custom_surcharge3 - ($this->invoice->custom_surcharge3 / (1 + ($tax['percentage'] / 100))), 2);
$this->setCustomSurchargeNetMap(['custom_surcharge3' => round($this->invoice->custom_surcharge3 / (1 + ($tax['percentage'] / 100)),2)]);
}

if ($this->invoice->custom_surcharge4) {
$tax_component += round($this->invoice->custom_surcharge4 - ($this->invoice->custom_surcharge4 / (1 + ($tax['percentage'] / 100))), 2);
$this->setCustomSurchargeNetMap(['custom_surcharge4' => round($this->invoice->custom_surcharge4 / (1 + ($tax['percentage'] / 100)),2)]);
}

$amount = $this->invoice->custom_surcharge4 + $this->invoice->custom_surcharge3 + $this->invoice->custom_surcharge2 + $this->invoice->custom_surcharge1;

if ($tax_component > 0) {
$this->groupTax($tax['name'], $tax['percentage'], $tax_component, $amount, $tax['tax_id']);
}

});

return $this;
}

private function setCustomSurchargeNetMap(array $surcharge): self
{
$this->custom_surcharge_map->push($surcharge);

return $this;
}

public function getCustomSurchargeNetMap()
{
return $this->custom_surcharge_map;
}






private function groupTax($tax_name, $tax_rate, $tax_total, $amount, $tax_id = '')
{
$group_tax = [];

$key = str_replace(' ', '', $tax_name.$tax_rate);

$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name.' '.Number::formatValueNoTrailingZeroes(floatval($tax_rate), $this->client).'%', 'tax_id' => $tax_id, 'base_amount' => $amount];
//Handles an edge case where a blank line is entered.
if ($tax_rate > 0 && $amount == 0) {
return;
}

$group_tax = ['key' => $key, 'total' => $tax_total, 'tax_name' => $tax_name.' '.Number::formatValueNoTrailingZeroes(floatval($tax_rate), $this->client).'%', 'tax_id' => $tax_id, 'tax_rate' => $tax_rate, 'base_amount' => $tax_rate > 0 ? round($amount/(1+($tax_rate/100)),2) : $amount];

$this->tax_collection->push(collect($group_tax));
}
Expand Down Expand Up @@ -430,9 +512,10 @@ public function calcTaxesWithAmountDiscount()

}

$this->getPeppolSurchargeTaxes();

return $this;

// $this->setTotalTaxes($item_tax);
}


Expand Down
9 changes: 8 additions & 1 deletion app/Helpers/Invoice/InvoiceSumInclusive.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ public function getTotalSurcharges()
return $this->total_custom_values;
}

public function getTotalNetSurcharges()
{
$map = $this->invoice_items->getCustomSurchargeNetMap();

return $map->sum('custom_surcharge1') + $map->sum('custom_surcharge2') + $map->sum('custom_surcharge3') + $map->sum('custom_surcharge4');
}

public function getRecurringInvoice()
{
$this->invoice->amount = $this->formatValue($this->getTotal(), $this->precision);
Expand Down Expand Up @@ -365,7 +372,7 @@ public function setTaxMap()
}

$this->tax_map = collect();

$keys = $this->invoice_items->getGroupedTaxes()->pluck('key')->unique();

$values = $this->invoice_items->getGroupedTaxes();
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ private function loginOrCreateFromSocialite($user, $provider)
$name[1] = request()->has('last_name') ? request()->input('last_name') : $name[1];
}

if($provider == 'apple' && !$user->email){
return response()->json(['message' => 'This signup method is not supported as no email was provided'], 403);
}

$new_account = [
'first_name' => $name[0],
'last_name' => $name[1],
Expand Down
10 changes: 7 additions & 3 deletions app/Http/Controllers/Bank/NordigenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function connect(ConnectNordigenBankIntegrationRequest $request): View|Re
}))[0];

try {
$txDays = $data['tx_days'] ?? 0;
$txDays = $data['tx_days'] ?? 0; //@phpstan-ignore-line

$agreement = $nordigen->firstValidAgreement($institution['id'], $data['access_days'] ?? 0, $txDays)
?? $nordigen->createAgreement($institution, $data['access_days'] ?? 9999, $txDays);
Expand Down Expand Up @@ -173,6 +173,8 @@ public function confirm(ConfirmNordigenBankIntegrationRequest $request): View|Re
if (isset($nordigen_account['error'])) {
continue;
}

$bank_integration = false;

try {
$bank_integration = $this->findIntegrationBy('account', $nordigen_account, $company);
Expand All @@ -194,6 +196,10 @@ public function confirm(ConfirmNordigenBankIntegrationRequest $request): View|Re
$bank_integration->nickname = $nordigen_account['nickname'];
$bank_integration->currency = $nordigen_account['account_currency'];
} finally {

if(!$bank_integration)
continue;

$bank_integration->auto_sync = true;
$bank_integration->disabled_upstream = false;
$bank_integration->balance = $nordigen_account['current_balance'];
Expand Down Expand Up @@ -224,8 +230,6 @@ public function confirm(ConfirmNordigenBankIntegrationRequest $request): View|Re
/**
* Handles failure scenarios for Nordigen bank integrations
*
* @param array{lang: string, redirect?: string}|null $context
* @param array{account: array}|null $company
*/
private function failed(string $reason, array $context, $company = null): View
{
Expand Down
10 changes: 9 additions & 1 deletion app/Jobs/EDocument/CreateEDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use App\Services\EDocument\Standards\RoEInvoice;
use App\Services\EDocument\Standards\OrderXDocument;
use App\Services\EDocument\Standards\FacturaEInvoice;
use App\Services\EDocument\Standards\ZugferdEDocument;
use App\Services\EDocument\Standards\ZugferdEDokument;

class CreateEDocument implements ShouldQueue
Expand Down Expand Up @@ -85,8 +86,15 @@ public function handle(): string|ZugferdDocumentBuilder
case "XInvoice-Extended":
case "XInvoice-BasicWL":
case "XInvoice-Basic":
$zugferd = (new ZugferdEDokument($this->document))->run();

//
if(config('ninja.zugferd_version_two')){
$zugferd = (new ZugferdEDocument($this->document))->run();
}
else {
$zugferd = (new ZugferdEDokument($this->document))->run();
}

return $this->returnObject ? $zugferd->xdocument : $zugferd->getXml();
case "Facturae_3.2":
case "Facturae_3.2.1":
Expand Down
5 changes: 4 additions & 1 deletion app/Models/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ public function badgeForStatus(): string
return '<h6><span class="badge badge-danger">'.ctrans('texts.payment_status_3').'</span></h6>';
case self::STATUS_COMPLETED:

if ($this->amount > $this->applied) {
if($this->applied == 0){
return '<h6><span class="badge badge-info">' . ctrans('texts.unapplied') . '</span></h6>';
}
elseif ($this->amount > $this->applied) {
return '<h6><span class="badge badge-info">' . ctrans('texts.partially_unapplied') . '</span></h6>';
}

Expand Down
2 changes: 1 addition & 1 deletion app/Services/EDocument/Jobs/SendEDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function handle(Storecove $storecove)
'account_key' => $model->company->account->key,
'e_invoicing_token' => $model->company->account->e_invoicing_token,
];

nlog($payload);
//Self Hosted Sending Code Path
if (Ninja::isSelfHost() && ($model instanceof Invoice) && $model->company->peppolSendingEnabled()) {

Expand Down
10 changes: 5 additions & 5 deletions app/Services/EDocument/Standards/Peppol.php
Original file line number Diff line number Diff line change
Expand Up @@ -987,14 +987,14 @@ private function getAccountingSupplierParty(): AccountingSupplierParty
$pi = new PartyIdentification();
$vatID = new ID();
$vatID->schemeID = $this->resolveScheme();
$vatID->value = $this->override_vat_number ?? preg_replace("/[^a-zA-Z0-9]/", "", $this->company->settings->vat_number); //todo if we are cross border - switch to the supplier local vat number
$vatID->value = $this->override_vat_number ?? preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->company->settings->vat_number); //todo if we are cross border - switch to the supplier local vat number

$pi->ID = $vatID;
$party->PartyIdentification[] = $pi;
$pts = new \InvoiceNinja\EInvoice\Models\Peppol\PartyTaxSchemeType\PartyTaxScheme();

$companyID = new \InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\CompanyID();
$companyID->value = $this->override_vat_number ?? preg_replace("/[^a-zA-Z0-9]/", "", $this->company->settings->vat_number);
$companyID->value = $this->override_vat_number ?? preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->company->settings->vat_number);
$pts->CompanyID = $companyID;

$ts = new TaxScheme();
Expand Down Expand Up @@ -1513,9 +1513,9 @@ private function standardizeTaxSchemeId(string $tax_name): string
private function resolveScheme(bool $is_client = false): string
{

$vat_number = $is_client ? preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->client->vat_number) : preg_replace("/[^a-zA-Z0-9]/", "", $this->company->settings->vat_number);
$tax_number = $is_client ? preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->client->id_number) : preg_replace("/[^a-zA-Z0-9]/", "", $this->company->settings->id_number);
$country_code = $is_client ? $this->invoice->client->country->iso_3166_2 : $this->company->country()->iso_3166_2;
$vat_number = $is_client ? preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->client->vat_number ?? '') : preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->company->settings->vat_number ?? '');
$tax_number = $is_client ? preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->client->id_number ?? ''): preg_replace("/[^a-zA-Z0-9]/", "", $this->invoice->company->settings->id_number ?? '');
$country_code = $is_client ? $this->invoice->client->country->iso_3166_2 : $this->invoice->company->country()->iso_3166_2;

return '0037';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ private function validateXsd(): self
return $this;
}

public function setXsd(string $xsd): self
{
$this->ubl_xsd = $xsd;

return $this;
}

public function getXsd(): string
{
return $this->ubl_xsd;
}

public function setStyleSheets(array $stylesheets): self
{
$this->stylesheets = $stylesheets;
Expand Down
Loading

0 comments on commit cbd4827

Please sign in to comment.