@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> Master</a></li>
			<li class="active">Upah Tenun</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Form Upah Tenun</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<form class="form-horizontal" method="post" action="{{ url('upah_tenun/simpan') }}" autocomplete="off" >
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_upahtenun" value="{{ $data['data']['id_upahtenun']}}">
	    	
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Nama Makelar</label>
        			<div class="col-sm-8">
        				<!-- <input class="form-control text-uppercase" type="text" name="nama_makelar" placeholder="Nama Makelar" value="{{ $data['data']['makelar'] }}" required/> -->
        				<select class="form-control select-search" name="makelar">
        					<option value="">--- Pilih Makelar ---</option>
        					@php $sel = $data['data']['makelar'];
        					foreach($data['makelar'] as $d){ @endphp
        					<option value="{{$d->id_kelompok}}" {{ ($d->id_kelompok == $sel) ? "selected":"" }}>{{$d->nama}}</option>
        					@php } @endphp
        				</select>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Rekanan</label>
        			<div class="col-sm-8">
        				<select class="form-control select-search" id="rekanan" name="rekanan">
        					<option value="">--- Pilih Rekanan ---</option>
        					@php $sel = $data['data']['rekanan'] ;
        					foreach($data['rekanan'] as $d){ @endphp
        					<option value="{{$d->id_rekanan}}" {{ ($d->id_rekanan == $sel) ? "selected":"" }}>{{$d->nama}}</option>
        				@php } @endphp
        				</select>
        			</div>
        		</div>
        		<div class="form-group">
	    			<label class="control-label col-sm-4">Jenis Produksi </label>
	    			<div class="col-sm-8">
	    				<select class="form-control select-search" name="id_jenis">
	    					<option value="">--- Pilih Jenis ---</option>
	    					@php $sel = $data['data']['jenis'];
	    					foreach($data['produksi'] as $d){@endphp
	    					<option value="{{$d->id_lokasi}}" {{ ($d->id_lokasi == $sel) ? "selected":"" }} >{{ $d->nama_lokasi }}</option>
	    					@php } @endphp
	    				</select>
	    			</div>
	    		</div>
        	</div>
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal</label>
        			<div class="col-sm-8">
        				<input class="form-control datepicker" type="text" name="tanggal" placeholder="Tanggal" value="{{ ($data['data']['tanggal'] == '') ? date('d-m-Y'):$data['data']['tanggal'] }}" required readonly />
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Nomor</label>
        			<div class="col-sm-8">
        				<input class="form-control text-uppercase" type="text" name="nomor" placeholder="Nomor" value="{{ $data['data']['nomor']}}" required/>
        			</div>
        		</div>
        	</div>

        	<div class="col-sm-12 form-group">
        	<h5 class="panel-title">Detail Barang</h5>
        		<br>
        		<button href="#" class="btn btn-success" style="margin-bottom: 1%;" id="btn_tambah_item" type="button">Tambah</button> 
        		<!-- <button href="#" class="btn btn-warning" style="margin-bottom: 1%;" id="btn_ambil_barang" type="button">Ambil Barang</button> -->
        	</div>
        	<div class="col-ms-12 ">
        	<div class="panel-body table-responsive">
        	<table class="table table-stripped table-bordered" id="table_barang">
	    	<thead>
				<tr>
					<th rowspan="3">No</th>
					<th rowspan="3">Motif</th>
					<th rowspan="3">Nominal (Rp)</th>
					<th rowspan="3">Tabungan (Rp)</th>
					<th colspan="7" class="text-center">Bonus Pick</th>
					<th rowspan="3" class="text-center">Aksi</th>
				</tr>
				<tr>
					<th colspan="3">Penambahan</th>
					<th>Pas</th>
					<th colspan="3">Pengurangan</th>
				</tr>
				<tr>
					<td><input type="text" name="penambahan1" class="form-control number-only" value="{{$data['data']['penambahan1']}}"></td>
					<td><input type="text" name="penambahan2"class="form-control number-only" value="{{$data['data']['penambahan2']}}"></td>
					<td><input type="text" name="penambahan3"class="form-control number-only" value="{{$data['data']['penambahan3']}}"></td>
					<td><input type="text" name="pas" class="form-control number-only" value="{{$data['data']['pas']}}"></td>
					<td><input type="text" name="pengurangan1" class="form-control number-only" value="{{$data['data']['pengurangan1']}}"></td>
					<td><input type="text" name="pengurangan2" class="form-control number-only" value="{{$data['data']['pengurangan2']}}"></td>
					<td><input type="text" name="pengurangan3" class="form-control number-only" value="{{$data['data']['pengurangan3']}}"></td>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
	    </table>
	</div>
        	</div>
   
	    </div>

	    <div class="panel-footer">
	    	<div class="form-group col-md-12 col-sm-12">
				<a href="{{url('upah_tenun')}}" class="btn bg-warning-400">Kembali</a>
				<div class="form-group pull-right">
					<button class="btn btn-primary" type="submit">Simpan</button>
				</div>
			</div>
	    </div>

	    </form>
	</div>
</div>

<!---Modal--->
<div class="modal fade" id="exampleModal"  role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-lg" role="document">
	    <div class="modal-content">
	    	<div class="modal-header">
	    		<h5 class="modal-title" id="exampleModalLabel">Data</h5>
	    		<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span></button>
	      	</div>
	      	<div class="modal-body">
	      		<form class="form-horizontal" autocomplete="off">
	      			<input type="hidden" name="popup_id_table">
	      			<!-- <div class="form-group">
	      				<label class="control-label col-sm-4">Barang</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_barang">
	      					</select>
	      				</div>
	      			</div> -->
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Motif</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_motif">
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Nominal</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_nominal" class="form-control number-only">
	      					<p class="pull-right" id="help_popup_nominal"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Tabungan</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_tabungan" class="form-control number-only">
	      					<p class="pull-right" id="help_popup_tabungan"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Penambahan 1</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_penambahan1" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Penambahan 2</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_penambahan2" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Penambahan 3</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_penambahan3" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Pas</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_pas" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Pengurangan 1</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_pengurangan1" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Pengurangan 2</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_pengurangan2" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Pengurangan 3</label>
	      				<div class="col-sm-8">
	      					<!-- <input type="text" name="popup_pengurangan3" class="form-control number-only"> -->
	      					<select class="form-control select-search" name="popup_pengurangan3">
	      						
	      					</select>
	      				</div>
	      			</div>
	      		</form>
	      	</div>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan">Simpan</button>
	      	</div>
	    </div>
	</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">

<input type="hidden" name="store_konversiorder" class="form-control">

<!----Modal---->
<script type="text/javascript">
	$("#btn_tambah_item").click(function(){
		$("[name=popup_id_table]").val('');
		$("[name=popup_barang]").val('').trigger('change');
		$("[name=popup_motif]").val('').trigger('change');
		$("[name=popup_nominal]").val('');
		$("#help_popup_nominal").text('');
		$("[name=popup_tabungan]").val('');
		$("#help_popup_tabungan").text('');
		$("[name=popup_penambahan1]").val('');
		$("[name=popup_penambahan2]").val('');
		$("[name=popup_penambahan3]").val('');
		$("[name=popup_pas]").val('');
		$("[name=popup_pengurangan1]").val('');
		$("[name=popup_pengurangan2]").val('');
		$("[name=popup_pengurangan3]").val('');
		$("#exampleModal").modal('show');	
	})

	var table_barang;
	var tb_no = parseInt(10000);
	var id_upahtenun;
	$(document).ready(function(){
		table_barang = $("#table_barang").DataTable({
			"paging": false
		});
		table_barang.on( 'order.dt search.dt', function () {
            table_barang.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();


		/*get_barang();*/
		get_motifket();
		get_kualitas();

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

		
	})

	function get_motifket(){
		$.ajax({
			url: "{{ url('upah_tenun/get_motifket') }}",
			type: 'get',
			dataType: 'json',
			success: function(result){
				if(result.status == 1){
					$("[name=popup_motif]").html('');
					$("[name=popup_motif]").append('<option value="" kode="">--- Pilih Motif ---</option>');
					for(i in result.data){
						$("[name=popup_motif]").append('<option value="'+result.data[i].id_motif+'" nama="'+result.data[i].nama_motif+'">'+result.data[i].nama_motif+'</option>');
					}
				}
			}
		})
	}

	function get_kualitas(){
		$.ajax({
			url: "{{ url('upah_tenun/get_kualitas') }}",
			type: 'get',
			dataType: 'json',
			success: function(result){
				if(result.status == 1){
					$("[name=popup_pengurangan3]").html('');
					$("[name=popup_pengurangan3]").append('<option value="" kode="">--- Pilih Kualitas ---</option>');
					for(i in result.data){
						$("[name=popup_pengurangan3]").append('<option value="'+result.data[i].id_kualitas+'" nama="'+result.data[i].nama_kualitas+'">'+result.data[i].nama_kualitas+'</option>');
					}
				}
			}
		})
	}

	
	$("#btn_popup_simpan").click(function(){
		var id_data = $("[name=popup_id_table]").val();
		var id_motif = $("[name=popup_motif").val();
		var nama_motif = $("[name=popup_motif] :selected").attr('nama');
		var nominal = $("[name=popup_nominal]").val();
		var tabungan = $("[name=popup_tabungan]").val();
		var penambahan1 = $("[name=popup_penambahan1]").val();
		var penambahan2 = $("[name=popup_penambahan2]").val();
		var penambahan3 = $("[name=popup_penambahan3]").val();
		var pas = $('[name=popup_pas]').val();
		var pengurangan1 = $('[name=popup_pengurangan1]').val();
		var pengurangan2 = $('[name=popup_pengurangan2]').val();
		var pengurangan3 = $('[name=popup_pengurangan3]').val();
		var nama_pengurangan3 = $('[name=popup_pengurangan3] :selected').attr('nama');
		if(id_motif != '' && nominal != '' && tabungan != '' && penambahan1 != '' && penambahan2 != ''
		&& penambahan3 != '' && pas != '' && pengurangan1 != '' && pengurangan2 != '' && pengurangan3 != ''){
			if(id_data == ''){
				table_barang.row.add(['<div><center></center></div>',
					'<div id="list_motif'+tb_no+'">'+nama_motif+'</div>',
					'<div id="list_nominal'+tb_no+'">'+curr(nominal)+'</div>',
					'<div id="list_tabungan'+tb_no+'">'+curr(tabungan)+'</div>',
					'<div id="list_penambahan1'+tb_no+'">'+penambahan1+'</div>',
					'<div id="list_penambahan2'+tb_no+'">'+penambahan2+'</div>',
					'<div id="list_penambahan3'+tb_no+'">'+penambahan3+'</div>',
					'<div id="list_pas'+tb_no+'">'+pas+'</div>',
					'<div id="list_pengurangan1'+tb_no+'">'+pengurangan1+'</div>',
					'<div id="list_pengurangan2'+tb_no+'">'+pengurangan2+'</div>',
					'<div id="list_pengurangan3'+tb_no+'">'+nama_pengurangan3+'</div>',
					'<div><button type="button" class="btn btn-xs bg-warning-400" onclick="edit_table('+tb_no+')"><i class="icon-pencil"></i> </button> <button class="btn btn-xs bg-danger-800" type="button" onclick="hapus($(this))"><i class="icon-eraser"></i></button></div>'+
					'<input type="hidden" name="tabel_id[]" id="tabel_id'+tb_no+'" value="">'+
					'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+tb_no+'" value="'+id_motif+'">'+
					'<input type="hidden" name="tabel_nominal[]" id="tabel_nominal'+tb_no+'" value="'+nominal+'">'+
					'<input type="hidden" name="tabel_tabungan[]" id="tabel_tabungan'+tb_no+'" value="'+tabungan+'">'+
					'<input type="hidden" name="tabel_penambahan1[]" id="tabel_penambahan1'+tb_no+'" value="'+penambahan1+'">'+
					'<input type="hidden" name="tabel_penambahan2[]" id="tabel_penambahan2'+tb_no+'" value="'+penambahan2+'">'+
					'<input type="hidden" name="tabel_penambahan3[]" id="tabel_penambahan3'+tb_no+'" value="'+penambahan3+'">'+
					'<input type="hidden" name="tabel_pas[]" id="tabel_pas'+tb_no+'" value="'+pas+'">'+
					'<input type="hidden" name="tabel_pengurangan1[]" id="tabel_pengurangan1'+tb_no+'" value="'+pengurangan1+'">'+
					'<input type="hidden" name="tabel_pengurangan2[]" id="tabel_pengurangan2'+tb_no+'" value="'+pengurangan2+'">'+
					'<input type="hidden" name="tabel_pengurangan3[]" id="tabel_pengurangan3'+tb_no+'" value="'+pengurangan3+'">'
					]).draw(false);
			}else{
				$("#list_motif"+id_data).text(nama_motif);
				$("#list_nominal"+id_data).text(curr(nominal));
				$("#list_tabungan"+id_data).text(curr(tabungan));
				$("#list_penambahan1"+id_data).text(penambahan1);
				$("#list_penambahan2"+id_data).text(penambahan2);
				$("#list_penambahan3"+id_data).text(penambahan3);
				$("#list_pas"+id_data).text(pas);
				$("#list_pengurangan1"+id_data).text(pengurangan1);
				$("#list_pengurangan2"+id_data).text(pengurangan2);
				$("#list_pengurangan3"+id_data).text(nama_pengurangan3);

				$("#tabel_id"+id_data).val(id_data);
				$("#tabel_idmotif"+id_data).val(id_motif);				
				$("#tabel_nominal"+id_data).val(nominal);
				$("#tabel_tabungan"+id_data).val(tabungan);
				$("#tabel_penambahan1"+id_data).val(penambahan1);
				$("#tabel_penambahan2"+id_data).val(penambahan2);
				$("#tabel_penambahan3"+id_data).val(penambahan3);
				$("#tabel_pas"+id_data).val(pas);
				$("#tabel_pengurangan1"+id_data).val(pengurangan1);
				$("#tabel_pengurangan2"+id_data).val(pengurangan2);
				$("#tabel_pengurangan3"+id_data).val(pengurangan3);
			}

			$("#exampleModal").modal('hide');
			tb_no++;
			get_jum();
		}
	//	console.log(id_barang+"\n"+nama_barang+"\n"+jumlah+"\n"+harga);
	})

	function edit_table(id){

		var id_motif = $("#tabel_idmotif"+id).val();
		var nominal = $("#tabel_nominal"+id).val();
		var tabungan = $("#tabel_tabungan"+id).val();
		var penambahan1 = $("#tabel_penambahan1"+id).val();
		var penambahan2 = $("#tabel_penambahan2"+id).val();
		var penambahan3 = $("#tabel_penambahan3"+id).val();
		var pas = $("#tabel_pas"+id).val();
		var pengurangan1 = $("#tabel_pengurangan1"+id).val();
		var pengurangan2 = $("#tabel_pengurangan2"+id).val();
		var pengurangan3 = $("#tabel_pengurangan3"+id).val();
		

		$("[name=popup_id_table]").val(id);
		$("[name=popup_motif]").val(id_motif).trigger('change');
		$("[name=popup_nominal]").val(nominal);
		$("[name=popup_tabungan]").val(tabungan);
		$("[name=popup_penambahan1]").val(penambahan1);
		$("[name=popup_penambahan2]").val(penambahan2);
		$("[name=popup_penambahan3]").val(penambahan3);
		$("[name=popup_pas]").val(pas);
		$("[name=popup_pengurangan1]").val(pengurangan1);
		$("[name=popup_pengurangan2]").val(pengurangan2);
		$("[name=popup_pengurangan3]").val(pengurangan3).trigger('change');
		
		$("#help_popup_nominal").text(curr(nominal));
		$("#help_popup_tabungan").text(curr(tabungan));

		$("#exampleModal").modal('show');
	}

	function get_jum(){
		var jum = parseInt(0);
		$('input[id^="tabel_total"]').each(function() {
              // alert($(this).val());
              var val = ($(this).val());
              jum += parseInt(val);
              
            });
		$("#td_total").text(curr(jum));
		$("[name=td_total]").val(jum);
		netto();
	}


	$("[name=popup_nominal]").keyup(function(){
		var rp = curr($("[name=popup_nominal]").val());
		$("#help_popup_nominal").text(rp);
		netto();
	});
	$("[name=popup_tabungan]").keyup(function(){
		var rp = curr($("[name=popup_tabungan]").val());
		$("#help_popup_tabungan").text(rp);
		netto();
	})

	

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

	function netto(){
		var total = parseInt($("[name=td_total]").val());
		var pot = parseInt($("[name=td_potongan]").val());
		var ppn = parseInt($("[name=td_pajak]").val());
		var ongkir = parseInt($("[name=td_ongkir]").val());
		var netto = parseInt(0);

		if(pot == '' || pot == 0 || isNaN(pot)){
			pot = parseInt(0);
		}
		if($('select[name=pajak]').val()==1){
			ppn = parseInt(total*10/100);
		}
		if(total == '' || total == 0 || isNaN(total)){
			total = parseInt(0);
		}

		if(ppn == '' || ppn == 0 || isNaN(ppn)){
			ppn = parseInt(0);
		}
		if(ongkir == '' || ongkir == 0 || isNaN(ongkir)){
			ongkir = parseInt(0);
		}
		netto = total-pot+ppn+ongkir; //+bunga
		$("#td_netto").text(curr(netto));
		$("[name=td_netto]").val(netto);
		$("[name=td_pajak]").val(ppn).keyup();
	//	console.log(total+"\n"+pot+"\n"+bunga+"\n"+netto);
	}

	function get_edit(id){
		$.ajax({
			url: "{{ url('upah_tenun/get_edit')}} ",
			type: 'post',
			data: {id : id,},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				if(respon.length > 0){
					for(i in respon){
						table_barang.row.add(['<div><center></center></div>',
							'<div id="list_motif'+respon[i].id_upahtenun_barang+'">'+respon[i].nama_motif+'</div>',
							'<div id="list_nominal'+respon[i].id_upahtenun_barang+'">'+curr(respon[i].nominal)+'</div>',
							'<div id="list_tabungan'+respon[i].id_upahtenun_barang+'">'+curr(respon[i].tabungan)+'</div>',
							'<div id="list_penambahan1'+respon[i].id_upahtenun_barang+'">'+respon[i].penambahan1+'</div>',
							'<div id="list_penambahan2'+respon[i].id_upahtenun_barang+'">'+respon[i].penambahan2+'</div>',
							'<div id="list_penambahan3'+respon[i].id_upahtenun_barang+'">'+respon[i].penambahan3+'</div>',
							'<div id="list_pas'+respon[i].id_upahtenun_barang+'">'+respon[i].pas+'</div>',
							'<div id="list_pengurangan1'+respon[i].id_upahtenun_barang+'">'+respon[i].pengurangan1+'</div>',
							'<div id="list_pengurangan2'+respon[i].id_upahtenun_barang+'">'+respon[i].pengurangan2+'</div>',
							'<div id="list_pengurangan3'+respon[i].id_upahtenun_barang+'">'+respon[i].nama_pengurangan3+'</div>',
							'<div><button type="button" class="btn btn-xs bg-warning-400" onclick="edit_table('+respon[i].id_upahtenun_barang+')"><i class="icon-pencil"></i> </button> <button class="btn btn-xs bg-danger-800" type="button" onclick="hapus($(this))"><i class="icon-eraser"></i></button></div>'+
							'<input type="hidden" name="tabel_id[]" id="tabel_id'+respon[i].id_upahtenun_barang+'" value="'+respon[i].id_upahtenun_barang+'">'+
							'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+respon[i].id_upahtenun_barang+'" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" name="tabel_nominal[]" id="tabel_nominal'+respon[i].id_upahtenun_barang+'" value="'+respon[i].nominal+'">'+
							'<input type="hidden" name="tabel_tabungan[]" id="tabel_tabungan'+respon[i].id_upahtenun_barang+'" value="'+respon[i].tabungan+'">'+
							'<input type="hidden" name="tabel_penambahan1[]" id="tabel_penambahan1'+respon[i].id_upahtenun_barang+'" value="'+respon[i].penambahan1+'">'+
							'<input type="hidden" name="tabel_penambahan2[]" id="tabel_penambahan2'+respon[i].id_upahtenun_barang+'" value="'+respon[i].penambahan2+'">'+
							'<input type="hidden" name="tabel_penambahan3[]" id="tabel_penambahan3'+respon[i].id_upahtenun_barang+'" value="'+respon[i].penambahan3+'">'+
							'<input type="hidden" name="tabel_pas[]" id="tabel_pas'+respon[i].id_upahtenun_barang+'" value="'+respon[i].pas+'">'+
							'<input type="hidden" name="tabel_pengurangan1[]" id="tabel_pengurangan1'+respon[i].id_upahtenun_barang+'" value="'+respon[i].pengurangan1+'">'+
							'<input type="hidden" name="tabel_pengurangan2[]" id="tabel_pengurangan2'+respon[i].id_upahtenun_barang+'" value="'+respon[i].pengurangan2+'">'+
							'<input type="hidden" name="tabel_pengurangan3[]" id="tabel_pengurangan3'+respon[i].id_upahtenun_barang+'" value="'+respon[i].pengurangan3+'">'
							]).draw(false);
					}

					get_jum();
					netto();
				}
				
			}
		})
	}


	function hapus(d){
		table_barang.row(d.parents('tr')).remove().draw();
		get_jum();
		netto();
		//  alert(d);
	}

	$("[name=popup_barang]").change(function(){
		var id_barang = $("[name=popup_barang]").val();
		
		$.ajax({
			url: "{{ url('pembelian/get_konversi')}} ",
			type: 'post',
			data: {id : id_barang},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				if(respon.length > 0){
					$("#div_konversi").removeClass('hide');

					$("#popup_satuanawal").text(respon[0].satuan_awal);
					$("#popup_satuanakhir").text(respon[0].satuan_akhir);
					var nilai = parseInt(respon[0].nilai_akhir)/parseInt(respon[0].nilai_awal);
					$("[name=store_konversi]").val(nilai);
				}else{
					$("#div_konversi").addClass('hide');
					$("[name=popup_jumlahakhir]").val('');
					$("#popup_satuanawal").text(respon.satuan_awal);
					$("#popup_satuanakhir").text('');				
				}
			}
		})
	})

	$("[name=popup_jumlah]").keyup(function(){
		var jum = parseInt($("[name=popup_jumlah]").val());
		if(isNaN(jum) || jum == 0 || jum == ''){
			jum = parseInt(0);
		}
		var nilai = parseInt($("[name=store_konversi]").val());

		var tot = jum*nilai;
		$("[name=popup_jumlahakhir]").val(tot);
	})

	
	function hapus_order(d){
		table_barang.row(d.parents('tr')).remove().draw();
		get_jum();
		netto();
		
	}

</script>

@endsection