Skip to content

Commit

Permalink
feat: Add tax condition verification
Browse files Browse the repository at this point in the history
  • Loading branch information
FacuMasino committed Feb 29, 2024
1 parent cdcdcc4 commit a033bff
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 61 deletions.
3 changes: 3 additions & 0 deletions ImprimirPolizas/ImprimirPolizas.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.1823.32, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.1823.32\lib\net45\Microsoft.Web.WebView2.Wpf.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PdfiumViewer, Version=2.13.0.0, Culture=neutral, PublicKeyToken=91e4789cfb0609e0, processorArchitecture=MSIL">
<HintPath>..\packages\PdfiumViewer.2.13.0.0\lib\net20\PdfiumViewer.dll</HintPath>
</Reference>
Expand Down
4 changes: 2 additions & 2 deletions ImprimirPolizas/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.1.1.0")]
[assembly: AssemblyFileVersion("1.1.1.0")]
29 changes: 28 additions & 1 deletion ImprimirPolizas/ScTools.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json.Linq;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
Expand Down Expand Up @@ -117,6 +118,28 @@ public static string GetFileName(string pcNumber, DownloadOpt opt)
return fileName;
}

public static async Task<bool> requiresInvoice(string policyNumber)
{
string baseUrl = $"{_baseUrl}requiresInvoice?pcN={policyNumber}";
try
{
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage res = await client.GetAsync(baseUrl))
{
using (HttpContent content = res.Content)
{
var resData = await content.ReadAsStringAsync();
//MessageBox.Show(resData);
return ((bool)JObject.Parse(resData)["requiresInvoice"]) || false;
}
}
}
} catch {
return false;
}
}

public static string GetOptionName(DownloadOpt opt)
{
switch (opt)
Expand All @@ -127,6 +150,10 @@ public static string GetOptionName(DownloadOpt opt)
return "Comprobante de pago";
case ScTools.DownloadOpt.policyCard:
return "Tarjeta Seguro Obligatorio";
case ScTools.DownloadOpt.coupons:
return "Cupones de pago";
case ScTools.DownloadOpt.invoice:
return "Factura";
default:
return "Desconocido";
}
Expand Down
104 changes: 52 additions & 52 deletions ImprimirPolizas/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 52 additions & 2 deletions ImprimirPolizas/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,39 @@ private void TxtPolicy_TextChanged(object sender, EventArgs e)
EnableBtnPrint();
}
}
private async Task NotifyInvoiceRequired(string policyNumber)
{
if (!await ScTools.requiresInvoice(policyNumber)) return;
string actualAction = rbPrint.Checked ? "imprimir" : "descargar";
DialogResult result = MessageBox.Show("La categoría del socio es R.I o Monotributo\n" +
$"Desea {actualAction} la Factura?", "Aviso", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No) return;
ScTools.DownloadOpt opt = ScTools.DownloadOpt.invoice;
try
{
ChangeCheckFromTask(chkInvoice, true);
SetIconStatus(ScTools.DownloadOpt.invoice, IconState.Loading);
await ScTools.DownloadDocAsync(policyNumber, 1, opt, downloadFolder);
if (rbPrint.Checked)
{
ChangeStatusFromTask("Imprimiendo " + ScTools.GetOptionName(opt) + "...");
string filePath = Path.Combine(downloadFolder, ScTools.GetFileName(policyNumber, opt));
PrintPDF(filePath);
}
SetIconStatus(opt, IconState.Ready);
}
catch (Exception ex)
{
SetIconStatus(opt, IconState.Error);
MessageBox.Show(
ex.Message,
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error
);
}

}
private async void BtnPrint_Click(object sender, EventArgs e)
{
string pcNumber = txtPolicy.Text;
Expand All @@ -164,6 +196,10 @@ private async void BtnPrint_Click(object sender, EventArgs e)
EnableControls(this, false); // deshabilitar mientras carga
bool hasFailed = false;
List<Task> printTasks = new List<Task>();
if (!chkInvoice.Checked)
{
printTasks.Add(Task.Run(async () => await NotifyInvoiceRequired(pcNumber)));
}
for (int i = 0; i < options.Length; i++)
{
if (options[i] == 0)
Expand Down Expand Up @@ -204,7 +240,7 @@ private async void BtnPrint_Click(object sender, EventArgs e)
}
// Esperar que terminen todas las tasks
await Task.WhenAll(printTasks);
btnPrint.Text = rbPrint.Checked ? "IMPRIMIR":"DESCARGAR";
btnPrint.Text = rbPrint.Checked ? "IMPRIMIR" : "DESCARGAR";
lblStatus.Text = hasFailed ? "Error" : "Listo";
lblStatus.ForeColor = hasFailed ? Color.Red : Color.Green;
if (!hasFailed && !lnkDownloads.Visible) lnkDownloads.Visible = true;
Expand Down Expand Up @@ -260,6 +296,20 @@ private void ChangeStatusFromTask(string text)
);
}

