Change to uniformize code of PDF generators

This commit is contained in:
Laurent Destailleur 2009-01-29 20:56:14 +00:00
parent 5de23dcc59
commit ce6f8a1c81
10 changed files with 123 additions and 113 deletions

View File

@ -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

View File

@ -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
{

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
*
@ -295,7 +295,7 @@ if ($_GET["action"] == 'create')
{
print '<tr><td colspan="3">'.$langs->trans("NotePrivate").': '.nl2br($object->note)."</td></tr>";
}
print '<tr><td>';
print $langs->trans("Weight");
print '</td><td><input name="weight" size="4" value=""></td><td>';
@ -325,9 +325,9 @@ if ($_GET["action"] == 'create')
print '<td colspan="3">';
print '<input name="tracking_number" size="20">';
print "</td></tr>\n";
print "</table>";
/*
* Lignes de commandes
*
@ -370,7 +370,7 @@ if ($_GET["action"] == 'create')
$ligne = $object->lignes[$indiceAsked];
$var=!$var;
print "<tr ".$bc[$var].">\n";
// Desc
if ($ligne->fk_product > 0)
{
@ -474,7 +474,7 @@ if ($_GET["action"] == 'create')
print "</tr>\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 '<a class="butAction" href="fiche.php?id='.$expedition->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
if ($user->rights->expedition->valider)
{
print '<a class="butAction" href="fiche.php?id='.$expedition->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
}
}
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 '</td><td valign="top" width="50%">';
// Rien a droite

View File

@ -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

View File

@ -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);

View File

@ -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 '<b>%s</b>' is present sevaral times. Remove duplicate trigger file in directory '<b>%s</b>'.

View File

@ -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 '<b>%s</b>' est present plusieurs fois. Supprimer le doublon du répertoire '<b>%s</b>'.

View File

@ -1576,7 +1576,7 @@ function dol_print_error($db='',$error='')
print $langs->trans("DolibarrHasDetectedError").".<br>\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.<br>\n";
print $langs->trans("InformationToHelpDiagnose").":<br><br>\n";
print $langs->trans("InformationToHelpDiagnose").":<br>\n";
print "<b>".$langs->trans("Dolibarr").":</b> ".DOL_VERSION."<br>\n";;
print "<b>".$langs->trans("Date").":</b> ".dolibarr_print_date(time(),'dayhourlog')."<br>\n";;
@ -1585,6 +1585,7 @@ function dol_print_error($db='',$error='')
print "<b>".$langs->trans("RequestedUrl").":</b> ".$_SERVER["REQUEST_URI"]."<br>\n";;
print "<b>".$langs->trans("Referer").":</b> ".$_SERVER["HTTP_REFERER"]."<br>\n";;
print "<b>".$langs->trans("MenuManager").":</b> ".$conf->left_menu.'/'.$conf->top_menu."<br>\n";
print "<br>\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('<br( [ a-zA-Z_="]*)?/?>','<br>',$stringtoencode); // Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
$newstring=eregi_replace('<br>$','',$newstring); // Replace "<br type="_moz" />" by "<br>". 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('<br( [ a-zA-Z_="]*)?/?>','<br>',$newstring); // Replace "<br type="_moz" />" by "<br>". It's same and avoid pb with FPDF.
$newstring=strtr($newstring,array('__lt__'=>'<','__gt__'=>'>'));
// If already HTML, CR should be <br> 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)
{

View File

@ -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<61>ne tout <20>a
foreach($peres as $k=>$v)

View File

@ -145,8 +145,6 @@ dolibarr_fiche_head($head, 'subproduct', $titre);
*/
if ($id || $ref)
{
if ( $result )
{
@ -253,7 +251,7 @@ if ($id || $ref)
print '<tr><td colspan="2"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td></tr>';
print '</form>';
print '<tr><td colspan="2"><br>';
if($action == 'search')
{
print '<table class="border">';
@ -314,7 +312,7 @@ if ($id || $ref)
}
$i++;
}
}
else
{
@ -325,7 +323,7 @@ if ($id || $ref)
print '<tr><td colspan="2"><input type="submit" class="button" value="'.$langs->trans("Update").'"></td></tr>';
print '</table>';
}
print '</form></td></tr>';
print '</td></tr>';
print '</table>';