1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Fixes for storecove

This commit is contained in:
David Bomba 2024-10-30 13:57:44 +11:00
parent 534ec2c5ec
commit e3471bed56
6 changed files with 29 additions and 200 deletions

View File

@ -13,7 +13,7 @@ class InvoiceLines
public float $itemPrice = 0.0;
public int $quantity = 0;
public float $quantity = 0;
public string $quantityUnitCode = '';
@ -60,12 +60,12 @@ class InvoiceLines
$this->itemPrice = $itemPrice;
}
public function getQuantity(): int
public function getQuantity()
{
return $this->quantity;
}
public function setQuantity(int $quantity): void
public function setQuantity($quantity): void
{
$this->quantity = $quantity;
}

View File

@ -496,8 +496,8 @@ class Mutator implements MutatorInterface
$this->p_invoice->AccountingCustomerParty->Party->PostalAddress->CountrySubentity = $resolved_state;
$this->p_invoice->AccountingCustomerParty->Party->PostalAddress->CityName = $resolved_city;
$this->p_invoice->AccountingCustomerParty->Party->PhysicalLocation->Address->CountrySubentity = $resolved_state;
$this->p_invoice->AccountingCustomerParty->Party->PhysicalLocation->Address->CityName = $resolved_city;
// $this->p_invoice->AccountingCustomerParty->Party->PhysicalLocation->Address->CountrySubentity = $resolved_state;
// $this->p_invoice->AccountingCustomerParty->Party->PhysicalLocation->Address->CityName = $resolved_city;
return $this;
}

View File

