
<!---- 
    Author 	: Fachri
    Tanggal : 08-06-2016	
    Revisi 	:
-->
<?php
//---------Untuk privellege jika dia ada tombol save----------
	if($group_user->SavePrivillage == 1){
		$cek_autority_save  = "";
	}
	else{
		$cek_autority_save 	= "disabled";
	}
//-------------end----------------------------
?>
<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 cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
					<tr>
						<td align="left" valign="middle">
							<a href="#" class="easyui-linkbutton" iconCls="icon-document" plain="true" onclick="location.reload()">New</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="location.reload()">Refresh</a>
							<!-- <a href="#" class="easyui-linkbutton" iconCls="icon-journal" plain="true" onclick="" disabled>Journal</a> -->
						</td>							
						<td height="25" align="right" valign="middle">								
							<span class="form-title">
								<?= $menu_label; ?>
							</span>
						</td>
					</tr>
				</table>		     	
		 </div>			
	</div>
	<!-- end top view -->	
	<!-- center view -->
	<div id="form-body" data-options="region:'center',border:false">
		<div id="form-wrapper" class="easyui-panel"  style="width:1180px;height:526px;padding:5px;" fit='true'>
			<form id="fm_purchase_dp" name="fm_purchase_dp" method="post">
                <table cellpadding="0" cellspacing="3" width="100%" height="100%" border="0">
					<tr height="20">
                            <td width="120"><b>Branch Name</b></td>
                            <td width="10"><b>:</b></td>
                            
                            <td>
                                <select class="combo-grid" name="cbg_branch" id="cbg_branch" style="width:252px;height:22px;" required <?=(($this->session->userdata("branch_status")==1)?"disabled":'') ?> editable="true" required
                                    data-options="
                                        panelWidth:400,
                                        value:'<?= $this->session->userdata("branch") ?>',
                                        idField: 'BranchCode',
                                        textField: 'BranchName',
                                        url: '<?=base_url()?>custom/get_data/branch_no_filter',
                                        method: 'get',
                                        columns: [[
                                            {field:'BranchCode',title:'Branch No',width:100,halign:'center'},
                                            {field:'BranchName',title:'Branch Name',width:161,halign:'center'}
                                        ]],
                                        fitColumns: true
                                    ">
                                </select>
                            </td>
                            
                            <td align="left" valign="middle">&nbsp;</td>
						<td rowspan="6" align="left" valign="top">
							<table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
								<tr>
									<td align="right" valign="top">
										<table cellpadding="0" cellspacing="1" width="100%" border="0">
											<tr>
												<td height="20">&nbsp;</td>
												<td width="122" align="center" valign="middle" bgcolor="#333399"><span style="color:#fff;">Purchase Dp Date</span></td>
											</tr>
											<tr>
												<td>&nbsp;</td>
												<td align="right" valign="top"><input name="txt_payment_date" id="txt_payment_date" type="text" class="easyui-datebox validBackward" style="width:122px;height:20px" required editable="false" value='<?= $pdpay_date;?>'/></td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
                        </tr>
                    <tr>
						<td width="143"><b>Vendor</b></td>
                        <td width="10"><b>:</b></td>
                        <td colspan="5">
                            <select class="easyui-combogrid" name="cbg_vendor" id="cbg_vendor" style="width:252px;height:22px;" required 
                                data-options="
                                    panelWidth:400,
                                    idField: 'VendorCode',
                                    textField: 'VendorName',
                                    url: '<?=base_url()?>custom/get_data/vendor_new_by_branch',
                                    method: 'get',
                                    columns: [[
                                        {field:'VendorCode',title:'Vendor No',width:100,halign:'center'},
                                        {field:'VendorName',title:'Vendor Name',width:161}
                                    ]],
                                    fitColumns: true
                                ">
                            </select>
                            <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-sales'" onClick="select_sales();">Select DP.</a>
                        </td>
					</tr>
                    <tr>
						<td width="143"><b>No Trans From.</b></td>
                        <td width="10"><b>:</b></td>
                        <td colspan="5">
                            <input type="text" name="txt_trans_dp_no" id="txt_trans_dp_no" class="easyui-validatebox" style="width:250px;background-color:#E3E2E2;text-align:left;" required readonly /> 
                        </td>
					</tr>					
					<tr>
						<td valign="top" height="51" align="left" style="padding-top:4px;"><b>Description</b></td>
                        <td valign="top" style="padding-top:4px;"><b>:</b></td>
						<td valign="top" align="left">
							<textarea class="textbox" name="txa_memo" id="txa_memo" rows="4" style="width:362px;resize:none;white-space:normal;"></textarea>
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<tr>
						<td height="22" valign="top" align="left"><b>Down Payment Owing</b></td>
                        <td width="10"><b>:</b></td>
						<td valign="top" height="22" align="left">
							<input name="owing_amount"  	 id="owing_amount" type="text" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',disabled:true" autoComplete="off" style="width:185px;" value="0" required="required" />
							~ <input name="txt_equal_invoice"  	 id="txt_equal_invoice" type="text" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',disabled:true" autoComplete="off" style="width:162px;" value="0" required="required" />
                            <input name="txt_amount" 		  id="txt_amount" type="hidden" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',disabled:true" autoComplete="off" style="width:362px;" />
							<input name="owing_amount_hidden" id="owing_amount_hidden" type="hidden" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',disabled:true" autoComplete="off" style="width:362px;" />
							<input type="hidden" 			  id="detail" name="detail" />
							<input type="hidden" 			  id="dp_rate" name="dp_rate" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',disabled:true"/>
                            <input type="hidden" 			  id="txt_dp_number" name="txt_dp_number" />
                            <input type="hidden" 			  id="txt_currency_code" name="txt_currency_code" />
                            <input type="hidden" 			  id="txt_status_vendor" name="txt_status_vendor" />
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
					<tr>
						<td valign="top" height="22" align="left">
							<input name="txt_rate" id="txt_rate" type="hidden" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" autoComplete="off" style="width:200px;" required="required" />
						</td>
						<td valign="top" align="left">&nbsp;</td>
					</tr>
                    <tr height="20" style="display:none">
                        <td width="150" align="left"><b>Bank Balance (<span class='bank_balance_currency'></span>)</b></td>
                        <td width="10"><b>:</b></td>
                        <td >
                            <input name="txt_bank_balance" id="txt_bank_balance" type="text" class="easyui-numberbox" data-options="precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" style="text-align:right;width:362px" readonly />
                        </td>
                    </tr>					
				</table>
                
                <!-- Item Grid -->
                <div class="easyui-tabs" data-options="tabHeight:18" style="margin:5px 0px;">
                    <div title="Account">
                        <table toolbar="#tb_dtg_sales_journal" id="dtg_list_invoice" 
                        idField="id" rownumbers="true" fitColumns="true" singleSelect="true" style="height:290px;"
                        
                        >
                            <thead>
                                <tr>
                                	<th field="AccountName" 	halign="center"	align="left" valign="middle"	data-options="width:900,align:'left'" 	editor="{type:'AccountName',options:{required:true}}">Account Name</th>
                                    <th field="CurrencyCode"	halign='center'	align="left" valign="middle"	data-options="width:300,align:'left'"  	editor="{type:'text',options:{required:true}}"><?php echo label_grid('curr_code');?></th>
                                    <th field="Amount" 			halign="center" align="left" valign="middle"	data-options="width:470,align:'left'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true}}" formatter="formatRp">Amount</th>
                                    <th field="Rate" 			halign="center" align="left" valign="middle"	data-options="width:470,align:'left'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:','}}" formatter="formatRp"><?php echo label_grid('rate');?></th>
                                    <th field="PrimeAmount" 	halign="center" align="left" valign="middle"	data-options="width:510,align:'left'" 	editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',required:true}}" formatter="formatRp">Equal(~)</th>
                                    <th field="Memo"			halign='center'	align="left" valign="middle"	data-options="width:700,align:'left'"  	editor="{type:'text'}">Memo</th>
                                    <th field="AccountNumber" 	halign="center"	align="left" valign="middle"	data-options="width:900,align:'left'" 	editor="{type:'text',options:{required:true}}" hidden>Account Number</th>
                                	<th field="SubtypeName" 	halign="center"	align="left" valign="middle"	data-options="width:900,align:'left'" 	editor="{type:'text',options:{required:true}}" hidden>SubtypeName</th>
                                    <th field="TypeName" 		halign="center"	align="left" valign="middle"	data-options="width:900,align:'left'" 	editor="{type:'text',options:{required:true}}" hidden>TypeName</th>
                                </tr>
                            </thead>
                        </table>
                        
                        <div id="tb_dtg_sales_journal">
                            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_row()">New</a>	
                            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row()">Delete</a>							
                        </div>
                    </div>
                </div>
                <!-- End of item grid -->
            </form>
		</div>
	</div>
    <div id="form-footer" data-options="region:'south',border:false">
        <table cellpadding="0" cellspacing="0" width="100%" height="100%" border="0">
             <tr>
               <td align="left">
               </td>
                <td align="right">                              
                      <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-help" onclick="" plain="true">Help</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button save-button" iconCls="icon-save" onclick="save_me()" <?= $cek_autority_save;?>>Save</a>
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="parent.tab_close('tt')">Cancel</a>
                </td>
             </tr>
        </table>				
    </div>	
