<?php
require('validate.php');
$startdate = $_POST["startdate"];
$enddate   = $_POST["enddate"];
$salesperson   = $_POST["head"];

$myvalstart=explode("-",$startdate);
$startdateval=date("j-M-y",mktime(0,0,0,$myvalstart[1],$myvalstart[2],$myvalstart[0]));	
	
$myvalend=explode("-",$enddate);
$enddateVal=date("j-M-y",mktime(0,0,0,$myvalend[1],$myvalend[2],$myvalend[0]));
//echo $enddate;


$query="SELECT salesman_code,salesman_name FROM ".$prefix."salesman WHERE salesman_code='$salesperson'";
$resultfund=mysqli_query($linkid,$query);
$getname=mysqli_fetch_assoc($resultfund);

if($salesperson=='All'){
$query="SELECT SUM(paid) FROM lab_order_payment WHERE trans_date BETWEEN '$startdate' AND '$enddate'";
//echo $query;exit;
$result=mysqli_query($linkid,$query);
$gettotal=mysqli_fetch_row($result);
$getcount=mysqli_num_rows($result);


$query="SELECT order_no,money_receipt_no,trans_date,paid,b.debtor_ref AS phone,b.name,b.address,c.salesman_name AS salesperson FROM lab_order_payment AS a,".$prefix."debtors_master AS b,".$prefix."salesman AS c WHERE a.debtor_no=b.debtor_no AND a.salesperson=c.salesman_code AND trans_date BETWEEN '$startdate' AND '$enddate'";
//echo $query;exit;
$resultType=mysqli_query($linkid,$query);
}


if($salesperson!='All'){
$query="SELECT SUM(paid) FROM lab_order_payment WHERE trans_date BETWEEN '$startdate' AND '$enddate' AND salesperson='$salesperson'";
//echo $query;exit;
$result=mysqli_query($linkid,$query);
$gettotal=mysqli_fetch_row($result);
$getcount=mysqli_num_rows($result);


$query="SELECT order_no,money_receipt_no,trans_date,paid,b.debtor_ref AS phone,b.name,b.address,c.salesman_name AS salesperson FROM lab_order_payment AS a,".$prefix."debtors_master AS b,".$prefix."salesman AS c WHERE a.debtor_no=b.debtor_no AND a.salesperson=c.salesman_code AND trans_date BETWEEN '$startdate' AND '$enddate' AND a.salesperson='$salesperson'";
$resultType=mysqli_query($linkid,$query);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Money Receipt Summary Report</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Bootstrap framework -->
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" />
<link rel="shortcut icon" href="img/favicon.ico" />
</head>
<body>
<table width="90%" border="0" align="center">
  <tr>
    <td><?php include "templates/logoHeader.php"?>
      <table width="100%" border="0">
        <tr>
          <td align="center"><?php include "templates/letterHeader.php"?>
            <h3 class="heading" align="center" style="font-family:'Times New Roman', Times, serif; font-size:30px; font-style:italic">Payment Summary Report (<?php if($salesperson=='All') echo "All"; else echo $getname['salesman_name'];?>) </h3>
            <p align="center" style="font-family:'Times New Roman', Times, serif; font-size:14px; font-style:italic">(<?php echo $startdateval.' - '. $enddateVal;?>) </p>
           <!-- <table  border="1" align="center" cellpadding="4" cellspacing="4" bordercolor="#E6E6E6" bordercolorlight="#CCCCCC" bordercolordark="#ffffff" bgcolor="#FFFFFF" style="FONT-SIZE:12px; border-collapse:collapse; border:1px #CCCCCC solid; FONT-FAMILY: Arial, Helvetica, sans-serif; TEXT-DECORATION: none; FONT-WEIGHT: normal;">-->
              <table class="table table-condensed table-striped" data-provides="rowlink" >
              <tr style="background-color:#F2F2F2; padding:5px;">
                  <th> MR Ref</th>
				  <th> Trans Date </th>
				  <th> Customer </th>
				  <th> Phone </th>
				  <th> Sales Person </th>
				  <th> Paid(BDT)</th>
              </tr>
              <?php 
		 if($resultType)

				{

				while($mydata = mysqli_fetch_assoc($resultType))
				{
		    	$dateval=explode("-",$mydata['trans_date']);
			    $monthval=date("d-m-Y",mktime(0,0,0,$dateval[1],$dateval[2],$dateval[0]));
				
			//	$dateval=explode("-",$mydata['delivery_date']);
			  //  $deliverydate=date("d-m-Y",mktime(0,0,0,$dateval[1],$dateval[2],$dateval[0]));
		  ?>
              <tr>
           		  <td><?php echo $mydata['money_receipt_no']?></td>
				  <td><?php echo $monthval;?></td>
				  <td><?php echo $mydata['name']?></td>
				  <td><img src="img/phn.png" width="16" />&nbsp;<?php echo $mydata['phone'];?></td>
				  <td><?php echo $mydata['salesperson']?></td>
				  <td><?php echo number_format($mydata['paid'],2)?></td>
              </tr>
              <?php 
				  }
				 } 
	      if($getcount=="")
		  echo "<tr><td colspan=6>There is no order record for this month.</tr></td>";
		 	?>
              <tr style="background-color:#F2F2F2; padding:5px;">
                <td colspan="4">&nbsp;</td>
				<td align="right"><strong>Grand Total : </strong></td>
                <td  align="left"><strong><?php echo number_format($gettotal[0],2);?></strong></td>
              
              </tr>
			   <tr style="background-color:#F2F2F2; padding:5px;">
                <td colspan="7" align="left"> <div style="padding-left:0px;">Issue Date:<?php echo date('j-M-y');?></div></td>
              </tr>
            </table>
           </td>
        </tr>
      </table></td>
  </tr>
</table>
<div>&nbsp;</div>
</body>
</html>
