diff --git a/htdocs/admin/fournisseur.php b/htdocs/admin/fournisseur.php index de552514a93..609e028728a 100644 --- a/htdocs/admin/fournisseur.php +++ b/htdocs/admin/fournisseur.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2007 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2006 Regis Houssin @@ -31,6 +31,7 @@ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT.'/fourn/fournisseur.commande.class.php'); $langs->load("admin"); $langs->load("bills"); @@ -41,10 +42,37 @@ if (!$user->admin) accessforbidden(); - /* * Actions */ +if ($_GET["action"] == 'specimen') +{ + $modele=$_GET["module"]; + + $facture = new CommandeFournisseur($db); + $facture->initAsSpecimen(); + + // Charge le modele + $dir = DOL_DOCUMENT_ROOT . "/fourn/commande/modules/pdf/"; + $file = "pdf_".$modele.".modules.php"; + if (file_exists($dir.$file)) + { + $classname = "pdf_".$modele; + require_once($dir.$file); + + $obj = new $classname($db); + + if ($obj->write_pdf_file($facture,$langs) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande_fournisseur&file=SPECIMEN.pdf"); + return; + } + } + else + { + $mesg='
'.$langs->trans("ErrorModuleNotFound").'
'; + } +} if ($_GET["action"] == 'set') { diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 89b8d1e63ac..d1fff65736b 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -2120,6 +2120,8 @@ class Commande extends CommonObject { global $user,$langs; + dolibarr_syslog("Commande::initAsSpecimen"); + // Charge tableau des id de société socids $socids = array(); $sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10"; @@ -2194,244 +2196,243 @@ class Commande extends CommonObject * \class CommandeLigne * \brief Classe de gestion des lignes de commande */ - class CommandeLigne { - var $db; - var $error; - - // From llx_commandedet - var $rowid; - var $fk_facture; - var $desc; // Description ligne - var $fk_product; // Id produit prédéfini + var $db; + var $error; - var $qty; - var $tva_tx; - var $subprice; - var $remise_percent; - var $rang = 0; - var $coef; - var $info_bits = 0; // Bit 0: 0 si TVA normal - 1 si TVA NPR - // Bit 1: 0 ligne normale - 1 si ligne de remise fixe - var $total_ht; // Total HT de la ligne toute quantité et incluant la remise ligne - var $total_tva; // Total TVA de la ligne toute quantité et incluant la remise ligne - var $total_ttc; // Total TTC de la ligne toute quantité et incluant la remise ligne - - // Ne plus utiliser - var $remise; - var $price; - - // From llx_product - var $ref; // Reference produit - var $product_libelle; // Label produit - var $product_desc; // Description produit - - - /** - * \brief Constructeur d'objets ligne de commande - * \param DB handler d'accès base de donnée - */ - function CommandeLigne($DB) - { - $this->db= $DB ; - } + // From llx_commandedet + var $rowid; + var $fk_facture; + var $desc; // Description ligne + var $fk_product; // Id produit prédéfini - /** - * \brief Recupére l'objet ligne de commande - * \param rowid id de la ligne de commande - */ - function fetch($rowid) - { - $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.description, cd.price, cd.qty, cd.tva_tx,'; - $sql.= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice,'; - $sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc, cd.coef, cd.rang,'; - $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as cd'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid'; - $sql.= ' WHERE cd.rowid = '.$rowid; - $result = $this->db->query($sql); - if ($result) - { - $objp = $this->db->fetch_object($result); - $this->rowid = $objp->rowid; - $this->fk_propal = $objp->fk_propal; - $this->desc = $objp->description; - $this->qty = $objp->qty; - $this->price = $objp->price; - $this->subprice = $objp->subprice; - $this->tva_tx = $objp->tva_tx; - $this->remise = $objp->remise; - $this->remise_percent = $objp->remise_percent; - $this->fk_remise_except = $objp->fk_remise_except; - $this->produit_id = $objp->fk_product; - $this->info_bits = $objp->info_bits; - $this->total_ht = $objp->total_ht; - $this->total_tva = $objp->total_tva; - $this->total_ttc = $objp->total_ttc; - $this->coef = $objp->coef; - $this->rang = $objp->rang; - - $this->ref = $objp->product_ref; - $this->product_libelle = $objp->product_libelle; - $this->product_desc = $objp->product_desc; - - $this->db->free($result); - } - else - { - dolibarr_print_error($this->db); - } - } + var $qty; + var $tva_tx; + var $subprice; + var $remise_percent; + var $rang = 0; + var $coef; + var $info_bits = 0; // Bit 0: 0 si TVA normal - 1 si TVA NPR + // Bit 1: 0 ligne normale - 1 si ligne de remise fixe + var $total_ht; // Total HT de la ligne toute quantité et incluant la remise ligne + var $total_tva; // Total TVA de la ligne toute quantité et incluant la remise ligne + var $total_ttc; // Total TTC de la ligne toute quantité et incluant la remise ligne - /** - * \brief Supprime la ligne de commande en base - * \return int <0 si ko, 0 si ok - */ - function Delete() - { - global $langs, $conf, $user; + // Ne plus utiliser + var $remise; + var $price; - dolibarr_syslog("CommandeLigne::Delete id=".$this->id); + // From llx_product + var $ref; // Reference produit + var $product_libelle; // Label produit + var $product_desc; // Description produit - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid='".$this->id."';"; - if ($this->db->query($sql) ) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('LINEORDER_DELETE',$this,$user,$langs,$conf); - // Fin appel triggers - return 0; - } - else - { - dolibarr_syslog("CommandeLigne::Delete id=".$this->id." ERROR SQL $sql"); - return -1; - } - } + /** + * \brief Constructeur d'objets ligne de commande + * \param DB handler d'accès base de donnée + */ + function CommandeLigne($DB) + { + $this->db= $DB ; + } - /** - * \brief Insère l'objet ligne de commande en base - * \return int <0 si ko, >0 si ok - */ - function insert() - { - global $langs, $conf, $user; + /** + * \brief Recupére l'objet ligne de commande + * \param rowid id de la ligne de commande + */ + function fetch($rowid) + { + $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.description, cd.price, cd.qty, cd.tva_tx,'; + $sql.= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice,'; + $sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc, cd.coef, cd.rang,'; + $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as cd'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid'; + $sql.= ' WHERE cd.rowid = '.$rowid; + $result = $this->db->query($sql); + if ($result) + { + $objp = $this->db->fetch_object($result); + $this->rowid = $objp->rowid; + $this->fk_propal = $objp->fk_propal; + $this->desc = $objp->description; + $this->qty = $objp->qty; + $this->price = $objp->price; + $this->subprice = $objp->subprice; + $this->tva_tx = $objp->tva_tx; + $this->remise = $objp->remise; + $this->remise_percent = $objp->remise_percent; + $this->fk_remise_except = $objp->fk_remise_except; + $this->produit_id = $objp->fk_product; + $this->info_bits = $objp->info_bits; + $this->total_ht = $objp->total_ht; + $this->total_tva = $objp->total_tva; + $this->total_ttc = $objp->total_ttc; + $this->coef = $objp->coef; + $this->rang = $objp->rang; + + $this->ref = $objp->product_ref; + $this->product_libelle = $objp->product_libelle; + $this->product_desc = $objp->product_desc; + + $this->db->free($result); + } + else + { + dolibarr_print_error($this->db); + } + } - dolibarr_syslog("CommandeLigne.class::insert rang=".$this->rang); - $this->db->begin(); - - $rangtouse=$this->rang; - if ($rangtouse == -1) - { - // Récupère rang max de la commande dans $rangmax - $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'commandedet'; - $sql.= ' WHERE fk_commande ='.$this->fk_commande; - $resql = $this->db->query($sql); - if ($resql) - { - $obj = $this->db->fetch_object($resql); - $rangtouse = $obj->max + 1; - } - else - { - dolibarr_print_error($this->db); - $this->db->rollback(); - return -1; - } - } - - // Insertion dans base de la ligne - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet'; - $sql.= ' (fk_commande, description, price, qty, tva_tx,'; - $sql.= ' fk_product, remise_percent, subprice, remise, fk_remise_except, '; - $sql.= ' rang, coef,'; - $sql.= ' info_bits, total_ht, total_tva, total_ttc)'; - $sql.= " VALUES (".$this->fk_commande.","; - $sql.= " '".addslashes($this->desc)."',"; - $sql.= " '".price2num($this->price)."',"; - $sql.= " '".price2num($this->qty)."',"; - $sql.= " '".price2num($this->tva_tx)."',"; - if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; } - else { $sql.='null,'; } - $sql.= " '".price2num($this->remise_percent)."',"; - $sql.= " '".price2num($this->subprice)."',"; - $sql.= " '".price2num($this->remise)."',"; - if ($this->fk_remise_except) $sql.= $this->fk_remise_except.","; - else $sql.= 'null,'; - $sql.= ' '.$rangtouse.','; - if (isset($this->coef)) $sql.= ' '.$this->coef.','; - else $sql.= ' null,'; - $sql.= " '".$this->info_bits."',"; - $sql.= " '".price2num($this->total_ht)."',"; - $sql.= " '".price2num($this->total_tva)."',"; - $sql.= " '".price2num($this->total_ttc)."'"; - $sql.= ')'; - - dolibarr_syslog("CommandeLigne.class.php::insert sql=$sql"); - - if ($this->fk_product) - { - $product = new Product($this->db); - $product->id = $this->fk_product; - $product->ajust_stock_commande($this->qty, 0); - } + /** + * \brief Supprime la ligne de commande en base + * \return int <0 si ko, 0 si ok + */ + function Delete() + { + global $langs, $conf, $user; - $resql=$this->db->query($sql); - if ($resql) - { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('LINEORDER_INSERT',$this,$user,$langs,$conf); - // Fin appel triggers + dolibarr_syslog("CommandeLigne::Delete id=".$this->id); - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dolibarr_syslog("CommandeLigne.class.php::insert Error ".$this->error); - $this->db->rollback(); - return -2; - } - } - - - /** - * \brief Mise a jour de l'objet ligne de commande en base - * \return int <0 si ko, >0 si ok - */ - function update_total() - { - $this->db->begin(); - - // Mise a jour ligne en base - $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET"; - $sql.= " total_ht='".price2num($this->total_ht)."'"; - $sql.= ",total_tva='".price2num($this->total_tva)."'"; - $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; - $sql.= " WHERE rowid = ".$this->rowid; - - dolibarr_syslog("CommandeLigne.class.php::update_total sql=$sql"); - - $resql=$this->db->query($sql); - if ($resql) - { - $this->db->commit(); - return 1; - } - else - { - $this->error=$this->db->error(); - dolibarr_syslog("CommandeLigne.class.php::update_total Error ".$this->error); - $this->db->rollback(); - return -2; - } - } + $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commandedet WHERE rowid='".$this->id."';"; + if ($this->db->query($sql) ) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('LINEORDER_DELETE',$this,$user,$langs,$conf); + // Fin appel triggers + + return 0; + } + else + { + dolibarr_syslog("CommandeLigne::Delete id=".$this->id." ERROR SQL $sql"); + return -1; + } + } + + /** + * \brief Insère l'objet ligne de commande en base + * \return int <0 si ko, >0 si ok + */ + function insert() + { + global $langs, $conf, $user; + + dolibarr_syslog("CommandeLigne.class::insert rang=".$this->rang); + $this->db->begin(); + + $rangtouse=$this->rang; + if ($rangtouse == -1) + { + // Récupère rang max de la commande dans $rangmax + $sql = 'SELECT max(rang) as max FROM '.MAIN_DB_PREFIX.'commandedet'; + $sql.= ' WHERE fk_commande ='.$this->fk_commande; + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + $rangtouse = $obj->max + 1; + } + else + { + dolibarr_print_error($this->db); + $this->db->rollback(); + return -1; + } + } + + // Insertion dans base de la ligne + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet'; + $sql.= ' (fk_commande, description, price, qty, tva_tx,'; + $sql.= ' fk_product, remise_percent, subprice, remise, fk_remise_except, '; + $sql.= ' rang, coef,'; + $sql.= ' info_bits, total_ht, total_tva, total_ttc)'; + $sql.= " VALUES (".$this->fk_commande.","; + $sql.= " '".addslashes($this->desc)."',"; + $sql.= " '".price2num($this->price)."',"; + $sql.= " '".price2num($this->qty)."',"; + $sql.= " '".price2num($this->tva_tx)."',"; + if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; } + else { $sql.='null,'; } + $sql.= " '".price2num($this->remise_percent)."',"; + $sql.= " '".price2num($this->subprice)."',"; + $sql.= " '".price2num($this->remise)."',"; + if ($this->fk_remise_except) $sql.= $this->fk_remise_except.","; + else $sql.= 'null,'; + $sql.= ' '.$rangtouse.','; + if (isset($this->coef)) $sql.= ' '.$this->coef.','; + else $sql.= ' null,'; + $sql.= " '".$this->info_bits."',"; + $sql.= " '".price2num($this->total_ht)."',"; + $sql.= " '".price2num($this->total_tva)."',"; + $sql.= " '".price2num($this->total_ttc)."'"; + $sql.= ')'; + + dolibarr_syslog("CommandeLigne.class.php::insert sql=$sql"); + + if ($this->fk_product) + { + $product = new Product($this->db); + $product->id = $this->fk_product; + $product->ajust_stock_commande($this->qty, 0); + } + + $resql=$this->db->query($sql); + if ($resql) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('LINEORDER_INSERT',$this,$user,$langs,$conf); + // Fin appel triggers + + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("CommandeLigne.class.php::insert Error ".$this->error); + $this->db->rollback(); + return -2; + } + } + + + /** + * \brief Mise a jour de l'objet ligne de commande en base + * \return int <0 si ko, >0 si ok + */ + function update_total() + { + $this->db->begin(); + + // Mise a jour ligne en base + $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET"; + $sql.= " total_ht='".price2num($this->total_ht)."'"; + $sql.= ",total_tva='".price2num($this->total_tva)."'"; + $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; + $sql.= " WHERE rowid = ".$this->rowid; + + dolibarr_syslog("CommandeLigne.class.php::update_total sql=$sql"); + + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error(); + dolibarr_syslog("CommandeLigne.class.php::update_total Error ".$this->error); + $this->db->rollback(); + return -2; + } + } } ?> diff --git a/htdocs/fourn/commande/modules/pdf/pdf_muscadet.modules.php b/htdocs/fourn/commande/modules/pdf/pdf_muscadet.modules.php index 806cfc4a4c6..585eef02972 100644 --- a/htdocs/fourn/commande/modules/pdf/pdf_muscadet.modules.php +++ b/htdocs/fourn/commande/modules/pdf/pdf_muscadet.modules.php @@ -30,7 +30,7 @@ \version $Revision$ */ -require_once(DOL_DOCUMENT_ROOT ."/fourn/commande/modules/modules_commandefournisseur.php"); +require_once(DOL_DOCUMENT_ROOT."/fourn/commande/modules/modules_commandefournisseur.php"); require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.commande.class.php"); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); @@ -49,7 +49,10 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers */ function pdf_muscadet($db) { - global $conf,$langs; + global $conf,$langs,$mysoc; + + $langs->load("main"); + $langs->load("bills"); $this->db = $db; $this->name = "muscadet"; @@ -70,24 +73,14 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $this->option_modereg = 1; // Affiche mode règlement $this->option_condreg = 1; // Affiche conditions règlement $this->option_codeproduitservice = 1; // Affiche code produit-service + $this->option_multilang = 1; // Dispo en plusieurs langues + if (defined("FACTURE_TVAOPTION") && FACTURE_TVAOPTION == 'franchise') $this->franchise=1; - // Recupere code pays de l'emmetteur - $this->emetteur->code_pays=substr($langs->defaultlang,-2); // Par defaut, si on trouve pas - $sql = "SELECT code from ".MAIN_DB_PREFIX."c_pays"; - $sql .= " WHERE rowid = '".$conf->global->MAIN_INFO_SOCIETE_PAYS."'"; - $result=$this->db->query($sql); - if ($result) { - $obj = $this->db->fetch_object($result); - if ($obj->code) $this->emetteur->code_pays=$obj->code; - } - else { - dolibarr_print_error($this->db); - } - $this->db->free($result); - - $this->tva=array(); + // Recupere emmetteur + $this->emetteur=$mysoc; + if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'était pas défini // Defini position des colonnes $this->posxdesc=$this->marge_gauche+1; @@ -97,6 +90,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $this->posxdiscount=162; $this->postotalht=177; + $this->tva=array(); $this->atleastoneratenotnull=0; $this->atleastonediscount=0; } @@ -129,24 +123,42 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers \remarks MAIN_INFO_TVAINTRA \remarks MAIN_INFO_LOGO */ - function write_pdf_file($id) + function write_pdf_file($com,$outputlangs='') { global $user,$langs,$conf; - $langs->load("main"); - $langs->load("bills"); - $langs->load("products"); - $langs->load("orders"); + if (! is_object($outputlangs)) $outputlangs=$langs; + $outputlangs->load("main"); + $outputlangs->load("companies"); + $outputlangs->load("bills"); + $outputlangs->load("products"); + $outputlangs->load("orders"); + + $outputlangs->setPhpLang(); if ($conf->fournisseur->commande->dir_output) { - $com = new CommandeFournisseur($this->db); - $ret=$com->fetch($id); - $nblignes = sizeof($com->lignes); + // Définition de l'objet $com (pour compatibilite ascendante) + if (! is_object($com)) + { + $id = $com; + $com = new CommandeFournisseur($this->db); + $ret=$com->fetch($id); + } + $deja_regle = ""; - $comref = sanitize_string($com->ref); - $dir = $conf->fournisseur->commande->dir_output . "/" . $comref; - $file = $dir . "/" . $comref . ".pdf"; + // Définition de $dir et $file + if ($com->specimen) + { + $dir = $conf->fournisseur->commande->dir_output; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $comref = sanitize_string($com->ref); + $dir = $conf->fournisseur->commande->dir_output . "/" . $comref; + $file = $dir . "/" . $comref . ".pdf"; + } if (! file_exists($dir)) { @@ -160,6 +172,8 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers if (file_exists($dir)) { + $nblignes = sizeof($com->lignes); + // Initialisation document vierge $pdf=new FPDF('P','mm',$this->format); $pdf->Open(); @@ -168,7 +182,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->SetDrawColor(128,128,128); $pdf->SetTitle($com->ref); - $pdf->SetSubject($langs->trans("Bill")); + $pdf->SetSubject($outputlangs->transnoentities("Bill")); $pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetAuthor($user->fullname); @@ -184,12 +198,13 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers } } - $this->_pagehead($pdf, $com); + $this->_pagehead($pdf, $com, 1, $outputlangs); $pagenb = 1; $tab_top = 90; $tab_top_newpage = 50; $tab_height = 110; + $tab_height_newpage = 180; $iniY = $tab_top + 8; $curY = $tab_top + 8; @@ -215,7 +230,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $prodser->fetch($com->lignes[$i]->fk_product); if ($prodser->ref) { - $libelleproduitservice=$langs->trans("Product")." ".$prodser->ref." - ".$libelleproduitservice; + $libelleproduitservice=$outputlangs->transnoentities("Product")." ".$prodser->ref." - ".$libelleproduitservice; } // Ajoute description du produit @@ -231,7 +246,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers if ($com->lignes[$i]->date_start && $com->lignes[$i]->date_end) { // Affichage durée si il y en a une - $libelleproduitservice.="\n(".$langs->trans("From")." ".dolibarr_print_date($com->lignes[$i]->date_start)." ".$langs->trans("to")." ".dolibarr_print_date($com->lignes[$i]->date_end).")"; + $libelleproduitservice.="\n(".$outputlangs->transnoentities("From")." ".dolibarr_print_date($com->lignes[$i]->date_start)." ".$outputlangs->transnoentities("to")." ".dolibarr_print_date($com->lignes[$i]->date_end).")"; } $pdf->SetFont('Arial','', 9); // Dans boucle pour gérer multi-page @@ -281,7 +296,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers // Nouvelle page $pdf->AddPage(); $pagenb++; - $this->_pagehead($pdf, $com, 0); + $this->_pagehead($pdf, $com, 0, $outputlangs); $nexY = $tab_top_newpage + 8; $pdf->SetTextColor(0,0,0); @@ -292,18 +307,18 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers // Affiche cadre tableau if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $tab_height, $nexY); + $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); $bottomlasttab=$tab_top + $tab_height + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $tab_height, $nexY); + $this->_tableau($pdf, $tab_top_newpage, $tab_height, $nexY, $outputlangs); $bottomlasttab=$tab_top_newpage + $tab_height + 1; } $deja_regle = ""; - $posy=$this->_tableau_tot($pdf, $com, $deja_regle, $bottomlasttab); + $posy=$this->_tableau_tot($pdf, $com, $deja_regle, $bottomlasttab, $outputlangs); if ($deja_regle) { $this->_tableau_versements($pdf, $fac, $posy); @@ -317,8 +332,8 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->SetXY ($this->marge_gauche, 228); $pdf->SetTextColor(200,0,0); $pdf->SetFont('Arial','B',8); - $pdf->MultiCell(90, 3, $langs->trans("ErrorNoPaiementModeConfigured"),0,'L',0); - $pdf->MultiCell(90, 3, $langs->trans("ErrorCreateBankAccount"),0,'L',0); + $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0); + $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorCreateBankAccount"),0,'L',0); $pdf->SetTextColor(0,0,0); } @@ -414,7 +429,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers /* * Pied de page */ - $this->_pagefoot($pdf); + $this->_pagefoot($pdf, $outputlangs); $pdf->AliasNbPages(); $pdf->Close(); @@ -445,12 +460,8 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers * \param deja_regle Montant deja regle * \return y Position pour suite */ - function _tableau_tot(&$pdf, $com, $deja_regle, $posy) + function _tableau_tot(&$pdf, $com, $deja_regle, $posy, $outputlangs) { - global $langs; - $langs->load("main"); - $langs->load("bills"); - $tab2_top = $posy; $tab2_hl = 5; $tab2_height = $tab2_hl * 4; @@ -469,7 +480,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers // Total HT $pdf->SetFillColor(256,256,256); $pdf->SetXY ($col1x, $tab2_top + 0); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalHT"), 0, 'L', 1); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1); $pdf->SetXY ($col2x, $tab2_top + 0); $pdf->MultiCell($largcol2, $tab2_hl, price($com->total_ht +$com->remise), 0, 'R', 1); @@ -478,7 +489,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers if ($com->remise > 0) { $pdf->SetXY ($col1x, $tab2_top + $tab2_hl); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("GlobalDiscount"), 0, 'L', 1); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("GlobalDiscount"), 0, 'L', 1); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl); $pdf->MultiCell($largcol2, $tab2_hl, "-".$com->remise_percent."%", 0, 'R', 1); @@ -506,8 +517,8 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $index++; $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); - $tvacompl = ( (float)$tvakey < 0 ) ? " (".$langs->trans("NonPercuRecuperable").")" : '' ; - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalVAT").' '.abs($tvakey).'%'.$tvacompl, 0, 'L', 1); + $tvacompl = ( (float)$tvakey < 0 ) ? " (".$outputlangs->transnoentities("NonPercuRecuperable").")" : '' ; + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT").' '.abs($tvakey).'%'.$tvacompl, 0, 'L', 1); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval * abs((float)$tvakey) / 100 ), 0, 'R', 1); @@ -517,7 +528,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers { $index++; $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalVAT"), 0, 'L', 1); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($com->total_tva), 0, 'R', 1); @@ -529,7 +540,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); $pdf->SetTextColor(0,0,60); $pdf->SetFillColor(224,224,224); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("TotalTTC"), $useborder, 'L', 1); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($com->total_ttc), $useborder, 'R', 1); @@ -541,7 +552,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $index++; $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("AlreadyPayed"), 0, 'L', 0); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPayed"), 0, 'L', 0); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0); @@ -550,7 +561,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->SetTextColor(0,0,60); //$pdf->SetFont('Arial','B', 9); $pdf->SetXY ($col1x, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $langs->trans("RemainderToPay"), $useborder, 'L', 1); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1); $pdf->SetXY ($col2x, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($largcol2, $tab2_hl, price($com->total_ttc - $deja_regle), $useborder, 'R', 1); @@ -566,16 +577,14 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers * \brief Affiche la grille des lignes de propales * \param pdf objet PDF */ - function _tableau(&$pdf, $tab_top, $tab_height, $nexY) + function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs) { - global $langs,$conf; - $langs->load("main"); - $langs->load("bills"); + global $conf; // Montants exprimés en (en tab_top - 1) $pdf->SetTextColor(0,0,0); $pdf->SetFont('Arial','',8); - $titre = $langs->trans("AmountInCurrency",$langs->trans("Currency".$conf->monnaie)); + $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentities("Currency".$conf->monnaie)); $pdf->Text($this->page_largeur - $this->marge_droite - $pdf->GetStringWidth($titre), $tab_top-1, $titre); $pdf->SetDrawColor(128,128,128); @@ -588,25 +597,25 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->SetFont('Arial','',10); $pdf->SetXY ($this->posxdesc-1, $tab_top+2); - $pdf->MultiCell(108,2, $langs->trans("Designation"),'','L'); + $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L'); $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height); $pdf->SetXY ($this->posxtva-1, $tab_top+2); - $pdf->MultiCell(12,2, $langs->trans("VAT"),'','C'); + $pdf->MultiCell(12,2, $outputlangs->transnoentities("VAT"),'','C'); $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height); $pdf->SetXY ($this->posxup-1, $tab_top+2); - $pdf->MultiCell(18,2, $langs->trans("PriceUHT"),'','C'); + $pdf->MultiCell(18,2, $outputlangs->transnoentities("PriceUHT"),'','C'); $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height); $pdf->SetXY ($this->posxqty-1, $tab_top+2); - $pdf->MultiCell(11,2, $langs->trans("Qty"),'','C'); + $pdf->MultiCell(11,2, $outputlangs->transnoentities("Qty"),'','C'); $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height); if ($this->atleastonediscount) { $pdf->SetXY ($this->posxdiscount-1, $tab_top+2); - $pdf->MultiCell(16,2, $langs->trans("ReductionShort"),'','C'); + $pdf->MultiCell(16,2, $outputlangs->transnoentities("ReductionShort"),'','C'); } if ($this->atleastonediscount) @@ -614,7 +623,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height); } $pdf->SetXY ($this->postotalht-1, $tab_top+2); - $pdf->MultiCell(23,2, $langs->trans("TotalHT"),'','C'); + $pdf->MultiCell(23,2, $outputlangs->transnoentities("TotalHT"),'','C'); } @@ -624,14 +633,14 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers * \param fac objet propale * \param showadress 0=non, 1=oui */ - function _pagehead(&$pdf, $com, $showadress=1) + function _pagehead(&$pdf, $com, $showadress=1, $outputlangs) { global $langs,$conf,$mysoc; - $langs->load("main"); - $langs->load("bills"); - $langs->load("orders"); - $langs->load("companies"); + $outputlangs->load("main"); + $outputlangs->load("bills"); + $outputlangs->load("orders"); + $outputlangs->load("companies"); $pdf->SetTextColor(0,0,60); $pdf->SetFont('Arial','B',13); @@ -652,8 +661,8 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers { $pdf->SetTextColor(200,0,0); $pdf->SetFont('Arial','B',8); - $pdf->MultiCell(100, 3, $langs->trans("ErrorLogoFileNotFound",$logo), 0, 'L'); - $pdf->MultiCell(100, 3, $langs->trans("ErrorGoToModuleSetup"), 0, 'L'); + $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); + $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); } } else if(defined("MAIN_INFO_SOCIETE_NOM") && FAC_PDF_SOCIETE_NOM) @@ -664,13 +673,13 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->SetFont('Arial','B',13); $pdf->SetXY(100,$posy); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(100, 4, $langs->trans("Order")." ".$com->ref, '' , 'R'); + $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Order")." ".$com->ref, '' , 'R'); $pdf->SetFont('Arial','',12); $posy+=6; $pdf->SetXY(100,$posy); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(100, 4, $langs->trans("Date")." : " . dolibarr_print_date($com->date,"%d %b %Y"), '', 'R'); + $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Date")." : " . dolibarr_print_date($com->date,"%d %b %Y"), '', 'R'); if ($showadress) { @@ -680,7 +689,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->SetTextColor(0,0,0); $pdf->SetFont('Arial','',8); $pdf->SetXY($this->marge_gauche,$posy-5); - $pdf->MultiCell(66,5, $langs->trans("BillTo").":"); + $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillTo").":"); $pdf->SetXY($this->marge_gauche,$posy); @@ -705,17 +714,17 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers } $carac_emetteur .= "\n"; // Tel - if (defined("FAC_PDF_TEL") && FAC_PDF_TEL) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Phone").": ".FAC_PDF_TEL; - elseif ($mysoc->tel) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Phone").": ".$mysoc->tel; + if (defined("FAC_PDF_TEL") && FAC_PDF_TEL) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".FAC_PDF_TEL; + elseif ($mysoc->tel) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Phone").": ".$mysoc->tel; // Fax - if (defined("FAC_PDF_FAX") && FAC_PDF_FAX) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Fax").": ".FAC_PDF_FAX; - elseif ($mysoc->fax) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Fax").": ".$mysoc->fax; + if (defined("FAC_PDF_FAX") && FAC_PDF_FAX) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".FAC_PDF_FAX; + elseif ($mysoc->fax) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Fax").": ".$mysoc->fax; // EMail - if (defined("FAC_PDF_MEL") && FAC_PDF_MEL) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Email").": ".FAC_PDF_MEL; - elseif ($mysoc->email) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Email").": ".$mysoc->email; + if (defined("FAC_PDF_MEL") && FAC_PDF_MEL) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".FAC_PDF_MEL; + elseif ($mysoc->email) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Email").": ".$mysoc->email; // Web - if (defined("FAC_PDF_WWW") && FAC_PDF_WWW) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Web").": ".FAC_PDF_WWW; - elseif ($mysoc->url) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$langs->trans("Web").": ".$mysoc->url; + if (defined("FAC_PDF_WWW") && FAC_PDF_WWW) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".FAC_PDF_WWW; + elseif ($mysoc->url) $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Web").": ".$mysoc->url; $pdf->SetFont('Arial','',9); $pdf->SetXY($this->marge_gauche+2,$posy+8); @@ -726,7 +735,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers $pdf->SetTextColor(0,0,0); $pdf->SetFont('Arial','',8); $pdf->SetXY(102,$posy-5); - $pdf->MultiCell(80,5, $langs->trans("BillFrom").":"); + $pdf->MultiCell(80,5, $outputlangs->transnoentities("BillFrom").":"); // $client = new Societe($this->db); $client->fetch($com->socid); @@ -744,7 +753,7 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers // Caractéristiques client $carac_client=$com->client->adresse; $carac_client.="\n".$com->client->cp . " " . $com->client->ville."\n"; - if ($com->client->tva_intra) $carac_client.="\n".$langs->trans("VATIntraShort").': '.$com->client->tva_intra; + if ($com->client->tva_intra) $carac_client.="\n".$outputlangs->transnoentities("VATIntraShort").': '.$com->client->tva_intra; $pdf->SetFont('Arial','',9); $pdf->SetXY(102,$posy+8); $pdf->MultiCell(86,4, $carac_client); @@ -756,12 +765,9 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers * \brief Affiche le pied de page * \param pdf objet PDF */ - function _pagefoot(&$pdf) + function _pagefoot(&$pdf, $outputlangs) { - global $langs, $conf; - $langs->load("main"); - $langs->load("bills"); - $langs->load("companies"); + global $conf; $html=new Form($this->db); @@ -773,30 +779,30 @@ class pdf_muscadet extends ModelePDFCommandesSuppliers } if ($conf->global->MAIN_INFO_CAPITAL) { - $ligne1.=($ligne1?" - ":"").$langs->trans("CapitalOf",$conf->global->MAIN_INFO_CAPITAL)." ".$langs->trans("Currency".$conf->monnaie); + $ligne1.=($ligne1?" - ":"").$outputlangs->transnoentities("CapitalOf",$conf->global->MAIN_INFO_CAPITAL)." ".$outputlangs->transnoentities("Currency".$conf->monnaie); } if ($conf->global->MAIN_INFO_SIRET) { - $ligne1.=($ligne1?" - ":"").$langs->transcountry("ProfId2",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_SIRET; + $ligne1.=($ligne1?" - ":"").$outputlangs->transcountry("ProfId2",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_SIRET; } if ($conf->global->MAIN_INFO_SIREN && (! $conf->global->MAIN_INFO_SIRET || $this->emetteur->code_pays != 'FR')) { - $ligne1.=($ligne1?" - ":"").$langs->transcountry("ProfId1",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_SIREN; + $ligne1.=($ligne1?" - ":"").$outputlangs->transcountry("ProfId1",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_SIREN; } if ($conf->global->MAIN_INFO_APE) { - $ligne1.=($ligne1?" - ":"").$langs->transcountry("ProfId3",$this->emetteur->code_pays).": ".MAIN_INFO_APE; + $ligne1.=($ligne1?" - ":"").$outputlangs->transcountry("ProfId3",$this->emetteur->code_pays).": ".MAIN_INFO_APE; } // Deuxieme ligne d'info réglementaires $ligne2=""; if ($conf->global->MAIN_INFO_RCS) { - $ligne2.=($ligne2?" - ":"").$langs->transcountry("ProfId4",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_RCS; + $ligne2.=($ligne2?" - ":"").$outputlangs->transcountry("ProfId4",$this->emetteur->code_pays).": ".$conf->global->MAIN_INFO_RCS; } if ($conf->global->MAIN_INFO_TVAINTRA != '') { - $ligne2.=($ligne2?" - ":"").$langs->trans("VATIntraShort").": ".$conf->global->MAIN_INFO_TVAINTRA; + $ligne2.=($ligne2?" - ":"").$outputlangs->transnoentities("VATIntraShort").": ".$conf->global->MAIN_INFO_TVAINTRA; } $pdf->SetFont('Arial','',8); diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php index fb16c5e8e50..864f9101973 100644 --- a/htdocs/fourn/fournisseur.commande.class.php +++ b/htdocs/fourn/fournisseur.commande.class.php @@ -69,102 +69,103 @@ class CommandeFournisseur extends Commande /** * Lit une commande */ - function fetch($id) - { - $sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva,"; - $sql .= " ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.fk_methode_commande,"; - $sql .= " c.note, c.note_public,"; - $sql .= " cm.libelle as methode_commande"; - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande"; - $sql .= " WHERE c.rowid = ".$id; - - $resql = $this->db->query($sql) ; - if ($resql) - { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->socid = $obj->fk_soc; - $this->fourn_id = $obj->fk_soc; - $this->statut = $obj->fk_statut; - $this->user_author_id = $obj->fk_user_author; - $this->total_ht = $obj->total_ht; - $this->total_tva = $obj->tva; - $this->total_ttc = $obj->total_ttc; - $this->date_commande = $obj->date_commande; // date à laquelle la commande a été transmise - $this->date = $obj->date_creation; - $this->remise_percent = $obj->remise_percent; - $this->methode_commande_id = $obj->fk_methode_commande; - $this->methode_commande = $obj->methode_commande; - - $this->source = $obj->source; - $this->facturee = $obj->facture; - $this->projet_id = $obj->fk_projet; - $this->note = $obj->note; - $this->note_public = $obj->note_public; - - $this->db->free(); - - if ($this->statut == 0) $this->brouillon = 1; - - // export pdf ----------- - - $this->lignes = array(); - $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,'; - $sql.= ' p.label, p.description as product_desc, p.ref, p.rowid as prodid'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as l'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; - $sql.= ' WHERE l.fk_commande = '.$this->id; - $sql.= ' ORDER BY l.rowid'; - $result = $this->db->query($sql); - if ($result) - { - $num = $this->db->num_rows($result); - $i = 0; - - while ($i < $num) - { - $objp = $this->db->fetch_object($result); + function fetch($id) + { + $sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva,"; + $sql .= " ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.fk_methode_commande,"; + $sql .= " c.note, c.note_public,"; + $sql .= " cm.libelle as methode_commande"; + $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande"; + $sql .= " WHERE c.rowid = ".$id; - $ligne = new CommandeFournisseurLigne(); - - $ligne->desc = $objp->description; // Description ligne - $ligne->qty = $objp->qty; - $ligne->tva_tx = $objp->tva_tx; - $ligne->subprice = $objp->subprice; - $ligne->remise_percent = $objp->remise_percent; - $ligne->price = $objp->price; - $ligne->fk_product = $objp->fk_product; - - $ligne->libelle = $objp->label; // Label produit - $ligne->product_desc = $objp->product_desc; // Description produit - $ligne->ref = $objp->ref; + $resql = $this->db->query($sql) ; + if ($resql) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->socid = $obj->fk_soc; + $this->fourn_id = $obj->fk_soc; + $this->statut = $obj->fk_statut; + $this->user_author_id = $obj->fk_user_author; + $this->total_ht = $obj->total_ht; + $this->total_tva = $obj->tva; + $this->total_ttc = $obj->total_ttc; + $this->date_commande = $obj->date_commande; // date à laquelle la commande a été transmise + $this->date = $obj->date_creation; + $this->remise_percent = $obj->remise_percent; + $this->methode_commande_id = $obj->fk_methode_commande; + $this->methode_commande = $obj->methode_commande; + + $this->source = $obj->source; + $this->facturee = $obj->facture; + $this->projet_id = $obj->fk_projet; + $this->note = $obj->note; + $this->note_public = $obj->note_public; + + $this->db->free(); + + if ($this->statut == 0) $this->brouillon = 1; + + // export pdf ----------- + + $this->lignes = array(); + $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,'; + $sql.= ' p.label, p.description as product_desc, p.ref, p.rowid as prodid'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as l'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; + $sql.= ' WHERE l.fk_commande = '.$this->id; + $sql.= ' ORDER BY l.rowid'; + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + + while ($i < $num) + { + $objp = $this->db->fetch_object($result); + + $ligne = new CommandeFournisseurLigne(); + + $ligne->desc = $objp->description; // Description ligne + $ligne->qty = $objp->qty; + $ligne->tva_tx = $objp->tva_tx; + $ligne->subprice = $objp->subprice; + $ligne->remise_percent = $objp->remise_percent; + $ligne->price = $objp->price; + $ligne->fk_product = $objp->fk_product; + + $ligne->libelle = $objp->label; // Label produit + $ligne->product_desc = $objp->product_desc; // Description produit + $ligne->ref = $objp->ref; + + $this->lignes[$i] = $ligne; + //dolibarr_syslog("1 ".$ligne->desc); + //dolibarr_syslog("2 ".$ligne->product_desc); + $i++; + } + $this->db->free($result); + + return 0; + } + else + { + $this->error=$this->db->error()." sql=".$sql; + dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error); + return -1; + } + } + else + { + $this->error=$this->db->error()." sql=".$sql; + dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error); + return -1; + } + } - $this->lignes[$i] = $ligne; - //dolibarr_syslog("1 ".$ligne->desc); - //dolibarr_syslog("2 ".$ligne->product_desc); - $i++; - } - $this->db->free($result); - - return 0; - } - else - { - $this->error=$this->db->error()." sql=".$sql; - dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error); - return -1; - } - } - else - { - $this->error=$this->db->error()." sql=".$sql; - dolibarr_syslog("CommandeFournisseur::Fetch ".$this->error); - return -1; - } - } /** * \brief Insère ligne de log * \param user Utilisateur qui modifie la commande @@ -1278,8 +1279,89 @@ class CommandeFournisseur extends Commande } } + + /** + * \brief Initialise la commande avec valeurs fictives aléatoire + * Sert à générer une commande pour l'aperu des modèles ou demo + */ + function initAsSpecimen() + { + global $user,$langs; + + dolibarr_syslog("CommandeFournisseur::initAsSpecimen"); + + // Charge tableau des id de société socids + $socids = array(); + $sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE fournisseur=1 LIMIT 10"; + $resql = $this->db->query($sql); + if ($resql) + { + $num_socs = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_socs) + { + $i++; + + $row = $this->db->fetch_row($resql); + $socids[$i] = $row[0]; + } + } + + // Charge tableau des produits prodids + $prodids = array(); + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE envente=1"; + $resql = $this->db->query($sql); + if ($resql) + { + $num_prods = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_prods) + { + $i++; + $row = $this->db->fetch_row($resql); + $prodids[$i] = $row[0]; + } + } + + // Initialise paramètres + $this->id=0; + $this->ref = 'SPECIMEN'; + $this->specimen=1; + $socid = rand(1, $num_socs); + $this->socid = $socids[$socid]; + $this->date = time(); + $this->date_lim_reglement=$this->date+3600*24*30; + $this->cond_reglement_code = 'RECEP'; + $this->mode_reglement_code = 'CHQ'; + $this->note_public='SPECIMEN'; + $nbp = rand(1, 9); + $xnbp = 0; + while ($xnbp < $nbp) + { + $ligne=new CommandeFournisseurLigne($this->db); + $ligne->desc=$langs->trans("Description")." ".$xnbp; + $ligne->qty=1; + $ligne->subprice=100; + $ligne->price=100; + $ligne->tva_tx=19.6; + $prodid = rand(1, $num_prods); + $ligne->produit_id=$prodids[$prodid]; + $this->lignes[$xnbp]=$ligne; + $xnbp++; + } + + $this->amount_ht = $xnbp*100; + $this->total_ht = $xnbp*100; + $this->total_tva = $xnbp*19.6; + $this->total_ttc = $xnbp*119.6; + } } + +/** + * \class CommandeFournisseurLigne + * \brief Classe de gestion des lignes de commande + */ class CommandeFournisseurLigne extends CommandeLigne { // From llx_propaldet diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php index 66b0d4bb881..404f638f8a6 100644 --- a/htdocs/fourn/fournisseur.facture.class.php +++ b/htdocs/fourn/fournisseur.facture.class.php @@ -638,5 +638,79 @@ class FactureFournisseur extends Facture return $result; } + + /** + * \brief Initialise la facture avec valeurs fictives aléatoire + * Sert à générer une facture pour l'aperu des modèles ou demo + */ + function initAsSpecimen() + { + global $user,$langs; + + // Charge tableau des id de société socids + $socids = array(); + $sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE fournisseur=1 LIMIT 10"; + $resql = $this->db->query($sql); + if ($resql) + { + $num_socs = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_socs) + { + $i++; + + $row = $this->db->fetch_row($resql); + $socids[$i] = $row[0]; + } + } + + // Charge tableau des produits prodids + $prodids = array(); + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE envente=1"; + $resql = $this->db->query($sql); + if ($resql) + { + $num_prods = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_prods) + { + $i++; + $row = $this->db->fetch_row($resql); + $prodids[$i] = $row[0]; + } + } + + // Initialise paramètres + $this->id=0; + $this->ref = 'SPECIMEN'; + $this->specimen=1; + $socid = rand(1, $num_socs); + $this->socid = $socids[$socid]; + $this->date = time(); + $this->date_lim_reglement=$this->date+3600*24*30; + $this->cond_reglement_code = 'RECEP'; + $this->mode_reglement_code = 'CHQ'; + $this->note_public='SPECIMEN'; + $nbp = 5; + $xnbp = 0; + while ($xnbp < $nbp) + { + $ligne=new FactureLigne($this->db); + $ligne->desc=$langs->trans("Description")." ".$xnbp; + $ligne->qty=1; + $ligne->subprice=100; + $ligne->price=100; + $ligne->tva_tx=19.6; + $prodid = rand(1, $num_prods); + $ligne->produit_id=$prodids[$prodid]; + $this->lignes[$xnbp]=$ligne; + $xnbp++; + } + + $this->amount_ht = $xnbp*100; + $this->total_ht = $xnbp*100; + $this->total_tva = $xnbp*19.6; + $this->total_ttc = $xnbp*119.6; + } } ?> diff --git a/htdocs/includes/modules/commande/pdf_einstein.modules.php b/htdocs/includes/modules/commande/pdf_einstein.modules.php index 25435197bc4..9fcbdfaa8a0 100644 --- a/htdocs/includes/modules/commande/pdf_einstein.modules.php +++ b/htdocs/includes/modules/commande/pdf_einstein.modules.php @@ -52,6 +52,7 @@ class pdf_einstein extends ModelePDFCommandes $langs->load("main"); $langs->load("bills"); + $this->db = $db; $this->name = "einstein"; $this->description = $langs->trans('PDFEinsteinDescription'); @@ -139,7 +140,7 @@ class pdf_einstein extends ModelePDFCommandes { if (create_exdir($dir) < 0) { - $this->error=$outputlangs->transnoentities("ErrorCanNotCreateDir",$dir); + $this->error=$outputlangs->trans("ErrorCanNotCreateDir",$dir); return 0; } }