From e6dabb0422b146b87f7d4f9cdf36c8816bce985b Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 10 Jun 2016 12:02:57 +0200 Subject: [PATCH 01/23] NEW : "dorade" expedition model with unit price ht and total ht --- .../expedition/doc/pdf_dorade.modules.php | 1023 +++++++++++++++++ htdocs/langs/fr_FR/sendings.lang | 1 + 2 files changed, 1024 insertions(+) create mode 100644 htdocs/core/modules/expedition/doc/pdf_dorade.modules.php diff --git a/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php b/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php new file mode 100644 index 00000000000..4c035bcef9e --- /dev/null +++ b/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php @@ -0,0 +1,1023 @@ + + * Copyright (C) 2005-2012 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014-2015 Marcos García + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/expedition/doc/pdf_dorade.modules.php + * \ingroup expedition + * \brief Fichier de la classe permettant de generer les bordereaux envoi au modele Dorade + */ + +require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; + + +/** + * Classe permettant de generer les borderaux envoi au modele Dorade + */ +class pdf_dorade extends ModelePdfExpedition +{ + var $emetteur; // Objet societe qui emet + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db=0) + { + global $conf,$langs,$mysoc; + + $this->db = $db; + $this->name = "dorade"; + $this->description = $langs->trans("DocumentModelDorade"); + + $this->type = 'pdf'; + $formatarray=pdf_getFormat(); + $this->page_largeur = $formatarray['width']; + $this->page_hauteur = $formatarray['height']; + $this->format = array($this->page_largeur,$this->page_hauteur); + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; + + $this->option_logo = 1; + + // Recupere emmetteur + $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 + $this->posxdesc=$this->marge_gauche+1; + $this->posxweightvol=$this->page_largeur - $this->marge_droite - 130; + $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 100; + $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 70; + $this->posxpuht=$this->page_largeur - $this->marge_droite - 40; + $this->posxtotalht=$this->page_largeur - $this->marge_droite - 20; + $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; + } + + if (! empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) + { + $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered); + $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered); + $this->posxqtyordered = $this->posxqtytoship; + } + } + + /** + * Function to build pdf onto disk + * + * @param Object $object Object expedition to generate (or id if old method) + * @param Translate $outputlangs Lang output object + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @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) + { + global $user,$conf,$langs,$hookmanager; + + $object->fetch_thirdparty(); + + if (! is_object($outputlangs)) $outputlangs=$langs; + // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO + if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; + + $outputlangs->load("main"); + $outputlangs->load("dict"); + $outputlangs->load("companies"); + $outputlangs->load("bills"); + $outputlangs->load("products"); + $outputlangs->load("propal"); + $outputlangs->load("deliveries"); + $outputlangs->load("sendings"); + $outputlangs->load("productbatch"); + + $nblignes = count($object->lines); + + // Loop on each lines to detect if there is at least one image to show + $realpatharray=array(); + if (! empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE)) + { + $objphoto = new Product($this->db); + + for ($i = 0 ; $i < $nblignes ; $i++) + { + if (empty($object->lines[$i]->fk_product)) continue; + + $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 + { + if ($obj['photo_vignette']) + { + $filename= $obj['photo_vignette']; + } + else + { + $filename=$obj['photo']; + } + } + else + { + $filename=$obj['photo']; + } + + $realpath = $dir.$filename; + break; + } + + if ($realpath) $realpatharray[$i]=$realpath; + } + } + + if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol; + + if ($conf->expedition->dir_output) + { + // Definition de $dir et $file + if ($object->specimen) + { + $dir = $conf->expedition->dir_output."/sending"; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $expref = dol_sanitizeFileName($object->ref); + $dir = $conf->expedition->dir_output."/sending/" . $expref; + $file = $dir . "/" . $expref . ".pdf"; + } + + if (! file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + if (file_exists($dir)) + { + // 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; + $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 = 8; // 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); + + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + // Set path to the background PDF File + if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) + { + $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $tplidx = $pdf->importPage(1); + } + + $pdf->Open(); + $pagenb=0; + $pdf->SetDrawColor(128,128,128); + + if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); + + $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); + $pdf->SetSubject($outputlangs->transnoentities("Shipment")); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); + $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment")); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + + $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right + + // New page + $pdf->AddPage(); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + $pagenb++; + $this->_pagehead($pdf, $object, 1, $outputlangs); + $pdf->SetFont('','', $default_font_size - 1); + $pdf->MultiCell(0, 3, ''); // Set interline to 3 + $pdf->SetTextColor(0,0,0); + + $tab_top = 90; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); + $tab_height = 130; + $tab_height_newpage = 150; + + // Incoterm + $height_incoterms = 0; + if ($conf->incoterm->enabled) + { + $desc_incoterms = $object->getIncotermsForPDF(); + if ($desc_incoterms) + { + $tab_top = 88; + + $pdf->SetFont('','', $default_font_size - 1); + $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1); + $nexY = $pdf->GetY(); + $height_incoterms=$nexY-$tab_top; + + // Rect prend une longueur en 3eme param + $pdf->SetDrawColor(192,192,192); + $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1); + + $tab_top = $nexY+6; + $height_incoterms += 4; + } + } + + if (! empty($object->note_public) || ! empty($object->tracking_number)) + { + $tab_top = 88 + $height_incoterms; + $tab_top_alt = $tab_top; + + $pdf->SetFont('','B', $default_font_size - 2); + $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L'); + + $tab_top_alt = $pdf->GetY(); + //$tab_top_alt += 1; + + // Tracking number + if (! empty($object->tracking_number)) + { + $object->GetUrlTrackingStatus($object->tracking_number); + if (! empty($object->tracking_url)) + { + if ($object->shipping_method_id > 0) + { + // Get code using getLabelFromKey + $code=$outputlangs->getLabelFromKey($this->db,$object->shipping_method_id,'c_shipment_mode','rowid','code'); + $label=''; + if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."
"; + $label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code)); + //var_dump($object->tracking_url != $object->tracking_number);exit; + if ($object->tracking_url != $object->tracking_number) + { + $label.=" : "; + $label.=$object->tracking_url; + } + $pdf->SetFont('','B', $default_font_size - 2); + $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L'); + + $tab_top_alt = $pdf->GetY(); + } + } + } + + // Notes + if (! empty($object->note_public)) + { + $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page + $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1); + } + + $nexY = $pdf->GetY(); + $height_note=$nexY-$tab_top; + + // Rect prend une longueur en 3eme param + $pdf->SetDrawColor(192,192,192); + $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); + + $tab_height = $tab_height - $height_note; + $tab_top = $nexY+6; + } + else + { + $height_note=0; + } + + $iniY = $tab_top + 7; + $curY = $tab_top + 7; + $nexY = $tab_top + 7; + + $num=count($object->lines); + // Loop on each lines + for ($i = 0; $i < $nblignes; $i++) + { + $curY = $nexY; + $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage + $pdf->SetTextColor(0,0,0); + + // Define size of image if we need it + $imglinesize=array(); + if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]); + + $pdf->setTopMargin($tab_top_newpage); + $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pageposbefore=$pdf->getPage(); + + $showpricebeforepagebreak=1; + $posYAfterImage=0; + $posYAfterDescription=0; + + // We start with Photo of product line + 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 + { + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + $pdf->setPage($pageposbefore+1); + + $curY = $tab_top_newpage; + $showpricebeforepagebreak=0; + } + + if (isset($imglinesize['width']) && isset($imglinesize['height'])) + { + $curX = $this->posxpicture-1; + $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']; + } + + // Description of product line + $curX = $this->posxdesc-1; + + $pdf->startTransaction(); + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); + + $pageposafter=$pdf->getPage(); + if ($pageposafter > $pageposbefore) // There is a pagebreak + { + $pdf->rollbackTransaction(true); + $pageposafter=$pageposbefore; + //print $pageposafter.'-'.$pageposbefore;exit; + $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); + + $pageposafter=$pdf->getPage(); + $posyafter=$pdf->GetY(); + //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; + if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text + { + if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page + { + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + $pdf->setPage($pageposafter+1); + } + } + else + { + // We found a page break + $showpricebeforepagebreak=0; + } + } + else // No pagebreak + { + $pdf->commitTransaction(); + } + $posYAfterDescription=$pdf->GetY(); + + $nexY = $pdf->GetY(); + $pageposafter=$pdf->getPage(); + + $pdf->setPage($pageposbefore); + $pdf->setTopMargin($this->marge_haute); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + + // We suppose that a too long description or photo were moved completely on next page + if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } + + // We suppose that a too long description is moved completely on next page + if ($pageposafter > $pageposbefore) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } + + $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?$object->lines[$i]->volume_units:0,"volume"); + } + + $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?', ':'').$voltxt,'','C'); + + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) + { + $pdf->SetXY($this->posxqtyordered, $curY); + $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked,'','C'); + } + + $pdf->SetXY($this->posxqtytoship, $curY); + $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C'); + + $pdf->SetXY($this->posxpuht, $curY); + $pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs),'','R'); + + $pdf->SetXY($this->posxtotalht, $curY); + $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs),'','R'); + + // Add line + if ($conf->global->MAIN_PDF_DASH_BETWEEN_LINES && $i < ($nblignes - 1)) + { + $pdf->setPage($pageposafter); + $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80))); + //$pdf->SetDrawColor(190,190,200); + $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); + $pdf->SetLineStyle(array('dash'=>0)); + } + + $nexY+=2; // Passe espace entre les lignes + + // Detect if some page were added automatically and output _tableau for past pages + while ($pagenb < $pageposafter) + { + $pdf->setPage($pagenb); + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); + $pagenb++; + $pdf->setPage($pagenb); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + } + if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) + { + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); + // New page + $pdf->AddPage(); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + $pagenb++; + } + } + + // Show square + if ($pagenb == 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 - $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(); + + $pdf->Close(); + + $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; + $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); + + return 1; // No error + } + else + { + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); + return 0; + } + } + else + { + $this->error=$langs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR"); + return 0; + } + $this->error=$langs->transnoentities("ErrorUnknown"); + 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('','B', $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; + }*/ + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol); + else $largcol2 = ($this->posxqtytoship - $this->posxweightvol); + + $useborder=0; + $index = 0; + + $totalWeighttoshow=''; + $totalVolumetoshow=''; + + // Load dim data + $tmparray=$object->getTotalWeightVolume(); + $totalWeight=$tmparray['weight']; + $totalVolume=$tmparray['volume']; + $totalOrdered=$tmparray['ordered']; + $totalToShip=$tmparray['toship']; + // 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); + + $pdf->SetFillColor(255,255,255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1); + + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) + { + $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1); + } + + //var_dump($object);exit; + + $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1); + + $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1); + + $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->largeur_page - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1); + + // Total Weight + if ($totalWeighttoshow) + { + $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2+20, $tab2_hl, $totalWeighttoshow, 0, 'R', 1); + + $index++; + } + if ($totalVolumetoshow) + { + $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2+20, $tab2_hl, $totalVolumetoshow, 0, 'R', 1); + + $index++; + } + if (! $totalWeighttoshow && ! $totalVolumetoshow) $index++; + + $pdf->SetTextColor(0,0,0); + + return ($tab2_top + ($tab2_hl * $index)); + } + + /** + * Show table for lines + * + * @param PDF $pdf Object PDF + * @param string $tab_top Top position of table + * @param string $tab_height Height of table (rectangle) + * @param int $nexY Y + * @param Translate $outputlangs Langs object + * @param int $hidetop Hide top bar of array + * @param int $hidebottom Hide bottom bar of array + * @return void + */ + function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) + { + global $conf; + + // Force to disable hidetop and hidebottom + $hidebottom=0; + if ($hidetop) $hidetop=-1; + + $default_font_size = pdf_getPDFFontSize($outputlangs); + + // Amount in (at tab_top - 1) + $pdf->SetTextColor(0,0,0); + $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); + + if (empty($hidetop)) + { + $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); + + $pdf->SetXY($this->posxdesc-1, $tab_top+1); + $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'); + } + + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) + { + $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->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"),'','C'); + } + } + + $pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxqtytoship, $tab_top+1); + $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C'); + } + + $pdf->line($this->posxpuht-1, $tab_top, $this->posxpuht-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxpuht-1, $tab_top+1); + $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"),'','C'); + } + + $pdf->line($this->posxtotalht-1, $tab_top, $this->posxtotalht-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxtotalht-1, $tab_top+1); + $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"),'','C'); + } + + } + + /** + * Show top header of page. + * + * @param PDF $pdf Object PDF + * @param Object $object Object to show + * @param int $showaddress 0=no, 1=yes + * @param Translate $outputlangs Object lang for output + * @return void + */ + function _pagehead(&$pdf, $object, $showaddress, $outputlangs) + { + global $conf,$langs,$mysoc; + $default_font_size = pdf_getPDFFontSize($outputlangs); + $langs->load("orders"); + + pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); + + // 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); + } + + //Prepare la suite + $pdf->SetTextColor(0,0,60); + $pdf->SetFont('','B', $default_font_size + 3); + + $w = 110; + $posx=$this->page_largeur-$this->marge_droite-100; + $posy=$this->marge_haute; + + $pdf->SetXY($this->marge_gauche,$posy); + + // Logo + $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; + if ($this->emetteur->logo) + { + if (is_readable($logo)) + { + $height=pdf_getHeightForLogo($logo); + $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) + } + else + { + $pdf->SetTextColor(200,0,0); + $pdf->SetFont('','B', $default_font_size - 2); + $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($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); + } + + // Show barcode + if (! empty($conf->barcode->enabled)) + { + $posx=105; + } + else + { + $posx=$this->marge_gauche+3; + } + //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30); + if (! empty($conf->barcode->enabled)) + { + // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref + //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); + //$pdf->Image($logo,10, 5, 0, 24); + } + + $pdf->SetDrawColor(128,128,128); + if (! empty($conf->barcode->enabled)) + { + // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref + //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); + //$pdf->Image($logo,10, 5, 0, 24); + } + + + $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($w, 4, $title, '', 'R'); + $posy+=1; + + $pdf->SetFont('','', $default_font_size + 1); + + $posy+=4; + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R'); + + // Date planned delivery + if (! empty($object->date_delivery)) + { + $posy+=4; + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R'); + } + + if (! empty($object->thirdparty->code_client)) + { + $posy+=4; + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R'); + } + + + $pdf->SetFont('','', $default_font_size + 3); + $Yoff=25; + + // Add list of linked orders + // TODO possibility to use with other document (business module,...) + //$object->load_object_linked(); + + $origin = $object->origin; + $origin_id = $object->origin_id; + + // TODO move to external function + if (! empty($conf->$origin->enabled)) + { + $outputlangs->load('orders'); + + $classname = ucfirst($origin); + $linkedobject = new $classname($this->db); + $result=$linkedobject->fetch($origin_id); + if ($result >= 0) + { + $pdf->SetFont('','', $default_font_size - 2); + $text=$linkedobject->ref; + if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')'; + $Yoff = $Yoff+8; + $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 - $w,$Yoff); + $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R'); + } + } + + if ($showaddress) + { + // Sender properties + $carac_emetteur=''; + // Add internal contact of origin element if defined + $arrayidcontact=array(); + if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal','SALESREPFOLL'); + if (count($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->thirdparty); + + // Show sender + $posx=$this->marge_gauche; + $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 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); + $pdf->SetXY($posx,$posy-5); + $pdf->MultiCell(66,5, $outputlangs->transnoentities("Sender").":", 0, 'L'); + $pdf->SetXY($posx,$posy); + $pdf->SetFillColor(230,230,230); + $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($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->SetFont('','', $default_font_size - 1); + $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L'); + + + // If SHIPPING contact defined, we use it + $usecontact=false; + $arrayidcontact=$object->$origin->getIdContact('external','SHIPPING'); + if (count($arrayidcontact) > 0) + { + $usecontact=true; + $result=$object->fetch_contact($arrayidcontact[0]); + } + + //Recipient name + // On peut utiliser le nom de la societe du contact + if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { + $thirdparty = $object->contact; + } else { + $thirdparty = $object->thirdparty; + } + + $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs); + + $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,(!empty($object->contact)?$object->contact:null),$usecontact,'targetwithdetails',$object); + + // Show recipient + $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=!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+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, 2, $carac_client_name, 0, 'L'); + + $posy = $pdf->getY(); + + // Show recipient information + $pdf->SetFont('','', $default_font_size - 1); + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); + } + + $pdf->SetTextColor(0,0,0); + } + + /** + * Show footer of page. Need this->emetteur object + * + * @param PDF $pdf PDF + * @param Object $object Object to show + * @param Translate $outputlangs Object lang for output + * @param int $hidefreetext 1=Hide free text + * @return int Return height of bottom margin including footer text + */ + function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) + { + global $conf; + $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; + return pdf_pagefoot($pdf,$outputlangs,'SHIPPING_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); + } + +} + diff --git a/htdocs/langs/fr_FR/sendings.lang b/htdocs/langs/fr_FR/sendings.lang index ee6ee57b453..9662b94ee25 100644 --- a/htdocs/langs/fr_FR/sendings.lang +++ b/htdocs/langs/fr_FR/sendings.lang @@ -51,6 +51,7 @@ GenericTransport=Transporteur générique Enlevement=Enlèvement sur place par le client DocumentModelSimple=Modèle simple DocumentModelMerou=Modèle Merou A5 +DocumentModelDorade=Modèle d'expédition chiffré WarningNoQtyLeftToSend=Alerte, aucun produit en attente d'expédition. StatsOnShipmentsOnlyValidated=Statistiques effectuées sur les expéditions validées uniquement. La date prise en compte est la date de validation (la date de prévision de livraison n'étant pas toujours renseignée). DateDeliveryPlanned=Date prévue de livraison From 6c08fbb630eba853c9cab0a3cfef1f86af1bcd39 Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 10 Jun 2016 12:08:50 +0200 Subject: [PATCH 02/23] FIX : langs just in en_US --- htdocs/langs/en_US/sendings.lang | 1 + htdocs/langs/fr_FR/sendings.lang | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index 1ec229af6c5..a36a8a1ae11 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -51,6 +51,7 @@ GenericTransport=Generic transport Enlevement=Gotten by customer DocumentModelSimple=Simple document model DocumentModelMerou=Merou A5 model +DocumentModelDorade=Model with amounts WarningNoQtyLeftToSend=Warning, no products waiting to be shipped. StatsOnShipmentsOnlyValidated=Statistics conducted on shipments only validated. Date used is date of validation of shipment (planed delivery date is not always known). DateDeliveryPlanned=Planned date of delivery diff --git a/htdocs/langs/fr_FR/sendings.lang b/htdocs/langs/fr_FR/sendings.lang index 9662b94ee25..ee6ee57b453 100644 --- a/htdocs/langs/fr_FR/sendings.lang +++ b/htdocs/langs/fr_FR/sendings.lang @@ -51,7 +51,6 @@ GenericTransport=Transporteur générique Enlevement=Enlèvement sur place par le client DocumentModelSimple=Modèle simple DocumentModelMerou=Modèle Merou A5 -DocumentModelDorade=Modèle d'expédition chiffré WarningNoQtyLeftToSend=Alerte, aucun produit en attente d'expédition. StatsOnShipmentsOnlyValidated=Statistiques effectuées sur les expéditions validées uniquement. La date prise en compte est la date de validation (la date de prévision de livraison n'étant pas toujours renseignée). DateDeliveryPlanned=Date prévue de livraison From 77071ca515120c2cf2dc852e33c8c9607700c34a Mon Sep 17 00:00:00 2001 From: frederic34 Date: Sun, 19 Jun 2016 18:53:19 +0200 Subject: [PATCH 03/23] select bank and payment mode for social contrib --- htdocs/compta/bank/treso.php | 2 + htdocs/compta/paiement_charge.php | 35 ++++---- htdocs/compta/sociales/charges.php | 84 +++++++++++++++++-- .../sociales/class/chargesociales.class.php | 34 +++++--- 4 files changed, 120 insertions(+), 35 deletions(-) diff --git a/htdocs/compta/bank/treso.php b/htdocs/compta/bank/treso.php index 26be80caa68..273477c2091 100644 --- a/htdocs/compta/bank/treso.php +++ b/htdocs/compta/bank/treso.php @@ -166,10 +166,12 @@ if ($_REQUEST["account"] || $_REQUEST["ref"]) // Social contributions $sql3= " SELECT 'social_contribution' as family, cs.rowid as objid, cs.libelle as ref, (-1*cs.amount) as total_ttc, ccs.libelle as type, cs.date_ech as dlr"; + $sql3.= ", cs.fk_account"; $sql3.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; $sql3.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id"; $sql3.= " WHERE cs.entity = ".$conf->entity; $sql3.= " AND cs.paye = 0"; // Not paid + $sql3.= " AND (cs.fk_account IN (0, ".$acct->id.") OR cs.fk_account IS NULL)"; // Id bank account of social contribution $sql3.= " ORDER BY dlr ASC"; $error=0; diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index a68f3445305..06a32c3865f 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -1,5 +1,6 @@ + * Copyright (C) 2016 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -159,6 +160,8 @@ if ($_GET["action"] == 'create') $charge = new ChargeSociales($db); $charge->fetch($chid); + $charge->accountid=$charge->fk_account?$charge->fk_account:$charge->accountid; + $charge->paiementtype=$charge->mode_reglement_id?$charge->mode_reglement_id:$charge->paiementtype; $total = $charge->amount; @@ -178,16 +181,16 @@ if ($_GET["action"] == 'create') dol_fiche_head('', ''); - print ''; + print '
'; - print ""; + print ""; - print ''; - print '\n"; - print '\n"; - print '\n"; - print '\n"; - print ''; + print ''; + print '\n"; + print '\n"; + print '\n"; + print '\n"; + print ''; $sql = "SELECT sum(p.amount) as total"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; @@ -199,28 +202,28 @@ if ($_GET["action"] == 'create') $sumpaid = $obj->total; $db->free(); } - print ''; - print ''; + print ''; + print ''; print ''; - print "'; + print "'; print ''; - print '"; print ''; - print '\n"; print ''; print ''; print ''; - print ''; @@ -228,11 +231,11 @@ if ($_GET["action"] == 'create') print ''; - print ''."\n"; + print ''."\n"; print ''; print ''; - print ''; + print ''; print ''; print '
".$langs->trans("SocialContribution")."
".$langs->trans("SocialContribution")."
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Type")."".$charge->type_libelle."
'.$langs->trans("Period")."".dol_print_date($charge->periode,'day')."
'.$langs->trans("Label").''.$charge->lib."
'.$langs->trans("DateDue")."".dol_print_date($charge->date_ech,'day')."
'.$langs->trans("Amount")."".price($charge->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Type")."".$charge->type_libelle."
'.$langs->trans("Period")."".dol_print_date($charge->periode,'day')."
'.$langs->trans("Label").''.$charge->lib."
'.$langs->trans("DateDue")."".dol_print_date($charge->date_ech,'day')."
'.$langs->trans("Amount")."".price($charge->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
".$langs->trans("Payment").'".$langs->trans("Payment").'
'.$langs->trans("Date").''; + print '
'.$langs->trans("Date").''; $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0; $form->select_date($datepayment,'','','','',"add_payment",1,1); print "
'.$langs->trans("PaymentMode").''; + print '
'.$langs->trans("PaymentMode").''; $form->select_types_paiements(isset($_POST["paiementtype"])?$_POST["paiementtype"]:$charge->paiementtype, "paiementtype"); print "
'.$langs->trans('AccountToDebit').''; + print ''; $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, '',1); // Show opend bank account list print '
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'.$langs->trans("Comments").'
'; diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 6e7c9ad93c2..f5a6cc2f6a9 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -1,6 +1,7 @@ * Copyright (C) 2005-2013 Regis Houssin + * Copyright (C) 2016 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -71,6 +72,23 @@ if ($action == 'reopen' && $user->rights->tax->charges->creer) { } } +// payment mode +if ($action == 'setmode' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); +} + +// bank account +if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result=$object->setBankAccount(GETPOST('fk_account', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + // Delete social contribution if ($action == 'confirm_delete' && $confirm == 'yes') { @@ -127,6 +145,8 @@ if ($action == 'add' && $user->rights->tax->charges->creer) $object->date_ech=$dateech; $object->periode=$dateperiod; $object->amount=$amount; + $object->mode_reglement_id = GETPOST('mode_reglement_id'); + $object->fk_account = GETPOST('fk_account', 'int'); $id=$object->create($user); if ($id <= 0) @@ -290,6 +310,17 @@ if ($action == 'create') print ''; print ''; print ''; + // Payment Mode + print '' . $langs->trans('PaymentMode') . ''; + $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id'); + print ''; + // Bank Account + if (! empty($conf->banque->enabled)) + { + print '' . $langs->trans('BankAccount') . ''; + $form->select_comptes($fk_account, 'fk_account', 0, '', 1); + print ''; + } // Date due print ''; print ''; @@ -313,7 +344,7 @@ if ($action == 'create') /* *************************************************************************** */ /* */ -/* Mode fiche */ +/* Card Mode */ /* */ /* *************************************************************************** */ if ($id > 0) @@ -382,7 +413,8 @@ if ($id > 0) // Type print "".$langs->trans("Type")."".$object->type_libelle.""; - $rowspan=5; + $rowspan=6; + if (! empty($conf->banque->enabled)) $rowspan++; print ''; /* @@ -422,8 +454,8 @@ if ($id > 0) print ""; print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''; print ''.dol_print_date($db->jdate($objp->dp),'day')."\n"; - $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type; - print "".$labeltype.' '.$objp->num_paiement."\n"; + $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type; + print "".$labeltype.' '.$objp->num_paiement."\n"; print ''.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; print ""; $totalpaye += $objp->amount; @@ -432,12 +464,12 @@ if ($id > 0) if ($object->paye == 0) { - print "".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."\n"; - print "".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; + print "".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."\n"; + print "".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; $resteapayer = $object->amount - $totalpaye; - print "".$langs->trans("RemainderToPay")." :"; + print "".$langs->trans("RemainderToPay")." :"; print "".price($resteapayer)." ".$langs->trans("Currency".$conf->currency)."\n"; } print ""; @@ -486,6 +518,42 @@ if ($id > 0) print ''.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).''; } + // Mode of payment + print ''; + print ''; + if ($action != 'editmode') + print ''; + print '
'; + print $langs->trans('PaymentMode'); + print 'id . '">' . img_edit($langs->trans('SetMode'), 1) . '
'; + print ''; + if ($action == 'editmode') { + $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id'); + } else { + $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none'); + } + print ''; + + // Bank Account + if (! empty($conf->banque->enabled)) + { + print ''; + print ''; + print '
'; + print $langs->trans('BankAccount'); + print ''; + if ($action != 'editbankaccount' && $user->rights->tax->charges->creer) + print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; + print ''; + if ($action == 'editbankaccount') { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } else { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + } + print ''; + print ''; + } + // Status print ''.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).''; @@ -500,7 +568,7 @@ if ($id > 0) print ''; print '   '; print ''; - print ''; } if ($action == 'edit') print "\n"; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index e5653ba2ee3..af3acbf4c7f 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2016 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,6 +50,7 @@ class ChargeSociales extends CommonObject var $date_creation; var $date_modification; var $date_validation; + var $fk_account; /** @@ -71,13 +73,16 @@ class ChargeSociales extends CommonObject */ function fetch($id, $ref='') { - $sql = "SELECT cs.rowid, cs.date_ech,"; - $sql.= " cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode, cs.import_key,"; - $sql.= " c.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs, ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= " WHERE cs.fk_type = c.id"; - if ($ref) $sql.= " AND cs.rowid = ".$ref; - else $sql.= " AND cs.rowid = ".$id; + $sql = "SELECT cs.rowid, cs.date_ech"; + $sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode, cs.import_key"; + $sql.= ", cs.fk_account, cs.fk_mode_reglement"; + $sql.= ", c.libelle"; + $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; + $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id'; + if ($ref) $sql.= " WHERE cs.rowid = ".$ref; + else $sql.= " WHERE cs.rowid = ".$id; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); @@ -93,6 +98,10 @@ class ChargeSociales extends CommonObject $this->lib = $obj->lib; $this->type = $obj->fk_type; $this->type_libelle = $obj->libelle; + $this->fk_account = $obj->fk_account; + $this->mode_reglement_id = $obj->fk_mode_reglement; + $this->mode_reglement_code = $obj->mode_reglement_code; + $this->mode_reglement = $obj->mode_reglement_libelle; $this->amount = $obj->amount; $this->paye = $obj->paye; $this->periode = $this->db->jdate($obj->periode); @@ -155,8 +164,11 @@ class ChargeSociales extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount, entity)"; - $sql.= " VALUES (".$this->type.",'".$this->db->escape($this->lib)."',"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, entity)"; + $sql.= " VALUES (".$this->type; + $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL'); + $sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"NULL"); + $sql.= ", '".$this->db->escape($this->lib)."',"; $sql.= " '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."',"; $sql.= " '".price2num($newamount)."',"; $sql.= " ".$conf->entity; @@ -216,7 +228,7 @@ class ChargeSociales extends CommonObject // Delete payments if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge where fk_charge='".$this->id."'"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge='".$this->id."'"; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) @@ -228,7 +240,7 @@ class ChargeSociales extends CommonObject if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid='".$this->id."'"; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) From e71833c0d98a22ef941278b7ae74518766b4e233 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Sun, 19 Jun 2016 20:24:20 +0200 Subject: [PATCH 04/23] typo --- htdocs/compta/bank/treso.php | 1 + htdocs/compta/sociales/index.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/bank/treso.php b/htdocs/compta/bank/treso.php index 273477c2091..e9596149e4f 100644 --- a/htdocs/compta/bank/treso.php +++ b/htdocs/compta/bank/treso.php @@ -3,6 +3,7 @@ * Copyright (C) 2008-2009 Laurent Destailleur (Eldy) * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2015 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/compta/sociales/index.php b/htdocs/compta/sociales/index.php index b673a5064ed..15ca799c1c2 100644 --- a/htdocs/compta/sociales/index.php +++ b/htdocs/compta/sociales/index.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2003 Rodolphe Quiedeville * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2016 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -255,7 +256,7 @@ if ($resql) // Due date print ''.dol_print_date($db->jdate($obj->date_ech), 'day').''; - print ''.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).''; + print ''.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).''; print ''; From 1233c443333faa86ca48d5dda3e69aa92cb1bca2 Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 24 Jun 2016 12:39:54 +0200 Subject: [PATCH 05/23] FIX : hidden configuration on pdf rouget for amount ht display to avoid using new model --- .../expedition/doc/pdf_dorade.modules.php | 1023 ----------------- .../expedition/doc/pdf_rouget.modules.php | 57 +- 2 files changed, 54 insertions(+), 1026 deletions(-) delete mode 100644 htdocs/core/modules/expedition/doc/pdf_dorade.modules.php diff --git a/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php b/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php deleted file mode 100644 index 4c035bcef9e..00000000000 --- a/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php +++ /dev/null @@ -1,1023 +0,0 @@ - - * Copyright (C) 2005-2012 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2014-2015 Marcos García - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * or see http://www.gnu.org/ - */ - -/** - * \file htdocs/core/modules/expedition/doc/pdf_dorade.modules.php - * \ingroup expedition - * \brief Fichier de la classe permettant de generer les bordereaux envoi au modele Dorade - */ - -require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; - - -/** - * Classe permettant de generer les borderaux envoi au modele Dorade - */ -class pdf_dorade extends ModelePdfExpedition -{ - var $emetteur; // Objet societe qui emet - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db=0) - { - global $conf,$langs,$mysoc; - - $this->db = $db; - $this->name = "dorade"; - $this->description = $langs->trans("DocumentModelDorade"); - - $this->type = 'pdf'; - $formatarray=pdf_getFormat(); - $this->page_largeur = $formatarray['width']; - $this->page_hauteur = $formatarray['height']; - $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; - $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; - $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; - $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; - - $this->option_logo = 1; - - // Recupere emmetteur - $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 - $this->posxdesc=$this->marge_gauche+1; - $this->posxweightvol=$this->page_largeur - $this->marge_droite - 130; - $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 100; - $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 70; - $this->posxpuht=$this->page_largeur - $this->marge_droite - 40; - $this->posxtotalht=$this->page_largeur - $this->marge_droite - 20; - $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; - } - - if (! empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) - { - $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered); - $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered); - $this->posxqtyordered = $this->posxqtytoship; - } - } - - /** - * Function to build pdf onto disk - * - * @param Object $object Object expedition to generate (or id if old method) - * @param Translate $outputlangs Lang output object - * @param string $srctemplatepath Full path of source filename for generator using a template file - * @param int $hidedetails Do not show line details - * @param int $hidedesc Do not show desc - * @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) - { - global $user,$conf,$langs,$hookmanager; - - $object->fetch_thirdparty(); - - if (! is_object($outputlangs)) $outputlangs=$langs; - // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO - if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; - - $outputlangs->load("main"); - $outputlangs->load("dict"); - $outputlangs->load("companies"); - $outputlangs->load("bills"); - $outputlangs->load("products"); - $outputlangs->load("propal"); - $outputlangs->load("deliveries"); - $outputlangs->load("sendings"); - $outputlangs->load("productbatch"); - - $nblignes = count($object->lines); - - // Loop on each lines to detect if there is at least one image to show - $realpatharray=array(); - if (! empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE)) - { - $objphoto = new Product($this->db); - - for ($i = 0 ; $i < $nblignes ; $i++) - { - if (empty($object->lines[$i]->fk_product)) continue; - - $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 - { - if ($obj['photo_vignette']) - { - $filename= $obj['photo_vignette']; - } - else - { - $filename=$obj['photo']; - } - } - else - { - $filename=$obj['photo']; - } - - $realpath = $dir.$filename; - break; - } - - if ($realpath) $realpatharray[$i]=$realpath; - } - } - - if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol; - - if ($conf->expedition->dir_output) - { - // Definition de $dir et $file - if ($object->specimen) - { - $dir = $conf->expedition->dir_output."/sending"; - $file = $dir . "/SPECIMEN.pdf"; - } - else - { - $expref = dol_sanitizeFileName($object->ref); - $dir = $conf->expedition->dir_output."/sending/" . $expref; - $file = $dir . "/" . $expref . ".pdf"; - } - - if (! file_exists($dir)) - { - if (dol_mkdir($dir) < 0) - { - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); - return 0; - } - } - - if (file_exists($dir)) - { - // 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; - $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 = 8; // 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); - - if (class_exists('TCPDF')) - { - $pdf->setPrintHeader(false); - $pdf->setPrintFooter(false); - } - $pdf->SetFont(pdf_getPDFFont($outputlangs)); - // Set path to the background PDF File - if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) - { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); - $tplidx = $pdf->importPage(1); - } - - $pdf->Open(); - $pagenb=0; - $pdf->SetDrawColor(128,128,128); - - if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); - - $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); - $pdf->SetSubject($outputlangs->transnoentities("Shipment")); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); - $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment")); - if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); - - $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right - - // New page - $pdf->AddPage(); - if (! empty($tplidx)) $pdf->useTemplate($tplidx); - $pagenb++; - $this->_pagehead($pdf, $object, 1, $outputlangs); - $pdf->SetFont('','', $default_font_size - 1); - $pdf->MultiCell(0, 3, ''); // Set interline to 3 - $pdf->SetTextColor(0,0,0); - - $tab_top = 90; - $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); - $tab_height = 130; - $tab_height_newpage = 150; - - // Incoterm - $height_incoterms = 0; - if ($conf->incoterm->enabled) - { - $desc_incoterms = $object->getIncotermsForPDF(); - if ($desc_incoterms) - { - $tab_top = 88; - - $pdf->SetFont('','', $default_font_size - 1); - $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1); - $nexY = $pdf->GetY(); - $height_incoterms=$nexY-$tab_top; - - // Rect prend une longueur en 3eme param - $pdf->SetDrawColor(192,192,192); - $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1); - - $tab_top = $nexY+6; - $height_incoterms += 4; - } - } - - if (! empty($object->note_public) || ! empty($object->tracking_number)) - { - $tab_top = 88 + $height_incoterms; - $tab_top_alt = $tab_top; - - $pdf->SetFont('','B', $default_font_size - 2); - $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L'); - - $tab_top_alt = $pdf->GetY(); - //$tab_top_alt += 1; - - // Tracking number - if (! empty($object->tracking_number)) - { - $object->GetUrlTrackingStatus($object->tracking_number); - if (! empty($object->tracking_url)) - { - if ($object->shipping_method_id > 0) - { - // Get code using getLabelFromKey - $code=$outputlangs->getLabelFromKey($this->db,$object->shipping_method_id,'c_shipment_mode','rowid','code'); - $label=''; - if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."
"; - $label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code)); - //var_dump($object->tracking_url != $object->tracking_number);exit; - if ($object->tracking_url != $object->tracking_number) - { - $label.=" : "; - $label.=$object->tracking_url; - } - $pdf->SetFont('','B', $default_font_size - 2); - $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L'); - - $tab_top_alt = $pdf->GetY(); - } - } - } - - // Notes - if (! empty($object->note_public)) - { - $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page - $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1); - } - - $nexY = $pdf->GetY(); - $height_note=$nexY-$tab_top; - - // Rect prend une longueur en 3eme param - $pdf->SetDrawColor(192,192,192); - $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); - - $tab_height = $tab_height - $height_note; - $tab_top = $nexY+6; - } - else - { - $height_note=0; - } - - $iniY = $tab_top + 7; - $curY = $tab_top + 7; - $nexY = $tab_top + 7; - - $num=count($object->lines); - // Loop on each lines - for ($i = 0; $i < $nblignes; $i++) - { - $curY = $nexY; - $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage - $pdf->SetTextColor(0,0,0); - - // Define size of image if we need it - $imglinesize=array(); - if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]); - - $pdf->setTopMargin($tab_top_newpage); - $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. - $pageposbefore=$pdf->getPage(); - - $showpricebeforepagebreak=1; - $posYAfterImage=0; - $posYAfterDescription=0; - - // We start with Photo of product line - 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 - { - $pdf->AddPage('','',true); - if (! empty($tplidx)) $pdf->useTemplate($tplidx); - if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); - $pdf->setPage($pageposbefore+1); - - $curY = $tab_top_newpage; - $showpricebeforepagebreak=0; - } - - if (isset($imglinesize['width']) && isset($imglinesize['height'])) - { - $curX = $this->posxpicture-1; - $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']; - } - - // Description of product line - $curX = $this->posxdesc-1; - - $pdf->startTransaction(); - pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); - - $pageposafter=$pdf->getPage(); - if ($pageposafter > $pageposbefore) // There is a pagebreak - { - $pdf->rollbackTransaction(true); - $pageposafter=$pageposbefore; - //print $pageposafter.'-'.$pageposbefore;exit; - $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. - pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); - - $pageposafter=$pdf->getPage(); - $posyafter=$pdf->GetY(); - //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; - if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text - { - if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page - { - $pdf->AddPage('','',true); - if (! empty($tplidx)) $pdf->useTemplate($tplidx); - if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); - $pdf->setPage($pageposafter+1); - } - } - else - { - // We found a page break - $showpricebeforepagebreak=0; - } - } - else // No pagebreak - { - $pdf->commitTransaction(); - } - $posYAfterDescription=$pdf->GetY(); - - $nexY = $pdf->GetY(); - $pageposafter=$pdf->getPage(); - - $pdf->setPage($pageposbefore); - $pdf->setTopMargin($this->marge_haute); - $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. - - // We suppose that a too long description or photo were moved completely on next page - if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { - $pdf->setPage($pageposafter); $curY = $tab_top_newpage; - } - - // We suppose that a too long description is moved completely on next page - if ($pageposafter > $pageposbefore) { - $pdf->setPage($pageposafter); $curY = $tab_top_newpage; - } - - $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?$object->lines[$i]->volume_units:0,"volume"); - } - - $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?', ':'').$voltxt,'','C'); - - if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) - { - $pdf->SetXY($this->posxqtyordered, $curY); - $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked,'','C'); - } - - $pdf->SetXY($this->posxqtytoship, $curY); - $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C'); - - $pdf->SetXY($this->posxpuht, $curY); - $pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs),'','R'); - - $pdf->SetXY($this->posxtotalht, $curY); - $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs),'','R'); - - // Add line - if ($conf->global->MAIN_PDF_DASH_BETWEEN_LINES && $i < ($nblignes - 1)) - { - $pdf->setPage($pageposafter); - $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80))); - //$pdf->SetDrawColor(190,190,200); - $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); - $pdf->SetLineStyle(array('dash'=>0)); - } - - $nexY+=2; // Passe espace entre les lignes - - // Detect if some page were added automatically and output _tableau for past pages - while ($pagenb < $pageposafter) - { - $pdf->setPage($pagenb); - if ($pagenb == 1) - { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); - } - else - { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); - } - $this->_pagefoot($pdf,$object,$outputlangs,1); - $pagenb++; - $pdf->setPage($pagenb); - $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. - } - if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) - { - if ($pagenb == 1) - { - $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); - } - else - { - $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); - } - $this->_pagefoot($pdf,$object,$outputlangs,1); - // New page - $pdf->AddPage(); - if (! empty($tplidx)) $pdf->useTemplate($tplidx); - $pagenb++; - } - } - - // Show square - if ($pagenb == 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 - $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(); - - $pdf->Close(); - - $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; - $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - - if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); - - return 1; // No error - } - else - { - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); - return 0; - } - } - else - { - $this->error=$langs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR"); - return 0; - } - $this->error=$langs->transnoentities("ErrorUnknown"); - 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('','B', $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; - }*/ - if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol); - else $largcol2 = ($this->posxqtytoship - $this->posxweightvol); - - $useborder=0; - $index = 0; - - $totalWeighttoshow=''; - $totalVolumetoshow=''; - - // Load dim data - $tmparray=$object->getTotalWeightVolume(); - $totalWeight=$tmparray['weight']; - $totalVolume=$tmparray['volume']; - $totalOrdered=$tmparray['ordered']; - $totalToShip=$tmparray['toship']; - // 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); - - $pdf->SetFillColor(255,255,255); - $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1); - - if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) - { - $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1); - } - - //var_dump($object);exit; - - $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1); - - $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1); - - $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($this->largeur_page - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1); - - // Total Weight - if ($totalWeighttoshow) - { - $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($largcol2+20, $tab2_hl, $totalWeighttoshow, 0, 'R', 1); - - $index++; - } - if ($totalVolumetoshow) - { - $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($largcol2+20, $tab2_hl, $totalVolumetoshow, 0, 'R', 1); - - $index++; - } - if (! $totalWeighttoshow && ! $totalVolumetoshow) $index++; - - $pdf->SetTextColor(0,0,0); - - return ($tab2_top + ($tab2_hl * $index)); - } - - /** - * Show table for lines - * - * @param PDF $pdf Object PDF - * @param string $tab_top Top position of table - * @param string $tab_height Height of table (rectangle) - * @param int $nexY Y - * @param Translate $outputlangs Langs object - * @param int $hidetop Hide top bar of array - * @param int $hidebottom Hide bottom bar of array - * @return void - */ - function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) - { - global $conf; - - // Force to disable hidetop and hidebottom - $hidebottom=0; - if ($hidetop) $hidetop=-1; - - $default_font_size = pdf_getPDFFontSize($outputlangs); - - // Amount in (at tab_top - 1) - $pdf->SetTextColor(0,0,0); - $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); - - if (empty($hidetop)) - { - $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); - - $pdf->SetXY($this->posxdesc-1, $tab_top+1); - $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'); - } - - if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) - { - $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->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"),'','C'); - } - } - - $pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height); - if (empty($hidetop)) - { - $pdf->SetXY($this->posxqtytoship, $tab_top+1); - $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C'); - } - - $pdf->line($this->posxpuht-1, $tab_top, $this->posxpuht-1, $tab_top + $tab_height); - if (empty($hidetop)) - { - $pdf->SetXY($this->posxpuht-1, $tab_top+1); - $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"),'','C'); - } - - $pdf->line($this->posxtotalht-1, $tab_top, $this->posxtotalht-1, $tab_top + $tab_height); - if (empty($hidetop)) - { - $pdf->SetXY($this->posxtotalht-1, $tab_top+1); - $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"),'','C'); - } - - } - - /** - * Show top header of page. - * - * @param PDF $pdf Object PDF - * @param Object $object Object to show - * @param int $showaddress 0=no, 1=yes - * @param Translate $outputlangs Object lang for output - * @return void - */ - function _pagehead(&$pdf, $object, $showaddress, $outputlangs) - { - global $conf,$langs,$mysoc; - $default_font_size = pdf_getPDFFontSize($outputlangs); - $langs->load("orders"); - - pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); - - // 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); - } - - //Prepare la suite - $pdf->SetTextColor(0,0,60); - $pdf->SetFont('','B', $default_font_size + 3); - - $w = 110; - $posx=$this->page_largeur-$this->marge_droite-100; - $posy=$this->marge_haute; - - $pdf->SetXY($this->marge_gauche,$posy); - - // Logo - $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; - if ($this->emetteur->logo) - { - if (is_readable($logo)) - { - $height=pdf_getHeightForLogo($logo); - $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) - } - else - { - $pdf->SetTextColor(200,0,0); - $pdf->SetFont('','B', $default_font_size - 2); - $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($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); - } - - // Show barcode - if (! empty($conf->barcode->enabled)) - { - $posx=105; - } - else - { - $posx=$this->marge_gauche+3; - } - //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30); - if (! empty($conf->barcode->enabled)) - { - // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref - //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); - //$pdf->Image($logo,10, 5, 0, 24); - } - - $pdf->SetDrawColor(128,128,128); - if (! empty($conf->barcode->enabled)) - { - // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref - //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); - //$pdf->Image($logo,10, 5, 0, 24); - } - - - $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($w, 4, $title, '', 'R'); - $posy+=1; - - $pdf->SetFont('','', $default_font_size + 1); - - $posy+=4; - $pdf->SetXY($posx,$posy); - $pdf->SetTextColor(0,0,60); - $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R'); - - // Date planned delivery - if (! empty($object->date_delivery)) - { - $posy+=4; - $pdf->SetXY($posx,$posy); - $pdf->SetTextColor(0,0,60); - $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R'); - } - - if (! empty($object->thirdparty->code_client)) - { - $posy+=4; - $pdf->SetXY($posx,$posy); - $pdf->SetTextColor(0,0,60); - $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R'); - } - - - $pdf->SetFont('','', $default_font_size + 3); - $Yoff=25; - - // Add list of linked orders - // TODO possibility to use with other document (business module,...) - //$object->load_object_linked(); - - $origin = $object->origin; - $origin_id = $object->origin_id; - - // TODO move to external function - if (! empty($conf->$origin->enabled)) - { - $outputlangs->load('orders'); - - $classname = ucfirst($origin); - $linkedobject = new $classname($this->db); - $result=$linkedobject->fetch($origin_id); - if ($result >= 0) - { - $pdf->SetFont('','', $default_font_size - 2); - $text=$linkedobject->ref; - if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')'; - $Yoff = $Yoff+8; - $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 - $w,$Yoff); - $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R'); - } - } - - if ($showaddress) - { - // Sender properties - $carac_emetteur=''; - // Add internal contact of origin element if defined - $arrayidcontact=array(); - if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal','SALESREPFOLL'); - if (count($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->thirdparty); - - // Show sender - $posx=$this->marge_gauche; - $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 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); - $pdf->SetXY($posx,$posy-5); - $pdf->MultiCell(66,5, $outputlangs->transnoentities("Sender").":", 0, 'L'); - $pdf->SetXY($posx,$posy); - $pdf->SetFillColor(230,230,230); - $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($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->SetFont('','', $default_font_size - 1); - $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L'); - - - // If SHIPPING contact defined, we use it - $usecontact=false; - $arrayidcontact=$object->$origin->getIdContact('external','SHIPPING'); - if (count($arrayidcontact) > 0) - { - $usecontact=true; - $result=$object->fetch_contact($arrayidcontact[0]); - } - - //Recipient name - // On peut utiliser le nom de la societe du contact - if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { - $thirdparty = $object->contact; - } else { - $thirdparty = $object->thirdparty; - } - - $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs); - - $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,(!empty($object->contact)?$object->contact:null),$usecontact,'targetwithdetails',$object); - - // Show recipient - $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=!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+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, 2, $carac_client_name, 0, 'L'); - - $posy = $pdf->getY(); - - // Show recipient information - $pdf->SetFont('','', $default_font_size - 1); - $pdf->SetXY($posx+2,$posy); - $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); - } - - $pdf->SetTextColor(0,0,0); - } - - /** - * Show footer of page. Need this->emetteur object - * - * @param PDF $pdf PDF - * @param Object $object Object to show - * @param Translate $outputlangs Object lang for output - * @param int $hidefreetext 1=Hide free text - * @return int Return height of bottom margin including footer text - */ - function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) - { - global $conf; - $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; - return pdf_pagefoot($pdf,$outputlangs,'SHIPPING_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); - } - -} - diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php index ae9a4300544..515b9c2ec92 100644 --- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php @@ -72,6 +72,18 @@ class pdf_rouget extends ModelePdfExpedition $this->posxweightvol=$this->page_largeur - $this->marge_droite - 76; $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 56; $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 28; + $this->posxpuht=$this->page_largeur - $this->marge_droite; + + if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) { + + $this->posxweightvol=$this->page_largeur - $this->marge_droite - 130; + $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 100; + $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 70; + $this->posxpuht=$this->page_largeur - $this->marge_droite - 40; + $this->posxtotalht=$this->page_largeur - $this->marge_droite - 20; + + } + $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 @@ -464,7 +476,17 @@ class pdf_rouget extends ModelePdfExpedition } $pdf->SetXY($this->posxqtytoship, $curY); - $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C'); + $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C'); + + if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) +{ + $pdf->SetXY($this->posxpuht, $curY); + $pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs),'','R'); + + $pdf->SetXY($this->posxtotalht, $curY); + $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs),'','R'); + + } // Add line if ($conf->global->MAIN_PDF_DASH_BETWEEN_LINES && $i < ($nblignes - 1)) @@ -628,7 +650,17 @@ class pdf_rouget extends ModelePdfExpedition } $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($this->largeur_page - $this->marge_droite - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1); + $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1); + + if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) { + + $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1); + + $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1); + + } // Total Weight if ($totalWeighttoshow) @@ -713,8 +745,27 @@ class pdf_rouget extends ModelePdfExpedition if (empty($hidetop)) { $pdf->SetXY($this->posxqtytoship, $tab_top+1); - $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C'); + $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C'); } + + if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) { + + $pdf->line($this->posxpuht-1, $tab_top, $this->posxpuht-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxpuht-1, $tab_top+1); + $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"),'','C'); + } + + $pdf->line($this->posxtotalht-1, $tab_top, $this->posxtotalht-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxtotalht-1, $tab_top+1); + $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"),'','C'); + } + + } + } /** From 7b1f9eeb160f911572a1a4cd99c2df1001101412 Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 24 Jun 2016 12:44:36 +0200 Subject: [PATCH 06/23] FIX : lang useless because of dorade model deletion --- htdocs/langs/en_US/sendings.lang | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index a36a8a1ae11..1ec229af6c5 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -51,7 +51,6 @@ GenericTransport=Generic transport Enlevement=Gotten by customer DocumentModelSimple=Simple document model DocumentModelMerou=Merou A5 model -DocumentModelDorade=Model with amounts WarningNoQtyLeftToSend=Warning, no products waiting to be shipped. StatsOnShipmentsOnlyValidated=Statistics conducted on shipments only validated. Date used is date of validation of shipment (planed delivery date is not always known). DateDeliveryPlanned=Planned date of delivery From 427a8c5bf4ad76d024f40aeeaaad9d4848bcced8 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Tue, 12 Jul 2016 09:56:43 +0200 Subject: [PATCH 07/23] Display label and location of event on tooltip Think some additionnal info must be show on society too --- htdocs/comm/action/class/actioncomm.class.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index e759e93a635..ad58f612c1c 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1102,10 +1102,13 @@ class ActionComm extends CommonObject $tooltip = '' . $langs->trans('ShowAction'.$objp->code) . ''; if (! empty($this->ref)) $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; - if (! empty($this->label)) - $tooltip .= '
' . $langs->trans('Title') . ': ' . $this->label; $label = $this->label; if (empty($label)) $label=$this->libelle; // For backward compatibility + if (! empty($label)) + $tooltip .= '
' . $langs->trans('Title') . ': ' . $label; + if (! empty($this->location)) + $tooltip .= '
' . $langs->trans('Location') . ': ' . $this->location; + $linkclose = '" title="'.dol_escape_htmltag($tooltip, 1).'">'; if ($option=='birthday') $link = ''; + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('productdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + + if ($option == 'supplier') { $link = 'db); + } + $hookmanager->initHooks(array('societedao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + } - $link.='>'; + $link.=$linkclose.'>'; $linkend=''; if ($withpicto) $result.=($link.img_object(($notooltip?'':$label), 'company', ($notooltip?'':'class="classfortooltip"')).$linkend); From 7e3978c4034c7ec9671994ce473cfab398b42838 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Fri, 15 Jul 2016 10:04:04 +0200 Subject: [PATCH 10/23] sql changes --- htdocs/install/mysql/migration/4.0.0-5.0.0.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql index 849a71c935f..5f0ba0277b5 100644 --- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -24,6 +24,6 @@ ALTER TABLE llx_website ADD COLUMN virtualhost varchar(255) after fk_default_home; - - +ALTER TABLE llx_chargesociales ADD COLUMN fk_account integer after fk_type; +ALTER TABLE llx_chargesociales ADD COLUMN fk_mode_reglement integer after fk_account; From f25ff0581cc42095220ba3a199ee6aa2e3fad21c Mon Sep 17 00:00:00 2001 From: frederic34 Date: Fri, 15 Jul 2016 10:07:02 +0200 Subject: [PATCH 11/23] sql changes --- htdocs/install/mysql/tables/llx_chargesociales.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/install/mysql/tables/llx_chargesociales.sql b/htdocs/install/mysql/tables/llx_chargesociales.sql index 68607b1065a..0514811eb15 100644 --- a/htdocs/install/mysql/tables/llx_chargesociales.sql +++ b/htdocs/install/mysql/tables/llx_chargesociales.sql @@ -27,6 +27,8 @@ create table llx_chargesociales date_creation datetime, -- date de creation date_valid datetime, -- date de validation fk_type integer NOT NULL, + fk_account integer, -- bank account + fk_mode_reglement integer, -- mode de reglement amount real default 0 NOT NULL, paye smallint default 0 NOT NULL, periode date, From 0ba308a9a5f58b6aa6e69621936e9b35f8277dc3 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 15 Jul 2016 11:52:59 +0200 Subject: [PATCH 12/23] Update product.class.php --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index fb38efb8a07..19d667fd6e9 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3132,7 +3132,7 @@ class Product extends CommonObject */ function getNomUrl($withpicto=0,$option='',$maxlength=0) { - global $conf, $langs; + global $conf, $langs, $hookmanager; include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; $result=''; From c3174e45519d3d14bedda56cb545d62c6c302d5d Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 15 Jul 2016 11:54:37 +0200 Subject: [PATCH 13/23] Update societe.class.php --- htdocs/societe/class/societe.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index ecd75166d7e..db70b958001 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1810,7 +1810,7 @@ class Societe extends CommonObject */ function getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0) { - global $conf,$langs; + global $conf,$langs, $hookmanager; $name=$this->name?$this->name:$this->nom; @@ -1898,6 +1898,7 @@ class Societe extends CommonObject // Add type of canvas $link.=(!empty($this->canvas)?'&canvas='.$this->canvas:'').'"'; + $linkclose=''; if (empty($notooltip)) { if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) From 282def193052af748834e96a5cf8f9d2596fce58 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 16 Jul 2016 18:00:53 +0200 Subject: [PATCH 14/23] add feature on other dolibarr element --- htdocs/contact/class/contact.class.php | 62 ++++++++++++++++---------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 259918c5aa9..78752bdba03 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -957,39 +957,53 @@ class Contact extends CommonObject */ function getNomUrl($withpicto=0,$option='',$maxlen=0,$moreparam='') { - global $conf, $langs; + global $conf, $langs, $hookmanager; $result=''; - $label = '' . $langs->trans("ShowContact") . ''; - $label.= '
' . $langs->trans("Name") . ': '.$this->getFullName($langs); - //if ($this->civility_id) $label.= '
' . $langs->trans("Civility") . ': '.$this->civility_id; // TODO Translate cibilty_id code - if (! empty($this->poste)) $label.= '
' . $langs->trans("Poste") . ': '.$this->poste; - $label.= '
' . $langs->trans("EMail") . ': '.$this->email; - $phonelist=array(); - if ($this->phone_pro) $phonelist[]=$this->phone_pro; - if ($this->phone_mobile) $phonelist[]=$this->phone_mobile; - if ($this->phone_perso) $phonelist[]=$this->phone_perso; - $label.= '
' . $langs->trans("Phone") . ': '.join(', ',$phonelist); - $label.= '
' . $langs->trans("Address") . ': '.dol_format_address($this, 1, ' ', $langs); + $label = '' . $langs->trans("ShowContact") . ''; + $label.= '
' . $langs->trans("Name") . ': '.$this->getFullName($langs); + //if ($this->civility_id) $label.= '
' . $langs->trans("Civility") . ': '.$this->civility_id; // TODO Translate cibilty_id code + if (! empty($this->poste)) $label.= '
' . $langs->trans("Poste") . ': '.$this->poste; + $label.= '
' . $langs->trans("EMail") . ': '.$this->email; + $phonelist=array(); + if ($this->phone_pro) $phonelist[]=$this->phone_pro; + if ($this->phone_mobile) $phonelist[]=$this->phone_mobile; + if ($this->phone_perso) $phonelist[]=$this->phone_perso; + $label.= '
' . $langs->trans("Phone") . ': '.join(', ',$phonelist); + $label.= '
' . $langs->trans("Address") . ': '.dol_format_address($this, 1, ' ', $langs); + + $link = 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label=$langs->trans("ShowContact"); + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose.= ' class="classfortooltip">'; - $link = 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label=$langs->trans("ShowContact"); - $link.=' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $link.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $link.= ' class="classfortooltip">'; + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('contactdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + + $link.=$linkclose; + $linkend=''; - + if ($option == 'xxx') { $link = ''; $linkend=''; } - - if ($withpicto) $result.=($link.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' '); - $result.=$link.($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs)).$linkend; + + if ($withpicto) $result.=($link.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' '); + $result.=$link.($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs)).$linkend; return $result; } From 05b02e7bef761114c23b2a6d6e6b8bef784c9841 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 16 Jul 2016 18:05:58 +0200 Subject: [PATCH 15/23] Update user.class.php --- htdocs/user/class/user.class.php | 159 +++++++++++++++++-------------- 1 file changed, 85 insertions(+), 74 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 5b79447736e..d10585fe12d 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1941,89 +1941,100 @@ class User extends CommonObject */ function getNomUrl($withpictoimg=0, $option='', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode='',$morecss='') { - global $langs, $conf, $db; - global $dolibarr_main_authentication, $dolibarr_main_demo; - global $menumanager; + global $langs, $conf, $db, $hookmanager; + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg=0; - $result = ''; - $companylink = ''; - $link = ''; + $result = ''; + $companylink = ''; + $link = ''; + + $label = '' . $langs->trans("User") . ''; + $label.= '
'; + $label.= '' . $langs->trans('Name') . ': ' . $this->getFullName($langs,'',''); + if (! empty($this->login)) + $label.= '
' . $langs->trans('Login') . ': ' . $this->login; + $label.= '
' . $langs->trans("EMail").': '.$this->email; + if (! empty($this->admin)) + $label.= '
' . $langs->trans("Administrator").': '.yn($this->admin); + if (! empty($this->societe_id) ) // Add thirdparty for external users + { + $thirdpartystatic = new Societe($db); + $thirdpartystatic->fetch($this->societe_id); + if (empty($hidethirdpartylogo)) $companylink = ' '.$thirdpartystatic->getNomUrl(2); // picto only of company + $company=' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; + } + $type=($this->societe_id?$langs->trans("External").$company:$langs->trans("Internal")); + $label.= '
' . $langs->trans("Type") . ': ' . $type; + $label.='
'; + if (! empty($this->photo)) + { + $label.= '
'; + $label.= Form::showphoto('userphoto', $this, 80, 0, 0, 'photowithmargin photologintooltip', 'small', 0, 1); + $label.= '
'; + } - $label = '' . $langs->trans("User") . ''; - $label.= '
'; - $label.= '' . $langs->trans('Name') . ': ' . $this->getFullName($langs,'',''); - if (! empty($this->login)) - $label.= '
' . $langs->trans('Login') . ': ' . $this->login; - $label.= '
' . $langs->trans("EMail").': '.$this->email; - if (! empty($this->admin)) - $label.= '
' . $langs->trans("Administrator").': '.yn($this->admin); - if (! empty($this->societe_id) ) // Add thirdparty for external users - { - $thirdpartystatic = new Societe($db); - $thirdpartystatic->fetch($this->societe_id); - if (empty($hidethirdpartylogo)) $companylink = ' '.$thirdpartystatic->getNomUrl(2); // picto only of company - $company=' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')'; - } - $type=($this->societe_id?$langs->trans("External").$company:$langs->trans("Internal")); - $label.= '
' . $langs->trans("Type") . ': ' . $type; - $label.='
'; - if (! empty($this->photo)) - { - $label.= '
'; - $label.= Form::showphoto('userphoto', $this, 80, 0, 0, 'photowithmargin photologintooltip', 'small', 0, 1); - $label.= '
'; - } - - // Info Login - if ($infologin) - { - $label.= '
'; - $label.= '
'.$langs->trans("Connection").''; - $label.= '
'.$langs->trans("IPAddress").': '.$_SERVER["REMOTE_ADDR"]; - if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $label.= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$this->entity.')'; - $label.= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo)?'':' (demo)'); - $label.= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($this->datelastlogin,"dayhour"); - $label.= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($this->datepreviouslogin,"dayhour"); - $label.= '
'.$langs->trans("CurrentTheme").': '.$conf->theme; - $label.= '
'.$langs->trans("CurrentMenuManager").': '.$menumanager->name; - $s=picto_from_langcode($langs->getDefaultLang()); - $label.= '
'.$langs->trans("CurrentUserLanguage").': '.($s?$s.' ':'').$langs->getDefaultLang(); - $label.= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version?' '.$conf->browser->version:'').' ('.$_SERVER['HTTP_USER_AGENT'].')'; - $label.= '
'.$langs->trans("Layout").': '.$conf->browser->layout; - $label.= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; - if (! empty($conf->browser->phone)) $label.= '
'.$langs->trans("Phone").': '.$conf->browser->phone; - if (! empty($_SESSION["disablemodules"])) $label.= '
'.$langs->trans("DisabledModules").':
'.join(', ',explode(',',$_SESSION["disablemodules"])); - } + // Info Login + if ($infologin) + { + $label.= '
'; + $label.= '
'.$langs->trans("Connection").''; + $label.= '
'.$langs->trans("IPAddress").': '.$_SERVER["REMOTE_ADDR"]; + if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY)) $label.= '
'.$langs->trans("ConnectedOnMultiCompany").': '.$conf->entity.' (user entity '.$this->entity.')'; + $label.= '
'.$langs->trans("AuthenticationMode").': '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo)?'':' (demo)'); + $label.= '
'.$langs->trans("ConnectedSince").': '.dol_print_date($this->datelastlogin,"dayhour"); + $label.= '
'.$langs->trans("PreviousConnexion").': '.dol_print_date($this->datepreviouslogin,"dayhour"); + $label.= '
'.$langs->trans("CurrentTheme").': '.$conf->theme; + $label.= '
'.$langs->trans("CurrentMenuManager").': '.$menumanager->name; + $s=picto_from_langcode($langs->getDefaultLang()); + $label.= '
'.$langs->trans("CurrentUserLanguage").': '.($s?$s.' ':'').$langs->getDefaultLang(); + $label.= '
'.$langs->trans("Browser").': '.$conf->browser->name.($conf->browser->version?' '.$conf->browser->version:'').' ('.$_SERVER['HTTP_USER_AGENT'].')'; + $label.= '
'.$langs->trans("Layout").': '.$conf->browser->layout; + $label.= '
'.$langs->trans("Screen").': '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight']; + if (! empty($conf->browser->phone)) $label.= '
'.$langs->trans("Phone").': '.$conf->browser->phone; + if (! empty($_SESSION["disablemodules"])) $label.= '
'.$langs->trans("DisabledModules").':
'.join(', ',explode(',',$_SESSION["disablemodules"])); + } - if ($option == 'leave') $link.= 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $langs->load("users"); - $label=$langs->trans("ShowUser"); - $link.=' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $link.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $link.= ' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; - } - $link.= '>'; + if ($option == 'leave') $link.= 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $langs->load("users"); + $label=$langs->trans("ShowUser"); + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose.= ' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; + } + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('userdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + + $link.=$linkclose.'>'; $linkend=''; - //if ($withpictoimg == -1) $result.='
'; + //if ($withpictoimg == -1) $result.='
'; $result.=$link; - if ($withpictoimg) - { - $paddafterimage=''; - if (abs($withpictoimg) == 1) $paddafterimage='style="padding-right: 3px;"'; - if ($withpictoimg > 0) $picto='
'.img_object('', 'user', $paddafterimage.' '.($notooltip?'':'class="classfortooltip"')).'
'; - else $picto='
'.Form::showphoto('userphoto', $this, 0, 0, 0, 'loginphoto', 'mini', 0, 1).'
'; - $result.=$picto; + if ($withpictoimg) + { + $paddafterimage=''; + if (abs($withpictoimg) == 1) $paddafterimage='style="padding-right: 3px;"'; + if ($withpictoimg > 0) $picto='
'.img_object('', 'user', $paddafterimage.' '.($notooltip?'':'class="classfortooltip"')).'
'; + else $picto='
'.Form::showphoto('userphoto', $this, 0, 0, 0, 'loginphoto', 'mini', 0, 1).'
'; + $result.=$picto; } if (abs($withpictoimg) != 2) { From 093f1da206834ccc2fed08c9e3cfce7d4e175ea2 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Mon, 18 Jul 2016 15:07:35 +0200 Subject: [PATCH 16/23] Some indenting and hookmanager feature --- htdocs/comm/action/class/actioncomm.class.php | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index ad58f612c1c..406d7b5916c 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1096,24 +1096,36 @@ class ActionComm extends CommonObject */ function getNomUrl($withpicto=0,$maxlength=0,$classname='',$option='',$overwritepicto=0) { - global $conf,$langs; + global $conf,$langs, $hookmanager; - $result=''; - $tooltip = '' . $langs->trans('ShowAction'.$objp->code) . ''; - if (! empty($this->ref)) - $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; - $label = $this->label; - if (empty($label)) $label=$this->libelle; // For backward compatibility - if (! empty($label)) - $tooltip .= '
' . $langs->trans('Title') . ': ' . $label; - if (! empty($this->location)) - $tooltip .= '
' . $langs->trans('Location') . ': ' . $this->location; + $result=''; + $tooltip = '' . $langs->trans('ShowAction'.$objp->code) . ''; + if (! empty($this->ref)) + $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; + $label = $this->label; + if (empty($label)) $label=$this->libelle; // For backward compatibility + if (! empty($label)) + $tooltip .= '
' . $langs->trans('Title') . ': ' . $label; + if (! empty($this->location)) + $tooltip .= '
' . $langs->trans('Location') . ': ' . $this->location; + + $linkclose = ' class="'.$classname.' classfortooltip" title="'.dol_escape_htmltag($tooltip, 1).'">'; + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('actiondao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + $linkclose = ($hookmanager->resPrint ? $hookmanager->resPrint : $linkclose); - $linkclose = '" title="'.dol_escape_htmltag($tooltip, 1).'">'; - if ($option=='birthday') $link = 'libelle.'-'.$withpicto; if ($withpicto == 2) { From 07b6c991ffed763e946d9fe6faae0664d9c5395c Mon Sep 17 00:00:00 2001 From: Sergio Sanchis Climent Date: Tue, 19 Jul 2016 12:57:23 +0200 Subject: [PATCH 17/23] Create CommandeFournisseurLigne->insert Create SupplierInvoiceLine->insert --- .../class/fournisseur.commande.class.php | 638 ++++++++++++------ .../fourn/class/fournisseur.facture.class.php | 381 ++++++++--- htdocs/fourn/facture/card.php | 3 +- 3 files changed, 710 insertions(+), 312 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 306dfbbb9a7..f91a7edab67 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -50,89 +50,89 @@ class CommandeFournisseur extends CommonOrder */ protected $table_ref_field = 'ref'; - var $id; + public $id; /** * Supplier order reference * @var string */ - var $ref; - var $ref_supplier; - var $brouillon; - var $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially + public $ref; + public $ref_supplier; + public $brouillon; + public $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially // -> 7=Canceled/Never received -> (reopen) 3=Process runing // -> 6=Canceled -> (reopen) 2=Approved // -> 9=Refused -> (reopen) 1=Validated // Note: billed or not is on another field "billed" - var $statuts; // List of status - - var $socid; - var $fourn_id; - var $date; - var $date_valid; - var $date_approve; - var $date_approve2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set - var $date_commande; + public $statuts; // List of status + + public $socid; + public $fourn_id; + public $date; + public $date_valid; + public $date_approve; + public $date_approve2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set + public $date_commande; /** * Delivery date */ - var $date_livraison; - var $total_ht; - var $total_tva; - var $total_localtax1; // Total Local tax 1 - var $total_localtax2; // Total Local tax 2 - var $total_ttc; - var $source; + public $date_livraison; + public $total_ht; + public $total_tva; + public $total_localtax1; // Total Local tax 1 + public $total_localtax2; // Total Local tax 2 + public $total_ttc; + public $source; /** * @deprecated * @see note_private, note_public */ - var $note; + public $note; public $note_private; public $note_public; - var $model_pdf; - var $fk_project; - var $cond_reglement_id; - var $cond_reglement_code; - var $fk_account; - var $mode_reglement_id; - var $mode_reglement_code; - var $user_author_id; - var $user_valid_id; - var $user_approve_id; - var $user_approve_id2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set + public $model_pdf; + public $fk_project; + public $cond_reglement_id; + public $cond_reglement_code; + public $fk_account; + public $mode_reglement_id; + public $mode_reglement_code; + public $user_author_id; + public $user_valid_id; + public $user_approve_id; + public $user_approve_id2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set //Incoterms - var $fk_incoterms; - var $location_incoterms; - var $libelle_incoterms; //Used into tooltip + public $fk_incoterms; + public $location_incoterms; + public $libelle_incoterms; //Used into tooltip - var $extraparams=array(); + public $extraparams=array(); /** * @var CommandeFournisseurLigne[] */ public $lines = array(); //Add for supplier_proposal - var $origin; - var $origin_id; - var $linked_objects=array(); + public $origin; + public $origin_id; + public $linked_objects=array(); // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; /** * Constructor * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { global $conf; @@ -161,7 +161,7 @@ class CommandeFournisseur extends CommonOrder * @param string $ref Ref of object * @return int >0 if OK, <0 if KO, 0 if not found */ - function fetch($id,$ref='') + public function fetch($id,$ref='') { global $conf; @@ -373,7 +373,7 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function valid($user,$idwarehouse=0,$notrigger=0) + public function valid($user,$idwarehouse=0,$notrigger=0) { global $langs,$conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -492,7 +492,7 @@ class CommandeFournisseur extends CommonOrder * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto * @return string Label */ - function getLibStatut($mode=0) + public function getLibStatut($mode=0) { return $this->LibStatut($this->statut,$mode,$this->billed); } @@ -584,7 +584,7 @@ class CommandeFournisseur extends CommonOrder * @param string $option On what the link points * @return string Chain with URL */ - function getNomUrl($withpicto=0,$option='') + public function getNomUrl($withpicto=0,$option='') { global $langs, $conf; @@ -620,7 +620,7 @@ class CommandeFournisseur extends CommonOrder * @param Societe $soc company object * @return string free reference for the invoice */ - function getNextNumRef($soc) + public function getNextNumRef($soc) { global $db, $langs, $conf; $langs->load("orders"); @@ -674,8 +674,9 @@ class CommandeFournisseur extends CommonOrder * @param User $user Object user making the change * @return int <0 if KO, >0 if KO */ - function classifyBilled(User $user) + public function classifyBilled(User $user) { + $error=0; $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1'; @@ -720,7 +721,7 @@ class CommandeFournisseur extends CommonOrder * @param int $secondlevel 0=Standard approval, 1=Second level approval (used when option SUPPLIER_ORDER_DOUBLE_APPROVAL is set) * @return int <0 if KO, >0 if OK */ - function approve($user, $idwarehouse=0, $secondlevel=0) + public function approve($user, $idwarehouse=0, $secondlevel=0) { global $langs,$conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -805,6 +806,7 @@ class CommandeFournisseur extends CommonOrder // Product with reference if ($this->lines[$i]->fk_product > 0) { + $this->line = $this->lines[$i]; $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; // We decrement stock of product (and sub-products) @@ -812,6 +814,7 @@ class CommandeFournisseur extends CommonOrder if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("OrderApprovedInDolibarr",$this->ref)); if ($result < 0) { $error++; } + unset($this->line); } } } @@ -870,7 +873,7 @@ class CommandeFournisseur extends CommonOrder * @param User $user User making action * @return int 0 if Ok, <0 if Ko */ - function refuse($user) + public function refuse($user) { global $conf, $langs; @@ -988,7 +991,7 @@ class CommandeFournisseur extends CommonOrder * @param string $comment Comment * @return int <0 if KO, >0 if OK */ - function commande($user, $date, $methode, $comment='') + public function commande($user, $date, $methode, $comment='') { global $langs; dol_syslog(get_class($this)."::commande"); @@ -1046,7 +1049,7 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger Disable all triggers * @return int <0 if KO, Id of supplier order if OK */ - function create($user, $notrigger=0) + public function create($user, $notrigger=0) { global $langs,$conf,$hookmanager; @@ -1217,7 +1220,7 @@ class CommandeFournisseur extends CommonOrder * * @return int New id of clone */ - function createFromClone() + public function createFromClone() { global $conf,$user,$langs,$hookmanager; @@ -1304,7 +1307,7 @@ class CommandeFournisseur extends CommonOrder * @param string $fk_unit Code of the unit to use. Null to use the default one * @return int <=0 if KO, >0 if OK */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0, $fk_unit=null) + public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0, $fk_unit=null) { global $langs,$mysoc,$conf; @@ -1420,77 +1423,80 @@ class CommandeFournisseur extends CommonOrder $subprice = price2num($pu,'MU'); - // TODO We should use here $this->line=new CommandeFournisseurLigne($this->db); and $this->line->insert(); to work loke other object (proposal, order, invoice) - $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet"; - $sql.= " (fk_commande, label, description, date_start, date_end,"; - $sql.= " fk_product, product_type,"; - $sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,"; - $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,"; - $sql.= " fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc"; - $sql.= ")"; - $sql.= " VALUES (".$this->id.", '" . $this->db->escape($label) . "','" . $this->db->escape($desc) . "',"; - $sql.= " ".($date_start?"'".$this->db->idate($date_start)."'":"null").","; - $sql.= " ".($date_end?"'".$this->db->idate($date_end)."'":"null").","; - if ($fk_product) { $sql.= $fk_product.","; } - else { $sql.= "null,"; } - $sql.= "'".$product_type."',"; - $sql.= "'".$qty."', ".$txtva.", ".$txlocaltax1.", ".$txlocaltax2; + // Insert line + $this->line=new CommandeFournisseurLigne($this->db); - $sql.= ", '".$localtax1_type."',"; - $sql.= " '".$localtax2_type."'"; + $this->line->context = $this->context; - $sql.= ", ".$remise_percent.",'".price2num($subprice,'MU')."','".$ref."',"; - $sql.= "'".price2num($total_ht)."',"; - $sql.= "'".price2num($total_tva)."',"; - $sql.= "'".price2num($total_localtax1)."',"; - $sql.= "'".price2num($total_localtax2)."',"; - $sql.= "'".price2num($total_ttc)."',"; - $sql.= ($fk_unit ? "'".$this->db->escape($fk_unit)."'":"null"); - $sql.= ", ".$this->fk_multicurrency; - $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; - $sql.= ", ".price2num($pu_ht * $this->multicurrency_tx); - $sql.= ", ".$multicurrency_total_ht; - $sql.= ", ".$multicurrency_total_tva; - $sql.= ", ".$multicurrency_total_ttc; - $sql.= ")"; + $this->line->fk_commande=$this->id; + $this->line->label=$label; + $this->line->desc=$desc; + $this->line->qty=$qty; + $this->line->tva_tx=$txtva; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->fk_product=$fk_product; + $this->line->product_type=$product_type; + $this->line->remise_percent=$remise_percent; + $this->line->subprice=$pu_ht; + $this->line->rang=$this->rang; + $this->line->info_bits=$info_bits; + $this->line->total_ht=$total_ht; + $this->line->total_tva=$total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; + $this->line->total_ttc=$total_ttc; + $this->line->product_type=$type; + $this->line->special_code=$this->special_code; + $this->line->origin=$this->origin; + $this->line->fk_unit=$fk_unit; - $resql=$this->db->query($sql); - //print $sql; - if ($resql) + $this->line->date_start=$date_start; + $this->line->date_end=$date_end; + + + // Multicurrency + $this->line->fk_multicurrency = $this->fk_multicurrency; + $this->line->multicurrency_code = $this->multicurrency_code; + $this->line->multicurrency_subprice = price2num($pu_ht * $this->multicurrency_tx); + $this->line->multicurrency_total_ht = $multicurrency_total_ht; + $this->line->multicurrency_total_tva = $multicurrency_total_tva; + $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + + $this->line->subprice=$pu; + $this->line->price=$this->line->subprice; + + $this->line->remise_percent=$remise_percent; + + if (is_array($array_options) && count($array_options)>0) { + $this->line->array_options=$array_options; + } + + $result=$this->line->insert($notrigger); + if ($result > 0) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $linetmp = new CommandeFournisseurLigne($this->db); - $linetmp->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'commande_fournisseurdet'); - $linetmp->array_options = $array_options; - $result=$linetmp->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } + // Reorder if child line + if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); - if (! $error && ! $notrigger) + // Mise a jour informations denormalisees au niveau de la commande meme + $result=$this->update_price(1,'auto'); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + if ($result > 0) { - global $conf, $langs, $user; - // Call trigger - $result=$this->call_trigger('LINEORDER_SUPPLIER_CREATE',$user); - if ($result < 0) - { - $this->db->rollback(); - return -1; - } - // End call triggers + $this->db->commit(); + return $this->line->id; + } + else + { + $this->db->rollback(); + return -1; } - - $this->update_price('','auto'); - - $this->db->commit(); - return 1; } else { - $this->error=$this->db->error(); + $this->error=$this->line->error; + dol_syslog(get_class($this)."::addline error=".$this->error, LOG_ERR); $this->db->rollback(); return -1; } @@ -1514,7 +1520,7 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger 1 = notrigger * @return int <0 if KO, >0 if OK */ - function dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0) + public function dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0) { global $conf, $langs; @@ -1616,9 +1622,10 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger 1=Disable call to triggers * @return <0 if KO, >0 if OK */ - function deleteline($idline, $notrigger=0) + public function deleteline($idline, $notrigger=0) { global $user,$langs,$conf; + $error = 0; if ($this->statut != 0) { @@ -1671,7 +1678,7 @@ class CommandeFournisseur extends CommonOrder * @param User $user Object user * @return int <0 if KO, >0 if OK */ - function delete($user='') + public function delete($user='') { global $langs,$conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1822,7 +1829,7 @@ class CommandeFournisseur extends CommonOrder * @param int $status Filter on stats (-1 = no filter, 0 = lines draft to be approved, 1 = approved lines) * @return array Array of lines */ - function getDispachedLines($status=-1) + public function getDispachedLines($status=-1) { $ret = array(); @@ -2048,7 +2055,7 @@ class CommandeFournisseur extends CommonOrder * @param int $comclientid Id of customer order to use as template * @return int <0 if KO, >0 if OK */ - function updateFromCommandeClient($user, $idc, $comclientid) + public function updateFromCommandeClient($user, $idc, $comclientid) { $comclient = new Commande($this->db); $comclient->fetch($comclientid); @@ -2089,7 +2096,7 @@ class CommandeFournisseur extends CommonOrder * @param int $status New status * @return int <0 if KO, >0 if OK */ - function setStatus($user,$status) + public function setStatus($user,$status) { global $conf,$langs; $error=0; @@ -2147,12 +2154,14 @@ class CommandeFournisseur extends CommonOrder * @param string $fk_unit Code of the unit to use. Null to use the default one * @return int < 0 if error, > 0 if ok */ - function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit=null) + public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit=null) { - global $mysoc; + global $mysoc, $conf; dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; + $error = 0; + if ($this->brouillon) { $this->db->begin(); @@ -2202,83 +2211,62 @@ class CommandeFournisseur extends CommonOrder $subprice = price2num($pu,'MU'); - // Mise a jour ligne en base - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseurdet SET"; - $sql.= " description='".$this->db->escape($desc)."'"; - $sql.= ",subprice='".price2num($subprice)."'"; - //$sql.= ",remise='".price2num($remise)."'"; - $sql.= ",remise_percent='".price2num($remise_percent)."'"; - $sql.= ",tva_tx='".price2num($txtva)."'"; - $sql.= ",localtax1_tx='".price2num($txlocaltax1)."'"; - $sql.= ",localtax2_tx='".price2num($txlocaltax2)."'"; - $sql.= ",localtax1_type='".$localtax1_type."'"; - $sql.= ",localtax2_type='".$localtax2_type."'"; - $sql.= ",qty='".price2num($qty)."'"; - $sql.= ",date_start=".(! empty($date_start)?"'".$this->db->idate($date_start)."'":"null"); - $sql.= ",date_end=".(! empty($date_end)?"'".$this->db->idate($date_end)."'":"null"); - $sql.= ",info_bits='".$info_bits."'"; - $sql.= ",total_ht='".price2num($total_ht)."'"; - $sql.= ",total_tva='".price2num($total_tva)."'"; - $sql.= ",total_localtax1='".price2num($total_localtax1)."'"; - $sql.= ",total_localtax2='".price2num($total_localtax2)."'"; - $sql.= ",total_ttc='".price2num($total_ttc)."'"; - $sql.= ",product_type=".$type; - $sql.= ($fk_unit ? ",fk_unit='".$this->db->escape($fk_unit)."'":", fk_unit=null"); - - // Multicurrency - $sql.= " , multicurrency_subprice=".price2num($subprice * $this->multicurrency_tx).""; - $sql.= " , multicurrency_total_ht=".price2num($multicurrency_total_ht).""; - $sql.= " , multicurrency_total_tva=".price2num($multicurrency_total_tva).""; - $sql.= " , multicurrency_total_ttc=".price2num($multicurrency_total_ttc).""; - - $sql.= " WHERE rowid = ".$rowid; + $this->line=new CommandeFournisseurLigne($this->db); + $this->line->fetch($rowid); - dol_syslog(get_class($this)."::updateline", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result > 0) + $this->line->context = $this->context; + + $this->line->fk_commande=$this->id; + //$this->line->label=$label; + $this->line->desc=$desc; + $this->line->qty=$qty; + $this->line->tva_tx=$txtva; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->remise_percent=$remise_percent; + $this->line->subprice=$pu; + $this->line->rang=$this->rang; + $this->line->info_bits=$info_bits; + $this->line->total_ht=$total_ht; + $this->line->total_tva=$total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; + $this->line->total_ttc=$total_ttc; + $this->line->product_type=$type; + $this->line->special_code=$this->special_code; + $this->line->origin=$this->origin; + $this->line->fk_unit=$fk_unit; + + $this->line->date_start=$date_start; + $this->line->date_end=$date_end; + + + // Multicurrency + $this->line->fk_multicurrency = $this->fk_multicurrency; + $this->line->multicurrency_code = $this->multicurrency_code; + $this->line->multicurrency_subprice = price2num($pu_ht * $this->multicurrency_tx); + $this->line->multicurrency_total_ht = $multicurrency_total_ht; + $this->line->multicurrency_total_tva = $multicurrency_total_tva; + $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + + $this->line->subprice=$pu; + $this->line->price=$this->line->subprice; + + $this->line->remise_percent=$remise_percent; + + if (is_array($array_options) && count($array_options)>0) { + $this->line->array_options=$array_options; + } + + $result=$this->line->update($notrigger); + + + // Mise a jour info denormalisees au niveau facture + if (! $error) { - $this->rowid = $rowid; - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $tmpline = new CommandeFournisseurLigne($this->db); - $tmpline->id=$this->rowid; - $tmpline->array_options = $array_options; - $result=$tmpline->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } - - if (! $error && ! $notrigger) - { - global $conf, $langs, $user; - // Call trigger - $result=$this->call_trigger('LINEORDER_SUPPLIER_UPDATE',$user); - if ($result < 0) - { - $this->db->rollback(); - return -1; - } - // End call triggers - } - - // Mise a jour info denormalisees au niveau facture - if (! $error) - { - $this->update_price('','auto'); - } - - if (! $error) - { - $this->db->commit(); - return $result; - } - else - { - $this->db->rollback(); - return -1; - } + $this->update_price('','auto'); } else { @@ -2303,7 +2291,7 @@ class CommandeFournisseur extends CommonOrder * * @return void */ - function initAsSpecimen() + public function initAsSpecimen() { global $user,$langs,$conf; @@ -2385,7 +2373,7 @@ class CommandeFournisseur extends CommonOrder * @param int $id Id de la facture a charger * @return void */ - function info($id) + public function info($id) { $sql = 'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,'; $sql.= ' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2'; @@ -2523,7 +2511,7 @@ class CommandeFournisseur extends CommonOrder * * @return string */ - function getInputMethod() + public function getInputMethod() { global $db, $langs; @@ -2593,7 +2581,7 @@ class CommandeFournisseur extends CommonOrder * @param Translate $langs Language object * @return Translated string */ - function getMaxDeliveryTimeDay($langs) + public function getMaxDeliveryTimeDay($langs) { if (empty($this->lines)) return ''; @@ -2689,17 +2677,31 @@ class CommandeFournisseur extends CommonOrder */ class CommandeFournisseurLigne extends CommonOrderLine { - public $element='commande_fournisseurdet'; + public $element='commande_fournisseurdet'; public $table_element='commande_fournisseurdet'; + public $oldline; + + /** + * Id of parent order + * @var int + */ + public $fk_commande; + + // From llx_commande_fournisseurdet + public $fk_parent_line; + public $fk_facture; + public $label; + public $rang = 0; + /** * Unit price without taxes * @var float */ public $pu_ht; - var $date_start; - var $date_end; + public $date_start; + public $date_end; // From llx_product_fournisseur_price @@ -2715,7 +2717,9 @@ class CommandeFournisseurLigne extends CommonOrderLine * Supplier reference * @var string */ - public $ref_supplier; + public $ref_supplier; + public $remise; + public $product_libelle; /** @@ -2723,7 +2727,7 @@ class CommandeFournisseurLigne extends CommonOrderLine * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { $this->db= $db; } @@ -2734,7 +2738,7 @@ class CommandeFournisseurLigne extends CommonOrderLine * @param int $rowid Id line order * @return int <0 if KO, >0 if OK */ - function fetch($rowid) + public function fetch($rowid) { $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx,'; $sql.= ' cd.localtax1_tx, cd.localtax2_tx,'; @@ -2751,6 +2755,7 @@ class CommandeFournisseurLigne extends CommonOrderLine { $objp = $this->db->fetch_object($result); $this->rowid = $objp->rowid; + $this->id = $objp->rowid; $this->fk_commande = $objp->fk_commande; $this->desc = $objp->description; $this->qty = $objp->qty; @@ -2770,6 +2775,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $this->product_type = $objp->product_type; $this->ref = $objp->product_ref; + $this->product_ref = $objp->product_ref; $this->product_libelle = $objp->product_libelle; $this->product_desc = $objp->product_desc; @@ -2792,7 +2798,7 @@ class CommandeFournisseurLigne extends CommonOrderLine * * @return int <0 si ko, >0 si ok */ - function update_total() + public function update_total() { $this->db->begin(); @@ -2820,5 +2826,209 @@ class CommandeFournisseurLigne extends CommonOrderLine return -2; } } + + /** + * Insert line into database + * + * @param int $notrigger 1 = disable triggers + * @return int <0 if KO, >0 if OK + */ + public function insert($notrigger=0) + { + global $conf, $user; + + $error=0; + + dol_syslog(get_class($this)."::insert rang=".$this->rang); + + // Clean parameters + if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->localtax1_tx)) $this->localtax1_tx=0; + if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + if (empty($this->localtax1_type)) $this->localtax1_type=0; + if (empty($this->localtax2_type)) $this->localtax2_type=0; + if (empty($this->total_localtax1)) $this->total_localtax1=0; + if (empty($this->total_localtax2)) $this->total_localtax2=0; + if (empty($this->rang)) $this->rang=0; + if (empty($this->remise)) $this->remise=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; + if (empty($this->special_code)) $this->special_code=0; + if (empty($this->fk_parent_line)) $this->fk_parent_line=0; + if (empty($this->pa_ht)) $this->pa_ht=0; + + + // Check parameters + if ($this->product_type < 0) return -1; + + $this->db->begin(); + + // Insertion dans base de la ligne + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; + $sql.= " (fk_commande, label, description, date_start, date_end,"; + $sql.= " fk_product, product_type,"; + $sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,"; + $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,"; + $sql.= " fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc"; + $sql.= ")"; + $sql.= " VALUES (".$this->fk_commande.", '" . $this->db->escape($this->product_label) . "','" . $this->db->escape($this->desc) . "',"; + $sql.= " ".($this->date_start?"'".$this->db->idate($this->date_start)."'":"null").","; + $sql.= " ".($this->date_end?"'".$this->db->idate($this->date_end)."'":"null").","; + if ($this->fk_product) { $sql.= $this->fk_product.","; } + else { $sql.= "null,"; } + $sql.= "'".$this->product_type."',"; + $sql.= "'".$this->qty."', ".$this->tva_tx.", ".$this->localtax1_tx.", ".$this->localtax2_tx; + + $sql.= ", '".$this->localtax1_type."',"; + $sql.= " '".$this->localtax2_type."'"; + + $sql.= ", ".$this->remise_percent.",'".price2num($this->subprice,'MU')."','".$this->product_ref."',"; + $sql.= "'".price2num($this->total_ht)."',"; + $sql.= "'".price2num($this->total_tva)."',"; + $sql.= "'".price2num($this->total_localtax1)."',"; + $sql.= "'".price2num($this->total_localtax2)."',"; + $sql.= "'".price2num($this->total_ttc)."',"; + $sql.= ($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'":"null"); + $sql.= ", ".$this->fk_multicurrency; + $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; + $sql.= ", ".price2num($this->pu_ht * $this->multicurrency_tx); + $sql.= ", ".$this->multicurrency_total_ht; + $sql.= ", ".$this->multicurrency_total_tva; + $sql.= ", ".$this->multicurrency_total_ttc; + $sql.= ")"; + + dol_syslog(get_class($this)."::insert", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->rowid =$this->id; + + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + + if (! $error && ! $notrigger) + { + // Call trigger + $result=$this->call_trigger('LINEORDER_INSERT',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (!$error) { + $this->db->commit(); + return 1; + } + + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->errors[]=($this->errors?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->errors[]=$this->db->error(); + $this->db->rollback(); + return -2; + } + } + /** + * Update the line object into db + * + * @param int $notrigger 1 = disable triggers + * @return int <0 si ko, >0 si ok + */ + public function update($notrigger=0) + { + global $conf,$user; + + $error=0; + + // Mise a jour ligne en base + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql.= " description='".$this->db->escape($this->desc)."'"; + $sql.= ",subprice='".price2num($this->subprice)."'"; + //$sql.= ",remise='".price2num($remise)."'"; + $sql.= ",remise_percent='".price2num($this->remise_percent)."'"; + $sql.= ",tva_tx='".price2num($this->tva_tx)."'"; + $sql.= ",localtax1_tx='".price2num($this->total_localtax1)."'"; + $sql.= ",localtax2_tx='".price2num($this->total_localtax2)."'"; + $sql.= ",localtax1_type='".$this->localtax1_type."'"; + $sql.= ",localtax2_type='".$this->localtax2_type."'"; + $sql.= ",qty='".price2num($this->qty)."'"; + $sql.= ",date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null"); + $sql.= ",date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null"); + $sql.= ",info_bits='".$this->info_bits."'"; + $sql.= ",total_ht='".price2num($this->total_ht)."'"; + $sql.= ",total_tva='".price2num($this->total_tva)."'"; + $sql.= ",total_localtax1='".price2num($this->total_localtax1)."'"; + $sql.= ",total_localtax2='".price2num($this->total_localtax2)."'"; + $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; + $sql.= ",product_type=".$this->product_type; + $sql.= ($this->fk_unit ? ",fk_unit='".$this->db->escape($this->fk_unit)."'":", fk_unit=null"); + + // Multicurrency + $sql.= " , multicurrency_subprice=".price2num($this->subprice * $this->multicurrency_tx).""; + $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; + $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; + $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; + + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::updateline", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result > 0) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + + if (! $error && ! $notrigger) + { + global $user; + // Call trigger + $result=$this->call_trigger('LINEORDER_SUPPLIER_UPDATE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return $result; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } } diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 8c1a86b03a5..aab90ce4b49 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -50,57 +50,57 @@ class FactureFournisseur extends CommonInvoice */ protected $table_ref_field = 'ref'; - var $rowid; - var $ref; - var $product_ref; - var $ref_supplier; - var $socid; + public $rowid; + public $ref; + public $product_ref; + public $ref_supplier; + public $socid; //Check constants for types - var $type = self::TYPE_STANDARD; + public $type = self::TYPE_STANDARD; /** * Supplier invoice status * @var int * @see FactureFournisseur::STATUS_DRAFT, FactureFournisseur::STATUS_VALIDATED, FactureFournisseur::STATUS_PAID, FactureFournisseur::STATUS_ABANDONED */ - var $statut; + public $statut; /** * Set to 1 if the invoice is completely paid, otherwise is 0 * @var int * @deprecated Use statuses stored in self::statut */ - var $paye; + public $paye; - var $author; - var $libelle; - var $datec; // Creation date - var $tms; // Last update date - var $date; // Invoice date - var $date_echeance; // Max payment date - var $amount; - var $remise; - var $tva; - var $localtax1; - var $localtax2; - var $total_ht; - var $total_tva; - var $total_localtax1; - var $total_localtax2; - var $total_ttc; + public $author; + public $libelle; + public $datec; // Creation date + public $tms; // Last update date + public $date; // Invoice date + public $date_echeance; // Max payment date + public $amount; + public $remise; + public $tva; + public $localtax1; + public $localtax2; + public $total_ht; + public $total_tva; + public $total_localtax1; + public $total_localtax2; + public $total_ttc; /** * @deprecated * @see note_private, note_public */ - var $note; - var $note_private; - var $note_public; - var $propalid; - var $cond_reglement_id; - var $cond_reglement_code; - var $fk_account; - var $mode_reglement_id; - var $mode_reglement_code; + public $note; + public $note_private; + public $note_public; + public $propalid; + public $cond_reglement_id; + public $cond_reglement_code; + public $fk_account; + public $mode_reglement_id; + public $mode_reglement_code; /** * Invoice lines @@ -110,29 +110,29 @@ class FactureFournisseur extends CommonInvoice /** * @deprecated */ - var $fournisseur; + public $fournisseur; //Incorterms - var $fk_incoterms; - var $location_incoterms; - var $libelle_incoterms; //Used into tooltip + public $fk_incoterms; + public $location_incoterms; + public $libelle_incoterms; //Used into tooltip - var $extraparams=array(); + public $extraparams=array(); // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; /** * Constructor * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { $this->db = $db; @@ -155,7 +155,7 @@ class FactureFournisseur extends CommonInvoice * @param User $user object utilisateur qui cree * @return int id facture si ok, < 0 si erreur */ - function create($user) + public function create($user) { global $langs,$conf,$hookmanager; @@ -355,7 +355,7 @@ class FactureFournisseur extends CommonInvoice * @param string $ref Ref supplier invoice * @return int <0 if KO, >0 if OK, 0 if not found */ - function fetch($id='',$ref='') + public function fetch($id='',$ref='') { global $langs; @@ -613,7 +613,7 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ - function update($user=null, $notrigger=0) + public function update($user=null, $notrigger=0) { global $conf, $langs; $error=0; @@ -741,7 +741,7 @@ class FactureFournisseur extends CommonInvoice * @param int $rowid Id of invoice to delete * @return int <0 if KO, >0 if OK */ - function delete($rowid) + public function delete($rowid) { global $user,$langs,$conf; @@ -955,7 +955,7 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, =0 if nothing to do, >0 if OK */ - function validate($user, $force_number='', $idwarehouse=0, $notrigger=0) + public function validate($user, $force_number='', $idwarehouse=0, $notrigger=0) { global $conf,$langs; @@ -1011,6 +1011,7 @@ class FactureFournisseur extends CommonInvoice { if ($this->lines[$i]->fk_product > 0) { + $this->line = $this->lines[$i]; $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; // We increase stock for product @@ -1018,6 +1019,7 @@ class FactureFournisseur extends CommonInvoice if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr",$num)); if ($result < 0) { $error++; } + unset($this->line); } } } @@ -1194,14 +1196,16 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger Disable triggers * @param array $array_options extrafields array * @param string $fk_unit Code of the unit to use. Null to use the default one + * @param int $origin_id id origin document * @return int >0 if OK, <0 if KO * * FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order. */ - function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit=null) + public function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit=null, $origin_id=0) { dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; + global $mysoc; // Clean parameters if (empty($remise_percent)) $remise_percent=0; @@ -1220,52 +1224,92 @@ class FactureFournisseur extends CommonInvoice $txlocaltax1=price2num($txlocaltax1); $txlocaltax2=price2num($txlocaltax2); + $localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc, $this->thirdparty); + + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; + $total_localtax1 = $tabprice[9]; + $total_localtax2 = $tabprice[10]; + + // MultiCurrency + $multicurrency_total_ht = $tabprice[16]; + $multicurrency_total_tva = $tabprice[17]; + $multicurrency_total_ttc = $tabprice[18]; + // Check parameters if ($type < 0) return -1; + // Insert line + $this->line=new SupplierInvoiceLine($this->db); - $this->db->begin(); + $this->line->context = $this->context; - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)'; - $sql.= ' VALUES ('.$this->id.')'; - dol_syslog(get_class($this)."::addline", LOG_DEBUG); + $this->line->fk_facture_fourn=$this->id; + //$this->line->label=$label; // deprecated + $this->line->desc=$desc; + $this->line->qty= ($this->type==self::TYPE_CREDIT_NOTE?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative + $this->line->tva_tx=$txtva; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; + $this->line->fk_product=$fk_product; + $this->line->product_type=$type; + $this->line->remise_percent=$remise_percent; + $this->line->subprice= ($this->type==self::TYPE_CREDIT_NOTE?-abs($pu):$pu); // For credit note, unit price always negative, always positive otherwise + $this->line->date_start=$date_start; + $this->line->date_end=$date_end; + $this->line->ventil=$ventil; + $this->line->rang=$rang; + $this->line->info_bits=$info_bits; + $this->line->total_ht= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ht):$total_ht); // For credit note and if qty is negative, total is negative + $this->line->total_tva= $total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->total_ttc= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ttc):$total_ttc); + $this->line->special_code=$this->special_code; + $this->line->fk_parent_line=$this->fk_parent_line; + $this->line->origin=$this->origin; + $this->line->origin_id=$origin_id; + $this->line->fk_unit=$fk_unit; - $resql = $this->db->query($sql); - if ($resql) + // Multicurrency + $this->line->fk_multicurrency = $this->fk_multicurrency; + $this->line->multicurrency_code = $this->multicurrency_code; + $this->line->multicurrency_subprice = price2num($this->line->subprice * $this->multicurrency_tx); + $this->line->multicurrency_total_ht = $multicurrency_total_ht; + $this->line->multicurrency_total_tva = $multicurrency_total_tva; + $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + + if (is_array($array_options) && count($array_options)>0) { + $this->line->array_options=$array_options; + } + + $result=$this->line->insert($notrigger); + if ($result > 0) { - $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det'); + // Reorder if child line + if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); - $result=$this->updateline($idligne, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $price_base_type, $info_bits, $type, $remise_percent, true, '', '', $array_options, $fk_unit); + // Mise a jour informations denormalisees au niveau de la facture meme + $result=$this->update_price(1,'auto',0,$mysoc); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode. if ($result > 0) { - $this->rowid = $idligne; - - if (! $notrigger) - { - global $conf, $langs, $user; - // Call trigger - $result=$this->call_trigger('LINEBILL_SUPPLIER_CREATE',$user); - if ($result < 0) - { - $this->db->rollback(); - return -1; - } - // End call triggers - } - $this->db->commit(); - return 1; + return $this->line->id; } else { - dol_syslog("Error after updateline error=".$this->error, LOG_ERR); + $this->error=$this->db->error(); $this->db->rollback(); return -1; } } else { - $this->error=$this->db->lasterror(); + $this->error=$this->line->error; $this->db->rollback(); return -2; } @@ -1293,7 +1337,7 @@ class FactureFournisseur extends CommonInvoice * @param string $fk_unit Code of the unit to use. Null to use the default one * @return int <0 if KO, >0 if OK */ - function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null) + public function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null) { global $mysoc; dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent,$fk_unit", LOG_DEBUG); @@ -1315,6 +1359,8 @@ class FactureFournisseur extends CommonInvoice $txlocaltax1=price2num($txlocaltax1); $txlocaltax2=price2num($txlocaltax2); + $localtaxes_type = array($txlocaltax1,$txlocaltax2); + // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker @@ -1404,7 +1450,7 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - function deleteline($rowid, $notrigger=0) + public function deleteline($rowid, $notrigger=0) { if (!$rowid) { $rowid = $this->id; @@ -1434,7 +1480,7 @@ class FactureFournisseur extends CommonInvoice * @param int $id Id de la facture a charger * @return void */ - function info($id) + public function info($id) { $sql = 'SELECT c.rowid, datec, tms as datem, '; $sql.= ' fk_user_author, fk_user_modif, fk_user_valid'; @@ -1543,9 +1589,9 @@ class FactureFournisseur extends CommonInvoice * @param int $max Max length of shown ref * @return string Chaine avec URL */ - function getNomUrl($withpicto=0,$option='',$max=0) + public function getNomUrl($withpicto=0,$option='',$max=0) { - global $langs; + global $langs, $conf; $result=''; $label = '' . $langs->trans("ShowSupplierInvoice") . ''; @@ -1587,7 +1633,7 @@ class FactureFournisseur extends CommonInvoice * @param string $mode 'next' for next value or 'last' for last value * @return string free ref or last ref */ - function getNextNumRef($soc,$mode='next') + public function getNextNumRef($soc,$mode='next') { global $db, $langs, $conf; $langs->load("orders"); @@ -1640,7 +1686,7 @@ class FactureFournisseur extends CommonInvoice * * @return void */ - function initAsSpecimen() + public function initAsSpecimen() { global $langs,$conf; include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; @@ -1780,7 +1826,7 @@ class FactureFournisseur extends CommonInvoice * @param int $invertdetail Reverse sign of amounts for lines * @return int New id of clone */ - function createFromClone($fromid,$invertdetail=0) + public function createFromClone($fromid,$invertdetail=0) { global $user,$langs; @@ -1942,7 +1988,7 @@ class SupplierInvoiceLine extends CommonObjectLine public $element='facture_fourn_det'; public $table_element='facture_fourn_det'; - var $oldline; + public $oldline; /** * @deprecated @@ -1999,22 +2045,22 @@ class SupplierInvoiceLine extends CommonObjectLine * Id of the corresponding supplier invoice * @var int */ - var $fk_facture_fourn; + public $fk_facture_fourn; /** * Product label * This field may contains label of product (when invoice create from order) * @var string */ - var $label; + public $label; /** * Description of the line * @var string */ - var $description; + public $description; - var $skip_update_total; // Skip update price total for special lines + public $skip_update_total; // Skip update price total for special lines /** * @var int Situation advance percentage @@ -2046,19 +2092,19 @@ class SupplierInvoiceLine extends CommonObjectLine public $localtax2_type; // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_subprice; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_subprice; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; /** * Constructor * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { $this->db= $db; } @@ -2292,5 +2338,146 @@ class SupplierInvoiceLine extends CommonObjectLine $this->db->commit(); return 1; } + + /** + * Insert line into database + * + * @param int $notrigger 1 no triggers + * @return int <0 if KO, >0 if OK + */ + public function insert($notrigger=0) + { + global $user,$conf; + + $error=0; + + dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG); + + // Clean parameters + $this->desc=trim($this->desc); + if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->localtax1_tx)) $this->localtax1_tx=0; + if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + if (empty($this->localtax1_type)) $this->localtax1_type=0; + if (empty($this->localtax2_type)) $this->localtax2_type=0; + if (empty($this->total_localtax1)) $this->total_localtax1=0; + if (empty($this->total_localtax2)) $this->total_localtax2=0; + if (empty($this->rang)) $this->rang=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; + if (empty($this->subprice)) $this->subprice=0; + if (empty($this->special_code)) $this->special_code=0; + if (empty($this->fk_parent_line)) $this->fk_parent_line=0; + if (! isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100; + + if (empty($this->pa_ht)) $this->pa_ht=0; + if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice=0; + if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht=0; + if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva=0; + if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc=0; + + + // Check parameters + if ($this->product_type < 0) + { + $this->error='ErrorProductTypeMustBe0orMore'; + return -1; + } + if (! empty($this->fk_product)) + { + // Check product exists + $result=Product::isExistingObject('product', $this->fk_product); + if ($result <= 0) + { + $this->error='ErrorProductIdDoesNotExists'; + return -1; + } + } + + $this->db->begin(); + + // Insertion dans base de la ligne + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; + $sql.= ' (fk_facture_fourn, fk_parent_line, label, description, qty,'; + $sql.= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,'; + $sql.= ' fk_product, product_type, remise_percent, pu_ht, pu_ttc,'; + $sql.= ' date_start, date_end, fk_code_ventilation, rang, special_code,'; + $sql.= ' info_bits, total_ht, tva, total_ttc, total_localtax1, total_localtax2, fk_unit'; + $sql.= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; + $sql.= ')'; + $sql.= " VALUES (".$this->fk_facture_fourn.","; + $sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").","; + $sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").","; + $sql.= " '".$this->db->escape($this->desc)."',"; + $sql.= " ".price2num($this->qty).","; + $sql.= " ".price2num($this->tva_tx).","; + $sql.= " ".price2num($this->localtax1_tx).","; + $sql.= " ".price2num($this->localtax2_tx).","; + $sql.= " '".$this->localtax1_type."',"; + $sql.= " '".$this->localtax2_type."',"; + $sql.= ' '.(! empty($this->fk_product)?$this->fk_product:"null").','; + $sql.= " ".$this->product_type.","; + $sql.= " ".price2num($this->remise_percent).","; + $sql.= " ".price2num($this->subprice).","; + $sql.= " ".price2num($this->total_ttc/$this->qty).","; + $sql.= " ".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null").","; + $sql.= " ".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null").","; + $sql.= ' '.(!empty($this->fk_code_ventilation)?$this->fk_code_ventilation:0).','; + $sql.= ' '.$this->rang.','; + $sql.= ' '.$this->special_code.','; + $sql.= " '".$this->info_bits."',"; + $sql.= " ".price2num($this->total_ht).","; + $sql.= " ".price2num($this->total_tva).","; + $sql.= " ".price2num($this->total_ttc).","; + $sql.= " ".price2num($this->total_localtax1).","; + $sql.= " ".price2num($this->total_localtax2); + $sql .= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit); + $sql.= ", ".(int) $this->fk_multicurrency; + $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; + $sql.= ", ".price2num($this->multicurrency_subprice); + $sql.= ", ".price2num($this->multicurrency_total_ht); + $sql.= ", ".price2num($this->multicurrency_total_tva); + $sql.= ", ".price2num($this->multicurrency_total_ttc); + $sql.= ')'; + + dol_syslog(get_class($this)."::insert", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->rowid=$this->id; + + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('LINEBILL_SUPPLIER_CREATE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -2; + } + // End call triggers + } + + $this->db->commit(); + return $this->id; + + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -2; + } + } } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 280664ea421..a8239bcb7fb 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -476,7 +476,8 @@ if (empty($reshook)) $lines[$i]->rang, 0, $lines[$i]->array_options, - $lines[$i]->fk_unit + $lines[$i]->fk_unit, + $lines[$i]->id ); if ($result < 0) From 76f17737be3f83a1ae244914d5bfa3ad5d168743 Mon Sep 17 00:00:00 2001 From: Sergio Sanchis Climent Date: Tue, 19 Jul 2016 13:50:32 +0200 Subject: [PATCH 18/23] change dolsyslog --- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index f91a7edab67..233d4e63e58 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2811,7 +2811,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog("CommandeFournisseurLigne.class.php::update_total", LOG_DEBUG); + dol_syslog(get_class($this)."::update_total", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) From c101a6c483adc0c14377e65b77f12f7adfa51bfe Mon Sep 17 00:00:00 2001 From: Sergio Sanchis Climent Date: Tue, 19 Jul 2016 13:56:48 +0200 Subject: [PATCH 19/23] update camel caps to update_total() --- htdocs/fourn/class/fournisseur.commande.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 233d4e63e58..26cfd08775e 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2798,7 +2798,7 @@ class CommandeFournisseurLigne extends CommonOrderLine * * @return int <0 si ko, >0 si ok */ - public function update_total() + public function updateTotal() { $this->db->begin(); @@ -2811,7 +2811,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog(get_class($this)."::update_total", LOG_DEBUG); + dol_syslog(get_class($this)."::updateTotal", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) From f4705873cb6790437a68e6fdae09f453d403e7d6 Mon Sep 17 00:00:00 2001 From: All3kcis Date: Tue, 19 Jul 2016 15:27:03 +0200 Subject: [PATCH 20/23] Update functions.lib.php Remove useless verification on $level. Second check "in_array" line 624 is sufficient with strict mode. Otherwise "Emerg level" is not possible with "empty($level).. LOG_EMERG = 0... --- htdocs/core/lib/functions.lib.php | 90 +++++++++++++++---------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 03b64113ac1..1549a2603b6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -619,54 +619,52 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename=' // If syslog module enabled if (empty($conf->syslog->enabled)) return; - if (! empty($level)) + // Test log level + $logLevels = array(LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG); + if (!in_array($level, $logLevels, true)) { - // Test log level - $logLevels = array( LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG); - if (!in_array($level, $logLevels)) - { - throw new Exception('Incorrect log level'); - } - if ($level > $conf->global->SYSLOG_LEVEL) return; - - // If adding log inside HTML page is required - if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML))) // MAIN_LOGTOHTML kept for backward compatibility - { - $conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message; - } - - //TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output - // If enable html log tag enabled and url parameter log defined, we show output log on HTML comments - if (! empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && ! empty($_GET["log"])) - { - print "\n\n\n"; - } - - $data = array( - 'message' => $message, - 'script' => (isset($_SERVER['PHP_SELF'])? basename($_SERVER['PHP_SELF'],'.php') : false), - 'level' => $level, - 'user' => ((is_object($user) && $user->id) ? $user->login : false), - 'ip' => false - ); - - if (! empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR']; - // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache) - else if (! empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR']; - // This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it). - else if (! empty($_SERVER['COMPUTERNAME'])) $data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']); - // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it). - else if (! empty($_SERVER['LOGNAME'])) $data['ip'] = '???@'.$_SERVER['LOGNAME']; - // Loop on each log handler and send output - foreach ($conf->loghandlers as $loghandlerinstance) - { - if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) continue; - $loghandlerinstance->export($data,$suffixinfilename); - } - unset($data); + throw new Exception('Incorrect log level'); } + if ($level > $conf->global->SYSLOG_LEVEL) return; + + // If adding log inside HTML page is required + if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML))) // MAIN_LOGTOHTML kept for backward compatibility + { + $conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message; + } + + //TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output + // If enable html log tag enabled and url parameter log defined, we show output log on HTML comments + if (! empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && ! empty($_GET["log"])) + { + print "\n\n\n"; + } + + $data = array( + 'message' => $message, + 'script' => (isset($_SERVER['PHP_SELF'])? basename($_SERVER['PHP_SELF'],'.php') : false), + 'level' => $level, + 'user' => ((is_object($user) && $user->id) ? $user->login : false), + 'ip' => false + ); + + if (! empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR']; + // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache) + else if (! empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR']; + // This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it). + else if (! empty($_SERVER['COMPUTERNAME'])) $data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']); + // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it). + else if (! empty($_SERVER['LOGNAME'])) $data['ip'] = '???@'.$_SERVER['LOGNAME']; + // Loop on each log handler and send output + foreach ($conf->loghandlers as $loghandlerinstance) + { + if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) continue; + $loghandlerinstance->export($data,$suffixinfilename); + } + unset($data); + if (! empty($ident)) { From 8830264c0e5f4b50cee46e0ba5f75139aa1e2020 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Wed, 20 Jul 2016 02:27:40 +0200 Subject: [PATCH 21/23] tooltip not present on picto, already present in $link and some case they are conflict --- htdocs/product/class/product.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 19d667fd6e9..f3f03c65ac6 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3185,8 +3185,8 @@ class Product extends CommonObject } if ($withpicto) { - if ($this->type == Product::TYPE_PRODUCT) $result.=($link.img_object($langs->trans("ShowProduct").' '.$this->label, 'product', 'class="classfortooltip"').$linkend.' '); - if ($this->type == Product::TYPE_SERVICE) $result.=($link.img_object($langs->trans("ShowService").' '.$this->label, 'service', 'class="classfortooltip"').$linkend.' '); + if ($this->type == Product::TYPE_PRODUCT) $result.=($link.img_object('', 'product', '').$linkend.' '); + if ($this->type == Product::TYPE_SERVICE) $result.=($link.img_object('', 'service', '').$linkend.' '); } $result.=$link.$newref.$linkend; return $result; From f2a479695eb4e3b18c73fd2f535aace720b0f601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Mon, 22 Feb 2016 18:45:00 +0100 Subject: [PATCH 22/23] New: Improved forced install process Tamper proofed the process by not relying on POST values for forced fields. Disabled all fields set when $force_install_noedit is set. Added a full-featured forced install config file template. On the side: Improved Dolibarr root and url detection. Prevent install locking if install was not successful. Added missing translation on failed administrator creation. Better escaping of posted values. --- htdocs/install/check.php | 19 +- htdocs/install/fileconf.php | 342 +++++++++++++---------- htdocs/install/inc.php | 100 ++++++- htdocs/install/index.php | 7 +- htdocs/install/install.forced.sample.php | 73 +++++ htdocs/install/step1.php | 148 ++++++---- htdocs/install/step2.php | 15 +- htdocs/install/step4.php | 18 +- htdocs/install/step5.php | 75 +++-- htdocs/install/upgrade.php | 10 +- htdocs/install/upgrade2.php | 12 +- htdocs/langs/en_US/install.lang | 3 +- 12 files changed, 542 insertions(+), 280 deletions(-) create mode 100644 htdocs/install/install.forced.sample.php diff --git a/htdocs/install/check.php b/htdocs/install/check.php index 66a9f7f77bb..c2326d58486 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -1,11 +1,11 @@ - * Copyright (C) 2004-2015 Laurent Destailleur - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2013-2014 Juanjo Menent +/* Copyright (C) 2004-2005 Rodolphe Quiedeville + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013-2014 Juanjo Menent * Copyright (C) 2014 Marcos García - * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2015-2016 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,8 @@ */ include_once 'inc.php'; +global $langs; + $err = 0; $allowinstall = 0; $allowupgrade = false; @@ -42,7 +44,10 @@ $langs->load("install"); $useforcedwizard=false; $forcedfile="./install.forced.php"; if ($conffile == "/etc/dolibarr/conf.php") $forcedfile="/etc/dolibarr/install.forced.php"; -if (@file_exists($forcedfile)) { $useforcedwizard=true; include_once $forcedfile; } +if (@file_exists($forcedfile)) { + $useforcedwizard = true; + include_once $forcedfile; +} dolibarr_install_syslog("--- check: Dolibarr install/upgrade process started"); diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index d0cf9a4a385..1782be430bc 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -1,10 +1,11 @@ - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2004-2012 Laurent Destailleur - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2004 Sebastien DiCintio - * Copyright (C) 2005-2011 Regis Houssin +/* Copyright (C) 2004 Rodolphe Quiedeville + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004 Sebastien DiCintio + * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2016 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +29,8 @@ include_once 'inc.php'; +global $langs; + $err=0; $setuplang=GETPOST("selectlang",'',3)?GETPOST("selectlang",'',3):(isset($_GET["lang"])?$_GET["lang"]:'auto'); @@ -58,12 +61,10 @@ $useforcedwizard=false; $forcedfile="./install.forced.php"; if ($conffile == "/etc/dolibarr/conf.php") $forcedfile="/etc/dolibarr/install.forced.php"; // Must be after inc.php if (@file_exists($forcedfile)) { - $useforcedwizard=true; include_once $forcedfile; + $useforcedwizard = true; + include_once $forcedfile; } -//$force_install_message='This is the message'; -//$force_install_noedit=1; - /* * View @@ -120,37 +121,20 @@ if (! empty($force_install_message)) print $langs->trans("WebPagesDirectory"); print ""; - if(! isset($dolibarr_main_url_root) || dol_strlen($dolibarr_main_url_root) == 0) - { - //print "x".$_SERVER["SCRIPT_FILENAME"]." y".$_SERVER["DOCUMENT_ROOT"]; - - // Si le php fonctionne en CGI, alors SCRIPT_FILENAME vaut le path du php et - // ce n'est pas ce qu'on veut. Dans ce cas, on propose $_SERVER["DOCUMENT_ROOT"] - if (preg_match('/^php$/i',$_SERVER["SCRIPT_FILENAME"]) || preg_match('/[\\/]php$/i',$_SERVER["SCRIPT_FILENAME"]) || preg_match('/php\.exe$/i',$_SERVER["SCRIPT_FILENAME"])) - { - $dolibarr_main_document_root=$_SERVER["DOCUMENT_ROOT"]; - - if (! preg_match('/[\\/]dolibarr[\\/]htdocs$/i',$dolibarr_main_document_root)) - { - $dolibarr_main_document_root.="/dolibarr/htdocs"; - } - } - else - { - $dolibarr_main_document_root = substr($_SERVER["SCRIPT_FILENAME"],0,dol_strlen($_SERVER["SCRIPT_FILENAME"]) - 21); - // Nettoyage du path propose - // Gere les chemins windows avec double "\" - $dolibarr_main_document_root = str_replace('\\\\','/',$dolibarr_main_document_root); - - // Supprime les slash ou antislash de fins - $dolibarr_main_document_root = preg_replace('/[\\/]+$/','',$dolibarr_main_document_root); - } + if (empty($dolibarr_main_url_root)) { + $dolibarr_main_document_root = detect_dolibarr_main_document_root(); } ?> - '; - print ''; - ?> + + + > + trans("WithNoSlashAtTheEnd")."
"; print $langs->trans("Examples").":
"; @@ -167,24 +151,21 @@ if (! empty($force_install_message)) trans("DocumentsDirectory"); ?> - '; - print ''; - ?> + + + > + trans("WithNoSlashAtTheEnd")."
"; print $langs->trans("DirectoryRecommendation")."
"; @@ -199,39 +180,23 @@ if (! empty($force_install_message)) trans("URLRoot"); ?> - '; - print ''; - ?> + + + > + trans("Examples").":
"; ?>
  • http://localhost/
  • @@ -245,9 +210,17 @@ if (! empty($force_install_message)) ?> trans("ForceHttps"); ?> - > + + + + > + trans("CheckToForceHttps"); ?> @@ -265,13 +238,18 @@ if (! empty($force_install_message)) - trans("DatabaseName"); ?> - - - - trans("DatabaseName"); ?> + trans("DatabaseName"); ?> + + + + > + + trans("DatabaseName"); ?> @@ -286,7 +264,8 @@ if (! empty($force_install_message)) trans("DriverType"); ?> - + + - if ($force_install_noedit && $force_install_type) print ''; - print ''; - - ?> + trans("DatabaseType"); ?> @@ -356,11 +339,14 @@ if (! empty($force_install_message)) trans("Server"); ?> - - value=""> - '; ?> + + + > trans("ServerAddressDescription"); ?> @@ -369,11 +355,15 @@ if (! empty($force_install_message)) trans("Port"); ?> - - value=""> - '; ?> + + + > trans("ServerPortDescription"); ?> @@ -383,20 +373,33 @@ if (! empty($force_install_message)) trans("DatabasePrefix"); ?> - - + + + > + trans("DatabasePrefix"); ?> trans("CreateDatabase"); ?> - - > + + + + > + trans("CheckToCreateDatabase"); ?> @@ -404,33 +407,54 @@ if (! empty($force_install_message)) trans("Login"); ?> - + + + > + trans("AdminLogin"); ?> trans("Password"); ?> - + + + > + trans("AdminPassword"); ?> trans("CreateUser"); ?> - - > + + + + > + trans("CheckToCreateUser"); ?> @@ -438,8 +462,8 @@ if (! empty($force_install_message))
    @@ -449,9 +473,17 @@ if (! empty($force_install_message)) trans("Login"); ?> - + + + > + trans("DatabaseRootLoginDescription"); ?>