From e06b06c788d7ccc683dbfa74971ab80c9a34918d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 17 Dec 2018 10:37:56 +0100 Subject: [PATCH] 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