Interfacesubtotaltrigger::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/* <one line to give the program's name and a brief idea of what it does.>
3
 * Copyright (C) 2013 ATM Consulting <[email protected]>
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
/**
20
 * 	\file		core/triggers/interface_99_modMyodule_Mytrigger.class.php
21
 * 	\ingroup	titre
22
 * 	\brief		Sample trigger
23
 * 	\remarks	You can create other triggers by copying this one
24
 * 				- File name should be either:
25
 * 					interface_99_modMymodule_Mytrigger.class.php
26
 * 					interface_99_all_Mytrigger.class.php
27
 * 				- The file must stay in core/triggers
28
 * 				- The class name must be InterfaceMytrigger
29
 * 				- The constructor method must be named InterfaceMytrigger
30
 * 				- The name property name must be Mytrigger
31
 */
32
33
/**
34
 * Trigger class
35
 */
36
class Interfacesubtotaltrigger extends DolibarrTriggers
37
{
38
    /**
39
     * Constructor
40
     *
41
     * 	@param		DoliDB		$db		Database handler
42
     */
43
    public function __construct($db)
44
    {
45
        $this->db = $db;
46
47
        $this->name = preg_replace('/^Interface/i', '', get_class($this));
48
        $this->family = "demo";
49
        $this->description = "Triggers of this module are subtotal functions.";
50
        // 'development', 'experimental', 'dolibarr' or version
51
        $this->version = 'development';
52
        $this->picto = 'subtotal@subtotal';
53
    }
54
55
    /**
56
     * Trigger name
57
     *
58
     * 	@return		string	Name of trigger file
59
     */
60
    public function getName()
61
    {
62
        return $this->name;
63
    }
64
65
    /**
66
     * Trigger description
67
     *
68
     * 	@return		string	Description of trigger file
69
     */
70
    public function getDesc()
71
    {
72
        return $this->description;
73
    }
74
75
    /**
76
     * Trigger version
77
     *
78
     * 	@return		string	Version of trigger file
79
     */
80
    public function getVersion()
81
    {
82
        global $langs;
83
        $langs->load("admin");
84
85
        if ($this->version == 'development') {
86
            return $langs->trans("Development");
87
        } elseif ($this->version == 'experimental')
88
89
                return $langs->trans("Experimental");
90
        elseif ($this->version == 'dolibarr') return DOL_VERSION;
91
        elseif ($this->version) return $this->version;
92
        else {
93
            return $langs->trans("Unknown");
94
        }
95
    }
96
97
	public function addToBegin(&$parent, &$object, $rang)
98
	{
99
		foreach ($parent->lines as &$line)
100
		{
101
			// Si (ma ligne courrante n'est pas celle que je viens d'ajouter) et que (le rang courrant est supérieure au rang du titre)
102
			if ($object->id != $line->id && $line->rang > $rang)
103
			{
104
				// Update du rang de toutes les lignes suivant mon titre
105
				$parent->updateRangOfLine($line->id, $line->rang+1);
106
			}
107
		}
108
109
		// Update du rang de la ligne fraichement ajouté pour la déplacer sous mon titre
110
		$parent->updateRangOfLine($object->id, $rang+1);
111
		$object->rang = $rang+1;
112
	}
113
114
	public function addToEnd(&$parent, &$object, $rang)
115
	{
116
		$title_level = -1;
117
		$subtotal_line_found = false;
118
		foreach ($parent->lines as $k => &$line)
119
		{
120
			if ($line->rang < $rang) continue;
121
			elseif ($line->rang == $rang) // Je suis sur la ligne de titre où je souhaite ajouter ma nouvelle ligne en fin de bloc
122
			{
123
				$title_level = $line->qty;
124
			}
125
			elseif (!$subtotal_line_found && $title_level > -1 && ($line->qty == 100 - $title_level)) // Le level de mon titre a été trouvé avant, donc maintenant je vais m'arrêter jusqu'à trouver un sous-total
126
			{
127
				$subtotal_line_found = true;
128
				$rang = $line->rang;
129
			}
130
131
132
			if ($subtotal_line_found)
133
			{
134
				$parent->updateRangOfLine($line->id, $line->rang+1);
135
			}
136
		}
137
138
		if ($subtotal_line_found)
139
		{
140
			$parent->updateRangOfLine($object->id, $rang);
141
			$object->rang = $rang;
142
		}
143
	}
144
145
    /**
146
     * Function called when a Dolibarrr business event is done.
147
     * All functions "runTrigger" are triggered if file
148
     * is inside directory core/triggers
149
     *
150
     * 	@param		string		$action		Event action code
151
     * 	@param		Object		$object		Object
152
     * 	@param		User		$user		Object user
153
     * 	@param		Translate	$langs		Object langs
154
     * 	@param		conf		$conf		Object conf
155
     * 	@return		int						<0 if KO, 0 if no triggered ran, >0 if OK
156
     */
157
    public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
158
    {
159
        // Put here code you want to execute when a Dolibarr business events occurs.
160
        // Data and type of action are stored into $object and $action
161
        // Users
162
        dol_include_once('/subtotal/class/subtotal.class.php');
163
        $langs->load('subtotal@subtotal');
164
165
        if (!empty($conf->global->SUBTOTAL_ALLOW_ADD_LINE_UNDER_TITLE) && in_array($action, array('LINEPROPAL_INSERT', 'LINEORDER_INSERT', 'LINEBILL_INSERT')))
166
		{
167
			$rang = GETPOST('under_title', 'int'); // Rang du titre
168
			if ($rang > 0)
169
			{
170
				switch ($action) {
171
					case 'LINEPROPAL_INSERT':
172
						$parent = new Propal($this->db);
173
						$parent->fetch($object->fk_propal);
174
						break;
175
					case 'LINEORDER_INSERT':
176
						$parent = new Commande($this->db);
177
						$parent->fetch($object->fk_commande);
178
						break;
179
					case 'LINEBILL_INSERT':
180
						$parent = new Facture($this->db);
181
						$parent->fetch($object->fk_facture);
182
						break;
183
                    case 'LINEBILL_SUPPLIER_CREATE':
184
                        $parent = new FactureFournisseur($this->db);
185
                        $parent->fetch($object->fk_facture_fourn);
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
186
					default:
187
						$parent = $object;
188
						break;
189
				}
190
191
				if (!empty($conf->global->SUBTOTAL_ADD_LINE_UNDER_TITLE_AT_END_BLOCK)) $this->addToEnd($parent, $object, $rang);
192
				else $this->addToBegin($parent, $object, $rang);
193
194
			}
195
196
		}
197
198
199
        if ($action == 'LINEBILL_INSERT' || $action == 'LINEBILL_SUPPLIER_CREATE')
200
		{
201
		    $is_supplier = $action == 'LINEBILL_SUPPLIER_CREATE' ? true : false;
202
            /** @var bool $subtotal_skip Permet d'éviter de faire du traitement en double sur les titres est sous-totaux car ils ont automatiquement le bon rang, il ne faut donc pas faire un addline pour en suite update le rang ici */
203
		    global $subtotal_skip;
204
205
		    if ($subtotal_skip)
206
            {
207
                $subtotal_skip = false;
208
            }
209
		    else
210
            {
211
			    $subtotal_add_title_bloc_from_orderstoinvoice = GETPOST('subtotal_add_title_bloc_from_orderstoinvoice', 'none');
212
			    if (!empty($subtotal_add_title_bloc_from_orderstoinvoice))
213
			    {
214
				    global $subtotal_current_rang, $subtotal_bloc_previous_fk_commande, $subtotal_bloc_already_add_title, $subtotal_bloc_already_add_st;
215
216
				    $current_fk_commande = TSubtotal::getOrderIdFromLineId($this->db, $object->origin_id, $is_supplier);
217
				    $last_fk_commandedet = TSubtotal::getLastLineOrderId($this->db, $current_fk_commande, $is_supplier);
0 ignored issues
show
Bug introduced by
It seems like $current_fk_commande can also be of type false; however, parameter $fk_commande of TSubtotal::getLastLineOrderId() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

217
				    $last_fk_commandedet = TSubtotal::getLastLineOrderId($this->db, /** @scrutinizer ignore-type */ $current_fk_commande, $is_supplier);
Loading history...
218
219
				    if (!$is_supplier){
220
				        $facture = new Facture($this->db);
221
				        $ret = $facture->fetch($object->fk_facture);
222
                    }
223
				    else
224
                    {
225
				        $facture = new FactureFournisseur($this->db);
226
				        $ret = $facture->fetch($object->fk_facture_fourn);
227
                    }
228
229
				    if ($ret > 0 && !$subtotal_bloc_already_add_st)
230
				    {
231
					    $rang = !empty($subtotal_current_rang) ? $subtotal_current_rang : $object->rang;
232
					    // Si le fk_commande courrant est différent alors on change de commande => ajout d'un titre
233
					    if ($current_fk_commande != $subtotal_bloc_previous_fk_commande ) {
234
                            if (!$is_supplier) $commande = new Commande($this->db);
235
                            else $commande = new CommandeFournisseur($this->db);
236
                            $commande->fetch($current_fk_commande);
0 ignored issues
show
Bug introduced by
It seems like $current_fk_commande can also be of type false; however, parameter $id of CommandeFournisseur::fetch() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

236
                            $commande->fetch(/** @scrutinizer ignore-type */ $current_fk_commande);
Loading history...
Bug introduced by
It seems like $current_fk_commande can also be of type false; however, parameter $id of Commande::fetch() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

236
                            $commande->fetch(/** @scrutinizer ignore-type */ $current_fk_commande);
Loading history...
237
238
                            $label = $conf->global->SUBTOTAL_TEXT_FOR_TITLE_ORDETSTOINVOICE;
239
                            if (empty($label)) {
240
                                $label = 'Commande [__REFORDER__]';
241
                                if (!$is_supplier) $label .= ' - Référence client : [__REFCUSTOMER__]';
242
                            }
243
                            $label = str_replace(array('__REFORDER__', '__REFCUSTOMER__'), array($commande->ref, $commande->ref_client), $label);
0 ignored issues
show
Bug introduced by
The property ref_client does not seem to exist on CommandeFournisseur.
Loading history...
244
245
                            if(!empty($current_fk_commande)) {
246
                                $subtotal_skip = true;
247
                                TSubtotal::addTitle($facture, $label, 1, $rang);
248
                                $rang++;
249
                            }
250
                        }
251
252
                        $object->rang = $rang;
253
					    $facture->updateRangOfLine($object->id, $rang);
254
					    $rang++;
255
					    // Est-ce qu'il s'agit de la dernière ligne de la commande d'origine ? Si oui alors on ajout un sous-total
256
                            if ($last_fk_commandedet === (int) $object->origin_id && !empty($current_fk_commande))
257
					    {
258
                            $subtotal_skip = true;
259
                            $subtotal_bloc_already_add_st = 1;
260
                            TSubtotal::addTotal($facture, $langs->trans('SubTotal'), 1, $rang);
261
                            $subtotal_bloc_already_add_st = 0;
262
                            $rang++;
263
					    }
264
				    }
265
266
				    $subtotal_bloc_previous_fk_commande = $current_fk_commande;
267
				    $subtotal_current_rang = $rang;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $rang does not seem to be defined for all execution paths leading up to this point.
Loading history...
268
			    }
269
		    }
270
271
		}
272
273
		if ($action == 'LINEBILL_UPDATE')
274
		{
275
			if (GETPOST('all_progress', 'none') && TSubtotal::isModSubtotalLine($object))
276
			{
277
				$object->situation_percent = 0;
278
				$object->update($user, true); // notrigger pour éviter la boucle infinie
279
			}
280
		}
281
282
		if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && in_array($action, array('LINEPROPAL_INSERT', 'LINEPROPAL_UPDATE', 'LINEORDER_INSERT', 'LINEORDER_UPDATE', 'LINEBILL_INSERT', 'LINEBILL_UPDATE', 'LINEBILL_SUPPLIER_CREATE', 'LINEBILL_SUPPLIER_UPDATE')))
283
		{
284
            if(! function_exists('_updateLineNC')) dol_include_once('/subtotal/lib/subtotal.lib.php');
285
286
			$doli_action = GETPOST('action', 'none');
287
			$set = GETPOST('set', 'none');
288
			if ( (in_array($doli_action, array('updateligne', 'updateline', 'addline', 'add', 'create', 'setstatut', 'save_nomenclature')) || $set == 'defaultTVA') && !TSubtotal::isTitle($object) && !TSubtotal::isSubtotal($object) && in_array($object->element, array('propaldet', 'commandedet', 'facturedet')))
289
			{
290
				 dol_syslog(
291
					"[SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS] Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". object=".$object->element." id=" . $object->id
292
				);
293
294
				$TTitle = TSubtotal::getAllTitleFromLine($object);
295
				foreach ($TTitle as &$line)
296
				{
297
					if (!empty($line->array_options['options_subtotal_nc']))
298
					{
299
						$object->total_ht = $object->total_tva = $object->total_ttc = $object->total_localtax1 = $object->total_localtax2 =
300
							$object->multicurrency_total_ht = $object->multicurrency_total_tva = $object->multicurrency_total_ttc = 0;
301
302
						if ($object->element == 'propal') $res = $object->update(1);
303
						else $res = $object->update($user, 1);
304
305
						if ($res > 0) setEventMessage($langs->trans('subtotal_update_nc_success'));
306
						break;
307
					}
308
				}
309
310
				// $object correspond à la ligne ajoutée
311
				if(empty($object->array_options)) $object->fetch_optionals();
312
313
				if(! empty($object->array_options['options_subtotal_nc'])) {
314
					$object->total_ht = $object->total_tva = $object->total_ttc = $object->total_localtax1 = $object->total_localtax2 =
315
							$object->multicurrency_total_ht = $object->multicurrency_total_tva = $object->multicurrency_total_ttc = 0;
316
317
					if ($object->element == 'propaldet') $res = $object->update(1);
318
					else $res = $object->update($user, 1);
319
320
					if ($res > 0) setEventMessage($langs->trans('subtotal_update_nc_success'));
321
				}
322
323
				// Correction d'un bug lors de la création d'une commande depuis une propale qui a, au moins, une ligne NC
324
				$parent_element = '';
325
				if($object->element == 'propaldet') $parent_element = 'propal';
326
				if($object->element == 'commandedet') $parent_element = 'commande';
327
				if($object->element == 'facturedet') $parent_element = 'facture';
328
329
				if(! empty($parent_element) && ! empty($object->array_options['options_subtotal_nc'])) {
330
					_updateLineNC($parent_element, $object->{'fk_'.$parent_element}, $object->id, $object->array_options['options_subtotal_nc'], 1);
331
				}
332
			}
333
		}
334
335
		// Les lignes libres (y compris les sous-totaux) créées à partir d'une facture modèle n'ont pas la TVA de la ligne du modèle mais la TVA par défaut
336
		if ($action == 'BILL_CREATE' && $object->fac_rec > 0) {
337
			dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id);
338
339
			$object->fetch_lines(); // Lignes pas rajoutées à $object->lines par les appels à addline();
340
341
			foreach($object->lines as &$line) {
342
				if(TSubtotal::isSubtotal($line) && ! empty($line->tva_tx)) {
343
					$line->tva_tx = 0;
344
					$line->update();
345
				}
346
			}
347
		}
