{$promotion_show_period_values = ConfigHelper::checkConfig('promotions.show_period_values', ConfigHelper::checkConfig('phpui.promotion_show_period_values'))}
{$promotion_schema_name_limit = intval(ConfigHelper::getConfig('promotions.schema_name_limit', ConfigHelper::getConfig('phpui.promotion_schema_name_limit', 40)))}

<style>

    div.lms-ui-multiselect hr {
        margin-top: 0px;
        margin-bottom: 0px;
    }
	div.nodes img,
	div.netdevnodes img,
	div.phones img {
		padding-top: 5px;
		padding-bottom: 5px;
	}

	table.single-assignment {
		border: 1px dotted;
		margin-left: 2em;
	}
	table.single-assignment tr:not(:last-child) {
		border-bottom: 1px dotted;
	}
	table.single-assignment td {
		text-align: center;
	}
	table.single-assignment td:not(:last-child) {
		border-right: 1px dotted;
	}
	table.single-assignment input[type="text"] {
		width: 5em;
		text-align: center;
	}
	table.single-assignment [data-restore-selector] {
		cursor: pointer;
	}

	.customerassignment-data {
		width: 100%;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: flex-start;
		flex-wrap: wrap;
	}

	.customerassignment > div {
		flex-grow: 1;
	}

	#customerassignment-right-panel {
		margin-right: 2em;
		flex-grow: 1;
	}

	#customerassignment-left-panel {
		display: flex;
		margin-right: 10em;
		flex-grow: 1;
	}

	.schema-tariff-container-row {
		display: flex;
		flex-wrap: wrap;
	}

	.schema-tariff-container-row > td:first-child {
		display: flex;
		flex-direction: column;
	}

	.schema-tariff-count {
		padding-top: 0.5em;
	}

	.schema-tariff-count input {
		width: 5em;
	}

	@media screen and (max-width: 600px) {
		#customerassignment-left-panel {
			margin-right: 0em;
		}
		#customerassignment-right-panel {
			margin-right: 0em;
		}
	}

	@media screen and (max-width: 450px) {
		.customerdevices .lms-ui-multiselect-wrapper {
			width: 170px;
			div.lms-ui-multiselect {
				min-width: 170px;
			}
		}

		[name="assignment[name]"] {
			width: 150px;
		}

		[name="assignment[numberplanid]"] {
			width: 150px;
		}

		[name="assignment[attribute]"] {
			width: 150px;
		}

		#recipient-select {
			width: 150px;
		}
	}

	#a_day > td > * {
		margin-top: 0.3em;
	}

	#a_price > td:last-child {
		padding-left: 0;
	}

	#attachments {
		display: flex;
		flex-direction: column;
	}

	.promotion-attachments {
		display: flex;
		flex-direction: column;
	}

	.promotion-attachments ul {
		margin-block-start: 0.3em;
		margin-block-end: 0.3em;
		list-style: none;
		padding-inline-start: 0;
	}

	.multi-check-all-label {
		display: block;
		padding-top: 0.5em;
	}

	.price-variants .lms-ui-box {
		display: flex;
		border: 1px dotted black;
		border-radius: 5px;
		background-color: #DFD5BD;
		flex-direction: column;
		justify-content: flex-start;
	}

	.price-variants .lms-ui-box-header {
		padding-top: 0.7em;
		padding-bottom: 0.3em;
		border-bottom: 1px dotted black;
		border-top-left-radius: 4px;
		border-top-right-radius: 4px;
		background-color: #CEBD9B;

		display: flex;
		flex-grow: 1;
		flex-wrap: wrap;
	}

	.price-variants .lms-ui-box-body {
		display: flex;
		flex-grow: 1;
		flex-wrap: wrap;
		flex-direction: column;
		border-bottom-left-radius: 4px;
		border-bottom-right-radius: 4px;
	}

	.price-variants .lms-ui-box-row {
		display: flex;
		flex-grow: 1;
		padding-left: 0.5em;
		justify-content: stretch;

	}

	.price-variants .lms-ui-box-field {
		width: 100%;
		min-width: 10em;
	}

	.price-variants .lms-ui-box-body .lms-ui-box-row {
		padding-top: 0.3em;
		padding-bottom: 0.3em;
	}

	.price-variants .lms-ui-background-cycle.lms-ui-box-body .lms-ui-box-row:not(:last-child) {
		border-bottom: 1px dotted grey;
	}

	.price-variants .lms-ui-background-cycle.lms-ui-box-body .lms-ui-box-row:last-child {
		border-bottom-left-radius: 4px;
		border-bottom-right-radius: 4px;
	}

	.price-variants .lms-ui-background-cycle.lms-ui-box-body .lms-ui-box-row:nth-child(even) {
		background-color: #EBE4D6;
	}

	.price-variants .lms-ui-background-cycle.lms-ui-box-body .lms-ui-box-row:nth-child(even).highlight:hover {
		background-color: #CFC;
	}

	.price-variants .lms-ui-background-cycle.lms-ui-box-body .lms-ui-box-row:nth-child(odd) {
		background-color: #DFD5BD;
	}

	.price-variants .lms-ui-background-cycle.lms-ui-box-body .lms-ui-box-row:nth-child(odd).highlight:hover {
		background-color: #CFC;
	}

	.assignment-options {
		display: flex;
		flex-direction: column;
	}

	.assignment-options > * {
		padding-top: 0.2em;
		padding-bottom: 0.2em;
	}

	.tariff-default-values {
		float: right;
	}

