Skip to content

Commit

Permalink
gestion de la TVA dans le tunnel de vente
Browse files Browse the repository at this point in the history
On affiche le prix HT unitaire, le prix HT, et précise quand les tarifs
sont en TTC.
  • Loading branch information
agallou committed Dec 10, 2023
1 parent 3a0dc7d commit 8bf93c9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 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' }}">
<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 %}
81 changes: 77 additions & 4 deletions htdocs/js/inscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ $(document).ready(function(){
'use strict';

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


var computeWithoutTaxesPriceFromPriceWithTaxes = function (price) {
return price / (1 + 0.1); // on a 10% sur la billeterie
}

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

return computeWithoutTaxesPriceFromPriceWithTaxes(price);
}

var 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 8bf93c9

Please sign in to comment.