Beispiel #1
0
        public bool Post(DeliveryLogVM data)
        {
            bool res = false;
            DeliveryLogService service = new DeliveryLogService();

            service.AddInventory(data);

            return(res);
        }
Beispiel #2
0
        public void TestMethod1()
        {
            DeliveryLogService service  = new DeliveryLogService();
            DeliveryLogVM      delivery = new DeliveryLogVM();

            List <DeliveryLogDetailVM> detail = new List <DeliveryLogDetailVM>();

            detail.Add(new DeliveryLogDetailVM
            {
                ProductId = 2,
                Good      = 10,
                Bad       = 1
            });

            delivery.BatchNo            = "dsads";
            delivery.BranchId           = 2;
            delivery.ReceivedBy         = "Luigie Cute";
            delivery.Remarks            = "Edi WOw";
            delivery.DeliverylogDetails = detail;
            service.AddInventory(delivery);
        }
        public bool AddInventory(DeliveryLogVM obj)
        {
            bool        result   = false;
            DeliveryLog delivery = new DeliveryLog();
            List <DeliverylogDetail>      details       = new List <DeliverylogDetail>();
            List <RunningInventory>       runinvee      = new List <RunningInventory>();
            List <BranchInventorySummary> branchsummary = new List <BranchInventorySummary>();

            foreach (var a in obj.DeliverylogDetails)
            {
                if (!_InventoryhelperRepo.CheckIfIsExist(obj.BranchId, a.ProductId))
                {
                    details.Add(new DeliverylogDetail
                    {
                        Good       = a.Good,
                        Bad        = a.Bad,
                        DateExpiry = a.DateExpiry,
                        ProductId  = a.ProductId
                    });

                    branchsummary.Add(new BranchInventorySummary
                    {
                        BranchId        = obj.BranchId,
                        ProductId       = a.ProductId,
                        TotalInventory  = a.Good,
                        ProductReleased = 0,
                        TotalIn         = a.Good,
                        TotalOut        = 0
                    });

                    runinvee.Add(new RunningInventory
                    {
                        ProductId = a.ProductId,
                        Bottles   = a.Good
                    });
                }
                else
                {
                    var currentdata = _branchInventorySumRepo.GetExistingBranchInveSum(obj.BranchId, a.ProductId).FirstOrDefault();

                    currentdata.TotalInventory += a.Good;
                    currentdata.TotalIn        += a.Good;
                    productRemaining            = currentdata.ProductOnHand.Value;
                    newProductStock             = currentdata.ProductOnHand.Value + a.Good;

                    var updatebranch = this._branchInventorySumRepo.Update(currentdata);
                    //if(updatebranch.)

                    details.Add(new DeliverylogDetail
                    {
                        Good = a.Good,
                        Bad  = a.Bad,
                        //DateExpiry = a.DateExpiry,
                        ProductId = a.ProductId
                    });

                    runinvee.Add(new RunningInventory
                    {
                        ProductId = a.ProductId,
                        Bottles   = a.Good
                    });
                }
            }


            delivery.BranchId           = obj.BranchId;
            delivery.ReceivedBy         = obj.ReceivedBy;
            delivery.RunningInventories = runinvee;
            delivery.DeliverylogDetails = details;
            delivery.BatchNo            = obj.BatchNo;



            var data = this._deliverylogrepo.Add(delivery);

            if (data != null)
            {
                result = true;
            }
            return(result);
        }