public override void CommitChanges(bool logChanges = false, bool logNewDetailChanges = false, long?mainAvailabilityLocation = null, bool checkAvailability = false) { using (DbTransaction transaction = new DbTransaction(BusinessDomain.DataAccessProvider)) { // Create a new operation Id if needed); bool editMode = true; OperationState operationState = State; if (operationState == OperationState.New || operationState == OperationState.NewDraft || operationState == OperationState.NewPending) { id = CreateNewId(); // Set the new operation id editMode = false; } // Save the order in the database RestaurantOrderDetail reservationDetail = new RestaurantOrderDetail { ReferenceDocumentId = referenceDocumentId, Note = Note }; BusinessDomain.DataAccessProvider.AddUpdateReservation(this, reservationDetail); RestaurantOrder order = GetRestaurantOrder(); if (order.Details.Count > 0) { order.Id = id; order.CommitChanges(logChanges, logNewDetailChanges, mainAvailabilityLocation, checkAvailability); } // We have to delete the payment records if there is nothing left if (editMode && Persons.IsZero()) { BusinessDomain.DataAccessProvider.DeleteOperationId(OperationType.Reservation, id); ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Void reservation No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } else if (!Persons.IsZero()) { // Don't update the amount paid if this is not a new sale if (editMode) { ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Edit reservation No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } } IsDirty = false; transaction.Complete(); } }
public override void Commit() { bool editMode = true; using (DbTransaction transaction = new DbTransaction(BusinessDomain.DataAccessProvider)) { transaction.SnapshotObject(this); // Create a new operation Id if needed); OperationState operationState = State; if (operationState == OperationState.New || operationState == OperationState.NewDraft || operationState == OperationState.NewPending) { id = CreateNewId(); editMode = false; } LotsEvaluate(Details); BusinessDomain.DataAccessProvider.AddUpdateWaste(this, details.ToArray(), BusinessDomain.AppConfiguration.AllowNegativeAvailability); if (editMode && Total.IsZero()) { BusinessDomain.DataAccessProvider.DeleteOperationId(Data.OperationType.Waste, id); ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Void waste No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } else if (editMode) { ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Edit waste No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } if (editMode) { RemoveAllEmptyDetails(); } transaction.Complete(); } }
public override void Commit() { bool editMode = true; using (DbTransaction transaction = new DbTransaction(BusinessDomain.DataAccessProvider)) { transaction.SnapshotObject(this); if (BusinessDomain.AppConfiguration.AutoProduction) { if (AutomaticProduction()) { RecalculatePrices(); } } // Create a new operation Id if needed); OperationState operationState = State; if (operationState == OperationState.New || operationState == OperationState.NewDraft || operationState == OperationState.NewPending) { id = CreateNewId(); editMode = false; if (BusinessDomain.AppConfiguration.ItemsManagementUseLots) { foreach (ComplexProductionDetail detail in DetailsProd) { if (detail.ProductionDate == null) { detail.ProductionDate = Date; } } } } LotsEvaluate(DetailsMat); // Save the output ComplexProduction in the database OperationType = OperationType.ComplexProductionMaterial; foreach (ComplexProductionDetail detail in DetailsMat) { detail.ReferenceDocumentId = id; detail.ResetSign(-1); } BusinessDomain.DataAccessProvider.AddUpdateComplexProductionMat(this, DetailsMat.ToArray(), BusinessDomain.AppConfiguration.AllowNegativeAvailability); // Save the input ComplexProduction in the database OperationType = OperationType.ComplexProductionProduct; foreach (ComplexProductionDetail detail in DetailsProd) { detail.ReferenceDocumentId = id; detail.ResetSign(1); } BusinessDomain.DataAccessProvider.AddUpdateComplexProductionProd(this, DetailsProd.ToArray(), BusinessDomain.AppConfiguration.AllowNegativeAvailability); Item.Cache.Clear(DetailsProd.Select(d => d.ItemId)); if (editMode && Total.IsZero()) { BusinessDomain.DataAccessProvider.DeleteOperationId(OperationType.ComplexProductionMaterial, id); ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Void production No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } else if (editMode) { ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Edit production No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } if (editMode) { RemoveAllEmptyDetails(); } transaction.Complete(); } }
public ComplexRecipe CommitChanges() { bool editMode = true; try { using (DbTransaction transaction = new DbTransaction(BusinessDomain.DataAccessProvider)) { // Create a new operation Id if needed if (State == OperationState.New || State == OperationState.NewDraft) { id = CreateNewId(); editMode = false; } // Save the output ComplexRecipe in the database OperationType = OperationType.ComplexRecipeMaterial; foreach (ComplexRecipeDetail detail in DetailsMat) { detail.Note = name; } BusinessDomain.DataAccessProvider.AddUpdateComplexRecipeMat(this, DetailsMat.ToArray()); // Save the input ComplexRecipe in the database OperationType = OperationType.ComplexRecipeProduct; foreach (ComplexRecipeDetail detail in DetailsProd) { detail.Note = name; } BusinessDomain.DataAccessProvider.AddUpdateComplexRecipeProd(this, DetailsProd.ToArray()); if (editMode && Total.IsZero()) { BusinessDomain.DataAccessProvider.DeleteOperationId(OperationType.ComplexRecipeMaterial, id); string format = Translator.GetString("Void recipe No.{0} from {1}"); ApplicationLogEntry.AddNew(string.Format(format, GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } else if (editMode) { string format = Translator.GetString("Edit recipe No.{0} from {1}"); ApplicationLogEntry.AddNew(string.Format(format, GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } if (editMode) { RemoveAllEmptyDetails(); } transaction.Complete(); } } catch { if (!editMode) { id = -1; } throw; } return(this); }
public void CommitChanges(bool increaseStoreAvailability = true, bool increaseStoreAvailabilityOnAnnull = true) { bool editMode = true; try { using (DbTransaction transaction = new DbTransaction(BusinessDomain.DataAccessProvider)) { transaction.SnapshotObject(this); if (BusinessDomain.AppConfiguration.AutoProduction) { AutomaticProduction(); } // Create a new operation Id if needed); OperationState operationState = State; if (operationState == OperationState.New || operationState == OperationState.NewDraft || operationState == OperationState.NewPending) { id = CreateNewId(); editMode = false; } LotsEvaluate(Details); // Save the output transfer in the database OperationType = OperationType.TransferOut; LocationId = SourceLocationId; bool annulling = editMode && Total.IsZero(); foreach (TransferDetail detail in details) { detail.Sign = annulling && !increaseStoreAvailabilityOnAnnull ? 0 : -1; detail.DetailId = detail.SourceDetailId; } BusinessDomain.DataAccessProvider.AddUpdateTransferOut(this, details.ToArray(), BusinessDomain.AppConfiguration.AllowNegativeAvailability); foreach (TransferDetail detail in details) { detail.SourceDetailId = detail.DetailId; } // Save the input transfer in the database OperationType = OperationType.TransferIn; LocationId = TargetLocationId; foreach (TransferDetail detail in details) { detail.Sign = 1; detail.DetailId = detail.TargetDetailId; } BusinessDomain.DataAccessProvider.AddUpdateTransferIn(this, details.ToArray(), BusinessDomain.AppConfiguration.AllowNegativeAvailability, increaseStoreAvailability); foreach (TransferDetail detail in details) { detail.TargetDetailId = detail.DetailId; } InvalidateItemsCache(); if (annulling) { BusinessDomain.DataAccessProvider.DeleteOperationId(OperationType.TransferIn, id); ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Void transfer No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } else if (editMode) { ApplicationLogEntry.AddNew(string.Format(Translator.GetString("Edit transfer No.{0} from {1}"), GetFormattedOperationNumber(id), BusinessDomain.GetFormattedDate(date))); } if (editMode) { RemoveAllEmptyDetails(); } transaction.Complete(); } } finally { LocationId = SourceLocationId; } }
public virtual void CommitChanges(bool logChanges = false, bool logNewDetailChanges = false, long?mainAvailabilityLocation = null, bool checkAvailability = false) { using (DbTransaction transaction = new DbTransaction(BusinessDomain.DataAccessProvider)) { transaction.SnapshotObject(this); IEnumerable <string> changes = logChanges ? GetChanges(logNewDetailChanges, false) : new List <string> (); Dictionary <long, double> orderedQuantities = new Dictionary <long, double> (details.Count); if (checkAvailability && mainAvailabilityLocation != null) { if (BusinessDomain.AppConfiguration.AutoProduction) { AutomaticProduction(mainAvailabilityLocation.Value, locationId); } else if (!BusinessDomain.AppConfiguration.AllowNegativeAvailability) { foreach (RestaurantOrderDetail orderDetail in details.Where(d => d.DetailId >= 0 || d.Quantity > 0)) { if (orderedQuantities.ContainsKey(orderDetail.ItemId)) { orderedQuantities [orderDetail.ItemId] += orderDetail.Quantity; } else { orderedQuantities.Add(orderDetail.ItemId, orderDetail.Quantity); } } foreach (KeyValuePair <long, double> orderedQuantity in orderedQuantities) { if (Item.GetAvailability(orderedQuantity.Key, mainAvailabilityLocation.Value, locationId) < orderedQuantity.Value) { throw new InsufficientItemAvailabilityException(details.Find(d => d.ItemId == orderedQuantity.Key).ItemName); } } } } if (State == OperationState.New) { if (BusinessDomain.AppConfiguration.PrintOrderCodeOnReceipts) { id = -10 - BusinessDomain.DataAccessProvider.CreateNewOperationId(operationType, mainAvailabilityLocation ?? Entities.Location.DefaultId, currentState: State); } else { id = 0; } } foreach (RestaurantOrderDetail detail in details) { detail.ReferenceDocumentId = referenceDocumentId; } // Save the order in the database BusinessDomain.DataAccessProvider.AddUpdateRestaurantOrder(this, isDirty ? details.ToArray() : details.Where(detail => detail.IsDirty).ToArray()); for (int i = details.Count - 1; i >= 0; i--) { if (details [i].Quantity.IsZero()) { details.RemoveAt(i); } } IsDirty = false; foreach (string change in changes) { ApplicationLogEntry.AddNew(change); } transaction.Complete(); } }