348
349
		// Gestion des titres et sous-totaux dans les expéditions
350
		// Il faut supprimer de l'expédition les titres et sous-totaux s'ils n'ont pas de lignes de produits / services entre eux
351
		if ($action == 'SHIPPING_CREATE') {
352
			$object->fetch_lines(); // Obligé de fetch les lines car au retour de la création, les lignes n'ont pas leur id...
353
354
			// Parcours des lignes et lorsque un tire et un sous-total de même niveau, ou 2 titres de même niveau sont à la suite, on les supprime
355
			foreach ($object->lines as &$line) {
356
				$orderline = new OrderLine($this->db);
357
				$orderline->fetch($line->origin_line_id);
358
359
				if(TSubtotal::isTitle($orderline) || TSubtotal::isSubtotal($orderline)) { // Nous sommes sur une ligne titre, si la ligne précédente est un titre de même niveau, on supprime la ligne précédente
360
					$line->special_code = TSubtotal::$module_number;
361
				}
362
			}
363
			$TLinesToDelete = array();
364
			foreach ($object->lines as &$line) {
365
				if(TSubtotal::isTitle($line)) {
366
					$TLines = TSubtotal::getLinesFromTitleId($object, $line->id, true);
367
					$TBlocks = array();
368
					$isThereProduct = false;
369
					foreach($TLines as $lineInBlock) {
370
						if(TSubtotal::isTitle($lineInBlock) || TSubtotal::isSubtotal($lineInBlock)) $TBlocks[$lineInBlock->id] = $lineInBlock;
371
						else $isThereProduct = true;
372
					}
373
					if(!$isThereProduct) {
374
						$TLinesToDelete = array_merge($TLinesToDelete, $TBlocks);
375
					}
376
				}
377
			}
378
			if (!empty($TLinesToDelete)) {
379
				foreach ($TLinesToDelete as $lineToDelete) {
380
					$lineToDelete->delete($user);
381
				}
382
			}
383
			//exit;
384
		}
