593 lines
31 KiB
C#
593 lines
31 KiB
C#
using Back.Common;
|
|
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 Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using Org.BouncyCastle.Asn1.Cmp;
|
|
using Org.BouncyCastle.Ocsp;
|
|
using Org.BouncyCastle.Utilities;
|
|
using Shared.DTOs;
|
|
using Shared.DTOs.Serch;
|
|
using System;
|
|
using System.Security.Cryptography;
|
|
using TaxCollectData.Library.Dto.Content;
|
|
using TaxCollectData.Library.Dto.Transfer;
|
|
using static Shared.DTOs._TaxPayer;
|
|
using static System.Collections.Specialized.BitVector32;
|
|
|
|
namespace Back.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[Authorize]
|
|
[ApiController]
|
|
public class TaxPayerController : ControllerBase
|
|
{
|
|
private readonly servTaxPayer _servTaxPayer;
|
|
private readonly servUser _servUser;
|
|
private readonly ActionTaxPayer _actionTaxPayer;
|
|
public TaxPayerController(servTaxPayer servTaxPayer, servUser servUser, ActionTaxPayer actionTaxPayer)
|
|
{
|
|
_servTaxPayer = servTaxPayer;
|
|
_servUser = servUser;
|
|
_actionTaxPayer = actionTaxPayer;
|
|
}
|
|
[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 || result.PatternID == 0)
|
|
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<Shared.DTOs._TaxPayer.Atemplatefield?>> 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> { "صورتحساب یافت نشد" });
|
|
|
|
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)
|
|
{
|
|
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> { "این صورتحساب به سازمان ارسال شده"+'\n'+
|
|
"برای تغییر ،صورتحساب را ابطال/اصلاح یا برگشت بزنید" });
|
|
|
|
// 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));
|
|
}
|
|
[HttpGet("CheckAuth")]
|
|
public async Task<ActionResult<bool>> CheckAuth()
|
|
{
|
|
|
|
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);
|
|
|
|
return BadRequest();
|
|
|
|
}
|
|
[HttpGet("SendInvoice/{InvoiceID}")]
|
|
public async Task<ActionResult<bool>> SendInvoice(int InvoiceID)
|
|
{
|
|
return BadRequest(new List<string> { "در حال حاضر سامانه مودیان در دسترس نمی باشد" });
|
|
|
|
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 _servTaxPayer.GetInvoice(user.RolUsers.First().CompanyID, InvoiceID);
|
|
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> { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع به سامانه مودیان ارسال شده باشد" });
|
|
|
|
#region Inital Send
|
|
InvoiceHeaderDto header = new InvoiceHeaderDto();
|
|
|
|
|
|
|
|
int level = result.pattern.ID;
|
|
|
|
//header
|
|
#region header
|
|
header = new InvoiceHeaderDto
|
|
{
|
|
//شماره منحصر به فرد مالیاتی
|
|
Taxid = _actionTaxPayer.GenerateTaxid(result.inno, result.InvoiceDate.Replace("/", "").Trim()),
|
|
//زمان صدور
|
|
Indatim = result.indatim ?? null,
|
|
//زمان ایجاد
|
|
Indati2m = result.Indati2m ?? null,
|
|
// صورتحساب نوع *
|
|
Inty = result.inty ?? 1,
|
|
//سریال صورت حساب
|
|
Inno = string.IsNullOrEmpty(result.inno) ? null : result.inno,
|
|
//شماره منحصر به فرد مالیاتی صورتحساب مرجع
|
|
Irtaxid = result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair ? result.invoice.taxid
|
|
: result.invoiceType == InvoiceType.Cancellation ? result.taxid : null,
|
|
//الگوی صورتحساب *
|
|
Inp = result.inp ?? 1,
|
|
//موضوع صورتحساب *
|
|
Ins = result.ins ?? 1,
|
|
//شماره اقتصادی فروشنده به جاش شناسه ملی داده شد
|
|
Tins = string.IsNullOrEmpty(result.tins) ? null : result.tins,
|
|
//نوع شخص خریدار
|
|
Tob = level == 10 ? null : result.tob==5 ? 1 : result.tob==6 ? 4 : result.tob,
|
|
//شماره/شناسه ملی/شناسه مشارکت مدنی / کد فراگیر
|
|
Bid = level == 10 || string.IsNullOrEmpty(result.bid) || !string.IsNullOrEmpty(result.tinb)
|
|
|| result.tob == 1 || result.tob == 2 || result.tob == 3 || result.tob == 4 ? null : result.bid,
|
|
//شماره اقتصادی خریدار
|
|
Tinb = level == 10 || string.IsNullOrEmpty(result.tinb) || result.tob == 5 || result.tob == 6 ? null : result.tinb,
|
|
//کد شعبه فروشنده
|
|
Sbc = string.IsNullOrEmpty(result.sbc) ? null : result.sbc,
|
|
//کد پستی خریدار
|
|
Bpc = level == 10 || string.IsNullOrEmpty(result.bpc) || !string.IsNullOrEmpty(result.tinb)
|
|
|| result.tob == 1 || result.tob == 2 || result.tob == 3 || result.tob == 4 ? null : result.bpc,
|
|
//کد شعبه خریدار
|
|
Bbc = level == 10 || string.IsNullOrEmpty(result.bbc) ? null : result.bbc,
|
|
//نوع پرواز
|
|
Ft = level == 9 ? result.ft : null,
|
|
//شماره گذرنامه خریدار
|
|
Bpn = (level == 9 || level == 4) && !string.IsNullOrEmpty(result.bpn) ? result.bpn : null,
|
|
//شماره پروانه گمرکی
|
|
Scln = (level == 3 || level == 4) && !string.IsNullOrEmpty(result.scln) ? result.scln : null,
|
|
//کد گمرک محل اظهار فروشنده
|
|
Scc = (level == 3 || level == 4 || level == 10) && !string.IsNullOrEmpty(result.scc) ? result.scc : null,
|
|
//شماره کدتاژ اظهارنامه گمرکی
|
|
Cdcn = level == 10 ? result.cdcn : null,
|
|
//تاریخ کوتاژ اظهارنامه گمرکی
|
|
Cdcd = level == 10 ? result.cdcd : null,
|
|
//شناسه یکتای ثبت قزارداد فروشنده
|
|
Crn = (level == 3 || level == 4 || level == 5 || level == 6) && !string.IsNullOrEmpty(result.crn) ? result.crn : null,
|
|
//شماره اشتراک/شناسه قبض بهره بردار
|
|
Billid = level == 8 ?result.billid:null,
|
|
//مجموع مبلغ قبل از کسر تخفیف
|
|
Tprdis = level == 10 ? null : result.tprdis ?? null,
|
|
//مجموع تخفیفات
|
|
Tdis = level == 10 ? null : result.tdis ?? null,
|
|
// مجموع مبلغ پس از کسر تخفیف
|
|
Tadis = level == 10 ? null : result.tadis ?? null,
|
|
//مجموع مالیات بر ارزش افزوده
|
|
Tvam = result.tvam ?? null,
|
|
// مجموع سایر مالیات، عوارض و وجوه قانونی
|
|
Todam = result.todam ?? null,
|
|
//صورتحساب مجموع
|
|
Tbill =-10 /* result.tbill ?? null*/,
|
|
//مجموع وزن خالض
|
|
Tonw = level == 10 ? result.tonw : null,
|
|
//مجموع ارزش ریالی
|
|
Torv = level == 10 ? result.torv : null,
|
|
//مجموع ارزش ارزی
|
|
Tocv = level == 10 ? result.tocv : null,
|
|
// تسویه روش
|
|
Setm = level == 8|| level == 10|| level == 11|| level == 13 || result.setm == 0 ? null : result.setm ?? null,
|
|
//نقدی پرداختی مبلغ
|
|
Cap = level == 8 || level == 10 || level == 11 || level == 13 ?null : result.cap ?? null,
|
|
//پرداختی نسیه
|
|
Insp = level == 8 || level == 10 || level == 11 || level == 13 ? null : result.insp ?? null,
|
|
//مجموع سهم مالیات بر ارزش افزوده از پرداخت
|
|
Tvop = level == 8 || level == 10 || level == 11 || level == 13 ? null : result.tvop ?? null,
|
|
//مالیات موضوع 17
|
|
Tax17 = level == 10 || string.IsNullOrEmpty(result.seventeentax) ? null : Convert.ToDecimal(result.seventeentax),
|
|
//شماره اقتصادی آژانس
|
|
Tinc = level == 9 && !string.IsNullOrEmpty(result.tinc) ? result.tinc : null
|
|
};
|
|
#endregion header
|
|
|
|
|
|
|
|
|
|
//body
|
|
List<InvoiceBodyDto> InvoiceBody = new List<InvoiceBodyDto>();
|
|
foreach (var bitem in result.invoiceDetails)
|
|
{
|
|
InvoiceBodyDto item = new InvoiceBodyDto();
|
|
#region body
|
|
|
|
item = new InvoiceBodyDto
|
|
{
|
|
//شناسه کالا / خدمت
|
|
Sstid = bitem.sstid,
|
|
//شرح کاال/خدمت
|
|
Sstt = bitem.sstt,
|
|
// تعداد
|
|
Am = level==4 ?null: bitem.am,
|
|
//واحد اندازه گیری
|
|
Mu = level == 4 || string.IsNullOrEmpty(bitem.mu) ? null : bitem.mu,
|
|
//وزن خالص
|
|
Nw=level==10 ? bitem.nw : null,
|
|
// مبلغ واحد
|
|
Fee = level == 4 ? null : bitem.fee,
|
|
//میزان ارز
|
|
Cfee = level==8 || level==10 ?null: bitem.cfee,
|
|
//نوع ارز
|
|
Cut = level == 8 || string.IsNullOrEmpty(bitem.cut) ? null : bitem.cut,
|
|
//نرخ برابری ارز با ریال
|
|
Exr = level == 8 ?null: bitem.exr,
|
|
// ارزش ریالی کاا
|
|
Ssrv= level == 10 ?bitem.ssrv : null,
|
|
// ارزش ارزی کاا
|
|
Sscv= level == 10 ? bitem.sscv : null,
|
|
//مبلغ قبل از تخفیف
|
|
Prdis = level == 10 ? null : bitem.prdis,
|
|
//مبلغ تخفیف
|
|
Dis = level == 10 ? null : bitem.dis,
|
|
//مبلغ بعد از تخفیف
|
|
Adis = level == 10 ? null : bitem.adis,
|
|
//نرخ مالیات بر ارزش افزوده
|
|
Vra = bitem.vra,
|
|
//مبلغ مالیات بر ارزش افزوده
|
|
Vam = bitem.vam,
|
|
//موضوع سایر مالیات و عوارض
|
|
Odt = string.IsNullOrEmpty(bitem.odt) ? null : bitem.odt,
|
|
//نرخ سایر مالیات و عوارض
|
|
Odr = bitem.odr,
|
|
//مبلغ سایر مالیات و عوارض
|
|
Odam = bitem.odam,
|
|
//موضوع سایر وجوه قانونی
|
|
Olt = string.IsNullOrEmpty(bitem.olt) ? null : bitem.olt,
|
|
//نرخ سایر وجوه قانونی
|
|
Olr = bitem.olr,
|
|
//مبلغ سایر وجوه قانونی
|
|
Olam = bitem.olam,
|
|
//اجرت ساخت
|
|
Consfee = level ==5 || level ==13 ?bitem.consfee : null,
|
|
// سود فروشنده
|
|
Spro= level == 5 || level == 13 ? bitem.spro : null,
|
|
//حقالعمل
|
|
Bros= level == 5 || level == 13 ? bitem.bros : null,
|
|
//جمع کل اجرت، حقالعمل و سود
|
|
Tcpbs= level == 5 || level == 13 ? bitem.tcpbs : null,
|
|
//سهم نقدی از پرداخت
|
|
Cop = level==8 ||level==10 ||level==11||level==13 ? null : bitem.cop,
|
|
//سهم مالیات بر لرزش افزوده از پرداخت
|
|
Vop = level == 8 || level == 10 || level == 11 || level == 13 ? null : bitem.vop,
|
|
//شناسه یکتای ثبت قرارداد حق العمل کاری
|
|
Bsrn = string.IsNullOrEmpty(bitem.bsrn) ? null : bitem.bsrn,
|
|
// مبلغ کل کالا / خدمت
|
|
Tsstam = bitem.tsstam,
|
|
//فاوت نرخ خرید و فروش ارز/ کارمزد فروش ارز
|
|
// Pspd=level==4 ?bitem.pspd: null,
|
|
//عیار
|
|
Cui =level==5||level==13?bitem.cui: null
|
|
};
|
|
#endregion
|
|
InvoiceBody.Add(item);
|
|
}
|
|
|
|
|
|
//Pay
|
|
List<PaymentDto> InvoicePay = new List<PaymentDto>();
|
|
if (result.setm==1 || result.setm == 3)
|
|
{
|
|
if (level != 10)
|
|
foreach (var pitem in result.payments)
|
|
{
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var responseModel = await _actionTaxPayer.SendInvoice(user.RolUsers.First().CompanyID, header, InvoiceBody, InvoicePay);
|
|
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)
|
|
{
|
|
|
|
|
|
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,
|
|
InvoiceModel = JsonConvert.SerializeObject(result, Formatting.Indented, new JsonSerializerSettings
|
|
{
|
|
PreserveReferencesHandling = PreserveReferencesHandling.Objects
|
|
}),
|
|
ResponseModel = JsonConvert.SerializeObject(responseModel)
|
|
|
|
};
|
|
await _servTaxPayer.AddSentTax(ressenttax);
|
|
}
|
|
result.taxid = header.Taxid;
|
|
result.irtaxid = header.Irtaxid;
|
|
return Ok(await _servTaxPayer.UpdateInvoice(result));
|
|
}
|
|
else
|
|
{
|
|
string errors = "";
|
|
foreach (var item in responseModel.Body.Errors)
|
|
errors += '\n' + $"{item.ErrorCode}:{item.Detail}";
|
|
|
|
return BadRequest(new List<string> { errors });
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|
|
[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));
|
|
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> { "کد پیگیری یافت نشد" });
|
|
|
|
if (!await _actionTaxPayer.login(user.RolUsers.First().CompanyID))
|
|
return BadRequest(new List<string> { "خطا در احراز هویت سازمان مالیاتی" });
|
|
|
|
DataInSendTaxDto desData = new DataInSendTaxDto();
|
|
|
|
|
|
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)
|
|
{
|
|
|
|
desData = new DataInSendTaxDto();
|
|
desData.SentStatus = SentStatus.Unsuccessful;
|
|
desData.error = inquiryerrorResult;
|
|
|
|
|
|
|
|
}
|
|
return Ok(desData);
|
|
}
|
|
else if (item.SentStatus == SentStatus.Send
|
|
|| item.SentStatus == SentStatus.pending
|
|
|| item.SentStatus == SentStatus.IN_PROGRESS
|
|
|| item.SentStatus == SentStatus.Unsuccessful)
|
|
{
|
|
|
|
//ta imja
|
|
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());
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
if (item.SentStatus == SentStatus.Unsuccessful)
|
|
item.ErrorsModel = JsonConvert.SerializeObject(desData.error);
|
|
}
|
|
|
|
|
|
if (await _servTaxPayer.UpdateSentTax(item)) return Ok(desData);
|
|
|
|
else return BadRequest(new List<string> { "خطای در ذخیره سازی" });
|
|
}
|
|
return BadRequest(new List<string> { "در این وضعیت امکان پذیر نمی باشد" });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BadRequest(new List<string> { "خطای ناشناخته" });
|
|
}
|
|
}
|
|
[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));
|
|
}
|
|
[HttpGet("GetUnits")]
|
|
public async Task<ActionResult<List<IdName<int>>>> GetUnits()
|
|
{
|
|
return Ok(await _servTaxPayer.GetUnits());
|
|
}
|
|
[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);
|
|
}
|
|
[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));
|
|
}
|
|
}
|
|
}
|