mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Updates for e-invoice to include legal literals and also payments
This commit is contained in:
parent
8d70dbcdfa
commit
a821f7e751
@ -94,42 +94,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment onlyTrashed()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel scope()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereAmount($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereApplied($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereAssignedUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereClientContactId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereClientId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereCompanyGatewayId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereCompanyId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereCurrencyId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereCustomValue1($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereCustomValue2($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereCustomValue3($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereCustomValue4($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereDate($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereExchangeCurrencyId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereExchangeRate($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereGatewayTypeId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereIdempotencyKey($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereInvitationId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereIsDeleted($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereIsManual($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereMeta($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereNumber($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment wherePayerId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment wherePrivateNotes($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereProjectId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereRefunded($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereStatusId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereTransactionId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereTransactionReference($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereTypeId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment whereVendorId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment withTrashed()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Payment withoutTrashed()
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
@ -137,61 +101,6 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyLedger> $company_ledger
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Credit> $credits
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Document> $documents
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Invoice> $invoices
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Paymentable> $paymentables
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Payment extends BaseModel
|
||||
|
@ -12,13 +12,15 @@
|
||||
namespace App\Services\Invoice\EInvoice;
|
||||
|
||||
use App\Models\Invoice;
|
||||
use App\Models\PaymentType;
|
||||
use josemmo\Facturae\Facturae;
|
||||
use App\Services\AbstractService;
|
||||
use josemmo\Facturae\FacturaeItem;
|
||||
use josemmo\Facturae\FacturaeParty;
|
||||
use josemmo\Facturae\FacturaeCentre;
|
||||
use josemmo\Facturae\FacturaePayment;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use josemmo\Facturae\Common\FacturaeSigner;
|
||||
use josemmo\Facturae\FacturaeCentre;
|
||||
|
||||
class FacturaEInvoice extends AbstractService
|
||||
{
|
||||
@ -169,6 +171,9 @@ class FacturaEInvoice extends AbstractService
|
||||
->buildItems()
|
||||
->setDiscount()
|
||||
->setPoNumber()
|
||||
->setLegalTerms()
|
||||
->setPayments()
|
||||
->setBillingPeriod()
|
||||
->signDocument();
|
||||
|
||||
$disk = config('filesystems.default');
|
||||
@ -228,6 +233,134 @@ class FacturaEInvoice extends AbstractService
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function setLegalTerms(): self
|
||||
{
|
||||
$this->fac->addLegalLiteral(substr($this->invoice->public_notes,0,250));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function setBillingPeriod(): self
|
||||
{
|
||||
if (\Carbon\Carbon::createFromFormat('Y-m-d', $this->invoice->custom_value3)->format('Y-m-d') === $this->invoice->custom_value3 &&
|
||||
\Carbon\Carbon::createFromFormat('Y-m-d', $this->invoice->custom_value4)->format('Y-m-d') === $this->invoice->custom_value4
|
||||
){
|
||||
$this->fac->setBillingPeriod(\Carbon\Carbon::parse($this->invoice->custom_value3)->format('Y-m-d'), \Carbon\Carbon::parse($this->invoice->custom_value4)->format('Y-m-d'));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function setPayments(): self
|
||||
{
|
||||
$this->invoice->payments()->each(function ($payment){
|
||||
|
||||
$payment_data = [
|
||||
"dueDate" => \Carbon\Carbon::parse($payment->date)->format('Y-m-d'),
|
||||
"amount" => $payment->pivot->amount,
|
||||
];
|
||||
|
||||
$data = array_merge($this->resolvePaymentMethod($payment), $payment_data);
|
||||
|
||||
$this->fac->addPayment(new FacturaePayment($data));
|
||||
|
||||
});
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* FacturaePayment::TYPE_CASH Cash
|
||||
* FacturaePayment::TYPE_DEBIT Domiciled receipt
|
||||
* FacturaePayment::TYPE_RECEIPT Receipt
|
||||
* FacturaePayment::TYPE_TRANSFER Transfer
|
||||
* FacturaePayment::TYPE_ACCEPTED_BILL_OF_EXCHANGE Letter Accepted
|
||||
* FacturaePayment::TYPE_DOCUMENTARY_CREDIT Letter of credit
|
||||
* FacturaePayment::TYPE_CONTRACT_AWARD contract award
|
||||
* FacturaePayment::TYPE_BILL_OF_EXCHANGE Bill of exchange
|
||||
* FacturaePayment::TYPE_TRANSFERABLE_IOU I will pay to order
|
||||
* FacturaePayment::TYPE_IOU I Will Pay Not To Order
|
||||
* FacturaePayment::TYPE_CHEQUE Check
|
||||
* FacturaePayment::TYPE_REIMBURSEMENT Replacement
|
||||
* FacturaePayment::TYPE_SPECIAL specials
|
||||
* FacturaePayment::TYPE_SETOFF Compensation
|
||||
* FacturaePayment::TYPE_POSTGIRO Money order
|
||||
* FacturaePayment::TYPE_CERTIFIED_CHEQUE conformed check
|
||||
* FacturaePayment::TYPE_BANKERS_DRAFT Bank check
|
||||
* FacturaePayment::TYPE_CASH_ON_DELIVERY Cash on delivery
|
||||
* FacturaePayment::TYPE_CARD Payment by card
|
||||
*
|
||||
* @param \App\Models\Payment $payment
|
||||
* @return array
|
||||
*/
|
||||
private function resolvePaymentMethod(\App\Models\Payment $payment): array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
match($payment->type_id){
|
||||
PaymentType::BANK_TRANSFER => $method = FacturaePayment::TYPE_TRANSFER ,
|
||||
PaymentType::CASH => $method = FacturaePayment::TYPE_CASH ,
|
||||
PaymentType::ACH => $method = FacturaePayment::TYPE_TRANSFER ,
|
||||
PaymentType::VISA => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::MASTERCARD => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::AMERICAN_EXPRESS => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::DISCOVER => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::DINERS => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::EUROCARD => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::NOVA => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::CREDIT_CARD_OTHER => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::PAYPAL => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::CHECK => $method = FacturaePayment::TYPE_CHEQUE ,
|
||||
PaymentType::CARTE_BLANCHE => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::UNIONPAY => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::JCB => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::LASER => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::MAESTRO => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::SOLO => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::SWITCH => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::VENMO => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::ALIPAY => $method = FacturaePayment::TYPE_CARD ,
|
||||
PaymentType::SOFORT => $method = FacturaePayment::TYPE_TRANSFER,
|
||||
PaymentType::SEPA => $method = FacturaePayment::TYPE_TRANSFER,
|
||||
PaymentType::GOCARDLESS => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::CRYPTO => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::CREDIT => $method = FacturaePayment::TYPE_DOCUMENTARY_CREDIT ,
|
||||
PaymentType::ZELLE => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::MOLLIE_BANK_TRANSFER => $method = FacturaePayment::TYPE_TRANSFER ,
|
||||
PaymentType::KBC => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::BANCONTACT => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::IDEAL => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::HOSTED_PAGE => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::GIROPAY => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::PRZELEWY24 => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::EPS => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::DIRECT_DEBIT => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::BECS => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::ACSS => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::INSTANT_BANK_PAY => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::FPX => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::KLARNA => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::Interac_E_Transfer => $method = FacturaePayment::TYPE_TRANSFER ,
|
||||
PaymentType::BACS => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
PaymentType::STRIPE_BANK_TRANSFER => $method = FacturaePayment::TYPE_TRANSFER ,
|
||||
PaymentType::CASH_APP => $method = FacturaePayment::TYPE_SPECIAL ,
|
||||
default => $method = FacturaePayment::TYPE_CARD ,
|
||||
};
|
||||
|
||||
$data['method'] = $method;
|
||||
|
||||
if($method == FacturaePayment::TYPE_TRANSFER)
|
||||
{
|
||||
$data['iban'] = $payment->custom_value1;
|
||||
$data['bic'] = $payment->custom_value2;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function buildItems(): self
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user