<?php
  session_start();
  if(!isset($_SESSION['LOGIN_STATUS']))
  {
      header('location:../index.php');
  }
  require "../model/configuration.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><?php echo $_SESSION['title'];?></title>
<link rel='stylesheet' type='text/css' href='../css/fonts.googleapis.com/css_cd14c140.css' />
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="../vendor/bootstrap/css/bootstrap.min.css" />
<!-- Theme CSS -->
<link rel="stylesheet" type="text/css" href="../css/vendor.css" />
<link rel="stylesheet" type="text/css" href="../css/theme.css" />
<link rel="stylesheet" type="text/css" href="../css/utility.css" />
<link rel="stylesheet" type="text/css" href="../css/custom.css" />
<link href="../vendor/Selectbox/bootstrap-select.min.css" rel="stylesheet" />
</head>

<body class="dashboard-page">
<script> var boxtest = localStorage.getItem('boxed'); if (boxtest === 'true') {document.body.className+=' boxed-layout';} </script> 
<!-- Start: Theme Preview Pane -->


<!-- Start: Header -->
<header class="navbar navbar-fixed-top">
  
   <?php include_once("../include/top_menu.php");?> 
</header>

<!-- Start: Main -->
<div id="main"> 
  
  <!-- Start: Sidebar -->
  <?php include_once("../include/left_menu.php");?>

  <!-- Start: Content -->
  <section id="content_wrapper">
    <div id="topbar">
      <div class="topbar-left">
        <ol class="breadcrumb">
          <li class="crumb-icon"><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
          <li class="crumb-link"><a href="#">Customer</a></li>
          <li class="crumb-trail">Customer Transactions</li>
        </ol>
      </div>
      
    </div>
    
    
    <div id="content">
      <div class="row">
        <div class="col-md-4">
          <div class="panel">
            <div class="panel-heading"> <span class="panel-title"> <span class="glyphicon glyphicon-lock"></span> Select Customer </span> </div>
            <div class="panel-body">
              <form class="cmxform form-horizontal" id="altForm" action="#" role="form" method="post" autocomplete="off">
              
              
  
                
                
   
                
              <div class="form-group">
                  <label for="cp" class="col-lg-2 control-label">Customer Name</label>
                  <div class="col-lg-10">
                    <div class="col-lg-12">
                      <select class="selectpicker form-control" data-live-search="true" name="customer" id="customer" tabindex="6">
                      
<option value="">--Select--</option>
 <?php
    
        $cusquery=$db->execute("select * from clients where delet='0'");
    while($cusresult=$cusquery->fetch_assoc())
      {
        
    ?>
        <option value="<?php echo $cusresult['client_id'];?>"><?php echo $cusresult['client_name'];?></option>
        <?php
      }
    ?>
   
      </select>
                    </div>
                  </div>
                </div>

                <div class="form-group">
                <div class="col-lg-11">
                  <input class="submit btn bg-purple pull-right" name="cust_trans" type="submit" value="Submit" />
                  </div>
                </div>
              </form>

<?php  
 if( isset($_POST['customer'])){
     $cusid=$_POST['customer'];
  }
else if( isset($_GET['cusid'])){ $cusid=$_GET['cusid']; }




 
         if(!empty($cusid))
                                {
 
  ?>
  
                <div class="col-md-12">                  
                                    <table class="table table-striped table-bordered table-hover" width="100%"><!-- id="sample_1"-->
                                        <thead>
                                        <tr><th colspan="5">Customer Name : 
                                        <?php
                                                       $qryvender=$db->execute("select * from clients where client_id='".$cusid."' and delet='0'");
                                                    $vndror=$qryvender->fetch_assoc();
                                                    
                                                    
                                                    echo $vndror['client_name']."&nbsp(".$vndror['phone'].")";   
                                                    $trantot=0;
                                                     $tranadvance=0;
                                                  $qry_tran_main=$db->execute("select * from cust_tran_main where custid='".$cusid."' and delet='0'");
                                                  
                                                  while($tran_main_tot=$qry_tran_main->fetch_assoc()){

                                                    $trantot=$trantot+$tran_main_tot['total_amt'];
                                                    $tranadvance=$tranadvance+$tran_main_tot['adv_amt'];

                                                  }      
                                                  $tran_get_amt=0;

                                                  $qry_tran_get=$db->execute("select * from cust_tran where cust_id='".$cusid."' and delet=0");
                                                  
                                                  while($tran_sub=$qry_tran_get->fetch_assoc()){

                                                    $tran_get_amt=$tran_get_amt+$tran_sub['amt'];

                                                  }   

                                                  $balce_amt=$trantot-$tran_get_amt-$tranadvance;




                                            ?>
                                        </th></tr>
                                           

                                        </thead>
                                        <tbody>
                                         
                                          <tr><th colspan="3" class="text-right" align="right">Total&nbsp;</th><th><?php echo round($trantot);?></th></tr> 
                                        </tbody>
                                    </table>
                                    
                                 </div> 

<?php 
}

?>


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


