<?php
  session_start();
  if(!isset($_SESSION['LOGIN_STATUS']))
  {
      header('location:../index.php');
  }
  require "../model/configuration.php";
$rn=rand(100,115000).time();
$_SESSION['prms']=$rn;
$_SESSION['purchase']="Purchase";
?>
<!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="#">Purchase</a></li>
          <li class="crumb-trail">Purchase Add</li>
        </ol>
      </div>
      
    </div>
    
    
    <div id="content">
      <div class="row">
        <div class="col-md-6">
          <div class="panel">
            <div class="panel-heading"> <span class="panel-title"> <span class="glyphicon glyphicon-lock"></span> Purchase </span> </div>
            <div class="panel-body">
              <!--<form class="cmxform form-horizontal" id="altForm" role="form" method="post" action="#">-->
              
              
              
              <div class="cmxform form-horizontal">
              
              <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Vendor</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                                        
                    
                      <select class="selectpicker form-control" data-live-search="true" name="vender" id="vender" tabindex="1">
                            <option value="">--Select--</option>
                                <?php
                                    $query=$db->execute("select * from vendor where delet='0'");
	                               	while($result=$query->fetch_assoc())
		                              	{
                                ?>
                            <option value="<?php echo $result['client_id'];?>"><?php echo $result['vendor_name'];?></option>
                                <?php
                                        }
                                ?>
                      </select>
                    </div>
                    </div>
                </div>
              
              
              
              <div class="form-group">
                  <label for="datepicker" class="col-lg-1 control-label">Date</label>
                  <div class="col-lg-11">
                    <div class="col-lg-11">
                      <input type="text" id="datepicker" name="invdte" class="form-control datepicker mtn" value="<?php echo date("d-m-Y");?>" placeholder="23/9/2013" required="" />
                  </div>
                  </div>
                </div>
              
              
              
              
              <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Invoice No</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                      <input type="text" name="invno" id="invno" placeholder="Invoice No" class="form-control" />
                    </div>
                    </div>
                </div>
              
              
              
                
                      
                <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Type</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                    
                       <select class="selectpicker form-control" name="ppr" id="ppr" required="required" >
                       <option value="">-------Select-------</option>
                         <option value="1">Paper</option>
                         <option value="0">Other</option>
                          <option value="2">Ink</option>
                       </select>
                    </div>
                    </div>
                </div>
                
                
                
              
              
              
              
              
              
              
              
              <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Product</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                                        
                    
                      <select class="selectpicker form-control" data-live-search="true" name="product" id="product" tabindex="6">
                            <option value="">--Select--</option>
                                <?php
                                    $query=$db->execute("select * from products where delet='0'");
	                               	while($result=$query->fetch_assoc())
		                              	{
                                ?>
                            <option value="<?php echo $result['productcode'];?>|<?php echo $result['productname'];?>"><?php echo $result['productcode'];?>|<?php echo $result['productname'];?></option>
                                <?php
                                        }
                                ?>
                      </select>
                    </div>
                    </div>
                </div>
                
                
                
                
                
                
                
                
                
               <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">GSM</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                      <input type="text" name="gsm" id="gsm" placeholder="GSM" class="form-control" />
                    </div>
                    </div>
                </div>
                
                
                
                <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Width</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                      <input type="text" name="width" id="width" placeholder="Width" class="form-control" />
                    </div>
                    </div>
                </div>
                
                
                
                
                <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Length</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                      <input type="text" name="length" id="length" placeholder="Length" class="form-control" />
                    </div>
                    </div>
                </div>
                
                
                
                <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Price</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                      <input type="text" name="prce" id="prce" placeholder="Price" class="form-control" />
                    </div>
                    </div>
                </div>
                
                
                
                
                
                
                
                <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Qty</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                      <input type="text" name="qty" id="qty" placeholder="Quantity" class="form-control" />
                    </div>
                    </div>
                </div> 
                
                
                
                <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Discount</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                      <input type="text" name="disc" id="disc" placeholder="Discount" class="form-control" />
                    </div>
                    </div>
                </div>
                
                
                
                <div class="form-group">
                  <label for="cp" class="col-lg-1 control-label">Tax(%)</label>
                  <div class="col-lg-11">
                  
                    <div class="col-lg-11">
                    
                      <input type="text" name="tax" id="tax" placeholder="Tax" class="form-control" />
                    </div>
                    </div>
                </div>
          
            
                <div class="form-group">
                <div class="col-lg-11">
                  <input class="submit btn bg-purple pull-right" name="roleadd" type="submit" id="FormSubmit" value="Add Item" />
                  </div>
                </div>
                </div>
              <!--</form>-->
              
              
              
            </div>
          </div>
          </div>
          
          <div class="col-md-6">
          <div class="panel panel-visible">
            <div class="panel-heading">
              <div class="panel-title hidden-xs"> <span class="glyphicon glyphicon-tasks"></span> Purchase Items</div>
            </div>
            <div class="panel-body pbn">
              <table class="table table-bordered table-hover" id="responds">
					<thead>
						<tr>
							<th width="15%">Sl</th>                            
							<th width="15%">Item Code</th>
							<th width="20%">Item Name</th>
                            <th width="10%">Unitprice</th>
							<th width="10%">Quantity</th>
                            <th width="15%">Discount</th>
                            <th width="10%">Tax</th>
                            <th width="10%">Total</th>
                            <th></th>
						</tr>
					</thead>
                    <tbody>
                    </tbody>
                    
                    
     <tr>
     
     <th colspan="7" style="text-align: right;"> Total </th><th id="test" colspan="2"></th></tr>               
                    </table>
                    
                    
                    
           <div class='row'>
      	          
            <form action="../controler/purchase_save.php" class="form-horizontal" method="post" onsubmit="return valid();">
            <div class="form-group">
                  <label for="cp" class="col-lg-2 control-label">Amount Type</label>
                  <div class="col-lg-10">
                    <div class="col-lg-12">
                      <select class="selectpicker form-control" data-live-search="true" name="ptype" id="ptype" tabindex="6" required="">
                      
