Allegro returns - KS document

This commit is contained in:
Michał Zieliński
2025-05-29 17:43:29 +02:00
parent 204334acd6
commit 35632037d7
14 changed files with 881 additions and 526 deletions

View File

@@ -73,6 +73,9 @@ class EcmStockDocCorrect extends SugarBean {
var $modified_by_name;
var $assigned_user_name;
var $stock_id;
var $ecommerce_invoices;
var $pdf_text;
var $type;
// SUBPANELS RELATED
// MODULE OBJECT DETAILS
var $module_dir = "EcmStockDocCorrects";

View File

@@ -1,12 +1,12 @@
<?php
ini_set('display_errors',1);
ini_set('display_errors', 1);
error_reporting(LC_ALL);
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
die ( 'NotAValidEntryPoint' );
if (! defined('sugarEntry') || ! sugarEntry)
die('NotAValidEntryPoint');
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings, $current_user, $app_list_strings;
require_once ('modules/EcmStockDocCorrects/EcmStockDocCorrect.php');
require_once ('include/time.php');
require_once('modules/EcmStockDocCorrects/EcmStockDocCorrect.php');
require_once('include/time.php');
$db = $GLOBALS['db'];
@@ -19,47 +19,151 @@ echo '<script type="text/javascript" src="include/ECM/tablenavigator.js"></scrip
$new_number = false;
$duplicate = false;
$focus = new EcmStockDocCorrect ();
$focus = new EcmStockDocCorrect();
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();
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 = '<select id="stock" name="stock"><option value=""></option>';
$stock_body = '';
while ($row = $db->fetchByAssoc($res))
$stock_body.='<option value="'.$row['id'].'">'.$row['name'].'</option>';
$stock.=$stock_body.'</select><input id="stock_id" name="stock_id" type="hidden"/>';
while ($row = $db->fetchByAssoc($res)) {
if ($focus->stock_id != '' && $row['id'] == $focus->stock_id) {
$s = 'selected';
} else {
$s = '';
}
$stock_body .= '<option value="' . $row['id'] . '" ' . $s . '>' . $row['name'] . '</option>';
}
$stock .= $stock_body . '</select><input id="stock_id" name="stock_id" type="hidden" value="' . $focus->stock_id . '"/>';
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 '<link rel="stylesheet" type="text/css" href="modules/EcmStockDocCorrects/javascript/helper.css" media="screen" /><div class="loading_panel"></div>';
echo '<link rel="stylesheet" type="text/css" href="modules/EcmStockDocCorrects/javascript/helper.css" media="screen" /><div class="loading_panel"></div>';

View File

@@ -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');
?>

View File

@@ -1,6 +1,6 @@
<?php
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
die ( 'Not A Valid Entry Point' );
if (! defined('sugarEntry') || ! sugarEntry)
die('Not A Valid Entry Point');
/**
* ***************************************************************************
@@ -98,47 +98,52 @@ if (! defined ( 'sugarEntry' ) || ! sugarEntry)
* ******************************************************************************
*/
$json = getJSONobj ();
require_once ("modules/EcmStockDocCorrects/EcmStockDocCorrect.php");
require_once ('include/formbase.php');
$focus = new EcmStockDocCorrect ();
$json = getJSONobj();
require_once("modules/EcmStockDocCorrects/EcmStockDocCorrect.php");
require_once('include/formbase.php');
$focus = new EcmStockDocCorrect();
if (isset ( $_POST ['record'] ) && $_POST ['record'] != '') {
$focus->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 '
<script type="text/javascript">
window.open(window.open(\'index.php?module=EcmStockDocCorrects&action=createPDF&to_pdf=1&pdf_type=\'+$(\'#pdf_type\').val()+\'&record=' . $return_id . '\',\'_blank\'););
</script>
';
handleRedirect ( $return_id, 'EcmStockDocCorrects' );
?>
handleRedirect($return_id, 'EcmStockDocCorrects');

View File

@@ -0,0 +1,3 @@
<?php
require_once('modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.php');

View File

@@ -0,0 +1,81 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
$db = $GLOBALS['db'];
global $app_list_strings;
$smarty = new Sugar_Smarty();
if (isset($_REQUEST['date_from'])) {
$DEBUG = $_REQUEST['debug'] == '1' ? true : false;
$smarty->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;
}

View File

@@ -0,0 +1,69 @@
<!-- HEADER -->
<table id="tableMenu" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<img src="themes/Sugar5/images/CaseReports.gif" style="margin-top: 3px; margin-right: 3px;" width="16"
height="16">
</td>
<td>
<h2>ZS E-Commerce</h2>
</td>
</tr>
</table>
<!-- FILTERS -->
<form action="index.php" method="get">
<input type="hidden" name="module" value="EcmStockDocCorrects">
<input type="hidden" name="action" value="eCommerceKS">
<table class="tabForm" cellspacing="0" cellpadding="0" style="border-top: 0px none; margin-bottom: 4px;width:100%">
<tbody>
<tr>
<td width="5%">Zakres dat:</td>
<td width="10%">
<input id="date_from" name="date_from" type="text" maxlength="10" size="11" tabindex="" title=""
value="{$date_from}" autocomplete="off">
<img id="date_from_trigger" src="themes/default/images/jscalendar.gif">
<script language="JavaScript" type="text/javascript">
Calendar.setup({ ldelim }
inputField: "date_from",
daFormat: "%d.%m.%Y",
button: "date_from_trigger",
singleClick: true,
dateStr: "",
step: 1
{ rdelim }
);
</script>
</td>
<td>
<input id="date_to" name="date_to" type="text" maxlength="10" size="11" tabindex="" title=""
value="{$date_to}" autocomplete="off">
<img id="date_to_trigger" src="themes/default/images/jscalendar.gif">
<script language="JavaScript" type="text/javascript">
Calendar.setup({ ldelim }
inputField: "date_to",
daFormat: "%d.%m.%Y",
button: "date_to_trigger",
singleClick: true,
dateStr: "",
step: 1
{ rdelim }
);
</script>
</td>
<td></td>
<td></td>
<td>
</td>
</tr>
</tbody>
</table>
<input type="submit" class="button" value="Filtruj">
</form>
<hr>
KS zbiorcza dla FVKOR:<br> {$invoicesNo}
<br><br>
<input title="Wystaw KS" class="button primary" type="button" name="Edit" id="edit_button" value="Wystaw KS"
onclick="window.open('index.php?module=EcmStockDocCorrects&action=EditView&ecommerceKS={$sessionId}')">

View File

@@ -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);
}

View File

@@ -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('<div id="onlyRemoveDif_'+index+'"><p style="text-align:right">(Różnica: '+FormatNumber(total-total2)+')<input type="hidden" id="diff_this_'+index+'" value="'+FormatNumber(total-total2)+'"></p></div>');
}
if ($('#type').val() == '6ed5b076-ddd1-9809-b236-54e5b2bcbd97') {
$('#onlyRemoveDif_' + index).remove();
$('#unit_name_' + index).parent().append('<div id="onlyRemoveDif_' + index + '"><p style="text-align:right">(Różnica: ' + FormatNumber(total - total2) + ')<input type="hidden" id="diff_this_' + index + '" value="' + FormatNumber(total - total2) + '"></p></div>');
}
// 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 = '<link rel="stylesheet" type="text/css" href="modules/EcmQuotes/MyTable.css" />';
html += '<div style="width:100%;border: 1px solid rgb(48,192,255);background-color:white;overflow:auto;" id="'
+ itemsTable + 'DIV">';
+ itemsTable + 'DIV">';
html += '<table class="positions" style="width:100%;" id="' + itemsTable
+ '_T">';
+ '_T">';
html += '<thead id="head">';
html += '<tr id="tr">';
// 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 += '<td width="' + column.width + '%" style="'+hide+'">' + column.label + '</td>';
html += '<td width="' + column.width + '%" style="' + hide + '">' + column.label + '</td>';
});
html += '</tr></thead><tbody></tbody></table>';
html += '</div><br>';
@@ -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($( "<p>"+items[index].product_consignment_doc+"</p>" ));
$('#product_code_' + index).parent().append($("<p>" + items[index].product_consignment_doc + "</p>"));
}
}
}
$(".loading_panel").css("display", "none");
},
data : params
data: params
});
}
@@ -408,22 +407,22 @@ function DrawDetailSummary() {
html += '<tr id="subtotal_tr"> ';
html += '<td class="positionsLabel" style="border-top:0px;">Suma dokumentu</td>';
html += '<td class="positionsField" style="border-top:0px;"><input type="text" style="border:0px;font-weight:900;width:100%;text-align:right;" readonly="readonly" name="t_netto" id="t_netto" value=\''
+ $("#doc_total").val() + '\'></td>';
+ $("#doc_total").val() + '\'></td>';
html += '</tr>';
$("#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 = '<option value=""></option>';
$.each(data, function(index, value) {
$.each(data, function (index, value) {
html += '<option value="' + value.id + '">' + value.name
+ '</option>';
+ '</option>';
$("#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<con_qty || price_new==price_old || price_new<=0){
if (qty <= 0 || qty < con_qty || price_new == price_old || price_new <= 0) {
error = true;
$("#quantity_" + index).css("color", "red");
@@ -510,10 +549,9 @@ function checkProducts() {
}
}
// korekta minus
console.log(qty+' '+con_qty+' '+Math.abs(qty));
if ($('#type').val() == '7bb903d0-c296-7d1b-6e50-54c209e30850') {
if(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");
}

View File

@@ -1,80 +1,88 @@
<?php
if (! defined ( 'sugarEntry' ) || ! sugarEntry)
die ( '-1' );
if (! $_POST ['job'] || $_POST ['job'] == '')
die ( '-1' );
switch ($_POST ['job']) {
case 'getParentInfo' :
getParentInfo ( $_POST ['id'], $_POST ['type'] );
if (! defined('sugarEntry') || ! sugarEntry)
die('-1');
if (! $_POST['job'] || $_POST['job'] == '')
die('-1');
switch ($_POST['job']) {
case 'getParentInfo':
getParentInfo($_POST['id'], $_POST['type']);
break;
case 'generateNumber' :
generateNumber ( $_POST ['stock'], $_POST ['date'] );
case 'generateNumber':
generateNumber($_POST['stock'], $_POST['date']);
break;
case 'searchProducts' :
searchProducts ( $_POST ['searchKey'], $_POST ['searchCategory'], $_POST ['searchStock'], $_POST ['searchSort'], $_POST ['searchStockId'] );
case 'searchProducts':
searchProducts($_POST['searchKey'], $_POST['searchCategory'], $_POST['searchStock'], $_POST['searchSort'], $_POST['searchStockId']);
break;
case 'getProduct' :
getProduct ( $_POST ['id'], $_POST ['stockId'] );
case 'getProduct':
getProduct($_POST['id'], $_POST['stockId']);
break;
case 'getItems' :
getItems ( $_POST ['record'] );
case 'getItems':
getItems($_POST['record']);
break;
case 'getCategoriesList' :
getCategoriesList ();
case 'getCategoriesList':
getCategoriesList();
break;
case 'getTranslation' :
getTranslation ( $_POST ['product_id'], $_POST ['language'], $_REQUEST ['unit_id'] );
case 'getTranslation':
getTranslation($_POST['product_id'], $_POST['language'], $_REQUEST['unit_id']);
break;
case 'getPricesInfo' :
getPricesInfo ( $_POST ['product_id'], $_POST ['pricebook_id'], $_POST ['account_id'] );
case 'getPricesInfo':
getPricesInfo($_POST['product_id'], $_POST['pricebook_id'], $_POST['account_id']);
break;
case 'getStockArray' :
getStockArray ( $_POST ['product_id'] );
case 'getStockArray':
getStockArray($_POST['product_id']);
break;
case 'getPurchaseArray' :
getPurchaseArray ( $_POST ['product_id'] );
case 'getPurchaseArray':
getPurchaseArray($_POST['product_id']);
break;
case 'getStockState' :
getStockState ( $_POST ['id'], $_POST ['stockId'] );
case 'getStockState':
getStockState($_POST['id'], $_POST['stockId']);
break;
case 'getComponents' :
getComponents ( $_POST ['product_id'] );
case 'getComponents':
getComponents($_POST['product_id']);
break;
case 'getConsignments' :
getConsignments ( $_POST ['prod_id'], $_REQUEST['stock_id'] );
case 'getConsignments':
getConsignments($_POST['prod_id'], $_REQUEST['stock_id']);
break;
case 'getConsignmentsDocs':
getConsignmentsDocs($_POST['prod_id'], $_REQUEST['stock_id']);
break;
case 'getLastEcmStockDocCorrectsDate':
getLastEcmStockDocCorrectsDate($_POST['stock']);
break;
case 'getStockStates':
getStockStates($_POST['ids'], $_POST['stockId']);
break;
case 'getConsignmentsDocs' :
getConsignmentsDocs ( $_POST ['prod_id'], $_REQUEST ['stock_id'] );
break;
case 'getLastEcmStockDocCorrectsDate' : getLastEcmStockDocCorrectsDate($_POST['stock']); break;
}
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 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);
}

View File

@@ -52,7 +52,9 @@ $viewdefs ['EcmStockDocCorrects'] ['EditView'] = array (
'<input type="hidden" id="total_brutto" name="total_brutto" value=\'{$fields.total_brutto.value}\'>',
'<input type="hidden" id="status" name="status" value=\'\'>',
'<input type="hidden" id="duplicate" name="duplicate" value=\'{$DUPLICATE}\'>',
'<input type="hidden" id="position_list" name="position_list" value="">'
'<input type="hidden" id="position_list" name="position_list" value="">',
'<input type="hidden" id="ecommerce_products" name="ecommerce_products" value=\'{$ECOMMERCE_PRODUCTS}\'>',
'<input type="hidden" id="ecommerce_invoices" name="ecommerce_invoices" value=\'{$ECOMMERCE_INVOICES}\'>',
),
),
'maxColumns' => '2',