385
386
        if ($action == 'USER_LOGIN') {
387
            dol_syslog(
388
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
389
            );
390
        } elseif ($action == 'USER_UPDATE_SESSION') {
391
            // Warning: To increase performances, this action is triggered only if
392
            // constant MAIN_ACTIVATE_UPDATESESSIONTRIGGER is set to 1.
393
            dol_syslog(
394
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
395
            );
396
        } elseif ($action == 'USER_CREATE') {
397
            dol_syslog(
398
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
399
            );
400
        } elseif ($action == 'USER_CREATE_FROM_CONTACT') {
401
            dol_syslog(
402
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
403
            );
404
        } elseif ($action == 'USER_MODIFY') {
405
            dol_syslog(
406
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
407
            );
408
        } elseif ($action == 'USER_NEW_PASSWORD') {
409
            dol_syslog(
410
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
411
            );
412
        } elseif ($action == 'USER_ENABLEDISABLE') {
413
            dol_syslog(
414
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
415
            );
416
        } elseif ($action == 'USER_DELETE') {
417
            dol_syslog(
418
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
419
            );
420
        } elseif ($action == 'USER_LOGOUT') {
421
            dol_syslog(
422
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
423
            );
424
        } elseif ($action == 'USER_SETINGROUP') {
425
            dol_syslog(
426
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
427
            );
428
        } elseif ($action == 'USER_REMOVEFROMGROUP') {
429
            dol_syslog(
430
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
431
            );
432
        }
