<!---- 
    Author 	: Ladur
    Tanggal : 12-08-2014	
    Revisi 	:
-->

<?php 

//---------Untuk privellege jika dia ada tombol save,suspen,jurnal----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "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";
	}
	
	if($group_user->DeletePrivillage == 1){
		$cek_autority_delete  = "";
	}
	else{
		$cek_autority_delete 	= "disabled";
	}
//-------------end----------------------------

if( $detail->SInvTaxesStatus == 1 || $detail->SInvDPStatus == 1){
	$checked_chk_tax        = 'checked';	
	$style_chk_tax          = 'opacity:0.6;';
	$checked_chk_dp        = 'checked';
	
	if( $detail->SInvInTaxStatus == 1){
		$checked_chk_inclusive = 'checked';	
		$style_chk_inclusive	= '';
	}
	else{
		$checked_chk_inclusive = '';
		$style_chk_inclusive	= 'opacity:0.6;';
	}
}
else{
	$checked_chk_tax 		= '';
	$checked_chk_dp        	= '';
	$checked_chk_inclusive	= '';
	$style_chk_tax 			= 'display:none';
	$style_chk_dp 			= 'display:none';	
	$style_chk_inclusive	= 'display:none';
}
?>

<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->SInvNumber?>');" <?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>
                    <a href="#" class="easyui-linkbutton" iconCls="icon-currency" plain="true" onclick="to_transaction();" <?=in_array($detail->TransStatus,array(1))?'':'disabled';?>>To Sales Receipt</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';
					}
				}
				else if($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" style="padding:5px;" fit="true">
        	<?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_sales_invoice" name="fm_sales_invoice" method="post">
                <input type="hidden" name="hdn_sinv_no" id="hdn_sinv_no" value="<?=$detail->SInvNumber?>"/>
                <input type="hidden" name="detail" id="detail" />	
                <input type="hidden" name="txt_hide_branch" id="txt_hide_branch" value="<?=$detail->BranchCode?>"/>
                <input type="hidden" name="txt_pcnt" id="txt_pcnt" value="<?=$detail->SInvPPNPcnt?>"/>
                <input type="hidden" name="txt_old_pinv" id="txt_old_pinv" value="<?=$detail->OldSInvNumber?>"/>
                
                <!-- Form Header -->
                <table width="100%" height="140" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1">
                        <tr height="26">
                            <td width="135"><b>Customer</b></td>
                            <td width="10"><b>:</b></td>
                            <td colspan="5">
                                <select class="easyui-combogrid" id="cmb_customer" 
                                	name="cmb_customer" required="required" 
                                	style="width:160px;height:20px;" readonly 
                                    data-options=" 
                                        value:'<?=$detail->CustomerCode?>',
                                        panelWidth: 300,
                                        idField: 'CustomerCode',
                                        textField: 'CustomerName',
                                        url: '<?=base_url()?>custom/get_data/customer_with_rate',
                                        method: 'get',
                                        fitColumns: true,
                                        columns: [[
                                            {field:'CustomerCode',title:'Customer Code',width:110},
                                            {field:'CustomerName',title:'Customer Name',width:190}
                                        ]],
                                    ">
                                </select>
								
                                <?php if($detail->SInvTaxesStatus==1){ ?>
                                <span style="width:175px;margin-left:5px;color:gray;">
                                    <input type="checkbox" name="chk_taxtable" id="chk_taxtable" value="1" onclick="return false;" <?=$checked_chk_tax?> style="opacity:0.5;" /> Taxable 
                                    <span><input type="checkbox" name="chk_inclusive" id="chk_inclusive" value="1" onClick="return false;" <?=$checked_chk_inclusive?> style="opacity:0.5;" /> Inclusive Tax</span>
                                </span>
                                <?php } ?>
                            </td>
                        </tr>
                        <tr id="rowRate">
                        	<td><b>Currency Code/Rate</b></td>
                            <td><b>:</b></td>
                            <td colspan="5">
                            	<input type="text" name="txt_currency_code" id="txt_currency_code" value="<?=$detail->CurrencyCode?>" style="width:55px" required readonly /> / 
                                <input type="numberbox" id="txt_rate" name="txt_rate" class="easyui-numberbox" value="<?=$detail->CurrencyRate?>" style="width:90px;text-align:right;" required readonly
                                	data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                />
                            	<span id="currency_code"></span>
                            </td>
                        </tr>
                        <tr id="rowRate">
                        	<td><b>Fiscal Rate</b></td>
                            <td><b>:</b></td>
                            <td colspan="5">
                            	 <input type="text" name="txt_currency_code_fiscal" id="txt_currency_code_fiscal" value="<?=$detail->CurrencyCode?>" style="width:55px" required readonly /> /
                            	 <input type="test" name="txt_fiscal_rate" id="txt_fiscal_rate" class="easyui-numberbox" style="width:90px;text-align:right;" required <?=($detail->TransStatus==4)?'':'readonly'?>
                            		data-options="min:1,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                    value="<?=$detail->FiscalRate?>" 
                                    <?=($detail->CurrencyCode=='IDR' or $detail->SInvTaxesStatus==0)?'readonly':''?>
                                />
                            </td>
                        </tr>
                        <tr height="20">
                            <td><b>Billing Address</b></td>
                            <td width="10"><b>:</b></td>
                            <td>&nbsp;</td>
                            <td width="120"><b>Shipping Address</b></td>
                            <td width="10"><b>:</b></td>
                            <td>&nbsp;</td>
                            <td width="114" rowspan="2">&nbsp;</td>
                        </tr>
                        <tr height="20">
                            <td colspan="3">
                                <textarea name="txa_address" id="txa_address" rows="4" style="width:225px;resize:none;" readonly><?=$detail->BillingAddress?></textarea>
                            </td>
                            <td colspan="3">
                                <textarea name="txa_ship_to" id="txa_ship_to" rows="4" style="width:225px;resize:none;" readonly><?=$detail->ShippingAddress?></textarea>
                            </td>
                        </tr>
                        </table>
                    </td>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1" style="margin-top:4px;">
                        <tr height="20">
                            <td valign="top" style="color:gray;">
                             <?php if($detail->SInvDPStatus==1){ ?>
                            	<input type="checkbox" id="chk_payment_dp" name="chk_payment_dp" value="1"  disabled <?=$checked_chk_tax?>/> Cust. Payment DP</td>
                             <?php } ?>
                            <td width="190" style="background:#333399;text-align:center;color:#FFF;">SInv. No.</td>
                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">SInv. Date</td>
                            <td width="122" style="background:#333399;text-align:center;color:#FFF;">FOB</td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td height="20" width="100" align="center" valign="middle">
                            	<input type="text" name="txt_si_no" id="txt_si_no" class="easyui-validatebox textbox" value="<?=$detail->SInvNumber?>" style="width:190px;height:18px;text-align:center;" required readonly />
                            </td>
                            <td width="100" align="center" valign="middle">
                                <input name="txt_si_date" id="txt_si_date" type="text" class="easyui-datebox validBackward" style="width:122px;height:20px;" required readonly editable="false" />
                            </td>
                            <td>
                                <select name="cmb_fob" id="cmb_fob" 
                                    class="easyui-combobox" style="width:122px;height:20px;" 
                                    readonly
                                >
									<?php 
									if($detail->FOB == 0) {
										$FOBName = "Shiping Point";
									}
									else {
										$FOBName = "Destination";
									}
                                    ?>
                                    <option value="<?php echo $detail->FOB; ?>"><?php echo $FOBName; ?></option>
                                </select>
                            </td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">DOrd. No.</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">Ship Date</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">Terms</td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td><input type="text" name="txt_do_no" id="txt_do_no" class="easyui-validatebox textbox" value="<?=$detail->DOrdNumber?>" style="width:190px;height:18px;text-align:center;" required readonly /></td>
                            <td><input name="txt_ship_date" id="txt_ship_date" type="text" class="easyui-datebox validBackward" style="width:122px;height:20px;" required readonly /></td>
                            <td>
                            	<select name="cmb_terms" id="cmb_terms" 
                                    class="easyui-combobox" editable="false" 
                                    data-options="
                                    	value:'<?=$detail->TermsPaymentID?>', 
                                        valueField:'TermspaymentID',
                                        textField:'TermDesc',
                                        url:'<?=base_url()?>custom/get_data/termspayment'
                                    " style="width:122px;height:20px;" 
                                    required readonly
                                >
                                </select>
                            </td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td style="background:#333399;text-align:center;color:#FFF;">Cust. PO. No.</td>
                            
                            <td style="background:#333399;text-align:center;color:#FFF;">Ship Via</td>
                        </tr>
                        <tr height="20">
                        	<td>&nbsp;</td>
                            <td><input type="text" name="txt_po_no" id="txt_po_no" class="easyui-validatebox textbox" style="width:190px;height:18px;text-align:center;" value="<?php echo $detail->CustPONumber; ?>" required readonly /></td>
                           
                            <td>
                            	<select name="cmb_ship_via" id="cmb_ship_via" 
                                    class="easyui-combobox" editable="false" 
                                    data-options="
                                    	value:'<?=$detail->ShipmentID?>', 
                                        valueField:'ShipmentID',
                                        textField:'ShipmentName',
                                        url:'<?php echo base_url(); ?>custom/get_data/shipment'
                                    " 
                                    style="width:122px;height:20px;" 
                                    required readonly 
                                >
                                </select>
                            </td>
                        </tr>
                        </table>
                    </td>
                </tr>
                </table>

                <!-- End of form header -->
                <div class="easyui-tabs" data-options="tabHeight:18" style="margin:5px 0px;">
                    <div id="tab_item" title="Items">
                        <table id="dg_item" class="easyui-datagrid" 
                        	url="<?php echo base_url().$menu_link."/ajax_detail/".$detail->SInvNumber; ?>"
							toolbar="#toolbar" idField="id"
							rownumbers="true" fitColumns="true" 
                            singleSelect="true" style="height:250px;"
                        >
							<thead>
                            <tr>
                                <th data-options="field:'SInvDetailID',width:20,halign:'center',align:'left'" hidden>ID</th>
                                <th data-options="field:'ItemCategoryID',width:20,halign:'center',align:'left'" hidden>Item Category ID</th>
                                <th data-options="field:'ItemCode',width:120,halign:'center',align:'left'">Item Code</th>
                                <th data-options="field:'ItemDesc',width:150,halign:'center',align:'left'">Description</th>
                                <th data-options="field:'ItemQty',width:30,halign:'center',align:'center'" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:0.01,required:true}}" formatter="formatRp">Qty</th>
                                <th data-options="field:'ItemUnit',width:30,halign:'center',align:'center'">Unit</th>
                                <th data-options="field:'ItemPrice',width:110,halign:'center',align:'right'" formatter="formatRp">Item Price</th>
                                <th data-options="field:'ItemDiscPcnt',width:50,halign:'center',align:'right'" formatter="formatRp">Item Disc %</th>
                                <th data-options="field:'ItemAmount',width:110,halign:'center',align:'right'" formatter="formatRp">Total Amount</th>
                            
                            	<th data-options="field:'ItemTax',width:110,halign:'center',align:'right'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                
                                }}" hidden>Item Tax</th>
                                <th data-options="field:'ItemCategoryCode',width:20,halign:'center',align:'left'" hidden>Item Category Code</th>
                                <th data-options="field:'ItemAmountKoma',width:110,halign:'center',align:'right'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                
                                }}" hidden>Total Amount Koma</th>
                                <th data-options="field:'ItemTaxtKoma',width:110,halign:'center',align:'right'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                
                                }}" hidden>Total Tax Koma</th>
                                <th data-options="field:'AmountDisc',width:120,halign:'center',align:'center'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                	return v;
                                },
                                parser:function(s){
                                	var v = parseFloat(s);
                                    return v;
                                }
                                }}" hidden>Amount Disc</th>
                                <th data-options="field:'ItemType',width:110,halign:'center',align:'right'" hidden>Item Type</th>
                                <th data-options="field:'ItemStatus',width:110,halign:'center',align:'right'" hidden>Item Status</th>

                                <th data-options="field:'ItemPph23',width:110,halign:'center',align:'right'" editor="{type:'numberbox',options:{decimalSeparator:',',groupSeparator:'.',min:0,required:true,readonly:true,
                                formatter:function(v){
                                    return v;
                                },
                                parser:function(s){
                                    var v = parseFloat(s);
                                    return v;
                                }
                                
                                }}" hidden>PPH 23</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;" <?=($detail->TransStatus==4)?'':'readonly'?>><?=$detail->SInvDesc?></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td><span class="dp" style="display:none" ><b>Downpayment</b></span></td>
                            <td><span class="dp" style="display:none" ><b>:</b></span></td>
                            <td>
                                <span class="dp" style="display:none" >
                                    <input type="numberbox" min="0" name="txt_downpayment" id="txt_downpayment" value="0" class="easyui-numberbox dp" 
                                    	data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" style="text-align:right;" 
                                    	readonly
                                    />
                                </span>
                            </td>
                        </tr>
                        </table>
                    </td>
                    <td width="50%" valign="top">
                        <table width="100%" cellpadding="0" cellspacing="1">
                        <tr>
                            <td rowspan="6">&nbsp;</td>
                            <td width="120"><b>Sub Total</b></td>
                            <td width="10"><b>:</b></td>
                            <td width="171">
                                <input type="numberbox" id="txt_sub_total" name="txt_sub_total" value="<?=$detail->SInvSubTotal?>" class="easyui-numberbox" style="text-align:right;" readonly
                                	data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                />
                                
                                <input type="hidden" id="txt_sub_total_hide" name="txt_sub_total_hide" value="<?=$detail->SInvSubTotal?>" 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>
                                <input type="numberbox" name="txt_discount" id="txt_discount" class="easyui-numberbox currency" value="<?=$detail->SInvDiscount?>" style="text-align:right" 
                                	data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" onChange="calculate()" readonly
                                    <?=($detail->TransStatus==4)?'':'readonly'?> 
                                />
                                
                                <input type="hidden" id="txt_discount_hide" name="txt_discount_hide" value="<?=$detail->SInvDiscount?>" 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>
                        <?php 
							if($detail->SInvTaxesStatus == 0)
								$tax_ppn = 0;
							else
								$tax_ppn = $detail->SInvPPNOut;
						?>
                        <tr height="22">
                            <td><?=($detail->SInvPPNOut==0)?'<b>PPN (0%)</b>':'<b>PPN ('. $detail->SInvPPNPcnt .'%)</b>'?></td>
                            <td><?=($detail->SInvPPNOut==0)?'<b>:</b>':'<b>:</b>'?></td>
                            <td>
                                <?php if($detail->SInvPPNOut>0){ ?>
                                    <input type="numberbox" name="txt_ppn" id="txt_ppn" value="<?=$detail->SInvPPNOut?>" 
                                    	class="easyui-numberbox" style="text-align:right" readonly 
                                    	data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                    />
                                    
                                    <input type="numberbox" id="txt_ppn_hide" name="txt_ppn_hide" value="<?=$detail->SInvPPNOut?>" 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;
                                        }
                                        " hidden
                                    />
                                <?php }else{ ?>
									<input type="numberbox" name="txt_ppn" id="txt_ppn" value="0" 
                                    	class="easyui-numberbox" style="text-align:right" readonly 
                                    	data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                    />
                                    
                                    <input type="numberbox" id="txt_ppn_hide" name="txt_ppn_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;
                                        }
                                        " hidden
                                    />
								<?php }?>
                            </td>
                        </tr>
                        <!--
                        <tr>
                            <td><b>PPh 22</b></td>
                            <td><b>:</b></td>
                            <td align="right">
                                <input type="numberbox" name="txt_pph22" id="txt_pph22" class="easyui-numberbox" value="<?=$detail->SInvPPH22?>" style="text-align:right;" readonly
                                    data-options="prefix:'Rp. ',min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                />
                            </td>
                        </tr>
                         -->
                        <tr height="22">
                            <td><b>PPh 23 (<?php echo $detail->SOrdPPh23Pcnt;?>% )</b></td>
                            <td><b>:</b></td>
                            <td >
                                <input type="numberbox" name="pph_value" id="pph_value" value="<?=$detail->SInvPPH23?>" class="easyui-numberbox" style="text-align:right" readonly
                               		data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                />
                            </td>
                        </tr>
                       
                       <input type="numberbox" name="txt_freight" id="txt_freight" class="easyui-numberbox" value="<?=$detail->SInvEstFreight?>" style="text-align:right;" 
                                    data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                    <?=($detail->TransStatus==4)?'':'readonly'?> 
                                hidden/>
                        <!-- <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="<?=$detail->SInvEstFreight?>" style="text-align:right;" 
                                	data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                    <?=($detail->TransStatus==4)?'':'readonly'?> 
                                />
                            </td>
                    	</tr> -->
                       
                        <tr>
                            <td><b>Total Invoice</b></td>
                            <td><b>:</b></td>
                            <td>
                                <input type="numberbox" name="txt_total_amount" id="txt_total_amount" value="<?=$detail->SInvTotalAmount?>" class="easyui-numberbox" style="text-align:right" readonly
                                	data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" 
                                />
                                
                                <input type="numberbox" id="txt_total_amount_hide" name="txt_total_amount_hide" value="<?=$detail->SInvTotalAmount?>" 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;
                                    }
                                    " hidden
                                />
                            </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>&nbsp;</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_si();"  <?= (($this->session->userdata("jobtitle_status") != 1 || !in_array($detail->TransStatus, array(4,6))) || (date('Y-m-d') < date('Y-m-d', strtotime($detail->SInvDate))))?'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)" id="save_button" class="easyui-linkbutton form-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="link_print('<?php echo $menu_link ?>/to_print_detail/<?php echo $detail->SInvNumber ?>');">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->SInvNumber?>');" <?=(in_array($detail->TransStatus,array(1,3,9,2,4,5,6)))?'':'disabled'?>>Preview & Print</a>  
                <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="parent.tab_close('tt')">Close</a>
            </td>
        </tr>
        </table>
    </div>
</div>
<?php $this->load->view('v_custom_pop_up');?>
<script type="text/javascript">
$(document).ready(function(){	
	$('#cmb_terms').combobox('select','<?=$detail->TermsPaymentID?>');
	$('#cmb_ship_via').combobox('select','<?=$detail->ShipmentID?>');
	$('#txt_si_date').datebox('setValue','<?=convert_to_dmy($detail->SInvDate)?>');
	$('#txt_ship_date').datebox('setValue','<?=convert_to_dmy($detail->ShipDate)?>');
	
	$('#dg_item').datagrid({
		onLoadSuccess:function(){
			dtg_item = $('#dg_item').datagrid('getRows');
			AmountDisc 		= 0;
			
			$.each(dtg_item,function(index,value){
				AmountDisc 		= (parseFloat(value.ItemQty * value.ItemPrice) * (parseFloat(value.ItemDiscPcnt / 100)));
				
				$('#dg_item').datagrid('updateRow',{
					index: index, 
					row:{
						AmountDisc: AmountDisc
					}
				});
				
			});
		}
	});
	
	$('#txt_freight').numberbox({
        onChange:function(){
                freight = $('#txt_freight').numberbox('getValue');

                if(isNaN(freight) || freight == ''){
                    $('#txt_freight').numberbox('setValue', 0);
                }
                
                calculate_total();
            }
     });

    $('#txt_do_no').on('mouseover',function(){
        $(this).css({'color':'blue','font-weight':'bold','cursor':'pointer'});
    }).on('mouseout',function(){
        $(this).css({'color':'#545454','font-weight':'normal'});
    }).on('click',function(){
        var TransNumber = $(this).val();
        parent.tab_edit('Edit Delivery Order','list/delivery_order', 'icon-edit', 'edit',TransNumber) ;
    });
	
	datagrid_item_type_status("dg_item");//untuk warna grid  
});

function calculate_total(){
	subtotal    = parseFloat($('#txt_sub_total_hide').numberbox('getValue'));
	ppn10       = parseFloat($('#txt_ppn_hide').numberbox('getValue'));
	freight     = parseFloat($('#txt_freight').numberbox('getValue'));

	total_purchase  = subtotal + ppn10 + freight;

	$('#txt_total_amount').numberbox('setValue', total_purchase);
	$('#txt_total_amount_hide').numberbox('setValue', total_purchase);
}

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

function approval_si(status) {
	var url_check           = '<?= base_url();?>custom/custom/checking_approval';
	var no_transaksi    	= $('#txt_si_no').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_item').datagrid('getRows');
	var detail 	= JSON.stringify(item);
	$("#detail").val(detail);
	
	proses_custom_data('<?=$menu_link?>/approval_mgr','#fm_sales_invoice');
}

function app_reverse(){
	var no_transaksi    = $('#txt_si_no').val();

	checking_reverse(no_transaksi,function(check){
		
		if(check.status == true){
			var i       = $('#dg_item').datagrid('getRows');
			var detail  = JSON.stringify(i);
	
			$("#detail").val(detail);
			reverse_data_by_detail('<?php echo $menu_link?>','#fm_sales_invoice');
		}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?>', $('#hdn_sinv_no').val(), 'Sales Invoice', url, created_by, login_as, job_title);
}

//function hide_tax(){
//	if($('#chk_taxtable').is(':checked')){
//		$('.hide_inclusive').css('display','');
//	}else{
//		$('.hide_inclusive').css('display','none');
//		$('#ppn_value').numberbox('setValue',0);
//	}
//	calculate();
//}

function to_transaction(){
    var appfinished         = '<?=$detail->TransStatus;?>';
    var no_transaksi        = $('#txt_si_no').val();
    var customer_code       = $('#cmb_customer').combogrid('getValue');
    var CurrencyCode        = $('#txt_currency_code').val();
    var no_trans            = no_transaksi.replace(/\//g,"__");
    var customer_code       = customer_code.replace(/\//g,"__");

    if(appfinished == 1){
        parent.tab_add('New Sales Receipt','list/sales_receipt','icon-add','add/'+no_trans+'/'+customer_code+'/'+CurrencyCode);
    }else{
        $.messager.alert('Unseccessfull','TransStatus Finished. Transaksi selesai.','error',function(){
            //location.reload();
        });
    }
    
}
</script>