diff --git a/dev/examples/create_invoice.php b/dev/examples/create_invoice.php index 8ef49197055..0f99a5775ff 100755 --- a/dev/examples/create_invoice.php +++ b/dev/examples/create_invoice.php @@ -55,7 +55,6 @@ $user->getrights(); print "***** ".$script_file." (".$version.") *****\n"; - // Start of transaction $db->begin(); @@ -63,6 +62,7 @@ require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); // Create invoice object $obj = new Facture($db); +//$obj->initAsSpecimen(); $obj->ref = 'ABCDE'; $obj->socid = 4; // Put id of third party (rowid in llx_societe table) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 899f5e49c04..80ef51c9784 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -65,8 +65,10 @@ class Facture extends CommonObject var $ref_int; //! 0=Standard invoice, 1=Replacement invoice, 2=Credit note invoice, 3=Deposit invoice, 4=Proforma invoice var $type; - var $amount; - var $remise; + + //var $amount; + var $remise_absolue; + var $remise_percent; var $total_ht; var $total_tva; var $total_ttc; @@ -102,27 +104,26 @@ class Facture extends CommonObject var $nbtodo; var $nbtodolate; var $specimen; - //! Numero d'erreur de 512 a 1023 - var $errno = 0; + /** * Constructor * - * @param DoliDB $DB Database handler + * @param DoliDB $db Database handler */ - function Facture($DB) + function Facture($db) { - $this->db = $DB; + $this->db = $db; - $this->amount = 0; - $this->remise = 0; + //$this->amount = 0; + //$this->remise = 0; $this->remise_percent = 0; + $this->remise_absolue = 0; $this->total_ht = 0; $this->total_tva = 0; $this->total_ttc = 0; $this->propalid = 0; $this->fk_project = 0; - $this->remise_exceptionnelle = 0; } /** @@ -144,7 +145,7 @@ class Facture extends CommonObject $this->ref_client=trim($this->ref_client); $this->note=trim($this->note); $this->note_public=trim($this->note_public); - if (! $this->remise) $this->remise = 0; + //if (! $this->remise) $this->remise = 0; if (! $this->cond_reglement_id) $this->cond_reglement_id = 0; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; $this->brouillon = 1; @@ -183,17 +184,17 @@ class Facture extends CommonObject $this->cond_reglement_id = $_facrec->cond_reglement_id; $this->mode_reglement = $_facrec->mode_reglement_id; $this->mode_reglement_id = $_facrec->mode_reglement_id; - $this->amount = $_facrec->amount; + //$this->amount = $_facrec->amount; $this->remise_absolue = $_facrec->remise_absolue; $this->remise_percent = $_facrec->remise_percent; - $this->remise = $_facrec->remise; + //$this->remise = $_facrec->remise; // Clean parametres if (! $this->type) $this->type = 0; $this->ref_client=trim($this->ref_client); $this->note=trim($this->note); $this->note_public=trim($this->note_public); - if (! $this->remise) $this->remise = 0; + //if (! $this->remise) $this->remise = 0; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; $this->brouillon = 1; } @@ -203,8 +204,8 @@ class Facture extends CommonObject // Insert into database $socid = $this->socid; - $amount = $this->amount; - $remise = $this->remise; + //$amount = $this->amount; + //$remise = $this->remise; $totalht = ($amount - $remise); @@ -214,7 +215,7 @@ class Facture extends CommonObject $sql.= ", type"; $sql.= ", fk_soc"; $sql.= ", datec"; - $sql.= ", amount"; + //$sql.= ", amount"; $sql.= ", remise_absolue"; $sql.= ", remise_percent"; $sql.= ", datef"; @@ -230,7 +231,7 @@ class Facture extends CommonObject $sql.= ", '".$this->type."'"; $sql.= ", '".$socid."'"; $sql.= ", '".$this->db->idate($now)."'"; - $sql.= ", '".$totalht."'"; + //$sql.= ", '".$totalht."'"; $sql.= ",".($this->remise_absolue>0?$this->remise_absolue:'NULL'); $sql.= ",".($this->remise_percent>0?$this->remise_percent:'NULL'); $sql.= ", '".$this->db->idate($this->date)."'"; @@ -484,7 +485,7 @@ class Facture extends CommonObject if ($invertdetail) { $facture->lines[$i]->subprice = -$facture->lines[$i]->subprice; - $facture->lines[$i]->price = -$facture->lines[$i]->price; + //$facture->lines[$i]->price = -$facture->lines[$i]->price; $facture->lines[$i]->total_ht = -$facture->lines[$i]->total_ht; $facture->lines[$i]->total_tva = -$facture->lines[$i]->total_tva; $facture->lines[$i]->total_localtax1 = -$facture->lines[$i]->total_localtax1; @@ -619,7 +620,7 @@ class Facture extends CommonObject $line->libelle = $object->lines[$i]->libelle; $line->desc = $object->lines[$i]->desc; - $line->price = $object->lines[$i]->price; + //$line->price = $object->lines[$i]->price; $line->subprice = $object->lines[$i]->subprice; $line->total_ht = $object->lines[$i]->total_ht; $line->total_tva = $object->lines[$i]->total_tva; @@ -774,7 +775,7 @@ class Facture extends CommonObject $this->amount = $obj->amount; $this->remise_percent = $obj->remise_percent; $this->remise_absolue = $obj->remise_absolue; - $this->remise = $obj->remise; + //$this->remise = $obj->remise; $this->total_ht = $obj->total; $this->total_tva = $obj->tva; $this->total_localtax1 = $obj->localtax1; @@ -897,8 +898,8 @@ class Facture extends CommonObject $line->fk_parent_line = $objp->fk_parent_line; // Ne plus utiliser - $line->price = $objp->price; - $line->remise = $objp->remise; + //$line->price = $objp->price; + //$line->remise = $objp->remise; $this->lines[$i] = $line; @@ -939,7 +940,7 @@ class Facture extends CommonObject if (isset($this->amount)) $this->amount=trim($this->amount); if (isset($this->remise_percent)) $this->remise_percent=trim($this->remise_percent); if (isset($this->remise_absolue)) $this->remise_absolue=trim($this->remise_absolue); - if (isset($this->remise)) $this->remise=trim($this->remise); + //if (isset($this->remise)) $this->remise=trim($this->remise); if (isset($this->close_code)) $this->close_code=trim($this->close_code); if (isset($this->close_note)) $this->close_note=trim($this->close_note); if (isset($this->total_tva)) $this->tva=trim($this->total_tva); @@ -977,7 +978,7 @@ class Facture extends CommonObject $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; $sql.= " remise_percent=".(isset($this->remise_percent)?$this->remise_percent:"null").","; $sql.= " remise_absolue=".(isset($this->remise_absolue)?$this->remise_absolue:"null").","; - $sql.= " remise=".(isset($this->remise)?$this->remise:"null").","; + //$sql.= " remise=".(isset($this->remise)?$this->remise:"null").","; $sql.= " close_code=".(isset($this->close_code)?"'".$this->db->escape($this->close_code)."'":"null").","; $sql.= " close_note=".(isset($this->close_note)?"'".$this->db->escape($this->close_note)."'":"null").","; $sql.= " tva=".(isset($this->total_tva)?$this->total_tva:"null").","; @@ -1078,8 +1079,8 @@ class Facture extends CommonObject $facligne->info_bits=2; // Ne plus utiliser - $facligne->price=-$remise->amount_ht; - $facligne->remise=0; + //$facligne->price=-$remise->amount_ht; + //$facligne->remise=0; $facligne->total_ht = -$remise->amount_ht; $facligne->total_tva = -$remise->amount_tva; @@ -2037,8 +2038,8 @@ class Facture extends CommonObject $this->line->skip_update_total = $skip_update_total; // A ne plus utiliser - $this->line->price=$price; - $this->line->remise=$remise; + //$this->line->price=$price; + //$this->line->remise=$remise; $result=$this->line->update(); if ($result > 0) @@ -3112,42 +3113,61 @@ class Facture extends CommonObject $line->desc=$langs->trans("Description")." ".$xnbp; $line->qty=1; $line->subprice=100; - $line->price=100; + //$line->price=100; $line->tva_tx=19.6; $line->localtax1_tx=0; $line->localtax2_tx=0; - if ($xnbp == 2) + $line->remise_percent=0; + if ($xnbp == 1) // Qty is negative (product line) { + $prodid = rand(1, $num_prods); + $line->fk_product=$prodids[$prodid]; + $line->qty=-1; + $line->total_ht=-100; + $line->total_ttc=-119.6; + $line->total_tva=-19.6; + } + else if ($xnbp == 2) // UP is negative (free line) + { + $line->subprice=-100; + $line->total_ht=-100; + $line->total_ttc=-119.6; + $line->total_tva=-19.6; + $line->remise_percent=0; + } + else if ($xnbp == 3) // Discount is 50% (product line) + { + $prodid = rand(1, $num_prods); + $line->fk_product=$prodids[$prodid]; $line->total_ht=50; $line->total_ttc=59.8; $line->total_tva=9.8; - $line->remise_percent=50; + $line->remise_percent=50; } - else + else // (product line) { + $prodid = rand(1, $num_prods); + $line->fk_product=$prodids[$prodid]; $line->total_ht=100; $line->total_ttc=119.6; $line->total_tva=19.6; $line->remise_percent=00; } - $prodid = rand(1, $num_prods); - $line->fk_product=$prodids[$prodid]; $this->lines[$xnbp]=$line; + $xnbp++; - $this->total_ht += $line->total_ht; + $this->total_ht += $line->total_ht; $this->total_tva += $line->total_tva; $this->total_ttc += $line->total_ttc; - - $xnbp++; } // Add a line "offered" $line=new FactureLigne($this->db); - $line->desc=$langs->trans("Description")." ".$xnbp; + $line->desc=$langs->trans("Description")." (offered line)"; $line->qty=1; $line->subprice=100; - $line->price=100; + //$line->price=100; $line->tva_tx=19.6; $line->localtax1_tx=0; $line->localtax2_tx=0; @@ -3159,8 +3179,7 @@ class Facture extends CommonObject $line->fk_product=$prodids[$prodid]; $this->lines[$xnbp]=$line; - - $xnbp++; + $xnbp++; } /** @@ -3277,7 +3296,7 @@ class Facture extends CommonObject /** * \class FactureLigne * \brief Classe permettant la gestion des lignes de factures - * \remarks Gere des lignes de la table llx_facturedet + * Gere des lignes de la table llx_facturedet */ class FactureLigne { @@ -3334,8 +3353,8 @@ class FactureLigne var $date_end; // Ne plus utiliser - var $price; // P.U. HT apres remise % de ligne (exemple 80) - var $remise; // Montant calcule de la remise % sur PU HT (exemple 20) + //var $price; // P.U. HT apres remise % de ligne (exemple 80) + //var $remise; // Montant calcule de la remise % sur PU HT (exemple 20) // From llx_product var $ref; // Product ref (deprecated) @@ -3348,17 +3367,19 @@ class FactureLigne /** - * \brief Constructeur d'objets ligne de facture - * \param DB handler d'acces base de donnee + * Constructeur d'objets ligne de facture + * + * @param DoliDB $db Database handler */ - function FactureLigne($DB) + function FactureLigne($db) { - $this->db= $DB ; + $this->db = $db; } /** - * \brief Recupere l'objet ligne de facture - * \param rowid id de la ligne de facture + * Recupere l'objet ligne de facture + * + * @param int $rowid id de la ligne de facture */ function fetch($rowid) { @@ -3403,8 +3424,8 @@ class FactureLigne $this->rang = $objp->rang; // Ne plus utiliser - $this->price = $objp->price; - $this->remise = $objp->remise; + //$this->price = $objp->price; + //$this->remise = $objp->remise; $this->ref = $objp->product_ref; // deprecated $this->product_ref = $objp->product_ref; @@ -3421,15 +3442,16 @@ class FactureLigne } /** - * \brief Insert line in database - * \param notrigger 1 no triggers - * \return int <0 if KO, >0 if OK + * Insert line in database + * + * @param int $notrigger 1 no triggers + * @return int <0 if KO, >0 if OK */ function insert($notrigger=0) { global $langs,$user,$conf; - dol_syslog("FactureLigne::Insert rang=".$this->rang, LOG_DEBUG); + dol_syslog(get_class($this)."::Insert rang=".$this->rang, LOG_DEBUG); // Clean parameters $this->desc=trim($this->desc); @@ -3439,11 +3461,11 @@ class FactureLigne if (empty($this->total_localtax1)) $this->total_localtax1=0; if (empty($this->total_localtax2)) $this->total_localtax2=0; if (empty($this->rang)) $this->rang=0; - if (empty($this->remise)) $this->remise=0; + //if (empty($this->remise)) $this->remise=0; if (empty($this->remise_percent)) $this->remise_percent=0; if (empty($this->info_bits)) $this->info_bits=0; if (empty($this->subprice)) $this->subprice=0; - if (empty($this->price)) $this->price=0; + //if (empty($this->price)) $this->price=0; if (empty($this->special_code)) $this->special_code=0; if (empty($this->fk_parent_line)) $this->fk_parent_line=0; @@ -3455,7 +3477,7 @@ class FactureLigne // Insertion dans base de la ligne $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet'; $sql.= ' (fk_facture, fk_parent_line, description, qty, tva_tx, localtax1_tx, localtax2_tx,'; - $sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,'; + $sql.= ' fk_product, product_type, remise_percent, subprice, fk_remise_except,'; $sql.= ' date_start, date_end, fk_code_ventilation, fk_export_compta, '; $sql.= ' rang, special_code,'; $sql.= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2)'; @@ -3471,8 +3493,8 @@ class FactureLigne $sql.= " ".$this->product_type.","; $sql.= " ".price2num($this->remise_percent).","; $sql.= " ".price2num($this->subprice).","; - $sql.= " ".price2num($this->price).","; - $sql.= " ".($this->remise?price2num($this->remise):'0').","; // Deprecated + //$sql.= " ".price2num($this->price).","; + //$sql.= " ".($this->remise?price2num($this->remise):'0').","; // Deprecated if ($this->fk_remise_except) $sql.= $this->fk_remise_except.","; else $sql.= 'null,'; if ($this->date_start) { $sql.= "'".$this->db->idate($this->date_start)."',"; } @@ -3491,7 +3513,7 @@ class FactureLigne $sql.= " ".price2num($this->total_localtax2); $sql.= ')'; - dol_syslog("FactureLigne::insert sql=".$sql); + dol_syslog(get_class($this)."::insert sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -3512,7 +3534,7 @@ class FactureLigne if ($discount->fk_facture) { $this->error=$langs->trans("ErrorDiscountAlreadyUsed",$discount->id); - dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR); $this->db->rollback(); return -3; } @@ -3522,7 +3544,7 @@ class FactureLigne if ($result < 0) { $this->error=$discount->error; - dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR); $this->db->rollback(); return -3; } @@ -3531,7 +3553,7 @@ class FactureLigne else { $this->error=$langs->trans("ErrorADiscountThatHasBeenRemovedIsIncluded"); - dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR); $this->db->rollback(); return -3; } @@ -3539,7 +3561,7 @@ class FactureLigne else { $this->error=$discount->error; - dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR); $this->db->rollback(); return -3; } @@ -3562,7 +3584,7 @@ class FactureLigne else { $this->error=$this->db->error(); - dol_syslog("FactureLigne::insert Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::insert Error ".$this->error, LOG_ERR); $this->db->rollback(); return -2; } @@ -3584,7 +3606,7 @@ class FactureLigne if (empty($this->localtax2_tx)) $this->localtax2_tx=0; if (empty($this->total_localtax1)) $this->total_localtax1=0; if (empty($this->total_localtax2)) $this->total_localtax2=0; - if (empty($this->remise)) $this->remise=0; + //if (empty($this->remise)) $this->remise=0; if (empty($this->remise_percent)) $this->remise_percent=0; if (empty($this->info_bits)) $this->info_bits=0; if (empty($this->product_type)) $this->product_type=0; @@ -3599,8 +3621,8 @@ class FactureLigne $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET"; $sql.= " description='".$this->db->escape($this->desc)."'"; $sql.= ",subprice=".price2num($this->subprice).""; - $sql.= ",price=".price2num($this->price).""; - $sql.= ",remise=".price2num($this->remise).""; + //$sql.= ",price=".price2num($this->price).""; + //$sql.= ",remise=".price2num($this->remise).""; $sql.= ",remise_percent=".price2num($this->remise_percent).""; if ($this->fk_remise_except) $sql.= ",fk_remise_except=".$this->fk_remise_except; else $sql.= ",fk_remise_except=null"; @@ -3653,7 +3675,8 @@ class FactureLigne /** * Delete line in database - * @return int <0 si ko, >0 si ok + * + * @return int <0 if KO, >0 if OK */ function delete() { @@ -3662,7 +3685,7 @@ class FactureLigne $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid; - dol_syslog("FactureLigne::delete sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::delete sql=".$sql, LOG_DEBUG); if ($this->db->query($sql) ) { // Appel des triggers @@ -3679,20 +3702,21 @@ class FactureLigne else { $this->error=$this->db->error()." sql=".$sql; - dol_syslog("FactureLigne::delete Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::delete Error ".$this->error, LOG_ERR); $this->db->rollback(); return -1; } } /** - * \brief Mise a jour en base des champs total_xxx de ligne de facture - * \return int <0 si ko, >0 si ok + * Mise a jour en base des champs total_xxx de ligne de facture + * + * @return int <0 if KO, >0 if OK */ function update_total() { $this->db->begin(); - dol_syslog("FactureLigne::update_total", LOG_DEBUG); + dol_syslog(get_class($this)."::update_total", LOG_DEBUG); // Clean parameters if (empty($this->total_localtax1)) $this->total_localtax1=0; @@ -3718,7 +3742,7 @@ class FactureLigne else { $this->error=$this->db->error(); - dol_syslog("FactureLigne::update_total Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::update_total Error ".$this->error, LOG_ERR); $this->db->rollback(); return -2; }