<?php
/*=======================================================\
|                 Point of Sales Module                  |
|--------------------------------------------------------|
|   Creator: Phương                                      |
|   Date :   18-Dec-2017                                 |
|   Description: ERP Point of Sales Extension            |
|   Website: http://notrinos.com                         |
|                                                        |
\=======================================================*/
define ('SS_POS', 253<<8);

class pos_app extends application {
	
    function __construct() {
        global $path_to_root;
        
        parent::__construct('pos', _($this->help_context = 'Point of Sales'));
        
        $this->add_module(_('Transactions'));
		$this->add_lapp_function(0, _('Sales'), $path_to_root.'/modules/pos/manage/sales_entry.php?NewInvoice=0', 'SA_SALESMAN', MENU_TRANSACTION);
        $this->add_lapp_function(0, _('Items Return'), $path_to_root.'/modules/pos/inquiry/pos_inquiry.php?return=Yes', 'SA_SALESMAN', MENU_TRANSACTION);

        $this->add_module(_('Inquiry & Reports'));
        $this->add_lapp_function(1, _('Sales Point Inquiry'), $path_to_root.'/modules/pos/inquiry/pos_inquiry.php?', 'SA_SALESTRANSVIEW', MENU_INQUIRY);
        $this->add_rapp_function(1, _('POS reports'), 'reporting/reports_main.php?Class=10', 'SA_SALESMANAGER', MENU_REPORT);
        
        $this->add_module(_('Maintenance'));
        $this->add_lapp_function(2, _('Settings'), $path_to_root.'/modules/pos/manage/pos_setup.php', 'SA_SALESMANAGER', MENU_MAINTENANCE);
        $this->add_lapp_function(2, _('Bank Payment Setting'), $path_to_root.'/modules/pos/manage/pos_credit_setup.php', 'SA_SALESMANAGER', MENU_MAINTENANCE);
        $this->add_lapp_function(2, _('Exclude from Retail'), $path_to_root.'/modules/pos/manage/pos_exclude.php', 'SA_SALESMANAGER', MENU_MAINTENANCE);
        $this->add_lapp_function(2, _('Exclude from Return'), $path_to_root.'/modules/pos/manage/pos_exclude_return.php', 'SA_SALESMANAGER', MENU_MAINTENANCE);
        $this->add_rapp_function(2, _('Service Salesman'), $path_to_root.'/modules/pos/manage/pos_salespeople.php', 'SA_SALESMANAGER', MENU_MAINTENANCE);
        $this->add_rapp_function(2, _('Commissions'), $path_to_root.'/modules/pos/manage/pos_commission.php', 'SA_SALESMANAGER', MENU_MAINTENANCE);
        $this->add_rapp_function(2, _('Shift Management'), $path_to_root.'/modules/pos/manage/shift_setup.php', 'SA_SALESMANAGER', MENU_MAINTENANCE);
		
		$this->add_extensions();
    }
}

class hooks_pos extends hooks {

    function __construct() {
 		$this->module_name = 'pos';
 	}
    function install_tabs($app) {
        $app->add_application(new pos_app);
    }
    function install_access() {
        $security_sections[SS_POS] = _('Point of Sales');
        $security_areas['SA_SALESMANAGER'] = array(SS_POS|1, _('Sales Manager'));
        $security_areas['SA_POSSUPERADMIN'] = array(SS_POS|1, _('See other branches transactions'));
        
        return array($security_areas, $security_sections);
    }
    function activate_extension($company, $check_only=true) {
        global $db_connections;
        $updates = array( 'update.sql' => array('pos'));

        return $this->update_databases($company, $updates, $check_only);
    }
	
    function deactivate_extension($company, $check_only=true) {
        global $db_connections;
        $updates = array('remove.sql' => array('pos'));

        return $this->update_databases($company, $updates, $check_only);
    }
}