X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;ds=inline;f=assistants%2Fbank.inc.php;h=e83af443b4fc529a3021b49676cbbc61ade0c25e;hb=2f7961270e722754ae6aff23da2251c98b711e8b;hp=d01d8c45816b45597956a997915a3ec5152a07e2;hpb=1d0a5f85672a3f037ede7da7e5aa2c28d55c9af6;p=mirrors%2FSokoMan.git
diff --git a/assistants/bank.inc.php b/assistants/bank.inc.php
index d01d8c4..e83af44 100644
--- a/assistants/bank.inc.php
+++ b/assistants/bank.inc.php
@@ -2,6 +2,7 @@
$bank_currency='KÄ';
global $bank_table;
$bank_table='transaction';
+$recursive=true; //USE RECURSIVE QUERIES???
function bank_name($name) {
return strtolower(trim($name));
@@ -37,12 +38,22 @@ function bank_add_account($ctx, $name) {
bank_transaction($ctx, $name, $name, "Created account \"$name\"");
}
-function bank_get_total($ctx, $account, $string=false) {
+function bank_month_sql($ctx, $month=false) {
+ global $bank_table;
+ $month_sql = 'TRUE';
+ if(!is_bool($month)) {
+ $month_q = $ctx->db->quote($month);
+ $month_sql .= " AND DATE_FORMAT(${bank_table}_time, '%Y-%m') = ".$month_q;
+ }
+ return $month_sql;
+}
+
+function bank_get_total($ctx, $account, $month, $string=false) {
global $bank_table;
$account_sql=$ctx->db->quote($account);
- $result = $ctx->db->safe_query_fetch("SELECT SUM(${bank_table}_amount) FROM `${bank_table}` WHERE `${bank_table}_to`=$account_sql;");
+ $result = $ctx->db->safe_query_fetch("SELECT SUM(${bank_table}_amount) FROM `${bank_table}` WHERE `${bank_table}_to`=$account_sql AND ".bank_month_sql($ctx,$month).';');
$deposits = $result[0]["SUM(${bank_table}_amount)"];
- $result = $ctx->db->safe_query_fetch("SELECT SUM(${bank_table}_amount) FROM `${bank_table}` WHERE `${bank_table}_from`=$account_sql;");
+ $result = $ctx->db->safe_query_fetch("SELECT SUM(${bank_table}_amount) FROM `${bank_table}` WHERE `${bank_table}_from`=$account_sql AND (".bank_month_sql($ctx,$month).');');
$withdrawals = $result[0]["SUM(${bank_table}_amount)"];
if($string) return "$deposits-$withdrawals";
return $deposits-$withdrawals;
@@ -61,56 +72,88 @@ function bank_rename_account($ctx, $old, $new) {
);
}
-function bank_get_overview($ctx) {
+function bank_get_overview($ctx,$prefix='',$month=false) {
global $bank_table;
$accounts = bank_get_accounts($ctx);
- foreach($accounts as $acc) $overview[]=array("${bank_table}_account"=>$acc,"${bank_table}_total"=>bank_get_total($ctx, $acc));
+ foreach($accounts as $acc) {
+ $total=bank_get_total($ctx, $acc, $month);
+ $overview['table'][]=array("${prefix}account"=>$acc,"${prefix}total"=>$total);
+ $overview['array'][$acc]=$total;
+ }
return $overview;
}
+if(isset($bank_json_only) && $bank_json_only) {
+ $overview=bank_get_overview($this,'');
+ die(json_encode(array(
+ 'overview'=>$overview['array']
+ )));
+}
+
if(isset($_POST['create_account'])) {
- bank_add_account($this, $_POST['account_name']);
- $this->post_redirect_get("$URL_INTERNAL","ÃÄet byl vytvoÅen");
+ $new_account=$_POST['account_name'];
+ bank_add_account($this, $new_account);
+ $this->post_redirect_get("$URL_INTERNAL/admin","ÃÄet $new_account byl vytvoÅen!");
}
if(isset($_POST['rename_account'])) {
+ $new_account=$_POST['account_new'];
+ $old_account=$_POST['account_old'];
if(bank_rename_account($this, $_POST['account_old'], $_POST['account_new'])) {
- $this->post_redirect_get("$URL_INTERNAL","ÃÄet byl upraven");
+ $this->post_redirect_get("$URL_INTERNAL/admin","ÃÄet $old_account byl pÅejmenován na $new_account!");
} else {
- $this->post_redirect_get("$URL_INTERNAL","Takový úÄet již existuje!", false);
+ $this->post_redirect_get("$URL_INTERNAL/admin","ÃÄet $new_account již existuje!", false);
}
}
if(isset($_POST['transaction'])) {
- if(!is_numeric($_POST['amount']) || $_POST['amount'] < 0) $this->post_redirect_get("$URL_INTERNAL?account=".$_POST['account_from'],"Lze pÅevádÄt jen kladné Äástky", true);
+ $account_from=$_POST['account_from'];
+ $account_to=$_POST['account_to'];
+ $amount=$_POST['amount'];
$comment=trim($_POST['comment']);
- if(strlen($comment)<4) $this->post_redirect_get("$URL_INTERNAL?account=".$_POST['account_from'],"KomentáŠmusà mÃt alespoÅ 4 znaky!",true);
- bank_transaction($this, $_POST['account_from'], $_POST['account_to'], $_POST['comment'], $_POST['amount']);
- $this->post_redirect_get("$URL_INTERNAL?account=".$_POST['account_from'],"Transakce byla provedena");
+ if(!is_numeric($amount) || $amount < 0) $this->post_redirect_get("$URL_INTERNAL?account=".$account_from,"Lze pÅevádÄt jen kladné Äástky", true);
+ if(strlen($comment)<4) $this->post_redirect_get("$URL_INTERNAL?account=".$account_from,"KomentáŠmusà mÃt alespoÅ 4 znaky!",true);
+ bank_transaction($this, $account_from, $account_to, $comment, $amount);
+ $this->post_redirect_get("$URL_INTERNAL?account=".$account_from,"Transakce byla provedena:
PÅevod $amount $bank_currency z úÄtu $account_from na úÄet $account_to.
($comment)");
}
+$month = isset($_GET['month']) ? $_GET['month'] : false;
+
//bank_add_account($this, 'material');
echo("Banka - ");
echo("Správa úÄtů - ");
-echo("ÃÄty: ");
+echo('');
+echo $this->html->form($URL, 'GET', array(
+ array('month',$month,'text',false,'','YYYY-MM:'),
+ array(false,'SELECT BY MONTH','submit')
+));
+echo('');
+echo("ÃÄty:
");
$accounts = bank_get_accounts($this, $SUBPATH[0]=='admin');
-foreach($accounts as $account) echo("$account, ");
+$lastaccount=false;
+foreach($accounts as $account) {
+ if($lastaccount && $lastaccount[0]!=$account[0] && !preg_match('/[a-zA-Z0-9]/', $lastaccount[0])) echo('
');
+ echo("$account, ");
+ $lastaccount=$account;
+}
+
+
switch($SUBPATH[0]) {
default:
if(!isset($_GET['account'])) {
- echo("