Browse Source

Work on cash fence feature

Laurent Destailleur 6 years ago
parent
commit
1c49599a47

+ 97 - 16
htdocs/compta/cashcontrol/class/cashcontrol.class.php

@@ -27,7 +27,7 @@
 /**
  *    Class to manage cash fence
  */
-class CashControl // extends CommonObject
+class CashControl extends CommonObject
 {
 	/**
 	 * @var string ID to identify managed object
@@ -55,18 +55,20 @@ class CashControl // extends CommonObject
 	public $picto = 'bank';
 
 	public $fields=array(
-		'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10),
-		'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15),
-		'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>20),
+		'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>0, '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),
+		'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>0, 'position'=>20),
 		'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),
 		//'card' =>array('type'=>'double(24,8)', 'label'=>'Card', 'enabled'=>1, 'visible'=>1, 'position'=>35),
+		'cheque' =>array('type'=>'double(24,8)', 'label'=>'Cheque', 'enabled'=>1, 'visible'=>1, 'position'=>35),
 		'day_close' =>array('type'=>'integer', 'label'=>'Day close', 'enabled'=>1, 'visible'=>1, 'position'=>50),
 		'month_close' =>array('type'=>'integer', 'label'=>'Month close', 'enabled'=>1, 'visible'=>1, 'position'=>55),
-		'year_close' =>array('type'=>'integer', 'label'=>'Year close', 'enabled'=>1, 'visible'=>1, 'position'=>60),
-		'posmodule' =>array('type'=>'varchar(30)', 'label'=>'Module', 'enabled'=>1, 'visible'=>1, 'position'=>65),
-		'posnumber' =>array('type'=>'varchar(30)', 'label'=>'CashDesk', 'enabled'=>1, 'visible'=>1, 'position'=>70),
-		//'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>40),
+		'year_close' =>array('type'=>'integer', 'label'=>'Year close', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>60),
+		'posmodule' =>array('type'=>'varchar(30)', 'label'=>'Module', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>65),
+		'posnumber' =>array('type'=>'varchar(30)', 'label'=>'CashDesk', 'enabled'=>1, 'visible'=>1, 'notnul'=>1, 'position'=>70),
+		'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'position'=>80),
 		'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),
@@ -111,16 +113,18 @@ class CashControl // extends CommonObject
 		// Insert request
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."pos_cash_fence (";
 		$sql .= "entity";
+		//$sql .= ", ref";
 		$sql .= ", opening";
         $sql .= ", status";
 		$sql .= ", date_creation";
 		$sql .= ", posmodule";
 		$sql .= ", posnumber";
 		$sql .= ") VALUES (";
+		//$sql .= "'(PROV)', ";
 		$sql .= $conf->entity;
 		$sql .= ", ".$this->opening;
         $sql .= ",1";
-		$sql .= ", now()";
+		$sql .= ", '".$this->db->idate(dol_now())."'";
 		$sql .= ", '".$this->posmodule."'";
 		$sql .= ", '".$this->posnumber."'";
 		$sql .= ")";
@@ -167,12 +171,12 @@ class CashControl // extends CommonObject
 
 		// Update request
 		$sql = "UPDATE ".MAIN_DB_PREFIX."pos_cash_fence ";
-		$sql .= "SET";
-		$sql .= " day_close=DAYOFMONTH(NOW())";
-		$sql .= ", month_close=MONTH(NOW())";
-		$sql .= ", year_close=YEAR(NOW())";
-        $sql .= ", status=2";
-		$sql .= " where rowid=".$this->id;
+		$sql.= "SET";
+		$sql.= " day_close=DAYOFMONTH(NOW())";
+		$sql.= ", month_close=MONTH(NOW())";
+		$sql.= ", year_close=YEAR(NOW())";
+        $sql.= ", status=2";
+		$sql.= " where rowid=".$this->id;
 		$this->db->begin();
 
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
@@ -222,14 +226,17 @@ class CashControl // extends CommonObject
 		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->date_creation = $obj->date_creation;
 				$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);
@@ -240,4 +247,78 @@ class CashControl // extends CommonObject
 			return -1;
 		}
 	}
+
+
+	/**
+	 *    Return clicable link of object (with eventually picto)
+	 *
+	 * @param  int    $withpicto             Add picto into link
+	 * @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
+	 * @return string                                String with URL
+	 */
+	public function getNomUrl($withpicto=0, $option='', $maxlength=0, $save_lastsearch_value=-1, $notooltip=0)
+	{
+		global $conf, $langs, $hookmanager;
+		include_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
+
+		$result='';
+		$newref=($this->ref?$this->ref:$this->id);
+		if ($maxlength) { $newref=dol_trunc($newref, $maxlength, 'middle'); }
+
+		$label = '<u>' . $langs->trans("ShowCashFence") . '</u>';
+		$label .= '<br><b>' . $langs->trans('ProductRef') . ':</b> ' . ($this->ref?$this->ref:$this->id);
+
+		$linkclose='';
+		if (empty($notooltip)) {
+			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
+				$label=$langs->trans("ShowCashFence");
+				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
+			}
+
+			$linkclose.= ' title="'.dol_escape_htmltag($label, 1, 1).'"';
+			$linkclose.= ' class="classfortooltip"';
+
+			/*
+			 $hookmanager->initHooks(array('productdao'));
+			 $parameters=array('id'=>$this->id);
+			 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
+			 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
+			 */
+		}
+
+		$url = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$this->id;
+
+		if ($option !== 'nolink') {
+			// Add param to save lastsearch_values or not
+			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { $add_save_lastsearch_values=1;
+			}
+			if ($add_save_lastsearch_values) { $url.='&save_lastsearch_values=1';
+			}
+		}
+
+		$linkstart = '<a href="'.$url.'"';
+		$linkstart.=$linkclose.'>';
+		$linkend='</a>';
+
+		$result.=$linkstart;
+		if ($withpicto) {
+			$result.=(img_object(($notooltip?'':$label), 'bank', ($notooltip?'class="paddingright"':'class="paddingright classfortooltip"'), 0, 0, $notooltip?0:1));
+		}
+		$result.= $newref;
+		$result.= $linkend;
+
+		global $action;
+		$hookmanager->initHooks(array('cashfencedao'));
+		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
+		$reshook=$hookmanager->executeHooks('getNomUrl', $parameters, $this, $action);    // Note that $action and $object may have been modified by some hooks
+		if ($reshook > 0) { $result = $hookmanager->resPrint;
+		} else { $result .= $hookmanager->resPrint;
+		}
+
+		return $result;
+	}
 }

