<?php
include("../classes/manager.class.php");
//error_reporting(E_ALL);
//ini_set('display_errors', '1');
if (!isset($_SESSION['sess_userid'])) {
    header("Location: ".PROJECT_ADMIN_URL);
    //print("Not Set");
    exit;
}
$m = new Manager();

 
    $filters = "";
    $str = "";
    $searchtxt = "";
    $claimid = "";
    $regno = "";
    $action = '';
    $obj = '';
    extract($_REQUEST);

    $claimid=$_REQUEST['claimid'];
    $regno=$_REQUEST['registrationno'];
    
    if ( empty($claimid) &&  empty($regno)) {
        $filters  = "order by cl.create_date desc";
    }
    elseif (!empty($claimid) &&  empty($regno)) {
        $filters  = "  where cl.claimid like '%$claimid'  order by cl.create_date desc  ";
    }  
    elseif ( empty($claimid) && !empty($regno)) {
        $filters  = "  where   cl.igis_registrationno like '%$regno' order by cl.create_date desc ";
    }
    elseif (!empty($claimid) &&  !empty($regno)) {
        $filters  = "  where cl.claimid like '%$claimid' and cl.igis_registrationno like '%$regno' order by cl.create_date desc    ";
    }  

    //echo $filter;
    //$obj = Policy::GetPolicyList($filter, $pageno, $pagesize);
if (!empty($claimid) || !empty($regno)) {
    $qry = Survey::GetSearchList($filters);
}
    $filters="";

    $num_rows = Survey::GetNumRows();
    $num_pages = Survey::GetNumberOfPages();
 

?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <?php include('includes/inc_head.php'); ?>
    <script src="<?= PROJECT_URL ?>js/jquery.validate.min.js"></script>
