Esempio n. 1
0
        public int GetCurrentStockByProductAndBatchCode(long?productCode, string batchNo)
        {
            int currentStock = 0;
            int totalStock   = 0;

            if (string.IsNullOrEmpty(batchNo))
            {
                List <Purchase>        _directpurchases      = _purchaseRepository.GetDirectPurchases().ToList();
                int?[]                 _directpurchasesIDs   = _directpurchases.Select(x => x.Id).ToArray();
                int?[]                 _purchaseFromSupplier = _purchaseRepository.GetPurchases().Where(x => x.Status != 2).Select(x => x.Id).ToArray(); // temprary code(int)CommonEnum.PurchaseStatus.WaitingForApproval
                List <OpeningStock>    _openingStock         = _openingStockRepository.GetOpeningStockByProductCode().Where(x => x.ProductCode == productCode).ToList();
                List <Wastage>         _wastage         = _productRepository.GetWastage().Where(x => x.ItemCode == productCode).ToList();
                List <Stock>           _stock           = _purchaseRepository.GetStocks().Where(x => (x.ProductCode == productCode && x.PurchaseId != null && _directpurchasesIDs.Contains(x.PurchaseId)) || ((x.ProductCode == productCode && _purchaseFromSupplier.Contains(x.PurchaseOrderId)))).ToList();
                List <StockAdjustment> _stockAdjustment = _stockAdjustmentRepository.GetStockAdjustments().Where(x => x.ProductCode == productCode).ToList();
                currentStock = CommonFunctions.CalcCurrentStock(_stock == null ? 0 : _stock.Sum(x => x.Quantity), _openingStock == null ? 0 : _openingStock.Sum(x => x.Quantity), _wastage == null ? 0 : _wastage.Sum(x => x.Quantity), _stockAdjustment == null ? 0 : _stockAdjustment.Sum(x => x.Quantity));
            }
            else
            {
                List <OpeningStock>    _openingStock    = _openingStockRepository.GetOpeningStockByProductCode().Where(x => x.BatchNo == batchNo && x.ProductCode == productCode).ToList();
                List <Stock>           _stock           = _purchaseRepository.GetStocks().Where(x => x.BatchNo == batchNo && x.ProductCode == productCode).ToList();
                List <StockAdjustment> _stockAdjustment = _stockAdjustmentRepository.GetStockAdjustments().Where(x => x.BatchNo == batchNo && x.ProductCode == productCode).ToList();
                //Batch not included
                List <Wastage> _wastage = _productRepository.GetWastage().Where(x => x.ItemCode == productCode).ToList();
                currentStock = CommonFunctions.CalcCurrentStock(_stock == null ? 0 : _stock.Sum(x => x.Quantity), _openingStock == null ? 0 : _openingStock.Sum(x => x.Quantity), _wastage == null ? 0 : _stock.Sum(x => x.Quantity), _stockAdjustment == null ? 0 : _stockAdjustment.Sum(x => x.Quantity));
            }
            List <PurchaseReturn> stocksRetrun = _purchaseRepository.GetPurchaseReturns().Where(x => (x.ProductCode == productCode)).ToList();

            totalStock = currentStock - (stocksRetrun == null ? 0 : stocksRetrun.Sum(x => x.Quantity));
            return(totalStock);
        }
 public bool CheckStockByProductCode(long productCode)
 {
     try
     {
         List <Purchase>        _directpurchases      = _purchaseRepository.GetDirectPurchases().ToList();
         int?[]                 _directpurchasesIDs   = _directpurchases.Select(x => x.Id).ToArray();
         bool                   isStockExists         = false;
         int?[]                 _purchaseFromSupplier = _purchaseRepository.GetPurchases().Where(x => x.Status != 2).Select(x => x.Id).ToArray();/* Temprary code 2 in this line (int)CommonEnum.PurchaseStatus.WaitingForApproval*/
         List <OpeningStock>    _openingStock         = _openingStockRepository.GetOpeningStockByProductCode().Where(x => x.ProductCode == productCode).ToList();
         List <Wastage>         _wastage         = _productRepository.GetWastage().Where(x => x.ItemCode == productCode).ToList();
         List <Stock>           _stock           = _purchaseRepository.GetStocks().Where(x => (x.ProductCode == productCode && x.PurchaseId != null && _directpurchasesIDs.Contains(x.PurchaseId)) || ((x.ProductCode == productCode && _purchaseFromSupplier.Contains(x.PurchaseOrderId)))).ToList();
         List <StockAdjustment> _stockAdjustment = _stockAdjustmentRepository.GetStockAdjustments().Where(x => x.ProductCode == productCode).ToList();
         if (_openingStock.Count > 0 || _stock.Count > 0 || _wastage.Count > 0 || _stockAdjustment.Count > 0)
         {
             isStockExists = true;
         }
         return(isStockExists);
     }
     catch (Exception ex)
     {
         fault.Result       = false;
         fault.ErrorMessage = "Error in CheckStockByProductCode method";
         fault.ErrorDetails = ex.ToString();
         throw new FaultException <FaultData>(fault);
     }
 }
Esempio n. 3
0
        public bool CheckProductOpningStock(long productCode)
        {
            bool            exists           = false;
            List <Purchase> _directpurchases = _purchaseRepository.GetDirectPurchases().ToList();

            int?[] _directpurchasesIDs        = _directpurchases.Select(x => x.Id).ToArray();
            int?[] _purchaseFromSupplier      = _purchaseRepository.GetPurchases().Where(x => x.Status != 2).Select(x => x.Id).ToArray(); /*temprary code 2 in this line (int)CommonEnum.PurchaseStatus.WaitingForApproval*/
            List <OpeningStock> _openingStock = _openingStockRepository.GetOpeningStockByProductCode().Where(x => x.ProductCode == productCode).ToList();
            List <Stock>        _stock        = _purchaseRepository.GetStocks().Where(x => (x.ProductCode == productCode && x.PurchaseId != null && _directpurchasesIDs.Contains(x.PurchaseId)) || ((x.ProductCode == productCode && _purchaseFromSupplier.Contains(x.PurchaseOrderId)))).ToList();

            if (_openingStock.Count > 0 && _stock.Count > 0)
            {
                exists = true;
            }
            return(exists);
        }