コード例 #1
0
        public void AddRepairAndMaintenance(ServiceRequestModel <RepairAndMaintenanceViewModel> serviceRequestModel)
        {
            var mapped = _mapper.Map <RepairAndMaintenanceViewModel, RepairAndMaintenance>(serviceRequestModel.Model);

            mapped.Id          = Guid.NewGuid();
            mapped.CreatedDate = GeneralService.CurrentDate;
            mapped.CreatedById = serviceRequestModel.CurrentUserId.Value;
            mapped.Step        = 1;
            if (serviceRequestModel.LoginInfo.RoleId == new Guid(ApplicationConstants.AreaAdministratorRoleId) ||
                serviceRequestModel.LoginInfo.RoleId == new Guid(ApplicationConstants.AssistantAreaAdministratorRoleId))
            {
                mapped.BranchId = serviceRequestModel.Model.BranchId.Value;
            }

            else
            {
                mapped.BranchId = serviceRequestModel.LoginInfo.LoginUserBranches.FirstOrDefault().Id;
            }
            _genericUnitOfWork.GetRepository <RepairAndMaintenance, Guid>().Add(mapped);
            _genericUnitOfWork.SaveChanges();
            var emails = _sharedService.GetRepairAndMaintenanceProcessorEmails(BranchRequestType.Maintenance, mapped.Id);

            SendEmailToFirstStep(emails, new AdminNotificationViewModel()
            {
                Date           = mapped.CreatedDate.ToString("dd/MM/yyyy"),
                Sender         = _sharedService.GetUserFullName(mapped.CreatedById),
                ProcessingType = mapped.ProcessingStatus.ToString(),
                Category       = serviceRequestModel.Model.CategoryName,
                CategoryItem   = serviceRequestModel.Model.CategoryItemName,
                Quotations     = serviceRequestModel.Model.Quotations,
            });
        }
コード例 #2
0
        public void AddRecoupment(ServiceRequestModel <RecoupmentViewModel> serviceRequestModel)
        {
            var repo     = _genericUnitOfWork.GetRepository <Recoupment, Guid>();
            var branchId = serviceRequestModel.LoginInfo.LoginUserBranches.FirstOrDefault().Id;

            var mapped = _objectMapper.Map <RecoupmentViewModel, Recoupment>(serviceRequestModel.Model);

            var pettyCashQuerable = _genericUnitOfWork.GetRepository <PettyCashLedger, Guid>().GetAll();

            var recoupmentExists = repo.GetAll().Any(c => !c.IsPaid && c.BranchId == branchId && c.ProcessingStatus != ProcessingStatus.Rejected);

            if (recoupmentExists)
            {
                throw new ArgumentNullException($"Recoupment for selected branch already exists in the system.", innerException: null);
            }


            var opentingBalance = pettyCashQuerable.FirstOrDefault(c => c.PettyCashSourceType == PettyCashSourceType.Opening && c.BranchId == branchId)?.Amount;

            if (opentingBalance == null)
            {
                throw new ArgumentNullException($"Opening balance is not set for the selected branch.", innerException: null);
            }

            var totalFund  = pettyCashQuerable.Where(c => c.PettyCashSourceType != PettyCashSourceType.Claim && c.BranchId == branchId).Select(s => s.Amount).DefaultIfEmpty().Sum();
            var totalClaim = pettyCashQuerable.Where(p => p.PettyCashSourceType == PettyCashSourceType.Claim && (p.BranchId == branchId)).Select(j => j.Amount).DefaultIfEmpty().Sum();

            if (totalClaim == 0)
            {
                throw new ArgumentNullException($"No any claim has been paid.", innerException: null);
            }



            var isClaimedAmountHalfOfInitial = totalClaim >= (totalFund / 2);

            if (!isClaimedAmountHalfOfInitial)
            {
                throw new ArgumentNullException($"Petty cash balance should be half or more than half for applying the recoupment.", innerException: null);
            }

            if (serviceRequestModel.Model.RequestedAmount > totalFund)
            {
                throw new ArgumentNullException($"Requested amount is greater than banchwise budget limit.", innerException: null);
            }

            if (serviceRequestModel.Model.RequestedAmount == 0)
            {
                throw new ArgumentNullException($"Requested amount should be greater than zero.", innerException: null);
            }


            mapped.Id               = Guid.NewGuid();
            mapped.Step             = 1;
            mapped.ProcessingStatus = ProcessingStatus.Pending;
            mapped.CreatedById      = serviceRequestModel.CurrentUserId;
            mapped.CreatedDate      = GeneralService.CurrentDate;
            mapped.RequestedDate    = GeneralService.CurrentDate;
            mapped.BranchId         = branchId;
            repo.Add(mapped);
            _genericUnitOfWork.SaveChanges();
            if (mapped.ProcessingStatus != ProcessingStatus.Pending)
            {
                return;
            }

            var emails       = GetRecoupmentProcessorEmails(mapped.Id);
            var emailRequest = new EmailRequestWithUrl <RecoupmentProcessingNotificationViewModel>()
            {
                Model = new RecoupmentProcessingNotificationViewModel()
                {
                    Amount         = mapped.RequestedAmount,
                    Sender         = _sharedService.GetUserFullName(mapped.CreatedById.Value),
                    ProcessingType = "verify",
                    Balance        = mapped.PvcCurrentBalance,
                    Date           = mapped.CreatedDate.ToString("dd/MM/yyyy")
                }
            };

            emails.ForEach(x => emailRequest.To.Add(new System.Net.Mail.MailAddress(x)));
            emailRequest.Subject  = MailSubject.RecoupmentProcess.ToDescription();
            emailRequest.Template = EmailTemplate.RecoupmentProcessing;
            _emailComposer.SendRecoupmentEmail(emailRequest);
        }