$pageNumber = is_null($_GET["page"]) ? 1 : $_GET["page"]; $page = $pageNumber - 1; $recordsPerPage = is_null($_GET["rp"]) ? 10 : $_GET["rp"]; $offset = $page * $recordsPerPage; $sortName = is_null($_GET["sortname"]) ? "tdate" : $_GET["sortname"]; $sortOrder = is_null($_GET["sortorder"]) ? "desc" : $_GET["sortorder"]; $searchQuery = is_null($_GET["query"]) ? null : trim($_GET["query"]); $searchQueryType = is_null($_GET["qtype"]) ? null : $_GET["qtype"]; $searchCondition = ""; if (!(is_null($searchQuery) || empty($searchQuery)) && !(is_null($searchQueryType) || empty($searchQueryType))) { $searchCondition = $searchQueryType . " LIKE '%" . $searchQuery . "%'"; } $valueCondition = $_GET["type"] == $transaction_type->income ? "in_amount>0 AND out_amount=0" : ($_GET["type"] == $transaction_type->expenses ? "in_amount=0 AND out_amount>0" : ""); $q = new MySqlSelect(); $q->COLUMNS("COUNT(*) as total, SUM(" . tbl_transactions::$in_amount . ") as inTotal, SUM(" . tbl_transactions::$out_amount . ") as outTotal"); $q->FROM(tbl_transactions::tableName()); $q->JOIN(tbl_stores::tableName()); $q->JOIN(tbl_tags::tableName()); if (!empty($valueCondition)) { $q->ADD_CONDITION($valueCondition); } $q->ADD_CONDITION("tdate BETWEEN " . $fromDate . " AND " . $toDate); if (!empty($searchCondition)) { $q->ADD_CONDITION($searchCondition); } $q->ADD_CONDITION(tbl_transactions::$istransfer . "='0'"); $q->ADD_CONDITION(tbl_transactions::tableName() . "." . tbl_transactions::$store_id . "=" . tbl_stores::tableName() . "." . tbl_stores::getPrimaryKeyField()); $q->ADD_CONDITION(tbl_transactions::tableName() . "." . tbl_transactions::$tag_id . "=" . tbl_tags::tableName() . "." . tbl_tags::getPrimaryKeyField()); //Debug($q->toString()); $results = db::MySqlSubmitQuery($q->toString()); if ($results) {
require_once "constants.php"; $cache = "<?php"; //special handling for stores table (creating stores cache) $selectStores = new MySqlSelect(); $selectStores->COLUMNS("*"); $selectStores->FROM("stores"); $selectStores->ADD_SORT("store_name", "desc"); $storesResult = db::MySqlSubmitQuery($selectStores->toString()); if ($storesResult) { $cache .= $newLine . "class db_cache_store{"; while ($storesResultRow = mysql_fetch_array($storesResult, MYSQL_ASSOC)) { $cache .= $newLine . " public static \$" . "_" . cleanName($storesResultRow["store_name"]) . " = array(id => " . $storesResultRow["id"] . " , name => '" . $storesResultRow["store_name"] . "', default_tag_id => '" . $storesResultRow["default_tag_id"] . "');"; } $cache .= $newLine . "}"; } //special handling for tags table (creating stores cache) $selectTags = new MySqlSelect(); $selectTags->COLUMNS("*"); $selectTags->FROM("tags"); $selectTags->ADD_SORT("tag_name", "desc"); $tagsResult = db::MySqlSubmitQuery($selectTags->toString()); if ($tagsResult) { $cache .= $newLine . "class db_cache_tag{"; while ($tagsResultRow = mysql_fetch_array($tagsResult, MYSQL_ASSOC)) { $cache .= $newLine . " public static \$" . "_" . cleanName($tagsResultRow["tag_name"]) . " = array(id => " . $tagsResultRow["id"] . " , name => '" . $tagsResultRow["tag_name"] . "');"; } $cache .= $newLine . "}"; } $cache .= $newLine . "?>"; file_put_contents("cache.php", $cache); echo 'complete.';