433
434
        // Groups
435
        elseif ($action == 'GROUP_CREATE') {
436
            dol_syslog(
437
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
438
            );
439
        } elseif ($action == 'GROUP_MODIFY') {
440
            dol_syslog(
441
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
442
            );
443
        } elseif ($action == 'GROUP_DELETE') {
444
            dol_syslog(
445
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
446
            );
447
        }
448
449
        // Companies
450
        elseif ($action == 'COMPANY_CREATE') {
451
            dol_syslog(
452
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
453
            );
454
        } elseif ($action == 'COMPANY_MODIFY') {
455
            dol_syslog(
456
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
457
            );
458
        } elseif ($action == 'COMPANY_DELETE') {
459
            dol_syslog(
460
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
461
            );
462
        }
463
464
        // Contacts
465
        elseif ($action == 'CONTACT_CREATE') {
466
            dol_syslog(
467
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
468
            );
469
        } elseif ($action == 'CONTACT_MODIFY') {
470
            dol_syslog(
471
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
472
            );
473
        } elseif ($action == 'CONTACT_DELETE') {
474
            dol_syslog(
475
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
476
            );
477
        }
478
479
        // Products
480
        elseif ($action == 'PRODUCT_CREATE') {
481
            dol_syslog(
482
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
483
            );
484
        } elseif ($action == 'PRODUCT_MODIFY') {
485
            dol_syslog(
486
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
487
            );
488
        } elseif ($action == 'PRODUCT_DELETE') {
489
            dol_syslog(
490
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
491
            );
492
        }
