Jump to content

Requete des factures


Anthony

Recommended Posts

3 hours ago, Eolia said:

requete multi-table sur:

ps_orders o

ps_order_invoice oi 

ps_order_slip os

ps_order_detail od

ORDER BY oi.date_add,  os.date_add, oi.id_order_invoice, os.id_order_slip

 

Merci de votre réponse mais je n'obtiens pas le bon résultat :
Ma requête est la suivante : 
 

SELECT oi.`date_add` as Date_facture, oi.`id_order` as N_commande, oi.`total_products` as Total_produits_HT, (oi.`total_paid_tax_incl` - oi.`total_paid_tax_excl`) as TVA, t.rate AS TVA_rate, (oi.`total_paid_tax_incl` - oi.`total_shipping_tax_incl`) as Total_produits_TTC, oi.`total_shipping_tax_excl` 
FROM ps_order_invoice oi 
left outer join ps_orders o on oi.`id_order` = o.`id_order` 
left outer join ps_order_slip os on oi.`id_order` = os.`id_order` 
left outer join ps_order_detail od on oi.`id_order` = od.`id_order` 
left outer join ps_order_detail_tax odt on od.id_order_detail = odt.id_order_detail
left outer join ps_tax t on odt.id_tax = t.id_tax 
ORDER BY oi.date_add, os.date_add, oi.id_order_invoice, os.id_order_slip
 

Capture d’écran 2018-09-28 à 13.58.46.png

Link to comment
Share on other sites

1 hour ago, Eolia said:

Vous avez peut-être oublié les id_products d'order_detail  dans votre select, non ?

Même en le rajoutant je n'ai pas le détail de chaque taxe par ligne.
Sur mon premier post il y a une seule commande et non plusieurs 

Link to comment
Share on other sites

37 minutes ago, Eolia said:

Vous ne voulez la requete que pour une commande ? Ajoutez where id_order =

Si vous voulez les taxes il faut faire les calculs dans la requete (TTC - HT)

 

J'ai cette erreur : #1064 - Erreur de syntaxe près de 'GROUP BY t.rate 

Pourquoi ? vous avez une idée ?

SELECT
  oi.`date_add` as Date_facture,
  od.product_id,
  oi.`id_order` as N_commande,
  oi.`total_products` as Total_produits_HT,
  (
    oi.`total_paid_tax_incl` - oi.`total_paid_tax_excl`
  ) as TVA,
  t.rate AS TVA_rate,
  (
    oi.`total_paid_tax_incl` - oi.`total_shipping_tax_incl`
  ) as Total_produits_TTC,
  oi.`total_shipping_tax_excl`
FROM
  ps_order_invoice oi
  left outer join ps_orders o on oi.`id_order` = o.`id_order`
  left outer join ps_order_slip os on oi.`id_order` = os.`id_order`
  left outer join ps_order_detail od on oi.`id_order` = od.`id_order`
  left outer join ps_order_detail_tax odt on od.id_order_detail = odt.id_order_detail
  left outer join ps_tax t on odt.id_tax = t.id_tax
ORDER BY
  oi.date_add,
  os.date_add,
  oi.id_order_invoice,
  os.id_order_slip
Group By
  t.rate
 

Link to comment
Share on other sites

ce group by est inutile et incompatible avec votre select, par contre classez-les par commande^^

 

SELECT
  oi.`date_add` as Date_facture,
  od.product_id,
  oi.`id_order` as N_commande,
  oi.`total_products` as Total_produits_HT,
  (
    oi.`total_paid_tax_incl` - oi.`total_paid_tax_excl`
  ) as TVA,
  t.rate AS TVA_rate,
  (
    oi.`total_paid_tax_incl` - oi.`total_shipping_tax_incl`
  ) as Total_produits_TTC,
  oi.`total_shipping_tax_excl`
FROM
  ps_order_invoice oi
  left outer join ps_orders o on oi.`id_order` = o.`id_order`
  left outer join ps_order_slip os on oi.`id_order` = os.`id_order`
  left outer join ps_order_detail od on oi.`id_order` = od.`id_order`
  left outer join ps_order_detail_tax odt on od.id_order_detail = odt.id_order_detail
  left outer join ps_tax t on odt.id_tax = t.id_tax
ORDER BY
  N_commande,
  oi.date_add,
  os.date_add,
  oi.id_order_invoice,
  os.id_order_slip
Link to comment
Share on other sites

3 minutes ago, Eolia said:

ce group by est inutile et incompatible avec votre select, par contre classez-les par commande^^

 


SELECT
  oi.`date_add` as Date_facture,
  od.product_id,
  oi.`id_order` as N_commande,
  oi.`total_products` as Total_produits_HT,
  (
    oi.`total_paid_tax_incl` - oi.`total_paid_tax_excl`
  ) as TVA,
  t.rate AS TVA_rate,
  (
    oi.`total_paid_tax_incl` - oi.`total_shipping_tax_incl`
  ) as Total_produits_TTC,
  oi.`total_shipping_tax_excl`
FROM
  ps_order_invoice oi
  left outer join ps_orders o on oi.`id_order` = o.`id_order`
  left outer join ps_order_slip os on oi.`id_order` = os.`id_order`
  left outer join ps_order_detail od on oi.`id_order` = od.`id_order`
  left outer join ps_order_detail_tax odt on od.id_order_detail = odt.id_order_detail
  left outer join ps_tax t on odt.id_tax = t.id_tax
ORDER BY
  N_commande,
  oi.date_add,
  os.date_add,
  oi.id_order_invoice,
  os.id_order_slip

 

D'accord mais le but c'est que par commande il y est le total des TVA à 5,5% et le total des TVA à 20% alors que la il y a tous les produit par commande

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...