@extends('base.layout')

@section('content')
<div class="wrapper">
	<div class="container-fluid">
		<div class="row">
			<div class="col-lg-6">
				<div class="card-box ribbon-box">
					<div class="ribbon ribbon-primary">Pick Report Range</div>
					<p class="m-b-0"></p>
					<div class="form-row">
						<div class="form-group col-md-3">
							<select class="form-control" id="bulan" name="bulan">
								<option value="ALL">Setahun</option>
								<option value="01">Januari</option>
								<option value="02">Februari</option>
								<option value="03">Maret</option>
								<option value="04">April</option>
								<option value="05">Mei</option>
								<option value="06">Juni</option>
								<option value="07">Juli</option>
								<option value="08">Agustus</option>
								<option value="09">September</option>
								<option value="10">Oktober</option>
								<option value="11">November</option>
								<option value="12">Desember</option>
							</select>
						</div>
						<div class="form-group col-md-3">
							<input type="text" name="tahun" id="tahun" class="form-control" value="{{ date('Y')}}">
						</div>
						<div class="form-group col-md-3">
							<button type="button" class="btn btn-primary" id="btnReport">Detail</button>
						</div>
						<div class="form-group col-md-3">
						</div>
						<div class="form-group col-md-3">
							<button type="button" class="btn btn-warning btn-block" id="btnrekap">Rekap Antibiotik</button>
						</div>
						<div class="form-group col-md-3">
							<button type="button" class="btn btn-info btn-block" id="btnrekapglassreport">Rekap Glass Report</button>
						</div>
						<div class="form-group col-md-3">
							<button type="button" class="btn btn-primary btn-block" id="btnrekapzn">Rekap Ziehl Nielsen</button>
						</div>
						<div class="form-group col-md-3">
							<button type="button" class="btn btn-danger btn-block" id="btnrekapbiorepo">Biorepository Bakteri</button>
						</div>
					</div>
				</div>
			</div>
			<div class="col-lg-6">
				<div class="card-box ribbon-box">
					<div class="ribbon ribbon-info">Pick Date Report</div>
					<p class="m-b-0"></p>
					<div class="form-row">
						<div class="form-group col-md-3">
							<input type="text" name="tanggal" id="tanggal" class="form-control">
						</div>
						<div class="form-group col-md-3">
							<button type="button" class="btn btn-info" id="btndatereport">Show</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="divlaporan">
			<div class="row">
				<div class="col-lg-12">
					<div class="card-box table-responsive">
						<h4 class="m-t-0 header-title">Result</h4>
						<button type="button" id="downexcell" class="btn btn-custom waves-light waves-effect">Export to Excell</button>
						<div id="result"></div>
					</div>
				</div>
			</div>
		</div>
		<div id="divlaporanharian">
			<div class="row">
				<div class="col-lg-12">
					<div class="card-box table-responsive">
						<h4 class="m-t-0 header-title">Result</h4>
						<button type="button" id="downexcellharian" class="btn btn-custom waves-light waves-effect">Export to Excell</button>
						<div id="resultharian"></div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div id="modaleditorbiorepository" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-xl">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
					<h4 class="modal-title" id="myModalLabel">Bio Repository</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal">
						<div class="form-group m-b-25">
							<div class="col-12">
								<label>Category Penyimpanan</label>
								<select class="form-control" id="kategorisimpan" name="kategorisimpan">
									<option value="A">Penyimpanan Suhu Ruang</option>
									<option value="B">Penyimpanan Suhu 4 Derajat</option>
									<option value="C">Penyimpanan Suhu 20 Derajat</option>
									<option value="D">Penyimpanan Suhu 80 Derajat</option>
								</select>
							</div>
						</div>
						<div class="form-group row">
							<div class="col-lg-4">
								<label>Shelf Nomor</label>
								<input type="number" class="form-control" id="shelfnomor">
							</div>
							<div class="col-lg-4">
								<label>Rack Number</label>
								<input type="number" class="form-control" id="raknomor">
							</div>
							<div class="col-lg-4">
								<label>Slot Number</label>
								<input type="number" class="form-control" id="slotnomor">
							</div>
							<div class="col-lg-4">
								<label>Box Number</label>
								<input type="number" class="form-control" id="boxnomor">
							</div>
							<div class="col-lg-4">
								<label>Tube Number</label>
								<input type="number" class="form-control" id="tubenomor">
							</div>
						</div>
						<div class="form-group m-b-25">
							<div class="col-12">
								<label>Bactery Name</label>
								<input type="text" class="form-control" id="nmbakteri">
							</div>
						</div>
						<div class="form-group m-b-25">
							<div class="col-12">
								<label>Strain</label>
								<select class="form-control" id="strain" name="strain">
									<option value="Gram Negatif">Gram Negatif</option>
									<option value="Gram Positif">Gram Positif</option>
								</select>
							</div>
						</div>
						<div class="form-group m-b-25">
							<div class="col-12">
								<label>ATCC</label>
								<input type="text" class="form-control" id="atcc">
							</div>
						</div>
						<div class="form-group m-b-25">
							<div class="col-12">
								<label>Tgl Penyimpanan</label>
								<input type="text" class="form-control" id="tglpenyimpanan">
							</div>
						</div>
						<div class="form-group m-b-25">
							<div class="col-12">
								<label>Nama Pelaksana / Pemilik</label>
								<input type="text" class="form-control" id="createdby">
							</div>
						</div>
						<div class="form-group account-btn text-center m-t-10">
							<div class="col-12">
								<input type="hidden" class="form-control" id="idbakteri">
								<button class="btn w-lg btn-custom waves-effect waves-light" id="btnsimpandata" type="button">Save</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
