<?php 

$query="SELECT id,name FROM ".$prefix."buyer ORDER BY name ASC";

$buyer1=mysqli_query($linkid,$query);

$buyer2=mysqli_query($linkid,$query);



$query="SELECT id,name FROM ".$prefix."style ORDER BY name ASC";

$style1=mysqli_query($linkid,$query);

$query="SELECT id,name FROM ".$prefix."style ORDER BY name ASC";

$style2=mysqli_query($linkid,$query);

?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<script type="text/javascript" language="javascript">

	 $(document).ready(function(){

      var i=1;

     $("#add_row").click(function(){

      $('#addr'+i).html("<td>"+ (i+1) +"</td><td><input  name='description"+i+"' type='text' placeholder='Description'  class='span12'></td><td><input  name='buyer"+i+"' type='text' placeholder='Buyer'  class='span12'></td><td><input  name='style"+i+"' type='text' placeholder='Style'  class='span12'></td><td><input  name='quantity"+i+"' type='text' placeholder='Quantity'  class='span12'></td><td><input  name='price"+i+"' type='text' placeholder='Price' class='span12'></td><td><input  name='rate"+i+"' type='text' placeholder='Rate' class='span12'></td><td><input  name='remarks"+i+"' type='text' placeholder='Remark'  class='input_text'></td>");



      $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');

      i++; 

  });

     $("#delete_row").click(function(){

    	 if(i>1){

		 $("#addr"+(i-1)).html('');

		 i--;

		 }

	 });



});



</script>



<div id="contentwrapper">

  <div class="main_content">

    <nav>

      <div id="jCrumbs" class="breadCrumb module">

        <ul>

          <li> <a href="#"><i class="icon-home"></i></a> </li>

          <li> <a href="index.php?tab=daily-production">Daily Production</a> </li>

        </ul>

      </div>

    </nav>

    <div class="row-fluid">

      <div class="span12">

        <?php

		          	if(isset($_POST['submit']))

						{				

							$type=$_POST['type'];

						    $dateval=$_POST['mydate'];

							

							$query = "INSERT INTO ".$prefix."production values (null,'".$dateval."','$type','$uid')";

						    $result=mysqli_query($linkid,$query) or die(mysqli_error());

							$getid=mysqli_insert_id($linkid);

						

							

						if ($_POST['description0'])

							{

							$continue = FALSE;

							$i = 0;

								while ($continue == FALSE)

								{

								if (isset($_POST['description'.$i]))

									{

									$description=$_POST['description'.$i];						

									$buyer=$_POST['buyer'.$i];

									$style=$_POST['style'.$i];

									$quantity=$_POST['quantity'.$i];
									$dozenquantity=$_POST['quantity'.$i] / 12;

									$dozenrate=$_POST['price'.$i];
									
									$totalprice=$dozenquantity * $dozenrate;

									$rate=$_POST['rate'.$i];

									$amount=$totalprice*$rate;

									$remarks=$_POST['remarks'.$i];

									

									$query = "INSERT INTO ".$prefix."production_details values (null,'$getid','$description','$buyer','$style','$quantity','$dozenquantity','$dozenrate','$totalprice','$rate','$amount','$remarks')";

									 $result2=mysqli_query($linkid,$query) or die(mysqli_error());

									}

									 else

											{

												$continue = TRUE;

											}

											$i++;

							 

									}   

						  }		

													

						}	

					

						if($result2){

						?>

        <div class="alert alert-success"> <a data-dismiss="alert" class="close">x</a> <strong>Production Record</strong> is saved.&nbsp;&nbsp;</div>

        <script type="text/javascript" language="javascript">

							  setTimeout(function () {

								 window.location.href= 'index.php?tab=production-record'; // the redirect goes here

								},3000);

							  </script>

        <?php 

						}

							

					 //unlink($filename1);

					 

						 unset($_POST);

						 $_POST['submit']='';

						 $_POST='';

					?>

        <h3 class="heading">New Production Record</h3>

        <form class="form_validation_reg" id="form_validation_reg" action=""  method="post">

          <div class="formSep">

            <div class="row-fluid">

              <div class="span4">

                <label>Production Type<span class="f_req">*</span></label>

                <SELECT class="input_text" name="type" id="type">

                  <OPTION SELECTED VALUE="">Please Select</OPTION>

                  <OPTION VALUE="1">Haque Print</OPTION>

                  <OPTION VALUE="2">Haque Embroidery</OPTION>

                </SELECT>
				

              </div>

			  <div class="span4">

                <label>Date<span class="f_req">*</span></label>

                <input type="text" name="mydate" id="mydate" class="span12"  value="<?php echo date('Y-m-d');?>"/>

              </div>

			   <div class="span4">

              &nbsp;

			  </div>

            </div>

          </div>

          <div class="formSep">

            <div class="row-fluid">

              <div class="span12">

                <table class="table table-bordered table-hover" id="tab_logic"  border="0">

                  <thead>

                    <tr >

                      <th class="text-center"> # </th>

                      <th class="text-center"> Description </th>

					  <th class="text-center"> Buyer </th>

					  <th class="text-center"> Style </th>

					  <th class="text-center"> Quantity </th>

					  <th class="text-center"> Price(Dozen) </th>

					  <th class="text-center"> Rate($) </th>

                      <th class="text-center"> Remarks </th>

                    </tr>

                  </thead>

                  <tbody>

                    <tr id='addr0'>

                      <td  width="3%"> 1 </td>

                      <td><input type="text" name='description0'  placeholder='Description' class="span12"/></td>

					  <td>
					  <input type="text" name="buyer0" id="buyer0" class="span12" placeholder='Buyer' />                      

                      </td>

					  <td>
					<input type="text" name="style0" id="style0"  placeholder='Style' class="span12" />  
                        

                      </td>

                      <td><input type="text" name='quantity0' placeholder='Quantity' class="span12"/></td>

                      <td><input type="text" name='price0' placeholder='Price' class="span12"/></td>

					  <td><input type="text" name='rate0' placeholder='Rate' class="span12"/	></td>

					  <td><input type="text" name='remarks0' placeholder='Remarks' class="input_text"/></td>

                    </tr>

                    <tr id='addr1'></tr>

                  </tbody>

                </table>

              </div>

              <a id="add_row" class="btn btn-default pull-left">Add Row</a><a id='delete_row' class="pull-right btn btn-default">Delete Row</a> </div>

          </div>

          <div class="form-actions">

            <input class="btn btn-inverse" name="submit" type="submit" value="SAVE" />

            <button class="btn">Cancel</button>

          </div>

        </form>

      </div>

    </div>

  </div>

</div>

