<!---- 
    Author 	: Wahyu
    Tanggal : 12-08-2014	
    Revisi 	: Fachri
-->
<?php
//---------Untuk privellege jika dia ada tombol save,suspen,jurnal----------
	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">
                            <input type="checkbox" id="chk_suspend" name="chk_suspend" value="3" style="margin-right:0px;margin-top:1px;<?=($row->CustStatus==3)?'opacity:0.7;':''?>" <?=($row->CustStatus==3)?'checked disabled':''?> />
                            <span style="<?=($row->CustStatus==3)?'color:gray;':''?>">Suspend</span>
                        </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-grey" data-options="region:'center',border:false">
		<div class="easyui-panel" style="width:auto;padding:5px;height:525px;" fit="true">
        	<form id="fm_customer" name="fm_customer" method="post">
                <input type="hidden" id="id" name="id" value="<?= $row->CustomerCode;?>" />
                <input type="hidden" name="detail" id="detail"/>
                <input type="hidden" name="detail_dp" id="detail_dp"/>
                <input type="hidden" name="id_klik" id="id_klik"/>
                <input type="hidden" name="konversi" id="konversi" class="easyui-numberbox"/>
                <input type="hidden" name="rate_data" id="rate_data" class="easyui-numberbox"/>
                <input name="txt_rate" id="txt_rate" type="hidden" class="easyui-numberbox" style="width:110px;" data-options="min:0.01,precision:2,decimalSeparator:',',groupSeparator:'.',prefix:''" formatter="formatRp" />
            	<div class="easyui-tabs">
                	<!-- Customer Address -->
					<div id="tab_addres" title="Address" style="padding:10px;">
                    	<table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td><b>Customer No.</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_customerno" class="easyui-validatebox" value="<?= $row->CustomerCode;?>" style="width:850px;text-transform:uppercase;background-color:#E3E2E2;" required readonly />
                                <!--
                                <input type="hidden" id="txt_customerno_hidden" name="txt_customerno_hidden" value="<?php //echo $customer_code;?>" />
                                -->
                            </td>
                        </tr>
                        <tr>
                            <td><b>Customer Name</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_customername" class="easyui-validatebox" data-options="required:true" value="<?= $Customer;?>" style="width:650px;text-transform:uppercase;" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            	- <input type="text" name="txt_curency_not_real" class="easyui-validatebox" data-options="required:true" value="<?= $row->CurrencyCode;?>" style="width:185px;text-transform:uppercase;"  readonly />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Address</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_address" class="easyui-validatebox" value="<?php echo $row->CustomerAddress;?>" style="width:850px;" required="true" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_addressdetail" id="txt_addressdetail" style="width:850px;" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Tax Address</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_taxaddress" id="txt_taxaddress" style="width:850px;" value="<?php echo $row->CustTaxAddress;?>" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_taxaddressdetail" id="txt_taxaddressdetail" style="width:850px;" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>City/Prov/Zip Code</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                            	<select name="cmb_city" id="cmb_city" class="combo-grid" style="width:280px;"  required="true" editable="true"
                                    data-options="
                                    	value:'<?php echo $row->CityCode;?>',
                                        idField:'CityCode',
                                        textField:'CityName',
                                        url:'<?php echo base_url(); ?>custom/get_data/city',
                                        method: 'get',
                                        columns: [[
                                            {field:'CityCode',title:'City Code',width:120,halign:'center',align:'left'},
                                            {field:'CityName',title:'City Name',width:230,halign:'center',align:'left'}
                                        ]],
                                    ">
                                </select>
								<select name="cmb_state" id="cmb_state" class="easyui-combogrid" style="width:280px;"  required="true" editable="false" readonly
                                    data-options="
                                    	value:'<?php echo $row->StateCode;?>',
                                        idField:'StateCode',
                                        textField:'StateName',
                                        url:'<?php echo base_url(); ?>custom/get_data/state',
                                        method: 'get',
                                        columns: [[
                                            {field:'StateCode',title:'State Code',width:100,halign:'center',align:'left'},
                                            {field:'StateName',title:'State Name',width:161,halign:'center',align:'left'}
                                        ]],
                                    ">
                                </select>
                                <input type="text" name="txt_zipcode" class="easyui-numberbox" style="width:280px;" autocomplete="off" value="<?php echo $row->CustomerPostalCode;?>" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?>/>
                                
                            </td>
                        </tr>
                        <tr>
                            <td><b>Country</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <select name="cmb_country" id="cmb_country" class="easyui-combogrid" style="width:852px;" required="true" editable="false" readonly
                                    data-options="
                                    	value:'<?php echo $row->CountryCode;?>',
                                        idField:'CountryCode',
                                        textField:'CountryName',
                                        url:'<?php echo base_url(); ?>custom/get_data/country',
                                        method: 'get',
                                        columns: [[
                                            {field:'CountryCode',title:'Country Code',width:100,halign:'center',align:'left'},
                                            {field:'CountryName',title:'Country Name',width:161,halign:'center',align:'left'}
                                        ]],
                                    ">
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Phone</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_phone" class="easyui-validatebox" value="<?php echo str_replace(',','',$row->PhoneNumber);?>" style="width:852px;" required <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Fax</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_fax" class="easyui-numberbox" value="<?php echo $row->FacsimileNumber;?>" style="width:852px" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Contact Person</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_contactperson" class="easyui-validatebox" value="<?php echo $row->ContactPerson;?>" style="width:850px;" required <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>E-Mail</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_email" class="easyui-validatebox" style="width:850px;" data-options="validType:'email'" value="<?php echo $row->EmailAddress;?>" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Web Page</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_webpage" style="width:850px;" data-options="validType:'url'" value="<?php echo $row->WebAddress;?>" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                            </td>
                        </tr>
                        </table>
                    </div>
                    <!-- Customer Terms -->
                    <div id="tab_terms" title="Terms, etc." style="padding:10px;">
                    	<fieldset>
                            <legend>Terms</legend>
                            <table width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><b>Terms</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <select name="cmb_terms" id="cmb_terms" class="combo-grid" style="width:830px;"  required="true" editable="true" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?>
                                        data-options="
                                        	value:'<?php echo $row->TermsID;?>',
                                            idField:'TermspaymentID',
                                            textField:'TermDesc',
                                            url:'<?=base_url()?>custom/get_data/termspayment',
                                            method: 'get',
                                            columns: [[
                                                {field:'TermspaymentID',title:'Terms payment ID',width:350,halign:'center',align:'left'},
                                                {field:'TermDesc',title:'Term Desc',width:435,halign:'center',align:'left'}
                                            ]],
                                            onSelect:function(rowIndex, rowData){
                                            	var disc_days       = rowData.disc_days;
                                                var disc_percent 	= rowData.disc_percent;
                                                var net_days 		= rowData.net_days;

                                                $('#disc_percent').html(disc_percent);
                                                $('#paid_within').html(disc_days);
                                                $('#net_due_in').html(net_days);
                                            }
                                        ">
                                    </select>
                                </td>
                            </tr>
                            
                            </table>
                        </fieldset>						

                        <fieldset>
                            <legend>Other</legend>
                            <table width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><b>Sales Order Limit</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <input type="text" id="txt_salesorderlimit" name="txt_salesorderlimit" onkeyup="duplicate_salesorderlimit()" class="easyui-validatebox easyui-numberbox" value="<?php echo $row->SalesLimit;?>" style="width:842px;" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" required <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?> autocomplete="off" />
                                    <input type="hidden" id="txt_salesorderlimit_hidden" name="txt_salesorderlimit_hidden" value="<?php echo $row->SalesLimit;?>" />
                                </td>
                            </tr>
                            <tr>
                                <td><b>Out Standing</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                	<input type="text" class="easyui-numberbox" name="txt_cust_balance" id="txt_cust_balance" value="<?php echo $row->OutStanding;?>"  style="width:812px;text-align:left;" readonly autocomplete="off" data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" />
                                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" onclick="modal_open('Select Customer Balance','dialog-customer-balance')" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'disabled':''?>></a>
                                    <input type="hidden" id="txt_cust_balance_hidden" class="easyui-numberbox" name="txt_cust_balance_hidden" value="<?php echo $row->OutStanding;?>" data-options="precision:2,decimalSeparator:',',groupSeparator:'.'"/>
                                </td>
                            </tr>
                            <?php if($row->CurrencyCode != "IDR"){ ?>
                            <tr>
                                <td><b>Out Standing Fiscal</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                	<input type="text" class="easyui-numberbox" name="txt_out_fiscal" id="txt_out_fiscal" value="<?php echo $row->OutStandingFiscal;?>"  style="width:842px;text-align:left;" readonly autocomplete="off" data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'readonly':''?>/>
                                   
                                </td>
                            </tr>
                            <?php } ?>
                            <tr>
                                <td title="Nilai Total Sales Order Yang Belum Di Proses" class="easyui-tooltip"><b>Temp Out Standing</b></td>
                                <td width="840" style="padding:1px 0px 2px;" >
                                    <input type="text" id="txt_temp_outstanding" name="txt_temp_outstanding" class="easyui-validatebox easyui-numberbox" value="<?php echo $row->TempOutStanding;?>" style="width:842px;" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" required readonly autocomplete="off" />
                                </td>
                            </tr>
                            
                            <tr>
                                <td><b>Down Payment</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <input type="text" id="txt_outstanding" style="width:812px;text-align:left;" class="easyui-numberbox" name="txt_outstanding" data-options="precision:2,decimalSeparator:',',groupSeparator:'.'" value="<?php echo $row->SaldoDPBalance;?>" onkeyup="duplicate_outstanding()" readonly="readonly" />
                                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" onclick="modal_open('Select Down Payment','dialog-dp-balance')" <?=($row->CustStatus==3 || $row->BranchCode != $this->session->userdata("branch"))?'disabled':''?>></a>
                                	<input type="hidden" id="txt_outstanding_hidden" name="txt_outstanding_hidden" value="<?php echo $row->SaldoDPBalance;?>" />
                                </td>
                            </tr>
                            
                            <tr>
                                <td><b>Currency</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <select name="cmb_currency" id="cmb_currency" class="combo-grid" style="width:830px;"  required="true" editable="true" readonly 
                                        data-options="
                                            value:'<?= $row->CurrencyCode;?>',
                                            idField:'CurrencyCode',
                                            textField:'CurrencyName',
                                            url:'<?=base_url()?>custom/get_data/currency',
                                            method: 'get',
                                            columns: [[
                                                {field:'CurrencyCode',title:'Currency Code',width:380,halign:'center',align:'left'},
                                                {field:'CurrencyName',title:'Currency Name',width:435,halign:'center',align:'left'}
                                            ]],
                                            onSelect:function(indexRow,rowData){
                                                get_master_rate(rowData.CurrencyCode);
                                            }
                                        " <?=($row->CustStatus==3)?'readonly':''?>>
                                    </select>
                                    
                                    
                                </td>
                            </tr>
                            <tr>
                                <td><b>Customer Type</b></td>
                                <td style="padding:1px 0px 2px;">
                                    <?php if($row->CustomerStatus == 0){ ?>
                                        <input name="rd_vendor_type" type="Radio" value="0" checked required="true"/>Badan
                                        <input name="rd_vendor_type" type="Radio" value="1" required="true"/>Perseorangan
                                        
                                     <?php }else if($row->CustomerStatus == 1){ ?>
                                        <input name="rd_vendor_type" type="Radio" value="0"  required="true"/>Badan
                                        <input name="rd_vendor_type" type="Radio" value="1" checked required="true"/>Perseorangan
                                        
                                     <?php } else{?>
                                        <input name="rd_vendor_type" type="Radio" value="0"  required="true"/>Badan
                                        <input name="rd_vendor_type" type="Radio" value="1" required="true"/>Perseorangan
                                     <?php }?>
                                    <!-- <input type="button" id="btn_unit" name="btn_unit" value="..." /> -->
                                </td>
                        </tr>
                            <tr>
                                <td valign="top" style="padding-top:4px;"><b>Message</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <textarea name="txa_message_terms" rows="4" style="width:836px;resize:none;" <?=($row->CustStatus==3)?'readonly':''?>><?php echo $row->CurrencyMemo;?></textarea>
                                </td>
                            </tr>
                            <!--
                            <tr>
                                <td class="td_label"></td>
                                <td>
                                    <input type="checkbox" name="chk_print_cust_stat_report" /> Print Customer Statement Report
                                </td>
                            </tr>
                            -->
                            </table>
                        </fieldset>
                    </div>
                    <!-- Customer Sales -->
                    <div id="tab_sales" title="Tax & Region" style="padding:10px;">
                        <fieldset>
                            <legend>Taxes</legend>
                            <table width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><b>Tax 1</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                	<select name="cmb_tax1" id="cmb_tax1" 
                                    	class="combo-grid"
                                        style="width:842px;" 
                                        data-options = "
                                        	value:'<?php echo $row->Taxes1Code;?>',
                                            idField:'TaxesCode',
                                            textField:'TaxesName',
                                            url:'<?=base_url()?>custom/get_data/taxes',
                                            method: 'get',
                                            columns: [[
                                                {field:'TaxesCode',title:'Tax Code',width:500,halign:'center',align:'left'},
                                                {field:'TaxesName',title:'Tax Name',width:330,halign:'center',align:'left'}
                                            ]],
                                        " editable="true" <?=($row->CustStatus==3)?'readonly':''?>
                                    >
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td><b>Tax 2</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                	<select name="cmb_tax2" id="cmb_tax2"  
                                    	class="combo-grid"
                                        style="width:842px;" 
                                        data-options = "
                                        	value:'<?php echo $row->Taxes2Code;?>',
                                            idField:'TaxesCode',
                                            textField:'TaxesName',
                                            url:'<?=base_url()?>custom/get_data/taxes',
                                            method: 'get',
                                            columns: [[
                                                {field:'TaxesCode',title:'Tax Code',width:500,halign:'center',align:'left'},
                                                {field:'TaxesName',title:'Tax Name',width:330,halign:'center',align:'left'}
                                            ]],
                                        " editable="true" <?=($row->CustStatus==3)?'readonly':''?>
                                    >
                                    </select>
                                </td>
                            </tr>
                            <!--<tr>
                                <td></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <input type="checkbox" name="chk_taxincluded" value="1" style="margin-left:0px;" <?php if($row->TaxIncludedStatus != 0){ echo "checked='checked'"; }else{ echo ""; }?> <?=($row->CustStatus==3)?'onClick="return false;" style="opacity:0.7;"':''?> /> Default Invoice is Tax Included
                                </td>
                            </tr>-->
                            <tr>
                                <td><b>NPWP Number</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <input type="text" name="txt_taxnumber" style="width:840px;" value="<?php echo $row->TaxesNumber;?>" <?=($row->CustStatus==3)?'readonly':''?> autocomplete="off" />
                                </td>
                            </tr>
                            <tr>
                                <td><b>NPPKP</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <input type="text" name="txt_nppkp" style="width:840px;" value="<?php echo $row->PPKPNumber;?>" <?=($row->CustStatus==3)?'readonly':''?> autocomplete="off" />
                                </td>
                            </tr>
                            <tr>
                                <td><b>Tax Type</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                	<select id="cmb_taxtype" name="cmb_taxtype"   
                                    	class="combo-grid"
                                        style="width:842px;" 
                                        data-options = "
                                        	value:'<?php echo $row->TaxesTypeID;?>',
                                            idField:'TaxTypeID',
                                            textField:'TaxTypeName',
                                            url:'<?=base_url()?>custom/get_data/taxtype',
                                            method: 'get',
                                            columns: [[
                                                {field:'TaxTypeID',title:'Tax Type ID',width:200,halign:'center',align:'left'},
                                                {field:'TaxTypeName',title:'Tax Type Name',width:610,halign:'center',align:'left'}
                                            ]],
                                        " editable="true" <?=($row->CustStatus==3)?'readonly':''?>
                                    >
                                    <option value="">&nbsp;</option>
                                    </select>
                                    <!--input type="text" id="txt_tax_type" name="txt_tax_type" class="" /-->				
                                </td>
                            </tr>
                            </table>			
                        </fieldset>						
                        <fieldset>
                            <legend>Other</legend>
                            <table width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><b>Region</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                	<select name="cmb_region" id="cmb_region"    
                                    	class="combo-grid"
                                        style="width:842px;" 
                                        data-options = "
                                        	value:'<?php echo $row->RegionCode;?>',
                                            idField:'RegionCode',
                                            textField:'RegionName',
                                            url:'<?=base_url()?>custom/get_data/region',
                                            method: 'get',
                                            columns: [[
                                                {field:'RegionCode',title:'Region Code',width:200,halign:'center',align:'left'},
                                                {field:'RegionName',title:'Region Name',width:630,halign:'center',align:'left'}
                                            ]],
                                        " editable="true" <?=($row->CustStatus==3)?'readonly':''?>
                                    >
                                    </select>
                                    
                                </td>
                            </tr>
                            </table>
                        </fieldset>
                    </div>
					<!-- Notes -->
                    <div id="tab_notes" title="Notes">
                        <textarea rows="18" name="txa_notes" style="width:calc(100% - 16px);margin:5px;resize:none;" <?=($row->CustStatus==3)?'readonly':''?>><?php echo $row->CustomerDesc;?></textarea>
                    </div>
                </div>
                
                <!-- Dialog SI -->
                <div id="dialog-customer-balance" class="easyui-dialog" style="width:575px;height:523px;top:27px;background-color:#F8F8F8;padding:0px;" closed="true" data-options="modal:true" buttons="#dialog-buttons-customer"> 
                	<table toolbar="#tb_dg_item" id="dg_sales_invoice" class="easyui-edatagrid"  
                        singleSelect="true" fitColumns="true" 
                        pageSize="20" idField="id"
                        remoteSort="false" rowNumbers="true" 
                        fit="true"

                    >
                    	<thead>
                        	<tr>
                            	<th field="OldSInvNumber" width="75" editor="{type:'text',options:{required:true}}">No Sales Invoice</th>
                                <th field="OutStanding" width="70" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:1,required:true,disabled:false}}" formatter="formatRp">Balance</th>
                                <?php if($row->CurrencyCode != "IDR"){ ?>
                                	<th field="Rate" width="50" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:1,required:true,disabled:false}}" formatter="formatRp">Exchange Rate</th>
                                 <?php } ?>	
                                 <th align="center" valign="middle" data-options="
                                    field:'EmployeeName',
                                    width:100,                                  
                                    align:'left',
                                    editor:{
                                        type:'combobox',
                                        options:{
                                            valueField:'EmployeeName',
                                            textField:'EmployeeName',
                                            width:290,
                                            url: '<?=base_url()?>list/customers/list_salesman',
                                            editable:true,
                                            required:true
                                         }
                                    } 
                                ">Salesman</th>
                                <th field="SInvDate" width="50" editor="{type:'datebox',options:{required:true,editable:false}}">Date</th>
                        	</tr>
                    	</thead>
                    </table>
        	    </div>
            	<div id="tb_dg_item">
                	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg_sales_invoice').edatagrid('addRow')">New</a>
                	<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row()">Delete</a>
            	</div>
            
            	<div id="dialog-buttons-customer" style="border:none;">
                	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_customer_balance();">Ok</a>
                	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="close_popup()">Cancel</a>
            	</div>
                
                <div id="dialog-dp-balance" class="easyui-dialog" style="width:575px;height:523px;top:27px;background-color:#F8F8F8;padding:0px;" closed="true" data-options="modal:true" buttons="#dialog-buttons-dp"> 
                	<table toolbar="#tb_dg_dp" id="dg_dp" class="easyui-edatagrid"  
                        singleSelect="true" fitColumns="true" 
                        pageSize="20" idField="id"
                        remoteSort="false" rowNumbers="true" 
                        fit="true" 
                    >
                    	<thead>
                        	<tr>
                            	<th field="NoTransaksi" width="50" editor="{type:'NoTransaksi',options:{required:true}}">No Transaction</th>
                                <th field="Rate" width="50" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:0.01,required:true,disabled:false}}" formatter="formatRp">Rate</th>
                                <th field="DownPayment" width="70" editor="{type:'numberbox',options:{precision:2,decimalSeparator:',',groupSeparator:'.',min:0,required:true,disabled:false}}" formatter="formatRp">Down Payment</th>
                            </tr>
                    	</thead>
                    </table>
                </div>
                <div id="tb_dg_dp">
                	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addNewRowDP()">New</a>
                	<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove_row_dp()">Delete</a>
            	</div>
                <div id="dialog-buttons-dp" style="border:none;">
                	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onClick="choose_dp_balance();">Ok</a>
                	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onClick="close_popup_dp()">Cancel</a>
            	</div>
            </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" iconCls="icon-save" onclick="update_data()" <?=($row->CustStatus==3)?'disabled':''?> <?php echo $cek_autority_save;?>>Save</a> 								
                     <!--<a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-print" onclick="" <?=($row->CustStatus==3)?'disabled':''?>>Preview & Print</a>   -->
                     <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="" <?=($row->CustStatus==3)?'disabled':''?>>Cancel</a>  
					 <a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="location.reload()" disabled>Cancel</a>
				</td>
			 </tr>
		</table>				
	</div>	
</div>
<script type="text/javascript">
var newIndex    = -1;
$(document).ready(function(){
	$('#dialog-customer-balance').click(function(){
		$('#dg_sales_invoice').edatagrid('saveRow');
	});
	
	$('#cmb_city').combogrid({
        onSelect:function(rowIndex, rowData){
            $('#cmb_state').combogrid('setValue', rowData.StateCode);
        }
    });

    $('#cmb_state').combogrid({
        onSelect:function(rowIndex, rowData){
            $('#cmb_country').combogrid('setValue', rowData.CountryCode);
        }
    });

    get_master_rate('<?=$row->CurrencyCode;?>');

    $('#fm_customer').on('click',function(){
        if(newIndex >=0){
            $('#dg_dp').datagrid('endEdit', newIndex);
            $('#dg_dp').edatagrid('saveRow');
        }
        
    });

    $('#dialog-dp-balance').click(function(){
        var item        = $('#dg_dp').datagrid('getRows');
        var TotalItem   = item.length + 1;

        for(var x=0;x<TotalItem;x++){
            $('#dg_dp').datagrid('endEdit', x);
        }
        $('#dg_dp').edatagrid('saveRow');
    });
		
});

function addNewRowDP(){
    if(newIndex >= 0){
        $('#dg_dp').datagrid('endEdit', newIndex);
        $('#dg_dp').edatagrid('saveRow');
    }
	
	var rate            = $('#txt_rate').numberbox('getValue');
    var cmb_currency    = $('#cmb_currency').combobox('getValue');
    var dg              = $('#dg_dp');
    var item            = dg.datagrid('getColumnOption','Rate');

    newIndex            = item.length;

    if(cmb_currency == 'IDR'){
       item.editor.options.disabled     = true;
    }
	
	var row 				= $('#dg_dp').datagrid('getRows');
	$('#dg_dp').datagrid('endEdit', (row.length - 1));
		
	$('#dg_dp').edatagrid('addRow',{
		//index: 1,
		row: {
			NoTransaksi     : '',
			Rate            : rate,
			DownPayment     : 0
		}
	});
	
	$('#dg_dp').datagrid('beginEdit', (row.length - 1));
}
		
