mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Storecove
This commit is contained in:
parent
68b7264c74
commit
5698c59322
@ -44,7 +44,7 @@ class AllowanceCharges
|
|||||||
?string $base_amount_excluding_tax,
|
?string $base_amount_excluding_tax,
|
||||||
?string $amount_including_tax,
|
?string $amount_including_tax,
|
||||||
?string $base_amount_including_tax,
|
?string $base_amount_including_tax,
|
||||||
?Tax $tax,
|
// ?Tax $tax,
|
||||||
?array $taxes_duties_fees,
|
?array $taxes_duties_fees,
|
||||||
?string $reason,
|
?string $reason,
|
||||||
?string $reason_code
|
?string $reason_code
|
||||||
@ -85,11 +85,6 @@ class AllowanceCharges
|
|||||||
return $this->base_amount_including_tax;
|
return $this->base_amount_including_tax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTax(): ?Tax
|
|
||||||
{
|
|
||||||
return $this->tax;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TaxesDutiesFees[]
|
* @return TaxesDutiesFees[]
|
||||||
*/
|
*/
|
||||||
@ -138,12 +133,6 @@ class AllowanceCharges
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTax(?Tax $tax): self
|
|
||||||
{
|
|
||||||
$this->tax = $tax;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TaxesDutiesFees[] $taxes_duties_fees
|
* @param TaxesDutiesFees[] $taxes_duties_fees
|
||||||
*/
|
*/
|
||||||
|
@ -2,11 +2,20 @@
|
|||||||
|
|
||||||
namespace App\Services\EDocument\Gateway\Storecove\Models;
|
namespace App\Services\EDocument\Gateway\Storecove\Models;
|
||||||
|
|
||||||
|
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||||
|
use Symfony\Component\Serializer\Attribute\SerializedPath;
|
||||||
|
|
||||||
class Contact
|
class Contact
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#[SerializedPath('[cbc:Name]')]
|
||||||
public ?string $first_name;
|
public ?string $first_name;
|
||||||
public ?string $last_name;
|
public ?string $last_name;
|
||||||
|
|
||||||
|
#[SerializedPath('[cbc:ElectronicMail]')]
|
||||||
public ?string $email;
|
public ?string $email;
|
||||||
|
|
||||||
|
#[SerializedPath('[cbc:Telephone]')]
|
||||||
public ?string $phone;
|
public ?string $phone;
|
||||||
public ?string $id;
|
public ?string $id;
|
||||||
|
|
||||||
|
@ -13,10 +13,10 @@ class Invoice
|
|||||||
#[SerializedPath('[cbc:ID][#]')]
|
#[SerializedPath('[cbc:ID][#]')]
|
||||||
public $invoice_number;
|
public $invoice_number;
|
||||||
|
|
||||||
/** @var ?\DateTime */
|
// /** @var ?\DateTime */
|
||||||
#[SerializedPath('[cbc:IssueDate]')]
|
#[SerializedPath('[cbc:IssueDate]')]
|
||||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
// #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||||
public ?DateTime $issue_date;
|
public $issue_date;
|
||||||
|
|
||||||
#[SerializedPath('[cac:AccountingCustomerParty]')]
|
#[SerializedPath('[cac:AccountingCustomerParty]')]
|
||||||
/** @var ?AccountingCustomerParty */
|
/** @var ?AccountingCustomerParty */
|
||||||
@ -64,10 +64,10 @@ class Invoice
|
|||||||
#[SerializedPath('[cbc:DocumentCurrencyCode][#]')]
|
#[SerializedPath('[cbc:DocumentCurrencyCode][#]')]
|
||||||
public $document_currency_code;
|
public $document_currency_code;
|
||||||
|
|
||||||
/** @var ?\DateTime */
|
// /** @var ?\DateTime */
|
||||||
#[SerializedPath('[cbc:DueDate]')]
|
#[SerializedPath('[cbc:DueDate]')]
|
||||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
// #[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||||
public ?DateTime $due_date;
|
public $due_date;
|
||||||
|
|
||||||
//may need something custom for this
|
//may need something custom for this
|
||||||
public ?string $invoice_period;
|
public ?string $invoice_period;
|
||||||
@ -117,7 +117,6 @@ class Invoice
|
|||||||
/** @var TaxSubtotals[] */
|
/** @var TaxSubtotals[] */
|
||||||
public $tax_subtotals;
|
public $tax_subtotals;
|
||||||
|
|
||||||
/** @var InvoiceLines[] */
|
|
||||||
//storecove - no mappings - tax_line_percentages
|
//storecove - no mappings - tax_line_percentages
|
||||||
public ?string $tax_system;
|
public ?string $tax_system;
|
||||||
|
|
||||||
@ -165,11 +164,9 @@ class Invoice
|
|||||||
#[SerializedPath('[cac:ProjectReference][cbc:ID][#]')]
|
#[SerializedPath('[cac:ProjectReference][cbc:ID][#]')]
|
||||||
public ?string $project_reference;
|
public ?string $project_reference;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
?string $invoice_number,
|
?string $invoice_number,
|
||||||
?DateTime $issue_date,
|
$issue_date,
|
||||||
?AccountingCustomerParty $accounting_customer_party,
|
?AccountingCustomerParty $accounting_customer_party,
|
||||||
?array $invoice_lines,
|
?array $invoice_lines,
|
||||||
?string $accounting_cost,
|
?string $accounting_cost,
|
||||||
@ -186,7 +183,7 @@ class Invoice
|
|||||||
?Delivery $delivery,
|
?Delivery $delivery,
|
||||||
?DeliveryTerms $delivery_terms,
|
?DeliveryTerms $delivery_terms,
|
||||||
?string $document_currency_code,
|
?string $document_currency_code,
|
||||||
?DateTime $due_date,
|
$due_date,
|
||||||
?string $invoice_period,
|
?string $invoice_period,
|
||||||
?array $issue_reasons,
|
?array $issue_reasons,
|
||||||
?string $issue_time,
|
?string $issue_time,
|
||||||
@ -376,7 +373,7 @@ class Invoice
|
|||||||
return $this->document_currency_code;
|
return $this->document_currency_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDueDate(): ?string
|
public function getDueDate()
|
||||||
{
|
{
|
||||||
return $this->due_date;
|
return $this->due_date;
|
||||||
}
|
}
|
||||||
@ -575,7 +572,7 @@ class Invoice
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIssueDate(?string $issue_date): self
|
public function setIssueDate($issue_date): self
|
||||||
{
|
{
|
||||||
$this->issue_date = $issue_date;
|
$this->issue_date = $issue_date;
|
||||||
return $this;
|
return $this;
|
||||||
@ -686,7 +683,7 @@ class Invoice
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDueDate(?string $due_date): self
|
public function setDueDate($due_date): self
|
||||||
{
|
{
|
||||||
$this->due_date = $due_date;
|
$this->due_date = $due_date;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -206,11 +206,6 @@ class InvoiceLines
|
|||||||
return $this->amount_including_tax;
|
return $this->amount_including_tax;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTax(): ?Tax
|
|
||||||
{
|
|
||||||
return $this->tax;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return TaxesDutiesFees[]
|
* @return TaxesDutiesFees[]
|
||||||
*/
|
*/
|
||||||
@ -351,11 +346,6 @@ class InvoiceLines
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTax(?Tax $tax): self
|
|
||||||
{
|
|
||||||
$this->tax = $tax;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TaxesDutiesFees[] $taxes_duties_fees
|
* @param TaxesDutiesFees[] $taxes_duties_fees
|
||||||
|
@ -18,6 +18,7 @@ class Party
|
|||||||
#[SerializedPath('[cac:PostalAddress]')]
|
#[SerializedPath('[cac:PostalAddress]')]
|
||||||
public ?Address $address;
|
public ?Address $address;
|
||||||
|
|
||||||
|
#[SerializedPath('[cac:Contact]')]
|
||||||
public ?Contact $contact;
|
public ?Contact $contact;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
@ -30,14 +30,14 @@ class StorecoveTransformer implements TransformerInterface
|
|||||||
public function transform(mixed $invoice)
|
public function transform(mixed $invoice)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->s_invoice = new StorecoveInvoice();
|
$this->s_invoice = (new \ReflectionClass(StorecoveInvoice::class))->newInstanceWithoutConstructor();
|
||||||
|
|
||||||
$this->s_invoice->setDocumentCurrency($invoice->DocumentCurrencyCode ?? '');
|
// $this->s_invoice->setDocumentCurrency($invoice->DocumentCurrencyCode ?? '');
|
||||||
$this->s_invoice->setInvoiceNumber($invoice->ID ?? '');
|
// $this->s_invoice->setInvoiceNumber($invoice->ID ?? '');
|
||||||
$this->s_invoice->setIssueDate($invoice->IssueDate->format('Y-m-d'));
|
// $this->s_invoice->setIssueDate($invoice->IssueDate->format('Y-m-d'));
|
||||||
$this->s_invoice->setTaxPointDate($invoice->IssueDate->format('Y-m-d'));
|
$this->s_invoice->setTaxPointDate($invoice->IssueDate->format('Y-m-d'));
|
||||||
$this->s_invoice->setDueDate($invoice->DueDate->format('Y-m-d') ?? '');
|
$this->s_invoice->setDueDate($invoice->DueDate->format('Y-m-d') ?? '');
|
||||||
$this->s_invoice->setNote($invoice->Note ?? '');
|
// $this->s_invoice->setNote($invoice->Note ?? '');
|
||||||
|
|
||||||
// Only use this if we are billing for services between a period.
|
// Only use this if we are billing for services between a period.
|
||||||
if (isset($invoice->InvoicePeriod[0]) &&
|
if (isset($invoice->InvoicePeriod[0]) &&
|
||||||
@ -46,144 +46,99 @@ class StorecoveTransformer implements TransformerInterface
|
|||||||
$this->s_invoice->setInvoicePeriod("{$invoice->InvoicePeriod[0]->StartDate->format('Y-m-d')} - {$invoice->InvoicePeriod[0]->EndDate->format('Y-m-d')}");
|
$this->s_invoice->setInvoicePeriod("{$invoice->InvoicePeriod[0]->StartDate->format('Y-m-d')} - {$invoice->InvoicePeriod[0]->EndDate->format('Y-m-d')}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($invoice->BuyerReference ?? false){
|
// $supplier_contact = new Contact(
|
||||||
$ref = new References(documentId: $invoice->BuyerReference, documentType: 'buyer_reference');
|
// email: $invoice->AccountingSupplierParty->Party->Contact->ElectronicMail,
|
||||||
$this->s_invoice->addReferences($ref);
|
// firstName: $invoice->AccountingSupplierParty->Party->Contact->Name ?? null,
|
||||||
}
|
// phone: $invoice->AccountingSupplierParty->Party->Contact->Telephone ?? null,
|
||||||
|
// );
|
||||||
if ($invoice->OrderReference->ID ?? false) {
|
|
||||||
$ref = new References(documentId: $invoice->OrderReference->ID->value, documentType: 'sales_order');
|
|
||||||
$this->s_invoice->addReferences($ref);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($invoice->AccountingCostCode ?? false){
|
// $supplier_party = new Party(contact: $supplier_contact);
|
||||||
$this->s_invoice->setAccountingCost($invoice->AccountingCostCode);
|
// $asp = new AccountingSupplierParty($supplier_party);
|
||||||
}
|
// $this->s_invoice->setAccountingSupplierParty($asp);
|
||||||
|
|
||||||
$customer_company_name = $invoice->AccountingCustomerParty->Party->PartyName[0]->Name ?? '';
|
|
||||||
|
|
||||||
$address = new Address(
|
|
||||||
street1: $invoice->AccountingCustomerParty->Party->PostalAddress->StreetName,
|
|
||||||
street2: $invoice->AccountingCustomerParty->Party->PostalAddress->AdditionalStreetName ?? null,
|
|
||||||
city: $invoice->AccountingCustomerParty->Party->PostalAddress->CityName,
|
|
||||||
zip: $invoice->AccountingCustomerParty->Party->PostalAddress->PostalZone,
|
|
||||||
county: $invoice->AccountingCustomerParty->Party->PostalAddress->CountrySubentity ?? null,
|
|
||||||
country: $invoice->AccountingCustomerParty->Party->PostalAddress->Country->IdentificationCode->value,
|
|
||||||
);
|
|
||||||
|
|
||||||
$contact = new Contact(
|
|
||||||
email: $invoice->AccountingCustomerParty->Party->Contact->ElectronicMail,
|
|
||||||
firstName: $invoice->AccountingCustomerParty->Party->Contact->Name ?? null,
|
|
||||||
phone: $invoice->AccountingCustomerParty->Party->Contact->Telephone ?? null,
|
|
||||||
);
|
|
||||||
|
|
||||||
$customer_party = new Party(companyName: $customer_company_name, address: $address, contact: $contact);
|
|
||||||
$party_identifiers = []; // do this outside the transformer.
|
|
||||||
$acp = new AccountingCustomerParty($party_identifiers, $customer_party);
|
|
||||||
$this->s_invoice->setAccountingCustomerParty($acp);
|
|
||||||
|
|
||||||
|
|
||||||
$supplier_contact = new Contact(
|
|
||||||
email: $invoice->AccountingSupplierParty->Party->Contact->ElectronicMail,
|
|
||||||
firstName: $invoice->AccountingSupplierParty->Party->Contact->Name ?? null,
|
|
||||||
phone: $invoice->AccountingSupplierParty->Party->Contact->Telephone ?? null,
|
|
||||||
);
|
|
||||||
|
|
||||||
$supplier_party = new Party(contact: $supplier_contact);
|
|
||||||
$asp = new AccountingSupplierParty($supplier_party);
|
|
||||||
$this->s_invoice->setAccountingSupplierParty($asp);
|
|
||||||
|
|
||||||
if (isset($invoice->PaymentMeans[0])) {
|
|
||||||
|
|
||||||
$payment_means = new PaymentMeans();
|
|
||||||
$payment_means->setCodeProps($invoice->PaymentMeans[0]);
|
|
||||||
|
|
||||||
$this->s_invoice->addPaymentMeans($payment_means);
|
|
||||||
}
|
|
||||||
|
|
||||||
$lines = [];
|
$lines = [];
|
||||||
|
|
||||||
foreach($invoice->InvoiceLine as $peppolLine)
|
// foreach($invoice->InvoiceLine as $peppolLine)
|
||||||
{
|
// {
|
||||||
|
|
||||||
$line = new InvoiceLines();
|
// $line = (new \ReflectionClass(InvoiceLines::class))->newInstanceWithoutConstructor();
|
||||||
|
|
||||||
// Basic line details
|
// // Basic line details
|
||||||
$line->setLineId($peppolLine->ID->value);
|
// $line->setLineId($peppolLine->ID->value);
|
||||||
$line->setQuantity((int)$peppolLine->InvoicedQuantity->amount);
|
// $line->setQuantity((int)$peppolLine->InvoicedQuantity->amount);
|
||||||
$line->setItemPrice((float)$peppolLine->Price->PriceAmount->amount);
|
// $line->setItemPrice((float)$peppolLine->Price->PriceAmount->amount);
|
||||||
$line->setAmountExcludingVat((float)$peppolLine->LineExtensionAmount->amount);
|
// $line->setAmountExcludingVat((float)$peppolLine->LineExtensionAmount->amount);
|
||||||
|
|
||||||
// Item details
|
// // Item details
|
||||||
$line->setName($peppolLine->Item->Name);
|
// $line->setName($peppolLine->Item->Name);
|
||||||
$line->setDescription($peppolLine->Item->Description);
|
// $line->setDescription($peppolLine->Item->Description);
|
||||||
|
|
||||||
// Tax handling
|
// // Tax handling
|
||||||
if(isset($peppolLine->Item->ClassifiedTaxCategory) && is_array($peppolLine->Item->ClassifiedTaxCategory)){
|
// if(isset($peppolLine->Item->ClassifiedTaxCategory) && is_array($peppolLine->Item->ClassifiedTaxCategory)){
|
||||||
foreach($peppolLine->Item->ClassifiedTaxCategory as $ctc)
|
// foreach($peppolLine->Item->ClassifiedTaxCategory as $ctc)
|
||||||
{
|
// {
|
||||||
$this->setTaxMap($ctc, $peppolLine, $invoice);
|
// $this->setTaxMap($ctc, $peppolLine, $invoice);
|
||||||
$tax = new Tax((float)$ctc->Percent, $this->resolveJurisdication($ctc, $invoice));
|
// $tax = new Tax((float)$ctc->Percent, $this->resolveJurisdication($ctc, $invoice));
|
||||||
$line->setTax($tax);
|
// $line->setTax($tax);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
//discounts
|
// //discounts
|
||||||
if(isset($peppolLine->Price->AllowanceCharge) && is_array($peppolLine->Price->AllowanceCharge)){
|
// if(isset($peppolLine->Price->AllowanceCharge) && is_array($peppolLine->Price->AllowanceCharge)){
|
||||||
|
|
||||||
foreach($peppolLine->Price->AllowanceCharge as $allowance)
|
// foreach($peppolLine->Price->AllowanceCharge as $allowance)
|
||||||
{
|
// {
|
||||||
$reason = isset($allowance->ChargeIndicator) ? ctrans('texts.discount') : ctrans('texts.fee');
|
// $reason = isset($allowance->ChargeIndicator) ? ctrans('texts.discount') : ctrans('texts.fee');
|
||||||
$amount = $allowance->Amount->amount;
|
// $amount = $allowance->Amount->amount;
|
||||||
|
|
||||||
$ac = new AllowanceCharges(reason: $reason, amountExcludingTax: $amount);
|
// $ac = new AllowanceCharges(reason: $reason, amountExcludingTax: $amount);
|
||||||
$line->addAllowanceCharge($ac);
|
// $line->addAllowanceCharge($ac);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
$lines[] = $line;
|
// $lines[] = $line;
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
$this->s_invoice->invoiceLines = $lines;
|
// $this->s_invoice->invoiceLines = $lines;
|
||||||
|
|
||||||
//invoice level discounts + surcharges
|
// //invoice level discounts + surcharges
|
||||||
if(isset($peppolLine->AllowanceCharge) && is_array($peppolLine->AllowanceCharge)){
|
// if(isset($peppolLine->AllowanceCharge) && is_array($peppolLine->AllowanceCharge)){
|
||||||
|
|
||||||
foreach ($peppolLine->AllowanceCharge as $allowance)
|
// foreach ($peppolLine->AllowanceCharge as $allowance)
|
||||||
{
|
// {
|
||||||
|
|
||||||
$reason = $allowance->ChargeIndicator ? ctrans('texts.fee') : ctrans('texts.discount');
|
// $reason = $allowance->ChargeIndicator ? ctrans('texts.fee') : ctrans('texts.discount');
|
||||||
$amount = $allowance->Amount->amount;
|
// $amount = $allowance->Amount->amount;
|
||||||
|
|
||||||
$ac = new AllowanceCharges(reason: $reason, amountExcludingTax: $amount);
|
// $ac = new AllowanceCharges(reason: $reason, amountExcludingTax: $amount);
|
||||||
$this->s_invoice->addAllowanceCharge($ac); //todo handle surcharge taxes
|
// $this->s_invoice->addAllowanceCharge($ac); //todo handle surcharge taxes
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
collect($this->tax_map)
|
// collect($this->tax_map)
|
||||||
->groupBy('percentage')
|
// ->groupBy('percentage')
|
||||||
->each(function ($group) {
|
// ->each(function ($group) {
|
||||||
|
|
||||||
$taxSubtotals = new TaxSubtotals(
|
// $taxSubtotals = new TaxSubtotals(
|
||||||
taxableAmount: $group->sum('taxableAmount'),
|
// taxableAmount: $group->sum('taxableAmount'),
|
||||||
taxAmount: $group->sum('taxAmount'),
|
// taxAmount: $group->sum('taxAmount'),
|
||||||
percentage: $group->first()['percentage'],
|
// percentage: $group->first()['percentage'],
|
||||||
country: $group->first()['country']
|
// country: $group->first()['country']
|
||||||
);
|
// );
|
||||||
|
|
||||||
$this->s_invoice->addTaxSubtotals($taxSubtotals);
|
// $this->s_invoice->addTaxSubtotals($taxSubtotals);
|
||||||
|
|
||||||
|
|
||||||
});
|
// });
|
||||||
|
|
||||||
$this->s_invoice->setAmountIncludingVat($invoice->LegalMonetaryTotal->TaxInclusiveAmount->amount);
|
// $this->s_invoice->setAmountIncludingVat($invoice->LegalMonetaryTotal->TaxInclusiveAmount->amount);
|
||||||
$this->s_invoice->setPrepaidAmount(0);
|
// $this->s_invoice->setPrepaidAmount(0);
|
||||||
|
|
||||||
return $this->s_invoice;
|
// return $this->s_invoice;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,21 +31,20 @@ use App\Services\EDocument\Gateway\Storecove\Storecove;
|
|||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
|
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
|
||||||
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
|
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
|
||||||
|
|
||||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||||
|
|
||||||
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
|
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
|
||||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||||
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
|
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
|
||||||
use InvoiceNinja\EInvoice\Models\Peppol\Invoice as PeppolInvoice;
|
use InvoiceNinja\EInvoice\Models\Peppol\Invoice as PeppolInvoice;
|
||||||
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
|
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
|
||||||
|
use App\Services\EDocument\Gateway\Transformers\StorecoveTransformer;
|
||||||
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
||||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
||||||
use App\Services\EDocument\Gateway\Storecove\PeppolToStorecoveNormalizer;
|
use App\Services\EDocument\Gateway\Storecove\PeppolToStorecoveNormalizer;
|
||||||
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
|
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
|
||||||
use App\Services\EDocument\Gateway\Storecove\Models\Invoice as StorecoveInvoice;
|
use App\Services\EDocument\Gateway\Storecove\Models\Invoice as StorecoveInvoice;
|
||||||
use App\Services\EDocument\Gateway\Transformers\StorecoveTransformer;
|
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
|
||||||
|
|
||||||
class StorecoveTest extends TestCase
|
class StorecoveTest extends TestCase
|
||||||
{
|
{
|
||||||
@ -65,79 +64,155 @@ class StorecoveTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTransformPeppolToStorecove()
|
||||||
public function testNormalizingToStorecove()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
$e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
|
$phpDocExtractor = new PhpDocExtractor();
|
||||||
|
$reflectionExtractor = new ReflectionExtractor();
|
||||||
|
// list of PropertyListExtractorInterface (any iterable)
|
||||||
|
$typeExtractors = [$reflectionExtractor,$phpDocExtractor];
|
||||||
|
// list of PropertyDescriptionExtractorInterface (any iterable)
|
||||||
|
$descriptionExtractors = [$phpDocExtractor];
|
||||||
|
// list of PropertyAccessExtractorInterface (any iterable)
|
||||||
|
$propertyInitializableExtractors = [$reflectionExtractor];
|
||||||
|
$propertyInfo = new PropertyInfoExtractor(
|
||||||
|
$propertyInitializableExtractors,
|
||||||
|
$descriptionExtractors,
|
||||||
|
$typeExtractors,
|
||||||
|
);
|
||||||
|
$xml_encoder = new XmlEncoder(['xml_format_output' => true, 'remove_empty_tags' => true,]);
|
||||||
|
$json_encoder = new JsonEncoder();
|
||||||
|
|
||||||
$invoice = $this->createATData();
|
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
|
||||||
|
$metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
|
||||||
|
|
||||||
$stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}');
|
$normalizer = new ObjectNormalizer($classMetadataFactory, $metadataAwareNameConverter, null, $propertyInfo);
|
||||||
foreach ($stub as $key => $value) {
|
|
||||||
$e_invoice->{$key} = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$invoice->e_invoice = $e_invoice;
|
$normalizers = [new DateTimeNormalizer(), $normalizer, new ArrayDenormalizer()];
|
||||||
|
$encoders = [$xml_encoder, $json_encoder];
|
||||||
|
$serializer = new Serializer($normalizers, $encoders);
|
||||||
|
|
||||||
$p = new Peppol($invoice);
|
$context = [
|
||||||
$p->run();
|
DateTimeNormalizer::FORMAT_KEY => 'Y-m-d',
|
||||||
$peppolInvoice = $p->getInvoice();
|
AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
$p = file_get_contents(base_path('tests/Integration/Einvoice/samples/peppol.xml'));
|
||||||
|
|
||||||
$s_transformer = new StorecoveTransformer();
|
$e = new \InvoiceNinja\EInvoice\EInvoice();
|
||||||
$s_transformer->transform($peppolInvoice);
|
$peppolInvoice = $e->decode('Peppol', $p, 'xml');
|
||||||
|
|
||||||
$json = $s_transformer->toJson();
|
$this->assertInstanceOf(\InvoiceNinja\EInvoice\Models\Peppol\Invoice::class, $peppolInvoice);
|
||||||
|
|
||||||
$this->assertJson($json);
|
$parent = \App\Services\EDocument\Gateway\Storecove\Models\Invoice::class;
|
||||||
|
// $peppolInvoice = $e->encode($peppolInvoice, 'json');
|
||||||
|
|
||||||
|
$peppolInvoice = $data = $e->encode($peppolInvoice, 'json', $context);
|
||||||
|
|
||||||
|
$invoice = $serializer->deserialize($peppolInvoice, $parent, 'json', $context);
|
||||||
|
|
||||||
|
$this->assertInstanceOf($parent, $invoice);
|
||||||
|
|
||||||
|
$s_invoice = $serializer->encode($invoice, 'json', $context);
|
||||||
|
|
||||||
|
$arr = json_decode($s_invoice, true);
|
||||||
|
|
||||||
|
$arr = $this->removeEmptyValues($arr);
|
||||||
|
|
||||||
|
nlog($arr);
|
||||||
|
|
||||||
nlog($json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStorecoveTransformer()
|
|
||||||
|
private function removeEmptyValues(array $array): array
|
||||||
{
|
{
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
$e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
|
if (is_array($value)) {
|
||||||
|
$array[$key] = $this->removeEmptyValues($value);
|
||||||
$invoice = $this->createATData();
|
if (empty($array[$key])) {
|
||||||
|
unset($array[$key]);
|
||||||
$item = new InvoiceItem();
|
}
|
||||||
$item->product_key = "Product Key";
|
} elseif ($value === null || $value === '') {
|
||||||
$item->notes = "Product Description";
|
unset($array[$key]);
|
||||||
$item->cost = 10;
|
}
|
||||||
$item->quantity = 10;
|
}
|
||||||
$item->is_amount_discount = true;
|
// nlog($array);
|
||||||
$item->discount=5;
|
return $array;
|
||||||
$item->tax_rate1 = 20;
|
|
||||||
$item->tax_name1 = 'VAT';
|
|
||||||
|
|
||||||
$invoice->line_items = [$item];
|
|
||||||
$invoice->calc()->getInvoice();
|
|
||||||
|
|
||||||
$stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}');
|
|
||||||
foreach ($stub as $key => $value) {
|
|
||||||
$e_invoice->{$key} = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$invoice->e_invoice = $e_invoice;
|
|
||||||
|
|
||||||
$p = new Peppol($invoice);
|
|
||||||
$p->run();
|
|
||||||
$peppolInvoice = $p->getInvoice();
|
|
||||||
|
|
||||||
|
|
||||||
$s_transformer = new StorecoveTransformer();
|
|
||||||
$s_transformer->transform($peppolInvoice);
|
|
||||||
|
|
||||||
$json = $s_transformer->toJson();
|
|
||||||
|
|
||||||
$this->assertJson($json);
|
|
||||||
|
|
||||||
nlog($json);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// public function testNormalizingToStorecove()
|
||||||
|
// {
|
||||||
|
|
||||||
|
// $e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
|
||||||
|
|
||||||
|
// $invoice = $this->createATData();
|
||||||
|
|
||||||
|
// $stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}');
|
||||||
|
// foreach ($stub as $key => $value) {
|
||||||
|
// $e_invoice->{$key} = $value;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $invoice->e_invoice = $e_invoice;
|
||||||
|
|
||||||
|
// $p = new Peppol($invoice);
|
||||||
|
// $p->run();
|
||||||
|
// $peppolInvoice = $p->getInvoice();
|
||||||
|
|
||||||
|
|
||||||
|
// $s_transformer = new StorecoveTransformer();
|
||||||
|
// $s_transformer->transform($peppolInvoice);
|
||||||
|
|
||||||
|
// $json = $s_transformer->toJson();
|
||||||
|
|
||||||
|
// $this->assertJson($json);
|
||||||
|
|
||||||
|
// nlog($json);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function testStorecoveTransformer()
|
||||||
|
// {
|
||||||
|
|
||||||
|
// $e_invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
|
||||||
|
|
||||||
|
// $invoice = $this->createATData();
|
||||||
|
|
||||||
|
// $item = new InvoiceItem();
|
||||||
|
// $item->product_key = "Product Key";
|
||||||
|
// $item->notes = "Product Description";
|
||||||
|
// $item->cost = 10;
|
||||||
|
// $item->quantity = 10;
|
||||||
|
// $item->is_amount_discount = true;
|
||||||
|
// $item->discount=5;
|
||||||
|
// $item->tax_rate1 = 20;
|
||||||
|
// $item->tax_name1 = 'VAT';
|
||||||
|
|
||||||
|
// $invoice->line_items = [$item];
|
||||||
|
// $invoice->calc()->getInvoice();
|
||||||
|
|
||||||
|
// $stub = json_decode('{"Invoice":{"Note":"Nooo","PaymentMeans":[{"ID":{"value":"afdasfasdfasdfas"},"PayeeFinancialAccount":{"Name":"PFA-NAME","ID":{"value":"DE89370400440532013000"},"AliasName":"PFA-Alias","AccountTypeCode":{"value":"CHECKING"},"AccountFormatCode":{"value":"IBAN"},"CurrencyCode":{"value":"EUR"},"FinancialInstitutionBranch":{"ID":{"value":"DEUTDEMMXXX"},"Name":"Deutsche Bank"}}}]}}');
|
||||||
|
// foreach ($stub as $key => $value) {
|
||||||
|
// $e_invoice->{$key} = $value;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// $invoice->e_invoice = $e_invoice;
|
||||||
|
|
||||||
|
// $p = new Peppol($invoice);
|
||||||
|
// $p->run();
|
||||||
|
// $peppolInvoice = $p->getInvoice();
|
||||||
|
|
||||||
|
|
||||||
|
// $s_transformer = new StorecoveTransformer();
|
||||||
|
// $s_transformer->transform($peppolInvoice);
|
||||||
|
|
||||||
|
// $json = $s_transformer->toJson();
|
||||||
|
|
||||||
|
// $this->assertJson($json);
|
||||||
|
|
||||||
|
// nlog($json);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
public function testStorecoveTransformerWithPercentageDiscount()
|
public function testStorecoveTransformerWithPercentageDiscount()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user