From ce6f8a1c819b0a1daf7ffa987ffcfa8906645736 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Jan 2009 20:56:14 +0000 Subject: [PATCH] Change to uniformize code of PDF generators --- htdocs/commande/commande.class.php | 15 ++- htdocs/expedition/expedition.class.php | 122 +++++++++--------- htdocs/expedition/fiche.php | 27 ++-- .../pdf/pdf_expedition_merou.modules.php | 44 +++---- .../pdf/pdf_expedition_rouget.modules.php | 2 - htdocs/langs/en_US/errors.lang | 1 + htdocs/langs/fr_FR/errors.lang | 1 + htdocs/lib/functions.lib.php | 11 +- htdocs/product.class.php | 5 +- htdocs/product/sousproduits/fiche.php | 8 +- 10 files changed, 123 insertions(+), 113 deletions(-) diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 0bdb9ab488b..8e6bf2b10b1 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -785,7 +785,7 @@ class Commande extends CommonObject $this->lines[] = $line; /** POUR AJOUTER AUTOMATIQUEMENT LES SOUSPRODUITS a LA COMMANDE - if($conf->global->PRODUIT_SOUSPRODUITS == 1) + if (! empty($conf->global->PRODUIT_SOUSPRODUITS)) { $prod = new Product($this->db, $idproduct); $prod -> get_sousproduits_arbo (); @@ -990,9 +990,9 @@ class Commande extends CommonObject /** - * \brief Reinitialise le tableau lignes - * \param only_product Ne renvoie que ligne liees a des produits physiques predefinis - * \return array Tableau de CommandeLigne + * \brief Reinitialize array lignes + * \param only_product Return only physical products + * \return array Array of CommandeLigne */ function fetch_lines($only_product=0) { @@ -1008,7 +1008,7 @@ class Commande extends CommonObject $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)'; $sql.= ' WHERE l.fk_commande = '.$this->id; - if ($only_product==1) $sql .= ' AND p.fk_product_type = 0'; + if ($only_product) $sql .= ' AND p.fk_product_type = 0'; $sql .= ' ORDER BY l.rang'; dolibarr_syslog("Commande::fetch_lines sql=".$sql,LOG_DEBUG); @@ -1023,8 +1023,8 @@ class Commande extends CommonObject $objp = $this->db->fetch_object($result); $ligne = new CommandeLigne($this->db); - $ligne->rowid = $objp->rowid; - $ligne->id = $objp->rowid; // \deprecated + $ligne->rowid = $objp->rowid; // \deprecated + $ligne->id = $objp->rowid; $ligne->fk_commande = $objp->fk_commande; $ligne->commande_id = $objp->fk_commande; // \deprecated $ligne->desc = $objp->description; // Description ligne @@ -1057,6 +1057,7 @@ class Commande extends CommonObject $i++; } $this->db->free($result); + return 1; } else diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index 1842b66e1e7..613a2d7407a 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -90,12 +90,12 @@ class Expedition extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (ref, date_creation, fk_user_author, date_expedition,"; - $sql.= " fk_soc, fk_expedition_methode, tracking_number, weight, size, width, height, weight_units, size_units"; - $sql.= ")"; - $sql.= " VALUES ('(PROV)', now(), $user->id, ".$this->db->idate($this->date_expedition); - $sql.= ", ".$this->socid.",'". $this->expedition_method_id."','". $this->tracking_number."',".$this->weight.",".$this->sizeS.",".$this->sizeW.",".$this->sizeH.",".$this->weight_units.",".$this->size_units; - $sql.= ")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition (ref, date_creation, fk_user_author, date_expedition,"; + $sql.= " fk_soc, fk_expedition_methode, tracking_number, weight, size, width, height, weight_units, size_units"; + $sql.= ")"; + $sql.= " VALUES ('(PROV)', now(), $user->id, ".$this->db->idate($this->date_expedition); + $sql.= ", ".$this->socid.",'". $this->expedition_method_id."','". $this->tracking_number."',".$this->weight.",".$this->sizeS.",".$this->sizeW.",".$this->sizeH.",".$this->weight_units.",".$this->size_units; + $sql.= ")"; $resql=$this->db->query($sql); if ($resql) @@ -232,76 +232,76 @@ class Expedition extends CommonObject if ($conf->livraison_bon->enabled) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON e.rowid = l.fk_expedition"; $sql.= " WHERE e.rowid = ".$id; + dolibarr_syslog("Expedition::fetch sql=".$sql); $result = $this->db->query($sql) ; - if ($result) { if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); + { + $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; - $this->ref = $obj->ref; - $this->socid = $obj->socid; - $this->statut = $obj->fk_statut; - $this->origin_id = $obj->origin_id; - $this->livraison_id = $obj->livraison_id; - $this->user_author_id = $obj->fk_user_author; - $this->date = $obj->date_expedition; - $this->adresse_livraison_id = $obj->fk_adresse_livraison; - $this->modelpdf = $obj->model_pdf; - $this->expedition_method_id = $obj->fk_expedition_methode; - $this->tracking_number = $obj->tracking_number; + $this->id = $obj->rowid; + $this->ref = $obj->ref; + $this->socid = $obj->socid; + $this->statut = $obj->fk_statut; + $this->origin_id = $obj->origin_id; + $this->livraison_id = $obj->livraison_id; + $this->user_author_id = $obj->fk_user_author; + $this->date = $obj->date_expedition; + $this->adresse_livraison_id = $obj->fk_adresse_livraison; + $this->modelpdf = $obj->model_pdf; + $this->expedition_method_id = $obj->fk_expedition_methode; + $this->tracking_number = $obj->tracking_number; - $this->trueWeight = $obj->weight; - $this->weight_units = $obj->weight_units; + $this->trueWeight = $obj->weight; + $this->weight_units = $obj->weight_units; - $this->trueWidth = $obj->width; - $this->width_units = $obj->size_units; - $this->trueHeight = $obj->height; - $this->height_units = $obj->size_units; - $this->trueDepth = $obj->size; - $this->depth_units = $obj->size_units; + $this->trueWidth = $obj->width; + $this->width_units = $obj->size_units; + $this->trueHeight = $obj->height; + $this->height_units = $obj->size_units; + $this->trueDepth = $obj->size; + $this->depth_units = $obj->size_units; - // A denormalized value - $this->trueSize = $obj->size."x".$obj->width."x".$obj->height; - $this->size_units = $obj->size_units; + // A denormalized value + $this->trueSize = $obj->size."x".$obj->width."x".$obj->height; + $this->size_units = $obj->size_units; - if ($conf->commande->enabled) - { - $this->origin = "commande"; - } - else - { - $this->origin = "propal"; - } + if ($conf->commande->enabled) + { + $this->origin = "commande"; + } + else + { + $this->origin = "propal"; + } - $this->db->free($result); + $this->db->free($result); - if ($this->statut == 0) $this->brouillon = 1; + if ($this->statut == 0) $this->brouillon = 1; - $this->lignes = array(); + $this->lignes = array(); - $file = $conf->expedition->dir_output . "/" .get_exdir($expedition->id,2) . "/" . $this->id.".pdf"; - $this->pdf_filename = $file; + $file = $conf->expedition->dir_output . "/" .get_exdir($expedition->id,2) . "/" . $this->id.".pdf"; + $this->pdf_filename = $file; - /* - * Lignes - */ - $result=$this->fetch_lines(); - if ($result < 0) - { - return -3; - } + /* + * Lignes + */ + $result=$this->fetch_lines(); + if ($result < 0) + { + return -3; + } - return 1; - } - else - { - dolibarr_syslog('Expedition::Fetch Error rowid='.$rowid.' numrows=0 sql='.$sql); - $this->error='Delivery with id '.$rowid.' not found sql='.$sql; - return -2; - } + return 1; + } + else + { + dolibarr_syslog('Expedition::Fetch Error rowid='.$rowid.' numrows=0 sql='.$sql); + $this->error='Delivery with id '.$rowid.' not found sql='.$sql; + return -2; + } } else { diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 6fd4b54c7d2..4832d053e1b 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2008 Laurent Destailleur + * Copyright (C) 2005-2009 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER * Copyright (C) 2005-2008 Regis Houssin * @@ -295,7 +295,7 @@ if ($_GET["action"] == 'create') { print ''.$langs->trans("NotePrivate").': '.nl2br($object->note).""; } - + print ''; print $langs->trans("Weight"); print ''; @@ -325,9 +325,9 @@ if ($_GET["action"] == 'create') print ''; print ''; print "\n"; - + print ""; - + /* * Lignes de commandes * @@ -370,7 +370,7 @@ if ($_GET["action"] == 'create') $ligne = $object->lignes[$indiceAsked]; $var=!$var; print "\n"; - + // Desc if ($ligne->fk_product > 0) { @@ -474,7 +474,7 @@ if ($_GET["action"] == 'create') print "\n"; // Show subproducts of product - if ($ligne->fk_product > 0) + if (! empty($conf->global->PRODUIT_SOUSPRODUITS) && $ligne->fk_product > 0) { $product->get_sousproduits_arbo (); $prods_arbo = $product->get_arbo_each_prod($qtyProdCom); @@ -783,9 +783,16 @@ else if (! eregi('^(valid|delete)',$_REQUEST["action"])) { - if ($expedition->statut == 0 && $user->rights->expedition->valider && $num_prod > 0) + if ($expedition->statut == 0 && $num_prod > 0) { - print ''.$langs->trans("Validate").''; + if ($user->rights->expedition->valider) + { + print ''.$langs->trans("Validate").''; + } + else + { + print ''.$langs->trans("Validate").''; + } } if ($conf->livraison_bon->enabled && $expedition->statut == 1 && $user->rights->expedition->livraison->creer && !$expedition->livraison_id) @@ -816,7 +823,7 @@ else $urlsource = $_SERVER["PHP_SELF"]."?id=".$expedition->id; - $genallowed=$user->rights->expedition->lire && ($expedition->statut > 0); + $genallowed=$user->rights->expedition->lire; $delallowed=$user->rights->expedition->supprimer; //$genallowed=1; //$delallowed=0; @@ -824,7 +831,7 @@ else $somethingshown=$formfile->show_documents('expedition',$expeditionref,$filedir,$urlsource,$genallowed,$delallowed,$expedition->modelpdf); if ($genallowed && ! $somethingshown) $somethingshown=1; } - + print ''; // Rien a droite diff --git a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php index de8cf155da1..493ff28ea73 100644 --- a/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php +++ b/htdocs/includes/modules/expedition/pdf/pdf_expedition_merou.modules.php @@ -195,37 +195,37 @@ Class pdf_expedition_merou extends ModelePdfExpedition $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs); //Recuperation des produits de la commande. - if ($this->expe->ref != 'SPECIMEN') $this->expe->commande->fetch_lines(1); - $Produits = $this->expe->commande->lignes; $nblignes = sizeof($Produits); - for ($i = 0 ; $i < $nblignes ; $i++){ - //Generation du produit - $Prod = new Product($this->db); - $Prod->fetch($Produits[$i]->fk_product); + for ($i = 0 ; $i < $nblignes ; $i++) + { + // Description de la ligne produit + $libelleproduitservice=pdf_getlinedesc($this->expe->commande->lignes[$i],$outputlangs); + //if ($i==1) { print $this->expe->commande->lignes[$i]->libelle.' - '.$libelleproduitservice; exit; } + //Creation des cases a cocher $pdf->rect(10+3, $curY+1, 3, 3); $pdf->rect(20+3, $curY+1, 3, 3); //Insertion de la reference du produit - $pdf->SetXY (30, $curY ); + $pdf->SetXY (30, $curY+1 ); $pdf->SetFont('Arial','B', 7); - $pdf->MultiCell(24, 5, $outputlangs->convToOutputCharset($Prod->ref), 0, 'L', 0); + $pdf->MultiCell(24, 3, $outputlangs->convToOutputCharset($this->expe->commande->lignes[$i]->ref), 0, 'L', 0); //Insertion du libelle $pdf->SetFont('Arial','', 7); - $pdf->SetXY (50, $curY ); - $pdf->MultiCell(90, 5, $outputlangs->convToOutputCharset($Prod->libelle), 0, 'L', 0); + $pdf->SetXY (50, $curY+1 ); + $pdf->writeHTMLCell(90, 3, 50, $curY+1, $outputlangs->convToOutputCharset($libelleproduitservice), 0, 'L', 0); //Insertion de la quantite commandee $pdf->SetFont('Arial','', 7); - $pdf->SetXY (140, $curY ); - $pdf->MultiCell(30, 5, $this->expe->lignes[$i]->qty_asked, 0, 'C', 0); + $pdf->SetXY (140, $curY+1 ); + $pdf->MultiCell(30, 3, $this->expe->lignes[$i]->qty_asked, 0, 'C', 0); //Insertion de la quantite a envoyer $pdf->SetFont('Arial','', 7); - $pdf->SetXY (170, $curY ); - $pdf->MultiCell(30, 5, $this->expe->lignes[$i]->qty_shipped, 0, 'C', 0); + $pdf->SetXY (170, $curY+1 ); + $pdf->MultiCell(30, 3, $this->expe->lignes[$i]->qty_shipped, 0, 'C', 0); //Generation de la page 2 - $curY += 4; + $curY += (dol_nboflines_bis($libelleproduitservice)*3+1); $nexY = $curY; if ($nexY > ($tab_top+$tab_height-10) && $i < $nblignes - 1) { @@ -233,7 +233,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition $this->_pagefoot($pdf, $outputlangs); $pdf->AliasNbPages(); - $nexY = $iniY; + $curY = $iniY; // New page $pdf->AddPage(); @@ -348,24 +348,24 @@ Class pdf_expedition_merou extends ModelePdfExpedition $pdf->MultiCell(100, 3, $langs->transnoentities("ErrorGoToModuleSetup"), 0, 'L'); } } - else $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($this->emetteur->nom), 0, 'L'); + else $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->nom), 0, 'L'); //*********************Entete**************************** //Nom du Document - $Xoff = 94; + $Xoff = 90; $Yoff = 0; $pdf->SetXY($Xoff,7); $pdf->SetFont('Arial','B',12); $pdf->SetTextColor(0,0,0); - $pdf->MultiCell(0, 8, $outputlangs->transnoentities("SendingSheet"), '' , 'L'); // Bordereau expedition + $pdf->MultiCell(0, 3, $outputlangs->transnoentities("SendingSheet"), '' , 'L'); // Bordereau expedition //Num Expedition $Yoff = $Yoff+7; - $Xoff = 160; + $Xoff = 154; // $pdf->rect($Xoff, $Yoff, 85, 8); $pdf->SetXY($Xoff,$Yoff); $pdf->SetFont('Arial','',8); $pdf->SetTextColor(0,0,0); - $pdf->MultiCell(0, 8, $outputlangs->transnoentities("RefSending").': '.$outputlangs->convToOutputCharset($exp->ref), '' , 'L'); + $pdf->MultiCell(0, 3, $outputlangs->transnoentities("RefSending").': '.$outputlangs->convToOutputCharset($exp->ref), '' , 'L'); //$this->Code39($Xoff+43, $Yoff+1, $this->expe->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true); //Num Commande $Yoff = $Yoff+4; @@ -373,7 +373,7 @@ Class pdf_expedition_merou extends ModelePdfExpedition $pdf->SetXY($Xoff,$Yoff); $pdf->SetFont('Arial','',8); $pdf->SetTextColor(0,0,0); - $pdf->MultiCell(0, 8, $outputlangs->transnoentities("RefOrder").': '.$outputlangs->convToOutputCharset($exp->commande->ref), '' , 'L'); + $pdf->MultiCell(0, 3, $outputlangs->transnoentities("RefOrder").': '.$outputlangs->convToOutputCharset($exp->commande->ref), '' , 'L'); //$this->Code39($Xoff+43, $Yoff+1, $exp->commande->ref,$ext = true, $cks = false, $w = 0.4, $h = 4, $wide = true); //Definition Emplacement du bloc Societe diff --git a/htdocs/includes/modules/expedition/pdf/pdf_expedition_rouget.modules.php b/htdocs/includes/modules/expedition/pdf/pdf_expedition_rouget.modules.php index ff01358b420..c605eb171be 100644 --- a/htdocs/includes/modules/expedition/pdf/pdf_expedition_rouget.modules.php +++ b/htdocs/includes/modules/expedition/pdf/pdf_expedition_rouget.modules.php @@ -216,8 +216,6 @@ Class pdf_expedition_rouget extends ModelePdfExpedition $curY = $this->tableau_top + 4; $pdf->writeHTMLCell(30, 3, 170, $curY, $outputlangs->trans("QtyToShip"), 0, 0); - if ($this->expe->ref != 'SPECIMEN') $this->expe->fetch_lines(); - for ($i = 0 ; $i < sizeof($this->expe->lignes) ; $i++) { $curY = $this->tableau_top + 14 + ($i * 7); diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index f388cfc2f34..064b0f73432 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -1,5 +1,6 @@ # Dolibarr language file - en_US - errors CHARSET=UTF-8 +MenuManager=Menu manager ErrorLoginAlreadyExists=Login %s already exists. ErrorGroupAlreadyExists=Group %s already exists. ErrorDuplicateTrigger=A trigger file with class nam '%s' is present sevaral times. Remove duplicate trigger file in directory '%s'. diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index c56c261db5d..debda9c2f2b 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -1,5 +1,6 @@ # Dolibarr language file - fr_FR - errors CHARSET=UTF-8 +MenuManager=Gestionnaire de menu ErrorLoginAlreadyExists=Le login %s existe déjà. ErrorGroupAlreadyExists=Le groupe %s existe déjà. ErrorDuplicateTrigger=Un fichier trigger de classe '%s' est present plusieurs fois. Supprimer le doublon du répertoire '%s'. diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index eda47b96a82..c0219af19b9 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1576,7 +1576,7 @@ function dol_print_error($db='',$error='') print $langs->trans("DolibarrHasDetectedError").".
\n"; if (! empty($conf->global->MAIN_FEATURES_LEVEL)) print "You use an experimental level of features, so please do NOT report any bugs, anywhere, until going back to MAIN_FEATURES_LEVEL = 0.
\n"; - print $langs->trans("InformationToHelpDiagnose").":

