Allegro returns - KS document
This commit is contained in:
@@ -342,3 +342,4 @@ if ($_SERVER['HTTP_HOST'] == 'localhost:8080') {
|
|||||||
$sugar_config['dbconfig']['db_user_name'] = 'root';
|
$sugar_config['dbconfig']['db_user_name'] = 'root';
|
||||||
$sugar_config['dbconfig']['db_password'] = 'rootpassword';
|
$sugar_config['dbconfig']['db_password'] = 'rootpassword';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
13
index.php
13
index.php
@@ -1,7 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
if(!defined('sugarEntry'))define('sugarEntry', true);
|
if(!defined('sugarEntry'))define('sugarEntry', true);
|
||||||
error_reporting(E_ERROR);
|
|
||||||
//ini_set('display_errors', 1);
|
$SHOW_ERRORS = false; // set to true to show errors, false to hide them
|
||||||
|
if ($SHOW_ERRORS) {
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
|
||||||
|
} else {
|
||||||
|
ini_set('display_errors', 0);
|
||||||
|
ini_set('display_startup_errors', 0);
|
||||||
|
error_reporting(0);
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
* SugarCRM is a customer relationship management program developed by
|
* SugarCRM is a customer relationship management program developed by
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ class EcmStockDocCorrect extends SugarBean {
|
|||||||
var $modified_by_name;
|
var $modified_by_name;
|
||||||
var $assigned_user_name;
|
var $assigned_user_name;
|
||||||
var $stock_id;
|
var $stock_id;
|
||||||
|
var $ecommerce_invoices;
|
||||||
|
var $pdf_text;
|
||||||
|
var $type;
|
||||||
// SUBPANELS RELATED
|
// SUBPANELS RELATED
|
||||||
// MODULE OBJECT DETAILS
|
// MODULE OBJECT DETAILS
|
||||||
var $module_dir = "EcmStockDocCorrects";
|
var $module_dir = "EcmStockDocCorrects";
|
||||||
|
|||||||
@@ -20,20 +20,122 @@ echo '<script type="text/javascript" src="include/ECM/tablenavigator.js"></scrip
|
|||||||
$new_number = false;
|
$new_number = false;
|
||||||
$duplicate = 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") {
|
if (isset($_REQUEST['record']) && $_REQUEST['isDuplicate'] == "false") {
|
||||||
$focus->retrieve($_REQUEST['record']);
|
$focus->retrieve($_REQUEST['record']);
|
||||||
if (isset($focus->id) && $focus->id != '') {
|
if (isset($focus->id) && $focus->id != '') {
|
||||||
$focus->format_all_fields();
|
$focus->format_all_fields();
|
||||||
}
|
}
|
||||||
}
|
} else if ($_REQUEST['isDuplicate'] == "true") {
|
||||||
else if ($_REQUEST['isDuplicate']=="true") {
|
|
||||||
$new_number = true;
|
$new_number = true;
|
||||||
$duplicate = true;
|
$duplicate = true;
|
||||||
//get data
|
//get data
|
||||||
$focus->retrieve($_REQUEST['return_id']);
|
$focus->retrieve($_REQUEST['return_id']);
|
||||||
|
} else if (isset($_REQUEST['ecommerceKS'])) {
|
||||||
|
$new_number = true;
|
||||||
|
$focus->stock_id = 'cf16804e-f698-5e09-2da3-6553588446ae';
|
||||||
|
$focus->register_date = date("d.m.Y");
|
||||||
|
$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'];
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
$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;
|
$new_number = true;
|
||||||
//dates
|
//dates
|
||||||
$focus->stock_id = $current_user->stock_id;
|
$focus->stock_id = $current_user->stock_id;
|
||||||
@@ -45,14 +147,16 @@ else {
|
|||||||
$res = $db->query("SELECT id, name FROM ecmstocks WHERE deleted = '0' ORDER BY name");
|
$res = $db->query("SELECT id, name FROM ecmstocks WHERE deleted = '0' ORDER BY name");
|
||||||
$stock = '<select id="stock" name="stock"><option value=""></option>';
|
$stock = '<select id="stock" name="stock"><option value=""></option>';
|
||||||
$stock_body = '';
|
$stock_body = '';
|
||||||
while ($row = $db->fetchByAssoc($res))
|
while ($row = $db->fetchByAssoc($res)) {
|
||||||
$stock_body.='<option value="'.$row['id'].'">'.$row['name'].'</option>';
|
if ($focus->stock_id != '' && $row['id'] == $focus->stock_id) {
|
||||||
$stock.=$stock_body.'</select><input id="stock_id" name="stock_id" type="hidden"/>';
|
$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->module = 'EcmStockDocCorrects';
|
||||||
$edit->bean = $focus;
|
$edit->bean = $focus;
|
||||||
$edit->tplFile = 'include/ECM/EcmViews/EditView/Tabs/EditView.tpl';
|
$edit->tplFile = 'include/ECM/EcmViews/EditView/Tabs/EditView.tpl';
|
||||||
|
|||||||
@@ -98,9 +98,8 @@ if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
|||||||
|
|
||||||
global $mod_strings, $current_user;
|
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');
|
$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');
|
||||||
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=eCommerceKS", "Utwórz zwrot E-Commerce","EcmStockDocCorrects", 'EcmStockDocCorrects');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,12 @@ $focus->save ( $check_notify );
|
|||||||
|
|
||||||
$return_id = $focus->id;
|
$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 $return_id;
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
@@ -141,4 +147,3 @@ echo $return_id;
|
|||||||
</script>
|
</script>
|
||||||
';
|
';
|
||||||
handleRedirect($return_id, 'EcmStockDocCorrects');
|
handleRedirect($return_id, 'EcmStockDocCorrects');
|
||||||
?>
|
|
||||||
3
modules/EcmStockDocCorrects/eCommerceKS.php
Normal file
3
modules/EcmStockDocCorrects/eCommerceKS.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.php');
|
||||||
81
modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.php
Normal file
81
modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
69
modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl
Normal file
69
modules/EcmStockDocCorrects/eCommerceKS/eCommerceKS.tpl
Normal 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}')">
|
||||||
@@ -23,6 +23,10 @@ $(document).ready(
|
|||||||
if (($("#new_number").val() == true)
|
if (($("#new_number").val() == true)
|
||||||
&& ($("#duplicate").val() != true)) {
|
&& ($("#duplicate").val() != true)) {
|
||||||
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocCorrects');
|
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocCorrects');
|
||||||
|
var ecp = $("#ecommerce_products").val();
|
||||||
|
if (ecp && ecp.length > 0) {
|
||||||
|
loadECommerceProducts(ecp);
|
||||||
|
}
|
||||||
} else if (($("#new_number").val() == true)
|
} else if (($("#new_number").val() == true)
|
||||||
&& ($("#duplicate").val() == true)) {
|
&& ($("#duplicate").val() == true)) {
|
||||||
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocCorrects');
|
EcmDocumentNumberGenerator_getNumberTemplate('document_no', 'EcmStockDocCorrects');
|
||||||
@@ -121,3 +125,9 @@ function lockEnter() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadECommerceProducts(ecp) {
|
||||||
|
var products = JSON.parse(ecp);
|
||||||
|
items = products;
|
||||||
|
FillTable(products);
|
||||||
|
}
|
||||||
|
|||||||
@@ -293,7 +293,6 @@ function addProducts() {
|
|||||||
"#searchInputQty").val()))))
|
"#searchInputQty").val()))))
|
||||||
p.quantity = $("#searchInputQty").val();
|
p.quantity = $("#searchInputQty").val();
|
||||||
items.push(p);
|
items.push(p);
|
||||||
console.log(p);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data: params
|
data: params
|
||||||
@@ -476,13 +475,53 @@ function refreshStock(index) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = $('#' + itemsTable + '_T tr').length - 1; // -1 - thead row
|
||||||
var count = items.length;
|
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 :)
|
var error = false; // hope :)
|
||||||
for (var index = 0; index != count; index++) {
|
for (var index = 0; index != count; index++) {
|
||||||
if ($("#product_id_" + index).val() != '') {
|
if ($("#product_id_" + index).val() != '') {
|
||||||
refreshStock(index);
|
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 qty = UnformatNumber($("#quantity_" + index).val());
|
||||||
var cat_id = $("#product_category_id_" + index).val();
|
var cat_id = $("#product_category_id_" + index).val();
|
||||||
var con_qty = $("#product_consignment_qty_" + index).val();
|
var con_qty = $("#product_consignment_qty_" + index).val();
|
||||||
@@ -510,7 +549,6 @@ function checkProducts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// korekta minus
|
// korekta minus
|
||||||
console.log(qty+' '+con_qty+' '+Math.abs(qty));
|
|
||||||
if ($('#type').val() == '7bb903d0-c296-7d1b-6e50-54c209e30850') {
|
if ($('#type').val() == '7bb903d0-c296-7d1b-6e50-54c209e30850') {
|
||||||
if (qty >= 0 || Math.abs(qty) > con_qty) {
|
if (qty >= 0 || Math.abs(qty) > con_qty) {
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,16 @@ switch ($_POST ['job']) {
|
|||||||
case 'getConsignmentsDocs':
|
case 'getConsignmentsDocs':
|
||||||
getConsignmentsDocs($_POST['prod_id'], $_REQUEST['stock_id']);
|
getConsignmentsDocs($_POST['prod_id'], $_REQUEST['stock_id']);
|
||||||
break;
|
break;
|
||||||
case 'getLastEcmStockDocCorrectsDate' : getLastEcmStockDocCorrectsDate($_POST['stock']); break;
|
case 'getLastEcmStockDocCorrectsDate':
|
||||||
|
getLastEcmStockDocCorrectsDate($_POST['stock']);
|
||||||
|
break;
|
||||||
|
case 'getStockStates':
|
||||||
|
getStockStates($_POST['ids'], $_POST['stockId']);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLastEcmStockDocCorrectsDate($stock){
|
function getLastEcmStockDocCorrectsDate($stock)
|
||||||
|
{
|
||||||
$db = $GLOBALS['db'];
|
$db = $GLOBALS['db'];
|
||||||
$uq = $db->query("SELECT MAX(register_date) AS date FROM ecmstockdoccorrects WHERE stock_id='" . $stock . "' and deleted=0");
|
$uq = $db->query("SELECT MAX(register_date) AS date FROM ecmstockdoccorrects WHERE stock_id='" . $stock . "' and deleted=0");
|
||||||
$rul = $db->fetchByAssoc($uq);
|
$rul = $db->fetchByAssoc($uq);
|
||||||
@@ -57,7 +63,8 @@ function getLastEcmStockDocCorrectsDate($stock){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateNumber($mag, $date) {
|
function generateNumber($mag, $date)
|
||||||
|
{
|
||||||
$data = array();
|
$data = array();
|
||||||
$data['number'] = EcmStockDocCorrect::generateNumber($date);
|
$data['number'] = EcmStockDocCorrect::generateNumber($date);
|
||||||
$data['document_no'] = EcmStockDocCorrect::generateDocNumberStock($mag, $date);
|
$data['document_no'] = EcmStockDocCorrect::generateDocNumberStock($mag, $date);
|
||||||
@@ -66,7 +73,8 @@ function generateNumber($mag, $date) {
|
|||||||
unset($data);
|
unset($data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function searchProducts($searchKey, $searchCategory, $searchStock, $searchSort, $searchStockId) {
|
function searchProducts($searchKey, $searchCategory, $searchStock, $searchSort, $searchStockId)
|
||||||
|
{
|
||||||
$db = $GLOBALS['db'];
|
$db = $GLOBALS['db'];
|
||||||
$q = "SELECT id, code, name FROM ecmproducts WHERE
|
$q = "SELECT id, code, name FROM ecmproducts WHERE
|
||||||
(UPPER(code) LIKE '%$searchKey%' OR
|
(UPPER(code) LIKE '%$searchKey%' OR
|
||||||
@@ -110,7 +118,8 @@ function searchProducts($searchKey, $searchCategory, $searchStock, $searchSort,
|
|||||||
echo json_encode($result);
|
echo json_encode($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getProduct($id, $stockId) {
|
function getProduct($id, $stockId)
|
||||||
|
{
|
||||||
$db = $GLOBALS['db'];
|
$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'"));
|
$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;
|
global $app_list_strings;
|
||||||
@@ -121,7 +130,8 @@ function getProduct($id, $stockId) {
|
|||||||
echo json_encode($p);
|
echo json_encode($p);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getItems($record) {
|
function getItems($record)
|
||||||
|
{
|
||||||
$mm = new EcmStockDocCorrect();
|
$mm = new EcmStockDocCorrect();
|
||||||
$mm->retrieve($record);
|
$mm->retrieve($record);
|
||||||
$pl = $mm->getPositionList(true);
|
$pl = $mm->getPositionList(true);
|
||||||
@@ -129,7 +139,8 @@ function getItems($record) {
|
|||||||
echo json_encode($pl);
|
echo json_encode($pl);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getCategoriesList() {
|
function getCategoriesList()
|
||||||
|
{
|
||||||
$db = $GLOBALS['db'];
|
$db = $GLOBALS['db'];
|
||||||
$res = $db->query("SELECT id, name FROM ecmproductcategories WHERE deleted='0'");
|
$res = $db->query("SELECT id, name FROM ecmproductcategories WHERE deleted='0'");
|
||||||
$result = array();
|
$result = array();
|
||||||
@@ -142,7 +153,8 @@ function getCategoriesList() {
|
|||||||
echo json_encode($result);
|
echo json_encode($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getTranslation($product_id, $language, $unit_id) {
|
function getTranslation($product_id, $language, $unit_id)
|
||||||
|
{
|
||||||
$db = $GLOBALS['db'];
|
$db = $GLOBALS['db'];
|
||||||
$result = array();
|
$result = array();
|
||||||
if ($language == 'en_us') {
|
if ($language == 'en_us') {
|
||||||
@@ -161,7 +173,8 @@ function getTranslation($product_id, $language, $unit_id) {
|
|||||||
echo json_encode($result);
|
echo json_encode($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getPricesInfo($product_id, $pricebook_id, $account_id) {
|
function getPricesInfo($product_id, $pricebook_id, $account_id)
|
||||||
|
{
|
||||||
$db = $GLOBALS['db'];
|
$db = $GLOBALS['db'];
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
@@ -213,29 +226,34 @@ function getPricesInfo($product_id, $pricebook_id, $account_id) {
|
|||||||
echo json_encode($result);
|
echo json_encode($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getStockArray($product_id) {
|
function getStockArray($product_id)
|
||||||
|
{
|
||||||
$o = new EcmStockOperation();
|
$o = new EcmStockOperation();
|
||||||
echo json_encode($o->getStockArray($product_id));
|
echo json_encode($o->getStockArray($product_id));
|
||||||
unset($o);
|
unset($o);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getPurchaseArray($product_id) {
|
function getPurchaseArray($product_id)
|
||||||
|
{
|
||||||
$o = new EcmStockOperation();
|
$o = new EcmStockOperation();
|
||||||
echo json_encode($o->getPurchaseArray($product_id));
|
echo json_encode($o->getPurchaseArray($product_id));
|
||||||
unset($o);
|
unset($o);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getStockState($id, $stock_id) {
|
function getStockState($id, $stock_id)
|
||||||
|
{
|
||||||
echo EcmStockOperation::getStock($id, $stock_id);
|
echo EcmStockOperation::getStock($id, $stock_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getComponents($product_id) {
|
function getComponents($product_id)
|
||||||
|
{
|
||||||
$p = new EcmProduct();
|
$p = new EcmProduct();
|
||||||
$p->retrieve($product_id);
|
$p->retrieve($product_id);
|
||||||
echo json_encode($p->getPositionList(true));
|
echo json_encode($p->getPositionList(true));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getConsignments($prod_id, $stock_id) {
|
function getConsignments($prod_id, $stock_id)
|
||||||
|
{
|
||||||
$documents_map = array(
|
$documents_map = array(
|
||||||
'EcmStockDocIns' => 'PZ',
|
'EcmStockDocIns' => 'PZ',
|
||||||
'EcmStockDocCorrects' => 'KS',
|
'EcmStockDocCorrects' => 'KS',
|
||||||
@@ -283,7 +301,8 @@ order by i.date_entered;
|
|||||||
echo json_encode($result);
|
echo json_encode($result);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function getConsignmentsDocs($prod_id, $stock_id) {
|
function getConsignmentsDocs($prod_id, $stock_id)
|
||||||
|
{
|
||||||
$documents_map = array(
|
$documents_map = array(
|
||||||
'EcmStockDocIns' => 'PZ',
|
'EcmStockDocIns' => 'PZ',
|
||||||
'EcmStockDocCorrects' => 'KS',
|
'EcmStockDocCorrects' => 'KS',
|
||||||
@@ -331,4 +350,16 @@ function getConsignmentsDocs($prod_id, $stock_id) {
|
|||||||
echo json_encode($result);
|
echo json_encode($result);
|
||||||
return;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -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="total_brutto" name="total_brutto" value=\'{$fields.total_brutto.value}\'>',
|
||||||
'<input type="hidden" id="status" name="status" value=\'\'>',
|
'<input type="hidden" id="status" name="status" value=\'\'>',
|
||||||
'<input type="hidden" id="duplicate" name="duplicate" value=\'{$DUPLICATE}\'>',
|
'<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',
|
'maxColumns' => '2',
|
||||||
|
|||||||
Reference in New Issue
Block a user