90 lines
3.8 KiB
C#
90 lines
3.8 KiB
C#
using Back.Data.Models;
|
|
using Back.Services;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Shared.DTOs;
|
|
using static Shared.DTOs._TaxPayer;
|
|
|
|
namespace Back.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class TaxPayerController : ControllerBase
|
|
{
|
|
private readonly servTaxPayer _servTaxPayer;
|
|
private readonly servUser _servUser;
|
|
public TaxPayerController(servTaxPayer servTaxPayer, servUser servUser)
|
|
{
|
|
_servTaxPayer = servTaxPayer;
|
|
_servUser = servUser;
|
|
}
|
|
[HttpGet("GetInvoice/{ID}")]
|
|
public async Task<ActionResult<_TaxPayer.Atemplatefield?>> Get(int ID)
|
|
{
|
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
|
var UserID = claim.Value;
|
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
|
var result = await _servTaxPayer.GetInvoice(user.RolUsers.First().CompanyID, ID);
|
|
if (result==null)
|
|
return BadRequest(new List<string> { "صورتحساب یافت نشد"});
|
|
|
|
else
|
|
{
|
|
if (!result.PatternID.HasValue)
|
|
return BadRequest(new List<string> { "ابتدا برای این صورتحساب الگو در نظر بگیرید" });
|
|
|
|
if (result.invoiceType == InvoiceType.Bidding)
|
|
return BadRequest(new List<string> { "صورتحساب در وضعیت پیش نویس نمیتواند ارسال شود" });
|
|
|
|
if (await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result))
|
|
return BadRequest(new List<string> { "این صورتحساب قبلا به سازمان ارسال شده"});
|
|
|
|
if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair)
|
|
&& !result.BillReference.HasValue)
|
|
return BadRequest(new List<string> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع وجود داشته باشد" });
|
|
|
|
|
|
if ((result.invoiceType==InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair)
|
|
&& !await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result.invoice))
|
|
return BadRequest(new List<string> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع به سامانه مودیان ارسال شده باشد" });
|
|
|
|
|
|
|
|
return Ok(await _servTaxPayer.GetFildInvoiceForPreparation(result));
|
|
}
|
|
|
|
}
|
|
[HttpPost("PreparationInvoiceBeforeSending")]
|
|
public async Task<ActionResult<bool>> PreparationInvoiceBeforeSending([FromBody] Atemplatefield item)
|
|
{
|
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
|
var UserID = claim.Value;
|
|
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
|
|
var result = await _servTaxPayer.GetInvoice(user.RolUsers.First().CompanyID, item.header.ID);
|
|
if (result == null)
|
|
return BadRequest(new List<string> { "صورتحساب یافت نشد" });
|
|
|
|
|
|
return Ok(await _servTaxPayer.PreparationInvoiceBeforeSending(item, result));
|
|
}
|
|
[HttpPost("CheckAuth")]
|
|
public async Task<ActionResult<string>> CheckAuth([FromBody] CheckAuthDTO item)
|
|
{
|
|
|
|
if (item == null)
|
|
return BadRequest("مدل صحیح نمی باشد");
|
|
|
|
using (ActionTaxPayer action = new ActionTaxPayer(item.UniqueMemory, item.PrivateKey))
|
|
{
|
|
if (action.login())
|
|
return Ok();
|
|
}
|
|
|
|
|
|
|
|
return BadRequest();
|
|
|
|
}
|
|
}
|
|
}
|