Skip to content

Commit

Permalink
Merge pull request #37 from josemmo/develop
Browse files Browse the repository at this point in the history
v0.2.4
  • Loading branch information
josemmo authored Jan 21, 2023
2 parents 9b1bc79 + a2fcfb4 commit 9879cbf
Show file tree
Hide file tree
Showing 9 changed files with 721 additions and 29 deletions.
219 changes: 218 additions & 1 deletion src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,232 @@
use function is_subclass_of;
use function round;

/** @phan-suppress PhanUnreferencedPublicClassConstant */
class Invoice {
const DEFAULT_DECIMALS = 8;

/**
* Request for payment
*
* Document/message issued by a creditor to a debtor to request payment of one or more invoices past due.
*/
const TYPE_REQUEST_FOR_PAYMENT = 71;

/**
* Debit note related to goods or services
*
* Debit information related to a transaction for goods or services to the relevant party.
*/
const TYPE_DEBIT_NOTE_RELATED_TO_GOODS_OR_SERVICES = 80;

/**
* Metered services invoice
*
* Document/message claiming payment for the supply of metered services (e.g., gas, electricity, etc.) supplied to
* a fixed meter whose consumption is measured over a period of time.
*/
const TYPE_METERED_SERVICES_INVOICE = 82;

/**
* Debit note related to financial adjustments
*
* Document/message for providing debit information related to financial adjustments to the relevant party.
*/
const TYPE_DEBIT_NOTE_RELATED_TO_FINANCIAL_ADJUSTMENTS = 84;

/**
* Tax notification
*
* Used to specify that the message is a tax notification.
*/
const TYPE_TAX_NOTIFICATION = 102;

/**
* Final payment request based on completion of work
*
* The final payment request of a series of payment requests submitted upon completion of all the work.
*/
const TYPE_FINAL_PAYMENT_REQUEST_BASED_ON_COMPLETION_OF_WORK = 218;

/**
* Payment request for completed units
*
* A request for payment for completed units.
*/
const TYPE_PAYMENT_REQUEST_FOR_COMPLETED_UNITS = 219;

/**
* Commercial invoice which includes a packing list
*
* Commercial transaction (invoice) will include a packing list.
*/
const TYPE_COMMERCIAL_INVOICE_WHICH_INCLUDES_A_PACKING_LIST = 331;

/**
* Commercial invoice
*
* Document/message claiming payment for goods or services supplied under conditions agreed between seller and
* buyer.
*/
const TYPE_COMMERCIAL_INVOICE = 380;

/**
* Commission note
*
* Document/message in which a seller specifies the amount of commission, the percentage of the invoice amount, or
* some other basis for the calculation of the commission to which a sales agent is entitled.
*/
const TYPE_COMMISSION_NOTE = 382;

/**
* Debit note
*
* Document/message for providing debit information to the relevant party.
*/
const TYPE_DEBIT_NOTE = 383;

/**
* Prepayment invoice
*
* An invoice to pay amounts for goods and services in advance; these amounts will be subtracted from the final
* invoice.
*/
const TYPE_PREPAYMENT_INVOICE = 386;

/**
* Tax invoice
*
* An invoice for tax purposes.
*/
const TYPE_TAX_INVOICE = 388;

/**
* Factored invoice
*
* Invoice assigned to a third party for collection.
*/
const TYPE_FACTORED_INVOICE = 393;

/**
* Consignment invoice
*
* Commercial invoice that covers a transaction other than one involving a sale.
*/
const TYPE_CONSIGNMENT_INVOICE = 395;

/**
* Forwarder's invoice discrepancy report
*
* Document/message reporting invoice discrepancies indentified by the forwarder.
*/
const TYPE_FORWARDERS_INVOICE_DISCREPANCY_REPORT = 553;

/**
* Insurer's invoice
*
* Document/message issued by an insurer specifying the cost of an insurance which has been effected and claiming
* payment therefore.
*/
const TYPE_INSURERS_INVOICE = 575;

/**
* Forwarder's invoice
*
* Invoice issued by a freight forwarder specifying services rendered and costs incurred and claiming payment
* therefore.
*/
const TYPE_FORWARDERS_INVOICE = 623;

/**
* Freight invoice
*
* Document/message issued by a transport operation specifying freight costs and charges incurred for a transport
* operation and stating conditions of payment.
*/
const TYPE_FREIGHT_INVOICE = 780;

/**
* Claim notification
*
* Document notifying a claim.
*/
const TYPE_CLAIM_NOTIFICATION = 817;

/**
* Consular invoice
*
* Document/message to be prepared by an exporter in his country and presented to a diplomatic representation of the
* importing country for endorsement and subsequently to be presented by the importer in connection with the import
* of the goods described therein.
*/
const TYPE_CONSULAR_INVOICE = 870;

/**
* Partial construction invoice
*
* Partial invoice in the context of a specific construction project.
*/
const TYPE_PARTIAL_CONSTRUCTION_INVOICE = 875;

/**
* Partial final construction invoice
*
* Invoice concluding all previous partial construction invoices of a completed partial rendered service in the
* context of a specific construction project.
*/
const TYPE_PARTIAL_FINAL_CONSTRUCTION_INVOICE = 876;

/**
* Final construction invoice
*
* Invoice concluding all previous partial invoices and partial final construction invoices in the context of a
* specific construction project.
*/
const TYPE_FINAL_CONSTRUCTION_INVOICE = 877;

/**
* Credit note related to goods or services
*
* Document message used to provide credit information related to a transaction for goods or services to the
* relevant party.
*/
const TYPE_CREDIT_NOTE_RELATED_TO_GOODS_OR_SERVICES = 81;

/**
* Credit note related to financial adjustments
*
* Document message for providing credit information related to financial adjustments to the relevant party,
* e.g., bonuses.
*/
const TYPE_CREDIT_NOTE_RELATED_TO_FINANCIAL_ADJUSTMENTS = 83;

/**
* Credit note
*
* Document/message for providing credit information to the relevant party.
*/
const TYPE_CREDIT_NOTE = 381;

/**
* Factored credit note
*
* Credit note related to assigned invoice(s).
*/
const TYPE_FACTORED_CREDIT_NOTE = 396;

/**
* Forwarder's credit note
*
* Document/message for providing credit information to the relevant party.
*/
const TYPE_FORWARDERS_CREDIT_NOTE = 532;

protected $preset = null;
protected $roundingMatrix = null;
protected $specification = null;
protected $businessProcess = null;
protected $number = null;
protected $type = 380; // TODO: add constants
protected $type = self::TYPE_COMMERCIAL_INVOICE;
protected $currency = "EUR"; // TODO: add constants
protected $vatCurrency = null;
protected $issueDate = null;
Expand Down
8 changes: 4 additions & 4 deletions src/Readers/UblReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ public function import(string $document): Invoice {
}

// BT-9: Due date
$dueDateNode = $xml->get("{{$cbc}}DueDate");
$dueDateNode = $xml->get("{{$cbc}}DueDate | {{$cac}}PaymentMeans/{{$cbc}}PaymentDueDate");
if ($dueDateNode !== null) {
$invoice->setDueDate(new DateTime($dueDateNode->asText()));
}

// BT-3: Invoice type code
$typeNode = $xml->get("{{$cbc}}InvoiceTypeCode");
$typeNode = $xml->get("{{$cbc}}InvoiceTypeCode | {{$cbc}}CreditNoteTypeCode");
if ($typeNode !== null) {
$invoice->setType((int) $typeNode->asText());
}
Expand Down Expand Up @@ -241,7 +241,7 @@ public function import(string $document): Invoice {
}

// Invoice lines
foreach ($xml->getAll("{{$cac}}InvoiceLine") as $node) {
foreach ($xml->getAll("{{$cac}}InvoiceLine | {{$cac}}CreditNoteLine") as $node) {
$invoice->addLine($this->parseInvoiceLine($node, $taxExemptions));
}

Expand Down Expand Up @@ -744,7 +744,7 @@ private function parseInvoiceLine(UXML $xml, array &$taxExemptions): InvoiceLine
}

// Quantity
$quantityNode = $xml->get("{{$cbc}}InvoicedQuantity");
$quantityNode = $xml->get("{{$cbc}}InvoicedQuantity | {{$cbc}}CreditedQuantity");
if ($quantityNode !== null) {
$line->setQuantity((float) $quantityNode->asText());
$line->setUnit($quantityNode->element()->getAttribute('unitCode'));
Expand Down
Loading

0 comments on commit 9879cbf

Please sign in to comment.