320 lines
13 KiB
PHP
320 lines
13 KiB
PHP
|
|
<?php
|
||
|
|
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/EcmInvoiceOuts/EcmInvoiceOut.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 '<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>';
|
||
|
|
|
||
|
|
$new_number = false;
|
||
|
|
$is_correct = false;
|
||
|
|
$is_wz = false;
|
||
|
|
$is_sale = false;
|
||
|
|
|
||
|
|
$focus = new EcmInvoiceOut ();
|
||
|
|
$db = $GLOBALS ['db'];
|
||
|
|
|
||
|
|
if (isset ( $_REQUEST ['record'] ) && $_REQUEST ['isDuplicate'] == "false") {
|
||
|
|
$focus->retrieve ( $_REQUEST ['record'] );
|
||
|
|
if (isset ( $focus->id ) && $focus->id != '') {
|
||
|
|
$focus->format_all_fields ();
|
||
|
|
}
|
||
|
|
$so_id=$focus->so_id;
|
||
|
|
$wz_id=$focus->wz_id;
|
||
|
|
|
||
|
|
} 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 ();
|
||
|
|
}
|
||
|
|
$focus->register_date = date ( "d.m.Y" );
|
||
|
|
$focus->sell_date = date ( "d.m.Y" );
|
||
|
|
$focus->validtill_date = date ( "d.m.Y" );
|
||
|
|
$focus->type = 'correct';
|
||
|
|
|
||
|
|
// saturn??
|
||
|
|
$tmp_a = new Account ();
|
||
|
|
$tmp_a->retrieve ( $focus->parent_id );
|
||
|
|
if ($tmp_a->parent_id == '1249') {
|
||
|
|
$a = new Account ();
|
||
|
|
$a->retrieve ( '1249' );
|
||
|
|
|
||
|
|
$focus->parent_payer_address_name = $a->name;
|
||
|
|
$focus->parent_payer_address_street = $a->shipping_address_street;
|
||
|
|
$focus->parent_payer_address_postalcode = $a->shipping_address_postalcode;
|
||
|
|
$focus->parent_payer_address_city = $a->shipping_address_city;
|
||
|
|
$focus->parent_payer_address_country = $a->shipping_address_country;
|
||
|
|
$focus->parent_payer_address_nip = $a->to_vatid;
|
||
|
|
$focus->parent_payer_address_iln = $a->iln;
|
||
|
|
}
|
||
|
|
global $current_user;
|
||
|
|
$focus->assigned_user_id = $current_user->id;
|
||
|
|
$focus->assigned_user_name = $current_user->full_name;
|
||
|
|
|
||
|
|
$focus->prepaid = '0';
|
||
|
|
} else if ($_REQUEST ['isWZ'] == "true") {
|
||
|
|
$new_number = true;
|
||
|
|
$is_wz = true;
|
||
|
|
// get data
|
||
|
|
$wz = new EcmStockDocOut ();
|
||
|
|
$wz->retrieve ( $_REQUEST ['wz_record'] );
|
||
|
|
if($_REQUEST ['wz_record_zb']!=""){
|
||
|
|
$wz_zb=$_REQUEST ['wz_record_zb'];
|
||
|
|
$wz_zb_array=explode(",",$wz_zb);
|
||
|
|
|
||
|
|
$wz->retrieve ( $wz_zb_array[0]);
|
||
|
|
}
|
||
|
|
$wz_id = $_REQUEST ['wz_record'];
|
||
|
|
$so_id = $wz->ecmsale_id;
|
||
|
|
$focus->so_id = $so_id;
|
||
|
|
$s = new EcmSale ();
|
||
|
|
$s->retrieve ( $so_id );
|
||
|
|
$focus->currency_id = $s->currency_id;
|
||
|
|
$wz_name = $wz->document_no;
|
||
|
|
// load from zs
|
||
|
|
$focus->parent_id = $s->parent_id;
|
||
|
|
$focus->parent_name = $s->parent_name;
|
||
|
|
$focus->order_no = $s->parent_document_no;
|
||
|
|
$focus->supplier_code = $s->parent_supplier_code;
|
||
|
|
// dates
|
||
|
|
$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->validtill_date = date ( "d.m.Y" );
|
||
|
|
$focus->parent_shipping_address_name = $s->shipping_address_name;
|
||
|
|
$focus->parent_shipping_address_street = $s->shipping_address_street;
|
||
|
|
$focus->parent_shipping_address_postalcode = $s->shipping_address_postalcode;
|
||
|
|
$focus->parent_shipping_address_city = $s->shipping_address_city;
|
||
|
|
$focus->parent_shipping_address_country = $s->shipping_address_country;
|
||
|
|
$focus->parent_shipping_address_nip = $s->shipping_nip;
|
||
|
|
$focus->parent_shipping_address_iln = $s->shipping_iln;
|
||
|
|
|
||
|
|
// saturn??
|
||
|
|
$tmp_a = new Account ();
|
||
|
|
$tmp_a->retrieve ( $focus->parent_id );
|
||
|
|
if ($tmp_a->parent_id == '1249') {
|
||
|
|
$a = new Account ();
|
||
|
|
$a->retrieve ( '1249' );
|
||
|
|
|
||
|
|
$focus->parent_payer_address_name = $a->name;
|
||
|
|
$focus->parent_payer_address_street = $a->shipping_address_street;
|
||
|
|
$focus->parent_payer_address_postalcode = $a->shipping_address_postalcode;
|
||
|
|
$focus->parent_payer_address_city = $a->shipping_address_city;
|
||
|
|
$focus->parent_payer_address_country = $a->shipping_address_country;
|
||
|
|
$focus->parent_payer_address_nip = $a->to_vatid;
|
||
|
|
$focus->parent_payer_address_iln = $a->iln;
|
||
|
|
}
|
||
|
|
|
||
|
|
$pc = new EcmPaymentCondition ();
|
||
|
|
$pc->retrieve ( $s->ecmpaymentcondition_id );
|
||
|
|
$focus->ecmpaymentcondition_id = $pc->id;
|
||
|
|
$focus->ecmpaymentcondition_name = $pc->name;
|
||
|
|
if ($tmp_a->parent_id != '1249')
|
||
|
|
$focus->payment_date = $GLOBALS ['timedate']->to_display_date ( date ( "Y-m-d", mktime () + 3600 * 24 * $pc->days ) );
|
||
|
|
else {
|
||
|
|
$ss = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "SELECT delivery_date FROM ecmsales WHERE id='" . $r ['ecmsale_id'] . "'" ) );
|
||
|
|
$d = date ( 'Y-m-t', strtotime ( $ss ['delivery_date'] ) );
|
||
|
|
$focus->payment_date = $GLOBALS ['timedate']->to_display_date ( date ( "Y-m-d", mktime () + 3600 * 24 * 60 ) );
|
||
|
|
}
|
||
|
|
|
||
|
|
$focus->ecmdeliverycondition_id = $s->ecmdeliverycondition_id;
|
||
|
|
$focus->ecmdeliverycondition_name = $s->ecmdeliverycondition_name;
|
||
|
|
|
||
|
|
// 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 wz
|
||
|
|
$focus->parent_id = $wz->parent_id;
|
||
|
|
$focus->parent_name = $wz->parent_name;
|
||
|
|
$focus->order_no = $wz->order_no;
|
||
|
|
$focus->ecmpaymentcondition_name = $wz->ecmpaymentcondition_name;
|
||
|
|
$focus->ecmpaymentcondition_id = $wz->ecmpaymentcondition_id;
|
||
|
|
// dates
|
||
|
|
$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->validtill_date = date ( "d.m.Y" );
|
||
|
|
} elseif ($_REQUEST ['prepaymentinvoice_id']) {
|
||
|
|
$new_number = true;
|
||
|
|
$is_sale = true;
|
||
|
|
// get data
|
||
|
|
$inv = new EcmPrepaymentInvoice();
|
||
|
|
$inv->retrieve($_REQUEST ['prepaymentinvoice_id']);
|
||
|
|
$sale = new EcmSale ();
|
||
|
|
$sale->retrieve ( $inv->ecmsale_id );
|
||
|
|
$so_id = $inv->ecmsale_id;
|
||
|
|
// load from sale
|
||
|
|
$focus->parent_id = $sale->parent_id;
|
||
|
|
$focus->parent_name = $sale->parent_name;
|
||
|
|
$focus->order_no = $sale->order_no;
|
||
|
|
$focus->ecmpaymentcondition_name = $sale->ecmpaymentcondition_name;
|
||
|
|
$focus->ecmpaymentcondition_id = $sale->ecmpaymentcondition_id;
|
||
|
|
// dates
|
||
|
|
$focus->stock_id = $sale->stock_id;
|
||
|
|
$focus->stock_name = $sale->stock_name;
|
||
|
|
$focus->register_date = date ( "d.m.Y" );
|
||
|
|
$focus->sell_date = $sale->register_date;
|
||
|
|
$focus->validtill_date = date ( "d.m.Y" );
|
||
|
|
// prepaid
|
||
|
|
$focus->prepaid = $inv->inv_value;
|
||
|
|
$focus->prepaid_nr = $inv->document_no;
|
||
|
|
|
||
|
|
} elseif ($_REQUEST ['parent_doc_type'] == 'EcmReturn') {
|
||
|
|
$new_number = true;
|
||
|
|
$is_return = true;
|
||
|
|
$return_id = $_REQUEST ['parent_doc_id'];
|
||
|
|
$sess_id = $_REQUEST ['sess_id'];
|
||
|
|
|
||
|
|
$ret = new EcmReturn ();
|
||
|
|
$ret->retrieve ( $return_id );
|
||
|
|
|
||
|
|
$tmp = json_decode ( $_SESSION [$sess_id], true );
|
||
|
|
// var_dump($tmp[0]);
|
||
|
|
|
||
|
|
$focus->parent_id = $ret->parent_id;
|
||
|
|
$focus->parent_name = $ret->parent_name;
|
||
|
|
$focus->type = 'correct';
|
||
|
|
$focus->register_date = date ( "d.m.Y" );
|
||
|
|
$focus->sell_date = date ( "d.m.Y" );
|
||
|
|
$focus->validtill_date = date ( "d.m.Y" );
|
||
|
|
$focus->order_no = $ret->name;
|
||
|
|
} elseif ($_REQUEST ['mdci'] == '1') {
|
||
|
|
$new_number = true;
|
||
|
|
$is_multiCorrectDiscountInvoice = true;
|
||
|
|
$discount = $_REQUEST['discount'];
|
||
|
|
$inv = $_REQUEST ['invoices'];
|
||
|
|
|
||
|
|
$focus->parent_id = $_REQUEST['account_id'];
|
||
|
|
$focus->parent_name = $_REQUEST['account_name'];
|
||
|
|
$focus->type = 'correct';
|
||
|
|
$focus->register_date = date ( "d.m.Y" );
|
||
|
|
$focus->sell_date = date ( "d.m.Y" );
|
||
|
|
$focus->validtill_date = date ( "d.m.Y" );
|
||
|
|
|
||
|
|
$a = new Account();
|
||
|
|
$a->retrieve($_REQUEST['account_id']);
|
||
|
|
if ($a->parent_id == '1249') {
|
||
|
|
$focus->payment_method = 'KOMPENSATA';
|
||
|
|
$mshp = new Account();
|
||
|
|
$mshp->retrieve('1249');
|
||
|
|
$focus->parent_payer_address_name = $mshp->name;
|
||
|
|
$focus->parent_payer_address_street = $mshp->billing_address_street;
|
||
|
|
$focus->parent_payer_address_postalcode = $mshp->billing_address_postalcode;
|
||
|
|
$focus->parent_payer_address_city = $mshp->billing_address_city;
|
||
|
|
$focus->parent_payer_address_country = $mshp->billing_address_country;
|
||
|
|
$focus->parent_payer_address_nip = $mshp->to_vatid;
|
||
|
|
|
||
|
|
$focus->parent_shipping_address_name = $a->name;
|
||
|
|
$focus->parent_shipping_address_street = $a->shipping_address_street;
|
||
|
|
$focus->parent_shipping_address_postalcode = $a->shipping_address_postalcode;
|
||
|
|
$focus->parent_shipping_address_city = $a->shipping_address_city;
|
||
|
|
$focus->parent_shipping_address_country = $a->shipping_address_country;
|
||
|
|
$focus->parent_shipping_address_nip = $a->to_vatid;
|
||
|
|
}
|
||
|
|
|
||
|
|
} 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" );
|
||
|
|
// 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 . '"/>';
|
||
|
|
|
||
|
|
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 ( "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 ( "WZ_ID", $wz_id );
|
||
|
|
$edit->ss->assign ( "WZ_NAME", $wz_name );
|
||
|
|
$edit->ss->assign ( "SO_ID", $so_id );
|
||
|
|
$edit->ss->assign ( "IS_RETURN", $is_return );
|
||
|
|
$edit->ss->assign ( "wz_record_zb",$wz_zb);
|
||
|
|
$edit->ss->assign ( "SESS_ID", $sess_id );
|
||
|
|
$edit->ss->assign ( "RETURN_ID", $return_id );
|
||
|
|
$edit->ss->assign ( "DUPLICATE", $duplicate );
|
||
|
|
$edit->ss->assign ( "STOCK", $stock );
|
||
|
|
$edit->ss->assign ("WZ_ZB_ID",$wz_zb);
|
||
|
|
$edit->ss->assign("isEditMode", (isset($_REQUEST['isEditMode']) && $_REQUEST['isEditMode'] == 'true') ? 'true' : 'false');
|
||
|
|
if ($is_multiCorrectDiscountInvoice) {
|
||
|
|
$edit->ss->assign ( "MULTIDISCOUNTCORRECTINVOICE", true );
|
||
|
|
$edit->ss->assign ( "MDCI_DISCOUNT", $discount );
|
||
|
|
$edit->ss->assign ( "MDCI_INV", $inv );
|
||
|
|
}
|
||
|
|
echo $edit->display ();
|
||
|
|
// loading view
|
||
|
|
echo '<link rel="stylesheet" type="text/css" href="modules/EcmInvoiceOuts/javascript/helper.css" media="screen" /><div class="loading_panel"></div>';
|