| Total Complexity | 250 | 
| Total Lines | 1609 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
Complex classes like pdf_crabe_subtotal often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use pdf_crabe_subtotal, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 39 | class pdf_crabe_subtotal extends ModelePDFFactures | ||
| 40 | { | ||
| 41 | var $db; | ||
| 42 | var $name; | ||
| 43 | var $description; | ||
| 44 | var $type; | ||
| 45 | |||
| 46 | var $phpmin = array(4,3,0); // Minimum version of PHP required by module | ||
| 47 | var $version = 'dolibarr'; | ||
| 48 | |||
| 49 | var $page_largeur; | ||
| 50 | var $page_hauteur; | ||
| 51 | var $format; | ||
| 52 | var $marge_gauche; | ||
| 53 | var $marge_droite; | ||
| 54 | var $marge_haute; | ||
| 55 | var $marge_basse; | ||
| 56 | |||
| 57 | var $emetteur; // Objet societe qui emet | ||
| 58 | |||
| 59 | |||
| 60 | /** | ||
| 61 | * Constructor | ||
| 62 | * | ||
| 63 | * @param DoliDB $db Database handler | ||
| 64 | */ | ||
| 65 | function __construct($db) | ||
|  | |||
| 66 | 	{ | ||
| 67 | global $conf,$langs,$mysoc; | ||
| 68 | |||
| 69 | 		$langs->load("main"); | ||
| 70 | 		$langs->load("bills"); | ||
| 71 | |||
| 72 | $this->db = $db; | ||
| 73 | $this->name = "crabe_subtotal"; | ||
| 74 | // J'ajoute l'annotation "déprécié" mais à garder... des fois qu'un client avec une vieille version utilise les modèles PDF custom | ||
| 75 | $this->description = 'Modèle de facture incluant des spécificités pour le module sous-total. (déprécié)'; | ||
| 76 | |||
| 77 | // Dimension page pour format A4 | ||
| 78 | $this->type = 'pdf'; | ||
| 79 | $formatarray=pdf_getFormat(); | ||
| 80 | $this->page_largeur = $formatarray['width']; | ||
| 81 | $this->page_hauteur = $formatarray['height']; | ||
| 82 | $this->format = array($this->page_largeur,$this->page_hauteur); | ||
| 83 | $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; | ||
| 84 | $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; | ||
| 85 | $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; | ||
| 86 | $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; | ||
| 87 | |||
| 88 | $this->option_logo = 1; // Affiche logo | ||
| 89 | $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION | ||
| 90 | $this->option_modereg = 1; // Affiche mode reglement | ||
| 91 | $this->option_condreg = 1; // Affiche conditions reglement | ||
| 92 | $this->option_codeproduitservice = 1; // Affiche code produit-service | ||
| 93 | $this->option_multilang = 1; // Dispo en plusieurs langues | ||
| 94 | $this->option_escompte = 1; // Affiche si il y a eu escompte | ||
| 95 | $this->option_credit_note = 1; // Support credit notes | ||
| 96 | $this->option_freetext = 1; // Support add of a personalised text | ||
| 97 | $this->option_draft_watermark = 1; // Support add of a watermark on drafts | ||
| 98 | |||
| 99 | $this->franchise=!$mysoc->tva_assuj; | ||
| 100 | |||
| 101 | // Get source company | ||
| 102 | $this->emetteur=$mysoc; | ||
| 103 | if (empty($this->emetteur->country_code)) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined | ||
| 104 | |||
| 105 | // Define position of columns | ||
| 106 | $this->posxdesc=$this->marge_gauche+1; | ||
| 107 | $this->posxtva=112; | ||
| 108 | $this->posxup=126; | ||
| 109 | $this->posxqty=145; | ||
| 110 | $this->posxdiscount=162; | ||
| 111 | $this->postotalht=174; | ||
| 112 | if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; | ||
| 113 | $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images | ||
| 114 | if ($this->page_largeur < 210) // To work with US executive format | ||
| 115 | 		{ | ||
| 116 | $this->posxpicture-=20; | ||
| 117 | $this->posxtva-=20; | ||
| 118 | $this->posxup-=20; | ||
| 119 | $this->posxqty-=20; | ||
| 120 | $this->posxdiscount-=20; | ||
| 121 | $this->postotalht-=20; | ||
| 122 | } | ||
| 123 | |||
| 124 | $this->tva=array(); | ||
| 125 | $this->localtax1=array(); | ||
| 126 | $this->localtax2=array(); | ||
| 127 | $this->atleastoneratenotnull=0; | ||
| 128 | $this->atleastonediscount=0; | ||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | /** | ||
| 133 | * Function to build pdf onto disk | ||
| 134 | * | ||
| 135 | * @param Object $object Object to generate | ||
| 136 | * @param Translate $outputlangs Lang output object | ||
| 137 | * @param string $srctemplatepath Full path of source filename for generator using a template file | ||
| 138 | * @param int $hidedetails Do not show line details | ||
| 139 | * @param int $hidedesc Do not show desc | ||
| 140 | * @param int $hideref Do not show ref | ||
| 141 | * @return int 1=OK, 0=KO | ||
| 142 | */ | ||
| 143 | function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) | ||
| 144 | 	{ | ||
| 145 | global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; | ||
| 146 | |||
| 147 | if (! is_object($outputlangs)) $outputlangs=$langs; | ||
| 148 | // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO | ||
| 149 | if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; | ||
| 150 | |||
| 151 | 		$outputlangs->load("main"); | ||
| 152 | 		$outputlangs->load("dict"); | ||
| 153 | 		$outputlangs->load("companies"); | ||
| 154 | 		$outputlangs->load("bills"); | ||
| 155 | 		$outputlangs->load("products"); | ||
| 156 | |||
| 157 | $nblignes = count($object->lines); | ||
| 158 | |||
| 159 | // Loop on each lines to detect if there is at least one image to show | ||
| 160 | $realpatharray=array(); | ||
| 161 | if (! empty($conf->global->MAIN_GENERATE_INVOICES_WITH_PICTURE)) | ||
| 162 | 		{ | ||
| 163 | for ($i = 0 ; $i < $nblignes ; $i++) | ||
| 164 | 			{ | ||
| 165 | if (empty($object->lines[$i]->fk_product)) continue; | ||
| 166 | |||
| 167 | $objphoto = new Product($this->db); | ||
| 168 | $objphoto->fetch($object->lines[$i]->fk_product); | ||
| 169 | |||
| 170 | $pdir = get_exdir($object->lines[$i]->fk_product,2) . $object->lines[$i]->fk_product ."/photos/"; | ||
| 171 | $dir = $conf->product->dir_output.'/'.$pdir; | ||
| 172 | |||
| 173 | $realpath=''; | ||
| 174 | foreach ($objphoto->liste_photos($dir,1) as $key => $obj) | ||
| 175 | 				{ | ||
| 176 | $filename=$obj['photo']; | ||
| 177 | //if ($obj['photo_vignette']) $filename='thumbs/'.$obj['photo_vignette']; | ||
| 178 | $realpath = $dir.$filename; | ||
| 179 | break; | ||
| 180 | } | ||
| 181 | |||
| 182 | if ($realpath) $realpatharray[$i]=$realpath; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva; | ||
| 186 | |||
| 187 | if ($conf->facture->dir_output) | ||
| 188 | 		{ | ||
| 189 | $object->fetch_thirdparty(); | ||
| 190 | 			if(!empty($object->client) ){ | ||
| 191 | $object->thirdparty = $object->client; | ||
| 192 | } | ||
| 193 | $deja_regle = $object->getSommePaiement(); | ||
| 194 | $amount_credit_notes_included = $object->getSumCreditNotesUsed(); | ||
| 195 | $amount_deposits_included = $object->getSumDepositsUsed(); | ||
| 196 | |||
| 197 | // Definition of $dir and $file | ||
| 198 | if ($object->specimen) | ||
| 199 | 			{ | ||
| 200 | $dir = $conf->facture->dir_output; | ||
| 201 | $file = $dir . "/SPECIMEN.pdf"; | ||
| 202 | } | ||
| 203 | else | ||
| 204 | 			{ | ||
| 205 | $objectref = dol_sanitizeFileName($object->ref); | ||
| 206 | $dir = $conf->facture->dir_output . "/" . $objectref; | ||
| 207 | $file = $dir . "/" . $objectref . ".pdf"; | ||
| 208 | } | ||
| 209 | if (! file_exists($dir)) | ||
| 210 | 			{ | ||
| 211 | if (dol_mkdir($dir) < 0) | ||
| 212 | 				{ | ||
| 213 | 					$this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); | ||
| 214 | return 0; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | if (file_exists($dir)) | ||
| 219 | 			{ | ||
| 220 | // Add pdfgeneration hook | ||
| 221 | if (! is_object($hookmanager)) | ||
| 222 | 				{ | ||
| 223 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; | ||
| 224 | $hookmanager=new HookManager($this->db); | ||
| 225 | } | ||
| 226 | 				$hookmanager->initHooks(array('pdfgeneration')); | ||
| 227 | 				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); | ||
| 228 | global $action; | ||
| 229 | 				$reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks | ||
| 230 | |||
| 231 | // Create pdf instance | ||
| 232 | $pdf=pdf_getInstance($this->format); | ||
| 233 | $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance | ||
| 234 | $heightforinfotot = 50; // Height reserved to output the info and total part | ||
| 235 | $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 | ||
| 236 | $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) | ||
| 237 | $pdf->SetAutoPageBreak(1,0); | ||
| 238 | |||
| 239 |                 if (class_exists('TCPDF')) | ||
| 240 |                 { | ||
| 241 | $pdf->setPrintHeader(false); | ||
| 242 | $pdf->setPrintFooter(false); | ||
| 243 | } | ||
| 244 | $pdf->SetFont(pdf_getPDFFont($outputlangs)); | ||
| 245 | |||
| 246 | // Set path to the background PDF File | ||
| 247 | if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) | ||
| 248 |                 { | ||
| 249 | $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); | ||
| 250 | $tplidx = $pdf->importPage(1); | ||
| 251 | } | ||
| 252 | |||
| 253 | $pdf->Open(); | ||
| 254 | $pagenb=0; | ||
| 255 | $pdf->SetDrawColor(128,128,128); | ||
| 256 | |||
| 257 | $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); | ||
| 258 | 				$pdf->SetSubject($outputlangs->transnoentities("Invoice")); | ||
| 259 | 				$pdf->SetCreator("Dolibarr ".DOL_VERSION); | ||
| 260 | $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); | ||
| 261 | 				$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Invoice")); | ||
| 262 | if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); | ||
| 263 | |||
| 264 | $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right | ||
| 265 | |||
| 266 | // Positionne $this->atleastonediscount si on a au moins une remise | ||
| 267 | for ($i = 0 ; $i < $nblignes ; $i++) | ||
| 268 | 				{ | ||
| 269 | if ($object->lines[$i]->remise_percent) | ||
| 270 | 					{ | ||
| 271 | $this->atleastonediscount++; | ||
| 272 | } | ||
| 273 | } | ||
| 274 | if (empty($this->atleastonediscount)) | ||
| 275 | 				{ | ||
| 276 | $this->posxpicture+=($this->postotalht - $this->posxdiscount); | ||
| 277 | $this->posxtva+=($this->postotalht - $this->posxdiscount); | ||
| 278 | $this->posxup+=($this->postotalht - $this->posxdiscount); | ||
| 279 | $this->posxqty+=($this->postotalht - $this->posxdiscount); | ||
| 280 | $this->posxdiscount+=($this->postotalht - $this->posxdiscount); | ||
| 281 | //$this->postotalht; | ||
| 282 | } | ||
| 283 | |||
| 284 | // New page | ||
| 285 | $pdf->AddPage(); | ||
| 286 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); | ||
| 287 | $pagenb++; | ||
| 288 | |||
| 289 | $this->_pagehead($pdf, $object, 1, $outputlangs); | ||
| 290 | 				$pdf->SetFont('','', $default_font_size - 1); | ||
| 291 | $pdf->MultiCell(0, 3, ''); // Set interline to 3 | ||
| 292 | $pdf->SetTextColor(0,0,0); | ||
| 293 | |||
| 294 | $tab_top = 90; | ||
| 295 | $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); | ||
| 296 | $tab_height = 130; | ||
| 297 | $tab_height_newpage = 150; | ||
| 298 | |||
| 299 | // Affiche notes | ||
| 300 | $notetoshow=empty($object->note_public)?'':$object->note_public; | ||
| 301 | if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) | ||
| 302 | 				{ | ||
| 303 | // Get first sale rep | ||
| 304 | if (is_object($object->thirdparty)) | ||
| 305 | 					{ | ||
| 306 | $salereparray=$object->thirdparty->getSalesRepresentatives($user); | ||
| 307 | $salerepobj=new User($this->db); | ||
| 308 | $salerepobj->fetch($salereparray[0]['id']); | ||
| 309 | if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature); | ||
| 310 | } | ||
| 311 | } | ||
| 312 | if ($notetoshow) | ||
| 313 | 				{ | ||
| 314 | $tab_top = 88; | ||
| 315 | |||
| 316 | 					$pdf->SetFont('','', $default_font_size - 1); | ||
| 317 | $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); | ||
| 318 | $nexY = $pdf->GetY(); | ||
| 319 | $height_note=$nexY-$tab_top; | ||
| 320 | |||
| 321 | // Rect prend une longueur en 3eme param | ||
| 322 | $pdf->SetDrawColor(192,192,192); | ||
| 323 | $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); | ||
| 324 | |||
| 325 | $tab_height = $tab_height - $height_note; | ||
| 326 | $tab_top = $nexY+6; | ||
| 327 | } | ||
| 328 | else | ||
| 329 | 				{ | ||
| 330 | $height_note=0; | ||
| 331 | } | ||
| 332 | |||
| 333 | $iniY = $tab_top + 7; | ||
| 334 | $curY = $tab_top + 7; | ||
| 335 | $nexY = $tab_top + 7; | ||
| 336 | |||
| 337 | $inPackage = false; | ||
| 338 | $TPackageInfos = array(); | ||
| 339 | $TChilds = array(); | ||
| 340 | $package_qty = 0; | ||
| 341 | $TStack = array(); | ||
| 342 | |||
| 343 | // Loop on each lines | ||
| 344 | for ($i = 0; $i < $nblignes; $i++) | ||
| 345 | 				{ | ||
| 346 | $package_qty = $TStack[count($TStack) - 1]['package_qty']; | ||
| 347 | $inPackage = count($TStack) > 0; | ||
| 348 | |||
| 349 | // Ligne de titre | ||
| 350 | 					if ($object->lines[$i]->product_type == 9 && $object->lines[$i]->qty < 97) { | ||
| 351 | $inPackage = true; | ||
| 352 | |||
| 353 | 						if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { | ||
| 354 | 							if (!empty($object->lines[$i]->fk_product)) { | ||
| 355 | $product = new Product($db); | ||
| 356 | $product->fetch($object->lines[$i]->fk_product); | ||
| 357 | |||
| 358 | $TChilds = $product->getChildsArbo($product->id); | ||
| 359 | |||
| 360 | $TStack[count($TStack)] = array( | ||
| 361 | 'childs' => $TChilds, | ||
| 362 | 'package' => array(), | ||
| 363 | 'package_qty' => 0 | ||
| 364 | ); | ||
| 365 | |||
| 366 | // Si on se trouvait déjà dans un package, on rajoute ce produit à la liste des produits | ||
| 367 | // du précédent package | ||
| 368 | 								if (count($TStack) > 1) { | ||
| 369 | $TStack[count($TStack) - 2]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty; | ||
| 370 | } | ||
| 371 | } | ||
| 372 | } | ||
| 373 | } | ||
| 374 | |||
| 375 | 					if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { | ||
| 376 | 						if ($inPackage && $object->lines[$i]->product_type != 9 && $object->lines[$i]->fk_product > 0) { | ||
| 377 | $TStack[count($TStack) - 1]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty; | ||
| 378 | } | ||
| 379 | } | ||
| 380 | |||
| 381 | 					if ($inPackage && $object->lines[$i]->product_type == 9 && $object->lines[$i]->qty >= 97) { | ||
| 382 | 						if (count($TStack) <= 1) { | ||
| 383 | $inPackage = false; | ||
| 384 | } | ||
| 385 | |||
| 386 | 						if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { | ||
| 387 | // Comparaison pour déterminer la quantité de package | ||
| 388 | $TProducts = array_keys($TStack[count($TStack) - 1]['package']); | ||
| 389 | $TProductsChilds = array_keys($TStack[count($TStack) - 1]['childs']); | ||
| 390 | |||
| 391 | 							if ($TProductsChilds == $TProducts) { | ||
| 392 | // Il s'agit d'un package | ||
| 393 | // On récupére la quantité | ||
| 394 | $first_child_id = $TProducts[0]; | ||
| 395 | $document_qty = $TStack[count($TStack) - 1]['package'][$first_child_id]; | ||
| 396 | $base_qty = $TStack[count($TStack) - 1]['childs'][$first_child_id][1]; | ||
| 397 | |||
| 398 | $TStack[count($TStack) - 1]['package_qty'] = $document_qty / $base_qty; | ||
| 399 | $package_qty = $TStack[count($TStack) - 1]['package_qty']; | ||
| 400 | } | ||
| 401 | |||
| 402 | array_pop($TStack); | ||
| 403 | } | ||
| 404 | } | ||
| 405 | |||
| 406 | $curY = $nexY; | ||
| 407 | 					$pdf->SetFont('','', $default_font_size - 1);   // Into loop to work with multipage | ||
| 408 | $pdf->SetTextColor(0,0,0); | ||
| 409 | |||
| 410 | // Define size of image if we need it | ||
| 411 | $imglinesize=array(); | ||
| 412 | if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]); | ||
| 413 | |||
| 414 | $pdf->setTopMargin($tab_top_newpage); | ||
| 415 | 					$pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot);	// The only function to edit the bottom margin of current page to set it. | ||
| 416 | $pageposbefore=$pdf->getPage(); | ||
| 417 | |||
| 418 | $showpricebeforepagebreak=1; | ||
| 419 | $posYAfterImage=0; | ||
| 420 | $posYAfterDescription=0; | ||
| 421 | |||
| 422 | // We start with Photo of product line | ||
| 423 | 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 | ||
| 424 | 					{ | ||
| 425 | 						$pdf->AddPage('','',true); | ||
| 426 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); | ||
| 427 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); | ||
| 428 | $pdf->setPage($pageposbefore+1); | ||
| 429 | |||
| 430 | $curY = $tab_top_newpage; | ||
| 431 | $showpricebeforepagebreak=0; | ||
| 432 | } | ||
| 433 | |||
| 434 | if (isset($imglinesize['width']) && isset($imglinesize['height'])) | ||
| 435 | 					{ | ||
| 436 | $curX = $this->posxpicture-1; | ||
| 437 | $pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi | ||
| 438 | // $pdf->Image does not increase value return by getY, so we save it manually | ||
| 439 | $posYAfterImage=$curY+$imglinesize['height']; | ||
| 440 | } | ||
| 441 | |||
| 442 | // Description of product line | ||
| 443 | $curX = $this->posxdesc-1; | ||
| 444 | |||
| 445 | $pdf->startTransaction(); | ||
| 446 | pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); | ||
| 447 | $pageposafter=$pdf->getPage(); | ||
| 448 | if ($pageposafter > $pageposbefore) // There is a pagebreak | ||
| 449 | 					{ | ||
| 450 | $pdf->rollbackTransaction(true); | ||
| 451 | $pageposafter=$pageposbefore; | ||
| 452 | //print $pageposafter.'-'.$pageposbefore;exit; | ||
| 453 | 						$pdf->setPageOrientation('', 1, $heightforfooter);	// The only function to edit the bottom margin of current page to set it. | ||
| 454 | pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); | ||
| 455 | $pageposafter=$pdf->getPage(); | ||
| 456 | $posyafter=$pdf->GetY(); | ||
| 457 | //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; | ||
| 458 | if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text | ||
| 459 | 						{ | ||
| 460 | if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page | ||
| 461 | 							{ | ||
| 462 | 								$pdf->AddPage('','',true); | ||
| 463 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); | ||
| 464 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); | ||
| 465 | $pdf->setPage($pageposafter+1); | ||
| 466 | } | ||
| 467 | } | ||
| 468 | else | ||
| 469 | 						{ | ||
| 470 | // We found a page break | ||
| 471 | $showpricebeforepagebreak=0; | ||
| 472 | } | ||
| 473 | } | ||
| 474 | else // No pagebreak | ||
| 475 | 					{ | ||
| 476 | $pdf->commitTransaction(); | ||
| 477 | } | ||
| 478 | $posYAfterDescription=$pdf->GetY(); | ||
| 479 | |||
| 480 | $nexY = $pdf->GetY(); | ||
| 481 | $pageposafter=$pdf->getPage(); | ||
| 482 | $pdf->setPage($pageposbefore); | ||
| 483 | $pdf->setTopMargin($this->marge_haute); | ||
| 484 | 					$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it. | ||
| 485 | |||
| 486 | // We suppose that a too long description or photo were moved completely on next page | ||
| 487 | 					if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { | ||
| 488 | $pdf->setPage($pageposafter); $curY = $tab_top_newpage; | ||
| 489 | } | ||
| 490 | |||
| 491 | 					$pdf->SetFont('','', $default_font_size - 1);   // On repositionne la police par defaut | ||
| 492 | |||
| 493 | // VAT Rate | ||
| 494 | if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) | ||
| 495 | 					{ | ||
| 496 | // Si on ne doit masquer que les sous-produits | ||
| 497 | 						if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { | ||
| 498 | $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, 0); | ||
| 499 | 						} else { | ||
| 500 | $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); | ||
| 501 | } | ||
| 502 | |||
| 503 | $pdf->SetXY($this->posxtva, $curY); | ||
| 504 | $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R'); | ||
| 505 | } | ||
| 506 | |||
| 507 | // Unit price before discount | ||
| 508 | 					if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { | ||
| 509 | $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, 0); | ||
| 510 | 					} else { | ||
| 511 | $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); | ||
| 512 | } | ||
| 513 | |||
| 514 | $pdf->SetXY($this->posxup, $curY); | ||
| 515 | $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0); | ||
| 516 | |||
| 517 | // Quantity | ||
| 518 | // Affichage de la quantité sur les lignes de total si la conf l'indique | ||
| 519 | |||
| 520 | // Récupération de la quantité à afficher | ||
| 521 | 					if ($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY && $hidedetails) { | ||
| 522 | 						if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) { | ||
| 523 | $qty = $package_qty; | ||
| 524 | 						} else { | ||
| 525 | $qty = pdf_getlineqty($object, $i, $outputlangs, 0); | ||
| 526 | } | ||
| 527 | 					} else { | ||
| 528 | 						if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) { | ||
| 529 | $qty = $package_qty; | ||
| 530 | 						} else { | ||
| 531 | $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); | ||
| 532 | } | ||
| 533 | } | ||
| 534 | |||
| 535 | $pdf->SetXY($this->posxqty, $curY); | ||
| 536 | $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars | ||
| 537 | |||
| 538 | // Discount on line | ||
| 539 | if ($object->lines[$i]->remise_percent) | ||
| 540 | 					{ | ||
| 541 | $pdf->SetXY($this->posxdiscount-2, $curY); | ||
| 542 | $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); | ||
| 543 | $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R'); | ||
| 544 | } | ||
| 545 | |||
| 546 | // Total HT line | ||
| 547 | 					if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { | ||
| 548 | $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, 0); | ||
| 549 | 					} else { | ||
| 550 | $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); | ||
| 551 | } | ||
| 552 | |||
| 553 | $pdf->SetXY($this->postotalht, $curY); | ||
| 554 | $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); | ||
| 555 | |||
| 556 | // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva | ||
| 557 | $tvaligne=doubleval($object->lines[$i]->total_tva); | ||
| 558 | $localtax1ligne=$object->lines[$i]->total_localtax1; | ||
| 559 | $localtax2ligne=$object->lines[$i]->total_localtax2; | ||
| 560 | $localtax1_rate=$object->lines[$i]->localtax1_tx; | ||
| 561 | $localtax2_rate=$object->lines[$i]->localtax2_tx; | ||
| 562 | $localtax1_type=$object->lines[$i]->localtax1_type; | ||
| 563 | $localtax2_type=$object->lines[$i]->localtax2_type; | ||
| 564 | |||
| 565 | if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100; | ||
| 566 | if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100; | ||
| 567 | if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100; | ||
| 568 | |||
| 569 | $vatrate=(string) $object->lines[$i]->tva_tx; | ||
| 570 | |||
| 571 | // Retrieve type from database for backward compatibility with old records | ||
| 572 | if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined | ||
| 573 | && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax | ||
| 574 | 					{ | ||
| 575 | $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0, $object->thirdparty, $mysoc); | ||
| 576 | $localtax1_type = $localtaxtmp_array[0]; | ||
| 577 | $localtax2_type = $localtaxtmp_array[2]; | ||
| 578 | } | ||
| 579 | |||
| 580 | // retrieve global local tax | ||
| 581 | if ($localtax1_type && $localtax1ligne != 0) | ||
| 582 | $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne; | ||
| 583 | if ($localtax2_type && $localtax2ligne != 0) | ||
| 584 | $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne; | ||
| 585 | |||
| 586 | if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*'; | ||
| 587 | if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=''; | ||
| 588 | |||
| 589 | if (!empty($object->lines[$i]->TTotal_tva)) | ||
| 590 | 					{ | ||
| 591 | foreach ($object->lines[$i]->TTotal_tva as $vatrate => $tvaligne) | ||
| 592 | 						{ | ||
| 593 | $this->tva[$vatrate] += $tvaligne; | ||
| 594 | } | ||
| 595 | } | ||
| 596 | 					else { | ||
| 597 | // standard | ||
| 598 | if(!empty($tvaligne)) $this->tva[$vatrate] += $tvaligne; | ||
| 599 | } | ||
| 600 | |||
| 601 | if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage; | ||
| 602 | |||
| 603 | // Add line | ||
| 604 | if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) | ||
| 605 | 					{ | ||
| 606 | $pdf->setPage($pageposafter); | ||
| 607 | 						$pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(210,210,210))); | ||
| 608 | //$pdf->SetDrawColor(190,190,200); | ||
| 609 | $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); | ||
| 610 | 						$pdf->SetLineStyle(array('dash'=>0)); | ||
| 611 | } | ||
| 612 | |||
| 613 | $nexY+=2; // Passe espace entre les lignes | ||
| 614 | |||
| 615 | // Detect if some page were added automatically and output _tableau for past pages | ||
| 616 | while ($pagenb < $pageposafter) | ||
| 617 | 					{ | ||
| 618 | $pdf->setPage($pagenb); | ||
| 619 | if ($pagenb == 1) | ||
| 620 | 						{ | ||
| 621 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); | ||
| 622 | } | ||
| 623 | else | ||
| 624 | 						{ | ||
| 625 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); | ||
| 626 | } | ||
| 627 | $this->_pagefoot($pdf,$object,$outputlangs,1); | ||
| 628 | $pagenb++; | ||
| 629 | $pdf->setPage($pagenb); | ||
| 630 | 						$pdf->setPageOrientation('', 1, 0);	// The only function to edit the bottom margin of current page to set it. | ||
| 631 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); | ||
| 632 | } | ||
| 633 | if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) | ||
| 634 | 					{ | ||
| 635 | if ($pagenb == 1) | ||
| 636 | 						{ | ||
| 637 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); | ||
| 638 | } | ||
| 639 | else | ||
| 640 | 						{ | ||
| 641 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); | ||
| 642 | } | ||
| 643 | $this->_pagefoot($pdf,$object,$outputlangs,1); | ||
| 644 | // New page | ||
| 645 | $pdf->AddPage(); | ||
| 646 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); | ||
| 647 | $pagenb++; | ||
| 648 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); | ||
| 649 | } | ||
| 650 | } | ||
| 651 | |||
| 652 | // Show square | ||
| 653 | if ($pagenb == 1) | ||
| 654 | 				{ | ||
| 655 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); | ||
| 656 | $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; | ||
| 657 | } | ||
| 658 | else | ||
| 659 | 				{ | ||
| 660 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); | ||
| 661 | $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; | ||
| 662 | } | ||
| 663 | |||
| 664 | // Affiche zone infos | ||
| 665 | $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); | ||
| 666 | |||
| 667 | 				if (!$conf->global->SUBTOTAL_HIDE_DOCUMENT_TOTAL) { | ||
| 668 | // Affiche zone totaux | ||
| 669 | $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); | ||
| 670 | } | ||
| 671 | |||
| 672 | // Affiche zone versements | ||
| 673 | if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) | ||
| 674 | 				{ | ||
| 675 | $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); | ||
| 676 | } | ||
| 677 | |||
| 678 | // Pied de page | ||
| 679 | $this->_pagefoot($pdf,$object,$outputlangs); | ||
| 680 | if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); | ||
| 681 | |||
| 682 | $pdf->Close(); | ||
| 683 | |||
| 684 | $pdf->Output($file,'F'); | ||
| 685 | |||
| 686 | // Add pdfgeneration hook | ||
| 687 | 				$hookmanager->initHooks(array('pdfgeneration')); | ||
| 688 | 				$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); | ||
| 689 | global $action; | ||
| 690 | 				$reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks | ||
| 691 | |||
| 692 | if (! empty($conf->global->MAIN_UMASK)) | ||
| 693 | @chmod($file, octdec($conf->global->MAIN_UMASK)); | ||
| 694 | |||
| 695 | return 1; // Pas d'erreur | ||
| 696 | } | ||
| 697 | else | ||
| 698 | 			{ | ||
| 699 | 				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir); | ||
| 700 | return 0; | ||
| 701 | } | ||
| 702 | } | ||
| 703 | else | ||
| 704 | 		{ | ||
| 705 | 			$this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); | ||
| 706 | return 0; | ||
| 707 | } | ||
| 708 | 		$this->error=$langs->trans("ErrorUnknown"); | ||
| 709 | return 0; // Erreur par defaut | ||
| 710 | } | ||
| 711 | |||
| 712 | |||
| 713 | /** | ||
| 714 | * Show payments table | ||
| 715 | * | ||
| 716 | * @param PDF $pdf Object PDF | ||
| 717 | * @param Object $object Object invoice | ||
| 718 | * @param int $posy Position y in PDF | ||
| 719 | * @param Translate $outputlangs Object langs for output | ||
| 720 | * @return int <0 if KO, >0 if OK | ||
| 721 | */ | ||
| 722 | function _tableau_versements(&$pdf, $object, $posy, $outputlangs) | ||
| 723 | 	{ | ||
| 724 | global $conf; | ||
| 725 | |||
| 726 | $sign=1; | ||
| 727 | if ($object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; | ||
| 728 | |||
| 729 | $tab3_posx = 120; | ||
| 730 | $tab3_top = $posy + 8; | ||
| 731 | $tab3_width = 80; | ||
| 732 | $tab3_height = 4; | ||
| 733 | if ($this->page_largeur < 210) // To work with US executive format | ||
| 734 | 		{ | ||
| 735 | $tab3_posx -= 20; | ||
| 736 | } | ||
| 737 | |||
| 738 | $default_font_size = pdf_getPDFFontSize($outputlangs); | ||
| 739 | |||
| 740 | 		$title=$outputlangs->transnoentities("PaymentsAlreadyDone"); | ||
| 741 | 		if ($object->type == 2) $title=$outputlangs->transnoentities("PaymentsBackAlreadyDone"); | ||
| 742 | |||
| 743 | 		$pdf->SetFont('','', $default_font_size - 3); | ||
| 744 | $pdf->SetXY($tab3_posx, $tab3_top - 4); | ||
| 745 | $pdf->MultiCell(60, 3, $title, 0, 'L', 0); | ||
| 746 | |||
| 747 | $pdf->line($tab3_posx, $tab3_top, $tab3_posx+$tab3_width, $tab3_top); | ||
| 748 | |||
| 749 | 		$pdf->SetFont('','', $default_font_size - 4); | ||
| 750 | $pdf->SetXY($tab3_posx, $tab3_top); | ||
| 751 | 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Payment"), 0, 'L', 0); | ||
| 752 | $pdf->SetXY($tab3_posx+21, $tab3_top); | ||
| 753 | 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Amount"), 0, 'L', 0); | ||
| 754 | $pdf->SetXY($tab3_posx+40, $tab3_top); | ||
| 755 | 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Type"), 0, 'L', 0); | ||
| 756 | $pdf->SetXY($tab3_posx+58, $tab3_top); | ||
| 757 | 		$pdf->MultiCell(20, 3, $outputlangs->transnoentities("Num"), 0, 'L', 0); | ||
| 758 | |||
| 759 | $pdf->line($tab3_posx, $tab3_top-1+$tab3_height, $tab3_posx+$tab3_width, $tab3_top-1+$tab3_height); | ||
| 760 | |||
| 761 | $y=0; | ||
| 762 | |||
| 763 | 		$pdf->SetFont('','', $default_font_size - 4); | ||
| 764 | |||
| 765 | // Loop on each deposits and credit notes included | ||
| 766 | $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; | ||
| 767 | $sql.= " re.description, re.fk_facture_source,"; | ||
| 768 | $sql.= " f.type, f.datef"; | ||
| 769 | $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re, ".MAIN_DB_PREFIX ."facture as f"; | ||
| 770 | $sql.= " WHERE re.fk_facture_source = f.rowid AND re.fk_facture = ".$object->id; | ||
| 771 | $resql=$this->db->query($sql); | ||
| 772 | if ($resql) | ||
| 773 | 		{ | ||
| 774 | $num = $this->db->num_rows($resql); | ||
| 775 | $i=0; | ||
| 776 | $invoice=new Facture($this->db); | ||
| 777 | while ($i < $num) | ||
| 778 | 			{ | ||
| 779 | $y+=3; | ||
| 780 | $obj = $this->db->fetch_object($resql); | ||
| 781 | |||
| 782 | 				if ($obj->type == 2) $text=$outputlangs->trans("CreditNote"); | ||
| 783 | 				elseif ($obj->type == 3) $text=$outputlangs->trans("Deposit"); | ||
| 784 | 				else $text=$outputlangs->trans("UnknownType"); | ||
| 785 | |||
| 786 | $invoice->fetch($obj->fk_facture_source); | ||
| 787 | |||
| 788 | $pdf->SetXY($tab3_posx, $tab3_top+$y); | ||
| 789 | $pdf->MultiCell(20, 3, dol_print_date($obj->datef,'day',false,$outputlangs,true), 0, 'L', 0); | ||
| 790 | $pdf->SetXY($tab3_posx+21, $tab3_top+$y); | ||
| 791 | $pdf->MultiCell(20, 3, price($obj->amount_ttc, 0, $outputlangs), 0, 'L', 0); | ||
| 792 | $pdf->SetXY($tab3_posx+40, $tab3_top+$y); | ||
| 793 | $pdf->MultiCell(20, 3, $text, 0, 'L', 0); | ||
| 794 | $pdf->SetXY($tab3_posx+58, $tab3_top+$y); | ||
| 795 | $pdf->MultiCell(20, 3, $invoice->ref, 0, 'L', 0); | ||
| 796 | |||
| 797 | $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3); | ||
| 798 | |||
| 799 | $i++; | ||
| 800 | } | ||
| 801 | } | ||
| 802 | else | ||
| 803 | 		{ | ||
| 804 | $this->error=$this->db->lasterror(); | ||
| 805 | return -1; | ||
| 806 | } | ||
| 807 | |||
| 808 | // Loop on each payment | ||
| 809 | $sql = "SELECT p.datep as date, p.fk_paiement as type, p.num_paiement as num, pf.amount as amount,"; | ||
| 810 | $sql.= " cp.code"; | ||
| 811 | $sql.= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; | ||
| 812 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; | ||
| 813 | $sql.= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".$object->id; | ||
| 814 | $sql.= " ORDER BY p.datep"; | ||
| 815 | $resql=$this->db->query($sql); | ||
| 816 | if ($resql) | ||
| 817 | 		{ | ||
| 818 | $num = $this->db->num_rows($resql); | ||
| 819 | $i=0; | ||
| 820 | 			while ($i < $num) { | ||
| 821 | $y+=3; | ||
| 822 | $row = $this->db->fetch_object($resql); | ||
| 823 | |||
| 824 | $pdf->SetXY($tab3_posx, $tab3_top+$y); | ||
| 825 | $pdf->MultiCell(20, 3, dol_print_date($this->db->jdate($row->date),'day',false,$outputlangs,true), 0, 'L', 0); | ||
| 826 | $pdf->SetXY($tab3_posx+21, $tab3_top+$y); | ||
| 827 | $pdf->MultiCell(20, 3, price($sign * $row->amount, 0, $outputlangs), 0, 'L', 0); | ||
| 828 | $pdf->SetXY($tab3_posx+40, $tab3_top+$y); | ||
| 829 | 				$oper = $outputlangs->transnoentitiesnoconv("PaymentTypeShort" . $row->code); | ||
| 830 | |||
| 831 | $pdf->MultiCell(20, 3, $oper, 0, 'L', 0); | ||
| 832 | $pdf->SetXY($tab3_posx+58, $tab3_top+$y); | ||
| 833 | $pdf->MultiCell(30, 3, $row->num, 0, 'L', 0); | ||
| 834 | |||
| 835 | $pdf->line($tab3_posx, $tab3_top+$y+3, $tab3_posx+$tab3_width, $tab3_top+$y+3); | ||
| 836 | |||
| 837 | $i++; | ||
| 838 | } | ||
| 839 | } | ||
| 840 | else | ||
| 841 | 		{ | ||
| 842 | $this->error=$this->db->lasterror(); | ||
| 843 | return -1; | ||
| 844 | } | ||
| 845 | |||
| 846 | } | ||
| 847 | |||
| 848 | |||
| 849 | /** | ||
| 850 | * Show miscellaneous information (payment mode, payment term, ...) | ||
| 851 | * | ||
| 852 | * @param PDF $pdf Object PDF | ||
| 853 | * @param Object $object Object to show | ||
| 854 | * @param int $posy Y | ||
| 855 | * @param Translate $outputlangs Langs object | ||
| 856 | * @return void | ||
| 857 | */ | ||
| 858 | function _tableau_info(&$pdf, $object, $posy, $outputlangs) | ||
| 859 | 	{ | ||
| 860 | global $conf; | ||
| 861 | |||
| 862 | $default_font_size = pdf_getPDFFontSize($outputlangs); | ||
| 863 | |||
| 864 | 		$pdf->SetFont('','', $default_font_size - 1); | ||
| 865 | |||
| 866 | // If France, show VAT mention if not applicable | ||
| 867 | if ($this->emetteur->country_code == 'FR' && $this->franchise == 1) | ||
| 868 | 		{ | ||
| 869 | 			$pdf->SetFont('','B', $default_font_size - 2); | ||
| 870 | $pdf->SetXY($this->marge_gauche, $posy); | ||
| 871 | 			$pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0); | ||
| 872 | |||
| 873 | $posy=$pdf->GetY()+4; | ||
| 874 | } | ||
| 875 | |||
| 876 | $posxval=52; | ||
| 877 | |||
| 878 | // Show payments conditions | ||
| 879 | if ($object->type != 2 && ($object->cond_reglement_code || $object->cond_reglement)) | ||
| 880 | 		{ | ||
| 881 | 			$pdf->SetFont('','B', $default_font_size - 2); | ||
| 882 | $pdf->SetXY($this->marge_gauche, $posy); | ||
| 883 | 			$titre = $outputlangs->transnoentities("PaymentConditions").':'; | ||
| 884 | $pdf->MultiCell(80, 4, $titre, 0, 'L'); | ||
| 885 | |||
| 886 | 			$pdf->SetFont('','', $default_font_size - 2); | ||
| 887 | $pdf->SetXY($posxval, $posy); | ||
| 888 | 			$lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc); | ||
| 889 | 			$lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement); | ||
| 890 | $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L'); | ||
| 891 | |||
| 892 | $posy=$pdf->GetY()+3; | ||
| 893 | } | ||
| 894 | |||
| 895 | if ($object->type != 2) | ||
| 896 | 		{ | ||
| 897 | // Check a payment mode is defined | ||
| 898 | if (empty($object->mode_reglement_code) | ||
| 899 | && empty($conf->global->FACTURE_CHQ_NUMBER) | ||
| 900 | && empty($conf->global->FACTURE_RIB_NUMBER)) | ||
| 901 | 			{ | ||
| 902 | 				$this->error = $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"); | ||
| 903 | } | ||
| 904 | // Avoid having any valid PDF with setup that is not complete | ||
| 905 | elseif (($object->mode_reglement_code == 'CHQ' && empty($conf->global->FACTURE_CHQ_NUMBER)) | ||
| 906 | || ($object->mode_reglement_code == 'VIR' && empty($conf->global->FACTURE_RIB_NUMBER))) | ||
| 907 | 			{ | ||
| 908 | 				$outputlangs->load("errors"); | ||
| 909 | |||
| 910 | $pdf->SetXY($this->marge_gauche, $posy); | ||
| 911 | $pdf->SetTextColor(200,0,0); | ||
| 912 | 				$pdf->SetFont('','B', $default_font_size - 2); | ||
| 913 | 				$this->error = $outputlangs->transnoentities("ErrorPaymentModeDefinedToWithoutSetup",$object->mode_reglement_code); | ||
| 914 | $pdf->MultiCell(80, 3, $this->error,0,'L',0); | ||
| 915 | $pdf->SetTextColor(0,0,0); | ||
| 916 | |||
| 917 | $posy=$pdf->GetY()+1; | ||
| 918 | } | ||
| 919 | |||
| 920 | // Show payment mode | ||
| 921 | if ($object->mode_reglement_code | ||
| 922 | && $object->mode_reglement_code != 'CHQ' | ||
| 923 | && $object->mode_reglement_code != 'VIR') | ||
| 924 | 			{ | ||
| 925 | 				$pdf->SetFont('','B', $default_font_size - 2); | ||
| 926 | $pdf->SetXY($this->marge_gauche, $posy); | ||
| 927 | 				$titre = $outputlangs->transnoentities("PaymentMode").':'; | ||
| 928 | $pdf->MultiCell(80, 5, $titre, 0, 'L'); | ||
| 929 | |||
| 930 | 				$pdf->SetFont('','', $default_font_size - 2); | ||
| 931 | $pdf->SetXY($posxval, $posy); | ||
| 932 | 				$lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement); | ||
| 933 | $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L'); | ||
| 934 | |||
| 935 | $posy=$pdf->GetY()+2; | ||
| 936 | } | ||
| 937 | |||
| 938 | // Show payment mode CHQ | ||
| 939 | if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') | ||
| 940 | 			{ | ||
| 941 | // Si mode reglement non force ou si force a CHQ | ||
| 942 | if (! empty($conf->global->FACTURE_CHQ_NUMBER)) | ||
| 943 | 				{ | ||
| 944 | $diffsizetitle=(empty($conf->global->PDF_DIFFSIZE_TITLE)?3:$conf->global->PDF_DIFFSIZE_TITLE); | ||
| 945 | |||
| 946 | if ($conf->global->FACTURE_CHQ_NUMBER > 0) | ||
| 947 | 					{ | ||
| 948 | $account = new Account($this->db); | ||
| 949 | $account->fetch($conf->global->FACTURE_CHQ_NUMBER); | ||
| 950 | |||
| 951 | $pdf->SetXY($this->marge_gauche, $posy); | ||
| 952 | 						$pdf->SetFont('','B', $default_font_size - $diffsizetitle); | ||
| 953 | 						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio),0,'L',0); | ||
| 954 | $posy=$pdf->GetY()+1; | ||
| 955 | |||
| 956 | if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) | ||
| 957 | 			            { | ||
| 958 | $pdf->SetXY($this->marge_gauche, $posy); | ||
| 959 | 							$pdf->SetFont('','', $default_font_size - $diffsizetitle); | ||
| 960 | $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0); | ||
| 961 | $posy=$pdf->GetY()+2; | ||
| 962 | } | ||
| 963 | } | ||
| 964 | if ($conf->global->FACTURE_CHQ_NUMBER == -1) | ||
| 965 | 					{ | ||
| 966 | $pdf->SetXY($this->marge_gauche, $posy); | ||
| 967 | 						$pdf->SetFont('','B', $default_font_size - $diffsizetitle); | ||
| 968 | 						$pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$this->emetteur->name),0,'L',0); | ||
| 969 | $posy=$pdf->GetY()+1; | ||
| 970 | |||
| 971 | if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) | ||
| 972 | 			            { | ||
| 973 | $pdf->SetXY($this->marge_gauche, $posy); | ||
| 974 | 							$pdf->SetFont('','', $default_font_size - $diffsizetitle); | ||
| 975 | $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0); | ||
| 976 | $posy=$pdf->GetY()+2; | ||
| 977 | } | ||
| 978 | } | ||
| 979 | } | ||
| 980 | } | ||
| 981 | |||
| 982 | // If payment mode not forced or forced to VIR, show payment with BAN | ||
| 983 | if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') | ||
| 984 | 			{ | ||
| 985 | if (! empty($object->fk_bank) || ! empty($conf->global->FACTURE_RIB_NUMBER)) | ||
| 986 | 				{ | ||
| 987 | $bankid=(empty($object->fk_bank)?$conf->global->FACTURE_RIB_NUMBER:$object->fk_bank); | ||
| 988 | $account = new Account($this->db); | ||
| 989 | $account->fetch($bankid); | ||
| 990 | |||
| 991 | $curx=$this->marge_gauche; | ||
| 992 | $cury=$posy; | ||
| 993 | |||
| 994 | $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size); | ||
| 995 | |||
| 996 | $posy+=2; | ||
| 997 | } | ||
| 998 | } | ||
| 999 | } | ||
| 1000 | |||
| 1001 | return $posy; | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | |||
| 1005 | /** | ||
| 1006 | * Show total to pay | ||
| 1007 | * | ||
| 1008 | * @param PDF $pdf Object PDF | ||
| 1009 | * @param Facture $object Object invoice | ||
| 1010 | * @param int $deja_regle Montant deja regle | ||
| 1011 | * @param int $posy Position depart | ||
| 1012 | * @param Translate $outputlangs Objet langs | ||
| 1013 | * @return int Position pour suite | ||
| 1014 | */ | ||
| 1015 | function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) | ||
| 1297 | } | ||
| 1298 | |||
| 1299 | /** | ||
| 1300 | * Show table for lines | ||
| 1301 | * | ||
| 1302 | * @param PDF $pdf Object PDF | ||
| 1303 | * @param string $tab_top Top position of table | ||
| 1304 | * @param string $tab_height Height of table (rectangle) | ||
| 1305 | * @param int $nexY Y (not used) | ||
| 1306 | * @param Translate $outputlangs Langs object | ||
| 1307 | * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title | ||
| 1308 | * @param int $hidebottom Hide bottom bar of array | ||
| 1309 | * @return void | ||
| 1310 | */ | ||
| 1311 | function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) | ||
| 1400 | } | ||
| 1401 | } | ||
| 1402 | |||
| 1403 | /** | ||
| 1404 | * Show top header of page. | ||
| 1405 | * | ||
| 1406 | * @param PDF $pdf Object PDF | ||
| 1407 | * @param Object $object Object to show | ||
| 1408 | * @param int $showaddress 0=no, 1=yes | ||
| 1409 | * @param Translate $outputlangs Object lang for output | ||
| 1410 | * @return void | ||
| 1411 | */ | ||
| 1412 | function _pagehead(&$pdf, $object, $showaddress, $outputlangs) | ||
| 1632 | } | ||
| 1633 | |||
| 1634 | /** | ||
| 1635 | * Show footer of page. Need this->emetteur object | ||
| 1636 | * | ||
| 1637 | * @param PDF $pdf PDF | ||
| 1638 | * @param Object $object Object to show | ||
| 1639 | * @param Translate $outputlangs Object lang for output | ||
| 1640 | * @param int $hidefreetext 1=Hide free text | ||
| 1641 | * @return int Return height of bottom margin including footer text | ||
| 1642 | */ | ||
| 1643 | function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) | ||
| 1652 | 
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.