<!---- 
    Author			: Hasan
    Created Date	: 03 Feb 2015
    Revision		: Fachri 
-->
<style>
table td{
	height: 20px;
}
</style>

<?php
			//---------Untuk privellege jika dia ada tombol save----------
			if($group_user->SavePrivillage == 1){
				$cek_autority_save 		= "";
			}
			else{
				$cek_autority_save 		= "disabled";
			}
			
			if($group_user->DeletePrivillage == 1){
				$cek_autority_delete 		= "";
			}
			else{
				$cek_autority_delete 		= "disabled";
			}
			
			if($group_user->JournalPrivillage == 1){
				$cek_autority_journal 		= "";
			}
			else{
				$cek_autority_journal 		= "disabled";
			}

            if($group_user->ReversePrivillage == 1){
                $cek_autority_reverse  = "";
            }
            else{
                $cek_autority_reverse    = "display:none";
            }
			
			//-------------end----------------------------
?>	
<div class="easyui-layout" data-options="fit:true,border:false">
    <form id="fm_job_costing" name="fm_job_costing" method="post">
		<input type="hidden" name="detail" id="detail" />
        <input type="hidden" name="detail_id" id="detail_id">
        <input type="hidden" name="detail_item" id="detail_item">
		<input type="hidden" name="id" id="id" value="<?php echo $detail->JCostNumber; ?>"/>
        
        <?php
			foreach($j_cost_detail as $row):
		?>
        <input type="hidden" name="item_code" id="item_code" value="<?php echo $row->ItemCode ;?>" />
        <?php endforeach;?>
        <!-- top view-->
        <div id="form-header" data-options="region:'north',border:false" >
            <div id="form-header-wrapper">
                <table cellpadding="0" cellspacing="0" width="100%" border="0">
                <tr>
                    <td align="left" width="30%">
                        <input type="checkbox" class="easyui-checkbox" name="chk_suspended" id="chk_suspended" style="margin-top:0px;margin-right:1px;" onClick="suspend(1)" <?php if($detail->TransStatus == 3){ echo"checked"; } ?> <?=(!in_array($detail->TransStatus,array(4,6)) || $detail->AppLevel1Status == 1) ? 'disabled' : ''?> <?php echo $cek_autority_delete;?>/>
                    	<span style="display:inline-block;margin-top:2px;<?=(($detail->AppLevel1Status!=0)?'color:gray;':'')?>"><?=(($detail->TransStatus!=3)?"Suspend":"Suspend")?> </span>
                    	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-journal" plain="true"  id="btn_journal" 
							onclick="parent.tab_add('Preview Journal <?=$menu_label?>', '<?php echo $menu_link; ?>', 'icon-print', 'to_preview_journal/<?php echo $detail->JCostNumber ?>')" <?php echo $cek_autority_journal;?>>Journal
						</a>
                        <a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</a>
                    </td>					
        			<td align="center" width="40%"><span id="approval_information">
							<?php
                            if($detail->TransStatus==4){
                                echo get_status_approval_header($detail->TransStatus);
                            }
                            ?>
                            </span>
                        </td>
                    <td height="25" align="right" valign="middle">
                        <span class="form-title" style="margin-left:7px;">
                            <?=$menu_label?>
                        </span>							
                    </td>
                </tr>
                </table>		     	
            </div>			
        </div>
        <!-- end top view -->	

    	<!-- center view -->
		<div id="form-body" data-options="region:'center',border:false">
            <div id="form-wrapper" class="easyui-panel"  style="width:1180px;height:526px;padding:5px;" fit='true'>
               	<?php if(in_array($detail->TransStatus,array(1,2,3,9))){ ?>
                	<div class="blanket"></div>
                	<div class="status-box"><b><?php if($detail->TransStatus==2){ echo 'Finished'; }elseif($detail->TransStatus==3){ echo 'Suspended'; }elseif($detail->TransStatus==1){ echo 'On Progres'; }elseif($detail->TransStatus==9){ echo 'Canceled by Dir.'; }else{ echo 'Unknown'; } ?></b></div>
            	<?php } ?>
                <input type="hidden" name="branch_hidden" id="branch_hidden" value="<?php echo $detail->BranchCode; ?>"/>
                <table width="100%" height="141">
                <tr>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1">
                        <tr height="20">
                            <td width="100px"><b>Job Costing</b></td>
                            <td colspan="3">
                            	<b>:</b> 
                                <select id="cmb_jcost" name="cmb_jcost" editable="false"
                                    class="easyui-combogrid" required 
                                    style="width:400px;height:22px;" readonly
                                     
                                    data-options="
                                    	panelWidth: 400,
                                        value:'<?php echo $detail->JCostAccount; ?>',
                                        idField: 'AccountNumber',
                                		textField: 'AccountName',
                                       	url: '<?php echo base_url(); ?><?php echo"list/job_costing"; ?>/get_persedian_bahan_baku', 
                                        method: 'post',
                                        columns: [[
                                        	{field:'AccountNumber',title:'Account Number',width:130},
                                 			{field:'AccountName',title:'Account Name',width:350}
                                        ]],
                                        fitColumns: true
                                    "
                                >
                                </select>
                            </td>
                            <td width="60"&nbsp;>&nbsp;</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td colspan="2">&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                            <td colspan="2">&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        </table>
                    </td>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1">
                        <tr>
                            <td width="150" align="center" valign="middle"></td>
                            <td width="190" align="center" valign="middle" bgcolor="#333399"><span style="color:#fff;">Batch No.</span></td>
                            <td width="100" align="center" valign="middle" bgcolor="#333399"><span style="color:#fff;">Date</span></td>
                            <td width="100" align="center" valign="middle" bgcolor="#333399"><span style="color:#fff;">Department</span></td>
                        </tr>
                        <tr>
                            <td align="center" valign="top">&nbsp;</td>
                            <td align="center" valign="top" height="20"><input type="text" name="txt_no" id="txt_no" value="<?php echo $detail->JCostNumber; ?>" style="width:263px;height:18px;text-align:center" class="easyui-validatebox textbox" required="required" readonly />
                            <input type="hidden" name="txt_no_hidden" id="txt_no_hidden" style="width:190px;height:18px;text-align:center" class="easyui-validatebox textbox" required="required" readonly />
                            </td>
                            <td align="right" valign="top"><input name="txt_date" value="<?php echo date("d-m-Y", strtotime($detail->JCostDate));?>" id="txt_date" type="text" class="easyui-datebox" style="width:122px;height:20px" required editable="false" readonly/></td>
                            <td align="left" valign="top">
                            	<select <?= in_array($detail->TransStatus,array(0,1,2,3)) ? 'readonly' : '' ?> name="cmb_departement" id="cmb_departement" 
                                	style="width:122px;height:20px;" 
                                    class="easyui-combobox" 
                                    data-options="
                                    	 value:'<?php echo $detail->DepartmentCode; ?>',
                                    	valueField:'DepartmentCode', 
                                        textField:'DepartmentName', 
                                        url:'<?=base_url()?>custom/get_data/department',
                                        onSelect: function(rec){
                                           /*====================on beg in edit saat grid di klik maka tombol save disable===================*/
                                            $('.app-button').linkbutton('disable');
                                            /*=================================end============================================================*/	
                                        }
                                    " 
                                    
                                    editable="false" 
                                />
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td height="20">&nbsp;</td>
                            <td width="190" height="20" align="center" valign="middle">&nbsp;</td>
                            <td width="100" align="center" valign="middle">&nbsp;</td>
                            <td width="100" align="center" valign="middle">&nbsp;</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td height="20" align="left" valign="top">&nbsp;</td>
                            <td align="right" valign="top">&nbsp;</td>
                            <td align="right" valign="top">&nbsp;</td>
                        </tr>
                        <tr>
                            <td width="100" align="center" valign="middle">&nbsp;</td>
                            <td height="20" width="100" align="center" valign="middle">&nbsp;</td>
                            <td width="100" align="center" valign="middle">&nbsp;</td>
                            <td width="100" align="center" valign="middle">&nbsp;</td>
                        </tr>		
                        <tr>
                            <td align="left" valign="top">&nbsp;</td>
                            <td height="20" align="left" valign="top">&nbsp;</td>
                            <td height="20" align="left" valign="top">&nbsp;</td>
                            <td align="right" valign="top">&nbsp;</td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                            <td>&nbsp;</td>
                        </tr>
                        </table>
                    </td>
            	</tr>											
                </table>	

                <!--Item Grid -->
                <div class="easyui-tabs" data-options="tabHeight:18">
                    <div title="Items">
                        <table toolbar="#tb_dg_item" id="dg_job" class="easyui-<?=(in_array($detail->TransStatus,array(3,1,2)))?'datagrid':'edatagrid'?>" idField="id"
                            rownumbers="true" fitColumns="true" 
                            singleSelect="true" style="height:256px;" 
                            url="<?php echo base_url()?>list/job_costing/detail_jobcost/<?php echo $detail->JCostNumber;?>"
                        >
                            <thead>
                            <tr>
                                <th halign="center" align="left" valign="middle" data-options="field:'ItemCode',width:400,align:'left'" >Item</th>
                                <th halign="center" align="left" valign="middle" data-options="field:'JCostDetailDesc',width:700,align:'left'" >Item Description</th>
                                
                                <th halign="center" align="left" valign="middle" data-options="field:'ItemQty',width:200,align:'left'" 		editor="{type:'numberbox',options:{precision:2,decimalSeparator:','}}" formatter="formatRp">Qty</th>
                                <th halign="center" align="left" valign="middle" data-options="field:'ItemUnit',width:200,align:'left'">Unit</th>
                                <th halign="center" align="left" valign="middle" data-options="field:'ItemHPP',width:150,align:'left'"  	editor="{type:'numberbox',options:{precision:2,decimalSeparator:','}}" formatter="formatRp" >Unit Price</th>
                                
                                <th halign="center" align="left" valign="middle" data-options="field:'JcostDetailDate',width:150,align:'left'" editor="{type:'datebox',options:{required:true,editable:false}}" formatter="formatDate">Date</th>
                                
                                <th halign="center" align="left" field="ItemAmount" 		editor="{type:'numberbox',options:{decimalSeparator:',',
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Item Amount</th>
                                
                                <th halign="center" align="left" valign="middle"	data-options="field:'JCostDetailID',width:150,align:'left'"  editor="{type:'numberbox',options:{required:true,min:1}}" hidden>JCost Detail ID</th>
                                <th halign="center" align="left" valign="middle"	data-options="field:'ItemCategoryID',width:150,align:'left'" hidden>Item Kategori</th>
                                <th halign="center" align="left" valign="middle"	data-options="field:'RowStatus',width:150,align:'left'"  	 hidden>RowStatus</th>
                                
                            	<th halign="center" align="left" valign="middle"	data-options="field:'ItemType',width:150,align:'left'" 		editor="{type:'text'}" 	  	hidden>Item Type</th>
                                <th halign="center" align="left" valign="middle"	data-options="field:'ItemStatus',width:150,align:'left'" 	editor="{type:'text'}" 	 	hidden>Item Status</th>
                           		<th field="ItemAverage_Real" halign="center" align="left" valign="middle"	data-options="width:150,align:'left'"  		editor="{type:'numberbox',options:{decimalSeparator:',',
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Real Hpp</th>
                            </tr>
                            </thead>
                        </table>
                        <div id="tb_dg_item">
                        	<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row()" <?= in_array($detail->TransStatus,array(0,1,2,3)) ? 'disabled' : '' ?>>Delete</a>
                        </div>						
                    </div>
                    
                </div>
                <!-- End Item Grid -->		

                <table width="100%" cellpadding="0" cellspacing="0" style="margin-top:5px;">
                <tr>
                    <td width="100" rowspan="2" valign="top"><b>Description</b></td>
                    <td width="362" rowspan="2" valign="top"><textarea name="txa_description" cols="55.5" rows="4" style="resize:none;" <?= in_array($detail->TransStatus,array(0,1,2,3)) ? 'readonly' : '' ?>><?php echo $detail->JCostDesc; ?></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td width="301" align="right" valign="top" height="23"><b>Total Job Cost :&nbsp;</b></td>
                    <td width="144" align="right" valign="top">
                        <input type="text" id="sub_total" name="sub_total" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" style="text-align:right;" readonly />
                    	<input type="text" id="sub_total_koma" name="sub_total_koma" class="easyui-numberbox" value="0" hidden
                        data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                        formatter:function(v){
                            return v;
                        },
                        parser:function(s){
                            var v = parseFloat(s);
                            return v;
                        }
                        " 
                         style="text-align:right;" readonly />
                    </td>
                </tr>
                </table>			
            </div>
        </div>
        <div id="form-footer" data-options="region:'south',border:false">
			<table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
				 <tr>
				   <td align="left">
						
				   </td>
					<td align="right">       
                    	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-document" onclick="show_legend();" plain="true">Legend</a>                       
						<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-help" onclick="" plain="true">Help</a>								
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" onclick="approval_jobs()" <?=($this->session->userdata('jobtitle_status') != 1 || $detail->TransStatus != 4 || (date('Y-m-d') < date('Y-m-d', strtotime($detail->JCostDate))))?'disabled':''?> >App. Mgr</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-reload" onclick="app_reverse()" <?=(in_array($detail->TransStatus,array(1,2)))?'':'disabled'?> style="<?= $cek_autority_reverse;?>" >Reverse</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onClick="update_data()" <?=(in_array($detail->TransStatus,array(0,1,2,3)))?'disabled':''?> <?php echo $cek_autority_save;?>>Save</a> 								
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_edit('Print Job Costing', '<?php echo $menu_link; ?>', 'icon-print', 'to_print_detail','<?php echo $detail->JCostNumber;?>')" <?=(in_array($detail->TransStatus,array(0,1,2,3,9,8)))?'':'disabled'?>>Preview & Print</a>
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="<?=($this->session->userdata('jobtitle_status')==0)?'suspend(2)':'parent.tab_close(\'tt\')'?>" <?=(!in_array($detail->TransStatus,array(0,4,6)))?'disabled':''?>><?=($this->session->userdata('jobtitle_status')==0)?'Cancel':'Close'?></a>	
					</td>
				 </tr>
			</table>				
		</div>
    </form>
