Betaverze novych financnich statistik
authorThomas Mudrunka <tomas@mudrunka.cz>
Thu, 12 Apr 2012 09:59:27 +0000 (11:59 +0200)
committerThomas Mudrunka <tomas@mudrunka.cz>
Thu, 12 Apr 2012 09:59:27 +0000 (11:59 +0200)
assistants/stats/financial.inc.php

index 3f38df3c0a49cf0a878f917ecedf815d0efab156..d06edba9a608c3798371c9eb6bb7aac2e00ea2db 100644 (file)
@@ -1,9 +1,14 @@
 <?php
 $month=date('Y-m');
 $month_sql='';
+$month_sql_bought='';
+$month_sql_sold='';
 if(isset($_GET['month'])) {
        $month = htmlspecialchars($_GET['month']);
-       $month_sql = " AND DATE_FORMAT(item_valid_from, '%Y-%m') = ".$this->db->quote($_GET['month']);
+       $month_q = $this->db->quote($_GET['month']);
+       $month_sql = " AND DATE_FORMAT(item_valid_from, '%Y-%m') = ".$month_q;
+       $month_sql_bought = " AND DATE_FORMAT(item_date_bought, '%Y-%m') = ".$month_q;
+       $month_sql_sold = " AND DATE_FORMAT(item_date_sold, '%Y-%m') = ".$month_q;
 }
 
 echo $this->html->form($URL, 'GET', array(
@@ -14,14 +19,23 @@ echo $this->html->form($URL, 'GET', array(
 if($month_sql == '') $month='';
 $queries += array( //TODO: use build_query_select()!!!
        "Nakoupeno celkem $month"
+               => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0'.$month_sql_bought,
+       "<strike>Nakoupeno celkem $month</strike>"
                => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0'.$month_sql,
        "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,
+               => 'SELECT COUNT(item_id),SUM(item_price_in) FROM item WHERE item_valid_till=0 AND status_id = 2'.$month_sql_sold,
        "Prodáno celkem $month"
+               => '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,
+       "<strike>Prodáno celkem $month</strike>"
                => '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,
        "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 =(prodej - všechny nákupy) $month"
+               => "SELECT (
+                               SUM(item_price_out)
+                               -(SELECT SUM(item_price_in) FROM item WHERE item_valid_till=0$month_sql_bought)
+                       ) FROM item WHERE item_valid_till=0 AND ( status_id = 3 )$month_sql_sold",
+       "<strike>Bilance celkem =(prodej - všechny nákupy) $month</strike>"
                => "SELECT (
                                SUM(item_price_out)
                                -(SELECT SUM(item_price_in) FROM item WHERE item_valid_till=0$month_sql)
This page took 0.099038 seconds and 4 git commands to generate.