335 lines
13 KiB
PHP
335 lines
13 KiB
PHP
|
|
<?php
|
||
|
|
if (!defined('sugarEntry') || !sugarEntry)
|
||
|
|
die('NotAValidEntryPoint');
|
||
|
|
|
||
|
|
//loading view
|
||
|
|
echo '<link rel="stylesheet" type="text/css" href="modules/EcmInvoiceOuts/javascript/helper.css" media="screen" /><div class="loading_panel"></div>';
|
||
|
|
|
||
|
|
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings, $current_user, $app_list_strings;
|
||
|
|
require_once('modules/EcmInvoiceOuts/EcmInvoiceOut.php');
|
||
|
|
require_once('include/time.php');
|
||
|
|
|
||
|
|
echo '<script type="text/javascript";
|
||
|
|
src="modules/EcmInvoiceOuts/javascript/searchcolumndefs.js?time=' . md5(microtime()) . '"></script>';
|
||
|
|
echo '<script type="text/javascript"
|
||
|
|
src="include/ECM/SearchProductTable.js?time=' . md5(microtime()) . '"></script>';
|
||
|
|
echo '<script type="text/javascript"
|
||
|
|
src="include/ECM/tablenavigator.js?time=' . md5(microtime()) . '"></script>';
|
||
|
|
// $cq=$current_user->getPreference('confirm_quotes');
|
||
|
|
|
||
|
|
$new_number = false;
|
||
|
|
$is_correct = false;
|
||
|
|
$is_wz = false;
|
||
|
|
$is_sale = false;
|
||
|
|
$duplicate = false;
|
||
|
|
$focus = new EcmInvoiceOut();
|
||
|
|
$db = $GLOBALS['db'];
|
||
|
|
$refreshPositions = '0';
|
||
|
|
|
||
|
|
if (isset($_REQUEST['record']) && $_REQUEST['isDuplicate'] == "false") {
|
||
|
|
$focus->retrieve($_REQUEST['record']);
|
||
|
|
if (isset($focus->id) && $focus->id != '') {
|
||
|
|
$focus->format_all_fields();
|
||
|
|
$wz_id = $focus->wz_id;
|
||
|
|
$wz_name = $focus->wz_name;
|
||
|
|
$so_id = $focus->so_id;
|
||
|
|
$is_wz = true;
|
||
|
|
$refreshPositions = '1';
|
||
|
|
if ($focus->type == 'correct') {
|
||
|
|
$is_correct = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else if ($_REQUEST['isDuplicate'] == "true") {
|
||
|
|
$new_number = true;
|
||
|
|
$duplicate = true;
|
||
|
|
//get data
|
||
|
|
$focus->retrieve($_REQUEST['return_id']);
|
||
|
|
$focus->register_date = date("d.m.Y");
|
||
|
|
$focus->sell_date = date("d.m.Y");
|
||
|
|
$focus->validtill_date = date("d.m.Y");
|
||
|
|
$focus->payment_date = date("d.m.Y");
|
||
|
|
$focus->payment_date_days = '0';
|
||
|
|
} else if ($_REQUEST['isCorrect'] == "true") {
|
||
|
|
$new_number = true;
|
||
|
|
$is_correct = true;
|
||
|
|
//get data
|
||
|
|
$focus->retrieve($_REQUEST['record']);
|
||
|
|
|
||
|
|
if (isset($focus->id) && $focus->id != '') {
|
||
|
|
$focus->format_all_fields();
|
||
|
|
}
|
||
|
|
$tmp = new EcmInvoiceOut();
|
||
|
|
$tmp->retrieve($_REQUEST['record']);
|
||
|
|
$focus->register_date = date("d.m.Y");
|
||
|
|
$focus->sell_date = date("d.m.Y", strtotime($tmp->sell_date));
|
||
|
|
$focus->validtill_date = date("d.m.Y");
|
||
|
|
$focus->type = 'correct';
|
||
|
|
$focus->payment_date = date("d.m.Y");
|
||
|
|
$focus->payment_date_days = '0';
|
||
|
|
$focus->currency_id = $tmp->currency_id;
|
||
|
|
unset($tmp);
|
||
|
|
} else if ($_REQUEST['isWZ'] == "true" || $_REQUEST['isWz'] == "true") {
|
||
|
|
$new_number = true;
|
||
|
|
$is_wz = true;
|
||
|
|
//get data
|
||
|
|
$wz = new EcmStockDocOut;
|
||
|
|
$lists = explode('@', $_REQUEST['record']);
|
||
|
|
$wz->retrieve($lists[0]);
|
||
|
|
$wz_id = $_REQUEST['record'];
|
||
|
|
$so_id = $wz->so_id;
|
||
|
|
$wz_name = $wz->document_no;
|
||
|
|
// load from wz
|
||
|
|
$focus->parent_id = $wz->parent_id;
|
||
|
|
$focus->parent_name = $wz->parent_name;
|
||
|
|
$focus->order_no = $wz->order_no;
|
||
|
|
//dates
|
||
|
|
$focus->type = 'normal';
|
||
|
|
$focus->stock_id = $wz->stock_id;
|
||
|
|
$focus->stock_name = $wz->stock_name;
|
||
|
|
$focus->register_date = date("d.m.Y");
|
||
|
|
$focus->sell_date = $wz->register_date;
|
||
|
|
|
||
|
|
$focus->payment_method_paid = "0";
|
||
|
|
|
||
|
|
|
||
|
|
$focus->validtill_date = date("d.m.Y");
|
||
|
|
if ($so_id != '') {
|
||
|
|
$so = new EcmSale();
|
||
|
|
$so->retrieve($so_id);
|
||
|
|
$focus->so_id = $so_id;
|
||
|
|
$focus->payment_date = $so->payment_date;
|
||
|
|
$focus->payment_date_days = $so->payment_date_days;
|
||
|
|
$focus->payment_method = $so->payment_method;
|
||
|
|
|
||
|
|
$focus->parent_shipping_address_name = $so->shipping_address_name;
|
||
|
|
$focus->parent_shipping_address_street = $so->shipping_address_street;
|
||
|
|
$focus->parent_shipping_address_postalcode = $so->shipping_address_postalcode;
|
||
|
|
$focus->parent_shipping_address_city = $so->shipping_address_city;
|
||
|
|
$focus->parent_shipping_address_country = $so->shipping_address_country;
|
||
|
|
$focus->parent_shipping_nip = $so->shipping_nip;
|
||
|
|
$focus->parent_shipping_iln = $so->shipping_iln;
|
||
|
|
|
||
|
|
if ($so->order_source == 'allegro') {
|
||
|
|
$focus->paid_val = $wz->total_brutto;
|
||
|
|
if ($so->payment_method == 'PRZEDPLATA') {
|
||
|
|
$focus->payment_method_paid = '0';
|
||
|
|
} else {
|
||
|
|
$focus->payment_method_paid = '1';
|
||
|
|
}
|
||
|
|
$focus->payment_date = date("d.m.Y");
|
||
|
|
$focus->payment_date_days = '0';
|
||
|
|
}
|
||
|
|
|
||
|
|
// saturn??
|
||
|
|
$tmp_a = new Account();
|
||
|
|
$tmp_a->retrieve($wz->parent_id);
|
||
|
|
if ($tmp_a->parent_id == '1249') {
|
||
|
|
$a = new Account();
|
||
|
|
$a->retrieve('1249');
|
||
|
|
$focus->supplier_code = '2503793';
|
||
|
|
$focus->parent_payer_address_name = $a->name;
|
||
|
|
$focus->parent_payer_address_street = $a->register_address_street;
|
||
|
|
$focus->parent_payer_address_postalcode = $a->register_address_postalcode;
|
||
|
|
$focus->parent_payer_address_city = $a->register_address_city;
|
||
|
|
$focus->parent_payer_address_country = $a->register_address_country;
|
||
|
|
|
||
|
|
$focus->parent_address_street = 'Al. Jerozolimskie 179';
|
||
|
|
$focus->parent_address_postalcode = '02-222';
|
||
|
|
$focus->parent_address_city = 'Warszawa';
|
||
|
|
$focus->parent_address_country = 'Polska';
|
||
|
|
|
||
|
|
$focus->parent_payer_nip = $a->to_vatid;
|
||
|
|
$focus->parent_payer_iln = $a->iln;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$focus->payment_date = date("d.m.Y");
|
||
|
|
$focus->payment_date_days = '0';
|
||
|
|
}
|
||
|
|
|
||
|
|
// Handle prepaid
|
||
|
|
if ($s->main_sale_id) {
|
||
|
|
$prepaids = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select SUM(inv_value) as total, GROUP_CONCAT(document_no, '') as documents FROM ecmprepaymentinvoices WHERE ecmsale_id
|
||
|
|
='" . $s->main_sale_id . "' GROUP BY ecmsale_id"));
|
||
|
|
} else {
|
||
|
|
$prepaids = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select SUM(inv_value) as total, GROUP_CONCAT(document_no, '') as documents FROM ecmprepaymentinvoices WHERE ecmsale_id
|
||
|
|
='" . $s->id . "' GROUP BY ecmsale_id"));
|
||
|
|
}
|
||
|
|
$focus->prepaid = $prepaids['total'];
|
||
|
|
$focus->prepaid_nr = $prepaids['documents'];
|
||
|
|
|
||
|
|
if ($focus->prapaid != '') {
|
||
|
|
$focus->ecmpaymentcondition_id = 'ec14f1da-09c5-7b99-77ef-4e9fd3cfd67f';
|
||
|
|
$focus->ecmpaymentcondition_name = 'Przedpłata';
|
||
|
|
}
|
||
|
|
} else if ($_REQUEST['isSALE'] == "true") {
|
||
|
|
|
||
|
|
$new_number = true;
|
||
|
|
$is_sale = true;
|
||
|
|
//get data
|
||
|
|
$wz = new EcmSale();
|
||
|
|
$wz->retrieve($_REQUEST['record']);
|
||
|
|
$so_id = $_REQUEST['record'];
|
||
|
|
$wz_name = $wz->document_no;
|
||
|
|
// load from sale...
|
||
|
|
$focus->parent_id = $wz->parent_id;
|
||
|
|
$focus->parent_name = $wz->parent_name;
|
||
|
|
|
||
|
|
$wz2 = new EcmStockDocOut();
|
||
|
|
$wz2->retrieve_by_string_fields(['so_id' => $_REQUEST['record']]);
|
||
|
|
if ($wz2->id != "") {
|
||
|
|
$wz_name = $wz2->document_no;
|
||
|
|
$wz_id = $wz2->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
$focus->order_no = $wz->parent_document_no;
|
||
|
|
$focus->ecmpaymentcondition_name = $wz->ecmpaymentcondition_name;
|
||
|
|
$focus->ecmpaymentcondition_id = $wz->ecmpaymentcondition_id;
|
||
|
|
//dates
|
||
|
|
$focus->type = 'normal';
|
||
|
|
$focus->stock_id = $wz2->stock_id;
|
||
|
|
$focus->stock_name = $wz2->stock_name;
|
||
|
|
$focus->register_date = date("d.m.Y");
|
||
|
|
$focus->sell_date = date("d.m.Y");
|
||
|
|
$focus->validtill_date = date("d.m.Y");
|
||
|
|
$focus->payment_date = date("d.m.Y");
|
||
|
|
$focus->payment_date_days = '0';
|
||
|
|
$focus->payment_date = $wz->payment_date;
|
||
|
|
$focus->payment_date_days = $wz->payment_date_days;
|
||
|
|
|
||
|
|
|
||
|
|
$focus->so_id = $so_id;
|
||
|
|
$focus->payment_date = $wz->payment_date;
|
||
|
|
$focus->payment_date_days = $wz->payment_date_days;
|
||
|
|
//var_dump($wz->payment_method);
|
||
|
|
$focus->payment_method = $wz->payment_method;
|
||
|
|
|
||
|
|
$focus->parent_shipping_address_name = $wz->shipping_address_name;
|
||
|
|
$focus->parent_shipping_address_street = $wz->shipping_address_street;
|
||
|
|
$focus->parent_shipping_address_postalcode = $wz->shipping_address_postalcode;
|
||
|
|
$focus->parent_shipping_address_city = $wz->shipping_address_city;
|
||
|
|
$focus->parent_shipping_address_country = $wz->shipping_address_country;
|
||
|
|
$focus->parent_shipping_nip = $wz->shipping_nip;
|
||
|
|
$focus->parent_shipping_iln = $wz->shipping_iln;
|
||
|
|
|
||
|
|
|
||
|
|
if ($wz->order_source == 'allegro') {
|
||
|
|
$focus->paid_val = $wz->total_brutto;
|
||
|
|
if ($wz->payment_method == 'PRZEDPLATA') {
|
||
|
|
$focus->payment_method_paid = '0';
|
||
|
|
} else {
|
||
|
|
$focus->payment_method_paid = '1';
|
||
|
|
}
|
||
|
|
$focus->payment_date = date("d.m.Y");
|
||
|
|
$focus->payment_date_days = '0';
|
||
|
|
}
|
||
|
|
|
||
|
|
// saturn??
|
||
|
|
$tmp_a = new Account();
|
||
|
|
$tmp_a->retrieve($wz->parent_id);
|
||
|
|
if ($tmp_a->parent_id == '1249') {
|
||
|
|
$a = new Account();
|
||
|
|
$a->retrieve('1249');
|
||
|
|
$focus->supplier_code = '2503793';
|
||
|
|
$focus->parent_payer_address_name = $a->name;
|
||
|
|
$focus->parent_payer_address_street = $a->register_address_street;
|
||
|
|
$focus->parent_payer_address_postalcode = $a->register_address_postalcode;
|
||
|
|
$focus->parent_payer_address_city = $a->register_address_city;
|
||
|
|
$focus->parent_payer_address_country = $a->register_address_country;
|
||
|
|
$focus->parent_address_street = 'Al. Jerozolimskie 179';
|
||
|
|
$focus->parent_address_postalcode = '02-222';
|
||
|
|
$focus->parent_address_city = 'Warszawa';
|
||
|
|
$focus->parent_address_country = 'Polska';
|
||
|
|
$focus->parent_payer_nip = $a->to_vatid;
|
||
|
|
$focus->parent_payer_iln = $a->iln;
|
||
|
|
}
|
||
|
|
//$focus->register_date=$wz->register_date;
|
||
|
|
// $focus->sell_date=$wz->register_date;
|
||
|
|
$z = $GLOBALS['db']->query("select id from ecmprepaymentinvoices where ecmsale_id='" . $wz->id . "'");
|
||
|
|
if ($z->num_rows > 0) {
|
||
|
|
$focus->endinvoice = 1;
|
||
|
|
$z2 = $GLOBALS['db']->query("select document_no,prepaid_amount from ecmprepaymentinvoices where ecmsale_id='" . $wz->id . "'");
|
||
|
|
while ($d2 = $GLOBALS['db']->fetchByAssoc($z2)) {
|
||
|
|
$focus->prepaid += $d2['prepaid_amount'];
|
||
|
|
$focus->prepaid_nr .= $d2['document_no'] . ', ';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$new_number = true;
|
||
|
|
//dates
|
||
|
|
$focus->stock_id = $current_user->stock_id;
|
||
|
|
$focus->register_date = date("d.m.Y");
|
||
|
|
$focus->sell_date = date("d.m.Y");
|
||
|
|
$focus->validtill_date = date("d.m.Y");
|
||
|
|
$focus->payment_date = date("d.m.Y");
|
||
|
|
$focus->type = 'normal';
|
||
|
|
|
||
|
|
$focus->assigned_user_id = $current_user->id;
|
||
|
|
$focus->assigned_user_name = $current_user->first_name . " " . $current_user->last_name;
|
||
|
|
$focus->payment_date_days = 0;
|
||
|
|
//$focus->number= EcmInvoiceOut::generateNumber($focus->stock_id,$focus->register_date );
|
||
|
|
//$focus->document_no= EcmInvoiceOut::formatNumber($focus->number,$focus->stock_id);
|
||
|
|
//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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$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' => strtoupper($v->name), 'value' => $v->value);
|
||
|
|
echo '<script> var OO=\'' . json_encode($oo) . '\'</script>';
|
||
|
|
//stock operations
|
||
|
|
|
||
|
|
$operation = '<select id="operation_type" name="operation_type">';
|
||
|
|
$operation_b = $app_list_strings['ecmoperation_type'];
|
||
|
|
foreach ($operation_b as $key => $val) {
|
||
|
|
$operation_b .= '<option value="' . $key . '">' . $val . '</option>';
|
||
|
|
}
|
||
|
|
$operation .= $operation_b . '</select><input id="operation_id" name="operation_id" type="hidden" value="' . $focus->operation_id . '"/>';
|
||
|
|
|
||
|
|
require_once('include/MVC/View/SugarView.php');
|
||
|
|
require_once('modules/EcmInvoiceOuts/views/EditView/view.edit.ecminvoiceouts.php');
|
||
|
|
$edit = new ViewEditEcmInvoiceOuts();
|
||
|
|
$edit->ss = new Sugar_Smarty();
|
||
|
|
$edit->module = 'EcmInvoiceOuts';
|
||
|
|
$edit->bean = $focus;
|
||
|
|
$edit->tplFile = 'include/ECM/EcmViews/EditView/Tabs/EditView.tpl';
|
||
|
|
$edit->preDisplay();
|
||
|
|
|
||
|
|
$edit->ss->assign("correctEdit", $_REQUEST['correctEdit']);
|
||
|
|
$edit->ss->assign("NEW_NUMBER", $new_number);
|
||
|
|
$edit->ss->assign("IS_CORRECT", $is_correct);
|
||
|
|
$edit->ss->assign("IS_WZ", $is_wz);
|
||
|
|
$edit->ss->assign("IS_SALE", $is_sale);
|
||
|
|
$edit->ss->assign("REFRESHPOSITIONS", $refreshPositions);
|
||
|
|
$edit->ss->assign("WZ_ID", $wz_id);
|
||
|
|
$edit->ss->assign("WZ_NAME", $wz_name);
|
||
|
|
$edit->ss->assign("SO_ID", $so_id);
|
||
|
|
$edit->ss->assign("DUPLICATE", $duplicate);
|
||
|
|
$edit->ss->assign("STOCK", $stock);
|
||
|
|
$edit->ss->assign("OPERATION_TYPE", $operation);
|
||
|
|
echo $edit->display();
|