</div>
<!----------------------------------------------Batas Awal Dialog Sales Invoice-------------------------------------------------->
<div id="dialog-si" class="easyui-dialog" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-buttons" style="width:860px;height:532px;top:27px;background-color:#F8F8F8;padding:5px;"> 
        <div id="tab_purchase_req" class="easyui-tabs" style="width:835px;height:485px; background-color:#F8F8F8;" data-options="fit:true,plain:true">
            <div title="Down Payment" style="padding:10px" >
            
             <table id="tt_choose" class="easyui-datagrid" 
                url="<?php echo base_url() ?>list/purchase_dp/dp_filter" 
                remoteSort="false"
                pageSize="150"
                fitColumns="true" 
                rowNumbers="true"
                singleSelect="true"
                style="width:812px;height:400px" 
                data-options = "border:true,view:scrollview,autoRowheight:false"
            >                      
                <thead>
                    <tr>
                        <th field="POrdNumber" 		width="200" sortable="true">Trans. Number</th>
                        <th field="SaldoDPBalance" 	width="180" editor="{type:'numberbox',options:{precision:2,decimalSeparator:','}}" formatter="formatRp" sortable="true">DP Balance</th>
                    	<th field="SInvDesc" 		width="306">Description</th>
                    </tr>
                </thead>
            </table>
            <!-- Dialog Button for Dialog Item-->
            <div style="border:none; margin-top:10px; float:right;">
                 <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_item_si();">&nbsp; OK &nbsp; &nbsp;</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="modal_close('dialog-si');">Cancel</a>
            </div>
            <!-- End of Dialog Button for Dialog Item-->
            </div>
         </div>
