NonInventPurchasingSystem/CPRNIMS.WebApps/wwwroot/JsFunctions/Receiving/ReceivingViewV4.js
2026-02-09 16:28:02 +08:00

917 lines
31 KiB
JavaScript

function viewRRDetailByPO(data) {
loader = $('#overlay, #loader');
$('#viewRRDetailByPO').modal('show');
$('#viewRRDetailByPO').css('z-index', 1050);
PONo = data.poNo;
POTypeId = data.poTypeId;
let amountUSDLabel = document.getElementById('amountUSDLabel');
let vatRateLabel = document.getElementById('vatRateLabel');
let amountPHPVatLabel = document.getElementById('amountPHPVatLabel');
let amountPHPLabel = document.getElementById('amountPHPLabel');
let vatRate = document.getElementById('vatRate');
let amountPHPVat = document.getElementById('amountPHPVat');
let amountUSD = document.getElementById('amountUSD');
let amountPHP = document.getElementById('amountPHP');
let btnSubmit = document.getElementById('btnSubmit');
let btnReject = document.getElementById('btnReject');
let btnPayment = document.getElementById('btnPayment');
if (POTypeId !== 3) {
amountUSD.style.display = 'none';
amountUSDLabel.style.display = 'none';
}
if (UserRights !== 'CnvssAppver' && UserRights !== 'POApprover') { //dont touch &&
btnSubmit.style.display = 'none';
amountUSDLabel.style.display = 'none';
vatRateLabel.style.display = 'none';
amountPHPVatLabel.style.display = 'none';
amountPHPLabel.style.display = 'none';
amountPHPVat.style.display = 'none';
vatRate.style.display = 'none';
amountPHP.style.display = 'none';
}
//let btnComplete = document.getElementById('btnComplete');
//let btnIncomplete = document.getElementById('btnIncomplete');
let btnClosePO = document.getElementById('btnClosePO');
btnPayment.style.display = 'none';
if (UserRights == 'POApprover' || UserRights == 'CnvssAppver') {
btnSubmit.style.display = 'none';
btnReject.style.display = 'none';
dynamicColumn = colRRFinance;
dynamicTable = '#FRRdataTable';
rrTableComponent(1, loader);
} else {
dynamicColumn = colForReceivingDetail;
dynamicTable = '#RRdataTable';
btnClosePO.style.display = 'none';
rrTableComponent(2, loader);
}
}
function inputPopulation() {
// Update hidden input when an item category is selected
$('#ItemCategory').on('change', function () {
var selectedValue = $(this).val();
$('#ItemCategoryId').val(selectedValue);
});
$('#itemCategorySelect').on('change', function () {
var selectedValue2 = $(this).val();
$('#ItemCategory2Id').val(selectedValue2);
});
// Bind the click event to the select element
$('#itemCategoryName').on('click', function () {
let itemCategory = document.getElementById('itemCategoryName');
itemCategory.style.display = 'none';
let itemCategorySelect = document.getElementById('itemCategorySelect');
itemCategorySelect.style.display = 'block';
populateItemCategSelect();
});
$("#itemColorName").on('keyup', function () {
populateItemColor();
});
$("#uomName").on('keyup', function () {
populateItemUOM();
});
$("#itemLocalName").on('keyup', function () {
populateItemLocalization();
});
}
function rrInitializeDatatable(loader) {
tableElement = $(dynamicTable);
tableDestroy(tableElement);
receivingDetailTable = tableElement.DataTable({
ajax: $.extend({
url: '/Receiving/GetRRDetailByPO',
type: 'POST',
data: { PONo, POTypeId },
}, beforeComplete(loader)),
searching: false,
responsive: true,
language: {
emptyTable: "No record available"
},
initComplete: initCompleteCallback(),
columns: dynamicColumn,
columnDefs: colDefForReceivingSKU,
rowCallback: rowRRDetailCallback,
error: errorHandler
});
}
function rrTableComponent(id, loader) {
$.ajax({
url: '/Receiving/GetRRTable',
type: 'GET',
data: { id: id },
success: function (response) {
$('#PRTableContainer').html(response);
rrInitializeDatatable(loader);
},
error: errorHandler
});
}
function viewRRNo() {
populateRRNo();
$('#viewRRNo').modal('show');
$('#viewRRNo').css('z-index', 1070);
}
//Start viewRRDetail
function viewRRDetail(data) {
$('#viewRRDetail').modal('show');
$('#viewRRDetail').css('z-index', 1070);
const RRNo = data.rrNo;
const POTypeId = data.poTypeId;
// First load the component, then initialize the table
rrComponent(POTypeId, function () {
// This callback will be called after the component is loaded
initializeRRDetailTable(RRNo, POTypeId);
});
}
function rrComponent(id, callback) {
$.ajax({
url: '/Receiving/GetRRBody',
type: 'GET',
data: { id: id },
success: function (response) {
$('#RRContainer').html(response);
if (typeof callback === 'function') {
callback();
}
const btnPrintSIRR = document.getElementById('btnPrintSIRR');
const btnPrintDRRR = document.getElementById('btnPrintDRRR');
if (id == 1) {
btnPrintSIRR.style.display = 'block';
btnPrintDRRR.style.display = 'none';
} else {
btnPrintSIRR.style.display = 'none';
btnPrintDRRR.style.display = 'block';
}
},
error: errorHandler
});
}
function initializeRRDetailTable(RRNo, POTypeId) {
var tableName = '';
if (POTypeId == 1) {
tableName=$('#RRDataTable');
} else {
tableName = $('#DRRRDataTable');
}
tableElement = tableName;
tableDestroy(tableElement);
rrDetailTable = tableElement.DataTable({
ajax: $.extend({
url: '/Receiving/GetRRDetail',
type: 'POST',
data: { RRNo, POTypeId },
}, beforeComplete(loader)),
dom: '<"top"i>rt<"bottom"f><"clear">',
searching: false,
lengthChange: false,
info: false,
language: {
emptyTable: "No record available"
},
initComplete: initCompleteCallback(),
columns: colRRDetail,
rowCallback: rowRRCallback,
error: errorHandler
});
return rrDetailTable;
}
//End viewRRDetail
function printRRSIBackup() {
// Create a hidden iframe to handle printing without affecting the main page
const iframe = document.createElement('iframe');
iframe.style.position = 'fixed';
iframe.style.right = '0';
iframe.style.bottom = '0';
iframe.style.width = '0';
iframe.style.height = '0';
iframe.style.border = 'none';
document.body.appendChild(iframe);
// Get the iframe's document
const doc = iframe.contentWindow.document;
// Open the document and write the HTML header
doc.open();
doc.write('<html><head><title>Print</title>');
// Copy all stylesheets from the main page to ensure consistent styling
const stylesheets = document.querySelectorAll('link[rel="stylesheet"]');
stylesheets.forEach(sheet => {
doc.write(sheet.outerHTML);
});
// Add print-specific styles
doc.write(`
<style>
@page {
size: 8.5in 11in;
margin: 0.25in;
}
body {
font-family: Roman, sans-serif;
margin: 0;
padding: 0px;
box-sizing: border-box;
font-size: 12pt;
line-height: normal;
width: 8.5in;
margin: 0.25in auto;
height: 11in;
position: relative;
page-break-after: avoid !important;
page-break-before: avoid !important;
}
.print-area {
width: 7.5in;
margin: 0 auto;
height: calc(11in - 0.5in);
position: relative;
page-break-after: avoid !important;
page-break-inside: avoid !important;
}
/* Specifically optimized for dot matrix printing */
table {
width: 100%;
top: 1.4in;
position: fixed !important;
border: none !important;
row-border: none !important;
border-collapse: collapse;
line-height: normal;
font-size: 12px;
font-family: Roman, sans-serif !important;
table-layout: fixed !important;
}
.content {
width: 100%;
height: calc(100% - 0.5in);
overflow: hidden;
}
.header {
font-family: Roman, sans-serif;
font-size: 14px;
font-weight: bold;
text-align: center;
margin-bottom: 5px;
padding: 5px 0;
}
.rowSupplier {
display: flex;
position: fixed;
top: .2in;
flex-direction: column;
margin-left: 60px;
}
#address {
font-size: 10pt; /* Reduced from your default 10pt */
line-height: 1.1; /* Tighter line height */
display: block; /* Ensure it's a block element */
}
table th,
table td {
padding: 1px 2px;
line-height: .9;
vertical-align: top;
}
th.itemNo, td.itemNo {
width: 15%; text-align: right !important;
}
th.itemDescription, td.itemDescription {
width: 50% !important;
text-align: left;
padding-left: 30px !important;
font-size: 10pt !important;
max-width: 50%;
padding-right: 0 !important;
}
th.qty, td.qty {
width: 10%;
text-align: right!important;
padding-left:40px !important;
padding-right: 0 !important;
}
th.uomName, td.uomName {
width: 10%;
text-align: right !important;
padding-right: 0 !important;*/
font-size: 8pt !important;
word-wrap: break-word; /* Enable word wrapping */
word-break: break-word; /* Allow breaking at appropriate points */
}
th.remarks, td.remarks {
width: 15%; text-align: left;
}
.pr-info-section {
font-size: 12px !important;
}
.footer-row {
position: fixed;
bottom: 6in;
left : 0;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: auto;
line-height: normal;
background-color: white;
margin: 0 5px; /* Add small margin to match body padding */
}
.footer-column {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 0 5px;
line-height: normal;
margin-right:15px;
}
.pr-info-section label,
.pr-info-section strong {
font-size: 10px !important;
}
/* Hide DataTables controls */
.dataTables_length,
.dataTables_filter,
.dataTables_info,
.dataTables_paginate {
display: none !important;
}
/* Additional style to ensure proper width for dot matrix printing */
@media print {
body, .print-area {
width: 8in !important; /* Specific width for Epson FX-2175II */
}
/* Force actual size printing */
html {
zoom: 100% !important;
}
}
</style>
`);
// Close the head and start the body
doc.write('</head><body>');
// Get the printable content
const printContent = document.getElementById('printableSIDR').cloneNode(true);
// Remove DataTables controls
const dataTableControls = printContent.querySelectorAll('.dataTables_length, .dataTables_filter, .dataTables_info, .dataTables_paginate');
dataTableControls.forEach(control => {
if (control && control.parentNode) {
control.parentNode.removeChild(control);
}
});
// Write the modified content to the iframe
doc.write(printContent.innerHTML);
// Close the document
doc.write('</body></html>');
doc.close();
// Wait for the iframe to load before printing
iframe.onload = function () {
// Print the iframe content
iframe.contentWindow.print();
// Remove the iframe after printing
setTimeout(function () {
document.body.removeChild(iframe);
}, 1000);
};
}
function printRRDRBackup() {
// Create a hidden iframe to handle printing without affecting the main page
const iframe = document.createElement('iframe');
iframe.style.position = 'fixed';
iframe.style.right = '0';
iframe.style.bottom = '0';
iframe.style.width = '0';
iframe.style.height = '0';
iframe.style.border = 'none';
document.body.appendChild(iframe);
// Get the iframe's document
const doc = iframe.contentWindow.document;
// Open the document and write the HTML header
doc.open();
doc.write('<html><head><title>Print</title>');
// Copy all stylesheets from the main page to ensure consistent styling
const stylesheets = document.querySelectorAll('link[rel="stylesheet"]');
stylesheets.forEach(sheet => {
doc.write(sheet.outerHTML);
});
// Add print-specific styles
doc.write(`
<style>
body {
font-family: Roman, sans-serif;
font-size: 9px;
margin: 0;
padding: 0px;
box-sizing: border-box;
font-family: Roman, sans-serif;
font-size: 10pt; /* Ensure consistent font size */
line-height: normal; /* Avoid font clipping */
width: 8.5in;
height: 7in;
overflow: hidden;
position: relative;
page-break-after: avoid !important;
page-break-before: avoid !important;
}
.print-area {
width: 100%;
height: calc(11in - 0.5in);
position: relative;
overflow: hidden;
page-break-after: avoid !important;
page-break-inside: avoid !important;
}
.content {
width: 100%;
height: calc(100% - 0.5in);
overflow: hidden;
}
.header {
font-family: Roman, sans-serif;
font-size: 14px;
font-weight: bold;
text-align: center;
margin-bottom: 5px;
padding: 5px 0;
}
.clientSupplier {
display: flex;
position: fixed;
top: 2.1in;
}
/* Reduce vertical padding inside table rows */
table {
width: 100%;
top: 2.4in !important;
position: fixed !important;
border: none !important;
row-border: none !important;
border-collapse: collapse;
line-height: normal;
font-size: 10px;
font-family: Roman, sans-serif !important;
table-layout: fixed !important;
}
table th,
table td {
padding: 1px 2px;
line-height: .9;
vertical-align: top;
}
th.itemNo, td.itemNo {
width: 15%; text-align: right !important;
}
th.itemDescription, td.itemDescription {
width: 50% !important;
text-align: left;
padding-left: 30px !important;
font-size: 10pt !important;
max-width: 50%;
padding-right: 0 !important;
}
th.qty, td.qty {
width: 10%;
text-align: right!important;
padding-left:40px !important;
padding-right: 0 !important;
}
th.uomName, td.uomName {
width: 10%;
text-align: right !important;
padding-right: 0 !important;*/
font-size: 8pt !important;
word-wrap: break-word; /* Enable word wrapping */
word-break: break-word; /* Allow breaking at appropriate points */
}
th.remarks, td.remarks {
width: 15%; text-align: left;
}
.pr-info-section {
font-size: 10px !important;
}
.footer-row {
position: fixed;
bottom: 1.5in !important;
left : 0;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
height: auto;
line-height: normal;
background-color: white;
margin: 0 5px; /* Add small margin to match body padding */
}
.footer-column {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 0 5px;
line-height: normal;
margin-right:15px;
}
.pr-info-section label,
.pr-info-section strong {
font-size: 10px !important;
}
/* Hide DataTables controls */
.dataTables_length,
.dataTables_filter,
.dataTables_info,
.dataTables_paginate {
display: none !important;
}
</style>
`);
// Close the head and start the body
doc.write('</head><body>');
// Get the printable content
const printContent = document.getElementById('printableSIDR').cloneNode(true);
// Remove DataTables controls
const dataTableControls = printContent.querySelectorAll('.dataTables_length, .dataTables_filter, .dataTables_info, .dataTables_paginate');
dataTableControls.forEach(control => {
if (control && control.parentNode) {
control.parentNode.removeChild(control);
}
});
// Write the modified content to the iframe
doc.write(printContent.innerHTML);
// Close the document
doc.write('</body></html>');
doc.close();
// Wait for the iframe to load before printing
iframe.onload = function () {
// Print the iframe content
iframe.contentWindow.print();
// Remove the iframe after printing
setTimeout(function () {
document.body.removeChild(iframe);
}, 1000);
};
}
function populateRRNo() {
loader = $('#overlay, #loader').css('z-index', 1060);
$.ajax($.extend({
url: '/Receiving/GetLatestRRNo',
type: 'GET',
success: function (data) {
if (data && data.data && data.data.length > 0) {
var item = data.data[0];
$('#rrNoSeries').val(item.rrNo);
} else {
console.log('Data is null or undefined');
window.location.href = '/Home/Logout';
}
},
error: errorHandler
}, beforeComplete(loader)));
}
function clearTextRec() {
if (UserRights == 'LLISCMAdmin' || UserRights == 'LTReceiver') {
document.getElementById('docTypeId').value = "";
document.getElementById('suppDocNo').value = "";
document.getElementById('remarks').value = "";
}
}
function printRRSI() {
try {
// Step 1: Prepare the content for printing
// Clone the content from printableSIDR which contains the full document
const contentDiv = document.getElementById('printableSIDR').cloneNode(true);
// Step 2: Clean up any DataTable controls that might affect layout
const dataTableControls = contentDiv.querySelectorAll('.dataTables_length, .dataTables_filter, .dataTables_info, .dataTables_paginate');
dataTableControls.forEach(control => control.parentNode?.removeChild(control));
// Step 3: Create a container with optimized print styles
const container = document.createElement('div');
container.id = 'print-container';
container.innerHTML = contentDiv.innerHTML;
// Step 4: Create style element with precise layout rules
const styleElement = document.createElement('style');
styleElement.textContent = `
/* Base document styles */
html, body {
margin: 0;
padding: 0;
font-family: Roman, sans-serif;
font-size: 11pt;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
/* Main container */
#print-container {
width: 100%;
padding: 10px;
box-sizing: border-box;
page-break-after: always;
}
/* Supplier section */
.rowSupplier {
display: block;
padding-bottom: 5px;
}
/* Reference section */
.rr-reference {
float: right;
margin-right: 30px;
margin-top: 0;
margin-bottom: 70px;
}
th, td {
font-family: Roman, sans-serif;
line-height: normal;
padding: 3px 5px;
height: 20px; /* Ensure minimum row height */
box-sizing: border-box; /* Ensure padding does not overflow */
}
/* Table styles */
#RRDataTable {
width: 100%;
border-collapse: collapse;
margin-top: 180px;
table-layout: fixed;
font-size: 10pt;
clear: both;
}
#RRDataTable th, #RRDataTable td {
padding: 4px;
vertical-align: top;
}
/* Column sizing */
.itemNo { width: 10%; text-align: right; }
.itemDescription { width: 55%; text-align: left; }
.qty { width: 10%; text-align: right; }
.uomName { width: 10%; text-align: center; }
/* Footer section */
.footer-row {
position: fixed !important;
bottom: 3.5in !important;
left: 0;
display: flex !important;
justify-content: center !important;
width: 100%;
z-index: 100 !important;
}
.footer-column {
flex: 0 0 auto;
text-align: center;
min-width: 150px;
}
.footer-span {
display: block;
padding-top: 3px;
text-align: center;
}
/* Hide datatables cruft */
.dataTables_length, .dataTables_filter,
.dataTables_info, .dataTables_paginate {
display: none !important;
}
`;
// Step 5: Create document wrapper
const wrapper = document.createElement('div');
wrapper.appendChild(styleElement);
wrapper.appendChild(container);
// Step 6: Set pdf generation options
const options = {
filename: `RRSI_Document_${new Date().toISOString().slice(0, 19).replace(/[-:T]/g, '')}.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: {
scale: 2, // High quality
useCORS: true, // Allow images
scrollY: 0, // No scroll
allowTaint: true, // Allow modified canvas
logging: false, // Reduce console noise
removeContainer: true
},
jsPDF: {
unit: 'mm',
format: 'letter',
orientation: 'portrait'
},
// Modest margin to prevent content being cut off
margin: [10, 10, 10, 10] // [top, right, bottom, left] in mm
};
// Step 7: Generate PDF and display in new window
html2pdf()
.from(wrapper)
.set(options)
.outputPdf('dataurlnewwindow')
.catch(error => {
console.error('PDF generation failed:', error);
alert('Error generating PDF. Please try again.');
});
} catch (error) {
console.error('Error in printRRSI function:', error);
alert('An unexpected error occurred. Please try again.');
}
}
function printRRDR() {
try {
// Step 1: Prepare the content for printing
// Clone the content from printableSIDR which contains the full document
const contentDiv = document.getElementById('printableSIDR').cloneNode(true);
// Step 2: Clean up any DataTable controls that might affect layout
const dataTableControls = contentDiv.querySelectorAll('.dataTables_length, .dataTables_filter, .dataTables_info, .dataTables_paginate');
dataTableControls.forEach(control => control.parentNode?.removeChild(control));
// Step 3: Create a container with optimized print styles
const container = document.createElement('div');
container.id = 'print-container';
container.innerHTML = contentDiv.innerHTML;
// Step 4: Create style element with precise layout rules
const styleElement = document.createElement('style');
styleElement.textContent = `
/* Base document styles */
html, body {
margin: 0;
padding: 0;
font-family: Roman, sans-serif;
font-size: 11pt;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
/* Main container */
#print-container {
width: 100%;
padding: 10px;
box-sizing: border-box;
page-break-after: always;
}
/* Supplier section */
.clientSupplier {
display: flex;
position: fixed;
top: 2.1in;
}
/* Reference section */
.rr-reference {
float: right;
margin-right: 30px;
margin-top: 10px;
margin-bottom: 55px;
}
/* Table styles */
#DRRRDataTable {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
font-size: 10pt;
clear: both;
}
#DRRRDataTable th, #DRRRDataTable td {
padding: 4px;
vertical-align: top;
}
th, td {
font-family: Roman, sans-serif;
line-height: normal !important;
padding: 3px 5px !important;
height: 20px !important;
box-sizing: border-box !important;
}
/* Column sizing */
.itemNo { width: 10%; text-align: right; }
.itemDescription { width: 55%; text-align: left; }
.qty { width: 10%; text-align: right; }
.uomName { width: 10%; text-align: center; }
/* Footer section */
.footer-row {
position: fixed !important;
bottom: 3in !important;
left: 0;
right: 0;
display: flex !important;
justify-content: center !important;
width: 100% !important;
z-index: 100 !important;
}
.footer-column {
flex: 0 0 auto;
text-align: center;
min-width: 150px;
}
.footer-span {
display: block;
padding-top: 3px;
text-align: center;
}
/* Hide datatables cruft */
.dataTables_length, .dataTables_filter,
.dataTables_info, .dataTables_paginate {
display: none !important;
}
`;
// Step 5: Create document wrapper
const wrapper = document.createElement('div');
wrapper.appendChild(styleElement);
wrapper.appendChild(container);
// Step 6: Set pdf generation options
const options = {
filename: `RRSI_Document_${new Date().toISOString().slice(0, 19).replace(/[-:T]/g, '')}.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: {
scale: 2, // High quality
useCORS: true, // Allow images
scrollY: 0, // No scroll
allowTaint: true, // Allow modified canvas
logging: false, // Reduce console noise
removeContainer: true
},
jsPDF: {
unit: 'mm',
format: 'letter',
orientation: 'portrait'
},
// Modest margin to prevent content being cut off
margin: [10, 10, 10, 10] // [top, right, bottom, left] in mm
};
// Step 7: Generate PDF and display in new window
html2pdf()
.from(wrapper)
.set(options)
.outputPdf('dataurlnewwindow')
.catch(error => {
console.error('PDF generation failed:', error);
alert('Error generating PDF. Please try again.');
});
} catch (error) {
console.error('Error in printRRSI function:', error);
alert('An unexpected error occurred. Please try again.');
}
}