@extends('layout')


@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="#"><i class="icon-home2 position-left"></i> Keuangan</a></li>
			<li><a href="#">Piutang Rekanan</a></li>
			<li class="active">Tambah Piutang Rekanan</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Tambah Piutang Rekanan</h5>

			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a href="{{ url('piutang_pegawai') }}" class="text-warning"><i class="icon-circle-left2 warning"></i> Kembali</a></li>
		      	</ul>
	       	</div>

	    </div>

	    <form class="" role="form" id="form-piutang-rekanan" method="post" action="{{ url('piutang_rekanan/').(isset($kasbon) ? '/'.$kasbon->id : '') }}">
	    	{{ Form::token()}}
	    	{{ method_field($method) }}
	    <div class="panel-body">
	    	<div class="row">
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-3 col-md-3">
				    	<div class="form-group">
			    			<label class="control-label">Lokasi</label>
			    			<select name="lokasi" class="form-control set_select2" required="">
			    				@foreach($lokasi_produksi AS $key => $value)
			    				@php
			    				$id_lokasi = (isset($kasbon) ? $kasbon->lokasi : Session::get("id_lokasi"));
			    				$attr = "";
			    				if($value->id_lokasi==$id_lokasi)
			    				{
			    					$attr = "selected=''";
			    				}
			    				@endphp
			    				<option value="{{ $value->id_lokasi }}" {{ $attr }}>{{ $value->nama_lokasi }}</option>
			    				@endforeach
			    			</select>
			    		</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-6 col-md-6">
	    				<div class="form-group">
	    					{{ Form::label("Rekanan", "", ['class'=>'control-label']) }}
	    					{{ Form::select("id_rekanan", $dataRekanan, (isset($kasbon) ? $kasbon->id_kelompok."|".$kasbon->id_rekanan : ''), ['class'=>'form-control set_select2']) }}
	    				</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-3 col-md-3">
	    				<div class="form-group">
		    				{{ Form::label("No. Transaksi", "", ['class'=>'control-label']) }}
		    				{{ Form::text("nomor_transaksi", (isset($kasbon) ? $kasbon->nomor_transaksi : '1'), ['class'=>'form-control']) }}
		    			</div>
	    			</div>
	    			<div class="col-sm-3 col-md-3">
	    				<div class="form-group">
		    				{{ Form::label("Tanggal", "", ['class'=>'control-label']) }}
		    				{{ Form::text("tanggal_transaksi", (isset($kasbon) ? date_db($kasbon->tanggal_transaksi, "true") : date("d/m/Y")), ['class'=>'form-control set_datepicker', 'onchange'=>'get_nomor_kasbon($(this))']) }}
		    			</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-3 col-md-3">
	    				<div class="form-group">
		    				{{ Form::label("Bayar dari", "", ['class'=>'control-label']) }}
		    				{{ Form::select("dari_akun", $akun, [1], ['class'=>'form-control set_select2']) }}
		    				{{ Form::hidden("tipe_dari_akun", "K") }}
		    			</div>
	    			</div>
	    			<div class="col-sm-3 col-md-3">
	    				<div class="form-group">
		    				{{ Form::label("Nominal", "", ['class'=>'control-label']) }}
		    				{{ Form::text("nominal", (isset($kasbon) ? $kasbon->nominal : ''), ['class'=>'form-control text-right', 'onkeyup'=>'setFormatMoney($(this), "div")']) }}
		    				<span class="help-block text-right" style="font-weight: bold;">Rp 0</span>
		    			</div>
	    			</div>
	    		</div>
	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-6 col-md-6">
	    				<div class="form-group">
		    				{{ Form::label("Untuk Keperluan", "", ['class'=>'control-label']) }}
		    				{{ Form::text("keterangan", (isset($kasbon) ? $kasbon->keterangan : '-'), ['class'=>'form-control']) }}
		    			</div>
	    			</div>
	    		</div>


	    		<div class="col-sm-12 col-md-12">
	    			<div class="col-sm-6 col-md-6 text-right">
	    				<div class="form-group">
					    	<button type="submit" class="btn btn-md btn-success"><i class="icon-floppy-disk"></i> Simpan</button>
		    			</div>
	    			</div>
	    		</div>
	    	</div>
	    </div>
		</form>
	    
	</div>
</div>

<script type="text/javascript">
var formPengeluaran = $("#form-piutang-rekanan");

$(document).ready(function () {
	$(".set_select2").select2();
	$(".set_datepicker").datepicker({
		format : 'dd/mm/yyyy',
		autoclose : true,
      	zIndexOffset : 9999,
	});

	$("#form-piutang-rekanan input[name=nominal]").trigger("keyup");
	$("#form-piutang-rekanan input[name=tanggal_transaksi]").trigger("onchange");
});

function get_nomor_kasbon(this_){
	var id_kasbon = "{{ (isset($kasbon) ? $kasbon->id : '') }}";
	var date = this_.val();
	var s_date = date.split("/");

	$.ajax({
		url : "{{ url('piutang_rekanan/get_nomor_kasbon') }}",
		type : "get",
		data : {id:id_kasbon, tanggal_transaksi:date},
		dataType : "json",
		success : function(result){			
			$("input[name=nomor_transaksi]").val(result.nomor_transaksi);
		}
	});
}

function setFormatMoney(this_, p) {
	var div = this_.parents(p);
	var data = this_.val();
	if(data==""){
		data = 0;
	}
	div.find(".help-block").html(accounting.formatMoney(data));
}
</script>

@endsection