File: /var/www/kpopbg.com/speedy/speedy_generate.tpl
{if ($ps_version == '1.6') OR ($ps_version == '1.7')}
<div class="col-lg-7">
<div class="panel">
<div class="panel-heading">
<span><img src="{$this_path}logo.png" /> {l s='Товарителница' mod='speedy'}</span>
</div>
{if $error_warning}
<p class="alert alert-danger">{$error_warning}</p>
{/if}
<div id="speedy" class="well hidden-print">
{else}
<fieldset>
<legend><img src="{$this_path}logo.png" />{l s='Товарителница' mod='speedy'}</legend>
<div class="speedy_error" style="{if !$error_warning}display: none;{/if}">{$error_warning}</div>
{/if}
<form action="{$action}" method="post" enctype="multipart/form-data" id="speedy_form">
<input id="speedy_taking_date" type="hidden" name="taking_date" value="{$taking_date}" />
<table class="speedy_generate">
<tr>
<td><label for="contents">{l s='Съдържание:' mod='speedy'} <span class="speedy_required"></span></label></td>
<td>
<input type="text" id="contents" name="contents" value="{$contents}" />
<br />
<span style="color: red; {if !$error_contents}display:none;{/if}" id="error_contents">{l s='Съдържанието трябва да е между 1 и 100 символа!' mod='speedy'}</span>
</td>
</tr>
<tr>
<td><label for="weight">{l s='Тегло (кг):' mod='speedy'} <span class="speedy_required"></span></label></td>
<td>
<input type="text" id="weight" name="weight" value="{$weight}" />
<br />
<span style="color: red; {if !$error_weight}display:none;{/if}" id="error_weight">{l s='Моля, попълнете тегло!' mod='speedy'}</span>
</td>
</tr>
<tr>
<td><label for="packing">{l s='Опаковка:' mod='speedy'}<span class="speedy_required"></span></label></td>
<td>
<input type="text" id="packing" name="packing" value="{$packing}" />
<br />
<span style="color: red; {if !$error_packing}display:none;{/if}" id="error_packing">{l s='Моля, въведете опаковка!' mod='speedy'}</span>
</td>
</tr>
<tr>
<td><label for="client_id">{l s='Обект, от който тръгват пратките:' mod='speedy'}<span class="speedy_required"></span></label></td>
<td>
<select id="client_id" name="client_id">
{foreach $clients as $client}
{if $client.clientId == $speedy_client_id}
<option value="{$client.clientId}" selected="selected">{l s='ID:' mod='speedy'} {$client.clientId}, {l s='Име:' mod='speedy'} {$client.name}, {l s='Адрес:' mod='speedy'} {$client.address}</option>
{else}
<option value="{$client.clientId}">{l s='ID:' mod='speedy'} {$client.clientId}, {l s='Име:' mod='speedy'} {$client.name}, {l s='Адрес:' mod='speedy'} {$client.address}</option>
{/if}
{/foreach}
</select>
</td>
</tr>
<tr>
<td><label for="payer_type">{l s='Страна платец:' mod='speedy'}</label></td>
<td>
<select id="payer_type" name="payer_type">
{if $payer_type}
<option value="1" selected="selected">{l s='Получател' mod='speedy'}</option>
<option value="0">{l s='Подател' mod='speedy'}</option>
{else}
<option value="1">{l s='Получател' mod='speedy'}</option>
<option value="0" selected="selected">{l s='Подател' mod='speedy'}</option>
{/if}
</select>
</td>
</tr>
<tr style="{if $shipping_method_id == 500}display:none{/if}">
<td><label for="count">{l s='Брой пакети:' mod='speedy'} <span class="speedy_required"></span></label></td>
<td>
<input type="text" id="count" name="count" value="{$count}" />
<br />
<span style="color: red; {if !$error_count}display:none;{/if}" id="error_count">{l s='Моля, попълнете брой пакети!' mod='speedy'}</span>
</td>
</tr>
<tr style="{if $shipping_method_id == 500}display:none{/if}">
<td><label>{l s='Размери на пакети (см.)' mod='speedy'}</label></td>
<td style="padding: 0;">
<table class="list" id="parcels_size">
<tbody>
{$parcels_size_row = 1}
{foreach $parcels_sizes as $parcels_size}
<tr id="parcel-size-row{$parcels_size_row}">
<td class="left"><input type="text" name="parcels_size[{$parcels_size_row}][width]" value="{$parcels_size.width}" placeholder="{l s='Широчина' mod='speedy'}" /></td>
<td class="left"><input type="text" name="parcels_size[{$parcels_size_row}][height]" value="{$parcels_size.height}" placeholder="{l s='Височина' mod='speedy'}" /></td>
<td class="left"><input type="text" name="parcels_size[{$parcels_size_row}][depth]" value="{$parcels_size.depth}" placeholder="{l s='Дълбочина' mod='speedy'}" /></td>
<td class="left"><input type="text" name="parcels_size[{$parcels_size_row}][weight]" value="{$parcels_size.weight}" placeholder="{l s='Тегло' mod='speedy'}" /></td>
</tr>
{$parcels_size_row = $parcels_size_row + 1}
{/foreach}
</tbody>
</table>
</td>
</tr>
<tr style="{if $shipping_method_id != 500}display:none{/if}">
<td><label>{l s='Минимален транспортен размер:' mod='speedy'}</label></td>
<td>
<select id="parcel_size" name="parcel_size">
{foreach $parcel_sizes as $option}
{if $option == $parcel_size}
<option value="{$option}" selected="selected">{$option}</option>
{else}
<option value="{$option}">{$option}</option>
{/if}
{/foreach}
</select>
</td>
</tr>
<tr>
<td><label for="deffered_days">{l s='Брой работни дни за отлагане на доставката' mod='speedy'}</label></td>
<td>
<select id="deffered_days" name="deffered_days">
{foreach $days as $day_id => $day}
{if $day_id == $deffered_days}
<option value="{$day_id}" selected="selected">{$day}</option>
{else}
<option value="{$day_id}">{$day}</option>
{/if}
{/foreach}
</select>
</td>
</tr>
<tr>
<td><label for="client_note">{l s='Забележка (клиент):' mod='speedy'}</label></td>
<td><input type="text" id="client_note" name="client_note" value="{$client_note}" size="50" /></td>
</tr>
<tr id="speedy_cod_status_container" {if !$cod_status}style="display: none;"{/if}>
<td><label>{l s='Наложен платеж:' mod='speedy'}</label></td>
<td>
<input type="radio" id="speedy_cod_yes" name="cod" value="1" {if $cod}checked="checked"{/if} onclick="$(this).parent().parent().next().show(); {if !$abroad}$('#speedy_options_before_payment_container').show();{/if}" />
<label for="speedy_cod_yes">{l s='Да' mod='speedy'}</label>
<input type="radio" id="speedy_cod_no" name="cod" value="0" {if !$cod}checked="checked"{/if} onclick="$(this).parent().parent().next().hide(); {if !$abroad}$('#speedy_options_before_payment_container').hide();{/if}" />
<label for="speedy_cod_no">{l s='Не' mod='speedy'}</label>
</td>
</tr>
<tr {if !$cod}style="display: none;"{/if}>
<td><label for="total">{l s='Сума на наложения платеж:' mod='speedy'}</label></td>
<td><input type="text" id="total" name="total" value="{$total}" /></td>
</tr>
<tr>
<td><label for="convertion_to_win1251">{l s='Автоматично транслитериране:' mod='speedy'}</label></td>
<td>
<select id="convertion_to_win1251" name="convertion_to_win1251">
{if $convertion_to_win1251}
<option value="1" selected="selected">{l s='Да' mod='speedy'}</option>
<option value="0">{l s='Не' mod='speedy'}</option>
{else}
<option value="1">{l s='Да' mod='speedy'}</option>
<option value="0" selected="selected">{l s='Не' mod='speedy'}</option>
{/if}
</select>
</td>
</tr>
<tr>
<td><label for="speedy_additional_copy_for_sender">{l s='Допълнително хартиено копие на товарителниците:' mod='speedy'}</label></td>
<td>
<select id="speedy_additional_copy_for_sender" name="speedy_additional_copy_for_sender">
{if $speedy_additional_copy_for_sender}
<option value="1" selected="selected">{l s='Да' mod='speedy'}</option>
<option value="0">{l s='Не' mod='speedy'}</option>
{else}
<option value="1">{l s='Да' mod='speedy'}</option>
<option value="0" selected="selected">{l s='Не' mod='speedy'}</option>
{/if}
</select>
</td>
</tr>
<tr id="speedy_options_before_payment_container" {if !$cod || $abroad}style="display: none;"{/if}>
<td><label for="option_before_payment">{l s='Опции преди плащане:' mod='speedy'}</label></td>
<td>
<select id="option_before_payment" name="option_before_payment">
{foreach $options_before_payment as $option_before_payment_id => $option_before_payment_value}
{if $option_before_payment_id == $option_before_payment}
<option value="{$option_before_payment_id}" selected="selected">{$option_before_payment_value}</option>
{else}
<option value="{$option_before_payment_id}">{$option_before_payment_value}</option>
{/if}
{/foreach}
</select>
</td>
</tr>
<tr>
<td><label for="insurance">{l s='Добавете oбявена стойност:' mod='speedy'}</label></td>
<td>
<select id="insurance" name="insurance" onchange="$('#fragile').parent().parent().toggle(); $('#speedy_total_insurance').parent().parent().toggle();">
{if $insurance}
<option value="1" selected="selected">{l s='Да' mod='speedy'}</option>
<option value="0">{l s='Не' mod='speedy'}</option>
{else}
<option value="1">{l s='Да' mod='speedy'}</option>
<option value="0" selected="selected">{l s='Не' mod='speedy'}</option>
{/if}
</select>
</td>
</tr>
<tr {if !$insurance}style="display: none;"{/if}>
<td><label for="fragile">{l s='Чупливи стоки:' mod='speedy'}<br/><span class="help">{l s='Може да бъде избрано, само ако е избрана и oбявена стойност.' mod='speedy'}</span></label></td>
<td>
<select id="fragile" name="fragile">
{if $fragile}
<option value="1" selected="selected">{l s='Да' mod='speedy'}</option>
<option value="0">{l s='Не' mod='speedy'}</option>
{else}
<option value="1">{l s='Да' mod='speedy'}</option>
<option value="0" selected="selected">{l s='Не' mod='speedy'}</option>
{/if}
</select>
</td>
</tr>
<tr {if !$insurance}style="display: none;"{/if}>
<td><label for="speedy_total_insurance">{l s='Сума на oбявената стойност:' mod='speedy'}</label></td>
<td><input type="text" id="speedy_total_insurance" name="totalNoShipping" value="{$totalNoShipping}" /></td>
</tr>
{if !$abroad or $allowed_country}
<tr id="speedy_city_container">
<td><label for="speedy_city">{l s='Населено място:' mod='speedy'}</label></td>
<td>
<input type="hidden" id="speedy_country" name="country" value="{$country}" size="39" />
<input type="hidden" id="speedy_country_id" name="country_id" value="{$country_id}" />
<input type="hidden" id="speedy_country_nomenclature" name="country_nomenclature" value="{$country_nomenclature}" />
<input type="hidden" id="speedy_state" name="state" value="{$state}" size="3" />
<input type="hidden" id="speedy_state_id" name="state_id" value="{$state_id}" />
<input type="hidden" id="required_state" name="required_state" value="{$required_state}" />
<input type="hidden" id="speedy_active_currency_code" name="active_currency_code" value="{$active_currency_code}" />
<input type="hidden" id="speedy_required_postcode" name="required_postcode" value="{$required_postcode}"/>
<input type="hidden" id="speedy_country_address_nomenclature" name="country_address_nomenclature" value="{$country_address_nomenclature}"/>
<input type="text" id="speedy_city" name="city" value="{$city}" size="39" />
<input type="hidden" id="speedy_city_id" name="city_id" value="{$city_id}" />
<input type="hidden" id="speedy_city_nomenclature" name="city_nomenclature" value="{$city_nomenclature}" />
<label for="speedy_postcode">{l s='ПК:' mod='speedy'}</label>
<input type="text" id="speedy_postcode" name="postcode" value="{$postcode}" disabled="disabled" size="3" />
</td>
</tr>
<tr id="to_office" {if !$offices} style="display: none;"{/if}>
<td><label>{l s='Доставка:' mod='speedy'}</label></td>
<td>
<input type="radio" id="speedy_shipping_to_apt" data-is-apt="1" name="to_office" value="1" {if !empty($to_office) && !empty($is_apt)}checked="checked"{/if} />
<label for="speedy_shipping_to_apt">{l s='до автомат' mod='speedy'}</label>
<input type="radio" id="speedy_shipping_to_office" data-is-apt="0" name="to_office" value="1" {if !empty($to_office) && empty($is_apt)}checked="checked"{/if} />
<label for="speedy_shipping_to_office">{l s='до офис' mod='speedy'}</label>
<input type="radio" id="speedy_shipping_to_door" data-is-apt="0" name="to_office" value="0" {if empty($to_office) && empty($is_apt)}checked="checked"{/if} />
<label for="speedy_shipping_to_door">{l s='до адрес' mod='speedy'}</label>
</td>
</tr>
<tr id="speedy_quarter_container" {if $to_office}style="display: none;"{/if}>
<td><label for="speedy_quarter">{l s='Квартал:' mod='speedy'}</label></td>
<td>
<input type="text" id="speedy_quarter" name="quarter" value="{$quarter}" size="52" />
<input type="hidden" id="speedy_quarter_id" name="quarter_id" value="{$quarter_id}" />
</td>
</tr>
<tr id="speedy_street_container" {if $to_office}style="display: none;"{/if}>
<td><label for="speedy_street">{l s='Улица:' mod='speedy'}</label></td>
<td>
<input type="text" id="speedy_street" name="street" value="{$street}" size="39" />
<input type="hidden" id="speedy_street_id" name="street_id" value="{$street_id}" />
<label for="speedy_street_no">{l s='№:' mod='speedy'}</label>
<input type="text" id="speedy_street_no" name="street_no" value="{$street_no}" size="3" />
</td>
</tr>
<tr id="speedy_block_no_container" {if $to_office}style="display: none;"{/if}>
<td><label for="speedy_block_no">{l s='Бл.:' mod='speedy'}</label></td>
<td>
<input type="text" id="speedy_block_no" name="block_no" value="{$block_no}" size="12" />
<label for="speedy_entrance_no">{l s='Вх.:' mod='speedy'}</label>
<input type="text" id="speedy_entrance_no" name="entrance_no" value="{$entrance_no}" size="3" />
<label for="speedy_floor_no">{l s='Ет.:' mod='speedy'}</label>
<input type="text" id="speedy_floor_no" name="floor_no" value="{$floor_no}" size="3" />
<label for="speedy_apartment_no">{l s='Ап.:' mod='speedy'}</label>
<input type="text" id="speedy_apartment_no" name="apartment_no" value="{$apartment_no}" size="3" />
<br />
<span style="color: red; {if !$error_address}display:none;{/if}" id="error_address">{l s='Моля, въведете валиден адрес!' mod='speedy'}</span>
</td>
</tr>
<tr id="speedy_object_container" {if $to_office}style="display: none;"{/if}>
<td><label for="speedy_object">{l s='Характерен обект:' mod='speedy'}</label></td>
<td>
<input type="text" id="speedy_object" name="object" value="{$object}" size="50" />
<input type="hidden" id="speedy_object_id" name="object_id" value="{$object_id}" />
</td>
</tr>
<tr id="speedy_note_container" {if $to_office}style="display: none;"{/if}>
<td><label for="speedy_note">{l s='Забележка към адреса' mod='speedy'}</label></td>
<td><input type="text" id="speedy_note" name="note" value="{$note}" size="52" /></td>
</tr>
<tr id="speedy_office_container" {if !$to_office}style="display: none;"{/if}>
<td><label for="speedy_office_id">{l s='Офис:' mod='speedy'}</label></td>
<td>
<select id="speedy_office_id" name="office_id">
{if !empty($offices) && !empty($is_apt)}
<option value="0" selected="selected">{l s=' --- Моля, изберете автомат --- ' mod='speedy'}</option>
{else}
<option value="0" selected="selected">{l s=' --- Моля, изберете офис --- ' mod='speedy'}</option>
{/if}
{foreach $offices as $office}
{if $office.id == $office_id}
<option value="{$office.id}" data-is-apt="{$office.is_apt}" selected="selected">{$office.label}</option>
{else}
<option value="{$office.id}" data-is-apt="{$office.is_apt}">{$office.label}</option>
{/if}
{/foreach}
</select>
<input type="hidden" id="is_apt" name="is_apt" value="{!empty($is_apt)}" />
</td>
</tr>
{else}
<tr id="speedy_country_container">
<td style="text-align: right;"><label class="speedy_required" for="speedy_country">{l s='Държава:' mod='speedy'}</label></td>
<td>
<input type="text" id="speedy_country" name="country" value="{$country}" size="39" />
<input type="hidden" id="speedy_country_id" name="country_id" value="{$country_id}" />
<input type="hidden" id="speedy_country_nomenclature" name="country_nomenclature" value="{$country_nomenclature}" />
<label for="speedy_state" id="speedy_state_label" {if $required_state}class="speedy_required"{/if}>{l s='Щат:' mod='speedy'}</label>
<input type="text" id="speedy_state" name="state" value="{$state}" size="3" />
<input type="hidden" id="speedy_state_id" name="state_id" value="{$state_id}" />
<input type="hidden" id="required_state" name="required_state" value="{$required_state}" />
<input type="hidden" id="speedy_active_currency_code" name="active_currency_code" value="{$active_currency_code}" />
</td>
</tr>
<tr id="speedy_city_container">
<td style="text-align: right;"><label class="speedy_required" for="speedy_city">{l s='Населено място:' mod='speedy'}</label></td>
<td>
<input type="text" id="speedy_city" name="city" value="{$city}" size="39" />
<input type="hidden" id="speedy_city_id" name="city_id" value="{$city_id}" />
<input type="hidden" id="speedy_city_nomenclature" name="city_nomenclature" value="{$city_nomenclature}" />
<label for="speedy_postcode" id="speedy_postcode_label" {if $required_postcode} class="speedy_required"{/if}>{l s='ПК:' mod='speedy'}</label>
<input type="text" id="speedy_postcode" name="postcode" value="{$postcode}"size="3" />
<input type="hidden" id="required_postcode" name="required_postcode" value="{$required_postcode}" />
</td>
</tr>
<tr id="speedy_address_1_container">
<td style="text-align: right;"><label class="speedy_required" for="speedy_address_1">{l s='Адрес 1:' mod='speedy'}</label></td>
<td>
<input type="text" id="speedy_address_1" name="address_1" value="{$address_1}" size="50" />
</td>
</tr>
<tr id="speedy_address_2_container">
<td style="text-align: right;"><label for="speedy_address_2">{l s='Адрес 2:' mod='speedy'}</label></td>
<td>
<input type="text" id="speedy_address_2" name="address_2" value="{$address_2}" size="50" />
</td>
</tr>
{/if}
<input type="hidden" id="abroad" name="abroad" value="{$abroad}" />
<tr style="display: none;">
<td><label>{l s='Метод за доставката:' mod='speedy'}</label></td>
<td id="speedy_methods">
</td>
</tr>
<tr>
<td><label><b>{l s='Изчисли цена' mod='speedy'}</b></label></td>
<td>
<input type="hidden" id="recalculate" name="recalculate" value="0" />
<a id="calculate" onclick="$('#speedy_form :input').removeAttr('disabled'); speedyCalculate(); $('#recalculate').val('0')" class="{if ($ps_version == '1.6') OR ($ps_version == '1.7')}btn btn-default{else}button{/if}">{l s='Изчисли цена' mod='speedy'}</a>
</td>
</tr>
</table>
{if ($ps_version == '1.6') OR ($ps_version == '1.7')}
<button id="createBillOfLading" type="submit" class="btn btn-primary pull-right" style="margin-top: -30px;" onclick="speedySubmit(); return false;" /> {l s='Генериране' mod='speedy'} </button>
<input type="hidden" name="speedy_generate" />
{else}
<input id="createBillOfLading" type="submit" name="speedy_generate" class="button" onclick="speedySubmit(); return false;" value="{l s='Генериране' mod='speedy'}" />
{/if}
</form>
{if ($ps_version == '1.6') OR ($ps_version == '1.7')}
</div>
</div>
</div>
{else}
</fieldset>
{/if}
{if ($ps_version == '1.6') OR ($ps_version == '1.7')}
<div class="col-lg-7">
<div class="panel">
<div class="panel-heading">
<span><img src="{$this_path}logo.png" /> {l s='Дневни поръчки' mod='speedy'}</span>
</div>
<div id="speedy-orders" class="well hidden-print">
{else}
<fieldset>
<legend><img src="{$this_path}logo.png" style="height:16px;" />{l s='Дневни поръчки' mod='speedy'}</legend>
{/if}
<form action="{$action}" method="post" enctype="multipart/form-data" id="courier_form">
<table id="loadings_curier">
{if $courier_warning}
<tr>
<td colspan="5" class="speedy_error">{$courier_warning}</td>
</tr>
{/if}
{if $courier_success}
<tr>
<td colspan="5" class="speedy_success">{$courier_success}</td>
</tr>
{/if}
<tr>
{if !$from_office}<td></td>{/if}
<td>{l s='Поръчка №' mod='speedy'}</td>
<td>{l s='Товарителница №' mod='speedy'}</td>
<td>{l s='Клиент' mod='speedy'}</td>
<td>{l s='Сума' mod='speedy'}</td>
</tr>
{if $order_list}
{foreach $order_list as $order_detail}
<tr>
{if !$from_office}
<td>
<input type="checkbox" name="selected[]" value="{$order_detail.order_id}" />
</td>
{/if}
<td>
<a target="_blank" href="{$order_detail.order_href}" title="{$order_detail.order_id}">{$order_detail.order_id}</a>
</td>
<td>
<a href="javascript: void(0);" onclick="printLoading({$order_detail.bol_id});" title="{$order_detail.bol_id}">{$order_detail.bol_id}</a>
</td>
<td>
<a target="_blank" href="{$order_detail.customer_href}" title="{$order_detail.customer}">{$order_detail.customer}</a>
</td>
<td>
{$order_detail.cost}
</td>
</tr>
{/foreach}
{if !$from_office}
<tr>
<td colspan="5"><input type="submit" value="{l s='Заявка за куриер' mod='speedy'}" name="query_courier" /></td>
</tr>
{/if}
{else}
<tr><td colspan="5" style="text-align: center;">{l s='Няма поръчки за деня!' mod='speedy'}</td></tr>
{/if}
</table>
</form>
<form action="{$action}" method="post" enctype="multipart/form-data" id="loading_form">
<input type="hidden" name="bol_id" id="bol_id" value="" />
<input type="hidden" name="do_action" id="do_action" value="" />
</form>
<script type="text/javascript"><!--
{literal}
function printLoading(bol_id) {
if (bol_id) {
$('#loading_form').attr('target', '_blank');
$('#bol_id').val(bol_id);
$('#do_action').val('print_pdf');
$('#loading_form').submit();
}
}
{/literal}
//--></script>
{if ($ps_version == '1.6') OR ($ps_version == '1.7')}
</div>
</div>
</div>
{else}
</fieldset>
{/if}
<script type="text/javascript"><!--
{literal}
function showTableForm(method_id) {
if (method_id) {
$('#loading_speedy').hide();
$('table.speedy_table').hide();
$('.speedy_' + method_id).show();
}
}
function speedyCalculate() {
$('#loading_speedy').show();
$('#error_message').remove();
$('.error_message').remove();
$('.speedy_error').hide();
$('#error_address').hide();
$('#error_office').hide();
$('#error_packing').hide();
$('#error_count').hide();
$('#error_contents').hide();
$('#error_weight').hide();
$('#error_fixed_time').hide();
$('#speedy_methods').parent().hide();
$('#speedy_form :input').removeAttr('disabled');
//$('.fixed_time').attr('disabled', true);
$.ajax({
url: 'index.php?controller=AdminModules&configure=speedy&token={/literal}{$speedy_token}{literal}&tab_module=shipping_logistics&module_name=speedy&ajax_function=speedy_calculate&order_id={/literal}{$order_id}{literal}',
type: 'POST',
data: $('#speedy_form input, #speedy_form textarea, #speedy_form select, input#email, input#firstname, input#lastname, input#phone, input#phone_mobile').serialize(),
dataType: 'json',
success: function(data) {
if (data) {
// $('#speedy_postcode').attr('disabled', 'disabled');
if ($('input.delivery_option_radio').size() > 1) {
$('input.delivery_option_radio').each(function( index ) {
if ($(this).is(':checked') && parseInt($(this).val()) == speedy_carrier_id) {
$(this).parent().find('.delivery_option_price').text('');
}
});
} else if ($('input.delivery_option_radio').size() == 1) {
var str = $('input.delivery_option_radio').val().trim();
var exploded = str.split(',');
for (i = 0; i < exploded.length-1; i++) {
if (exploded[i] == speedy_carrier_id) {
$('input.delivery_option_radio').parent().find('.delivery_option_price').text('');
}
}
}
$('#loading_speedy').hide();
if (data.error) {
if (data.error.warning) {
$('.speedy_error').html(data.error.warning).show();
$('#speedy_form').after('<span class="speedy_error error_message">'+data.error_warning+'</span>');
}
} else if (data.error_address || data.error_office || data.error_contents || data.error_weight || data.error_count || data.error_packing || data.error_warning) {
if (data.error_address) {
$('#error_address').show();
}
if (data.error_office) {
$('#error_office').show();
}
if (data.error_contents) {
$('#error_contents').show();
}
if (data.error_weight) {
$('#error_weight').show();
}
if (data.error_count) {
$('#error_count').show();
}
if (data.error_packing) {
$('#error_packing').show();
}
if (data.error_warning) {
$('.speedy_error').html(data.error_warning).show();
$('#speedy_form').after('<span class="speedy_error error_message">'+data.error_warning+'</span>');
}
} else if (data.methods) {
html = '';
if (data.methods.length) {
for (i = 0; i < data.methods.length; i++) {
html += '<div>';
html += '<input type="radio" name="shipping_method_id" id="'+data.methods[i]['code']+'" value="'+data.methods[i]['code']+'" ';
if (data.shipping_method_id == data.methods[i]['code']) {
html += 'checked="checked"';
}
html += ' /> <label for="'+data.methods[i]['code']+'">'+data.methods[i]['title']+' | ' + data.methods[i]['text'] + '</label>';
if (data.methods[i]['default_fixed_time']) {
html += '<div class="speedy_fixed_time_cb" style="display: none;">';
html += '<input style="display: none;" class="fixed_time" type="checkbox" ';
if (!data.methods[i]['fixed_time_cb']) {
html += 'disabled="disabled"';
} else {
html += 'checked="checked"';
}
html += ' id="speedy_fixed_time_cb_'+data.methods[i]['code']+'" name="fixed_time_cb['+data.methods[i]['code']+']" value="1" onclick="speedyCheckFixedTime('+data.methods[i]['code']+');" />';
html += "<label style=\"display: none;\" id='speedy_fixed_time_cb_label_" + data.methods[i]['code'] + "' class=\"fixed_time\" for=\"speedy_fixed_time_cb_"+data.methods[i]['code']+"\">{/literal} {l s='Фиксиран час:' mod='speedy'} {literal}</label>";
html += '<select style="display: none;" class="fixed_time" id="speedy_fixed_time_hour_'+data.methods[i]['code']+'" name="fixed_time_hour['+data.methods[i]['code']+']" ';
if (!data.methods[i]['fixed_time_cb']) {
html += 'disabled="disabled"';
}
html += ' onchange="speedySetFixedTime('+data.methods[i]['code']+');">';
for (n=10; n<18; n++) {
hour_str_pad = str_pad(n, 2, '0', 'STR_PAD_LEFT');
if (hour_str_pad == data.methods[i]['fixed_time_hour'] || !data.methods[i]['fixed_time_hour']) {
html += '<option value="'+hour_str_pad+'" selected="selected">'+hour_str_pad+'</option>';
} else {
html += '<option value="'+hour_str_pad+'">'+hour_str_pad+'</option>';
}
}
html += '</select>';
if (data.methods[i]['fixed_time_hour'] == 10) {
min_fixed_time_mins = 30;
} else {
min_fixed_time_mins = 0;
}
if (data.methods[i]['fixed_time_hour'] == 17) {
max_fixed_time_mins = 30;
} else {
max_fixed_time_mins = 59;
}
html += '<select style="display: none;" class="fixed_time" id="speedy_fixed_time_min_'+data.methods[i]['code']+'" name="fixed_time_min['+data.methods[i]['code']+']" ';
if (!data.methods[i]['fixed_time_cb']) {
html += 'disabled="disabled"';
}
html += '>';
for (n=min_fixed_time_mins; n <= max_fixed_time_mins; n++) {
hour_str_pad = str_pad(n, 2, '0', 'STR_PAD_LEFT');
if (hour_str_pad == data.methods[i]['fixed_time_min']) {
html += '<option value="'+hour_str_pad+'" selected="selected">'+hour_str_pad+'</option>';
} else {
html += '<option value="'+hour_str_pad+'">'+hour_str_pad+'</option>';
}
}
html += '</select> ';
html += '</div>';
}
if (data.methods[i]['default_fixed_time']) {
if (data.methods[i]['error_fixed_time']) {
html += "<span style=\"color: red;\" class=\"error_fixed_time\">{/literal}{l s='Моля, изберете валиден час!' mod='speedy'}{literal}</span>";
}
}
if (data.methods[i]['total_form'].length) {
html += ' <table style="display: none;" class="speedy_'+data.methods[i]['code']+' speedy_table">';
for (j = 0; j< data.methods[i]['total_form'].length; j++) {
html += ' <tr>';
html += ' <td>'+data.methods[i]['total_form'][j]['label']+'</td>';
html += ' <td>'+data.methods[i]['total_form'][j]['value']+'</td>';
html += ' </tr>';
}
html += ' </table>';
}
html += '</div>';
}
} else {
html += "<label>{/literal}{l s='Няма намерени услуги!' mod='speedy'}{literal}</label>";
}
$('#speedy_methods').html(html);
$('#speedy_methods').parent().show();
$('input[name=\'shipping_method_id\']').change(function () {
if ($(this).is(':checked')) {
showTableForm($(this).attr('id'));
setSpeedyMethod($(this).val());
}
});
if ($('input[name=\'shipping_method_id\']:checked').length) {
setSpeedyMethod($('input[name=\'shipping_method_id\']:checked').val());
}
} else {
if (data.redirect) {
window.location.href = data.redirect;
} else {
$('#speedy').html(data.html);
}
}
}
}
});
}
function str_pad(input, pad_length, pad_string, pad_type) {
// From: http://phpjs.org/functions
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + namespaced by: Michael White (http://getsprink.com)
// + input by: Marco van Oort
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// * example 1: str_pad('Kevin van Zonneveld', 30, '-=', 'STR_PAD_LEFT');
// * returns 1: '-=-=-=-=-=-Kevin van Zonneveld'
// * example 2: str_pad('Kevin van Zonneveld', 30, '-', 'STR_PAD_BOTH');
// * returns 2: '------Kevin van Zonneveld-----'
var half = '',
pad_to_go;
var str_pad_repeater = function (s, len) {
var collect = '',
i;
while (collect.length < len) {
collect += s;
}
collect = collect.substr(0, len);
return collect;
};
input += '';
pad_string = pad_string !== undefined ? pad_string : ' ';
if (pad_type !== 'STR_PAD_LEFT' && pad_type !== 'STR_PAD_RIGHT' && pad_type !== 'STR_PAD_BOTH') {
pad_type = 'STR_PAD_RIGHT';
}
if ((pad_to_go = pad_length - input.length) > 0) {
if (pad_type === 'STR_PAD_LEFT') {
input = str_pad_repeater(pad_string, pad_to_go) + input;
} else if (pad_type === 'STR_PAD_RIGHT') {
input = input + str_pad_repeater(pad_string, pad_to_go);
} else if (pad_type === 'STR_PAD_BOTH') {
half = str_pad_repeater(pad_string, Math.ceil(pad_to_go / 2));
input = half + input + half;
input = input.substr(0, pad_length);
}
}
return input;
}
$('#parcel_size, #client_id').on('change', function() {
if ($('#recalculate').val() == 0) {
alert("{/literal}{l s='Моля, преди да генерирате товарителница преизчислете цената за доставка' mod='speedy'}{literal}");
$('#createBillOfLading').attr('disabled', 'disabled');
$('#recalculate').val('1');
}
});
function speedySubmit() {
if ($('input[name=\'shipping_method_id\']:checked').parent().find('.error_fixed_time').length != 0) {
alert("{/literal}{l s='Моля, изберете валиден час и натиснете изчисли!' mod='speedy'}{literal}");
} else {
if ($('input[name=\'shipping_method_id\']:checked').length) {
shipping_method_id = $('input[name=\'shipping_method_id\']:checked').val();
} else {
shipping_method_id = '{/literal}{$shipping_method_id}{literal}';
}
var post_data = {
'shipping_method_id' : shipping_method_id,
'abroad' : $('#abroad').val()
};
if(!parseInt($('#abroad').val())) {
post_data.speedy_shipping_to_office = $('input[name=to_office]:checked').val();
post_data.speedy_option_before_payment = $('#option_before_payment').val();
post_data.speedy_city_id = $('#speedy_city_id').val();
post_data.speedy_office_id = $('#speedy_office_id').val();
}
$.ajax({
url: 'index.php?controller=AdminModules&configure=speedy&token={/literal}{$speedy_token}{literal}&tab_module=shipping_logistics&module_name=speedy&ajax_function=speedy_validate_bill_of_lading',
type: 'POST',
data: post_data,
dataType: 'json',
success: function(data) {
if (data.error) {
var confurm = 1;
if (data.taking_date) {
$('#speedy_taking_date').val(data.taking_date);
}
for(error in data.errors) {
if (!confirm(data.errors[error])) {
confurm = 0;
}
}
if(confurm) {
$('#speedy_form :input').removeAttr('disabled');
$('#speedy_form').submit();
}
} else {
$('#speedy_form :input').removeAttr('disabled');
$('#speedy_form').submit();
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
}
function speedyCheckFixedTime(method_id) {
if ($('#speedy_fixed_time_cb_'+method_id+':checked').length) {
$('#speedy_fixed_time_hour_'+method_id).removeAttr('disabled');
$('#speedy_fixed_time_min_'+method_id).removeAttr('disabled');
} else {
$('#speedy_fixed_time_hour_'+method_id).attr('disabled', 'disabled');
$('#speedy_fixed_time_min_'+method_id).attr('disabled', 'disabled');
}
}
function speedySetFixedTime(method_id) {
if ($('#speedy_fixed_time_hour_'+method_id).val() == 10) {
min_fixed_time_mins = 30;
} else {
min_fixed_time_mins = 0;
}
if ($('#speedy_fixed_time_hour_'+method_id).val() == 17) {
max_fixed_time_mins = 30;
} else {
max_fixed_time_mins = 59;
}
html = '';
for (i = min_fixed_time_mins; i <= max_fixed_time_mins; i++) {
iStr = i.toString();
if (iStr.length < 2) {
fixed_time_min = '0' + i;
} else {
fixed_time_min = i;
}
html += '<option value="' + fixed_time_min + '">' + fixed_time_min + '</option>';
}
$('#speedy_fixed_time_min_'+method_id).html(html);
}
function setSpeedyMethod(method_id) {
if (method_id) {
$('input[name^=\'fixed_time_cb\']').attr('disabled', true);
$('input[name^=\'fixed_time_cb\']').addClass('fixed_time');
//$('select[name=\'fixed_time_hour\']').attr('disabled', true);
$('select[name^=\'fixed_time_hour\']').addClass('fixed_time');
//$('select[name=\'fixed_time_min\']').attr('disabled', true);
$('select[name^=\'fixed_time_min\']').addClass('fixed_time');
$('input[name^=\'fixed_time_cb\']').parent().hide();
$('.error_fixed_time').hide();
$('.fixed_time').hide();
//$('input[name=\'fixed_time_cb\']:checked').removeAttr('checked');
$('#speedy_fixed_time_cb_'+method_id).parent().show();
$('#speedy_fixed_time_cb_'+method_id).parent().parent().find('.error_fixed_time').show();
$('#speedy_fixed_time_cb_'+method_id).show();
$('#speedy_fixed_time_cb_'+method_id).removeAttr('disabled');
$('#speedy_fixed_time_cb_'+method_id).removeClass('fixed_time');
$('#speedy_fixed_time_cb_label_'+method_id).show();
$('#speedy_fixed_time_hour_'+method_id).show();
$('#speedy_fixed_time_hour_'+method_id).removeClass('fixed_time');
$('#speedy_fixed_time_min_'+method_id).show();
$('#speedy_fixed_time_min_'+method_id).removeClass('fixed_time');
$('.speedy_' + method_id).show();
}
}
var speedy_count_previous;
$('#count').keydown(function (e) {
if (!e.key.match(/\d/)) {
e.preventDefault()
}
}).on('focus', function () {
speedy_count_previous = parseInt($(this).val());
}).change(function() {
// Do something with the previous value after the change
if (parseInt(speedy_count_previous) < parseInt($(this).val())) {
addParcelsSize(parseInt(speedy_count_previous) + 1, parseInt($(this).val()));
} else {
removeParcelsSize(parseInt($(this).val()), parseInt(speedy_count_previous));
}
// Make sure the previous value is updated
speedy_count_previous = parseInt($(this).val());
});
function addParcelsSize(old_rows, new_rows) {
for (i = old_rows; i <= new_rows; i++) {
html = '<tr id="parcel-size-row' + i + '">';
html += ' <td class="left"><input type="text" name="parcels_size[' + i + '][width]" value="" placeholder="{/literal}{l s='Широчина' mod='speedy'}{literal}" /></td>';
html += ' <td class="left"><input type="text" name="parcels_size[' + i + '][height]" value="" placeholder="{/literal}{l s='Височина' mod='speedy'}{literal}" class="form-control" /></td>';
html += ' <td class="left"><input type="text" name="parcels_size[' + i + '][depth]" value="" placeholder="{/literal}{l s='Дълбочина' mod='speedy'}{literal}" class="form-control" /></td>';
html += ' <td class="left"><input type="text" name="parcels_size[' + i + '][weight]" value="" placeholder="{/literal}{l s='Тегло' mod='speedy'}{literal}" class="form-control" /></td>';
html += '</tr>';
$('#parcels_size tbody').append(html);
}
}
function removeParcelsSize(old_rows, new_rows) {
for (i = new_rows; i > old_rows; i--) {
$('#parcel-size-row' + i).remove();
}
}
var speedy_city = '{/literal}{$city}{literal}';
var speedy_object = '{/literal}{$object}{literal}';
var speedy_quarter = '{/literal}{$quarter}{literal}';
var speedy_street = '{/literal}{$street}{literal}';
var speedy_country = '{/literal}{$country}{literal}';
var speedy_state = '{/literal}{$state}{literal}';
var abroad = '{/literal}{$abroad}{literal}';
$(document).ready(function() {
$('#speedy_object').autocompletespeedy({
source: function(request, response) {
var $this = $(this);
var $element = $(this.element);
var jqXHR = $element.data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$element.data('jqXHR', $.ajax({
url: '{/literal}{$this_path}{literal}ajax.php?ajax_function=get_object_by_name',
dataType: 'json',
data: {
term: request.term,
city_id: function() { return $('#speedy_city_id').val(); },
abroad: abroad
},
complete: function() {
$this.removeData('jqXHR');
},
success: function(data) {
if (data.error) {
alert(data.error);
} else {
if (data.length) {
response(data);
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
}));
},
minLength: 1,
select: function(event, ui) {
if (ui.item) {
speedy_object = ui.item.label;
$('#speedy_object_id').val(ui.item.id);
if (ui.item.value) {
if ($('#speedy_note').val()) {
$('#speedy_note').val(ui.item.value+", "+$('#speedy_note').val());
} else {
$('#speedy_note').val(ui.item.value);
}
}
$(this).val(ui.item.label);
return false;
}
},
change: function(event, ui) {
if(!ui.item) {
$('#speedy_object').val('');
$('#speedy_object_id').val('');
}
}
});
$('#speedy_object').blur(function() {
var $this = $(this);
var jqXHR = $(this).data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$this.removeData('jqXHR');
if ($this.val() != speedy_object) {
$('#speedy_object').val('');
$('#speedy_object_id').val('');
}
});
$('#speedy_city').autocompletespeedy({
source: function(request, response) {
var $this = $(this);
var $element = $(this.element);
var jqXHR = $element.data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$element.data('jqXHR', $.ajax({
url: '{/literal}{$this_path}{literal}ajax.php?ajax_function=get_cities_by_name',
dataType: 'json',
data: {
term: request.term,
country_id: $('#speedy_country_id').val(),
abroad: abroad
},
complete: function() {
$this.removeData('jqXHR');
},
success: function(data) {
if (data.error) {
alert(data.error);
} else {
if ($('#speedy_country_nomenclature').val() == 'FULL') {
if (data.length) {
response(data);
}
} else {
response(data);
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
}));
},
minLength: 1,
select: function(event, ui) {
if (ui.item) {
$('#speedy_methods').html('');
$('#speedy_methods').parent().hide();
speedy_city = ui.item.value;
$('#speedy_postcode').val(ui.item.postcode);
$('#speedy_city_id').val(ui.item.id);
$('#speedy_city_nomenclature').val(ui.item.nomenclature);
$('#speedy_quarter').val('');
$('#speedy_quarter_id').val('');
$('#speedy_street').val('');
$('#speedy_street_id').val('');
$('#speedy_object').val('');
$('#speedy_object_id').val('');
$('#speedy_street_no').val('');
$('#speedy_block_no').val('');
$('#speedy_entrance_no').val('');
$('#speedy_floor_no').val('');
$('#speedy_apartment_no').val('');
$('#speedy_note').val('');
$('#speedy_office_id').html("<option value=\"0\">{/literal}{l s='Моля, изчакайте' mod='speedy'}{literal}</option>");
$.ajax({
url: '{/literal}{$this_path}{literal}ajax.php?ajax_function=get_offices_by_city_id',
dataType: 'json',
data: {
country_id: $('#speedy_country_id').val(),
city_id: ui.item.id,
abroad: abroad
},
success: function(data) {
if (data.error) {
alert(data.error);
} else {
html = '<option value="0"></option>';
if (data.length) {
var hasApt = false;
var hasOffices = false;
for (i = 0; i < data.length; i++) {
html += '<option value="' + data[i]['id'] + '" data-is-apt="' + data[i]['is_apt'] + '">' + data[i]['label'] + '</option>';
if (data[i]['is_apt'] == 1) {
hasApt = true;
}
if (data[i]['is_apt'] == 0) {
hasOffices = true;
}
}
$('#speedy_office_id').html(html);
if ($('#to_office:hidden').length == 1
|| (hasApt && $('#speedy_shipping_to_apt:checked'))
|| (hasOffices && $('#speedy_shipping_to_office:checked'))
) {
if (hasApt) {
$('#speedy_shipping_to_apt').trigger('click').change();
} else if (hasOffices) {
$('#speedy_shipping_to_office').trigger('click').change();
}
}
$('#speedy_shipping_to_apt').parent().toggle(hasApt);
$('#speedy_shipping_to_office').parent().toggle(hasOffices);
$('#to_office').show();
} else {
$('#speedy_shipping_to_door').trigger('click').trigger('change');
hideOffices($('#to_office input[name=to_office]:checked'));
$('#to_office').hide();
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
}
},
change: function(event, ui) {
if (!ui.item && $('#speedy_country_nomenclature').val() == 'FULL') {
$('#speedy_city').val('');
$('#speedy_city_id').val('');
$('#speedy_city_nomenclature').val('');
$('#speedy_postcode').val('');
$('#speedy_office_id').html("<option value=\"0\">{/literal}{l s=' --- Моля, въведете населено място --- ' mod='speedy'}{literal}</option>");
}
$('#speedy_methods').html('');
$('#speedy_methods').parent().hide();
$('#speedy_quarter').val('');
$('#speedy_quarter_id').val('');
$('#speedy_street').val('');
$('#speedy_street_id').val('');
$('#speedy_object').val('');
$('#speedy_object_id').val('');
$('#speedy_street_no').val('');
$('#speedy_block_no').val('');
$('#speedy_entrance_no').val('');
$('#speedy_floor_no').val('');
$('#speedy_apartment_no').val('');
$('#speedy_note').val('');
}
});
$('#speedy_city').blur(function() {
var $this = $(this);
var jqXHR = $(this).data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$this.removeData('jqXHR');
if ($(this).val() != speedy_city) {
if (!abroad || (abroad && ($('#speedy_country_nomenclature').val() == 'FULL'))) {
$('#speedy_city').val('');
}
$('#speedy_city_id').val('');
$('#speedy_city_nomenclature').val('');
$('#speedy_postcode').val('');
$('#speedy_office_id').html("<option value=\"0\">{/literal}{l s=' --- Моля, въведете населено място --- ' mod='speedy'}{literal}</option>");
$('#speedy_quarter').val('');
$('#speedy_quarter_id').val('');
$('#speedy_street').val('');
$('#speedy_street_id').val('');
$('#speedy_street_no').val('');
$('#speedy_block_no').val('');
$('#speedy_entrance_no').val('');
$('#speedy_floor_no').val('');
$('#speedy_apartment_no').val('');
$('#speedy_note').val('');
}
});
$('#speedy_quarter').autocompletespeedy({
source: function(request, response) {
var $this = $(this);
var $element = $(this.element);
var jqXHR = $element.data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$element.data('jqXHR', $.ajax({
url: '{/literal}{$this_path}{literal}ajax.php?ajax_function=get_quarters_by_name',
dataType: 'json',
data: {
term: request.term,
city_id: function() { return $('#speedy_city_id').val(); },
abroad: abroad
},
complete: function() {
$this.removeData('jqXHR');
},
success: function(data) {
if (data.error) {
$('#speedy_quarter').val('');
$('#speedy_quarter_id').val('');
alert(data.error);
} else {
if ($('#speedy_city_nomenclature').val() == 'FULL') {
if (data.length) {
response(data);
}
} else {
response(data);
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
}));
},
minLength: 1,
select: function(event, ui) {
if (ui.item) {
speedy_quarter = ui.item.value;
$('#speedy_quarter_id').val(ui.item.id);
}
},
change: function(event, ui) {
if(!ui.item && $('#speedy_city_nomenclature').val() == 'FULL') {
$('#speedy_quarter').val('');
$('#speedy_quarter_id').val('');
}
}
});
$('#speedy_quarter').blur(function() {
var $this = $(this);
var jqXHR = $(this).data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$this.removeData('jqXHR');
if (($this.val() != speedy_quarter) && ($('#speedy_city_nomenclature').val() == 'FULL')) {
$('#speedy_quarter').val('');
$('#speedy_quarter_id').val('');
}
});
$('#speedy_street').autocompletespeedy({
source: function(request, response) {
var $this = $(this);
var $element = $(this.element);
var jqXHR = $element.data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$element.data('jqXHR', $.ajax({
url: '{/literal}{$this_path}{literal}ajax.php?ajax_function=get_streets_by_name',
dataType: 'json',
data: {
term: request.term,
city_id: function() { return $('#speedy_city_id').val(); },
abroad: abroad
},
complete: function() {
$this.removeData('jqXHR');
},
success: function(data) {
if (data.error) {
$('#speedy_street').val('');
$('#speedy_street_id').val('');
alert(data.error);
} else {
if ($('#speedy_city_nomenclature').val() == 'FULL') {
if (data.length) {
response(data);
}
} else {
response(data);
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
}));
},
minLength: 1,
select: function(event, ui) {
if (ui.item) {
speedy_street = ui.item.value;
$('#speedy_street_id').val(ui.item.id);
}
},
change: function(event, ui) {
if(!ui.item && $('#speedy_city_nomenclature').val() == 'FULL') {
$('#speedy_street').val('');
$('#speedy_street_id').val('');
}
}
});
$('#speedy_street').blur(function() {
var $this = $(this);
var jqXHR = $(this).data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$this.removeData('jqXHR');
if (($this.val() != speedy_street) && ($('#speedy_city_nomenclature').val() == 'FULL')) {
$('#speedy_street').val('');
$('#speedy_street_id').val('');
}
});
$('#speedy_block_no').autocompletespeedy({
source: function(request, response) {
var $this = $(this);
var $element = $(this.element);
var jqXHR = $element.data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$element.data('jqXHR', $.ajax({
url: '{/literal}{$this_path}{literal}ajax.php?ajax_function=get_blocks_by_name',
dataType: 'json',
data: {
term: request.term,
city_id: function() { return $('#speedy_city_id').val(); },
abroad: abroad
},
complete: function() {
$this.removeData('jqXHR');
},
success: function(data) {
if (data.error) {
$('#speedy_block_no').val('');
alert(data.error);
} else {
response(data);
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
}));
},
minLength: 1
});
$('#speedy_block_no').blur(function() {
var $this = $(this);
var jqXHR = $(this).data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$this.removeData('jqXHR');
});
$('#speedy_country').autocompletespeedy({
source: function(request, response) {
var $this = $(this);
var $element = $(this.element);
var jqXHR = $element.data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$element.data('jqXHR', $.ajax({
url: '{/literal}{$this_path}{literal}ajax.php?ajax_function=get_countries_by_name',
dataType: 'json',
data: {
term: request.term,
abroad: abroad
},
success: function(data) {
$('.wait').remove();
if (data.error) {
alert(data.error);
} else {
if (data.length) {
response(data);
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
}));
},
minLength: 1,
select: function(event, ui) {
if (ui.item) {
$('#speedy_methods').html('');
$('#speedy_methods').parent().hide();
$('#speedy_state_label, #speedy_postcode_label').removeClass('speedy_required');
speedy_country = ui.item.value;
$('#speedy_country').val(ui.item.value);
$('#speedy_country_id').val(ui.item.id);
$('#speedy_country_nomenclature').val(ui.item.nomenclature);
$('#required_state').val(ui.item.required_state);
$('#required_postcode').val(ui.item.required_postcode);
$('#speedy_active_currency_code').val(ui.item.active_currency_code);
if (!ui.item.active_currency_code) {
$('#speedy_cod_status_container').hide();
$('#speedy_cod_no').click();
} else {
$('#speedy_cod_status_container').show();
}
if (ui.item.required_state) {
$('#speedy_state_label').addClass('speedy_required');
} else {
$('#speedy_state_label').removeClass('speedy_required');
}
if (ui.item.required_postcode) {
$('#speedy_postcode_label').addClass('speedy_required');
} else {
$('#speedy_postcode_label').removeClass('speedy_required');
}
}
},
change: function(event, ui) {
if (!ui.item) {
$('#speedy_country').val('');
$('#speedy_country_id').val('');
$('#speedy_country_nomenclature').val('');
}
$('#speedy_methods').html('');
$('#speedy_methods').parent().hide();
$('#speedy_state').val('');
$('#speedy_state_id').val('');
$('#speedy_city').val('');
$('#speedy_city_id').val('');
$('#speedy_city_nomenclature').val('');
$('#speedy_postcode').val('');
}
});
$('#speedy_country').blur(function() {
var $this = $(this);
var jqXHR = $(this).data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$this.removeData('jqXHR');
if ($this.val() != speedy_country) {
$this.val('');
$('#speedy_country_id').val('');
$('#speedy_country_nomenclature').val('');
$('#speedy_state').val('');
$('#speedy_state_id').val('');
$('#speedy_city').val('');
$('#speedy_city_id').val('');
$('#speedy_city_nomenclature').val('');
$('#speedy_postcode').val('');
}
if ($('#speedy_country_container .wait').length != 0) {
$('#speedy_country_container .wait').remove();
}
});
$('#speedy_state').autocompletespeedy({
source: function(request, response) {
var $this = $(this);
var $element = $(this.element);
var jqXHR = $element.data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$element.data('jqXHR', $.ajax({
url: '{/literal}{$this_path}{literal}ajax.php?ajax_function=get_states_by_name',
dataType: 'json',
data: {
term: request.term,
country_id: $('#speedy_country_id').val()
},
success: function(data) {
$('.wait').remove();
if (data.error) {
alert(data.error);
} else {
if (data.length) {
response(data);
}
}
},
error: function(xhr, ajaxOptions, thrownError) {
//alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
}));
},
minLength: 1,
select: function(event, ui) {
if (ui.item) {
speedy_state = ui.item.value;
$('#speedy_methods').html('');
$('#speedy_methods').parent().hide();
$('#speedy_state').val(ui.item.value);
$('#speedy_state_id').val(ui.item.id);
}
},
change: function(event, ui) {
if (!ui.item) {
$('#speedy_methods').html('');
$('#speedy_methods').parent().hide();
$('#speedy_state').val('');
$('#speedy_state_id').val('');
}
}
});
$('#speedy_state').blur(function() {
var $this = $(this);
var jqXHR = $(this).data('jqXHR');
if (jqXHR) {
jqXHR.abort();
}
$this.removeData('jqXHR');
if ($this.val() != speedy_state) {
$(this).val('');
$('#speedy_state_id').val('');
}
if ($('#speedy_country_container .wait').length != 0) {
$('#speedy_country_container .wait').remove();
}
});
$('#speedy_form input').keypress(function(event){
if ((abroad == 1) && event.key.match(/[а-яА-я]/)) {
event.preventDefault();
alert('{/literal}{l s='Моля, използвайте само латински символи!' mod='speedy'}{literal}');
}
});
});
$(document).keypress(function(e) {
if(e.which == 13) {
return false;
}
});
$(document).on('change', 'input[name=shipping_method_id]', function() {
if($(this).val() == 500) { // id for speedy POST method
$('#count').parent().parent().hide();
$('#parcels_size').parent().parent().hide();
$('#parcel_size').parent().parent().show();
} else {
$('#count').parent().parent().show();
$('#parcels_size').parent().parent().show();
$('#parcel_size').parent().parent().hide();
}
});
$('#to_office input[name=to_office], #speedy_street_id, #speedy_street_no, #speedy_quarter_id, #speedy_block_no, #speedy_note').on('change', function () {
hideOffices($('#to_office input[name=to_office]:checked'));
if ($('#is_apt').val() == 1) {
$('#speedy_office_id option[value=0]').text('{/literal}{l s=' --- Моля, изберете автомат --- ' mod='speedy'}{literal}');
} else {
$('#speedy_office_id option[value=0]').text('{/literal}{l s=' --- Моля, изберете офис --- ' mod='speedy'}{literal}');
}
$('#speedy_office_id').val(0);
});
hideOffices($('#to_office input[name=to_office]:checked'));
function hideOffices(speedy_radio) {
var hasApt = false;
var hasOffices = false;
if ($(speedy_radio).val() == 1) {
$('#is_apt').val($(speedy_radio).attr('data-is-apt'));
$('#speedy_quarter_container, #speedy_street_container, #speedy_block_no_container, #speedy_note_container').hide();
$('#speedy_office_container').show();
} else {
$('#is_apt').val(0);
$('#speedy_quarter_container, #speedy_street_container, #speedy_block_no_container, #speedy_note_container').show();
$('#speedy_office_container').hide();
}
$('#speedy_office_id option').each(function() {
if ($(this).val() == 0) {
return;
}
if (($(this).attr('data-is-apt') == 1 && $(speedy_radio).attr('data-is-apt') != 1)
|| ($(this).attr('data-is-apt') != 1 && $(speedy_radio).attr('data-is-apt') == 1)
) {
$(this).hide();
} else {
$(this).show();
}
if ($(this).attr('data-is-apt') == 1) {
hasApt = true;
} else {
hasOffices = true;
}
});
$('#speedy_shipping_to_apt, [for=speedy_shipping_to_apt]').toggle(hasApt);
$('#speedy_shipping_to_office, [for=speedy_shipping_to_office]').toggle(hasOffices);
}
{/literal}
//--></script>
{if $show_invoice_courier_sevice_as_text}
<script type="text/javascript"><!--
{literal}
$(document).ready(function() {
if ($('tr#total_shipping').length != 0) {
$('tr#total_shipping td:first-child').text('{/literal}{$speedy_label}{literal}');
}
});
{/literal}
//--></script>
{/if}