if(!orders.contains(oid))return;
if(varname=="CUSTOMERID")value=QString::number(orders[oid].orderid());else
- if(varname=="CUSTOMER")value=orders[oid].customer().name().value();else
+ if(varname=="CUSTOMER")value=orders[oid].customer_().name().value();else
if(varname=="FULLPRICE"){
value=orders[oid].totalprice().value();
av=MOdtRenderer::MoneyVar;
gl->addWidget(new QLabel(tr("Shipping Date:")),++rw,0);
gl->addWidget(m_sentdate=new QLabel(m_order.sentDateTimeStr()),rw,1);
gl->addWidget(new QLabel(tr("Customer:")),++rw,0);
- gl->addWidget(new QLabel(m_order.customer().address()),rw,1);
+ gl->addWidget(new QLabel(m_order.customer_().address()),rw,1);
gl->addWidget(new QLabel(tr("Delivery Address:")),++rw,0);
//FIXME:gl->addWidget(lab=new QLabel(m_order.deliveryAddress()),rw,1);
//lab->setWordWrap(true);
if(loopname=="TICKETS")iterations=printBuffer.tickets.size();
if(loopname=="ACCTICKETS")iterations=printBuffer.tickinfo.size();
if(loopname=="VOUCHERS")iterations=printBuffer.vouchers.size();
- if(loopname=="ADDRESSLINES")iterations=m_order.customer().address().split("\n").size();
+ if(loopname=="ADDRESSLINES")iterations=m_order.customer_().address().split("\n").size();
}
void MOrderWindow::getLoopVariable(QString loopname,int it,QString vn,MOdtRenderer::VarType& av,QVariant&value)
{
}else
if(vn=="ID")value=printBuffer.vouchers[it].voucherid().value();
}else if(loopname=="ADDRESSLINES"){
- QStringList lst=m_order.customer().address().split("\n");
+ QStringList lst=m_order.customer_().address().split("\n");
if(it<0 || it>=lst.size())return;
value=lst[it];
}else
int scid=0;
for(int i=0;i<all.size();i++){
opt->addItem(all[i].description());
- if(all[i].id().value()==cid)
+ if(all[i].shipid().value()==cid)
scid=i+1;
}
opt->setCurrentIndex(scid);
model->insertRows(0,all.size());
model->setHorizontalHeaderLabels(QStringList()<<tr("ID")<<tr("Description")<<tr("Price")<<tr("Web")<<tr("Any User"));
for(int i=0;i<all.size();i++){
- model->setData(model->index(i,0),all[i].id().value());
+ model->setData(model->index(i,0),all[i].shipid().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"));
+// 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();
}
return true;
}
-MCustomer MOrder::customer()const
+MCustomer MOrder::customer_()const
{
return MCustomer(customerid());
}
bool isValid()const;
/**returns a customer object (calls database!)*/
- MCustomer customer()const;
+ MCustomer customer_()const;
/**returns whether this order is a reservation*/
bool isReservation()const;
MTGetAllShipping sh=MTGetAllShipping::query();
QList<MOShipping>ship=sh.getshipping();
for(int i=0;i<ship.size();i++)
- cartship->addItem(ship[i].description(),(int)ship[i].id());
+ cartship->addItem(ship[i].description(),(int)ship[i].shipid());
}
void MCartTab::initCart()
vl->addSpacing(15);
vl->addWidget(p=new QPushButton(tr("Find by Ticket...")),0);
connect(p,SIGNAL(clicked()),this,SLOT(orderByTicket()));
- p->setEnabled(req->hasRole("orderbyticket"));
+ p->setEnabled(req->hasRight(req->RGetOrderByBarcode));
vl->addWidget(p=new QPushButton(tr("Find by Event...")),0);
connect(p,SIGNAL(clicked()),this,SLOT(orderByEvent()));
p->setEnabled(req->hasRight(req->RGetOrdersByEvents));
ordermodel->setData(ordermodel->index(cl,0),ord.orderid().value(),Qt::UserRole);
ordermodel->setData(ordermodel->index(cl,1),ord.totalPriceString());
ordermodel->setData(ordermodel->index(cl,2),ord.amountPaidString());
+ if(ord.amountpaid()<ord.totalprice())
+ ordermodel->setData(ordermodel->index(cl,2),QColor("#ff8080"),Qt::BackgroundRole);
+ if(ord.amountpaid()>ord.totalprice())
+ ordermodel->setData(ordermodel->index(cl,2),QColor("#80ff80"),Qt::BackgroundRole);
int cid=ord.customerid();
//TODO: make this more effective:
for(int j=0;j<cust.size();j++)
}
void MOrdersTab::orderByTicket()
-{/*TODO
+{
//get selected order
bool ok;
QString tid=QInputDialog::getText(this,tr("Enter Ticket"),tr("Please enter the ID of one of the tickets of the order you seek:"),QLineEdit::Normal,"",&ok);
if(!ok || tid=="")return;
//request it
- if(!req->request("orderbyticket",tid.toUtf8())){
- QMessageBox::warning(this,tr("Warning"),tr("Unable to query server."));
- return;
- }
- if(req->responseStatus()!=MSInterface::Ok){
- QMessageBox::warning(this,tr("Warning"),qApp->translate("php::",req->responseBody()));
+ MTGetOrderByBarcode obb=req->queryGetOrderByBarcode(tid);
+ if(obb.hasError()){
+ QMessageBox::warning(this,tr("Warning"),tr("Error while searching for order: %1").arg(obb.errorString()));
return;
}
- int id=req->responseBody().trimmed().toInt(&ok);
- if(!ok || id<0){
- QMessageBox::warning(this,tr("Warning"),tr("Server returned an invalid order ID."));
+ if(obb.getorder().isNull()){
+ QMessageBox::warning(this,tr("Warning"),tr("Order for barcode '%1' not found.").arg(tid));
return;
}
//open order window
- MOrderWindow *om=new MOrderWindow(this,req,MOrder(req,id));
+ MOrderWindow *om=new MOrderWindow(this,obb.getorder().value());
om->setAttribute(Qt::WA_DeleteOnClose);
- om->show();*/
+ om->show();
}
void MOrdersTab::orderByEvent()
</Table>
+ <Class name="Shipping">
+ <Doc>This class encapsulates shipping types.</Doc>
+ <Property name="shipid" type="int"/>
+ <Property name="cost" type="int"/>
+ <Property name="flags" type="string"/>
+ <Property name="description" type="string"/>
+ <Mapping table="shipping">
+ <Map column="shipid"/>
+ <Map column="cost"/>
+ <Map column="flags"/>
+ <Map column="description"/>
+ </Mapping>
+ </Class>
+
<!-- both sides implement some additional logic, hence abstract -->
<Class name="Ticket" abstract="yes">
<Doc>This class represents the data of a ticket as stored in the database.</Doc>
<Doc>used for basic info about items</Doc>
<Property name="itemid" type="int"/>
<Property name="productid" type="int"/>
- <!-- etc. -->
+ <Property name="productname" type="string"/>
+ <Property name="orderid" type="int"/>
+ <Property name="amount" type="int"/>
+ <Property name="totalprice" type="int"/>
+
+ <Mapping table="item">
+ <Map column="itemid"/>
+ <Map column="productid"/>
+ <Map column="orderid"/>
+ <Map column="amount"/>
+ <Map column="totalprice"/>
+ <Map property="productname">
+ <Call lang="php" method="WTproduct::getFromDB($data->prop_productid)->name"/>
+ </Map>
+ </Mapping>
</Class>
<Class name="Order" abstract="yes">
<Enum name="OrderState" refColumn="order:status" />
<Property name="orderid" type="int"/>
- <Property name="customerid" type="int"/><!-- should be a full customer object -->
- <!--invoice/delivery addresses missing -->
+ <Property name="customerid" type="int"/>
+ <Property name="customer" type="CustomerInfo"/>
+ <Property name="invoiceaddressid" type="int64"/>
+ <Property name="invoiceaddress" type="Address"/>
+ <Property name="deliveryaddressid" type="int64"/>
+ <Property name="deliveryaddress" type="Address"/>
<Property name="soldby" type="astring"/>
+
<Property name="tickets" type="List:Ticket"/>
<Property name="vouchers" type="List:Voucher"/>
- <!-- products/items missing -->
+ <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="shippingtypeid" type="int"/>
+ <Property name="shippingtype" type="Shipping"/>
- <Property name="totalprice" type="int"/>
<Property name="ordertime" type="int64"/>
<Property name="senttime" type="int64"/>
+
+ <Property name="comments" type="string"/>
<!-- etc.pp. -->
+
+ <Mapping table="order">
+ <Map column="orderid"/>
+ <Map column="customerid"/>
+ <Map property="customer"><Call lang="php" method="WOCustomerInfo::fromTablecustomer(WTcustomer::getFromDB($data->prop_customerid))"/></Map>
+ <Map column="soldby"/>
+ <Map column="invoiceaddress" property="invoiceaddressid"/>
+ <Map column="deliveryaddress" property="deliveryaddressid"/>
+ <Map property="invoiceaddress"><Call lang="php" method="WOAddress::fromTableaddress(WTaddress::getFromDB($table->invoiceaddress))"/></Map>
+ <Map property="deliveryaddress"><Call lang="php" method="WOAddress::fromTableaddress(WTaddress::getFromDB($table->deliveryaddress))"/></Map>
+ <Map column="amountpaid"/>
+ <Map column="status"/>
+ <Map column="shippingcosts"/>
+ <Map column="shippingtype" property="shippingtypeid"/>
+ <Map property="shippingtype"><Call lang="php" method="WOShipping::fromTableshipping(WTshipping::getFromDB($table->shippingtype))"/></Map>
+ <Map column="ordertime"/>
+ <Map column="senttime"/>
+ <Map column="comments"/>
+
+ <Map property="tickets"><Call lang="php" method="WOTicket::fromTableArrayticket(WTticket::selectFromDB('orderid='.$GLOBALS['db']->escapeInt($table->orderid)))"/></Map>
+ <Map property="vouchers"><Call lang="php" method="WOVoucher::fromTableArrayvoucher(WTvoucher::selectFromDB('orderid='.$GLOBALS['db']->escapeInt($table->orderid)))"/></Map>
+ <Map property="items"><Call lang="php" method="WOItemInfo::fromTableArrayitem(WTitem::selectFromDB('orderid='.$GLOBALS['db']->escapeInt($table->orderid)))"/></Map>
+
+ <Map property="totalprice"><Call lang="php" method="$data->getTotalPrice()"/></Map>
+ <Map property="amountdue"><Call lang="php" method="$data->prop_totalprice - $data->prop_amountpaid"/></Map>
+ </Mapping>
</Class>
<Transaction name="GetOrder">
<Input>
<Var name="orderid" type="int"/>
</Input>
+ <Call lang="php" method="$this->setorder(WOOrder::fromTableorder(WTorder::getFromDB($this->getorderid())));"/>
<Output>
<Var name="order" type="Order"/>
</Output>
</Output>
</Transaction>
+ <Transaction name="GetOrderByBarcode">
+ <Input>
+ <Var name="barcode" type="string"/>
+ </Input>
+ <Call lang="php" method="WOOrder::getOrderByBarcode($this);"/>
+ <Output>
+ <Var name="order" type="Order"/>
+ </Output>
+ </Transaction>
+
<Transaction name="CreateOrder"/>
<Transaction name="CreateSale"/>
- <Class name="Shipping">
- <Property name="id" type="int32" id="yes"/>
- <Property name="cost" type="int32"/> <!--default cost of this shipping type-->
- <Property name="canuseweb" type="bool"/> <!--is offered on web interface-->
- <Property name="canallusers" type="bool"/> <!--all GUI users may select it-->
- <Property name="description" type="string"/>
- <Mapping table="shipping">
- <Map column="shipid" property="id"/>
- <Map column="cost"/>
- <Map column="canuseweb"/>
- <Map column="canallusers"/>
- <Map column="description"/>
- </Mapping>
- </Class>
-
<Transaction name="GetAllShipping">
<Input/>
<Output>
class WOOrder extends WOOrderAbstract
{
+ /**analyses itself and returns price*/
+ public function getTotalPrice()
+ {
+ //closed does not have a price
+ if($this->prop_status==self::Closed)
+ return 0;
+ $prc=$this->prop_shippingcosts;
+ //cancelled pais only shipping
+ if($this->prop_status==self::Cancelled)
+ return $prc;
+ //add tickets
+ foreach($this->prop_tickets as $it)
+ $prc+=$it->amountToPay();
+ //add vouchers
+ foreach($this->prop_vouchers as $it)
+ $prc+=$it->getprice();
+ //add items
+ foreach($this->prop_items as $it)
+ $prc+=$it->gettotalprice();
+ //return
+ return $prc;
+ }
+
+ /**called by GetOrderByBarcode transaction*/
+ static public function getOrderByBarcode($trans)
+ {
+ global $db;
+ //find ticket
+ $res=$db->select("ticket","orderid","ticketid=".$db->escapeString($trans->getbarcode()));
+ //if none: find voucher
+ if(count($res)<1)
+ $res=$db->select("voucher","orderid","voucherid=".$db->escapeString($trans->getbarcode()));
+ //find order
+ if(count($res)>=0)
+ $trans->setorder(WOOrder::fromTableorder(WTorder::getFromDB($res[0]["orderid"])));
+ }
};
?>
\ No newline at end of file