| 1 | <?php |
| 2 | $columns = $this->db->get_columns('item'); |
| 3 | $selectbox = $this->db->columns_get_selectbox($columns, 'item'); |
| 4 | |
| 5 | switch($SUBPATH[0]) { |
| 6 | default: case 1: |
| 7 | $barcode = isset($_GET['barcode']) ? htmlspecialchars($_GET['barcode']) : ''; //TODO: XSS |
| 8 | |
| 9 | echo $this->html->form("$URL/2", 'GET', array( |
| 10 | array('barcode',$barcode,'text',false,'autofocus','model_barcode:'), |
| 11 | array('quantity','1','text',false,false,'quantity:'), |
| 12 | array('serials','','textarea',false,'autofocus','serial(s):'), |
| 13 | array('vendor',false,'select',$selectbox['vendor_id'],false,'vendor:'), |
| 14 | array('room',false,'select',$selectbox['room_id'],false,'room:'), |
| 15 | array(false,'STORE','submit') |
| 16 | )); |
| 17 | break; |
| 18 | case 2: |
| 19 | $barcode=$_GET['barcode']; |
| 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); |
| 27 | //$vendor_id = $this->db->map_unique('barcode_id', $barcode_id, 'vendor_id', 'item', false); |
| 28 | |
| 29 | $serials=explode("\n",trim($_GET['serials'])); |
| 30 | if(trim($_GET['serials']) == '') $serials = array(''); |
| 31 | |
| 32 | foreach($serials as $serial) { |
| 33 | $serial=trim($serial); |
| 34 | |
| 35 | $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'); |
| 36 | |
| 37 | $multi_insert = true; |
| 38 | //$disable_cols[] = 'item_quantity'; |
| 39 | $item_serial = $serial; |
| 40 | $item_quantity = $quantity_added = 1; |
| 41 | $action = $_SERVER['SCRIPT_NAME'].'/item/new'; |
| 42 | |
| 43 | //print_r(array('<pre>', $selectbox)); |
| 44 | //foreach($selectbox['model_id'] as $id => $name) if($id != $model_id) unset($selectbox['model_id'][$id]); |
| 45 | $current = array(array( |
| 46 | 'barcode_id' => $barcode_id, |
| 47 | 'item_serial' => $item_serial, |
| 48 | 'item_quantity' => $item_quantity, |
| 49 | 'status_id' => 1, |
| 50 | 'item_price_in' => $item_price_in + ($quantity_added * $model_price_in), |
| 51 | 'item_price_out' => $item_price_out + ($quantity_added * $model_price_out), |
| 52 | 'item_author' => $this->db->auth->get_user_id(), |
| 53 | 'item_date_bought' => date('Y-m-d'), |
| 54 | 'location_id' => 0, |
| 55 | 'room_id' => $_GET['room'], |
| 56 | 'vendor_id' => $_GET['vendor'] |
| 57 | )); |
| 58 | |
| 59 | //echo("<pre>"); print_r($selectbox); |
| 60 | $insert_form[]=array('item', $columns, $selectbox, $current, $disable_cols, $action, $multi_insert); |
| 61 | } |
| 62 | |
| 63 | echo $this->html->render_insert_form_multi($insert_form); |
| 64 | |
| 65 | break; |
| 66 | } |