<%= javascript_include_tag 'payrollsettings', :plugin => "redmine_wktime" %>
<%= title l(:label_payroll_settings) %>
<div class="contextual">
	<%= render :partial => 'sidebar' %>
</div>
<%= render partial: "wkattendance/render_hr_tabs" %>
<script type="text/javascript">
	payroll_name = "<%=l(:label_basic_name) %>";
	payroll_name_errormsg = "<%=l(:label_name_errormsg) %>";
	payroll_date_errormsg = "<%=l(:label_date_errormsg) %>";
	payroll_factor_errormsg = "<%=l(:label_factor_errormsg) %>";
	payroll_condition_errormsg = "<%=l(:label_condition_errormsg) %>";
	lblcreditLedger = "<%= l(:label_credit_with_ledger) %>";
	lbldebitLedger = "<%= l(:label_debit_with_ledger) %>";
	selectListAlertMsg = "<%=l(:actionview_instancetag_blank_option) %>";
	attendanceAlertMsg = "<%= l(:text_are_you_sure) %>";
	label_basic = "<%= l(:label_basic) %>";
	label_allowances = "<%= l(:label_allowances) %>";
	label_deduction = "<%= l(:label_deduction) %>";
	label_calculated_fields = "<%= l(:label_calculated_fields) %>";
	equalOpAlertMsg = "<%= l(:alert_eq_operator) %>";
	label_reimburse = "<%= l(:label_reimbursements) %>";
</script>

<%= form_tag({:controller => controller_name, :action => 'payrollsettings'}, :method => :post) do %>
	<%= hidden_field_tag 'settings[comp_del_ids]', "" %>
	<%= hidden_field_tag 'settings[dep_del_ids]', "" %>
	<%= hidden_field_tag 'settings[cond_del_ids]', "" %>
	<fieldset>
		<table><tr>
			<td><label><%= l(:label_basic) %></label></td>
			<td><%=  select_tag('settings[basic]',
					options_for_select(@payrollsettings['basic']), :multiple=> true, :style => "width:390px; height:18px;")%></td>

			</tr>
			<tr>
				<td></td>
				<td>
					<%= link_to l(:button_add), "javascript:payrollDialogAction('settings_basic', 'Add');", :class => "button", :id => "basic_add"%>
					<%= link_to l(:button_edit), "javascript:payrollDialogAction('settings_basic', 'Edit');", :class => "button"%>
				</td>
			</tr>
			<tr>
			<td><label><%= l(:label_allowances) %></label></td>
			<td><%=  select_tag('settings[allowances]',
					options_for_select(@payrollsettings["allowances"]), :multiple=> true, :style => "width:390px; height:80px;")%></td>

			</tr>
			<tr>
				<td></td><td><%= link_to l(:button_add), "javascript:payrollDialogAction('settings_allowances', 'Add');", :class => "button"%>  |
				<%= link_to l(:button_edit), "javascript:payrollDialogAction('settings_allowances', 'Edit');", :class => "button"%>  |
				<%= link_to l(:button_delete), "javascript:removeSelectedValue('settings_allowances');", :class => "button" %></td>
			</tr>
			<tr>
				<td><label><%= l(:label_deduction) %></label></td>
				<td><%=  select_tag('settings[deduction]',
					options_for_select(@payrollsettings["deduction"]), :multiple=> true, :style => "width:390px; height:80px;")%></td>
			</tr>
			<tr>
				<td></td><td><%= link_to l(:button_add), "javascript:payrollDialogAction('settings_deduction', 'Add');", :class => "button"%>  |
				<%= link_to l(:button_edit), "javascript:payrollDialogAction('settings_deduction', 'Edit');", :class => "button"%>  |
				<%= link_to l(:button_delete), "javascript:removeSelectedValue('settings_deduction');", :class => "button" %></td>
			</tr>
			<tr>
				<td><label><%= l(:label_calculated_fields) %></label></td>
				<td><%=  select_tag('settings[calculated_fields]',
					options_for_select(@payrollsettings["calculated_fields"]), :multiple=> true, :style => "width:390px; height:80px;")%></td>
			</tr>
			<tr>
				<td></td>
				<td>
					<%= link_to l(:button_add), "javascript:payrollDialogAction('settings_calculated_fields', 'Add');", :class => "button"%>  |
					<%= link_to l(:button_edit), "javascript:payrollDialogAction('settings_calculated_fields', 'Edit');", :class => "button"%>  |
					<%= link_to l(:button_delete), "javascript:removeSelectedValue('settings_calculated_fields');", :class => "button" %>
				</td>
			</tr>
			<tr>
				<td><label><%= l(:label_reimbursements) %></label></td>
				<td><%=  select_tag('settings[reimburse]', options_for_select(@payrollsettings["reimburse"]), :multiple=> true, :style => "width:390px; height:20px;")%></td>
			</tr>
			<tr>
				<td></td>
				<td>
					<%= link_to l(:button_add), "javascript:payrollDialogAction('settings_reimburse', 'Add');", :class => "button", :id => "reimburse_add"%>
					<%= link_to l(:button_edit), "javascript:payrollDialogAction('settings_reimburse', 'Edit');", :class => "button"%> |
					<%= link_to l(:button_delete), "javascript:removeSelectedValue('settings_reimburse');", :class => "button"%>
				</td>
			</tr>
			<tr>
				<td><label><%= l(:label_tax_rule) %></label></td>
				<td><%= select_tag 'taxsettings[tax_rule]', options_for_select(get_tax_rule.unshift(['','']), getTaxSettings('tax_rule')) %></td>
			</tr>
			<tr>
				<td><label><%= l(:label_income_tax) %></label></td>
				<td><%= select_tag 'taxsettings[income_tax]', options_for_select(getSalaryCompNames.invert, getTaxSettings('income_tax')) %></td>
			</tr>
			</table>
	</fieldset>

	<div><%= submit_tag l(:button_apply), :class => 'button-small', :name => 'submit' %></div>
