.
*/
/**
* \file core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php
* \ingroup mymodule
* \brief Example trigger.
*
* Put detailed description here.
*
* \remarks You can create other triggers by copying this one.
* - File name should be either:
* - interface_99_modMyModule_MyTrigger.class.php
* - interface_99_all_MyTrigger.class.php
* - The file must stay in core/triggers
* - The class name must be InterfaceMytrigger
* - The constructor method must be named InterfaceMytrigger
* - The name property name must be MyTrigger
*/
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
// dol_include_once('/cfdimx/class/facturacfdimx.class.php');
/**
* Class of triggers for MyModule module
*/
class InterfacemodCFDIMXTriggers extends DolibarrTriggers
{
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
$this->name = preg_replace('/^Interface/i', '', get_class($this));
$this->family = "bill";
$this->description = "CFDIMX triggers.";
// 'development', 'experimental', 'dolibarr' or version
// $this->version = 'development';
// $this->picto = 'mymodule@mymodule';
}
/**
* Trigger name
*
* @return string Name of trigger file
*/
public function getName()
{
return $this->name;
}
/**
* Trigger description
*
* @return string Description of trigger file
*/
public function getDesc()
{
return $this->description;
}
/**
* Function called when a Dolibarrr business event is done.
* All functions "runTrigger" are triggered if file
* is inside directory core/triggers
*
* @param string $action Event action code
* @param CommonObject $object Object
* @param User $user Object user
* @param Translate $langs Object langs
* @param Conf $conf Object conf
* @return int <0 if KO, 0 if no triggered ran, >0 if OK
*/
public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
{
global $db;
// if (empty($conf->mymodule) || empty($conf->mymodule->enabled)) {
// return 0; // If module is not enabled, we do nothing
// }
// Put here code you want to execute when a Dolibarr business events occurs.
// Data and type of action are stored into $object and $action
// You can isolate code for each action in a separate method: this method should be named like the trigger in camelCase.
// For example : COMPANY_CREATE => public function companyCreate($action, $object, User $user, Translate $langs, Conf $conf)
// $methodName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($action)))));
// $callback = array($this, $methodName);
// if (is_callable($callback)) {
// dol_syslog(
// "Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id
// );
// return call_user_func($callback, $action, $object, $user, $langs, $conf);
// };
// Or you can execute some code here
switch ($action) {
case 'PAYMENT_CUSTOMER_CREATE':
@$moneda_cfdimx = $_REQUEST['moneda_cfdimx'];
if((int)DOL_VERSION < 15){
$moneda_cfdimx = $conf->currency;
}
dol_syslog("ID Object :: ".$object->id);
dol_syslog("moneda_cfdimx :: ".$moneda_cfdimx);
$sql_update = "UPDATE ".MAIN_DB_PREFIX."paiement_facture";
$sql_update .= " SET ";
dol_syslog("moneda_cfdimx :: ".$moneda_cfdimx);
$sql_update .= " multicurrency_code = '".$moneda_cfdimx."'";
$sql_update .= " WHERE ";
$sql_update .= " fk_paiement = ".$object->id;
if($object->id > 0 && $moneda_cfdimx != -1){
$res_update = $db->query($sql_update);
}
dol_syslog("SQL Update :: ".$sql_update);
dol_syslog(
"Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id
);
break;
// Users
//case 'USER_CREATE':
//case 'USER_MODIFY':
//case 'USER_NEW_PASSWORD':
//case 'USER_ENABLEDISABLE':
//case 'USER_DELETE':
// Actions
//case 'ACTION_MODIFY':
//case 'ACTION_CREATE':
//case 'ACTION_DELETE':
// Groups
//case 'USERGROUP_CREATE':
//case 'USERGROUP_MODIFY':
//case 'USERGROUP_DELETE':
// Companies
//case 'COMPANY_CREATE':
//case 'COMPANY_MODIFY':
//case 'COMPANY_DELETE':
// Contacts
//case 'CONTACT_CREATE':
//case 'CONTACT_MODIFY':
//case 'CONTACT_DELETE':
//case 'CONTACT_ENABLEDISABLE':
// Products
//case 'PRODUCT_CREATE':
//case 'PRODUCT_MODIFY':
//case 'PRODUCT_DELETE':
//case 'PRODUCT_PRICE_MODIFY':
//case 'PRODUCT_SET_MULTILANGS':
//case 'PRODUCT_DEL_MULTILANGS':
//Stock mouvement
//case 'STOCK_MOVEMENT':
//MYECMDIR
//case 'MYECMDIR_CREATE':
//case 'MYECMDIR_MODIFY':
//case 'MYECMDIR_DELETE':
// Customer orders
//case 'ORDER_CREATE':
//case 'ORDER_MODIFY':
//case 'ORDER_VALIDATE':
//case 'ORDER_DELETE':
//case 'ORDER_CANCEL':
//case 'ORDER_SENTBYMAIL':
//case 'ORDER_CLASSIFY_BILLED':
//case 'ORDER_SETDRAFT':
//case 'LINEORDER_INSERT':
//case 'LINEORDER_UPDATE':
//case 'LINEORDER_DELETE':
// Supplier orders
//case 'ORDER_SUPPLIER_CREATE':
//case 'ORDER_SUPPLIER_MODIFY':
//case 'ORDER_SUPPLIER_VALIDATE':
//case 'ORDER_SUPPLIER_DELETE':
//case 'ORDER_SUPPLIER_APPROVE':
//case 'ORDER_SUPPLIER_REFUSE':
//case 'ORDER_SUPPLIER_CANCEL':
//case 'ORDER_SUPPLIER_SENTBYMAIL':
//case 'ORDER_SUPPLIER_DISPATCH':
//case 'LINEORDER_SUPPLIER_DISPATCH':
//case 'LINEORDER_SUPPLIER_CREATE':
//case 'LINEORDER_SUPPLIER_UPDATE':
//case 'LINEORDER_SUPPLIER_DELETE':
// Proposals
//case 'PROPAL_CREATE':
//case 'PROPAL_MODIFY':
//case 'PROPAL_VALIDATE':
//case 'PROPAL_SENTBYMAIL':
//case 'PROPAL_CLOSE_SIGNED':
//case 'PROPAL_CLOSE_REFUSED':
//case 'PROPAL_DELETE':
//case 'LINEPROPAL_INSERT':
//case 'LINEPROPAL_UPDATE':
//case 'LINEPROPAL_DELETE':
// SupplierProposal
//case 'SUPPLIER_PROPOSAL_CREATE':
//case 'SUPPLIER_PROPOSAL_MODIFY':
//case 'SUPPLIER_PROPOSAL_VALIDATE':
//case 'SUPPLIER_PROPOSAL_SENTBYMAIL':
//case 'SUPPLIER_PROPOSAL_CLOSE_SIGNED':
//case 'SUPPLIER_PROPOSAL_CLOSE_REFUSED':
//case 'SUPPLIER_PROPOSAL_DELETE':
//case 'LINESUPPLIER_PROPOSAL_INSERT':
//case 'LINESUPPLIER_PROPOSAL_UPDATE':
//case 'LINESUPPLIER_PROPOSAL_DELETE':
// Contracts
//case 'CONTRACT_CREATE':
//case 'CONTRACT_MODIFY':
//case 'CONTRACT_ACTIVATE':
//case 'CONTRACT_CANCEL':
//case 'CONTRACT_CLOSE':
//case 'CONTRACT_DELETE':
//case 'LINECONTRACT_INSERT':
//case 'LINECONTRACT_UPDATE':
//case 'LINECONTRACT_DELETE':
// Bills
case 'BILL_CREATE':
// print 'action::'.$action.':
';
// print '
'; // print_r($_REQUEST); // print ''; // $object->errors[] = "triggers BILL_CREATE"; // return -1; break; case 'BILL_MODIFY': break; case 'BILL_VALIDATE': $object->cond_reglement_id = GETPOST("condicionespago"); // $res = $object->update($user); // $res = $object->validate($user); // $object->errors[] = "triggers BILL_VALIDATE"; // print '
'; // print_r($_REQUEST); // print ''; // return -1; break; case 'BILL_UNVALIDATE': break; //case 'BILL_SENTBYMAIL': //case 'BILL_CANCEL': //case 'BILL_DELETE': //case 'BILL_PAYED': case 'BILL_UNPAYED': if($conf->cfdimx->enabled){ // $fac = new FacturaCFDI($db); // $uuid = $fac->getUUID($object->id); $uuid = null; $sql = "SELECT * FROM ".MAIN_DB_PREFIX."cfdimx WHERE fk_facture = ". $object->id." LIMIT 1"; $resql = $this->db->query($sql); if($resql){ $num = $this->db->num_rows($resql); if($num > 0){ $obj = $this->db->fetch_object($resql); $uuid = $obj->uuid; } } if(!is_null($uuid)){ $object->errors[] = "Error: No se puede ".$langs->trans('ReOpen')." la Factura porque cuenta con un Timbre Fiscal (".$uuid.")"; // return -1; } } break; case 'LINEBILL_INSERT': // if($user->admin){ // } // $object->errors[] = "TASA SEL ::".$object->tva_tx; // $object->errors[] = $object->socid; // print '
'; // print_r($object); // print ''; // return -1; break; //case 'LINEBILL_UPDATE': //case 'LINEBILL_DELETE': //Supplier Bill //case 'BILL_SUPPLIER_CREATE': //case 'BILL_SUPPLIER_UPDATE': //case 'BILL_SUPPLIER_DELETE': //case 'BILL_SUPPLIER_PAYED': //case 'BILL_SUPPLIER_UNPAYED': //case 'BILL_SUPPLIER_VALIDATE': //case 'BILL_SUPPLIER_UNVALIDATE': //case 'LINEBILL_SUPPLIER_CREATE': //case 'LINEBILL_SUPPLIER_UPDATE': //case 'LINEBILL_SUPPLIER_DELETE': // Payments //case 'PAYMENT_CUSTOMER_CREATE': //case 'PAYMENT_SUPPLIER_CREATE': //case 'PAYMENT_ADD_TO_BANK': //case 'PAYMENT_DELETE': // Online //case 'PAYMENT_PAYBOX_OK': //case 'PAYMENT_PAYPAL_OK': //case 'PAYMENT_STRIPE_OK': // Donation //case 'DON_CREATE': //case 'DON_UPDATE': //case 'DON_DELETE': // Interventions //case 'FICHINTER_CREATE': //case 'FICHINTER_MODIFY': //case 'FICHINTER_VALIDATE': //case 'FICHINTER_DELETE': //case 'LINEFICHINTER_CREATE': //case 'LINEFICHINTER_UPDATE': //case 'LINEFICHINTER_DELETE': // Members //case 'MEMBER_CREATE': //case 'MEMBER_VALIDATE': //case 'MEMBER_SUBSCRIPTION': //case 'MEMBER_MODIFY': //case 'MEMBER_NEW_PASSWORD': //case 'MEMBER_RESILIATE': //case 'MEMBER_DELETE': // Categories //case 'CATEGORY_CREATE': //case 'CATEGORY_MODIFY': //case 'CATEGORY_DELETE': //case 'CATEGORY_SET_MULTILANGS': // Projects //case 'PROJECT_CREATE': //case 'PROJECT_MODIFY': //case 'PROJECT_DELETE': // Project tasks //case 'TASK_CREATE': //case 'TASK_MODIFY': //case 'TASK_DELETE': // Task time spent //case 'TASK_TIMESPENT_CREATE': //case 'TASK_TIMESPENT_MODIFY': //case 'TASK_TIMESPENT_DELETE': //case 'PROJECT_ADD_CONTACT': //case 'PROJECT_DELETE_CONTACT': //case 'PROJECT_DELETE_RESOURCE': // Shipping //case 'SHIPPING_CREATE': //case 'SHIPPING_MODIFY': //case 'SHIPPING_VALIDATE': //case 'SHIPPING_SENTBYMAIL': //case 'SHIPPING_BILLED': //case 'SHIPPING_CLOSED': //case 'SHIPPING_REOPEN': //case 'SHIPPING_DELETE': // and more... default: dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); break; } return 0; } }