<!---- 
Author 	: Wahyu / Tanggal : 12-08-2014	
Revisi 	: Ferry
-->
<?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="parent.tab_add('New Customer','<?=$menu_link?>','icon-add','add')">New</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-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">
            	<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" data-options="required:true" readonly value="<?php echo $branch_code,"-".$next_customer_numb; ?>" style="width:850px;text-transform:uppercase;background-color:#E3E2E2;" />
                                <!--
                                <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" style="width:850px;text-transform:uppercase;" autocomplete="off" />
                            </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" style="width:850px;" required="true" 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;" 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;" 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;" 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="
                                        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="
                                        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" />
                            </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="
                                    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 easyui-numberbox" style="width:852px;" required="true" 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" style="width:852px" 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" style="width:850px;" required="true" 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'" 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'" 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" >
                                    <select name="cmb_terms" id="cmb_terms" class="combo-grid" style="width:830px;"  required="true" editable="true" 
                                        data-options="
                                            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" formatter="formatRp" style="width:842px;" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" required autocomplete="off" />
                                    <input type="hidden" id="txt_salesorderlimit_hidden" name="txt_salesorderlimit_hidden" />
                                </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="0" formatter="formatRp" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" style="width:812px;text-align:left;" readonly autocomplete="off" />
                                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" onclick="modal_open('Select Customer Balance','dialog-cust-balance')" disabled></a>
                                </td>
                            </tr>
                            <tr>
                                <td><b>Down Payment</b></td>
                                <td width="840" style="padding:1px 0px 2px;">
                                    <input type="text" id="txt_outstanding" name="txt_outstanding" onkeyup="duplicate_outstanding()" class="easyui-validatebox easyui-numberbox" formatter="formatRp" style="width:840px;" data-options="min:0,precision:2,decimalSeparator:',',groupSeparator:'.'" readonly="readonly"/>
                                    <input type="hidden" id="txt_outstanding_hidden" name="txt_outstanding_hidden" />
                                </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" 
                                        data-options="
                                            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'}
                                            ]]
                                        ">
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td><b>Customer Type.</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <input name="rd_vendor_type" type="Radio" value="0" required="true" checked="checked"/>Badan <input name="rd_vendor_type" type="Radio" value="1" required="true"/>Perseorangan
                                </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;"></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 = "
                                            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" 
                                    >
                                    </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 = "
                                            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" 
                                    >
                                    </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;" /> 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;" 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;" 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 = "
                                            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" 
                                    >
                                    </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 = "
                                            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" 
                                    >
                                    </select>
                                </td>
                            </tr>
                            </table>
                        </fieldset>
                    </div>
					<!-- Notes -->
                    <div id="tab_notes" title="Notes">
                        <textarea rows="20" name="txa_notes" style="width:calc(100% - 16px);margin:5px;resize:none;"></textarea>
                    </div>
                </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)" id="save_customers" class="easyui-linkbutton form-button" iconCls="icon-save" <?php echo $cek_autority_save;?>>Save</a>   
            			<a href="javascript:void(0)" class="easyui-linkbutton form-button" iconCls="icon-cancel" onclick="">Cancel</a>
		
					</td>
				 </tr>
			</table>				
		</div>
</div>

<?php $this->load->view('v_popup_item'); ?>

<script type="text/javascript">
$(document).ready(function(){
	
	$('#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);
		}
	});
			
    $('#save_customers').click(function(){
        if($('#cmb_terms').combobox('getValue') == ''){
            $.messager.alert('Info','Terms pada tab Terms, etc harus di isi');
        }
        else if($('#txt_salesorderlimit').val() == ''){
            $.messager.alert('Info','Sales Order Limit pada tab Terms, etc');
        }
        else if($('#cmb_currency').combobox('getValue') == ''){
            $.messager.alert('Info','Currency pada tab Terms, etc harus di isi');
        }
        else{
            save_transaction('<?php echo $menu_link?>','#fm_customer');
        }
    });
	
	$("#form-cust-balance").click(function(){
		$("#tt-cust-balance").edatagrid('saveRow');
	});
});

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 choose_cust_balance(){
	dg_item = $('#tt-cust-balance').datagrid('getRows');
	total_balance = 0;
	$.each(dg_item, function(index,value){
		total_balance = total_balance + parseInt(value.CustBalance);
	});
	
	$('#txt_cust_balance').val(total_balance);
	
	//$.post('',{SInvNumber:value.SInvNUmber,SInvDate:value.SInvDate,SInvTotalAmount:CustBalance});
	modal_close('dialog-cust-balance');
}
</script>