<div id="tempatctk" style="overflow: hidden; display: none;">
	<div id="tabel_cetak"></div>        
</div>
<input type="hidden" name="_token" id="token" value="{{ csrf_token() }}">
@endsection

@push('script')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>

<script type="text/javascript">
$(document).ready(function () {
    $('#divlaporan').hide();
	$('#divlaporanharian').hide();
	$("#tanggal").datepicker({format: 'yyyy-mm-dd'});
	$("#tglpenyimpanan").datepicker({format: 'yyyy-mm-dd'});
	$('#btnReport').click(function () {
        var bulan	= document.getElementById('bulan').value;
        var tahun	= document.getElementById('tahun').value;
        var token	= document.getElementById('token').value;
        var source 	= {
			datatype: "json",
			datafields: [
				{ name: 'id',type: 'text'},
				{ name: 'nofoto',type: 'text'},
				{ name: 'noregister',type: 'text'},
				{ name: 'nmpasien',type: 'text'},
				{ name: 'usia',type: 'text'},
				{ name: 'l',type: 'text'},
				{ name: 'p', type: 'text'},
				{ name: 'jenis',type: 'text'},
				{ name: 'ruangan',type: 'text'},
				{ name: 'kesimpulan', type: 'text'},
				{ name: 'poli', type: 'text'},
				{ name: 'jkn', type: 'text'},
				{ name: 'umm', type: 'text'},
				{ name: 'swasta', type: 'text'},
				{ name: 'gcu', type: 'text'},
				{ name: 'tag', type: 'text'},
				{ name: 'swasta', type: 'text'},
				{ name: 'billing', type: 'text'},
				{ name: 'ele', type: 'text'},
				{ name: 'cito', type: 'text'},
				{ name: 'daftar', type: 'text'},
				{ name: 'foto',type: 'text'},
				{ name: 'baca',type: 'text'},
				{ name: 'export',type: 'text'},
				{ name: 'created_at',type: 'text'},
				{ name: 'nmdokter',type: 'text'},
				{ name: 'nmppdssenior',type: 'text'},
				{ name: 'nmmiddleppds',type: 'text'},
				{ name: 'nmppdsjunior',type: 'text'},
				{ name: 'nmppdsmiddle2',type: 'text'},
				{ name: 'nmppdsjunior2',type: 'text'},
				{ name: 'diagnosa2',type: 'text'},
				{ name: 'modality',type: 'text'},
				{ name: 'dlp',type: 'text'},
				{ name: 'nm_spesimen',type: 'text'},
				{ name: 'kd_spesimen',type: 'text'},
				{ name: 'asalpasien',type: 'text'},
				{ name: 'status',type: 'text'},
				{ name: 'nmrs',type: 'text'},
				{ name: 'berat',type: 'text'},
				{ name: 'klinisi',type: 'text'},
				{ name: 'klinis',type: 'text'},
				{ name: 'tlppasien',type: 'text'},
				{ name: 'nmanalis',type: 'text'},
				{ name: 'verifikasi',type: 'text'},
				{ name: 'noloket',type: 'text'},
				{ name: 'jumlah',type: 'text'},
				{ name: 'nmdrafter',type: 'text'},
				{ name: 'tgldraft',type: 'text'},
				{ name: 'nmpembaca',type: 'text'},
				{ name: 'tgladendum',type: 'text'},
				{ name: 'nmadendum',type: 'text'},
				{ name: 'filefoto',type: 'text'},
				{ name: 'durasi', type: 'text'},
			],
			updaterow	: function (rowid, rowdata, commit) {commit(true);},
			type		: 'POST',
			data		: {bulan: bulan, tahun: tahun,  jenisreport: '', _token: token },
			url			: '{{ route("reportPeriksa") }}',
		};
        var dataAdapter = new $.jqx.dataAdapter(source);
        $('#divlaporan').show();
		$('#divlaporanharian').hide();
        $("#result").jqxGrid({
            width					: '100%',
			enablebrowserselection	: true,
            filterable				: true,
            autoheight				: true,
            showfilterrow			: true,
			altrows 				: true,
            source					: dataAdapter,
            pageable				: true,
            theme					: "energyblue",
            columnsresize			: true,
            selectionmode			: 'multiplecellsextended',
            columns					: [
				{ text: 'File Report', editable: false, sortable: false, filterable: false, datafield: 'filefoto', width: 80, cellsalign: 'left', align: 'center'  },
				{ text: 'No.Loket', datafield: 'noloket', width: 80, cellsalign: 'left', align: 'center'  },
                { text: 'No.RM', datafield: 'noregister', width: 70, align: 'center', cellsalign: 'left'},
                { text: 'Nama', datafield: 'nmpasien', width: 160, cellsalign: 'left', align: 'center' },
				{ text: 'No.HP', datafield: 'tlppasien', width: 100, cellsalign: 'left', align: 'center' },
                { text: 'Umur', datafield: 'usia', width: 70, cellsalign: 'left', align: 'center'  },
                { text: 'M', editable: false, sortable: false, filterable: false, datafield: 'l', width: 20, cellsalign: 'left', align: 'center'  },            
                { text: 'F', editable: false, sortable: false, filterable: false, datafield: 'p', width: 20, cellsalign: 'left', align: 'center'  },
                { text: 'Order', editable: false, sortable: false, filterable: false, datafield: 'jenis', width: 80, cellsalign: 'left', align: 'center'  },
                { text: 'JKN', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'jkn', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'UMM', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'umm', width: 40, cellsalign: 'left', align: 'center'  },
				{ text: 'TAG', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'tag', width: 40, cellsalign: 'left', align: 'center'  },
				{ text: 'GCU', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'gcu', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'Billing', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'billing', width: 40, cellsalign: 'left', align: 'center'  },
				{ text: 'SWASTA', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'swasta', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'Elective', editable: false, sortable: false, filterable: false, columngroup: 'urgensi', datafield: 'ele', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'CITO', editable: false, sortable: false, filterable: false, columngroup: 'urgensi', datafield: 'cito', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'Sample Masuk', columngroup: 'waktu', datafield: 'daftar', width: 160, cellsalign: 'left', align: 'center'  },
                { text: 'Draft By', columngroup: 'waktu', datafield: 'nmdrafter', width: 150, cellsalign: 'left', align: 'center'  },
                { text: 'Tgl. Draft', columngroup: 'waktu', datafield: 'tgldraft', width: 80, cellsalign: 'left', align: 'center'  },
                { text: 'Expertise By', columngroup: 'waktu', datafield: 'nmpembaca', width: 150, cellsalign: 'left', align: 'center'  },
                { text: 'Supervisor', columngroup: 'waktu', datafield: 'nmdokter', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Verifikasi', columngroup: 'waktu', datafield: 'verifikasi', width: 80, cellsalign: 'left', align: 'center'  },
				{ text: 'Cetak', columngroup: 'waktu', datafield: 'export', width: 80, cellsalign: 'left', align: 'center'  },
				{ text: 'Asal Pasien', datafield: 'asalpasien', width: 100, cellsalign: 'left', align: 'center'},
				{ text: 'Asal RS', datafield: 'nmrs', width: 100, cellsalign: 'left', align: 'center'},
				{ text: 'Klinisi', datafield: 'klinisi', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'Klinis', datafield: 'klinis', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'Analis', datafield: 'nmanalis', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'PPDS', datafield: 'nmppdssenior', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'Device', datafield: 'modality', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'Code', datafield: 'kd_spesimen', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'Speciment', datafield: 'nm_spesimen', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'Template', datafield: 'dlp', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'Jenis', datafield: 'diagnosa2', width: 150, cellsalign: 'left', align: 'center'},
				{ text: 'Duration', editable: false, sortable: false, filterable: false, datafield: 'durasi', width: 100, cellsalign: 'left', align: 'center'},
            ],
			columngroups:
			[
				{ text: 'Riwayat Tindakan', align: 'center', name: 'waktu' },
				{ text: 'Urgensi', align: 'center', name: 'urgensi' },
				{ text: 'Insurance', align: 'center', name: 'asuransi' }
			]
        });
    });
	$('#btnrekapbiorepo').click(function () {
        var bulan	= document.getElementById('bulan').value;
        var tahun	= document.getElementById('tahun').value;
		if (bulan == '' || tahun == ''){
			swal({
				title	: 'Mohon diLengkapi',
				text	: 'Data Dasar Bulan dan Tahun Wajib di Isi',
				type	: 'error',
			});
		} else {
			var token	= document.getElementById('token').value;
			var source 	= {
				datatype: "json",
				datafields: [
					{ name: 'id',type: 'text'},
					{ name: 'urlhasil',type: 'text'},
					{ name: 'nofoto',type: 'text'},
					{ name: 'noregister',type: 'text'},
					{ name: 'nmpasien',type: 'text'},
					{ name: 'usia',type: 'text'},
					{ name: 'dlp',type: 'text'},
					{ name: 'nm_spesimen',type: 'text'},
					{ name: 'kd_spesimen',type: 'text'},
					{ name: 'reques', type: 'text'},
					{ name: 'nobiorepository', type: 'text'},
					{ name: 'isidata', type: 'text'},
					{ name: 'strain', type: 'text'},
					{ name: 'atcc', type: 'text'},
					{ name: 'sample', type: 'text'},
					{ name: 'tglpenyimpanan', type: 'text'},
					{ name: 'created_by', type: 'text'},
				],
				updaterow	: function (rowid, rowdata, commit) {commit(true);},
				type		: 'POST',
				data		: {bulan: bulan, tahun: tahun, jenisreport: 'biorepository', _token: token },
				url			: '{{ route("reportPeriksa") }}',
			};
			var dataAdapter = new $.jqx.dataAdapter(source);
			$('#divlaporan').show();
			$('#divlaporanharian').hide();
			$("#result").jqxGrid({
				width					: '100%',
				enablebrowserselection	: true,
				filterable				: true,
				autoheight				: true,
				showfilterrow			: true,
				altrows 				: true,
				source					: dataAdapter,
				pageable				: true,
				theme					: "energyblue",
				columnsresize			: true,
				selectionmode			: 'multiplecellsextended',
				columns					: [
					{ text: 'Edit', filterable: false, columntype: 'button', align: 'center', width: 50, cellsrenderer: function () {
						return "Edit";
						}, buttonclick: function (row) {
							editrowjabatan 	= row;
							var offset      = $("#result").offset();
							var dataRecord  = $("#result").jqxGrid('getrowdata', editrowjabatan);
							$("#idbakteri").val(dataRecord.id);
							$("#createdby").val(dataRecord.created_by);
							$("#tglpenyimpanan").val(dataRecord.tglpenyimpanan);
							$("#atcc").val(dataRecord.atcc);
							$("#strain").val(dataRecord.strain);
							$("#nmbakteri").val(dataRecord.isidata);
							$("#tubenomor").val('');
							$("#boxnomor").val('');
							$("#slotnomor").val('');
							$("#raknomor").val('');
							$("#shelfnomor").val('');
							$("#kategorisimpan").val('');
							$('#modaleditorbiorepository').modal('show');
						}
					},
					{ text: 'Stiker', filterable: false, columntype: 'button', align: 'center', width: 50, cellsrenderer: function () {
						return "Print";
						}, buttonclick: function (row) {
							editrowjabatan 	= row;
							var offset      = $("#result").offset();
							var dataRecord  = $("#result").jqxGrid('getrowdata', editrowjabatan);
							if (typeof window.jspdf === 'undefined' || typeof JsBarcode === 'undefined') {
								swal({
									title	: 'Plugin Error',
									text	: 'Kesalahan: Library jsPDF atau JsBarcode belum dimuat',
									type	: 'error',
								})
								return;
							}
							const { jsPDF } = window.jspdf;
							const doc = new jsPDF({
								orientation: 'landscape',
								unit: 'mm',
								format: [50, 35]
							});
							const leftMargin = 2;
							const contentWidth = 50 - (leftMargin * 2);
							let yPosition = 4;

							doc.setFont('helvetica', 'bold');
							doc.setFontSize(7);
							doc.text(`${dataRecord.nofoto} / ${dataRecord.noregister}`, leftMargin, yPosition, {
								maxWidth: contentWidth,
							});
							yPosition += 4;
							try {
								const canvas = document.createElement('canvas');
								JsBarcode(canvas, dataRecord.nobiorepository, {
									format: "CODE128",
									displayValue: false,
									height: 40,
									width: 1.5,
									margin: 5
								});
								const barcodeDataUrl = canvas.toDataURL('image/png');
								const barcodeHeight = 10;
								doc.addImage(barcodeDataUrl, 'PNG', leftMargin, yPosition, contentWidth, barcodeHeight);
								yPosition += barcodeHeight + 3; 
								doc.setFont('helvetica', 'bold');
								doc.setFontSize(9);
								const centerX = 50 / 2;
								doc.text(dataRecord.nobiorepository, centerX, yPosition, { align: 'center' });
								yPosition += 4;

							} catch (e) {
								console.error("Gagal membuat barcode:", e);
								doc.text("Error Barcode", leftMargin, yPosition);
								yPosition += 12;
							}
							doc.setFont('helvetica', 'bold');
							doc.setFontSize(6.5);
							doc.text(`${dataRecord.isidata} / ${dataRecord.strain} / ${dataRecord.created_by} `, leftMargin, yPosition, {
								maxWidth: contentWidth,
							});
							yPosition += 6;
							doc.text(`${dataRecord.atcc} ( ${dataRecord.tglpenyimpanan} )`, leftMargin, yPosition, {
								maxWidth: contentWidth,
							});
							doc.output('dataurlnewwindow');
						}
					},
					{ text: 'Nomor BioRepository', datafield: 'nobiorepository', width: 150, cellsalign: 'left', align: 'center'},
					{ text: 'Nama Bakteri', datafield: 'isidata', width: 150, cellsalign: 'left', align: 'center'},
					{ text: 'STRAIN', datafield: 'strain', width: 150, cellsalign: 'left', align: 'center'},
					{ text: 'ATCC', datafield: 'atcc', width: 150, cellsalign: 'left', align: 'center'},
					{ text: 'Tanggal Penyimpanan', datafield: 'tglpenyimpanan', width: 80, cellsalign: 'left', align: 'center'},
					{ text: 'Nama Pelaksana/ Pemilik', datafield: 'created_by', width: 180, cellsalign: 'left', align: 'center'  },
					{ text: 'No.Loket', datafield: 'nofoto', width: 80, cellsalign: 'left', align: 'center'  },
					{ text: 'No.RM', datafield: 'noregister', width: 70, align: 'center', cellsalign: 'left'},
					{ text: 'Nama', datafield: 'nmpasien', width: 160, cellsalign: 'left', align: 'center' },
					{ text: 'Umur', datafield: 'usia', width: 70, cellsalign: 'left', align: 'center'  },
					{ text: 'Speciment', datafield: 'nm_spesimen', width: 150, cellsalign: 'left', align: 'center'},
					{ text: 'Template', datafield: 'dlp', width: 150, cellsalign: 'left', align: 'center'},
					{ text: 'Order', datafield: 'reques', width: 150, cellsalign: 'left', align: 'center'},
					{ text: 'File Report', editable: false, sortable: false, filterable: false, datafield: 'urlhasil', width: 80, cellsalign: 'left', align: 'center'  },
				],
			});
		}
    });
	$('#btnrekap').click(function () {
        var bulan	= document.getElementById('bulan').value;
        var tahun	= document.getElementById('tahun').value;
		var url = '{{url('/')}}/rekapantibiotik?bulan='+bulan+'?tahun='+tahun;
		window.location.href = url;
    });
	$('#btnrekapglassreport').click(function () {
        var bulan	= document.getElementById('bulan').value;
        var tahun	= document.getElementById('tahun').value;
		var url = '{{url('/')}}/glassreport?bulan='+bulan+'?tahun='+tahun;
		window.location.href = url;
    });
	$('#btnrekapzn').click(function () {
        var bulan	= document.getElementById('bulan').value;
        var tahun	= document.getElementById('tahun').value;
		var url = '{{url('/')}}/znreport?bulan='+bulan+'?tahun='+tahun;
		window.location.href = url;
    });
    $('#btndatereport').click(function () {
        var bulan	= 'pertanggal';
        var tahun	= document.getElementById('tanggal').value;
        var token	= document.getElementById('token').value;
        var source 	= {
			datatype: "json",
			datafields: [
				{ name: 'id',type: 'text'},
				{ name: 'nofoto',type: 'text'},
				{ name: 'noregister',type: 'text'},
				{ name: 'nmpasien',type: 'text'},
				{ name: 'usia',type: 'text'},
				{ name: 'l',type: 'text'},
				{ name: 'p', type: 'text'},
				{ name: 'jenis',type: 'text'},
				{ name: 'ruangan',type: 'text'},
				{ name: 'kesimpulan', type: 'text'},
				{ name: 'poli', type: 'text'},
				{ name: 'jkn', type: 'text'},
				{ name: 'umm', type: 'text'},
				{ name: 'swasta', type: 'text'},
				{ name: 'gcu', type: 'text'},
				{ name: 'tag', type: 'text'},
				{ name: 'swasta', type: 'text'},
				{ name: 'billing', type: 'text'},
				{ name: 'ele', type: 'text'},
				{ name: 'cito', type: 'text'},
				{ name: 'daftar', type: 'text'},
				{ name: 'foto',type: 'text'},
				{ name: 'baca',type: 'text'},
				{ name: 'export',type: 'text'},
				{ name: 'created_at',type: 'text'},
				{ name: 'nmdokter',type: 'text'},
				{ name: 'nmppdssenior',type: 'text'},
				{ name: 'nmmiddleppds',type: 'text'},
				{ name: 'nmppdsjunior',type: 'text'},
				{ name: 'nmppdsmiddle2',type: 'text'},
				{ name: 'nmppdsjunior2',type: 'text'},
				{ name: 'diagnosa2',type: 'text'},
				{ name: 'modality',type: 'text'},
				{ name: 'dlp',type: 'text'},
				{ name: 'nm_spesimen',type: 'text'},
				{ name: 'kd_spesimen',type: 'text'},
				{ name: 'asalpasien',type: 'text'},
				{ name: 'status',type: 'text'},
				{ name: 'nmrs',type: 'text'},
				{ name: 'berat',type: 'text'},
				{ name: 'klinisi',type: 'text'},
				{ name: 'klinis',type: 'text'},
				{ name: 'tlppasien',type: 'text'},
				{ name: 'nmanalis',type: 'text'},
				{ name: 'verifikasi',type: 'text'},
				{ name: 'noloket',type: 'text'},
				{ name: 'jumlah',type: 'text'},
				{ name: 'nmdrafter',type: 'text'},
				{ name: 'tgldraft',type: 'text'},
				{ name: 'nmpembaca',type: 'text'},
				{ name: 'tgladendum',type: 'text'},
				{ name: 'nmadendum',type: 'text'},
				{ name: 'durasi', type: 'text'},

			],
			updaterow	: function (rowid, rowdata, commit) {commit(true);},
			type		: 'POST',
			data		: {bulan: bulan, tahun: tahun,  jenisreport: '', _token: token },
			url			: '{{ route("reportPeriksa") }}',

		};
        var dataAdapter = new $.jqx.dataAdapter(source);
        $('#divlaporan').hide();
		$('#divlaporanharian').show();
		var editrowjabatan = -1;
        $("#resultharian").jqxGrid({
            width					: '100%',
			enablebrowserselection	: true,
            filterable				: true,
            autoheight				: true,
            showfilterrow			: true,
			altrows 				: true,
            source					: dataAdapter,
            pageable				: true,
            theme					: "energyblue",
            columnsresize			: true,
            selectionmode			: 'multiplecellsextended',
            columns					: [
				{ text: 'File Report', editable: false, sortable: false, filterable: false, datafield: 'filefoto', width: 80, cellsalign: 'left', align: 'center'  },
				{ text: 'No.Loket', datafield: 'noloket', width: 80, cellsalign: 'left', align: 'center'  },
				{ text: 'No.RM', datafield: 'noregister', width: 70, align: 'center', cellsalign: 'left'},
                { text: 'Nama', datafield: 'nmpasien', width: 160, cellsalign: 'left', align: 'center' },
				{ text: 'No.HP', datafield: 'tlppasien', width: 100, cellsalign: 'left', align: 'center' },
                { text: 'Umur', datafield: 'usia', width: 70, cellsalign: 'left', align: 'center'  },
                { text: 'M', editable: false, sortable: false, filterable: false, datafield: 'l', width: 20, cellsalign: 'left', align: 'center'  },            
                { text: 'F', editable: false, sortable: false, filterable: false, datafield: 'p', width: 20, cellsalign: 'left', align: 'center'  },
                { text: 'Order', editable: false, sortable: false, filterable: false, datafield: 'jenis', width: 80, cellsalign: 'left', align: 'center'  },
                { text: 'JKN', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'jkn', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'UMM', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'umm', width: 40, cellsalign: 'left', align: 'center'  },
				{ text: 'TAG', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'tag', width: 40, cellsalign: 'left', align: 'center'  },
				{ text: 'GCU', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'gcu', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'Billing', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'billing', width: 40, cellsalign: 'left', align: 'center'  },
				{ text: 'SWASTA', editable: false, sortable: false, filterable: false, columngroup: 'asuransi', datafield: 'swasta', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'Elective', editable: false, sortable: false, filterable: false, columngroup: 'urgensi', datafield: 'ele', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'CITO', editable: false, sortable: false, filterable: false, columngroup: 'urgensi', datafield: 'cito', width: 40, cellsalign: 'left', align: 'center'  },
                { text: 'Sample Masuk', columngroup: 'waktu', datafield: 'daftar', width: 160, cellsalign: 'left', align: 'center'  },
                { text: 'Draft By', columngroup: 'waktu', datafield: 'nmdrafter', width: 150, cellsalign: 'left', align: 'center'  },
                { text: 'Tgl. Draft', columngroup: 'waktu', datafield: 'tgldraft', width: 80, cellsalign: 'left', align: 'center'  },
                { text: 'Expertise By', columngroup: 'waktu', datafield: 'nmpembaca', width: 150, cellsalign: 'left', align: 'center'  },
                { text: 'Supervisor', columngroup: 'waktu', datafield: 'nmdokter', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Verifikasi', columngroup: 'waktu', datafield: 'verifikasi', width: 80, cellsalign: 'left', align: 'center'  },
				{ text: 'Cetak', columngroup: 'waktu', datafield: 'export', width: 80, cellsalign: 'left', align: 'center'  },
				{ text: 'Asal Pasien', datafield: 'asalpasien', width: 100, cellsalign: 'left', align: 'center'  },
				{ text: 'Asal RS', datafield: 'nmrs', width: 100, cellsalign: 'left', align: 'center'  },
				{ text: 'Klinisi', datafield: 'klinisi', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Klinis', datafield: 'klinis', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Analis', datafield: 'nmanalis', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'PPDS', datafield: 'nmppdssenior', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Device', datafield: 'modality', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Code', datafield: 'kd_spesimen', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Speciment', datafield: 'nm_spesimen', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Template', datafield: 'dlp', width: 150, cellsalign: 'left', align: 'center'  },
				{ text: 'Duration', editable: false, sortable: false, filterable: false, datafield: 'durasi', width: 100, cellsalign: 'left', align: 'center'  },
            ],
			columngroups:
			[
				{ text: 'Riwayat Tindakan', align: 'center', name: 'waktu' },
				{ text: 'Urgensi', align: 'center', name: 'urgensi' },
				{ text: 'Insurance', align: 'center', name: 'asuransi' }
			]
        });
    });
    $('#downexcell').click(function(){
		var gridContent = $("#result").jqxGrid('exportdata', 'json');
		data = $.parseJSON(gridContent);
		var noOfContacts = data.length;
		if(noOfContacts>0){
			var table = document.createElement("table");
				table.style.width = '100%';
				table.setAttribute('border', '1');
				table.setAttribute('cellspacing', '0');
				table.setAttribute('cellpadding', '5');
				table.setAttribute('id', 'tabelcetak');
				table.setAttribute('class', 'text');
			var col = [];
			for (var i = 0; i < noOfContacts; i++) {
				for (var key in data[i]) {
					if (col.indexOf(key) === -1) {
						col.push(key);
					}
				}
			}
			var tHead = document.createElement("thead");
			var hRow = document.createElement("tr");
			for (var i = 0; i < col.length; i++) {
					var th = document.createElement("th");
					th.innerHTML = col[i];
					hRow.appendChild(th);
			}
			tHead.appendChild(hRow);
			table.appendChild(tHead);
			var tBody = document.createElement("tbody");
			for (var i = 0; i < noOfContacts; i++) {
				var bRow = document.createElement("tr");
				for (var j = 0; j < col.length; j++) {
					var td 		= document.createElement("td");
					var isi 	= data[i][col[j]];
					var isi2 	= isi.toString();
					var pjg 	= isi2.length;
					if (pjg > 8){
						if (pjg == 9 || pjg == 10 || pjg == 11 || pjg == 12 || pjg == 13){
							if( isi2.indexOf(',') != -1 ){
								var res = isi2.replace(/,/g, "");
								td.innerHTML = res;
							}
							else {
								var res = isi2;
								td.setAttribute('style', 'mso-number-format: "\@";');
								td.innerHTML = res;
							}
						}
						else { 
							var res = isi2;
							td.setAttribute('style', 'mso-number-format: "\@";');
							td.innerHTML = res;
						}						
					}
					else {
						var res = isi2.replace(/,/g, "");
						td.innerHTML = res;
					}
						
					bRow.appendChild(td);
				}
				tBody.appendChild(bRow)
			}
			table.appendChild(tBody);
			var divContainer = document.getElementById("tabel_cetak");
				divContainer.innerHTML = "";
				divContainer.appendChild(table);
		}
		
		$("#tabel_cetak").btechco_excelexport({
			containerid: "tabel_cetak"
			, datatype: $datatype.Table
		});
		return false;
	});
	$('#downexcellharian').click(function(){
		var gridContent = $("#resultharian").jqxGrid('exportdata', 'json');
			data = $.parseJSON(gridContent);
		var noOfContacts = data.length;
		if(noOfContacts>0){
			var table = document.createElement("table");
				table.style.width = '100%';
				table.setAttribute('border', '1');
				table.setAttribute('cellspacing', '0');
				table.setAttribute('cellpadding', '5');
				table.setAttribute('id', 'tabelcetak');
				table.setAttribute('class', 'text');
			var col = [];
			for (var i = 0; i < noOfContacts; i++) {
				for (var key in data[i]) {
					if (col.indexOf(key) === -1) {
						col.push(key);
					}
				}
			}
			var tHead = document.createElement("thead");
			var hRow = document.createElement("tr");
			for (var i = 0; i < col.length; i++) {
					var th = document.createElement("th");
					th.innerHTML = col[i];
					hRow.appendChild(th);
			}
			tHead.appendChild(hRow);
			table.appendChild(tHead);
			var tBody = document.createElement("tbody");
			for (var i = 0; i < noOfContacts; i++) {
				var bRow = document.createElement("tr");
				for (var j = 0; j < col.length; j++) {
					var td 		= document.createElement("td");
					var isi 	= data[i][col[j]];
					var isi2 	= isi.toString();
					var pjg 	= isi2.length;
					if (pjg > 8){
						if (pjg == 9 || pjg == 10 || pjg == 11 || pjg == 12 || pjg == 13){
							if( isi2.indexOf(',') != -1 ){
								var res = isi2.replace(/,/g, "");
								td.innerHTML = res;
							}
							else {
								var res = isi2;
								td.setAttribute('style', 'mso-number-format: "\@";');
								td.innerHTML = res;
							}
						}
						else { 
							var res = isi2;
							td.setAttribute('style', 'mso-number-format: "\@";');
							td.innerHTML = res;
						}						
					}
					else {
						var res = isi2.replace(/,/g, "");
						td.innerHTML = res;
					}
						
					bRow.appendChild(td);
				}
				tBody.appendChild(bRow)
			}
			table.appendChild(tBody);
			var divContainer = document.getElementById("tabel_cetak");
				divContainer.innerHTML = "";
				divContainer.appendChild(table);
		}
		
		$("#tabel_cetak").btechco_excelexport({
			containerid: "tabel_cetak"
			, datatype: $datatype.Table
		});
		return false;
	});
	$("#btnsimpandata").click(function(){
		var set01 = document.getElementById('idbakteri').value;
		var set02 = document.getElementById('createdby').value;
		var set03 = document.getElementById('tglpenyimpanan').value;
		var set04 = document.getElementById('atcc').value;
		var set05 = document.getElementById('strain').value;
		var set06 = document.getElementById('nmbakteri').value;
		var set07 = document.getElementById('tubenomor').value;
		var set08 = document.getElementById('boxnomor').value;
		var set09 = document.getElementById('slotnomor').value;
		var set10 = document.getElementById('raknomor').value;
		var set11 = document.getElementById('shelfnomor').value;
		var set12 = document.getElementById('kategorisimpan').value;
		$('#modaleditorbiorepository').modal('hide');
		var form_data 	= 	new FormData();
			form_data.append('id', set01);
			form_data.append('created_by', set02);
			form_data.append('tglpenyimpanan', set03);
			form_data.append('atcc', set04);
			form_data.append('strain', set05);
			form_data.append('nmbakteri', set06);
			form_data.append('tubenomor', set07);
			form_data.append('boxnomor', set08);
			form_data.append('slotnomor', set09);
			form_data.append('raknomor', set10);
			form_data.append('shelfnomor', set11);
			form_data.append('kategorisimpan', set12);
			form_data.append('tabel', 'BioRepository');
			form_data.append('_token', '{{csrf_token()}}');
		$.ajax({
			url			: '{{ route("exSIRAb") }}',
			data		: form_data,
			type		: 'POST',
			contentType	: false,
			processData	: false,
			success		: function (data) {
				var status  = data.status;
				var message = data.message;
				var icon 	= data.icon;
				var warna 	= data.warna;
				$("html, body").animate({ scrollTop: 0 }, "slow");
				$.toast({
					heading		: status,
					text		: message,
					position	: 'top-right',
					loaderBg	: warna,
					icon		: icon,
					hideAfter	: 3000,
					stack		: 1
				});
				$("#result").jqxGrid('updatebounddata', 'filter');
				return false;
			},
			error		: function (xhr, status, error) {
				var response 	= xhr.responseJSON || {};
				var traceText 	= response.trace ? JSON.stringify(response.trace) : null;
				swal({
					title	: response,
					text	: traceText,
					type	: 'error',
				})
			}
		});
	});
});
</script>
@endpush
