show moneylog
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 22 Dec 2008 16:28:50 +0000 (16:28 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Mon, 22 Dec 2008 16:28:50 +0000 (16:28 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@226 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/moneylog.cpp [new file with mode: 0644]
src/moneylog.h [new file with mode: 0644]
src/orderwin.cpp
src/orderwin.h
src/overview.cpp
src/overview.h
src/smoke.pro
www/inc/classes/order.php
www/inc/classes/voucher.php
www/machine.php

diff --git a/src/moneylog.cpp b/src/moneylog.cpp
new file mode 100644 (file)
index 0000000..c77ab1e
--- /dev/null
@@ -0,0 +1,53 @@
+//
+// C++ Implementation: moneylog
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "moneylog.h"
+#include "webrequest.h"
+#include "misc.h"
+
+#include <QBoxLayout>
+#include <QPushButton>
+#include <QTextEdit>
+
+MMoneyLog::MMoneyLog(QWidget*pa,MWebRequest*req,QString q)
+       :QDialog(pa)
+{
+       //set title
+       QStringList sl=q.split("\n");
+       sl[0][0]=sl[0][0].toUpper();
+       setWindowTitle(tr("Money Log of %1 %2").arg(sl[0]).arg(sl[1]));
+       
+       //layout
+       QVBoxLayout*vl;
+       QHBoxLayout*hl;
+       QTextEdit*text;
+       QPushButton*p;
+       setLayout(vl=new QVBoxLayout);
+       vl->addWidget(text=new QTextEdit,10);
+       text->setReadOnly(true);
+       vl->addSpacing(15);
+       vl->addLayout(hl=new QHBoxLayout,0);
+       hl->addStretch(10);
+       hl->addWidget(p=new QPushButton(tr("Close")));
+       connect(p,SIGNAL(clicked()),this,SLOT(accept()));
+       
+       //query
+       if(req->request("moneylog",q.toAscii())){
+               if(req->responseStatus()==MWebRequest::Ok){
+                       text->setPlainText(QString::fromUtf8(req->responseBody()));
+               }else{
+                       text->setHtml("<h1>Error</h1>"+htmlize(QString::fromUtf8(req->responseBody())));
+               }
+       }else{
+               text->setHtml("<h1>Low Level Error</h1>Request failed.");
+       }
+}
\ No newline at end of file
diff --git a/src/moneylog.h b/src/moneylog.h
new file mode 100644 (file)
index 0000000..dbce7e3
--- /dev/null
@@ -0,0 +1,28 @@
+//
+// C++ Interface: moneylog
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_MONEYLOG_H
+#define MAGICSMOKE_MONEYLOG_H
+
+#include <QDialog>
+
+class MWebRequest;
+
+class MMoneyLog:public QDialog
+{
+       Q_OBJECT
+       public:
+               MMoneyLog(QWidget*,MWebRequest*req,QString);
+};
+
+
+#endif
index 7a027e3..1f7f69e 100644 (file)
@@ -14,6 +14,7 @@
 #include "event.h"
 #include "labeldlg.h"
 #include "misc.h"
+#include "moneylog.h"
 #include "odtrender.h"
 #include "orderwin.h"
 #include "ticketrender.h"
@@ -77,6 +78,11 @@ MOrderWindow::MOrderWindow(QWidget*par,MWebRequest*r,const MOrder&o)
        m->addAction(tr("Change Sh&ipping Method..."),this,SLOT(changeShipping()))
         ->setEnabled(req->hasRole("changeordershipping"));
        m->addSeparator();
+       m->addAction(tr("MoneyLog for Order..."),this,SLOT(moneyLogOrder()))
+        ->setEnabled(req->hasRole("moneylog"));
+       m->addAction(tr("MoneyLog for selected Voucher..."),this,SLOT(moneyLogVoucher()))
+        ->setEnabled(req->hasRole("moneylog"));
+       m->addSeparator();
        m->addAction(tr("&Close"),this,SLOT(close()));
        
        m=mb->addMenu(tr("&Payment"));
@@ -940,6 +946,33 @@ void MOrderWindow::changeShipping()
        m_total->setText(m_order.totalPriceString());
 }
 
+void MOrderWindow::moneyLogOrder()
+{
+       if(m_order.orderID()<0)return;
+       MMoneyLog ml(this,req,"order\n"+QString::number(m_order.orderID()));
+       ml.exec();
+}
+
+void MOrderWindow::moneyLogVoucher()
+{
+       if(m_order.orderID()<0)return;
+       //get selection
+       if(!m_order.isValid())return;
+       //get ticket selection
+       QModelIndexList lst=m_table->selectionModel()->selectedIndexes();
+       if(lst.size()<1)return;
+       QModelIndex idx=m_model->index(lst[0].row(),0);
+       QString id=m_model->data(idx).toString();
+       if(id=="")return;
+       int type=m_model->data(idx,Qt::UserRole).toInt();
+       if(type==ITEM_VOUCHER){
+               MMoneyLog ml(this,req,"voucher\n"+id);
+               ml.exec();
+       }else
+               QMessageBox::warning(this,tr("Warning"),tr("This is not a voucher, cannot show the money log."));
+}
+
+
 /*************************************************************************************/
 
 MOrderItemView::MOrderItemView(QWidget*w,MWebRequest*r,QList<MTicket>t,QList<MVoucher>v)
index 1d2d2fe..010595d 100644 (file)
@@ -102,6 +102,11 @@ class MOrderWindow:public QMainWindow
                
                /**prune and recheck the order*/
                void recheckOrder();
+               
+               /**money log for the order*/
+               void moneyLogOrder();
+               /**money log for a voucher*/
+               void moneyLogVoucher();
        
        private:
                MWebRequest*req;
index be375f7..386405f 100644 (file)
@@ -15,6 +15,7 @@
 #include "eventedit.h"
 #include "eventsummary.h"
 #include "misc.h"
+#include "moneylog.h"
 #include "orderwin.h"
 #include "overview.h"
 #include "webrequest.h"
@@ -114,6 +115,9 @@ MOverview::MOverview(MWebRequest*mw,QString pk)
        m->addAction(tr("Edit &Shipping Options..."),this,SLOT(editShipping()));
        m->addSeparator();
        m->addAction(tr("&Deduct from voucher..."),this,SLOT(deductVoucher()));
+       m->addSeparator();
+       m->addAction(tr("&Money Log for voucher..."),this,SLOT(moneylogVoucher()));
+       m->addAction(tr("Money Log for &user..."),this,SLOT(moneylogUser()));
        
        m=mb->addMenu(tr("C&onfigure"));
        m->addAction(tr("&Auto-Refresh settings..."),this,SLOT(setRefresh()));
@@ -1558,6 +1562,21 @@ void MOverview::backupSettings()
        }
 }
 
