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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387 | <?php
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* Copyright (C) 2011 Fabrice CHERRIER (12/05/2011) http://www.fcinc.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/fichinter/pdf_soleil.modules.php
* \ingroup ficheinter
* \brief Fichier de la classe permettant de generer les fiches d'intervention au modele Soleil
*/
require_once(DOL_DOCUMENT_ROOT."/core/modules/fichinter/modules_fichinter.php");
require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
require_once(DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php');
/**
* \class pdf_soleil
* \brief Class to build interventions documents with model Soleil
*/
class pdf_soleil extends ModelePDFFicheinter
{
/**
* \brief Constructeur
* \param db Handler acces base de donnee
*/
function pdf_soleil($db=0)
{
global $conf,$langs,$mysoc;
$this->db = $db;
$this->name = 'soleil';
$this->description = $langs->trans("DocumentModelStandard");
// 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=10;
$this->marge_droite=10;
$this->marge_haute=10;
$this->marge_basse=10;
$this->option_logo = 1; // Affiche logo
$this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION
$this->option_modereg = 0; // Affiche mode reglement
$this->option_condreg = 0; // Affiche conditions reglement
$this->option_codeproduitservice = 0; // Affiche code produit-service
$this->option_multilang = 0; // Dispo en plusieurs langues
$this->option_draft_watermark = 1; //Support add of a watermark on drafts
// Recupere emmetteur
$this->emetteur=$mysoc;
if (! $this->emetteur->code_pays) $this->emetteur->code_pays=substr($langs->defaultlang,-2); // By default, if not defined
// Defini position des colonnes
$this->posxdesc=$this->marge_gauche+1;
}
/**
* \brief Fonction generant la fiche d'intervention sur le disque
* \param fichinter Object fichinter
* \param outputlangs Lang output object
* \return int 1=ok, 0=ko
*/
function write_file($fichinter,$outputlangs)
{
global $user,$langs,$conf,$mysoc;
$default_font_size = pdf_getPDFFontSize($outputlangs);
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)
{
// If $fichinter is id instead of object
if (! is_object($fichinter))
{
$id = $fichinter;
$fichinter = new Fichinter($this->db);
$result=$fichinter->fetch($id);
if ($result < 0)
{
dol_print_error($this->db,$fichinter->error);
}
}
$fichinter->fetch_thirdparty();
$fichref = dol_sanitizeFileName($fichinter->ref);
$dir = $conf->ficheinter->dir_output;
if (! preg_match('/specimen/i',$fichref)) $dir.= "/" . $fichref;
$file = $dir . "/" . $fichref . ".pdf";
if (! file_exists($dir))
{
if (create_exdir($dir) < 0)
{
$this->error=$outputlangs->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->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
$pdf->SetAutoPageBreak(1,0);
// New page
$pdf->AddPage();
$pagenb++;
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('','', $default_font_size - 1);
$pdf->MultiCell(0, 3, ''); // Set interline to 3
// Pagehead
//Affiche le filigrane brouillon - Print Draft Watermark
if($fichinter->statut==0 && (! empty($conf->global->FICHINTER_DRAFT_WATERMARK)) )
{
pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->FICHINTER_DRAFT_WATERMARK);
}
$posy=$this->marge_haute;
$pdf->SetXY($this->marge_gauche,$posy);
// Logo
$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo;
if ($mysoc->logo)
{
if (is_readable($logo))
{
$pdf->Image($logo, $this->marge_gauche, $posy, 0, 24);
}
else
{
$pdf->SetTextColor(200,0,0);
$pdf->SetFont('','B', $default_font_size - 2);
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
}
}
// Nom emetteur
$posy=40;
$hautcadre=40;
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('','', $default_font_size - 2);
$pdf->SetXY($this->marge_gauche,$posy);
$pdf->SetFillColor(230,230,230);
$pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
$pdf->SetXY($this->marge_gauche+2,$posy+3);
// Sender name
$pdf->SetTextColor(0,0,60);
$pdf->SetFont('','B', $default_font_size);
$pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
// Sender properties
$carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
$pdf->SetFont('','', $default_font_size - 1);
$pdf->SetXY($this->marge_gauche+2,$posy+9);
$pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
$object=$fichinter;
// Recipient name
if (! empty($usecontact))
{
// On peut utiliser le nom de la societe du contact
if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
else $socname = $object->client->nom;
$carac_client_name=$outputlangs->convToOutputCharset($socname);
}
else
{
$carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
}
$carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
// Client destinataire
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('','B', $default_font_size);
$fichinter->fetch_thirdparty();
$pdf->SetXY(102,42);
$pdf->MultiCell(86,4, $carac_client_name, 0, 'L');
$pdf->SetFont('','', $default_font_size - 1);
$pdf->SetXY(102,$pdf->GetY());
$pdf->MultiCell(66,4, $carac_client, 0, 'L');
$pdf->rect(100, 40, 100, 40);
$pdf->SetTextColor(0,0,100);
$pdf->SetFont('','B', $default_font_size + 2);
$pdf->SetXY(10,86);
$pdf->MultiCell(120, 4, $outputlangs->transnoentities("InterventionCard")." : ".$outputlangs->convToOutputCharset($fichinter->ref), 0, 'L');
$pdf->SetFillColor(220,220,220);
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('','', $default_font_size);
$tab_top = 100;
$tab_top_newpage = 50;
$tab_height = 110;
$tab_height_newpage = 150;
// Affiche notes
if (! empty($fichinter->note_public))
{
$tab_top = 98;
$pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
$pdf->SetXY($this->posxdesc-1, $tab_top);
$pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($fichinter->note_public), 0, 'L');
$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;
}
$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->MultiCell(0, 3, ''); // Set interline to 3
$pdf->SetXY($this->marge_gauche, $tab_top + 8 );
$text=$fichinter->description;
if ($fichinter->duree > 0)
{
$totaltime=ConvertSecondToTime($fichinter->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);
$pdf->MultiCell(0, 3, ''); // Set interline to 3. Then writeMultiCell must use 3 also.
//dol_syslog("desc=".dol_htmlentitiesbr($fichinter->description));
$nblignes = count($fichinter->lines);
$curY = $pdf->GetY();
$nexY = $pdf->GetY();
// Loop on each lines
for ($i = 0 ; $i < $nblignes ; $i++)
{
$fichinterligne = $fichinter->lines[$i];
$valide = $fichinterligne->id ? $fichinterligne->fetch($fichinterligne->id) : 0;
if ($valide>0 || $fichinter->specimen)
{
$curY = $nexY+3;
$pdf->SetXY($this->marge_gauche, $curY);
$pdf->writeHTMLCell(0, 3, $this->marge_gauche, $curY,
dol_htmlentitiesbr($outputlangs->transnoentities("Date")." : ".dol_print_date($fichinterligne->datei,'dayhour',false,$outputlangs,true)." - ".$outputlangs->transnoentities("Duration")." : ".ConvertSecondToTime($fichinterligne->duration),1,$outputlangs->charset_output), 0, 1, 0);
$nexY = $pdf->GetY();
$pdf->SetXY($this->marge_gauche, $curY + 3);
$desc = dol_htmlentitiesbr($fichinterligne->desc,1);
$pdf->writeHTMLCell(0, 3, $this->marge_gauche, $curY + 3, $desc, 0, 1, 0);
$nexY+=dol_nboflines_bis($fichinterligne->desc,52,$outputlangs->charset_output)*3;
}
}
//$pdf->line(10, $tab_top+$tab_height+3, 200, $tab_top+$tab_height+3);
// Rectangle for title and all lines
$pdf->Rect($this->marge_gauche, $tab_top, ($this->page_largeur-$this->marge_gauche-$this->marge_droite), $tab_height+3);
$pdf->SetXY($this->marge_gauche, $pdf->GetY() + 20);
$pdf->MultiCell(60, 5, '', 0, 'J', 0);
$pdf->SetXY(20,220);
$pdf->MultiCell(66,5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"),0,'L',0);
$pdf->SetXY(20,225);
$pdf->MultiCell(80,30, '', 1);
$pdf->SetXY(110,220);
$pdf->MultiCell(80,5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"),0,'L',0);
$pdf->SetXY(110,225);
$pdf->MultiCell(80,30, '', 1);
$pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
$this->_pagefoot($pdf,$fichinter,$outputlangs);
$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
}
/**
* \brief Show footer of page
* \param pdf PDF factory
* \param object Object invoice
* \param outputlangs Object lang for output
* \remarks Need this->emetteur object
*/
function _pagefoot(&$pdf,$object,$outputlangs)
{
return pdf_pagefoot($pdf,$outputlangs,'FICHINTER_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
}
}
?>
|