m_state->setText(m_order.orderStatusString());*/
}
-void MOrderWindow::createOrder(Create mode)
-{/*TODO
- MOrder ord;
- //handle reservation changes specially
- if(m_order.orderStatus()==MOrder::Reserved){
- bool ok=false;
- ord=m_order;
- switch(mode){
- case CreateOrder:ok=ord.reservationToOrder();break;
- case CreateSale:ok=ord.reservationToSale();break;
- default:ok=false;
- }
- if(!ok)return;
- }else{
- //handle case of new order
- switch(mode){
- case CreateSale:ord=m_order.createSale();break;
- case CreateOrder:ord=m_order.createOrder();break;
- case CreateReservation:ord=m_order.createReservation();break;
- }
- if(!ord.isValid())return;
+void MOrderWindow::createOrder()
+{
+ //sanity check
+ if(m_order.status()!=MOOrder::Reserved)return;
+ //call server
+ MTReservationToOrder ro=req->queryReservationToOrder(m_order.orderid());
+ if(ro.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while changing order status: %1").arg(ro.errorString()));
+ return;
}
- //display final order
- MOrderWindow *ow=new MOrderWindow(parentWidget(),req,ord);
- ow->show();
- //undisplay self
- close();*/
+ m_order=ro.getorder();
+ updateData();
}
void MOrderWindow::shipOrder()
/**creates the order window*/
MOrderWindow(QWidget*,const MOOrder&);
- private:
- /**helper enum for create* methods*/
- enum Create{CreateOrder,CreateSale,CreateReservation};
-
private slots:
/**internal: updates the labels and the ticket table*/
void updateData();
/**mark as shipped*/
void shipOrder();
- /**create a new order*/
- void createOrder(Create mode=CreateOrder);
+ /**create a new order from a reservation*/
+ void createOrder();
private:
MOOrder m_order;
<Transaction name="CreateOrder"/>
<Transaction name="CreateReservation"/>
- <Transaction name="ReservationToOrder"/>
+ <Transaction name="ReservationToOrder">
+ <Input>
+ <Var name="orderid" type="int"/>
+ </Input>
+ <Call lang="php" method="WOOrder::reservation2Order($this);"/>
+ <Output>
+ <Var name="order" type="Order"/>
+ </Output>
+ </Transaction>
<Transaction name="CancelOrder"/>
<Transaction name="OrderPay">
<Input>
$trans->setorder(WOOrder::fromTableorder($ord));
$trans->setamount($pay);
}
+
+ /**called from the ReservationToOrder transaction*/
+ public static function reservation2Order($trans)
+ {
+ //get order
+ $ord=WTorder::getFromDB($trans->getorderid());
+ if($ord===false){
+ $trans->abortWithError(tr("Invalid Order ID."));
+ return;
+ }
+ //check state
+ if($ord->status != WTorder::Reserved){
+ $trans->abortWithError(tr("This order is not a reservation."));
+ return;
+ }
+ //change state
+ $ord->status = WTorder::Sold;
+ $ord->update();
+ //return
+ $trans->setorder(WOOrder::fromTableorder($ord));
+ }
};
?>
\ No newline at end of file