Example #1
0
        public ProductGroup GetById(int id)
        {
            ProductGroup item = null;

            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));
                    item = _uow.ProductGroupRepository.GetById(id);
                    if (item != null)
                    {
                        item.MarkOld();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
            return(item);
        }
Example #2
0
        public Order GetById(long id)
        {
            Order item = null;

            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));
                    item = _uow.OrderRepository.GetById(id);
                    if (item != null)
                    {
                        item.Table       = _uow.TableRepository.GetById(item.TableId);
                        item.CreatorUser = _uow.UserRepository.GetById(item.CreatorId);
                        item.LockKeeper  = _uow.UserRepository.GetById(item.LockKeeperId);

                        // get order items
                        List <OrderItem> itemList = _uow.OrderItemRepository.GetBy(o => o.OrderId == item.Id).ToList();
                        // get material info of each item
                        foreach (OrderItem detail in itemList)
                        {
                            detail.ProductInfo      = _uow.ProductRepository.GetById(detail.ProductId);
                            detail.ProductInfo.Unit = _uow.UnitRepository.GetById(detail.ProductInfo.UnitId);
                            detail.SetOldQuantity();
                            detail.EdittedQuantity = 0;
                            MarkOld(detail);
                            MarkAsChild(detail);
                            item.OrderItems.Add(detail);
                        }
                        item.MarkOld();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
            return(item);
        }
Example #3
0
        public List <ReportOrderItemEdition> GetEdititonReportOfOrder(Order order)
        {
            List <ReportOrderItemEdition> list = null;

            try
            {
                if (order == null)
                {
                    throw new ArgumentNullException("order");
                }

                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));
                    // get report of order
                    ReportOrder report = _uow.ReportOrderRepository.GetByOrderCode(order.Code);

                    // get edition report of order base on report counter
                    list = _uow.ReportOrderItemEditionRepository.GetBy(o => o.ReportCounter == report.ReportCounter).ToList();
                    if (list != null)
                    {
                        foreach (ReportOrderItemEdition item in list)
                        {
                            item.OrderEdition = _uow.ReportOrderEditionRepository
                                                .GetBy(o => o.ReportCounter == item.ReportCounter && o.EditionCounter == item.EditionCounter)
                                                .FirstOrDefault();;
                            item.MarkOld();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
            return(list);
        }
Example #4
0
        public User GetById(int id)
        {
            User item = null;

            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));
                    item = _uow.UserRepository.GetById(id);
                    if (item != null)
                    {
                        // get data of inside class
                        item.Role = _uow.UserRoleRepository.GetBy(o => o.Id == item.RoleId).FirstOrDefault();
                        item.MarkOld();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
            return(item);
        }
Example #5
0
        public override UserRole GetByKey(UserRole itemWithKeys)
        {
            UserRole item = null;

            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));
                    item = _uow.UserRoleRepository
                           .GetBy(o => o.Id == itemWithKeys.Id)
                           .FirstOrDefault();
                    if (item != null)
                    {
                        item.MarkOld();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
            return(item);
        }
Example #6
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);
            }
        }
Example #7
0
        public override bool Create(Order item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            bool result = false;

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

                    // add order
                    // get latest order code definition
                    XRMS.Data.EntityFramework.CodeDefinitionEntity code = (_uow.GetDbContext() as XRMS.Data.EntityFramework.XRMSEntities).CodeDefinitionEntities.Where(o => o.Type == "ORDER").FirstOrDefault();

                    // set order data
                    item.Code = code.Prefix + (code.LastIndex + 1).ToString().PadLeft(7, '0');
                    // temporarily set id of user is 1
                    //item.CreatorId = 1;
                    // set order time
                    item.OrderDatetime = _uow.GetDbCurrentDatetime();
                    Order resultItem = _uow.OrderRepository.Add(item);
                    resultItem.CreatorUser = _uow.UserRepository.GetById(item.CreatorId);

                    // add order report
                    ReportOrder report = new ReportOrder();
                    report.Code        = resultItem.Code;
                    report.CreatorName = resultItem.CreatorUser.Fullname;
                    report             = _uow.ReportOrderRepository.Add(report);

                    // add order edition history
                    ReportOrderEdition orderEdition = new ReportOrderEdition();
                    orderEdition.ReportCounter = report.ReportCounter;
                    orderEdition.EditionUser   = resultItem.CreatorUser.Fullname;
                    orderEdition.EditionDate   = resultItem.OrderDatetime;
                    orderEdition = _uow.ReportOrderEditionRepository.Add(orderEdition);

                    foreach (OrderItem orderItem in item.OrderItems)
                    {
                        // assign order id and sequence
                        orderItem.OrderId        = item.Id;
                        orderItem.CreateDatetime = _uow.GetDbCurrentDatetime();
                        _uow.OrderItemRepository.Add(orderItem);

                        // add order item edition history
                        ReportOrderItemEdition itemEdition = new ReportOrderItemEdition();
                        itemEdition.ReportCounter   = orderEdition.ReportCounter;
                        itemEdition.EditionCounter  = orderEdition.EditionCounter;
                        itemEdition.Sequence        = orderItem.Sequence;
                        itemEdition.ProductCode     = orderItem.ProductInfo.Code;
                        itemEdition.ProductName     = orderItem.ProductInfo.Name;
                        itemEdition.EditionType     = 0;
                        itemEdition.EdittedQuantity = orderItem.EdittedQuantity;

                        itemEdition = _uow.ReportOrderItemEditionRepository.Add(itemEdition);
                    }

                    // create order report and order item report
                    // ...

                    // update last index
                    code.LastIndex++;
                    (_uow.GetDbContext() as XRMS.Data.EntityFramework.XRMSEntities).Set <CodeDefinitionEntity>().AddOrUpdate(code);

                    // set table state to busy, and order id matched with table
                    Table table = _uow.TableRepository.GetById(item.TableId);
                    table.State = TableState.Busy;
                    //table.State = 1;
                    table.CurrentOrderId = item.Id;
                    _uow.TableRepository.Update(table);

                    // add event report
                    ReportEvent reportEvent = new ReportEvent();
                    reportEvent.ReportCounter = report.ReportCounter;
                    reportEvent.EventClass    = 0;
                    reportEvent.EventDate     = _uow.GetDbCurrentDatetime();
                    reportEvent.Text          = resultItem.CreatorUser.Fullname + " created order " + resultItem.Code + " for table \"" + table.Name + "\"";

                    reportEvent = _uow.ReportEventRepository.Add(reportEvent);

                    // commit
                    _uow.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
            }
            return(result);
        }
