Skip to content

Commit

Permalink
NEW checkbox to choose thirdparty nature (#30192)
Browse files Browse the repository at this point in the history
* New checkbox to choose thirdparty nature

* fix some values

* fix display for fields

---------

Co-authored-by: Hystepik <lmarcouiller@nltechno.com>
  • Loading branch information
Hystepik and Hystepik authored Jul 1, 2024
1 parent 4170bd4 commit f7c0253
Showing 1 changed file with 109 additions and 103 deletions.
212 changes: 109 additions & 103 deletions htdocs/societe/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -1350,18 +1359,44 @@ function formatCustomerSelection (selection) {
print '<tr id="name_alias"><td><label for="name_alias_input">'.$langs->trans('AliasNames').'</label></td>';
print '<td colspan="3"><input type="text" class="minwidth300" name="name_alias" id="name_alias_input" value="'.dol_escape_htmltag($object->name_alias).'"></td></tr>';

// Prospect/Customer
print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
print '<td class="maxwidthonsmartphone">';
$selected = (GETPOSTISSET('client') ? GETPOSTINT('client') : $object->client);
print $formcompany->selectProspectCustomerType($selected);
print '</td>';

if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
// 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 '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
$selectedprospect = (GETPOSTISSET('prospect') ? GETPOSTINT('prospect') : $selectedprospect);
$selectedcustomer = (GETPOSTISSET('customer') ? GETPOSTINT('customer') : $selectedcustomer);
print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('NatureOfThirdParty', 'customerprospect', '', $object, 0, 'string', '', 0).'</td>';
print '<td class="maxwidthonsmartphone" colspan="3">';
print '<span class="customer-back opacitymedium">'.$langs->trans("Prospect").'</span><input id="prospect" class="flat checkforselect marginleftonly" type="checkbox" name="prospect" value="2"'.($selectedprospect ? ' checked="checked"' : '').'>';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

print '<span class="customer-back">'.$langs->trans("Customer").'</span><input id="customer" class="flat checkforselect marginleftonly" type="checkbox" name="customer" value="1"'.($selectedcustomer ? ' checked="checked"' : '').'>';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

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 '<span class="vendor-back">'.$langs->trans("Vendor").'</span><input id="supplier" class="flat checkforselect marginleftonly" type="checkbox" name="supplier" value="1"'.($selected ? ' checked="checked"' : '').'>';
}
print '</td>';
print '</tr>';
print '<tr><td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
print '<table class="nobordernopadding"><tr><td>';
$tmpcode = $object->code_client;
if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
Expand All @@ -1372,44 +1407,22 @@ function formatCustomerSelection (selection) {
$s = $modCodeClient->getToolTip($langs, $object, 0);
print $form->textwithpicto('', $s, 1);
print '</td></tr></table>';
print '</td></tr>';

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 '<tr>';
print '<td>'.$form->editfieldkey('Vendor', 'fournisseur', '', $object, 0, 'string', '', 1).'</td><td>';
$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 '</td>';


if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>'.$form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0).'</td><td>';

print '<td>';
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 '<table class="nobordernopadding"><tr><td>';
$tmpcode = $object->code_fournisseur;
if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
$tmpcode = $modCodeFournisseur->getNextValue($object, 1);
}
print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
print '</td><td>';
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 '<table class="nobordernopadding"><tr><td>';
$tmpcode = $object->code_fournisseur;
if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
$tmpcode = $modCodeFournisseur->getNextValue($object, 1);
}
print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
print '</td><td>';
$s = $modCodeFournisseur->getToolTip($langs, $object, 1);
print $form->textwithpicto('', $s, 1);
print '</td></tr></table>';
}
print '</td></tr>';
$s = $modCodeFournisseur->getToolTip($langs, $object, 1);
print $form->textwithpicto('', $s, 1);
print '</td></tr></table>';
}
print '</td></tr>';

// Status
print '<tr><td>'.$form->editfieldkey('Status', 'status', '', $object, 0).'</td><td colspan="3">';
Expand Down Expand Up @@ -2090,78 +2103,71 @@ function init_supplier_categ() {
print '</td>';
}

