NEW: deposit payment terms: set required invoice fields + filter payment terms with deposits in select + UI
This commit is contained in:
parent
6580c2e308
commit
1b2494855d
@ -690,10 +690,17 @@ if (empty($reshook)) {
|
|||||||
$deposit_percent_from_payment_terms = getDictvalue(MAIN_DB_PREFIX . 'c_payment_term', 'deposit_percent', $object->cond_reglement_id);
|
$deposit_percent_from_payment_terms = getDictvalue(MAIN_DB_PREFIX . 'c_payment_term', 'deposit_percent', $object->cond_reglement_id);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!$error && GETPOST('statut', 'int') == $object::STATUS_SIGNED && GETPOST('generate_deposit', 'int') > 0
|
!$error && GETPOST('statut', 'int') == $object::STATUS_SIGNED && GETPOST('generate_deposit', 'alpha') == 'on'
|
||||||
&& ! empty($deposit_percent_from_payment_terms) && ! empty($conf->facture->enabled) && ! empty($user->rights->facture->creer)
|
&& ! empty($deposit_percent_from_payment_terms) && ! empty($conf->facture->enabled) && ! empty($user->rights->facture->creer)
|
||||||
) {
|
) {
|
||||||
$deposit = Facture::createDepositFromOrigin($object, $user, 0, GETPOST('validate_generated_deposit', 'int') > 0);
|
$date = dol_mktime(0, 0, 0, GETPOST('datefmonth', 'int'), GETPOST('datefday', 'int'), GETPOST('datefyear', 'int'));
|
||||||
|
$forceFields = array();
|
||||||
|
|
||||||
|
if (GETPOSTISSET('date_pointoftax')) {
|
||||||
|
$forceFields['date_pointoftax'] = dol_mktime(0, 0, 0, GETPOST('date_pointoftaxmonth', 'int'), GETPOST('date_pointoftaxday', 'int'), GETPOST('date_pointoftaxyear', 'int'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$deposit = Facture::createDepositFromOrigin($object, $date, GETPOST('cond_reglement_id', 'int'), $user, 0, GETPOST('validate_generated_deposit', 'alpha') == 'on', $forceFields);
|
||||||
|
|
||||||
if ($deposit) {
|
if ($deposit) {
|
||||||
setEventMessage('DepositGenerated');
|
setEventMessage('DepositGenerated');
|
||||||
@ -2005,33 +2012,89 @@ if ($action == 'create') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($eligibleForDepositGeneration) {
|
if ($eligibleForDepositGeneration) {
|
||||||
|
$formquestion[] = array(
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'tdclass' => 'showonlyifsigned',
|
||||||
|
'name' => 'generate_deposit',
|
||||||
|
'label' => $form->textwithpicto($langs->trans('GenerateDeposit', $object->deposit_percent), $langs->trans('PaymentConditionPermitsDepositGenerationSelected'))
|
||||||
|
);
|
||||||
|
|
||||||
|
$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'),
|
||||||
|
'value' => dol_now(),
|
||||||
|
'datenow' => true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$form->select_conditions_paiements(0, 'cond_reglement_id', 1, 0, 0, 'minwidth200'); // TODO param 3
|
||||||
|
$paymentTermsSelect = ob_get_clean();
|
||||||
|
|
||||||
|
$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')
|
||||||
|
);
|
||||||
|
|
||||||
$formquestion[] = array(
|
$formquestion[] = array(
|
||||||
'type' => 'onecolumn',
|
'type' => 'onecolumn',
|
||||||
'name' => 'generate_deposit,validate_generated_deposit',
|
|
||||||
'value' => '
|
'value' => '
|
||||||
<div id="generate-deposit-box" style="display: none">
|
|
||||||
<p>' . $langs->trans('PaymentConditionPermitsDepositGenerationSelected') . '</p>
|
|
||||||
<p style="padding-left: 20%">
|
|
||||||
<input type="checkbox" name="generate_deposit" id="generate_deposit" value="1" checked />
|
|
||||||
<label for="generate_deposit">' . $langs->trans('GenerateDeposit', $object->deposit_percent) . '</label><br />
|
|
||||||
<input type="checkbox" name="validate_generated_deposit" id="validate_generated_deposit" value="1" checked />
|
|
||||||
<label for="validate_generated_deposit">' . $langs->trans('ValidateGeneratedDeposit') . '</label>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script>
|
<script>
|
||||||
let signedValue = ' . $object::STATUS_SIGNED . ';
|
let signedValue = ' . $object::STATUS_SIGNED . ';
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$("#statut").change(function(event) {
|
$("[name=generate_deposit]").change(function () {
|
||||||
if ($(this).val() == signedValue) {
|
let $self = $(this);
|
||||||
$("#generate-deposit-box").show();
|
let $target = $(".showonlyifgeneratedeposit").parent(".tagtr");
|
||||||
|
|
||||||
|
if (! $self.parents(".tagtr").is(":hidden") && $self.is(":checked")) {
|
||||||
|
$target.show();
|
||||||
} else {
|
} else {
|
||||||
$("#generate-deposit-box").hide();
|
$target.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#statut").change(function() {
|
||||||
|
let $target = $(".showonlyifsigned").parent(".tagtr");
|
||||||
|
|
||||||
|
if ($(this).val() == signedValue) {
|
||||||
|
$target.show();
|
||||||
|
} else {
|
||||||
|
$target.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
$("[name=generate_deposit]").trigger("change");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#statut").trigger("change");
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
'
|
'
|
||||||
|
|||||||
@ -1411,9 +1411,10 @@ class Facture extends CommonInvoice
|
|||||||
* @param User $user
|
* @param User $user
|
||||||
* @param type $notrigger
|
* @param type $notrigger
|
||||||
* @param bool $autoValidate
|
* @param bool $autoValidate
|
||||||
|
* @param array $overrideFields
|
||||||
* @return Facture
|
* @return Facture
|
||||||
*/
|
*/
|
||||||
static public function createDepositFromOrigin(CommonObject $origin, User $user, $notrigger = 0, $autoValidateDeposit = false, $forceInvoiceDate = null)
|
static public function createDepositFromOrigin(CommonObject $origin, $date, $cond_reglement_id, User $user, $notrigger = 0, $autoValidateDeposit = false, $overrideFields = array())
|
||||||
{
|
{
|
||||||
global $conf, $langs, $hookmanager, $action;
|
global $conf, $langs, $hookmanager, $action;
|
||||||
|
|
||||||
@ -1422,16 +1423,19 @@ class Facture extends CommonInvoice
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($date)) {
|
||||||
|
$origin->error = $langs->trans('ErrorFieldRequired', $langs->transnoentities('DateInvoice'));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
|
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
|
||||||
|
|
||||||
$invoiceDate = ! empty($forceInvoiceDate) ? $forceInvoiceDate : dol_now();
|
if ($date > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||||
|
|
||||||
if ($invoiceDate > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
|
||||||
$origin->error = 'ErrorDateIsInFuture';
|
$origin->error = 'ErrorDateIsInFuture';
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($origin->cond_reglement_id <= 0) {
|
if ($cond_reglement_id <= 0) {
|
||||||
$origin->error = $langs->trans('ErrorFieldRequired', $langs->transnoentities('PaymentConditionsShort'));
|
$origin->error = $langs->trans('ErrorFieldRequired', $langs->transnoentities('PaymentConditionsShort'));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -1453,9 +1457,9 @@ class Facture extends CommonInvoice
|
|||||||
$deposit->type = self::TYPE_DEPOSIT;
|
$deposit->type = self::TYPE_DEPOSIT;
|
||||||
$deposit->fk_project = $origin->fk_project;
|
$deposit->fk_project = $origin->fk_project;
|
||||||
$deposit->ref_client = $origin->ref_client;
|
$deposit->ref_client = $origin->ref_client;
|
||||||
$deposit->date = $invoiceDate;
|
$deposit->date = $date;
|
||||||
$deposit->mode_reglement_id = $origin->mode_reglement_id; // CHECK
|
$deposit->mode_reglement_id = $origin->mode_reglement_id;
|
||||||
// TODO Deposit is always due upon reception ?
|
$deposit->cond_reglement_id = $cond_reglement_id;
|
||||||
$deposit->availability_id = $origin->availability_id;
|
$deposit->availability_id = $origin->availability_id;
|
||||||
$deposit->demand_reason_id = $origin->demand_reason_id;
|
$deposit->demand_reason_id = $origin->demand_reason_id;
|
||||||
$deposit->fk_account = $origin->fk_account;
|
$deposit->fk_account = $origin->fk_account;
|
||||||
@ -1492,6 +1496,10 @@ class Facture extends CommonInvoice
|
|||||||
|
|
||||||
$deposit->linked_objects[$deposit->origin] = $deposit->origin_id;
|
$deposit->linked_objects[$deposit->origin] = $deposit->origin_id;
|
||||||
|
|
||||||
|
foreach ($overrideFields as $key => $value) {
|
||||||
|
$deposit->$key = $value;
|
||||||
|
}
|
||||||
|
|
||||||
$deposit->context['createdepositfromorigin'] = 'createdepositfromorigin';
|
$deposit->context['createdepositfromorigin'] = 'createdepositfromorigin';
|
||||||
|
|
||||||
$origin->db->begin();
|
$origin->db->begin();
|
||||||
|
|||||||
@ -3877,7 +3877,7 @@ class Form
|
|||||||
*
|
*
|
||||||
* @param int $selected Id of payment term to preselect by default
|
* @param int $selected Id of payment term to preselect by default
|
||||||
* @param string $htmlname Nom de la zone select
|
* @param string $htmlname Nom de la zone select
|
||||||
* @param int $filtertype Not used
|
* @param int $filtertype If > 0, don't include payment terms with deposit percentage (for invoices)
|
||||||
* @param int $addempty Add an empty entry
|
* @param int $addempty Add an empty entry
|
||||||
* @param int $noinfoadmin 0=Add admin info, 1=Disable admin info
|
* @param int $noinfoadmin 0=Add admin info, 1=Disable admin info
|
||||||
* @param string $morecss Add more CSS on select tag
|
* @param string $morecss Add more CSS on select tag
|
||||||
@ -3905,6 +3905,10 @@ class Form
|
|||||||
|
|
||||||
$selectedDepositPercent = null;
|
$selectedDepositPercent = null;
|
||||||
foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
|
foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
|
||||||
|
if ($filtertype > 0 && ! empty($arrayconditions['deposit_percent'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($selected == $id) {
|
if ($selected == $id) {
|
||||||
$selectedDepositPercent = ! empty($deposit_percent) ? $deposit_percent : $arrayconditions['deposit_percent'];
|
$selectedDepositPercent = ! empty($deposit_percent) ? $deposit_percent : $arrayconditions['deposit_percent'];
|
||||||
print '<option value="'.$id.'" data-deposit_percent="' . $arrayconditions['deposit_percent'] . '" selected>';
|
print '<option value="'.$id.'" data-deposit_percent="' . $arrayconditions['deposit_percent'] . '" selected>';
|
||||||
@ -3933,7 +3937,6 @@ class Form
|
|||||||
print '</span>';
|
print '</span>';
|
||||||
print '
|
print '
|
||||||
<script>
|
<script>
|
||||||
// let defaultDepositPercent = ' . (! empty($depositPercent) ? $depositPercent : null) . ';
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$("#' . $htmlname . '").change(function () {
|
$("#' . $htmlname . '").change(function () {
|
||||||
let $selected = $(this).find("option:selected");
|
let $selected = $(this).find("option:selected");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user