create money log
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 21 Dec 2008 18:49:39 +0000 (18:49 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 21 Dec 2008 18:49:39 +0000 (18:49 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@224 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/inc/classes/order.php
www/inc/classes/voucher.php
www/inc/db/db.php
www/inc/db/db_scheme.php

index 2ce4a91..91db946 100644 (file)
@@ -253,6 +253,7 @@ class Order
                        $this->amountpaid=$totalprice;
                }
 //             print(4);
+               $db->mkLog(array("orderid"=>$this->orderid,"orderpaid"=>$this->amountpaid,"orderdue"=>$totalprice),tr("create order"));
                //end
                $db->commitTransaction();
                return true;
@@ -665,6 +666,7 @@ class Order
                $db->update("voucher",array("price"=>0,"value"=>0,"isused"=>0),"orderid=".$db->escapeInt($this->orderid));
                //set order to cancelled
                $db->update("order",array("status"=>ORDER_CANCELLED,"senttime"=>time()),"orderid=".$db->escapeInt($this->orderid));
+               $db->mkLog(array("orderid"=>$this->orderid,"orderdue"=>0,"orderpaid"=>$this->amountpaid),tr("order cancelled"));
                $db->commitTransaction();
                return true;
        }
@@ -697,10 +699,12 @@ class Order
                        return false;
                }
                //set new status
-               $set=array("status"=>$mode);
+               $due=$this->totalPrice();
+               $set=array("status"=>$mode,"amountpaid"=>0);
                if($mode==ORDER_SOLD)
-                       $set["amountpaid"]=$this->totalPrice();
+                       $set["amountpaid"]=$due;
                $db->update("order",$set,"orderid=".$db->escapeInt($this->orderid));
+               $db->mkLog(array("orderid"=>$this->orderid,"orderpaid"=>$set["amountpaid"],"orderdue"=>$due),tr("reservation to order"));
                $db->commitTransaction();
                return true;
        }
@@ -808,7 +812,7 @@ function getOrderListXml($where="")
        global $db;
        $xml=new DomDocument;
        $doc=$xml->createElement("OrderList");
-       $res=$db->select("order","orderid,customerid,status,amountpaid,shippingtype,shippingcosts",$where);
+       $res=$db->select("order","orderid,customerid,status,amountpaid,shippingtype,shippingcosts",$where,"ORDER BY orderid DESC");
        foreach($res as $ord){
                $price=0;
                //check shipping
@@ -914,6 +918,7 @@ function orderPayXml($data,$factor)
        //correct DB
        $amt2=$res[0]["amountpaid"]+($amt*$factor);
        $db->update("order",array("amountpaid"=>$amt2),"orderid=".$db->escapeInt($oid));
+       $db->mkLog(array("orderid"=>$oid,"orderpaid"=>$amt2,"moved"=>$amt),$factor>0?tr("payment"):tr("refund"));
        $db->commitTransaction();
        //output
        header("X-MagicSmoke-Status: Ok");
@@ -1116,6 +1121,7 @@ function setOrderShippingXml($txt)
        $db->commitTransaction();
        //dump order object
        $ord=new Order($oid);
+       $db->mkLog(array("orderid"=>$oid,"orderpaid"=>$ord->amountPaid(),"orderdue"=>$ord->totalPrice()),tr("shipping changed"));
        header("X-MagicSmoke-Status: Ok");
        $ord->dumpXml();
 }
index f103e3b..7fbf1f4 100644 (file)
@@ -117,6 +117,7 @@ class Voucher
                }
                //overwrite
                $db->update("voucher",array("price"=>0,"value"=>0,"isused"=>0),"voucherid=".$db->escapeString($this->voucherid));
+               $db->mkLog(array("voucherid"=>$this->voucherid, "vouchervalue"=>0),tr("cancel voucher"));
                $db->commitTransaction();
                return true;
        }
@@ -130,6 +131,7 @@ class Voucher
                //now do the deed
                global $db;
                $db->update("voucher",array("value"=>0,"isused"=>1),"voucherid=".$db->escapeString($this->voucherid));
+               $db->mkLog(array("voucherid"=>$this->voucherid, "vouchervalue"=>0),tr("empty voucher"));
        }
        
        /**create the voucher in the database; returns false on failue*/
@@ -152,9 +154,10 @@ class Voucher
                        $db->rollbackTransaction();
                        return false;
                }
+               $db->mkLog(array("voucherid"=>$vid, "vouchervalue"=>value, "orderid"=>$orderid),tr("create voucher"));
                $db->commitTransaction();
                $this->voucherid=$vid;
-               $this->orderid=$oroderid;
+               $this->orderid=$orderid;
                $this->price=$price+0;
                $this->value=$value+0;
                $this->isused=false;
@@ -215,6 +218,7 @@ class Voucher
                        $db->rollbackTransaction();
                        return false;
                }
+               $db->mkLog(array("voucherid"=>$this->voucherid,"orderid"=>$orderid,"orderdue"=>$adue,"orderpaid"=>$a,"vouchervalue"=>$this->value,"moved"=>$pay),tr("pay with voucher"));
                //whoo. got it!
                $db->commitTransaction();
                return true;
index a047153..ca628ee 100644 (file)
@@ -538,6 +538,17 @@ abstract class DbEngine
                fclose($fd);
                $this->unlockDB();
        }
+       
+       
+       /**creates a log entry, the array must supply values for the moneylog table; time, username are generated automatically, the log entry is delivered via the second argument*/
+       public function mkLog(array $vals,$logtext)
+       {
+               global $session;
+               $vals["logtime"]=time();
+               $vals["uname"]=$session->getUser();
+               $vals["log"]=$logtext;
+               $this->insert("moneylog",$vals);
+       }
 };
 
 ?>
\ No newline at end of file
index 98b047f..c2af52f 100644 (file)
@@ -204,6 +204,21 @@ class DbScheme {
                );
                $this->backup[]="voucher";
                
+               //money transaction log
+               $this->scheme["moneylog"]=array(
+                       "logid" => array("seq64","primarykey"),
+                       "logtime" => array("int64","notnull"),
+                       "uname" => array("string:64","foreignkey:users:uname","null"),
+                       "orderid" => array("int32","foreignkey:order:orderid","null"),
+                       "voucherid" => array("string:32","foreignkey:voucher:voucherid","null"),
+                       "moved" => array("int32","notnull"),
+                       "orderpaid" => array("int32","null"),
+                       "orderdue" => array("int32","null"),
+                       "vouchervalue" => array("int32","null"),
+                       "log" => array("string","notnull")
+               );
+               $this->backup[]="moneylog";
+               
                
                // /////////////////////////
                // Web-Interface Stuff