// Prospect/Customer
print '<tr><td>'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).'</td>';
print '<td class="maxwidthonsmartphone">';
print $formcompany->selectProspectCustomerType($object->client);
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
// 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 '<td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';

$selectedprospect = (GETPOSTISSET('prospect') ? GETPOSTINT('prospect') : $selectedprospect);
$selectedcustomer = (GETPOSTISSET('customer') ? GETPOSTINT('customer') : $selectedcustomer);
print '<tr><td class="titlefieldcreate">'.$form->editfieldkey('NatureOfThirdParty', 'customerprospect', '', $object, 0, 'string', '', 0).'</td>';
print '<td class="maxwidthonsmartphone" colspan="3">';
print '<span class="customer-back opacitymedium">'.$langs->trans("Prospect").'</span><input id="prospect" class="flat checkforselect marginleftonly" type="checkbox" name="prospect" value="2"'.($selectedprospect ? ' checked="checked"' : '').'>';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

print '<span class="customer-back">'.$langs->trans("Customer").'</span><input id="customer" class="flat checkforselect marginleftonly" type="checkbox" name="customer" value="1"'.($selectedcustomer ? ' checked="checked"' : '').'>';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

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 '<span class="vendor-back">'.$langs->trans("Vendor").'</span><input id="supplier" class="flat checkforselect marginleftonly" type="checkbox" name="supplier" value="1"'.($selected ? ' checked="checked"' : '').'>';
}
print '</td>';
print '</tr>';
print '<tr><td>'.$form->editfieldkey('CustomerCode', 'customer_code', '', $object, 0).'</td><td>';
print '<table class="nobordernopadding"><tr><td>';
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 '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
} elseif ($object->codeclient_modifiable()) {
print '<input type="text" name="customer_code" id="customer_code" size="16" value="'.dol_escape_htmltag($object->code_client).'" maxlength="24">';
} else {
print $object->code_client;
print '<input type="hidden" name="customer_code" value="'.dol_escape_htmltag($object->code_client).'">';
$tmpcode = $object->code_client;
if (empty($tmpcode) && !empty($modCodeClient->code_auto)) {
$tmpcode = $modCodeClient->getNextValue($object, 0);
}
print '<input type="text" name="customer_code" id="customer_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
print '</td><td>';
$s = $modCodeClient->getToolTip($langs, $object, 0);
print $form->textwithpicto('', $s, 1);
print '</td></tr></table>';

print '</td></tr>';
print '<td>'.$form->editfieldkey('SupplierCode', 'supplier_code', '', $object, 0).'</td><td>';

// 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 '<tr>';
print '<td>'.$form->editfieldkey('Supplier', 'fournisseur', '', $object, 0, 'string', '', 1).'</td>';
print '<td class="maxwidthonsmartphone">';
print $form->selectyesno("fournisseur", $object->fournisseur, 1, false, 0, 1);
print '</td>';
if ($conf->browser->layout == 'phone') {
print '</tr><tr>';
}
print '<td>';
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 '</td>';
print '<td>';
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 '<table class="nobordernopadding"><tr><td>';
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 '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
} elseif ($object->codefournisseur_modifiable()) {
print '<input type="text" name="supplier_code" id="supplier_code" size="16" value="'.dol_escape_htmltag($object->code_fournisseur).'" maxlength="24">';
} else {
print $object->code_fournisseur;
print '<input type="hidden" name="supplier_code" value="'.$object->code_fournisseur.'">';
$tmpcode = $object->code_fournisseur;
if (empty($tmpcode) && !empty($modCodeFournisseur->code_auto)) {
$tmpcode = $modCodeFournisseur->getNextValue($object, 1);
}
print '<input type="text" name="supplier_code" id="supplier_code" class="maxwidthonsmartphone" value="'.dol_escape_htmltag($tmpcode).'" maxlength="24">';
print '</td><td>';
$s = $modCodeFournisseur->getToolTip($langs, $object, 1);
print $form->textwithpicto('', $s, 1);
print '</td></tr></table>';
print '</td></tr>';
}
print '</td></tr>';


// Barcode
if (isModEnabled('barcode')) {
Expand Down

0 comments on commit f7c0253

Please sign in to comment.