171 lines
6.5 KiB
PHP
Executable File
171 lines
6.5 KiB
PHP
Executable File
<?php
|
|
if (! defined('sugarEntry') || ! sugarEntry)
|
|
die('NotAValidEntryPoint');
|
|
|
|
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings, $current_user, $app_list_strings;
|
|
$db = $GLOBALS['db'];
|
|
require_once('modules/EcmSales/EcmSale.php');
|
|
require_once('include/time.php');
|
|
|
|
//add jquery
|
|
echo '<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.css"/>';
|
|
echo '<link rel="stylesheet" type="text/css" href="include/jQuery/jquery-ui/themes/base/jquery-ui.css"/>';
|
|
echo '<link rel="stylesheet" type="text/css" href="modules/EcmSales/css/autocomplete.css"/>';
|
|
echo '<script type="text/javascript"
|
|
src="include/jQuery/jquery-2.1.0.min.js"></script>';
|
|
echo '<script type="text/javascript"
|
|
src="include/jQuery/jquery-table/jquery.appendGrid-1.3.1.js"></script>';
|
|
echo '<script type="text/javascript"
|
|
src="include/jQuery/jquery-ui/ui/jquery-ui.js"></script>';
|
|
echo '<script type="text/javascript"
|
|
src="modules/EcmSales/javascript/searchcolumndefs.js"></script>';
|
|
echo '<script type="text/javascript"
|
|
src="include/ECM/tablenavigator.js"></script>';
|
|
echo '<script type="text/javascript"
|
|
src="include/ECM/SearchProductTable.js"></script>';
|
|
|
|
|
|
// $cq=$current_user->getPreference('confirm_quotes');
|
|
$new_number = false;
|
|
$duplicate = false;
|
|
$focus = new EcmSale();
|
|
|
|
require_once('include/MVC/View/SugarView.php');
|
|
require_once('modules/EcmSales/views/EditView/view.edit.ecmsales.php');
|
|
$edit = new ViewEditEcmSales();
|
|
$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();
|
|
}
|
|
} else if (isset($_REQUEST['ecommerceZS'])) {
|
|
$new_number = true;
|
|
$focus->stock_id = 'cf16804e-f698-5e09-2da3-6553588446ae';
|
|
$focus->register_date = date("d.m.Y");
|
|
$focus->parent_id = 'b5612f7f-85e5-f930-293e-62cead14b424';
|
|
$db = $GLOBALS['db'];
|
|
$invoiceIds = $_SESSION[$_REQUEST['ecommerceZS']];
|
|
$i = $db->fetchByAssoc($db->query("SELECT register_date FROM ecommerce_invoices WHERE id = '$invoiceIds[0]'"));
|
|
$focus->delivery_date = date("d.m.Y");
|
|
$focus->payment_date = date("d.m.Y");
|
|
$focus->send_date = date("d.m.Y");
|
|
$focus->payment_date_days = 0;
|
|
$focus->status = 's30';
|
|
$focus->order_source = 'baselinker';
|
|
|
|
$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')
|
|
GROUP BY ip.ecmproduct_id, ip.price_netto;
|
|
";
|
|
$res = $db->query($query);
|
|
$products = array();
|
|
$position = 1;
|
|
while ($row = $db->fetchByAssoc($res)) {
|
|
$products[] = array(
|
|
'position' => $position++,
|
|
'product_id' => $row['ecmproduct_id'],
|
|
'product_code' => $row['code'],
|
|
'name' => $row['name'],
|
|
'quantity' => $row['quantity'],
|
|
'price_start' => $row['price_netto'],
|
|
'price_netto' => $row['price_netto'],
|
|
'unit_id' => $row['unit_id'],
|
|
'unit_name' => $app_list_strings['ecmproducts_unit_dom'][$row['unit_id']],
|
|
'ecmvat_name' => '23%',
|
|
'ecmvat_value' => 23,
|
|
'ecmvat_id' => '28079566-b825-e38f-9993-4ccc7b781de5',
|
|
);
|
|
}
|
|
$edit->ss->assign('ECOMMERCE_PRODUCTS', json_encode($products));
|
|
$edit->ss->assign('ECOMMERCE_INVOICES', json_encode($invoiceIds));
|
|
|
|
$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 if ($_REQUEST['isDuplicate'] == "true") {
|
|
$new_number = true;
|
|
$duplicate = true;
|
|
//get data
|
|
$focus->retrieve($_REQUEST['return_id']);
|
|
$focus->id = null;
|
|
$focus->register_date = date("d.m.Y");
|
|
$focus->delivery_date = null;
|
|
$focus->send_date = null;
|
|
$focus->assigned_user_name = $current_user->full_name;
|
|
$focus->assigned_user_id = $current_user->id;
|
|
$focus->status = 's10';
|
|
} else if ($_REQUEST['ecmquote_id']) {
|
|
$new_number = true;
|
|
$ecmquote_id = $_REQUEST['ecmquote_id'];
|
|
$ecmquote = true;
|
|
$q = new EcmQuote();
|
|
//get data
|
|
$q->retrieve($_REQUEST['ecmquote_id']);
|
|
$focus->parent_id = $q->parent_id;
|
|
$focus->parent_name = $q->parent_name;
|
|
$focus->register_date = date("d.m.Y");
|
|
$focus->position_list = $q->getPositionList(true);
|
|
} else {
|
|
$new_number = true;
|
|
$focus->stock_id = $current_user->stock_id;
|
|
$focus->register_date = date("d.m.Y");
|
|
$focus->delivery_date = date("d.m.Y");
|
|
//for subpanels??
|
|
if (isset($_REQUEST['contact_id']) && $_REQUEST['contact_id'] != '' && isset($_REQUEST['contact_name']) && $_REQUEST['contact_name'] != '') {
|
|
$_REQUEST['parent_type'] = 'Contacts';
|
|
$_REQUEST['parent_name'] = $_REQUEST['contact_name'];
|
|
$_REQUEST['parent_id'] = $_REQUEST['contact_id'];
|
|
$OPT['check_parent_id'] = false;
|
|
}
|
|
|
|
if (isset($_REQUEST['account_id']) && $_REQUEST['account_id'] != '' && isset($_REQUEST['account_name']) && $_REQUEST['account_name'] != '') {
|
|
$_REQUEST['parent_type'] = 'Accounts';
|
|
$_REQUEST['parent_name'] = $_REQUEST['account_name'];
|
|
$_REQUEST['parent_id'] = $_REQUEST['account_id'];
|
|
$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)) {
|
|
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 . '"/>';
|
|
//includ OO VAT
|
|
$v = new EcmVat();
|
|
$v->retrieve('a8c52d5e-15df-2a13-c934-5578307bebd2');
|
|
$oo = array('id' => 'a8c52d5e-15df-2a13-c934-5578307bebd2', 'name' => $v->name, 'value' => $v->value);
|
|
echo '<script> var OO=\'' . json_encode($oo) . '\'</script>';
|
|
$edit->module = 'EcmSales';
|
|
$edit->bean = $focus;
|
|
$edit->tplFile = 'include/ECM/EcmViews/EditView/Tabs/EditView.tpl';
|
|
$edit->preDisplay();
|
|
$edit->ss->assign("NEW_NUMBER", $new_number);
|
|
$edit->ss->assign("ECMQUOTE_ID", $ecmquote_id);
|
|
$edit->ss->assign("ECMQUOTE", $ecmquote);
|
|
$edit->ss->assign("STOCK", $stock);
|
|
$edit->ss->assign("DUPLICATE", $duplicate);
|
|
|
|
|
|
echo $edit->display();
|
|
//loading view
|
|
echo '<link rel="stylesheet" type="text/css" href="modules/EcmSales/javascript/helper.css" media="screen" />';
|