From cbb5e3bbe9ae7c45858d303958b074ed344e7843 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 17 Dec 2018 03:31:20 +0100 Subject: [PATCH 1/4] Better translation --- htdocs/langs/en_US/stocks.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index fbbc00887aa..70f83dbab94 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -53,7 +53,7 @@ PMPValue=Weighted average price PMPValueShort=WAP EnhancedValueOfWarehouses=Warehouses value UserWarehouseAutoCreate=Create a user warehouse automatically when creating a user -AllowAddLimitStockByWarehouse=Allow to add limit and desired stock per couple (product, warehouse) instead of per product +AllowAddLimitStockByWarehouse=Manage also values for minimum and desired stock per couple (product, warehouse) in addition to values per product IndependantSubProductStock=Product stock and subproduct stock are independent QtyDispatched=Quantity dispatched QtyDispatchedShort=Qty dispatched From e06b06c788d7ccc683dbfa74971ab80c9a34918d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 17 Dec 2018 10:37:56 +0100 Subject: [PATCH 2/4] Work on cash fence --- htdocs/blockedlog/class/blockedlog.class.php | 4 + .../compta/cashcontrol/cashcontrol_card.php | 92 ++++++++++++------- .../cashcontrol/class/cashcontrol.class.php | 66 ++++++++++++- htdocs/langs/en_US/blockedlog.lang | 5 +- 4 files changed, 131 insertions(+), 36 deletions(-) diff --git a/htdocs/blockedlog/class/blockedlog.class.php b/htdocs/blockedlog/class/blockedlog.class.php index 46766277669..aeb71fc6e95 100644 --- a/htdocs/blockedlog/class/blockedlog.class.php +++ b/htdocs/blockedlog/class/blockedlog.class.php @@ -172,6 +172,10 @@ class BlockedLog if ($conf->banque->enabled) $this->trackedevents['PAYMENT_VARIOUS_CREATE']='logPAYMENT_VARIOUS_CREATE'; if ($conf->banque->enabled) $this->trackedevents['PAYMENT_VARIOUS_MODIFY']='logPAYMENT_VARIOUS_MODIFY'; if ($conf->banque->enabled) $this->trackedevents['PAYMENT_VARIOUS_DELETE']='logPAYMENT_VARIOUS_DELETE'; + + // $conf->global->BANK_ENABLE_POS_CASHCONTROL must be set to 1 by all POS modules + $moduleposenabled = ($conf->cashdesk->enabled || $conf->takepos->enabled || ! empty($conf->global->BANK_ENABLE_POS_CASHCONTROL)); + if ($moduleposenabled) $this->trackedevents['CASHCONTROL_VALIDATE']='logCASHCONTROL_VALIDATE'; } /** diff --git a/htdocs/compta/cashcontrol/cashcontrol_card.php b/htdocs/compta/cashcontrol/cashcontrol_card.php index e212f8ff75b..8a122a3f939 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_card.php +++ b/htdocs/compta/cashcontrol/cashcontrol_card.php @@ -32,8 +32,9 @@ require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php' $langs->loadLangs(array("cashcontrol","install","cashdesk","admin","banks")); -$action=GETPOST('action','aZ09'); $id=GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action=GETPOST('action','aZ09'); $categid = GETPOST('categid'); $label = GETPOST("label"); @@ -47,9 +48,10 @@ if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortfield) $sortfield='b.label'; +if (! $sortfield) $sortfield='rowid'; if (! $sortorder) $sortorder='ASC'; +// Security check if (! $user->rights->cashdesk->use && ! $user->rights->takepos->use) { accessforbidden(); @@ -62,8 +64,14 @@ if (! empty($conf->cashdesk->enabled)) $arrayofposavailable['cashdesk']=$langs-> if (! empty($conf->takepos->enabled)) $arrayofposavailable['takepos']=$langs->trans('TakePOS').' (takepos)'; // TODO Add hook here to allow other POS to add themself -$cashcontrol= new CashControl($db); +$object= new CashControl($db); +$extrafields = new ExtraFields($db); +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('cashcontrolcard','globalcard')); /* @@ -111,21 +119,21 @@ elseif ($action=="add") } else { - $cashcontrol->$key = price2num(GETPOST($key,'alpha')); + $object->$key = price2num(GETPOST($key,'alpha')); } } if (! $error) { - $cashcontrol->day_close = GETPOST('closeday', 'int'); - $cashcontrol->month_close = GETPOST('closemonth', 'int'); - $cashcontrol->year_close = GETPOST('closeyear', 'int'); + $object->day_close = GETPOST('closeday', 'int'); + $object->month_close = GETPOST('closemonth', 'int'); + $object->year_close = GETPOST('closeyear', 'int'); - $cashcontrol->opening=price2num(GETPOST('opening','alpha')); - $cashcontrol->posmodule=GETPOST('posmodule','alpha'); - $cashcontrol->posnumber=GETPOST('posnumber','alpha'); + $object->opening=price2num(GETPOST('opening','alpha')); + $object->posmodule=GETPOST('posmodule','alpha'); + $object->posnumber=GETPOST('posnumber','alpha'); - $id=$cashcontrol->create($user); + $id=$object->create($user); $action="view"; } @@ -133,12 +141,24 @@ elseif ($action=="add") if ($action=="close") { - $cashcontrol= new CashControl($db); - $cashcontrol->id=$id; - $cashcontrol->valid($user); - $action="view"; + $object->id=$id; + $result = $object->valid($user); + if ($result <= 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + } + + $action="view"; } + + +/* + * View + */ + +$form=new Form($db); + if ($action=="create" || $action=="start") { llxHeader(); @@ -260,10 +280,20 @@ if ($action=="create" || $action=="start") if (empty($action) || $action=="view") { - $cashcontrol= new CashControl($db); - $cashcontrol->fetch($id); - llxHeader(); - print load_fiche_titre($langs->trans("CashControl"), '', 'title_bank.png'); + $object->fetch($id); + + llxHeader('', $langs->trans("CashControl")); + + dol_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'cashcontrol'); + + $linkback = '' . $langs->trans("BackToList") . ''; + + $morehtmlref='
'; + $morehtmlref.='
'; + + + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref); + print '
'; print '
'; print '
'; @@ -276,24 +306,17 @@ if (empty($action) || $action=="view") print ''; print ''.$langs->trans("Module").''; - print $cashcontrol->posmodule; + print $object->posmodule; print ""; print ''.$langs->trans("InitialBankBalance").''; - print price($cashcontrol->opening); + print price($object->opening); print ""; print ''; - print $langs->trans("DateEnd"); + print $langs->trans("Period"); print ''; - print $cashcontrol->year_close."-".$cashcontrol->month_close."-".$cashcontrol->day_close; - print ''; - - print ''; - print $langs->trans("Status"); - print ''; - if ($cashcontrol->status==1) print $langs->trans("Opened"); - if ($cashcontrol->status==2) print $langs->trans("Closed"); + print $object->year_close."-".$object->month_close."-".$object->day_close; print ''; print ''; @@ -306,11 +329,11 @@ if (empty($action) || $action=="view") print ''; print $langs->trans("DateCreationShort"); print ''; - print dol_print_date($cashcontrol->date_creation, 'dayhour'); + print dol_print_date($object->date_creation, 'dayhour'); print ''; print ''.$langs->trans("CashDesk").' ID'; - print $cashcontrol->posnumber; + print $object->posnumber; print ""; print "\n"; @@ -322,7 +345,10 @@ if (empty($action) || $action=="view") print '
'; print ''; - if ($cashcontrol->status==1) print ''; + if ($object->status == CashControl::STATUS_DRAFT) + { + print ''; + } print '
'; print '
'; diff --git a/htdocs/compta/cashcontrol/class/cashcontrol.class.php b/htdocs/compta/cashcontrol/class/cashcontrol.class.php index 37f73f6712f..fc83239ea70 100644 --- a/htdocs/compta/cashcontrol/class/cashcontrol.class.php +++ b/htdocs/compta/cashcontrol/class/cashcontrol.class.php @@ -88,7 +88,7 @@ class CashControl extends CommonObject public $card; const STATUS_DRAFT = 0; - const STATUS_VALIDATE = 1; + const STATUS_VALIDATED = 1; /** @@ -302,6 +302,70 @@ class CashControl extends CommonObject } } + /** + * Return label of the status + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status + */ + public function getLibStatut($mode=0) + { + return $this->LibStatut($this->status, $mode); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return the status + * + * @param int $status Id status + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status + */ + public function LibStatut($status, $mode=0) + { + // phpcs:enable + if (empty($this->labelstatus)) + { + global $langs; + //$langs->load("mymodule"); + $this->labelstatus[0] = $langs->trans('Draft'); + $this->labelstatus[1] = $langs->trans('Closed'); + } + + if ($mode == 0) + { + return $this->labelstatus[$status]; + } + elseif ($mode == 1) + { + return $this->labelstatus[$status]; + } + elseif ($mode == 2) + { + if ($status == 1) return img_picto($this->labelstatus[$status],'statut6', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelstatus[$status]; + elseif ($status == 0) return img_picto($this->labelstatus[$status],'statut0', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelstatus[$status]; + } + elseif ($mode == 3) + { + if ($status == 1) return img_picto($this->labelstatus[$status],'statut6', '', false, 0, 0, '', 'valignmiddle'); + elseif ($status == 0) return img_picto($this->labelstatus[$status],'statut0', '', false, 0, 0, '', 'valignmiddle'); + } + elseif ($mode == 4) + { + if ($status == 1) return img_picto($this->labelstatus[$status],'statut6', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelstatus[$status]; + elseif ($status == 0) return img_picto($this->labelstatus[$status],'statut0', '', false, 0, 0, '', 'valignmiddle').' '.$this->labelstatus[$status]; + } + elseif ($mode == 5) + { + if ($status == 1) return $this->labelstatus[$status].' '.img_picto($this->labelstatus[$status],'statut6', '', false, 0, 0, '', 'valignmiddle'); + elseif ($status == 0) return $this->labelstatus[$status].' '.img_picto($this->labelstatus[$status],'statut0', '', false, 0, 0, '', 'valignmiddle'); + } + elseif ($mode == 6) + { + if ($status == 1) return $this->labelstatus[$status].' '.img_picto($this->labelstatus[$status],'statut6', '', false, 0, 0, '', 'valignmiddle'); + elseif ($status == 0) return $this->labelstatus[$status].' '.img_picto($this->labelstatus[$status],'statut0', '', false, 0, 0, '', 'valignmiddle'); + } + } /** * Return clicable link of object (with eventually picto) diff --git a/htdocs/langs/en_US/blockedlog.lang b/htdocs/langs/en_US/blockedlog.lang index 88d3662be9c..0dac5a6fd8c 100644 --- a/htdocs/langs/en_US/blockedlog.lang +++ b/htdocs/langs/en_US/blockedlog.lang @@ -8,8 +8,8 @@ BrowseBlockedLog=Unalterable logs ShowAllFingerPrintsMightBeTooLong=Show all archived logs (might be long) ShowAllFingerPrintsErrorsMightBeTooLong=Show all non-valid archive logs (might be long) DownloadBlockChain=Download fingerprints -KoCheckFingerprintValidity=Archived log is not valid. It means someone (a hacker?) has modified some data of this archived log after it was recorded, or has erased the previous archived record (check that line with previous # exists). -OkCheckFingerprintValidity=Archived log is valid. It means all data on this line were not modified and record follow the previous one. +KoCheckFingerprintValidity=Archived log record is not valid. It means someone (a hacker?) has modified some data of this archived log record after it was recorded, or has erased the previous archived record (check that line with previous # exists). +OkCheckFingerprintValidity=Archived log record is valid. It means all data on this line were not modified and record follow the previous one. OkCheckFingerprintValidityButChainIsKo=Archived log seems valid compared to previous one but the chain was corrupted previously. AddedByAuthority=Stored into remote authority NotAddedByAuthorityYet=Not yet stored into remote authority @@ -35,6 +35,7 @@ logDON_DELETE=Donation logical deletion logMEMBER_SUBSCRIPTION_CREATE=Member subscription created logMEMBER_SUBSCRIPTION_MODIFY=Member subscription modified logMEMBER_SUBSCRIPTION_DELETE=Member subscription logical deletion +logCASHCONTROL_VALIDATE=Cash fence recording BlockedLogBillDownload=Customer invoice download BlockedLogBillPreview=Customer invoice preview BlockedlogInfoDialog=Log Details From 1979e3238c32813384e33d755ba4bcf38922006f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 17 Dec 2018 10:42:30 +0100 Subject: [PATCH 3/4] Fix rounding --- htdocs/expensereport/card.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 082cccc6868..b5e8ed8151e 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -1953,13 +1953,14 @@ else $totalpaid += $objp->amount; $i++; } + $totalpaid = price2num($totalpaid); // Round $totalpaid to fix floating problem after addition into loop if ($object->paid == 0) { print ''.$langs->trans("AlreadyPaid").':'.price($totalpaid).''; print ''.$langs->trans("AmountExpected").':'.price($object->total_ttc).''; - $remaintopay = $object->total_ttc - $totalpaid; + $remaintopay = price2num($object->total_ttc - $totalpaid); print ''.$langs->trans("RemainderToPay").':'; print ''.price($remaintopay).''; From 6b5c0d1ea1fc2a0b73318ac96f3e43fb10edfab7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 17 Dec 2018 11:41:59 +0100 Subject: [PATCH 4/4] Save cash fence event into unalterable log --- htdocs/blockedlog/class/blockedlog.class.php | 22 +++- .../compta/cashcontrol/cashcontrol_card.php | 35 ++++-- .../cashcontrol/class/cashcontrol.class.php | 115 +++++++----------- ..._modBlockedlog_ActionsBlockedLog.class.php | 11 +- 4 files changed, 102 insertions(+), 81 deletions(-) diff --git a/htdocs/blockedlog/class/blockedlog.class.php b/htdocs/blockedlog/class/blockedlog.class.php index aeb71fc6e95..cb36c4cd4f7 100644 --- a/htdocs/blockedlog/class/blockedlog.class.php +++ b/htdocs/blockedlog/class/blockedlog.class.php @@ -274,6 +274,17 @@ class BlockedLog $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') { return 'System to track events into unalterable logs were enabled'; @@ -355,6 +366,10 @@ class BlockedLog { $this->date_object = $object->dateh; } + elseif ($object->element=='cashcontrol') + { + $this->date_object = $object->date_creation; + } else { $this->date_object = $object->date; } @@ -368,7 +383,12 @@ class BlockedLog // Set object_data $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 if (empty($object->thirdparty) && method_exists($object, 'fetch_thirdparty')) $object->fetch_thirdparty(); diff --git a/htdocs/compta/cashcontrol/cashcontrol_card.php b/htdocs/compta/cashcontrol/cashcontrol_card.php index 8a122a3f939..11c86e53af3 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_card.php +++ b/htdocs/compta/cashcontrol/cashcontrol_card.php @@ -141,12 +141,17 @@ elseif ($action=="add") if ($action=="close") { - $object->id=$id; + $object->fetch($id); + $result = $object->valid($user); if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); } + else + { + setEventMessages($langs->trans("CashFenceDone"), null); + } $action="view"; } @@ -284,6 +289,11 @@ if (empty($action) || $action=="view") 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'); $linkback = '' . $langs->trans("BackToList") . ''; @@ -299,7 +309,7 @@ if (empty($action) || $action=="view") print '
'; print ''; - print '"; - print '"; print '
'; + print '
'; print $langs->trans("Ref"); print ''; print $id; @@ -309,8 +319,8 @@ if (empty($action) || $action=="view") print $object->posmodule; print "
'.$langs->trans("InitialBankBalance").''; - print price($object->opening); + print '
'.$langs->trans("CashDesk").' ID'; + print $object->posnumber; print "
'; @@ -326,15 +336,26 @@ if (empty($action) || $action=="view") print '
'; print ''; - print ''; - print '"; + + print '"; + print '"; + print '"; + print "
'; + print '
'; print $langs->trans("DateCreationShort"); print ''; print dol_print_date($object->date_creation, 'dayhour'); print '
'.$langs->trans("CashDesk").' ID'; - print $object->posnumber; + print '
'.$langs->trans("InitialBankBalance").''; + print price($object->opening, 0, $langs, 1, -1, -1, $conf->currency); + print "
'.$langs->trans("Cash").''; + print price($object->cash, 0, $langs, 1, -1, -1, $conf->currency); print "
'.$langs->trans("Cheque").''; + print price($object->cheque, 0, $langs, 1, -1, -1, $conf->currency); + print "
'.$langs->trans("Card").''; + print price($object->card, 0, $langs, 1, -1, -1, $conf->currency); + print "
\n"; print ''; diff --git a/htdocs/compta/cashcontrol/class/cashcontrol.class.php b/htdocs/compta/cashcontrol/class/cashcontrol.class.php index fc83239ea70..0acb9c0dd82 100644 --- a/htdocs/compta/cashcontrol/class/cashcontrol.class.php +++ b/htdocs/compta/cashcontrol/class/cashcontrol.class.php @@ -32,7 +32,7 @@ class CashControl extends CommonObject /** * @var string ID to identify managed object */ - public $element = 'CashControl'; + public $element = 'cashcontrol'; /** * @var string Name of table without prefix where object is stored @@ -55,29 +55,29 @@ class CashControl extends CommonObject public $picto = 'bank'; public $fields=array( - 'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>10), - 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>15), - 'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>18), - 'posmodule' =>array('type'=>'varchar(30)', 'label'=>'Module', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>19), - 'posnumber' =>array('type'=>'varchar(30)', 'label'=>'CashDesk', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>20), - 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>0, 'position'=>24), - 'opening' =>array('type'=>'double(24,8)', 'label'=>'Opening', 'enabled'=>1, 'visible'=>1, 'position'=>25), - 'cash' =>array('type'=>'double(24,8)', 'label'=>'Cash', 'enabled'=>1, 'visible'=>1, 'position'=>30), - 'cheque' =>array('type'=>'double(24,8)', 'label'=>'Cheque', 'enabled'=>1, 'visible'=>1, 'position'=>33), - 'card' =>array('type'=>'double(24,8)', 'label'=>'CreditCard', 'enabled'=>1, 'visible'=>1, 'position'=>36), - '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), - '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), - '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), - 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array('0'=>'Brouillon', '1'=>'Validated')), + 'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>10), + 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=>1, 'position'=>15), + 'ref' =>array('type'=>'varchar(64)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>18), + 'posmodule' =>array('type'=>'varchar(30)', 'label'=>'Module', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>19), + 'posnumber' =>array('type'=>'varchar(30)', 'label'=>'CashDesk', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>20), + 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>0, 'position'=>24), + 'opening' =>array('type'=>'double(24,8)', 'label'=>'Opening', 'enabled'=>1, 'visible'=>1, 'position'=>25), + 'cash' =>array('type'=>'double(24,8)', 'label'=>'Cash', 'enabled'=>1, 'visible'=>1, 'position'=>30), + 'cheque' =>array('type'=>'double(24,8)', 'label'=>'Cheque', 'enabled'=>1, 'visible'=>1, 'position'=>33), + 'card' =>array('type'=>'double(24,8)', 'label'=>'CreditCard', 'enabled'=>1, 'visible'=>1, 'position'=>36), + '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), + 'day_close' =>array('type'=>'integer', 'label'=>'Day close', 'enabled'=>1, 'visible'=>1, 'position'=>60), + '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), + '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')), ); public $id; public $opening; public $status; - public $date_creation; public $year_close; public $month_close; public $day_close; @@ -86,6 +86,9 @@ class CashControl extends CommonObject public $cash; public $cheque; public $card; + public $date_valid; + public $date_creation; + public $date_modification; const STATUS_DRAFT = 0; const STATUS_VALIDATED = 1; @@ -125,7 +128,7 @@ class CashControl extends CommonObject $sql .= "entity"; //$sql .= ", ref"; $sql .= ", opening"; - $sql .= ", status"; + $sql .= ", status"; $sql .= ", date_creation"; $sql .= ", posmodule"; $sql .= ", posnumber"; @@ -139,7 +142,7 @@ class CashControl extends CommonObject //$sql .= "'(PROV)', "; $sql .= $conf->entity; $sql .= ", ".($this->opening > 0 ? $this->opening : 0); - $sql .= ", 0"; // Draft by default + $sql .= ", 0"; // Draft by default $sql .= ", '".$this->db->idate(dol_now())."'"; $sql .= ", '".$this->db->escape($this->posmodule)."'"; $sql .= ", '".$this->db->escape($this->posnumber)."'"; @@ -203,14 +206,14 @@ class CashControl extends CommonObject } /* - $posmodule = $this->posmodule; - if (! empty($user->rights->$posmodule->use)) - { - $this->error='NotEnoughPermissions'; - dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); - return -1; - } - */ + $posmodule = $this->posmodule; + if (! empty($user->rights->$posmodule->use)) + { + $this->error='NotEnoughPermissions'; + dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); + return -1; + } + */ $now=dol_now(); @@ -231,13 +234,13 @@ class CashControl extends CommonObject } 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) { - $this->context=array('date_valid'=>$now); - // Call trigger $result=$this->call_trigger('CASHCONTROL_VALIDATE', $user); if ($result < 0) $error++; @@ -260,48 +263,20 @@ class CashControl extends CommonObject /** - * Load object in memory from database + * Load object in memory from the database * - * @param int $id Id object - * @return int <0 if KO, >0 if OK + * @param int $id Id object + * @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; - - $sql = "SELECT"; - $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; - } + $result = $this->fetchCommon($id, $ref); + if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines(); + return $result; } + /** * Return label of the status * @@ -374,7 +349,7 @@ class CashControl extends CommonObject * @param string $option Where point the link ('stock', 'composition', 'category', 'supplier', '') * @param int $maxlength Maxlength of ref * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @param int $notooltip No tooltip + * @param int $notooltip No tooltip * @return string String with URL */ public function getNomUrl($withpicto=0, $option='', $maxlength=0, $save_lastsearch_value=-1, $notooltip=0) diff --git a/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php b/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php index f2c19394df9..b3eee673198 100644 --- a/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php +++ b/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php @@ -56,10 +56,10 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { - 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 - $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; 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==='MEMBER_SUBSCRIPTION_CREATE' || $action==='MEMBER_SUBSCRIPTION_MODIFY' || $action==='MEMBER_SUBSCRIPTION_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') ) { @@ -88,6 +89,10 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers if (in_array($action, array( 'MEMBER_SUBSCRIPTION_CREATE','MEMBER_SUBSCRIPTION_MODIFY','MEMBER_SUBSCRIPTION_DELETE', '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; } /*if ($action === 'BILL_PAYED' || $action==='BILL_UNPAYED' @@ -103,7 +108,7 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers $amounts = 0; if(!empty($object->amounts)) { foreach($object->amounts as $amount) { - $amounts+= price2num($amount); + $amounts += price2num($amount); } } }