コード例 #1
0
        public List <long> CreateGoodsIssues(IList <GoodsIssueDTO> pLstObjPickList)
        {
            List <GoodsIssue> lLstObjResultList = new List <GoodsIssue>();

            foreach (var lObjListToPick in pLstObjPickList)
            {
                //Valid availability
                if (lObjListToPick.QuantityToPick > 0 && lObjListToPick.AvailableQuantity >= lObjListToPick.QuantityToPick)
                {
                    //Get item batches
                    foreach (var lObjBatch in lObjListToPick.Batches.Where(x => x.AvailableQuantity > 0 && x.Gender == lObjListToPick.Gender))
                    {
                        if (lObjListToPick.QuantityToPick > 0 && lObjListToPick.AvailableQuantity >= lObjListToPick.QuantityToPick)
                        {
                            //Get quantity to apply
                            int lIntQuantityToApply = lObjListToPick.QuantityToPick > lObjBatch.AvailableQuantity ? lObjBatch.AvailableQuantity : lObjListToPick.QuantityToPick;

                            //Create Goods Issue
                            GoodsIssue lObjGoodIssue = new GoodsIssue()
                            {
                                BatchId  = lObjBatch.BatchId,
                                Quantity = lIntQuantityToApply,
                                Exported = false
                            };

                            //Add Goods Issue
                            lLstObjResultList.Add(lObjGoodIssue);
                            //Batch
                            lObjListToPick.AvailableQuantity -= lIntQuantityToApply;
                            lObjListToPick.QuantityToPick    -= lIntQuantityToApply;

                            //Line
                            lObjBatch.AvailableQuantity -= lIntQuantityToApply;
                        }
                    }
                }
            }

            int lIntNumber = GetNextNumber();

            foreach (long lLonBuyer in GetBuyersListByGoodsIssuesList(lLstObjResultList))
            {
                foreach (long lLonBatch in GetBatchesListByGoodsIssuesListAndBuyer(lLstObjResultList, lLonBuyer))
                {
                    foreach (GoodsIssue lObjGoodIssue in lLstObjResultList.Where(x => x.BatchId == lLonBatch))
                    {
                        lObjGoodIssue.Number = lIntNumber;
                        lObjGoodIssue.Folio  = string.Concat(DateTime.Now.ToString("yyMMdd"), lIntNumber.ToString("0000"));
                    }
                }
            }

            mObjGoodsIssueDAO.AddEntitiesList(lLstObjResultList);
            LogService.WriteInfo("Good Issue Created");
            return(lLstObjResultList
                   .Select(x => x.Id)
                   .ToList());
        }