dolibarr /htdocs/core/modules/action/rapport.pdf.php

Language PHP Lines 266
MD5 Hash 583e9f2b4db84645f1674eb49be8560f
Repository https://github.com/asterix14/dolibarr.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/* Copyright (C) 2004      Rodolphe Quiedeville <rodolphe@quiedeville.org>
 * Copyright (C) 2004-2008 Laurent Destailleur  <eldy@users.sourceforge.net>
 * Copyright (C) 2005-2009 Regis Houssin        <regis@dolibarr.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * or see http://www.gnu.org/
 */

/**
 *	\file       htdocs/core/modules/action/rapport.pdf.php
 *	\ingroup    commercial
 *	\brief      File to build PDF with events
 */

require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");

/**
 *	\class      CommActionRapport
 *	\brief      Classe permettant la generation des rapports d'actions
 */
class CommActionRapport
{
	var $db;
	var $description;
	var $date_edition;
	var $year;
	var $month;

	var $title;
	var $subject;

	function CommActionRapport($db=0, $month, $year)
	{
		global $langs;
		$langs->load("commercial");

		$this->db = $db;
		$this->description = "";
		$this->date_edition = time();
		$this->month = $month;
		$this->year = $year;

		// Dimension page pour format A4
		$this->type = 'pdf';
		$formatarray=pdf_getFormat();
		$this->page_largeur = $formatarray['width'];
		$this->page_hauteur = $formatarray['height'];
		$this->format = array($this->page_largeur,$this->page_hauteur);
		$this->marge_gauche=5;
		$this->marge_droite=5;
		$this->marge_haute=10;
		$this->marge_basse=10;

        $this->title=$langs->transnoentitiesnoconv("ActionsReport").' '.$this->year."-".$this->month;
        $this->subject=$langs->transnoentitiesnoconv("ActionsReport").' '.$this->year."-".$this->month;
	}

