From 3036c94198d039e1ebc76c43928f3619d670172f Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Tue, 7 Aug 2018 15:18:42 +0200 Subject: [PATCH 01/23] Add new situation retained warranty field --- htdocs/admin/facture_situation.php | 181 ++++++++++++++++++ htdocs/compta/facture/class/facture.class.php | 18 +- htdocs/core/lib/invoice.lib.php | 9 +- .../install/mysql/migration/8.0.0-9.0.0.sql | 5 + htdocs/install/mysql/tables/llx_facture.sql | 2 + htdocs/langs/en_US/bills.lang | 4 + 6 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 htdocs/admin/facture_situation.php diff --git a/htdocs/admin/facture_situation.php b/htdocs/admin/facture_situation.php new file mode 100644 index 00000000000..cfee53da5f5 --- /dev/null +++ b/htdocs/admin/facture_situation.php @@ -0,0 +1,181 @@ + + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005 Eric Seigne + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2008 Raphael Bertrand (Resultic) + * Copyright (C) 2012-2013 Juanjo Menent + * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/admin/facture.php + * \ingroup facture + * \brief Page to setup invoice module + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array('admin', 'errors', 'other', 'bills')); + +if (! $user->admin) accessforbidden(); + +$action = GETPOST('action','alpha'); +$value = GETPOST('value','alpha'); +$label = GETPOST('label','alpha'); +$scandir = GETPOST('scan_dir','alpha'); +$type='invoice'; + + +/* + * Actions + */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php'; + + + +/* + * View + */ + +$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']); + +llxHeader("",$langs->trans("BillsSetup"),'EN:Invoice_Configuration|FR:Configuration_module_facture|ES:ConfiguracionFactura'); + +$form=new Form($db); + + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("BillsSetup"),$linkback,'title_setup'); + +$head = invoice_admin_prepare_head(); +dol_fiche_head($head, 'situation', $langs->trans("InvoiceSituation"), -1, 'invoice'); + +/* + * Numbering module + */ + +print load_fiche_titre($langs->trans("InvoiceSituation"),'',''); +$var=0; +print ''; + + +_print_on_off('INVOICE_USE_SITUATION',$langs->trans('UseSituationInvoices')); +_print_on_off('INVOICE_USE_SITUATION_CREDIT_NOTE',$langs->trans('UseSituationInvoicesCreditNote')); +_print_on_off('INVOICE_USE_SITUATION_RETAINED_WARANTY',$langs->trans('Retainedwarranty')); + +$metas = array( + 'type' => 'number', + 'step' => '0.01', + 'min' => 0, + 'max' => 100 +); +_print_input_form_part('INVOICE_SITUATION_DEFAULT_RETAINED_WARANTY_PERCENT',$langs->trans('RetainedwarrantyDefaultPercent'),'',$metas); + + + + +dol_fiche_end(); + +// End of page +llxFooter(); +$db->close(); + +function _print_on_off($confkey, $title = false, $desc ='') +{ + global $var, $bc, $langs, $conf; + $var=!$var; + + print ''; + print ''; + print ''; + print ''; +} + + +function _print_input_form_part($confkey, $title = false, $desc ='', $metas = array(), $type='input', $help = false) +{ + global $var, $bc, $langs, $conf, $db; + $var=!$var; + + $form=new Form($db); + + $defaultMetas = array( + 'name' => $confkey + ); + + if($type!='textarea'){ + $defaultMetas['type'] = 'text'; + $defaultMetas['value'] = $conf->global->{$confkey}; + } + + + $metas = array_merge ($defaultMetas, $metas); + $metascompil = ''; + foreach ($metas as $key => $values) + { + $metascompil .= ' '.$key.'="'.$values.'" '; + } + + print ''; + print ''; + print ''; + print ''; +} diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 4edce36b82f..418339a0383 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -160,6 +160,9 @@ class Facture extends CommonInvoice public $tab_next_situation_invoice=array(); public $oldcopy; + + + public $retained_waranty; /** * Standard invoice @@ -339,6 +342,8 @@ class Facture extends CommonInvoice $this->note_public=trim($this->note_public); $this->note_private=trim($this->note_private); $this->note_private=dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref)); + + $this->retained_waranty = floatval($this->retained_waranty); $this->array_options=$_facrec->array_options; @@ -426,6 +431,7 @@ class Facture extends CommonInvoice $sql.= ", fk_multicurrency"; $sql.= ", multicurrency_code"; $sql.= ", multicurrency_tx"; + $sql.= ", retained_waranty"; $sql.= ")"; $sql.= " VALUES ("; $sql.= "'(PROV)'"; @@ -458,6 +464,8 @@ class Facture extends CommonInvoice $sql.= ", ".(int) $this->fk_multicurrency; $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; $sql.= ", ".(double) $this->multicurrency_tx; + $sql.= ", ".(empty($this->retained_waranty)?"0":$this->db->escape($this->retained_waranty)); + $sql.=")"; $resql=$this->db->query($sql); @@ -1276,6 +1284,7 @@ class Facture extends CommonInvoice $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc'; $sql.= ', f.fk_incoterms, f.location_incoterms'; $sql.= ", i.libelle as libelle_incoterms"; + $sql.= ", f.retained_waranty as retained_waranty"; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; @@ -1343,9 +1352,9 @@ class Facture extends CommonInvoice $this->situation_cycle_ref = $obj->situation_cycle_ref; $this->situation_counter = $obj->situation_counter; $this->situation_final = $obj->situation_final; + $this->retained_waranty = $obj->retained_waranty; $this->extraparams = (array) json_decode($obj->extraparams, true); - - //Incoterms + // Incoterms $this->fk_incoterms = $obj->fk_incoterms; $this->location_incoterms = $obj->location_incoterms; $this->libelle_incoterms = $obj->libelle_incoterms; @@ -1569,7 +1578,9 @@ class Facture extends CommonInvoice if (isset($this->note_public)) $this->note_public=trim($this->note_public); if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf); if (isset($this->import_key)) $this->import_key=trim($this->import_key); - + if (isset($this->retained_waranty)) $this->retained_waranty = floatval($this->retained_waranty); + + // Check parameters // Put here code to add control on parameters values @@ -1610,6 +1621,7 @@ class Facture extends CommonInvoice $sql.= " situation_cycle_ref=".(empty($this->situation_cycle_ref)?"null":$this->db->escape($this->situation_cycle_ref)).","; $sql.= " situation_counter=".(empty($this->situation_counter)?"null":$this->db->escape($this->situation_counter)).","; $sql.= " situation_final=".(empty($this->situation_counter)?"0":$this->db->escape($this->situation_counter)); + $sql.= " retained_waranty=".(empty($this->retained_waranty)?"0":$this->db->escape($this->retained_waranty)); $sql.= " WHERE rowid=".$this->id; $this->db->begin(); diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php index 4e7fa860529..c4ecbacf6e7 100644 --- a/htdocs/core/lib/invoice.lib.php +++ b/htdocs/core/lib/invoice.lib.php @@ -136,7 +136,14 @@ function invoice_admin_prepare_head() $head[$h][1] = $langs->trans("Payments"); $head[$h][2] = 'payment'; $h++; - + + if($conf->global->INVOICE_USE_SITUATION){ + $head[$h][0] = DOL_URL_ROOT.'/admin/facture_situation.php'; + $head[$h][1] = $langs->trans("InvoiceSituation"); + $head[$h][2] = 'situation'; + $h++; + } + // Show more tabs from modules // Entries must be declared in modules descriptor with line // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab diff --git a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql index be072b8bacb..2a429fc7765 100644 --- a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql +++ b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql @@ -50,3 +50,8 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('EXPENSE_DELETE','Expense report deleted','Executed when an expense report is deleted','expensereport',204); ALTER TABLE llx_payment_salary ADD COLUMN fk_projet integer DEFAULT NULL after amount; + +ALTER TABLE llx_facture ADD COLUMN retained_waranty real DEFAULT NULL after situation_final; + + + diff --git a/htdocs/install/mysql/tables/llx_facture.sql b/htdocs/install/mysql/tables/llx_facture.sql index c0783a7bbd8..decd48f46bc 100644 --- a/htdocs/install/mysql/tables/llx_facture.sql +++ b/htdocs/install/mysql/tables/llx_facture.sql @@ -86,6 +86,8 @@ create table llx_facture situation_counter smallint, -- situation counter situation_final smallint, -- is the situation final ? + retained_waranty real DEFAULT NULL, -- % of retained warranty + import_key varchar(14), extraparams varchar(255), -- for other parameters with json format diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 54194358748..94f0786343e 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -211,6 +211,10 @@ ShowInvoiceReplace=Show replacing invoice ShowInvoiceAvoir=Show credit note ShowInvoiceDeposit=Show down payment invoice ShowInvoiceSituation=Show situation invoice +UseSituationInvoices=Allow situation invoice +UseSituationInvoicesCreditNote=Allow situation invoice credit note +Retainedwarranty=Retained warranty +RetainedwarrantyDefaultPercent=Retained warranty default percent ShowPayment=Show payment AlreadyPaid=Already paid AlreadyPaidBack=Already paid back From 06be98c63855797f67508dec6177795e2cf5b177 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Wed, 8 Aug 2018 17:36:39 +0200 Subject: [PATCH 02/23] add date field --- htdocs/admin/facture_situation.php | 4 +- htdocs/compta/facture/card.php | 96 ++++++++++++++++ htdocs/compta/facture/class/facture.class.php | 104 ++++++++++++++++-- .../install/mysql/migration/8.0.0-9.0.0.sql | 4 +- htdocs/install/mysql/tables/llx_facture.sql | 3 +- htdocs/langs/en_US/bills.lang | 2 + 6 files changed, 199 insertions(+), 14 deletions(-) diff --git a/htdocs/admin/facture_situation.php b/htdocs/admin/facture_situation.php index cfee53da5f5..ad6f858df20 100644 --- a/htdocs/admin/facture_situation.php +++ b/htdocs/admin/facture_situation.php @@ -81,7 +81,7 @@ print '
'.($title?$title:$langs->trans($confkey)); + if(!empty($desc)) + { + print '
'.$langs->trans($desc).''; + } + print '
 '; + print '
