<!-- Main content -->
<section class="content">
  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="card">
          <div class="card-header">
            <div class="row">
              <div class="col-sm-6">
                <h3 class="card-title">Profile Tagihan</h3>
              </div>
              <div class="col-sm-6">
                <ol class="float-sm-right mb-0">
                  <a type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#staticBackdrop">Tambah</a>
                </ol>
              </div>
              <!-- Modal Tambah -->
              <div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <form method="post" enctype="multipart/form-data">
                      <div class="modal-header bg-primary">
                        <h5 class="modal-title" id="staticBackdropLabel">Tambah Profile Tagihan</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                        </button>
                      </div>
                      <div class="modal-body">
                        <div class="card-body pb-0">
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Nama Server</label>
                                <select class="form-control" name="ids" required="required">
                                  <?php 
                                  $List = new Listdata();
                                  $List->set_list("data_server", $SqlDataWH);
                                  foreach ($List->get_list() as $key => $value): ?>
                                  <option value="<?php echo $value['id']; ?>" ><?php echo $value['nama_server']; ?></option>
                                  <?php endforeach ?>
                                </select>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Nama Profile Tagihan</label>
                                <input type="text" class="form-control" name="nama" required="required">
                              </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Tanggal Kirim Tagihan</label>
                                <input type="text" class="form-control" name="kirim" required="required">
                                <i class="text-danger">Isi tanggal pengiriman tagihan setiap bulan nya</i>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Konpensasi Tagihan</label>
                                <input type="text" class="form-control" name="konpensasi" required="required">
                                <i class="text-danger">Isi nilai persentase potongan tagihan perhari '3.333'</i>
                              </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Tanggal Isolir</label>
                                <input type="text" class="form-control" name="isolir" required="required">
                                <i class="text-danger">Isi tanggal saat isolir pelanggan</i>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Tanggal Buat Tagihan</label>
                                <input type="text" class="form-control" name="buat" required="required">
                                <i class="text-danger">Isi angka jumlah hari sebelum kirim tagihan</i>
                              </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>PPN Tagihan</label>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="ppn" id="exampleRadios1" value="1" checked>
                                  <label class="form-check-label" for="exampleRadios1">
                                    Harga Paket Tanpa PPN <?= $ppnnow.'%' ?>
                                  </label>
                                </div>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="ppn" id="exampleRadios2" value="2">
                                  <label class="form-check-label" for="exampleRadios2">
                                    Harga Paket Ditambah PPN <?= $ppnnow.'%' ?>
                                  </label>
                                </div>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="ppn" id="exampleRadios3" value="3">
                                  <label class="form-check-label" for="exampleRadios3">
                                    Harga Paket Termasuk PPN <?= $ppnnow.'%' ?>
                                  </label>
                                </div>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group form-check">
                                <input type="checkbox" class="form-check-input" value="1" name="peringatan" checked>
                                <label>Kirim Pesan Peringatan</label><br>
                                <i class="text-danger">Mengirim pesan peringatan 1 hari sebelum isolir pelanggan</i>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <input type="submit" name="tambah" class="btn btn-primary" value="Tambah">
                      </div>
                    </form>
                    <?php
                    if (isset($_POST['tambah'])) 
                    {
                      if($_POST['peringatan'] == 1) {
                        $peringatan = $_POST['isolir'] - 1 ;
                      } else {
                        $peringatan = '' ;
                      }
                      $SQLIN = "INSERT INTO profile_tagihan (id_data_server, nama, kirim_tagihan, buat_tagihan, limit_tagihan, konpensasi, ppn, peringatan_tagihan) VALUES ('$_POST[ids]', '$_POST[nama]', '$_POST[kirim]', '$_POST[buat]', '$_POST[isolir]','$_POST[konpensasi]', '$_POST[ppn]', '$peringatan')"; 
                      $input = mysqli_query($con,$SQLIN);
                      if ($input) 
                      {
                        sweetAlert("Data telah di tambah", "success");
                      }
                    }
                    ?>
                  </div>
                </div>
              </div>
              <!-- END Modal Tambah -->
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
            <table id="example1" class="table table-bordered table-striped">
              <thead>
              <tr>
                <?php if($SvId == 1) { ?>
                <th>Nama Server</th> <?php } ?>
                <th>Nama Profile</th>
                <th>PPN</th>
                <th>Tanggal Kirim Tagihan</th>
                <th>Tanggal Isoril</th>
                <th>Action</th>
              </tr>
              </thead>
              <tbody>
              <?php
                $aserver = mysqli_query($con,"SELECT * FROM profile_tagihan $SqlDataWHId");
                while ($server = mysqli_fetch_assoc($aserver)) 
                {
                if($server['ppn'] == 1 ) { $ppnw = 'Harga Paket Tanpa PPN '.$ppnnow.'%'; } elseif($server['ppn'] == 2 ) { $ppnw = 'Harga Paket Ditambah PPN '.$ppnnow.'%'; } elseif($server['ppn'] == 3 ) { $ppnw = 'Harga Paket Termasuk PPN '.$ppnnow.'%'; } elseif($server['ppn'] == 4 ) { $ppnw = 'Harga Paket Ditambah PPN '.$ppnnow.'% dan Subsidi 3 angka terakhir'; }
              ?>
              <tr>
                <?php if($SvId == 1) { ?>
                <td>
                  <?php 
                    $datasv = explode("|", $server['id_data_server']);
                    foreach ($datasv as $isidata)
                    {
                      $asv = mysqli_query($con,"SELECT nama_server FROM data_server WHERE id = '$isidata'");
                      $sv = mysqli_fetch_assoc($asv);
                      echo $sv['nama_server'];
                    } 
                  ?>
                </td>
                <?php } ?>
                <td><?php echo $server['nama']; ?></td>
                <td><?php echo $ppnw; ?></td>
                <td><?php echo 'tanggal '.$server['kirim_tagihan']; ?></td>
                <td><?php echo 'tanggal '.$server['limit_tagihan']; ?></td>
                <td>
                  <form method="post">
                    <a type="button" class="btn btn-secondary btn-sm ml-1" data-toggle="modal" data-target="#modal-edit<?php echo $server['id'];?>">Detail / Edit</a>
                    <input type="submit" name="hapus<?php echo $server['id'];?>" value="Hapus" class="btn btn-danger btn-sm ml-1" />
                  </form>
                </td>
              </tr>
              <!-- Modal Edit -->
              <div class="modal fade" id="modal-edit<?php echo $server['id'];?>" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <form method="post" enctype="multipart/form-data">
                      <div class="modal-header bg-secondary">
                        <h5 class="modal-title" id="staticBackdropLabel">Edit Profile Tagihan</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                          <span aria-hidden="true">&times;</span>
                        </button>
                      </div>
                      <div class="modal-body">
                        <div class="card-body pb-0">
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Nama Server</label>
                                <select class="form-control" name="ids">
                                <?php 
                                $List = new Listdata();
                                $List->set_list("data_server", $SqlDataWH);
                                foreach ($List->get_list() as $key => $value): ?>
                                <option value="<?php echo $value['id']; ?>" <?php if($value['id'] == $server['id_data_server']) { echo "selected";} ?> ><?php echo $value['nama_server']; ?></option>
                                <?php endforeach ?>
                              </select>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Nama Profile Tagihan</label>
                                <input type="text" class="form-control" value="<?php echo $server['nama']; ?>" name="nama" required="required">
                              </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Tanggal Kirim Tagihan</label>
                                <input type="text" class="form-control" value="<?php echo $server['kirim_tagihan']; ?>" name="kirim" required="required">
                                <i class="text-danger">Isi tanggal pengiriman tagihan setiap bulan nya</i>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Konpensasi Tagihan</label>
                                <input type="text" class="form-control" value="<?php echo $server['konpensasi']; ?>" name="konpensasi" required="required">
                                <i class="text-danger">Isi nilai persentase potongan tagihan perhari '3.333'</i>
                              </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Tanggal Isolir</label>
                                <input type="text" class="form-control" value="<?php echo $server['limit_tagihan']; ?>" name="isolir" required="required">
                                <i class="text-danger">Isi tanggal saat isolir pelanggan</i>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>Tanggal Buat Tagihan</label>
                                <input type="text" class="form-control" value="<?php echo $server['buat_tagihan']; ?>" name="buat" required="required">
                                <i class="text-danger">Isi angka jumlah hari sebelum kirim tagihan</i>
                              </div>
                            </div>
                          </div>
                          <div class="row">
                            <div class="col-sm-6">
                              <div class="form-group">
                                <label>PPN Tagihan</label>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="ppn" id="exampleRadios1" value="1" <?php echo ($server['ppn'] == 1 ) ? 'checked' : ''; ?>>
                                  <label class="form-check-label" for="exampleRadios1">
                                    Harga Paket Tanpa PPN <?= $ppnnow.'%' ?>
                                  </label>
                                </div>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="ppn" id="exampleRadios2" value="2" <?php echo ($server['ppn'] == 2 ) ? 'checked' : ''; ?>>
                                  <label class="form-check-label" for="exampleRadios2">
                                    Harga Paket Ditambah PPN <?= $ppnnow.'%' ?>
                                  </label>
                                </div>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="ppn" id="exampleRadios3" value="3" <?php echo ($server['ppn'] == 3 ) ? 'checked' : ''; ?>>
                                  <label class="form-check-label" for="exampleRadios3">
                                    Harga Paket Termasuk PPN <?= $ppnnow.'%' ?>
                                  </label>
                                </div>
                                <?php if($server['ppn'] == 4)  { ?>
                                <div class="form-check">
                                  <input class="form-check-input" type="radio" name="ppn" id="exampleRadios4" value="4" <?php echo ($server['ppn'] == 4 ) ? 'checked' : ''; ?>>
                                  <label class="form-check-label" for="exampleRadios4">
                                    Harga Ditambah PPN <?= $ppnnow.'%' ?> dan Subsidi 3 angka terakhir
                                  </label>
                                </div>
                                <?php } ?>
                              </div>
                            </div>
                            <div class="col-sm-6">
                              <div class="form-group form-check">
                                <input type="checkbox" class="form-check-input" value="1" name="peringatan" <?php if($server['peringatan_tagihan'] != '0'){ echo "checked";} ?>>
                                <label>Kirim Pesan Peringatan</label><br>
                                <i class="text-danger">Mengirim pesan peringatan 1 hari sebelum isolir pelanggan</i>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <input type="submit" name="edit<?php echo $server['id']; ?>" class="btn btn-warning" value="Edit">
                      </div>
                    </form>
                    <?php
                    if (isset($_POST['edit'.$server['id']])) 
                    {
                      if($_POST['peringatan'] == 1) {
                        $peringatan = $_POST['isolir'] - 1 ;
                      } else {
                        $peringatan = '' ;
                      }
                      $SQLUP = "UPDATE profile_tagihan SET id_data_server='$_POST[ids]', nama='$_POST[nama]', kirim_tagihan='$_POST[kirim]', buat_tagihan='$_POST[buat]', peringatan_tagihan='$peringatan', limit_tagihan='$_POST[isolir]', konpensasi='$_POST[konpensasi]', ppn='$_POST[ppn]' WHERE id = '$server[id]'";
                      $update = mysqli_query($con,$SQLUP);
                      if ($update) 
                      {
                        sweetAlert("Data telah di ubah", "success");
                      }
                    }
                    if (isset($_POST['hapus'.$server['id']]))
                    {
                      $iddata = $server['id'];
                      deleteAlert("profile_tagihan",$iddata );
                    } 
                    ?>
                  </div>
                </div>
              </div>
              <!-- END Modal Edit -->
            <?php } ?>
              </tbody>
            </table>
          </div>
          <!-- /.card-body -->
        </div>
        <!-- /.card -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </div>
  <!-- /.container-fluid -->
</section>
<!-- /.content -->