From 5b0075faa84afd5c1ffda52926ef12fdff0cd74e Mon Sep 17 00:00:00 2001 From: Thomas Mudrunka Date: Thu, 25 Aug 2011 23:48:27 +0200 Subject: [PATCH] Temer plna podpora "nepocitatelnych" polozek, zbyva dodelat assistant/sell --- assistants/dispose.inc.php | 36 +++++++++++++++++++++++++----------- assistants/stats.inc.php | 13 ++++++++++--- index.php | 13 +++++++------ 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/assistants/dispose.inc.php b/assistants/dispose.inc.php index 6d13b15..4ac4362 100644 --- a/assistants/dispose.inc.php +++ b/assistants/dispose.inc.php @@ -4,6 +4,7 @@ //TODO: Add support for selling/disposing multiple items at once... //TODO: Reuse /item/$item_id/edit //TODO: Stop using map_unique()!!! +//TODO: we can use empty selectbox[] if no selectboxes are shown switch($SUBPATH[0]) { default: case 1: echo $this->html->form("$URL/2", 'GET', array( @@ -17,32 +18,45 @@ switch($SUBPATH[0]) { $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]['item_customer'] = 0; + $forked_item = $current; - $disable_cols = array('status_id','item_price_in','item_customer','item_serial','item_quantity','model_id','vendor_id','room_id'); + $disable_cols = array('status_id','item_price_in','item_serial','item_quantity','model_id','vendor_id','room_id','item_customer'); $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')) { + $model_countable = $this->db->map_unique('model_id', $model_id, 'model_countable', 'model'); + if($model_countable) { $current[$item_id]['status_id'] = 2; + $current[$item_id]['item_customer'] = 0; $item_quantity = 1; $current[$item_id]['item_price_out'] = $model_price_out; } else { - $disable_cols = array_merge($disable_cols,array('item_price_out')); + $disable_cols = array_merge($disable_cols,array('item_price_out','item_note')); $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; + + echo("Stock: ".$quantity_stored."
Disposing/Selling: ".$quantity_removed."
Keeping: ".$item_quantity); + + $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; + + $forked_item[$item_id]['item_id'] = ''; + $forked_item[$item_id]['item_serial'] .= '@'.time(); + $forked_item[$item_id]['status_id'] = '2'; + $forked_item[$item_id]['item_quantity'] = $quantity_removed; + $forked_item[$item_id]['item_price_in'] = $quantity_removed * $model_price_in; + $forked_item[$item_id]['item_price_out'] = $quantity_removed * $model_price_out; + $forked_item[$item_id]['item_customer'] = 0; + + $forked_disable_cols = array('model_id','vendor_id','item_serial','item_quantity','room_id','status_id','item_price_in','item_price_out','item_customer'); } $columns = $this->db->get_columns('item'); @@ -50,9 +64,9 @@ switch($SUBPATH[0]) { $action = $_SERVER['SCRIPT_NAME']."/item/$item_id/edit"; //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) - )); + + $insert_form[]=array('item', $columns, $selectbox, $current, $disable_cols, $action, false); + if(!$model_countable) $insert_form[]=array('item', $columns, $selectbox, $forked_item, $forked_disable_cols, $action, false); + echo $this->html->render_insert_form_multi($insert_form); break; } diff --git a/assistants/stats.inc.php b/assistants/stats.inc.php index 6ccfb9f..bd7caf0 100644 --- a/assistants/stats.inc.php +++ b/assistants/stats.inc.php @@ -18,13 +18,20 @@ $queries = array( //TODO: use build_query_select()!!! "Použito celkem $month" => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 2'.$month_sql, "Prodáno celkem $month" - => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 3'.$month_sql, + => 'SELECT COUNT(item_id),SUM(item_price_out) FROM item WHERE item_valid_till=0 AND status_id = 3'.$month_sql, + "Skladem celkem $month" + => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 1'.$month_sql, + "Bilance celkem $month" + => 'SELECT ( + SUM(item_price_out) + -(SELECT SUM(item_price_in) FROM item WHERE item_valid_till=0) + ) FROM item WHERE item_valid_till=0 AND ( status_id = 3 )', "Počet kusů skladem" - => 'SELECT room_id,room_name,model_id,model_name,model_barcode,COUNT(item_id)'. + => 'SELECT room_id,room_name,model_id,model_name,model_barcode,COUNT(item_id),SUM(item_quantity)'. ' FROM item LEFT JOIN model USING(model_id) LEFT JOIN room USING(room_id)'. ' WHERE item_valid_till=0 AND status_id=1'. ' GROUP BY model_id,room_id'. - ' ORDER BY room_id,model_id;' + ' ORDER BY room_id,model_id;', ); foreach($queries as $description => $sql) { diff --git a/index.php b/index.php index 8af511c..f4fd40c 100755 --- a/index.php +++ b/index.php @@ -357,10 +357,12 @@ EOF; } if(!isset($array[$key+1])) { $parts[]='foot'; - } - $args[] = true; + $hr = ''; + } else $hr = '
'; + //$args[] = false; $args[] = $parts; $html .= call_user_func_array(array($this, 'render_insert_form'), $args); + $html .= $hr; } return $html; } @@ -382,17 +384,16 @@ EOF; if(!is_array($parts) || in_array('head', $parts)) { $action = $action ? " action='$action'" : false; $html.=""; //TODO: use $this->form() - if($multi_insert) $html.='
'; + $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)) { + $html .= '

'; if($multi_insert) { //TODO, move to separate JS file $html.=<< -