Merge pull request #13145 from atm-john/12.0_new_extend_retained_warranty

NEW : Extend retained warranty to be  available for all invoices
This commit is contained in:
Laurent Destailleur 2020-04-18 15:32:33 +02:00 committed by GitHub
commit 2f2e3d5057
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 633 additions and 595 deletions

View File

@ -36,13 +36,13 @@ require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
// Load translation files required by the page // Load translation files required by the page
$langs->loadLangs(array('admin', 'errors', 'other', 'bills')); $langs->loadLangs(array('admin', 'errors', 'other', 'bills'));
if (!$user->admin) accessforbidden(); if (! $user->admin) accessforbidden();
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$value = GETPOST('value', 'alpha'); $value = GETPOST('value', 'alpha');
$label = GETPOST('label', 'alpha'); $label = GETPOST('label', 'alpha');
$scandir = GETPOST('scan_dir', 'alpha'); $scandir = GETPOST('scan_dir', 'alpha');
$type = 'invoice'; $type='invoice';
/* /*
@ -57,17 +57,17 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
* View * View
*/ */
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $dirmodels=array_merge(array('/'), (array) $conf->modules_parts['models']);
llxHeader( llxHeader(
"", $langs->trans("BillsSetup"), "", $langs->trans("BillsSetup"),
'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura' 'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura'
); );
$form = new Form($db); $form=new Form($db);
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup'); print load_fiche_titre($langs->trans("BillsSetup"), $linkback, 'title_setup');
$head = invoice_admin_prepare_head(); $head = invoice_admin_prepare_head();
@ -96,7 +96,26 @@ print "</tr>\n";
_printOnOff('INVOICE_USE_SITUATION', $langs->trans('UseSituationInvoices')); _printOnOff('INVOICE_USE_SITUATION', $langs->trans('UseSituationInvoices'));
_printOnOff('INVOICE_USE_SITUATION_CREDIT_NOTE', $langs->trans('UseSituationInvoicesCreditNote')); _printOnOff('INVOICE_USE_SITUATION_CREDIT_NOTE', $langs->trans('UseSituationInvoicesCreditNote'));
_printOnOff('INVOICE_USE_SITUATION_RETAINED_WARRANTY', $langs->trans('Retainedwarranty')); //_printOnOff('INVOICE_USE_RETAINED_WARRANTY', $langs->trans('Retainedwarranty'));
$confkey = 'INVOICE_USE_RETAINED_WARRANTY';
$arrayAvailableType = array(
Facture::TYPE_SITUATION => $langs->trans("InvoiceSituation"),
Facture::TYPE_STANDARD.'+'.Facture::TYPE_SITUATION => $langs->trans("InvoiceSituation").' + '.$langs->trans("InvoiceStandard"),
);
$selected = array();
$implodeglue = '+';
if(!empty($conf->global->{$confkey}) && !is_array($conf->global->{$confkey})){
$selected = explode('+', $conf->global->{$confkey});
}
$curentInput = (empty($inputCount)?1:($inputCount+1));
$formSelectInvoiceType = $form->selectarray('value'. $curentInput, $arrayAvailableType, $selected, 1);
_printInputFormPart($confkey, $langs->trans('AllowedInvoiceForRetainedWarranty'), '', array(), $formSelectInvoiceType);
//_printOnOff('INVOICE_RETAINED_WARRANTY_LIMITED_TO_SITUATION', $langs->trans('RetainedwarrantyOnlyForSituation'));
_printOnOff('INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION', $langs->trans('RetainedwarrantyOnlyForSituationFinal'));
$metas = array( $metas = array(
'type' => 'number', 'type' => 'number',
@ -107,7 +126,7 @@ $metas = array(
_printInputFormPart('INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT', $langs->trans('RetainedwarrantyDefaultPercent'), '', $metas); _printInputFormPart('INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT', $langs->trans('RetainedwarrantyDefaultPercent'), '', $metas);
// Conditions paiements // Conditions paiements
$inputCount = empty($inputCount) ? 1 : ($inputCount + 1); $inputCount = empty($inputCount)?1:($inputCount+1);
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'.$langs->trans('PaymentConditionsShortRetainedWarranty').'</td>'; print '<td>'.$langs->trans('PaymentConditionsShortRetainedWarranty').'</td>';
print '<td class="center" width="20">&nbsp;</td>'; print '<td class="center" width="20">&nbsp;</td>';
@ -159,7 +178,7 @@ function _printOnOff($confkey, $title = false, $desc = '')
global $langs; global $langs;
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'.($title ? $title : $langs->trans($confkey)); print '<td>'.($title?$title:$langs->trans($confkey));
if (!empty($desc)) { if (!empty($desc)) {
print '<br><small>'.$langs->trans($desc).'</small>'; print '<br><small>'.$langs->trans($desc).'</small>';
} }
@ -187,14 +206,14 @@ function _printInputFormPart($confkey, $title = false, $desc = '', $metas = arra
{ {
global $langs, $conf, $db, $inputCount; global $langs, $conf, $db, $inputCount;
$inputCount = empty($inputCount) ? 1 : ($inputCount + 1); $inputCount = empty($inputCount)?1:($inputCount+1);
$form = new Form($db); $form=new Form($db);
$defaultMetas = array( $defaultMetas = array(
'name' => 'value'.$inputCount 'name' => 'value'.$inputCount
); );
if ($type != 'textarea') { if ($type!='textarea') {
$defaultMetas['type'] = 'text'; $defaultMetas['type'] = 'text';
$defaultMetas['value'] = $conf->global->{$confkey}; $defaultMetas['value'] = $conf->global->{$confkey};
} }
@ -210,9 +229,9 @@ function _printInputFormPart($confkey, $title = false, $desc = '', $metas = arra
print '<td>'; print '<td>';
if (!empty($help)) { if (!empty($help)) {
print $form->textwithtooltip(($title ? $title : $langs->trans($confkey)), $langs->trans($help), 2, 1, img_help(1, '')); print $form->textwithtooltip(($title?$title:$langs->trans($confkey)), $langs->trans($help), 2, 1, img_help(1, ''));
} else { } else {
print $title ? $title : $langs->trans($confkey); print $title?$title:$langs->trans($confkey);
} }
if (!empty($desc)) { if (!empty($desc)) {
@ -225,10 +244,14 @@ function _printInputFormPart($confkey, $title = false, $desc = '', $metas = arra
print '<input type="hidden" name="param'.$inputCount.'" value="'.$confkey.'">'; print '<input type="hidden" name="param'.$inputCount.'" value="'.$confkey.'">';
print '<input type="hidden" name="action" value="setModuleOptions">'; print '<input type="hidden" name="action" value="setModuleOptions">';
if ($type == 'textarea') { if ($type=='textarea') {
print '<textarea '.$metascompil.' >'.dol_htmlentities($conf->global->{$confkey}).'</textarea>'; print '<textarea '.$metascompil.' >'.dol_htmlentities($conf->global->{$confkey}).'</textarea>';
} else { }elseif($type=='input'){
print '<input '.$metascompil.' />'; print '<input '.$metascompil.' />';
}
else{
// custom
print $type;
} }
print '</td></tr>'; print '</td></tr>';
} }

View File

@ -139,6 +139,11 @@ if ($user->socid) $socid = $user->socid;
$isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0); $isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0);
$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft); $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft);
// retained warranty invoice available type
$retainedWarrantyInvoiceAvailableType=array();
if(!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
$retainedWarrantyInvoiceAvailableType = explode('+', $conf->global->INVOICE_USE_RETAINED_WARRANTY);
}
/* /*
@ -947,7 +952,7 @@ if (empty($reshook))
} }
$discount->tva_tx = abs($tva_tx); $discount->tva_tx = abs($tva_tx);
$discount->vat_src_code = $vat_src_code; $discount->vat_src_code =$vat_src_code;
$result = $discount->create($user); $result = $discount->create($user);
if ($result < 0) if ($result < 0)
@ -1355,17 +1360,22 @@ if (empty($reshook))
$object->situation_counter = 1; $object->situation_counter = 1;
$object->situation_final = 0; $object->situation_final = 0;
$object->situation_cycle_ref = $object->newCycle(); $object->situation_cycle_ref = $object->newCycle();
}
if(in_array($object->type, $retainedWarrantyInvoiceAvailableType)){
$object->retained_warranty = GETPOST('retained_warranty', 'int'); $object->retained_warranty = GETPOST('retained_warranty', 'int');
$object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); $object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int');
}
else{
$object->retained_warranty = 0;
$object->retained_warranty_fk_cond_reglement = 0;
}
$retained_warranty_date_limit = GETPOST('retained_warranty_date_limit'); $retained_warranty_date_limit = GETPOST('retained_warranty_date_limit');
if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) { if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
$object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit); $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
} }
$object->retained_warranty_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); $object->retained_warranty_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
}
$object->fetch_thirdparty(); $object->fetch_thirdparty();
@ -1756,20 +1766,31 @@ if (empty($reshook))
$object->fk_facture_source = $_POST['situations']; $object->fk_facture_source = $_POST['situations'];
$object->type = Facture::TYPE_SITUATION; $object->type = Facture::TYPE_SITUATION;
if (!empty($origin) && !empty($originid))
{
$object->origin = $origin;
$object->origin_id = $originid;
$object->retained_warranty = GETPOST('retained_warranty', 'int'); // retained warranty
if(!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY))
{
$retained_warranty = GETPOST('retained_warranty', 'int');
if(price2num($retained_warranty) > 0)
{
$object->retained_warranty = price2num($retained_warranty);
}
if(GETPOST('retained_warranty_fk_cond_reglement', 'int') > 0)
{
$object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); $object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int');
}
$retained_warranty_date_limit = GETPOST('retained_warranty_date_limit'); $retained_warranty_date_limit = GETPOST('retained_warranty_date_limit');
if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) { if (!empty($retained_warranty_date_limit) && $db->jdate($retained_warranty_date_limit)) {
$object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit); $object->retained_warranty_date_limit = $db->jdate($retained_warranty_date_limit);
} }
$object->retained_warranty_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); $object->retained_warranty_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
}
if (!empty($origin) && !empty($originid))
{
$object->origin = $origin;
$object->origin_id = $originid;
foreach ($object->lines as $i => &$line) foreach ($object->lines as $i => &$line)
{ {
@ -2608,10 +2629,10 @@ if (empty($reshook))
$pa_ht = $originLine->pa_ht; $pa_ht = $originLine->pa_ht;
$label = $originLine->label; $label = $originLine->label;
$array_options = $originLine->array_options; $array_options = $originLine->array_options;
if ($object->type == Facture::TYPE_SITUATION) { if($object->type == Facture::TYPE_SITUATION){
$situation_percent = 0; $situation_percent = 0;
} }
else { else{
$situation_percent = 100; $situation_percent = 100;
} }
$fk_prev_id = ''; $fk_prev_id = '';
@ -3371,22 +3392,20 @@ if ($action == 'create')
$form->select_conditions_paiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id'); $form->select_conditions_paiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id');
print '</td></tr>'; print '</td></tr>';
if (!empty($conf->global->INVOICE_USE_SITUATION))
{ if($conf->global->INVOICE_USE_RETAINED_WARRANTY){
if ($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY) {
$rwStyle = 'display:none;'; $rwStyle = 'display:none;';
if (GETPOST('type', 'int') == Facture::TYPE_SITUATION) { if(in_array(GETPOST('type', 'int'), $retainedWarrantyInvoiceAvailableType)){
$rwStyle = ''; $rwStyle = '';
} }
$retained_warranty = GETPOST('retained_warranty', 'int'); $retained_warranty = GETPOST('retained_warranty', 'int');
if (empty($retained_warranty)) { if(empty($retained_warranty)){
if (!empty($objectsrc->retained_warranty)) { // use previous situation value if(!empty($objectsrc->retained_warranty)){ // use previous situation value
$retained_warranty = $objectsrc->retained_warranty; $retained_warranty = $objectsrc->retained_warranty;
} else {
$retained_warranty = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
} }
} }
$retained_warranty_js_default = !empty($retained_warranty)?$retained_warranty:$conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
print '<tr class="retained-warranty-line" style="'.$rwStyle.'" ><td class="nowrap">'.$langs->trans('RetainedWarranty').'</td><td colspan="2">'; print '<tr class="retained-warranty-line" style="'.$rwStyle.'" ><td class="nowrap">'.$langs->trans('RetainedWarranty').'</td><td colspan="2">';
print '<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.'" step="0.01" min="0" max="100" />%'; print '<input id="new-situation-invoice-retained-warranty" name="retained_warranty" type="number" value="'.$retained_warranty.'" step="0.01" min="0" max="100" />%';
@ -3394,11 +3413,11 @@ if ($action == 'create')
// Retained warranty payment term // Retained warranty payment term
print '<tr class="retained-warranty-line" style="'.$rwStyle.'" ><td class="nowrap">'.$langs->trans('PaymentConditionsShortRetainedWarranty').'</td><td colspan="2">'; print '<tr class="retained-warranty-line" style="'.$rwStyle.'" ><td class="nowrap">'.$langs->trans('PaymentConditionsShortRetainedWarranty').'</td><td colspan="2">';
$retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int');
if (empty($retained_warranty_fk_cond_reglement)) { if(empty($retained_warranty_fk_cond_reglement)){
$retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
if (!empty($objectsrc->retained_warranty_fk_cond_reglement)) { // use previous situation value if(!empty($objectsrc->retained_warranty_fk_cond_reglement)){ // use previous situation value
$retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement; $retained_warranty_fk_cond_reglement = $objectsrc->retained_warranty_fk_cond_reglement;
} else { }else{
$retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; $retained_warranty_fk_cond_reglement = $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID;
} }
} }
@ -3407,19 +3426,22 @@ if ($action == 'create')
print '<script type="text/javascript" language="javascript"> print '<script type="text/javascript" language="javascript">
$(document).ready(function() { $(document).ready(function() {
$("[name=\'type\'").change(function() { $("[name=\'type\']").change(function() {
if($( this ).prop("checked") && $( this ).val() == '.Facture::TYPE_SITUATION.') if($( this ).prop("checked") && $.inArray($( this ).val(), '.json_encode($retainedWarrantyInvoiceAvailableType).' ) !== -1)
{ {
$(".retained-warranty-line").show(); $(".retained-warranty-line").show();
$("#new-situation-invoice-retained-warranty").val("'.doubleval($retained_warranty_js_default).'");
} }
else{ else{
$(".retained-warranty-line").hide(); $(".retained-warranty-line").hide();
$("#new-situation-invoice-retained-warranty").val("");
} }
}); });
$("[name=\'type\']").trigger("change");
}); });
</script>'; </script>';
} }
}
// Payment mode // Payment mode
print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">'; print '<tr><td>'.$langs->trans('PaymentMode').'</td><td colspan="2">';
@ -4333,21 +4355,17 @@ elseif ($id > 0 || !empty($ref))
print '</td></tr>'; print '</td></tr>';
} }
$displayWarranty = false;
if (($object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY))))
{ if(!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
// Check if this situation invoice is 100% for real
if (!empty($object->situation_final) && !empty($object->lines)) {
$displayWarranty = true; $displayWarranty = true;
foreach ($object->lines as $i => $line) { if(!in_array($object->type, $retainedWarrantyInvoiceAvailableType) && empty($object->retained_warranty)){
if ($line->product_type < 2 && $line->situation_percent < 100) {
$displayWarranty = false; $displayWarranty = false;
break;
}
}
} }
if($displayWarranty)
{
// Retained Warranty // Retained Warranty
print '<tr class="retained-warranty-lines" ><td>'; print '<tr class="retained-warranty-lines" ><td>';
@ -4413,9 +4431,6 @@ elseif ($id > 0 || !empty($ref))
} }
print '</td></tr>'; print '</td></tr>';
if ($displayWarranty)
{
// Retained Warranty payment date limit // Retained Warranty payment date limit
print '<tr class="retained-warranty-lines" ><td>'; print '<tr class="retained-warranty-lines" ><td>';
print '<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>'; print '<table id="retained-warranty-date-limit-table" class="nobordernopadding" width="100%"><tr><td>';

View File

@ -302,9 +302,9 @@ class Facture extends CommonInvoice
'situation_cycle_ref' =>array('type'=>'smallint(6)', 'label'=>'Situation cycle ref', 'enabled'=>'$conf->global->INVOICE_USE_SITUATION', 'visible'=>-1, 'position'=>230), 'situation_cycle_ref' =>array('type'=>'smallint(6)', 'label'=>'Situation cycle ref', 'enabled'=>'$conf->global->INVOICE_USE_SITUATION', 'visible'=>-1, 'position'=>230),
'situation_counter' =>array('type'=>'smallint(6)', 'label'=>'Situation counter', 'enabled'=>'$conf->global->INVOICE_USE_SITUATION', 'visible'=>-1, 'position'=>235), 'situation_counter' =>array('type'=>'smallint(6)', 'label'=>'Situation counter', 'enabled'=>'$conf->global->INVOICE_USE_SITUATION', 'visible'=>-1, 'position'=>235),
'situation_final' =>array('type'=>'smallint(6)', 'label'=>'Situation final', 'enabled'=>'empty($conf->global->INVOICE_USE_SITUATION) ? 0 : 1', 'visible'=>-1, 'position'=>240), 'situation_final' =>array('type'=>'smallint(6)', 'label'=>'Situation final', 'enabled'=>'empty($conf->global->INVOICE_USE_SITUATION) ? 0 : 1', 'visible'=>-1, 'position'=>240),
'retained_warranty' =>array('type'=>'double', 'label'=>'Retained warranty', 'enabled'=>'$conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY', 'visible'=>-1, 'position'=>245), 'retained_warranty' =>array('type'=>'double', 'label'=>'Retained warranty', 'enabled'=>'$conf->global->INVOICE_USE_RETAINED_WARRANTY', 'visible'=>-1, 'position'=>245),
'retained_warranty_date_limit' =>array('type'=>'date', 'label'=>'Retained warranty date limit', 'enabled'=>'$conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY', 'visible'=>-1, 'position'=>250), 'retained_warranty_date_limit' =>array('type'=>'date', 'label'=>'Retained warranty date limit', 'enabled'=>'$conf->global->INVOICE_USE_RETAINED_WARRANTY', 'visible'=>-1, 'position'=>250),
'retained_warranty_fk_cond_reglement' =>array('type'=>'integer', 'label'=>'Retained warranty fk cond reglement', 'enabled'=>'$conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY', 'visible'=>-1, 'position'=>255), 'retained_warranty_fk_cond_reglement' =>array('type'=>'integer', 'label'=>'Retained warranty fk cond reglement', 'enabled'=>'$conf->global->INVOICE_USE_RETAINED_WARRANTY', 'visible'=>-1, 'position'=>255),
'fk_incoterms' =>array('type'=>'integer', 'label'=>'IncotermCode', 'enabled'=>'$conf->incoterm->enabled', 'visible'=>-1, 'position'=>260), 'fk_incoterms' =>array('type'=>'integer', 'label'=>'IncotermCode', 'enabled'=>'$conf->incoterm->enabled', 'visible'=>-1, 'position'=>260),
'location_incoterms' =>array('type'=>'varchar(255)', 'label'=>'IncotermLabel', 'enabled'=>'$conf->incoterm->enabled', 'visible'=>-1, 'position'=>265), 'location_incoterms' =>array('type'=>'varchar(255)', 'label'=>'IncotermLabel', 'enabled'=>'$conf->incoterm->enabled', 'visible'=>-1, 'position'=>265),
'date_pointoftax' =>array('type'=>'date', 'label'=>'DatePointOfTax', 'enabled'=>'$conf->global->INVOICE_POINTOFTAX_DATE', 'visible'=>-1, 'position'=>270), 'date_pointoftax' =>array('type'=>'date', 'label'=>'DatePointOfTax', 'enabled'=>'$conf->global->INVOICE_POINTOFTAX_DATE', 'visible'=>-1, 'position'=>270),
@ -813,12 +813,12 @@ class Facture extends CommonInvoice
$vatrate = $line->tva_tx; $vatrate = $line->tva_tx;
if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) $vatrate .= ' ('.$line->vat_src_code.')'; if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) $vatrate .= ' ('.$line->vat_src_code.')';
if (!empty($conf->global->MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION)) { if(!empty($conf->global->MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION)) {
$originid = $line->origin_id; $originid=$line->origin_id;
$origintype = $line->origin; $origintype=$line->origin;
} else { } else {
$originid = $line->id; $originid=$line->id;
$origintype = $this->element; $origintype=$this->element;
} }
$result = $this->addline( $result = $this->addline(
@ -3733,44 +3733,44 @@ class Facture extends CommonInvoice
} }
if (!empty($addon)) { if (!empty($addon)) {
dol_syslog("Call getNextNumRef with ".$addonConstName." = ".$conf->global->FACTURE_ADDON.", thirdparty=".$soc->nom.", type=".$soc->typent_code, LOG_DEBUG); dol_syslog("Call getNextNumRef with " . $addonConstName . " = " . $conf->global->FACTURE_ADDON . ", thirdparty=" . $soc->nom . ", type=" . $soc->typent_code, LOG_DEBUG);
$mybool = false; $mybool = false;
$file = $addon.'.php'; $file = $addon . '.php';
$classname = $addon; $classname = $addon;
// Include file with class // Include file with class
$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
foreach ($dirmodels as $reldir) { foreach ($dirmodels as $reldir) {
$dir = dol_buildpath($reldir.'core/modules/'.$moduleName.'/'); $dir = dol_buildpath($reldir . 'core/modules/' . $moduleName . '/');
// Load file with numbering class (if found) // Load file with numbering class (if found)
if (is_file($dir.$file) && is_readable($dir.$file)) { if (is_file($dir . $file) && is_readable($dir . $file)) {
$mybool |= include_once $dir.$file; $mybool |= include_once $dir . $file;
} }
} }
// For compatibility // For compatibility
if (!$mybool) { if (!$mybool) {
$file = $addon.'/'.$addon.'.modules.php'; $file = $addon . '/' . $addon . '.modules.php';
$classname = 'mod_'.$moduleName.'_'.$addon; $classname = 'mod_' . $moduleName . '_' . $addon;
$classname = preg_replace('/\-.*$/', '', $classname); $classname = preg_replace('/\-.*$/', '', $classname);
// Include file with class // Include file with class
foreach ($conf->file->dol_document_root as $dirroot) { foreach ($conf->file->dol_document_root as $dirroot) {
$dir = $dirroot.'/core/modules/'.$moduleName.'/'; $dir = $dirroot . '/core/modules/' . $moduleName . '/';
// Load file with numbering class (if found) // Load file with numbering class (if found)
if (is_file($dir.$file) && is_readable($dir.$file)) { if (is_file($dir . $file) && is_readable($dir . $file)) {
$mybool |= include_once $dir.$file; $mybool |= include_once $dir . $file;
} }
} }
} }
if (!$mybool) { if (!$mybool) {
dol_print_error('', 'Failed to include file '.$file); dol_print_error('', 'Failed to include file ' . $file);
return ''; return '';
} }
@ -3789,7 +3789,7 @@ class Facture extends CommonInvoice
return $numref; return $numref;
} else { } else {
$langs->load('errors'); $langs->load('errors');
print $langs->trans('Error').' '.$langs->trans('ErrorModuleSetupNotComplete', $langs->transnoentitiesnoconv($moduleSourceName)); print $langs->trans('Error') . ' ' . $langs->trans('ErrorModuleSetupNotComplete', $langs->transnoentitiesnoconv($moduleSourceName));
return ''; return '';
} }
} }
@ -4742,6 +4742,43 @@ class Facture extends CommonInvoice
return $hasDelay; return $hasDelay;
} }
/**
* Currently used for documents generation : to know if retained warranty need to be displayed
* @return bool
*/
public function displayRetainedWarranty()
{
global $conf;
// TODO : add a flag on invoices to store this conf : INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION
// note : we dont need to test INVOICE_USE_RETAINED_WARRANTY because if $this->retained_warranty is not empty it's because it was set when this conf was active
$displayWarranty = false;
if(!empty($this->retained_warranty)) {
$displayWarranty = true;
if ($this->type == Facture::TYPE_SITUATION && !empty($conf->global->INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION)) {
// Check if this situation invoice is 100% for real
$displayWarranty = false;
if (!empty($this->situation_final)) {
$displayWarranty = true;
} elseif (!empty($this->lines) && $this->status == Facture::STATUS_DRAFT) {
// $object->situation_final need validation to be done so this test is need for draft
$displayWarranty = true;
foreach ($this->lines as $i => $line) {
if ($line->product_type < 2 && $line->situation_percent < 100) {
$displayWarranty = false;
break;
}
}
}
}
}
return $displayWarranty;
}
/** /**
* @param int $rounding Minimum number of decimal to show. If 0, no change, if -1, we use min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT) * @param int $rounding Minimum number of decimal to show. If 0, no change, if -1, we use min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT)
@ -4757,7 +4794,7 @@ class Facture extends CommonInvoice
$retainedWarrantyAmount = 0; $retainedWarrantyAmount = 0;
// Billed - retained warranty // Billed - retained warranty
if ($this->type == Facture::TYPE_SITUATION) if($this->type == Facture::TYPE_SITUATION && !empty($conf->global->INVOICE_RETAINED_WARRANTY_LIMITED_TO_FINAL_SITUATION))
{ {
$displayWarranty = true; $displayWarranty = true;
// Check if this situation invoice is 100% for real // Check if this situation invoice is 100% for real
@ -4795,7 +4832,10 @@ class Facture extends CommonInvoice
if ($rounding < 0) { if ($rounding < 0) {
$rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT);
return round($retainedWarrantyAmount, 2); }
if($rounding>0){
return round($retainedWarrantyAmount, $rounding);
} }
return $retainedWarrantyAmount; return $retainedWarrantyAmount;

View File

@ -208,7 +208,7 @@ $arrayfields = array(
'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000), 'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
); );
if ($conf->global->INVOICE_USE_SITUATION && $conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY) if ($conf->global->INVOICE_USE_SITUATION && $conf->global->INVOICE_USE_RETAINED_WARRANTY)
{ {
$arrayfields['f.retained_warranty'] = array('label'=>$langs->trans("RetainedWarranty"), 'checked'=>0, 'position'=>86); $arrayfields['f.retained_warranty'] = array('label'=>$langs->trans("RetainedWarranty"), 'checked'=>0, 'position'=>86);
} }
@ -1137,7 +1137,7 @@ if ($resql)
$facturestatic->note_public = $obj->note_public; $facturestatic->note_public = $obj->note_public;
$facturestatic->note_private = $obj->note_private; $facturestatic->note_private = $obj->note_private;
if ($conf->global->INVOICE_USE_SITUATION && $conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY) if ($conf->global->INVOICE_USE_SITUATION && $conf->global->INVOICE_USE_RETAINED_WARRANTY)
{ {
$facturestatic->retained_warranty = $obj->retained_warranty; $facturestatic->retained_warranty = $obj->retained_warranty;
$facturestatic->retained_warranty_date_limit = $obj->retained_warranty_date_limit; $facturestatic->retained_warranty_date_limit = $obj->retained_warranty_date_limit;

View File

@ -1393,26 +1393,12 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
// Retained warranty // Retained warranty
if (!empty($object->situation_final) && ($object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty)))) if ($object->displayRetainedWarranty())
{ {
$displayWarranty = false;
// Check if this situation invoice is 100% for real
if (!empty($object->lines)) {
$displayWarranty = true;
foreach ($object->lines as $i => $line) {
if ($line->product_type < 2 && $line->situation_percent < 100) {
$displayWarranty = false;
break;
}
}
}
if ($displayWarranty) {
$pdf->SetTextColor(40, 40, 40); $pdf->SetTextColor(40, 40, 40);
$pdf->SetFillColor(255, 255, 255); $pdf->SetFillColor(255, 255, 255);
$retainedWarranty = $object->total_ttc * $object->retained_warranty / 100; $retainedWarranty = $object->getRetainedWarrantyAmount();
$billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty; $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
// Billed - retained warranty // Billed - retained warranty
@ -1433,7 +1419,7 @@ class pdf_crabe extends ModelePDFFactures
$pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
}
} }
} }
} }

View File

@ -776,9 +776,9 @@ class pdf_sponge extends ModelePDFFactures
$parameters = array( $parameters = array(
'object' => $object, 'object' => $object,
'i' => $i, 'i' => $i,
'pdf' => &$pdf, 'pdf' =>& $pdf,
'curY' => &$curY, 'curY' =>& $curY,
'nexY' => &$nexY, 'nexY' =>& $nexY,
'outputlangs' => $outputlangs, 'outputlangs' => $outputlangs,
'hidedetails' => $hidedetails 'hidedetails' => $hidedetails
); );
@ -1685,51 +1685,21 @@ class pdf_sponge extends ModelePDFFactures
$pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1);
/*if($object->type == Facture::TYPE_SITUATION)
{
// reste à payer total
$index++;
$pdf->SetFont('','', $default_font_size - 1);
$pdf->SetFillColor(255,255,255);
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities('SituationTotalRayToRest'), 0, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($total_a_payer_ttc-$deja_regle, 0, $outputlangs), 0, 'R', 1);
}*/
// Retained warranty // Retained warranty
if (!empty($object->situation_final) && ($object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty)))) if ($object->displayRetainedWarranty())
{ {
$displayWarranty = false;
// Check if this situation invoice is 100% for real
if (!empty($object->situation_final)) {
$displayWarranty = true;
}
elseif (!empty($object->lines) && $object->status == Facture::STATUS_DRAFT) {
// $object->situation_final need validation to be done so this test is need for draft
$displayWarranty = true;
foreach ($object->lines as $i => $line) {
if ($line->product_type < 2 && $line->situation_percent < 100) {
$displayWarranty = false;
break;
}
}
}
if ($displayWarranty) {
$pdf->SetTextColor(40, 40, 40); $pdf->SetTextColor(40, 40, 40);
$pdf->SetFillColor(255, 255, 255); $pdf->SetFillColor(255, 255, 255);
$retainedWarranty = $total_a_payer_ttc * $object->retained_warranty / 100; $retainedWarranty = $object->getRetainedWarrantyAmount();
$billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty; $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
// Billed - retained warranty // Billed - retained warranty
$index++; $index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("PDFEVOLToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')), $useborder, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
$pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1); $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
@ -1738,8 +1708,8 @@ class pdf_sponge extends ModelePDFFactures
$index++; $index++;
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
$retainedWarrantyToPayOn = $outputlangs->transnoentities("PDFEVOLRetainedWarranty").' ('.$object->retained_warranty.'%)'; $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty").' ('.$object->retained_warranty.'%)';
$retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("PDFEVOLtoPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : ''; $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("toPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
$pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1); $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
@ -1747,7 +1717,6 @@ class pdf_sponge extends ModelePDFFactures
} }
} }
} }
}
$pdf->SetTextColor(0, 0, 0); $pdf->SetTextColor(0, 0, 0);

