init
This commit is contained in:
141
modules/EcmPurchaseOrders/javascript/EcmPurchaseOrders.js
Normal file
141
modules/EcmPurchaseOrders/javascript/EcmPurchaseOrders.js
Normal file
@@ -0,0 +1,141 @@
|
||||
//START:
|
||||
$(document).ready(
|
||||
function() {
|
||||
// confirm exit
|
||||
window.onbeforeunload = confirmExit;
|
||||
// prevent submit by enter press
|
||||
lockEnter();
|
||||
//// categories
|
||||
|
||||
$('#parent_name').change(
|
||||
function() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function() {
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
}, 1000);
|
||||
});
|
||||
$('#parent_shipping_name').change(
|
||||
function() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function() {
|
||||
getAddresses($("#parent_shipping_id").val(), 'Accounts');
|
||||
}, 1000);
|
||||
});
|
||||
$('#contact_id').on('inputchange',
|
||||
function() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function() {
|
||||
getContactInfo($("#contact_id").val());
|
||||
}, 1000);
|
||||
});
|
||||
getCategoriesList();
|
||||
$("#stock_pw").change(function() {
|
||||
$("#pw_stock_id").val(($("#stock_pw :selected").val()));
|
||||
});
|
||||
$("#stock_rw").change(function() {
|
||||
$("#rw_stock_id").val(($("#stock_rw :selected").val()));
|
||||
});
|
||||
DrawHeaders();
|
||||
|
||||
$("#register_date").prop("disabled", true);
|
||||
$("#assigned_user_name").prop("disabled", true);
|
||||
//$("#register_date_trigger").hide();
|
||||
$("#btn_assigned_user_name").hide();
|
||||
$("#btn_clr_assigned_user_name").hide();
|
||||
|
||||
if (($("#new_number").val() == true)
|
||||
&& ($("#duplicate").val() != true)) {
|
||||
generateNumber();
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#duplicate").val() == true)) {
|
||||
generateNumber();
|
||||
getParentInfo($("#parent_id").val(),
|
||||
'Accounts');
|
||||
getContactInfo($("#contact_id").val());
|
||||
getItems();
|
||||
|
||||
} else {
|
||||
getParentInfo($("#parent_id").val(),
|
||||
'Accounts');
|
||||
if($("#contact_id").val()!=''){
|
||||
getContactInfo($("#contact_id").val());
|
||||
}
|
||||
getItems();
|
||||
|
||||
}
|
||||
if ($("#position_list").val().length) {
|
||||
const data = JSON.parse($("#position_list").val().replaceAll("'", '"'));
|
||||
setItems(data);
|
||||
FillTable(data, false);
|
||||
calculateAllRows();
|
||||
checkProducts();
|
||||
calculateTotal();
|
||||
}
|
||||
//console.log('ITEMSS', $("#position_list").val());
|
||||
// handle setItems
|
||||
setITEMS = function() {
|
||||
var formname = 'EditView';
|
||||
if (check_form_(formname) == true) {
|
||||
SetTab('ITEMS');
|
||||
checkProducts();
|
||||
calculateTotal();
|
||||
//disable stock change
|
||||
$("#stock_pw").prop("disabled", true);
|
||||
$("#stock_rw").prop("disabled", true);
|
||||
}
|
||||
};
|
||||
// wyszukiwanie start
|
||||
$('#searchProductsInput').keyup(function() {
|
||||
// stronicowanie od 1 strony przy zmianie szukanego produktu
|
||||
$('#searchStart').val(0);
|
||||
searchProducts();
|
||||
});
|
||||
//AddSearchRecord();
|
||||
|
||||
});
|
||||
// handle save
|
||||
var check_form_ = check_form;
|
||||
check_form = function(formname,event) {
|
||||
// zapobiega zapisywaniu dokumentu firefox bug, w przypadku nacisniecia enter w polu z autocomplete
|
||||
if(event.clientY==0 && event.clientX==0){
|
||||
return false;
|
||||
}
|
||||
window.onbeforeunload = null;
|
||||
if (items.length == 0 || items[0].product_id=='') {
|
||||
alert("Brak produktów");
|
||||
return false;
|
||||
}
|
||||
//clearEmpty();
|
||||
$(".loading_panel").css("display", "block");
|
||||
$("#register_date").prop("disabled", false);
|
||||
$("#assigned_user_name").prop("disabled", false);
|
||||
|
||||
$("#position_list").val(JSON.stringifyNoSecurity(items));
|
||||
|
||||
var check = checkProducts();
|
||||
|
||||
$(".loading_panel").css("display", "none");
|
||||
if (check_form_(formname) == false || check == false) {
|
||||
$("#register_date").prop("disabled", true);
|
||||
$("#assigned_user_name").prop("disabled", true);
|
||||
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);
|
||||
});
|
||||
|
||||
1158
modules/EcmPurchaseOrders/javascript/bimit_table.js
Normal file
1158
modules/EcmPurchaseOrders/javascript/bimit_table.js
Normal file
File diff suppressed because it is too large
Load Diff
99
modules/EcmPurchaseOrders/javascript/columndefs-detail.js
Normal file
99
modules/EcmPurchaseOrders/javascript/columndefs-detail.js
Normal file
@@ -0,0 +1,99 @@
|
||||
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};
|
||||
columns[1]['content'][3] = {'name' : 'component', 'type': 'hidden'};
|
||||
//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' : 'checkProducts();'};
|
||||
//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'};
|
||||
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, 'readonly' : true};
|
||||
//end: price_start
|
||||
//begin: ecmvat
|
||||
columns[6] = {
|
||||
'name' : 'ecmvat_',
|
||||
'label' : 'VAT (%)',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[6]['content'][0] = {'name' : 'name', 'type': 'text'};
|
||||
columns[6]['content'][1] = {'name' : 'value', 'type': 'hidden'};
|
||||
columns[6]['content'][2] = {'name' : 'id', 'type': 'hidden'};
|
||||
//end: ecmvat
|
||||
//begin: total
|
||||
columns[7] = {
|
||||
'name' : 'price_cbm',
|
||||
'label' : 'CBM',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[7]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'readonly' : true};
|
||||
columns[8] = {
|
||||
'name' : 'price_moq',
|
||||
'label' : 'MOQ',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[8]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true, 'readonly' : true};
|
||||
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: units
|
||||
98
modules/EcmPurchaseOrders/javascript/columndefs.js
Normal file
98
modules/EcmPurchaseOrders/javascript/columndefs.js
Normal file
@@ -0,0 +1,98 @@
|
||||
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' : 'product_id', 'type': 'hidden'};
|
||||
columns[1]['content'][3] = {'name' : 'component', 'type': 'hidden'};
|
||||
columns[1]['content'][4] = {'name' : 'link', 'type': 'text', 'readonly' : true};
|
||||
columns[1]['content'][5] = {'name' : 'category_id', 'type': 'hidden'};
|
||||
columns[1]['content'][6] = {'name' : 'precision', 'type': 'hidden'};
|
||||
//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());'};
|
||||
columns[3]['content'][1] = {'name' : '_comp', 'type': 'hidden'};
|
||||
//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'};
|
||||
//pricr
|
||||
columns[5] = {
|
||||
'name' : 'price_start',
|
||||
'label' : 'Cena<br>netto',
|
||||
'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'};
|
||||
//vat
|
||||
columns[6] = {
|
||||
'name' : 'ecmvat_',
|
||||
'label' : 'VAT (%)',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[6]['content'][0] = {'name' : 'name', 'type': 'text'};
|
||||
columns[6]['content'][1] = {'name' : 'value', 'type': 'hidden'};
|
||||
columns[6]['content'][2] = {'name' : 'id', 'type': 'hidden'};
|
||||
//end: unit
|
||||
//begin: stock_state
|
||||
columns[7] = {
|
||||
'name' : 'total_',
|
||||
'label' : 'Wartość<br>netto',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[7]['content'][0] = {'name' : 'netto', 'type': 'text', 'isNumber' : true, 'readonly' : true};
|
||||
//end: stock_state
|
||||
//begin: options
|
||||
//cbm
|
||||
|
||||
// opcje
|
||||
columns[8] = {
|
||||
'name' : 'options',
|
||||
'label' : 'Opcje',
|
||||
'width' : 3,
|
||||
'content' : new Array(),
|
||||
};
|
||||
117
modules/EcmPurchaseOrders/javascript/helper.js
Normal file
117
modules/EcmPurchaseOrders/javascript/helper.js
Normal file
@@ -0,0 +1,117 @@
|
||||
var ajax_url = "index.php?module=EcmPurchaseOrders&action=javahelper&to_pdf=1";
|
||||
|
||||
|
||||
//get parent info use ajax
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
//insert parent info in fields
|
||||
function setParentInfo(data) {
|
||||
//pricebooks
|
||||
createPricebookSelect(data.pricebooks);
|
||||
if (data.ecmprice_id && data.ecmprice_name) {
|
||||
$("#ecmprice_id").val(data.ecmprice_id);
|
||||
$("#ecmprice_name").val(data.ecmprice_name);
|
||||
}
|
||||
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.invoice_type && data.invoice_type!='K')
|
||||
$("#no_tax").attr('checked', true);
|
||||
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');
|
||||
//hide loading
|
||||
$(".loading_panel").css("display", "none");
|
||||
}
|
||||
|
||||
function createPricebookSelect(pricebooks) {
|
||||
var s = $("<select id=\"pricebook_id\"/>");
|
||||
var opt = '';
|
||||
$.each(pricebooks, function(index, value) {
|
||||
opt+='<option value="'+value.id+'">'+value.name+'</option>';
|
||||
});
|
||||
s.html(opt);
|
||||
$("#pricebooks").append(s);
|
||||
}
|
||||
|
||||
function generateNumber() {
|
||||
var params = {
|
||||
job : 'generateNumber'
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
dataType : "json",
|
||||
success: function(data) {
|
||||
if (data == '-1') {
|
||||
//try loading again
|
||||
generateNumber();
|
||||
} else {
|
||||
$("#document_no").val(data.document_no);
|
||||
$("#number").val(data.number);
|
||||
$(".loading_panel").css("display", "none");
|
||||
}
|
||||
},
|
||||
data: params
|
||||
});
|
||||
}
|
||||
|
||||
function getCategoriesList() {
|
||||
var params = {
|
||||
job : 'getCategoriesList'
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
dataType : "json",
|
||||
success: function(data) {
|
||||
var html = '<option value=""></option>';
|
||||
$.each(data, function(index, value){
|
||||
html+='<option value="'+value.id+'">'+value.name+'</option>';
|
||||
$("#productSearchCategory").html(html);
|
||||
});
|
||||
},
|
||||
data: params
|
||||
});
|
||||
}
|
||||
387
modules/EcmPurchaseOrders/javascript/helper.php
Normal file
387
modules/EcmPurchaseOrders/javascript/helper.php
Normal file
@@ -0,0 +1,387 @@
|
||||
<?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 'getContactInfo':
|
||||
getContactInfo($_POST['id']);
|
||||
break;
|
||||
case 'generateNumber':
|
||||
generateNumber();
|
||||
break;
|
||||
case 'searchProducts':
|
||||
searchProducts($_POST['searchKey'], $_POST['searchCategory'],
|
||||
$_POST['searchStock'], $_POST['searchSort'],
|
||||
$_POST['searchStockId']);
|
||||
break;
|
||||
case 'getProduct':
|
||||
getProduct($_POST['id'], $_POST['stockId']);
|
||||
break;
|
||||
case 'getItems':
|
||||
getItems($_POST['record']);
|
||||
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 'getStockState':
|
||||
getStockState($_POST['id'], $_POST['stockId']);
|
||||
break;
|
||||
case 'getComponents':
|
||||
getComponents($_POST['product_id']);
|
||||
break;
|
||||
case 'getAddresses':
|
||||
getAddresses($_POST['account_id']);
|
||||
break;
|
||||
case 'getAddress':
|
||||
getAddress($_POST['account_id']);
|
||||
break;
|
||||
case 'setAdress':
|
||||
setAdress($_POST['account_id']);
|
||||
break;
|
||||
}
|
||||
|
||||
function setAdress ($account_id)
|
||||
{
|
||||
$a = new Account();
|
||||
$a->retrieve($account_id);
|
||||
$res=array();
|
||||
$res['street']=$a->billing_address_street;
|
||||
$res['city']=$a->billing_address_city;
|
||||
$res['postalcode']=$a->billing_address_postalcode;
|
||||
$res['country']=$a->billing_address_country;
|
||||
$res['nip']=$a->to_vatid;
|
||||
echo json_encode($res);
|
||||
unset($a);
|
||||
return;
|
||||
}
|
||||
|
||||
function getAddress ($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 getContactInfo ($id)
|
||||
{
|
||||
if (! $id || $id == '')
|
||||
die('-1');
|
||||
$c = new Contact();
|
||||
$c->retrieve($id);
|
||||
$data = array();
|
||||
$data['parent_contact_name'] = $c->first_name . ' ' . $c->last_name;
|
||||
$data['parent_contact_title'] = $c->title;
|
||||
echo json_encode($data);
|
||||
unset($data);
|
||||
unset($c);
|
||||
return;
|
||||
}
|
||||
|
||||
function getParentInfo ($id, $type)
|
||||
{
|
||||
if (! $id || $id == '')
|
||||
die('-1');
|
||||
if (! $type || $type == '')
|
||||
die('-1');
|
||||
|
||||
if ($type == 'Accounts') {
|
||||
$a = new Account();
|
||||
$a->retrieve($id);
|
||||
$data = array();
|
||||
$data['name'] = html_entity_decode($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;
|
||||
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 ()
|
||||
{
|
||||
$data = array();
|
||||
$data['number'] = EcmPurchaseOrder::generateNumber();
|
||||
$data['document_no'] = EcmPurchaseOrder::formatNumber($data['number']);
|
||||
echo json_encode($data);
|
||||
unset($data);
|
||||
return;
|
||||
}
|
||||
|
||||
function searchProducts ($searchKey, $searchCategory, $searchStock, $searchSort,
|
||||
$searchStockId)
|
||||
{
|
||||
$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();
|
||||
|
||||
$stock_id = $searchStockId;
|
||||
|
||||
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, $stockId)
|
||||
{
|
||||
$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']];
|
||||
$p['stock_state'] = $tmp['stock_state'] = EcmStockOperation::getStock($id,
|
||||
$stockId);
|
||||
$p['unit_precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$p['unit_id']];
|
||||
|
||||
echo json_encode($p);
|
||||
return;
|
||||
}
|
||||
|
||||
function getItems ($record)
|
||||
{
|
||||
$mm = new EcmPurchaseOrder();
|
||||
$mm->retrieve($record);
|
||||
$pl = $mm->getPositionList(true);
|
||||
unset($mm);
|
||||
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;
|
||||
}
|
||||
|
||||
function getStockState ($id, $stock_id)
|
||||
{
|
||||
echo EcmStockOperation::getStock($id, $stock_id);
|
||||
return;
|
||||
}
|
||||
|
||||
function getComponents ($product_id)
|
||||
{
|
||||
$p = new EcmProduct();
|
||||
$p->retrieve($product_id);
|
||||
echo json_encode($p->getPositionList(true));
|
||||
return;
|
||||
}
|
||||
|
||||
4
modules/EcmPurchaseOrders/javascript/searchcolumndefs.js
Normal file
4
modules/EcmPurchaseOrders/javascript/searchcolumndefs.js
Normal file
@@ -0,0 +1,4 @@
|
||||
var extraproductinfo_show=true; // info o produkcie
|
||||
var unit_show=true; // jednostka produktu
|
||||
var number_show=false; // numeruje wiersze
|
||||
var module_function="EcmPurchaseOrders";
|
||||
Reference in New Issue
Block a user