From: Thomas Mudrunka Date: Thu, 25 Aug 2011 18:22:32 +0000 (+0200) Subject: Priprava na nepocitatelny polozky X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=d0e7939cf5ffbebce8db62be368e36d890105e62;p=mirrors%2FSokoMan.git Priprava na nepocitatelny polozky --- diff --git a/assistants/dispose.inc.php b/assistants/dispose.inc.php index fcaf7f2..6d13b15 100644 --- a/assistants/dispose.inc.php +++ b/assistants/dispose.inc.php @@ -1,21 +1,58 @@ html->form("$URL/2", 'GET', array( array('serial','','text',false,'autofocus','item_serial:'), + array('quantity','1','text',false,false,'quantity:'), array(false,'DISPOSE','submit') )); break; case 2: - $item_id = $this->db->map_unique('item_serial', $_GET['serial'], 'item_id', 'item'); - $columns = $this->db->get_columns('item'); - $selectbox = $this->db->columns_get_selectbox($columns, 'item'); + $item_serial = $_GET['serial']; + $item_id = $this->db->map_unique('item_serial', $item_serial, 'item_id', 'item'); $current = $this->db->get_listing('item', $item_id, 1); - $current[$item_id]['status_id'] = 2; $current[$item_id]['item_customer'] = 0; + $disable_cols = array('status_id','item_price_in','item_customer','item_serial','item_quantity','model_id','vendor_id','room_id'); + + $model_id = $this->db->map_unique('item_serial', $item_serial, 'model_id', 'item'); + $model_price_in = $this->db->map_unique('model_id', $model_id, 'model_price_in', 'model'); + $model_price_out = $this->db->map_unique('model_id', $model_id, 'model_price_out', 'model'); + + if($this->db->map_unique('model_id', $model_id, 'model_countable', 'model')) { + $current[$item_id]['status_id'] = 2; + $item_quantity = 1; + $current[$item_id]['item_price_out'] = $model_price_out; + } else { + $disable_cols = array_merge($disable_cols,array('item_price_out')); + $quantity_removed = $_GET['quantity']; + if($quantity_removed <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't dispose non-possitive amount of items!"); + if(!is_numeric($quantity_removed)) $quantity_removed = 1; + $quantity_stored = $this->db->map_unique('item_serial', $item_serial, 'item_quantity', 'item', false); + if(!is_numeric($quantity_stored)) $quantity_stored = 0; + echo("Quantity stored: ".$quantity_stored); + + $item_quantity = $quantity_stored - $quantity_removed; + $current[$item_id]['item_quantity'] = $item_quantity; + + $current[$item_id]['item_price_in'] = $item_quantity * $model_price_in; + $current[$item_id]['item_price_out'] = $item_quantity * $model_price_out; + } + + $columns = $this->db->get_columns('item'); + $selectbox = $this->db->columns_get_selectbox($columns, 'item'); + $action = $_SERVER['SCRIPT_NAME']."/item/$item_id/edit"; - echo $this->html->render_insert_form('item', $columns, $selectbox, $current, false, $action); + //echo $this->html->render_insert_form('item', $columns, $selectbox, $current, $disable_cols, $action); + echo $this->html->render_insert_form_multi(array( + //array('item', $columns, $selectbox, $current, $disable_cols, $action), + array('item', $columns, $selectbox, $current, $disable_cols, $action) + )); break; } diff --git a/assistants/sell.inc.php b/assistants/sell.inc.php index 4bdfbfd..6a1a3b8 100644 --- a/assistants/sell.inc.php +++ b/assistants/sell.inc.php @@ -1,8 +1,4 @@ html->form("$URL/2", 'GET', array( diff --git a/assistants/store-single.inc.php b/assistants/store-single.inc.php index dc550b8..7af375d 100644 --- a/assistants/store-single.inc.php +++ b/assistants/store-single.inc.php @@ -4,7 +4,7 @@ switch($SUBPATH[0]) { default: case 1: echo $this->render_form_add('model'); break; - case 2: + case 2: //TODO: reuse assistants/store for this step $model_id = trim($_GET['last']); $columns = $this->db->get_columns('item'); $selectbox = $this->db->columns_get_selectbox($columns, 'item'); diff --git a/assistants/store.inc.php b/assistants/store.inc.php index cacee8f..b7818ab 100644 --- a/assistants/store.inc.php +++ b/assistants/store.inc.php @@ -3,23 +3,46 @@ switch($SUBPATH[0]) { default: case 1: echo $this->html->form("$URL/2", 'GET', array( array('barcode','','text',false,'autofocus','model_barcode:'), + array('quantity','1','text',false,false,'quantity:'), array(false,'STORE','submit') )); break; case 2: $model_id = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_id', 'model'); + + $disable_cols = array('status_id','item_price_out','item_customer', 'model_id','item_quantity'); + if($this->db->map_unique('model_barcode', $_GET['barcode'], 'model_countable', 'model')) { + //$disable_cols[] = 'item_quantity'; + $item_serial = ''; + $item_quantity = 1; + $action = $_SERVER['SCRIPT_NAME'].'/item/new'; + } else { + $quantity_added = $_GET['quantity']; + if($quantity_added <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't store non-possitive amount of items!"); + if(!is_numeric($quantity_added)) $quantity_added = 1; + $quantity_stored = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_quantity', 'item', false); + if(!is_numeric($quantity_stored)) $quantity_stored = 0; + echo("Quantity stored: ".$quantity_stored); + + $disable_cols[] = 'item_serial'; + $item_serial = $_GET['barcode']; + $item_quantity = $quantity_stored + $quantity_added; + $action = $_SERVER['SCRIPT_NAME'].'/item/0/edit'; + } $columns = $this->db->get_columns('item'); - $selectbox = $this->db->columns_get_selectbox($columns, 'item'); + $selectbox = $this->db->columns_get_selectbox($columns, 'item'); //print_r(array('
', $selectbox));
 		//foreach($selectbox['model_id'] as $id => $name) if($id != $model_id) unset($selectbox['model_id'][$id]);
 		$current = array(array(
 			'model_id' => $model_id,
-			'item_quantity' => 1,
-			'status_id' => 1
+			'item_serial' => $item_serial,
+			'item_quantity' => $item_quantity,
+			'status_id' => 1,
+			'item_price_in' => $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_price_in', 'model'),
+			'item_price_out' => $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_price_out', 'model')
 		));
 
-		$action = $_SERVER['SCRIPT_NAME'].'/item/new';
-    echo $this->html->render_insert_form('item', $columns, $selectbox, $current, false, $action);
+    echo $this->html->render_insert_form('item', $columns, $selectbox, $current, $disable_cols, $action);
 		break;
 }
diff --git a/index.php b/index.php
index 5c54331..8af511c 100755
--- a/index.php
+++ b/index.php
@@ -167,7 +167,7 @@ class Sklad_HTML extends HTML { //TODO: Split into few more methods
 * { font-family: arial; }
 td,body { background-color: white; }
 table { background-color: orange; border: orange; }
-a { text-decoration:none; color: darkblue; }
+a, a img { text-decoration:none; color: darkblue; border:none; }
 li a, a:hover { text-decoration:underline; }
 
 .menu li {
@@ -322,21 +322,8 @@ EOF;
 		return $this->table($table);
 	}
 
-	function render_insert_form($class, $columns, $selectbox=array(), $current=false, $hidecols=false, $action=false, $multi_insert=true) {
-		//echo('
'); print_r($selectbox);
-		//echo('
'); print_r($current);
-		$update = false;
-		if(is_array($current)) {
-			$update = true;
-			$current = array_shift($current);
-		}
-
-		if(!is_array($hidecols)) $hidecols = array('item_author', 'item_valid_from', 'item_valid_till'); //TODO Autodetect
-
-		$action = $action ? " action='$action'" : false;
-		$html=""; //TODO: use $this->form()
-		if($multi_insert) $html.='
'; - //$html.=$this->input('table', $class, 'hidden'); + function render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update) { + $html = ''; foreach($columns as $column) { $html.=T($class).':'.T($column['Field']).': '; $name="values[$class][".$column['Field'].'][]'; @@ -356,24 +343,70 @@ EOF; } $html.='
'; } + return $html; + } - if($multi_insert) { //TODO, move to separate JS file - $html.=<< -
- - + -EOF; + function render_insert_form_multi($array) { + $html = ''; + $head=false; + + foreach($array as $key => $args) { + $parts=array('inputs'); + if(!$head) { $head = true; + $parts[]='head'; + } + if(!isset($array[$key+1])) { + $parts[]='foot'; + } + $args[] = true; + $args[] = $parts; + $html .= call_user_func_array(array($this, 'render_insert_form'), $args); } + return $html; + } + + function render_insert_form($class, $columns, $selectbox=array(), $current=false, $hidecols=false, $action=false, $multi_insert=true, $parts=false) { + $html = ''; + //print_r($parts); + //echo('
'); print_r($selectbox);
+		//echo('
'); print_r($current);
+		$update = false;
+		if(is_array($current)) {
+			$update = true;
+			$current = array_shift($current);
+		}
+
+		if(!is_array($hidecols)) $hidecols = array();
+		$hidecols = array_merge($hidecols, array('item_author', 'item_valid_from', 'item_valid_till')); //TODO Autodetect
 
-		$btn = is_array($current) ? 'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting...
-		$html.=$this->input(false, $btn, 'submit');
-		$html.='';
+		if(!is_array($parts) || in_array('head', $parts)) {
+			$action = $action ? " action='$action'" : false;
+			$html.=""; //TODO: use $this->form()
+			if($multi_insert) $html.='
'; + } + + if(!is_array($parts) || in_array('inputs', $parts)) + $html.=$this->render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update); + + if(!is_array($parts) || in_array('foot', $parts)) { + if($multi_insert) { //TODO, move to separate JS file + $html.=<< +
+ + + +EOF; + } + + $btn = is_array($current) ? 'UPDATE' : 'INSERT'; //TODO: $current may be set even when inserting... + $html.=$this->input(false, $btn, 'submit'); + $html.=''; + } return $html; } } @@ -476,10 +509,14 @@ class Sklad_DB extends PDO { return $indexed; } - function get_columns($class) { + function get_columns($class,$disable_cols=array()) { //TODO: Not sure if compatible with non-MySQL DBs $class = $this->escape($class); $sql = "SHOW COLUMNS FROM $class;"; - return $this->safe_query_fetch($sql); + $columns = $this->safe_query_fetch($sql); + /*foreach($columns as $colk => $col) foreach($col as $key => $val) { + if(in_array($col['Field'],$disable_cols)) $columns[$colk]['Extra']='auto_increment'; + }*/ + return $columns; } function columns_get_selectbox($columns, $class=false, $suffix_id='_id', $suffix_name='_name') { @@ -500,12 +537,12 @@ class Sklad_DB extends PDO { return array_filter($selectbox, 'ksort'); } - function map_unique($key, $value, $select, $table) { //TODO: Guess $select and $table if not passed + function map_unique($key, $value, $select, $table, $fatal=true) { //TODO: Guess $select and $table if not passed $history = $this->contains_history($table) ? " AND ${table}_valid_till=0" : ''; $value=$this->quote($value); $sql = "SELECT $select FROM $table WHERE $key=$value$history LIMIT 1;"; //TODO use build_query_select()!!! $result = $this->safe_query_fetch($sql); - if(isset($result[0][$select])) return $result[0][$select]; else die(trigger_error(T('Record not found!'))); //TODO post_redirect_get... + if(isset($result[0][$select])) return $result[0][$select]; else if($fatal) die(trigger_error(T('Record not found!'))); //TODO post_redirect_get... } function contains_history($table) { diff --git a/locale/cs/messages.inc.php b/locale/cs/messages.inc.php index 679f450..e6db9c2 100644 --- a/locale/cs/messages.inc.php +++ b/locale/cs/messages.inc.php @@ -26,6 +26,7 @@ $LOCALE_MESSAGES = array( 'model_descript' => 'Popis modelu', 'model_barcode' => 'Čárový kód modelu', 'model_barcode:' => 'Čárový kód modelu:', + 'model_price_in' => 'Předpokládaná cena', 'model_price_out' => 'Doporučená cena', 'room_name' => 'Sklad',