<% end %>
<div id="payroll-dlg" style="padding-right: 25px;" >
	<div class="box tabular" style="width: 100%;">

		<%= hidden_field_tag("salaryCompID","") %>
		<%= hidden_field_tag("basicCompDepID","") %>
		<p>
			<label><%= l(:field_name) %></label><%= text_field_tag 'name', "", :maxlength => 50 %>
		</p>

		<p id = "payroll_frequency">
			<label><%= l(:label_frequency) %></label>
			<%= select_tag 'frequency', options_for_select(getSalaryFrequency.invert) %>
		</p>

		<p id="payroll_start_date">
			<label><%= l(:field_start_date) %></label>
			<%= date_field_tag('start_date', "", {:id => 'start_date', :size => 12, :style => "width:130px; "}) + calendar_for('start_date') %>
		</p>

		<p id="basic_salary_type">
			<label><%= l(:label_salary_type) %></label>
			<%= select_tag 'salary_type', options_for_select(getSalaryType.invert)%>
		</p>

		<p id="basic_factor">
			<label><%= l(:label_factor) %></label><%= text_field_tag 'basic_field_factor', "", :maxlength => 7 %>
		</p>
		<% if showAccounting %>
			<p id="payrollDBLedger">
				<label id="ledgersLabel"><%= l(:label_debit_with_ledger) %></label>

				<%= select_tag 'db_ledger', options_for_select(getLedgerNames.invert) %>
			</p>
		<% end %>

		<p id="calculatedFieldsType" style="display:none">
			<label id="TypeLabel"><%= l(:field_type)  %></label>
			<%= select_tag 'calculated_fields_type', options_for_select(get_calculated_field_types) %>
		</p>
	</div>
	<div id="addDeps">
		<div id="salaryCompDeps"></div>
		<p style="float: right;">
			<%= link_to l(:button_add), "#", {onclick: "javascript:addDependent()", class: 'icon icon-add'} %>
		</p>
	</div>
</div>

<div id="compDepTemplate" style="display: none;">
	<div id="compDep_INDEX" class="box tabular compDep" style="width: 100%;">
		<table style="width: 100%;">
			<tr>
				<th></th>
				<th style="font-weight:normal;"><%= l(:label_component) %></th>
				<th></th>
				<th style="font-weight:normal;"><%= l(:label_factor) %></th>
				<th colspan="6"></th>
			</tr>
			<tr>
				<td valign="justify" style="font-weight:normal">
					<label style="padding-left: 90px;font-weight: normal;"><%= l(:label_dependent) %></label>
					<%= hidden_field_tag("compDepID_INDEX","") %>
				</td>
				<td><%= select_tag('depID_INDEX', options_for_select(getSalaryCompNames.invert), class: "component depElements", style: "width: 125px") %></td>
				<td align="center"><%= select_tag('factorOp_INDEX', options_for_select(getFactorOperators), class: "depElements") %></td>
				<td><%= text_field_tag('factor_INDEX', "", size: 5, maxlength: 7, class: "depElements") %></td>

				<td valign="justify" style="font-weight:normal;padding-left: 20px;"><%= l(:label_if) %><%= hidden_field_tag("compDepConID_INDEX","") %></td>
				<td><%= select_tag('condDepID_INDEX', options_for_select(getSalaryCompNames.invert), class: "component condElements_INDEX", style: "width: 125px") %></td>
				<td>
					<%= select_tag('condOp_INDEX', options_for_select(getLogicalCond), class: "condElements_INDEX",
					onchange: "showFactor(this);", style: "width: 50px") %>
				</td>

				<td><%= text_field_tag('condFactor_INDEX', "", size: 5, maxlength: 7, class: "condElements_INDEX") %></td>
				<td><%= text_field_tag('condFactor2_INDEX', "", size: 5, maxlength: 7, class: "condElements_INDEX") %></td>
				<td><%= link_to image_tag('delete.png'), "javascript:deleterow(INDEX);", :title => l(:button_delete) %></td>
			</tr>
		</table>
	</div>
</div>