<?php
	$now = @$this->uri->segment(3);
	$cat = substr($now,-1);
	$query = $this->db->query("select sum(grand_total) as total from transaksi where status='1' and date(created_date)='".date("Y-m-d")."'")->result_array(); 
	$total =  $query[0]['total'];
	$queryb = $this->db->query("select sum(sisa) as total from transaksi where status='1' and date(created_date)='".date("Y-m-d")."'")->result_array(); 
	$totalb =  $queryb[0]['total'];
	$querys = $this->db->query("select sum(bayar) as total from transaksi where status='1' and date(created_date)='".date("Y-m-d")."'")->result_array(); 
	$totals =  $querys[0]['total'];
?>

<h3 class="page-header">
	<?php echo $judul;?>
</h3>
<div style='background:#0B2A05; padding:15px; color:#FFFFFF; font-size:17px; font-weight:normal;'>
	Penjualan : Rp. <?=number_format($total);?>
	:: Total Sudah Bayar : Rp. <?=number_format($totals);?>
	:: Total Belum Bayar : Rp. <?=number_format($totalb);?>
</div>
<div class="panel panel-default">
<div class="panel-heading">
	<div class="row">
		<div class='col-sm-8'><?php echo $judul;?> List</div>
		<div class='col-sm-4' align='right'>
		</div>
	</div>
</div>
<div class="panel-body">
	<div class="table-responsive">
		<table class="table table-striped table-bordered table-hover dataTables" id='ssp'>
			<thead>
				<tr>
					<th width='35'>No</th>
					<th width='100'>No Transaksi</th> 
					<th width='140'>Tanggal</th> 
					<th width=''>Pelanggan</th> 
					<th width='150'>Keterangan</th> 
					<th width='100'>Total</th> 
					<th width='50'>Diskon</th> 
					<th width='150'>Potongan</th> 
					<th width='100'>Grand Total</th>
					<th width='100'>Bayar</th>
					<th width='100'>Sisa</th>
					<th width='50'></th>
				</tr>
			</thead>
			<tbody>
				<?php
					$nos=1;
					if(isset($data) && count($data) > 0): foreach($data as $row):  
					$now = @$this->uri->segment(3);
				?>
				<tr>
					<td align='center'><?=$nos;?></td>
					<td align='left'><?=$row['no'];?></td>
					<td align='left'><?=$row['created_date'];?></td>
					<td align='left'><?=$row['pelanggan'];?></td>
					<td align='left'><?=$row['keterangan'];?></td>
					<td align='left'>Rp. <?=number_format($row['total']);?></td>
					<td align='left'><?=$row['diskon'];?>%</td>
					<td align='left'>Rp. <?=number_format($row['potongan']);?></td>
					<td align='left'>Rp. <?=number_format($row['grand_total']);?></td>
					<td align='left'>Rp. <?=number_format($row['bayar']);?></td>
					<td align='left'>Rp. <?=number_format($row['sisa']);?></td>
					<td align='center'>
						<button type='button' title="View"  data-toggle="modal-<?=$no;?>" data-target="#myModal-<?=$nos;?>" class='btn btn-xs btn-success modal-view'><i class="fa fa-eye "></i></button>
						<?php if($datasession["akses"]!="3"){?>
						<a title="Delete" class='btn btn-xs btn-danger' onclick="return confirm('Are you sure you want to delete this item?');" href="<?=base_url()?>cms/logic/deletet/transaksi/<?=$row['id_transaksi']?>?part=<?=$now;?>" class="text-danger"><i class="fa fa-trash-o"></i></a>					
						<?php }?>
						<div id="myModal-<?=$nos;?>" class="modal fade" role="dialog">
						  <div class="modal-dialog">

							<div class="modal-content">
							  <div class="modal-header" style='padding:10px;background:#172D44; color:#FFFFFF;'>
								<button type="button" class="close" data-dismiss="modal" style='color:#FFFFFF;'>&times;</button>
								<h4 class="modal-title">Detil Penjualan</h4>
							  </div>
							  <div class="modal-body">

<?php
		$item = $this->model_global->get_data(array(
			'select' => 'b.*,a.*, c.nama as satuan', 
			'table' => 'item a',
			'join' => array('barang b','b.id_barang = a.id_barang'),
			'join2' => array('satuan c','c.id_satuan = b.id_satuan'),
			'where' => array('a.status'=>1,'a.id_transaksi'=>$row['id_transaksi']), 
			'order_by' => 'b.nama asc'
		));		
		$isi = "<table width='100%'>";
		if(isset($item) && count($item) > 0):
		$no=1;
		foreach($item as $rows):
			$qty = $rows['qty'] * 1;
			$isi.="
				<tr>
					<td width='10' align='left' valign='top'>$no</td>
					<td width='' style='padding-bottom:10px;'>
						$rows[nama]<br>
						&nbsp; $qty $rows[satuan] x ".number_format($rows['harga'])."
						
					</td>
					<td width='50' align='right' valign='top'>".number_format($rows['total'])."</td>
				</tr>
			";
			$no++;
		endforeach; endif;
		$isi.= "</table>";
		echo " 
			<style>
				@font-face {
					font-family: merchant;
					src: url(".base_url()."assets/webadmin/fonts/merchant.ttf);
				}
				@font-face {
					font-family: receipt;
					src: url(".base_url()."assets/webadmin/fonts/receipt.ttf);
				}

				.modal-body{
					padding:0px;
					margin:10px 0px;
					font-family:receipt;
					font-size:12px;
					color:#000000;
					letter-spacing:-1px;
				}
				.modal-body td,.modal-body p,.modal-body div{
					font-size:12px;
					font-family:receipt;
					/*font-family:'courier new';*/
				}
				p{
					margin:0px;padding:0px;
					line-height: 13px;
				}
				@media print{
					.cetak{display:none;}
				}
			</style>
			
			<div align='center'> 
				
				$row[no]<br>$row[created_date]<br><br>
				Yth Bpk/Ibu : $row[pelanggan]
			</div>
			<div style='border-top:1px dashed #000000; margin:10px; padding:5px 0px;'>
				$isi
			</div> 
			<div style='border-top:1px dashed #000000;border-bottom:1px dashed #000000; margin:5px; padding:5px;'>
				<table width='100%'>
					<tr>
						<td></td>
						<td align='right' width='100'>Total</td><td width='10' align='center'>:</td>
						<td align='right' width='100'>Rp. ".number_format($row['total'])."</td>
					</tr>
					<tr>
						<td></td>
						<td align='right' width='100'>Diskon</td><td width='10' align='center'>:</td>
						<td align='right' width='100'>".$row['diskon']."%</td>
					</tr>
					<tr>
						<td></td>
						<td align='right' width='100'></td><td width='10' align='center'></td>
						<td align='right' width='100'>Rp. ".number_format($row['potongan'])."</td>
					</tr>
					<tr>
						<td></td>
						<td align='right' width='100'>Grand Total</td><td width='10' align='center'>:</td>
						<td align='right' width='100'>Rp. ".number_format($row['grand_total'])."</td>
					</tr>
					<tr>
						<td></td>
						<td align='right' width='100'>Bayar</td><td width='10' align='center'>:</td>
						<td align='right' width='100'>Rp. ".number_format($row['bayar'])."</td>
					</tr>
					<tr>
						<td></td>
						<td align='right' width='100'>Sisa</td><td width='10' align='center'>:</td>
						<td align='right' width='100'>Rp. ".number_format($row['sisa'])."</td>
					</tr>
				</table>
			</div> 
			<div style='margin:5px; padding:5px; text-align:left;'>
				<em>*) : $row[keterangan]</em>
			</div> 
			
		";
?>							  
							  </div>
							  <div class="modal-footer" style='padding:10px;'>
								<button type="button" class="btn btn-success cetak-ulang" data-dismiss="modal" data-id='<?=$row['id_transaksi'];?>'><i class='fa fa-print'></i> Cetak Ulang</button>
								<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
							  </div>
							</div>

						  </div>
					</td>
				</tr>
				</div>				
				<?php $nos++; endforeach; endif; ?>
			</tbody>
		</table>
	</div>
</div>
</div>