</style>

{$default_taxrate = ConfigHelper::getConfig('phpui.default_taxrate')}
{$default_taxlabel = ConfigHelper::getConfig('phpui.default_taxlabel')}

{if isset($promotion_only)}
<select id="tariff-select" name="{$variable_prefix}[tariffid]" style="display: none;">
<option value="-2"></option>
</select>
{/if}

<table class="lmsbox-inner" width="100%">
	<TBODY>
	<tr>
		<td>
		<div class="customerassignment-data">
			<div id="customerassignment-left-panel">
			<table width="100%;" cellpadding="3">
				{if !empty($promotions)}
				<tr>
					<td>
						<table id="a_promotions" style="display: none;">
							{if isset($promotion_only)}
								<tr>
									<td>
										{icon name="assignment"}
									</td>
									<td>
										<label for="dont-create-assignments">
											<strong>{trans("Don't create assignments")}</strong>
										</label>
									</td>
									<td>
										<input type="checkbox" id="dont-create-assignments" name="{$variable_prefix}[dont-create-assignments]"
											value="1"
											{if !empty($variables['dont-create-assignments'])} checked{/if}>
									</td>
								</tr>
							{/if}
							<TR>
								<TD>
									{icon name="money"}
								</TD>
								<TD class="bold">
									{trans("Schema")}
								</TD>
								<TD style="width: 98%;">
									<select size="1" name="{$variable_prefix}[schemaid]" id="promotion-select" data-required="1"
										{tip text="Select promotion schema" trigger="promotion-select" class="lms-ui-advanced-select-test show-group-labels"}>
										{if $promotion_only}
											<option value="0">{trans("<!promotionschema>— none —")}</option>
										{/if}
										{foreach $promotions as $promotion}
											{if $promotion.valid || $promotion.datefrom > $smarty.now}
												<optgroup title="{$promotion.description|trunescape:512}"
													label="{strip}
															{$promotion.name|escape}
															{if !$promotion.valid && $promotion.datefrom > $smarty.now}
																&nbsp;({trans("from")}&nbsp;{$promotion.datefrom|date_format:"Y-m-d"})
															{/if}
														{/strip}"
													data-valid="{$promotion.valid}"
													{if !$promotion.valid}
														class="blend" disabled
														{if !$variables.alltariffs && $promotion.datefrom < $smarty.now}
															style="display: none;"
														{/if}
													{/if}
												>
													{foreach $promotion.schemas as $schemaid => $schema}
														{if $schema.valid || $schema.datefrom > $smarty.now}
															<option title="{$schema.description|trunescape:512}"
																value="{$schemaid}"
																{if $variables.schemaid == $schemaid}
																	selected
																{/if}
																data-valid="{if $promotion.valid && $schema.valid}1{else}0{/if}"
																{if !$promotion.valid || !$schema.valid}
																	class="blend" disabled
																{/if}
															>{strip}
																{$schema.name|trunescape:$promotion_schema_name_limit}
																{if !$schema.valid && $schema.datefrom > $smarty.now}
																	&nbsp;({trans("from")}&nbsp;{$schema.datefrom|date_format:"Y-m-d"})
																{/if}
															{/strip}</option>
														{/if}
													{/foreach}
												</optgroup>
											{/if}
										{/foreach}
									</select>
									<i id="promotion-schema-info" class="lms-ui-icon-info"></i>
								</TD>
							</TR>
							<tr id="a_attachments" style="display: none;">
								<td class="valign-top">
									{icon name="attachment"}
								</td>
								<td class="valign-top">
									<strong>
										{trans("Attachments")}
									</strong>
								</td>
								<td>
									<div id="promotion-attachments">
									</div>
								</td>
							</tr>
							<tr id="a_location" style="display: none;">
								<td>
									{icon name="location"}
								</td>
								<td class="bold">
									{trans("Location:")}
								</td>
								<td style="width: 98%;">
									<input type="hidden" name="{$variable_prefix}[location_address_id]" id="location-address-id"
										{if !empty($variables.location_address_id)} value="{$variables.location_address_id}"{/if}>
									<select name="{$variable_prefix}[location]" id="location-select"
										{tip text="Select promotion location" class="lms-ui-customer-address-select lms-ui-advanced-select-test"}>
										{*
										this contents is generated by ajax
										?m=customerassignmenthelper&api=1&customerid=... call
										*}
									</select>
								</td>
							</tr>
							<tr id="a_check_all_terminals" style="display: none;">
								<td colspan="2">
								</td>
								<td>
									<label>
										<input type="checkbox" id="check_all_terminals" name="{$variable_prefix}[check_all_terminals]"
											value="1" {if $variables.check_all_terminals} checked{/if}>
										{trans("all terminals")}
									</label>
								</td>
							</tr>
							<TR>
								<TD></TD>
								<TD colspan="2">
									{foreach $promotions as $promotionid => $promotion}
										{if !$promotion.valid}
											{continue}
										{/if}
										{foreach $promotion.schemas as $schemaid => $schema}
											{if !$schema.valid}
												{continue}
											{/if}
										<table class="promotion-table" id="schema{$schemaid}">
											{foreach $schema.items as $label => $item}
											<tr>
												<td class="valign-top text-right">
													{t a=$label}<!tariffselection>$a:{/t}
												</td>
												<td class="valign-top" style="padding-bottom: 10px; padding-top: 0;">
													<table>
														<tr class="schema-tariff-container">
															{textformat assign="countid"}counts-{$schemaid}-{iconv('UTF-8', 'ASCII//TRANSLIT', preg_replace('/[ _]/', '-', $label))}{/textformat}
															{if isset($item.single)}
															<td class="valign-top{if !$item.single.optional} blend{/if}">
																<table>
																	<tr class="schema-tariff-container-row">
																		<td>
																			<label>
																				<input class="schema-tariff-checkbox" type="checkbox" name="{$variable_prefix}[sassignmentid][{$schemaid}][{$label}]"
																					value="{$item.single.assignmentid}" data-label="{$label}"
																					data-tarifftype="{$item.single.type}"
																					data-assignment-id="{$item.single.assignmentid}"
																					{if isset($variables.sassignmentid[$schemaid][$label]) || !$item.single.optional} checked{/if}
																					{if !$item.single.optional} disabled data-mandatory="1"{/if}
																					data-tariffaccess="{$item.single.authtype}">
																				<span class="tariff-default-values">
																					{if ($item.single.flags & $smarty.const.TARIFF_FLAG_NET_ACCOUNT) > 0}
																						{if $promotion_show_period_values}
																							{t a=$item.single.tariff b=Utils::smartFormatMoney($item.single.netvalue, $item.single.currency) c=implode(' / ', $item.single.periodvalues)}$a (default: $b; $c){/t}
																						{else}
																							{t a=$item.single.tariff b=Utils::smartFormatMoney($item.single.netvalue, $item.single.currency)}$a (default: $b){/t}
																						{/if}
																						<br>
																						{trans("(net)")}
																					{else}
																						{if $promotion_show_period_values}
																							{t a=$item.single.tariff b=Utils::smartFormatMoney($item.single.value, $item.single.currency) c=implode(' / ', $item.single.periodvalues)}$a (default: $b; $c){/t}
																						{else}
																							{t a=$item.single.tariff b=Utils::smartFormatMoney($item.single.value, $item.single.currency)}$a (default: $b){/t}
																						{/if}
																						<br>
																						{trans("(gross)")}
																					{/if}
																				</span>
																			</label>
																			<span class="schema-tariff-count">
																				{trans("Count:")}
																				<input type="number" name="{$variable_prefix}[counts][{$schemaid}][{$label}]"
																					id="{$countid}" min="1" max="50" required
																					value="{if isset($variables.counts[$schemaid][$label])}{$variables.counts[$schemaid][$label]}{else}1{/if}">
																			</span>
																			<input type="hidden" name="{$variable_prefix}[backwardperiods][{$schemaid}][{$label}][{$item.single.assignmentid}]"
																				value="{$item.single.backwardperiod}">
																		</td>
																		<td>
																			<table class="single-assignment" data-assignment-id="{$item.single.assignmentid}"
																					{if !isset($variables.sassignmentid[$schemaid][$label]) && $item.single.optional}style="display: none;"{/if}>
																				<tr>
																					{foreach $item.single.periods as $period}
																					<td>{$period.label}</td>
																					{/foreach}
																				</tr>
																				<tr>
																					{foreach $item.single.periods as $key => $period}
																					<td>
																						{if $period.modifiable}
																							{textformat assign="elemid"}value-{$schemaid}-{iconv('UTF-8', 'ASCII//TRANSLIT', preg_replace('/[ _]/', '-', $label))}-{$item.single.assignmentid}-{$key}{/textformat}
																							<input id="{$elemid}" type="text" name="{$variable_prefix}[values][{$schemaid}][{$label}][{$item.single.assignmentid}][{$key}]" class="format-3f"
																									value="{if isset($variables.values[$schemaid][$label][$item.single.assignmentid][$key])}{$variables.values[$schemaid][$label][$item.single.assignmentid][$key]}{else}{Localisation::smartFormatNumber($period.value, true)}{/if}"
																									{tip trigger=$elemid}>
																							<i class="lms-ui-icon-restore" data-restore-selector="#{$elemid}" data-restore-value="{Localisation::smartFormatNumber($period.value, true)}"></i>
																						{else}
																							{if $period.value == ''}
																								-
																							{else}
																								{Utils::smartFormatMoney($period.value)}
																							{/if}
																						{/if}
																					</td>
																					{/foreach}
																				</tr>
																			</table>
																		</td>
																	</tr>
																</table>
															</td>
															{else}
															<td class="valign-top">
																<table>
																	<tr class="schema-tariff-container-row">
																		<td>
																			<select class="schema-tariff-selection" name="{$variable_prefix}[sassignmentid][{$schemaid}][{$label}]" data-label="{$label}">
																				{if !$item.selection.required}
																				<option value="0" data-tariffaccess="-1" data-tarifftype="0">{trans("— none —")}</option>
																				{/if}
																				{foreach $item.selection.items as $item}
																				<option value="{$item.assignmentid}" data-tariffaccess="{$item.authtype}"
																						data-tarifftype="{$item.type}" data-assignment-id="{$item.assignmentid}"
																						{if in_array($item.assignmentid, (array)$variables.sassignmentid[$schemaid])} selected{/if}
																					>{strip}
																						{if ($item.flags & $smarty.const.TARIFF_FLAG_NET_ACCOUNT) > 0}
																							{if $promotion_show_period_values}
																								{t a=$item.tariff b=Utils::smartFormatMoney($item.netvalue, $item.currency) c=implode(' / ', $item.periodvalues)}$a (default: $b; $c){/t}
																							{else}
																								{t a=$item.tariff b=Utils::smartFormatMoney($item.netvalue, $item.currency)}$a (default: $b){/t}
																							{/if}
																							{trans("(net)")}
																						{else}
																							{if $promotion_show_period_values}
																								{t a=$item.tariff b=Utils::smartFormatMoney($item.value, $item.currency) c=implode(' / ', $item.periodvalues)}$a (default: $b; $c){/t}
																							{else}
																								{t a=$item.tariff b=Utils::smartFormatMoney($item.value, $item.currency)}$a (default: $b){/t}
																							{/if}
																							{trans("(gross)")}
																						{/if}
																				{/strip}</option>
																				{/foreach}
																			</select>
																			<span class="schema-tariff-count">
																				{trans("Count:")}
																				<input type="number" name="{$variable_prefix}[counts][{$schemaid}][{$label}]"
																					id="{$countid}" min="1" max="50" required
																					value="{if isset($variables.counts[$schemaid][$label])}{$variables.counts[$schemaid][$label]}{else}1{/if}">
																			</span>
																		</td>
																		<td>
																			{foreach $item.selection.items as $item}
																			<table class="single-assignment" data-assignment-id="{$item.assignmentid}"
																					{if !in_array($item.assignmentid, (array)$variables.sassignmentid[$schemaid])}style="display: none;"{/if}>
																				<input type="hidden" name="{$variable_prefix}[backwardperiods][{$schemaid}][{$label}][{$item.assignmentid}]"
																					   value="{$item.backwardperiod}">
																				<tr>
																					{foreach $item.periods as $period}
																						<td>{$period.label}</td>
																					{/foreach}
																				</tr>
																				<tr>
																					{foreach $item.periods as $key => $period}
																						<td>
																							{if $period.modifiable}
																								{textformat assign="elemid"}value-{$schemaid}-{iconv('UTF-8', 'ASCII//TRANSLIT', preg_replace('/[ _]/', '-', $label))}-{$item.assignmentid}-{$key}{/textformat}
																								<input id="{$elemid}"
																										type="text" name="{$variable_prefix}[values][{$schemaid}][{$label}][{$item.assignmentid}][{$key}]"
																										value="{if isset($variables.values[$schemaid][$label][$item.assignmentid][$key])}{$variables.values[$schemaid][$label][$item.assignmentid][$key]}{else}{$period.value}{/if}"
																										{tip trigger=$elemid}>
																								<i class="lms-ui-icon-restore" data-restore-selector="#{$elemid}" data-restore-value="{$period.value}"></i>
																							{else}
																								{if $period.value == ''}
																									-
																								{else}
																									{$period.value|money_format}
																								{/if}
																							{/if}
																						</td>
																					{/foreach}
																				</tr>
																			</table>
																			{/foreach}
																		</td>
																	</tr>
																</table>
															</td>
															{/if}
														</tr>
														<tr class="customerdevices" data-schemaid="{$schemaid}" data-label="{$label}">
															{*
															content of this row is generated by ajax
															?m=customerassignmenthelper&api=1&customerid=... call
															*}
														</tr>
													</table>
												</td>
											</tr>
											{/foreach}
										</table>
										{/foreach}
									{/foreach}
								</TD>
							</TR>
						</table>
					</td>
				</tr>
				{/if}
				<tr id="a_properties" style="display: none;">
					<td>
						<TABLE width="100%" cellpadding="3">
							<COLGROUP>
								<COL style="width: 1%;">
								<COL style="width: 1%;">
								<COL style="width: 98%;">
							</COLGROUP>

							<TBODY>
							{block name="customerassignmenthelper-properties"}

							<TR id="a_count" style="display: none;">
								<TD>
									{icon name="quantity"}
								</TD>
								<TD class="bold nobr">
									{trans("Count:")}
								</TD>
								<TD>
									<INPUT type="text" id="quantity" name="{$variable_prefix}[count]" value="{if $variables.count}{$variables.count}{else}1{/if}" size="15" pattern="[0-9]+([\.][0-9]+)?" formnovalidate {tip text="Enter count in numeric format" trigger="count"}>
								</TD>
							</TR>

							<TR id="a_name" style="display: none;">
								<TD>
									{icon name="description"}
								</TD>
								<TD class="bold nobr">
									{trans("Name:")}
								</TD>
								<TD>
									<INPUT type="text" name="{$variable_prefix}[name]" value="{if $variables.tariffid<=0}{$variables.name|default:""|escape}{/if}"
										size="30" {tip text="Enter liability name/description (tariffless liabilities only)" trigger="name"}>
								</TD>
							</TR>

							<TR id="a_attribute" style="display: none;">
								<TD>
									{icon name="tags"}
								</TD>
								<TD class="bold nobr">
									{trans("Attribute:")}
								</TD>
								<TD>
									<INPUT type="text" name="{$variable_prefix}[attribute]" value="{if $variables.attribute}{$variables.attribute|escape}{/if}" size="30" {tip text="Enter tariff attribute" trigger="attribute"}>
								</TD>
							</TR>

							<tr id="a_note">
								<td>
									{icon name="notes"}
								</td>
								<td class="nobr">
									<strong>{trans("Note")}</strong>
								</td>
								<td>
									<input type="text" name="{$variable_prefix}[note]" value="{if $variables.note}{$variables.note|escape}{/if}"
										size="30" {tip text="Enter assignment/liability note" trigger="note"}>
								</td>
							</tr>

							<TR id="a_day" style="display: none;">
								<TD>
									{icon name="accounting"}
								</TD>
								<TD class="bold nobr">
									{trans("Accounting:")}
								</TD>
								<TD>
									<SELECT id="assignment-period" size="1" name="{$variable_prefix}[period]" {tip text="Select time period to account liability"}>
										{foreach from=$_PERIODS key=key item=item}
										<OPTION value="{$key}"{if $variables.period == $key} SELECTED{/if}>{$item}</OPTION>
										{/foreach}
									</SELECT>
									<label id="backward-period" {tip text="Check if tariff should be accounted backward"}>
										<input type="checkbox" name="{$variable_prefix}[backwardperiod]" value="1"
											{if !empty($variables.backwardperiod)} checked{/if}>
										{trans("<!assignment>backward")}
									</label>
									<br>
									<INPUT id="a-day-of-month" type="TEXT" name="{$variable_prefix}[at]"
										value="{if $variables.at}{$variables.at}{/if}" required
										{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"}
										{if $variables.at == 0 && $variables.at != ''} style="display: none;" disabled{/if}
										SIZE="8">
									<label{if $variables.period != $smarty.const.MONTHLY} style="display: none;"{/if}>
										<input type="checkbox" id="last-day-of-month" name="{$variable_prefix}[at]" value="0"
											{if $variables.period != $smarty.const.MONTHLY} disabled{else}{if $variables.at == 0 && $variables.at != ''} checked{/if}{/if}>
										{trans("last day of month")}
									</label>
									{if $variables.atwarning}
									<INPUT type="hidden" name="{$variable_prefix}[atwarning]" value="1">
									{/if}
								</TD>
							</TR>

							<TR id="a_period">
								<TD>
									{icon name="period"}
								</TD>
								<TD class="bold nobr">
									{trans("Period:")}
								</TD>
								<TD>
									{trans("from:")}
									<input type="text" name="{$variable_prefix}[datefrom]"
										value="{if $variables.datefrom}{$variables.datefrom}{/if}"
										placeholder="{trans("yyyy/mm/dd")}"
										{tip class="lms-ui-date lms-ui-date-unix" text="Enter accounting start date in YYYY/MM/DD format. If you don't want to define 'From' date leave this field empty" trigger="datefrom"}
										size="10">
									{trans("to:")}
									<input type="text" name="{$variable_prefix}[dateto]"
										value="{if $variables.dateto}{$variables.dateto}{/if}"
										placeholder="{trans("yyyy/mm/dd")}"
										{tip class="lms-ui-date lms-ui-date-unix" text="Enter accounting end date in YYYY/MM/DD format. Leave this field empty if you don't want to set expiration date" trigger="dateto"}
										size="10">
								</TD>
							</TR>

							<tr id="a_price" style="display: none;">
								<td>
									{icon name="money"}
								</td>
								<td class="bold">
									{trans("Price")}
								</td>
								<td>
									<table>
										<tr>
											<td>
												<label for="netprice">
													{trans('net')}
												</label>
											</td>
											<td>
												<input type="text" size="11" id="netprice" name="{$variable_prefix}[netvalue]" value="{if $variables.netvalue}{$variables.netvalue}{/if}"
													   {tip text="Enter liability net price (tariffless liabilities only)" trigger="netvalue"}>
											</td>
											<td rowspan="2">
												<label>
													<input type="checkbox" id="netflag" name="{$variable_prefix}[netflag]" value="1"
														{tip text="Billing according to the net price"}
														{if !empty($variables.netflag)} checked{/if}>
													<span class="lms-ui-label">{trans('calculated from net')}</span>
												</label>
												<span id="tariff-price-variants"></span>
											</td>
										</tr>
										<tr>
											<td>
												<label for="grossprice">
													{trans('gross')}
												</label>
											</td>
											<td>
												<input type="text" size="11" id="grossprice" name="{$variable_prefix}[value]" value="{if $variables.value}{$variables.value}{/if}"
													{tip text="Enter liability gross price (tariffless liabilities only)" trigger="value"}>
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr id="a_currency" style="display: none;">
								<td>
									{icon name="money"}
								</td>
								<td class="bold">
									{trans("Currency")}
								</td>
								<td class="nobr">
									{currency_selection selected=$variables.currency elementname=$variable_prefix|cat:"[currency]"}
								</td>
							</tr>

							<tr id="a_discount_type" class="a_discount" style="display: none;">
								<td style="{if !ConfigHelper::checkConfig('privileges.superuser') && ConfigHelper::checkConfig('privileges.hide_finances')} display: none;{/if}">
									{icon name="discount"}
								</td>
								<td style="{if !ConfigHelper::checkConfig('privileges.superuser') && ConfigHelper::checkConfig('privileges.hide_finances')} display: none;{/if}">
									<strong>{trans("Discount type")}</strong>
								</td>
								<td style="{if !ConfigHelper::checkConfig('privileges.superuser') && ConfigHelper::checkConfig('privileges.hide_finances')} display: none;{/if}">
									<select id="discount_type" name="{$variable_prefix}[discount_type]">
										{foreach $_DISCOUNTTYPES as $key => $item}
											<option value="{$key}"{if $variables.discount_type == $key} selected{/if}>{$item}</option>
										{/foreach}
									</select>
								</td>
							</tr>

							<tr id="a_discount_value" class="a_discount" style="display: none;">
								<td style="{if !ConfigHelper::checkConfig('privileges.superuser') && ConfigHelper::checkConfig('privileges.hide_finances')} display: none;{/if}">
									{icon name="discount"}
								</td>
								<td style="{if !ConfigHelper::checkConfig('privileges.superuser') && ConfigHelper::checkConfig('privileges.hide_finances')} display: none;{/if}">
									<span id="discount_label"{if !empty($variables.target_price_trigger)} style="display: none;"{/if}>
										<strong>{trans("Discount")}</strong>
									</span>
									<span id="target_price_label"{if empty($variables.target_price_trigger)} style="display: none;"{/if}>
										<strong>{trans("Discounted price")}</strong>
									</span>
								</td>
								<td style="{if !ConfigHelper::checkConfig('privileges.superuser') && ConfigHelper::checkConfig('privileges.hide_finances')} display: none;{/if}">
									<input type="text" size="8" id="discount_value"
										name="{$variable_prefix}[discount]"
										value="{if $variables.pdiscount != 0}{Localisation::formatNumber($variables.pdiscount)}{else}{if $variables.vdiscount != 0}{Localisation::smartFormatNumber($variables.vdiscount, true)}{/if}{/if}"
										{if !empty($variables.target_price_trigger)} style="display: none;"{/if}
										{tip text="Enter discount percentage or amount" trigger="discount"}>
									<input type="text" size="8" id="target_price"
										{if empty($variables.target_price_trigger)} style="display: none;"{/if}
										name="{$variable_prefix}[target_price]"
										value="{$variables.target_price}">
									<label>
										<input type="checkbox" id="target_price_trigger"
											name="{$variable_prefix}[target_price_trigger]"
											{if !empty($variables.target_price_trigger)} checked{/if}>
										{trans("target price")}
									</label>
								</td>
							</tr>

							<TR id="a_type" style="display: none;">
								<TD>
									{icon name="type"}
								</TD>
								<TD class="bold">
									{trans("Type:")}
								</TD>
								<TD>
									<SELECT id="tariff-type" size="1" name="{$variable_prefix}[type]" {tip text="Select liability type" trigger="type"}>
										{foreach $_SERVICETYPES as $key => $item}
											<OPTION VALUE="{$key}"{if $variables.type == $key} selected{/if}>{$item}</OPTION>
										{/foreach}
									</SELECT>
								</TD>

							<tr id="a_splitpayment" style="display: none;">
								<td>
									{icon name="value"}
								</td>
								<td class="bold">
									<label for="splitpayment">
										{trans("Split payment:")}
									</label>
								</td>
								<td>
									<input type="checkbox" id="splitpayment" name="{$variable_prefix}[splitpayment]" value="1"{if $variables.splitpayment} checked{/if}>
								</td>
							</tr>

							<TR id="a_tax" style="display: none;">
								<TD>
									{icon name="tax"}
								</TD>
								<TD class="bold">
									{trans("Tax:")}
								</TD>
								<TD>
									<SELECT SIZE="1" id="tax" name="{$variable_prefix}[taxid]" {tip text="Select Tax value" trigger="taxid"}>
										{foreach $taxeslist as $tax}
										<option value="{$tax.id}"
											{if $variables.taxid && $tax.id == $variables.taxid
												|| (!$variables.taxid && (isset($default_taxlabel) && $tax.label == $default_taxlabel
													|| !isset($default_taxlabel) && $tax.value == $default_taxrate))} selected{/if}
											>{$tax.label}</option>
										{/foreach}
									</SELECT>
									{foreach $taxeslist as $tax}
										<input type="hidden" id="tax{$tax.id}" name="tax{$tax.id}" value="{$tax.value}" disabled>
									{/foreach}
								</TD>
							</TR>

							<TR id="a_taxcategory" style="display: none;">
								<TD>
									{icon name="tax"}
								</TD>
								<TD class="bold">
									<label for="taxcategory">
										{trans("Tax category:")}
									</label>
								</TD>
								<TD>
									{tax_category_selection id="taxcategory" elementname=$variable_prefix|cat:"[taxcategory]"
										selected=$variables.taxcategory tip="Select tax category"}
								</TD>
							</TR>

							<TR id="a_productid" style="display: none;">
								<TD>
									{icon name="optional-info"}
								</TD>
								<TD class="bold">
									{trans("Product ID:")}
								</TD>
								<TD>
									<INPUT type="text" name="{$variable_prefix}[prodid]" value="{$variables.prodid|default:""|escape}"
										size="10" {tip text="Enter liability Product ID (tariffless liabilities only)"}>
								</TD>
							</TR>

							<TR id="a_numberplan" style="display: none;">
								<TD>
									{icon name="id"}
								</TD>
								<TD class="bold nobr">
									{trans("Numbering Plan:")}
								</TD>
								<TD>
									<SELECT name="{$variable_prefix}[numberplanid]" {tip text="Select numbering plan"}>
										<OPTION value=""{if !$variables.numberplanid} selected{/if}>— {trans("default")} —</OPTION>

										{foreach item=plan from=$numberplanlist}
										{assign var=period value=$plan.period}
										<OPTION value="{$plan.id}"{if $plan.id==$variables.numberplanid} SELECTED{/if}>{$plan.template} ({$_NUM_PERIODS.$period})</OPTION>
										{/foreach}
									</SELECT>
								</TD>
							</TR>

							<tr id="a_paytime" style="display: none;">
								<td>
									{icon name="deadline"}
								</td>
								<td>
									<strong>{trans("Deadline")}</strong>
								</td>
								<td>
									<div class="valign-middle">
										<select name="{$variable_prefix}[paytime]"{if isset($variables.paytime)} data-value="{$variables.paytime}"{/if}
											{tip class="lms-ui-combobox" trigger="paytime"}>
											<option value="-1"{if !isset($variables.paytime) || $variables.paytime == -1} selected{/if}>— {trans("default")} —</option>
											<option value="0"{if isset($variables.paytime) && strlen($variables.paytime) && $variables.paytime == 0} selected{/if}>0</option>
											<option value="7"{if $variables.paytime == 7} selected{/if}>7</option>
											<option value="10"{if $variables.paytime == 10} selected{/if}>10</option>
											<option value="14"{if $variables.paytime == 14} selected{/if}>14</option>
											<option value="21"{if $variables.paytime == 21} selected{/if}>21</option>
											<option value="30"{if $variables.paytime == 30} selected{/if}>30</option>
											<option value="60"{if $variables.paytime == 60} selected{/if}>60</option>
											<option value="90"{if $variables.paytime == 90} selected{/if}>90</option>
										</select>
										{hint content="Select default deadline in days"}
									</div>
								</td>
							</tr>

							<TR id="a_paytype" style="display: none;">
								<TD>
									{icon name="paytype"}
								</TD>
								<TD class="bold nobr">
									{trans("Payment Type:")}
								</TD>
								<TD>
									{paytypes elemname="{$variable_prefix}[paytype]" selected=$variables.paytype}
								</TD>
							</TR>

							<tr id="a_address" style="display: none;">
								<td>
									{icon name="recipient"}
								</td>
								<td class="bold">
									<span class="bold">{trans("Recipient:")}</span>
								</td>
								<td>
									<select id="recipient-select" name="{$variable_prefix}[recipient_address_id]"
										class="lms-ui-customer-address-select">
										{*
										this contents is generated by ajax
										?m=customerassignmenthelper&api=1&customerid=... call
										*}
									</select>
								</td>
							</tr>

							{/block}
							</TBODY>
						</TABLE>
					</td>
				</tr>
			</table>
			</div>
			<div id="customerassignment-right-panel">
			<TABLE style="width: 100%;" cellpadding="3">
				<COLGROUP>
					<COL style="width: 1%;">
					<COL style="width: 1%;">
					<COL style="width: 98%;">
				</COLGROUP>

				<TBODY>
				<tr id="a_options" style="display: none;">
					<td>
						{icon name="options"}
					</td>
					<td>
						<strong>{trans("Options")}</strong>
					</td>
					<td>
						<div class="assignment-options">
							<label>
								<span>{trans("document type")}</span>
								<select id="invoice" name="{$variable_prefix}[invoice]" {tip text="Select document type" trigger="invoice"}>
									<option value="">{trans("without document")}</option>
									<option value="{$smarty.const.DOC_INVOICE}"{if $variables.invoice == $smarty.const.DOC_INVOICE} selected{/if}>{trans("invoice")}</option>
									<option value="{$smarty.const.DOC_INVOICE_PRO}"{if $variables.invoice == $smarty.const.DOC_INVOICE_PRO} selected{/if}>{trans("pro forma invoice")}</option>
									<option value="{$smarty.const.DOC_DNOTE}"{if $variables.invoice == $smarty.const.DOC_DNOTE} selected{/if}>{trans("debit note")}</option>
								</select>
							</label>
							<label>
								{trans("Document separation group")}
								<input type="hidden" id="document-separation-group-value" name="{$variable_prefix}[separatedocumentvalue]">
								<input type="hidden" id="document-separation-group" name="{$variable_prefix}[separatedocument]">
								<select id="separatedocument" class="lms-ui-combobox"
									data-value="{$variables.separatedocumentvalue}"
									data-id-value="{$variables.separatedocument}"
									data-alt-field="#document-separation-group"
									data-alt-invalid-field="#document-separation-group-value">
									{foreach $document_separation_groups as $document_separation_group}
										<option value="{$document_separation_group}"{if $variables.separatedocument == $document_separation_group} selected{/if}>{$document_separation_group|escape}</option>
									{/foreach}
								</select>
							</label>
							<label>
								<input type="checkbox" name="{$variable_prefix}[separateitem]" value="1"{if $variables.separateitem} checked{/if}>
								{trans("separate document position")}
							</label>
							<label>
								{if $variables.id}
									<input type="checkbox" name="{$variable_prefix}[settlement]" value="1"{if $variables.settlement} checked{/if}>
									{trans("with settlement of first deficient period")}
								{else}
									{trans("settlement type of first deficient period")}
									<select name="{$variable_prefix}[settlement]">
										<option value="0">{trans("<!settlement>— none —")}</option>
										<option value="1"{if $variables.settlement == 1} selected{/if}>{trans("<!settlement>next period")}</option>
										<option value="2"{if $variables.settlement == 2} selected{/if}>{trans("<!settlement>current period")}</option>
									</select>
								{/if}
							</label>
							{if !$variables.id}
							<label>
								<input type="checkbox" name="{$variable_prefix}[last-settlement]" value="1"
									id="last-settlement" {if $variables['last-settlement']} checked{/if}>
								{trans("with settlement of last deficient period")}
							</label>
							<span id="a_align_periods">
								<br>
								<label>
									<input type="checkbox" name="{$variable_prefix}[align-periods]" value="1"
										id="align-periods" {if $variables['align-periods']} checked{/if}>
									{trans("full calendar periods")}
								</label>
							</span>
							{/if}
							<label>
								<input type="checkbox" name="{$variable_prefix}[suspended]" value="1"
									id="suspended" {if !empty($variables.suspended)} checked{/if}>
								{trans("suspended")}
							</label>
						</div>
					</td>
				</tr>

				<tr id="a_existingassignments" style="display: none;">
					<td>
						{icon name="assignment"}
					</td>
					<td>
						<strong>{trans("Existing assignments")}</strong>
					</td>
					<td>
						<select name="{$variable_prefix}[existing_assignments][operation]">
							{foreach $_EXISTINGASSIGNMENTS as $operid => $operation}
							<option value="{$operid}"{if $variables.existing_assignments.operation == $operid} selected{/if}>{$operation}</option>
							{/foreach}
						</select>
						<label id="a_reference_document_limit" style="display: none;">
							<input type="checkbox" name="{$variable_prefix}[existing_assignments][reference_document_limit]"
								value="1"{if isset($variables.existing_assignments.reference_document_limit)} checked{/if}>
							{trans("limit to reference document")}
						</label>
						<label id="a_assignment_type_limit" style="display: none;">
							<input type="checkbox" name="{$variable_prefix}[existing_assignments][assignment_type_limit]"
								id="assignment_type_limit"
								value="1"{if isset($variables.existing_assignments.assignment_type_limit)} checked{/if}>
							{trans("limit to type")}
						</label>
					</td>
				</tr>

				{if $customernodes}
				<tr id="a_nodes" style="display: none;">
					<td>
						{icon name="node"}
					</td>
					<td>
						<strong>{trans("Nodes")}</strong>
					</td>
					<td id="nodelist">
						{foreach $customernodes as $customernode}
						<span data-tariffaccess="{$customernode.authtype}" class="global-node-checkbox">
							<label>
								<input type="checkbox" name="{$variable_prefix}[nodes][{$customernode.id}]" value="{$customernode.id}"{if isset($variables.nodes[$customernode.id])} checked{/if}>
								<span class="bold">{$customernode.name}</span> ({$customernode.id|string_format:"%04d"}){if $customernode.location} / {$customernode.location|trunescape:60}{/if}
							</label>
							{if isset($variables.node_warns[$customernode.id])}
								<input type="hidden" name="{$variable_prefix}[node_warns][{$customernode.id}]" value="{$customernode.id}">
							{/if}
							<br>
						</span>
						{/foreach}
					</td>
				</tr>
				{/if}

				{if $customernetdevnodes}
				<tr id="a_netdevnodes" style="display: none;">
					<td>
						{icon name="netdev"}
					</td>
					<td class="bold">
						{trans("Network Devices:")}
					</td>
					<td id="nodelist">
						{foreach $customernetdevnodes as $customernode}
						<span data-tariffaccess="{$customernode.authtype}" class="global-node-checkbox">
							<label>
								<input type="checkbox" name="{$variable_prefix}[nodes][{$customernode.id}]" value="{$customernode.id}"{if isset($variables.nodes[$customernode.id])} checked{/if}>
								<span class="bold">{$customernode.name}</span> {if !empty($customernode.netdev_name)} / {$customernode.netdev_name}{/if}  ({$customernode.id|string_format:"%04d"}){if $customernode.location} / {$customernode.location|trunescape:60}{/if}
							</label>
							{if isset($variables.node_warns[$customernode.id])}
								<input type="hidden" name="{$variable_prefix}[node_warns][{$customernode.id}]" value="{$customernode.id}">
							{/if}
							<br>
						</span>
						{/foreach}
					</td>
				</tr>
				{/if}

				{if $voipaccounts}
				<tr id="a_phones" style="display: none;">
					<td>
						{icon name="phone"}
					</td>
					<td class="bold">
						{trans("Phones:")}
					</td>
					<td id="nodelist">
						{foreach $voipaccounts as $account}
						{foreach $account.phones as $phone}
						<label>
							<input type="checkbox" name="{$variable_prefix}[phones][]" value="{$phone.id}" {if !empty($variables.phones) && in_array($phone.id, (array)$variables.phones)} checked{/if}>
							<span class="bold">{$phone.phone}</span> / {$account.login}
						</label>
						<br>
						{/foreach}
						{/foreach}
					</td>
				</tr>
				{/if}

				{if ($customernodes && count($customernodes)) || ($customernetdevnodes && count($customernetdevnodes)) || ($voipaccounts && count($voipaccounts))}
				<tr id="a_checkall" style="display: none;">
					<td colspan="2"></td>
					<td>
						<label>
							<INPUT TYPE="checkbox" NAME="allbox" onchange="javascript:checkAllNodes();" VALUE="1">
							{trans("check all<!items>")}
						</label>
					</td>
				</tr>
				{/if}
				</TBODY>
			</TABLE>
			</div>
		</div>
		</td>
	</tr>
	</TBODY>
</TABLE>

<template id="tariff_price_variants_template">
	{capture assign="assignment_hint"}
	{/capture}
	{hint text=$assignment_hint icon="options"}
</template>

<script src="js/customerassignmenthelper.js"></script>
