diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 9785e2f1007..f3550580985 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -48,8 +48,8 @@ if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande $sall=isset($_GET["sall"])?$_GET["sall"]:$_POST["sall"]; -if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; } if (isset($_GET["msg"])) { $msg=urldecode($_GET["msg"]); } +if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; } // Sécurité accés client if ($user->societe_id > 0) @@ -512,347 +512,356 @@ $html = new Form($db); **********************************************************************/ if ($_GET["action"] == 'create') { - print_titre($langs->trans("NewBill")); if ($_GET["propalid"]) { - $sql = "SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, ".$db->pdate("p.datep")." as dp, c.id as statut, c.label as lst"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; - $sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id"; - $sql .= " AND p.rowid = ".$_GET["propalid"]; + $propal = New Propal($db); + $propal->fetch($_GET["propalid"]); + $societe_id = $propal->soc_id; } - else - { - $sql = "SELECT s.nom, s.prefix_comm, s.idp "; - $sql .= "FROM ".MAIN_DB_PREFIX."societe as s "; - $sql .= "WHERE s.idp = ".$_GET["socidp"]; - } - - if ($_GET["commandeid"]) + elseif ($_GET["commandeid"]) { $commande = New Commande($db); $commande->fetch($_GET["commandeid"]); $societe_id = $commande->soc_id; } - - if ( $db->query($sql) ) + elseif ($_GET["contratid"]) { - $num = $db->num_rows(); - if ($num) - { - $obj = $db->fetch_object(); + $contrat = New Contrat($db); + $contrat->fetch($_GET["contratid"]); + $societe_id = $contrat->soc_id; + } + else $societe_id=$socidp; - $soc = new Societe($db); - $soc->fetch($obj->idp); + $soc = new Societe($db); + $soc->fetch($societe_id); - print '
'; - print ''; - print '' ."\n"; - print ''; + print ''; + print ''; + print '' ."\n"; + print ''; - print ''; + print '
'; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; - print ''; + print ''; + print ''; - print ''; + print ''; + print ''; + print ''; - print ''; + print ''; - print ''; - print ''; + // Notes + print ''; - // Conditions de réglement - $id_condition_paiements_defaut=1; - print ""; + // Conditions de réglement + $id_condition_paiements_defaut=1; + print ""; - // Mode de réglement - print ""; + // Mode de réglement + print ""; - // Projet - if ($conf->projet->enabled) - { - $langs->load("projects"); - print '"; - } - else - { - print ''; - } - - if ($_GET["propalid"] > 0) - { - $amount = ($obj->price); - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''; - - print ''; - print ''; - print '"; - print '"; - } - elseif ($_GET["commandeid"] > 0) - { - print ''; - print ''; - print ''; - print '"; - print '"; - } - else - { - print ''; - print ''; - } - - /* - * Factures récurrentes - */ - if ($_GET["propalid"] == 0 && $_GET["commandeid"] == 0) - { - $sql = "SELECT r.rowid, r.titre, r.amount FROM ".MAIN_DB_PREFIX."facture_rec as r"; - $sql .= " WHERE r.fk_soc = ".$soc->id; - if ( $db->query($sql) ) - { - $num = $db->num_rows(); - $i = 0; - - if ($num > 0) - { - print ''; - } - $db->free(); - } - else - { - dolibarr_print_error($db); - } - } - - /* - * - */ - print ''; - print "\n"; - print "
'.$langs->trans("Company").''.$soc->nom.'
'.$langs->trans("Ref").''.$langs->trans("Draft").'
'.$langs->trans("Author").''.$user->fullname.''.$langs->trans("Comments").'
'.$langs->trans("Company").''.$soc->nom.'
'.$langs->trans("Date").''; - $html->select_date(); - print '
'.$langs->trans("Author").''.$user->fullname.''.$langs->trans("Comments").'
'; - print '
'.$langs->trans("Date").''; + $html->select_date(); + print '
'.$langs->trans("Ref").'Provisoire
'; + print '
".$langs->trans("PaymentConditions").""; - $html->select_conditions_paiements($id_condition_paiements_defaut,'cond_reglement_id'); - print "
".$langs->trans("PaymentConditions").""; + $html->select_conditions_paiements($id_condition_paiements_defaut,'cond_reglement_id'); + print "
".$langs->trans("PaymentMode").""; - $html->select_types_paiements('','mode_reglement_id'); - print "
".$langs->trans("PaymentMode").""; + $html->select_types_paiements('','mode_reglement_id'); + print "
'.$langs->trans("Project").''; - $html->select_projects($socidp); - print "
 
