<?php

include("../includes/site_config.php");

include('../session_handler.inc');

$area = 'member';
/*if ($Sess_UserType != "A") {
        exit;
}*/
$radiobutton = $_REQUEST['radiobutton'];

$duringday = $_REQUEST['textfield'];

$ondate = $_REQUEST['ex5'];
$date1 = explode("/",$ondate);
$mon1 = $date1[0];
$day1 = $date1[1];
$year1 = $date1[2];
$On_date = "$year1-$mon1-$day1";
$startdate = $_REQUEST['ex6'];
$date2 = explode("/",$startdate);
$mon2 = $date2[0];
$day2 = $date2[1];
$year2 = $date2[2];
$On_startdate = "$year2-$mon2-$day2";

$enddate = $_REQUEST['ex7'];
$date3 = explode("/",$enddate);
$mon3 = $date3[0];
$day3 = $date3[1];
$year3 = $date3[2];
$On_enddate = "$year3-$mon3-$day3";
//print_r($_REQUEST);
	if($_REQUEST['radiobutton'] == "r_amount")
	{
	$query = "select sum(pay_samount) as total_amount from payments where pay_transid !='0'";
	}
	else if($_REQUEST['radiobutton'] == "r_duringlast" && $_REQUEST['textfield'] != "")
	{
	$lastdate = date("Y-m-d",time() - 3600*24*$duringday);
	$query = "select sum(pay_samount) as total_amount from payments where pay_date < $lastdate AND pay_transid !='0'";
	} 
	else if($_REQUEST['radiobutton'] == "r_onday" && $_REQUEST['ex5'] != "")
	{
	$query = "select sum(pay_samount) as total_amount  from payments where pay_date = '".$On_date."' AND pay_transid !='0'";
	//echo $query;
	} 
	else if($_REQUEST['radiobutton'] == "r_betweenday" && $_REQUEST['ex6'] != "" && $_REQUEST['ex7'] != "")
	{ 
	$query = "select sum(pay_samount) as total_amount from payments where pay_date between '".$On_startdate."' and '".$On_enddate."' AND pay_transid !='0'";
	//echo $query;
	}
	else 
	{
	 $query = "select sum(pay_samount) as total_amount from payments where pay_transid !='0'";
	}

/*if (isset($_POST['lstYear'])) $lstYear=$_POST['lstYear'];

elseif (isset($_GET['lstYear'])) $lstYear=$_GET['lstYear'];

else $lstYear=date('Y');

if (isset($_POST['WMonth'])) $WMonth=$_POST['WMonth'];

elseif (isset($_GET['WMonth'])) $WMonth=$_GET['WMonth'];

else $WMonth=date('m');*/

# retrieve the template


