@extends('layout')

@section('content')
<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="index.html"><i class="icon-home2 position-left"></i> Produksi</a></li>
			<li class="active">Upah Harian</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Tambah Upah Harian</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	       	<hr>
	    </div>
	    <div class="panel-body">
	    	<div class="row">
	    		<form action="{{ url('upahharian/tambah-form/simpan') }}" method="POST" class="form-horizontal" autocomplete="off">
	    			{{ csrf_field() }}
	    			<div class="col-md-12">
	    				<div class="col-md-6">
	    					<div class="form-group">
	    						<label class="control-label col-md-4">No. Upah</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="text" name="noupah" id="noupah" placeholder="No. Upah" value="{{ $data['noupah'] }}" required/>
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Tanggal</label>
	    						<div class="col-md-8">
	    							<input class="form-control datepicker" type="text" name="tanggal" id="tanggal" placeholder="Tanggal" value="{{ date('d-m-Y') }}" required/>
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Bulan Gaji</label>
	    						<div class="col-md-4">
	    							<select class="form-control select-search" name="bulan_gaji" id="bulan_gaji">
			        					<option value="1" @if(date('m') == "01") selected @endif>Januari</option>
			        					<option value="2" @if(date('m') == "02") selected @endif>Februari</option>
			        					<option value="3" @if(date('m') == "03") selected @endif>Maret</option>
			        					<option value="4" @if(date('m') == "04") selected @endif>April</option>
			        					<option value="5" @if(date('m') == "05") selected @endif>Mei</option>
			        					<option value="6" @if(date('m') == "06") selected @endif>Juni</option>
			        					<option value="7" @if(date('m') == "07") selected @endif>Juli</option>
			        					<option value="8" @if(date('m') == "08") selected @endif>Agustus</option>
			        					<option value="9" @if(date('m') == "09") selected @endif>September</option>
			        					<option value="10" @if(date('m') == "10") selected @endif>Oktober</option>
			        					<option value="11" @if(date('m') == "11") selected @endif>November</option>
			        					<option value="12" @if(date('m') == "12") selected @endif>Desember</option>
			        				</select>
	    						</div>
	    						<div class="col-md-4">
	    							<input type="number" min="0" name="tahun_gaji" id="tahun_gaji" class="form-control" placeholder="Tahun Gaji" value="{{ date('Y') }}" required>
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Akun Bayar</label>
	    						<div class="col-md-8">
	    							<select class="form-control select-search" name="akun_bayar" id="akun_bayar" required>
			        					<option value="">-- Pilih Akun --</option>
			        					@foreach($data['akun2'] as $key => $value)
			        					    <option value="{{ $key }}" @if($key == "4") selected @endif>{{ $value }}</option>
			        					@endforeach
			        				</select>
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Keterangan</label>
	    						<div class="col-md-8">
	    							<textarea class="form-control" name="keterangan" id="keterangan"></textarea>
	    						</div>
	    					</div>
	    				</div>
	    				<div class="col-md-6">
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Departemen</label>
	    						<div class="col-md-8">
	    							<select class="form-control select-search" name="departemen" id="departemen" required onchange="getPegawai()">
			        					<option value="">-- Pilih Departemen --</option>
			        					@foreach($data['departement'] as $key => $value)
			        					    <option value="{{ $value->id_departement }}">{{ $value->nama }}</option>
			        					@endforeach
			        				</select>
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Pegawai</label>
	    						<div class="col-md-8">
	    							<select class="form-control select-search" name="pegawai" id="pegawai" required>
			        					<option value="">-- Pilih Pegawai --</option>
			        				</select>
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Jenis Pegawai</label>
	    						<div class="col-md-8">
	    							<select class="form-control select-search" name="jenis_pegawai" id="jenis_pegawai" required>
			        					<option value="">-- Pilih Jenis Pegawai --</option>
			        					<option value="2">Harian Adm. Gudang</option>
			        					<option value="3">Mandor & Manager Produksi</option>
			        					<option value="4">Adm. Umum & Design</option>
			        					<option value="5">Harian Non Produksi</option>
			        				</select>
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Gaji/Hari</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="number" min="0" name="gaji_hari" id="gaji_hari" placeholder="Gaji/Hari" value="0" required onkeyup="changeGajiHari()" />
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Gaji/Jam</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="number" min="0" name="gaji_jam" id="gaji_jam" placeholder="Gaji/Jam" value="0" required onkeyup="changeGajiJam()"/>
	    						</div>
	    					</div>
	    				</div>
	    			</div>
	    			<div class="col-md-12">
	    				<h5 class="panel-title">Upah</h5>
	    				<hr>
	    				<div class="col-md-6">
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Gaji Pokok</label>
	    						<div class="col-md-4">
	    							<select class="form-control select-search" name="akun_gaji_pokok" id="akun_gaji_pokok" required>
			        					<option value="">-- Pilih Akun --</option>
			        					@foreach($data['akun2'] as $key => $value)
			        					    <option value="{{ $key }}" @if($key == "152") selected @endif>{{ $value }}</option>
			        					@endforeach
			        				</select>
	    						</div>
	    						<div class="col-md-4">
	    							<input class="form-control" type="number" min="0" name="hari_gaji_pokok" id="hari_gaji_pokok" placeholder="Total Hari" value="" required onkeyup="changeHariGajiPokok()" />
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Tunj. Jabatan</label>
	    						<div class="col-md-8">
	    							<select class="form-control select-search" name="akun_tunj_jabatan" id="akun_tunj_jabatan" required>
			        					<option value="">-- Pilih Akun --</option>
			        					@foreach($data['akun2'] as $key => $value)
			        					    <option value="{{ $key }}" @if($key == "154") selected @endif>{{ $value }}</option>
			        					@endforeach
			        				</select>
	    						</div>
	    					</div>
	    				</div>
	    				<div class="col-md-6">
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Total</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="text" name="total_gp_hari" id="total_gp_hari" placeholder="Total" value="0" required readonly />
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Total</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="number" min="0" name="total_tunj_jabatan" id="total_tunj_jabatan" placeholder="Total" value="0" required onkeyup="hitungNetto()" />
	    						</div>
	    					</div>
	    				</div>
	    			</div>
	    			<div class="col-md-12">
	    				<h5 class="panel-title">Lembur</h5>
	    				<hr>
	    				<div class="col-md-6">
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Lembur/Hari</label>
	    						<div class="col-md-4">
	    							<select class="form-control select-search" name="akun_lembur_hari" id="akun_lembur_hari" required>
			        					<option value="">-- Pilih Akun --</option>
			        					@foreach($data['akun2'] as $key => $value)
			        					    <option value="{{ $key }}" @if($key == "153") selected @endif>{{ $value }}</option>
			        					@endforeach
			        				</select>
	    						</div>
	    						<div class="col-md-4">
	    							<input class="form-control" type="number" min="0" name="hari_lembur_hari" id="hari_lembur_hari" placeholder="Total Hari" value="" required onkeyup="changeHariLembur()" />
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Lembur/Jam</label>
	    						<div class="col-md-4">
	    							<select class="form-control select-search" name="akun_lembur_jam" id="akun_lembur_jam" required>
			        					<option value="">-- Pilih Akun --</option>
			        					@foreach($data['akun2'] as $key => $value)
			        					    <option value="{{ $key }}" @if($key == "153") selected @endif>{{ $value }}</option>
			        					@endforeach
			        				</select>
	    						</div>
	    						<div class="col-md-4">
	    							<input class="form-control" type="number" min="0" name="jam_lembur_jam" id="jam_lembur_jam" placeholder="Total Jam" value="" required onkeyup="changeJamLembur()" />
	    						</div>
	    					</div>
	    				</div>
	    				<div class="col-md-6">
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Total</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="text" name="total_lembur_hari" id="total_lembur_hari" placeholder="Total" value="0" required readonly />
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Total</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="text" name="total_lembur_jam" id="total_lembur_jam" placeholder="Total" value="0" required readonly />
	    						</div>
	    					</div>
	    				</div>
	    			</div>
	    			<div class="col-md-12">
	    				<h5 class="panel-title">Lainnya</h5>
	    				<hr>
	    				<div class="col-md-6">
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Premi</label>
	    						<div class="col-md-8">
	    							<select class="form-control select-search" name="akun_premi" id="akun_premi" required>
			        					<option value="">-- Pilih Akun --</option>
			        					@foreach($data['akun2'] as $key => $value)
			        					    <option value="{{ $key }}" @if($key == "154") selected @endif>{{ $value }}</option>
			        					@endforeach
			        				</select>
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Potongan</label>
	    						<div class="col-md-8">
	    							<select class="form-control select-search" name="akun_potongan" id="akun_potongan" required>
			        					<option value="">-- Pilih Akun --</option>
			        					@foreach($data['akun2'] as $key => $value)
			        					    <option value="{{ $key }}" @if($key == "4") selected @endif>{{ $value }}</option>
			        					@endforeach
			        				</select>
	    						</div>
	    					</div>
	    				</div>
	    				<div class="col-md-6">
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Total</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="text" name="total_premi" id="total_premi" placeholder="Total" value="0" required onkeyup="hitungNetto()" />
	    						</div>
	    					</div>
	    					<div class="form-group">
	    						<label class="control-label col-md-4">Total</label>
	    						<div class="col-md-8">
	    							<input class="form-control" type="text" name="total_potongan" id="total_potongan" placeholder="Total" value="0" required onkeyup="hitungNetto()" />
	    						</div>
	    					</div>
	    				</div>
	    			</div>
	    			<div class="col-md-12"><hr></div>
	    			<div class="col-md-6 pull-right">
	    				<div class="form-group">
	    					<label class="control-label col-md-4">Netto</label>
	    					<div class="col-md-8">
	    						<input class="form-control" type="text" name="netto" id="netto" placeholder="Netto" value="0" required readonly />
	    					</div>
	    				</div>
	    				<div class="form-group">
	    					<label class="control-label col-md-4">Pembulatan</label>
	    					<div class="col-md-4">
	    						<input class="form-control" type="number" min="0" name="pembulatan" id="pembulatan" placeholder="Pembulatan" value="0" required onkeyup="totalAkhir()" />
	    						<label><input type="checkbox" name="check_pembulatan" id="check_pembulatan" onchange="totalAkhir()"> Pengurangan</label>
	    					</div>

    						<div class="col-md-4">
    							<select class="form-control select-search" name="akun_pembulatan" id="akun_pembulatan">
		        					<option value="">-- Pilih Akun --</option>
		        					@foreach($data['akun2'] as $key => $value)
		        					    <option value="{{ $key }}" @if($key == "177") selected @endif>{{ $value }}</option>
		        					@endforeach
		        				</select>
    						</div>

	    				</div>
	    				<div class="form-group">
	    					<label class="control-label col-md-4">Total Akhir</label>
	    					<div class="col-md-8">
	    						<input class="form-control" type="text" name="total_akhir" id="total_akhir" placeholder="Total Akhir" value="0" required readonly />
	    					</div>
	    				</div>
	    				<div class="pull-right">
	    					<button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> Simpan</button>
	    				</div>
	    			</div>
	    		</form>
	    	</div>
	    </div>
	</div>
