<?php
    error_reporting(0);
        if ($voucher) {
            $date_now = date('m/d/Y');
            $date = str_replace('/', '-', $date_now);
            $date_last = str_replace('/', '-', $register[0]->date_last);
            if ($date <= $date_last){
                $no=1;
                if ($voucher == $register[0]->voucher && $register[0]->used == 0){
                    $data_array = array(
                        'no' => $no++,
                        'username' => $register[0]->username,
                        'voucher' => $register[0]->voucher,
                        'item_name' => $register[0]->item_name,
                        'item_value' => $register[0]->item_value,
                        'item_image' => site_url()."upload/".$register[0]->image,
                        'id_order' => $register[0]->id_order,
                        'code' => 200
                    );
                    $data = $data_array;
                }else{
                    $data = array(
                        'ErrorMsg' => "Voucher is invalid!",
                        'code' => 505
                    );
                }
            }elseif($date_last == NULL){
                $no=1;
            if ($voucher == $register[0]->voucher && $register[0]->used == 0){
                $data_array = array(
                    'no' => $no++,
                    'username' => $register[0]->username,
                    'voucher' => $register[0]->voucher,
                    'item_name' => $register[0]->item_name,
                    'item_value' => $register[0]->item_value,
                    'item_image' => site_url()."upload/".$register[0]->image,
                    'id_order' => $register[0]->id_order,
                    'code' => 200
                );
                $data = $data_array;
            }else{
                $data = array(
                    'ErrorMsg' => "Voucher is invalid!",
                    'code' => 505
                );
            }
            }else{
                $data = array(
                    'ErrorMsg' => "Voucher is Expired!",
                    'code' => 505
                );
            }
        }else{
            $data = array(
                'code' => 505
            );
        }
        echo json_encode($data);
?>