init
This commit is contained in:
196
modules/EcmInvoiceOuts/javascript/EcmInvoiceOuts3.js
Normal file
196
modules/EcmInvoiceOuts/javascript/EcmInvoiceOuts3.js
Normal file
@@ -0,0 +1,196 @@
|
||||
//START:
|
||||
$(document).ready(
|
||||
|
||||
function() {
|
||||
// confirm exit
|
||||
window.onbeforeunload = confirmExit;
|
||||
// prevent submit by enter press
|
||||
lockEnter();
|
||||
// parent info
|
||||
$('#parent_id').on('inputchange', function() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function() {
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
// categories
|
||||
getCategoriesList();
|
||||
// its vat free change
|
||||
$("#no_tax").change(function() {
|
||||
// calculate totals
|
||||
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 -
|
||||
// thead row
|
||||
for (var index = 0; index != count; index++)
|
||||
calculateRow(index);
|
||||
});
|
||||
$("#type").change(function() {
|
||||
if ($("#type :selected").val() == 'normal') {
|
||||
if($('#new_number').val()==1){
|
||||
|
||||
generateNumber();
|
||||
}
|
||||
|
||||
} else {
|
||||
generateNumberCorrect();
|
||||
}
|
||||
});
|
||||
$("#currency_id").change(function() {
|
||||
getNBPCurrencyExchange($("#currency_id :selected").val());
|
||||
|
||||
});
|
||||
var previousVal;
|
||||
var pollInterval = setInterval(function() {
|
||||
var val = $('#sell_date').val();
|
||||
if (val !== previousVal) {
|
||||
getNBPCurrencyExchange($("#currency_id :selected").val());
|
||||
}
|
||||
previousVal = val;
|
||||
}, 500);
|
||||
$("#ecmlanguage").change(
|
||||
function() {
|
||||
if ($("#pdf_type :selected").val() == 'U'
|
||||
|| $("#pdf_type :selected").val() == 'E') {
|
||||
changeVat();
|
||||
calculateTotal();
|
||||
}
|
||||
});
|
||||
$("#pdf_type").change(
|
||||
function() {
|
||||
if ($("#pdf_type :selected").val() == 'U'
|
||||
|| $("#pdf_type :selected").val() == 'E') {
|
||||
changeVat();
|
||||
calculateTotal();
|
||||
}
|
||||
});
|
||||
$("#ecmpaymentcondition_id").on('inputchange', function() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function() {
|
||||
|
||||
calculatePaymentDate($("#ecmpaymentcondition_id").val());
|
||||
$(".loading_panel").css("display", "none");
|
||||
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
$('#paid_val').change(function() {
|
||||
calculateTotal();
|
||||
});
|
||||
$('#prepaid').change(function() {
|
||||
calculateTotal();
|
||||
});
|
||||
// searchProductInput change
|
||||
$('#searchProductsInput').keyup(function() {
|
||||
searchProducts();
|
||||
});
|
||||
DrawHeaders();
|
||||
|
||||
if (($("#new_number").val() == true)
|
||||
&& ($("#is_correct").val() != true)
|
||||
&& ($("#is_wz").val() != true)
|
||||
&& ($("#is_sale").val() != true)
|
||||
&& ($("#multiDiscountCorrectInvoice").val() != true)
|
||||
&& ($("#is_return").val() != true)) {
|
||||
generateNumber($("#stock :selected").val());
|
||||
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#is_correct").val() == true)) {
|
||||
$('#searchProducts').hide();
|
||||
generateNumberCorrect();
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
getItems();
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#is_wz").val() == true)) {
|
||||
|
||||
generateNumber($("#stock :selected").val());
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
if($("#wz_zb_id").val()!=""){
|
||||
|
||||
getItemsZBFromWZ();
|
||||
} else {
|
||||
|
||||
getItemsFromWZ();
|
||||
}
|
||||
|
||||
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#is_sale").val() == true)) {
|
||||
generateNumber($("#stock :selected").val());
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
getItemsFromSale();
|
||||
if ($("#ecmpaymentcondition_id").val() != '')
|
||||
calculatePaymentDate($("#ecmpaymentcondition_id").val());
|
||||
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#is_return").val() == true)) {
|
||||
|
||||
generateNumberCorrect();
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
getItemsFromReturn();
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#multiDiscountCorrectInvoice").val() == true)) {
|
||||
generateNumberCorrect();
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
getItemsFromMDCI();
|
||||
} else {
|
||||
$('#document_no').prop("readonly",false);
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
getItems();
|
||||
}
|
||||
$(".loading_panel").css("display", "none");
|
||||
// handle setItems
|
||||
setITEMS = function() {
|
||||
var formname = 'EditView';
|
||||
if (check_form_(formname) == true) {
|
||||
SetTab('ITEMS');
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// handle save
|
||||
var check_form_ = check_form;
|
||||
check_form = function(formname) {
|
||||
window.onbeforeunload = null;
|
||||
if (items.length == 0) {
|
||||
alert("Brak produktów");
|
||||
return false;
|
||||
}
|
||||
$(".loading_panel").css("display", "block");
|
||||
// calculate totals
|
||||
var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||||
for (var index = 0; index != count; index++) {
|
||||
calculateRow(index);
|
||||
//total_vat must be != 0 if its country correct
|
||||
if ($('#pdf_type').val()=='K' && items[index].ecmvat_name=='0%' && items[index].product_corrected != 'true') {
|
||||
alert("Niedopuszczalna, zerowa stawka VAT na fakturze krajowej.");
|
||||
$(".loading_panel").css("display", "none");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$("#total_netto").val($("#t_netto").val());
|
||||
$("#total_brutto").val($("#t_brutto").val());
|
||||
$("#discount").val($("#disc").val());
|
||||
$("#position_list").val(JSON.stringifyNoSecurity(items));
|
||||
if (check_form_(formname) == false) {
|
||||
console.log('check_form error');
|
||||
window.onbeforeunload = confirmExit;
|
||||
$(".loading_panel").css("display", "none");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
function confirmExit() {
|
||||
return "";
|
||||
}
|
||||
|
||||
function lockEnter() {
|
||||
// prevent default
|
||||
$(window).keydown(function(event) {
|
||||
if (event.keyCode == 13 && $(":focus").prop('tagName') != 'TEXTAREA') {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//START:
|
||||
$(document).ready(
|
||||
function() {
|
||||
DrawHeaders();
|
||||
getItems(false);
|
||||
});
|
||||
|
||||
127
modules/EcmInvoiceOuts/javascript/ListSales.js
Normal file
127
modules/EcmInvoiceOuts/javascript/ListSales.js
Normal file
@@ -0,0 +1,127 @@
|
||||
$(document).ready(function()
|
||||
{
|
||||
// by document no
|
||||
$.tablesorter.addParser({
|
||||
// set a unique id
|
||||
id: 'rangesort',
|
||||
is: function (s) {
|
||||
// return false so this parser is not auto detected
|
||||
return false;
|
||||
},
|
||||
format: function (s, table, cell, cellIndex) {
|
||||
// get data attributes from $(cell).attr('data-something');
|
||||
// check specific column using cellIndex
|
||||
|
||||
return $(cell).attr('data-price');
|
||||
},
|
||||
// set type, either numeric or text
|
||||
type: 'numeric'
|
||||
});
|
||||
// by total netto
|
||||
$.tablesorter.addParser({
|
||||
// set a unique id
|
||||
id: 'rangesorttota',
|
||||
is: function (s) {
|
||||
// return false so this parser is not auto detected
|
||||
return false;
|
||||
},
|
||||
format: function (s, table, cell, cellIndex) {
|
||||
// get data attributes from $(cell).attr('data-something');
|
||||
// check specific column using cellIndex
|
||||
|
||||
return $(cell).attr('data-total');
|
||||
},
|
||||
// set type, either numeric or text
|
||||
type: 'numeric'
|
||||
});
|
||||
// by vat
|
||||
|
||||
$.tablesorter.addParser({
|
||||
// set a unique id
|
||||
id: 'rangesorttotav',
|
||||
is: function (s) {
|
||||
// return false so this parser is not auto detected
|
||||
return false;
|
||||
},
|
||||
format: function (s, table, cell, cellIndex) {
|
||||
// get data attributes from $(cell).attr('data-something');
|
||||
// check specific column using cellIndex
|
||||
|
||||
return $(cell).attr('data-total');
|
||||
},
|
||||
// set type, either numeric or text
|
||||
type: 'numeric'
|
||||
});
|
||||
// by total brutto
|
||||
$.tablesorter.addParser({
|
||||
// set a unique id
|
||||
id: 'rangesorttotan',
|
||||
is: function (s) {
|
||||
// return false so this parser is not auto detected
|
||||
return false;
|
||||
},
|
||||
format: function (s, table, cell, cellIndex) {
|
||||
// get data attributes from $(cell).attr('data-something');
|
||||
// check specific column using cellIndex
|
||||
|
||||
return $(cell).attr('data-total');
|
||||
},
|
||||
// set type, either numeric or text
|
||||
type: 'numeric'
|
||||
});
|
||||
// by total invoice
|
||||
$.tablesorter.addParser({
|
||||
// set a unique id
|
||||
id: 'rangesorttotai',
|
||||
is: function (s) {
|
||||
// return false so this parser is not auto detected
|
||||
return false;
|
||||
},
|
||||
format: function (s, table, cell, cellIndex) {
|
||||
// get data attributes from $(cell).attr('data-something');
|
||||
// check specific column using cellIndex
|
||||
|
||||
return $(cell).attr('data-total');
|
||||
},
|
||||
// set type, either numeric or text
|
||||
type: 'numeric'
|
||||
});
|
||||
$('#selectall').click(function(event) { //on click
|
||||
if(this.checked) { // check select status
|
||||
$('.make_pdf').each(function() { //loop through each checkbox
|
||||
this.checked = true; //select all checkboxes with class "checkbox1"
|
||||
});
|
||||
}else{
|
||||
$('.make_pdf').each(function() { //loop through each checkbox
|
||||
this.checked = false; //deselect all checkboxes with class "checkbox1"
|
||||
});
|
||||
}
|
||||
});
|
||||
// hightlight table row
|
||||
$('#myTable tr').mouseover(function(e) {
|
||||
$('#myTable tr').removeClass('highlighted');
|
||||
$(this).addClass('highlighted');
|
||||
});
|
||||
$('.tablesorter').tablesorter({
|
||||
headers: {
|
||||
0: {
|
||||
// disable it by setting the property sorter to false
|
||||
sorter: false
|
||||
},
|
||||
1: {
|
||||
sorter: 'rangesort'
|
||||
},
|
||||
|
||||
4: {
|
||||
sorter: 'rangesorttotav'
|
||||
},
|
||||
5: {
|
||||
sorter: 'rangesorttotan'
|
||||
},
|
||||
6: {
|
||||
sorter: 'rangesorttotai'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
1447
modules/EcmInvoiceOuts/javascript/bimit_table.js
Normal file
1447
modules/EcmInvoiceOuts/javascript/bimit_table.js
Normal file
File diff suppressed because it is too large
Load Diff
115
modules/EcmInvoiceOuts/javascript/columndefs-detail.js
Normal file
115
modules/EcmInvoiceOuts/javascript/columndefs-detail.js
Normal file
@@ -0,0 +1,115 @@
|
||||
columns = new Array();
|
||||
//define columns
|
||||
//begin: number
|
||||
columns[0] = {
|
||||
'name' : 'number',
|
||||
'label' : 'Lp.',
|
||||
'width' : 4,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[0]['content'][0] = {'name' : '', 'type': 'text', 'readonly' : true};
|
||||
//end: number
|
||||
//begin: code
|
||||
columns[1] = {
|
||||
'name' : 'product_',
|
||||
'label' : 'Kod',
|
||||
'width' : 6,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[1]['content'][0] = {'name' : 'code', 'type': 'hidden', 'readonly' : true};
|
||||
columns[1]['content'][1] = {'name' : 'id', 'type': 'hidden'};
|
||||
columns[1]['content'][2] = {'name' : 'link', 'type': 'text', 'readonly' : true};
|
||||
//end: code
|
||||
//begin: name
|
||||
columns[2] = {
|
||||
'name' : 'name',
|
||||
'label' : 'Nazwa',
|
||||
'width' : 20,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[2]['content'][0] = {'name' : '', 'type': 'text'};
|
||||
//end: name
|
||||
//begin: quantity
|
||||
columns[3] = {
|
||||
'name' : 'quantity',
|
||||
'label' : 'Ilość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[3]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'};
|
||||
//end: quantity
|
||||
//begin: unit
|
||||
columns[4] = {
|
||||
'name' : 'unit_',
|
||||
'label' : 'J.M.',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'center',
|
||||
};
|
||||
columns[4]['content'][0] = {'name' : 'name', 'type': 'text','readonly' : true};
|
||||
columns[4]['content'][1] = {'name' : 'id', 'type': 'hidden'};
|
||||
//end: unit
|
||||
//begin: price_start
|
||||
columns[5] = {
|
||||
'name' : 'price_start',
|
||||
'label' : 'Cena<br>początkowa',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[5]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'};
|
||||
columns[5]['content'][1] = {'name' : '_div', 'type': 'text'};
|
||||
//end: price_start
|
||||
//begin: discount
|
||||
columns[6] = {
|
||||
'name' : 'discount',
|
||||
'label' : 'Upust (%)',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[6]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'};
|
||||
//end: discount
|
||||
//begin: price_netto
|
||||
columns[7] = {
|
||||
'name' : 'price_netto',
|
||||
'label' : 'Cena<br>po upuście',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[7]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'readonly' : true};
|
||||
//end: price_start
|
||||
//begin: ecmvat
|
||||
columns[8] = {
|
||||
'name' : 'ecmvat_',
|
||||
'label' : 'VAT (%)',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[8]['content'][0] = {'name' : 'name', 'type': 'text'};
|
||||
columns[8]['content'][1] = {'name' : 'value', 'type': 'hidden'};
|
||||
columns[8]['content'][2] = {'name' : 'id', 'type': 'hidden'};
|
||||
//end: ecmvat
|
||||
//begin: total
|
||||
columns[9] = {
|
||||
'name' : 'total_',
|
||||
'label' : 'Wartość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[9]['content'][0] = {'name' : 'netto', 'type': 'text', 'isNumber' : true, 'readonly' : true};
|
||||
//end: total
|
||||
//begin: recipient_code
|
||||
columns[10] = {
|
||||
'name' : 'recipient_code',
|
||||
'label' : 'Kod Odbiorcy',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[10]['content'][0] = {'name' : '', 'type': 'text'};
|
||||
//end: recipient_code
|
||||
239
modules/EcmInvoiceOuts/javascript/columndefs.js
Normal file
239
modules/EcmInvoiceOuts/javascript/columndefs.js
Normal file
@@ -0,0 +1,239 @@
|
||||
columns = new Array();
|
||||
// define columns
|
||||
// begin: number
|
||||
columns[0] = {
|
||||
'name' : 'number',
|
||||
'label' : 'Lp.',
|
||||
'width' : 4,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[0]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text',
|
||||
'readonly' : true
|
||||
};
|
||||
// end: number
|
||||
// begin: code
|
||||
columns[1] = {
|
||||
'name' : 'product_',
|
||||
'label' : 'Kod',
|
||||
'width' : 6,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[1]['content'][0] = {
|
||||
'name' : 'code',
|
||||
'type' : 'hidden',
|
||||
'readonly' : true
|
||||
};
|
||||
columns[1]['content'][1] = {
|
||||
'name' : 'id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][2] = {
|
||||
'name' : 'item_id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][3] = {
|
||||
'name' : 'itemold_id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][4] = {
|
||||
'name' : 'link',
|
||||
'type' : 'text',
|
||||
'readonly' : true
|
||||
};
|
||||
columns[1]['content'][5] = {
|
||||
'name' : 'parent_doc_id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][6] = {
|
||||
'name' : 'parent_doc_type',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][7] = {
|
||||
'name' : 'parent_doc_item_id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][8] = {
|
||||
'name' : 'corrected',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][9] = {
|
||||
'name' : 'ean',
|
||||
'type' : 'hidden',
|
||||
};
|
||||
// end: codes
|
||||
// begin: name
|
||||
columns[2] = {
|
||||
'name' : 'name',
|
||||
'label' : 'Nazwa',
|
||||
'width' : 20,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[2]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text'
|
||||
};
|
||||
// end: name
|
||||
// begin: quantity
|
||||
columns[3] = {
|
||||
'name' : 'quantity',
|
||||
'label' : 'Ilość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[3]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text',
|
||||
'isNumber' : true,
|
||||
'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'
|
||||
};
|
||||
// end: quantity
|
||||
// begin: unit
|
||||
columns[4] = {
|
||||
'name' : 'unit_',
|
||||
'label' : 'J.M.',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'center',
|
||||
};
|
||||
columns[4]['content'][0] = {
|
||||
'name' : 'name',
|
||||
'type' : 'text',
|
||||
'readonly' : true
|
||||
};
|
||||
columns[4]['content'][1] = {
|
||||
'name' : 'id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
// end: unit
|
||||
// begin: price_start
|
||||
columns[5] = {
|
||||
'name' : 'price_start',
|
||||
'label' : 'Cena<br>początkowa',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[5]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text',
|
||||
'isNumber' : true,
|
||||
'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'
|
||||
};
|
||||
columns[5]['content'][1] = {
|
||||
'name' : '_div',
|
||||
'type' : 'text'
|
||||
};
|
||||
// end: price_start
|
||||
// begin: discount
|
||||
columns[6] = {
|
||||
'name' : 'discount',
|
||||
'label' : 'Upust (%)',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[6]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text',
|
||||
'isNumber' : true,
|
||||
'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'
|
||||
};
|
||||
// end: discount
|
||||
// begin: price_netto
|
||||
columns[7] = {
|
||||
'name' : 'price_',
|
||||
'label' : 'Cena<br>po upuście',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[7]['content'][0] = {
|
||||
'name' : 'netto',
|
||||
'type' : 'text',
|
||||
'isNumber' : true,
|
||||
'readonly' : true
|
||||
};
|
||||
columns[7]['content'][1] = {
|
||||
'name' : 'brutto',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
// end: price_start
|
||||
// begin: ecmvat
|
||||
columns[8] = {
|
||||
'name' : 'ecmvat_',
|
||||
'label' : 'VAT (%)',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[8]['content'][0] = {
|
||||
'name' : 'name',
|
||||
'type' : 'text'
|
||||
};
|
||||
columns[8]['content'][1] = {
|
||||
'name' : 'value',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[8]['content'][2] = {
|
||||
'name' : 'id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[8]['content'][3] = {
|
||||
'name' : 'alter_id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[8]['content'][4] = {
|
||||
'name' : 'alter_value',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[8]['content'][5] = {
|
||||
'name' : 'alter_name',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
// end: ecmvat
|
||||
// begin: total
|
||||
columns[9] = {
|
||||
'name' : 'total_',
|
||||
'label' : 'Wartość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[9]['content'][0] = {
|
||||
'name' : 'netto',
|
||||
'type' : 'text',
|
||||
'isNumber' : true,
|
||||
'readonly' : true
|
||||
};
|
||||
columns[9]['content'][1] = {
|
||||
'name' : 'brutto',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[9]['content'][2] = {
|
||||
'name' : 'vat',
|
||||
'type' : 'hidden'
|
||||
}
|
||||
// end: total
|
||||
// begin: recipient_code
|
||||
columns[10] = {
|
||||
'name' : 'recipient_code',
|
||||
'label' : 'Kod Odbiorcy',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[10]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text'
|
||||
};
|
||||
// end: recipient_code
|
||||
// begin: options
|
||||
columns[11] = {
|
||||
'name' : 'options',
|
||||
'label' : 'Opcje',
|
||||
'width' : 3,
|
||||
'content' : new Array(),
|
||||
};
|
||||
595
modules/EcmInvoiceOuts/javascript/helper.php
Normal file
595
modules/EcmInvoiceOuts/javascript/helper.php
Normal file
@@ -0,0 +1,595 @@
|
||||
<?php
|
||||
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
|
||||
die ( '-1' );
|
||||
if (! $_POST ['job'] || $_POST ['job'] == '')
|
||||
die ( '-1' );
|
||||
switch ($_POST ['job']) {
|
||||
case 'getParentInfo' :
|
||||
getParentInfo ( $_POST ['id'], $_POST ['type'] );
|
||||
break;
|
||||
case 'generateNumber' :
|
||||
generateNumber ( $_POST ['stock_id'] );
|
||||
break;
|
||||
case 'generateNumberCorrect' :
|
||||
generateNumberCorrect ();
|
||||
break;
|
||||
case 'searchProducts' :
|
||||
searchProducts ( $_POST ['searchKey'], $_POST ['searchCategory'], $_POST ['searchStock'], $_POST ['searchSort'] );
|
||||
break;
|
||||
case 'getProduct' :
|
||||
getProduct ( $_POST ['id'], $_POST ['pricebook'], $_POST ['account_id'], $_POST ['language'] );
|
||||
break;
|
||||
case 'getItems' :
|
||||
getItems ( $_POST ['record'], $_POST ['type'] );
|
||||
break;
|
||||
case 'getItemsFromWZ' :
|
||||
getItemsFromWZ ( $_POST ['record'], $_POST ['type'] );
|
||||
break;
|
||||
case 'getItemsFromSale' :
|
||||
getItemsFromSale ( $_POST ['record'], $_POST ['type'] );
|
||||
break;
|
||||
case 'getItemsFromReturn' :
|
||||
getItemsFromReturn ( $_POST ['sess_id'] );
|
||||
break;
|
||||
case 'getItemsFromMDCI' :
|
||||
getItemsFromMDCI ( $_POST ['discount'], $_POST['inv'] );
|
||||
break;
|
||||
case 'getCategoriesList' :
|
||||
getCategoriesList ();
|
||||
break;
|
||||
case 'getTranslation' :
|
||||
getTranslation ( $_POST ['product_id'], $_POST ['language'], $_REQUEST ['unit_id'] );
|
||||
break;
|
||||
case 'getPricesInfo' :
|
||||
getPricesInfo ( $_POST ['product_id'], $_POST ['pricebook_id'], $_POST ['account_id'] );
|
||||
break;
|
||||
case 'getStockArray' :
|
||||
getStockArray ( $_POST ['product_id'] );
|
||||
break;
|
||||
case 'getPurchaseArray' :
|
||||
getPurchaseArray ( $_POST ['product_id'] );
|
||||
break;
|
||||
case 'getAddresses' :
|
||||
getAddresses ( $_POST ['account_id'] );
|
||||
break;
|
||||
case 'getPayers' :
|
||||
getPayers ( $_POST ['account_id'] );
|
||||
break;
|
||||
case 'getPayer' :
|
||||
getPayer ( $_POST ['account_id'] );
|
||||
break;
|
||||
case 'getAddress' :
|
||||
getAddress ( $_POST ['account_id'] );
|
||||
break;
|
||||
case 'getNBPCurrencyExchange' :
|
||||
getNBPCurrencyExchange ( $_POST ['c_id'], $_POST ['date'] );
|
||||
break;
|
||||
case 'calculatePaymentDate' :
|
||||
calculatePaymentDate ( $_POST ['pid'], $_POST ['date'] );
|
||||
break;
|
||||
case 'getWzPositions' :
|
||||
getWzPositions( $_POST ['id']);
|
||||
break;
|
||||
}
|
||||
function getWzPositions($record) {
|
||||
$lists=explode(',',$record);
|
||||
$items=array();
|
||||
$of = new EcmStockDocOut();
|
||||
$poz=0;
|
||||
$total=0;
|
||||
foreach ($lists as $list){
|
||||
|
||||
$of->retrieve($list);
|
||||
$pl = $of->getPositionList(true);
|
||||
foreach ($pl as $pls){
|
||||
$total=$total+$pls['quantity'];
|
||||
if($items[$pls['product_id']]['quantity']!=""){
|
||||
$pls['quantity']=$pls['quantity']+$items[$pls['product_id']]['quantity'];
|
||||
}
|
||||
$items[$pls['product_id']]=$pls;
|
||||
$poz++;
|
||||
}
|
||||
}
|
||||
|
||||
$return=[];
|
||||
foreach ($items as $item){
|
||||
$item['position']=$poz;
|
||||
$return[]=$item;
|
||||
$poz++;
|
||||
}
|
||||
|
||||
// echo $total;
|
||||
|
||||
|
||||
unset($of);
|
||||
echo json_encode($return);
|
||||
return;
|
||||
}
|
||||
|
||||
function getItemsFromMDCI($discount, $inv) {
|
||||
$inv = str_replace('|', "','", $inv);
|
||||
$q = "SELECT ii.* FROM ecminvoiceoutitems AS ii
|
||||
INNER JOIN ecminvoiceouts AS i
|
||||
on i.id = ii.ecminvoiceout_id
|
||||
WHERE
|
||||
i.id IN ('$inv') AND
|
||||
ii.deleted='0'
|
||||
ORDER BY i.date_entered DESC, ii.position";
|
||||
$db = $GLOBALS['db'];
|
||||
$res = $db->query($q);
|
||||
global $app_list_strings;
|
||||
$position_list = array();
|
||||
$i = 0;
|
||||
while ($position = $db->fetchByAssoc($res)) {
|
||||
|
||||
$pos = array ();
|
||||
|
||||
$pos ['product_id'] = $position ['id'];
|
||||
$pos ['position'] = $i; $i++;
|
||||
$pos ['product_code'] = $position ['code'];
|
||||
$pos ['name'] = $position ['name'];
|
||||
$pos ['quantity'] = $position ['quantity'];
|
||||
$pos ['price_start'] = floatval($position['price_netto']) - (floatval($position['price_netto']* (floatval($discount)/100)));
|
||||
$pos ['price_netto'] = floatval($position['price_netto']) - (floatval($position['price_netto']* (floatval($discount)/100)));
|
||||
$pos ['discount'] = '0';//$discount;
|
||||
$pos ['unit_id'] = $position ['dd_unit_id'];
|
||||
$pos ['unit_name'] = $app_list_strings ['ecmproducts_unit_dom'][$pos['unit_id']];
|
||||
$pos ['ecmvat_id'] = $position ['ecmvat_id'];
|
||||
$pos ['ecmvat_name'] = $position ['ecmvat_name'];
|
||||
$pos ['ecmvat_value'] = $position ['ecmvat_value'];
|
||||
$pos ['recipient_code'] = $position ['recipient_code'];
|
||||
$pos ['remarks'] = $position ['remarks'];
|
||||
$pos ['product_itemold_id'] = $position['id'];
|
||||
$pos ['product_item_id'] = $position['id'];
|
||||
$pos ['old_total_netto'] = $position ['total_netto'];
|
||||
$pos ['old_total_brutto'] = $position ['total_brutto'];
|
||||
$pos ['old_quantity'] = $position ['quantity'];
|
||||
$pos ['old_total_vat'] = $position ['total_vat'];
|
||||
$pos ['ecminvoiceoutitem_id'] = $position ['id'];
|
||||
$pos ['product_corrected'] = 'false';
|
||||
$position_list[] = $pos;
|
||||
//corrected item
|
||||
$pos = array ();
|
||||
$pos ['product_id'] = $position ['id'];
|
||||
$pos ['position'] = $i; $i++;
|
||||
$pos ['product_code'] = $position ['code'];
|
||||
$pos ['name'] = $position ['name'];
|
||||
$pos ['quantity'] = $position ['quantity'];
|
||||
$pos ['price_start'] = $position ['price_netto'];
|
||||
$pos ['price_netto'] = $position ['price_netto'];
|
||||
$pos ['discount'] = '0';
|
||||
$pos ['unit_id'] = $position ['dd_unit_id'];
|
||||
$pos ['unit_name'] = $app_list_strings ['ecmproducts_unit_dom'][$pos['unit_id']];
|
||||
$pos ['ecmvat_id'] = $position ['ecmvat_id'];
|
||||
$pos ['ecmvat_name'] = $position ['ecmvat_name'];
|
||||
$pos ['ecmvat_value'] = $position ['ecmvat_value'];
|
||||
$pos ['recipient_code'] = $position ['recipient_code'];
|
||||
$pos ['remarks'] = $position ['remarks'];
|
||||
$pos ['old_ecminvoiceoutitem_id'] = $position ['id'];
|
||||
$pos ['old_total_netto'] = $position ['total_netto'];
|
||||
$pos ['old_total_brutto'] = $position ['total_brutto'];
|
||||
$pos ['old_quantity'] = $position ['quantity'];
|
||||
$pos ['old_total_vat'] = $position ['total_vat'];
|
||||
$pos ['ecminvoiceoutitem_id'] = $position ['id'];
|
||||
$pos ['product_corrected'] = 'true';
|
||||
$position_list[] = $pos;
|
||||
}
|
||||
|
||||
echo json_encode($position_list);
|
||||
return;
|
||||
}
|
||||
function getItemsFromReturn($sess_id) {
|
||||
$items = json_decode ( $_SESSION [$sess_id] , true);
|
||||
$position_list = array ();
|
||||
$i = 0;
|
||||
|
||||
global $app_list_strings;
|
||||
|
||||
foreach ( $items as $position ) {
|
||||
|
||||
$pos = array ();
|
||||
|
||||
$pos ['product_id'] = $position ['id'];
|
||||
$pos ['position'] = $i; $i++;
|
||||
$pos ['product_code'] = $position ['code'];
|
||||
$pos ['name'] = $position ['name'];
|
||||
$pos ['quantity'] = $position ['quantity'];
|
||||
$pos ['price_start'] = $position ['price_netto'];
|
||||
$pos ['price_netto'] = $position ['price_netto'];
|
||||
$pos ['discount'] = '0';
|
||||
$pos ['total_netto'] = $position ['total_netto'];
|
||||
$pos ['unit_id'] = $position ['unit_id'];
|
||||
$pos ['unit_name'] = $app_list_strings ['ecmproducts_unit_dom'][$pos['unit_id']];
|
||||
$pos ['ecmvat_id'] = $position ['vat_id'];
|
||||
$pos ['ecmvat_name'] = $position ['vat_name'];
|
||||
$pos ['ecmvat_value'] = $position ['vat_value'];
|
||||
$pos ['recipient_code'] = $position ['recipient_code'];
|
||||
$pos ['remarks'] = $position ['remarks'];
|
||||
$pos ['product_itemold_id'] = $position['old_ecminvoiceoutitem_id'];
|
||||
$pos ['product_item_id'] = $position['item_id'];
|
||||
$pos ['old_total_netto'] = $position ['total_netto'];
|
||||
$pos ['old_total_brutto'] = $position ['total_brutto'];
|
||||
$pos ['old_quantity'] = $position ['old_qty'];
|
||||
$pos ['old_total_vat'] = $position ['total_vat'];
|
||||
$pos ['ecminvoiceoutitem_id'] = $position ['ecminvoiceoutitem_id'];
|
||||
$pos ['total_vat'] = $position ['total_vat'];
|
||||
$pos ['total_brutto'] = $position ['total_brutto'];
|
||||
$pos ['product_corrected'] = 'false';
|
||||
$position_list[] = $pos;
|
||||
//corrected item
|
||||
$pos = array ();
|
||||
$pos ['product_id'] = $position ['id'];
|
||||
$pos ['position'] = $i; $i++;
|
||||
$pos ['product_code'] = $position ['code'];
|
||||
$pos ['name'] = $position ['name'];
|
||||
$pos ['quantity'] = $position ['old_qty'];
|
||||
$pos ['price_start'] = $position ['price_netto'];
|
||||
$pos ['price_netto'] = $position ['price_netto'];
|
||||
$pos ['discount'] = '0';
|
||||
$pos ['total_netto'] = $position ['total_netto'];
|
||||
$pos ['unit_id'] = $position ['unit_id'];
|
||||
$pos ['unit_name'] = $app_list_strings ['ecmproducts_unit_dom'][$pos['unit_id']];
|
||||
$pos ['ecmvat_id'] = $position ['vat_id'];
|
||||
$pos ['ecmvat_name'] = $position ['vat_name'];
|
||||
$pos ['ecmvat_value'] = $position ['vat_value'];
|
||||
$pos ['recipient_code'] = $position ['recipient_code'];
|
||||
$pos ['remarks'] = $position ['remarks'];
|
||||
$pos ['old_ecminvoiceoutitem_id'] = $position ['old_ecminvoiceoutitem_id'];
|
||||
$pos ['old_total_netto'] = $position ['old_total_netto'];
|
||||
$pos ['old_total_brutto'] = $position ['old_total_brutto'];
|
||||
$pos ['old_quantity'] = $position ['old_quantity'];
|
||||
$pos ['old_total_vat'] = $position ['old_total_vat'];
|
||||
$pos ['ecminvoiceoutitem_id'] = $position ['ecminvoiceoutitem_id'];
|
||||
$pos ['total_vat'] = $position ['total_vat'];
|
||||
$pos ['total_brutto'] = $position ['total_brutto'];
|
||||
$pos ['product_corrected'] = 'true';
|
||||
$position_list[] = $pos;
|
||||
}
|
||||
|
||||
echo json_encode($position_list);
|
||||
return;
|
||||
}
|
||||
function calculatePaymentDate($pid, $d) {
|
||||
global $timedate;
|
||||
|
||||
$w = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "select days from ecmpaymentconditions where id='" . $pid . "'" ) );
|
||||
$date = new DateTime ( $d );
|
||||
$date->add ( new DateInterval ( 'P' . $w ['days'] . 'D' ) );
|
||||
echo json_encode ( $date->format ( 'd.m.Y' ) );
|
||||
return;
|
||||
}
|
||||
function getNBPCurrencyExchange($c_id, $d) {
|
||||
global $timedate;
|
||||
$d = explode ( '-', reset ( explode ( " ", $timedate->to_db ( $d ) ) ) );
|
||||
$date = date ( "Y-m-d", @mktime ( 0, 0, 0, $d [1], $d [2], $d [0] ) + 3600 * 24 );
|
||||
|
||||
// what day is it?
|
||||
$dn = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "SELECT DAYNAME('$date') as dayname" ) );
|
||||
|
||||
if ($dn ['dayname'] == 'Sunday') // - 2 days
|
||||
$q = "SELECT value, nbp_table_name FROM currency_nbp_archive WHERE currency_id='$c_id' AND date = DATE_ADD('$date', INTERVAL -2 DAY)";
|
||||
elseif ($dn ['dayname'] == 'Saturday') // - 1 day
|
||||
$q = "SELECT value, nbp_table_name FROM currency_nbp_archive WHERE currency_id='$c_id' AND date = DATE_ADD('$date', INTERVAL -1 DAY)";
|
||||
else // any other day - just get exchange
|
||||
$q = "SELECT value, nbp_table_name FROM currency_nbp_archive WHERE currency_id='$c_id' AND date='$date'";
|
||||
|
||||
$w = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( $q ) );
|
||||
|
||||
$tmp = array();
|
||||
if(round ( $w ['value'], 2 )!=0){
|
||||
$tmp['value'] = round ( $w ['value'], 2 );
|
||||
} else {
|
||||
$tmp['value'] = null;
|
||||
}
|
||||
|
||||
$tmp['name'] = $w['nbp_table_name'];
|
||||
echo json_encode($tmp);
|
||||
unset($tmp);
|
||||
return;
|
||||
}
|
||||
function getAddress($account_id) {
|
||||
$a = new Account ();
|
||||
echo json_encode ( $a->getAddress ( $account_id ) );
|
||||
unset ( $a );
|
||||
return;
|
||||
}
|
||||
function getPayer($account_id) {
|
||||
$a = new Account ();
|
||||
echo json_encode ( $a->getAddress ( $account_id ) );
|
||||
unset ( $a );
|
||||
return;
|
||||
}
|
||||
function getAddresses($account_id) {
|
||||
$a = new Account ();
|
||||
|
||||
echo json_encode ( $a->getAddresses ( $account_id ) );
|
||||
unset ( $a );
|
||||
return;
|
||||
}
|
||||
function getPayers($account_id) {
|
||||
$a = new Account ();
|
||||
|
||||
echo json_encode ( $a->getPayers ( $account_id ) );
|
||||
unset ( $a );
|
||||
return;
|
||||
}
|
||||
function getParentInfo($id, $type) {
|
||||
if (! $id || $id == '')
|
||||
die ( '-1' );
|
||||
if (! $type || $type == '')
|
||||
die ( '-1' );
|
||||
|
||||
if ($type == 'Accounts')
|
||||
$a = new Account ();
|
||||
elseif ($type == 'Leads')
|
||||
$a = new Lead ();
|
||||
else
|
||||
die ( - 1 );
|
||||
|
||||
$a->retrieve ( $id );
|
||||
$data = array ();
|
||||
$data ['name'] = $a->name;
|
||||
$data ['parent_nip'] = $a->to_vatid;
|
||||
$data ['parent_address_street'] = $a->billing_address_street;
|
||||
$data ['parent_address_postalcode'] = $a->billing_address_postalcode;
|
||||
$data ['parent_address_city'] = $a->billing_address_city;
|
||||
$data ['parent_address_country'] = $a->billing_address_country;
|
||||
$data ['invoice_type'] = $a->invoice_type;
|
||||
$data ['currency_id'] = $a->currency_id;
|
||||
$data ['parent_iln'] = $a->iln;
|
||||
if ($a->ecmpaymentcondition_id && $a->ecmpaymentcondition_id != '') {
|
||||
$pc = new EcmPaymentCondition ();
|
||||
$pc->retrieve ( $a->ecmpaymentcondition_id );
|
||||
$data ['ecmpaymentcondition_id'] = $pc->id;
|
||||
$data ['ecmpaymentcondition_name'] = $pc->name;
|
||||
}
|
||||
if ($a->ecmdeliverycondition_id && $a->ecmdeliverycondition_id != '') {
|
||||
$pc = new EcmdeliveryCondition ();
|
||||
$pc->retrieve ( $a->ecmdeliverycondition_id );
|
||||
$data ['ecmdeliverycondition_id'] = $pc->id;
|
||||
$data ['ecmdeliverycondition_name'] = $pc->name;
|
||||
}
|
||||
|
||||
if ($a->ecmprice_id && $a->ecmprice_id != '') {
|
||||
$pr = new EcmPrice ();
|
||||
$pr->retrieve ( $a->ecmprice_id );
|
||||
$data ['ecmprice_id'] = $pr->id;
|
||||
$data ['ecmprice_name'] = $pr->name;
|
||||
}
|
||||
// get pricebooks, ownership pricebooks
|
||||
$pricebooks = array ();
|
||||
$db = $GLOBALS ['db'];
|
||||
$res = $db->query ( "SELECT id, name FROM ecmpricebooks WHERE account_id IN ('" . $a->id . "','" . $a->parent_id . "') AND active='1' AND deleted='0'" );
|
||||
while ( $row = $db->fetchByAssoc ( $res ) ) {
|
||||
$tmp = array ();
|
||||
$tmp ['id'] = $row ['id'];
|
||||
$tmp ['name'] = $row ['name'];
|
||||
$pricebooks [] = $tmp;
|
||||
unset ( $tmp );
|
||||
}
|
||||
$data ['pricebooks'] = $pricebooks;
|
||||
echo json_encode ( $data );
|
||||
unset ( $data );
|
||||
unset ( $a );
|
||||
unset ( $res );
|
||||
return;
|
||||
}
|
||||
function generateNumber($stock_id) {
|
||||
$data = array ();
|
||||
$data ['number'] = EcmInvoiceOut::generateNumber ( );
|
||||
$data ['document_no'] = EcmInvoiceOut::formatNumber ( $data ['number'] );
|
||||
echo json_encode ( $data );
|
||||
unset ( $data );
|
||||
return;
|
||||
}
|
||||
function generateNumberCorrect() {
|
||||
$data = array ();
|
||||
$data ['number'] = EcmInvoiceOut::generateNumberCorrect ();
|
||||
$data ['document_no'] = EcmInvoiceOut::formatNumberCorrect ( $data ['number'] );
|
||||
echo json_encode ( $data );
|
||||
unset ( $data );
|
||||
return;
|
||||
}
|
||||
function searchProducts($searchKey, $searchCategory, $searchStock, $searchSort) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$q = "SELECT id, code, name FROM ecmproducts WHERE
|
||||
(UPPER(code) LIKE '%$searchKey%' OR
|
||||
UPPER(name) LIKE '%$searchKey%')
|
||||
AND deleted='0' ";
|
||||
if ($searchCategory && $searchCategory != "")
|
||||
$q .= "AND product_category_id='$searchCategory' ";
|
||||
|
||||
if ($searchSort == '1')
|
||||
$q .= "ORDER BY code";
|
||||
else if ($searchSort == '2')
|
||||
$q .= "ORDER BY code DESC";
|
||||
else if ($searchSort == '3')
|
||||
$q .= "ORDER BY name";
|
||||
else if ($searchSort == '4')
|
||||
$q .= "ORDER BY name DESC";
|
||||
|
||||
$q .= " LIMIT 0,50";
|
||||
|
||||
$res = $db->query ( $q );
|
||||
$result = array ();
|
||||
|
||||
if ($searchStock != '1') {
|
||||
// get main stock id
|
||||
$stock_res = $db->fetchByAssoc ( $db->query ( "SELECT id FROM ecmstocks WHERE main='1' LIMIT 0,1" ) );
|
||||
$stock_id = $stock_res ['id'];
|
||||
}
|
||||
while ( $row = $db->fetchByAssoc ( $res ) ) {
|
||||
$tmp = array ();
|
||||
$tmp ['id'] = $row ['id'];
|
||||
$tmp ['name'] = $row ['name'];
|
||||
$tmp ['code'] = $row ['code'];
|
||||
|
||||
// get stock if necessary
|
||||
if ($searchStock != '1') {
|
||||
$tmp ['stock_state'] = EcmStockOperation::getStock ( $row ['id'], $stock_id );
|
||||
}
|
||||
|
||||
if ($searchStock == '3' && $tmp ['stock_state'] == 0)
|
||||
continue; // don't show null stock
|
||||
|
||||
$result [] = $tmp;
|
||||
}
|
||||
echo json_encode ( $result );
|
||||
return;
|
||||
}
|
||||
function getProduct($id, $pricebook_id, $account_id, $language) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$p = $db->fetchByAssoc ( $db->query ( "SELECT p.id, p.code, p.name, v.id as ecmvat_id, v.name as ecmvat_name, v.value as ecmvat_value, p.ean, p.ean2, p.unit_id FROM ecmproducts as p INNER JOIN ecmvats as v ON v.id=p.vat_id WHERE p.id='$id'" ) );
|
||||
global $app_list_strings;
|
||||
$p ['unit_name'] = $app_list_strings ['ecmproducts_unit_dom'] [$p ['unit_id']];
|
||||
// try get recipient_code and price from pricebook
|
||||
if ($pricebook_id && $pricebook_id != '') {
|
||||
$pr = $db->fetchByAssoc ( $db->query ( "SELECT price, recipient_code FROM ecmpricebooks_ecmproducts WHERE ecmpricebook_id='$pricebook_id' AND ecmproduct_id='$id' AND deleted='0'" ) );
|
||||
$p ['price_start'] = $pr ['price'];
|
||||
$p ['recipient_code'] = $pr ['recipient_code'];
|
||||
}
|
||||
if (! $p ['price_start'] || floatval ( $p ['price_start'] ) == 0) {
|
||||
// try price from default prices
|
||||
$pr = $db->fetchByAssoc ( $db->query ( "SELECT pp.price FROM ecmprices_ecmproducts AS pp INNER JOIN ecmprices AS p ON pp.ecmprice_id=p.id INNER JOIN accounts AS a ON p.id=a.ecmprice_id WHERE a.id='$account_id' AND pp.ecmproduct_id='$id'" ) );
|
||||
$p ['price_start'] = $pr ['price'];
|
||||
}
|
||||
|
||||
if ($language == 'en_us') {
|
||||
$r = $db->fetchByAssoc ( $db->query ( "SELECT short_description FROM ecmproduct_language WHERE ecmproduct_id='$id' AND language='en'" ) );
|
||||
$p ['name'] = htmlspecialchars_decode ( $r ['short_description'] );
|
||||
|
||||
$lists = return_app_list_strings_language ( $language );
|
||||
$p ['unit_name'] = $lists ['ecmproducts_unit_dom'] [$p ['unit_id']];
|
||||
|
||||
$p ['ecmvat_alter_id'] = $p ['ecmvat_id'];
|
||||
$p ['ecmvat_alter_name'] = $p ['ecmvat_name'];
|
||||
$p ['ecmvat_alter_value'] = $p ['ecmvat_value'];
|
||||
$p ['ecmvat_id'] = '9b783d21-5548-6653-e1d6-49610eb3f9dd';
|
||||
$p ['ecmvat_name'] = '0%';
|
||||
$p ['ecmvat_value'] = '0';
|
||||
unset ( $lists );
|
||||
}
|
||||
echo json_encode ( $p );
|
||||
return;
|
||||
}
|
||||
function getItems($record, $type) {
|
||||
$of = new EcmInvoiceOut ();
|
||||
$of->retrieve ( $record );
|
||||
$pl = $of->getPositionList ( true, $type );
|
||||
unset ( $of );
|
||||
echo json_encode ( $pl );
|
||||
return;
|
||||
}
|
||||
function getItemsFromWZ($record, $type) {
|
||||
$of = new EcmStockDocOut ();
|
||||
$of->retrieve ( $record );
|
||||
$pl = $of->getPositionList ( true );
|
||||
unset ( $of );
|
||||
echo json_encode ( $pl );
|
||||
return;
|
||||
}
|
||||
function getItemsFromSale($record, $type) {
|
||||
$of = new EcmSale ();
|
||||
$of->retrieve ( $record );
|
||||
$pl = $of->getPositionList ( true );
|
||||
unset ( $of );
|
||||
echo json_encode ( $pl );
|
||||
return;
|
||||
}
|
||||
function getCategoriesList() {
|
||||
$db = $GLOBALS ['db'];
|
||||
$res = $db->query ( "SELECT id, name FROM ecmproductcategories WHERE deleted='0'" );
|
||||
$result = array ();
|
||||
while ( $row = $db->fetchByAssoc ( $res ) ) {
|
||||
$tmp = array ();
|
||||
$tmp ['id'] = $row ['id'];
|
||||
$tmp ['name'] = $row ['name'];
|
||||
$result [] = $tmp;
|
||||
}
|
||||
echo json_encode ( $result );
|
||||
return;
|
||||
}
|
||||
function getTranslation($product_id, $language, $unit_id) {
|
||||
$db = $GLOBALS ['db'];
|
||||
$result = array ();
|
||||
if ($language == 'en_us') {
|
||||
$r = $db->fetchByAssoc ( $db->query ( "SELECT short_description FROM ecmproduct_language WHERE ecmproduct_id='$product_id' AND language='en'" ) );
|
||||
$result ['name'] = htmlspecialchars_decode ( $r ['short_description'] );
|
||||
} else if ($language == 'pl_pl') {
|
||||
$p = new EcmProduct ();
|
||||
$p->retrieve ( $product_id );
|
||||
$result ['name'] = htmlspecialchars_decode ( $p->name );
|
||||
unset ( $p );
|
||||
}
|
||||
$lists = return_app_list_strings_language ( $language );
|
||||
$result ['unit_name'] = $lists ['ecmproducts_unit_dom'] [$unit_id];
|
||||
unset ( $lists );
|
||||
|
||||
echo json_encode ( $result );
|
||||
return;
|
||||
}
|
||||
function getPricesInfo($product_id, $pricebook_id, $account_id) {
|
||||
$db = $GLOBALS ['db'];
|
||||
|
||||
$result = array ();
|
||||
if ($pricebook_id && $pricebook_id != '') {
|
||||
// try get price from pricebook
|
||||
$res = $db->fetchByAssoc ( $db->query ( "SELECT price FROM ecmpricebooks_ecmproducts WHERE ecmpricebook_id='$pricebook_id' AND ecmproduct_id='$product_id' AND deleted='0'" ) );
|
||||
if ($res ['price'] && $res ['price'] != '' && $res ['price'] != 0) {
|
||||
$tmp = array ();
|
||||
$tmp ['name'] = 'pricebook';
|
||||
$tmp ['price'] = $res ['price'];
|
||||
$result [] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// get from ecmprices
|
||||
$res = $db->query ( "SELECT p.name, pp.price FROM ecmprices_ecmproducts AS pp
|
||||
INNER JOIN ecmprices AS p
|
||||
ON p.id=pp.ecmprice_id
|
||||
WHERE
|
||||
pp.ecmproduct_id='$product_id'
|
||||
AND pp.price!=0" );
|
||||
while ( $row = $db->fetchByAssoc ( $res ) ) {
|
||||
$tmp = array ();
|
||||
$tmp ['name'] = $row ['name'];
|
||||
$tmp ['price'] = $row ['price'];
|
||||
$result [] = $tmp;
|
||||
}
|
||||
|
||||
// get last invoice price
|
||||
if ($account_id && $account_id != '') {
|
||||
$res = $db->fetchByAssoc ( $db->query ( "SELECT ii.subprice, i.id, i.document_no FROM ecminvoiceoutitems AS ii
|
||||
INNER JOIN ecminvoiceouts AS i
|
||||
ON ii.ecminvoiceout_id=i.id
|
||||
WHERE ii.ecmproduct_id='$product_id'
|
||||
AND i.parent_id='$account_id'
|
||||
AND ii.deleted='0'
|
||||
AND i.deleted='0'
|
||||
AND i.canceled='0'
|
||||
ORDER BY i.register_date DESC
|
||||
LIMIT 0,1" ) );
|
||||
if ($res && $res ['subprice'] != '') {
|
||||
$tmp = array ();
|
||||
$tmp ['name'] = $res ['document_no'];
|
||||
$tmp ['price'] = $res ['subprice'];
|
||||
$result [] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode ( $result );
|
||||
return;
|
||||
}
|
||||
function getStockArray($product_id) {
|
||||
$o = new EcmStockOperation ();
|
||||
echo json_encode ( $o->getStockArray ( $product_id ) );
|
||||
unset ( $o );
|
||||
return;
|
||||
}
|
||||
function getPurchaseArray($product_id) {
|
||||
$o = new EcmStockOperation ();
|
||||
echo json_encode ( $o->getPurchaseArray ( $product_id ) );
|
||||
unset ( $o );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
$(document).ready(function() {
|
||||
//load number functions if they are not loaded yet
|
||||
if (typeof window["FormatNumber"] === 'undefined') {
|
||||
$.ajax({
|
||||
async : false,
|
||||
url : "include/ECM/EcmNumberFunctions.js",
|
||||
dataType : "script"
|
||||
});
|
||||
}
|
||||
$('#invSelectAll').click(function(event) { //on click
|
||||
if(this.checked) { // check select status
|
||||
$('.invcheckbox').each(function() { //loop through each checkbox
|
||||
this.checked = true; //select all checkboxes with class "checkbox1"
|
||||
calculate();
|
||||
});
|
||||
}else{
|
||||
$('.invcheckbox').each(function() { //loop through each checkbox
|
||||
this.checked = false; //deselect all checkboxes with class "checkbox1"
|
||||
calculate();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#discount').on('blur', function() {
|
||||
calculate();
|
||||
});
|
||||
});
|
||||
|
||||
var calculate = function() {
|
||||
var discount = UnformatNumber($('#discount').val())/100;
|
||||
$('#discount').val(FormatNumber(UnformatNumber($('#discount').val())));
|
||||
console.log(discount);
|
||||
var sum_disc = 0;
|
||||
$('#invTable tr').each(function (i, row) {
|
||||
if (i == 0 || i == $('#invTable tr').lenght) return;
|
||||
if ($(row).find('.invcheckbox').is(':checked') == false) return;
|
||||
var val = parseFloat($(row).find('.netto').html());
|
||||
sum_disc += val * discount;
|
||||
});
|
||||
$('#total_info').html('-'+FormatNumber(sum_disc));
|
||||
}
|
||||
|
||||
var prepareData = function() {
|
||||
var inv = "";
|
||||
$('.invcheckbox:checked').each(function (){
|
||||
inv+=this.value+'|';
|
||||
});
|
||||
inv = inv.slice(0,-1);
|
||||
var link = "index.php?module=EcmInvoiceOuts&action=EditView&mdci=1&account_id="+$('#account_id').val();
|
||||
link +="&account_name="+$('#account_name').val()+'&invoices='+inv+'&discount='+UnformatNumber($('#discount').val());
|
||||
window.location = link;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user