...
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Service">
|
||||
<HintPath>..\..\Dlls\Service.dll</HintPath>
|
||||
<HintPath>..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
|
105
Back/Controllers/InvoiceItemController.cs
Normal file
105
Back/Controllers/InvoiceItemController.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using Back.Common;
|
||||
using Back.Data.Models;
|
||||
using Back.Services;
|
||||
using Back.Validations;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Shared.DTOs;
|
||||
using System.Net;
|
||||
|
||||
namespace Back.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class InvoiceItemController : ControllerBase
|
||||
{
|
||||
private readonly servInvoiceItem _servInvoiceItem;
|
||||
private readonly servUser _servUser;
|
||||
private readonly AUInvoiceItemValidation _validationInvoiceItem;
|
||||
private readonly servInvoice _servInvoice;
|
||||
public InvoiceItemController(servInvoiceItem servInvoiceItem, AUInvoiceItemValidation validationInvoiceItem
|
||||
, servUser servUser, servInvoice servInvoice)
|
||||
{
|
||||
_servInvoiceItem = servInvoiceItem;
|
||||
_validationInvoiceItem = validationInvoiceItem;
|
||||
_servUser = servUser;
|
||||
_servInvoice = servInvoice;
|
||||
|
||||
}
|
||||
[HttpPost("AddItem/{invoiceID}")]
|
||||
public async Task<ActionResult> AddItem([FromRoute] int invoiceID, [FromBody] InvoiceItemDTO 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, invoiceID, model, 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, invoiceID);
|
||||
if (invoice == null)
|
||||
return BadRequest(new List<string> { "invoice notFound..." });
|
||||
|
||||
|
||||
invoice.LastChangeUserID = Convert.ToInt32(UserID);
|
||||
|
||||
if (await _servInvoice.UpdateInvoice(invoice))
|
||||
{
|
||||
return Ok(await _servInvoiceItem.Add(new InvoiceItem
|
||||
{
|
||||
am=model.am,
|
||||
fee=model.fee,
|
||||
dis=model.dis,
|
||||
CODID=model.CODID,
|
||||
InvoiceID=invoiceID,
|
||||
|
||||
}));
|
||||
}
|
||||
else return BadRequest(new List<string> { "خطایی رخ داده" });
|
||||
|
||||
|
||||
}
|
||||
[HttpPost("UpdateItem/{invoiceID}")]
|
||||
public async Task<ActionResult> UpdateItem([FromRoute] int invoiceID, [FromBody] InvoiceItemDTO 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, invoiceID, model, eActionValidation.update));
|
||||
if (!resultValidationmodel.IsValid)
|
||||
return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList());
|
||||
|
||||
//-----Get invoice
|
||||
Invoice invoice = await _servInvoice.GetInvoiceByInvoiceID(user.RolUsers.First().CompanyID, invoiceID);
|
||||
if (invoice == null)
|
||||
return BadRequest(new List<string> { "invoice notFound..." });
|
||||
|
||||
|
||||
var invoiceitem=await _servInvoiceItem.Getinvoiceitem(user.RolUsers.First().CompanyID, invoiceID, model.ID.Value);
|
||||
if (invoiceitem == null)
|
||||
return BadRequest(new List<string> { "invoice Item notFound..." });
|
||||
|
||||
invoice.LastChangeUserID = Convert.ToInt32(UserID);
|
||||
|
||||
invoiceitem.am = model.am;
|
||||
invoiceitem.fee = model.fee;
|
||||
invoiceitem.dis = model.dis;
|
||||
// invoiceitem.CODID = model.CODID;
|
||||
|
||||
if (await _servInvoice.UpdateInvoice(invoice))
|
||||
return Ok(await _servInvoiceItem.Update(invoiceitem));
|
||||
|
||||
else return BadRequest(new List<string> { "خطایی رخ داده" });
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -44,6 +44,8 @@ builder.Services.AddScoped<AddOrCodValidation>();
|
||||
builder.Services.AddScoped<ServCOD>();
|
||||
builder.Services.AddScoped<servInvoice>();
|
||||
builder.Services.AddScoped<AddOrUpdateInvoiceValidation>();
|
||||
builder.Services.AddScoped<AUInvoiceItemValidation>();
|
||||
builder.Services.AddScoped<servInvoiceItem>();
|
||||
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));
|
||||
|
||||
string origins = "OriginTaxPayer";
|
||||
|
@@ -80,7 +80,7 @@ namespace Back.Services
|
||||
return await _CODRepo
|
||||
.Get(w => w.ID == CodID && w.CompanyID == CompanyID && !w.IsDeleted).FirstOrDefaultAsync();
|
||||
}
|
||||
public async Task<bool> ExistCodByCustomerID(int CodID, int CompanyID)
|
||||
public async Task<bool> ExistCodByCompanyID(int CodID, int CompanyID)
|
||||
{
|
||||
return await _CODRepo
|
||||
.Get(w => w.ID == CodID && w.CompanyID == CompanyID && !w.IsDeleted).AnyAsync();
|
||||
|
32
Back/Services/servInvoiceItem.cs
Normal file
32
Back/Services/servInvoiceItem.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Back.Data.Contracts;
|
||||
using Back.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Back.Services
|
||||
{
|
||||
public class servInvoiceItem
|
||||
{
|
||||
private readonly IAsyncRepository<InvoiceItem> _invoiceitemRepo;
|
||||
public servInvoiceItem(IAsyncRepository<InvoiceItem> invoiceitemRepo)
|
||||
{
|
||||
_invoiceitemRepo = invoiceitemRepo;
|
||||
}
|
||||
public async Task<bool> Add(InvoiceItem item)
|
||||
{
|
||||
return await _invoiceitemRepo.AddBoolResultAsync(item);
|
||||
}
|
||||
public async Task<bool> Update(InvoiceItem item)
|
||||
{
|
||||
return await _invoiceitemRepo.UpdateAsync(item);
|
||||
}
|
||||
public async Task<bool> Exist(int companyID,int invoiceID,int invoiceitemID)
|
||||
{
|
||||
return await _invoiceitemRepo.Get(w => w.InvoiceID == invoiceID && w.ID == invoiceitemID && w.invoice.CompanyID == companyID).AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<InvoiceItem> Getinvoiceitem(int companyID, int invoiceID, int invoiceitemID)
|
||||
{
|
||||
return await _invoiceitemRepo.Get(w => w.InvoiceID == invoiceID && w.ID == invoiceitemID && w.invoice.CompanyID == companyID).FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,7 +20,7 @@ namespace Back.Services
|
||||
}
|
||||
public async Task<bool> ExistSuccessfulorSendorpendingInvoice(Invoice invoice)
|
||||
{
|
||||
return _repoSentTax.Get(w => w.InvoiceType == invoice.invoiceType && w.InvoiceID == invoice.ID &&
|
||||
return _repoSentTax.Get(w => /*w.InvoiceType == invoice.invoiceType &&*/ w.InvoiceID == invoice.ID &&
|
||||
(w.SentStatus == SentStatus.Successful || w.SentStatus == SentStatus.Send || w.SentStatus == SentStatus.pending)).Any();
|
||||
}
|
||||
public async Task<bool> CheckingTheCompanyKeyInformation(int CompanyID, string UniqeMemory, string PrivateKey, string EconomicCode)
|
||||
|
78
Back/Validations/AUInvoiceItemValidation.cs
Normal file
78
Back/Validations/AUInvoiceItemValidation.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Back.Common;
|
||||
using Back.Services;
|
||||
using FluentValidation;
|
||||
using Shared.DTOs;
|
||||
|
||||
namespace Back.Validations
|
||||
{
|
||||
// com ,invoice,model,action
|
||||
public class AUInvoiceItemValidation : AbstractValidator<Tuple<int,int, InvoiceItemDTO, eActionValidation>>
|
||||
{
|
||||
public AUInvoiceItemValidation(servInvoice servInvoice,ServCOD servCOD, servTaxPayer servTaxPayer, servInvoiceItem servInvoiceItem)
|
||||
{
|
||||
When(m => m.Item4 == eActionValidation.update, () =>
|
||||
{
|
||||
RuleFor(r => r)
|
||||
.Custom((model, context) =>
|
||||
{
|
||||
if (!model.Item3.ID.HasValue)
|
||||
context.AddFailure("شناسه در حالت ویرایش نمی تواند خالی باشد");
|
||||
if (!servInvoiceItem.Exist(model.Item1,model.Item2,model.Item3.ID.Value).Result)
|
||||
context.AddFailure("شناسه یافت نشد");
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
RuleFor(r => r)
|
||||
.Custom( (model, context) =>
|
||||
{
|
||||
if (model.Item3.CODID != null && model.Item3.CODID > 0)
|
||||
{
|
||||
if (! servCOD.ExistCodByCompanyID(model.Item3.CODID, model.Item1).Result)
|
||||
context.AddFailure("کالا یافت نشد");
|
||||
}
|
||||
|
||||
else 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 ( servTaxPayer.ExistSuccessfulorSendorpendingInvoice(invoice).Result)
|
||||
context.AddFailure("این صورتحساب به سازمان ارسال شده"+'\n'+
|
||||
"برای تغییر ،صورتحساب را ابطال/اصلاح یا برگشت بزنید");
|
||||
}
|
||||
}
|
||||
|
||||
else context.AddFailure("صورتحساب صحیح نمی باشد");
|
||||
|
||||
});
|
||||
|
||||
RuleFor(r => r.Item3.am)
|
||||
.NotEmpty().WithMessage("تعداد مشخص نشده")
|
||||
.NotNull().WithMessage("تعداد مشخص نشده");
|
||||
|
||||
RuleFor(r => r.Item3.fee)
|
||||
.NotEmpty().WithMessage("مبلغ واحد مشخص نشده")
|
||||
.NotNull().WithMessage("مبلغ واحد مشخص نشده");
|
||||
|
||||
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("مبلغ تخفیف نمی تواند از (تعداد * مبلغ واحد) بیشتر باشد");
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -32,7 +32,7 @@ namespace Back.Validations
|
||||
else
|
||||
{
|
||||
var customerid = model.Item2.ID.Value;
|
||||
if (!servCod.ExistCodByCustomerID(customerid, companyid).Result)
|
||||
if (!servCod.ExistCodByCompanyID(customerid, companyid).Result)
|
||||
context.AddFailure("کالا با این شناسه یافت نشد");
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user