function update_data(){
	$('#dg_sales_invoice').edatagrid('saveRow');
	var i=$('#dg_sales_invoice').datagrid('getRows');
	var detail = JSON.stringify(i);
	$("#detail").val(detail);
    var dp=$('#dg_dp').datagrid('getRows');
    var DownPayment = JSON.stringify(dp);
    $("#detail_dp").val(DownPayment);
	edit_data('<?php echo $menu_link?>','#fm_customer');
}

function close_popup(){
	$('#dg_sales_invoice').datagrid('reload');
	modal_close('dialog-customer-balance')
}

function close_popup_dp(){
    $('#dg_dp').datagrid('reload');
    modal_close('dialog-dp-balance')
}

function choose_dp_balance(){
    var item        = $('#dg_dp').datagrid('getRows');
    var TotalItem   = item.length + 1;
    var TotalDP     = 0;

    for(var x=0;x<TotalItem;x++){
        $('#dg_dp').datagrid('endEdit', x);
    }
    $('#dg_dp').edatagrid('saveRow');

    $.each(item,function(ind,val){
        TotalDP += parseFloat(val.DownPayment);
    });

    $('#txt_outstanding').numberbox('setValue',TotalDP);

    modal_close('dialog-dp-balance');
}

function choose_customer_balance(){
	$('#dg_sales_invoice').edatagrid('saveRow');
	var item 			= $('#dg_sales_invoice').datagrid('getRows');
	var sub_total   	= 0;
	var cmb_currency 	= $('#cmb_currency').val();
	var rate 			= 0;
	var tot_rate 		= 0;
	var val_rate 		= 0;
	var tot_rate_outstanding = 0;
	var keseluruhan 		= 0;
	var txt_aoutstanding 	 = $('#txt_cust_balance_hidden').numberbox('getValue');
	if(cmb_currency == 'IDR'){
		$.each(item, function( index, value ) {
			if(value.OutStanding != undefined){
				sub_total+= parseFloat(value.OutStanding);
				$('#id_klik').val('1');
			}				
		});
		tot_amount = parseFloat(txt_aoutstanding) + parseFloat(sub_total);
		$('#txt_cust_balance').numberbox('setValue',tot_amount);
	}
	else{
		$.each(item, function( index, value ) {
			if(value.OutStanding != ""){
				rate = parseFloat(value.OutStanding) * parseFloat(value.Rate);
				sub_total+= parseFloat(value.OutStanding);
				tot_rate+= parseFloat(rate);
				val_rate+= parseFloat(value.OutStanding);
				$('#id_klik').val('1');
			}	
		});
		
		outstanding_customer 	 = parseFloat(txt_aoutstanding) + parseFloat(val_rate);
		$('#txt_cust_balance').numberbox('setValue',outstanding_customer);
		//$('#txt_customer_rate_hidden').numberbox('setValue',hasil_keseluruhan_rate);
		
		tot_rate_outstanding 	= parseFloat(tot_rate) / parseFloat(val_rate);
		tot_amount 				= parseFloat(txt_aoutstanding) + parseFloat(sub_total);
		
		
		keseluruhan = parseFloat(tot_amount) * parseFloat(tot_rate_outstanding);
		$('#konversi').numberbox('setValue',keseluruhan);
		$('#rate_data').numberbox('setValue',tot_rate);
	}
	//$.post('',{SInvNumber:value.SInvNUmber,SInvDate:value.SInvDate,SInvTotalAmount:CustBalance});
	modal_close('dialog-customer-balance');
}