'.$langs->trans("Proposal").''.$obj->ref.'
'.$langs->trans("TotalHT").''.price($amount).'
'.$langs->trans("VAT").''.price($obj->tva)."
'.$langs->trans("TotalTTC").''.price($obj->total)."
'.$langs->trans("Order").''.$commande->ref.'
'.$langs->trans("TotalHT").''.price($commande->total_ht).'
'.$langs->trans("VAT").''.price($commande->total_tva)."
'.$langs->trans("TotalTTC").''.price($commande->total_ttc)."
 
'; - - print ''; - print ''; - if ($conf->service->enabled) - { - print ''; - } - for ($i = 1 ; $i <= $NBLINES ; $i++) - { - print ''; - print ''; - print ''; - print ''; - // Si le module service est actif, on propose des dates de début et fin à la ligne - if ($conf->service->enabled) { - print ''; - } - print "\n"; - } - - print '
Services/Produits prédéfinis'.$langs->trans("Qty").''.$langs->trans("Discount").'     Si produit de type service à durée limitée
'; - $html->select_produits('',"idprod$i"); - print '% '; - print 'Du '; - print $html->select_date('',"date_start$i",0,0,1); - print '
au '; - print $html->select_date('',"date_end$i",0,0,1); - print '
'; - print '
Factures récurrentes :
\n"; - - // Si creation depuis un propal - if ($_GET["propalid"]) - { - print '
'; - print_titre($langs->trans("ProductsAndServices")); - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - // Lignes de propal produits prédéfinis - $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.tva_tx, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = ".$_GET["propalid"]; - $sql .= " ORDER BY pt.rowid ASC"; - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print '\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - // Lignes de propal non produits prédéfinis - $sql = "SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.price, pt.qty, pt.remise_percent"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt "; - $sql .= " WHERE pt.fk_propal = ".$_GET["propalid"]; - $sql .= " AND pt.fk_product = 0"; - $sql .= " ORDER BY pt.rowid ASC"; - $result=$db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - - print '
'.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'
'.img_object($langs->trans(""),"product")." ".$objp->ref.""; - print $objp->product?' - '.$objp->product:''; - print "'; - print $objp->description; - print ''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
 '.$objp->product.''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
'; - } - - // Si creation depuis une commande - if ($_GET["commandeid"]) - { - print_titre($langs->trans("Products")); - - print ''; - print ''; - print ''; - - $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.subprice, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pt, ".MAIN_DB_PREFIX."product as p"; - $sql .= " WHERE pt.fk_product = p.rowid AND pt.fk_commande = ".$commande->id; - $sql .= " ORDER BY pt.rowid ASC"; - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows(); - $i = 0; - $var=True; - while ($i < $num) - { - $objp = $db->fetch_object(); - $var=!$var; - print '\n"; - print ''; - print ''; - print ''; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - // Lignes de commande non produits prédéfinis - $sql = "SELECT pt.rowid, pt.description as product, pt.subprice, pt.qty, pt.remise_percent"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pt"; - $sql .= " WHERE pt.fk_commande = ".$commande->id; - $sql .= " AND pt.fk_product = 0"; - $sql .= " ORDER BY pt.rowid ASC"; - - $result=$db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - $i++; - } - } - else - { - dolibarr_print_error($db); - } - - print '
'.$langs->trans("Ref").''.$langs->trans("Product").''.$langs->trans("Price").''.$langs->trans("Discount").''.$langs->trans("Qty").'
'.img_object($langs->trans(""),"product")." ".$objp->ref.""; - print $objp->product?' - '.$objp->product:''; - print "'; - print $objp->description; - print ''.price($objp->subprice).''.$objp->remise_percent.'%'.$objp->qty.'
 '.$objp->product.''.price($objp->subprice).''.$objp->remise_percent.'%'.$objp->qty.'
