This commit is contained in:
mmrbnjd
2024-08-28 00:29:35 +03:30
parent 21eeb4d11b
commit c118dc0d6b
9 changed files with 338 additions and 27 deletions

View File

@@ -0,0 +1,169 @@
using Back.Common;
using Back.Data.Models;
using Back.Services;
using Back.Validations;
using FluentValidation;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
using System.Net;
using System.Runtime.ConstrainedExecution;
using System.Security.Cryptography;
namespace Back.Controllers
{
[Route("api/[controller]")]
[Authorize]
[ApiController]
public class InvoicePaymentController : ControllerBase
{
private readonly servInvoicePayment _servpay;
private readonly servUser _servUser;
private readonly AUInvoicePayValidation _validation;
private readonly servInvoice _servInvoice;
public InvoicePaymentController(servInvoicePayment servpay, AUInvoicePayValidation validation
, servUser servUser, servInvoice servInvoice)
{
_servpay = servpay;
_validation = validation;
_servUser = servUser;
_servInvoice = servInvoice;
}
[HttpPost("AddPay")]
public async Task<ActionResult<bool>> AddItem([FromBody] InvoiceItemAction<InvoicePaymentDTO> model)
{
//-----GetUserAndCompany
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
//-----Validaton
//var resultValidationmodel = await _validationInvoiceItem.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, model.invoiceID, model.item, eActionValidation.add));
//if (!resultValidationmodel.IsValid)
// return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
//-----Get invoice
Invoice invoice = await _servInvoice.GetInvoiceByInvoiceID(user.RolUsers.First().CompanyID, model.invoiceID);
if (invoice == null)
return BadRequest(new List<string> { "invoice notFound..." });
invoice.LastChangeUserID = Convert.ToInt32(UserID);
if (await _servInvoice.UpdateInvoice(invoice))
{
return Ok(await _servpay.Add(new Data.Models.InvoicePayment
{
InvoiceID = model.invoiceID,
acn = model.item.acn,
iinn = model.item.iinn,
PaymentDateTime = model.item.PaymentDateTime.Replace("/", ""),
pcn = model.item.pcn,
pid = model.item.pid,
pmt = model.item.pmt,
pv = model.item.pv,
trmn = model.item.trmn,
trn = model.item.trn,
}));
}
else return BadRequest(new List<string> { "خطایی رخ داده" });
}
[HttpPut("UpdatePay")]
public async Task<ActionResult<bool>> UpdateItem([FromBody] InvoiceItemAction<InvoicePaymentDTO> model)
{
//-----GetUserAndCompany
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
//-----Get invoice
Invoice invoice = await _servInvoice.GetInvoiceByInvoiceID(user.RolUsers.First().CompanyID, model.invoiceID);
if (invoice == null)
return BadRequest(new List<string> { "invoice notFound..." });
//-----Validaton
//var resultValidationmodel = await _validationInvoiceItem.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, model.invoiceID, model.item, eActionValidation.update));
//if (!resultValidationmodel.IsValid)
//{
// if (invoice.invoiceType != InvoiceType.BackFrmSale || (invoice.invoiceType != InvoiceType.BackFrmSale
// && resultValidationmodel.Errors.Count > 1))
// {
// return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
// }
//}
var item = await _servpay.GetInvoicePayByInvoicePayID(user.RolUsers.First().CompanyID, model.invoiceID, model.item.ID.Value);
if (item == null)
return BadRequest(new List<string> { "invoice Pay notFound..." });
invoice.LastChangeUserID = Convert.ToInt32(UserID);
item.acn = model.item.acn;
item.iinn = model.item.iinn;
item.PaymentDateTime = model.item.PaymentDateTime.Replace("/", "");
item.pcn = model.item.pcn;
item.pid = model.item.pid;
item.pmt = model.item.pmt;
item.pv = model.item.pv;
item.trmn = model.item.trmn;
item.trn = model.item.trn;
if (await _servInvoice.UpdateInvoice(invoice))
return Ok(await _servpay.Update(item));
else
return BadRequest(new List<string> { "خطایی رخ داده" });
}
[HttpDelete("DeletePay/{InvoicePayID}")]
public async Task<ActionResult<bool>> DeleteItem(int InvoicePayID)
{
//-----GetUserAndCompany
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
//-----Get invoicePay
var payitem = await _servpay.GetinvoicePay(user.RolUsers.First().CompanyID, InvoicePayID);
if (payitem == null)
return NotFound(new List<string> { "invoice pay notFound..." });
////-----Validaton
//var resultValidationmodel = await _validationInvoiceItem.ValidateAsync(Tuple.Create(user.RolUsers.First().CompanyID, invoiceitem.InvoiceID, new InvoiceItemDTO(), eActionValidation.delete));
//if (!resultValidationmodel.IsValid)
// return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
payitem.invoice.LastChangeUserID = Convert.ToInt32(UserID);
if (await _servInvoice.UpdateInvoice(payitem.invoice))
return Ok(await _servpay.Delete(payitem));
else return BadRequest(new List<string> { "خطایی رخ داده" });
}
}
}

View File

@@ -236,7 +236,7 @@ namespace Back.Controllers
//شماره کدتاژ اظهارنامه گمرکی
Cdcn = level == 10 ? result.cdcn : null,
//تاریخ کوتاژ اظهارنامه گمرکی
// Cdcd = level == 10 ? result.cdcd : null,
Cdcd = level == 10 ? result.cdcd : null,
//شناسه یکتای ثبت قزارداد فروشنده
Crn = (level == 3 || level == 4 || level == 5 || level == 6) && !string.IsNullOrEmpty(result.crn) ? result.crn : null,
//شماره اشتراک/شناسه قبض بهره بردار
@@ -358,26 +358,30 @@ namespace Back.Controllers
//Pay
List<PaymentDto> InvoicePay = new List<PaymentDto>();
if(level!=10)
foreach (var pitem in result.payments)
if (result.setm==1 || result.setm == 3)
{
PaymentDto payment = new PaymentDto();
payment = new PaymentDto
if (level != 10)
foreach (var pitem in result.payments)
{
Iinn=pitem.iinn,
Acn=pitem.acn,
Trmn=pitem.trmn,
Pmt=pitem.pmt,
Trn=pitem.trn,
Pcn=pitem.pcn,
Pid=pitem.pid,
Pdt=pitem.pdt,
Pv=pitem.pv,
};
PaymentDto payment = new PaymentDto();
payment = new PaymentDto
{
Iinn = pitem.iinn,
Acn = pitem.acn,
Trmn = pitem.trmn,
Pmt = pitem.pmt,
Trn = pitem.trn,
Pcn = pitem.pcn,
Pid = pitem.pid,
Pdt = pitem.pdt,
Pv = pitem.pv,
InvoicePay.Add(payment);
};
InvoicePay.Add(payment);
}
}