493
494
        // Customer orders
495
        elseif ($action == 'ORDER_VALIDATE') {
496
            dol_syslog(
497
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
498
            );
499
        } elseif ($action == 'ORDER_DELETE') {
500
            dol_syslog(
501
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
502
            );
503
        } elseif ($action == 'ORDER_BUILDDOC') {
504
            dol_syslog(
505
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
506
            );
507
        } elseif ($action == 'ORDER_SENTBYMAIL') {
508
            dol_syslog(
509
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
510
            );
511
        } elseif ($action == 'LINEORDER_INSERT') {
512
            dol_syslog(
513
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
514
            );
515
        } elseif ($action == 'LINEORDER_DELETE') {
516
            dol_syslog(
517
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
518
            );
519
        }
520
521
        // Supplier orders
522
        elseif ($action == 'ORDER_SUPPLIER_CREATE') {
523
            dol_syslog(
524
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
525
            );
526
        } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') {
527
            dol_syslog(
528
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
529
            );
530
        } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') {
531
            dol_syslog(
532
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
533
            );
534
        } elseif ($action == 'SUPPLIER_ORDER_BUILDDOC') {
535
            dol_syslog(
536
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
537
            );
538
        }
539
540
        // Proposals
541
        elseif ((floatval(DOL_VERSION) <= 7.0 && in_array($action, array('PROPAL_CLONE', 'ORDER_CLONE', 'BILL_CLONE'))) ||
542
                (floatval(DOL_VERSION) >= 8.0 && ! empty($object->context) && in_array('createfromclone', $object->context) && in_array($action, array('PROPAL_CREATE', 'ORDER_CREATE', 'BILL_CREATE')))) {
543
            dol_syslog(
544
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
545
            );
546
547
			$doli_action = GETPOST('action', 'none');
548
549
			if (!empty($conf->global->SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS) && in_array($doli_action, array('confirm_clone')))
550
			{
551
				dol_syslog(
552
					"[SUBTOTAL_MANAGE_COMPRIS_NONCOMPRIS] Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". object=".$object->element." id=" . $object->id
553
				);
554
555
				// En fonction de l'objet et de la version, les lignes conservent l'id de l'objet d'origine
556
				if (method_exists($object, 'fetch_lines')) $object->fetch_lines();
557
				else $object->fetch($object->id);
558
559
				foreach ($object->lines as &$line)
560
				{
561
					if (empty($line->array_options)) $line->fetch_optionals();
562
563
					if (!TSubtotal::isModSubtotalLine($line) && !empty($line->array_options['options_subtotal_nc']))
564
					{
565
						$line->total_ht = $line->total_tva = $line->total_ttc = $line->total_localtax1 = $line->total_localtax2 =
566
							$line->multicurrency_total_ht = $line->multicurrency_total_tva = $line->multicurrency_total_ttc = 0;
567
568
						if ($line->element == 'propaldet') $res = $line->update(1);
569
						else $res = $line->update($user, 1);
570
571
						if ($res > 0) setEventMessage($langs->trans('subtotal_update_nc_success'));
572
					}
573
				}
574
575
				if (!empty($line)) $object->update_price(1);
576
			}
577
578
        } elseif ($action == 'PROPAL_MODIFY') {
579
            dol_syslog(
580
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
581
            );
582
        } elseif ($action == 'PROPAL_VALIDATE') {
583
            dol_syslog(
584
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
585
            );
586
        } elseif ($action == 'PROPAL_BUILDDOC') {
587
            dol_syslog(
588
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
589
            );
590
        } elseif ($action == 'PROPAL_SENTBYMAIL') {
591
            dol_syslog(
592
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
593
            );
594
        } elseif ($action == 'PROPAL_CLOSE_SIGNED') {
595
            dol_syslog(
596
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
597
            );
598
        } elseif ($action == 'PROPAL_CLOSE_REFUSED') {
599
            dol_syslog(
600
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
601
            );
602
        } elseif ($action == 'PROPAL_DELETE') {
603
            dol_syslog(
604
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
605
            );
606
        } elseif ($action == 'LINEPROPAL_INSERT') {
607
            dol_syslog(
608
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
609
            );
610
        } elseif ($action == 'LINEPROPAL_MODIFY') {
611
            dol_syslog(
612
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
613
            );
614
        } elseif ($action == 'LINEPROPAL_DELETE') {
615
            dol_syslog(
616
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
617
            );
618
        }