'; - } - - } + // Projet + if ($conf->projet->enabled) + { + $langs->load("projects"); + print ''.$langs->trans("Project").''; + $html->select_projects($socidp); + print ""; } else { - dolibarr_print_error($db); + print ' '; } + + if ($_GET["propalid"] > 0) + { + $amount = ($propal->price); + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''; + + print ''.$langs->trans("Proposal").''.$propal->ref.''; + print ''.$langs->trans("GlobalDiscount").''.$propal->remise_percent.'%'; + print ''.$langs->trans("TotalHT").''.price($amount).''; + print ''.$langs->trans("VAT").''.price($propal->tva).""; + print ''.$langs->trans("TotalTTC").''.price($propal->total).""; + } + elseif ($_GET["commandeid"] > 0) + { + print ''; + + print ''.$langs->trans("Order").''.$commande->ref.''; + print ''.$langs->trans("TotalHT").''.price($commande->total_ht).''; + print ''.$langs->trans("VAT").''.price($commande->total_tva).""; + print ''.$langs->trans("TotalTTC").''.price($commande->total_ttc).""; + } + elseif ($_GET["contratid"] > 0) + { + $amount = ($obj->price); + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''; + + print ''.$langs->trans("Contract").''.$obj->ref.''; + print ''.$langs->trans("TotalHT").''.price($amount).''; + print ''.$langs->trans("VAT").''.price($obj->tva).""; + print ''.$langs->trans("TotalTTC").''.price($obj->total).""; + } + else + { + print ' '; + print ''; + + print ''; + print ''; + if ($conf->service->enabled) + { + print ''; + } + for ($i = 1 ; $i <= $NBLINES ; $i++) + { + print ''; + print ''; + print ''; + print ''; + // Si le module service est actif, on propose des dates de début et fin à la ligne + if ($conf->service->enabled) { + print ''; + } + print "\n"; + } + + print '
'.$langs->trans("ProductsAndServices").''.$langs->trans("Qty").''.$langs->trans("Discount").'     Si produit de type service à durée limitée
'; + $html->select_produits('',"idprod$i"); + print '% '; + print 'Du '; + print $html->select_date('',"date_start$i",0,0,1); + print '
au '; + print $html->select_date('',"date_end$i",0,0,1); + print '
'; + print ''; + } + + /* + * Factures récurrentes + */ + if ($_GET["propalid"] == 0 && $_GET["commandeid"] == 0) + { + $sql = "SELECT r.rowid, r.titre, r.amount FROM ".MAIN_DB_PREFIX."facture_rec as r"; + $sql .= " WHERE r.fk_soc = ".$soc->id; + if ( $db->query($sql) ) + { + $num = $db->num_rows(); + $i = 0; + + if ($num > 0) + { + print 'Factures récurrentes : '; + } + $db->free(); + } + else + { + dolibarr_print_error($db); + } + } + + // Bouton "Create Draft" + print ''; + print "\n"; + print "\n"; + + // Si creation depuis un propal + if ($_GET["propalid"]) + { + print '
'; + print_titre($langs->trans("ProductsAndServices")); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Lignes de propal produits prédéfinis + $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.tva_tx, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description"; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt, ".MAIN_DB_PREFIX."product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = ".$_GET["propalid"]; + $sql .= " ORDER BY pt.rowid ASC"; + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print '\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + // Lignes de propal non produits prédéfinis + $sql = "SELECT pt.rowid, pt.description as product, pt.tva_tx, pt.price, pt.qty, pt.remise_percent"; + $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pt "; + $sql .= " WHERE pt.fk_propal = ".$_GET["propalid"]; + $sql .= " AND pt.fk_product = 0"; + $sql .= " ORDER BY pt.rowid ASC"; + $result=$db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print "\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + print '
'.$langs->trans("Ref").''.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Discount").'
'.img_object($langs->trans(""),"product")." ".$objp->ref.""; + print $objp->product?' - '.$objp->product:''; + print "'; + print dolibarr_trunc($objp->description,60); + print ''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
 '.$objp->product.''.$objp->tva_tx.'%'.price($objp->price).''.$objp->qty.''.$objp->remise_percent.'%
