<?php include("sass/icon_for_datepicker_and_datatable.php");?>
        
      
        
        <?php
$errMsg=""; 
if(isset($_POST['submit'])) // To check 'submmited or not' by if(isset($_POST['submit'])) 
{
	$customer_name = $_POST['customer_name'];
	$address = $_POST['address'];
	$district = $_POST['district'];
	$mobile_no = $_POST['mobile_no'];
	
	if(empty($customer_name)) $errMsg="write wholeseller name";
	if(empty($errMsg))
	{
		
		
		mysqli_query($connection,"INSERT INTO customer_setup (customer_name, address, district, mobile_no, branch_id) VALUES ('$customer_name','$address','$district','$mobile_no','$branch_id_for_header_user')")
		or die(mysqli_error());
		
		
		$result_for_sup_tran = mysqli_query($connection,"SELECT customer_id FROM customer_setup WHERE customer_name  = '$customer_name' AND address  = '$address' AND branch_id  = '$branch_id_for_header_user'");
		$test_for_sup_tran = mysqli_fetch_array($result_for_sup_tran);
				
				$customer_id=$test_for_sup_tran['customer_id'];
		
		
		
		mysqli_query($connection,"INSERT INTO transaction (date, customer_id, ledger, credit, hint, payment_type, branch_id) VALUES ('2014-01-02','$customer_id','2','0','sale due permanent customer','due','$branch_id_for_header_user')")
		or die(mysqli_error()) ;
		
		 
		$errMsg="Wholeseller Name Inserted Successfully";
	
}
}
?>

        
        
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <!-- Left side column. contains the logo and sidebar -->
            <?php include("sass/sidebar.php");?>

            <!-- Right side column. Contains the navbar and content of the page -->
               <aside class="right-side">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                       <?php echo $company_name ; ?>
                        <small>Control panel</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">customer Setup</li>
                    </ol>
                </section>
                 <section class="content">
                 <!---Main Content--->
                 
                     <div class="row">
                     
                         <div class="col-md-8 col-md-offset-2">
                         
                       
                        <?php
							if (!empty($errMsg))
							{echo "<div class='alert alert-warning alert-dismissible' role='alert'>$errMsg";
							echo "<button type='button' class='close' data-dismiss='alert'><span aria-hidden='false'>&times;</span><span class='sr-only'>		Close</span></button>
                        </div>";}
                        ?>
                        
                         <div class="box box-primary">
                                <div class="box-header">
                                    <h3 class="box-title">Whole seller Set-up</h3>
                                </div><!-- /.box-header -->
                                <!-- form start -->
                                <form role="form"  action="<?php echo "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post">
                                    <div class="box-body">
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Wholeseller Name</label>
                                            <input type="text" class="form-control" name="customer_name" id="" placeholder="write wholeseller name" required>
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Address</label>
                                            <input type="text" class="form-control" name="address" id="" placeholder="write address">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">District</label>
                                            <input type="text" class="form-control" name="district" id="" placeholder="write district name">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Mobile Number</label>
                                            <input type="text" class="form-control" name="mobile_no" id="" placeholder="write mobile number">
                                        </div>
                                     
                                    </div><!-- /.box-body -->

                                    <div class="box-footer">
                                        <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                </form>
                            </div>
                         
                         </div>
                         
                         
                         <div class="col-md-12">
                         
                         
                         <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">Wholesellers list with details</h3>
                                </div><!-- /.box-header -->
                                <div class="box-body table-responsive">
                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Wholeseller Name</th>
                                                <th>Address</th>
                                                <th>District</th>
                                                <th>Mobile Number</th>
                                                <th>Cash</th>
                                                <th>Bank</th>
                                                <th>Total</th>
                                                <th>Due</th>
                                                <th>Apply</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
												<?php
                                                
                                                $query = "SELECT * FROM customer_setup WHERE branch_id  = '$branch_id_for_header_user'";
                                                $result = mysqli_query($connection,$query);
                                                
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
                                                $customer_setup_id = $row['customer_id'];
                                                $customer_name = $row['customer_name'];
                                                $address = $row['address'];
                                                $district = $row['district'];
                                                $mobile_no = $row['mobile_no'];
												$opening_due = $row['opening_due'];
												$due = $row['due'];
												
												$result_for_supplier = mysqli_query($connection,"SELECT SUM(payment) AS Total_Payment , SUM(cash) AS cash , SUM(bank) AS bank FROM sale_taka WHERE customer_id  = '$customer_setup_id'");
		$test_for_supplier = mysqli_fetch_array($result_for_supplier);
				
				$Total_Payment=$test_for_supplier['Total_Payment'];
				$cash=$test_for_supplier['cash'];
				$bank=$test_for_supplier['bank'];
				$due= $due + $opening_due ;
				
				$result_for_supplier = mysqli_query($connection,"SELECT SUM(cash) AS cash , SUM(bank) AS bank FROM cus_due_payment WHERE customer_id  = '$customer_setup_id'");
		$test_for_supplier = mysqli_fetch_array($result_for_supplier);
				
				
				$cash_d=$test_for_supplier['cash'];
				$bank_d=$test_for_supplier['bank'];	
$total_d = $cash_d+$bank_d ;
				
				$Total_Payment = $Total_Payment + $total_d;
				$cash = $cash + $cash_d ;
				$bank = $bank + $bank_d ;
                                                
                                                echo "<tr>";
                                                echo "<td>$customer_name</td>";
                                                echo "<td>$address</td>";
                                                echo "<td>$district</td>";
                                                echo "<td>$mobile_no</td>";
                                                echo "<td>$cash</td>";
                                                echo "<td>$bank</td>";
                                                echo "<td>$Total_Payment</td>";
                                                echo "<td>$due</td>";
                                                echo "<td><button type='button' class='btn btn-info' id='supplier_button' value='$customer_setup_id' onclick='EditProduct(this.value)'><i class='fa fa-pencil-square-o'></i></button>
												
												</td>";
                                                echo "</tr>";
                                                }
                                                
                                                ?>
                                         
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>Wholeseller Name</th>
                                                <th>Address</th>
                                                <th>District</th>
                                                <th>Mobile Number</th>
                                                <th>Cash</th>
                                                <th>Bank</th>
                                                <th>Total</th>
                                                <th>Due</th>
                                                <th>Apply</th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div><!-- /.box-body -->
                            </div>
                         
                         </div>
                     </div>
                 
                 
                 
                 
                 </section>
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->
<script>
function EditProduct(id) {
    window.open('edit_customer.php?id='+id,'logos','width=500,height=500');}
</script>
  <?php include("sass/footer_for_datatable.php");?>

    </body>
</html>