Ejemplo n.º 1
0
        public Result <bool> Validate(ReturnCalculationRequest request)
        {
            Result <bool> result = new Result <bool>();

            result.Code  = ResultCode.Error;
            result.Value = false;

            if (request == null)
            {
                return(result.AddMessage("Request is null"));
            }
            if (request.SiNumber <= 0)
            {
                return(result.AddMessage("SiNumber must be 1 or higher"));
            }
            if (request.SiNumber > 99999999999)
            {
                return(result.AddMessage("SiNumber is too large"));
            }
            if (string.IsNullOrWhiteSpace(request.Reason))
            {
                return(result.AddMessage("Reason not provided"));
            }
            if (string.IsNullOrWhiteSpace(request.Insz))
            {
                return(result.AddMessage("INSZ not provided"));
            }

            if (request.ReturnByDeduction > 0 ||
                request.ReturnByOGM > 0)
            {
                //Proposition was altered

                decimal sum   = request.ReturnByOGM + request.ReturnByDeduction;
                var     lines = _unreturnablePaymentLineService.GetReturnableLines(request.IsFraude, request.ReturnLines);

                if (lines.Sum(rl => rl.PaymentLines.Sum(pl => pl.Amount)) != sum)
                {
                    return(result.AddMessage("Total returnable amount does not match custom proposition"));
                }
            }

            result.Code  = ResultCode.Ok;
            result.Value = true;

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostCreateLetter([FromBody] ReturnCalculationRequest request)
        {
            if (ModelState.IsValid)
            {
                var originalFile = Path.Combine(_environment.ContentRootPath, "Docs", "Returns", "Regular.dotx");
                var newFile      = Path.GetTempFileName();

                System.IO.File.Copy(originalFile, newFile, true);

                var dict = new Dictionary <string, string>
                {
                    { "SiNumber", request.SiNumber.ToString() },
                    { "INSZ", request.Insz },
                    { "Reason", request.Reason },
                    { "Remark", request.Remark },
                };

                using (var doc = WordprocessingDocument.Open(newFile, true))
                {
                    doc.ChangeDocumentType(WordprocessingDocumentType.Document);
                    var mainPart = doc.MainDocumentPart;
                    DocumentCoreGenerator.RunElements(mainPart.Document.Body, dict);
                    mainPart.Document.Save();
                    doc.Close();
                }

                var filename = string.Format("Brief terugvordering_{0}.docx", request.Insz);
                var result   = await _dataService.StoreReturnCalculationAsync(request);

                string applicationType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                HttpContext.Response.ContentType = applicationType;
                var bytes = await System.IO.File.ReadAllBytesAsync(newFile);

                return(new FileContentResult(bytes, applicationType)
                {
                    FileDownloadName = filename
                });
            }
            return(BadRequest(ModelState));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PostReturnLines([FromBody] ReturnCalculationRequest request)
        {
            if (ModelState.IsValid)
            {
                request.CreatedBy = User.Identity.Name;
                var response = await _service.CalculateDefaultProposition(request);

                switch (response.Code)
                {
                case ResultCode.Ok:
                    return(Ok(response.Value));

                case ResultCode.Error:
                    return(BadRequest(string.Join(";", response.Messages)));

                case ResultCode.Warning:
                    return(Ok(response.Value));

                default:
                    break;
                }
            }
            return(BadRequest(ModelState));
        }
Ejemplo n.º 4
0
        public async Task <Result <bool> > StoreReturnCalculationAsync(ReturnCalculationRequest request)
        {
            var validationResult = _validationService.Validate(request);

            if (validationResult.Code != ResultCode.Ok)
            {
                return(validationResult);
            }

            var serviceRequest = Mapper.Map <SaveReturnCalculationRequest>(request);

            decimal amount = request.ReturnByDeduction;

            if (amount > 0)
            {
                var result = await _propositionService.DistributeAmount(amount, request.SiNumber, request.Insz);

                var lines = result.lines;
                amount = result.amount;

                if (amount > 0)
                {
                    return new Result <bool>(false)
                           {
                               Code = ResultCode.Error
                           }
                }
                ;
                foreach (var item in lines)
                {
                    switch (item.Kind)
                    {
                    case VSBaseAngular.Models.ReturnCalculationKind.ZVZ:
                        serviceRequest.ReturnByZVZ = item.Amount;
                        break;

                    case VSBaseAngular.Models.ReturnCalculationKind.BOB:
                        serviceRequest.ReturnByBOB = item.Amount;
                        break;

                    case VSBaseAngular.Models.ReturnCalculationKind.THAB:
                        serviceRequest.ReturnByTHAB = item.Amount;
                        break;

                    default:
                        break;
                    }
                }
            }


            var returnMessage = await _vsbService.UpsertReturnCalculationAsync(serviceRequest);

            if (returnMessage.Value != null)
            {
                return(new Result <bool>(returnMessage.Value.Succeeded));
            }
            else
            {
                return(new Result <bool>(false)
                {
                    Code = ResultCode.Error, Messages = returnMessage.BusinessMessages.Select(m => m.MessageString).ToList()
                });
            }
        }
    }
Ejemplo n.º 5
0
        public async Task <Result <ReturnCalculationResponse> > CalculateDefaultProposition(ReturnCalculationRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (request.SiNumber <= 0 || request.SiNumber >= 99999999999)
            {
                throw new ArgumentException("SiNumber is not within a valid range");
            }

            var result = _validation.Validate(request);

            if (result.Code != ResultCode.Ok)
            {
                return(new Result <ReturnCalculationResponse>()
                {
                    Code = result.Code, Messages = result.Messages
                });
            }


            ReturnCalculationResponse response = new ReturnCalculationResponse();

            if (request.ReturnLines == null || request.ReturnLines.Count() == 0)
            {
                return(new Result <ReturnCalculationResponse>(response));
            }

            response.AmountNonRefundable   = _paymentLineService.GetUnreturnableAmount(request.IsFraude, request.ReturnLines);
            response.AmountRefundableByFOD = _paymentLineService.GetReturnableAmountByFOD(request.IsFraude, request.ReturnLines);
            decimal amountToRecover = _paymentLineService.GetReturnableAmount(request.IsFraude, request.ReturnLines);

            var distributeResponse = await this.DistributeAmount(amountToRecover, request.SiNumber, request.Insz);

            response.ReturnLines           = distributeResponse.lines;
            response.AmountRefundableByOGM = distributeResponse.amount;

            return(new Result <ReturnCalculationResponse>(response));
        }