$str_query = mysql_fetch_object(mysql_query($query));
//$query="select min(year(pay_date)) as first_year from payments";	
//$retval=mysql_query($query,$link) or die(mysql_error());
//$first_year=mysql_fetch_object($retval);
/*if ($first_year->first_year=="") $first_year->first_year=date("Y");

if (isset($WMonth) and $WMonth != '-Choose-' and $lstYear != '-Choose-') {

    $query="SELECT *, DATE_FORMAT(pay_date,'%d-%M-%Y') AS paydate

        FROM payments LEFT JOIN members ON (pay_userid=mem_userid)

        WHERE MONTH(pay_date) = '$WMonth'

        AND YEAR(pay_date) = '$lstYear' AND pay_transid !=''

        ORDER BY pay_date DESC";

    $result=mysql_query($query,$link) or die(mysql_error());

    $qrynum=mysql_num_rows($result);

}
*/
?>
<link rel="stylesheet" type="text/css" href="<?php echo $CONST_LINK_ROOT ?>/admin/calendar/calpopup.css">
<script src="<?php echo $CONST_LINK_ROOT ?>/admin/calendar/calpopup.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo $CONST_LINK_ROOT ?>/admin/calendar/dateparse.js"></script>
<script type="text/javascript">
function Check_Validation()
{
		if(document.getElementById("During_last").value=="r_duringlast")
		{
		document.getElementById("dayid").disabled=false;
		document.getElementById("ex5").disabled=true;
		document.getElementById("ex6").disabled=true;
		document.getElementById("ex7").disabled=true;
		document.getElementById("on_date").disabled=true;
		document.getElementById("between_date").disabled=true;
		document.getElementById("totalid").disabled=true;
		return false;
		}	
}
function Check_Validation1()
{
		if(document.getElementById("on_date").value=="r_onday")
		{
		document.getElementById("dayid").disabled=true;
		document.getElementById("ex5").disabled=false;
		document.getElementById("ex6").disabled=true;
		document.getElementById("ex7").disabled=true;
		document.getElementById("During_last").disabled=true;
		document.getElementById("between_date").disabled=true;
		document.getElementById("totalid").disabled=true;
		return false;
		}	
}
function Check_Validation2()
{
		if(document.getElementById("between_date").value=="r_betweenday")
		{
		document.getElementById("dayid").disabled=true;
		document.getElementById("ex5").disabled=true;
		document.getElementById("ex6").disabled=false;
		document.getElementById("ex7").disabled=false;
		document.getElementById("During_last").disabled=true;
		document.getElementById("on_date").disabled=true;
		document.getElementById("totalid").disabled=true;
		return false;
		}	
}
/*function Check_form_Validation()
{
    
	  if(document.FrmReports.textfield.value=="")
		{
			alert(" Please Enter The Numbert of Day.");
			document.FrmReports.textfield.focus();
			return false;
		}
			
		if(isNaN(document.FrmReports.textfield.value))
		{
			alert(" Please Enter Only Integer Value.");
			document.FrmReports.textfield.focus();
			return false;
		}
		if(document.FrmReports.ex5.value=="")
		{
			alert(" Please Select The Date.");
			document.FrmReports.ex5.focus();
			return false;
		}
		if(document.FrmReports.ex6.value=="")
		{
			alert(" Please Select The From Date.");
			document.FrmReports.ex6.focus();
			return false;
		}
		if(document.FrmReports.ex7.value=="")
		{
			alert("Please Select The To Date.");
			document.FrmReports.ex7.focus();
			return false;
		}
return(true);	
}*/


</script>