</div>
<!-- Job Costing -->
<div id="dialog-job-cos" class="easyui-dialog" style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#job_cos">
    <form id="form_job_cos" method="post" novalidate>
        <table width="100%" align="left" border="0">
            <tr>
                <td width="308"><b>Persedian Barang Dalam Proses</b></td>
                <td width="10"><b>:</b></td>

                <td>
                    <select name="cmbx_item_job_costing" id="cmbx_item_job_costing" class="easyui-combobox" style="width:502px;" editable="false" 
                        data-options = "
                            valueField:'ItemCategory',
                            textField:'AccountName',
                            url:'<?php echo base_url(); ?>custom/get_data/persedian_barang_dalam_proses',
                            onSelect: function(rec){
                                var id = rec.ItemCategory;
                               
                                search_job_cos(id );	
                            }
                        ">
                    </select>
                </td>
            </tr>

            <tr>
                <td><b>Item Code</b></td>
                <td width="10"><b>:</b></td>
                
                <td>
                    <input type="text" style="width:500px;height:20px" name="txt_item_job_costing" id="txt_item_job_costing" class="easyui-validatebox" placeholder="Item Code" onkeyup="search_job_cos();" />
                </td>
            </tr>
            
            <tr>
                <td><b>Item Name</b></td>
                <td><b>:</b></td>
            
                <td>
                    <input type="text" style="width:500px;height:20px" name="txt_desc_job_costing" id="txt_desc_job_costing" class="easyui-validatebox" placeholder="Item Name" onkeyup="search_job_cos();" />
                </td>
            </tr>
            
            <tr>
                <td colspan="3">
                    <table id="dg_job_costiing" class="easyui-datagrid" singleSelect="true" style="width:828px;height:360px;"
                        url="<?Php echo base_url()?>list/job_costing/search_job_cos" 
                    >
                        <thead>
                            <tr bgcolor="">
                                <th halign="center" field="ItemCode" width="100%" sortable="true">Item Code</th>
                                <th halign="center" field="ItemDesc" width="100%" sortable="true">Name</th>
                                <th field="ItemUnit" width="200" sortable="true">Item Unit</th>
                                <th halign="center" field="ItemAverage" width="100%" sortable="true" hidden="true">Item Average</th>
                                <th halign="center" field="IsLock" width="200" sortable="true">Status</th>
                                <th halign="center" field="ItemCategoryID" width="200" sortable="true" hidden="true">ItemCategoryID</th>
                                <th halign="center" field="ItemQty" width="200" sortable="true" hidden="true">Item Qty</th>
                                <th halign="center" field="ItemLockId" width="200" sortable="true" hidden="true">Item Lock Id</th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- Dialog Button -->
