minor issue for custom PO but working already, need to change the incormterms into autocomplete
This commit is contained in:
parent
da0af6a64e
commit
798f8f67ea
@ -54,6 +54,7 @@ namespace CPRNIMS.Domain.Contracts.PO
|
|||||||
Task<PurchaseOrder> PostPutPO(PODto PODto);
|
Task<PurchaseOrder> PostPutPO(PODto PODto);
|
||||||
Task<OtherCharges> PostSuppCharges(PODto poDto);
|
Task<OtherCharges> PostSuppCharges(PODto poDto);
|
||||||
Task<CustomPO> PostPutCustomPO(PODto pODto);
|
Task<CustomPO> PostPutCustomPO(PODto pODto);
|
||||||
|
Task<CustomPO> PutExistingPO(PODto pODto);
|
||||||
Task<DocRequired>PostSuppDocRequirements(PODto poDto);
|
Task<DocRequired>PostSuppDocRequirements(PODto poDto);
|
||||||
Task<PurchaseOrder> PostPOToSupplier(PODto PODto);
|
Task<PurchaseOrder> PostPOToSupplier(PODto PODto);
|
||||||
Task<Suppliers> PostApprovedSupplier(PODto PODto);
|
Task<Suppliers> PostApprovedSupplier(PODto PODto);
|
||||||
|
|||||||
@ -343,7 +343,7 @@ namespace CPRNIMS.Domain.Services.PO
|
|||||||
public async Task<List<Infrastructure.Entities.PO.PO>> GetPOListByTerm(PODto itemDto)
|
public async Task<List<Infrastructure.Entities.PO.PO>> GetPOListByTerm(PODto itemDto)
|
||||||
{
|
{
|
||||||
return await _dbContext.POs
|
return await _dbContext.POs
|
||||||
.Where(p => !p.IsCancel && !p.IsPOClosed &&
|
.Where(p => !p.IsCancel && !p.IsPOClosed && p.PreparedBy == itemDto.UserId &&
|
||||||
p.IsActive && p.PONo.StartsWith(itemDto.PONo ?? "N/A"))
|
p.IsActive && p.PONo.StartsWith(itemDto.PONo ?? "N/A"))
|
||||||
.Take(50)
|
.Take(50)
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
@ -481,7 +481,7 @@ namespace CPRNIMS.Domain.Services.PO
|
|||||||
|
|
||||||
var (messCode, message) = CreateOutputParams();
|
var (messCode, message) = CreateOutputParams();
|
||||||
await _dbContext.Database
|
await _dbContext.Database
|
||||||
.ExecuteSqlRawAsync($"EXEC PostPutCustomPO @UserId,@POTypeId,@PONumber,@PRDetailsId,@Specification,@PRNo,@PORemarks,@IncoTermsId," +
|
.ExecuteSqlRawAsync("EXEC PostPutCustomPO @UserId,@POTypeId,@PONumber,@PRDetailsId,@Specification,@PRNo,@PORemarks,@IncoTermsId," +
|
||||||
$"@PODId,@ProfInvoiceNo,@ProfInvoiceDate,@PaymentTermsId,@ShippingInstructionId,@SupplierId,@DeliveryDate,@Discount,@Amount," +
|
$"@PODId,@ProfInvoiceNo,@ProfInvoiceDate,@PaymentTermsId,@ShippingInstructionId,@SupplierId,@DeliveryDate,@Discount,@Amount," +
|
||||||
$"@UnitPrice,@Quantity,@DeliverTo, @MessCode OUTPUT, @Message OUTPUT",
|
$"@UnitPrice,@Quantity,@DeliverTo, @MessCode OUTPUT, @Message OUTPUT",
|
||||||
new SqlParameter("@UserId", pODto.UserId),
|
new SqlParameter("@UserId", pODto.UserId),
|
||||||
@ -517,6 +517,59 @@ namespace CPRNIMS.Domain.Services.PO
|
|||||||
PONo = formattedPONumber
|
PONo = formattedPONumber
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
bool isRemoved = false;
|
||||||
|
public async Task<CustomPO> PutExistingPO(PODto pODto)
|
||||||
|
{
|
||||||
|
if (pODto.POTypeId != 3)
|
||||||
|
{
|
||||||
|
pODto.PODId = 0;
|
||||||
|
pODto.ProfInvoiceDate = DateTime.Now;
|
||||||
|
pODto.ShippingInstructionId = 0;
|
||||||
|
pODto.IncoTermsId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var (messCode, message) = CreateOutputParams();
|
||||||
|
formattedPONumber = pODto.PONo ?? "N/A";
|
||||||
|
await _dbContext.Database
|
||||||
|
.ExecuteSqlRawAsync("EXEC PutExistingPO @UserId,@POTypeId,@PONumber,@PRDetailsId,@Specification,@PRNo,@PORemarks,@IncoTermsId," +
|
||||||
|
$"@PODId,@ProfInvoiceNo,@ProfInvoiceDate,@PaymentTermsId,@ShippingInstructionId,@SupplierId,@DeliveryDate,@Discount,@Amount," +
|
||||||
|
$"@UnitPrice,@Quantity,@DeliverTo,@IsRemoved, @MessCode OUTPUT, @Message OUTPUT",
|
||||||
|
new SqlParameter("@UserId", pODto.UserId),
|
||||||
|
new SqlParameter("@POTypeId", pODto.POTypeId),
|
||||||
|
new SqlParameter("@PONumber", pODto.PONo),
|
||||||
|
new SqlParameter("@PRDetailsId", pODto.PRDetailsId),
|
||||||
|
new SqlParameter("@Specification", pODto.Specification ?? string.Empty),
|
||||||
|
new SqlParameter("@PRNo", pODto.PRNo),
|
||||||
|
new SqlParameter("@PORemarks", pODto.PORemarks ?? "N/A"),
|
||||||
|
new SqlParameter("@IncoTermsId", pODto.IncoTermsId),
|
||||||
|
new SqlParameter("@PODId", pODto.PODId),
|
||||||
|
new SqlParameter("@ProfInvoiceNo", pODto.ProfInvoiceNo ?? "N/A"),
|
||||||
|
new SqlParameter("@ProfInvoiceDate", pODto.ProfInvoiceDate == null || pODto.ProfInvoiceDate == DateTime.MinValue
|
||||||
|
? DateTime.Now : pODto.ProfInvoiceDate),
|
||||||
|
new SqlParameter("@PaymentTermsId", pODto.PaymentTermsId),
|
||||||
|
new SqlParameter("@ShippingInstructionId", pODto.ShippingInstructionId),
|
||||||
|
new SqlParameter("@SupplierId", pODto.SupplierId),
|
||||||
|
new SqlParameter("@DeliveryDate", pODto.DeliveryDate),
|
||||||
|
new SqlParameter("@Discount", pODto.Discount),
|
||||||
|
new SqlParameter("@Amount", pODto.Amount),
|
||||||
|
new SqlParameter("@UnitPrice", pODto.UnitPrice),
|
||||||
|
new SqlParameter("@Quantity", pODto.Quantity),
|
||||||
|
new SqlParameter("@DeliverTo", pODto.DeliverTo),
|
||||||
|
new SqlParameter("@IsRemoved", isRemoved),
|
||||||
|
messCode,
|
||||||
|
message);
|
||||||
|
|
||||||
|
isRemoved = true;
|
||||||
|
|
||||||
|
if ((byte)messCode.Value == 0)
|
||||||
|
{
|
||||||
|
throw new Exception(message.Value.ToString());
|
||||||
|
}
|
||||||
|
return new CustomPO
|
||||||
|
{
|
||||||
|
Message= messCode.ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
public async Task Prerequisite(POVM poVM)
|
public async Task Prerequisite(POVM poVM)
|
||||||
{
|
{
|
||||||
//CHARGES LIST
|
//CHARGES LIST
|
||||||
@ -568,7 +621,8 @@ namespace CPRNIMS.Domain.Services.PO
|
|||||||
Discount = PODto.Discount,
|
Discount = PODto.Discount,
|
||||||
DeliveryDate = PODto.DeliveryDate,
|
DeliveryDate = PODto.DeliveryDate,
|
||||||
DeliverTo = PODto.DeliverTo ?? "N/A",
|
DeliverTo = PODto.DeliverTo ?? "N/A",
|
||||||
Specification = specification
|
Specification = specification,
|
||||||
|
IsUpdate = PODto.IsUpdate
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public async Task<DocRequired> PostSuppDocRequirements(PODto poDto)
|
public async Task<DocRequired> PostSuppDocRequirements(PODto poDto)
|
||||||
@ -580,15 +634,20 @@ namespace CPRNIMS.Domain.Services.PO
|
|||||||
new SqlParameter("@PONumber", formattedPONumber));
|
new SqlParameter("@PONumber", formattedPONumber));
|
||||||
return new DocRequired();
|
return new DocRequired();
|
||||||
}
|
}
|
||||||
|
bool isChargesRemoved = false;
|
||||||
public async Task<OtherCharges> PostSuppCharges(PODto poDto)
|
public async Task<OtherCharges> PostSuppCharges(PODto poDto)
|
||||||
{
|
{
|
||||||
|
|
||||||
await _dbContext.Database
|
await _dbContext.Database
|
||||||
.ExecuteSqlRawAsync("EXEC PostSuppCharges @UserId,@PONo,@OtherChargesId,@POTypeId,@Amount",
|
.ExecuteSqlRawAsync("EXEC PostSuppChargesV2 @UserId,@PONo,@OtherChargesId,@POTypeId,@Amount,@IsRemoved",
|
||||||
new SqlParameter("@UserId", poDto.UserId),
|
new SqlParameter("@UserId", poDto.UserId),
|
||||||
new SqlParameter("@PONo", formattedPONumber),
|
new SqlParameter("@PONo", formattedPONumber),
|
||||||
new SqlParameter("@OtherChargesId", poDto.OtherChargesId),
|
new SqlParameter("@OtherChargesId", poDto.OtherChargesId),
|
||||||
new SqlParameter("@POTypeId", poDto.POTypeId),
|
new SqlParameter("@POTypeId", poDto.POTypeId),
|
||||||
new SqlParameter("@Amount", poDto.Amount));
|
new SqlParameter("@Amount", poDto.Amount),
|
||||||
|
new SqlParameter("@IsRemoved", isChargesRemoved));
|
||||||
|
|
||||||
|
isChargesRemoved = true;
|
||||||
return new OtherCharges();
|
return new OtherCharges();
|
||||||
}
|
}
|
||||||
public async Task<Infrastructure.Entities.PO.PurchaseOrder> PutPRItemDetails(PODto pODto)
|
public async Task<Infrastructure.Entities.PO.PurchaseOrder> PutPRItemDetails(PODto pODto)
|
||||||
@ -814,7 +873,6 @@ namespace CPRNIMS.Domain.Services.PO
|
|||||||
await PostIncShipFollowUp(itemDto, shipFollowUp);
|
await PostIncShipFollowUp(itemDto, shipFollowUp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,7 +54,7 @@ namespace CPRNIMS.Domain.UIServices.PO
|
|||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
_logger.LogError("GetPOFormData failed: {StatusCode}", response.StatusCode);
|
_logger.LogError("GetPOFormData failed: {StatusCode}", response.StatusCode);
|
||||||
return new POFormData(); // return empty rather than throw
|
return new POFormData();
|
||||||
}
|
}
|
||||||
|
|
||||||
var json = await response.Content.ReadAsStringAsync();
|
var json = await response.Content.ReadAsStringAsync();
|
||||||
|
|||||||
@ -109,6 +109,7 @@ namespace CPRNIMS.Infrastructure.Dto.PO
|
|||||||
public decimal Quantity { get; set; }
|
public decimal Quantity { get; set; }
|
||||||
public string? DeliverTo { get; set; }
|
public string? DeliverTo { get; set; }
|
||||||
public bool IsManual { get; set; }
|
public bool IsManual { get; set; }
|
||||||
|
public bool IsUpdate { get; set; }
|
||||||
public string? Specification { get; set; }
|
public string? Specification { get; set; }
|
||||||
public DateTime To { get; set; }
|
public DateTime To { get; set; }
|
||||||
public DateTime From { get; set; }
|
public DateTime From { get; set; }
|
||||||
|
|||||||
@ -22,6 +22,6 @@ namespace CPRNIMS.Infrastructure.Entities.PO
|
|||||||
public byte PaymentTermsId { get; set; }
|
public byte PaymentTermsId { get; set; }
|
||||||
public byte PODId { get; set; }
|
public byte PODId { get; set; }
|
||||||
public byte POTypeId { get; set; }
|
public byte POTypeId { get; set; }
|
||||||
public DateTime? UpdatedDate { get; set; }
|
public string? PreparedBy { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ namespace CPRNIMS.Infrastructure.Entities.PO
|
|||||||
public int SupplierId { get; set; }
|
public int SupplierId { get; set; }
|
||||||
public string? SupplierName { get; set; }
|
public string? SupplierName { get; set; }
|
||||||
public DateTime DeliveryDate { get; set; }
|
public DateTime DeliveryDate { get; set; }
|
||||||
|
public string? DeliverTo { get; set; }
|
||||||
public DateTime? ProfInvoiceDate { get; set; }
|
public DateTime? ProfInvoiceDate { get; set; }
|
||||||
public string? ProfInvoiceNo { get; set; }
|
public string? ProfInvoiceNo { get; set; }
|
||||||
public string? CurrencyName { get; set; }
|
public string? CurrencyName { get; set; }
|
||||||
@ -32,5 +33,6 @@ namespace CPRNIMS.Infrastructure.Entities.PO
|
|||||||
public byte PODId { get; set; }
|
public byte PODId { get; set; }
|
||||||
public byte POTypeId { get; set; }
|
public byte POTypeId { get; set; }
|
||||||
public byte IncoTermsId { get; set; }
|
public byte IncoTermsId { get; set; }
|
||||||
|
public string? IncotermsName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ namespace CPRNIMS.Infrastructure.Entities.PO
|
|||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public long PODetailId { get; set; }
|
public long PODetailId { get; set; }
|
||||||
|
public long PRDetailsId { get; set; }
|
||||||
public long PRNo { get; set; }
|
public long PRNo { get; set; }
|
||||||
public decimal Qty { get; set; }
|
public decimal Qty { get; set; }
|
||||||
public decimal UnitPrice { get; set; }
|
public decimal UnitPrice { get; set; }
|
||||||
|
|||||||
@ -128,6 +128,7 @@ namespace CPRNIMS.Infrastructure.ViewModel.PO
|
|||||||
public string? PODate { get; set; }
|
public string? PODate { get; set; }
|
||||||
public string? RRDate { get; set; }
|
public string? RRDate { get; set; }
|
||||||
public long RRNo { get; set; }
|
public long RRNo { get; set; }
|
||||||
|
public bool IsUpdate { get; set; }
|
||||||
public decimal Quantity { get; set; }
|
public decimal Quantity { get; set; }
|
||||||
public decimal QuantityReceived { get; set; }
|
public decimal QuantityReceived { get; set; }
|
||||||
public long POId { get; set; }
|
public long POId { get; set; }
|
||||||
|
|||||||
@ -95,7 +95,12 @@ namespace CPRNIMS.WebApi.Controllers.PO
|
|||||||
poVM.PRItemList.Specification[i]
|
poVM.PRItemList.Specification[i]
|
||||||
);
|
);
|
||||||
|
|
||||||
var po = await _purchaseOrder.PostPutCustomPO(poDto);
|
var po = new CustomPO();
|
||||||
|
if(poDto.IsUpdate)
|
||||||
|
po=await _purchaseOrder.PutExistingPO(poDto);
|
||||||
|
else
|
||||||
|
po = await _purchaseOrder.PostPutCustomPO(poDto);
|
||||||
|
|
||||||
poResults.Add(po);
|
poResults.Add(po);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using CPRNIMS.Infrastructure.Helper;
|
|||||||
using CPRNIMS.Infrastructure.ViewModel.PO;
|
using CPRNIMS.Infrastructure.ViewModel.PO;
|
||||||
using CPRNIMS.WebApps.Controllers.Base;
|
using CPRNIMS.WebApps.Controllers.Base;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||||
|
|
||||||
namespace CPRNIMS.WebApps.Controllers.PO
|
namespace CPRNIMS.WebApps.Controllers.PO
|
||||||
{
|
{
|
||||||
|
|||||||
@ -78,9 +78,18 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" id="clearCustomPage" onclick="clearCustomPage()" class="btn btn-warning" data-bs-dismiss="modal">Cancel</button>
|
|
||||||
<button type="button" id="btnSubmitPO" onclick="postPutCustomPO()" class="btn btn-success">Submit</button>
|
<button type="button" id="clearCustomPage"
|
||||||
|
onclick="clearCustomPage()" class="btn btn-outline-secondary px-4" style="margin-bottom:20px; margin-right:10px;"
|
||||||
|
data-bs-dismiss="modal">
|
||||||
|
<i class="bi bi-x-circle me-2"></i>Cancel
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button id="btnSubmitPO" type="button" class="btn btn-success" onclick="postPutCustomPO();" style="margin-bottom:20px; margin-right:10px;">
|
||||||
|
<i class="bi bi-check-circle me-2"></i> Submit
|
||||||
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -158,7 +167,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<input hidden id="poTypeId"/>
|
<input hidden id="poTypeId"/>
|
||||||
<link href="~/css/po/CustomPOV2.css" rel="stylesheet" />
|
<link href="~/css/po/CustomPOV2.css" rel="stylesheet" />
|
||||||
<script src="~/JsFunctions/PO/CustomPOV5.js"></script>
|
<script src="~/JsFunctions/PO/CustomPOV6.js"></script>
|
||||||
@await Html.PartialAsync("PagesView/PR/_PRWOCanvass")
|
@await Html.PartialAsync("PagesView/PR/_PRWOCanvass")
|
||||||
@await Html.PartialAsync("PagesView/PO/_POScripts")
|
@await Html.PartialAsync("PagesView/PO/_POScripts")
|
||||||
</body>
|
</body>
|
||||||
@ -5,7 +5,7 @@
|
|||||||
<div id="loader" class="loader"></div>
|
<div id="loader" class="loader"></div>
|
||||||
</div>
|
</div>
|
||||||
<link href="~/css/common/rowhighlighter.css" rel="stylesheet" />
|
<link href="~/css/common/rowhighlighter.css" rel="stylesheet" />
|
||||||
<script src="~/jsfunctions/po/ComponentsV2.js"></script>
|
<script src="~/jsfunctions/po/ComponentsV3.js"></script>
|
||||||
<script src="~/jsfunctions/common/componentid.js"></script>
|
<script src="~/jsfunctions/common/componentid.js"></script>
|
||||||
<script src="~/jsfunctions/common/indexcard.js"></script>
|
<script src="~/jsfunctions/common/indexcard.js"></script>
|
||||||
<script src="~/jsfunctions/common/termsV2.js"></script>
|
<script src="~/jsfunctions/common/termsV2.js"></script>
|
||||||
@ -20,10 +20,10 @@
|
|||||||
<script src="~/JsFunctions/PO/POColumn.js"></script>
|
<script src="~/JsFunctions/PO/POColumn.js"></script>
|
||||||
<script src="~/jsfunctions/po/ApiV3.js"></script>
|
<script src="~/jsfunctions/po/ApiV3.js"></script>
|
||||||
<script src="~/jsfunctions/po/populatetable.js"></script>
|
<script src="~/jsfunctions/po/populatetable.js"></script>
|
||||||
<script src="~/jsfunctions/po/POVarV5.js"></script>
|
<script src="~/jsfunctions/po/POVarV6.js"></script>
|
||||||
<script src="~/jsfunctions/po/POViewV4.js"></script>
|
<script src="~/jsfunctions/po/POViewV4.js"></script>
|
||||||
<script src="~/jsfunctions/po/PopulateDopdownV2.js"></script>
|
<script src="~/jsfunctions/po/PopulateDopdownV3.js"></script>
|
||||||
<script src="~/jsfunctions/po/POPutPostV2.js"></script>
|
<script src="~/jsfunctions/po/POPutPostV3.js"></script>
|
||||||
<script src="~/jsfunctions/po/rowCallBackV4.js"></script>
|
<script src="~/jsfunctions/po/rowCallBackV4.js"></script>
|
||||||
|
|
||||||
<script src="~/jsfunctions/utilities/NewStyle.js"></script>
|
<script src="~/jsfunctions/utilities/NewStyle.js"></script>
|
||||||
|
|||||||
@ -28,7 +28,7 @@ function poTableComponent(id, loader) {
|
|||||||
async function customFormPOElemComponent(id) {
|
async function customFormPOElemComponent(id) {
|
||||||
document.getElementById("poNo").readOnly = true;
|
document.getElementById("poNo").readOnly = true;
|
||||||
document.getElementById('customPOHeading').innerHTML = 'Custom P.O. Creation';
|
document.getElementById('customPOHeading').innerHTML = 'Custom P.O. Creation';
|
||||||
populateIncoterms();
|
|
||||||
$('#poTypeId').val(id);
|
$('#poTypeId').val(id);
|
||||||
|
|
||||||
$("#supplierName").off('keyup').on('keyup', function () {
|
$("#supplierName").off('keyup').on('keyup', function () {
|
||||||
@ -64,13 +64,12 @@ async function customFormPOElemComponent(id) {
|
|||||||
await populatePOElem(id);
|
await populatePOElem(id);
|
||||||
|
|
||||||
// 3. NOW read from those inputs
|
// 3. NOW read from those inputs
|
||||||
|
populateIncoterms();
|
||||||
getPONoType(id);
|
getPONoType(id);
|
||||||
getPOType(id);
|
getPOType(id);
|
||||||
|
|
||||||
|
isUpdate = false;
|
||||||
}
|
}
|
||||||
/*function poNoComponent(id) {
|
|
||||||
populatePONoElem(id);
|
|
||||||
$('#poTypeId').val(id);
|
|
||||||
}*/
|
|
||||||
function poReportComponent(id) {
|
function poReportComponent(id) {
|
||||||
return $.ajax({
|
return $.ajax({
|
||||||
url: '/POMgmt/GetPOReportTable',
|
url: '/POMgmt/GetPOReportTable',
|
||||||
@ -1,243 +0,0 @@
|
|||||||
$(document).ready(function () {
|
|
||||||
loader = $('#overlay, #loader');
|
|
||||||
tableName = '#PODataTable';
|
|
||||||
totalSelectedLabel = $('#totalSelected');
|
|
||||||
tableElement = $(tableName);
|
|
||||||
|
|
||||||
poDataTable = $(tableName).DataTable({
|
|
||||||
initComplete: function () {
|
|
||||||
var api = this.api();
|
|
||||||
var data = api.ajax.json();
|
|
||||||
if (!data || !data.data || data.data === "No Data") {
|
|
||||||
$('.dataTables_empty').html("No record available");
|
|
||||||
toggleSubmitButton();
|
|
||||||
}
|
|
||||||
calculateTotalPesoAmount();
|
|
||||||
},
|
|
||||||
columns: colCustomPO,
|
|
||||||
columnDefs:colDefCustomPO,
|
|
||||||
language: {
|
|
||||||
emptyTable: "No items added yet"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
async function fetchAndPopulatePOFormData(poType, poId = null) {
|
|
||||||
loader = $('#overlay, #loader').css('z-index', 1060);
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
$.ajax({
|
|
||||||
url: '/POMgmt/GetPOFormData',
|
|
||||||
type: 'GET',
|
|
||||||
data: { poId: poId },
|
|
||||||
beforeSend: function () {
|
|
||||||
loader.show();
|
|
||||||
},
|
|
||||||
complete: function () {
|
|
||||||
loader.hide();
|
|
||||||
},
|
|
||||||
success: function (response) {
|
|
||||||
const d = response;
|
|
||||||
|
|
||||||
document.getElementById("poType").value = poType;
|
|
||||||
$('#poNoFinal').val($('#poNo').val());
|
|
||||||
// --- Header Fields ---
|
|
||||||
if (d.header) {
|
|
||||||
document.getElementById("supplierName").value = d.header.supplierName || '';
|
|
||||||
|
|
||||||
$('#supplierId').val(d.header.supplierId || 0);
|
|
||||||
|
|
||||||
console.log(d.header.supplierId);
|
|
||||||
console.log(d.header.supplierName);
|
|
||||||
|
|
||||||
$('#deliveryDate').val(d.header.deliveryDate || '');
|
|
||||||
$('#piDate').val(d.header.profInvoiceDate || '');
|
|
||||||
$('#piNo').val(d.header.profInvoiceNo || '');
|
|
||||||
$('#currencyCER').val(d.header.currencyCER || '59.00');
|
|
||||||
$('#podId').val(d.header.podId || 0);
|
|
||||||
$('#shippingInstructionId').val(1 || 0);
|
|
||||||
$('#incotermsName').val(d.header.incoTermsId || 0);
|
|
||||||
$('#incoTermsId').val(d.header.incoTermsId || 0);
|
|
||||||
$('#C-paymentTerms').val(d.header.paymentTerms || '');
|
|
||||||
$('#C-paymentTermsId').val(d.header.paymentTermsId || 0);
|
|
||||||
$('#remarks').val(d.header.remarks || '');
|
|
||||||
$('#grossAmountUSD').val(d.header.grossAmountUSD || 0);
|
|
||||||
$('#finalAmountUSD').val(d.header.finalAmountUSD || 0);
|
|
||||||
$('#grossAmountPHP').val(d.header.grossAmountPHP || 0);
|
|
||||||
$('#finalAmountPHP').val(d.header.finalAmountPHP || 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- DataTable: Line Items ---
|
|
||||||
if (poDataTable) {
|
|
||||||
poDataTable.clear();
|
|
||||||
if (d.lineItems && d.lineItems.length > 0) {
|
|
||||||
poDataTable.rows.add(d.lineItems).draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- DataTable: Charges ---
|
|
||||||
if (d.charges && d.charges.length > 0) {
|
|
||||||
const $tbody = $('#DestChargesTable tbody');
|
|
||||||
$tbody.empty(); // clear existing rows first
|
|
||||||
|
|
||||||
d.charges.forEach(function (charge) {
|
|
||||||
var newRow = '<tr>' +
|
|
||||||
'<td style="display: none;">' + charge.otherChargesId + '</td>' +
|
|
||||||
'<td>' + charge.otherChargesName + '</td>' +
|
|
||||||
'<td>' + charge.amount + '</td>' +
|
|
||||||
'<td><button class="btn btn-default" onclick="removeRow(this)" data-otherChargesId="' + charge.otherChargesId + '">' +
|
|
||||||
'<i class="fa-solid fa-trash fa-xl" style="color: #ff0000;" aria-hidden="true"></i>' +
|
|
||||||
'</button></td>' +
|
|
||||||
'</tr>';
|
|
||||||
$tbody.append(newRow);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Recalculate after populating charges
|
|
||||||
calculateFinalPesoAmount($('#poTypeId').val());
|
|
||||||
calculateFinalUsdAmount();
|
|
||||||
lessDiscount();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Docs Required ---
|
|
||||||
if (d.docsRequired && d.docsRequired.length > 0) {
|
|
||||||
$('#docRequiredId').val(
|
|
||||||
d.docsRequired.map(x => x.docName).join('\n')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve();
|
|
||||||
},
|
|
||||||
error: function (xhr, status, error) {
|
|
||||||
console.error("Error loading PO form data:", error);
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function enablePONoAutocomplete() {
|
|
||||||
|
|
||||||
document.getElementById('customPOHeading').innerHTML = 'Custom P.O. Modification';
|
|
||||||
customFormPOElemComponent(4);
|
|
||||||
document.getElementById("poNo").removeAttribute("readonly");
|
|
||||||
document.getElementById("poNo").value ='';
|
|
||||||
document.getElementById("poNo").focus();
|
|
||||||
document.getElementById("poType").value = "0";
|
|
||||||
popPONo();
|
|
||||||
}
|
|
||||||
function lessDiscount() {
|
|
||||||
let amount = parseFloat($('#finalAmount').val()) || 0;
|
|
||||||
let discount = parseFloat($('#discount').val()) || 0;
|
|
||||||
|
|
||||||
if (!isNaN(discount) && discount > 0) {
|
|
||||||
let finalAmount = amount - discount;
|
|
||||||
$('#finalAmount').val(numberWithCommas(finalAmount));
|
|
||||||
} else {
|
|
||||||
$('#finalAmount').val(numberWithCommas(amount));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateTotalPesoAmount(poTypeId) {
|
|
||||||
$(tableName + ' tbody').on('input', '.unitPrice,.qty', function () {
|
|
||||||
const $row = $(this).closest('tr');
|
|
||||||
const qty = parseFloat($row.find('.qty').eq(0).val()) || 0;
|
|
||||||
const price = parseFloat($row.find('.unitPrice').eq(0).val()) || 0;
|
|
||||||
|
|
||||||
const grossAmount = (qty * price).toFixed(4);
|
|
||||||
$row.find('td').eq(8).text(grossAmount);
|
|
||||||
|
|
||||||
var updatedPoTypeId = $('#poTypeId').val();
|
|
||||||
if (updatedPoTypeId == 1) {
|
|
||||||
$('#vatRate').on('input', calculateFinalPesoAmount);
|
|
||||||
}
|
|
||||||
calculateFinalPesoAmount(updatedPoTypeId);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateFinalPesoAmount(poTypeId) {
|
|
||||||
|
|
||||||
let grossAmount = 0;
|
|
||||||
let chargesAmount = 0;
|
|
||||||
let finalAmount = 0;
|
|
||||||
$('#PODataTable tbody tr').each(function () {
|
|
||||||
const $row = $(this);
|
|
||||||
const totalAmountStr = $row.find('td').eq(8).text().replace(/,/g, '');
|
|
||||||
const totalAmount = parseFloat(totalAmountStr) || 0;
|
|
||||||
grossAmount += totalAmount;
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#DestChargesTable tbody tr').each(function () {
|
|
||||||
const $row = $(this);
|
|
||||||
const totalAmountStr = $row.find('td').eq(4).text().replace(/,/g, '');
|
|
||||||
const totalAmount = parseFloat(totalAmountStr) || 0;
|
|
||||||
chargesAmount += totalAmount;
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#grossAmount').val(numberWithCommas(grossAmount));
|
|
||||||
|
|
||||||
|
|
||||||
if (poTypeId == 1) {
|
|
||||||
const vatRateInput = $('#vatRate').val();
|
|
||||||
|
|
||||||
const vatAmount = (vatRateInput / 100) * grossAmount;
|
|
||||||
|
|
||||||
const grossWithVat = parseFloat(grossAmount) + parseFloat(vatAmount) + parseFloat(chargesAmount);
|
|
||||||
finalAmount = grossWithVat.toFixed(4);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
const grossWithVat = parseFloat(grossAmount) + parseFloat(chargesAmount);
|
|
||||||
finalAmount = grossWithVat.toFixed(4);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#finalAmount').val(numberWithCommas(finalAmount));
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateFinalUsdAmount() {
|
|
||||||
const currencyCer = parseFloat($('#currencyCER').val()) || 0;
|
|
||||||
let grossAmount = 0;
|
|
||||||
let chargesAmount = 0;
|
|
||||||
let finalAmount = 0;
|
|
||||||
let finalConvertedAmount = 0;
|
|
||||||
$('#PODataTable tbody tr').each(function () {
|
|
||||||
const $row = $(this);
|
|
||||||
const totalAmountStr = $row.find('td').eq(8).text().replace(/,/g, '');
|
|
||||||
const totalAmount = parseFloat(totalAmountStr) || 0;
|
|
||||||
grossAmount += totalAmount;
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#DestChargesTable tbody tr').each(function () {
|
|
||||||
const $row = $(this);
|
|
||||||
const totalAmountStr = $row.find('td').eq(4).text().replace(/,/g, '');
|
|
||||||
const totalAmount = parseFloat(totalAmountStr) || 0;
|
|
||||||
chargesAmount += totalAmount;
|
|
||||||
});
|
|
||||||
const convertedPhpAmount = parseFloat(grossAmount) * currencyCer;
|
|
||||||
const convertedChargesAmount = parseFloat(chargesAmount) * currencyCer;
|
|
||||||
// Update the total PHP amount
|
|
||||||
$('#grossAmountPHP').val(numberWithCommas(convertedPhpAmount));
|
|
||||||
|
|
||||||
finalConvertedAmount = parseFloat(convertedPhpAmount) + parseFloat(convertedChargesAmount);
|
|
||||||
|
|
||||||
$('#finalAmountPHP').val(numberWithCommas(finalConvertedAmount));
|
|
||||||
|
|
||||||
// Update the total USD amount
|
|
||||||
$('#grossAmountUSD').val(numberWithCommas(grossAmount));
|
|
||||||
|
|
||||||
finalAmount = parseFloat(grossAmount) + parseFloat(chargesAmount);
|
|
||||||
|
|
||||||
$('#finalAmountUSD').val(numberWithCommas(finalAmount));
|
|
||||||
}
|
|
||||||
function calculateTotalUsdAmount() {
|
|
||||||
let totalAmountUSD = 0;
|
|
||||||
$('#PODataTable tbody').on('input', '.unitPrice,.qty', function () {
|
|
||||||
const $row = $(this).closest('tr');
|
|
||||||
const qty = parseFloat($row.find('.qty').eq(0).val()) || 0;
|
|
||||||
const price = parseFloat($row.find('.unitPrice').eq(0).val()) || 0;
|
|
||||||
|
|
||||||
const grossAmount = (qty * price).toFixed(4);
|
|
||||||
$row.find('td').eq(8).text(grossAmount);
|
|
||||||
totalAmountUSD += grossAmount;
|
|
||||||
calculateFinalUsdAmount();
|
|
||||||
$('#currencyCER').on('input', calculateFinalUsdAmount);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
286
CPRNIMS.WebApps/wwwroot/JsFunctions/PO/CustomPOV6.js
Normal file
286
CPRNIMS.WebApps/wwwroot/JsFunctions/PO/CustomPOV6.js
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
$(document).ready(function () {
|
||||||
|
loader = $('#overlay, #loader');
|
||||||
|
tableName = '#PODataTable';
|
||||||
|
totalSelectedLabel = $('#totalSelected');
|
||||||
|
tableElement = $(tableName);
|
||||||
|
|
||||||
|
poDataTable = $(tableName).DataTable({
|
||||||
|
initComplete: function () {
|
||||||
|
var api = this.api();
|
||||||
|
var data = api.ajax.json();
|
||||||
|
if (!data || !data.data || data.data === "No Data") {
|
||||||
|
$('.dataTables_empty').html("No record available");
|
||||||
|
toggleSubmitButton();
|
||||||
|
}
|
||||||
|
calculateTotalPesoAmount();
|
||||||
|
},
|
||||||
|
columns: colCustomPO,
|
||||||
|
columnDefs:colDefCustomPO,
|
||||||
|
language: {
|
||||||
|
emptyTable: "No items added yet"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
async function fetchAndPopulatePOFormData(poType, poId = null) {
|
||||||
|
loader = $('#overlay, #loader').css('z-index', 1060);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
$.ajax({
|
||||||
|
url: '/POMgmt/GetPOFormData',
|
||||||
|
type: 'GET',
|
||||||
|
data: { poId: poId },
|
||||||
|
beforeSend: function () {
|
||||||
|
loader.show();
|
||||||
|
},
|
||||||
|
complete: function () {
|
||||||
|
loader.hide();
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
const d = response;
|
||||||
|
|
||||||
|
document.getElementById("poType").value = poType;
|
||||||
|
$('#poNoFinal').val($('#poNo').val());
|
||||||
|
// --- Header Fields ---
|
||||||
|
if (d.header) {
|
||||||
|
document.getElementById("supplierName").value = d.header.supplierName || '';
|
||||||
|
|
||||||
|
$('#supplierId').val(d.header.supplierId || 0);
|
||||||
|
if (d.header?.deliveryDate) {
|
||||||
|
let deliveryDate = d.header.deliveryDate.split("T")[0];
|
||||||
|
$('#deliveryDate').val(deliveryDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d.header?.profInvoiceDate) {
|
||||||
|
let profInvoiceDate = d.header.profInvoiceDate.split("T")[0];
|
||||||
|
$('#piDate').val(profInvoiceDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#deliverTo').val(d.header.deliverTo || '');
|
||||||
|
|
||||||
|
$('#piNo').val(d.header.profInvoiceNo || '');
|
||||||
|
$('#currencyCER').val(d.header.currencyCER || '59.00');
|
||||||
|
$('#podId').val(d.header.podId || 0);
|
||||||
|
$('#shippingInstructionId').val(1);
|
||||||
|
$('#discount').val(d.header.discount || 0);
|
||||||
|
|
||||||
|
$('#C-paymentTerms').val(d.header.paymentTerms || '');
|
||||||
|
$('#C-paymentTermsId').val(d.header.paymentTermsId || 0);
|
||||||
|
$('#remarks').val(d.header.remarks || '');
|
||||||
|
$('#grossAmountUSD').val(d.header.grossAmountUSD || 0);
|
||||||
|
|
||||||
|
$('#finalAmountUSD').val(d.header.finalAmountUSD || 0);
|
||||||
|
$('#grossAmountPHP').val(d.header.grossAmountPHP || 0);
|
||||||
|
$('#finalAmountPHP').val(d.header.finalAmountPHP || 0);
|
||||||
|
|
||||||
|
$('#finalAmount').val(d.header.finalAmountPHP || 0);
|
||||||
|
$('#grossAmount').val(d.header.grossAmountPHP || 0);
|
||||||
|
|
||||||
|
console.log('d.header.incotermsName', d.header.incotermsName);
|
||||||
|
|
||||||
|
$('#incoTermsId').val(d.header.incotermsId);
|
||||||
|
|
||||||
|
$('#incotermsName').val(d.header.incotermsName || '');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- DataTable: Line Items ---
|
||||||
|
if (poDataTable) {
|
||||||
|
poDataTable.clear();
|
||||||
|
if (d.lineItems && d.lineItems.length > 0) {
|
||||||
|
poDataTable.rows.add(d.lineItems).draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- DataTable: Charges ---
|
||||||
|
if (d.charges && d.charges.length > 0) {
|
||||||
|
const $tbody = $('#DestChargesTable tbody');
|
||||||
|
$tbody.empty();
|
||||||
|
|
||||||
|
d.charges.forEach(function (charge) {
|
||||||
|
var newRow = '<tr>' +
|
||||||
|
'<td style="display: none;">' + charge.otherChargesId + '</td>' +
|
||||||
|
'<td>' + charge.otherChargesName + '</td>' +
|
||||||
|
'<td>' + charge.amount + '</td>' +
|
||||||
|
'<td><button class="btn btn-default" onclick="removeRow(this)" data-otherChargesId="' + charge.otherChargesId + '">' +
|
||||||
|
'<i class="fa-solid fa-trash fa-xl" style="color: #ff0000;" aria-hidden="true"></i>' +
|
||||||
|
'</button></td>' +
|
||||||
|
'</tr>';
|
||||||
|
$tbody.append(newRow);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Docs Required ---
|
||||||
|
if (d.docsRequired && d.docsRequired.length > 0) {
|
||||||
|
$('#docRequiredId').val(
|
||||||
|
d.docsRequired.map(x => x.docName).join('\n')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
console.error("Error loading PO form data:", error);
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function enablePONoAutocomplete() {
|
||||||
|
poDataTable.clear().draw();
|
||||||
|
document.getElementById('customPOHeading').innerHTML = 'Custom P.O. Modification';
|
||||||
|
customFormPOElemComponent(4);
|
||||||
|
document.getElementById("poNo").removeAttribute("readonly");
|
||||||
|
document.getElementById("poNo").value ='';
|
||||||
|
document.getElementById("poNo").focus();
|
||||||
|
document.getElementById("poType").value = "0";
|
||||||
|
popPONo();
|
||||||
|
|
||||||
|
}
|
||||||
|
// =====================================================================
|
||||||
|
// UTILITIES
|
||||||
|
// =====================================================================
|
||||||
|
|
||||||
|
function getGrossFromTable() {
|
||||||
|
let gross = 0;
|
||||||
|
|
||||||
|
const table = $('#PODataTable').DataTable();
|
||||||
|
|
||||||
|
table.rows().every(function () {
|
||||||
|
const rowNode = this.node();
|
||||||
|
const cellText = $(rowNode).find('td').eq(8).text().replace(/,/g, '');
|
||||||
|
const val = parseFloat(cellText) || 0;
|
||||||
|
gross += val;
|
||||||
|
});
|
||||||
|
|
||||||
|
return gross;
|
||||||
|
}
|
||||||
|
function getChargesFromTable() {
|
||||||
|
let charges = 0;
|
||||||
|
$('#DestChargesTable tbody tr').each(function () {
|
||||||
|
const val = parseFloat($(this).find('td').eq(2).text().replace(/,/g, '')) || 0;
|
||||||
|
charges += val;
|
||||||
|
});
|
||||||
|
|
||||||
|
return charges;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDiscount() {
|
||||||
|
return parseFloat($('#discount').val()) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPoTypeId() {
|
||||||
|
return parseInt($('#poTypeId').val()) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function recalculateAll() {
|
||||||
|
const poTypeId = getPoTypeId();
|
||||||
|
const grossAmount = getGrossFromTable();
|
||||||
|
const chargesAmount = getChargesFromTable();
|
||||||
|
|
||||||
|
const discount = getDiscount();
|
||||||
|
const currencyCER = parseFloat($('#currencyCER').val()) || 1;
|
||||||
|
|
||||||
|
const grossAfterDiscount = grossAmount - parseFloat(discount.toFixed(4));
|
||||||
|
|
||||||
|
if (poTypeId === 3) {
|
||||||
|
|
||||||
|
const finalAmountUSD = grossAfterDiscount + chargesAmount;
|
||||||
|
const grossAmountPHP = grossAfterDiscount * currencyCER;
|
||||||
|
const finalAmountPHP = finalAmountUSD * currencyCER;
|
||||||
|
|
||||||
|
|
||||||
|
$('#grossAmountUSD').val(numberWithCommas(grossAfterDiscount.toFixed(4)));
|
||||||
|
$('#finalAmountUSD').val(numberWithCommas(finalAmountUSD.toFixed(4)));
|
||||||
|
$('#grossAmountPHP').val(numberWithCommas(grossAmountPHP.toFixed(4)));
|
||||||
|
$('#finalAmountPHP').val(numberWithCommas(finalAmountPHP.toFixed(4)));
|
||||||
|
|
||||||
|
// Hide PHP-only fields, show USD fields
|
||||||
|
$('#grossAmount, #finalAmount').val('');
|
||||||
|
|
||||||
|
} else if (poTypeId === 1 ) {
|
||||||
|
|
||||||
|
const vatRate = parseFloat($('#vatRate').val()) || 0;
|
||||||
|
const vatAmount = (vatRate / 100) * grossAfterDiscount;
|
||||||
|
const finalAmountPHP = grossAfterDiscount + vatAmount + chargesAmount;
|
||||||
|
|
||||||
|
$('#grossAmount').val(numberWithCommas(grossAfterDiscount.toFixed(4)));
|
||||||
|
$('#finalAmount').val(numberWithCommas(finalAmountPHP.toFixed(4)));
|
||||||
|
|
||||||
|
$('#grossAmountUSD, #finalAmountUSD, #grossAmountPHP, #finalAmountPHP').val('');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const finalAmount = grossAfterDiscount + chargesAmount;
|
||||||
|
|
||||||
|
$('#grossAmount').val(numberWithCommas(grossAfterDiscount.toFixed(4)));
|
||||||
|
$('#finalAmount').val(numberWithCommas(finalAmount.toFixed(4)));
|
||||||
|
|
||||||
|
$('#grossAmountUSD, #finalAmountUSD, #grossAmountPHP, #finalAmountPHP').val('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================
|
||||||
|
// ROW-LEVEL: Update TotalAmount cell then trigger recalc
|
||||||
|
// =====================================================================
|
||||||
|
|
||||||
|
function bindTableInputEvents() {
|
||||||
|
$(tableName + ' tbody').on('input', '.unitPrice, .qty', function () {
|
||||||
|
const $row = $(this).closest('tr');
|
||||||
|
const qty = parseFloat($row.find('.qty').eq(0).val()) || 0;
|
||||||
|
const price = parseFloat($row.find('.unitPrice').eq(0).val()) || 0;
|
||||||
|
|
||||||
|
$row.find('td').eq(8).text((qty * price).toFixed(4));
|
||||||
|
|
||||||
|
recalculateAll();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================
|
||||||
|
// SECONDARY INPUT TRIGGERS
|
||||||
|
// =====================================================================
|
||||||
|
|
||||||
|
function bindSecondaryInputEvents() {
|
||||||
|
// Discount changed → recalculate
|
||||||
|
$('#discount').on('input', function () {
|
||||||
|
recalculateAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
// VAT rate changed → recalculate (only relevant for POTypeId=1)
|
||||||
|
$('#vatRate').on('input', function () {
|
||||||
|
recalculateAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Currency exchange rate changed → recalculate (only relevant for POTypeId=3)
|
||||||
|
$('#currencyCER').on('input', function () {
|
||||||
|
recalculateAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
// PO Type changed → recalculate with new logic branch
|
||||||
|
$('#poTypeId').on('change', function () {
|
||||||
|
recalculateAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Charges table changes → recalculate
|
||||||
|
$('#DestChargesTable').on('input change', function () {
|
||||||
|
recalculateAll();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// =====================================================================
|
||||||
|
// INIT — call on page load / form load
|
||||||
|
// =====================================================================
|
||||||
|
|
||||||
|
function initPOCalculations() {
|
||||||
|
bindTableInputEvents();
|
||||||
|
bindSecondaryInputEvents();
|
||||||
|
recalculateAll(); // Populate on load from existing data
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Kept for backward compatibility if called elsewhere ────────────
|
||||||
|
function lessDiscount() { recalculateAll(); }
|
||||||
|
function calculateFinalPesoAmount() { recalculateAll(); }
|
||||||
|
function calculateFinalUsdAmount() { recalculateAll(); }
|
||||||
|
function calculateTotalPesoAmount() { bindTableInputEvents(); }
|
||||||
|
function calculateTotalUsdAmount() { bindTableInputEvents(); }
|
||||||
@ -219,6 +219,62 @@ function postPOToSupplier() {
|
|||||||
}
|
}
|
||||||
function postPutCustomPO() {
|
function postPutCustomPO() {
|
||||||
loader = $('#overlay, #loader').css('z-index', 1070);
|
loader = $('#overlay, #loader').css('z-index', 1070);
|
||||||
|
|
||||||
|
if (isUpdate) {
|
||||||
|
updateExistingPO()
|
||||||
|
} else {
|
||||||
|
docRequiredList();
|
||||||
|
otherCharges();
|
||||||
|
|
||||||
|
POTypeId = $('#poTypeId').val();
|
||||||
|
PONo = $('#poNo').val();
|
||||||
|
var PoRemarks = $('#remarks').val() ?? 'N/A';
|
||||||
|
|
||||||
|
if (!prItemList()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!poValidateParameters(POTypeId, 'customPO', false)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let Discount = $('#discount').val();
|
||||||
|
showConfirmation({
|
||||||
|
title: 'Create Purchase Order',
|
||||||
|
message: 'Are you sure you want to create this PO? This action cannot be undone.',
|
||||||
|
type: 'warning',
|
||||||
|
confirmText: 'Yes, Create PO',
|
||||||
|
cancelText: 'Cancel'
|
||||||
|
}).then((confirmed) => {
|
||||||
|
if (confirmed) {
|
||||||
|
$.ajax($.extend({
|
||||||
|
url: endpoint.PostPutCustomPO,
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
DocRequiredList, OtherChargesList, PRItemList,
|
||||||
|
POTypeId, PONo, IncotermsId, ProfInvoiceNo, ProfInvoiceDate,
|
||||||
|
ShippingInstructionId, PodId, PaymentTermsId,
|
||||||
|
PoRemarks, Discount, SupplierId, DeliveryDate, DeliverTo
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
if (response.success) {
|
||||||
|
clearCustomPOParam();
|
||||||
|
const poNo = response.data?.customPOs?.[0]?.poNo || 'N/A';
|
||||||
|
$('#poNoFinal').val(poNo);
|
||||||
|
if (typeof PRItemTable !== "undefined" && PRItemTable) {
|
||||||
|
PRItemTable.ajax.reload();
|
||||||
|
}
|
||||||
|
isLoaded = false;
|
||||||
|
showToast('success', 'PO Created successfully with final PO#: ' + poNo, 'Success', 4000);
|
||||||
|
} else {
|
||||||
|
showToast('error', response.response, 'PO Creation failed', 4000);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: errorHandler
|
||||||
|
}, beforeComplete(loader)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function updateExistingPO() {
|
||||||
docRequiredList();
|
docRequiredList();
|
||||||
otherCharges();
|
otherCharges();
|
||||||
|
|
||||||
@ -229,15 +285,17 @@ function postPutCustomPO() {
|
|||||||
if (!prItemList()) {
|
if (!prItemList()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!poValidateParameters(POTypeId,'customPO',false)) {
|
if (!poValidateParameters(POTypeId, 'customPO', false)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let Discount = $('#discount').val();
|
let Discount = $('#discount').val();
|
||||||
|
let IsUpdate = true;
|
||||||
|
|
||||||
showConfirmation({
|
showConfirmation({
|
||||||
title: 'Create Purchase Order',
|
title: 'Update Purchase Order',
|
||||||
message: 'Are you sure you want to create this PO? This action cannot be undone.',
|
message: 'Are you sure you want to update this PO? This action cannot be undone.',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
confirmText: 'Yes, Create PO',
|
confirmText: 'Yes, Update PO',
|
||||||
cancelText: 'Cancel'
|
cancelText: 'Cancel'
|
||||||
}).then((confirmed) => {
|
}).then((confirmed) => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
@ -248,18 +306,20 @@ function postPutCustomPO() {
|
|||||||
DocRequiredList, OtherChargesList, PRItemList,
|
DocRequiredList, OtherChargesList, PRItemList,
|
||||||
POTypeId, PONo, IncotermsId, ProfInvoiceNo, ProfInvoiceDate,
|
POTypeId, PONo, IncotermsId, ProfInvoiceNo, ProfInvoiceDate,
|
||||||
ShippingInstructionId, PodId, PaymentTermsId,
|
ShippingInstructionId, PodId, PaymentTermsId,
|
||||||
PoRemarks, Discount, SupplierId, DeliveryDate, DeliverTo
|
PoRemarks, Discount, SupplierId, DeliveryDate, DeliverTo, IsUpdate
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
clearCustomPOParam();
|
clearCustomPOParam();
|
||||||
const poNo = response.data?.customPOs?.[0]?.poNo || 'N/A';
|
const poNo = $('#poNoFinal').val();
|
||||||
$('#poNoFinal').val(poNo);
|
|
||||||
PRItemTable.ajax.reload();
|
if (typeof PRItemTable !== "undefined" && PRItemTable) {
|
||||||
|
PRItemTable.ajax.reload();
|
||||||
|
}
|
||||||
isLoaded = false;
|
isLoaded = false;
|
||||||
showToast('success', 'PO Created successfully with final PO#: ' + poNo, 'Success', 4000);
|
showToast('success', 'PO Updated successfully with final PO#: ' + poNo, 'Success', 4000);
|
||||||
} else {
|
} else {
|
||||||
showToast('error', response.response, 'PO Creation failed', 4000);
|
showToast('error', response.response, 'PO Updating failed', 4000);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: errorHandler
|
error: errorHandler
|
||||||
@ -432,7 +492,6 @@ function prItemList() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
if (PRItemList.length === 0) {
|
if (PRItemList.length === 0) {
|
||||||
alert('Please select an item!');
|
|
||||||
showToast('error', 'Please select an item in the list!',
|
showToast('error', 'Please select an item in the list!',
|
||||||
'Creation of purchase order failed!', 4000);
|
'Creation of purchase order failed!', 4000);
|
||||||
return false;
|
return false;
|
||||||
@ -734,30 +793,43 @@ function AddDiscount() {
|
|||||||
|
|
||||||
function removeRowMain(rowData) {
|
function removeRowMain(rowData) {
|
||||||
var poDataTable = $('#PODataTable').DataTable();
|
var poDataTable = $('#PODataTable').DataTable();
|
||||||
var prItemTable = $('#PRItemTable').DataTable();
|
|
||||||
|
|
||||||
// Remove the row from PODataTable
|
// Remove the row from PODataTable
|
||||||
poDataTable
|
if (typeof poDataTable !== "undefined" && poDataTable) {
|
||||||
.rows(function (idx, data, node) {
|
poDataTable
|
||||||
return data.prDetailsId === rowData.prDetailsId;
|
.rows(function (idx, data, node) {
|
||||||
})
|
return data.prDetailsId === rowData.prDetailsId;
|
||||||
.remove()
|
})
|
||||||
.draw();
|
.remove()
|
||||||
|
.draw();
|
||||||
|
|
||||||
|
calculateTotalPesoAmount($('#poTypeId').val());
|
||||||
|
calculateFinalPesoAmount($('#poTypeId').val());
|
||||||
|
toggleSubmitButton();
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the row already exists in PRItemTable
|
// Check if the row already exists in PRItemTable
|
||||||
var existingRow = prItemTable
|
if (typeof prItemTable !== "undefined" && prItemTable) {
|
||||||
.rows(function (idx, data, node) {
|
var prItemTable = $('#PRItemTable').DataTable({
|
||||||
return data.prDetailsId === rowData.prDetailsId;
|
destroy: true,
|
||||||
})
|
columns: [
|
||||||
.data();
|
{ data: 'prDetailsId', visible: false },
|
||||||
|
{ data: 'itemNo' },
|
||||||
if (existingRow.length === 0) {
|
{ data: 'itemName' },
|
||||||
// Add the row back to PRItemTable
|
{ data: 'specification' },
|
||||||
prItemTable.row.add(rowData).draw();
|
{ data: 'qty' },
|
||||||
|
{ data: 'uomName' },
|
||||||
|
{
|
||||||
|
data: 'unitPrice',
|
||||||
|
render: $.fn.dataTable.render.number(',', '.', 2)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'totalAmount',
|
||||||
|
render: $.fn.dataTable.render.number(',', '.', 2)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
calculateTotalPesoAmount($('#poTypeId').val());
|
|
||||||
calculateFinalPesoAmount($('#poTypeId').val());
|
|
||||||
toggleSubmitButton();
|
|
||||||
}
|
}
|
||||||
function removeRow(button) {
|
function removeRow(button) {
|
||||||
$(button).closest('tr').remove();
|
$(button).closest('tr').remove();
|
||||||
@ -3,6 +3,7 @@ let isLoaded = false;
|
|||||||
let IsHistory = false;
|
let IsHistory = false;
|
||||||
let IsPrint = false;
|
let IsPrint = false;
|
||||||
let isAdded = false;
|
let isAdded = false;
|
||||||
|
let isUpdate = false;
|
||||||
var blankImage = 'blank_signature.png';
|
var blankImage = 'blank_signature.png';
|
||||||
var DocRequiredList = [];
|
var DocRequiredList = [];
|
||||||
var OtherChargesList = [];
|
var OtherChargesList = [];
|
||||||
@ -670,6 +670,7 @@ function getPOType(poType) {
|
|||||||
$('#remarks').val('');
|
$('#remarks').val('');
|
||||||
$('#deliveryDate').val('');
|
$('#deliveryDate').val('');
|
||||||
$('#poNo').val(poNo);
|
$('#poNo').val(poNo);
|
||||||
|
$('#poNoFinal').val(poNo);
|
||||||
$('#poType').val(poType);
|
$('#poType').val(poType);
|
||||||
}
|
}
|
||||||
function poReferenceComponent(id) {
|
function poReferenceComponent(id) {
|
||||||
|
|||||||
@ -31,13 +31,19 @@
|
|||||||
$('#poNo').val(ui.item.label);
|
$('#poNo').val(ui.item.label);
|
||||||
$('#poId').val(ui.item.value);
|
$('#poId').val(ui.item.value);
|
||||||
$('#poTypeId').val(ui.item.value2);
|
$('#poTypeId').val(ui.item.value2);
|
||||||
console.log("Selected PO ID:", ui.item.value);
|
|
||||||
|
|
||||||
//#1
|
|
||||||
populatePOModificationForm(ui.item.value2);
|
populatePOModificationForm(ui.item.value2);
|
||||||
|
populateIncoterms();
|
||||||
fetchAndPopulatePOFormData(ui.item.value2,ui.item.value);
|
fetchAndPopulatePOFormData(ui.item.value2,ui.item.value);
|
||||||
|
|
||||||
|
$("#supplierName").off('keyup').on('keyup', function () {
|
||||||
|
populateSupplier();
|
||||||
|
});
|
||||||
|
// Recalculate after populating charges
|
||||||
|
calculateTotalPesoAmount();
|
||||||
|
calculateFinalUsdAmount();
|
||||||
|
document.getElementById('btnSubmitPO').style.display = 'block';
|
||||||
|
isUpdate = true;
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
focus: function (event, ui) {
|
focus: function (event, ui) {
|
||||||
@ -59,18 +65,11 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function populatePOModificationForm(id) {
|
async function populatePOModificationForm(id) {
|
||||||
populateIncoterms();
|
|
||||||
|
|
||||||
$("#supplierName").off('keyup').on('keyup', function () {
|
|
||||||
populateSupplier();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
console.warn("No PO Type selected.");
|
console.warn("No PO Type selected.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Load the custom form container FIRST
|
|
||||||
await new Promise(function (resolve, reject) {
|
await new Promise(function (resolve, reject) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/POMgmt/GetCustomFormPOElem',
|
url: '/POMgmt/GetCustomFormPOElem',
|
||||||
@ -99,6 +98,7 @@ function populatePOElem(id) {
|
|||||||
url: endpoint.GetLatestPO2,
|
url: endpoint.GetLatestPO2,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
poDataTable.clear().draw();
|
||||||
if (data && data.data && data.data.length > 0) {
|
if (data && data.data && data.data.length > 0) {
|
||||||
var item = data.data[0];
|
var item = data.data[0];
|
||||||
$('#si-poNo').val('00' + (parseFloat(item.poNoVatInc) + 1));
|
$('#si-poNo').val('00' + (parseFloat(item.poNoVatInc) + 1));
|
||||||
@ -111,6 +111,12 @@ function printPRItem() {
|
|||||||
<style>
|
<style>
|
||||||
@media print {
|
@media print {
|
||||||
/* Reduce overall print font */
|
/* Reduce overall print font */
|
||||||
|
{
|
||||||
|
color: #000 !important;
|
||||||
|
background-color: #fff !important;
|
||||||
|
border-color: #000 !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
body {
|
body {
|
||||||
font-size: 10px !important;
|
font-size: 10px !important;
|
||||||
}
|
}
|
||||||
@ -163,7 +169,7 @@ function printPRItem() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
border: 1px #ddd !important;
|
border: 1px solid #000 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-body {
|
.card-body {
|
||||||
@ -172,24 +178,14 @@ function printPRItem() {
|
|||||||
|
|
||||||
|
|
||||||
th {
|
th {
|
||||||
background-color: #444 !important;
|
background: #fff !important;
|
||||||
color: white !important;
|
color: #000 !important;
|
||||||
|
|
||||||
-webkit-print-color-adjust: exact;
|
|
||||||
print-color-adjust: exact;
|
|
||||||
}
|
|
||||||
|
|
||||||
tbody tr:nth-child(even) {
|
|
||||||
background-color: #666 !important;
|
|
||||||
color: white !important;
|
|
||||||
-webkit-print-color-adjust: exact;
|
|
||||||
print-color-adjust: exact;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tbody tr:nth-child(even),
|
||||||
tbody tr:nth-child(odd) {
|
tbody tr:nth-child(odd) {
|
||||||
background-color: #f9f9f9 !important;
|
background: #fff !important;
|
||||||
-webkit-print-color-adjust: exact;
|
color: #000 !important;
|
||||||
print-color-adjust: exact;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@page {
|
@page {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user