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

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, OPTIONS, POST, GET, PUT");
header("Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding");

date_default_timezone_set('Asia/Kolkata');

class Admin extends CI_Controller {
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/userguide3/general/urls.html
	 */
	
	public function all_shops()
	{
		$data=$this->Admin_model->get_all_shops();
		echo json_encode($data);
	}
	public function all_company()
	{
		$data=$this->Admin_model->get_all_company();
		echo json_encode($data);
	}
	public function get_Owners()
	{
		$data=$this->Admin_model->get_Owners();
		echo json_encode($data);
	}
	public function add_OwnersAccount()
	{
	    $UserName=$this->input->get('UserName');
	    $Password=$this->input->get('Password');
		$data=$this->Admin_model->add_OwnersAccount($UserName,$Password);
		echo json_encode($data);
	}
	public function add_ShopUsers()
	{
	    $UserName=$this->input->get('UserName');
	    $Password=$this->input->get('Password');
	    $ShopID=$this->input->get('ShopID');
	    $UserType=$this->input->get('UserType');
		$data=$this->Admin_model->add_ShopUsers($UserName,$Password,$ShopID,$UserType);
		echo json_encode($data);
	}
	public function update_ShopUsers()
	{
	    $UserID=$this->input->get('UserID');
	    $Password=$this->input->get('Password');
	    $UserType=$this->input->get('UserType');
		$data=$this->Admin_model->update_ShopUsers($UserID,$Password,$UserType);
		echo json_encode($data);
	}
	public function get_ShopUsers()
	{
	    $ShopID=$this->input->get('ShopID');
		$data=$this->Admin_model->get_ShopUsers($ShopID);
		echo json_encode($data);
	}
	public function get_ShopUserByID()
	{
	    $UserID=$this->input->get('UserID');
		$data=$this->Admin_model->get_ShopUserByID($UserID);
		echo json_encode($data);
	}
	public function delete_ShopUsers()
	{
	    $UserID=$this->input->get('UserID');
		$data=$this->Admin_model->delete_ShopUsers($UserID);
		echo json_encode($data);
	}
	public function delete_OwnersAccount()
	{
	    $UserName=$this->input->get('UserName');
		$data=$this->Admin_model->delete_OwnersAccount($UserName);
		echo json_encode($data);
	}
	public function get_owners_details()
	{
	    $UserID=$this->input->get('UserID');
        $check=$this->Admin_model->get_owners_details($UserID);
		echo json_encode($check);
	}
	public function get_owners_ShopBills()
	{
	    $UserID=$this->input->get('UserID');
	    $EntryDate=$this->input->get('EntryDate');
	    $ShopName=$this->input->get('ShopName');
	    $StaffName=$this->input->get('StaffName');
        $check=$this->Admin_model->get_owners_ShopBills($UserID,$EntryDate,$ShopName,$StaffName);
		echo json_encode($check);
	}
	
	public function owner_ChairStatus()
	{
	    $UserID=$this->input->get('UserID');
        $check=$this->Admin_model->owner_ChairStatus($UserID);
		echo json_encode($check);
	}
	public function admin_dashboard()
	{
		$data=$this->Admin_model->admin_dashboard();
		echo json_encode($data);
	}
	
	public function get_shop()
	{
	    $ShopID=$this->input->get('ShopID');
        $check=$this->Admin_model->get_shop($ShopID);
		echo json_encode($check);
	}
	
	public function get_company()
	{
	    $CompanyID=$this->input->get('CompanyID');
        $check=$this->Admin_model->get_company($CompanyID);
		echo json_encode($check);
	}
	
