add ticket audit
authorKonrad Rosenbaum <konrad@silmor.de>
Thu, 29 Dec 2011 13:22:03 +0000 (14:22 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Thu, 29 Dec 2011 13:22:03 +0000 (14:22 +0100)
src/dialogs/orderwin.cpp
src/dialogs/orderwin.h
wob/db/user.wolf
wob/transact/order.wolf
www/inc/wext/ticket.php

index 347e61e..d9cd83e 100644 (file)
@@ -129,6 +129,8 @@ MOrderWindow::MOrderWindow(QWidget*par,const MOOrder&o)
        m=mb->addMenu(tr("&Audit"));
        m->addAction(tr("Voucher History..."),this,SLOT(voucherAudit()))
         ->setEnabled(req->hasRight(req->RGetVoucherAudit));
+       m->addAction(tr("Ticket History..."),this,SLOT(ticketAudit()))
+        ->setEnabled(req->hasRight(req->RGetTicketAudit));
        m->addAction(tr("Order History..."),this,SLOT(orderAudit()))
         ->setEnabled(req->hasRight(req->RGetOrderAudit));
        
@@ -1077,6 +1079,7 @@ void MOrderWindow::voucherAudit()
        int type=m_model->data(idx,Qt::UserRole).toInt();
        if(type!=ITEM_VOUCHER){
                QMessageBox::warning(this,tr("Warning"),tr("The selected item is not a voucher."));
+               return;
        }
        //get data
        MTGetVoucherAudit va=req->queryGetVoucherAudit(id);
@@ -1128,6 +1131,73 @@ void MOrderWindow::voucherAudit()
        d.exec();
 }
 
