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

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

define('RC_POS', 10);

function salesman_list($name, $type) {
	if($type == 'POSSALESMAN')
		return pos_salesman_list($name, null, _('No salesman filter'));
}
$reports->register_controls('salesman_list');

function pos_receipts_list($name, $type) {
	global $type_shortcuts, $SysPrefs;

	if($type == 'POSINVOICE') {

		$IV = $type_shortcuts[ST_SALESINVOICE];
		$ref = ($SysPrefs->print_invoice_no() == 1 ? "trans_no" : "reference");

		$sql = "SELECT concat(debtor_trans.trans_no, '-', debtor_trans.type) AS TNO,
					concat('$IV ', debtor_trans.$ref,' ', debtor.name) as IName
				FROM ".TB_PREF."debtors_master debtor,"
					.TB_PREF."debtor_trans debtor_trans," 
					.TB_PREF."pos_trans pt
				WHERE type=".ST_SALESINVOICE." AND debtor.debtor_no=debtor_trans.debtor_no 
					AND debtor_trans.trans_no = pt.trans_no 
				ORDER BY debtor_trans.trans_no DESC";
		return combo_input($name, '', $sql, 'TNO', 'IName',array('order'=>false));
	}
}
$reports->register_controls('pos_receipts_list');

function pos_sale_types_list($name, $type) {

	if($type == 'POSSALESTYPE') {
		$methods = array(0=>_('No method filter'), 1=>_('Dine-In'), 2=>_('Take Away'), 3=>_('Delivery'));
		return array_selector($name, null, $methods);
	}
}
$reports->register_controls('pos_sale_types_list');

function pos_shift_list($name, $type) {

	if($type == 'POSSHIFT') {
		$sql = "SELECT id, shift_name, start_time, end_time FROM ".TB_PREF."pos_shift WHERE !inactive";
		return combo_input($name, '', $sql, 'id', 'shift_name', array('spec_option'=>_('No shift filter')));
	}
}
$reports->register_controls('pos_shift_list');

function pos_sales_points_list($name, $type) {

	if($type == 'SALESPOINT')
		return pos_sales_point_list($name, null, false, _('All Sales Points'));
}
$reports->register_controls('pos_sales_points_list');

$reports->addReportClass(_('Point of Sales'), RC_POS);
$reports->addReport(RC_POS, 'pos2', _('Sales People Commission'),
	array(	_('From Salesman') => 'POSSALESMAN',
		    _('To Salesman') => 'POSSALESMAN',
		    _('Customer') => 'CUSTOMERS_NO_FILTER',
		    _('From') => 'DATEBEGIN',
			_('To') => 'DATE',
			_('Comments') => 'TEXTBOX',
			_('Orientation') => 'ORIENTATION',
			_('Destination') => 'DESTINATION'
));
$reports->addReport(RC_POS, '_receipts', _('Print Receipts'),
	array(	_('From Receipt') => 'POSINVOICE',
		    _('To Receipt') => 'POSINVOICE',
		    _('Customer') => 'CUSTOMERS_NO_FILTER',
			_('Comments') => 'TEXTBOX',
			_('Orientation') => 'ORIENTATION'
));
$reports->addReport(RC_POS, 'pos4', _('Sales Method Report'),
	array(	_('Sales Method') => 'POSSALESTYPE',
			_('Sales Point') => 'SALESPOINT',
			_('User') => 'USERS',
			_('From') => 'DATEBEGIN',
			_('To') => 'DATE',
			_('Include Zeros') => 'YES_NO',
			_('Comments') => 'TEXTBOX',
			_('Orientation') => 'ORIENTATION'
));
$reports->addReport(RC_POS, 'pos5', _('Shift Revenue Report'),
	array(	_('Shift Filter') => 'POSSHIFT',
			_('Sales Point') => 'SALESPOINT',
			_('From') => 'DATE',
			_('To') => 'DATE',
			_('Include Zeros') => 'YES_NO',
			_('Comments') => 'TEXTBOX',
			_('Orientation') => 'ORIENTATION'
));
$reports->addReport(RC_POS, 'pos6', _('Payment Wise Report'),
	array(	_('Sales Point') => 'SALESPOINT',
			_('User') => 'USERS',
			_('From') => 'DATE',
			_('To') => 'DATE',
			_('Include Zeros') => 'YES_NO',
			_('Suppress Credit Note') => 'YES_NO',
			_('Summary Only') => 'YES_NO',
			_('Comments') => 'TEXTBOX',
			_('Orientation') => 'ORIENTATION'
));