	public function get_staff_dashbord()
	{
	    $ShopID=$this->input->get('ShopID');
        $check=$this->Admin_model->get_staff_dashbord($ShopID);
		echo json_encode($check);
	}
	public function get_staffBills()
	{
	    $StaffID=$this->input->get('StaffID');
	    $EntryDate=$this->input->get('EntryDate');
	    $ShopID=$this->input->get('ShopID');
        $check=$this->Admin_model->get_staffBills($StaffID,$EntryDate,$ShopID);
		echo json_encode($check);
	}
	public function update_bill()
	{
	    $BID=$this->input->get('BID');
	    $Amount=$this->input->get('Amount');
	    $Cash=$this->input->get('Cash');
	    $Card=$this->input->get('Card');
	    $Customer=$this->input->get('Customer');
	    $Mobile=$this->input->get('Mobile');
	    $Net=$this->input->get('Net');
	    $Tax=$this->input->get('Tax');
        $check=$this->Admin_model->update_bill($BID,$Amount,$Cash,$Card,$Customer,$Mobile,$Net,$Tax);
		echo json_encode($check);
	}
	//================================Add Shop =============================
	public function add_shop()
	{
	    $shops=json_decode($this->input->post('shops'));
	    $check=$this->Admin_model->insert_shop($shops);
		echo json_encode($check);
	}
	public function update_shop()
	{
	    $shops=json_decode($this->input->post('shops'));
	    $check=$this->Admin_model->update_shop($shops);
		echo json_encode($check);
	}
	public function delete_shop()
	{
	    $ShopID=$this->input->get('ShopID');
	    $check=$this->Admin_model->delete_shop($ShopID);
		echo json_encode($check);
	}
	public function delete_company()
	{
	    $CompanyID=$this->input->get('CompanyID');
	    $check=$this->Admin_model->delete_company($CompanyID);
		echo json_encode($check);
	}
	//================================Add Shop =============================

    //===========Syncing=============================================
	//================================Add Chair =============================
	public function add_chair()
	{
	    $chair=json_decode($this->input->post('chair'));
	    $check=$this->Admin_model->insert_chair($chair);
		echo json_encode($check);
	}

	public function update_chair()
	{
	    $chair=json_decode($this->input->post('chair'));
	    $check=$this->Admin_model->update_chair($chair);
		echo json_encode($check);
	}
	public function all_chairs()
	{
	    $ShopID=$this->input->get('ShopID');
		$data=$this->Admin_model->get_all_Chairs($ShopID);
		echo json_encode($data);
	}
	//================================Add Chair =============================

	//================================Add Item =============================
	public function add_item()
	{
	    $item=json_decode($this->input->post('item'));
	    $check=$this->Admin_model->insert_item($item);
		echo json_encode($check);
	}
	public function update_item()
	{
	    $item=json_decode($this->input->post('item'));
	    $check=$this->Admin_model->update_item($item);
		echo json_encode($check);
	}
	public function add_owner()
	{
	    $details=json_decode($this->input->post('details'));
	    $Shops=json_decode($this->input->post('Shops'));
	    $check=$this->Admin_model->add_owner($details,$Shops);
		echo json_encode($check);
	}
	public function update_owner()
	{
	    $details=json_decode($this->input->post('details'));
	    $Shops=json_decode($this->input->post('Shops'));
	    $check=$this->Admin_model->update_owner($details,$Shops);
		echo json_encode($check);
	}
	public function change_pwd_owner()
	{
	    $UserName=$this->input->get('UserName');
	    $OldPwd=$this->input->get('OldPwd');
	    $NewPwd=$this->input->get('NewPwd');
 	    $check=$this->Admin_model->change_pwd_owner($UserName,$OldPwd,$NewPwd);
		echo json_encode($check); 	    
	}
	public function all_items()
	{
	    $ShopID=$this->input->get('ShopID');
		$data=$this->Admin_model->get_all_Items($ShopID);
		echo json_encode($data);
	}
	//================================Add Chair =============================
    public function get_shop_chair_status()
	{
	    $ShopID=$this->input->get('ShopID');
 	    $check=$this->Admin_model->get_shop_chair_status($ShopID);
 		echo json_encode($check);
	}


	public function chair_status()
	{
	    $ChairID=$this->input->get('ChairID');
	    $StaffID=$this->input->get('StaffID');
	    $Status=$this->input->get('Status');
	    $EntryDate=$this->input->get('EntryDate');
 	    $check=$this->Admin_model->chair_status($ChairID,$StaffID,$Status,$EntryDate);
 		echo json_encode($check);
	}
	
		public function get_dattym()
	{
	    
 	    $check=$this->Admin_model->get_dattym();
 		echo json_encode($check);
	}
	

	public function upload_image()
	{
	    $details=json_decode($this->input->post('details'));
 	    $check=$this->Admin_model->upload_image($details);
 		echo json_encode($check);
	}

	//================================Add Staff =============================
	public function add_staff()
	{
 	    $staff=json_decode($this->input->post('staff'));
 	    $ProofDetails=json_decode($this->input->post('ProofDetails'));
 	    $check=$this->Admin_model->insert_staff($staff,$ProofDetails);
 		echo json_encode($check);
	}
	
	public function update_staff()
	{
	    $staff=json_decode($this->input->post('staff'));
	    $ProofDetails=json_decode($this->input->post('ProofDetails'));
	    $check=$this->Admin_model->update_staff($staff,$ProofDetails);
		echo json_encode($check);
	}
	public function add_billing()
	{
	    $details=json_decode($this->input->post('details'));
	    $items=json_decode($this->input->post('items'));
	    $check=$this->Admin_model->add_billing($details,$items);
	    //$check=$items;
	    echo json_encode($check);
	}
	public function add_expenses()
	{
	    $details=json_decode($this->input->post('details'));
	    $items=json_decode($this->input->post('items'));
	    $check=$this->Admin_model->add_expenses($details,$items);
	    //$check=$items;
	    echo json_encode($check);
	}
	//================================Add Staff =============================

