Temer plna podpora "nepocitatelnych" polozek, zbyva dodelat assistant/sell
authorThomas Mudrunka <tomas@mudrunka.cz>
Thu, 25 Aug 2011 21:48:27 +0000 (23:48 +0200)
committerThomas Mudrunka <tomas@mudrunka.cz>
Thu, 25 Aug 2011 21:48:27 +0000 (23:48 +0200)
assistants/dispose.inc.php
assistants/stats.inc.php
index.php

index 6d13b1568b055de122ba3d731c1c66f565ad0284..4ac4362424ae3ea14b6399a2685ae1a21bde9040 100644 (file)
@@ -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."<br />Disposing/Selling: ".$quantity_removed."<br />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;
 }
index 6ccfb9f693fefa61d6b689ba527477ff93d0e88f..bd7caf0d386978f8517f22e24b15d9180cd56c48 100644 (file)
@@ -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) {
index 8af511cb76b3634042364ccbff9892be5281a80b..f4fd40c3afb65ca18508675fab17a4890363a0ec 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -357,10 +357,12 @@ EOF;
                        }
                        if(!isset($array[$key+1])) {
                                $parts[]='foot';
-                       }
-                       $args[] = true;
+                               $hr = '';
+                       } else $hr = '<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.="<form$action method='POST'>"; //TODO: use $this->form()
-                       if($multi_insert) $html.='<span><div name="input_set" style="float:left; border:1px solid grey; padding: 1px; margin: 1px;">';
+                       $html.='<span><div name="input_set" style="float:left; border:1px solid grey; padding: 1px; margin: 1px;">';
                }
 
                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 .= '</div></span><br style="clear:both" />';
                        if($multi_insert) { //TODO, move to separate JS file
                                $html.=<<<EOF
-                               </div></span>
-                               <br style="clear:both" />
                                <script>
                                        function duplicate_element(what, where) {
                                                var node = document.getElementsByName(what)[0];
@@ -573,7 +574,7 @@ class Sklad_DB extends PDO {
                                $sql .= " WHERE ${table}_valid_till=0 AND (";
                                $or = '';
                                foreach($values as $row) {
-                                       $sql .= $or.' '.$table.'_id='.$row[$table.'_id'];
+                                       $sql .= $or.' '.$table.'_id='.$this->quote($row[$table.'_id']);
                                        $or = ' OR';
                                }
                                $sql .= " );\n\n";
This page took 0.183735 seconds and 4 git commands to generate.