Esempio n. 1
0
        public async Task <ActionResult <IList <DisbursementList> > > GetDisbursementDetailByDeptId([FromBody] List <DisbursementDetailViewModel> fdd)
        {
            Console.WriteLine(fdd.Count());
            var incoming     = fdd;
            var incomingDDiD = fdd.Select(x => x.id);
            var incomingDDDL = fdd.Select(x => x.DisbursementListId);

            var allCP = await _clerkService.findAllCollectionPointAsync();

            var allDL = await _clerkService.findAllDisbursementListAsync();

            var currDL   = allDL.Where(x => incomingDDDL.Contains(x.id));
            var currDLPt = currDL.Select(x => x.deliveryPoint);
            var currCP   = allCP.Where(x => currDLPt.Contains(x.collectionPoint));
            var allDD    = await _clerkService.findAllDisbursementDetailAsync();

            var currDD = allDD.Where(x => incomingDDiD.Contains(x.id));
            var allRD  = await _clerkService.findAllRequsitionDetailsAsync();

            StockAdjustment SA = new StockAdjustment();

            SA.date       = DateTime.Now;
            SA.EmployeeId = currCP.FirstOrDefault().clerkId;
            SA.type       = "lost during delivery to";
            _clerkService.saveStockAdjustment(SA);


            foreach (DisbursementDetail dd in currDD)
            {
                foreach (DisbursementDetailViewModel fkdd in fdd)
                {
                    if (fkdd.id == dd.id)
                    {
                        if (fkdd.qty != dd.qty)
                        {
                            RequisitionDetail rd = allRD.Where(x => x.Id == fkdd.RequisitionDetailId).FirstOrDefault();
                            rd.rcvQty -= (dd.qty - fkdd.qty);
                            _clerkService.udpateRequisitionDetail(rd);

                            StockAdjustmentDetail SAD = new StockAdjustmentDetail();
                            SAD.stockAdjustmentId = SA.Id;
                            SAD.StationeryId      = rd.StationeryId;
                            SAD.discpQty          = (dd.qty - fkdd.qty);
                            SAD.comment           = "lost during delivery";
                            SAD.Status            = "Approved";
                            _clerkService.saveStockAdjustmentDetail(SAD);

                            dd.qty = fkdd.qty;
                            _clerkService.updateDisbursementDetail(dd);
                        }
                        else
                        {
                            RequisitionDetail rd = allRD.Where(x => x.Id == fkdd.RequisitionDetailId).FirstOrDefault();
                            if (rd.rcvQty == rd.reqQty)
                            {
                                rd.status = "Delivered";
                                _clerkService.udpateRequisitionDetail(rd);
                            }
                            else if (rd.reqQty > rd.rcvQty && rd.rcvQty != 0)
                            {
                                rd.status = "Partially_Delivered";
                                _clerkService.udpateRequisitionDetail(rd);
                            }
                        }
                    }
                }
            }

            foreach (DisbursementList dl in currDL)
            {
                dl.status = "delivered";
                _clerkService.updateDisbursementList(dl);
                var currClk = await _clerkService.findEmployeeByIdAsync(currCP.FirstOrDefault().clerkId);

                String str = await _emailService.SendMail(currClk.email, "Disbursement Confirmed", "This is to confirm you have delivered disbursement no." + dl.id);
            }
            return(null);
        }
Esempio n. 2
0
        public async Task <ActionResult <IList <RequisitionDetail> > > GetAllPendingRequisitions(int id)
        {
            Console.WriteLine("android called for pending retrievals");

            var clerk = await _clkService.findEmployeeByIdAsync(id);

            var collectionpoints = await _clkService.findAllCollectionPointAsync();

            var currCollectionpoint  = collectionpoints.Where(x => x.clerkId == clerk.Id);
            var currCollectionpoint2 = currCollectionpoint.Select(x => x.Id);
            var departments          = await _clkService.findAllDepartmentAsync();

            var currDepartments  = departments.Where(x => currCollectionpoint2.Contains(x.CollectionId));
            var currDepartments2 = currDepartments.Select(x => x.Id);
            var employees        = await _clkService.findEmployeesAsync();

            var currEmployees  = employees.Where(x => currDepartments2.Contains(x.departmentId));
            var currEmployees2 = currEmployees.Select(x => x.Id);
            var requisitions   = await _clkService.findAllRequsitionAsync();

            var allRD = await _clkService.findAllRequsitionDetailsAsync();

            var nonDeliveredRD = allRD.Where(x => x.status != "Delivered");
            var nonDeclinedRD  = nonDeliveredRD.Where(x => x.status != "Declined");
            var nonApprovedRD  = nonDeclinedRD.Where(x => x.status != "Applied");
            var result         = nonApprovedRD.Where(x => x.reqQty != x.rcvQty);
            var requisition    = result.Select(x => x.RequisitionId);

            HashSet <int> uniqueRequisitionID = new HashSet <int>();

            foreach (int i in requisition)
            {
                uniqueRequisitionID.Add(i);
            }

            List <Requisition> currentRequisitions = new List <Requisition>();

            foreach (Requisition r in requisitions)
            {
                foreach (int i in uniqueRequisitionID)
                {
                    if (r.Id == i && currEmployees2.Contains(r.EmployeeId))
                    {
                        currentRequisitions.Add(r);
                    }
                }
            }

            var currentRequisitions2 = currentRequisitions.Select(x => x.Id);
            var result2 = result.Where(x => currentRequisitions2.Contains(x.RequisitionId));

            if (result2 != null)
            {
                //convert to json file
                Console.WriteLine("Sent requisition details");
                return(Ok(result2));
            }
            else
            {
                //in case there is nothing to process
                return(NotFound("No pending requistions"));
            }
        }