Exemple #1
0
        /// <summary>
        /// Cancel the order.
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="item"></param>
        public void CancelOrder(User actor, Order item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));

                    Order order = _uow.OrderRepository.GetById(item.Id);
                    // update order
                    order.IsCancelled  = true;
                    order.CancelReason = item.CancelReason;
                    _uow.OrderRepository.Update(order);

                    // set table state to free, and reset order id matched with table
                    Table table = _uow.TableRepository.GetById(order.TableId);
                    table.State = TableState.Free;
                    //table.State = 0;
                    table.CurrentOrderId = 0;
                    _uow.TableRepository.Update(table);

                    // get order report, useful for writing report
                    ReportOrder report = _uow.ReportOrderRepository.GetByOrderCode(item.Code);
                    report.TableCode        = item.Table.Code;
                    report.TableName        = item.Table.Name;
                    report.State            = order.State;
                    report.OrderDatetime    = order.OrderDatetime;
                    report.EditDatetime     = order.EditDatetime;
                    report.BillDatetime     = order.BillDatetime;
                    report.CheckoutDatetime = order.CheckoutDatetime;
                    report.SubTotalPrice    = order.SubTotalPrice;
                    report.TotalPrice       = order.TotalPrice;
                    report.ServiceCharge    = order.ServiceCharge;
                    report.VatEnable        = order.VatEnable;
                    report.VatPrice         = order.VatPrice;
                    report.DiscountPercent  = order.DiscountPercent;
                    report.DiscountPrice    = order.DiscountPrice;
                    report.SpecialDiscount  = order.SpecialDiscount;
                    report.Cash             = order.Cash;
                    report.Change           = order.Change;
                    report.PrintCount       = order.PrintCount;
                    report.IsCancelled      = order.IsCancelled;
                    report.CancelReason     = order.CancelReason;
                    _uow.ReportOrderRepository.Update(report);

                    // report order item
                    foreach (OrderItem orderItem in item.OrderItems)
                    {
                        ReportOrderItem reportOrderItem = new ReportOrderItem();
                        reportOrderItem.ReportCounter             = report.ReportCounter;
                        reportOrderItem.Sequence                  = orderItem.Sequence;
                        reportOrderItem.ProductCode               = orderItem.ProductInfo.Code;
                        reportOrderItem.ProductName               = orderItem.ProductInfo.Name;
                        reportOrderItem.ProductGroup              = _uow.ProductGroupRepository.GetById(orderItem.ProductInfo.GroupId).Name;
                        reportOrderItem.UnitName                  = _uow.UnitRepository.GetById(orderItem.ProductInfo.UnitId).Name;
                        reportOrderItem.UnitPrice                 = orderItem.ProductInfo.Price;
                        reportOrderItem.Quantity                  = orderItem.Quantity;
                        reportOrderItem.State                     = orderItem.State;
                        reportOrderItem.CreateDatetime            = orderItem.CreateDatetime;
                        reportOrderItem.StartDatetime             = orderItem.StartDatetime;
                        reportOrderItem.StopDatetime              = orderItem.StopDatetime;
                        reportOrderItem.ServeDatetime             = orderItem.ServeDatetime;
                        reportOrderItem.IsCancelled               = orderItem.IsCancelled;
                        reportOrderItem.IsKitchenProcessCompleted = orderItem.IsKitchenProcessCompleted;

                        _uow.ReportOrderItemRepository.Add(reportOrderItem);
                    }


                    // add event report
                    ReportEvent reportEvent1 = new ReportEvent();
                    reportEvent1.ReportCounter = report.ReportCounter;
                    reportEvent1.EventClass    = 0;
                    reportEvent1.EventDate     = _uow.GetDbCurrentDatetime();
                    reportEvent1.Text          = actor.Fullname + " cancelled order " + item.Code + " for table \"" + item.Table.Name + "\"";

                    reportEvent1 = _uow.ReportEventRepository.Add(reportEvent1);

                    // delete real time order
                    _uow.OrderRepository.Remove(order);

                    // commit
                    _uow.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }
