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