<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<?php foreach($kontak as $kontak) :   endforeach; ?> 
 
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="x-ua-compatible" content="ie=edge">

  <title>Laporan Transaksi</title>
  <!-- DataTables -->
  <link rel="stylesheet" href="<?php echo base_url();?>assets/plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="<?php echo base_url();?>assets/plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <!-- SweetAlert2 -->
  <link rel="stylesheet" href="<?php echo base_url();?>assets/plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css">
  <!-- Toastr -->
  <link rel="stylesheet" href="<?php echo base_url();?>assets/plugins/toastr/toastr.min.css">
  <link rel="icon" href="<?php echo base_url();?>images/kontak/<?php echo $kontak->logo ;?>" type="image/png" /> 
  <!-- Font Awesome Icons -->
  <link rel="stylesheet" href="<?php echo base_url();?>assets/plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="<?php echo base_url();?>assets/dist/css/adminlte.min.css">
  <!-- Google Font: Source Sans Pro -->
  
</head>
<body class="hold-transition sidebar-collapse layout-top-nav"  >
<div class="wrapper">

   

 

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
       
      
      
    </div>
    <!-- /.content-header -->

    <!-- Main content -->
    <div class="content">

        <div class="row">
          <div class="col-lg-12">
            <div class="card card-success card-outline">
              <div class="card-body">
              	<div class="row">
              		<div class="col-lg-12">
              			
              			<h2>LAPORAN TRANSAKSI <?php echo  strtoupper($jenis_laporan.' '.$kontak->nama_toko) ;?> </h2>
              			<h5>Alamat <?php echo  $kontak->alamat ;?> </h5>
              			<h5>Laporan <?php echo  ucwords($jenis_laporan).", " ;?>  <?php if($jenis_laporan =='harian'){
              				echo "Tanggal : ".$tanggal;
              			}else if($jenis_laporan =='bulanan'){
              				echo "Bulan : ".bulan_cetak(date($bulan))." Tahun ".$tahun;
              			} else if($jenis_laporan =='pilihan'){
              				echo "Tanggal : ".tgl_indo(date($tanggal_awal))." s/d ".tgl_indo(date($tanggal_akhir));

              			} else if($jenis_laporan =='kasir'){
              					$username = $this->session->userdata("username");  
												$this->db->where('username',$username);
												$query = $this->db->get('tb_admin');
												$row = $query->row();
											 
												$nama_admin = $row->nama_admin;
              				echo "Tanggal : ".tgl_indo(date($tanggal))." , Kasir : ".$nama_admin;

              			} 
              			?> </h5>
              				 
              		</div>
              	</div><!-- /.row -->
              	<table  class="table table-bordered ">
              		<thead>
              			<tr style="background-color: #bddb8e ">
              				<th>No</th>
              				<th>ID Transaksi</th>
              				<th>Date</th>
              				<th>Kantor</th>
              				<th>Member</th>
              				<th style="text-align: right;">Sub Total</th>
              				<th style="text-align: right;">Potongan</th>
              				<th style="text-align: right;">Total</th>
              				<th>Status</th>
              				<th>Pembayaran</th>
              				<th>Kasir</th>
              			 
              				
              			</tr>
              		</thead>
              		<tbody>

              			<?php $no=1; foreach($transaksi as $rows) : ?> 
              			<tr style="background-color: #70fff3;">
              				<td><?php echo $no; ?></td>
              				<td><a href="<?php echo base_url('transaksi/detail_transaksi/'); ?><?php echo $rows->id_transaksi; ?>" target="_blank"><?php echo $rows->id_transaksi; ?></a></td>
              				<td><?php echo $rows->date; ?></td>
              				<td>
              					<?php 
              					$id_kantor = $rows->id_kantor; 
              					$sql_menu = "SELECT * FROM tb_kantor WHERE  id_kantor = '$id_kantor' ";
              					$main_menu = $this->db->query($sql_menu)->result();
              					foreach ($main_menu as $maink) {
              						echo  $maink->nama_kantor;

              					}
              					?>
              				</td>
              				<td> 
              					<?php 
              					$id_member = $rows->id_member; 
              					$sql_menu = "SELECT * FROM tb_member WHERE  id_member = '$id_member' ";
              					$main_menu = $this->db->query($sql_menu)->result();
              					foreach ($main_menu as $maink) {
              						echo  $maink->nama_member;

              					}
              					?>
              				</td>
              				<td style="text-align: right;"><?php echo nominal($rows->sub_total); ?></td>
              				<td style="text-align: right;color: red;"><?php echo nominal($rows->potongan); ?></td>
              				<td style="text-align: right;color: #48bc16;"><?php echo nominal($rows->total); ?></td>
              				<td><?php echo $rows->status; ?></td>
              				<td><?php 
              				$id_metode = $rows->metode_bayar; 
              				$sql_menuk = "SELECT * FROM tb_metode WHERE  id_metode = '$id_metode' ";
              				$main_menuk = $this->db->query($sql_menuk)->result();
              				foreach ($main_menuk as $mainkk) {
              					echo  $mainkk->nama_metode;

              				}
              				?></td>



              				<td><?php 
              				$id_admin = $rows->id_admin; 
              				$sql_menu = "SELECT * FROM tb_admin WHERE  id = '$id_admin' ";
              				$main_menu = $this->db->query($sql_menu)->result();
              				foreach ($main_menu as $maink) {
              					echo   $maink->nama_admin;

              				}
              				?>

              			</td>


              		 
              		</tr>
         
              		<?php $no++; endforeach; ?>

              	</tbody>
              	<tfoot>
              		<tr>
              			<td></td>
              			<td></td>
              			<td></td>
              			<td></td>
              			<td>Total</td>
              				<?php $no=1; foreach($jumlah as $rowss) : ?> 
              			<td style="text-align: right;"> <?php echo nominal($rowss->sub_total); ?></td>
              			<td style="text-align: right;color: red;"><?php echo nominal($rowss->potongan); ?></td>
              			<td style="text-align: right;"><?php echo nominal($rowss->total); ?></td>
              			<?php  endforeach; ?>
              			<td></td>
              			<td></td>
              			<td></td>
              		</tr>

              	</tfoot>
              		

              </table>

              <br>
              <h3>Perhitungan Laba/Rugi</h3> 
              <hr>
              <div class="row">
              	<div class="col-lg-4">
              		<table width="100%">

              			<tr>
              				<td>Total Sub Total Transaksi</td>
              				<td>=</td>
              				<td style="text-align: right;color: #48bc16;"><?php echo nominal($rowss->sub_total); ?></td>
              				<td></td>
              			</tr>
              			<tr>
              				<td>Total Potongan</td>
              				<td>=</td>
              				<td style="text-align: right;color: red;"><?php echo nominal($rowss->potongan); ?> </td>
              				<td></td> 
              			</tr>
              			<tr>
              				<td></td>
              				<td></td>
              				<td style="text-align: right;">____________________</td>
              				<td>-</td>
              			</tr>
              			<tr>
              				<td>Total Kotor</td>
              				<td>=</td>
              				<td style="text-align: right;color: blue;"><?php echo nominal($rowss->sub_total - $rowss->potongan); ?></td>
              				<td></td>
              			</tr>
              			 
              		</table>
              	</div>
              	<div class="col-lg-4">
              		<table width="100%">
										<?php 
											$jenis_laporan= $this->input->post('jenis_laporan');
											$tanggal= $this->input->post('tanggal');
											$id_kantor_cari= $this->input->post('id_kantor');
											$bulan= $this->input->post('bulan');
											$tahun= $this->input->post('tahun');
											$tanggal_awal= $this->input->post('tanggal_awal');
											$tanggal_akhir= $this->input->post('tanggal_akhir');
											$id_admin= $this->input->post('id_admin');

										if($jenis_laporan =='harian'){
											if($id_kantor_cari == 'all'){
											  	$sql_total = "SELECT sum(harga_beli*jumlah) as t_beli , sum(harga_jual*jumlah) as t_jual  FROM tb_jual_detail WHERE date(tb_jual_detail.date) = '$tanggal'   ";
			              				$tt = $this->db->query($sql_total)->result();
			              				foreach ($tt as $t) { 
			              						$t_beli = $t->t_beli;
			              						$t_jual = $t->t_jual;


			              				}
											}else{
												 	$sql_total = "SELECT sum(harga_beli*jumlah) as t_beli , sum(harga_jual*jumlah) as t_jual  FROM tb_jual_detail WHERE    date(tb_jual_detail.date) = '$tanggal' and tb_jual_detail.id_kantor ='$id_kantor_cari'    ";
			              				$tt = $this->db->query($sql_total)->result();
			              				foreach ($tt as $t) { 
			              						$t_beli = $t->t_beli;
			              						$t_jual = $t->t_jual;


			              				}
											}

										}else  if($jenis_laporan =='bulanan'){
											if($id_kantor_cari == 'all'){
											  	$sql_total = "SELECT sum(harga_beli*jumlah) as t_beli , sum(harga_jual*jumlah) as t_jual  FROM tb_jual_detail WHERE  month(tb_jual_detail.date)='$bulan' and year(tb_jual_detail.date)='$tahun'  ";
			              				$tt = $this->db->query($sql_total)->result();
			              				foreach ($tt as $t) { 
			              						$t_beli = $t->t_beli;
			              						$t_jual = $t->t_jual;


			              				}
											}else{
												 	$sql_total = "SELECT sum(harga_beli*jumlah) as t_beli , sum(harga_jual*jumlah) as t_jual  FROM tb_jual_detail WHERE  tb_jual_detail.id_kantor ='$id_kantor_cari' and   month(tb_jual_detail.date)='$bulan' and year(tb_jual_detail.date)='$tahun'  ";
			              				$tt = $this->db->query($sql_total)->result();
			              				foreach ($tt as $t) { 
			              						$t_beli = $t->t_beli;
			              						$t_jual = $t->t_jual;


			              				}
											}
												
										}else  if($jenis_laporan =='pilihan'){
											if($id_kantor_cari == 'all'){
											  	$sql_total = "SELECT sum(harga_beli*jumlah) as t_beli , sum(harga_jual*jumlah) as t_jual  FROM tb_jual_detail WHERE  tb_jual_detail.date BETWEEN '$tanggal_awal' AND '$tanggal_akhir' ";
			              				$tt = $this->db->query($sql_total)->result();
			              				foreach ($tt as $t) { 
			              						$t_beli = $t->t_beli;
			              						$t_jual = $t->t_jual;


			              				}
											}else{
												 	$sql_total = "SELECT sum(harga_beli*jumlah) as t_beli , sum(harga_jual*jumlah) as t_jual  FROM tb_jual_detail WHERE    tb_jual_detail.id_kantor ='$id_kantor_cari'   and tb_jual_detail.date BETWEEN '$tanggal_awal' AND '$tanggal_akhir'  ";
			              				$tt = $this->db->query($sql_total)->result();
			              				foreach ($tt as $t) { 
			              						$t_beli = $t->t_beli;
			              						$t_jual = $t->t_jual;


			              				}
											}
										
										
										}else  if($jenis_laporan =='kasir'){
											if($id_kantor_cari == 'all'){
											  	$sql_total = "SELECT sum(harga_beli*jumlah) as t_beli , sum(harga_jual*jumlah) as t_jual  FROM tb_jual_detail WHERE date(tb_jual_detail.date) = '$tanggal' and tb_jual_detail.id_admin ='$id_admin'  ";
			              				$tt = $this->db->query($sql_total)->result();
			              				foreach ($tt as $t) { 
			              						$t_beli = $t->t_beli;
			              						$t_jual = $t->t_jual;


			              				}
											}else{
												 	$sql_total = "SELECT sum(harga_beli*jumlah) as t_beli , sum(harga_jual*jumlah) as t_jual  FROM tb_jual_detail WHERE    date(tb_jual_detail.date) = '$tanggal' and tb_jual_detail.id_kantor ='$id_kantor_cari' and tb_jual_detail.id_admin ='$id_admin'  ";
			              				$tt = $this->db->query($sql_total)->result();
			              				foreach ($tt as $t) { 
			              						$t_beli = $t->t_beli;
			              						$t_jual = $t->t_jual;


			              				}
											}
										
										}
										?>

              		 
              			<tr>
              				<td>Total Penjualan</td>
              				<td>=</td>
              				<td style="text-align: right;color: #039aaa;"><?php echo nominal($t_jual); ?></td>
              				<td></td>
              			</tr>
              			
              			<tr>
              				<td>Total Kulak</td>
              				<td>=</td>
              				<td style="text-align: right;color: #039aaa;"><?php echo nominal($t_beli); ?></td>
              				<td></td>
              			</tr>
              			<tr>
              				<td></td>
              				<td></td>
              				<td style="text-align: right;">____________________</td>
              				<td>-</td>
              			</tr>

              			<tr>
              				<td>Komisi</td>
              				<td>=</td>
              				<td style="text-align: right;"><?php echo nominal($t_jual - $t_beli); ?></td>
              				<td></td>
              			</tr>
              		</table>
              	</div>

              	
              	<div class="col-lg-4">
              		<table width="100%">
								 

              		 
              			<tr>
              				<td>Komisi</td>
              				<td>=</td>
              				<td style="text-align: right;"><?php echo nominal($t_jual - $t_beli); ?></td>
              				<td></td>
              			</tr>
              			
              			<tr>
              				<td>Total Potongan</td>
              				<td>=</td>
              				<td style="text-align: right;color: red;"><?php echo nominal($rowss->potongan); ?> </td>
              				<td></td> 
              			</tr>
              			<tr>
              				<td></td>
              				<td></td>
              				<td style="text-align: right;">____________________</td>
              				<td>-</td>
              			</tr>

              			<tr>
              				<td>LABA/RUGI</td>
              				<td>=</td>
              				<td style="text-align: right;"><?php echo nominal(($t_jual - $t_beli) - $rowss->potongan); ?></td>
              				<td></td>
              			</tr>
              		</table>
              	</div>
              </div>
               <hr>
              <div class="row">
              	<div class="col-lg-12">
              		<table width="100%" border="0">
              			<tr>

              				<td >Mangetahui,</td>
              				<td width="400px;"  ></td>
              				<td ><?php echo $kontak->kab_kota ; ?>, <?php echo tgl_indo(date('Y-m-d'));  ?></td>
              			</tr>
              			<tr>
              				<td>Manager </td>
              				<td width="400px;"></td>
              				<td>Admin</td>
              			</tr>
              			<tr height="70px;">
              				<td></td>
              				<td></td>
              				<td></td>
              			</tr>
              			<tr>
              				<td> (............................) </td>
              				<td width="400px;"></td>
              				<td><strong><?php echo $nama_admin; ?></strong></td>
              			</tr>
              		</table>

              	</div><!-- /.row -->
              </div>
            </div>

             
          </div>
          <!-- /.col-md-6 -->
          
          <!-- /.col-md-6 -->
        </div>
        <!-- /.row -->
      
    </div>
   
  </div>
  <!-- /.content-wrapper -->

   
 




 
<!-- jQuery -->
<script src="<?php echo base_url();?>assets/plugins/jquery/jquery.min.js"></script>
<script src="<?php echo base_url().'assets/js/jquery.js'?>"></script>
<script src="<?php echo base_url().'assets/js/numeral.min.js'?>"></script>
<!-- Bootstrap 4 -->
<script src="<?php echo base_url();?>assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="<?php echo base_url();?>assets/dist/js/adminlte.min.js"></script>
 
<!-- DataTables -->
<script src="<?php echo base_url();?>assets/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="<?php echo base_url();?>assets/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="<?php echo base_url();?>assets/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="<?php echo base_url();?>assets/plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
 
<!-- AdminLTE for demo purposes -->
<script src="<?php echo base_url();?>assets/dist/js/demo.js"></script>
 
</body>
</html>
