<?php
	namespace App\Http\Controllers;
	use Illuminate\Foundation\Bus\DispatchesJobs;
	use Illuminate\Routing\Controller as BaseController;
	use Illuminate\Foundation\Validation\ValidatesRequests;
	use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
	use Illuminate\Foundation\Auth\Access\AuthorizesResources;
	use Illuminate\Http\Request;
	use DB;
	use App\Http\Model\DelayPaymentModel;
	use Validator;
	
	class DelayPaymentController extends Controller
	{
		public function __construct()
		{
			$this->User= new DelayPaymentModel;
		}
		public function LoadDelaypayment()
		{
			$data['url']='delaypayment';
		    $Mid=$this->User->BranchPermission($data);
			$data['delete']= $Mid->Delete;
			$data['edit']= $Mid->Edit;
			$data['create']= $Mid->create;
			$status= 'Deleted';
			$data['delaypayment']=DB::table('dpmt_delaypayment')->where([["dpmt_status","<>",$status]])->get();
			return view('delaypayment',compact('data'));
		}		
		public function InsertdelaypaymenttypePost(Request $req)
		{
			$dpmt_id = $req->input('dpmt_id');
			$dpmt_charge= $req->input('dpmt_charge');
			$status = $req->input('dpmt_status');
			
			if($dpmt_id == 0)
			{
				$data = array('dpmt_charge'=>$dpmt_charge,'dpmt_status'=>$status);
				$insertdetails = DB::table('dpmt_delaypayment')->insert($data);
				if (!is_null($insertdetails))
				{
					return response()->json(['status' => '1', 'message' => trans('Record Inserted Successfully.')]);
				}
				else
				{
					return response()->json(['status' => '0', 'message' => trans('Error in Insertion.. Please Try again..')]);
				}
			}
			else
			{
				$data = array('dpmt_charge'=>$dpmt_charge,'dpmt_status'=>$status);
				$updatedetails = DB::table('dpmt_delaypayment')->where('dpmt_id',$dpmt_id)->update($data);
				if (!is_null($updatedetails))
				{
					return response()->json(['status' => '1', 'message' => trans('Record Updated Successfully.')]);
				}
				else
				{
					return response()->json(['status' => '0', 'message' => trans('Error in Updation.. Please Try again..')]);
				}
			}
		}
		public function Editdelaypaymenttype(Request $req)
		{
			$id = $req->id;
			$branch = DB::table('dpmt_delaypayment')->where(['dpmt_id'=>$id])->get();
			return response()->json($branch);
		}
		public function Deletedelaypaymenttype(Request $req)
		{
			$id = $req->id;
			$status= 'Deleted';
			$data = array('dpmt_status'=>$status);
			
			$UpdateDetails = DB::table('dpmt_delaypayment')->where('dpmt_id',$id)->update($data);
			if (!is_null($UpdateDetails))
			{
				return response()->json(['status' => '1', 'message' => trans('Record Deleted Successfully.')]);
			}
			else
			{
				return response()->json(['status' => '0', 'message' => trans('Error in Deletion.. Please Try again..')]);
			}
		}
	}