+void MOrderWindow::ticketAudit()
+{
+       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_TICKET){
+               QMessageBox::warning(this,tr("Warning"),tr("The selected item is not a ticket."));
+               return;
+       }
+       //get data
+       MTGetTicketAudit va=req->queryGetTicketAudit(id);
+       if(va.getticket().size()==0){
+               QMessageBox::warning(this,tr("No Data"),tr("No audit data found for this ticket."));
+               return;
+       }
+       //display construction
+       QList<MOTicketAudit>tlist=va.getticket();
+       QList<MOEvent>elist=va.getevent();
+       qDebug()<<"got # tickets:"<<tlist.size();
+       QDialog d(this);
+       d.setWindowTitle(tr("Ticket Audit: %1").arg(id));
+       d.setSizeGripEnabled(true);
+       d.resize(800,600);
+       QHBoxLayout*hl;
+       QVBoxLayout*vl;
+       d.setLayout(vl=new QVBoxLayout);
+       QTableView*tab;
+       QStandardItemModel*model;
+       vl->addWidget(tab=new QTableView,1);
+       tab->setEditTriggers(QAbstractItemView::NoEditTriggers);
+       tab->setModel(model=new QStandardItemModel(tab));
+       vl->addLayout(hl=new QHBoxLayout);
+       hl->addStretch(1);
+       QPushButton*p;
+       hl->addWidget(p=new QPushButton(tr("Close")));
+       connect(p,SIGNAL(clicked()),&d,SLOT(accept()));
+       //enter data
+       model->insertRows(0,tlist.size());
+//     model->insertColumns(0,5);
+       model->setHorizontalHeaderLabels(QStringList()
+               <<tr("Date/Time")
+               <<tr("User")
+               <<tr("Transaction")
+               <<tr("Price")
+               <<tr("Event Date")
+               <<tr("Event")
+               );
+       for(int i=0;i<tlist.size();i++){
+               int eid=tlist[i].eventid();
+               MOEvent ev;
+               foreach(MOEvent e,elist)
+                       if(e.eventid()==eid)ev=e;
+               model->setData(model->index(i,0),unix2dateTime(tlist[i].audittime()));
+               model->setData(model->index(i,1),tlist[i].audituname().value());
+               model->setData(model->index(i,2),tlist[i].audittransaction().value());
+               model->setData(model->index(i,3),tlist[i].priceString());
+               model->setData(model->index(i,4),unix2dateTime(ev.start()));
+               model->setData(model->index(i,5),ev.title().value());
+       }
+       tab->resizeColumnsToContents();
+       //show
+       d.exec();
+}
+
 void MOrderWindow::orderAudit()
 {
        MTGetOrderAudit oa=req->queryGetOrderAudit(m_order.orderid());
index a8861bf..a6f65eb 100644 (file)
@@ -99,6 +99,8 @@ class MOrderWindow:public QMainWindow
                
                ///retrieve audit data for a voucher
                void voucherAudit();
+               ///retrieve audit data for a ticket
+               void ticketAudit();
                ///retrieve order audit
                void orderAudit();
                
index be6e851..94e46fb 100644 (file)
@@ -78,6 +78,7 @@
                <Preset><V col="rolename" val="Auditing"/><V col="rightname" val="GetOrderAudit"/></Preset>
                <Preset><V col="rolename" val="Auditing"/><V col="rightname" val="GetVoucher"/></Preset>
                <Preset><V col="rolename" val="Auditing"/><V col="rightname" val="GetVoucherAudit"/></Preset>
+               <Preset><V col="rolename" val="Auditing"/><V col="rightname" val="GetTicketAudit"/></Preset>
                <Preset><V col="rolename" val="CustomerManagement"/><V col="rightname" val="ChangeCustomer"/></Preset>
                <Preset><V col="rolename" val="CustomerManagement"/><V col="rightname" val="CreateContactType"/></Preset>
                <Preset><V col="rolename" val="CustomerManagement"/><V col="rightname" val="CreateCountry"/></Preset>
index 0e401fb..4de0d10 100644 (file)
                        <Var name="ticket" type="Ticket"/>
                </Output>
        </Transaction>
+
+       <Transaction name="GetTicketAudit" updating="no">
+               <Doc>returns all audit data for a ticket (when it was bought, changed prices, when it was used)</Doc>
+               <Input>
+                       <Var name="ticketid" type="astring"/>
+               </Input>
+               <Call lang="php" method="WOTicket::GetTicketAuditTransaction($this);"/>
+               <Output>
+                       <Var name="ticket" type="List:TicketAudit"/>
+                       <Var name="event" type="List:Event"/>
+               </Output>
+       </Transaction>
        
        <Transaction name="GetVoucher" updating="no">
                <Doc>returns a specific voucher with detailed info</Doc>
                <Input>
                        <Var name="orderid" type="int">ID of the order that is to be paid for</Var>
                        <Var name="voucherid" type="astring">ID of the voucher that is to be used for payment</Var>
+                       <!-- if this transaction ever gains a "comment" field you need to enhance the voucher audit table to include the additional orderid - currently the orderid is stored as comment in the audit -->
                </Input>
                <Call lang="php" method="WOOrder::payForOrderVoucher($this);"/>
                <Output>
index f80a5d3..a775df3 100644 (file)
@@ -82,6 +82,22 @@ class WOTicket extends WOTicketAbstract
        {
                return WOEvent::fromTableevent(WTevent::getFromDB($this->geteventid()));
        }
+       
+       ///GetTicketAudit transaction
+       public static function GetTicketAuditTransaction($trans)
+       {
+               global $db;
+               //get ticket data
+               $tab=WTticket_audit::selectFromDB('ticketid='.$db->escapeString($trans->getticketid()));
+               $arr=WOTicketAudit::fromTableArrayticket_audit($tab);
+               $trans->setticket($arr);
+               //get associated event(s)
+               $evl=array();
+               foreach($tab as $t)
+                       if(!in_array($t->eventid,$evl))
+                               $evl[]=$t->eventid;
+               $trans->setevent(WOEvent::fromTableArrayevent(WTevent::selectFromDB("eventid IN ".$db->escapeIntList($evl))));
+       }
 };
 
 ?>
\ No newline at end of file