<option value="">--Select--</option>
 <option value="Cash">Cash</option>
 <option value="Credit">Credit</option>
   
      </select>
                    </div>
                  </div>
                </div>
            
             <div class="col-md-7 pull-right">
             <input type="hidden" name="sion" id="sion" value="<?php echo $_SESSION['prms'];?>" />
             <input type="submit" id="Formsave" value="Save" name="save_purchase" class="btn btn-success pull-left"/><br />
             
             </div>
             </form>
             </div>         
                    
                    
                    
            </div>
          </div>
        
          </div>
          </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> 

<!-- Page Plugins --> 
<script src="../vendor/Selectbox/bootstrap-select.min.js"></script>
<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/jvectormap/jquery-jvectormap.min.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> 
<script type="text/javascript" src="../vendor/editors/xeditable/js/bootstrap-editable.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">
var autoLoad = setInterval(
function ()
{
$('#test').load('purchase_total_price.php');
  }, 100); // refresh page every 1 seconds
</script>

<script type="text/javascript">
$(document).ready(function() {

"use strict";

     // Init Theme Core 	  
     Core.init();

     // Enable Ajax Loading 	  
     Ajax.init(); 
     
     $('.datepicker').datepicker();


	//##### send add record Ajax request to response.php #########
	$("#FormSubmit").click(function (e) {
			e.preventDefault();
             if($("#vender").val()==='')
			{
				alert("Please Select Vender!");
				return false;
			}
			else if($("#datepicker").val()==='')
			{
				alert("Please enter Date!");
				return false;
			}
			else if($("#ppr").val()==='')
			{
				alert("Please Select Product Type!");
				return false;
			}
			else if($("#product").val()==='')
			{
				alert("Please Enter Product Code or Product Name!");
				return false;
			}
			
           /* else if($("#width").val()==='')
			{
				alert("Please Enter Width!");
				return false;
			}
			else if($("#length").val()==='')
			{
				alert("Please Enter Length!");
				return false;
			}*/
						
			$("#FormSubmit").hide(); //hide submit button
			$("#LoadingImage").show(); //show loading image
			
				
			
		 	var myData = 'vender='+ $("#vender").val() + '&datepicker=' + $("#datepicker").val() + '&invno=' + $("#invno").val() + '&product=' + $("#product").val() + '&gsm=' + $("#gsm").val() + '&width=' + $("#width").val() + '&length=' + $("#length").val() + '&prce=' + $("#prce").val()+ '&qty=' + $("#qty").val()+ '&disc=' + $("#disc").val()+ '&tax=' + $("#tax").val()+ '&paper=' + $("#ppr").val() +'&sion=' + $("#sion").val(); //build a post data structure
			jQuery.ajax({
			type: "POST", // HTTP method POST or GET
			url: "../controler/purchase_temp.php", //Where to make Ajax calls
			dataType:"text", // Data type, HTML, json etc.
			data:myData, //Form variables
			success:function(response){
				$("#responds").append(response);
				//$("#salesdate").val(''); //empty text field on successful
				$("#FormSubmit").show(); //show submit button
				$("#LoadingImage").hide(); //hide loading image

			},
			error:function (xhr, ajaxOptions, thrownError){
				$("#FormSubmit").show(); //show submit button
				$("#LoadingImage").hide(); //hide loading image
				alert(thrownError);
			}
			});
	});

	//##### Send delete Ajax request to response.php #########
	$("body").on("click", "#responds .del_button", function(e) {
		 e.preventDefault();
		 var clickedID = this.id.split('-'); //Split ID string (Split works as PHP explode)
		 var DbNumberID = clickedID[1]; //and get number from array
		 var myData = 'recordToDelete='+ DbNumberID; //build a post data structure
if(confirm("Are you sure you want to delete this?")){		 
		$('#item_'+DbNumberID).addClass( "sel" ); //change background of this element by adding class
		$(this).hide(); //hide currently clicked delete button

			jQuery.ajax({
			type: "POST", // HTTP method POST or GET
			url: "../controler/purchase_temp_dell.php", //Where to make Ajax calls
			dataType:"text", // Data type, HTML, json etc.
			data:myData, //Form variables
			success:function(response){
				//on success, hide  element user wants to delete.
				$('#item_'+DbNumberID).fadeOut();
			},
			error:function (xhr, ajaxOptions, thrownError){
				//On error, we alert user
				alert(thrownError);
			}
			});
}
	});

});
</script>







</body>
</html>