diff --git a/config.php b/config.php
index 82463b5b..22f2286b 100755
--- a/config.php
+++ b/config.php
@@ -342,3 +342,4 @@ if ($_SERVER['HTTP_HOST'] == 'localhost:8080') {
$sugar_config['dbconfig']['db_user_name'] = 'root';
$sugar_config['dbconfig']['db_password'] = 'rootpassword';
}
+
diff --git a/index.php b/index.php
index 8d7c98d3..16d040ec 100755
--- a/index.php
+++ b/index.php
@@ -1,7 +1,16 @@
ss = new Sugar_Smarty();
-if (isset ( $_REQUEST ['record'] ) && $_REQUEST['isDuplicate']=="false" ) {
- $focus->retrieve ( $_REQUEST ['record'] );
- if (isset ( $focus->id ) && $focus->id != '') {
- $focus->format_all_fields ();
+if (isset($_REQUEST['record']) && $_REQUEST['isDuplicate'] == "false") {
+ $focus->retrieve($_REQUEST['record']);
+ if (isset($focus->id) && $focus->id != '') {
+ $focus->format_all_fields();
}
-}
-else if ($_REQUEST['isDuplicate']=="true") {
- $new_number=true;
- $duplicate=true;
+} else if ($_REQUEST['isDuplicate'] == "true") {
+ $new_number = true;
+ $duplicate = true;
//get data
$focus->retrieve($_REQUEST['return_id']);
-}
-else {
- $new_number=true;
- //dates
- $focus->stock_id=$current_user->stock_id;
+} else if (isset($_REQUEST['ecommerceKS'])) {
+ $new_number = true;
+ $focus->stock_id = 'cf16804e-f698-5e09-2da3-6553588446ae';
$focus->register_date = date("d.m.Y");
- $OPT ['check_parent_id'] = false;
+ $db = $GLOBALS['db'];
+ $invoiceIds = $_SESSION[$_REQUEST['ecommerceKS']];
+
+
+ $query = "
+ SELECT
+ ip.ecmproduct_id,
+ SUM(ip.quantity) AS quantity,
+ ip.price_netto,
+ p.code,
+ p.name,
+ p.unit_id
+ FROM ecommerce_invoices_products AS ip
+ INNER JOIN ecmproducts AS p ON ip.ecmproduct_id = p.id
+ WHERE invoice_id IN ('" . implode('\',\'', $invoiceIds) . "')
+ AND ip.ecmproduct_id NOT IN ('', '165f364e-9301-25ac-5906-58e38f1de4ca')
+ AND ip.quantity > 0
+ GROUP BY ip.ecmproduct_id, ip.price_netto;
+ ";
+
+ $res = $db->query($query);
+ $products = array();
+ $productIds = array();
+
+ while ($row = $db->fetchByAssoc($res)) {
+ $products[$row['ecmproduct_id']] = $row;
+ $productIds[] = $row['ecmproduct_id'];
+ }
+
+ $prices = array();
+ if (!empty($productIds)) {
+ $priceQuery = "
+ SELECT
+ sdi.ecmproduct_id,
+ sdi.price,
+ sd.register_date
+ FROM ecmstockdocinitems sdi
+ INNER JOIN ecmstockdocins sd ON sdi.ecmstockdocin_id = sd.id
+ WHERE sd.parent_id = 'f084e64a-4e63-a3d1-6417-58cbf730df3f'
+ AND sdi.ecmproduct_id IN ('" . implode('\',\'', $productIds) . "')
+ AND sdi.deleted = 0
+ AND sd.deleted = 0
+ ORDER BY sdi.ecmproduct_id, sd.register_date DESC
+ ";
+
+ $priceRes = $db->query($priceQuery);
+ while ($row = $db->fetchByAssoc($priceRes)) {
+ if (!isset($prices[$row['ecmproduct_id']])) {
+ $prices[$row['ecmproduct_id']] = $row['price'];
+ }
+ }
+ }
+
+ $finalProducts = array();
+ $position = 1;
+ foreach ($products as $productId => $product) {
+ $finalPrice = isset($prices[$productId]) ? $prices[$productId] : $product['price_netto'];
+ $finalProducts[] = array(
+ 'position' => $position++,
+ 'product_id' => $productId,
+ 'product_code' => $product['code'],
+ 'name' => $product['name'],
+ 'quantity' => $product['quantity'],
+ 'price' => $finalPrice,
+ 'unit_id' => $product['unit_id'],
+ 'unit_name' => $app_list_strings['ecmproducts_unit_dom'][$product['unit_id']],
+ 'ecmvat_name' => '23%',
+ 'ecmvat_value' => 23,
+ 'ecmvat_id' => '28079566-b825-e38f-9993-4ccc7b781de5',
+ );
+ }
+
+ $finalProducts = array_values(array_reduce($finalProducts, function ($carry, $item) {
+ $key = $item['product_id'] . '-' . $item['price'];
+ if (!isset($carry[$key])) {
+ $carry[$key] = $item;
+ } else {
+ $carry[$key]['quantity'] += $item['quantity'];
+ }
+ return $carry;
+ }, array()));
+
+ $edit->ss->assign('ECOMMERCE_PRODUCTS', json_encode($finalProducts));
+ $edit->ss->assign('ECOMMERCE_INVOICES', json_encode($invoiceIds));
+ $focus->ecommerce_invoices = $invoiceIds;
+ $focus->type = '8a6b804b-fac7-5cc2-de19-54c209116b19';
+ $focus->stock_id = 'cf16804e-f698-5e09-2da3-6553588446ae';
+ $focus->name = 'Zwrot allegro';
+
+ $query = "SELECT document_no FROM ecommerce_invoices WHERE id IN ('" . implode('\',\'', $invoiceIds) . "')";
+ $res = $db->query($query);
+ $documentNos = array();
+ while ($row = $db->fetchByAssoc($res)) {
+ $documentNos[] = $row['document_no'];
+ }
+ $focus->pdf_text = "Dotyczy faktur: " . implode(', ', $documentNos);
+} else {
+ $new_number = true;
+ //dates
+ $focus->stock_id = $current_user->stock_id;
+ $focus->register_date = date("d.m.Y");
+ $OPT['check_parent_id'] = false;
}
//get stocks
$res = $db->query("SELECT id, name FROM ecmstocks WHERE deleted = '0' ORDER BY name");
$stock = '';
+while ($row = $db->fetchByAssoc($res)) {
+ if ($focus->stock_id != '' && $row['id'] == $focus->stock_id) {
+ $s = 'selected';
+ } else {
+ $s = '';
+ }
+ $stock_body .= '';
+}
+$stock .= $stock_body . '';
-require_once ('include/MVC/View/SugarView.php');
-require_once ('modules/EcmStockDocCorrects/views/EditView/view.edit.ecmstockdoccorrects.php');
-$edit = new ViewEditEcmStockDocCorrects ();
-$edit->ss = new Sugar_Smarty ();
$edit->module = 'EcmStockDocCorrects';
$edit->bean = $focus;
$edit->tplFile = 'include/ECM/EcmViews/EditView/Tabs/EditView.tpl';
-$edit->preDisplay ();
-$edit->ss->assign ( "NEW_NUMBER", $new_number );
+$edit->preDisplay();
+$edit->ss->assign("NEW_NUMBER", $new_number);
$edit->ss->assign("DUPLICATE", $duplicate);
$edit->ss->assign("STOCK", $stock);
-echo $edit->display ();
+echo $edit->display();
//loading view
-echo '
';
\ No newline at end of file
+echo '';
diff --git a/modules/EcmStockDocCorrects/Menu.php b/modules/EcmStockDocCorrects/Menu.php
index 1e0c69ed..342996b6 100755
--- a/modules/EcmStockDocCorrects/Menu.php
+++ b/modules/EcmStockDocCorrects/Menu.php
@@ -98,9 +98,8 @@ if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
global $mod_strings, $current_user;
- if(ACLController::checkAccess('EcmStockDocCorrects', "edit", true)) $module_menu [] = Array("index.php?module=".'EcmStockDocCorrects'."&action=EditView&return_module=".'EcmStockDocCorrects'."&return_action=DetailView", translate('LNK_NEW_'.'ECMSTOCKDOCCORRECT', 'EcmStockDocCorrects'),"CreateEcmStockDocCorrects", 'EcmStockDocCorrects');
-
- if(ACLController::checkAccess('EcmStockDocCorrects', "list", true)) $module_menu [] = Array("index.php?module=EcmStockDocCorrects&action=index&return_module=EcmStockDocCorrects&return_action=DetailView", translate('LNK_ECMSTOCKDOCCORRECTS_LIST','EcmStockDocCorrects'),"EcmStockDocCorrects", 'EcmStockDocCorrects');
-
+$module_menu [] = Array("index.php?module=".'EcmStockDocCorrects'."&action=EditView&return_module=".'EcmStockDocCorrects'."&return_action=DetailView", translate('LNK_NEW_'.'ECMSTOCKDOCCORRECT', 'EcmStockDocCorrects'),"CreateEcmStockDocCorrects", 'EcmStockDocCorrects');
+$module_menu [] = Array("index.php?module=EcmStockDocCorrects&action=index&return_module=EcmStockDocCorrects&return_action=DetailView", translate('LNK_ECMSTOCKDOCCORRECTS_LIST','EcmStockDocCorrects'),"EcmStockDocCorrects", 'EcmStockDocCorrects');
+ $module_menu [] = Array("index.php?module=EcmStockDocCorrects&action=eCommerceKS", "Utwórz zwrot E-Commerce","EcmStockDocCorrects", 'EcmStockDocCorrects');
?>
diff --git a/modules/EcmStockDocCorrects/Save.php b/modules/EcmStockDocCorrects/Save.php
index 424092cf..9a11a113 100755
--- a/modules/EcmStockDocCorrects/Save.php
+++ b/modules/EcmStockDocCorrects/Save.php
@@ -1,6 +1,6 @@
retrieve ( $_POST ['record'] );
+if (isset($_POST['record']) && $_POST['record'] != '') {
+ $focus->retrieve($_POST['record']);
}
-if (! $focus->ACLAccess ( 'Save' )) {
- ACLController::displayNoAccess ( true );
- sugar_cleanup ( true );
+if (! $focus->ACLAccess('Save')) {
+ ACLController::displayNoAccess(true);
+ sugar_cleanup(true);
}
$check_notify = FALSE;
-foreach ( $focus->column_fields as $field ) {
- if (isset ( $_POST [$field] )) {
- $value = $_POST [$field];
+foreach ($focus->column_fields as $field) {
+ if (isset($_POST[$field])) {
+ $value = $_POST[$field];
$focus->$field = $value;
}
}
-foreach ( $focus->additional_column_fields as $field ) {
- if (isset ( $_POST [$field] )) {
- $value = $_POST [$field];
+foreach ($focus->additional_column_fields as $field) {
+ if (isset($_POST[$field])) {
+ $value = $_POST[$field];
$focus->$field = $value;
}
}
-$focus->position_list = $json->decode ( htmlspecialchars_decode ( $_POST ['position_list'] ) );
+$focus->position_list = $json->decode(htmlspecialchars_decode($_POST['position_list']));
-$focus->save ( $check_notify );
+$focus->save($check_notify);
$return_id = $focus->id;
+$focus->ecommerce_invoices = $json->decode(htmlspecialchars_decode($_POST['ecommerce_invoices']));
+if (isset($focus->ecommerce_invoices) && count($focus->ecommerce_invoices) > 0) {
+ $db = $GLOBALS['db'];
+ $db->query("UPDATE ecommerce_invoices SET ecmstockdoccorrect_id = '$return_id' WHERE id IN ('" . implode("','", $focus->ecommerce_invoices) . "')");
+}
+
echo $return_id;
-
- echo '
+
+echo '
';
-handleRedirect ( $return_id, 'EcmStockDocCorrects' );
-?>
\ No newline at end of file
+handleRedirect($return_id, 'EcmStockDocCorrects');
diff --git a/modules/EcmStockDocCorrects/eCommerceKS.php b/modules/EcmStockDocCorrects/eCommerceKS.php
new file mode 100644
index 00000000..90aa6935
--- /dev/null
+++ b/modules/EcmStockDocCorrects/eCommerceKS.php
@@ -0,0 +1,3 @@
+assign('debug', $DEBUG ? '1' : '');
+
+ $invoices = getInvoices($_REQUEST['date_from'], $_REQUEST['date_to']);
+
+ $invoiceIds = array();
+ foreach ($invoices as $invoice) {
+ $invoiceIds[] = $invoice['id'];
+ }
+ $sessionId = create_guid();
+ $_SESSION[$sessionId] = $invoiceIds;
+ $smarty->assign('sessionId', $sessionId);
+
+ $invoiceNo = array();
+ foreach ($invoices as $invoice) {
+ $invoiceNo[] = $invoice['document_no'];
+ }
+ $smarty->assign('invoicesNo', join(", ", $invoiceNo));
+
+ $smarty->assign('date_from', $_REQUEST['date_from']);
+ $smarty->assign('date_to', $_REQUEST['date_to']);
+ echo $smarty->display(getcwd() . '/modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl');
+} else {
+ $smarty->assign('date_from', date('d.m.Y'));
+ $smarty->assign('date_to', date('d.m.Y'));
+ echo $smarty->display(getcwd() . '/modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl');
+}
+
+function getInvoices($dateFrom, $dateTo) {
+ $db = $GLOBALS['db'];
+ $invoices = array();
+ $dateFrom = date('Y-m-d', strtotime($dateFrom));
+ $dateTo = date('Y-m-d', strtotime($dateTo));
+ $query = "SELECT ip.ecmproduct_id, ip.code, i.document_no, SUM(ip.quantity) AS quantity, i.register_date, i.id
+FROM ecommerce_invoices_products AS ip
+INNER JOIN ecommerce_invoices AS i ON ip.invoice_id = i.id AND i.register_date BETWEEN '$dateFrom' AND '$dateTo' AND i.type='correcting'
+AND i.origin IN ('allegro', 'shop')
+WHERE ip.ecmproduct_id != '' AND ip.ecmproduct_id !='165f364e-9301-25ac-5906-58e38f1de4ca' AND ip.quantity > 0
+AND i.ecmstockdoccorrect_id IS NULL
+GROUP BY i.id, ip.ecmproduct_id
+ORDER BY i.register_date;";
+ $res = $db->query($query);
+ while ($row = $db->fetchByAssoc($res)) {
+ if (!isset($invoices[$row['document_no']])) {
+ $invoices[$row['document_no']] = array();
+ $invoices[$row['document_no']]['document_no'] = $row['document_no'];
+ $invoices[$row['document_no']]['register_date'] = $row['register_date'];
+ $invoices[$row['document_no']]['id'] = $row['id'];
+ $invoices[$row['document_no']]['products'] = array();
+ $invoices[$row['document_no']]['products'][] = array (
+ 'ecmproduct_id' => $row['ecmproduct_id'],
+ 'code' => $row['code'],
+ 'quantity' => $row['quantity'],
+ );
+ } else {
+ $invoices[$row['document_no']]['products'][] = array (
+ 'ecmproduct_id' => $row['ecmproduct_id'],
+ 'code' => $row['code'],
+ 'quantity' => $row['quantity'],
+ );
+ }
+ }
+ $invoices = array_values($invoices);
+ usort($invoices, function($a, $b) {
+ return $a['id'] - $b['id'];
+ });
+ return $invoices;
+}
+
+
diff --git a/modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl b/modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl
new file mode 100644
index 00000000..fe11a041
--- /dev/null
+++ b/modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+KS zbiorcza dla FVKOR:
{$invoicesNo}
+
+
\ No newline at end of file
diff --git a/modules/EcmStockDocCorrects/javascript/EcmStockDocCorrects.js b/modules/EcmStockDocCorrects/javascript/EcmStockDocCorrects.js
index d43df352..1b8a80cb 100755
--- a/modules/EcmStockDocCorrects/javascript/EcmStockDocCorrects.js
+++ b/modules/EcmStockDocCorrects/javascript/EcmStockDocCorrects.js
@@ -1,101 +1,105 @@
//START:
$(document).ready(
- function() {
- var checkgen;
- // confirm exit
- window.onbeforeunload = confirmExit;
- // prevent submit by enter press
- lockEnter();
- // categories
- getCategoriesList();
+ function () {
+ var checkgen;
+ // confirm exit
+ window.onbeforeunload = confirmExit;
+ // prevent submit by enter press
+ lockEnter();
+ // categories
+ getCategoriesList();
- $("#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();
-
- if (($("#new_number").val() == true)
- && ($("#duplicate").val() != true)) {
- EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocCorrects');
- } else if (($("#new_number").val() == true)
- && ($("#duplicate").val() == true)) {
- EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocCorrects');
- getItems();
- }
- $("#stock").change(function() {
- $("#stock_id").val(($("#stock :selected").val()));
- EcmDocumentNumberGenerator_getNumber('tmp_number', 'EcmStockDocCorrects', $("#stock :selected").val());
- });
- // handle setItems
- setITEMS = function() {
- var formname = 'EditView';
- if (check_form_(formname) == true) {
- SetTab('ITEMS');
- checkProducts();
- //disable stock change
- $("#stock").prop("disabled", true);
- $("#type").prop("disabled", true);
- }
- };
- // wyszukiwanie start
- $('#searchProductsInput').keyup(function() {
- // stronicowanie od 1 strony przy zmianie szukanego produktu
- $('#searchStart').val(0);
- searchProducts();
- });
- AddSearchRecord();
-
- $(".loading_panel").css("display", "none");
+ $("#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();
+
+ if (($("#new_number").val() == true)
+ && ($("#duplicate").val() != true)) {
+ EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocCorrects');
+ var ecp = $("#ecommerce_products").val();
+ if (ecp && ecp.length > 0) {
+ loadECommerceProducts(ecp);
+ }
+ } else if (($("#new_number").val() == true)
+ && ($("#duplicate").val() == true)) {
+ EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocCorrects');
+ getItems();
+ }
+ $("#stock").change(function () {
+ $("#stock_id").val(($("#stock :selected").val()));
+ EcmDocumentNumberGenerator_getNumber('tmp_number', 'EcmStockDocCorrects', $("#stock :selected").val());
+ });
+ // handle setItems
+ setITEMS = function () {
+ var formname = 'EditView';
+ if (check_form_(formname) == true) {
+ SetTab('ITEMS');
+ checkProducts();
+ //disable stock change
+ $("#stock").prop("disabled", true);
+ $("#type").prop("disabled", true);
+ }
+ };
+ // wyszukiwanie start
+ $('#searchProductsInput').keyup(function () {
+ // stronicowanie od 1 strony przy zmianie szukanego produktu
+ $('#searchStart').val(0);
+ searchProducts();
+ });
+ AddSearchRecord();
+
+ $(".loading_panel").css("display", "none");
+ });
// handle save
var check_form_ = check_form;
-check_form = function(formname,event) {
+check_form = function (formname, event) {
window.onbeforeunload = null;
// zapobiega zapisywaniu dokumentu firefox bug, w przypadku nacisniecia enter w polu z autocomplete
- if(event.clientY==0 && event.clientX==0){
- return false;
- }
-
-
- if (items.length == 0 || items[0].product_id=='') {
+ if (event.clientY == 0 && event.clientX == 0) {
+ return false;
+ }
+
+
+ if (items.length == 0 || items[0].product_id == '') {
alert("Brak produktów");
return false;
}
-
- var part_error=true;
- $.each(items, function(i, v) {
- if (!v.product_id || v.product_id=="") return;
- if (v.product_is_consignment!='1') return;
- if($('#type').val()=='8a6b804b-fac7-5cc2-de19-54c209116b19'){
- if (!v.product_consignment_part || v.product_consignment_part=="") {
- alert("Nie wprowadzono partii");
- part_error=false;
- }
- } else {
- if (!v.product_consignment_id || v.product_consignment_id=="") {
- alert("Nie wybrano partii");
- part_error=false;
- }
- }
-
- })
-
+
+ var part_error = true;
+ $.each(items, function (i, v) {
+ if (!v.product_id || v.product_id == "") return;
+ if (v.product_is_consignment != '1') return;
+ if ($('#type').val() == '8a6b804b-fac7-5cc2-de19-54c209116b19') {
+ if (!v.product_consignment_part || v.product_consignment_part == "") {
+ alert("Nie wprowadzono partii");
+ part_error = false;
+ }
+ } else {
+ if (!v.product_consignment_id || v.product_consignment_id == "") {
+ alert("Nie wybrano partii");
+ part_error = false;
+ }
+ }
+
+ })
+
$(".loading_panel").css("display", "block");
$("#register_date").prop("disabled", false);
$("#assigned_user_name").prop("disabled", false);
$("#type").prop("disabled", false);
-
-
+
+
var check = checkProducts();
$(".loading_panel").css("display", "none");
- if (check_form_(formname) == false || check == false || part_error==false) {
+ if (check_form_(formname) == false || check == false || part_error == false) {
$("#register_date").prop("disabled", true);
$("#assigned_user_name").prop("disabled", true);
window.onbeforeunload = confirmExit;
@@ -114,10 +118,16 @@ function confirmExit() {
function lockEnter() {
// prevent default
- $(window).keydown(function(event) {
- if (event.keyCode == 13 && $(":focus").prop('tagName')!='TEXTAREA') {
+ $(window).keydown(function (event) {
+ if (event.keyCode == 13 && $(":focus").prop('tagName') != 'TEXTAREA') {
event.preventDefault();
return false;
}
});
}
+
+function loadECommerceProducts(ecp) {
+ var products = JSON.parse(ecp);
+ items = products;
+ FillTable(products);
+}
diff --git a/modules/EcmStockDocCorrects/javascript/bimit_table.js b/modules/EcmStockDocCorrects/javascript/bimit_table.js
index e29a58b2..974b41c1 100644
--- a/modules/EcmStockDocCorrects/javascript/bimit_table.js
+++ b/modules/EcmStockDocCorrects/javascript/bimit_table.js
@@ -7,24 +7,24 @@ var ajax_url = "index.php?module=EcmStockDocCorrects&action=javahelper&to_pdf=1"
//custom Fill Table
function calculateAll() {
- var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
- for (var index = 0; index != count; index++) {
- calculateRow(index);
- }
+ var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
+ for (var index = 0; index != count; index++) {
+ calculateRow(index);
+ }
}
function calculateRow(index) {
if (index == -1)
return;
- items[index].quantity_consignment_id = $('#quantity_consignment_id_'+index).val();
- items[index].quantity_consignment_doc = $('#quantity_consignment_doc_'+index).val();
- if($('#type').val()!='8a6b804b-fac7-5cc2-de19-54c209116b19'){
+ items[index].quantity_consignment_id = $('#quantity_consignment_id_' + index).val();
+ items[index].quantity_consignment_doc = $('#quantity_consignment_doc_' + index).val();
+ if ($('#type').val() != '8a6b804b-fac7-5cc2-de19-54c209116b19') {
getConsignmentsDiv(index);
} else {
getInsertConsignmentsDiv(index);
}
-
-
+
+
// liczone według najlepszych zasad księgowości
var price = UnformatNumber($('#price_' + index).val());
var price_old = UnformatNumber($('#price_old_' + index).val());
@@ -33,7 +33,7 @@ function calculateRow(index) {
//alert(palet);
var total = price * quantity;
-var total2 = price_old * quantity;
+ var total2 = price_old * quantity;
// put data
$('#product_total_' + index).val(FormatNumber(total));
@@ -46,66 +46,66 @@ var total2 = price_old * quantity;
items[index].name = $('#name_' + index).val();
items[index].unit_name = $('#unit_name_' + index).val();
- if($('#type').val()=='6ed5b076-ddd1-9809-b236-54e5b2bcbd97'){
- $('#onlyRemoveDif_'+index).remove();
- $('#unit_name_'+index).parent().append('(Różnica: '+FormatNumber(total-total2)+')
');
-
- }
+ if ($('#type').val() == '6ed5b076-ddd1-9809-b236-54e5b2bcbd97') {
+ $('#onlyRemoveDif_' + index).remove();
+ $('#unit_name_' + index).parent().append('(Różnica: ' + FormatNumber(total - total2) + ')
');
+
+ }
// calculate total
calculateTotal();
}
function calculateTotal() {
- if($('#type').val()=='6ed5b076-ddd1-9809-b236-54e5b2bcbd97'){
- var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
- count = items.length;
- var vats = new Array();
- var all_subtotal = 0;
- var all_total = 0;
- var sum_vats = 0;
- var sum_discounts = 0;
- var weight_total=0;
-
-
- for (var index = 0; index != count; index++) {
- subtotal = UnformatNumber($('#diff_this_' + index).val());
- if(!isNaN(subtotal)){
- all_subtotal += subtotal;
-
+ if ($('#type').val() == '6ed5b076-ddd1-9809-b236-54e5b2bcbd97') {
+ var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
+ count = items.length;
+ var vats = new Array();
+ var all_subtotal = 0;
+ var all_total = 0;
+ var sum_vats = 0;
+ var sum_discounts = 0;
+ var weight_total = 0;
+
+
+ for (var index = 0; index != count; index++) {
+ subtotal = UnformatNumber($('#diff_this_' + index).val());
+ if (!isNaN(subtotal)) {
+ all_subtotal += subtotal;
+
+ }
+
}
+ all_total = all_subtotal;
- }
- all_total = all_subtotal;
+ DrawSummary();
- DrawSummary();
+ $("#t_netto").val(FormatNumber(all_total));
+ } else {
+ var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
+ count = items.length;
+ var vats = new Array();
+ var all_subtotal = 0;
+ var all_total = 0;
+ var sum_vats = 0;
+ var sum_discounts = 0;
+ var weight_total = 0;
+
+
+ for (var index = 0; index != count; index++) {
+ subtotal = UnformatNumber($('#product_total_' + index).val());
+ if (!isNaN(subtotal)) {
+ all_subtotal += subtotal;
+
+ }
- $("#t_netto").val(FormatNumber(all_total));
- } else {
- var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
- count = items.length;
- var vats = new Array();
- var all_subtotal = 0;
- var all_total = 0;
- var sum_vats = 0;
- var sum_discounts = 0;
- var weight_total=0;
-
-
- for (var index = 0; index != count; index++) {
- subtotal = UnformatNumber($('#product_total_' + index).val());
- if(!isNaN(subtotal)){
- all_subtotal += subtotal;
-
}
+ all_total = all_subtotal;
+ DrawSummary();
+
+ $("#t_netto").val(FormatNumber(all_total));
}
- all_total = all_subtotal;
- DrawSummary();
- $("#t_netto").val(FormatNumber(all_total));
- }
-
-
}
function DrawSummary() {
$("#result_table").html('');
@@ -121,19 +121,19 @@ function DrawSummary() {
function DrawHeaders() {
var html = '';
html += '';
+ + itemsTable + 'DIV">';
html += '
';
+ + '_T">';
html += '';
html += '';
// draw columns headers
- $.each(columns, function(index, column) {
- if(column.hide=='yes'){
- hide='display:none;'
+ $.each(columns, function (index, column) {
+ if (column.hide == 'yes') {
+ hide = 'display:none;'
} else {
- hide='';
+ hide = '';
}
- html += '| ' + column.label + ' | ';
+ html += '' + column.label + ' | ';
});
html += '
';
html += '
';
@@ -255,23 +255,23 @@ function addProducts() {
$(".loading_panel").css("display", "block");
clearEmpty();
var products = new Array();
- $.each(searchedProducts, function(index, value) {
+ $.each(searchedProducts, function (index, value) {
if ($('#prod_' + value).is(':checked'))
products[value] = true;
});
- var stockId=$("#stock_id").val();
- for ( var key in products) {
+ var stockId = $("#stock_id").val();
+ for (var key in products) {
var params = {
- job : 'getProduct',
- id : key,
- stockId : stockId,
+ job: 'getProduct',
+ id: key,
+ stockId: stockId,
};
$.ajax({
- type : "POST",
- url : ajax_url,
- dataType : "json",
- async : false,
- success : function(data) {
+ type: "POST",
+ url: ajax_url,
+ dataType: "json",
+ async: false,
+ success: function (data) {
if (data != '-1') {
var p = new Object();
p.product_id = data.id;
@@ -285,18 +285,17 @@ function addProducts() {
p.ecmvat_name = data.ecmvat_name;
p.stock_state = data.stock_state;
p.product_category_id = data.product_category_id;
- p.product_precision = data.unit_precision;
- p.unit_precision = data.unit_precision;
+ p.product_precision = data.unit_precision;
+ p.unit_precision = data.unit_precision;
p.product_is_consignment = data.is_consignment;
if ($("#searchInputQty").val() != ''
- && !isNaN(parseFloat(UnformatNumber($(
- "#searchInputQty").val()))))
+ && !isNaN(parseFloat(UnformatNumber($(
+ "#searchInputQty").val()))))
p.quantity = $("#searchInputQty").val();
items.push(p);
- console.log(p);
}
},
- data : params
+ data: params
});
}
AddSearchRecord();
@@ -310,61 +309,61 @@ function addProducts() {
$(".loading_panel").css("display", "none");
}
-function AddProduct(index,record){
+function AddProduct(index, record) {
$(".loading_panel").css("display", "block");
var record;
var pricebook = $("#pricebook_id :selected").val();
- var params = {
- job : 'getProduct',
- id : record,
- stockId : $("#stock_id").val(),
- };
- $.ajax({
- type : "POST",
- url : ajax_url,
- dataType : "json",
- async : false,
- success : function(data) {
- if (data != '-1') {
-
- items[index].product_id = data.id;
- items[index].name = data.name;
- items[index].product_code = data.code;
- items[index].product_id = data.id;
- items[index].ecmvat_id = data.ecmvat_id;
- items[index].ecmvat_value = data.ecmvat_value;
- items[index].ecmvat_name = data.ecmvat_name;
- items[index].product_ean = data.ean;
- items[index].discount = data.discount;
- items[index].product_ean2 = data.ean2;
- items[index].unit_name = data.unit_name;
- items[index].unit_id = data.unit_id;
- items[index].price_start = data.price_start;
- items[index].recipient_code = data.recipient_code;
- items[index].stock_state = data.stock_state;
- items[index].product_precision = data.unit_precision;
- items[index].unit_precision = data.unit_precision;
- items[index].product_is_consignment = data.is_consignment;
- if ($("#searchInputPrice").val() != ''
- && !isNaN(parseFloat(UnformatNumber($(
- "#searchInputPrice").val()))))
- items[index].price_start = $("#searchInputPrice").val();
- if ($("#searchInputQty").val() != ''
- && !isNaN(parseFloat(UnformatNumber($(
- "#searchInputQty").val()))))
- items[index].quantity = $("#searchInputQty").val();
-
- }
- },
- data : params
- });
+ var params = {
+ job: 'getProduct',
+ id: record,
+ stockId: $("#stock_id").val(),
+ };
+ $.ajax({
+ type: "POST",
+ url: ajax_url,
+ dataType: "json",
+ async: false,
+ success: function (data) {
+ if (data != '-1') {
+
+ items[index].product_id = data.id;
+ items[index].name = data.name;
+ items[index].product_code = data.code;
+ items[index].product_id = data.id;
+ items[index].ecmvat_id = data.ecmvat_id;
+ items[index].ecmvat_value = data.ecmvat_value;
+ items[index].ecmvat_name = data.ecmvat_name;
+ items[index].product_ean = data.ean;
+ items[index].discount = data.discount;
+ items[index].product_ean2 = data.ean2;
+ items[index].unit_name = data.unit_name;
+ items[index].unit_id = data.unit_id;
+ items[index].price_start = data.price_start;
+ items[index].recipient_code = data.recipient_code;
+ items[index].stock_state = data.stock_state;
+ items[index].product_precision = data.unit_precision;
+ items[index].unit_precision = data.unit_precision;
+ items[index].product_is_consignment = data.is_consignment;
+ if ($("#searchInputPrice").val() != ''
+ && !isNaN(parseFloat(UnformatNumber($(
+ "#searchInputPrice").val()))))
+ items[index].price_start = $("#searchInputPrice").val();
+ if ($("#searchInputQty").val() != ''
+ && !isNaN(parseFloat(UnformatNumber($(
+ "#searchInputQty").val()))))
+ items[index].quantity = $("#searchInputQty").val();
+
+ }
+ },
+ data: params
+ });
AddSearchRecord();
FillTable(items);
calculateAll();
$('#searchResultDiv').html('');
$(".loading_panel").css("display", "none");
- $("#quantity_"+index).focus().select();
+ $("#quantity_" + index).focus().select();
}
function getItems(editview) {
@@ -376,29 +375,29 @@ function getItems(editview) {
if (isNaN(editview))
editview = true;
var params = {
- job : 'getItems',
- record : record,
+ job: 'getItems',
+ record: record,
};
$.ajax({
- type : "POST",
- url : ajax_url,
- dataType : "json",
- success : function(data) {
+ type: "POST",
+ url: ajax_url,
+ dataType: "json",
+ success: function (data) {
items = data;
if (editview)
FillTable(items, false);
else {
FillTable(items, true);
- var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
+ var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
for (var index = 0; index != count; index++) {
if (items[index].product_consignment_doc) {
- $('#product_code_'+index).parent().append($( ""+items[index].product_consignment_doc+"
" ));
+ $('#product_code_' + index).parent().append($("" + items[index].product_consignment_doc + "
"));
}
}
}
$(".loading_panel").css("display", "none");
},
- data : params
+ data: params
});
}
@@ -408,22 +407,22 @@ function DrawDetailSummary() {
html += ' ';
html += '| Suma dokumentu | ';
html += ' | ';
+ + $("#doc_total").val() + '\'>';
html += '
';
$("#result_table").html(html);
}
function generateNumber() {
var params = {
- job : 'generateNumber',
+ job: 'generateNumber',
stock: $("#stock_id").val(),
- date : $("#register_date").val(),
+ date: $("#register_date").val(),
};
$.ajax({
- type : "POST",
- url : ajax_url,
- dataType : "json",
- success : function(data) {
+ type: "POST",
+ url: ajax_url,
+ dataType: "json",
+ success: function (data) {
if (data == '-1') {
// try loading again
generateNumber();
@@ -433,56 +432,96 @@ function generateNumber() {
$(".loading_panel").css("display", "none");
}
},
- data : params
+ data: params
});
}
function getCategoriesList() {
var params = {
- job : 'getCategoriesList'
+ job: 'getCategoriesList'
};
$.ajax({
- type : "POST",
- url : ajax_url,
- dataType : "json",
- success : function(data) {
+ type: "POST",
+ url: ajax_url,
+ dataType: "json",
+ success: function (data) {
var html = '';
- $.each(data, function(index, value) {
+ $.each(data, function (index, value) {
html += '';
+ + '';
$("#productSearchCategory").html(html);
});
},
- data : params
+ data: params
});
}
function refreshStock(index) {
var params = {
- job : 'getStockState',
- id : $("#product_id_" + index).val(),
- stockId : $("#stock_id").val(),
+ job: 'getStockState',
+ id: $("#product_id_" + index).val(),
+ stockId: $("#stock_id").val(),
};
$.ajax({
- type : "POST",
- url : ajax_url,
- dataType : "json",
- async : false,
- success : function(data) {
+ type: "POST",
+ url: ajax_url,
+ dataType: "json",
+ async: false,
+ success: function (data) {
$("#stock_state_" + index).val(FormatNumber(data));
},
- data : params
+ data: params
});
}
-function checkProducts() {
+function refreshAllStocks(ids) {
+ return new Promise((resolve) => {
+ var params = {
+ job: "getStockStates",
+ ids: ids.join("|"),
+ stockId: $("#stock_id").val(),
+ };
+
+ $.ajax({
+ type: "POST",
+ url: ajax_url,
+ dataType: "json",
+ async: false,
+ success: function (data) {
+ resolve(data);
+ },
+ data: params
+ });
+ });
+}
+
+async function checkProducts() {
//var count = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
var count = items.length;
+
+ var ids = [];
+ for (var index = 0; index != count; index++) {
+ var id = $("#product_id_" + index).val();
+ if (id !== "") {
+ ids.push(id);
+ }
+ }
+ var states = [];
+ if (ids.length > 0) {
+ states = await refreshAllStocks(ids);
+ }
var error = false; // hope :)
for (var index = 0; index != count; index++) {
- if($("#product_id_" + index).val()!=''){
- refreshStock(index);
+ if ($("#product_id_" + index).val() != '') {
+ var prodId = $("#product_id_" + index).val();
+ var state = states.find(x => x.id === prodId);
+ if (state) {
+ $("#stock_state_" + index).val(FormatNumber(state.state, $("#product_precision_" + index).val()));
+ } else {
+ $("#stock_state_" + index).val(FormatNumber(0, $("#product_precision_" + index).val()));
+ }
+ //refreshStock(index);
var qty = UnformatNumber($("#quantity_" + index).val());
var cat_id = $("#product_category_id_" + index).val();
var con_qty = $("#product_consignment_qty_" + index).val();
@@ -491,17 +530,17 @@ function checkProducts() {
var price_old = UnformatNumber($("#price_old_" + index).val());
// refresh items array
items[index].quantity = qty;
- if ($('#product_is_consignment_' + index).val() != '1' && $('#product_consignment_id_' + index).val()=='' ) {
- con_qty=stock;
+ if ($('#product_is_consignment_' + index).val() != '1' && $('#product_consignment_id_' + index).val() == '') {
+ con_qty = stock;
}
items[index].price = UnformatNumber($("#price_" + index).val());
// przecena
if ($('#type').val() == '6ed5b076-ddd1-9809-b236-54e5b2bcbd97') {
- if($('#product_consignment_id_' + index).val()==''){
- error=true;
+ if ($('#product_consignment_id_' + index).val() == '') {
+ error = true;
alert("Można przecenić tylko konkretną pozycje!");
}
- if(qty<=0 || qty=0 || Math.abs(qty)>con_qty){
-
+ if (qty >= 0 || Math.abs(qty) > con_qty) {
+
error = true;
$("#quantity_" + index).css("color", "red");
@@ -523,7 +561,7 @@ function checkProducts() {
}
// korekta plus
if ($('#type').val() == '8a6b804b-fac7-5cc2-de19-54c209116b19') {
- if(qty<=0 || price_new<=0){
+ if (qty <= 0 || price_new <= 0) {
error = true;
$("#quantity_" + index).css("color", "red");
@@ -547,18 +585,18 @@ function getComponents(index) {
//var price = items[index].price;
var params = {
- job : 'getComponents',
- product_id : product_id,
+ job: 'getComponents',
+ product_id: product_id,
};
$.ajax({
- type : "POST",
- url : ajax_url,
- dataType : "json",
- async : false,
- success : function(data) {
+ type: "POST",
+ url: ajax_url,
+ dataType: "json",
+ async: false,
+ success: function (data) {
if (data.length > 0) {
items.splice(index, 1);
- $.each(data, function(index, value) {
+ $.each(data, function (index, value) {
var p = new Object();
p.product_id = value.id;
p.name = value.name;
@@ -568,17 +606,17 @@ function getComponents(index) {
p.unit_id = value.unit_id;
p.quantity = qty * parseInt(value.quantity);
p.product_category_id = value.product_category_id;
-
- if (p.product_category_id=='d7f876b0-1a3d-43a1-7c9b-511ba40df3d1')
+
+ if (p.product_category_id == 'd7f876b0-1a3d-43a1-7c9b-511ba40df3d1')
return;
items.push(p);
});
};
},
- data : params
+ data: params
});
FillTable(items);
- //getConsignmentsDiv(index);
+ //getConsignmentsDiv(index);
$(".loading_panel").css("display", "none");
}
diff --git a/modules/EcmStockDocCorrects/javascript/helper.php b/modules/EcmStockDocCorrects/javascript/helper.php
index 19cb4a6d..f6a30967 100755
--- a/modules/EcmStockDocCorrects/javascript/helper.php
+++ b/modules/EcmStockDocCorrects/javascript/helper.php
@@ -1,80 +1,88 @@
query("SELECT MAX(register_date) AS date FROM ecmstockdoccorrects WHERE stock_id='".$stock."' and deleted=0");
- $rul=$db->fetchByAssoc($uq);
- echo json_encode($rul['date']);
- return;
-}
-
-function generateNumber($mag, $date) {
- $data = array ();
- $data ['number'] = EcmStockDocCorrect::generateNumber ( $date );
- $data ['document_no'] = EcmStockDocCorrect::generateDocNumberStock ( $mag, $date );
-
- echo json_encode ( $data );
- unset ( $data );
+function getLastEcmStockDocCorrectsDate($stock)
+{
+ $db = $GLOBALS['db'];
+ $uq = $db->query("SELECT MAX(register_date) AS date FROM ecmstockdoccorrects WHERE stock_id='" . $stock . "' and deleted=0");
+ $rul = $db->fetchByAssoc($uq);
+ echo json_encode($rul['date']);
return;
}
-function searchProducts($searchKey, $searchCategory, $searchStock, $searchSort, $searchStockId) {
- $db = $GLOBALS ['db'];
+
+function generateNumber($mag, $date)
+{
+ $data = array();
+ $data['number'] = EcmStockDocCorrect::generateNumber($date);
+ $data['document_no'] = EcmStockDocCorrect::generateDocNumberStock($mag, $date);
+
+ 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')
@@ -83,116 +91,121 @@ function searchProducts($searchKey, $searchCategory, $searchStock, $searchSort,
$q .= "ORDER BY name";
else if ($searchSort == '4')
$q .= "ORDER BY name DESC";
-
+
$q .= " LIMIT 0,50";
-
- $res = $db->query ( $q );
- $result = array ();
-
+
+ $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'];
-
+
+ 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 );
+ $tmp['stock_state'] = EcmStockOperation::getStock($row['id'], $stock_id);
}
-
- if ($searchStock == '3' && $tmp ['stock_state'] == 0)
+
+ if ($searchStock == '3' && $tmp['stock_state'] == 0)
continue; // don't show null stock
-
- $result [] = $tmp;
+
+ $result[] = $tmp;
}
- echo json_encode ( $result );
+ 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.is_consignment, p.product_category_id,v.id as ecmvat_id, v.name as ecmvat_name, v.value as ecmvat_value FROM ecmproducts as p INNER JOIN ecmvats as v ON v.id=p.vat_id WHERE p.id='$id'" ) );
+function getProduct($id, $stockId)
+{
+ $db = $GLOBALS['db'];
+ $p = $db->fetchByAssoc($db->query("SELECT p.id, p.code, p.name, p.unit_id,p.is_consignment, p.product_category_id,v.id as ecmvat_id, v.name as ecmvat_name, v.value as ecmvat_value 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 );
+ $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 EcmStockDocCorrect ();
- $mm->retrieve ( $record );
- $pl = $mm->getPositionList ( true );
- unset ( $mm );
- echo json_encode ( $pl );
+function getItems($record)
+{
+ $mm = new EcmStockDocCorrect();
+ $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;
+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 );
+ echo json_encode($result);
return;
}
-function getTranslation($product_id, $language, $unit_id) {
- $db = $GLOBALS ['db'];
- $result = array ();
+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'] );
+ $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 );
+ $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 );
+ $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 ();
+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;
+ $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
+ $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;
+ 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
+ $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'
@@ -201,49 +214,54 @@ function getPricesInfo($product_id, $pricebook_id, $account_id) {
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;
+ LIMIT 0,1"));
+ if ($res && $res['subprice'] != '') {
+ $tmp = array();
+ $tmp['name'] = $res['document_no'];
+ $tmp['price'] = $res['subprice'];
+ $result[] = $tmp;
}
}
-
- echo json_encode ( $result );
+
+ echo json_encode($result);
return;
}
-function getStockArray($product_id) {
- $o = new EcmStockOperation ();
- echo json_encode ( $o->getStockArray ( $product_id ) );
- unset ( $o );
+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 );
+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 );
+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 ) );
+function getComponents($product_id)
+{
+ $p = new EcmProduct();
+ $p->retrieve($product_id);
+ echo json_encode($p->getPositionList(true));
return;
}
-function getConsignments($prod_id, $stock_id) {
- $documents_map = array (
- 'EcmStockDocIns' => 'PZ',
- 'EcmStockDocCorrects' => 'KS',
- 'EcmStockDocMoves' => 'MM',
- 'EcmStockDocInsideIns' => 'PW'
+function getConsignments($prod_id, $stock_id)
+{
+ $documents_map = array(
+ 'EcmStockDocIns' => 'PZ',
+ 'EcmStockDocCorrects' => 'KS',
+ 'EcmStockDocMoves' => 'MM',
+ 'EcmStockDocInsideIns' => 'PW'
);
-
- $db = $GLOBALS ['db'];
+
+ $db = $GLOBALS['db'];
$query = "
select i.id, i.parent_id, i.parent_type, i.parent_name, i.price, i.quantity as in_qty, ifnull(sum(o.quantity),0) as out_qty, p.unit_id, i.part_no
from ecmstockoperations as i
@@ -264,35 +282,36 @@ order by i.date_entered;
global $app_list_strings, $sugar_config;
while ($row = $db->fetchByAssoc($res)) {
$availability = (floatval($row['in_qty']) - floatval($row['out_qty']));
- if ($availability<=0) continue;
-
+ if ($availability <= 0) continue;
+
$tmp = array();
$tmp['operation_id'] = $row['id'];
- $tmp['document_no'] = $documents_map[$row['parent_type']].' '.$row['parent_name'];
+ $tmp['document_no'] = $documents_map[$row['parent_type']] . ' ' . $row['parent_name'];
$tmp['availability'] = $availability;
$tmp['parent_id'] = $row['parent_id'];
$tmp['parent_type'] = $row['parent_type'];
$tmp['price'] = $row['price'];
$tmp['part_no'] = $row['part_no'];
$tmp['unit'] = $app_list_strings['ecmproducts_unit_dom'][$row['unit_id']];
- $tmp ['precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$row ['unit_id']];
+ $tmp['precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$row['unit_id']];
$tmp['currency'] = $sugar_config['default_currency_iso4217'];
-
+
$result[] = $tmp;
}
echo json_encode($result);
return;
}
-function getConsignmentsDocs($prod_id, $stock_id) {
- $documents_map = array (
- 'EcmStockDocIns' => 'PZ',
- 'EcmStockDocCorrects' => 'KS',
- 'EcmStockDocMoves' => 'MM',
- 'EcmStockDocInsideIns' => 'PW'
- );
-
- $db = $GLOBALS ['db'];
- $query = "
+function getConsignmentsDocs($prod_id, $stock_id)
+{
+ $documents_map = array(
+ 'EcmStockDocIns' => 'PZ',
+ 'EcmStockDocCorrects' => 'KS',
+ 'EcmStockDocMoves' => 'MM',
+ 'EcmStockDocInsideIns' => 'PW'
+ );
+
+ $db = $GLOBALS['db'];
+ $query = "
select i.id, i.parent_id, i.parent_type, i.parent_name, i.price, i.quantity as in_qty, ifnull(sum(o.quantity),0) as out_qty, p.unit_id
from ecmstockoperations as i
left join ecmstockoperations as o
@@ -307,28 +326,40 @@ function getConsignmentsDocs($prod_id, $stock_id) {
group by i.id
order by i.date_entered;
";
- $res = $db->query ( $query );
- $result = array ();
- global $app_list_strings, $sugar_config;
- while ( $row = $db->fetchByAssoc ( $res ) ) {
- $availability = (floatval ( $row ['in_qty'] ) - floatval ( $row ['out_qty'] ));
- if ($availability <= 0)
- continue;
-
- $tmp = array ();
- $tmp ['operation_id'] = $row ['id'];
- $tmp ['part_no'] = $documents_map [$row ['parent_type']] . ' ' . $row ['parent_name'];
- $tmp ['availability'] = $availability;
- $tmp ['parent_id'] = $row ['parent_id'];
- $tmp ['parent_type'] = $row ['parent_type'];
- $tmp ['price'] = $row ['price'];
- $tmp ['unit'] = $app_list_strings ['ecmproducts_unit_dom'] [$row ['unit_id']];
- $tmp ['precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$row ['unit_id']];
- $tmp ['currency'] = $sugar_config ['default_currency_iso4217'];
-
- $result [] = $tmp;
- }
- echo json_encode ( $result );
- return;
+ $res = $db->query($query);
+ $result = array();
+ global $app_list_strings, $sugar_config;
+ while ($row = $db->fetchByAssoc($res)) {
+ $availability = (floatval($row['in_qty']) - floatval($row['out_qty']));
+ if ($availability <= 0)
+ continue;
+
+ $tmp = array();
+ $tmp['operation_id'] = $row['id'];
+ $tmp['part_no'] = $documents_map[$row['parent_type']] . ' ' . $row['parent_name'];
+ $tmp['availability'] = $availability;
+ $tmp['parent_id'] = $row['parent_id'];
+ $tmp['parent_type'] = $row['parent_type'];
+ $tmp['price'] = $row['price'];
+ $tmp['unit'] = $app_list_strings['ecmproducts_unit_dom'][$row['unit_id']];
+ $tmp['precision'] = $app_list_strings['ecmproducts_unit_dom_precision'][$row['unit_id']];
+ $tmp['currency'] = $sugar_config['default_currency_iso4217'];
+
+ $result[] = $tmp;
+ }
+ echo json_encode($result);
+ return;
+}
+function getStockStates($ids, $stock_id)
+{
+ $ids = explode("|", $ids);
+ // foreach ids
+ $res = array();
+ foreach ($ids as $id) {
+ $p = array();
+ $p['id'] = $id;
+ $p['state'] = EcmStockOperation::getStock($id, $stock_id);
+ $res[] = $p;
+ }
+ echo json_encode($res);
}
-
\ No newline at end of file
diff --git a/modules/EcmStockDocCorrects/metadata/editviewdefs.php b/modules/EcmStockDocCorrects/metadata/editviewdefs.php
index 7b85dabc..d8c3f9d3 100755
--- a/modules/EcmStockDocCorrects/metadata/editviewdefs.php
+++ b/modules/EcmStockDocCorrects/metadata/editviewdefs.php
@@ -52,7 +52,9 @@ $viewdefs ['EcmStockDocCorrects'] ['EditView'] = array (
'',
'',
'',
- ''
+ '',
+ '',
+ '',
),
),
'maxColumns' => '2',