'; + print ''; + print ''; + print ajax_constantonoff($confkey); + print '
'; + print '
'; + + if(!empty($help)){ + print $form->textwithtooltip( ($title?$title:$langs->trans($confkey)) , $langs->trans($help),2,1,img_help(1,'')); + } + else { + print $title?$title:$langs->trans($confkey); + } + + if(!empty($desc)) + { + print '
'.$langs->trans($desc).''; + } + + print '
 '; + print '
'; + print ''; + print ''; + if($type=='textarea'){ + print ''; + } + else { + print ''; + } + + print ''; + print '
'; + print '
'; _print_on_off('INVOICE_USE_SITUATION',$langs->trans('UseSituationInvoices')); _print_on_off('INVOICE_USE_SITUATION_CREDIT_NOTE',$langs->trans('UseSituationInvoicesCreditNote')); -_print_on_off('INVOICE_USE_SITUATION_RETAINED_WARANTY',$langs->trans('Retainedwarranty')); +_print_on_off('INVOICE_USE_SITUATION_RETAINED_WARRANTY',$langs->trans('Retainedwarranty')); $metas = array( 'type' => 'number', @@ -89,7 +89,7 @@ $metas = array( 'min' => 0, 'max' => 100 ); -_print_input_form_part('INVOICE_SITUATION_DEFAULT_RETAINED_WARANTY_PERCENT',$langs->trans('RetainedwarrantyDefaultPercent'),'',$metas); +_print_input_form_part('INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT',$langs->trans('RetainedwarrantyDefaultPercent'),'',$metas); diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index e411f8c5b1b..6415ef4cdcd 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -288,6 +288,23 @@ if (empty($reshook)) if ($result < 0) dol_print_error($db, $object->error); } + + else if ($action == 'setretainedwarranty' && $user->rights->facture->creer) + { + $object->fetch($id); + $result = $object->setRetainedWarranty(GETPOST('retained_warranty', 'float')); + if ($result < 0) + dol_print_error($db, $object->error); + } + + else if ($action == 'setretainedwarrantydatelimit' && $user->rights->facture->creer) + { + $object->fetch($id); + $result = $object->setRetainedWarrantyDateLimit(GETPOST('retained_warranty_date_limit', 'float')); + if ($result < 0) + dol_print_error($db, $object->error); + } + // Multicurrency Code else if ($action == 'setmulticurrencycode' && $user->rights->facture->creer) { @@ -1152,6 +1169,7 @@ if (empty($reshook)) $object->situation_counter = 1; $object->situation_final = 0; $object->situation_cycle_ref = $object->newCycle(); + $object->retained_warranty = !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)?$conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY:0; } $object->fetch_thirdparty(); @@ -3919,6 +3937,70 @@ else if ($id > 0 || ! empty($ref)) print ''; } + + if($object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)) ) + { + // Retained Warranty + print ''; + + + // Retained Warranty payment date limit + print ''; + } + + // Other attributes $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; @@ -4360,6 +4442,20 @@ else if ($id > 0 || ! empty($ref)) // Billed print ''; + if(!empty($object->retained_warranty)){ + // Billed - retained warranty + $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100; + $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty ; + print ''; + + // retained warranty + print ''; + + } + // Remainder to pay print ''; print ''; print ''; - print ''; } function _print_input_form_part($confkey, $title = false, $desc ='', $metas = array(), $type='input', $help = false) { - global $var, $bc, $langs, $conf, $db; + global $var, $bc, $langs, $conf, $db, $inputCount; $var=!$var; - + $inputCount = empty($inputCount)?1:($inputCount+1); $form=new Form($db); $defaultMetas = array( - 'name' => $confkey + 'name' => 'value'.$inputCount ); if($type!='textarea'){ @@ -165,17 +190,14 @@ function _print_input_form_part($confkey, $title = false, $desc ='', $metas = ar print ''; print ''; print ''; } diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 6415ef4cdcd..c9e14304954 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -289,6 +289,21 @@ if (empty($reshook)) dol_print_error($db, $object->error); } + else if ($action == 'setretainedwarrantyconditions' && $user->rights->facture->creer) + { + $object->fetch($id); + $object->retained_warranty_fk_cond_reglement = 0; // To clean property + $result = $object->setRetainedWarrantyPaymentTerms(GETPOST('retained_warranty_fk_cond_reglement', 'int')); + if ($result < 0) dol_print_error($db, $object->error); + + $old_rw_date_lim_reglement = $object->retained_warranty_date_limit; + $new_rw_date_lim_reglement = $object->calculate_date_lim_reglement($object->retained_warranty_fk_cond_reglement); + if ($new_rw_date_lim_reglement > $old_rw_date_lim_reglement) $object->retained_warranty_date_limit = $new_rw_date_lim_reglement; + if ($object->retained_warranty_date_limit < $object->date) $object->retained_warranty_date_limit = $object->date; + $result = $object->update($user); + if ($result < 0) dol_print_error($db, $object->error); + } + else if ($action == 'setretainedwarranty' && $user->rights->facture->creer) { $object->fetch($id); @@ -877,7 +892,7 @@ if (empty($reshook)) $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); - + // Proprietes particulieres a facture de remplacement $object->fk_facture_source = $_POST['fac_replacement']; $object->type = Facture::TYPE_REPLACEMENT; @@ -1163,13 +1178,25 @@ if (empty($reshook)) $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); + + + if (GETPOST('type') == Facture::TYPE_SITUATION) { $object->situation_counter = 1; $object->situation_final = 0; $object->situation_cycle_ref = $object->newCycle(); - $object->retained_warranty = !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)?$conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY:0; + + + $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(); @@ -1583,7 +1610,7 @@ if (empty($reshook)) $object->mode_reglement_id = GETPOST('mode_reglement_id','int'); $object->remise_absolue = GETPOST('remise_absolue','int'); $object->remise_percent = GETPOST('remise_percent','int'); - + // Proprietes particulieres a facture de remplacement $object->situation_counter = $object->situation_counter + 1; @@ -3082,6 +3109,44 @@ if ($action == 'create') 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 ''; + } + } // Payment mode print ''; } - - if($object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)) ) + $displayWarranty = false; + if( !empty($object->situation_final) + && ( $object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)) ) + ) { + // 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; + } + } + } + + + // Retained Warranty - print '
'; + print ''; + if ($action != 'editretainedwarranty' && $user->rights->facture->creer){ + print ''; + } + + print '
'; + print $langs->trans('RetainedWarranty'); + print 'id . '">' . img_edit($langs->trans('setretainedwarranty'), 1) . '
'; + print '
'; + if ($action == 'editretainedwarranty') + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print '
'; + } + else + { + print price($object->retained_warranty).'%'; + } + print '
'; + print ''; + if ($action != 'editretainedwarrantydatelimit' && $user->rights->facture->creer){ + print ''; + } + + print '
'; + print $langs->trans('RetainedWarrantyDateLimit'); + print 'id . '">' . img_edit($langs->trans('setretainedwarrantyDateLimit'), 1) . '
'; + print '
'; + $defaultDate = !empty($object->retained_warranty_date_limit)?$object->retained_warranty_date_limit:strtotime('-1 years', $object->date_lim_reglement); + if($object->date > $defaultDate){ + $defaultDate = $object->date; + } + + if ($action == 'editretainedwarrantydatelimit') + { + //date('Y-m-d',$object->date_lim_reglement) + print '
'; + print ''; + print ''; + print ''; + print ''; + print '
'; + } + else + { + print dol_print_date($defaultDate); + } + print '
' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' 
' . $langs->trans("ToPayOn", dol_print_date($object->date_lim_reglement)) . ' :' . price($billedWithRetainedWarranty) . ' 
'; + print $langs->trans("RetainedWarranty") . ' ('.$object->retained_warranty.'%)'; + print !empty($object->retained_warranty_date_limit)?' '.$langs->trans("ToPayOn", dol_print_date($object->retained_warranty_date_limit)):''; + print ' :' . price($retainedWarranty) . ' 
'; if ($resteapayeraffiche >= 0) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 418339a0383..9c387f6630a 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -162,7 +162,9 @@ class Facture extends CommonInvoice public $oldcopy; - public $retained_waranty; + public $retained_warranty; + + public $retained_warranty_date_limit; /** * Standard invoice @@ -343,7 +345,7 @@ class Facture extends CommonInvoice $this->note_private=trim($this->note_private); $this->note_private=dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref)); - $this->retained_waranty = floatval($this->retained_waranty); + $this->retained_warranty = floatval($this->retained_warranty); $this->array_options=$_facrec->array_options; @@ -431,7 +433,8 @@ class Facture extends CommonInvoice $sql.= ", fk_multicurrency"; $sql.= ", multicurrency_code"; $sql.= ", multicurrency_tx"; - $sql.= ", retained_waranty"; + $sql.= ", retained_warranty"; + $sql.= ", retained_warranty_date_limit"; $sql.= ")"; $sql.= " VALUES ("; $sql.= "'(PROV)'"; @@ -464,7 +467,8 @@ class Facture extends CommonInvoice $sql.= ", ".(int) $this->fk_multicurrency; $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; $sql.= ", ".(double) $this->multicurrency_tx; - $sql.= ", ".(empty($this->retained_waranty)?"0":$this->db->escape($this->retained_waranty)); + $sql.= ", ".(empty($this->retained_warranty)?"0":$this->db->escape($this->retained_warranty)); + $sql.= ", '".$this->db->idate($this->retained_warranty_date_limit)."'"; $sql.=")"; @@ -1284,7 +1288,7 @@ class Facture extends CommonInvoice $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc'; $sql.= ', f.fk_incoterms, f.location_incoterms'; $sql.= ", i.libelle as libelle_incoterms"; - $sql.= ", f.retained_waranty as retained_waranty"; + $sql.= ", f.retained_warranty as retained_warranty, f.retained_warranty_date_limit as retained_warranty_date_limit"; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; @@ -1352,7 +1356,9 @@ class Facture extends CommonInvoice $this->situation_cycle_ref = $obj->situation_cycle_ref; $this->situation_counter = $obj->situation_counter; $this->situation_final = $obj->situation_final; - $this->retained_waranty = $obj->retained_waranty; + $this->retained_warranty = $obj->retained_warranty; + $this->retained_warranty_date_limit = $this->db->jdate($obj->retained_warranty_date_limit); + $this->extraparams = (array) json_decode($obj->extraparams, true); // Incoterms $this->fk_incoterms = $obj->fk_incoterms; @@ -1578,7 +1584,7 @@ class Facture extends CommonInvoice if (isset($this->note_public)) $this->note_public=trim($this->note_public); if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf); if (isset($this->import_key)) $this->import_key=trim($this->import_key); - if (isset($this->retained_waranty)) $this->retained_waranty = floatval($this->retained_waranty); + if (isset($this->retained_warranty)) $this->retained_warranty = floatval($this->retained_warranty); // Check parameters @@ -1620,8 +1626,9 @@ class Facture extends CommonInvoice $sql.= " import_key=".(isset($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null").","; $sql.= " situation_cycle_ref=".(empty($this->situation_cycle_ref)?"null":$this->db->escape($this->situation_cycle_ref)).","; $sql.= " situation_counter=".(empty($this->situation_counter)?"null":$this->db->escape($this->situation_counter)).","; - $sql.= " situation_final=".(empty($this->situation_counter)?"0":$this->db->escape($this->situation_counter)); - $sql.= " retained_waranty=".(empty($this->retained_waranty)?"0":$this->db->escape($this->retained_waranty)); + $sql.= " situation_final=".(empty($this->situation_counter)?"0":$this->db->escape($this->situation_counter)).","; + $sql.= " retained_warranty=".(empty($this->retained_warranty)?"0":$this->db->escape($this->retained_warranty)).","; + $sql.= " retained_warranty_date_limit=".(strval($this->retained_warranty_date_limit)!='' ? "'".$this->db->idate($this->retained_warranty_date_limit)."'" : 'null'); $sql.= " WHERE rowid=".$this->id; $this->db->begin(); @@ -4226,6 +4233,85 @@ class Facture extends CommonInvoice return $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay); } + + + /** + * Change the retained warranty + * + * @param float $value value of retained warranty + * @return int >0 if OK, <0 if KO + */ + function setRetainedWarranty($value) + { + dol_syslog(get_class($this).'::setRetainedWarranty('.$value.')'); + if ($this->statut >= 0) + { + $fieldname = 'retained_warranty'; + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql .= ' SET '.$fieldname.' = '.floatval($value); + $sql .= ' WHERE rowid='.$this->id; + + if ($this->db->query($sql)) + { + $this->retained_warranty = floatval($value); + return 1; + } + else + { + dol_syslog(get_class($this).'::setRetainedWarranty Erreur '.$sql.' - '.$this->db->error()); + $this->error=$this->db->error(); + return -1; + } + } + else + { + dol_syslog(get_class($this).'::setRetainedWarranty, status of the object is incompatible'); + $this->error='Status of the object is incompatible '.$this->statut; + return -2; + } + } + + + /** + * Change the retained_warranty_date_limit + * + * @param timestamp $value value of retained warranty + * @return int >0 if OK, <0 if KO + */ + function setRetainedWarrantyDateLimit($timestamp,$dateYmd=false) + { + if(!$timestamp && $dateYmd){ + $timestamp = $this->db->jdate($dateYmd); + } + + + dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit('.$value.')'); + if ($this->statut >= 0) + { + $fieldname = 'retained_warranty_date_limit'; + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql .= ' SET '.$fieldname.' = '.(strval($timestamp)!='' ? '\'' .$this->db->idate($timestamp).'\'' : 'null' ); + $sql .= ' WHERE rowid='.$this->id; + + if ($this->db->query($sql)) + { + $this->retained_warranty_date_limit = $timestamp; + return 1; + } + else + { + dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit Erreur '.$sql.' - '.$this->db->error()); + $this->error=$this->db->error(); + return -1; + } + } + else + { + dol_syslog(get_class($this).'::setRetainedWarrantyDateLimit, status of the object is incompatible'); + $this->error='Status of the object is incompatible '.$this->statut; + return -2; + } + } } /** diff --git a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql index 2a429fc7765..fb7db220138 100644 --- a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql +++ b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql @@ -51,7 +51,7 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value ALTER TABLE llx_payment_salary ADD COLUMN fk_projet integer DEFAULT NULL after amount; -ALTER TABLE llx_facture ADD COLUMN retained_waranty real DEFAULT NULL after situation_final; - +ALTER TABLE llx_facture ADD COLUMN retained_warranty real DEFAULT NULL after situation_final; +ALTER TABLE llx_facture ADD COLUMN retained_warranty_date_limit date DEFAULT NULL after retained_warranty; diff --git a/htdocs/install/mysql/tables/llx_facture.sql b/htdocs/install/mysql/tables/llx_facture.sql index decd48f46bc..abdefedc944 100644 --- a/htdocs/install/mysql/tables/llx_facture.sql +++ b/htdocs/install/mysql/tables/llx_facture.sql @@ -86,7 +86,8 @@ create table llx_facture situation_counter smallint, -- situation counter situation_final smallint, -- is the situation final ? - retained_waranty real DEFAULT NULL, -- % of retained warranty + retained_warranty real DEFAULT NULL, -- % of retained warranty + retained_warranty_date_limit date DEFAULT NULL, import_key varchar(14), extraparams varchar(255), -- for other parameters with json format diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 94f0786343e..c547f385be0 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -550,3 +550,5 @@ AutoFillDateFromShort=Set start date AutoFillDateTo=Set end date for service line with next invoice date AutoFillDateToShort=Set end date MaxNumberOfGenerationReached=Max number of gen. reached +ToPayOn=To pay on %s +RetainedWarranty=Retained Warranty From d6d8f98f38f01930958654f6d720f478c60c88b5 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Fri, 10 Aug 2018 15:06:00 +0200 Subject: [PATCH 03/23] add retained warranty cond field and add forms --- htdocs/admin/facture_situation.php | 54 ++++-- htdocs/compta/facture/card.php | 169 +++++++++++++++--- htdocs/compta/facture/class/facture.class.php | 23 ++- htdocs/core/class/commonobject.class.php | 37 ++++ .../install/mysql/migration/8.0.0-9.0.0.sql | 1 + htdocs/install/mysql/tables/llx_facture.sql | 5 +- htdocs/langs/en_US/bills.lang | 7 + 7 files changed, 248 insertions(+), 48 deletions(-) diff --git a/htdocs/admin/facture_situation.php b/htdocs/admin/facture_situation.php index ad6f858df20..dc3ec771b16 100644 --- a/htdocs/admin/facture_situation.php +++ b/htdocs/admin/facture_situation.php @@ -76,6 +76,12 @@ dol_fiche_head($head, 'situation', $langs->trans("InvoiceSituation"), -1, 'invoi print load_fiche_titre($langs->trans("InvoiceSituation"),'',''); $var=0; + +print '
'; +print ''; + +_updateBtn(); + print ''; @@ -94,17 +100,40 @@ _print_input_form_part('INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_PERCENT',$la +// Conditions paiements +$inputCount = empty($inputCount)?1:($inputCount+1); +print ''; +print ''; +print ''; +print ''; + + +print '
'.$langs->trans('PaymentConditionsShortRetainedWarranty').' '; +print ''; +$form->select_conditions_paiements($conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID, 'value'.$inputCount, -1, 1); +print '
'; + +_updateBtn(); + +print '
'; + dol_fiche_end(); // End of page llxFooter(); $db->close(); +function _updateBtn(){ + global $langs; + print '
'; + print ''; + print '
'; +} + function _print_on_off($confkey, $title = false, $desc ='') { - global $var, $bc, $langs, $conf; + global $var, $bc, $langs; $var=!$var; - print '
'.($title?$title:$langs->trans($confkey)); if(!empty($desc)) @@ -113,25 +142,21 @@ function _print_on_off($confkey, $title = false, $desc ='') } print ' '; - print '
'; - print ''; - print ''; + print '
'; print ajax_constantonoff($confkey); - print ''; print '
 '; - print '
