| Conditions | 88 |
| Total Lines | 643 |
| Code Lines | 414 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 197 | public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
||
| 198 | { |
||
| 199 | // phpcs:enable |
||
| 200 | global $user, $langs, $conf, $mysoc, $db, $hookmanager; |
||
| 201 | |||
| 202 | if (!is_object($outputlangs)) { |
||
| 203 | $outputlangs = $langs; |
||
| 204 | } |
||
| 205 | // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
||
| 206 | if (!empty($conf->global->MAIN_USE_FPDF)) { |
||
| 207 | $outputlangs->charset_output = 'ISO-8859-1'; |
||
| 208 | } |
||
| 209 | |||
| 210 | // Load traductions files required by page |
||
| 211 | $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries")); |
||
| 212 | |||
| 213 | /** |
||
| 214 | * TODO: get from object |
||
| 215 | */ |
||
| 216 | |||
| 217 | $id = GETPOST('id', 'int'); |
||
| 218 | $ref = GETPOST('ref', 'alpha'); |
||
| 219 | $msid = GETPOST('msid', 'int'); |
||
| 220 | $product_id = GETPOST("product_id"); |
||
| 221 | $action = GETPOST('action', 'aZ09'); |
||
| 222 | $cancel = GETPOST('cancel', 'alpha'); |
||
| 223 | $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'movementlist'; |
||
| 224 | |||
| 225 | $idproduct = GETPOST('idproduct', 'int'); |
||
| 226 | $year = GETPOST("year"); |
||
| 227 | $month = GETPOST("month"); |
||
| 228 | $search_ref = GETPOST('search_ref', 'alpha'); |
||
| 229 | $search_movement = GETPOST("search_movement"); |
||
| 230 | $search_product_ref = trim(GETPOST("search_product_ref")); |
||
| 231 | $search_product = trim(GETPOST("search_product")); |
||
| 232 | $search_warehouse = trim(GETPOST("search_warehouse")); |
||
| 233 | $search_inventorycode = trim(GETPOST("search_inventorycode")); |
||
| 234 | $search_user = trim(GETPOST("search_user")); |
||
| 235 | $search_batch = trim(GETPOST("search_batch")); |
||
| 236 | $search_qty = trim(GETPOST("search_qty")); |
||
| 237 | $search_type_mouvement = GETPOST('search_type_mouvement', 'int'); |
||
| 238 | |||
| 239 | $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; |
||
| 240 | $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); |
||
| 241 | $sortfield = GETPOST("sortfield", 'alpha'); |
||
| 242 | $sortorder = GETPOST("sortorder", 'alpha'); |
||
| 243 | if (empty($page) || $page == -1) { |
||
| 244 | $page = 0; |
||
| 245 | } // If $page is not defined, or '' or -1 |
||
| 246 | $offset = $limit * $page; |
||
| 247 | if (!$sortfield) { |
||
| 248 | $sortfield = "m.datem"; |
||
| 249 | } |
||
| 250 | if (!$sortorder) { |
||
| 251 | $sortorder = "DESC"; |
||
| 252 | } |
||
| 253 | |||
| 254 | $pdluoid = GETPOST('pdluoid', 'int'); |
||
| 255 | |||
| 256 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
||
| 257 | $hookmanager->initHooks(array('movementlist')); |
||
| 258 | $extrafields = new ExtraFields($this->db); |
||
| 259 | |||
| 260 | // fetch optionals attributes and labels |
||
| 261 | $extrafields->fetch_name_optionals_label('movement'); |
||
| 262 | $search_array_options = $extrafields->getOptionalsFromPost('movement', '', 'search_'); |
||
| 263 | |||
| 264 | $productlot = new ProductLot($this->db); |
||
| 265 | $productstatic = new Product($this->db); |
||
| 266 | $warehousestatic = new Entrepot($this->db); |
||
| 267 | $movement = new MouvementStock($this->db); |
||
| 268 | $userstatic = new User($this->db); |
||
| 269 | $element = 'movement'; |
||
| 270 | |||
| 271 | $sql = "SELECT p.rowid, p.ref as product_ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.entity,"; |
||
| 272 | $sql .= " e.ref as warehouse_ref, e.rowid as entrepot_id, e.lieu,"; |
||
| 273 | $sql .= " m.rowid as mid, m.value as qty, m.datem, m.fk_user_author, m.label, m.inventorycode, m.fk_origin, m.origintype,"; |
||
| 274 | $sql .= " m.batch, m.price,"; |
||
| 275 | $sql .= " m.type_mouvement,"; |
||
| 276 | $sql .= " pl.rowid as lotid, pl.eatby, pl.sellby,"; |
||
| 277 | $sql .= " u.login, u.photo, u.lastname, u.firstname"; |
||
| 278 | // Add fields from extrafields |
||
| 279 | if (!empty($extrafields->attributes[$element]['label'])) { |
||
| 280 | foreach ($extrafields->attributes[$element]['label'] as $key => $val) { |
||
| 281 | $sql .= ($extrafields->attributes[$element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : ''); |
||
| 282 | } |
||
| 283 | } |
||
| 284 | // Add fields from hooks |
||
| 285 | $parameters = array(); |
||
| 286 | $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook |
||
| 287 | $sql .= $hookmanager->resPrint; |
||
| 288 | $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e,"; |
||
| 289 | $sql .= " ".MAIN_DB_PREFIX."product as p,"; |
||
| 290 | $sql .= " ".MAIN_DB_PREFIX."stock_mouvement as m"; |
||
| 291 | if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { |
||
| 292 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (m.rowid = ef.fk_object)"; |
||
| 293 | } |
||
| 294 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON m.fk_user_author = u.rowid"; |
||
| 295 | $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON m.batch = pl.batch AND m.fk_product = pl.fk_product"; |
||
| 296 | $sql .= " WHERE m.fk_product = p.rowid"; |
||
| 297 | if ($msid > 0) { |
||
| 298 | $sql .= " AND m.rowid = ".((int) $msid); |
||
| 299 | } |
||
| 300 | $sql .= " AND m.fk_entrepot = e.rowid"; |
||
| 301 | $sql .= " AND e.entity IN (".getEntity('stock').")"; |
||
| 302 | if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { |
||
| 303 | $sql .= " AND p.fk_product_type = 0"; |
||
| 304 | } |
||
| 305 | if ($id > 0) { |
||
| 306 | $sql .= " AND e.rowid = ".((int) $id); |
||
| 307 | } |
||
| 308 | if ($month > 0) { |
||
| 309 | if ($year > 0) { |
||
| 310 | $sql .= " AND m.datem BETWEEN '".$this->db->idate(dol_get_first_day($year, $month, false))."' AND '".$this->db->idate(dol_get_last_day($year, $month, false))."'"; |
||
| 311 | } else { |
||
| 312 | $sql .= " AND date_format(m.datem, '%m') = '".((int) $month)."'"; |
||
| 313 | } |
||
| 314 | } elseif ($year > 0) { |
||
| 315 | $sql .= " AND m.datem BETWEEN '".$this->db->idate(dol_get_first_day($year, 1, false))."' AND '".$this->db->idate(dol_get_last_day($year, 12, false))."'"; |
||
| 316 | } |
||
| 317 | if ($idproduct > 0) { |
||
| 318 | $sql .= " AND p.rowid = ".((int) $idproduct); |
||
| 319 | } |
||
| 320 | if (!empty($search_ref)) { |
||
| 321 | $sql .= natural_search('m.rowid', $search_ref, 1); |
||
| 322 | } |
||
| 323 | if (!empty($search_movement)) { |
||
| 324 | $sql .= natural_search('m.label', $search_movement); |
||
| 325 | } |
||
| 326 | if (!empty($search_inventorycode)) { |
||
| 327 | $sql .= natural_search('m.inventorycode', $search_inventorycode); |
||
| 328 | } |
||
| 329 | if (!empty($search_product_ref)) { |
||
| 330 | $sql .= natural_search('p.ref', $search_product_ref); |
||
| 331 | } |
||
| 332 | if (!empty($search_product)) { |
||
| 333 | $sql .= natural_search('p.label', $search_product); |
||
| 334 | } |
||
| 335 | if ($search_warehouse > 0) { |
||
| 336 | $sql .= " AND e.rowid = ".((int) $this->db->escape($search_warehouse)); |
||
| 337 | } |
||
| 338 | if (!empty($search_user)) { |
||
| 339 | $sql .= natural_search('u.login', $search_user); |
||
| 340 | } |
||
| 341 | if (!empty($search_batch)) { |
||
| 342 | $sql .= natural_search('m.batch', $search_batch); |
||
| 343 | } |
||
| 344 | if ($search_qty != '') { |
||
| 345 | $sql .= natural_search('m.value', $search_qty, 1); |
||
| 346 | } |
||
| 347 | if ($search_type_mouvement > 0) { |
||
| 348 | $sql .= " AND m.type_mouvement = '".$this->db->escape($search_type_mouvement)."'"; |
||
| 349 | } |
||
| 350 | // Add where from extra fields |
||
| 351 | include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; |
||
| 352 | // Add where from hooks |
||
| 353 | $parameters = array(); |
||
| 354 | $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook |
||
| 355 | $sql .= $hookmanager->resPrint; |
||
| 356 | $sql .= $this->db->order($sortfield, $sortorder); |
||
| 357 | |||
| 358 | $nbtotalofrecords = ''; |
||
| 359 | if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { |
||
| 360 | $result = $this->db->query($sql); |
||
| 361 | $nbtotalofrecords = $this->db->num_rows($result); |
||
| 362 | if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 |
||
| 363 | $page = 0; |
||
| 364 | $offset = 0; |
||
| 365 | } |
||
| 366 | } |
||
| 367 | |||
| 368 | if (empty($search_inventorycode)) { |
||
| 369 | $sql .= $this->db->plimit($limit + 1, $offset); |
||
| 370 | } |
||
| 371 | |||
| 372 | |||
| 373 | $resql = $this->db->query($sql); |
||
| 374 | $nbtotalofrecords = $this->db->num_rows($result); |
||
| 375 | |||
| 376 | /* |
||
| 377 | * END TODO |
||
| 378 | **/ |
||
| 379 | |||
| 380 | //$nblines = count($object->lines); |
||
| 381 | |||
| 382 | if ($conf->stock->dir_output) { |
||
| 383 | if ($resql) { |
||
| 384 | $product = new Product($this->db); |
||
| 385 | $object = new Entrepot($this->db); |
||
| 386 | |||
| 387 | if ($idproduct > 0) { |
||
| 388 | $product->fetch($idproduct); |
||
| 389 | } |
||
| 390 | if ($id > 0 || $ref) { |
||
| 391 | $result = $object->fetch($id, $ref); |
||
| 392 | if ($result < 0) { |
||
| 393 | dol_print_error($this->db); |
||
| 394 | } |
||
| 395 | } |
||
| 396 | |||
| 397 | $num = $this->db->num_rows($resql); |
||
| 398 | |||
| 399 | $arrayofselected = is_array($toselect) ? $toselect : array(); |
||
| 400 | |||
| 401 | $i = 0; |
||
| 402 | $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; |
||
| 403 | if ($msid) { |
||
| 404 | $texte = $langs->trans('StockMovementForId', $msid); |
||
| 405 | } else { |
||
| 406 | $texte = $langs->trans("ListOfStockMovements"); |
||
| 407 | if ($id) { |
||
| 408 | $texte .= ' ('.$langs->trans("ForThisWarehouse").')'; |
||
| 409 | } |
||
| 410 | } |
||
| 411 | } |
||
| 412 | |||
| 413 | // Definition of $dir and $file |
||
| 414 | if ($object->specimen) { |
||
| 415 | $dir = $conf->stock->dir_output."/movement"; |
||
| 416 | $file = $dir."/SPECIMEN.pdf"; |
||
| 417 | } else { |
||
| 418 | $objectref = dol_sanitizeFileName($object->ref); |
||
| 419 | if (!empty($search_inventorycode)) { |
||
| 420 | $objectref .= "_".$id."_".$search_inventorycode; |
||
| 421 | } |
||
| 422 | if ($search_type_mouvement) { |
||
| 423 | $objectref .= "_".$search_type_mouvement; |
||
| 424 | } |
||
| 425 | $dir = $conf->stock->dir_output."/movement/".$objectref; |
||
| 426 | $file = $dir."/".$objectref.".pdf"; |
||
| 427 | } |
||
| 428 | |||
| 429 | $stockFournisseur = new ProductFournisseur($this->db); |
||
| 430 | $supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id); |
||
| 431 | $object->supplierprices = $supplierprices; |
||
| 432 | |||
| 433 | $productstatic = new Product($this->db); |
||
| 434 | |||
| 435 | if (!file_exists($dir)) { |
||
| 436 | if (dol_mkdir($dir) < 0) { |
||
| 437 | $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
||
| 438 | return -1; |
||
| 439 | } |
||
| 440 | } |
||
| 441 | |||
| 442 | if (file_exists($dir)) { |
||
| 443 | // Add pdfgeneration hook |
||
| 444 | if (!is_object($hookmanager)) { |
||
| 445 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
||
| 446 | $hookmanager = new HookManager($this->db); |
||
| 447 | } |
||
| 448 | $hookmanager->initHooks(array('pdfgeneration')); |
||
| 449 | $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); |
||
| 450 | global $action; |
||
| 451 | $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 452 | |||
| 453 | // Create pdf instance |
||
| 454 | $pdf = pdf_getInstance($this->format); |
||
| 455 | $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
||
| 456 | $pdf->SetAutoPageBreak(1, 0); |
||
| 457 | |||
| 458 | $heightforinfotot = 40; // Height reserved to output the info and total part |
||
| 459 | $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 |
||
| 460 | $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
||
| 461 | |||
| 462 | if (class_exists('TCPDF')) { |
||
| 463 | $pdf->setPrintHeader(false); |
||
| 464 | $pdf->setPrintFooter(false); |
||
| 465 | } |
||
| 466 | $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
||
| 467 | // Set path to the background PDF File |
||
| 468 | if (empty($conf->global->MAIN_DISABLE_FPDI) && !empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { |
||
| 469 | $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); |
||
| 470 | $tplidx = $pdf->importPage(1); |
||
| 471 | } |
||
| 472 | |||
| 473 | $pdf->Open(); |
||
| 474 | $pagenb = 0; |
||
| 475 | $pdf->SetDrawColor(128, 128, 128); |
||
| 476 | |||
| 477 | $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
||
| 478 | $pdf->SetSubject($outputlangs->transnoentities("Stock")); |
||
| 479 | $pdf->SetCreator("Dolibarr ".DOL_VERSION); |
||
| 480 | $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
||
| 481 | $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Stock")." ".$outputlangs->convToOutputCharset($object->label)); |
||
| 482 | if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) { |
||
| 483 | $pdf->SetCompression(false); |
||
| 484 | } |
||
| 485 | |||
| 486 | $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
||
| 487 | |||
| 488 | |||
| 489 | // New page |
||
| 490 | $pdf->AddPage(); |
||
| 491 | if (!empty($tplidx)) { |
||
| 492 | $pdf->useTemplate($tplidx); |
||
| 493 | } |
||
| 494 | $pagenb++; |
||
| 495 | $this->_pagehead($pdf, $object, 1, $outputlangs); |
||
| 496 | $pdf->SetFont('', '', $default_font_size - 1); |
||
| 497 | $pdf->MultiCell(0, 3, ''); // Set interline to 3 |
||
| 498 | $pdf->SetTextColor(0, 0, 0); |
||
| 499 | |||
| 500 | $tab_top = 42; |
||
| 501 | $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 : 10); |
||
| 502 | $tab_height = 130; |
||
| 503 | $tab_height_newpage = 150; |
||
| 504 | |||
| 505 | /* ************************************************************************** */ |
||
| 506 | /* */ |
||
| 507 | /* Affichage de la liste des produits du MouvementStock */ |
||
| 508 | /* */ |
||
| 509 | /* ************************************************************************** */ |
||
| 510 | |||
| 511 | $nexY += 5; |
||
| 512 | $nexY = $pdf->GetY(); |
||
| 513 | $nexY += 10; |
||
| 514 | |||
| 515 | $totalunit = 0; |
||
| 516 | $totalvalue = $totalvaluesell = 0; |
||
| 517 | $arrayofuniqueproduct = array(); |
||
| 518 | |||
| 519 | //dol_syslog('List products', LOG_DEBUG); |
||
| 520 | $resql = $this->db->query($sql); |
||
| 521 | if ($resql) { |
||
| 522 | $num = $this->db->num_rows($resql); |
||
| 523 | $i = 0; |
||
| 524 | $nblines = $num; |
||
| 525 | for ($i = 0; $i < $nblines; $i++) { |
||
| 526 | $objp = $this->db->fetch_object($resql); |
||
| 527 | |||
| 528 | // Multilangs |
||
| 529 | if (!empty($conf->global->MAIN_MULTILANGS)) { // si l'option est active |
||
| 530 | $sql = "SELECT label"; |
||
| 531 | $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; |
||
| 532 | $sql .= " WHERE fk_product = ".((int) $objp->rowid); |
||
| 533 | $sql .= " AND lang = '".$this->db->escape($langs->getDefaultLang())."'"; |
||
| 534 | $sql .= " LIMIT 1"; |
||
| 535 | |||
| 536 | $result = $this->db->query($sql); |
||
| 537 | if ($result) { |
||
| 538 | $objtp = $this->db->fetch_object($result); |
||
| 539 | if ($objtp->label != '') { |
||
| 540 | $objp->produit = $objtp->label; |
||
| 541 | } |
||
| 542 | } |
||
| 543 | } |
||
| 544 | |||
| 545 | $curY = $nexY; |
||
| 546 | $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage |
||
| 547 | $pdf->SetTextColor(0, 0, 0); |
||
| 548 | |||
| 549 | $pdf->setTopMargin($tab_top_newpage); |
||
| 550 | $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); // The only function to edit the bottom margin of current page to set it. |
||
| 551 | $pageposbefore = $pdf->getPage(); |
||
| 552 | |||
| 553 | // Description of product line |
||
| 554 | $curX = $this->posxdesc - 1; |
||
| 555 | |||
| 556 | $showpricebeforepagebreak = 1; |
||
| 557 | |||
| 558 | $pdf->startTransaction(); |
||
| 559 | pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 3, $curX, $curY, $hideref, $hidedesc); |
||
| 560 | $pageposafter = $pdf->getPage(); |
||
| 561 | if ($pageposafter > $pageposbefore) { // There is a pagebreak |
||
| 562 | $pdf->rollbackTransaction(true); |
||
| 563 | $pageposafter = $pageposbefore; |
||
| 564 | //print $pageposafter.'-'.$pageposbefore;exit; |
||
| 565 | $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
||
| 566 | pdf_writelinedesc($pdf, $object, $i, $outputlangs, $this->posxtva - $curX, 4, $curX, $curY, $hideref, $hidedesc); |
||
| 567 | $pageposafter = $pdf->getPage(); |
||
| 568 | $posyafter = $pdf->GetY(); |
||
| 569 | if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { // There is no space left for total+free text |
||
| 570 | if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page |
||
| 571 | $pdf->AddPage('', '', true); |
||
| 572 | if (!empty($tplidx)) { |
||
| 573 | $pdf->useTemplate($tplidx); |
||
| 574 | } |
||
| 575 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { |
||
| 576 | $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 577 | } |
||
| 578 | $pdf->setPage($pageposafter + 1); |
||
| 579 | } |
||
| 580 | } else { |
||
| 581 | // We found a page break |
||
| 582 | |||
| 583 | // Allows data in the first page if description is long enough to break in multiples pages |
||
| 584 | if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) { |
||
| 585 | $showpricebeforepagebreak = 1; |
||
| 586 | } else { |
||
| 587 | $showpricebeforepagebreak = 0; |
||
| 588 | } |
||
| 589 | } |
||
| 590 | } else // No pagebreak |
||
| 591 | { |
||
| 592 | $pdf->commitTransaction(); |
||
| 593 | } |
||
| 594 | $posYAfterDescription = $pdf->GetY(); |
||
| 595 | |||
| 596 | $nexY = $pdf->GetY(); |
||
| 597 | $pageposafter = $pdf->getPage(); |
||
| 598 | |||
| 599 | $pdf->setPage($pageposbefore); |
||
| 600 | $pdf->setTopMargin($this->marge_haute); |
||
| 601 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
| 602 | |||
| 603 | // We suppose that a too long description is moved completely on next page |
||
| 604 | if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { |
||
| 605 | $pdf->setPage($pageposafter); |
||
| 606 | $curY = $tab_top_newpage; |
||
| 607 | } |
||
| 608 | |||
| 609 | $pdf->SetFont('', '', $default_font_size - 1); // On repositionne la police par defaut |
||
| 610 | |||
| 611 | // $objp = $this->db->fetch_object($resql); |
||
| 612 | |||
| 613 | $userstatic->id = $objp->fk_user_author; |
||
| 614 | $userstatic->login = $objp->login; |
||
| 615 | $userstatic->lastname = $objp->lastname; |
||
| 616 | $userstatic->firstname = $objp->firstname; |
||
| 617 | $userstatic->photo = $objp->photo; |
||
| 618 | |||
| 619 | $productstatic->id = $objp->rowid; |
||
| 620 | $productstatic->ref = $objp->product_ref; |
||
| 621 | $productstatic->label = $objp->produit; |
||
| 622 | $productstatic->type = $objp->type; |
||
| 623 | $productstatic->entity = $objp->entity; |
||
| 624 | $productstatic->status_batch = $objp->tobatch; |
||
| 625 | |||
| 626 | $productlot->id = $objp->lotid; |
||
| 627 | $productlot->batch = $objp->batch; |
||
| 628 | $productlot->eatby = $objp->eatby; |
||
| 629 | $productlot->sellby = $objp->sellby; |
||
| 630 | |||
| 631 | $warehousestatic->id = $objp->entrepot_id; |
||
| 632 | $warehousestatic->label = $objp->warehouse_ref; |
||
| 633 | $warehousestatic->lieu = $objp->lieu; |
||
| 634 | |||
| 635 | $arrayofuniqueproduct[$objp->rowid] = $objp->produit; |
||
| 636 | if (!empty($objp->fk_origin)) { |
||
| 637 | $origin = $movement->get_origin($objp->fk_origin, $objp->origintype); |
||
| 638 | } else { |
||
| 639 | $origin = ''; |
||
| 640 | } |
||
| 641 | |||
| 642 | // Id movement. |
||
| 643 | $pdf->SetXY($this->posxidref, $curY); |
||
| 644 | $pdf->MultiCell($this->posxdesc - $this->posxidref - 0.8, 3, $objp->mid, 0, 'L'); |
||
| 645 | |||
| 646 | // Date. |
||
| 647 | $pdf->SetXY($this->posxdatemouv, $curY); |
||
| 648 | $pdf->MultiCell($this->posxdesc - $this->posxdatemouv - 0.8, 6, dol_print_date($this->db->jdate($objp->datem), 'dayhour'), 0, 'L'); |
||
| 649 | |||
| 650 | // Ref. |
||
| 651 | $pdf->SetXY($this->posxdesc, $curY); |
||
| 652 | $pdf->MultiCell($this->posxlabel - $this->posxdesc - 0.8, 3, $productstatic->ref, 0, 'L'); |
||
| 653 | |||
| 654 | // Label |
||
| 655 | $pdf->SetXY($this->posxlabel + 0.8, $curY); |
||
| 656 | $pdf->MultiCell($this->posxqty - $this->posxlabel - 0.8, 6, $productstatic->label, 0, 'L'); |
||
| 657 | |||
| 658 | // Lot/serie |
||
| 659 | $pdf->SetXY($this->posxqty, $curY); |
||
| 660 | $pdf->MultiCell($this->posxup - $this->posxqty - 0.8, 3, $productlot->batch, 0, 'R'); |
||
| 661 | |||
| 662 | // Inv. code |
||
| 663 | $pdf->SetXY($this->posxup, $curY); |
||
| 664 | $pdf->MultiCell($this->posxunit - $this->posxup - 0.8, 3, $objp->inventorycode, 0, 'R'); |
||
| 665 | |||
| 666 | // Label mouvement |
||
| 667 | $pdf->SetXY($this->posxunit, $curY); |
||
| 668 | $pdf->MultiCell($this->posxdiscount - $this->posxunit - 0.8, 3, $objp->label, 0, 'R'); |
||
| 669 | $totalvalue += price2num($objp->ppmp * $objp->value, 'MT'); |
||
| 670 | |||
| 671 | // Origin |
||
| 672 | $pricemin = $objp->price; |
||
| 673 | $pdf->SetXY($this->posxdiscount, $curY); |
||
| 674 | $pdf->MultiCell($this->postotalht - $this->posxdiscount - 0.8, 3, $origin, 0, 'R', 0); |
||
| 675 | |||
| 676 | // Qty |
||
| 677 | $valtoshow = price2num($objp->qty, 'MS'); |
||
| 678 | $towrite = (empty($valtoshow) ? '0' : $valtoshow); |
||
| 679 | $totalunit += $objp->qty; |
||
| 680 | |||
| 681 | $pdf->SetXY($this->postotalht, $curY); |
||
| 682 | $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $objp->qty, 0, 'R', 0); |
||
| 683 | |||
| 684 | $totalvaluesell += price2num($pricemin * $objp->value, 'MT'); |
||
| 685 | |||
| 686 | $nexY += 3.5; // Add space between lines |
||
| 687 | // Add line |
||
| 688 | if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) { |
||
| 689 | $pdf->setPage($pageposafter); |
||
| 690 | $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80))); |
||
| 691 | //$pdf->SetDrawColor(190,190,200); |
||
| 692 | $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1); |
||
| 693 | $pdf->SetLineStyle(array('dash'=>0)); |
||
| 694 | } |
||
| 695 | |||
| 696 | $nexY += 2; // Add space between lines |
||
| 697 | |||
| 698 | // Detect if some page were added automatically and output _tableau for past pages |
||
| 699 | while ($pagenb < $pageposafter) { |
||
| 700 | $pdf->setPage($pagenb); |
||
| 701 | if ($pagenb == 1) { |
||
| 702 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code); |
||
| 703 | } else { |
||
| 704 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code); |
||
| 705 | } |
||
| 706 | $this->_pagefoot($pdf, $object, $outputlangs, 1); |
||
| 707 | $pagenb++; |
||
| 708 | $pdf->setPage($pagenb); |
||
| 709 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
| 710 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { |
||
| 711 | $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 712 | } |
||
| 713 | } |
||
| 714 | if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) { |
||
| 715 | if ($pagenb == 1) { |
||
| 716 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code); |
||
| 717 | } else { |
||
| 718 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code); |
||
| 719 | } |
||
| 720 | $this->_pagefoot($pdf, $object, $outputlangs, 1); |
||
| 721 | // New page |
||
| 722 | $pdf->AddPage(); |
||
| 723 | if (!empty($tplidx)) { |
||
| 724 | $pdf->useTemplate($tplidx); |
||
| 725 | } |
||
| 726 | $pagenb++; |
||
| 727 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) { |
||
| 728 | $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 729 | } |
||
| 730 | } |
||
| 731 | } |
||
| 732 | |||
| 733 | $this->db->free($resql); |
||
| 734 | |||
| 735 | /** |
||
| 736 | * footer table |
||
| 737 | */ |
||
| 738 | $nexY = $pdf->GetY(); |
||
| 739 | $nexY += 5; |
||
| 740 | $curY = $nexY; |
||
| 741 | |||
| 742 | $pdf->SetLineStyle(array('dash'=>'0', 'color'=>array(220, 26, 26))); |
||
| 743 | $pdf->line($this->marge_gauche, $curY - 1, $this->page_largeur - $this->marge_droite, $curY - 1); |
||
| 744 | $pdf->SetLineStyle(array('dash'=>0)); |
||
| 745 | |||
| 746 | $pdf->SetFont('', 'B', $default_font_size - 1); |
||
| 747 | $pdf->SetTextColor(0, 0, 120); |
||
| 748 | |||
| 749 | // Total |
||
| 750 | $pdf->SetXY($this->posxidref, $curY); |
||
| 751 | $pdf->MultiCell($this->posxdesc - $this->posxidref, 3, $langs->trans("Total"), 0, 'L'); |
||
| 752 | |||
| 753 | // Total Qty |
||
| 754 | $pdf->SetXY($this->postotalht, $curY); |
||
| 755 | $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->postotalht, 3, $totalunit, 0, 'R', 0); |
||
| 756 | } else { |
||
| 757 | dol_print_error($this->db); |
||
| 758 | } |
||
| 759 | |||
| 760 | if ($notetoshow) { |
||
| 761 | $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object); |
||
| 762 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
| 763 | $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs); |
||
| 764 | $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow); |
||
| 765 | |||
| 766 | $tab_top = 88; |
||
| 767 | |||
| 768 | $pdf->SetFont('', '', $default_font_size - 1); |
||
| 769 | $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); |
||
| 770 | $nexY = $pdf->GetY(); |
||
| 771 | $height_note = $nexY - $tab_top; |
||
| 772 | |||
| 773 | // Rect takes a length in 3rd parameter |
||
| 774 | $pdf->SetDrawColor(192, 192, 192); |
||
| 775 | $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_note + 1); |
||
| 776 | |||
| 777 | $tab_height = $tab_height - $height_note; |
||
| 778 | $tab_top = $nexY + 6; |
||
| 779 | } else { |
||
| 780 | $height_note = 0; |
||
| 781 | } |
||
| 782 | |||
| 783 | $iniY = $tab_top + 7; |
||
| 784 | $curY = $tab_top + 7; |
||
| 785 | $nexY = $tab_top + 7; |
||
| 786 | |||
| 787 | $tab_top = $tab_top_newpage + 21; |
||
| 788 | |||
| 789 | // Show square |
||
| 790 | if ($pagenb == 1) { |
||
| 791 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code); |
||
| 792 | $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
| 793 | } else { |
||
| 794 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code); |
||
| 795 | $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
| 796 | } |
||
| 797 | |||
| 798 | $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
| 799 | |||
| 800 | // Affiche zone infos |
||
| 801 | //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); |
||
| 802 | |||
| 803 | // Affiche zone totaux |
||
| 804 | //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); |
||
| 805 | |||
| 806 | // Pied de page |
||
| 807 | $this->_pagefoot($pdf, $object, $outputlangs); |
||
| 808 | if (method_exists($pdf, 'AliasNbPages')) { |
||
| 809 | $pdf->AliasNbPages(); |
||
| 810 | } |
||
| 811 | |||
| 812 | $pdf->Close(); |
||
| 813 | |||
| 814 | $pdf->Output($file, 'F'); |
||
| 815 | |||
| 816 | // Add pdfgeneration hook |
||
| 817 | $hookmanager->initHooks(array('pdfgeneration')); |
||
| 818 | $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); |
||
| 819 | global $action; |
||
| 820 | $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
||
| 821 | if ($reshook < 0) { |
||
| 822 | $this->error = $hookmanager->error; |
||
| 823 | $this->errors = $hookmanager->errors; |
||
| 824 | } |
||
| 825 | |||
| 826 | if (!empty($conf->global->MAIN_UMASK)) { |
||
| 827 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
||
| 828 | } |
||
| 829 | |||
| 830 | $this->result = array('fullpath'=>$file); |
||
| 831 | |||
| 832 | return 1; // No error |
||
| 833 | } else { |
||
| 834 | $this->error = $langs->trans("ErrorCanNotCreateDir", $dir); |
||
| 835 | return 0; |
||
| 836 | } |
||
| 837 | } else { |
||
| 838 | $this->error = $langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR"); |
||
| 839 | return 0; |
||
| 840 | } |
||
| 1200 |