private void ChangeCheckFromTask(CheckBox chk, bool check)
{
chk.Invoke(
(
new MethodInvoker(
delegate
{
chk.Checked = check;
}
)
)
);
}

private void ChkPolicy_CheckedChanged(object sender, EventArgs e)
{
EnableBtnPrint();
Expand Down Expand Up @@ -363,7 +413,7 @@ private void chkCoupons_CheckedChanged(object sender, EventArgs e)

private void chkInvoice_CheckedChanged(object sender, EventArgs e)
{
EnableBtnPrint();
if(btnPrint.Text != "Aguarde...") EnableBtnPrint();
if (chkInvoice.Checked)
{
options[4] = (int)ScTools.DownloadOpt.invoice;
Expand Down
4 changes: 2 additions & 2 deletions ImprimirPolizas/frmMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAO
GQAAAk1TRnQBSQFMAgEBAwEAATABAAEwAQABGQEAARkBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAFk
GQAAAk1TRnQBSQFMAgEBAwEAATgBAAE4AQABGQEAARkBAAT/AREBAAj/AUIBTQE2BwABNgMAASgDAAFk
AwABGQMAAQEBAAEQBQABiAETEgAB3gF7Ad4BewHeAXsB3gF7Ad4BewHeAXsB3gF7Ad4BewHeAXsB3gF7
Ad4BewHeAXsB3gF7Ad4BewHeAXsB3gF7Ad4BewHeAXsB3gF7Ad4BewHeAXsB3gF7Ad4BewHeAXsB3gF7
DgAB/wF/AboBawFxAUcBKAEjAeIBCgHgAQIB4gEKASgBIwFxAUcBugFrAf8BfxQAAaUBUAEAAXQhAAFw
Expand Down Expand Up @@ -235,7 +235,7 @@
</value>
</data>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>34</value>
<value>25</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Expand Down
1 change: 1 addition & 0 deletions ImprimirPolizas/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<package id="Autoupdater.NET.Official" version="1.8.4" targetFramework="net48" />
<package id="BouncyCastle" version="1.8.9" targetFramework="net48" />
<package id="Microsoft.Web.WebView2" version="1.0.1823.32" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="PdfiumViewer" version="2.13.0.0" targetFramework="net48" />
<package id="PdfiumViewer.Native.x86.v8-xfa" version="2018.4.8.256" targetFramework="net48" />
<package id="PdfiumViewer.Native.x86_64.v8-xfa" version="2018.4.8.256" targetFramework="net48" />
Expand Down
4 changes: 2 additions & 2 deletions autoupdater.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.1.0.0</version>
<url>https://github.com/FacuMasino/imprimir-polizas-utility/releases/download/v1.1/ImprimirPolizasv1.1.0.zip</url>
<version>1.1.1.0</version>
<url>https://github.com/FacuMasino/imprimir-polizas-utility/releases/download/v.1.1.1/ImprimirPolizasv1.1.1.zip</url>
<mandatory mode="2">true</mandatory>
</item>

0 comments on commit a033bff

Please sign in to comment.