<div id="job_cos">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_job_costing_ok();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-job-cos');">Cancel</a>
</div>
<?php $this->load->view('v_custom_pop_up');?>
<script type="text/javascript">
var SavePrivillage 	= '<?php echo $group_user->SavePrivillage;?>';
/*========================deklar variabel array for remove===================*/
var array_item 			= [];
var array_item_detail 	= [];
/*==============================end=========================================*/

$(document).ready(function(){
        $('#txt_no_hidden').val('<?php echo $detail->JCostNumber; ?>');
       
		
		$('#dg_job').datagrid({
			onLoadSuccess:function(){
				dg_item = $('#dg_job').datagrid('getRows');
				
				sub_total = 0;
				$.each(dg_item, function( index, value ) {
					sub_total+= parseFloat(value.ItemAmount);
                });

                $('#sub_total').numberbox('setValue',sub_total);
				$('#sub_total_koma').numberbox('setValue',sub_total);
			},
			onBeginEdit:function(rowIndex){
				editors = $('#dg_job').datagrid('getEditors',rowIndex);
				qty_editor		= $(editors[0].target);
				hpp_editor		= $(editors[1].target);
				ItemAmount		= $(editors[3].target);
				ItemType		= $(editors[5].target);
				RealHPP			= $(editors[7].target);
				
				ItemAmount.prop('readonly', true);
				var sub_total   = 0;
				
				/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
				save_button_begendedit(SavePrivillage);
				$('.app-button').linkbutton('disable');
				/*=================================end============================================================*/
				
				if(ItemType.val() == 0){
					hpp_editor.prop('readonly', true);
				}
				else{
					hpp_editor.prop('readonly', false);
				}
				
				qty_editor.numberbox({
					onChange:function(){
						qty 			= $(qty_editor).numberbox('getValue');
						hpp 			= $(hpp_editor).numberbox('getValue');
						
						amount = parseFloat(qty) * parseFloat(hpp);
						$(ItemAmount).numberbox('setValue',amount);
						
					}
				});
				
				hpp_editor.numberbox({
					onChange:function(){
						qty 	 = $(qty_editor).numberbox('getValue');
						hpp 	 = $(hpp_editor).numberbox('getValue');
						hpp_real = $(RealHPP).numberbox('setValue', hpp);
						
						amount = parseFloat(qty) * parseFloat(hpp);
						$(Amount_item).numberbox('setValue',amount);
					}
				});
			},
			onEndEdit:function(){
				var item        = $('#dg_job').datagrid('getRows');
                var sub_total   = 0;

                $.each(item, function( index, value ) {
                    if(value.ItemAmount != undefined){
                        sub_total+= parseFloat(value.ItemQty * value.ItemAverage_Real);
                    }				
                });

                $('#sub_total').numberbox('setValue',sub_total);
				$('#sub_total_koma').numberbox('setValue',sub_total);
				
				/*====================on end in edit saat grid di klik maka tombol save enable===================*/
				save_button_endedit(SavePrivillage);
				
				/*=================================end============================================================*/
			}
		});
		$('#fm_job_costing').click(function(){
			$('#dg_job').edatagrid('saveRow');
		});
		
		datagrid_item_type("dg_job");//untuk warna grid
});
	
function remove_row(){
	var item = $('#dg_job').datagrid('getData').total;

	if(item <= 1){
		$.messager.alert('Warning','Anda tidak dapat menghapus list item, minimum list item adalah satu (1)','error');
	}
	else {
		var selectedrow     = $('#dg_job').datagrid('getSelected');
		var row_index       = $('#dg_job').datagrid('getRowIndex', selectedrow);

		$.messager.confirm('Confirmation :', 'Anda yakin, Anda ingin menghapus item "' + selectedrow.ItemCode + '"',  
			function(r){
				if (r){
					array_item.push(selectedrow.JCostDetailID);
					array_item_detail.push(selectedrow.JCostDetailID, selectedrow.ItemCode, selectedrow.OldQty);
					
                   	$("#detail_id").val(JSON.stringify(array_item));
					$("#detail_item").val(JSON.stringify(array_item_detail));
					
                   	$('#dg_job').datagrid('deleteRow', row_index);	
					calculate_sub();	
					$('.save-button').linkbutton('enable');
				}
			}
		);        
					
	}            
}

function update_data(){
	var url             = '<?= base_url();?>custom/custom/checking_update';
	var no_transaksi    = $('#txt_no').val();
	var trans_status 	= '<?=$detail->TransStatus?>';
	
	var created_by 		= '<?php echo $detail->CreatedBy;?>';
	var login_as 			= '<?php echo $this->session->userdata('username');?>';
	var job_title 			= '<?php echo $this->session->userdata('jobtitle_status');?>'; 
			
	$('#dg_job').edatagrid('saveRow');
	var i=$('#dg_job').datagrid('getRows');
	var detail = JSON.stringify(i);
	$("#detail").val(detail);
	
	edit_transaction_check('<?php echo $menu_link;?>', '#fm_job_costing', no_transaksi, url, trans_status,created_by, login_as, job_title);
}

function approval_jobs() {
	var url_check           = '<?= base_url();?>custom/custom/checking_approval';
	var no_transaksi    	= $('#txt_no').val();
	
	checking_approval(no_transaksi,function(check){
		if(check.status == false){
			app_mgr();
		}else{
			$.messager.alert('Unseccessfull',check.message,'error',function(){
				location.reload();
			});
		}
	});
}

function app_mgr() {
	var url_check           = '<?= base_url();?>custom/custom/checking_approval';
	var no_transaksi    	= $('#dg_job').val();
	
	checking_approval(no_transaksi,function(check){
		if(check.status == false){
			approve_transaction();
		}else{
			$.messager.alert('Unseccessfull',check.message,'error',function(){
				location.reload();
			});
		}
	});
}

function approve_transaction(){
	var item 	= $('#dg_job').datagrid('getRows');
	var detail 	= JSON.stringify(item);
	$("#detail").val(detail);
	proses_custom_data('<?=$menu_link?>/approval_mgr','#fm_job_costing');
}

function app_reverse(){
    var no_transaksi    = $('#txt_no').val();
    var TransStatus     = '<?=$detail->TransStatus;?>';

    checking_reverse(no_transaksi,function(check){
        
        if(check.status == true){
            reversed_data('F','<?=$menu_link?>',no_transaksi, '<?=$menu_label?>');
        }else{
           $.messager.alert('Unseccessfull',check.message,'error',function(){
                location.reload();
            });
        }
    });
}

function suspend(type){
	var created_by 		= '<?php echo $detail->CreatedBy;?>';
	var login_as 		= '<?php echo$this->session->userdata('username');?>';
	var job_title 		= '<?php echo $this->session->userdata('jobtitle_status');?>';
	var url             = '<?= base_url();?>custom/custom/checking_suspend';
	
	suspend_check_trans('F', type, '<?=$menu_link?>', $('#txt_no').val(), 'Job Costing', url, created_by, login_as, job_title);
}

function calculate_sub(){
	$('#dg_job').edatagrid('saveRow');

	var item        	= $('#dg_job').datagrid('getRows');
	var sub_total   	= 0;
	 
	$.each(item, function( index, value ) {
		if(value.ItemAmount != undefined){
			 sub_total+= parseFloat(value.ItemQty * value.ItemAverage_Real);
		}			
	});
	
	$('#sub_total').numberbox('setValue',sub_total);
	$('#sub_total_koma').numberbox('setValue',sub_total);
}
</script>