<?php

namespace App\Models;

use CodeIgniter\Model;
use CodeIgniter\I18n\Time;

class Md_student extends Model {
    
    public $db;

    public function __construct() {
        parent::__construct();
        $this->db = \Config\Database::connect();
        
    }
    
    
       public function HostelFeesmst() {

        $result = $this->db
                ->table('fees')
                ->where('pk_id', 1)
                ->get()
                ->getRow();
        return $result;
    }
    
    
     public function GetAllDraft() {
     
         $regdate =new \DateTime('now');
         $time = Time::parse('1 month ago');
         $regdatet= $time->toDateTimeString();

/*
        $result = $this->db
                ->table('student')
                ->whereIn('status',[2,3])
                ->where('payment_status !=', '1')
                ->where('created_date<=',$regdatet)
                ->delete();
                
        return $result;
  */      
        $result = $this->db
                ->table('student')
                // ->whereIn('pk_id',[1])
                ->where('payment_status !=', '1')
                ->where('created_date<=',$regdatet)
                ->get()
                ->getResult('array');
                 
        return $result;
    }
    
     public function DeleteAllDraft($pk_id) {
        $this->db
                ->table('student')
                ->where('pk_id',$pk_id)
                // ->whereIn('status',[2,3])
                // ->where('payment_status !=', '1')
                // ->where('created_date<=',$regdatet)
                ->delete();
                
        return true;
    }
    
      public function AllDraftStudent() {
     
         $regdate =new \DateTime('now');
         $time = Time::parse('1 month ago');
         $regdatet= $time->toDateTimeString();

        $result = $this->db
                ->table('student')
                ->select('pk_id,payment_status,status,year,created_date')
                ->where('status!=',1)
                ->where('payment_status !=', '1')
                ->where('created_date<=',$regdatet)
                // ->where('pk_id', '21174')
                ->get()
                ->getResult('array');
                
        return $result;
        
        // $result = $this->db
        //         ->table('student')
        //         // ->where('status',1)
        //         // ->where('year !=', date('Y'))
        //         // ->where('payment_status', 1)
        //         ->get()
        //         ->getRow();
                 
        return $result;
    }
    
     public function FormDataOfStudent($loginid,$formid) {

        $result = $this->db
                ->table('student')
                ->where('fk_login_id', $loginid)
                ->where('pk_id', $formid)
                ->where('payment_status', 5)
                ->get()
                ->getRow();
        return $result;
    }
    
     public function PaymentGatewayConfig($id) {

        $result = $this->db
                ->table('payment_mode')
                ->where('type', $id)
                ->get()
                ->getRow();
        return $result;
    }
    
      public function Hostels($userid) {

        $result = $this->db
                ->table('name')
                ->where('pk_id', $userid)
                ->get()
                ->getRow();
        return $result;
    }
    
     public function OrderHistory($userid) {

        $result = $this->db
                ->table('student')
                ->where('fk_login_id', $userid)
                ->get()
                ->getResult('array');
        return $result;
    }
    
       public function UpdateData($table, $pk_id, $data = array()) {
        $this->db
                ->table($table)
                ->update($data, $pk_id);
        return true;
    }
    
 public function OTPVerifyNow($otp) {

        $notifications = $this->db
                ->table('otp_verify')
                ->where('otp', $otp)
                ->where('verify', 1)
                ->limit(1)
                ->get()
                ->getRow();
        return $notifications;
    }
    
  public function OTPVerifyCheck($Mobile) {

        $notifications = $this->db
                ->table('otp_verify')
                ->where('mobile', $Mobile)
                ->where('verify', 1)
                ->limit(1)
                ->get()
                ->getRow();
        return $notifications;
    }
    
    public function MobilenoUniqueCheck($Mobile) {

        $notifications = $this->db
                ->table('login')
                ->where('mobile', $Mobile)
                ->where('status !=', 3)
                ->limit(1)
                ->get()
                ->getRow();
        return $notifications;
    }

  public function loginCheck($Mobile,$EncryPassword) {

        $notifications = $this->db
                ->table('login')
                ->where('mobile', $Mobile)
                ->where('password', $EncryPassword)
                ->where('status', 1)
                ->limit(1)
                ->get()
                ->getRow();
        return $notifications;
    }
    
    public function InsertLoginAction($table, $data) {
        $this->db->table($table)->insert($data);
        $result=$this->db->insertID();
        return $result;
    }


}