'; - print ''; - print ''; + print ''; + + print ''; if($type=='textarea'){ print ''; } else { print ''; } - - print ''; - print '
'; print '
' . $langs->trans('PaymentConditionsShort') . ''; $form->select_conditions_paiements(isset($_POST['cond_reglement_id']) ? $_POST['cond_reglement_id'] : $cond_reglement_id, 'cond_reglement_id'); print '
' . $langs->trans('RetainedWarranty') . ''; + print '%'; + + // Retained warranty payment term + print '
' . $langs->trans('PaymentConditionsShortRetainedWarranty') . ''; + $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); + $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement)? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; + $form->select_conditions_paiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement'); + print '
' . $langs->trans('PaymentMode') . ''; @@ -3937,12 +4002,27 @@ else if ($id > 0 || ! empty($ref)) print '
'; - print '
'; + print '
'; + print ''; if ($action != 'editretainedwarranty' && $user->rights->facture->creer){ @@ -3953,7 +4033,7 @@ else if ($id > 0 || ! empty($ref)) print ''; - - // Retained Warranty payment date limit - print '
'; print $langs->trans('RetainedWarranty'); print ''; if ($action == 'editretainedwarranty') { - print '
'; + print ''; print ''; print ''; print ''; @@ -3966,14 +4046,13 @@ else if ($id > 0 || ! empty($ref)) } print '
'; - print ''; + + + + + if($displayWarranty) + { + // Retained Warranty payment date limit + print ''; + } + } @@ -4442,16 +4566,17 @@ else if ($id > 0 || ! empty($ref)) // Billed print ''; - if(!empty($object->retained_warranty)){ + // Retained warranty : usualy use on construction industry + if(!empty($object->situation_final) && !empty($object->retained_warranty) && $displayWarranty){ // Billed - retained warranty $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100; $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty ; - print ''; + print ''; // retained warranty print ''; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 9c387f6630a..e108b526576 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -165,6 +165,8 @@ class Facture extends CommonInvoice public $retained_warranty; public $retained_warranty_date_limit; + + public $retained_warranty_fk_cond_reglement; /** * Standard invoice @@ -345,8 +347,8 @@ class Facture extends CommonInvoice $this->note_private=trim($this->note_private); $this->note_private=dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref)); - $this->retained_warranty = floatval($this->retained_warranty); + $this->array_options=$_facrec->array_options; //if (! $this->remise) $this->remise = 0; @@ -356,6 +358,7 @@ class Facture extends CommonInvoice $this->linked_objects = $_facrec->linkedObjectsIds; $forceduedate = $this->calculate_date_lim_reglement(); + // For recurring invoices, update date and number of last generation of recurring template invoice, before inserting new invoice if ($_facrec->frequency > 0) @@ -407,7 +410,7 @@ class Facture extends CommonInvoice // Define due date if not already defined $datelim=(empty($forceduedate)?$this->calculate_date_lim_reglement():$forceduedate); - + // Insert into database $socid = $this->socid; @@ -435,6 +438,7 @@ class Facture extends CommonInvoice $sql.= ", multicurrency_tx"; $sql.= ", retained_warranty"; $sql.= ", retained_warranty_date_limit"; + $sql.= ", retained_warranty_fk_cond_reglement"; $sql.= ")"; $sql.= " VALUES ("; $sql.= "'(PROV)'"; @@ -468,10 +472,11 @@ class Facture extends CommonInvoice $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; $sql.= ", ".(double) $this->multicurrency_tx; $sql.= ", ".(empty($this->retained_warranty)?"0":$this->db->escape($this->retained_warranty)); - $sql.= ", '".$this->db->idate($this->retained_warranty_date_limit)."'"; + $sql.= ", ".(!empty($this->retained_warranty_date_limit)?"'".$this->db->idate($this->retained_warranty_date_limit)."'":'NULL'); + $sql.= ", ".(int) $this->retained_warranty_fk_cond_reglement; $sql.=")"; - + $resql=$this->db->query($sql); if ($resql) { @@ -1288,7 +1293,7 @@ class Facture extends CommonInvoice $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc'; $sql.= ', f.fk_incoterms, f.location_incoterms'; $sql.= ", i.libelle as libelle_incoterms"; - $sql.= ", f.retained_warranty as retained_warranty, f.retained_warranty_date_limit as retained_warranty_date_limit"; + $sql.= ", f.retained_warranty as retained_warranty, f.retained_warranty_date_limit as retained_warranty_date_limit, f.retained_warranty_fk_cond_reglement as retained_warranty_fk_cond_reglement"; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_payment_term as c ON f.fk_cond_reglement = c.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON f.fk_mode_reglement = p.id'; @@ -1356,8 +1361,9 @@ class Facture extends CommonInvoice $this->situation_cycle_ref = $obj->situation_cycle_ref; $this->situation_counter = $obj->situation_counter; $this->situation_final = $obj->situation_final; - $this->retained_warranty = $obj->retained_warranty; - $this->retained_warranty_date_limit = $this->db->jdate($obj->retained_warranty_date_limit); + $this->retained_warranty = $obj->retained_warranty; + $this->retained_warranty_date_limit = $this->db->jdate($obj->retained_warranty_date_limit); + $this->retained_warranty_fk_cond_reglement = $obj->retained_warranty_fk_cond_reglement; $this->extraparams = (array) json_decode($obj->extraparams, true); // Incoterms @@ -1628,7 +1634,8 @@ class Facture extends CommonInvoice $sql.= " situation_counter=".(empty($this->situation_counter)?"null":$this->db->escape($this->situation_counter)).","; $sql.= " situation_final=".(empty($this->situation_counter)?"0":$this->db->escape($this->situation_counter)).","; $sql.= " retained_warranty=".(empty($this->retained_warranty)?"0":$this->db->escape($this->retained_warranty)).","; - $sql.= " retained_warranty_date_limit=".(strval($this->retained_warranty_date_limit)!='' ? "'".$this->db->idate($this->retained_warranty_date_limit)."'" : 'null'); + $sql.= " retained_warranty_date_limit=".(strval($this->retained_warranty_date_limit)!='' ? "'".$this->db->idate($this->retained_warranty_date_limit)."'" : 'null').","; + $sql.= " retained_warranty_fk_cond_reglement=".(isset($this->retained_warranty_fk_cond_reglement)?intval($this->retained_warranty_fk_cond_reglement):"null"); $sql.= " WHERE rowid=".$this->id; $this->db->begin(); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5e528f6a1d0..37f61e01f32 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1906,6 +1906,43 @@ abstract class CommonObject return -2; } } + + /** + * Change the retained warranty payments terms + * + * @param int $id Id of new payment terms + * @return int >0 if OK, <0 if KO + */ + function setRetainedWarrantyPaymentTerms($id) + { + dol_syslog(get_class($this).'::setRetainedWarrantyPaymentTerms('.$id.')'); + if ($this->statut >= 0 || $this->element == 'societe') + { + $fieldname = 'retained_warranty_fk_cond_reglement'; + + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql .= ' SET '.$fieldname.' = '.$id; + $sql .= ' WHERE rowid='.$this->id; + + if ($this->db->query($sql)) + { + $this->retained_warranty_fk_cond_reglement = $id; + return 1; + } + else + { + dol_syslog(get_class($this).'::setRetainedWarrantyPaymentTerms Erreur '.$sql.' - '.$this->db->error()); + $this->error=$this->db->error(); + return -1; + } + } + else + { + dol_syslog(get_class($this).'::setRetainedWarrantyPaymentTerms, status of the object is incompatible'); + $this->error='Status of the object is incompatible '.$this->statut; + return -2; + } + } /** * Define delivery address diff --git a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql index fb7db220138..3eb266d3559 100644 --- a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql +++ b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql @@ -53,5 +53,6 @@ ALTER TABLE llx_payment_salary ADD COLUMN fk_projet integer DEFAULT NULL after a ALTER TABLE llx_facture ADD COLUMN retained_warranty real DEFAULT NULL after situation_final; ALTER TABLE llx_facture ADD COLUMN retained_warranty_date_limit date DEFAULT NULL after retained_warranty; +ALTER TABLE llx_facture ADD COLUMN retained_warranty_fk_cond_reglement integer DEFAULT NULL after retained_warranty_date_limit; diff --git a/htdocs/install/mysql/tables/llx_facture.sql b/htdocs/install/mysql/tables/llx_facture.sql index abdefedc944..f18ec0f521c 100644 --- a/htdocs/install/mysql/tables/llx_facture.sql +++ b/htdocs/install/mysql/tables/llx_facture.sql @@ -86,8 +86,9 @@ create table llx_facture situation_counter smallint, -- situation counter situation_final smallint, -- is the situation final ? - retained_warranty real DEFAULT NULL, -- % of retained warranty - retained_warranty_date_limit date DEFAULT NULL, + retained_warranty real DEFAULT NULL, -- % of retained warranty + retained_warranty_date_limit date DEFAULT NULL, + retained_warranty_fk_cond_reglement integer DEFAULT NULL, -- payment condition of retained warranty import_key varchar(14), extraparams varchar(255), -- for other parameters with json format diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index c547f385be0..c9f966b2e2a 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -552,3 +552,10 @@ AutoFillDateToShort=Set end date MaxNumberOfGenerationReached=Max number of gen. reached ToPayOn=To pay on %s RetainedWarranty=Retained Warranty +PaymentConditionsShortRetainedWarranty=Retained warranty payment terms +DefaultPaymentConditionsRetainedWarranty=Default retained warranty payment terms +setPaymentConditionsShortRetainedWarranty=Set retained warranty payment terms +setretainedwarranty=Set retained warranty +setretainedwarrantyDateLimit=Set retained warranty date limit +RetainedWarrantyDateLimit=Retained warranty date limit +RetainedWarrantyNeed100Percent=The situation invoice need to be at 100%% progress to be displayed on PDF From 6fad0ea5bd07307efb56573714b377db3bde61a9 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Fri, 10 Aug 2018 16:03:39 +0200 Subject: [PATCH 04/23] Add retained warranty to pdf --- htdocs/compta/facture/card.php | 2 +- .../modules/facture/doc/pdf_crabe.modules.php | 43 +++++++++++++++++++ htdocs/langs/en_US/bills.lang | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index c9e14304954..b1d1116e54c 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -4079,7 +4079,7 @@ else if ($id > 0 || ! empty($ref)) { print $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->retained_warranty_fk_cond_reglement, 'none'); if(!$displayWarranty){ - print img_picto($langs->trans('RetainedWarrantyNeed100Percent'), 'warning.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')); + print img_picto($langs->trans('RetainedWarrantyNeed100Percent'), 'warning.png', 'class="pictowarning valignmiddle" '); } } print ''; diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index ba52759ea35..ad650aca9b4 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -1331,6 +1331,49 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $total_ttc, 0, $outputlangs), $useborder, 'R', 1); + + // Retained warranty + if( !empty($object->situation_final) && ( $object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty) ) ) ) + { + // 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->SetFillColor(255,255,255); + + $retainedWarranty = $object->total_ttc * $object->retained_warranty / 100; + $billedWithRetainedWarranty = $object->total_ttc - $retainedWarranty ; + + // Billed - retained warranty + $index++; + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); + $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->MultiCell($largcol2, $tab2_hl, price($billedWithRetainedWarranty) , $useborder, 'R', 1); + + // retained warranty + $index++; + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); + + $retainedWarrantyToPayOn = $outputlangs->transnoentities("RetainedWarranty") . ' ('.$object->retained_warranty.'%)'; + $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->SetXY($col2x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2, $tab2_hl, price($retainedWarranty) , $useborder, 'R', 1); + } + } + } } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index c9f966b2e2a..95c1a87172a 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -551,6 +551,7 @@ AutoFillDateTo=Set end date for service line with next invoice date AutoFillDateToShort=Set end date MaxNumberOfGenerationReached=Max number of gen. reached ToPayOn=To pay on %s +toPayOn=to pay on %s RetainedWarranty=Retained Warranty PaymentConditionsShortRetainedWarranty=Retained warranty payment terms DefaultPaymentConditionsRetainedWarranty=Default retained warranty payment terms From 681ae88e97b8b3155ccdf7ffbd5072a63961314e Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Fri, 10 Aug 2018 16:59:22 +0200 Subject: [PATCH 05/23] fix display cond --- htdocs/compta/facture/card.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index b1d1116e54c..6f4796106c7 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -4001,14 +4001,12 @@ else if ($id > 0 || ! empty($ref)) } print ''; } - + $displayWarranty = false; - if( !empty($object->situation_final) - && ( $object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)) ) - ) + if( ( $object->type == Facture::TYPE_SITUATION && (!empty($object->retained_warranty) || !empty($conf->global->INVOICE_USE_SITUATION_RETAINED_WARRANTY)) ) ) { // Check if this situation invoice is 100% for real - if(!empty($object->lines)){ + if(!empty($object->situation_final) && !empty($object->lines)){ $displayWarranty = true; foreach( $object->lines as $i => $line ){ if($line->product_type < 2 && $line->situation_percent < 100){ From 40369280ba330e9645d5e52835f212311e01883a Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Tue, 25 Sep 2018 12:16:16 +0200 Subject: [PATCH 06/23] fix allow empty selection on form conditions reglement --- htdocs/compta/facture/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 6f4796106c7..4974bcb4a39 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -3129,7 +3129,7 @@ if ($action == 'create') print ''; print '
'; - print $langs->trans('RetainedWarrantyDateLimit'); + // Retained warranty payment term + print '
'; + print ''; - if ($action != 'editretainedwarrantydatelimit' && $user->rights->facture->creer){ - print ''; + if ($action != 'editretainedwarrantypaymentterms' && $user->rights->facture->creer){ + print ''; } print '
'; + print $langs->trans('PaymentConditionsShortRetainedWarranty'); print 'id . '">' . img_edit($langs->trans('setretainedwarrantyDateLimit'), 1) . 'id . '">' . img_edit($langs->trans('setPaymentConditionsShortRetainedWarranty'), 1) . '
'; @@ -3983,21 +4062,66 @@ else if ($id > 0 || ! empty($ref)) $defaultDate = $object->date; } - if ($action == 'editretainedwarrantydatelimit') + if ($action == 'editretainedwarrantypaymentterms') { //date('Y-m-d',$object->date_lim_reglement) print ''; - print ''; + print ''; print ''; - print ''; + $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); + $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement)? $retained_warranty_fk_cond_reglement : $object->retained_warranty_fk_cond_reglement; + $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement)? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; + $form->select_conditions_paiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement'); print ''; print ''; } else { - print dol_print_date($defaultDate); + print $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->retained_warranty_fk_cond_reglement, 'none'); + if(!$displayWarranty){ + print img_picto($langs->trans('RetainedWarrantyNeed100Percent'), 'warning.png', 'class="pictowarning valignmiddle"'.($moreatt ? ($moreatt == '1' ? ' style="float: right"' : ' '.$moreatt): '')); + } } print '
'; + print ''; + if ($action != 'editretainedwarrantydatelimit' && $user->rights->facture->creer){ + print ''; + } + + print '
'; + print $langs->trans('RetainedWarrantyDateLimit'); + print 'id . '">' . img_edit($langs->trans('setretainedwarrantyDateLimit'), 1) . '
'; + print '
'; + $defaultDate = !empty($object->retained_warranty_date_limit)?$object->retained_warranty_date_limit:strtotime('-1 years', $object->date_lim_reglement); + if($object->date > $defaultDate){ + $defaultDate = $object->date; + } + + if ($action == 'editretainedwarrantydatelimit') + { + //date('Y-m-d',$object->date_lim_reglement) + print '
'; + print ''; + print ''; + print ''; + print ''; + print '
'; + } + else + { + print dol_print_date($object->retained_warranty_date_limit, 'day'); + } + print '
' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' 
' . $langs->trans("ToPayOn", dol_print_date($object->date_lim_reglement)) . ' :' . price($billedWithRetainedWarranty) . ' 
' . $langs->trans("ToPayOn", dol_print_date($object->date_lim_reglement, 'day')) . ' :' . price($billedWithRetainedWarranty) . ' 
'; print $langs->trans("RetainedWarranty") . ' ('.$object->retained_warranty.'%)'; - print !empty($object->retained_warranty_date_limit)?' '.$langs->trans("ToPayOn", dol_print_date($object->retained_warranty_date_limit)):''; + print !empty($object->retained_warranty_date_limit)?' '.$langs->trans("ToPayOn", dol_print_date($object->retained_warranty_date_limit, 'day')):''; print ' :' . price($retainedWarranty) . ' 
' . $langs->trans('PaymentConditionsShortRetainedWarranty') . ''; $retained_warranty_fk_cond_reglement = GETPOST('retained_warranty_fk_cond_reglement', 'int'); $retained_warranty_fk_cond_reglement = !empty($retained_warranty_fk_cond_reglement)? $retained_warranty_fk_cond_reglement : $conf->global->INVOICE_SITUATION_DEFAULT_RETAINED_WARRANTY_COND_ID; - $form->select_conditions_paiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement'); + $form->select_conditions_paiements($retained_warranty_fk_cond_reglement, 'retained_warranty_fk_cond_reglement', -1, 1); print '