<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-lg-12">
			<div class="ibox float-e-margins ">
				<?= form_header('7') ?>
				<div class="ibox-content">
					<div class="">
						<form method="post" class="" id="form_coa">
							<input type="hidden" name="t_action_new" id="action_new" value="<?=$action_new?>">
							<div class="panel-body">
								<div class="form-horizontal">
									<div class="form-group">
										<label class="col-sm-2 control-label">Account parent</label>
										<div class="col-sm-6">
										<div <?=$action_new?'hidden':''?>>
											<input class="form-control" readonly type="text" value="<?=$head['accountParentCode']?> - <?=$head['accountParentName']?>">
										</div>
											<div <?=$action_new?'':'hidden'?> > 
											<select id="accountParentCode" name="t_accountParentCode" data-placeholder="Choose..." class="chosen-select" tabindex="0">
											</select>
											</div>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">Account Code</label>
										<div class="col-sm-3">
											<input <?=$action_new?'':'readonly'?> type="text" class="form-control" placeholder="Kode Coa" name="t_accountCode" value="<?= $head['accountCode'] ?>" required>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">Account Name</label>
										<div class="col-sm-4">
											<input rows="2" type="text" placeholder="Nama Coa" class="form-control" name="t_accountName" value="<?= $head['accountName'] ?>" required>
										</div>
									</div>
								</div>
							</div>

							<div class="hr-line-dashed"></div>

							<div class="panel-body">
								<div class="form-horizontal">
									<div class="form-group">
										<label class="col-sm-2 control-label">Cash</label>
										<div class="col-sm-3">
											<div class="i-checks checkbox-inline "><label> <input <?=($head['cash']==='1')?'checked=""':''?>   type="radio" value="1" name="t_cash"> <i></i> Yes </label></div>
											<div class="i-checks checkbox-inline "><label> <input <?=($head['cash']==='0')?'checked=""':''?> type="radio" value="0" name="t_cash"> <i></i> No </label></div>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">balanceSheet</label>
										<div class="col-sm-3">
											<div class="i-checks checkbox-inline "><label> <input <?=($head['balanceSheet']==='1')?'checked=""':''?>   type="radio" value="1" name="t_balanceSheet"> <i></i> Yes </label></div>
											<div class="i-checks checkbox-inline "><label> <input <?=($head['balanceSheet']==='0')?'checked=""':''?> type="radio" value="0" name="t_balanceSheet"> <i></i> No </label></div>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">incomeStatement</label>
										<div class="col-sm-3">
											<div class="i-checks checkbox-inline "><label> <input <?=($head['incomeStatement']==='1')?'checked=""':''?>   type="radio" value="1" name="t_incomeStatement"> <i></i> Yes </label></div>
											<div class="i-checks checkbox-inline "><label> <input <?=($head['incomeStatement']==='0')?'checked=""':''?> type="radio" value="0" name="t_incomeStatement"> <i></i> No </label></div>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">operational</label>
										<div class="col-sm-3">
											<div class="i-checks checkbox-inline "><label> <input <?=($head['operational']==='1')?'checked=""':''?>   type="radio" value="1" name="t_operational"> <i></i> Yes </label></div>
											<div class="i-checks checkbox-inline "><label> <input <?=($head['operational']==='0')?'checked=""':''?> type="radio" value="0" name="t_operational"> <i></i> No </label></div>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">investment</label>
										<div class="col-sm-3">
											<div class="i-checks checkbox-inline "><label> <input <?=($head['investment']==='1')?'checked=""':''?>   type="radio" value="1" name="t_investment"> <i></i> Yes </label></div>
											<div class="i-checks checkbox-inline "><label> <input <?=($head['investment']==='0')?'checked=""':''?> type="radio" value="0" name="t_investment"> <i></i> No </label></div>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">funding</label>
										<div class="col-sm-3">
											<div class="i-checks checkbox-inline "><label> <input <?=($head['funding']==='1')?'checked=""':''?>   type="radio" value="1" name="t_funding"> <i></i> Yes </label></div>
											<div class="i-checks checkbox-inline "><label> <input <?=($head['funding']==='0')?'checked=""':''?> type="radio" value="0" name="t_funding"> <i></i> No </label></div>
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">Note</label>
										<div class="col-sm-6">
											<textarea id="note" name="t_note" rows="4" class="form-control" placeholder="note"><?= $head['note'] ?></textarea>
										</div>
									</div>
								</div>
							</div>

							<div class="hr-line-dashed"></div>

						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	getCoaParent();
	$('.btn-find-last-no').ladda();
	$('.btn-check-availability-code').ladda();
	$(document).ready(function() {
			$('.i-checks').iCheck({
				checkboxClass: 'icheckbox_square-green',
				radioClass: 'iradio_square-green',
			});
		saveBtn.click(function() {
			let btn = $(this);
			startLoadingButton(btn);
			swal.fire({
				title: "Apakah data sudah benar?",
				text: "Perubahan akan disimpan",
				icon: "warning",
				showCancelButton: true,
				confirmButtonText: 'Simpan',
			}).then(isConfirm => {
				if (isConfirm.value) {
					// $('#rolecode').removeAttr('disabled');
					// $('#bpcode').removeAttr('disabled');
					$.ajax({
						type: "POST",
						url: site_url + "master/coa/save",
						data: $('#form_coa').serialize(),
						dataType: 'json',
						success: function(response) {
							swal.fire(response['header'] || 'success', response['message'] || '', "success").then(() => {
								window.location = site_url + "master/coa/input/" + response['account_code'];
								stopLoadingButton(btn);
							});
						},
						error: function(jqXhr, textStatus, errorThrown) {
							var error_message = 'internal error';
							if (jqXhr.responseJSON !== undefined) {
								error_message = jqXhr['responseJSON']['message'];
							}
							swal.fire('error', error_message, "error");
							stopLoadingButton(btn);
						}
					});
				} else {
					stopLoadingButton(btn);
					return false;
				}
			});
		});

	});

	function getCoaParent() {
		$.ajax({
			type: 'POST',
			url: site_url + "master/coa/getCoaParent",
			dataType: 'html',
			success: function(result) {
				$('#accountParentCode').empty();
				$('#accountParentCode').append('<option value=""></option>');
				$('#accountParentCode').append(result).trigger("chosen:updated");
			}
		});
	}
</script>