From b272877fe20ca1149bebdf731c0ae2a560e926d7 Mon Sep 17 00:00:00 2001 From: Anthony Berton Date: Fri, 18 Nov 2022 16:20:52 +0100 Subject: [PATCH] Sponge and FIx and optimise --- htdocs/admin/facture.php | 2 +- htdocs/admin/pdf_other.php | 22 ++++--- .../modules/facture/doc/pdf_crabe.modules.php | 40 +++++++----- .../facture/doc/pdf_sponge.modules.php | 65 +++++++++++++++++-- .../modules/facture/mod_facture_mercure.php | 22 +++++-- htdocs/langs/en_US/admin.lang | 2 + htdocs/langs/en_US/bills.lang | 3 +- 7 files changed, 119 insertions(+), 37 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index d2e1ec4ea25..2dd2f242a05 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -754,7 +754,7 @@ print ''; print ''; print $langs->trans("ForceInvoiceDate"); print ''; -print $form->selectyesno("forcedate", $conf->global->FAC_FORCE_DATE_VALIDATION, 1); +print $form->selectyesno("forcedate", getDolGlobalInt('FAC_FORCE_DATE_VALIDATION')?$conf->global->FAC_FORCE_DATE_VALIDATION:0, 1); print ''; print ''; print "\n"; diff --git a/htdocs/admin/pdf_other.php b/htdocs/admin/pdf_other.php index f2f9f83f67c..3a10bd8f2e8 100644 --- a/htdocs/admin/pdf_other.php +++ b/htdocs/admin/pdf_other.php @@ -69,6 +69,10 @@ if ($action == 'update') { dolibarr_set_const($db, "INVOICE_ADD_SWISS_QR_CODE", GETPOST("INVOICE_ADD_SWISS_QR_CODE", 'int'), 'chaine', 0, '', $conf->entity); dolibarr_del_const($db, "INVOICE_ADD_ZATCA_QR_CODE", $conf->entity); } + if (GETPOSTISSET('DOC_SHOW_SHIPPING_ADDRESS')) { + dolibarr_set_const($db, "DOC_SHOW_SHIPPING_ADDRESS", GETPOST("DOC_SHOW_SHIPPING_ADDRESS", 'int'), 'chaine', 0, '', $conf->entity); + dolibarr_del_const($db, "DOC_SHOW_SHIPPING_ADDRESS", $conf->entity); + } setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); @@ -155,16 +159,16 @@ if (isModEnabled('facture')) { } print ''; - /* - print ''.$langs->trans("MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING").''; - if ($conf->use_javascript_ajax) { - print ajax_constantonoff('MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING'); - } else { + print ''; + print $form->textwithpicto($langs->trans("INVOICE_SHOW_SHIPPING_ADDRESS"), $langs->trans("INVOICE_SHOW_SHIPPING_ADDRESSMore")); + print ''; + if ($conf->use_javascript_ajax) { + print ajax_constantonoff('INVOICE_SHOW_SHIPPING_ADDRESS'); + } else { $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes")); - print $form->selectarray("MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING", $arrval, $conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING); - } - print ''; - */ + print $form->selectarray("INVOICE_SHOW_SHIPPING_ADDRESS", $arrval, $conf->global->INVOICE_SHOW_SHIPPING_ADDRESS); + } + print ''; print ''; print ''; diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 8d68664b48f..fc08f9814d0 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -947,7 +947,8 @@ class pdf_crabe extends ModelePDFFactures $pdf->useTemplate($tplidx); } if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { - $this->_pagehead($pdf, $object, 0, $outputlangs); + $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs); + $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); } $pdf->setPage($current_page); $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height); @@ -1009,7 +1010,8 @@ class pdf_crabe extends ModelePDFFactures $pdf->useTemplate($tplidx); } if (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD')) { - $this->_pagehead($pdf, $object, 0, $outputlangs); + $top_shift = $this->_pagehead($pdf, $object, 0, $outputlangs); + $tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); } $pdf->setPage($current_page); $this->_tableau_versements_header($pdf, $object, $outputlangs, $default_font_size, $tab3_posx, $tab3_top + $y - 3, $tab3_width, $tab3_height); @@ -2028,6 +2030,25 @@ class pdf_crabe extends ModelePDFFactures $mode = 'target'; $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object); + $titelrecipient = $outputlangs->transnoentities("BillTo"); + + if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS') || $this->emetteur->country_code == 'FR') { + $idaddressshipping = $object->getIdContact('external', 'SHIPPING'); + + if (!empty($idaddressshipping)) { + $contactshipping = $object->fetch_Contact($idaddressshipping[0]); + $object->fetch_thirdparty($object->contact->fk_soc); + $carac_client_name_shipping=pdfBuildThirdpartyName($object->contact, $outputlangs); + $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, $usecontact, 'target', $object); + } else { + $carac_client_name_shipping=pdfBuildThirdpartyName($object->thirdparty, $outputlangs); + $carac_client_shipping=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);; + } + if ((isset($object->contact->socid) && $object->contact->socid == $object->socid) || !isset($object->contact->socid)) { + $titelrecipient = $outputlangs->transnoentities("BillShippTo"); + } + } + // Show recipient $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100; if ($this->page_largeur < 210) { @@ -2045,7 +2066,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetTextColor(0, 0, 0); $pdf->SetFont('', '', $default_font_size - 2); $pdf->SetXY($posx + 2, $posy - 5); - $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection); + $pdf->MultiCell($widthrecbox - 2, 5, $titelrecipient, 0, $ltrdirection); $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); } @@ -2062,18 +2083,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection); // Show shipping address - if (getDolGlobalInt('DOC_SHOW_SHIPPING_ADDRESS')) { - $idaddressshipping = $object->getIdContact('external', 'SHIPPING'); - - if (!empty($idaddressshipping)) { - $contactshipping = $object->fetch_Contact($idaddressshipping[0]); - $object->fetch_thirdparty($object->contact->fk_soc); - $carac_client_name_shipping=pdfBuildThirdpartyName($object->contact, $outputlangs); - $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, $usecontact, 'target', $object); - } else { - $carac_client_name_shipping=pdfBuildThirdpartyName($object->thirdparty, $outputlangs); - $carac_client_shipping=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);; - } + if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS') || $this->emetteur->country_code == 'FR') { if (!empty($carac_client_shipping) && (isset($object->contact->socid) && $object->contact->socid != $object->socid)) { $posy += $hautcadre; diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index e11cd90bc43..3f001f1c5d2 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -448,7 +448,9 @@ class pdf_sponge extends ModelePDFFactures $pagenb++; // Output header (logo, ref and address blocks). This is first call for first page. - $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis); + $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis); + $top_shift = $pagehead['top_shift']; + $shipp_shift = $pagehead['shipp_shift']; $pdf->SetFont('', '', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0, 0, 0); @@ -456,7 +458,7 @@ class pdf_sponge extends ModelePDFFactures // $pdf->GetY() here can't be used. It is bottom of the second addresse box but first one may be higher // $this->tab_top is y where we must continue content (90 = 42 + 48: 42 is height of logo and ref, 48 is address blocks) - $this->tab_top = 90 + $top_shift; // top_shift is an addition for linked objects or addons (0 in most cases) + $this->tab_top = 90 + $top_shift + $shipp_shift; // top_shift is an addition for linked objects or addons (0 in most cases) $this->tab_top_newpage = (!getDolGlobalInt('MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10); // You can add more thing under header here, if you increase $extra_under_address_shift too. @@ -1290,7 +1292,7 @@ class pdf_sponge extends ModelePDFFactures // Decret n°2099-1299 2022-10-07 // French mention : "Option pour le paiement de la taxe d'après les débits" if ($this->emetteur->country_code == 'FR') { - if ($conf->global->TAX_MODE == 1) { + if (isset($conf->global->TAX_MODE) && $conf->global->TAX_MODE == 1) { $pdf->SetXY($this->marge_gauche, $posy); $pdf->writeHTMLCell(80, 5, '', '', $outputlangs->transnoentities("MentionVATDebitOptionIsOn"), 0, 1); @@ -2222,6 +2224,7 @@ class pdf_sponge extends ModelePDFFactures $posy += 1; $top_shift = 0; + $shipp_shift = 0; // Show list of linked objects $current_y = $pdf->getY(); $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size); @@ -2244,7 +2247,6 @@ class pdf_sponge extends ModelePDFFactures $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40; $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82; - // Show sender frame if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) { $pdf->SetTextColor(0, 0, 0); @@ -2290,6 +2292,25 @@ class pdf_sponge extends ModelePDFFactures $mode = 'target'; $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object); + $titelrecipient = $outputlangs->transnoentities("BillTo"); + + if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS') || $this->emetteur->country_code == 'FR') { + $idaddressshipping = $object->getIdContact('external', 'SHIPPING'); + + if (!empty($idaddressshipping)) { + $contactshipping = $object->fetch_Contact($idaddressshipping[0]); + $object->fetch_thirdparty($object->contact->fk_soc); + $carac_client_name_shipping=pdfBuildThirdpartyName($object->contact, $outputlangs); + $carac_client_shipping = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, $object->contact, $usecontact, 'target', $object); + } else { + $carac_client_name_shipping=pdfBuildThirdpartyName($object->thirdparty, $outputlangs); + $carac_client_shipping=pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'target', $object);; + } + if ((isset($object->contact->socid) && $object->contact->socid == $object->socid) || !isset($object->contact->socid)) { + $titelrecipient = $outputlangs->transnoentities("BillShippTo"); + } + } + // Show recipient $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100; if ($this->page_largeur < 210) { @@ -2307,7 +2328,7 @@ class pdf_sponge extends ModelePDFFactures $pdf->SetTextColor(0, 0, 0); $pdf->SetFont('', '', $default_font_size - 2); $pdf->SetXY($posx + 2, $posy - 5); - $pdf->MultiCell($widthrecbox - 2, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection); + $pdf->MultiCell($widthrecbox - 2, 5, $titelrecipient, 0, $ltrdirection); $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); } @@ -2322,10 +2343,42 @@ class pdf_sponge extends ModelePDFFactures $pdf->SetFont('', '', $default_font_size - 1); $pdf->SetXY($posx + 2, $posy); $pdf->MultiCell($widthrecbox - 2, 4, $carac_client, 0, $ltrdirection); + + // Show shipping address + if (getDolGlobalInt('INVOICE_SHOW_SHIPPING_ADDRESS') || $this->emetteur->country_code == 'FR') { + if (!empty($carac_client_shipping) && (isset($object->contact->socid) && $object->contact->socid != $object->socid)) { + $posy += $hautcadre; + + // Show shipping frame + $pdf->SetXY($posx + 2, $posy - 5); + $pdf->SetFont('', '', $default_font_size - 2); + $pdf->MultiCell($widthrecbox, '', $langs->trans('ShippingTo'), 0, 'L', 0); + $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); + + // Show shipping name + $pdf->SetXY($posx + 2, $posy + 3); + $pdf->SetFont('', 'B', $default_font_size); + $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_name_shipping, '', 'L'); + + $posy = $pdf->getY(); + + // Show shipping information + $pdf->SetXY($posx+2, $posy); + $pdf->SetFont('', '', $default_font_size - 1); + $pdf->MultiCell($widthrecbox - 2, 2, $carac_client_shipping, '', 'L'); + $shipp_shift += $hautcadre; + } + } } $pdf->SetTextColor(0, 0, 0); - return $top_shift; + + // $pagehead = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis); + // $top_shift = $pagehead->top_shift; + // $shipp_shift = $pagehead->shipp_shift; + + $pagehead = array('top_shift' => $top_shift, 'shipp_shift' => $shipp_shift); + return $pagehead; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore diff --git a/htdocs/core/modules/facture/mod_facture_mercure.php b/htdocs/core/modules/facture/mod_facture_mercure.php index 7a572615a21..7692568feff 100644 --- a/htdocs/core/modules/facture/mod_facture_mercure.php +++ b/htdocs/core/modules/facture/mod_facture_mercure.php @@ -143,16 +143,28 @@ class mod_facture_mercure extends ModeleNumRefFactures // Get Mask value $mask = ''; if (is_object($invoice) && $invoice->type == 1) { - $mask = $conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; + if (isset($conf->global->FACTURE_MERCURE_MASK_REPLACEMENT)) { + $mask = $conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; + } if (!$mask) { - $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE; + if (isset($conf->global->FACTURE_MERCURE_MASK_INVOICE)) { + $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE; + } } } elseif (is_object($invoice) && $invoice->type == 2) { - $mask = $conf->global->FACTURE_MERCURE_MASK_CREDIT; + if (isset($conf->global->FACTURE_MERCURE_MASK_CREDIT)) { + $mask = $conf->global->FACTURE_MERCURE_MASK_CREDIT; + } } elseif (is_object($invoice) && $invoice->type == 3) { - $mask = $conf->global->FACTURE_MERCURE_MASK_DEPOSIT; + if (isset($conf->global->FACTURE_MERCURE_MASK_DEPOSIT)) { + $mask = $conf->global->FACTURE_MERCURE_MASK_DEPOSIT; + } } else { - $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE; + if (isset($conf->global->FACTURE_MERCURE_MASK_INVOICE)) { + $mask = $conf->global->FACTURE_MERCURE_MASK_INVOICE; + } else { + $mask = ''; + } } if (!$mask) { $this->error = 'NotConfigured'; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 2cd9d55aefb..adec92ba029 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2299,6 +2299,8 @@ IconOnly=Icon only - Text on tooltip only INVOICE_ADD_ZATCA_QR_CODE=Show the ZATCA QR code on invoices INVOICE_ADD_ZATCA_QR_CODEMore=Some Arabic countries need this QR Code on their invoices INVOICE_ADD_SWISS_QR_CODE=Show the swiss QR-Bill code on invoices +INVOICE_SHOW_SHIPPING_ADDRESS=Show shipping address +INVOICE_SHOW_SHIPPING_ADDRESSMore=Compulsory mention for France UrlSocialNetworksDesc=Url link of social network. Use {socialid} for the variable part that contains the social network ID. IfThisCategoryIsChildOfAnother=If this category is a child of another one DarkThemeMode=Dark theme mode diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index d7c29a82399..b631fada41b 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -161,7 +161,8 @@ ErrorCantCancelIfReplacementInvoiceNotValidated=Error, can't cancel an invoice t ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved=This part or another is already used so discount series cannot be removed. ErrorInvoiceIsNotLastOfSameType=Error: The date of invoice %s is %s. It must be posterior or equal to last date for same type invoices (%s). Please change the invoice date. BillFrom=From -BillTo=To +BillTo=Address to +BillShippTo=Address and shipping to ShippingTo=Shipping to ActionsOnBill=Actions on invoice RecurringInvoiceTemplate=Template / Recurring invoice