'; + } + + // Si creation depuis une commande + if ($_GET["commandeid"]) + { + print_titre($langs->trans("Products")); + + print ''; + print ''; + print ''; + + $sql = "SELECT pt.rowid, p.label as product, p.ref, pt.subprice, pt.qty, p.rowid as prodid, pt.remise_percent, pt.description"; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pt, ".MAIN_DB_PREFIX."product as p"; + $sql .= " WHERE pt.fk_product = p.rowid AND pt.fk_commande = ".$commande->id; + $sql .= " ORDER BY pt.rowid ASC"; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows(); + $i = 0; + $var=True; + while ($i < $num) + { + $objp = $db->fetch_object(); + $var=!$var; + print '\n"; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + // Lignes de commande non produits prédéfinis + $sql = "SELECT pt.rowid, pt.description as product, pt.subprice, pt.qty, pt.remise_percent"; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as pt"; + $sql .= " WHERE pt.fk_commande = ".$commande->id; + $sql .= " AND pt.fk_product = 0"; + $sql .= " ORDER BY pt.rowid ASC"; + + $result=$db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print "\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } + } + else + { + dolibarr_print_error($db); + } + + print '
'.$langs->trans("Ref").''.$langs->trans("Product").''.$langs->trans("Price").''.$langs->trans("Discount").''.$langs->trans("Qty").'
'.img_object($langs->trans(""),"product")." ".$objp->ref.""; + print $objp->product?' - '.$objp->product:''; + print "'; + print dolibarr_trunc($objp->description,60); + print ''.price($objp->subprice).''.$objp->remise_percent.'%'.$objp->qty.'
 '.$objp->product.''.price($objp->subprice).''.$objp->remise_percent.'%'.$objp->qty.'
