<section class="container" style="padding-bottom: 2rem;">
	<div class="row">
		<div class="col-sm-12">
			<div class="tab-content" id="tabContent">
				<div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="profile-tab">
					<div class="card bg-light-transparent">
						<div class="card-header bg-light">
							<h4 class="card-title float-left"><?php echo (empty($ID))?'New ':'Edit '; ?> Credit Note Request Form</h4>
						</div>
						<div class="card-body">
							<div class="card no-shadow">
								<div class="card-body">
									<?php if(!empty($ID)){ ?>
										<form id="creditNoteForm" class="form" action="<?php echo base_url('hr/Serviceform/credit_note_edit'); ?>" method="POST" onsubmit="return confirm('Confirm to update this form?')">
										<?php }else{ ?>	
											<form id="creditNoteForm" class="form" action="<?php echo base_url('hr/Serviceform/credit_note_save') ?>" method="POST" onsubmit="return confirm('Confirm to submit this form?')">
											<?php }?>

											<input type="text" class="form-control" name="creditNoteID" id="creditNoteID" value="<?php echo $ID; ?>" hidden>
											<input type="text" class="form-control" name="entityID" id="entityID" value="<?php echo $entity_id; ?>" hidden>

											<div class="form-row">
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>MGS Job ID</label>
														<select class="form-control select" name="job_id" id="job_id" required onchange="change_invoice_input()">
															<option value="-1" selected>-- Please Select --</option>
															<?php if($mgs_job) foreach($mgs_job as $row){ ?>
																<option value="<?php echo $row['job_id'] ?>">
																	<?php echo '[JOB ID: '.str_pad($row['job_id'],5,0,STR_PAD_LEFT).'] '.$row['customerName'].' - '.$row['job_description']; ?>
																</option>
															<?php } ?>
														</select>
													</div>
												</div>

												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>Invoice No</label>
														<select class="form-control" name="inv_form_no" id="inv_form_no" required disabled>
															<option value="-1" selected>-- Please Select --</option>
														</select>
													</div>
												</div>

												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>Company Name</label>
														<input type="text" class="form-control" name="client_name" id="client_name" required readonly>
														<input type="text" class="form-control" name="client_id" id="client_id" hidden>
													</div>
												</div>

												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>Group</label>
														<input type="text" class="form-control" name="client_group_id" id="client_group_id" readonly>
													</div>
												</div>

												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>Client PIC</label>
														<input type="text" class="form-control" name="client_pic" id="client_pic" required readonly>
													</div>
												</div>

												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>Tel No</label>
														<input type="text" class="form-control" name="client_tel_no" id="client_tel_no" readonly required>
													</div>
												</div>

												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>Email</label>
														<input type="text" class="form-control" name="client_email" id="client_email" required readonly>
													</div>
												</div>
												
												<div class="col-12 col-sm-6">
													<div class="form-group">
														<label>Branch</label>
														<select class="form-control" name="branch_id" id="branch_id">
															<option value="-1" selected disabled>-- Please Select --</option>
															<?php if($branch) foreach($branch as $row){ ?>
																<option value="<?php echo $row['id']; ?>" <?php echo ($ID)?(($credit_note_list['branch_id'] == $row['id'])?'selected':''):''; ?>><?php echo $row['name']; ?></option>
															<?php } ?>
														</select>
													</div>
												</div>
											</div>

											<div class="form-row py-3">
												<div class="col-12">
													<div class="form-group">
														<!-- <h5><b>Description</b></h5> -->
														<!-- <hr> -->
														<div class="form-row">
															<div class="col-10">
																<div class="form-group text-center"><b>DESCRIPTION</b></div>
															</div>
															<div class="col-2">
																<div class="form-group text-center"><b>AMOUNT (RM)</b></div>
															</div>
														</div>

														<hr style="margin-top: 1px; margin-bottom: 2rem;">

														<div class="form-row">
															<?php if($description) foreach($description as $row){ ?>
																<div class="col-1 text-center">
																	<div class="form-group">
																		<input type="checkbox" name="desc_check_<?php echo $row['ID']; ?>" id="desc_check_<?php echo $row['ID']; ?>" onclick="change_input(<?php echo $row['ID']; ?>)">
																	</div>
																</div>
																<div class="col-3">
																	<div class="form-group">
																		<?php echo $row['description']; ?>
																	</div>
																</div>
																<div class="col-5">
																	<div class="form-group">
																		<input type="text" class="form-control" name="desc_detail__<?php echo $row['ID']; ?>" id="desc_detail__<?php echo $row['ID']; ?>" disabled>
																	</div>
																</div>
																<div class="col-3">
																	<div class="form-group">
																		<?php if(strpos(strtolower($row['description']), 'date')){ ?>
																			<input type="text" class="text-right form-control datepicker" name="desc_amount__<?php echo $row['ID']; ?>" id="desc_amount__<?php echo $row['ID']; ?>" disabled>
																		<?php } else { ?>
																			<input type="text" class="text-right form-control" name="desc_amount__<?php echo $row['ID']; ?>" id="desc_amount__<?php echo $row['ID']; ?>" value="<?php echo number_format(0,2); ?>" onchange="update_total(<?php echo $row['ID']; ?>)" disabled>
																		<?php } ?>
																	</div>
																</div>
															<?php } ?>

															<div class="col-1 text-center">
																<div class="form-group">
																	<input type="checkbox" name="desc_check_sst" id="desc_check_sst" <?php echo ($business_entity_detail['is_sst'] == true)?'checked':'disabled style="cursor: not-allowed;"'; ?> onclick="change_sst_input()">
																</div>
															</div>
															<div class="col-3">
																<div class="form-group">
																	SST <?php echo ($business_entity_detail['is_sst'])?'('.($business_entity_detail['tax_amount']*100).'%)':''; ?>
																</div>
															</div>
															<div class="col-5"></div>
															<div class="col-3">
																<div class="form-group">
																	<input type="text" class="text-right form-control" name="desc_amount__sst" id="desc_amount__sst" value="<?php echo number_format(0,2); ?>" <?php echo ($business_entity_detail['is_sst'] == true)?'readonly required style="background: transparent; cursor: not-allowed;"':'disabled style="cursor: not-allowed;"'; ?>>
																</div>
															</div>
														</div>

														<hr style="margin-top: 1px; border: 1px solid;">
														<div class="form-row">
															<div class="col-9">
																<div class="form-group text-center">
																	<h6 style="margin-top: 10px;">TOTAL (RM)</h6>
																</div>
															</div>
															<div class="col-3">
																<div class="form-group">
																	<input type="text" class="text-right form-control" name="total_credit_note" id="total_credit_note" readonly required value="<?php echo ($ID)?number_format($credit_note_list['total'],2):number_format(0,2); ?>" style="background: transparent; cursor: not-allowed;">
																</div>
															</div>
														</div>
														<hr style="margin-top: 1px; margin-bottom: 2rem; border: 1px solid;">
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12">
													<div class="form-group">
														<h5><b>Prepared By</b></h5>
														<hr>
														<div class="form-row">
															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label>Name</label>
																	<input type="text" class="form-control" name="request_name" id="request_name" value="<?php echo ($ID)?$credit_note_list['requester_name']:$_SESSION['user']['name']; ?>" readonly>	
																	<input type="text" class="form-control" name="request_name_id" id="request_name_id" value="<?php echo ($ID)?$credit_note_list['requester_id']:$_SESSION['user']['id']; ?>" hidden>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="email">Email Address</label>
																	<input type="text" class="form-control" name="request_email" id="request_email" value="<?php echo ($ID)?$credit_note_list['requester_email']:$_SESSION['user']['email']; ?>" readonly>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="department">Department</label>
																	<input type="text" class="form-control" name="request_dept" id="request_dept" value="<?php echo ($ID)?$credit_note_list['dept_name'].' ['.$credit_note_list['branchName'].']':$_SESSION['user']['department_name'].' ['.$_SESSION['user']['branch_name'].']'; ?>" readonly>	
																	<input type="text" class="form-control" name="request_dept_id" id="request_dept_id" value="<?php echo ($ID)?$credit_note_list['department_id']:$_SESSION['user']['department_id']; ?>" hidden>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="datereq">Date Request</label>
																	<input type="text" class="form-control" name="datereq" id="datereq" value="<?php echo ($ID)?date("d-m-Y",strtotime($credit_note_list['createdTS'])):date("d-m-Y"); ?>" readonly>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>

											<div class="form-row">
												<div class="col-12">
													<p>
														Kindly Take Note of the followings:-<br>
														i)	Kindly indicate in detail job undertake<br>
														ii)	Kindly ensure amount is in accordance to proposal or quotation issued.<br>
														iii)	Check for major variation from previous credit_note(s) issued<br>
														iv)	This form is to be approved by Manager above<br>
													</p> 
												</div>
											</div>

											<!-- <div class="form-row py-2" <?php //echo (isset($mode) && ($mode == 'view'))?'style="display: none;"':''; ?>>
												<div class="col-12">
													<div class="float-right">
														<a class="btn btn-light" href="<?php //echo base_url('hr/serviceform/credit_note') ?>">Cancel</a>
														<button type="submit" class="btn btn-primary"><?php //echo ($ID)?'Update':'Submit'; ?></button>
													</div> 
												</div>
											</div> -->
											<div class="form-row" <?php echo (isset($mode) && ($mode == 'view'))?'style="display: none;"':''; ?>>
												<div class="col-12" style="padding-top: 2rem;">
													<div class="float-left <?php echo ($ID)?'d-none':''; ?>">
														<table>
															<tbody>
																<tr>
																	<td class="text-center">
																		<label class="switch" data-trigger="hover" data-tooltip="tooltip" title="" data-original-title="Send me a copy of this form">
																			<input type="checkbox" name="send_email_checkbox">
																			<span class="slider round"></span>
																		</label>
																	</td>
																	<td class="p-3 py-1"><b><h6 style="">Send me a copy of this form</h6></b></td>
																</tr>
															</tbody>
														</table>
													</div> 
													<div class="float-right">
														<a class="btn btn-light" href="<?php echo base_url('hr/serviceform/credit_note_list/'); ?>">Cancel</a>
														<button type="submit" id="submitBtn" class="btn btn-primary"><?php echo ($ID)?'Update':'Submit'; ?></button>
													</div> 
												</div>
											</div>
										</form>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>

<!-- manager approval -->
<?php if($_SESSION['user']['grade'] >= 31){ ?>
	<section class="container" style="padding-bottom: 2rem;">
		<div class="row">
			<div class="col-sm-12">
				<div class="tab-content" id="tabContent">
					<div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="profile-tab">
						<div class="card bg-light-transparent">
							<div class="card-header bg-light">
								<h4 class="card-title">Approved By</h4>
							</div>
							<div class="card-body">
								<div class="card no-shadow">
									<div class="card-body">
										<form id="creditNoteApprovedForm" class="form" action="<?php echo base_url('hr/Serviceform/credit_note_approved/manager') ?>" method="POST">
											<input type="text" class="form-control" name="creditNoteID" id="creditNoteID" value="<?php echo $ID; ?>" hidden>
											<div class="form-row py-3">
												<div class="col-12">
													<div class="form-group">
														<div class="form-row">
															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label>Name</label>
																	<input type="text" class="form-control" name="approve_name" id="approve_name" value="<?php echo ($ID)?(($credit_note_list['approval_status'] > 0)?$credit_note_list['approved_by_name']:$_SESSION['user']['name']):''; ?>" readonly>	
																	<input type="text" class="form-control" name="approve_name_id" id="approve_name_id" value="<?php echo ($ID)?(($credit_note_list['approval_status'] > 0)?$credit_note_list['approved_by_staff_id']:$_SESSION['user']['id']):''; ?>" hidden>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="email">Email Address</label>
																	<input type="text" class="form-control" name="approve_email" id="approve_email" value="<?php echo ($ID)?(($credit_note_list['approval_status'] > 0)?$credit_note_list['approved_by_email']:$_SESSION['user']['email']):''; ?>" readonly>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="dateapprv">Date Approve</label>
																	<input type="text" class="form-control" name="dateapprv" id="dateapprv" value="<?php echo ($ID)?(($credit_note_list['approval_status'] > 0)?date("d-m-Y h:iA",strtotime($credit_note_list['approvedTS'])):date("d-m-Y h:iA")):''; ?>" readonly>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>
											<div class="col-12" <?php echo ($ID && $credit_note_list['prepared_status'] > 0)?'style="display: none;"':''; ?>>
												<div class="float-right">
													<button type="submit" class="btn btn-danger" name="approveBtn" id="rejectBtn" value="2">Reject</button>
													<button type="submit" class="btn btn-success" name="approveBtn" id="approveBtn" value="1">Approved</button>
												</div> 
											</div>
										</form>									
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
<?php } ?>

<!-- for finance use -->
<?php if($ID && $credit_note_list['approval_status'] > 0 && $finance_division){ ?>
	<section class="container" style="padding-bottom: 2rem;">
		<div class="row">
			<div class="col-sm-12">
				<div class="tab-content" id="tabContent">
					<div class="tab-pane fade show active" id="profile" role="tabpanel" aria-labelledby="profile-tab">
						<div class="card bg-light-transparent">
							<div class="card-header bg-light">
								<h4 class="card-title">For Finance Division Use Only</h4>
							</div>
							<div class="card-body">
								<div class="card no-shadow">
									<div class="card-body">
										<form id="creditNoteApprovedForm" class="form" action="<?php echo base_url('hr/Serviceform/credit_note_approved/finance') ?>" method="POST">
											<input type="text" class="form-control" name="creditNoteID" id="creditNoteID" value="<?php echo $ID; ?>" hidden>
											<div class="form-row py-3">
												<div class="col-12">
													<div class="form-group">
														<div class="form-row">
															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label>Name</label>
																	<input type="text" class="form-control" name="finance_name" id="finance_name" value="<?php echo ($ID)?(($credit_note_list['prepared_status'] > 0)?$credit_note_list['prepared_by_name']:$_SESSION['user']['name']):''; ?>" readonly>	
																	<input type="text" class="form-control" name="finance_name_id" id="finance_name_id" value="<?php echo ($ID)?(($credit_note_list['prepared_status'] > 0)?$credit_note_list['prepared_by_staff_id']:$_SESSION['user']['id']):''; ?>" hidden>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="email">Email Address</label>
																	<input type="text" class="form-control" name="finance_email" id="finance_email" value="<?php echo ($ID)?(($credit_note_list['prepared_status'] > 0)?$credit_note_list['prepared_by_email']:$_SESSION['user']['email']):''; ?>" readonly>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="finance_date">Date Issued</label>
																	<input type="text" class="form-control" name="finance_date" id="finance_date" value="<?php echo ($ID)?(($credit_note_list['prepared_status'] > 0)?date("d-m-Y h:iA",strtotime($credit_note_list['preparedTS'])):date("d-m-Y h:iA")):''; ?>" readonly>
																</div>
															</div>

															<div class="col-12 col-sm-6">
																<div class="form-group">
																	<label for="finance_inv_no">Credit Note No</label>
																	<input type="text" class="form-control" name="finance_inv_no" id="finance_inv_no" value="<?php echo ($ID)?(($credit_note_list['prepared_status'] > 0)?$credit_note_list['inv_form_no']:''):''; ?>" required>
																</div>
															</div>
														</div>
													</div>
												</div>
											</div>
											<div class="col-12">
												<div class="float-right">
													<button type="submit" class="btn btn-danger" name="financeCompleteBtn" id="financeDuplicateBtn" value="2">Duplicate</button>
													<button type="submit" class="btn btn-success" name="financeCompleteBtn" id="financeCompleteBtn" value="1">Complete</button>
												</div> 
											</div>
										</form>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
<?php } ?>

<script>
	$(document).ready(function()
	{
		var client_id = $('#client_id').val();
		if(client_id > 0)
		{
			$('#addClientPhone').removeAttr('disabled');
			$('#addClientPhone').css('cursor','pointer');
		}else{
			$('#addClientPhone').attr('disabled','disabled');
			$('#addClientPhone').css('cursor','not-allowed');
		}

		var job_id = '<?php echo ($ID)?$credit_note_list['job_id']:''; ?>';
		var client_id = '<?php echo ($ID)?$credit_note_list['client_id']:''; ?>';
		
		if('<?php echo $ID; ?>' > 0)
		{
			if(job_id > 0) change_invoice_input(job_id);
			edit_description_value();
		}
		
	});

	function change_invoice_input(jobID = null)
	{
		if(jobID > 0)
		{
			var job_id 		= jobID;
		}else{
			var job_id 		= $('#job_id').val();
		}

		var entity_id = $('#entityID').val();

		var group_id 	= '';
		var tel_no 		= '';
		var email 		= '';

		if(job_id > 0)
		{
			$('#job_id').select2();
			$('#job_id').val(job_id);

			$('#job_id').select2({
				theme: 'bootstrap4',
			});

			$('#inv_form_no').html('');
			$('#inv_form_no').append('<option value="-1" selected disabled>-- Please Select --</option>');
			$('#inv_form_no').removeAttr('disabled');

			$.ajax({
				url:'<?php echo base_url('hr/serviceform/credit_note_get_invoice') ?>',
				data: {
					job_id 		: job_id,
					entity_id	: entity_id,
				},
				type: 'post',
				dataType: 'json',
				success: (data) => {
					if(data.status == "success") {
						var invoice_list 	= data.invoice_list;
						var client_detail 	= data.client_detail;

						$.each(invoice_list, function(key,content){
							if('<?php echo $ID; ?>' > 0)
							{
								if('<?php echo $credit_note_list['invoice_id']; ?>' == content.ID)
								{
									var selected = 'selected';
								}else{
									var selected = '';
								}
							}else{
								var selected	= '';
							}

							var inv_temp = '<option value="'+content.ID+'" '+selected+'>'+content.inv_form_no+'</option>';
							$('#inv_form_no').append(inv_temp);
						});

						if(client_detail.groupName != null && client_detail.groupName != '') $('#client_group_id').val(client_detail.groupName);

						$('#client_email').val(invoice_list[0]['client_email']);
						$('#client_id').val(invoice_list[0]['client_id']);
						$('#client_name').val(invoice_list[0]['customerName']);
						$('#client_pic').val(invoice_list[0]['attention_to']);
						$('#client_tel_no').val(invoice_list[0]['client_contact']);
					}
              	}
           	});
		}else{
			$('#inv_form_no').html('');
			$('#inv_form_no').append('<option value="-1" selected disabled>-- Please Select --</option>');
			$('#inv_form_no').attr('disabled','disabled');
			$('#client_group_id').val(group_id);
			$('#client_email').val(email);
			$('#client_pic').val('');
			$('#client_tel_no').val('');
			$('#inv_form_no').val('-1');
			$('#client_id').val('');

		}
	}

	function open_modal()
	{
		var client_id = $('#client_id').val();

		if(client_id > 0)
		{
			$('#client_ID').val(client_id);
			$('#modal_add_client_phone_modal').modal('show');
		}
	}

	function change_input(description_id)
	{
		var description_checkbox = $('#desc_check_'+description_id).is(':checked');

		if(description_checkbox == true)
		{
			$('#desc_amount__'+description_id).removeAttr('disabled');
			$('#desc_amount__'+description_id).attr('required','required');
			$('#desc_detail__'+description_id).removeAttr('disabled');
			$('#desc_detail__'+description_id).attr('required','required');

			if('<?php echo $entity_id; ?>' == 3 && description_id == 1)
			{
				$('#signing_partner').attr('required','required');
			}
			
		}else{
			$('#desc_amount__'+description_id).removeAttr('required');
			$('#desc_amount__'+description_id).attr('disabled','disabled');
			$('#desc_detail__'+description_id).removeAttr('required');
			$('#desc_detail__'+description_id).attr('disabled','disabled');

			if('<?php echo $entity_id; ?>' == 3 && description_id == 1)
			{
				$('#signing_partner').removeAttr('required');
			}

			$('#desc_detail__'+description_id).val("");
			$('#desc_amount__'+description_id).val("0");

			update_total(description_id);
		}
	}

	function update_total(description_id)
	{
		var description_first_id = '<?php echo min($description)['ID']; ?>';
		var description_last_id = '<?php echo max($description)['ID']; ?>';
		// var description_amount = $('#desc_amount__'+description_id).val();
		
		if($('#desc_check_sst').is(':checked')) var sst_amount = '<?php echo $business_entity_detail['tax_amount']; ?>';
		var total = 0;

		if(description_id > 0)
		{
			var description_amount = $('#desc_amount__'+description_id).val().replace(",","");

			if(description_amount != '' && description_amount != null && description_amount > 0)
			{
				var amount = parseFloat(description_amount);
				// var amount = $('#desc_amount__'+description_id).val();
			}else{
				var amount = 0.00;
			}
		}
			
		for(var i = description_first_id; i <= description_last_id; i++)
		{
			var desc_amount = $('#desc_amount__'+i).val().replace(",","");
			// if($('#desc_amount__'+i).val() != '' && $('#desc_amount__'+i).val() != null && $('#desc_amount__'+i).val() > 0)
			if(desc_amount != '' && desc_amount != null && desc_amount > 0)
			{
				// total += parseFloat($('#desc_amount__'+i).val());
				total += parseFloat(desc_amount);
			}else{
				total += 0;
			}
		}

		if(total > 0)
		{
			var sst = total * sst_amount; 
		}else{
			var sst = 0.00;
		}

		if($('#desc_check_sst').is(':checked'))
		{
			$('#desc_amount__sst').val(parseFloat(sst).toFixed(2));
			$('#total_credit_note').val(parseFloat(total + sst).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
		}else{
			$('#total_credit_note').val(parseFloat(total).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
		}
	}

	function edit_description_value()
	{
		// var desc_id = ('<?php //echo $credit_note_list['description_id']; ?>').split('->');
		// var desc_remark = ('<?php //echo $credit_note_list['description_remark']; ?>').split('->');
		// var desc_amount = ('<?php //echo $credit_note_list['description_amount']; ?>').split('->');
		// $.each(desc_id,function(key, row){
		// 	$('#desc_check_'+row).prop('checked', true);
		// 	$('#desc_detail__'+row).prop('disabled',false);
		// 	$('#desc_amount__'+row).prop('disabled',false);
		// 	$('#desc_amount__'+row).prop('required',true);
		// 	$('#desc_detail__'+row).val(desc_remark[key]);
		// 	$('#desc_amount__'+row).val(parseFloat(desc_amount[key]).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
		// });
		<?php
			$desc_id = explode('->',$credit_note_list['description_id']);
			$desc_remark = explode('->',$credit_note_list['description_remark']);
			$desc_amount = explode('->',$credit_note_list['description_amount']);

			if(sizeof($desc_id) > 0){
				foreach($desc_id as $key => $row){ ?>
					$('#desc_check_'+'<?php echo $row; ?>').prop('checked', true);
					$('#desc_detail__'+'<?php echo $row; ?>').prop('disabled',false);
					$('#desc_amount__'+'<?php echo $row; ?>').prop('disabled',false);
					$('#desc_amount__'+'<?php echo $row; ?>').prop('required',true);
					$('#desc_detail__'+'<?php echo $row; ?>').val('<?php echo $desc_remark[$key]; ?>');
					<?php if(strtotime($desc_amount[$key]) > 0){ ?>
						$('#desc_amount__'+'<?php echo $row; ?>').val('<?php echo $desc_amount[$key]; ?>');
					<?php }else{ ?>
						$('#desc_amount__'+'<?php echo $row; ?>').val(parseFloat('<?php echo $desc_amount[$key]; ?>').toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
					<?php }
				}
			}
		?>

	}

	function change_sst_input()
	{
		if($('#desc_check_sst').is(':checked'))
		{
			$('#desc_amount__sst').css('background','transparent');
		}else{
			$('#desc_amount__sst').css('background','#e9ecef');
			$('#desc_amount__sst').val((0.00).toFixed(2));
		}

		update_total();
	}
</script>