{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
<H1>{$layout.pagetitle}</H1>

<style>

	#consent-table {
		padding-right: 2em;
	}

	#consent-table > .lmsbox-inner {
		border: 1px dotted black;
	}

	#consent-table > .lmsbox-inner > tfoot {
		border: 0;
	}

	#consent-table > .lmsbox-inner .in-consent-group > td:first-child {
		padding-left: 2em;
	}

	#balance-days-container {
		margin-top: 0.5em;
	}

	#balance-days-container > label {
		float: left;
	}

	#balance-days-container > *:not(:last-child) {
		margin-left: 0.5em;
	}

	#assignment-properties {
		display: flex;
		flex-direction: column;
	}

	#assignment-properties > div {
		display: flex;
		padding-top: 0.5em;
		padding-bottom: 0.5em;
	}

	.reverse-elements {
		display: flex;
		flex-direction: row-reverse;
	}

	.reverse-elements > :not(:first-child) {
		margin-right: 0.5em;
	}

	.document-filters {
		display: flex;
		flex-direction: column;
	}

	.document-filter {
		display: flex;
		align-items: center;
		margin: 0.3em 0 0.3em 0;
	}

	.document-filter > :not(:first-child) {
		margin-left: 0.3em;
	}

</style>

<script>

	function PrintList() {
		document.customersearch.action = "?m=customersearch&search=1&print=1";
		document.customersearch.target = "_BLANK";
		document.customersearch.submit();
	}

	function ExportCSV() {
		document.customersearch.action = "?m=customersearch&search=1&export=1";
		document.customersearch.target = "_BLANK";
		document.customersearch.submit();
	}

	function Search() {
		document.customersearch.action = "?m=customersearch&search=1";
		document.customersearch.target = "";
		document.customersearch.submit();
	}

	function change_linktype(linktype) {
		var options = document.getElementById('linktechnology').options;
		while (options.length)
			options.remove(0);
		options.add(new Option('{trans("— none —")}', ''));
		options.add(new Option("{trans("— without technology —")}", 0));
		switch (linktype) {
			case '':
				{foreach array({$smarty.const.LINKTYPE_WIRE}, {$smarty.const.LINKTYPE_WIRELESS}, {$smarty.const.LINKTYPE_FIBER}) as $linktype}
					{foreach $_LINKTECHNOLOGIES[$linktype] as $linktechnologyidx => $linktechnology}
					options.add(new Option('{$linktechnology}', {$linktechnologyidx}));
					{/foreach}
				{/foreach}
				break;
			case '0':
				{foreach $_LINKTECHNOLOGIES[$smarty.const.LINKTYPE_WIRE] as $linktechnologyidx => $linktechnology}
				options.add(new Option('{$linktechnology}', {$linktechnologyidx}));
				{/foreach}
				break;
			case '1':
				{foreach $_LINKTECHNOLOGIES[$smarty.const.LINKTYPE_WIRELESS] as $linktechnologyidx => $linktechnology}
				options.add(new Option('{$linktechnology}', {$linktechnologyidx}));
				{/foreach}
				break;
			case '2':
				{foreach $_LINKTECHNOLOGIES[$smarty.const.LINKTYPE_FIBER] as $linktechnologyidx => $linktechnology}
				options.add(new Option('{$linktechnology}', {$linktechnologyidx}));
				{/foreach}
				break;
		}
	}

