1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00

Merge branch 'v5-develop' of https://github.com/turbo124/invoiceninja into v5-develop

This commit is contained in:
David Bomba 2022-07-01 08:26:32 +10:00
commit 8d0dffa4f4
8 changed files with 74 additions and 80 deletions

View File

@ -24,11 +24,11 @@ class SwissQrGenerator
protected Company $company; protected Company $company;
protected Invoice $invoice; protected $invoice;
protected Client $client; protected Client $client;
public function __construct(Invoice $invoice, Company $company) public function __construct($invoice, Company $company)
{ {
$this->company = $company; $this->company = $company;
@ -86,11 +86,11 @@ class SwissQrGenerator
// They are interchangeable for creditor as well as debtor. // They are interchangeable for creditor as well as debtor.
$qrBill->setUltimateDebtor( $qrBill->setUltimateDebtor(
QrBill\DataGroup\Element\StructuredAddress::createWithStreet( QrBill\DataGroup\Element\StructuredAddress::createWithStreet(
$this->client->present()->name(), substr($this->client->present()->name(), 0 , 70),
$this->client->address1 ?: '', $this->client->address1 ? substr($this->client->address1, 0 , 70) : '',
$this->client->address2 ?: '', $this->client->address2 ? substr($this->client->address2, 0 , 16) : '',
$this->client->postal_code ?: '', $this->client->postal_code ? substr($this->client->postal_code, 0, 16) : '',
$this->client->city ?: '', $this->client->city ? substr($this->client->postal_code, 0, 35) : '',
'CH' 'CH'
)); ));
@ -106,7 +106,7 @@ class SwissQrGenerator
// This is what you will need to identify incoming payments. // This is what you will need to identify incoming payments.
$referenceNumber = QrBill\Reference\QrPaymentReferenceGenerator::generate( $referenceNumber = QrBill\Reference\QrPaymentReferenceGenerator::generate(
$this->company->present()->besr_id() ?: '', // You receive this number from your bank (BESR-ID). Unless your bank is PostFinance, in that case use NULL. $this->company->present()->besr_id() ?: '', // You receive this number from your bank (BESR-ID). Unless your bank is PostFinance, in that case use NULL.
$this->invoice->number // A number to match the payment with your internal data, e.g. an invoice number $this->invoice->number// A number to match the payment with your internal data, e.g. an invoice number
); );
$qrBill->setPaymentReference( $qrBill->setPaymentReference(
@ -124,23 +124,28 @@ class SwissQrGenerator
// Now get the QR code image and save it as a file. // Now get the QR code image and save it as a file.
try { try {
// $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png');
// $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg');
} catch (\Exception $e) {
foreach($qrBill->getViolations() as $key => $violation) {
}
// return $e->getMessage(); $output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en');
}
$output = new QrBill\PaymentPart\Output\HtmlOutput\HtmlOutput($qrBill, 'en'); $html = $output
->setPrintable(false)
->getPaymentPart();
return $html;
} catch (\Exception $e) {
foreach($qrBill->getViolations() as $key => $violation) {
nlog("qr");
nlog($violation);
}
return '';
// return $e->getMessage();
}
$html = $output
->setPrintable(false)
->getPaymentPart();
return $html;
} }
} }

View File

@ -284,12 +284,11 @@ class PreviewController extends BaseController
} }
catch(\Exception $e){ catch(\Exception $e){
nlog($e->getMessage());
DB::connection(config('database.default'))->rollBack(); DB::connection(config('database.default'))->rollBack();
return; return;
} }
//if phantom js...... inject here.. //if phantom js...... inject here..
if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') {
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true)); return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));

View File

