dolibarr  7.0.0-beta
interface_50_modBlockedlog_ActionsBlockedLog.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
3  * Copyright (C) 2017-2018 Laurent Destailleur <eldy@users.sourceforge.net>
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 
25 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
26 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
27 
28 
33 {
34  public $family = 'system';
35  public $description = "Triggers of this module add action for BlockedLog module.";
36  public $version = self::VERSION_DOLIBARR;
37  public $picto = 'technic';
38 
49  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
50  {
51  if (empty($conf->blockedlog->enabled)) return 0; // Module not active, we do nothing
52 
53  // Test if event/record is qualified
54  $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription');
55  if (! in_array($object->element, $listofqualifiedelement)) return 1;
56 
57  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
58 
59  $b=new BlockedLog($this->db);
60 
61  // Tracked events
62  if (! in_array($action, array_keys($b->trackedevents)))
63  {
64  return 0;
65  }
66 
67  // Event/record is qualified
68  $qualified = 0;
69  $amounts = 0;
70  if ($action==='BILL_VALIDATE' || $action==='BILL_DELETE' || $action === 'BILL_SENTBYMAIL'
71  || $action==='BILL_SUPPLIER_VALIDATE' || $action==='BILL_SUPPLIER_DELETE' || $action === 'BILL_SUPPLIER_SENTBYMAIL'
72  || $action==='MEMBER_SUBCRIPTION_CREATE' || $action==='MEMBER_SUBCRIPTION_MODIFY' || $action==='MEMBER_SUBCRIPTION_DELETE'
73  || $action==='DON_VALIDATE' || $action==='DON_MODIFY' || $action==='DON_DELETE'
74  || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_DOWNLOAD') || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_PREVIEW')
75  )
76  {
77  $qualified++;
78 
79  if ($action==='DON_VALIDATE') $amounts = (double) $object->amount;
80  else $amounts = (double) $object->total_ttc;
81  }
82  /*if ($action === 'BILL_PAYED' || $action==='BILL_UNPAYED'
83  || $action === 'BILL_SUPPLIER_PAYED' || $action === 'BILL_SUPPLIER_UNPAYED')
84  {
85  $qualified++;
86  $amounts= (double) $object->total_ttc;
87  }*/
88  if ($action === 'PAYMENT_CUSTOMER_CREATE' || $action === 'PAYMENT_SUPPLIER_CREATE' || $action === 'DONATION_PAYMENT_CREATE'
89  || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE')
90  {
91  $qualified++;
92  $amounts = 0;
93  if(!empty($object->amounts)) {
94  foreach($object->amounts as $amount) {
95  $amounts+= price2num($amount);
96  }
97  }
98  }
99  elseif (strpos($action,'PAYMENT')!==false && ! in_array($action, array('PAYMENT_ADD_TO_BANK')))
100  {
101  $qualified++;
102  $amounts = (double) $object->amount;
103  }
104 
105  // Another protection.
106  // May be used when event is DOC_DOWNLOAD or DOC_PREVIEW and element is not an invoice
107  if (! $qualified)
108  {
109  return 0; // not implemented action log
110  }
111 
112  $result = $b->setObjectData($object, $action, $amounts); // Set field date_object, ref_object, fk_object, element, object_data
113 
114  if ($result < 0)
115  {
116  $this->error = $b->error;
117  $this->errors = $b->errors;
118  return -1;
119  }
120 
121  $res = $b->create($user);
122 
123  if ($res<0)
124  {
125  setEventMessages($b->error, $b->errors, 'errors');
126  return -1;
127  }
128  else
129  {
130  return 1;
131  }
132  }
133 
134 }
Class to stock current configuration.
Definition: conf.class.php:33
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage Dolibarr users.
Definition: user.class.php:39
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called on Dolibarrr payment or invoice event.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage Blocked Log.
Class of triggered functions for agenda module.
Class to manage translations.
Class that all the triggers must extend.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...