dolibarr 20.0.0
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 <https://www.gnu.org/licenses/>.
17 */
18
25require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
26
27
32{
38 public function __construct($db)
39 {
40 $this->db = $db;
41
42 $this->name = preg_replace('/^Interface/i', '', get_class($this));
43 $this->family = "system";
44 $this->description = "Triggers of this module add action for BlockedLog module (Module of unalterable logs).";
45 $this->version = self::VERSIONS['prod'];
46 $this->picto = 'technic';
47 }
48
59 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
60 {
61 if (empty($conf->blockedlog) || empty($conf->blockedlog->enabled)) {
62 return 0; // Module not active, we do nothing
63 }
64
65 // Test if event/record is qualified
66 if (!getDolGlobalString('BLOCKEDLOG_ADD_ACTIONS_SUPPORTED') || !in_array($action, explode(',', getDolGlobalString('BLOCKEDLOG_ADD_ACTIONS_SUPPORTED')))) {
67 // If custom actions are not set or if action not into custom actions, we can exclude action if object->elementis not valid
68 $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription', 'payment_various', 'cashcontrol');
69 if (!is_object($object) || !property_exists($object, 'element') || !in_array($object->element, $listofqualifiedelement)) {
70 return 1;
71 }
72 }
73
74 dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
75
76 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
77 $b = new BlockedLog($this->db);
78 $b->loadTrackedEvents();
79
80 // Tracked events
81 if (!in_array($action, array_keys($b->trackedevents))) {
82 return 0;
83 }
84
85 // Event/record is qualified
86 $qualified = 0;
87 $amounts = 0;
88 if ($action === 'BILL_VALIDATE' || (($action === 'BILL_DELETE' || $action === 'BILL_SENTBYMAIL') && $object->statut != 0)
89 || $action === 'BILL_SUPPLIER_VALIDATE' || (($action === 'BILL_SUPPLIER_DELETE' || $action === 'BILL_SUPPLIER_SENTBYMAIL') && $object->statut != 0)
90 || $action === 'MEMBER_SUBSCRIPTION_CREATE' || $action === 'MEMBER_SUBSCRIPTION_MODIFY' || $action === 'MEMBER_SUBSCRIPTION_DELETE'
91 || $action === 'DON_VALIDATE' || (($action === 'DON_MODIFY' || $action === 'DON_DELETE') && $object->statut != 0)
92 || $action === 'CASHCONTROL_VALIDATE'
93 || (in_array($object->element, array('facture', 'supplier_invoice')) && $action === 'DOC_DOWNLOAD' && $object->statut != 0)
94 || (in_array($object->element, array('facture', 'supplier_invoice')) && $action === 'DOC_PREVIEW' && $object->statut != 0)
95 || (getDolGlobalString('BLOCKEDLOG_ADD_ACTIONS_SUPPORTED') && in_array($action, explode(',', getDolGlobalString('BLOCKEDLOG_ADD_ACTIONS_SUPPORTED'))))
96 ) {
97 $qualified++;
98
99 if (in_array($action, array(
100 'MEMBER_SUBSCRIPTION_CREATE', 'MEMBER_SUBSCRIPTION_MODIFY', 'MEMBER_SUBSCRIPTION_DELETE',
101 'DON_VALIDATE', 'DON_MODIFY', 'DON_DELETE'))) {
102 $amounts = (float) $object->amount;
103 } elseif ($action == 'CASHCONTROL_VALIDATE') {
104 $amounts = (float) $object->cash + (float) $object->cheque + (float) $object->card;
105 } elseif (property_exists($object, 'total_ttc')) {
106 $amounts = (float) $object->total_ttc;
107 }
108 }
109 /*if ($action === 'BILL_PAYED' || $action==='BILL_UNPAYED'
110 || $action === 'BILL_SUPPLIER_PAYED' || $action === 'BILL_SUPPLIER_UNPAYED')
111 {
112 $qualified++;
113 $amounts= (double) $object->total_ttc;
114 }*/
115 if ($action === 'PAYMENT_CUSTOMER_CREATE' || $action === 'PAYMENT_SUPPLIER_CREATE' || $action === 'DONATION_PAYMENT_CREATE'
116 || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') {
117 $qualified++;
118 $amounts = 0;
119 if (!empty($object->amounts)) {
120 foreach ($object->amounts as $amount) {
121 $amounts += (float) $amount;
122 }
123 } elseif (!empty($object->amount)) {
124 $amounts = $object->amount;
125 }
126 } elseif (strpos($action, 'PAYMENT') !== false && !in_array($action, array('PAYMENT_ADD_TO_BANK'))) {
127 $qualified++;
128 $amounts = (float) $object->amount;
129 }
130
131 // Another protection.
132 // May be used when event is DOC_DOWNLOAD or DOC_PREVIEW and element is not an invoice
133 if (!$qualified) {
134 return 0; // not implemented action log
135 }
136
137 // Set field date_object, ref_object, fk_object, element, object_data
138 $result = $b->setObjectData($object, $action, $amounts, $user);
139 //var_dump($b); exit;
140
141 if ($result < 0) {
142 $this->error = $b->error;
143 $this->errors = $b->errors;
144 return -1;
145 }
146
147 $res = $b->create($user);
148
149 if ($res < 0) {
150 $this->error = $b->error;
151 $this->errors = $b->errors;
152 return -1;
153 } else {
154 return 1;
155 }
156 }
157}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
Class to manage Blocked Log.
Class to stock current configuration.
Class that all triggers must inherit.
Class of triggered functions for agenda module.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called on Dolibarr payment or invoice event.
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142