Podpora kasy
authorThomas Mudrunka <tomas@mudrunka.cz>
Fri, 24 May 2013 23:58:48 +0000 (01:58 +0200)
committerThomas Mudrunka <tomas@mudrunka.cz>
Fri, 24 May 2013 23:58:48 +0000 (01:58 +0200)
assistants/bank.inc.php [new file with mode: 0644]
index.php
locale/cs/messages.inc.php

diff --git a/assistants/bank.inc.php b/assistants/bank.inc.php
new file mode 100644 (file)
index 0000000..4c64d0d
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+$bank_currency='Kč';
+
+function bank_name($name) {
+       return strtolower(trim($name));
+}
+
+function bank_transaction($ctx, $from, $to, $comment, $amount=0) {
+       $author=$ctx->db->quote($ctx->db->auth->get_user_id());
+       $from=$ctx->db->quote(bank_name($from));
+       $to=$ctx->db->quote(bank_name($to));
+
+       $comment=trim($comment);
+       if(strlen($comment)<4) die("Komentář musí mít alespoň 4 znaky!");
+       $comment=$ctx->db->quote($comment);
+
+       $sql="INSERT INTO `bank` (`bank_time`, `bank_from`, `bank_to`, `bank_amount`, `bank_author`, `bank_comment`) VALUES (now(), $from, $to, $amount, $author, $comment);";
+       $ctx->db->safe_query($sql);
+}
+
+function bank_get_accounts($ctx) {
+       $fetch = $ctx->db->safe_query_fetch('SELECT DISTINCT bank_to FROM bank ORDER BY bank_to;');
+       foreach($fetch as $account) $accounts[]=$account['bank_to'];
+       return $accounts;
+}
+
+function bank_add_account($ctx, $name) {
+       bank_transaction($ctx, $name, $name, "Created account \"$name\"");
+}
+
+if(isset($_POST['create_account'])) {
+       bank_add_account($this, $_POST['account_name']);
+       $this->post_redirect_get("$URL_INTERNAL","Účet byl vytvořen");
+}
+if(isset($_POST['transaction'])) {
+       bank_transaction($this, $_POST['account_from'], $_POST['account_to'], $_POST['comment'], $_POST['amount']);
+       $this->post_redirect_get("$URL_INTERNAL","Transakce byla provedena"); //TODO redirect na account_from
+}
+
+//bank_add_account($this, 'material');
+               echo("<a href='$URL/'>Banka</a> - ");
+               echo("<a href='$URL/admin'>Správa účtů</a> - ");
+               echo("Účty: ");
+               $accounts = bank_get_accounts($this);
+               foreach($accounts as $account) echo("<a href='$URL?account=$account'>$account</a>, ");
+
+switch($SUBPATH[0]) {
+       default:
+
+               if(!isset($_GET['account'])) {
+                       echo("<h1>Banka</h1>");
+           $result = $this->db->safe_query_fetch("SELECT SUM(bank_amount) as troughput FROM bank;");
+                       echo("Obrat: ".$result[0]['troughput'].' '.$bank_currency);
+           $result = $this->db->safe_query_fetch("SELECT * FROM `bank` ORDER BY bank_time DESC;");
+               } else {
+                       $account=bank_name($_GET['account']);
+                       $account_sql=$this->db->quote($account);
+           $result = $this->db->safe_query_fetch("SELECT SUM(bank_amount) FROM `bank` WHERE `bank_to`=$account_sql;");
+                       $deposits = $result[0]['SUM(bank_amount)'];
+           $result = $this->db->safe_query_fetch("SELECT SUM(bank_amount) FROM `bank` WHERE `bank_from`=$account_sql;");
+                       $withdrawals = $result[0]['SUM(bank_amount)'];
+                       echo("<h1>Účet: ".$_GET['account']." (".($deposits-$withdrawals).$bank_currency.")</h1>");
+
+                       ?>
+                       <form action="?" method="POST">
+                               Převést <input type="number" name="amount" value="" /> <?php echo $bank_currency; ?>
+                               z účtu <?php echo $account; ?> <input type="hidden" name="account_from" value="<?php echo $account; ?>" />
+                               na účet <select name='account_to'>
+                                       <?php foreach($accounts as $acc) echo("<option value='$acc'>$acc</option>"); ?>
+                               </select> (pozor, dluhy se převádí opačným směrem než peníze!)<br />
+                               Důvod: <input type="text" name="comment" style="width:800px;" />
+                               <input type="submit" name="transaction" value="Převést" />
+                       </form>
+                       <?php
+
+                       echo("$deposits-$withdrawals $bank_currency");
+           $result = $this->db->safe_query_fetch("SELECT * FROM `bank` WHERE `bank_to`=$account_sql OR `bank_from`=$account_sql ORDER BY bank_time DESC;");
+               }
+         echo $this->html->render_item_table($result);
+
+
+               break;
+       case 'admin':
+?>
+       <form action="<?php echo $ASSISTANT; ?>" method="POST" >
+               Account name:
+               <input type="text" name="account_name" />
+               <input type="submit" name="create_account" value="Create account" />
+       </form>
+<?php
+               break;
+}
index c8a746d5d1781040f4af1a506f3ea95daa524fa7..a81433445999be3e5b8661501203e188c11de4e1 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -737,7 +737,8 @@ class Sklad_DB extends PDO {
        function load_backend_data_to_query_results(&$result,$suffix_backend='_backend') {
                $translate_cols = array(
                        'item_author' => 'return($this->auth->get_username_by_id($result[$key][$col]));',
-                       'lock_author' => 'return($this->auth->get_username_by_id($result[$key][$col]));'
+                       'lock_author' => 'return($this->auth->get_username_by_id($result[$key][$col]));',
+                       'bank_author' => 'return($this->auth->get_username_by_id($result[$key][$col]));'
                ); //TODO: Hardcoded
                foreach($result as $key => $row) {
                        foreach($translate_cols as $col => $backend) if(isset($result[$key][$col])){
index d7a4b8a3be0e47a7ebc54ca5bd97a76d0661f976..2bef64015c58c96b2b06f5c9736e501b7aaaaa13 100644 (file)
@@ -57,6 +57,15 @@ $LOCALE_MESSAGES = array(
                'status_name' => 'Stav',
                'category_name' => 'Kategorie',
 
+               'bank_id' => 'Transakce',
+               'bank_time' => 'Čas',
+               'bank_from' => 'Zdrojový účet',
+               'bank_to' => 'Cílový účet',
+               'bank_amount' => 'Částka',
+               'bank_author' => 'Odpověný',
+               'bank_author_backend' => 'Odpověný',
+               'bank_comment' => 'Popis',
+
                'model_relations' => 'Souvisejici s timto modelem',
                'category_relations' => 'V teto kategorii',
                'producer_relations' => 'Od tohoto vyrobce',
This page took 0.169043 seconds and 4 git commands to generate.