diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 90bc80a6a19..1dd7dab2de8 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -553,7 +553,7 @@ if (empty($reshook)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) ) { - $idwarehouse = GETPOST('idwarehouse'); + $idwarehouse = GETPOST('idwarehouse','int'); $object->fetch($id); $object->fetch_thirdparty(); @@ -640,8 +640,8 @@ if (empty($reshook)) else if ($action == 'confirm_paid_partially' && $confirm == 'yes' && $user->rights->facture->paiement) { $object->fetch($id); - $close_code = $_POST["close_code"]; - $close_note = $_POST["close_note"]; + $close_code = GETPOST("close_code",'none'); + $close_note = GETPOST("close_note",'none'); if ($close_code) { $result = $object->set_paid($user, $close_code, $close_note); if ($result<0) setEventMessages($object->error, $object->errors, 'errors'); @@ -651,8 +651,8 @@ if (empty($reshook)) } // Classify "abandoned" else if ($action == 'confirm_canceled' && $confirm == 'yes') { $object->fetch($id); - $close_code = $_POST["close_code"]; - $close_note = $_POST["close_note"]; + $close_code = GETPOST("close_code",'none'); + $close_note = GETPOST("close_note",'none'); if ($close_code) { $result = $object->set_canceled($user, $close_code, $close_note); if ($result<0) setEventMessages($object->error, $object->errors, 'errors'); @@ -1419,6 +1419,7 @@ if (empty($reshook)) } } + // Situation invoices if (GETPOST('type') == Facture::TYPE_SITUATION && (!empty($_POST['situations']))) { $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); @@ -1455,16 +1456,16 @@ if (empty($reshook)) $object->fetch_thirdparty(); $object->date = $datefacture; $object->date_pointoftax = $date_pointoftax; - $object->note_public = trim($_POST['note_public']); - $object->note = trim($_POST['note']); - $object->ref_client = $_POST['ref_client']; - $object->ref_int = $_POST['ref_int']; - $object->modelpdf = $_POST['model']; - $object->fk_project = $_POST['projectid']; - $object->cond_reglement_id = $_POST['cond_reglement_id']; - $object->mode_reglement_id = $_POST['mode_reglement_id']; - $object->remise_absolue = $_POST['remise_absolue']; - $object->remise_percent = $_POST['remise_percent']; + $object->note_public = trim(GETPOST('note_public','none')); + $object->note = trim(GETPOST('note','none')); + $object->ref_client = GETPOST('ref_client','alpha'); + $object->ref_int = GETPOST('ref_int','alpha'); + $object->modelpdf = GETPOST('model','alpha'); + $object->fk_project = GETPOST('projectid','int'); + $object->cond_reglement_id = GETPOST('cond_reglement_id','int'); + $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 @@ -1533,14 +1534,14 @@ if (empty($reshook)) // Set if we used free entry or predefined product $predef=''; - $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):''); + $product_desc=(GETPOST('dp_desc','none')?GETPOST('dp_desc','none'):''); $price_ht = GETPOST('price_ht'); $price_ht_devise = GETPOST('multicurrency_price_ht'); $prod_entry_mode = GETPOST('prod_entry_mode','alpha'); if ($prod_entry_mode == 'free') { $idprod=0; - $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); + $tva_tx = (GETPOST('tva_tx','alpha') ? GETPOST('tva_tx','alpha') : 0); } else { diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index c36e6cb09d1..630433324c4 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -439,7 +439,7 @@ class FactureRec extends CommonInvoice $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, '; $sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,'; - $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; + $sql.= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc,'; //$sql.= ' l.situation_percent, l.fk_prev_id,'; //$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise_percent, l.fk_remise_except, l.subprice,'; $sql.= ' l.rang, l.special_code,'; @@ -487,6 +487,8 @@ class FactureRec extends CommonInvoice $line->remise_percent = $objp->remise_percent; $line->fk_remise_except = $objp->fk_remise_except; $line->fk_product = $objp->fk_product; + $line->date_start_fill = $objp->date_start_fill; + $line->date_end_fill = $objp->date_end_fill; $line->info_bits = $objp->info_bits; $line->total_ht = $objp->total_ht; $line->total_tva = $objp->total_tva; @@ -602,15 +604,17 @@ class FactureRec extends CommonInvoice * @param string $label Label of the line * @param string $fk_unit Unit * @param double $pu_ht_devise Unit price in currency + * @param int $date_start_fill 1=Flag to fill start date when generating invoice + * @param int $date_end_fill 1=Flag to fill end date when generating invoice * @return int <0 if KO, Id of line if OK */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0) + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise=0, $date_start_fill=0, $date_end_fill=0) { global $mysoc; $facid=$this->id; - dol_syslog(get_class($this)."::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit,pu_ht_devise=$pu_ht_devise", LOG_DEBUG); + dol_syslog(get_class($this)."::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit,pu_ht_devise=$pu_ht_devise,date_start_fill=$date_start_fill,date_end_fill=$date_end_fill", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; // Check parameters @@ -700,6 +704,8 @@ class FactureRec extends CommonInvoice $sql.= ", total_localtax1"; $sql.= ", total_localtax2"; $sql.= ", total_ttc"; + $sql.= ", date_start_fill"; + $sql.= ", date_end_fill"; $sql.= ", info_bits"; $sql.= ", rang"; $sql.= ", special_code"; @@ -727,6 +733,8 @@ class FactureRec extends CommonInvoice $sql.= ", ".price2num($total_localtax1); $sql.= ", ".price2num($total_localtax2); $sql.= ", ".price2num($total_ttc); + $sql.= ", ".(int) $date_start_fill; + $sql.= ", ".(int) $date_end_fill; $sql.= ", ".$info_bits; $sql.= ", ".$rang; $sql.= ", ".$special_code; @@ -778,9 +786,11 @@ class FactureRec extends CommonInvoice * @param string $fk_unit Unit * @param double $pu_ht_devise Unit price in currency * @param int $notrigger disable line update trigger + * @param int $date_start_fill 1=Flag to fill start date when generating invoice + * @param int $date_end_fill 1=Flag to fill end date when generating invoice * @return int <0 if KO, Id of line if OK */ - function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise = 0, $notrigger=0) + function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null, $pu_ht_devise = 0, $notrigger=0, $date_start_fill=0, $date_end_fill=0) { global $mysoc; @@ -883,6 +893,8 @@ class FactureRec extends CommonInvoice $sql.= ", total_localtax1='".price2num($total_localtax1)."'"; $sql.= ", total_localtax2='".price2num($total_localtax2)."'"; $sql.= ", total_ttc='".price2num($total_ttc)."'"; + $sql.= ", date_start_fill=".((int) $date_start_fill); + $sql.= ", date_end_fill=".((int) $date_end_fill); $sql.= ", info_bits=".$info_bits; $sql.= ", rang=".$rang; $sql.= ", special_code=".$special_code; @@ -948,7 +960,7 @@ class FactureRec extends CommonInvoice * Create all recurrents invoices (for all entities if multicompany is used). * A result may also be provided into this->output. * - * WARNING: This method change context $conf->entity to be in correct context for each recurring invoice found. + * WARNING: This method change temporarly context $conf->entity to be in correct context for each recurring invoice found. * * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) */ @@ -1561,6 +1573,10 @@ class FactureLigneRec extends CommonInvoiceLine public $element='facturedetrec'; public $table_element='facturedet_rec'; + var $date_start_fill; + var $date_end_fill; + + /** * Delete line in database * @@ -1615,7 +1631,7 @@ class FactureLigneRec extends CommonInvoiceLine { $sql = 'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx,'; $sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,'; - $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; + $sql.= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; $sql.= ' l.rang, l.special_code,'; $sql.= ' l.fk_unit, l.fk_contract_line,'; $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc'; @@ -1655,6 +1671,8 @@ class FactureLigneRec extends CommonInvoiceLine $this->remise_percent = $objp->remise_percent; $this->fk_remise_except = $objp->fk_remise_except; $this->fk_product = $objp->fk_product; + $this->date_start_fill = $objp->date_start_fill; + $this->date_end_fill = $objp->date_end_fill; $this->info_bits = $objp->info_bits; $this->total_ht = $objp->total_ht; $this->total_tva = $objp->total_tva; @@ -1711,6 +1729,9 @@ class FactureLigneRec extends CommonInvoiceLine $sql.= ", product_type=".$this->product_type; $sql.= ", remise_percent='".price2num($this->remise_percent)."'"; $sql.= ", subprice='".price2num($this->subprice)."'"; + $sql.= ", info_bits='".price2num($this->info_bits)."'"; + $sql.= ", date_start_fill=".(int) $this->date_start_fill; + $sql.= ", date_end_fill=".(int) $this->date_end_fill; $sql.= ", total_ht='".price2num($this->total_ht)."'"; $sql.= ", total_tva='".price2num($this->total_tva)."'"; $sql.= ", total_localtax1='".price2num($this->total_localtax1)."'"; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 1939aa0e62f..8aca7562654 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -287,6 +287,10 @@ class Facture extends CommonInvoice $this->db->begin(); + $originaldatewhen=null; + $nextdatewhen=null; + $previousdaynextdatewhen=null; + // Create invoice from a template invoice if ($this->fac_rec > 0) { @@ -297,7 +301,10 @@ class Facture extends CommonInvoice $result=$_facrec->fetch($this->fac_rec); $result=$_facrec->fetchObjectLinked(); // This load $_facrec->linkedObjectsIds + // Define some dates $originaldatewhen = $_facrec->date_when; + $nextdatewhen=dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency); + $previousdaynextdatewhen=dol_time_plus_duree($nextdatewhen, -1, 'd'); $this->socid = $_facrec->socid; // Invoice created on same thirdparty than template $this->entity = $_facrec->entity; // Invoice created in same entity than template @@ -374,7 +381,8 @@ class Facture extends CommonInvoice $substitutionarray['__INVOICE_NEXT_YEAR__'] = dol_print_date(dol_time_plus_duree($this->date, 1, 'y'), '%Y'); // Only for tempalte invoice $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = dol_print_date($originaldatewhen, 'dayhour'); - $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date(dol_time_plus_duree($originaldatewhen, $_facrec->frequency, $_facrec->unit_frequency), 'dayhour'); + $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date($nextdatewhen, 'dayhour'); + $substitutionarray['__INVOICE_PREVIOUS_DATE_NEXT_INVOICE_AFTER_GEN__'] = dol_print_date($previousdaynextdatewhen, 'dayhour'); //var_dump($substitutionarray);exit; @@ -494,6 +502,7 @@ class Facture extends CommonInvoice } } + // Propagate contacts if (! $error && $this->id && ! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && ! empty($this->origin) && ! empty($this->origin_id)) // Get contact from origin object { $originforcontact = $this->origin; @@ -531,11 +540,10 @@ class Facture extends CommonInvoice else dol_print_error($resqlcontact); } - /* - * Insert lines of invoices into database + * Insert lines of invoices, if not from template invoice, into database */ - if (count($this->lines) && is_object($this->lines[0])) // If this->lines is array of InvoiceLines (preferred mode) + if (! $error && empty($this->fac_rec) && count($this->lines) && is_object($this->lines[0])) // If this->lines is array of InvoiceLines (preferred mode) { $fk_parent_line = 0; @@ -545,9 +553,18 @@ class Facture extends CommonInvoice $newinvoiceline=$this->lines[$i]; $newinvoiceline->fk_facture=$this->id; - // TODO This seems not used. Here we put origin 'facture' but after, we put an id of object ! - $newinvoiceline->origin = $this->element; - $newinvoiceline->origin_id = $this->lines[$i]->id; + $newinvoiceline->origin = $this->lines[$i]->element; + $newinvoiceline->origin_id = $this->lines[$i]->id; + + // Auto set date of service ? + if ($this->lines[$i]->date_start_fill == 1 && $originaldatewhen) // $originaldatewhen is defined when generating from recurring invoice only + { + $newinvoiceline->date_start = $originaldatewhen; + } + if ($this->lines[$i]->date_end_fill == 1 && $previousdaynextdatewhen) // $previousdaynextdatewhen is defined when generating from recurring invoice only + { + $newinvoiceline->date_end = $previousdaynextdatewhen; + } if ($result >= 0) { @@ -581,7 +598,7 @@ class Facture extends CommonInvoice } } } - else // If this->lines is an array of invoice line arrays + elseif (! $error && empty($this->fac_rec)) // If this->lines is an array of invoice line arrays { $fk_parent_line = 0; @@ -689,7 +706,9 @@ class Facture extends CommonInvoice $localtax2_tx, $_facrec->lines[$i]->fk_product, $_facrec->lines[$i]->remise_percent, - '','',0, + ($_facrec->lines[$i]->date_start_fill == 1 && $originaldatewhen)?$originaldatewhen:'', + ($_facrec->lines[$i]->date_end_fill == 1 && $previousdaynextdatewhen)?$previousdaynextdatewhen:'', + 0, $tva_npr, '', 'HT', @@ -2522,8 +2541,8 @@ class Facture extends CommonInvoice * @param double $txlocaltax2 Local tax 2 rate (deprecated, use instead txtva with code inside) * @param int $fk_product Id of predefined product/service * @param double $remise_percent Percent of discount on line - * @param int $date_start Date start of service - * @param int $date_end Date end of service + * @param int $date_start Date start of service + * @param int $date_end Date end of service * @param int $ventil Code of dispatching into accountancy * @param int $info_bits Bits de type de lignes * @param int $fk_remise_except Id discount used diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 8d955f1141d..6f96e74d345 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -66,22 +66,8 @@ if ($action == "create" || $action == "add") $objecttype = ''; $result = restrictedArea($user, 'facture', $id, $objecttype); $projectid = GETPOST('projectid','int'); -$search_ref=GETPOST('search_ref'); -$search_societe=GETPOST('search_societe'); -$search_montant_ht=GETPOST('search_montant_ht'); -$search_montant_vat=GETPOST('search_montant_vat'); -$search_montant_ttc=GETPOST('search_montant_ttc'); -$search_payment_mode=GETPOST('search_payment_mode'); -$search_payment_term=GETPOST('search_payment_term'); -$day=GETPOST('day'); -$year=GETPOST('year'); -$month=GETPOST('month'); -$day_date_when=GETPOST('day_date_when'); $year_date_when=GETPOST('year_date_when'); $month_date_when=GETPOST('month_date_when'); -$search_recurring=GETPOST('search_recurring','int'); -$search_frequency=GETPOST('search_frequency','alpha'); -$search_unit_frequency=GETPOST('search_unit_frequency','alpha'); $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); @@ -144,28 +130,6 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once - // Do we click on purge search criteria ? - if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All test are required to be compatible with all browsers - { - $search_ref=''; - $search_societe=''; - $search_montant_ht=''; - $search_montant_vat=''; - $search_montant_ttc=''; - $search_montant_mode=''; - $search_montant_term=''; - $day=''; - $year=''; - $month=''; - $day_date_when=''; - $year_date_when=''; - $month_date_when=''; - $search_recurring=''; - $search_frequency=''; - $search_unit_frequency=''; - $search_array_options=array(); - } - // Mass actions /*$objectclass='MyObject'; $objectlabel='MyObject'; @@ -686,6 +650,9 @@ if (empty($reshook)) $fk_unit= GETPOST('units', 'alpha'); } + $date_start_fill = GETPOST('date_start_fill','int'); + $date_end_fill = GETPOST('date_end_fill','int'); + // Margin $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : ''); $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value @@ -706,7 +673,7 @@ if (empty($reshook)) else { // Insert line - $result = $object->addline($desc, $pu_ht, $qty, $tva_tx,$localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit); + $result = $object->addline($desc, $pu_ht, $qty, $tva_tx,$localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit, 0, $date_start_fill, $date_end_fill); if ($result > 0) { @@ -762,6 +729,9 @@ if (empty($reshook)) unset($_POST['date_endmonth']); unset($_POST['date_endyear']); + unset($_POST['date_start_fill']); + unset($_POST['date_end_fill']); + unset($_POST['situations']); unset($_POST['progress']); } @@ -883,6 +853,9 @@ if (empty($reshook)) $error ++; } + $date_start_fill = GETPOST('date_start_fill','int'); + $date_end_fill = GETPOST('date_end_fill','int'); + // Update line if (! $error) { @@ -905,7 +878,10 @@ if (empty($reshook)) $special_code, $label, GETPOST('units'), - $pu_ht_devise + $pu_ht_devise, + 0, + $date_start_fill, + $date_end_fill ); if ($result >= 0) diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 501e3db3d6c..e2dfed0f68b 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -283,6 +283,18 @@ else { if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes'; $doleditor=new DolEditor('dp_desc',GETPOST('dp_desc'),'',100,$toolbarname,'',false,true,$enabled,$nbrows,'98%'); $doleditor->Create(); + + // Show autofill date for recuring invoices + if (! empty($conf->service->enabled) && $object->element == 'facturerec') + { + echo '