@ -173,9 +173,27 @@ class Design extends BaseDesign
$this->sharedFooterElements(), $this->sharedFooterElements(),
], ],
], ],
// 'swiss-qr' => [
// 'id' => 'swiss-qr',
// 'elements' => $this->swissQrCodeElement(),
// ]
]; ];
} }
public function swissQrCodeElement() :array
{
if($this->type == self::DELIVERY_NOTE)
return [];
$elements = [];
if(strlen($this->company->getSetting('qr_iban')) > 5 && strlen($this->company->getSetting('besr_id')) > 1)
$elements[] = ['element' => 'qr_code', 'content' => '$swiss_qr', 'show_empty' => false, 'properties' => ['data-ref' => 'swiss-qr-code']];
return $elements;
}
public function companyDetails(): array public function companyDetails(): array
{ {
$variables = $this->context['pdf_variables']['company_details']; $variables = $this->context['pdf_variables']['company_details'];

View File

@ -12,6 +12,7 @@
namespace App\Utils; namespace App\Utils;
use App\Helpers\SwissQr\SwissQrGenerator;
use App\Models\Country; use App\Models\Country;
use App\Models\CreditInvitation; use App\Models\CreditInvitation;
use App\Models\GatewayType; use App\Models\GatewayType;
@ -162,6 +163,17 @@ class HtmlEngine
if($this->entity->vendor) { if($this->entity->vendor) {
$data['$invoice.vendor'] = ['value' => $this->entity->vendor->present()->name(), 'label' => ctrans('texts.vendor_name')]; $data['$invoice.vendor'] = ['value' => $this->entity->vendor->present()->name(), 'label' => ctrans('texts.vendor_name')];
} }
if(strlen($this->company->getSetting('qr_iban')) > 5 && strlen($this->company->getSetting('besr_id')) > 1)
{
try{
$data['$swiss_qr'] = ['value' => (new SwissQrGenerator($this->entity, $this->company))->run(), 'label' => ''];
}
catch(\Exception $e){
$data['$swiss_qr'] = ['value' => '', 'label' => ''];
}
}
} }
if ($this->entity_string == 'quote') { if ($this->entity_string == 'quote') {
@ -281,6 +293,7 @@ class HtmlEngine
$data['$assigned_to_user'] = ['value' => $this->entity->assigned_user ? $this->entity->assigned_user->present()->name() : '', 'label' => ctrans('texts.name')]; $data['$assigned_to_user'] = ['value' => $this->entity->assigned_user ? $this->entity->assigned_user->present()->name() : '', 'label' => ctrans('texts.name')];
$data['$user_iban'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company1', $this->settings->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company1')]; $data['$user_iban'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company1', $this->settings->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company1')];
$data['$invoice.custom1'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice1', $this->entity->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice1')]; $data['$invoice.custom1'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice1', $this->entity->custom_value1, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice1')];
$data['$invoice.custom2'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice2', $this->entity->custom_value2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice2')]; $data['$invoice.custom2'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice2', $this->entity->custom_value2, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice2')];
$data['$invoice.custom3'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice3', $this->entity->custom_value3, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice3')]; $data['$invoice.custom3'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'invoice3', $this->entity->custom_value3, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'invoice3')];

View File

@ -27,6 +27,7 @@ use App\Utils\Ninja;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml; use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\MakesTemplateData; use App\Utils\Traits\MakesTemplateData;
use App\Utils\VendorHtmlEngine;
use DB; use DB;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Lang;
@ -157,7 +158,8 @@ class TemplateEngine
} }
elseif ($this->entity_obj) { elseif ($this->entity_obj) {
$this->entityValues($this->entity_obj->client->primary_contact()->first()); $this->entityValues($this->entity_obj->client->primary_contact()->first());
} else { }
else {
$this->fakerValues(); $this->fakerValues();
} }
@ -184,11 +186,13 @@ class TemplateEngine
private function entityValues($contact) private function entityValues($contact)
{ {
$this->labels_and_values = (new HtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues(); if($this->entity == 'purchase_order')
$this->labels_and_values = (new VendorHtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues();
else
$this->labels_and_values = (new HtmlEngine($this->entity_obj->invitations->first()))->generateLabelsAndValues();
$this->body = strtr($this->body, $this->labels_and_values['labels']); $this->body = strtr($this->body, $this->labels_and_values['labels']);
$this->body = strtr($this->body, $this->labels_and_values['values']); $this->body = strtr($this->body, $this->labels_and_values['values']);
// $this->body = str_replace("\n", "<br>", $this->body);
$this->subject = strtr($this->subject, $this->labels_and_values['labels']); $this->subject = strtr($this->subject, $this->labels_and_values['labels']);
$this->subject = strtr($this->subject, $this->labels_and_values['values']); $this->subject = strtr($this->subject, $this->labels_and_values['values']);
@ -219,6 +223,7 @@ class TemplateEngine
$data['whitelabel'] = $this->entity_obj ? $this->entity_obj->company->account->isPaid() : true; $data['whitelabel'] = $this->entity_obj ? $this->entity_obj->company->account->isPaid() : true;
$data['company'] = $this->entity_obj ? $this->entity_obj->company : ''; $data['company'] = $this->entity_obj ? $this->entity_obj->company : '';
$data['settings'] = $this->settings; $data['settings'] = $this->settings;
} }
@ -263,6 +268,9 @@ class TemplateEngine
private function mockEntity() private function mockEntity()
{ {
if(!$this->entity && $this->template && str_contains($this->template, 'purchase_order'))
$this->entity = 'purchase_order';
DB::connection(config('database.default'))->beginTransaction(); DB::connection(config('database.default'))->beginTransaction();
$vendor = false; $vendor = false;

View File

@ -111,6 +111,10 @@ trait AppSetup
'subject' => EmailTemplateDefaults::emailCreditSubject(), 'subject' => EmailTemplateDefaults::emailCreditSubject(),
'body' => EmailTemplateDefaults::emailCreditTemplate(), 'body' => EmailTemplateDefaults::emailCreditTemplate(),
], ],
'purchase_order' => [
'subject' => EmailTemplateDefaults::emailPurchaseOrderSubject(),
'body' => EmailTemplateDefaults::emailPurchaseOrderTemplate(),
],
]; ];
Cache::forever($name, $data); Cache::forever($name, $data);

