<?php
$must_login            = true ;
$require_path          = '../../../' ;
$require_sub           = '../../' ;
require( $require_sub.'header.php' ) ;

if ( $boolean_login ){
    $status            = '201' ;

    $searchfilter      = $array['searchfilter'] ;

    $search_query      = '' ;
    if ( $array['search'] != '' ){
        $search_query .= " AND ( a.sonumber LIKE '%".$array['search']."%' OR a.dialcode LIKE '%".$array['search']."%' OR a.mobile LIKE '%".$array['search']."%' OR c.title LIKE '%".$array['search']."%' )" ;
    }
    switch ( $searchfilter ){
        case 'pending'   :
            $search_query .= " AND a.status IN ( 'new', 'pending', 'progress' )" ;
        break ;
        case 'confirmed' :
            $search_query .= " AND a.status IN ( 'confirmed' )" ;
        break ;
        case 'cancelled' :
            $search_query .= " AND a.status IN ( 'cancelled', 'failed' )" ;
        break ;
    }

    $query             = "SELECT a.order_id, a.sonumber, a.deno_code, a.dialcode, a.mobile, a.amount, a.status, a.created_at, b.file , c.title FROM staff_rms_prepaid_order a
                          LEFT JOIN rms_prepaid_item b ON ( a.item_id = b.item_id )
                          LEFT JOIN rms_prepaid_deno_translation c ON ( a.deno_id = c.deno_id )
                          WHERE a.deleted_at IS NULL AND a.staff_id = '".$staff_info['staff_id']."' AND c.lang = '".$array['lang']."' " . $search_query ;
    $mysqli_query      = $mysqli->query( $query . " ORDER BY a.order_id DESC LIMIT " . getLimit( $current ) ) ;

    if ( $mysqli_query->num_rows > 0 ){

        $status        = '200' ;

        $list          = [] ;
        while ( $row   = $mysqli_query->fetch_assoc() ){
            $row['created_at']      = resetDateFormat( $row['created_at'] ) ;
            $row['order_status']    = ( checkExists( $row['status'] ) != '' ? $row['status'] : '' ) ;
            $row['file']            = ( $row['file'] != '' ? PATH.'uploads/RmsPrepaidItem/b/'.$row['file'] : '' ) ;
            $list[]                 = $row ;
        }

        $data['list']  = $list ;

    }
}

require( $require_sub.'footer.php' ) ;
?>