<?php if(!empty($cusid))
                                
 { ?>
          
          <div class="col-md-8">
          <div class="panel">
            <div class="panel-heading"> <span class="panel-title"> <span class="glyphicon glyphicon-pencil"></span> Transaction Entry </span> </div>
            <div class="panel-body pbn">
              <table class="table table-striped table-bordered table-hover" width="100%"><!-- id="sample_1"-->
                                        <thead>
                                            <tr>
                                                <th class="all" width="20%">Date</th>
                                                <th class="min-phone-l" width="20%">Amount</th>
                                                <th class="min-tablet" width="20%">Type</th>
                                                <th width="30%">Details</th>
                                            </tr>
                                            
</thead>
<form action="../controler/add_customer_transaction.php" method="post">
<input type="hidden" name="custid" value="<?php echo $cusid;?>" />
<tbody>
  <tr><td>
  <input type="date" class="form-control" name="date" value="<?php echo date("Y-m-d");?>" placeholder="Date"/></td>
  <td>
  <input type="text" class="form-control" name="amt" placeholder="Amount"/></td>
  <td>
  <select class="form-control" name="type">
  <option value="Cash">Cash</option>
  <option value="DD">DD</option>
  <option value="Cheque">Cheque</option>
  <option value="Slip">Slip</option>
  </select>
  </td>
  <td>
  <textarea class="form-control" name="details" cols="20" rows="2"></textarea>
  </td></tr>
  <tr><td colspan="4">
  <input type="submit" class="btn btn-info" name="addtrans" value="Add Transaction" />
  </td></tr>
</tbody>
</form>
</table>


 <table class="table table-striped table-bordered table-hover" width="100%"><!-- id="sample_1"-->
                                                                            
                                        
                                        <tbody>                                                                                                                                                                                                               <tr><th>Total</th><td><?php echo round($trantot);?></td></tr>
                                        <tr><th>Balance Amount : </th><td><?php echo round($balce_amt);?></td></tr>
                                        <tr><th colspan="5"><a href="cust_trans_details.php?cusid=<?php echo $cusid;?>" style="color: #1B1194;">Detail View</a></th></tr>
                                        </tbody>
                                        </table>                           

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

<?php 
}?>



          </div>
          
    
    
    
    
    
    
    
    
    
      <?php //include_once("dashboard_content.php");?>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    </div>
    
  </section>
  
  <!-- Start: Right Sidebar -->
  
</div>
<!-- End #Main --> 


<!-- jQuery --> 
<script type="text/javascript" src="../vendor/jquery/jquery-1.11.1.min.js"></script> 
<script type="text/javascript" src="../vendor/jquery/jquery_ui/jquery-ui.min.js"></script> <!-- Bootstrap --> 
<script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script> 
<script src="../vendor/Selectbox/bootstrap-select.min.js"></script>
<!-- Page Plugins --> 
<script type="text/javascript" src="../vendor/plugins/validate/jquery.validate.js"></script>  
<script type="text/javascript" src="../vendor/plugins/morris/morris.js"></script> 
<script type="text/javascript" src="../vendor/plugins/datatables/js/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="../vendor/plugins/datatables/js/datatables.js"></script> 
<script type="text/javascript" src="../vendor/plugins/multiselect/bootstrap-multiselect.js"></script> 
<script type="text/javascript" src="../vendor/plugins/jvectormap/jquery-jvectormap.min.js"></script> 
<script type="text/javascript" src="../vendor/plugins/jvectormap/assets/jquery-jvectormap-us-lcc-en.js"></script> 
<script type="text/javascript" src="../vendor/plugins/clndr/clndr.js"></script> 
<script type="text/javascript" src="../vendor/plugins/clndr/moment.js"></script> 
<script type="text/javascript" src="../vendor/plugins/datepicker/bootstrap-datepicker.js"></script> 
<script type="text/javascript" src="../vendor/plugins/jquerymask/jquery.maskedinput.min.js"></script> 
<!-- Flot Plugins --> 
<script type="text/javascript" src="../vendor/plugins/jqueryflot/jquery.flot.min.js"></script> 

<!-- Theme Javascript --> 
<script type="text/javascript" src="../js/utility/spin.min.js"></script> 
<script type="text/javascript" src="../js/utility/underscore-min.js"></script> 
<script type="text/javascript" src="../js/main.js"></script> 
<script type="text/javascript" src="../js/ajax.js"></script> 
<script type="text/javascript" src="../js/custom.js"></script> 
<script type="text/javascript">
jQuery(document).ready(function () {
	  
	 "use strict";

     // Init Theme Core 	  
     Core.init();

     // Enable Ajax Loading 	  
     Ajax.init();     
     
	 
	 	
	 // validate the comment form when it is submitted
	 $("#altForm").validate();

	 //Init jquery Date Picker
	 $('.datepicker').datepicker()
	 
	 $('#datatable').dataTable( {
	"aoColumnDefs": [{ 'bSortable': false, 'aTargets': [ -1 ] }],
	"oLanguage": { "oPaginate": {"sPrevious": "", "sNext": ""} },
	"iDisplayLength": 5,
	"aLengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
	"sDom": 'T<"panel-menu dt-panelmenu"lfr><"clearfix">tip',
	"oTableTools": {
		"sSwfPath": "./vendor/plugins/datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf"
	}
  });	
  
  // Add Placeholder text to datatables filter bar
  $('.dataTables_filter input').attr("placeholder", "Enter Filter Terms Here....");
  
  // Manually Init Chosen on Datatables Filters
  $("select[name='datatable_length']").chosen();	
	
});
</script>
</body>
</html>
<?php
if(isset($_GET['msg']) && $_GET['msg']!= NULL)
{
?>
<script>
alert("<?php echo $_GET['msg'];?>");
</script>
<?php
}
?>