Oprava PDF
[mirrors/SokoMan.git] / assistants / sell.inc.php
CommitLineData
ec28d06c 1<?php
5ef6c52f
TM
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
8if(!isset($status_id)) $status_id = 3;
9if(!isset($item_customer)) $item_customer = '';
10if(!isset($hide_cols_additional)) $hide_cols_additional = array();
11$button_label = strtoupper($ASSISTANT);
12
5389f01c 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','item_date_bought'));
5ef6c52f 14
de77377e 15switch($SUBPATH[0]) {
ec28d06c 16 default: case 1:
4ece8e80 17 $serial = isset($_GET['serial']) ? htmlspecialchars($_GET['serial']) : ''; //TODO: XSS
35916247 18 echo $this->html->form("$URL/2", 'GET', array(
4ece8e80 19 array('serial',$serial,'text',false,'autofocus','item_serial:'),
5ef6c52f
TM
20 array('quantity','1','text',false,false,'quantity:'),
21 array(false,$button_label,'submit')
35916247 22 ));
ec28d06c
TM
23 break;
24 case 2:
5ef6c52f
TM
25 $item_serial = $_GET['serial'];
26 $item_id = $this->db->map_unique('item_serial', $item_serial, 'item_id', 'item');
ec28d06c
TM
27
28 $current = $this->db->get_listing('item', $item_id, 1);
253705f2 29 $current[$item_id]['item_author'] = $this->db->auth->get_user_id();
5ef6c52f
TM
30 $forked_item = $current;
31
eca3fc1d
TM
32 $barcode_id = $this->db->map_unique('item_id', $item_id, 'barcode_id', 'item');
33 $model_id = $this->db->map_unique('barcode_id', $barcode_id, 'model_id', 'barcode');
5ef6c52f
TM
34 $model_price_in = $this->db->map_unique('model_id', $model_id, 'model_price_in', 'model');
35 $model_price_out = $this->db->map_unique('model_id', $model_id, 'model_price_out', 'model');
36
37 $model_countable = $this->db->map_unique('model_id', $model_id, 'model_countable', 'model');
38 if($model_countable) {
39 $current[$item_id]['status_id'] = $status_id;
40 $current[$item_id]['item_customer'] = $item_customer;
41 $item_quantity = 1;
5389f01c
TM
42 $current[$item_id]['item_price_out'] = $model_price_out;
43 $current[$item_id]['item_date_sold'] = date('Y-m-d');
5ef6c52f
TM
44 $hide_cols = $hide_cols_common;
45 } else {
51630db6 46 $hide_cols = array_merge($hide_cols_common,array('item_price_out','item_note','item_customer','item_date_sold','location_id'));
5ef6c52f
TM
47 $quantity_removed = $_GET['quantity'];
48 if($quantity_removed <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't dispose non-possitive amount of items!");
49 if(!is_numeric($quantity_removed)) $quantity_removed = 1;
50 $quantity_stored = $this->db->map_unique('item_serial', $item_serial, 'item_quantity', 'item', false);
51 if(!is_numeric($quantity_stored)) $quantity_stored = 0;
52 $item_quantity = $quantity_stored - $quantity_removed;
7c1f53f7 53 if($item_quantity < 0) $this->post_redirect_get("$URL_INTERNAL/1","You don't have enough stored items!");
5ef6c52f
TM
54
55
56 echo("Stock: ".$quantity_stored."<br />Disposing/Selling: ".$quantity_removed."<br />Keeping: ".$item_quantity);
57
58 $current[$item_id]['item_quantity'] = $item_quantity;
fbf1a4e6
TM
59 $current[$item_id]['item_price_in'] -= $quantity_removed * $model_price_in;
60 $current[$item_id]['item_price_out'] -= $quantity_removed * $model_price_out;
5ef6c52f
TM
61
62 $forked_item[$item_id]['item_id'] = '';
63 $forked_item[$item_id]['item_serial'] .= '@'.time();
64 $forked_item[$item_id]['status_id'] = $status_id;
65 $forked_item[$item_id]['item_quantity'] = $quantity_removed;
66 $forked_item[$item_id]['item_price_in'] = $quantity_removed * $model_price_in;
67 $forked_item[$item_id]['item_price_out'] = $quantity_removed * $model_price_out;
68 $forked_item[$item_id]['item_customer'] = $item_customer;
5389f01c 69 $forked_item[$item_id]['item_date_sold'] = date('Y-m-d');
5ef6c52f
TM
70
71 $forked_hide_cols = array_merge($hide_cols_common,array('item_price_out'));
72 }
73
74 $columns = $this->db->get_columns('item');
75 $selectbox = $this->db->columns_get_selectbox($columns, 'item');
ec28d06c
TM
76
77 $action = $_SERVER['SCRIPT_NAME']."/item/$item_id/edit";
5ef6c52f
TM
78 //echo $this->html->render_insert_form('item', $columns, $selectbox, $current, $hide_cols, $action);
79
80 $insert_form[]=array('item', $columns, $selectbox, $current, $hide_cols, $action, false);
81 if(!$model_countable) $insert_form[]=array('item', $columns, $selectbox, $forked_item, $forked_hide_cols, $action, false);
82 echo $this->html->render_insert_form_multi($insert_form);
ec28d06c
TM
83 break;
84}
This page took 0.659897 seconds and 4 git commands to generate.