This commit is contained in:
mmrbnjd
2024-04-30 16:40:05 +03:30
parent 319270d567
commit 827aa36860
8 changed files with 258 additions and 8 deletions

View File

@@ -1,6 +1,8 @@
using Back.Services;
using Back.Data.Models;
using Back.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Shared.DTOs;
@@ -13,17 +15,20 @@ namespace Back.Controllers
{
private readonly servCompany _servCompany;
private readonly servUser _servUser;
public CompanyController(servCompany servCompany, servUser servUser)
private readonly servTaxPayer _servTaxPayer;
public CompanyController(servCompany servCompany, servUser servUser, servTaxPayer servTaxPayer)
{
_servUser = servUser;
_servCompany = servCompany;
_servCompany = servCompany;
_servTaxPayer = servTaxPayer;
}
[HttpPost("ChangeLogo")]
public async Task<ActionResult<bool>> ChangeLogo(byte[] logo)
{
if (logo == null)
return BadRequest();
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var result = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
var company = result?.RolUsers.First().Company;
@@ -44,5 +49,49 @@ namespace Back.Controllers
await _servUser.UpdateUser(user);
return Ok(await _servCompany.AddORUpdateCompanyBoolResult(company));
}
[HttpGet("TaxPayerInfo")]
public async Task<ActionResult<TaxPayerInfoDto>> TaxPayerInfo()
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
var company = user?.RolUsers.First().Company;
return Ok(new TaxPayerInfoDto
{
EconomicCode = company.EconomicCode,
PrivateKey = company.PrivateKey ,
UniqeMemory = company.UniqeMemory ,
BranchID=company.BranchID,
});
}
[HttpPut("ChangeTaxPayerInfo")]
public async Task<ActionResult<bool>> ChangeTaxPayerInfo(TaxPayerInfoDto model)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
if (!string.IsNullOrEmpty(model.BranchID) && (model.BranchID.Length > 10 || !int.TryParse(model.BranchID, out int a)))
return BadRequest(new List<string> {"مقدار کد شعبه صحیح نمی باشد" });
if (!string.IsNullOrEmpty(model.UniqeMemory) && (model.UniqeMemory.Length !=6 ))
return BadRequest(new List<string> { "مقدار حافظه مالیاتی صحیح نمی باشد" });
var company = user?.RolUsers.First().Company;
if (await _servTaxPayer.ExistSuccessfulorSendorpendingInvoiceinCompanyID(company.ID) &&
(model.EconomicCode != company.EconomicCode || model.PrivateKey != company.PrivateKey || model.UniqeMemory != company.UniqeMemory))
return BadRequest(new List<string> { "به دلیل اینکه صورتحسابی با مشخصات کلیدی شما به سازمان مالیات ارسال شده امکان تغییر این موارد را ندارید" +
'\n' + "فیلدهای کلیدی شامل (کداقتصادی،شناسه حافظه مالیاتی،کلید خصوصی)" });
if (await _servTaxPayer.CheckingTheCompanyKeyInformation(company.ID, model.UniqeMemory, model.PrivateKey, model.EconomicCode))
return BadRequest(new List<string> { "فیلدهای کلیدی شامل (کداقتصادی،شناسه حافظه مالیاتی،کلید خصوصی)" + " برای شرکت دیگری ثبت شده است" });
company.EconomicCode = model.EconomicCode;
company.PrivateKey = model.PrivateKey;
company.UniqeMemory = model.UniqeMemory;
company.BranchID = model.BranchID;
return Ok(await _servCompany.AddORUpdateCompanyBoolResult(company));
}
}
}

View File

@@ -36,6 +36,7 @@ builder.Services.AddScoped<servNotification>();
builder.Services.AddScoped<servPermission>();
builder.Services.AddScoped<servSendMsg>();
builder.Services.AddScoped<servUser>();
builder.Services.AddScoped<servTaxPayer>();
builder.Services.AddScoped<CompanyRegistrationValidation>();
builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2"));

View File

@@ -0,0 +1,27 @@
using Back.Common.Enums;
using Back.Data.Contracts;
using Back.Data.Models;
using Microsoft.EntityFrameworkCore;
namespace Back.Services
{
public class servTaxPayer
{
private readonly IAsyncRepository<SentTax> _repoSentTax;
public servTaxPayer(IAsyncRepository<SentTax> repoSentTax)
{
_repoSentTax = repoSentTax;
}
public async Task<bool> ExistSuccessfulorSendorpendingInvoiceinCompanyID(int CompanyID)
{
return await _repoSentTax.Get(w => w.invoice.CompanyID == CompanyID && (w.SentStatus == SentStatus.Successful || w.SentStatus == SentStatus.Send || w.SentStatus == SentStatus.pending)).AnyAsync();
}
public async Task<bool> CheckingTheCompanyKeyInformation(int CompanyID, string UniqeMemory, string PrivateKey, string EconomicCode)
{
return await _repoSentTax.Get(w => (w.invoice.company.UniqeMemory == UniqeMemory || w.invoice.company.PrivateKey == PrivateKey || w.invoice.company.EconomicCode == EconomicCode)
&& (w.SentStatus == SentStatus.Successful || w.SentStatus == SentStatus.Send || w.SentStatus == SentStatus.pending)
&& w.invoice.CompanyID != CompanyID).AnyAsync();
}
}
}