From f7c0253035f901dace4c8323a38fa233562ee3ad Mon Sep 17 00:00:00 2001 From: Lucas Marcouiller <45882981+Hystepik@users.noreply.github.com> Date: Mon, 1 Jul 2024 14:18:56 +0200 Subject: [PATCH] NEW checkbox to choose thirdparty nature (#30192) * New checkbox to choose thirdparty nature * fix some values * fix display for fields --------- Co-authored-by: Hystepik --- htdocs/societe/card.php | 212 +++++++++++++++++++++------------------- 1 file changed, 109 insertions(+), 103 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 075670f105b21..31d8b9f79f69d 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -283,11 +283,15 @@ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors'); $error++; } - if (GETPOSTINT('client') && GETPOSTINT('client') < 0) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors'); + if (GETPOSTINT('customer') && GETPOSTINT('customer') < 0) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Customer")), null, 'errors'); $error++; } - if (GETPOSTISSET('fournisseur') && GETPOSTINT('fournisseur') < 0) { + if (GETPOSTINT('prospect') && GETPOSTINT('prospect') < 0) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Prospect")), null, 'errors'); + $error++; + } + if (GETPOSTISSET('supplier') && GETPOSTINT('supplier') < 0) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors'); $error++; } @@ -375,8 +379,13 @@ $object->typent_code = dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type - $object->client = GETPOSTINT('client'); - $object->fournisseur = GETPOSTINT('fournisseur'); + // Calculate the type of the thirdparty + $customer = (GETPOSTINT('customer') > 0 ? 1 : 0); + $prospect = (GETPOSTINT('prospect') > 0 ? 2 : 0); + $prospectcustomer = $customer + $prospect; + + $object->client = $prospectcustomer; + $object->fournisseur = (GETPOSTINT('supplier') > 0 ? 1 : 0); $object->commercial_id = GETPOSTINT('commercial_id'); $object->default_lang = GETPOST('default_lang'); @@ -1350,18 +1359,44 @@ function formatCustomerSelection (selection) { print ''; print ''; - // Prospect/Customer - print ''.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).''; - print ''; - $selected = (GETPOSTISSET('client') ? GETPOSTINT('client') : $object->client); - print $formcompany->selectProspectCustomerType($selected); - print ''; - - if ($conf->browser->layout == 'phone') { - print ''; + // Prospect/Customer/Supplier + $selected = $object->client; + $selectedcustomer = 0; + $selectedprospect = 0; + switch ($selected) { + case 1: + $selectedcustomer = 1; + break; + case 2: + $selectedprospect = 1; + break; + case 3: + $selectedprospect = 1; + $selectedcustomer = 1; + break; + default: + break; } - print ''.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).''; + $selectedprospect = (GETPOSTISSET('prospect') ? GETPOSTINT('prospect') : $selectedprospect); + $selectedcustomer = (GETPOSTISSET('customer') ? GETPOSTINT('customer') : $selectedcustomer); + print ''.$form->editfieldkey('NatureOfThirdParty', 'customerprospect', '', $object, 0, 'string', '', 0).''; + print ''; + print ''.$langs->trans("Prospect").''; + print '      '; + + print ''.$langs->trans("Customer").''; + print '      '; + + if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire')) + || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) { + // Supplier + $selected = (GETPOSTISSET('supplier') ? GETPOSTINT('supplier') : $object->fournisseur); + print ''.$langs->trans("Vendor").''; + } + print ''; + print ''; + print ''.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).''; print '
'; $tmpcode = $object->code_client; if (empty($tmpcode) && !empty($modCodeClient->code_auto)) { @@ -1372,44 +1407,22 @@ function formatCustomerSelection (selection) { $s = $modCodeClient->getToolTip($langs, $object, 0); print $form->textwithpicto('', $s, 1); print '
'; - print ''; - - if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire')) - || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) { - // Supplier - print ''; - print ''.$form->editfieldkey('Vendor', 'fournisseur', '', $object, 0, 'string', '', 1).''; - $default = -1; - if (getDolGlobalString('THIRDPARTY_SUPPLIER_BY_DEFAULT')) { - $default = 1; - } - print $form->selectyesno("fournisseur", (GETPOSTINT('fournisseur') != '' ? GETPOSTINT('fournisseur') : (GETPOSTINT("type") == '' ? $default : $object->fournisseur)), 1, 0, (GETPOSTINT("type") == '' ? 1 : 0), 1); - print ''; - - if ($conf->browser->layout == 'phone') { - print ''; - } + print ''.$form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0).''; - print ''; - if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) { - print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0); + if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) { + print ''; + $s = $modCodeFournisseur->getToolTip($langs, $object, 1); + print $form->textwithpicto('', $s, 1); + print '
'; + $tmpcode = $object->code_fournisseur; + if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) { + $tmpcode = $modCodeFournisseur->getNextValue($object, 1); } + print ''; print ''; - if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) { - print '
'; - $tmpcode = $object->code_fournisseur; - if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) { - $tmpcode = $modCodeFournisseur->getNextValue($object, 1); - } - print ''; - print ''; - $s = $modCodeFournisseur->getToolTip($langs, $object, 1); - print $form->textwithpicto('', $s, 1); - print '
'; - } - print '
'; } + print ''; // Status print ''.$form->editfieldkey('Status', 'status', '', $object, 0).''; @@ -2090,78 +2103,71 @@ function init_supplier_categ() { print ''; } - // Prospect/Customer - print ''.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).''; - print ''; - print $formcompany->selectProspectCustomerType($object->client); - print ''; - if ($conf->browser->layout == 'phone') { - print ''; + // Prospect/Customer/Supplier + $selected = $object->client; + $selectedcustomer = 0; + $selectedprospect = 0; + switch ($selected) { + case 1: + $selectedcustomer = 1; + break; + case 2: + $selectedprospect = 1; + break; + case 3: + $selectedprospect = 1; + $selectedcustomer = 1; + break; + default: + break; } - print ''.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).''; + $selectedprospect = (GETPOSTISSET('prospect') ? GETPOSTINT('prospect') : $selectedprospect); + $selectedcustomer = (GETPOSTISSET('customer') ? GETPOSTINT('customer') : $selectedcustomer); + print ''.$form->editfieldkey('NatureOfThirdParty', 'customerprospect', '', $object, 0, 'string', '', 0).''; + print ''; + print ''.$langs->trans("Prospect").''; + print '      '; + + print ''.$langs->trans("Customer").''; + print '      '; + + if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire')) + || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) { + // Supplier + $selected = (GETPOSTISSET('supplier') ? GETPOSTINT('supplier') : $object->fournisseur); + print ''.$langs->trans("Vendor").''; + } + print ''; + print ''; + print ''.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).''; print '
'; - if ((!$object->code_client || $object->code_client == -1) && $modCodeClient->code_auto) { - $tmpcode = $object->code_client; - if (empty($tmpcode) && !empty($object->oldcopy->code_client)) { - $tmpcode = $object->oldcopy->code_client; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value. - } - if (empty($tmpcode) && !empty($modCodeClient->code_auto)) { - $tmpcode = $modCodeClient->getNextValue($object, 0); - } - print ''; - } elseif ($object->codeclient_modifiable()) { - print ''; - } else { - print $object->code_client; - print ''; + $tmpcode = $object->code_client; + if (empty($tmpcode) && !empty($modCodeClient->code_auto)) { + $tmpcode = $modCodeClient->getNextValue($object, 0); } + print ''; print ''; $s = $modCodeClient->getToolTip($langs, $object, 0); print $form->textwithpicto('', $s, 1); print '
'; - print ''; + print ''.$form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0).''; - // Supplier - if (((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) - || (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire'))) { - print ''; - print ''.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).''; - print ''; - print $form->selectyesno("fournisseur", $object->fournisseur, 1, false, 0, 1); - print ''; - if ($conf->browser->layout == 'phone') { - print ''; - } - print ''; - if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) { - print $form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0); - } - print ''; - print ''; + if ((isModEnabled("fournisseur") && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire'))) { print '
'; - if ((!$object->code_fournisseur || $object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) { - $tmpcode = $object->code_fournisseur; - if (empty($tmpcode) && !empty($object->oldcopy->code_fournisseur)) { - $tmpcode = $object->oldcopy->code_fournisseur; // When there is an error to update a thirdparty, the number for supplier and customer code is kept to old value. - } - if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) { - $tmpcode = $modCodeFournisseur->getNextValue($object, 1); - } - print ''; - } elseif ($object->codefournisseur_modifiable()) { - print ''; - } else { - print $object->code_fournisseur; - print ''; + $tmpcode = $object->code_fournisseur; + if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) { + $tmpcode = $modCodeFournisseur->getNextValue($object, 1); } + print ''; print ''; $s = $modCodeFournisseur->getToolTip($langs, $object, 1); print $form->textwithpicto('', $s, 1); print '
'; - print ''; } + print ''; + // Barcode if (isModEnabled('barcode')) {