This commit is contained in:
2024-04-27 09:23:34 +02:00
commit 11e713ca6f
11884 changed files with 3263371 additions and 0 deletions

View File

@@ -0,0 +1,476 @@
function searchCode(start_from) {
url='index.php?module=EcmProducts&action=searchCode&start='+start_from+'&to_pdf=1';
var req=mint.Request();
req.OnSuccess = function() {
document.getElementById("code").value = this.responseText;
};
req.Send(url);
}
function checkCode(code) {
if (document.forms.EditView.record.value!="") return;
url='index.php?module=EcmProducts&action=checkCode&code='+code+'&to_pdf=1';
var req=mint.Request();
req.OnSuccess = function() {
if (this.responseText=='0') alert(MOD.LBL_CODE_ERROR);
if (this.responseText=='2') alert('Istnieje kod typu: '+code+'_-----');
};
req.Send(url);
}
function freeCodes(code) {
window.open("index.php?module=EcmProducts&action=freeCodes&code="+code, "_blank");
}
function getBaseComponents(type) {
if (type == 1)
var code = OPT.base_code;
if (type == 2)
var code = document.getElementById("components_code").value;
url='index.php?module=EcmProducts&action=getBaseComponents&product_code='+code+'&to_pdf=1';
var req=mint.Request();
req.OnSuccess = function() {
ItemListClear();
OPT.base_code = null;
try {
pl = eval(this.responseText);
for(x in pl) { var pl_row = pl[x]; if(!pl[x].code || pl[x].code == '') {} else N.addRow().setData(pl_row); }
} catch(err) { pl = null; };
};
req.Send(url);
}
function SetTabIndexs() {
var main = document.getElementById('main');
var td = main.getElementsByTagName('td');
var selectedTable = null;
//var selectingColor = 'red';
//var selectingCellTable = 'green';
var TableIndex = 0;
for(var i=0; i<td.length; i++) {
if(td[i].className == 'tabEditViewDF') {
var TI = 0;
if(td[i].parentNode.cells.item(1) == td[i]) TI = 101+TableIndex; else TI = 102+TableIndex;
var nodes = td[i].getElementsByTagName('input');
for(var j=0; j<nodes.length; j++) nodes[j].tabIndex = TI;
var nodes = td[i].getElementsByTagName('select');
for(var j=0; j<nodes.length; j++) nodes[j].tabIndex = TI;
var nodes = td[i].getElementsByTagName('textarea');
for(var j=0; j<nodes.length; j++) nodes[j].tabIndex = TI;
if(td[i].parentNode.parentNode.parentNode !== selectedTable) {
//if(selectingColor == 'red') selectingColor = 'blue'; else selectingColor = 'red';
selectedTable = td[i].parentNode.parentNode.parentNode;
TableIndex++;
}
}
}
}
function doRequest(where,post,doFunction,error) {
this.Display = function(result) { doFunction(result.responseText); }
this.Fail = function(result){ if(error) alert(error);}
YAHOO.util.Connect.asyncRequest('POST',where,{success:this.Display,failure:this.Fail},post);
}
function changeValidateRequired(formname,name,required) {
for(var i=0; i<validate[formname].length; i++)
if(validate[formname][i][0] == name) { validate[formname][i][2] = required; break; }
}
function set_focus() { document.getElementById('name').focus(); }
function my_popup(module, field_array, met, call_back_function, form_name) {
if(!call_back_function) call_back_function = "set_return";
if(!form_name) form_name = "EditView";
return open_popup(module, 900, 700, met, true, false, {"call_back_function":call_back_function,"form_name":form_name,"field_to_name_array":field_array});
}
function addEvent(object,eventName,do_function) {
if(typeof(object) == "string") object = document.getElementById(object);
if(!object) { alert('No object in function addEvent!'); return; }
if(object.addEventListener) {
object.addEventListener(eventName, do_function, false);
} else {
object.attachEvent('on'+eventName, do_function);
}
}
function findPos(obj) {
var nleft = 0;
var ntop = 0;
if (obj.offsetParent) {
nleft = obj.offsetLeft
ntop = obj.offsetTop
while (obj = obj.offsetParent) {
nleft += obj.offsetLeft
ntop += obj.offsetTop
}
}
return [nleft,ntop];
}
function cursorEOT(isField) {
isRange = isField.createTextRange();
isRange.move('textedit');
isRange.select();
testOverflow = isField.scrollTop;
if (testOverflow != 0){return true}
else {return false}
}
function adjustRows(isField) {
while (cursorEOT(isField)){isField.rows++}
}
function insertText(isField,isText) {
isField.value = testText;
isField.focus();
}
function changer() {
this.list = new Object();
this.add = function(object,type,do_function,start_value) {
if(typeof(object) == "string") object = document.getElementById(object);
if(!object) return;
this.list[object.id] = new Object();
this.list[object.id].object = object;
this.list[object.id].type = type;
this.list[object.id].do_function = do_function;
this.list[object.id].start_value = start_value;
this.list[object.id].value = '';
}
this.getValue = function(element) {
var value = null;
if(element.object) {
if(element.type == "innerHTML") value = element.object.innerHTML;
if(element.type == "value") value = element.object.value;
if(element.type == "checked") value = element.object.checked;
}
return value;
}
this.interval = 1000;
this.timer = null;
this.startTimer = function() {
var cc = this;
this.timer = setInterval(
function(){
var list = cc.list;
for(x in list) {
if(list[x].start_value) {
list[x].value = cc.getValue(list[x]);
list[x].start_value = false;
}
else {
var value = cc.getValue(list[x]);
if(list[x].value !== value)
if(list[x].do_function)
list[x].do_function(list[x].object);
list[x].value = value;
}
}
},
this.interval
);
}
this.stopTimer = function () {
clearInterval(this.timer);
this.timer = null;
}
}
var ERROR = false;
var ItemListSave = function(json) { }
function ShowLoadingView() {
var slv = document.getElementById('ShowLoadingView');
if(!slv) {
slv = document.createElement('div');
slv.id = 'ShowLoadingView';
slv.className = 'transparent_class_loading';
slv.style.width = '100%';
slv.style.height = '500%';
var sli = document.createElement('img');
sli.className = 'transparent_class_loading_image';
sli.src = 'themes/default/images/loading.gif';
slv.appendChild(sli);
document.body.appendChild(slv);
}
slv.style.display = '';
}
function HideLoadingView() {
var slv = document.getElementById('ShowLoadingView');
if(slv) slv.style.display = 'none';
}
function SaveForm() {
ShowLoadingView();
setTimeout( function() {
if(OPT['checkbox_demo'] == 1 && document.forms.EditView.record.value == '') { alert(MOD.LBL_DEMO_VERSION_INFORMATION); return; }
ERROR = false;
//document.getElementById('position_list').value = ItemListSave(true);
if(ERROR) { alert(MOD['LBL_SAVE_FORM_ERROR']); HideLoadingView(); return false; }
document.forms.EditView.action.value = 'Save';
if(check_form('EditView')) {
var result = confirm(MOD.LBL_CONFIRM_QUESTION);
if(result) document.forms.EditView.status.value = (OPT['auto_commiting']?'s30':'s20');
doRequest('index.php',getFormPost('Save'),function(result){
document.forms.EditView.record.value = result.substring(result.length-36);
alert(MOD['LBL_SAVED']);
if(OPT['setEmailTab']) setEMAIL(true); else window.location = 'index.php?module='+document.forms.EditView.module.value+'&action=DetailView&record='+document.forms.EditView.record.value;
},
MOD['LBL_NOT_SAVED']
);
} else { alert(MOD['LBL_NOT_SAVED']); HideLoadingView(); return false; }
},200);
}
function ItemListClear() {
while(N.rowCount()>0) N.row(0).deleteRow();
}
function getFormPost(action) {
if(!action) action = 'previewPDF';
var pd = 'to_pdf=1'+'&module=EcmQuotes&action='+action+'&record='+document.forms.EditView.record.value;
pd += '&cache=fromJava'+ItemListSave(true);
var pd2 = new Object();
pd2['module'] = 'EcmQuotes';
pd2['action'] = action;
pd2['record'] = document.forms.EditView.record.value;
pd2['to_pdf'] = '1';
pd2['cache'] = 'fromJava';
document.forms.EditView.position_list.value = '';
document.forms["EditView"].action.value = action;
var tmp;
for(var i=0; i<document.forms["EditView"].elements.length; i++) {
tmp = document.forms["EditView"].elements[i];
if(tmp.name != '') {
if(tmp.type == "checkbox")
pd2[document.forms["EditView"].elements[i].name] =(document.forms["EditView"].elements[i].checked ? '1' : '0');
else
pd2[document.forms["EditView"].elements[i].name] = document.forms["EditView"].elements[i].value;
}
}
pd += '&otherFormData='+JSON.stringifyNoSecurity(pd2);
return pd;
}
/*
function sendFormPostToPdf() {
ShowLoadingView();
setTimeout( function() {
ERROR = false;
//document.getElementById('position_list').value = ItemListSave(true);
if(ERROR) { alert('There are some errors on list'); HideLoadingView(); return false; }
doRequest("index.php",getFormPost(),function(result){
HideLoadingView();
SetTab('PREVIEW');
EcmPreviewPDF('index.php?module=EcmQuotes&action=previewPDF&to_pdf=1&from=EcmQuotes',{zoom:75});
}
);
}, 200);
}*/
function sendFormPostToPdf() {
ERROR = false;
document.getElementById('position_list').value = ItemListSave(true);
if(ERROR) { alert('There are some errors on list'); return false; }
doRequest("index.php",getFormPost(),function(result){
if(SHOW_PDF_IN_DIV==1){
HideLoadingView();
//SetTab('PREVIEW');
EcmPreviewPDF('index.php?module=EcmQuotes&action=previewPDF&to_pdf=1&from=EcmQuotes',{zoom:75});
}
else{
SetTab('PREVIEW');
document.getElementById('previewPDF').innerHTML = "<iframe style='border:none;width:100%;height:1200px;' frameborder='no' src='index.php?module=EcmQuotes&action=previewPDF&to_pdf=1&from=EcmQuotes#zoom=75'>Yours browser not accept iframes!</iframe>";
}
}
);
}
function canConfirm() {
if(document.forms.EditView.status.value == "accepted" && !OPT.user.confirm_quotes) {
alert('This option is disabled for You.');
document.forms.EditView.status.value = ((OPT.old_status)?OPT.old_status:'');
}
OPT.old_status = document.forms.EditView.status.value;
}
function CheckDiscount(noAlert) {
var discount = 0;
var tmp = UserFormatNumberToNumber(document.getElementById('discount').value);
if(tmp == -1) {
if(!noAlert)
alert(MOD['LBL_DISCOUNT_ERROR']+' ('+document.getElementById('discount').value+')');
discount = -1;
document.getElementById('discount').style.color = 'red';
} else {
discount = tmp;
document.getElementById('discount').value = NumberToUserFormatNumber(discount);
document.getElementById('discount').style.color = 'black';
}
return discount;
}
//document.getElementById('previewPDF').innerHTML = "<iframe style='border:0px; width:100%; height:100%;' src='index.php?module=EcmInvoiceOuts&action=InvoicePDFPreview&to_pdf=1'>Yours browser not accept iframes!</iframe>";
//ProductListSave();
//YAHOO.util.Connect.asyncRequest('POST','index.php',{success:this.Display,failure:this.Fail},this.postData());
var AjaxSearchProducts;
var parentFL;
var productFL;
var contactFL;
addEvent(
window,
'load',
function () {
var CHANGER = new changer();
CHANGER.interval = 500;
set_focus();
//initialize table
//N = new MyTable('itemsTable');
//N.divParent = document.getElementById('itemsTableDIV');
var from_popup_return = false;
function returnedData(popup_reply_data) {
from_popup_return = true;
var form_name = popup_reply_data.form_name;
var name_to_value_array = popup_reply_data.name_to_value_array;
for (var the_key in name_to_value_array) {
if(the_key == 'toJSON'){}
else {
var displayValue=name_to_value_array[the_key].replace(/&amp;/gi,'&').replace(/&lt;/gi,'<').replace(/&gt;/gi,'>').replace(/&#039;/gi,'\'').replace(/&quot;/gi,'"');;
var e = document.getElementById(the_key);
if(e) { e.value = displayValue; }
}
}
//if(N.selectedRow) N.selectedRow.calculateTotal();
};
var itd = document.getElementById('itemsTableDIV');
itd.onscroll = function() {
if(!AjaxSearchProducts.AjaxSearchFrozen)
if(N.selectedCell && N.selectedCell.LeftPosition && N.selectedCell.TopPosition) {
var top = N.selectedCell.TopPosition+N.selectedCell.offsetHeight;
if(((N.selectedCell.offsetTop+N.selectedCell.offsetHeight-this.scrollTop) > (this.offsetHeight+5)) || ((N.selectedCell.offsetTop-this.scrollTop) < (-10)))
AjaxSearchProducts.div.style.display = 'none';
else
AjaxSearchProducts.div.style.display = '';
AjaxSearchProducts.div.style.top = top - this.scrollTop;
}
}
ItemListSave = function(json) {
//if(CheckDiscount() == -1) { ERROR = true; return false; }
//calculateTotal();
var data = new Object();
for(var i=0; i<N.rowCount(); i++) {
data[i.toString()] = N.row(i).getData();
}
return json ? JSON.stringifyNoSecurity(data) : data;
}
var sqs_objects = [];
sqs_objects["code_p"] = {
"method":"get_product_array",
"modules":["EcmProducts"],
"field_list":["date_entered", "code", "id", "encoded_unit_id", "vat_id", "encoded_category_id", "name", "selling_price", "currency_id"],
"populate_list":["code_p", "code_p", "id_p", "unit_id_p", "vat_id_p", "category_id_p", "name_p", "price_p", "currency_id_p"],
"conditions":[{"name":"code","op":"like_custom","end":"%","value":""}],
"limit":"30",
"order":"code",
"no_match_text":"No Match"
};
sqs_objects["name_p"] = {
"method":"get_product_array",
"modules":["EcmProducts"],
"field_list":["date_entered", "name", "id", "encoded_unit_id", "vat_id", "encoded_category_id", "code", "selling_price", "currency_id"],
"populate_list":["name_p", "name_p", "id_p", "unit_id_p", "vat_id_p", "category_id_p", "code_p", "price_p", "currency_id_p"],
"conditions":[{"name":"name","op":"like_custom","end":"%","value":""}],
"limit":"30",
"order":"name",
"no_match_text":"No Match"
};
function generateNumber() {
if(document.getElementById('template_id').value == '') { alert('There are no DocumentTemplates in data base!'); return;}
doRequest(
'index.php',
'to_pdf=1&generate=1&module=EcmQuotes&action=generateNumber&type=normal&template_id='+document.getElementById('template_id').value+'&record='+document.forms.EditView.record.value,
function(result){
var arr = eval(result)[0];
document.getElementById('number').value = arr.number;
document.getElementById('document_no').value = arr.document_no;
},
''
);
};
//create Product
productFL = new FormLoader();
productFL.load('EcmQuotes','Parents','productFL');
productFL.onResponseData = function(data) {
data.price = data.selling_price;
data.quantity = '1';
N.selectedRow.setData(data);
N.selectedRow.calculateTotal();
};
CHANGER.startTimer();
var check_form_ = check_form;
check_form = function(formname) {
CTABLE.saveItems();
ATABLE.saveItems();
// return false;
if ((document.getElementById('group_ks').value)=='0') {
alert('Grupa księgowa nie może być pusta!');
return false;
}
//document.forms.EditView.position_list.value = ItemListSave(true);
saveItems3();
saveItems4();
return check_form_(formname);
}
}
);

View File

@@ -0,0 +1,213 @@
function addEvent(object, eventName, do_function) {
if (typeof (object) == "string") object = document.getElementById(object);
if (!object) { alert('No object in function addEvent!'); return; }
if (object.addEventListener) {
object.addEventListener(eventName, do_function, false);
} else {
object.attachEvent('on' + eventName, do_function);
}
}
function findPos(obj) {
var nleft = 0;
var ntop = 0;
if (obj.offsetParent) {
nleft = obj.offsetLeft
ntop = obj.offsetTop
while (obj = obj.offsetParent) {
nleft += obj.offsetLeft
ntop += obj.offsetTop
}
}
return [nleft, ntop];
}
function cursorEOT(isField) {
isRange = isField.createTextRange();
isRange.move('textedit');
isRange.select();
testOverflow = isField.scrollTop;
if (testOverflow != 0) { return true }
else { return false }
}
function adjustRows(isField) {
while (cursorEOT(isField)) { isField.rows++ }
}
function insertText(isField, isText) {
isField.value = testText;
isField.focus();
}
var ERROR = false;
var ItemListSave = function (json) { }
function ItemListClear() {
while (N.rowCount() > 0) N.row(0).deleteRow();
}
var AjaxSearchProducts;
var parentFL;
var productFL;
var contactFL;
addEvent(
window,
'load',
function () {
/*
N.onCreateCell = function (cell) {
var i = cell.index;
cell.change = function (select) { };
cell.style.height = OPT['row_item_height'];
cell.noSelect = true;
if (i == 0) {
cell.setData = function (data) {
if (data.index) cell.firstChild.value = data.index;
};
cell.getData = function (data) {
data.index = cell.firstChild.value;
}
cell.select = function () { this.selectNext(); }
var edit = document.createElement('input');
edit.setAttribute('type', 'text');
edit.setAttribute('readOnly', 'readonly');
edit.setAttribute('tabIndex', 1);
edit.className = 'inputs';
cell.appendChild(edit);
}
if (i == 1) {
cell.getData = function (data) {
var cn = this.getElementsByTagName('input');
data.code = cn[0].value;
data.id = cn[1].value;
data.unit_id = cn[2].value;
data.vat_id = cn[3].value;
data.category_id = cn[4].value;
}
cell.setData = function (data) {
var cn = this.getElementsByTagName('input');
if (data.code) cn[0].value = data.code;
if (data.id) cn[1].value = data.id;
if (data.unit_id) cn[2].value = data.unit_id;
if (data.vat_id) cn[3].value = data.vat_id;
if (data.category_id) cn[4].value = data.category_id;
}
var edit = '<input type="text" readonly="readonly" tabindex="1" class="inputs" autocomplete="off" >';
cell.innerHTML = edit;
cell.align = 'right';
var id = document.createElement('input');
id.setAttribute('type', 'hidden');
cell.appendChild(id);
var unit_id = document.createElement('input');
unit_id.setAttribute('type', 'hidden');
unit_id.setAttribute('value', OPT['default_unit']);
cell.appendChild(unit_id);
var vat_id = document.createElement('input');
vat_id.setAttribute('type', 'hidden');
vat_id.setAttribute('value', OPT['default_vat']);
cell.appendChild(vat_id);
var category_id = document.createElement('input');
category_id.setAttribute('type', 'hidden');
category_id.setAttribute('value', OPT['default_category']);
cell.appendChild(category_id);
var img = document.createElement('img');
img.setAttribute('alt', MOD['LBL_IMG_SEARCH']);
img.setAttribute('src', 'modules/EcmQuotes/images/search.gif');
img.style.cursor = 'pointer';
img.onclick = function () {
window.open("index.php?module=EcmProducts&action=DetailView&record=" + cell.getElementsByTagName('input')[1].value);
};
cell.appendChild(img);
calculateTotal = function () {
var product_total = 0;
var work_total = 0;
var total = 0;
var red = false;
for (var i = 0; i < N.rowCount(); i++) {
var data = N.row(i).getData();
if (data.ems_price > 0) {
var t = data.quantity * data.ems_price;
if (data.category_id == 'd7f876b0-1a3d-43a1-7c9b-511ba40df3d1')
work_total += t;
else
product_total += t;
total += t;
}
else red = true;
}
document.getElementById('total_all').value = NumberToUserFormatNumber(total);
document.getElementById('total_products').value = NumberToUserFormatNumber(product_total);
document.getElementById('total_work').value = NumberToUserFormatNumber(work_total);
if (red) document.getElementById('subtotal').style.color = 'red';
}
calculateTotal();
}
}
*/
}
);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,131 @@
getCopyElements = function() {
PTABLE = new EcmJsTable(pcolumns, $('#copyProduct'), 'EditView');
PTABLE.customQuickSearch = function(search) {
// clear previous data
this.items = new Array();
// AJAX call
var a = jQuery
.ajax({
type : 'POST',
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
data : {
job : 'searchProduct',
searchText : search,
},
dataType : 'json',
async : false,
});
return $.parseJSON(a.responseText);
}
PTABLE.setItems(new Array());
PTABLE.getHeaders();
PTABLE.fillTable();
// create butons
var b = $('<input></input>');
b.addClass('button');
b.attr('type', 'button');
b.css('width', '100%');
b.val('Komponenty');
b
.click(function() {
var prod = PTABLE.getItems();
if (prod.length == 0 || !prod[0].product_id
|| prod[0].product_id == "") {
alert('Wybierz produkt źródłowy');
return;
}
if (CTABLE.getItemsCount() > 0)
var keepitems = confirm("Zachować aktualne komponenty?");
var i = jQuery
.ajax({
type : 'POST',
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
data : {
job : 'getItemsComponents',
prod_id : prod[0].product_id,
},
dataType : 'json',
async : false,
});
var response = $.parseJSON(i.responseText);
if (response.length==0) {alert('Brak komponentów dla '+prod[0].product_code); return;}
if (keepitems) {
var items = CTABLE.getItems();
$.each(response, function(c, i) {
items.push(i)
});
} else
var items = response;
CTABLE.setItems(items);
CTABLE.fillTable();
});
$('#copyButtons').append(b);
$('#copyButtons').append('<br>');
//czynności
var b = $('<input></input>');
b.addClass('button');
b.attr('type', 'button');
b.css('width', '100%');
b.val('Czynności');
b
.click(function() {
var prod = PTABLE.getItems();
if (prod.length == 0 || !prod[0].product_id
|| prod[0].product_id == "") {
alert('Wybierz produkt źródłowy');
return;
}
if (ATABLE.getItemsCount() > 0)
var keepitems = confirm("Zachować aktualne komponenty?");
var i = jQuery
.ajax({
type : 'POST',
url : 'index.php?module=EcmProducts&action=ProductionTablesHelper&to_pdf=1',
data : {
job : 'getItemsActions',
prod_id : prod[0].product_id,
},
dataType : 'json',
async : false,
});
var response = $.parseJSON(i.responseText);
if (response.length==0) {alert('Brak czynności dla '+prod[0].product_code); return;}
if (keepitems) {
var items = ATABLE.getItems();
$.each(response, function(c, i) {
items.push(i)
});
} else
var items = response;
ATABLE.setItems(items);
ATABLE.fillTable();
});
$('#copyButtons').append(b);
}
var pcolumns = new Array();
// end: number
// begin: code
pcolumns[0] = {
'name' : 'product_',
'label' : 'Kopiuj elementy z: ',
'searchTrigger' : true,
'width' : 100, // %
'content' : new Array(),
};
pcolumns[0]['content'][0] = {
'name' : 'id',
'attr' : {
'type' : 'hidden',
}
};
pcolumns[0]['content'][1] = {
'name' : 'code',
'css' : {
'text-align' : 'left',
}
};

View File

@@ -0,0 +1,77 @@
getProductionSummary = function() {
STABLE = new EcmJsTable(columns, $('#summaryTable'),
'DetailView');
//calculate summary
var comp = 0;
var act_n = 0;
var act_b = 0;
var total_n = 0;
var total_b = 0;
var components = CTABLE.getItems();
$.each(components, function(i, c) {
comp+=c.quantity*c.purchase_price;
});
var actions = ATABLE.getItems();
$.each(actions, function(i, a) {
act_n+=a.quantity*a.price_netto;
act_b+=a.quantity*a.price_brutto;
});
total_n = comp + act_n;
total_b = comp + act_b;
var items = new Array();
items[0] = new Array();
items[0]['name'] = 'Wartość komponentów';
items[0]['value'] = comp;
items[1] = new Array();
items[1]['name'] = 'Wartość czynności - netto';
items[1]['value'] = act_n
items[2] = new Array();
items[2]['name'] = 'Wartość czynności - brutto';
items[2]['value'] = act_b;
items[3] = new Array();
items[3]['name'] = 'Suma netto';
items[3]['value'] = total_n;
items[4] = new Array();
items[4]['name'] = 'Suma brutto';
items[4]['value'] = total_b;
STABLE.setItems(items);
STABLE.getHeaders();
STABLE.fillTable();
//hide table header
STABLE.container.find('#EcmJsItemsTable > thead').remove();
//set align right
STABLE.container.find('#itemsTableDIV').attr('align', 'right');
}
var columns = new Array();
//end: number
//begin: code
columns[0] = {
'name' : 'name',
'label' : '',
'width' : 50, // %
'content' : new Array(),
};
columns[0]['content'][0] = {
'name' : '',
'css' : {
'text-align' : 'left',
'background-color' : 'rgb(224,240,255)',
}
};
columns[1] = {
'name' : 'value',
'label' : '',
'width' : 50, // %
'content' : new Array(),
};
columns[1]['content'][0] = {
'name' : '',
'dataType' : 'number',
'precision' : 4,
'css' : {
'text-align' : 'right',
}
};

View File

@@ -0,0 +1,536 @@
$(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(),
};

View File

@@ -0,0 +1,164 @@
function doRequest(where,post,doFunction,error) {
this.Display = function(result) { doFunction(result.responseText); }
this.Fail = function(result){ if(error) alert(error);}
YAHOO.util.Connect.asyncRequest('POST',where,{success:this.Display,failure:this.Fail},post);
}
function changeValidateRequired(formname,name,required) {
for(var i=0; i<validate[formname].length; i++)
if(validate[formname][i][0] == name) { validate[formname][i][2] = required; break; }
}
function my_popup(module, field_array, call_back_function, form_name) {
if(!call_back_function) call_back_function = "set_return";
if(!form_name) form_name = "EditView";
return open_popup(module, 900, 700, "", true, false, {"call_back_function":call_back_function,"form_name":form_name,"field_to_name_array":field_array});
}
function addEvent(object,eventName,do_function) {
if(typeof(object) == "string") object = document.getElementById(object);
if(!object) { alert('No object in function addEvent!'); return; }
if(object.addEventListener) {
object.addEventListener(eventName, do_function, false);
} else {
object.attachEvent('on'+eventName, do_function);
}
}
function FormLoader() {
this.module;
this.createModule;
this.fieldName;
this.buttonName = 'FormLoaderButton';
this.load = function(module,createModule,fieldName) {
this.module = module;
this.createModule = createModule;
this.fieldName = fieldName;
}
this.createButton = function() {
var b = document.createElement('input');
b.type = 'button';
b.className = 'button';
b.name = this.buttonName;
b.value = 'Create';
b.FL = this;
b.onclick = function() {
if(this.FL.createModule == '') return;
if(this.FL.onButtonClick) var data = this.FL.onButtonClick();
window.open("index.php?module="+this.FL.module+"&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName="+this.FL.fieldName+"&createModule="+this.FL.createModule+(data?data:''),"Create10"+this.FL.module,"resizable=yes,scrollbars=no,status=no,height=540,width=700").focus();
}
return b;
}
this.setEditDblClick = function(edit) { edit.FL=this; edit.ondblclick=this.editDblClick; }
this.editDblClick = function() {
if(this.FL.createModule == '') return;
if(this.FL.onEditDblClick) var data = this.FL.onEditDblClick();
window.open("index.php?module="+this.FL.module+"&action=formloader&to_pdf=1&loaderAction=ViewForm&loaderFieldName="+this.FL.fieldName+"&createModule="+this.FL.createModule+(data?data:''),"Create10"+this.FL.module,"resizable=yes,scrollbars=no,status=no,height=540,width=700").focus();
}
this.responseData = function(data) {
if(this.onResponseData) this.onResponseData(data);
}
this.onResponseData;
this.addPostData = function() {
if(this.onAddPostData)
return this.onAddPostData();
else
return '';
}
this.onAddPostData;
this.onButtonClick;
}

View File

@@ -0,0 +1,200 @@
function openProductCard(productId) {
window.open(`index.php?module=EcmProducts&action=DetailView&record=${productId}`).focus();
}
function searchByIndex(index) {
$("#index").val(index);
$("#productId").val(CODES.find(x => x.code === $("#index").val())?.id);
$("#searchByIndexForm").submit();
}
function addProductToAddress() {
if (!isProductValid("#addProductInput")) {
return;
}
if (!isAddressValid("#address")) {
return;
}
const productId = CODES.find(x => x.code === $("#addProductInput").val())?.id;
$("#loader").show();
$.ajax({
url: "index.php?module=EcmProducts&action=&action=stockAddress&ajax=addAddress&to_pdf=1&productId=" + productId + "&address=" + $("#address").val(),
}).done(function (data) {
$("#loader").hide();
var res = JSON.parse(data);
if (res.status === 'Error') {
alert('Błąd: ' + res.msg);
} else {
$("#searchByAddressForm").submit();
}
}).fail(() => {
$("#loader").hide();
alert('Błąd serwera.');
});
}
function removeProductFromAddress() {
if (!isAddressValid("#address")) {
return;
}
$("#loader").show();
$.ajax({
url: "index.php?module=EcmProducts&action=&action=stockAddress&ajax=removeAddress&to_pdf=1&address=" + $("#address").val(),
}).done(function (data) {
$("#loader").hide();
var res = JSON.parse(data);
if (res.status === 'Error') {
alert('Błąd: ' + res.msg);
} else {
$("#searchByAddressForm").submit();
}
}).fail(() => {
$("#loader").hide();
alert('Błąd serwera.')
});
}
function removeAddressFromProduct(address) {
$("#loader").show();
$.ajax({
url: "index.php?module=EcmProducts&action=&action=stockAddress&ajax=removeAddress&to_pdf=1&address=" + address,
}).done(function (data) {
$("#loader").hide();
var res = JSON.parse(data);
if (res.status === 'Error') {
alert('Błąd: ' + res.msg);
} else {
$("#searchByIndexTrigger").click();
}
}).fail(() => {
$("#loader").hide();
alert('Błąd serwera.');
});
}
function addAddressToProduct() {
if (!isProductValid("#index")) {
return;
}
const productId = CODES.find(x => x.code === $("#index").val())?.id;
if (!isAddressValid("#newAddress")) {
return;
}
const isNotFull = $("#isNotFull").is(':checked') ? 1 : 0;
$("#loader").show();
$.ajax({
url: "index.php?module=EcmProducts&action=&action=stockAddress&ajax=addAddress&to_pdf=1&productId=" + productId + "&address=" + $("#newAddress").val() + "&isNotFull=" + isNotFull,
}).done(function (data) {
$("#loader").hide();
var res = JSON.parse(data);
if (res.status === 'Error') {
alert('Błąd: ' + res.msg);
} else {
$("#searchByIndexTrigger").click();
}
}).fail(() => {
$("#loader").hide();
alert('Błąd serwera.')
});
}
function setAddressIsNotFull(address, checkbox) {
$.ajax({
url: "index.php?module=EcmProducts&action=&action=stockAddress&ajax=setIsNotFull&to_pdf=1&address=" + address + "&isNotFull=" + $(checkbox).is(':checked'),
}).done(function (data) {
$("#loader").hide();
var res = JSON.parse(data);
console.log(res);
if (res.status === 'Error') {
alert('Błąd: ' + res.msg);
}
}).fail(() => {
$("#loader").hide();
alert('Błąd serwera.')
});
}
function isAddressValid(id) {
if (!id) { id = "#address"; }
if ($(id).val().length < 9) {
$(id + "Error").html("Błędny format [ __.__._._ ]");
return false;
}
const segments = $(id).val().split(".");
if (parseInt(segments[0]) > 17) {
$(id + "Error").html("Błąd pierwszego segmentu [zakres 01-20]");
return false;
}
if (parseInt(segments[1]) > 15) {
$(id + "Error").html("Błąd drugiego segmentu [zakres 01-15]");
return false;
}
return true;
}
function isProductValid(id) {
if (!id) { id = "#index"; }
const index = $(id).val();
if (CODES.find(x => x.code === index)) {
return true;
} else {
$(id + "Error").html("Niepoprawny indeks produktu [Produkt musi być aktywny]");
return false;
}
}
$(document).ready(function () {
$("#address").mask("AB.CD.E.F", {
placeholder: "__.__._._",
translation: {
A: { pattern: /[0-2]/ },
B: { pattern: /[0-9]/ },
C: { pattern: /[0-1]/ },
D: { pattern: /[0-9]/ },
E: { pattern: /[1-5]/ },
F: { pattern: /[0-5]/ },
}
});
if ($("#newAddress")) {
$("#newAddress").mask("AB.CD.E.F", {
placeholder: "__.__._._",
translation: {
A: { pattern: /[0-2]/ },
B: { pattern: /[0-9]/ },
C: { pattern: /[0-1]/ },
D: { pattern: /[0-9]/ },
E: { pattern: /[1-5]/ },
F: { pattern: /[0-5]/ },
}
});
$("#newAddress").focus(() => $("#newAddressError").html(""));
$("#newAddress").blur(() => isAddressValid("#newAddress"));
}
$("#address").focus(() => $("#addressError").html(""));
$("#index").focus(() => $("#indexError").html(""));
$("#index").autocomplete({
source: CODES.map(x => x.code),
minLength: 4,
max: 20,
scroll: true
});
if ($("#addProductInput")) {
$("#addProductInput").autocomplete({
source: CODES.map(x => x.code),
minLength: 4,
max: 20,
scroll: true
});
$("#addProductInput").focus(() => $("#addProductInputError").html(""));
}
$("#searchByAddressTrigger").click(() => {
if (isAddressValid()) {
$("#searchByAddressForm").submit();
}
});
$("#searchByIndexTrigger").click(() => {
if (isProductValid()) {
$("#productId").val(CODES.find(x => x.code === $("#index").val())?.id);
$("#searchByIndexForm").submit();
}
});
$('[name^="showAddress').click((event) => {
$("#address").val(event.target.name.split('-')[1]);
if (isAddressValid()) {
$("#searchByAddressForm").submit();
}
});
//bind buttons
});