619
620
        // Contracts
621
        elseif ($action == 'CONTRACT_CREATE') {
622
            dol_syslog(
623
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
624
            );
625
        } elseif ($action == 'CONTRACT_MODIFY') {
626
            dol_syslog(
627
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
628
            );
629
        } elseif ($action == 'CONTRACT_ACTIVATE') {
630
            dol_syslog(
631
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
632
            );
633
        } elseif ($action == 'CONTRACT_CANCEL') {
634
            dol_syslog(
635
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
636
            );
637
        } elseif ($action == 'CONTRACT_CLOSE') {
638
            dol_syslog(
639
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
640
            );
641
        } elseif ($action == 'CONTRACT_DELETE') {
642
            dol_syslog(
643
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
644
            );
645
        }
646
647
		elseif ($action == 'BILL_MODIFY') {
648
            dol_syslog(
649
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
650
            );
651
652
653
            global $conf;
654
655
            if (!empty($conf->global->INVOICE_USE_SITUATION) && $object->element == 'facture' && $object->type == Facture::TYPE_SITUATION)
656
            {
657
                $object->situation_final = 1;
658
                foreach($object->lines as $i => $line) {
659
                    if(!TSubtotal::isModSubtotalLine($line) && $line->situation_percent != 100){
660
                        $object->situation_final = 0;
661
                        break;
662
                    }
663
                }
664
                // ne pas utiliser $object->setFinal ne peut pas marcher
665
                $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture SET situation_final = ' . $object->situation_final . ' where rowid = ' . $object->id;
666
                $resql=$object->db->query($sql);
0 ignored issues
show
Unused Code introduced by
The assignment to $resql is dead and can be removed.
Loading history...
667
            }
668
669
670
        } elseif ($action == 'BILL_VALIDATE') {
671
            dol_syslog(
672
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
673
            );
674
        } elseif ($action == 'BILL_BUILDDOC') {
675
            dol_syslog(
676
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
677
            );
678
        } elseif ($action == 'BILL_SENTBYMAIL') {
679
            dol_syslog(
680
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
681
            );
682
        } elseif ($action == 'BILL_CANCEL') {
683
            dol_syslog(
684
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
685
            );
686
        } elseif ($action == 'BILL_DELETE') {
687
            dol_syslog(
688
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
689
            );
690
        } elseif ($action == 'LINEBILL_INSERT') {
691
692
        	dol_syslog(
693
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
694
            );
695
        } elseif ($action == 'LINEBILL_DELETE') {
696
            dol_syslog(
697
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
698
            );
699
        }
