<?php 
require_once("config/configDB.php"); 
//session_start();
require "userPermission.php";
require 'financial_year_calculation.php';

$accountyear    = $financialYearStart."-".$financialYearEnd;

$sql_customer = mysqli_query($conn,"SELECT id,cname FROM customer_master WHERE isdelete='1' order by cname ASC ");
$row_customer = '';

$sqlproduct = mysqli_query($conn,"SELECT id, productname FROM product_master WHERE isdelete='1'  and product_type<>'Purchase' order by productname ASC ");

$sql_product = '';

while($prow = mysqli_fetch_array($sqlproduct)){

    $sql_product =$sql_product."<option value='".$prow['id']."'>".$prow['productname']."</option>";

}

$sqlInvoiceCount = mysqli_query($conn,"SELECT count(*) as invoice FROM saleheaderwo where flag=1 and accountyear='$accountyear'  and status=''");
 
$rowInvoiceCount=mysqli_fetch_array($sqlInvoiceCount,MYSQLI_ASSOC);

$invoice1   = sprintf('%03d',$rowInvoiceCount['invoice']+1);

//$invoice1   = sprintf('%03d',$rowInvoiceCount['invoice']+1);

$acyear="INE/".$syr."-".$eyr."/";

$invoice= $acyear.$invoice1;




date_default_timezone_set('Asia/Kolkata');
$currentTime = date( 'h:i:s A', time () );


?>

<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Sale Add</title>
    <?php require 'header.php' ?>
    <style>
    
    .table-grid{
        display: grid;
        width:95%;
        max-width: 95vw;
        margin:0px auto;
        height:100px;
       /* background-color: sandybrown;*/
        grid-template-columns: 200px repeat(8, auto) 90px;
    }
    .each-section{
        background-color: aqua;
        display:grid;
        grid-template-rows: 50% 50%;
    }
    .each-section div{
        background-color: white;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0px 10px;
        border: 1px solid #ccc;
    }
    .section-label{
        font-weight:700;
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-size:14px;
       
    }
    .section-input{
        background-color: #eee !important;
    }
    
    @media screen and (max-width:720px){
        .table-grid{
            display: flex;
            flex-direction: column;
            height:auto;
        }
        .each-section{
            grid-template-rows: 100%;
            grid-template-columns: 40% 60%;
            padding: 0px 0px;
        }
        .each-section div{
            padding: 10px;
        }
        .section-input input[type=button]{
            width:80%;
        }
    }
</style>


    
</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid">
<form class="form-horizontal" action="saleAddInsertwo.php" method="post">
<div class=" col-sm-12">
    <div class=" col-sm-2">
        <label for="inputlg">Invoice No</label>
        <input class="form-control input-lg" type="text" name="saleinvoice" value="<?php echo $invoice; ?>" readonly >
    </div>
    <div class=" col-sm-2">
        <label for="inputlg">Date</label>
        <input class="form-control input-lg datepicker-sale" id="date" type="text" name="saledate" autocomplete="off">
    </div>
    
    <div class="col-sm-4">
        <label for="inputlg">Customer </label>

        <select class="form-control input-lg customerName-select" name="customerName">
        <option value="">Please Select the Customer </option>
        <?php
        while($row = mysqli_fetch_array($sql_customer)){
        ?>
        <option value="<?php echo $row['id'] ?>" > <?php echo $row['cname']; ?> </option>
        <?php
        //echo "<option value='".$row['id']."'>".$row['cname']."</option>";
        }
        ?>
        </select>
         <input class="form-control input-lg" type="hidden" name="saleGSTNO" value="<?php echo  $COMPANYGST; ?>" >
    </div>
    

    <div class="col-sm-4">
        <label for="inputlg">Mode of Sales </label>

        <select class="form-control input-lg " name="sales_mode" required>
        <option value="">Please Select Mode of sales </option>
       
        <option value="Cash" > Cash </option>
        <option value="Upi" > Upi </option>
        <option value="cash_upi" > Cash and Upi </option>
       
        </select>
         <input class="form-control input-lg" type="hidden" name="saleGSTNO" value="<?php echo  $COMPANYGST; ?>" >
    </div>
     
</div>
<div class=" col-sm-12">
    
    
   
    <div class=" col-sm-6">
        <label for="inputlg">Customer Address</label>
        <input class="form-control input-lg" type="text" id="caddress" name="billing_address" >
    </div>
     <div class=" col-sm-6">
    <label for="inputlg">Remarks</label>
        <input class="form-control input-lg" type="text"  name="remarks" >
    </div>
    

</div>



<div>&nbsp;</div>

