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