<?php
$page = $this->uri->segment(3); 
?>


                    </div>
                </div> 
				 
            </div>
        </div>
    </div>
		<div class='overlay-all'>
			<div class='inoverlay'>
				<div class='contentoverlay'>
					Silahkan tunggu...
				</div>
			</div>
		</div>	
    <script src="<?=base_url()?>assets/webadmin/js/jquery-1.10.2.js"></script>
    <script src="<?=base_url()?>assets/webadmin/js/bootstrap.min.js"></script>
    <script src="<?=base_url()?>assets/webadmin/js/hotkey.js"></script>
    <script src="<?=base_url()?>assets/webadmin/js/tag.js"></script>
    <script src="<?=base_url()?>assets/webadmin/js/jquery.metisMenu.js"></script>
    <script src="<?=base_url()?>assets/webadmin/js/dataTables/jquery.dataTables.js"></script>
    <script src="<?=base_url()?>assets/webadmin/js/dataTables/dataTables.bootstrap.js"></script>
	<script src="<?=base_url()?>assets/datepicker/js/bootstrap-datepicker.js"></script>
	<script src="<?=base_url()?>assets/webadmin/js/bootstrap-datetimepicker.js"></script>
	<script src="<?=base_url()?>assets/webadmin/js/bootstrap-datetimepickerid.js"></script>
		<!--fancy-->
		<script type="text/javascript" src="<?=base_url()?>assets/fancy/jquery.mousewheel-3.0.6.pack.js"></script>
		<script type="text/javascript" src="<?=base_url()?>assets/fancy/jquery.fancybox.js?v=2.1.5"></script>
		<link rel="stylesheet" type="text/css" href="<?=base_url()?>assets/fancy/jquery.fancybox.css?v=2.1.5" media="screen" />
		<link rel="stylesheet" type="text/css" href="<?=base_url()?>assets/fancy/helpers/jquery.fancybox-buttons.css?v=1.0.5" />
		<script type="text/javascript" src="<?=base_url()?>assets/fancy/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
		<link rel="stylesheet" type="text/css" href="<?=base_url()?>assets/fancy/helpers/jquery.fancybox-thumbs.css?v=1.0.7" />
		<script type="text/javascript" src="<?=base_url()?>assets/fancy/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>
		<script type="text/javascript" src="<?=base_url()?>assets/fancy/helpers/jquery.fancybox-media.js?v=1.0.6"></script>		
		<!--endfancy-->	
	<!--<script type="text/javascript" src="<?=base_url()?>assets/webadmin/tinymce/tinymce.min.js"></script>
	<script type="text/javascript" src="<?=base_url()?>assets/webadmin/tinymce/jquery.tinymce.min.js"></script>	-->
	
	<script type="text/javascript" src="<?=base_url()?>assets/webadmin/js/moment.js"></script>	
	<script type="text/javascript" src="<?=base_url()?>assets/webadmin/js/daterangepicker.js"></script>	
	<script type="text/javascript" src="<?=base_url()?>assets/webadmin/chartjs/Chart.bundle.js"></script>	
	<script type="text/javascript" src="<?=base_url()?>assets/webadmin/chartjs/canvasjs.min.js"></script>			
		<?php
		$uri =  $this->uri->segment(3); 
		?>		
        <script> 
	function getRandomColor() {
	  var letters = '0123456789ABCDEF';
	  var color = '#';
	  for (var i = 0; i < 6; i++) {
		color += letters[Math.floor(Math.random() * 16)];
	  }
	  return color;
	  
	}
			function numberWithCommas(x) {
				return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
			}	

	<?php
				function random_color_part() {
					return str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT);
				}

				function random_color() {
					return random_color_part() . random_color_part() . random_color_part();
				}	
				if($uri=="laporan"){ 
					if(isset($resultgraph) && count($resultgraph) > 0){ 
						$grv="";$grt="";
						$warna="";
						$border="";
						foreach($resultgraph as $row){
							$x = explode("-",$row['tanggal']);
							$tgl = $x[2]."/".$x[1]."/".$x[0];
							$grv.= $row['total'].",";
							$grt.= $tgl.",";
							$warna.= '#'.random_color()."xx";
							$border.= "#FFFFFF,";
						}
						$grv = substr_replace($grv ,"", -1);
						$grt = substr_replace($grt ,"", -1);
						$warna = substr_replace($warna ,"", -2);
						$border = substr_replace($border ,"", -1);
					
			?>
			
			
			var grv = "<?=$grv;?>";
			var grt = "<?=$grt;?>";
			var warna = "<?=$warna;?>";
			var border = "<?=$border;?>";
			
			var argrv = grv.split(",");
			var argrt = grt.split(",");
			var arwarna = warna.split("xx");
			var arborder = border.split(",");
			var ctx = document.getElementById('myChart').getContext('2d');
			var myChart = new Chart(ctx, {
				
				type: 'bar',
				data: {
					labels: argrt,
					datasets: [{
						label: '',
						data: argrv,
						backgroundColor:arwarna,
						borderColor:arborder,
						borderWidth: 1
					}]
				},
				options: {
					tooltips: {
						callbacks: {
							label: function(tooltipItem, data) {
								var label = data.datasets[tooltipItem.datasetIndex].label || '';

								if (label) {
									label += ': ';
								}
								label += Math.round(tooltipItem.yLabel * 100) / 100;
								return "Rp. "+numberWithCommas(label);
							}
						}
					},					
					legend: {
						display: false
					},
					title: {
						display: true,
						text: 'Grapik Penjualan'
					},					
					scales: {
						display: true,
						yAxes: [{
							ticks: {
								beginAtZero: false,
								callback: function(value, index, values) {
								  return value.toLocaleString();
								}
							}
						}]
					}
				}
			});		
			 
			
		<?php }}?>
		<?php
				if($uri=="laporanp"){ 
					if(isset($resultgraph) && count($resultgraph) > 0){ 
						$grv="";$grt="";
						$warna="";
						$border="";
						foreach($resultgraph as $row){
							$x = explode("-",$row['tanggal']);
							$tgl = $x[2]."/".$x[1]."/".$x[0];
							$grv.= $row['total'].",";
							$grt.= $tgl.",";
							$warna.= '#'.random_color()."xx";
							$border.= "#FFFFFF,";
						}
						$grv = substr_replace($grv ,"", -1);
						$grt = substr_replace($grt ,"", -1);
						$warna = substr_replace($warna ,"", -2);
						$border = substr_replace($border ,"", -1);
					
			?>
			
			
			var grv = "<?=$grv;?>";
			var grt = "<?=$grt;?>";
			var warna = "<?=$warna;?>";
			var border = "<?=$border;?>";
			
			var argrv = grv.split(",");
			var argrt = grt.split(",");
			var arwarna = warna.split("xx");
			var arborder = border.split(",");
			var ctx = document.getElementById('myChart').getContext('2d');
			var myChart = new Chart(ctx, {
				
				type: 'bar',
				data: {
					labels: argrt,
					datasets: [{
						label: '',
						data: argrv,
						backgroundColor:arwarna,
						borderColor:arborder,
						borderWidth: 1
					}]
				},
				options: {
					tooltips: {
						callbacks: {
							label: function(tooltipItem, data) {
								var label = data.datasets[tooltipItem.datasetIndex].label || '';

								if (label) {
									label += ': ';
								}
								label += Math.round(tooltipItem.yLabel * 100) / 100;
								return "Rp. "+numberWithCommas(label);
							}
						}
					},					
					legend: {
						display: false
					},
					title: {
						display: true,
						text: 'Grapik Pembelian'
					},					
					scales: {
						display: true,
						yAxes: [{
							ticks: {
								beginAtZero: false,
								callback: function(value, index, values) {
								  return value.toLocaleString();
								}
							}
						}]
					}
				}
			});		
			 
			
		<?php }}?>		
		<?php if($uri=="laporan-laba"){
			if(isset($resultgraph) && count($resultgraph) > 0){ 
				$grv="";$grt="";
				$warna="";
				$border="";
				foreach($resultgraph as $row){ 
					$grv.= $row['total'].",";
					$grt.= $row['bln'].",";
					$warna.= '#'.random_color()."xx";
					$border.= "#FFFFFF,";
				}
				$grv = substr_replace($grv ,"", -1);
				$grt = substr_replace($grt ,"", -1);
				$warna = substr_replace($warna ,"", -2);
				$border = substr_replace($border ,"", -1);
		?>		
			var grv = "<?=$grv;?>";
			var grt = "<?=$grt;?>";
			var warna = "<?=$warna;?>";
			var border = "<?=$border;?>";
			
			var argrv = grv.split(",");
			var argrt = grt.split(",");
			var arwarna = warna.split("xx");
			var arborder = border.split(",");
			var ctx = document.getElementById('myChartLaba').getContext('2d');
			var myChart = new Chart(ctx, {
				
				type: 'bar',
				data: {
					labels: argrt,
					datasets: [{
						label: '',
						data: argrv,
						backgroundColor:arwarna,
						borderColor:arborder,
						borderWidth: 1
					}]
				},
				options: {
					tooltips: {
						callbacks: {
							label: function(tooltipItem, data) {
								var label = data.datasets[tooltipItem.datasetIndex].label || '';

								if (label) {
									label += ': ';
								}
								label += Math.round(tooltipItem.yLabel * 100) / 100;
								return "Rp. "+numberWithCommas(label);
							}
						}
					},					
					legend: {
						display: false
					},
					title: {
						display: true,
						text: 'Grapik Penjualan'
					},					
					scales: {
						display: true,
						yAxes: [{
							ticks: {
								beginAtZero: false,
								callback: function(value, index, values) {
								  return value.toLocaleString();
								}
							}
						}]
					}
				}
			});	
		<?php }}?>		


	
		
			//$(".modal").modal()
			$(document).on('click', '.btn-detil', function(e) {
				$('#detil').show();
				$('#graph').hide();
			});
			$(document).on('click', '.btn-graph', function(e) {
				$('#detil').hide();
				$('#graph').show();
			});
			$(document).on('click', '.del-row', function(e) {
				if (confirm("Hapus ?")) {
					$(this).closest('tr').remove();
					var val = $(this).attr('data-val');
					$("#pilih_barang option[value='"+val+"']").removeAttr('style');
					$("#diskon").val('');
					sum();
				} 
			}); 
			$(document).on('click', '.del-rowmutasi', function(e) {
				if (confirm("Hapus ?")) {
					$(this).closest('tr').remove();
					var val = $(this).attr('data-val');
					$("#mutasi_barang option[value='"+val+"']").removeAttr('style');
					summutasi();
				} 
			}); 
			$(document).on('click', '.del-rowbeli', function(e) {
				if (confirm("Hapus ?")) {
					$(this).closest('tr').remove();
					var val = $(this).attr('data-val');
					$("#beli_barang option[value='"+val+"']").removeAttr('style');
					sumbeli();
				} 
			}); 
		$('#mutasi_barang').on('change', function() {
			var harga = $('option:selected', this).attr('data-harga');
			var stok = $('option:selected', this).attr('data-stok');
			if(stok==undefined && harga==undefined){
				
			}else{
				$('#mutasi_harga').val(harga);
			}
		});
		$('#pilih_barang').on('change', function() {
			var jenis = $('#jenis_harga').val(); 
			var pilih = 'satuan';
			switch(jenis){
				case "1":pilih='resep';break;
				case "2":pilih='satuan';break;
				case "3":pilih='box';break;
			} 				
			var stok = $('option:selected', this).attr('data-stok');
			var harga = $('option:selected', this).attr('data-'+pilih);
			var nama = $('option:selected', this).attr('data-nama');
			var satuan = $('option:selected', this).attr('data-satuan');
			//console.log(stok + " " + harga);$('option:selected', this)
			if(stok==undefined && harga==undefined){
				
			}else{
				$('#pilih_qty').val('');
				$('#pilih_qty').attr('data-max',stok);
				$('#pilih_qty').attr('data-satuan',harga);
				$('#pilih_total').val(addCommas(0));
				$('#pilih_qty').focus();
			}
		});
		$('#jenis_harga').on('change', function() {
			var j = $(this).val();
			var pilih = 'satuan';
			switch(j){
				case "1":pilih='resep';break;
				case "2":pilih='satuan';break;
				case "3":pilih='box';break;
			} 
			var pilihan = $('option:selected', '#pilih_barang').attr('data-'+pilih);
			if(pilihan==undefined){
				alert('Pilih Nama Obat');
				$('#barcode').focus();
			}else{
				var harga = pilihan * $('#pilih_qty').val(); 
				if(harga==""){harga=0;}
				$('#pilih_qty').attr('data-'+pilih,harga);
				$('#pilih_total').val(addCommas(harga)); 
			}
		});
		function addCommas(nStr)
		{
			nStr += '';
			x = nStr.split('.');
			x1 = x[0];
			x2 = x.length > 1 ? '.' + x[1] : '';
			var rgx = /(\d+)(\d{3})/;
			while (rgx.test(x1)) {
				x1 = x1.replace(rgx, '$1' + '.' + '$2');
			}
			return x1 + x2;
		}
		

		//document.location.href='<?=base_url()?>webadmin/dashboard/transaksi';
		
		
		$("#submitalls").submit(function (eve) {
			eve.preventDefault(); 
			//if($('#pelangganketik').val()==""){
			//	alert('Isi Nama Pelanggan!');
			//	$('#pelangganketik').focus();
			//}else{				
				var dataform = new FormData();
				var inputtxt = $('#submitalls').serializeArray();
				for (var i = 0; i < inputtxt.length; i++) {
					dataform.append(inputtxt[i]["name"], inputtxt[i]["value"]); 
				}

				$.ajax({
					type: "POST",
					data: dataform,
					dataType: "json",
					contentType: false,
					processData: false,
					url: "<?php echo base_url();?>cms/logic/transaksiProses",
					beforeSend: function () {
						$('.overlay-all').show();
					},
					success: function (e) { 
						if(e.status=="true"){  
							var url = '<?=base_url()?>webadmin/dashboard/cetakstruk?id='+e.id;
							var windowName = "Cetak Struk";
							var windowSize = "width=600,height=600";
							window.open(url, windowName, windowSize);
							//document.location.href='<?=base_url()?>webadmin/dashboard/transaksi';
						}else{ 
							alert('Gagal memproses data..!!');
						}
					},
					error: function () { 
						alert('Gagal memproses data..!!');
					}
				});
			//}
		});
		$("#submitrow").submit(function (eve) {
			eve.preventDefault(); 

			var jenis = $('#jenis_harga').val(); 
			var pilih = 'satuan';
			switch(jenis){
				case "1":pilih='resep';break;
				case "2":pilih='satuan';break;
				case "3":pilih='box';break;
			} 			
			var val = $('option:selected', $('#pilih_barang')).attr('value');
			var st = $("#pilih_barang option[value='"+val+"']").attr('data-stok');
			var nama = $('option:selected', $('#pilih_barang')).attr('data-nama');
			var harga = $('option:selected', $('#pilih_barang')).attr('data-'+pilih);
			var satuan = $('option:selected', $('#pilih_barang')).attr('data-satuan');
			var isi = $('option:selected', $('#pilih_barang')).attr('data-isi');
			var qty = $('#pilih_qty').val(); 
			var jenisharga = $('#jenis_harga option:selected').text(); 
			var total = eval(qty * harga);
			if(eval(qty) > st){
				//document.getElementById("submitrow").reset(); 
				$('#pilih_barang').prop('selectedIndex',0); 
				$('#pilih_total').val('');
				$('#pilih_qty').val('');
				
				$('#barcode').focus();
				alert('Sisa stok : '+st);
			}else{
				if(qty<1){
					alert('Qty tidak boleh kurang dari 1');
					$('#pilih_qty').focus();
				}else{
					$('#listable tr:last').after('<tr> <td>'+nama+'<input type="hidden"  name="item[id_barang][]" value="'+val+'"><input type="hidden"  name="item[jenis_harga][]" value="'+jenis+'"></td><td>'+isi+'</td><td>'+qty+'<input type="hidden"  name="item[qty][]" value="'+qty+'"></td><td>'+jenisharga+'</td>  <td>Rp. '+addCommas(harga)+'<input type="hidden" name="item[harga][]" value="'+harga+'"></td> <td>Rp. '+addCommas(total)+'<input type="hidden" class="sum" name="item[total][]" value="'+total+'"></td> <td align="center"><a class="btn btn-xs btn-danger del-row"  data-val="'+val+'"><i class="fa fa-trash"></i></a></td> </tr>');
					$("#pilih_barang option[value='"+val+"']").attr('style','display:none;');
					
					sum();
					$("#diskon").val('0');
					//document.getElementById("submitrow").reset(); 
					$('#pilih_barang').prop('selectedIndex',0); 
					$('#pilih_total').val('');					
					$('#pilih_qty').val('');					
					
					$('#barcode').val("");
					$('#barcode').focus();
					var minst = st - qty; 
					$("#pilih_barang option[value='"+val+"']").attr('data-stok',minst);			
					$("#pilih_qty").attr('data-max',minst);			
				}
			}
		});		
		$("#submitallsmutasi").submit(function (eve) {
			eve.preventDefault(); 
			var dataform = new FormData();
			var inputtxt = $('#submitallsmutasi').serializeArray();
			for (var i = 0; i < inputtxt.length; i++) {
				dataform.append(inputtxt[i]["name"], inputtxt[i]["value"]); 
			}

			$.ajax({
				type: "POST",
				data: dataform,
				dataType: "json",
				contentType: false,
				processData: false,
				url: "<?php echo base_url();?>cms/logic/mutasiProses",
				beforeSend: function () { 
				},
				success: function (e) { 
					if(e.status=="true"){ 
						alert('Berhasil memproses data..!!');  
						document.location.href='<?=base_url()?>webadmin/dashboard/mutasi-new';
					}else{ 
						alert('Gagal memproses data..!!');
					}
				},
				error: function () { 
					alert('Gagal memproses data..!!');
				}
			});
		});
		$("#submitallsbeli").submit(function (eve) {
			eve.preventDefault(); 
			var dataform = new FormData();
			var inputtxt = $('#submitallsbeli').serializeArray();
			for (var i = 0; i < inputtxt.length; i++) {
				dataform.append(inputtxt[i]["name"], inputtxt[i]["value"]); 
			}

			$.ajax({
				type: "POST",
				data: dataform,
				dataType: "json",
				contentType: false,
				processData: false,
				url: "<?php echo base_url();?>cms/logic/pembelianProses",
				beforeSend: function () { 
				},
				success: function (e) { 
					if(e.status=="true"){ 
						alert('Berhasil memproses data..!!');  
						document.location.href='<?=base_url()?>webadmin/dashboard/pembelian-new';
					}else{ 
						alert('Gagal memproses data..!!');
					}
				},
				error: function () { 
					alert('Gagal memproses data..!!');
				}
			});
		});
		
		$("#submitrowmutasi").submit(function (eve) {
			eve.preventDefault(); 
			var val = $('option:selected', $('#mutasi_barang')).attr('value');
			var nama = $('option:selected', $('#mutasi_barang')).attr('data-nama');
			var satuan = $('option:selected', $('#mutasi_barang')).attr('data-satuan');
			var harga = $('option:selected', $('#mutasi_barang')).attr('data-harga');
			var stok = $('option:selected', $('#mutasi_barang')).attr('data-stok');
			var qty = $('#mutasi_qty').val(); 
			if(eval(qty)>eval(stok)){
				alert('Qty melebihi stok yang ada!');
			}else{
				$('#beli_harga').val(harga); 
				//var harga = $('#mutasi_harga').val(); 
				var total = eval(qty * harga);
				$('#listablemutasi tr:last').after('<tr> <td>'+nama+'<input type="hidden"  name="item[id_barang][]" value="'+val+'"></td> <td>'+qty+'<input type="hidden"  name="item[qty][]" value="'+qty+'"></td> <td>'+satuan+'</td> <td>Rp. '+addCommas(harga)+'<input type="hidden" name="item[harga][]" value="'+harga+'"></td> <td>Rp. '+addCommas(total)+'<input type="hidden" class="sum" name="item[total][]" value="'+total+'"></td> <td align="center"><a class="btn btn-xs btn-danger del-rowmutasi"  data-val="'+val+'"><i class="fa fa-trash"></i></a></td> </tr>');
				$("#mutasi_barang option[value='"+val+"']").attr('style','display:none;');
				
				summutasi(); 
				document.getElementById("submitrowmutasi").reset(); 
			}
		});
		$("#submitrowbeli").submit(function (eve) {
			eve.preventDefault(); 
			var val = $('option:selected', $('#beli_barang')).attr('value');
			var nama = $('option:selected', $('#beli_barang')).attr('data-nama');
			var satuan = $('option:selected', $('#beli_barang')).attr('data-satuan');
			var qty = $('#beli_qty').val(); 
			var harga = $('#beli_harga').val(); 
			var total = eval(qty * harga);
			$('#listablebeli tr:last').after('<tr> <td>'+nama+'<input type="hidden"  name="item[id_barang][]" value="'+val+'"></td> <td>'+qty+'<input type="hidden"  name="item[qty][]" value="'+qty+'"></td> <td>'+satuan+'</td> <td>Rp. '+addCommas(harga)+'<input type="hidden" name="item[harga][]" value="'+harga+'"></td> <td>Rp. '+addCommas(total)+'<input type="hidden" class="sum" name="item[total][]" value="'+total+'"></td> <td align="center"><a class="btn btn-xs btn-danger del-rowbeli"  data-val="'+val+'"><i class="fa fa-trash"></i></a></td> </tr>');
			$("#beli_barang option[value='"+val+"']").attr('style','display:none;');
			
			sumbeli(); 
			document.getElementById("submitrowbeli").reset(); 
		});
			function sum(){
				var sum = 0;
				$('.sum').each(function(){
					sum += parseFloat(this.value);
				});
				$('#totala').html(addCommas(sum));				
				$('#subtotal').val(sum);				
				$('#grand_total').val(sum);				
				$('#bayar').val(sum);				

				$('#divtotal').html("Rp. "+addCommas(sum));				
				$('#divgrand_total').html("Rp. "+addCommas(sum));					
			}
			function summutasi(){
				var sum = 0;
				$('.sum').each(function(){
					sum += parseFloat(this.value);
				}); 				
				$('#subtotal').val(sum);		 			

				$('#divtotal').html("Rp. "+addCommas(sum));			 				
			}
			function sumbeli(){
				var sum = 0;
				$('.sum').each(function(){
					sum += parseFloat(this.value);
				}); 				
				$('#subtotal').val(sum);		 			

				$('#divtotal').html("Rp. "+addCommas(sum));			 				
			}
			$("#diskon").on('keyup keypress', function(e) {
				var ini =$(this).val();
				if($(this).val() >100){
					$(this).val('0');
				}else{
					if($(this).val()==""){
						//$(this).val('0');
						ini = 0;
					}
					var kurang = (eval($('#subtotal').val()) * eval(ini)) / 100;
					var jadi = eval($('#subtotal').val()) - kurang;
					//if(isNaN(kurang)) {}else{
						//$('#divpotongan').html("Rp. "+addCommas(jadi));
						//$('#potongan').val(jadi);
						$('#divpotongan').html("Rp. "+addCommas(kurang));
						$('#potongan').val(kurang);
						$('#divgrand_total').html("Rp. "+addCommas(jadi));
						$('#grand_total').val(jadi);
						$('#bayar').val(jadi);
						$('#totala').html(addCommas(jadi));
						
					$('#sisa').val('0');
						
					//}
				
				}
			});				
			$("#bayar").on('keyup keypress', function(e) {
				var ini =$(this).val();
				//if($(this).val() > eval($('#grand_total').val())){
					//$(this).val($('#grand_total').val());
				//}else{
					if($(this).val()==""){
						//$(this).val('0');
						ini = 0;
					}
					var kurang = eval($('#grand_total').val()) - eval(ini);
					$('#sisa').val(kurang);
				
				//}
			});				

			$(".numbersmutasi").keyup(function (e) {
				var harga = $('#mutasi_harga').val();
				var kali = eval(harga)  * eval($('#mutasi_qty').val());
				if(isNaN(kali)) {
					$('#mutasi_total').val("0"); 
				}else{ 
					$('#mutasi_total').val(addCommas(kali));
				}
			});		
			$(".numbersbeli").keyup(function (e) {
				var harga = $('#beli_harga').val();
				var kali = eval(harga)  * eval($('#beli_qty').val());
				if(isNaN(kali)) {
					$('#beli_total').val("0"); 
				}else{ 
					$('#beli_total').val(addCommas(kali));
				}
			});		
			$(".numbers").keyup(function (e) {
				var jenis = $('#jenis_harga').val(); 
				var pilih = 'satuan';
				switch(jenis){
					case "1":pilih='resep';break;
					case "2":pilih='satuan';break;
					case "3":pilih='box';break;
				} 				
				var harga = $('option:selected', $('#pilih_barang')).attr('data-'+pilih);
				var stok = $('#pilih_qty').attr('data-max');
				if(eval($('#pilih_qty').val()) > eval(stok)){
					alert('Stok tidak cukup,  maksimal '+stok);
					$('#pilih_qty').val('');
				}else{
					var kali = eval(harga)  * eval($('#pilih_qty').val());
					if(isNaN(kali)) {
						$('#pilih_total').val("0"); 
					}else{ 
						$('#pilih_total').val(addCommas(kali));
					}
				}
			});		
			<?php  if($page=="transaksi"){ ?>
			function startTime() {
				var today = new Date();
				var h = today.getHours();
				var m = today.getMinutes();
				var s = today.getSeconds();
				m = checkTime(m);
				s = checkTime(s);
				document.getElementById('txt').innerHTML =
				h + ":" + m + ":" + s;
				var t = setTimeout(startTime, 500);
			}
				<?php }?>
			function checkTime(i) {
				if (i < 10) {i = "0" + i};  // add zero in front of numbers < 10
				return i;
			}		
			function change_status(htmlst,statusnya,idnya,pagenya){
				$.ajax({
					type: "GET",
					url: pagenya,
					beforeSend: function () { },
					success: function (e) {
						e = jQuery.parseJSON(e);
						if(e.status_ajx=="false"){
							alert('Gagal merubah data');
						}else{
							$('#'+htmlst).html(e.hasil);
						}
					}
				});
			}			
			function pilih_jawaban(htmlst,statusnya,idnya,pagenya){
				$.ajax({
					type: "GET",
					url: pagenya,
					beforeSend: function () { },
					success: function (e) {
						e = jQuery.parseJSON(e);
						if(e.status_ajx=="false"){
							alert('Gagal merubah data');
						}else{
							$('#'+htmlst).html(e.hasil);
						}
					}
				});
			}		 
function getpersen(){
	var beli = $('#harga_beli').val();
	var satuan = $('#harga_satuan').val();
	var box = $('#harga_box').val();
	if(beli!=''){
		if(satuan!=''){
			var persen = ((satuan / beli) * 100) - 100;
			$('#persen').html(persen);
		}
		if(box!=''){
			var persenbox = ((box / beli) * 100) - 100;
			$('#persenbox').html(persenbox);
		}
	}
}	 
            $(document).ready(function () { 
			
			$('#harga_beli').on('keyup', function() {
				getpersen();
			});
			$('#harga_satuan').on('keyup',function(){
				getpersen();
			});
			$('#harga_box').on('keyup',function(){
				getpersen();
			});
			$('.overlay-all').hide();
			<?php
			if($uri=="barang"){ 
			$now = @$this->uri->segment(3);
			?>
				$("#btnprint").on('click',function(){
					var s = $('input[type=search]').val();
					var url = $(this).attr('data-url');
					window.open(url+s,'_blank');
					
				});
				$("#btnexcel").on('click',function(){
					var s = $('input[type=search]').val();
					var url = $(this).attr('data-url');
					window.open(url+s,'_blank');
					
				});
				var tabel = null; 
				tabel = $('.dataTablesbarang').DataTable({
					"processing": true,
					"serverSide": true,
					"ordering": true, 
					"order": [[ 1, 'asc' ]], 
					"ajax":
					{
						"url": "<?=base_url();?>webadmin/dashboard/barangajax", 
						"type": "POST"
					},
					"deferRender": true,
					"aLengthMenu": [[15, 50,100],[ 15, 50,100]], 
					"columns": [
						{ "data": "kode" }, 
						{ "data": "nama" },  
						{ "data": "kategori" }, 
						{ "data": "isi" }, 
						{ "data": "satuan" }, 
						{ "data": "harga_beli" }, 
						{ "data": "harga_resep" }, 
						{ "data": "harga_satuan" }, 
						{ "data": "harga_box" }, 
						{ "data": "stok" },  
						{ "data": null, 
						"render": function ( data, type, row ) { 
								var st = "";
								if(row.status=="1"){st="Aktif";}else{st="Tidak Aktif";}
								var html  = "<a href='javascript:void(0);' class='label label-success' id='st-"+row.id_barang+"' onclick=\"change_status('st-"+row.id_barang+"','"+row.status+"','"+row.id_barang+"','<?=base_url()?>cms/logic/delete_ajax/barang/"+row.id_barang+"')\">";
								html += st+"</a>";
								return html
							}
						},
						{ "data": null, 
						"render": function ( data, type, row ) { 
								var html  = "<a title='Edit' href='<?=$url?>barang-new?_id="+row.id_barang+"' class='btn btn-xs btn-success '><i class='fa fa-edit '></i></a> ";
								html += "<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/delete/barang/"+row.id_barang+"?part=<?=$now;?>' class='text-danger'><i class='fa fa-trash-o'></i></a>";
								return html
							}
						},
					],
				});		
			<?php
			}
			?>				
				
				$('#barcodemutasi').on({
					keypress : function(){
						typed_into = true;
					},
					change : function(){
						if(typed_into){
							//alert($('#barcode').val());
							var kode = $('#barcodemutasi').val();
							//$('#mutasi_barang').attr('data-kode',kode).selected();
							var dataform = new FormData();
							dataform.append('kode', kode); 
							$.ajax({
								type: "POST",
								data: dataform,
								dataType: "json",
								contentType: false,
								processData: false,
								url: "<?php echo base_url();?>webadmin/dashboard/cariobat",
								beforeSend: function () { 
								},
								success: function (e) { 
									if(e.status=="true"){ 
										$('#mutasi_barang').val(e.id);
										$('#mutasi_barang').change();
										$('#barcodemutasi').val("");
									}else{ 
										alert(e.message);
									}
								},
								error: function () { 
									alert('Gagal scan data..!!');
								}
							});							
						}else{
							
						}
					}
				});
				$('#barcodebeli').on({
					keypress : function(){
						typed_into = true;
					},
					change : function(){
						if(typed_into){
							//alert($('#barcode').val());
							var kode = $('#barcodebeli').val();
							//$('#beli_barang').attr('data-kode',kode).selected();
							var dataform = new FormData();
							dataform.append('kode', kode); 
							$.ajax({
								type: "POST",
								data: dataform,
								dataType: "json",
								contentType: false,
								processData: false,
								url: "<?php echo base_url();?>webadmin/dashboard/cariobat",
								beforeSend: function () { 
								},
								success: function (e) { 
									if(e.status=="true"){ 
										$('#beli_barang').val(e.id);
										$('#beli_barang').change();
										$('#barcodebeli').val("");
									}else{ 
										alert(e.message);
									}
								},
								error: function () { 
									alert('Gagal scan data..!!');
								}
							});							
						}else{
							
						}
					}
				});
				$('#barcode').on({
					keypress : function(){
						typed_into = true;
					},
					change : function(){
						if(typed_into){
							//alert($('#barcode').val());
							var kode = $('#barcode').val();
							//$('#pilih_barang').attr('data-kode',kode).selected();
							var dataform = new FormData();
							dataform.append('kode', kode); 
							$.ajax({
								type: "POST",
								data: dataform,
								dataType: "json",
								contentType: false,
								processData: false,
								url: "<?php echo base_url();?>webadmin/dashboard/cariobat",
								beforeSend: function () { 
								},
								success: function (e) { 
									if(e.status=="true"){ 
										$('#pilih_barang').val(e.id);
										$('#pilih_barang').change();
										$('#barcode').val("");
									}else{ 
										alert(e.message);
									}
								},
								error: function () { 
									alert('Gagal scan data..!!');
								}
							});							
						}else{
							
						}
					}
				});
				/*$('#barcode').keyup(function(){
					alert('code');
				});*/
				
				$(".tgl").daterangepicker({
					locale: {
						format: 'YYYY-MM-DD'
					},
				});	 
				$('.cetak-ulang').click(function(){
						var url = '<?=base_url()?>webadmin/dashboard/cetakstruk?id='+$(this).attr('data-id');
						var windowName = "Cetak Struk";
						var windowSize = "width=600,height=600";
						window.open(url, windowName, windowSize); 

				});
				$('.cetak-ulangmutasi').click(function(){
						var url = '<?=base_url()?>webadmin/dashboard/cetakstrukmutasi?id='+$(this).attr('data-id');
						var windowName = "Cetak Struk";
						var windowSize = "width=600,height=600";
						window.open(url, windowName, windowSize); 

				});
				$('.modal-view').click(function(){
					var tar = $(this).attr('data-target');
					$(tar).modal();
				});
				
				
				$('.flag-photo').click(function(){
					$('.media-photo').show();
					$('.media-video').hide();
				});
				$('.flag-video').click(function(){
					$('.media-video').show();
					$('.media-photo').hide();
				});
				//$('#tag').tagsinput('add', 'vino');
				//$('#tag').tagsinput('add', 'vino sf');
				$('.dataTables').dataTable({"pageLength" : 15});
 
                $(".datepicker").datepicker({
                    dateFormat: "yy-mm-dd",
				});
                $(".datepickertime").datetimepicker({format: 'yyyy-mm-dd hh:ii:ss'});
				$('.fancybox').fancybox({
					width: "80%",
				});			
                $('.pilih_icon a').click(function(){
					var icon = $(this).attr('data-icon');
					var target = $(this).attr('data-target');
					$('#'+target).val(icon);
					if($(this).attr('class')=='active'){}else{
						$('.pilih_icon a').attr('class','');
						$(this).attr('class','pilih');
					}
				});
				$('form #judul').keyup(function() {
					slug = $(this).val().toLowerCase().replace(/ +/g, '-').replace('--', '-').replace(/[^a-z0-9\-\.]+/g,'').substring(0, $(this).val().length > 100?100:$(this).val().length);
					$('form #slug').val(slug);
				}); 		
				$('#pelangganketik').keyup(function() {
					slug = $(this).val().toLowerCase().replace(/ +/g, '-').replace('--', '-').replace(/[^a-z0-9\-\.]+/g,'').substring(0, $(this).val().length > 100?100:$(this).val().length);
					$('#pelanggan').val($(this).val());
				}); 		
				//$('textarea.tinymce-editoradv').tinymce({
				//	mode: "exact",
					/*plugins: [
						"advlist autolink lists link image charmap print preview hr anchor pagebreak",
						"searchreplace wordcount visualblocks visualchars code fullscreen",
						"insertdatetime media nonbreaking save table contextmenu directionality",
						"emoticons template paste textcolor filemanager"
					],*/
					//toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
					//toolbar2: "print preview media | forecolor backcolor emoticons",
					//image_advtab: true,
					//relative_urls: false
				//}); 
				$(".angka").keydown(function (e) {
					if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||
						(e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) || 
						(e.keyCode >= 35 && e.keyCode <= 40)) {
							return;
					}
					if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
						e.preventDefault();
					}
				});				
				$(".number").keydown(function (e) {
					if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||
						(e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) || 
						(e.keyCode >= 35 && e.keyCode <= 40)) {
							return;
					}
					if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
						e.preventDefault();
					}
				});				
				$(".numberdddd").keyup(function (e) {
					var kali = eval($('#harga').val())  * eval($('#qty').val());
					if(isNaN(kali)) {
						$('#subtotal').val("0");
						$('#totala').html("0");
					}else{
						$('#subtotal').val(kali);
						$('#totala').html(addCommas(kali));
					}
				});
				$(".number2").keydown(function (e) {
					if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110]) !== -1 ||
						(e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) || 
						(e.keyCode >= 35 && e.keyCode <= 40)) {
							return;
					}
					if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
						e.preventDefault();
					}
				});				
				$(".number2").keyup(function (e) {
					var kali = eval($('#harga_beli').val())  * eval($('#qty').val());
					if(isNaN(kali)) {
						$('#total_beli').val("0");
						$('#totala_beli').html("0");
					}else{
						$('#total_beli').val(kali);
						$('#totala_beli').html(addCommas(kali));
					}
				});
				function addCommas(nStr)
				{
					nStr += '';
					x = nStr.split('.');
					x1 = x[0];
					x2 = x.length > 1 ? '.' + x[1] : '';
					var rgx = /(\d+)(\d{3})/;
					while (rgx.test(x1)) {
						x1 = x1.replace(rgx, '$1' + ',' + '$2');
					}
					return x1 + x2;
				}				
            });		
    </script>	
    <script src="<?=base_url()?>assets/webadmin/js/custom-scripts.js"></script>
</body>
</html>