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