QMenuBar*mb=menuBar();
QMenu *m=mb->addMenu(tr("&Order"));
- m->addAction(tr("&Order..."),this,SLOT(createOrder()))
- ->setEnabled(req->hasRight(req->RReservationToOrder)&&o.isReservation());
- m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder()))
- ->setEnabled(req->hasRight(req->RCancelOrder));
- m->addAction(tr("&Mark Order as Shipped..."),this,SLOT(shipOrder()))
- ->setEnabled(req->hasRight(req->ROrderMarkShipped));
+ m_res2order=m->addAction(tr("&Order..."),this,SLOT(createOrder()));
+ m_cancel=m->addAction(tr("C&ancel Order..."),this,SLOT(cancelOrder()));
+ m_ship=m->addAction(tr("&Mark Order as Shipped..."),this,SLOT(shipOrder()));
m->addSeparator();
m->addAction(tr("Ch&ange Item-Price..."),this,SLOT(changeItem()))
->setEnabled(req->hasRole("changeticketprice"));
m->addAction(tr("&Return Item..."),this,SLOT(itemReturn()))
->setEnabled(req->hasRole("ticketreturn"));
- m->addAction(tr("Change Commen&t..."),this,SLOT(changeComment()))
- ->setEnabled(req->hasRole("setordercomment"));
+ m->addAction(tr("Add Commen&t..."),this,SLOT(changeComment()))
+ ->setEnabled(req->hasRight(req->ROrderAddComment));
m->addAction(tr("Change Sh&ipping Method..."),this,SLOT(changeShipping()))
->setEnabled(req->hasRight(req->ROrderChangeShipping));
m->addSeparator();
m->addAction(tr("&Close"),this,SLOT(close()));
m=mb->addMenu(tr("&Payment"));
- m->addAction(tr("Receive &Payment..."),this,SLOT(payment()))
- ->setEnabled(req->hasRight(req->ROrderPay));
- m->addAction(tr("&Refund..."),this,SLOT(refund()))
- ->setEnabled(req->hasRight(req->ROrderRefund));
- m->addAction(tr("Pay with &Voucher..."),this,SLOT(payvoucher()))
- ->setEnabled(req->hasRight(req->RUseVoucher));
-
+ m_pay=m->addAction(tr("Receive &Payment..."),this,SLOT(payment()));
+ m_refund=m->addAction(tr("&Refund..."),this,SLOT(refund()));
+ m_payv=m->addAction(tr("Pay with &Voucher..."),this,SLOT(payvoucher()));
+
m=mb->addMenu(tr("P&rinting"));
m->addAction(tr("Print &Bill..."),this,SLOT(printBill()));
m->addAction(tr("Save Bill &as file..."),this,SLOT(saveBill()));
}
//refresh
m_table->resizeColumnsToContents();
+ m_res2order->setEnabled(req->hasRight(req->RReservationToOrder)&&m_order.isReservation());
+ m_cancel->setEnabled(req->hasRight(req->RCancelOrder));
+ m_ship->setEnabled(req->hasRight(req->ROrderMarkShipped)&&m_order.status()==m_order.Placed);
+ m_pay->setEnabled(req->hasRight(req->ROrderPay)&&m_order.needsPayment());
+ m_payv->setEnabled(req->hasRight(req->RUseVoucher)&&m_order.needsPayment());
+ m_refund->setEnabled(req->hasRight(req->ROrderRefund)&&m_order.needsRefund());
}
void MOrderWindow::itemView()
}
void MOrderWindow::payment()
-{/*TODO
- if(!m_order.isValid())return;
+{
//get value
bool ok;
int pay=MCentDialog::getCents(this,tr("Enter Payment"),tr("Please enter the amount that has been paid:"),m_order.amountToPay(),m_order.amountToPay(),&ok);
if(!ok)return;
if(pay<=0)return;
//submit
- QByteArray rq=QByteArray::number(m_order.orderID())+" "+QByteArray::number(pay);
- if(!req->request("orderpay",rq)){
- QMessageBox::warning(this,tr("Warning"),tr("Unable to submit payment request."));
+ MTOrderPay op=req->queryOrderPay(m_order.orderid(),pay);
+ if(op.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay: %1").arg(op.errorString()));
return;
}
- if(req->responseStatus()!=MWebRequest::Ok){
- QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay: %1").arg(qApp->translate("php::",req->responseBody())));
- return;
- }
- m_order.setAmountPaid(req->responseBody().trimmed().toInt());
- m_paid->setText(m_order.amountPaidString());*/
+ m_order=op.getorder();
+ updateData();
}
void MOrderWindow::payvoucher()
-{/*TODO
+{
if(!m_order.isValid())return;
//get voucher
bool ok;
QString vid=QInputDialog::getText(this,tr("Enter Voucher"),tr("Please enter the ID of the voucher you want to use:"),QLineEdit::Normal,"",&ok);
if(!ok)return;
if(vid=="")return;
- MVoucher vou(req,vid);
- if(!vou.isValid()){
- QMessageBox::warning(this,tr("Warning"),tr("This voucher is not valid."));
- return;
- }
//submit
- QByteArray rq=vid.toAscii()+"\n"+QByteArray::number(m_order.orderID());
- if(!req->request("usevoucher",rq)){
- QMessageBox::warning(this,tr("Warning"),tr("Unable to submit payment request."));
+ MTUseVoucher uv=req->queryUseVoucher(m_order.orderid(),vid);
+ if(uv.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay with voucher '%1': %2").arg(vid).arg(uv.errorString()));
return;
}
- if(req->responseStatus()!=MWebRequest::Ok){
- QMessageBox::warning(this,tr("Warning"),tr("Error while trying to pay: %1").arg(qApp->translate("php::",req->responseBody())));
- return;
- }
- QStringList sl=QString::fromAscii(req->responseBody().trimmed()).split("\n");
- if(sl.size()>1){
- m_order.setAmountPaid(sl[1].toInt());
- m_paid->setText(m_order.amountPaidString());
- }
- if(sl.size()>0){
- QMessageBox::information(this,tr("Voucher Info"),tr("Remaining value of this voucher: %1").arg(cent2str(sl[0].toInt())));
- }*/
+ m_order=uv.getorder();
+ QMessageBox::information(this,tr("Voucher Info"),
+ tr("Successfully paid order %1 with voucher '%2'.\nAmount deducted: %3\nRemaining value of this voucher: %4")
+ .arg(m_order.orderid())
+ .arg(vid)
+ .arg(cent2str(uv.getamount()))
+ .arg(cent2str(uv.getvoucher().value().value()))
+ );
+ updateData();
}
void MOrderWindow::refund()
-{/*TODO
+{
if(!m_order.isValid())return;
//get value
bool ok;
if(!ok)return;
if(pay<=0)return;
//submit
- QByteArray rq=QByteArray::number(m_order.orderID())+" "+QByteArray::number(pay);
- if(!req->request("orderrefund",rq)){
- QMessageBox::warning(this,tr("Warning"),tr("Unable to submit refund request."));
+ MTOrderRefund op=req->queryOrderRefund(m_order.orderid(),pay);
+ if(op.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while trying to refund: %1").arg(op.errorString()));
return;
}
- if(req->responseStatus()!=MWebRequest::Ok){
- QMessageBox::warning(this,tr("Warning"),tr("Error whily trying to refund: %1").arg(qApp->translate("php::",req->responseBody())));
- return;
- }
- m_order.setAmountPaid(req->responseBody().trimmed().toInt());
- m_paid->setText(m_order.amountPaidString());*/
+ m_order=op.getorder();
+ updateData();
}
void MOrderWindow::changeItem()
}
void MOrderWindow::changeComment()
-{/*TODO
+{
//create editor dialog
- QString cmt=m_order.comment();
+ QString cmt=m_order.comments();
QDialog d;
- d.setWindowTitle(tr("Set comment: order %1").arg(m_order.orderID()));
+ d.setWindowTitle(tr("Add comment: order %1").arg(m_order.orderid()));
QVBoxLayout*vl;
d.setLayout(vl=new QVBoxLayout);
QTextEdit*te;
+ QLabel*lab;
+ vl->addWidget(lab=new QLabel("Current comment:\n"+cmt));
+ lab->setWordWrap(true);
vl->addWidget(te=new QTextEdit,1);
- te->setPlainText(cmt);
vl->addSpacing(15);
QHBoxLayout*hl;
vl->addLayout(hl=new QHBoxLayout,0);
//get status
if(d.exec()!=QDialog::Accepted)return;
//send to server
- m_order.sendComment(cmt=te->toPlainText());
+ MTOrderAddComment ac=req->queryOrderAddComment(m_order.orderid(),te->toPlainText());
+ if(ac.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("There was a problem uploading the new comment: %1").arg(ac.errorString()));
+ return;
+ }
+ m_order=ac.getorder();
//reset display
- m_comment->setText(cmt);*/
+ updateData();
}
void MOrderWindow::changeShipping()
<Input>
<Var name="ticketid" type="astring"/>
</Input>
+ <Call lang="php" method="$this->setticket(WOTicket::fromTableticket(WTticket::getFromDB($this->getticketid())));"/>
<Output>
<Var name="ticket" type="Ticket"/>
</Output>
<Map column="orderid"/>
<Map column="isused"/>
<Map property="status">
+ <!-- dummy, since this conversion is only used for existing valid vouchers -->
<Call lang="php" method="self::Ok"/>
</Map>
</Mapping>
<Input>
<Var name="voucherid" type="astring"/>
</Input>
+ <Call lang="php" method="$this->setvoucher(WOVoucher::fromTablevoucher(WTvoucher::getFromDB($this->getvoucherid())));"/>
<Output>
<Var name="voucher" type="Voucher"/>
</Output>
<Property name="vouchers" type="List:Voucher"/>
<Property name="items" type="List:ItemInfo"/>
- <Property name="amountpaid" type="int"/>
<Property name="status" type="OrderState"/>
- <Property name="amountdue" type="int"/><!-- abstract="yes"? -->
- <Property name="totalprice" type="int"/><!-- abstract="yes"? -->
- <Property name="shippingcosts" type="int"/>
+ <Property name="amountpaid" type="int">amount that has been paid for this order</Property>
+ <Property name="amountdue" type="int">amount that needs to be paid, negative if too much has been paid</Property>
+ <Property name="totalprice" type="int">total price for this order (including shipping and all items)</Property>
+ <Property name="shippingcosts" type="int">costs for shipping</Property>
<Property name="shippingtypeid" type="int"/>
<Property name="shippingtype" type="Shipping"/>
<Property name="status" type="OrderState"/>
- <Property name="amountpaid" type="int"/>
- <Property name="amountdue" type="int"/>
- <Property name="totalprice" type="int"/>
- <Property name="shippingcosts" type="int"/>
+ <Property name="amountpaid" type="int">amount that has been paid for this order</Property>
+ <Property name="amountdue" type="int">amount that needs to be paid, negative if too much has been paid</Property>
+ <Property name="totalprice" type="int">total price for this order (including shipping and all items)</Property>
+ <Property name="shippingcosts" type="int">costs for shipping</Property>
<Property name="ordertime" type="int64"/>
<Property name="senttime" type="int64"/>
<Transaction name="CreateReservation"/>
<Transaction name="ReservationToOrder"/>
<Transaction name="CancelOrder"/>
- <Transaction name="OrderPay"/>
- <Transaction name="OrderRefund"/>
- <Transaction name="UseVoucher"/>
+ <Transaction name="OrderPay">
+ <Input>
+ <Var name="orderid" type="int">The order to be paid</Var>
+ <Var name="amount" type="int">amount offered, it must be positive</Var>
+ </Input>
+ <Call lang="php" method="WOOrder::payForOrder($this);"/>
+ <Output>
+ <Var name="order" type="Order">fresh copy of the order</Var>
+ <Var name="amount" type="int">the amount actually taken, it is between 0 and at maximum the amount due for the order, it is never above the offered amount</Var>
+ </Output>
+ </Transaction>
+
+ <Transaction name="OrderRefund">
+ <Input>
+ <Var name="orderid" type="int"/>
+ <Var name="amount" type="int"/>
+ </Input>
+ <Call lang="php" method="WOOrder::refundOrder($this);"/>
+ <Output>
+ <Var name="order" type="Order"/>
+ <Var name="amount" type="int"/>
+ </Output>
+ </Transaction>
+
+ <Transaction name="UseVoucher">
+ <Input>
+ <Var name="orderid" type="int"/>
+ <Var name="voucherid" type="string"/>
+ </Input>
+ <Call lang="php" method="WOOrder::payForOrderVoucher($this);"/>
+ <Output>
+ <Var name="order" type="Order"/>
+ <Var name="voucher" type="Voucher"/>
+ <Var name="amount" type="int"/>
+ </Output>
+ </Transaction>
+
<Transaction name="OrderChangeShipping">
<Doc>Changes the shipping option and/or price of an order</Doc>
</Output>
</Transaction>
+ <Transaction name="OrderAddComment">
+ <Input>
+ <Var name="orderid" type="int">the order to be commented upon</Var>
+ <Var name="comment" type="string">the comment</Var>
+ </Input>
+ <Call lang="php" method="WOOrder::addComment($this);"/>
+ <Output>
+ <Var name="order" type="Order">a fresh copy of the changed order</Var>
+ </Output>
+ </Transaction>
+
<Transaction name="GetAllShipping">
<Input/>
<Call lang="php" method="$this->setshipping(WOShipping::fromTableArrayshipping(WTshipping::selectFromDB()));"/>
//return
$trans->setorder(WOOrder::fromTableorder($ord));
}
+
+ /**called from the OrderAddComment transaction*/
+ public static function addComment($trans)
+ {
+ global $session;
+ //get order
+ $ord=WTorder::getFromDB($trans->getorderid());
+ if($ord===false){
+ $trans->abortWithError(tr("Order ID is not valid."));
+ return;
+ }
+ //modify comment
+ $cmt=trim($ord->comments);
+ $nc=trim($trans->getcomment()."");
+ if($nc!=""){
+ if($cmt!="")$cmt.="\n";
+ $cmt.="[".$session->currentUserName()." ".date("Y-m-d G:i")."] ".$nc;
+ $ord->comments=$cmt;
+ $ord->update();
+ }
+ //return
+ $trans->setorder(WOOrder::fromTableorder($ord));
+ }
+
+ /**called from the OrderPay transaction*/
+ public static function payForOrder($trans)
+ {
+ //get order
+ $ord=WTorder::getFromDB($trans->getorderid());
+ if($ord===false){
+ $trans->abortWithError(tr("Order ID is not valid."));
+ return;
+ }
+ //calculate payment
+ $pay=$trans->getamount()+0;
+ if($pay<0){//negative: error out
+ $trans->abortWithError(tr("Amount to be paid must be positive."));
+ return;
+ }
+ $order=WOOrder::fromTableorder($ord);
+ $max=$order->prop_amountdue;
+ if($max<=0)$pay=0;else
+ if($max<$pay)$pay=$max;
+ if($pay==0){//zero: ignore it
+ $trans->setorder($order);
+ $trans->setamount(0);
+ return;
+ }
+ //make corrections
+ $ord->amountpaid+=$pay;
+ $ord->update();
+ //return (redo object conversion: calculated data has changed!)
+ $trans->setorder(WOOrder::fromTableorder($ord));
+ $trans->setamount($pay);
+ }
+
+ /**called from the UseVoucher transaction*/
+ public static function payForOrderVoucher($trans)
+ {
+ //get order
+ $ord=WTorder::getFromDB($trans->getorderid());
+ if($ord===false){
+ $trans->abortWithError(tr("Order ID is not valid."));
+ return;
+ }
+ //get and verify voucher
+ $vou=WTvoucher::getFromDB($trans->getvoucherid());
+ if($vou===false){
+ $trans->abortWithError(tr("Voucher is not valid!"));
+ return;
+ }
+ $vord=WOOrder::fromTableorder(WTorder::getFromDB($vou->orderid));
+ if($vord===false){
+ $trans->abortWithError(tr("Voucher is not valid!"));
+ return;
+ }
+ if($vord->get_amountdue()>0){
+ $trans->abortWithError(tr("Voucher cannot be used: it has not been paid for."));
+ return;
+ }
+ //calculate payment
+ $pay=$vou->value+0;
+ if($pay<0){//negative: error out
+ $trans->abortWithError(tr("Amount to be paid must be positive."));
+ return;
+ }
+ $order=WOOrder::fromTableorder($ord);
+ $max=$order->prop_amountdue;
+ if($max<=0)$pay=0;else
+ if($max<$pay)$pay=$max;
+ if($pay==0){//zero: ignore it
+ $trans->setorder($order);
+ $trans->setamount(0);
+ return;
+ }
+ //make corrections
+ $ord->amountpaid+=$pay;
+ $ord->update();
+ $vou->value-=$pay;
+ $vou->isused=true;
+ $vou->update();
+ //return (redo object conversion: calculated data has changed!)
+ $trans->setorder(WOOrder::fromTableorder($ord));
+ $trans->setvoucher(WOVoucher::fromTablevoucher($vou));
+ $trans->setamount($pay);
+ }
+
+ /**called from the OrderRefund transaction*/
+ public static function refundOrder($trans)
+ {
+ //get order
+ $ord=WTorder::getFromDB($trans->getorderid());
+ if($ord===false){
+ $trans->abortWithError(tr("Order ID is not valid."));
+ return;
+ }
+ //calculate payment
+ $pay=$trans->getamount()+0;
+ if($pay<0){//negative: error out
+ $trans->abortWithError(tr("Amount to be refunded must be positive."));
+ return;
+ }
+ $order=WOOrder::fromTableorder($ord);
+ $max=0-$order->prop_amountdue; //refund is negative due
+ if($max<=0)$pay=0;else
+ if($max<$pay)$pay=$max;
+ if($pay==0){//zero: ignore it
+ $trans->setorder($order);
+ $trans->setamount(0);
+ return;
+ }
+ //make corrections
+ $ord->amountpaid-=$pay;
+ $ord->update();
+ //return (redo object conversion: calculated data has changed!)
+ $trans->setorder(WOOrder::fromTableorder($ord));
+ $trans->setamount($pay);
+ }
};
?>
\ No newline at end of file