//ChangeTable - Change Order From Table to Table void _buttonKeyChangeTable_Clicked(object sender, EventArgs e) { PosTablesDialog dialog = new PosTablesDialog(this.SourceWindow, DialogFlags.DestroyWithParent, TableFilterMode.OnlyFreeTables); ResponseType response = (ResponseType)dialog.Run(); if (response == ResponseType.Ok || response == ResponseType.Cancel || response == ResponseType.DeleteEvent) { if (response == ResponseType.Ok) { OrderMain currentOrderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; POS_ConfigurationPlaceTable xOldTable = (POS_ConfigurationPlaceTable)FrameworkUtils.GetXPGuidObject(typeof(POS_ConfigurationPlaceTable), currentOrderMain.Table.Oid); POS_ConfigurationPlaceTable xNewTable = (POS_ConfigurationPlaceTable)FrameworkUtils.GetXPGuidObject(typeof(POS_ConfigurationPlaceTable), dialog.CurrentTableOid); //Require to Prevent A first chance exception of type 'DevExpress.Xpo.DB.Exceptions.LockingException' occurred in DevExpress.Xpo.v13.2.dll when it is Changed in Diferent Session ex UnitOfWork //TODO: Confirm working with Reload Commented //xOldTable.Reload(); //xNewTable.Reload(); if (xNewTable.TableStatus != TableStatus.Free) { Utils.ShowMessageTouch( GlobalApp.WindowPos, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, Resx.global_error, Resx.dialog_message_table_is_not_free ); } else { //Put Old table Status to Free xOldTable.TableStatus = TableStatus.Free; xOldTable.Save(); FrameworkUtils.Audit("TABLE_OPEN", string.Format(Resx.audit_message_table_open, xOldTable.Designation)); //Put New table Status to Open xNewTable.TableStatus = TableStatus.Open; xNewTable.Save(); FrameworkUtils.Audit("TABLE_CLOSE", string.Format(Resx.audit_message_table_close, xNewTable.Designation)); //Change DocumentOrderMain table, If OpenOrder Exists in That table Guid documentOrderMainOid = currentOrderMain.GetOpenTableFieldValueGuid(xOldTable.Oid, "Oid"); FIN_DocumentOrderMain xDocumentOrderMain = (FIN_DocumentOrderMain)FrameworkUtils.GetXPGuidObject(typeof(FIN_DocumentOrderMain), documentOrderMainOid); if (xDocumentOrderMain != null) { xDocumentOrderMain.PlaceTable = xNewTable; xDocumentOrderMain.UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); xDocumentOrderMain.Save(); } //Assign Session Data currentOrderMain.Table.Oid = xNewTable.Oid; currentOrderMain.Table.Name = xNewTable.Designation; currentOrderMain.Table.PriceType = (PriceType)xNewTable.Place.PriceType.EnumValue; currentOrderMain.OrderTickets[currentOrderMain.CurrentTicketId].PriceType = (PriceType)xNewTable.Place.PriceType.EnumValue; currentOrderMain.Table.PlaceId = xNewTable.Place.Oid; GlobalFramework.SessionApp.Write(); //Finally Update Status Bar, Table Name, Totals Etc UpdateOrderStatusBar(); } } dialog.Destroy(); } ; }
public FIN_DocumentOrderTicket FinishOrder(Session pSession, bool pPrintTicket) { //Local Vars DateTime currentDateTime = DateTime.Now; FIN_DocumentOrderMain xOrderMain; Session _sessionXpo = pSession; bool isInUOW = (_sessionXpo.GetType() == typeof(UnitOfWork)); //Result FIN_DocumentOrderTicket xOrderTicket = null; //Get current Working Order from SessionApp OrderMain currentOrderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; OrderTicket currentOrderTicket = currentOrderMain.OrderTickets[currentOrderMain.CurrentTicketId]; //Get Place Object to extract TaxSellType Normal|TakeWay POS_ConfigurationPlace configurationPlace = (POS_ConfigurationPlace)GlobalFramework.SessionXpo.GetObjectByKey(typeof(POS_ConfigurationPlace), currentOrderMain.Table.PlaceId); //Use VatDirectSelling if in Retail or in TakeWay mode TaxSellType taxSellType = (configurationPlace.MovementType.VatDirectSelling || SettingsApp.AppMode == AppOperationMode.Retail) ? TaxSellType.TakeAway : TaxSellType.Normal; //Open Table on First Finish OrderTicket POS_ConfigurationPlaceTable xTable = (POS_ConfigurationPlaceTable)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(POS_ConfigurationPlaceTable), _table.Oid); xTable.Reload(); if (xTable.TableStatus != TableStatus.Open) { xTable.TableStatus = TableStatus.Open; FrameworkUtils.Audit("TABLE_OPEN", string.Format(Resx.audit_message_table_open, xTable.Designation)); xTable.DateTableOpen = FrameworkUtils.CurrentDateTimeAtomic(); if (!isInUOW) { xTable.Save(); } } //Get Current _persistentOid and _from Database _persistentOid = GetOpenTableFieldValueGuid(_table.Oid, "Oid"); _orderStatus = (OrderStatus)GetOpenTableFieldValue(_table.Oid, "OrderStatus"); _UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); //Insert if (_persistentOid == Guid.Empty) { //OrderMain xOrderMain = new FIN_DocumentOrderMain(_sessionXpo) { //Always assign New date to Persistent Date DateStart = currentDateTime,//currentOrderMain.DateStart, OrderStatus = OrderStatus.Open, PlaceTable = xTable, UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic() }; if (!isInUOW) { xOrderMain.Save(); } //After Save, Get Oid _persistentOid = xOrderMain.Oid; //Change to Open Status _orderStatus = OrderStatus.Open; } //Update else { xOrderMain = (FIN_DocumentOrderMain)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(FIN_DocumentOrderMain), _persistentOid); if (xOrderMain.PlaceTable != xTable) { xOrderMain.PlaceTable = xTable; } //Force Changes in Record, else UpdatedAt dont Update xOrderMain.UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); //TODO: Check if User was Automatically Updated //if (xOrderMain.UpdatedBy != GlobalFramework.LoggedUser) xOrderMain.UpdatedBy = GlobalFramework.LoggedUser; if (!isInUOW) { xOrderMain.Save(); } } //Create OrderTicket xOrderTicket = new FIN_DocumentOrderTicket(_sessionXpo) { TicketId = currentOrderMain.CurrentTicketId, DateStart = currentOrderTicket.DateStart, PriceType = currentOrderTicket.PriceType, Discount = xTable.Discount, OrderMain = xOrderMain, PlaceTable = xTable }; if (!isInUOW) { xOrderTicket.Save(); } //Create OrderDetail FIN_DocumentOrderDetail xOrderDetailLine; FIN_Article xArticle; uint itemOrd = 0; decimal priceTax = 0; foreach (OrderDetailLine line in currentOrderTicket.OrderDetails.Lines) { //Use Order in print tickets etc itemOrd++; xArticle = (FIN_Article)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(FIN_Article), line.ArticleOid); //Get PriceTax from TaxSellType priceTax = (taxSellType == TaxSellType.Normal) ? xArticle.VatOnTable.Value : xArticle.VatDirectSelling.Value; xOrderDetailLine = new FIN_DocumentOrderDetail(_sessionXpo) { //Values Ord = itemOrd, Code = xArticle.Code, Designation = line.Designation, Quantity = line.Properties.Quantity, UnitMeasure = xArticle.UnitMeasure.Acronym, Price = line.Properties.PriceNet, Discount = (xArticle.Discount > 0) ? xArticle.Discount : 0.0m, TotalGross = line.Properties.TotalGross, TotalDiscount = line.Properties.TotalDiscount, TotalTax = line.Properties.TotalTax, TotalFinal = line.Properties.TotalFinal, //Use PriceTax Normal|TakeAway Vat = priceTax, //XPGuidObjects Article = xArticle, OrderTicket = xOrderTicket }; //Detect VatExemptionReason if (line.Properties.VatExemptionReason != Guid.Empty) { xOrderDetailLine.VatExemptionReason = line.Properties.VatExemptionReason; } if (!isInUOW) { xOrderDetailLine.Save(); } } ; //Clean Details and Open a New Blank Ticket in Session //Increment Terminal SessionApp CurrentTicketId _currentTicketId += 1; currentOrderMain.OrderTickets = new Dictionary <int, OrderTicket>(); currentOrderMain.OrderTickets.Add(currentOrderMain.CurrentTicketId, new OrderTicket(this, _table.PriceType)); //Finish Writing Session GlobalFramework.SessionApp.Write(); return(xOrderTicket); //Debug //_log.Debug(string.Format("FinishOrder(): xOrderMain.Oid [{0}]", xOrderMain.Oid)); //_log.Debug(string.Format("FinishOrder(): _table.OrderMainId [{0}], _currentTicketId [{1}], _table.Name [{2}]", _table.OrderMainId, _currentTicketId, _table.Name)); }