IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

Calcul total HT, TTC et TVA


Sujet :

Symfony PHP

  1. #1
    Membre du Club
    Homme Profil pro
    symfony2
    Inscrit en
    Mars 2016
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : symfony2

    Informations forums :
    Inscription : Mars 2016
    Messages : 124
    Points : 51
    Points
    51
    Par défaut Calcul total HT, TTC et TVA
    Salut, je fais partie vente en ligne du site web amis je trouve une probléme au cours de calcul tva et totalHt

    voici probléme :

    Nom : Capture5387.PNG
Affichages : 5320
Taille : 14,6 Ko

    partie du code commande (code facture):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    public function facture()
    ****{
    *********$em = $this->getDoctrine()->getManager();
    ********$generator = $this->container->get('security.secure_random');
    ********$session = $this->getRequest()->getSession();
    ********$adresse = $session->get('adresse');
    ********$panier = $session->get('panier');
    ********$commande = array();
    ********$totalHT = 0;
    ********$totalTVA = 0;
    *********
    ********$facturation = $em->getRepository('ventenligneBundle:UtilisateursAdresses')->find($adresse['facturation']);
    ********$livraison = $em->getRepository('ventenligneBundle:UtilisateursAdresses')->find($adresse['livraison']);
    ********$produits = $em->getRepository('ventenligneBundle:Produit')->findArray(array_keys($session->get('panier')));
    *********
    **********
    ********foreach($produits as $produit)
    ********{
    ************$prixHT = ($produit->getPrix() * $panier[$produit->getId()]);
    ************$prixTTC =** ($produit->getPrix() * $panier[$produit->getId()] / $produit->getTva()->getMultiplicate());
    ************$totalHT += $prixHT;
    *************
    ************if (!isset($commande['tva']['%'.$produit->getTva()->getValeur()]))
    ****************$commande['tva']['%'.$produit->getTva()->getValeur()] = round($prixTTC - $prixHT,2);
    ************else
    ****************$commande['tva']['%'.$produit->getTva()->getValeur()] += round($prixTTC - $prixHT,2);
    *************
    ************$totalTVA += round($prixTTC - $prixHT,2);
    *************
    ************$commande['produit'][$produit->getId()] = array('reference' => $produit->getNom(),
    ************************************************************'quantite' => $panier[$produit->getId()],
    ************************************************************'prixHT' => round($produit->getPrix(),2),
    *************************'prixTTC' => round($produit->getPrix() / $produit->getTva()->getMultiplicate(),2));
    ********}**
    *********
    ********$commande['livraison'] = array('prenom' => $livraison->getPrenom(),
    ************************************'nom' => $livraison->getNom(),
    ************************************'telephone' => $livraison->getTelephone(),
    ************************************'adresse' => $livraison->getAdresse(),
    ************************************'cp' => $livraison->getCp(),
    ************************************'ville' => $livraison->getVille());
    ********$commande['facturation'] = array('prenom' => $facturation->getPrenom(),
    ************************************'nom' => $facturation->getNom(),
    ************************************'telephone' => $facturation->getTelephone(),
    ************************************'adresse' => $facturation->getAdresse(),
    ************************************'cp' => $facturation->getCp(),
    ************************************'ville' => $facturation->getVille());
    ********$commande['prixHT'] = round($totalHT,2);
    ********$commande['prixTTC'] = round($totalHT + $totalTVA,2);
    ********$commande['token'] = bin2hex($generator->nextBytes(20));
    ********return $commande;
    ****}
    *****
    ****public function prepareCommandeAction()
    ****{
    *********$session = $this->getRequest()->getSession();
    ********$em = $this->getDoctrine()->getManager();
    *********
    ********if (!$session->has('commande'))
    ************$commande = new Commandes();
    ********else
    ************$commande = $em->getRepository('ventenligneBundle:Commandes')->find($session->get('commande'));
    *********
    ********$commande->setDate(new \DateTime());
    ********$commande->setUtilisateur($this->container->get('security.context')->getToken()->getUser());
    ********$commande->setValider(0);
    ********$commande->setReference(0);
    ********$commande->setCommande($this->facture());
    *********
    ********if (!$session->has('commande')) {
    ************$em->persist($commande);
    ************$session->set('commande',$commande);
    ********}
    *********
    ********$em->flush();
    *********
    ********return new Response($commande->getId());
    ****}
    code panier.html.twig :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    <link rel="stylesheet" href="{{ asset ('bundles/crud/css/bootstrap.css') }}" />
    <link rel="stylesheet" href="{{ asset ('bundles/crud/css/bootstrap-responsive.css') }}" />
    <link rel="stylesheet" href="{{ asset ('bundles/crud/css/style.css') }}" />
    <link rel="stylesheet" href=" {{ asset ('bundles/crud/css/font-awesome.css') }}" />
    *
    {% set totalHT = 0 %}
    {% set totalTTC = 0%}
    {% set refTva = {} %}
    {% set remise = 0 %}***
    *{% for produit in produits %}
    *****{% set refTva = refTva|merge({ (produit.tva.valeur ~ '%' ) : 0 }) %}
    **{% endfor %}
    *******
    <div class="container">
    ****<div class="row">
    ********<div class="span3">
    ****************{% include '::ModulesUsed/navigation.html.twig' %}
    ************</div>*
    *
    ************<div class="span8">
    ******************{% for flashMessage in app.session.flashbag.get('success') %}
    ********************<div class="alert alert-success">
    ************************{{ flashMessage }}
    ********************</div>
    ****************{% endfor %}***
    ************<h2>Votre parnier</h2>**
    *************
    ****************<table class="table table-striped table-hover">
    ********************<thead>
    ************************<tr>
    ****************************<th>Références</th>
    ****************************<th>Quantité</th>
    ****************************<th>Prix unitaire</th>
    ****************************<th>Total HT</th>
    ************************</tr>
    ********************</thead>
    ********************<tbody>
    ************************{% if produits|length == 0 %}
    ****************************<tr>
    ********************************<td class="text-center" colspan="4">Aucun article dans votre panier</td>
    ****************************</tr>**
    ************************{% endif %}***
    *************************
    ************************{% for produit in produits %}
    *****************************
    ********************{% set totalHT = totalHT + (produit.prix * panier[produit.id]) %}
    ********************{% set totalTTC = totalTTC + (produit.prix * panier[produit.id])|tva(produit.tva.multiplicate) %}
    ********************{% set refTva = refTva|merge({ ( produit.tva.valeur ~ '%' ) : refTva[produit.tva.valeur ~ '%'] + ( produit.prix * panier[produit.id])|montantTva(produit.tva.multiplicate) }) %}
    ********************{% set remise = ((totalHT * 10) /100) %}
    ***********************
    ************************<tr>
    ***************************<form action="{{ path('ajouter', { 'id' : produit.id }) }}" method="get">
    *
    ****************************<td>{{ produit.nom }}</td>
    ****************************<td>
    ********************************<select name="qte" class="span1" onChange="this.form.submit()">
    ************************************{% for i in 1..10 %}
    ****************************************<option value="{{ i }}" {% if i == panier[produit.id] %} selected="selected" {% endif %}>{{ i }}</option>
    ************************************{% endfor %}
    ********************************</select>&nbsp;
    **********************************
    ********************************<a href="{{ path('supprimer', { 'id' : produit.id }) }}"><i class="icon-trash"></i></a>
    ****************************</td>
    ****************************<td>{{ produit.prix }} €</td>
    *****************************
    **********************************{% if is_granted('ROLE_ADHERANT') %}
    ****************************<td>{{ produit.prix * panier[produit.id] - remise }}* €</td>
    ****************************{% else %}
    ********************************<td>{{ produit.prix * panier[produit.id] }}* €</td>
    ****************************{% endif %}
    ***************************</form>
    ************************</tr>
    *********************
    ************************{% endfor %}
    ********************</tbody>
    ****************</table>
    ************</form>
    *
    ************<dl class="dl-horizontal pull-right">
    ******************{% if is_granted('ROLE_ADHERANT') %}
    ********************<dt>Total HT:</dt> <dd>{{ totalHT - remise }} €</dd>
    ********************{% else %}
    ****************<dt>Total HT :</dt> <dd>{{ totalHT }} €</dd>
    ***************{% endif %}
    ****************{% for key, tva in refTva %}
    ****************<dt>TVA {{ key }} :</dt> <dd>{{ tva }} €</dd>
    ****************{% endfor %}
    ***********************************
    ****************<dt>Total TTC:</dt> <dd>{{ totalTTC }} €</dd>
    ******************
    ************</dl>
    ************<div class="clearfix"></div>
    ************<a href="{{ path('livraison') }}" class="btn btn-success pull-right">Valider mon panier</a>
    ************<a href="{{ path('produit') }}" class="btn btn-primary">Continuer mes achats</a>
    ********</div>
    *
    ****</div>
    </div>
    *
    <script src="{{ asset ('bundles/crud/js/bootstrap.js') }}"></script>
    <script src="{{ asset ('bundles/crud/js/jquery.min.js') }}"></script>***
    code du facturePDF:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    ****<head>
    ********<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    ********<title>Facture</title>
    ********<link rel="stylesheet" href="{{ asset ('bundles/crud/css/bootstrap.css') }}" />
    ********<link rel="stylesheet" href="{{ asset ('bundles/crud/css/bootstrap-responsive.css') }}" />
    ********<link rel="stylesheet" href="{{ asset ('bundles/crud/css/style.css') }}" />
    ********<link rel="stylesheet" href=" {{ asset ('bundles/crud/css/font-awesome.css') }}" />
    ********<link href=" {{ asset ('bundles/crud/css/facture.css') }}" rel="stylesheet" />
    ****</head>
    ****<body style="background-color:#444;">
    *
    ****
    ************
    ********<h1>DevAndClick</h1>
    ********<table id="enTete">
    ************<tr>
    ****************<td colspan="1"></td>
    ****************<td colspan="1"><h1>Facture</h1></td>
    ****************<td colspan="1"></td>
    ************</tr>
    **************
    ************<tr>
    ****************<td width="80">Page</td>
    ****************<td width="100">Date</td>
    ****************<td width="120">Ref</td>
    ************</tr>
    ************<tr>
    ****************<td class="color">[[page_nb]]</td>
    ****************<td class="color">{{ facture.date|date('d-m-Y') }}</td>
    ****************<td class="color">{{ facture.reference }}</td>
    ************</tr>
    ********</table>
    ********<ul id="coordonnes">
    ************<li>{{ facture.commande.facturation.nom }} {{ facture.commande.facturation.prenom }}</li>
    ************<li>{{ facture.commande.facturation.adresse}}</li>
    ************<li>{{ facture.commande.facturation.cp }} {{ facture.commande.facturation.ville }}</li>
    ********</ul>
    ********<table id="entity">
    ************<tr>
    ****************<td width="280">DESIGNATION</td>
    ****************<td width="105">QUANTITE</td>
    ****************<td width="100">P.U - HT</td>
    ****************<td width="105">MONTANT HT</td>
    ****************<td width="105">MONTANT TTC</td>
    ************</tr>
    ****************{% for produit in facture.commande.produit %}
    ****************<tr>
    ********************<td class="color">{{ produit.reference }}</td>
    ********************<td class="color">{{ produit.quantite }}</td>
    ********************<td class="color">{{ produit.prixHT }} €</td>
    ********************<td class="color">{{ produit.prixHT * produit.quantite }} €</td>
    ********************<td class="color">{{ produit.prixTTC * produit.quantite }} €</td>
    ****************</tr>
    ****************{% endfor %}
    ********</table>
    ********<table id="total">
    ************<tr>
    ****************<td width="110">TOTAL HT :</td>
    ****************<td width="100" class="color">{{ facture.commande.prixHT }} €</td>
    ************</tr>
    ************{% for key, tva in facture.commande.tva %}
    ************<tr>
    ****************<td width="110">TVA <span class="color min">{{ key }}</span> :</td>
    ****************<td width="100" class="color">{{ tva }} €</td>
    ************</tr>
    ************{% endfor %}
    ************<tr>
    ****************<td width="110">TOTAL TTC :</td>
    ****************<td width="100" class="color">{{ facture.commande.prixTTC }} €</td>
    ************</tr>
    ********</table>
    ********<div id="footer">
    *************
    ********</div>
    *********
    ****</body>
    </html>
    *
    ***
    ou ést la probléme et merci d'avance

  2. #2
    Membre expérimenté Avatar de Nico_F
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2011
    Messages : 728
    Points : 1 310
    Points
    1 310
    Par défaut
    Salut,

    Commence par expliquer quel est ton problème, on ne peut pas le deviner.

    ++

  3. #3
    Membre du Club
    Homme Profil pro
    symfony2
    Inscrit en
    Mars 2016
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : symfony2

    Informations forums :
    Inscription : Mars 2016
    Messages : 124
    Points : 51
    Points
    51
    Par défaut
    le probléme est au cours du calcul , par exemple quand il on à un produit de 20 euros et tva 20%,la calcul du valeur tva et total TTC est faux , je sais pas ou est erreur exactement , normalment au cours du calcul en controller , je fais copie coller du code

  4. #4
    Membre expérimenté Avatar de Nico_F
    Homme Profil pro
    Développeur Web
    Inscrit en
    Avril 2011
    Messages
    728
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Avril 2011
    Messages : 728
    Points : 1 310
    Points
    1 310
    Par défaut
    Si le calcul est faux c'est un problème de maths, plus d'informatique.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $prixHT = ($produit->getPrix() * $panier[$produit->getId()]);
    $prixTTC =** ($produit->getPrix() * $panier[$produit->getId()] / $produit->getTva()->getMultiplicate());
    $totalHT += $prixHT;
    Que vaut $produit->getTva()->getMultiplicate() ici ?

  5. #5
    Membre du Club
    Homme Profil pro
    symfony2
    Inscrit en
    Mars 2016
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : symfony2

    Informations forums :
    Inscription : Mars 2016
    Messages : 124
    Points : 51
    Points
    51
    Par défaut
    normalment ici faute , non c'est maths c'est faute au cours de quelque methode

  6. #6
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    1/ Inutile de citer un message complet : Utilisez le bouton "+Répondre à la discussion" (ci-dessous à gauche)
    Merci.

    2/ exemple
    • Total HT = 258 €
    • TVA (taux 20%) = 51.60 €
    • Total TTC = 309,60 €


    => Il faut revoir les formules de calcul.

    Méthode 1 :
    • prixTVA = round( prixHT * tauxTVA ) / 100 (arrondi au centime le plus proche)
    • prixTTC = prixHT + prixTVA


    Méthode 2 :
    • prixTTC = round( 100 * prixHT * (1 + tauxTVA / 100) ) / 100 (arrondi au centime le plus proche)
    • prixTVA = prixTTC - prixHT
    Dernière modification par Invité ; 17/05/2016 à 15h29.

  7. #7
    Membre du Club
    Homme Profil pro
    symfony2
    Inscrit en
    Mars 2016
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 32
    Localisation : Tunisie

    Informations professionnelles :
    Activité : symfony2

    Informations forums :
    Inscription : Mars 2016
    Messages : 124
    Points : 51
    Points
    51
    Par défaut
    @jreaux62

    merci beaucoup

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème de lenteur de calcul
    Par Fred4321 dans le forum Excel
    Réponses: 2
    Dernier message: 26/07/2007, 16h34
  2. Problème Formule dans Colones Calculées
    Par vds2302 dans le forum SharePoint
    Réponses: 2
    Dernier message: 04/06/2007, 08h14
  3. [MySQL] script calcul devis avec tva
    Par faucon54 dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 15/05/2007, 11h18
  4. [Système] Problème pour effectuer des calculs
    Par tissard dans le forum Langage
    Réponses: 10
    Dernier message: 09/12/2005, 14h07
  5. Problème de gestion de calculs
    Par Clad3 dans le forum C++
    Réponses: 6
    Dernier message: 22/10/2005, 21h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo