@extends('layout')


@section('content')

<style type="text/css">
	 .table-form>tbody>tr>th, .table-form>tfoot>tr>th, .table-form>thead>tr>td, .table-form>tbody>tr>td, .table-form>tfoot>tr>td{
		    padding: 5px;
		   -- vertical-align: middle;
		}
		table.table-form tbody>tr.selected, table.table-form tbody>tr.selected td, table.table-form tbody>tr>.selected{
		    color: white !important;
		    background-color: #49b6d6 !important;
		}

	 table, th, td, input, textarea, select {
            color:  black !important; 
        }
        .help-block {
 
    margin-top: 0px!important;
    margin-bottom: 0px!important;
}
</style>

<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> Penjualan</a></li>
			<li class="active">Surat Jalan</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Form Input Surat Jalan</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a href="{{ url('surat_jalan') }}" class="text-warning"><i class="icon-circle-left2 warning"></i> Kembali</a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<form class="form-horizontal" method="post" action="{{ url('penjualan/simpan') }}" autocomplete="off" >
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_penjualan" value="{{ $data['data']['id_penjualan']}}">
        	<div class="col-sm-6">
	    		<div class="form-group">
	    			{{ Form::label("Label CV", "", ['class'=>'control-label col-sm-4']) }}
	    			<div class="col-sm-8">
	    				<div class="checkbox">
	    					<label>
		    					{{ Form::checkbox("cv", '1', $data['data']['cv'], ['class'=>'styled']) }}
	    					</label>
	    				</div>
	    			</div>
	    		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Pelanggan</label>
        			<div class="col-sm-8">
        				<select class="form-control select-search" name="pelanggan">
        					@php foreach($data['pelanggan'] as $s){ 
        					$sel = $data['data']['id_pelanggan'];
        					@endphp

        					<option value="@php echo $s->id_pelanggan @endphp" {{ ($s->id_pelanggan == $sel) ? "selected":"" }}>@php echo  $s->pic.' - '.$s->nama @endphp</option>

        					@php } @endphp
        				</select>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Input</label>
        			<div class="col-sm-8">
        				<input class="form-control set_datepicker" type="text" name="tanggal" placeholder="Tanggal" value="{{ ($data['data']['tanggal'] == '') ? date('d-m-Y'):$data['data']['tanggal'] }}" required/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Faktur</label>
        			<div class="col-sm-8">
        				<input class="form-control set_datepicker" type="text" name="tanggal_faktur" placeholder="Tanggal Faktur" value="{{ $data['data']['tanggal_faktur'] }}" onchange="get_nomor($(this)), set_jatuh_tempo($(this))" required/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Jatuh Tempo</label>
        			<div class="col-sm-8">
        				<input class="form-control set_datepicker" type="text" name="tanggal_tempo" placeholder="Tanggal Jatuh Tempo" value="{{ $data['data']['tanggal_tempo'] }}" required/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">No. Faktur</label>
        			<div class="col-sm-3 col-md-3">
        				{{ Form::text('no_faktur', $data['data']['no_faktur'], ['class'=>'form-control text-right', 'placeholder'=>'Nomor']) }}
        			</div>
        			<div class="col-sm-5 col-md-5">
        				{{ Form::text("sufix_no_faktur", $data['data']['sufix_no_faktur'], ['class'=>'form-control text-uppercase']) }}
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Keterangan</label>
        			<div class="col-sm-8">
        				<textarea class="form-control" name="keterangan" rows="2">{{ $data['data']['keterangan'] }}</textarea>
        			</div>
        		</div>
        	</div>

        	<div class="col-sm-6">
        	</div>

        	
        	<div class="col-sm-12 form-group">
	        	<h5 class="panel-title">Detail Barang</h5>
	        	<!-- <a href="#" class="btn btn-success" style="margin-bottom: 1%;" id="btn_tambah_item">Tambah Barang</a> -->
	        </div>

	    </div>
        
        <div class="responsive">
        <table class="table table-stripped" id="table_barang">
	    	<thead>
				<tr>
					<th>Kode Barang</th>
					<th>Nama Barang</th>
					<th>Jumlah</th>
					<th class="text-center" width="5%">Aksi</th>
				</tr>
			</thead>
			<tbody>
				<tr class="row-barang">
					<td>
						@php($dataBarang = sizeOf($data['dataBarang'])>0 ? $data['dataBarang']:[])
						{{ Form::select("id_barang", $dataBarang, null, ['class'=>'form-control set_select2']) }}
					</td>
					<td>
						{{ Form::text("nama_barang", "", ["class"=>"form-control"]) }}
					</td>
					<td>
						{{ Form::number("jumlah", "", ["class"=>"form-control text-right", "step"=>0.01]) }}
					</td>
					<td>
						<button type='button' class='btn btn-xs btn-link text-danger' onclick='hapusRowBarang($(this))'><i class='icon-trash'></i></button>
					</td>
				</tr>
			</tbody>
	    </table>
		</div>

	    <div class="panel-footer">
	    	<div class="col-sm-12 col-md-12">
	            <div class="form-group pull-right">
	             	<button class="btn btn-primary" type="submit">Simpan</button>
	            </div>

	    	</div>

	    </div>


		<input type="hidden" name="td_total" class="form-control">
		<input type="hidden" name="td_netto" class="form-control">
	    </form>
	</div>
</div>

<input type="hidden" name="store_konversi_awal" class="form-control">
<input type="hidden" name="store_konversi_akhir" class="form-control">
<input type="hidden" name="store_konversi" class="form-control">

<!----Modal---->
<script type="text/javascript">

	var table_barang;
	var id_penjualan = '';
	var tb_no = parseInt(10000);

	$(document).ready(function(){
		table_barang = $("#table_barang").DataTable({
			paging : false,
		});
		table_barang.on( 'order.dt search.dt', function () {
        } ).draw();

		id_penjualan = '{{ $data['data']['id_penjualan']}}';
		if(id_penjualan != ''){
			get_edit(id_penjualan);
		}

		$(".set_select2").select2();
        $("input[name=tanggal_faktur]").trigger("change");
	})

	function get_nomor(this_){
		var id_penjualan = $("input[name=id_penjualan]").val();
		var date = this_.val();
		var s_date = date.split("/");
		var sufix_no_faktur = "/KTJB";
		$.ajax({
			url : "{{ url('penjualan/get_nomor') }}",
			type : "get",
			data : {id_penjualan:id_penjualan, tanggal:date},
			dataType : "json",
			success : function(result){
				if(id_penjualan!=""){
					sufix_no_faktur = result.sufix_no_faktur;
				}
				
				$("input[name=no_faktur]").val(result.no_faktur);
				$("input[name=sufix_no_faktur]").val(sufix_no_faktur);
			}
		});
	}

	function set_jatuh_tempo(this_) {
		var id_penjualan = $("input[name=id_penjualan]").val();
		var date = this_.val();
		var s_date = date.split("/");
		var _date = new Date(s_date[2], s_date[1], s_date[0]);
		_date.setMonth(_date.getMonth()+1);

		var dd = _date.getDate();
		var mm = _date.getMonth()+1;
		var yyyy = _date.getFullYear();
		if(mm < 10) mm = '0'+mm;
		if(dd < 10) dd = '0'+dd;

		var set = [dd, mm, yyyy];
		$("input[name=tanggal_tempo]").val(set.join("/"));
	}

	function setFormatNumber(this_, p) {
		var parentz = this_.parents(p);
		var data = this_.val();
		parentz.find(".help-block").text(curr(data));
	}


</script>

@endsection