/** * Function to build pdf onto disk * * @param CommonObject $object Id of object to generate * @param object $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, $langs, $conf, $hookmanager, $mysoc; 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("contracts"); if ($conf->contrat->dir_output) { $object->fetch_thirdparty(); // Definition of $dir and $file if ($object->specimen) { $dir = $conf->contrat->dir_output; $file = $dir . "/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->contrat->dir_output . "/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; } if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $outputlangs->trans("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 $pdf = pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $heightforinfotot = 50; // 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); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("ContractCard")); $pdf->SetCreator("Dolibarr " . DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("ContractCard")); 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; // Affiche notes if (!empty($object->note_public)) { $tab_top = 88; $pdf->SetFont('', '', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, 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 + 2; $pdf->SetXY($this->marge_gauche, $tab_top); $pdf->MultiCell(0, 2, ''); // Set interline to 3. Then writeMultiCell must use 3 also. $nblines = count($object->lines); // Loop on each lines for ($i = 0; $i < $nblines; $i++) { $objectligne = $object->lines[$i]; $valide = $objectligne->id ? 1 : 0; if ($valide > 0 || $object->specimen) { $curX = $this->posxdesc - 1; $curY = $nexY; $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage $pdf->SetTextColor(0, 0, 0); $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(); // Description of product line if ($objectligne->date_ouverture_prevue) { $datei = dol_print_date($objectligne->date_ouverture_prevue, 'day', false, $outputlangs, true); } else { $datei = $langs->trans("Unknown"); } if ($objectligne->date_fin_validite) { $durationi = convertSecondToTime($objectligne->date_fin_validite - $objectligne->date_ouverture_prevue, 'allwithouthour'); $datee = dol_print_date($objectligne->date_fin_validite, 'day', false, $outputlangs, true); } else { $durationi = $langs->trans("Unknown"); $datee = $langs->trans("Unknown"); } if ($objectligne->date_ouverture) { $daters = dol_print_date($objectligne->date_ouverture, 'day', false, $outputlangs, true); } else { $daters = $langs->trans("Unknown"); } if ($objectligne->date_cloture) { $datere = dol_print_date($objectligne->date_cloture, 'day', false, $outputlangs, true); } else { $datere = $langs->trans("Unknown"); } $txtpredefinedservice = ''; $txtpredefinedservice = $objectligne->product_ref; if ($objectligne->product_label) { $txtpredefinedservice .= ' - '; $txtpredefinedservice .= $objectligne->product_label; } $txt = '<strong>' . dol_htmlentitiesbr($outputlangs->transnoentities("DateStartPlannedShort") . " : " . $datei . " - " . $outputlangs->transnoentities("DateEndPlanned") . " : " . $datee, 1, $outputlangs->charset_output) . '</strong>'; $txt .= '<br>'; $txt .= '<strong>' . dol_htmlentitiesbr($outputlangs->transnoentities("DateStartRealShort") . " : " . $daters, 1, $outputlangs->charset_output); if ($objectligne->date_cloture) { $txt .= dol_htmlentitiesbr(" - " . $outputlangs->transnoentities("DateEndRealShort") . " : " . $datere, 1, $outputlangs->charset_output) . '</strong>'; } $desc = dol_htmlentitiesbr($objectligne->desc, 1); $pdf->writeHTMLCell(0, 0, $curX, $curY, dol_concatdesc($txt, dol_concatdesc($txtpredefinedservice, $desc)), 0, 1, 0); $nexY = $pdf->GetY() + 2; $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 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 // 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 - $heightforfooter - $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 - $heightforfooter - $heightforfooter + 1; } $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; } else { $this->error = $langs->trans("ErrorCanNotCreateDir", $dir); return 0; } } else { $this->error = $langs->trans("ErrorConstantNotDefined", "CONTRACT_OUTPUTDIR"); return 0; } $this->error = $langs->trans("ErrorUnknown"); return 0; // Erreur par defaut }
/** * Function to build pdf onto disk * * @param CommonObject $object Id of object to generate * @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, $langs, $conf, $mysoc; 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("interventions"); if ($conf->ficheinter->dir_output) { $object->fetch_thirdparty(); $objectref = dol_sanitizeFileName($object->ref); $dir = $conf->ficheinter->dir_output; if (!preg_match('/specimen/i', $objectref)) { $dir .= "/" . $objectref; } $file = $dir . "/" . $objectref . ".pdf"; if (!file_exists($dir)) { if (dol_mkdir($dir) < 0) { $this->error = $outputlangs->trans("ErrorCanNotCreateDir", $dir); return 0; } } if (file_exists($dir)) { $pdf = pdf_getInstance($this->format); $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance $heightforinfotot = 50; // 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); $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); $pdf->SetSubject($outputlangs->transnoentities("InterventionCard")); $pdf->SetCreator("Dolibarr " . DOL_VERSION); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("InterventionCard")); 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->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; // Affiche notes if (!empty($object->note_public)) { $tab_top = 88; $pdf->SetFont('', '', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, 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; $pdf->SetXY($this->marge_gauche, $tab_top); $pdf->MultiCell(190, 8, $outputlangs->transnoentities("Description"), 0, 'L', 0); $pdf->line($this->marge_gauche, $tab_top + 8, $this->page_largeur - $this->marge_droite, $tab_top + 8); $pdf->SetFont('', '', $default_font_size - 1); $pdf->SetXY($this->marge_gauche, $tab_top + 8); $text = $object->description; if ($object->duree > 0) { $totaltime = convertSecondToTime($object->duree, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY); $text .= ($text ? ' - ' : '') . $langs->trans("Total") . ": " . $totaltime; } $desc = dol_htmlentitiesbr($text, 1); //print $outputlangs->convToOutputCharset($desc); exit; $pdf->writeHTMLCell(180, 3, 10, $tab_top + 8, $outputlangs->convToOutputCharset($desc), 0, 1); $nexY = $pdf->GetY(); $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY); $nblines = count($object->lines); // Loop on each lines for ($i = 0; $i < $nblines; $i++) { $objectligne = $object->lines[$i]; $valide = empty($objectligne->id) ? 0 : $objectligne->fetch($objectligne->id); if ($valide > 0 || $object->specimen) { $curX = $this->posxdesc - 1; $curY = $nexY; $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage $pdf->SetTextColor(0, 0, 0); $pdf->setTopMargin($tab_top_newpage); $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); // The only function to edit the bottom margin of current page to set it. $pageposbefore = $pdf->getPage(); // Description of product line $txt = '<strong>' . dol_htmlentitiesbr($outputlangs->transnoentities("Date") . " : " . dol_print_date($objectligne->datei, 'dayhour', false, $outputlangs, true) . " - " . $outputlangs->transnoentities("Duration") . " : " . convertSecondToTime($objectligne->duration), 1, $outputlangs->charset_output) . '</strong>'; $desc = dol_htmlentitiesbr($objectligne->desc, 1); $pdf->startTransaction(); $pdf->writeHTMLCell(0, 0, $curX, $curY + 1, dol_concatdesc($txt, $desc), 0, 1, 0); $pageposafter = $pdf->getPage(); if ($pageposafter > $pageposbefore) { $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->writeHTMLCell(0, 0, $curX, $curY, $txt . '<br>' . $desc, LR, 1, 0); $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)) { if ($i == $nblines - 1) { $pdf->AddPage('', '', true); $pdf->setPage($pageposafter + 1); } } } else { $pdf->commitTransaction(); } $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 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 // 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 - $heightforfreetext, 0, $outputlangs, 0, 1); } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 0, $outputlangs, 1); } $this->_pagefoot($pdf, $object, $outputlangs, 1); $pagenb++; $pdf->setPage($pagenb); $this->_pagehead($pdf, $object, 0, $outputlangs); $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 - $heightforfreetext, 0, $outputlangs, 0, 1); } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter - $heightforfreetext, 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 - $heightforfreetext - $heightforfooter - 50, 0, $outputlangs, 0, 0); $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1; } else { $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfreetext - $heightforfooter - 50, 0, $outputlangs, 1, 0); $bottomlasttab = $this->page_hauteur - $heightforfooter - $heightforfooter + 1; } $this->_pagefoot($pdf, $object, $outputlangs); if (method_exists($pdf, 'AliasNbPages')) { $pdf->AliasNbPages(); } $pdf->Close(); $pdf->Output($file, 'F'); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; } else { $this->error = $langs->trans("ErrorCanNotCreateDir", $dir); return 0; } } else { $this->error = $langs->trans("ErrorConstantNotDefined", "FICHEINTER_OUTPUTDIR"); return 0; } $this->error = $langs->trans("ErrorUnknown"); return 0; // Erreur par defaut }
/** * Create a meta file with document file into same directory. * This should allow "grep" search. * This feature is enabled only if option MAIN_DOC_CREATE_METAFILE is set. * * @param CommonObject $object Object * @return int 0 if we did nothing, >0 success, <0 error */ function dol_meta_create($object) { global $conf; if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) { return 0; } // By default, no metafile. // Define parent dir of elements $element = $object->element; if ($object->element == 'order_supplier') { $dir = $conf->fournisseur->dir_output . '/commande'; } elseif ($object->element == 'invoice_supplier') { $dir = $conf->fournisseur->dir_output . '/facture'; } elseif ($object->element == 'project') { $dir = $conf->projet->dir_output; } elseif ($object->element == 'shipping') { $dir = $conf->expedition->dir_output . '/sending'; } elseif ($object->element == 'delivery') { $dir = $conf->expedition->dir_output . '/receipt'; } elseif ($object->element == 'fichinter') { $dir = $conf->ficheinter->dir_output; } else { $dir = empty($conf->{$element}->dir_output) ? '' : $conf->{$element}->dir_output; } if ($dir) { $object->fetch_thirdparty(); $facref = dol_sanitizeFileName($object->ref); $dir = $dir . "/" . $facref; $file = $dir . "/" . $facref . ".meta"; if (!is_dir($dir)) { dol_mkdir($dir); } if (is_dir($dir)) { $nblignes = count($object->lines); $client = $object->client->name . " " . $object->client->address . " " . $object->client->zip . " " . $object->client->town; $meta = "REFERENCE=\"" . $object->ref . "\"\n\t\t\tDATE=\"" . dol_print_date($object->date, '') . "\"\n\t\t\tNB_ITEMS=\"" . $nblignes . "\"\n\t\t\tCLIENT=\"" . $client . "\"\n\t\t\tTOTAL_HT=\"" . $object->total_ht . "\"\n\t\t\tTOTAL_TTC=\"" . $object->total_ttc . "\"\n"; for ($i = 0; $i < $nblignes; $i++) { //Pour les articles $meta .= "ITEM_" . $i . "_QUANTITY=\"" . $object->lines[$i]->qty . "\"\n\t\t\t\tITEM_" . $i . "_TOTAL_HT=\"" . $object->lines[$i]->total_ht . "\"\n\t\t\t\tITEM_" . $i . "_TVA=\"" . $object->lines[$i]->tva_tx . "\"\n\t\t\t\tITEM_" . $i . "_DESCRIPTION=\"" . str_replace("\r\n", "", nl2br($object->lines[$i]->desc)) . "\"\n\t\t\t\t"; } } $fp = fopen($file, "w"); fputs($fp, $meta); fclose($fp); if (!empty($conf->global->MAIN_UMASK)) { @chmod($file, octdec($conf->global->MAIN_UMASK)); } return 1; } return 0; }
/** * Show block with links to link to other objects. * * @param CommonObject $object Object we want to show links to * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order') * @return int <0 if KO, >0 if OK */ function showLinkToObjectBlock($object, $restrictlinksto = array()) { global $conf, $langs, $hookmanager; global $bc; $linktoelem = ''; if (!is_object($object->thirdparty)) { $object->fetch_thirdparty(); } if ((!is_array($restrictlinksto) || in_array('order', $restrictlinksto)) && !empty($conf->commande->enabled)) { $linktoelem .= ($linktoelem ? ' ' : '') . '<a href="#linktoorder" id="linktoorder">' . $langs->trans('LinkedOrder') . '</a>'; print ' <script type="text/javascript" language="javascript"> jQuery(document).ready(function() { jQuery("#linktoorder").click(function() { jQuery("#orderlist").toggle(); jQuery("#linktoorder").toggle(); }); }); </script> '; print '<div id="orderlist"' . (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display:none"' : '') . '>'; $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_client, c.total_ht"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= ", " . MAIN_DB_PREFIX . "commande as c"; $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id . ''; $resqlorderlist = $this->db->query($sql); if ($resqlorderlist) { $num = $this->db->num_rows($resqlorderlist); $i = 0; print '<br><form action="" method="POST" name="LinkedOrder">'; print '<table class="noborder">'; print '<tr class="liste_titre">'; print '<td class="nowrap"></td>'; print '<td align="center">' . $langs->trans("Ref") . '</td>'; print '<td align="left">' . $langs->trans("RefCustomer") . '</td>'; print '<td align="left">' . $langs->trans("AmountHTShort") . '</td>'; print '<td align="left">' . $langs->trans("Company") . '</td>'; print '</tr>'; while ($i < $num) { $objp = $this->db->fetch_object($resqlorderlist); $var = !$var; print '<tr ' . $bc[$var] . '>'; print '<td aling="left">'; print '<input type="radio" name="linkedOrder" value=' . $objp->rowid . '>'; print '</td>'; print '<td align="center">' . $objp->ref . '</td>'; print '<td>' . $objp->ref_client . '</td>'; print '<td>' . price($objp->total_ht) . '</td>'; print '<td>' . $objp->name . '</td>'; print '</tr>'; $i++; } print '</table>'; print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('ToLink') . '"> <input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '"></div>'; print '</form>'; $this->db->free($resqlorderlist); } else { dol_print_error($this->db); } print '</div>'; } if ((!is_array($restrictlinksto) || in_array('supplier_order', $restrictlinksto)) && !empty($conf->fournisseur->enabled)) { $linktoelem .= ($linktoelem ? ' ' : '') . '<a href="#linktoorder" id="linktoorder">' . $langs->trans('LinkedOrder') . '</a>'; print ' <script type="text/javascript" language="javascript"> jQuery(document).ready(function() { jQuery("#linktoorder").click(function() { jQuery("#orderlist").toggle(); jQuery("#linktoorder").toggle(); }); }); </script> '; print '<div id="orderlist"' . (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display:none"' : '') . '>'; $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_supplier, c.total_ht"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as c"; $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id; $resqlorderlist = $this->db->query($sql); if ($resqlorderlist) { $num = $this->db->num_rows($resqlorderlist); $i = 0; print '<br><form action="" method="POST" name="LinkedOrder">'; print '<table class="noborder">'; print '<tr class="liste_titre">'; print '<td class="nowrap"></td>'; print '<td align="center">' . $langs->trans("Ref") . '</td>'; print '<td align="left">' . $langs->trans("RefSupplier") . '</td>'; print '<td align="left">' . $langs->trans("AmountHTShort") . '</td>'; print '<td align="left">' . $langs->trans("Company") . '</td>'; print '</tr>'; while ($i < $num) { $objp = $this->db->fetch_object($resqlorderlist); $var = !$var; print '<tr ' . $bc[$var] . '>'; print '<td aling="left">'; print '<input type="radio" name="linkedOrder" value=' . $objp->rowid . '>'; print '</td>'; print '<td align="center">' . $objp->ref . '</td>'; print '<td>' . $objp->ref_supplier . '</td>'; print '<td>' . price($objp->total_ht) . '</td>'; print '<td>' . $objp->name . '</td>'; print '</tr>'; $i++; } print '</table>'; print '<br><div class="center"><input type="submit" class="button" value="' . $langs->trans('ToLink') . '"> <input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '"></div>'; print '</form>'; $this->db->free($resqlorderlist); } else { dol_print_error($this->db); } print '</div>'; } return $linktoelem; }