<?php
/*=======================================================\
|                 Point of Sales Module                  |
|--------------------------------------------------------|
|   Creator: Phương                                      |
|   Date :   18-Dec-2017                                 |
|   Description: ERP Point of Sales Extension            |
|   Website: http://notrinos.com                         |
|                                                        |
\=======================================================*/

$page_security = 'SA_SALESMANAGER';
$path_to_root  = '../../..';
include_once($path_to_root.'/includes/session.inc');
add_access_extensions();

$js = '';
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(900, 500);

include_once($path_to_root.'/includes/ui.inc');
include_once($path_to_root.'/modules/pos/includes/pos_ui.inc');
include_once($path_to_root.'/modules/pos/includes/pos_db.inc');

//--------------------------------------------------------------------------

if (isset($_POST['submit']))
	$Ajax->activate('_page_body');

if (isset($_POST['addItems'])) {
	$count = 0;
	foreach ($_POST['stock_id_1'] as $code) {
		if($code != '') {
			pos_exclude_returnable_items($code);
			$count ++;
		}
	}
	$Ajax -> activate('_page_body');
	if($count > 0)
		display_notification(_('Items have been excluded from the list of items that can be returned.'));
}

if (isset($_POST['delItems'])) {
	$count = 0;
	foreach ($_POST['stock_id_2'] as $code) {
		if($code != '') {
			pos_include_returnable_item($code);
			$count ++;
		}
	}
	$Ajax -> activate('_page_body');
	if($count > 0)
		display_notification(_('Items have been added to returned list.'));
}

//--------------------------------------------------------------------------

$css = $path_to_root.'/modules/pos/css/pos_exclude.css';
page(_($help_context = 'Exclude from Return'), false, false, '', $js, false, $css);

start_form();
start_table();

table_header(array(_('Returnable'), '', _('Excluded')));

start_row();
echo "<td rowspan='2'>".sales_items_list('stock_id_1', null, _('Select Items'), true, '', array('multi' => true,'search_box'=>false,'height'=>20,'cells'=>false), false, '')."</td>";
submit_cells('addItems', _(" Add >> "), "align='center'", '', 'default');
echo "<td rowspan='2'>".returnable_items_exclude_list('stock_id_2', null, _('Select Items'), true, array('multi' => true,'search_box'=>false,'height'=>20,'cells'=>false), false, '')."</td>";
end_row();

start_row();
submit_cells('delItems', _(" << Delete"), "align='center'", '', 'cancel');
end_row();

end_table(1);

end_form();
// var_dump($_POST['stock_id_1']);br();
// var_dump($_POST['stock_id_2']);
end_page();