fcc420f55aadaf440831f5a135bb02281504c7ff
[mirrors/SokoMan.git] / assistants / store.inc.php
1 <?php
2 switch($SUBPATH[0]) {
3 default: case 1:
4 echo $this->html->form("$URL/2", 'GET', array(
5 array('barcode','','text',false,'autofocus','model_barcode:'),
6 array('quantity','1','text',false,false,'quantity:'),
7 array(false,'STORE','submit')
8 ));
9 break;
10 case 2:
11 $model_id = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_id', 'model');
12
13 $disable_cols = array('status_id','item_price_out','item_customer', 'model_id','item_quantity');
14 if($this->db->map_unique('model_barcode', $_GET['barcode'], 'model_countable', 'model')) {
15 //$disable_cols[] = 'item_quantity';
16 $item_serial = '';
17 $item_quantity = 1;
18 $action = $_SERVER['SCRIPT_NAME'].'/item/new';
19 } else {
20 $quantity_added = $_GET['quantity'];
21 if($quantity_added <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't store non-possitive amount of items!");
22 if(!is_numeric($quantity_added)) $quantity_added = 1;
23 $quantity_stored = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_quantity', 'item', false);
24 $item_price_in = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_price_in', 'item', false);
25 $item_price_out = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_price_out', 'item', false);
26 $model_price_in = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_price_in', 'model');
27 $model_price_out = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_price_out', 'model');
28 if(!is_numeric($quantity_stored)) $quantity_stored = 0;
29 echo("Quantity stored: ".$quantity_stored);
30
31 $disable_cols[] = 'item_serial';
32 $item_serial = $_GET['barcode'];
33 $item_quantity = $quantity_stored + $quantity_added;
34 $action = $_SERVER['SCRIPT_NAME'].'/item/0/edit';
35 }
36 $columns = $this->db->get_columns('item');
37
38 $selectbox = $this->db->columns_get_selectbox($columns, 'item');
39 //print_r(array('<pre>', $selectbox));
40 //foreach($selectbox['model_id'] as $id => $name) if($id != $model_id) unset($selectbox['model_id'][$id]);
41 $current = array(array(
42 'model_id' => $model_id,
43 'item_serial' => $item_serial,
44 'item_quantity' => $item_quantity,
45 'status_id' => 1,
46 'item_price_in' => $item_price_in + ($quantity_added * $model_price_in),
47 'item_price_out' => $item_price_out + ($quantity_added * $model_price_out),
48 'item_author' => $this->db->auth->get_user_id()
49 ));
50
51 echo $this->html->render_insert_form('item', $columns, $selectbox, $current, $disable_cols, $action);
52 break;
53 }
This page took 0.443905 seconds and 3 git commands to generate.