Commit | Line | Data |
---|---|---|
049a7400 TM |
1 | <?php |
2 | $month=date('Y-m'); | |
3 | $month_sql=''; | |
c8fe68ff TM |
4 | $month_sql_bought=''; |
5 | $month_sql_sold=''; | |
049a7400 TM |
6 | if(isset($_GET['month'])) { |
7 | $month = htmlspecialchars($_GET['month']); | |
c8fe68ff TM |
8 | $month_q = $this->db->quote($_GET['month']); |
9 | $month_sql = " AND DATE_FORMAT(item_valid_from, '%Y-%m') = ".$month_q; | |
10 | $month_sql_bought = " AND DATE_FORMAT(item_date_bought, '%Y-%m') = ".$month_q; | |
11 | $month_sql_sold = " AND DATE_FORMAT(item_date_sold, '%Y-%m') = ".$month_q; | |
049a7400 TM |
12 | } |
13 | ||
14 | echo $this->html->form($URL, 'GET', array( | |
bf9a965c | 15 | array('month',$month,'text',false,'','YYYY-MM:'), |
049a7400 TM |
16 | array(false,'SELECT BY MONTH','submit') |
17 | )); | |
18 | ||
19 | if($month_sql == '') $month=''; | |
20 | $queries += array( //TODO: use build_query_select()!!! | |
21 | "Nakoupeno celkem $month" | |
c8fe68ff | 22 | => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0'.$month_sql_bought, |
049a7400 | 23 | "Použito celkem $month" |
c8fe68ff | 24 | => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 2'.$month_sql_sold, |
049a7400 | 25 | "Prodáno celkem $month" |
c8fe68ff | 26 | => 'SELECT COUNT(item_id),SUM(item_price_out),SUM(item_price_in),(SUM(item_price_out)-SUM(item_price_in)) as sale_profit FROM item WHERE item_valid_till=0 AND status_id = 3'.$month_sql_sold, |
049a7400 TM |
27 | "Skladem celkem $month" |
28 | => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 1'.$month_sql, | |
29 | "Bilance celkem =(prodej - všechny nákupy) $month" | |
c8fe68ff TM |
30 | => "SELECT ( |
31 | SUM(item_price_out) | |
32 | -(SELECT SUM(item_price_in) FROM item WHERE item_valid_till=0$month_sql_bought) | |
33 | ) FROM item WHERE item_valid_till=0 AND ( status_id = 3 )$month_sql_sold", | |
049a7400 | 34 | ); |