From 428a7e70423732033ebf0f80b8381aedc8619b8f Mon Sep 17 00:00:00 2001 From: phf Date: Fri, 12 Feb 2016 15:55:55 +0100 Subject: [PATCH] FIX remove comment, calcul next date for recurring invoice, increment nb_gen_done --- .../facture/class/facture-rec.class.php | 42 ++++++---------- htdocs/compta/facture/class/facture.class.php | 50 ++++++++----------- htdocs/compta/facture/fiche-rec.php | 8 +-- 3 files changed, 40 insertions(+), 60 deletions(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 26659db4796..60aebfb7dc3 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -233,27 +233,6 @@ class FactureRec extends Facture $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; $sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc'; $sql.= ', el.fk_source'; - - /* - $sql.= ', f.remise_percent, f.remise_absolue, f.remise'; - $sql.= ', f.datef as df'; - $sql.= ', f.date_lim_reglement as dlr'; - $sql.= ', f.datec as datec'; - $sql.= ', f.date_valid as datev'; - $sql.= ', f.tms as datem'; - $sql.= ', f.note_private, f.note_public, f.fk_statut, f.paye, f.close_code, f.close_note, f.fk_user_author, f.fk_user_valid, f.model_pdf'; - $sql.= ', f.fk_facture_source'; - $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet, f.extraparams'; - $sql.= ', f.situation_cycle_ref, f.situation_counter, f.situation_final'; - $sql.= ', f.fk_account'; - $sql.= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc"; - $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; - $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.= ' FROM '.MAIN_DB_PREFIX.'facture_rec 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'; @@ -599,7 +578,7 @@ class FactureRec extends Facture function getNextDate() { if (empty($this->date_when)) return false; - return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency); + return dol_time_plus_duree(strtotime($this->date_when), $this->frequency, $this->unit_frequency); } /** @@ -627,15 +606,20 @@ class FactureRec extends Facture { $facturerec = new FactureRec($db); $facturerec->fetch($line->rowid); - + $facture = new Facture($db); - $result = $facture->createFromRec($user, $facturerec); // >0 create and validate if auto_validate // =0 create but not validate if auto_validate // <0 broken - if ($result >= 0) $nb_create++; + if ($result >= 0) + { + $next_date = $facturerec->getNextDate(); + $facturerec->setNextDate($next_date,1); + + $nb_create++; + } } } @@ -764,10 +748,11 @@ class FactureRec extends Facture /** * Update the next date of execution * - * @param datetime $date date of execution (format timestamp) - * @return int <0 if KO, >0 if OK + * @param datetime $date date of execution + * @param int $increment_nb_gen_done 0 do nothing more, >0 increment nb_gen_done + * @return int <0 if KO, >0 if OK */ - function setNextDate($date) + function setNextDate($date, $increment_nb_gen_done=0) { if (! $this->table_element) { @@ -777,6 +762,7 @@ class FactureRec extends Facture $date = $this->db->idate($date); $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= ' SET date_when = "'.$date.'"'; + if ($increment_nb_gen_done>0) $sql.= ', nb_gen_done = nb_gen_done + 1'; $sql.= ' WHERE rowid = '.$this->id; dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index a10202470c4..dd1d9b6ca8c 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -922,47 +922,41 @@ class Facture extends CommonInvoice /** * Create a new invoice in database from facturerec * - * @param User $user Object user that ask creation - * @return int <0 if KO, 0 if not validate, >0 if OK + * @param User $user Object user that ask creation + * @param FactureRec $facturerec Object facturerec source + * @return int <0 if KO, 0 if not validate, >0 if OK */ - function createFromRec($user, $object) + function createFromRec($user, $facturerec) { // Clean parameters - if (! $this->type) $this->type = self::TYPE_STANDARD; - $this->ref_client=trim($this->ref_client); - $this->note_private=trim($this->note_private); - $this->note_public=trim($this->note_public); - //if (! $this->remise) $this->remise = 0; - if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; + $this->type = self::TYPE_STANDARD; $this->brouillon = 1; // Charge facture source - $facture=new Facture($object->db); + $facture=new Facture($facturerec->db); - $facture->fk_facture_source = $object->fk_facture_source; - $facture->type = $object->type; - $facture->socid = $object->socid; + $facture->socid = $facturerec->socid; $facture->date = dol_mktime(12, 0, 0, date('m'), date('d'), date('Y')); - $facture->note_public = $object->note_public; - $facture->note_private = $object->note_private; - $facture->ref_client = $object->ref_client; - $facture->modelpdf = $object->modelpdf; - $facture->fk_project = $object->fk_project; - $facture->cond_reglement_id = $object->cond_reglement_id; - $facture->mode_reglement_id = $object->mode_reglement_id; - $facture->remise_absolue = $object->remise_absolue; - $facture->remise_percent = $object->remise_percent; - $facture->fk_incoterms = $object->fk_incoterms; - $facture->location_incoterms= $object->location_incoterms; + $facture->note_public = $facturerec->note_public; + $facture->note_private = $facturerec->note_private; + $facture->fk_project = $facturerec->fk_project; + $facture->fk_account = $facturerec->fk_account; + $facture->cond_reglement_id = $facturerec->cond_reglement_id; + $facture->mode_reglement_id = $facturerec->mode_reglement_id; + + $new_date_lim_reglement = $facture->calculate_date_lim_reglement(); + $facture->date_lim_reglement = $new_date_lim_reglement; + + $facture->remise_absolue = $facturerec->remise_absolue; + $facture->remise_percent = $facturerec->remise_percent; - $facture->lines = $object->lines; // Tableau des lignes de factures - $facture->products = $object->lines; // Tant que products encore utilise + $facture->lines = $facturerec->lines; // Tableau des lignes de factures // Loop on each line of new invoice foreach($facture->lines as $i => $line) { - $facture->lines[$i]->fk_prev_id = $object->lines[$i]->rowid; + $facture->lines[$i]->fk_prev_id = $facturerec->lines[$i]->rowid; } dol_syslog(get_class($this)."::createFromRec socid=".$this->socid." nboflines=".count($facture->lines)); @@ -970,7 +964,7 @@ class Facture extends CommonInvoice $facid = $facture->create($user); if ($facid <= 0) return -1; - if ($object->auto_validate) + if ($facturerec->auto_validate) { $result = $facture->validate($user); if ($result<=0) return 0; diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index ae1e74829d9..0d462d25066 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -121,7 +121,8 @@ if ($action == 'add') if ($object->create($user, $id) > 0) { $id = $object->id; - $action = ''; + header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $id); + exit; } else { @@ -134,13 +135,12 @@ if ($action == 'add') // Delete if ($action == 'delete' && $user->rights->facture->supprimer) { - $object->fetch($id); $object->delete(); - $id = 0 ; + header("Location: " . $_SERVER['PHP_SELF'] ); + exit; } - // Update field // Set condition if ($action == 'setconditions' && $user->rights->facture->creer)