<?php include("include/header.php"); ?>
<div class="mainwidth">
<div class="admin-page-header"><div class="admin-page-heading">&nbsp;&nbsp;Member Payment Accounting</div></div>
<div class="clear"></div>
<div class="admin-page">
  <table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="<?php print("$CONST_TABLE_CELLSPACING"); ?>" cellpadding="<?php print("$CONST_TABLE_CELLPADDING"); ?>">
    
    <tr>
      <td><table width="<?php print("$CONST_TABLE_WIDTH"); ?>" align="<?php print("$CONST_TABLE_ALIGN"); ?>" border="0" cellspacing="10" cellpadding="<?php print("$CONST_SUBTABLE_CELLPADDING"); ?>">
        <!--DWLayoutTable-->
        <form method='post' action='<?php echo $CONST_LINK_ROOT ?>/admin/report_payments.php<?php print("?PHPSESSID=".session_id()); //print("$sess_id"); ?>' name='FrmReports' onsubmit=" return Check_form_Validation()" >
         
          <tr>
            <td width="20" height="20" align='right' valign='top'><input name="radiobutton" checked="checked" type="radio" value="r_amount" id="totalid"/></td>
            <td width="97" align='left' valign='middle' >Total Amount</td>
            <td width="22" align='left' valign='top'>&nbsp;</td>
            <td width="11" align='left' valign='top'>&nbsp;</td>
            <td width="42" align='left' valign='top'>&nbsp;</td>
            <td width="45" align='left' valign='top'>&nbsp;</td>
            <td width="42" align='left' valign='top'>&nbsp;</td>
            <td width="139" align='left' valign='top'>&nbsp;</td>
            <td width="70" align='left' valign='top'>&nbsp;</td>
            </tr>
          <tr>
            <td height="24" align='right' valign='middle'><input name="radiobutton" type="radio" value="r_duringlast" id="During_last" onclick="Check_Validation(this.value)"/></td>
            <td align='left' valign='middle' >During Last:</td>
            <td colspan="3" align='left' valign='top'><input type="text" size="14" name="textfield" id="dayid"/></td>
            <td colspan="3" align='left' valign='top'>Days (type 0 for today's transactions) </td>
            <td>&nbsp;</td>
            </tr>
          <tr>
            <td height="36" align='right' valign='middle'><input name="radiobutton" type="radio" value="r_onday" id="on_date" onclick="Check_Validation1(this.value)"/></td>
            <td align='left' valign='middle' >On the Date: </td>
            <td colspan="5" valign="middle"><input type="text" name="ex5" id="ex5" size="14" onBlur="dp_dateFormat='m/dd/yyyy';magicDate(this)" onFocus="if (this.className != 'error') this.select()">              <a href="javascript:void(0);" onClick="g_Calendar.show(event, 'ex5', 'm/dd/yyyy')" title="Show popup calendar"><img src="<?php echo $CONST_LINK_ROOT ?>/admin/calendar/calendar.gif" border="0"></a></td>
            <td>&nbsp;</td>
            <td align='left' valign='top'>&nbsp;</td>
            </tr>
          <tr>
            <td height="36" align='right' valign='middle'><input name="radiobutton" type="radio" value="r_betweenday" id="between_date" onclick="Check_Validation2(this.value)"/></td>
            <td align='left' valign='middle' >Between Dates: </td>
            <td colspan="5" valign="middle"><input type="text" name="ex6" id="ex6" size="14" onBlur="dp_dateFormat='m/dd/yyyy';magicDate(this)" onFocus="if (this.className != 'error') this.select()">              <a href="javascript:void(0);" onClick="g_Calendar.show(event, 'ex6', 'm/dd/yyyy')" title="Show popup calendar"><img src="<?php echo $CONST_LINK_ROOT ?>/admin/calendar/calendar.gif" border="0"></a></td>
            <td>&nbsp;</td>
            <td align='left' valign='top'>&nbsp;</td>
            </tr>
          <tr>
            <td height="36" align='left' valign='top'>&nbsp;</td>
            <td align='left' valign='top' >&nbsp;</td>
            <td colspan="5" valign="middle"><input type="text" name="ex7" id="ex7" size="14" onBlur="dp_dateFormat='m/dd/yyyy';magicDate(this)" onFocus="if (this.className != 'error') this.select()">              <a href="javascript:void(0);" onClick="g_Calendar.show(event, 'ex7', 'm/dd/yyyy')" title="Show popup calendar"><img src="<?php echo $CONST_LINK_ROOT ?>/admin/calendar/calendar.gif" border="0"></a></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            </tr>
          <tr>
            <td height="24" align='left' valign='top'>&nbsp;</td>
            <td align='left' valign='top' >&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td colspan="3" align='left' valign='top'><div align="right">
              <input type="submit" name="Submit22" value="Submit" id="sumbit"/>
            </div></td>
            <td>&nbsp;</td>
            <td align='left' valign='top'>&nbsp;</td>
            </tr>
          <tr>
            <td height="19" colspan="9" align='left' valign='top'><hr class="line" /></td>
            </tr>
          <tr>
            <td height="19">&nbsp;</td>
            <td colspan="2" align='left' valign='top'><b class="pageheader">
      Totals</b></td>
            <td>&nbsp;</td>
			 
			 <? if($str_query->total_amount!="")
			 { ?>
            <td colspan="2" align='left' valign='top'><div align="right">$<?=number_format(round($str_query->total_amount , 2), 2, '.', '');?></div></td>
			<? } else { ?>
			<td colspan="2" align='left' valign='top'><div align="right">$0.00</div></td>
			<? } ?>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align='left' valign='top'>&nbsp;</td>
            </tr>
          <?php /*?><tr>
            <td align='left' valign='top'> <b> </b> </td>
            <td align='left' valign='top' > <b>
              <?=REPORT_PAYMENTS_MONTH?>
              <select size="1" name="WMonth">
                <option value="-Choose-"  <?php if ($WMonth == "") { print("selected");} ?>>
                <?=REPORT_PAYMENTS_CHOOSE?>
                </option>
                <option value="01" <?php if ($WMonth == "01") { print("selected");} ?>>
                <?=MONTH_JAN?>
                </option>
                <option value="02" <?php if ($WMonth == "02") { print("selected");} ?>>
                <?=MONTH_FEB?>
                </option>
                <option value="03" <?php if ($WMonth == "03") { print("selected");} ?>>
                <?=MONTH_MAR?>
                </option>
                <option value="04" <?php if ($WMonth == "04") { print("selected");} ?>>
                <?=MONTH_APR?>
                </option>
                <option value="05" <?php if ($WMonth == "05") { print("selected");} ?>>
                <?=MONTH_MAY?>
                </option>
                <option value="06" <?php if ($WMonth == "06") { print("selected");} ?>>
                <?=MONTH_JUN?>
                </option>
                <option value="07" <?php if ($WMonth == "07") { print("selected");} ?>>
                <?=MONTH_JUL?>
                </option>
                <option value="08" <?php if ($WMonth == "08") { print("selected");} ?>>
                <?=MONTH_AUG?>
                </option>
                <option value="09" <?php if ($WMonth == "09") { print("selected");} ?>>
                <?=MONTH_SEP?>
                </option>
                <option value="10" <?php if ($WMonth == "10") { print("selected");} ?>>
                <?=MONTH_OCT?>
                </option>
                <option value="11" <?php if ($WMonth == "11") { print("selected");} ?>>
                <?=MONTH_NOV?>
                </option>
                <option value="12" <?php if ($WMonth == "12") { print("selected");} ?>>
                <?=MONTH_DEC?>
                </option>
              </select>
              </b> </td>
            <td align='left' valign='top'> <b>
              <?=REPORT_PAYMENTS_YEAR?>
              </b> </td>
            <td align='left' valign='top'> <b>
              <select size="1" name="lstYear">
                <option value="-Choose-"><?=REPORT_PAYMENTS_CHOOSE?></option>
				<?php 
					for ($i=date("Y"); $i >= $first_year->first_year; $i--) {
						if ($i==$lstYear) $selected="selected"; else $selected="";
						print("<option value='$i' $selected>$i</option>");
					}
				?>
              </select>
              </b> </td>
            <td align='left' valign='top'> <input name="btnSubmit" type="submit" class="button" value="<?=REPORT_PAYMENTS_GET?>">            </td>
          </tr>
          <tr >
            <td colspan="6" align='left' valign='top'>&nbsp;</td>
          </tr>
          <?php
 if (isset($WMonth) and $WMonth != '-Choose-' and $lstYear != '-Choose-') {
    print("<tr>
                             <td>&nbsp;</td>
                             <td ><b>".REPORT_PAYMENTS_TDATE."</b></td>
                             <td ><b>".REPORT_PAYMENTS_USER."</b></td>
                             <td ><b>".REPORT_PAYMENTS_TCODE."</b></td>
                             <td ><b>".REPORT_PAYMENTS_TSTATUS."</b></td>
                             <td ><b>".REPORT_PAYMENTS_AMOUNT."</b></td>
                        </tr>
                      ");
    while ($sql_array = mysql_fetch_object($result) ) {
        print("<tr>
                     <td>&nbsp;</td>
                  <td >".date($CONST_FORMAT_DATE_SHORT,strtotime($sql_array->paydate))."</td>
                  <td >$sql_array->mem_username</td>
                  <td >$sql_array->pay_transid</td>
                  <td >$sql_array->pay_transstatus</td>
                  <td >$CONST_SYMBOL $sql_array->pay_samount</td>
                </tr> ");
        $sum_ammount += $sql_array->pay_samount;
    }
    print("<tr>
             <td   colspan='6'> &nbsp;</td>
            </tr>
            <tr>
              <td  class='tdhead' colspan='6'><b>".REPORT_PAYMENTS_SUMMARY."</b></td>
            </tr>
             ");

        print("<tr>
                  <td colspan='5'>&nbsp;</td>
                  <td>$CONST_SYMBOL ".round($sum_ammount,2)."</td>
                </tr> ");
    print("
            <tr>
              <td   align='right' colspan='6'><a href=\"./report_payments_csv.php?$sess_id&WMonth=$WMonth&lstYear=$lstYear\" target=_blank>".REPORT_PAYMENTS_GETCSV."</a></td>
            </tr>
");
}
mysql_close($link);
?><?php */?>




        </form>
      </table></td>
    </tr>
</table></div><div class="admin-page-bottom"></div></div>
<?php include("include/footer.php"); ?>

