Beispiel #1
0
     print '<td>' . $langs->trans("From") . ' ';
     print $form->select_date($dates, 'dates', 0, 0, 1);
     print '</td>';
     print '<td>' . $langs->trans("to") . ' ';
     print $form->select_date($datee, 'datee', 0, 0, 1);
     print '</td>';
     print '<td>';
     print '<input type="submit" name="refresh" value="' . $langs->trans("Refresh") . '" class="button">';
     print '</td>';
     print '</tr></table>';
     print '</form><br>';
     $showdatefilter++;
 }
 print '<br>';
 print_titre($langs->trans($title));
 $selectList = $formproject->select_element($tablename, $project->thirdparty->id);
 if (!$selectList || $selectList < 0) {
     setEventMessage($formproject->error, 'errors');
 } else {
     print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $projectid . '" method="post">';
     print '<input type="hidden" name="tablename" value="' . $tablename . '">';
     print '<input type="hidden" name="action" value="addelement">';
     print '<input type="hidden" name="datesrfc" value="' . dol_print_date($dates, 'dayhourrfc') . '">';
     print '<input type="hidden" name="dateerfc" value="' . dol_print_date($datee, 'dayhourrfc') . '">';
     print '<table><tr><td>' . $langs->trans("SelectElement") . '</td>';
     print '<td>' . $selectList . '</td>';
     print '<td><input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans("AddElement")) . '"></td>';
     print '</tr></table>';
     print '</form>';
 }
 print '<table class="noborder" width="100%">';
    $tablename = GETPOST("tablename");
    $elementselectid = GETPOST("elementselect");
    $result = $project->update_element($tablename, $elementselectid);
    if ($result < 0) {
        setEventMessage($project->error, 'errors');
    }
}
foreach ($listofreferent as $key => $value) {
    $title = $value['title'];
    $classname = $value['class'];
    $tablename = $value['table'];
    $qualified = $value['test'];
    if ($qualified) {
        print '<br>';
        print_titre($langs->trans($title));
        $selectList = $formproject->select_element($tablename, $project->societe->id);
        if (!$selectList || $selectList < 0) {
            setEventMessage($formproject->error, 'errors');
        } else {
            print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $projectid . '" method="post">';
            print '<input type="hidden" name="tablename" value="' . $tablename . '">';
            print '<input type="hidden" name="action" value="addelement">';
            print '<table><tr><td>' . $langs->trans("SelectElement") . '</td>';
            print '<td>' . $selectList . '</td>';
            print '<td><input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans("AddElement")) . '"></td>';
            print '</tr></table>';
            print '</form>';
        }
        print '<table class="noborder" width="100%">';
        print '<tr class="liste_titre">';
        print '<td width="100">' . $langs->trans("Ref") . '</td>';
 /**
  *	Fonction generant le projet sur le disque
  *
  *	@param	Project		$object   		Object project a generer
  *	@param	Translate	$outputlangs	Lang output object
  *	@return	int         				1 if OK, <=0 if KO
  */
 function write_file($object, $outputlangs)
 {
     global $user, $langs, $conf;
     $formproject = new FormProjets($this->db);
     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("projects");
     if ($conf->projet->dir_output) {
         //$nblignes = count($object->lines);  // This is set later with array of tasks
         $objectref = dol_sanitizeFileName($object->ref);
         $dir = $conf->projet->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 = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
                 return 0;
             }
         }
         if (file_exists($dir)) {
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action);
             // Note that $action and $object may have been modified by some hooks
             $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));
             // Complete object by loading several other informations
             $task = new Task($this->db);
             $tasksarray = $task->getTasksArray(0, 0, $object->id);
             $object->lines = $tasksarray;
             $nblignes = count($object->lines);
             $pdf->Open();
             $pagenb = 0;
             $pdf->SetDrawColor(128, 128, 128);
             $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
             $pdf->SetSubject($outputlangs->transnoentities("Project"));
             $pdf->SetCreator("Dolibarr " . DOL_VERSION);
             $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
             $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref) . " " . $outputlangs->transnoentities("Project"));
             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();
             $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 = 50;
             $tab_height = 200;
             $tab_top_newpage = 40;
             $tab_height_newpage = 210;
             // Affiche notes
             if (!empty($object->note_public)) {
                 $pdf->SetFont('', '', $default_font_size - 1);
                 $pdf->writeHTMLCell(190, 3, $this->posxref - 1, $tab_top - 2, dol_htmlentitiesbr($object->note_public), 0, 1);
                 $nexY = $pdf->GetY();
                 $height_note = $nexY - ($tab_top - 2);
                 // Rect prend une longueur en 3eme param
                 $pdf->SetDrawColor(192, 192, 192);
                 $pdf->Rect($this->marge_gauche, $tab_top - 3, $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;
             $listofreferent = array('propal' => array('name' => "Proposals", 'title' => "ListProposalsAssociatedProject", 'class' => 'Propal', 'table' => 'propal', 'datefieldname' => 'datep', 'test' => $conf->propal->enabled && $user->rights->propale->lire), 'order' => array('name' => "CustomersOrders", 'title' => "ListOrdersAssociatedProject", 'class' => 'Commande', 'table' => 'commande', 'datefieldname' => 'date_commande', 'test' => $conf->commande->enabled && $user->rights->commande->lire), 'invoice' => array('name' => "CustomersInvoices", 'title' => "ListInvoicesAssociatedProject", 'class' => 'Facture', 'margin' => 'add', 'table' => 'facture', 'datefieldname' => 'datef', 'test' => $conf->facture->enabled && $user->rights->facture->lire), 'invoice_predefined' => array('name' => "PredefinedInvoices", 'title' => "ListPredefinedInvoicesAssociatedProject", 'class' => 'FactureRec', 'table' => 'facture_rec', 'datefieldname' => 'datec', 'test' => $conf->facture->enabled && $user->rights->facture->lire), 'order_supplier' => array('name' => "SuppliersOrders", 'title' => "ListSupplierOrdersAssociatedProject", 'class' => 'CommandeFournisseur', 'table' => 'commande_fournisseur', 'datefieldname' => 'date_commande', 'test' => $conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire), 'invoice_supplier' => array('name' => "BillsSuppliers", 'title' => "ListSupplierInvoicesAssociatedProject", 'class' => 'FactureFournisseur', 'margin' => 'minus', 'table' => 'facture_fourn', 'datefieldname' => 'datef', 'test' => $conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), 'contract' => array('name' => "Contracts", 'title' => "ListContractAssociatedProject", 'class' => 'Contrat', 'table' => 'contrat', 'datefieldname' => 'date_contrat', 'test' => $conf->contrat->enabled && $user->rights->contrat->lire), 'intervention' => array('name' => "Interventions", 'title' => "ListFichinterAssociatedProject", 'class' => 'Fichinter', 'table' => 'fichinter', 'datefieldname' => 'date_valid', 'disableamount' => 1, 'test' => $conf->ficheinter->enabled && $user->rights->ficheinter->lire), 'trip' => array('name' => "TripsAndExpenses", 'title' => "ListTripAssociatedProject", 'class' => 'Deplacement', 'table' => 'deplacement', 'datefieldname' => 'dated', 'margin' => 'minus', 'disableamount' => 1, 'test' => $conf->deplacement->enabled && $user->rights->deplacement->lire), 'agenda' => array('name' => "Agenda", 'title' => "ListActionsAssociatedProject", 'class' => 'ActionComm', 'table' => 'actioncomm', 'datefieldname' => 'datep', 'disableamount' => 1, 'test' => $conf->agenda->enabled && $user->rights->agenda->allactions->lire));
             foreach ($listofreferent as $key => $value) {
                 $title = $value['title'];
                 $classname = $value['class'];
                 $tablename = $value['table'];
                 $datefieldname = $value['datefieldname'];
                 $qualified = $value['test'];
                 if ($qualified) {
                     $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee);
                     $num = count($elementarray);
                     if ($num > 0) {
                         $nexY = $pdf->GetY() + 5;
                         $curY = $nexY;
                         $pdf->SetXY($this->posxref, $curY);
                         $pdf->MultiCell($this->posxstatut - $this->posxref, 3, $outputlangs->transnoentities($title), 0, 'L');
                         $selectList = $formproject->select_element($tablename, $project->thirdparty->id);
                         $nexY = $pdf->GetY() + 1;
                         $curY = $nexY;
                         $pdf->SetXY($this->posxref, $curY);
                         $pdf->MultiCell($this->posxdate - $this->posxref, 3, $outputlangs->transnoentities("Ref"), 1, 'L');
                         $pdf->SetXY($this->posxdate, $curY);
                         $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, $outputlangs->transnoentities("Date"), 1, 'C');
                         $pdf->SetXY($this->posxsociety, $curY);
                         $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $outputlangs->transnoentities("ThirdParty"), 1, 'L');
                         if (empty($value['disableamount'])) {
                             $pdf->SetXY($this->posxamountht, $curY);
                             $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, $outputlangs->transnoentities("AmountHT"), 1, 'R');
                             $pdf->SetXY($this->posxamountttc, $curY);
                             $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, $outputlangs->transnoentities("AmountTTC"), 1, 'R');
                         } else {
                             $pdf->SetXY($this->posxamountht, $curY);
                             $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R');
                         }
                         $pdf->SetXY($this->posxstatut, $curY);
                         $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Statut"), 1, 'R');
                         if (is_array($elementarray) && count($elementarray) > 0) {
                             $nexY = $pdf->GetY();
                             $curY = $nexY;
                             $total_ht = 0;
                             $total_ttc = 0;
                             $num = count($elementarray);
                             for ($i = 0; $i < $num; $i++) {
                                 $element = new $classname($this->db);
                                 $element->fetch($elementarray[$i]);
                                 $element->fetch_thirdparty();
                                 // print $classname;
                                 $qualifiedfortotal = true;
                                 if ($key == 'invoice') {
                                     if ($element->close_code == 'replaced') {
                                         $qualifiedfortotal = false;
                                     }
                                     // Replacement invoice
                                 }
                                 $pdf->SetXY($this->posxref, $curY);
                                 $pdf->MultiCell($this->posxdate - $this->posxref, 3, $element->ref, 1, 'L');
                                 // Date
                                 if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') {
                                     $date = $element->date_commande;
                                 } else {
                                     $date = $element->date;
                                     if (empty($date)) {
                                         $date = $element->datep;
                                     }
                                     if (empty($date)) {
                                         $date = $element->date_contrat;
                                     }
                                     if (empty($date)) {
                                         $date = $element->datev;
                                     }
                                     // Fiche inter
                                 }
                                 $pdf->SetXY($this->posxdate, $curY);
                                 $pdf->MultiCell($this->posxsociety - $this->posxdate, 3, dol_print_date($date, 'day'), 1, 'C');
                                 $pdf->SetXY($this->posxsociety, $curY);
                                 if (is_object($element->thirdparty)) {
                                     $pdf->MultiCell($this->posxamountht - $this->posxsociety, 3, $element->thirdparty->name, 1, 'L');
                                 }
                                 // Amount without tax
                                 if (empty($value['disableamount'])) {
                                     $pdf->SetXY($this->posxamountht, $curY);
                                     $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, isset($element->total_ht) ? price($element->total_ht) : '&nbsp;', 1, 'R');
                                     $pdf->SetXY($this->posxamountttc, $curY);
                                     $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, isset($element->total_ttc) ? price($element->total_ttc) : '&nbsp;', 1, 'R');
                                 } else {
                                     $pdf->SetXY($this->posxamountht, $curY);
                                     $pdf->MultiCell($this->posxstatut - $this->posxamountht, 3, "", 1, 'R');
                                 }
                                 // Status
                                 if ($element instanceof CommonInvoice) {
                                     // This applies for Facture and FactureFournisseur
                                     $outputstatut = $element->getLibStatut(1, $element->getSommePaiement());
                                 } else {
                                     $outputstatut = $element->getLibStatut(1);
                                 }
                                 $pdf->SetXY($this->posxstatut, $curY);
                                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputstatut, 1, 'R', false, 1, '', '', true, 0, true);
                                 if ($qualifiedfortotal) {
                                     $total_ht = $total_ht + $element->total_ht;
                                     $total_ttc = $total_ttc + $element->total_ttc;
                                 }
                                 $nexY = $pdf->GetY();
                                 $curY = $nexY;
                             }
                             if (empty($value['disableamount'])) {
                                 $curY = $nexY;
                                 $pdf->SetXY($this->posxref, $curY);
                                 $pdf->MultiCell($this->posxamountttc - $this->posxref, 3, "TOTAL", 1, 'L');
                                 $pdf->SetXY($this->posxamountht, $curY);
                                 $pdf->MultiCell($this->posxamountttc - $this->posxamountht, 3, isset($element->total_ht) ? price($total_ht) : '&nbsp;', 1, 'R');
                                 $pdf->SetXY($this->posxamountttc, $curY);
                                 $pdf->MultiCell($this->posxstatut - $this->posxamountttc, 3, isset($element->total_ttc) ? price($total_ttc) : '&nbsp;', 1, 'R');
                                 $pdf->SetXY($this->posxstatut, $curY);
                                 $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxstatut, 3, $outputlangs->transnoentities("Nb") . " " . $num, 1, 'L');
                             }
                             $nexY = $pdf->GetY() + 5;
                             $curY = $nexY;
                         }
                     }
                 }
             }
             /*
              * Pied de page
              */
             $this->_pagefoot($pdf, $object, $outputlangs);
             if (method_exists($pdf, 'AliasNbPages')) {
                 $pdf->AliasNbPages();
             }
             $pdf->Close();
             $pdf->Output($file, 'F');
             // Add pdfgeneration hook
             if (!is_object($hookmanager)) {
                 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
                 $hookmanager = new HookManager($this->db);
             }
             $hookmanager->initHooks(array('pdfgeneration'));
             $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs);
             global $action;
             $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action);
             // Note that $action and $object may have been modified by some hooks
             if (!empty($conf->global->MAIN_UMASK)) {
                 @chmod($file, octdec($conf->global->MAIN_UMASK));
             }
             return 1;
             // Pas d'erreur
         } else {
             $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
             return 0;
         }
     }
     $this->error = $langs->transnoentities("ErrorConstantNotDefined", "LIVRAISON_OUTPUTDIR");
     return 0;
 }
Beispiel #4
0
	if ($qualified)
	{
		// If we want the project task array to have details of users
		//if ($key == 'project_task') $key = 'project_task_time';

		$element = new $classname($db);

		$addform='';

		$idtofilterthirdparty=0;
		if (! in_array($tablename, array('facture_fourn', 'commande_fourn'))) $idtofilterthirdparty=$object->thirdparty->id;

       	if (empty($conf->global->PROJECT_LINK_DISABLE)) 
       	{
			$selectList=$formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300');
			if (! $selectList || ($selectList<0))
			{
				setEventMessages($formproject->error,$formproject->errors,'errors');
			}
			elseif($selectList)
			{
				// Define form with the combo list of elements to link
				$addform.='<form action="'.$_SERVER["PHP_SELF"].'?id='.$projectid.'" method="post">';
				$addform.='<input type="hidden" name="tablename" value="'.$tablename.'">';
				$addform.='<input type="hidden" name="action" value="addelement">';
				$addform.='<input type="hidden" name="datesrfc" value="'.dol_print_date($dates,'dayhourrfc').'">';
				$addform.='<input type="hidden" name="dateerfc" value="'.dol_print_date($datee,'dayhourrfc').'">';
				$addform.='<table><tr><td>'.$langs->trans("SelectElement").'</td>';
				$addform.='<td>'.$selectList.'</td>';
				$addform.='<td><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("AddElement")).'"></td>';