<!---- 
    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    = "disabled";
            }
			
			//-------------end----------------------------

            $FDNumber   = $detail->FDNumber;
            $FDNumber   = str_replace('/', 'slash', $FDNumber);
?>	
<div class="easyui-layout" data-options="fit:true,border:false">
    <form id="fm_fixed_asset_dispose" name="fm_fixed_asset_dispose" method="post">
		<input type="hidden" name="detail" id="detail" />
		<input type="hidden" name="id" id="id" value="<?= $detail->FDNumber; ?>"/>
        
        <!-- 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">
                        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-journal" plain="true"  id="btn_journal" 
							onclick="parent.tab_add('Preview Journal <?=$menu_label?>', '<?= $menu_link; ?>', 'icon-print', 'to_preview_journal/<?= $detail->FDNumber ?>')" <?php echo $cek_autority_journal;?>>Journal
						</a>
                        
                        <input type="checkbox" class="easyui-checkbox" name="chk_suspended" id="chk_suspended" style="margin-top:0px;margin-right:1px;" onClick="suspend(1)" <?=(!in_array($detail->TransStatus,array(4,5,6))) ? 'disabled' : ''?> <?=(($detail->TransStatus==3)?'checked':'')?> <?php echo $cek_autority_delete;?>/>
                    	<span style="display:inline-block;margin-top:2px;<?=(($detail->TransStatus==3)?'color:gray;':'color:black')?>">Suspend Transaction</span>
                    	<a href="#" class="easyui-linkbutton" id="refresh-linkbutton" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</a>
                    </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">
        <?php if($detail->TransStatus == 2){ ?>
            <div class="blanket"></div>
            <div class="paid-box"><b>Finished</b></div>
        <?php }else if($detail->TransStatus==1){ ?>
             <div class="blanket"></div>
             <div class="suspend-box"><b>On Progress</b></div>
		<?php }else if($detail->TransStatus==3){ ?>
             <div class="blanket"></div>
             <div class="suspend-box"><b>Suspended</b></div>
        <?php
        }
        ?>
            <div id="form-wrapper" class="easyui-panel"  style="width:1180px;height:526px;padding:5px;" fit='true'>
               
                <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="150"><b>Gain / Loss Account</b></td>
                            <td colspan="3">
                                <b>:</b>
                                <select name="cmb_gl" class="easyui-combogrid" id="cmb_gl" required="required" editable="false"  style="width:400px;height:22px;" data-options="
                                panelWidth: 400,
                                value     : '<?= $detail->GLAccount?>',
                                idField: 'AccountNumber',
                                textField: 'AccountName',
                                url: '<?= base_url().$menu_link; ?>/get_gl_account',               
                                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 height="20">&nbsp;</td>
                                <td width="731" align="center" valign="middle"></td>
                                <td width="250" align="center" valign="middle" bgcolor="#333399" ><span style="color:#fff;">Dispose Fixed Asset No.</span></td>
                                <td width="150" align="center" valign="middle" bgcolor="#333399" ><span style="color:#fff;">Date</span></td>
                                
                            </tr>
                            <tr>
                                <td height="20">&nbsp;</td>
                                <td align="center" valign="top">&nbsp;</td>
                                <td align="left" valign="top"><input name="txt_fd_no" id="txt_fd_no" type="text" value="<?= $detail->FDNumber;?>" style="width:250px; height:18px" required editable="false" readonly /></td>
                                <td align="right" valign="top"><input name="txt_date" id="txt_date" type="text" value="<?= $detail->FDDate;?>" class="easyui-datebox validBackward" style="width:150px" required editable="false" readonly/></td>
                            </tr>
                        </table>
                    </td>
            	</tr>											
                </table>	

                 <!--Item Grid -->
                <div class="easyui-tabs" data-options="tabHeight:18">
                    <div title="Items">
                        <table id="dg_fd" class="easyui-edatagrid" idField="id"
                            rownumbers="true" fitColumns="true" url="<?= base_url().$menu_link;?>/get_detail_fixed_asset/<?=$FDNumber;?>"
                            singleSelect="true" style="height:256px;" 
                            >
                            <thead>
                            <tr>
                                <th field="AssetCode"   halign="center" align="left" valign="middle"    data-options="width:400,align:'left'"           editor="{options:{required:true}}">AssetCode</th>
                                <th field="ItemCode"    halign="center" align="left" valign="middle"    data-options="width:400,align:'left'"           editor="{options:{required:true}}">ItemCode</th>
                                <th field="Description" halign="center" align="left" valign="middle"    data-options="width:700,align:'left'"           editor="description">Item Description</th>
                                <th field="Qty"         halign="center" align="left" valign="middle"    data-options="width:200,align:'left'"           editor="{type:'numberbox',options:{required:true,min:1,disabled:true}}">Qty</th>
                                <th field="Amount"         halign="center" align="left" valign="middle"    data-options="width:200,align:'left'"           editor="{type:'numberbox',options:{required:true,min:0.01,disabled:true}}" formatter="formatRp" >Amount</th>
                                <th field="ItemAverage"         halign="center" align="left" valign="middle"    data-options="width:200,align:'left'"           editor="{type:'numberbox',options:{required:true,min:0.01,disabled:true}}" formatter="formatRp" hidden="true">ItemAverage</th>
                                <th field="ReceiptNumber" data-options="width:200,align:'left'" hidden="true">ReceiptNumber</th>
                                <th field="FixedAssetType" data-options="width:200,align:'left'" hidden="true">FixedAssetType</th>
                                <th field="ItemCategoryID" width="200" halign="center" align="left" hidden="true">ItemCategoryID</th>
                                
                            </tr>
                            </thead>
                        </table>                 
                    </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->FDDesc; ?></textarea></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td width="301" align="right" valign="top" height="23"><b>Total Amount :&nbsp;</b></td>
                    <td width="144" align="right" valign="top">
                        <input type="text" id="TotalAmount" name="TotalAmount" class="easyui-numberbox" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" style="text-align:right;" value="<?= $detail->TotalAmount?>" 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-help" onclick="" plain="true">Help</a>								
                        <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-ok" onclick="app_dir()" <?=($this->session->userdata('jobtitle_status') != 0 || $detail->TransStatus != 5 || (date('Y-m-d') < date('Y-m-d', strtotime($detail->FDDate))))?'disabled':''?> >App. Dir</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,9)))?'':'disabled'?> <?php echo $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 Dispose Fixed Asset', '<?php echo $menu_link; ?>', 'icon-print', 'to_print_detail','<?php echo $detail->FDNumber;?>')" <?=(in_array($detail->TransStatus,array(1,2,3,9)))?'':'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,5,6)))?'disabled':''?>><?=($this->session->userdata('jobtitle_status')==0)?'Cancel':'Close'?></a>	
					</td>
				 </tr>
			</table>				
		</div>
    </form>
</div>


<script type="text/javascript">

$(document).ready(function(){
    $("#fm_fixed_asset_dispose").click(function(){
        $('#dg_fd').edatagrid('saveRow');
    });
});


function update_data(){

    $('#dg_fd').edatagrid('saveRow'); 

    var row         = $('#dg_fd').datagrid('getRows');
    var totalAmount = 0;

    $.each(row, function(ind, value) {
        totalAmount += value.Amount;
    });

    if(totalAmount <= 0){
        $.messager.alert('Unseccessfull','Total Amount tidak boleh nol','error',function(){
            return false;
        });
    }else{
        var detail = JSON.stringify(row);
        $('#detail').val(detail);
        edit_data('<?= $menu_link?>','#fm_fixed_asset_dispose');
    }
}

function app_dir(){
	approved_dir('<?=$menu_link?>','#fm_fixed_asset_dispose');
}

function suspend(type){
	suspend_data_new('F', type, '<?=$menu_link?>', $('#txt_fd_no').val(), 'Dispose Fixed Asset');
}

function app_reverse(){
    reversed_data('F','<?=$menu_link?>', $('#txt_fd_no').val(), 'Dispose Fixed Asset');
}

</script>