2024-06-01 12:58:04 +03:30
|
|
|
|
using Back.Data.Models;
|
|
|
|
|
using Back.Services;
|
2024-05-31 00:24:45 +03:30
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-05-31 00:59:38 +03:30
|
|
|
|
using Shared.DTOs;
|
2024-06-08 17:13:12 +03:30
|
|
|
|
using static Shared.DTOs._TaxPayer;
|
2024-05-31 00:24:45 +03:30
|
|
|
|
|
|
|
|
|
namespace Back.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class TaxPayerController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly servTaxPayer _servTaxPayer;
|
2024-05-31 00:59:38 +03:30
|
|
|
|
private readonly servUser _servUser;
|
|
|
|
|
public TaxPayerController(servTaxPayer servTaxPayer, servUser servUser)
|
2024-05-31 00:24:45 +03:30
|
|
|
|
{
|
|
|
|
|
_servTaxPayer = servTaxPayer;
|
2024-05-31 00:59:38 +03:30
|
|
|
|
_servUser = servUser;
|
|
|
|
|
}
|
|
|
|
|
[HttpGet("GetInvoice/{ID}")]
|
2024-06-01 12:58:04 +03:30
|
|
|
|
public async Task<ActionResult<_TaxPayer.Atemplatefield?>> Get(int ID)
|
2024-05-31 00:59:38 +03:30
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
2024-06-01 12:58:04 +03:30
|
|
|
|
if (!result.PatternID.HasValue)
|
|
|
|
|
return BadRequest(new List<string> { "ابتدا برای این صورتحساب الگو در نظر بگیرید" });
|
|
|
|
|
|
|
|
|
|
if (result.invoiceType == InvoiceType.Bidding)
|
|
|
|
|
return BadRequest(new List<string> { "صورتحساب در وضعیت پیش نویس نمیتواند ارسال شود" });
|
|
|
|
|
|
2024-05-31 00:59:38 +03:30
|
|
|
|
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> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع به سامانه مودیان ارسال شده باشد" });
|
|
|
|
|
|
2024-06-01 12:58:04 +03:30
|
|
|
|
|
2024-05-31 00:59:38 +03:30
|
|
|
|
|
2024-06-01 12:58:04 +03:30
|
|
|
|
return Ok(await _servTaxPayer.GetFildInvoiceForPreparation(result));
|
2024-05-31 00:59:38 +03:30
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 00:24:45 +03:30
|
|
|
|
}
|
2024-06-08 17:13:12 +03:30
|
|
|
|
[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));
|
|
|
|
|
}
|
2024-05-31 00:24:45 +03:30
|
|
|
|
}
|
|
|
|
|
}
|