Save cash fence event into unalterable log

This commit is contained in:
Laurent Destailleur 2018-12-17 11:41:59 +01:00
parent 1979e3238c
commit 6b5c0d1ea1
4 changed files with 102 additions and 81 deletions

View File

@ -274,6 +274,17 @@ class BlockedLog
$this->error++; $this->error++;
} }
} }
else if($this->element === 'cashcontrol') {
require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
$object = new CashControl($this->db);
if ($object->fetch($this->fk_object)>0) {
return $object->getNomUrl(1);
}
else{
$this->error++;
}
}
else if ($this->action == 'MODULE_SET') else if ($this->action == 'MODULE_SET')
{ {
return '<i class="opacitymedium">System to track events into unalterable logs were enabled</i>'; return '<i class="opacitymedium">System to track events into unalterable logs were enabled</i>';
@ -355,6 +366,10 @@ class BlockedLog
{ {
$this->date_object = $object->dateh; $this->date_object = $object->dateh;
} }
elseif ($object->element=='cashcontrol')
{
$this->date_object = $object->date_creation;
}
else { else {
$this->date_object = $object->date; $this->date_object = $object->date;
} }
@ -368,7 +383,12 @@ class BlockedLog
// Set object_data // Set object_data
$this->object_data=new stdClass(); $this->object_data=new stdClass();
$arrayoffieldstoexclude = array('table_element','fields','ref_previous','ref_next','origin','origin_id','oldcopy','picto','error','modelpdf','table_element_line','linkedObjectsIds','linkedObjects','fk_delivery_address'); $arrayoffieldstoexclude = array(
'table_element','fields','ref_previous','ref_next','origin','origin_id','oldcopy','picto','error','errors','modelpdf',
'table_element_line','ismultientitymanaged','isextrafieldmanaged',
'linkedObjectsIds','linkedObjects','fk_delivery_address',
'context'
);
// Add thirdparty info // Add thirdparty info
if (empty($object->thirdparty) && method_exists($object, 'fetch_thirdparty')) $object->fetch_thirdparty(); if (empty($object->thirdparty) && method_exists($object, 'fetch_thirdparty')) $object->fetch_thirdparty();

View File

@ -141,12 +141,17 @@ elseif ($action=="add")
if ($action=="close") if ($action=="close")
{ {
$object->id=$id; $object->fetch($id);
$result = $object->valid($user); $result = $object->valid($user);
if ($result <= 0) if ($result <= 0)
{ {
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
else
{
setEventMessages($langs->trans("CashFenceDone"), null);
}
$action="view"; $action="view";
} }
@ -284,6 +289,11 @@ if (empty($action) || $action=="view")
llxHeader('', $langs->trans("CashControl")); llxHeader('', $langs->trans("CashControl"));
$head=array();
$head[0][0] = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$object->id;
$head[0][1] = $langs->trans("Card");
$head[0][2] = 'cashcontrol';
dol_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'cashcontrol'); dol_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'cashcontrol');
$linkback = '<a href="' . DOL_URL_ROOT . '/compta/cashcontrol/cashcontrol_list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>'; $linkback = '<a href="' . DOL_URL_ROOT . '/compta/cashcontrol/cashcontrol_list.php?restore_lastsearch_values=1">' . $langs->trans("BackToList") . '</a>';
@ -299,7 +309,7 @@ if (empty($action) || $action=="view")
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield" width="100%">'; print '<table class="border tableforfield" width="100%">';
print '<tr><td class="tdfieldcreate nowrap">'; print '<tr><td class="titlefield nowrap">';
print $langs->trans("Ref"); print $langs->trans("Ref");
print '</td><td>'; print '</td><td>';
print $id; print $id;
@ -309,8 +319,8 @@ if (empty($action) || $action=="view")
print $object->posmodule; print $object->posmodule;
print "</td></tr>"; print "</td></tr>";
print '<tr><td valign="middle">'.$langs->trans("InitialBankBalance").'</td><td>'; print '<tr><td valign="middle">'.$langs->trans("CashDesk").' ID</td><td>';
print price($object->opening); print $object->posnumber;
print "</td></tr>"; print "</td></tr>";
print '<tr><td class="nowrap">'; print '<tr><td class="nowrap">';
@ -326,16 +336,27 @@ if (empty($action) || $action=="view")
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border tableforfield" width="100%">'; print '<table class="border tableforfield" width="100%">';
print '<tr><td class="nowrap">'; print '<tr><td class="titlefield nowrap">';
print $langs->trans("DateCreationShort"); print $langs->trans("DateCreationShort");
print '</td><td>'; print '</td><td>';
print dol_print_date($object->date_creation, 'dayhour'); print dol_print_date($object->date_creation, 'dayhour');
print '</td></tr>'; print '</td></tr>';
print '<tr><td valign="middle">'.$langs->trans("CashDesk").' ID</td><td>'; print '<tr><td valign="middle">'.$langs->trans("InitialBankBalance").'</td><td>';
print $object->posnumber; print price($object->opening, 0, $langs, 1, -1, -1, $conf->currency);
print "</td></tr>"; print "</td></tr>";
print '<tr><td valign="middle">'.$langs->trans("Cash").'</td><td>';
print price($object->cash, 0, $langs, 1, -1, -1, $conf->currency);
print "</td></tr>";
print '<tr><td valign="middle">'.$langs->trans("Cheque").'</td><td>';
print price($object->cheque, 0, $langs, 1, -1, -1, $conf->currency);
print "</td></tr>";
print '<tr><td valign="middle">'.$langs->trans("Card").'</td><td>';
print price($object->card, 0, $langs, 1, -1, -1, $conf->currency);
print "</td></tr>";
print "</table>\n"; print "</table>\n";
print '</div>'; print '</div>';
print '</div></div>'; print '</div></div>';

View File

@ -32,7 +32,7 @@ class CashControl extends CommonObject
/** /**
* @var string ID to identify managed object * @var string ID to identify managed object
*/ */
public $element = 'CashControl'; public $element = 'cashcontrol';
/** /**
* @var string Name of table without prefix where object is stored * @var string Name of table without prefix where object is stored
@ -68,7 +68,8 @@ class CashControl extends CommonObject
'year_close' =>array('type'=>'integer', 'label'=>'Year close', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>50), 'year_close' =>array('type'=>'integer', 'label'=>'Year close', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>50),
'month_close' =>array('type'=>'integer', 'label'=>'Month close', 'enabled'=>1, 'visible'=>1, 'position'=>55), 'month_close' =>array('type'=>'integer', 'label'=>'Month close', 'enabled'=>1, 'visible'=>1, 'position'=>55),
'day_close' =>array('type'=>'integer', 'label'=>'Day close', 'enabled'=>1, 'visible'=>1, 'position'=>60), 'day_close' =>array('type'=>'integer', 'label'=>'Day close', 'enabled'=>1, 'visible'=>1, 'position'=>60),
'date_creation' =>array('type'=>'datetime', 'label'=>'Date creation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500), 'date_valid' =>array('type'=>'datetime', 'label'=>'DateValid', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>490),
'date_creation' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500),
'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>505), 'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>505),
'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>0, 'position'=>510), 'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>0, 'position'=>510),
'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Validated')), 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Validated')),
@ -77,7 +78,6 @@ class CashControl extends CommonObject
public $id; public $id;
public $opening; public $opening;
public $status; public $status;
public $date_creation;
public $year_close; public $year_close;
public $month_close; public $month_close;
public $day_close; public $day_close;
@ -86,6 +86,9 @@ class CashControl extends CommonObject
public $cash; public $cash;
public $cheque; public $cheque;
public $card; public $card;
public $date_valid;
public $date_creation;
public $date_modification;
const STATUS_DRAFT = 0; const STATUS_DRAFT = 0;
const STATUS_VALIDATED = 1; const STATUS_VALIDATED = 1;
@ -231,13 +234,13 @@ class CashControl extends CommonObject
} }
if (!$error) { if (!$error) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."pos_cash_fence"); $this->status = self::STATUS_VALIDATED;
$this->date_valid = $now;
$this->fk_user_valid = $user->id;
} }
if (! $error && ! $notrigger) if (! $error && ! $notrigger)
{ {
$this->context=array('date_valid'=>$now);
// Call trigger // Call trigger
$result=$this->call_trigger('CASHCONTROL_VALIDATE', $user); $result=$this->call_trigger('CASHCONTROL_VALIDATE', $user);
if ($result < 0) $error++; if ($result < 0) $error++;
@ -260,47 +263,19 @@ class CashControl extends CommonObject
/** /**
* Load object in memory from database * Load object in memory from the database
* *
* @param int $id Id object * @param int $id Id object
* @return int <0 if KO, >0 if OK * @param string $ref Ref
* @return int <0 if KO, 0 if not found, >0 if OK
*/ */
public function fetch($id) public function fetch($id, $ref = null)
{ {
global $conf; $result = $this->fetchCommon($id, $ref);
if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
$sql = "SELECT"; return $result;
$sql .= " *";
$sql .= " FROM ".MAIN_DB_PREFIX."pos_cash_fence";
$sql .= " WHERE rowid = ".$id;
$sql .= " AND entity = ".$conf->entity;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql)) {
$obj = $this->db->fetch_object($resql);
$this->ref = $obj->id;
$this->label = $obj->label;
$this->opening = $obj->opening;
$this->status = $obj->status;
$this->year_close = $obj->year_close;
$this->month_close = $obj->month_close;
$this->day_close = $obj->day_close;
$this->posmodule = $obj->posmodule;
$this->posnumber = $obj->posnumber;
$this->date_creation = $obj->date_creation;
$this->tms = $obj->tms;
$this->id=$id;
} }
$this->db->free($resql);
return 1;
} else {
$this->error = "Error ".$this->db->lasterror();
return -1;
}
}
/** /**
* Return label of the status * Return label of the status

View File

@ -59,7 +59,7 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
if (empty($conf->blockedlog->enabled)) return 0; // Module not active, we do nothing if (empty($conf->blockedlog->enabled)) return 0; // Module not active, we do nothing
// Test if event/record is qualified // Test if event/record is qualified
$listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription','payment_various'); $listofqualifiedelement = array('facture', 'don', 'payment', 'payment_donation', 'subscription', 'payment_various', 'cashcontrol');
if (! in_array($object->element, $listofqualifiedelement)) return 1; if (! in_array($object->element, $listofqualifiedelement)) return 1;
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
@ -80,6 +80,7 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
|| $action==='BILL_SUPPLIER_VALIDATE' || $action==='BILL_SUPPLIER_DELETE' || $action === 'BILL_SUPPLIER_SENTBYMAIL' || $action==='BILL_SUPPLIER_VALIDATE' || $action==='BILL_SUPPLIER_DELETE' || $action === 'BILL_SUPPLIER_SENTBYMAIL'
|| $action==='MEMBER_SUBSCRIPTION_CREATE' || $action==='MEMBER_SUBSCRIPTION_MODIFY' || $action==='MEMBER_SUBSCRIPTION_DELETE' || $action==='MEMBER_SUBSCRIPTION_CREATE' || $action==='MEMBER_SUBSCRIPTION_MODIFY' || $action==='MEMBER_SUBSCRIPTION_DELETE'
|| $action==='DON_VALIDATE' || $action==='DON_MODIFY' || $action==='DON_DELETE' || $action==='DON_VALIDATE' || $action==='DON_MODIFY' || $action==='DON_DELETE'
|| $action==='CASHCONTROL_VALIDATE'
|| (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_DOWNLOAD') || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_PREVIEW') || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_DOWNLOAD') || (in_array($object->element, array('facture','suplier_invoice')) && $action === 'DOC_PREVIEW')
) )
{ {
@ -88,6 +89,10 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
if (in_array($action, array( if (in_array($action, array(
'MEMBER_SUBSCRIPTION_CREATE','MEMBER_SUBSCRIPTION_MODIFY','MEMBER_SUBSCRIPTION_DELETE', 'MEMBER_SUBSCRIPTION_CREATE','MEMBER_SUBSCRIPTION_MODIFY','MEMBER_SUBSCRIPTION_DELETE',
'DON_VALIDATE','DON_MODIFY','DON_DELETE'))) $amounts = (double) $object->amount; 'DON_VALIDATE','DON_MODIFY','DON_DELETE'))) $amounts = (double) $object->amount;
elseif ($action == 'CASHCONTROL_VALIDATE')
{
$amounts = (double) $object->cash + (double) $object->cheque + (double) $object->card;
}
else $amounts = (double) $object->total_ttc; else $amounts = (double) $object->total_ttc;
} }
/*if ($action === 'BILL_PAYED' || $action==='BILL_UNPAYED' /*if ($action === 'BILL_PAYED' || $action==='BILL_UNPAYED'
@ -103,7 +108,7 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
$amounts = 0; $amounts = 0;
if(!empty($object->amounts)) { if(!empty($object->amounts)) {
foreach($object->amounts as $amount) { foreach($object->amounts as $amount) {
$amounts+= price2num($amount); $amounts += price2num($amount);
} }
} }
} }