<?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.reference1 LIKE '%".$array['search']."%' OR b.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.biller_code, a.reference1, a.reference2, a.reference3, a.reference4, a.amount, a.status, a.created_at, b.title, c.file FROM staff_rms_bill_order a
                          LEFT JOIN staff_rms_bill b ON ( a.bill_id = b.bill_id )
                          LEFT JOIN rms_bill_item c ON ( b.item_id = c.item_id )
                          WHERE a.deleted_at IS NULL AND a.staff_id = '".$staff_info['staff_id']."' " . $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/RmsBillItem/b/'.$row['file'] : '' ) ;
            $list[]                 = $row ;
        }

        $data['list']  = $list ;

    }
}

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