| 1 | <?php |
| 2 | switch($SUBPATH[0]) { |
| 3 | default: case 1: |
| 4 | $barcode = isset($_GET['barcode']) ? htmlspecialchars($_GET['barcode']) : ''; //TODO: XSS |
| 5 | echo $this->html->form("$URL/2", 'GET', array( |
| 6 | array('barcode',$barcode,'text',false,'autofocus','model_barcode:'), |
| 7 | array('quantity','1','text',false,false,'quantity:'), |
| 8 | array('serials',$barcode,'textarea',false,'autofocus','serial(s):'), |
| 9 | array(false,'STORE','submit') |
| 10 | )); |
| 11 | break; |
| 12 | case 2: |
| 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); |
| 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'); |
| 26 | |
| 27 | $disable_cols = array('status_id','item_price_out','item_customer', 'model_id','item_quantity','item_date_sold'); |
| 28 | if($countable) { |
| 29 | $multi_insert = true; |
| 30 | //$disable_cols[] = 'item_quantity'; |
| 31 | $item_serial = $serial; |
| 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; |
| 41 | |
| 42 | $disable_cols[] = 'item_serial'; |
| 43 | $item_serial = $barcode; |
| 44 | $item_quantity = $quantity_stored + $quantity_added; |
| 45 | $action = $_SERVER['SCRIPT_NAME'].'/item/0/edit'; |
| 46 | |
| 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); |
| 67 | } |
| 68 | |
| 69 | echo $this->html->render_insert_form_multi($insert_form); |
| 70 | |
| 71 | break; |
| 72 | } |