From 82bcfc1ffe7900835a846b11891d23c1e1b9983a Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Sun, 9 Jun 2024 17:23:57 +0330 Subject: [PATCH] ... --- Back/Back.csproj | 2 +- Back/Controllers/TaxPayerController.cs | 431 +++++++++++++++++- Back/Program.cs | 1 + Back/Services/ActionTaxPayer.cs | 67 +-- Back/Services/servCompany.cs | 68 +-- Back/Services/servTaxPayer.cs | 42 +- Shared/DTOs/SentTaxDto.cs | 20 + Shared/DTOs/Serch/ItemSerchGetSentTax.cs | 20 + TaxPayerFull/Pages/UserPanel/TaxPayer.razor | 161 ++++++- .../Pages/UserPanel/TaxPayerInvoiceItem.razor | 68 ++- TaxPayerFull/Program.cs | 4 +- 11 files changed, 780 insertions(+), 104 deletions(-) create mode 100644 Shared/DTOs/SentTaxDto.cs create mode 100644 Shared/DTOs/Serch/ItemSerchGetSentTax.cs diff --git a/Back/Back.csproj b/Back/Back.csproj index fd97cd7..899d7e4 100644 --- a/Back/Back.csproj +++ b/Back/Back.csproj @@ -36,7 +36,7 @@ - ..\..\Dlls\Service.dll + ..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll diff --git a/Back/Controllers/TaxPayerController.cs b/Back/Controllers/TaxPayerController.cs index ce8088b..fdaf89b 100644 --- a/Back/Controllers/TaxPayerController.cs +++ b/Back/Controllers/TaxPayerController.cs @@ -1,22 +1,35 @@ -using Back.Data.Models; +using Back.Common; +using Back.Data.Models; using Back.Services; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; +using Org.BouncyCastle.Asn1.Cmp; using Shared.DTOs; +using Shared.DTOs.Serch; +using System; +using System.Security.Cryptography; +using TaxCollectData.Library.Dto.Content; 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; - public TaxPayerController(servTaxPayer servTaxPayer, servUser servUser) + private readonly ActionTaxPayer _actionTaxPayer; + public TaxPayerController(servTaxPayer servTaxPayer, servUser servUser, ActionTaxPayer actionTaxPayer) { - _servTaxPayer = servTaxPayer; + _servTaxPayer = servTaxPayer; _servUser = servUser; + _actionTaxPayer = actionTaxPayer; } [HttpGet("GetInvoice/{ID}")] public async Task> Get(int ID) @@ -25,9 +38,9 @@ namespace Back.Controllers 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 { "صورتحساب یافت نشد"}); - + if (result == null) + return BadRequest(new List { "صورتحساب یافت نشد" }); + else { if (!result.PatternID.HasValue) @@ -37,19 +50,19 @@ namespace Back.Controllers return BadRequest(new List { "صورتحساب در وضعیت پیش نویس نمیتواند ارسال شود" }); if (await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result)) - return BadRequest(new List { "این صورتحساب قبلا به سازمان ارسال شده"}); + return BadRequest(new List { "این صورتحساب قبلا به سازمان ارسال شده" }); if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair) && !result.BillReference.HasValue) return BadRequest(new List { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع وجود داشته باشد" }); - - if ((result.invoiceType==InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair) + + if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair) && !await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result.invoice)) return BadRequest(new List { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع به سامانه مودیان ارسال شده باشد" }); - - + + return Ok(await _servTaxPayer.GetFildInvoiceForPreparation(result)); } @@ -67,23 +80,395 @@ namespace Back.Controllers return Ok(await _servTaxPayer.PreparationInvoiceBeforeSending(item, result)); } - [HttpPost("CheckAuth")] - public async Task> CheckAuth([FromBody] CheckAuthDTO item) + [HttpGet("CheckAuth")] + public async Task> CheckAuth() { - if (item == null) - return BadRequest("مدل صحیح نمی باشد"); - - using (ActionTaxPayer action = new ActionTaxPayer(item.UniqueMemory, item.PrivateKey)) - { - if (action.login()) - return Ok(); - } - - + 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 Ok(); return BadRequest(); } + [HttpGet("SendInvoice/{InvoiceID}")] + public async Task> SendInvoice(int InvoiceID) + { + + 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 { "خطا در احراز هویت سازمان مالیاتی" }); + + var result = await _servTaxPayer.GetInvoice(user.RolUsers.First().CompanyID, InvoiceID); + if (result == null) + return BadRequest(new List { "صورتحساب یافت نشد" }); + + else + { + if (!result.PatternID.HasValue) + return BadRequest(new List { "ابتدا برای این صورتحساب الگو در نظر بگیرید" }); + + if (result.invoiceType == InvoiceType.Bidding) + return BadRequest(new List { "صورتحساب در وضعیت پیش نویس نمیتواند ارسال شود" }); + + if (await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result)) + return BadRequest(new List { "این صورتحساب قبلا به سازمان ارسال شده" }); + + if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair) + && !result.BillReference.HasValue) + return BadRequest(new List { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع وجود داشته باشد" }); + + + if ((result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair) + && !await _servTaxPayer.ExistSuccessfulorSendorpendingInvoice(result.invoice)) + return BadRequest(new List { "در وضعیت برگشت از فروش و اصلاحی باید صورتحساب مرجع به سامانه مودیان ارسال شده باشد" }); + + #region Inital Send + InvoiceHeaderDto header = new InvoiceHeaderDto(); + #region header + if (header.Inty == 1 && header.Inp == 1) + header = new InvoiceHeaderDto + { + //نوع شخص خریدار + Tob = result.tob, + // صورتحساب نوع * + Inty = result.inty ?? 1, + //الگوی صورتحساب * + Inp = result.inp ?? 1, + //موضوع صورتحساب * + Ins = result.ins ?? 1, + //شماره منحصر به فرد مالیاتی + Taxid = _actionTaxPayer.GenerateTaxid(result.inno, result.InvoiceDate.Replace("/", "").Trim()), + //سریال صورت حساب + Inno = result.inno ?? null, + //شماره اقتصادی فروشنده به جاش شناسه ملی داده شد + Tins = result.tins ?? null, + //مجموع مبلغ قبل از کسر تخفیف + Tprdis = result.tprdis ?? null, + // مجموع مبلغ پس از کسر تخفیف + Tadis = result.tadis ?? null, + //مجموع مالیات بر ارزش افزوده + Tvam = result.tvam ?? null, + // مجموع سایر مالیات، عوارض و وجوه قانونی + Todam = result.todam ?? null, + //صورتحساب مجموع + Tbill = result.tbill ?? null, + // تسویه روش + Setm = result.setm ?? null, + //نقدی پرداختی مبلغ + Cap = result.cap ?? null, + //پرداختی نسیه + Insp = result.insp ?? null, + //مجموع تخفیفات + Tdis = result.tdis ?? null, + //شماره منحصر به فرد مالیاتی صورتحساب مرجع + Irtaxid = result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair ? result.invoice.taxid : null, + //شماره اقتصادی خریدار + Tinb = result.tinb ?? null, + //زمان صدور + Indatim = result.indatim ?? null, + //زمان ایجاد + Indati2m = result.Indati2m ?? null, + //کد شعبه خریدار + Bbc = result.bbc ?? null, + Tvop = result.tvop ?? null, + Crn = result.crn ?? null, + Tax17 = string.IsNullOrEmpty(result.seventeentax) ? null : Convert.ToDecimal(result.seventeentax), + Scc = result.scc ?? null, + Scln = result.scln ?? null, + Bid = result.bid ?? null, + }; + if (header.Inty == 1 && header.Inp == 2) + header = new InvoiceHeaderDto + { + //نوع شخص خریدار + Tob = result.tob, + // صورتحساب نوع * + Inty = result.inty ?? 1, + //الگوی صورتحساب * + Inp = result.inp ?? 1, + //موضوع صورتحساب * + Ins = result.ins ?? 1, + //شماره منحصر به فرد مالیاتی + Taxid = _actionTaxPayer.GenerateTaxid(result.inno, result.InvoiceDate.Replace("/", "").Trim()), + //سریال صورت حساب + Inno = result.inno ?? null, + //شماره اقتصادی فروشنده به جاش شناسه ملی داده شد + Tins = result.tins ?? null, + //مجموع مبلغ قبل از کسر تخفیف + Tprdis = result.tprdis ?? null, + // مجموع مبلغ پس از کسر تخفیف + Tadis = result.tadis ?? null, + //مجموع مالیات بر ارزش افزوده + Tvam = result.tvam ?? null, + // مجموع سایر مالیات، عوارض و وجوه قانونی + Todam = result.todam ?? null, + //صورتحساب مجموع + Tbill = result.tbill ?? null, + // تسویه روش + Setm = result.setm ?? null, + //نقدی پرداختی مبلغ + Cap = result.cap ?? null, + //پرداختی نسیه + Insp = result.insp ?? null, + //مجموع تخفیفات + Tdis = result.tdis ?? null, + //شماره منحصر به فرد مالیاتی صورتحساب مرجع + Irtaxid = result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair ? result.invoice.taxid : null, + //شماره اقتصادی خریدار + Tinb = result.tinb ?? null, + //زمان صدور + Indatim = result.indatim ?? null, + //زمان ایجاد + Indati2m = result.Indati2m ?? null, + //کد شعبه خریدار + Bbc = result.bbc ?? null, + Tvop = result.tvop ?? null, + Crn = result.crn ?? null, + Tax17 = string.IsNullOrEmpty(result.seventeentax) ? null : Convert.ToDecimal(result.seventeentax), + Scc = result.scc ?? null, + Scln = result.scln ?? null, + Bpn = result.bpn ?? null, + Bid = result.bid ?? null, + }; + if (header.Inty == 1 && header.Inp == 3) + header = new InvoiceHeaderDto + { + //نوع شخص خریدار + Tob = result.tob, + // صورتحساب نوع * + Inty = result.inty ?? 1, + //الگوی صورتحساب * + Inp = result.inp ?? 1, + //موضوع صورتحساب * + Ins = result.ins ?? 1, + //شماره منحصر به فرد مالیاتی + Taxid = _actionTaxPayer.GenerateTaxid(result.inno, result.InvoiceDate.Replace("/", "").Trim()), + //سریال صورت حساب + Inno = result.inno ?? null, + //شماره اقتصادی فروشنده به جاش شناسه ملی داده شد + Tins = result.tins ?? null, + //مجموع مبلغ قبل از کسر تخفیف + Tprdis = result.tprdis ?? null, + // مجموع مبلغ پس از کسر تخفیف + Tadis = result.tadis ?? null, + //مجموع مالیات بر ارزش افزوده + Tvam = result.tvam ?? null, + // مجموع سایر مالیات، عوارض و وجوه قانونی + Todam = result.todam ?? null, + //صورتحساب مجموع + Tbill = result.tbill ?? null, + // تسویه روش + Setm = result.setm ?? null, + //نقدی پرداختی مبلغ + Cap = result.cap ?? null, + //پرداختی نسیه + Insp = result.insp ?? null, + //مجموع تخفیفات + Tdis = result.tdis ?? null, + //شماره منحصر به فرد مالیاتی صورتحساب مرجع + Irtaxid = result.invoiceType == InvoiceType.BackFrmSale || result.invoiceType == InvoiceType.Repair ? result.invoice.taxid : null, + //شماره اقتصادی خریدار + Tinb = result.tinb ?? null, + //زمان صدور + Indatim = result.indatim ?? null, + //زمان ایجاد + Indati2m = result.Indati2m ?? null, + //کد شعبه خریدار + Bbc = result.bbc ?? null, + Tvop = result.tvop ?? null, + Crn = result.crn ?? null, + Tax17 = string.IsNullOrEmpty(result.seventeentax) ? null : Convert.ToDecimal(result.seventeentax), + Bid = result.bid ?? null, + }; + #endregion header + List InvoiceBody = new List(); + foreach (var bitem in result.invoiceDetails) + { + InvoiceBodyDto item=new InvoiceBodyDto(); + #region body + if (header.Inty==1 && header.Inp==1) + item = new InvoiceBodyDto + { + //شناسه کالا / خدمت + Sstid = bitem.sstid, + //شرح کاال/خدمت + Sstt = bitem.sstt, + //واحد اندازه گیری + Mu = bitem.mu, + // تعداد + Am = bitem.am, + // مبلغ واحد + Fee = bitem.fee, + //مبلغ قبل از تخفیف + Prdis = bitem.prdis, + //مبلغ تخفیف + Dis = bitem.dis, + //مبلغ بعد از تخفیف + Adis = bitem.adis, + //نرخ مالیات بر ارزش افزوده + Vra = bitem.vra, + //مبلغ مالیات بر ارزش افزوده + Vam = bitem.vam, + // مبلغ کل کالا / خدمت + Tsstam = bitem.tsstam, + Cfee = bitem.cfee, + Cut = bitem.cut, + Exr = bitem.exr, + Odt = bitem.odt, + Odr = bitem.odr, + Odam = bitem.odam, + Olt = bitem.olt, + Olr = bitem.olr, + Olam = bitem.olam, + Cop = bitem.cop, + Vop = bitem.vop, + Bsrn = bitem.bsrn, + + + }; + + else if (header.Inty == 1 && header.Inp == 2) + item = new InvoiceBodyDto + { + //شناسه کالا / خدمت + Sstid = bitem.sstid, + //شرح کاال/خدمت + Sstt = bitem.sstt, + //واحد اندازه گیری + Mu = bitem.mu, + // تعداد + Am = bitem.am, + // مبلغ واحد + Fee = bitem.fee, + //مبلغ قبل از تخفیف + Prdis = bitem.prdis, + //مبلغ تخفیف + Dis = bitem.dis, + //مبلغ بعد از تخفیف + Adis = bitem.adis, + //نرخ مالیات بر ارزش افزوده + Vra = bitem.vra, + //مبلغ مالیات بر ارزش افزوده + Vam = bitem.vam, + // مبلغ کل کالا / خدمت + Tsstam = bitem.tsstam, + Cfee = bitem.cfee, + Cut = bitem.cut, + Exr = bitem.exr, + Odt = bitem.odt, + Odr = bitem.odr, + Odam = bitem.odam, + Olt = bitem.olt, + Olr = bitem.olr, + Olam = bitem.olam, + Cop = bitem.cop, + Vop = bitem.vop, + Bsrn = bitem.bsrn, + + + }; + + else if(header.Inty == 1 && header.Inp == 3) + item = new InvoiceBodyDto + { + //شناسه کالا / خدمت + Sstid = bitem.sstid, + //شرح کاال/خدمت + Sstt = bitem.sstt, + //واحد اندازه گیری + Mu = bitem.mu, + // تعداد + Am = bitem.am, + // مبلغ واحد + Fee = bitem.fee, + //مبلغ قبل از تخفیف + Prdis = bitem.prdis, + //مبلغ تخفیف + Dis = bitem.dis, + //مبلغ بعد از تخفیف + Adis = bitem.adis, + //نرخ مالیات بر ارزش افزوده + Vra = bitem.vra, + //مبلغ مالیات بر ارزش افزوده + Vam = bitem.vam, + // مبلغ کل کالا / خدمت + Tsstam = bitem.tsstam, + Cfee = bitem.cfee, + Cut = bitem.cut, + Exr = bitem.exr, + Odt = bitem.odt, + Odr = bitem.odr, + Odam = bitem.odam, + Olt = bitem.olt, + Olr = bitem.olr, + Olam = bitem.olam, + Cop = bitem.cop, + Vop = bitem.vop, + Bsrn = bitem.bsrn, + Consfee=bitem.consfee, + Spro=bitem.spro, + Bros=bitem.bros, + Tcpbs=bitem.tcpbs, + }; + + #endregion + InvoiceBody.Add(item); + } + + var responseModel =await _actionTaxPayer.SendInvoice(user.RolUsers.First().CompanyID,header, InvoiceBody, new PaymentDto { }); + if (responseModel == null) + { + return BadRequest(new List { "خطا در ورود به سامانه مودیان" }); + } + 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), + 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 { errors }); + } + + + #endregion + + + } + } + [HttpPost("GetAllSentTax")] + public async Task>> 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(_servTaxPayer.GetSentTax(user.RolUsers.First().CompanyID,item)); + } } } diff --git a/Back/Program.cs b/Back/Program.cs index 7b76991..a5a5f75 100644 --- a/Back/Program.cs +++ b/Back/Program.cs @@ -74,6 +74,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2")); string origins = "OriginTaxPayer"; diff --git a/Back/Services/ActionTaxPayer.cs b/Back/Services/ActionTaxPayer.cs index 60772ea..c4ce83a 100644 --- a/Back/Services/ActionTaxPayer.cs +++ b/Back/Services/ActionTaxPayer.cs @@ -1,4 +1,5 @@ using Back.Common; +using Microsoft.IdentityModel.Tokens; using TaxCollectData.Library.Business; using TaxCollectData.Library.Dto.Config; using TaxCollectData.Library.Dto.Content; @@ -8,32 +9,23 @@ using TaxCollectData.Library.Enums; namespace Back.Services { - public class ActionTaxPayer : IDisposable + public class ActionTaxPayer { private string _UniqueMemory; - public ActionTaxPayer(string UniqueMemory, string PrivateKey) + private string _PrivateKey; + private readonly servCompany _servCompany; + public ActionTaxPayer(servCompany servCompany) { - #region TokenTax - if (!string.IsNullOrEmpty(UniqueMemory) && !string.IsNullOrEmpty(PrivateKey)) - { - _UniqueMemory = UniqueMemory; - - TaxApiService.Instance.Init(UniqueMemory, - new SignatoryConfig(PrivateKey, null), - new NormalProperties(ClientType.SELF_TSP), "https://tp.tax.gov.ir/req/api/"); - TaxApiService.Instance.TaxApis.GetServerInformation(); - } - #endregion + _servCompany = servCompany; } public string GenerateTaxid(string FactorNo, string InvoiceDate) { return TaxApiService.Instance.TaxIdGenerator.GenerateTaxId(_UniqueMemory, Convert.ToInt64(FactorNo), InvoiceDate.ToMiladi()); } - - public InquiryResultModel GetResultByUid(string uid) + public async Task GetResultByUid(int CompanyID, string uid) { - if (!login()) + if (!await login(CompanyID)) return null; var uidAndFiscalId = new UidAndFiscalId(uid, _UniqueMemory); var inquiryResultModels = TaxApiService.Instance.TaxApis.InquiryByUidAndFiscalId(new() { uidAndFiscalId }); @@ -41,45 +33,58 @@ namespace Back.Services return inquiryResultModels[0]; return null; } - public TaxCollectData.Library.Dto.HttpResponse SendInvoice(InvoiceHeaderDto header, List InvoiceBody, PaymentDto payment) + public async Task> SendInvoice(int CompanyID,InvoiceHeaderDto header, List InvoiceBody, PaymentDto payment) { - if (!login()) + if (!await login(CompanyID)) return null; - return TaxApiService.Instance.TaxApis.SendInvoices(new List() + return await TaxApiService.Instance.TaxApis.SendInvoicesAsync(new List() { - new InvoiceDto() + new() { Header =header,Body =InvoiceBody,Payments = new() {payment} } } , null); } - public EconomicCodeModel? GetEconomicCodeInformation(string Item) + public async Task GetEconomicCodeInformation(string Item) { - return TaxApiService.Instance.TaxApis.GetEconomicCodeInformation(Item); + return await TaxApiService.Instance.TaxApis.GetEconomicCodeInformationAsync(Item); } //-------------------internal - public bool login() + public async Task login(int CompanyID) { try { + #region TokenTax + var resquth = await _servCompany.GetTaxAuth(CompanyID); + if (string.IsNullOrEmpty(resquth.UniqueMemory) || string.IsNullOrEmpty(resquth.PrivateKey)) + return false; + + if (!string.IsNullOrEmpty(resquth.UniqueMemory) && !string.IsNullOrEmpty(resquth.PrivateKey)) + { + _UniqueMemory = resquth.UniqueMemory; + _PrivateKey = resquth.PrivateKey; + TaxApiService.Instance.Init(_UniqueMemory, + new SignatoryConfig(_PrivateKey, null), + new NormalProperties(ClientType.SELF_TSP), "https://tp.tax.gov.ir/req/api/"); + await TaxApiService.Instance.TaxApis.GetServerInformationAsync(); + } + #endregion + if (TaxApiService.Instance.TaxApis.GetToken() is null) { - if(TaxApiService.Instance.TaxApis.RequestToken()==null) - return false; + if (await TaxApiService.Instance.TaxApis.RequestTokenAsync() == null) + return false; } - return true; + return true; } catch (Exception) { return false; } - + } - public void Dispose() - { - throw new NotImplementedException(); - } + } } diff --git a/Back/Services/servCompany.cs b/Back/Services/servCompany.cs index d53062b..e010b1a 100644 --- a/Back/Services/servCompany.cs +++ b/Back/Services/servCompany.cs @@ -18,38 +18,38 @@ namespace Back.Services _repoCompany = repoCompany; _repoRolUser = repoRolUser; } - public async Task ExsistCompanyByComoanyIDandUserID(int ComoanyID, int UserID,bool InAdmin=false) + public async Task ExsistCompanyByComoanyIDandUserID(int ComoanyID, int UserID, bool InAdmin = false) { - var res= _repoRolUser.Get(w => w.CompanyID == ComoanyID && w.UserID == UserID && w.Company.IsActive); + var res = _repoRolUser.Get(w => w.CompanyID == ComoanyID && w.UserID == UserID && w.Company.IsActive); if (InAdmin) - res = res.Where( w=> w.IsAdmin); + res = res.Where(w => w.IsAdmin); - return await res.AnyAsync(); + return await res.AnyAsync(); } public async Task GetCompany(int ComoanyID) { - return await _repoCompany.Get(w => w.ID == ComoanyID && w.IsActive) - .Select(s=>new CompanyDTO() - { - BranchID = s.BranchID, - EconomicCode = s.EconomicCode, - ID = s.ID, - Email = s.Email, - Logo= s.Logo==null ?null: System.Text.Encoding.UTF8.GetString(s.Logo) , - Mobile = s.Mobile, - Name = s.Name, - Phone = s.Phone, - PrivateKey= s.PrivateKey, - UniqeMemory = s.UniqeMemory - }).FirstOrDefaultAsync(); + return await _repoCompany.Get(w => w.ID == ComoanyID && w.IsActive) + .Select(s => new CompanyDTO() + { + BranchID = s.BranchID, + EconomicCode = s.EconomicCode, + ID = s.ID, + Email = s.Email, + Logo = s.Logo == null ? null : System.Text.Encoding.UTF8.GetString(s.Logo), + Mobile = s.Mobile, + Name = s.Name, + Phone = s.Phone, + PrivateKey = s.PrivateKey, + UniqeMemory = s.UniqeMemory + }).FirstOrDefaultAsync(); } - public async Task GetCompanyOrg(int ComoanyID,bool IsActive=true) + public async Task GetCompanyOrg(int ComoanyID, bool IsActive = true) { var inv = _repoCompany.Get(w => w.ID == ComoanyID); if (IsActive) - inv= inv.Where(w=>w.IsActive); - - return await inv.FirstOrDefaultAsync(); + inv = inv.Where(w => w.IsActive); + + return await inv.FirstOrDefaultAsync(); } public async Task GetCompanyOrgByMobileAndCompanynotActive(string Mobile) { @@ -72,16 +72,16 @@ namespace Back.Services //}; //_contextMongodb.InsertItem(log); - if (item.ID == null || item.ID ==0) + if (item.ID == null || item.ID == 0) { - return await _repoCompany.AddAsync(item); + return await _repoCompany.AddAsync(item); } else { - return await _repoCompany.UpdateByObjAsync(item); + return await _repoCompany.UpdateByObjAsync(item); } - + } catch (Exception ex) @@ -144,15 +144,23 @@ namespace Back.Services } } - public async Task ExistMobileInCompany(string mobile,bool IsActive=true) + public async Task ExistMobileInCompany(string mobile, bool IsActive = true) { - var resquest= _repoCompany.GetAll().Where(w => w.Mobile == mobile ); + var resquest = _repoCompany.GetAll().Where(w => w.Mobile == mobile); if (IsActive) resquest = resquest.Where(w => w.IsActive); - + return await resquest.AnyAsync(); } - + public async Task GetTaxAuth(int ComoanyID) + { + return await _repoCompany.Get(w => w.ID == ComoanyID && w.IsActive) + .Select(s => new CheckAuthDTO() + { + PrivateKey = s.PrivateKey, + UniqueMemory = s.UniqeMemory + }).FirstOrDefaultAsync(); + } diff --git a/Back/Services/servTaxPayer.cs b/Back/Services/servTaxPayer.cs index bc06050..f4aa0b7 100644 --- a/Back/Services/servTaxPayer.cs +++ b/Back/Services/servTaxPayer.cs @@ -3,6 +3,9 @@ using Back.Data.Contracts; using Back.Data.Models; using Microsoft.EntityFrameworkCore; using Back.Common; +using Shared; +using Microsoft.OpenApi.Extensions; +using Shared.DTOs.Serch; namespace Back.Services { @@ -48,7 +51,10 @@ namespace Back.Services return await _repoPattern.Get(w=>w.Status).Select(s => new IdName { ID = s.ID, Title = s.Title }).ToListAsync(); } - + public async Task UpdateInvoice(Invoice invoice) + { + return await _invoiceRepo.UpdateAsync(invoice); + } public async Task GetInvoice(int CompanyID, int ID) { #region AdvancedSearch @@ -71,7 +77,10 @@ namespace Back.Services .ThenInclude(inc => inc.CODUnit) .FirstOrDefaultAsync(); } - + public async Task AddSentTax(SentTax sentTax) + { + return await _repoSentTax.AddBoolResultAsync(sentTax); + } public async Task<_TaxPayer.Atemplatefield> GetFildInvoiceForPreparation(Invoice InvoiceItem) { _TaxPayer.Atemplatefield ret = new _TaxPayer.Atemplatefield(); @@ -192,6 +201,35 @@ namespace Back.Services + } + public async Task> GetSentTax(int CompanyID, ItemSerchGetSentTax itemSerchGetSentTax) + { + var request = _repoSentTax.Get(w => w.invoice.CompanyID == CompanyID); + + if (itemSerchGetSentTax.ID.HasValue) + request = request.Where(w => w.ID == itemSerchGetSentTax.ID.Value); + + if (itemSerchGetSentTax.invoiceType.HasValue) + request = request.Where(w => w.invoice.invoiceType == itemSerchGetSentTax.invoiceType.Value); + + if (itemSerchGetSentTax.SentStatus.HasValue) + request = request.Where(w => w.SentStatus == itemSerchGetSentTax.SentStatus.Value); + + if (itemSerchGetSentTax.InvoiceID.HasValue) + request = request.Where(w => w.InvoiceID == itemSerchGetSentTax.InvoiceID.Value); + + return await request.OrderByDescending(o=>o.ID) + .Select(s => new SentTaxDto + { + Date = s.Date.ShamciToFormatShamciinFront(), + Time = s.Time, + ID = s.ID, + InvoiceID = s.InvoiceID, + SentStatus=s.SentStatus, + msgInvoiceType = s.InvoiceType.GetDisplayName(), + msgSentStatus = s.SentStatus.GetDisplayName() + + }).Paging(itemSerchGetSentTax.PageIndex, itemSerchGetSentTax.PageSize); } private void SetValue(_TaxPayer.Fild fild, ref T obj) { diff --git a/Shared/DTOs/SentTaxDto.cs b/Shared/DTOs/SentTaxDto.cs new file mode 100644 index 0000000..5d04190 --- /dev/null +++ b/Shared/DTOs/SentTaxDto.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs +{ + public class SentTaxDto + { + public int ID { get; set; } + public int InvoiceID { get; set; } + public string Date { get; set; } + public string Time { get; set; } + public SentStatus SentStatus { get; set; } + public string msgInvoiceType { get; set; } + public string msgSentStatus { get; set; } + } +} diff --git a/Shared/DTOs/Serch/ItemSerchGetSentTax.cs b/Shared/DTOs/Serch/ItemSerchGetSentTax.cs new file mode 100644 index 0000000..c7f2813 --- /dev/null +++ b/Shared/DTOs/Serch/ItemSerchGetSentTax.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs.Serch +{ + public class ItemSerchGetSentTax : IFildGlobalItemSerch + { + [Display(Name = "شناسه")] + public int? ID { get; set; } + public int? InvoiceID { get; set; } + public InvoiceType? invoiceType { get; set; } + public SentStatus? SentStatus { get; set; } + public int PageIndex { get; set; } = 1; + public int PageSize { get; set; } = 5; + } +} diff --git a/TaxPayerFull/Pages/UserPanel/TaxPayer.razor b/TaxPayerFull/Pages/UserPanel/TaxPayer.razor index 183b4f8..f3a799d 100644 --- a/TaxPayerFull/Pages/UserPanel/TaxPayer.razor +++ b/TaxPayerFull/Pages/UserPanel/TaxPayer.razor @@ -2,7 +2,166 @@ @inject HttpClientController hc; @layout PanelLayout @page "/TaxPayer" +@page "/TaxPayer/{routed:int}" @using Front.Services -@code { +@using Shared +@using Shared.DTOs +@using Shared.DTOs.Serch + +@* search *@ +
+

+ سرویس ها / سامانه مودیان +

+
+
+
+
+
    +
  • +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    +
  • +
+
+
+
+
+
+@* alert *@ +
+ + +
+@* data *@ +@if (request != null) +{ + + @* pagination *@ +

@request?.RowCount آیتم یافت شد

+ } + +@code { + [Inject] protected PreloadService PreloadService { get; set; } = default!; + ItemSerchGetSentTax itemsearch = new ItemSerchGetSentTax(); + public int? routed { get; set; } = 0; + // alert + AlertColor alertColor = AlertColor.Primary; + IconName alertIconName = IconName.CheckCircleFill; + bool Hidealert = true; + string alertMessage = ""; + [Parameter, SupplyParameterFromQuery] + public int? PageIndex { get; set; } + public Shared.DTOs.PagingDto? request { get; set; } + + protected override async Task OnParametersSetAsync() + { + if (routed.HasValue && routed > 0) + { + ShowSuccessAlert($"صورتحساب شماره {routed} با موفقیت ارسال شد " +'\n'+ + "برای برای 'نمایش وضعیت' آن را تعیین وضعیت کنید"); + itemsearch.InvoiceID = routed.Value; + } + + if (PageIndex == null) PageIndex = 1; + await Load(PageIndex.Value); + await base.OnParametersSetAsync(); + } +} +@functions{ + public async Task SentTaxItem(int ID) + { + + } + public async Task Load(int pi) + { + itemsearch.PageSize = 10; + itemsearch.PageIndex = pi; + PreloadService.Show(SpinnerColor.Dark); + var rsp = await hc.Post("TaxPayer/GetAllSentTax", itemsearch); + if (rsp.IsSuccessStatusCode) + { + request = await rsp.Content.ReadFromJsonAsync>(); + } + else if (rsp.StatusCode == System.Net.HttpStatusCode.Forbidden) + { + ShowDangerAlert("شما دسترسی به خواندن اطلاعات صورتحساب را نداربد"); + } + else + { + ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); + } + PreloadService.Hide(); + } + private void ShowSuccessAlert(string msg) + { + Hidealert = false; + alertColor = AlertColor.Success; + alertIconName = IconName.CheckCircleFill; + alertMessage = msg; + } + private void ShowDangerAlert(string msg) + { + Hidealert = false; + alertColor = AlertColor.Danger; + alertIconName = IconName.ExclamationTriangleFill; + alertMessage = msg; + } +} \ No newline at end of file diff --git a/TaxPayerFull/Pages/UserPanel/TaxPayerInvoiceItem.razor b/TaxPayerFull/Pages/UserPanel/TaxPayerInvoiceItem.razor index 8c5520d..c62e7df 100644 --- a/TaxPayerFull/Pages/UserPanel/TaxPayerInvoiceItem.razor +++ b/TaxPayerFull/Pages/UserPanel/TaxPayerInvoiceItem.razor @@ -5,8 +5,9 @@ @inject HttpClientController hc; - + آماده سازی صورتحساب + @* alert *@