Merge pull request #18853 from marc-dll/NEW_deposit_payment_terms
NEW: payment conditions enabling semi-automatic deposit creation (Issue #18439)
This commit is contained in:
commit
5912a4a6c0
@ -209,7 +209,7 @@ $tabsql[8] = "SELECT t.id as rowid, t.code as code, t.libelle, t.fk_country as
|
||||
$tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c";
|
||||
$tabsql[10] = "SELECT t.rowid, t.code, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
|
||||
$tabsql[11] = "SELECT t.rowid as rowid, t.element, t.source, t.code, t.libelle, t.position, t.active FROM ".MAIN_DB_PREFIX."c_type_contact AS t";
|
||||
$tabsql[12] = "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder, c.entity FROM ".MAIN_DB_PREFIX."c_payment_term AS c WHERE c.entity = ".getEntity($tabname[12]);
|
||||
$tabsql[12] = "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.deposit_percent, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder, c.entity FROM ".MAIN_DB_PREFIX."c_payment_term AS c WHERE c.entity = ".getEntity($tabname[12]);
|
||||
$tabsql[13] = "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.entity FROM ".MAIN_DB_PREFIX."c_paiement AS c WHERE c.entity = ".getEntity($tabname[13]);
|
||||
$tabsql[14] = "SELECT e.rowid as rowid, e.code as code, e.label, e.price, e.organization, e.fk_pays as country_id, c.code as country_code, c.label as country, e.active FROM ".MAIN_DB_PREFIX."c_ecotaxe AS e, ".MAIN_DB_PREFIX."c_country as c WHERE e.fk_pays=c.rowid and c.active=1";
|
||||
$tabsql[15] = "SELECT rowid as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format";
|
||||
@ -303,7 +303,7 @@ $tabfield[8] = "code,libelle,country_id,country".(!empty($conf->global->SOCIETE_
|
||||
$tabfield[9] = "code,label,unicode";
|
||||
$tabfield[10] = "country_id,country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
|
||||
$tabfield[11] = "element,source,code,libelle,position";
|
||||
$tabfield[12] = "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder,entity";
|
||||
$tabfield[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder,entity";
|
||||
$tabfield[13] = "code,libelle,type,entity";
|
||||
$tabfield[14] = "code,label,price,organization,country";
|
||||
$tabfield[15] = "code,libelle,width,height,unit";
|
||||
@ -350,7 +350,7 @@ $tabfieldvalue[8] = "code,libelle,country".(!empty($conf->global->SOCIETE_SORT_O
|
||||
$tabfieldvalue[9] = "code,label,unicode";
|
||||
$tabfieldvalue[10] = "country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
|
||||
$tabfieldvalue[11] = "element,source,code,libelle,position";
|
||||
$tabfieldvalue[12] = "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder";
|
||||
$tabfieldvalue[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder";
|
||||
$tabfieldvalue[13] = "code,libelle,type";
|
||||
$tabfieldvalue[14] = "code,label,price,organization,country";
|
||||
$tabfieldvalue[15] = "code,libelle,width,height,unit";
|
||||
@ -397,7 +397,7 @@ $tabfieldinsert[8] = "code,libelle,fk_country".(!empty($conf->global->SOCIETE_SO
|
||||
$tabfieldinsert[9] = "code_iso,label,unicode";
|
||||
$tabfieldinsert[10] = "fk_pays,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
|
||||
$tabfieldinsert[11] = "element,source,code,libelle,position";
|
||||
$tabfieldinsert[12] = "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder,entity";
|
||||
$tabfieldinsert[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder,entity";
|
||||
$tabfieldinsert[13] = "code,libelle,type,entity";
|
||||
$tabfieldinsert[14] = "code,label,price,organization,fk_pays";
|
||||
$tabfieldinsert[15] = "code,label,width,height,unit";
|
||||
@ -761,7 +761,7 @@ if (empty($reshook)) {
|
||||
continue; // For a column name 'sortorder', we use the field name 'position'
|
||||
}
|
||||
if ((!GETPOSTISSET($value) || GETPOST($value) == '')
|
||||
&& (!in_array($value, array('decalage', 'module', 'accountancy_code', 'accountancy_code_sell', 'accountancy_code_buy', 'tracking', 'picto')) // Fields that are not mandatory
|
||||
&& (!in_array($value, array('decalage', 'module', 'accountancy_code', 'accountancy_code_sell', 'accountancy_code_buy', 'tracking', 'picto', 'deposit_percent')) // Fields that are not mandatory
|
||||
&& ($id != 10 || ($value != 'code' && $value != 'note')) // Field code and note is not mandatory for dictionary table 10
|
||||
)
|
||||
) {
|
||||
@ -774,6 +774,9 @@ if (empty($reshook)) {
|
||||
if ($fieldnamekey == 'libelle_facture') {
|
||||
$fieldnamekey = 'LabelOnDocuments';
|
||||
}
|
||||
if ($fieldnamekey == 'deposit_percent') {
|
||||
$fieldnamekey = 'DepositPercent';
|
||||
}
|
||||
if ($fieldnamekey == 'nbjour') {
|
||||
$fieldnamekey = 'NbOfDays';
|
||||
}
|
||||
@ -1356,6 +1359,10 @@ if ($id) {
|
||||
if ($value == 'libelle_facture') {
|
||||
$valuetoshow = $form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
|
||||
}
|
||||
if ($value == 'deposit_percent') {
|
||||
$valuetoshow = $langs->trans('DepositPercent');
|
||||
$class = 'right';
|
||||
}
|
||||
if ($value == 'country') {
|
||||
if (in_array('region_id', $fieldlist)) {
|
||||
print '<td> </td>'; continue;
|
||||
@ -1717,6 +1724,10 @@ if ($id) {
|
||||
if ($value == 'libelle_facture') {
|
||||
$valuetoshow = $langs->trans("LabelOnDocuments");
|
||||
}
|
||||
if ($value == 'deposit_percent') {
|
||||
$valuetoshow = $langs->trans('DepositPercent');
|
||||
$cssprefix = 'right ';
|
||||
}
|
||||
if ($value == 'country') {
|
||||
$valuetoshow = $langs->trans("Country");
|
||||
}
|
||||
@ -2097,7 +2108,7 @@ if ($id) {
|
||||
if ($value == 'tracking') {
|
||||
$class .= ' tdoverflowauto';
|
||||
}
|
||||
if (in_array($value, array('pos', 'position'))) {
|
||||
if (in_array($value, array('pos', 'position', 'deposit_percent'))) {
|
||||
$class .= ' right';
|
||||
}
|
||||
if (in_array($value, array('localtax1_type', 'localtax2_type'))) {
|
||||
@ -2499,7 +2510,7 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
|
||||
if ($fieldlist[$field] == 'code') {
|
||||
$class = 'maxwidth100';
|
||||
}
|
||||
if (in_array($fieldlist[$field], array('pos', 'position'))) {
|
||||
if (in_array($fieldlist[$field], array('pos', 'position', 'deposit_percent'))) {
|
||||
$classtd = 'right'; $class = 'maxwidth50 right';
|
||||
}
|
||||
if (in_array($fieldlist[$field], array('dayrule', 'day', 'month', 'year', 'use_default', 'affect', 'delay', 'public', 'sortorder', 'sens', 'category_type', 'fk_parent'))) {
|
||||
|
||||
@ -173,7 +173,7 @@ if (empty($reshook)) {
|
||||
// terms of the settlement
|
||||
if ($action == 'setconditions' && $user->rights->societe->creer) {
|
||||
$object->fetch($id);
|
||||
$result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
|
||||
$result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha'));
|
||||
if ($result < 0) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
@ -415,9 +415,9 @@ if ($object->id > 0) {
|
||||
print '</tr></table>';
|
||||
print '</td><td>';
|
||||
if ($action == 'editconditions') {
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent);
|
||||
} else {
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none');
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none', 0, '', 1, $object->deposit_percent);
|
||||
}
|
||||
print "</td>";
|
||||
print '</tr>';
|
||||
|
||||
@ -402,6 +402,7 @@ if (empty($reshook)) {
|
||||
$object->warehouse_id = GETPOST('warehouse_id', 'int');
|
||||
$object->duree_validite = $duration;
|
||||
$object->cond_reglement_id = GETPOST('cond_reglement_id');
|
||||
$object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha');
|
||||
$object->mode_reglement_id = GETPOST('mode_reglement_id');
|
||||
$object->fk_account = GETPOST('fk_account', 'int');
|
||||
$object->remise_absolue = price2num(GETPOST('remise_absolue'), 'MU', 2); // deprecated
|
||||
@ -434,6 +435,7 @@ if (empty($reshook)) {
|
||||
$object->warehouse_id = GETPOST('warehouse_id', 'int');
|
||||
$object->duree_validite = price2num(GETPOST('duree_validite', 'alpha'));
|
||||
$object->cond_reglement_id = GETPOST('cond_reglement_id', 'int');
|
||||
$object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha');
|
||||
$object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
|
||||
$object->fk_account = GETPOST('fk_account', 'int');
|
||||
$object->contact_id = GETPOST('contactid', 'int');
|
||||
@ -687,11 +689,59 @@ if (empty($reshook)) {
|
||||
$error++;
|
||||
}
|
||||
|
||||
$deposit = null;
|
||||
$locationTarget = $_SERVER['PHP_SELF'] . '?id=' . $object->id;
|
||||
|
||||
$deposit_percent_from_payment_terms = getDictionaryValue(MAIN_DB_PREFIX . 'c_payment_term', 'deposit_percent', $object->cond_reglement_id);
|
||||
|
||||
if (
|
||||
!$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)
|
||||
) {
|
||||
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
|
||||
|
||||
$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) {
|
||||
setEventMessage('DepositGenerated');
|
||||
$locationTarget = DOL_URL_ROOT . '/compta/facture/card.php?id=' . $deposit->id;
|
||||
} else {
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$db->commit();
|
||||
if ($deposit && empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
||||
$ret = $deposit->fetch($deposit->id); // Reload to get new records
|
||||
$outputlangs = $langs;
|
||||
|
||||
if ($conf->global->MAIN_MULTILANGS) {
|
||||
$outputlangs = new Translate('', $conf);
|
||||
$outputlangs->setDefaultLang($deposit->thirdparty->default_lang);
|
||||
$outputlangs->load('products');
|
||||
}
|
||||
|
||||
$result = $deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||
|
||||
if ($result < 0) {
|
||||
setEventMessages($deposit->error, $deposit->errors, 'errors');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$db->rollback();
|
||||
}
|
||||
|
||||
header('Location: ' . $locationTarget);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
} elseif ($action == 'confirm_reopen' && $usercanclose && !GETPOST('cancel', 'alpha')) {
|
||||
@ -1370,7 +1420,7 @@ if (empty($reshook)) {
|
||||
$result = $object->set_demand_reason($user, GETPOST('demand_reason_id', 'int'));
|
||||
} elseif ($action == 'setconditions' && $usercancreate) {
|
||||
// Terms of payment
|
||||
$result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
|
||||
$result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha'));
|
||||
} elseif ($action == 'setremisepercent' && $usercancreate) {
|
||||
$result = $object->set_remise_percent($user, price2num(GETPOST('remise_percent'), '', 2));
|
||||
} elseif ($action == 'setremiseabsolue' && $usercancreate) {
|
||||
@ -1656,9 +1706,9 @@ if ($action == 'create') {
|
||||
print '<tr class="field_duree_validitee"><td class="titlefieldcreate fieldrequired">'.$langs->trans("ValidityDuration").'</td><td class="valuefieldcreate">'.img_picto('', 'clock', 'class="paddingright"').'<input name="duree_validite" class="width50" value="'.(GETPOSTISSET('duree_validite') ? GETPOST('duree_validite', 'alphanohtml') : $conf->global->PROPALE_VALIDITY_DURATION).'"> '.$langs->trans("days").'</td></tr>';
|
||||
|
||||
// Terms of payment
|
||||
print '<tr class="field_cond_reglement_id"><td class="titlefieldcreate nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td class="valuefieldcreate">';
|
||||
print img_picto('', 'payment', 'class="pictofixedwidth"');
|
||||
$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);
|
||||
print '<tr><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 '</td></tr>';
|
||||
|
||||
// Mode of payment
|
||||
@ -1945,6 +1995,129 @@ if ($action == 'create') {
|
||||
array('type' => 'text', 'name' => 'note_private', 'label' => $langs->trans("Note"), 'value' => '') // Field to complete private note (not replace)
|
||||
);
|
||||
|
||||
$deposit_percent_from_payment_terms = getDictionaryValue(MAIN_DB_PREFIX . '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';
|
||||
|
||||
$object->fetchObjectLinked();
|
||||
|
||||
$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 ($eligibleForDepositGeneration && array_key_exists('commande', $object->linkedObjects)) {
|
||||
foreach ($object->linkedObjects['commande'] as $order) {
|
||||
$order->fetchObjectLinked();
|
||||
|
||||
if (array_key_exists('facture', $order->linkedObjects)) {
|
||||
foreach ($order->linkedObjects['facture'] as $invoice) {
|
||||
if ($invoice->type == Facture::TYPE_DEPOSIT) {
|
||||
$eligibleForDepositGeneration = false;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($eligibleForDepositGeneration) {
|
||||
$formquestion[] = array(
|
||||
'type' => 'checkbox',
|
||||
'tdclass' => 'showonlyifsigned',
|
||||
'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'),
|
||||
'value' => dol_now(),
|
||||
'datenow' => true
|
||||
);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$form->select_conditions_paiements(0, 'cond_reglement_id', -1, 0, 0, 'minwidth200');
|
||||
$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(
|
||||
'type' => 'onecolumn',
|
||||
'value' => '
|
||||
<script>
|
||||
let signedValue = ' . $object::STATUS_SIGNED . ';
|
||||
|
||||
$(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;
|
||||
});
|
||||
|
||||
$("#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>
|
||||
'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($conf->notification->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
|
||||
$notify = new Notify($db);
|
||||
@ -2171,9 +2344,9 @@ if ($action == 'create') {
|
||||
print '</tr></table>';
|
||||
print '</td><td class="valuefield">';
|
||||
if ($action == 'editconditions' && $usercancreate && $caneditfield) {
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id');
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, '', 1, $object->deposit_percent);
|
||||
} else {
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 0, '', 1, $object->deposit_percent);
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
@ -206,6 +206,7 @@ class Propal extends CommonObject
|
||||
public $total;
|
||||
|
||||
public $cond_reglement_code;
|
||||
public $deposit_percent;
|
||||
public $mode_reglement_code;
|
||||
public $remise_percent;
|
||||
|
||||
@ -319,6 +320,7 @@ class Propal extends CommonObject
|
||||
'fk_account' =>array('type'=>'integer', 'label'=>'BankAccount', 'enabled'=>1, 'visible'=>-1, 'position'=>150),
|
||||
'fk_currency' =>array('type'=>'varchar(3)', 'label'=>'Currency', 'enabled'=>1, 'visible'=>-1, 'position'=>155),
|
||||
'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'PaymentTerm', 'enabled'=>1, 'visible'=>-1, 'position'=>160),
|
||||
'deposit_percent' =>array('type'=>'varchar(63)', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>161),
|
||||
'fk_mode_reglement' =>array('type'=>'integer', 'label'=>'PaymentMode', 'enabled'=>1, 'visible'=>-1, 'position'=>165),
|
||||
'note_private' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>170),
|
||||
'note_public' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>175),
|
||||
@ -1100,6 +1102,7 @@ class Propal extends CommonObject
|
||||
$sql .= ", model_pdf";
|
||||
$sql .= ", fin_validite";
|
||||
$sql .= ", fk_cond_reglement";
|
||||
$sql .= ", deposit_percent";
|
||||
$sql .= ", fk_mode_reglement";
|
||||
$sql .= ", fk_account";
|
||||
$sql .= ", ref_client";
|
||||
@ -1133,6 +1136,7 @@ class Propal extends CommonObject
|
||||
$sql .= ", '".$this->db->escape($this->model_pdf)."'";
|
||||
$sql .= ", ".($this->fin_validite != '' ? "'".$this->db->idate($this->fin_validite)."'" : "NULL");
|
||||
$sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : 'NULL');
|
||||
$sql .= ", ".(! empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : 'NULL');
|
||||
$sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : 'NULL');
|
||||
$sql .= ", ".($this->fk_account > 0 ? ((int) $this->fk_account) : 'NULL');
|
||||
$sql .= ", '".$this->db->escape($this->ref_client)."'";
|
||||
@ -1360,6 +1364,7 @@ class Propal extends CommonObject
|
||||
if ($objsoc->fetch($socid) > 0) {
|
||||
$object->socid = $objsoc->id;
|
||||
$object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
|
||||
$object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent : null);
|
||||
$object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
|
||||
$object->fk_delivery_address = '';
|
||||
|
||||
@ -1536,7 +1541,7 @@ class Propal extends CommonObject
|
||||
$sql .= ", c.label as statut_label";
|
||||
$sql .= ", ca.code as availability_code, ca.label as availability";
|
||||
$sql .= ", dr.code as demand_reason_code, dr.label as demand_reason";
|
||||
$sql .= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc";
|
||||
$sql .= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent";
|
||||
$sql .= ", cp.code as mode_reglement_code, cp.libelle as mode_reglement";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_propalst as c ON p.fk_statut = c.id';
|
||||
@ -1619,6 +1624,7 @@ class Propal extends CommonObject
|
||||
$this->cond_reglement_code = $obj->cond_reglement_code;
|
||||
$this->cond_reglement = $obj->cond_reglement;
|
||||
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
|
||||
$this->deposit_percent = $obj->deposit_percent;
|
||||
|
||||
$this->extraparams = (array) json_decode($obj->extraparams, true);
|
||||
|
||||
@ -1728,6 +1734,7 @@ class Propal extends CommonObject
|
||||
$sql .= " fk_user_valid=".(isset($this->user_valid) ? $this->user_valid : "null").",";
|
||||
$sql .= " fk_projet=".(isset($this->fk_project) ? $this->fk_project : "null").",";
|
||||
$sql .= " fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id : "null").",";
|
||||
$sql .= " deposit_percent=".(! empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : "null").",";
|
||||
$sql .= " fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id : "null").",";
|
||||
$sql .= " fk_input_reason=".(isset($this->demand_reason_id) ? $this->demand_reason_id : "null").",";
|
||||
$sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").",";
|
||||
|
||||
@ -537,7 +537,7 @@ $sql .= ' p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multic
|
||||
$sql .= ' p.datec as date_creation, p.tms as date_update, p.date_cloture as date_cloture,';
|
||||
$sql .= ' p.date_signature as dsignature,';
|
||||
$sql .= ' p.note_public, p.note_private,';
|
||||
$sql .= ' p.fk_cond_reglement,p.fk_mode_reglement,p.fk_shipping_method,p.fk_input_reason,';
|
||||
$sql .= ' p.fk_cond_reglement,p.deposit_percent,p.fk_mode_reglement,p.fk_shipping_method,p.fk_input_reason,';
|
||||
$sql .= " pr.rowid as project_id, pr.ref as project_ref, pr.title as project_label,";
|
||||
$sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity as user_entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
|
||||
if (empty($user->rights->societe->client->voir) && !$socid) {
|
||||
@ -1224,7 +1224,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);
|
||||
$form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
|
||||
print '</td>';
|
||||
}
|
||||
// Payment mode
|
||||
@ -1821,7 +1821,7 @@ if ($resql) {
|
||||
// Payment terms
|
||||
if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
|
||||
print '<td>';
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none');
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
|
||||
print '</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
|
||||
@ -272,6 +272,7 @@ if (empty($reshook)) {
|
||||
$object->ref_client = GETPOST('ref_client', 'alpha');
|
||||
$object->model_pdf = GETPOST('model');
|
||||
$object->cond_reglement_id = GETPOST('cond_reglement_id');
|
||||
$object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha');
|
||||
$object->mode_reglement_id = GETPOST('mode_reglement_id');
|
||||
$object->fk_account = GETPOST('fk_account', 'int');
|
||||
$object->availability_id = GETPOST('availability_id');
|
||||
@ -571,7 +572,7 @@ if (empty($reshook)) {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
} elseif ($action == 'setconditions' && $usercancreate) {
|
||||
$result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
|
||||
$result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha'));
|
||||
if ($result < 0) {
|
||||
dol_print_error($db, $object->error);
|
||||
} else {
|
||||
@ -1176,30 +1177,75 @@ if (empty($reshook)) {
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$locationTarget = $_SERVER['PHP_SELF'] . '?id=' . $object->id;
|
||||
$db->begin();
|
||||
$result = $object->valid($user, $idwarehouse);
|
||||
if ($result >= 0) {
|
||||
// Define output language
|
||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
|
||||
$newlang = GETPOST('lang_id', 'aZ09');
|
||||
}
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
|
||||
$newlang = $object->thirdparty->default_lang;
|
||||
}
|
||||
if (!empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
}
|
||||
$model = $object->model_pdf;
|
||||
$ret = $object->fetch($id); // Reload to get new records
|
||||
$error = 0;
|
||||
$deposit = null;
|
||||
|
||||
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||
$deposit_percent_from_payment_terms = getDictionaryValue(MAIN_DB_PREFIX . 'c_payment_term', 'deposit_percent', $object->cond_reglement_id);
|
||||
|
||||
if (
|
||||
GETPOST('generate_deposit', 'alpha') == 'on' && ! 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';
|
||||
|
||||
$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) {
|
||||
setEventMessage('DepositGenerated');
|
||||
$locationTarget = DOL_URL_ROOT . '/compta/facture/card.php?id=' . $deposit->id;
|
||||
} else {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
// Define output language
|
||||
if (! $error) {
|
||||
$db->commit();
|
||||
|
||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
|
||||
$newlang = GETPOST('lang_id', 'aZ09');
|
||||
}
|
||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
|
||||
$newlang = $object->thirdparty->default_lang;
|
||||
}
|
||||
if (!empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
}
|
||||
$model = $object->model_pdf;
|
||||
$ret = $object->fetch($id); // Reload to get new records
|
||||
|
||||
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||
|
||||
if ($deposit) {
|
||||
$deposit->fetch($deposit->id); // Reload to get new records
|
||||
$deposit->generateDocument($deposit->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$db->rollback();
|
||||
}
|
||||
} else {
|
||||
$db->rollback();
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
|
||||
header('Location: ' . $locationTarget);
|
||||
exit;
|
||||
}
|
||||
} elseif ($action == 'confirm_modif' && $usercancreate) {
|
||||
// Go back to draft status
|
||||
@ -1460,6 +1506,10 @@ if ($action == 'create' && $usercancreate) {
|
||||
|
||||
$currency_code = $conf->currency;
|
||||
|
||||
$cond_reglement_id = GETPOST('cond_reglement_id', 'int');
|
||||
$deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha');
|
||||
$mode_reglement_id = GETPOST('mode_reglement_id', 'int');
|
||||
|
||||
if (!empty($origin) && !empty($originid)) {
|
||||
// Parse element/subelement (ex: project_task)
|
||||
$element = $subelement = $origin;
|
||||
@ -1475,6 +1525,9 @@ if ($action == 'create' && $usercancreate) {
|
||||
if (!$cond_reglement_id) {
|
||||
$cond_reglement_id = $soc->cond_reglement_id;
|
||||
}
|
||||
if (!$deposit_percent) {
|
||||
$deposit_percent = $soc->deposit_percent;
|
||||
}
|
||||
if (!$mode_reglement_id) {
|
||||
$mode_reglement_id = $soc->mode_reglement_id;
|
||||
}
|
||||
@ -1515,6 +1568,7 @@ if ($action == 'create' && $usercancreate) {
|
||||
|
||||
$soc = $objectsrc->thirdparty;
|
||||
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0)); // TODO maybe add default value option
|
||||
$deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : null));
|
||||
$mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
|
||||
$fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
|
||||
$availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : 0);
|
||||
@ -1547,6 +1601,7 @@ if ($action == 'create' && $usercancreate) {
|
||||
}
|
||||
} else {
|
||||
$cond_reglement_id = $soc->cond_reglement_id;
|
||||
$deposit_percent = $soc->deposit_percent;
|
||||
$mode_reglement_id = $soc->mode_reglement_id;
|
||||
$fk_account = $soc->fk_account;
|
||||
$availability_id = 0;
|
||||
@ -1677,8 +1732,8 @@ if ($action == 'create' && $usercancreate) {
|
||||
|
||||
// Terms of the settlement
|
||||
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);
|
||||
print img_picto('', 'paiment', 'class="pictofixedwidth"');
|
||||
$form->select_conditions_paiements($cond_reglement_id, 'cond_reglement_id', 1, 1, 0, '', $deposit_percent);
|
||||
print '</td></tr>';
|
||||
|
||||
// Payment mode
|
||||
@ -1967,6 +2022,111 @@ if ($action == 'create' && $usercancreate) {
|
||||
if ($nbMandated > 0 ) $text .= '<div><span class="clearboth nowraponall warning">'.$langs->trans("mandatoryPeriodNeedTobeSetMsgValidate").'</span></div>';
|
||||
|
||||
|
||||
$deposit_percent_from_payment_terms = getDictionaryValue(MAIN_DB_PREFIX . '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';
|
||||
|
||||
$object->fetchObjectLinked();
|
||||
|
||||
$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 ($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 ($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'),
|
||||
'value' => dol_now(),
|
||||
'datenow' => true
|
||||
);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$form->select_conditions_paiements(0, 'cond_reglement_id', -1, 0, 0, 'minwidth200');
|
||||
$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(
|
||||
'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>
|
||||
'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
|
||||
}
|
||||
@ -2270,9 +2430,9 @@ if ($action == 'create' && $usercancreate) {
|
||||
print $form->editfieldkey("PaymentConditionsShort", 'conditions', '', $object, $editenable);
|
||||
print '</td><td class="valuefield">';
|
||||
if ($action == 'editconditions') {
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, '', 1, $object->deposit_percent);
|
||||
} else {
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1);
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1, '', 1, $object->deposit_percent);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
|
||||
@ -134,6 +134,11 @@ class Commande extends CommonOrder
|
||||
*/
|
||||
public $cond_reglement_code;
|
||||
|
||||
/**
|
||||
* @var double Deposit % for payment terms
|
||||
*/
|
||||
public $deposit_percent;
|
||||
|
||||
/**
|
||||
* @var int bank account ID
|
||||
*/
|
||||
@ -332,6 +337,7 @@ class Commande extends CommonOrder
|
||||
'fk_account' =>array('type'=>'integer', 'label'=>'BankAccount', 'enabled'=>1, 'visible'=>-1, 'position'=>170),
|
||||
'fk_currency' =>array('type'=>'varchar(3)', 'label'=>'MulticurrencyID', 'enabled'=>1, 'visible'=>-1, 'position'=>175),
|
||||
'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'PaymentTerm', 'enabled'=>1, 'visible'=>-1, 'position'=>180),
|
||||
'deposit_percent' =>array('type'=>'varchar(63)', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>181),
|
||||
'fk_mode_reglement' =>array('type'=>'integer', 'label'=>'PaymentMode', 'enabled'=>1, 'visible'=>-1, 'position'=>185),
|
||||
'date_livraison' =>array('type'=>'date', 'label'=>'DateDeliveryPlanned', 'enabled'=>1, 'visible'=>-1, 'position'=>190),
|
||||
'fk_shipping_method' =>array('type'=>'integer', 'label'=>'ShippingMethod', 'enabled'=>1, 'visible'=>-1, 'position'=>195),
|
||||
@ -940,7 +946,7 @@ class Commande extends CommonOrder
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande (";
|
||||
$sql .= " ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note_private, note_public, ref_ext, ref_client, ref_int";
|
||||
$sql .= ", model_pdf, fk_cond_reglement, fk_mode_reglement, fk_account, fk_availability, fk_input_reason, date_livraison, fk_delivery_address";
|
||||
$sql .= ", model_pdf, fk_cond_reglement, deposit_percent, fk_mode_reglement, fk_account, fk_availability, fk_input_reason, date_livraison, fk_delivery_address";
|
||||
$sql .= ", fk_shipping_method";
|
||||
$sql .= ", fk_warehouse";
|
||||
$sql .= ", remise_absolue, remise_percent";
|
||||
@ -961,6 +967,7 @@ class Commande extends CommonOrder
|
||||
$sql .= ", ".($this->ref_int ? "'".$this->db->escape($this->ref_int)."'" : "null");
|
||||
$sql .= ", '".$this->db->escape($this->model_pdf)."'";
|
||||
$sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : "null");
|
||||
$sql .= ", ".(! empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : "null");
|
||||
$sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "null");
|
||||
$sql .= ", ".($this->fk_account > 0 ? ((int) $this->fk_account) : 'NULL');
|
||||
$sql .= ", ".($this->availability_id > 0 ? ((int) $this->availability_id) : "null");
|
||||
@ -1212,6 +1219,7 @@ class Commande extends CommonOrder
|
||||
if ($objsoc->fetch($socid) > 0) {
|
||||
$this->socid = $objsoc->id;
|
||||
$this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
|
||||
$this->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent : null);
|
||||
$this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
|
||||
$this->fk_project = 0;
|
||||
$this->fk_delivery_address = 0;
|
||||
@ -1354,6 +1362,7 @@ class Commande extends CommonOrder
|
||||
$this->socid = $object->socid;
|
||||
$this->fk_project = $object->fk_project;
|
||||
$this->cond_reglement_id = $object->cond_reglement_id;
|
||||
$this->deposit_percent = $object->deposit_percent;
|
||||
$this->mode_reglement_id = $object->mode_reglement_id;
|
||||
$this->fk_account = $object->fk_account;
|
||||
$this->availability_id = $object->availability_id;
|
||||
@ -1811,7 +1820,7 @@ class Commande extends CommonOrder
|
||||
}
|
||||
|
||||
$sql = 'SELECT c.rowid, c.entity, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_user_valid, c.fk_user_modif, c.fk_statut';
|
||||
$sql .= ', c.amount_ht, c.total_ht, c.total_ttc, c.total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_availability, c.fk_input_reason';
|
||||
$sql .= ', c.amount_ht, c.total_ht, c.total_ttc, c.total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.deposit_percent, c.fk_mode_reglement, c.fk_availability, c.fk_input_reason';
|
||||
$sql .= ', c.fk_account';
|
||||
$sql .= ', c.date_commande, c.date_valid, c.tms';
|
||||
$sql .= ', c.date_livraison as delivery_date';
|
||||
@ -1904,6 +1913,7 @@ class Commande extends CommonOrder
|
||||
$this->cond_reglement_code = $obj->cond_reglement_code;
|
||||
$this->cond_reglement = $obj->cond_reglement_libelle;
|
||||
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
|
||||
$this->deposit_percent = $obj->deposit_percent;
|
||||
$this->fk_account = $obj->fk_account;
|
||||
$this->availability_id = $obj->fk_availability;
|
||||
$this->availability_code = $obj->availability_code;
|
||||
@ -3340,6 +3350,7 @@ class Commande extends CommonOrder
|
||||
$sql .= " fk_user_valid=".(isset($this->user_valid) ? $this->user_valid : "null").",";
|
||||
$sql .= " fk_projet=".(isset($this->fk_project) ? $this->fk_project : "null").",";
|
||||
$sql .= " fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id : "null").",";
|
||||
$sql .= " deposit_percent=".(! empty($this->deposit_percent) ? strval($this->deposit_percent) : "null").",";
|
||||
$sql .= " fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id : "null").",";
|
||||
$sql .= " date_livraison=".(strval($this->delivery_date) != '' ? "'".$this->db->idate($this->delivery_date)."'" : 'null').",";
|
||||
$sql .= " fk_shipping_method=".(isset($this->shipping_method_id) ? $this->shipping_method_id : "null").",";
|
||||
|
||||
@ -787,7 +787,7 @@ $sql .= ' c.date_valid, c.date_commande, c.note_public, c.note_private, c.date_l
|
||||
$sql .= ' c.date_creation as date_creation, c.tms as date_update, c.date_cloture as date_cloture,';
|
||||
$sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
|
||||
$sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender,';
|
||||
$sql .= ' c.fk_cond_reglement,c.fk_mode_reglement,c.fk_shipping_method,';
|
||||
$sql .= ' c.fk_cond_reglement,c.deposit_percent,c.fk_mode_reglement,c.fk_shipping_method,';
|
||||
$sql .= ' c.fk_input_reason, c.import_key';
|
||||
if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
|
||||
$sql .= ", cc.fk_categorie, cc.fk_soc";
|
||||
@ -1479,7 +1479,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);
|
||||
$form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
|
||||
print '</td>';
|
||||
}
|
||||
// Payment mode
|
||||
@ -2032,7 +2032,7 @@ if ($resql) {
|
||||
// Payment terms
|
||||
if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
|
||||
print '<td>';
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none');
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
|
||||
print '</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
|
||||
@ -3287,10 +3287,21 @@ if ($action == 'create') {
|
||||
'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')),
|
||||
'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines')
|
||||
);
|
||||
print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit', 'aZ09'), 0, 0, 0, '', 1);
|
||||
$typedeposit = GETPOST('typedeposit', 'aZ09');
|
||||
$valuedeposit = GETPOST('valuedeposit', 'int');
|
||||
if (empty($typedeposit) && ! empty($objectsrc->deposit_percent)) {
|
||||
$origin_payment_conditions_deposit_percent = getDictionaryValue(MAIN_DB_PREFIX . 'c_payment_term', 'deposit_percent', $objectsrc->cond_reglement_id);
|
||||
if (! empty($origin_payment_conditions_deposit_percent)) {
|
||||
$typedeposit = 'variable';
|
||||
}
|
||||
}
|
||||
if (empty($valuedeposit) && $typedeposit == 'variable' && ! empty($objectsrc->deposit_percent)) {
|
||||
$valuedeposit = $objectsrc->deposit_percent;
|
||||
}
|
||||
print $form->selectarray('typedeposit', $arraylist, $typedeposit, 0, 0, 0, '', 1);
|
||||
print '</td>';
|
||||
print '<td class="nowrap" style="padding-left: 5px">';
|
||||
print '<span class="opacitymedium paddingleft">'.$langs->trans("AmountOrPercent").'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.GETPOST('valuedeposit', 'int').'"/>';
|
||||
print '<span class="opacitymedium paddingleft">'.$langs->trans("AmountOrPercent").'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="'.$valuedeposit.'"/>';
|
||||
print '</td>';
|
||||
}
|
||||
print '</tr></table>';
|
||||
|
||||
@ -1463,6 +1463,292 @@ class Facture extends CommonInvoice
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a deposit from a proposal or an order by grouping lines by VAT rates
|
||||
*
|
||||
* @param Propal|Commande $origin The original proposal or order
|
||||
* @param int $date Invoice date
|
||||
* @param int $payment_terms_id Invoice payment terms
|
||||
* @param User $user Object user
|
||||
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
||||
* @param bool $autoValidateDeposit Whether to aumatically validate the deposit created
|
||||
* @param array $overrideFields Array of fields to force values
|
||||
* @return Facture|null The deposit created, or null if error (populates $origin->error in this case)
|
||||
*/
|
||||
static public function createDepositFromOrigin(CommonObject $origin, $date, $payment_terms_id, User $user, $notrigger = 0, $autoValidateDeposit = false, $overrideFields = array())
|
||||
{
|
||||
global $conf, $langs, $hookmanager, $action;
|
||||
|
||||
if (! in_array($origin->element, array('propal', 'commande'))) {
|
||||
$origin->error = 'ErrorCanOnlyAutomaticallyGenerateADepositFromProposalOrOrder';
|
||||
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';
|
||||
|
||||
if ($date > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
|
||||
$origin->error = 'ErrorDateIsInFuture';
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($payment_terms_id <= 0) {
|
||||
$origin->error = $langs->trans('ErrorFieldRequired', $langs->transnoentities('PaymentConditionsShort'));
|
||||
return null;
|
||||
}
|
||||
|
||||
$payment_conditions_deposit_percent = getDictionaryValue(MAIN_DB_PREFIX . 'c_payment_term', 'deposit_percent', $origin->cond_reglement_id);
|
||||
|
||||
if (empty($payment_conditions_deposit_percent)) {
|
||||
$origin->error = 'ErrorPaymentConditionsNotEligibleToDepositCreation';
|
||||
return null;
|
||||
}
|
||||
|
||||
if (empty($origin->deposit_percent)) {
|
||||
$origin->error = $langs->trans('ErrorFieldRequired', $langs->transnoentities('DepositPercent'));
|
||||
return null;
|
||||
}
|
||||
|
||||
$deposit = new self($origin->db);
|
||||
$deposit->socid = $origin->socid;
|
||||
$deposit->type = self::TYPE_DEPOSIT;
|
||||
$deposit->fk_project = $origin->fk_project;
|
||||
$deposit->ref_client = $origin->ref_client;
|
||||
$deposit->date = $date;
|
||||
$deposit->mode_reglement_id = $origin->mode_reglement_id;
|
||||
$deposit->cond_reglement_id = $payment_terms_id;
|
||||
$deposit->availability_id = $origin->availability_id;
|
||||
$deposit->demand_reason_id = $origin->demand_reason_id;
|
||||
$deposit->fk_account = $origin->fk_account;
|
||||
$deposit->fk_incoterms = $origin->fk_incoterms;
|
||||
$deposit->location_incoterms = $origin->location_incoterms;
|
||||
$deposit->fk_multicurrency = $origin->fk_multicurrency;
|
||||
$deposit->multicurrency_code = $origin->multicurrency_code;
|
||||
$deposit->multicurrency_tx = $origin->multicurrency_tx;
|
||||
$deposit->module_source = $origin->module_source;
|
||||
$deposit->pos_source = $origin->pos_source;
|
||||
$deposit->model_pdf = 'crabe';
|
||||
|
||||
$modelByTypeConfName = 'FACTURE_ADDON_PDF_' . $deposit->type;
|
||||
|
||||
if (!empty($conf->global->$modelByTypeConfName)) {
|
||||
$deposit->model_pdf = $conf->global->$modelByTypeConfName;
|
||||
} elseif (!empty($conf->global->FACTURE_ADDON_PDF)) {
|
||||
$deposit->model_pdf = $conf->global->FACTURE_ADDON_PDF;
|
||||
}
|
||||
|
||||
if (empty($conf->global->MAIN_DISABLE_PROPAGATE_NOTES_FROM_ORIGIN)) {
|
||||
$deposit->note_private = $origin->note_private;
|
||||
$deposit->note_public = $origin->note_public;
|
||||
}
|
||||
|
||||
$deposit->origin = $origin->element;
|
||||
$deposit->origin_id = $origin->id;
|
||||
|
||||
$origin->fetch_optionals();
|
||||
|
||||
foreach ($origin->array_options as $extrakey => $value) {
|
||||
$deposit->array_options[$extrakey] = $value;
|
||||
}
|
||||
|
||||
$deposit->linked_objects[$deposit->origin] = $deposit->origin_id;
|
||||
|
||||
foreach ($overrideFields as $key => $value) {
|
||||
$deposit->$key = $value;
|
||||
}
|
||||
|
||||
$deposit->context['createdepositfromorigin'] = 'createdepositfromorigin';
|
||||
|
||||
$origin->db->begin();
|
||||
|
||||
// Facture::create() also imports contact from origin
|
||||
$createReturn = $deposit->create($user, $notrigger);
|
||||
|
||||
if ($createReturn <= 0) {
|
||||
$origin->db->rollback();
|
||||
$origin->error = $deposit->error;
|
||||
$origin->errors = $deposit->errors;
|
||||
return null;
|
||||
}
|
||||
|
||||
$amount_ttc_diff = 0;
|
||||
$amountdeposit = array();
|
||||
$descriptions = array();
|
||||
|
||||
if (! empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
|
||||
$amount = $origin->total_ttc * ($origin->deposit_percent / 100);
|
||||
|
||||
$TTotalByTva = array();
|
||||
foreach ($origin->lines as &$line) {
|
||||
if (!empty($line->special_code)) {
|
||||
continue;
|
||||
}
|
||||
$TTotalByTva[$line->tva_tx] += $line->total_ttc;
|
||||
$descriptions[$line->tva_tx] .= '<li>' . (! empty($line->product_ref) ? $line->product_ref . ' - ' : '');
|
||||
$descriptions[$line->tva_tx] .= (! empty($line->product_label) ? $line->product_label . ' - ' : '');
|
||||
$descriptions[$line->tva_tx] .= $langs->trans('Qty') . ' : ' . $line->qty;
|
||||
$descriptions[$line->tva_tx] .= ' - ' . $langs->trans('TotalHT') . ' : ' . price($line->total_ht) . '</li>';
|
||||
}
|
||||
|
||||
foreach ($TTotalByTva as $tva => &$total) {
|
||||
$coef = $total / $origin->total_ttc; // Calc coef
|
||||
$am = $amount * $coef;
|
||||
$amount_ttc_diff += $am;
|
||||
$amountdeposit[$tva] += $am / (1 + $tva / 100); // Convert into HT for the addline
|
||||
}
|
||||
} else {
|
||||
$totalamount = 0;
|
||||
$lines = $origin->lines;
|
||||
$numlines = count($lines);
|
||||
for ($i = 0; $i < $numlines; $i++) {
|
||||
if (empty($lines[$i]->qty)) {
|
||||
continue; // We discard qty=0, it is an option
|
||||
}
|
||||
if (!empty($lines[$i]->special_code)) {
|
||||
continue; // We discard special_code (frais port, ecotaxe, option, ...)
|
||||
}
|
||||
|
||||
$totalamount += $lines[$i]->total_ht; // Fixme : is it not for the customer ? Shouldn't we take total_ttc ?
|
||||
$tva_tx = $lines[$i]->tva_tx;
|
||||
$amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $origin->deposit_percent) / 100;
|
||||
$descriptions[$tva_tx] .= '<li>' . (! empty($lines[$i]->product_ref) ? $lines[$i]->product_ref . ' - ' : '');
|
||||
$descriptions[$tva_tx] .= (! empty($lines[$i]->product_label) ? $lines[$i]->product_label . ' - ' : '');
|
||||
$descriptions[$tva_tx] .= $langs->trans('Qty') . ' : ' . $lines[$i]->qty;
|
||||
$descriptions[$tva_tx] .= ' - ' . $langs->trans('TotalHT') . ' : ' . price($lines[$i]->total_ht) . '</li>';
|
||||
}
|
||||
|
||||
if ($totalamount == 0) {
|
||||
$amountdeposit[0] = 0;
|
||||
}
|
||||
|
||||
$amount_ttc_diff = $amountdeposit[0];
|
||||
}
|
||||
|
||||
foreach ($amountdeposit as $tva => $amount) {
|
||||
if (empty($amount)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$descline = '(DEPOSIT) ('. $origin->deposit_percent .'%) - '.$origin->ref;
|
||||
|
||||
// Hidden conf
|
||||
if (! empty($conf->global->INVOICE_DEPOSIT_VARIABLE_MODE_DETAIL_LINES_IN_DESCRIPTION) && ! empty($descriptions[$tva])) {
|
||||
$descline .= '<ul>' . $descriptions[$tva] . '</ul>';
|
||||
}
|
||||
|
||||
$addlineResult = $deposit->addline(
|
||||
$descline,
|
||||
$amount, // subprice
|
||||
1, // quantity
|
||||
$tva, // vat rate
|
||||
0, // localtax1_tx
|
||||
0, // localtax2_tx
|
||||
(empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT), // fk_product
|
||||
0, // remise_percent
|
||||
0, // date_start
|
||||
0, // date_end
|
||||
0,
|
||||
$lines[$i]->info_bits, // info_bits
|
||||
0,
|
||||
'HT',
|
||||
0,
|
||||
0, // product_type
|
||||
1,
|
||||
$lines[$i]->special_code,
|
||||
$deposit->origin,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
//,$langs->trans('Deposit') //Deprecated
|
||||
);
|
||||
|
||||
if ($addlineResult < 0) {
|
||||
$origin->db->rollback();
|
||||
$origin->error = $deposit->error;
|
||||
$origin->errors = $deposit->errors;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$diff = $deposit->total_ttc - $amount_ttc_diff;
|
||||
|
||||
if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
|
||||
$deposit->fetch_lines();
|
||||
$subprice_diff = $deposit->lines[0]->subprice - $diff / (1 + $deposit->lines[0]->tva_tx / 100);
|
||||
|
||||
$updatelineResult = $deposit->updateline(
|
||||
$deposit->lines[0]->id,
|
||||
$deposit->lines[0]->desc,
|
||||
$subprice_diff,
|
||||
$deposit->lines[0]->qty,
|
||||
$deposit->lines[0]->remise_percent,
|
||||
$deposit->lines[0]->date_start,
|
||||
$deposit->lines[0]->date_end,
|
||||
$deposit->lines[0]->tva_tx,
|
||||
0,
|
||||
0,
|
||||
'HT',
|
||||
$deposit->lines[0]->info_bits,
|
||||
$deposit->lines[0]->product_type,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$deposit->lines[0]->pa_ht,
|
||||
$deposit->lines[0]->label,
|
||||
0,
|
||||
array(),
|
||||
100
|
||||
);
|
||||
|
||||
if ($updatelineResult < 0) {
|
||||
$origin->db->rollback();
|
||||
$origin->error = $deposit->error;
|
||||
$origin->errors = $deposit->errors;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (! is_object($hookmanager)) {
|
||||
require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
|
||||
$hookmanager = new HookManager($origin->db);
|
||||
}
|
||||
|
||||
$hookmanager->initHooks(array('invoicedao'));
|
||||
|
||||
$parameters = array('objFrom' => $origin);
|
||||
$reshook = $hookmanager->executeHooks('createFrom', $parameters, $deposit, $action); // Note that $action and $object may have been
|
||||
// modified by hook
|
||||
if ($reshook < 0) {
|
||||
$origin->db->rollback();
|
||||
$origin->error = $hookmanager->error;
|
||||
$origin->errors = $hookmanager->errors;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! empty($autoValidateDeposit)) {
|
||||
$validateReturn = $deposit->validate($user, '', 0, $notrigger);
|
||||
|
||||
if ($validateReturn < 0) {
|
||||
$origin->db->rollback();
|
||||
$origin->error = $deposit->error;
|
||||
$origin->errors = $deposit->errors;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
unset($deposit->context['createdepositfromorigin']);
|
||||
|
||||
$origin->db->commit();
|
||||
|
||||
return $deposit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return clicable link of object (with eventually picto)
|
||||
*
|
||||
|
||||
@ -2588,12 +2588,13 @@ abstract class CommonObject
|
||||
/**
|
||||
* Change the payments terms
|
||||
*
|
||||
* @param int $id Id of new payment terms
|
||||
* @return int >0 if OK, <0 if KO
|
||||
* @param int $id Id of new payment terms
|
||||
* @param string $deposit_percent % of deposit if needed by payment terms
|
||||
* @return int >0 if OK, <0 if KO
|
||||
*/
|
||||
public function setPaymentTerms($id)
|
||||
public function setPaymentTerms($id, $deposit_percent = null)
|
||||
{
|
||||
dol_syslog(get_class($this).'::setPaymentTerms('.$id.')');
|
||||
dol_syslog(get_class($this).'::setPaymentTerms('.$id.', '.var_export($deposit_percent, true).')');
|
||||
if ($this->statut >= 0 || $this->element == 'societe') {
|
||||
// TODO uniformize field name
|
||||
$fieldname = 'fk_cond_reglement';
|
||||
@ -2604,8 +2605,17 @@ abstract class CommonObject
|
||||
$fieldname = 'cond_reglement_supplier';
|
||||
}
|
||||
|
||||
if (empty($deposit_percent) || $deposit_percent < 0) {
|
||||
$deposit_percent = getDictionaryValue(MAIN_DB_PREFIX . 'c_payment_term', 'deposit_percent', $id);
|
||||
}
|
||||
|
||||
if ($deposit_percent > 100) {
|
||||
$deposit_percent = 100;
|
||||
}
|
||||
|
||||
$sql = 'UPDATE '.$this->db->prefix().$this->table_element;
|
||||
$sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL');
|
||||
$sql .= " , deposit_percent = " . (! empty($deposit_percent) ? "'".$this->db->escape($deposit_percent)."'" : 'NULL');
|
||||
$sql .= ' WHERE rowid='.((int) $this->id);
|
||||
|
||||
if ($this->db->query($sql)) {
|
||||
@ -2615,6 +2625,7 @@ abstract class CommonObject
|
||||
$this->cond_reglement_supplier_id = $id;
|
||||
}
|
||||
$this->cond_reglement = $id; // for compatibility
|
||||
$this->deposit_percent = $deposit_percent;
|
||||
return 1;
|
||||
} else {
|
||||
dol_syslog(get_class($this).'::setPaymentTerms Error '.$sql.' - '.$this->db->error());
|
||||
|
||||
@ -3729,7 +3729,7 @@ class Form
|
||||
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
|
||||
$sql = "SELECT rowid, code, libelle as label";
|
||||
$sql = "SELECT rowid, code, libelle as label, deposit_percent";
|
||||
$sql .= " FROM ".$this->db->prefix().'c_payment_term';
|
||||
$sql .= " WHERE entity IN (".getEntity('c_payment_term').")";
|
||||
$sql .= " AND active > 0";
|
||||
@ -3746,6 +3746,7 @@ class Form
|
||||
$label = ($langs->trans("PaymentConditionShort".$obj->code) != ("PaymentConditionShort".$obj->code) ? $langs->trans("PaymentConditionShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
||||
$this->cache_conditions_paiements[$obj->rowid]['code'] = $obj->code;
|
||||
$this->cache_conditions_paiements[$obj->rowid]['label'] = $label;
|
||||
$this->cache_conditions_paiements[$obj->rowid]['deposit_percent'] = $obj->deposit_percent;
|
||||
$i++;
|
||||
}
|
||||
|
||||
@ -3991,39 +3992,45 @@ class Form
|
||||
|
||||
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
||||
/**
|
||||
* print list of payment modes.
|
||||
* Constant MAIN_DEFAULT_PAYMENT_TERM_ID can used to set default value but scope is all application, probably not what you want.
|
||||
* See instead to force the default value by the caller.
|
||||
* print list of payment modes.
|
||||
* Constant MAIN_DEFAULT_PAYMENT_TERM_ID can used to set default value but scope is all application, probably not what you want.
|
||||
* See instead to force the default value by the caller.
|
||||
*
|
||||
* @param int $selected Id of payment term to preselect by default
|
||||
* @param string $htmlname Nom de la zone select
|
||||
* @param int $filtertype Not used
|
||||
* @param int $addempty Add an empty entry
|
||||
* @param int $noinfoadmin 0=Add admin info, 1=Disable admin info
|
||||
* @param string $morecss Add more CSS on select tag
|
||||
* @return void
|
||||
* @param int $selected Id of payment term to preselect by default
|
||||
* @param string $htmlname Nom de la zone select
|
||||
* @param int $filtertype If > 0, include payment terms with deposit percentage (for objects other than invoices and invoice templates)
|
||||
* @param int $addempty Add an empty entry
|
||||
* @param int $noinfoadmin 0=Add admin info, 1=Disable admin info
|
||||
* @param string $morecss Add more CSS on select tag
|
||||
* @param string $deposit_percent < 0 : deposit_percent input makes no sense (for example, in list filters)
|
||||
* 0 : use default deposit percentage from entry
|
||||
* > 0 : force deposit percentage (for example, from company object)
|
||||
* @return void
|
||||
*/
|
||||
public function select_conditions_paiements($selected = 0, $htmlname = 'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss = '')
|
||||
public function select_conditions_paiements($selected = 0, $htmlname = 'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss = '', $deposit_percent = -1)
|
||||
{
|
||||
// phpcs:enable
|
||||
print $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, $noinfoadmin, $morecss);
|
||||
print $this->getSelectConditionsPaiements($selected, $htmlname, $filtertype, $addempty, $noinfoadmin, $morecss, $deposit_percent = -1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return list of payment modes.
|
||||
* Constant MAIN_DEFAULT_PAYMENT_TERM_ID can used to set default value but scope is all application, probably not what you want.
|
||||
* See instead to force the default value by the caller.
|
||||
* Return list of payment modes.
|
||||
* Constant MAIN_DEFAULT_PAYMENT_TERM_ID can used to set default value but scope is all application, probably not what you want.
|
||||
* See instead to force the default value by the caller.
|
||||
*
|
||||
* @param int $selected Id of payment term to preselect by default
|
||||
* @param string $htmlname Nom de la zone select
|
||||
* @param int $filtertype Not used
|
||||
* @param int $addempty Add an empty entry
|
||||
* @param int $noinfoadmin 0=Add admin info, 1=Disable admin info
|
||||
* @param string $morecss Add more CSS on select tag
|
||||
* @return void
|
||||
* @param int $selected Id of payment term to preselect by default
|
||||
* @param string $htmlname Nom de la zone select
|
||||
* @param int $filtertype If > 0, include payment terms with deposit percentage (for objects other than invoices and invoice templates)
|
||||
* @param int $addempty Add an empty entry
|
||||
* @param int $noinfoadmin 0=Add admin info, 1=Disable admin info
|
||||
* @param string $morecss Add more CSS on select tag
|
||||
* @param string $deposit_percent < 0 : deposit_percent input makes no sense (for example, in list filters)
|
||||
* 0 : use default deposit percentage from entry
|
||||
* > 0 : force deposit percentage (for example, from company object)
|
||||
* @return string
|
||||
*/
|
||||
public function getSelectConditionsPaiements($selected = 0, $htmlname = 'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss = '')
|
||||
public function getSelectConditionsPaiements($selected = 0, $htmlname = 'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $deposit_percent = -1)
|
||||
{
|
||||
|
||||
global $langs, $user, $conf;
|
||||
@ -4041,20 +4048,59 @@ class Form
|
||||
if ($addempty) {
|
||||
$out.= '<option value="0"> </option>';
|
||||
}
|
||||
|
||||
$selectedDepositPercent = null;
|
||||
|
||||
foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
|
||||
if ($selected == $id) {
|
||||
$out.= '<option value="'.$id.'" selected>';
|
||||
} else {
|
||||
$out.= '<option value="'.$id.'">';
|
||||
if ($filtertype <= 0 && ! empty($arrayconditions['deposit_percent'])) {
|
||||
continue;
|
||||
}
|
||||
$out.= $arrayconditions['label'];
|
||||
$out.= '</option>';
|
||||
|
||||
if ($selected == $id) {
|
||||
$selectedDepositPercent = $deposit_percent > 0 ? $deposit_percent : $arrayconditions['deposit_percent'];
|
||||
$out .= '<option value="'.$id.'" data-deposit_percent="' . $arrayconditions['deposit_percent'] . '" selected>';
|
||||
} else {
|
||||
$out .= '<option value="'.$id.'" data-deposit_percent="' . $arrayconditions['deposit_percent'] . '">';
|
||||
}
|
||||
$label = $arrayconditions['label'];
|
||||
|
||||
if (! empty($arrayconditions['deposit_percent'])) {
|
||||
$label = str_replace('__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $arrayconditions['deposit_percent'], $label);
|
||||
}
|
||||
|
||||
$out.= $label;
|
||||
$out.= '</option>';
|
||||
}
|
||||
$out.= '</select>';
|
||||
if ($user->admin && empty($noinfoadmin)) {
|
||||
$out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
||||
}
|
||||
$out.= ajax_combobox($htmlname);
|
||||
|
||||
if ($deposit_percent >= 0) {
|
||||
$out .= ' <span id="'.$htmlname.'_deposit_percent_container"' . (empty($selectedDepositPercent) ? ' style="display: none"' : '') . '>';
|
||||
$out .= $langs->trans('DepositPercent') . ' : ';
|
||||
$out .= '<input id="'.$htmlname.'_deposit_percent" name="'.$htmlname.'_deposit_percent" class="maxwidth50" value="' . strval($deposit_percent) . '" />';
|
||||
$out .= '</span>';
|
||||
$out .= '
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("#' . $htmlname . '").change(function () {
|
||||
let $selected = $(this).find("option:selected");
|
||||
let depositPercent = $selected.attr("data-deposit_percent");
|
||||
|
||||
if (depositPercent.length > 0) {
|
||||
$("#'.$htmlname.'_deposit_percent_container").show().find("#'.$htmlname.'_deposit_percent").val(depositPercent);
|
||||
} else {
|
||||
$("#'.$htmlname.'_deposit_percent_container").hide();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
@ -5245,14 +5291,18 @@ class Form
|
||||
/**
|
||||
* Show a form to select payment conditions
|
||||
*
|
||||
* @param int $page Page
|
||||
* @param string $selected Id condition pre-selectionne
|
||||
* @param string $htmlname Name of select html field
|
||||
* @param int $addempty Add empty entry
|
||||
* @param string $type Type ('direct-debit' or 'bank-transfer')
|
||||
* @param int $page Page
|
||||
* @param string $selected Id condition pre-selectionne
|
||||
* @param string $htmlname Name of select html field
|
||||
* @param int $addempty Add empty entry
|
||||
* @param string $type Type ('direct-debit' or 'bank-transfer')
|
||||
* @param int $filtertype If > 0, include payment terms with deposit percentage (for objects other than invoices and invoice templates)
|
||||
* @param string $deposit_percent < 0 : deposit_percent input makes no sense (for example, in list filters)
|
||||
* 0 : use default deposit percentage from entry
|
||||
* > 0 : force deposit percentage (for example, from company object)
|
||||
* @return void
|
||||
*/
|
||||
public function form_conditions_reglement($page, $selected = '', $htmlname = 'cond_reglement_id', $addempty = 0, $type = '')
|
||||
public function form_conditions_reglement($page, $selected = '', $htmlname = 'cond_reglement_id', $addempty = 0, $type = '', $filtertype = -1, $deposit_percent = -1)
|
||||
{
|
||||
// phpcs:enable
|
||||
global $langs;
|
||||
@ -5263,14 +5313,20 @@ class Form
|
||||
if ($type) {
|
||||
print '<input type="hidden" name="type" value="'.dol_escape_htmltag($type).'">';
|
||||
}
|
||||
$this->select_conditions_paiements($selected, $htmlname, -1, $addempty, 0, '');
|
||||
$this->select_conditions_paiements($selected, $htmlname, $filtertype, $addempty, 0, '', $deposit_percent);
|
||||
print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
|
||||
print '</form>';
|
||||
} else {
|
||||
if ($selected) {
|
||||
$this->load_cache_conditions_paiements();
|
||||
if (isset($this->cache_conditions_paiements[$selected])) {
|
||||
print $this->cache_conditions_paiements[$selected]['label'];
|
||||
$label = $this->cache_conditions_paiements[$selected]['label'];
|
||||
|
||||
if (! empty($this->cache_conditions_paiements[$selected]['deposit_percent'])) {
|
||||
$label = str_replace('__DEPOSIT_PERCENT__', $deposit_percent > 0 ? $deposit_percent : $this->cache_conditions_paiements[$selected]['deposit_percent'], $label);
|
||||
}
|
||||
|
||||
print $label;
|
||||
} else {
|
||||
$langs->load('errors');
|
||||
print $langs->trans('ErrorNotInDictionaryPaymentConditions');
|
||||
|
||||
@ -742,6 +742,9 @@ class pdf_einstein extends ModelePDFCommandes
|
||||
$pdf->SetXY($posxval, $posy);
|
||||
$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
|
||||
$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
|
||||
if ($object->deposit_percent > 0) {
|
||||
$lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
|
||||
}
|
||||
$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
|
||||
|
||||
$posy = $pdf->GetY() + 3;
|
||||
|
||||
@ -960,6 +960,9 @@ class pdf_eratosthene extends ModelePDFCommandes
|
||||
$pdf->SetXY($posxval, $posy);
|
||||
$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
|
||||
$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
|
||||
if ($object->deposit_percent > 0) {
|
||||
$lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
|
||||
}
|
||||
$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
|
||||
|
||||
$posy = $pdf->GetY() + 3;
|
||||
|
||||
@ -964,6 +964,9 @@ class pdf_azur extends ModelePDFPropales
|
||||
$pdf->SetXY($posxval, $posy);
|
||||
$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
|
||||
$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
|
||||
if ($object->deposit_percent > 0) {
|
||||
$lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
|
||||
}
|
||||
$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
|
||||
|
||||
$posy = $pdf->GetY() + 3;
|
||||
|
||||
@ -1083,6 +1083,9 @@ class pdf_cyan extends ModelePDFPropales
|
||||
$pdf->SetXY($posxval, $posy);
|
||||
$lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
|
||||
$lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
|
||||
if ($object->deposit_percent > 0) {
|
||||
$lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
|
||||
}
|
||||
$pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
|
||||
|
||||
$posy = $pdf->GetY() + 3;
|
||||
|
||||
@ -266,7 +266,7 @@ if ($object->id > 0) {
|
||||
print '</tr></table>';
|
||||
print '</td><td>';
|
||||
if ($action == 'editconditions') {
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'cond_reglement_supplier_id', -1, 1);
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'cond_reglement_supplier_id', 1);
|
||||
} else {
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'none');
|
||||
}
|
||||
|
||||
@ -1474,7 +1474,7 @@ if ($resql) {
|
||||
// Payment condition
|
||||
if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
|
||||
print '<td class="tdoverflowmax125">';
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', '', -1);
|
||||
$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1);
|
||||
print '</td>';
|
||||
if (!$i) {
|
||||
$totalarray['nbfield']++;
|
||||
|
||||
@ -26,17 +26,18 @@
|
||||
-- Do not include comments at end of line, this file is parsed during install and string '--' are removed.
|
||||
--
|
||||
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (1 ,'RECEP', 1,1, 'Due upon receipt','Due upon receipt',0,1);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (2 ,'30D', 2,1, '30 days','Due in 30 days',0,30);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (3 ,'30DENDMONTH', 3,1, '30 days end of month','Due in 30 days, end of month',1,30);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (4 ,'60D', 4,1, '60 days','Due in 60 days, end of month',0,60);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (5 ,'60DENDMONTH', 5,1, '60 days end of month','Due in 60 days, end of month',1,60);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (6 ,'PT_ORDER', 6,1, 'Due on order','Due on order',0,1);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (7 ,'PT_DELIVERY', 7,1, 'Due on delivery','Due on delivery',0,1);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (8 ,'PT_5050', 8,1, '50 and 50','50% on order, 50% on delivery',0,1);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (1 ,'RECEP', 1,1, 'Due upon receipt','Due upon receipt',0,1,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (2 ,'30D', 2,1, '30 days','Due in 30 days',0,30,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (3 ,'30DENDMONTH', 3,1, '30 days end of month','Due in 30 days, end of month',1,30,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (4 ,'60D', 4,1, '60 days','Due in 60 days, end of month',0,60,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (5 ,'60DENDMONTH', 5,1, '60 days end of month','Due in 60 days, end of month',1,60,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (6 ,'PT_ORDER', 6,1, 'Due on order','Due on order',0,1,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (7 ,'PT_DELIVERY', 7,1, 'Due on delivery','Due on delivery',0,1,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (8 ,'PT_5050', 8,1, '50 and 50','50% on order, 50% on delivery',0,1,NULL);
|
||||
|
||||
-- Add additional payment terms often needed in Austria
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (9 ,'10D', 9,1, '10 days','Due in 10 days',0,10);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (10,'10DENDMONTH', 10,1, '10 days end of month','Due in 10 days, end of month',1,10);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (11,'14D', 11,1, '14 days','Due in 14 days',0,14);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour) values (12,'14DENDMONTH', 12,1, '14 days end of month','Due in 14 days, end of month',1,14);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (9 ,'10D', 9,1, '10 days','Due in 10 days',0,10,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (10,'10DENDMONTH', 10,1, '10 days end of month','Due in 10 days, end of month',1,10,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (11,'14D', 11,1, '14 days','Due in 14 days',0,14,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (12,'14DENDMONTH', 12,1, '14 days end of month','Due in 14 days, end of month',1,14,NULL);
|
||||
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (13,'DEP30PCTDEL', 13,0, '__DEPOSIT_PERCENT__% deposit','__DEPOSIT_PERCENT__% deposit, remainder on delivery',0,1,'30');
|
||||
|
||||
@ -327,6 +327,15 @@ UPDATE llx_c_availability SET type_duration = 'w', qty = 2 WHERE code = 'AV_2W';
|
||||
UPDATE llx_c_availability SET type_duration = 'w', qty = 3 WHERE code = 'AV_3W';
|
||||
UPDATE llx_c_availability SET type_duration = 'w', qty = 4 WHERE code = 'AV_4W';
|
||||
|
||||
|
||||
-- Deposit generation helper with specific payment terms
|
||||
ALTER TABLE llx_c_payment_term ADD COLUMN deposit_percent VARCHAR(63) DEFAULT NULL AFTER decalage;
|
||||
ALTER TABLE llx_societe ADD COLUMN deposit_percent VARCHAR(63) DEFAULT NULL AFTER cond_reglement;
|
||||
ALTER TABLE llx_propal ADD COLUMN deposit_percent VARCHAR(63) DEFAULT NULL AFTER fk_cond_reglement;
|
||||
ALTER TABLE llx_commande ADD COLUMN deposit_percent VARCHAR(63) DEFAULT NULL AFTER fk_cond_reglement;
|
||||
INSERT INTO llx_c_payment_term(code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values ('DEP30PCTDEL', 13, 0, '__DEPOSIT_PERCENT__% deposit', '__DEPOSIT_PERCENT__% deposit, remainder on delivery', 0, 1, '30');
|
||||
|
||||
|
||||
ALTER TABLE llx_boxes_def ADD COLUMN fk_user integer DEFAULT 0 NOT NULL;
|
||||
|
||||
ALTER TABLE llx_contratdet ADD COLUMN rang integer DEFAULT 0 AFTER info_bits;
|
||||
@ -352,3 +361,4 @@ ALTER TABLE llx_c_email_template ADD COLUMN email_to varchar(255);
|
||||
ALTER TABLE llx_c_email_template ADD COLUMN email_tocc varchar(255);
|
||||
ALTER TABLE llx_c_email_template ADD COLUMN email_tobcc varchar(255);
|
||||
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@ create table llx_c_payment_term
|
||||
type_cdr tinyint, -- Type of change date reckoning. 1=Payment at end of current month, 2=the Nth of next month
|
||||
nbjour smallint,
|
||||
decalage smallint,
|
||||
deposit_percent varchar(63) DEFAULT NULL,
|
||||
module varchar(32) NULL,
|
||||
position integer NOT NULL DEFAULT 0
|
||||
)ENGINE=innodb;
|
||||
|
||||
@ -63,6 +63,7 @@ create table llx_commande
|
||||
fk_account integer, -- bank account
|
||||
fk_currency varchar(3), -- currency code
|
||||
fk_cond_reglement integer, -- condition de reglement
|
||||
deposit_percent varchar(63) DEFAULT NULL, -- default deposit % if payment term needs it
|
||||
fk_mode_reglement integer, -- mode de reglement
|
||||
|
||||
date_livraison datetime default NULL,
|
||||
|
||||
@ -58,6 +58,7 @@ create table llx_propal
|
||||
fk_account integer, -- bank account
|
||||
fk_currency varchar(3), -- currency code
|
||||
fk_cond_reglement integer, -- condition de reglement (30 jours, fin de mois ...)
|
||||
deposit_percent varchar(63) DEFAULT NULL, -- default deposit % if payment term needs it
|
||||
fk_mode_reglement integer, -- mode de reglement (Virement, Prelevement)
|
||||
|
||||
online_sign_ip varchar(48),
|
||||
|
||||
@ -84,6 +84,7 @@ create table llx_societe
|
||||
remise_supplier real DEFAULT 0, -- discount by default granted by this supplier
|
||||
mode_reglement tinyint, -- payment mode customer
|
||||
cond_reglement tinyint, -- payment term customer
|
||||
deposit_percent varchar(63) DEFAULT NULL, -- default deposit % if payment term needs it
|
||||
transport_mode tinyint, -- transport mode customer (Intracomm report)
|
||||
mode_reglement_supplier tinyint, -- payment mode supplier
|
||||
cond_reglement_supplier tinyint, -- payment term supplier
|
||||
|
||||
@ -429,10 +429,19 @@ PaymentConditionShort14D=14 days
|
||||
PaymentCondition14D=14 days
|
||||
PaymentConditionShort14DENDMONTH=14 days of month-end
|
||||
PaymentCondition14DENDMONTH=Within 14 days following the end of the month
|
||||
PaymentConditionShortDEP30PCTDEL=__DEPOSIT_PERCENT__%% deposit
|
||||
PaymentConditionDEP30PCTDEL=__DEPOSIT_PERCENT__%% deposit, remainder on delivery
|
||||
FixAmount=Fixed amount - 1 line with label '%s'
|
||||
VarAmount=Variable amount (%% tot.)
|
||||
VarAmountOneLine=Variable amount (%% tot.) - 1 line with label '%s'
|
||||
VarAmountAllLines=Variable amount (%% tot.) - all lines from origin
|
||||
DepositPercent=Deposit %%
|
||||
DepositGenerationPermittedByThePaymentTermsSelected=This is permitted by the payment terms selected
|
||||
GenerateDeposit=Generate a %s%% deposit invoice
|
||||
ValidateGeneratedDeposit=Validate the generated deposit
|
||||
DepositGenerated=Deposit generated
|
||||
ErrorCanOnlyAutomaticallyGenerateADepositFromProposalOrOrder=You can only automatically generate a deposit from a proposal or an order
|
||||
ErrorPaymentConditionsNotEligibleToDepositCreation=The chose payment conditions are not eligible for automatic deposit generation
|
||||
# PaymentType
|
||||
PaymentTypeVIR=Bank transfer
|
||||
PaymentTypeShortVIR=Bank transfer
|
||||
|
||||
@ -209,6 +209,7 @@ class Societe extends CommonObject
|
||||
//'remise_supplier' =>array('type'=>'double', 'label'=>'SupplierDiscount', 'enabled'=>1, 'visible'=>-1, 'position'=>290, 'isameasure'=>1),
|
||||
'mode_reglement' =>array('type'=>'tinyint(4)', 'label'=>'Mode reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>295),
|
||||
'cond_reglement' =>array('type'=>'tinyint(4)', 'label'=>'Cond reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>300),
|
||||
'deposit_percent' =>array('type'=>'varchar(63)', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>301),
|
||||
'mode_reglement_supplier' =>array('type'=>'integer', 'label'=>'Mode reglement supplier', 'enabled'=>1, 'visible'=>-1, 'position'=>305),
|
||||
'cond_reglement_supplier' =>array('type'=>'integer', 'label'=>'Cond reglement supplier', 'enabled'=>1, 'visible'=>-1, 'position'=>308),
|
||||
'outstanding_limit' =>array('type'=>'double(24,8)', 'label'=>'OutstandingBill', 'enabled'=>1, 'visible'=>-1, 'position'=>310, 'isameasure'=>1),
|
||||
@ -482,6 +483,9 @@ class Societe extends CommonObject
|
||||
public $remise_percent;
|
||||
public $remise_supplier_percent;
|
||||
|
||||
public $mode_reglement_id;
|
||||
public $cond_reglement_id;
|
||||
public $deposit_percent;
|
||||
public $mode_reglement_supplier_id;
|
||||
public $cond_reglement_supplier_id;
|
||||
public $transport_mode_supplier_id;
|
||||
@ -1462,6 +1466,7 @@ class Societe extends CommonObject
|
||||
|
||||
$sql .= ",mode_reglement = ".(!empty($this->mode_reglement_id) ? "'".$this->db->escape($this->mode_reglement_id)."'" : "null");
|
||||
$sql .= ",cond_reglement = ".(!empty($this->cond_reglement_id) ? "'".$this->db->escape($this->cond_reglement_id)."'" : "null");
|
||||
$sql .= ",deposit_percent = ".(!empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : "null");
|
||||
$sql .= ",transport_mode = ".(!empty($this->transport_mode_id) ? "'".$this->db->escape($this->transport_mode_id)."'" : "null");
|
||||
$sql .= ",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ? "'".$this->db->escape($this->mode_reglement_supplier_id)."'" : "null");
|
||||
$sql .= ",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ? "'".$this->db->escape($this->cond_reglement_supplier_id)."'" : "null");
|
||||
@ -1691,7 +1696,7 @@ class Societe extends CommonObject
|
||||
$sql .= ', spe.accountancy_code_customer as code_compta, spe.accountancy_code_supplier as code_compta_fournisseur, spe.accountancy_code_buy, spe.accountancy_code_sell';
|
||||
}
|
||||
$sql .= ', s.code_client, s.code_fournisseur, s.parent, s.barcode';
|
||||
$sql .= ', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.mode_reglement, s.cond_reglement, s.transport_mode';
|
||||
$sql .= ', s.fk_departement as state_id, s.fk_pays as country_id, s.fk_stcomm, s.mode_reglement, s.cond_reglement, s.deposit_percent, s.transport_mode';
|
||||
$sql .= ', s.fk_account, s.tva_assuj';
|
||||
$sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.transport_mode_supplier';
|
||||
$sql .= ', s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo, s.logo_squarred';
|
||||
@ -1869,6 +1874,7 @@ class Societe extends CommonObject
|
||||
|
||||
$this->mode_reglement_id = $obj->mode_reglement;
|
||||
$this->cond_reglement_id = $obj->cond_reglement;
|
||||
$this->deposit_percent = $obj->deposit_percent;
|
||||
$this->transport_mode_id = $obj->transport_mode;
|
||||
$this->mode_reglement_supplier_id = $obj->mode_reglement_supplier;
|
||||
$this->cond_reglement_supplier_id = $obj->cond_reglement_supplier;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user