<?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['estimatethree']="Estimatethree";
?>
<!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="#">Estimate</a></li>
          <li class="crumb-trail">Estimate 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> Estimate Add </span> </div>
            <div class="panel-body">
              
              <form class="cmxform form-horizontal" action="" method="POST">
              
              
              <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">
                  <label for="datepicker" class="col-lg-2 control-label">Date</label>
                  <div class="col-lg-10">
                    <div class="input-group"> <span class="input-group-addon"><i class="fa fa-calendar"></i> </span>
                      <input type="text" id="datepicker" name="dates" class="form-control datepicker mtn" placeholder="Date" required />
                  </div>
                  </div>
                </div>




 <div class="form-group">
                  <label for="cp" class="col-lg-2 control-label">Product</label>
                  <div class="col-lg-10">
                  
                    <div class="col-lg-12">
                                        
                    
                      <select class="form-control selectpicker" 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-2 control-label">L</label>
                  <div class="col-lg-10">
                    <div class="col-lg-12">
                      <input id="length" name="length" type="text" class="form-control" placeholder="Length" required="" autocomplete="off" />
                    </div>
                  </div>
</div>







 <div class="form-group">
<label for="cp" class="col-lg-2 control-label">W</label>
                  <div class="col-lg-10">
                    <div class="col-lg-12">
                      <input id="prwidth" name="prwidth" type="text" class="form-control" placeholder="Width" required="" autocomplete="off" />
                    </div>
                  </div>
</div>  
 
 
 
 
 
 
 
 
 
              
              
              
              
              <div class="form-group">
                  <label for="cp" class="col-lg-2 control-label">Machines Name</label>
                  <div class="col-lg-10">
                    <div class="col-lg-12">
                      <select class="selectpicker form-control" data-live-search="true" name="machinename" id="machinename" onchange="getCate(this.value);" tabindex="6">
                      
<option value="">--Select--</option>
 <?php
		
        $query=$db->execute("select * from machines_table where delet='0'");
		while($result=$query->fetch_assoc())
			{
				
		?>
        <option value="<?php echo $result['id'];?>"><?php echo $result['Machine_Name'];?></option>
        <?php
			}
		?>
   
      </select>
                    </div>
                  </div>
                </div>
                
                
                 <div class="form-group">
                  <label for="cp" class="col-lg-2 control-label">Category Name</label>
                  <div class="col-lg-10">
                    <div class="col-lg-12">
                      
                      <select class="form-control" name="categoryname" id="categor" onchange="getFields(this.value);">
<option value="">--Select--</option>
   
      </select>
                      
                    </div>
                  </div>
                </div>
                
                
                <div id="fields">
                  
                </div>
                
   
   

   
   
   
   
   
   
   
   
   
   
                
                
               <div class="form-group">
<label for="cp" class="col-lg-2 control-label">Type of Work</label>
                  <div class="col-lg-10">
                    <div class="col-lg-12">
                      <input id="typeofwrk" name="typeofwrk" type="text" class="form-control" placeholder="Type of Work" required="" autocomplete="off" />
                    </div>
                  </div>
</div> 
                
                
                
                
                
         <div class="form-group">
<label for="cp" class="col-lg-2 control-label">Description</label>
                  <div class="col-lg-10">
                    <div class="col-lg-12">
                      <input id="wrkdescription" name="wrkdescription" type="text" class="form-control" placeholder="Customer Description of work" required="" autocomplete="off" />
                    </div>
                  </div>
</div>       
                
                
                
                
                
                
                
                
                
                
              
                <div class="form-group">
                <div class="col-lg-11">
                  <input class="submit btn bg-purple pull-right" id="FormSubmit" name="catagry_add" type="submit" value="Submit" />
                  </div>
                </div>
              </form>
            </div>
          </div>
          </div>
          
          <div class="col-md-6" style="background-color: white;">
          <div class="panel">
            <div class="panel-heading"> <span class="panel-title"> <span class="glyphicon glyphicon-pencil"></span> Estimate </span> </div>
            <div class="panel-body pbn">
              <table class="table table-striped table-bordered table-hover" id="responds">
                <thead>
                  <tr>
                    <th>#</th>
                    <th>Machine</th>
                    <th>Category</th>
                    <th>Copys</th>
                    <th>Plate</th>
                    <th>CTP</th>
                    <th>Binding</th>
                    
                    <th class="text-center hidden-xs">Actions</th>
                  </tr>
                </thead>
                <tbody>
                  
                </tbody>
              </table>
            </div>
          </div>
          
          <form action="save_estimatethree.php" class="form-horizontal" method="post">
            <div class='col-xs-12 col-sm-12 col-md-6 col-lg-6'>
                <input type="hidden" name="sion" id="sion" value="<?php echo $_SESSION['prms'];?>" />
                <div class="form-group">
<label for="cp" class="col-lg-2 control-label">Advance</label>
                  <div class="col-lg-10">
                    <div class="input-group"><span class="input-group-addon"><i class="fa fa-hand-o-right"></i></span>
                      <input id="advamt" name="advamt" type="text" class="form-control" placeholder="Advance Amount" required="" autocomplete="off" />
                    </div>
                  </div>
</div> 		
                <input type="submit" id="Formsave" value="Save" name="save_estimatethree" class="btn btn-success pull-right"/>
            </div>
          </form>
          
          
          
          
          
          
          
          </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/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>
function getCate(val)
{
   $.ajax({
     type: 'post',
     url: 'get_category.php',
     data: {
       get_option:val
     },
     success: function (response) {
       document.getElementById("categor").innerHTML=response; 
     }
   });
}
function getFields(val)
{
   $.ajax({
     type: 'post',
     url: 'get_fields_three.php',
     data: {
       get_option:val
     },
     success: function (response) {
       document.getElementById("fields").innerHTML=response; 
     }
   });
}
</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($("#customer").val()==='')
			{
				alert("Please Select Customer!");
				return false;
			}
			else if($("#datepicker").val()==='')
			{
				alert("Please enter Date!");
				return false;
			}
			else if($("#machinename").val()==='')
			{
				alert("Please Select Machine!");
				return false;
			}
			else if($("#categor").val()==='')
			{
				alert("Please Select Category!");
				return false;
			}
            else if($("#prwidth").val()==='')
			{
				alert("Please Enter Paper Width!");
				return false;
			}
						
			$("#FormSubmit").hide(); //hide submit button
			$("#LoadingImage").show(); //show loading image
			
				
			//+ '&paperwght=' + $("#paperwght").val()
		 	var myData = 'datepicker='+ $("#datepicker").val() + '&customer=' + $("#customer").val() + '&product=' + $("#product").val() + '&machinename=' + $("#machinename").val() + '&categor=' + $("#categor").val() + '&numofcopys=' + $("#numofcopys").val() + '&plate=' + $("#plate").val() + '&ctp=' + $("#ctp").val()+ '&length=' + $("#length").val()+ '&prwidth=' + $("#prwidth").val()+ '&typeofwrk=' + $("#typeofwrk").val()+ '&wrkdescription=' + $("#wrkdescription").val()+ '&binding=' + $("input:radio[name=binding]:checked").val()+ '&sion=' + $("#sion").val(); //build a post data structure
			jQuery.ajax({
			type: "POST", // HTTP method POST or GET
			url: "../controler/estimate_three_add_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/dell_estimatethree_temp.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>