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]
|
||||
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,30 +2388,104 @@ namespace OSS.Controllers
|
|||
return RedirectToAction("Payment", "NewCOI");
|
||||
}
|
||||
|
||||
var getPDetails = myContext.ApplicationManagers
|
||||
// First, check if there's a newer Additional_Amount invoice in tblInvoice
|
||||
InvoiceDisplay additionalInvoice = null;
|
||||
try
|
||||
{
|
||||
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)
|
||||
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");
|
||||
}
|
||||
|
||||
ExchangeRate exchangeRate = myContext.ExchangeRates
|
||||
.FirstOrDefault(t => t.Currency == getPDetails.Currency);
|
||||
.FirstOrDefault(t => t.Currency == currencyToUse);
|
||||
|
||||
if(exchangeRate != null){
|
||||
Session["EqAmount"] = exchangeRate.Rate * getPDetails.Amount;
|
||||
Session["EqAmount"] = exchangeRate.Rate * amountToUse;
|
||||
} else {
|
||||
TempData["error"] = "Couldn\'t process control number. Contact Administrators";
|
||||
return RedirectToAction("GenerateControlNo", "NewCOI");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (getPDetails != null)
|
||||
{
|
||||
getPDetails.UpdatedDate = DateTime.Now;
|
||||
}
|
||||
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
|
|
@ -2420,21 +2494,21 @@ namespace OSS.Controllers
|
|||
{
|
||||
gepgCtrlno = new gepgCtrlno()
|
||||
{
|
||||
BillId = getPDetails.InvoiceID.ToString(),
|
||||
BillAmt = getPDetails.Amount.ToString(),
|
||||
BillId = invoiceIdToUse.Value.ToString(),
|
||||
BillAmt = amountToUse.ToString(),
|
||||
BillEqvAmt = Session["EqAmount"].ToString(),
|
||||
BillExprDt = DateTime.Now.AddDays(30).ToString("yyyy-MM-ddTHH:mm:ss"),
|
||||
PyrId = getPDetails.CompanyName.ToString(),
|
||||
PyrName = getPDetails.CompanyName.ToString(),
|
||||
PyrId = companyNameToUse ?? "",
|
||||
PyrName = companyNameToUse ?? "",
|
||||
BillGenDt = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"),
|
||||
PyrCellNum = getPDetails.MobileNo.ToString(),
|
||||
Ccy = getPDetails.Currency.ToString(),
|
||||
BillDesc = getPDetails.ServiceName.ToString(),
|
||||
PyrCellNum = mobileNoToUse ?? "",
|
||||
Ccy = currencyToUse ?? "TZS",
|
||||
BillDesc = serviceNameToUse ?? "",
|
||||
BillItems = new BillItems
|
||||
{
|
||||
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
|
||||
|
|
@ -2451,19 +2525,20 @@ namespace OSS.Controllers
|
|||
HttpResponseMessage responseMessage = await client.PostAsync("http://192.168.2.31:8090/tic/generate-controlno", httpContent);
|
||||
var responseJson = await responseMessage.Content.ReadAsStringAsync();
|
||||
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");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var getGepgResponse = myContext.ApplicationManagers
|
||||
.Where(t => t.ProjectCode == ProjectCode)
|
||||
.OrderByDescending(t => t.CreatedDate)
|
||||
.FirstOrDefault();
|
||||
TempData["error"] = "Network timeout..please try again";
|
||||
return RedirectToAction("GenerateControlNo", "NewCOI");
|
||||
}
|
||||
|
||||
}
|
||||
public ActionResult ExpansionProject()
|
||||
{
|
||||
|
|
|
|||
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