<? if($_SESSION['page'] == '8' and $_SESSION['section'] == '2') { ?>
<link href="../admin.css" rel="stylesheet" type="text/css" />

<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">Staff Collection by Batch</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'] == '' ) { ?>
    	<script type="text/javascript">
			window.addEvent('domready', function() { 
				new vlaDatePicker('from_date', { style: 'apple_widget',separator: '-', format: 'y/m/d'});
				new vlaDatePicker('to_date', { style: 'apple_widget',separator: '-', format: 'y/m/d'});
			});	
		</script>
              <form action="index.php?stat=create" method="post" name="form1" id="form1">
                
                <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="image/subheader_icon.gif" width="12" height="12" /><strong class="text2">&nbsp;&nbsp;&nbsp;Select the Client</strong></p>
                <table width="70%" border="0" align="center">
                  <tr>
                    <td width="30%" class="Main_Text1_case"><span class="Main_Text1">Client</span></td>
                    <td class="Main_SText_case1"><div align="center">
                      <select name="bid" id="bid">
                        <option value="0">All Client</option>
                        <?
						
						$result1 = mysql_query("SELECT dcm_client.cli_name, dcm_bucket.bucket_no , dcm_bucket.Created_Date, dcm_bucket.bid FROM dcm_bucket INNER JOIN dcm_client ON dcm_bucket.cli_id = dcm_client.cli_id GROUP BY dcm_bucket.stop_bucket, dcm_client.cli_name, dcm_bucket.bucket_no, dcm_bucket.bid HAVING (((dcm_bucket.stop_bucket)=0)) ORDER BY dcm_bucket.stop_bucket"); 

						
						
						 // $result1 = mysql_query("SELECT * FROM ".$dcm_table_start."userlist where active=1"); 
							while($row = mysql_fetch_array($result1)){ 
							?>
                        			<option value="<? echo $row['bid'];?>"><? echo $row['cli_name'];?> ( <? echo $row['bucket_no'];?> , <? echo $row['Created_Date'];?> )</option>
                            <? } ?>
                      </select>
                    </div></td>
                  </tr>
                  <tr>
                    <td><input name="Submit" type="submit" class="Button1" id="Submit" value="   Create   " /></td>
                    <td>&nbsp;</td>
                  </tr>
                </table>
                <br />
              </form>
            <? }if ($_GET['stat'] == 'create' ) { ?>
            <br />

                <table width="90%" border="0" align="center">
                  <tr>
                    <td class="Main_Text1"><div align="center">Staff id</div></td>
                    <td class="Main_Text1"><div align="center">Number of case</div></td>
                    <td class="Main_Text1"><div align="center">bucket no</div></td>
                    <td class="Main_Text1"><div align="center">bucket Date</div></td>
                    <td class="Main_Text1"><div align="center">principle amt</div></td>
                    <td class="Main_Text1"><div align="center">Amt of collection</div></td>
                    <td class="Main_Text1"><div align="center">percentage</div></td>
                  </tr>
                  <?
				  		if ($_POST['bid'] == "0") 
							{
									$result1 = mysql_query("SELECT dcm_case.manage_uid, Count(dcm_case.case_id) CountOfcase, dcm_bucket.bucket_no, dcm_bucket.Created_Date, Sum(dcm_case.principle_amt) SumOfprinciple_amt, Sum(dcm_case.collected) SumOfcollected FROM dcm_bucket INNER JOIN dcm_case ON dcm_bucket.bid = dcm_case.bid GROUP BY dcm_case.manage_uid, dcm_bucket.bid, dcm_bucket.bucket_no, dcm_bucket.Created_Date");
							}else{
									$result1 = mysql_query("SELECT dcm_case.manage_uid, Count(dcm_case.case_id) CountOfcase, dcm_bucket.bucket_no, dcm_bucket.Created_Date, Sum(dcm_case.principle_amt) SumOfprinciple_amt, Sum(dcm_case.collected) SumOfcollected FROM dcm_bucket INNER JOIN dcm_case ON dcm_bucket.bid = dcm_case.bid where dcm_bucket.bid = ".$_POST['bid']." GROUP BY dcm_case.manage_uid, dcm_bucket.bid, dcm_bucket.bucket_no, dcm_bucket.Created_Date");
							}
						
						
						

						 while($row = mysql_fetch_array($result1)){ 


				  ?>
                  <tr>
                    <td class="Main_SText_case1"><div align="center"><? echo $row['manage_uid']?></div></td>
                    <td class="Main_SText_case1"><div align="center"><? echo $row['CountOfcase']?></div></td>
                    <td class="Main_SText_case1"><div align="center"><? echo $row['bucket_no']?></div></td>
                    <td class="Main_SText_case1"><div align="center"><? echo $row['Created_Date']?></div></td>
                    <td class="Main_SText_case1"><div align="center"><? echo $row['SumOfprinciple_amt']?></div></td>
                    <td class="Main_SText_case1"><div align="center"><? echo $row['SumOfcollected']?></div></td>
                    <td class="Main_SText_case1"><div align="center"><? echo round($row['SumOfcollected']/$row['SumOfprinciple_amt']*100,2)?> %</div></td>
                  </tr>
                  <?
				  		}
				  ?>
                </table>
              <br />

            <? } ?>            </td>
          </tr>
        </table></td>
      </tr>
</table>
<? } ?>
