Advertisement
Guest User

extrafield

a guest
Aug 16th, 2018
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 39.90 KB | None | 0 0
  1. <?php
  2. /* Copyright (C) 2005      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3.  * Copyright (C) 2005-2012 Laurent Destailleur  <eldy@users.sourceforge.net>
  4.  * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
  5.  * Copyright (C) 2014-2015 Marcos García        <marcosgdf@gmail.com>
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19.  * or see http://www.gnu.org/
  20.  */
  21.  
  22. /**
  23.  *  \file       htdocs/core/modules/expedition/doc/pdf_rouget.modules.php
  24.  *  \ingroup    expedition
  25.  *  \brief      Fichier de la classe permettant de generer les bordereaux envoi au modele Rouget
  26.  */
  27.  
  28. require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  32.  
  33.  
  34. /**
  35.  *  Classe permettant de generer les borderaux envoi au modele Rouget
  36.  */
  37. class pdf_rouget_specif extends ModelePdfExpedition
  38. {
  39.     var $emetteur;  // Objet societe qui emet
  40.  
  41.  
  42.     /**
  43.      *  Constructor
  44.      *
  45.      *  @param  DoliDB  $db     Database handler
  46.      */
  47.     function __construct($db=0)
  48.     {
  49.         global $conf,$langs,$mysoc;
  50.  
  51.         $this->db = $db;
  52.         $this->name = "rouget specif";
  53.         $this->description = $langs->trans("DocumentModelStandardPDF");
  54.  
  55.         $this->type = 'pdf';
  56.         $formatarray=pdf_getFormat();
  57.         $this->page_largeur = $formatarray['width'];
  58.         $this->page_hauteur = $formatarray['height'];
  59.         $this->format = array($this->page_largeur,$this->page_hauteur);
  60.         $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
  61.         $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
  62.         $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
  63.         $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
  64.  
  65.         $this->option_logo = 1;
  66.  
  67.         // Get source company
  68.         $this->emetteur=$mysoc;
  69.         if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2);    // By default if not defined
  70.  
  71.         // Define position of columns
  72.         $this->posxdesc=$this->marge_gauche+1;
  73.         $this->posxweightvol=$this->page_largeur - $this->marge_droite - 78;
  74.         $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 56;
  75.         $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 28;
  76.         $this->posxpuht=$this->page_largeur - $this->marge_droite;
  77.  
  78.         if (!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) {
  79.  
  80.             $this->posxweightvol=$this->page_largeur - $this->marge_droite - 118;
  81.             $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 96;
  82.             $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 68;
  83.             $this->posxpuht=$this->page_largeur - $this->marge_droite - 40;
  84.             $this->posxtotalht=$this->page_largeur - $this->marge_droite - 20;
  85.         }
  86.  
  87.         $this->posxpicture=$this->posxweightvol - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH);    // width of images
  88.  
  89.         if ($this->page_largeur < 210) // To work with US executive format
  90.         {
  91.             $this->posxweightvol-=20;
  92.             $this->posxpicture-=20;
  93.             $this->posxqtyordered-=20;
  94.             $this->posxqtytoship-=20;
  95.         }
  96.  
  97.         if (! empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
  98.         {
  99.             $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered);
  100.             $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered);
  101.             $this->posxqtyordered = $this->posxqtytoship;
  102.         }
  103.     }
  104.  
  105.     /**
  106.      *  Function to build pdf onto disk
  107.      *
  108.      *  @param      Object      $object         Object expedition to generate (or id if old method)
  109.      *  @param      Translate   $outputlangs        Lang output object
  110.      *  @param      string      $srctemplatepath    Full path of source filename for generator using a template file
  111.      *  @param      int         $hidedetails        Do not show line details
  112.      *  @param      int         $hidedesc           Do not show desc
  113.      *  @param      int         $hideref            Do not show ref
  114.      *  @return     int                             1=OK, 0=KO
  115.      */
  116.     function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
  117.     {
  118.         global $user,$conf,$langs,$hookmanager;
  119.  
  120.         $object->fetch_thirdparty();
  121.         $extrafields = new ExtraFields($db);
  122.         $extralabels=$extrafields->fetch_name_optionals_label($object->table_element_line);
  123.        
  124.        
  125.  
  126.         if (! is_object($outputlangs)) $outputlangs=$langs;
  127.         // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  128.         if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  129.  
  130.         $outputlangs->load("main");
  131.         $outputlangs->load("dict");
  132.         $outputlangs->load("companies");
  133.         $outputlangs->load("bills");
  134.         $outputlangs->load("products");
  135.         $outputlangs->load("propal");
  136.         $outputlangs->load("deliveries");
  137.         $outputlangs->load("sendings");
  138.         $outputlangs->load("productbatch");
  139.  
  140.         $nblignes = count($object->lines);
  141.  
  142.         // Loop on each lines to detect if there is at least one image to show
  143.         $realpatharray=array();
  144.         if (! empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE))
  145.         {
  146.             $objphoto = new Product($this->db);
  147.  
  148.             for ($i = 0 ; $i < $nblignes ; $i++)
  149.             {
  150.                
  151.                
  152.                 if (empty($object->lines[$i]->fk_product)) continue;
  153.  
  154.                 $objphoto = new Product($this->db);
  155.                 $objphoto->fetch($object->lines[$i]->fk_product);
  156.  
  157.                 $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/";
  158.                 $dir = $conf->product->dir_output.'/'.$pdir;
  159.  
  160.                 $realpath='';
  161.  
  162.                 foreach ($objphoto->liste_photos($dir,1) as $key => $obj)
  163.                         {
  164.                             if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES))      // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
  165.                             {
  166.                                 if ($obj['photo_vignette'])
  167.                                 {
  168.                                     $filename= $obj['photo_vignette'];
  169.                                 }
  170.                                 else
  171.                                 {
  172.                                     $filename=$obj['photo'];
  173.                                 }
  174.                             }
  175.                             else
  176.                             {
  177.                                 $filename=$obj['photo'];
  178.                             }
  179.  
  180.                             $realpath = $dir.$filename;
  181.                             break;
  182.                 }
  183.  
  184.                 if ($realpath) $realpatharray[$i]=$realpath;
  185.             }
  186.         }
  187.  
  188.         if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol;
  189.  
  190.         if ($conf->expedition->dir_output)
  191.         {
  192.             // Definition de $dir et $file
  193.             if ($object->specimen)
  194.             {
  195.                 $dir = $conf->expedition->dir_output."/sending";
  196.                 $file = $dir . "/SPECIMEN.pdf";
  197.             }
  198.             else
  199.             {
  200.                 $expref = dol_sanitizeFileName($object->ref);
  201.                 $dir = $conf->expedition->dir_output."/sending/" . $expref;
  202.                 $file = $dir . "/" . $expref . ".pdf";
  203.             }
  204.  
  205.             if (! file_exists($dir))
  206.             {
  207.                 if (dol_mkdir($dir) < 0)
  208.                 {
  209.                     $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  210.                     return 0;
  211.                 }
  212.             }
  213.  
  214.             if (file_exists($dir))
  215.             {
  216.                 // Add pdfgeneration hook
  217.                 if (! is_object($hookmanager))
  218.                 {
  219.                     include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  220.                     $hookmanager=new HookManager($this->db);
  221.                 }
  222.                 $hookmanager->initHooks(array('pdfgeneration'));
  223.                 $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  224.                 global $action;
  225.                 $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
  226.  
  227.                 // Set nblignes with the new facture lines content after hook
  228.                 $nblignes = count($object->lines);
  229.  
  230.                 $pdf=pdf_getInstance($this->format);
  231.                 $default_font_size = pdf_getPDFFontSize($outputlangs);
  232.                 $heightforinfotot = 8;  // Height reserved to output the info and total part
  233.                 $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page
  234.                 $heightforfooter = $this->marge_basse + 8;  // Height reserved to output the footer (value include bottom margin)
  235.                 $pdf->SetAutoPageBreak(1,0);
  236.  
  237.                 if (class_exists('TCPDF'))
  238.                 {
  239.                     $pdf->setPrintHeader(false);
  240.                     $pdf->setPrintFooter(false);
  241.                 }
  242.                 $pdf->SetFont(pdf_getPDFFont($outputlangs));
  243.                 // Set path to the background PDF File
  244.                 if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  245.                 {
  246.                     $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  247.                     $tplidx = $pdf->importPage(1);
  248.                 }
  249.  
  250.                 $pdf->Open();
  251.                 $pagenb=0;
  252.                 $pdf->SetDrawColor(128,128,128);
  253.  
  254.                 if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
  255.  
  256.                 $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  257.                 $pdf->SetSubject($outputlangs->transnoentities("Shipment"));
  258.                 $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  259.                 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  260.                 $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment"));
  261.                 if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  262.  
  263.                 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
  264.  
  265.                 // New page
  266.                 $pdf->AddPage();
  267.                 if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  268.                 $pagenb++;
  269.                 $this->_pagehead($pdf, $object, 1, $outputlangs);
  270.                 $pdf->SetFont('','', $default_font_size - 1);
  271.                 $pdf->MultiCell(0, 3, '');      // Set interline to 3
  272.                 $pdf->SetTextColor(0,0,0);
  273.  
  274.                 $tab_top = 90;
  275.                 $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
  276.                 $tab_height = 130;
  277.                 $tab_height_newpage = 150;
  278.  
  279.                 // Incoterm
  280.                 $height_incoterms = 0;
  281.                 if ($conf->incoterm->enabled)
  282.                 {
  283.                     $desc_incoterms = $object->getIncotermsForPDF();
  284.                     if ($desc_incoterms)
  285.                     {
  286.                         $tab_top = 88;
  287.  
  288.                         $pdf->SetFont('','', $default_font_size - 1);
  289.                         $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  290.                         $nexY = $pdf->GetY();
  291.                         $height_incoterms=$nexY-$tab_top;
  292.  
  293.                         // Rect prend une longueur en 3eme param
  294.                         $pdf->SetDrawColor(192,192,192);
  295.                         $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1);
  296.  
  297.                         $tab_top = $nexY+6;
  298.                         $height_incoterms += 4;
  299.                     }
  300.                 }
  301.  
  302.                 if (! empty($object->note_public) || ! empty($object->tracking_number))
  303.                 {
  304.                     $tab_top = 88 + $height_incoterms;
  305.                     $tab_top_alt = $tab_top;
  306.  
  307.                     $pdf->SetFont('','B', $default_font_size - 2);
  308.                     $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L');
  309.  
  310.                     $tab_top_alt = $pdf->GetY();
  311.                     //$tab_top_alt += 1;
  312.  
  313.                     // Tracking number
  314.                     if (! empty($object->tracking_number))
  315.                     {
  316.                         $object->GetUrlTrackingStatus($object->tracking_number);
  317.                         if (! empty($object->tracking_url))
  318.                         {
  319.                             if ($object->shipping_method_id > 0)
  320.                             {
  321.                                 // Get code using getLabelFromKey
  322.                                 $code=$outputlangs->getLabelFromKey($this->db,$object->shipping_method_id,'c_shipment_mode','rowid','code');
  323.                                 $label='';
  324.                                 if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."<br>";
  325.                                 $label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code));
  326.                                 //var_dump($object->tracking_url != $object->tracking_number);exit;
  327.                                 if ($object->tracking_url != $object->tracking_number)
  328.                                 {
  329.                                     $label.=" : ";
  330.                                     $label.=$object->tracking_url;
  331.                                 }
  332.                                 $pdf->SetFont('','B', $default_font_size - 2);
  333.                                 $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L');
  334.  
  335.                                 $tab_top_alt = $pdf->GetY();
  336.                             }
  337.                         }
  338.                     }
  339.  
  340.                     // Notes
  341.                     if (! empty($object->note_public))
  342.                     {
  343.                         $pdf->SetFont('','', $default_font_size - 1);   // Dans boucle pour gerer multi-page
  344.                         $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1);
  345.                     }
  346.  
  347.                     $nexY = $pdf->GetY();
  348.                     $height_note=$nexY-$tab_top;
  349.  
  350.                     // Rect prend une longueur en 3eme param
  351.                     $pdf->SetDrawColor(192,192,192);
  352.                     $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  353.  
  354.                     $tab_height = $tab_height - $height_note;
  355.                     $tab_top = $nexY+6;
  356.                 }
  357.                 else
  358.                 {
  359.                     $height_note=0;
  360.                 }
  361.  
  362.                 $iniY = $tab_top + 7;
  363.                 $curY = $tab_top + 7;
  364.                 $nexY = $tab_top + 7;
  365.  
  366.                 // Loop on each lines
  367.                 for ($i = 0; $i < $nblignes; $i++)
  368.                 {
  369.                    
  370.                     $object->lines[$i]->fetch_optionals($object->lines[$i]->rowid);
  371.                     $optionkeyname="unit";
  372.                     $unityvalue = $extrafieldsline->showOutputField($optionkeyname, $object->lines[$i]->array_options['options_'.$optionkeyname]);
  373.                                                            
  374.                     $curY = $nexY;
  375.                     $pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage
  376.                     $pdf->SetTextColor(0,0,0);
  377.  
  378.                     // Define size of image if we need it
  379.                     $imglinesize=array();
  380.                     if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]);
  381.  
  382.                     $pdf->setTopMargin($tab_top_newpage);
  383.                     $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  384.                     $pageposbefore=$pdf->getPage();
  385.  
  386.                     $showpricebeforepagebreak=1;
  387.                     $posYAfterImage=0;
  388.                     $posYAfterDescription=0;
  389.  
  390.                     // We start with Photo of product line
  391.                     if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot)))  // If photo too high, we moved completely on new page
  392.                     {
  393.                         $pdf->AddPage('','',true);
  394.                         if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  395.                         if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  396.                         $pdf->setPage($pageposbefore+1);
  397.  
  398.                         $curY = $tab_top_newpage;
  399.                         $showpricebeforepagebreak=0;
  400.                     }
  401.  
  402.                     if (isset($imglinesize['width']) && isset($imglinesize['height']))
  403.                     {
  404.                         $curX = $this->posxpicture-1;
  405.                         $pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  406.                         // $pdf->Image does not increase value return by getY, so we save it manually
  407.                         $posYAfterImage=$curY+$imglinesize['height'];
  408.                     }
  409.  
  410.                     // Description of product line
  411.                     $curX = $this->posxdesc-1;
  412.  
  413.                     $pdf->startTransaction();
  414.                     pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
  415.  
  416.                     $pageposafter=$pdf->getPage();
  417.                     if ($pageposafter > $pageposbefore) // There is a pagebreak
  418.                     {
  419.                         $pdf->rollbackTransaction(true);
  420.                         $pageposafter=$pageposbefore;
  421.                         //print $pageposafter.'-'.$pageposbefore;exit;
  422.                         $pdf->setPageOrientation('', 1, $heightforfooter);  // The only function to edit the bottom margin of current page to set it.
  423.                         pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc);
  424.  
  425.                         $pageposafter=$pdf->getPage();
  426.                         $posyafter=$pdf->GetY();
  427.                         //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  428.                         if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot)))   // There is no space left for total+free text
  429.                         {
  430.                             if ($i == ($nblignes-1))    // No more lines, and no space left to show total, so we create a new page
  431.                             {
  432.                                 $pdf->AddPage('','',true);
  433.                                 if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  434.                                 if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  435.                                 $pdf->setPage($pageposafter+1);
  436.                             }
  437.                         }
  438.                         else
  439.                         {
  440.                             // We found a page break
  441.                             $showpricebeforepagebreak=0;
  442.                         }
  443.                     }
  444.                     else    // No pagebreak
  445.                     {
  446.                         $pdf->commitTransaction();
  447.                     }
  448.                     $posYAfterDescription=$pdf->GetY();
  449.  
  450.                     $nexY = $pdf->GetY();
  451.                     $pageposafter=$pdf->getPage();
  452.  
  453.                     $pdf->setPage($pageposbefore);
  454.                     $pdf->setTopMargin($this->marge_haute);
  455.                     $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  456.  
  457.                     // We suppose that a too long description or photo were moved completely on next page
  458.                     if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  459.                         $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  460.                     }
  461.  
  462.                     // We suppose that a too long description is moved completely on next page
  463.                     if ($pageposafter > $pageposbefore) {
  464.                         $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  465.                     }
  466.  
  467.                     $pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut
  468.  
  469.                     $pdf->SetXY($this->posxweightvol, $curY);
  470.                     $weighttxt='';
  471.                     if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight)
  472.                     {
  473.                         $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->weight_units,"weight");
  474.                     }
  475.                     $voltxt='';
  476.                     if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume)
  477.                     {
  478.                         $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0,"volume");
  479.                     }
  480.  
  481.                     $pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt, 0, 0, false, true, 'C');
  482.                     //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'<br>':'').$voltxt,'','C');
  483.  
  484.                     if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
  485.                     {
  486.                        $pdf->SetXY($this->posxqtyordered, $curY);
  487.                       // $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked,'','C');
  488.                       $pdf -> MultiCell(($this->posxqtytoship - $this->posxqtyordered), 5 ,  $unityvalue , 0 , 'C' );                                    
  489.                     }
  490.  
  491.                     $pdf->SetXY($this->posxqtytoship, $curY);
  492.                 //  $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C');
  493.  
  494.                     if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT))
  495.                     {
  496.                         $pdf->SetXY($this->posxpuht, $curY);
  497.                         $pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs),'','R');
  498.  
  499.                         $pdf->SetXY($this->posxtotalht, $curY);
  500.                         $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs),'','R');
  501.                     }
  502.  
  503.                     $nexY+=3;
  504.                     if ($weighttxt && $voltxt) $nexY+=2;
  505.  
  506.                     // Add line
  507.                     if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
  508.                     {
  509.                         $pdf->setPage($pageposafter);
  510.                         $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
  511.                         //$pdf->SetDrawColor(190,190,200);
  512.                         $pdf->line($this->marge_gauche, $nexY-1, $this->page_largeur - $this->marge_droite, $nexY-1);
  513.                         $pdf->SetLineStyle(array('dash'=>0));
  514.                     }
  515.  
  516.                     // Detect if some page were added automatically and output _tableau for past pages
  517.                     while ($pagenb < $pageposafter)
  518.                     {
  519.                         $pdf->setPage($pagenb);
  520.                         if ($pagenb == 1)
  521.                         {
  522.                             $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  523.                         }
  524.                         else
  525.                         {
  526.                             $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  527.                         }
  528.                         $this->_pagefoot($pdf,$object,$outputlangs,1);
  529.                         $pagenb++;
  530.                         $pdf->setPage($pagenb);
  531.                         $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  532.                     }
  533.                     if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  534.                     {
  535.                         if ($pagenb == 1)
  536.                         {
  537.                             $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  538.                         }
  539.                         else
  540.                         {
  541.                             $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  542.                         }
  543.                         $this->_pagefoot($pdf,$object,$outputlangs,1);
  544.                         // New page
  545.                         $pdf->AddPage();
  546.                         if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  547.                         $pagenb++;
  548.                     }
  549.                 }
  550.  
  551.                 // Show square
  552.                 if ($pagenb == 1)
  553.                 {
  554.                     $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0);
  555.                     $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  556.                 }
  557.                 else
  558.                 {
  559.                     $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0);
  560.                     $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  561.                 }
  562.  
  563.                 // Affiche zone totaux
  564.                 $posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs);
  565.  
  566.                 // Pied de page
  567.                 $this->_pagefoot($pdf,$object,$outputlangs);
  568.                 if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
  569.  
  570.                 $pdf->Close();
  571.  
  572.                 $pdf->Output($file,'F');
  573.  
  574.                 // Add pdfgeneration hook
  575.                 $hookmanager->initHooks(array('pdfgeneration'));
  576.                 $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  577.                 global $action;
  578.                 $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
  579.  
  580.                 if (! empty($conf->global->MAIN_UMASK))
  581.                 @chmod($file, octdec($conf->global->MAIN_UMASK));
  582.  
  583.                 $this->result = array('fullpath'=>$file);
  584.  
  585.                 return 1;   // No error
  586.             }
  587.             else
  588.             {
  589.                 $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  590.                 return 0;
  591.             }
  592.         }
  593.         else
  594.         {
  595.             $this->error=$langs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR");
  596.             return 0;
  597.         }
  598.     }
  599.  
  600.     /**
  601.      *  Show total to pay
  602.      *
  603.      *  @param  PDF         $pdf           Object PDF
  604.      *  @param  Facture     $object         Object invoice
  605.      *  @param  int         $deja_regle     Montant deja regle
  606.      *  @param  int         $posy           Position depart
  607.      *  @param  Translate   $outputlangs    Objet langs
  608.      *  @return int                         Position pour suite
  609.      */
  610.     function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  611.     {
  612.         global $conf,$mysoc;
  613.  
  614.         $sign=1;
  615.  
  616.         $default_font_size = pdf_getPDFFontSize($outputlangs);
  617.  
  618.         $tab2_top = $posy;
  619.         $tab2_hl = 4;
  620.         $pdf->SetFont('','B', $default_font_size - 1);
  621.  
  622.         // Tableau total
  623.         $col1x = $this->posxweightvol-50; $col2x = $this->posxweightvol;
  624.         /*if ($this->page_largeur < 210) // To work with US executive format
  625.         {
  626.             $col2x-=20;
  627.         }*/
  628.         if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol);
  629.         else $largcol2 = ($this->posxqtytoship - $this->posxweightvol);
  630.  
  631.         $useborder=0;
  632.         $index = 0;
  633.  
  634.         $totalWeighttoshow='';
  635.         $totalVolumetoshow='';
  636.  
  637.         // Load dim data
  638.         $tmparray=$object->getTotalWeightVolume();
  639.         $totalWeight=$tmparray['weight'];
  640.         $totalVolume=$tmparray['volume'];
  641.         $totalOrdered=$tmparray['ordered'];
  642.         $totalToShip=$tmparray['toship'];
  643.         // Set trueVolume and volume_units not currently stored into database
  644.         if ($object->trueWidth && $object->trueHeight && $object->trueDepth)
  645.         {
  646.             $object->trueVolume=price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0);
  647.             $object->volume_units=$object->size_units * 3;
  648.         }
  649.  
  650.         if ($totalWeight!='') $totalWeighttoshow=showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs);
  651.         if ($totalVolume!='') $totalVolumetoshow=showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs);
  652.         if ($object->trueWeight) $totalWeighttoshow=showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs);
  653.         if ($object->trueVolume) $totalVolumetoshow=showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs);
  654.  
  655.         $pdf->SetFillColor(255,255,255);
  656.         $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  657.         $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1);
  658.  
  659.         if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
  660.         {
  661.             $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index);
  662.             $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1);
  663.         }
  664.  
  665.         $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index);
  666.         $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1);
  667.  
  668.         if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) {
  669.  
  670.             $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index);
  671.             $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1);
  672.  
  673.             $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index);
  674.             $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1);
  675.  
  676.         }
  677.  
  678.         // Total Weight
  679.         if ($totalWeighttoshow)
  680.         {
  681.             $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  682.             $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1);
  683.  
  684.             $index++;
  685.         }
  686.         if ($totalVolumetoshow)
  687.         {
  688.             $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index);
  689.             $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1);
  690.  
  691.             $index++;
  692.         }
  693.         if (! $totalWeighttoshow && ! $totalVolumetoshow) $index++;
  694.  
  695.         $pdf->SetTextColor(0,0,0);
  696.  
  697.         return ($tab2_top + ($tab2_hl * $index));
  698.     }
  699.  
  700.     /**
  701.      *   Show table for lines
  702.      *
  703.      *   @param     PDF         $pdf            Object PDF
  704.      *   @param     string      $tab_top        Top position of table
  705.      *   @param     string      $tab_height     Height of table (rectangle)
  706.      *   @param     int         $nexY           Y
  707.      *   @param     Translate   $outputlangs    Langs object
  708.      *   @param     int         $hidetop        Hide top bar of array
  709.      *   @param     int         $hidebottom     Hide bottom bar of array
  710.      *   @return    void
  711.      */
  712.     function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
  713.     {
  714.         global $conf;
  715.  
  716.         // Force to disable hidetop and hidebottom
  717.         $hidebottom=0;
  718.         if ($hidetop) $hidetop=-1;
  719.  
  720.         $default_font_size = pdf_getPDFFontSize($outputlangs);
  721.  
  722.         // Amount in (at tab_top - 1)
  723.         $pdf->SetTextColor(0,0,0);
  724.         $pdf->SetFont('','',$default_font_size - 2);
  725.  
  726.         // Output Rect
  727.         $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom);  // Rect prend une longueur en 3eme param et 4eme param
  728.  
  729.         $pdf->SetDrawColor(128,128,128);
  730.         $pdf->SetFont('','', $default_font_size - 1);
  731.  
  732.         if (empty($hidetop))
  733.         {
  734.             $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);
  735.  
  736.             $pdf->SetXY($this->posxdesc-1, $tab_top+1);
  737.             $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L');
  738.         }
  739.  
  740.         $pdf->line($this->posxweightvol-1, $tab_top, $this->posxweightvol-1, $tab_top + $tab_height);
  741.         if (empty($hidetop))
  742.         {
  743.             $pdf->SetXY($this->posxweightvol-1, $tab_top+1);
  744.             $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("Volume"),'','C');
  745.         }
  746.  
  747.        /* if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED))
  748.         {
  749.             $pdf->line($this->posxqtyordered-1, $tab_top, $this->posxqtyordered-1, $tab_top + $tab_height);
  750.             if (empty($hidetop))
  751.             {
  752.                 $pdf->SetXY($this->posxqtyordered-1, $tab_top+1);
  753.                 $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"),'','C');
  754.             }
  755.         }
  756.  
  757.         $pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height);
  758.         if (empty($hidetop))
  759.         {
  760.             $pdf->SetXY($this->posxqtytoship, $tab_top+1);
  761.             $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C');
  762.         }*/
  763.  
  764.         if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) {
  765.  
  766.             $pdf->line($this->posxpuht-1, $tab_top, $this->posxpuht-1, $tab_top + $tab_height);
  767.             if (empty($hidetop))
  768.             {
  769.                 $pdf->SetXY($this->posxpuht-1, $tab_top+1);
  770.                 $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"),'','C');
  771.             }
  772.  
  773.             $pdf->line($this->posxtotalht-1, $tab_top, $this->posxtotalht-1, $tab_top + $tab_height);
  774.             if (empty($hidetop))
  775.             {
  776.                 $pdf->SetXY($this->posxtotalht-1, $tab_top+1);
  777.                 $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"),'','C');
  778.             }
  779.  
  780.         }
  781.  
  782.     }
  783.  
  784.     /**
  785.      *  Show top header of page.
  786.      *
  787.      *  @param  PDF         $pdf            Object PDF
  788.      *  @param  Object      $object         Object to show
  789.      *  @param  int         $showaddress    0=no, 1=yes
  790.      *  @param  Translate   $outputlangs    Object lang for output
  791.      *  @return void
  792.      */
  793.     function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  794.     {
  795.         global $conf,$langs,$mysoc;
  796.  
  797.         $langs->load("orders");
  798.  
  799.         $default_font_size = pdf_getPDFFontSize($outputlangs);
  800.  
  801.         pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  802.  
  803.         // Show Draft Watermark
  804.         if($object->statut==0 && (! empty($conf->global->SHIPPING_DRAFT_WATERMARK)) )
  805.         {
  806.                     pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SHIPPING_DRAFT_WATERMARK);
  807.         }
  808.  
  809.         //Prepare la suite
  810.         $pdf->SetTextColor(0,0,60);
  811.         $pdf->SetFont('','B', $default_font_size + 3);
  812.  
  813.         $w = 110;
  814.  
  815.         $posy=$this->marge_haute;
  816.         $posx=$this->page_largeur-$this->marge_droite-$w;
  817.  
  818.         $pdf->SetXY($this->marge_gauche,$posy);
  819.  
  820.         // Logo
  821.         $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  822.         if ($this->emetteur->logo)
  823.         {
  824.             if (is_readable($logo))
  825.             {
  826.                 $height=pdf_getHeightForLogo($logo);
  827.                 $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  828.             }
  829.             else
  830.             {
  831.                 $pdf->SetTextColor(200,0,0);
  832.                 $pdf->SetFont('','B', $default_font_size - 2);
  833.                 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  834.                 $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  835.             }
  836.         }
  837.         else
  838.         {
  839.             $text=$this->emetteur->name;
  840.             $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  841.         }
  842.  
  843.         // Show barcode
  844.         if (! empty($conf->barcode->enabled))
  845.         {
  846.             $posx=105;
  847.         }
  848.         else
  849.         {
  850.             $posx=$this->marge_gauche+3;
  851.         }
  852.         //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30);
  853.         if (! empty($conf->barcode->enabled))
  854.         {
  855.             // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  856.             //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  857.             //$pdf->Image($logo,10, 5, 0, 24);
  858.         }
  859.  
  860.         $pdf->SetDrawColor(128,128,128);
  861.         if (! empty($conf->barcode->enabled))
  862.         {
  863.             // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref
  864.             //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3);
  865.             //$pdf->Image($logo,10, 5, 0, 24);
  866.         }
  867.  
  868.  
  869.         $posx=$this->page_largeur - $w - $this->marge_droite;
  870.         $posy=$this->marge_haute;
  871.  
  872.         $pdf->SetFont('','B', $default_font_size + 2);
  873.         $pdf->SetXY($posx,$posy);
  874.         $pdf->SetTextColor(0,0,60);
  875.         $title=$outputlangs->transnoentities("SendingSheet");
  876.         $pdf->MultiCell($w, 4, $title, '', 'R');
  877.  
  878.         $pdf->SetFont('','', $default_font_size + 1);
  879.  
  880.         $posy+=5;
  881.  
  882.         $pdf->SetXY($posx,$posy);
  883.         $pdf->SetTextColor(0,0,60);
  884.         $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R');
  885.  
  886.         // Date planned delivery
  887.         if (! empty($object->date_delivery))
  888.         {
  889.                 $posy+=4;
  890.                 $pdf->SetXY($posx,$posy);
  891.                 $pdf->SetTextColor(0,0,60);
  892.                 $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R');
  893.         }
  894.  
  895.         if (! empty($object->thirdparty->code_client))
  896.         {
  897.             $posy+=4;
  898.             $pdf->SetXY($posx,$posy);
  899.             $pdf->SetTextColor(0,0,60);
  900.             $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  901.         }
  902.  
  903.  
  904.         $pdf->SetFont('','', $default_font_size + 3);
  905.         $Yoff=25;
  906.  
  907.         // Add list of linked orders
  908.         $origin     = $object->origin;
  909.         $origin_id  = $object->origin_id;
  910.  
  911.         // TODO move to external function
  912.         if (! empty($conf->$origin->enabled))     // commonly $origin='commande'
  913.         {
  914.             $outputlangs->load('orders');
  915.  
  916.             $classname = ucfirst($origin);
  917.             $linkedobject = new $classname($this->db);
  918.             $result=$linkedobject->fetch($origin_id);
  919.             if ($result >= 0)
  920.             {
  921.                 //$linkedobject->fetchObjectLinked()   Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects
  922.  
  923.                 $pdf->SetFont('','', $default_font_size - 2);
  924.                 $text=$linkedobject->ref;
  925.                 if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
  926.                 $Yoff = $Yoff+8;
  927.                 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff);
  928.                 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
  929.                 $Yoff = $Yoff+3;
  930.                 $pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff);
  931.                 $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R');
  932.             }
  933.         }
  934.  
  935.         if ($showaddress)
  936.         {
  937.             // Sender properties
  938.             $carac_emetteur='';
  939.             // Add internal contact of origin element if defined
  940.             $arrayidcontact=array();
  941.             if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal','SALESREPFOLL');
  942.             if (count($arrayidcontact) > 0)
  943.             {
  944.                 $object->fetch_user(reset($arrayidcontact));
  945.                 $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  946.             }
  947.  
  948.             $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
  949.  
  950.             // Show sender
  951.             $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  952.             $posx=$this->marge_gauche;
  953.             if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  954.  
  955.             $hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  956.             $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  957.  
  958.             // Show sender frame
  959.             $pdf->SetTextColor(0,0,0);
  960.             $pdf->SetFont('','', $default_font_size - 2);
  961.             $pdf->SetXY($posx,$posy-5);
  962.             $pdf->MultiCell(66,5, $outputlangs->transnoentities("Sender").":", 0, 'L');
  963.             $pdf->SetXY($posx,$posy);
  964.             $pdf->SetFillColor(230,230,230);
  965.             $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  966.             $pdf->SetTextColor(0,0,60);
  967.             $pdf->SetFillColor(255,255,255);
  968.  
  969.             // Show sender name
  970.             $pdf->SetXY($posx+2,$posy+3);
  971.             $pdf->SetFont('','B',$default_font_size);
  972.             $pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  973.             $posy=$pdf->getY();
  974.  
  975.             // Show sender information
  976.             $pdf->SetXY($posx+2,$posy);
  977.             $pdf->SetFont('','', $default_font_size - 1);
  978.             $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L');
  979.  
  980.  
  981.             // If SHIPPING contact defined, we use it
  982.             $usecontact=false;
  983.             $arrayidcontact=$object->$origin->getIdContact('external','SHIPPING');
  984.             if (count($arrayidcontact) > 0)
  985.             {
  986.                 $usecontact=true;
  987.                 $result=$object->fetch_contact($arrayidcontact[0]);
  988.             }
  989.  
  990.             //Recipient name
  991.             // On peut utiliser le nom de la societe du contact
  992.             if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
  993.                 $thirdparty = $object->contact;
  994.             } else {
  995.                 $thirdparty = $object->thirdparty;
  996.             }
  997.  
  998.             $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs);
  999.  
  1000.             $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,(!empty($object->contact)?$object->contact:null),$usecontact,'targetwithdetails',$object);
  1001.  
  1002.             // Show recipient
  1003.             $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  1004.             if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format
  1005.             $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1006.             $posx=$this->page_largeur - $this->marge_droite - $widthrecbox;
  1007.             if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  1008.  
  1009.             // Show recipient frame
  1010.             $pdf->SetTextColor(0,0,0);
  1011.             $pdf->SetFont('','', $default_font_size - 2);
  1012.             $pdf->SetXY($posx+2,$posy-5);
  1013.             $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L');
  1014.             $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1015.  
  1016.             // Show recipient name
  1017.             $pdf->SetXY($posx+2,$posy+3);
  1018.             $pdf->SetFont('','B', $default_font_size);
  1019.             $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
  1020.  
  1021.             $posy = $pdf->getY();
  1022.  
  1023.             // Show recipient information
  1024.             $pdf->SetFont('','', $default_font_size - 1);
  1025.             $pdf->SetXY($posx+2,$posy);
  1026.             $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
  1027.         }
  1028.  
  1029.         $pdf->SetTextColor(0,0,0);
  1030.     }
  1031.  
  1032.     /**
  1033.      *      Show footer of page. Need this->emetteur object
  1034.      *
  1035.      *      @param  PDF         $pdf                PDF
  1036.      *      @param  Object      $object             Object to show
  1037.      *      @param  Translate   $outputlangs        Object lang for output
  1038.      *      @param  int         $hidefreetext       1=Hide free text
  1039.      *      @return int                             Return height of bottom margin including footer text
  1040.      */
  1041.     function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
  1042.     {
  1043.         global $conf;
  1044.         $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  1045.         return pdf_pagefoot($pdf,$outputlangs,'SHIPPING_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
  1046.     }
  1047.  
  1048. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement