27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
92 $langs->loadLangs(array(
"commercial",
"projects"));
96 $this->date_edition = time();
97 $this->month = $month;
103 $this->page_largeur = $formatarray[
'width'];
104 $this->page_hauteur = $formatarray[
'height'];
105 $this->format = array($this->page_largeur, $this->page_hauteur);
111 $this->title = $langs->transnoentitiesnoconv(
"ActionsReport").
' '.$this->year.
"-".$this->month;
112 $this->subject = $langs->transnoentitiesnoconv(
"ActionsReport").
' '.$this->year.
"-".$this->month;
124 public function write_file($socid = 0, $catid = 0, $outputlangs =
'')
127 global $user, $conf, $langs, $hookmanager;
129 if (!is_object($outputlangs)) {
130 $outputlangs = $langs;
133 if (!empty($conf->global->MAIN_USE_FPDF)) {
134 $outputlangs->charset_output =
'ISO-8859-1';
138 $outputlangs->loadLangs(array(
"main",
"dict",
"companies",
"bills",
"products"));
140 $dir = $conf->agenda->dir_temp.
"/";
141 $file = $dir.
"actions-".sprintf(
"%02d", $this->month).
"-".sprintf(
"%04d", $this->year).
".pdf";
143 if (!file_exists($dir)) {
145 $this->error = $langs->trans(
"ErrorCanNotCreateDir", $dir);
150 if (file_exists($dir)) {
152 if (!is_object($hookmanager)) {
153 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
156 $hookmanager->initHooks(array(
'pdfgeneration'));
159 $object =
new stdClass();
161 $parameters = array(
'file'=>$file,
'outputlangs'=>$outputlangs);
162 $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action);
165 $heightforinfotot = 50;
166 $heightforfreetext = (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT) ? $conf->global->MAIN_PDF_FREETEXT_HEIGHT : 5);
167 $heightforfooter = $this->marge_basse + 8;
168 $pdf->SetAutoPageBreak(1, 0);
170 if (class_exists(
'TCPDF')) {
171 $pdf->setPrintHeader(
false);
172 $pdf->setPrintFooter(
false);
178 $pdf->SetDrawColor(128, 128, 128);
179 $pdf->SetFillColor(220, 220, 220);
181 $pdf->SetTitle($outputlangs->convToOutputCharset($this->title));
182 $pdf->SetSubject($outputlangs->convToOutputCharset($this->subject));
183 $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
184 $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
185 $pdf->SetKeywords($outputlangs->convToOutputCharset($this->title.
" ".$this->subject));
187 $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);
189 $nbpage = $this->
_pages($pdf, $outputlangs);
191 if (method_exists($pdf,
'AliasNbPages')) {
192 $pdf->AliasNbPages();
196 $pdf->Output($file,
'F');
199 if (!is_object($hookmanager)) {
200 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
203 $hookmanager->initHooks(array(
'pdfgeneration'));
204 $parameters = array(
'file'=>$file,
'object'=>$object,
'outputlangs'=>$outputlangs);
206 $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action);
208 $this->error = $hookmanager->error;
209 $this->errors = $hookmanager->errors;
212 if (!empty($conf->global->MAIN_UMASK)) {
213 @chmod($file, octdec($conf->global->MAIN_UMASK));
216 $this->result = array(
'fullpath'=>$file);
229 private function _pages(&$pdf, $outputlangs)
236 $y = $this->
_pagehead($pdf, $outputlangs, $pagenb);
238 $pdf->SetFont(
'',
'', 8);
240 $sql =
"SELECT s.nom as thirdparty, s.rowid as socid, s.client,";
241 $sql .=
" a.id, a.datep as dp, a.datep2 as dp2,";
242 $sql .=
" a.fk_contact, a.note, a.percent as percent, a.fulldayevent, a.label, a.fk_project,";
243 $sql .=
" c.code, c.libelle,";
245 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as c, ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"actioncomm as a";
246 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON a.fk_soc = s.rowid";
247 $sql .=
" WHERE c.id=a.fk_action AND a.fk_user_author = u.rowid";
248 $sql .=
" AND a.datep BETWEEN '".$this->db->idate(
dol_get_first_day($this->year, $this->month,
false)).
"'";
249 $sql .=
" AND '".$this->db->idate(
dol_get_last_day($this->year, $this->month,
false)).
"'";
250 $sql .=
" AND a.entity = ".$conf->entity;
251 $sql .=
" ORDER BY a.datep DESC";
256 dol_syslog(get_class($this).
"::_page", LOG_DEBUG);
261 $y0 = $y1 = $y2 = $y3 = 0;
264 $obj = $this->
db->fetch_object(
$resql);
266 $eventstatic->id = $obj->id;
267 $eventstatic->percentage = $obj->percent;
268 $eventstatic->fulldayevent = $obj->fulldayevent;
270 $y = max($y, $pdf->GetY(), $y0, $y1, $y2, $y3);
274 if (!preg_match(
'/^'.preg_quote($obj->label,
'/').
'/', $obj->note)) {
275 $text = $obj->label.
"\n";
282 if ($obj->fk_project > 0) {
283 $projectstatic->fetch($obj->fk_project);
284 if ($projectstatic->ref) {
285 $text .= ($status ?
' - ' :
'').$outputlangs->transnoentitiesnoconv(
"Project").
": ".
dol_htmlentitiesbr_decode($projectstatic->ref);
292 $heightlinemax = max(2 * $height, $nboflines * $height);
294 if ((1 + $y + $heightlinemax) >= ($this->page_hauteur - $this->marge_haute)) {
297 $y = $this->
_pagehead($pdf, $outputlangs, $pagenb);
299 $pdf->SetFont(
'',
'', 8);
304 $pdf->SetXY($this->marge_gauche, $y);
308 $textdate .=
" -> ".dol_print_date($this->
db->jdate($obj->dp2),
"day").
" - ".
dol_print_date($this->
db->jdate($obj->dp2),
"hour");
310 $textdate .=
" -> ".dol_print_date($this->
db->jdate($obj->dp2),
"hour");
313 $textdate = $outputlangs->trans(
"ID").
' '.$obj->id.
' - '.$textdate;
314 $pdf->MultiCell(45 - $this->marge_gauche, $height, $textdate, 0,
'L', 0);
319 $pdf->MultiCell(28, $height,
dol_trunc($outputlangs->convToOutputCharset($obj->thirdparty), 28), 0,
'L', 0);
324 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
325 if ($code ==
'AC_OTH') {
328 if ($code ==
'AC_OTH_AUTO') {
333 $labelactiontype = $outputlangs->transnoentitiesnoconv(
"Action".$code);
334 $labelactiontypeshort = $outputlangs->transnoentitiesnoconv(
"Action".$code.
'Short');
335 $pdf->MultiCell(32, $height,
dol_trunc($outputlangs->convToOutputCharset($labelactiontypeshort ==
"Action".$code.
'Short' ? $labelactiontype : $labelactiontypeshort), 32), 0,
'L', 0);
339 $pdf->SetXY(106, $y);
340 $pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset(
dol_trunc(
dol_string_nohtmltag($text, 0), 250,
'right',
'UTF-8', 0)), 0,
'L', 0);
358 private function _pagehead(&$pdf, $outputlangs, $pagenb)
360 global $conf, $langs;
369 $pdf->SetFont(
'',
'B', 10);
370 $pdf->SetXY($this->marge_gauche, $this->marge_haute);
371 $pdf->MultiCell(120, 1, $outputlangs->convToOutputCharset($this->title), 0,
'L', 0);
374 $pdf->SetXY($this->page_largeur - $this->marge_droite - 40, $this->marge_haute);
375 $pdf->MultiCell(40, 1, $pagenb.
'/'.$pdf->getAliasNbPages(), 0,
'R', 0);
378 $y = $pdf->GetY() + 2;
380 $pdf->Rect($this->marge_gauche, $y, ($this->page_largeur - $this->marge_gauche - $this->marge_droite), ($this->page_hauteur - $this->marge_haute - $this->marge_basse));
381 $y = $pdf->GetY() + 1;