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();
            }
        }
Example #2
0
		public static async Task<bool> LogMessageAsync(this LoggingManager manager, String message)
		{
			if(manager == null)
			{
				throw new ArgumentNullException(nameof(manager));
			}

			if (manager.IsConnected)
			{
				ApplicationLogEntry entry = new ApplicationLogEntry();
				entry.ApplicationId = APPLICATION_ID;
				entry.DeviceId = DEVICE_ID;
				entry.Message = message;
				return await manager.LogApplicationEntry(entry);
			}
			return false;
		}
Example #3
0
            public List <ApplicationLogEntry> ReadNextBatch(int batchSize)
            {
                if (_disposed)
                {
                    throw new ObjectDisposedException("_enumerator");
                }

                ApplicationLogEntry        currentEntry = new ApplicationLogEntry();
                List <ApplicationLogEntry> entries      = new List <ApplicationLogEntry>();

                if (_enumerator == null)
                {
                    _enumerator = _lines.GetEnumerator();
                }

                while (entries.Count < batchSize && _enumerator.MoveNext())
                {
                    string line  = _enumerator.Current;
                    var    match = Regex.Match(line, ApplicationLogsReader.LogEntryRegexPattern, RegexOptions.IgnoreCase);
                    if (match.Success)
                    {
                        currentEntry.TimeStamp = DateTimeOffset.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                        currentEntry.PID       = int.Parse(match.Groups[2].Value);
                        currentEntry.Level     = match.Groups[3].Value;
                        currentEntry.AddMessageLine(match.Groups[4].Value);
                        entries.Add(currentEntry);
                        currentEntry = new ApplicationLogEntry();
                    }
                    else
                    {
                        currentEntry.AddMessageLine(line);
                    }
                }

                if (entries.Count > 0)
                {
                    this.LastTime = entries.Last().TimeStamp;
                }

                return(entries);
            }
Example #4
0
		public async Task<bool> LogApplicationEntry(ApplicationLogEntry entry)
		{
			if (entry == null)
			{
				throw new ArgumentNullException(nameof(entry));
			}

			var vs = new ValueSet();
			vs["MessageType"] = nameof(ApplicationLogEntry);
			vs["Message"] = JsonConvert.SerializeObject(entry);
			var result = await connection.SendMessageAsync(vs);
			if (result.Status == AppServiceResponseStatus.Success)
			{
				bool? v = result.Message["result"] as bool?;
				if (v.HasValue)
				{
					return v.Value;
				}
			}

			return false;
		}
Example #5
0
        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 static void AssertLogEntry(this ApplicationLogEntry entry, DateTimeOffset timeStamp, string level, string message)
 {
     Assert.Equal(timeStamp, entry.TimeStamp);
     Assert.Equal(level, entry.Level);
     Assert.Equal(message, entry.Message);
 }
 public static void AssertLogEntry(this ApplicationLogEntry entry, string timeStamp, string level, string message)
 {
     AssertLogEntry(entry, DateTimeOffset.Parse(timeStamp, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal), level, message);
 }
Example #9
0
 private static void AssertLogEntry(ApplicationLogEntry entry, string timeStamp, string level, string message)
 {
     Assert.Equal(DateTimeOffset.Parse(timeStamp, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal), entry.TimeStamp);
     Assert.Equal(level, entry.Level);
     Assert.Equal(message, entry.Message);
 }
        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);
        }
Example #11
0
        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();
            }
        }