<?php
  if( !hasPermission($_SESSION['user_detail']['role_id'], 'company_add') ) {
    echo '<script>window.location.href="index.php?page=no_permission.php"</script>';die();
  }
    
  $voucher_no          = vendorCode($conn);
  $g_act_codes         = accountCode($conn);

  if (isset($_REQUEST['eid']) && !empty($_REQUEST['eid']) && $_REQUEST['eid']!=0){
    $select_update     = "SELECT * FROM company_mst WHERE id='".$_REQUEST['eid']."'";
    $select_update_res = mysqli_query($conn,$select_update);
    $update_row        = mysqli_fetch_array($select_update_res,MYSQLI_BOTH);
    $name              = $update_row['name'];
    $phone             = $update_row['phone'];
    $email             = $update_row['email'];
    $panno             = $update_row['panno'];
    $gst               = $update_row['gst'];
    $address           = $update_row['address'];
    $status            = $update_row['status'];
    $account_no        = $update_row['account_no'];
    $bank_name         = $update_row['bank_name'];
    $branch_name       = $update_row['branch'];
    $ifsc_code         = $update_row['ifsc_code'];
    $id                = $_REQUEST['eid'];
  }
?>
<section class="content-header">
  <div class="row">
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 bottom20">
        <h3 class="capital font15 padding5 bold">ADD NEW COMPANY</h3>
      </div>
      <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 text-right bottom20">
        <h3>
          <?php if( hasPermission($_SESSION['user_detail']['role_id'], 'company_list') ) { ?>
          <a href="index.php?page=company_mst/list.php" class="btn btn-danger capital bottom10 custome-btn">VIEW COMPANY DETAILS</a>
          <?php } ?>
        </h3>
      </div>
  </div>
</section>
<hr class="bottom35"> 
<section class="hitz-top-header">
   <div class="row bottom40">
      <div class="col-xs-12">
         <div class="box box-success">
            <div class="box-body">
              <form action="company_mst/insert.php" method="post" enctype="multipart/form-data" class="common-frm-validation" id="signupForm">
                <div class="row">
                  <div class="col-lg-6">
                    <legend class="capital hitz-legend">COMPANY DETAILS</legend>
                    <div class="row">
                      <div class="col-md-7">
                        <div class="form-group">
                          <label class="capital">name</label><span style="color: red">*</span>
                          <input type="text" size="35" id="name" name="name" class="form-control required" placeholder="COMPANY NAME" autocomplete="off" autofocus="" value="<?php echo $name;?>" onchange="Checkname(this.value);"/>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="capital">address</label><span style="color: red">*</span>
                          <textarea class="form-control required" name="address" id="address" style="height: 35px !important;"><?php echo $address;?></textarea> 
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="capital">PHONE</label><span style="color: red">*</span>
                          <input type="text" name="phone" id="phone" class="form-control required" placeholder="PHONE" value="<?php echo $phone;?>"/>
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="capital">EMAIL</label><span style="color: red">*</span>
                          <input type="text" name="email" id="email" class="form-control required" placeholder="EMAIL" value="<?php echo $email;?>"/>    
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="capital">PANCARD NO</label>
                          <input type="text" size="35" id="panno" name="panno" class="form-control" placeholder="PANCARD NO" autocomplete="off" value="<?php echo $panno;?>"/>
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="capital">GST NO</label><span style="color: red">*</span>
                          <input type="text" size="35" id="gst" name="gst" class="form-control required" placeholder="GST NO" autocomplete="off" value="<?php echo $gst;?>"/>
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="capital">Status</label><span style="color: red">*</span><br>
                          <label class="radio-inline fontradiobuttion">
                          <input type="radio" name="status" value="0" <?php echo ($status == 0) ? 'checked' : ''; ?>> <span class="label-text">ACTIVE</span>
                          </label>
                          <label class="radio-inline fontradiobuttion">
                          <input type="radio" name="status" value="1" <?php echo ($status == 1) ? 'checked' : ''; ?>> <span class="label-text">IN-ACTIVE</span>
                          </label>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="col-lg-6">
                    <legend class="capital hitz-legend">BANK DETAILS</legend>
                    <div class="row">
                      <div class="col-md-7">
                        <div class="form-group">
                          <label class="capital">BANK NAME</label><span style="color: red">*</span>
                          <input type="text" size="35" id="bank_name" name="bank_name" class="form-control required" placeholder="BANK NAME" autocomplete="off" autofocus="" value="<?php echo $bank_name;?>" />
                        </div>
                      </div>
                      <div class="col-md-5">
                        <div class="form-group">
                          <label class="capital">ACCOUNT NO</label><span style="color: red">*</span>
                          <input type="text" size="35" id="account_no" name="account_no" class="form-control required" placeholder="ACCOUNT NO" autocomplete="off" autofocus="" value="<?php echo $account_no;?>" />
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="capital">BRANCH</label><span style="color: red">*</span>
                          <input type="text" name="branch" id="branch" class="form-control required" placeholder="BRANCH" value="<?php echo $branch_name;?>"/>
                        </div>
                      </div>
                      <div class="col-md-4">
                        <div class="form-group">
                          <label class="capital">IFSC CODE</label><span style="color: red">*</span>
                          <input type="text" name="ifsc_code" id="ifsc_code" class="form-control required" placeholder="IFSC CODE" value="<?php echo $ifsc_code;?>"/>    
                        </div>
                      </div>
                    </div>
                    
                  </div>
                </div>
                <input type="hidden" value="<?php echo $id;?>" name="id" id="id">
                <hr>
                <div class="row" align="center">
                  <button id="btn" class="btn btn-primary ajax-submit capital" type="submit"> <?php echo ($id == 0) ? 'Save & List' : 'Update & save'; ?></button>
                  <a href="index.php?page=company_mst/list.php" class="btn btn-danger capital"> Cancel</a>
                </div>
              </form>
              
            </div>
         </div>
      </div>
   </div>
</section>
<script type="text/javascript">
  function Checkname() {
    var name = $("#name").val();
    $.ajax({
      'type': 'POST',
      'url': 'company_mst/check_name.php',
      'data': {
        'name': name
      },
      dataType: 'JSON',
        success: function (result) {
          if(result.status == 1) {
             jQuery('.submit').attr('disabled', false);
          }else{
            jQuery('.submit').attr('disabled', true);
            swal("Opps !!", "SAME COMPANY DETECT...!!!", "info")
            setTimeout("location.reload(true);",700);  
          }
        }
    });
  }
</script>