Clean code

This commit is contained in:
Laurent Destailleur 2022-09-08 15:05:51 +02:00
parent c3f673c3ad
commit aa9036a0f5
13 changed files with 94 additions and 91 deletions

View File

@ -1791,7 +1791,7 @@ if ($action == 'create') {
// Terms of payment
print '<tr class="field_cond_reglement_id"><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
print img_picto('', 'paiment');
$form->select_conditions_paiements((GETPOSTISSET('cond_reglement_id') && GETPOST('cond_reglement_id') != 0) ? GETPOST('cond_reglement_id', 'int') : $soc->cond_reglement_id, 'cond_reglement_id', 1, 1, 0, '', (GETPOSTISSET('cond_reglement_id_deposit_percent') ? GETPOST('cond_reglement_id_deposit_percent', 'alpha') : $soc->deposit_percent));
print $form->getSelectConditionsPaiements((GETPOSTISSET('cond_reglement_id') && GETPOST('cond_reglement_id') != 0) ? GETPOST('cond_reglement_id', 'int') : $soc->cond_reglement_id, 'cond_reglement_id', 1, 1, 0, '', (GETPOSTISSET('cond_reglement_id_deposit_percent') ? GETPOST('cond_reglement_id_deposit_percent', 'alpha') : $soc->deposit_percent));
print '</td></tr>';
// Mode of payment

View File

@ -1232,7 +1232,7 @@ if ($resql) {
// Payment term
if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
print '<td class="liste_titre">';
$form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
print $form->getSelectConditionsPaiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
print '</td>';
}
// Payment mode

View File

@ -1813,7 +1813,7 @@ if ($action == 'create' && $usercancreate) {
// Terms of payment
print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
print img_picto('', 'payment', 'class="pictofixedwidth"');
$form->select_conditions_paiements($cond_reglement_id, 'cond_reglement_id', 1, 1, 0, 'maxwidth200 widthcentpercentminusx', $deposit_percent);
print $form->getSelectConditionsPaiements($cond_reglement_id, 'cond_reglement_id', 1, 1, 0, 'maxwidth200 widthcentpercentminusx', $deposit_percent);
print '</td></tr>';
// Payment mode
@ -2105,109 +2105,112 @@ if ($action == 'create' && $usercancreate) {
}
if ($nbMandated > 0 ) $text .= '<div><span class="clearboth nowraponall warning">'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'</span></div>';
if (getDolGlobalInt('SALE_ORDER_SUGGEST_DOWN_PAYMENT_INVOICE_CREATION')) {
// This is a hidden option:
// Suggestion to create invoice during order validation is not enabled by default.
// Such choice should be managed by the workflow module and trigger. This option generates conflicts with some setup.
// It may also break step of creating an order when invoicing must be done from proposals and not from orders
$deposit_percent_from_payment_terms = getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
$deposit_percent_from_payment_terms = getDictionaryValue('c_payment_term', 'deposit_percent', $object->cond_reglement_id);
if (!empty($deposit_percent_from_payment_terms) && !empty($conf->facture->enabled) && !empty($user->rights->facture->creer)) {
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
if (!empty($deposit_percent_from_payment_terms) && !empty($conf->facture->enabled) && !empty($user->rights->facture->creer)) {
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
$object->fetchObjectLinked();
$object->fetchObjectLinked();
$eligibleForDepositGeneration = true;
$eligibleForDepositGeneration = true;
if (array_key_exists('facture', $object->linkedObjects)) {
foreach ($object->linkedObjects['facture'] as $invoice) {
if ($invoice->type == Facture::TYPE_DEPOSIT) {
$eligibleForDepositGeneration = false;
break;
if (array_key_exists('facture', $object->linkedObjects)) {
foreach ($object->linkedObjects['facture'] as $invoice) {
if ($invoice->type == Facture::TYPE_DEPOSIT) {
$eligibleForDepositGeneration = false;
break;
}
}
}
}
if ($eligibleForDepositGeneration && array_key_exists('propal', $object->linkedObjects)) {
foreach ($object->linkedObjects['propal'] as $proposal) {
$proposal->fetchObjectLinked();
if ($eligibleForDepositGeneration && array_key_exists('propal', $object->linkedObjects)) {
foreach ($object->linkedObjects['propal'] as $proposal) {
$proposal->fetchObjectLinked();
if (array_key_exists('facture', $proposal->linkedObjects)) {
foreach ($proposal->linkedObjects['facture'] as $invoice) {
if ($invoice->type == Facture::TYPE_DEPOSIT) {
$eligibleForDepositGeneration = false;
break 2;
if (array_key_exists('facture', $proposal->linkedObjects)) {
foreach ($proposal->linkedObjects['facture'] as $invoice) {
if ($invoice->type == Facture::TYPE_DEPOSIT) {
$eligibleForDepositGeneration = false;
break 2;
}
}
}
}
}
}
if ($eligibleForDepositGeneration) {
$formquestion[] = array(
'type' => 'checkbox',
'tdclass' => '',
'name' => 'generate_deposit',
'label' => $form->textwithpicto($langs->trans('GenerateDeposit', $object->deposit_percent), $langs->trans('DepositGenerationPermittedByThePaymentTermsSelected'))
);
if ($eligibleForDepositGeneration) {
$formquestion[] = array(
'type' => 'checkbox',
'tdclass' => '',
'name' => 'generate_deposit',
'label' => $form->textwithpicto($langs->trans('GenerateDeposit', $object->deposit_percent), $langs->trans('DepositGenerationPermittedByThePaymentTermsSelected'))
);
$formquestion[] = array(
'type' => 'date',
'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
'name' => 'datef',
'label' => $langs->trans('DateInvoice'),
'value' => dol_now(),
'datenow' => true
);
if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
$formquestion[] = array(
'type' => 'date',
'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
'name' => 'date_pointoftax',
'label' => $langs->trans('DatePointOfTax'),
'name' => 'datef',
'label' => $langs->trans('DateInvoice'),
'value' => dol_now(),
'datenow' => true
);
}
ob_start();
$form->select_conditions_paiements(0, 'cond_reglement_id', -1, 0, 0, 'minwidth200');
$paymentTermsSelect = ob_get_clean();
if (!empty($conf->global->INVOICE_POINTOFTAX_DATE)) {
$formquestion[] = array(
'type' => 'date',
'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
'name' => 'date_pointoftax',
'label' => $langs->trans('DatePointOfTax'),
'value' => dol_now(),
'datenow' => true
);
}
$formquestion[] = array(
'type' => 'other',
'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
'name' => 'cond_reglement_id',
'label' => $langs->trans('PaymentTerm'),
'value' => $paymentTermsSelect
);
$formquestion[] = array(
'type' => 'checkbox',
'tdclass' => 'showonlyifgeneratedeposit',
'name' => 'validate_generated_deposit',
'label' => $langs->trans('ValidateGeneratedDeposit')
);
$paymentTermsSelect = $form->getSelectConditionsPaiements(0, 'cond_reglement_id', -1, 0, 0, 'minwidth200');
$formquestion[] = array(
'type' => 'onecolumn',
'value' => '
<script>
$(document).ready(function() {
$("[name=generate_deposit]").change(function () {
let $self = $(this);
let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
$formquestion[] = array(
'type' => 'other',
'tdclass' => 'fieldrequired showonlyifgeneratedeposit',
'name' => 'cond_reglement_id',
'label' => $langs->trans('PaymentTerm'),
'value' => $paymentTermsSelect
);
if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
$target.show();
} else {
$target.hide();
}
$formquestion[] = array(
'type' => 'checkbox',
'tdclass' => 'showonlyifgeneratedeposit',
'name' => 'validate_generated_deposit',
'label' => $langs->trans('ValidateGeneratedDeposit')
);
return true;
$formquestion[] = array(
'type' => 'onecolumn',
'value' => '
<script>
$(document).ready(function() {
$("[name=generate_deposit]").change(function () {
let $self = $(this);
let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
$target.show();
} else {
$target.hide();
}
return true;
});
});
});
</script>
'
);
</script>
'
);
}
}
}

View File

@ -1507,7 +1507,7 @@ if ($resql) {
// Payment term
if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
print '<td class="liste_titre">';
$form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
print $form->getSelectConditionsPaiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
print '</td>';
}
// Payment mode

View File

@ -3670,7 +3670,7 @@ if ($action == 'create') {
// Payment term
print '<tr><td class="nowrap fieldrequired">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
$form->select_conditions_paiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id');
print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id');
print '</td></tr>';
@ -3702,7 +3702,7 @@ if ($action == 'create') {
$retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
}
}
$form->select_conditions_paiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1);
print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1);
print '</td></tr>';
print '<script type="text/javascript">
@ -4728,7 +4728,7 @@ if ($action == 'create') {
$retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int');
$retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement;
$retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement) ? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
$form->select_conditions_paiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1);
print $form->getSelectConditionsPaiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1);
print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
print '</form>';
} else {

View File

@ -530,7 +530,7 @@ if ($resql) {
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
// Payment term
print '<td class="liste_titre right">';
$form->select_conditions_paiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
print $form->getSelectConditionsPaiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
print "</td>";
}
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {

View File

@ -1371,7 +1371,7 @@ if ($resql) {
// Payment terms
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
print '<td class="liste_titre">';
$form->select_conditions_paiements($search_paymentterms, 'search_paymentterms', -1, 1, 1);
print $form->getSelectConditionsPaiements($search_paymentterms, 'search_paymentterms', -1, 1, 1);
print '</td>';
}
// Module source

View File

@ -5372,7 +5372,7 @@ class Form
if ($type) {
print '<input type="hidden" name="type" value="'.dol_escape_htmltag($type).'">';
}
$this->select_conditions_paiements($selected, $htmlname, $filtertype, $addempty, 0, '', $deposit_percent);
print $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, 0, '', $deposit_percent);
print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
print '</form>';
} else {

View File

@ -1729,7 +1729,7 @@ if ($action == 'create') {
// Payment term
print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
$form->select_conditions_paiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id');
print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id');
print '</td></tr>';
// Payment mode

View File

@ -2400,7 +2400,7 @@ if ($action == 'create') {
// Payment term
print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
$form->select_conditions_paiements(GETPOSTISSET('cond_reglement_id') ?GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id');
print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ?GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id');
print '</td></tr>';
// Payment mode

View File

@ -521,7 +521,7 @@ if ($resql) {
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
// Payment term
print '<td class="liste_titre right">';
$form->select_conditions_paiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
print $form->getSelectConditionsPaiements($search_payment_term, 'search_payment_term', -1, 1, 1, 'maxwidth100');
print "</td>";
}
if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {

View File

@ -1045,7 +1045,7 @@ if ($resql) {
// Condition of payment
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
print '<td class="liste_titre left">';
$form->select_conditions_paiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
print '</td>';
}
// Payment mode

View File

@ -1276,7 +1276,7 @@ if ($action == 'create') {
// Terms of payment
print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td colspan="2">';
$form->select_conditions_paiements(GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id', -1, 1);
print $form->getSelectConditionsPaiements(GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $cond_reglement_id, 'cond_reglement_id', -1, 1);
print '</td></tr>';
// Mode of payment