<? if($_SESSION['page'] == '5' and $_SESSION['section'] == '2') {

?>
<link href="../admin.css" rel="stylesheet" type="text/css" />
<?	 if ($_GET['stat'] <> 'print') { ?>

<table width="95%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
      <tr>
        <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td class="Main_Text"><a class="Main_Text">Generate the report</a></td>
            <td width="10%" class="Main_Text"><div align="right"><img src="image/more_info.gif" width="32" height="32" border="0" /></a></div></td>
          </tr>
          <tr>
            <td colspan="2"><? if ($_GET['stat'] == '' ) {?>
              <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="image/subheader_icon.gif" width="12" height="12" /><strong class="text2">&nbsp;&nbsp;Select </strong></p>
              <div align="left">
                <form action="index.php?stat=show" method="post" name="form1" id="form1">
                  <table width="95%" border="0" align="center">
                    <tr>
                      <td width="15%" class="Main_Text1_case">Client</td>
                      <td width="35%" height="35" class="Main_SText_case"><select name="cli_id" id="cli_id">
                        <option value="0">All Client</option>
                        <?
							$result1 = mysql_query("SELECT * FROM ".$dcm_table_start."client"); 
							while($row = mysql_fetch_array($result1)){ 
						?>
                        <option value="<? echo $row['cli_id'];?>"><? echo $row['cli_name']; ?></option>
                        <?
							}
						?>
                        
                      </select></td>
                      <td width="15%" class="Main_Text1_case">Booking Date</td>
                      <td class="Main_SText_case"><select name="Created_Date" id="Created_Date">
                        <option value="0">All Booking Date</option>
                        <?
							$result1 = mysql_query("SELECT Created_Date FROM ".$dcm_table_start."bucket where stop_bucket =0 group by Created_Date"); 
							while($row = mysql_fetch_array($result1)){ 
						?>
                        <option value="<? echo $row['Created_Date'];?>"><? echo $row['Created_Date']; ?></option>
                        <?
							}
						?>
                        
                      </select></td>
                    </tr>
                    <tr>
                      <td class="Main_Text1_case"><span class="Main_Text1">Staff ID</span></td>
                      <td height="35" class="Main_SText_case"><select name="user_id" id="user_id">
                        <option value="0">All Staff</option>
                        <?
							$result1 = mysql_query("SELECT * FROM ".$dcm_table_start."userlist"); 
							while($row = mysql_fetch_array($result1)){ 
						?>
                        <option value="<? echo $row['user_id'];?>"><? echo $row['fname']; ?> <? echo $row['lname']; ?> ( <? echo $row['user_id'];?> )</option>
                        <?
							}
						?>
                        
                      </select></td>
                      <td class="Main_Text1_case"><span class="Main_Text1">Product</span></td>
                      <td class="Main_SText_case"><select name="prodect" id="prodect">
                               <option value="0">All Product</option>
                               <option value="Personel Loan">Personel Loan</option>
                               <option value="Auto Loan">Auto Loan</option>
                               <option value="Mobile">Mobile</option>
                               <option value="Fixd">Fixd</option>
                               <option value="Other">Other</option>
                            </select></td>
                    </tr>
                    <tr>
                      <td class="Main_Text1_case"><span class="Main_Text1">Bucket no</span></td>
                      <td height="35" class="Main_SText_case"><select name="bucket_no" id="bucket_no">
                        <option value="0">All Bucket no</option>
                        <?
							$result1 = mysql_query("SELECT bucket_no FROM ".$dcm_table_start."bucket where stop_bucket =0 group by bucket_no"); 
							while($row = mysql_fetch_array($result1)){ 
						?>
                        <option value="<? echo $row['bucket_no'];?>"><? echo $row['bucket_no']; ?></option>
                        <?
							}
						?>
                        
                      </select></td>
                      <td class="Main_Text1_case"><span class="Main_Text1">Case Status</span></td>
                      <td class="Main_SText_case"><select name="status_id" id="status_id">
                                      	<option value="0">All Case Status</option>
                                        <?
											$result_lest = mysql_query("SELECT * FROM ".$dcm_table_start."status"); 
											while($row = mysql_fetch_array($result_lest)){ 

										?>
                                        		<option value="<? echo $row['status_id']; ?>"><? echo $row['status_name']; ?></option>
                                        <?
											}
										?>
                      </select></td>
                    </tr>
                    <tr>
                      <td class="Main_Text1_case"><span class="Main_Text1">sort By</span></td>
                      <td height="35" class="Main_SText_case"><select name="sortby" id="sortby">
                        <option value="1">Case ID</option>
                        <option value="2">Claim Amt</option>
                        <option value="3">Colleced Amt</option>
                        <option value="4">Balance</option>
                      </select>
                      </td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                  </table>
                                <p align="center">
                                  <input name="button" type="submit" class="Button1" id="button" value="Generate" />
                                </p>
                </form>
                <br />
              </div>
              <? }if ($_GET['stat'] == 'show' ) { ?>
 		<p align="center"><span class="box_main">Case Report</span></p>
 
 	    <table width="100%" border="0" align="center">
          <tr>
            <td class="Main_Text1">Case ID</td>
            <td class="Main_Text1">CPR/CR</td>
            <td class="Main_Text1">Name</td>
            <td class="Main_Text1">Account No.</td>
            <td class="Main_Text1">Product</td>
            <td class="Main_Text1">Principle amt</td>
            <td class="Main_Text1">Collected</td>
            <td class="Main_Text1">Balance Amt</td>
            <td class="Main_Text1">Client</td>
            <td class="Main_Text1">Staff ID </td>
            <td class="Main_Text1"><span class="Main_Text1_case">Booking Date</span></td>
            <td class="Main_Text1">mobile</td>
            <td class="Main_Text1">Address</td>
            <td class="Main_Text1"><span class="Main_Text1_case">Bucket no</span></td>
            <td class="Main_Text1">Select</td>
          </tr>
          <?
		  		$where1 = 0;
				$andwhere =0;
				$cli_id = "";
				$Created_Date = "";
				$manage_uid = "";
				$prodect = "";
				$bucket_no = "";
				$status_id = "";

		// Load Client
				if ($_POST['cli_id'] <> "0" )
					{
						$cli_id = "dcm_bucket.cli_id= ".$_POST['cli_id'];
						$where1 = 1;
						$andwhere = 1;
					}
		// Load Booking Date
				if ($_POST['Created_Date'] <> "0" )
					{
						if ($andwhere == 0)
						{
							$Created_Date = " dcm_bucket.Created_Date = '".$_POST['Created_Date']."'";
						}else{
							$Created_Date = " and dcm_bucket.Created_Date = '".$_POST['Created_Date']."'";
						}
						$where1 = 1;
						$andwhere =1;
					}
		// Load Staff
					
				if ($_POST['user_id'] <> "0" )
					{
						if ($andwhere == 0)
						{
							$manage_uid = " dcm_case.manage_uid = '".$_POST['user_id']."'";
						}else{
							$manage_uid = " and dcm_case.manage_uid = '".$_POST['user_id']."'";
						}
						$where1 = 1;
						$andwhere =1;
					}
		// Load prodect			
				if ($_POST['prodect'] <> "0" )
					{
						if ($andwhere == 0)
						{
							$prodect = " dcm_bucket.prodect = '".$_POST['prodect']."'";
						}else{
							$prodect = " and dcm_bucket.prodect = '".$_POST['prodect']."'";
						}
						$where1 = 1;
						$andwhere =1;
					}
		// Load bucket no			
					
				if ($_POST['bucket_no'] <> "0" )
					{
						if ($andwhere == 0)
						{
							$bucket_no = " dcm_bucket.bucket_no = '".$_POST['bucket_no']."'";
						}else{
							$bucket_no = " and dcm_bucket.bucket_no = '".$_POST['bucket_no']."'";
						}
						$where1 = 1;
						$andwhere =1;
					}
		// load Case Status
					
				if ($_POST['status_id'] <> "0" )
					{
						if ($andwhere == 0)
						{
							$status_id = " dcm_case.status_id = '".$_POST['status_id']."'";
						}else{
							$status_id = " and dcm_case.status_id = '".$_POST['status_id']."'";
						}
						$where1 = 1;
						$andwhere =1;
					}
		// order by 
		
				if ($_POST['sortby'] == "1" )
				   {
						$sortby = " order by case_id";
					}
				if ($_POST['sortby'] == "2" )
				   {
						$sortby = " order by principle_amt";
					}
				if ($_POST['sortby'] == "3" )
				   {
						$sortby = " order by collected";
					}
				if ($_POST['sortby'] == "4" )
				   {
						$sortby = " order by Balance";
					}
		// Load all select
		  
		  		if ($where1 == 1 ) {
					$where_str = " where ".$cli_id;
					$where_str = $where_str."".$Created_Date;
					$where_str = $where_str."".$manage_uid;
					$where_str = $where_str."".$prodect;
					$where_str = $where_str."".$bucket_no;
					$where_str = $where_str."".$status_id;
				}else{
					$where_str = "";
				}
				
				$result_lest = mysql_query("SELECT dcm_case.case_id,dcm_bucket.cli_id, dcm_case.collected , (dcm_case.principle_amt-dcm_case.collected) Balance, dcm_customer.CPR, dcm_customer.CR, dcm_customer.cus_name, dcm_case.account_no, dcm_bucket.prodect, dcm_case.principle_amt, dcm_case.status_id, dcm_client.cli_name, dcm_case.manage_uid, dcm_bucket.Created_Date, dcm_customer.cus_mobile, dcm_customer.cus_address, dcm_bucket.bucket_no FROM dcm_bucket INNER JOIN (dcm_customer INNER JOIN (dcm_client INNER JOIN dcm_case ON dcm_client.cli_id = dcm_case.cli_id) ON dcm_customer.cus_id = dcm_case.cus_id) ON dcm_bucket.bid = dcm_case.bid".$where_str.$sortby); 
				while($row = mysql_fetch_array($result_lest)){ 

		?>
          <tr>
            <td class="Main_Text"><? echo $row['case_id'];?></td>
            <td class="Main_Text"><? echo $row['CPR'];?><? echo $row['CR'];?></td>
            <td class="Main_Text"><? echo $row['cus_name'];?></td>
            <td class="Main_Text"><? echo $row['account_no'];?></td>
            <td class="Main_Text"><? echo $row['prodect'];?></td>
            <td class="Main_Text"><? echo $row['principle_amt'];?></td>
            <td class="Main_Text"><? echo $row['collected'];?></td>
            <td class="Main_Text"><? echo $row['principle_amt']-$row['collected'];?></td>
            <td class="Main_Text"><? echo $row['cli_name'];?></td>
            <td class="Main_Text"><? echo $row['manage_uid'];?></td>
            <td class="Main_Text"><? echo $row['Created_Date'];?></td>
            <td class="Main_Text"><? echo $row['cus_mobile'];?></td>
            <td class="Main_Text"><? echo $row['cus_address'];?></td>
            <td class="Main_Text"><? echo $row['bucket_no'];?></td>
            <td class="Main_Text"><a href="index.php?page=4&section=1&stat=select&case_id=<? echo $row['case_id'];?>" class="box_main">Select</a></td>
          </tr>
         <?
		 	}
		?>
        </table>
              <br />

              
                  <? } ?>            
          </td></tr>
        </table></td>
      </tr>
</table>
  
	 <? }if ($_GET['stat'] == 'print' ) { ?>
 		<p align="center"><span class="box_main">Case Report</span></p>
 
 	    <table width="80%" border="0" align="center">
          <tr>
            <td class="Main_Text1">Case ID</td>
            <td class="Main_Text1">CPR/CR</td>
            <td class="Main_Text1">Name</td>
            <td class="Main_Text1">Account No.</td>
            <td class="Main_Text1">Product</td>
            <td class="Main_Text1">Claim Amt</td>
            <td class="Main_Text1">Collected</td>
            <td class="Main_Text1">Balance Amt</td>
            <td class="Main_Text1">Client</td>
            <td class="Main_Text1">Staff ID </td>
          </tr>
          <tr>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
            <td class="Main_Text">&nbsp;</td>
          </tr>
        </table>
 	    <? } ?>
<? } ?>
