//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, resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_error"), resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "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(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "audit_message_table_open"), xOldTable.Designation)); //Put New table Status to Open xNewTable.TableStatus = TableStatus.Open; xNewTable.Save(); FrameworkUtils.Audit("TABLE_CLOSE", string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "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(); } ; }
/// <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)); }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //OrderMain/Document Conferences //Works in Dual Mode based on pGenerateNewIfDiferentFromArticleBag, sometimes passes 2 times, on for get last document and other to create new one //Mode1 : GenerateNewIfDiferentFromArticleBag = false : Returns Last Conference Document for Current Working Order Main //Mode2 : GenerateNewIfDiferentFromArticleBag = true : Returns Last or New Conference Document if Current Working Order Main is Diferent from working currente Working OrderMain ArticleBag //Returns Last|New DocumentConference, for table current OrderMain //GenerateNewIfDiferentFromArticleBag : Used to generate a new Document if latest Document has been changed (Compare it to current ArticleBag), //else if false use the latest on Database ignoring Diferences, Used to Get latest DocumentConference to use in Generate DocumentConference PosOrdersDialog.buttonTableConsult_Clicked public static fin_documentfinancemaster GetOrderMainLastDocumentConference(bool pGenerateNewIfDiferentFromArticleBag = false) { //Declare local Variables fin_documentfinancemaster lastDocument = null; fin_documentfinancemaster newDocument = null; fin_documentfinancemaster result = null; fin_documentordermain orderMain = null; Guid currentOrderMainOid = GlobalFramework.SessionApp.CurrentOrderMainOid; _log.Debug("fin_documentfinancemaster GetOrderMainLastDocumentConference(bool pGenerateNewIfDiferentFromArticleBag = false) :: currentOrderMainOid: " + currentOrderMainOid); OrderMain currentOrderMain = null; try { /* IN009179 - System.Collections.Generic.KeyNotFoundException */ if (GlobalFramework.SessionApp.OrdersMain.Count > 0) { currentOrderMain = GlobalFramework.SessionApp.OrdersMain[currentOrderMainOid]; } else { currentOrderMain = new OrderMain(); } string sql = string.Format(@" SELECT Oid FROM fin_documentfinancemaster WHERE DocumentType = '{0}' AND SourceOrderMain = '{1}' ORDER BY CreatedAt DESC; " , SettingsApp.XpoOidDocumentFinanceTypeConferenceDocument , currentOrderMain.PersistentOid ); var sqlResult = GlobalFramework.SessionXpo.ExecuteScalar(sql); //Get LastDocument Object if (sqlResult != null) { lastDocument = (fin_documentfinancemaster)GlobalFramework.SessionXpo.GetObjectByKey(typeof(fin_documentfinancemaster), new Guid(Convert.ToString(sqlResult))); } //If GenerateNewIfDiferentFromArticleBag Enabled compare ArticleBag with Document and If is diferent Generate a New One if (pGenerateNewIfDiferentFromArticleBag) { //Initialize ArticleBag to Compare with Order Detail and use in ProcessFinanceDocuments ArticleBag articleBag = ArticleBag.TicketOrderToArticleBag(currentOrderMain); //Check if Total is Not Equal and Generate New DocumentConference, This way it will be Equal to Invoice if ( lastDocument == null || (!lastDocument.TotalFinal.Equals(articleBag.TotalFinal) || !lastDocument.DocumentDetail.Count.Equals(articleBag.Count)) ) { //Prepare ProcessFinanceDocumentParameter ProcessFinanceDocumentParameter processFinanceDocumentParameter = new ProcessFinanceDocumentParameter(SettingsApp.XpoOidDocumentFinanceTypeConferenceDocument, articleBag) { Customer = SettingsApp.XpoOidDocumentFinanceMasterFinalConsumerEntity }; orderMain = (fin_documentordermain)GlobalFramework.SessionXpo.GetObjectByKey(typeof(fin_documentordermain), currentOrderMain.PersistentOid); processFinanceDocumentParameter.SourceOrderMain = orderMain; if (lastDocument != null) { processFinanceDocumentParameter.DocumentParent = lastDocument.Oid; processFinanceDocumentParameter.OrderReferences = new List <fin_documentfinancemaster>(); processFinanceDocumentParameter.OrderReferences.Add(lastDocument); } //Generate New Document newDocument = ProcessFinanceDocument.PersistFinanceDocument(processFinanceDocumentParameter, false); //Assign DocumentStatus and OrderReferences if (newDocument != null) { //Assign Result Document to New Document //Get Object outside UOW else we have a problem with "A first chance exception of type 'System.ObjectDisposedException'" result = (fin_documentfinancemaster)GlobalFramework.SessionXpo.GetObjectByKey(typeof(fin_documentfinancemaster), newDocument.Oid); ////Old Code that changes last Conference Document to Status "A", it is not Required, Confirmed with Carlos Bento, we must Leave it without status changes //if (lastDocument != null) //{ // lastDocument.DocumentStatusStatus = "A"; // lastDocument.DocumentStatusDate = newDocument.DocumentStatusDate; // lastDocument.DocumentStatusUser = newDocument.DocumentStatusUser; // lastDocument.SystemEntryDate = newDocument.SystemEntryDate; // lastDocument.Save(); //} } } } else { result = lastDocument; } } catch (Exception ex) { _log.Error("fin_documentfinancemaster GetOrderMainLastDocumentConference(bool pGenerateNewIfDiferentFromArticleBag = false) :: currentOrderMain: " + currentOrderMain); // Send Exception to logicpos, must treat exception in ui, to Show Alert to User throw ex; } return(result); }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //Used to Remove Articles from DocumentOrder ex when we Delete Article From TicketList.OrderMain Details public decimal DeleteFromDocumentOrder(ArticleBagKey pKey, decimal pRemoveQuantity) { bool isDone = false; decimal resultRemainQuantity = 0; string where = string.Empty; //Store Reference to Future delete Object (After foreach Loop) fin_documentordermain deleteOrderMain = null; fin_documentorderticket deleteOrderTicket = null; fin_documentorderdetail deleteOrderDetail = null; string articleDesignation = string.Empty; //Start UnitOfWork using (UnitOfWork uowSession = new UnitOfWork()) { OrderMain orderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; fin_documentordermain xDocumentOrderMain = (fin_documentordermain)FrameworkUtils.GetXPGuidObject(uowSession, typeof(fin_documentordermain), orderMain.PersistentOid); if (xDocumentOrderMain != null && xDocumentOrderMain.OrderTicket != null) { foreach (fin_documentorderticket ticket in xDocumentOrderMain.OrderTicket) { foreach (fin_documentorderdetail detail in ticket.OrderDetail) { try { //Check Equal Key if (pKey.ArticleOid == detail.Article.Oid && pKey.Price == detail.Price && pKey.Discount == detail.Discount && pKey.Vat == detail.Vat) { articleDesignation = pKey.Designation; resultRemainQuantity += detail.Quantity; if (!isDone) { detail.Quantity -= pRemoveQuantity; //Assign references to Future Deletes if (detail.Quantity <= 0) { deleteOrderDetail = detail; } isDone = true; } else { where += string.Format(" OR Oid = '{0}'", detail.Oid); } } } catch (Exception ex) { _log.Error(ex.Message, ex); } } } } //Debug //string sql = @"SELECT * FROM fin_documentorderdetail WHERE 1=0{0};"; //_log.Debug(string.Format("Delete(): sql [{0}]", string.Format(sql, where))); //Audit FrameworkUtils.Audit("ORDER_ARTICLE_REMOVED", string.Format( resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "audit_message_order_article_removed"), articleDesignation, 1, resultRemainQuantity - 1, GlobalFramework.LoggedUser.Name ) ); if (isDone) { //Update xDocumentOrderMain UpdatedAt, Required for RealTime Update xDocumentOrderMain.UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); //Remove Quantity resultRemainQuantity -= pRemoveQuantity; //Delete Records, OrderMain, OrderTicket and OrderDetails if (deleteOrderDetail != null) { deleteOrderTicket = deleteOrderDetail.OrderTicket; deleteOrderMain = deleteOrderTicket.OrderMain; //Delete Details deleteOrderDetail.Delete(); //Check if OrderTicket in Empty, If so Delete it, its not required anymore if (deleteOrderTicket.OrderDetail.Count <= 0) { deleteOrderTicket.Delete(); } ; //Check if OrderMain in Empty, If so Delete it, its not required anymore if (deleteOrderMain.OrderTicket.Count <= 0) { //Before Delete OrderMain, we must UnAssign DocumentMaster SourceOrderMain else we have a CONSTRAINT ERROR on FK_DocumentFinanceMaster_SourceOrderMain trying to delete used OrderMain string sql = string.Format(@"UPDATE fin_documentfinancemaster SET SourceOrderMain = NULL WHERE SourceOrderMain = '{0}';", deleteOrderMain.Oid); uowSession.ExecuteScalar(sql); //Open Table deleteOrderMain.PlaceTable.TableStatus = TableStatus.Free; //Audit FrameworkUtils.Audit("TABLE_OPEN", string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "audit_message_table_open"), deleteOrderMain.PlaceTable.Designation)); //Delete OrderMain deleteOrderMain.Delete(); } ; } ; } ; try { //Commit UOW Changes uowSession.CommitChanges(); //Update OrderMain UpdatedAt, Required to Sync Terminals orderMain.UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); //Update ArticleBag Price Properties this[pKey].Quantity = resultRemainQuantity; UpdateKeyProperties(pKey); //SEARCH#001 //Require to Remove PartialPayed Items Quantity return(resultRemainQuantity - FrameworkUtils.GetPartialPaymentPayedItems(uowSession, xDocumentOrderMain.Oid, pKey.ArticleOid)); } catch (Exception ex) { _log.Error(ex.Message, ex); uowSession.RollbackTransaction(); return(-1); } } }
//Delete void _buttonKeyDelete_Clicked(object sender, EventArgs e) { if (_listMode == TicketListMode.OrderMain) { ResponseType responseType = Utils.ShowMessageTouch(_sourceWindow, DialogFlags.Modal, new System.Drawing.Size(400, 280), MessageType.Question, ButtonsType.YesNo, string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_warning"), GlobalFramework.ServerVersion), resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "dialog_message__pos_order_cancel")); if (responseType == ResponseType.Yes) { try { _listStoreModel.Clear(); _listStoreModelSelectedIndex = -1; _listStoreModelTotalItems = 0; //Get Reference to current OrderMain OrderMain orderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; fin_documentordermain documentOrderMain = null; //Get current OrderMain Article Bag, After Process Payment/PartialPayment to check if current OrderMain has Items, or is Empty ArticleBag pParameters = ArticleBag.TicketOrderToArticleBag(orderMain); //Start UnitOfWork using (UnitOfWork uowSession = new UnitOfWork()) { if (pParameters.Count > 0) { // Warning required to check if (documentOrderMain != null), when we work with SplitPayments and work only one product, // the 2,3,4....orders are null, this is because first FinanceDocument Closes Order //Close OrderMain //if (documentOrderMain != null) documentOrderMain.OrderStatus = OrderStatus.Close; //Required to Update and Sync Terminals //if (documentOrderMain != null) documentOrderMain.UpdatedAt = documentDateTime; //Change Table Status to Free pos_configurationplacetable placeTable; placeTable = (pos_configurationplacetable)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(pos_configurationplacetable), orderMain.Table.Oid); documentOrderMain = (fin_documentordermain)uowSession.GetObjectByKey(typeof(fin_documentordermain), orderMain.PersistentOid); placeTable.TableStatus = TableStatus.Free; FrameworkUtils.Audit("TABLE_OPEN", string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "audit_message_table_open"), placeTable.Designation)); placeTable.DateTableClosed = DateTime.Now; placeTable.TotalOpen = 0; placeTable.Save(); //Required to Reload Objects after has been changed in Another Session(uowSession) if (documentOrderMain != null) { documentOrderMain = (fin_documentordermain)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(fin_documentordermain), orderMain.PersistentOid); documentOrderMain.OrderStatus = OrderStatus.Close; documentOrderMain.Save(); } if (documentOrderMain != null) { documentOrderMain.Reload(); } //aceTable = (pos_configurationplacetable)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(pos_configurationplacetable), orderMain.Table.Oid); //placeTable.Reload(); ArticleBag.TicketOrderToArticleBag(orderMain).Clear(); //Clean Session if Commited without problems orderMain.OrderStatus = OrderStatus.Close; orderMain.CleanSessionOrder(); GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid] = orderMain; GlobalFramework.SessionApp.DeleteEmptyTickets(); //obalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid].CleanSessionOrder(); uowSession.CommitChanges(); } } //PartialPayment Detected //else //{ // //Required to Update and Sync Terminals // if (documentOrderMain != null) documentOrderMain.UpdatedAt = documentDateTime; //} //Remove from SessionApp //_currentOrderDetails.Delete(_listStoreModelSelectedIndex); //Remove from TreviewModel //_listStoreModel.Remove(ref _treeIter); //Get Reference to current OrderMain CurrentOrderDetails = orderMain.OrderTickets[orderMain.CurrentTicketId].OrderDetails; //Always Change to OrderMain ListMode before Update Model _listMode = TicketListMode.Ticket; orderMain.CleanSessionOrder(); Gdk.Color colorListMode = (_listMode == TicketListMode.Ticket) ? colorListMode = Utils.ColorToGdkColor(_colorPosTicketListModeTicketBackground) : colorListMode = Utils.ColorToGdkColor(_colorPosTicketListModeOrderMainBackground); _treeView.ModifyBase(StateType.Normal, colorListMode); //UpdateModel(); UpdateOrderStatusBar(); UpdateTicketListOrderButtons(); //IMPORTANT & REQUIRED: Assign Current Order Details from New CurrentTicketId, ELSE we cant add items to OrderMain CurrentOrderDetails = orderMain.OrderTickets[orderMain.CurrentTicketId].OrderDetails; } catch (Exception ex) { _log.Error(ex.Message, ex); } } } else { DeleteItem_Event(TicketListDeleteMode.Delete); } }