Exemple #1
0
        public List <ChartDTO> TrendChartInfoForSupplier(int SupplierId, int CategoryId, int StationeryId)
        {
            List <PurchaseOrderDetail>   PurchaseOrderDetailsList = purchaseOrderDetailRepo.GetPurchaseOrderDetailsBySupplierId(SupplierId);
            IEnumerable <SupplierTender> SupplierTendersList      = supplierTenderRepo.FindBy(x => x.SupplierId == SupplierId);
            List <ChartDTO> chartDTOs = new List <ChartDTO>();

            foreach (PurchaseOrderDetail pod in PurchaseOrderDetailsList)
            {
                foreach (SupplierTender st in SupplierTendersList)
                {
                    if (pod.StationeryId == st.StationeryId && pod.PurchaseOrder.SupplierId == st.SupplierId && pod.Stationery.CategoryId == CategoryId && pod.StationeryId == StationeryId)
                    {
                        ChartDTO chartDTO = new ChartDTO()
                        {
                            PubchaseOrderDetailId     = pod.Id,
                            PurchaseOrderId           = pod.PurchaseOrderId,
                            SupplierChartStationeryId = pod.StationeryId,
                            SupplierChartCategoryId   = pod.Stationery.Category.Id,
                            QuantityOrdered           = pod.QuantityOrdered,
                            QuantityDelivered         = pod.QuantityDelivered == null ? 0 : (int)pod.QuantityDelivered,
                            ItemName      = pod.Stationery.Description,
                            ItemType      = pod.Stationery.Category.Type,
                            UnitOfMeasure = pod.Stationery.UnitOfMeasure,
                            OrderDateTime = pod.PurchaseOrder.OrderDateTime,
                            SupplierName  = pod.PurchaseOrder.Supplier.Name,
                            ItemUnitPrice = st.Price,
                            EmployeeId    = pod.PurchaseOrder.Employee.Id,
                            EmployeeName  = pod.PurchaseOrder.Employee.Name,
                            SupplierId    = pod.PurchaseOrder.SupplierId,
                            PurchaseOrderDetailForChart = pod,
                            EmployeeForChart            = pod.PurchaseOrder.Employee,
                            SupplierForChart            = pod.PurchaseOrder.Supplier,
                            StationeryForChart          = pod.Stationery,
                            PurchaseOrderForChart       = pod.PurchaseOrder,
                            SupplierTenderForChart      = st,
                            CategoryForChart            = pod.Stationery.Category,
                        };
                        chartDTOs.Add(chartDTO);
                    }
                }
            }
            return(chartDTOs);
        }
        public StockAndSupplierDTO RetrieveStockMovement(int stationeryId)
        {
            List <StockMovementDTO>        stockMovement        = new List <StockMovementDTO>();
            List <StockMovementBalanceDTO> stockMovementBalance = new List <StockMovementBalanceDTO>();
            List <SupplierStockRankDTO>    supplierStockRank    = new List <SupplierStockRankDTO>();
            Stationery            s  = stationeryRepo.FindById(stationeryId);
            Category              c  = categoryRepo.FindById(s.CategoryId);
            List <SupplierTender> st = (List <SupplierTender>)supplierTenderRepo.FindBy(x => x.StationeryId == stationeryId);
            List <Supplier>       sp = new List <Supplier>();

            foreach (SupplierTender rankedsupplier in st)
            {
                Supplier supplier = (Supplier)supplierRepo.FindById(rankedsupplier.SupplierId);
                sp.Add(supplier);
            }

            //add Suppliers To SupplierStockRankDTO
            int limit = 3;

            for (int i = 1; i <= limit; i++)
            {
                SupplierStockRankDTO supstockrank = new SupplierStockRankDTO();
                {
                    supstockrank.Rank = i;

                    SupplierTender rankingsupplier = (SupplierTender)supplierTenderRepo.FindOneBy(x => x.StationeryId == stationeryId && x.Rank == i);
                    supstockrank.SupplierCode  = rankingsupplier.Supplier.Code;
                    supstockrank.SupplierName  = rankingsupplier.Supplier.Name;
                    supstockrank.ContactPerson = rankingsupplier.Supplier.ContactName;
                    supstockrank.ContactNumber = rankingsupplier.Supplier.PhoneNo;
                    supstockrank.Price         = rankingsupplier.Price;
                }
                supplierStockRank.Add(supstockrank);
            }

            //retrieve all adjustment voucher Ids that are acknowledged
            List <int> avId = adjustmentVoucherRepo.getAdjustmentVoucherIdsWithAcknowledgedStatus();

            //retrieve all adjustment voucher details with adjustment voucher Ids that are acknowledged and stationeryId
            List <AdjustmentVoucherDetail> avDet = new List <AdjustmentVoucherDetail>();

            foreach (int adjvouch in avId)
            {
                List <AdjustmentVoucherDetail> adjvouchDetail = (List <AdjustmentVoucherDetail>)adjustmentVoucherDetailRepo.FindBy(x => x.AdjustmentVoucherId == adjvouch && x.StationeryId == stationeryId);
                foreach (AdjustmentVoucherDetail aVD in adjvouchDetail)
                {
                    avDet.Add(aVD);
                }
            }

            // set retrieved adjustmentvouchers into StockMovementDTO
            foreach (AdjustmentVoucherDetail adjV in avDet)
            {
                StockMovementDTO stockMovList = new StockMovementDTO();
                {
                    stockMovList.MovementDate         = adjV.DateTime;
                    stockMovList.DepartmentOrSupplier = "Adjustment Voucher - " + adjV.AdjustmentVoucherId;
                    stockMovList.Quantity             = adjV.Quantity;
                }
                stockMovement.Add(stockMovList);
            }

            //retrieve all purchase Order Ids that are closed
            List <int> poId = purchaseOrderRepo.getPurchaseOrderIdsWithClosedStatus();

            //retrieve all PO details with PO Ids that are closed and stationeryId
            List <PurchaseOrderDetail> purchaseOrderDet = new List <PurchaseOrderDetail>();

            foreach (int a in poId)
            {
                PurchaseOrderDetail purOrderDetail = (PurchaseOrderDetail)purchaseOrderDetailRepo.FindOneBy(x => x.PurchaseOrderId == a && x.StationeryId == stationeryId);
                purchaseOrderDet.Add(purOrderDetail);
            }

            // set retrieved PODetails into StockMovementDTO
            foreach (PurchaseOrderDetail poDetail in purchaseOrderDet)
            {
                if (poDetail != null)
                {
                    StockMovementDTO stockMovList = new StockMovementDTO();
                    {
                        stockMovList.MovementDate         = (DateTime)purchaseOrderRepo.FindById(poDetail.PurchaseOrderId).DeliveryDateTime;
                        stockMovList.DepartmentOrSupplier = "Supplier - " + supplierRepo.FindById(purchaseOrderRepo.FindById(poDetail.PurchaseOrderId).SupplierId).Name;
                        stockMovList.Quantity             = (int)poDetail.QuantityDelivered;
                    }
                    stockMovement.Add(stockMovList);
                }
            }

            //retrieve all requisitiondetails that are delivered and are of the input stationeryId
            List <RequisitionDetail> reqDet = (List <RequisitionDetail>)requisitionDetailRepo.FindBy(x => x.Status == "Collected" && x.StationeryId == stationeryId);

            // set retrieved PODetails into StockMovementDTO
            foreach (RequisitionDetail reqDetails in reqDet)
            {
                StockMovementDTO stockMovList = new StockMovementDTO();

                stockMovList.MovementDate = (DateTime)reqDetails.Disbursement.DeliveryDateTime;

                int rcdEmployeeId = (int)disbursementRepo.FindOneBy(x => x.Id == reqDetails.DisbursementId).ReceivedEmployeeId;

                stockMovList.DepartmentOrSupplier = employeeRepo.FindById(rcdEmployeeId).Department.DepartmentName;;

                stockMovList.Quantity = (int)reqDetails.QuantityDelivered * -1;

                stockMovement.Add(stockMovList);
            }

            // order the list by date & alphabetically
            stockMovement = stockMovement.OrderBy(x => x.MovementDate).ToList();
            int runningBal = 0;

            // set StockMovementDTO into StockMovementBalanceDTO
            foreach (StockMovementDTO stkMovDTO in stockMovement)
            {
                StockMovementBalanceDTO stockMovBalList = new StockMovementBalanceDTO();
                stockMovBalList.StockMovement = stkMovDTO;
                runningBal = runningBal + stkMovDTO.Quantity;
                stockMovBalList.Balance = runningBal;
                stockMovementBalance.Add(stockMovBalList);
            }

            stockMovement.Reverse();
            //stockMovementBalance.Reverse();

            // set StockMovementBalanceDTO into StockAndSupplierDTO
            StockAndSupplierDTO stockAndSuppliers = new StockAndSupplierDTO();

            stockAndSuppliers.StationeryId      = s.Id;
            stockAndSuppliers.ItemNumber        = s.Code;
            stockAndSuppliers.Category          = (String)categoryRepo.getCategoryType(s.CategoryId);
            stockAndSuppliers.Description       = s.Description;
            stockAndSuppliers.Location          = s.Bin;
            stockAndSuppliers.UnitOfMeasure     = s.UnitOfMeasure;
            stockAndSuppliers.SupplierStockRank = supplierStockRank;

            foreach (StockMovementBalanceDTO stockMovementBalanceDTO in stockMovementBalance)
            {
                stockMovementBalanceDTO.Balance += s.Quantity - stockMovementBalance.Last().Balance;
            }

            stockAndSuppliers.StockMovementBalance = stockMovementBalance;
            return(stockAndSuppliers);
        }