Statistiky odted nejsou fatalni
[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('serials','','textarea',false,'autofocus','serial(s):'),
9 array(false,'STORE','submit')
10 ));
11 break;
12 case 2:
13 $barcode=$_GET['barcode'];
14
15 $barcode_id = $this->db->map_unique('barcode_name', $barcode, 'barcode_id', 'barcode');
16 $model_id = $this->db->map_unique('barcode_id', $barcode_id, 'model_id', 'barcode');
17 $model_price_in = $this->db->map_unique('model_id', $model_id, 'model_price_in', 'model');
18 $model_price_out = $this->db->map_unique('model_id', $model_id, 'model_price_out', 'model');
19 $item_price_in = $this->db->map_unique('item_serial', $barcode, 'item_price_in', 'item', false);
20 $item_price_out = $this->db->map_unique('item_serial', $barcode, 'item_price_out', 'item', false);
21
22 $countable = $this->db->map_unique('model_id', $model_id, 'model_countable', 'model');
23
24 $serials=explode("\n",trim($_GET['serials']));
25 if(!$countable || trim($_GET['serials']) == '') $serials = array('');
26
27 foreach($serials as $serial) {
28 $serial=trim($serial);
29
30 $disable_cols = array('status_id','item_price_out','item_customer', 'model_id','item_quantity','item_date_sold');
31 if($countable) {
32 $multi_insert = true;
33 //$disable_cols[] = 'item_quantity';
34 $item_serial = $serial;
35 $item_quantity = $quantity_added = 1;
36 $action = $_SERVER['SCRIPT_NAME'].'/item/new';
37 } else {
38 $multi_insert = false;
39 $quantity_added = $_GET['quantity'];
40 if($quantity_added <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't store non-possitive amount of items!");
41 if(!is_numeric($quantity_added)) $quantity_added = 1;
42 $quantity_stored = $this->db->map_unique('item_serial', $barcode, 'item_quantity', 'item', false);
43 if(!is_numeric($quantity_stored)) $quantity_stored = 0;
44
45 $disable_cols[] = 'item_serial';
46 $item_serial = $barcode;
47 $item_quantity = $quantity_stored + $quantity_added;
48 $action = $_SERVER['SCRIPT_NAME'].'/item/0/edit';
49
50 echo('Stock: '.$quantity_stored.'<br />Storing: '.$quantity_added.'<br />Total: '.$item_quantity);
51 }
52 $columns = $this->db->get_columns('item');
53
54 $selectbox = $this->db->columns_get_selectbox($columns, 'item');
55 //print_r(array('<pre>', $selectbox));
56 //foreach($selectbox['model_id'] as $id => $name) if($id != $model_id) unset($selectbox['model_id'][$id]);
57 $current = array(array(
58 'barcode_id' => $barcode_id,
59 'item_serial' => $item_serial,
60 'item_quantity' => $item_quantity,
61 'status_id' => 1,
62 'item_price_in' => $item_price_in + ($quantity_added * $model_price_in),
63 'item_price_out' => $item_price_out + ($quantity_added * $model_price_out),
64 'item_author' => $this->db->auth->get_user_id(),
65 'item_date_bought' => date('Y-m-d'),
66 'location_id' => 0
67 ));
68
69 $insert_form[]=array('item', $columns, $selectbox, $current, $disable_cols, $action, $multi_insert);
70 }
71
72 echo $this->html->render_insert_form_multi($insert_form);
73
74 break;
75 }
This page took 0.409915 seconds and 4 git commands to generate.