...
This commit is contained in:
169
Back/Controllers/InvoicePaymentController.cs
Normal file
169
Back/Controllers/InvoicePaymentController.cs
Normal 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> { "خطایی رخ داده" });
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -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,6 +358,8 @@ namespace Back.Controllers
|
||||
|
||||
//Pay
|
||||
List<PaymentDto> InvoicePay = new List<PaymentDto>();
|
||||
if (result.setm==1 || result.setm == 3)
|
||||
{
|
||||
if (level != 10)
|
||||
foreach (var pitem in result.payments)
|
||||
{
|
||||
@@ -378,6 +380,8 @@ namespace Back.Controllers
|
||||
|
||||
InvoicePay.Add(payment);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -71,7 +71,10 @@ namespace Back.Data.Models
|
||||
//اریخ کوتاژ اظهارنامه گمرکی
|
||||
// Unix Time => from fild CottageDateOfCustomsDeclaration
|
||||
[MaxLength(5)]
|
||||
public long? cdcd { get { return string.IsNullOrEmpty(CottageDateOfCustomsDeclaration) ? null : new DateTimeOffset(CottageDateOfCustomsDeclaration.Trim().ToMiladi()).ToUnixTimeMilliseconds(); } }
|
||||
public int? cdcd { get {
|
||||
return string.IsNullOrEmpty(CottageDateOfCustomsDeclaration) ? null : (int)DateTime.UtcNow.Subtract(CottageDateOfCustomsDeclaration.Trim().ToMiladi()).TotalSeconds;
|
||||
// return string.IsNullOrEmpty(CottageDateOfCustomsDeclaration) ? null : new DateTimeOffset(CottageDateOfCustomsDeclaration.Trim().ToMiladi()).ToUnixTimeMilliseconds();
|
||||
} }
|
||||
//کد پستی خریدار
|
||||
[MaxLength(10)]
|
||||
public string? bpc { get { return Customer.ZipCode; } }
|
||||
@@ -89,7 +92,10 @@ namespace Back.Data.Models
|
||||
public string? sbc { get { return company?.BranchID; } }
|
||||
//مبلغ پرداختی نقدی
|
||||
[MaxLength(18)]
|
||||
public decimal? cap { get { return tbill- insp- tvam- todam; } }
|
||||
public decimal? cap { get {
|
||||
return
|
||||
setm == 1 ? tbill : setm == 2 ? 0 : tbill - insp;
|
||||
} }
|
||||
//موضوع صورتحساب
|
||||
[MaxLength(1)]
|
||||
public int? ins { get { return (int)invoiceType; } }
|
||||
|
@@ -67,6 +67,7 @@ builder.Services.AddScoped<servSendMsg>();
|
||||
builder.Services.AddScoped<servUser>();
|
||||
builder.Services.AddScoped<servTaxPayer>();
|
||||
builder.Services.AddScoped<servCustomer>();
|
||||
builder.Services.AddScoped<servInvoicePayment>();
|
||||
builder.Services.AddScoped<CompanyRegistrationValidation>();
|
||||
builder.Services.AddScoped<AddOrCustomerValidation>();
|
||||
builder.Services.AddScoped<AddOrCodValidation>();
|
||||
|
@@ -99,7 +99,6 @@ namespace Back.Services
|
||||
acn = x.acn,
|
||||
iinn = x.acn,
|
||||
pcn = x.acn,
|
||||
pdt = x.pdt,
|
||||
PaymentDateTime = x.PaymentDateTime,
|
||||
pid = x.pid,
|
||||
pmt = x.pmt,
|
||||
@@ -233,6 +232,7 @@ namespace Back.Services
|
||||
.Include(inc => inc.sentTax)
|
||||
.Include(inc => inc.pattern)
|
||||
.Include(inc => inc.invoice)
|
||||
.Include(inc=>inc.payments)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<bool> DeleteInvoice(Invoice item)
|
||||
|
45
Back/Services/servInvoicePayment.cs
Normal file
45
Back/Services/servInvoicePayment.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Shared.DTOs;
|
||||
|
||||
namespace Back.Services
|
||||
{
|
||||
public class servInvoicePayment
|
||||
{
|
||||
private readonly IAsyncRepository<InvoicePayment> _Repo;
|
||||
public servInvoicePayment(IAsyncRepository<InvoicePayment> Repo)
|
||||
{
|
||||
_Repo = Repo;
|
||||
}
|
||||
public async Task<bool> Add(InvoicePayment item)
|
||||
{
|
||||
return await _Repo.AddBoolResultAsync(item);
|
||||
}
|
||||
public async Task<bool> Update(InvoicePayment item)
|
||||
{
|
||||
return await _Repo.UpdateAsync(item);
|
||||
}
|
||||
public async Task<bool> Delete(InvoicePayment item)
|
||||
{
|
||||
return await _Repo.DeleteAsync(item);
|
||||
}
|
||||
public async Task<bool> Exist(int companyID, int invoiceID, int ID)
|
||||
{
|
||||
return await _Repo.Get(w => w.InvoiceID == invoiceID && w.ID == ID && w.invoice.CompanyID == companyID).AnyAsync();
|
||||
}
|
||||
public async Task<InvoicePayment?> GetinvoicePay(int CompanyID, int ID)
|
||||
{
|
||||
return await _Repo
|
||||
.Get(w => w.ID == ID && w.invoice.CompanyID == CompanyID && !w.invoice.IsDeleted)
|
||||
.Include(s=>s.invoice)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<InvoicePayment> GetInvoicePayByInvoicePayID (int companyID, int invoiceID, int ID)
|
||||
{
|
||||
return await _Repo.Get(w => w.InvoiceID == invoiceID && w.ID == ID && w.invoice.CompanyID == companyID).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
89
Back/Validations/AUInvoicePayValidation.cs
Normal file
89
Back/Validations/AUInvoicePayValidation.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using Back.Common;
|
||||
using Back.Services;
|
||||
using FluentValidation;
|
||||
using Shared.DTOs;
|
||||
|
||||
namespace Back.Validations
|
||||
{
|
||||
// companyid invoiceid model
|
||||
public class AUInvoicePayValidation : AbstractValidator<Tuple<int, int, InvoicePaymentDTO, eActionValidation>>
|
||||
{
|
||||
public AUInvoicePayValidation(servInvoice servInvoice, servTaxPayer servTaxPayer, servInvoicePayment servInvoicepay)
|
||||
{
|
||||
When(m => m.Item4 == eActionValidation.update, () =>
|
||||
{
|
||||
RuleFor(r => r)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!model.Item3.ID.HasValue)
|
||||
context.AddFailure("شناسه در حالت ویرایش نمی تواند خالی باشد");
|
||||
if (!servInvoicepay.Exist(model.Item1, model.Item2, model.Item3.ID.Value).Result)
|
||||
context.AddFailure("شناسه یافت نشد");
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
When(m => m.Item4 == eActionValidation.update || m.Item4 == eActionValidation.add, () =>
|
||||
{
|
||||
|
||||
|
||||
|
||||
RuleFor(r => r.Item3).Custom((model, context) =>
|
||||
{
|
||||
if (model.pmt.HasValue && model.pmt.Value > 0 && model.pmt.Value < 9)
|
||||
{
|
||||
|
||||
}
|
||||
else context.AddFailure("روش پرداخت مشخص نشده");
|
||||
});
|
||||
|
||||
//RuleFor(r => r).Custom(async (model, context) =>
|
||||
//{
|
||||
// if (model.Item3.dis != null && model.Item3.dis > 0)
|
||||
// if (model.Item3.dis > model.Item3.am * model.Item3.fee)
|
||||
// context.AddFailure("مبلغ تخفیف نمی تواند از (تعداد * مبلغ واحد) بیشتر باشد");
|
||||
|
||||
|
||||
//});
|
||||
});
|
||||
RuleFor(r => r)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (model.Item2 != null && model.Item2 > 0)
|
||||
{
|
||||
var invoice = servInvoice.GetInvoiceByInvoiceID(model.Item1, model.Item2).Result;
|
||||
if (invoice == null)
|
||||
context.AddFailure("صورتحساب یافت نشد");
|
||||
|
||||
|
||||
else
|
||||
{
|
||||
if (model.Item4 == eActionValidation.update || model.Item4 == eActionValidation.add)
|
||||
{
|
||||
var totalpay = invoice.payments.Sum(s => s.pv).GetValueOrDefault() + model.Item3.pv;
|
||||
if (totalpay > invoice.tbill) context.AddFailure("مجموع مبلغ پرداختی میبایست از مجموع صورتحساب کوچکتر باشد.");
|
||||
|
||||
}
|
||||
|
||||
if (servTaxPayer.ExistSuccessfulorSendorpendingInvoice(invoice).Result)
|
||||
context.AddFailure("این صورتحساب به سازمان ارسال شده" + '\n' +
|
||||
"برای تغییر ،صورتحساب را ابطال/اصلاح یا برگشت بزنید");
|
||||
else if ((model.Item4 == eActionValidation.add || model.Item4 == eActionValidation.delete)
|
||||
&& invoice.invoiceType == InvoiceType.BackFrmSale)
|
||||
context.AddFailure("پرداخت های صورتحساب در وضعیت برگشت از فروش نمی تواند اضافه یا کم شود");
|
||||
else if (invoice.invoiceType != InvoiceType.Bidding
|
||||
&& invoice.invoiceType != InvoiceType.Sale && invoice.invoiceType != InvoiceType.Repair)
|
||||
{
|
||||
context.AddFailure($"صورتحساب در حالت {invoice.invoiceType.GetEnumDisplayName()} نمی تواند ویرایش شود" + '\n' +
|
||||
$"فقط در حالت پیش نویس ، فاکتور و اصلاح (که به سازمان ارسال نشده باشد) میتوان سند را ویرایش کرد");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else context.AddFailure("صورتحساب صحیح نمی باشد");
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -141,12 +141,10 @@ namespace Shared.DTOs
|
||||
[MaxLength(12)]
|
||||
public string? pid { get; set; }
|
||||
//تاریخ و زمان پرداخت
|
||||
[MaxLength(13)]
|
||||
public long? pdt { get; set; }
|
||||
public string? PaymentDateTime { get; set; }
|
||||
//مبلغ پرداختی
|
||||
[MaxLength(18)]
|
||||
public decimal? pv { get; set; }
|
||||
public long? pv { get; set; }
|
||||
|
||||
}
|
||||
//------------------------------
|
||||
|
@@ -23,8 +23,7 @@ builder.Services.AddScoped(sp => new UserAuthenticationDTO()
|
||||
IsAdmin = false,
|
||||
Logo = "",
|
||||
Name = ""
|
||||
}
|
||||
,
|
||||
},
|
||||
FullName = "",
|
||||
Photo="",
|
||||
Token="",
|
||||
@@ -37,10 +36,10 @@ builder.Services.AddScoped(sp => new UserAuthenticationDTO()
|
||||
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://195.88.208.142:7075/api/") });
|
||||
|
||||
//Home
|
||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") });
|
||||
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") });
|
||||
|
||||
//farzan
|
||||
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") });
|
||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") });
|
||||
|
||||
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fa-Ir");
|
||||
|
||||
|
Reference in New Issue
Block a user