From 960aaded8eba83f58c0a04f056869f9e28b6a694 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 9 Jan 2022 21:08:06 +0100 Subject: [PATCH] NEW Thirdparty - Add rules customer accountancy code is mandatory to validate invoice --- htdocs/compta/facture/card.php | 10 +++++- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/langs/en_US/errors.lang | 2 ++ htdocs/societe/admin/societe.php | 31 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index c7376f961f8..7881c76ff80 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -607,7 +607,7 @@ if (empty($reshook)) { // Check parameters // Check for mandatory fields in thirdparty (defined into setup) - $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL'); + $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL', 'ACCOUNTANCY_CODE_CUSTOMER'); foreach ($array_to_check as $key) { $keymin = strtolower($key); $i = (int) preg_replace('/[^0-9]/', '', $key); @@ -635,6 +635,14 @@ if (empty($reshook)) { setEventMessages($langs->trans("ErrorBadEMail", $object->thirdparty->email).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors'); } } + if ($key == 'ACCOUNTANCY_CODE_CUSTOMER') { + // Check for mandatory + if (!empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_INVOICE_MANDATORY) && empty($object->thirdparty->code_compta)) { + $langs->load("errors"); + $error++; + setEventMessages($langs->trans("ErrorAccountancyCodeCustomerIsMandatory", $object->thirdparty->name).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors'); + } + } } } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 4f72b5a14a3..57d0f347913 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1622,7 +1622,7 @@ class Facture extends CommonInvoice if ($rowid) { $sql .= " WHERE f.rowid=".((int) $rowid); } else { - $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')'; // Dont't use entity if you use rowid + $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')'; // Don't use entity if you use rowid if ($ref) { $sql .= " AND f.ref='".$this->db->escape($ref)."'"; } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 7f4ca7b074f..1f00d2fe5eb 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -27,7 +27,9 @@ ErrorThisContactIsAlreadyDefinedAsThisType=This contact is already defined as co ErrorCashAccountAcceptsOnlyCashMoney=This bank account is a cash account, so it accepts payments of type cash only. ErrorFromToAccountsMustDiffers=Source and targets bank accounts must be different. ErrorBadThirdPartyName=Bad value for third-party name +ForbiddenBySetupRules=Forbidden by setup rules ErrorProdIdIsMandatory=The %s is mandatory +ErrorAccountancyCodeCustomerIsMandatory=The accountancy code of customer %s is mandatory ErrorBadCustomerCodeSyntax=Bad syntax for customer code ErrorBadBarCodeSyntax=Bad syntax for barcode. May be you set a bad barcode type or you defined a barcode mask for numbering that does not match value scanned. ErrorCustomerCodeRequired=Customer code required diff --git a/htdocs/societe/admin/societe.php b/htdocs/societe/admin/societe.php index 2f272ceca1c..9e1fb330019 100644 --- a/htdocs/societe/admin/societe.php +++ b/htdocs/societe/admin/societe.php @@ -169,6 +169,20 @@ if ($action == 'setdoc') { } } +//Activate Set accountancy code customer invoice mandatory +if ($action == "setaccountancycodecustomerinvoicemandatory") { + $setaccountancycodecustomerinvoicemandatory = GETPOST('value', 'int'); + $res = dolibarr_set_const($db, "SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_INVOICE_MANDATORY", $setaccountancycodecustomerinvoicemandatory, 'yesno', 0, '', $conf->entity); + if (!($res > 0)) { + $error++; + } + if (!$error) { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } else { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} + //Activate Set ref in list if ($action == "setaddrefinlist") { $setaddrefinlist = GETPOST('value', 'int'); @@ -709,6 +723,23 @@ foreach ($profid as $key => $val) { $i++; } +if ($conf->accounting->enabled) { + print ''; + print ''.$langs->trans('CustomerAccountancyCodeShort')."\n"; + print ''; + + if (!empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_INVOICE_MANDATORY)) { + print ''; + print img_picto($langs->trans("Activated"), 'switch_on'); + print ''; + } else { + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; + } + print "\n"; +} + print "\n"; print '';