From 3c65901d56ca2df3fefe5aaca23865057bfc85f2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 11 May 2005 01:23:52 +0000 Subject: [PATCH] =?UTF-8?q?New:=20La=20gestion=20de=20TVA=20apparait=20dan?= =?UTF-8?q?s=20les=20rapports=20r=E9sultats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/resultat/clientfourn.php | 174 +++++++++++++++++++++++-- htdocs/compta/resultat/index.php | 102 +++++++++++++++ 2 files changed, 266 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index a80310e741a..4ac782debb9 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -177,6 +177,7 @@ if ($modecompta == 'CREANCES-DETTES') print ''.pri print ''.price($total_ttc).''; print ''; + /* * Frais, factures fournisseurs. */ @@ -218,8 +219,8 @@ if ($result) { print " "; print "".$langs->trans("Bills")." idp."\">$objp->nom\n"; - if ($modecompta == 'CREANCES-DETTES') print "".price($objp->amount_ht)."\n"; - print "".price($objp->amount_ttc)."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price(-$objp->amount_ht)."\n"; + print "".price(-$objp->amount_ttc)."\n"; $total_ht = $total_ht - $objp->amount_ht; $total_ttc = $total_ttc - $objp->amount_ttc; @@ -241,6 +242,159 @@ if ($result) { dolibarr_print_error($db); } print ''; +if ($modecompta == 'CREANCES-DETTES') print ''.price(-$subtotal_ht).''; +print ''.price(-$subtotal_ttc).''; +print ''; + + +/* + * TVA + */ +print ''.$langs->trans("VAT").''; +$subtotal_ht = 0; +$subtotal_ttc = 0; + +if ($modecompta == 'CREANCES-DETTES') { + // TVA à payer + $obj->amount=0; + $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.fk_statut = 1"; + if ($year) { + $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + } + $sql .= " GROUP BY dm DESC"; + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=false; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); + + $total_ht = $total_ht - $obj->amount; + $total_ttc = $total_ttc - $obj->amount; + $subtotal_ht = $subtotal_ht - $obj->amount; + $subtotal_ttc = $subtotal_ttc - $obj->amount; + + $i++; + } + } + } else { + dolibarr_print_error($db); + } + print " "; + print "".$langs->trans("VATToPay")."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price(-$obj->amount)."\n"; + print "".price(-$obj->amount)."\n"; + print "\n"; + // TVA à récupérer + $obj->amount=0; + $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql .= " WHERE f.fk_statut = 1"; + if ($year) { + $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + } + $sql .= " GROUP BY dm DESC"; + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=true; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); + + $total_ht = $total_ht + $obj->amount; + $total_ttc = $total_ttc + $obj->amount; + $subtotal_ht = $subtotal_ht + $obj->amount; + $subtotal_ttc = $subtotal_ttc + $obj->amount; + + $i++; + } + } + } else { + dolibarr_print_error($db); + } + print " "; + print "".$langs->trans("VATToCollect")."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price($obj->amount)."\n"; + print "".price($obj->amount)."\n"; + print "\n"; +} +else { + // TVA payée + $obj->amount=0; + $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql .= " WHERE amount > 0"; + if ($year) { + $sql .= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + } + $sql .= " GROUP BY dm DESC"; + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=false; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); + + $total_ht = $total_ht - $obj->amount; + $total_ttc = $total_ttc - $obj->amount; + $subtotal_ht = $subtotal_ht - $obj->amount; + $subtotal_ttc = $subtotal_ttc - $obj->amount; + + $i++; + } + } + } else { + dolibarr_print_error($db); + } + print " "; + print "".$langs->trans("VATToPay")."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price(-$obj->amount)."\n"; + print "".price(-$obj->amount)."\n"; + print "\n"; + // TVA récupérée + $obj->amount=0; + $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql .= " WHERE amount < 0"; + if ($year) { + $sql .= " AND t.datev between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; + } + $sql .= " GROUP BY dm DESC"; + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=true; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); + + $total_ht = $total_ht + $obj->amount; + $total_ttc = $total_ttc + $obj->amount; + $subtotal_ht = $subtotal_ht + $obj->amount; + $subtotal_ttc = $subtotal_ttc + $obj->amount; + + $i++; + } + } + } else { + dolibarr_print_error($db); + } + print " "; + print "".$langs->trans("VATToCollect")."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price($obj->amount)."\n"; + print "".price($obj->amount)."\n"; + print "\n"; +} +print ''; if ($modecompta == 'CREANCES-DETTES') print ''.price($subtotal_ht).''; print ''.price($subtotal_ttc).''; print ''; @@ -289,8 +443,8 @@ if ($result) { $var = !$var; print " "; print ''.$obj->nom.''; - if ($modecompta == 'CREANCES-DETTES') print ''.price($obj->amount).''; - print ''.price($obj->amount).''; + if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; + print ''.price(-$obj->amount).''; print ''; $i++; } @@ -304,8 +458,8 @@ if ($result) { dolibarr_print_error($db); } print ''; -if ($modecompta == 'CREANCES-DETTES') print ''.price($subtotal_ht).''; -print ''.price($subtotal_ttc).''; +if ($modecompta == 'CREANCES-DETTES') print ''.price(-$subtotal_ht).''; +print ''.price(-$subtotal_ttc).''; print ''; @@ -352,8 +506,8 @@ if ($result) { $var = !$var; print " "; print ''.$obj->nom.''; - if ($modecompta == 'CREANCES-DETTES') print ''.price($obj->amount).''; - print ''.price($obj->amount).''; + if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; + print ''.price(-$obj->amount).''; print ''; $i++; } @@ -367,8 +521,8 @@ if ($result) { dolibarr_print_error($db); } print ''; -if ($modecompta == 'CREANCES-DETTES') print ''.price($subtotal_ht).''; -print ''.price($subtotal_ttc).''; +if ($modecompta == 'CREANCES-DETTES') print ''.price(-$subtotal_ht).''; +print ''.price(-$subtotal_ttc).''; print ''; diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 23f99c0c3b5..ba8f39c7f1b 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -181,6 +181,108 @@ else { } +/* + * TVA + */ + +if ($modecompta == 'CREANCES-DETTES') { + // TVA à payer + $sql = "SELECT sum(f.tva) as amount, date_format(f.datef,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.fk_statut = 1"; + $sql .= " GROUP BY dm DESC"; + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=false; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); + + $decaiss[$obj->dm] += $obj->amount; + $decaiss_ttc[$obj->dm] += $obj->amount; + + $i++; + } + } + } else { + dolibarr_print_error($db); + } + // TVA à récupérer + $sql = "SELECT sum(f.total_tva) as amount, date_format(f.datef,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql .= " WHERE f.fk_statut = 1"; + $sql .= " GROUP BY dm DESC"; + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=false; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); + + $encaiss[$obj->dm] += $obj->amount; + $encaiss_ttc[$obj->dm] += $obj->amount; + + $i++; + } + } + } else { + dolibarr_print_error($db); + } +} +else { + // TVA payée + $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql .= " WHERE amount > 0"; + $sql .= " GROUP BY dm DESC"; + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=false; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); + + $decaiss[$obj->dm] += $obj->amount; + $decaiss_ttc[$obj->dm] += $obj->amount; + + $i++; + } + } + } else { + dolibarr_print_error($db); + } + // TVA récupérée + $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; + $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql .= " WHERE amount < 0"; + $sql .= " GROUP BY dm DESC"; + $result=$db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $var=false; + $i = 0; + if ($num) { + while ($i < $num) { + $obj = $db->fetch_object($result); + + $encaiss[$obj->dm] += $obj->amount; + $encaiss_ttc[$obj->dm] += $obj->amount; + + $i++; + } + } + } else { + dolibarr_print_error($db); + } +} + + /* * Charges sociales non déductibles */