<?php
	
//////////////////////////////////////////////////////////////////
//
//	acc_organizations
//
/////////////////////////////////////////////////////////////////

	$acc_delete_entry = function($_p) {
    	if (isset($_POST['data'])) {
    		$data = json_decode($_POST['data'], true);
			if(isset($data["ent_id"])) {
				require_once '../../../library_html/accounting/core/dat/dat_accounting_adv.php';
				$dat = new dat_accounting_adv();
				$comp = $dat->delete_acc_entries(["ent_id"=>$data['ent_id']]);
			} else {
				//do nothing
			}
		}
    };

    $acc_insert_entry = function($_p) {
		/*require_once '../../../library_html/accounting/core/dat/dat_accounting_adv.php';
		$dat = new dat_accounting_adv();
    	$dat->insert_all_acc_totals([]);*/
		/*require_once '../../../library_html/accounting/core/dat/dat_accounting_adv.php';
		$dat = new dat_accounting_adv();
    	$dat->insert_all_acc_carries([]);*/
    	if (isset($_POST['data'])) {
    		$data = json_decode($_POST['data'], true);
			if((isset($data['from']) || isset($data['to'])) && isset($data['day']) && isset($data['ammount']) && isset($data['description'])) {
				require_once '../../../library_html/accounting/core/dat/dat_accounting_adv.php';
				require_once '../../../library_html/accounting/core/lib/lib_acc_basic.php';
				$dat = new dat_accounting_adv();
				$par = [];
				$year = get_acc_year();
				$month = get_acc_month();
				if (isset($data['from']) && $data['from'] != '__NONE__') $par['from'] = $data['from'];
				if (isset($data['to']) && $data['to'] != '__NONE__') $par['to'] = $data['to'];
				$par['year'] = $year;
				$par['month'] = $month;
				$par['day'] = $data['day'];
				$par['ammount'] = $data['ammount'];
				$par['description'] = $data['description'];
				$comp = $dat->insert_dual_acc_entries($par);
				set_acc_day(['setting'=>$data['day']]);
			} else {
				//do nothing
			}
		}
    };

    $acc_date = function($_p) {
    	if (isset($_POST['data'])) {
    		$data = json_decode($_POST['data'], true);
			if(isset($data['month']) && isset($data['year'])) {
				require_once '../../../library_html/accounting/core/lib/lib_acc_basic.php';
				set_acc_month(['setting'=>$data['month']]);
				set_acc_year(['setting'=>$data['year']]);
			} else {
				//do nothing
			}
		}
    };

	$postIndex = [
		'acc_delete_entry'=>	$acc_delete_entry,
		'acc_insert_entry'=>	$acc_insert_entry,
		'acc_date'=>			$acc_date,
	];
?>