Merge branch '2024_12_09_rounding_unit_costs' into v5-develop
This commit is contained in:
commit
4545b7b6f7
9
.env.ci
9
.env.ci
|
|
@ -25,11 +25,4 @@ CACHE_DRIVER=redis
|
||||||
QUEUE_CONNECTION=redis
|
QUEUE_CONNECTION=redis
|
||||||
SESSION_DRIVER=redis
|
SESSION_DRIVER=redis
|
||||||
PDF_GENERATOR=snappdf
|
PDF_GENERATOR=snappdf
|
||||||
|
R2_DEFAULT_REGION_BACKUP=us-east-1
|
||||||
R2_ACCESS_KEY_ID_BACKUP=
|
|
||||||
R2_SECRET_ACCESS_KEY_BACKUP=
|
|
||||||
R2_DEFAULT_REGION_BACKUP=us-east-1
|
|
||||||
R2_BUCKET_BACKUP=
|
|
||||||
R2_URL_BACKUP=
|
|
||||||
R2_ENDPOINT_BACKUP=
|
|
||||||
R2_USE_PATH_STYLE_ENDPOINT_BACKUP=
|
|
||||||
|
|
@ -488,8 +488,6 @@ class InvoiceItemSum
|
||||||
$amount = $this->item->line_total;
|
$amount = $this->item->line_total;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $amount = round($amount,2);
|
|
||||||
|
|
||||||
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
|
$item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount);
|
||||||
|
|
||||||
$item_tax += $item_tax_rate1_total;
|
$item_tax += $item_tax_rate1_total;
|
||||||
|
|
@ -523,7 +521,7 @@ class InvoiceItemSum
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->getPeppolSurchargeTaxes();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,10 +183,10 @@ class BaseRepository
|
||||||
|
|
||||||
$model->fill($tmp_data);
|
$model->fill($tmp_data);
|
||||||
|
|
||||||
$model->custom_surcharge_tax1 = $client->company->custom_surcharge_taxes1;
|
$model->custom_surcharge_tax1 = $client->getSetting('e_invoice_type') == 'PEPPOL' ? true : $client->company->custom_surcharge_taxes1;
|
||||||
$model->custom_surcharge_tax2 = $client->company->custom_surcharge_taxes2;
|
$model->custom_surcharge_tax2 = $client->getSetting('e_invoice_type') == 'PEPPOL' ? true : $client->company->custom_surcharge_taxes2;
|
||||||
$model->custom_surcharge_tax3 = $client->company->custom_surcharge_taxes3;
|
$model->custom_surcharge_tax3 = $client->getSetting('e_invoice_type') == 'PEPPOL' ? true : $client->company->custom_surcharge_taxes3;
|
||||||
$model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4;
|
$model->custom_surcharge_tax4 = $client->getSetting('e_invoice_type') == 'PEPPOL' ? true : $client->company->custom_surcharge_taxes4;
|
||||||
|
|
||||||
if (!$model->id) {
|
if (!$model->id) {
|
||||||
$this->new_model = true;
|
$this->new_model = true;
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,7 @@ class Peppol extends AbstractService
|
||||||
|
|
||||||
$xml .= $suffix;
|
$xml .= $suffix;
|
||||||
|
|
||||||
|
nlog($xml);
|
||||||
return $xml;
|
return $xml;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -473,12 +474,13 @@ class Peppol extends AbstractService
|
||||||
|
|
||||||
// Add Allowance Charge to Price
|
// Add Allowance Charge to Price
|
||||||
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
|
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
|
||||||
|
$allowanceCharge->ChargeIndicator = 'true';
|
||||||
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
|
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
|
||||||
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
|
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
|
||||||
$allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge1, 2, '.', '');
|
$allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge1, 2, '.', '');
|
||||||
$allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
|
// $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
|
||||||
$allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
|
// $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
|
||||||
$allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges();
|
// $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges();
|
||||||
|
|
||||||
$this->calculateTaxMap($this->invoice->custom_surcharge1);
|
$this->calculateTaxMap($this->invoice->custom_surcharge1);
|
||||||
|
|
||||||
|
|
@ -492,12 +494,13 @@ class Peppol extends AbstractService
|
||||||
|
|
||||||
// Add Allowance Charge to Price
|
// Add Allowance Charge to Price
|
||||||
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
|
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
|
||||||
|
$allowanceCharge->ChargeIndicator = 'true';
|
||||||
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
|
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
|
||||||
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
|
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
|
||||||
$allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge2, 2, '.', '');
|
$allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge2, 2, '.', '');
|
||||||
$allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
|
// $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
|
||||||
$allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
|
// $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
|
||||||
$allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges();
|
// $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges();
|
||||||
|
|
||||||
|
|
||||||
$this->calculateTaxMap($this->invoice->custom_surcharge2);
|
$this->calculateTaxMap($this->invoice->custom_surcharge2);
|
||||||
|
|
@ -512,12 +515,13 @@ class Peppol extends AbstractService
|
||||||
|
|
||||||
// Add Allowance Charge to Price
|
// Add Allowance Charge to Price
|
||||||
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
|
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
|
||||||
|
$allowanceCharge->ChargeIndicator = 'true';
|
||||||
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
|
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
|
||||||
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
|
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
|
||||||
$allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge3, 2, '.', '');
|
$allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge3, 2, '.', '');
|
||||||
$allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
|
// $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
|
||||||
$allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
|
// $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
|
||||||
$allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges();
|
// $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges();
|
||||||
|
|
||||||
$this->calculateTaxMap($this->invoice->custom_surcharge3);
|
$this->calculateTaxMap($this->invoice->custom_surcharge3);
|
||||||
|
|
||||||
|
|
@ -531,12 +535,13 @@ class Peppol extends AbstractService
|
||||||
|
|
||||||
// Add Allowance Charge to Price
|
// Add Allowance Charge to Price
|
||||||
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
|
$allowanceCharge = new \InvoiceNinja\EInvoice\Models\Peppol\AllowanceChargeType\AllowanceCharge();
|
||||||
|
$allowanceCharge->ChargeIndicator = 'true';
|
||||||
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
|
$allowanceCharge->Amount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\Amount();
|
||||||
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
|
$allowanceCharge->Amount->currencyID = $this->invoice->client->currency()->code;
|
||||||
$allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge4, 2, '.', '');
|
$allowanceCharge->Amount->amount = number_format($this->invoice->custom_surcharge4, 2, '.', '');
|
||||||
$allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
|
// $allowanceCharge->BaseAmount = new \InvoiceNinja\EInvoice\Models\Peppol\AmountType\BaseAmount();
|
||||||
$allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
|
// $allowanceCharge->BaseAmount->currencyID = $this->invoice->client->currency()->code;
|
||||||
$allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges();
|
// $allowanceCharge->BaseAmount->amount = (string) $this->calc->getSubtotalWithSurcharges();
|
||||||
|
|
||||||
$this->calculateTaxMap($this->invoice->custom_surcharge4);
|
$this->calculateTaxMap($this->invoice->custom_surcharge4);
|
||||||
|
|
||||||
|
|
@ -563,7 +568,7 @@ class Peppol extends AbstractService
|
||||||
|
|
||||||
$lea = new LineExtensionAmount();
|
$lea = new LineExtensionAmount();
|
||||||
$lea->currencyID = $this->invoice->client->currency()->code;
|
$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;
|
$lmt->LineExtensionAmount = $lea;
|
||||||
|
|
||||||
$tea = new TaxExclusiveAmount();
|
$tea = new TaxExclusiveAmount();
|
||||||
|
|
@ -587,6 +592,11 @@ class Peppol extends AbstractService
|
||||||
$am->amount = number_format($this->calc->getTotalDiscount(), 2, '.', '');
|
$am->amount = number_format($this->calc->getTotalDiscount(), 2, '.', '');
|
||||||
$lmt->AllowanceTotalAmount = $am;
|
$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;
|
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;
|
$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;
|
$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;
|
$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;
|
$total += $this->invoice->custom_surcharge4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -873,7 +873,7 @@ class PdfBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
//nlog(microtime(true) - $start);
|
//nlog(microtime(true) - $start);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -393,17 +393,22 @@ class PdfConfiguration
|
||||||
/* 08-01-2022 allow increased precision for unit price*/
|
/* 08-01-2022 allow increased precision for unit price*/
|
||||||
$v = rtrim(sprintf('%f', $value), '0');
|
$v = rtrim(sprintf('%f', $value), '0');
|
||||||
$parts = explode('.', $v);
|
$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*/
|
/* 08-02-2023 special if block to render $0.5 to $0.50*/
|
||||||
if ($v < 1 && strlen($v) == 3) {
|
// if ($v < 1 && strlen($v) == 3) {
|
||||||
$precision = 2;
|
// $precision = 2;
|
||||||
} elseif ($v < 1) {
|
// } elseif ($v < 1) {
|
||||||
$precision = strlen($v) - strrpos($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;
|
// if (is_array($parts) && $parts[0] != 0) {
|
||||||
}
|
// $precision = 2;
|
||||||
|
// }
|
||||||
|
|
||||||
//04-04-2023 if currency = JPY override precision to 0
|
//04-04-2023 if currency = JPY override precision to 0
|
||||||
if ($this->currency->code == 'JPY') {
|
if ($this->currency->code == 'JPY') {
|
||||||
|
|
|
||||||
|
|
@ -323,16 +323,21 @@ class Number
|
||||||
$v = rtrim(sprintf('%f', $value), '0');
|
$v = rtrim(sprintf('%f', $value), '0');
|
||||||
$parts = explode('.', $v);
|
$parts = explode('.', $v);
|
||||||
|
|
||||||
/* 08-02-2023 special if block to render $0.5 to $0.50*/
|
/* 2024-12-09 improved decimal resolution
|
||||||
if ($v < 1 && strlen($v) == 3) {
|
if (strlen($parts[1] ?? '') > 2) {
|
||||||
$precision = 2;
|
$precision = strlen($parts[1]);
|
||||||
} elseif ($v < 1) {
|
|
||||||
$precision = strlen($v) - strrpos($v, '.') - 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($parts) && $parts[0] != 0) {
|
/* 08-02-2023 special if block to render $0.5 to $0.50*/
|
||||||
$precision = 2;
|
// 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
|
//04-04-2023 if currency = JPY override precision to 0
|
||||||
if ($currency->code == 'JPY') {
|
if ($currency->code == 'JPY') {
|
||||||
|
|
|
||||||
|
|
@ -147,11 +147,12 @@ return [
|
||||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINTP', false),
|
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINTP', false),
|
||||||
'throw' => false,
|
'throw' => false,
|
||||||
],
|
],
|
||||||
|
|
||||||
'backup' => [
|
'backup' => [
|
||||||
'driver' => 's3',
|
'driver' => 's3',
|
||||||
'key' => env('R2_ACCESS_KEY_ID_BACKUP'),
|
'key' => env('R2_ACCESS_KEY_ID_BACKUP'),
|
||||||
'secret' => env('R2_SECRET_ACCESS_KEY_BACKUP'),
|
'secret' => env('R2_SECRET_ACCESS_KEY_BACKUP'),
|
||||||
'region' => env('R2_DEFAULT_REGION_BACKUP'),
|
'region' => env('R2_DEFAULT_REGION_BACKUP','auto'),
|
||||||
'bucket' => env('R2_BUCKET_BACKUP'),
|
'bucket' => env('R2_BUCKET_BACKUP'),
|
||||||
'url' => env('R2_URL_BACKUP'),
|
'url' => env('R2_URL_BACKUP'),
|
||||||
'visibility' => 'private',
|
'visibility' => 'private',
|
||||||
|
|
|
||||||
|
|
@ -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()
|
public function testThreeDecimalFloatAsTax()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue