<!---- 
    Author 	: Herpan / Tanggal : 12-08-2014	
    Revisi 	: Ferry / Tanggal : 16-01-2015
-->

	<?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";
				}
				
				//-------------end----------------------------
	?>


<style>
.datagrid-header-row [field='ck'] input{
    display:none;
}
</style>

<div class="easyui-layout" data-options="fit:true,border:false">
    <!-- Top view-->
    <div id="form-header" data-options="region:'north',border:false" >
        <div id="form-header-wrapper">
            <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="left" width="30%">
                        <input type="checkbox" name="chk_suspended" id="chk_suspended" value="3" onClick="suspend(1);" style="margin-top:0px;margin-right:1px;" <?php if($detail->TransStatus == 3){ echo"checked"; } ?> <?=((!in_array($detail->TransStatus,array(0,6,4)))?"disabled":"")?> <?php echo $cek_autority_delete;?>/>
                    	<span style="display:inline-block;margin-top:2px;<?=(($detail->TransStatus==3)?'color:gray;':'color:black')?>">Suspend</span>
                        
                        <a href="#" class="easyui-linkbutton" iconCls="icon-journal" plain="true" onclick="parent.tab_add('Journal <?=$menu_label?>', '<?=$menu_link?>', 'icon-print', 'to_preview_journal/<?=$detail->PInvNumber?>');" >Journal</a>
                        <a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-currency" onclick="to_transaction()" <?=(in_array($detail->TransStatus,array(1)))?'':'disabled'?>>To Purchase Payment</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){
                                if($this->session->userdata('jobtitle_status')==1){
                                    echo 'Need Your Approval';
                                }
                                else{
                                    echo 'Need Manager Approval';
                                }
                            }
                            elseif($detail->TransStatus==5){
                                if($this->session->userdata('jobtitle_status')==0){
                                    echo 'Need Your Approval';
                                }
                                else{
                                    echo 'Need Director Approval';
                                }
                            }
                            elseif($detail->TransStatus==6){
                                if($this->session->userdata('jobtitle_status')==1){
                                    echo 'Need Your Approval';
                                }
                                elseif($this->session->userdata('jobtitle_status')==0){
                                    echo 'Need Your Approval';
                                }
                                else{
                                    echo 'Need Director and Manager Approval';
                                }
                            }elseif($detail->TransStatus==1){
                                echo 'On Progress';
                            }
                            ?>
                        </span>
                    </td>
                    
                    <td align="right" width="30%">
                        <span class="form-title"><?=$menu_label?></span>							
                    </td>
                </tr>
            </table>		     	
        </div>			
    </div>
    <!-- End of top view -->
        
    <!-- center view -->
    <div id="form-body" data-options="region:'center',border:false">
        <div id="form-wrapper" class="easyui-panel" fit="true" style="padding:5px;">
            <?php if(in_array($detail->TransStatus,array(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==9){ echo 'Canceled by Dir.'; }else{ echo 'Unknown'; } ?></b></div>
            <?php } ?>
        	
            <form id="fm_purchase_invoice" name="fm_purchase_invoice" method="post">
                <input type="hidden" name="detail" id="detail"/>
                <input type="hidden" name="hdn_ppn10_pcnt" id="hdn_ppn10_pcnt"/>
                <input type="hidden" name="hdn_pph22_pcnt" id="hdn_pph22_pcnt"/>
                <input type="hidden" name="hdn_pph23_pcnt" id="hdn_pph23_pcnt"/>
                <input type="hidden" name="txt_prec_no" id="txt_prec_no" value="<?=$detail->PRecNumber?>" />
                <input type="hidden" name="txt_prec_date" id="txt_prec_date" class="easyui-validatebox textbox" required="required" value="<?=$detail->PRecDate?>" style="width:120px;" readonly editable="false" <?=(!in_array($detail->TransStatus,array(0,6)))?'disabled':''?> />
                <input type="hidden" name="hdn_currency_code" id="hdn_currency_code"/>
                <input type="hidden" name="hdn_taxes_status" id="hdn_taxes_status"/>
                <input type="hidden" name="hdn_intax_status" id="hdn_intax_status"/>
                <input type="hidden" name="hdn_pord_no" id="hdn_pord_no" value="<?php echo $detail->POrdNumber ?>"/>
                <input type="hidden" name="txt_old_pinv" id="txt_old_pinv" value="<?php echo $detail->OldPInvNumber ?>"/>
                
            	<!-- Form Header -->
                <table width="100%" height="140" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="66%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1">
                                <tr height="20">
                                    <td width="120"><b>Vendor Name</b></td>
                                    <td width="10"><b>:</b></td>

                                    <td width="270" colspan='2'>
                                        <select name="cbg_vendor" class="easyui-combogrid" id="cbg_vendor" style="width:180px;height:20px" editable="false" required readonly 
                                            data-options="
                                                panelWidth: 445,
                                                value:'<?php echo $detail->VendorCode ?>', 
                                                idField: 'VendorCode', 
                                                textField: 'VendorName', 
                                                url: '<?php echo base_url(); ?>custom/get_data/vendor', 
                                                fitColumns: true,
                                                method: 'get', 
                                                columns: [[
                                                    {field:'VendorCode', title:'Vendor No', halign:'center', align:'center', width:110},
                                                    {field:'VendorName',title:'Vendor Name', halign:'center', width:250}
                                                ]]
                                            ">
                                        </select>
                                        
                                        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-sales'" onClick="select_ri();" disabled>Select RI</a>
                                        
                                        <span class="disableme" style="display:none;">
                                            <input type="checkbox" name="chk_taxtable" id="chk_taxtable" value="1" onClick="set_ppn_value();" disabled>Taxable
                                        </span>
                                        
                                        <span class="disableme1" style="display:none;">
                                            <input type="checkbox" name="chk_inclusive" id="chk_inclusive" value="1" disabled>Inclusive Tax
                                        </span>                                                                                
                                    </td>
                                    
                                    <td width='132' class="disableme2" style="display:none;" valign="middle" >
                                        <input type="checkbox" id="chk_vendor_dp" name="chk_vendor_dp" value='1' disabled />Vendor Needs DP
                                    </td>
                                </tr>

                                <tr id="row_currency_rate" style="display:none">
                                    <td><b>Currency Rate</b></td>
                                    <td><b>:</b></td>
                                    
                                    <td colspan="5">
                                        <input type="text" name="txt_currency_rate" id="txt_currency_rate" class="easyui-numberbox currency" style="width:70px;text-align:right;" readonly
                                            data-options=" min:1, precision:2, decimalSeparator:',', groupSeparator:'.'"/>
                                        <span id="currency" style="font-weight:bold"></span>
                                    </td>
                                </tr>

                                <tr id="row_fiscal_rate" style="display:none;">
                                    <td><b>Fiscal Rate</b></td>
                                    <td><b>:</b></td>
                                    
                                    <td colspan="5">
                                        <input type="text" name="txt_fiscal_rate" id="txt_fiscal_rate" class="easyui-numberbox currency" style="width:70px;text-align:right;" <?=(!in_array($detail->TransStatus,array(0,4)))?'disabled':''?>
                                            data-options=" min:1, precision:2, decimalSeparator:',', groupSeparator:'.'"/>
                                        <span id="fiscal" style="font-weight:bold"></span>
                                    </td>
                                </tr>

                                <tr height="20">
                                    <td width="120" valign="top" style="padding-top:4px;"><b>Vendor Address</b></td>
                                    <td width="10" valign="top" style="padding-top:4px;"><b>:</b></td>
                                    
                                    <td>
                                        <textarea name="txa_address" id="txa_address" rows="4" style="width:254px;resize:none;" readonly><?=$detail->VendorAddress?></textarea>
                                        <!-- <p id="tes">hanya Kamu yang bisa, aku syg kamu </p> -->
                                    </td>
                                </tr>
                            </table>
                        </td>
                    
                        <td width="34%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                                <tr height="20">
                                    <td width="206" style="background:#333399;text-align:center;color:#FFF;">PI. No.</td>
                                    <td width="122" style="background:#333399;text-align:center;color:#FFF;">PI. Date</td>
                                    <td width="122" style="background:#333399;text-align:center;color:#FFF;">Terms</td>
                                </tr>
                        
                                <tr height="20">
                                    <td><input type="text" name="txt_pinv_no" id="txt_pinv_no" class="easyui-validatebox" required="true" value="<?=$detail->PInvNumber?>" style="width:200px;text-align:center;" readonly /></td>
                                    <td><input type="text" name="txt_pinv_date" id="txt_pinv_date" class="easyui-datebox" required="required" style="width:122px;height:20px" editable="false" readonly/></td>

                                    <td>
                                        <select class="combo-grid" required="required"
                                            name="cbo_terms" id="cbo_terms" 
                                            style="width:122px;height:20px;" 
                                            <?=(!in_array($detail->TransStatus,array(0,4)))?'disabled':''?>
                                            data-options="
                                                panelWidth: 250,
                                                value:'<?=$detail->TermsPaymentID?>',
                                                idField: 'TermspaymentID',
                                                textField: 'TermDesc',
                                                url:'<?=base_url()?>custom/get_data/termspayment',                                        
                                                method: 'get',
                                                columns: [[
                                                    {field:'TermspaymentID',title:'Terms payment ID',width:90,halign:'center'},
                                                    {field:'TermDesc',title:'Term Desc',width:90,halign:'center'}
                                                ]],
                                                fitColumns: true
                                            ">
                                        </select>
                                    </td>
                                </tr>

                                <tr height="20">
                                    <!-- <td style="background:#333399;text-align:center;color:#FFF;">RI. No.</td>
                                    <td style="background:#333399;text-align:center;color:#FFF;">RI. Date</td> -->
                                    <td style="background:#333399;text-align:center;color:#FFF;">Vendor Inv. No.</td>
                                    <td style="background:#333399;text-align:center;color:#FFF;">Ship Date</td>
                                    <td style="background:#333399;text-align:center;color:#FFF;">FOB</td>
                                </tr>

                                <tr height="20">
                                    <!-- <td><input type="text" name="txt_prec_no" id="txt_prec_no" class="easyui-validatebox" required="true" value="<?=$detail->PRecNumber?>" style="width:200px;text-align:center;" readonly <?=(!in_array($detail->TransStatus,array(0,6)))?'disabled':''?> /></td>
                                    <td><input type="text" name="txt_prec_date" id="txt_prec_date" class="easyui-validatebox textbox" required="required" value="<?=$detail->PRecDate?>" style="width:120px;" readonly editable="false" <?=(!in_array($detail->TransStatus,array(0,6)))?'disabled':''?> /></td> -->
                                    <td><input type="text" name="txt_vendor_inv_no" id="txt_vendor_inv_no" class="easyui-validatebox" value="<?=$detail->VendInvNumber?>" style="width:200px;text-align:center;" <?=(!in_array($detail->TransStatus,array(0,6)))?'readonly':''?> /></td>
                                    <td><input type="text" name="txt_shipment_date" id="txt_shipment_date" class="easyui-datebox" style="width:122px;height:20px" editable="false" readonly /></td>
                                    <td>
                                        <select class="easyui-combogrid" required="required"
                                            name="cbo_fob" id="cbo_fob" 
                                            style="width:122px;height:20px;" 
                                            <?=(!in_array($detail->TransStatus,array(0,4)))?'disabled':''?>
                                            data-options="
                                                panelWidth: 250,
                                                value:'<?php echo $detail->FOBID; ?>',
                                                idField: 'FobID',
                                                textField: 'FobName',
                                                url:'<?=base_url()?>custom/get_data/fob',                                     
                                                method: 'get',
                                                columns: [[
                                                    {field:'FobID',title:'FOB ID',width:90,halign:'center'},
                                                    {field:'FobName',title:'FOB Name',width:90,halign:'center'}
                                                ]],
                                                fitColumns: true
                                            ">
                                        </select>
                                    </td>
                                </tr>
                                
                                <tr height="20">
                                   <!--  <td style="background:#333399;text-align:center;color:#FFF;">Vendor Inv. No.</td>
                                    <td style="background:#333399;text-align:center;color:#FFF;">Ship Date</td> -->
                                    <td></td>
                                    <td></td>
                                    <td style="background:#333399;text-align:center;color:#FFF;">Ship Via</td>
                                </tr>
                                
                                <tr height="20">
                                    <!-- <td><input type="text" name="txt_vendor_inv_no" id="txt_vendor_inv_no" class="easyui-validatebox" value="<?=$detail->VendInvNumber?>" style="width:200px;text-align:center;" <?=(!in_array($detail->TransStatus,array(0,6)))?'readonly':''?> /></td>
                                    <td><input type="text" name="txt_shipment_date" id="txt_shipment_date" class="easyui-datebox" style="width:122px;height:20px" editable="false" readonly /></td> -->
                                    <td></td>
                                    <td></td>
                                    <td>
                                        <select class="combo-grid" required="required"
                                            name="cbo_ship_via" id="cbo_ship_via" 
                                            style="width:122px;height:20px;" 
                                            <?=(!in_array($detail->TransStatus,array(0,4)))?'disabled':''?>
                                            data-options="
                                                panelWidth: 250,
                                                value:'<?=$detail->ShipmentID?>',
                                                idField: 'ShipmentID',
                                                textField: 'ShipmentName',
                                                url:'<?=base_url()?>custom/get_data/shipment',                                     
                                                method: 'get',
                                                columns: [[
                                                    {field:'ShipmentID',title:'Shipment ID',width:90,halign:'center'},
                                                    {field:'ShipmentName',title:'Shipment Name',width:90,halign:'center'}
                                                ]],
                                                fitColumns: true
                                            ">
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <!-- End of form header -->

                <!--Item Grid -->
                <div class="easyui-tabs" data-options="tabHeight:18" style="margin:5px 0px;">		
                    <div id="tab_item" title="Item">
                        <table id="dtg_item" class="easyui-datagrid" idField="PRecDetailID" rownumbers="true" fitColumns="true" singleSelect="true" style="height:250px;" 
                            url="<?=base_url() . $menu_link . "/ajax_item_for_edit/" . $detail->PInvNumber?>" 
                            data-options = "
                                onDblClickRow:function(index,row){
                                    //alert(index);
                                    var number_string           = $('#dtg_item').datagrid('getSelected').PRecNumber;
                                    var length_number_string    = number_string.length;
                                    var arr_number              = number_string.split(',');
                                    var total_number            = arr_number.length;
                                    var pos_char                = get_character_position('datagrid-row-r4-2-0');

                                    var no_trans                = '';

                                    for(var x=0;x<total_number;x++){
                                        var length_per_number       = arr_number[x].length;
                                        var start_pos               = x * length_per_number;
                                        var end_pos                 = start_pos + length_per_number;
                                        if((pos_char >=start_pos) && (pos_char<= end_pos)){
                                            no_trans                = arr_number[x];
                                        }
                                    }

                                    if(pos_char < length_number_string){
                                        parent.tab_edit('Edit Receive Item','list/receive_item', 'icon-edit', 'edit',no_trans);
                                    }
                                }
                            "
                            >
                            <thead>
                                <tr>
                                    <th field="PRecNumber" width="60" editor="text" data-options="halign:'center',align:'left'">RI No.</th>
                                    <th field="ItemCode" width="50" editor="text" data-options="halign:'center',align:'left'">Item</th>
                                    <th field="ItemCodeVendor"   width="50"  data-options="halign:'center',align:'left'"   ><?php echo label_grid('no_seri');?></th>
                                    <th field="ItemDesc" width="150" editor="text" data-options="halign:'center',align:'left'">Description</th>
                                    <th field="ItemQty" width="30" data-options="halign:'center',align:'center'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true}}" formatter="formatRp">Qty</th>
                                    <th field="ItemUnit" width="30" editor="text" data-options="halign:'center',align:'center'">Unit</th>
                                    <th field="ItemPrice" width="40"  data-options="halign:'center',align:'right'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:1,required:true,disabled:false}}" formatter="formatRp" >Unit Price</th>
                                    <th field="ItemDiscPcnt"  	 width="40"  data-options="halign:'center',align:'right'"  editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',required:true,disabled:false}}" formatter="formatRp" >Item Disc %</th>	
                                    <th field="ItemAmount" width="40" data-options="halign:'center',align:'right'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:1,required:true,disabled:false}}" formatter="formatRp" >Item Amount</th>

                                    <th field="ItemTaxPPn10" width="50" data-options="halign:'center',align:'right'" 
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Item Tax PPn</th>   
                                    <th field="ItemTaxPPn10_Hide" width="40" data-options="halign:'center',align:'right'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:1,required:true,disabled:false}}" formatter="formatRp" hidden>Item Tax PPn</th>
                                                                     
                                    <th field="ItemTaxPPh22" width="50" data-options="halign:'center',align:'right'" 
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                   	 hidden>Item Tax PPh22</th>
                                    <th field="ItemTaxPPh22_Hide" width="40" data-options="halign:'center',align:'right'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:1,required:true,disabled:false}}" formatter="formatRp" hidden>Item Tax PPh22</th>
                                    
                                    <th field="ItemTaxPPh23" width="50" data-options="halign:'center',align:'right'" 
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Item Tax PPh23</th>
                                    <th field="ItemTaxPPh23_Hide" width="40" data-options="halign:'center',align:'right'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:1,required:true,disabled:false}}" formatter="formatRp" hidden>Item Tax PPh23</th>
                                    
                                    <th field="ItemTotalAmount" width="50" data-options="halign:'center',align:'right'" 
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Item Total Amount</th>                                    
                                    <th field="ItemCategoryID" width="50" data-options="halign:'center',align:'center'" editor="text" hidden>Category ID</th>
                                    <th field="ItemCategoryCode" width="50" data-options="halign:'center',align:'center'" editor="text" hidden>Category Code</th>								
                                    <th field="ItemType" width="50" data-options="align:'center',halign:'center'" editor="text" hidden>Item Type</th>
                                    <th field="PInvDetailID" width="50" data-options="halign:'center',align:'center'" editor="text" hidden>PInv Detail ID</th>
                                    <th field="ItemPPh22Status" width="50" data-options="halign:'center',align:'center'" hidden>PPh222 Status</th>
                                    <th field="ItemAdvNetDueIn" width="50" data-options="halign:'center',align:'center'" hidden>Net Due In</th>
                                    <th field="ItemStatus" width="50" data-options="halign:'center',align:'center'" hidden>Item Status</th>	
                                    						
                                	<th field="AmountDisc"  width="40"  data-options="halign:'center',align:'right'"  
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Amount Disc</th>
                                    
                                    <th field="ItemAmount_Hide"  width="40"  data-options="halign:'center',align:'right'"  
                                    editor="{type:'numberbox',options:{decimalSeparator:',',
                                    formatter:function(v){
                                        return v;
                                    },
                                    parser:function(s){
                                        var v = parseFloat(s);
                                        return v;
                                    }
                                    }}"
                                    hidden>Item Amount Hide</th>
                                </tr>
                            </thead>                                  	
                        </table>										  
                    </div>
                </div>
                <!-- End Item Grid -->

                <table width="100%" cellpadding="0" cellspacing="0">
                    <tr>
                        <td width="50%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1">
                                <tr>
                                    <td width="120" valign="top" style="padding-top:4px;"><b>Description</b></td>
                                    <td width="10" valign="top" style="padding-top:4px;"><b>:</b></td>
                                    
                                    <td>
                                        <textarea name="txa_description" id="txa_description" rows="4" style="width:335px;resize:none;" <?=(!in_array($detail->TransStatus,array(0,4)))?'readonly':''?>><?=$detail->PInvDesc?></textarea>
                                    </td>
                                </tr>
                            </table>
                        </td>

                        <td width="50%" valign="top">
                            <table width="100%" cellpadding="0" cellspacing="1">
                                <tr>
                                    <td rowspan="8">&nbsp;</td>
                                    <td width="120"><b>Sub Total</b></td>
                                    <td width="10"><b>:</b></td>
                                    
                                    <td width="171" align="right">
                                        <input type="text" id="txt_sub_total" name="txt_sub_total" class="easyui-numberbox" value="<?=$detail->PInvSubTotal?>" style="text-align:right;width:173px;" readonly 
                                            data-options="min:0,precision:2,groupSeparator:'.',decimalSeparator:','"
                                        />
                                        
                                        <input type="hidden" id="txt_sub_total_hide" name="txt_sub_total_hide" value="0" class="easyui-numberbox" style="text-align:right;" readonly
                                            data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                                            formatter:function(v){
                                                return v;
                                            },
                                            parser:function(s){
                                                var v = parseFloat(s);
                                                return v;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>

                                <tr>
                                    <td><b>Discount</b></td>
                                    <td><b>:</b></td>

                                    <td align="right">
                                        <input type="text" name="txt_discount" id="txt_discount" class="easyui-numberbox" value="<?=$detail->PInvDiscount?>" style="text-align:right;width:173px;" <?=(!in_array($detail->TransStatus,array(0,4)))?'readonly':''?>
                                            data-options="min:0,precision:2,groupSeparator:'.',decimalSeparator:','" readonly
                                        />
                                        
                                        <input type="hidden" id="txt_discount_hide" name="txt_discount_hide" value="0" class="easyui-numberbox" style="text-align:right;" readonly
                                            data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                                            formatter:function(v){
                                                return v;
                                            },
                                            parser:function(s){
                                                var v = parseFloat(s);
                                                return v;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>

                                <tr>
                                    <td>
                                        <span id="lbl_ppn10" style="font-weight:bold">PPn (10%)</span>
                                    </td>
                                    
                                    <td width="10"><b>:</b></td>

                                    <td align="right">
                                        <input type="numberbox" name="txt_ppn10" id="txt_ppn10" class="easyui-numberbox" value="0" min="0" style="text-align:right;" readonly
                                            data-options="min:0,precision:2,groupSeparator:'.',decimalSeparator:','"
                                        />
                                        
                                        <input type="hidden" id="txt_ppn10_hide" name="txt_ppn10_hide" value="0" class="easyui-numberbox" style="text-align:right;" readonly
                                            data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                                            formatter:function(v){
                                                return v;
                                            },
                                            parser:function(s){
                                                var v = parseFloat(s);
                                                return v;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>                    

                                <tr>
                                    <td>
                                        <span id="lbl_pph22" style="font-weight:bold">PPh22 (2.5%)</span>
                                    </td>

                                    <td><b>:</b></td>

                                    <td align="right">
                                        <input type="numberbox" name="txt_pph22" id="txt_pph22" class="easyui-numberbox" value="<?=$detail->PInvPPh22?>" style="text-align:right;" readonly
                                            data-options="min:0,precision:2,groupSeparator:'.',decimalSeparator:','"
                                        />
                                        
                                        <input type="hidden" id="txt_pph22_hide" name="txt_pph22_hide" value="0" class="easyui-numberbox" style="text-align:right;" readonly
                                            data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                                            formatter:function(v){
                                                return v;
                                            },
                                            parser:function(s){
                                                var v = parseFloat(s);
                                                return v;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>

                                <tr>
                                    <td>
                                        <span id="lbl_pph23" style="font-weight:bold">PPh23 (2%)</span>
                                    </td>

                                    <td><b>:</b></td>

                                    <td align="right">
                                        <input type="numberbox" name="txt_pph23" id="txt_pph23" class="easyui-numberbox" value="<?=$detail->PInvPPh23?>" style="text-align:right;" readonly
                                            data-options="min:0,precision:2,groupSeparator:'.',decimalSeparator:','"
                                        />
                                        
                                        <input type="hidden" id="txt_pph23_hide" name="txt_pph23_hide" value="0" class="easyui-numberbox" style="text-align:right;" readonly
                                            data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                                            formatter:function(v){
                                                return v;
                                            },
                                            parser:function(s){
                                                var v = parseFloat(s);
                                                return v;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td><b>Est. Freight</b></td>
                                    <td><b>:</b></td>

                                    <td align="right">
                                        <input type="numberbox" name="txt_freight" id="txt_freight" class="easyui-numberbox" value="0" style="text-align:right;" <?=(!in_array($detail->TransStatus,array(0,4)))?'readonly':''?>
                                            data-options="precision:2,groupSeparator:'.',decimalSeparator:','"
                                        />
                                    </td>
                                </tr>

                                <tr><td colspan="3"><hr/></td></tr>

                                <tr>
                                    <td><b>Total Purchase</b></td>
                                    <td><b>:</b></td>
                                    
                                    <td align="right">
                                        <input type="numberbox" name="txt_total_purchase" id="txt_total_purchase" class="easyui-numberbox" value="0" style="text-align:right;" readonly  
                                            data-options="min:0,precision:2,groupSeparator:'.',decimalSeparator:','"
                                        />
                                        
                                        <input type="hidden" id="txt_total_purchase_hide" name="txt_total_purchase_hide" value="0" class="easyui-numberbox" style="text-align:right;" readonly
                                            data-options="min:0,decimalSeparator:',',groupSeparator:'.',
                                            formatter:function(v){
                                                return v;
                                            },
                                            parser:function(s){
                                                var v = parseFloat(s);
                                                return v;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>

                                <tr>
                                    <td rowspan="8">&nbsp;</td>
                                    <td  width="120"><b>Total DP</b></td>
                                    <td><b>:</b></td>
                                    
                                    <td align="right">
                                        <input type="numberbox" name="txt_total_dp" id="txt_total_dp" class="easyui-numberbox" value="0" style="text-align:right;" readonly  
                                            data-options="min:0,precision:2,groupSeparator:'.',decimalSeparator:','"
                                        />
                                    </td>
                                </tr>

                                <tr><td colspan="3"><hr/></td></tr>
                                                        
                                <tr>
                                    <td><b>Outstanding</b></td>
                                    <td><b>:</b></td>
 
                                    <td align="right">
                                        <input type="numberbox" name="txt_total_invoice" id="txt_total_invoice" class="easyui-numberbox" value="<?=$detail->PInvTotalAmount?>" style="text-align:right" readonly
                                            data-options="precision:2,groupSeparator:'.',decimalSeparator:','"
                                        />
                                        
                                        <input type="hidden" id="txt_total_invoice_hide" name="txt_total_invoice_hide" value="0" class="easyui-numberbox" style="text-align:right;" readonly
                                            data-options="decimalSeparator:',',groupSeparator:'.',
                                            formatter:function(v){
                                                return v;
                                            },
                                            parser:function(s){
                                                var v = parseFloat(s);
                                                return v;
                                            }
                                            " 
                                        />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    
    <div id="form-footer" data-options="region:'south',border:false">  
    	<table width="100%" cellpadding="0" cellspacing="0">
            <tr>                
                <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_data(1);" <?=($this->session->userdata("jobtitle_status") != 1 || !in_array($detail->TransStatus,array(4,6)) || (date('Y-m-d') < date('Y-m-d', strtotime($detail->PInvDate))))?'disabled':''?>>App. Mgr</a>
                    <?php
					if(($group_user->ReversePrivillage == 1)){
					?>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button app-button" iconCls="icon-reload" onclick="app_reverse()" <?=(($this->session->userdata("jobtitle_status") == 0) && (in_array($detail->TransStatus,array(1,2,8))))?'':'disabled'?>>Reverse</a>  
                    <?php
					}
					?>
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="update_data();" <?=(!in_array($detail->TransStatus,array(0,4)))?'disabled':''?> <?php echo $cek_autority_save;?>>Save</a> 								
                    <!-- <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="link_print('<?php echo $menu_link ?>/to_print_detail/<?php echo $detail->POrdNumber ?>');" <?=(in_array($detail->TransStatus,array(3,9)))?'disabled':''?>>Preview & Print</a>   --> 
                    <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="parent.tab_add('Form <?=$menu_label?>', '<?=$menu_link?>', 'icon-print', 'to_print_detail/<?=$detail->PInvNumber?>');" <?=(in_array($detail->TransStatus,array(6,4,5,1,2,3)))?'':'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(3,9)) || $detail->AppLevel2Status==1)?'disabled':''?>><?=($this->session->userdata('jobtitle_status')==0)?'Cancel':'Close'?></a>
    		</td>
            </tr>
        </table>
    </div>
</div>

<div id="dialog-ri" class="easyui-dialog" style="width:725px;height:525px;background-color:#F8F8F8;padding:0px;" closed="true" data-options="modal:true, iconCls:'icon-edit'" buttons="#dialogpo-buttons">
    <table id="tt_choose_ri" class="easyui-datagrid" ctrlSelect="true" remoteSort="false" pagination="true" pageSize="40" fit="true" fitColumns="true" rowNumbers="true"
        url="<?=base_url() . $menu_link . "/ajax_for_choose_ri"?>" 
    >
        <thead>
            <tr>
                <th field="ck" checkbox="true"></th>
                <th field="PRecNumber" width="147" halign='center' align='center' sortable="true">RI. Number</th>
                <th field="PRecDate" width="90" halign='center' align='center' sortable="true">RI. Date</th>
                <th field="PRecDesc" width="300" halign="center" align="left">Description</th>
            </tr>
        </thead>
    </table>
</div>
<!-- Dialog Button -->

<div id="dialogpo-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_ri();">OK</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog_po');">Cancel</a>
</div>
<?php $this->load->view('v_custom_pop_up');?>
<script>

    $(document).ready(function(){

    	tax_status      = '<?=$detail->PInvTaxesStatus?>';
    	intax_status    = '<?=$detail->PInvInTaxStatus?>';
    	currency_code   = '<?=$detail->CurrencyCode?>';
    	currency_rate   = '<?=$detail->CurrencyRate?>';
    	fiscal_rate     = '<?=$detail->FiscalRate?>';  
    	
    	ppn10_pcnt      = '<?=$detail->PInvPPn10Pcnt?>'; 
    	pph22_pcnt      = '<?=$detail->PInvPPh22Pcnt?>'; 
    	pph23_pcnt      = '<?=$detail->PInvPPh23Pcnt?>'; 
    	total_purchase  = '<?=$detail->PInvTotalAmount?>';
    	total_dp        = '<?=$detail->PInvTotalDP?>'; 
    	total_invoice   = parseFloat(total_purchase) - parseFloat(total_dp);
    	sub_total 		= '<?=$detail->PInvSubTotal?>';
    	discount 		= '<?=$detail->PInvDiscount?>';
    	ppn10 			= '<?=$detail->PInvPPn10?>';
    	pph22 			= '<?=$detail->PInvPPh22?>';
    	pph23 			= '<?=$detail->PInvPPh23?>';
    	
    	freight 		= '<?=$detail->PInvEstFreight?>';
    		
    	if(tax_status == 1){
                $('.disableme').css('display','');                
                $('#chk_taxtable').prop('checked',true);

                if(intax_status == 1){
                    $('.disableme1').css('display','');                
                    $('#chk_inclusive').prop('checked',true);
                }
                else{
                    $('#chk_inclusive').prop('checked',false);
                    $('.disableme1').css('display','none');                
                }	
    	}
    	else{
                $('.disableme').css('display','');                
                $('#chk_taxtable').prop('checked',false);
                $('#chk_inclusive').prop('checked',false);
    	}

    	if(total_dp > 0){
    		$('.disableme2').css('display','');                
    		$('#chk_vendor_dp').prop('checked',true);
    	}
    	else{
    		$('.disableme2').css('display','None');                
    		$('#chk_vendor_dp').prop('checked',false);
    	}

    	if(currency_code != 'IDR'){
    		$('#row_currency_rate').show();
    		$('#row_fiscal_rate').show();

    		$('#txt_currency_rate').attr('readonly',true);
    		$('#txt_fiscal_rate').attr('readonly',false);
    	}
    	else{
    		$('#row_currency_rate').hide();
    		$('#row_fiscal_rate').hide();

    		$('#txt_currency_rate').attr('readonly',true);
    		$('#txt_fiscal_rate').attr('readonly',true);
    	}

    	if(total_dp > 0){
    		$('#chk_vendor_dp').prop('checked',true);
    	}
    	else{
    		$('#chk_vendor_dp').prop('checked',false);
    	}

    	$('#txt_currency_rate').numberbox('setValue', currency_rate);
    	$('#txt_fiscal_rate').numberbox('setValue', fiscal_rate);
    	$('#currency').text(currency_code + ' / IDR');
    	$('#fiscal').text(currency_code + ' / IDR');

    	$('#hdn_taxes_status').val(tax_status);
    	$('#hdn_intax_status').val(intax_status);
    	$('#hdn_currency_code').val(currency_code);
    	$('#hdn_ppn10_pcnt').val(ppn10_pcnt);
    	$('#hdn_pph22_pcnt').val(pph22_pcnt);
    	$('#hdn_pph23_pcnt').val(pph23_pcnt);

    	$('#lbl_ppn10').text('PPn (' + ppn10_pcnt + '%)');
    	$('#lbl_pph22').text('PPh22 (' + pph22_pcnt + '%)');
    	$('#lbl_pph23').text('PPh23 (' + pph23_pcnt + '%)');

    	//$('#cbo_fob').combobox('select','<?php echo $detail->FOBID ?>');
    	//$('#cbo_terms').combobox('select','<?php echo $detail->TermsPaymentID ?>');
    	//$('#cbo_ship_via').combobox('select','<?php echo $detail->ShipmentID ?>');
    	$('#txt_pinv_date').datebox('setValue', '<?= date("d-m-Y", strtotime($detail->PInvDate))?>');
    	$('#txt_prec_date').val('<?php echo $detail->PRecDate ?>');
    	$('#txt_shipment_date').datebox('setValue', '<?= date("d-m-Y", strtotime($detail->ShipmentDate))?>');

    	$('#txt_sub_total').numberbox('setValue', '<?=$detail->PInvSubTotal?>');
    	$('#txt_sub_total_hide').numberbox('setValue', '<?=$detail->PInvSubTotal?>');
    	
    	$('#txt_discount').numberbox('setValue', '<?=$detail->PInvDiscount?>');
    	$('#txt_discount_hide').numberbox('setValue', '<?=$detail->PInvDiscount?>');
    	
    	$('#txt_ppn10').numberbox('setValue', '<?=$detail->PInvPPn10?>');
    	$('#txt_ppn10_hide').numberbox('setValue', '<?=$detail->PInvPPn10?>');
    	
    	$('#txt_pph22').numberbox('setValue', '<?=$detail->PInvPPh22?>');
    	$('#txt_pph22_hide').numberbox('setValue', '<?=$detail->PInvPPh22?>');
    	
    	$('#txt_pph23').numberbox('setValue', '<?=$detail->PInvPPh23?>');
    	$('#txt_pph23_hide').numberbox('setValue', '<?=$detail->PInvPPh23?>');
    	
    	$('#txt_freight').numberbox('setValue', '<?=$detail->PInvEstFreight?>');
    	
    	$('#txt_total_purchase').numberbox('setValue', total_purchase);
    	$('#txt_total_purchase_hide').numberbox('setValue', total_purchase);
    	
    	$('#txt_total_dp').numberbox('setValue', total_dp);
    	
    	if(parseFloat(total_dp) > parseFloat(total_purchase)){
    		$('#txt_total_invoice').numberbox('setValue', total_invoice);
    		$('#txt_total_invoice_hide').numberbox('setValue', 0);
    	}
    	else{
    		$('#txt_total_invoice').numberbox('setValue', total_invoice);
    		$('#txt_total_invoice_hide').numberbox('setValue', total_invoice);
    	}

        $('#txt_freight').numberbox({
        onChange:function(){
                freight = $('#txt_freight').numberbox('getValue');

                if(isNaN(freight) || freight == ''){
                    $('#txt_freight').numberbox('setValue', 0);
                }
                
                calculate_total();
            }
        });
        datagrid_item_type("dtg_item");//untuk warna grid
    });

    function calculate_total(){
        subtotal    = parseFloat($('#txt_sub_total_hide').numberbox('getValue'));
        discount    = parseFloat($('#txt_discount_hide').numberbox('getValue'));
        ppn10       = parseFloat($('#txt_ppn10_hide').numberbox('getValue'));
        pph22       = parseFloat($('#txt_pph22_hide').numberbox('getValue'));
        pph23       = parseFloat($('#txt_pph23_hide').numberbox('getValue'));
        freight     = parseFloat($('#txt_freight').numberbox('getValue'));
        totaldp     = parseFloat($('#txt_total_dp').numberbox('getValue'));

        total_purchase  = subtotal + ppn10 + pph22 - pph23 + freight;
        total_invoice   = total_purchase - totaldp;

        $('#txt_total_purchase').numberbox('setValue', total_purchase);
		$('#txt_total_purchase_hide').numberbox('setValue', total_purchase);
		
        $('#txt_total_invoice').numberbox('setValue', total_invoice); 
		$('#txt_total_invoice_hide').numberbox('setValue', total_invoice);    
    }
	
    function set_ppn_value(){
	if($('#chk_taxtable').is(':checked')){            
            $('#hdn_taxes_status').val(1);

            if($('#chk_inclusive').is(':checked')){
                $('#hdn_intax_status').val(1);
            }
            else{
                $('#hdn_intax_status').val(0);
            }
	}
	else{
            $('#hdn_taxes_status').val(0);
            $('#hdn_intax_status').val(0);
	}
	
	calculate_ppn();
    }

    function calculate_ppn(){
        var item            = $('#dtg_item').datagrid('getRows');
        var ppn10_pcnt      = $('#hdn_ppn10_pcnt').val();

        total_amount        = 0;
        item_total_amount   = 0;

        $.each(item, function(index, value){
            item_ppn    = 0;
            item_amount = value.ItemAmount;
            item_disc   = value.ItemDiscount;

            if(itemamount > 0 || itemamount !== null){
        	if($('#chk_taxtable').is(':checked')){
                    item_ppn = parseFloat(item_amount) * (ppn10_pcnt / 100);
                }
                else{
                    item_ppn = 0;
                }
            }

            item_total_amount   = parseFloat(item_amount) + parseFloat(item_ppn);
                        
            $('#dtg_item').datagrid('updateRow',{
                index:index,
                row: {ItemTaxPPn10      : item_ppn,
                      ItemTotalAmount   : item_total_amount}
            });
        });

	$('#dtg_item').edatagrid('saveRow');
    }
	
	function approval_data($status){
		var url_check           = '<?= base_url();?>custom/custom/checking_approval';
		var no_transaksi    	= $('#txt_pinv_no').val();
		modal_open('Progress Bar','dlg_loading');
		
		$.post(url_check, {no_transaksi:no_transaksi}, function(result){
			if (result.status === false){
				approval($status);
			} 
			else{
				$.messager.alert('Unseccessfull',result.message,'error',function(){
					location.reload();
				});
			}
		},'json');
    }
	
    function approval($status){
		var url         = base_url + 'list/purchases_invoice/approval';
		var i           = $('#dtg_item').datagrid('getRows');
	
		Status          = $status;
		PRecNumber      = $('#txt_prec_no').val();
		PInvNumber      = $('#txt_pinv_no').val();
		PInvDate        = $('#txt_pinv_date').datebox('getValue');
		VendorCode      = $('#cbg_vendor').combogrid('getValue');
		PInvDesc        = $("#txa_description").val();
			
		CurrencyCode    = $('#hdn_currency_code').val();
		TaxesStatus     = $('#hdn_taxes_status').val();
		POrdNumber 		= $('#hdn_pord_no').val(); 
		
		TaxPPn10Pcnt    = parseFloat($('#hdn_ppn10_pcnt').val());
		TaxPPn10        = parseFloat($('#txt_ppn10_hide').numberbox('getValue'));
		TaxPPh22        = parseFloat($('#txt_pph22_hide').numberbox('getValue'));
		TaxPPh23        = parseFloat($('#txt_pph23_hide').numberbox('getValue'));
		        
		CurrencyRate    = parseFloat($('#txt_currency_rate').numberbox('getValue'));
		FiscalRate      = parseFloat($('#txt_fiscal_rate').numberbox('getValue'));
		SubTotal        = parseFloat($('#txt_sub_total_hide').numberbox('getValue'));
		SubTotal_Real   = parseFloat($('#txt_sub_total').numberbox('getValue'));
		
		TotalDiscount   = parseFloat($('#txt_discount_hide').numberbox('getValue'));
		TotalFreight    = parseFloat($('#txt_freight').numberbox('getValue'));
		TotalPurchase   = parseFloat($('#txt_total_purchase_hide').numberbox('getValue'));
		TotalDP         = parseFloat($('#txt_total_dp').numberbox('getValue'));
		TotalInvoice    = parseFloat($('#txt_total_invoice_hide').numberbox('getValue'));
		TotalInvoice_Hide    = parseFloat($('#txt_total_invoice_hide').numberbox('getValue'));
	
		Detail          = JSON.stringify(i);
	
		$.post(url, {Status:Status, PInvNumber:PInvNumber, PRecNumber:PRecNumber, PInvDate:PInvDate, PInvDesc:PInvDesc, 
						 VendorCode:VendorCode, CurrencyCode:CurrencyCode, CurrencyRate:CurrencyRate, FiscalRate:FiscalRate, 
						 TaxPPn10Pcnt:TaxPPn10Pcnt, TaxPPn10:TaxPPn10, SubTotal:SubTotal, TotalDiscount:TotalDiscount, TotalFreight:TotalFreight, 
						 TotalPurchase:TotalPurchase, TotalDP:TotalDP, TotalInvoice:TotalInvoice, Detail:Detail, POrdNumber:POrdNumber,TotalInvoice_Hide:TotalInvoice_Hide, TaxPPh22:TaxPPh22, TaxPPh23:TaxPPh23, SubTotal_Real:SubTotal_Real}, function(result){
				if (result.status == true){
					$.messager.alert('Success',result.message,'info',function(){
						location.reload();						                    
					});	
					modal_close('dlg_loading');			
				} 
				else {
					$.messager.alert('Error',result.message,'error',function(){
						location.reload();						                    
					});				
				}
		},'json');
    }

    function update_data(){    	
		var url             = '<?= base_url();?>custom/custom/checking_update';
		var no_transaksi    = $('#txt_pinv_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');?>';
		
		var item    		= $('#dtg_item').datagrid('getRows');
		var detail  		= JSON.stringify(item);
		
		sub_total 	= $('#txt_sub_total').numberbox('getValue');
		freight 	= $('#txt_freight').numberbox('getValue');
		txt_pph23 	= $('#txt_pph23').numberbox('getValue');
		flag 		= true;
		
		if(freight < 0){
			if(Math.abs(freight) > sub_total){
				if(txt_pph23 > 0){
					if(Math.abs(freight) > parseFloat(sub_total - txt_pph23)){
						$.messager.alert('Maaf', 'PPh 23 Aktif, Total Freight tidak boleh melebihi (Sub total - PPh23), silahkan lihat kembali transaksi anda');
					}
				}
				else{
					$.messager.alert('Maaf', 'Total Freight tidak boleh melebihi sub total, silahkan lihat kembali transaksi anda');
				}
			}
			else{
				if(txt_pph23 > 0){
					if(Math.abs(freight) > parseFloat(sub_total - txt_pph23)){
						$.messager.alert('Maaf', 'PPh 23 Aktif, Total Freight tidak boleh melebihi (Sub total - PPh23), silahkan lihat kembali transaksi anda');
					}
					else{
						$("#detail").val(detail);		
						edit_transaction_check('<?=$menu_link?>','#fm_purchase_invoice', no_transaksi, url, trans_status,created_by, login_as, job_title);
					}
				}
				else{
					$("#detail").val(detail);	
					edit_transaction_check('<?=$menu_link?>','#fm_purchase_invoice', no_transaksi, url, trans_status,created_by, login_as, job_title);
				}
			}
		}
		else{	
			$("#detail").val(detail);		
			edit_transaction_check('<?=$menu_link?>','#fm_purchase_invoice', no_transaksi, url, trans_status,created_by, login_as, job_title);
		}
    }   

    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_pinv_no').val(), 'Purchase Invoices', url, created_by, login_as, job_title);
	}

    function to_transaction(){

        var appfinished     = '<?=$detail->TransStatus;?>';
        var no_transaksi    = $('#txt_pinv_no').val();
        var arr_number      = no_transaksi.split('/');
        var branch          = arr_number[0];
        var currency_code   = $('#hdn_currency_code').val();
        var vendor_code     = $('#cbg_vendor').combogrid('getValue');
        var no_trans        = no_transaksi.replace(/\//g,"__");
        var vendor_code     = vendor_code.replace(/\//g,"__");

        if(appfinished == 1){
           parent.tab_add('New Purchase Payment','list/purchases_payment','icon-add','add/'+no_trans+'/'+branch+'/'+vendor_code+'/'+currency_code);
        }else{
            $.messager.alert('Unseccessfull','TransStatus Finished. Transaksi selesai.','error',function(){
                //location.reload();
            });
        }
    }
	
	function app_reverse(){
		var no_transaksi    = $('#txt_pinv_no').val();
	
		checking_reverse(no_transaksi,function(check){
			
			if(check.status == true){
				var i       = $('#dtg_item').datagrid('getRows');
				var detail  = JSON.stringify(i);
		
				$("#detail").val(detail);
				reverse_data_by_detail('<?php echo $menu_link?>','#fm_purchase_invoice');
			}else{
			   $.messager.alert('Unseccessfull',check.message,'error',function(){
					location.reload();
				});
			}
		});
	}
</script>