1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class TSubtotal { |
5
|
|
|
|
6
|
|
|
static $module_number = 104777; |
7
|
|
|
|
8
|
|
|
static function addSubTotalLine(&$object, $label, $qty, $rang=-1) { |
|
|
|
|
9
|
|
|
|
10
|
|
|
$res = 0; |
11
|
|
|
|
12
|
|
|
if( (float)DOL_VERSION <= 3.4 ) { |
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var $object Facture |
15
|
|
|
*/ |
16
|
|
|
if($object->element=='facture') $res = $object->addline($object->id, $label, 0,$qty,0,0,0,0,0,'','',0,0,'','HT',0,9,-1, TSubtotal::$module_number); |
17
|
|
|
/** |
18
|
|
|
* @var $object Propal |
19
|
|
|
*/ |
20
|
|
|
else if($object->element=='propal') $res = $object->addline($object->id,$label, 0,$qty,0,0,0,0,0,'HT',0,0,9,-1, TSubtotal::$module_number); |
21
|
|
|
/** |
22
|
|
|
* @var $object Commande |
23
|
|
|
*/ |
24
|
|
|
else if($object->element=='commande') $res = $object->addline($object->id,$label, 0,$qty,0,0,0,0,0,0,0,'HT',0,'','',9,-1, TSubtotal::$module_number); |
25
|
|
|
|
26
|
|
|
} |
27
|
|
|
else { |
28
|
|
|
$desc = ''; |
29
|
|
|
if ((float) DOL_VERSION < 6 || $qty==50) { |
30
|
|
|
$desc = $label; |
31
|
|
|
$label = ''; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var $object Facture |
36
|
|
|
*/ |
37
|
|
|
if($object->element=='facture') $res = $object->addline($desc, 0,$qty,0,0,0,0,0,'','',0,0,'','HT',0,9,$rang, TSubtotal::$module_number, '', 0, 0, null, 0, $label); |
38
|
|
|
/** |
39
|
|
|
* @var $object Facture fournisseur |
40
|
|
|
*/ |
41
|
|
|
else if($object->element=='invoice_supplier') { |
42
|
|
|
$object->special_code = TSubtotal::$module_number; |
43
|
|
|
$rang = $object->line_max() + 1; |
44
|
|
|
$res = $object->addline($label,0,0,0,0,$qty,0,0,'','',0,0,'HT',9,$rang); |
45
|
|
|
} |
46
|
|
|
/** |
47
|
|
|
* @var $object Propal |
48
|
|
|
*/ |
49
|
|
|
else if($object->element=='propal') $res = $object->addline($desc, 0,$qty,0,0,0,0,0,'HT',0,0,9,$rang, TSubtotal::$module_number, 0, 0, 0, $label); |
50
|
|
|
/** |
51
|
|
|
* @var $object Propal Fournisseur |
52
|
|
|
*/ |
53
|
|
|
else if($object->element=='supplier_proposal') $res = $object->addline($desc, 0,$qty,0,0,0,0,0,'HT',0,0,9,$rang, TSubtotal::$module_number, 0, 0, 0, $label); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var $object Commande |
57
|
|
|
*/ |
58
|
|
|
else if($object->element=='commande') $res = $object->addline($desc, 0,$qty,0,0,0,0,0,0,0,'HT',0,'','',9,$rang, TSubtotal::$module_number, 0, null, 0, $label); |
59
|
|
|
/** |
60
|
|
|
* @var $object Commande fournisseur |
61
|
|
|
*/ |
62
|
|
|
else if($object->element=='order_supplier') { |
63
|
|
|
$object->special_code = TSubtotal::$module_number; |
64
|
|
|
$res = $object->addline($label, 0,$qty,0,0,0,0,0,'',0,'HT', 0, 9); |
65
|
|
|
} |
66
|
|
|
/** |
67
|
|
|
* @var $object Facturerec |
68
|
|
|
*/ |
69
|
|
|
else if($object->element=='facturerec') $res = $object->addline($desc, 0,$qty, 0, 0, 0, 0, 0, 'HT', 0, '', 0, 9, $rang, TSubtotal::$module_number,$label); |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
self::generateDoc($object); |
74
|
|
|
|
75
|
|
|
return $res; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public static function generateDoc(&$object) |
79
|
|
|
{ |
80
|
|
|
global $conf,$langs,$db; |
81
|
|
|
|
82
|
|
|
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) |
83
|
|
|
{ |
84
|
|
|
$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); |
|
|
|
|
85
|
|
|
$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); |
86
|
|
|
$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); |
87
|
|
|
|
88
|
|
|
// Define output language |
89
|
|
|
$outputlangs = $langs; |
90
|
|
|
$newlang = GETPOST('lang_id', 'alpha'); |
91
|
|
|
if (! empty($conf->global->MAIN_MULTILANGS) && empty($newlang)) |
92
|
|
|
$newlang = !empty($object->client) ? $object->client->default_lang : $object->thirdparty->default_lang; |
93
|
|
|
if (! empty($newlang)) { |
94
|
|
|
$outputlangs = new Translate("", $conf); |
|
|
|
|
95
|
|
|
$outputlangs->setDefaultLang($newlang); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$ret = $object->fetch($object->id); // Reload to get new records |
|
|
|
|
99
|
|
|
if ((float) DOL_VERSION <= 3.6) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
if ($object->element == 'propal') propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
|
|
|
102
|
|
|
elseif ($object->element == 'commande') commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
|
|
|
103
|
|
|
elseif ($object->element == 'facture') facture_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
|
|
|
104
|
|
|
} |
105
|
|
|
else |
106
|
|
|
{ |
107
|
|
|
if ($object->element!= 'facturerec') $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Permet de mettre à jour les rangs afin de décaler des lignes pour une insertion en milieu de document |
114
|
|
|
* |
115
|
|
|
* @param type $object |
116
|
|
|
* @param type $rang_start |
117
|
|
|
* @param type $move_to |
118
|
|
|
*/ |
119
|
|
|
public static function updateRang(&$object, $rang_start, $move_to=1) |
120
|
|
|
{ |
121
|
|
|
if (!class_exists('GenericObject')) require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; |
|
|
|
|
122
|
|
|
|
123
|
|
|
$row=new GenericObject($object->db); |
|
|
|
|
124
|
|
|
$row->table_element_line = $object->table_element_line; |
125
|
|
|
$row->fk_element = $object->fk_element; |
126
|
|
|
$row->id = $object->id; |
127
|
|
|
|
128
|
|
|
foreach ($object->lines as &$line) |
129
|
|
|
{ |
130
|
|
|
if ($line->rang < $rang_start) continue; |
131
|
|
|
|
132
|
|
|
$row->updateRangOfLine($line->id, $line->rang+$move_to); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Méthode qui se charge de faire les ajouts de sous-totaux manquant afin de fermer les titres ouvert lors de l'ajout d'un nouveau titre |
138
|
|
|
* |
139
|
|
|
* @global type $langs |
140
|
|
|
* @param type $object |
141
|
|
|
* @param type $level_new_title |
142
|
|
|
*/ |
143
|
|
|
public static function addSubtotalMissing(&$object, $level_new_title) |
144
|
|
|
{ |
145
|
|
|
global $langs; |
146
|
|
|
$TTitle = self::getAllTitleWithoutTotalFromDocument($object); |
147
|
|
|
// Reverse - Pour partir de la fin et remonter dans les titres pour me permettre de m'arrêter quand je trouve un titre avec un niveau inférieur à celui qui a était ajouté |
148
|
|
|
$TTitle_reverse = array_reverse($TTitle); |
149
|
|
|
|
150
|
|
|
foreach ($TTitle_reverse as $k => $title_line) |
151
|
|
|
{ |
152
|
|
|
$title_niveau = self::getNiveau($title_line); |
153
|
|
|
if ($title_niveau < $level_new_title) break; |
154
|
|
|
|
155
|
|
|
$rang_to_add = self::titleHasTotalLine($object, $title_line, true, true); |
156
|
|
|
|
157
|
|
|
if (is_numeric($rang_to_add)) |
158
|
|
|
{ |
159
|
|
|
if ($rang_to_add != -1) self::updateRang($object, $rang_to_add); |
160
|
|
|
|
161
|
|
|
self::addSubTotalLine($object, $langs->trans('SubTotal'), 100-$title_niveau, $rang_to_add); |
162
|
|
|
|
163
|
|
|
$object->lines[] = $object->line; // ajout de la ligne dans le tableau de ligne (Dolibarr ne le fait pas) |
164
|
|
|
if ($rang_to_add != -1) |
165
|
|
|
{ |
166
|
|
|
if (method_exists($object, 'fetch_lines')) $object->fetch_lines(); |
167
|
|
|
else $object->fetch($object->id); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public static function addTitle(&$object, $label, $level, $rang=-1) |
174
|
|
|
{ |
175
|
|
|
self::addSubTotalLine($object, $label, $level, $rang); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public static function addTotal(&$object, $label, $level, $rang=-1) |
179
|
|
|
{ |
180
|
|
|
self::addSubTotalLine($object, $label, (100-$level), $rang); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Récupère la liste des lignes de titre qui n'ont pas de sous-total |
185
|
|
|
* |
186
|
|
|
* @param Propal|Commande|Facture $object |
|
|
|
|
187
|
|
|
* @param boolean $get_block_total |
188
|
|
|
* |
189
|
|
|
* @return array |
190
|
|
|
*/ |
191
|
|
|
public static function getAllTitleWithoutTotalFromDocument(&$object, $get_block_total=false) |
192
|
|
|
{ |
193
|
|
|
$TTitle = self::getAllTitleFromDocument($object, $get_block_total); |
194
|
|
|
|
195
|
|
|
foreach ($TTitle as $k => $title_line) |
196
|
|
|
{ |
197
|
|
|
if (self::titleHasTotalLine($object, $title_line)) unset($TTitle[$k]); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
return $TTitle; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Est-ce que mon titre ($title_line) a un sous-total ? |
205
|
|
|
* |
206
|
|
|
* @param Propal|Commande|Facture $object |
207
|
|
|
* @param PropaleLigne|OrderLine|FactureLigne $title_line |
|
|
|
|
208
|
|
|
* @param boolean $strict_mode si true alors un titre doit avoir un sous-total de même niveau; si false un titre possède un sous-total à partir du moment où l'on trouve un titre de niveau égale ou inférieur |
209
|
|
|
* @param boolean $return_rang_on_false si true alors renvoi le rang où devrait ce trouver le sous-total |
210
|
|
|
* @return boolean |
211
|
|
|
*/ |
212
|
|
|
public static function titleHasTotalLine(&$object, &$title_line, $strict_mode=false, $return_rang_on_false=false) |
213
|
|
|
{ |
214
|
|
|
if (empty($object->lines) || !is_array($object->lines)) return false; |
215
|
|
|
|
216
|
|
|
$title_niveau = self::getNiveau($title_line); |
217
|
|
|
foreach ($object->lines as &$line) |
218
|
|
|
{ |
219
|
|
|
if ($line->rang <= $title_line->rang) continue; |
220
|
|
|
if (self::isTitle($line) && self::getNiveau($line) <= $title_niveau) return false; // Oups on croise un titre d'un niveau inférieur ou égale (exemple : je croise un titre niveau 2 alors que je suis sur un titre de niveau 3) pas lieu de continuer car un nouveau bloc commence |
221
|
|
|
if (!self::isSubtotal($line)) continue; |
222
|
|
|
|
223
|
|
|
$subtotal_niveau = self::getNiveau($line); |
224
|
|
|
|
225
|
|
|
// Comparaison du niveau de la ligne de sous-total avec celui du titre |
226
|
|
|
if ($subtotal_niveau == $title_niveau) return true; // niveau égale => Ok mon titre a un sous-total |
227
|
|
|
elseif ($subtotal_niveau < $title_niveau) // niveau inférieur trouvé (exemple : sous-total de niveau 1 contre mon titre de niveau 3) |
228
|
|
|
{ |
229
|
|
|
if ($strict_mode) return ($return_rang_on_false) ? $line->rang : false; // mode strict niveau pas égale donc faux |
230
|
|
|
else return true; // mode libre => OK je considère que mon titre à un sous-total |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
// Sniff, j'ai parcouru toutes les lignes et pas de sous-total pour ce titre |
235
|
|
|
return ($return_rang_on_false) ? -1 : false; |
|
|
|
|
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
public static function getAllTitleFromDocument(&$object, $get_block_total=false) |
239
|
|
|
{ |
240
|
|
|
$TRes = array(); |
241
|
|
|
if (!empty($object->lines)) |
242
|
|
|
{ |
243
|
|
|
foreach ($object->lines as $k => &$line) |
244
|
|
|
{ |
245
|
|
|
if (self::isTitle($line)) |
246
|
|
|
{ |
247
|
|
|
if ($get_block_total) |
248
|
|
|
{ |
249
|
|
|
$TTot = self::getTotalBlockFromTitle($object, $line); |
250
|
|
|
|
251
|
|
|
$line->total_pa_ht = $TTot['total_pa_ht']; |
252
|
|
|
$line->total_options = $TTot['total_options']; |
253
|
|
|
$line->total_ht = $TTot['total_ht']; |
254
|
|
|
$line->total_tva = $TTot['total_tva']; |
255
|
|
|
$line->total_ttc = $TTot['total_ttc']; |
256
|
|
|
$line->TTotal_tva = $TTot['TTotal_tva']; |
257
|
|
|
$line->multicurrency_total_ht = $TTot['multicurrency_total_ht']; |
258
|
|
|
$line->multicurrency_total_tva = $TTot['multicurrency_total_tva']; |
259
|
|
|
$line->multicurrency_total_ttc = $TTot['multicurrency_total_ttc']; |
260
|
|
|
$line->TTotal_tva_multicurrency = $TTot['TTotal_tva_multicurrency']; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
$TRes[] = $line; |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
return $TRes; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
public static function getTotalBlockFromTitle(&$object, &$line) |
272
|
|
|
{ |
273
|
|
|
dol_include_once('/core/lib/price.lib.php'); |
|
|
|
|
274
|
|
|
$TTot = array('total_pa_ht' => 0, 'total_options' => 0, 'total_ht' => 0, 'total_tva' => 0, 'total_ttc' => 0, 'TTotal_tva' => array(), 'multicurrency_total_ht' => 0, 'multicurrency_total_tva' => 0, 'multicurrency_total_ttc' => 0, 'TTotal_tva_multicurrency' => array()); |
275
|
|
|
|
276
|
|
|
foreach ($object->lines as &$l) |
277
|
|
|
{ |
278
|
|
|
if ($l->rang <= $line->rang) continue; |
279
|
|
|
elseif (self::isSubtotal($l) && self::getNiveau($l) == $line->qty) break; |
280
|
|
|
elseif (self::isModSubtotalLine($l)) continue; |
281
|
|
|
|
282
|
|
|
if (!empty($l->array_options['options_subtotal_nc'])) |
283
|
|
|
{ |
284
|
|
|
$tabprice = calcul_price_total($l->qty, $l->subprice, $l->remise_percent, $l->tva_tx, $l->localtax1_tx, $l->localtax2_tx, 0, 'HT', $l->info_bits, $l->product_type); |
|
|
|
|
285
|
|
|
$TTot['total_options'] += $tabprice[0]; // total ht |
286
|
|
|
} |
287
|
|
|
else |
288
|
|
|
{ |
289
|
|
|
$TTot['total_pa_ht'] += $l->pa_ht * $l->qty; |
290
|
|
|
$TTot['total_ht'] += $l->total_ht; |
291
|
|
|
$TTot['total_tva'] += $l->total_tva; |
292
|
|
|
$TTot['total_ttc'] += $l->total_ttc; |
293
|
|
|
$TTot['TTotal_tva'][$l->tva_tx] += $l->total_tva; |
294
|
|
|
$TTot['multicurrency_total_ht'] += $l->multicurrency_total_ht; |
295
|
|
|
$TTot['multicurrency_total_tva'] += $l->multicurrency_total_tva; |
296
|
|
|
$TTot['multicurrency_total_ttc'] += $l->multicurrency_total_ttc; |
297
|
|
|
$TTot['TTotal_tva_multicurrency'][$l->tva_tx] += $l->multicurrency_total_tva; |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
return $TTot; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public static function getOrderIdFromLineId(&$db, $fk_commandedet) |
305
|
|
|
{ |
306
|
|
|
if (empty($fk_commandedet)) return false; |
307
|
|
|
|
308
|
|
|
$sql = 'SELECT fk_commande FROM '.MAIN_DB_PREFIX.'commandedet WHERE rowid = '.$fk_commandedet; |
|
|
|
|
309
|
|
|
$resql = $db->query($sql); |
310
|
|
|
|
311
|
|
|
if ($resql && ($row = $db->fetch_object($resql))) return $row->fk_commande; |
312
|
|
|
else return false; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
public static function getLastLineOrderId(&$db, $fk_commande) |
316
|
|
|
{ |
317
|
|
|
if (empty($fk_commande)) return false; |
318
|
|
|
|
319
|
|
|
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commandedet WHERE fk_commande = '.$fk_commande.' ORDER BY rang DESC LIMIT 1'; |
|
|
|
|
320
|
|
|
$resql = $db->query($sql); |
321
|
|
|
|
322
|
|
|
if ($resql && ($row = $db->fetch_object($resql))) return $row->rowid; |
323
|
|
|
else return false; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
public static function getParentTitleOfLine(&$object, $i) |
327
|
|
|
{ |
328
|
|
|
if ($i <= 0) return false; |
329
|
|
|
|
330
|
|
|
$skip_title = 0; |
331
|
|
|
// Je parcours les lignes précédentes |
332
|
|
|
while ($i--) |
333
|
|
|
{ |
334
|
|
|
$line = &$object->lines[$i]; |
335
|
|
|
// S'il s'agit d'un titre |
336
|
|
|
if ($line->product_type == 9 && $line->qty <= 10 && $line->qty >= 1) |
337
|
|
|
{ |
338
|
|
|
if ($skip_title) |
339
|
|
|
{ |
340
|
|
|
$skip_title--; |
341
|
|
|
continue; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
//@INFO J'ai ma ligne titre qui contient ma ligne, par contre je check pas s'il y a un sous-total |
345
|
|
|
return $line; |
346
|
|
|
break; |
|
|
|
|
347
|
|
|
} |
348
|
|
|
elseif ($line->product_type == 9 && $line->qty >= 90 && $line->qty <= 99) |
349
|
|
|
{ |
350
|
|
|
// Il s'agit d'un sous-total, ça veut dire que le prochain titre théoriquement doit être ignorer (je travail avec un incrément au cas ou je croise plusieurs sous-totaux) |
351
|
|
|
$skip_title++; |
352
|
|
|
} |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
return false; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
public static function isTitle(&$line, $level=-1) |
359
|
|
|
{ |
360
|
|
|
$res = $line->special_code == self::$module_number && $line->product_type == 9 && $line->qty <= 9; |
361
|
|
|
if($res && $level > -1) { |
362
|
|
|
return $line->qty == $level; |
363
|
|
|
} else return $res; |
364
|
|
|
|
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
public static function isSubtotal(&$line) |
368
|
|
|
{ |
369
|
|
|
return $line->special_code == self::$module_number && $line->product_type == 9 && $line->qty >= 90; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
public static function isFreeText(&$line) |
373
|
|
|
{ |
374
|
|
|
return $line->special_code == self::$module_number && $line->product_type == 9 && $line->qty == 50; |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
public static function isModSubtotalLine(&$line) |
378
|
|
|
{ |
379
|
|
|
return self::isTitle($line) || self::isSubtotal($line) || self::isFreeText($line); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
public static function getFreeTextHtml(&$line, $readonly=0) |
383
|
|
|
{ |
384
|
|
|
global $conf; |
385
|
|
|
|
386
|
|
|
// Copie du fichier "objectline_edit.tpl.php" |
387
|
|
|
// editeur wysiwyg |
388
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
|
|
|
389
|
|
|
$nbrows=ROWS_2; |
|
|
|
|
390
|
|
|
if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; |
391
|
|
|
$enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0); |
392
|
|
|
$toolbarname='dolibarr_details'; |
393
|
|
|
if (! empty($conf->global->FCKEDITOR_ENABLE_DETAILS_FULL)) $toolbarname='dolibarr_notes'; |
394
|
|
|
$text = !empty($line->description)?$line->description:$line->label; |
395
|
|
|
$doleditor=new DolEditor('line-description',$text,'',164,$toolbarname,'',false,true,$enable,$nbrows,'98%', $readonly); |
|
|
|
|
396
|
|
|
return $doleditor->Create(1); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
public static function duplicateLines(&$object, $lineid, $withBlockLine=false) |
400
|
|
|
{ |
401
|
|
|
global $db,$user,$conf; |
402
|
|
|
|
403
|
|
|
$createRight = $user->rights->{$object->element}->creer; |
404
|
|
|
if($object->element == 'facturerec' ) |
405
|
|
|
{ |
406
|
|
|
$object->statut = 0; // hack for facture rec |
407
|
|
|
$createRight = $user->rights->facture->creer; |
408
|
|
|
} |
409
|
|
|
elseif($object->element == 'order_supplier' ) |
410
|
|
|
{ |
411
|
|
|
$createRight = $user->rights->fournisseur->commande->creer; |
412
|
|
|
} |
413
|
|
|
elseif($object->element == 'invoice_supplier' ) |
414
|
|
|
{ |
415
|
|
|
$createRight = $user->rights->fournisseur->facture->creer; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
if ($object->statut == 0 && $createRight && !empty($conf->global->SUBTOTAL_ALLOW_DUPLICATE_BLOCK)) |
419
|
|
|
{ |
420
|
|
|
dol_include_once('/subtotal/lib/subtotal.lib.php'); |
|
|
|
|
421
|
|
|
|
422
|
|
|
$TLine = self::getLinesFromTitleId($object, $lineid, $withBlockLine); |
423
|
|
|
|
424
|
|
|
if (!empty($TLine)) |
425
|
|
|
{ |
426
|
|
|
$object->db->begin(); |
427
|
|
|
$res = 1; |
428
|
|
|
|
429
|
|
|
$TLineAdded = array(); |
430
|
|
|
foreach ($TLine as $line) |
431
|
|
|
{ |
432
|
|
|
// TODO refactore avec un doAddLine sur le même schéma que le doUpdateLine |
433
|
|
|
switch ($object->element) { |
434
|
|
|
case 'propal': |
435
|
|
|
//$desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$date_start='', $date_end='',$array_options=0, $fk_unit=null, $origin='', $origin_id=0) |
436
|
|
|
$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, 'HT', 0, $line->info_bits, $line->product_type, -1, $line->special_code, 0, 0, $line->pa_ht, $line->label, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->origin, $line->origin_id); |
437
|
|
|
break; |
438
|
|
|
|
439
|
|
|
case 'supplier_proposal': |
440
|
|
|
$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, 'HT', 0, $line->info_bits, $line->product_type, -1, $line->special_code, 0, 0, $line->pa_ht, $line->label, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->origin, $line->origin_id); |
441
|
|
|
break; |
442
|
|
|
|
443
|
|
|
case 'commande': |
444
|
|
|
//$desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_options=0, $fk_unit=null, $origin='', $origin_id=0) |
445
|
|
|
$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->info_bits, $line->fk_remise_except, 'HT', 0, $line->date_start, $line->date_end, $line->product_type, -1, $line->special_code, 0, 0, $line->pa_ht, $line->label, $line->array_options, $line->fk_unit, $line->origin, $line->origin_id); |
446
|
|
|
break; |
447
|
|
|
|
448
|
|
|
case 'order_supplier': |
449
|
|
|
$object->line = $line; |
450
|
|
|
$object->line->fk_commande = $object->id; |
451
|
|
|
$object->line->rang = $object->line_max() +1; |
452
|
|
|
$res = $object->line->insert(1); |
453
|
|
|
break; |
454
|
|
|
|
455
|
|
|
case 'facture': |
456
|
|
|
//$desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null |
457
|
|
|
$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->date_start, $line->date_end, 0, $line->info_bits, $line->fk_remise_except, 'HT', 0, $line->product_type, -1, $line->special_code, $line->origin, $line->origin_id, $line->fk_parent_line, $line->fk_fournprice, $line->pa_ht, $line->label, $line->array_options, $line->situation_percent, $line->fk_prev_id, $line->fk_unit); |
458
|
|
|
break; |
459
|
|
|
/* Totally useless on invoice supplier |
460
|
|
|
case 'invoice_supplier': |
461
|
|
|
//var_dump($line); exit; |
462
|
|
|
$rang = $object->line_max() +1; |
463
|
|
|
$object->special_code = $line->special_code; |
464
|
|
|
if (TSubtotal::isModSubtotalLine($line)) { |
465
|
|
|
$object->line = $line; |
466
|
|
|
$object->line->desc = $line->description; |
467
|
|
|
$object->line->description = $line->description; |
468
|
|
|
$object->line->fk_facture_fourn = $object->id; |
469
|
|
|
$object->line->rang = $rang; |
470
|
|
|
//var_dump($object->line); exit; |
471
|
|
|
$res = $object->line->insert(1); |
472
|
|
|
break; |
473
|
|
|
//var_dump($line->desc, $line->label, $line->description); exit; |
474
|
|
|
} |
475
|
|
|
$res = $object->addline($line->desc, $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, $line->fk_product, $line->remise_percent, $line->date_start, $line->date_end, 0, $line->info_bits, 'HT', $line->product_type, $rang); |
476
|
|
|
break; |
477
|
|
|
*/ |
478
|
|
|
case 'facturerec': |
479
|
|
|
//$desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null |
480
|
|
|
$res = $object->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->date_start, $line->date_end, 0, $line->info_bits, $line->fk_remise_except, 'HT', 0, $line->product_type, -1, $line->special_code, $line->origin, $line->origin_id, $line->fk_parent_line, $line->fk_fournprice, $line->pa_ht, $line->label, $line->array_options, $line->situation_percent, $line->fk_prev_id, $line->fk_unit); |
481
|
|
|
break; |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
$TLineAdded[] = $object->line; |
485
|
|
|
// Error from addline |
486
|
|
|
if ($res <= 0) break; |
487
|
|
|
else |
488
|
|
|
{ |
489
|
|
|
$object->line_from = $line; |
490
|
|
|
// Call trigger |
491
|
|
|
$result=$object->call_trigger('LINE_DUPLICATE',$user); // $object->line |
492
|
|
|
if ($result < 0) |
493
|
|
|
{ |
494
|
|
|
$object->db->rollback(); |
495
|
|
|
return -2; |
496
|
|
|
} |
497
|
|
|
} |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
if ($res > 0) |
501
|
|
|
{ |
502
|
|
|
$object->db->commit(); |
503
|
|
|
foreach ($TLineAdded as &$line) |
504
|
|
|
{ |
505
|
|
|
// ça peut paraitre non optimisé de déclancher la fonction sur toutes les lignes mais ceci est nécessaire pour réappliquer l'état exact de chaque ligne |
506
|
|
|
_updateLineNC($object->element, $object->id, $line->id, $line->array_options['options_subtotal_nc']); |
507
|
|
|
} |
508
|
|
|
return count($TLineAdded); |
509
|
|
|
} |
510
|
|
|
else |
511
|
|
|
{ |
512
|
|
|
$object->db->rollback(); |
513
|
|
|
return -1; |
514
|
|
|
} |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
return 0; |
518
|
|
|
} |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
public static function getLinesFromTitle(&$object, $key_trad, $level=1, $under_title='', $withBlockLine=false, $key_is_id=false) |
522
|
|
|
{ |
523
|
|
|
global $langs; |
524
|
|
|
|
525
|
|
|
// Besoin de comparer sur les 2 formes d'écriture |
526
|
|
|
if (!$key_is_id) $TTitle_search = array($langs->trans($key_trad), $langs->transnoentitiesnoconv($key_trad)); |
527
|
|
|
|
528
|
|
|
$TTitle_under_search = array(); |
529
|
|
|
if (!empty($under_title)) $TTitle_under_search = array($langs->trans($under_title), $langs->transnoentitiesnoconv($under_title)); |
530
|
|
|
|
531
|
|
|
$TLine = array(); |
532
|
|
|
$add_line = false; |
533
|
|
|
$under_title_found=false; |
534
|
|
|
|
535
|
|
|
foreach ($object->lines as $key => &$line) |
536
|
|
|
{ |
537
|
|
|
if (!$under_title_found && !empty($TTitle_under_search)) |
538
|
|
|
{ |
539
|
|
|
if ($line->product_type == 9 && (in_array($line->desc, $TTitle_under_search) || in_array($line->label, $TTitle_under_search)) ) $under_title_found = true; |
540
|
|
|
} |
541
|
|
|
else |
542
|
|
|
{ |
543
|
|
|
if ( ($key_is_id && $line->id == $key_trad) || (!$key_is_id && $line->product_type == 9 && $line->qty == $level && (in_array($line->desc, $TTitle_search) || in_array($line->label, $TTitle_search) ))) |
|
|
|
|
544
|
|
|
{ |
545
|
|
|
if ($key_is_id) $level = $line->qty; |
546
|
|
|
|
547
|
|
|
$add_line = true; |
548
|
|
|
if ($withBlockLine) $TLine[] = $line; |
549
|
|
|
continue; |
550
|
|
|
} |
551
|
|
|
elseif ($add_line && $line->product_type == 9 && (100 - $line->qty == $level) ) // Si on tombe sur un sous-total, il faut que ce soit un du même niveau que le titre |
552
|
|
|
{ |
553
|
|
|
if ($withBlockLine) $TLine[] = $line; |
554
|
|
|
break; |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
if ($add_line) |
558
|
|
|
{ |
559
|
|
|
if (!$withBlockLine && (self::isTitle($line) || self::isSubtotal($line)) ) continue; |
560
|
|
|
else $TLine[] = $line; |
561
|
|
|
} |
562
|
|
|
} |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
return $TLine; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
public static function getLinesFromTitleId(&$object, $lineid, $withBlockLine=false) |
569
|
|
|
{ |
570
|
|
|
return self::getLinesFromTitle($object, $lineid, '', '', $withBlockLine, true); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
public static function doUpdateLine(&$object, $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $type, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0, $fk_unit = null) |
574
|
|
|
{ |
575
|
|
|
$res = 0; |
576
|
|
|
$object->db->begin(); |
577
|
|
|
|
578
|
|
|
switch ($object->element) |
579
|
|
|
{ |
580
|
|
|
case 'propal': |
581
|
|
|
$res = $object->updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $desc, $price_base_type, $info_bits, $special_code, $fk_parent_line, $skip_update_total, $fk_fournprice, $pa_ht, $label, $type, $date_start, $date_end, $array_options, $fk_unit); |
582
|
|
|
break; |
583
|
|
|
|
584
|
|
|
case 'supplier_proposal': |
585
|
|
|
$res = $object->updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $desc, $price_base_type, $info_bits, $special_code, $fk_parent_line, $skip_update_total, $fk_fournprice, $pa_ht, $label, $type, $array_options,'', $fk_unit); |
586
|
|
|
break; |
587
|
|
|
|
588
|
|
|
case 'commande': |
589
|
|
|
$res = $object->updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $date_start, $date_end, $type, $fk_parent_line, $skip_update_total, $fk_fournprice, $pa_ht, $label, $special_code, $array_options, $fk_unit); |
590
|
|
|
break; |
591
|
|
|
|
592
|
|
|
case 'order_supplier': |
593
|
|
|
$object->special_code = SELF::$module_number; |
594
|
|
|
if (empty($desc)) $desc = $label; |
595
|
|
|
$res = $object->updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $type, 0, $date_start, $date_end, $array_options, $fk_unit); |
596
|
|
|
break; |
597
|
|
|
|
598
|
|
|
case 'facture': |
599
|
|
|
$res = $object->updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $type, $fk_parent_line, $skip_update_total, $fk_fournprice, $pa_ht, $label, $special_code, $array_options, $situation_percent, $fk_unit); |
600
|
|
|
break; |
601
|
|
|
|
602
|
|
|
case 'invoice_supplier': |
603
|
|
|
$object->special_code = SELF::$module_number; |
604
|
|
|
if (empty($desc)) $desc = $label; |
605
|
|
|
$res = $object->updateline($rowid, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, 0, $price_base_type, $info_bits, $type, $remise_percent, 0, $date_start, $date_end, $array_options, $fk_unit); |
606
|
|
|
break; |
607
|
|
|
|
608
|
|
|
case 'facturerec': |
609
|
|
|
// Add extrafields and get rang |
610
|
|
|
$factureRecLine = new FactureLigneRec($object->db); |
|
|
|
|
611
|
|
|
$factureRecLine->fetch($rowid); |
612
|
|
|
$factureRecLine->array_options = $array_options; |
613
|
|
|
$factureRecLine->insertExtraFields(); |
614
|
|
|
$rang=$factureRecLine->rang; |
615
|
|
|
|
616
|
|
|
$fk_product=0; $fk_remise_except=''; $pu_ttc=0; |
617
|
|
|
$res = $object->updateline($rowid, $desc, $pu, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $price_base_type, $info_bits, $fk_remise_except, $pu_ttc, $type, $rang, $special_code, $label, $fk_unit); |
618
|
|
|
break; |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
if ($res <= 0) $object->db->rollback(); |
622
|
|
|
else $object->db->commit(); |
623
|
|
|
|
624
|
|
|
return $res; |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
public static function getAllTitleFromLine(&$origin_line, $reverse = false) |
628
|
|
|
{ |
629
|
|
|
global $db, $object; |
630
|
|
|
|
631
|
|
|
$TTitle = array(); |
632
|
|
|
if(! empty($object->id) && in_array($object->element, array('propal', 'commande', 'facture'))) {} |
633
|
|
|
else { |
634
|
|
|
if ($origin_line->element == 'propaldet') |
635
|
|
|
{ |
636
|
|
|
$object = new Propal($db); |
637
|
|
|
$object->fetch($origin_line->fk_propal); |
638
|
|
|
} |
639
|
|
|
else if ($origin_line->element == 'commandedet') |
640
|
|
|
{ |
641
|
|
|
$object = new Commande($db); |
642
|
|
|
$object->fetch($origin_line->fk_commande); |
643
|
|
|
} |
644
|
|
|
else if ($origin_line->element == 'facturedet') |
645
|
|
|
{ |
646
|
|
|
$object = new Facture($db); |
647
|
|
|
$object->fetch($origin_line->fk_facture); |
648
|
|
|
} |
649
|
|
|
else |
650
|
|
|
{ |
651
|
|
|
return $TTitle; |
652
|
|
|
} |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
// Récupération de la position de la ligne |
656
|
|
|
$i = 0; |
657
|
|
|
foreach ($object->lines as &$line) |
658
|
|
|
{ |
659
|
|
|
if ($origin_line->id == $line->id) break; |
660
|
|
|
else $i++; |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
$i--; // Skip la ligne d'origine |
664
|
|
|
|
665
|
|
|
// Si elle n'est pas en 1ère position, alors on cherche des titres au dessus |
666
|
|
|
if ($i >= 0) |
667
|
|
|
{ |
668
|
|
|
$next_title_lvl_to_skip = 0; |
669
|
|
|
for ($y = $i; $y >= 0; $y--) |
670
|
|
|
{ |
671
|
|
|
// Si je tombe sur un sous-total, je récupère son niveau pour savoir quel est le prochain niveau de titre que doit ignorer |
672
|
|
|
if (self::isSubtotal($object->lines[$y])) |
673
|
|
|
{ |
674
|
|
|
$next_title_lvl_to_skip = self::getNiveau($object->lines[$y]); |
675
|
|
|
} |
676
|
|
|
elseif (self::isTitle($object->lines[$y])) |
677
|
|
|
{ |
678
|
|
|
if ($object->lines[$y]->qty == $next_title_lvl_to_skip) |
679
|
|
|
{ |
680
|
|
|
$next_title_lvl_to_skip = 0; |
681
|
|
|
continue; |
682
|
|
|
} |
683
|
|
|
else |
684
|
|
|
{ |
685
|
|
|
if (empty($object->lines[$y]->array_options)) $object->lines[$y]->fetch_optionals(); |
686
|
|
|
$TTitle[$object->lines[$y]->id] = $object->lines[$y]; |
687
|
|
|
|
688
|
|
|
if ($object->lines[$y]->qty == 1) break; |
689
|
|
|
} |
690
|
|
|
} |
691
|
|
|
} |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
if ($reverse) $TTitle = array_reverse($TTitle, true); |
695
|
|
|
|
696
|
|
|
return $TTitle; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
public static function getNiveau(&$line) |
700
|
|
|
{ |
701
|
|
|
if (self::isTitle($line)) return $line->qty; |
702
|
|
|
elseif (self::isSubtotal($line)) return 100 - $line->qty; |
703
|
|
|
else return 0; |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
/** |
707
|
|
|
* Ajoute une page de récap à la génération du PDF |
708
|
|
|
* Le tableau total en bas du document se base sur les totaux des titres niveau 1 pour le moment |
709
|
|
|
*/ |
710
|
|
|
public static function addRecapPage(&$parameters, &$origin_pdf) |
711
|
|
|
{ |
712
|
|
|
global $user,$conf,$langs; |
713
|
|
|
|
714
|
|
|
$origin_file = $parameters['file']; |
715
|
|
|
$outputlangs = $parameters['outputlangs']; |
716
|
|
|
$object = $parameters['object']; |
717
|
|
|
|
718
|
|
|
$outputlangs->load('subtotal@subtotal'); |
719
|
|
|
|
720
|
|
|
$objmarge = new stdClass(); |
721
|
|
|
$objmarge->page_hauteur = 297; |
722
|
|
|
$objmarge->page_largeur = 210; |
723
|
|
|
$objmarge->marge_gauche = 10; |
724
|
|
|
$objmarge->marge_haute = 10; |
725
|
|
|
$objmarge->marge_droite = 10; |
726
|
|
|
|
727
|
|
|
$objectref = dol_sanitizeFileName($object->ref); |
|
|
|
|
728
|
|
|
if ($object->element == 'propal') $dir = $conf->propal->dir_output . '/' . $objectref; |
729
|
|
|
elseif ($object->element == 'commande') $dir = $conf->commande->dir_output . '/' . $objectref; |
730
|
|
|
elseif ($object->element == 'facture') $dir = $conf->facture->dir_output . '/' . $objectref; |
731
|
|
|
elseif ($object->element == 'facturerec') return; // no PDF for facturerec |
732
|
|
|
else |
733
|
|
|
{ |
734
|
|
|
setEventMessage($langs->trans('warning_subtotal_recap_object_element_unknown', $object->element), 'warnings'); |
|
|
|
|
735
|
|
|
return -1; |
736
|
|
|
} |
737
|
|
|
$file = $dir . '/' . $objectref . '_recap.pdf'; |
738
|
|
|
|
739
|
|
|
// $pdf=pdf_getInstance($origin_pdf->format); |
740
|
|
|
$pdf=pdf_getInstance(array(210, 297)); // Format A4 Portrait |
|
|
|
|
741
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
742
|
|
|
$pdf->SetAutoPageBreak(1,0); |
743
|
|
|
|
744
|
|
|
if (class_exists('TCPDF')) |
745
|
|
|
{ |
746
|
|
|
$pdf->setPrintHeader(false); |
747
|
|
|
$pdf->setPrintFooter(false); |
748
|
|
|
} |
749
|
|
|
$pdf->SetFont(pdf_getPDFFont($outputlangs)); |
750
|
|
|
// Set path to the background PDF File |
751
|
|
|
if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) |
752
|
|
|
{ |
753
|
|
|
$pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); |
|
|
|
|
754
|
|
|
$tplidx = $pdf->importPage(1); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
$pdf->Open(); |
758
|
|
|
$pagenb=0; |
|
|
|
|
759
|
|
|
$pdf->SetDrawColor(128,128,128); |
760
|
|
|
|
761
|
|
|
$pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
762
|
|
|
$pdf->SetSubject($outputlangs->transnoentities("subtotalRecap")); |
763
|
|
|
$pdf->SetCreator("Dolibarr ".DOL_VERSION); |
|
|
|
|
764
|
|
|
$pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
765
|
|
|
$pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("subtotalRecap")." ".$outputlangs->convToOutputCharset($object->thirdparty->name)); |
766
|
|
|
if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
767
|
|
|
|
768
|
|
|
$pdf->SetMargins($objmarge->marge_gauche, $objmarge->marge_haute, $objmarge->marge_droite); // Left, Top, Right |
769
|
|
|
|
770
|
|
|
$pagenb=0; |
771
|
|
|
$pdf->SetDrawColor(128,128,128); |
772
|
|
|
|
773
|
|
|
|
774
|
|
|
// New page |
775
|
|
|
$pdf->AddPage(); |
776
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
777
|
|
|
$pagenb++; |
778
|
|
|
|
779
|
|
|
|
780
|
|
|
self::pagehead($objmarge, $pdf, $object, 1, $outputlangs); |
781
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
782
|
|
|
$pdf->MultiCell(0, 3, ''); // Set interline to 3 |
783
|
|
|
$pdf->SetTextColor(0,0,0); |
784
|
|
|
|
785
|
|
|
$heightforinfotot = 25; // Height reserved to output the info and total part |
786
|
|
|
$heightforfooter = $objmarge->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
787
|
|
|
|
788
|
|
|
$posx_designation = 25; |
789
|
|
|
$posx_options = 150; |
790
|
|
|
$posx_montant = 170; |
791
|
|
|
|
792
|
|
|
$tab_top = 72; |
793
|
|
|
$tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?72:20); // TODO à vérifier |
794
|
|
|
|
795
|
|
|
$TTot = array('total_ht' => 0, 'total_ttc' => 0, 'TTotal_tva' => array()); |
796
|
|
|
|
797
|
|
|
$TLine = self::getAllTitleFromDocument($object, true); |
798
|
|
|
if (!empty($TLine)) |
799
|
|
|
{ |
800
|
|
|
$hidetop = 0; |
801
|
|
|
|
802
|
|
|
$iniY = $tab_top + 10; |
|
|
|
|
803
|
|
|
$curY = $tab_top + 10; |
|
|
|
|
804
|
|
|
$nexY = $tab_top + 10; |
805
|
|
|
|
806
|
|
|
$nblignes = count($TLine); |
807
|
|
|
foreach($TLine as $i => &$line) |
808
|
|
|
{ |
809
|
|
|
$curY = $nexY; |
810
|
|
|
|
811
|
|
|
if (self::getNiveau($line) == 1) |
812
|
|
|
{ |
813
|
|
|
$pdf->SetFont('','B', $default_font_size - 1); // Into loop to work with multipage |
814
|
|
|
$curY+=2; |
815
|
|
|
|
816
|
|
|
$TTot['total_ht'] += $line->total_ht; |
817
|
|
|
$TTot['total_tva'] += $line->total_tva; |
818
|
|
|
$TTot['total_ttc'] += $line->total_ttc; |
819
|
|
|
$TTot['multicurrency_total_ht'] += $line->multicurrency_total_ht; |
820
|
|
|
$TTot['multicurrency_total_tva'] += $line->multicurrency_total_tva; |
821
|
|
|
$TTot['multicurrency_total_ttc'] += $line->multicurrency_total_ttc; |
822
|
|
|
|
823
|
|
|
foreach ($line->TTotal_tva as $tx => $amount) |
824
|
|
|
{ |
825
|
|
|
$TTot['TTotal_tva'][$tx] += $amount; |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
foreach ($line->TTotal_tva_multicurrency as $tx => $amount) |
829
|
|
|
{ |
830
|
|
|
$TTot['TTotal_tva_multicurrency'][$tx] += $amount; |
831
|
|
|
} |
832
|
|
|
} |
833
|
|
|
else $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage |
834
|
|
|
|
835
|
|
|
$pdf->SetTextColor(0,0,0); |
836
|
|
|
|
837
|
|
|
$pdf->setTopMargin($tab_top_newpage + 10); |
838
|
|
|
$pdf->setPageOrientation('', 1, $heightforfooter+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. |
839
|
|
|
$pageposbefore=$pdf->getPage(); |
840
|
|
|
|
841
|
|
|
$showpricebeforepagebreak=1; |
842
|
|
|
|
843
|
|
|
$decalage = (self::getNiveau($line) - 1) * 2; |
844
|
|
|
|
845
|
|
|
// Print: Designation |
846
|
|
|
$label = $line->label; |
847
|
|
|
if( (float)DOL_VERSION < 6 ) { |
848
|
|
|
$label = !empty($line->label) ? $line->label : $line->desc; |
849
|
|
|
} |
850
|
|
|
|
851
|
|
|
|
852
|
|
|
$pdf->startTransaction(); |
853
|
|
|
$pdf->writeHTMLCell($posx_options-$posx_designation-$decalage, 3, $posx_designation+$decalage, $curY, $outputlangs->convToOutputCharset($label), 0, 1, false, true, 'J',true); |
854
|
|
|
$pageposafter=$pdf->getPage(); |
855
|
|
|
if ($pageposafter > $pageposbefore) // There is a pagebreak |
856
|
|
|
{ |
857
|
|
|
$pdf->rollbackTransaction(true); |
858
|
|
|
$pageposafter=$pageposbefore; |
|
|
|
|
859
|
|
|
//print $pageposafter.'-'.$pageposbefore;exit; |
860
|
|
|
$pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
861
|
|
|
$pdf->writeHTMLCell($posx_options-$posx_designation-$decalage, 3, $posx_designation+$decalage, $curY, $outputlangs->convToOutputCharset($label), 0, 1, false, true, 'J',true); |
862
|
|
|
|
863
|
|
|
$pageposafter=$pdf->getPage(); |
864
|
|
|
$posyafter=$pdf->GetY(); |
865
|
|
|
//var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; |
866
|
|
|
if ($posyafter > ($objmarge->page_hauteur - ($heightforfooter+$heightforinfotot))) // There is no space left for total+free text |
867
|
|
|
{ |
868
|
|
|
if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page |
869
|
|
|
{ |
870
|
|
|
$pdf->AddPage('','',true); |
871
|
|
|
if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
872
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) self::pagehead($objmarge, $pdf, $object, 0, $outputlangs); |
873
|
|
|
$pdf->setPage($pageposafter+1); |
874
|
|
|
} |
875
|
|
|
} |
876
|
|
|
else |
877
|
|
|
{ |
878
|
|
|
// We found a page break |
879
|
|
|
$showpricebeforepagebreak=0; |
880
|
|
|
} |
881
|
|
|
} |
882
|
|
|
else // No pagebreak |
883
|
|
|
{ |
884
|
|
|
$pdf->commitTransaction(); |
885
|
|
|
} |
886
|
|
|
$posYAfterDescription=$pdf->GetY(); |
|
|
|
|
887
|
|
|
|
888
|
|
|
$nexY = $pdf->GetY(); |
889
|
|
|
$pageposafter=$pdf->getPage(); |
890
|
|
|
|
891
|
|
|
$pdf->setPage($pageposbefore); |
892
|
|
|
$pdf->setTopMargin($objmarge->marge_haute); |
893
|
|
|
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
894
|
|
|
|
895
|
|
|
// We suppose that a too long description or photo were moved completely on next page |
896
|
|
|
if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { |
897
|
|
|
$pdf->setPage($pageposafter); $curY = $tab_top_newpage + 10; |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
self::printLevel($objmarge, $pdf, $line, $curY, $posx_designation); |
901
|
|
|
|
902
|
|
|
// Print: Options |
903
|
|
|
if (!empty($line->total_options)) |
904
|
|
|
{ |
905
|
|
|
$pdf->SetXY($posx_options, $curY); |
906
|
|
|
$pdf->MultiCell($posx_montant-$posx_options-0.8, 3, price($line->total_options, 0, $outputlangs), 0, 'R', 0); |
|
|
|
|
907
|
|
|
} |
908
|
|
|
|
909
|
|
|
// Print: Montant |
910
|
|
|
$pdf->SetXY($posx_montant, $curY); |
911
|
|
|
$pdf->MultiCell($objmarge->page_largeur-$objmarge->marge_droite-$posx_montant-0.8, 3, price($line->total_ht, 0, $outputlangs), 0, 'R', 0); |
912
|
|
|
|
913
|
|
|
$nexY+=2; // Passe espace entre les lignes |
914
|
|
|
|
915
|
|
|
// Detect if some page were added automatically and output _tableau for past pages |
916
|
|
|
while ($pagenb < $pageposafter) |
917
|
|
|
{ |
918
|
|
|
$pdf->setPage($pagenb); |
919
|
|
|
if ($pagenb == 1) |
920
|
|
|
{ |
921
|
|
|
self::tableau($objmarge, $pdf, $posx_designation, $posx_options, $posx_montant, $tab_top, $objmarge->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code); |
922
|
|
|
} |
923
|
|
|
else |
924
|
|
|
{ |
925
|
|
|
self::tableau($objmarge, $pdf, $posx_designation, $posx_options, $posx_montant, $tab_top_newpage, $objmarge->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code); |
926
|
|
|
} |
927
|
|
|
|
928
|
|
|
$pagenb++; |
929
|
|
|
$pdf->setPage($pagenb); |
930
|
|
|
$pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
931
|
|
|
if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) self::pagehead($objmarge, $pdf, $object, 0, $outputlangs); |
932
|
|
|
} |
933
|
|
|
} |
934
|
|
|
} |
935
|
|
|
|
936
|
|
|
// Show square |
937
|
|
|
if ($pagenb == 1) |
938
|
|
|
{ |
939
|
|
|
self::tableau($objmarge, $pdf, $posx_designation, $posx_options, $posx_montant, $tab_top, $objmarge->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code); |
940
|
|
|
$bottomlasttab=$objmarge->page_hauteur - $heightforinfotot - $heightforfooter + 1; |
941
|
|
|
} |
942
|
|
|
else |
943
|
|
|
{ |
944
|
|
|
self::tableau($objmarge, $pdf, $posx_designation, $posx_options, $posx_montant, $tab_top_newpage, $objmarge->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code); |
|
|
|
|
945
|
|
|
$bottomlasttab=$objmarge->page_hauteur - $heightforinfotot - $heightforfooter + 1; |
946
|
|
|
} |
947
|
|
|
|
948
|
|
|
// Affiche zone totaux |
949
|
|
|
$posy=self::tableau_tot($objmarge, $pdf, $object, $bottomlasttab, $outputlangs, $TTot); |
|
|
|
|
950
|
|
|
|
951
|
|
|
$pdf->Close(); |
952
|
|
|
$pdf->Output($file,'F'); |
953
|
|
|
|
954
|
|
|
$pagecount = self::concat($outputlangs, array($origin_file, $file), $origin_file); |
955
|
|
|
|
956
|
|
|
if (empty($conf->global->SUBTOTAL_KEEP_RECAP_FILE)) unlink($file); |
957
|
|
|
} |
958
|
|
|
|
959
|
|
|
private static function printLevel($objmarge, $pdf, $line, $curY, $posx_designation) |
960
|
|
|
{ |
961
|
|
|
$level = $line->qty; // TODO à améliorer |
962
|
|
|
|
963
|
|
|
$pdf->SetXY($objmarge->marge_gauche, $curY); |
964
|
|
|
$pdf->MultiCell($posx_designation-$objmarge->marge_gauche-0.8, 5, $level, 0, 'L', 0); |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
/** |
968
|
|
|
* Show top header of page. |
969
|
|
|
* |
970
|
|
|
* @param PDF $pdf Object PDF |
971
|
|
|
* @param Object $object Object to show |
972
|
|
|
* @param int $showdetail 0=no, 1=yes |
973
|
|
|
* @param Translate $outputlangs Object lang for output |
974
|
|
|
* @return void |
975
|
|
|
*/ |
976
|
|
|
private static function pagehead(&$objmarge, &$pdf, &$object, $showdetail, $outputlangs) |
977
|
|
|
{ |
978
|
|
|
global $conf,$mysoc; |
979
|
|
|
|
980
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
981
|
|
|
|
982
|
|
|
pdf_pagehead($pdf,$outputlangs,$objmarge->page_hauteur); |
983
|
|
|
|
984
|
|
|
$pdf->SetTextColor(0,0,60); |
985
|
|
|
$pdf->SetFont('','B', $default_font_size + 3); |
986
|
|
|
|
987
|
|
|
$posy=$objmarge->marge_haute; |
988
|
|
|
$posx=$objmarge->page_largeur-$objmarge->marge_droite-100; |
|
|
|
|
989
|
|
|
|
990
|
|
|
$pdf->SetXY($objmarge->marge_gauche,$posy); |
991
|
|
|
|
992
|
|
|
$logo=$conf->mycompany->dir_output.'/logos/'.$mysoc->logo; |
993
|
|
|
if ($mysoc->logo) |
994
|
|
|
{ |
995
|
|
|
if (is_readable($logo)) |
996
|
|
|
{ |
997
|
|
|
$height=pdf_getHeightForLogo($logo); |
998
|
|
|
$pdf->Image($logo, $objmarge->marge_gauche, $posy, 0, $height); // width=0 (auto) |
999
|
|
|
} |
1000
|
|
|
else |
1001
|
|
|
{ |
1002
|
|
|
$pdf->SetTextColor(200,0,0); |
1003
|
|
|
$pdf->SetFont('','B',$default_font_size - 2); |
1004
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); |
1005
|
|
|
$pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); |
1006
|
|
|
} |
1007
|
|
|
|
1008
|
|
|
$posy+=35; |
1009
|
|
|
} |
1010
|
|
|
else |
1011
|
|
|
{ |
1012
|
|
|
$text=$mysoc->name; |
1013
|
|
|
$pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); |
1014
|
|
|
|
1015
|
|
|
$posy+=15; |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
|
1019
|
|
|
$pdf->SetTextColor(0,0,0); |
1020
|
|
|
$pdf->SetFont('','B', $default_font_size + 2); |
1021
|
|
|
$pdf->SetXY($objmarge->marge_gauche,$posy); |
1022
|
|
|
|
1023
|
|
|
$key = 'subtotalPropalTitle'; |
1024
|
|
|
if ($object->element == 'commande') $key = 'subtotalCommandeTitle'; |
1025
|
|
|
elseif ($object->element == 'facture') $key = 'subtotalInvoiceTitle'; |
1026
|
|
|
elseif ($object->element == 'facturerec') $key = 'subtotalInvoiceTitle'; |
1027
|
|
|
|
1028
|
|
|
$pdf->MultiCell(150, 4, $outputlangs->transnoentities($key, $object->ref, $object->thirdparty->name), '', 'L'); |
1029
|
|
|
|
1030
|
|
|
$pdf->SetFont('','', $default_font_size); |
1031
|
|
|
$pdf->SetXY($objmarge->page_largeur-$objmarge->marge_droite-40,$posy); |
1032
|
|
|
$pdf->MultiCell(40, 4, dol_print_date($object->date, 'daytext'), '', 'R'); |
|
|
|
|
1033
|
|
|
|
1034
|
|
|
$posy += 8; |
1035
|
|
|
|
1036
|
|
|
$pdf->SetFont('','B', $default_font_size + 2); |
1037
|
|
|
$pdf->SetXY($objmarge->marge_gauche,$posy); |
1038
|
|
|
$pdf->MultiCell(70, 4, $outputlangs->transnoentities('subtotalRecapLot'), '', 'L'); |
1039
|
|
|
|
1040
|
|
|
} |
1041
|
|
|
|
1042
|
|
|
/** |
1043
|
|
|
* Show table for lines |
1044
|
|
|
* |
1045
|
|
|
* @param PDF $pdf Object PDF |
1046
|
|
|
* @param string $tab_top Top position of table |
1047
|
|
|
* @param string $tab_height Height of table (rectangle) |
1048
|
|
|
* @param int $nexY Y (not used) |
1049
|
|
|
* @param Translate $outputlangs Langs object |
1050
|
|
|
* @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
1051
|
|
|
* @param int $hidebottom Hide bottom bar of array |
1052
|
|
|
* @param string $currency Currency code |
1053
|
|
|
* @return void |
1054
|
|
|
*/ |
1055
|
|
|
private static function tableau(&$objmarge, &$pdf, $posx_designation, $posx_options, $posx_montant, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='') |
1056
|
|
|
{ |
1057
|
|
|
global $conf; |
1058
|
|
|
|
1059
|
|
|
// Force to disable hidetop and hidebottom |
1060
|
|
|
$hidebottom=0; |
|
|
|
|
1061
|
|
|
if ($hidetop) $hidetop=-1; |
1062
|
|
|
|
1063
|
|
|
$currency = !empty($currency) ? $currency : $conf->currency; |
1064
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
1065
|
|
|
|
1066
|
|
|
// Amount in (at tab_top - 1) |
1067
|
|
|
$pdf->SetTextColor(0,0,0); |
1068
|
|
|
$pdf->SetFont('','',$default_font_size); |
1069
|
|
|
|
1070
|
|
|
if (empty($hidetop)) |
1071
|
|
|
{ |
1072
|
|
|
$titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency)); |
1073
|
|
|
$pdf->SetXY($objmarge->page_largeur - $objmarge->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4.5); |
1074
|
|
|
$pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre); |
1075
|
|
|
|
1076
|
|
|
if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($objmarge->marge_gauche, $tab_top, $objmarge->page_largeur-$objmarge->marge_droite-$objmarge->marge_gauche, 8, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)); |
1077
|
|
|
|
1078
|
|
|
|
1079
|
|
|
$pdf->line($objmarge->marge_gauche, $tab_top, $objmarge->page_largeur-$objmarge->marge_droite, $tab_top); // line prend une position y en 2eme param et 4eme param |
1080
|
|
|
|
1081
|
|
|
$pdf->SetXY($posx_designation, $tab_top+2); |
1082
|
|
|
$pdf->MultiCell($posx_options - $posx_designation,2, $outputlangs->transnoentities("Designation"),'','L'); |
1083
|
|
|
$pdf->SetXY($posx_options, $tab_top+2); |
1084
|
|
|
$pdf->MultiCell($posx_montant - $posx_options,2, $outputlangs->transnoentities("Options"),'','R'); |
1085
|
|
|
$pdf->SetXY($posx_montant, $tab_top+2); |
1086
|
|
|
$pdf->MultiCell($objmarge->page_largeur - $objmarge->marge_droite - $posx_montant,2, $outputlangs->transnoentities("Amount"),'','R'); |
1087
|
|
|
|
1088
|
|
|
$pdf->line($objmarge->marge_gauche, $tab_top+8, $objmarge->page_largeur-$objmarge->marge_droite, $tab_top+8); // line prend une position y en 2eme param et 4eme param |
1089
|
|
|
} |
1090
|
|
|
else |
1091
|
|
|
{ |
1092
|
|
|
$pdf->line($objmarge->marge_gauche, $tab_top-2, $objmarge->page_largeur-$objmarge->marge_droite, $tab_top-2); // line prend une position y en 2eme param et 4eme param |
1093
|
|
|
} |
1094
|
|
|
|
1095
|
|
|
} |
1096
|
|
|
|
1097
|
|
|
private static function tableau_tot(&$objmarge, &$pdf, $object, $posy, $outputlangs, $TTot) |
1098
|
|
|
{ |
1099
|
|
|
global $conf; |
1100
|
|
|
|
1101
|
|
|
$pdf->line($objmarge->marge_gauche, $posy, $objmarge->page_largeur-$objmarge->marge_droite, $posy); // line prend une position y en 2eme param et 4eme param |
1102
|
|
|
|
1103
|
|
|
$default_font_size = pdf_getPDFFontSize($outputlangs); |
1104
|
|
|
|
1105
|
|
|
$tab2_top = $posy+2; |
1106
|
|
|
$tab2_hl = 4; |
1107
|
|
|
$pdf->SetFont('','', $default_font_size - 1); |
1108
|
|
|
|
1109
|
|
|
// Tableau total |
1110
|
|
|
$col1x = 120; $col2x = 170; |
1111
|
|
|
if ($objmarge->page_largeur < 210) // To work with US executive format |
1112
|
|
|
{ |
1113
|
|
|
$col2x-=20; |
1114
|
|
|
} |
1115
|
|
|
$largcol2 = ($objmarge->page_largeur - $objmarge->marge_droite - $col2x); |
1116
|
|
|
|
1117
|
|
|
$useborder=0; |
1118
|
|
|
$index = 0; |
1119
|
|
|
|
1120
|
|
|
// Total HT |
1121
|
|
|
$pdf->SetFillColor(255,255,255); |
1122
|
|
|
$pdf->SetXY($col1x, $tab2_top + 0); |
1123
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1); |
1124
|
|
|
|
1125
|
|
|
// $total_ht = ($conf->multicurrency->enabled && $object->mylticurrency_tx != 1) ? $TTot['multicurrency_total_ht'] : $TTot['total_ht']; |
1126
|
|
|
$total_ht = $TTot['total_ht']; |
1127
|
|
|
$pdf->SetXY($col2x, $tab2_top + 0); |
1128
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($total_ht, 0, $outputlangs), 0, 'R', 1); |
|
|
|
|
1129
|
|
|
|
1130
|
|
|
// Show VAT by rates and total |
1131
|
|
|
$pdf->SetFillColor(248,248,248); |
1132
|
|
|
|
1133
|
|
|
$atleastoneratenotnull=0; |
1134
|
|
|
foreach($TTot['TTotal_tva'] as $tvakey => $tvaval) |
1135
|
|
|
{ |
1136
|
|
|
if ($tvakey != 0) // On affiche pas taux 0 |
1137
|
|
|
{ |
1138
|
|
|
$atleastoneratenotnull++; |
1139
|
|
|
|
1140
|
|
|
$index++; |
1141
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
1142
|
|
|
|
1143
|
|
|
$tvacompl=''; |
1144
|
|
|
if (preg_match('/\*/',$tvakey)) |
1145
|
|
|
{ |
1146
|
|
|
$tvakey=str_replace('*','',$tvakey); |
1147
|
|
|
$tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")"; |
1148
|
|
|
} |
1149
|
|
|
$totalvat =$outputlangs->transnoentities("TotalVAT").' '; |
1150
|
|
|
$totalvat.=vatrate($tvakey,1).$tvacompl; |
|
|
|
|
1151
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1); |
1152
|
|
|
|
1153
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
1154
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1); |
1155
|
|
|
} |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
// Total TTC |
1159
|
|
|
$index++; |
1160
|
|
|
$pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); |
1161
|
|
|
$pdf->SetTextColor(0,0,60); |
1162
|
|
|
$pdf->SetFillColor(224,224,224); |
1163
|
|
|
$pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1); |
1164
|
|
|
|
1165
|
|
|
// $total_ttc = ($conf->multicurrency->enabled && $object->multiccurency_tx != 1) ? $TTot['multicurrency_total_ttc'] : $TTot['total_ttc']; |
1166
|
|
|
$total_ttc = $TTot['total_ttc']; |
1167
|
|
|
$pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); |
1168
|
|
|
$pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1); |
1169
|
|
|
|
1170
|
|
|
$pdf->SetTextColor(0,0,0); |
1171
|
|
|
|
1172
|
|
|
$index++; |
1173
|
|
|
return ($tab2_top + ($tab2_hl * $index)); |
1174
|
|
|
|
1175
|
|
|
} |
1176
|
|
|
|
1177
|
|
|
/** |
1178
|
|
|
* Rect pdf |
1179
|
|
|
* |
1180
|
|
|
* @param PDF $pdf Object PDF |
1181
|
|
|
* @param float $x Abscissa of first point |
1182
|
|
|
* @param float $y Ordinate of first point |
1183
|
|
|
* @param float $l ?? |
1184
|
|
|
* @param float $h ?? |
1185
|
|
|
* @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title |
1186
|
|
|
* @param int $hidebottom Hide bottom |
1187
|
|
|
* @return void |
1188
|
|
|
*/ |
1189
|
|
|
private static function printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0) |
1190
|
|
|
{ |
1191
|
|
|
if (empty($hidetop) || $hidetop==-1) $pdf->line($x, $y, $x+$l, $y); |
1192
|
|
|
$pdf->line($x+$l, $y, $x+$l, $y+$h); |
1193
|
|
|
if (empty($hidebottom)) $pdf->line($x+$l, $y+$h, $x, $y+$h); |
1194
|
|
|
$pdf->line($x, $y+$h, $x, $y); |
1195
|
|
|
} |
1196
|
|
|
|
1197
|
|
|
|
1198
|
|
|
public static function concat(&$outputlangs, $files, $fileoutput='') |
1199
|
|
|
{ |
1200
|
|
|
global $conf; |
1201
|
|
|
|
1202
|
|
|
if (empty($fileoutput)) $fileoutput = $file[0]; |
|
|
|
|
1203
|
|
|
|
1204
|
|
|
$pdf=pdf_getInstance(); |
1205
|
|
|
if (class_exists('TCPDF')) |
1206
|
|
|
{ |
1207
|
|
|
$pdf->setPrintHeader(false); |
1208
|
|
|
$pdf->setPrintFooter(false); |
1209
|
|
|
} |
1210
|
|
|
$pdf->SetFont(pdf_getPDFFont($outputlangs)); |
1211
|
|
|
|
1212
|
|
|
if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
1213
|
|
|
|
1214
|
|
|
|
1215
|
|
|
foreach($files as $file) |
1216
|
|
|
{ |
1217
|
|
|
$pagecount = $pdf->setSourceFile($file); |
1218
|
|
|
for ($i = 1; $i <= $pagecount; $i++) |
1219
|
|
|
{ |
1220
|
|
|
$tplidx = $pdf->ImportPage($i); |
1221
|
|
|
$s = $pdf->getTemplatesize($tplidx); |
1222
|
|
|
$pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); |
1223
|
|
|
$pdf->useTemplate($tplidx); |
1224
|
|
|
} |
1225
|
|
|
} |
1226
|
|
|
|
1227
|
|
|
$pdf->Output($fileoutput,'F'); |
1228
|
|
|
if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
|
|
|
1229
|
|
|
|
1230
|
|
|
return $pagecount; |
|
|
|
|
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
/** |
1234
|
|
|
* Méthode pour savoir si une ligne fait partie d'un bloc Compris/Non Compris |
1235
|
|
|
* |
1236
|
|
|
* @param PropaleLigne|OrderLine|FactureLigne $line |
1237
|
|
|
* @return true or false |
1238
|
|
|
*/ |
1239
|
|
|
public static function hasNcTitle(&$line) |
1240
|
|
|
{ |
1241
|
|
|
if(isset($line->has_nc_title)) return $line->has_nc_title; |
1242
|
|
|
|
1243
|
|
|
$TTitle = self::getAllTitleFromLine($line); |
1244
|
|
|
foreach ($TTitle as &$line_title) |
1245
|
|
|
{ |
1246
|
|
|
if (!empty($line_title->array_options['options_subtotal_nc'])) |
1247
|
|
|
{ |
1248
|
|
|
$line->has_nc_title = true; |
1249
|
|
|
return true; |
1250
|
|
|
} |
1251
|
|
|
} |
1252
|
|
|
|
1253
|
|
|
$line->has_nc_title = false; |
1254
|
|
|
return false; |
|
|
|
|
1255
|
|
|
} |
1256
|
|
|
|
1257
|
|
|
/** |
1258
|
|
|
* Méthode pour récupérer le titre de la ligne |
1259
|
|
|
* |
1260
|
|
|
* @param PropaleLigne|OrderLine|FactureLigne $line |
1261
|
|
|
* @return string |
1262
|
|
|
*/ |
1263
|
|
|
public static function getTitleLabel($line) |
1264
|
|
|
{ |
1265
|
|
|
$title = $line->label; |
1266
|
|
|
if (empty($title)) $title = !empty($line->description) ? $line->description : $line->desc; |
1267
|
|
|
return $title; |
1268
|
|
|
} |
1269
|
|
|
} |
1270
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.