</div>
<!---------------------------------------------Batas Akhir Dialog Purchase Invoice------------------------------------------------>

<div id="dialog-account" class="easyui-dialog" style="width:850px;height:523px;top:27px;background-color:#F8F8F8;padding:0px" closed="true" data-options="modal:true, iconCls:'icon-save'" buttons="#dialog-buttons-account-payment">
    <table width="100%" align="left" border="0">
        
        <tr>
            <td><b>Account Number</b></td>
            <td width="10"><b>:</b></td>
            
            <td>
                <input type="text" style="width:705px;height:20px" name="txt_AccountNumber" id="txt_AccountNumber" class="easyui-validatebox" placeholder="Account Number" onkeyup="search_akun();" />
            </td>
        </tr>
        
        <tr>
            <td><b>Account Name</b></td>
            <td><b>:</b></td>
        
            <td>
                <input type="text" style="width:705px;height:20px" name="txt_AccountName" id="txt_AccountName" class="easyui-validatebox" placeholder="Account Name" onkeyup="search_akun();" />
            </td>
        </tr>
        
        <tr>
            <td colspan="3">
                <table id="grid_akun" class="easyui-datagrid" singleSelect="true"  rownumbers="true" style="width:828px;height:387px;"
                    pageSize="150" 
                    data-options = "border:true,view:scrollview,autoRowheight:false" 
                >
                    <thead>
                        <tr bgcolor="">
                           	<th field="AccountNumber" width="150" sortable="true" formatter="format_acc">Account Number</th>
                            <th field="AccountName" width="304" sortable="true" formatter="format_acc">Account Name</th>
                            <th field="SubtypeName" width="300" sortable="true" >Type Name</th>
                            <th field="CurrencyCode" width="460" sortable="true" hidden="true">Currency Code</th>
                            <th field="AccountLevel" width="460" sortable="true" hidden="true">Account Level</th>
                        </tr>
                    </thead>
                </table>
            </td>
        </tr>
    </table>
</div>

<!-- Dialog Button -->
<div id="dialog-buttons-account-payment">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_account_journal();">OK</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="close_modal()">Cancel</a>
</div>

<script type="text/javascript">
var SavePrivillage 	= '<?php echo $group_user->SavePrivillage;?>';
var indChoAccount   = 0;

$(document).ready(function(){ 
	$('#dtg_list_invoice').edatagrid({
		onBeginEdit:function(rowIndex,rowDatax){
			var editors     = $('#dtg_list_invoice').datagrid('getEditors', rowIndex);
			var AccountName	= $(editors[0].target); 
			var Currency   	= $(editors[1].target); 
			var Amount   	= $(editors[2].target);
			var Rate   		= $(editors[3].target); 
			var PrimeAmount   	= $(editors[4].target); 
			var Memo   		= $(editors[5].target); 
			PrimeAmount_Con = 0;
			
			/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
			save_button_begendedit(SavePrivillage);
			/*=================================end============================================================*/
			
			Rate.prop('disabled',true);
			Currency.prop('disabled',true);
			PrimeAmount.prop('disabled',true);
			
			var currency_code = $('#txt_currency_code').val();
			var CurrRate = $('#txt_rate').numberbox('getValue');
			var CurrAccountCode = Currency.val();
			
			$(AccountName).click(function(){
				open_account_journal(rowIndex);
			}).mouseover(function(){
				$(this).css('cursor','pointer');
			})
								
			if(AccountName.val() != ""){
				if(currency_code == 'IDR'){
					if(CurrAccountCode == 'IDR'){
						Rate.prop('disabled',true);
					}
					else{
						Rate.prop('disabled',false);
					}
				}
				else{
					if(CurrAccountCode == 'IDR'){
						Rate.prop('disabled',false);
					}
					else{
						Rate.prop('disabled',false);
					}
				}
			}
			
			$(Amount).numberbox({
				onChange:function(){
					if(currency_code == 'IDR'){
						if(CurrAccountCode == 'IDR'){
							PrimeAmount_Con = Amount.numberbox('getValue') * Rate.numberbox('getValue');
						}
						else{
							PrimeAmount_Con = Amount.numberbox('getValue') * Rate.numberbox('getValue');
						}
					}
					else{
						if(CurrAccountCode == 'IDR'){
							PrimeAmount_Con = Amount.numberbox('getValue') / Rate.numberbox('getValue');
						}
						else{
							PrimeAmount_Con = Amount.numberbox('getValue') * Rate.numberbox('getValue');
						}
					}
	
					$(PrimeAmount).numberbox('setValue', PrimeAmount_Con);
				}
			}); 
			
			$(Rate).numberbox({
				onChange:function(){
					if(currency_code == 'IDR'){
						if(CurrAccountCode == 'IDR'){
							PrimeAmount_Con = Amount.numberbox('getValue') * Rate.numberbox('getValue');
						}
						else{
							PrimeAmount_Con = Amount.numberbox('getValue') * Rate.numberbox('getValue');
						}
					}
					else{
						if(CurrAccountCode == 'IDR'){
							PrimeAmount_Con = Amount.numberbox('getValue') / Rate.numberbox('getValue');
						}
						else{
							PrimeAmount_Con = Amount.numberbox('getValue') * Rate.numberbox('getValue');
						}
					}
	
					$(PrimeAmount).numberbox('setValue', PrimeAmount_Con);
				}
			}); 
		},
		onEndEdit:function(rowIndex, rowData, changes){
			calculate_total();
			save_button_endedit(SavePrivillage);
	   }
	});
	
	$('#fm_purchase_dp').click(function(){
		$('#dtg_list_invoice').edatagrid('saveRow');
	});     
});

function calculate_total(){
	var item        = $('#dtg_list_invoice').edatagrid('getRows');
	var sub_total   = 0;
	var amount  	= 0;
	var currency_code = $('#txt_currency_code').val();
	
	$.each(item, function( index, value ) {
		if(currency_code == 'IDR'){
			if(value.CurrencyCode == 'IDR'){
				amount  = isNaN(value.Amount) ? 0 : value.Amount;
			}
			else{
				amount  = isNaN(value.Amount) ? 0 : value.Amount * value.Rate;
			}
		}
		else{
			if(value.CurrencyCode == 'IDR'){
				amount  = isNaN(value.Amount) ? 0 : value.Amount / value.Rate;
			}
			else{
				amount  = isNaN(value.Amount) ? 0 : value.Amount;
			}
		}
		
		sub_total		+= parseFloat(amount);			
	});
	$('#txt_amount').numberbox('setValue', sub_total);
}

$('#cbg_branch').combogrid({
	onSelect:function(rowIndex, rowData){
		$('#cmb_vendor').combogrid('setValue','');
		
											
		$('#cbg_vendor').combogrid('grid').datagrid('load',{
			BranchCode : rowData.BranchCode,
			CompanyCode : rowData.CompanyCode
		});
	}
}); 
	
$('#cbg_vendor').combogrid({
	onSelect:function(rowIndex, rowData){
		var branch = $('#cbg_branch').combogrid('getValue');
		
		$('#tt_choose').datagrid('load',{
			vend_code : rowData.VendorCode
		});	
		
		search_account(rowData.CurrencyCode,branch);
		
		$('#txt_rate').numberbox('setValue', rowData.CurrencyRate);
		$('#txt_currency_code').val(rowData.CurrencyCode);
		$('#txt_status_vendor').val(rowData.LockStatus);
		
		
		if(rowData.CurrencyCode == 'IDR' ){
			$('#txt_rate').prop('disabled', true);
		}
		else{
			$('#txt_rate').prop('disabled', false);
		}
	}
});	
	
function select_sales() {
	var Vendor = $('#cbg_vendor').combogrid('grid');	// get datagrid object
	
	var SelectedVendor = Vendor.datagrid('getSelected');// get the selected row
	if(SelectedVendor == null ){
		$.messager.alert('Maaf','Silahkan pilih vendor terlebih dahulu','warning',function(){		
		});
	}
	else{
		modal_open('Select Down Payment','dialog-si');
	}		
}

function choose_item_si(){
	
	var CurrencyRate 	= $('#tt_choose').datagrid('getSelected').CurrencyRate;
	var SaldoDPBalance 	= $('#tt_choose').datagrid('getSelected').SaldoDPBalance;
	var POrdNumber 		= $('#tt_choose').datagrid('getSelected').POrdNumber;
	var DPAmountRate 		= $('#tt_choose').datagrid('getSelected').SumDp_rate;
	var DPAmountNoRate 		= $('#tt_choose').datagrid('getSelected').SumDp_norate;
	var CurrencyCode 		= $('#tt_choose').datagrid('getSelected').CurrencyCode;
	
	$('#dp_rate').numberbox('setValue',CurrencyRate);
	$('#owing_amount').numberbox('setValue',SaldoDPBalance);
	$('#owing_amount_hidden').numberbox('setValue',SaldoDPBalance);
	$('#txt_dp_number').val(POrdNumber);
	$('#txt_trans_dp_no').val(POrdNumber);

	if(CurrencyCode == 'IDR'){
		convert_owing 	= DPAmountNoRate;
	}
	else{
		convert_owing = DPAmountRate;
	}
	
	$('#txt_equal_invoice').numberbox('setValue',convert_owing);
	
	$('#dtg_list_invoice').datagrid('loadData',{'total':0,'rows':[]});
	$('#dtg_list_invoice').datagrid('reload');
	
	modal_close('dialog-si');
}

function add_row(){
	if($('#cbg_vendor').combogrid('getValue')  == ""){
		$.messager.alert('Maaf','Silahkan pilih vendor terlebih dahulu','warning',function(){	
		
		});
	}
	else if($('#owing_amount').numberbox('getValue')  == 0){
		$.messager.alert('Maaf','Silahkan pilih Select DP terlebih dahulu','warning',function(){	
		
		});
	}
	else{
		var row 				= $('#dtg_list_invoice').datagrid('getRows');
		$('#dtg_list_invoice').datagrid('endEdit', (row.length - 1));
			
		Rate = $('#txt_rate').numberbox('getValue');
		$('#dtg_list_invoice').edatagrid('addRow',{
			//index: 1,
			row: {
				Rate            : Rate,
				Amount          : 0,
				PrimeAmount     : 0
			}
		});
		
		$('#dtg_list_invoice').datagrid('beginEdit', (row.length - 1));
		
		//$('#dtg_list_invoice').edatagrid('addRow');
	}
}

function open_account_journal(indexRow){ 
   indChoAccount = indexRow;
   modal_open('Account List','dialog-account');
}

function remove_row(){
	var row 			= $('#dtg_list_invoice').datagrid('getRows');
	$('#dtg_list_invoice').datagrid('endEdit', (row.length - 1));

	$('#dtg_list_invoice').edatagrid('saveRow');  
	
	var selectedrow     = $('#dtg_list_invoice').datagrid('getSelected');
	var row_index       = $('#dtg_list_invoice').datagrid('getRowIndex', selectedrow);
	
	$.messager.confirm('Confirmation :', 'Anda yakin, Anda ingin menghapus item "' + selectedrow.AccountName + '"?',  
		function(r){
			if (r){
				/*====================on beg in edit saat grid di klik maka tombol save disable===================*/
				save_button_endedit(SavePrivillage);
				/*=================================end============================================================*/
			   //$('#dtg_list_invoice').edatagrid('saveRow');
				$('#dtg_list_invoice').datagrid('deleteRow', row_index);
				calculate_total();
			}
		}
	);
}

function close_modal(){
	modal_close('dialog-account');
}

function format_acc(val,row){
	return '<span style="padding-left:'+row.AccountLevel+'em;">'+val+'</span>';	
}

function search_account(CurrencyCode,branch){
	$('#grid_akun').datagrid({
		url:'<?php echo base_url(); ?>list/purchase_dp/get_akun/'+CurrencyCode+'/'+branch
	});
}

function choose_account_journal(){
	var selected_data	=	$('#grid_akun').datagrid('getSelected');
	
	get_master_rate_on_grid(selected_data.CurrencyCode,function(MstRate){
    	$('#dtg_list_invoice').datagrid('updateRow',{
			index: indChoAccount,
			row: {
				AccountName     : selected_data.AccountName,
				Rate           	: MstRate.value,
				Amount          : 0,
			   CurrencyCode     : selected_data.CurrencyCode,
			   AccountNumber 	: selected_data.AccountNumber,
			   SubtypeName 		: selected_data.SubtypeName,
			   TypeName 		: selected_data.TypeName
			}
		});
		
		$('#dtg_list_invoice').edatagrid('beginEdit', indChoAccount);
    });
			
	modal_close('dialog-account');
}

function save_me(){
	if($('#txt_amount').numberbox('getValue') > $('#owing_amount').numberbox('getValue')){
		$.messager.alert('Maaf','Amount melebihi Total Owing Downpayment, silahkan lihat kembali transaksi ini','warning',function(){	
		
		});
	}
	else if($('#txt_status_vendor').val() == 1){
		$.messager.alert('Maaf','Maaf Vendor sedang di Lock, silahkan proses Transaksi yang berada di Purchase Payment atau Purchase Journal','warning',function(){	
		
		});
	}
	else{
		$('#dtg_list_invoice').edatagrid('saveRow');	
		var i=$('#dtg_list_invoice').datagrid('getRows');
		var detail = JSON.stringify(i);
		
		$("#detail").val(detail);
		save_transaction('<?=$menu_link?>','#fm_purchase_dp');
	}
}

$.extend($.fn.datagrid.defaults.editors, {
	AccountName: {
		init: function(container, options){
			var input = $('<input type="text" class="AccountName" style="height:18px;" readonly/>').appendTo(container);
			return input.validatebox(options);
		},
		destroy: function(target){
			$(target).remove();
		},
		getValue: function(target){
			 return $(target).val();
		},
		setValue: function(target, value){
			  $(target).val(value);
		},
		resize: function(target, width){
			   $(target)._outerWidth(width);
		}
	}
});
</script>