</head>
<body>
<section id="container">
    <?php include('includes/inc_top.php'); ?>
    <section id="main-content">
        <section class="wrapper">
            <div class="row">
                <section class="panel-body">
                    <div class="panel">
                        <div class="panel-body">
                            <!--mini statistics start-->
                            <div class="">
                                <div class="span12">
                                    <div class="span12">
                                        <div class="">
                                            <h2>
                                                Claim Searching
                                            </h2>
                                        </div>
                                    </div>
                                    <div class="">
 
                                        <form action="" method="get" name="search"
                                              id="searchfrm">
                                                <table class="table">
                                                    <tr>
                                                        <td class="col-lg-4">Claim ID<br>
                                                            <input type="text" name="claimid" id="claimid"
                                                                   placeholder="Claim ID"
                                                                    class="form-control"/>
                                                        </td>
                                                        <td class="col-lg-4"> Registration #<br>
                                                            <input type="text" name="registrationno" id="registrationno"
                                                                   placeholder="Registation #"
                                                                     class="form-control"/>
                                                        </td>
                                                        <td class="col-lg-4">&nbsp;<br>
                                                            <button type="submit" class="btn btn-primary btn-large"
                                                                    style="float:left;">
                                                                Search
                                                            </button>
                                                        </td>
                                                    </tr>
                                                </table>
                                            <div class="adv-table">
                                                <table class="display table table-bordered table-striped"
                                                       id="dynamic-table">
                                                    <thead>
                                                        <tr>
                                                            <th>Action</th>
                                                            <th>Claim No</th>
                                                            <th>Status</th>
                                                            <th>Branch</th>
                                                            <th>Policy No</th>
                                                            <th>Reg. No</th>
                                                            <th>Engine No.</th>
                                                            <th>Chassis No.</th>
                                                            <th>Date</th>
                                                            <th>Surveyor</th>
                                                            <th>User</th>
                                                             
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                    <?php
                                                        if ($qry) {
                                                            $cnt = 0;
                                                            $row = '';
                                                            foreach ($qry as $row) {
                                                                 ($cnt % 2) ? $class = "bg_tr1" : $class = "bg_tr2";
                                                                 $cnt++;
                                                                $user = User_setup::GetUserSetupId($row->surveyor_userid);
                                                                if(!empty($row->policyno)){
                                                                    $policyno = $row->policyno." / ".$row->igis_policy_no;
                                                                }else{
                                                                    $policyno = $row->igis_policy_no;
                                                                }
                                                                 
                                                                    if ($row->status=='A'){  $status = 'Surveyor';}
                                                                    elseif ( $row->status=='N'){ if (!empty($row->surveyorid) || $row->surveyorid != 0){
                                                                    		$status = 'Pending Cases';
                                                                    		$link = '<a href="orders/pending_case_view.php?surveyid='.$row->surveyid.'" target="_blank">View</a> | <a href="orders/print/printpendingcase.php?surveyid='.$row->surveyid.'" target="_blank">Print</a>';
                                                                    }else{ 
                                                                    			$status = 'Notification';
                                                                    			$link = '<a href="orders/view.php?claimid='.$row->claimid.'" target="_blank">View</a> | <a href="orders/print/printview.php?claimid='.$row->claimid.'" target="_blank">Print</a>';
                                                                    		}
                                                                    }
                                                                    elseif ( $row->status=='I'){
                                                                    		$status = 'Reinspection';
                                                                    		$link = '<a href="orders/pending_case_view.php?surveyid='.$row->surveyid.'" target="_blank">View</a> | <a href="orders/print/printpendingcase.php?surveyid='.$row->surveyid.'" target="_blank">Print</a>';
                                                                    }
                                                                    elseif ( $row->status=='R'){$status = 'Refer to Surveyor'; }
                                                                    elseif ( $row->status=='P'){
                                                                    		$status = 'Pending Settlement';
                                                                    		$link = '<a href="orders/pending_settlement_case_view.php?surveyid='.$row->surveyid.'" target="_blank">View</a> | <a href="orders/print/printpendingcase.php?surveyid='.$row->surveyid.'" target="_blank">Print</a>';
                                                                    }
                                                                    elseif ( $row->status=='PR'){
                                                                    		$status = 'Pending Reispection Settlement';
                                                                    		$link = '<a href="orders/pending_settlement_case_view.php?surveyid='.$row->surveyid.'" target="_blank">View</a> | <a href="orders/print/printpendingcase.php?surveyid='.$row->surveyid.'" target="_blank">Print</a>';
                                                                    }
                                                                    elseif ( $row->status=='S'){
                                                                    		$status = 'Settled';
                                                                    		$link = '<a href="orders/settled_case_view.php?surveyid='.$row->surveyid.'" target="_blank">View</a> | <a href="orders/print/printpendingcase.php?surveyid='.$row->surveyid.'" target="_blank">Print</a>';
                                                                    }
                                                                    elseif ( $row->status=='E'){ $status = 'Pending Inspection'; }
                                                                    elseif ( $row->status=='C'){
                                                                    		$status = 'Closed';
                                                                    		$link = '<a href="orders/closed_case_view.php?surveyid='.$row->surveyid.'" target="_blank">View</a> | <a href="orders/print/printpendingcase.php?surveyid='.$row->surveyid.'" target="_blank">Print</a>';
                                                                    }
                                                                    elseif ( $row->status=='F'){
                                                                    		$status = 'Finished';
                                                                    		$link = '<a href="orders/pending_case_view.php?surveyid='.$row->surveyid.'" target="_blank">View</a> | <a href="orders/print/printpendingcase.php?surveyid='.$row->surveyid.'" target="_blank">Print</a>';
                                                                    }
                                                                    elseif ( $row->status==''){ $status = 'Notification';
                                                                    		$link = '<a href="orders/view.php?claimid='.$row->claimid.'" target="_blank">View</a> | <a href="orders/print/printview.php?claimid='.$row->claimid.'" target="_blank">Print</a>';
                                                                    }
                                                                    ?>

                                                                <tr class="<?= $class ?>">
                                                                    <td><?php echo $link; $link=''; ?></td>
                                                                    <td><?= $row->claimid; ?></td>

                                                                    <td>
                                                                    <?php /*
                                                                    if ($row->status=='A'){  echo 'Surveyor';}
                                                                    elseif ( $row->status=='N'){ if (!empty($row->surveyorid) || $row->surveyorid != 0){echo 'Pending Cases';}else{echo 'Notification';} }
                                                                    elseif ( $row->status=='I'){echo 'Reinspection'; }
                                                                    elseif ( $row->status=='R'){echo 'Refer to Surveyor'; }
                                                                    elseif ( $row->status=='P'){echo 'Pending Settlement'; }
                                                                    elseif ( $row->status=='PR'){echo 'Pending Reispection Settlement'; }
                                                                    elseif ( $row->status=='S'){echo 'Settled'; }
                                                                    elseif ( $row->status=='E'){echo 'Pending Inspection'; }
                                                                    elseif ( $row->status=='C'){echo 'Closed'; }
                                                                    elseif ( $row->status=='F'){echo 'Finished'; }
                                                                    elseif ( $row->status==''){echo 'Notification'; }*/
                                                                    echo $status;
                                                                    ?></td>
                                                                    <td><?php $obj_branch = Branch_setup::GetBranchSetupByCode($row->branchid); echo $obj_branch->branch_name; ?></td>
                                                                    <td><?= $policyno; ?></td>
                                                                    <td><?= $row->igis_registrationno; ?></td>
                                                                    <td><?= $row->igis_engineno; ?></td>
                                                                    <td><?= $row->igis_chassisno; ?></td>
                                                                    <td><?= date('d-m-Y h:i A', strtotime($row->create_date)); ?></td>
                                                                    <td><?php $obj_so = so_setup::GetSoSetup($row->surveyorid); echo $obj_so->name; ?></td>
                                                                    <td><?= $user->username; ?></td>
                                                                </tr>
                                                                <?php
                                                            }
                                                        } ?>
                                                        </tbody>
                                                </table>
                                            </div>
                                        </form>
                                    </div>
                                    <!--/row-->
                                </div>
                            </div>
                        </div>
                </section>
            </div>
            <footer>
                <?php include('includes/inc_footer.php'); ?>
            </footer>
            </div>
        </section>
        <!--/.fluid-container-->
        <?php include('includes/inc_js.php'); ?>

</body>
</html>
