Add JS files
This commit is contained in:
888
modules/EcmProducts/javascript/EditViewDocumentReady44.js
Executable file
888
modules/EcmProducts/javascript/EditViewDocumentReady44.js
Executable file
@@ -0,0 +1,888 @@
|
||||
$(document).ready(function () {
|
||||
InitializeTableCost();
|
||||
if ($('#tableTimeEdit').appendGrid('getRowCount') === 0) {
|
||||
$('#tableTimeEdit').appendGrid('appendRow', 1);
|
||||
}
|
||||
InitializeTableComponents();
|
||||
if ($('#tableComponents').appendGrid('getRowCount') === 0) {
|
||||
$('#tableComponents').appendGrid('appendRow', 1);
|
||||
}
|
||||
var tmp = $("select[name=select_ecmaction_category]");
|
||||
tmp.append($('<option>', {value: ""})
|
||||
.text(""));
|
||||
tmp.val('');
|
||||
|
||||
$('#srp_price').on('click',function(){
|
||||
$('#srp_price').select();
|
||||
});
|
||||
|
||||
$('#srp_price').on('change',function(){
|
||||
$('#srp_price').val(FormatNumber($('#srp_price').val(),2));
|
||||
|
||||
srp_price_replace
|
||||
|
||||
var r = confirm("Czy podmienić cenę w komponentach?");
|
||||
if (r == true) {
|
||||
$('#srp_price_replace').val(1);
|
||||
} else {
|
||||
$('#srp_price_replace').val(0);
|
||||
}
|
||||
});
|
||||
|
||||
$('#price_msh').on('click',function(){
|
||||
$('#price_msh').select();
|
||||
});
|
||||
|
||||
$('#price_msh').on('change',function(){
|
||||
$('#price_msh').val(FormatNumber($('#price_msh').val(),2));
|
||||
});
|
||||
|
||||
|
||||
$('#cena_produkcyjna').on('click',function(){
|
||||
$('#cena_produkcyjna').select();
|
||||
});
|
||||
|
||||
$('#cena_produkcyjna').on('change',function(){
|
||||
$('#cena_produkcyjna').val(FormatNumber($('#cena_produkcyjna').val(),2));
|
||||
});
|
||||
// rozszerzenie kolumn do maksa
|
||||
var trki = $("#LBL_TIME_TABLE").children('table').children('tbody').children('tr');
|
||||
$.each(trki, function (index, value) {
|
||||
if (index == 1) {
|
||||
var tmp = $(value).children('td').attr('colspan');
|
||||
$(value).children('td').attr('colspan', (tmp + 1));
|
||||
}
|
||||
});
|
||||
var trki = $("#LBL_COMPONENTS").children('table').children('tbody').children('tr');
|
||||
$.each(trki, function (index, value) {
|
||||
if (index == 1) {
|
||||
var tmp = $(value).children('td').attr('colspan');
|
||||
$(value).children('td').attr('colspan', (tmp + 1));
|
||||
}
|
||||
});
|
||||
});
|
||||
$["ui"]["autocomplete"].prototype["_renderItem"] = function (ul, item) {
|
||||
return $("<li></li>").data("item.autocomplete", item).append(
|
||||
$("<a></a>").html(item.label)).appendTo(ul);
|
||||
};
|
||||
|
||||
function InitializeTableCost() {
|
||||
// Initialize appendGrid
|
||||
$('#tableTimeEdit').appendGrid({
|
||||
hideRowNumColumn: false,
|
||||
initRows: 1,
|
||||
initData: $.parseJSON($("input[name='action_list']").val()),
|
||||
columns: [
|
||||
{
|
||||
name: 'indeks',
|
||||
display: SUGAR.language.get("app_strings", "LBL_INDEX"),
|
||||
type: 'ui-autocomplete',
|
||||
displayCss: {
|
||||
'width': '80px',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
uiOption: {
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchEcmActionsAutocomplite",
|
||||
term: request.term,
|
||||
source: 'indeks',
|
||||
},
|
||||
success: function (data) {
|
||||
response(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 3,
|
||||
select: function (event, ui) {
|
||||
var uniqueid = $(event.target).attr('id');
|
||||
uniqueid = uniqueid.substring('tableTimeEdit_indeks_'.length);
|
||||
var rowIndex = $('#tableTimeEdit').appendGrid('getRowIndex', uniqueid);
|
||||
if (ui.item.id != '') {
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'name', rowIndex, ui.item.name);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', rowIndex, '1,00');
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'ecmactionid', rowIndex, ui.item.id);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'category', rowIndex, ui.item.category);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'price', rowIndex, ui.item.price);
|
||||
}
|
||||
},
|
||||
},
|
||||
ctrlClass: 'inputs'
|
||||
}, {
|
||||
name: 'name',
|
||||
display: SUGAR.language.get("app_strings", "LBL_NAME"),
|
||||
type: 'ui-autocomplete',
|
||||
displayCss: {
|
||||
// 'width': '40%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
uiOption: {
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchEcmActionsAutocomplite",
|
||||
term: request.term,
|
||||
source: 'name',
|
||||
},
|
||||
success: function (data) {
|
||||
response(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 3,
|
||||
select: function (event, ui) {
|
||||
var uniqueid = $(event.target).attr('id');
|
||||
uniqueid = uniqueid.substring('tableTimeEdit_name_'.length);
|
||||
var rowIndex = $('#tableTimeEdit').appendGrid('getRowIndex', uniqueid);
|
||||
if (ui.item.id != '') {
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'indeks', rowIndex, ui.item.indeks);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', rowIndex, '1,00');
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'ecmactionid', rowIndex, ui.item.id);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'category', rowIndex, ui.item.category);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'price', rowIndex, ui.item.price);
|
||||
}
|
||||
},
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
}, {
|
||||
name: 'category',
|
||||
display: SUGAR.language.get("app_strings", "LBL_CATEGORY"),
|
||||
type: 'text',
|
||||
displayCss: {
|
||||
'width': '15%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
ctrlAttr: {
|
||||
disabled: 'disabled',
|
||||
readonly: 'readonly'
|
||||
},
|
||||
}, {
|
||||
name: 'unit_id',
|
||||
display: SUGAR.language.get("app_strings", "LBL_JM"),
|
||||
type: 'select',
|
||||
ctrlOptions: SUGAR.language.get("app_list_strings", "ecmproducts_unit_dom"),
|
||||
displayCss: {
|
||||
'width': '5%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
}, {
|
||||
name: 'quantity',
|
||||
display: SUGAR.language.get("app_strings", "LBL_QUANTITY"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0,00',
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
onChange: function (evt, rowIndex) {
|
||||
var row = $('#tableTimeEdit').appendGrid('getRowValue', rowIndex);
|
||||
var formatedQuantity = FormatNumber(row.quantity);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', rowIndex, formatedQuantity);
|
||||
var Quantity = UnformatNumber(formatedQuantity);
|
||||
var PriceSingle = UnformatNumber(row.price.Single);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'price', rowIndex, {Single: row.price.Single, Summary: Quantity * PriceSingle});
|
||||
updateSumEcmAction();
|
||||
}
|
||||
}, {
|
||||
name: 'price',
|
||||
display: 'Cena / Wartość',
|
||||
type: 'custom',
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
customBuilder: function (parent, idPrefix, name, uniqueIndex) {
|
||||
// Tworzenie Id dla inputow
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
//kontener
|
||||
var ctrl = document.createElement('span');
|
||||
//dodajemy kontener do komorki w tabeli
|
||||
$(ctrl).attr({id: ctrlId, name: ctrlId}).appendTo(parent);
|
||||
//Tworzymy pierwszy input dla ceny jednostkowej
|
||||
var Single = $('<input/>', {type: 'text', id: ctrlId + '_Single', name: ctrlId + '_Single', class: 'inputs'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Single).val('0,00');
|
||||
//Akacja wywolywana podczas zmiany wartosci oraz formatuje
|
||||
// oblicza (ilosc*cena jednostkowa) i wstawia
|
||||
$(Single).change(function () {
|
||||
var SingleFormated = FormatNumber($(this).val());
|
||||
$(this).val(SingleFormated);
|
||||
var qunatity = UnformatNumber($('#' + idPrefix + '_quantity_' + uniqueIndex).val());
|
||||
$('#' + ctrlId + '_Summary').val(FormatNumber(qunatity * UnformatNumber(SingleFormated)));
|
||||
updateSumEcmAction();
|
||||
});
|
||||
//dodajemy do kontenera
|
||||
$(Single).appendTo(ctrl);
|
||||
//oddzielamy widoczna linia
|
||||
var hr = document.createElement('hr');
|
||||
$(hr).css('margin', '0em').appendTo(ctrl);
|
||||
//Tworzymy drugi input dla sumy
|
||||
var Summary = $('<input/>', {type: 'text', id: ctrlId + '_Summary', name: ctrlId + '_Summary', class: 'inputs'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Summary).val('0,00');
|
||||
//Akacja wywolywana podczas zmiany wartosci oraz formatuje
|
||||
// oblicza (suma / ilosc) i wstawia
|
||||
$(Summary).change(function () {
|
||||
var SummaryFormated = FormatNumber($(this).val());
|
||||
$(this).val(SummaryFormated);
|
||||
var qunatity = UnformatNumber($('#' + idPrefix + '_quantity_' + uniqueIndex).val());
|
||||
$('#' + ctrlId + '_Single').val(FormatNumber(UnformatNumber(SummaryFormated) / qunatity));
|
||||
updateSumEcmAction();
|
||||
});
|
||||
$(Summary).appendTo(ctrl);
|
||||
return ctrl;
|
||||
},
|
||||
customGetter: function (idPrefix, name, uniqueIndex) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
var Single = $('#' + ctrlId + '_Single').val();
|
||||
var Summary = $('#' + ctrlId + '_Summary').val();
|
||||
return {Single: Single, Summary: Summary};
|
||||
},
|
||||
customSetter: function (idPrefix, name, uniqueIndex, value) {
|
||||
if (value != null) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
$('#' + ctrlId + '_Single').val(value['Single'] == null ? '0,00' : FormatNumber(value['Single']));
|
||||
$('#' + ctrlId + '_Summary').val(value['Summary'] == null ? '0,00' : FormatNumber(value['Summary']));
|
||||
}
|
||||
},
|
||||
}, {
|
||||
name: 'ecmactionid',
|
||||
display: 'ecmactionid',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
},
|
||||
],
|
||||
i18n: {
|
||||
append: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_APPEND"),
|
||||
remove: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVE"),
|
||||
insert: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_INSERT"),
|
||||
moveUp: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEUP"),
|
||||
moveDown: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEDOWN"),
|
||||
removeLast: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVELAST"),
|
||||
rowEmpty: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWEMPTY"),
|
||||
rowDrag: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWDRAG"),
|
||||
},
|
||||
customGridButtons: {
|
||||
insert: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/add_position.gif';
|
||||
return button;
|
||||
},
|
||||
remove: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/deleterow.gif';
|
||||
return button;
|
||||
},
|
||||
moveUp: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowup.gif';
|
||||
return button;
|
||||
},
|
||||
moveDown: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowdown.gif';
|
||||
return button;
|
||||
},
|
||||
},
|
||||
afterRowRemoved: function (caller, rowIndex) {
|
||||
var quantity = $('#tableTimeEdit').appendGrid(
|
||||
'getRowCount');
|
||||
if (quantity == 0) {
|
||||
$('#tableTimeEdit').appendGrid('appendRow', 1);
|
||||
}
|
||||
},
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
append: true,
|
||||
moveUp: true,
|
||||
moveDown: true
|
||||
}
|
||||
});
|
||||
$('#tableTimeEdit_price_td_head').html('Cena<br>Wartość');
|
||||
var count = $('#tableTimeEdit').appendGrid('getRowCount');
|
||||
for (var i = 0; i < count; i++) {
|
||||
var value = $('#tableTimeEdit').appendGrid('getCtrlValue', 'quantity', i);
|
||||
$('#tableTimeEdit').appendGrid('setCtrlValue', 'quantity', i, FormatNumber(value));
|
||||
}
|
||||
//Podsumowanie
|
||||
var html = '<tr><td colspan="6" style="vertical-align: middle;border-top: 1px solid black">Suma:</td><td style="text-align: right;border-top: 1px solid black"><span id="sumEcmActionPriceTotal">0,00</span></td></tr>';
|
||||
$('#tableTimeEdit').find('tfoot tr:last').after(html);
|
||||
updateSumEcmAction();
|
||||
}
|
||||
|
||||
function updateSumEcmAction() {
|
||||
var data = $('#tableTimeEdit').appendGrid('getAllValue');
|
||||
var sumPriceSingle = 0;
|
||||
var sumPriceTotal = 0;
|
||||
$.each(data, function (index, value) {
|
||||
sumPriceTotal += parseFloat(UnformatNumber(value.price.Summary));
|
||||
});
|
||||
$('#sumEcmActionPriceTotal').html(FormatNumber(sumPriceTotal));
|
||||
}
|
||||
|
||||
|
||||
function searchActions() {
|
||||
var nazwa = $('#searchEcmActionInput').val();
|
||||
var kategoria = $('select[name=select_ecmaction_category]').find(":selected").val();
|
||||
var wynik = '';
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchActionsList",
|
||||
term: nazwa,
|
||||
category: kategoria,
|
||||
},
|
||||
success: function (data) {
|
||||
wynik = data;
|
||||
}
|
||||
});
|
||||
if (wynik != '') {
|
||||
InitializeSearchtableTable(wynik);
|
||||
$('#ttabble').show();
|
||||
} else {
|
||||
console.log("nie znaleziono wyników");
|
||||
}
|
||||
}
|
||||
|
||||
function InitializeSearchtableTable(data) {
|
||||
// Initialize appendGrid
|
||||
$('#wyszukiwanie').appendGrid({
|
||||
hideRowNumColumn: true,
|
||||
initRows: 0,
|
||||
columns: [
|
||||
{
|
||||
name: 'indeks',
|
||||
display: 'Indeks',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'width': '90px', 'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'name',
|
||||
display: 'Nazwa',
|
||||
//type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'category',
|
||||
display: 'Kategoria',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'width': '130px', 'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'price1',
|
||||
display: 'Koszt',
|
||||
type: 'text',
|
||||
ctrlCss: {'text-align': 'right'},
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'width': '70px', 'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'displaytime',
|
||||
display: 'Czas',
|
||||
type: 'text',
|
||||
ctrlAttr: {readonly: 'readonly'},
|
||||
displayCss: {'width': '70px', 'vertical-align': 'middle'},
|
||||
onClick: function (evt, rowIndex) {
|
||||
dodajDoListy(evt, rowIndex);
|
||||
}
|
||||
}, {
|
||||
name: 'ecmactionid',
|
||||
display: 'ecmactionid',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'time',
|
||||
display: 'time',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'cost_action',
|
||||
display: 'cost_action',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'cost_hour',
|
||||
display: 'cost_hour',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, ],
|
||||
i18n: {
|
||||
rowEmpty: 'Brak wyników'
|
||||
},
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
append: true,
|
||||
insert: true,
|
||||
remove: true,
|
||||
moveUp: true,
|
||||
moveDown: true
|
||||
},
|
||||
initData: data,
|
||||
});
|
||||
$('thead').removeClass('ui-widget-header');
|
||||
$('td').removeClass('ui-widget-header');
|
||||
$('tbody').removeClass('ui-widget-content');
|
||||
$('td').removeClass('ui-widget-content');
|
||||
$('tfoot').removeClass('ui-widget-header');
|
||||
}
|
||||
|
||||
function dodajDoListy(evt, rowIndex) {
|
||||
var tmp = $('#wyszukiwanie').appendGrid('getRowValue', rowIndex);
|
||||
tmp['price1'] = '0,00';
|
||||
tmp['displaytime'] = '00.00:00';
|
||||
tmp['quantity'] = '0';
|
||||
$('#tableTimeEdit').appendGrid(
|
||||
'insertRow',
|
||||
[{
|
||||
indeks: tmp['indeks'],
|
||||
name: tmp['name'],
|
||||
quantity: '0,00',
|
||||
ecmactionid: tmp['ecmactionid'],
|
||||
category: tmp['category'],
|
||||
cost_action: tmp['cost_action'],
|
||||
cost_hour: tmp['cost_hour'],
|
||||
displaytime: tmp['displaytime'],
|
||||
time: tmp['time'],
|
||||
price1: '0,00'
|
||||
}], 0);
|
||||
$('#ttabble').hide();
|
||||
}
|
||||
|
||||
|
||||
function InitializeTableComponents() {
|
||||
// Initialize appendGrid
|
||||
$('#tableComponents').appendGrid({
|
||||
hideRowNumColumn: false,
|
||||
initRows: 1,
|
||||
initData: $.parseJSON($("input[name='component_list']").val()),
|
||||
columns: [
|
||||
{
|
||||
name: 'code',
|
||||
display: SUGAR.language.get("app_strings", "LBL_INDEX"),
|
||||
type: 'ui-autocomplete',
|
||||
displayCss: {
|
||||
'width': '150px',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left',
|
||||
'vertical-align': 'middle',
|
||||
},
|
||||
uiOption: {
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchComponentsAutocomplite",
|
||||
term: request.term,
|
||||
source: 'code',
|
||||
},
|
||||
success: function (data) {
|
||||
response(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 3,
|
||||
select: function (event, ui) {
|
||||
var uniqueid = $(event.target).attr('id');
|
||||
uniqueid = uniqueid.substring('tableComponents_code_'.length);
|
||||
var rowIndex = $('#tableComponents').appendGrid('getRowIndex', uniqueid);
|
||||
|
||||
if (ui.item.id != '') {
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'name', rowIndex, ui.item.name);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex, '0.000000');
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'ecmcomponent_id', rowIndex, ui.item.ecmcomponent_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'unit_id', rowIndex, ui.item.unit_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'product_category_id', rowIndex, ui.item.product_category_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'product_category_name', rowIndex, ui.item.product_category_name);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: ui.item.srp_price, Summary: 0.000000});
|
||||
|
||||
}
|
||||
},
|
||||
},
|
||||
ctrlClass: 'inputs'
|
||||
}, {
|
||||
name: 'name',
|
||||
display: SUGAR.language.get("app_strings", "LBL_NAME"),
|
||||
type: 'ui-autocomplete',
|
||||
displayCss: {
|
||||
// 'width': '40%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
uiOption: {
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "index.php?module=EcmProducts&action=javahelper&to_pdf=1",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
data: {
|
||||
job: "searchComponentsAutocomplite",
|
||||
term: request.term,
|
||||
source: 'name',
|
||||
},
|
||||
success: function (data) {
|
||||
|
||||
console.log(data);
|
||||
response(data);
|
||||
}
|
||||
});
|
||||
},
|
||||
minLength: 3,
|
||||
select: function (event, ui) {
|
||||
var uniqueid = $(event.target).attr('id');
|
||||
uniqueid = uniqueid.substring('tableComponents_name_'.length);
|
||||
var rowIndex = $('#tableComponents').appendGrid('getRowIndex', uniqueid);
|
||||
if (ui.item.id != '') {
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'code', rowIndex, ui.item.code);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex, '0.000000');
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'ecmcomponent_id', rowIndex, ui.item.ecmcomponent_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'unit_id', rowIndex, ui.item.unit_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'product_category_id', rowIndex, ui.item.product_category_id);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'product_category_name', rowIndex, ui.item.product_category_name);
|
||||
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: ui.item.srp_price, Summary: 0.000000});
|
||||
}
|
||||
},
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
}, {
|
||||
name: 'product_category_name',
|
||||
display: SUGAR.language.get("app_strings", "LBL_CATEGORY"),
|
||||
type: 'text',
|
||||
displayCss: {
|
||||
'width': '10%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
ctrlAttr: {
|
||||
disabled: 'disabled',
|
||||
readonly: 'readonly'
|
||||
},
|
||||
}, {
|
||||
name: 'unit_id',
|
||||
display: SUGAR.language.get("app_strings", "LBL_JM"),
|
||||
type: 'select',
|
||||
ctrlOptions: SUGAR.language.get("app_list_strings", "ecmproducts_unit_dom"),
|
||||
displayCss: {
|
||||
'width': '3%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'left'
|
||||
},
|
||||
ctrlClass: 'inputs',
|
||||
}, {
|
||||
name: 'quantity_recipe',
|
||||
display: SUGAR.language.get("app_strings", "LBL_QUANTITY_RECIPE"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0.00000000',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
onClick: function (evt, rowIndex) {
|
||||
|
||||
|
||||
$('#tableComponents_quantity_recipe_'+(rowIndex+1)).select();
|
||||
},
|
||||
onChange: function (evt, rowIndex) {
|
||||
var row = $('#tableComponents').appendGrid('getRowValue', rowIndex);
|
||||
var formatedQuantity = QuantityFormat(row.quantity_recipe,8);
|
||||
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity_recipe', rowIndex, formatedQuantity);
|
||||
var Quantity=formatedQuantity;
|
||||
var PriceSingle = (row.price.Single);
|
||||
|
||||
var Divider = UnformatNumber(row.divider);
|
||||
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex,QuantityFormat(Quantity/Divider,8));
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: row.price.Single, Summary: (Quantity/Divider) * PriceSingle});
|
||||
|
||||
updateSumComponents();
|
||||
}
|
||||
}, {
|
||||
name: 'divider',
|
||||
display: SUGAR.language.get("app_strings", "LBL_DIVIDER"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '1,0',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
onClick: function (evt, rowIndex) {
|
||||
|
||||
|
||||
$('#tableComponents_divider_'+(rowIndex+1)).select();
|
||||
},
|
||||
onChange: function (evt, rowIndex) {
|
||||
var row = $('#tableComponents').appendGrid('getRowValue', rowIndex);
|
||||
var formatedQuantity = FormatNumber(row.divider,2);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'divider', rowIndex, formatedQuantity);
|
||||
var Quantity = UnformatNumber(formatedQuantity);
|
||||
var PriceSingle = (row.price.Single);
|
||||
var Divider = row.quantity_recipe;
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex,QuantityFormat(Divider/Quantity,6));
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: row.price.Single, Summary: (Divider/Quantity) * PriceSingle});
|
||||
|
||||
updateSumComponents();
|
||||
}
|
||||
}, {
|
||||
name: 'quantity',
|
||||
display: SUGAR.language.get("app_strings", "LBL_QUANTITY"),
|
||||
type: 'text',
|
||||
ctrlClass: 'inputs',
|
||||
value: '0.000000',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
ctrlCss: {
|
||||
'text-align': 'right'
|
||||
},
|
||||
onClick: function (evt, rowIndex) {
|
||||
|
||||
|
||||
$('#tableComponents_quantity_'+(rowIndex+1)).select();
|
||||
},
|
||||
ctrlAttr: { 'readonly': 'readonly' },
|
||||
onChange: function (evt, rowIndex) {
|
||||
var row = $('#tableComponents').appendGrid('getRowValue', rowIndex);
|
||||
var formatedQuantity = QuantityFormat(row.quantity,6);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', rowIndex, formatedQuantity);
|
||||
var Quantity = formatedQuantity;
|
||||
var PriceSingle = (row.price.Single);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'price', rowIndex, {Single: row.price.Single, Summary: Quantity * PriceSingle});
|
||||
|
||||
updateSumComponents();
|
||||
}
|
||||
}, {
|
||||
name: 'price',
|
||||
display: 'Cena / Wartość',
|
||||
type: 'custom',
|
||||
displayCss: {
|
||||
'width': '7%',
|
||||
'vertical-align': 'middle'
|
||||
},
|
||||
customBuilder: function (parent, idPrefix, name, uniqueIndex) {
|
||||
// Tworzenie Id dla inputow
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
//kontener
|
||||
var ctrl = document.createElement('span');
|
||||
//dodajemy kontener do komorki w tabeli
|
||||
$(ctrl).attr({id: ctrlId, name: ctrlId}).appendTo(parent);
|
||||
//Tworzymy pierwszy input dla ceny jednostkowej
|
||||
var Single = $('<input/>', {type: 'text', id: ctrlId + '_Single', name: ctrlId + '_Single', class: 'inputs'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Single).val('0,00');
|
||||
//Akacja wywolywana podczas zmiany wartosci oraz formatuje
|
||||
// oblicza (ilosc*cena jednostkowa) i wstawia
|
||||
$(Single).change(function () {
|
||||
var SingleFormated = FormatNumber($(this).val());
|
||||
$(this).val(SingleFormated);
|
||||
var qunatity = ($('#' + idPrefix + '_quantity_' + uniqueIndex).val());
|
||||
$('#' + ctrlId + '_Summary').val(FormatNumber(qunatity * UnformatNumber(SingleFormated),6));
|
||||
updateSumComponents();
|
||||
});
|
||||
$(Single).on('click',function () {
|
||||
$('#tableComponents_price_'+(uniqueIndex)+"_Single").select();
|
||||
});
|
||||
//dodajemy do kontenera
|
||||
$(Single).appendTo(ctrl);
|
||||
//oddzielamy widoczna linia
|
||||
var hr = document.createElement('hr');
|
||||
$(hr).css('margin', '0em').appendTo(ctrl);
|
||||
//Tworzymy drugi input dla sumy
|
||||
var Summary = $('<input/>', {type: 'text', id: ctrlId + '_Summary', name: ctrlId + '_Summary', class: 'inputs'}).css({'width': '100%', 'text-align': 'right'});
|
||||
//Ustawiamy wartosc domyslna
|
||||
$(Summary).val('0,000000');
|
||||
//Akacja wywolywana podczas zmiany wartosci oraz formatuje
|
||||
// oblicza (suma / ilosc) i wstawia
|
||||
$(Summary).change(function () {
|
||||
var SummaryFormated = FormatNumber($(this).val(),6);
|
||||
$(this).val(SummaryFormated);
|
||||
var qunatity = ($('#' + idPrefix + '_quantity_' + uniqueIndex).val());
|
||||
$('#' + ctrlId + '_Single').val(FormatNumber(UnformatNumber(SummaryFormated) / qunatity));
|
||||
updateSumComponents();
|
||||
});
|
||||
$(Summary).appendTo(ctrl);
|
||||
return ctrl;
|
||||
},
|
||||
customGetter: function (idPrefix, name, uniqueIndex) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
var Single = UnformatNumber($('#' + ctrlId + '_Single').val());
|
||||
var Summary = UnformatNumber($('#' + ctrlId + '_Summary').val());
|
||||
return {Single: Single, Summary: Summary};
|
||||
},
|
||||
customSetter: function (idPrefix, name, uniqueIndex, value) {
|
||||
console.log(value);
|
||||
if (value != null) {
|
||||
var ctrlId = idPrefix + '_' + name + '_' + uniqueIndex;
|
||||
$('#' + ctrlId + '_Single').val(value['Single'] == null ? '0,00' : FormatNumber(value['Single']));
|
||||
$('#' + ctrlId + '_Summary').val(value['Summary'] == null ? '0,000000' : FormatNumber(value['Summary'],6));
|
||||
}
|
||||
},
|
||||
}, {
|
||||
name: 'ecmcomponent_id',
|
||||
display: 'ecmcomponent_id',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
}, {
|
||||
name: 'product_category_id',
|
||||
display: 'product_category_id',
|
||||
type: 'text',
|
||||
invisible: true,
|
||||
},
|
||||
],
|
||||
i18n: {
|
||||
append: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_APPEND"),
|
||||
remove: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVE"),
|
||||
insert: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_INSERT"),
|
||||
moveUp: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEUP"),
|
||||
moveDown: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_MOVEDOWN"),
|
||||
removeLast: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_REMOVELAST"),
|
||||
rowEmpty: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWEMPTY"),
|
||||
rowDrag: SUGAR.language.get("app_strings", "LBL_APPENDGRID_I18_ROWDRAG"),
|
||||
},
|
||||
customGridButtons: {
|
||||
insert: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/add_position.gif';
|
||||
return button;
|
||||
},
|
||||
remove: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/deleterow.gif';
|
||||
return button;
|
||||
},
|
||||
moveUp: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowup.gif';
|
||||
return button;
|
||||
},
|
||||
moveDown: function () {
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/moverowdown.gif';
|
||||
return button;
|
||||
},
|
||||
},
|
||||
afterRowRemoved: function (caller, rowIndex) {
|
||||
var quantity = $('#tableComponents').appendGrid(
|
||||
'getRowCount');
|
||||
if (quantity == 0) {
|
||||
$('#tableComponents').appendGrid('appendRow', 1);
|
||||
}
|
||||
},
|
||||
afterRowAppended: function(caller, parentRowIndex, addedRowIndex){
|
||||
|
||||
$('#tableComponents_name_'+(addedRowIndex+1)).focus();
|
||||
},
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
append: false,
|
||||
insert: false,
|
||||
moveUp: true,
|
||||
moveDown: true
|
||||
}
|
||||
});
|
||||
var buttonSelect = document.createElement('img');
|
||||
buttonSelect.src = 'modules/EcmQuotes/images/search.gif';
|
||||
$(buttonSelect).addClass('selectComponent');
|
||||
$(buttonSelect).on('click', selectComponent);
|
||||
//$("#tableComponents").find("tbody").find(".last").append(buttonSelect);
|
||||
$('#tableComponents_price_td_head').html('Cena<br>Wartość');
|
||||
var count = $('#tableComponents').appendGrid('getRowCount');
|
||||
for (var i = 0; i < count; i++) {
|
||||
var value = $('#tableComponents').appendGrid('getCtrlValue', 'quantity', i);
|
||||
var divider = $('#tableComponents').appendGrid('getCtrlValue', 'divider', i);
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'quantity', i, QuantityFormat(value,6));
|
||||
$('#tableComponents').appendGrid('setCtrlValue', 'divider', i, FormatNumber(divider,2));
|
||||
}
|
||||
//Podsumowanie
|
||||
var html = '<tr><td colspan="8" style="vertical-align: middle;border-top: 1px solid black">Suma:</td><td style="text-align: right;border-top: 1px solid black"><span id="sumComponentsPriceTotal">0,000000</span></td></tr>';
|
||||
$('#tableComponents').find('tfoot tr:last').after(html);
|
||||
updateSumComponents();
|
||||
}
|
||||
|
||||
function selectComponent(){
|
||||
var id = $(this).closest('tr').find("input[name^='tableComponents_ecmcomponent_id_']").attr('id');
|
||||
var name = $(this).closest('tr').find("input[name^='tableComponents_name_']").attr('id');
|
||||
var code = $(this).closest('tr').find("input[name^='tableComponents_code_']").attr('id');
|
||||
var unit_id = $(this).closest('tr').find("select[name^='tableComponents_unit_id']").attr('id');
|
||||
|
||||
var window = open_popup('EcmProducts', 600, 400, '', true, false,{'call_back_function': 'testms', 'form_name': 'EditView', 'field_to_name_array':{'id': id, 'name': name ,'code' : code ,'unit_id' : unit_id}}, 'single', true);
|
||||
}
|
||||
function testms(dane1,dane2){
|
||||
console.log(dane1);
|
||||
console.log(dane2);
|
||||
}
|
||||
function updateSumComponents() {
|
||||
var data = $('#tableComponents').appendGrid('getAllValue');
|
||||
var sumPriceSingle = 0;
|
||||
var sumPriceTotal = 0;
|
||||
$.each(data, function (index, value) {
|
||||
console.log(value.price.Single);
|
||||
console.log(parseFloat(value.price.Single));
|
||||
sumPriceTotal += parseFloat(value.price.Summary);
|
||||
});
|
||||
$('#sumComponentsPriceTotal').html(FormatNumber(sumPriceTotal,6));
|
||||
}
|
||||
Reference in New Issue
Block a user