Example #8
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);
            }
        }
Example #9
0
        public override bool Update(Order item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            bool result = false;

            try
            {
                using (XRMSEntities context = new XRMSEntities())
                {
                    _uow = new UnitOfWork(context, new RepositoryProvider(RepositoryFactories.Instance()));
                    // get order report, useful for writing report
                    ReportOrder report = _uow.ReportOrderRepository.GetByOrderCode(item.Code);
                    item.Table = _uow.TableRepository.GetById(item.TableId);

                    Order order = _uow.OrderRepository.GetById(item.Id);


                    // change table
                    if (order.TableId != item.TableId)
                    {
                        // assign order to new table and free old table
                        // set table state to busy, and order id matched with table
                        Table oldTable = _uow.TableRepository.GetById(order.TableId);
                        oldTable.State = TableState.Free;
                        //oldTable.State = 0;
                        oldTable.CurrentOrderId = 0;
                        _uow.TableRepository.Update(oldTable);

                        Table newTable = item.Table;
                        newTable.State = TableState.Busy;
                        //newTable.State = 1;
                        newTable.CurrentOrderId = item.Id;
                        _uow.TableRepository.Update(newTable);

                        // add event report
                        ReportEvent reportEvent = new ReportEvent();
                        reportEvent.ReportCounter = report.ReportCounter;
                        reportEvent.EventClass    = 0;
                        reportEvent.EventDate     = _uow.GetDbCurrentDatetime();
                        //reportEvent.Text = "Test";
                        reportEvent.Text = item.LockKeeper.Fullname + " changed order " + item.Code + " from table \"" + oldTable.Name + "\"" + " to \"" + newTable.Name + "\"";
                        reportEvent      = _uow.ReportEventRepository.Add(reportEvent);
                    }

                    // update order
                    item.EditDatetime = _uow.GetDbCurrentDatetime();
                    _uow.OrderRepository.Update(item);

                    /*item.EditDatetime = _uow.GetDbCurrentDatetime();
                     * _uow.OrderRepository.Update(item);*/

                    // add order edition history
                    ReportOrderEdition orderEdition = new ReportOrderEdition();
                    orderEdition.ReportCounter = report.ReportCounter;
                    orderEdition.EditionUser   = item.CreatorUser.Fullname;
                    orderEdition.EditionDate   = _uow.GetDbCurrentDatetime();
                    orderEdition = _uow.ReportOrderEditionRepository.Add(orderEdition);

                    // process deleted list first
                    foreach (OrderItem orderItem in (List <OrderItem>)(item.OrderItems as IEditableCollection).GetDeletedList())
                    {
                        if (!orderItem.IsNew)
                        {
                            _uow.OrderItemRepository.Remove(orderItem);
                        }
                    }

                    foreach (OrderItem orderItem in item.OrderItems)
                    {
                        if (orderItem.IsDirty)
                        {
                            byte editionType = 0;
                            if (orderItem.IsNew == false)
                            {
                                try
                                {
                                    _uow.OrderItemRepository.Update(orderItem);
                                    if (orderItem.IsCancelled == true)
                                    {
                                        // cancel
                                        editionType = 3;
                                    }
                                    else
                                    {
                                        if (orderItem.EdittedQuantity > 0)
                                        {
                                            // increase
                                            editionType = 1;
                                        }
                                        else
                                        {
                                            // decrease
                                            editionType = 2;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception(ex.Message + "\nOrderItem: " + orderItem.OrderId.ToString() + " " + orderItem.Sequence.ToString());
                                }
                            }
                            else
                            {
                                // assign order id and sequence
                                orderItem.OrderId        = item.Id;
                                orderItem.CreateDatetime = _uow.GetDbCurrentDatetime();
                                _uow.OrderItemRepository.Add(orderItem);
                            }

                            // add order item edition history
                            ReportOrderItemEdition itemEdition = new ReportOrderItemEdition();
                            itemEdition.ReportCounter   = orderEdition.ReportCounter;
                            itemEdition.EditionCounter  = orderEdition.EditionCounter;
                            itemEdition.Sequence        = orderItem.Sequence;
                            itemEdition.ProductCode     = orderItem.ProductInfo.Code;
                            itemEdition.ProductName     = orderItem.ProductInfo.Name;
                            itemEdition.EditionType     = editionType;
                            itemEdition.EdittedQuantity = orderItem.EdittedQuantity;

                            itemEdition = _uow.ReportOrderItemEditionRepository.Add(itemEdition);
                        }
                    }

                    // error when insert event report 2 times, need one more commit
                    _uow.SaveChanges();

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

                    reportEvent1 = _uow.ReportEventRepository.Add(reportEvent1);

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