Vylepseni prekladu
[mirrors/SokoMan.git] / assistants / store.inc.php
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 $item_price_in = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_price_in', 'item', false);
14 $item_price_out = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_price_out', 'item', false);
15 $model_price_in = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_price_in', 'model');
16 $model_price_out = $this->db->map_unique('model_barcode', $_GET['barcode'], 'model_price_out', 'model');
17
18 $disable_cols = array('status_id','item_price_out','item_customer', 'model_id','item_quantity','item_date_sold');
19 if($this->db->map_unique('model_barcode', $_GET['barcode'], 'model_countable', 'model')) {
20 $multi_insert = true;
21 //$disable_cols[] = 'item_quantity';
22 $item_serial = '';
23 $item_quantity = $quantity_added = 1;
24 $action = $_SERVER['SCRIPT_NAME'].'/item/new';
25 } else {
26 $multi_insert = false;
27 $quantity_added = $_GET['quantity'];
28 if($quantity_added <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't store non-possitive amount of items!");
29 if(!is_numeric($quantity_added)) $quantity_added = 1;
30 $quantity_stored = $this->db->map_unique('item_serial', $_GET['barcode'], 'item_quantity', 'item', false);
31 if(!is_numeric($quantity_stored)) $quantity_stored = 0;
32
33 $disable_cols[] = 'item_serial';
34 $item_serial = $_GET['barcode'];
35 $item_quantity = $quantity_stored + $quantity_added;
36 $action = $_SERVER['SCRIPT_NAME'].'/item/0/edit';
37
38 echo('Stock: '.$quantity_stored.'<br />Storing: '.$quantity_added.'<br />Total: '.$item_quantity);
39 }
40 $columns = $this->db->get_columns('item');
41
42 $selectbox = $this->db->columns_get_selectbox($columns, 'item');
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 'model_id' => $model_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 ));
56
57 echo $this->html->render_insert_form('item', $columns, $selectbox, $current, $disable_cols, $action, $multi_insert);
58 break;
59 }
This page took 0.700192 seconds and 4 git commands to generate.