This commit is contained in:
parent
9496a74f1c
commit
4b36f5e995
BIN
.vs/OSS/v16/.suo
BIN
.vs/OSS/v16/.suo
Binary file not shown.
|
|
@ -20,6 +20,7 @@ using Rotativa;
|
||||||
using System.Data.Entity.Migrations;
|
using System.Data.Entity.Migrations;
|
||||||
using System.Web.WebPages;
|
using System.Web.WebPages;
|
||||||
using System.Data.Entity.Validation;
|
using System.Data.Entity.Validation;
|
||||||
|
using System.Data.SqlClient;
|
||||||
|
|
||||||
namespace OSS.Controllers
|
namespace OSS.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -2220,16 +2221,22 @@ namespace OSS.Controllers
|
||||||
return RedirectToAction("Payment");
|
return RedirectToAction("Payment");
|
||||||
}
|
}
|
||||||
|
|
||||||
var project = myContext.ProjectProfilesExternal.FirstOrDefault(t => t.ProjectCode == code);
|
// Find the parent application using ProjectCode
|
||||||
if (project == null)
|
var parentApplication = myContext.ApplicationManagers
|
||||||
|
.Where(a => a.ProjectCode == code)
|
||||||
|
.OrderByDescending(a => a.CreatedDate)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
if (parentApplication == null)
|
||||||
{
|
{
|
||||||
TempData["PaymentError"] = "Project details not found.";
|
TempData["PaymentError"] = "Parent application not found for this project code.";
|
||||||
EnsurePaymentSessionDefaults("TZS");
|
EnsurePaymentSessionDefaults("TZS");
|
||||||
return RedirectToAction("Payment");
|
return RedirectToAction("Payment");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve additional amount from tblService (ServiceName='Additional_Amount', Currency='TZS', Status='1')
|
// Resolve additional amount and GFSCode from tblService (ServiceName='Additional_Amount', Currency='TZS', Status='1')
|
||||||
decimal addAmount = 0m;
|
decimal addAmount = 0m;
|
||||||
|
string gfsCode = "142201370002"; // Default fallback
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var feeRow = myContext.ServiceFees
|
var feeRow = myContext.ServiceFees
|
||||||
|
|
@ -2240,7 +2247,11 @@ namespace OSS.Controllers
|
||||||
(s.ServiceName ?? "").Trim() == "Additional_Amount");
|
(s.ServiceName ?? "").Trim() == "Additional_Amount");
|
||||||
|
|
||||||
if (feeRow != null && feeRow.Fee.HasValue && feeRow.Fee.Value > 0m)
|
if (feeRow != null && feeRow.Fee.HasValue && feeRow.Fee.Value > 0m)
|
||||||
|
{
|
||||||
addAmount = feeRow.Fee.Value;
|
addAmount = feeRow.Fee.Value;
|
||||||
|
if (!string.IsNullOrWhiteSpace(feeRow.GFSCode))
|
||||||
|
gfsCode = feeRow.GFSCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|
@ -2255,87 +2266,70 @@ namespace OSS.Controllers
|
||||||
return RedirectToAction("Payment");
|
return RedirectToAction("Payment");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If an additional invoice already exists, reuse it (check for all Additional_Amount variants)
|
// Check if additional invoice already exists in tblInvoice
|
||||||
var existingInv = myContext.ApplicationManagers
|
var existingInvoiceId = myContext.Database.SqlQuery<long?>(
|
||||||
.OrderByDescending(a => a.CreatedDate)
|
"SELECT TOP 1 InvoiceID FROM tblInvoice WHERE ApplicationCode = @p0 AND SubServiceName LIKE 'Additional_Amount%' ORDER BY InvoiceID DESC",
|
||||||
.FirstOrDefault(a => a.ProjectCode == code );
|
code).FirstOrDefault();
|
||||||
|
|
||||||
if (existingInv != null)
|
if (existingInvoiceId.HasValue)
|
||||||
{
|
{
|
||||||
Session["Amount"] = existingInv.Amount.ToString("0");
|
// Get the existing invoice details
|
||||||
var currency = string.IsNullOrWhiteSpace(existingInv.Currency) ? "TZS" : existingInv.Currency;
|
var invoiceDetails = myContext.Database.SqlQuery<dynamic>(
|
||||||
Session["Currency"] = currency;
|
"SELECT Amount, Currency FROM tblInvoice WHERE InvoiceID = @p0",
|
||||||
Session["AmountinWords"] = CurrencyUtils.ToWords(existingInv.Amount) + " " + currency;
|
existingInvoiceId.Value).FirstOrDefault();
|
||||||
// In Additional Payment context: hide the button and paid invoices, and mark additional context
|
|
||||||
|
if (invoiceDetails != null)
|
||||||
|
{
|
||||||
|
Session["Amount"] = invoiceDetails.Amount.ToString();
|
||||||
|
var currency = invoiceDetails.Currency ?? "TZS";
|
||||||
|
Session["Currency"] = currency;
|
||||||
|
Session["AmountinWords"] = CurrencyUtils.ToWords(Convert.ToDecimal(invoiceDetails.Amount)) + " " + currency;
|
||||||
|
}
|
||||||
ViewBag.HideAdditionalButton = true;
|
ViewBag.HideAdditionalButton = true;
|
||||||
TempData["HidePaidInvoices"] = true;
|
TempData["HidePaidInvoices"] = true;
|
||||||
TempData["AdditionalContext"] = true;
|
TempData["AdditionalContext"] = true;
|
||||||
return View("Payment");
|
return View("Payment");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the original application invoice to copy all details from (exclude all Additional_Amount variants)
|
// Generate BillItemRefNo (using timestamp and project code)
|
||||||
var originalInvoice = myContext.ApplicationManagers
|
string billItemRefNo = "BILL-" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + code;
|
||||||
.Where(a => a.ProjectCode == code &&
|
|
||||||
a.ServiceName != "Additional_Amount" &&
|
|
||||||
a.ServiceName != "Additional_Amount_New" &&
|
|
||||||
a.ServiceName != "Additional_Amount_Expansion")
|
|
||||||
.OrderByDescending(a => a.CreatedDate)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
var applicant = myContext.InvestorExternl.FirstOrDefault(x => x.CompanyEmail == username);
|
// Determine ServiceTypeID (default to 1, adjust if needed based on business logic)
|
||||||
|
int serviceTypeID = 1;
|
||||||
|
|
||||||
// Determine ServiceName based on original invoice (New or Expansion)
|
// Insert directly into tblInvoice using the parent application details
|
||||||
string serviceNameForAdditional = "Additional_Amount";
|
string sql = @"
|
||||||
if (originalInvoice != null && !string.IsNullOrWhiteSpace(originalInvoice.ServiceName))
|
INSERT INTO [dbo].[tblInvoice]
|
||||||
|
([FullName],[PhoneNo],[GFSCode],[BillItemRefNo],[SubServiceName],[Amount],FrontUserId,ApplicationID,StartDate,Expiredate,ServiceTypeID,ApplicationCode,[Currency],[TIN_No])
|
||||||
|
VALUES
|
||||||
|
(@FullName,@PhoneNo,@GFSCode,@BillItemRefNo,@SubServiceName,@Amount,@FrontUserId,@ApplicationID,GETDATE(),DATEADD(day,30,GETDATE()),@ServiceTypeID,@ApplicationCode,@Currency,@TIN_No)";
|
||||||
|
|
||||||
|
int rowsAffected = myContext.Database.ExecuteSqlCommand(sql,
|
||||||
|
new SqlParameter("@FullName", (object)parentApplication.FullName ?? DBNull.Value),
|
||||||
|
new SqlParameter("@PhoneNo", (object)parentApplication.MobileNo ?? DBNull.Value),
|
||||||
|
new SqlParameter("@GFSCode", (object)gfsCode ?? DBNull.Value),
|
||||||
|
new SqlParameter("@BillItemRefNo", (object)billItemRefNo ?? DBNull.Value),
|
||||||
|
new SqlParameter("@SubServiceName", (object)"Additional_Amount" ?? DBNull.Value),
|
||||||
|
new SqlParameter("@Amount", addAmount),
|
||||||
|
new SqlParameter("@FrontUserId", (object)username ?? DBNull.Value),
|
||||||
|
new SqlParameter("@ApplicationID", (object)parentApplication.ApplicationID ?? DBNull.Value),
|
||||||
|
new SqlParameter("@ServiceTypeID", serviceTypeID),
|
||||||
|
new SqlParameter("@ApplicationCode", (object)code ?? DBNull.Value),
|
||||||
|
new SqlParameter("@Currency", "TZS"),
|
||||||
|
new SqlParameter("@TIN_No", (object)parentApplication.CompanyTIN ?? DBNull.Value)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rowsAffected <= 0)
|
||||||
{
|
{
|
||||||
var originalService = originalInvoice.ServiceName.Trim();
|
TempData["PaymentError"] = "Could not create additional payment invoice in tblInvoice.";
|
||||||
if (originalService.IndexOf("new", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
EnsurePaymentSessionDefaults("TZS");
|
||||||
originalService.Equals("New", StringComparison.OrdinalIgnoreCase))
|
return RedirectToAction("Payment");
|
||||||
{
|
|
||||||
serviceNameForAdditional = "Additional_Amount_New";
|
|
||||||
}
|
|
||||||
else if (originalService.IndexOf("expansion", StringComparison.OrdinalIgnoreCase) >= 0 ||
|
|
||||||
originalService.Equals("Expansion", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
serviceNameForAdditional = "Additional_Amount_Expansion";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new invoice copying all details from original invoice, but with Additional_Amount service and amount
|
|
||||||
var inv = new ApplicationManager
|
|
||||||
{
|
|
||||||
ProjectCode = code,
|
|
||||||
ProjectName = originalInvoice?.ProjectName ?? (project.ProjectName ?? string.Empty),
|
|
||||||
CompanyName = originalInvoice?.CompanyName ?? (project.CompanyName ?? string.Empty),
|
|
||||||
ServiceName = serviceNameForAdditional,
|
|
||||||
MobileNo = originalInvoice?.MobileNo ?? (applicant?.Mobile ?? string.Empty),
|
|
||||||
FullName = originalInvoice?.FullName ?? string.Empty,
|
|
||||||
CreatedDate = DateTime.Now,
|
|
||||||
CompanyTIN = originalInvoice?.CompanyTIN ?? (Session["CompanyTIN"] as string) ?? string.Empty,
|
|
||||||
CompanyEmail = username,
|
|
||||||
Currency = "TZS",
|
|
||||||
Station = originalInvoice?.Station ?? "HQ",
|
|
||||||
Amount = addAmount, // 2,000,000 TZS from tblService
|
|
||||||
StartDate = originalInvoice?.StartDate ?? DateTime.Now,
|
|
||||||
Expiredate = originalInvoice?.Expiredate ?? DateTime.Now.AddYears(1),
|
|
||||||
Comments = originalInvoice?.Comments ?? string.Empty,
|
|
||||||
EvaluationStatus = originalInvoice?.EvaluationStatus ?? string.Empty,
|
|
||||||
GePGComment = originalInvoice?.GePGComment ?? string.Empty
|
|
||||||
};
|
|
||||||
|
|
||||||
Session["Amount"] = addAmount.ToString("0");
|
Session["Amount"] = addAmount.ToString("0");
|
||||||
Session["Currency"] = "TZS";
|
Session["Currency"] = "TZS";
|
||||||
Session["AmountinWords"] = CurrencyUtils.ToWords(addAmount) + " Tanzanian Shillings";
|
Session["AmountinWords"] = CurrencyUtils.ToWords(addAmount) + " Tanzanian Shillings";
|
||||||
|
|
||||||
string saveErr;
|
|
||||||
var company = myContext.CompanyProfileExternal.FirstOrDefault(c => c.AddedBy == username);
|
|
||||||
if (!TrySaveInvoice(myContext, inv, company, out saveErr))
|
|
||||||
{
|
|
||||||
TempData["PaymentError"] = "Could not save additional payment invoice. " + saveErr;
|
|
||||||
EnsurePaymentSessionDefaults("TZS");
|
|
||||||
return RedirectToAction("Payment");
|
|
||||||
}
|
|
||||||
|
|
||||||
// In Additional Payment context: hide the "Pay Additional Amount" button and hide previous paid invoices
|
// In Additional Payment context: hide the "Pay Additional Amount" button and hide previous paid invoices
|
||||||
ViewBag.HideAdditionalButton = true;
|
ViewBag.HideAdditionalButton = true;
|
||||||
TempData["HidePaidInvoices"] = true;
|
TempData["HidePaidInvoices"] = true;
|
||||||
|
|
|
||||||
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