+ 2 - 2
htdocs/compta/cashcontrol/report.php

@@ -88,8 +88,8 @@ if ($resql)
 	$i = 0;
 
 	print "<center><h2>";
-	if ($cashcontrol->status==2) print "Cashcontrol ".$cashcontrol->id;
-	else print $langs->trans("Cashcontrol")." - ".$langs->trans("Draft");
+	if ($cashcontrol->status==2) print $langs->trans("CashControl")." ".$cashcontrol->id;
+	else print $langs->trans("CashControl")." - ".$langs->trans("Draft");
 	print "<br>".$langs->trans("DateCreationShort").": ".dol_print_date($cashcontrol->date_creation, 'day')."</h2></center>";
 
 

+ 3 - 0
htdocs/install/mysql/migration/8.0.0-9.0.0.sql

@@ -234,10 +234,12 @@ DROP TABLE llx_ticket_logs;
 CREATE TABLE llx_pos_cash_fence(
 	rowid INTEGER AUTO_INCREMENT PRIMARY KEY,
 	entity INTEGER DEFAULT 1 NOT NULL,
+	ref VARCHAR(64),
 	label VARCHAR(255),
 	opening double(24,8) default 0,
 	cash double(24,8) default 0,
 	card double(24,8) default 0,
+	cheque double(24,8) default 0,
 	status INTEGER,
 	date_creation DATETIME NOT NULL,
 	day_close INTEGER,
@@ -245,6 +247,7 @@ CREATE TABLE llx_pos_cash_fence(
 	year_close INTEGER,
 	posmodule VARCHAR(30),
 	posnumber VARCHAR(30),
+	fk_user_creat integer,
 	fk_user_valid integer,
 	tms TIMESTAMP NOT NULL,
 	import_key VARCHAR(14)

+ 3 - 0
htdocs/install/mysql/tables/llx_pos_cash_fence.sql

@@ -17,10 +17,12 @@
 CREATE TABLE llx_pos_cash_fence(
 	rowid INTEGER AUTO_INCREMENT PRIMARY KEY,
 	entity INTEGER DEFAULT 1 NOT NULL,
+	ref VARCHAR(64),
 	label VARCHAR(255),
 	opening double(24,8) default 0,
 	cash double(24,8) default 0,
 	card double(24,8) default 0,
+	cheque double(24,8) default 0,
 	status INTEGER,
 	date_creation DATETIME NOT NULL,
 	day_close INTEGER,
@@ -28,6 +30,7 @@ CREATE TABLE llx_pos_cash_fence(
 	year_close INTEGER,
 	posmodule VARCHAR(30),
 	posnumber VARCHAR(30),
+	fk_user_creat integer,
 	fk_user_valid integer,
 	tms TIMESTAMP NOT NULL,
 	import_key VARCHAR(14)