<!--// $Id$ //-->
<table class="lmsbox" id="documentpromotions" style="display: none;">
	<colgroup>
		<col style="width: 100%;">
	</colgroup>
	<thead>
		<tr class="hand lmsbox-titlebar" data-lmsbox-content="documentpromotionpanel">
			<td>
				{icon name="money"}
				<strong>{trans("Promotion Schema")}</strong>
			</td>
		</tr>
	</thead>
	<tbody>
		<tr id="documentpromotionpanel"  style="display: none;">
			<td>
				<table class="lmsbox-inner">
					<tbody>
						<tr>
							<td>
								{include file="customer/customerassignmenthelper.html" variable_prefix="document[assignment]" variables=$document.assignment promotion_only=1}
							</td>
						</tr>
					</tbody>
				</table>
			</td>
		</tr>
	</tbody>
</table>

<script>
	var tariffDefaultTaxId = {$defaultTaxId};
	var assignmentGrossvalue = '{$document.assignment.value}';
	var assignmentNetvalue = '{$document.assignment.netvalue}';
	var assignmentNetflag = '{$document.assignment.netflag}';
	var assignmentTaxid = '{$document.assignment.taxid}';
	var assignmentTariffId = '{$document.assignment.tariffid}';

	var tariffTypes = [];
	{foreach $tariffs as $tariff}
	tariffTypes[{$tariff.id}] = {$tariff.tarifftype};
	{/foreach}

	var selected = {};
	{if !empty($document.assignment.snodes)}
	selected["snodes"] = {json_encode($document.assignment.snodes)};
	{/if}
	{if !empty($document.assignment.sphones)}
	selected["sphones"] = {json_encode($document.assignment.sphones)};
	{/if}
	selected["location"] = "{if isset($document.assignment.location)}{$document.assignment.location}{/if}";
	selected["recipient_address_id"] = "{if isset($document.assignment.recipient_address_id)}{$document.assignment.recipient_address_id}{else}0{/if}";

	var promotionAttachments = JSON.parse('{json_encode($promotionattachments, JSON_FORCE_OBJECT)}');
	var assignmentPromotionAttachments = {};
	{if !empty($document.assignment['promotion-attachments'])}
		assignmentPromotionAttachments = JSON.parse('{json_encode($document.assignment['promotion-attachments'], JSON_FORCE_OBJECT)}');
	{/if}
	var assignmentPromotionSchemaAttachments = {};
	{if !empty($document.assignment['promotion-schema-attachments'])}
		assignmentPromotionSchemaAttachments = JSON.parse('{json_encode($document.assignment['promotion-schema-attachments'], JSON_FORCE_OBJECT)}');
	{/if}

	var assignment_settings = {
		customerid: {if !empty($cid)}{$cid}{else}0{/if},
		selected: selected,
		internetTariffType: {$smarty.const.SERVICE_INTERNET},
		phoneTariffType: {$smarty.const.SERVICE_PHONE},
		tvTariffType: {$smarty.const.SERVICE_TV},
		DOC_DNOTE: {$smarty.const.DOC_DNOTE},
		tariffTypes: tariffTypes,
		variablePrefix: 'document[assignment]',
		promotionAttachments: promotionAttachments,
		assignmentPromotionAttachments: assignmentPromotionAttachments,
		assignmentPromotionSchemaAttachments: assignmentPromotionSchemaAttachments,
		hideFinances: {if !ConfigHelper::checkConfig('privileges.superuser') && ConfigHelper::checkConfig('privileges.hide_finances')}true{else}false{/if}
	}

	var customer_assignment_helper = new CustomerAssignmentHelper(assignment_settings);

	$('#a_period').remove();

	$(function() {
		$('#submit-button,#print-button').click(function (e) {
			if (!$(this)[0].form.checkValidity() || (parseInt($('#promotion-select').val()) && !customer_assignment_helper.validate(e))) {
				$('#submit-button,#print-button').prop('disabled', false);
				return;
			}
			document.documentadd.submit();
		});

		$('[data-lmsbox-content="documentpromotionpanel"]').click(function() {
			init_multiselects('select.lms-ui-multiselect-deferred:visible');
		});
	});

	(function() {
		$("#documentpromotionpanel").toggle(getStorageItem("documentpromotionpanel", "local") == "1");
	})();

</script>
