Reorganizace kodu pro generovani statistik
authorThomas Mudrunka <tomas@mudrunka.cz>
Wed, 23 Nov 2011 00:50:38 +0000 (01:50 +0100)
committerThomas Mudrunka <tomas@mudrunka.cz>
Wed, 23 Nov 2011 00:50:38 +0000 (01:50 +0100)
assistants/lib/stats.inc.php [new file with mode: 0644]
assistants/stats.inc.php
assistants/stats/financial.inc.php [new file with mode: 0644]
assistants/stats/reserve.inc.php [new file with mode: 0644]
assistants/stats/stock.inc.php [new file with mode: 0644]

diff --git a/assistants/lib/stats.inc.php b/assistants/lib/stats.inc.php
new file mode 100644 (file)
index 0000000..1334822
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+$queries = array(); //TODO: use build_query_select()!!!
+foreach($stats as $stat) include("assistants/stats/$stat.inc.php");
+foreach($queries as $description => $sql) {
+       echo "<h2>$description</h2>";
+       echo $this->html->render_item_table($result = $this->db->safe_query_fetch($sql));
+}
index e46a6660ef443a9070592623314b2c3808f80805..56238d4ead629984a0cfea11a7d32e1d1f6fc355 100644 (file)
@@ -1,48 +1,3 @@
 <?php
-$month=date('Y-m');
-$month_sql='';
-if(isset($_GET['month'])) {
-       $month = htmlspecialchars($_GET['month']);
-       $month_sql = " AND DATE_FORMAT(item_valid_from, '%Y-%m') = ".$this->db->quote($_GET['month']);
-}
-
-echo $this->html->form($URL, 'GET', array(
-       array('month',$month,'text',false,'autofocus','YYYY-MM:'),
-       array(false,'SELECT BY MONTH','submit')
-));
-
-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,
-       "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_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)
-                       ) FROM item WHERE item_valid_till=0 AND ( status_id = 3 )$month_sql",
-       "Nutno koupit"
-               => 'SELECT room_id,room_name,model_id,model_name,model_barcode,model_reserve,'.
-               ' COUNT(item_id),SUM(item_quantity),model_reserve-SUM(item_quantity) as item_quantity_to_buy'.
-               ' 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'.
-               ' HAVING SUM(item_quantity)<model_reserve'.
-               ' ORDER BY room_id,model_id;',
-       "Ceník + Počet kusů skladem"
-               => 'SELECT room_id,room_name,model_id,model_name,model_barcode,model_price_out,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;',
-);
-
-foreach($queries as $description => $sql) {
-       echo "<h2>$description</h2>";
-       echo $this->html->render_item_table($result = $this->db->safe_query_fetch($sql));
-}
+$stats = array('financial','reserve','stock');
+include('lib/stats.inc.php');
diff --git a/assistants/stats/financial.inc.php b/assistants/stats/financial.inc.php
new file mode 100644 (file)
index 0000000..88464c8
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+$month=date('Y-m');
+$month_sql='';
+if(isset($_GET['month'])) {
+       $month = htmlspecialchars($_GET['month']);
+       $month_sql = " AND DATE_FORMAT(item_valid_from, '%Y-%m') = ".$this->db->quote($_GET['month']);
+}
+
+echo $this->html->form($URL, 'GET', array(
+       array('month',$month,'text',false,'autofocus','YYYY-MM:'),
+       array(false,'SELECT BY MONTH','submit')
+));
+
+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,
+       "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_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)
+                       ) FROM item WHERE item_valid_till=0 AND ( status_id = 3 )$month_sql",
+);
diff --git a/assistants/stats/reserve.inc.php b/assistants/stats/reserve.inc.php
new file mode 100644 (file)
index 0000000..8277814
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+$queries += array(
+       "Nutno koupit"
+               => 'SELECT room_id,room_name,model_id,model_name,model_barcode,model_reserve,'.
+               ' COUNT(item_id),SUM(item_quantity),model_reserve-SUM(item_quantity) as item_quantity_to_buy'.
+               ' 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'.
+               ' HAVING SUM(item_quantity)<model_reserve'.
+               ' ORDER BY room_id,model_id;',
+);
diff --git a/assistants/stats/stock.inc.php b/assistants/stats/stock.inc.php
new file mode 100644 (file)
index 0000000..8067a77
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+$queries += array(
+       "Ceník + Počet kusů skladem"
+               => 'SELECT room_id,room_name,model_id,model_name,model_barcode,model_price_out,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;',
+);
This page took 0.125135 seconds and 4 git commands to generate.