	/**
     *      Write the object to document file to disk
     *      @param      socid
     *      @param      catid
     *      @param      outputlangs     Lang object for output language
     *      @return     int             1=OK, 0=KO
	 */
	function write_file($socid = 0, $catid = 0, $outputlangs='')
	{
		global $user,$conf,$langs;

		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("bills");
		$outputlangs->load("products");

        $dir = $conf->agenda->dir_temp."/";
		$file = $dir . "actions-".$this->month."-".$this->year.".pdf";

		if (! file_exists($dir))
		{
			if (create_exdir($dir) < 0)
			{
				$this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
				return 0;
			}
		}

		if (file_exists($dir))
		{
            $pdf=pdf_getInstance($this->format);

            if (class_exists('TCPDF'))
            {
                $pdf->setPrintHeader(false);
                $pdf->setPrintFooter(false);
            }
            $pdf->SetFont(pdf_getPDFFont($outputlangs));

			$pdf->Open();
			$pagenb=0;
			$pdf->SetDrawColor(128,128,128);
			$pdf->SetFillColor(220,220,220);

			$pdf->SetTitle($outputlangs->convToOutputCharset($this->title));
			$pdf->SetSubject($outputlangs->convToOutputCharset($this->subject));
			$pdf->SetCreator("Dolibarr ".DOL_VERSION);
			$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
			$pdf->SetKeywords($outputlangs->convToOutputCharset($this->title." ".$this->subject));

			$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite);   // Left, Top, Right
			$pdf->SetAutoPageBreak(1,0);

			$nbpage = $this->_pages($pdf, $outputlangs);

			$pdf->AliasNbPages();
			$pdf->Close();

			$pdf->Output($file,'F');
			if (! empty($conf->global->MAIN_UMASK))
			@chmod($file, octdec($conf->global->MAIN_UMASK));

			return 1;
		}
	}

	/**
	 * Write content of pages
	 *
	 * @param      $pdf
     * @param      $outputlangs
	 * @return     int				1
	 */
	function _pages(&$pdf, $outputlangs)
	{
		$height=3;		// height for text separation
		$pagenb=1;

		$y=$this->_pagehead($pdf, $outputlangs, $pagenb);
		$y++;
		$pdf->SetFont('','',8);

		$sql = "SELECT s.nom as societe, s.rowid as socid, s.client,";
		$sql.= " a.id, a.datep as dp, a.datep2 as dp2,";
		$sql.= " a.fk_contact, a.note, a.percent as percent,";
		$sql.= " c.libelle,";
		$sql.= " u.login";
		$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."actioncomm as a";
        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
		$sql.= " WHERE c.id=a.fk_action AND a.fk_user_author = u.rowid";
		$sql.= " AND a.datep BETWEEN '".$this->db->idate(dol_get_first_day($this->year,$this->month,false))."'";
		$sql.= " AND '".$this->db->idate(dol_get_last_day($this->year,$this->month,false))."'";
		$sql.= " ORDER BY a.datep DESC";

		dol_syslog("Rapport.pdf::_page sql=".$sql);
		$resql=$this->db->query($sql);
		if ($resql)
		{
			$num = $this->db->num_rows($resql);
			$i = 0;
			$y0=$y1=$y2=$y3=0;

			while ($i < $num)
			{
				$obj = $this->db->fetch_object($resql);

				$y = max($y, $pdf->GetY(), $y0, $y1, $y2, $y3);

				// Calculate height of text
				$text=dol_trunc(dol_htmlentitiesbr_decode($obj->note),150);
				//print 'd'.$text; exit;
				$nboflines=dol_nboflines($text);
				$heightlinemax=max(2*$height,$nboflines*$height);
				// Check if there is enough space to print record
				if ((1+$y+$heightlinemax) >= ($this->page_hauteur - $this->marge_haute))
				{
					// We need to break page
					$pagenb++;
					$y=$this->_pagehead($pdf, $outputlangs, $pagenb);
					$y++;
					$pdf->SetFont('','',8);
				}
				$y++;

				$pdf->SetXY($this->marge_gauche, $y);
				$pdf->MultiCell(22, $height, dol_print_date($this->db->jdate($obj->dp),"day")."\n".dol_print_date($this->db->jdate($obj->dp),"hour"), 0, 'L', 0);
				$y0 = $pdf->GetY();

				$pdf->SetXY(26, $y);
				$pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->societe),32), 0, 'L', 0);
				$y1 = $pdf->GetY();

				$pdf->SetXY(60,$y);
				$pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->libelle),32), 0, 'L', 0);
				$y2 = $pdf->GetY();

				$pdf->SetXY(106,$y);
				$pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset($text), 0, 'L', 0);
				$y3 = $pdf->GetY();

				//$pdf->MultiCell(94,2,"y=$y y3=$y3",0,'L',0);

				$i++;
			}
		}

		return 1;
	}

	/**
	 *      Show page head
	 *
	 *      @param      pdf             Objet PDF
	 *      @param      outputlangs		Objet lang cible
	 * 		@param		pagenb			Page nb
	 */
	function _pagehead(&$pdf, $outputlangs, $pagenb)
	{
		global $conf,$langs;

		// Do not add the BACKGROUND as this is a report
		//pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);

		// New page
		$pdf->AddPage();

		// Show title
		$pdf->SetFont('','B',10);
		$pdf->SetXY($this->marge_gauche, $this->marge_haute);
		$pdf->MultiCell(120, 1, $outputlangs->convToOutputCharset($this->title), 0, 'L', 0);
        // Show page nb only on iso languages (so default Helvetica font)
        if (pdf_getPDFFont($outputlangs) == 'Helvetica')
        {
		    $pdf->SetXY($this->page_largeur-$this->marge_droite-40, $this->marge_haute);
            $pdf->MultiCell(40, 1, $pagenb.'/'.$pdf->getAliasNbPages(), 0, 'R', 0);
        }

		$y=$pdf->GetY()+2;

		$pdf->Rect($this->marge_gauche, $y,
		$this->page_largeur - $this->marge_gauche - $this->marge_droite,
		$this->page_hauteur - $this->marge_haute - $this->marge_basse);
		$y=$pdf->GetY()+1;

		return $y;
	}
}

?>
Back to Top