Skip to content

Commit

Permalink
Merge pull request #1383 from afup/vat_tunnel
Browse files Browse the repository at this point in the history
Gestion de la TVA dans le tunnel de vente
  • Loading branch information
agallou authored Dec 16, 2023
2 parents 6ec38bf + e93cb7a commit a49de0a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 7 deletions.
7 changes: 5 additions & 2 deletions app/Resources/views/event/ticket/ticket.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
{% endfor %}
{% endfor %}

<div class="col-md-8">
<div class="col-md-8" id="ticketing" data-is-subjected-to-vat="{{ isSubjectedToVat ? '1' : '0' }}" data-vat-rate="{{ constant('Afup\\Site\\Utils\\Utils::TICKETING_VAT_RATE') }}">
<h1>{{ 'Billetterie'|trans }}: {{ event.title }}</h1>

{% if allTicketsSold and event.getWaitingListUrl %}
Expand Down Expand Up @@ -140,6 +140,9 @@
{% else %}
{{ type.vars.attr['data-price'] }}€
{% endif %}
{% if isSubjectedToVat %}
TTC
{% endif %}
</span>
<br />
<span class="tickets--type-details">
Expand Down Expand Up @@ -305,4 +308,4 @@
});
</script>
{# Debut block conversion linkedIn Insights #}
{% endblock %}
{% endblock %}
83 changes: 78 additions & 5 deletions htdocs/js/inscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,33 @@ $ = jQuery;
$(document).ready(function(){
'use strict';

var nbMaxPersonnes = $('#divPersonne').data('nb-max-personnes');
let nbMaxPersonnes = $('#divPersonne').data('nb-max-personnes');
let isSubjectedToVat = $('#ticketing').data('is-subjected-to-vat') == 1;
let vatRate = parseFloat($('#ticketing').data('vat-rate'))

let computeWithoutTaxesPriceFromPriceWithTaxes = function (price) {
return price / (1 + vatRate);
}

let computeWithoutTaxesPriceFromPriceWithTaxesConditionally = function (price) {
if (!isSubjectedToVat) {
return price;
}

return computeWithoutTaxesPriceFromPriceWithTaxes(price);
}

let formatPrice = function (price) {
let formatter = Intl.NumberFormat(
'fr-FR',
{
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}
)

return formatter.format(price);
}

// Check if there is some saved data in LocalStorage
var storageAvailable = function (type) {
Expand Down Expand Up @@ -95,6 +121,35 @@ $(document).ready(function(){

var df = document.createDocumentFragment();

if (isSubjectedToVat) {
var trClone = tr.cloneNode();
trClone.classList.add('registration')
var thClone = th.cloneNode();
thClone.appendChild(document.createTextNode("Type"));
trClone.appendChild(thClone);

var tdClone = td.cloneNode();
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode("Prix HT Unitaire"));
trClone.appendChild(tdClone);

var tdClone = td.cloneNode();
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode("Quantité"));
trClone.appendChild(tdClone);

var tdClone = td.cloneNode();
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode("Prix HT"));
trClone.appendChild(tdClone);

var tdClone = td.cloneNode();
tdClone.appendChild(document.createTextNode("Prix TTC"));
trClone.appendChild(tdClone);

df.appendChild(trClone);
}

for (var i in inscriptions) {
var trClone = tr.cloneNode();
trClone.classList.add('registration')
Expand All @@ -103,17 +158,26 @@ $(document).ready(function(){
trClone.appendChild(thClone);

var tdClone = td.cloneNode();
tdClone.appendChild(document.createTextNode(inscriptions[i].price + '€'));
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode(formatPrice(computeWithoutTaxesPriceFromPriceWithTaxesConditionally(inscriptions[i].price)) + '€'));
trClone.appendChild(tdClone);

var tdClone = td.cloneNode();
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode('x' + inscriptions[i].quantity));
trClone.appendChild(tdClone);

var tdClone = td.cloneNode();
tdClone.appendChild(document.createTextNode(inscriptions[i].subtotal + '€'));
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode(formatPrice(computeWithoutTaxesPriceFromPriceWithTaxesConditionally(inscriptions[i].subtotal)) + '€'));
trClone.appendChild(tdClone);

if (isSubjectedToVat) {
var tdClone = td.cloneNode();
tdClone.appendChild(document.createTextNode(formatPrice(inscriptions[i].subtotal) + '€'));
trClone.appendChild(tdClone);
}

df.appendChild(trClone);
numberOfTickets += inscriptions[i].quantity;
total += inscriptions[i].subtotal;
Expand All @@ -129,13 +193,22 @@ $(document).ready(function(){
trClone.appendChild(tdClone);

var tdClone = td.cloneNode();
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode('x' + numberOfTickets));
trClone.appendChild(tdClone);

var tdClone = td.cloneNode();
tdClone.appendChild(document.createTextNode(total + '€'));
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode(formatPrice(computeWithoutTaxesPriceFromPriceWithTaxesConditionally(total)) + '€'));
trClone.appendChild(tdClone);

if (isSubjectedToVat) {
var tdClone = td.cloneNode();
tdClone.setAttribute('class', 'text-align-right');
tdClone.appendChild(document.createTextNode(formatPrice(total) + '€'));
trClone.appendChild(tdClone);
}

df.appendChild(trClone);

table.appendChild(df);
Expand All @@ -162,7 +235,7 @@ $(document).ready(function(){
} else {
var price = fieldset.find('ul.tickets--type-list input[type=radio]:checked').data('price');
if (typeof price !== 'undefined') {
$(fieldset).find('legend span.fieldset--legend--price').html(price + '€');
$(fieldset).find('legend span.fieldset--legend--price').html(price + '€' + (isSubjectedToVat ? ' TTC ' : ''));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions htdocs/templates/site/scss/base/typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,7 @@ hr {
border: 1px solid #ddd;
border-bottom: none;
}

.text-align-right {
text-align: right;
}
2 changes: 2 additions & 0 deletions sources/AppBundle/Controller/TicketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AppBundle\Controller;

use Afup\Site\Forum\Facturation;
use Afup\Site\Utils\Vat;
use AppBundle\Association\Model\Repository\UserRepository;
use AppBundle\Association\Model\User;
use AppBundle\Compta\BankAccount\BankAccountFactory;
Expand Down Expand Up @@ -234,6 +235,7 @@ public function ticketAction($eventSlug, Request $request)
'ticketForm' => $purchaseForm->createView(),
'nbPersonnes' => $purchaseForm->get('nbPersonnes')->getData(), // If there is an error, this will open all fields
'maxNbPersonnes' => count($purchaseForm->getData()->getTickets()),
'isSubjectedToVat' => Vat::isSubjectedToVat(new \DateTime('now')),
'soldTicketsForMember' => $totalOfSoldTicketsByMember,
'hasMembersTickets' => $this->get('ting')->get(TicketEventTypeRepository::class)->doesEventHasRestrictedToMembersTickets($event, true, TicketEventTypeRepository::REMOVE_PAST_TICKETS),

Expand Down

0 comments on commit a49de0a

Please sign in to comment.