diff --git a/app/Helpers/SwissQr/SwissQrGenerator.php b/app/Helpers/SwissQr/SwissQrGenerator.php index e0e6766211e0..354b76392190 100644 --- a/app/Helpers/SwissQr/SwissQrGenerator.php +++ b/app/Helpers/SwissQr/SwissQrGenerator.php @@ -24,11 +24,11 @@ class SwissQrGenerator protected Company $company; - protected Invoice $invoice; + protected $invoice; protected Client $client; - public function __construct(Invoice $invoice, Company $company) + public function __construct($invoice, Company $company) { $this->company = $company; @@ -86,11 +86,11 @@ class SwissQrGenerator // They are interchangeable for creditor as well as debtor. $qrBill->setUltimateDebtor( QrBill\DataGroup\Element\StructuredAddress::createWithStreet( - $this->client->present()->name(), - $this->client->address1 ?: '', - $this->client->address2 ?: '', - $this->client->postal_code ?: '', - $this->client->city ?: '', + substr($this->client->present()->name(), 0 , 70), + $this->client->address1 ? substr($this->client->address1, 0 , 70) : '', + $this->client->address2 ? substr($this->client->address2, 0 , 16) : '', + $this->client->postal_code ? substr($this->client->postal_code, 0, 16) : '', + $this->client->city ? substr($this->client->postal_code, 0, 35) : '', 'CH' )); @@ -106,7 +106,7 @@ class SwissQrGenerator // This is what you will need to identify incoming payments. $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->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( @@ -124,23 +124,28 @@ class SwissQrGenerator // Now get the QR code image and save it as a file. - try { - // $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png'); - // $qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg'); - } catch (\Exception $e) { - foreach($qrBill->getViolations() as $key => $violation) { - } + try { - // 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; } } \ No newline at end of file diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index be970d56d692..1edd5cc6ae76 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -284,12 +284,11 @@ class PreviewController extends BaseController } catch(\Exception $e){ - + nlog($e->getMessage()); DB::connection(config('database.default'))->rollBack(); return; } - //if phantom js...... inject here.. if (config('ninja.phantomjs_pdf_generation') || config('ninja.pdf_generator') == 'phantom') { return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true)); diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index 01be541aa1c0..a1e7beaaae2b 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -173,9 +173,27 @@ class Design extends BaseDesign $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 { $variables = $this->context['pdf_variables']['company_details']; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 160198d1d61b..ce5895a362ba 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -12,6 +12,7 @@ namespace App\Utils; +use App\Helpers\SwissQr\SwissQrGenerator; use App\Models\Country; use App\Models\CreditInvitation; use App\Models\GatewayType; @@ -162,6 +163,17 @@ class HtmlEngine if($this->entity->vendor) { $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') { @@ -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['$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.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')]; diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index 9f13195f808e..9acf3093ad42 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -27,6 +27,7 @@ use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesInvoiceHtml; use App\Utils\Traits\MakesTemplateData; +use App\Utils\VendorHtmlEngine; use DB; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Lang; @@ -157,7 +158,8 @@ class TemplateEngine } elseif ($this->entity_obj) { $this->entityValues($this->entity_obj->client->primary_contact()->first()); - } else { + } + else { $this->fakerValues(); } @@ -184,11 +186,13 @@ class TemplateEngine 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['values']); -// $this->body = str_replace("\n", "
", $this->body); $this->subject = strtr($this->subject, $this->labels_and_values['labels']); $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['company'] = $this->entity_obj ? $this->entity_obj->company : ''; $data['settings'] = $this->settings; + } @@ -263,6 +268,9 @@ class TemplateEngine private function mockEntity() { + if(!$this->entity && $this->template && str_contains($this->template, 'purchase_order')) + $this->entity = 'purchase_order'; + DB::connection(config('database.default'))->beginTransaction(); $vendor = false; diff --git a/app/Utils/Traits/AppSetup.php b/app/Utils/Traits/AppSetup.php index 66a6ed6d8847..68c135aa47df 100644 --- a/app/Utils/Traits/AppSetup.php +++ b/app/Utils/Traits/AppSetup.php @@ -111,6 +111,10 @@ trait AppSetup 'subject' => EmailTemplateDefaults::emailCreditSubject(), 'body' => EmailTemplateDefaults::emailCreditTemplate(), ], + 'purchase_order' => [ + 'subject' => EmailTemplateDefaults::emailPurchaseOrderSubject(), + 'body' => EmailTemplateDefaults::emailPurchaseOrderTemplate(), + ], ]; Cache::forever($name, $data); diff --git a/app/Utils/Traits/MakesTemplateData.php b/app/Utils/Traits/MakesTemplateData.php index ce4e844c5dc0..9c019bb0f652 100644 --- a/app/Utils/Traits/MakesTemplateData.php +++ b/app/Utils/Traits/MakesTemplateData.php @@ -228,59 +228,6 @@ trait MakesTemplateData $data['$vendor.billing_postal_code'] = &$data['$vendor.postal_code']; $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)); array_multisort($arrKeysLength, SORT_DESC, $data); diff --git a/resources/views/pdf-designs/clean.html b/resources/views/pdf-designs/clean.html index 706129159743..9230bf86aa44 100644 --- a/resources/views/pdf-designs/clean.html +++ b/resources/views/pdf-designs/clean.html @@ -341,7 +341,7 @@ $entity_images 'product-table', 'task-table', 'delivery-note-table', 'statement-invoice-table', 'statement-payment-table', 'statement-aging-table-totals', 'statement-invoice-table-totals', 'statement-payment-table-totals', 'statement-aging-table', - 'client-details','vendor-details' + 'client-details','vendor-details', 'swiss-qr' ]; tables.forEach((tableIdentifier) => {