<?php 
  include '_header.php';
  include '_nav.php';
  include '_sidebar.php'; 
?>
<?php  
  // Pengkondisian Pemanggilan data berdasrkan cabang
  $cabangId = abs((int)base64_decode($_GET["cabang"]));
  if ( $sessionCabang < 1 ) {
    $cabangId = $cabangId;
    
  } else {
    $cabangId = $sessionCabang;
  }

  if ( $levelLogin !== "super admin" ) {
    echo "
      <script>
        document.location.href = 'bo';
      </script>
    ";
  }  
?>


  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Import Data Barang</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="bo">Home</a></li>
              <li class="breadcrumb-item active">Data Barang</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <!-- left column -->
          <div class="col-md-12">
            <!-- general form elements -->
            <div class="card card-default">
              <div class="card-header">
                <div class="row">
                    <div class="col-md-6 col-lg-6">
                        <h3 class="card-title card-title-user">Import Data Barang</h3>
                    </div>
                    <div class="col-md-6 col-lg-6">
                        <?php if ( $sessionCabang < 1 ) { ?>
                        <div class="box-user-select">
                          <?php if( isset($_POST["btn_filter"]) ){ ?>
                            <?php  
                              // Aksi filter cabang
                              $filter_cabang  = base64_encode($_POST['filter_cabang']);
                              echo "
                                <script>
                                  document.location.href = 'barang-import?cabang=".$filter_cabang."';
                                </script>
                              ";
                            ?>
                          <?php  } ?>
                          <form action="" method="POST">
                            <span style="color: red;"><b>Pilih Cabang untuk Import:</b> </span>
                            <span>
                                <select class="form-control" name="filter_cabang" required="">
                                    <?php 
                                      //Pengkondisian
                                      if ( $cabangId < 1 ) {
                                          $dataPilihCabangTeksUtama = "Pusat";
                                      } else {
                                          $dataPilihCabangTeksUtama = "Cabang ".$cabangId." ";
                                      }
                                    ?>
                                    <option value="<?= $cabangId; ?>"><?= $dataPilihCabangTeksUtama; ?></option>

                                    <?php foreach ( $dataPilihCabang as $row ) : ?>
                                      <?php if ( $row['toko_cabang'] != $cabangId ) { ?>
                                      <?php 
                                          //Pengkondisian
                                          if ( $row['toko_cabang'] < 1 ) {
                                            $dataPilihCabangTeks = "Pusat";
                                          } else {
                                            $dataPilihCabangTeks = "Cabang ".$row['toko_cabang']." ";
                                          }
                                      ?>

                                      <option value="<?= $row['toko_cabang']; ?>">
                                          <?= $dataPilihCabangTeks; ?>
                                      </option>
                                      <?php } ?> 
                                    <?php endforeach; ?>
                                </select>
                            </span>
                            <span>
                              <button type="submit" class="btn btn-primary" name="btn_filter"><i class="fa fa-filter"></i></button>
                            </span>
                          </form>
                        </div>
                        <?php } ?>
                    </div>
                </div>
              </div>
             
              <form id="idfrmtarg6" action="" method="POST" enctype="multipart/form-data">
                  <div class="wizard-form-input wsb">
                      <div class="row">
                          <div class="col-md-6 col-lg-6">
                              <div class="wizard-form-input-finish">
                                 <div class="wfif-img">
                                      <img src="dist/img/img-download.png" alt="image" class="img-fluid">
                                  </div>
                                  <div class="wfif-title">
                                       Download Template, Kategori & Satuan
                                  </div>
                                  <div class="wfif-cta wfif-cta-download">
                                       <a class="btn btn-primary" data-toggle="modal" href='#modal-id'>Download</a>
                                  </div>
                              </div>
                            </div>
                            <div class="col-md-6 col-lg-6">
                                <div class="wizard-form-input-finish">
                                    <div class="wfif-img">
                                        <img src="dist/img/img-upload.png" alt="image" class="img-fluid">
                                    </div>
                                    <div class="wfif-title">
                                         Import Data Barang
                                    </div>
                                    <div class="wfif-cta">
                                      <?php include "barang-import-proses.php"; ?>
                                      <form action="" method="POST" enctype="multipart/form-data" >
                                        <div class="row">
                                          <div class="col-6">
                                            <input type="file" accept=".xls, .xlsx" name="filexls" id="formFile" required>
                                            <input type="hidden" name="barang_cabang" value="<?= $cabangId; ?>">
                                          </div>
                                          <div class="col-6">
                                              <input type="submit" name="submit" class="btn btn-success" value="Upload File">
                                          </div>
                                        </div>
                                      </form>
                                    </div>
                                 </div>
                              </div>
                         </div>
                      </div> 
                   </form>
            </div>
          </div>
        </div>
      </div>
    </section>


  </div>

  <div class="modal fade" id="modal-id" data-backdrop="static">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header">
                 <h4 class="modal-title">Download 3 File Berikut:</h4>
                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              </div>
              <div class="modal-body">
                  <div class="modal-body-button">
                      <a href="vendor/file-excel-download/template-barang-v1.zip">
                          <button type="" name="" class="btn btn-success">Template Excel <i class="fa fa-download"></i></button>
                      </a>
                      <a>
                         <form action="barang-import-export-kategori" method="POST" class="">
                            <input type="hidden" name="kategori_cabang" value="<?= $sessionCabang; ?>">
                                <button type="submit" name="export_btn" class="btn btn-primary">ID Kategori Barang <i class="fa fa-download"></i></button>
                          </form>
                      </a>
                      <a>
                         <form action="barang-import-export-satuan" method="POST" class="">
                            <input type="hidden" name="satuan_cabang" value="<?= $sessionCabang; ?>">
                                <button type="submit" name="export_btn" class="btn btn-warning">ID Satuan Barang <i class="fa fa-download"></i></button>
                          </form>
                      </a>
                   </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
          </div>
    </div>

<?php include '_footer.php'; ?>
<script>
    function hanyaAngka(evt) {
      var charCode = (evt.which) ? evt.which : event.keyCode
       if (charCode > 31 && (charCode < 48 || charCode > 57))
 
        return false;
      return true;
    }
</script>

