#include <QFormLayout>
#include <QInputDialog>
#include <QLabel>
+#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QSettings>
vl->addWidget(ordertable=new QTableView);
ordertable->setModel(ordermodel=new QStandardItemModel(this));
ordertable->setSelectionMode(QAbstractItemView::SingleSelection);
+ ordertable->setSelectionBehavior(QAbstractItemView::SelectRows);
ordertable->setEditTriggers(QAbstractItemView::NoEditTriggers);
connect(ordertable,SIGNAL(doubleClicked(const QModelIndex&)),this,SLOT(orderDetails()));
hl->addLayout(vl=new QVBoxLayout,0);
}
}
+QList< QMenu* > MOrdersTab::menu()
+{
+ //menu
+ QList<QMenu*>ret;
+ QMenu*m=new QMenu(tr("&Order List"));
+ ret<<m;
+ m->addAction(tr("Update Order &List"),this,SLOT(updateOrders()));
+ m->addSeparator();
+ m->addAction(tr("Order &Details..."),this,SLOT(orderDetails()))
+ ->setEnabled(req->hasRight(req->RGetOrder));
+ m->addSeparator();
+ m->addAction(tr("Orders &since..."),this,SLOT(orderSinceDate()))
+ ->setEnabled(req->hasRight(req->RGetOrderList));
+ m->addSeparator();
+ m->addAction(tr("Find by &Ticket..."),this,SLOT(orderByTicket()))
+ ->setEnabled(req->hasRight(req->RGetOrderByBarcode));
+ m->addAction(tr("Find by &Event..."),this,SLOT(orderByEvent()))
+ ->setEnabled(req->hasRight(req->RGetOrdersByEvents));
+ m->addAction(tr("Find by &Customer..."),this,SLOT(orderByCustomer()))
+ ->setEnabled(req->hasRight(req->RGetOrdersByCustomer));
+ m->addAction(tr("Find by &User..."),this,SLOT(orderByUser()))
+ ->setEnabled(req->hasRight(req->RGetOrdersByUser) || req->hasRight(req->RGetMyOrders));
+ m->addAction(tr("Find by &Order ID..."),this,SLOT(orderByOrder()))
+ ->setEnabled(req->hasRight(req->RGetOrder));
+ m->addSeparator();
+ m->addAction(tr("Generate &Report..."),this,SLOT(genReport()));
+ //return menu
+ return ret;
+}
+
qint64 MOrdersTab::oldestOrderStamp(OrderTimeStampMode mode,int age)
{
if(age<0){//age not given, get configuration
//do not show cancelled ones per default
if(ord.isCancelled())return false;
//select by mask: not yet sent and reserved...
- if((omode&ORDERUNSENT)!=0 && !ord.isSent())return true;
+ if((omode&ORDERUNSENT)!=0 && !ord.isSent() && !ord.isReservation())return true;
if((omode&ORDERRESERVE)!=0 && ord.isReservation())return true;
//no match: ignore the entry
return false;
{
ordermodel->clear();
ordermodel->setHorizontalHeaderLabels(QStringList()<<tr("Status")<<tr("Total")<<tr("Paid")<<tr("Customer"));
+ m_orders.clear();
}
void MOrdersTab::addOrderToModel(const MOOrderInfo&ord,const QList<MOCustomerInfo>&cust)
{
+ m_orders.append(ord);
int cl=0;
ordermodel->insertRow(cl);
ordermodel->setHeaderData(cl,Qt::Vertical,ord.orderid().value());
ordermode->setCurrentIndex(ordermode->count()-1);
}
+void MOrdersTab::genReport()
+{
+ MOrdersReport(m_orders,this).exec();
+}
+
MOrdersByUserDlg::MOrdersByUserDlg(int olddef,QWidget* parent, Qt::WindowFlags f): QDialog(parent, f)
{
setWindowTitle(tr("Select User Criteria"));
fl->addRow(tr("Maximum Age (days):"),m_days=new QSpinBox);
m_days->setRange(0,9999);
m_days->setValue(olddef);
- fl->addRow(tr("Limit:"),m_incall=new QCheckBox(tr("Include all orders the user touched")));
+ fl->addRow(tr("Limit:"),m_incall=new QComboBox);
+ m_incall->addItem(tr("Orders that the user created"),false);
+ m_incall->addItem(tr("Include all orders the user touched"),true);
//init and preselect
if(req->hasRight(req->RGetOrdersByUser)){
//try to get all user names
bool MOrdersByUserDlg::includeAll() const
{
- return m_incall->isChecked();
+ return m_incall->itemData(m_incall->currentIndex()).toBool();
}
bool MOrdersByUserDlg::mySelfOnly() const
if(d<=0)return 0;
return QDateTime::currentDateTime().toTime_t() - (d*86400);
}
+
+MOrdersReport::MOrdersReport(const QList< MOOrderInfo >& orders, QWidget* parent, Qt::WindowFlags f)
+ : QDialog(parent, f)
+{
+ setSizeGripEnabled(true);
+ setWindowTitle(tr("Order Report"));
+
+ QVBoxLayout*vl;
+ QHBoxLayout*hl;
+ QTabWidget*tab;
+ setLayout(vl=new QVBoxLayout);
+
+ vl->addWidget(tab=new QTabWidget,1);
+ QTableView*stable,*otable,*dtable;
+
+ //tab: sums ( #orders, # tickets, #vouchers, $money, $paid, $for tickets, ...)
+ tab->addTab(stable=new QTableView,tr("Sums"));
+ stable->setModel(sum=new QStandardItemModel);
+ stable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ stable->setSelectionMode(QAbstractItemView::NoSelection);
+ sum->setHorizontalHeaderLabels(QStringList()
+ <<tr("Category")<<tr("Number Orders")
+ <<tr("Number Tickets")<<tr("Number Vouchers")
+ <<tr("Sum Money")<<tr("Sum Paid")<<tr("Sum Due")
+ );
+
+ //tab: by order (status, money in, money paid, tickets, vouchers)
+ tab->addTab(otable=new QTableView,tr("By Order"));
+ otable->setModel(byord=new QStandardItemModel);
+ otable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ otable->setSelectionMode(QAbstractItemView::NoSelection);
+ byord->setHorizontalHeaderLabels(QStringList()
+ <<tr("Order ID")<<tr("Number Tickets")<<tr("Number Vouchers")
+ <<tr("Price")<<tr("Paid")<<tr("Due") );
+
+ //tab: by day
+ tab->addTab(dtable=new QTableView,tr("By Day"));
+ dtable->setModel(byday=new QStandardItemModel);
+ dtable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ dtable->setSelectionMode(QAbstractItemView::NoSelection);
+ byday->setHorizontalHeaderLabels(QStringList()
+ <<tr("Date")
+ <<tr("Number Orders")<<tr("Number Tickets")<<tr("Number Vouchers")
+ <<tr("Price")<<tr("Paid")<<tr("Due") );
+
+ qDebug()<<"reporting on"<<orders.size()<<"orders";
+ //buttons
+ vl->addSpacing(10);
+ vl->addLayout(hl=new QHBoxLayout);
+ hl->addStretch(1);
+ QPushButton*p;
+ hl->addWidget(p=new QPushButton(tr("Close")));
+ connect(p,SIGNAL(clicked(bool)),this,SLOT(accept()));
+
+ //create display
+ QMap<QDate,QList<MOOrderInfo>>dayorders;
+ qint64 sumtickets=0,sumvouchers=0,summoney=0,sumpaid=0,sumdue=0,
+ sumreserve=0,sumreservemoney=0,sumreservetick=0,sumreservevou=0,sumreservepaid=0,sumreservedue=0,
+ sumcancel=0,sumcancelmoney=0,sumcanceltick=0,sumcancelvou=0,sumcancelpaid=0,sumcanceldue=0,
+ sumsent=0,sumsentmoney=0,sumsenttick=0,sumsentvou=0,sumsentpaid=0,sumsentdue=0,
+ sumplaced=0,sumplacedmoney=0,sumplacedtick=0,sumplacedvou=0,sumplacedpaid=0,sumplaceddue=0;
+ for(const MOOrderInfo&ord:orders){
+ //total sums
+ summoney+=ord.totalprice();
+ sumtickets+=ord.amounttickets();
+ sumvouchers+=ord.amountvouchers();
+ sumpaid+=ord.amountpaid();
+ sumdue+=ord.amountdue();
+ //part sums
+ if(ord.isReservation()){
+ sumreserve++;sumreservemoney+=ord.totalprice();
+ sumreservetick+=ord.amounttickets();
+ sumreservevou+=ord.amountvouchers();
+ sumreservepaid+=ord.amountpaid();
+ sumreservedue+=ord.amountdue();
+ }
+ if(ord.isCancelled()){
+ sumcancel++;sumcancelmoney+=ord.totalprice();
+ sumcanceltick+=ord.amounttickets();
+ sumcancelvou+=ord.amountvouchers();
+ sumcancelpaid+=ord.amountpaid();
+ sumcanceldue+=ord.amountdue();
+ }
+ if(ord.isSent()){
+ sumsent++;sumsentmoney+=ord.totalprice();
+ sumsenttick+=ord.amounttickets();
+ sumsentvou+=ord.amountvouchers();
+ sumsentpaid+=ord.amountpaid();
+ sumsentdue+=ord.amountdue();
+ }
+ if(ord.isPlaced()){
+ sumplaced++;sumplacedmoney+=ord.totalprice();
+ sumplacedtick+=ord.amounttickets();
+ sumplacedvou+=ord.amountvouchers();
+ sumplacedpaid+=ord.amountpaid();
+ sumplaceddue+=ord.amountdue();
+ }
+ //order table
+ const int cl=byord->rowCount();
+ byord->insertRow(cl);
+ byord->setData(byord->index(cl,0),ord.orderid().value());
+ byord->setData(byord->index(cl,1),ord.amounttickets().value());
+ byord->setData(byord->index(cl,2),ord.amountvouchers().value());
+ byord->setData(byord->index(cl,3),ord.totalPriceString());
+ byord->setData(byord->index(cl,4),ord.amountPaidString());
+ byord->setData(byord->index(cl,5),ord.amountDueString());
+ //sort by day
+ const QDate date=QDateTime::fromTime_t(ord.ordertime().value()).date();
+ if(!dayorders.contains(date))dayorders.insert(date,QList<MOOrderInfo>());
+ dayorders[date].append(ord);
+ }
+ //fill total sum tab
+ auto sumline=[&](QString title,int num,qint64 tick,qint64 vou,qint64 summ,qint64 paid,qint64 due){
+ const int cl=sum->rowCount();
+ sum->insertRow(cl);
+ sum->setData(sum->index(cl,0),title);
+ sum->setData(sum->index(cl,1),num);
+ sum->setData(sum->index(cl,2),tick);
+ sum->setData(sum->index(cl,3),vou);
+ sum->setData(sum->index(cl,4),cent2str(summ));
+ sum->setData(sum->index(cl,5),cent2str(paid));
+ sum->setData(sum->index(cl,6),cent2str(due));
+ };
+ sumline(tr("Total Orders"), orders.size(), sumtickets, sumvouchers, summoney, sumpaid, sumdue);
+ sumline(tr("Reserved Orders"), sumreserve, sumreservetick, sumreservevou, sumreservemoney, sumreservepaid, sumreservedue);
+ sumline(tr("Cancelled"), sumcancel, sumcanceltick, sumcancelvou, sumcancelmoney, sumcancelpaid, sumcanceldue);
+ sumline(tr("Placed"), sumplaced, sumplacedtick, sumplacedvou, sumplacedmoney, sumplacedpaid, sumplaceddue);
+ sumline(tr("Sent"), sumsent, sumsenttick, sumsentvou, sumsentmoney, sumsentpaid, sumsentdue);
+ //fill date tab
+ for(const QDate&date:dayorders.keys()){
+ const int cl=byday->rowCount();
+ byday->insertRow(cl);
+ byday->setData(byday->index(cl,0),date.toString());
+ const QList<MOOrderInfo>&day=dayorders[date];
+ byday->setData(byday->index(cl,1),day.size());
+ qint64 ticks=0,vous=0,money=0,paid=0,due=0;
+ for(const MOOrderInfo&ord:day){
+ ticks+=ord.amounttickets();
+ vous+=ord.amountvouchers();
+ money+=ord.totalprice();
+ paid+=ord.amountpaid();
+ due+=ord.amountdue();
+ }
+ byday->setData(byday->index(cl,2),ticks);
+ byday->setData(byday->index(cl,3),vous);
+ byday->setData(byday->index(cl,4),cent2str(money));
+ byday->setData(byday->index(cl,5),cent2str(paid));
+ byday->setData(byday->index(cl,6),cent2str(due));
+ }
+ //adjust
+ stable->resizeColumnsToContents();
+ dtable->resizeColumnsToContents();
+ otable->resizeColumnsToContents();
+}
+
+void MOrdersReport::saveAs()
+{
+ //TODO: use template if available
+}