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