430 lines
17 KiB
PHP
430 lines
17 KiB
PHP
<div id="incomingControlPopup"></div>
|
|
|
|
<style>
|
|
.incoming-popup-cell {
|
|
position: relative;
|
|
padding-right: 26px !important;
|
|
}
|
|
.incoming-popup-trigger {
|
|
position: absolute;
|
|
top: 50%;
|
|
right: 4px;
|
|
transform: translateY(-50%);
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 18px;
|
|
height: 18px;
|
|
border-radius: 50%;
|
|
font-size: 11px;
|
|
color: #1e88e5;
|
|
cursor: pointer;
|
|
background: rgba(255,255,255,0.6);
|
|
border: 1px solid rgba(30,136,229,0.4);
|
|
}
|
|
.incoming-popup-trigger:hover {
|
|
color: #0d47a1;
|
|
border-color: #0d47a1;
|
|
}
|
|
.incoming-file-link {
|
|
margin: 0 3px;
|
|
color: #3949ab;
|
|
}
|
|
.incoming-file-link:hover {
|
|
color: #1a237e;
|
|
}
|
|
.incoming-row-highlight {
|
|
background-color: #fff3f3;
|
|
}
|
|
.incoming-highlight-cell {
|
|
font-weight: bold;
|
|
color: #c62828;
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
(function(){
|
|
var popupState = {
|
|
popup: null,
|
|
grid: null,
|
|
dataSource: null,
|
|
callback: null,
|
|
params: null,
|
|
warningElement: null,
|
|
gridElement: null
|
|
};
|
|
|
|
function buildRequestUrl(params) {
|
|
var query = [];
|
|
if(params.componentCode) {
|
|
query.push("component_code=" + encodeURIComponent(params.componentCode));
|
|
}
|
|
if(params.lineCode) {
|
|
query.push("line_code=" + encodeURIComponent(params.lineCode));
|
|
}
|
|
if(params.ruGroup) {
|
|
query.push("ru_group=" + encodeURIComponent(params.ruGroup));
|
|
}
|
|
if(params.weldingDate) {
|
|
query.push("welding_date=" + encodeURIComponent(params.weldingDate));
|
|
}
|
|
return "{{url('admin-ajax/get-incoming-for-weldlog')}}" + "?" + query.join("&");
|
|
}
|
|
|
|
function ensureDataSource() {
|
|
// Always create a new dataSource to ensure fresh parameters
|
|
popupState.dataSource = new DevExpress.data.CustomStore({
|
|
key: "id",
|
|
load: function(loadOptions) {
|
|
var deferred = $.Deferred();
|
|
var params = popupState.params || {};
|
|
|
|
// Build request URL with pagination parameters (show all if no filters)
|
|
var requestUrl = buildRequestUrl(params);
|
|
|
|
// Add pagination parameters if provided
|
|
if(loadOptions && loadOptions.skip !== undefined && loadOptions.take !== undefined) {
|
|
var separator = requestUrl.indexOf('?') === -1 ? '?' : '&';
|
|
requestUrl += separator + 'skip=' + loadOptions.skip + '&take=' + loadOptions.take;
|
|
}
|
|
|
|
$.getJSON(requestUrl).then(function(result) {
|
|
|
|
var data = [];
|
|
var totalCount = 0;
|
|
|
|
if(Array.isArray(result)) {
|
|
data = result;
|
|
totalCount = result.length;
|
|
} else if(result && Array.isArray(result.data)) {
|
|
data = result.data;
|
|
totalCount = result.totalCount !== undefined ? result.totalCount : result.data.length;
|
|
|
|
// Show warning if filter failed and showing all data
|
|
if(result.filterFailed && popupState.warningElement) {
|
|
popupState.warningElement.find('.warning-text').text("{{e2('Filter could not be applied. Showing all data.')}}");
|
|
popupState.warningElement.removeClass('alert-warning').addClass('alert-info').show();
|
|
if(popupState.gridElement) {
|
|
popupState.gridElement.css('height', 'calc(100% - 50px)');
|
|
}
|
|
}
|
|
} else if(result && typeof result === "object") {
|
|
data = [result];
|
|
totalCount = 1;
|
|
}
|
|
|
|
deferred.resolve({ data: data, totalCount: totalCount });
|
|
}, function(error) {
|
|
var message = (error && (error.responseText || error.statusText)) || "Unknown error";
|
|
if(window.Swal) {
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "{{e2('Incoming Control')}}",
|
|
text: message
|
|
});
|
|
}
|
|
deferred.resolve({ data: [], totalCount: 0 });
|
|
});
|
|
return deferred.promise();
|
|
}
|
|
});
|
|
return popupState.dataSource;
|
|
}
|
|
|
|
function applySelection(rowData) {
|
|
if(!rowData) {
|
|
return;
|
|
}
|
|
if(typeof popupState.callback === "function") {
|
|
popupState.callback(rowData);
|
|
}
|
|
if(popupState.popup) {
|
|
popupState.popup.hide();
|
|
}
|
|
}
|
|
|
|
function ensurePopup() {
|
|
if(popupState.popup) {
|
|
return popupState.popup;
|
|
}
|
|
var $popup = $("#incomingControlPopup");
|
|
$popup.dxPopup({
|
|
title: "{{e2('Incoming Control Records')}}",
|
|
width: 1250,
|
|
height: 720,
|
|
visible: false,
|
|
showCloseButton: true,
|
|
shading: true,
|
|
resizeEnabled: true,
|
|
contentTemplate: function(contentElement) {
|
|
// Warning message container (hidden by default)
|
|
var $warning = $('<div class="incoming-control-warning alert alert-warning mb-2" style="display:none;"><i class="fa fa-exclamation-triangle mr-2"></i><span class="warning-text"></span></div>');
|
|
contentElement.append($warning);
|
|
popupState.warningElement = $warning;
|
|
|
|
var $grid = $('<div class="incoming-control-grid" style="height: calc(100% - 50px);"></div>');
|
|
contentElement.append($grid);
|
|
popupState.gridElement = $grid;
|
|
popupState.grid = $grid.dxDataGrid({
|
|
dataSource: ensureDataSource(),
|
|
remoteOperations: {
|
|
paging: true,
|
|
filtering: false,
|
|
sorting: false
|
|
},
|
|
keyExpr: "id",
|
|
showBorders: true,
|
|
hoverStateEnabled: true,
|
|
height: "100%",
|
|
columnAutoWidth: true,
|
|
allowColumnResizing: true,
|
|
searchPanel: {
|
|
visible: true,
|
|
width: 260
|
|
},
|
|
filterRow: {
|
|
visible: true
|
|
},
|
|
scrolling: {
|
|
mode: "virtual",
|
|
rowRenderingMode: "virtual",
|
|
useNative: false,
|
|
preloadEnabled: true
|
|
},
|
|
paging: {
|
|
pageSize: 50,
|
|
enabled: true
|
|
},
|
|
pager: {
|
|
visible: false
|
|
},
|
|
selection: {
|
|
mode: "single"
|
|
},
|
|
columns: [
|
|
{
|
|
dataField: "component_code",
|
|
caption: "Component Code",
|
|
width: 150
|
|
},
|
|
{
|
|
dataField: "rfi_date",
|
|
caption: "Received / RFI Date",
|
|
dataType: "date",
|
|
format: "dd/MM/yyyy",
|
|
width: 150
|
|
},
|
|
{
|
|
dataField: "project",
|
|
caption: "Project",
|
|
width: 120
|
|
},
|
|
{
|
|
dataField: "drawing_number",
|
|
caption: "Line",
|
|
width: 120
|
|
},
|
|
{
|
|
dataField: "description_en",
|
|
caption: "Material Description EN",
|
|
width: 220
|
|
},
|
|
{
|
|
dataField: "description_ru",
|
|
caption: "Material Description RU",
|
|
width: 220
|
|
},
|
|
{
|
|
dataField: "certificate_no",
|
|
caption: "Certificate No",
|
|
width: 160
|
|
},
|
|
{
|
|
dataField: "heat_number",
|
|
caption: "Heat No",
|
|
width: 140
|
|
},
|
|
{
|
|
dataField: "received_quantity",
|
|
caption: "Received Qty",
|
|
width: 120
|
|
},
|
|
{
|
|
dataField: "certificate_date",
|
|
caption: "Certificate Date",
|
|
dataType: "date",
|
|
format: "dd/MM/yyyy",
|
|
width: 140
|
|
},
|
|
{
|
|
dataField: "constructor",
|
|
caption: "Constructor / Supplier",
|
|
width: 160
|
|
},
|
|
{
|
|
dataField: "email_tq_number",
|
|
caption: "TQ",
|
|
width: 140
|
|
},
|
|
{
|
|
dataField: "osd_report_date",
|
|
caption: "OSD Report Date",
|
|
dataType: "date",
|
|
format: "dd/MM/yyyy",
|
|
width: 140
|
|
}
|
|
],
|
|
onRowPrepared: function(e) {
|
|
if(e.rowType === "data" && e.data && e.data.highlight) {
|
|
$(e.rowElement).addClass("incoming-row-highlight");
|
|
}
|
|
},
|
|
onCellPrepared: function(e) {
|
|
if(e.rowType === "data" && e.data && e.data.highlight && e.column && e.column.dataField === "rfi_date") {
|
|
$(e.cellElement).addClass("incoming-highlight-cell");
|
|
}
|
|
},
|
|
onRowDblClick: function(e) {
|
|
applySelection(e.data);
|
|
},
|
|
onSelectionChanged: function(e) {
|
|
if(e.selectedRowsData && e.selectedRowsData.length > 0) {
|
|
applySelection(e.selectedRowsData[0]);
|
|
}
|
|
}
|
|
}).dxDataGrid("instance");
|
|
},
|
|
onShowing: function(e) {
|
|
// Show/hide warning based on filter presence
|
|
var params = popupState.params || {};
|
|
|
|
if(popupState.warningElement) {
|
|
// Reset warning state
|
|
popupState.warningElement.removeClass('alert-info').addClass('alert-warning');
|
|
|
|
if(!params.componentCode && !params.lineCode) {
|
|
popupState.warningElement.find('.warning-text').text("{{e2('Missing Component: Please fill Element Code or Line Number')}}");
|
|
popupState.warningElement.show();
|
|
if(popupState.gridElement) {
|
|
popupState.gridElement.css('height', 'calc(100% - 50px)');
|
|
}
|
|
} else {
|
|
popupState.warningElement.hide();
|
|
if(popupState.gridElement) {
|
|
popupState.gridElement.css('height', '100%');
|
|
}
|
|
}
|
|
}
|
|
|
|
if(popupState.grid) {
|
|
popupState.grid.clearSelection();
|
|
// Recreate dataSource with fresh parameters
|
|
popupState.dataSource = null;
|
|
var newDataSource = ensureDataSource();
|
|
popupState.grid.option('dataSource', newDataSource);
|
|
popupState.grid.refresh();
|
|
}
|
|
}
|
|
});
|
|
popupState.popup = $popup.dxPopup("instance");
|
|
return popupState.popup;
|
|
}
|
|
|
|
window.showIncomingControlPopup = function(options) {
|
|
options = options || {};
|
|
popupState.params = {
|
|
componentCode: options.componentCode || "",
|
|
lineCode: options.lineCode || "",
|
|
ruGroup: options.ruGroup || "",
|
|
weldingDate: options.weldingDate || ""
|
|
};
|
|
popupState.callback = typeof options.onSelect === "function" ? options.onSelect : null;
|
|
var popup = ensurePopup();
|
|
var titleSuffix = popupState.params.componentCode ? " (" + popupState.params.componentCode + ")" : (popupState.params.lineCode ? " (Line: " + popupState.params.lineCode + ")" : "");
|
|
popup.option("title", "{{e2('Incoming Control Records')}}" + titleSuffix);
|
|
if(popupState.grid) {
|
|
// Recreate dataSource with fresh parameters before refresh
|
|
popupState.dataSource = null;
|
|
var newDataSource = ensureDataSource();
|
|
popupState.grid.option('dataSource', newDataSource);
|
|
popupState.grid.clearSelection();
|
|
popupState.grid.refresh();
|
|
}
|
|
popup.show();
|
|
};
|
|
|
|
window.setupIncomingControlPopupHelpers = function(dataGrid) {
|
|
if(!dataGrid || dataGrid.__incomingPopupAttached) {
|
|
return;
|
|
}
|
|
dataGrid.__incomingPopupAttached = true;
|
|
var targetFields = [
|
|
"certificate_number_of_1",
|
|
"heat_number_1",
|
|
"certificate_number_of_2",
|
|
"heat_number_2"
|
|
];
|
|
var originalCellPrepared = dataGrid.option("onCellPrepared");
|
|
dataGrid.option("onCellPrepared", function(e) {
|
|
if(typeof originalCellPrepared === "function") {
|
|
originalCellPrepared.apply(this, arguments);
|
|
}
|
|
if(!e || e.rowType !== "data" || !e.column || targetFields.indexOf(e.column.dataField) === -1) {
|
|
return;
|
|
}
|
|
var $cell = $(e.cellElement);
|
|
$cell.addClass("incoming-popup-cell");
|
|
if($cell.find(".incoming-popup-trigger").length > 0) {
|
|
return;
|
|
}
|
|
var rowIndexSnapshot = typeof e.rowIndex !== "undefined" ? e.rowIndex : (e.row && e.row.rowIndex);
|
|
var keySnapshot = e.key;
|
|
var elementNo = e.column.dataField.indexOf("_2") !== -1 ? 2 : 1;
|
|
var $button = $('<span class="incoming-popup-trigger" title="{{e2('Incoming Control')}}"></span>');
|
|
$button.append('<i class="fa fa-search"></i>');
|
|
$button.on("click", function(ev) {
|
|
ev.preventDefault();
|
|
ev.stopPropagation();
|
|
var rowData = e.data || {};
|
|
var componentCode = rowData["element_code_" + elementNo] || "";
|
|
var lineCode = rowData["line_number"] || "";
|
|
// No blocking - popup will show warning inside if filters are empty
|
|
var ruGroup = rowData["ru_material_group_" + elementNo] || "";
|
|
var weldingDate = rowData.welding_date || "";
|
|
if(weldingDate && typeof weldingDate === "object" && typeof weldingDate.toISOString === "function") {
|
|
weldingDate = weldingDate.toISOString().slice(0, 10);
|
|
}
|
|
showIncomingControlPopup({
|
|
componentCode: componentCode,
|
|
lineCode: lineCode,
|
|
ruGroup: ruGroup,
|
|
weldingDate: weldingDate,
|
|
onSelect: function(selectedRow) {
|
|
if(!selectedRow) {
|
|
return;
|
|
}
|
|
var resolvedRowIndex = -1;
|
|
if(typeof keySnapshot !== "undefined" && keySnapshot !== null) {
|
|
resolvedRowIndex = dataGrid.getRowIndexByKey(keySnapshot);
|
|
}
|
|
if(resolvedRowIndex < 0 && typeof rowIndexSnapshot !== "undefined") {
|
|
resolvedRowIndex = rowIndexSnapshot;
|
|
}
|
|
if(resolvedRowIndex < 0) {
|
|
return;
|
|
}
|
|
if(selectedRow.certificate_no) {
|
|
dataGrid.cellValue(resolvedRowIndex, "certificate_number_of_" + elementNo, selectedRow.certificate_no);
|
|
}
|
|
if(selectedRow.heat_number) {
|
|
dataGrid.cellValue(resolvedRowIndex, "heat_number_" + elementNo, selectedRow.heat_number);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
$cell.append($button);
|
|
});
|
|
};
|
|
})();
|
|
</script>
|