public OrderTicket(OrderMain pOrderMain, PriceType pPriceType) { //Reference to Parent OrderMain _orderMain = pOrderMain; _priceType = pPriceType; _dateStart = FrameworkUtils.CurrentDateTimeAtomic(); _orderDetails = new OrderDetail(this); }
/// <summary> /// <para> /// Method responsible for check all items from Current Order (from temp file). /// </para> /// For Parking Ticket purposes, it is not allowed to have 2 units of same article, /// therefore, after adding a new article in Current Order and finishing this order, /// all items from the same will be persisted in data base, merging temp order and database order. /// <para> /// It is necessary to check for duplicates, removing it from database order. /// </para> /// </summary> /// <remarks>Please see TK013134 for further details</remarks> /// <param name="session"></param> public void CheckForDuplicatedArticleInArticleBag(Session session) { _log.Debug("OrderMain.CheckForDuplicatedArticleInArticleBag(Session session)"); Session _sessionXpo = session; fin_documentordermain xOrderMain = (fin_documentordermain)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(fin_documentordermain), _persistentOid); //Get current Working Order from SessionApp OrderMain currentOrderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; OrderTicket currentOrderTicket = currentOrderMain.OrderTickets[currentOrderMain.CurrentTicketId]; OrderDetailLine[] orderDetailsLines = currentOrderTicket.OrderDetails.Lines.ToArray(); if (xOrderMain != null) { /* iterates over current Order ticket list */ foreach (OrderDetailLine line in orderDetailsLines) { string currentDesignation = line.Designation; /* iterates over main Order list */ foreach (var xOrderMainTicket in xOrderMain.OrderTicket) { xOrderMainTicket.OrderDetail.Load(); /* iterates over main Order ticket list */ foreach (var xOrderMainTicketOrderDetail in xOrderMainTicket.OrderDetail) { { fin_documentorderdetail aa = xOrderMainTicket.OrderDetail[0]; /* When order already has the parking ticket, remove and break */ if (xOrderMainTicketOrderDetail.Designation.Equals(currentDesignation)) { currentOrderTicket.OrderDetails.Lines.Remove(line); break; } } } } } } }
public fin_documentorderticket FinishOrder(Session pSession, bool pPrintTicket, bool pTicketDrecrease) { //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(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "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(); Guid orderTicketOid = Guid.Empty; //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 //if (pTicketDrecrease) //{ //var sql = string.Format(@"SELECT * FROM fin_documentorderticket WHERE TicketId = '{0}' AND OrderMain = '{1}';", currentOrderMain.CurrentTicketId, currentOrderMain.PersistentOid); //_log.Debug(string.Format("sql: [{0}]", sql)); string sql = string.Format(@"SELECT Oid FROM fin_documentorderticket WHERE OrderMain = '{0}' AND TicketId = '{1}';", currentOrderMain.PersistentOid, currentOrderMain.CurrentTicketId); //_log.Debug(string.Format("sql: [{0}]", sql)); orderTicketOid = FrameworkUtils.GetGuidFromQuery(sql); xOrderTicket = (fin_documentorderticket)GlobalFramework.SessionXpo.GetObjectByKey(typeof(fin_documentorderticket), orderTicketOid); //xOrderTicket = (fin_documentorderticket)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(fin_documentorderticket), currentOrderMain._persistentOid); if (xOrderTicket != null) { xOrderTicket.TicketId = currentOrderMain.CurrentTicketId; xOrderTicket.DateStart = currentOrderTicket.DateStart; xOrderTicket.PriceType = currentOrderTicket.PriceType; xOrderTicket.Discount = xTable.Discount; xOrderTicket.OrderMain = xOrderMain; xOrderTicket.PlaceTable = xTable; xOrderTicket.UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); if (!isInUOW) { xOrderTicket.Save(); } } //} else { 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; //Edit/cancel orders lindote 10/07/2020 //Get order ticket Oid from DB string sql3 = string.Format(@"SELECT Oid FROM fin_documentorderticket WHERE OrderMain = '{0}' AND TicketId = '{1}';", currentOrderMain.PersistentOid, currentOrderMain.CurrentTicketId); orderTicketOid = FrameworkUtils.GetGuidFromQuery(sql3); //Get order detail Oid from DB string sql4 = string.Format(@"SELECT Oid FROM fin_documentorderdetail WHERE OrderTicket = '{0}' AND Article = '{1}' AND Price = '{2}' AND TotalDiscount = '{3}' AND Vat = '{4}';", orderTicketOid, line.ArticleOid, line.Properties.PriceNet.ToString().Replace(",", "."), line.Properties.TotalDiscount.ToString().Replace(",", "."), line.Properties.Vat.ToString().Replace(",", ".")); Guid orderDetailOid = FrameworkUtils.GetGuidFromQuery(sql4); string pToken2 = ""; if (pTicketDrecrease) { pToken2 = "decreased"; } if (orderDetailOid == Guid.Empty) { 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, Token2 = pToken2, //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(); } } else { xOrderDetailLine = (fin_documentorderdetail)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(fin_documentorderdetail), orderDetailOid); if (xOrderDetailLine.Token2 != "decreased" && !pTicketDrecrease) { xOrderDetailLine.Ord = itemOrd; xOrderDetailLine.Code = xArticle.Code; xOrderDetailLine.Designation = line.Designation; xOrderDetailLine.Quantity += line.Properties.Quantity; xOrderDetailLine.UnitMeasure = xArticle.UnitMeasure.Acronym; xOrderDetailLine.Price = line.Properties.PriceNet; xOrderDetailLine.Discount = (xArticle.Discount > 0) ? xArticle.Discount : 0.0m; xOrderDetailLine.TotalGross = line.Properties.TotalGross; xOrderDetailLine.TotalDiscount = line.Properties.TotalDiscount; xOrderDetailLine.TotalTax = line.Properties.TotalTax; xOrderDetailLine.TotalFinal = line.Properties.TotalFinal; xOrderDetailLine.Token2 = pToken2; //Use PriceTax Normal|TakeAway xOrderDetailLine.Vat = priceTax; //XPGuidObjects xOrderDetailLine.Article = xArticle; xOrderDetailLine.OrderTicket = xOrderTicket; if (!isInUOW) { xOrderDetailLine.Save(); } } else if (xOrderDetailLine.Token2 == "decreased" && pTicketDrecrease) { xOrderDetailLine.Ord = itemOrd; xOrderDetailLine.Code = xArticle.Code; xOrderDetailLine.Designation = line.Designation; xOrderDetailLine.Quantity += line.Properties.Quantity; xOrderDetailLine.UnitMeasure = xArticle.UnitMeasure.Acronym; xOrderDetailLine.Price = line.Properties.PriceNet; xOrderDetailLine.Discount = (xArticle.Discount > 0) ? xArticle.Discount : 0.0m; xOrderDetailLine.TotalGross = line.Properties.TotalGross; xOrderDetailLine.TotalDiscount = line.Properties.TotalDiscount; xOrderDetailLine.TotalTax = line.Properties.TotalTax; xOrderDetailLine.TotalFinal = line.Properties.TotalFinal; xOrderDetailLine.Token2 = pToken2; //Use PriceTax Normal|TakeAway xOrderDetailLine.Vat = priceTax; //XPGuidObjects xOrderDetailLine.Article = xArticle; xOrderDetailLine.OrderTicket = xOrderTicket; if (!isInUOW) { xOrderDetailLine.Save(); } } else if (xOrderDetailLine.Token2 == "decreased" && !pTicketDrecrease) { xOrderDetailLine.Ord = itemOrd; xOrderDetailLine.Code = xArticle.Code; xOrderDetailLine.Designation = line.Designation; xOrderDetailLine.Quantity = xOrderDetailLine.Quantity; xOrderDetailLine.UnitMeasure = xArticle.UnitMeasure.Acronym; xOrderDetailLine.Price = line.Properties.PriceNet; xOrderDetailLine.Discount = (xArticle.Discount > 0) ? xArticle.Discount : 0.0m; xOrderDetailLine.TotalGross = line.Properties.TotalGross; xOrderDetailLine.TotalDiscount = line.Properties.TotalDiscount; xOrderDetailLine.TotalTax = line.Properties.TotalTax; xOrderDetailLine.TotalFinal = line.Properties.TotalFinal; xOrderDetailLine.Token2 = pToken2; //Use PriceTax Normal|TakeAway xOrderDetailLine.Vat = priceTax; //XPGuidObjects xOrderDetailLine.Article = xArticle; xOrderDetailLine.OrderTicket = xOrderTicket; if (!isInUOW) { xOrderDetailLine.Save(); } } } //} } ; //Clean Details and Open a New Blank Ticket in Session //Increment Terminal SessionApp CurrentTicketId //Only increase in new ticket, else stays the same if (!pTicketDrecrease) { _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)); }
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)); }