mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Working on UBL
This commit is contained in:
parent
2f80e1cc77
commit
2723fb8014
@ -12,6 +12,7 @@ use CleverIt\UBL\Invoice\Contact;
|
||||
use CleverIt\UBL\Invoice\TaxTotal;
|
||||
use CleverIt\UBL\Invoice\TaxSubTotal;
|
||||
use CleverIt\UBL\Invoice\TaxCategory;
|
||||
use CleverIt\UBL\Invoice\TaxScheme;
|
||||
use CleverIt\UBL\Invoice\InvoiceLine;
|
||||
use CleverIt\UBL\Invoice\Item;
|
||||
use CleverIt\UBL\Invoice\LegalMonetaryTotal;
|
||||
@ -57,26 +58,32 @@ class ConvertInvoiceToUbl extends Job
|
||||
$taxtotal = new TaxTotal();
|
||||
$taxAmount1 = $taxAmount2 = 0;
|
||||
|
||||
if ($item->tax_name1 || floatval($item->tax_rate1)) {
|
||||
if ($invoice->tax_name1 || floatval($invoice->tax_rate1)) {
|
||||
$taxAmount1 = $invoice->taxAmount($taxable, $invoice->tax_rate1);
|
||||
$taxScheme = ((new TaxScheme()))
|
||||
->setId($invoice->tax_name1);
|
||||
$taxtotal->addTaxSubTotal((new TaxSubTotal())
|
||||
->setTaxAmount($taxAmount1)
|
||||
->setTaxableAmount($taxable)
|
||||
->setTaxCategory((new TaxCategory())
|
||||
->setId($item->tax_name1)
|
||||
->setName($item->tax_name1)
|
||||
->setPercent($item->tax_rate1)));
|
||||
->setId($invoice->tax_name1)
|
||||
->setName($invoice->tax_name1)
|
||||
->setTaxScheme($taxScheme)
|
||||
->setPercent($invoice->tax_rate1)));
|
||||
}
|
||||
|
||||
if ($item->tax_name2 || floatval($item->tax_rate2)) {
|
||||
if ($invoice->tax_name2 || floatval($invoice->tax_rate2)) {
|
||||
$itemTaxAmount2 = $invoice->taxAmount($taxable, $invoice->tax_rate2);
|
||||
$taxScheme = ((new TaxScheme()))
|
||||
->setId($invoice->tax_name2);
|
||||
$taxtotal->addTaxSubTotal((new TaxSubTotal())
|
||||
->setTaxAmount($taxAmount2)
|
||||
->setTaxableAmount($taxable)
|
||||
->setTaxCategory((new TaxCategory())
|
||||
->setId($item->tax_name2)
|
||||
->setName($item->tax_name2)
|
||||
->setPercent($item->tax_rate2)));
|
||||
->setId($invoice->tax_name2)
|
||||
->setName($invoice->tax_name2)
|
||||
->setTaxScheme($taxScheme)
|
||||
->setPercent($invoice->tax_rate2)));
|
||||
}
|
||||
|
||||
$taxtotal->setTaxAmount($taxAmount1 + $taxAmount2);
|
||||
@ -134,23 +141,29 @@ class ConvertInvoiceToUbl extends Job
|
||||
|
||||
if ($item->tax_name1 || floatval($item->tax_rate1)) {
|
||||
$itemTaxAmount1 = $invoice->taxAmount($taxable, $item->tax_rate1);
|
||||
$taxScheme = ((new TaxScheme()))
|
||||
->setId($item->tax_name1);
|
||||
$taxtotal->addTaxSubTotal((new TaxSubTotal())
|
||||
->setTaxAmount($itemTaxAmount1)
|
||||
->setTaxableAmount($taxable)
|
||||
->setTaxCategory((new TaxCategory())
|
||||
->setId($item->tax_name1)
|
||||
->setName($item->tax_name1)
|
||||
->setTaxScheme($taxScheme)
|
||||
->setPercent($item->tax_rate1)));
|
||||
}
|
||||
|
||||
if ($item->tax_name2 || floatval($item->tax_rate2)) {
|
||||
$itemTaxAmount2 = $invoice->taxAmount($taxable, $item->tax_rate2);
|
||||
$taxScheme = ((new TaxScheme()))
|
||||
->setId($item->tax_name2);
|
||||
$taxtotal->addTaxSubTotal((new TaxSubTotal())
|
||||
->setTaxAmount($itemTaxAmount2)
|
||||
->setTaxableAmount($taxable)
|
||||
->setTaxCategory((new TaxCategory())
|
||||
->setId($item->tax_name2)
|
||||
->setName($item->tax_name2)
|
||||
->setTaxScheme($taxScheme)
|
||||
->setPercent($item->tax_rate2)));
|
||||
}
|
||||
|
||||
|
@ -1485,6 +1485,14 @@ class Account extends Eloquent
|
||||
return $this->hasFeature(FEATURE_PDF_ATTACHMENT) && $this->pdf_email_attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function attachUBL()
|
||||
{
|
||||
return $this->hasFeature(FEATURE_PDF_ATTACHMENT) && $this->ubl_email_attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
@ -701,11 +701,11 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName()
|
||||
public function getFileName($extension = 'pdf')
|
||||
{
|
||||
$entityType = $this->getEntityType();
|
||||
|
||||
return trans("texts.$entityType") . '_' . $this->invoice_number . '.pdf';
|
||||
return trans("texts.$entityType") . '_' . $this->invoice_number . '.' . $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ use App\Models\Invitation;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Services\TemplateService;
|
||||
use App\Jobs\ConvertInvoiceToUbl;
|
||||
use Event;
|
||||
use Utils;
|
||||
|
||||
@ -61,10 +62,14 @@ class ContactMailer extends Mailer
|
||||
|
||||
$sent = false;
|
||||
$pdfString = false;
|
||||
$ublString = false;
|
||||
|
||||
if ($account->attachPDF()) {
|
||||
$pdfString = $invoice->getPDFString();
|
||||
}
|
||||
if ($account->attachUBL()) {
|
||||
$ublString = dispatch(new ConvertInvoiceToUbl($invoice));
|
||||
}
|
||||
|
||||
$documentStrings = [];
|
||||
if ($account->document_email_attachment && $invoice->hasDocuments()) {
|
||||
@ -88,7 +93,12 @@ class ContactMailer extends Mailer
|
||||
|
||||
$isFirst = true;
|
||||
foreach ($invoice->invitations as $invitation) {
|
||||
$response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString, $documentStrings, $reminder, $isFirst);
|
||||
$data = [
|
||||
'pdfString' => $pdfString,
|
||||
'documentStrings' => $documentStrings,
|
||||
'ublString' => $ublString,
|
||||
];
|
||||
$response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $reminder, $isFirst, $data);
|
||||
$isFirst = false;
|
||||
if ($response === true) {
|
||||
$sent = true;
|
||||
@ -126,10 +136,9 @@ class ContactMailer extends Mailer
|
||||
Invoice $invoice,
|
||||
$body,
|
||||
$subject,
|
||||
$pdfString,
|
||||
$documentStrings,
|
||||
$reminder,
|
||||
$isFirst
|
||||
$isFirst,
|
||||
$attachments
|
||||
) {
|
||||
$client = $invoice->client;
|
||||
$account = $invoice->account;
|
||||
@ -177,16 +186,20 @@ class ContactMailer extends Mailer
|
||||
'account' => $account,
|
||||
'client' => $client,
|
||||
'invoice' => $invoice,
|
||||
'documents' => $documentStrings,
|
||||
'documents' => $attachments['documentStrings'],
|
||||
'notes' => $reminder,
|
||||
'bccEmail' => $isFirst ? $account->getBccEmail() : false,
|
||||
'fromEmail' => $account->getFromEmail(),
|
||||
];
|
||||
|
||||
if ($account->attachPDF()) {
|
||||
$data['pdfString'] = $pdfString;
|
||||
$data['pdfString'] = $attachments['pdfString'];
|
||||
$data['pdfFileName'] = $invoice->getFileName();
|
||||
}
|
||||
if ($account->attachUBL()) {
|
||||
$data['ublString'] = $attachments['ublString'];
|
||||
$data['ublFileName'] = $invoice->getFileName('xml');
|
||||
}
|
||||
|
||||
$subject = $this->templateService->processVariables($subject, $variables);
|
||||
$fromEmail = $account->getReplyToEmail() ?: $user->email;
|
||||
|
@ -67,12 +67,13 @@ class Mailer
|
||||
$message->bcc($data['bccEmail']);
|
||||
}
|
||||
|
||||
// Attach the PDF to the email
|
||||
// Handle invoice attachments
|
||||
if (! empty($data['pdfString']) && ! empty($data['pdfFileName'])) {
|
||||
$message->attachData($data['pdfString'], $data['pdfFileName']);
|
||||
}
|
||||
|
||||
// Attach documents to the email
|
||||
if (! empty($data['ublString']) && ! empty($data['ublFileName'])) {
|
||||
$message->attachData($data['ublString'], $data['ublFileName']);
|
||||
}
|
||||
if (! empty($data['documents'])) {
|
||||
foreach ($data['documents'] as $document) {
|
||||
$message->attachData($document['data'], $document['name']);
|
||||
|
Loading…
Reference in New Issue
Block a user