<!-- Content Header (Page header) -->
<section class="content-header">
  <h1>
    <i class="fa fa-folder-o icon-title"></i> NOTA LAUNDRY
	<a class="btn btn-primary btn-social pull-right" href="?module=form_penjualan&form=add" title="Tambah Data" data-toggle="tooltip">
      <i class="fa fa-plus"></i> Tambah
    </a>
  </h1>
  
  

</section>

<!-- Main content -->
<section class="content">
  <div class="row">
    <div class="col-md-12">

    <?php  
    // fungsi untuk menampilkan pesan
    // jika alert = "" (kosong)
    // tampilkan pesan "" (kosong)
    if (empty($_GET['alert'])) {
      echo "";
    } 
    // jika alert = 1
    // tampilkan pesan Sukses "Data obat baru berhasil disimpan"
    elseif ($_GET['alert'] == 1) {
      echo "<div class='alert alert-success alert-dismissable'>
              <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
              <h4>  <i class='icon fa fa-check-circle'></i> Sukses!</h4>
              Nota Laundry baru berhasil disimpan.
            </div>";
    }
    // jika alert = 2
    // tampilkan pesan Sukses "Data obat berhasil diubah"
    elseif ($_GET['alert'] == 2) {
      echo "<div class='alert alert-success alert-dismissable'>
              <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
              <h4>  <i class='icon fa fa-check-circle'></i> Sukses!</h4>
              Nota Laundry berhasil diubah.
            </div>";
    }
    // jika alert = 3
    // tampilkan pesan Sukses "Data obat berhasil dihapus"
    elseif ($_GET['alert'] == 3) {
      echo "<div class='alert alert-success alert-dismissable'>
              <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
              <h4>  <i class='icon fa fa-check-circle'></i> Sukses!</h4>
              Nota Laundry berhasil dinonaktifkan.
            </div>";
    }
	elseif ($_GET['alert'] == 5) {
      echo "<div class='alert alert-success alert-dismissable'>
              <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
              <h4>  <i class='icon fa fa-check-circle'></i> Sukses!</h4>
              Nota Laundry berhasil diselesaikan.
            </div>";
    }
    ?>

      <div class="box box-primary">
        <div class="box-body">
		<?php
			$dt = strtotime('today GMT');
			$awal = $_GET['awal'];
			$akhir = $_GET['akhir'];
				
			if ($awal == ""){
				$awal = date('01-m-Y', strtotime('today', $dt));
				$tglawal = date('Y-m-01', strtotime('today', $dt));
			}else{
				$tanggal = substr($awal,0,2);
				$bulan = substr($awal,3,2);
				$tahun = substr($awal,6,4);
				$tglawal = $tahun.'-'.$bulan.'-'.$tanggal;
			}
			
			if ($akhir == ""){
				$akhir = date('t-m-Y', strtotime('today', $dt)); 
				$tglakhir = date('Y-m-t', strtotime('today', $dt)); 
			}else{
				$tanggal = substr($akhir,0,2);
				$bulan = substr($akhir,3,2);
				$tahun = substr($akhir,6,4);
				$tglakhir = $tahun.'-'.$bulan.'-'.$tanggal;
			}	
			
			
			

		?>
		<form role="form" class="form-horizontal" method="POST" action="modules/penjualan/proses.php?act=view">


            <div class="form-group">
              <div class="col-sm-1"><label>Tanggal</label></div>
              <div class="col-sm-2">
                <input type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" name="tgl_awal" value = "<?php echo"$awal";?>" autocomplete="off" required>
              </div>

              <div class="col-sm-1" align="center"><label >s.d.</label></div>
              <div class="col-sm-2">
                <input type="text" class="form-control date-picker" data-date-format="dd-mm-yyyy" name="tgl_akhir" value = "<?php echo"$akhir";?>" autocomplete="off" required>
              </div>
			  
			  <div class="col-sm-2" style="padding-top:-10px">
                <button type="submit" class="btn btn-primary btn-social btn-submit">
                  <i class="fa fa-print"></i> View
                </button>
              </div>
            </div>
		</form>

          <!-- tampilan tabel obat -->
          <table id="dataTables1" class="table table-bordered table-striped table-hover">
            <!-- tampilan tabel header -->
            <thead>
              <tr>
				<th class="center">Tanggal</th>
                <th class="center">Inv #</th>              
                <th class="center">Customer</th>
				<th class="center">Jumlah</th>
				<th class="center">Selesai</th>
				<th class="center">Bayar</th>
                <th class="center">Action</th>
              </tr>
            </thead>
            <!-- tampilan tabel body -->
            <tbody>
            <?php  
            $no = 1;
			$gudang 		= $_SESSION['gudang'];
            // fungsi query untuk menampilkan data dari tabel obat
            $query = mysqli_query($mysqli, "SELECT * ,(select nama from customer where id = jual.supplier) as supp,(select sum(((qty * harga) * (100 - disc) / 100) - discharga) from jualdetail where billno = jual.billno) as tot 
											FROM jual 
											where status <> 'N' and gudang ='$gudang' and (billdate >= '$tglawal' and billdate <= '$tglakhir') ORDER BY billno ASC")
                                            or die('Ada kesalahan pada query tampil : '.mysqli_error($mysqli));

            // tampilkan data
            while ($data = mysqli_fetch_assoc($query)) { 
			  $billno = str_pad($data['billno'], 4, "0", STR_PAD_LEFT);
			  
			  $kode = str_pad($data['kode'], 4, "0", STR_PAD_LEFT);
			  $tanggal = tgl_ind($data['billdate']);
              $tot = format_rupiah(($data['tot'] * (100 - $data['d1']) / 100) - $data['d2']);
              // menampilkan isi tabel dari database ke tabel di aplikasi
			  if ($data['kirim'] == '1'){
				  $status = "<button class='btn btn-success' type='submit'><i
                                                        class='fa fa-check-square-o'></i> Selesai
                                            </button>";
			  }
			  else{
				  $status = "<button class='btn btn-warning' type='submit'><i class='fa fa-ban'></i> Belum
                                            </button>";
			  }
			  
			  if ($data['bayar'] == 'Y'){
				  $lunas = "<button class='btn btn-success' type='submit'><i
                                                        class='fa fa-check-square-o'></i> Lunas
                                            </button>";
			  }
			  else{
				  $lunas = "<button class='btn btn-warning' type='submit'><i class='fa fa-ban'></i> Belum
                                            </button>";
			  }

              echo "<tr>
					  <td class='center'><p style='display:none;'>$data[billdate]</p>$tanggal</td>
                      <td class='center'>$data[kode]</td>                    
                      <td >$data[supp]</td>
					   <td class='right'>$tot</td>
					   <td class='center'>$status</td>
					   <td class='center'>$lunas</td>
                      <td class='center'>
                        <div>
                          <a data-toggle='tooltip' data-placement='top' title='Lihat' style='margin-right:5px' class='btn btn-primary btn-sm' href='?module=form_penjualan&form=edit&id=$data[billno]'>
                              <i style='color:#fff' class='glyphicon glyphicon-edit'></i>
                          </a>";
            ?>
                          <a data-toggle="tooltip" data-placement="top" title="Hapus" class="btn btn-danger btn-sm" href="modules/penjualan/proses.php?act=delete&id=<?php echo $data['billno'];?>" onclick="return confirm('Anda yakin ingin menghapus invoice <?php echo $billno; ?> ?');">
                              <i style="color:#fff" class="glyphicon glyphicon-trash"></i>
                          </a>
						  &nbsp;
				
						  <a data-toggle="tooltip" data-placement="top" title="INV" class="btn btn-info btn-sm" target="_blank" href="modules/penjualan/cetak.php?id=<?php echo $data['billno'];?>" onclick="return confirm('Anda yakin ingin mencetak invoice <?php echo $kode; ?> ?');">
                              <i style="color:#fff" class="glyphicon glyphicon-print"></i>
                          </a>
						  &nbsp;
						  
						  <a data-toggle="tooltip" data-placement="top" title="Selesai" class="btn btn-warning btn-sm" target="_blank" href="modules/penjualan/proses.php?act=kirim&id=<?php echo $data['billno'];?>" onclick="return confirm('Anda yakin ingin selesaikan invoice <?php echo $kode; ?> ?');">
                              <i style="color:#fff" class="glyphicon glyphicon-thumbs-up"></i>
                          </a>
						  &nbsp;
						  
						  <a data-toggle="tooltip" data-placement="top" title="Selesai" class="btn btn-success btn-sm"  href="?module=form_piutang&form=edit&id=<?php echo $data['billno'];?>" onclick="return confirm('Anda yakin ingin selesaikan invoice <?php echo $kode; ?> ?');">
                              <i style="color:#fff" class="glyphicon glyphicon-usd"></i>
                          </a>
						  &nbsp;
						  
            <?php
              echo "    </div>
                      </td>
                    </tr>";
              $no++;
            }
            ?>
            </tbody>
          </table>
        </div><!-- /.box-body -->
      </div><!-- /.box -->
    </div><!--/.col -->
  </div>   <!-- /.row -->
</section><!-- /.content