//TODO: Add support for selling/disposing multiple items at once...
//TODO: Reuse /item/$item_id/edit
//TODO: Stop using map_unique()!!!
+//TODO: we can use empty selectbox[] if no selectboxes are shown
switch($SUBPATH[0]) {
default: case 1:
echo $this->html->form("$URL/2", 'GET', array(
$item_id = $this->db->map_unique('item_serial', $item_serial, 'item_id', 'item');
$current = $this->db->get_listing('item', $item_id, 1);
- $current[$item_id]['item_customer'] = 0;
+ $forked_item = $current;
- $disable_cols = array('status_id','item_price_in','item_customer','item_serial','item_quantity','model_id','vendor_id','room_id');
+ $disable_cols = array('status_id','item_price_in','item_serial','item_quantity','model_id','vendor_id','room_id','item_customer');
$model_id = $this->db->map_unique('item_serial', $item_serial, 'model_id', 'item');
$model_price_in = $this->db->map_unique('model_id', $model_id, 'model_price_in', 'model');
$model_price_out = $this->db->map_unique('model_id', $model_id, 'model_price_out', 'model');
- if($this->db->map_unique('model_id', $model_id, 'model_countable', 'model')) {
+ $model_countable = $this->db->map_unique('model_id', $model_id, 'model_countable', 'model');
+ if($model_countable) {
$current[$item_id]['status_id'] = 2;
+ $current[$item_id]['item_customer'] = 0;
$item_quantity = 1;
$current[$item_id]['item_price_out'] = $model_price_out;
} else {
- $disable_cols = array_merge($disable_cols,array('item_price_out'));
+ $disable_cols = array_merge($disable_cols,array('item_price_out','item_note'));
$quantity_removed = $_GET['quantity'];
if($quantity_removed <= 0) $this->post_redirect_get("$URL_INTERNAL/1","Can't dispose non-possitive amount of items!");
if(!is_numeric($quantity_removed)) $quantity_removed = 1;
$quantity_stored = $this->db->map_unique('item_serial', $item_serial, 'item_quantity', 'item', false);
if(!is_numeric($quantity_stored)) $quantity_stored = 0;
- echo("Quantity stored: ".$quantity_stored);
-
$item_quantity = $quantity_stored - $quantity_removed;
- $current[$item_id]['item_quantity'] = $item_quantity;
+
+ echo("Stock: ".$quantity_stored."<br />Disposing/Selling: ".$quantity_removed."<br />Keeping: ".$item_quantity);
+
+ $current[$item_id]['item_quantity'] = $item_quantity;
$current[$item_id]['item_price_in'] = $item_quantity * $model_price_in;
$current[$item_id]['item_price_out'] = $item_quantity * $model_price_out;
+
+ $forked_item[$item_id]['item_id'] = '';
+ $forked_item[$item_id]['item_serial'] .= '@'.time();
+ $forked_item[$item_id]['status_id'] = '2';
+ $forked_item[$item_id]['item_quantity'] = $quantity_removed;
+ $forked_item[$item_id]['item_price_in'] = $quantity_removed * $model_price_in;
+ $forked_item[$item_id]['item_price_out'] = $quantity_removed * $model_price_out;
+ $forked_item[$item_id]['item_customer'] = 0;
+
+ $forked_disable_cols = array('model_id','vendor_id','item_serial','item_quantity','room_id','status_id','item_price_in','item_price_out','item_customer');
}
$columns = $this->db->get_columns('item');
$action = $_SERVER['SCRIPT_NAME']."/item/$item_id/edit";
//echo $this->html->render_insert_form('item', $columns, $selectbox, $current, $disable_cols, $action);
- echo $this->html->render_insert_form_multi(array(
- //array('item', $columns, $selectbox, $current, $disable_cols, $action),
- array('item', $columns, $selectbox, $current, $disable_cols, $action)
- ));
+
+ $insert_form[]=array('item', $columns, $selectbox, $current, $disable_cols, $action, false);
+ if(!$model_countable) $insert_form[]=array('item', $columns, $selectbox, $forked_item, $forked_disable_cols, $action, false);
+ echo $this->html->render_insert_form_multi($insert_form);
break;
}
"Použito celkem $month"
=> 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 2'.$month_sql,
"Prodáno celkem $month"
- => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 3'.$month_sql,
+ => 'SELECT COUNT(item_id),SUM(item_price_out) FROM item WHERE item_valid_till=0 AND status_id = 3'.$month_sql,
+ "Skladem celkem $month"
+ => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 1'.$month_sql,
+ "Bilance celkem $month"
+ => 'SELECT (
+ SUM(item_price_out)
+ -(SELECT SUM(item_price_in) FROM item WHERE item_valid_till=0)
+ ) FROM item WHERE item_valid_till=0 AND ( status_id = 3 )',
"Počet kusů skladem"
- => 'SELECT room_id,room_name,model_id,model_name,model_barcode,COUNT(item_id)'.
+ => 'SELECT room_id,room_name,model_id,model_name,model_barcode,COUNT(item_id),SUM(item_quantity)'.
' FROM item LEFT JOIN model USING(model_id) LEFT JOIN room USING(room_id)'.
' WHERE item_valid_till=0 AND status_id=1'.
' GROUP BY model_id,room_id'.
- ' ORDER BY room_id,model_id;'
+ ' ORDER BY room_id,model_id;',
);
foreach($queries as $description => $sql) {
}
if(!isset($array[$key+1])) {
$parts[]='foot';
- }
- $args[] = true;
+ $hr = '';
+ } else $hr = '<hr />';
+ //$args[] = false;
$args[] = $parts;
$html .= call_user_func_array(array($this, 'render_insert_form'), $args);
+ $html .= $hr;
}
return $html;
}
if(!is_array($parts) || in_array('head', $parts)) {
$action = $action ? " action='$action'" : false;
$html.="<form$action method='POST'>"; //TODO: use $this->form()
- if($multi_insert) $html.='<span><div name="input_set" style="float:left; border:1px solid grey; padding: 1px; margin: 1px;">';
+ $html.='<span><div name="input_set" style="float:left; border:1px solid grey; padding: 1px; margin: 1px;">';
}
if(!is_array($parts) || in_array('inputs', $parts))
$html.=$this->render_insert_inputs($class,$columns,$selectbox,$current,$hidecols,$update);
if(!is_array($parts) || in_array('foot', $parts)) {
+ $html .= '</div></span><br style="clear:both" />';
if($multi_insert) { //TODO, move to separate JS file
$html.=<<<EOF
- </div></span>
- <br style="clear:both" />
<script>
function duplicate_element(what, where) {
var node = document.getElementsByName(what)[0];
$sql .= " WHERE ${table}_valid_till=0 AND (";
$or = '';
foreach($values as $row) {
- $sql .= $or.' '.$table.'_id='.$row[$table.'_id'];
+ $sql .= $or.' '.$table.'_id='.$this->quote($row[$table.'_id']);
$or = ' OR';
}
$sql .= " );\n\n";