<?php
	
	namespace App\Http\Model;
	use Illuminate\Database\Eloquent\Model;
	use DB;
	use Auth;
	class IncomeExpeneModel extends Model
	{
		
		public function QPermission($id)
	 	{
		    $QModules=DB::table('modules')->select('Mid')->where('mUrl',$id['url'])->first();
			$Mid=$QModules->Mid;
			return $Qpermission=DB::table('permission')->where('Mid',$Mid)->first();
		}
		public function Income()
		{
			return $Expence=DB::table('income')->where('incomeActive','0')->get();
			
		}
		public function Expence()
		{
			return $Expence=DB::table('Expence')->where('ExpenceStatus','0')->get();
			
		}
		public function submitincome($id)
		{
			return $Income=DB::table('trn_transaction')->insertGetId(['trn_type'=>'Income','trn_code'=>'000','trn_billno'=>'000','cst_id'=>'000','br_id'=>'000','trn_amt'=>$id['amount'],'trn_date'=>date('Y-m-d'),'trn_note'=>$id['duration'],'trn_paytype'=>'000','trn_paydetail'=>$id['duration1'],'trn_status'=>'Active']);
			
		}
		public function submitExpense($id)
		{
			return $Income=DB::table('trn_transaction')->insertGetId(['trn_type'=>'Expense','trn_code'=>'000','trn_billno'=>'000','cst_id'=>'000','br_id'=>'000','trn_amt'=>$id['amount'],'trn_date'=>date('Y-m-d'),'trn_note'=>$id['duration'],'trn_paytype'=>'000','trn_paydetail'=>$id['duration1'],'trn_status'=>'Active']);
			
		}
		public function IncomecategoryUpdate($id)
		{
			return $Income=DB::table('income')->insertGetId(['IncomeName'=>$id['Incomecategory'],'IncomeType'=>$id['Incomecategory1'],'Inamount'=>$id['amount']]);
		}
		public function ExpencecategoryUpdate($id)
		{
			return $expense=DB::table('Expence')->insertGetId(['ExpenceName'=>$id['Incomecategory'],'ExpenceType'=>$id['Incomecategory1'],'ExAmount'=>$id['amount']]);
		}
		public function IncomeReport()
		{
			return $Income=DB::table('trn_transaction')
			->leftjoin('income','income.incomeId','=','trn_transaction.trn_paydetail')
			->where('trn_type','Income')
			->get();
		}
		public function ExpenseReport()
		{
			return $expense=DB::table('trn_transaction')
			->leftjoin('Expence','Expence.ExpenceId','=','trn_transaction.trn_paydetail')
			->where('trn_type','Expense')
			->get();
		}
	}		
	
