<?php require_once('../auth/auth.php');?>
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-md-2"></div>
      <div class="col-md-8">
        <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
          <div class="card-header" style="padding: 5px 8px;">
            <h3 class="card-title"><?php echo language(296)?></h3>
            <div class="card-tools m-0">
              <div class="btn-group">
                <button type="button" class="btn btn-tool" data-dismiss="modal" data-card-widget="remove">
                <i class="fas fa-times"></i>
                </button>
              </div>
            </div>
          </div>
        <form id="price_adj" action="#" method="post" autocomplete="off"> 
           <input type="hidden" name="g_coid" value="<?php echo $coid;?>">
           <input type="hidden" name="g_bid" value="<?php echo $bid;?>">  
           <input type="hidden" name="g_brid" value="<?php echo $brid;?>">        
          <div class="card-body mt-2">
            <div class="col-md-12">
                <div class="row">
                  <div class="col-md-4">
                    <div class="form-group">
                      <label><?php echo language(69)?><b class="text-danger"> * </b></label>
                      <select name="item_gid" class="form-control select2" style="width: 100%;" required="true">
                        <?php
                        $pgroup_query= mysqli_query($conn,"SELECT pgid,pgroup_name FROM item_group  WHERE coid='$coid' AND bid='$bid' AND active=1 ORDER BY pgid ASC") or die (mysqli_error($conn));
                        while($rowgroup= mysqli_fetch_assoc($pgroup_query)){
                        echo '<option value='.$rowgroup["pgid"].'>'.$rowgroup["pgroup_name"].' </option>';
                        }?>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label><?php echo language(70)?><b class="text-danger"> * </b></label>
                      <select name="item_cid" class="form-control select2" style="width: 100%;" required="true">
                        <?php
                        $pcatt_query= mysqli_query($conn,"SELECT pcid,pcat_name FROM item_catagory  WHERE coid='$coid' AND bid='$bid' AND active=1 ORDER BY pcid ASC") or die (mysqli_error($conn));
                        while($rowcat= mysqli_fetch_assoc($pcatt_query)){
                        echo '<option value='.$rowcat["pcid"].'>'.$rowcat["pcat_name"].' </option>';
                        }?>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label><?php echo language(71)?><b class="text-danger"> * </b></label>
                      <select name="item_brnd" class="form-control select2" style="width: 100%;" required="true">
                        <option></option>
                        <?php
                        $pbrand_query= mysqli_query($conn,"SELECT pbid,pbrand_name FROM item_brand  WHERE coid='$coid' AND bid='$bid' AND active=1 ORDER BY pbid ASC") or die (mysqli_error($conn));
                        while($rowbrand= mysqli_fetch_assoc($pbrand_query)){
                        echo '<option value='.$rowbrand["pbid"].'>'.$rowbrand["pbrand_name"].'</option>';
                        }?>
                      </select>
                    </div>
                  </div> 
                  <div class="col-md-4">
                    <div class="form-group">
                      <label><?php echo language(207)?><b class="text-danger"> * </b></label>
                      <select name="price_type" class="form-control select2" style="width: 100%;" required="true">
                        <option value="mrp_sales"><?php echo language(141)?></option>
                        <option value="mrp_purchase"><?php echo language(81)?></option>
                      </select>
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label><?php echo language(130)?><b class="text-danger"> * </b></label>
                      <select name="plus" class="form-control select2" style="width: 100%;" required="true">
                        <option value="+"><?php echo language(217)?> (+)</option>
                        <option value="-"><?php echo language(218)?> (-)</option>
                      </select>
                    </div>
                  </div> 
                  <div class="col-md-4">
                     <div class="form-group">
                      <label><?php echo language(163)?><b class="text-danger"> * </b></label>
                      <div class="input-group">
                        <input type="number" name="parcent" class="form-control text-center form-control-sm amn" required="true" placeholder="%" step="0.001" min="0.01" max="100">
                         <div class="input-group-append">
                            <span class="input-group-text btn-outline-dark" onclick="amper(this);">%</span>
                         </div>
                      </div> 
                    </div>   
                  </div>                             
                </div>
            </div>
            <center>
              <div class="card-footer" style="padding: 8px 5px;">
                <button type="submit" id="save" class="btn btn-success btn-xs"><?php echo language(23);?></button>
                <button type="reset" class="btn btn-secondary btn-xs"><?php echo language(24);?></button>
              </div>
            </center>
          </div>
        </div>
      </div>
      <div class="col-md-2"></div>
    </div>
  </form>    
  </div>
</section>

<script>
  $("select").select2();    
  function amper(text) {
      $(text).text((_, ppp) => ppp == '%' ? '<?php echo $currency?>' : '%'); 
      $('.amn').attr({"name": (_, abc) => abc == 'parcent' ? 'amount' : 'parcent', "placeholder": (_, xyz) => xyz == '%' ? '<?php echo $currency?>' : '%', "max": (_, sdf) => sdf == 100 ? '' : 100});
   }
</script>

<script>
   $(document).ready(function() {
   $('#price_adj').on('submit', function(e){
   e.preventDefault(); 
   $('#save').prop('disabled', true);
   $('#save').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> '+'Loading...'); 
        $.post("../itemadjust/price_index_db.php",$(this).serialize(),function(data){
        toastr.success(Successfully, yourdata);
        pagecall('../itemadjust/price_index.php','#stockhome',0);
      });
     });
   });  
</script>