public IActionResult SaveAndSendRequest(AcctAdvancePaymentModel model) { if (!ModelState.IsValid) { return(BadRequest()); } if (model.AdvanceRequests.Count > 0) { //Nếu sum(Amount) > 100.000.000 & Payment Method là Cash thì báo lỗi if (model.PaymentMethod.Equals(AccountingConstants.PAYMENT_METHOD_CASH)) { var totalAmount = model.AdvanceRequests.Select(s => s.Amount).Sum(); if (totalAmount > 100000000) { ResultHandle _result = new ResultHandle { Status = false, Message = "Total Advance Amount by cash is not exceed 100.000.000 VND" }; return(BadRequest(_result)); } } //Kiểm tra tồn tại shipment trong 1 Advance Payment khác. Nếu đã tồn tại thì báo lỗi //Updated 27/08/2019 by Andy.Hoa - [ĐÃ THAY ĐỔI YÊU CẦU - 1 SHIPMENT CHO PHÉP ĐƯỢC TẠO TRONG NHIỀU ADVANCE PAYMENT] //foreach (var item in model.AdvanceRequests) //{ // var shipment = new ShipmentAdvancePaymentCriteria // { // JobId = item.JobId, // HBL = item.Hbl, // MBL = item.Mbl, // AdvanceNo = model.AdvanceNo//Truyền vào Advance No cần update // }; // if (acctAdvancePaymentService.CheckShipmentsExistInAdvancePayment(shipment)) // { // ResultHandle _result = new ResultHandle { Status = false, Message = "Duplicate Shipment" }; // return BadRequest(_result); // } //} } //Check exist thông tin Manager, Accountant của User requester AcctApproveAdvanceModel advanceAppr = new AcctApproveAdvanceModel { Requester = model.Requester }; var isExistsManager = acctAdvancePaymentService.CheckExistsInfoManagerOfRequester(advanceAppr); if (!isExistsManager.Success) { ResultHandle _result = new ResultHandle { Status = false, Message = isExistsManager.Exception.Message }; return(BadRequest(_result)); } HandleState hs; if (string.IsNullOrEmpty(model.AdvanceNo))//Insert Advance Payment { model.StatusApproval = AccountingConstants.STATUS_APPROVAL_REQUESTAPPROVAL; hs = acctAdvancePaymentService.AddAdvancePayment(model); if (hs.Code == 403) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } } else //Update Advance Payment { var isAllowUpdate = acctAdvancePaymentService.CheckUpdatePermissionByAdvanceId(model.Id); if (isAllowUpdate == false) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } if (!model.StatusApproval.Equals(AccountingConstants.STATUS_APPROVAL_NEW) && !model.StatusApproval.Equals(AccountingConstants.STATUS_APPROVAL_DENIED)) { ResultHandle _result = new ResultHandle { Status = false, Message = "Only allowed to edit the advance payment status is New or Deny" }; return(BadRequest(_result)); } model.StatusApproval = AccountingConstants.STATUS_APPROVAL_REQUESTAPPROVAL; hs = acctAdvancePaymentService.UpdateAdvancePayment(model); if (hs.Code == 403) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } } var message = HandleError.GetMessage(hs, Crud.Insert); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value, Data = model }; if (hs.Success) { AcctApproveAdvanceModel approve = new AcctApproveAdvanceModel { AdvanceNo = model.AdvanceNo, Requester = model.Requester }; var resultInsertUpdateApprove = acctAdvancePaymentService.InsertOrUpdateApprovalAdvance(approve); if (!resultInsertUpdateApprove.Success) { ResultHandle _result = new ResultHandle { Status = false, Message = resultInsertUpdateApprove.Exception.Message }; return(BadRequest(_result)); } return(Ok(result)); } else { return(BadRequest(result)); } }
public IActionResult Update(AcctAdvancePaymentModel model) { if (!ModelState.IsValid) { return(BadRequest()); } var isAllowUpdate = acctAdvancePaymentService.CheckUpdatePermissionByAdvanceId(model.Id); if (isAllowUpdate == false) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } //Đã check bên trong function UpdateAdvancePayment //if (!model.StatusApproval.Equals(Constants.STATUS_APPROVAL_NEW) && !model.StatusApproval.Equals(Constants.STATUS_APPROVAL_DENIED)) //{ // ResultHandle _result = new ResultHandle { Status = false, Message = "Only allowed to edit the advance payment status is New or Deny" }; // return BadRequest(_result); //} if (model.AdvanceRequests.Count > 0) { //Nếu sum(Amount) > 100.000.000 & Payment Method là Cash thì báo lỗi if (model.PaymentMethod.Equals(AccountingConstants.PAYMENT_METHOD_CASH)) { var totalAmount = model.AdvanceRequests.Sum(x => x.Amount); if (totalAmount > 100000000) { ResultHandle _result = new ResultHandle { Status = false, Message = "Total Advance Amount by cash is not exceed 100.000.000 VND" }; return(BadRequest(_result)); } } //Kiểm tra tồn tại shipment trong 1 Advance Payment khác. Nếu đã tồn tại thì báo lỗi //Updated 27/08/2019 by Andy.Hoa - [ĐÃ THAY ĐỔI YÊU CẦU - 1 SHIPMENT CHO PHÉP ĐƯỢC TẠO TRONG NHIỀU ADVANCE PAYMENT] //foreach (var item in model.AdvanceRequests) //{ // var shipment = new ShipmentAdvancePaymentCriteria // { // JobId = item.JobId, // HBL = item.Hbl, // MBL = item.Mbl, // AdvanceNo = model.AdvanceNo//Truyền vào Advance No cần update // }; // if (acctAdvancePaymentService.CheckShipmentsExistInAdvancePayment(shipment)) // { // ResultHandle _result = new ResultHandle { Status = false, Message = "Duplicate Shipment" }; // return BadRequest(_result); // } //} } var hs = acctAdvancePaymentService.UpdateAdvancePayment(model); if (hs.Code == 403) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } var message = HandleError.GetMessage(hs, Crud.Update); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value, Data = model }; if (!hs.Success) { return(BadRequest(result)); } return(Ok(result)); }
public IActionResult PreviewAdvancePaymentRequest(AcctAdvancePaymentModel advance) { var result = acctAdvancePaymentService.Preview(advance); return(Ok(result)); }
public IActionResult Add(AcctAdvancePaymentModel model) { if (!ModelState.IsValid) { return(BadRequest()); } if (model.AdvanceRequests.Count > 0) { //Nếu sum(Amount) > 100.000.000 & Payment Method là Cash thì báo lỗi if (model.PaymentMethod.Equals(AccountingConstants.PAYMENT_METHOD_CASH)) { var totalAmount = model.AdvanceRequests.Sum(x => x.Amount); if (totalAmount > 100000000) { ResultHandle _result = new ResultHandle { Status = false, Message = "Total Advance Amount by cash is not exceed 100.000.000 VND" }; return(BadRequest(_result)); } } //Kiểm tra tồn tại shipment trong 1 Advance Payment khác. Nếu đã tồn tại thì báo lỗi //Updated 27/08/2019 by Andy.Hoa - [ĐÃ THAY ĐỔI YÊU CẦU - 1 SHIPMENT CHO PHÉP ĐƯỢC TẠO TRONG NHIỀU ADVANCE PAYMENT] //foreach(var item in model.AdvanceRequests) //{ // var shipment = new ShipmentAdvancePaymentCriteria // { // JobId = item.JobId, // HBL = item.Hbl, // MBL = item.Mbl, // AdvanceNo = item.AdvanceNo // }; // if (acctAdvancePaymentService.CheckShipmentsExistInAdvancePayment(shipment)) // { // ResultHandle _result = new ResultHandle { Status = false, Message = "Duplicate Shipment" }; // return BadRequest(_result); // } //} } var hs = acctAdvancePaymentService.AddAdvancePayment(model); if (hs.Code == 403) { return(BadRequest(new ResultHandle { Status = false, Message = stringLocalizer[LanguageSub.DO_NOT_HAVE_PERMISSION].Value })); } var message = HandleError.GetMessage(hs, Crud.Insert); ResultHandle result = new ResultHandle { Status = hs.Success, Message = stringLocalizer[message].Value, Data = model }; if (!hs.Success) { return(BadRequest(result)); } return(Ok(result)); }