View File

@ -200,6 +200,8 @@ DELETE FROM llx_const WHERE name = __ENCRYPT('DONATION_ART885')__;
ALTER TABLE llx_extrafields MODIFY COLUMN printable integer DEFAULT 0; ALTER TABLE llx_extrafields MODIFY COLUMN printable integer DEFAULT 0;
ALTER TABLE llx_extrafields ADD COLUMN printable integer DEFAULT 0; ALTER TABLE llx_extrafields ADD COLUMN printable integer DEFAULT 0;
UPDATE llx_const SET name = 'INVOICE_USE_RETAINED_WARRANTY' WHERE name = 'INVOICE_USE_SITUATION_RETAINED_WARRANTY';
ALTER TABLE llx_accounting_account DROP COLUMN pcg_subtype; ALTER TABLE llx_accounting_account DROP COLUMN pcg_subtype;
ALTER TABLE llx_product ADD COLUMN accountancy_code_buy_intra varchar(32) AFTER accountancy_code_buy; ALTER TABLE llx_product ADD COLUMN accountancy_code_buy_intra varchar(32) AFTER accountancy_code_buy;

View File

@ -219,7 +219,10 @@ ShowInvoiceSituation=Show situation invoice
UseSituationInvoices=Allow situation invoice UseSituationInvoices=Allow situation invoice
UseSituationInvoicesCreditNote=Allow situation invoice credit note UseSituationInvoicesCreditNote=Allow situation invoice credit note
Retainedwarranty=Retained warranty Retainedwarranty=Retained warranty
AllowedInvoiceForRetainedWarranty=Retained warranty usable on the following types of invoices
RetainedwarrantyDefaultPercent=Retained warranty default percent RetainedwarrantyDefaultPercent=Retained warranty default percent
RetainedwarrantyOnlyForSituation=Make "retained warranty" available only for situation invoices
RetainedwarrantyOnlyForSituationFinal=On situation invoices the global "retained warranty" deduction is applied only on the final situation
ToPayOn=To pay on %s ToPayOn=To pay on %s
toPayOn=to pay on %s toPayOn=to pay on %s
RetainedWarranty=Retained Warranty RetainedWarranty=Retained Warranty