<?php

class Service_model extends CI_Model {

    function __construct() {
        
    }

    public function getAdminDashData($data) {
        $out = array();
        $y = $this->getDashRecentSignup(10);
        $out['recent_signup'] = $y['recent_signup'];
        return $out;
    }

    
    public function getServiceRequestListStatus($serviceType,$statusList, $limit) {
        $out = array();
        
        
        
        $mysql = "SELECT r.id AS service_request_id,DATE_PART('day', r.service_date - now() ) AS day_gap, r.*,a.agent_name,m.firstname,m.lastname,m.email,m.phone,"
                . " s.service AS service_type_text "
                . " FROM members_service_request r "
                . " LEFT JOIN members m ON m.id = r.member_id LEFT JOIN agents a ON a.id=r.agent_id LEFT JOIN service_types s ON s.id = r.service_type "
                . " WHERE r.service_type=".$serviceType." AND r.flags IN(".$statusList.") ORDER BY r.id DESC LIMIT $limit ";


        $q = $this->db->query($mysql);
        $out['service_request_list'] = $q->result();
        return $out;
    }

    
    public function getServiceRequestList($limit) {
        $out = array();
        $mysql = "SELECT r.id AS service_request_id,DATE_PART('day', r.service_date - now() ) AS day_gap, r.*,a.agent_name,m.firstname,m.lastname,m.email,m.phone,"
                . " s.service AS service_type_text "
                . " FROM members_service_request r "
                . " LEFT JOIN members m ON m.id = r.member_id LEFT JOIN agents a ON a.id=r.agent_id LEFT JOIN service_types s ON s.id = r.service_type "
                . "  ORDER BY r.id DESC LIMIT $limit ";


        $q = $this->db->query($mysql);
        $out['service_request_list'] = $q->result();
        return $out;
    }

    public function getMemberServiceRequestList($member_id, $limit) {
        $out = array();
        $mysql = "SELECT r.id AS service_request_id,DATE_PART('day', r.service_date - now() ) AS day_gap, r.*,a.agent_name,m.firstname,m.lastname,m.email,m.phone,"
                . " s.service AS service_type_text "
                . " FROM members_service_request r "
                . " LEFT JOIN members m ON m.id = r.member_id LEFT JOIN agents a ON a.id=r.agent_id LEFT JOIN service_types s ON s.id = r.service_type WHERE r.member_id= " . $member_id
                . "  ORDER BY r.id DESC LIMIT $limit ";


        $q = $this->db->query($mysql);
        $out['service_request_list'] = $q->result();
        return $out;
    }

    /*
     * 
     *  id | pid | member_id | agent_id | service_type |    service_date     |           added            | status | flags |       loc       | dist_mode | miles | minutes |         agent_name         | firstname | lastname |          email          |   phone    
----+-----+-----------+----------+--------------+---------------------+----------------------------+--------+-------+-----------------+-----------+-------+---------+----------------------------+-----------+----------+-------------------------+------------
  1 | 100 |        11 |        3 |            3 | 2018-04-10 16:30:00 | 2018-04-23 17:12:33.642712 |      1 |     1 | 104.238.127.115 |           |     0 |       0 | Agenr Name with name 10003 | Thompson  | david    | ses66181+5726@gmail.com | 7702223282
  2 | 100 |         3 |        4 |            3 | 2018-04-10 18:30:00 | 2018-04-23 17:13:13.310014 |      1 |     1 | 104.238.127.115 |           |     0 |       0 | Agenr Name with name 10004 | nidia     | Kate     | ses66181+5514@gmail.com | 7702222657
  3 | 100 |        10 |        6 |            5 | 2018-04-10 07:30:00 | 2018-04-23 17:13:50.357451 |      1 |     1 | 104.238.127.115 |           |     0 |       0 | Agenr Name with name 10006 | mayowa    | Idowu    | ses66181+4862@gmail.com | 7702224559
  4 | 100 |        13 |        6 |            2 | 2018-04-10 18:30:00 | 2018-04-23 17:14:03.610904 |      1 |     1 | 104.238.127.115 |           |     0 |       0 | Agenr Name with name 10006 | Oyewumi   | Olalekan | ses66181+6839@gmail.com | 7702225690
  5 | 100 |        13 |        7 |            2 | 2018-04-10 15:30:00 | 2018-04-23 17:14:07.596965 |      1 |     1 | 104.238.127.115 |           |     0 |       0 | Agenr Name with name 86517 | Oyewumi   | Olalekan | ses66181+6839@gmail.com | 7702225690
  6 | 100 |         2 |        9 |            2 | 2018-04-10 17:30:00 | 2018-04-23 17:14:28.341037 |      1 |     1 | 104.238.127.115 |           |     0 |       0 | Agenr Name with name 3297  | Caroline  | travis   | ses66181+5527@gmail.com | 7702226881

kleen=> select * from service_types;
 id |        service        |      description      | status |           added            
----+-----------------------+-----------------------+--------+----------------------------
  1 | Laundry Drop Off      | Laundry Drop Off      |      1 | 2018-04-17 11:36:42.94168
  2 | Dryclean Pick & Deliv | Dryclean Pick & Deliv |      1 | 2018-04-17 11:36:42.953587
  3 | Home Cleaning         | Home Cleaning         |      1 | 2018-04-17 11:36:42.984192
  4 | Home Laundry          | Home Laundry          |      1 | 2018-04-17 11:36:42.990875
  5 | Wash/Fold             | Wash/Fold             |      1 | 2018-04-17 11:36:43.003582
(5 rows)



     */
    
}
