<script type="text/javascript"> 
lblInvCompName = "<%=l(:field_name) %>";
lblInvCompVal = "<%=l(:field_value) %>";
</script>
<% @ledgers = ["", ""] %> 
<% @ledgers << WkLedger.order(:name).pluck(:name, :id) %> 
<%  ledgerhash = Hash[*@ledgers.flatten].invert %>
<fieldset>
	<%
		wktime_helper = Object.new.extend(WktimeHelper)
		user_custom_fields = UserCustomField.order('name')
		cfUserRateF = wktime_helper.getCfListArr(user_custom_fields, 'float', true)
		cfUserRateI = wktime_helper.getCfListArr(user_custom_fields, 'int', false)
		cfUserRate = (cfUserRateF + cfUserRateI).uniq
		cfUserCurrency = wktime_helper.getCfListArr(user_custom_fields, 'string', true)
		
		project_custom_fields = ProjectCustomField.order('name')
		cfProjRateF = wktime_helper.getCfListArr(project_custom_fields, 'float', true)
		cfProjRateI = wktime_helper.getCfListArr(project_custom_fields, 'int', false)
		cfProjRate = (cfProjRateF + cfProjRateI).uniq
		cfProjCurrency = wktime_helper.getCfListArr(project_custom_fields, 'string', true)
		
		issue_custom_fields = IssueCustomField.order('name')
		cfIssueRateF = wktime_helper.getCfListArr(issue_custom_fields, 'float', true)
		cfIssueRateI = wktime_helper.getCfListArr(issue_custom_fields, 'int', false)
		cfIssueRate = (cfIssueRateF + cfIssueRateI).uniq
		cfIssueCurrency = wktime_helper.getCfListArr(issue_custom_fields, 'string', true)
		
		te_custom_fields = TimeEntryCustomField.order('name')
		cfBillIndicator = wktime_helper.getCfListArr(te_custom_fields, 'int', true)
		
		hash_invoice_period = { 'q' =>  l(:label_quarterly), 'm'  => l(:label_monthly), 'bw' =>  l(:label_bi_weekly), 'w' => l(:label_weekly) }
		
		hr = []
				for i in 1..31
					if i < 10
						hr << ['0' + i.to_s,i]
					else
						hr << [i,i]
					end
				end
	%>
	<legend><%= l(:label_wk_billing) %></legend>
	
	
	<p>
			<%= check_box_tag('settings[invoice_auto_post_gl]', 1, @settings['invoice_auto_post_gl'].to_i == 1) %> <label><%= l(:label_auto_post_gl) %></label>
	</p>

	<p><label><%= l(:label_credit_with_ledger)  %></label>
	    <%= select_tag 'settings[invoice_cr_ledger]', options_for_select(ledgerhash.invert, :selected => @settings['invoice_cr_ledger']) %></p>
	
	<p><label><%= l(:label_debit_with_ledger)  %></label>
	    <%= select_tag 'settings[invoice_db_ledger]', options_for_select(ledgerhash.invert, :selected => @settings['invoice_db_ledger']) %></p>
	
	<p><label><%= l(:label_txn_payment_with_credit_with_ledger)  %></label>
	    <%= select_tag 'settings[payment_cr_ledger]', options_for_select(ledgerhash.invert, :selected => @settings['payment_cr_ledger']) %></p>
	
	<p><label><%= l(:label_txn_payment_with_debit_with_ledger)  %></label>
	    <%= select_tag 'settings[payment_db_ledger]', options_for_select(ledgerhash.invert, :selected => @settings['payment_db_ledger']) %></p>
		
<!--	<p><label><%#= l(:label_txn_payment) + " " + l(:label_fluctuation) + " " +  l(:label_ledger)  %></label>
	    <%#= select_tag 'settings[payment_fluctuation_ledger]', options_for_select(ledgerhash.invert, :selected => @settings['payment_fluctuation_ledger']) %></p> -->
		
	<%= l(:label_redmine_restart_warning) %>
	<p>
			<%= check_box_tag('settings[wktime_auto_generate_invoice]', 1, @settings['wktime_auto_generate_invoice'].to_i == 1) %> <label><%= l(:label_auto_generate_invoice) %></label>
	</p>
	<p><label><%= l(:label_invoice_generate_period) %></label>
		<%= select_tag 'settings[wktime_generate_invoice_period]', options_for_select(hash_invoice_period.invert, :selected => @settings['wktime_generate_invoice_period']) %>
	</p>
	<p>
		  <label><%= l(:label_contract_no_prefix) %></label><%= text_field_tag 'settings[wktime_contract_no_prefix]', @settings['wktime_contract_no_prefix'], :size => 13 %> 
	</p>
	<p>	
			<label><%= l(:label_invoice_generation_day) %></label>
			<%= select_tag('settings[wktime_generate_invoice_day]', options_for_select([[l('date.day_names')[0], 0],
										   [l('date.day_names')[1], 1],
										   [l('date.day_names')[2], 2],
										   [l('date.day_names')[3], 3],
										   [l('date.day_names')[4], 4],
										   [l('date.day_names')[5], 5],
										   [l('date.day_names')[6], 6]], :selected => @settings['wktime_generate_invoice_day']))%>

	</p>   
  <p>	
			<label><%= l(:label_invoice_generation_month) %></label>			
			<%=h select_tag('settings[wktime_generate_invoice_month_start]', options_for_select(hr, :selected => @settings['wktime_generate_invoice_month_start']) ) %></td>
	</p>  
	
	<p>
		  <label><%= l(:label_invoice_no_prefix) %></label><%= text_field_tag 'settings[wktime_invoice_no_prefix]', @settings['wktime_invoice_no_prefix'], :size => 13 %> 
	</p>
	<p>
		<label><%= l(:label_generate_invoice_from) %> </label><%=h date_field_tag('settings[wktime_generate_invoice_from]',@settings['wktime_generate_invoice_from'],:size => 10) %> <%= calendar_for('settings_wktime_generate_invoice_from') %>
	</p>
	<!-- <p>
		<label><%#= l(:label_billing_id) %> </label><%#=h select_tag('settings[wktime_billing_id_cf]', 
			options_for_select(cfBillIndicator, :selected =>  @settings['wktime_billing_id_cf'])) %>
	</p> -->
	<!--
	<p>
		<label><%#= l(:label_user_billing_rate) %> </label><%#=h select_tag('settings[wktime_user_billing_rate_cf]', 
			options_for_select(cfUserRate, :selected =>  @settings['wktime_user_billing_rate_cf'])) %>
	</p>
	<p>
		<label><%#= l(:label_user_billing_currency) %> </label><%#=h select_tag('settings[wktime_user_billing_currency_cf]', 
			options_for_select(cfUserCurrency, :selected =>  @settings['wktime_user_billing_currency_cf'])) %>
	</p>
	-->
	<!--
	<p>
		<label><%#= l(:label_issue_billing_currency) %> </label><%#=h select_tag('settings[wktime_issue_billing_currency_cf]', 
			options_for_select(cfIssueCurrency, :selected =>  @settings['wktime_issue_billing_currency_cf'])) %>
	</p>
	<p>
		<label><%#= l(:label_issue_billing_rate) %> </label><%#=h select_tag('settings[wktime_issue_billing_rate_cf]', 
			options_for_select(cfIssueRate, :selected =>  @settings['wktime_issue_billing_rate_cf'])) %>
	</p>
	-->
</fieldset>