</script>
<FORM method="post" action="?m=customersearch&amp;search=1" name="customersearch" id="customersearch">
<INPUT type="submit" class="hiddenbtn">
<TABLE class="lmsbox">
	<colgroup>
		<col style="width: 1%;">
		<col style="width: 99%;">
	</colgroup>
	<THEAD>
	<TR>
		<TD colspan="2" class="bold">
			{trans("Display customers matching the following criteria:")}
		</TD>
	</TR>
	</THEAD>
	<TBODY>
	<tr>
		<td class="nobr">
			{icon name="spacer"}
			<strong>{trans("Qualification operator")}</strong>
		</td>
		<td>
			<label>
				<input type="radio" value="AND" name="k"{if $k != 'OR'} checked{/if}>
				{trans("and")}
			</label>
			<label>
				<input type="radio" value="OR" name="k"{if $k == 'OR'} checked{/if}>
				{trans("or")}
			</label>
		</td>
	</tr>
	<tr>
		<td class="bold nobr">
			<label for="hidessn">
				{icon name="id"}
				{trans("hide customer SSN")}
			</label>
		</td>
		<td>
			<input type="hidden" name="hidessn" value="0">
			<input type="checkbox" name="hidessn" id="hidessn" value="1"
				{if !empty($listdata.hidessn) || !isset($listdata.hidessn)} checked{/if}>
		</td>
	</tr>
	<TR>
		<TD class="bold nobr">
			{icon name="customer"} {trans("First/last or Company name:")}
		</TD>
		<TD>
			<input type="text" name="search[customername]" value="{$search.customername}">
			<label>
				<input type="checkbox" name="search[customernamestartingwith]" value="1"
					{if !empty($search.customernamestartingwith)} checked{/if}>
				{trans("starting with")}
			</label>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="karma"} {trans("Karma:")}
		</TD>
		<TD>
			<INPUT type="text" name="search[karma]" VALUE="{$search.karma}"
				{tip text="Negative value means customers with karma less or equal than specified, but positive means greater or equal then specified"}>
		</TD>
	</TR>
	<TR>
		<TD style="width: 1%;" class="bold nobr">
			{icon name="home"} {trans("Address:")}
		</TD>
		<TD style="width: 99%;" class="nobr">
			<INPUT type="text" name="search[address]" VALUE="{$search.address}">
			<span class="bold">{trans("City:")}</span> <INPUT type="text" name="search[city]" VALUE="{$search.city}">
			<span class="bold">{trans("Postcode:")}</span> <INPUT type="text" name="search[zip]" VALUE="{$search.zip}" SIZE="10">
			<span class="bold">{trans("Address type:")}</span>
			<SELECT name="search[addresstype]">
				<OPTION value="">{trans("— all —")}</OPTION>
				<OPTION value="{$smarty.const.BILLING_ADDRESS}">{trans("settlement<!addresstype>")}</OPTION>
				<OPTION value="{$smarty.const.POSTAL_ADDRESS}">{trans("postal")}</OPTION>
				<OPTION value="{$smarty.const.LOCATION_ADDRESS}">{trans("localisation<!addresstype>")}</OPTION>
			</SELECT>
		</TD>
	</TR>
	<TR>
		<TD class="nobr">
			<label for="phone">
				{icon name="phone"}
				<strong>{trans("Phone")}</strong>
			</label>
		</TD>
		<TD class="nobr">
			<INPUT type="tel" name="search[phone]" id="phone" VALUE="{$search.phone}">
			<label>
				<input type="checkbox" name="search[without-phone]" value="1" class="without-contact">
				{trans("without phone contact")}
			</label>
		</TD>
	</TR>
	<TR>
		<TD class="nobr">
			<label for="email">
				{icon name="mail"}
				<strong>{trans("E-mail")}</strong>
			</label>
		</TD>
		<TD>
			<INPUT type="text" name="search[email]" id="email" VALUE="{$search.email}">
			<label>
				<input type="checkbox" name="search[without-email]" value="1" class="without-contact">
				{trans("without e-mail contact")}
			</label>
		</TD>
	</TR>
	{*
	<TR>
		<TD class="bold nobr">
			<IMG src="img/gg.gif" alt=""> {trans("IM:")}
		</TD>
		<TD>
			<INPUT type="text" name="search[im]" VALUE="{$search.im}">
		</TD>
	</TR>
	*}

	<TR>
		<TD class="nobr bold">
			{icon name="user-id-number"} {trans("Identity type:")}
		</TD>
		<TD>
			{identitytypes elemname="search[ict]" selected=$search.ict}
		</TD>
	</TR>
	<tr>
		<td class="nobr">
			<span class="customer-property-label">
				<strong>
					{icon name="user-id-number"}
					{trans("Identity number")}
				</strong>
			</span>
		</td>
		<td>
			<input type="text" name="search[icn]" value="{$search.icn}" data-customer-property="icn">
			<span style="display: none;"></span>
			<label>
				<input type="radio" name="icn-match-selector" data-controlled-customer-property="icn" value="=" checked>
				<span>{trans("given value")}</span>
			</label>
			<label>
				<input type="radio" name="icn-match-selector" data-controlled-customer-property="icn" value="*">
				<span>{trans("non-empty")}</span>
			</label>
			<label>
				<input type="radio" name="icn-match-selector" data-controlled-customer-property="icn" value="-">
				<span>{trans("empty")}</span>
			</label>
			<input type="hidden" name="search[icn]" data-customer-property="icn"
				value="*"{if $search.icn != '*'} disabled{/if}>
			<input type="hidden" name="search[icn]" data-customer-property="icn"
				value="-"{if $search.icn != '-'} disabled{/if}>
		</td>
	</tr>

	<tr>
		<td class="nobr">
			<label for="ic-expired">
				{icon name="calendar"}
				<strong>{trans("Expired identity card")}</strong>
			</label>
		</td>
		<td>
			<input type="checkbox" name="search[ic-expired]" id="ic-expired"
				value="1" {if !empty($search['ic-expired'])} checked{/if}
		</td>
	</tr>

	<tr>
		<td class="nobr">
			<span class="customer-property-label">
				<strong>
					{icon name="user-id-number"}
					{trans("SSN")}
				</strong>
			</span>
		</td>
		<td>
			<input type="text" name="search[ssn]" value="{$search.ssn}" data-customer-property="ssn">
			<span style="display: none;"></span>
			<label>
				<input type="radio" name="ssn-match-selector" data-controlled-customer-property="ssn" value="=" checked>
				<span>{trans("given value")}</span>
			</label>
			<label>
				<input type="radio" name="ssn-match-selector" data-controlled-customer-property="ssn" value="*">
				<span>{trans("non-empty")}</span>
			</label>
			<label>
				<input type="radio" name="ssn-match-selector" data-controlled-customer-property="ssn" value="-">
				<span>{trans("empty")}</span>
			</label>
			<input type="hidden" name="search[ssn]" data-customer-property="ssn"
				value="*"{if $search.ssn != '*'} disabled{/if}>
			<input type="hidden" name="search[ssn]" data-customer-property="ssn"
				value="-"{if $search.ssn != '-'} disabled{/if}>
		</td>
	</tr>
	<tr>
		<td class="bold nobr">
			<span class="customer-property-label">
				<strong>
					{icon name="user-id-number"}
					{trans("TEN")}
				</strong>
			</span>
		</td>
		<td>
			<input type="text" name="search[ten]" data-customer-property="ten"
				{if $search.ten != '*'} value="{$search.ten}"{else} disabled{/if}>
			<span style="display: none;"></span>
			<label>
				<input type="radio" name="ten-match-selector" data-controlled-customer-property="ten" value="=" checked>
				<span>{trans("given value")}</span>
			</label>
			<label>
				<input type="radio" name="ten-match-selector" data-controlled-customer-property="ten" value="*">
				<span>{trans("non-empty")}</span>
			</label>
			<label>
				<input type="radio" name="ten-match-selector" data-controlled-customer-property="ten" value="-">
				<span>{trans("empty")}</span>
			</label>
			<input type="hidden" name="search[ten]" data-customer-property="ten"
				value="*"{if $search.ten != '*'} disabled{/if}>
			<input type="hidden" name="search[ten]" data-customer-property="ten"
				value="-"{if $search.ten != '-'} disabled{/if}>
		</td>
	</tr>
	<TR>
		<TD class="bold nobr">
			{icon name="user-id-number"} {trans("REGON:")}
		</TD>
		<TD>
			<INPUT type="text" name="search[regon]" VALUE="{$search.regon}">
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="user-id-number"} {trans("RBE:")}
		</TD>
		<TD>
			<INPUT type="text" name="search[rbe]" VALUE="{$search.rbe}">
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="notes"} {trans("Notes:")}
		</TD>
		<TD>
			<INPUT type="text" name="search[notes]" VALUE="{$search.notes}">
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="optional-info"} {trans("Additional information:")}
		</TD>
		<TD>
			<INPUT type="text" name="search[info]" VALUE="{$search.info}">
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="legal-personality"} {trans("Legal personality:")}
		</TD>
		<TD>
			<SELECT SIZE="1" name="search[type]">
				<OPTION VALUE="">{trans("— all —")}</OPTION>
				<OPTION VALUE="0">{trans("private person")}</OPTION>
				<OPTION VALUE="1">{trans("legal entity")}</OPTION>
			</SELECT>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="legal-personality"} {trans("Flags:")}
		</TD>
		<TD>
			<input type="hidden" name="flags[]" value="0">
			<select name="flags[]" {tip text="Select customer flags (optional)" class="lms-ui-multiselect"}
					multiple data-default-value="{trans("— all —")}">
				{foreach Localisation::arraySort($_CUSTOMERFLAGS, 'label') as $cflag => $flag}
					<option value="{$cflag}" title="{$flag.tip}">{$flag.label}</option>
				{/foreach}
			</select>
			<label>
				<INPUT class="radio" type="radio" value="AND" name="fk"{if $fk != 'OR'} checked{/if}>
				{trans("and")}
			</label>
			<label>
				<INPUT class="radio" type="radio" value="OR" name="fk"{if $fk == 'OR'} checked{/if}>
				{trans("or")}
			</label>
		</TD>
	</TR>

	<TR>
		<TD class="bold nobr">
			{icon name="consent"} {trans("Consents:")}
		</TD>
		<TD id="consent-table">
			<table class="lmsbox-inner lms-ui-background-cycle">
				<colgroup>
					<col style="width: 70%;">
					<col style="width: 30%;">
				</colgroup>
				<tbody>
					{$in_consent_group = false}
					{foreach $_CCONSENTS as $consentid => $consent}
						{if !is_array($consent)}
							{continue}
						{/if}

						{$customer_consent_group_id = Utils::findCustomerConsentGroupByCustomerConsent($consentid, $_CCONSENT_GROUPS)}
						{if $current_customer_consent_group_id && $current_customer_consent_group_id != $customer_consent_group_id || $current_customer_consent_group_id && $consent@last}
							{$in_consent_group = false}
						{/if}
						{if $customer_consent_group_id && $customer_consent_group_id != $current_customer_consent_group_id}
							<tr class="superdark">
								<td colspan="2" class="superdark">
									<strong>{$_CCONSENT_GROUPS[$customer_consent_group_id].label}</strong>
								</td>
							</tr>
							{$in_consent_group = true}
						{/if}

						{if $consent.type == 'selection'}
							{foreach $consent.values as $subconsentid => $subconsent}
								{if !isset($subconsent.name)}
									{continue}
								{/if}
								<tr class="highlight{if $in_consent_group} in-consent-group{/if}">
									<td>
										{t a=$consent.label b=$subconsent.label}$a ($b){/t}
									</td>
									<td>
										<label>
											<input type="radio" class="cconsent" name="consents[{$subconsentid}]" value="-1"
													{if !isset($consents[$subconsentid]) || $consents[$subconsentid] == -1} checked{/if}>
											{trans("ignore")}
										</label>
										<label>
											<input type="radio" class="cconsent" name="consents[{$subconsentid}]" value="1"
													{if isset($consents[$subconsentid]) && $consents[$subconsentid] == 1} checked{/if}>
											{trans("yes")}
										</label>
										<label>
											<input type="radio" class="cconsent" name="consents[{$subconsentid}]" value="0"
													{if isset($consents[$subconsentid]) && $consents[$subconsentid] == 0} checked{/if}>
											{trans("no")}
										</label>
									</td>
								</tr>
							{/foreach}
						{else}
							<tr class="highlight{if $in_consent_group} in-consent-group{/if}">
								<td>
									{$consent.label}
								</td>
								<td>
									<label>
										<input type="radio" class="cconsent" name="consents[{$consentid}]" value="-1"
											{if !isset($consents[$consentid]) || $consents[$consentid] == -1} checked{/if}>
										{trans("ignore")}
									</label>
									<label>
										<input type="radio" class="cconsent" name="consents[{$consentid}]" value="1"
												{if isset($consents[$consentid]) && $consents[$consentid] == 1} checked{/if}>
										{trans("yes")}
									</label>
									<label>
										<input type="radio" class="cconsent" name="consents[{$consentid}]" value="0"
												{if isset($consents[$consentid]) && $consents[$consentid] == 0} checked{/if}>
										{trans("no")}
									</label>
								</td>
							</tr>
						{/if}
						{$current_customer_consent_group_id = $customer_consent_group_id}
					{/foreach}
				</tbody>
				<tfoot>
					<tr class="dark">
						<td colspan="2" class="text-center">
							{button icon="reload" label="Reset" id="reset-consents"}
						</td>
					</tr>
				</tfoot>
			</table>
		</TD>
	</TR>

	<TR>
		<TD class="bold nobr">
			{icon name="location"} {trans("Country state:")}
		</TD>
		<TD>
			<SELECT name="search[stateid]" {tip text="Select country state"}>
				<OPTION value="">{trans("— all states —")}</OPTION>
				{foreach from=$cstateslist item=item key=key}
				<OPTION value="{$key}">{$item.name}</OPTION>
				{/foreach}
			</SELECT>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="netdev"} {trans("Link type:")}
		</TD>
		<td>
			<select size="1" name="search[linktype]" onchange="change_linktype(this.options[this.selectedIndex].value)">
				<option value="">{trans("— all —")}</option>
				{foreach $_LINKTECHNOLOGIES as $linktype => $linktech}
					<option value="{$linktype}">{$_LINKTYPES[$linktype]}</option>
				{/foreach}
			</select>
		</td>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="netdev"} {trans("Link technology:")}
		</TD>
		<TD>
			<SELECT SIZE="1" name="search[linktechnology]" id="linktechnology">
				<OPTION VALUE="">{trans("— all —")}</OPTION>
				<option value="0">{trans("— without technology —")}</option>
				{foreach array(0, 1, 2) as $linktype}
					{foreach $_LINKTECHNOLOGIES[$linktype] as $linktechnologyidx => $linktechnology}
					<OPTION VALUE="{$linktechnologyidx}">{$linktechnology}</OPTION>
					{/foreach}
				{/foreach}
			</SELECT>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="netdev"} {trans("Link speed:")}
		</TD>
		<TD>
			<SELECT SIZE="1" name="search[linkspeed]">
				<OPTION VALUE="">{trans("— all —")}</OPTION>
				{foreach from=$_LINKSPEEDS item=item key=key}
					<OPTION VALUE="{$key}">{$item}</OPTION>
				{/foreach}
			</SELECT>
		</TD>
	</TR>
	<tr>
		<td class="nobr">
			{icon name="netdevice"}
			<strong>{trans("Network devices")}</strong>
		</td>
		<td>
			<select size="1" name="search[netdevices]">
				<option value="">{trans("— any —")}</option>
				<option value="1">{trans("yes")}</option>
				<option value="0">{trans("no")}</option>
			</select>
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="hardware"}
			<strong>{trans("Network device type")}</strong>
		</td>
		<td>
			<select size="1" name="search[netdevtype]">
				<option value="">{trans("— any —")}</option>
				{foreach Localisation::arraySort($netdevicetypes, 'name') as $type => $info}
					<option value="{$type}">{$info.name}</option>
				{/foreach}
			</select>
		</td>
	</tr>
	<TR>
		<TD class="bold nobr">
			{icon name="money"} {trans("Tariffs:")}
		</TD>
		<TD class="multiselect">
			<select size="1" name="search[tariffs][]" class="lms-ui-multiselect" multiple data-default-value="{trans("— all —")}">
				{foreach $tariffs as $item}
					<option value="{$item.id}">{$item.name} ({Utils::formatMoney($item.value, $item.currency)})</option>
				{/foreach}
			</select>
			&nbsp;{trans("with end date:")}
			<select name="search[withenddate]">
				<option value="-1">{trans("<!enddate>— any —")}</option>
				<option value="1">{trans("yes")}</option>
				<option value="0">{trans("no")}</option>
			</select>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="money"} {trans("Tariff type:")}
		</TD>
		<TD>
			<SELECT SIZE="1" name="search[tarifftype]">
				<OPTION VALUE="" SELECTED>{trans("— all —")}</OPTION>
				{foreach $_SERVICETYPES as $id => $name}
				 	<OPTION VALUE="{$id}">{$name}</OPTION>
				{/foreach}
			</SELECT>
		</TD>
	</TR>
	{if !empty($promotions)}
		<tr>
			<td class="nobr">
				{icon name="money"}
				<strong>{trans("Promotion schemas")}</strong>
			</td>
			<td class="nobr">
				<select size="1" name="search[promotion-schema][]" multiple class="lms-ui-multiselect"
					data-placeholder="{trans("— any —")}"
					data-show-group-labels="true">
					{foreach $promotions as $promotion}
						<optgroup title="{$promotion.description|trunescape:512}"
							label="{$promotion.name}" data-valid="{$promotion.valid}"
							{if !$promotion.valid} class="blend"{/if}>
							{foreach $promotion.schemas as $schemaid => $schema}
								<option title="{$schema.description|trunescape:512}"
									value="{$schemaid}"{if $variables.schemaid == $schemaid} SELECTED{/if}
									data-valid="{$promotion.valid}"{if !$promotion.valid} class="blend"{/if}
								>{$schema.name|trunescape:40}</option>
							{/foreach}
					</optgroup>
					{/foreach}
				</select>
			</td>
		</tr>
	{/if}
	<TR>
		<TD class="bold nobr">
			{icon name="money"} {trans("Assignments")}
		</TD>
		<TD>
			<select size="1" id="assignment-selector" name="search[assignments]">
				<option value="0">{trans('— all —')}</option>
				<option value="7">{trans('expire in $a days', 7)}</option>
				<option value="14">{trans('expire in $a days', 14)}</option>
				<option value="30">{trans('expire in $a days', 30)}</option>
				<option value="60">{trans('expire in $a days', 60)}</option>
				<option value="90">{trans('expire in $a days', 90)}</option>
				<option value="-100">{trans('expire in indicated number of days')}</option>
				<option value="-14">{trans('<!assignments>expired')}</option>
				<option value="-1">{trans('without end date')}</option>
				<option value="-15">{trans("all without end date")}</option>
				<option value="-10">{trans('without start date')}</option>
				<option value="-2">{trans('active')}</option>
				<option value="-7">{trans('active, without nodes')}</option>
				<option value="-3">{trans('active, with invoice')}</option>
				<option value="-5">{trans('active, with pro forma')}</option>
				<option value="-13">{trans('active, without document')}</option>
				<option value="-4">{trans('suspended')}</option>
				<option value="-16">{trans('suspended, current')}</option>
				<option value="-9">{trans('all suspended')}</option>
				<option value="-6">{trans('waiting')}</option>
				<option value="-8">{trans('waiting, without nodes')}</option>
				<option value="-11">{trans("<!assignment>commited")}</option>
				<option value="-12">{trans("<!assignment>not commited")}</option>
				<option value="-17">{trans("with recipient address")}</option>
			</select>
			<input type="text" id="assignment-days" name="search[assignments]" value="" disabled required
				size="5" placeholder="{trans("days")}" style="display: none;" pattern="[0-9]+">
		</TD>
	</TR>
	<tr>
		<td></td>
		<td>
			<div id="assignment-properties">
				<div>
					<div class="reverse-elements">
						<select id="assignment-period" size="1" name="search[assignment][period]" disabled
							{tip text="Select time period to account liability"}>
							<option value="">{trans("— all —")}</option>
							{foreach $_PERIODS as $key => $item}
								<option value="{$key}">{$item}</option>
							{/foreach}
						</select>
						<label for="assignment-period">
							{trans("Accounting")}
						</label>
					</div>
					<input type="checkbox" id="backward-period" name="search[assignment][backwardperiod]" value="1" disabled>
					<label for="backward-period" {tip text="Check if tariff should be accounted backward"}>
						{trans("<!assignment>backward")}
					</label>
				</div>
				<div>
					<input id="a-day-of-month" type="text" name="search[assignment][at]"
						value="" size="8" disabled
						{tip text="Enter accounting time. For disposable accounting enter date in format YYYY/MM/DD, for weekly accounting enter day of week (Monday = 1), for monthly accounting enter day of month (1 to 28), for yearly accounting enter day and month in format DD/MM (15/09 means September 15th), for half-yearly DD/MM (MM <=6) and for quarterly DD/MM (MM <= 3)" trigger="at"}>
					<input type="checkbox" id="last-day-of-month" name="search[assignment][at]" value="0"
						disabled>
					<label for="last-day-of-month">
						{trans("last day of month")}
					</label>
				</div>
			</div>
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="modified-date"}
			<strong>{trans("Created")}</strong>
		</td>
		<td>
			<span class="lms-ui-date-period-container">
				{date_period_preset from="#createdfrom" to="#createdto"}
				<span>{trans("from")}</span>
				<input type="text" class="lms-ui-date lms-ui-date-unix" value=""
					id="createdfrom" name="search[createdfrom]" size="10"
					placeholder="{trans("yyyy/mm/dd")}">
				<span>{trans("to")}</span>
				<input type="text" class="lms-ui-date lms-ui-date-unix" value=""
					id="createdto" name="search[createdto]" size="10"
					placeholder="{trans("yyyy/mm/dd")}">
			</span>
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="modified-date"}
			<strong>{trans("Modified")}</strong>
		</td>
		<td>
			<span class="lms-ui-date-period-container">
				{date_period_preset from="#modifiedfrom" to="#modifiedto"}
				<span>{trans("from")}</span>
				<input type="text" class="lms-ui-date lms-ui-date-unix" value=""
					id="modifiedfrom" name="search[modifiedfrom]" size="10"
					placeholder="{trans("yyyy/mm/dd")}">
				<span>{trans("to")}</span>
				<input type="text" class="lms-ui-date lms-ui-date-unix" value=""
					id="modifiedto" name="search[modifiedto]" size="10"
					placeholder="{trans("yyyy/mm/dd")}">
			</span>
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="modified-date"}
			<strong>{trans("Deleted")}</strong>
		</td>
		<td>
			<span class="lms-ui-date-period-container">
				{date_period_preset from="#deletedfrom" to="#deletedto"}
				<span>{trans("from")}</span>
				<input type="text" class="lms-ui-date lms-ui-date-unix" value=""
					id="deletedfrom" name="search[deletedfrom]" size="10"
					placeholder="{trans("yyyy/mm/dd")}">
				<span>{trans("to")}</span>
				<input type="text" class="lms-ui-date lms-ui-date-unix" value=""
					id="deletedto" name="search[deletedto]" size="10"
					placeholder="{trans("yyyy/mm/dd")}">
			</span>
		</td>
	</tr>
	<tr>
		<td class="nobr">
			{icon name="paytype"}
			<strong>{trans("Cutoff suspending")}</strong>
		</td>
		<td>
			<span class="lms-ui-date-period-container">
				{date_period_preset from="#cutoffstopfrom" to="#cutoffstopto"}
				<span>{trans("from")}</span>
				<input type="text" class="lms-ui-date lms-ui-date-unix" value=""
					id="cutoffstopfrom" name="search[cutoffstopfrom]" size="10"
					placeholder="{trans("yyyy/mm/dd")}">
				<span>{trans("to")}</span>
				<input type="text" class="lms-ui-date lms-ui-date-unix" value=""
					id="cutoffstopto" name="search[cutoffstopto]" size="10"
					placeholder="{trans("yyyy/mm/dd")}">
			</span>
		</td>
	</tr>
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<TR>
		<TD class="bold nobr">
			{icon name="division"} {trans("Division")}:
		</TD>
		<TD>
			<SELECT SIZE="1" name="d">
				<OPTION VALUE="">{trans("— all —")}</OPTION>
				{foreach $divisions as $division}
					<OPTION VALUE="{$division.id}"{if $listdata.division==$division.id} selected{/if}
						>{$division.shortname|trunescape:30}</OPTION>
				{/foreach}
			</SELECT>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr valign-top">
			{icon name="filter"} {trans("Status:")}
		</TD>
		<TD>
			<input type="hidden" name="s[]" value="0">
			<SELECT SIZE="1" name="s[]" class="lms-ui-multiselect" multiple data-default-value="{trans("— all —")}">
				{foreach $_CSTATUSES as $statusidx => $status}
				<OPTION VALUE="{$statusidx}">{$status.plurallabel}</OPTION>
				{/foreach}
				<OPTION VALUE="50">{trans("deleted<!plural>")}</OPTION>
				<OPTION VALUE="72">{trans("existing<!plural>")}</OPTION>
				<OPTION VALUE="51">{trans("with disconnected nodes")}</OPTION>
				{if !ConfigHelper::checkPrivilege('hide_finances')}
					<OPTION VALUE="52">{trans("in debt")}</OPTION>
					<OPTION VALUE="57">{trans("in debt above 100%")}</OPTION>
					<OPTION VALUE="58">{trans("in debt above 200%")}</OPTION>
					<OPTION VALUE="82">{trans("in debt above or equal 100%")}</OPTION>
					<OPTION VALUE="83">{trans("in debt above or equal 200%")}</OPTION>
					<option value="71">{trans("overdue receivables")}</option>
				{/if}
				<OPTION VALUE="55">{trans("without tariff")}</OPTION>
				<OPTION VALUE="75">{trans("with discount")}</OPTION>
				<option value="79">{trans("with active tariffless liabilities")}</option>
				<option value="80">{trans("with tariffless liabilities")}</option>
				<OPTION VALUE="53">{trans("online")}</OPTION>
				<OPTION VALUE="54">{trans("without group")}</OPTION>
				<OPTION VALUE="56">{trans("suspended<!plural>")}</OPTION>
				<OPTION value="59">{trans("without contracts")}</OPTION>
				<OPTION value="76">{trans("without active contracts")}</OPTION>
				<option value="84">{trans("with term contracts")}</option>
				<option value="85">{trans("with active term contracts")}</option>
				<OPTION value="60">{trans("with expired contracts")}</OPTION>
				<OPTION value="77">{trans("with expired, active contracts")}</OPTION>
				<OPTION value="61">{trans("with expiring contracts")}</OPTION>
				<OPTION value="78">{trans("with expiring, active contracts")}</OPTION>
				<OPTION VALUE="70">{trans("TERYT not specified")}</OPTION>
				<OPTION VALUE="68">{trans("without zip (main address)")}</OPTION>
				<OPTION VALUE="74">{trans("without zip (other addresses)")}</OPTION>
				<option value="81">{trans("without location address")}</option>
				<OPTION value="73">{trans("with unarchived documents")}</OPTION>
			</SELECT>
			<label>
				<INPUT class="radio" type="radio" value="AND" name="sk"{if $sk!='OR'} checked{/if}>
				{trans("and")}
			</label>
			<label>
				<INPUT class="radio" type="radio" value="OR" name="sk"{if $sk=='OR'} checked{/if}>
				{trans("or")}
			</label>
			<div id="balance-days-container">
				<input type="text" name="search[balance_days]" id="balance-days" size="7" disabled>
				<label for="balance-days">
					{trans("receivables overdue by days")}
				</label>
			</div>
		</TD>
	</TR>

	<tr>
		<td class="nobr valign-top">
			{icon name="origin" class="fa-fw"}
			<strong>{trans("<!origin>Origin")}</strong>
		</td>
		<td>
			<select size="1" name="search[origin]" {tip trigger="origin"}>
				<option value="-1">{trans("<!origin>— any —")}</option>
				<option value="0">{trans("<!origin>— unspecified —")}</option>
				{foreach Localisation::arraySort($_ORIGINS) as $originidx => $origin}
					<option value="{$originidx}">{$origin}</option>
				{/foreach}
			</select>
		</td>
	</tr>

	<tr>
		<td class="nobr valign-top">
			{icon name="document"}
			<strong>{trans("Documents")}</strong>
		</td>
		<td>
			<div class="document-filters">
				<div class="document-filter">
					<span>
						{trans("<!document>Type")}
					</span>
					<select name="document[type][]" class="lms-ui-multiselect" multiple
						data-default-value="{trans("<!document-type>— any —")}">
						{foreach Localisation::arraySort($_DOCTYPES) as $doctypeidx => $doctype}
							{if $doctypeidx >= 0}
								{continue}
							{/if}
							<option value="{$doctypeidx}">{$doctype}</option>
						{/foreach}
					</select>
				</div>
				<div class="document-filter">
					<span>
						{trans("Date selection")}
					</span>
					<select name="document[dateselection]">
						<option value="creationdate">{trans("creation date")}</option>
						<option value="confirmationdate">{trans("confirmation date")}</option>
						<option value="archivizationdate">{trans("archivization date")}</option>
						<option value="fromdate">{trans("'from' date")}</option>
						<option value="todate" selected>{trans("'to' date")}</option>
					</select>
				</div>
				<div class="document-filter">
					{date_period_preset from="[name=\"document[datefrom]\"]" to="[name=\"document[dateto]\"]"}
					<span>{trans("from")}</span>
					<input type="text" name="document[datefrom]" size="10" maxlength="10"
						{tip class="lms-ui-date" text="Enter date in YYYY/MM/DD format (empty field means no limit) or click to choose it from calendar"}>
					<span>{trans("to")}</span>
					<input type="text" name="document[dateto]" size="10" maxlength="10"
						{tip class="lms-ui-date" text="Enter date in YYYY/MM/DD format (empty field means no limit) or click to choose it from calendar"}>
				</div>
			</div>
		</td>
	</tr>
	<TR>
		<TD class="bold nobr">
			{icon name="money"} {trans("Balance:")}
		</TD>
		<TD>
			<label>
				<input type="radio" name="search[balance_relation]" value="-1" checked>
				{trans("less or equal")}
			</label>
			<label>
				<input type="radio" name="search[balance_relation]" value="1">
				{trans("greater or equal")}
			</label>
			&nbsp;<input type="text" name="search[balance]" size="7">
			{trans("on day")}
			<input type="text" name="search[balance_date]" {tip class="calendar" text="Enter date in YYYY/MM/DD format (empty field means today) or click to choose it from calendar"}>
		</TD>
	</TR>
	<TR>
		<TD class="bold nobr">
			{icon name="ipnetwork"} {trans("Network:")}
		</TD>
		<TD>
			<input type="hidden" name="n" value="all">
			<SELECT SIZE="1" name="n[]" class="lms-ui-multiselect" data-default-value="{trans("— all networks —")}" multiple>
				{foreach $networks as $network}
				<OPTION value="{$network.id}"{if $listdata.network && in_array($network.id, $listdata.network)} selected{/if}>{$network.name|truncate:50:"&hellip;":true}</OPTION>
				{/foreach}
			</SELECT>
		</TD>
	</TR>
	<tr>
		<td class="nobr valign-top" rowspan="2">
			{icon name="customergroup"}
			<strong>{trans("Group")}</strong>
		</td>
		<td>
			<label>
				<input type="hidden" value="0" name="cgnot">
				<input type="checkbox" value="NOT" name="cgnot"{if !empty($cgnot)} checked{/if}>
				{trans("negation")}
			</label>
			&nbsp;
			<input type="hidden" name="g" value="all">
			<select size="1" name="g[]" multiple class="lms-ui-multiselect">
				<option value=""{if ! is_array($listdata.customergroup) && !$listdata.customergroup} selected{/if}
					data-exclusive>{trans("— all groups —")}</option>
				<option value="-1"{if !is_array($listdata.customergroup) && $listdata.customergroup == -1} selected{/if}
					data-exclusive>{trans("— without assigned groups —")}</option>
				{foreach $customergroups as $customergroup}
					<option value="{$customergroup.id}"
						{if is_array($listdata.customergroup) && in_array($customergroup.id, $listdata.customergroup)}selected{/if}
						>{$customergroup.name|truncate:50:"&hellip;":true}</option>
				{/foreach}
			</select>
			<label>
				<input type="radio" value="AND" name="cgk"{if $cgk!='OR'} checked{/if}>
				{trans("and")}
			</label>
			<label>
				<input type="radio" value="OR" name="cgk"{if $cgk=='OR'} checked{/if}>
				{trans("or")}
			</label>
			<label>
				<input type="radio" value="exact-match" name="cgk"{if $cgk == 'exact-match'} checked{/if}>
				{trans("exact match")}
			</label>
		</td>
	</tr>
	<tr>
		<td>
			{trans("on day")}
			<input type="text" name="group-date"{if !empty($customergroupdate)} value="{$customergroupdate|date_format:"Y/m/d"}"{/if}
				{tip class="lms-ui-date" text="Enter date in YYYY/MM/DD format (empty field means today) or click to choose it from calendar"}>
		</td>
	</tr>
	<TR>
		<TD class="bold nobr">
			{icon name="nodegroup"} {trans("Nodes Group:")}
		</TD>
		<TD>
			<label>
				<input type="hidden" value="0" name="ngnot">
				<input type="checkbox" value="NOT" name="ngnot"{if !empty($ngnot)} checked{/if}>
				{trans("negation")}
			</label>
			&nbsp;
			<select size="1" name="ng">
				<option value="" {if !$listdata.nodegroup} SELECTED {/if}>{trans("— all groups —")}</option>
				{foreach $nodegroups as $nodegroup}
					<option value="{$nodegroup.id}"
						{if $listdata.nodegroup == $nodegroup.id} selected{/if}
						>{$nodegroup.name|trunescape:30}</option>
				{/foreach}
			</select>
		</TD>
	</TR>
	<TR>
		<TD class="lms-ui-box-buttons" colspan="2">
			{button id="submit-btn" class="form-btn" icon="search" label="Search"}
			{button id="download-btn" class="form-btn" icon="csv" label="Download (CSV)"}
			{button id="print-btn" class="form-btn" icon="print" label="Print"}
		</TD>
	</TR>
	</TBODY>
