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'); | |
274c2053 TM |
13 | $item_price_in = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_price_in', 'item', false); |
14 | $item_price_out = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_price_out', 'item', false); | |
15 | $model_price_in = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_price_in', 'model'); | |
16 | $model_price_out = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_price_out', 'model'); | |
d0e7939c TM |
17 | |
18 | $disable_cols = array('status_id','item_price_out','item_customer', 'model_id','item_quantity'); | |
19 | if($this->db->map_unique('model_barcode', $_GET['barcode'], 'model_countable', 'model')) { | |
20 | //$disable_cols[] = 'item_quantity'; | |
21 | $item_serial = ''; | |
274c2053 | 22 | $item_quantity = $quantity_added = 1; |
d0e7939c TM |
23 | $action = $_SERVER['SCRIPT_NAME'].'/item/new'; |
24 | } else { | |
25 | $quantity_added = $_GET['quantity']; | |
26 | if($quantity_added <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't store non-possitive amount of items!"); | |
27 | if(!is_numeric($quantity_added)) $quantity_added = 1; | |
28 | $quantity_stored = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_quantity', 'item', false); | |
29 | if(!is_numeric($quantity_stored)) $quantity_stored = 0; | |
d0e7939c TM |
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'; | |
274c2053 TM |
35 | |
36 | echo('Stock: '.$quantity_stored.'<br />Storing: '.$quantity_added.'<br />Total: '.$item_quantity); | |
d0e7939c | 37 | } |
16261142 | 38 | $columns = $this->db->get_columns('item'); |
16261142 | 39 | |
d0e7939c | 40 | $selectbox = $this->db->columns_get_selectbox($columns, 'item'); |
16261142 TM |
41 | //print_r(array('<pre>', $selectbox)); |
42 | //foreach($selectbox['model_id'] as $id => $name) if($id != $model_id) unset($selectbox['model_id'][$id]); | |
43 | $current = array(array( | |
44 | 'model_id' => $model_id, | |
d0e7939c TM |
45 | 'item_serial' => $item_serial, |
46 | 'item_quantity' => $item_quantity, | |
47 | 'status_id' => 1, | |
fbf1a4e6 TM |
48 | 'item_price_in' => $item_price_in + ($quantity_added * $model_price_in), |
49 | 'item_price_out' => $item_price_out + ($quantity_added * $model_price_out), | |
253705f2 | 50 | 'item_author' => $this->db->auth->get_user_id() |
16261142 TM |
51 | )); |
52 | ||
d0e7939c | 53 | echo $this->html->render_insert_form('item', $columns, $selectbox, $current, $disable_cols, $action); |
16261142 TM |
54 | break; |
55 | } |