<div class="table-grid">
<div class="each-section">
        <div class="section-label">Category</div>
        <div class="section-input">
        <select class="form-control " name="category" id="category" >
            
           
           <option value="">Select the category </option>
           <option value="Gold">Gold</option>
           <option value="Silver">Silver</option>
        </select>
        </div>
    </div>

    <div class="each-section">
        <div class="section-label">Pro Name</div>
        <div class="section-input">
        <select class="form-control product-select-box" name="product" >
            <option value="">Select the Product </option>
            <?php echo  $sql_product; ?>
        </select>
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">Rate</div>
        <div class="section-input">
            <input class="form-control productrate" type="text" id="prate">
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">GR.WT</div>
        <div class="section-input">
            <input class="form-control " type="text" id="gross_weight" value="0.00" onFocus="this.value=''">
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">VA(%)</div>
        <div class="section-input">
            <input class="form-control " type="text" id="wastage_percentage" value="0.00" >
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">VA(G)</div>
        <div class="section-input">
            <input class="form-control " type="text" id="wastage" value="0.00">
        </div>
    </div>
    
    
    
    <div class="each-section">
        <div class="section-label">Net Quantity</div>
        <div class="section-input">
            <input class="form-control eqty-input" type="text" id="eqty"  readonly>
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">MC</div>
        <div class="section-input">
            <input class="form-control " type="text" id="making_charge" value="0.00" onFocus="this.value=''">
        </div>
    </div>
    
    
   
    
    
    </div>
    <div>
    <p>&nbsp;</p>
    </div>
    <div class="table-grid">
    
    <div class="each-section">
        <div class="section-label">Amount</div>
        <div class="section-input">
            <input class="form-control " type="text" id="amt" readonly>
        </div>
    </div>
    
    
     <div class="each-section">
        <div class="section-label">GST (%)</div>
        <div class="section-input">
            <input class="form-control " type="text" id="gst" readonly>
        </div>
    </div>
    <div class="each-section">
        <div class="section-label">GST Amount</div>
        <div class="section-input">
            <input class="form-control " type="text" id="gst_amount" readonly>
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">CGST Amount</div>
        <div class="section-input">
            <input class="form-control " type="text" id="cgst" readonly>
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">SGST Amount</div>
        <div class="section-input">
            <input class="form-control " type="text" id="sgst" readonly>
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">Net Amount</div>
        <div class="section-input">
            <input class="form-control " type="text" id="netamt" readonly>
        </div>
    </div>
    
    <div class="each-section">
        <div class="section-label">Action</div>
        <div class="section-input">
            <input type="button" class="btn btn-default addProduct-sale" value="Add">
        </div>
    </div>
    
    
    
</div>


<div class="container-fluid">
                                                                                       
  <div class="col-sm-12  table-responsive" style="padding-top: 25px;margin-top: 30px;">          
  <table class="table  table-striped table-bordered dt-responsive" style="overflow-x:auto;" id="saleDetailsAdd">
    <thead>
      <tr style="background-color:  lightsteelblue; border: 1px solid black;">
        <!-- <th>#</th> -->
        <!-- <th>Pro code</th> -->
        <th>Pro Name</th>
        <th>Category</th>
        <th>G.Wt</th>
        <th>VA(%)</th>
        <th>VA(g)</th>
        <th>Nt.Wt</th>
        <th>Rate</th>
        <th>GST(%)</th>
        <th>MC</th>
        <th>Amount</th>
        
        <th>GST (CGST + SGST) </th>
        <!-- <th>IGST</th> -->
        <th>Net amt</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      
    </tbody>
    <tfoot>
        <tr>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th>Total</th>
            <th class="saleT-Amount">0.000 <input class="form-control saleT-Amount" name="totalamt" type="hidden" value="0.000"></th>
            <th class="saleT-GST">0.000 <input class="form-control saleT-GST" name="totalGSTamt" type="hidden" value="0.000"></th>
            <th class="saleT-NetAmt">0.000<input class="form-control saleT-NetAmt" name="totalNetamt" type="hidden" value="0.000"></th>
            <th></th>
        </tr>
        </tfoot>
  </table>
  </div>
</div>

<div class="form-group">        
    <div class="col-sm-12 text-center">
        <button type="submit" class="btn btn-default">Submit</button>
    </div>
</div>

</form>
    <?php require 'footer.php' ?>
    <script type="text/javascript">var sql_product = "<?= $sql_product ?>";</script>
    <script type="text/javascript">var base_url = "<?= $base_url ?>";</script>
    <script type="text/javascript" language="javascript" src="js/saleaddwo.js"></script>
    <!-- Include jQuery -->
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Include Date Range Picker -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>


    <script>
	$(document).ready(function(){
		var date_input=$('input[name="saledate"]'); //our date input has the name "date"
		var container=$('form >  .datepicker-sale').length>0 ? $('form > .datepicker-sale ').parent() : "body";
		date_input.datepicker({
			format: 'dd-mm-yyyy',
			container: container,
			todayHighlight: true,
			autoclose: true,
        });

        
        

	});
</script>

</body>
</html>