//check for current selection
if(nid<0){
QModelIndex idx=m_listview->currentIndex();
- if(idx.isValid())
- nid=m_proxymodel->data(idx,Qt::UserRole).toInt();
+ if(idx.isValid()){
+ int i=m_proxymodel->data(idx,Qt::UserRole).toInt();
+ if(i>=0&&i<m_list.size())
+ nid=m_list[i].customerid();
+ }
}
//go to server
MTGetAllCustomerNames gac=req->queryGetAllCustomerNames();
m_addr.setcountryid(m_addr.country().value().id());
m_country->setText(m_addr.country().value().name());
}
+
+/*****************************************************************************/
+
+MAddressChoiceDialog::MAddressChoiceDialog(QWidget*par,const MOCustomer&c)
+ :QDialog(par),m_cust(c)
+{
+ m_needupdate=false;
+ setWindowTitle(tr("Chose an Address"));
+ QHBoxLayout*hl;
+ QVBoxLayout*vl;
+ setLayout(vl=new QVBoxLayout);
+ vl->addWidget(m_lwidget=new MAddressListWidget(this,m_cust.addresses(),true),10);
+ connect(m_lwidget,SIGNAL(addressChanged(const MOAddress&)),this,SLOT(changed()));
+ connect(m_lwidget,SIGNAL(addressDeleted(const MOAddress&)),this,SLOT(changed()));
+ connect(m_lwidget,SIGNAL(addressCreated(const MOAddress&)),this,SLOT(changed()));
+ connect(m_lwidget,SIGNAL(addressEdited(const MOAddress&)),this,SLOT(changed()));
+ //on selection: first update customer, then close window
+ connect(m_lwidget,SIGNAL(addressSelected(qint64)),this,SLOT(updateCustomer()),Qt::DirectConnection);
+
+ vl->addLayout(hl=new QHBoxLayout,0);
+ hl->addStretch(10);
+ QPushButton*p;
+ hl->addWidget(p=new QPushButton(tr("Add Address")),0);
+ connect(p,SIGNAL(clicked()),m_lwidget,SLOT(createAddress()));
+ hl->addSpacing(20);
+ hl->addWidget(p=new QPushButton(tr("Cancel")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(reject()));
+}
+
+MOAddress MAddressChoiceDialog::address()const{return m_lwidget->selection();}
+qint64 MAddressChoiceDialog::addressId()const{return m_lwidget->selection().addressid();}
+void MAddressChoiceDialog::changed(){m_needupdate=true;}
+
+void MAddressChoiceDialog::updateCustomer()
+{
+ setEnabled(false);
+ if(m_needupdate){
+ //do update
+ m_cust.setaddresses(m_lwidget->addressList());
+ MTChangeCustomer cc=MTChangeCustomer::query(m_cust);
+ if(cc.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Unable to save changes made to addresses: %1").arg(cc.errorString()));
+ return;
+ }
+ m_cust=cc.getcustomer();
+ }
+ //close dialog successfully
+ accept();
+}
MCartTab::MCartTab(QString pk)
{
profilekey=pk;
+ deliveryaddrid=invoiceaddrid=-1;
QVBoxLayout*vl;QHBoxLayout*hl;
QPushButton*p;
connect(p,SIGNAL(clicked()),this,SLOT(cartAddTicket()));
hl2->addWidget(p=new QPushButton(tr("Add Voucher")),0);
connect(p,SIGNAL(clicked()),this,SLOT(cartAddVoucher()));
- hl2->addWidget(p=new QPushButton(tr("Remove Item")),0);
+ hl2->addWidget(p=new QPushButton(tr("Add Shop Item")),0);
+ //TODO: implement items
+ p->setEnabled(false);
+ connect(p,SIGNAL(clicked()),this,SLOT(cartAddItem()));
+ hl2->addSpacing(15);
+ hl2->addWidget(p=new QPushButton(tr("Remove Line")),0);
connect(p,SIGNAL(clicked()),this,SLOT(cartRemoveItem()));
QFrame*frm;
hl->addWidget(frm=new QFrame,0);
hl->addLayout(vl2=new QVBoxLayout,1);
vl2->addWidget(p=new QPushButton(tr("Customer:")),0);
connect(p,SIGNAL(clicked()),this,SLOT(setCustomer()));
- vl2->addWidget(cartcustomer=new QLabel("...\n \n \n "));
+ vl2->addWidget(cartcustomer=new QLabel("..."));
+ vl2->addWidget(frm=new QFrame,0);
+ frm->setFrameShape(QFrame::HLine);
+ vl2->addWidget(p=new QPushButton(tr("Invoice Address:")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(setInvoiceAddr()));
+ vl2->addWidget(invoiceaddr=new QLabel("..."));
+ vl2->addWidget(frm=new QFrame,0);
+ frm->setFrameShape(QFrame::HLine);
+ vl2->addWidget(p=new QPushButton(tr("Delivery Address:")),0);
+ connect(p,SIGNAL(clicked()),this,SLOT(setDeliveryAddr()));
+ vl2->addWidget(deliveryaddr=new QLabel("..."));
vl2->addWidget(frm=new QFrame,0);
frm->setFrameShape(QFrame::HLine);
vl2->addSpacing(10);
vl2->addWidget(new QLabel(tr("Shipping Method:")),0);
vl2->addWidget(cartship=new QComboBox,0);
cartship->setEditable(false);
- vl2->addWidget(new QLabel(tr("Delivery Address:")),0);
- vl2->addWidget(cartaddr=new QTextEdit);
vl2->addSpacing(10);
vl2->addWidget(new QLabel(tr("Comments:")),0);
vl2->addWidget(cartcomment=new QTextEdit);
//clear customer
customer=MOCustomer();
cartcustomer->setText("");
- //clear address/comment
- cartaddr->setPlainText("");
+ //clear address
+ deliveryaddr->setText("");
+ invoiceaddr->setText("");
+ deliveryaddrid=invoiceaddrid=-1;
+ //clear comment
cartcomment->setPlainText("");
//clear shipping
cartship->setCurrentIndex(0);
MCustomerListDialog mcl(this,true,customer.id());
if(mcl.exec()!=QDialog::Accepted)return;
customer=mcl.getCustomer();
- //TODO: follow up with address dialog
-// cartcustomer->setText(customer.getNameAddress());
+ cartcustomer->setText(customer.fullName());
+ //clear address
+ deliveryaddr->setText("");
+ invoiceaddr->setText("");
+ deliveryaddrid=invoiceaddrid=-1;
+ //follow up with address dialog
+ if(!customer.customerid().isNull())
+ setInvoiceAddr();
+}
+
+void MCartTab::setDeliveryAddr()
+{
+ if(customer.customerid().isNull()){
+ QMessageBox::warning(this,tr("Warning"),tr("Please set the customer first."));
+ return;
+ }
+ MAddressChoiceDialog d(this,customer);
+ if(d.exec()!=QDialog::Accepted)return;
+ customer=d.customer();
+ deliveryaddr->setText(d.address().fullAddress(customer.fullName()));
+ deliveryaddrid=d.addressId();
+}
+
+void MCartTab::setInvoiceAddr()
+{
+ if(customer.customerid().isNull()){
+ //customer not set yet, chose it
+ setCustomer();
+ //the setCustomer routine will recurse back to here
+ return;
+ }
+ MAddressChoiceDialog d(this,customer);
+ if(d.exec()!=QDialog::Accepted)return;
+ customer=d.customer();
+ invoiceaddr->setText(d.address().fullAddress(customer.fullName()));
+ invoiceaddrid=d.addressId();
}
static const int CART_TICKET=1;
}
void MCartTab::cartAddVoucher()
-{/*TODO
+{
//create voucher selection dialog
QDialog dlg;
dlg.setWindowTitle(tr("Select Voucher"));
QGridLayout*gl;
QStandardItemModel mdl;
QRegExpValidator regv(priceRegExp(),this);
- QList<int>prc=req->getVoucherPrices();
+ QList<qint64>prc=MTGetValidVoucherPrices::query().getprices();
mdl.insertRows(0,prc.size());
mdl.insertColumns(0,1);
for(int i=0;i<prc.size();i++)mdl.setData(mdl.index(i,0),cent2str(prc[i]));
dlg.setLayout(gl=new QGridLayout);
gl->addWidget(new QLabel(tr("Select voucher price and value:")),0,0,1,2);
- if(req->hasRole("_anypricevoucher")){
+ if(req->hasRight(req->PCreateOrder_DiffVoucherValuePrice)){
gl->addWidget(new QLabel(tr("Price:")),1,0);
gl->addWidget(cp=new QComboBox,1,1);
cp->setModel(&mdl);
gl->addWidget(new QLabel(tr("Value:")),2,0);
gl->addWidget(cv=new QComboBox,2,1);
cv->setModel(&mdl);
- cv->setEditable(req->hasRole("_anyvoucher"));
+ cv->setEditable(req->hasRight(req->PCreateOrder_AnyVoucherValue));
cv->setValidator(®v);
gl->setRowMinimumHeight(3,15);
gl->setColumnStretch(0,0);
//get selection
int price,value;
value=str2cent(cv->currentText());
- if(req->hasRole("_anypricevoucher") && cp)
+ if(req->hasRight(req->PCreateOrder_DiffVoucherValuePrice) && cp)
price=str2cent(cp->currentText());
else
price=value;
cartmodel->setData(cartmodel->index(cr,0),CART_VOUCHER,CART_TYPEROLE);
cartmodel->setData(cartmodel->index(cr,1),tr("Voucher (price: %1, value %2)").arg(cent2str(price)).arg(cent2str(value)));
carttable->resizeColumnsToContents();
- }*/
+ }
+}
+
+void MCartTab::cartAddItem()
+{
+ //TODO: implement items
}
void MCartTab::cartRemoveItem()
void MCartTab::cartOrder()
{
-/* //sanity checks
+ //sanity checks
if(cartmodel->rowCount()<1){
QMessageBox::warning(this,tr("Error"),tr("There is nothing in the order. Ignoring it."));
return;
QMessageBox::warning(this,tr("Error"),tr("Please chose a customer first!"));
return;
}
+ if(cartship->currentIndex()>0 && deliveryaddrid<0 && invoiceaddrid<0){
+ if(QMessageBox::question(this,tr("Shipping"),tr("You have chosen a shipping method, but no address. Are you sure you want to continue?"),QMessageBox::Yes|QMessageBox::No) != QMessageBox::Yes)return;
+ }
///////////////
//create order
- QDomDocument doc;
- QDomElement root=doc.createElement("Order");
- root.setAttribute("customer",customer.id());
+ MOCartOrder cord;
+ cord.setcustomerid(customer.id());
//is there a delivery address
- QString s=cartaddr->toPlainText().trimmed();
- if(s!=""){
- QDomElement da=doc.createElement("DeliveryAddress");
- da.appendChild(doc.createTextNode(s));
- root.appendChild(da);
- }
+ if(deliveryaddrid>=0)cord.setdeliveryaddressid(deliveryaddrid);
+ if(invoiceaddrid>=0)cord.setinvoiceaddressid(invoiceaddrid);
//is there a comment?
- s=cartcomment->toPlainText().trimmed();
- if(s!=""){
- QDomElement cc=doc.createElement("Comment");
- cc.appendChild(doc.createTextNode(s));
- root.appendChild(cc);
- }
+ QString s=cartcomment->toPlainText().trimmed();
+ if(s!="")cord.setcomment(s);
//scan tickets & scan vouchers
for(int i=0;i<cartmodel->rowCount();i++){
QModelIndex idx=cartmodel->index(i,0);
int tp=cartmodel->data(idx,CART_TYPEROLE).toInt();
if(tp==CART_TICKET){
- int amt=cartmodel->data(idx).toInt();
- int evid=cartmodel->data(idx,CART_IDROLE).toInt();
- for(int j=0;j<amt;j++){
- QDomElement tc=doc.createElement("Ticket");
- tc.setAttribute("event",evid);
- root.appendChild(tc);
- }
+ MOCartTicket ct;
+ ct.setamount(cartmodel->data(idx).toInt());
+ ct.seteventid(cartmodel->data(idx,CART_IDROLE).toInt());
+ cord.addtickets(ct);
}else
if(tp==CART_VOUCHER){
- int amt=cartmodel->data(idx).toInt();
- int price=cartmodel->data(idx,CART_PRICEROLE).toInt();
- int value=cartmodel->data(idx,CART_VALUEROLE).toInt();
- for(int j=0;j<amt;j++){
- QDomElement tc=doc.createElement("Voucher");
- tc.setAttribute("price",price);
- tc.setAttribute("value",value);
- root.appendChild(tc);
- }
-
+ MOCartVoucher cv;
+ cv.setamount(cartmodel->data(idx).toInt());
+ cv.setprice(cartmodel->data(idx,CART_PRICEROLE).toInt());
+ cv.setvalue(cartmodel->data(idx,CART_VALUEROLE).toInt());
+ cord.addvouchers(cv);
}
+ //TODO: product/items
}
//set shipping info
- if(cartship->currentIndex()>0){
- QDomElement si=doc.createElement("Shipping");
- si.setAttribute("type",cartship->itemData(cartship->currentIndex()).toInt());
- root.appendChild(si);
- }
- //finalize
- doc.appendChild(root);*/
+ cord.setshippingtypeid(cartship->itemData(cartship->currentIndex()).toInt());
//send
- /*TODO
- if(req->request("checkorder",doc.toByteArray())==false){
- QMessageBox::warning(this,tr("Error"),tr("The request failed."));
- return;
- }
- if(req->responseStatus()!=MSInterface::Ok){
- QMessageBox::warning(this,tr("Error"),tr("A problem occurred during the order: %1").arg(qApp->translate("php::",req->responseBody())));
+ MTCreateOrder co=req->queryCreateOrder(cord);
+ if(co.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while creating order: %1").arg(co.errorString()));
return;
}
- //parse result
- QDomDocument rdoc;
- rdoc.setContent(req->responseBody());
- //display order and give user chance to actually order it
- MOrderWindow *ow=new MOrderWindow(this,req,MOrder(req,rdoc.documentElement()));
+ initCart();
+ MOrderWindow *ow=new MOrderWindow(window(),co.getorder());
ow->show();
- //empty the cart
- initCart();*/
}
/********************************************************************************/