'; + } + } else { diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index c639ad58f09..27e6e88a17a 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -112,29 +112,8 @@ class Facture $this->remise_percent = $_facrec->remise_percent; } - $sql = "SELECT fdm,nbjour "; - $sql.= " FROM ".MAIN_DB_PREFIX."cond_reglement"; - $sql.= " WHERE rowid = ".$this->cond_reglement; - if ($this->db->query($sql)) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object(); - $cdr_nbjour = $obj->nbjour; - $cdr_fdm = $obj->fdm; - } - $this->db->free(); - } - // Definition de la date limite - $datelim = $this->date + ( $cdr_nbjour * 3600 * 24 ); - if ($cdr_fdm) - { - $mois=date('m', $datelim); - $annee=date('Y', $datelim); - $fins=array(31,28,31,30,31,30,31,31,30,31,30,31); - $datelim=mktime(0,0,0,$mois,$fins[$mois-1],$annee); - } + $datelim=$this->calculate_date_lim_reglement(); /* * Insertion dans la base @@ -145,7 +124,7 @@ class Facture $remise = $this->remise; if (! $remise) $remise = 0 ; - if (strlen($this->mode_reglement)==0) $this->mode_reglement = 0; + if (strlen($this->mode_reglement_id)==0) $this->mode_reglement_id = 0; if (! $this->projetid) $this->projetid = "NULL"; $totalht = ($amount - $remise); @@ -337,7 +316,7 @@ class Facture //dolibarr_syslog("Facture::Fetch rowid : $rowid, societe_id : $societe_id"); $sql = "SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise,f.remise_percent"; - $sql .= ",".$this->db->pdate("f.datef")." as df,f.fk_projet"; + $sql .= ",".$this->db->pdate("f.datef")." as df, f.fk_projet"; $sql .= ",".$this->db->pdate("f.date_lim_reglement")." as dlr"; $sql .= ", f.note, f.paye, f.fk_statut, f.fk_user_author"; $sql .= ", f.fk_mode_reglement, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle"; @@ -356,6 +335,7 @@ class Facture if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); + //print strftime("%Y%m%d%H%M%S",$obj->df)." ".$obj->df." ".dolibarr_print_date($obj->df); $this->id = $rowid; $this->datep = $obj->dp; @@ -637,10 +617,54 @@ class Facture } } + /** - * \brief Tag la facture comme payée complètement - * \param rowid id de la facture à modifier - */ + * \brief Renvoi une date limite de reglement de facture en fonction des + * conditions de reglements de la facture et date de facturation + * \param cond_reglement_id Condition de reglement à utiliser, 0=Condition actuelle de la facture + * \return date Date limite de réglement si ok, <0 si ko + */ + function calculate_date_lim_reglement($cond_reglement_id=0) + { + if (! $cond_reglement_id) $cond_reglement_id=$this->cond_reglement_id; + + $sqltemp = "SELECT c.fdm,c.nbjour"; + $sqltemp.= " FROM ".MAIN_DB_PREFIX."cond_reglement as c"; + $sqltemp.= " WHERE c.rowid=".$cond_reglement_id; + $resqltemp=$this->db->query($sqltemp); + if ($resqltemp) + { + if ($this->db->num_rows($resqltemp)) + { + $obj = $this->db->fetch_object($resqltemp); + $cdr_nbjour = $obj->nbjour; + $cdr_fdm = $obj->fdm; + } + } + else + { + $this->error=$this->db->error(); + return -1; + } + $this->db->free($resqltemp); + // Definition de la date limite + $datelim = $this->date + ( $cdr_nbjour * 3600 * 24 ); + if ($cdr_fdm) + { + $mois=date('m', $datelim); + $annee=date('Y', $datelim); + $fins=array(31,28,31,30,31,30,31,31,30,31,30,31); + $datelim=mktime(12,0,0,$mois,$fins[$mois-1],$annee); + } + + return $datelim; + } + + + /** + * \brief Tag la facture comme payée complètement + * \param rowid id de la facture à modifier + */ function set_payed($rowid) { $sql = "UPDATE ".MAIN_DB_PREFIX."facture set paye=1 WHERE rowid = ".$rowid ; @@ -747,38 +771,17 @@ class Facture /* Si l'option est activée on force la date de facture */ if (defined("FAC_FORCE_DATE_VALIDATION") && FAC_FORCE_DATE_VALIDATION == "1") { - $sql .= ", datef=now()"; - // du coup, il faut aussi recalculer la date limite de règlement - $sqltemp = "SELECT c.fdm,c.nbjour,c.rowid,f.fk_cond_reglement,f.rowid"; - $sqltemp.= " FROM ".MAIN_DB_PREFIX."cond_reglement as c, ".MAIN_DB_PREFIX."facture as f"; - $sqltemp.= " WHERE c.rowid=f.fk_cond_reglement AND f.rowid=".$this->id; - if ($this->db->query($sqltemp)) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object(); - $cdr_nbjour = $obj->nbjour; - $cdr_fdm = $obj->fdm; - } - } - $this->db->free(); - // Definition de la date limite - $datelim = time() + ( $cdr_nbjour * 3600 * 24 ); - if ($cdr_fdm) - { - $mois=date('m', $datelim); - $annee=date('Y', $datelim); - $fins=array(31,28,31,30,31,30,31,31,30,31,30,31); - $datelim=mktime(0,0,0,$mois,$fins[$mois-1],$annee); - } + $this->date=time(); + $datelim=$this->calculate_date_lim_reglement(); + $sql .= ", datef=".$this->db->idate($this->date); $sql .= ", date_lim_reglement=".$this->db->idate($datelim); - } + $sql .= " WHERE rowid = $rowid ;"; - $result = $this->db->query( $sql); - if ($result) + $resql = $this->db->query($sql); + if ($resql) { // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); @@ -1359,8 +1362,8 @@ class Facture } /** - * \brief Change les conditions de réglement - * \param cond_reglement_id Id des nouvelles conditions + * \brief Change les conditions de réglement de la facture + * \param cond_reglement_id Id de la nouvelle condition de réglement * \return int >0 si ok, <0 si ko */ function cond_reglement($cond_reglement_id) @@ -1368,8 +1371,11 @@ class Facture dolibarr_syslog("Facture::cond_reglement($cond_reglement_id)"); if ($this->statut >= 0 && $this->paye == 0) { + $datelim=$this->calculate_date_lim_reglement($cond_reglement_id); + $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; $sql .= " SET fk_cond_reglement = ".$cond_reglement_id; + $sql .= ", date_lim_reglement=".$this->db->idate($datelim); $sql .= " WHERE rowid=".$this->id; if ( $this->db->query($sql) ) @@ -1719,13 +1725,15 @@ class FactureLigne */ function fetch($rowid, $societe_id=0) { - $sql = "SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent, subprice, ".$this->db->pdate("date_start")." as date_start,".$this->db->pdate("date_end")." as date_end"; - $sql .= " FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$rowid; + $sql = "SELECT fk_product, description, price, qty, rowid, tva_taux, remise, remise_percent,"; + $sql.= " subprice, ".$this->db->pdate("date_start")." as date_start,".$this->db->pdate("date_end")." as date_end"; + $sql.= " FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$rowid; $result = $this->db->query($sql); if ($result) { $objp = $this->db->fetch_object($result); + $this->desc = stripslashes($objp->description); $this->qty = $objp->qty; $this->price = $objp->price;