+void MOverview::moneylogVoucher()
+{
+       QString vid=QInputDialog::getText(this,tr("Voucher ID"),tr("Please enter voucher ID to show log:"));
+       if(vid!="")
+               MMoneyLog(this,req,"voucher\n"+vid).exec();
+}
+
+void MOverview::moneylogUser()
+{
+       QString vid=QInputDialog::getText(this,tr("User"),tr("Please enter login name of user to show log:"));
+       if(vid!="")
+               MMoneyLog(this,req,"user\n"+vid).exec();
+}
+
+
 /**********************************************/
 
 MBackupDialog::MBackupDialog(QWidget*par,QString pk,MWebRequest*req)
index 16cb73f..fa426e9 100644 (file)
@@ -142,6 +142,11 @@ class MOverview:public QMainWindow
                /**deduct some money from a voucher (to pay outside the system)*/
                void deductVoucher();
                
+               /**money log for voucher*/
+               void moneylogVoucher();
+               /**money log for user*/
+               void moneylogUser();
+               
                /**refresh data that we can refresh*/
                void refreshData();
                /**set refresh timeout*/
index a3dea82..1e554c8 100644 (file)
@@ -48,7 +48,8 @@ SOURCES = \
        templates.cpp \
        templatedlg.cpp \
        office.cpp \
-       centbox.cpp
+       centbox.cpp \
+       moneylog.cpp
 
 HEADERS = \
        keygen.h \
