示例#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);
        }
示例#2
0
        public async Task <ActionResult <DisbursementList> > processRetrieval(
            [FromBody] List <fakeRequisitionDetails> fakeRequisitions, int id, int year, int month, int day)
        {
            Console.WriteLine(year);
            Console.WriteLine(month);
            Console.WriteLine(day);
            string time = year + "-" + month + "-" + day + " 23:59:59";

            Console.WriteLine(time);
            #region data fetching for processing
            Console.WriteLine("post");
            var allRD = await _clkService.findAllRequsitionDetailsAsync();

            var nonDeliveredRD     = allRD.Where(x => x.status != "Delivered");
            var nonAppliedRD       = nonDeliveredRD.Where(x => x.status != "Applied");
            var requisitiondetails = nonAppliedRD.Where(x => x.status != "Declined");
            var requisitions       = await _clkService.findAllRequsitionAsync();

            var stationeries = await _clkService.findAllStationeriesAsync();

            var departments = await _clkService.findAllDepartmentAsync();

            var collectionpoints = await _clkService.findAllCollectionPointAsync();

            Console.WriteLine("fetching done and starting processing");
            #endregion

            #region create new Stock Adjustment
            StockAdjustment newSA = new StockAdjustment();
            newSA.date       = DateTime.Now;
            newSA.EmployeeId = id;
            newSA.type       = "stock retrieval";
            _clkService.saveStockAdjustment(newSA);
            Console.WriteLine("created stock adjustment");
            #endregion

            #region creating necessary Disbursement List
            HashSet <Department> deptlist = new HashSet <Department>();
            foreach (fakeRequisitionDetails i in fakeRequisitions)
            {
                foreach (RequisitionDetail rd in requisitiondetails)
                {
                    if ((i.reqQty != 0) && (i.id == rd.Id))
                    {
                        var rul = await _clkService.findEmployeeByIdAsync(requisitions.Where(y => y.Id == rd.RequisitionId).FirstOrDefault().EmployeeId);

                        deptlist.Add(departments.Where(x => x.Id == rul.departmentId).FirstOrDefault());
                    }
                }
            }

            List <DisbursementList> disbursementList = new List <DisbursementList>();
            foreach (Department d in deptlist)
            {
                DisbursementList newDL = new DisbursementList();
                newDL.DepartmentId  = d.Id;
                newDL.date          = DateTime.Parse(time);
                newDL.deliveryPoint = collectionpoints.Where(x => x.Id == d.CollectionId).FirstOrDefault().collectionPoint;
                //d.Collection.collectionPoint;
                disbursementList.Add(newDL);
                _clkService.saveDisbursementList(newDL);
            }
            #endregion

            foreach (DisbursementList dl in disbursementList)
            {
                foreach (fakeRequisitionDetails i in fakeRequisitions)
                {
                    foreach (RequisitionDetail rd in requisitiondetails)
                    {
                        if ((i.reqQty != 0) && (i.id == rd.Id))
                        {
                            var currEmp = await _clkService.findEmployeeByIdAsync(requisitions.Where(y => y.Id == rd.RequisitionId).FirstOrDefault().EmployeeId);

                            if (currEmp.departmentId == dl.DepartmentId)
                            {
                                #region saving stockadjustments
                                StockAdjustmentDetail SAD = new StockAdjustmentDetail();
                                SAD.stockAdjustmentId = newSA.Id;
                                SAD.StationeryId      = rd.StationeryId;
                                SAD.discpQty          = -(i.reqQty);
                                SAD.comment           = "sent to " + departments.Where(x => x.Id == currEmp.departmentId).FirstOrDefault().deptName;
                                SAD.Status            = "Approved";
                                _clkService.saveStockAdjustmentDetail(SAD);
                                #endregion

                                #region updating stationeries item
                                foreach (Stationery s in stationeries)
                                {
                                    if (s.Id == rd.StationeryId)
                                    {
                                        s.inventoryQty -= i.reqQty;
                                        _clkService.updateStationery(s);
                                    }
                                }
                                #endregion

                                #region updating requisition detail

                                rd.rcvQty += i.reqQty;
                                Console.WriteLine($"{rd.Id},{rd.reqQty},{rd.rcvQty},{rd.StationeryId}, for the incoming {i.reqQty}");
                                _clkService.udpateRequisitionDetail(rd);
                                #endregion

                                #region creating disbursements
                                DisbursementDetail currDB = new DisbursementDetail();
                                currDB.DisbursementListId = dl.id;
                                currDB.qty = i.reqQty;
                                currDB.RequisitionDetailId = rd.Id;
                                _clkService.saveDisbursementDetail(currDB);
                                #endregion



                                Console.WriteLine("id:" + i.id + ", reqID:" + rd.RequisitionId + ", qty:" + i.reqQty);
                            }
                        }
                    }
                }
            }
            Console.WriteLine("done");
            return(Ok(disbursementList));
        }