{% extends 'base.html.twig' %}
{% block title %}Objednávka zprávy{% endblock %}
{% block body %}
<section class="page-section" id="login">
<div class="container px-4 px-lg-5">
<div class="row gx-4 gx-lg-5 justify-content-center">
<div class="col-lg-8 col-xl-6 text-center">
<h2 class="mt-0">Objednávka Vaší zprávy</h2>
</div>
</div>
<div class="row gx-4 gx-lg-5 justify-content-center mb-5">
<div class="col-lg-6">
{{ form_start(form) }}
{{ form_errors(form) }}
<h3 class="mt-0">Fakturační adresa</h3>
{{ form_row(form.deliveryAddressCheckbox, { 'attr': { 'class': 'toggleDeliveryDetailsCheckbox', 'checked': 'checked' }}) }}
{% if loggedUser %}
{{ form_row(form.billingFirstname, { 'value': loggedUser.firstname}) }}
{{ form_row(form.billingLastname, { 'value': loggedUser.lastname}) }}
{{ form_row(form.billingCountry, { 'value': loggedUser.country}) }}
{{ form_row(form.billingCity, { 'value': loggedUser.city}) }}
{{ form_row(form.billingZipcode, { 'value': loggedUser.zipcode}) }}
{{ form_row(form.billingStreet, { 'value': loggedUser.street}) }}
{{ form_row(form.billingStreet2, { 'value': loggedUser.street2}) }}
{{ form_row(form.billingEmail, { 'value': loggedUser.email}) }}
{{ form_row(form.billingPhone, { 'value': loggedUser.phone}) }}
<div class="deliveryDetails" style="display: none">
<hr class="solid" />
<h3 class="mt-0">Doručovací adresa</h3>
{{ form_row(form.deliveryFirstname) }}
{{ form_row(form.deliveryLastname) }}
{{ form_row(form.deliveryCountry) }}
{{ form_row(form.deliveryCity) }}
{{ form_row(form.deliveryZipcode) }}
{{ form_row(form.deliveryStreet) }}
{{ form_row(form.deliveryStreet2) }}
{{ form_row(form.deliveryEmail) }}
{{ form_row(form.deliveryPhone) }}
</div>
{% else %}
{{ form_row(form.billingFirstname) }}
{{ form_row(form.billingLastname) }}
{{ form_row(form.billingCountry) }}
{{ form_row(form.billingCity) }}
{{ form_row(form.billingZipcode) }}
{{ form_row(form.billingStreet) }}
{{ form_row(form.billingStreet2) }}
{{ form_row(form.billingEmail) }}
{{ form_row(form.billingPhone) }}
<div class="deliveryDetails" style="display: none">
<hr class="solid" />
<h3 class="mt-0">Doručovací adresa</h3>
{{ form_row(form.deliveryFirstname) }}
{{ form_row(form.deliveryLastname) }}
{{ form_row(form.deliveryCountry) }}
{{ form_row(form.deliveryCity) }}
{{ form_row(form.deliveryZipcode) }}
{{ form_row(form.deliveryStreet) }}
{{ form_row(form.deliveryStreet2) }}
{{ form_row(form.deliveryEmail) }}
{{ form_row(form.deliveryPhone) }}
</div>
{% endif %}
<hr class="solid" />
<p>Text zprávy</p>
{{ form_row(form.text) }}
<hr class="solid" />
{{ form_row(form.template) }}
<div>
<img width="70%" height="500" name="plugin" id="order_form_template_img" class="border border-1 mx-auto d-block">
</div>
<hr class="solid" />
{{ form_row(form.deliveryDate) }}
{{ form_row(form.code) }}
<p id="coupon-code-text" hidden>Tady sem vložit slevu</p>
{{ form_row(form.price, { 'value': messagePrice, 'attr': { 'class': 'disable'}} ) }}
{{ form_widget(form) }}
{{ form_end(form) }}
<img id="barion_logo" class="mx-auto d-block" src="{{ asset('images/barion-smart-payment-banners-cz/barion-card-strip-cz__small.png') }}">
</div>
</div>
</div>
</section>
{% endblock %}
{% block javascripts %}
<script>
$(document).ready(function () {
const template = document.getElementById('order_form_template');
document.getElementById('order_form_template_img').src = '/upload/templates/' + template.value;
const date = new Date();
$('.js-datepicker input').datepicker({
format: "dd.mm.yyyy",
language: "cs",
daysOfWeekDisabled: "0,6",
daysOfWeekHighlighted: "1,2,3,4,5",
startDate: new Date(date.getFullYear(), date.getMonth(), date.getDay() + 14),
todayHighlight: true
});
$('.toggleDeliveryDetailsCheckbox').change(function() {
document.querySelector('.deliveryDetails').style.display = $(".toggleDeliveryDetailsCheckbox").is(':checked') ? 'none' : '';
});
$('#order_form_code').on('input', processChange);
});
function debounce(func, timeout = 500) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => { func.apply(this, args); }, timeout);
};
}
function saveInput() {
const codeInput = document.getElementById('order_form_code').value;
if(codeInput) {
$.ajax('{{ path('app_get_couponCode') }}', {
data: {
code: codeInput,
},
success: function(data) {
if (data) {
const codeData = JSON.parse(data);
document.getElementById('coupon-code-text').hidden = false;
document.getElementById('coupon-code-text').style = 'color: green;';
const currentDate = new Date().getTime() / 1000;
// if current date is between codeData.activeFrom and codeData.endsAt
if (currentDate >= codeData.activeFrom.timestamp && currentDate <= codeData.endsAt.timestamp) {
document.getElementById('coupon-code-text').textContent = `Kupón ${codeData.code} se slevou ${codeData.value}${codeData.percentage ? '%' : ' Kč'}.`;
const currentPrice = document.getElementById('order_form_price').value;
if (codeData.percentage) {
document.getElementById('order_form_price').value = currentPrice - ((currentPrice / 100) * codeData.value);
} else {
document.getElementById('order_form_price').value = currentPrice - codeData.value;
}
} else {
document.getElementById('coupon-code-text').textContent = `Kupón ${codeData.code} již není platný.`;
document.getElementById('coupon-code-text').style = 'color: red;';
}
} else {
document.getElementById('coupon-code-text').textContent = `Kupón ${codeData.code} nebyl nalezen.`;
document.getElementById('coupon-code-text').style = 'color: red;';
}
},
error: function() {
document.getElementById('coupon-code-text').hidden = false;
document.getElementById('coupon-code-text').textContent = 'Kupón nebyl nalezen.';
document.getElementById('coupon-code-text').style = 'color: red;';
}
});
} else {
document.getElementById('coupon-code-text').hidden = true;
}
}
const processChange = debounce(() => saveInput());
window.addEventListener("DOMContentLoaded", (event) => {
document.getElementById('order_form_template').addEventListener('change', function() {
document.getElementById('order_form_template_img').src = '/upload/templates/' + this.value;
});
});
</script>
{% endblock %}