</TABLE>
</FORM>
<script>

	$(function() {
		$('form[name="customersearch"] [name="search[customername]"]').focus();

		$("[data-controlled-customer-property]").change(function() {
			var customerProperty = $(this).attr("data-controlled-customer-property");
			var value = $(this).val();
			var checked = $(this).prop('checked');
			$('input[type="text"][data-customer-property="' + customerProperty + '"]').prop('disabled', checked && (value == '*' || value == '-'));
			$('input[type="hidden"][data-customer-property="' + customerProperty + '"]').each(function() {
				$(this).prop('disabled', $(this).val() != value);
			});
			$(this).closest('tr').find('.customer-property-label').toggleClass('lms-ui-disabled', checked);
		});

		$('#reset-consents').click(function() {
			$('.cconsent[value="-1"]').prop('checked', true);
		});

		$('#assignment-selector').change(function() {
			var value = parseInt($(this).val());
			$('#assignment-days').toggle(value == -100).prop('disabled', function() {
				return value != -100;
			});
		});

		$('.form-btn').click(function() {
			if ($('#customersearch').get(0).checkValidity()) {
				switch ($(this).attr('id')) {
					case 'submit-btn':
						Search();
						break;
					case 'download-btn':
						ExportCSV();
						break;
					case 'print-btn':
						PrintList();
						break;
				}
			}
		});

		$('.without-contact').change(function() {
			var checkboxElement = $(this).parent().prev();
			checkboxElement.prop('disabled', $(this).prop('checked'));
			$('label[for="' + checkboxElement.attr('id') + '"]').toggleClass('lms-ui-disabled', $(this).prop('checked'));
		});

		$('[name="s[]"]').change(function() {
			var disabled = $(this).val().indexOf('71') === -1;
			$('[name="search[balance_days]"]').prop('disabled', disabled).closest('label').toggleClass('lms-ui-disabled', disabled);
		});

		$('#assignment-selector').change(function() {
			$('#assignment-properties').find('select,input').prop('disabled', !parseInt($(this).val()));
			$('#last-day-of-month').prop('disabled', parseInt($(this).val()) != {$smarty.const.MONTHLY});
		});

		$('#assignment-period').change(function() {
			$('#last-day-of-month').prop('disabled', parseInt($(this).val()) != {$smarty.const.MONTHLY});
		});

		$('#last-day-of-month').change(function() {
			$('#a-day-of-month').prop('disabled', $(this).prop('checked'));
		});
	});

</script>
{/block}
