<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php include "common/config.php";
	include "include/head.php"; ?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
   
  <h1><i class="icon-bar-chart"></i> Reminder Payment</h1>
</div>


   <div class="main-content">
   
            <div class="widget">
           <!-- <div class="widget-content-white glossed">
                    <div class="padded">
                      <form role="form" class="form-horizontal" method="post" action="reminder_payment.php">
                         <div class="form-group">
                          <label class="col-md control-label">Tanggal Reminder Payment</label>
                           <input type="text" class="inputDate" name="inputDate"  value="<?php echo date('d-m-Y'); ?>" id="inputDate" >
                            <input type="text" class="inputDate2" name="inputDate2"  value="<?php echo date('d-m-Y'); ?>" id="inputDate2" >
                            <button class="btn btn-primary" type="submit">Submit</button>
                        <button class="btn btn-default" type="reset">Reset</button>
                           
                        </div>
                      </form>
                    </div>
             </div>-->
              <div class="widget-content-white glossed">
                <div class="padded">
                <table class="table table-striped table-bordered table-hover">
                   <thead>
                        <tr>
                            <th>Invoice No.</th>
                            <th>Invoice Date</th>
                            <th>Customer No. - Customer Name</th>
                            <th>Inventory</th>
                            <th>Sales Name</th>
                            <th>Total Invoice</th>
                            <th>Sisa Invoice</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tbody>
                  <?php
					//list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate']);
//						$datepicker=$f."-".$e."-".$d;
//						list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate2']);
//						$datepicker1=$f."-".$e."-".$d;
//						if(strtotime($datepicker1) < strtotime($datepicker))
//						{
//						?>
										<script language="javascript">
//										 alert("Date From < Date To");
//										document.location="reminder_payment.php";
//										</script>
						<?php
//						}
//						else
//						{
						$sql = mysql_query("select *,a.id_sales as aid_sales from sales a
						inner join tbl_customer b on a.id_customer  = b.id_customer
						left join  (select id_sales,IFNULL(sum(nominal),0) as nominal from sales_payment) c on a.id_sales = c.id_sales
						where a.status_sales = 1");
						while($fetch = mysql_fetch_array($sql))
						{
								$user_update = $fetch['user_update'];
								$id_sales = $fetch['aid_sales'];
								$invoice = $fetch['invoice'];
								list($d, $e, $f)=split ("[-]", $fetch['invoice_date']);
								$invoice_date   =$f."-".$e."-".$d;
								$sql2 = mysql_fetch_array(mysql_query("select IFNULL(sum(price),0) as total,currency  from salesdetails where id_sales  = '$id_sales' and status=1 group by currency"));
								$total = $sql2['total'];
								$currency = $sql2['currency'];
								$sql3 = mysql_fetch_array(mysql_query("select IFNULL(sum(nominal),0) as nominal  from sales_payment where id_sales  = '$id_sales'"));
								$nominal = $sql2['total'] - $sql3['nominal']; 
								if($nominal > 0)
								{
								
					?>
                      <tr class="gradeX">
                          <td><a href="view_sales.php?id_sales=<?php echo $id_sales; ?>"><?php echo $fetch['invoice']; ?></a></td>
                          <td align="center"><?php echo $invoice_date; ?></td>
                           <td><?php echo $fetch['kode_customer'];?> - <?php echo $fetch['nama_customer'];?></td>
                             <td align="center"><?php echo $fetch['inventory']; ?></td>
                              <td><?php echo $user_update; ?></td>
                                <td><?php echo $currency; ?> <?php echo $total; ?></td>
                                  <td><?php echo $currency; ?> <?php echo $nominal; ?></td>
                                   <td class="actions aligncenter"><a href="payment_histori.php?id_sales=<?php echo $id_sales; ?>"class="btn btn-default btn-xs"><i class="icon-usd"></i> history</a> </td>
                       </tr>
                       <?php
								}
						}
						//}
						?>
                  </tbody>
                </table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
</div>       

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>

</html>