commit
This commit is contained in:
parent
4b36f5e995
commit
535b5f4732
BIN
.vs/OSS/v16/.suo
BIN
.vs/OSS/v16/.suo
Binary file not shown.
|
|
@ -21,6 +21,7 @@ using System.Data.Entity.Migrations;
|
|||
using System.Web.WebPages;
|
||||
using System.Data.Entity.Validation;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
|
||||
namespace OSS.Controllers
|
||||
{
|
||||
|
|
@ -2266,62 +2267,85 @@ namespace OSS.Controllers
|
|||
return RedirectToAction("Payment");
|
||||
}
|
||||
|
||||
// Check if additional invoice already exists in tblInvoice
|
||||
var existingInvoiceId = myContext.Database.SqlQuery<long?>(
|
||||
"SELECT TOP 1 InvoiceID FROM tblInvoice WHERE ApplicationCode = @p0 AND SubServiceName LIKE 'Additional_Amount%' ORDER BY InvoiceID DESC",
|
||||
code).FirstOrDefault();
|
||||
long? existingInvoiceId = null;
|
||||
try
|
||||
{
|
||||
existingInvoiceId = myContext.Database.SqlQuery<long?>(
|
||||
"SELECT TOP 1 InvoiceID FROM tblInvoice WHERE ApplicationCode = @p0 AND SubServiceName LIKE 'Additional_Amount%' ORDER BY InvoiceID DESC",
|
||||
code).FirstOrDefault();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Continue to create new invoice
|
||||
}
|
||||
|
||||
if (existingInvoiceId.HasValue)
|
||||
{
|
||||
// Get the existing invoice details
|
||||
var invoiceDetails = myContext.Database.SqlQuery<dynamic>(
|
||||
"SELECT Amount, Currency FROM tblInvoice WHERE InvoiceID = @p0",
|
||||
existingInvoiceId.Value).FirstOrDefault();
|
||||
|
||||
if (invoiceDetails != null)
|
||||
try
|
||||
{
|
||||
Session["Amount"] = invoiceDetails.Amount.ToString();
|
||||
var currency = invoiceDetails.Currency ?? "TZS";
|
||||
Session["Currency"] = currency;
|
||||
Session["AmountinWords"] = CurrencyUtils.ToWords(Convert.ToDecimal(invoiceDetails.Amount)) + " " + currency;
|
||||
var invoiceDetails = myContext.Database.SqlQuery<dynamic>(
|
||||
"SELECT Amount, Currency FROM tblInvoice WHERE InvoiceID = @p0",
|
||||
existingInvoiceId.Value).FirstOrDefault();
|
||||
|
||||
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.HideInvoiceGrid = true;
|
||||
TempData["HidePaidInvoices"] = true;
|
||||
TempData["AdditionalContext"] = true;
|
||||
return View("Payment");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TempData["PaymentError"] = "Error retrieving existing invoice: " + ex.Message;
|
||||
EnsurePaymentSessionDefaults("TZS");
|
||||
return RedirectToAction("Payment");
|
||||
}
|
||||
ViewBag.HideAdditionalButton = true;
|
||||
TempData["HidePaidInvoices"] = true;
|
||||
TempData["AdditionalContext"] = true;
|
||||
return View("Payment");
|
||||
}
|
||||
|
||||
// Generate BillItemRefNo (using timestamp and project code)
|
||||
string billItemRefNo = "BILL-" + DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + code;
|
||||
|
||||
// Determine ServiceTypeID (default to 1, adjust if needed based on business logic)
|
||||
int serviceTypeID = 1;
|
||||
|
||||
// Insert directly into tblInvoice using the parent application details
|
||||
string sql = @"
|
||||
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)
|
||||
try
|
||||
{
|
||||
TempData["PaymentError"] = "Could not create additional payment invoice in tblInvoice.";
|
||||
var parameters = new SqlParameter[]
|
||||
{
|
||||
new SqlParameter("@FullName", SqlDbType.NVarChar, -1) { Value = (object)parentApplication.FullName ?? DBNull.Value },
|
||||
new SqlParameter("@PhoneNo", SqlDbType.NVarChar, -1) { Value = (object)parentApplication.MobileNo ?? DBNull.Value },
|
||||
new SqlParameter("@GFSCode", SqlDbType.NVarChar, 50) { Value = (object)gfsCode ?? DBNull.Value },
|
||||
new SqlParameter("@BillItemRefNo", SqlDbType.NVarChar, 50) { Value = (object)billItemRefNo ?? DBNull.Value },
|
||||
new SqlParameter("@SubServiceName", SqlDbType.VarChar, -1) { Value = "Additional_Amount" },
|
||||
new SqlParameter("@Amount", SqlDbType.Decimal) { Value = addAmount, Precision = 18, Scale = 2 },
|
||||
new SqlParameter("@FrontUserId", SqlDbType.BigInt) { Value = DBNull.Value },
|
||||
new SqlParameter("@ApplicationID", SqlDbType.BigInt) { Value = parentApplication.ApplicationID },
|
||||
new SqlParameter("@ServiceTypeID", SqlDbType.BigInt) { Value = (long)serviceTypeID },
|
||||
new SqlParameter("@ApplicationCode", SqlDbType.NVarChar, -1) { Value = (object)code ?? DBNull.Value },
|
||||
new SqlParameter("@Currency", SqlDbType.VarChar, 10) { Value = "TZS" },
|
||||
new SqlParameter("@TIN_No", SqlDbType.NVarChar, -1) { Value = (object)parentApplication.CompanyTIN ?? DBNull.Value }
|
||||
};
|
||||
|
||||
int rowsAffected = myContext.Database.ExecuteSqlCommand(sql, parameters);
|
||||
if (rowsAffected <= 0)
|
||||
{
|
||||
TempData["PaymentError"] = "Could not create additional payment invoice.";
|
||||
EnsurePaymentSessionDefaults("TZS");
|
||||
return RedirectToAction("Payment");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TempData["PaymentError"] = "Error creating additional payment invoice: " + ex.Message;
|
||||
EnsurePaymentSessionDefaults("TZS");
|
||||
return RedirectToAction("Payment");
|
||||
}
|
||||
|
|
@ -2332,13 +2356,14 @@ namespace OSS.Controllers
|
|||
|
||||
// In Additional Payment context: hide the "Pay Additional Amount" button and hide previous paid invoices
|
||||
ViewBag.HideAdditionalButton = true;
|
||||
ViewBag.HideInvoiceGrid = true;
|
||||
TempData["HidePaidInvoices"] = true;
|
||||
TempData["AdditionalContext"] = true;
|
||||
return View("Payment");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
TempData["PaymentError"] = "Error creating additional payment invoice. " + ex.Message;
|
||||
TempData["PaymentError"] = "Error creating additional payment invoice: " + ex.Message;
|
||||
EnsurePaymentSessionDefaults("TZS");
|
||||
return RedirectToAction("Payment");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,12 @@
|
|||
/**/
|
||||
|
||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||
|
||||
bool hideInvoiceGrid = false;
|
||||
if (ViewBag.HideInvoiceGrid != null)
|
||||
{
|
||||
bool.TryParse(ViewBag.HideInvoiceGrid.ToString(), out hideInvoiceGrid);
|
||||
}
|
||||
}
|
||||
|
||||
<link href="~/Content/assets/css/tables/table-basic.css" rel="stylesheet" type="text/css" />
|
||||
|
|
@ -82,8 +88,10 @@
|
|||
</div>
|
||||
|
||||
<br /><br />
|
||||
<h6 class="text-primary"> Invoice Details</h6>
|
||||
@(Html.DevExtreme().DataGrid<OSS.Models.ApplicationManager>()
|
||||
@if (!hideInvoiceGrid)
|
||||
{
|
||||
<h6 class="text-primary"> Invoice Details</h6>
|
||||
@(Html.DevExtreme().DataGrid<OSS.Models.ApplicationManager>()
|
||||
.ID("invoiceGrid")
|
||||
.DataSource(ds => ds.WebApi()
|
||||
.RouteName("CompanyProfile")
|
||||
|
|
@ -140,6 +148,7 @@ columns.AddFor(m => m.CompanyEmail).Caption("Company Email").Visible(true).Allow
|
|||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
@ -178,7 +187,7 @@ columns.AddFor(m => m.CompanyEmail).Caption("Company Email").Visible(true).Allow
|
|||
}
|
||||
|
||||
|
||||
@if (TempData["HidePaidInvoices"] != null)
|
||||
@if (TempData["HidePaidInvoices"] != null && !hideInvoiceGrid)
|
||||
{
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
|
|
@ -190,7 +199,7 @@ columns.AddFor(m => m.CompanyEmail).Caption("Company Email").Visible(true).Allow
|
|||
</script>
|
||||
}
|
||||
|
||||
@if (TempData["AdditionalContext"] != null)
|
||||
@if (TempData["AdditionalContext"] != null && !hideInvoiceGrid)
|
||||
{
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
|
|
|
|||
|
|
@ -185,7 +185,6 @@
|
|||
<label for="validationCustom05" class="text-black">Currency</label>
|
||||
@Html.DropDownListFor(m => m.Currency, new List<SelectListItem> {
|
||||
//new SelectListItem{ Text="List of allowed currency", Value = "", Selected= true},
|
||||
new SelectListItem{ Text="Select Allowed Currency", Value = "", Selected= true},
|
||||
new SelectListItem{ Text="TZS", Value = "TZS" },
|
||||
// new SelectListItem{ Text="USD", Value = "USD" },
|
||||
}, new { @class = "selectpicker form-control", @id = "Currency", @required = "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.
Binary file not shown.
Loading…
Reference in New Issue