function duplicate_salesorderlimit(){
	var limit 			= $('#txt_salesorderlimit').val();
	var limitToAngka	= toAngka(limit);
	$('#txt_salesorderlimit_hidden').val(limitToAngka);
}
function duplicate_outstanding(){
	var limit_out 			= $('#txt_outstanding').val();
	var limitToAngka_out	= toAngka(limit_out);
	$('#txt_outstanding_hidden').val(limitToAngka_out);
}

function remove_row(){
	var selectedrow     = $('#dg_sales_invoice').datagrid('getSelected');
	var row_index       = $('#dg_sales_invoice').datagrid('getRowIndex', selectedrow);

	$.messager.confirm('Confirmation :', 'Anda yakin, Anda ingin menghapus transaksi "' + selectedrow.OldSInvNumber + '"?',  
		function(r){
			if (r){
				var item = $('#dg_sales_invoice').datagrid('getData').total;
				$('#dg_sales_invoice').datagrid('deleteRow', row_index);
			}
		}
	);
}

function remove_row_dp(){
    var selectedrow     = $('#dg_dp').datagrid('getSelected');
    var row_index       = $('#dg_dp').datagrid('getRowIndex', selectedrow);

    $.messager.confirm('Confirmation :', 'Anda yakin, Anda ingin menghapus transaksi "' + selectedrow.NoTransaksi + '"?',  
        function(r){
            if (r){
                var item = $('#dg_dp').datagrid('getData').total;
                $('#dg_dp').datagrid('deleteRow', row_index);
            }
        }
    );
}

$.extend($.fn.datagrid.defaults.editors, {
	NoTransaksi: {
        init: function(container, options){
            var input = $('<input type="text" class="NoTransaksi" style="height:18px;" />').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>