<!---- 
    Author 	: Wahyu
    Tanggal : 12-08-2014	
    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="parent.tab_add('New Vendor','<?php echo $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" data-options="region:'center',border:false">
		<div id="form-wrapper" class="easyui-panel"  style="width:1180%;height:525px;padding:5px;" fit="true">
			<form id="fm_vendor" name="fm_vendor" method="post">
            <input type="hidden" name="detail" id="detail"/>
            	<div id="wrapptabs" name="" class="easyui-tabs">
					<div id="tab_addres" title="Address" style="padding:10px">
                    	<table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td><b>Vendor Code</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_vendorno" class="easyui-validatebox" data-options="required:true" readonly value="<?php echo $branch_param1,"-".$next_vendor_numb; ?>" style="width:850px;text-transform:uppercase;background-color:#E3E2E2;" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Vendor Name</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_vendorname" id="txt_vendorname" class="easyui-validatebox" data-options="required:true" autocomplete="off" style="width:850px;text-transform:uppercase;" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Vendor Address</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_address" id="txt_address" class="easyui-validatebox" style="width:850px;" required="true" autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td><b></b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_addressdetail" style="width:850px" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Tax Address</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_taxaddress" style="width:850px;" />
                            </td>
                        </tr>
                        <tr>
                            <td><b></b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_taxaddressdetail" style="width:850px;" />
                            </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:282px;"  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:282px;"  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;" />
                            </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" id="txt_phone" class="easyui-validatebox easyui-numberbox" style="width:850px" 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>Category</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_kategori" style="width:850px" autocomplete="off" />
                            </td>
                        </tr>
                        <tr>
                            <td><b>Group</b></td>
                            <td width="850" style="padding:1px 0px 2px;">
                                <input type="text" name="txt_group" style="width:850px" 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" id="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" data-options="validType:'email'" style="width:850px" 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" autocomplete="off" />
                            </td>
                        </tr>
                        </table>
                    </div>
                    <div id="tab_terms" title="Terms, etc." style="padding:10px">
                        <fieldset>
                            <legend>Terms, etc</legend>
                            <table width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><b>Terms</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <select onchange="get_percent()" name="cmb_terms" id="cmb_terms" class="combo-grid"  style="width:852px;"  required="true" editable="true"
                                        data-options="
                                            idField:'TermspaymentID',
                                            textField:'TermDesc',
                                           	url:'<?php echo base_url(); ?>custom/get_data/termspayment',
                                            method: 'get',
                                            columns: [[
                                                {field:'TermspaymentID',title:'Terms Id',width:400,halign:'center',align:'left'},
                                                {field:'TermDesc',title:'Terms Name',width:430,halign:'center',align:'left'}
                                            ]],
                                        ">
                                    </select>
                                    
                                </td>
                            </tr>
                            <tr>
                                <td><b>Currency</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                	<select name="cmb_currency" id="cmb_currency" 
                                    	class="combo-grid"
                                        style="width:852px;"
                                        data-options="
                                            
                                            idField:'CurrencyCode', 
                                            textField:'CurrencyName', 
                                            url:'<?php echo base_url(); ?>custom/get_data/currency',
                                            method: 'get',
                                            columns: [[
                                                {field:'CurrencyCode',title:'Currency Code',width:400,halign:'center',align:'left'},
                                                {field:'CurrencyName',title:'Currency Name',width:430,halign:'center',align:'left'}
                                            ]],
                                        " editable="true" required="true" 
                                    >
                                    </select>
                                </td>
                            </tr>
                            
                            <tr>
                                <td><b>Default Description</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <input type="text" id="" name="txt_termsdefaultdesctiption" style="width:850px;" onKeyPress="return goodchars(event,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ',this)"/>
                                </td>
                            </tr>
                            </table>
                        </fieldset>
                        <fieldset>
                        	<legend>Taxes</legend>
                            <table width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><b>Tax 1</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                	<select name="cmb_tax1" id="cmb_tax1" 
                                    	class="combo-grid"
                                    	style="width:822px;" 
										data-options="
											idField:'TaxesCode', 
                                            textField:'TaxesName', 
											url:'<?php echo base_url(); ?>custom/get_data/taxes',
                                            method: 'get',
                                            columns: [[
                                                {field:'TaxesCode',title:'Taxes Code',width:370,halign:'center',align:'left'},
                                                {field:'TaxesName',title:'Taxes Name',width:430,halign:'center',align:'left'}
                                            ]],
										" editable="true" 
                                    >
									</select>
									<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#cmb_tax1').combobox('clear')"></a>
                                </td>
                            </tr>
                            <tr>
                                <td><b>Tax 2</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <select name="cmb_tax2" id="cmb_tax2" on 
                                    	class="combo-grid"
                                   		style="width:822px;" 
										data-options="
											idField:'TaxesCode',textField:'TaxesName',
											url:'<?php echo base_url(); ?>custom/get_data/taxes',
                                            method: 'get',
                                            columns: [[
                                                {field:'TaxesCode',title:'Taxes Code',width:370,halign:'center',align:'left'},
                                                {field:'TaxesName',title:'Taxes Name',width:430,halign:'center',align:'left'}
                                            ]],
										" editable="true" 
                                    >
									</select>
									<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#cmb_tax2').combobox('clear')"></a>
                                </td>
                            </tr>
                           <!-- <tr>
                                <td></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <input type="checkbox" name="chk_termsdefaultinvoice" value="1" style="margin-left:0px;" /> Default Invoice is Tax Included 
                                </td>
                            </tr>-->
                            <tr>
                                <td><b>Out Standing</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <input type="text" class="easyui-numberbox" name="txt_vendor_balance" id="txt_vendor_balance" value="0" style="width:822px;" readonly />
                                	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" onclick="modal_open('Select Vendor Balance','dialog-vendor-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" value="0" formatter="formatRp" style="width:852px;" 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>Vendor 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><b>Vendor Tax No / NPWP</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <input type="text" name="txt_termsvendortaxno" style="width:852px;" />
                                </td>
                            </tr>
                            <tr>
                                <td><b>PKP No.</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <input type="text" name="txt_termspkpno" style="width:852px;"/>
                                </td>
                            </tr>
                            <tr>
                                <td><b>Tax Type</b></td>
                                <td width="850" style="padding:1px 0px 2px;">
                                    <select id="cmb_taxtype" name="cmb_taxtype"
                                    	class="combo-grid"
                                        style="width:822px" 
										data-options="
											idField:'TaxTypeID',
											textField:'TaxTypeName',
											url:'<?php echo base_url(); ?>custom/get_data/taxtype',
                                            method: 'get',
                                            columns: [[
                                                {field:'TaxTypeID',title:'Taxes Type ID',width:370,halign:'center',align:'left'},
                                                {field:'TaxTypeName',title:'Taxes Type Name',width:430,halign:'center',align:'left'}
                                            ]],
										" editable="true" 
                                    >
									</select>
									<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#cmb_taxtype').combobox('clear')"></a>
                                </td>
                            </tr>
                            </table>
                        </fieldset>
                    </div>
                    <div id="tab_notes" title="Notes">
                    	<textarea rows="18" 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)" class="easyui-linkbutton form-button" iconCls="icon-save" onclick="save_me()" <?php echo $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>