Exemple #2
0
        public void CheckOutOrder(User actor, Order item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));

                    Order order = _uow.OrderRepository.GetById(item.Id);
                    // update order
                    order.State            = OrderState.Finished;
                    order.CheckoutDatetime = _uow.GetDbCurrentDatetime();
                    _uow.OrderRepository.Update(order);

                    // set table state to free, and reset order id matched with table
                    Table table = _uow.TableRepository.GetById(order.TableId);
                    table.State = TableState.Free;
                    //table.State = 0;
                    table.CurrentOrderId = 0;
                    _uow.TableRepository.Update(table);

                    // get order report, useful for writing report
                    ReportOrder report = _uow.ReportOrderRepository.GetByOrderCode(item.Code);
                    report.TableCode        = item.Table.Code;
                    report.TableName        = item.Table.Name;
                    report.State            = order.State;
                    report.OrderDatetime    = order.OrderDatetime;
                    report.EditDatetime     = order.EditDatetime;
                    report.BillDatetime     = order.BillDatetime;
                    report.CheckoutDatetime = order.CheckoutDatetime;
                    report.SubTotalPrice    = order.SubTotalPrice;
                    report.TotalPrice       = order.TotalPrice;
                    report.ServiceCharge    = order.ServiceCharge;
                    report.VatEnable        = order.VatEnable;
                    report.VatPrice         = order.VatPrice;
                    report.DiscountPercent  = order.DiscountPercent;
                    report.DiscountPrice    = order.DiscountPrice;
                    report.SpecialDiscount  = order.SpecialDiscount;
                    report.Cash             = order.Cash;
                    report.Change           = order.Change;
                    report.PrintCount       = order.PrintCount;
                    report.IsCancelled      = order.IsCancelled;
                    report.CancelReason     = order.CancelReason;
                    _uow.ReportOrderRepository.Update(report);

                    // report order item
                    foreach (OrderItem orderItem in item.OrderItems)
                    {
                        ReportOrderItem reportOrderItem = new ReportOrderItem();
                        reportOrderItem.ReportCounter             = report.ReportCounter;
                        reportOrderItem.Sequence                  = orderItem.Sequence;
                        reportOrderItem.ProductCode               = orderItem.ProductInfo.Code;
                        reportOrderItem.ProductName               = orderItem.ProductInfo.Name;
                        reportOrderItem.ProductGroup              = _uow.ProductGroupRepository.GetById(orderItem.ProductInfo.GroupId).Name;
                        reportOrderItem.UnitName                  = _uow.UnitRepository.GetById(orderItem.ProductInfo.UnitId).Name;
                        reportOrderItem.UnitPrice                 = orderItem.ProductInfo.Price;
                        reportOrderItem.Quantity                  = orderItem.Quantity;
                        reportOrderItem.State                     = orderItem.State;
                        reportOrderItem.CreateDatetime            = orderItem.CreateDatetime;
                        reportOrderItem.StartDatetime             = orderItem.StartDatetime;
                        reportOrderItem.StopDatetime              = orderItem.StopDatetime;
                        reportOrderItem.ServeDatetime             = orderItem.ServeDatetime;
                        reportOrderItem.IsCancelled               = orderItem.IsCancelled;
                        reportOrderItem.IsKitchenProcessCompleted = orderItem.IsKitchenProcessCompleted;

                        _uow.ReportOrderItemRepository.Add(reportOrderItem);
                    }

                    // report material
                    List <Material> usedMaterials = new List <Material>();
                    foreach (OrderItem orderItem in item.OrderItems.Where(o => o.IsCancelled != true))
                    {
                        List <RecipeItem> recipeItems = _uow.RecipeItemRepository.GetBy(o => o.ProductId == orderItem.ProductInfo.Id).ToList();
                        foreach (RecipeItem recipeItem in recipeItems)
                        {
                            Material searchMaterial = usedMaterials.Where(o => o.Id == recipeItem.MaterialId).FirstOrDefault();
                            if (searchMaterial == null)
                            {
                                searchMaterial = _uow.MaterialRepository.GetById(recipeItem.MaterialId);
                                usedMaterials.Add(searchMaterial);
                            }
                            //Material searchMaterial = _uow.MaterialRepository.GetById(recipeItem.MaterialId);
                            ReportMaterial reportMaterial = new ReportMaterial();
                            reportMaterial.ReportCounter     = report.ReportCounter;
                            reportMaterial.OrderItemSequence = orderItem.Sequence;
                            reportMaterial.MaterialCode      = searchMaterial.Code;
                            reportMaterial.MaterialName      = searchMaterial.Name;
                            reportMaterial.UnitName          = "Test";
                            reportMaterial.Amount            = orderItem.Quantity * recipeItem.UsedAmount;
                            _uow.ReportMaterialRepository.Add(reportMaterial);

                            // update material amount in storage
                            searchMaterial.UsageAmount += reportMaterial.Amount;
                            //_uow.MaterialRepository.Update(searchMaterial);
                        }
                    }

                    // update material amount in storage
                    foreach (Material material in usedMaterials)
                    {
                        _uow.MaterialRepository.Update(material);
                    }


                    // add event report
                    ReportEvent reportEvent1 = new ReportEvent();
                    reportEvent1.ReportCounter = report.ReportCounter;
                    reportEvent1.EventClass    = 0;
                    reportEvent1.EventDate     = _uow.GetDbCurrentDatetime();
                    reportEvent1.Text          = actor.Fullname + " checked out order " + item.Code + " for table \"" + item.Table.Name + "\"";

                    reportEvent1 = _uow.ReportEventRepository.Add(reportEvent1);

                    // delete real time order
                    _uow.OrderRepository.Remove(order);

                    // commit
                    _uow.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
        }