Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get real invoice value #69

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
16dd095
feat: allow multiple payment means
robert-stanciu Dec 22, 2023
50b1e2e
feat: allow multiple payment means
robert-stanciu Dec 22, 2023
6b1230d
feat: allow multiple payment means
robert-stanciu Dec 22, 2023
537244c
Update InvoiceTotals.php
robert-stanciu Jan 17, 2024
94f2694
fix static analysis
robert-stanciu Jan 17, 2024
049acb6
Merge pull request #1 from Kronos-IT-Support-Consulting/robert-stanci…
robert-stanciu Jan 17, 2024
659d553
fix ubl reader price
robert-stanciu Jan 29, 2024
b4a9021
fix php stan
robert-stanciu Jan 29, 2024
952f09f
Merge branch 'master' into fix-ubl-reader-price
robert-stanciu Jan 29, 2024
0611ddb
fix price reader
robert-stanciu Jan 29, 2024
23ef35d
fix price reader
robert-stanciu Jan 29, 2024
59ff62e
Merge pull request #2 from Kronos-IT-Support-Consulting/fix-ubl-reade…
robert-stanciu Jan 29, 2024
29c4f9a
fix: division by 0
robert-stanciu Jan 29, 2024
166fd09
Merge pull request #3 from Kronos-IT-Support-Consulting/robert-stanci…
robert-stanciu Jan 29, 2024
aa6b326
conditional-vat-number-tax-scheme
robert-stanciu Mar 4, 2024
fbb31aa
conditional-vat-number-tax-scheme
robert-stanciu Mar 4, 2024
2756b8c
Merge pull request #4 from Kronos-IT-Support-Consulting/conditional-v…
robert-stanciu Mar 4, 2024
7abb358
rollback
robert-stanciu Mar 4, 2024
597d1cb
rollback
robert-stanciu Mar 4, 2024
4266e7d
Merge pull request #5 from Kronos-IT-Support-Consulting/conditional-v…
robert-stanciu Mar 4, 2024
7ae67d0
add two ways for calculation totals
robert-stanciu Mar 15, 2024
ce2053d
add two ways for calculation totals
robert-stanciu Mar 15, 2024
cab98d4
Merge pull request #6 from Kronos-IT-Support-Consulting/add-two-ways-…
robert-stanciu Mar 15, 2024
9e70d0a
add two ways for calculation totals
robert-stanciu Mar 15, 2024
54a83d1
Merge pull request #7 from Kronos-IT-Support-Consulting/add-two-ways-…
robert-stanciu Mar 15, 2024
daab6ab
fix rounding (#8)
robert-stanciu Mar 22, 2024
5fc9271
feat: add read-totals (#9)
robert-stanciu Mar 25, 2024
40adb1c
Create dependabot.yml
robert-stanciu Mar 25, 2024
e069c81
Bump actions/checkout from 3 to 4 (#10)
dependabot[bot] Mar 25, 2024
c5f1489
feat: add read-totals (#11)
robert-stanciu Mar 25, 2024
0bdcafc
fix: prepaid amount != 0 (#12)
robert-stanciu Apr 4, 2024
4e77ec5
feat: add project reference (#13)
robert-stanciu Jul 8, 2024
a977548
Add project reference: fix order (#14)
robert-stanciu Jul 8, 2024
676318a
Add project reference (#15)
robert-stanciu Jul 8, 2024
38a5b67
Add project reference (#16)
robert-stanciu Jul 8, 2024
16d6e46
Add project reference: fix order (#17)
robert-stanciu Jul 8, 2024
5d28865
add-despatch-document-reference (#19)
robert-stanciu Sep 5, 2024
7003d1c
fix-allowance-amount-read (#20)
robert-stanciu Dec 9, 2024
c585c4d
add-base-amount-to-allowance-or-charge (#21)
robert-stanciu Dec 9, 2024
b5bbbfd
add abs to allowance charge (#22)
robert-stanciu Dec 9, 2024
a329676
add real amount of invoice
robert-stanciu Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Basic set up for three package managers

version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
# Workflow files stored in the default location of `.github/workflows`. (You don't need to specify `/.github/workflows` for `directory`. You can use `directory: "/"`.)
directory: "/"
schedule:
interval: "weekly"

# Maintain dependencies for Composer
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [push, pull_request]
on: [ pull_request]

jobs:
ci:
Expand All @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php-version: ['8.2', '8.3']
include:
- php-version: '8.2'
deploy: ${{ github.ref == 'refs/heads/master' }}
Expand All @@ -19,7 +19,7 @@ jobs:
steps:
# Download code from repository
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

# Setup PHP
- name: Setup PHP
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor
composer.lock
composer.lock
.idea
50 changes: 45 additions & 5 deletions src/AllowanceOrCharge.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class AllowanceOrCharge {
protected $reasonCode = null;
protected $reason = null;
protected $amount = null;
protected $baseAmount = null;
protected $factorMultiplier = null;
protected $isPercentage = false;

use VatTrait;
Expand Down Expand Up @@ -71,6 +73,46 @@ public function setAmount(float $amount): self {
}


/**
* Get base amount
* @return float|null Allowance/charge base amount
*/
public function getBaseAmount(): ?float {
return $this->baseAmount;
}


/**
* Set base amount
* @param float $baseAmount Allowance/charge base amount
* @return self This instance
*/
public function setBaseAmount(float $baseAmount): self {
$this->baseAmount = $baseAmount;
return $this;
}


/**
* Get factor multiplier
* @return float|null Allowance/charge factor multiplier
*/
public function getFactorMultiplier(): ?float {
return $this->factorMultiplier;
}


/**
* Set factor multiplier
* @param float $factorMultiplier Allowance/charge factor multiplier
* @return self This instance
*/
public function setFactorMultiplier(float $factorMultiplier): self {
$this->factorMultiplier = $factorMultiplier;
return $this;
}


/**
* Is percentage
* @return boolean Whether amount is a percentage or not
Expand Down Expand Up @@ -102,15 +144,13 @@ public function markAsFixedAmount(): self {

/**
* Get effective amount relative to base amount
* @param float $baseAmount Base amount
* @return float Effective amount
*/
public function getEffectiveAmount(float $baseAmount): float {
$amount = $this->getAmount();
public function getEffectiveAmount(): float {
if ($this->isPercentage()) {
$amount = $baseAmount * ($amount / 100);
return $this->baseAmount * ($this->factorMultiplier / 100);
}

return $amount;
return $this->getAmount();
}
}
115 changes: 107 additions & 8 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use DateTime;
use Einvoicing\Models\InvoiceTotals;
use Einvoicing\Payments\Payment;
use Einvoicing\Payments\PaymentTerms;
use Einvoicing\Presets\AbstractPreset;
use Einvoicing\Traits\AllowanceOrChargeTrait;
use Einvoicing\Traits\AttachmentsTrait;
Expand Down Expand Up @@ -244,6 +245,7 @@ class Invoice {
protected $businessProcess = null;
protected $number = null;
protected $type = self::TYPE_COMMERCIAL_INVOICE;
protected $legacySum = true;
protected $currency = "EUR"; // TODO: add constants
protected $vatCurrency = null;
protected $issueDate = null;
Expand All @@ -252,7 +254,9 @@ class Invoice {
protected $notes = [];
protected $buyerReference = null;
protected $purchaseOrderReference = null;
protected $despatchDocumentReference = null;
protected $salesOrderReference = null;
protected $projectReference = null;
protected $tenderOrLotReference = null;
protected $contractReference = null;
protected $paidAmount = 0;
Expand All @@ -262,8 +266,10 @@ class Invoice {
protected $buyer = null;
protected $payee = null;
protected $delivery = null;
protected $payment = null;
protected $payments = [];
protected $paymentTerms = null;
protected $lines = [];
protected $totals = null;

use AllowanceOrChargeTrait;
use AttachmentsTrait;
Expand Down Expand Up @@ -388,6 +394,25 @@ public function setNumber(string $number): self {
return $this;
}

/**
* Get legacy sum
* @return bool legacy sum
*/
public function getLegacySum(): bool {
return $this->legacySum;
}


/**
* Set legacy sum
* @param bool $legacySum legacy sum
* @return self Invoice instance
*/
public function setLegacySum(bool $legacySum): self {
$this->legacySum = $legacySum;
return $this;
}


/**
* Get invoice type code
Expand Down Expand Up @@ -619,6 +644,46 @@ public function setPurchaseOrderReference(?string $purchaseOrderReference): self
}


/**
* Get despatch document reference
* @return string|null despatch document reference
*/
public function getDespatchDocumentReference(): ?string {
return $this->despatchDocumentReference;
}


/**
* Set despatch document reference
* @param string|null $despatchDocumentReference despatch document reference
* @return self Invoice instance
*/
public function setDespatchDocumentReference(?string $despatchDocumentReference): self {
$this->despatchDocumentReference = $despatchDocumentReference;
return $this;
}


/**
* Get project reference
* @return string|null Project reference
*/
public function getProjectReference(): ?string {
return $this->projectReference;
}


/**
* Set project reference
* @param string|null $projectReference Project reference
* @return self Invoice instance
*/
public function setProjectReference(?string $projectReference): self {
$this->projectReference = $projectReference;
return $this;
}


/**
* Get sales order reference
* @return string|null Sales order reference
Expand Down Expand Up @@ -819,22 +884,42 @@ public function setDelivery(?Delivery $delivery): self {
}


/**
* Get payment terms information
* @return PaymentTerms|null PaymentTerms instance
*/
public function getPaymentTerms(): ?PaymentTerms {
return $this->paymentTerms;
}


/**
* Set payment terms information
* @param PaymentTerms|null $paymentTerms PaymentTerms instance
* @return self Invoice instance
*/
public function setPaymentTerms(?PaymentTerms $paymentTerms): self {
$this->paymentTerms = $paymentTerms;
return $this;
}


/**
* Get payment information
* @return Payment|null Payment instance
* @return Payment[] Payment instance
*/
public function getPayment(): ?Payment {
return $this->payment;
public function getPayments(): array {
return $this->payments;
}


/**
* Set payment information
* @param Payment|null $payment Payment instance
* @return self Invoice instance
* @param Payment $payment Payment instance
* @return self Invoice instance
*/
public function setPayment(?Payment $payment): self {
$this->payment = $payment;
public function addPayment(Payment $payment): self {
$this->payments[] = $payment;
return $this;
}

Expand Down Expand Up @@ -889,6 +974,20 @@ public function clearLines(): self {
* @return InvoiceTotals Invoice totals
*/
public function getTotals(): InvoiceTotals {
if (! empty($this->totals)) {
return $this->totals;
}

return InvoiceTotals::fromInvoice($this);
}


/**
* Set invoice total
* @return self Invoice instance
*/
public function setTotals(InvoiceTotals $invoiceTotals): self {
$this->totals = $invoiceTotals;
return $this;
}
}
10 changes: 4 additions & 6 deletions src/InvoiceLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class InvoiceLine {
protected $quantity = 1;
protected $unit = "C62"; // TODO: add constants
protected $price = null;
protected $baseQuantity = 1;
protected $baseQuantity = 1.0;

use AllowanceOrChargeTrait;
use AttributesTrait;
Expand Down Expand Up @@ -289,7 +289,7 @@ public function getBaseQuantity(): float {
* @return self Invoice line instance
*/
public function setBaseQuantity(float $baseQuantity): self {
$this->baseQuantity = $baseQuantity;
$this->baseQuantity = $baseQuantity != 0.0 ? $baseQuantity : 1.0;
return $this;
}

Expand All @@ -312,9 +312,8 @@ public function getNetAmountBeforeAllowancesCharges(): ?float {
*/
public function getAllowancesAmount(): float {
$allowancesAmount = 0;
$baseAmount = $this->getNetAmountBeforeAllowancesCharges() ?? 0.0;
foreach ($this->getAllowances() as $item) {
$allowancesAmount += $item->getEffectiveAmount($baseAmount);
$allowancesAmount += $item->getEffectiveAmount();
}
return $allowancesAmount;
}
Expand All @@ -326,9 +325,8 @@ public function getAllowancesAmount(): float {
*/
public function getChargesAmount(): float {
$chargesAmount = 0;
$baseAmount = $this->getNetAmountBeforeAllowancesCharges() ?? 0.0;
foreach ($this->getCharges() as $item) {
$chargesAmount += $item->getEffectiveAmount($baseAmount);
$chargesAmount += $item->getEffectiveAmount();
}
return $chargesAmount;
}
Expand Down
Loading