	//================================Login =============================
	public function shop_login()
	{
	    $username=$this->input->get('username'); 
	    $password=$this->input->get('password');
	    $check=$this->Admin_model->check_login($username,$password);
		echo json_encode($check);
	}
	public function owner_login()
	{
	    $username=$this->input->get('username'); 
	    $password=$this->input->get('password');
	    $check=$this->Admin_model->owner_login($username,$password);
		echo json_encode($check);
	}
	public function admin_login()
	{
	    $username=$this->input->get('username');
	    $password=$this->input->get('password');
	    $check=$this->Admin_model->admin_login($username,$password);
		echo json_encode($check);
	}
	public function add_admin()
	{
	    $username=$this->input->get('username');
	    $password=$this->input->get('password');
	    $usertype=$this->input->get('usertype');
	    $check=$this->Admin_model->add_admin($username,$password,$usertype);
		echo json_encode($check);
	}
	//========================Reports====================================	
	public function owner_allstaff()
	{
	    $UserID=$this->input->get('UserID');
 	    $check=$this->Admin_model->owner_allstaff($UserID);
 		echo json_encode($check);
	}
	public function owner_allChairs()
	{
	    $UserID=$this->input->get('UserID');
 	    $check=$this->Admin_model->owner_allChairs($UserID);
 		echo json_encode($check);
	}
	public function owner_Shops()
	{
	    $UserID=$this->input->get('UserID');
 	    $check=$this->Admin_model->owner_Shops($UserID);
 		echo json_encode($check);
	}
	public function owner_sales_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $ShopName=$this->input->get('ShopName');
 	    $check=$this->Admin_model->owner_sales_report($UserID,$SDate,$EDate,$ShopName);
 		echo json_encode($check);
	}
	public function owner_salessummary_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $ShopName=$this->input->get('ShopName');
 	    $check=$this->Admin_model->owner_salessummary_report($UserID,$SDate,$EDate,$ShopName);
 		echo json_encode($check);
	}
	public function owner_staff_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $Staff=$this->input->get('Staff');
 	    $check=$this->Admin_model->owner_staff_report($UserID,$SDate,$EDate,$Staff);
 		echo json_encode($check);
	}

	public function owner_staffsummary_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $Staff=$this->input->get('Staff');
 	    $check=$this->Admin_model->owner_staffsummary_report($UserID,$SDate,$EDate,$Staff);
 		echo json_encode($check);
	}
    public function owner_chair_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $chair=$this->input->get('chair');
 	    $check=$this->Admin_model->owner_chair_report($UserID,$SDate,$EDate,$chair);
 		echo json_encode($check);
	}
	public function owner_chairsummary_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $chair=$this->input->get('chair');
 	    $check=$this->Admin_model->owner_chairsummary_report($UserID,$SDate,$EDate,$chair);
 		echo json_encode($check);
	}
    public function owner_expense_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $ShopName=$this->input->get('ShopName');
 	    $check=$this->Admin_model->owner_expense_report($UserID,$SDate,$EDate,$ShopName);
 		echo json_encode($check);
	}
	public function owner_expensesummary_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $ShopName=$this->input->get('ShopName');
 	    $check=$this->Admin_model->owner_expensesummary_report($UserID,$SDate,$EDate,$ShopName);
 		echo json_encode($check);
	}
	public function activity_report()
	{
	    $UserID=$this->input->get('UserID');
	    $SDate=$this->input->get('SDate');
 	    $EDate=$this->input->get('EDate');
 	    $ShopName=$this->input->get('ShopName');
 	    $Staff=$this->input->get('Staff');
 	    $check=$this->Admin_model->activity_report($UserID,$SDate,$EDate,$ShopName,$Staff);
 		echo json_encode($check);
	}
    public function TimeSheet_report()
	{
	    $EntryDate=$this->input->get('EntryDate');
 	    $StaffID=$this->input->get('StaffID');
 	    $check=$this->Admin_model->TimeSheet_reportB($EntryDate,$StaffID);
 		echo json_encode($check);
	}
	public function closing_report()
	{
	    $ShopID=$this->input->get('ShopID');
	    $EntryDate=$this->input->get('EntryDate');
 	    $check=$this->Admin_model->closing_report($ShopID,$EntryDate);
 		echo json_encode($check);
	}
	public function close_day()
	{
	    $ShopID=$this->input->get('ShopID');
	    $EntryDate=$this->input->get('EntryDate');
 	    $check=$this->Admin_model->close_day($ShopID,$EntryDate);
 		echo json_encode($check);
	}
	public function billing_report()
	{
	    $ShopID=$this->input->get('ShopID');
	    $EntryDate=$this->input->get('EntryDate');
	    $SDate=$this->input->get('SDate');
	    $EDate=$this->input->get('EDate');
	    $StaffID=$this->input->get('StaffID');
 	    $check=$this->Admin_model->billing_report($ShopID,$SDate,$EDate,$StaffID);
 		echo json_encode($check);
	}
	public function expenses_report()
	{
	    $ShopID=$this->input->get('ShopID');
	    $SDate=$this->input->get('SDate');
	    $EDate=$this->input->get('EDate');
 	    $check=$this->Admin_model->expenses_report($ShopID,$SDate,$EDate);
 		echo json_encode($check);
	}
	public function staff_report()
	{
	    $ShopID=$this->input->get('ShopID');
	    $SDate=$this->input->get('SDate');
	    $EDate=$this->input->get('EDate');
	    $StaffID=$this->input->get('StaffID');
 	    $check=$this->Admin_model->staff_report($ShopID,$SDate,$EDate,$StaffID);
 		echo json_encode($check);
	}
	public function staff_summary_report()
	{
	    $ShopID=$this->input->get('ShopID');
	    $SDate=$this->input->get('SDate');
	    $EDate=$this->input->get('EDate');
	    $StaffID=$this->input->get('StaffID');
 	    $check=$this->Admin_model->staff_summary_report($ShopID,$SDate,$EDate,$StaffID);
 		echo json_encode($check);
	}	
	
	//============================================================
	public function change_status()
	{
	    $status=json_decode($this->input->post('status'));
	    $check=$this->Admin_model->update_staff($status);
	    
		echo json_encode($check);
	}
	//============================================================

	public function add_company()
	{
	    $status=false;
	    $company=json_decode($this->input->post('company'));
	    $check=$this->Admin_model->insert_company($company);
		echo json_encode($check);
	}
	public function update_company()
	{
	    $company=json_decode($this->input->post('company'));
	    $check=$this->Admin_model->update_company($company);
		echo json_encode($check);
	}
	
}
