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