	<?php
        $this->load->view('admin/master/header_2');
		$modul=$this->uri->segment(3);
		$menuid=$this->uri->segment(4);
		$id_workorder=$this->uri->segment(5);
		$control = $this->uri->segment(6);
		$added=$this->uri->segment(6);

		$next     = $id_workorder + 1;
		$previous = $id_workorder - 1;


		$data_workorder=$this->master_model->select_in('ts_workorder','*',"WHERE ID=$id_workorder");

		$data_workorder_labour=$this->master_model->select_in('ts_workorder_labour','*',"WHERE id_workorder=$id_workorder ORDER BY ID ASC");

		$data_workorder_labour_total = $this->db->query('SELECT COUNT(*) AS total_labour FROM `ts_workorder_labour` WHERE id_workorder = '.$id_workorder.'')->row();

		$workorder_no=$data_workorder[0]->workorder_no;

		$check_wo_labour=$this->master_model->mst_check('ts_workorder_labour', 'id_workorder', $id_workorder);

		if($check_wo_labour==false)
		{
			$disable_date_schedule='';
			$disable_date_target='';
		}else
		{
			$disable_date_schedule=''; //disabled="disabled"
			$disable_date_target=''; //disabled="disabled"
		}

		if($data_workorder[0]->date_schedule=='0000-00-00')
		{
			$today=strtotime(date('Y-m-d'));
			$today=date('m/d/Y', $today);

			$date_schedule=$today;
		}else
		{
			$date_schedule=date('m/d/Y', strtotime($data_workorder[0]->date_schedule));
		}

		if($data_workorder[0]->date_target=='0000-00-00')
		{
			$required=strtotime(date('Y-m-d'));
			$required=strtotime('+30 day', $required);
			$required=date('m/d/Y', $required);
			$date_target=$required;
		}else
		{
			$date_target=date('m/d/Y', strtotime($data_workorder[0]->date_target));
		}


		$data_workorder_labour=$this->master_model->select_in('ts_workorder_labour','*',"WHERE id_workorder=$id_workorder ORDER BY ID ASC");



		if($data_workorder_labour[0]->start_date=='0000-00-00')
		{
			$today=strtotime(date('Y-m-d'));
			$today=date('m/d/Y', $today);

			$schedule_date=$today;
		}else
		{
			$schedule_date=date('d M Y', strtotime($data_workorder_labour[0]->schedule_date));
		}

		if($data_workorder_labour[0]->end_date=='0000-00-00')
		{
			$required=strtotime(date('Y-m-d'));
			$required=strtotime('+30 day', $required);
			$required=date('m/d/Y', $required);
			$target_date=$required;
		}else
		{
			$target_date=date('d M Y', strtotime($data_workorder_labour[0]->target_date));
		}

		setlocale(LC_ALL, 'id_ID.UTF-8');

		$today=date('Y-m-d');
    ?>

	<script>
		$(document).ready(function() {
		    var added = '<?php echo $added;?>';

		    if (added !== '') {
		        var state = history.state || {};
		        var reloadCount = state.reloadCount || 0;
		        if (performance.navigation.type === 1) { // Reload
		            state.reloadCount = ++reloadCount;
		            history.replaceState(state, null, document.URL);
		        } else if (reloadCount) {
		            delete state.reloadCount;
		            reloadCount = 0;
		            history.replaceState(state, null, document.URL);
		        }
		        if (reloadCount >= 1) {
		            return true;
		        } else {
		            var x = document.getElementById("snackbar")
		            x.className = "show";
		            setTimeout(function() {
		                x.className = x.className.replace("show", "");
		            }, 3000);
		        }
		    }
		});
	</script>

	<div class="content-wrapper">
	    <section class="content-header">
	        <h1>
	            Production Process
	            <small>Control panel</small>
	        </h1>
	        <ol class="breadcrumb">
	            <li><a href="<?php echo base_url();?>admin/home/index/8"><i class="fa fa-dashboard"></i> Home</a></li>
	            <li><a href="<?php echo base_url();?>admin/transaction/production/<?php echo $menuid;?>">Production</a>
	            </li>
	            <li class="active">Production Process</li>
	        </ol>
	    </section>
	    <!-- <?php 
	    // echo "<pre>";
		// print_r($data_workorder_labour_total->total_labour);die();
		?> -->
	    <section class="content">
	        <?php echo $this->session->flashdata('message') ?>
	        <?php echo $this->session->flashdata('mdt') ?>
	        <div class="row">
	            <div class="col-md-12">
	                <div class="box box-primary">
	                    <div class="box-header with-border">
	                        <h3 class="box-title">Filter</h3>
	                        <hr>
	                        <div class="box-tools pull-right">
	                            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i
	                                    class="fa fa-minus"></i></button>
	                            <button type="button" class="btn btn-box-tool" data-widget="remove"><i
	                                    class="fa fa-remove"></i></button>
	                            <a href="<?php echo base_url();?>admin/transaction/production_insert/<?php echo $menuid.'/'.$previous;?>"
	                                class="btn btn-box-tool" data-toggle="tooltip" title="Previous">
	                                <i class="fa fa-chevron-left"></i>
	                            </a>
	                            <a href="<?php echo base_url();?>admin/transaction/production_insert/<?php echo $menuid.'/'.$next;?>"
	                                class="btn btn-box-tool" data-toggle="tooltip" title="Next">
	                                <i class="fa fa-chevron-right"></i>
	                            </a>
	                        </div>
	                        <form
	                            action="<?php echo base_url();?>admin/transaction/insert_production/<?php echo $menuid.'/'.$id_workorder.'/'.$control;?>"
	                            method="post" enctype="multipart/form-data">
	                            <div class="body">
	                                <div class="row clearfix">
	                                    <div class="col-md-4">
	                                        <div class="form-group">
	                                            <div class="form-line">
	                                                <label>Work Order No <font color="#FF0000">*</font></label>
	                                                <input type="text" name="workorder" class="form-control"
	                                                    placeholder="Purchase Order No" disabled="disabled"
	                                                    required="required"
	                                                    value="<?php echo $data_workorder[0]->workorder_no;?>">
	                                            </div>
	                                        </div>
	                                        <div class="form-group">
	                                            <div class="form-line">
	                                                <label>Schedule Date <font color="#FF0000">*</font></label>
	                                                <input type="text" name="schedule_date" id="datepicker"
	                                                    class="form-control datepicker" placeholder="Date"
	                                                    <?php echo $disable_date_schedule;?>
	                                                    value="<?php echo $date_schedule;?>">
	                                            </div>
	                                            <script type="text/javascript">
	                                            $(function() {
	                                                $(".datepicker").datepicker();
	                                            });
	                                            </script>
	                                        </div>
	                                        <div class="form-group">
	                                            <div class="form-line">
	                                                <label>Target Date <font color="#FF0000">*</font></label>
	                                                <input type="text" name="target_date" id="datepicker2"
	                                                    class="form-control datepicker" placeholder="Date"
	                                                    <?php echo $disable_date_target;?>
	                                                    value="<?php echo $date_target;?>">
	                                            </div>
	                                            <script type="text/javascript">
	                                            $(function() {
	                                                $(".datepicker2").datepicker();
	                                            });
	                                            </script>
	                                        </div>
	                                    </div>
	                                    <div class="col-md-4">

	                                        <div class="form-group">
	                                            <div class="form-line">
	                                                <label>Product Code <font color="#FF0000">*</font></label>
	                                                <input type="text" name="product_code" class="form-control" readonly=""
	                                                    placeholder="Product Code"
	                                                    value="<?php echo $data_workorder[0]->product_code;?>" />
	                                            </div>
	                                        </div>

	                                        <div class="form-group">
	                                            <div class="form-line">
	                                                <label>Finish Good <font color="#FF0000">*</font></label>
	                                                <input type="text" name="finish_good" class="form-control" readonly=""
	                                                    placeholder="Finish Good"
	                                                    value="<?php echo $data_workorder[0]->finish_good;?>" />
	                                            </div>
	                                        </div>
	                                        <div class="form-group">
	                                            <div class="form-line">
	                                                <label>Sales Order No</label>

	                                                <input type="text" name="sales_order_no" list="purchase_number"
	                                                    id="purchase_numbers" class="form-control"
	                                                    placeholder="Sales Order No"
	                                                    value="<?php echo $data_workorder[0]->sales_order_no;?>">
	                                                <datalist id="purchase_number"></datalist>
	                                            </div>
	                                        </div>
	                                        <!-- <div class="col-md-6">
					                    	<div class="row"> -->
	                                        <div class="form-group">
	                                            <div class="form-line">
	                                                <label>Customer <font color="#FF0000">*</font></label>
	                                                <!-- <span id="code-supplier-result" style="display:none"><i class="fa fa-refresh fa-spin"></i></span>
							                            <input type="text" name="supplier_code" list="supplier_code" class="form-control " placeholder="Customer Code" id="supplier_code_2" value="<?php echo $data_workorder[0]->supplier_code;?>">
							                            <datalist id="supplier_code"></datalist> -->
	                                                <select class="form-control supplier_get_preview" name="id_customer"
	                                                    style="width: 100%;">
	                                                    <option value="">Select Customer</option>
	                                                    <?php $customer=$this->master_model->mst_data('ms_customer');
											              ?>
	                                                    <?php foreach ($customer as $key => $value): ?>
	                                                    <?php if($data_workorder[0]->id_customer == $value->ID): ?>
	                                                    <?php $select='selected="selected"'; ?>
	                                                    <?php else: ?>
	                                                    <?php $select=''; ?>
	                                                    <?php endif ?>
	                                                    <option value="<?php echo $value->ID ?>" <?php echo $select; ?>>
	                                                        <?php echo $value->code.' - '.$value->name; ?>
	                                                    </option>
	                                                    <?php endforeach ?>

	                                                </select>
	                                            </div>
	                                        </div>
	                                        <!-- </div>
					                    </div> -->
	                                        <!-- <div class="col-md-6">
					                    	<div class="row">
						                        <div class="form-group">
						                        	<div class="form-line">
														<label>Customer Name</label>
														<span id="name-supplier-result" style="display:none"><i class="fa fa-refresh fa-spin"></i></span>
														<input type="text" name="supplier_name" list="supplier_name" id="supplier_name_2" class="form-control" placeholder="Customer Name" value="<?php echo $data_workorder[0]->supplier_name;?>">
														<datalist id="supplier_name"></datalist>
													</div>
						                        </div>
					                    	</div>
					                    </div> -->
	                                    </div>
	                                    <div class="col-md-4">
	                                        <div class="col-md-6">
	                                            <div class="form-group">
	                                                <div class="form-line">
	                                                    <label>Target Pcs <font color="#FF0000">*</font></label>
	                                                    <script>
	                                                    $(function() {
	                                                        $("#target_pcs_header").focusout(function() {
	                                                            var target_pcs_header = $(this).val();

	                                                            //$(".requested1").val(target_pcs_header);
	                                                        });
	                                                    });
	                                                    </script>
	                                                    <input type="text" name="target_pcs"
	                                                        class="form-control target_pcs_header" id="target_pcs_header"
	                                                        placeholder="Pcs"
	                                                        value="<?php echo $data_workorder[0]->target_pcs;?>">
	                                                </div>
	                                            </div>
	                                        </div>
	                                        <div class="col-md-6">
	                                            <div class="form-group">
	                                                <div class="form-line">
	                                                    <label>Finish</label>
	                                                    <input type="text" name="finish" class="form-control finish"
	                                                        placeholder="Pcs" readonly="readonly"
	                                                        value="<?php echo $data_workorder[0]->finish;?>">
	                                                </div>
	                                            </div>
	                                        </div>
	                                        <div class="col-md-6">
	                                            <div class="form-group">
	                                                <div class="form-line">
	                                                    <label>Status</label>
	                                                    <br />
	                                                    <?php
															if($data_workorder[0]->status=='Pending')
															{
																$font='text-red';
															}elseif($data_workorder[0]->status=='Process')
															{
																$font='text-green';
															}elseif($data_workorder[0]->status=='Done')
															{
																$font='text-aqua';
															}

															echo '<font class="'.$font.'">'.$data_workorder[0]->status.'</font>';


															if($data_workorder[0]->status=='Process')
															{
																?>
	                                                    <a href="<?php echo base_url();?>admin/transaction/done_process/<?php echo 'production/'.$menuid.'/'.$id_workorder;?>"
	                                                        class="text-blue pull-right"
	                                                        onClick='return confirm("Are you sure want to close this transaction?")'>
	                                                        [Close]
	                                                    </a>
	                                                    <?php
															}else
															{
																echo'';
															}
														?>
	                                                    <br />
	                                                    <br />
	                                                </div>
	                                                <div class="form-line">
	                                                    <label>Cost</label>
	                                                    <script>
	                                                    $(function() {
	                                                        $(".cost").focusout(function() {
	                                                            var cost = $(this).val();
	                                                            var grand_total = $("#grandtotal_real")
	                                                                .val();
	                                                            var cost = cost.toString().replace(/[,]/,
	                                                                ".");
	                                                            var grandtotal = parseFloat(cost) +
	                                                                parseFloat(grand_total);
	                                                            var grandtotal_html = grandtotal.toString()
	                                                                .replace(/[.]/, ",");
	                                                            $("#grand_total").html(addCommas(
	                                                                grandtotal_html));
	                                                            $(".grandtotal").val(grandtotal);
	                                                            //$("#update_total_labour").trigger("click");
	                                                        });
	                                                    });
	                                                    </script>
	                                                    <br />
	                                                    <input type="text" class="form-control cost" name="cost"
	                                                        style="margin-bottom: 10px;"
	                                                        value="<?php echo $data_workorder[0]->cost;?>">
	                                                </div>
	                                                <div class="form-line">
	                                                    <label>HPP</label>
	                                                    <br />
	                                                    <?php
							                        		if($data_workorder[0]->finish==0)
							                        		{
							                        			echo 0;
							                        		}else
							                        		{
							                        			echo number_format($data_workorder[0]->grandtotal/$data_workorder[0]->finish);
							                        		}
							                        	?>
	                                                </div>
	                                            </div>
	                                        </div>
	                                        <div class="col-md-6">
	                                            <div class="form-group">
	                                                <div class="form-line">
	                                                    <label>Total Material</label>
	                                                    <br />
	                                                    <?php echo number_format($data_workorder[0]->total_material);?>
	                                                    <br />
	                                                    <br />
	                                                </div>
	                                                <div class="form-line">
	                                                    <label>Total Labour</label>
	                                                    <br />
	                                                    <?php echo number_format($data_workorder[0]->total_labour);?>
	                                                    <br />
	                                                    <br />
	                                                </div>
	                                                <div class="form-line">
	                                                    <label>Grand Total</label>
	                                                    <br />
	                                                    <span id="grand_total">
	                                                        <?php echo number_format($data_workorder[0]->grandtotal);?>
	                                                    </span>

	                                                    <input type="hidden"
	                                                        value="<?php echo $data_workorder[0]->grandtotal;?>"
	                                                        id="grandtotal_real">

	                                                    <input type="hidden" name="grandtotal"
	                                                        value="<?php echo $data_workorder[0]->grandtotal;?>"
	                                                        class="grandtotal">
	                                                </div>
	                                            </div>
	                                        </div>
	                                    </div>

	                                </div>
	                                <div class="nav-tabs-custom">
	                                    <ul class="nav nav-tabs">
	                                        <li class="active"><a href="#tab_1" data-toggle="tab">Material</a></li>
	                                        <li><a href="#tab_2" data-toggle="tab">Labour</a></li>
	                                        <li><a href="#tab_3" data-toggle="tab">Design</a></li>
	                                    </ul>
	                                    <div class="tab-content">
	                                        <div class="tab-pane active" id="tab_1">
	                                            <div class="row">
	                                                <div class="col-md-12">
	                                                    <div class="table-responsive">
	                                                        <table
	                                                            class="table table-bordered table-striped table-hover js-basic-example dataTable">
	                                                            <thead>
	                                                                <tr>
	                                                                    <th>No.</th>
	                                                                    <th>Code Material</th>
	                                                                    <th>Description</th>
	                                                                    <th>Available Stock</th>
	                                                                    <th>Plan</th>
	                                                                    <th>Unit</th>
	                                                                    <th>Pick Material</th>
	                                                                    <th>Used Material</th>
	                                                                    <th>Return Material</th>
	                                                                    <th>Price</th>
	                                                                    <th>Total Material</th>
	                                                                    <th>Status</th>
	                                                                    <th>Action</th>
	                                                                </tr>
	                                                            </thead>
	                                                            <tbody>
	                                                                <?php
																$data_workorder_material=$this->master_model->select_in_workorder_material($id_workorder);

																$count_wo_material=count($data_workorder_material);

																for($a=0; $a < count($data_workorder_material); $a++)
																{
																	$b=$a+1;

																	$id_material=$data_workorder_material[$a]->ID;

																	$code_inventory=$data_workorder_material[$a]->id_inventory;
																	$get_unit=$this->master_model->select_in('ms_inventory','unit',"WHERE id='$code_inventory'");

																	$unit=$get_unit[0]->unit;

																	echo'
																		<tr>
																			<td>
																				'.$b.'
																			</td>
																			<td>
																			   '.$data_workorder_material[$a]->code_inventory .' - '.$data_workorder_material[$a]->name_inventory.'
																			</td>
																			<td>
																				'.$data_workorder_material[$a]->name_inventory.'
																			</td>
																			<td>
																				'.$data_workorder_material[$a]->stock_balance.'
																			</td>
																			<td>
																				'.$data_workorder_material[$a]->plan.'
																			</td>

																			<td>
																			<script type="text/javascript">
																				$(document).on("keyup", "#add_qty_' . $a . '", function(){
																					//alert("eda")
																					value = $(this).val() == "" ? 0 : parseInt($(this).val());
																					qty_avail = $(this).attr("isi-qty-avail");
																					qty_order = $(this).attr("isi-order-qty");

																					//console.log(qty_avail)
																					if (value > qty_avail) {
																					alert("Exceeds pick in qty");
																					$(this).val(qty_avail)
																						cal = 0;
																					} else {
																						cal = qty_avail - value
																					}
																					$("#in_qty_total_' . $a . '").text(cal);
																					console.log(cal)

																					});

																				$(document).on("keyup", "#add_qty_pick_' . $a . '", function(){
																					//alert("eda")
																					value = $(this).val() == "" ? 0 : parseInt($(this).val());
																					qty_avail = $(this).attr("isi-qty-pick");

																					//console.log(qty_avail)
																					if (value > qty_avail) {
																					alert("Exceeds plan in qty");
																					$(this).val(qty_avail)
																						cal = 0;
																					} else {
																						cal = qty_avail - value
																					}
																					$("#in_qty_total_' . $a . '").text(cal);
																					console.log(cal)

																					});
																			</script>
																			'.$unit.'
																			</td>
																			<td>
																				';
																				if ($data_workorder_material[$a]->status == 'Process') {
																					if ($data_workorder_material[$a]->requested == '') {
	                                                                                    echo '<input type="text" id="add_qty_pick_' . $a . '" isi-qty-pick="' . $data_workorder_material[$a]->plan . '" name=pick_material[] class="form-control">
	                                                                                    	<input type="hidden" name=pick_material_old[] value="0" class="form-control">
	                                                                                    	<input type="hidden" name="id_inventory[]" value="'.$data_workorder_material[$a]->id_inventory.'">
	                                                                                    	<input type="hidden" name="ID[]" value="'.$id_material.'">';
	                                                                                } else {
	                                                                                    // echo $data_workorder_material[$a]->requested;
	                                                                                    echo '<input type="text" id="add_qty_pick_' . $a . '" isi-qty-pick="' . $data_workorder_material[$a]->plan . '" name=pick_material[] value="'.$data_workorder_material[$a]->requested.'" class="form-control">
	                                                                                    <input type="hidden" name=pick_material_old[] value="'.$data_workorder_material[$a]->requested.'" class="form-control">
	                                                                                    <input type="hidden" name=stock_out_id[] value="'.$data_workorder_material[$a]->ID.'" class="form-control">
	                                                                                    <input type="hidden" name="id_inventory[]" value="'.$data_workorder_material[$a]->id_inventory.'">
	                                                                                    <input type="hidden" name="ID[]" value="'.$id_material.'">';
	                                                                                }
																				}else if($data_workorder_material[$a]->status == 'Close'){
																					echo $data_workorder_material[$a]->requested;
																				}
                                                                                
                                                                                echo '
																				
																			</td>
																			<td>
																				';
																				if ($data_workorder_material[$a]->status == 'Process') {
																					if ($data_workorder_material[$a]->requested != '' AND $data_workorder_material[$a]->actual == 0) {
																					
	                                                                                    echo '<input type="text" id="add_qty_' . $a . '" value="0" name="actual[]" class="form-control" isi-qty-avail="' . $data_workorder_material[$a]->requested . '" >';
	                                                                                    echo '<input type="hidden" value="'.$data_workorder_material[$a]->actual.'" name="actual_old[]" class="form-control">';
	                                                                                
																					}else{
																						if ($data_workorder_material[$a]->actual > 0) {
																							echo '<input type="text" id="add_qty_' . $a . '" value="'.$data_workorder_material[$a]->actual.'" name="actual[]" class="form-control" isi-qty-avail="' . $data_workorder_material[$a]->requested . '">';
		                                                                                    echo '<input type="hidden" value="'.$data_workorder_material[$a]->actual.'" name="actual_old[]" class="form-control">';
																						}
		                                                                                	
																					}
																				}else if($data_workorder_material[$a]->status == 'Close') {
																					echo $data_workorder_material[$a]->actual;
																				}
																				
                                                                                echo '
																				
																			</td>
																			<td>
																				'.$data_workorder_material[$a]->retur.'
																			</td>
																			<td align="right">
																				'.number_format($data_workorder_material[$a]->last_cost).'
																				<input type="hidden" name="price[]" value="'.$data_workorder_material[$a]->last_cost.'">
																			</td>
																			<td align="right">
																				'.number_format($data_workorder_material[$a]->gross_ammount).'
																			</td>
																			<td align="center">
																				'.$data_workorder_material[$a]->status.'
																			</td>
																			<td align="center">
																				<script>
																					$(function(){
																						$(".edit_'.$b.'").click(function()
																						{
																						   var ID = $(this).attr("alt");

																						   //alert(ID);
																						   //return false;

																						   $.ajax({
																								type: "POST",
																								dataType: "html",
																								url: "'.base_url().'admin/transaction/production_material/'.$menuid.'",
																								data: "ID="+ID,
																								success: function(data)
																								{
																									$(".modal-content").html(data);
																								}
																							});
																						});
																					});
																				</script>
																				';
																					if ($data_workorder_material[$a]->requested == '') {
																						if($data_workorder[0]->status=='Done') {
																						echo'-';
																						}else{
																							
																							echo'
																								';
																								echo'
																									<a href="'.base_url().'admin/transaction/delete_material/'.$menuid.'/'.$id_workorder.'/'.$id_material.'/'.$data_workorder_material[$a]->id_inv.'" class="btn btn-sm btn-danger alert_notif" value="'.$data_workorder_material[$a]->code_inventory.'" >

														                                            <i class="fa fa-trash-o"></i>

														                                        </a>';


																								// <a href="'.base_url().'admin/transaction/delete_material/'.$menuid.'/'.$id_workorder.'/'.$id_material.'/'.$data_workorder_material[$a]->id_inv.'" style="margin-left:10px; cursor:pointer; float:left">
																								// 		<i class="fa fa-trash text-red" aria-hidden="true"></i>
																								// 	</a>';
																									
																								if($data_workorder_material[$a]->status=='Close') {

																									echo 'Close <br>';
																									 //jika tidak ada id matrial konfersi gydang
																									if($data_workorder_material[$a]->id_jurnal_workorder == null){
																									 	echo'
																										<a class="btn btn-danger pull-right" href="'.base_url().'admin/transaction/close_material_jurnal/'.$menuid.'/'.$id_workorder.'/'.$id_material.'" style="margin-left:10px; cursor:pointer; float:left">
																											Send To Jurnal</i>
																										</a>';
																									} else {
																									 	echo'
																										<a href="https://my.jurnal.id/warehouse_transfers/'.$data_workorder_material[$a]->id_jurnal_workorder.'"  target="_blank">
																											#'.$data_workorder_material[$a]->id_jurnal_workorder.'
																										</a>';
																									}
																								    
																								}
																								echo'
																							';
																						}
																						
																					}else{
																						if($data_workorder[0]->status=='Done') {
																						echo'-';
																						}else{
																							
																							echo'
																								';
																								echo'<a href="'.base_url().'admin/transaction/delete_material/'.$menuid.'/'.$id_workorder.'/'.$id_material.'/'.$data_workorder_material[$a]->id_inv.'" style="margin-left:10px; cursor:pointer; float:left">
																										<i class="fa fa-trash text-red" aria-hidden="true"></i>
																									</a>';
																									
																								if($data_workorder_material[$a]->status=='Close') {

																									echo 'Close <br>';
																									 //jika tidak ada id matrial konfersi gydang
																									if($data_workorder_material[$a]->id_jurnal_workorder == null){
																									 	echo'
																										<a class="btn btn-danger pull-right" href="'.base_url().'admin/transaction/close_material_jurnal/'.$menuid.'/'.$id_workorder.'/'.$id_material.'" style="margin-left:10px; cursor:pointer; float:left">
																											Send To Jurnal</i>
																										</a>';
																									} else {
																									 	echo'
																										<a href="https://my.jurnal.id/warehouse_transfers/'.$data_workorder_material[$a]->id_jurnal_workorder.'"  target="_blank">
																											#'.$data_workorder_material[$a]->id_jurnal_workorder.'
																										</a>';
																									}
																								    
																								}
																								echo'
																							';
																						}
																						if ($data_workorder_material[$a]->status == 'Process' AND $data_workorder_material[$a]->actual <= $data_workorder_material[$a]->requested AND $data_workorder_material[$a]->actual != 0) {
																							echo '<a href="'.base_url().'admin/transaction/close_material/'.$menuid.'/'.$id_workorder.'/'.$id_material.'/'.$data_workorder_material[$a]->requested.'/'.$data_workorder_material[$a]->actual.'/'.$data_workorder_material[$a]->id_inv.'/'.$data_workorder_material[$a]->last_cost.'/'.$data_workorder_material[$a]->actual.'" style="margin-left:10px; cursor:pointer; float:left">
																										Close
																									</a>';
																						}
																					}
																					// if($data_workorder[0]->status=='Done') {
																					// 	echo'-';
																					// }else{
																						
																					// 	echo'
																					// 		';
																					// 		echo'<a href="'.base_url().'admin/transaction/delete_material/'.$menuid.'/'.$id_workorder.'/'.$id_material.'/'.$data_workorder_material[$a]->id_inv.'" style="margin-left:10px; cursor:pointer; float:left">
																					// 				<i class="fa fa-trash text-red" aria-hidden="true"></i>
																					// 			</a>';
																								
																							if($data_workorder_material[$a]->status=='Close') {
																								 //jika tidak ada id matrial konfersi gydang
																								if($data_workorder_material[$a]->id_jurnal_workorder == null){
																								 	echo'
																									<a class="btn btn-danger pull-right" href="'.base_url().'admin/transaction/close_material_jurnal_2/'.$menuid.'/'.$id_workorder.'/'.$id_material.'" style="margin-left:10px; cursor:pointer; float:left">
																										Send To Jurnal</i>
																									</a>';
																								} else {
																								 	echo'
																									<a class="btn btn-danger pull-right" href="'.base_url().'admin/transaction/close_material_jurnal_2/'.$menuid.'/'.$id_workorder.'/'.$id_material.'" style="margin-left:10px; cursor:pointer; float:left">
																										Send To Jurnal</i>
																									</a>';

																								}
																							    
																							}
																							echo'
																						';
																					// }
																					// if ($data_workorder_material[$a]->status == 'Process' AND $data_workorder_material[$a]->actual <= $data_workorder_material[$a]->requested) {
																					// 	echo '<a href="'.base_url().'admin/transaction/close_material/'.$menuid.'/'.$id_workorder.'/'.$id_material.'/'.$data_workorder_material[$a]->requested.'/'.$data_workorder_material[$a]->actual.'/'.$data_workorder_material[$a]->id_inv.'" style="margin-left:10px; cursor:pointer; float:left">
																					// 				Close
																					// 			</a>';
																					// }
																				echo'
																			</td>
																		</tr>
																	';
																}
																for($r=0; $r < 20-$count_wo_material; $r++) {
																	$s=$r+1+$count_wo_material;
																	?>
	                                                                <tr id="row3<?php echo $s;?>" style="display:none">
	                                                                    <td>
	                                                                        <?php echo $s;?>
	                                                                    </td>
	                                                                    <td>
	                                                                        <script>
	                                                                        $(document).ready(function() {
	                                                                            $(".inventory_code_<?php echo $s;?>")
	                                                                                .bind('input', function(e) {
	                                                                                    var code = $(this)
	                                                                                        .val();
	                                                                                    $.ajax({
	                                                                                        type: "GET",
	                                                                                        dataType: "html",
	                                                                                        url: "<?php echo base_url();?>admin/transaction/get_code_inventory/<?php echo $menuid;?>",
	                                                                                        data: "code=" +
	                                                                                            code,
	                                                                                        success: function(
	                                                                                            msg
	                                                                                        ) {
	                                                                                            $("#inventory_code_<?php echo $s;?>")
	                                                                                                .html(
	                                                                                                    msg
	                                                                                                );
	                                                                                        }
	                                                                                    });
	                                                                                });

	                                                                            $(".inventory_get_detail_<?php echo $s;?>")
	                                                                                .focusout(function(e) {
	                                                                                    var code = $(this)
	                                                                                        .val();
	                                                                                    //alert(code);
	                                                                                    //return false;
	                                                                                    $.ajax({
	                                                                                        type: "POST",
	                                                                                        dataType: "html",
	                                                                                        url: "<?php echo base_url();?>admin/transaction/inventory_get_detail_3/<?php echo $menuid;?>",
	                                                                                        data: "code=" +
	                                                                                            code,
	                                                                                        success: function(
	                                                                                            msg
	                                                                                        ) {
	                                                                                            if (code ==
	                                                                                                ''
	                                                                                            ) {
	                                                                                                $("#inventory_names_<?php echo $s;?>")
	                                                                                                    .val(
	                                                                                                        ''
	                                                                                                    );
	                                                                                                $("#qty_<?php echo $s;?>")
	                                                                                                    .val(
	                                                                                                        0
	                                                                                                    );
	                                                                                            } else {
	                                                                                                var data_inventory =
	                                                                                                    msg;
	                                                                                                var explode =
	                                                                                                    data_inventory
	                                                                                                    .split(
	                                                                                                        "%"
	                                                                                                    );
	                                                                                                var inventory_name =
	                                                                                                    explode[
	                                                                                                        0
	                                                                                                    ];
	                                                                                                var plan =
	                                                                                                    explode[
	                                                                                                        1
	                                                                                                    ];
	                                                                                                var check =
	                                                                                                    explode[
	                                                                                                        2
	                                                                                                    ];
	                                                                                                if (check ==
	                                                                                                    'exist'
	                                                                                                ) {
	                                                                                                    $("#inventory_names_<?php echo $s;?>")
	                                                                                                        .val(
	                                                                                                            inventory_name
	                                                                                                        );
	                                                                                                    $(".unit_<?php echo $s;?>")
	                                                                                                        .html(
	                                                                                                            plan
	                                                                                                        );
	                                                                                                } else {
	                                                                                                    $("#inventory_names_<?php echo $s;?>")
	                                                                                                        .val(
	                                                                                                            ''
	                                                                                                        );
	                                                                                                    $(".unit_<?php echo $s;?>")
	                                                                                                        .html(
	                                                                                                            '<input type="text" name="plan[]" class="form-control" style="width:100px;" />'
	                                                                                                        );

	                                                                                                    var x =
	                                                                                                        document
	                                                                                                        .getElementById(
	                                                                                                            "snackbar"
	                                                                                                        )
	                                                                                                    x.className =
	                                                                                                        "show";
	                                                                                                    x.innerHTML =
	                                                                                                        "Item does not exist!";
	                                                                                                    setTimeout
	                                                                                                        (function() {
	                                                                                                                x.className =
	                                                                                                                    x
	                                                                                                                    .className
	                                                                                                                    .replace(
	                                                                                                                        "show",
	                                                                                                                        ""
	                                                                                                                    );
	                                                                                                            },
	                                                                                                            3000
	                                                                                                        );
	                                                                                                }
	                                                                                            }
	                                                                                        }
	                                                                                    });

	                                                                                    $.ajax({
	                                                                                        type: "POST",
	                                                                                        dataType: "html",
	                                                                                        url: "<?php echo base_url();?>admin/transaction/inventory_get_detail_stock/<?php echo $menuid;?>",
	                                                                                        data: "code=" +
	                                                                                            code,
	                                                                                        success: function(
	                                                                                            msg
	                                                                                        ) {
	                                                                                            if (code ==
	                                                                                                ''
	                                                                                            ) {
	                                                                                                $("#inventory_names_<?php echo $s;?>")
	                                                                                                    .val(
	                                                                                                        ''
	                                                                                                    );
	                                                                                                $("#qty_<?php echo $s;?>")
	                                                                                                    .val(
	                                                                                                        0
	                                                                                                    );
	                                                                                            } else {
	                                                                                                var data_inventory =
	                                                                                                    msg;
	                                                                                                var explode =
	                                                                                                    data_inventory
	                                                                                                    .split(
	                                                                                                        "%"
	                                                                                                    );
	                                                                                                var inventory_name =
	                                                                                                    explode[
	                                                                                                        0
	                                                                                                    ];
	                                                                                                var plan =
	                                                                                                    explode[
	                                                                                                        1
	                                                                                                    ];
	                                                                                                var check =
	                                                                                                    explode[
	                                                                                                        2
	                                                                                                    ];
	                                                                                                if (check ==
	                                                                                                    'exist'
	                                                                                                ) {
	                                                                                                    $("#inventory_names_<?php echo $s;?>")
	                                                                                                        .val(
	                                                                                                            inventory_name
	                                                                                                        );
	                                                                                                    $(".availabe_<?php echo $s;?>")
	                                                                                                        .html(
	                                                                                                            plan
	                                                                                                        );
	                                                                                                } else {
	                                                                                                    $("#inventory_names_<?php echo $s;?>")
	                                                                                                        .val(
	                                                                                                            ''
	                                                                                                        );
	                                                                                                    $(".availabe_<?php echo $s;?>")
	                                                                                                        .html(
	                                                                                                            '<input type="text" class="form-control" style="width:100px;" />'
	                                                                                                        );

	                                                                                                    var x =
	                                                                                                        document
	                                                                                                        .getElementById(
	                                                                                                            "snackbar"
	                                                                                                        )
	                                                                                                    x.className =
	                                                                                                        "show";
	                                                                                                    x.innerHTML =
	                                                                                                        "Item does not exist!";
	                                                                                                    setTimeout
	                                                                                                        (function() {
	                                                                                                                x.className =
	                                                                                                                    x
	                                                                                                                    .className
	                                                                                                                    .replace(
	                                                                                                                        "show",
	                                                                                                                        ""
	                                                                                                                    );
	                                                                                                            },
	                                                                                                            3000
	                                                                                                        );
	                                                                                                }
	                                                                                            }
	                                                                                        }
	                                                                                    });
	                                                                                });
	                                                                        });
	                                                                        </script>
	                                                                        <!-- <input type="text" name="code_material[]"
	                                                                            placeholder="Code"
	                                                                            list="inventory_code_<?php echo $s;?>"
	                                                                            id="inventory_codes_<?php echo $s;?>"
	                                                                            class="form-control inventory_code_<?php echo $s;?> inventory_get_detail_<?php echo $s;?>"
	                                                                            style="width:100px" />
	                                                                        <datalist
	                                                                            id="inventory_code_<?php echo $s;?>"></datalist> -->
	                                                                        <select
	                                                                            class="form-control inventory_get_material_addrow2_<?php echo $s;?>"
	                                                                            name="code_material[]"
	                                                                            style="width: 100%;">
	                                                                            <option value="">Select Inventory</option>
	                                                                            <?php foreach ($inventory as $key => $value): ?>
	                                                                            <option value="<?php echo $value->ID ?>">
	                                                                                <?php echo $value->code.' - '.$value->name; ?>
	                                                                            </option>
	                                                                            <?php endforeach ?>

	                                                                        </select>
	                                                                    </td>
	                                                                    <td>
	                                                                        <script>
	                                                                        $(document).ready(function() {
	                                                                            $(".inventory_name_<?php echo $s;?>")
	                                                                                .bind('input', function(e) {
	                                                                                    var name = $(this)
	                                                                                        .val();
	                                                                                    $.ajax({
	                                                                                        type: "GET",
	                                                                                        dataType: "html",
	                                                                                        url: "<?php echo base_url();?>admin/transaction/get_name_inventory/<?php echo $menuid;?>",
	                                                                                        data: "name=" +
	                                                                                            name,
	                                                                                        success: function(
	                                                                                            msg
	                                                                                        ) {
	                                                                                            $("#inventory_name_<?php echo $s;?>")
	                                                                                                .html(
	                                                                                                    msg
	                                                                                                );
	                                                                                        }
	                                                                                    });
	                                                                                });
	                                                                            $(".inventory_name_get_detail_<?php echo $s;?>")
	                                                                                .focusout(function(e) {
	                                                                                    var name = $(this)
	                                                                                        .val();
	                                                                                    $.ajax({
	                                                                                        type: "POST",
	                                                                                        dataType: "html",
	                                                                                        url: "<?php echo base_url();?>admin/transaction/inventory_name_get_detail_3/<?php echo $menuid;?>",
	                                                                                        data: "name=" +
	                                                                                            name,
	                                                                                        success: function(
	                                                                                            msg
	                                                                                        ) {
	                                                                                            if (name ==
	                                                                                                ''
	                                                                                            ) {
	                                                                                                $("#inventory_codes_<?php echo $s;?>")
	                                                                                                    .val(
	                                                                                                        ''
	                                                                                                    );
	                                                                                                $("#qty_<?php echo $b;?>")
	                                                                                                    .val(
	                                                                                                        0
	                                                                                                    );
	                                                                                            } else {
	                                                                                                var data_inventory =
	                                                                                                    msg;
	                                                                                                var explode =
	                                                                                                    data_inventory
	                                                                                                    .split(
	                                                                                                        "%"
	                                                                                                    );
	                                                                                                var inventory_code =
	                                                                                                    explode[
	                                                                                                        0
	                                                                                                    ];
	                                                                                                var plan =
	                                                                                                    explode[
	                                                                                                        1
	                                                                                                    ];
	                                                                                                var check =
	                                                                                                    explode[
	                                                                                                        2
	                                                                                                    ];
	                                                                                                if (check ==
	                                                                                                    'exist'
	                                                                                                ) {
	                                                                                                    $("#inventory_codes_<?php echo $s;?>")
	                                                                                                        .val(
	                                                                                                            inventory_code
	                                                                                                        );
	                                                                                                    $(".unit_<?php echo $s;?>")
	                                                                                                        .html(
	                                                                                                            plan
	                                                                                                        );
	                                                                                                } else {
	                                                                                                    $("#inventory_codes_<?php echo $s;?>")
	                                                                                                        .val(
	                                                                                                            ''
	                                                                                                        );
	                                                                                                    $(".unit_<?php echo $s;?>")
	                                                                                                        .html(
	                                                                                                            '<input type="text" name="plan[]" class="form-control" style="width:100px;" />'
	                                                                                                        );
	                                                                                                    var x =
	                                                                                                        document
	                                                                                                        .getElementById(
	                                                                                                            "snackbar"
	                                                                                                        )
	                                                                                                    x.className =
	                                                                                                        "show";
	                                                                                                    x.innerHTML =
	                                                                                                        "Item does not exist!";
	                                                                                                    setTimeout
	                                                                                                        (function() {
	                                                                                                                x.className =
	                                                                                                                    x
	                                                                                                                    .className
	                                                                                                                    .replace(
	                                                                                                                        "show",
	                                                                                                                        ""
	                                                                                                                    );
	                                                                                                            },
	                                                                                                            3000
	                                                                                                        );
	                                                                                                }
	                                                                                            }
	                                                                                        }
	                                                                                    });

	                                                                                    $.ajax({
	                                                                                        type: "POST",
	                                                                                        dataType: "html",
	                                                                                        url: "<?php echo base_url();?>admin/transaction/inventory_name_get_detail_stock/<?php echo $menuid;?>",
	                                                                                        data: "name=" +
	                                                                                            name,
	                                                                                        success: function(
	                                                                                            msg
	                                                                                        ) {
	                                                                                            if (name ==
	                                                                                                ''
	                                                                                            ) {
	                                                                                                $("#inventory_codes_<?php echo $s;?>")
	                                                                                                    .val(
	                                                                                                        ''
	                                                                                                    );
	                                                                                                $("#qty_<?php echo $b;?>")
	                                                                                                    .val(
	                                                                                                        0
	                                                                                                    );
	                                                                                            } else {
	                                                                                                var data_inventory =
	                                                                                                    msg;
	                                                                                                var explode =
	                                                                                                    data_inventory
	                                                                                                    .split(
	                                                                                                        "%"
	                                                                                                    );
	                                                                                                var inventory_code =
	                                                                                                    explode[
	                                                                                                        0
	                                                                                                    ];
	                                                                                                var plan =
	                                                                                                    explode[
	                                                                                                        1
	                                                                                                    ];
	                                                                                                var check =
	                                                                                                    explode[
	                                                                                                        2
	                                                                                                    ];
	                                                                                                if (check ==
	                                                                                                    'exist'
	                                                                                                ) {
	                                                                                                    $("#inventory_codes_<?php echo $s;?>")
	                                                                                                        .val(
	                                                                                                            inventory_code
	                                                                                                        );
	                                                                                                    $(".availabe_<?php echo $s;?>")
	                                                                                                        .html(
	                                                                                                            plan
	                                                                                                        );
	                                                                                                } else {
	                                                                                                    $("#inventory_codes_<?php echo $s;?>")
	                                                                                                        .val(
	                                                                                                            ''
	                                                                                                        );
	                                                                                                    $(".availabe_<?php echo $s;?>")
	                                                                                                        .html(
	                                                                                                            '<input type="text" class="form-control" style="width:100px;" />'
	                                                                                                        );
	                                                                                                    var x =
	                                                                                                        document
	                                                                                                        .getElementById(
	                                                                                                            "snackbar"
	                                                                                                        )
	                                                                                                    x.className =
	                                                                                                        "show";
	                                                                                                    x.innerHTML =
	                                                                                                        "Item does not exist!";
	                                                                                                    setTimeout
	                                                                                                        (function() {
	                                                                                                                x.className =
	                                                                                                                    x
	                                                                                                                    .className
	                                                                                                                    .replace(
	                                                                                                                        "show",
	                                                                                                                        ""
	                                                                                                                    );
	                                                                                                            },
	                                                                                                            3000
	                                                                                                        );
	                                                                                                }
	                                                                                            }
	                                                                                        }
	                                                                                    });
	                                                                                });
	                                                                        });
	                                                                        </script>
	                                                                        <!-- <input type="text" name="item_material[]"
	                                                                            list="inventory_name_<?php echo $s;?>"
	                                                                            placeholder="Item"
	                                                                            id="inventory_names_<?php echo $s;?>"
	                                                                            class="form-control inventory_name_<?php echo $s;?> inventory_name_get_detail_<?php echo $s;?>"
	                                                                            style="width:250px" />
	                                                                        <datalist
	                                                                            id="inventory_name_<?php echo $s;?>"></datalist> -->
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        <input type="text"
	                                                                            class="form-control available_<?php echo $s;?>"
	                                                                            value="0" style="width:100px;" readonly />
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        <input type="text" name="plan[]"
	                                                                            class="form-control"
	                                                                            style="width:100px;" />
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        <input type="text"
	                                                                            class="form-control unit_<?php echo $s;?>"
	                                                                            style="width:100px;" readonly />
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        <input type="text" class="form-control"
	                                                                            name="pick_material_[]">
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        <input style="display: none;" type="text"
	                                                                            class="form-control" name="actual_[]">
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        0
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        0
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        0
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        -
	                                                                    </td>
	                                                                    <td align="center">
	                                                                        <button type="button"
	                                                                            class="btn btn-xs btn-danger hapus-row"><i
	                                                                                class="material-icons">clear</i></button>
	                                                                        <script type="text/javascript">
	                                                                        $(document).on('click', '.hapus-row',
	                                                                            function() {
	                                                                                $(this).parent().parent().remove();
	                                                                            });
	                                                                        </script>
	                                                                    </td>
	                                                                </tr>
	                                                                <?php
																}
															?>
	                                                            </tbody>
	                                                            <tfoot>
	                                                                <tr>
	                                                                    <td colspan="10">
	                                                                        <?php
						                                        				if($data_workorder[0]->finish != 0) {
						                                        					echo'';
						                                        				}else{
						                                        					?>
			                                                                        <a class="btn btn-primary addOption loading_btn"
			                                                                            onClick="clickME()"
			                                                                            data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing">
			                                                                            Add Row
			                                                                        </a>
			                                                                        <?php
						                                        				}
						                                        			?>
	                                                                        <script>
	                                                                        $('.loading_btn').on('click', function() {
	                                                                            var $this = $(this);
	                                                                            $this.button('loading');
	                                                                            setTimeout(function() {
	                                                                                $this.button('reset');
	                                                                            }, 500);
	                                                                        });
	                                                                        </script>
	                                                                        <script>
	                                                                        $(document).ready(function() {
	                                                                            var inc =
	                                                                                <?php echo $count_wo_material;?>;
	                                                                            $(".addOption").on('click',
	                                                                                function() {
	                                                                                    inc = inc + 1;
	                                                                                    $("#row3" + inc + "")
	                                                                                        .show();
	                                                                                });
	                                                                        });
	                                                                        </script>
	                                                                    </td>
	                                                                </tr>
	                                                                <tr>
	                                                                    <td colspan="6">
	                                                                        <strong>Note Material : </strong>
	                                                                        <input type="text" name="note_material"
	                                                                            class="form-control"
	                                                                            value="<?php echo $data_workorder[0]->note_material;?>" />
	                                                                    </td>
	                                                                    <td colspan="4" valign="middle">
	                                                                        <input type="submit"
	                                                                            class="btn btn-info btn-fill pull-right"
	                                                                            value="Save" id="save"
	                                                                            style="margin-top:10px;">
	                                                                        <a href="<?php echo base_url();?>admin/transaction/production/<?php echo $menuid;?>"
	                                                                            class="btn btn-danger pull-right"
	                                                                            style="margin:10px 5px 0 0;">Cancel</a>
	                                                                        <button type="reset"
	                                                                            class="btn btn-default pull-right"
	                                                                            style="margin:10px 5px 0 0;">Reset</button>

	                                                                        <a href="<?php echo base_url();?>admin/transaction/workorder_spk/<?php echo $menuid.'/'.$id_workorder;?>"
	                                                                            class="btn btn-primary pull-right"
	                                                                            style="margin:10px 5px 0 0;">Print SPK</a>
	                                                                    </td>
	                                                                </tr>
	                                                            </tfoot>
	                                                        </table>
	                                                    </div>
	                                                </div>
	                                            </div>
	                                        </div>
	                                        <div class="tab-pane" id="tab_2">
	                                            <div class="row">
	                                                <div class="col-md-12" style="overflow: auto; white-space: nowrap;">
	                                                    <div class="table-responsive">
	                                                        <table
	                                                            class="table table-bordered table-striped table-hover js-basic-example dataTable">
	                                                            <thead>
	                                                                <tr>
	                                                                    <th>No.</th>
	                                                                    <th>Code</th>
	                                                                    <th>Description</th>
	                                                                    <th>Supplier Code</th>
	                                                                    <th>Supplier Name</th>
	                                                                    <th>Schedule Date</th>
	                                                                    <th>Target Date</th>
	                                                                    <th>Start Date</th>
	                                                                    <th>End Date</th>
	                                                                    <th>Requested</th>

	                                                                    <th width="200">Done</th>
	                                                                    <th>Bad</th>
	                                                                    <th>@Cost</th>
	                                                                    <th>Internal</th>
	                                                                    <th>Total Labour</th>
	                                                                    <th>Paid</th>
	                                                                </tr>
	                                                            </thead>
	                                                            <tbody>
	                                                                <?php
																	$count=count($data_workorder_labour);
																	if($count==0) {
																		for($c=0; $c < 5; $c++) {
																			$d=$c+1;
																			$f=$c+40;
																			$g=$c+50;
																			if($d==1) {
																				$required='required="required"';
																			}else{
																				$required='';
																			}
																		?>
		                                                                <tr>
		                                                                    <td>
		                                                                        <?php echo $d;?>
		                                                                    </td>
		                                                                    <td>
		                                                                        <script>
		                                                                        $(document).ready(function() {
		                                                                            $(".labour_code_<?php echo $d;?>")
		                                                                                .bind('input', function(e) {
		                                                                                    var code = $(this)
		                                                                                        .val();
		                                                                                    $.ajax({
		                                                                                        type: "GET",
		                                                                                        dataType: "html",
		                                                                                        url: "<?php echo base_url();?>admin/transaction/get_code_inventory_2/<?php echo $menuid;?>",
		                                                                                        data: "code=" +
		                                                                                            code,
		                                                                                        success: function(
		                                                                                            msg
		                                                                                        ) {
		                                                                                            $("#labour_code_<?php echo $d;?>")
		                                                                                                .html(
		                                                                                                    msg
		                                                                                                );
		                                                                                        }
		                                                                                    });
		                                                                                });
		                                                                            $(".labour_get_detail_<?php echo $d;?>")
		                                                                                .focusout(function(e) {
		                                                                                    var code = $(this)
		                                                                                        .val();
		                                                                                    $.ajax({
		                                                                                        type: "POST",
		                                                                                        dataType: "html",
		                                                                                        url: "<?php echo base_url();?>admin/transaction/inventory_get_detail_2/<?php echo $menuid;?>",
		                                                                                        data: "code=" +
		                                                                                            code,
		                                                                                        success: function(
		                                                                                            msg
		                                                                                        ) {
		                                                                                            if (code ==
		                                                                                                ''
		                                                                                            ) {
		                                                                                                $("#labour_names_<?php echo $d;?>")
		                                                                                                    .val(
		                                                                                                        ''
		                                                                                                    );
		                                                                                            } else {
		                                                                                                var data_inventory =
		                                                                                                    msg;
		                                                                                                var explode =
		                                                                                                    data_inventory
		                                                                                                    .split(
		                                                                                                        "%"
		                                                                                                    );
		                                                                                                var inventory_name =
		                                                                                                    explode[
		                                                                                                        0
		                                                                                                    ];
		                                                                                                var check =
		                                                                                                    explode[
		                                                                                                        1
		                                                                                                    ];
		                                                                                                if (check ==
		                                                                                                    'exist'
		                                                                                                ) {
		                                                                                                    $("#labour_names_<?php echo $d;?>")
		                                                                                                        .val(
		                                                                                                            inventory_name
		                                                                                                        );
		                                                                                                } else {
		                                                                                                    $("#labour_names_<?php echo $d;?>")
		                                                                                                        .val(
		                                                                                                            ''
		                                                                                                        );
		                                                                                                    var x =
		                                                                                                        document
		                                                                                                        .getElementById(
		                                                                                                            "snackbar"
		                                                                                                        )
		                                                                                                    x.className =
		                                                                                                        "show";
		                                                                                                    x.innerHTML =
		                                                                                                        "Item does not exist!";
		                                                                                                    setTimeout
		                                                                                                        (function() {
		                                                                                                                x.className =
		                                                                                                                    x
		                                                                                                                    .className
		                                                                                                                    .replace(
		                                                                                                                        "show",
		                                                                                                                        ""
		                                                                                                                    );
		                                                                                                            },
		                                                                                                            3000
		                                                                                                        );
		                                                                                                }
		                                                                                            }
		                                                                                        }
		                                                                                    });
		                                                                                });
		                                                                        });
		                                                                        </script>
		                                                                        <input type="text" name="code_labour[]"
		                                                                            list="labour_code_<?php echo $d;?>"
		                                                                            placeholder="Code"
		                                                                            class="form-control labour_code_<?php echo $d;?> labour_get_detail_<?php echo $d;?>"
		                                                                            id="labour_codes_<?php echo $d;?>"
		                                                                            style="width:100px" value="" />
		                                                                        <datalist id="labour_code_1"></datalist>
		                                                                    </td>
		                                                                    <td>
		                                                                        <script>
		                                                                        $(document).ready(function() {
		                                                                            $(".labour_name_<?php echo $d;?>")
		                                                                                .bind('input', function(e) {
		                                                                                    var name = $(this)
		                                                                                        .val();
		                                                                                    $.ajax({
		                                                                                        type: "GET",
		                                                                                        dataType: "html",
		                                                                                        url: "<?php echo base_url();?>admin/transaction/get_name_inventory_2/<?php echo $menuid;?>",
		                                                                                        data: "name=" +
		                                                                                            name,
		                                                                                        success: function(
		                                                                                            msg
		                                                                                        ) {
		                                                                                            $("#labour_name_<?php echo $d;?>")
		                                                                                                .html(
		                                                                                                    msg
		                                                                                                );
		                                                                                        }
		                                                                                    });
		                                                                                });
		                                                                            $(".labour_name_get_detail_<?php echo $d;?>")
		                                                                                .focusout(function(e) {
		                                                                                    var name = $(this)
		                                                                                        .val();
		                                                                                    $.ajax({
		                                                                                        type: "POST",
		                                                                                        dataType: "html",
		                                                                                        url: "<?php echo base_url();?>admin/transaction/inventory_name_get_detail_2/<?php echo $menuid;?>",
		                                                                                        data: "name=" +
		                                                                                            name,
		                                                                                        success: function(
		                                                                                            msg
		                                                                                        ) {
		                                                                                            if (name ==
		                                                                                                ''
		                                                                                            ) {
		                                                                                                $("#labour_codes_<?php echo $d;?>")
		                                                                                                    .val(
		                                                                                                        ''
		                                                                                                    );
		                                                                                            } else {
		                                                                                                var data_inventory =
		                                                                                                    msg;
		                                                                                                var explode =
		                                                                                                    data_inventory
		                                                                                                    .split(
		                                                                                                        "%"
		                                                                                                    );
		                                                                                                var inventory_name =
		                                                                                                    explode[
		                                                                                                        0
		                                                                                                    ];
		                                                                                                var check =
		                                                                                                    explode[
		                                                                                                        1
		                                                                                                    ];
		                                                                                                if (check ==
		                                                                                                    'exist'
		                                                                                                ) {
		                                                                                                    $("#labour_codes_<?php echo $d;?>")
		                                                                                                        .val(
		                                                                                                            inventory_name
		                                                                                                        );
		                                                                                                } else {
		                                                                                                    $("#labour_codes_<?php echo $d;?>")
		                                                                                                        .val(
		                                                                                                            ''
		                                                                                                        );
		                                                                                                    var x =
		                                                                                                        document
		                                                                                                        .getElementById(
		                                                                                                            "snackbar"
		                                                                                                        )
		                                                                                                    x.className =
		                                                                                                        "show";
		                                                                                                    x.innerHTML =
		                                                                                                        "Item does not exist!";
		                                                                                                    setTimeout
		                                                                                                        (function() {
		                                                                                                                x.className =
		                                                                                                                    x
		                                                                                                                    .className
		                                                                                                                    .replace(
		                                                                                                                        "show",
		                                                                                                                        ""
		                                                                                                                    );
		                                                                                                            },
		                                                                                                            3000
		                                                                                                        );
		                                                                                                }
		                                                                                            }
		                                                                                        }
		                                                                                    });
		                                                                                });
		                                                                        });
		                                                                        </script>
		                                                                        <input type="text" name="item_labour[]"
		                                                                            list="labour_name_<?php echo $d;?>"
		                                                                            id="labour_names_<?php echo $d;?>"
		                                                                            placeholder="Desc"
		                                                                            class="form-control labour_name_<?php echo $d;?> labour_name_get_detail_<?php echo $d;?>"
		                                                                            style="width:250px" value="" />
		                                                                        <datalist id="labour_name_1"></datalist>
		                                                                    </td>
		                                                                    <script>
		                                                                    $(document).ready(function() {
		                                                                        $(".supplier_code_<?php echo $d;?>")
		                                                                            .bind('input', function(e) {
		                                                                                var code = $(this).val();
		                                                                                $.ajax({
		                                                                                    type: "GET",
		                                                                                    dataType: "html",
		                                                                                    url: "<?php echo base_url();?>admin/transaction/get_supplier/<?php echo $menuid;?>",
		                                                                                    data: "code=" +
		                                                                                        code,
		                                                                                    success: function(
		                                                                                        msg) {
		                                                                                        $("#supplier_code_<?php echo $d;?>")
		                                                                                            .html(
		                                                                                                msg
		                                                                                            );
		                                                                                    }
		                                                                                });
		                                                                            });
		                                                                    });
		                                                                    </script>
		                                                                    <td>
		                                                                        <input type="text"
		                                                                            name="supplier_code_labour[]"
		                                                                            list="supplier_code_<?php echo $d;?>"
		                                                                            placeholder="Supplier"
		                                                                            class="form-control supplier_code_<?php echo $d;?>"
		                                                                            style="width:100px" />
		                                                                        <datalist
		                                                                            id="supplier_code_<?php echo $d;?>"></datalist>
		                                                                    </td>
		                                                                    <td>
		                                                                        <input type="text" name="supplier[]"
		                                                                            list="supplier_code_<?php echo $d;?>"
		                                                                            placeholder="Supplier"
		                                                                            class="form-control supplier_code_<?php echo $d;?>"
		                                                                            style="width:100px" />
		                                                                        <datalist
		                                                                            id="supplier_name_<?php echo $d;?>"></datalist>
		                                                                    </td>
		                                                                    <td>
		                                                                        <input type="text" name="schedule[]"
		                                                                            placeholder="Schedule"
		                                                                            id="datepicker<?php echo $f;?>"
		                                                                            class="form-control datepicker"
		                                                                            style="width:100px" value="" />
		                                                                    </td>
		                                                                    <td>
		                                                                        <input type="text" name="target[]"
		                                                                            placeholder="Target"
		                                                                            id="datepicker<?php echo $g;?>"
		                                                                            class="form-control datepicker"
		                                                                            style="width:100px" />
		                                                                    </td>
		                                                                    <td align="center">
		                                                                        -
		                                                                    </td>
		                                                                    <td align="center">
		                                                                        -
		                                                                    </td>
		                                                                    <td align="center">
		                                                                        0
		                                                                    </td>

		                                                                    <td align="center">
		                                                                        0
		                                                                    </td>
		                                                                    <td align="center">
		                                                                        0
		                                                                    </td>
		                                                                    <td>
		                                                                        <input type="text" name="price[]"
		                                                                            placeholder="Price" class="form-control"
		                                                                            style="width:100px" />
		                                                                    </td>
		                                                                    <td align="center">
		                                                                        <script>
		                                                                        $(function() {
		                                                                            $(".internal<?php echo $d;?>")
		                                                                                .click(function() {
		                                                                                    var internal = $(
		                                                                                        "#internal<?php echo $d;?>"
		                                                                                    ).val();
		                                                                                    var x = document
		                                                                                        .getElementById(
		                                                                                            "snackbar4")
		                                                                                    x.className = "show";
		                                                                                    x.innerHTML =
		                                                                                        "Internal success change!";
		                                                                                    setTimeout(function() {
		                                                                                        x.className =
		                                                                                            x
		                                                                                            .className
		                                                                                            .replace(
		                                                                                                "show",
		                                                                                                ""
		                                                                                            );
		                                                                                    }, 3000);
		                                                                                    if (internal == 0) {
		                                                                                        $("#change_icon<?php echo $d;?>")
		                                                                                            .html(
		                                                                                                '<i class="fa fa-check-square-o" aria-hidden="true"></i>'
		                                                                                            );
		                                                                                        $("#internal<?php echo $d;?>")
		                                                                                            .val(1);
		                                                                                    } else {
		                                                                                        $("#change_icon<?php echo $d;?>")
		                                                                                            .html(
		                                                                                                '<i class="fa fa-square-o" aria-hidden="true"></i>'
		                                                                                            );
		                                                                                        $("#internal<?php echo $d;?>")
		                                                                                            .val(0);
		                                                                                    }
		                                                                                });
		                                                                        });
		                                                                        </script>
		                                                                        <a class="text-blue internal<?php echo $d;?>"
		                                                                            id="change_icon<?php echo $d;?>"
		                                                                            style="cursor:pointer">
		                                                                            <i class="fa fa-square-o"
		                                                                                aria-hidden="true"></i>
		                                                                        </a>
		                                                                        <input type="hidden" name="internal[]"
		                                                                            value="0" id="internal<?php echo $d;?>" />
		                                                                    </td>
		                                                                    <td align="right">
		                                                                        0
		                                                                    </td>
		                                                                    <td align="right">
		                                                                        0
		                                                                    </td>
		                                                                </tr>
	                                                                <?php
																		}
																	} else {
																		$paid_total=0;
																		for($b=0; $b < count($data_workorder_labour); $b++) {
																			// echo "<pre>";
																			// print_r($data_workorder_labour);
																			$id_labour=$data_workorder_labour[$b]->ID;
																			$internal=$data_workorder_labour[$b]->internal;
																			$c=$b+1;
																			$d=$c+1;
																			$f=$c+40;
																			$g=$c+50;
																			$h=$d+40;					
																			if($data_workorder_labour[$b]->schedule_date=='0000-00-00') {
																				$schedule_date='
																				<input type="text" name="schedule[]" placeholder="Schedule" id="datepicker'.$f.'" class="form-control datepicker" style="width:100px" value=""/>';
																			} else	{
																				$schedule_date=date('m/d/Y', strtotime($data_workorder_labour[$b]->schedule_date)).'
																				<input type="hidden" name="schedule[]" placeholder="Schedule"  class="form-control" style="width:100px" value="'.$data_workorder_labour[$b]->schedule_date.'"/>';
																			}
																			if($data_workorder_labour[$b]->target_date=='0000-00-00'){
																					$target_date='
																				<input type="text" name="target[]" placeholder="Target" id="datepicker'.$g.'" class="form-control datepicker" style="width:100px"/>';
																			} else {
																				$target_date=date('m/d/Y', strtotime($data_workorder_labour[$b]->target_date)).'
																				<input type="hidden" name="target[]" placeholder="Target"  class="form-control" style="width:100px" value="'.$data_workorder_labour[$b]->target_date.'"/>';
																			}
																			if($data_workorder_labour[$b]->requested == 0){
																				$requested=$data_workorder[0]->target_pcs;
																			} else	{
																				$requested=$data_workorder_labour[$b]->requested;
																			}
																			$paid_total=$paid_total+$data_workorder_labour[$b]->paid;
																		 	@$sum_qty_labour_detail = $this->master_model->select_in('ts_workorder_labour_detail', 'SUM(qty) AS qty_labour_detail', "WHERE id_workorder_labour=$id_labour");
																			// 			echo "<pre>";
																			// print_r($sum_qty_labour_detail);
																			// die();
																			@$qty_labour_detail=$sum_qty_labour_detail[0]->qty_labour_detail;
																			@$bad_2= $requested - $qty_labour_detail;
																			 $data_workorder_labour_detail=$this->master_model->select_in('ts_workorder_labour_detail', 'SUM(qty), any_value(price) as price', "WHERE id_workorder_labour=$id_labour ORDER BY `ID` DESC LIMIT 1");
																		 	$price_labour_detail=$data_workorder_labour_detail[0]->price;

																			// if($data_workorder_labour[$b]->start_date=='0000-00-00' || ! empty($qty_labour_detail))
																			if($data_workorder_labour[$b]->start_date==''){
																				// $start_date='';
																				$start_date=date('m/d/Y', strtotime($data_workorder_labour[$b]->schedule_date));
																			}else{
																				$start_date=date('m/d/Y', strtotime($data_workorder_labour[$b]->start_date));
																			}

																			// if($data_workorder_labour[$b]->end_date=='0000-00-00' || ! empty($qty_labour_detail))
																			if($data_workorder_labour[$b]->end_date == ''){
																				$end_date=date('m/d/Y', strtotime($data_workorder_labour[$b]->target_date));
																			}else{
																				$end_date=date('m/d/Y', strtotime($data_workorder_labour[$b]->end_date));
																			}
																			
																			echo'
																				<tr>
																					<td>
																						'.$c.'
																						<input type="hidden" name="id_labour[]" value="'.$id_labour.'">
																					</td>
																					<td>
																						'.$data_workorder_labour[$b]->code_inventory.'
																						<input type="hidden" name="code_labour[]" value="'.$data_workorder_labour[$b]->code_inventory.'">
																					</td>
																					<td>
																						'.$data_workorder_labour[$b]->name_inventory.'
																						<input type="hidden" name="item_labour[]" value="'.$data_workorder_labour[$b]->name_inventory.'">
																					</td>
					                                                        		<td>
					                                                        			<script>
															                                $(document).ready(function(){
															                                    $(".supplier_code'.$b.'").bind("input", function(e){
															                                        var code = $(this).val();
															                                        $.ajax({
															                                            type: "GET",
															                                            dataType: "html",
															                                            url: "'.base_url().'admin/transaction/get_supplier/'.$menuid.'",
															                                            data:"code="+code,
															                                            success: function(msg){
															                                                $("#supplier_code'.$b.'").html(msg);
															                                            }
															                                        });
															                                    });
															                                    $(".supplier_get_po_2'.$b.'").focusout(function(e){
															                                        var code = $(this).val();
																									$.ajax({
																										type: "POST",
																										dataType: "html",
																										url: "'.base_url().'admin/transaction/supplier_get_detail/'.$menuid.'",
																										data:"code="+code,
																										success: function(msg)
																											if(code==""){
																												$("#supplier_name_2'.$b.'").val("");
																												$(".payment_terms'.$b.'").val("");
																											}else{
																												var data_supplier = msg;
																												var explode = data_supplier.split("%");
																											    var supplier_name  = explode[0];
																												var payment_terms  = explode[1];
																												var check = explode[2];
																												if(check=="exist"){
																													$("#supplier_name_2'.$b.'").val(supplier_name);
																												}else{
																													$("#supplier_code_2'.$b.'").val("");
																													$("#supplier_name_2'.$b.'").val("");

																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Supplier code is missing!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										}
																									});
															                                    });
															                                });
															                            </script>
																						';
																						if($qty_labour_detail == 0){
																							$readonly_code = '';
																						}else {
																							$readonly_code = 'readonly="readonly"';
																						}
																						echo'
																					    <input type="text" name="supplier_code_labour[]" list="supplier_code'.$b.'" id="supplier_code_2'.$b.'" class="form-control supplier_code'.$b.' supplier_get_po_2'.$b.'" placeholder="Supplier Code" value="'.$data_workorder_labour[$b]->code_supplier.'" '.$readonly_code.'>
																					    <datalist id="supplier_code'.$b.'"></datalist>
																					</td>
																					<td>
																						<script>
																							$(document).ready(function(){
																							  	$(".supplier_name'.$b.'").bind("input", function(e){
																							  		var name = $(this).val();
																							    	$.ajax({
																							    		type: "GET",
																						        		dataType: "html",
																						        		url: "'.base_url().'admin/transaction/get_supplier_2/'.$menuid.'",
																						        		data:"name="+name,
																						       			success: function(msg){
																								        	$("#supplier_name'.$b.'").html(msg);
																								        }
															                                        });
															                                    });

																								$(".supplier_get_po'.$b.'").focusout(function(e){
  																									var name = $(this).val();

																									$.ajax({
																									 	type: "POST",
																									 	dataType: "html",
																								 		url: "'.base_url().'admin/transaction/supplier_get_detail_2/'.$menuid.'",
																										data:"name="+name,
																										success: function(msg){
																											if(name==""){
																												$("#supplier_code_2'.$b.'").val("");
																											}else{
																												var data_supplier = msg;
																												var explode = data_supplier.split("%");

																												var supplier_code  = explode[0];
																												var payment_terms  = explode[1];
																												var check = explode[2];

																												if(check=="exist"){
																													$("#supplier_code_2'.$b.'").val(supplier_code);
																												}else{
																													$("#supplier_name_2'.$b.'").val("");
																													$("#supplier_code_2'.$b.'").val("");
																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Supplier name is missing!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										}
																									});
															                                    });
															                                });
															                            </script>
															                            ';
														                            	$code_supplier=$data_workorder_labour[$b]->code_supplier;
														                            	if($code_supplier==''){
														                            		$name_supplier='';
														                            	}else{
														                            		$get_name_supplier=$this->master_model->select_in('ms_supplier', 'name', "WHERE code='$code_supplier'");
														                            		$name_supplier=$get_name_supplier[0]->name;
														                            	}
														                            	echo'
																							<input type="text" name="supplier[]" list="supplier_name'.$b.'" id="supplier_name_2'.$b.'" class="form-control supplier_name'.$b.' supplier_get_po'.$b.'" placeholder="Supplier Name" value="'.$name_supplier.'" '.$readonly_code.'>
															                            <datalist id="supplier_name'.$b.'"></datalist>
									                                                </td>
																					<td>
																					   '.$schedule_date.'
																					</td>
																					<td>
																					   '.$target_date.'
																					</td>
																					<td>
																						<input type="text" name="start_date[]" placeholder="Start Date" id="datepicker3" '.$f.' class="form-control datepicker3" style="width:100px" value="'.$start_date.'"/>
																					</td>

																					<script type="text/javascript">
										                                                $(function(){
										                                                    $(".datepicker3").datepicker();
										                                                });
										                                            </script>

																					<td>
																						<input type="text" name="end_date[]" placeholder="End Date" id="datepicker4"'.$g.' class="form-control datepicker4" style="width:100px" value="'.$end_date.'"/>
																					</td>
																					<script type="text/javascript">
										                                                $(function(){
										                                                    $(".datepicker4").datepicker();
										                                                });
										                                            </script>
																					';
																					if($data_workorder_labour[0]->requested == 0){
																						$display='display:none';
																						$finish=0;
																						$disable_save='disabled="disabled"';
																					}else{
																						$display='display:block';
																						$finish=$data_workorder[0]->target_pcs;
																						$disable_save='disabled="disabled"';
																					}
																					if($data_workorder_labour_total->total_labour == 1){
																						echo'
																						<td align="center">
																								<script>
																									$(function(){
																										$(".requested'.$c.'").focusout(function(){
																										   var done = $("#done'.$c.'").val();
																										   var requested = $(this).val();

																										   var bad=requested-done;

																										   $( "#next_'.$b.'" ).show();

																										   $(".requested_2_'.$h.'").html(done);
																										   $(".requested_3_'.$h.'").val(done);

																										   $(".bad'.$c.'").html(bad);
																										   $("#bad'.$c.'").val(bad);

																										   $(".target_pcs_header").val(requested);

																										   //$("#done'.$c.'").focus();
																										});
																									});
																								</script>
																							<input type="text" name="requested[]" placeholder="Requested" class="form-control requested'.$c.'" style="width:50px" value="'.$requested.'" id="requested'.$c.'"/>
																						</td>
																						<td align="center">
																							<script>
																								$(function(){
																									$(".done'.$c.'").focusout(function(){
																								   		var requested = $("#requested'.$c.'").val();
																								   		var done = $(this).val();
																								   		var price = $("#price_'.$c.'").val();
																								   		var bad_bottom = $("#bad'.$d.'").val();
																								   		var done_bottm = done-bad_bottom;
																								   		var bad=requested-done;
																								   		$( "#next_'.$h.'" ).show();
																								   		if(done > parseFloat(requested)){
																											var x = document.getElementById("snackbar")
																											x.className = "show";
																											x.innerHTML = "Done should not be greater than requested!";
																											setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																											$(".requested_2_'.$h.'").html(requested);
																										   	$(".requested_3_'.$h.'").val(requested);
																										   	$(".bad'.$c.'").html(0);
																										   	$("#bad'.$c.'").val(0);
																										   	$("#done'.$c.'").val(requested);
																										   	$("#done'.$d.'").val(done_bottm);
																											//$("#done'.$d.'").focus();
																											//$(".target_pcs").html(requested);
																											//$("#target_pcs").val(requested);
																											$(".finish").val(requested);
																											$("#gross_ammount_'.$c.'").html(addCommas(price*done_top));
																											$("#gross_ammount_val_'.$c.'").val(price*done_top);
																										}else{
																										   	$(".requested_2_'.$h.'").html(done);
																										   	$(".requested_3_'.$h.'").val(done);
																										   	$(".bad'.$c.'").html(bad);
																										   	$("#bad'.$c.'").val(bad);
																											$("#done'.$c.'").val(done);
																											$("#done'.$d.'").val(done_bottm);
																										   	//$("#done'.$d.'").focus();
																										   	//$(".target_pcs").html(done);
																											//$("#target_pcs").val(done);
																										   $(".finish").val(done);
																										   var gross=price*done;
																										   var gross_ammount=gross.toString().replace(/[.]/, ",");
																										   $("#gross_ammount_'.$c.'").html(addCommas(gross_ammount));
																										   $("#gross_ammount_val_'.$c.'").val(price*done);
																									   	}
																									   	$("#update_total_labour").trigger("click");
																									   	$(".save").attr("disabled", true);
																									});
																								});
																							</script>
																							<script>
																								$(function(){
																									$(".pick_labour_'.$c.'").click(function(){
																									   var ID = $(this).attr("alt");
																									   var count = '.$count.';
																									   var loop = '.$c.';
																									   if(count == loop){
																									   	  var count_loop = "Yes";
																									   }else{
																									   	  var count_loop = "No";
																									   }
																									   //alert(count_loop);
																									   //return false;
																									   var code_supplier = $("#supplier_code_2'.$b.'").val();
																									   var date_in = '.$today.';
																									   var requested = $("#requested'.$c.'").val();
																									   var price = $("#price_'.$c.'").val();
																									   var ID = ID+"--"+code_supplier+"--"+date_in+"--"+requested+"--"+price;
																									   //alert(date_in);
																									   //return false;
																									   $.ajax({
																											type: "POST",
																											dataType: "html",
																											url: "'.base_url().'admin/transaction/production_labour_pick/'.$menuid.'/'.$id_workorder.'/"+count_loop,
																											data: "ID="+ID,
																											success: function(data){
																												$(".labour-content").html(data);
																											}
																										});
																									});
																								});
																							</script>
																							<div class="input-group">
																								<span alt="'.$id_labour.'" class="input-group-addon pick_labour_'.$c.'" style="cursor:pointer; font-size:10px" data-toggle="modal" data-target="#labour-modal" >
																								<i class="fa fa-fw fa-plus"></i>
																								</span>
																								<input type="text" name="done[]" placeholder="Done" class="form-control pull-left" style="width:55px" value="'.$qty_labour_detail.'" id="done'.$c.'" readonly="readonly"/>
																								<script>
																									$(function(){
																										$(".next_'.$b.'").click(function(){
																										   	var done = $("#done'.$c.'").val();
																										   	$(".requested_2_'.$h.'").html(done);
																										   	$(".requested_3_'.$h.'").val(done);
																										});
																										$( ".next_'.$b.'" ).trigger( "click" );
																									});
																								</script>
                                                                                                <script>
                                                                                                    $(function(){
                                                                                                        $(".update_finish_").click(function(){
                                                                                                            var done = $("#done'.$c.'").val();
                                                                                                            $.ajax({
                                                                                                                type: "POST",
                                                                                                                dataType: "html",
                                                                                                                url: "'.base_url().'admin/transaction/update_finish/'.$menuid.'/'.$id_workorder.'",
                                                                                                                data:"done="+done,
                                                                                                                success: function(msg){
                                                                                                                    var x = document.getElementById("snackbar")
                                                                                                                    x.className = "show";
                                                                                                                    x.innerHTML = "Finish successfully update!";
                                                                                                                    setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
                                                                                                                    $(".finish").val(done);
                                                                                                                }
                                                                                                            });
                                                                                                        });
                                                                                                    });
                                                                                                </script>
																								<span class="input-group-addon update_finish_" style="cursor:pointer; padding:0 15px"" id="update_finish">
																									<i class="fa fa-level-up next_'.$b.'" style="cursor:pointer;" id="next_'.$b.'" aria-hidden="true"></i>
																								</span>
																							</div>
																						</td>';
																					} else {
																						echo'
																						<td align="center" class="requested_2_'.$f.'">
																							'.$data_workorder_labour[$b]->requested.'
																						</td>
																						<td align="center">
																							<input type="hidden" name="requested[]" style="width:50px" class="requested_3_'.$f.'" value="'.$data_workorder_labour[$b]->requested.'" id="requested_3_'.$f.'">
																							<script>
																								$(function(){
																									$(".done'.$c.'").focusout(function(){
																									   	var done_top = $("#requested_3_'.$f.'").val();
																									   	var done = $(this).val();

																									   	var bad_bottom = $("#bad'.$d.'").val();
																									   	var done_bottm = done-bad_bottom;

																									   	var price = $("#price_'.$c.'").val();

																									   	var done_bottom_2= done_top-bad_bottom;

																									   	var bad=done_top-done;

																									   	$( "#next_'.$h.'" ).show();

																									   	if(done > parseFloat(done_top)){
																										   	var x = document.getElementById("snackbar")
																											x.className = "show";
																											x.innerHTML = "Done should not be greater than requested!";
																											setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);

																											$(".requested_2_'.$h.'").html(done_top);
																										   	$(".requested_3_'.$h.'").val(done_top);

																										   	$(".bad'.$c.'").html(0);
																										   	$("#bad'.$c.'").val(0);

																										   	$("#done'.$c.'").val(done_top);

																										   	$("#done'.$d.'").val(done_bottom_2);
																										   	//$("#done'.$d.'").focus();

																										   	//$(".target_pcs").html(done_top);
																										   	//$("#target_pcs").val(done_top);
																										   	$(".finish").val(done_top);
																										   	$("#gross_ammount_'.$c.'").html(addCommas(price*done_top));
																										   	$("#gross_ammount_val_'.$c.'").val(price*done_top);
																									   	}else{
																										   	$(".requested_2_'.$h.'").html(done);
																										   	$(".requested_3_'.$h.'").val(done);

																										   	$(".bad'.$c.'").html(bad);
																										   	$("#bad'.$c.'").val(bad);

																										   	$("#done'.$c.'").val(done);

																										   	$("#done'.$d.'").val(done_bottm);
																										   	//$("#done'.$d.'").focus();

																										   	//$(".target_pcs").html(done);
																										   	//$("#target_pcs").val(done);
																										   	$(".finish").val(done);

																										   	var gross=price*done;

																										   	var gross_ammount=gross.toString().replace(/[.]/, ",");

																										   	$("#gross_ammount_'.$c.'").html(addCommas(gross_ammount));

																											   $("#gross_ammount_val_'.$c.'").val(price*done);
																										}

																								   		var count_labour='.$c.';
																								   		var total_count_labour='.($count-$b).';

																								   		var total_count_labour_end='.$count.';


																								   		if(count_labour == total_count_labour){
																									   		if(done > parseFloat(done_top)){
																										   		$(".target_pcs").html(done_bottom_2);
																										   		$("#target_pcs").val(done_bottom_2);

																										   		$(".finish").html(done_bottom_2);
																									   		}else{
																										   		$(".target_pcs").html(done_bottm);
																									   	   		$("#target_pcs").val(done_bottm);

																										   		$(".finish").html(done_bottm);
																									   		}

																									   		$(".save").removeAttr("disabled");
																								   		}else if(count_labour == total_count_labour_end){
																									   		if(done > parseFloat(done_top)){
																										   		$(".target_pcs").html(done_top);
																										   		$("#target_pcs").val(done_top);

																										   		$(".finish").html(done_top);
																									   		}else{
																										   		$(".target_pcs").html(done);
																										   		$("#target_pcs").val(done);
																										   		$(".finish").html(done);
																									   		}

																									   		$(".save").removeAttr("disabled");
																								   		}

																										$("#update_total_labour").trigger("click");
																									});
																								});
																							</script>

																							<script>
																								$(function(){
																									$("#pick_labour_'.$f.'").click(function(){
																									   var ID = $(this).attr("alt");
																									   var count = '.$count.';
																									   var loop = '.$c.';

																									   //alert(count);
																									   //return false;

																									   	if(count == loop){
																									   	  	var count_loop = "Yes";

																									   	  	//alert("Yes");
																									   	  	//return false;
																									   	}else{
																									   	  	var count_loop = "No";

																									   	  	//alert("No");
																									   	  	//return false;
																									   	}

																									   	//alert(count_loop);
																									   	//return false;

																									   	var code_supplier = $("#supplier_code_2'.$b.'").val();
																									   	var date_in = '.$today.';
																									   	var requested = $("#requested_3_'.$f.'").val();
																									   	var price = $("#price_'.$c.'").val();

																									   	var ID = ID+"--"+code_supplier+"--"+date_in+"--"+requested+"--"+price;

																									   	//alert(ID);
																									   	//return false;

																									   	$.ajax({
																											type: "POST",
																											dataType: "html",
																											url: "'.base_url().'admin/transaction/production_labour_pick/'.$menuid.'/'.$id_workorder.'/"+count_loop,
																											data: "ID="+ID,
																											success: function(data){
																												$(".labour-content").html(data);
																											}
																										});
																									});
																								});
																							</script>
																							';
											                                					if($count==$c){
																									echo'

																									';
																								}else{
																									echo'';
																								}
																							echo'
																							<div class="input-group">
																								<span alt="'.$id_labour.'"  class="input-group-addon" style="cursor:pointer; font-size:10px" id="pick_labour_'.$f.'" data-toggle="modal" data-target="#labour-modal">
																									<i class="fa fa-fw fa-plus"></i>
																								</span>
																								<input type="text" name="done[]" placeholder="Done" class="form-control pull-left" style="width:55px" value="'.$qty_labour_detail.'" id="done'.$c.'" readonly/>

																								<script>
																									$(function(){
																										$(".next_'.$f.'").click(function(){
																										   var done = $("#done'.$c.'").val();

																										   // alert(done);
																										   //return false;

																										   $(".requested_2_'.$h.'").html(done);
																										   $(".requested_3_'.$h.'").val(done);
																										});

																										$( ".next_'.$f.'" ).trigger( "click" );
																									});
																								</script>
																								';
														                                		if($count==$c){
																									echo'
																									<script>
																										$(function(){
																											$(".update_finish").click(function(){
  																												var done = $("#done'.$c.'").val();
																												$.ajax({
																												 	type: "POST",
																												 	dataType: "html",
																												 	url: "'.base_url().'admin/transaction/update_finish/'.$menuid.'/'.$id_workorder.'",
																												 	data:"done="+done,
																												 	success: function(msg){
																												 		var x = document.getElementById("snackbar")
																														x.className = "show";
																														x.innerHTML = "Finish successfully update!";
																														setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												   		$(".finish").val(done);
																												 	}
																												});
																											});
																										});
																									</script>
																									<span class="input-group-addon update_finish" style="cursor:pointer; padding:0 15px"" id="update_finish">
																										<i class="fa fa-level-up" aria-hidden="true"></i>
																									</span>
																								';
																								}else{
																									echo'
																									<span class="input-group-addon next_'.$f.'" style="cursor:pointer; padding:0 15px"" id="next_'.$f.'">
																										<i class="fa fa-level-down" aria-hidden="true"></i>
																									</span>';
																								}
																								echo'

																							</div>
																						</td>
																						';
																					}
																					echo'
																					<td class="bad'.$c.'">
																						';
																						if($start_date=='' || $end_date==''){
																							echo "0";
																							// date_default_timezone_set('Asia/Jakarta'); echo $date_now = date('Y-m-d h:i:s');
																						}else{
																							echo $bad_2;
																						}
																						echo'
																					</td>
																					<td>
																						<script>
																							$(function(){
																								$(".price'.$c.'").focusout(function(){
																								 	var price = $(this).val();
																									var done = $("#done'.$c.'").val();

																									var price=price.toString().replace(/[,]/, ".");

																									var gross=parseFloat(price)*parseFloat(done);

																									//alert(gross);
																									//return false;

																									var gross_ammount=gross.toString().replace(/[.]/, ",");

																									$("#gross_ammount_'.$c.'").html(addCommas(gross_ammount));

																									$("#gross_ammount_val_'.$c.'").val(price*done);

																									$("#update_total_labour").trigger("click");
																								});
																							});
																						</script>
																						<input type="text" name="price[]" placeholder="Cost" class="form-control price'.$c.'" style="width:100px" id="price_'.$c.'" value="'.$price_labour_detail.'" readonly="readonly"/>
																					</td>

																					<td align="center">
																						<input type="hidden" name="bad[]" style="width:50px" value="'.$bad_2.'" id="bad'.$c.'">
																						<script>
																							$(function(){
																								$(".internal'.$c.'").click(function(){
																									var ID = $(this).attr("alt");

																									$.ajax({
																										type: "POST",
																										dataType: "html",
																										url: "'.base_url().'admin/transaction/change_internal/'.$menuid.'",
																										data:"ID="+ID,
																										success: function(msg){
																											var x = document.getElementById("snackbar")
																											x.className = "show";
																											x.innerHTML = "Internal success change!";
																											setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																											var internal = msg;
																											var explode = internal.split("%");
																											var icon  = explode[0];
																											var inter  = explode[1];

																											$("#change_icon'.$c.'").html(icon);
																											$("#internal'.$c.'").val(inter);
																										}
																									});
																								});
																							});
																						</script>

																						';
																						if($internal==0){
																							$icon='<i class="fa fa-square-o" aria-hidden="true"></i>';
																						}else{
																							$icon='<i class="fa fa-check-square-o" aria-hidden="true"></i>';
																						}
																						echo'

																						<a alt="'.$id_labour.'" class="text-blue internal'.$c.'" id="change_icon'.$c.'" style="cursor:pointer">
																							'.$icon.'
																						</a>

																						<input type="hidden" name="internal[]" style="width:50px" value="'.$internal.'" id="internal'.$c.'">

																						<input type="hidden" name="gross_ammount[]" value="'.$data_workorder_labour[$b]->gross_ammount.'" id="gross_ammount_val_'.$c.'">
																					</td>
																					<td align="right" style="font-weight:bold" id="gross_ammount_'.$c.'">
																						'.number_format($data_workorder_labour[$b]->gross_ammount).'

																						';

											                                			if($control == 'production'){
											                                					echo'';
											                                			}else{
											                                				if($count==$c){
																									echo'
																										<a href="'.base_url().'admin/transaction/delete_labour/'.$menuid.'/'.$id_workorder.'/'.$id_labour.'" style="margin-left:10px; cursor:pointer; float:right">
																											<i class="fa fa-trash text-red" aria-hidden="true"></i>
																										</a>
																									';
																							}else{
																								echo'';
																							}
											                                			}

																						echo'
																					</td>
																					<td align="right" style="font-weight:bold">
					                                                                	'.number_format($data_workorder_labour[$b]->paid).'
					                                                            	</td>
																				</tr>

																			';
																		}


																		for($a=0; $a < 20-$count; $a++) {
																			$b=$a+1+$count;

																			$h=$a+45;
																			$i=$a+55;

																			$j=$a+40;
																			$k=$a+50;
																			?>
																				<tr id="row2<?php echo $b; ?>" style="display:none">
																					<td>
																						<?php echo $b; ?>
																					</td>
																					<td>
																						<script>
																							$(document).ready(function(){
																								$(".labour_code_<?php echo $b; ?>").bind("input", function(e){
																									var code = $(this).val();
																									$.ajax({
																										type: "GET",
																										dataType: "html",
																										url: "'.base_url().'admin/transaction/get_code_inventory_2/<?php echo $menuid; ?>",
																										data:"code="+code,
																										success: function(msg){
																											$("#labour_code_<?php echo $b; ?>").html(msg);
																										}
																									});
																								});

																								$(".labour_get_detail_<?php echo $b; ?>").focusout(function(e){
																									var code = $(this).val();

																									$.ajax({
																										type: "POST",
																										dataType: "html",
																										url: "'.base_url().'admin/transaction/inventory_get_detail_2/<?php echo $menuid; ?>",
																										data:"code="+code,
																										success: function(msg){
																											if(code==""){
																												$("#labour_names_<?php echo $b; ?>").val("");
																											}else{
																												var data_inventory = msg;
																												var explode = data_inventory.split("%");

																												var inventory_name  = explode[0];
																												var check   		   = explode[1];

																												if(check=="exist"){
																													$("#labour_names_<?php echo $b; ?>").val(inventory_name);
																												}else{
																													$("#labour_names_<?php echo $b; ?>").val("");

																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Item does not exist!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										}
																									});
																								});
																							});
																						</script>
																						<!-- <input type="text" name="code_labour[]" list="labour_code_<?php echo $b; ?>" placeholder="Code" class="form-control labour_code_<?php echo $b; ?> labour_get_detail_<?php echo $b; ?>" id="labour_codes_<?php echo $b; ?>" style="width:100px" value=""/>
																						<datalist id="labour_code_<?php echo $b; ?>"></datalist> -->
																						<select
				                                                                            class="form-control inventory_get_labour_addrow2_<?php echo $b;?>"
				                                                                            name="code_labour[]" style="width: 100%;">
				                                                                            <option value="">Select Inventory</option>
				                                                                            <?php foreach ($inventory_labour as $key => $value): ?>
				                                                                            <option value="<?php echo $value->ID ?>">
				                                                                                <?php echo $value->code.' - '.$value->name; ?>
				                                                                            </option>
				                                                                            <?php endforeach ?>

				                                                                        </select>
																					</td>
																					<td>
																						<script>
																							$(document).ready(function(){
																								$(".labour_name_<?php echo $b; ?>").bind("input", function(e){
																									var name = $(this).val();
																									$.ajax({
																										type: "GET",
																										dataType: "html",
																										url: "'.base_url().'admin/transaction/get_name_inventory_2/<?php echo $menuid; ?>",
																										data:"name="+name,
																										success: function(msg){
																											$("#labour_name_<?php echo $b; ?>").html(msg);
																										}
																									});
																								});

																								$(".labour_name_get_detail_<?php echo $b; ?>").focusout(function(e) {
																									var name = $(this).val();

																									$.ajax({
																										type: "POST",
																										dataType: "html",
																										url: "'.base_url().'admin/transaction/inventory_name_get_detail_2/<?php echo $menuid; ?>",
																										data:"name="+name,
																										success: function(msg){
																											if(name==""){
																												$("#labour_codes_<?php echo $b; ?>").val("");
																											}else{
																												var data_inventory = msg;
																												var explode = data_inventory.split("%");

																												var inventory_name  = explode[0];
																												var check   		   = explode[1];

																												if(check=="exist"){
																													$("#labour_codes_<?php echo $b; ?>").val(inventory_name);
																												}else{
																													$("#labour_codes_<?php echo $b; ?>").val("");

																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Item does not exist!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										}
																									});
																								});
																							});
																						</script>
																						<!-- <input type="text" name="item_labour[]" list="labour_name_<?php echo $b; ?>" id="labour_names_<?php echo $b; ?>" placeholder="Desc" class="form-control labour_name_<?php echo $b; ?> labour_name_get_detail_<?php echo $b; ?>" style="width:250px" value=""/>
																						<datalist id="labour_name_<?php echo $b; ?>"></datalist> -->
																					</td>

																					<td>
					                                                        			<script>
															                                $(document).ready(function(){
															                                    $(".supplier_code<?php echo $b; ?>").bind("input", function(e){
															                                        var code = $(this).val();
															                                        $.ajax({
															                                            type: "GET",
															                                            dataType: "html",
															                                            url: "'.base_url().'admin/transaction/get_supplier/<?php echo $menuid; ?>",
															                                            data:"code="+code,
              																							success: function(msg){
                    																						$("#supplier_code<?php echo $b; ?>").html(msg);
															                                            }
															                                        });
															                                    });
          																						$(".supplier_get_po_2<?php echo $b; ?>").focusout(function(e){
                         																			var code = $(this).val();

																									$.ajax({
																									 	type: "POST",
																										dataType: "html",
																									 	url: "'.base_url().'admin/transaction/supplier_get_detail/'.$menuid.'",
			 																							data:"code="+code,
 																										success: function(msg){
																										if(code==""){
																											$("#supplier_name_2<?php echo $b; ?>").val("");
																											$(".payment_terms<?php echo $b; ?>").val("");
																										}else{
																											var data_supplier = msg;
																											var explode = data_supplier.split("%");

																											var supplier_name  = explode[0];
																											var payment_terms  = explode[1];
																											var check   		  = explode[2];

																											if(check=="exist"){
																												$("#supplier_name_2<?php echo $b; ?>").val(supplier_name);
																											}else{
																												$("#supplier_code_2<?php echo $b; ?>").val("");
																													$("#supplier_name_2<?php echo $b; ?>").val("");

																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Supplier code is missing!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
																										}
																									});
															                                    });
															                                });
															                            </script>
															                            <!-- <input type="text" name="supplier_code_labour[]" list="supplier_code<?php echo $b; ?>" id="supplier_code_2<?php echo $b; ?>" class="form-control supplier_code<?php echo $b; ?> supplier_get_po_2<?php echo $b; ?>" placeholder="Supplier Code">
															                            <datalist id="supplier_code<?php echo $b; ?>"></datalist> -->
															                            <select
				                                                                            class="form-control supplier_get_addrow2_<?php echo $b; ?>"
				                                                                            name="supplier_code_labour[]"
				                                                                            style="width: 100%;">
				                                                                            <option value="">Select Supplier</option>
				                                                                            <?php foreach ($supplier as $key => $value): ?>
				                                                                            <option value="<?php echo $value->ID ?>">
				                                                                                <?php echo $value->code.' - '.$value->name; ?>
				                                                                            </option>
				                                                                            <?php endforeach ?>

				                                                                        </select>
									                                                </td>

									                                                <td>
					                                                        			<script>
															                                $(document).ready(function(){
															                                    $(".supplier_name<?php echo $b; ?>").bind("input", function(e){
                           																			var name = $(this).val();
	                             																	$.ajax({
																						                type: "GET",
																						          		dataType: "html",
																							           	url: "'.base_url().'admin/transaction/get_supplier_2/<?php echo $menuid; ?>",
																						              	data:"name="+name,
																						              	success: function(msg){
                               																				$("#supplier_name<?php echo $b; ?>").html(msg);
																                                        }
                                    																});
                                   																});
                       																			$(".supplier_get_po<?php echo $b; ?>").focusout(function(e){
																			                      	var name = $(this).val();

																									$.ajax({
																						 				type: "POST",
																						 				dataType: "html",
																						 				url: "'.base_url().'admin/transaction/supplier_get_detail_2/<?php echo $menuid; ?>",
																					 					data:"name="+name,
																					 					success: function(msg){
																											if(name==""){
																												$("#supplier_code_2<?php echo $b; ?>").val("");
																											}else{
																												var data_supplier = msg;
																												var explode = data_supplier.split("%");
																												var supplier_code  = explode[0];
																												var payment_terms  = explode[1];
																												var check = explode[2];
																												if(check=="exist"){
																													$("#supplier_code_2<?php echo $b; ?>").val(supplier_code);
																												}else{
																													$("#supplier_name_2<?php echo $b; ?>").val("");
																													$("#supplier_code_2<?php echo $b; ?>").val("");
																													var x = document.getElementById("snackbar")
																													x.className = "show";
																													x.innerHTML = "Supplier name is missing!";
																													setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
																												}
																											}
			 																							}
																									});
																                                });
															                            	});
															                        	</script>

																						<!-- <input type="text" name="supplier[]" list="supplier_name<?php echo $b; ?>" id="supplier_name_2<?php echo $b; ?>" class="form-control supplier_name<?php echo $b; ?> supplier_get_po<?php echo $b; ?>" placeholder="Supplier Name">
															                            <datalist id="supplier_name<?php echo $b; ?>"></datalist> -->
									                                                </td>
																					<td>
																						<input type="text" name="schedule[]" placeholder="Schedule" id="datepicker<?php echo $h; ?>" class="form-control datepicker" style="width:100px" value=""/>
																					</td>
																					<td>
																						<input type="text" name="target[]" placeholder="Target" id="datepicker<?php echo $i; ?>" class="form-control datepicker" style="width:100px" value=""/>
																					</td>
																					<td>
																						<input type="text" name="start_date[]" placeholder="Start Date" id="datepicker<?php echo $j; ?>" class="form-control datepicker" style="width:100px" value=""/>
																					</td>
																					<td>
																						<input type="text" name="target[]" placeholder="End Date" id="datepicker<?php echo $k; ?>" class="form-control datepicker" style="width:100px" value=""/>
																					</td>
																					<td align="center">
																						0
																					</td>
																					<!--
																					<td align="center">
																						0
																					</td>
																					<td align="center">
																						0
																					</td>
																					-->
																					<td align="center">
																						0
																					</td>
																					<td align="center">
																						0
																					</td>
																					<td>
																						<input type="text" name="price[]" placeholder="Price" class="form-control" style="width:100px"/>
																					</td>
																					<td align="center">
																						<a alt="<?php echo $id_labour; ?>" class="text-blue internal<?php echo $b; ?>" id="change_icon<?php echo $b; ?>" style="cursor:pointer">
																						<i class="fa fa-square-o" aria-hidden="true"></i>
																						</a>
																					</td>
																					<td align="right">
																						0
																					</td>
																				</tr>
																			<?php
																		}
																	}
																?>
	                                                            </tbody>
	                                                            <tfoot>
	                                                                <tr>
	                                                                    <td colspan="14">
	                                                                        <?php
						                                        			if($data_workorder[0]->finish != 0){
						                                        				echo'';
						                                        			}else{
						                                        		?>
	                                                                        <a class="btn btn-primary add_row loading_btn pull-left"
	                                                                            onClick="clickME()"
	                                                                            data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing">Add
	                                                                            Row</a>
	                                                                        <?php
					                                        				}
					                                        			?>
	                                                                        <script>
	                                                                        $('.loading_btn').on('click', function() {
	                                                                            var $this = $(this);
	                                                                            $this.button('loading');
	                                                                            setTimeout(function() {
	                                                                                $this.button('reset');
	                                                                            }, 500);
	                                                                        });
	                                                                        </script>
	                                                                        <script>
	                                                                        $(document).ready(function() {
	                                                                            var inc = <?php echo $count;?>;
	                                                                            $(".add_row").on('click',
	                                                                                function() {
	                                                                                    inc = inc + 1;
	                                                                                    $("#row2" + inc + "")
	                                                                                        .show();
	                                                                                });
	                                                                        });
	                                                                        </script>

	                                                                        <span class="pull-right">
	                                                                            <strong>Total :</strong>
	                                                                        </span>
	                                                                        <button type="button" id="update_total_labour"
	                                                                            class="update_total_labour"
	                                                                            style="display:none">Submit</button>
	                                                                        <script>
	                                                                        $(function() {
	                                                                            $(".update_total_labour").click(
	                                                                                function() {
	                                                                                    var count =
	                                                                                        <?php echo $count;?>;

	                                                                                    var total = 0;
	                                                                                    for (a = 0; a <
	                                                                                        count; a++) {
	                                                                                        var c = a + 1;
	                                                                                        var total_labour =
	                                                                                            parseFloat($(
	                                                                                                    "#gross_ammount_val_" +
	                                                                                                    c)
	                                                                                                .val());
	                                                                                        var total =
	                                                                                            parseFloat(
	                                                                                                total) +
	                                                                                            total_labour;
	                                                                                        //alert(total_labour);
	                                                                                        //return false;
	                                                                                    }

	                                                                                    var total = total
	                                                                                        .toString()
	                                                                                        .replace(/[.]/,
	                                                                                            ",");

	                                                                                    $(".total_finish")
	                                                                                        .html(addCommas(
	                                                                                            total));
	                                                                                });
	                                                                        });
	                                                                        </script>
	                                                                    </td>
	                                                                    <td align="right">
	                                                                        <strong class="total_finish">
	                                                                            <?php
						                                                		echo number_format($data_workorder[0]->total_labour);
					                                                		?>
	                                                                        </strong>
	                                                                    </td>
	                                                                    <td align="right">
	                                                                        <strong>
	                                                                            <?php
						                                                		echo number_format($paid_total);
						                                                	?>
	                                                                        </strong>
	                                                                    </td>
	                                                                </tr>
	                                                                <tr>
	                                                                    <td colspan="12">
	                                                                        <strong>Note Labour : </strong>
	                                                                        <input type="text" name="note_labour"
	                                                                            class="form-control"
	                                                                            value="<?php echo $data_workorder[0]->note_labour;?>" />
	                                                                    </td>
	                                                                    <td colspan="4" valign="middle">
	                                                                        <input type="submit"
	                                                                            class="btn btn-info btn-fill pull-right save"
	                                                                            value="Save" id="save"
	                                                                            style="margin-top:10px;">
	                                                                        <!-- <?php echo $disable_save;?>-->
	                                                                        <a href="<?php echo base_url();?>admin/transaction/production/<?php echo $menuid;?>"
	                                                                            class="btn btn-danger pull-right"
	                                                                            style="margin:10px 5px 0 0;">Cancel</a>
	                                                                        <button type="reset"
	                                                                            class="btn btn-default pull-right"
	                                                                            style="margin:10px 5px 0 0;">Reset</button>
	                                                                        <a href="<?php echo base_url();?>admin/transaction/workorder_spk/<?php echo $menuid.'/'.$id_workorder;?>"
	                                                                            class="btn btn-primary pull-right"
	                                                                            style="margin:10px 5px 0 0;">Print SPK</a>
	                                                                    </td>
	                                                                </tr>
	                                                            </tfoot>
	                                                        </table>
	                                                    </div>
	                                                </div>
	                                            </div>
	                                        </div>
	                                        <div class="tab-pane" id="tab_3">
	                                            <div class="row">
	                                                <div class="col-md-12" style="overflow: auto; white-space: nowrap;">
	                                                    <style>
	                                                    .img {
	                                                        max-width: 80px;
	                                                    }
	                                                    </style>
	                                                    <div class="table-responsive">
	                                                        <table
	                                                            class="table table-bordered table-striped table-hover js-basic-example dataTable">
	                                                            <!--purchase_service-->
	                                                            <thead>
	                                                                <tr>
	                                                                    <th>
	                                                                        No.
	                                                                    </th>
	                                                                    <th>
	                                                                        Image
	                                                                    </th>
	                                                                    <th>
	                                                                        Preview
	                                                                    </th>
	                                                                    <th>
	                                                                        Action
	                                                                    </th>
	                                                                </tr>
	                                                            </thead>
	                                                            <tbody>
	                                                                <?php
																$data_design=$this->master_model->select_in('ts_workorder_design','ID, image',"WHERE id_workorder=$id_workorder ORDER BY image ASC");
																$count_data_design=count($data_design);
																if($count_data_design==0){
																	for($a=0; $a < 3; $a++){
																		$b=$a+1;
																		echo'
																		<tr>
																			<td>
																				'.$b.'
																				<input type="hidden" name="id_image[]" value="'.$b.'">
																			</td>
																			<td valign="middle">
																				<input type="file" name="ImageUpload'.$b.'" id="imageUpload_'.$b.'" onchange="readURL_'.$b.'(this);"/>
																			</td>
																			<td>
																				<img id="blah_'.$b.'" class="img" src="http://placehold.it/80" alt="your image" />
																				<script>
																					function readURL_'.$b.'(input) {
																						if (input.files && input.files[0]){
																							var reader = new FileReader();
																							reader.onload = function (e) {
																								$("#blah_'.$b.'")
																							.attr("src", e.target.result);
																							};
																							reader.readAsDataURL(input.files[0]);
																						}
																					}
																				</script>
																			</td>
																			<td>
																			</td>
																		</tr>';
																	}
																}else{
         															for($a=0; $a < count($data_design); $a++){
																		$b=$a+1;
																		$id_image=$data_design[$a]->ID;
																		$image=$data_design[$a]->image;
																		echo'
																		<tr>
																			<td>
																				'.$b.'
																				<input type="hidden" name="id_image[]" value="'.$b.'">
																			</td>
																			<td valign="middle">
																				<input type="file" name="ImageUpload'.$b.'" id="imageUpload_'.$b.'" onchange="readURL_'.$b.'(this);"/>
																			</td>
																			<td>
																				<img id="blah_'.$b.'" class="img" src="'.base_url().'uploads/design/'.$image.'" alt="your image" />
																				<script>
																					function readURL_'.$b.'(input) {
																						if (input.files && input.files[0]){
																							var reader = new FileReader();
																							reader.onload = function (e) {
																								$("#blah_'.$b.'")
																								.attr("src", e.target.result);
																							};
																							reader.readAsDataURL(input.files[0]);
																						}
																					}
																				</script>
																			</td>
																			<td style="text-align: center">
																				<a href="'.base_url().'admin/transaction/delete_image/'.$menuid.'/'.$id_workorder.'/'.$id_image.'/'.$image.'" class="text-red">
																					<i class="fa fa-trash"></i>
																				</a>
																			</td>
																		</tr>
																		';
																	}
																	if(count($data_design) < 3){
																		for($c=0; $c < (3-count($data_design)); $c++){
																			$d=$c+count($data_design)+1;
																			echo'
																			<tr>
																				<td>
																					'.$d.'
																					<input type="hidden" name="id_image[]" value="'.$d.'">
																				</td>
																				<td valign="middle">
																					<input type="file" name="ImageUpload'.$d.'" id="imageUpload_'.$d.'" onchange="readURL_'.$d.'(this);"/>
																				</td>
																				<td>
																					<img id="blah_'.$d.'" class="img" src="http://placehold.it/80" alt="your image" />
																					<script>
																						function readURL_'.$d.'(input) {
																							if (input.files && input.files[0]){
																								var reader = new FileReader();
																								reader.onload = function (e) {
																									$("#blah_'.$d.'")
																									.attr("src", e.target.result);
																								};
																								reader.readAsDataURL(input.files[0]);
																							}
																						}
																					</script>
																				</td>
																				<td style="text-align: center">
																				</td>
																			</tr>
																			';
																		}
																	}
																}
															?>
	                                                            </tbody>
	                                                            <tfoot>
	                                                                <tr>
	                                                                    <td colspan="4" valign="middle">
	                                                                        <input type="submit"
	                                                                            class="btn btn-info btn-fill pull-right"
	                                                                            value="Save" id="save"
	                                                                            style="margin-top:10px;">
	                                                                        <a href="<?php echo base_url();?>admin/transaction/workorder/<?php echo $menuid;?>"
	                                                                            class="btn btn-danger pull-right"
	                                                                            style="margin:10px 5px 0 0;">Cancel</a>
	                                                                        <button type="reset"
	                                                                            class="btn btn-default pull-right"
	                                                                            style="margin:10px 5px 0 0;">Reset</button>
	                                                                        <a href="<?php echo base_url();?>admin/transaction/workorder_spk/<?php echo $menuid.'/'.$id_workorder;?>"
	                                                                            class="btn btn-primary pull-right"
	                                                                            style="margin:10px 5px 0 0;">Print SPK</a>
	                                                                    </td>
	                                                                </tr>
	                                                            </tfoot>
	                                                        </table>
	                                                    </div>
	                                                    <div class="modal" id="modal-gallery" role="dialog">
	                                                        <div class="modal-dialog">
	                                                            <div class="modal-content">
	                                                                <div class="modal-header">
	                                                                    <button class="close" type="button"
	                                                                        data-dismiss="modal">Ã—</button>
	                                                                    <h3 class="modal-title"></h3>
	                                                                </div>
	                                                                <div class="modal-body">
	                                                                    <div id="modal-carousel" class="carousel">
	                                                                        <div class="carousel-inner">
	                                                                        </div>
	                                                                        <a class="carousel-control left"
	                                                                            href="#modal-carousel" data-slide="prev"><i
	                                                                                class="glyphicon glyphicon-chevron-left"></i></a>
	                                                                        <a class="carousel-control right"
	                                                                            href="#modal-carousel" data-slide="next"><i
	                                                                                class="glyphicon glyphicon-chevron-right"></i></a>
	                                                                    </div>
	                                                                </div>
	                                                                <div class="modal-footer">
	                                                                    <button class="btn btn-default"
	                                                                        data-dismiss="modal">Close</button>
	                                                                </div>
	                                                            </div>
	                                                        </div>
	                                                    </div>
	                                                    <style>
	                                                    .thumbnail {
	                                                        margin-bottom: 6px;
	                                                    }

	                                                    .carousel-control.left,
	                                                    .carousel-control.right {
	                                                        background-image: none;
	                                                        margin-top: 10%;
	                                                        width: 5%;
	                                                    }
	                                                    </style>

	                                                </div>
	                                            </div>
	                                        </div>
	                                    </div>
	                                </div>
	                        </form>
	                    </div>
	                </div>
	            </div>
	        </div>
	        <script>
	        $(document).ready(function() {
	            $("#done1").focus();
	        });
	        </script>


	        <div class="modal fade" id="edit-modal" role="dialog">
	            <div class="modal-dialog" style="width: 60%">
	                <div class="modal-content " style="z-index:999">
	                    <div class="modal-header">
	                    </div>
	                </div>
	            </div>
	        </div>

	        <div class="modal fade" id="labour-modal" role="dialog">
	            <div class="modal-dialog" style="width: 60%">
	                <div class="modal-content labour-content box" id="overlay-body">

	                </div>
	            </div>
	        </div>
	        <div id="snackbar2">Workorder Close</div>
	        <div id="snackbar">Workorder Close <?php echo $added;?>!</div>
	    </section>
	</div>

	<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10.15.7/dist/sweetalert2.all.min.js"></script>

	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

	<script>
$('.alert_notif').on('click', function() {
    var getLink = $(this).attr('href');
    var getData = $(this).attr('value');
    // alert(getData);
    Swal.fire({
        title: "Yakin ingin hapus data? " + getData,
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#d33',
        confirmButtonText: 'Ya',
        cancelButtonColor: '#3085d6',
        cancelButtonText: "Batal"

    }).then(result => {
        //jika klik ya maka arahkan ke proses.php
        if (result.isConfirmed) {
            Swal.fire('Deleted!', 'Your file has been deleted.', 'success')
            window.location.href = getLink
        }
    })
    return false;
});
	</script>

	<?php $this->load->view('admin/master/footer_2');?>

	<script>
$(document).ready(function() {
    /* activate the carousel */
    $("#modal-carousel").carousel({
        interval: false
    });

    /* change modal title when slide changes */
    $("#modal-carousel").on("slid.bs.carousel",
        function() {
            $(".modal-title")
                .html($(this)
                    .find(".active img")
                    .attr("title"));
        });

    /* when clicking a thumbnail */
    $(".row .thumbnail").click(function() {
        var content = $(".carousel-inner");
        var title = $(".modal-title");

        content.empty();
        title.empty();

        var id = this.id;
        var repo = $("#img-repo .item");
        var repoCopy = repo.filter("#" + id).clone();
        var active = repoCopy.first();

        active.addClass("active");
        title.html(active.find("img").attr("title"));
        content.append(repoCopy);

        // show the modal
        $("#modal-gallery").modal("show");
    });

});
	</script>


	<?php
		for($a=0; $a < 20; $a++)
		{
			$b=$a+40;
			?>
	<script>
$(function() {
    $('.datepicker<?php echo $b;?>').datepicker({
        autoclose: true
    });
});
	</script>
	<?php
		}
	?>