<?php
ob_start();
error_reporting(0);
include("connect.php");
session_start();
$ver = $_SESSION['distributor_user_id'];
$user_role= $_SESSION['user_role']; 
if(!isset($_SESSION["distributor_user_id"])){
   header('location:https://tarkashcorp.appexperts.net/index.php');
}
date_default_timezone_set('Asia/Calcutta');
$da  = date("Y-m-d");

$pid=$_GET['id'];
?>
<!DOCTYPE html>
<html lang="en">
    <head>
      <?php include("link_head.php");?>  
    <!-- END HEAD -->
<script>
<!--function myFunction() {
	var txt;
	var r = confirm("Are you sure to cancel!");
	if (r == true) {
		window.location.href="customer-master.php";
	} 
}-->

</script>
	<style>
	::-webkit-scrollbar {
		display: none;
		overflow: hidden;
	}
	</style>
	<script>
	window.onscroll = function () {
	window.scrollTo(0,0);
	}
	</script>			
		<script>
		function myfinalfunction()
		{
			var final_flag=0;
			var len_arr=document.forms["form1"]["temppro"].value;
			for (ik = 1; ik <=len_arr; ik++) { 
				var varcal11="proquan"+ik;
				if(document.forms["form1"][varcal11].value==0)
					document.forms["form1"][varcal11].value="";
			}
			for (ik = 1; ik <=len_arr; ik++) { 
				var varcal11="proquan"+ik;
				if(document.forms["form1"][varcal11].value!="")
					final_flag=1;
			}
			if(final_flag==0)
			{
				alert("Fields can't be empty or zero!");
				return false;
			}
			var len_arr=document.forms["form1"]["billdate"].value;
			var d = new Date();
			var cy = d.getFullYear();
			var cm = d.getMonth();
			var check_date=len_arr.split('-');
			if(check_date[1]!=cm && check_date[0]!=cy)
			{
				alert("Purchase can be added for current month only!");
				return false;
			}
			return true;
				
		}
		</script>
		<script> function valide() {  
		var today = new Date().toISOString().split('T')[0];
		document.getElementsByName("billdate")[0].setAttribute('max', today);
		} </script>
		<script>
		function partyAdd(str)		
		{  
		  if(str=='add_party')
		  {
			  window.location.href="add-purchase-party.php";
		  }
		} 
		</script>
		
		</head>
    <!-- END HEAD -->

    <body class="">
        <!-- BEGIN HEADER -->
		<?php include("header.php");?>
        <!-- END HEADER -->
		
        <!-- BEGIN CONTAINER -->
        <div class="container-fluid">
            <div class="page-content page-content-popup" style="margin-top:18px; max-height:542px;">
                
                <div class="page-sidebar-wrapper">
                    <!-- BEGIN SIDEBAR -->
                    <?php include("menu.php");?> 
				    <!-- END SIDEBAR -->
                </div>

                <!-- END SIDEBAR -->
                <!-- BEGIN CONTENT -->
                <div class="page-fixed-main-content">
                        <div class="row">
                            <div class="col-md-12">
                                <!-- BEGIN SAMPLE TABLE PORTLET-->
                                <div class="portlet">
                                    <div class="portlet-title">
                                        <div class="caption">
                                            <i class="fa fa-bell-o"></i>Edit All Order</div>
											<div class="actions">
										
										   <div class="form-group">
										   <a href="order-detail.php?id=<?=$pid; ?>"><button type="submit" style="padding:3px 10px;" class="btn btn-outline btn-circle blue btn-sm blue" name="searchd">Back </button></a>
											</div>
                                            </div>
                                    </div>
                        <!-- END PAGE BAR -->
                        <!-- BEGIN PAGE TITLE-->
                        <h1 class="page-title">
                        </h1>
                        <!-- END PAGE TITLE-->
                        <!-- END PAGE HEADER-->
                        <?php
						$call_pro_type=$_GET['type'];
						
						$res_check = mysqli_query($con,"select * from tbl_distributor where distributor_id='$ver'");  
						while($fetch_check=mysqli_fetch_assoc($res_check))
						{
							$distributor_category=$fetch_check['distributor_category'];
							if (strpos($distributor_category, 'FMCG') !== false) {
								$distributor_category="FMCG";
							}
							else
								$distributor_category="Service";
						}
						?>
                        <div class="row">
                            <div class="col-md-12">
                                <!-- BEGIN SAMPLE TABLE PORTLET-->
                                <div class="portlet">
                                    <div class="portlet-body" style="padding-bottom:0; margin-bottom:0.8%; height:380px; overflow-Y:scroll; overflow-X:hidden;">
                                        <div class="table-scrollable">
										<form name="form1" action="edit-all-confirmation.php?id=<?=$pid; ?>" onsubmit="return myfinalfunction();" method="post">
										 <div class="form-body">
							                <table class="table table-striped table-bordered table-advance table-hover">
                                                <thead>
                                                    <tr>
                                                        <th><b>S.No</b> </th>
														<th><b>Product Name</b></th>
														<th><b>Quantity</b></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
												<?php
												$pid=$_GET['id'];
												$c=1;
												$tk=0;
												date_default_timezone_set('Asia/Calcutta');
												$da  = date("Y-m-d");
										
												$res = mysqli_query($con,"select * from tbl_transaction_detail,tbl_master_product where
												tbl_transaction_detail.product_id=tbl_master_product.product_id and tbl_transaction_detail.transaction_id='$pid'");
												if(mysqli_num_rows($res)>0)
												{     
													while($fetch_product=mysqli_fetch_assoc($res))
													{
														$tk=$tk+1;
														extract($fetch_product);
												?>
                                                <tr>
												<td title="S.No."><?php echo $c++; ?></td>
                                                <td><?php echo $product_name; ?></a></td>
                                                <td>
												<input type="text" name="proquan<?php echo $tk; ?>" maxlength="12" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" value="<?=$quantity; ?>"> 
												</td>
												
                                                </tr>
												<?php }}  ?>
													
                                                </tbody>
                                            </table>
											 <div class="form-actions" style="padding:1%;">
											 <?php if($user_role=="Admin") { ?>
                                                <button type="submit" name="sub" class="btn blue">Submit</button>
                                                 <button type="submit" onClick="return confirm('Are you sure to cancel')" name="subcancel" class="btn blue">Cancel</button>
											 <?php } ?>
                                            </div>
                                        </form>
										
                                        </div>
										
                                    </div>
									
                                </div>
                                <!-- END SAMPLE TABLE PORTLET-->
                            </div>
							
                           
                        </div>
                    </div>
                    <!-- END CONTENT BODY -->
                </div>
                <!-- END CONTENT -->

            </div>
            <!-- END CONTAINER -->
            <!-- BEGIN FOOTER -->
		    <!-- END CONTAINER -->
            <!-- BEGIN FOOTER -->
		<!--<a href="#index" class="go2top">
                    <i class="icon-arrow-up"></i>
                </a>-->
                <!-- END FOOTER -->
            </div>
        </div>
        </div>
		<div class="copyright-v2" style="padding:3px; margin-top:-18px;">
		    <?=date("Y")?> &copy; Tarkashcorp Developed By <a target="_blank" href="http://www.belltechnology.in">Bell Technology</a>
			</div>
        </div>
        <!-- END CONTAINER -->
        <!-- BEGIN QUICK SIDEBAR -->
        <a href="javascript:;" class="page-quick-sidebar-toggler">
            <i class="icon-login"></i>
        </a>
        
        <!-- END QUICK SIDEBAR -->
        <!-- BEGIN QUICK NAV -->
        
        <div class="quick-nav-overlay"></div>
        <!-- END QUICK NAV -->
        
        <!-- BEGIN CORE PLUGINS -->
        <?php include("link_script.php");?>  
        <!-- END THEME LAYOUT SCRIPTS -->
        <script>
            $(document).ready(function()
            {
                $('#clickmewow').click(function()
                {
                    $('#radio1003').attr('checked', 'checked');
                });
            });
        </script>
    </body>
</html>