Podopora nepocitatelnych polozek byla dotazena do konce
[mirrors/SokoMan.git] / assistants / sell.inc.php
1 <?php
2 //TODO: Highlight fields that should be filled (and maybe even check them when submited)
3 //TODO: Add support for selling/disposing multiple items at once...
4 //TODO: Reuse /item/$item_id/edit
5 //TODO: Stop using map_unique()!!!
6 //TODO: we can use empty selectbox[] if no selectboxes are shown
7
8 if(!isset($status_id)) $status_id = 3;
9 if(!isset($item_customer)) $item_customer = '';
10 if(!isset($hide_cols_additional)) $hide_cols_additional = array();
11 $button_label = strtoupper($ASSISTANT);
12
13 $hide_cols_common = array_merge($hide_cols_additional,array('status_id','item_price_in','item_serial','item_quantity','model_id','vendor_id','room_id'));
14
15 switch($SUBPATH[0]) {
16 default: case 1:
17 echo $this->html->form("$URL/2", 'GET', array(
18 array('serial','','text',false,'autofocus','item_serial:'),
19 array('quantity','1','text',false,false,'quantity:'),
20 array(false,$button_label,'submit')
21 ));
22 break;
23 case 2:
24 $item_serial = $_GET['serial'];
25 $item_id = $this->db->map_unique('item_serial', $item_serial, 'item_id', 'item');
26
27 $current = $this->db->get_listing('item', $item_id, 1);
28 $forked_item = $current;
29
30 $model_id = $this->db->map_unique('item_serial', $item_serial, 'model_id', 'item');
31 $model_price_in = $this->db->map_unique('model_id', $model_id, 'model_price_in', 'model');
32 $model_price_out = $this->db->map_unique('model_id', $model_id, 'model_price_out', 'model');
33
34 $model_countable = $this->db->map_unique('model_id', $model_id, 'model_countable', 'model');
35 if($model_countable) {
36 $current[$item_id]['status_id'] = $status_id;
37 $current[$item_id]['item_customer'] = $item_customer;
38 $item_quantity = 1;
39 $current[$item_id]['item_price_out'] = $model_price_out;
40 $hide_cols = $hide_cols_common;
41 } else {
42 $hide_cols = array_merge($hide_cols_common,array('item_price_out','item_note','item_customer'));
43 $quantity_removed = $_GET['quantity'];
44 if($quantity_removed <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't dispose non-possitive amount of items!");
45 if(!is_numeric($quantity_removed)) $quantity_removed = 1;
46 $quantity_stored = $this->db->map_unique('item_serial', $item_serial, 'item_quantity', 'item', false);
47 if(!is_numeric($quantity_stored)) $quantity_stored = 0;
48 $item_quantity = $quantity_stored - $quantity_removed;
49
50
51 echo("Stock: ".$quantity_stored."<br />Disposing/Selling: ".$quantity_removed."<br />Keeping: ".$item_quantity);
52
53 $current[$item_id]['item_quantity'] = $item_quantity;
54 $current[$item_id]['item_price_in'] = $item_quantity * $model_price_in;
55 $current[$item_id]['item_price_out'] = $item_quantity * $model_price_out;
56
57 $forked_item[$item_id]['item_id'] = '';
58 $forked_item[$item_id]['item_serial'] .= '@'.time();
59 $forked_item[$item_id]['status_id'] = $status_id;
60 $forked_item[$item_id]['item_quantity'] = $quantity_removed;
61 $forked_item[$item_id]['item_price_in'] = $quantity_removed * $model_price_in;
62 $forked_item[$item_id]['item_price_out'] = $quantity_removed * $model_price_out;
63 $forked_item[$item_id]['item_customer'] = $item_customer;
64
65 $forked_hide_cols = array_merge($hide_cols_common,array('item_price_out'));
66 }
67
68 $columns = $this->db->get_columns('item');
69 $selectbox = $this->db->columns_get_selectbox($columns, 'item');
70
71 $action = $_SERVER['SCRIPT_NAME']."/item/$item_id/edit";
72 //echo $this->html->render_insert_form('item', $columns, $selectbox, $current, $hide_cols, $action);
73
74 $insert_form[]=array('item', $columns, $selectbox, $current, $hide_cols, $action, false);
75 if(!$model_countable) $insert_form[]=array('item', $columns, $selectbox, $forked_item, $forked_hide_cols, $action, false);
76 echo $this->html->render_insert_form_multi($insert_form);
77 break;
78 }
This page took 0.342391 seconds and 5 git commands to generate.