<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class BiltyControllers extends CI_Controller {

//...............State construct............


public function __construct(){
parent::__construct();
$this->load->library("form_validation");
$this->load->model("BiltyModel");
$this->load->model("ConsigneeModel");
	$this->load->model("ConsignorModel");
$this->load->library('upload');
$this->load->library('session');
	$this->load->model("DestinationModel");

}



			public function fetch_Consignor()
					{


						$rsm=$this->input->post('name');

	              
				if($this->input->post('name'))
				  {
					    //print_r($rsm); die;
						$data =  $this->ConsignorModel->selectInfoBYID($this->input->post('name'));
					echo json_encode($data);
				  }
			}
			

			public function fetch_Consignee()
			{


				$rsm=$this->input->post('name');

		  
		if($this->input->post('name'))
		  {
				//print_r($rsm); die;
				$data =  $this->ConsigneeModel->selectInfoBYID($this->input->post('name'));
			echo json_encode($data);
		  }
	}
    //...............End construct............

//...............State index function............




		public function loktantra_senani_login()
	    	{
					$result['all_info_add_top'] = $this->AdvertisementModel->manageFrontInfo(2);
					$this->load->view('frontheader',$result);
	 	//	$this->load->view('add_sub_gallery');
	 			$this->load->view('loktantra_senani_login');
				  	$this->load->view('front_footer');

		}

		public function change_password_loktantra_senani()
				{
						$this->load->view('loktantra_senani_header');
		//	$this->load->view('add_sub_gallery');
				$this->load->view('change_password_loktantra_senani');
						$this->load->view('front_footer');

		}

		public function forgetpassword()
				{
					$result['all_info_add_top'] = $this->AdvertisementModel->manageFrontInfo(2);
					$this->load->view('frontheader',$result);
				$this->load->view('forgetpassword');
				$this->load->view('front_footer');
		}


		public function checkLogin(){

			$this->load->library("form_validation");

			$this->form_validation->set_rules('mobile','mobile','required');
			$this->form_validation->set_rules('PASSWORD','Password','required');

			if($this->form_validation->run() == true){

				$user_name = $this->input->post('mobile');
				$pass = $this->input->post('PASSWORD');

				$result = $this->LoktantraSenaniModel->checkLogin($user_name, $pass);

				if($result){

				//		print_r($result); die;
					$sess_data = array(

				"isUserLoggedIn"	=> TRUE,
						"id"=> $result['id']
					);

					$this->session->set_userdata($sess_data);

					$login_status = $this->LoktantraSenaniModel->logged_status("loktantra_senani_tb", array('login_status' => 1), array('id' => $result['id']));

					if($login_status){
									$this->session->set_userdata($sess_data);
								redirect('LoktantraSenaniControllers/getInfoByIdFront');
								}else{
									redirect('LoktantraSenaniControllers/loktantra_senani_login');
								}

				}else{
				//	echo "Enter your valid ID & Password.";
					$this->session->set_flashdata('msg', 'Enter your valid Mobile No. & Password..');
				}
			}
			redirect('LoktantraSenaniControllers/loktantra_senani_login');
		}



		public function logout(){



		$login_status = $this->LoktantraSenaniModel->logged_status("loktantra_senani_tb", array('login_status' => 0), array('id' => $this->session->userdata("id")));

		if($login_status){
				// print_r($sess_data); die;
		//	$this->session->unset_userdata($sess_data);
			$this->session->sess_destroy();
			redirect('LoktantraSenaniControllers/loktantra_senani_login');
		}else{
			redirect('LoktantraSenaniControllers/getInfoByIdFront');
		}
	}


	public function bilty_registration()
			{
			
				$this->load->view('admin/header');

				$result['single_data'] = $this->BiltyModel->getMaxInvoiceNo();
				$result['consignor_info'] = $this->ConsignorModel->selectInfoActive();
				$result['Consignee_info'] = $this->ConsigneeModel->selectInfoActive();
				$result['Destination_info'] = $this->DestinationModel->selectInfoActive();				


			$this->load->view('admin/add_bilty',$result);
			
	}






	function BiltyManageInfoPendding() {


$this->load->view('admin/header');

   	$result['all_info'] = $this->BiltyModel->BiltyManageInfoPendding($this->input->post('date1'),$this->input->post('date2'));

$this->load->view('admin/manage_pending_Bilty_Report', $result);


  }



function BiltyManageInfoComplete() {


	$this->load->view('admin/header');
	
		   $result['all_info'] = $this->BiltyModel->BiltyManageInfoComplete($this->input->post('date1'),$this->input->post('date2'));
	
	$this->load->view('admin/manage_complete_Bilty_Report', $result);
	
	
	}




function getInfoById() {

	$id = $this->uri->segment(3);
		 $data1['single_data'] = $this->BiltyModel->getInfoById($id);
		
			//print_r($data1); die;
		$this->load->view('admin/reciptA5_all',$data1);
		
		
		 }


		 function getInfoByIdConsignee() {

			$id = $this->uri->segment(3);
				 $data1['single_data'] = $this->BiltyModel->getInfoById($id);
				
					//print_r($data1); die;
				$this->load->view('admin/reciptA5_consignee',$data1);
				
				
				 }


				 function getInfoByIdConsignor() {

					$id = $this->uri->segment(3);
						 $data1['single_data'] = $this->BiltyModel->getInfoById($id);
						
							//print_r($data1); die;
						$this->load->view('admin/reciptA5_consignor',$data1);
						
						
						 }



		 function getInfoByIdBlank() {

			$id = $this->uri->segment(3);
				 $data1['single_data'] = $this->BiltyModel->getInfoById($id);
				
					//print_r($data1); die;
				$this->load->view('admin/reciptA5_blank',$data1);
				
				
				 }


		 function getFullInfoById() {

			$id = $this->uri->segment(3);
			$this->load->view('admin/header');
			$result['consignor_info'] = $this->ConsignorModel->selectInfo();
			$result['Consignee_info'] = $this->ConsigneeModel->selectInfo();
			$result['Destination_info'] = $this->DestinationModel->selectInfo();
		    $result['single_data'] = $this->BiltyModel->getInfoById($id);
				
					//print_r($data1); die;
				$this->load->view('admin/edit_bilty',$result);
				
				
				 }


		 




		public function insertInfo(){
		$data = array(

			'invoice_no' => $this->input->post('invoice_no'),
			'consignee_name' => $this->input->post('consignee_name'),
			'consignee_address' => $this->input->post('consignee_address'),
			'consignee_gstin' => $this->input->post('consignee_gstin'),
				'consignor_name' => $this->input->post('consignor_name'),
				'consignor_address' => $this->input->post('consignor_address'),
				'consignor_gstin' => $this->input->post('consignor_gstin'),
				'source' => $this->input->post('source'),
					'destination' => $this->input->post('destination'),
					'bill_date' => $this->input->post('bill_date'),
					'truck_no' => $this->input->post('truck_no'),
					'lot_no' => $this->input->post('lot_no'),
					'pr_no' => $this->input->post('pr_no'),
					'quality' => $this->input->post('quality'),
						'item' => $this->input->post('item'),
						'weight' => $this->input->post('weight'),
						'rate' => $this->input->post('rate'),
						'total_amount' => $this->input->post('total_amount'),
							'remark' => $this->input->post('remark'),
							'packages' => $this->input->post('packages'),
							'sms_no' => $this->input->post('sms_no'),
							'TYPE' => $this->input->post('TYPE'),
							'pm' => $this->input->post('pm')
							
		);

    	$id = $this->BiltyModel->insertInfo('transport_bilty_tb', $data);

		if($id){
		
			$this->session->set_flashdata('msg', 'data inserted.');

			$this->load->view('admin/header');

			$result['single_data'] = $this->BiltyModel->getMaxInvoiceNo();
			$result['consignor_info'] = $this->ConsignorModel->selectInfoActive();
			$result['Consignee_info'] = $this->ConsigneeModel->selectInfoActive();
			$result['Destination_info'] = $this->DestinationModel->selectInfoActive();				


		$this->load->view('admin/add_bilty',$result);

			}
			else{
			$this->session->set_flashdata('msg', 'error...');
			$this->load->view('admin/header');

				$result['single_data'] = $this->BiltyModel->getMaxInvoiceNo();
				$result['consignor_info'] = $this->ConsignorModel->selectInfoActive();
				$result['Consignee_info'] = $this->ConsigneeModel->selectInfoActive();
				$result['Destination_info'] = $this->DestinationModel->selectInfoActive();				


			$this->load->view('admin/add_bilty',$result);

			}



	}



       function updateInfoById() {

    $id= $this->input->post('id');

      $data = array(

		'invoice_no' => $this->input->post('invoice_no'),
		'consignee_name' => $this->input->post('consignee_name'),
		'consignee_address' => $this->input->post('consignee_address'),
		'consignee_gstin' => $this->input->post('consignee_gstin'),
			'consignor_name' => $this->input->post('consignor_name'),
			'consignor_address' => $this->input->post('consignor_address'),
			'consignor_gstin' => $this->input->post('consignor_gstin'),
			'source' => $this->input->post('source'),
				'destination' => $this->input->post('destination'),
				'bill_date' => $this->input->post('bill_date'),
				'truck_no' => $this->input->post('truck_no'),
				'lot_no' => $this->input->post('lot_no'),
				'pr_no' => $this->input->post('pr_no'),
				'quality' => $this->input->post('quality'),
					'item' => $this->input->post('item'),
					'weight' => $this->input->post('weight'),
					'rate' => $this->input->post('rate'),
					'total_amount' => $this->input->post('total_amount'),
						'remark' => $this->input->post('remark'),
						'packages' => $this->input->post('packages'),
						'sms_no' => $this->input->post('sms_no'),
						'TYPE' => $this->input->post('TYPE'),
						'pm' => $this->input->post('pm'),
						'paid_amount' => $this->input->post('paid_amount')
						


      ) ;


      $this->BiltyModel->updateInfoById($id,$data);

	 
$this->load->view('admin/header');

$result['all_info'] = $this->BiltyModel->BiltyManageInfoPendding($this->input->post('date1'),$this->input->post('date2'));

$this->load->view('admin/manage_pending_Bilty_Report', $result);
     }



public function changepassword(){


	$id = $this->session->userdata("id");

$data = array(
	'PASSWORD' => $this->input->post('PASSWORD')
);


	$this->LoktantraSenaniModel->updatePasswordById($id,$data);

			redirect("LoktantraSenaniControllers/logout");

}

public function selectPassword(){


	$mobile = $this->input->post('mobile');
	$message = $this->input->post('message');

	 	//print_r($result); die;

		$this->LoktantraSenaniModel->mySms($mobile,$message );

	redirect("LoktantraSenaniControllers/loktantra_senani_login");

}



public function deleteInfo()
{
$id = $this->uri->segment(3);

//	print_r($id); die;

$this->BiltyModel->deleteInfo($id);

$this->load->view('admin/header');

   	$result['all_info'] = $this->BiltyModel->BiltyManageInfoPendding($this->input->post('date1'),$this->input->post('date2'));

$this->load->view('admin/manage_pending_Bilty_Report', $result);

}


   	//...............End Update Subgallery By ID ............
	


}
