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
|
||||
{
|
||||
// Get invoice from tblInvoice to get ApplicationCode
|
||||
var invoice = myContext.Database.SqlQuery<dynamic>(
|
||||
// Get invoice from tblInvoice using strongly-typed query
|
||||
var invoice = myContext.Database.SqlQuery<InvoiceDisplay>(
|
||||
"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");
|
||||
}
|
||||
|
||||
// Set ProjectCode in session and redirect to DisplayPDF
|
||||
Session["InvoiceID"] = invoiceId.Value;
|
||||
|
||||
// Set ProjectCode and InvoiceID in session for DisplayPDF
|
||||
Session["ProjectCode"] = invoice.ApplicationCode;
|
||||
Session["InvoiceID"] = invoiceId.Value; // Store specific invoice ID to use in DisplayPDF
|
||||
return RedirectToAction("DisplayPDF");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -4115,21 +4115,45 @@ namespace OSS.Controllers
|
|||
}
|
||||
public async Task<ActionResult> DisplayPDF()
|
||||
{
|
||||
if (Session["ProjectCode"] == null)
|
||||
{
|
||||
TempData["PaymentError"] = "Project code is required.";
|
||||
return RedirectToAction("ApplicationStatus");
|
||||
}
|
||||
|
||||
var ProjectCode = Session["ProjectCode"].ToString();
|
||||
var checkIfExist = myContext.ApplicationManagers.SingleOrDefault(t => t.ProjectCode == ProjectCode);
|
||||
|
||||
// Changes to remove hardcoded exchange rates
|
||||
ExchangeRate exchangeRate = myContext.ExchangeRates.SingleOrDefault(t => t.Currency ==checkIfExist.Currency);
|
||||
COIPrice coiPrice = myContext.COIPrices.SingleOrDefault(t => t.ApplicationType == checkIfExist.ServiceName);
|
||||
// Use FirstOrDefault instead of SingleOrDefault to handle multiple rows
|
||||
var checkIfExist = myContext.ApplicationManagers.FirstOrDefault(t => t.ProjectCode == ProjectCode);
|
||||
|
||||
if (checkIfExist == null)
|
||||
{
|
||||
TempData["PaymentError"] = "Application not found.";
|
||||
return RedirectToAction("ApplicationStatus");
|
||||
}
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
decimal Price = coiPrice.Price * exchangeRate.Rate;
|
||||
if (!invoiceIdToUse.HasValue)
|
||||
{
|
||||
TempData["PaymentError"] = "Invoice ID not found.";
|
||||
return RedirectToAction("ApplicationStatus");
|
||||
}
|
||||
|
||||
Session["AmountinWords"] = CurrencyUtils.ToWords(Price);
|
||||
|
||||
var InvoiceID = checkIfExist.InvoiceID;
|
||||
var InvoiceID = invoiceIdToUse.Value;
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
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();
|
||||
if (checkresult == "0")
|
||||
{
|
||||
|
||||
Session["ControlNo"] = jObject.SelectToken("result.ControlNo").Value<string>();
|
||||
Session["QRCode"] = jObject.SelectToken("result.QRCode").Value<string>();
|
||||
Session["SubServiceName"] = jObject.SelectToken("result.SubServiceName").Value<string>();
|
||||
Session["FullName"] = jObject.SelectToken("result.FullName").Value<string>();
|
||||
Session["ControlNo"] = jObject.SelectToken("result.ControlNo")?.Value<string>();
|
||||
Session["QRCode"] = jObject.SelectToken("result.QRCode")?.Value<string>();
|
||||
Session["SubServiceName"] = jObject.SelectToken("result.SubServiceName")?.Value<string>();
|
||||
Session["FullName"] = jObject.SelectToken("result.FullName")?.Value<string>();
|
||||
Session["CompanyName"] = checkIfExist.CompanyName;
|
||||
Session["PhoneNo"] = jObject.SelectToken("result.PhoneNo").Value<string>();
|
||||
Session["Amount"] = jObject.SelectToken("result.Amount").Value<string>();
|
||||
Session["BillDescription"] = jObject.SelectToken("result.SubServiceName").Value<string>();
|
||||
Session["Currency"] = jObject.SelectToken("result.Currency").Value<string>();
|
||||
Session["ExpireDate"] = jObject.SelectToken("result.ExpireDate").Value<string>();
|
||||
Session["PhoneNo"] = jObject.SelectToken("result.PhoneNo")?.Value<string>();
|
||||
Session["Amount"] = jObject.SelectToken("result.Amount")?.Value<string>();
|
||||
Session["BillDescription"] = jObject.SelectToken("result.SubServiceName")?.Value<string>();
|
||||
Session["Currency"] = jObject.SelectToken("result.Currency")?.Value<string>();
|
||||
Session["ExpireDate"] = jObject.SelectToken("result.ExpireDate")?.Value<string>();
|
||||
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")
|
||||
{
|
||||
var Reslt = jObject.GetValue("message").ToString();
|
||||
ViewData["Notfound"] = Reslt.ToString();
|
||||
var Reslt = jObject.GetValue("message")?.ToString();
|
||||
ViewData["Notfound"] = Reslt ?? "Invoice generation failed.";
|
||||
return View("NotFoundApp");
|
||||
}
|
||||
|
||||
return View("NotFoundApp");
|
||||
}
|
||||
|
||||
}
|
||||
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