Example #1
0
        public Models.MobileDTOs.DisbursementListDTO GetClerkDisbursements(int EmployeeId)
        {
            Models.MobileDTOs.DisbursementListDTO disbursementList = new Models.MobileDTOs.DisbursementListDTO();
            List <Disbursement> disbursements = (List <Disbursement>)disbursementRepo.GetDisbursementsByClerkId(EmployeeId);
            List <Models.MobileDTOs.DisbursementDTO> disbursements1 = new List <Models.MobileDTOs.DisbursementDTO>();

            foreach (Disbursement disbursement in disbursements)
            {
                Models.MobileDTOs.DisbursementDTO disbursement1 = new Models.MobileDTOs.DisbursementDTO
                {
                    Id = disbursement.Id,
                    DeliveredEmployeeId  = disbursement.DeliveredEmployeeId,
                    ReceivedEmployeeId   = (int)disbursement.ReceivedEmployeeId,
                    ReceivedEmployeeName = disbursement.Employee1.Name,
                    DepartmentName       = disbursement.Employee1.Department.DepartmentName,
                    AdHoc            = disbursement.AdHoc,
                    CollectionPoint  = disbursement.CollectionPoint,
                    DeliveryDateTime = (DateTime)disbursement.DeliveryDateTime,
                    OnRoute          = disbursement.OnRoute
                };
                disbursement1.RequisitionDetails = new List <Models.MobileDTOs.RequisitionDetailDTO>();
                foreach (RequisitionDetail rd in disbursement.RequisitionDetails)
                {
                    Models.MobileDTOs.RequisitionDetailDTO rd1 = new Models.MobileDTOs.RequisitionDetailDTO
                    {
                        Id                = rd.Id,
                        RequisitionId     = rd.RequisitionId,
                        DisbursementId    = (int)rd.DisbursementId,
                        StationeryId      = rd.StationeryId,
                        QuantityOrdered   = rd.QuantityOrdered,
                        QuantityDelivered = (int)rd.QuantityDelivered,
                        Status            = rd.Status,
                        Stationery        = new Models.MobileDTOs.StationeryDTO
                        {
                            Description = rd.Stationery.Description
                        },
                        Requisition = new Models.MobileDTOs.RequisitionDTO
                        {
                            Employee = new Models.MobileDTOs.EmployeeDTO
                            {
                                Name = rd.Requisition.Employee.Name
                            }
                        }
                    };
                    disbursement1.RequisitionDetails.Add(rd1);
                }
                disbursements1.Add(disbursement1);
            }
            disbursementList.Disbursements = disbursements1;
            return(disbursementList);
        }
Example #2
0
        public void CompleteDisbursementProcess(Models.MobileDTOs.DisbursementDTO disbursement)
        {
            List <Models.MobileDTOs.RequisitionDetailDTO> requisitionDetails = disbursement.RequisitionDetails;
            List <RequisitionDetail> unfulfilledRds = new List <RequisitionDetail>();

            foreach (Models.MobileDTOs.RequisitionDetailDTO rd in requisitionDetails)
            {
                if (rd.QuantityOrdered != rd.QuantityDelivered)
                {
                    int qtyDifference = (int)rd.QuantityDelivered - rd.QuantityOrdered;
                    AdjustmentVoucher targetAdjustmentVoucher = retrievalService.retrieveNewOrAvailableAdjustmentVoucherForClerk(disbursement.DeliveredEmployeeId);
                    retrievalService.createNewAdjustmentVoucherDetail(targetAdjustmentVoucher, rd.StationeryId, qtyDifference);
                    if (rd.QuantityDelivered > 0)
                    {
                        RequisitionDetail rd1 = requisitionDetailRepo.FindById(rd.Id);
                        rd1.QuantityDelivered = rd.QuantityDelivered;
                        rd1.Status            = RequisitionDetailStatusEnum.COLLECTED.ToString();
                        requisitionDetailRepo.Update(rd1);
                        int diff = rd.QuantityOrdered - (int)rd.QuantityDelivered;
                        int availStockForUnfulfilled = requisitionCatalogueService.GetAvailStockForUnfulfilledRd(rd.StationeryId, rd.Id);
                        if (availStockForUnfulfilled < diff) //insufficient stock
                        {
                            int waitlistCount = diff - availStockForUnfulfilled;
                            requisitionCatalogueService.createNewRequisitionDetail(waitlistCount, rd.RequisitionId, rd.StationeryId, RequisitionDetailStatusEnum.WAITLIST_APPROVED);

                            if (availStockForUnfulfilled > 0)
                            {
                                requisitionCatalogueService.createNewRequisitionDetail(availStockForUnfulfilled, rd.RequisitionId, rd.StationeryId, RequisitionDetailStatusEnum.PREPARING);
                            }
                        }
                        else
                        {
                            requisitionCatalogueService.createNewRequisitionDetail(diff, rd.RequisitionId, rd.StationeryId, RequisitionDetailStatusEnum.PREPARING);
                        }
                    }
                }
                else
                {
                    RequisitionDetail rd1 = requisitionDetailRepo.FindById(rd.Id);
                    rd1.QuantityDelivered = rd.QuantityDelivered;
                    rd1.Status            = RequisitionDetailStatusEnum.COLLECTED.ToString();
                    requisitionDetailRepo.Update(rd1);
                }
            }
            requisitionCatalogueService.CheckRequisitionCompletenessAfterDisbursement(disbursement.Id, disbursement);
        }
        //only call AFTER GENERATING NEW RD FOR UNFULFILLED ITEMS
        public void CheckRequisitionCompletenessAfterDisbursement(int disbursementId, Models.MobileDTOs.DisbursementDTO dDto)
        {
            List <Requisition> uniqueReqs = requisitionDetailRepo.GetUniqueRequisitionsForDisbursement(disbursementId);

            foreach (Requisition r in uniqueReqs)
            {
                int rowsReqDets   = requisitionDetailRepo.FindBy(x => x.RequisitionId == r.Id).Count();
                int rowsFulfilled = requisitionDetailRepo.FindBy(x => x.RequisitionId == r.Id &&
                                                                 x.Status.Equals("COLLECTED")).Count();
                if (rowsReqDets == rowsFulfilled)
                {
                    //update r to completed
                    Requisition req = requisitionRepo.FindById(r.Id);
                    req.Status = RequisitionStatusEnum.COMPLETED.ToString();
                    requisitionRepo.Update(req);
                    emailNotificationService.NotifyEmployeeCompletedRequisition(req, req.Employee);
                }
            }
            Disbursement d = disbursementRepo.FindById(disbursementId);

            d.DeliveryDateTime = DateTime.Now;
            byte[] bytes = Convert.FromBase64String(dDto.Signature);
            d.Signature = bytes;
            d.OnRoute   = false;
            disbursementRepo.Update(d);
            foreach (RequisitionDetail rd in d.RequisitionDetails)
            {
                Stationery s = stationeryRepo.FindById(rd.Stationery.Id);
                s.Quantity -= (int)rd.QuantityDelivered;
                stationeryRepo.Update(s);
            }
        }