init
This commit is contained in:
112
modules/EcmStockDocOuts/javascript/EcmStockDocOuts.js
Normal file
112
modules/EcmStockDocOuts/javascript/EcmStockDocOuts.js
Normal file
@@ -0,0 +1,112 @@
|
||||
//START:
|
||||
$(document).ready(
|
||||
function() {
|
||||
var checkgen;
|
||||
// confirm exit
|
||||
window.onbeforeunload = confirmExit;
|
||||
// prevent submit by enter press
|
||||
lockEnter();
|
||||
// categories
|
||||
getCategoriesList();
|
||||
$('#parent_id').on('inputchange',
|
||||
function() {
|
||||
$(".loading_panel").css("display", "block");
|
||||
setTimeout(function() {
|
||||
getParentInfo($("#parent_id").val(), 'Accounts');
|
||||
}, 1000);
|
||||
});
|
||||
// searchProductInput change
|
||||
$('#searchProductsInput').keyup(function() {
|
||||
searchProducts();
|
||||
});
|
||||
$("#stock").change(function() {
|
||||
$("#stock_id").val(($("#stock :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();
|
||||
$(".loading_panel").css("display", "none");
|
||||
|
||||
if (($("#new_number").val() == true)
|
||||
&& ($("#duplicate").val() != true)&& ($("#ecmsale").val() != true)) {
|
||||
checkgen=1;
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#duplicate").val() == true)) {
|
||||
checkgen=1;
|
||||
getItems();
|
||||
} else if (($("#new_number").val() == true)
|
||||
&& ($("#ecmsale").val() == true)) {
|
||||
checkgen=1;
|
||||
getParentInfo($("#parent_id").val(),'Accounts');
|
||||
|
||||
getItemsFromEcmSale();
|
||||
|
||||
|
||||
} else {
|
||||
checkgen=0;
|
||||
}
|
||||
|
||||
//console.log(checkProducts());
|
||||
//if (checkProducts()==false)
|
||||
//alert("Nie ma produktów na stanie");
|
||||
|
||||
if(checkgen==1){
|
||||
generateDocNumberStock();
|
||||
|
||||
}
|
||||
// handle setItems
|
||||
setITEMS = function() {
|
||||
var formname = 'EditView';
|
||||
if (check_form_(formname) == true) {
|
||||
SetTab('ITEMS');
|
||||
checkProducts();
|
||||
//disable stock change
|
||||
$("#stock").prop("disabled", true);
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
// 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");
|
||||
$("#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);
|
||||
});
|
||||
|
||||
1103
modules/EcmStockDocOuts/javascript/bimit_table.js
Normal file
1103
modules/EcmStockDocOuts/javascript/bimit_table.js
Normal file
File diff suppressed because it is too large
Load Diff
128
modules/EcmStockDocOuts/javascript/columndefs-detail.js
Normal file
128
modules/EcmStockDocOuts/javascript/columndefs-detail.js
Normal file
@@ -0,0 +1,128 @@
|
||||
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' : 'checkProducts();'};
|
||||
//end: quantity
|
||||
//begin: unit
|
||||
columns[4] = {
|
||||
'name' : 'unit_',
|
||||
'label' : 'J.M.',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'center',
|
||||
'precision' : 0,
|
||||
};
|
||||
columns[4]['content'][0] = {'name' : 'name', 'type': 'text','readonly' : true};
|
||||
columns[4]['content'][1] = {'name' : 'id', 'type': 'hidden'};
|
||||
//end: unit
|
||||
//begin: price
|
||||
columns[5] = {
|
||||
'name' : 'price_sell',
|
||||
'label' : 'Cena sprzedaży',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[5]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true};
|
||||
//end: price
|
||||
//begin: total
|
||||
columns[6] = {
|
||||
'name' : 'total_sell',
|
||||
'label' : 'Wartość',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[6]['content'][0] = {'name' : '', 'type': 'text', 'isNumber' : true};
|
||||
|
||||
//end: total
|
||||
columns[7] = {
|
||||
'name' : 'ean',
|
||||
'label' : 'Ean',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[7]['content'][0] = {'name' : '', 'type': 'text'};
|
||||
columns[8] = {
|
||||
'name' : 'supplier_code',
|
||||
'label' : 'Kod odbiorcy',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[8]['content'][0] = {'name' : '', 'type': 'text'};
|
||||
columns[9] = {
|
||||
'name' : 'product_',
|
||||
'label' : 'Sztuk w kartonie',
|
||||
'width' : 4,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[9]['content'][0] = {
|
||||
'name' : 'pieces_per_carton',
|
||||
'type': 'text',
|
||||
'isNumber' : true,
|
||||
'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'
|
||||
};
|
||||
columns[10] = {
|
||||
'name' : 'product_',
|
||||
'label' : 'Ilość kartonów',
|
||||
'width' : 4,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[10]['content'][0] = {
|
||||
'name' : 'cartons',
|
||||
'type': 'text',
|
||||
'isNumber' : true,
|
||||
'readonly' : true
|
||||
};
|
||||
columns[11] = {
|
||||
'name' : 'part_no',
|
||||
'label' : 'Numer partii',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[11]['content'][0] = {
|
||||
'name' : '',
|
||||
'type': 'text',
|
||||
'onChange' : 'updatePartNo($(this).parent(\'td\').parent(\'tr\').index());'
|
||||
};
|
||||
184
modules/EcmStockDocOuts/javascript/columndefs.js
Normal file
184
modules/EcmStockDocOuts/javascript/columndefs.js
Normal file
@@ -0,0 +1,184 @@
|
||||
columns = new Array();
|
||||
// define columns
|
||||
// begin: number
|
||||
columns[0] = {
|
||||
'name' : 'number',
|
||||
'label' : 'Lp.',
|
||||
'width' : 2,
|
||||
'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' : 'category_id',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][4] = {
|
||||
'name' : 'ean',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
columns[1]['content'][5] = {
|
||||
'name' : 'supplier_code',
|
||||
'type' : 'hidden'
|
||||
};
|
||||
// end: code
|
||||
// begin: name
|
||||
columns[2] = {
|
||||
'name' : 'name',
|
||||
'label' : 'Nazwa',
|
||||
'width' : 17,
|
||||
'content' : new Array(),
|
||||
};
|
||||
columns[2]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text'
|
||||
};
|
||||
// end: name
|
||||
// begin: quantity
|
||||
columns[3] = {
|
||||
'name' : 'quantity',
|
||||
'label' : 'Ilość',
|
||||
'width' : 3,
|
||||
'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' : 3,
|
||||
'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: stock_state
|
||||
columns[5] = {
|
||||
'name' : 'stock_state',
|
||||
'label' : 'Stan',
|
||||
'width' : 3,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[5]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text',
|
||||
'isNumber' : true
|
||||
};
|
||||
// end: stock_state
|
||||
// begin: price
|
||||
columns[6] = {
|
||||
'name' : 'price_',
|
||||
'label' : 'Cena sprzedaży',
|
||||
'width' : 3,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[6]['content'][0] = {
|
||||
'name' : 'sell',
|
||||
'type' : 'text',
|
||||
'isNumber' : true,
|
||||
'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'
|
||||
};
|
||||
columns[6]['content'][1] = {
|
||||
'name' : 'total_sell',
|
||||
'type' : 'hidden',
|
||||
'isNumber' : true
|
||||
};
|
||||
|
||||
columns[7] = {
|
||||
'name' : 'product_supplier_code',
|
||||
'label' : 'Kod odbiorcy',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[7]['content'][0] = {
|
||||
'name' : '',
|
||||
'type' : 'text'
|
||||
};
|
||||
columns[8] = {
|
||||
'name' : 'product_',
|
||||
'label' : 'Sztuk w kartonie',
|
||||
'width' : 4,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[8]['content'][0] = {
|
||||
'name' : 'pieces_per_carton',
|
||||
'type': 'text',
|
||||
'isNumber' : true,
|
||||
'onChange' : 'calculateRow($(this).parent(\'td\').parent(\'tr\').index());'
|
||||
};
|
||||
columns[9] = {
|
||||
'name' : 'product_',
|
||||
'label' : 'Ilość kartonów',
|
||||
'width' : 4,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[9]['content'][0] = {
|
||||
'name' : 'cartons',
|
||||
'type': 'text',
|
||||
'isNumber' : true,
|
||||
'readonly' : true
|
||||
};
|
||||
columns[10] = {
|
||||
'name' : 'part_no',
|
||||
'label' : 'Numer partii',
|
||||
'width' : 5,
|
||||
'content' : new Array(),
|
||||
'align' : 'right',
|
||||
};
|
||||
columns[10]['content'][0] = {
|
||||
'name' : '',
|
||||
'type': 'text',
|
||||
'onChange' : 'updatePartNo($(this).parent(\'td\').parent(\'tr\').index());'
|
||||
};
|
||||
// begin: options
|
||||
columns[11] = {
|
||||
'name' : 'options',
|
||||
'label' : 'Opcje',
|
||||
'width' : 3,
|
||||
'content' : new Array(),
|
||||
};
|
||||
338
modules/EcmStockDocOuts/javascript/helper.php
Normal file
338
modules/EcmStockDocOuts/javascript/helper.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?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 'generateDocNumberStock': generateDocNumberStock($_POST['stock_id']); 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 'getItemsFromEcmSale': getItemsFromEcmSale($_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;
|
||||
}
|
||||
function getParentInfo($id, $type) {
|
||||
if (!$id || $id == '') die('-1');
|
||||
|
||||
$a = new Account();
|
||||
$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['parent_iln'] = $a->iln;
|
||||
$data['parent_supplier_code']=$a->supplier_code;
|
||||
$data['invoice_type'] = $a->invoice_type;
|
||||
$data['currency_id'] = $a->currency_id;
|
||||
$data['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;
|
||||
//document validation fields
|
||||
$data['document_recipient_code'] = $a->document_recipient_code;
|
||||
$data['document_parent_order_no'] = $a->document_parent_order_no;
|
||||
$data['document_delivery_address'] = $a->document_delivery_address;
|
||||
$data['document_parent_iln'] = $a->document_parent_iln;
|
||||
$data['document_shipping_iln'] = $a->document_shipping_iln;
|
||||
$data['document_parent_nip'] = $a->document_parent_nip;
|
||||
$data['document_shipping_nip'] = $a->document_shipping_nip;
|
||||
|
||||
//delivery addresses && ownership addresses
|
||||
$addresses = array();
|
||||
//delivery
|
||||
$delivery = $a->getPositionList(true);
|
||||
foreach ($delivery as $d) {
|
||||
$address = array();
|
||||
$address['name'] = $d['name'];
|
||||
$address['street'] = $d['street'];
|
||||
$address['postalcode'] = $d['postalcode'];
|
||||
$address['city'] = $d['city'];
|
||||
$address['country'] = $d['country'];
|
||||
$addresses[] = $address;
|
||||
unset($address);
|
||||
}
|
||||
//ownership
|
||||
$res = $db->query("SELECT name, shipping_address_street, shipping_address_postalcode, shipping_address_city, shipping_address_country, iln, to_vatid,supplier_code FROM accounts WHERE parent_id='$a->id'");
|
||||
while ($r = $db->fetchByAssoc($res)) {
|
||||
$address = array();
|
||||
$address['name'] = $r['name'];
|
||||
$address['street'] = $r['shipping_address_street'];
|
||||
$address['postalcode'] = $r['shipping_address_postalcode'];
|
||||
$address['city'] = $r['shipping_address_city'];
|
||||
$address['country'] = $r['shipping_address_country'];
|
||||
$address['iln'] = $r['iln'];
|
||||
$address['nip'] = $r['to_vatid'];
|
||||
$address['supplier_code']=$r['supplier_code'];
|
||||
$addresses[] = $address;
|
||||
unset($address);
|
||||
}
|
||||
|
||||
$data['addresses'] = $addresses;
|
||||
unset($addresses);
|
||||
|
||||
echo json_encode($data);
|
||||
unset($data);
|
||||
unset($a);
|
||||
unset($res);
|
||||
return;
|
||||
}
|
||||
|
||||
function generateDocNumberStock($stock_id) {
|
||||
$data = array();
|
||||
$data['number'] = EcmStockDocOut::generateNumber($stock_id);
|
||||
$data['document_no'] = EcmStockDocOut::generateDocNumberStock($stock_id);
|
||||
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, p.unit_id, p.product_category_id,p.ean, p.pieces_per_carton 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);
|
||||
|
||||
echo json_encode($p);
|
||||
return;
|
||||
}
|
||||
|
||||
function getItemsFromEcmSale($record) {
|
||||
$s = new EcmSale();
|
||||
$s->retrieve($record);
|
||||
$pl = $s->getPositionList(true);
|
||||
$db = $GLOBALS['db'];
|
||||
foreach($pl as &$p) {
|
||||
$c = $db->fetchByAssoc($db->query("SELECT pieces_per_carton FROM ecmproducts WHERE id='".$p['product_id']."' AND deleted=0"));
|
||||
$p['product_pieces_per_carton'] = intval($c['pieces_per_carton']);
|
||||
$p['product_cartons'] = ceil(intval($p['quantity']) / $p['product_pieces_per_carton']);
|
||||
}
|
||||
unset($s);
|
||||
echo json_encode($pl);
|
||||
return;
|
||||
}
|
||||
function getItems($record) {
|
||||
$mm = new EcmStockDocOut();
|
||||
$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'];
|
||||
$tmp['module']='EcmPrices';
|
||||
$tmp['visible']='1';
|
||||
$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'] = '<a href="index.php?module=EcmInvoiceOuts&action=DetailView&record='.$res['id'].'">'.$res['document_no'].'</a>';
|
||||
$tmp['price'] = $res['subprice'];
|
||||
$tmp['module']='EcmInvoiceOuts';
|
||||
$tmp['visible']='1';
|
||||
$result[] = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
//get from ecmstockdocins
|
||||
$res = $db->query("SELECT ii.price, i.id, i.document_no,ii.quantity,i.register_date FROM ecmstockdocinitems AS ii
|
||||
INNER JOIN ecmstockdocins AS i
|
||||
ON ii.ecmstockdocin_id=i.id
|
||||
WHERE ii.ecmproduct_id='$product_id'
|
||||
AND ii.deleted='0'
|
||||
AND i.deleted='0'
|
||||
ORDER BY i.register_date DESC");
|
||||
while ($row = $db->fetchByAssoc($res)) {
|
||||
$tmp = array();
|
||||
$tmp['name'] = '<a href="index.php?module=EcmStockDocIns&action=DetailView&record='.$row['id'].'">'.$row['document_no'].'</a>';
|
||||
$tmp['price'] = $row['price'];
|
||||
$tmp['module']='EcmStockDocIns';
|
||||
$tmp['quantity']=$row['quantity'];
|
||||
$tmp['register_date']=$row['register_date'];
|
||||
$tmp['visible']='0';
|
||||
$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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user