diff --git a/htdocs/admin/facture_situation.php b/htdocs/admin/facture_situation.php
index 408b762358e..aced29bc125 100644
--- a/htdocs/admin/facture_situation.php
+++ b/htdocs/admin/facture_situation.php
@@ -96,7 +96,9 @@ print "\n";
_printOnOff('INVOICE_USE_SITUATION', $langs->trans('UseSituationInvoices'));
_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'));
+_printOnOff('USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION',$langs->trans('RetainedwarrantyOnlyForSituation'));
+_printOnOff('USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL',$langs->trans('RetainedwarrantyOnlyForSituationFinal'));
$metas = array(
'type' => 'number',
diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php
index 5038079085b..593e33734c5 100644
--- a/htdocs/compta/facture/card.php
+++ b/htdocs/compta/facture/card.php
@@ -136,7 +136,12 @@ if ($user->socid) $socid = $user->socid;
$isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0);
$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft);
-
+// retained warranty invoice available type
+if(empty($conf->global->USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION)) {
+ $RetainedWarrantyInvoiceAvailableType = array( Facture::TYPE_SITUATION, Facture::TYPE_STANDARD);
+} else {
+ $RetainedWarrantyInvoiceAvailableType = array( Facture::TYPE_SITUATION );
+}
/*
* Actions
@@ -1308,18 +1313,17 @@ if (empty($reshook))
$object->situation_counter = 1;
$object->situation_final = 0;
$object->situation_cycle_ref = $object->newCycle();
-
-
- $object->retained_warranty = GETPOST('retained_warranty', 'int');
- $object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int');
-
- $retained_warranty_date_limit = GETPOST('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 = !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 = GETPOST('retained_warranty', 'int');
+ $object->retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int');
+
+ $retained_warranty_date_limit = GETPOST('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 = !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();
// If creation from another object of another module (Example: origin=propal, originid=1)
@@ -1714,6 +1718,23 @@ if (empty($reshook))
$object->origin = $origin;
$object->origin_id = $originid;
+ // retained warranty
+ if(!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY))
+ {
+ $retained_warranty = GETPOST('retained_warranty');
+ 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_date_limit = !empty($object->retained_warranty_date_limit) ? $object->retained_warranty_date_limit : $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement);
+ }
+
foreach ($object->lines as $i => &$line)
{
$line->origin = $object->origin;
@@ -3309,40 +3330,41 @@ if ($action == 'create')
$form->select_conditions_paiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id');
print '';
- if (!empty($conf->global->INVOICE_USE_SITUATION))
- {
- if ($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY) {
- $rwStyle = 'display:none;';
- if (GETPOST('type', 'int') == Facture::TYPE_SITUATION) {
- $rwStyle = '';
- }
- $retained_warranty = GETPOST('retained_warranty', 'int');
- $retained_warranty = !empty($retained_warranty) ? $retained_warranty : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT;
- print '
';
print '| ';
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index cb2bf087652..30f3867a843 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -297,9 +297,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_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),
- 'retained_warranty' =>array('type'=>'double', 'label'=>'Retained warranty', 'enabled'=>'$conf->global->INVOICE_USE_SITUATION_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_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' =>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_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_RETAINED_WARRANTY', 'visible'=>-1, 'position'=>255),
'fk_incoterms' =>array('type'=>'integer', 'label'=>'IncotermsCode', 'enabled'=>'$conf->incoterm->enabled', 'visible'=>-1, 'position'=>260),
'location_incoterms' =>array('type'=>'varchar(255)', 'label'=>'IncotermsLocation', '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),
@@ -4606,6 +4606,42 @@ class Facture extends CommonInvoice
return $hasDelay;
}
+ /**
+ * Currently used for documents generation : to know if retained warranty need to be displayed
+ * @return bool
+ */
+ function displayRetainedWarranty(){
+ global $conf;
+
+ // TODO : add a flag on invoices to store this conf : USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL
+
+ // note : we dont need to test USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION 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->USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL)) {
+ // 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)
@@ -4621,7 +4657,7 @@ class Facture extends CommonInvoice
$retainedWarrantyAmount = 0;
// Billed - retained warranty
- if ($this->type == Facture::TYPE_SITUATION)
+ if($this->type == Facture::TYPE_SITUATION && !empty($conf->global->USE_RETAINED_WARRANTY_ONLY_FOR_SITUATION_FINAL))
{
$displayWarranty = true;
// Check if this situation invoice is 100% for real
@@ -4659,7 +4695,10 @@ class Facture extends CommonInvoice
if ($rounding < 0){
$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;
diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index b32d82a08cb..dc685c0a893 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -188,7 +188,7 @@ $arrayfields = array(
'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);
}
@@ -1002,7 +1002,7 @@ if ($resql)
$facturestatic->date_lim_reglement = $db->jdate($obj->datelimite);
$facturestatic->note_public = $obj->note_public;
$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_date_limit = $obj->retained_warranty_date_limit;
diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php
index a9d1230fdec..5ab59275666 100644
--- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php
+++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php
@@ -1663,51 +1663,32 @@ class pdf_sponge extends ModelePDFFactures
// Retained warranty
- if (!empty($object->situation_final) && ($object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty))))
+ if ($object->displayRetainedWarranty())
{
- $displayWarranty = false;
+ $pdf->SetTextColor(40, 40, 40);
+ $pdf->SetFillColor(255, 255, 255);
- // 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;
- }
- }
- }
+ $retainedWarranty = $object->getRetainedWarrantyAmount();
+ $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
- if ($displayWarranty) {
- $pdf->SetTextColor(40, 40, 40);
- $pdf->SetFillColor(255, 255, 255);
+ // Billed - retained warranty
+ $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);
- $retainedWarranty = $total_a_payer_ttc * $object->retained_warranty / 100;
- $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty;
+ $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
+ $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
- // Billed - retained warranty
- $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);
+ // retained warranty
+ $index++;
+ $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
- $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
- $pdf->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty), $useborder, 'R', 1);
+ $retainedWarrantyToPayOn = $outputlangs->transnoentities("PDFEVOLRetainedWarranty").' ('.$object->retained_warranty.'%)';
+ $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("PDFEVOLtoPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
- // retained warranty
- $index++;
- $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
-
- $retainedWarrantyToPayOn = $outputlangs->transnoentities("PDFEVOLRetainedWarranty").' ('.$object->retained_warranty.'%)';
- $retainedWarrantyToPayOn .= !empty($object->retained_warranty_date_limit) ? ' '.$outputlangs->transnoentities("PDFEVOLtoPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')) : '';
-
- $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
- $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
- $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
- }
+ $pdf->MultiCell($col2x - $col1x, $tab2_hl, $retainedWarrantyToPayOn, $useborder, 'L', 1);
+ $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
+ $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty), $useborder, 'R', 1);
}
}
}
diff --git a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql
index 447630e7eb2..bf641871be9 100644
--- a/htdocs/install/mysql/migration/11.0.0-12.0.0.sql
+++ b/htdocs/install/mysql/migration/11.0.0-12.0.0.sql
@@ -163,4 +163,6 @@ INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, desc
INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, description) VALUES('CANCELED', '50', 'Canceled', 1, 0, NULL);
INSERT INTO llx_c_ticket_resolution (code, pos, label, active, use_default, description) VALUES('OTHER', '90', 'Other', 1, 0, NULL);
-DELETE FROM llx_const WHERE name = __ENCRYPT('DONATION_ART885')__;
\ No newline at end of file
+DELETE FROM llx_const WHERE name = __ENCRYPT('DONATION_ART885')__;
+
+UPDATE llx_const SET name = 'INVOICE_USE_RETAINED_WARRANTY' WHERE name = 'INVOICE_USE_SITUATION_RETAINED_WARRANTY'
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index 6d7c61784f7..fe33c173cea 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -220,6 +220,8 @@ UseSituationInvoices=Allow situation invoice
UseSituationInvoicesCreditNote=Allow situation invoice credit note
Retainedwarranty=Retained warranty
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
RetainedWarranty=Retained Warranty
|
|