700
701
        // Payments
702
        elseif ($action == 'PAYMENT_CUSTOMER_CREATE') {
703
            dol_syslog(
704
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
705
            );
706
        } elseif ($action == 'PAYMENT_SUPPLIER_CREATE') {
707
            dol_syslog(
708
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
709
            );
710
        } elseif ($action == 'PAYMENT_ADD_TO_BANK') {
711
            dol_syslog(
712
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
713
            );
714
        } elseif ($action == 'PAYMENT_DELETE') {
715
            dol_syslog(
716
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
717
            );
718
        }
719
720
        // Interventions
721
        elseif ($action == 'FICHEINTER_CREATE') {
722
            dol_syslog(
723
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
724
            );
725
        } elseif ($action == 'FICHEINTER_MODIFY') {
726
            dol_syslog(
727
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
728
            );
729
        } elseif ($action == 'FICHEINTER_VALIDATE') {
730
            dol_syslog(
731
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
732
            );
733
        } elseif ($action == 'FICHEINTER_DELETE') {
734
            dol_syslog(
735
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
736
            );
737
        }
738
739
        // Members
740
        elseif ($action == 'MEMBER_CREATE') {
741
            dol_syslog(
742
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
743
            );
744
        } elseif ($action == 'MEMBER_VALIDATE') {
745
            dol_syslog(
746
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
747
            );
748
        } elseif ($action == 'MEMBER_SUBSCRIPTION') {
749
            dol_syslog(
750
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
751
            );
752
        } elseif ($action == 'MEMBER_MODIFY') {
753
            dol_syslog(
754
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
755
            );
756
        } elseif ($action == 'MEMBER_NEW_PASSWORD') {
757
            dol_syslog(
758
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
759
            );
760
        } elseif ($action == 'MEMBER_RESILIATE') {
761
            dol_syslog(
762
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
763
            );
764
        } elseif ($action == 'MEMBER_DELETE') {
765
            dol_syslog(
766
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
767
            );
768
        }
