commit
This commit is contained in:
parent
4312588221
commit
f9381c6717
BIN
.vs/OSS/v16/.suo
BIN
.vs/OSS/v16/.suo
Binary file not shown.
|
|
@ -4086,20 +4086,20 @@ namespace OSS.Controllers
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get invoice from tblInvoice to get ApplicationCode
|
// Get invoice from tblInvoice using strongly-typed query
|
||||||
var invoice = myContext.Database.SqlQuery<dynamic>(
|
var invoice = myContext.Database.SqlQuery<InvoiceDisplay>(
|
||||||
"SELECT InvoiceID, ApplicationCode, ApplicationID FROM tblInvoice WHERE InvoiceID = @p0",
|
"SELECT InvoiceID, ApplicationCode, ApplicationID FROM tblInvoice WHERE InvoiceID = @p0",
|
||||||
invoiceId.Value).FirstOrDefault();
|
new System.Data.SqlClient.SqlParameter("@p0", invoiceId.Value)).FirstOrDefault();
|
||||||
|
|
||||||
if (invoice == null)
|
if (invoice == null || string.IsNullOrEmpty(invoice.ApplicationCode))
|
||||||
{
|
{
|
||||||
TempData["PaymentError"] = "Invoice not found.";
|
TempData["PaymentError"] = "Invoice not found or invalid.";
|
||||||
return RedirectToAction("ApplicationStatus");
|
return RedirectToAction("ApplicationStatus");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set ProjectCode in session and redirect to DisplayPDF
|
// Set ProjectCode and InvoiceID in session for DisplayPDF
|
||||||
Session["InvoiceID"] = invoiceId.Value;
|
Session["ProjectCode"] = invoice.ApplicationCode;
|
||||||
|
Session["InvoiceID"] = invoiceId.Value; // Store specific invoice ID to use in DisplayPDF
|
||||||
return RedirectToAction("DisplayPDF");
|
return RedirectToAction("DisplayPDF");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -4115,21 +4115,45 @@ namespace OSS.Controllers
|
||||||
}
|
}
|
||||||
public async Task<ActionResult> DisplayPDF()
|
public async Task<ActionResult> DisplayPDF()
|
||||||
{
|
{
|
||||||
|
if (Session["ProjectCode"] == null)
|
||||||
|
{
|
||||||
|
TempData["PaymentError"] = "Project code is required.";
|
||||||
|
return RedirectToAction("ApplicationStatus");
|
||||||
|
}
|
||||||
|
|
||||||
var ProjectCode = Session["ProjectCode"].ToString();
|
var ProjectCode = Session["ProjectCode"].ToString();
|
||||||
var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode);
|
|
||||||
|
|
||||||
// Changes to remove hardcoded exchange rates
|
// Use FirstOrDefault instead of SingleOrDefault to handle multiple rows
|
||||||
ExchangeRate exchangeRate = myContext.ExchangeRates.SingleOrDefault(t => t.Currency ==checkIfExist.Currency);
|
var checkIfExist = myContext.ApplicationManagers.FirstOrDefault(t => t.ProjectCode == ProjectCode);
|
||||||
COIPrice coiPrice = myContext.COIPrices.SingleOrDefault(t => t.ApplicationType == checkIfExist.ServiceName);
|
|
||||||
|
|
||||||
decimal Price = coiPrice.Price * exchangeRate.Rate;
|
if (checkIfExist == null)
|
||||||
|
{
|
||||||
|
TempData["PaymentError"] = "Application not found.";
|
||||||
|
return RedirectToAction("ApplicationStatus");
|
||||||
|
}
|
||||||
|
|
||||||
Session["AmountinWords"] = CurrencyUtils.ToWords(Price);
|
// Use specific invoice ID from session if available (from DownloadInvoice),
|
||||||
|
// otherwise use the one from ApplicationManagers
|
||||||
|
long? invoiceIdToUse = Session["InvoiceID"] as long?;
|
||||||
|
if (!invoiceIdToUse.HasValue)
|
||||||
|
{
|
||||||
|
invoiceIdToUse = checkIfExist.InvoiceID;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Clear the session invoice ID after using it
|
||||||
|
Session.Remove("InvoiceID");
|
||||||
|
}
|
||||||
|
|
||||||
var InvoiceID = checkIfExist.InvoiceID;
|
if (!invoiceIdToUse.HasValue)
|
||||||
|
{
|
||||||
|
TempData["PaymentError"] = "Invoice ID not found.";
|
||||||
|
return RedirectToAction("ApplicationStatus");
|
||||||
|
}
|
||||||
|
|
||||||
|
var InvoiceID = invoiceIdToUse.Value;
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
|
|
||||||
client.DefaultRequestHeaders.Accept.Clear();
|
client.DefaultRequestHeaders.Accept.Clear();
|
||||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
HttpResponseMessage responseMessage = await client.GetAsync("http://192.168.2.31:8090/tic/invoice-gen/" + InvoiceID);
|
HttpResponseMessage responseMessage = await client.GetAsync("http://192.168.2.31:8090/tic/invoice-gen/" + InvoiceID);
|
||||||
|
|
@ -4138,32 +4162,49 @@ namespace OSS.Controllers
|
||||||
var checkresult = jObject.GetValue("resultcode").ToString();
|
var checkresult = jObject.GetValue("resultcode").ToString();
|
||||||
if (checkresult == "0")
|
if (checkresult == "0")
|
||||||
{
|
{
|
||||||
|
Session["ControlNo"] = jObject.SelectToken("result.ControlNo")?.Value<string>();
|
||||||
Session["ControlNo"] = jObject.SelectToken("result.ControlNo").Value<string>();
|
Session["QRCode"] = jObject.SelectToken("result.QRCode")?.Value<string>();
|
||||||
Session["QRCode"] = jObject.SelectToken("result.QRCode").Value<string>();
|
Session["SubServiceName"] = jObject.SelectToken("result.SubServiceName")?.Value<string>();
|
||||||
Session["SubServiceName"] = jObject.SelectToken("result.SubServiceName").Value<string>();
|
Session["FullName"] = jObject.SelectToken("result.FullName")?.Value<string>();
|
||||||
Session["FullName"] = jObject.SelectToken("result.FullName").Value<string>();
|
|
||||||
Session["CompanyName"] = checkIfExist.CompanyName;
|
Session["CompanyName"] = checkIfExist.CompanyName;
|
||||||
Session["PhoneNo"] = jObject.SelectToken("result.PhoneNo").Value<string>();
|
Session["PhoneNo"] = jObject.SelectToken("result.PhoneNo")?.Value<string>();
|
||||||
Session["Amount"] = jObject.SelectToken("result.Amount").Value<string>();
|
Session["Amount"] = jObject.SelectToken("result.Amount")?.Value<string>();
|
||||||
Session["BillDescription"] = jObject.SelectToken("result.SubServiceName").Value<string>();
|
Session["BillDescription"] = jObject.SelectToken("result.SubServiceName")?.Value<string>();
|
||||||
Session["Currency"] = jObject.SelectToken("result.Currency").Value<string>();
|
Session["Currency"] = jObject.SelectToken("result.Currency")?.Value<string>();
|
||||||
Session["ExpireDate"] = jObject.SelectToken("result.ExpireDate").Value<string>();
|
Session["ExpireDate"] = jObject.SelectToken("result.ExpireDate")?.Value<string>();
|
||||||
Session["PrintedDate"] = DateTime.Now.ToString("dd-MM-yyyy");
|
Session["PrintedDate"] = DateTime.Now.ToString("dd-MM-yyyy");
|
||||||
|
|
||||||
return RedirectToAction("DisplayInvoice", "NewCOI");
|
// Calculate AmountinWords from the actual invoice amount from API, not from COIPrice
|
||||||
|
if (!string.IsNullOrEmpty(Session["Amount"]?.ToString()))
|
||||||
|
{
|
||||||
|
if (decimal.TryParse(Session["Amount"].ToString(), out decimal invoiceAmount))
|
||||||
|
{
|
||||||
|
Session["AmountinWords"] = CurrencyUtils.ToWords(invoiceAmount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fallback: use COIPrice calculation if parsing fails
|
||||||
|
ExchangeRate exchangeRate = myContext.ExchangeRates.FirstOrDefault(t => t.Currency == checkIfExist.Currency);
|
||||||
|
COIPrice coiPrice = myContext.COIPrices.FirstOrDefault(t => t.ApplicationType == checkIfExist.ServiceName);
|
||||||
|
if (exchangeRate != null && coiPrice != null)
|
||||||
|
{
|
||||||
|
decimal Price = coiPrice.Price * exchangeRate.Rate;
|
||||||
|
Session["AmountinWords"] = CurrencyUtils.ToWords(Price);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToAction("DisplayInvoice", "NewCOI");
|
||||||
}
|
}
|
||||||
if (checkresult == "Failure")
|
if (checkresult == "Failure")
|
||||||
{
|
{
|
||||||
var Reslt = jObject.GetValue("message").ToString();
|
var Reslt = jObject.GetValue("message")?.ToString();
|
||||||
ViewData["Notfound"] = Reslt.ToString();
|
ViewData["Notfound"] = Reslt ?? "Invoice generation failed.";
|
||||||
return View("NotFoundApp");
|
return View("NotFoundApp");
|
||||||
}
|
}
|
||||||
|
|
||||||
return View("NotFoundApp");
|
return View("NotFoundApp");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public async Task<ActionResult> DisplayPDFTransfer()
|
public async Task<ActionResult> DisplayPDFTransfer()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
BIN
bin/OSS.dll
BIN
bin/OSS.dll
Binary file not shown.
BIN
bin/OSS.pdb
BIN
bin/OSS.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue