@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 Baorongan</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Form Input Upah</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" id="form_submit" method="post" action="{{ url('upahproduksi/simpan_bayar') }}" autocomplete="off">
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_upahproduksi" value="{{ $data['data']['id_upahproduksi'] }}">
	    	<input type="hidden" name="spk" value="{{ $data['data']['id_workorder']}}">
	    	<input type="hidden" name="workorder" value="{{ $data['data']['id_workorder_barang']}}">
	    	<input type="hidden" name="id_barangkeluar" value="{{ $data['data']['id_barangkeluar']}}">
	    	<input type="hidden" name="id_proses" value="{{ $data['data']['id_proses']}}">
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Upah</label>
        			<div class="col-sm-8">         				
        				<select class="form-control select-search" name="jenis" required="" disabled="">
        					@php $sel = $data['data']['id_jenis']; @endphp
        					<option value="">--- Pilih Upah ---</option>
        					<option value="1" {{ ( "1" == $sel) ? "selected":""}}>Borongan</option>
        					<option value="2" {{ ( "2" == $sel) ? "selected":""}}>Harian</option>
        				</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" name="rekanan" id="rekanan" disabled>
        					<option value="">--- Pilih Rekanan ---</option>
        					@php $sel = $data['data']['id_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">Pegawai</label>
        			<div class="col-sm-8">        				
        				<select class="form-control select-search" name="pegawai" id="pegawai" disabled="">
        					<option value="">--- Pilih Pegawai ---</option>
        					@php $sel = $data['data']['id_pegawai'];
        					foreach($data['pegawai'] as $d){@endphp
        					<option value="{{$d->id_pegawai}}" {{ ($d->id_pegawai == $sel) ? "selected":""}}>{{$d->nama_pegawai}}</option>
        					@php } @endphp
        				</select>
        			</div>
        		</div>        		
        		<div class="form-group">
        			<label class="control-label col-sm-4">Proses Produksi</label>
        			<div class="col-sm-8">
        				<select class="form-control select-search" name="proses" required="" id="proses" disabled="">
        				</select>
        			</div>
        		</div>
        		<div class="form-group">
	    			<label class="control-label col-sm-4">Lokasi Produksi </label>
	    			<div class="col-sm-8">
	    				<select class="form-control select-search" name="id_jenis" disabled="">
	    					<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 Bayar</label>
        			<div class="col-sm-8">
        				<input class="form-control datepicker" type="text" name="tanggal" placeholder="Tanggal" value="<?= date('d-m-Y') ?>" required/>
        			</div>
        		</div>
                <div class="form-group">
                    <label class="control-label col-sm-4">Akun Bayar</label>
                    <div class="col-sm-8">                      
                        <select class="form-control select-search" name="akun_bayar" required>
                            <?php foreach ($data['akun2'] as $key => $value) { ?>
                                <option value="<?= $key ?>"><?= $value ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Jumlah Bayar</label>
        			<div class="col-sm-8">
        				<input type="hidden" name="jumlah_bayar" id="jumlah_bayar" value="0">
        				<input class="form-control" type="text" name="txt_jumlah_bayar" placeholder="" value="" id="txt_jumlah_bayar" readonly />
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">PPN</label>
        			<div class="col-sm-8">
        				<select class="form-control select-search" name="pajak" disabled>
							<option value="0" @if($data['data']['pajak'] == 0) selected @endif>Tidak</option>
							<option value="1" @if($data['data']['pajak'] == 1) selected @endif>Iya</option>
						</select>
        				{{-- <input class="form-control" type="text" name="ppn" placeholder="" value="" id="ppn" /> --}}
        			</div>
        		</div>
        	</div>
        	<?php if ($data['jenis_trx']==2){ ?>
        	
        	<div class="col-sm-12 form-group">
        		<h5>Laporan Hasil</h5>
        		<table class="table table-striped" id="table_hasil">
        			<thead>
        				<tr>
        					<th>No</th>
							<th>Kode Barang</th>
							<th>Nama Barang</th>
							<th>Warna</th>
							<th>Jumlah</th>
							<th>Satuan</th>
							<th>Gudang</th>
							<th>Corak</th>
							<th>Motif</th>
							<th>Kualitas</th>
							<th>Dudulan</th>
							<th>Label</th>
							<th>Kemasan</th>
							<th>Kemasan Satuan</th>
							<th>Kemasan 10 Potong</th>
							<th>Kemasan Dus Ball</th>
        				</tr>
        			</thead>
        			<tbody>
        				
        			</tbody>
        		</table>
        	</div>
        <?php } else if($data['jenis_trx']==1) {?>

        	<div class="col-sm-12 form-group">
        		<h5>Hasil</h5>
                @if($data['data']['id_proses'] == 37)
                <table class="table table-striped" id="table_hasil">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>Kode Barang</th>
                            <th>Nama Barang</th>
                            <th>Corak</th>
                            <th>Motif</th>
                            <th>Jumlah</th>
                            <th>Upah</th>
                            <th>Pick</th>
                            <th>Total</th>                          
                        </tr>
                    </thead>
                    <tbody>
                        
                    </tbody>
                    <tfoot>
                        <tr>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th></th>
                            <th>Sub Total</th>
                            <th></th>
                            <th></th>
                            <th><p type="text" name="sub_total" id="sub_total1" disabled="true" value="0"></p></th>
                        </tr>
                    </tfoot>
                </table>
                @else
        		<table class="table table-striped" id="table_hasil">
        			<thead>
        				<tr>
        					<th>No</th>
							<th>Kode Barang</th>
							<th>Nama Barang</th>
                            <th>Corak</th>
                            <th>Motif</th>
							<th>Jumlah</th>
							<th>Upah</th>
							<th>Total</th>							
        				</tr>
        			</thead>
        			<tbody>
        				
        			</tbody>
        			<tfoot>
        				<tr>
        					<th></th>
        					<th></th>
                            <th></th>
                            <th></th>
        					<th>Sub Total</th>
        					<th></th>
        					<th></th>
        					<th><p type="text" name="sub_total" id="sub_total1" disabled="true" value="0"></p></th>
        				</tr>
        			</tfoot>
        		</table>
                @endif
        	</div>

        <?php } 
        if ($data['jenis_trx']==2){ ?>
        	<div class="col-sm-12 form-group">
        		<h5>Upah</h5>
        		<table class="table table-striped" id="table_upah">
        			<thead>
        				<tr>
        					<th>No.</th>
        					<th>Keterangan</th>
        					<th>Motif</th>
        					<th>Nominal (Rupiah)</th>
        				</tr>
        			</thead>
        			<tbody>
        				
        			</tbody>
        		</table>
        	</div>
        <?php } else if($data['jenis_trx']==1){ ?>
        <div class="col-sm-12 form-group"> 
        	<h5>Lain Lain</h5>        	
        		<!-- <a class="btn btn-success" id="btn_tambah_item_lain_lain">Tambah</a>   -->
        		<table class="table table-striped" id="table_lain2">
        			<thead>
        				<tr>
        					<th>No.</th>
							<th>Jenis</th>
							<th>Jumlah</th>					
        				</tr>
        			</thead>
        			<tbody>
        				
        			</tbody>
        			<tfoot>
        				<tr>
        					<th></th>
        					<th>Sub Total</th>
        					<th><p id="sub_total2">0</p></th>
        				</tr>
                        <tr>
                            <th></th>
                            <th></th>
                            <th></th>
                        </tr>
                        <tr>
                            <th></th>
                            <th>PPN</th>
                            <th><p id="ppn">0%</p></th>
                        </tr>
                        <tr>
                            <th></th>
                            <th>Total Upah</th>
                            <th><p id="total_upah">0</p></th>
                        </tr>
        			</tfoot>
        		</table>
        	</div>
        <?php } ?>
        	
        	<div class="col-sm-12">
        	<a href="{{url('upahproduksi')}}" class="btn bg-warning-400">Kembali</a>
            <div class="form-group pull-right">
             	<button class="btn btn-primary" type="submit" id="btn_simpan">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>

<!---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">Keterangan</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_keterangan">	      						
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Kode Perkiraan</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_perkiraan">
	      						
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Satuan</label>
	      				<div class="col-sm-5">
	      					<input type="text" class="form-control col-sm-6" name="popup_satuan">
	      				</div>
	      				<div class="col-sm-3">
	      					<select class="form-control select-search" name="popup_satuan_waktu">
	      						
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Gaji Satuan</label>
	      				<div class="col-sm-8">
	      					<input type="text" class="form-control number-only" name="popup_upah">
	      					<p class="pull-right" id="help_popup_upah"></p>
	      				</div>
	      			</div>
	      		</form>
	      	</div>
	      	<h5 id="alert_workorder"></h5>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>


<div class="modal fade" id="exampleModal2" 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_lain_lain">
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jenis</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="jenis_lain_lain" class="form-control" id="jenis_lain_lain">
	      					<!-- <select class="form-control select-search" name="popup_keterangan">	      						
	      					</select> -->
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Upah</label>
	      				<div class="col-sm-8">
	      					<input type="text" id="upah_lain_lain" name="upah_lain_lain" class="form-control number-only">
	      					<p class="pull-right" id="help_popup_upah_lain_lain"></p>
	      					<!-- <select class="form-control select-search" name="popup_perkiraan">	      						
	      					</select> -->
	      				</div>
	      			</div>	      			
	      		</form>
	      	</div>
	      	<h5 id="alert_workorder"></h5>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan_lain_lain">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>


<!-- EndModal -->

<input type="hidden" name="store_konversi">


<script type="text/javascript">
    var total_gaji=0;
    var total_lain_2=0;


	$("#btn_tambah_item").click(function(){
		$("[name=popup_id_table]").val('');
		$("[name=popup_keterangan]").val(null).trigger('change');
		$("[name=popup_perkiraan]").val(null).trigger('change');
		$("[name=popup_satuan]").val('');
		$("[name=popup_satuan_waktu]").val(null).trigger('change');
		$("[name=popup_upah]").val('');
		$("#exampleModal").modal('show');
	})
	$("#btn_tambah_item_lain_lain").click(function(){
		$("[name=popup_id_table_lain_lain]").val('');
		$("#jenis_lain_lain").val('');
		$("#upah_lain_lain").val('');
		$("#help_popup_upah_lain_lain").text('');
		$("#exampleModal2").modal('show');

	})
	$("#upah_lain_lain").keyup(function(){
		var rp=curr($("#upah_lain_lain").val());
		$("#help_popup_upah_lain_lain").text(rp);
	});

	$("[name=popup_upah]").keyup(function(){
		var rp = curr($("[name=popup_upah]").val());
		$("#help_popup_upah").text(rp);
	});

        
	

	var table_barang;
	var table_hasil;
	var table_upah;
	var table_lain2;
	var tb_no = parseInt(10000);
	var tb_no_ll= parseInt(10000);
	var nama_transaksi= <?php echo $data['jenis_trx'] ?>;

	$(document).ready(function(){
		table_hasil = $("#table_hasil").DataTable({
        	"paging": false
        });
		table_hasil.on( 'order.dt search.dt', function () {
            table_hasil.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();
        table_lain2 = $("#table_lain2").DataTable({
        	"paging": false
        })
        table_lain2.on('order.dt search.dt',function(){
        	table_lain2.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();
        table_upah = $("#table_upah").DataTable({
        	"paging": false
        });
		table_upah.on( 'order.dt search.dt', function () {
            table_upah.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();
		table_barang = $("#table_barang").DataTable({});
		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();

        var id = "{{$data['data']['id_upahproduksi']}}";
        var c_rekanan 	= "{{$data['data']['id_rekanan']}}";
        var c_pegawai 	= "{{$data['data']['id_pegawai']}}";
        var c_proses  	= "{{$data['data']['id_proses']}}";
        var c_barangmasuk  	= "{{$data['data']['id_barangmasuk']}}";
        var c_jenis 	= "{{$data['data']['id_jenis']}}"; 
        // console.log(c_jenis+' - '+c_rekanan+' - '+c_pegawai);
        if(id != ''){
        	get_edit(id);
        	if(c_rekanan != '' || c_rekanan != 0){
        		var FunctionOne = function (){        		
        		var r = $.Deferred();
				 $("[name=jenis]").val(c_jenis).trigger('change');
				 $("[name=rekanan]").val(c_rekanan).trigger('change');
					disabled('[name=rekanan]', true);
				  setTimeout(function () {
				    r.resolve();
				  }, 4000);
				  return r;
        		}
        		var FunctionTwo = function () {
        			$("[name=proses]").val(c_barangmasuk).trigger('change');   
				};

				FunctionOne().done(FunctionTwo);
        	}else{

        		var FunctionOne = function (){        		
        		var r = $.Deferred();
        		 $("[name=jenis]").val(c_jenis).trigger('change');
				 $("[name=pegawai]").val(c_pegawai).trigger('change');
				 
				  setTimeout(function () {
				    r.resolve();
				  }, 3000);
				  return r;
        		}
        		var FunctionTwo = function () {
        			$("[name=proses]").val(c_proses).trigger('change');   
				};
				FunctionOne().done(FunctionTwo);
        	}

			     	
        	
        }else{
        	var id_tabel= <?php echo $data['id_tabel']; ?>;
        	if(id_tabel==1){
        		get_by_id();
	        }else{
	        	get_by_id_barang_masuk();
	        }
        }

        get_satuan();
        get_ket();
        get_perkiraan();

        var pegawai = $("[name=pegawai]").val();
		if(pegawai > 0){

		$("[name=rekanan]").val('').trigger('change');
			disabled('[name=rekanan]', true);				
		}else{
			disabled('[name=rekanan]', false);
		}

		var rekanan = $("[name=rekanan]").val();
		if(rekanan > 0){
			$("[name=pegawai]").val('').trigger('change');
			disabled('[name=pegawai]',true);	
		}else{
			disabled('[name=pegawai]',false);
		}

        
	})

	$("[name=pegawai]").change(function(){
		var pegawai = $("[name=pegawai]").val();
		if(pegawai > 0){
			disabled('[name=rekanan]', true);
			
		}else{
			disabled('[name=rekanan]', false);
			$("[name=proses]").val(null).trigger('change');
		}
		get_proses();
	});

	$("[name=rekanan]").change(function(){
		var rekanan = $("[name=rekanan]").val();		
		if(rekanan > 0){
			disabled('[name=pegawai]',true);
			
		}else{
			disabled('[name=pegawai]',false);
			$("[name=proses]").val(null).trigger('change');
		}
		get_proses();
	});

	/*$("[name=jenis]").change(function(){
		var jenis = $(this).val();
		if(jenis != '' || jenis != 0 || !isNaN(jenis)){
			if(jenis == '1'){
			$("#tanggal_harian").addClass('hidden');
			}else if(jenis == '2'){
			$("#tanggal_harian").removeClass('hidden');
			}else{
			$("#tanggal_harian").addClass('hidden');	
			}
		}
	})
*/
	

	$("[name=proses]").change(function(){
		var id_barangmasuk = $(this).val();
		var id_barangkeluar = $("[name=proses] :selected").attr('barangkeluar');
		var id_workorder = $("[name=proses] :selected").attr('spk');
		var id_workorder_barang = $("[name=proses] :selected").attr('workorder');
		var id_proses = $("[name=proses] :selected").attr('proses');
		var id_rekanan = $("[name=rekanan]").val();
		var id_pegawai = $("[name=pegawai]").val();
		var id_jenis = $("[name=jenis]").val();

		$("[name=id_barangkeluar").val(id_barangkeluar);
		$("[name=spk").val(id_workorder);
		$("[name=workorder").val(id_workorder_barang);
		$("[name=id_proses").val(id_proses);
		var id_lain2= <?php echo $data['id_trans']; ?>;

		// console.log(id_jenis+' - '+id_rekanan+' - '+id_pegawai);


		if(id_rekanan != '' || id_rekanan != 0){
				// console.log(id_jenis+' - '+id_rekanan+' - '+id_pegawai+' rekanan');
			$.ajax({
				url: "{{ url('upahproduksi/get_rekanan')}} ",
				type: 'post',
				data: {id_barangmasuk : id_barangmasuk, id_barangkeluar : id_barangkeluar, id_workorder : id_workorder, id_workorder_barang : id_workorder_barang, id_proses : id_proses, id_rekanan : id_rekanan, id_pegawai : '', id_jenis : id_jenis, id_upah_borongan : id_lain2,},
				headers : {
					'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
				},
				success: function(respon){
					table_hasil.clear().draw();
					table_upah.clear().draw();
					if(respon.status_hasil == 1){
						if(nama_transaksi==2){
							for(i in respon.hasil){
								table_hasil.row.add(['<div><center></center></div>',
									'<div id="list_kode'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].kode_barang+'</div>',
									'<div id="list_nama'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_barang+'</div>',
									'<div id="list_komposisi'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_komposisi+'</div>',
									'<div id="list_jumlah'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].jumlah+'</div>',
									'<div id="list_namasatuan'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_satuan+'</div>',
									'<div id="list_gudang'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_gudang+'</div>',
									'<div id="list_corak'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].motif_keterangan+'</div>',
									'<div>'+respon.hasil[i].nama_motif+'</div>',
									'<div>'+respon.hasil[i].nama_kualitas+'</div>',
									'<div>'+respon.hasil[i].kualitas_dudul+'</div>',
									'<div>'+respon.hasil[i].nama_label+'</div>',
									'<div>'+respon.hasil[i].nama_kemasan+'</div>',
									'<div>'+respon.hasil[i].nama_kemasansatuan+'</div>',
									'<div>'+respon.hasil[i].nama_kemasansepuluh+'</div>',
									'<div>'+respon.hasil[i].nama_kemasanseratus+'</div>'
									]).draw(false);
								}
						}else{
							var sub_total1=0;
							for(i in respon.hasil){

								var upah= parseFloat(respon.hasil[i].upah);
                                var pick = 0;
                                var idBarang = respon.hasil[i].id_barang || 0;
                                var idMotif = respon.hasil[i].id_motif || 0;
                                var idMotifBarang = respon.hasil[i].id_motif_barang || 0;
                                var idProses = respon.hasil[i].id_proses || 0;
                                
                                for(j in respon.upah_bayar){
                                    if(respon.upah_bayar[j].id_proses==idProses && respon.upah_bayar[j].id_barang==idBarang && respon.upah_bayar[j].id_motif_barang==idMotifBarang && respon.upah_bayar[j].id_motif==idMotif && respon.hasil[i].id==respon.upah_bayar[j].id_pbb){
                                        upah = parseFloat(respon.upah_bayar[j].upah_satuan);
                                        pick = parseFloat(respon.upah_bayar[j].upah_pick);
                                    }
                                }
								//alert(isNaN(upah));
								if (isNaN(upah)){
									upah=0;
								}
								var jumlah=parseFloat(respon.hasil[i].jumlah);
								var total_upah= (upah*jumlah)+(pick*jumlah);
								sub_total1 +=total_upah;
								table_hasil.row.add(['<div><center></center></div>',
									'<div id="list_kode'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].kode_barang+'</div>',
									'<div id="list_nama'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_barang+'</div>',
                                    '<div id="list_nama'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_motif+'</div>',
                                    '<div id="list_nama'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].motif_keterangan+'</div>',
									'<div id="list_jumlah'+i+'">'+respon.hasil[i].jumlah+'</div>',
									'<div><p type="text" id="list_upah'+i+'" disabled="true"'+
									// 'onkeyup="get_total_upah(num='+i+',jumlah='+respon.hasil[i].jumlah+',banyak='+respon.hasil.length+')"'+
									'">'+curr(upah)+'</p></div>',
                                    '<div><p type="text" id="list_upah_pick'+i+'" disabled="true"'+
                                    '">'+curr(pick)+'</p></div>',
									'<div id="list_upah_total'+respon.hasil[i].id_masuk+'"><p type="text" id="list_upah_total'+i+'" disabled="true"">'+curr(total_upah)+'</p></div>',
									]).draw(false);

							}
                            total_gaji +=sub_total1;
							$("#sub_total1").text(curr(sub_total1));
                            set_sub_total_lain2();
                            set_total_upah();
						}

					}else{
							table_hasil.clear().draw();	
					}

					if(respon.status_upah == 1){
						if(respon.s_upah == 1){
						for(i in respon.upah){
							var keterangan = '';
							var motif = '';
							if(respon.upah[i].id_barang != '' || respon.upah[i].id_barang != 0){
								var keterangan = respon.upah[i].kode_barang+' - '+respon.upah[i].nama_barang; 
							}

							if(respon.upah[i].id_motif_barang != '' || respon.upah[i].id_motif_barang != 0){
								var motif_barang = respon.upah[i].motif_keterangan; 
							}

							table_upah.row.add(['<div><center></center></div>',
								'<div>'+keterangan+'</div>',
								'<div>'+respon.upah[i].motif_keterangan+'</div>',
								'<div>'+respon.upah[i].nominal+'</div>'
								]).draw(false);
						}

						}else{
							for(i in respon.upah){	
							table_upah.row.add(['<div><center></center></div>',
								'<div>Gaji Harian</div>',
								'<div></div>',
								'<div>'+curr(respon.upah[i].upah_harian)+'/Hari </div>'
								]).draw(false);
							}

							for(i in respon.upah){	
							table_upah.row.add(['<div><center></center></div>',
								'<div>Gaji Lembur</div>',
								'<div></div>',
								'<div>'+curr(respon.upah[i].upah_lembur)+'/Jam </div>'
								]).draw(false);
							}
						}

					}else{
							table_upah.clear().draw();	
					}
					if(respon.status_lain2==1){
						table_lain2.clear().draw();
						for(i in respon.lain2){
							table_lain2.row.add(['<div><center>'+no+'</center></div>',
								'<div id="list_jenis'+respon.lain2[i].id_upah+'">'+respon.lain2[i].jenis+'</div>',
								'<div id="list_upah'+respon.lain2[i].id_upah+'">'+curr(respon.lain2[i].jumlah)+'</div>'+
								// '<div><button type="button" class="btn bg-warning-400" onclick="edit_tablell('+respon.lain2[i].id_upah+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapusll(d=$(this))"><i class="icon-eraser"></i></button></div>'+
								'<input type="hidden" id="tabel_id2'+respon.lain2[i].id_upah+'" name="tabel_id2[]" value="'+respon.lain2[i].id_upah+'">'+
								'<input type="hidden" id="tabel_jenis'+respon.lain2[i].id_upah+'" name="tabel_jenis[]" value="'+respon.lain2[i].jenis+'">'+
								'<input type="hidden" id="tabel_upah'+respon.lain2[i].id_upah+'" name="tabel_upahll[]" value="'+respon.lain2[i].jumlah+'">'+
								'<input type="hidden" id="tabel_upah'+tb_no_ll+'" value="'+respon.lain2[i].jumlah+'">',
								]).draw(false);
							tb_no_ll++;
							set_sub_total_lain2();
                            set_total_upah();
						}
					}else{
						table_lain2.clear().draw();
					}
				}
			})

			}else{
				// console.log(id_jenis+' - '+id_rekanan+' - '+id_pegawai+' pegawai');
				$.ajax({
				url: "{{ url('upahproduksi/get_pegawai')}} ",
				type: 'post',
				data: {id_barangmasuk : id_barangmasuk, id_barangkeluar : id_barangkeluar, id_workorder : id_workorder, id_workorder_barang : id_workorder_barang, id_proses : id_proses, id_rekanan : '', id_pegawai : id_pegawai, id_jenis : id_jenis, id_upah_borongan : id_lain2 },
				headers : {
					'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
				},
				success: function(respon){
					table_hasil.clear().draw();	
					table_upah.clear().draw();	
					if(respon.status_hasil == 1){
						if(nama_transaksi==2){
							for(i in respon.hasil){
								table_hasil.row.add(['<div><center></center></div>',
									'<div id="list_kode'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].kode_barang+'</div>',
									'<div id="list_nama'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_barang+'</div>',
									'<div id="list_komposisi'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_komposisi+'</div>',
									'<div id="list_jumlah'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].jumlah+'</div>',
									'<div id="list_namasatuan'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_satuan+'</div>',
									'<div id="list_gudang'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_gudang+'</div>',
									'<div id="list_corak'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].motif_keterangan+'</div>',
									'<div>'+respon.hasil[i].nama_motif+'</div>',
									'<div>'+respon.hasil[i].nama_kualitas+'</div>',
									'<div>'+respon.hasil[i].kualitas_dudul+'</div>',
									'<div>'+respon.hasil[i].nama_label+'</div>',
									'<div>'+respon.hasil[i].nama_kemasan+'</div>',
									'<div>'+respon.hasil[i].nama_kemasansatuan+'</div>',
									'<div>'+respon.hasil[i].nama_kemasansepuluh+'</div>',
									'<div>'+respon.hasil[i].nama_kemasanseratus+'</div>'
									]).draw(false);
                                set_sub_total_lain2();
                                set_total_upah();
							}
						}else{
							var sub_total1=0;
							for(i in respon.hasil){
								var upah= parseFloat(respon.hasil[i].upah);
                                var idBarang = respon.hasil[i].id_barang || 0;
                                var idMotif = respon.hasil[i].id_motif || 0;
                                var idMotifBarang = respon.hasil[i].id_motif_barang || 0;
                                var idProses = respon.hasil[i].id_proses || 0;
                                
                                for(j in respon.upah_bayar){

                                    if(respon.upah_bayar[j].id_proses==idProses && respon.upah_bayar[j].id_barang==idBarang && respon.upah_bayar[j].id_motif_barang==idMotifBarang && respon.upah_bayar[j].id_motif==idMotif && respon.hasil[i].id==respon.upah_bayar[j].id_pbb){
                                        upah = parseFloat(respon.upah_bayar[j].upah_satuan);
                                    }
                                }
								//alert(isNaN(upah));
								if (isNaN(upah)){
									upah=0;
								}
								var jumlah=parseFloat(respon.hasil[i].jumlah);
								var total_upah= upah*jumlah;
								sub_total1 +=total_upah;
								table_hasil.row.add(['<div><center></center></div>',
									'<div id="list_kode'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].kode_barang+'</div>',
									'<div id="list_nama'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_barang+'</div>',
                                    '<div id="list_nama'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].nama_motif+'</div>',
                                    '<div id="list_nama'+respon.hasil[i].id_masuk+'">'+respon.hasil[i].motif_keterangan+'</div>',
									'<div id="list_jumlah'+i+'">'+respon.hasil[i].jumlah+'</div>',
									'<div><p type="text" id="list_upah'+i+'" disabled="true"'+
									// 'onkeyup="get_total_upah(num='+i+',jumlah='+respon.hasil[i].jumlah+',banyak='+respon.hasil.length+')"'+
									'">'+curr(upah)+'</p></div>',
									'<div id="list_upah_total'+respon.hasil[i].id_masuk+'"><p type="text" id="list_upah_total'+i+'" disabled="true"">'+curr(total_upah)+'</p></div>',
									]).draw(false);

							}
                            total_gaji +=sub_total1;
							$("#sub_total1").text(curr(sub_total1));
                            set_sub_total_lain2();
                            set_total_upah();
						}

					}else{
							table_hasil.clear().draw();	
					}

					if(respon.status_upah == 1){
						if(respon.s_upah == 1){
						for(i in respon.upah){
							var barang = '';
							var motif = '';
							if(respon.upah[i].id_barang != '' || respon.upah[i].id_barang != 0){
								var barang = respon.upah[i].kode_barang+' - '+respon.upah[i].nama_barang; 
							}

							if(respon.upah[i].id_motif_barang != '' || respon.upah[i].id_motif_barang != 0){
								var motif_barang = respon.upah[i].motif_keterangan; 
							}

							table_upah.row.add(['<div><center></center></div>',
								'<div>'+barang+'</div>',
								'<div>'+respon.upah[i].motif_keterangan+'</div>',
								'<div>'+respon.upah[i].nominal+'</div>'
								]).draw(false);
						}
					}else{
							for(i in respon.upah){	
							table_upah.row.add(['<div><center></center></div>',
								'<div>Gaji Harian</div>',
								'<div></div>',
								'<div>'+curr(respon.upah[i].upah_harian)+'/Hari </div>'
								]).draw(false);
							}

							for(i in respon.upah){	
							table_upah.row.add(['<div><center></center></div>',
								'<div>Gaji Lembur</div>',
								'<div></div>',
								'<div>'+curr(respon.upah[i].upah_lembur)+'/Jam </div>'
								]).draw(false);
							}
						}

					}else{
							table_upah.clear().draw();	
					}
					if(respon.status_lain2==1){
						table_lain2.clear().draw();
						for(i in respon.lain2){
							table_lain2.row.add(['<div><center>'+no+'</center></div>',
								'<div id="list_jenis'+respon.lain2[i].id_upah+'">'+respon.lain2[i].jenis+'</div>',
								'<div id="list_upah'+respon.lain2[i].id_upah+'">'+curr(respon.lain2[i].jumlah)+'</div>'+
								// '<div><button type="button" class="btn bg-warning-400" onclick="edit_tablell('+respon.lain2[i].id_upah+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapusll(d=$(this))"><i class="icon-eraser"></i></button></div>'+
								'<input type="hidden" id="tabel_id2'+respon.lain2[i].id_upah+'" name="tabel_id2[]" value="'+respon.lain2[i].id_upah+'">'+
								'<input type="hidden" id="tabel_jenis'+respon.lain2[i].id_upah+'" name="tabel_jenis[]" value="'+respon.lain2[i].jenis+'">'+
								'<input type="hidden" id="tabel_upah'+respon.lain2[i].id_upah+'" name="tabel_upahll[]" value="'+respon.lain2[i].jumlah+'">'+
								'<input type="hidden" id="tabel_upah'+tb_no_ll+'" value="'+respon.lain2[i].jumlah+'">',
								]).draw(false);
							tb_no_ll++;
							set_sub_total_lain2();
                            set_total_upah();
						}
					}else{
						table_lain2.clear().draw();
					}

					
				}
			})


		}
		

		


	}) 
	// $( "#nomor" ).keyup(function() {
	//   alert($( "#nomor" ).val());
	// });
	function get_total_upah(id,jumlah,banyak){
		var upah=$("#list_upah"+num).val();
		var total=jumlah*upah;
		var sub_total=0
		$("#list_upah_total"+num).val(total);
		for(var i=0;i<banyak;i++){
			sub_total += parseFloat($("#list_upah_total"+i).val());
		}
		$("#sub_total1").val(sub_total);
		
	}
	function set_sub_total_lain2(){
		var sub_total2=0;
		for(var i=10000;i<=tb_no_ll;i++){
			var data=parseFloat($("#tabel_upah"+i).val());
			if(!isNaN(data)){
				sub_total2 += data;
				// console.log(id_terakhir);
			}
		}
        total_lain_2= sub_total2;
		$("#sub_total2").text(curr(sub_total2));
	}

	function get_proses(){
		var rekanan = $("[name=rekanan]").val();
		var pegawai = $("[name=pegawai]").val();

		var id_jenis = $("[name=jenis]").val();
		
		$.ajax({
			url: "{{ url('upahproduksi/get_proses') }}",
			type: 'post',
			data: {rekanan : rekanan, pegawai : pegawai, id_jenis : id_jenis},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			dataType: 'json',
			success: function(result){
				if(result.status == 1){
					$("[name=proses]").html('');
					$("[name=proses]").append('<option value="" kode="">--- Pilih Proses ---</option>');
					for(i in result.data){	
						if(result.data[i].id_workorder != '' || result.data[i].id_workorder != 0){
							$nomor = result.data[i].no_workorder+' '+'(Nomor SPK)';
						}else{
							$nomor = result.data[i].no_workorder_barang+' '+'(Nomor Order)';
						}

						
						$("[name=proses]").append('<option value="'+result.data[i].id_barangmasuk+'" barangkeluar="'+result.data[i].id_barangkeluar+'" spk="'+result.data[i].id_workorder+'" workorder="'+result.data[i].id_workorder_barang+'" proses="'+result.data[i].id_proses+'" rekanan="'+result.data[i].id_rekanan+'" pegawai="'+result.data[i].id_pegawai+'">'+$nomor+' - '+result.data[i].nama_proses+'</option>');
						disabled('[name=rekanan]', true);
					}
				}else{
					$("[name=proses]").html('');
				}
			}
		})
	}

	function get_ket(){
		$.ajax({
			url: "{{ url('upahproduksi/get_ket') }}",
			type: 'get',
			dataType: 'json',
			success: function(result){
				if(result.status == 1){
					$("[name=popup_keterangan]").html('');
					$("[name=popup_keterangan]").append('<option value="" kode="">--- Pilih Keterangan ---</option>');
					for(i in result.data){
						$("[name=popup_keterangan]").append('<option value="'+result.data[i].id_upahket+'" nama="'+result.data[i].nama_upahket+'">'+result.data[i].nama_upahket+'</option>');
					}
				}
			}
		})
	}

	function get_perkiraan(){
		$.ajax({
			url: "{{ url('upahproduksi/get_perkiraan') }}",
			type: 'get',
			dataType: 'json',
			success: function(result){
				if(result.status == 1){
					$("[name=popup_perkiraan]").html('');
					$("[name=popup_perkiraan]").append('<option value="">--- Pilih Kategori ---</option>');
					for(i in result.data){
						$("[name=popup_perkiraan]").append('<option value="'+result.data[i].id+'" kode="'+result.data[i].kode_perkiraan+'" nama="'+result.data[i].nama_perkiraan+'">'+result.data[i].kode_perkiraan+' - '+result.data[i].nama_perkiraan+'</option>');
					}
					
				}
			}
		})
	}
	
	function get_satuan(){
		$.ajax({
			url: "{{ url('upahproduksi/get_satuan') }}",
			type: 'get',
			dataType: 'json',
			success: function(result){
				if(result.status == 1){
					$("[name=popup_satuan_waktu]").html('');
					$("[name=popup_satuan_waktu]").append('<option value="" kode="">--- Pilih Waktu ---</option>');
					for(i in result.data){
						$("[name=popup_satuan_waktu]").append('<option value="'+result.data[i].id_satuan+'" nama="'+result.data[i].nama_satuan+'">'+result.data[i].nama_satuan+'</option>');
					}
				}
			}
		})
	}

	var id_trans=<?php Print($data['id_trans']); ?>;
	function get_by_id(){
		$.ajax({
			url:"{{ url('upahproduksi/getNoWorker') }}"+"/"+id_trans+"/1",
			type:'get',
			dataType:'json',
			success:function(result){
			if(result[0]['stat_pekerja'] == "Pegawai"){
					$("[name=pegawai]").val(result[0]['id_pegawai']).trigger('change');
					document.getElementById('rekanan').disabled=true;
				}else if(result[0]['stat_pekerja'] == "Rekanan"){
					$("[name=rekanan]").val(result[0]['id_rekanan']).trigger('change');
					document.getElementById('pegawai').disabled=true;
				}
				setTimeout(function(){
					$("#proses").val(result[0]['idPros']).trigger('change');
				},1000);
			
				
			}
		})
	}
	function get_by_id_barang_masuk(){
		$.ajax({
			url:"{{ url('upahproduksi/getNoWorker') }}"+"/"+id_trans+"/2",
			type:'get',
			dataType:'json',
			success:function(result){
        		 if(result[0]['stat_pekerja'] == "Pegawai"){
					$("[name=pegawai]").val(result[0]['id_pegawai']).trigger('change');
					document.getElementById('rekanan').disabled=true;
				}else if(result[0]['stat_pekerja'] == "Rekanan"){
					$("[name=rekanan]").val(result[0]['id_rekanan']).trigger('change');
					document.getElementById('pegawai').disabled=true;
				}
				setTimeout(function(){
					$("#proses").val(result[0]['idPros']).trigger('change');
				},1000);
			}
		})
	}
	var total_lain2=0;
	var no=parseInt(0);
	$("#btn_popup_simpan_lain_lain").click(function(){
		// alert("berhasil");
		var id_data = $("[name=popup_id_table_lain_lain]").val();
		var jenis= $("#jenis_lain_lain").val();
		var upah=$("#upah_lain_lain").val();
		if(jenis != '' && upah !=''){
			if(id_data==''){
				table_lain2.row.add(['<div><center>'+no+'</center></div>',
					'<div id="list_jenis'+tb_no_ll+'">'+jenis+'</div>',
					'<div id="list_upah'+tb_no_ll+'">'+curr(upah)+'</div>',
					'<div><button type="button" class="btn bg-warning-400" onclick="edit_tablell('+tb_no_ll+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapusll(d=$(this))"><i class="icon-eraser"></i></button></div>'+
					'<input type="hidden" id="tabel_id2'+tb_no_ll+'" name="tabel_id2[]" value="">'+
					'<input type="hidden" id="tabel_jenis'+tb_no_ll+'" name="tabel_jenis[]" value="'+jenis+'">'+
					'<input type="hidden" id="tabel_upah'+tb_no_ll+'" name="tabel_upahll[]" value="'+upah+'">',
					]).draw(false);
				set_sub_total_lain2();
                set_total_upah();
				tb_no_ll++;
				no=tb_no_ll;
			}else{
				$("#list_jenis"+id_data).text(jenis);
				$("#list_upah"+id_data).text(curr(upah));

				$("#tabel_id2"+id_data).val(id_data);
				$("#tabel_jenis"+id_data).val(jenis);
				$("#tabel_upah"+id_data).val(upah);
				set_sub_total_lain2();
                set_total_upah();
			}
		}
		//total_lain2 += parseFloat(upah);
		// $("#sub_total2").text(curr(total_lain2));
		$("#exampleModal2").modal('hide');
		
	})


	$("#btn_popup_simpan").click(function(){
		var id_data = $("[name=popup_id_table]").val();
		var id_ket = $("[name=popup_keterangan]").val();
		var keterangan = $("[name=popup_keterangan] :selected").attr('nama');
		var id_perkiraan = $("[name=popup_perkiraan]").val();
		var kode_perkiraan = $("[name=popup_perkiraan] :selected").attr('kode');
		var nama_perkiraan = $("[name=popup_perkiraan] :selected").attr('nama');
		var satuan = $("[name=popup_satuan]").val();
		var satuan_waktu = $("[name=popup_satuan_waktu]").val();
		var nama_satuanwaktu = $("[name=popup_satuan_waktu] :selected").attr('nama');
		var upah = $("[name=popup_upah]").val();
		var total_upah = parseFloat($("[name=popup_upah]").val())*($("[name=popup_satuan]").val());
		
		if(keterangan != '' && satuan != '' && satuan_waktu != '' && upah != ''){
			if(id_data == ''){
				table_barang.row.add(['<div><center></center></div>',
					'<div id="list_ket'+tb_no+'">'+keterangan+'</div>',
					'<div id="list_perkiraan'+tb_no+'">'+kode_perkiraan+' - '+nama_perkiraan+'</div>',
					'<div id="list_satuan'+tb_no+'">'+satuan+' /'+nama_satuanwaktu+'</div>',
					'<div id="list_upah'+tb_no+'">'+curr(upah)+'</div>',
					'<div id="list_total'+tb_no+'">'+curr(total_upah)+'</div>',
					'<div><button type="button" class="btn bg-warning-400" onclick="edit_table('+tb_no+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapus($(this))""><i class="icon-eraser"></i></button></div>'+
					'<input type="hidden" id="tabel_id'+tb_no+'" name="tabel_id[]" value="">'+
					'<input type="hidden" id="tabel_ket'+tb_no+'" name="tabel_ket[]" value="'+id_ket+'">'+
					'<input type="hidden" id="tabel_perkiraan'+tb_no+'" name="tabel_perkiraan[]" value="'+id_perkiraan+'">'+
					'<input type="hidden" id="tabel_satuan'+tb_no+'" name="tabel_satuan[]" value="'+satuan+'">'+
					'<input type="hidden" id="tabel_satuanwaktu'+tb_no+'" name="tabel_satuanwaktu[]" value="'+satuan_waktu+'">'+
					'<input type="hidden" id="tabel_nama_satuanwaktu'+tb_no+'" name="tabel_nama_satuanwaktu[]" value="'+nama_satuanwaktu+'">'+
                    '<input type="hidden" id="tabel_upah'+tb_no+'" name="tabel_upah[]" value="'+upah+'">'+
                    '<input type="hidden" id="tabel_total'+tb_no+'" name="tabel_total[]" value="'+total_upah+'">'
					]).draw(false);
			}else{
				$("#list_ket"+id_data).text(keterangan);
				$("#list_perkiraan"+id_data).text(kode_perkiraan+' - '+nama_perkiraan);
				$("#list_satuan"+id_data).text(satuan+' /'+nama_satuanwaktu);
				$("#list_upah"+id_data).text(curr(upah));
				$("#list_total"+id_data).text(curr(total_upah));
				
				$("#tabel_id"+id_data).val(id_data);
				$("#tabel_ket"+id_data).val(id_ket);
				$("#tabel_perkiraan"+id_data).val(id_perkiraan);
				$("#tabel_satuan"+id_data).val(satuan);	
				$("#tabel_satuanwaktu"+id_data).val(satuan_waktu);
				$("#tabel_nama_satuanwaktu"+id_data).val(nama_satuanwaktu);				
				$("#tabel_upah"+id_data).val(upah);
				$("#tabel_total"+id_data).val(total_upah);
			}
		
		$("#exampleModal").modal('hide');
		tb_no++;
		}
	})

	function edit_table(id){
		var keterangan = $("#tabel_ket"+id).val();
		var perkiraan = $("#tabel_perkiraan"+id).val();
		var satuan = $("#tabel_satuan"+id).val();
		var satuan_waktu = $("#tabel_satuanwaktu"+id).val();
		var upah = $("#tabel_upah"+id).val();
		
		$("[name=popup_id_table]").val(id);
		$("[name=popup_keterangan]").val(keterangan).trigger('change');
		$("[name=popup_perkiraan]").val(perkiraan).trigger('change');
		$("[name=popup_satuan]").val(satuan);
		$("[name=popup_satuan_waktu]").val(satuan_waktu).trigger('change');
		$("[name=popup_upah]").val(upah);
		$("#help_popup_upah").text(curr(upah));

		$("#exampleModal").modal('show');
	}
	function edit_tablell(id){
		$("[name=popup_id_table_lain_lain]").val(id);
		$("#jenis_lain_lain").val($("#tabel_jenis"+id).val());
		$("#upah_lain_lain").val($("#tabel_upah"+id).val());		
		$("#help_popup_upah_lain_lain").text(curr($("#tabel_upah"+id).val()));
		$("#exampleModal2").modal('show');

	}

	function get_edit(id){
		$.ajax({
			url: "{{ url('upahproduksi/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){
						var total_upah = parseFloat(respon[i].satuan)*parseFloat(respon[i].upah);
						table_barang.row.add(['<div><center></center></div>',
							'<div id="list_ket'+respon[i].id_upahproduksi_barang+'">'+respon[i].keterangan+'</div>',
							'<div id="list_ket'+respon[i].id_upahproduksi_barang+'">'+respon[i].perkiraan+'</div>',
							'<div id="list_satuan'+respon[i].id_upahproduksi_barang+'">'+respon[i].satuan+ ' /'+respon[i].nama_satuanwaktu+'</div>',
							'<div id="list_upah'+respon[i].id_upahproduksi_barang+'">'+curr(respon[i].upah)+'</div>',
							'<div id="list_total'+respon[i].id_upahproduksi_barang+'">'+curr(total_upah)+'</div>',
							'<div><button type="button" class="btn bg-warning-400" onclick="edit_table('+respon[i].id_upahproduksi_barang+')"><i class="icon-pencil"></i> </button><button class="btn 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_upahproduksi_barang+'" value="'+respon[i].id_upahproduksi_barang+'">'+
							'<input type="hidden" name="tabel_ket[]" id="tabel_ket'+respon[i].id_upahproduksi_barang+'" value="'+respon[i].id_keterangan+'">'+
							'<input type="hidden" name="tabel_perkiraan[]" id="tabel_perkiraan'+respon[i].id_upahproduksi_barang+'" value="'+respon[i].id_perkiraan+'">'+
							'<input type="hidden" name="tabel_satuan[]" id="tabel_satuan'+respon[i].id_upahproduksi_barang+'" value="'+respon[i].satuan+'">'+
							'<input type="hidden" name="tabel_satuanwaktu[]" id="tabel_satuanwaktu'+respon[i].id_upahproduksi_barang+'" value="'+respon[i].satuan_waktu+'">'+
							'<input type="hidden" name="tabel_nama_satuanwaktu[]" id="tabel_nama_satuanwaktu'+respon[i].id_upahproduksi_barang+'" value="'+respon[i].nama_satuan_waktu+'">'+
							'<input type="hidden" name="tabel_upah[]" id="tabel_upah'+respon[i].id_upahproduksi_barang+'" value="'+respon[i].upah+'">'+
							'<input type="hidden" name="tabel_total[]" id="tabel_total'+respon[i].id_upahproduksi_barang+'" value="'+total_upah+'">'
							]).draw(false);
					}

				}
				
			}
		})

	}

	function hapus(d){
	table_barang.row(d.parents('tr')).remove().draw();	
	}
	function hapusll(d){
		table_lain2.row(d.parents('tr')).remove().draw();
		//alert(tb_no_ll);
		set_sub_total_lain2();
        set_total_upah();
	}
    function set_total_upah(){
    	var ppn = parseFloat(0);
    	var netto = parseFloat(0);
    	var pajak = "0%";
        var gaji_bersih=total_gaji+total_lain_2;
        if($('select[name=pajak]').val()==1){
			ppn = parseFloat(gaji_bersih*(10/100));
			pajak = "10%";
		}
		netto = total_gaji+total_lain_2+ppn;
        $('#jumlah_bayar').val(netto);
        $('#txt_jumlah_bayar').val(accounting.formatMoney(netto));
        $('#total_upah').text(curr(netto));
        $("#ppn").text(pajak);
    }

	
</script>
@endsection