diff --git a/.env.ci b/.env.ci index fa835031f4..f082f171b9 100644 --- a/.env.ci +++ b/.env.ci @@ -32,4 +32,4 @@ R2_DEFAULT_REGION_BACKUP=us-east-1 R2_BUCKET_BACKUP= R2_URL_BACKUP= R2_ENDPOINT_BACKUP= -R2_USE_PATH_STYLE_ENDPOINT_BACKUP= +R2_USE_PATH_STYLE_ENDPOINT_BACKUP=false diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 1a6fa06484..3d06a14a88 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -488,8 +488,6 @@ class InvoiceItemSum $amount = $this->item->line_total; } - // $amount = round($amount,2); - $item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount); $item_tax += $item_tax_rate1_total; @@ -523,7 +521,7 @@ class InvoiceItemSum } - + $this->getPeppolSurchargeTaxes(); return $this; } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index c337f22d79..1b08056a16 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -183,10 +183,10 @@ class BaseRepository $model->fill($tmp_data); - $model->custom_surcharge_tax1 = $client->company->custom_surcharge_taxes1; - $model->custom_surcharge_tax2 = $client->company->custom_surcharge_taxes2; - $model->custom_surcharge_tax3 = $client->company->custom_surcharge_taxes3; - $model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4; + $model->custom_surcharge_tax1 = $client->getSetting('e_invoice_type') == 'PEPPOL' ? true : $client->company->custom_surcharge_taxes1; + $model->custom_surcharge_tax2 = $client->getSetting('e_invoice_type') == 'PEPPOL' ? true : $client->company->custom_surcharge_taxes2; + $model->custom_surcharge_tax3 = $client->getSetting('e_invoice_type') == 'PEPPOL' ? true : $client->company->custom_surcharge_taxes3; + $model->custom_surcharge_tax4 = $client->getSetting('e_invoice_type') == 'PEPPOL' ? true : $client->company->custom_surcharge_taxes4; if (!$model->id) { $this->new_model = true; diff --git a/app/Services/EDocument/Standards/Peppol.php b/app/Services/EDocument/Standards/Peppol.php index 3282eb4fab..dbbeb47955 100644 --- a/app/Services/EDocument/Standards/Peppol.php +++ b/app/Services/EDocument/Standards/Peppol.php @@ -345,6 +345,7 @@ class Peppol extends AbstractService $xml .= $suffix; + nlog($xml); return $xml; } @@ -473,12 +474,13 @@ class Peppol extends AbstractService // Add Allowance Charge to Price $allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge(); + $allowanceCharge->ChargeIndicator = 'true'; $allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount(); $allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code; $allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge1, 2, '.', ''); - $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount(); - $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code; - $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges(); + // $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount(); + // $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code; + // $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges(); $this->calculateTaxMap($this->invoice->custom_surcharge1); @@ -492,12 +494,13 @@ class Peppol extends AbstractService // Add Allowance Charge to Price $allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge(); + $allowanceCharge->ChargeIndicator = 'true'; $allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount(); $allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code; $allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge2, 2, '.', ''); - $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount(); - $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code; - $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges(); + // $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount(); + // $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code; + // $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges(); $this->calculateTaxMap($this->invoice->custom_surcharge2); @@ -512,12 +515,13 @@ class Peppol extends AbstractService // Add Allowance Charge to Price $allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge(); + $allowanceCharge->ChargeIndicator = 'true'; $allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount(); $allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code; $allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge3, 2, '.', ''); - $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount(); - $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code; - $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges(); + // $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount(); + // $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code; + // $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges(); $this->calculateTaxMap($this->invoice->custom_surcharge3); @@ -531,12 +535,13 @@ class Peppol extends AbstractService // Add Allowance Charge to Price $allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge(); + $allowanceCharge->ChargeIndicator = 'true'; $allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount(); $allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code; $allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge4, 2, '.', ''); - $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount(); - $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code; - $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges(); + // $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount(); + // $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code; + // $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges(); $this->calculateTaxMap($this->invoice->custom_surcharge4); @@ -563,7 +568,7 @@ class Peppol extends AbstractService $lea = new LineExtensionAmount(); $lea->currencyID = $this->invoice->client->currency()->code; - $lea->amount = $this->invoice->uses_inclusive_taxes ? round($this->invoice->amount - $this->invoice->total_taxes, 2) : $this->calc->getSubTotal(); + $lea->amount = $this->invoice->uses_inclusive_taxes ? round($this->invoice->amount - $this->invoice->total_taxes, 2) : $this->calc->getSubtotal(); $lmt->LineExtensionAmount = $lea; $tea = new TaxExclusiveAmount(); @@ -587,6 +592,11 @@ class Peppol extends AbstractService $am->amount = number_format($this->calc->getTotalDiscount(), 2, '.', ''); $lmt->AllowanceTotalAmount = $am; + $cta = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\ChargeTotalAmount(); + $cta->currencyID = $this->invoice->client->currency()->code; + $cta->amount = number_format($this->calc->getTotalSurcharges(), 2, '.', ''); + $lmt->ChargeTotalAmount = $cta; + return $lmt; } @@ -1200,19 +1210,20 @@ class Peppol extends AbstractService } } - if ($this->invoice->custom_surcharge1 && $this->invoice->custom_surcharge_tax1) { + //** Surcharges are taxable regardless, if control is needed over taxable components, add it as a line item! */ + if ($this->invoice->custom_surcharge1 > 0) { $total += $this->invoice->custom_surcharge1; } - if ($this->invoice->custom_surcharge2 && $this->invoice->custom_surcharge_tax2) { + if ($this->invoice->custom_surcharge2 > 0) { $total += $this->invoice->custom_surcharge2; } - if ($this->invoice->custom_surcharge3 && $this->invoice->custom_surcharge_tax3) { + if ($this->invoice->custom_surcharge3 > 0) { $total += $this->invoice->custom_surcharge3; } - if ($this->invoice->custom_surcharge4 && $this->invoice->custom_surcharge_tax4) { + if ($this->invoice->custom_surcharge4 > 0) { $total += $this->invoice->custom_surcharge4; } diff --git a/app/Services/Pdf/PdfBuilder.php b/app/Services/Pdf/PdfBuilder.php index 1585846aff..3b13acc44a 100644 --- a/app/Services/Pdf/PdfBuilder.php +++ b/app/Services/Pdf/PdfBuilder.php @@ -873,7 +873,7 @@ class PdfBuilder } //nlog(microtime(true) - $start); - + return $data; } diff --git a/app/Services/Pdf/PdfConfiguration.php b/app/Services/Pdf/PdfConfiguration.php index 86e7c9a810..e7d8c0c396 100644 --- a/app/Services/Pdf/PdfConfiguration.php +++ b/app/Services/Pdf/PdfConfiguration.php @@ -393,17 +393,22 @@ class PdfConfiguration /* 08-01-2022 allow increased precision for unit price*/ $v = rtrim(sprintf('%f', $value), '0'); $parts = explode('.', $v); + + /** 2024-12-09 improve resolution of unit cost precision */ + if (strlen($parts[1] ?? '') > 2) + $precision = strlen($parts[1]); /* 08-02-2023 special if block to render $0.5 to $0.50*/ - if ($v < 1 && strlen($v) == 3) { - $precision = 2; - } elseif ($v < 1) { - $precision = strlen($v) - strrpos($v, '.') - 1; - } - - if (is_array($parts) && $parts[0] != 0) { - $precision = 2; - } + // if ($v < 1 && strlen($v) == 3) { + // $precision = 2; + // } elseif ($v < 1) { + // $precision = strlen($v) - strrpos($v, '.') - 1; + // } elseif ($v > 1) { + // $precision = strlen($v) - strrpos($v, '.') - 1; + // } + // if (is_array($parts) && $parts[0] != 0) { + // $precision = 2; + // } //04-04-2023 if currency = JPY override precision to 0 if ($this->currency->code == 'JPY') { diff --git a/app/Utils/Number.php b/app/Utils/Number.php index 650bc64cad..fdfeedc7f5 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -323,16 +323,21 @@ class Number $v = rtrim(sprintf('%f', $value), '0'); $parts = explode('.', $v); - /* 08-02-2023 special if block to render $0.5 to $0.50*/ - if ($v < 1 && strlen($v) == 3) { - $precision = 2; - } elseif ($v < 1) { - $precision = strlen($v) - strrpos($v, '.') - 1; + /* 2024-12-09 improved decimal resolution + if (strlen($parts[1] ?? '') > 2) { + $precision = strlen($parts[1]); } - if (is_array($parts) && $parts[0] != 0) { - $precision = 2; - } + /* 08-02-2023 special if block to render $0.5 to $0.50*/ + // if ($v < 1 && strlen($v) == 3) { + // $precision = 2; + // } elseif ($v < 1) { + // $precision = strlen($v) - strrpos($v, '.') - 1; + // } + + // if (is_array($parts) && $parts[0] != 0) { + // $precision = 2; + // } //04-04-2023 if currency = JPY override precision to 0 if ($currency->code == 'JPY') { diff --git a/tests/Unit/NumberTest.php b/tests/Unit/NumberTest.php index dd3dae956c..2176ea2a88 100644 --- a/tests/Unit/NumberTest.php +++ b/tests/Unit/NumberTest.php @@ -72,6 +72,37 @@ class NumberTest extends TestCase } + public function testNumberPrecisionFormatting() + { + $data = [ + "5.1" => "5.10", + "5.12345656" => "5.12345656", + "0.13" => "0.13", + "0.1" => "0.10", + "0.5" => "0.50", + "10.5" => "10.50", + "10100.00" => "10,100.00", + "10100.1" => "10,100.10", + ]; + + foreach($data as $key => $value) + { + + $parts = explode(".", $key); + + $precision_part = $parts[1]; + + $precision = 2; + + if(strlen($precision_part) > 2) + $precision = strlen($precision_part); + + $formatted_value = number_format($key, $precision, ".", ","); + + $this->assertEquals($value, $formatted_value); + } + } + public function testThreeDecimalFloatAsTax() {