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( |
68cf81dd | 6 | array('barcode',$barcode,'text',false,'autofocus','model_barcode:'), |
d0e7939c | 7 | array('quantity','1','text',false,false,'quantity:'), |
68cf81dd | 8 | array('serials',$barcode,'textarea',false,'autofocus','serial(s):'), |
35916247 TM |
9 | array(false,'STORE','submit') |
10 | )); | |
16261142 TM |
11 | break; |
12 | case 2: | |
68cf81dd TM |
13 | $barcode=$_GET['barcode']; |
14 | $countable = $this->db->map_unique('model_barcode', $barcode, 'model_countable', 'model'); | |
15 | ||
16 | $serials=explode("\n",trim($_GET['serials'])); | |
17 | if(!$countable || trim($_GET['serials']) == '') $serials = array(''); | |
18 | ||
19 | foreach($serials as $serial) { | |
20 | $serial=trim($serial); | |
cb32a7df TM |
21 | $model_id = $this->db->map_unique('model_barcode', $barcode, 'model_id', 'model'); |
22 | $item_price_in = $this->db->map_unique('item_serial', $barcode, 'item_price_in', 'item', false); | |
23 | $item_price_out = $this->db->map_unique('item_serial', $barcode, 'item_price_out', 'item', false); | |
24 | $model_price_in = $this->db->map_unique('model_barcode', $barcode, 'model_price_in', 'model'); | |
25 | $model_price_out = $this->db->map_unique('model_barcode', $barcode, 'model_price_out', 'model'); | |
d0e7939c | 26 | |
cb32a7df | 27 | $disable_cols = array('status_id','item_price_out','item_customer', 'model_id','item_quantity','item_date_sold'); |
68cf81dd | 28 | if($countable) { |
cb32a7df TM |
29 | $multi_insert = true; |
30 | //$disable_cols[] = 'item_quantity'; | |
68cf81dd | 31 | $item_serial = $serial; |
cb32a7df TM |
32 | $item_quantity = $quantity_added = 1; |
33 | $action = $_SERVER['SCRIPT_NAME'].'/item/new'; | |
34 | } else { | |
35 | $multi_insert = false; | |
36 | $quantity_added = $_GET['quantity']; | |
37 | if($quantity_added <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't store non-possitive amount of items!"); | |
38 | if(!is_numeric($quantity_added)) $quantity_added = 1; | |
39 | $quantity_stored = $this->db->map_unique('item_serial', $barcode, 'item_quantity', 'item', false); | |
40 | if(!is_numeric($quantity_stored)) $quantity_stored = 0; | |
d0e7939c | 41 | |
cb32a7df TM |
42 | $disable_cols[] = 'item_serial'; |
43 | $item_serial = $barcode; | |
44 | $item_quantity = $quantity_stored + $quantity_added; | |
45 | $action = $_SERVER['SCRIPT_NAME'].'/item/0/edit'; | |
274c2053 | 46 | |
cb32a7df TM |
47 | echo('Stock: '.$quantity_stored.'<br />Storing: '.$quantity_added.'<br />Total: '.$item_quantity); |
48 | } | |
49 | $columns = $this->db->get_columns('item'); | |
50 | ||
51 | $selectbox = $this->db->columns_get_selectbox($columns, 'item'); | |
52 | //print_r(array('<pre>', $selectbox)); | |
53 | //foreach($selectbox['model_id'] as $id => $name) if($id != $model_id) unset($selectbox['model_id'][$id]); | |
54 | $current = array(array( | |
55 | 'model_id' => $model_id, | |
56 | 'item_serial' => $item_serial, | |
57 | 'item_quantity' => $item_quantity, | |
58 | 'status_id' => 1, | |
59 | 'item_price_in' => $item_price_in + ($quantity_added * $model_price_in), | |
60 | 'item_price_out' => $item_price_out + ($quantity_added * $model_price_out), | |
61 | 'item_author' => $this->db->auth->get_user_id(), | |
62 | 'item_date_bought' => date('Y-m-d'), | |
63 | 'location_id' => 0 | |
64 | )); | |
65 | ||
66 | $insert_form[]=array('item', $columns, $selectbox, $current, $disable_cols, $action, $multi_insert); | |
d0e7939c | 67 | } |
16261142 | 68 | |
cb32a7df | 69 | echo $this->html->render_insert_form_multi($insert_form); |
16261142 | 70 | |
16261142 TM |
71 | break; |
72 | } |