Пример #1
0
        private void Save()
        {
            var model = new SupplyInventoryModel();

            model.SupplyTypeID     = supplyTypeID;
            model.SupplyClassID    = supplyClassID;
            model.PurchaseQuantity = LocalUtils.ConvertToDouble(txtPurchaseQty.Text);
            // get id
            if (id != 0)
            {
                model.Date = dtDate.Value;
                if (!ValidateFields())
                {
                    LocalUtils.ShowValidationFailedMessage(this);
                    return;
                }
                Factories.CreateSupplyInventory().Edit(id, model);
                LocalUtils.ShowSaveMessage(this);
            }
            else
            {
                model.Date = dtSearchDate.Value;
                Factories.CreateSupplyInventory().Add(model);
                id = model.ID;
                mainPage.SetPage(pageDetail);
                bunifuTransition1.HideSync(pnlSide, false, BunifuAnimatorNS.Animation.Transparent);
            }
        }
Пример #2
0
        /// <summary>
        /// Get Single record of Supply Inventory
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public SupplyInventoryModel GetBy(int id)
        {
            using (var uow = new UnitOfWork(new DataContext()))
            {
                var model = new SupplyInventoryModel();
                var obj   = uow.SupplyInventories.GetBy(id);

                if (obj.SupplyType.SupplyClass.Description == "Raw Milk")
                {
                    throw new ApplicationException("Values for this group (Raw Milk) will automatically generated by milk collection form and production form!");
                    //var totalRawMilk = uow.MilkCollections.GetAllByMonthV2(obj.ActualDate, supplyTypeID: obj.SupplyTypeID).Sum(x => x.Volume);
                    //model.PurchaseQuantity = totalRawMilk;
                }
                else
                {
                    model.PurchaseQuantity = obj.PurchaseQuantity;
                }



                model.Date                = obj.ActualDate;
                model.UnitPrice           = obj.SupplyType.UnitPrice;
                model.supplyTypeClassName = obj.SupplyType.SupplyClass.Description;
                model.SupplyTypeName      = obj.SupplyType.Description;
                model.SupplyClassID       = obj.SupplyType.SupplyClassID;
                model.SupplyTypeID        = obj.SupplyTypeID;
                model.WithdrawQuantity    = GetWithdrawV2(obj.SupplyTypeID, model.Date.Month, model.Date.Year);
                model.WithdrawTotaAmount  = model.UnitPrice * model.WithdrawQuantity;
                model.PurchaseTotalAmount = model.UnitPrice * model.PurchaseQuantity;
                return(model);
            }
        }
Пример #3
0
 public void Add(SupplyInventoryModel model)
 {
     using (var uow = new UnitOfWork(new DataContext()))
     {
         var supplyType = uow.SupplyTypes.GetIncludeSupplyClass(model.SupplyTypeID);
         if (supplyType.SupplyClass.Description == "Raw Milk")
         {
             throw new ApplicationException("Values for this group (Raw Milk) will automatically generated by milk collection form and production form!");
         }
         // use to avoid multiple record of supply type per month
         var supplyInv = uow.SupplyInventories.GetByMonth(model.Date, supplyTypeID: model.SupplyTypeID);
         if (supplyInv != null)
         {
             throw new ApplicationException("Record for selected Supply was already created!");
         }
         var obj = new SupplyInventory();
         obj.CreateDateTime   = DateTime.Now;
         obj.ActualDate       = model.Date;
         obj.PurchaseQuantity = model.PurchaseQuantity;
         obj.SupplyTypeID     = model.SupplyTypeID;
         obj.WithdrawQuantity = 0;
         uow.SupplyInventories.Add(obj);
         uow.Complete();
         model.ID = obj.SupplyInventoryID;
     }
 }
Пример #4
0
 public void Edit(int id, SupplyInventoryModel model)
 {
     using (var uow = new UnitOfWork(new DataContext()))
     {
         var obj = uow.SupplyInventories.Get(id);
         obj.ActualDate       = model.Date;
         obj.PurchaseQuantity = model.PurchaseQuantity;
         obj.SupplyTypeID     = model.SupplyTypeID;
         obj.WithdrawQuantity = 0;
         uow.SupplyInventories.Edit(obj);
         uow.Complete();
     }
 }