<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);
            }
        });
	/*$('#dg_purchase_invoice').datagrid({
		onBeginEdit:function(rowIndex){
			editors = $('#dg_purchase_invoice').datagrid('getEditors',rowIndex);
			date_editor		= $(editors[2].target);
			tanggal_grid 	 = $(date_editor).val();
			alert(date_editor);
			 //$('#date_inv').val(tanggal_grid);
		}
	});*/
	
	/*$('#save_vendors').click(function(){
		if($('#cmb_terms').combobox('getValue') == ''){
			$.messager.alert('Info','Terms pada tab Terms, etc harus di isi');
		}
		else if($('#cmb_currency').combobox('getValue') == ''){
			$.messager.alert('Info','Currency pada tab Terms, etc harus di isi');
		}*/
		/* else if($('#cmb_taxtype').combobox('getValue') == ''){
			$.messager.alert('Info','Tax Type pada tab Terms, etc harus di isi');
		} */
		/*else{
			$('#dg_purchase_invoice').edatagrid('saveRow');
			var i=$('#dg_purchase_invoice').datagrid('getRows');
			var detail = JSON.stringify(i);
			$("#detail").val(detail);
			save_transaction('<?php echo $menu_link?>','#fm_vendor');
		}
	});*/
	
	$("#form-vendor-balance").click(function(){
		$("#tt-vendor-balance").edatagrid('saveRow');
	});
	
	$('#txt_address').keyup(function(){
		text = $(this).val();
		$('#txa_vendor_addres').val(text);
	});
	
	$('#dialog-vendor-balance').click(function(){
		$('#dg_purchase_invoice').edatagrid('saveRow');
	});
	
});

function getkey(e){
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}

function goodchars(e, goods, field){
	var key, keychar;
	key = getkey(e);
	if (key == null) return true;
	
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods 	= goods.toLowerCase();
	
	// check goodkeys
	if (goods.indexOf(keychar) != -1)
		return true;
	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==27 )
	   return true;
	   
	if (key == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	};
	// else return false
	return false;
}

function choose_vendor_balance(){
	var item = $('#dg_purchase_invoice').datagrid('getRows');
	var sub_total   = 0;
	
	$.each(item, function( index, value ) {
		if(value.OutStanding != undefined){
			sub_total+= parseFloat(value.OutStanding);
		}				
	});

	$('#txt_vendor_balance').numberbox('setValue',sub_total);
	
	//$.post('',{SInvNumber:value.SInvNUmber,SInvDate:value.SInvDate,SInvTotalAmount:CustBalance});
	modal_close('dialog-vendor-balance');
}

function duplicate_outstanding(){
	var limit_out 			= $('#txt_outstanding').val();
	var limitToAngka_out	= toAngka(limit_out);
	$('#txt_outstanding_hidden').val(limitToAngka_out);
}

function save_me(){
	if($('#txt_vendorname').val() == ""){
		 $.messager.alert('Warning','Vendor Name tidak boleh kosong, silahkan lengkap','warning',function(){
		});		
	}
	else if($('#txt_address').val() == ""){
		 $.messager.alert('Warning','Vendor Addres tidak boleh kosong, silahkan lengkap','warning',function(){
		});	
	}
	else if($('#cmb_city').combogrid('getValue') == ""){
		 $.messager.alert('Warning','City/Prov/Zip Code tidak boleh kosong, silahkan lengkap','warning',function(){
		});	
	}
	else if($('#txt_phone').val() == ""){
		 $.messager.alert('Warning','Phone tidak boleh kosong, silahkan lengkap','warning',function(){
		});	
	}
	else if($('#txt_contactperson').val() == ""){
		 $.messager.alert('Warning','Contact Person tidak boleh kosong, silahkan lengkap','warning',function(){
		});	
	}
	else if($('#cmb_terms').combogrid('getValue') == ""){
		 $.messager.alert('Warning','Terms tidak boleh kosong, silahkan lengkap','warning',function(){
		});	
	}
	else if($('#cmb_currency').combogrid('getValue') == ""){
		 $.messager.alert('Warning','Currency tidak boleh kosong, silahkan lengkap','warning',function(){
		});	
	}
	else{
		save_transaction('<?php echo $menu_link?>','#fm_vendor');
	}
	
}
</script>