diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f7b8ab9de0b885a0031dc43fdc45217d8731323a..a285e256860063f3eb41d4808246e0e1bb9e92e4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3408,6 +3408,42 @@ function price2num($amount,$rounding='',$alreadysqlnb=0) return $amount; } + +/** + * Output a dimension with best unit + * @param float $dimension Dimension + * @param int $unit Unit of dimension (0, -3, ...) + * @param string $type 'weight', 'volume', ... + */ +function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs) +{ + if ($dimension < 1/10000) + { + $dimension = $dimension * 1000000; + $unit = $unit - 6; + } + elseif ($dimension < 1/10) + { + $dimension = $dimension * 1000; + $unit = $unit - 3; + } + elseif ($dimension > 100000000) + { + $dimension = $dimension / 1000000; + $unit = $unit + 6; + } + elseif ($dimension > 100000) + { + $dimension = $dimension / 1000; + $unit = $unit + 3; + } + + $ret=price($dimension, 0, $outputlangs, 0, 0).' '.measuring_units_string($unit, $type); + + return $ret; +} + + /** * Return localtax rate for a particular vat, when selling a product with vat $vatrate, from a $thirdparty_buyer to a $thirdparty_seller * Note: This function applies same rules than get_default_tva diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 1d3114f881954fe045102b8d748bd5fa9855cf9a..d946ef2b588efa8831ae424ae97e56dc62b4cd91 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -337,7 +337,7 @@ function show_stats_for_company($product,$socid) * @param int $unit Unit key (-3,0,3,98,99...) * @param string $measuring_style Style of unit: weight, volume,... * @return string Unit string - * @see load_measuring_units + * @see formproduct->load_measuring_units */ function measuring_units_string($unit,$measuring_style='') { @@ -346,41 +346,41 @@ function measuring_units_string($unit,$measuring_style='') $measuring_units=array(); if ($measuring_style == 'weight') { - $measuring_units[3] = $langs->trans("WeightUnitton"); - $measuring_units[0] = $langs->trans("WeightUnitkg"); - $measuring_units[-3] = $langs->trans("WeightUnitg"); - $measuring_units[-6] = $langs->trans("WeightUnitmg"); - $measuring_units[99] = $langs->trans("WeightUnitpound"); + $measuring_units[3] = $langs->transnoentitiesnoconv("WeightUnitton"); + $measuring_units[0] = $langs->transnoentitiesnoconv("WeightUnitkg"); + $measuring_units[-3] = $langs->transnoentitiesnoconv("WeightUnitg"); + $measuring_units[-6] = $langs->transnoentitiesnoconv("WeightUnitmg"); + $measuring_units[99] = $langs->transnoentitiesnoconv("WeightUnitpound"); } else if ($measuring_style == 'size') { - $measuring_units[0] = $langs->trans("SizeUnitm"); - $measuring_units[-1] = $langs->trans("SizeUnitdm"); - $measuring_units[-2] = $langs->trans("SizeUnitcm"); - $measuring_units[-3] = $langs->trans("SizeUnitmm"); - $measuring_units[98] = $langs->trans("SizeUnitfoot"); - $measuring_units[99] = $langs->trans("SizeUnitinch"); + $measuring_units[0] = $langs->transnoentitiesnoconv("SizeUnitm"); + $measuring_units[-1] = $langs->transnoentitiesnoconv("SizeUnitdm"); + $measuring_units[-2] = $langs->transnoentitiesnoconv("SizeUnitcm"); + $measuring_units[-3] = $langs->transnoentitiesnoconv("SizeUnitmm"); + $measuring_units[98] = $langs->transnoentitiesnoconv("SizeUnitfoot"); + $measuring_units[99] = $langs->transnoentitiesnoconv("SizeUnitinch"); } else if ($measuring_style == 'surface') { - $measuring_units[0] = $langs->trans("SurfaceUnitm2"); - $measuring_units[-2] = $langs->trans("SurfaceUnitdm2"); - $measuring_units[-4] = $langs->trans("SurfaceUnitcm2"); - $measuring_units[-6] = $langs->trans("SurfaceUnitmm2"); - $measuring_units[98] = $langs->trans("SurfaceUnitfoot2"); - $measuring_units[99] = $langs->trans("SurfaceUnitinch2"); + $measuring_units[0] = $langs->transnoentitiesnoconv("SurfaceUnitm2"); + $measuring_units[-2] = $langs->transnoentitiesnoconv("SurfaceUnitdm2"); + $measuring_units[-4] = $langs->transnoentitiesnoconv("SurfaceUnitcm2"); + $measuring_units[-6] = $langs->transnoentitiesnoconv("SurfaceUnitmm2"); + $measuring_units[98] = $langs->transnoentitiesnoconv("SurfaceUnitfoot2"); + $measuring_units[99] = $langs->transnoentitiesnoconv("SurfaceUnitinch2"); } else if ($measuring_style == 'volume') { - $measuring_units[0] = $langs->trans("VolumeUnitm3"); - $measuring_units[-3] = $langs->trans("VolumeUnitdm3"); - $measuring_units[-6] = $langs->trans("VolumeUnitcm3"); - $measuring_units[-9] = $langs->trans("VolumeUnitmm3"); - $measuring_units[88] = $langs->trans("VolumeUnitfoot3"); - $measuring_units[89] = $langs->trans("VolumeUnitinch3"); - $measuring_units[97] = $langs->trans("VolumeUnitounce"); - $measuring_units[98] = $langs->trans("VolumeUnitlitre"); - $measuring_units[99] = $langs->trans("VolumeUnitgallon"); + $measuring_units[0] = $langs->transnoentitiesnoconv("VolumeUnitm3"); + $measuring_units[-3] = $langs->transnoentitiesnoconv("VolumeUnitdm3"); + $measuring_units[-6] = $langs->transnoentitiesnoconv("VolumeUnitcm3"); + $measuring_units[-9] = $langs->transnoentitiesnoconv("VolumeUnitmm3"); + $measuring_units[88] = $langs->transnoentitiesnoconv("VolumeUnitfoot3"); + $measuring_units[89] = $langs->transnoentitiesnoconv("VolumeUnitinch3"); + $measuring_units[97] = $langs->transnoentitiesnoconv("VolumeUnitounce"); + $measuring_units[98] = $langs->transnoentitiesnoconv("VolumeUnitlitre"); + $measuring_units[99] = $langs->transnoentitiesnoconv("VolumeUnitgallon"); } return $measuring_units[$unit]; diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php index 6cc965c5c4fdbb50abdda256fdf0bb861cac4af4..a4d72c6531e78f7742f7fff3bf1b6ecaa6e504d5 100644 --- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php @@ -63,18 +63,20 @@ class pdf_rouget extends ModelePdfExpedition $this->option_logo = 1; - // Recupere emmetteur + // Get source company $this->emetteur=$mysoc; if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined - // Defini position des colonnes + // Define position of columns $this->posxdesc=$this->marge_gauche+1; - $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 70; - $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 35; - $this->posxpicture=$this->posxqtyordered - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images - + $this->posxweightvol=$this->page_largeur - $this->marge_droite - 80; + $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 60; + $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 30; + $this->posxpicture=$this->posxweightvol - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images + if ($this->page_largeur < 210) // To work with US executive format { + $this->posxweightvol-=20; $this->posxpicture-=20; $this->posxqtyordered-=20; $this->posxqtytoship-=20; @@ -92,7 +94,7 @@ class pdf_rouget extends ModelePdfExpedition * @param int $hideref Do not show ref * @return int 1=OK, 0=KO */ - function write_file(&$object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) + function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { global $user,$conf,$langs,$hookmanager; @@ -123,27 +125,15 @@ class pdf_rouget extends ModelePdfExpedition { if (empty($object->lines[$i]->fk_product)) continue; - $objphoto->fetch($object->lines[$i]->fk_product); - //var_dump($objphoto->ref);exit; - if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) - { - $pdir[0] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/"; - $pdir[1] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/'; - } - else - { - $pdir[0] = get_exdir(0,0,0,0,$objphoto,'product') . dol_sanitizeFileName($objphoto->ref).'/'; // default - $pdir[1] = get_exdir($objphoto->id,2,0,0,$objphoto,'product') . $objphoto->id ."/photos/"; // alternative - } - - $arephoto = false; - foreach ($pdir as $midir) - { - if (! $arephoto) - { - $dir = $conf->product->dir_output.'/'.$midir; - - foreach ($objphoto->liste_photos($dir,1) as $key => $obj) + $objphoto = new Product($this->db); + $objphoto->fetch($object->lines[$i]->fk_product); + + $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/"; + $dir = $conf->product->dir_output.'/'.$pdir; + + $realpath=''; + + foreach ($objphoto->liste_photos($dir,1) as $key => $obj) { if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo { @@ -162,16 +152,14 @@ class pdf_rouget extends ModelePdfExpedition } $realpath = $dir.$filename; - $arephoto = true; - } - } + break; } - if ($realpath && $arephoto) $realpatharray[$i]=$realpath; + if ($realpath) $realpatharray[$i]=$realpath; } } - if (count($realpatharray) == 0) $this->posxpicture=$this->posxqtyordered; + if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol; if ($conf->expedition->dir_output) { @@ -210,9 +198,12 @@ class pdf_rouget extends ModelePdfExpedition global $action; $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + // Set nblignes with the new facture lines content after hook + $nblignes = count($object->lines); + $pdf=pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); - $heightforinfotot = 0; // Height reserved to output the info and total part + $heightforinfotot = 30; // Height reserved to output the info and total part $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 $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) $pdf->SetAutoPageBreak(1,0); @@ -380,7 +371,7 @@ class pdf_rouget extends ModelePdfExpedition if (isset($imglinesize['width']) && isset($imglinesize['height'])) { $curX = $this->posxpicture-1; - $pdf->Image($realpatharray[$i], $curX + (($this->posxqtyordered-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi + $pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi // $pdf->Image does not increase value return by getY, so we save it manually $posYAfterImage=$curY+$imglinesize['height']; } @@ -389,7 +380,6 @@ class pdf_rouget extends ModelePdfExpedition $curX = $this->posxdesc-1; $pdf->startTransaction(); - // Description de la ligne produit pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); $pageposafter=$pdf->getPage(); @@ -445,6 +435,20 @@ class pdf_rouget extends ModelePdfExpedition $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut + $pdf->SetXY($this->posxweightvol, $curY); + $weighttxt=''; + if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight) + { + $weighttxt=$object->lines[$i]->weight*$object->lines[$i]->qty_shipped.' '.measuring_units_string($object->lines[$i]->weight_units,"weight"); + } + $voltxt=''; + if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume) + { + $voltxt=$object->lines[$i]->volume*$object->lines[$i]->qty_shipped.' '.measuring_units_string($object->lines[$i]->volume_units,"volume"); + } + + $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?', ':'').$voltxt,'','C'); + $pdf->SetXY($this->posxqtyordered, $curY); $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked,'','C'); @@ -501,15 +505,18 @@ class pdf_rouget extends ModelePdfExpedition // Show square if ($pagenb == 1) { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 0, 0); - $bottomlasttab=$this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1; + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } else { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext - $heightforinfotot, 0, $outputlangs, 1, 0); - $bottomlasttab=$this->page_hauteur - $heightforfooter - $heightforfreetext - $heightforinfotot + 1; + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; } + // Affiche zone totaux + $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); + // Pied de page $this->_pagefoot($pdf,$object,$outputlangs); if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); @@ -519,11 +526,6 @@ class pdf_rouget extends ModelePdfExpedition $pdf->Output($file,'F'); // Add pdfgeneration hook - if (! is_object($hookmanager)) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; - $hookmanager=new HookManager($this->db); - } $hookmanager->initHooks(array('pdfgeneration')); $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); global $action; @@ -532,7 +534,7 @@ class pdf_rouget extends ModelePdfExpedition if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); - return 1; + return 1; // No error } else { @@ -549,6 +551,89 @@ class pdf_rouget extends ModelePdfExpedition return 0; // Erreur par defaut } + /** + * Show total to pay + * + * @param PDF $pdf Object PDF + * @param Facture $object Object invoice + * @param int $deja_regle Montant deja regle + * @param int $posy Position depart + * @param Translate $outputlangs Objet langs + * @return int Position pour suite + */ + function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) + { + global $conf,$mysoc; + + $sign=1; + + $default_font_size = pdf_getPDFFontSize($outputlangs); + + $tab2_top = $posy; + $tab2_hl = 4; + $pdf->SetFont('','', $default_font_size - 1); + + // Tableau total + $col1x = $this->posxweightvol-50; $col2x = $this->posxweightvol; + /*if ($this->page_largeur < 210) // To work with US executive format + { + $col2x-=20; + }*/ + $largcol2 = ($this->posxqtyordered - $this->posxweightvol); + + $useborder=0; + $index = 0; + + $totalWeighttoshow=''; + $totalVolumetoshow=''; + + // Load dim data + $tmparray=$object->getTotalWeightVolume(); + $totalWeight=$tmparray['weight']; + $totalVolume=$tmparray['volume']; + // Set trueVolume and volume_units not currently stored into database + if ($object->trueWidth && $object->trueHeight && $object->trueDepth) + { + $object->trueVolume=price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0); + $object->volume_units=$object->size_units * 3; + } + + if ($totalWeight!='') $totalWeighttoshow=showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs); + if ($totalVolume!='') $totalVolumetoshow=showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs); + if ($object->trueWeight) $totalWeighttoshow=showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs); + if ($object->trueVolume) $totalVolumetoshow=showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs); + + // Total Weight + if ($totalWeighttoshow) + { + $pdf->SetFillColor(255,255,255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Weigth"), 0, 'L', 1); + + $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2+20, $tab2_hl, $totalWeighttoshow, 0, 'R', 1); + + $index++; + } + + if ($totalVolumetoshow) + { + // Total Volume + $pdf->SetFillColor(255,255,255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Volume"), 0, 'L', 1); + + $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2+20, $tab2_hl, $totalVolumetoshow, 0, 'R', 1); + + $index++; + } + + $pdf->SetTextColor(0,0,0); + + return ($tab2_top + ($tab2_hl * $index)); + } + /** * Show table for lines * @@ -573,13 +658,13 @@ class pdf_rouget extends ModelePdfExpedition // Amount in (at tab_top - 1) $pdf->SetTextColor(0,0,0); - $pdf->SetFont('','',$default_font_size - 1); + $pdf->SetFont('','',$default_font_size - 2); // Output Rect $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 $pdf->SetDrawColor(128,128,128); - $pdf->SetFont('','',$default_font_size - 1); + $pdf->SetFont('','', $default_font_size - 1); if (empty($hidetop)) { @@ -589,10 +674,17 @@ class pdf_rouget extends ModelePdfExpedition $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L'); } + $pdf->line($this->posxweightvol-1, $tab_top, $this->posxweightvol-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxweightvol-1, $tab_top+1); + $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"),'','C'); + } + $pdf->line($this->posxqtyordered-1, $tab_top, $this->posxqtyordered-1, $tab_top + $tab_height); if (empty($hidetop)) { - $pdf->SetXY($this->posxqtyordered, $tab_top+1); + $pdf->SetXY($this->posxqtyordered-1, $tab_top+1); $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"),'','C'); } @@ -616,12 +708,14 @@ class pdf_rouget extends ModelePdfExpedition function _pagehead(&$pdf, $object, $showaddress, $outputlangs) { global $conf,$langs,$mysoc; - $default_font_size = pdf_getPDFFontSize($outputlangs); + $langs->load("orders"); + + $default_font_size = pdf_getPDFFontSize($outputlangs); pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); - //Affiche le filigrane brouillon - Print Draft Watermark + // Show Draft Watermark if($object->statut==0 && (! empty($conf->global->SHIPPING_DRAFT_WATERMARK)) ) { pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SHIPPING_DRAFT_WATERMARK); @@ -631,8 +725,10 @@ class pdf_rouget extends ModelePdfExpedition $pdf->SetTextColor(0,0,60); $pdf->SetFont('','B', $default_font_size + 3); - $posx=$this->page_largeur-$this->marge_droite-100; + $w = 110; + $posy=$this->marge_haute; + $posx=$this->page_largeur-$this->marge_droite-$w; $pdf->SetXY($this->marge_gauche,$posy); @@ -649,14 +745,14 @@ class pdf_rouget extends ModelePdfExpedition { $pdf->SetTextColor(200,0,0); $pdf->SetFont('','B', $default_font_size - 2); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); } } else { $text=$this->emetteur->name; - $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); + $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); } // Show barcode @@ -685,14 +781,14 @@ class pdf_rouget extends ModelePdfExpedition } - $posx=$this->page_largeur - 100 - $this->marge_droite; + $posx=$this->page_largeur - $w - $this->marge_droite; $posy=$this->marge_haute; $pdf->SetFont('','B', $default_font_size + 2); $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); $title=$outputlangs->transnoentities("SendingSheet"); - $pdf->MultiCell(100, 4, $title, '', 'R'); + $pdf->MultiCell($w, 4, $title, '', 'R'); $posy+=1; $pdf->SetFont('','', $default_font_size + 1); @@ -700,7 +796,7 @@ class pdf_rouget extends ModelePdfExpedition $posy+=4; $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(100, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R'); + $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R'); // Date planned delivery if (! empty($object->date_delivery)) @@ -708,7 +804,7 @@ class pdf_rouget extends ModelePdfExpedition $posy+=4; $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(100, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R'); + $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R'); } if (! empty($object->client->code_client)) @@ -716,7 +812,7 @@ class pdf_rouget extends ModelePdfExpedition $posy+=4; $pdf->SetXY($posx,$posy); $pdf->SetTextColor(0,0,60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'R'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->client->code_client), '', 'R'); } @@ -744,11 +840,11 @@ class pdf_rouget extends ModelePdfExpedition $text=$linkedobject->ref; if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')'; $Yoff = $Yoff+8; - $pdf->SetXY($this->page_largeur - $this->marge_droite - 100,$Yoff); - $pdf->MultiCell(100, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R'); + $pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff); + $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R'); $Yoff = $Yoff+3; - $pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff); - $pdf->MultiCell(60, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R'); + $pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff); + $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R'); } } @@ -761,18 +857,20 @@ class pdf_rouget extends ModelePdfExpedition if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal','SALESREPFOLL'); if (count($arrayidcontact) > 0) { - $object->fetch_user($arrayidcontact[0]); + $object->fetch_user(reset($arrayidcontact)); $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; } $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->client); // Show sender + $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42; $posx=$this->marge_gauche; - $posy=42; - $hautcadre=40; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80; + $hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40; + $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82; + // Show sender frame $pdf->SetTextColor(0,0,0); $pdf->SetFont('','', $default_font_size - 2); @@ -780,19 +878,19 @@ class pdf_rouget extends ModelePdfExpedition $pdf->MultiCell(66,5, $outputlangs->transnoentities("Sender").":", 0, 'L'); $pdf->SetXY($posx,$posy); $pdf->SetFillColor(230,230,230); - $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1); - + $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1); + $pdf->SetTextColor(0,0,60); + // Show sender name $pdf->SetXY($posx+2,$posy+3); - $pdf->SetTextColor(0,0,60); $pdf->SetFont('','B',$default_font_size); - $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L'); + $pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L'); $posy=$pdf->getY(); // Show sender information - $pdf->SetFont('','', $default_font_size - 1); $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L'); + $pdf->SetFont('','', $default_font_size - 1); + $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L'); // If SHIPPING contact defined, we use it @@ -817,24 +915,23 @@ class pdf_rouget extends ModelePdfExpedition $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,(!empty($object->contact)?$object->contact:null),$usecontact,'targetwithdetails'); // Show recipient - $widthrecbox=100; + $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100; if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format - $posy=42; + $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42; $posx=$this->page_largeur - $this->marge_droite - $widthrecbox; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; // Show recipient frame $pdf->SetTextColor(0,0,0); $pdf->SetFont('','', $default_font_size - 2); - $pdf->SetXY($posx,$posy-5); - $pdf->MultiCell($widthrecbox, 4, $outputlangs->transnoentities("Recipient").":", 0, 'L'); + $pdf->SetXY($posx+2,$posy-5); + $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L'); $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); - $pdf->SetTextColor(0,0,0); // Show recipient name $pdf->SetXY($posx+2,$posy+3); $pdf->SetFont('','B', $default_font_size); - $pdf->MultiCell($widthrecbox, 4, $carac_client_name, 0, 'L'); + $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L'); $posy = $pdf->getY(); @@ -844,6 +941,7 @@ class pdf_rouget extends ModelePdfExpedition $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); } + $pdf->SetTextColor(0,0,0); } /** @@ -853,7 +951,7 @@ class pdf_rouget extends ModelePdfExpedition * @param Object $object Object to show * @param Translate $outputlangs Object lang for output * @param int $hidefreetext 1=Hide free text - * @return void + * @return int Return height of bottom margin including footer text */ function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) { diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 030a67a1c58c4851d36947c1707036e109aad36a..c971cb4e3fe46d42c919ee3e3204e59e343cfd0f 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -86,7 +86,6 @@ class pdf_crabe extends ModelePDFFactures $this->name = "crabe"; $this->description = $langs->trans('PDFCrabeDescription'); - // Dimension page pour format A4 $this->type = 'pdf'; $formatarray=pdf_getFormat(); $this->page_largeur = $formatarray['width']; @@ -673,20 +672,20 @@ class pdf_crabe extends ModelePDFFactures if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); - return 1; // Pas d'erreur + return 1; // No error } else { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); return 0; } } else { - $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); + $this->error=$langs->transnoentities("ErrorConstantNotDefined","FAC_OUTPUTDIR"); return 0; } - $this->error=$langs->trans("ErrorUnknown"); + $this->error=$langs->transnoentities("ErrorUnknown"); return 0; // Erreur par defaut } diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index b0bdbf75af333e2a880d3b7436a1f5a495093430..e51841ed4997436168a1df946ea50583bb54e0e1 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1251,44 +1251,13 @@ else if ($id || $ref) } - // Calculate true totalWeight and totalVolume for all products + + // Calculate totalWeight and totalVolume for all products // by adding weight and volume of each product line. - $totalWeight = ''; - $totalVolume = ''; - $weightUnit=0; - $volumeUnit=0; - for ($i = 0 ; $i < $num_prod ; $i++) - { - $weightUnit=0; - $volumeUnit=0; - if (! empty($lines[$i]->weight_units)) $weightUnit = $lines[$i]->weight_units; - if (! empty($lines[$i]->volume_units)) $volumeUnit = $lines[$i]->volume_units; - - // TODO Use a function addvalueunits(val1,unit1,val2,unit2)=>(val,unit) - if ($lines[$i]->weight_units < 50) - { - $trueWeightUnit=pow(10,$weightUnit); - $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped*$trueWeightUnit; - } - else - { - $trueWeightUnit=$weightUnit; - $totalWeight += $lines[$i]->weight*$lines[$i]->qty_shipped; - } - if ($lines[$i]->volume_units < 50) - { - //print $lines[$i]->volume."x".$lines[$i]->volume_units."x".($lines[$i]->volume_units < 50)."x".$volumeUnit; - $trueVolumeUnit=pow(10,$volumeUnit); - //print $lines[$i]->volume; - $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped*$trueVolumeUnit; - } - else - { - $trueVolumeUnit=$volumeUnit; - $totalVolume += $lines[$i]->volume*$lines[$i]->qty_shipped; - } - } - + $tmparray=$object->getTotalWeightVolume(); + $totalWeight=$tmparray['weight']; + $totalVolume=$tmparray['volume']; + print '<table class="border" width="100%">'; $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php">'.$langs->trans("BackToList").'</a>'; @@ -1391,7 +1360,8 @@ else if ($id || $ref) if ($totalWeight > 0) { if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': '; - print $totalWeight.' '.measuring_units_string(0,"weight"); + //print $totalWeight.' '.measuring_units_string(0,"weight"); + print showDimensionInBestUnit($totalWeight, 0, "weight", $langs); //if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')'; if (!empty($object->trueWeight)) print ')'; } @@ -1438,18 +1408,27 @@ else if ($id || $ref) print '</td>'; print '<td colspan="3">'; $calculatedVolume=0; - if ($object->trueWidth && $object->trueHeight && $object->trueDepth) $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth); + $volumeUnit=0; + if ($object->trueWidth && $object->trueHeight && $object->trueDepth) + { + $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth); + $volumeUnit=$object->size_units * 3; + } // If sending volume not defined we use sum of products if ($calculatedVolume > 0) { - print $calculatedVolume.' '; - if ($volumeUnit < 50) print measuring_units_string(0,"volume"); - else print measuring_units_string($volumeUnit,"volume"); + if ($volumeUnit < 50) + { + //print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume"); + print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs); + } + else print $calculatedVolume.' '.measuring_units_string($volumeUnit,"volume"); } if ($totalVolume > 0) { if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': '; - print $totalVolume.' '.measuring_units_string(0,"volume"); + //print $totalVolume.' '.measuring_units_string(0,"volume"); + print showDimensionInBestUnit($totalVolume, 0, "volume", $langs); //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')'; if ($calculatedVolume) print ')'; } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 62ffb53cc51fe94f5d796ff79302ebbc678e9f7a..1c0989797408d13df7d29f7645d498dee5ea0cdd 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1003,7 +1003,7 @@ class Expedition extends CommonObject if (isset($this->trueWeight)) $this->weight=trim($this->trueWeight); if (isset($this->note_private)) $this->note=trim($this->note_private); if (isset($this->note_public)) $this->note=trim($this->note_public); - if (isset($this->model_pdf)) $this->model_pdf=trim($this->model_pdf); + if (isset($this->modelpdf)) $this->modelpdf=trim($this->modelpdf); @@ -1035,7 +1035,7 @@ class Expedition extends CommonObject $sql.= " weight=".(($this->trueWeight != '')?$this->trueWeight:"null").","; $sql.= " note_private=".(isset($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null").","; $sql.= " note_public=".(isset($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null").","; - $sql.= " model_pdf=".(isset($this->model_pdf)?"'".$this->db->escape($this->model_pdf)."'":"null").","; + $sql.= " model_pdf=".(isset($this->modelpdf)?"'".$this->db->escape($this->modelpdf)."'":"null").","; $sql.= " entity=".$conf->entity; $sql.= " WHERE rowid=".$this->id; @@ -1742,6 +1742,52 @@ class Expedition extends CommonObject } + /** + * Return into unit=0, the calculated total of weight and volume of all lines * qty + * Calculate by adding weight and volume of each product line. + * + * @return array array('weight'=>...,'volume'=>...) + */ + function getTotalWeightVolume() + { + $weightUnit=0; + $volumeUnit=0; + $totalWeight = ''; + $totalVolume = ''; + foreach ($this->lines as $line) + { + $weightUnit=0; + $volumeUnit=0; + if (! empty($line->weight_units)) $weightUnit = $line->weight_units; + if (! empty($line->volume_units)) $volumeUnit = $line->volume_units; + + //var_dump($line->volume_units); + if ($line->weight_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) + { + $trueWeightUnit=pow(10,$weightUnit); + $totalWeight += $line->weight*$line->qty_shipped*$trueWeightUnit; + } + else + { + $totalWeight += $line->weight*$line->qty_shipped; // This may be wrong if we mix different units + } + if ($line->volume_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) + { + //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; + $trueVolumeUnit=pow(10,$volumeUnit); + //print $line->volume; + $totalVolume += $line->volume*$line->qty_shipped*$trueVolumeUnit; + } + else + { + $totalVolume += $line->volume*$line->qty_shipped; // This may be wrong if we mix different units + } + } + + return array('weight'=>$totalWeight, 'volume'=>$totalVolume); + } + + /** * Forge an set tracking url * diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index bba305a9f0a93005484849d494b51a9685cc8ea1..cd4b812ad54b8a02928e98ed4b28ced9bda389bf 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -70,6 +70,7 @@ ProductQtyInSuppliersOrdersRunning=Product quantity into opened suppliers orders ProductQtyInShipmentAlreadySent=Product quantity from opened customer order already sent ProductQtyInSuppliersShipmentAlreadyRecevied=Product quantity from opened supplier order already received NoProductToShipFoundIntoStock=No product to ship found into warehouse <b>%s</b>. Correct stock or go back to choose another warehouse. +WeightVolShort=Weight/Vol. # Sending methods SendingMethodCATCH=Catch by customer