\n"; + print $langs->trans("InformationToHelpDiagnose").":
\n"; print "".$langs->trans("Dolibarr").": ".DOL_VERSION."
\n";; print "".$langs->trans("Date").": ".dolibarr_print_date(time(),'dayhourlog')."
\n";; @@ -1585,6 +1585,7 @@ function dol_print_error($db='',$error='') print "".$langs->trans("RequestedUrl").": ".$_SERVER["REQUEST_URI"]."
\n";; print "".$langs->trans("Referer").": ".$_SERVER["HTTP_REFERER"]."
\n";; print "".$langs->trans("MenuManager").": ".$conf->left_menu.'/'.$conf->top_menu."
\n"; + print "
\n"; $syslog.="url=".$_SERVER["REQUEST_URI"]; $syslog.=", query_string=".$_SERVER["QUERY_STRING"]; } @@ -2457,6 +2458,7 @@ function dol_nl2br($stringtoencode,$nl2brmode=0) /** * \brief This function is called to encode a string into a HTML string. All entities except <> are converted. + * This function also remove last CR/BR. * \param stringtoencode String to encode * \param nl2brmode 0=Adding br before \n, 1=Replacing \n by br (for use with FPDF writeHTMLCell function for example) * \remarks For PDF usage, you can show text by 2 ways: @@ -2470,9 +2472,10 @@ function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8') if (dol_textishtml($stringtoencode)) { //$trans = get_html_translation_table(HTML_ENTITIES, ENT_COMPAT); var_dump($trans); - $newstring=strtr($stringtoencode,array('<'=>'__lt__','>'=>'__gt__')); + $newstring=eregi_replace('" by "
". It's same and avoid pb with FPDF. + $newstring=eregi_replace('
$','',$newstring); // Replace "
" by "
". It's same and avoid pb with FPDF. + $newstring=strtr($newstring,array('<'=>'__lt__','>'=>'__gt__')); $newstring=@htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding - $newstring=eregi_replace('" by "
". It's same and avoid pb with FPDF. $newstring=strtr($newstring,array('__lt__'=>'<','__gt__'=>'>')); // If already HTML, CR should be
so we don't change \n } @@ -2572,7 +2575,7 @@ function dol_nboflines_bis($texte,$maxlinesize=0) $texte = strtr($texte, $repTable); $pattern = '/(<[^>]+>)/Uu'; $a = preg_split($pattern, $texte, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - $nblines = ((count($a)+1)/2); + $nblines = floor((count($a)+1)/2); // count possible auto line breaks if($maxlinesize) { diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 2141e08dece..478bcca51b7 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1993,12 +1993,13 @@ class Product extends CommonObject */ function get_sousproduits_arbo () { - $peres = $this -> get_pere(); foreach($peres as $k=>$v) { foreach($this -> get_fils_arbo($v[0]) as $kf=>$vf) - $peres[$k][$kf] = $vf; + { + $peres[$k][$kf] = $vf; + } } // on concat�ne tout �a foreach($peres as $k=>$v) diff --git a/htdocs/product/sousproduits/fiche.php b/htdocs/product/sousproduits/fiche.php index b665c14d731..0157565fbc4 100644 --- a/htdocs/product/sousproduits/fiche.php +++ b/htdocs/product/sousproduits/fiche.php @@ -145,8 +145,6 @@ dolibarr_fiche_head($head, 'subproduct', $titre); */ if ($id || $ref) { - - if ( $result ) { @@ -253,7 +251,7 @@ if ($id || $ref) print ''; print ''; print '
'; - + if($action == 'search') { print ''; @@ -314,7 +312,7 @@ if ($id || $ref) } $i++; } - + } else { @@ -325,7 +323,7 @@ if ($id || $ref) print ''; print '
'; } - + print ''; print ''; print '';