@@ -75,7 +76,8 @@ HEADERS = \
        templates.h \
        templatedlg.h \
        office.h \
-       centbox.h
+       centbox.h \
+       moneylog.h
        
 #some PHP files are listed in this file to scan them for translatable items
 #use genphpscan.sh to regenerate it.
index 91db946..d893924 100644 (file)
@@ -1226,4 +1226,62 @@ function changeReservationXml($oid,$mode)
        }       
 
 }
+
+function cent2str($c)
+{
+       $r=floor($c/100).".";
+       $c="".$c%100;
+       if(strlen($c)<2)$c="0".$c;
+       return $r.$c;
+}
+
+function moneylogXml($data)
+{
+       //split/validate data
+       $splt=explode("\n",$data);
+       if(count($splt)<2){
+               header("X-MagicSmoke-Status: Error");
+               echo tr("Expected 2 arguments: query type and ID.");
+               return;
+       }
+       //formulate query
+       global $db;
+       $query="";
+       switch(trim($splt[0])){
+               case "order":
+                       $query="orderid=".$db->escapeInt(trim($splt[1]));
+                       break;
+               case "voucher":
+                       $query="voucherid=".$db->escapeString(trim($splt[1]));
+                       break;
+               case "user":
+                       $query="uname=".$db->escapeString(trim($splt[1]));
+                       break;
+       }
+       if($query==""){
+               header("X-MagicSmoke-Status: Error");
+               echo tr("Invalid Query Type.");
+               return;
+       }
+       //query and print
+       header("X-MagicSmoke-Status: Ok");
+       $res=$db->select("moneylog","*",$query);
+       foreach($res as $row){
+               print(date(DATE_W3C,$row["logtime"])." ".$row["log"]." by ".$row["uname"]);
+               if(!$db->isNull($row["orderid"]))
+                       print(", order ".$row["orderid"]);
+               if(!$db->isNull($row["voucherid"]))
+                       print(", voucher ".$row["voucherid"]);
+               if(!$db->isNull($row["moved"]))
+                       print(", money moved ".cent2str($row["moved"]));
+               if(!$db->isNull($row["orderpaid"]))
+                       print(", now paid for order ".cent2str($row["orderpaid"]));
+               if(!$db->isNull($row["orderdue"]))
+                       print(", total price of order ".cent2str($row["orderdue"]));
+               if(!$db->isNull($row["vouchervalue"]))
+                       print(", remaining value of voucher ".cent2str($row["vouchervalue"]));
+               print("\n");
+       }
+}
+
 ?>
\ No newline at end of file
index 8c810f0..376b5bb 100644 (file)
@@ -154,7 +154,7 @@ class Voucher
                        $db->rollbackTransaction();
                        return false;
                }
-               $db->mkLog(array("voucherid"=>$vid, "vouchervalue"=>value, "orderid"=>$orderid),tr("create voucher"));
+               $db->mkLog(array("voucherid"=>$vid, "vouchervalue"=>$value, "orderid"=>$orderid),tr("create voucher"));
                $db->commitTransaction();
                $this->voucherid=$vid;
                $this->orderid=$orderid;
index 9fe7ed3..cbe7977 100644 (file)
@@ -51,7 +51,9 @@ $ALLOWEDREQUESTS=array(
        tr("gettemplatelist"),tr("gettemplate"),tr("settemplate"),tr("settemplatedescription"),
        tr("deletetemplate"),
        //backup
-       tr("backup")
+       tr("backup"),
+       //money trail
+       tr("moneylog")
 );
 /**special roles begin with _ and are listed here (in lower case and wrapped in tr())*/
 $SPECIALROLES=array(
@@ -471,6 +473,13 @@ if($SMOKEREQUEST=="getvoucher"){
 }
 
 
+//get info about a voucher
+if($SMOKEREQUEST=="moneylog"){
+       moneylogXml(trim($REQUESTDATA));
+       exit();
+}
+
+
 //retrieve backup
 if($SMOKEREQUEST=="backup"){
        header("X-MagicSmoke-Status: Ok");