additional logging

This commit is contained in:
David Bomba 2024-10-25 17:51:01 +11:00
parent 77f93f8bdd
commit ab2b5438e8
11 changed files with 423 additions and 151 deletions

View File

@ -1 +1 @@
5.10.42 5.10.43

View File

@ -63,6 +63,9 @@ class SelfUpdateController extends BaseController
$file_headers = @get_headers($this->getDownloadUrl()); $file_headers = @get_headers($this->getDownloadUrl());
nlog("Download URL");
nlog($this->getDownloadUrl());
if(!is_array($file_headers)) { if(!is_array($file_headers)) {
nlog($file_headers); nlog($file_headers);
return response()->json(['message' => 'There was a problem reaching the update server, please try again in a little while.'], 410); return response()->json(['message' => 'There was a problem reaching the update server, please try again in a little while.'], 410);

View File

@ -1,92 +1,171 @@
<?php <?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\EDocument\Gateway\Storecove\Models; namespace App\Services\EDocument\Gateway\Storecove\Models;
class Invoice use JsonSerializable;
use Symfony\Component\Serializer\Annotation\SerializedName;
use DateTime;
class Invoice implements JsonSerializable
{ {
public string $taxSystem; #[SerializedName('taxSystem')]
public string $documentCurrency; private string $taxSystem = 'tax_line_percentages';
public string $invoiceNumber;
public string $issueDate; #[SerializedName('documentCurrency')]
public string $taxPointDate; private string $documentCurrency = '';
public string $dueDate;
public string $invoicePeriod; #[SerializedName('invoiceNumber')]
/** @var References[] */ private string $invoiceNumber = '';
public array $references;
public string $accountingCost; #[SerializedName('issueDate')]
public string $note; private DateTime $issueDate;
public AccountingSupplierParty $accountingSupplierParty;
public AccountingCustomerParty $accountingCustomerParty; #[SerializedName('taxPointDate')]
public Delivery $delivery; private ?DateTime $taxPointDate = null;
public PaymentTerms $paymentTerms;
/** @var PaymentMeansArray[] */ #[SerializedName('dueDate')]
public array $paymentMeansArray; private DateTime $dueDate;
/** @var InvoiceLines[] */
public array $invoiceLines; #[SerializedName('invoicePeriod')]
/** @var AllowanceCharges[] */ private array $invoicePeriod = [];
public array $allowanceCharges;
/** @var TaxSubtotals[] */ #[SerializedName('references')]
public array $taxSubtotals; private array $references = [];
public float $amountIncludingVat;
public int $prepaidAmount; #[SerializedName('accountingCost')]
private ?string $accountingCost = null;
#[SerializedName('note')]
private string $note = '';
#[SerializedName('amountIncludingVat')]
private float $amountIncludingVat = 0.0;
#[SerializedName('prepaidAmount')]
private ?float $prepaidAmount = null;
#[SerializedName('accountingSupplierParty')]
private array $accountingSupplierParty = [];
#[SerializedName('accountingCustomerParty')]
private array $accountingCustomerParty = [];
#[SerializedName('paymentMeans')]
private array $paymentMeans = [];
#[SerializedName('taxTotal')]
private array $taxTotal = [];
/** /**
* @param References[] $references * @var InvoiceLines[]
* @param PaymentMeansArray[] $paymentMeansArray
* @param InvoiceLines[] $invoiceLines
* @param AllowanceCharges[] $allowanceCharges
* @param TaxSubtotals[] $taxSubtotals
*/ */
public function __construct( private array $invoiceLines = [];
string $taxSystem,
string $documentCurrency, // Getters and setters for all properties
string $invoiceNumber,
string $issueDate, public function setDocumentCurrency(string $documentCurrency): void
string $taxPointDate, {
string $dueDate,
string $invoicePeriod,
array $references,
string $accountingCost,
string $note,
AccountingSupplierParty $accountingSupplierParty,
AccountingCustomerParty $accountingCustomerParty,
Delivery $delivery,
PaymentTerms $paymentTerms,
array $paymentMeansArray,
array $invoiceLines,
array $allowanceCharges,
array $taxSubtotals,
float $amountIncludingVat,
int $prepaidAmount
) {
$this->taxSystem = $taxSystem;
$this->documentCurrency = $documentCurrency; $this->documentCurrency = $documentCurrency;
}
public function setInvoiceNumber(string $invoiceNumber): void
{
$this->invoiceNumber = $invoiceNumber; $this->invoiceNumber = $invoiceNumber;
}
public function setIssueDate(DateTime $issueDate): void
{
$this->issueDate = $issueDate; $this->issueDate = $issueDate;
}
public function setTaxPointDate(?DateTime $taxPointDate): void
{
$this->taxPointDate = $taxPointDate; $this->taxPointDate = $taxPointDate;
}
public function setDueDate(DateTime $dueDate): void
{
$this->dueDate = $dueDate; $this->dueDate = $dueDate;
}
public function setInvoicePeriod(array $invoicePeriod): void
{
$this->invoicePeriod = $invoicePeriod; $this->invoicePeriod = $invoicePeriod;
}
public function setReferences(array $references): void
{
$this->references = $references; $this->references = $references;
}
public function setAccountingCost(?string $accountingCost): void
{
$this->accountingCost = $accountingCost; $this->accountingCost = $accountingCost;
}
public function setNote(string $note): void
{
$this->note = $note; $this->note = $note;
$this->accountingSupplierParty = $accountingSupplierParty; }
$this->accountingCustomerParty = $accountingCustomerParty;
$this->delivery = $delivery; public function setAmountIncludingVat(float $amountIncludingVat): void
$this->paymentTerms = $paymentTerms; {
$this->paymentMeansArray = $paymentMeansArray;
$this->invoiceLines = $invoiceLines;
$this->allowanceCharges = $allowanceCharges;
$this->taxSubtotals = $taxSubtotals;
$this->amountIncludingVat = $amountIncludingVat; $this->amountIncludingVat = $amountIncludingVat;
}
public function setPrepaidAmount(?float $prepaidAmount): void
{
$this->prepaidAmount = $prepaidAmount; $this->prepaidAmount = $prepaidAmount;
} }
public function setAccountingSupplierParty(array $accountingSupplierParty): void
{
$this->accountingSupplierParty = $accountingSupplierParty;
}
public function setAccountingCustomerParty(array $accountingCustomerParty): void
{
$this->accountingCustomerParty = $accountingCustomerParty;
}
public function setPaymentMeans(array $paymentMeans): void
{
$this->paymentMeans = $paymentMeans;
}
public function setTaxTotal(array $taxTotal): void
{
$this->taxTotal = $taxTotal;
}
/**
* @param InvoiceLines[] $invoiceLines
*/
public function setInvoiceLines(array $invoiceLines): void
{
$this->invoiceLines = $invoiceLines;
}
public function jsonSerialize(): mixed
{
return [
'taxSystem' => $this->taxSystem,
'documentCurrency' => $this->documentCurrency,
'invoiceNumber' => $this->invoiceNumber,
'issueDate' => $this->issueDate->format('Y-m-d'),
'taxPointDate' => $this->taxPointDate ? $this->taxPointDate->format('Y-m-d') : null,
'dueDate' => $this->dueDate->format('Y-m-d'),
'invoicePeriod' => $this->invoicePeriod,
'references' => $this->references,
'accountingCost' => $this->accountingCost,
'note' => $this->note,
'amountIncludingVat' => $this->amountIncludingVat,
'prepaidAmount' => $this->prepaidAmount,
'accountingSupplierParty' => $this->accountingSupplierParty,
'accountingCustomerParty' => $this->accountingCustomerParty,
'paymentMeans' => $this->paymentMeans,
'taxTotal' => $this->taxTotal,
'invoiceLines' => $this->invoiceLines,
];
}
} }

View File

@ -1,77 +1,119 @@
<?php <?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\EDocument\Gateway\Storecove\Models; namespace App\Services\EDocument\Gateway\Storecove\Models;
use App\Services\EDocument\Gateway\Storecove\Models\Tax;
use Symfony\Component\Serializer\Annotation\SerializedName;
class InvoiceLines class InvoiceLines
{ {
public string $lineId; #[SerializedName('ID.value')]
public float $amountExcludingVat; public string $lineId = '';
public float $itemPrice;
public int $baseQuantity;
public int $quantity;
public string $quantityUnitCode;
/** @var AllowanceCharges[] */
public array $allowanceCharges;
public Tax $tax;
public string $orderLineReferenceLineId;
public string $accountingCost;
public string $name;
public string $description;
public string $invoicePeriod;
public string $note;
/** @var References[] */
public array $references;
/** @var AdditionalItemProperties[] */
public array $additionalItemProperties;
/** #[SerializedName('LineExtensionAmount.amount')]
* @param AllowanceCharges[] $allowanceCharges public float $amountExcludingVat = 0.0;
* @param References[] $references
* @param AdditionalItemProperties[] $additionalItemProperties #[SerializedName('Price.PriceAmount.amount')]
*/ public float $itemPrice = 0.0;
public function __construct(
string $lineId, #[SerializedName('InvoicedQuantity')]
float $amountExcludingVat, public int $quantity = 0;
float $itemPrice,
int $baseQuantity, #[SerializedName('InvoicedQuantity.unitCode')]
int $quantity, public string $quantityUnitCode = '';
string $quantityUnitCode,
array $allowanceCharges, #[SerializedName('Item.Name')]
Tax $tax, public string $name = '';
string $orderLineReferenceLineId,
string $accountingCost, #[SerializedName('Item.Description')]
string $name, public string $description = '';
string $description,
string $invoicePeriod, public Tax $tax;
string $note,
array $references, public function __construct()
array $additionalItemProperties {
) { $this->tax = new Tax();
}
// Getters and setters
public function getLineId(): string
{
return $this->lineId;
}
public function setLineId(string $lineId): void
{
$this->lineId = $lineId; $this->lineId = $lineId;
}
public function getAmountExcludingVat(): float
{
return $this->amountExcludingVat;
}
public function setAmountExcludingVat(float $amountExcludingVat): void
{
$this->amountExcludingVat = $amountExcludingVat; $this->amountExcludingVat = $amountExcludingVat;
}
public function getItemPrice(): float
{
return $this->itemPrice;
}
public function setItemPrice(float $itemPrice): void
{
$this->itemPrice = $itemPrice; $this->itemPrice = $itemPrice;
$this->baseQuantity = $baseQuantity; }
public function getQuantity(): int
{
return $this->quantity;
}
public function setQuantity(int $quantity): void
{
$this->quantity = $quantity; $this->quantity = $quantity;
}
public function getQuantityUnitCode(): string
{
return $this->quantityUnitCode;
}
public function setQuantityUnitCode(string $quantityUnitCode): void
{
$this->quantityUnitCode = $quantityUnitCode; $this->quantityUnitCode = $quantityUnitCode;
$this->allowanceCharges = $allowanceCharges; }
$this->tax = $tax;
$this->orderLineReferenceLineId = $orderLineReferenceLineId; public function getName(): string
$this->accountingCost = $accountingCost; {
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name; $this->name = $name;
}
public function getDescription(): string
{
return $this->description;
}
public function setDescription(string $description): void
{
$this->description = $description; $this->description = $description;
$this->invoicePeriod = $invoicePeriod; }
$this->note = $note;
$this->references = $references; public function getTax(): Tax
$this->additionalItemProperties = $additionalItemProperties; {
return $this->tax;
}
public function setTax(Tax $tax): void
{
$this->tax = $tax;
} }
} }

View File

@ -11,19 +11,61 @@
namespace App\Services\EDocument\Gateway\Storecove\Models; namespace App\Services\EDocument\Gateway\Storecove\Models;
use Symfony\Component\Serializer\Annotation\SerializedName;
class Tax class Tax
{ {
public int $percentage; #[SerializedName('Item.ClassifiedTaxCategory.0.Percent')]
public string $country; public float $taxPercentage = 0.0;
public string $category;
public function __construct( #[SerializedName('LineExtensionAmount.amount')]
int $percentage, public float $taxableAmount = 0.0;
string $country,
string $category #[SerializedName('TaxTotal.0.TaxAmount.amount')]
) { public float $taxAmount = 0.0;
$this->percentage = $percentage;
$this->country = $country; #[SerializedName('Item.ClassifiedTaxCategory.0.ID.value')]
$this->category = $category; public string $taxCategory = '';
// Getters and setters
public function getTaxPercentage(): float
{
return $this->taxPercentage;
}
public function setTaxPercentage(float $taxPercentage): void
{
$this->taxPercentage = $taxPercentage;
}
public function getTaxableAmount(): float
{
return $this->taxableAmount;
}
public function setTaxableAmount(float $taxableAmount): void
{
$this->taxableAmount = $taxableAmount;
}
public function getTaxAmount(): float
{
return $this->taxAmount;
}
public function setTaxAmount(float $taxAmount): void
{
$this->taxAmount = $taxAmount;
}
public function getTaxCategory(): string
{
return $this->taxCategory;
}
public function setTaxCategory(string $taxCategory): void
{
$this->taxCategory = $taxCategory;
} }
} }

View File

@ -896,6 +896,26 @@ class Peppol extends AbstractService
$party_name->Name = $this->invoice->company->present()->name(); $party_name->Name = $this->invoice->company->present()->name();
$party->PartyName[] = $party_name; $party->PartyName[] = $party_name;
if (strlen($this->company->settings->vat_number ?? '') > 1) {
$pi = new PartyIdentification();
$vatID = new ID();
if ($scheme = $this->resolveTaxScheme()) {
$vatID->schemeID = $scheme;
}
$vatID->value = $this->company->settings->vat_number; //todo if we are cross border - switch to the supplier local vat number
$pi->ID = $vatID;
$party->PartyIdentification[] = $pi;
}
$address = new Address(); $address = new Address();
$address->CityName = $this->invoice->company->settings->city; $address->CityName = $this->invoice->company->settings->city;
$address->StreetName = $this->invoice->company->settings->address1; $address->StreetName = $this->invoice->company->settings->address1;

View File

@ -88,7 +88,6 @@ class PdfService
*/ */
public function getPdf() public function getPdf()
{ {
try { try {
$pdf = $this->resolvePdfEngine($this->getHtml()); $pdf = $this->resolvePdfEngine($this->getHtml());

View File

@ -283,7 +283,6 @@ class TemplateService
*/ */
public function processData($data): self public function processData($data): self
{ {
$this->data = $this->preProcessDataBlocks($data); $this->data = $this->preProcessDataBlocks($data);
return $this; return $this;
@ -494,6 +493,7 @@ class TemplateService
*/ */
private function preProcessDataBlocks($data): array private function preProcessDataBlocks($data): array
{ {
return collect($data)->map(function ($value, $key) { return collect($data)->map(function ($value, $key) {
$processed = []; $processed = [];
@ -962,7 +962,8 @@ class TemplateService
'created_at' => $this->translateDate($task->created_at, $task->client ? $task->client->date_format() : $task->company->date_format(), $task->client ? $task->client->locale() : $task->company->locale()), 'created_at' => $this->translateDate($task->created_at, $task->client ? $task->client->date_format() : $task->company->date_format(), $task->client ? $task->client->locale() : $task->company->locale()),
'updated_at' => $this->translateDate($task->updated_at, $task->client ? $task->client->date_format() : $task->company->date_format(), $task->client ? $task->client->locale() : $task->company->locale()), 'updated_at' => $this->translateDate($task->updated_at, $task->client ? $task->client->date_format() : $task->company->date_format(), $task->client ? $task->client->locale() : $task->company->locale()),
'date' => $task->calculated_start_date ? $this->translateDate($task->calculated_start_date, $task->client ? $task->client->date_format() : $task->company->date_format(), $task->client ? $task->client->locale() : $task->company->locale()) : '', 'date' => $task->calculated_start_date ? $this->translateDate($task->calculated_start_date, $task->client ? $task->client->date_format() : $task->company->date_format(), $task->client ? $task->client->locale() : $task->company->locale()) : '',
'project' => $task->project ? $this->transformProject($task->project, true) : [], // 'project' => $task->project ? $this->transformProject($task->project, true) : [],
'project' => $task->project ? $task->project->name : '',
'time_log' => $task->processLogsExpandedNotation(), 'time_log' => $task->processLogsExpandedNotation(),
'custom_value1' => $task->custom_value1 ?: '', 'custom_value1' => $task->custom_value1 ?: '',
'custom_value2' => $task->custom_value2 ?: '', 'custom_value2' => $task->custom_value2 ?: '',

View File

@ -17,8 +17,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true), 'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => env('APP_VERSION', '5.10.42'), 'app_version' => env('APP_VERSION', '5.10.43'),
'app_tag' => env('APP_TAG', '5.10.42'), 'app_tag' => env('APP_TAG', '5.10.43'),
'minimum_client_version' => '5.0.16', 'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1', 'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', false), 'api_secret' => env('API_SECRET', false),

View File

@ -172,7 +172,6 @@ class PeppolTest extends TestCase
$this->assertCount(0, $errors); $this->assertCount(0, $errors);
} }

View File

@ -22,8 +22,20 @@ use App\DataMapper\Tax\TaxModel;
use App\DataMapper\ClientSettings; use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings; use App\DataMapper\CompanySettings;
use App\Services\EDocument\Standards\Peppol; use App\Services\EDocument\Standards\Peppol;
use Symfony\Component\Serializer\Serializer;
use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans; use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use InvoiceNinja\EInvoice\Models\Peppol\Invoice as PeppolInvoice;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use App\Services\EDocument\Gateway\Storecove\PeppolToStorecoveNormalizer;
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
use App\Services\EDocument\Gateway\Storecove\Models\Invoice as StorecoveInvoice;
class StorecoveTest extends TestCase class StorecoveTest extends TestCase
{ {
@ -1320,6 +1332,81 @@ class StorecoveTest extends TestCase
} }
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;
try {
// Assuming $invoice is already defined or created earlier in your test
$p = new Peppol($invoice);
$p->run();
$peppolInvoice = $p->getInvoice();
nlog("Peppol Invoice: " . json_encode($peppolInvoice, JSON_PRETTY_PRINT));
// Create the serializer with all necessary normalizers
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory);
$objectNormalizer = new ObjectNormalizer($classMetadataFactory, $metadataAwareNameConverter);
$encoders = [new JsonEncoder()];
$normalizers = [
new ArrayDenormalizer(),
$objectNormalizer,
new ObjectNormalizer(), // This is a fallback normalizer
];
$serializer = new Serializer($normalizers, $encoders);
// Create the PeppolToStorecoveNormalizer with the serializer
$peppolToStorecoveNormalizer = new PeppolToStorecoveNormalizer($serializer);
// Denormalize the Peppol invoice to a Storecove invoice
$storecoveInvoice = $peppolToStorecoveNormalizer->denormalize($peppolInvoice, StorecoveInvoice::class);
nlog("Storecove Invoice after denormalization: " . json_encode($storecoveInvoice, JSON_PRETTY_PRINT));
// Serialize the Storecove invoice to JSON
$jsonOutput = $serializer->serialize($storecoveInvoice, 'json', [
'json_encode_options' => JSON_PRETTY_PRINT
]);
nlog("Final JSON output: " . $jsonOutput);
// Add assertions to verify the output
$this->assertInstanceOf(StorecoveInvoice::class, $storecoveInvoice);
$this->assertJson($jsonOutput);
// Add more specific assertions based on your expected output
$decodedOutput = json_decode($jsonOutput, true);
$this->assertArrayHasKey('documentCurrency', $decodedOutput);
$this->assertArrayHasKey('invoiceNumber', $decodedOutput);
$this->assertArrayHasKey('invoiceLines', $decodedOutput);
$this->assertIsArray($decodedOutput['invoiceLines']);
// Add more assertions as needed
} catch (\Exception $e) {
nlog("Error occurred: " . $e->getMessage());
nlog("Stack trace: " . $e->getTraceAsString());
throw $e; // Re-throw the exception to fail the test
}
}
public function PestAtRules() public function PestAtRules()
{ {
$this->routing_id = 293801; $this->routing_id = 293801;