Add JS files
This commit is contained in:
332
modules/EcmNewKpkws/javascript/bimit_table2.js
Executable file
332
modules/EcmNewKpkws/javascript/bimit_table2.js
Executable file
@@ -0,0 +1,332 @@
|
||||
var ajax_url = "index.php?module=EcmNewKpkws&action=javahelper&to_pdf=1";
|
||||
var tableid='#transactionstable';
|
||||
|
||||
function FormatNumber(number, precision) {
|
||||
if (number < 0)
|
||||
number = 0;
|
||||
|
||||
var precision = precision || 2;
|
||||
// make string..
|
||||
number = number + '';
|
||||
number = number.replace(',', '.');
|
||||
// round
|
||||
number = toFixed(number, precision);
|
||||
// add 1000 sep
|
||||
var tmp = number.split(".");
|
||||
var c = '';
|
||||
for (var i = tmp[0].length; i != -1; i--) {
|
||||
c += tmp[0].charAt(i);
|
||||
if ((tmp[0].length - i) == 0 || i == 0)
|
||||
continue;
|
||||
if ((tmp[0].length - i) % 3 == 0)
|
||||
c += '.';
|
||||
}
|
||||
// reverse c
|
||||
c = c.split("").reverse().join("");
|
||||
|
||||
return c + ',' + tmp[1];
|
||||
}
|
||||
|
||||
function UnformatNumber(number) {
|
||||
// make string..
|
||||
number = number + '';
|
||||
// remove 1000 sep
|
||||
number = number.replace('.', '');
|
||||
// change ',' to '.'
|
||||
number = number.replace(',', '.');
|
||||
|
||||
return parseFloat(number);
|
||||
}
|
||||
|
||||
// round with precision
|
||||
function toFixed(value, precision) {
|
||||
var precision = precision || 0, neg = value < 0, power = Math.pow(10,
|
||||
precision), value = Math.round(value * power), integral = String((neg ? Math.ceil
|
||||
: Math.floor)(value / power)), fraction = String((neg ? -value
|
||||
: value)
|
||||
% power), padding = new Array(Math.max(precision - fraction.length,
|
||||
0) + 1).join('0');
|
||||
|
||||
return precision ? integral + '.' + padding + fraction : integral;
|
||||
}
|
||||
|
||||
function getCashCurrency(cash_id) {
|
||||
var params = {
|
||||
cash_id : cash_id,
|
||||
job : 'getCashCurrency'
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
dataType : "json",
|
||||
success: function(data) {
|
||||
if (data == '-1') {
|
||||
|
||||
} else {
|
||||
$("#currency_id").val((data.currency_id));
|
||||
$("#currency").val(data.currency_id);
|
||||
getNBPCurrencyExchange($("#currency_id").val());
|
||||
}
|
||||
},
|
||||
data: params
|
||||
});
|
||||
}
|
||||
|
||||
function getParentInfo(parent_id, parent_type) {
|
||||
var params = {
|
||||
id : parent_id,
|
||||
type : parent_type,
|
||||
job : 'getParentInfo'
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
dataType : "json",
|
||||
success: function(data) {
|
||||
if (data == '-1') {
|
||||
alert('Błąd');
|
||||
$("#parent_name").val('');
|
||||
$("#parent_id").val('');
|
||||
} else {
|
||||
setParentInfo(data);
|
||||
}
|
||||
},
|
||||
data: params
|
||||
});
|
||||
}
|
||||
|
||||
function setParentInfo(data) {
|
||||
//pricebooks
|
||||
|
||||
if ($("#new_number").val() == false) return; //if edit exists load only pricebooks
|
||||
if (data.name)
|
||||
$("#parent_name_copy").val(data.name);
|
||||
if (data.parent_nip)
|
||||
$("#parent_nip").val(data.parent_nip);
|
||||
if (data.parent_address_street)
|
||||
$("#parent_address_street").val(data.parent_address_street);
|
||||
if (data.parent_address_city)
|
||||
$("#parent_address_city").val(data.parent_address_city);
|
||||
if (data.parent_address_postalcode)
|
||||
$("#parent_address_postalcode").val(data.parent_address_postalcode);
|
||||
if (data.parent_address_country)
|
||||
$("#parent_address_country").val(data.parent_address_country);
|
||||
|
||||
if (data.ecmpaymentcondition_id && data.ecmpaymentcondition_name) {
|
||||
$("#ecmpaymentcondition_id").val(data.ecmpaymentcondition_id);
|
||||
$("#ecmpaymentcondition_name").val(data.ecmpaymentcondition_name);
|
||||
}
|
||||
if (data.ecmdeliverycondition_id && data.ecmdeliverycondition_name) {
|
||||
$("#ecmdeliverycondition_id").val(data.ecmdeliverycondition_id);
|
||||
$("#ecmdeliverycondition_name").val(data.ecmdeliverycondition_name);
|
||||
}
|
||||
|
||||
if (data.currency_id)
|
||||
$("#currency_id option[value=\""+data.currency_id+"\"]").attr('selected', 'selected');
|
||||
|
||||
$(".loading_panel").css("display", "none");
|
||||
}
|
||||
|
||||
function generateDocNumber() {
|
||||
var params = {
|
||||
job : 'generateDocNumber',
|
||||
cash_id: $("#cash_id").val(),
|
||||
type: $("#type_id").val(),
|
||||
date : $("#register_date").val(),
|
||||
};
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : ajax_url,
|
||||
dataType : "json",
|
||||
success : function(data) {
|
||||
if (data == '-1') {
|
||||
// try loading again
|
||||
generateDocNumber();
|
||||
} else {
|
||||
|
||||
$("#document_no").val(data.document_no);
|
||||
$("#number").val(data.number);
|
||||
$(".loading_panel").css("display", "none");
|
||||
}
|
||||
},
|
||||
data : params
|
||||
});
|
||||
}
|
||||
|
||||
function getNBPCurrencyExchange(c_id) {
|
||||
|
||||
var date = $("#register_date").val();
|
||||
var d = date.split(".");
|
||||
d[0] -= 1;
|
||||
date = d.join(".");
|
||||
var params = {
|
||||
job : 'getNBPCurrencyExchange',
|
||||
c_id : c_id,
|
||||
date : date,
|
||||
};
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : ajax_url,
|
||||
dataType : "json",
|
||||
async : false,
|
||||
success : function(data) {
|
||||
if (data != false) {
|
||||
$("#currency_value_nbp").val(data);
|
||||
$("#currency_value").val(data);
|
||||
} else {
|
||||
$("#currency_value_nbp").val(0);
|
||||
$("#currency_value").val(0);
|
||||
}
|
||||
},
|
||||
data : params
|
||||
});
|
||||
}
|
||||
|
||||
$.event.special.inputchange = {
|
||||
setup: function() {
|
||||
var self = this, val;
|
||||
$.data(this, 'timer', window.setInterval(function() {
|
||||
val = self.value;
|
||||
if ( $.data( self, 'cache') != val ) {
|
||||
$.data( self, 'cache', val );
|
||||
$( self ).trigger( 'inputchange' );
|
||||
}
|
||||
}, 20));
|
||||
},
|
||||
teardown: function() {
|
||||
window.clearInterval( $.data(this, 'timer') );
|
||||
},
|
||||
add: function() {
|
||||
$.data(this, 'cache', this.value);
|
||||
}
|
||||
};
|
||||
|
||||
function InitializeTable(){
|
||||
// Initialize appendGrid
|
||||
$(tableid).appendGrid({
|
||||
hideRowNumColumn: true,
|
||||
initRows: 0,
|
||||
// definicje kolumn
|
||||
columns: [
|
||||
{name: 'name', display: 'Transakcja', ctrlClass: 'inputs', ctrlAttr: {maxlength: 100, readonly: 'readonly'},ctrlCss: {width: '99%'}},
|
||||
{name: 'type', display: 'Typ', type: 'text', ctrlAttr: {maxlength: 100, readonly: 'readonly'}, ctrlCss: {width: '99%','text-align': 'right'}, ctrlClass: 'inputs'},
|
||||
{name: 'value', display: 'Kwota',type: 'text', ctrlAttr: {maxlength: 100, readonly: 'readonly'}, ctrlCss: {width: '99%','text-align': 'right'}, ctrlClass: 'inputs'},
|
||||
{name: 'id', display: 'ID', invisible: true},
|
||||
{name: 'type_id', display: 'ID', invisible: true}
|
||||
|
||||
],
|
||||
// custome guziczki
|
||||
customGridButtons: {
|
||||
insert: $('<img>').css('color', 'red').text('Insert').get(0),
|
||||
// Use a function that create DOM element
|
||||
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;
|
||||
},
|
||||
remove: function (){
|
||||
var button = document.createElement('img');
|
||||
button.src = 'modules/EcmQuotes/images/deleterow.gif';
|
||||
return button;
|
||||
}
|
||||
|
||||
},
|
||||
// labele
|
||||
i18n: {
|
||||
rowEmpty: 'Tabelka jest pusta'
|
||||
},
|
||||
// ukrywanie nie potrzebnych guziczkow
|
||||
hideButtons: {
|
||||
removeLast: true,
|
||||
insert: true,
|
||||
append: true
|
||||
},
|
||||
// akcja po usunieciu rekordu
|
||||
afterRowRemoved: function (caller, rowIndex) {
|
||||
CalculateTable();
|
||||
}
|
||||
});
|
||||
|
||||
// hide css classes
|
||||
$('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 CalculateTable(){
|
||||
var count = $(tableid).appendGrid('getRowCount');
|
||||
var total=0;
|
||||
for (var i = 0; i < count; i++) {
|
||||
|
||||
var date = $(tableid).appendGrid('getRowValue', i);
|
||||
|
||||
total = total + UnformatNumber(date.value);
|
||||
|
||||
}
|
||||
$("#amount").val(FormatNumber(total));
|
||||
var result='<table cellspacing="0" cellpadding="0" style="width:50%; height:100%; border: 1px solid rgb(48,192,255);float: right;" id="result_table">'
|
||||
+'<tbody><tr id="subtotal_tr">'
|
||||
+'<td style="border-top:0px;" class="positionsLabel">Suma</td>'
|
||||
+'<td style="border-top:0px;" class="positionsField"><input type="text" value="'+FormatNumber(total)+'" id="total_transactions" name="total_transactions" readonly="readonly" style="border:0px;font-weight:900;width:100%;text-align:right;"></td>'
|
||||
+'</tr></tbody></table>';
|
||||
$( "#ResultDiv" ).html(result);
|
||||
}
|
||||
|
||||
function PreventDuplicates(id){
|
||||
var count = $(tableid).appendGrid('getRowCount');
|
||||
var result=false;
|
||||
for (var i = 0; i < count; i++) {
|
||||
var date = $(tableid).appendGrid('getRowValue', i);
|
||||
if(date.id==id)result=true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function LoadTransaction(call_back){
|
||||
if(call_back.name_to_value_array){
|
||||
var positions=(call_back.name_to_value_array);
|
||||
}else {
|
||||
var positions=(call_back.selection_list);
|
||||
}
|
||||
$.each(positions, function (idx2, obj2) {
|
||||
var params = {
|
||||
job : 'getTransactions',
|
||||
id : obj2,
|
||||
};
|
||||
$.ajax({
|
||||
type : "POST",
|
||||
url : ajax_url,
|
||||
dataType : "json",
|
||||
async : false,
|
||||
success : function(data) {
|
||||
if(PreventDuplicates(data.id)!=true){
|
||||
$(tableid).appendGrid('appendRow', [{ name: data.name, type: data.type, value: FormatNumber(data.value),id: data.id,type_id: data.type_id }]);
|
||||
} else {
|
||||
alert("Transakcja o nazwie "+data.name+" została już dodana!");
|
||||
}
|
||||
},
|
||||
data : params
|
||||
});
|
||||
});
|
||||
CalculateTable();
|
||||
}
|
||||
|
||||
function PrepareTabletoSave(){
|
||||
var count = $(tableid).appendGrid('getRowCount');
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
|
||||
var data2 = $(tableid).appendGrid('getRowValue', i);
|
||||
|
||||
$(tableid).appendGrid('setCtrlValue', 'value', i, UnformatNumber(data2.value));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user