</div>

@endsection

<script type="text/javascript">
	var BASE_URL = "{{ url('/') }}";
	function changeGajiHari()
	{
		var gaji_hari  = $("#gaji_hari").val(),
			hr_gj_pk   = $("#hari_gaji_pokok").val(),
			hr_lm_hr   = $("#hari_lembur_hari").val(),
			jm_lm_jm   = $("#jam_lembur_jam").val();

		var tot_gj_jam = (parseFloat(gaji_hari)/7).toFixed(2);

		if (isNaN(tot_gj_jam)) {
			tot_gj_jam = 0;
		}

		$("#gaji_jam").val(tot_gj_jam);

		if (hr_gj_pk == "") {
			hr_gj_pk = 1;
			$("#hari_gaji_pokok").val(hr_gj_pk);
		}

		if (hr_lm_hr == "") {
			hr_lm_hr = 1;
			$("#hari_lembur_hari").val(hr_lm_hr);
		}

		if (jm_lm_jm == "") {
			jm_lm_jm = 1;
			$("#jam_lembur_jam").val(jm_lm_jm);
		}

		var tot_gj_pk = gaji_hari * hr_gj_pk;

		$("#total_gp_hari").val(tot_gj_pk);

		var tot_lm_hr = gaji_hari * hr_lm_hr * 2;

		$("#total_lembur_hari").val(tot_lm_hr);

		var tot_lm_jm = tot_gj_jam * jm_lm_jm;

		$("#total_lembur_jam").val(tot_lm_jm);

		hitungNetto();
	}

	function changeGajiJam()
	{
		var gaji_jam = $("#gaji_jam").val(),
			jm_lm_jm = $("#jam_lembur_jam").val();

		if (jm_lm_jm == "") {
			jm_lm_jm = 1;
			$("#jam_lembur_jam").val(jm_lm_jm);
		}

		var tot_lm_jm = gaji_jam * jm_lm_jm;

		$("#total_lembur_jam").val(tot_lm_jm);

		hitungNetto();
	}

	function changeHariGajiPokok()
	{
		var gaji_hari  = $("#gaji_hari").val(), 
			hr_gj_pk   = $("#hari_gaji_pokok").val();

		if (hr_gj_pk == "") {
			hr_gj_pk = 0;
		}

		var tot_gj_pk = gaji_hari * hr_gj_pk;

		$("#total_gp_hari").val(tot_gj_pk);

		hitungNetto();
	}

	function changeHariLembur()
	{
		var gaji_hari  = $("#gaji_hari").val(), 
			hr_lm_hr   = $("#hari_lembur_hari").val();

		if (hr_lm_hr == "") {
			hr_lm_hr = 1;
		}

		var tot_lm_hr = gaji_hari * hr_lm_hr * 2;

		$("#total_lembur_hari").val(tot_lm_hr);

		hitungNetto();
	}

	function changeJamLembur()
	{
		var gaji_jam  = $("#gaji_jam").val(), 
			jm_lm_jm   = $("#jam_lembur_jam").val();

		if (jm_lm_jm == "") {
			jm_lm_jm = 1;
		}

		var tot_lm_jam = gaji_jam * jm_lm_jm;

		$("#total_lembur_jam").val(tot_lm_jam);

		hitungNetto();
	}

	function getPegawai()
	{
		var id_departement = $("#departemen").val();
		$.getJSON(BASE_URL+'/upahharian/get-pegawai/'+id_departement, function(result){
			$("#pegawai option").remove();
			var option = '<option value="">-- Pilih Pegawai --</option>';
			$.each(result, function(index, value){
				option += '<option value="'+value.nomor_pegawai+'">('+value.nomor_pegawai+') '+value.nama_pegawai+'</option>';
			});

			$("#pegawai").append(option);
		});
	}

	function hitungNetto()
	{
		var gaji_pokok = $("#total_gp_hari").val(),
			tunj_jabatan = $("#total_tunj_jabatan").val(),
			lembur_hari = $("#total_lembur_hari").val(),
			lembur_jam = $("#total_lembur_jam").val(),
			premi = $("#total_premi").val(),
			potongan = $("#total_potongan").val();

		if (gaji_pokok == "") {gaji_pokok=0;}
		if (tunj_jabatan == "") {tunj_jabatan=0;}
		if (lembur_hari == "") {lembur_hari=0;}
		if (lembur_jam == "") {lembur_jam=0;}
		if (premi == "") {premi=0;}
		if (potongan == "") {potongan=0;}
		
		var net = parseFloat(gaji_pokok) + parseFloat(tunj_jabatan) + parseFloat(lembur_hari) + parseFloat(lembur_jam) + parseFloat(premi) - parseFloat(potongan);

		$("#netto").val(net);

		totalAkhir();
	}

	function totalAkhir()
	{
		var netto = $("#netto").val(),
			pembulatan = $("#pembulatan").val();

		if (netto == "") {netto=0;}
		if (pembulatan == "") {pembulatan=0;}

		if($("#check_pembulatan").is(':checked')){
		    var hasil = parseFloat(netto) - parseFloat(pembulatan);
		} else {
		    var hasil = parseFloat(netto) + parseFloat(pembulatan);
		}

		$("#total_akhir").val(hasil);
	}
</script>