From 567e82c7d6beae9975f17bd2df5196cf224f8e22 Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 28 Dec 2009 14:19:31 +0000 Subject: [PATCH] move remaining helper classes to iface and dialogs git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@363 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/README | 2 +- src/customer.cpp | 305 ----------------------------- src/customer.h | 107 ----------- src/dialogs/customerdlg.cpp | 269 ++++++++++++++++++++++++++ src/dialogs/customerdlg.h | 83 ++++++++ src/dialogs/dialogs.pri | 4 + src/dialogs/shipping.cpp | 198 +++++++++++++++++++ src/dialogs/shipping.h | 44 +++++ src/event.cpp | 66 ------- src/event.h | 69 ------- src/iface/customer.cpp | 49 +++++ src/iface/customer.h | 44 +++++ src/iface/event.cpp | 66 +++++++ src/iface/event.h | 69 +++++++ src/iface/iface.pri | 10 +- src/iface/order.cpp | 445 +++++++++++++++++++++++++++++++++++++++++++ src/iface/order.h | 243 +++++++++++++++++++++++ src/order.cpp | 445 ------------------------------------------- src/order.h | 243 ----------------------- src/shipping.cpp | 198 ------------------- src/shipping.h | 44 ----- src/smoke.pro | 15 +-- 22 files changed, 1525 insertions(+), 1493 deletions(-) delete mode 100644 src/customer.cpp delete mode 100644 src/customer.h create mode 100644 src/dialogs/customerdlg.cpp create mode 100644 src/dialogs/customerdlg.h create mode 100644 src/dialogs/shipping.cpp create mode 100644 src/dialogs/shipping.h delete mode 100644 src/event.cpp delete mode 100644 src/event.h create mode 100644 src/iface/customer.cpp create mode 100644 src/iface/customer.h create mode 100644 src/iface/event.cpp create mode 100644 src/iface/event.h create mode 100644 src/iface/order.cpp create mode 100644 src/iface/order.h delete mode 100644 src/order.cpp delete mode 100644 src/order.h delete mode 100644 src/shipping.cpp delete mode 100644 src/shipping.h diff --git a/src/README b/src/README index 473d435..3a6b138 100644 --- a/src/README +++ b/src/README @@ -4,7 +4,7 @@ README for src Directory The following (sub-)directories exist: . - main build directory, contains main widget and some global classes + main build directory, contains main application stub wbase Web object base classes. diff --git a/src/customer.cpp b/src/customer.cpp deleted file mode 100644 index aed971b..0000000 --- a/src/customer.cpp +++ /dev/null @@ -1,305 +0,0 @@ -// -// C++ Implementation: customer -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "customer.h" -#include "msinterface.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define req (MSInterface::instance()) - -MCustomer::MCustomer(qint64 i) -{ - MTGetCustomer gc=req->queryGetCustomer(i); - if(gc.stage()==gc.Success) - operator=(gc.getcustomer().value()); -} - -bool MCustomer::isValid() -{ - //TODO: reconsider isValid - return id()>-1; -} - -QString MCustomer::address(int i) -{ - if(i<0)return ""; - QListadrs=addresses(); - if(i>=adrs.size())return ""; - QString ret; - MOAddress adr=adrs[i]; - if(adr.name().isNull())ret=name(); - else ret=adr.name().value(); - ret+="\n"; - if(!adr.company().isNull())ret+=adr.company().value()+"\n"; - if(!adr.addr1().isNull())ret+=adr.addr1().value()+"\n"; - if(!adr.addr2().isNull())ret+=adr.addr2().value()+"\n"; - if(!adr.city().isNull())ret+=adr.city().value()+"\n"; - if(!adr.state().isNull())ret+=adr.state().value()+"\n"; - if(!adr.zipcode().isNull())ret+=adr.zipcode().value()+"\n"; - if(!adr.country().isNull())ret+=adr.country().value().name(); - return ret; -} - - -/*********************************************************/ - -MCustomerListDialog::MCustomerListDialog(QWidget*par,bool isselect,qint64 presel) - :QDialog(par) -{ - if(isselect) - setWindowTitle(tr("Select a Customer")); - else - setWindowTitle(tr("Customers")); - - //layout - QVBoxLayout*vl,*vl2; - QHBoxLayout*hl; - setLayout(vl=new QVBoxLayout); - vl->addLayout(hl=new QHBoxLayout,10); - hl->addLayout(vl2=new QVBoxLayout,10); - vl2->addWidget(m_filter=new QLineEdit,0); - vl2->addWidget(m_listview=new QListView,10); - m_listmodel=new QStandardItemModel(this); - m_proxymodel=new QSortFilterProxyModel(this); - m_proxymodel->setSourceModel(m_listmodel); - m_proxymodel->setDynamicSortFilter(true); - m_proxymodel->setSortCaseSensitivity(Qt::CaseInsensitive); - connect(m_filter,SIGNAL(textChanged(const QString&)),m_proxymodel,SLOT(setFilterFixedString(const QString&))); - m_proxymodel->setFilterCaseSensitivity(Qt::CaseInsensitive); - m_listview->setModel(m_proxymodel); - m_listview->setEditTriggers(QAbstractItemView::NoEditTriggers); - hl->addLayout(vl2=new QVBoxLayout,0); - QPushButton*p; - vl2->addWidget(p=new QPushButton(tr("Details...")),0); - connect(p,SIGNAL(clicked()),this,SLOT(editCustomer())); - vl2->addWidget(p=new QPushButton(tr("Create new...")),0); - connect(p,SIGNAL(clicked()),this,SLOT(newCustomer())); - p->setEnabled(req->hasRole("setcustomer")); - vl2->addWidget(p=new QPushButton(tr("Delete...")),0); - connect(p,SIGNAL(clicked()),this,SLOT(deleteCustomer())); - p->setEnabled(req->hasRole("deletecustomer")); - vl2->addStretch(2); - vl->addSpacing(15); - vl->addLayout(hl=new QHBoxLayout,0); - hl->addStretch(10); - if(isselect){ - hl->addWidget(p=new QPushButton(tr("Select")),0); - connect(p,SIGNAL(clicked()),this,SLOT(accept())); - connect(m_listview,SIGNAL(doubleClicked(const QModelIndex&)),this,SLOT(accept())); - hl->addWidget(p=new QPushButton(tr("Cancel")),0); - connect(p,SIGNAL(clicked()),this,SLOT(reject())); - }else{ - hl->addWidget(p=new QPushButton(tr("Close")),0); - connect(p,SIGNAL(clicked()),this,SLOT(reject())); - } - - //update data - updateList(presel); -} - -void MCustomerListDialog::updateList(int nid) -{ - //check for current selection - if(nid<0){ - QModelIndex idx=m_listview->currentIndex(); - if(idx.isValid()) - nid=m_proxymodel->data(idx,Qt::UserRole).toInt(); - } - //go to server - MTGetAllCustomerNames gac=req->queryGetAllCustomerNames(); - if(gac.stage()!=gac.Success)return; - m_list.clear(); - QListcl=gac.getcustomers(); - //FIXME -// for(int i=0;iclear(); - m_listmodel->insertRows(0,m_list.size()); - m_listmodel->insertColumn(0); - for(int i=0;iindex(i,0); - m_listmodel->setData(idx,m_list[i].name().value()); - m_listmodel->setData(idx,i,Qt::UserRole); - } - m_listmodel->sort(0); - //reset current - if(nid>=0) - for(int i=0;irowCount();i++){ - QModelIndex idx=m_proxymodel->index(i,0); - int j=m_proxymodel->data(idx,Qt::UserRole).toInt(); - if(j<0 || j>=m_list.size())continue; - if(nid==m_list[j].id()){ - m_listview->setCurrentIndex(idx); - break; - } - } -} - -MCustomer MCustomerListDialog::getCustomer() -{ - //get selection - QModelIndex idx=m_listview->currentIndex(); - if(!idx.isValid())return MCustomer(); - //return object - int i=m_proxymodel->data(idx,Qt::UserRole).toInt(); - if(i<0||i>=m_list.size())return MCustomer(); - return m_list[i]; -} - -void MCustomerListDialog::newCustomer() -{ - MCustomerDialog cd(MCustomer(),this); - if(cd.exec()==QDialog::Accepted) - updateList(cd.getCustomer().id()); -} -void MCustomerListDialog::editCustomer() -{ - //1get selection - QModelIndex idx=m_listview->currentIndex(); - if(!idx.isValid())return; - //return object - int i=m_proxymodel->data(idx,Qt::UserRole).toInt(); - if(i<0||i>=m_list.size())return; - //open dialog - MCustomerDialog cd(m_list[i],this); - if(cd.exec()==QDialog::Accepted) - updateList(); -} -void MCustomerListDialog::deleteCustomer() -{ - //get selection - QModelIndex idx=m_listview->currentIndex(); - if(!idx.isValid())return; - //get pointer to customer - int dusr=m_proxymodel->data(idx,Qt::UserRole).toInt(); - if(dusr<0||dusr>=m_list.size())return; - //show delete dialog - QDialog d; - d.setWindowTitle(tr("Delete Customer")); - QVBoxLayout*vl; - d.setLayout(vl=new QVBoxLayout); - vl->addWidget(new QLabel(tr("Really delete this customer (%1)?").arg(m_proxymodel->data(idx).toString()))); - vl->addSpacing(20); - QCheckBox*cb; - vl->addWidget(cb=new QCheckBox(tr("merge with other entry:"))); - QComboBox*cm; - vl->addWidget(cm=new QComboBox); - cm->setModel(m_listmodel); - cm->setEnabled(cb->isEnabled()); - connect(cb,SIGNAL(toggled(bool)),cm,SLOT(setEnabled(bool))); - vl->addSpacing(20); - vl->addStretch(10); - QHBoxLayout*hl; - vl->addLayout(hl=new QHBoxLayout); - hl->addStretch(10); - QPushButton*p; - hl->addWidget(p=new QPushButton(tr("&Yes"))); - connect(p,SIGNAL(clicked()),&d,SLOT(accept())); - hl->addWidget(p=new QPushButton(tr("&No"))); - connect(p,SIGNAL(clicked()),&d,SLOT(reject())); - if(d.exec()!=QDialog::Accepted)return; - //compose request - QString rd=QString::number(m_list[dusr].id()); - if(cb->isChecked()){ - int musr=m_listmodel->data(m_listmodel->index(cm->currentIndex(),0),Qt::UserRole).toInt(); - rd+=" "; - rd+=QString::number(m_list[musr].id()); - } - //delete it - /*TODO - if(!req->request("deletecustomer",rd.toAscii())){ - QMessageBox::warning(this,tr("Error"),tr("Failed to delete customer.")); - return; - } - if(m_req->responseStatus()!=MWebRequest::Ok){ - QMessageBox::warning(this,tr("Error"),tr("Failed to delete customer: %1").arg(qApp->translate("php::",m_req->responseBody()))); - return; - } - //update view - updateList(); - */ -} - - -/****************************************************************/ - -MCustomerDialog::MCustomerDialog(MCustomer c,QWidget*par) - :QDialog(par),m_cust(c) -{ - if(m_cust.isValid()) - setWindowTitle(tr("Customer %1").arg(m_cust.name())); - else - setWindowTitle(tr("New Customer")); - - //layout - QGridLayout *gl; - setLayout(gl=new QGridLayout); - int lc=0; - gl->addWidget(new QLabel(tr("Name:")),lc,0); - gl->addWidget(m_name=new QLineEdit(m_cust.name()),lc,1); - gl->addWidget(new QLabel(tr("Address:")),++lc,0); - gl->addWidget(m_addr=new QTextEdit,lc,1); - m_addr->setPlainText(m_cust.address()); - gl->addWidget(new QLabel(tr("Contact Information:")),++lc,0); - gl->addWidget(m_cont=new QTextEdit,lc,1); - //FIXME -// m_cont->setPlainText(m_cust.contact()); - gl->setRowMinimumHeight(++lc,10); - gl->addWidget(new QLabel(tr("Web-Login/eMail:")),++lc,0); - gl->addWidget(m_mail=new QLabel(m_cust.email()),lc,1); - gl->setRowMinimumHeight(++lc,10); - gl->addWidget(new QLabel(tr("Comment:")),++lc,0,1,2); - gl->addWidget(m_comm=new QTextEdit,++lc,0,1,2); - m_comm->setPlainText(m_cust.comments()); - gl->setRowMinimumHeight(++lc,15); - QHBoxLayout*hl; - gl->addLayout(hl=new QHBoxLayout,++lc,0,1,2); - hl->addStretch(10); - QPushButton*p; - hl->addWidget(p=new QPushButton(tr("Save")),0); - connect(p,SIGNAL(clicked()),this,SLOT(accept())); - connect(p,SIGNAL(clicked()),this,SLOT(save())); - hl->addWidget(p=new QPushButton(tr("Cancel")),0); - connect(p,SIGNAL(clicked()),this,SLOT(reject())); -} - -MCustomer MCustomerDialog::getCustomer() -{ - //copy data from input fields - m_cust.setname(m_name->text()); - //TODO: redo address editing - //m_cust.setaddress(m_addr->toPlainText()); - //m_cust.setcontact(m_cont->toPlainText()); - m_cust.setcomments(m_comm->toPlainText()); - return m_cust; -} - -void MCustomerDialog::save() -{/*TODO: - getCustomer(); - m_cust.save();*/ -} diff --git a/src/customer.h b/src/customer.h deleted file mode 100644 index 3653381..0000000 --- a/src/customer.h +++ /dev/null @@ -1,107 +0,0 @@ -// -// C++ Interface: customer -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef MAGICSMOKE_CUSTOMER_H -#define MAGICSMOKE_CUSTOMER_H - -#include -#include -#include - -#include "MOCustomerShort.h" -#include "MOCustomer.h" - -/**this class expands on MOCustomer to add some convenience methods*/ -class MCustomer:public MOCustomer -{ - public: - /**creates an empty/invalid customer*/ - MCustomer(){} - /**fetches customer from the Database*/ - MCustomer(qint64); - /**copies a customer*/ - MCustomer(const MCustomer&c):MOCustomer(c){} - MCustomer(const MOCustomer&c):MOCustomer(c){} - - /**copies a customer*/ - MCustomer& operator=(const MCustomer&c){MOCustomer::operator=(c);return *this;} - MCustomer& operator=(const MOCustomer&c){MOCustomer::operator=(c);return *this;} - - /**returns whether the customer is valid*/ - bool isValid(); - - /**returns the address of the customer*/ - QString address(int i=0); -}; - -class QListView; -class QStandardItemModel; -class QSortFilterProxyModel; -class QLineEdit; - -/**shows a list of customers, lets the user select and offers to alter/create customers*/ -class MCustomerListDialog:public QDialog -{ - Q_OBJECT - public: - /**creates a new customer list dialog; expects a usable webrequest object and a parent, if isselect is set to true it offers a select button, if selected is set to a matching customerID it will be pre-selected*/ - MCustomerListDialog(QWidget*,bool isselect=false,qint64 selected=-1); - - /**returns the selected customer*/ - MCustomer getCustomer(); - - private slots: - /**internal: new customer*/ - void newCustomer(); - /**internal: edit selected customer*/ - void editCustomer(); - /**internal: delete selected customer*/ - void deleteCustomer(); - - private: - QList m_list; - QListView*m_listview; - QStandardItemModel*m_listmodel; - QSortFilterProxyModel*m_proxymodel; - QLineEdit*m_filter; - - /**updates internal list*/ - void updateList(int id=-1); -}; - -class QLineEdit; -class QTextEdit; -class QLabel; - -/**edit a specific customer*/ -class MCustomerDialog:public QDialog -{ - Q_OBJECT - public: - /**creates a new customer dialog*/ - MCustomerDialog(MCustomer,QWidget*); - - /**returns the customer as currently entered*/ - MCustomer getCustomer(); - - private slots: - /**internal: save data*/ - void save(); - - private: - MCustomer m_cust; - QLineEdit*m_name; - QTextEdit*m_addr,*m_cont,*m_comm; - QLabel*m_mail; -}; - -#endif diff --git a/src/dialogs/customerdlg.cpp b/src/dialogs/customerdlg.cpp new file mode 100644 index 0000000..c15affa --- /dev/null +++ b/src/dialogs/customerdlg.cpp @@ -0,0 +1,269 @@ +// +// C++ Implementation: customer +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "customerdlg.h" +#include "msinterface.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define req (MSInterface::instance()) + +MCustomerListDialog::MCustomerListDialog(QWidget*par,bool isselect,qint64 presel) + :QDialog(par) +{ + if(isselect) + setWindowTitle(tr("Select a Customer")); + else + setWindowTitle(tr("Customers")); + + //layout + QVBoxLayout*vl,*vl2; + QHBoxLayout*hl; + setLayout(vl=new QVBoxLayout); + vl->addLayout(hl=new QHBoxLayout,10); + hl->addLayout(vl2=new QVBoxLayout,10); + vl2->addWidget(m_filter=new QLineEdit,0); + vl2->addWidget(m_listview=new QListView,10); + m_listmodel=new QStandardItemModel(this); + m_proxymodel=new QSortFilterProxyModel(this); + m_proxymodel->setSourceModel(m_listmodel); + m_proxymodel->setDynamicSortFilter(true); + m_proxymodel->setSortCaseSensitivity(Qt::CaseInsensitive); + connect(m_filter,SIGNAL(textChanged(const QString&)),m_proxymodel,SLOT(setFilterFixedString(const QString&))); + m_proxymodel->setFilterCaseSensitivity(Qt::CaseInsensitive); + m_listview->setModel(m_proxymodel); + m_listview->setEditTriggers(QAbstractItemView::NoEditTriggers); + hl->addLayout(vl2=new QVBoxLayout,0); + QPushButton*p; + vl2->addWidget(p=new QPushButton(tr("Details...")),0); + connect(p,SIGNAL(clicked()),this,SLOT(editCustomer())); + vl2->addWidget(p=new QPushButton(tr("Create new...")),0); + connect(p,SIGNAL(clicked()),this,SLOT(newCustomer())); + p->setEnabled(req->hasRole("setcustomer")); + vl2->addWidget(p=new QPushButton(tr("Delete...")),0); + connect(p,SIGNAL(clicked()),this,SLOT(deleteCustomer())); + p->setEnabled(req->hasRole("deletecustomer")); + vl2->addStretch(2); + vl->addSpacing(15); + vl->addLayout(hl=new QHBoxLayout,0); + hl->addStretch(10); + if(isselect){ + hl->addWidget(p=new QPushButton(tr("Select")),0); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + connect(m_listview,SIGNAL(doubleClicked(const QModelIndex&)),this,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("Cancel")),0); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); + }else{ + hl->addWidget(p=new QPushButton(tr("Close")),0); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); + } + + //update data + updateList(presel); +} + +void MCustomerListDialog::updateList(int nid) +{ + //check for current selection + if(nid<0){ + QModelIndex idx=m_listview->currentIndex(); + if(idx.isValid()) + nid=m_proxymodel->data(idx,Qt::UserRole).toInt(); + } + //go to server + MTGetAllCustomerNames gac=req->queryGetAllCustomerNames(); + if(gac.stage()!=gac.Success)return; + m_list.clear(); + QListcl=gac.getcustomers(); + //FIXME +// for(int i=0;iclear(); + m_listmodel->insertRows(0,m_list.size()); + m_listmodel->insertColumn(0); + for(int i=0;iindex(i,0); + m_listmodel->setData(idx,m_list[i].name().value()); + m_listmodel->setData(idx,i,Qt::UserRole); + } + m_listmodel->sort(0); + //reset current + if(nid>=0) + for(int i=0;irowCount();i++){ + QModelIndex idx=m_proxymodel->index(i,0); + int j=m_proxymodel->data(idx,Qt::UserRole).toInt(); + if(j<0 || j>=m_list.size())continue; + if(nid==m_list[j].id()){ + m_listview->setCurrentIndex(idx); + break; + } + } +} + +MCustomer MCustomerListDialog::getCustomer() +{ + //get selection + QModelIndex idx=m_listview->currentIndex(); + if(!idx.isValid())return MCustomer(); + //return object + int i=m_proxymodel->data(idx,Qt::UserRole).toInt(); + if(i<0||i>=m_list.size())return MCustomer(); + return m_list[i]; +} + +void MCustomerListDialog::newCustomer() +{ + MCustomerDialog cd(MCustomer(),this); + if(cd.exec()==QDialog::Accepted) + updateList(cd.getCustomer().id()); +} +void MCustomerListDialog::editCustomer() +{ + //1get selection + QModelIndex idx=m_listview->currentIndex(); + if(!idx.isValid())return; + //return object + int i=m_proxymodel->data(idx,Qt::UserRole).toInt(); + if(i<0||i>=m_list.size())return; + //open dialog + MCustomerDialog cd(m_list[i],this); + if(cd.exec()==QDialog::Accepted) + updateList(); +} +void MCustomerListDialog::deleteCustomer() +{ + //get selection + QModelIndex idx=m_listview->currentIndex(); + if(!idx.isValid())return; + //get pointer to customer + int dusr=m_proxymodel->data(idx,Qt::UserRole).toInt(); + if(dusr<0||dusr>=m_list.size())return; + //show delete dialog + QDialog d; + d.setWindowTitle(tr("Delete Customer")); + QVBoxLayout*vl; + d.setLayout(vl=new QVBoxLayout); + vl->addWidget(new QLabel(tr("Really delete this customer (%1)?").arg(m_proxymodel->data(idx).toString()))); + vl->addSpacing(20); + QCheckBox*cb; + vl->addWidget(cb=new QCheckBox(tr("merge with other entry:"))); + QComboBox*cm; + vl->addWidget(cm=new QComboBox); + cm->setModel(m_listmodel); + cm->setEnabled(cb->isEnabled()); + connect(cb,SIGNAL(toggled(bool)),cm,SLOT(setEnabled(bool))); + vl->addSpacing(20); + vl->addStretch(10); + QHBoxLayout*hl; + vl->addLayout(hl=new QHBoxLayout); + hl->addStretch(10); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("&Yes"))); + connect(p,SIGNAL(clicked()),&d,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("&No"))); + connect(p,SIGNAL(clicked()),&d,SLOT(reject())); + if(d.exec()!=QDialog::Accepted)return; + //compose request + QString rd=QString::number(m_list[dusr].id()); + if(cb->isChecked()){ + int musr=m_listmodel->data(m_listmodel->index(cm->currentIndex(),0),Qt::UserRole).toInt(); + rd+=" "; + rd+=QString::number(m_list[musr].id()); + } + //delete it + /*TODO + if(!req->request("deletecustomer",rd.toAscii())){ + QMessageBox::warning(this,tr("Error"),tr("Failed to delete customer.")); + return; + } + if(m_req->responseStatus()!=MWebRequest::Ok){ + QMessageBox::warning(this,tr("Error"),tr("Failed to delete customer: %1").arg(qApp->translate("php::",m_req->responseBody()))); + return; + } + //update view + updateList(); + */ +} + + +/****************************************************************/ + +MCustomerDialog::MCustomerDialog(MCustomer c,QWidget*par) + :QDialog(par),m_cust(c) +{ + if(m_cust.isValid()) + setWindowTitle(tr("Customer %1").arg(m_cust.name())); + else + setWindowTitle(tr("New Customer")); + + //layout + QGridLayout *gl; + setLayout(gl=new QGridLayout); + int lc=0; + gl->addWidget(new QLabel(tr("Name:")),lc,0); + gl->addWidget(m_name=new QLineEdit(m_cust.name()),lc,1); + gl->addWidget(new QLabel(tr("Address:")),++lc,0); + gl->addWidget(m_addr=new QTextEdit,lc,1); + m_addr->setPlainText(m_cust.address()); + gl->addWidget(new QLabel(tr("Contact Information:")),++lc,0); + gl->addWidget(m_cont=new QTextEdit,lc,1); + //FIXME +// m_cont->setPlainText(m_cust.contact()); + gl->setRowMinimumHeight(++lc,10); + gl->addWidget(new QLabel(tr("Web-Login/eMail:")),++lc,0); + gl->addWidget(m_mail=new QLabel(m_cust.email()),lc,1); + gl->setRowMinimumHeight(++lc,10); + gl->addWidget(new QLabel(tr("Comment:")),++lc,0,1,2); + gl->addWidget(m_comm=new QTextEdit,++lc,0,1,2); + m_comm->setPlainText(m_cust.comments()); + gl->setRowMinimumHeight(++lc,15); + QHBoxLayout*hl; + gl->addLayout(hl=new QHBoxLayout,++lc,0,1,2); + hl->addStretch(10); + QPushButton*p; + hl->addWidget(p=new QPushButton(tr("Save")),0); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + connect(p,SIGNAL(clicked()),this,SLOT(save())); + hl->addWidget(p=new QPushButton(tr("Cancel")),0); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); +} + +MCustomer MCustomerDialog::getCustomer() +{ + //copy data from input fields + m_cust.setname(m_name->text()); + //TODO: redo address editing + //m_cust.setaddress(m_addr->toPlainText()); + //m_cust.setcontact(m_cont->toPlainText()); + m_cust.setcomments(m_comm->toPlainText()); + return m_cust; +} + +void MCustomerDialog::save() +{/*TODO: + getCustomer(); + m_cust.save();*/ +} diff --git a/src/dialogs/customerdlg.h b/src/dialogs/customerdlg.h new file mode 100644 index 0000000..cc242f2 --- /dev/null +++ b/src/dialogs/customerdlg.h @@ -0,0 +1,83 @@ +// +// C++ Interface: customer +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_CUSTOMERDLG_H +#define MAGICSMOKE_CUSTOMERDLG_H + +#include +#include +#include + +#include "customer.h" + +class QListView; +class QStandardItemModel; +class QSortFilterProxyModel; +class QLineEdit; + +/**shows a list of customers, lets the user select and offers to alter/create customers*/ +class MCustomerListDialog:public QDialog +{ + Q_OBJECT + public: + /**creates a new customer list dialog; expects a usable webrequest object and a parent, if isselect is set to true it offers a select button, if selected is set to a matching customerID it will be pre-selected*/ + MCustomerListDialog(QWidget*,bool isselect=false,qint64 selected=-1); + + /**returns the selected customer*/ + MCustomer getCustomer(); + + private slots: + /**internal: new customer*/ + void newCustomer(); + /**internal: edit selected customer*/ + void editCustomer(); + /**internal: delete selected customer*/ + void deleteCustomer(); + + private: + QList m_list; + QListView*m_listview; + QStandardItemModel*m_listmodel; + QSortFilterProxyModel*m_proxymodel; + QLineEdit*m_filter; + + /**updates internal list*/ + void updateList(int id=-1); +}; + +class QLineEdit; +class QTextEdit; +class QLabel; + +/**edit a specific customer*/ +class MCustomerDialog:public QDialog +{ + Q_OBJECT + public: + /**creates a new customer dialog*/ + MCustomerDialog(MCustomer,QWidget*); + + /**returns the customer as currently entered*/ + MCustomer getCustomer(); + + private slots: + /**internal: save data*/ + void save(); + + private: + MCustomer m_cust; + QLineEdit*m_name; + QTextEdit*m_addr,*m_cont,*m_comm; + QLabel*m_mail; +}; + +#endif diff --git a/src/dialogs/dialogs.pri b/src/dialogs/dialogs.pri index b18df66..c5377a2 100644 --- a/src/dialogs/dialogs.pri +++ b/src/dialogs/dialogs.pri @@ -5,6 +5,8 @@ HEADERS += \ dialogs/orderwin.h \ dialogs/moneylog.h \ dialogs/login.h \ + dialogs/shipping.h \ + dialogs/customerdlg.h \ dialogs/passwdchg.h SOURCES += \ @@ -14,6 +16,8 @@ SOURCES += \ dialogs/orderwin.cpp \ dialogs/moneylog.cpp \ dialogs/login.cpp \ + dialogs/shipping.cpp \ + dialogs/customerdlg.cpp \ dialogs/passwdchg.cpp INCLUDEPATH += ./dialogs \ No newline at end of file diff --git a/src/dialogs/shipping.cpp b/src/dialogs/shipping.cpp new file mode 100644 index 0000000..574912a --- /dev/null +++ b/src/dialogs/shipping.cpp @@ -0,0 +1,198 @@ +// +// C++ Implementation: shipping +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "misc.h" +#include "shipping.h" +#include "centbox.h" + +#include "MOShipping.h" + +#include "msinterface.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define req (MSInterface::instance()) + +MShippingEditor::MShippingEditor(QWidget*par) + :QDialog(par) +{ + all=req->queryGetAllShipping().getshipping(); + setWindowTitle(tr("Edit Shipping Options")); + + QHBoxLayout*hl; + QVBoxLayout*vl,*vl2; + setLayout(vl=new QVBoxLayout); + vl->addLayout(hl=new QHBoxLayout,1); + hl->addWidget(table=new QTableView,1); + table->setModel(model=new QStandardItemModel(this)); + table->setEditTriggers(QAbstractItemView::NoEditTriggers); + updateTable(); + hl->addLayout(vl2=new QVBoxLayout,0); + QPushButton*p; + vl2->addWidget(p=new QPushButton(tr("Change Description"))); + connect(p,SIGNAL(clicked()),this,SLOT(changeDescription())); + vl2->addWidget(p=new QPushButton(tr("Change Price"))); + connect(p,SIGNAL(clicked()),this,SLOT(changePrice())); + vl2->addWidget(p=new QPushButton(tr("Change Availability"))); + connect(p,SIGNAL(clicked()),this,SLOT(changeAvail())); + vl2->addSpacing(20); + vl2->addWidget(p=new QPushButton(tr("Add Option"))); + connect(p,SIGNAL(clicked()),this,SLOT(addNew())); + vl2->addWidget(p=new QPushButton(tr("Delete Option"))); + connect(p,SIGNAL(clicked()),this,SLOT(deleteShip())); + vl2->addStretch(1); + + vl->addSpacing(15); + vl->addLayout(hl=new QHBoxLayout,0); + hl->addStretch(10); + hl->addWidget(p=new QPushButton(tr("Ok"))); + connect(p,SIGNAL(clicked()),this,SLOT(accept())); + hl->addWidget(p=new QPushButton(tr("Cancel"))); + connect(p,SIGNAL(clicked()),this,SLOT(reject())); +} +void MShippingEditor::updateTable() +{ + model->clear(); + model->insertColumns(0,5); + model->insertRows(0,all.size()); + model->setHorizontalHeaderLabels(QStringList()<setData(model->index(i,0),all[i].id().value()); + model->setData(model->index(i,1),all[i].description().value()); + model->setData(model->index(i,2),cent2str(all[i].cost())); + model->setData(model->index(i,3),all[i].canuseweb().value()?tr("Yes"):tr("No")); + model->setData(model->index(i,4),all[i].canallusers().value()?tr("Yes"):tr("No")); + } + table->resizeColumnsToContents(); +} + +void MShippingEditor::changeDescription() +{/*TODO + //find item + QModelIndexList lst=table->selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=lst[0]; + //get shipping + MShipping s=all[idx.row()]; + //get new value + QString r=QInputDialog::getText(this,tr("Shipping Option Description"),tr("Please select a new description for this shipping option:"),QLineEdit::Normal,s.description()); + if(r=="")return; + s.setDescription(r); + if(!s.save()){ + QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes.")); + return; + } + all[idx.row()]=s; + updateTable();*/ +} + +void MShippingEditor::changePrice() +{/*TODO + //find item + QModelIndexList lst=table->selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=lst[0]; + //get shipping + MShipping s=all[idx.row()]; + //get new value + bool b; + int r=MCentDialog::getCents(this,tr("Shipping Option Price"),tr("Please select a new price for this shipping option:"),s.price(),1000000000,&b); + if(!b)return; + s.setPrice(r); + if(!s.save()){ + QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes.")); + return; + } + all[idx.row()]=s; + updateTable();*/ +} +void MShippingEditor::changeAvail() +{/*TODO + //find item + QModelIndexList lst=table->selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=lst[0]; + //get shipping + MShipping s=all[idx.row()]; + //get new value + bool b; + QStringList opt; + opt<selectionModel()->selectedIndexes(); + if(lst.size()<1)return; + QModelIndex idx=lst[0]; + //get shipping + int id=all[idx.row()].id(); + if(!req->request("deleteshipping",QString::number(id).toAscii())){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to delete this option.")); + return; + } + if(req->responseStatus()!=MWebRequest::Ok){ + QMessageBox::warning(this,tr("Warning"),tr("Unable to delete this option.")); + return; + } + all.removeAt(idx.row()); + updateTable();*/ +} diff --git a/src/dialogs/shipping.h b/src/dialogs/shipping.h new file mode 100644 index 0000000..58815aa --- /dev/null +++ b/src/dialogs/shipping.h @@ -0,0 +1,44 @@ +// +// C++ Interface: shipping +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_SHIPPING_H +#define MAGICSMOKE_SHIPPING_H + +#include +#include + +class QStandardItemModel; +class QTableView; + +#include "MOShipping.h" + +class MShippingEditor:public QDialog +{ + Q_OBJECT + public: + MShippingEditor(QWidget*); + + private slots: + void changeDescription(); + void changePrice(); + void changeAvail(); + void addNew(); + void deleteShip(); + void updateTable(); + + private: + QListall; + QStandardItemModel*model; + QTableView*table; +}; + +#endif diff --git a/src/event.cpp b/src/event.cpp deleted file mode 100644 index e81f4a6..0000000 --- a/src/event.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// -// C++ Implementation: event -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2007 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "event.h" - -#include -#include -#include -#include - -#include "msinterface.h" - -MEvent::MEvent(qint64 i) -{ - MTGetEvent ge=MSInterface::instance()->queryGetEvent(i); - if(ge.stage()==ge.Success) - operator=(ge.getevent().value()); -} - -QRegExp MEvent::priceRegExp()const -{ - return QRegExp(QCoreApplication::translate("MEvent","[0-9]+\\.[0-9]{2}","price validator regexp")); -} - -QString MEvent::priceString()const -{ - qint64 dp=/*defaultprice()*/0; - QString ret=QString::number(dp/100); - ret+=QCoreApplication::translate("MEvent",".","price decimal dot"); - ret+=QString::number((dp/10)%10); - ret+=QString::number(dp%10); - return ret; -} - -QString MEvent::startTimeString()const -{ - return QDateTime::fromTime_t(start()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd hh:mm ap","date/time format")); -} - -QString MEvent::startDateString()const -{ - return QDateTime::fromTime_t(start()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd","date format")); -} - -QString MEvent::endTimeString()const -{ - return QDateTime::fromTime_t(end()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd hh:mm ap","date/time format")); -} - -void MEvent::setdefaultprice(QString str) -{ - QStringList ps=str.split(QCoreApplication::translate("MEvent",".","price decimal dot")); - qint64 prc=0; - if(ps.size()>=1)prc=ps[0].toInt()*100; - if(ps.size()>=2)prc+=ps[1].toInt(); - setdefaultprice(prc); -} diff --git a/src/event.h b/src/event.h deleted file mode 100644 index e5b9f7b..0000000 --- a/src/event.h +++ /dev/null @@ -1,69 +0,0 @@ -// -// C++ Interface: event -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2007 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef EVENT_H -#define EVENT_H - -#include -#include - -/**encapsulation of an event, this class wraps the auto-generated event class to provide some convenience methods*/ -class MEvent:public MOEvent -{ - public: - /**creates an invalid event*/ - MEvent():MOEvent(){} - /**copies an event*/ - MEvent(const MEvent&e):MOEvent(e){} - /**copies an event*/ - MEvent(const MOEvent&e):MOEvent(e){} - /**get event directly from server*/ - MEvent(qint64); - /**destructs an event*/ - ~MEvent(){} - - /**copies the event*/ - MEvent& operator=(const MEvent&e){MOEvent::operator=(e);return *this;} - - /**updates data from the database, can be used to upgrade an incomplete event to a complete one*/ - //void refresh(); - - /**saves all data back to the database, it returns an empty string on success, it does not do anything if the event is invalid or incomplete*/ - //QString save(); - - /**returns the start time of the event as localized string*/ - QString startTimeString()const; - /**returns the start date as localized string*/ - QString startDateString()const; - /**returns the end time of the event as localized string*/ - QString endTimeString()const; - /**returns the room of the event, the room must be one out of the list of valid rooms*/ - - /**returns the price as a localized string*/ - QString priceString()const; - /**returns the local regular expression for prices*/ - QRegExp priceRegExp()const; - - /**set the price as string*/ - void setdefaultprice(QString); - - //inherit alternative definition - inline void setdefaultprice(qint64 p){/*MOEvent::setdefaultprice(p);*/} - - /**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/ - //bool isValid()const{return m_valid;} - - /**requests to cancel the event from the DB; expects reason as argument; returns true on success*/ - //bool cancelEvent(QString); -}; - -#endif diff --git a/src/iface/customer.cpp b/src/iface/customer.cpp new file mode 100644 index 0000000..281518e --- /dev/null +++ b/src/iface/customer.cpp @@ -0,0 +1,49 @@ +// +// C++ Implementation: customer +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "customer.h" +#include "msinterface.h" + +#define req (MSInterface::instance()) + +MCustomer::MCustomer(qint64 i) +{ + MTGetCustomer gc=req->queryGetCustomer(i); + if(gc.stage()==gc.Success) + operator=(gc.getcustomer().value()); +} + +bool MCustomer::isValid() +{ + //TODO: reconsider isValid + return id()>-1; +} + +QString MCustomer::address(int i) +{ + if(i<0)return ""; + QListadrs=addresses(); + if(i>=adrs.size())return ""; + QString ret; + MOAddress adr=adrs[i]; + if(adr.name().isNull())ret=name(); + else ret=adr.name().value(); + ret+="\n"; + if(!adr.company().isNull())ret+=adr.company().value()+"\n"; + if(!adr.addr1().isNull())ret+=adr.addr1().value()+"\n"; + if(!adr.addr2().isNull())ret+=adr.addr2().value()+"\n"; + if(!adr.city().isNull())ret+=adr.city().value()+"\n"; + if(!adr.state().isNull())ret+=adr.state().value()+"\n"; + if(!adr.zipcode().isNull())ret+=adr.zipcode().value()+"\n"; + if(!adr.country().isNull())ret+=adr.country().value().name(); + return ret; +} diff --git a/src/iface/customer.h b/src/iface/customer.h new file mode 100644 index 0000000..55c7589 --- /dev/null +++ b/src/iface/customer.h @@ -0,0 +1,44 @@ +// +// C++ Interface: customer +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2008 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_CUSTOMER_H +#define MAGICSMOKE_CUSTOMER_H + +#include + +#include "MOCustomerShort.h" +#include "MOCustomer.h" + +/**this class expands on MOCustomer to add some convenience methods*/ +class MCustomer:public MOCustomer +{ + public: + /**creates an empty/invalid customer*/ + MCustomer(){} + /**fetches customer from the Database*/ + MCustomer(qint64); + /**copies a customer*/ + MCustomer(const MCustomer&c):MOCustomer(c){} + MCustomer(const MOCustomer&c):MOCustomer(c){} + + /**copies a customer*/ + MCustomer& operator=(const MCustomer&c){MOCustomer::operator=(c);return *this;} + MCustomer& operator=(const MOCustomer&c){MOCustomer::operator=(c);return *this;} + + /**returns whether the customer is valid*/ + bool isValid(); + + /**returns the address of the customer*/ + QString address(int i=0); +}; + +#endif diff --git a/src/iface/event.cpp b/src/iface/event.cpp new file mode 100644 index 0000000..e81f4a6 --- /dev/null +++ b/src/iface/event.cpp @@ -0,0 +1,66 @@ +// +// C++ Implementation: event +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "event.h" + +#include +#include +#include +#include + +#include "msinterface.h" + +MEvent::MEvent(qint64 i) +{ + MTGetEvent ge=MSInterface::instance()->queryGetEvent(i); + if(ge.stage()==ge.Success) + operator=(ge.getevent().value()); +} + +QRegExp MEvent::priceRegExp()const +{ + return QRegExp(QCoreApplication::translate("MEvent","[0-9]+\\.[0-9]{2}","price validator regexp")); +} + +QString MEvent::priceString()const +{ + qint64 dp=/*defaultprice()*/0; + QString ret=QString::number(dp/100); + ret+=QCoreApplication::translate("MEvent",".","price decimal dot"); + ret+=QString::number((dp/10)%10); + ret+=QString::number(dp%10); + return ret; +} + +QString MEvent::startTimeString()const +{ + return QDateTime::fromTime_t(start()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd hh:mm ap","date/time format")); +} + +QString MEvent::startDateString()const +{ + return QDateTime::fromTime_t(start()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd","date format")); +} + +QString MEvent::endTimeString()const +{ + return QDateTime::fromTime_t(end()).toString(QCoreApplication::translate("MEvent","yyyy-MM-dd hh:mm ap","date/time format")); +} + +void MEvent::setdefaultprice(QString str) +{ + QStringList ps=str.split(QCoreApplication::translate("MEvent",".","price decimal dot")); + qint64 prc=0; + if(ps.size()>=1)prc=ps[0].toInt()*100; + if(ps.size()>=2)prc+=ps[1].toInt(); + setdefaultprice(prc); +} diff --git a/src/iface/event.h b/src/iface/event.h new file mode 100644 index 0000000..e5b9f7b --- /dev/null +++ b/src/iface/event.h @@ -0,0 +1,69 @@ +// +// C++ Interface: event +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef EVENT_H +#define EVENT_H + +#include +#include + +/**encapsulation of an event, this class wraps the auto-generated event class to provide some convenience methods*/ +class MEvent:public MOEvent +{ + public: + /**creates an invalid event*/ + MEvent():MOEvent(){} + /**copies an event*/ + MEvent(const MEvent&e):MOEvent(e){} + /**copies an event*/ + MEvent(const MOEvent&e):MOEvent(e){} + /**get event directly from server*/ + MEvent(qint64); + /**destructs an event*/ + ~MEvent(){} + + /**copies the event*/ + MEvent& operator=(const MEvent&e){MOEvent::operator=(e);return *this;} + + /**updates data from the database, can be used to upgrade an incomplete event to a complete one*/ + //void refresh(); + + /**saves all data back to the database, it returns an empty string on success, it does not do anything if the event is invalid or incomplete*/ + //QString save(); + + /**returns the start time of the event as localized string*/ + QString startTimeString()const; + /**returns the start date as localized string*/ + QString startDateString()const; + /**returns the end time of the event as localized string*/ + QString endTimeString()const; + /**returns the room of the event, the room must be one out of the list of valid rooms*/ + + /**returns the price as a localized string*/ + QString priceString()const; + /**returns the local regular expression for prices*/ + QRegExp priceRegExp()const; + + /**set the price as string*/ + void setdefaultprice(QString); + + //inherit alternative definition + inline void setdefaultprice(qint64 p){/*MOEvent::setdefaultprice(p);*/} + + /**returns whether the event is valid. an event can be invalid if it is uninitialized (negative ID) or the server request failed*/ + //bool isValid()const{return m_valid;} + + /**requests to cancel the event from the DB; expects reason as argument; returns true on success*/ + //bool cancelEvent(QString); +}; + +#endif diff --git a/src/iface/iface.pri b/src/iface/iface.pri index ac98ba4..f38a1b1 100644 --- a/src/iface/iface.pri +++ b/src/iface/iface.pri @@ -1,10 +1,16 @@ HEADERS += \ iface/msinterface.h \ - iface/sslexception.h + iface/event.h \ + iface/order.h \ + iface/sslexception.h \ + iface/customer.h SOURCES += \ iface/msinterface.cpp \ - iface/sslexception.cpp + iface/event.cpp \ + iface/order.cpp \ + iface/sslexception.cpp \ + iface/customer.cpp INCLUDEPATH += ./iface \ No newline at end of file diff --git a/src/iface/order.cpp b/src/iface/order.cpp new file mode 100644 index 0000000..404ec6a --- /dev/null +++ b/src/iface/order.cpp @@ -0,0 +1,445 @@ +// +// C++ Implementation: host +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#include "misc.h" +#include "order.h" + +#include "msinterface.h" + +#include +#include +#include + +#define req (MSInterface::instance()) + +MOrder::MOrder(qint64 id) +{ + MTGetOrder go=req->queryGetOrder(id); + if(go.stage()==go.Success) + operator=(go.getorder().value()); +} + +bool MOrder::isValid()const +{ + //TODO: redefine isValid + return true; +} + +MCustomer MOrder::customer()const +{ + return MCustomer(customerid()); +} + +bool MOrder::isReservation()const +{ + return state()==Reserved; +} + +bool MOrder::canOrder()const +{ + //TODO:redefine canOrder + //return m_status==CheckOk || m_status==CheckOrderOnly; + return true; +} + +bool MOrder::canReserve()const{return canOrder();} + +bool MOrder::canSell()const +{ + //TODO: redefine canSell + //return m_status==CheckOk || m_status==CheckSaleOnly; + return true; +} + +QString MOrder::orderStatusString()const +{ + return OrderState2str(state()); +} + +QString MOrder::totalPriceString(int off)const +{ + return cent2str(totalprice()+off); +} + +QString MOrder::amountPaidString(int off)const +{ + return cent2str(amountpaid()+off); +} + +bool MOrder::needsPayment()const +{ + if(state()==Placed || state()==Sent) + if(amountpaid()0; + if(state()==Placed || state()==Sent) + return amountpaid()>totalprice(); + return false; +} + +int MOrder::amountToPay()const +{ + if(state()==Placed || state()==Sent) + if(amountpaid()totalprice()) + return amountpaid()-totalprice(); + return 0; +} + +QString MOrder::amountToPayStr(int off)const +{ + return cent2str(amountToPay()+off); +} + +QString MOrder::amountToRefundStr(int off)const +{ + return cent2str(amountToRefund()+off); +} + +bool MOrder::isSent()const +{ + //only in placed mode there is a need for action, hence in all other modes we assume sent + return state()!=Placed; +} + + +void MOrder::pruneInvalid() +{/*TODO + //tickets + QListntc; + for(int i=0;invc; + for(int i=0;irequest("cancelorder",QByteArray::number(m_orderid)))return false; + bool r=req->responseStatus()==MWebRequest::Ok; + if(r)m_status=Cancelled; + return r;*/ + return false; +} + +bool MOrder::shipOrder(QDateTime tm) +{/*TODO + QByteArray rq=QByteArray::number(m_orderid); + if(req->hasRole("_explicitshipdate")){ + rq+="\n"; + rq+=QByteArray::number(tm.toTime_t()); + } + if(!req->request("ordershipped",rq))return false; + bool r=req->responseStatus()==MWebRequest::Ok; + if(r){ + m_status=Sent; + m_stime=req->responseBody().trimmed().toInt(); + } + return r;*/ + return false; +} + +bool MOrder::sendComment(QString nc) +{/*TODO + //make sure we are in a sane state + makeComplete(); + if(!req || m_orderid<0)return false; + //create XML + QDomDocument doc; + QDomElement root=doc.createElement("OrderComment"); + root.setAttribute("orderid",m_orderid); + root.appendChild(doc.createTextNode(nc)); + doc.appendChild(root); + //request + if(!req->request("setordercomment",doc.toByteArray()))return false; + if(req->responseStatus()==MWebRequest::Ok){ + m_comment=nc; + return true; + }else + return false;*/ + return false; +} + +bool MOrder::reservationToOrder(QString cmd) +{/*TODO + //make sure we are in a sane state + makeComplete(); + if(!req || m_orderid<0)return false; + //request + if(!req->request(cmd,QString::number(m_orderid).toUtf8()))return false; + if(req->responseStatus()==MWebRequest::Ok){ + m_status=Placed; + return true; + }else + return false;*/ + return false; +} + +bool MOrder::reservationToSale() +{/*TODO + if(reservationToOrder("reservationtosale")){ + m_status=Sent; + m_paid=m_price; + return true; + }else return false;*/ + return false; +} + +/****************************************************************************** + * Ticket + ******************************************************************************/ + +MTicket::MTicket() +{ + m_paystate=PSUnknown; +} + +MTicket::MTicket(QString t) +{ + m_paystate=PSUnknown; + MTGetTicket gt=req->queryGetTicket(t); + if(gt.stage()==gt.Success){ + MOTicket::operator=(gt.getticket().value()); + } +} + +MTicket::MTicket(const MTicket&t) + :MOTicket(t) +{ + m_paystate=t.m_paystate; +} + +MTicket::MTicket(const MOTicket&t) + :MOTicket(t) +{ + m_paystate=PSUnknown; +} + +MTicket& MTicket::operator=(const MTicket&t) +{ + MOTicket::operator=(t); + m_paystate=t.m_paystate; + return *this; +} + +bool MTicket::isValid()const +{ + //TODO: redo this method + return true; +} + +QString MTicket::priceString(int off)const +{ + qint64 mp=price()+off; + return QString::number(mp/100)+QCoreApplication::translate("MTicket",".","decimal dot")+QString().sprintf("%02Ld",mp%100); +} + +MEvent MTicket::event()const +{ + if(!isValid())return MEvent(); + if(eventid()<0)return MEvent(); + //TODO: reconsider if + //if(!m_event.isValid()) + m_event=req->queryGetEvent(eventid()).getevent().value(); + return m_event; +} + +QString MTicket::statusString()const +{ + return TicketState2str(status()); +} + + +MTicket::PaymentStatus MTicket::paymentStatus() +{ + /*TODO + if(m_paystate!=PSUnknown)return m_paystate; + if(!isValid())return PSUnknown; + if(!req->request("getticket",m_id.toAscii()))return PSUnknown; + if(req->responseStatus()!=MWebRequest::Ok)return PSUnknown; + QDomDocument doc; + if(!doc.setContent(req->responseBody()))return PSUnknown; + scanXml(doc.documentElement()); + */ + return m_paystate; +} + +QString MTicket::markUsed() +{/*TODO + if(!req->request("useticket",m_id.toAscii()))return QCoreApplication::translate("MTicket","Cannot execute request."); + if(req->responseStatus()==MWebRequest::Ok)return ""; + return QCoreApplication::translate("MTicket",req->responseBody().data());*/ + return ""; +} + +void MTicket::updatePrice(int p) +{ + if(p<0 || p==price())return; + //it only makes sense to contact the DB if it can be found there + /*TODO + if(isStored()){ + if(req==0)return; + //send request + QByteArray rq=m_id.toAscii()+"\n"+QByteArray::number(p); + if(!req->request("changeticketprice",rq))return; + if(req->responseStatus()!=MWebRequest::Ok)return; + }*/ + //update locally + setprice(p); +} + +QString MTicket::ticketReturn() +{/*TODO + if(!isStored())return QT_TRANSLATE_NOOP("MTicket","Ticket is not stored, can't return it."); + if(!req->request("ticketreturn",m_id.toUtf8())) + return QT_TRANSLATE_NOOP("MTicket","Failed to execute request"); + if(req->responseStatus()!=MWebRequest::Ok) + return QString::fromUtf8(req->responseBody()); + m_status=Refund;*/ + return ""; +} + +/*int MTicket::amountToPay()const +{ + if(status()==Bought || status()==Used)return price(); + else return 0; +}*/ + +bool MTicket::isToBePaid()const +{ + if(status()==Ordered || status()==Used)return true; + else return false; +} + + +/****************************************************************************** + * Voucher + ******************************************************************************/ + +MVoucher::MVoucher(QString v) +{ + MTGetVoucher gv=req->queryGetVoucher(v); + if(gv.stage()==gv.Success) + operator=(gv.getvoucher().value()); +} + +QString MVoucher::priceString(int off)const{return cent2str(price()+off);} +QString MVoucher::valueString(int off)const{return cent2str(value()+off);} + +bool MVoucher::isValid()const{return voucherid().value()!="";} + +bool MVoucher::isCancelled()const{return price().value()==0 && value().value()==0;} + +bool MVoucher::isEmpty()const{return value().value()==0;} + +QString MVoucher::statusString()const +{ + return VoucherState2str(status()); +} + +QString MVoucher::voucherReturn() +{/*TODO + if(!req)return QT_TRANSLATE_NOOP("MVoucher","Voucher is not stored, can't return it."); + if(!req->request("cancelvoucher",m_id.toUtf8())) + return QT_TRANSLATE_NOOP("MVoucher","Failed to execute request"); + if(req->responseStatus()!=MWebRequest::Ok) + return QString::fromUtf8(req->responseBody()); + m_value=m_price=0;*/ + return ""; +} diff --git a/src/iface/order.h b/src/iface/order.h new file mode 100644 index 0000000..610ac84 --- /dev/null +++ b/src/iface/order.h @@ -0,0 +1,243 @@ +// +// C++ Interface: host +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef MAGICSMOKE_ORDER_H +#define MAGICSMOKE_ORDER_H + +#include +#include +#include + +#include "customer.h" +#include "event.h" +#include "shipping.h" + +#include "MOTicket.h" +#include "MOVoucher.h" +#include "MOOrder.h" + +class MWebRequest; +class QDomDocument; +class QDomElement; + +/**this class represents a single ticket*/ +class MTicket:public MOTicket +{ + public: + /**creates an invalid ticket*/ + MTicket(); + /**gets the ticket from the database*/ + MTicket(QString); + /**copies a ticket*/ + MTicket(const MTicket&); + MTicket(const MOTicket&); + + /**copies the ticket*/ + MTicket& operator=(const MTicket&); + + /**returns whether the ticket is valid*/ + bool isValid()const; + + /**returns the price of the ticket as localized string*/ + QString priceString(int offsetvalue=0)const; + + /**returns whether the ticket is to be paid (ie. it is bought or already used)*/ + bool isToBePaid()const; + + /**returns the event for this ticket (queries DB once)*/ + MEvent event()const; + + /**returns the ticket status as string*/ + QString statusString()const; + + /**payment state of the order*/ + enum PaymentStatus{ + /**yet unknown, need to retrieve it*/ + PSUnknown, + /**no order state (no order)*/ + PSNone, + /**order has been paid ok*/ + PSOk, + /**order is cancelled*/ + PSCancelled, + /**order needs payment*/ + PSNeedPayment, + /**order needs refund*/ + PSNeedRefund + }; + + /**returns the payment state of the order (may check database)*/ + PaymentStatus paymentStatus(); + + /**marks the ticket as used in the database; returns empty string on success, error on failure*/ + QString markUsed(); + + /**updates the price of this ticket, calls DB*/ + void updatePrice(int); + + /**attempts to return the ticket; returns empty string on success, error message on failure*/ + QString ticketReturn(); + + private: + PaymentStatus m_paystate; + mutable MEvent m_event; +}; + +/**this class represents a voucher*/ +class MVoucher:public MOVoucher +{ + public: + /**create empty/invalid voucher*/ + MVoucher(){} + MVoucher(QString); + /**copy voucher*/ + MVoucher(const MVoucher&v):MOVoucher(v){} + MVoucher(const MOVoucher&v):MOVoucher(v){} + + /**copy voucher*/ + MVoucher& operator=(const MVoucher&v){MOVoucher::operator=(v);return *this;} + MVoucher& operator=(const MOVoucher&v){MOVoucher::operator=(v);return *this;} + + /**returns the price of the voucher as string*/ + QString priceString(int off=0)const; + /**returns the remaining value of the voucher as string*/ + QString valueString(int off=0)const; + + /**returns whether this is a valid voucher object*/ + bool isValid()const; + + /**returns whether the voucher is cancelled*/ + bool isCancelled()const; + + /**returns whether the voucher is empty, ie. its remaining value is zero*/ + bool isEmpty()const; + + /**returns a status string for the voucher for displaying*/ + QString statusString()const; + + /**attempts to return the voucher; returns empty string on success, error message on failure*/ + QString voucherReturn(); +}; + +/**this class represents a complete order*/ +class MOrder:public MOOrder +{ + public: + /**create invalid order*/ + MOrder(){} + /**create order by id*/ + MOrder(qint64); + /**copy order*/ + MOrder(const MOrder&o):MOOrder(o){} + + /**copies the order*/ + MOrder& operator=(const MOrder&o){MOOrder::operator=(o);return *this;} + MOrder& operator=(const MOOrder&o){MOOrder::operator=(o);return *this;} + + /**returns whether the order is valid (it comes from the DB and it has been understood by the parser)*/ + bool isValid()const; + + /**returns a customer object (calls database!)*/ + MCustomer customer()const; + + /**returns whether this order is a reservation*/ + bool isReservation()const; + + /**returns whether this order object can be used to generate an order (to be delivered later)*/ + bool canOrder()const; + + /**returns whether this order object can be used to generate a reservation (same rules as for canOrder)*/ + bool canReserve()const; + + /**returns whether this order object can be used to generate a sale (delivered and paid immediately)*/ + bool canSell()const; + + /**returns the status of the order as localized string*/ + QString orderStatusString()const; + + /**returns how much money needs to be paid in total for this order, in cents*/ + QString totalPriceString(int offsetvalue=0)const; + + /**returns how much money has already been paid for this order, in cents*/ + QString amountPaidString(int offsetvalue=0)const; + + /**returns whether there is anything left to pay*/ + bool needsPayment()const; + + /**returns whether there is anything left to refund*/ + bool needsRefund()const; + + /**returns how much there is to be paid, in cents*/ + int amountToPay()const; + + /**returns how much there is to be paid, as localized string*/ + QString amountToPayStr(int offsetvalue=0)const; + + /**returns how much there is to be refunded, in cents*/ + int amountToRefund()const; + + /**returns how much there is to be refunded, as localized string*/ + QString amountToRefundStr(int offsetvalue=0)const; + + /**returns whether the tickets of this order have already been shipped*/ + bool isSent()const; + + /**returns the order date+time as string*/ + QString orderDateTimeStr(); + + /**returns the order date only*/ + QDate orderDate(); + + /**returns the order date only as string*/ + QString orderDateStr(); + + /**returns the shipping date+time*/ + QDateTime sentDateTime(); + + /**returns the shipping date+time as string*/ + QString sentDateTimeStr(); + + /**returns the shipping date only*/ + QDate sentDate(); + + /**returns the shipping date only as string*/ + QString sentDateStr(); + + /**create a new order in the DB; returns it*/ + MOrder createOrder(); + + /**create a sale in the DB; returns it*/ + MOrder createSale(); + + /**create a reservation in the DB; returns it*/ + MOrder createReservation(); + + /**change a reservation into an order*/ + bool reservationToOrder(QString cmd="reservationtoorder"); + + /**change a reservation into a sale*/ + bool reservationToSale(); + + /**cancel the order; queries DB; returns true on success*/ + bool cancelOrder(); + + /**mark the order as shipped; queries DB; returns true on success*/ + bool shipOrder(QDateTime tm=QDateTime::currentDateTime()); + + /**set a new comment and immediately send it to the server (will not set the comment if the server rejects it); returns whether setting was successful*/ + bool sendComment(QString); + + /**if the order is in check state yet: prune invalid objects*/ + void pruneInvalid(); +}; + +#endif diff --git a/src/order.cpp b/src/order.cpp deleted file mode 100644 index 404ec6a..0000000 --- a/src/order.cpp +++ /dev/null @@ -1,445 +0,0 @@ -// -// C++ Implementation: host -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// - -#include "misc.h" -#include "order.h" - -#include "msinterface.h" - -#include -#include -#include - -#define req (MSInterface::instance()) - -MOrder::MOrder(qint64 id) -{ - MTGetOrder go=req->queryGetOrder(id); - if(go.stage()==go.Success) - operator=(go.getorder().value()); -} - -bool MOrder::isValid()const -{ - //TODO: redefine isValid - return true; -} - -MCustomer MOrder::customer()const -{ - return MCustomer(customerid()); -} - -bool MOrder::isReservation()const -{ - return state()==Reserved; -} - -bool MOrder::canOrder()const -{ - //TODO:redefine canOrder - //return m_status==CheckOk || m_status==CheckOrderOnly; - return true; -} - -bool MOrder::canReserve()const{return canOrder();} - -bool MOrder::canSell()const -{ - //TODO: redefine canSell - //return m_status==CheckOk || m_status==CheckSaleOnly; - return true; -} - -QString MOrder::orderStatusString()const -{ - return OrderState2str(state()); -} - -QString MOrder::totalPriceString(int off)const -{ - return cent2str(totalprice()+off); -} - -QString MOrder::amountPaidString(int off)const -{ - return cent2str(amountpaid()+off); -} - -bool MOrder::needsPayment()const -{ - if(state()==Placed || state()==Sent) - if(amountpaid()0; - if(state()==Placed || state()==Sent) - return amountpaid()>totalprice(); - return false; -} - -int MOrder::amountToPay()const -{ - if(state()==Placed || state()==Sent) - if(amountpaid()totalprice()) - return amountpaid()-totalprice(); - return 0; -} - -QString MOrder::amountToPayStr(int off)const -{ - return cent2str(amountToPay()+off); -} - -QString MOrder::amountToRefundStr(int off)const -{ - return cent2str(amountToRefund()+off); -} - -bool MOrder::isSent()const -{ - //only in placed mode there is a need for action, hence in all other modes we assume sent - return state()!=Placed; -} - - -void MOrder::pruneInvalid() -{/*TODO - //tickets - QListntc; - for(int i=0;invc; - for(int i=0;irequest("cancelorder",QByteArray::number(m_orderid)))return false; - bool r=req->responseStatus()==MWebRequest::Ok; - if(r)m_status=Cancelled; - return r;*/ - return false; -} - -bool MOrder::shipOrder(QDateTime tm) -{/*TODO - QByteArray rq=QByteArray::number(m_orderid); - if(req->hasRole("_explicitshipdate")){ - rq+="\n"; - rq+=QByteArray::number(tm.toTime_t()); - } - if(!req->request("ordershipped",rq))return false; - bool r=req->responseStatus()==MWebRequest::Ok; - if(r){ - m_status=Sent; - m_stime=req->responseBody().trimmed().toInt(); - } - return r;*/ - return false; -} - -bool MOrder::sendComment(QString nc) -{/*TODO - //make sure we are in a sane state - makeComplete(); - if(!req || m_orderid<0)return false; - //create XML - QDomDocument doc; - QDomElement root=doc.createElement("OrderComment"); - root.setAttribute("orderid",m_orderid); - root.appendChild(doc.createTextNode(nc)); - doc.appendChild(root); - //request - if(!req->request("setordercomment",doc.toByteArray()))return false; - if(req->responseStatus()==MWebRequest::Ok){ - m_comment=nc; - return true; - }else - return false;*/ - return false; -} - -bool MOrder::reservationToOrder(QString cmd) -{/*TODO - //make sure we are in a sane state - makeComplete(); - if(!req || m_orderid<0)return false; - //request - if(!req->request(cmd,QString::number(m_orderid).toUtf8()))return false; - if(req->responseStatus()==MWebRequest::Ok){ - m_status=Placed; - return true; - }else - return false;*/ - return false; -} - -bool MOrder::reservationToSale() -{/*TODO - if(reservationToOrder("reservationtosale")){ - m_status=Sent; - m_paid=m_price; - return true; - }else return false;*/ - return false; -} - -/****************************************************************************** - * Ticket - ******************************************************************************/ - -MTicket::MTicket() -{ - m_paystate=PSUnknown; -} - -MTicket::MTicket(QString t) -{ - m_paystate=PSUnknown; - MTGetTicket gt=req->queryGetTicket(t); - if(gt.stage()==gt.Success){ - MOTicket::operator=(gt.getticket().value()); - } -} - -MTicket::MTicket(const MTicket&t) - :MOTicket(t) -{ - m_paystate=t.m_paystate; -} - -MTicket::MTicket(const MOTicket&t) - :MOTicket(t) -{ - m_paystate=PSUnknown; -} - -MTicket& MTicket::operator=(const MTicket&t) -{ - MOTicket::operator=(t); - m_paystate=t.m_paystate; - return *this; -} - -bool MTicket::isValid()const -{ - //TODO: redo this method - return true; -} - -QString MTicket::priceString(int off)const -{ - qint64 mp=price()+off; - return QString::number(mp/100)+QCoreApplication::translate("MTicket",".","decimal dot")+QString().sprintf("%02Ld",mp%100); -} - -MEvent MTicket::event()const -{ - if(!isValid())return MEvent(); - if(eventid()<0)return MEvent(); - //TODO: reconsider if - //if(!m_event.isValid()) - m_event=req->queryGetEvent(eventid()).getevent().value(); - return m_event; -} - -QString MTicket::statusString()const -{ - return TicketState2str(status()); -} - - -MTicket::PaymentStatus MTicket::paymentStatus() -{ - /*TODO - if(m_paystate!=PSUnknown)return m_paystate; - if(!isValid())return PSUnknown; - if(!req->request("getticket",m_id.toAscii()))return PSUnknown; - if(req->responseStatus()!=MWebRequest::Ok)return PSUnknown; - QDomDocument doc; - if(!doc.setContent(req->responseBody()))return PSUnknown; - scanXml(doc.documentElement()); - */ - return m_paystate; -} - -QString MTicket::markUsed() -{/*TODO - if(!req->request("useticket",m_id.toAscii()))return QCoreApplication::translate("MTicket","Cannot execute request."); - if(req->responseStatus()==MWebRequest::Ok)return ""; - return QCoreApplication::translate("MTicket",req->responseBody().data());*/ - return ""; -} - -void MTicket::updatePrice(int p) -{ - if(p<0 || p==price())return; - //it only makes sense to contact the DB if it can be found there - /*TODO - if(isStored()){ - if(req==0)return; - //send request - QByteArray rq=m_id.toAscii()+"\n"+QByteArray::number(p); - if(!req->request("changeticketprice",rq))return; - if(req->responseStatus()!=MWebRequest::Ok)return; - }*/ - //update locally - setprice(p); -} - -QString MTicket::ticketReturn() -{/*TODO - if(!isStored())return QT_TRANSLATE_NOOP("MTicket","Ticket is not stored, can't return it."); - if(!req->request("ticketreturn",m_id.toUtf8())) - return QT_TRANSLATE_NOOP("MTicket","Failed to execute request"); - if(req->responseStatus()!=MWebRequest::Ok) - return QString::fromUtf8(req->responseBody()); - m_status=Refund;*/ - return ""; -} - -/*int MTicket::amountToPay()const -{ - if(status()==Bought || status()==Used)return price(); - else return 0; -}*/ - -bool MTicket::isToBePaid()const -{ - if(status()==Ordered || status()==Used)return true; - else return false; -} - - -/****************************************************************************** - * Voucher - ******************************************************************************/ - -MVoucher::MVoucher(QString v) -{ - MTGetVoucher gv=req->queryGetVoucher(v); - if(gv.stage()==gv.Success) - operator=(gv.getvoucher().value()); -} - -QString MVoucher::priceString(int off)const{return cent2str(price()+off);} -QString MVoucher::valueString(int off)const{return cent2str(value()+off);} - -bool MVoucher::isValid()const{return voucherid().value()!="";} - -bool MVoucher::isCancelled()const{return price().value()==0 && value().value()==0;} - -bool MVoucher::isEmpty()const{return value().value()==0;} - -QString MVoucher::statusString()const -{ - return VoucherState2str(status()); -} - -QString MVoucher::voucherReturn() -{/*TODO - if(!req)return QT_TRANSLATE_NOOP("MVoucher","Voucher is not stored, can't return it."); - if(!req->request("cancelvoucher",m_id.toUtf8())) - return QT_TRANSLATE_NOOP("MVoucher","Failed to execute request"); - if(req->responseStatus()!=MWebRequest::Ok) - return QString::fromUtf8(req->responseBody()); - m_value=m_price=0;*/ - return ""; -} diff --git a/src/order.h b/src/order.h deleted file mode 100644 index 610ac84..0000000 --- a/src/order.h +++ /dev/null @@ -1,243 +0,0 @@ -// -// C++ Interface: host -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// - -#ifndef MAGICSMOKE_ORDER_H -#define MAGICSMOKE_ORDER_H - -#include -#include -#include - -#include "customer.h" -#include "event.h" -#include "shipping.h" - -#include "MOTicket.h" -#include "MOVoucher.h" -#include "MOOrder.h" - -class MWebRequest; -class QDomDocument; -class QDomElement; - -/**this class represents a single ticket*/ -class MTicket:public MOTicket -{ - public: - /**creates an invalid ticket*/ - MTicket(); - /**gets the ticket from the database*/ - MTicket(QString); - /**copies a ticket*/ - MTicket(const MTicket&); - MTicket(const MOTicket&); - - /**copies the ticket*/ - MTicket& operator=(const MTicket&); - - /**returns whether the ticket is valid*/ - bool isValid()const; - - /**returns the price of the ticket as localized string*/ - QString priceString(int offsetvalue=0)const; - - /**returns whether the ticket is to be paid (ie. it is bought or already used)*/ - bool isToBePaid()const; - - /**returns the event for this ticket (queries DB once)*/ - MEvent event()const; - - /**returns the ticket status as string*/ - QString statusString()const; - - /**payment state of the order*/ - enum PaymentStatus{ - /**yet unknown, need to retrieve it*/ - PSUnknown, - /**no order state (no order)*/ - PSNone, - /**order has been paid ok*/ - PSOk, - /**order is cancelled*/ - PSCancelled, - /**order needs payment*/ - PSNeedPayment, - /**order needs refund*/ - PSNeedRefund - }; - - /**returns the payment state of the order (may check database)*/ - PaymentStatus paymentStatus(); - - /**marks the ticket as used in the database; returns empty string on success, error on failure*/ - QString markUsed(); - - /**updates the price of this ticket, calls DB*/ - void updatePrice(int); - - /**attempts to return the ticket; returns empty string on success, error message on failure*/ - QString ticketReturn(); - - private: - PaymentStatus m_paystate; - mutable MEvent m_event; -}; - -/**this class represents a voucher*/ -class MVoucher:public MOVoucher -{ - public: - /**create empty/invalid voucher*/ - MVoucher(){} - MVoucher(QString); - /**copy voucher*/ - MVoucher(const MVoucher&v):MOVoucher(v){} - MVoucher(const MOVoucher&v):MOVoucher(v){} - - /**copy voucher*/ - MVoucher& operator=(const MVoucher&v){MOVoucher::operator=(v);return *this;} - MVoucher& operator=(const MOVoucher&v){MOVoucher::operator=(v);return *this;} - - /**returns the price of the voucher as string*/ - QString priceString(int off=0)const; - /**returns the remaining value of the voucher as string*/ - QString valueString(int off=0)const; - - /**returns whether this is a valid voucher object*/ - bool isValid()const; - - /**returns whether the voucher is cancelled*/ - bool isCancelled()const; - - /**returns whether the voucher is empty, ie. its remaining value is zero*/ - bool isEmpty()const; - - /**returns a status string for the voucher for displaying*/ - QString statusString()const; - - /**attempts to return the voucher; returns empty string on success, error message on failure*/ - QString voucherReturn(); -}; - -/**this class represents a complete order*/ -class MOrder:public MOOrder -{ - public: - /**create invalid order*/ - MOrder(){} - /**create order by id*/ - MOrder(qint64); - /**copy order*/ - MOrder(const MOrder&o):MOOrder(o){} - - /**copies the order*/ - MOrder& operator=(const MOrder&o){MOOrder::operator=(o);return *this;} - MOrder& operator=(const MOOrder&o){MOOrder::operator=(o);return *this;} - - /**returns whether the order is valid (it comes from the DB and it has been understood by the parser)*/ - bool isValid()const; - - /**returns a customer object (calls database!)*/ - MCustomer customer()const; - - /**returns whether this order is a reservation*/ - bool isReservation()const; - - /**returns whether this order object can be used to generate an order (to be delivered later)*/ - bool canOrder()const; - - /**returns whether this order object can be used to generate a reservation (same rules as for canOrder)*/ - bool canReserve()const; - - /**returns whether this order object can be used to generate a sale (delivered and paid immediately)*/ - bool canSell()const; - - /**returns the status of the order as localized string*/ - QString orderStatusString()const; - - /**returns how much money needs to be paid in total for this order, in cents*/ - QString totalPriceString(int offsetvalue=0)const; - - /**returns how much money has already been paid for this order, in cents*/ - QString amountPaidString(int offsetvalue=0)const; - - /**returns whether there is anything left to pay*/ - bool needsPayment()const; - - /**returns whether there is anything left to refund*/ - bool needsRefund()const; - - /**returns how much there is to be paid, in cents*/ - int amountToPay()const; - - /**returns how much there is to be paid, as localized string*/ - QString amountToPayStr(int offsetvalue=0)const; - - /**returns how much there is to be refunded, in cents*/ - int amountToRefund()const; - - /**returns how much there is to be refunded, as localized string*/ - QString amountToRefundStr(int offsetvalue=0)const; - - /**returns whether the tickets of this order have already been shipped*/ - bool isSent()const; - - /**returns the order date+time as string*/ - QString orderDateTimeStr(); - - /**returns the order date only*/ - QDate orderDate(); - - /**returns the order date only as string*/ - QString orderDateStr(); - - /**returns the shipping date+time*/ - QDateTime sentDateTime(); - - /**returns the shipping date+time as string*/ - QString sentDateTimeStr(); - - /**returns the shipping date only*/ - QDate sentDate(); - - /**returns the shipping date only as string*/ - QString sentDateStr(); - - /**create a new order in the DB; returns it*/ - MOrder createOrder(); - - /**create a sale in the DB; returns it*/ - MOrder createSale(); - - /**create a reservation in the DB; returns it*/ - MOrder createReservation(); - - /**change a reservation into an order*/ - bool reservationToOrder(QString cmd="reservationtoorder"); - - /**change a reservation into a sale*/ - bool reservationToSale(); - - /**cancel the order; queries DB; returns true on success*/ - bool cancelOrder(); - - /**mark the order as shipped; queries DB; returns true on success*/ - bool shipOrder(QDateTime tm=QDateTime::currentDateTime()); - - /**set a new comment and immediately send it to the server (will not set the comment if the server rejects it); returns whether setting was successful*/ - bool sendComment(QString); - - /**if the order is in check state yet: prune invalid objects*/ - void pruneInvalid(); -}; - -#endif diff --git a/src/shipping.cpp b/src/shipping.cpp deleted file mode 100644 index 574912a..0000000 --- a/src/shipping.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// -// C++ Implementation: shipping -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#include "misc.h" -#include "shipping.h" -#include "centbox.h" - -#include "MOShipping.h" - -#include "msinterface.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define req (MSInterface::instance()) - -MShippingEditor::MShippingEditor(QWidget*par) - :QDialog(par) -{ - all=req->queryGetAllShipping().getshipping(); - setWindowTitle(tr("Edit Shipping Options")); - - QHBoxLayout*hl; - QVBoxLayout*vl,*vl2; - setLayout(vl=new QVBoxLayout); - vl->addLayout(hl=new QHBoxLayout,1); - hl->addWidget(table=new QTableView,1); - table->setModel(model=new QStandardItemModel(this)); - table->setEditTriggers(QAbstractItemView::NoEditTriggers); - updateTable(); - hl->addLayout(vl2=new QVBoxLayout,0); - QPushButton*p; - vl2->addWidget(p=new QPushButton(tr("Change Description"))); - connect(p,SIGNAL(clicked()),this,SLOT(changeDescription())); - vl2->addWidget(p=new QPushButton(tr("Change Price"))); - connect(p,SIGNAL(clicked()),this,SLOT(changePrice())); - vl2->addWidget(p=new QPushButton(tr("Change Availability"))); - connect(p,SIGNAL(clicked()),this,SLOT(changeAvail())); - vl2->addSpacing(20); - vl2->addWidget(p=new QPushButton(tr("Add Option"))); - connect(p,SIGNAL(clicked()),this,SLOT(addNew())); - vl2->addWidget(p=new QPushButton(tr("Delete Option"))); - connect(p,SIGNAL(clicked()),this,SLOT(deleteShip())); - vl2->addStretch(1); - - vl->addSpacing(15); - vl->addLayout(hl=new QHBoxLayout,0); - hl->addStretch(10); - hl->addWidget(p=new QPushButton(tr("Ok"))); - connect(p,SIGNAL(clicked()),this,SLOT(accept())); - hl->addWidget(p=new QPushButton(tr("Cancel"))); - connect(p,SIGNAL(clicked()),this,SLOT(reject())); -} -void MShippingEditor::updateTable() -{ - model->clear(); - model->insertColumns(0,5); - model->insertRows(0,all.size()); - model->setHorizontalHeaderLabels(QStringList()<setData(model->index(i,0),all[i].id().value()); - model->setData(model->index(i,1),all[i].description().value()); - model->setData(model->index(i,2),cent2str(all[i].cost())); - model->setData(model->index(i,3),all[i].canuseweb().value()?tr("Yes"):tr("No")); - model->setData(model->index(i,4),all[i].canallusers().value()?tr("Yes"):tr("No")); - } - table->resizeColumnsToContents(); -} - -void MShippingEditor::changeDescription() -{/*TODO - //find item - QModelIndexList lst=table->selectionModel()->selectedIndexes(); - if(lst.size()<1)return; - QModelIndex idx=lst[0]; - //get shipping - MShipping s=all[idx.row()]; - //get new value - QString r=QInputDialog::getText(this,tr("Shipping Option Description"),tr("Please select a new description for this shipping option:"),QLineEdit::Normal,s.description()); - if(r=="")return; - s.setDescription(r); - if(!s.save()){ - QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes.")); - return; - } - all[idx.row()]=s; - updateTable();*/ -} - -void MShippingEditor::changePrice() -{/*TODO - //find item - QModelIndexList lst=table->selectionModel()->selectedIndexes(); - if(lst.size()<1)return; - QModelIndex idx=lst[0]; - //get shipping - MShipping s=all[idx.row()]; - //get new value - bool b; - int r=MCentDialog::getCents(this,tr("Shipping Option Price"),tr("Please select a new price for this shipping option:"),s.price(),1000000000,&b); - if(!b)return; - s.setPrice(r); - if(!s.save()){ - QMessageBox::warning(this,tr("Warning"),tr("Could not store the changes.")); - return; - } - all[idx.row()]=s; - updateTable();*/ -} -void MShippingEditor::changeAvail() -{/*TODO - //find item - QModelIndexList lst=table->selectionModel()->selectedIndexes(); - if(lst.size()<1)return; - QModelIndex idx=lst[0]; - //get shipping - MShipping s=all[idx.row()]; - //get new value - bool b; - QStringList opt; - opt<selectionModel()->selectedIndexes(); - if(lst.size()<1)return; - QModelIndex idx=lst[0]; - //get shipping - int id=all[idx.row()].id(); - if(!req->request("deleteshipping",QString::number(id).toAscii())){ - QMessageBox::warning(this,tr("Warning"),tr("Unable to delete this option.")); - return; - } - if(req->responseStatus()!=MWebRequest::Ok){ - QMessageBox::warning(this,tr("Warning"),tr("Unable to delete this option.")); - return; - } - all.removeAt(idx.row()); - updateTable();*/ -} diff --git a/src/shipping.h b/src/shipping.h deleted file mode 100644 index 58815aa..0000000 --- a/src/shipping.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// C++ Interface: shipping -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2008 -// -// Copyright: See README/COPYING files that come with this distribution -// -// - -#ifndef MAGICSMOKE_SHIPPING_H -#define MAGICSMOKE_SHIPPING_H - -#include -#include - -class QStandardItemModel; -class QTableView; - -#include "MOShipping.h" - -class MShippingEditor:public QDialog -{ - Q_OBJECT - public: - MShippingEditor(QWidget*); - - private slots: - void changeDescription(); - void changePrice(); - void changeAvail(); - void addNew(); - void deleteShip(); - void updateTable(); - - private: - QListall; - QStandardItemModel*model; - QTableView*table; -}; - -#endif diff --git a/src/smoke.pro b/src/smoke.pro index f487a77..1200bd8 100644 --- a/src/smoke.pro +++ b/src/smoke.pro @@ -20,19 +20,8 @@ MOC_DIR = .ctmp RCC_DIR = .ctmp -SOURCES = \ - main.cpp \ - event.cpp \ - order.cpp \ - shipping.cpp \ - customer.cpp - -HEADERS = \ - main.h \ - event.h \ - order.h \ - shipping.h \ - customer.h +SOURCES = main.cpp +HEADERS = main.h RESOURCES += images/files.qrc -- 1.7.2.5