Files
moadiran/Back/Controllers/TaxPayerController.cs

627 lines
31 KiB
C#
Raw Normal View History

2024-06-09 17:23:57 +03:30
using Back.Common;
using Back.Data.Models;
2024-06-01 12:58:04 +03:30
using Back.Services;
2024-06-09 17:23:57 +03:30
using Microsoft.AspNetCore.Authorization;
2024-05-31 00:24:45 +03:30
using Microsoft.AspNetCore.Http;
2024-06-10 17:26:31 +03:30
using Microsoft.AspNetCore.Http.HttpResults;
2024-05-31 00:24:45 +03:30
using Microsoft.AspNetCore.Mvc;
2024-06-09 17:23:57 +03:30
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.Cmp;
2024-06-10 17:26:31 +03:30
using Org.BouncyCastle.Ocsp;
2024-08-15 19:15:51 +03:30
using Org.BouncyCastle.Utilities;
2024-05-31 00:59:38 +03:30
using Shared.DTOs;
2024-06-09 17:23:57 +03:30
using Shared.DTOs.Serch;
using System;
using System.Security.Cryptography;
using TaxCollectData.Library.Dto.Content;
2024-07-08 16:10:06 +03:30
using TaxCollectData.Library.Dto.Transfer;
2024-06-08 17:13:12 +03:30
using static Shared.DTOs._TaxPayer;
2024-06-09 17:23:57 +03:30
using static System.Collections.Specialized.BitVector32;
2024-05-31 00:24:45 +03:30
namespace Back.Controllers
{
[Route("api/[controller]")]
2024-06-09 17:23:57 +03:30
[Authorize]
2024-05-31 00:24:45 +03:30
[ApiController]
public class TaxPayerController : ControllerBase
{
private readonly servTaxPayer _servTaxPayer;
2024-05-31 00:59:38 +03:30
private readonly servUser _servUser;
2024-06-09 17:23:57 +03:30
private readonly ActionTaxPayer _actionTaxPayer;
public TaxPayerController(servTaxPayer servTaxPayer, servUser servUser, ActionTaxPayer actionTaxPayer)
2024-05-31 00:24:45 +03:30
{
2024-06-09 17:23:57 +03:30
_servTaxPayer = servTaxPayer;
2024-05-31 00:59:38 +03:30
_servUser = servUser;
2024-06-09 17:23:57 +03:30
_actionTaxPayer = actionTaxPayer;
2024-05-31 00:59:38 +03:30
}
[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);
2024-06-09 17:23:57 +03:30
if (result == null)
return BadRequest(new List<string> { "صورتحساب یافت نشد" });
2024-05-31 00:59:38 +03:30
else
{
2024-07-08 22:51:59 +03:30
if (!result.PatternID.HasValue || result.PatternID == 0)
2024-06-01 12:58:04 +03:30
return BadRequest(new List<string> { "ابتدا برای این صورتحساب الگو در نظر بگیرید" });
2024-07-20 15:52:29 +03:30
//if (result.invoiceType == InvoiceType.Bidding)
// return BadRequest(new List<string> { "صورتحساب در وضعیت پیش نویس نمیتواند ارسال شود" });
2024-06-01 12:58:04 +03:30
2024-07-20 15:52:29 +03:30
//if (await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result))
// return BadRequest(new List<string> { "این صورتحساب قبلا به سازمان ارسال شده" });
2024-05-31 00:59:38 +03:30
2024-07-20 15:52:29 +03:30
//if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair)
// && !result.BillReference.HasValue)
// return BadRequest(new List<string> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع وجود داشته باشد" });
2024-05-31 00:59:38 +03:30
2024-06-09 17:23:57 +03:30
2024-07-20 15:52:29 +03:30
//if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair)
// && !await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result.invoice))
// return BadRequest(new List<string> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع به سامانه مودیان ارسال شده باشد" });
2024-05-31 00:59:38 +03:30
2024-06-09 17:23:57 +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")]
2024-10-19 18:30:02 +03:30
public async Task<ActionResult<Shared.DTOs._TaxPayer.Atemplatefield?>> PreparationInvoiceBeforeSending([FromBody] Atemplatefield item)
2024-07-22 22:29:28 +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, item.header.ID);
if (result == null)
return BadRequest(new List<string> { "صورتحساب یافت نشد" });
else
{
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.PreparationInvoiceBeforeSending(item, result));
}
[HttpPost("UpdateInvoice")]
public async Task<ActionResult<bool>> UpdateInvoice([FromBody] Atemplatefield item)
2024-06-08 17:13:12 +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, item.header.ID);
if (result == null)
return BadRequest(new List<string> { "صورتحساب یافت نشد" });
2024-07-20 17:34:28 +03:30
//else
//{
// if (result.invoiceType == InvoiceType.Bidding)
// return BadRequest(new List<string> { "صورتحساب در وضعیت پیش نویس نمیتواند آماده ارسال شود" });
2024-07-20 15:52:29 +03:30
2024-07-22 22:29:28 +03:30
if (await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result))
return BadRequest(new List<string> { "این صورتحساب به سازمان ارسال شده"+'\n'+
"برای تغییر ،صورتحساب را ابطال/اصلاح یا برگشت بزنید" });
2024-07-20 15:52:29 +03:30
2024-07-20 17:34:28 +03:30
// if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair)
// && !result.BillReference.HasValue)
// return BadRequest(new List<string> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع وجود داشته باشد" });
2024-07-20 15:52:29 +03:30
2024-07-20 17:34:28 +03:30
// if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair)
// && !await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result.invoice))
// return BadRequest(new List<string> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع به سامانه مودیان ارسال شده باشد" });
2024-07-20 15:52:29 +03:30
2024-07-20 17:34:28 +03:30
//}
2024-07-20 15:52:29 +03:30
2024-06-08 17:13:12 +03:30
return Ok(await _servTaxPayer.PreparationInvoiceBeforeSending(item, result));
}
2024-06-09 17:23:57 +03:30
[HttpGet("CheckAuth")]
public async Task<ActionResult<bool>> CheckAuth()
{
2024-07-20 12:58:17 +03:30
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
return Ok(await _actionTaxPayer.login(user.RolUsers.First().CompanyID));
// return Ok(true);
2024-06-09 17:23:57 +03:30
return BadRequest();
}
[HttpGet("SendInvoice/{InvoiceID}")]
public async Task<ActionResult<bool>> SendInvoice(int InvoiceID)
2024-06-09 10:03:30 +03:30
{
2024-11-29 18:52:58 +03:30
//return BadRequest(new List<string> { "در حال حاضر سامانه مودیان در دسترس نمی باشد" });
2024-06-09 10:03:30 +03:30
2024-06-09 17:23:57 +03:30
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
2024-07-20 12:58:17 +03:30
if (!await _actionTaxPayer.login(user.RolUsers.First().CompanyID))
return BadRequest(new List<string> { "خطا در احراز هویت سازمان مالیاتی" });
2024-06-09 17:23:57 +03:30
var result = await _servTaxPayer.GetInvoice(user.RolUsers.First().CompanyID, InvoiceID);
if (result == null)
return BadRequest(new List<string> { "صورتحساب یافت نشد" });
2024-06-09 10:03:30 +03:30
2024-06-09 17:23:57 +03:30
else
2024-06-09 10:03:30 +03:30
{
2024-06-09 17:23:57 +03:30
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> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع به سامانه مودیان ارسال شده باشد" });
2024-12-13 16:04:57 +03:30
if (result.invoiceType == InvoiceType.Cancellation && string.IsNullOrEmpty(result.taxid))
{
return BadRequest(new List<string> { "صورتحساب در وضعیت ابطالی باید صورتحساب مرجع آن به سامانه مودیان ارسال شده باشد" });
}
2024-06-09 17:23:57 +03:30
#region Inital Send
InvoiceHeaderDto header = new InvoiceHeaderDto();
2024-12-10 17:17:17 +03:30
PreparationHeaderTaxInvoice preparation = new PreparationHeaderTaxInvoice(result, _actionTaxPayer);
2024-08-15 19:15:51 +03:30
int level = result.pattern.ID;
//header
2024-06-09 17:23:57 +03:30
#region header
2024-08-15 19:15:51 +03:30
header = new InvoiceHeaderDto
{
//شماره منحصر به فرد مالیاتی
2024-12-10 17:17:17 +03:30
Taxid = preparation.Taxid,
2024-08-15 19:15:51 +03:30
//زمان صدور
2024-12-10 17:17:17 +03:30
Indatim = preparation.Indatim,
2024-08-15 19:15:51 +03:30
//زمان ایجاد
2024-12-10 17:17:17 +03:30
Indati2m = preparation.Indati2m,
2024-08-15 19:15:51 +03:30
// صورتحساب نوع *
2024-12-10 17:17:17 +03:30
Inty = preparation.Inty,
2024-08-15 19:15:51 +03:30
//سریال صورت حساب
2024-12-10 17:17:17 +03:30
Inno = preparation.Inno,
2024-08-15 19:15:51 +03:30
//شماره منحصر به فرد مالیاتی صورتحساب مرجع
2024-12-10 17:17:17 +03:30
Irtaxid = preparation.Irtaxid,
2024-08-15 19:15:51 +03:30
//الگوی صورتحساب *
2024-12-10 17:17:17 +03:30
Inp = preparation.Inp,
2024-08-15 19:15:51 +03:30
//موضوع صورتحساب *
2024-12-10 17:17:17 +03:30
Ins = preparation.Ins,
2024-08-15 19:15:51 +03:30
//شماره اقتصادی فروشنده به جاش شناسه ملی داده شد
2024-12-10 17:17:17 +03:30
Tins = preparation.Tins,
2024-08-15 19:15:51 +03:30
//نوع شخص خریدار
2024-12-10 17:17:17 +03:30
Tob = preparation.Tob,
2024-08-15 19:15:51 +03:30
//شماره/شناسه ملی/شناسه مشارکت مدنی / کد فراگیر
2024-12-10 17:17:17 +03:30
Bid = preparation.Bid,
2024-08-15 19:15:51 +03:30
//شماره اقتصادی خریدار
2024-12-10 17:17:17 +03:30
Tinb = preparation.Tinb,
2024-08-15 19:15:51 +03:30
//کد شعبه فروشنده
2024-12-10 17:17:17 +03:30
Sbc = preparation.Sbc,
2024-08-15 19:15:51 +03:30
//کد پستی خریدار
2024-12-10 17:17:17 +03:30
Bpc = preparation.Bpc,
2024-08-15 19:15:51 +03:30
//کد شعبه خریدار
2024-12-10 17:17:17 +03:30
Bbc = preparation.Bbc,
2024-08-15 19:15:51 +03:30
//نوع پرواز
2024-12-10 17:17:17 +03:30
Ft = preparation.Ft,
2024-08-15 19:15:51 +03:30
//شماره گذرنامه خریدار
2024-12-10 17:17:17 +03:30
Bpn = preparation.Bpn,
2024-08-15 19:15:51 +03:30
//شماره پروانه گمرکی
2024-12-10 17:17:17 +03:30
Scln = preparation.Scln,
2024-08-15 19:15:51 +03:30
//کد گمرک محل اظهار فروشنده
2024-12-10 17:17:17 +03:30
Scc = preparation.Scc,
2024-08-15 19:15:51 +03:30
//شماره کدتاژ اظهارنامه گمرکی
2024-12-10 17:17:17 +03:30
Cdcn = preparation.Cdcn,
2024-08-15 19:15:51 +03:30
//تاریخ کوتاژ اظهارنامه گمرکی
2024-12-10 17:17:17 +03:30
Cdcd = preparation.Cdcd,
2024-08-15 19:15:51 +03:30
//شناسه یکتای ثبت قزارداد فروشنده
2024-12-10 17:17:17 +03:30
Crn = preparation.Crn,
2024-08-15 19:15:51 +03:30
//شماره اشتراک/شناسه قبض بهره بردار
2024-12-10 17:17:17 +03:30
Billid = preparation.Billid,
2024-08-15 19:15:51 +03:30
//مجموع مبلغ قبل از کسر تخفیف
2024-12-10 17:17:17 +03:30
Tprdis = preparation.Tprdis,
2024-08-15 19:15:51 +03:30
//مجموع تخفیفات
2024-12-10 17:17:17 +03:30
Tdis = preparation.Tdis,
2024-08-15 19:15:51 +03:30
// مجموع مبلغ پس از کسر تخفیف
2024-12-10 17:17:17 +03:30
Tadis = preparation.Tadis,
2024-08-15 19:15:51 +03:30
//مجموع مالیات بر ارزش افزوده
2024-12-10 17:17:17 +03:30
Tvam = preparation.Tvam,
2024-08-15 19:15:51 +03:30
// مجموع سایر مالیات، عوارض و وجوه قانونی
2024-12-10 17:17:17 +03:30
Todam = preparation.Todam,
2024-08-15 19:15:51 +03:30
//صورتحساب مجموع
2024-12-10 17:17:17 +03:30
Tbill = preparation.Tbill,
2024-08-15 19:15:51 +03:30
//مجموع وزن خالض
2024-12-10 17:17:17 +03:30
Tonw = preparation.Tonw,
2024-08-15 19:15:51 +03:30
//مجموع ارزش ریالی
2024-12-10 17:17:17 +03:30
Torv = preparation.Torv,
2024-08-15 19:15:51 +03:30
//مجموع ارزش ارزی
2024-12-10 17:17:17 +03:30
Tocv = preparation.Tocv,
2024-08-15 19:15:51 +03:30
// تسویه روش
2024-12-10 17:17:17 +03:30
Setm = preparation.Setm,
2024-08-15 19:15:51 +03:30
//نقدی پرداختی مبلغ
2024-12-10 17:17:17 +03:30
Cap = preparation.Cap,
2024-08-15 19:15:51 +03:30
//پرداختی نسیه
2024-12-10 17:17:17 +03:30
Insp = preparation.Insp,
2024-08-15 19:15:51 +03:30
//مجموع سهم مالیات بر ارزش افزوده از پرداخت
2024-12-10 17:17:17 +03:30
Tvop = preparation.Tvop,
2024-08-15 19:15:51 +03:30
//مالیات موضوع 17
2024-12-10 17:17:17 +03:30
Tax17 = preparation.Tax17,
2024-08-15 19:15:51 +03:30
//شماره اقتصادی آژانس
2024-12-10 17:17:17 +03:30
Tinc = preparation.Tinc,
//تاریخ اعلامیه فروش
Asd=null,
//شماره اعلامیه فروش
Asn = null,
//شماره ناوگان
Cno=null,
//شهر مقصد
Dci = null,
//کشور مقصد
Dco = null,
//کد ملی/ کد فراگیر اتباع غیر ایرانی راننده) در حمل و نقل جاده ای(
Did = null,
//شماره بارنامه
Lno = null,
//شماره بارنامه مرجع
Lrno = null,
//نوع بارنامه/ نوع حمل
Lt = null,
//شهر مبدا
Oci = null,
//کشور مبدا
Ocu = null,
//شناسه ملی/ شماره ملی/ شناسه مشارکت مدنی/ کد فراگیر اتباع غیر ایرانی گیرنده
Rid = null,
//کالاهای حمل شده
Sg = new List<ShippingGoodDto>(),
//شناسه ملی/ شماره ملی/ شناسه مشارکت مدنی / کد فراگیر اتباع غیر ایرانی فرستنده
Tid =null
2024-08-15 19:15:51 +03:30
};
2024-06-09 17:23:57 +03:30
#endregion header
2024-08-15 19:15:51 +03:30
//body
2024-06-09 17:23:57 +03:30
List<InvoiceBodyDto> InvoiceBody = new List<InvoiceBodyDto>();
foreach (var bitem in result.invoiceDetails)
{
2024-06-10 17:26:31 +03:30
InvoiceBodyDto item = new InvoiceBodyDto();
2024-12-10 17:17:17 +03:30
PreparationBodyTaxInvoice preparationBody = new PreparationBodyTaxInvoice(bitem, level);
2024-06-09 17:23:57 +03:30
#region body
2024-08-15 19:15:51 +03:30
2024-06-09 17:23:57 +03:30
item = new InvoiceBodyDto
{
//شناسه کالا / خدمت
2024-12-10 17:17:17 +03:30
Sstid = preparationBody.Sstid,
2024-06-09 17:23:57 +03:30
//شرح کاال/خدمت
2024-12-10 17:17:17 +03:30
Sstt = preparationBody.Sstt,
2024-06-09 17:23:57 +03:30
// تعداد
2024-12-10 17:17:17 +03:30
Am = preparationBody.Am,
2024-08-07 16:31:55 +03:30
//واحد اندازه گیری
2024-12-10 17:17:17 +03:30
Mu = preparationBody.Mu,
2024-08-15 19:15:51 +03:30
//وزن خالص
2024-12-10 17:17:17 +03:30
Nw= preparationBody.Nw,
2024-06-09 17:23:57 +03:30
// مبلغ واحد
2024-12-10 17:17:17 +03:30
Fee = preparationBody.Fee,
2024-08-07 16:31:55 +03:30
//میزان ارز
2024-12-10 17:17:17 +03:30
Cfee = preparationBody.Cfee ,
2024-08-07 16:31:55 +03:30
//نوع ارز
2024-12-10 17:17:17 +03:30
Cut = preparationBody.Cut,
2024-08-07 16:31:55 +03:30
//نرخ برابری ارز با ریال
2024-12-10 17:17:17 +03:30
Exr = preparationBody.Exr,
2024-08-15 19:15:51 +03:30
// ارزش ریالی کاا
2024-12-10 17:17:17 +03:30
Ssrv= preparationBody.Ssrv,
2024-08-15 19:15:51 +03:30
// ارزش ارزی کاا
2024-12-10 17:17:17 +03:30
Sscv= preparationBody.Sscv,
2024-06-09 17:23:57 +03:30
//مبلغ قبل از تخفیف
2024-12-10 17:17:17 +03:30
Prdis = preparationBody.Prdis,
2024-06-09 17:23:57 +03:30
//مبلغ تخفیف
2024-12-10 17:17:17 +03:30
Dis = preparationBody.Dis,
2024-06-09 17:23:57 +03:30
//مبلغ بعد از تخفیف
2024-12-10 17:17:17 +03:30
Adis = preparationBody.Adis,
2024-06-09 17:23:57 +03:30
//نرخ مالیات بر ارزش افزوده
2024-12-10 17:17:17 +03:30
Vra = preparationBody.Vra,
2024-06-09 17:23:57 +03:30
//مبلغ مالیات بر ارزش افزوده
2024-12-10 17:17:17 +03:30
Vam = preparationBody.Vam,
2024-08-07 16:31:55 +03:30
//موضوع سایر مالیات و عوارض
2024-12-10 17:17:17 +03:30
Odt = preparationBody.Odt,
2024-08-07 16:31:55 +03:30
//نرخ سایر مالیات و عوارض
2024-12-10 17:17:17 +03:30
Odr = preparationBody.Odr,
2024-08-07 16:31:55 +03:30
//مبلغ سایر مالیات و عوارض
2024-12-10 17:17:17 +03:30
Odam = preparationBody.Odam,
2024-08-07 16:31:55 +03:30
//موضوع سایر وجوه قانونی
2024-12-10 17:17:17 +03:30
Olt = preparationBody.Olt,
2024-08-07 16:31:55 +03:30
//نرخ سایر وجوه قانونی
2024-12-10 17:17:17 +03:30
Olr = preparationBody.Olr,
2024-08-07 16:31:55 +03:30
//مبلغ سایر وجوه قانونی
2024-12-10 17:17:17 +03:30
Olam = preparationBody.Olam,
2024-08-15 19:15:51 +03:30
//اجرت ساخت
2024-12-10 17:17:17 +03:30
Consfee = preparationBody.Consfee,
2024-08-15 19:15:51 +03:30
// سود فروشنده
2024-12-10 17:17:17 +03:30
Spro= preparationBody.Spro,
2024-08-15 19:15:51 +03:30
//حقالعمل
2024-12-10 17:17:17 +03:30
Bros= preparationBody.Bros,
2024-08-15 19:15:51 +03:30
//جمع کل اجرت، حقالعمل و سود
2024-12-10 17:17:17 +03:30
Tcpbs= preparationBody.Tcpbs,
2024-08-07 16:31:55 +03:30
//سهم نقدی از پرداخت
2024-12-10 17:17:17 +03:30
Cop = preparationBody.Cop,
2024-08-07 16:31:55 +03:30
//سهم مالیات بر لرزش افزوده از پرداخت
2024-12-10 17:17:17 +03:30
Vop = preparationBody.Vop,
2024-08-07 16:31:55 +03:30
//شناسه یکتای ثبت قرارداد حق العمل کاری
2024-12-10 17:17:17 +03:30
Bsrn = preparationBody.Bsrn,
2024-08-07 16:31:55 +03:30
// مبلغ کل کالا / خدمت
2024-12-10 17:17:17 +03:30
Tsstam = preparationBody.Tsstam,
2024-08-15 19:15:51 +03:30
//عیار
2024-12-10 17:17:17 +03:30
Cui = preparationBody.Cui,
// نرخ خرید ارز
Cpr = preparationBody.Cpr,
//ماخذ مالیات بر ارزش افزوده در الگوی فروش ارز
Sovat = preparationBody.Sovat
2024-06-09 17:23:57 +03:30
};
#endregion
InvoiceBody.Add(item);
}
2024-07-08 22:51:59 +03:30
2024-08-15 19:15:51 +03:30
//Pay
List<PaymentDto> InvoicePay = new List<PaymentDto>();
2024-08-28 00:29:35 +03:30
if (result.setm==1 || result.setm == 3)
2024-08-15 19:15:51 +03:30
{
2024-08-28 00:29:35 +03:30
if (level != 10)
foreach (var pitem in result.payments)
2024-08-15 19:15:51 +03:30
{
2024-10-20 17:10:12 +03:30
2024-08-28 00:29:35 +03:30
PaymentDto payment = new PaymentDto();
payment = new PaymentDto
{
Iinn = pitem.iinn,
Acn = pitem.acn,
Trmn = pitem.trmn,
Pmt = pitem.pmt,
Trn = pitem.trn,
Pcn = pitem.pcn,
Pid = pitem.pid,
Pdt = pitem.pdt,
Pv = pitem.pv,
};
InvoicePay.Add(payment);
}
2024-08-15 19:15:51 +03:30
}
2024-08-28 00:29:35 +03:30
2024-08-15 19:15:51 +03:30
var responseModel = await _actionTaxPayer.SendInvoice(user.RolUsers.First().CompanyID, header, InvoiceBody, InvoicePay);
2024-06-09 17:23:57 +03:30
if (responseModel == null)
{
return BadRequest(new List<string> { "خطا در ورود به سامانه مودیان" });
}
else if (responseModel.Status == 200 && (responseModel.Body.Errors == null || responseModel.Body.Errors.Count == 0))
{
foreach (var item in responseModel.Body.Result)
{
2024-08-06 17:24:25 +03:30
2024-07-08 22:51:59 +03:30
2024-06-09 17:23:57 +03:30
var ressenttax = new SentTax
{
InvoiceID = result.ID,
Date = DateTime.Now.ConvertMiladiToShamsi(),
Time = $"{DateTime.Now.Hour}:{DateTime.Now.Minute}:{DateTime.Now.Second}",
InvoiceType = result.invoiceType,
ReferenceNumber = item.ReferenceNumber,
uId = item.Uid,
SentStatus = SentStatus.Send,
2024-08-06 17:24:25 +03:30
InvoiceModel = JsonConvert.SerializeObject(result, Formatting.Indented, new JsonSerializerSettings
{
2024-07-09 23:04:19 +03:30
PreserveReferencesHandling = PreserveReferencesHandling.Objects
}),
2024-06-09 17:23:57 +03:30
ResponseModel = JsonConvert.SerializeObject(responseModel)
2024-08-06 17:24:25 +03:30
2024-06-09 17:23:57 +03:30
};
2024-06-10 17:26:31 +03:30
await _servTaxPayer.AddSentTax(ressenttax);
2024-06-09 17:23:57 +03:30
}
result.taxid = header.Taxid;
result.irtaxid = header.Irtaxid;
2024-06-10 17:26:31 +03:30
return Ok(await _servTaxPayer.UpdateInvoice(result));
2024-06-09 17:23:57 +03:30
}
else
{
string errors = "";
foreach (var item in responseModel.Body.Errors)
2024-06-10 17:26:31 +03:30
errors += '\n' + $"{item.ErrorCode}:{item.Detail}";
2024-06-09 17:23:57 +03:30
return BadRequest(new List<string> { errors });
}
#endregion
2024-06-10 17:26:31 +03:30
2024-06-09 17:23:57 +03:30
}
}
[HttpPost("GetAllSentTax")]
public async Task<ActionResult<PagingDto<SentTaxDto>>> GetSentTax([FromBody] ItemSerchGetSentTax item)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
2024-06-10 17:26:31 +03:30
return Ok(await _servTaxPayer.GetSentTax(user.RolUsers.First().CompanyID, item));
}
[HttpGet("GetResult/{ID}")]
public async Task<ActionResult<DataInSendTaxDto>> GetResultByUid(int ID)
{
try
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
var item = await _servTaxPayer.GetSentTax(user.RolUsers.First().CompanyID, ID);
if (item == null)
return BadRequest(new List<string> { "یافت نشد" });
if (string.IsNullOrEmpty(item.uId))
return BadRequest(new List<string> { "کد پیگیری یافت نشد" });
2024-07-20 12:58:17 +03:30
if (!await _actionTaxPayer.login(user.RolUsers.First().CompanyID))
return BadRequest(new List<string> { "خطا در احراز هویت سازمان مالیاتی" });
2024-06-10 17:26:31 +03:30
DataInSendTaxDto desData = new DataInSendTaxDto();
2024-08-06 17:24:25 +03:30
2024-07-20 21:27:09 +03:30
if (item.SentStatus == SentStatus.Unsuccessful && !string.IsNullOrEmpty(item.ErrorsModel))
{
List<MessageInSendTaxDto> inquiryerrorResult = JsonConvert.DeserializeObject<List<MessageInSendTaxDto>>(item.ErrorsModel);
InquiryResultModel inquiryResult = JsonConvert.DeserializeObject<InquiryResultModel>(item.InquiryResultModel);
if (inquiryResult.Data != null)
{
2024-08-06 17:24:25 +03:30
2024-07-20 21:27:09 +03:30
desData = new DataInSendTaxDto();
desData.SentStatus = SentStatus.Unsuccessful;
desData.error = inquiryerrorResult;
2024-08-06 17:24:25 +03:30
2024-07-20 21:27:09 +03:30
}
return Ok(desData);
}
else if (item.SentStatus == SentStatus.Send
2024-06-10 17:26:31 +03:30
|| item.SentStatus == SentStatus.pending
2024-07-09 23:04:19 +03:30
|| item.SentStatus == SentStatus.IN_PROGRESS
2024-07-20 21:27:09 +03:30
|| item.SentStatus == SentStatus.Unsuccessful)
2024-06-10 17:26:31 +03:30
{
2024-07-08 22:51:59 +03:30
2024-07-09 23:04:19 +03:30
//ta imja
2024-06-10 17:26:31 +03:30
var result = await _actionTaxPayer.GetResultByUid(user.RolUsers.First().CompanyID, item.uId);
if (result == null)
return BadRequest(new List<string> { "پاسخی از سازمان دریافت نشد" });
else
{
item.InquiryResultModel = JsonConvert.SerializeObject(result);
if (result.Data != null)
{
desData = JsonConvert.DeserializeObject<DataInSendTaxDto>(result.Data.ToString());
if (desData == null)
{
desData = new DataInSendTaxDto();
desData.error = JsonConvert.DeserializeObject<List<MessageInSendTaxDto>>(result.Data.ToString());
}
}
2024-07-20 21:27:09 +03:30
2024-06-10 17:26:31 +03:30
desData.SentStatus = item.SentStatus =
result.Status == "FAILED" ? SentStatus.Unsuccessful
: result.Status == "PENDING" ? SentStatus.pending
: result.Status == "SUCCESS" ? SentStatus.Successful
: result.Status == "NOT_FOUND" ? SentStatus.NOT_FOUND
: result.Status == "IN_PROGRESS" ? SentStatus.IN_PROGRESS
: SentStatus.Unknown;
2024-07-20 21:27:09 +03:30
if (item.SentStatus == SentStatus.Unsuccessful)
item.ErrorsModel = JsonConvert.SerializeObject(desData.error);
2024-06-10 17:26:31 +03:30
}
2024-07-09 23:04:19 +03:30
2024-07-20 21:27:09 +03:30
if (await _servTaxPayer.UpdateSentTax(item)) return Ok(desData);
2024-06-10 17:26:31 +03:30
2024-07-20 21:27:09 +03:30
else return BadRequest(new List<string> { "خطای در ذخیره سازی" });
}
2024-06-10 17:26:31 +03:30
return BadRequest(new List<string> { "در این وضعیت امکان پذیر نمی باشد" });
}
catch (Exception ex)
{
return BadRequest(new List<string> { "خطای ناشناخته" });
}
2024-06-09 10:03:30 +03:30
}
2024-08-08 18:20:21 +03:30
[HttpGet("GetBillTypes")]
public async Task<ActionResult<List<IdName<int>>>> GetBillTypes()
{
return Ok(await _servTaxPayer.GetBillTypes());
}
[HttpGet("GetPatterns")]
public async Task<ActionResult<List<IdName<int>>>> GetPatterns()
{
return Ok(await _servTaxPayer.GetPatterns(true));
}
2024-08-11 18:59:36 +03:30
[HttpGet("GetUnits")]
public async Task<ActionResult<List<IdName<int>>>> GetUnits()
{
return Ok(await _servTaxPayer.GetUnits());
}
2024-10-16 23:36:52 +03:30
[HttpGet("EconomicCodeInformation")]
public async Task<ActionResult<EconomicCodeModelDto>> GetEconomicCodeInformation(string item)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
if (!await _actionTaxPayer.login(user.RolUsers.First().CompanyID))
return BadRequest(new List<string> { "خطا در احراز هویت سازمان مالیاتی" });
var result=await _actionTaxPayer.GetEconomicCodeInformation(item);
if (result == null) return NotFound();
return Ok(result);
}
[HttpGet("FiscalInformation")]
public async Task<ActionResult<FiscalInformationModelDto>> GetFiscalInformation(string item)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
if (!await _actionTaxPayer.login(user.RolUsers.First().CompanyID))
return BadRequest(new List<string> { "خطا در احراز هویت سازمان مالیاتی" });
var result=await _actionTaxPayer.GetFiscalInformation(item);
if (result == null) return NotFound();
return Ok(result);
}
2024-10-22 12:31:34 +03:30
[HttpGet("CodInTaxPayerHaveBeenSentSuccessfully/{CODID}")]
public async Task<ActionResult<bool>> CodInTaxPayerHaveBeenSentSuccessfully(int CODID)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
return Ok(await _servTaxPayer.AnyCodInTaxPayerHaveBeenSentSuccessfully(CODID, user.RolUsers.First().CompanyID));
}
[HttpGet("CustomerInTaxPayerHaveBeenSentSuccessfully/{CUSID}")]
public async Task<ActionResult<bool>> CustomerInTaxPayerHaveBeenSentSuccessfully(int CUSID)
{
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
var UserID = claim.Value;
var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID));
return Ok(await _servTaxPayer.AnyCusInTaxPayerHaveBeenSentSuccessfully(CUSID, user.RolUsers.First().CompanyID));
}
2024-05-31 00:24:45 +03:30
}
}