<?php

	//require_once '../../../library_html/elements/core/lib/lib_elementsCore.php';
	//require_once '../../../library_html/components/card/lib/lib_card.php';
	//require_once '../../../library_html/components/table/lib/lib_table.php';

	function get_acc_selected_org() {
		require_once '../../../library_html/properties/core/dat/dat_properties.php';
    	$dat = new dat_properties();
    	$result = $dat->select_settings(["user_id"=>$_COOKIE['user_id'],"property"=>"ACC_SEL_ORG"]);
    	if (count($result) > 0) {
    		return $result[0]['setting'];
    	} else {
    		return null;
    	}
	}

	function get_acc_accounts_list() {
		require_once '../../../library_html/accounting/core/dat/dat_accounting.php';
    	$dat = new dat_accounting();
    	$org_id = get_acc_selected_org();
		$result = $dat->select_acc_accounts(["org_id"=>$org_id]);
		return $result;
	}

	function get_acc_accounts_indexer() {
		$accounts = get_acc_accounts_list();
		$result = [];
		for($i = 0; $i < count($accounts); $i++) {
			$result[$accounts[$i]['account_id']] = $i;
		}
		return $result;
	}

    function get_acc_selected_budget() {
        require_once '../../../library_html/properties/core/dat/dat_properties.php';
        $dat = new dat_properties();
        $result = $dat->select_settings(["user_id"=>$_COOKIE['user_id'],"property"=>"ACC_SEL_BUDG"]);
        if (count($result) > 0) {
            return $result[0]['setting'];
        } else {
            return null;
        }
    }

	function get_acc_year() {
		require_once '../../../library_html/properties/core/dat/dat_properties.php';
    	$dat = new dat_properties();
    	$result = $dat->select_settings(["user_id"=>$_COOKIE['user_id'],"property"=>"ACC_SEL_YEAR"]);
    	if (count($result) > 0) {
    		return $result[0]['setting'];
    	} else {
    		return null;
    	}
	}

	function get_acc_month() {
		require_once '../../../library_html/properties/core/dat/dat_properties.php';
    	$dat = new dat_properties();
    	$result = $dat->select_settings(["user_id"=>$_COOKIE['user_id'],"property"=>"ACC_SEL_MONTH"]);
    	if (count($result) > 0) {
    		return $result[0]['setting'];
    	} else {
    		return null;
    	}
	}

	function get_acc_day() {
		require_once '../../../library_html/properties/core/dat/dat_properties.php';
    	$dat = new dat_properties();
    	$result = $dat->select_settings(["user_id"=>$_COOKIE['user_id'],"property"=>"ACC_SEL_DAY"]);
    	if (count($result) > 0) {
    		return $result[0]['setting'];
    	} else {
    		return null;
    	}
	}

    function set_acc_day($_p) {
        require_once '../../../library_html/properties/core/dat/dat_properties.php';
            $dat = new dat_properties();
            $dat->insert_settings(["user_id"=>$user[0]['user_id'], "property"=>"ACC_SEL_DAY", "setting"=>$_p['setting']]);
    }

    function set_acc_month($_p) {
        require_once '../../../library_html/properties/core/dat/dat_properties.php';
		$dat = new dat_properties();
		$dat->insert_settings(["user_id"=>$user[0]['user_id'],"property"=>"ACC_SEL_MONTH", "setting"=>$_p['setting']]);
    }

    function set_acc_year($_p) {
        require_once '../../../library_html/properties/core/dat/dat_properties.php';
		$dat = new dat_properties();
		$dat->insert_settings(["user_id"=>$user[0]['user_id'],"property"=>"ACC_SEL_YEAR", "setting"=>$_p['setting']]);
    }
?>