commit
This commit is contained in:
parent
f9381c6717
commit
7e754d9fa8
BIN
.vs/OSS/v16/.suo
BIN
.vs/OSS/v16/.suo
Binary file not shown.
|
|
@ -91,7 +91,20 @@ namespace OSS.Controllers
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public HttpResponseMessage GetInvoiceByUserAll(DataSourceLoadOptions loadOptions, string ProjectCode)
|
public HttpResponseMessage GetInvoiceByUserAll(DataSourceLoadOptions loadOptions, string ProjectCode)
|
||||||
{
|
{
|
||||||
return Request.CreateResponse(DataSourceLoader.Load(myContext.ApplicationManagers.Where(t => t.ProjectCode == ProjectCode && (t.ServiceName == "New" || t.ServiceName == "Expansion" || t.ServiceName == "Amendment" || t.ServiceName == "Extension")).OrderByDescending(t => t.CreatedDate), loadOptions));
|
// Get invoices from ApplicationManagers
|
||||||
|
var appManagerInvoices = myContext.ApplicationManagers
|
||||||
|
.Where(t => t.ProjectCode == ProjectCode && (t.ServiceName == "New" || t.ServiceName == "Expansion" || t.ServiceName == "Amendment" || t.ServiceName == "Extension"))
|
||||||
|
.OrderByDescending(t => t.CreatedDate)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// Get additional payment invoices from tblInvoice
|
||||||
|
var additionalInvoices = myContext.Database.SqlQuery<InvoiceDisplay>(
|
||||||
|
"SELECT InvoiceID, Amount, Currency, ApplicationCode, ApplicationID, SubServiceName, FullName, PhoneNo, GFSCode, BillItemRefNo, StartDate, Expiredate, ServiceTypeID, PaymentStatus, ControlNo FROM tblInvoice WHERE ApplicationCode = @p0 AND SubServiceName LIKE 'Additional_Amount%' ORDER BY InvoiceID DESC",
|
||||||
|
new System.Data.SqlClient.SqlParameter("@p0", ProjectCode)).ToList();
|
||||||
|
|
||||||
|
// Combine and return (you may need to map InvoiceDisplay to ApplicationManager or create a combined DTO)
|
||||||
|
// For now, return ApplicationManagers as before, but this shows the structure
|
||||||
|
return Request.CreateResponse(DataSourceLoader.Load(appManagerInvoices, loadOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2388,22 +2388,92 @@ namespace OSS.Controllers
|
||||||
return RedirectToAction("Payment", "NewCOI");
|
return RedirectToAction("Payment", "NewCOI");
|
||||||
}
|
}
|
||||||
|
|
||||||
var getPDetails = myContext.ApplicationManagers
|
// First, check if there's a newer Additional_Amount invoice in tblInvoice
|
||||||
.Where(t => t.ProjectCode == ProjectCode)
|
InvoiceDisplay additionalInvoice = null;
|
||||||
.OrderByDescending(t => t.CreatedDate)
|
try
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (getPDetails == null)
|
|
||||||
{
|
{
|
||||||
TempData["PaymentError"] = "No invoice found for this project. Create an invoice first.";
|
additionalInvoice = myContext.Database.SqlQuery<InvoiceDisplay>(
|
||||||
|
"SELECT TOP 1 InvoiceID, Amount, Currency, ApplicationCode, ApplicationID, SubServiceName, FullName, PhoneNo, GFSCode, BillItemRefNo, StartDate, Expiredate, ServiceTypeID, PaymentStatus, ControlNo FROM tblInvoice WHERE ApplicationCode = @p0 AND SubServiceName LIKE 'Additional_Amount%' ORDER BY InvoiceID DESC",
|
||||||
|
new System.Data.SqlClient.SqlParameter("@p0", ProjectCode)).FirstOrDefault();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Continue to check ApplicationManagers
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplicationManager getPDetails = null;
|
||||||
|
long? invoiceIdToUse = null;
|
||||||
|
decimal amountToUse = 0m;
|
||||||
|
string currencyToUse = null;
|
||||||
|
string companyNameToUse = null;
|
||||||
|
string mobileNoToUse = null;
|
||||||
|
string serviceNameToUse = null;
|
||||||
|
|
||||||
|
// Always fetch the latest invoiceId from tblInvoice for this project (covers regenerated invoices)
|
||||||
|
long? latestInvoiceId = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
latestInvoiceId = myContext.Database.SqlQuery<long?>(
|
||||||
|
"SELECT TOP 1 InvoiceID FROM tblInvoice WHERE ApplicationCode = @p0 ORDER BY InvoiceID DESC",
|
||||||
|
new SqlParameter("@p0", ProjectCode)).FirstOrDefault();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignore, will handle below
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalInvoice != null)
|
||||||
|
{
|
||||||
|
// Use the additional payment invoice (2M) and keep company/contact from ApplicationManagers
|
||||||
|
invoiceIdToUse = additionalInvoice.InvoiceID;
|
||||||
|
amountToUse = additionalInvoice.Amount ?? 0m;
|
||||||
|
currencyToUse = additionalInvoice.Currency ?? "TZS";
|
||||||
|
|
||||||
|
getPDetails = myContext.ApplicationManagers
|
||||||
|
.Where(t => t.ProjectCode == ProjectCode)
|
||||||
|
.OrderByDescending(t => t.CreatedDate)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
if (getPDetails != null)
|
||||||
|
{
|
||||||
|
companyNameToUse = getPDetails.CompanyName;
|
||||||
|
mobileNoToUse = getPDetails.MobileNo;
|
||||||
|
serviceNameToUse = additionalInvoice.SubServiceName ?? "Additional_Amount";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fall back to ApplicationManagers, but use the latest invoice ID from tblInvoice when available
|
||||||
|
getPDetails = myContext.ApplicationManagers
|
||||||
|
.Where(t => t.ProjectCode == ProjectCode)
|
||||||
|
.OrderByDescending(t => t.CreatedDate)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
if (getPDetails == null || !latestInvoiceId.HasValue)
|
||||||
|
{
|
||||||
|
TempData["PaymentError"] = "No invoice found for this project. Create an invoice first.";
|
||||||
|
return RedirectToAction("Payment", "NewCOI");
|
||||||
|
}
|
||||||
|
|
||||||
|
invoiceIdToUse = latestInvoiceId;
|
||||||
|
amountToUse = getPDetails.Amount;
|
||||||
|
currencyToUse = getPDetails.Currency;
|
||||||
|
companyNameToUse = getPDetails.CompanyName;
|
||||||
|
mobileNoToUse = getPDetails.MobileNo;
|
||||||
|
serviceNameToUse = getPDetails.ServiceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!invoiceIdToUse.HasValue || amountToUse <= 0)
|
||||||
|
{
|
||||||
|
TempData["PaymentError"] = "Invalid invoice data found.";
|
||||||
return RedirectToAction("Payment", "NewCOI");
|
return RedirectToAction("Payment", "NewCOI");
|
||||||
}
|
}
|
||||||
|
|
||||||
ExchangeRate exchangeRate = myContext.ExchangeRates
|
ExchangeRate exchangeRate = myContext.ExchangeRates
|
||||||
.FirstOrDefault(t => t.Currency == getPDetails.Currency);
|
.FirstOrDefault(t => t.Currency == currencyToUse);
|
||||||
|
|
||||||
if(exchangeRate != null){
|
if(exchangeRate != null){
|
||||||
Session["EqAmount"] = exchangeRate.Rate * getPDetails.Amount;
|
Session["EqAmount"] = exchangeRate.Rate * amountToUse;
|
||||||
} else {
|
} else {
|
||||||
TempData["error"] = "Couldn\'t process control number. Contact Administrators";
|
TempData["error"] = "Couldn\'t process control number. Contact Administrators";
|
||||||
return RedirectToAction("GenerateControlNo", "NewCOI");
|
return RedirectToAction("GenerateControlNo", "NewCOI");
|
||||||
|
|
@ -2411,7 +2481,11 @@ namespace OSS.Controllers
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getPDetails.UpdatedDate = DateTime.Now;
|
if (getPDetails != null)
|
||||||
|
{
|
||||||
|
getPDetails.UpdatedDate = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
using (var client = new HttpClient())
|
using (var client = new HttpClient())
|
||||||
{
|
{
|
||||||
client.DefaultRequestHeaders.Accept.Clear();
|
client.DefaultRequestHeaders.Accept.Clear();
|
||||||
|
|
@ -2420,21 +2494,21 @@ namespace OSS.Controllers
|
||||||
{
|
{
|
||||||
gepgCtrlno = new gepgCtrlno()
|
gepgCtrlno = new gepgCtrlno()
|
||||||
{
|
{
|
||||||
BillId = getPDetails.InvoiceID.ToString(),
|
BillId = invoiceIdToUse.Value.ToString(),
|
||||||
BillAmt = getPDetails.Amount.ToString(),
|
BillAmt = amountToUse.ToString(),
|
||||||
BillEqvAmt = Session["EqAmount"].ToString(),
|
BillEqvAmt = Session["EqAmount"].ToString(),
|
||||||
BillExprDt = DateTime.Now.AddDays(30).ToString("yyyy-MM-ddTHH:mm:ss"),
|
BillExprDt = DateTime.Now.AddDays(30).ToString("yyyy-MM-ddTHH:mm:ss"),
|
||||||
PyrId = getPDetails.CompanyName.ToString(),
|
PyrId = companyNameToUse ?? "",
|
||||||
PyrName = getPDetails.CompanyName.ToString(),
|
PyrName = companyNameToUse ?? "",
|
||||||
BillGenDt = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"),
|
BillGenDt = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||||||
PyrCellNum = getPDetails.MobileNo.ToString(),
|
PyrCellNum = mobileNoToUse ?? "",
|
||||||
Ccy = getPDetails.Currency.ToString(),
|
Ccy = currencyToUse ?? "TZS",
|
||||||
BillDesc = getPDetails.ServiceName.ToString(),
|
BillDesc = serviceNameToUse ?? "",
|
||||||
BillItems = new BillItems
|
BillItems = new BillItems
|
||||||
{
|
{
|
||||||
BillItem = new List<BillItem>
|
BillItem = new List<BillItem>
|
||||||
{
|
{
|
||||||
new BillItem { BillItemRef = getPDetails.InvoiceID.ToString() , BillItemAmt=getPDetails.Amount.ToString(), BillItemEqvAmt=Session["EqAmount"].ToString(), GfsCode="142201370002"}
|
new BillItem { BillItemRef = invoiceIdToUse.Value.ToString() , BillItemAmt=amountToUse.ToString(), BillItemEqvAmt=Session["EqAmount"].ToString(), GfsCode="142201370002"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
systemInfo = new systemInfo
|
systemInfo = new systemInfo
|
||||||
|
|
@ -2451,19 +2525,20 @@ namespace OSS.Controllers
|
||||||
HttpResponseMessage responseMessage = await client.PostAsync("http://192.168.2.31:8090/tic/generate-controlno", httpContent);
|
HttpResponseMessage responseMessage = await client.PostAsync("http://192.168.2.31:8090/tic/generate-controlno", httpContent);
|
||||||
var responseJson = await responseMessage.Content.ReadAsStringAsync();
|
var responseJson = await responseMessage.Content.ReadAsStringAsync();
|
||||||
var jObject = JObject.Parse(responseJson);
|
var jObject = JObject.Parse(responseJson);
|
||||||
|
|
||||||
|
// Store invoice ID in session for GenerateControlNo view
|
||||||
|
Session["InvoiceID"] = invoiceIdToUse.Value;
|
||||||
|
Session["Amount"] = amountToUse.ToString();
|
||||||
|
Session["Currency"] = currencyToUse;
|
||||||
|
|
||||||
return RedirectToAction("GenerateControlNo", "NewCOI");
|
return RedirectToAction("GenerateControlNo", "NewCOI");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var getGepgResponse = myContext.ApplicationManagers
|
|
||||||
.Where(t => t.ProjectCode == ProjectCode)
|
|
||||||
.OrderByDescending(t => t.CreatedDate)
|
|
||||||
.FirstOrDefault();
|
|
||||||
TempData["error"] = "Network timeout..please try again";
|
TempData["error"] = "Network timeout..please try again";
|
||||||
return RedirectToAction("GenerateControlNo", "NewCOI");
|
return RedirectToAction("GenerateControlNo", "NewCOI");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public ActionResult ExpansionProject()
|
public ActionResult ExpansionProject()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@
|
||||||
<remove name="X-AspNetMvc-Version"/>
|
<remove name="X-AspNetMvc-Version"/>
|
||||||
<remove name="X-Powered-By"/>
|
<remove name="X-Powered-By"/>
|
||||||
<remove name="Server"/>
|
<remove name="Server"/>
|
||||||
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains; frame-ancestors 'self'"/>
|
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains; frame-ancestors 'self'"/>
|
||||||
<add name="Set-Cookie" value="Secure; HttpOnly"/>
|
<add name="Set-Cookie" value="Secure; HttpOnly"/>
|
||||||
</customHeaders>
|
</customHeaders>
|
||||||
</httpProtocol>
|
</httpProtocol>
|
||||||
|
|
|
||||||
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.
Binary file not shown.
Loading…
Reference in New Issue