@ -2,6 +2,8 @@
namespace App\Services\EDocument\Gateway\Transformers;
use App\Helpers\Invoice\Taxer;
use App\Utils\Traits\NumberFormatter;
use App\Services\EDocument\Gateway\Storecove\Models\Tax;
use App\Services\EDocument\Gateway\Storecove\Models\Party;
use App\Services\EDocument\Gateway\Storecove\Models\Address;
@ -9,14 +11,17 @@ use App\Services\EDocument\Gateway\Storecove\Models\Contact;
use App\Services\EDocument\Gateway\Storecove\Models\References;
use App\Services\EDocument\Gateway\Storecove\Models\InvoiceLines;
use App\Services\EDocument\Gateway\Storecove\Models\PaymentMeans;
use App\Services\EDocument\Gateway\Storecove\Models\TaxSubtotals;
use App\Services\EDocument\Gateway\Storecove\Models\AllowanceCharges;
use App\Services\EDocument\Gateway\Storecove\Models\AccountingCustomerParty;
use App\Services\EDocument\Gateway\Storecove\Models\AccountingSupplierParty;
use App\Services\EDocument\Gateway\Storecove\Models\Invoice as StorecoveInvoice;
use App\Services\EDocument\Gateway\Storecove\Models\TaxSubtotals;
class StorecoveTransformer implements TransformerInterface
{
use Taxer;
use NumberFormatter;
private StorecoveInvoice $s_invoice;
private array $tax_map = [];
@ -104,7 +109,7 @@ class StorecoveTransformer implements TransformerInterface
// Basic line details
$line->setLineId($peppolLine->ID->value);
$line->setQuantity((int)$peppolLine->InvoicedQuantity);
$line->setQuantity((int)$peppolLine->InvoicedQuantity->amount);
$line->setItemPrice((float)$peppolLine->Price->PriceAmount->amount);
$line->setAmountExcludingVat((float)$peppolLine->LineExtensionAmount->amount);
@ -186,11 +191,20 @@ class StorecoveTransformer implements TransformerInterface
$taxAmount = 0;
$taxableAmount = 0;
foreach($peppolLine->TaxTotal as $taxTotal)
foreach($peppolLine->Item as $item)
{
$taxableAmount += $taxTotal->TaxSubtotal[0]->TaxableAmount->amount;
$taxAmount += $taxTotal->TaxSubtotal[0]->TaxAmount->amount;
$_taxAmount = $this->calcAmountLineTax($ctc->Percent, $peppolLine->LineExtensionAmount->amount);
$taxAmount += $_taxAmount;
$taxableAmount += $peppolLine->LineExtensionAmount->amount;
}
// foreach($peppolLine->TaxTotal as $taxTotal)
// {
// $taxableAmount += $taxTotal->TaxSubtotal[0]->TaxableAmount->amount;
// $taxAmount += $taxTotal->TaxSubtotal[0]->TaxAmount->amount;
// }
$this->tax_map[] = [
'percentage' => $ctc->Percent,
@ -208,7 +222,7 @@ class StorecoveTransformer implements TransformerInterface
if(isset($ctc->TaxTotal[0]->JurisdictionRegionAddress->Country->IdentificationCode->value))
return $ctc->TaxTotal[0]->JurisdictionRegionAddress->Country->IdentificationCode->value;
return $peppolInvoice->AccountingSupplierParty->Party->PhysicalLocation->Country->IdentificationCode->value;
return $peppolInvoice->AccountingSupplierParty->Party->PostalAddress->Country->IdentificationCode->value;
}
public function getInvoice(): StorecoveInvoice

View File

@ -673,14 +673,6 @@ class Peppol extends AbstractService
// $line->TaxTotal = $item_taxes;
// }
// $price = new Price();
// $pa = new PriceAmount();
// $pa->currencyID = $this->invoice->client->currency()->code;
// $pa->amount = (string) ($this->costWithDiscount($item) - ($this->invoice->uses_inclusive_taxes ? ($this->calcInclusiveLineTax($item->tax_rate1, $item->line_total) / $item->quantity) : 0));
// $price->PriceAmount = $pa;
// $line->Price = $price;
// Handle Price and Discounts
if ($item->discount > 0) {
// Base Price (before discount)
@ -1005,7 +997,6 @@ class Peppol extends AbstractService
$ts->ID = $vatID;
$pts->TaxScheme = $ts;
//@todo if we have an exact GLN/routing number we should update this, otherwise Storecove will proxy and update on transit
$id = new \InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\EndpointID();
$id->value = $this->company->settings->vat_number;
@ -1388,84 +1379,6 @@ class Peppol extends AbstractService
$tax_number = $is_client ? $this->invoice->client->id_number : $this->company->settings->id_number;
$country_code = $is_client ? $this->invoice->client->country->iso_3166_2 : $this->company->country()->iso_3166_2;
switch ($country_code) {
case 'FR': // France
return '0002'; // SIRENE
case 'SE': // Sweden
return '0007'; // Organisationsnummer
case 'NO': // Norway
return '0192'; // Enhetsregisteret
case 'FI': // Finland
return '0213'; // Finnish VAT
// '0212', // Finnish Organization Identifier
// '0216', // OVT
case 'DK': // Denmark
return '0184'; // DIGSTORG
case 'IT': // Italy
return '0201'; // IPA
// '0210', // CODICE FISCALE
// '0211', // PARTITA IVA
case 'NL': // Netherlands
return '0106'; // Chamber of Commerce
// '0190', // Dutch Originator's Identification Number
case 'BE': // Belgium
return '0208'; // Enterprise Number
case 'LU': // Luxembourg
return '0060'; // DUNS
case 'ES': // Spain
return '0195'; // Company Registry
case 'AT': // Austria
return '0088'; // GLN
case 'DE': // Germany
return '0196'; // Leitweg-ID
case 'GB': // United Kingdom
return '0088'; // GLN
case 'CH': // Switzerland
return '0183'; // Swiss Unique Business ID
case 'SG': // Singapore
return '0195'; // UEN
//0009 DUNS
case 'AU': // Australia
return '0151'; // ABN
case 'US': // United States
return '0060'; // DUNS
case 'LT':
return '0200';
case 'JP':
return '0221'; // Japan Registered Invoice Number
case 'MY':
return '0230'; // Malaysia National e-invoicing framework
case 'NZ':
return '0088';
// Default to GLN for any other country
default:
if (!empty($tax_number) && strlen($tax_number) === 9) {
return '0009'; // DUNS if 9 digits
}
return '0088'; // Global Location Number (GLN)
}
}
return '0037';
}
}