View File

@ -228,59 +228,6 @@ trait MakesTemplateData
$data['$vendor.billing_postal_code'] = &$data['$vendor.postal_code']; $data['$vendor.billing_postal_code'] = &$data['$vendor.postal_code'];
$data['$vendor.billing_country'] = &$data['$vendor.country']; $data['$vendor.billing_country'] = &$data['$vendor.country'];
//$data['$paid_to_date'] = ;
// $data['$your_invoice'] = ;
// $data['$quote'] = ;
// $data['$your_quote'] = ;
// $data['$invoice_issued_to'] = ;
// $data['$quote_issued_to'] = ;
// $data['$rate'] = ;
// $data['$hours'] = ;
// $data['$from'] = ;
// $data['$to'] = ;
// $data['$invoice_to'] = ;
// $data['$quote_to'] = ;
// $data['$details'] = ;
// $data['custom_label1'] = ['value' => '', 'label' => ctrans('texts.')];
// $data['custom_label2'] = ['value' => '', 'label' => ctrans('texts.')];
// $data['custom_label3'] = ['value' => '', 'label' => ctrans('texts.')];
// $data['custom_label4'] = ['value' => '', 'label' => ctrans('texts.')];
//$data['$blank'] = ;
//$data['$surcharge'] = ;
/*
$data['$tax_invoice'] =
$data['$tax_quote'] =
$data['$statement'] = ;
$data['$statement_date'] = ;
$data['$your_statement'] = ;
$data['$statement_issued_to'] = ;
$data['$statement_to'] = ;
$data['$credit_note'] = ;
$data['$credit_date'] = ;
$data['$credit_issued_to'] = ;
$data['$credit_to'] = ;
$data['$your_credit'] = ;
$data['$phone'] = ;
$data['$outstanding'] = ;
$data['$invoice_due_date'] = ;
$data['$quote_due_date'] = ;
$data['$service'] = ;
$data['$product_key'] = ;
$data['$unit_cost'] = ;
$data['$custom_value1'] = ;
$data['$custom_value2'] = ;
$data['$delivery_note'] = ;
$data['$date'] = ;
$data['$method'] = ;
$data['$payment_date'] = ;
$data['$reference'] = ;
$data['$amount'] = ;
$data['$amount_paid'] =;
*/
$arrKeysLength = array_map('strlen', array_keys($data)); $arrKeysLength = array_map('strlen', array_keys($data));
array_multisort($arrKeysLength, SORT_DESC, $data); array_multisort($arrKeysLength, SORT_DESC, $data);

View File

@ -341,7 +341,7 @@ $entity_images
'product-table', 'task-table', 'delivery-note-table', 'product-table', 'task-table', 'delivery-note-table',
'statement-invoice-table', 'statement-payment-table', 'statement-aging-table-totals', 'statement-invoice-table', 'statement-payment-table', 'statement-aging-table-totals',
'statement-invoice-table-totals', 'statement-payment-table-totals', 'statement-aging-table', 'statement-invoice-table-totals', 'statement-payment-table-totals', 'statement-aging-table',
'client-details','vendor-details' 'client-details','vendor-details', 'swiss-qr'
]; ];
tables.forEach((tableIdentifier) => { tables.forEach((tableIdentifier) => {