769
770
        // Categories
771
        elseif ($action == 'CATEGORY_CREATE') {
772
            dol_syslog(
773
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
774
            );
775
        } elseif ($action == 'CATEGORY_MODIFY') {
776
            dol_syslog(
777
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
778
            );
779
        } elseif ($action == 'CATEGORY_DELETE') {
780
            dol_syslog(
781
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
782
            );
783
        }
784
785
        // Projects
786
        elseif ($action == 'PROJECT_CREATE') {
787
            dol_syslog(
788
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
789
            );
790
        } elseif ($action == 'PROJECT_MODIFY') {
791
            dol_syslog(
792
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
793
            );
794
        } elseif ($action == 'PROJECT_DELETE') {
795
            dol_syslog(
796
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
797
            );
798
        }
799
800
        // Project tasks
801
        elseif ($action == 'TASK_CREATE') {
802
            dol_syslog(
803
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
804
            );
805
        } elseif ($action == 'TASK_MODIFY') {
806
            dol_syslog(
807
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
808
            );
809
        } elseif ($action == 'TASK_DELETE') {
810
            dol_syslog(
811
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
812
            );
813
        }
814
815
        // Task time spent
816
        elseif ($action == 'TASK_TIMESPENT_CREATE') {
817
            dol_syslog(
818
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
819
            );
820
        } elseif ($action == 'TASK_TIMESPENT_MODIFY') {
821
            dol_syslog(
822
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
823
            );
824
        } elseif ($action == 'TASK_TIMESPENT_DELETE') {
825
            dol_syslog(
826
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
827
            );
828
        }
829
830
        // Shipping
831
        elseif ($action == 'SHIPPING_CREATE') {
832
            dol_syslog(
833
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
834
            );
835
        } elseif ($action == 'SHIPPING_MODIFY') {
836
            dol_syslog(
837
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
838
            );
839
        } elseif ($action == 'SHIPPING_VALIDATE') {
840
            dol_syslog(
841
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
842
            );
843
        } elseif ($action == 'SHIPPING_SENTBYMAIL') {
844
            dol_syslog(
845
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
846
            );
847
        } elseif ($action == 'SHIPPING_DELETE') {
848
            dol_syslog(
849
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
850
            );
851
        } elseif ($action == 'SHIPPING_BUILDDOC') {
852
            dol_syslog(
853
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
854
            );
855
        }
856
857
        // File
858
        elseif ($action == 'FILE_UPLOAD') {
859
            dol_syslog(
860
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
861
            );
862
        } elseif ($action == 'FILE_DELETE') {
863
            dol_syslog(
864
                "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id
865
            );
866
        }
867
868
        return 0;
869
    }
870
}
871