View File

@ -55,8 +55,6 @@ class XsltDocumentValidator
$xsltExecutable = $xslt->compileFromFile(app_path($stylesheet)); //@phpstan-ignore-line
$result = $xsltExecutable->transformToValue($xdmNode);
nlog($result->size());
if($result->size() == 0)
continue;

View File

@ -191,6 +191,7 @@ class PeppolTest extends TestCase
$settings->state = 'Bayern';
$settings->postal_code = '98060';
$settings->vat_number = 'DE923356489';
$settings->id_number = '991-00110-12';
$settings->country_id = '276';
$settings->currency_id = '3';
@ -301,8 +302,6 @@ class PeppolTest extends TestCase
$peppol->setInvoiceDefaults();
$peppol->run();
// $peppol->toJson()->toXml();
$de_invoice = $peppol->getInvoice();
$this->assertNotNull($de_invoice);
@ -311,7 +310,6 @@ class PeppolTest extends TestCase
$xml = $e->encode($de_invoice, 'xml');
$this->assertNotNull($xml);
$errors = $e->validate($de_invoice);
if(count($errors) > 0) {
@ -322,17 +320,6 @@ class PeppolTest extends TestCase
$xml = $peppol->toXml();
$cen = base_path('/tests/Feature/EInvoice/Validation/CEN-EN16931-UBL.xslt');
$pep = base_path('/tests/Feature/EInvoice/Validation/PEPPOL-EN16931-UBL.xslt');
$stylesheet = base_path('/tests/Feature/EInvoice/Validation/stylesheet.xslt');
$peppol_stylesheet = base_path('/tests/Feature/EInvoice/Validation/peppol.xslt');
$pep_test = base_path('tests/Feature/EInvoice/Validation/peppol_test.xml');
$pschema = base_path('tests/Feature/EInvoice/Validation/PEPPOL-EN16931-UBL.sch');
$validator = new XsltDocumentValidator($xml);
$validator->validate();
@ -340,89 +327,6 @@ class PeppolTest extends TestCase
$this->assertCount(0, $validator->getErrors());
// try{
// $processor = new \Saxon\SaxonProcessor();
// $f = file_get_contents($pep_test);
// $xmlFile = $f;
// // $xslt = file_get_contents($cen);
// $schematronFile = base_path('tests/Feature/EInvoice/Validation/PEPPOL-EN16931-UBL.sch');
// $xslt = $processor->newXslt30Processor(); // Changed to newXsltProcessor
// $x = $xslt->compileFromFile($pep);
// $result = $x->transformFileToString($pep_test);
// nlog($result);
// $x = $xslt->compileFromFile($cen);
// $result = $x->transformFileToString($pep_test);
// $y = $x->transformFileToValue($pep_test);
// nlog($result);
// nlog($y);
// // $result = $xslt->transformFileToString($pep_test, $peppol_stylesheet); //output to strings
// // nlog("success");
// nlog($result);
// // nlog($result->getErrorMessage());
// } catch (Exception $e) {
// nlog([
// 'valid' => false,
// 'message' => $e->getMessage()
// ]);
// }
// try {
// $xslt = $processor->newXslt30Processor();
// // $xslt->compileFromFile($cen); // Changed to compileFromString since we have the file content
// // Attempt transformation to validate
// $result = $xslt->transformFileToString($xml,$cen);
// nlog([
// 'valid' => true,
// 'message' => 'XSLT is valid'
// ]);
// } catch (Exception $e) {
// nlog([
// 'valid' => false,
// 'message' => $e->getMessage()
// ]);
// }
// try {
// $xslt = $processor->newXslt30Processor(); // Changed to newXsltProcessor
// $xslt->compileFromString($cen);
// // Attempt transformation to validate
// $result = $xslt->transformFileToString($xml);
// nlog([
// 'valid' => true,
// 'message' => 'XSLT is valid'
// ]);
// } catch (Exception $e) {
// nlog([
// 'valid' => false,
// 'message' => $e->getMessage()
// ]);
// }
}