536 lines
12 KiB
JavaScript
536 lines
12 KiB
JavaScript
$(document)
|
|
.ready(
|
|
function() {
|
|
// get EcmJsTable class if it isn't loaded yet.
|
|
if (typeof window["EcmJsTable"] === 'undefined') {
|
|
$.ajax({
|
|
async : false,
|
|
url : "include/ECM/EcmJsTable/EcmJsTable.class.js",
|
|
dataType : "script"
|
|
});
|
|
}
|
|
// get number functions if it isn't loaded yet.
|
|
if (typeof window["FormatNumber"] === 'undefined') {
|
|
$.ajax({
|
|
async : false,
|
|
url : "include/ECM/EcmNumberFunctions.js",
|
|
dataType : "script"
|
|
});
|
|
}
|
|
// is Detail or Edit View??
|
|
if ($('form[name="EditView"]').length == 1)
|
|
var type = 'EditView';
|
|
else
|
|
var type = 'DetailView';
|
|
// setup components table
|
|
CTABLE = new EcmJsTable(ccolumns, $('#componentsTable'),
|
|
type);
|
|
CTABLE.updateItems = function(){
|
|
|
|
}
|
|
CTABLE.customQuickSearch = function(search) {
|
|
// AJAX call
|
|
var a = jQuery
|
|
.ajax({
|
|
type : 'POST',
|
|
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
|
|
data : {
|
|
job : 'searchComponents',
|
|
searchText : search,
|
|
},
|
|
dataType : 'json',
|
|
async : false,
|
|
});
|
|
return $.parseJSON(a.responseText);
|
|
}
|
|
// create save function
|
|
CTABLE.customSave = function(items, prod_id) {
|
|
// AJAX call
|
|
jQuery
|
|
.ajax({
|
|
type : 'POST',
|
|
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
|
|
data : {
|
|
job : 'saveItemsComponents',
|
|
items : items,
|
|
prod_id : prod_id
|
|
},
|
|
dataType : 'json',
|
|
async : false,
|
|
});
|
|
}
|
|
// get components
|
|
CTABLE.getComponents = function(row_index) {
|
|
var prod = CTABLE.getItems();
|
|
product_id = prod[row_index].product_id;
|
|
var i = jQuery
|
|
.ajax({
|
|
type : 'POST',
|
|
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
|
|
data : {
|
|
job : 'getItemsComponents',
|
|
prod_id : product_id,
|
|
},
|
|
dataType : 'json',
|
|
async : false,
|
|
});
|
|
var response = $.parseJSON(i.responseText);
|
|
if (response.length == 0) {
|
|
alert('Brak komponentów dla '
|
|
+ prod[row_index].product_code);
|
|
return;
|
|
}
|
|
prod.splice(row_index, 1);
|
|
var newItems = insertArrayAt(prod, row_index, response);
|
|
CTABLE.setItems(newItems);
|
|
CTABLE.fillTable();
|
|
}
|
|
var i = jQuery
|
|
.ajax({
|
|
type : 'POST',
|
|
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
|
|
data : {
|
|
job : 'getItemsComponents',
|
|
prod_id : $('[name=record]').val(),
|
|
},
|
|
dataType : 'json',
|
|
async : false,
|
|
});
|
|
CTABLE.setItems($.parseJSON(i.responseText));
|
|
CTABLE.getHeaders();
|
|
CTABLE.fillTable();
|
|
// setup actions table
|
|
ATABLE = new EcmJsTable(acolumns, $('#actionsTable'), type);
|
|
ATABLE.customQuickSearch = function(search) {
|
|
// AJAX call
|
|
var a = jQuery
|
|
.ajax({
|
|
type : 'POST',
|
|
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
|
|
data : {
|
|
job : 'searchActions',
|
|
searchText : search,
|
|
},
|
|
dataType : 'json',
|
|
async : false,
|
|
});
|
|
return $.parseJSON(a.responseText);
|
|
}
|
|
// create save function
|
|
ATABLE.customSave = function(items, prod_id) {
|
|
// AJAX call
|
|
jQuery
|
|
.ajax({
|
|
type : 'POST',
|
|
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
|
|
data : {
|
|
job : 'saveItemsActions',
|
|
items : items,
|
|
prod_id : prod_id
|
|
},
|
|
dataType : 'json',
|
|
async : false,
|
|
});
|
|
}
|
|
// get components
|
|
ATABLE.getComponents = function(row_index) {
|
|
var prod = ATABLE.getItems();
|
|
console.log(prod[row_index]);
|
|
action_id = prod[row_index].action_id;
|
|
var i = jQuery
|
|
.ajax({
|
|
type : 'POST',
|
|
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
|
|
data : {
|
|
job : 'getItemsActions',
|
|
prod_id : action_id,
|
|
},
|
|
dataType : 'json',
|
|
async : false,
|
|
});
|
|
var response = $.parseJSON(i.responseText);
|
|
console.log(response);
|
|
if (response.length == 0) {
|
|
alert('Brak komponentów dla '
|
|
+ prod[row_index].action_code);
|
|
return;
|
|
}
|
|
prod.splice(row_index, 1);
|
|
var newItems = insertArrayAt(prod, row_index, response);
|
|
CTABLE.setItems(newItems);
|
|
CTABLE.fillTable();
|
|
}
|
|
var i = jQuery
|
|
.ajax({
|
|
type : 'POST',
|
|
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
|
|
data : {
|
|
job : 'getItemsActions',
|
|
prod_id : $('[name=record]').val(),
|
|
},
|
|
dataType : 'json',
|
|
async : false,
|
|
});
|
|
ATABLE.setItems($.parseJSON(i.responseText));
|
|
ATABLE.getHeaders();
|
|
ATABLE.fillTable();
|
|
|
|
if (type == 'DetailView')
|
|
getProductionSummary(); // in ProductionSummary.js
|
|
if (type == 'EditView')
|
|
getCopyElements(); // in ProductionCopyElements.js
|
|
|
|
});
|
|
// helper
|
|
function insertArrayAt(array, index, arrayToInsert) {
|
|
Array.prototype.splice.apply(array, [ index, 0 ].concat(arrayToInsert));
|
|
return array;
|
|
}
|
|
// components table columns
|
|
var ccolumns = new Array();
|
|
// define columns
|
|
// begin: number
|
|
ccolumns[0] = {
|
|
'name' : 'number',
|
|
'label' : 'Lp.',
|
|
'width' : 5, // %
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[0]['content'][0] = {
|
|
'name' : '',
|
|
'type' : 'text',
|
|
'readonly' : true
|
|
};
|
|
// end: number
|
|
// begin: code
|
|
ccolumns[1] = {
|
|
'name' : 'product_',
|
|
'label' : 'Indeks',
|
|
'width' : 14, // %
|
|
'searchTrigger' : true,
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[1]['content'][0] = {
|
|
'name' : 'code',
|
|
'attr' : {
|
|
'type' : 'hidden',
|
|
}
|
|
};
|
|
ccolumns[1]['content'][1] = {
|
|
'name' : 'id',
|
|
'attr' : {
|
|
'type' : 'hidden',
|
|
}
|
|
};
|
|
ccolumns[1]['content'][2] = {
|
|
'name' : 'link',
|
|
'readonly' : true,
|
|
'css' : {
|
|
'text-align' : 'left'
|
|
}
|
|
};
|
|
ccolumns[1]['content'][3] = {
|
|
'name' : 'custom',
|
|
'customCodeEdit' : '<img src="modules/EcmSales/images/add_position.gif" onClick="CTABLE.getComponents({{row_index}});" style="cursor:pointer"/>',
|
|
};
|
|
ccolumns[2] = {
|
|
'name' : 'name',
|
|
'label' : 'Nazwa',
|
|
'searchTrigger' : true,
|
|
'width' : 40, // %
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[2]['content'][0] = {
|
|
'name' : '',
|
|
'readonly' : true,
|
|
'attr' : {
|
|
'type' : 'text'
|
|
},
|
|
'css' : {
|
|
'text-align' : 'left',
|
|
}
|
|
};
|
|
ccolumns[3] = {
|
|
'name' : 'unit',
|
|
'label' : 'J.M.',
|
|
'width' : 3, // %
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[3]['content'][0] = {
|
|
'name' : '',
|
|
'readonly' : true,
|
|
'attr' : {
|
|
'type' : 'text',
|
|
},
|
|
'css' : {
|
|
'text-align' : 'left'
|
|
}
|
|
};
|
|
ccolumns[4] = {
|
|
'name' : 'quantity_recipe',
|
|
'label' : 'Ilość receptura',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[4]['content'][0] = {
|
|
'name' : '',
|
|
'dataType' : 'number',
|
|
'precision' : 6,
|
|
'quantity':true,
|
|
'attr' : {
|
|
'type' : 'text'
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
},
|
|
'onChange': '$(this).val(QuantityFormat($(this).val(),6));CTABLE.setRowDate(this,$(this).parent(\'td\').parent(\'tr\').index());'
|
|
};
|
|
ccolumns[5] = {
|
|
'name' : 'divider',
|
|
'label' : 'Dzielnik',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[5]['content'][0] = {
|
|
'name' : '',
|
|
'dataType' : 'number',
|
|
'precision' : 6,
|
|
'quantity':true,
|
|
'attr' : {
|
|
'type' : 'text'
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
},
|
|
'onChange': '$(this).val(QuantityFormat($(this).val(),6));CTABLE.setRowDate(this,$(this).parent(\'td\').parent(\'tr\').index());'
|
|
};
|
|
ccolumns[6] = {
|
|
'name' : 'quantity',
|
|
'label' : 'Ilość',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[6]['content'][0] = {
|
|
'name' : '',
|
|
'dataType' : 'number',
|
|
'quantity':true,
|
|
'precision' : 6,
|
|
'attr' : {
|
|
'type' : 'text'
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
},
|
|
'readonly':true
|
|
};
|
|
ccolumns[7] = {
|
|
'name' : 'purchase_price',
|
|
'label' : 'Sr. cena zakupu',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[7]['content'][0] = {
|
|
'name' : '',
|
|
'dataType' : 'number',
|
|
'precision' : 2,
|
|
'readonly' : true,
|
|
'attr' : {
|
|
'type' : 'text',
|
|
'hint' : 'test'
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
},
|
|
};
|
|
ccolumns[7]['content'][1] = {
|
|
'name' : '_document',
|
|
'readonly' : true,
|
|
'attr' : {
|
|
'type' : 'text',
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
},
|
|
};
|
|
ccolumns[8] = {
|
|
'showIn' : 'DetailView',
|
|
'name' : 'total',
|
|
'label' : 'Wartość',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
ccolumns[8]['content'][0] = {
|
|
'name' : '',
|
|
'dataType' : 'number',
|
|
'precision' : 6,
|
|
'readonly' : true,
|
|
'attr' : {
|
|
'type' : 'text',
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
}
|
|
};
|
|
ccolumns[9] = {
|
|
'name' : 'options',
|
|
'label' : 'Opcje',
|
|
'width' : 5, // %
|
|
'content' : new Array(),
|
|
};
|
|
|
|
var acolumns = new Array();
|
|
// define columns
|
|
// begin: number
|
|
acolumns[0] = {
|
|
'name' : 'number',
|
|
'label' : 'Lp.',
|
|
'width' : 5, // %
|
|
'content' : new Array(),
|
|
};
|
|
acolumns[0]['content'][0] = {
|
|
'name' : '',
|
|
'type' : 'text',
|
|
'readonly' : true
|
|
};
|
|
// end: number
|
|
// begin: code
|
|
acolumns[1] = {
|
|
'name' : 'action_',
|
|
'label' : 'Indeks',
|
|
'width' : 14, // %
|
|
'searchTrigger' : true,
|
|
'content' : new Array(),
|
|
};
|
|
acolumns[1]['content'][0] = {
|
|
'name' : 'code',
|
|
'attr' : {
|
|
'type' : 'hidden',
|
|
}
|
|
};
|
|
acolumns[1]['content'][1] = {
|
|
'name' : 'id',
|
|
'attr' : {
|
|
'type' : 'hidden',
|
|
}
|
|
};
|
|
acolumns[1]['content'][2] = {
|
|
'name' : 'link',
|
|
'readonly' : true,
|
|
'css' : {
|
|
'text-align' : 'left'
|
|
}
|
|
};
|
|
acolumns[1]['content'][3] = {
|
|
'name' : 'custom',
|
|
'customCodeEdit' : '<img src="modules/EcmSales/images/add_position.gif" onClick="ATABLE.getComponents({{row_index}});" style="cursor:pointer"/>',
|
|
};
|
|
acolumns[2] = {
|
|
'name' : 'name',
|
|
'label' : 'Nazwa',
|
|
'searchTrigger' : true,
|
|
'width' : 40, // %
|
|
'content' : new Array(),
|
|
};
|
|
acolumns[2]['content'][0] = {
|
|
'name' : '',
|
|
'readonly' : true,
|
|
'attr' : {
|
|
'type' : 'text'
|
|
},
|
|
'css' : {
|
|
'text-align' : 'left',
|
|
}
|
|
};
|
|
acolumns[3] = {
|
|
'name' : 'quantity',
|
|
'label' : 'Ilość',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
acolumns[3]['content'][0] = {
|
|
'name' : '',
|
|
'dataType' : 'number',
|
|
'precision' : 2,
|
|
'attr' : {
|
|
'type' : 'text'
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
}
|
|
};
|
|
acolumns[4] = {
|
|
'name' : 'price_netto',
|
|
'label' : 'Cena netto',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
acolumns[4]['content'][0] = {
|
|
'name' : '',
|
|
'readonly' : true,
|
|
'dataType' : 'number',
|
|
'attr' : {
|
|
'type' : 'text',
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
}
|
|
};
|
|
acolumns[5] = {
|
|
'name' : 'price_brutto',
|
|
'label' : 'Cena brutto',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
acolumns[5]['content'][0] = {
|
|
'name' : '',
|
|
'readonly' : true,
|
|
'dataType' : 'number',
|
|
'attr' : {
|
|
'type' : 'text',
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
}
|
|
};
|
|
acolumns[6] = {
|
|
'showIn' : 'DetailView',
|
|
'name' : 'total_netto',
|
|
'label' : 'Wartość netto',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
acolumns[6]['content'][0] = {
|
|
'name' : '',
|
|
'readonly' : true,
|
|
'dataType' : 'number',
|
|
'attr' : {
|
|
'type' : 'text',
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
}
|
|
};
|
|
acolumns[7] = {
|
|
'showIn' : 'DetailView',
|
|
'name' : 'total_brutto',
|
|
'label' : 'Wartość brutto',
|
|
'width' : 9, // %
|
|
'content' : new Array(),
|
|
};
|
|
acolumns[7]['content'][0] = {
|
|
'name' : '',
|
|
'readonly' : true,
|
|
'dataType' : 'number',
|
|
'attr' : {
|
|
'type' : 'text',
|
|
},
|
|
'css' : {
|
|
'text-align' : 'right'
|
|
}
|
|
};
|
|
acolumns[8] = {
|
|
'name' : 'options',
|
|
'label' : 'Opt',
|
|
'width' : 5, // %
|
|
'content' : new Array(),
|
|
}; |