<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============
$branchid = $_SESSION['LOGIN_BRANCH'];
extract($_POST);


if($opr=='voucher_entry'){

	$date_c = date("Y-m-d");
	$tot = $obj->Total_Count_By_Cond("acc_voucher","DATE(_entry_date)='$date_c'");	

	if($tot==0){
	   $date = date("Ymd");
	   $cons = '00001';
	   $trxn_id = $date.$cons;
	}
	else{
		$mx = $obj->Max_Value_By_Cond("acc_voucher","_trxn_id","DATE(_entry_date)='$date_c'");
		$trxn_id = $mx['max_valu']+1;
	}


	$form_data=array(
			'_br_id'=>$branchid,
			'_trxn_type'=>'C',
			'_trxn_id'=>$trxn_id,
			'_date'=>date("Y:m:d",strtotime($voucher_date)),
			'_voutcher_type'=>$voucher_type,
			'_amount'=>$amount,
			'_voutcher_no'=>$voucher_number,
			'_particullar'=>$particular,
			'_entry_by'=>$_SESSION['LOGIN_USERID'],
			'_entry_date'=>date("Y:m:d h:i:s")

			);
	echo $entry_voucher = $obj->Insert_Data_By_Cond("acc_voucher",$form_data,"_voutcher_no='$voucher_number'");
	
	
}


// ================================



if($opr=='voucher_gl_entry'){

    if($debit!=0){
     	$amount = $debit;
     	$trxn_type = 'D';
    }
    if($credit!=0){
     	$amount = $credit;
     	$trxn_type = 'C';
    }

	$form_data2=array(
			'_br_id'=>$branchid,
			'_voucher_id'=>$v_pid,
			'_gl_id'=>$gl_id,
			'_amount'=>$amount,
			'_trxn_type'=>$trxn_type,
			'_entry_by'=>$_SESSION['LOGIN_USERID'],
			'_entry_date'=>date("Y:m:d h:i:s"),
			'_status'=>'A'
			);
	$vc_gp = $obj->Insert_Data("acc_voucher_gl",$form_data2);
	if($vc_gp){
		echo $xy = $vc_gp.'-'.$sl.'-'.$trxn_type;
	}
}

if($opr=='voucher_sub_gl_entry'){

		$form_data3=array(
			'_br_id'=>$branchid,
			'_voucher_id'=>$v_pid,
			'_voucher_gl_id'=>$vcgl_id,
			'_sub_gl_id'=>$sub_gl_id,
			'_amount'=>$sub_gl_amount,
			'_trxn_type'=>$trxn_type,
			'_entry_by'=>$_SESSION['LOGIN_USERID'],
			'_entry_date'=>date("Y:m:d h:i:s"),
			'_status'=>'A'
			

			);
 $entry2 = $obj->Insert_Data("acc_voucher_sub_gl",$form_data3);

}

?>