diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 77d0d5d93a5..6cd10819396 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -35,7 +35,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); $langs->load("bills"); // Security check -$socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; +$socid = GETPOST("socid"); if ($user->societe_id > 0) $socid = $user->societe_id; if (!$user->rights->compta->resultat->lire && !$user->rights->accounting->comptarapport->lire) accessforbidden(); @@ -44,43 +44,47 @@ accessforbidden(); $year=GETPOST("year"); if (empty($year)) { - $year_current = strftime("%Y",dol_now()); - $month_current = strftime("%m",dol_now()); - $year_start = $year_current; + $year_current = strftime("%Y",dol_now()); + $month_current = strftime("%m",dol_now()); + $year_start = $year_current; } else { - $year_current = $year; - $month_current = strftime("%m",dol_now()); - $year_start = $year; + $year_current = $year; + $month_current = strftime("%m",dol_now()); + $year_start = $year; } $date_start=dol_mktime(0,0,0,$_REQUEST["date_startmonth"],$_REQUEST["date_startday"],$_REQUEST["date_startyear"]); // Date for local PHP server $date_end=dol_mktime(23,59,59,$_REQUEST["date_endmonth"],$_REQUEST["date_endday"],$_REQUEST["date_endyear"]); // Date for local PHP server // Quarter if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $q=GETPOST("q")?GETPOST("q"):0; - if ($q==0) - { - // We define date_start and date_end - $year_end=$year_start; - $month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); - if ($month_start > $month_current) - { - $year_start--; - $year_end--; - } - $month_end=$month_start-1; - if ($month_end < 1) $month_end=12; - else $year_end++; - $date_start=dol_get_first_day($year_start,$month_start,false); $date_end=dol_get_last_day($year_end,$month_end,false); - } - if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); } - if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); } - if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); } - if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); } + $q=GETPOST("q")?GETPOST("q"):0; + if ($q==0) + { + // We define date_start and date_end + $year_end=$year_start; + $month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1); + if (! GETPOST('month')) + { + if ($month_start > $month_current) + { + $year_start--; + $year_end--; + } + $month_end=$month_start-1; + if ($month_end < 1) $month_end=12; + else $year_end++; + } + else $month_end=$month_start; + $date_start=dol_get_first_day($year_start,$month_start,false); $date_end=dol_get_last_day($year_end,$month_end,false); + } + if ($q==1) { $date_start=dol_get_first_day($year_start,1,false); $date_end=dol_get_last_day($year_start,3,false); } + if ($q==2) { $date_start=dol_get_first_day($year_start,4,false); $date_end=dol_get_last_day($year_start,6,false); } + if ($q==3) { $date_start=dol_get_first_day($year_start,7,false); $date_end=dol_get_last_day($year_start,9,false); } + if ($q==4) { $date_start=dol_get_first_day($year_start,10,false); $date_end=dol_get_last_day($year_start,12,false); } } else { - // TODO We define q + // TODO We define q } @@ -101,23 +105,23 @@ $html=new Form($db); // Affiche en-tete de rapport if ($modecompta=="CREANCES-DETTES") { - $nom=$langs->trans("AnnualByCompaniesDueDebtMode"); - $nom.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); - //$periodlink=''.img_previous().' '.img_next().''; - $description=$langs->trans("RulesResultDue"); - $builddate=time(); - //$exportlink=$langs->trans("NotYetAvailable"); + $nom=$langs->trans("AnnualByCompaniesDueDebtMode"); + $nom.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + //$periodlink=''.img_previous().' '.img_next().''; + $description=$langs->trans("RulesResultDue"); + $builddate=time(); + //$exportlink=$langs->trans("NotYetAvailable"); } else { - $nom=$langs->trans("AnnualByCompaniesInputOutputMode"); - $nom.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; - //$period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',1,1,0,'',1,0,1); - $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); - //$periodlink=''.img_previous().' '.img_next().''; - $description=$langs->trans("RulesResultInOut"); - $builddate=time(); - //$exportlink=$langs->trans("NotYetAvailable"); + $nom=$langs->trans("AnnualByCompaniesInputOutputMode"); + $nom.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; + //$period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',1,1,0,'',1,0,1); + $period=$html->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$html->select_date($date_end,'date_end',0,0,0,'',1,0,1); + //$periodlink=''.img_previous().' '.img_next().''; + $description=$langs->trans("RulesResultInOut"); + $builddate=time(); + //$exportlink=$langs->trans("NotYetAvailable"); } report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); @@ -135,26 +139,26 @@ print "\n"; print ''.$langs->trans("CustomersInvoices").''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT s.nom, s.rowid as socid, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ", ".MAIN_DB_PREFIX."facture as f"; - $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND f.fk_statut in (1,2)"; - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql = "SELECT s.nom, s.rowid as socid, sum(f.total) as amount_ht, sum(f.total_ttc) as amount_ttc"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut in (1,2)"; + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } else { - /* - * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les - * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) - */ - $sql = "SELECT s.nom as nom, s.rowid as socid, sum(pf.amount) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ", ".MAIN_DB_PREFIX."facture as f"; - $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; - $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " WHERE p.rowid = pf.fk_paiement"; - $sql.= " AND pf.fk_facture = f.rowid"; - $sql.= " AND f.fk_soc = s.rowid"; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + /* + * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les + * vieilles versions, ils n'etaient pas lies via paiement_facture. On les ajoute plus loin) + */ + $sql = "SELECT s.nom as nom, s.rowid as socid, sum(pf.amount) as amount_ttc"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture as f"; + $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " WHERE p.rowid = pf.fk_paiement"; + $sql.= " AND pf.fk_facture = f.rowid"; + $sql.= " AND f.fk_soc = s.rowid"; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; @@ -162,98 +166,98 @@ $sql.= " GROUP BY s.nom, s.rowid"; $sql.= " ORDER BY s.nom"; /* -print dol_print_date($date_end,'dayhour',true).'
'; -print $db->idate($date_end).'
'; + print dol_print_date($date_end,'dayhour',true).'
'; + print $db->idate($date_end).'
'; -print adodb_get_gmt_diff(); -print adodb_date('Y-d-m H:i',$date_end,true).'
'; -print adodb_date('Y-d-m H:i',$date_end,false).'
'; + print adodb_get_gmt_diff(); + print adodb_date('Y-d-m H:i',$date_end,true).'
'; + print adodb_date('Y-d-m H:i',$date_end,false).'
'; -$date_end=0; -print dol_print_date($date_end,'dayhour',true).'
'; -print $db->idate($date_end).'
'; -print adodb_gmstrftime('%Y-%d-%m %H:%M',$date_end).'
'; -print $sql; -*/ + $date_end=0; + print dol_print_date($date_end,'dayhour',true).'
'; + print $db->idate($date_end).'
'; + print adodb_gmstrftime('%Y-%d-%m %H:%M',$date_end).'
'; + print $sql; + */ dol_syslog("get customer invoices sql=".$sql); $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - $var=true; - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; + $num = $db->num_rows($result); + $i = 0; + $var=true; + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; - print " "; - print "".$langs->trans("Bills")." socid."\">$objp->nom\n"; + print " "; + print "".$langs->trans("Bills")." socid."\">$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; - print "\n"; - $i++; - } - $db->free($result); + $total_ht = $total_ht + $objp->amount_ht; + $total_ttc = $total_ttc + $objp->amount_ttc; + print "\n"; + $i++; + } + $db->free($result); } else { - dol_print_error($db); + dol_print_error($db); } // On ajoute les paiements clients anciennes version, non lie par paiement_facture if ($modecompta != 'CREANCES-DETTES') { - $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; - $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; - $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; - $sql.= " WHERE pf.rowid IS NULL"; - $sql.= " AND p.fk_bank = b.rowid"; - $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity = ".$conf->entity; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; - $sql.= " GROUP BY nom, idp"; - $sql.= " ORDER BY nom"; + $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; + $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; + $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; + $sql.= " WHERE pf.rowid IS NULL"; + $sql.= " AND p.fk_bank = b.rowid"; + $sql.= " AND b.fk_account = ba.rowid"; + $sql.= " AND ba.entity = ".$conf->entity; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql.= " GROUP BY nom, idp"; + $sql.= " ORDER BY nom"; - dol_syslog("get old customer payments not linked to invoices sql=".$sql); - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - $i = 0; - if ($num) { - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; + dol_syslog("get old customer payments not linked to invoices sql=".$sql); + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i = 0; + if ($num) { + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; - print " "; - print "".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n"; + print " "; + print "".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\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; - print "\n"; - $i++; - } - } - $db->free($result); - } else { - dol_print_error($db); - } + $total_ht = $total_ht + $objp->amount_ht; + $total_ttc = $total_ttc + $objp->amount_ttc; + print "\n"; + $i++; + } + } + $db->free($result); + } else { + dol_print_error($db); + } } if ($total_ttc == 0) { - $var=!$var; - print " "; - print ''.$langs->trans("None").''; - print ''; + $var=!$var; + print " "; + print ''.$langs->trans("None").''; + print ''; } print ''; @@ -267,22 +271,22 @@ print ''; */ if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT s.nom, s.rowid as socid, date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND f.fk_statut in (1,2)"; - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql = "SELECT s.nom, s.rowid as socid, date_format(f.datef,'%Y-%m') as dm, sum(f.total_ht) as amount_ht, sum(f.total_ttc) as amount_ttc"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql.= " WHERE f.fk_soc = s.rowid"; + $sql.= " AND f.fk_statut in (1,2)"; + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } else { - $sql = "SELECT s.nom, s.rowid as socid, date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p"; - $sql.= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= " ON pf.fk_facturefourn = f.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s"; - $sql .= " ON f.fk_soc = s.rowid"; - $sql .= " WHERE p.rowid = pf.fk_paiementfourn "; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql = "SELECT s.nom, s.rowid as socid, date_format(p.datep,'%Y-%m') as dm, sum(pf.amount) as amount_ttc"; + $sql .= " FROM ".MAIN_DB_PREFIX."paiementfourn as p"; + $sql.= ", ".MAIN_DB_PREFIX."paiementfourn_facturefourn as pf"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql .= " ON pf.fk_facturefourn = f.rowid"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s"; + $sql .= " ON f.fk_soc = s.rowid"; + $sql .= " WHERE p.rowid = pf.fk_paiementfourn "; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND f.entity = ".$conf->entity; if ($socid) $sql.= " AND f.fk_soc = ".$socid; @@ -296,38 +300,38 @@ $subtotal_ttc = 0; dol_syslog("get suppliers invoices sql=".$sql); $result = $db->query($sql); if ($result) { - $num = $db->num_rows($result); - $i = 0; - $var=true; - if ($num > 0) { - while ($i < $num) { - $objp = $db->fetch_object($result); - $var=!$var; + $num = $db->num_rows($result); + $i = 0; + $var=true; + if ($num > 0) { + while ($i < $num) { + $objp = $db->fetch_object($result); + $var=!$var; - print " "; - print "".$langs->trans("Bills")." socid."\">".$objp->nom."\n"; + print " "; + print "".$langs->trans("Bills")." socid."\">".$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; - $subtotal_ht = $subtotal_ht + $objp->amount_ht; - $subtotal_ttc = $subtotal_ttc + $objp->amount_ttc; - print "\n"; - $i++; - } - } - else { - $var=!$var; - print " "; - print ''.$langs->trans("None").''; - print ''; - } + $total_ht = $total_ht - $objp->amount_ht; + $total_ttc = $total_ttc - $objp->amount_ttc; + $subtotal_ht = $subtotal_ht + $objp->amount_ht; + $subtotal_ttc = $subtotal_ttc + $objp->amount_ttc; + print "\n"; + $i++; + } + } + else { + $var=!$var; + print " "; + print ''.$langs->trans("None").''; + print ''; + } - $db->free($result); + $db->free($result); } else { - dol_print_error($db); + dol_print_error($db); } print ''; if ($modecompta == 'CREANCES-DETTES') print ''.price(-$subtotal_ht).''; @@ -343,22 +347,22 @@ print ''; print ''.$langs->trans("SocialContributions").''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; - $sql.= " WHERE s.fk_type = c.id"; - $sql.= " AND c.deductible = 0"; - if ($date_start && $date_end) $sql.= " AND s.date_ech >= '".$db->idate($date_start)."' AND s.date_ech <= '".$db->idate($date_end)."'"; + $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= " WHERE s.fk_type = c.id"; + $sql.= " AND c.deductible = 0"; + if ($date_start && $date_end) $sql.= " AND s.date_ech >= '".$db->idate($date_start)."' AND s.date_ech <= '".$db->idate($date_end)."'"; } else { - $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; - $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql.= " WHERE p.fk_charge = s.rowid"; - $sql.= " AND s.fk_type = c.id"; - $sql.= " AND c.deductible = 0"; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql.= " WHERE p.fk_charge = s.rowid"; + $sql.= " AND s.fk_type = c.id"; + $sql.= " AND c.deductible = 0"; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } $sql.= " AND s.entity = ".$conf->entity; $sql.= " GROUP BY c.libelle"; @@ -368,35 +372,35 @@ $result=$db->query($sql); $subtotal_ht = 0; $subtotal_ttc = 0; if ($result) { - $num = $db->num_rows($result); - $var=true; - $i = 0; - if ($num) { - while ($i < $num) { - $obj = $db->fetch_object($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; + $total_ht = $total_ht - $obj->amount; + $total_ttc = $total_ttc - $obj->amount; + $subtotal_ht = $subtotal_ht + $obj->amount; + $subtotal_ttc = $subtotal_ttc + $obj->amount; - $var = !$var; - print " "; - print ''.$obj->nom.''; - if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; - print ''.price(-$obj->amount).''; - print ''; - $i++; - } - } - else { - $var = !$var; - print " "; - print ''.$langs->trans("None").''; - print ''; - } + $var = !$var; + print " "; + print ''.$obj->nom.''; + if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; + print ''.price(-$obj->amount).''; + print ''; + $i++; + } + } + else { + $var = !$var; + print " "; + print ''.$langs->trans("None").''; + print ''; + } } else { - dol_print_error($db); + dol_print_error($db); } print ''; if ($modecompta == 'CREANCES-DETTES') print ''.price(-$subtotal_ht).''; @@ -411,26 +415,26 @@ print ''; print ''.$langs->trans("SocialContributions").''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; - $sql.= " WHERE s.fk_type = c.id"; - $sql.= " AND c.deductible = 1"; - if ($date_start && $date_end) $sql.= " AND s.date_ech >= '".$db->idate($date_start)."' AND s.date_ech <= '".$db->idate($date_end)."'"; - $sql.= " AND s.entity = ".$conf->entity; - $sql.= " GROUP BY c.libelle DESC"; + $sql = "SELECT c.libelle as nom, sum(s.amount) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= " WHERE s.fk_type = c.id"; + $sql.= " AND c.deductible = 1"; + if ($date_start && $date_end) $sql.= " AND s.date_ech >= '".$db->idate($date_start)."' AND s.date_ech <= '".$db->idate($date_end)."'"; + $sql.= " AND s.entity = ".$conf->entity; + $sql.= " GROUP BY c.libelle DESC"; } else { - $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; - $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; - $sql .= " WHERE p.fk_charge = s.rowid"; - $sql.= " AND s.fk_type = c.id"; - $sql.= " AND c.deductible = 1"; - if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; - $sql.= " AND s.entity = ".$conf->entity; - $sql.= " GROUP BY c.libelle"; + $sql = "SELECT c.libelle as nom, sum(p.amount) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql.= ", ".MAIN_DB_PREFIX."chargesociales as s"; + $sql.= ", ".MAIN_DB_PREFIX."paiementcharge as p"; + $sql .= " WHERE p.fk_charge = s.rowid"; + $sql.= " AND s.fk_type = c.id"; + $sql.= " AND c.deductible = 1"; + if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; + $sql.= " AND s.entity = ".$conf->entity; + $sql.= " GROUP BY c.libelle"; } dol_syslog("get social contributions deductible=1 sql=".$sql); @@ -438,35 +442,35 @@ $result=$db->query($sql); $subtotal_ht = 0; $subtotal_ttc = 0; if ($result) { - $num = $db->num_rows($result); - $var=true; - $i = 0; - if ($num) { - while ($i < $num) { - $obj = $db->fetch_object($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; + $total_ht = $total_ht - $obj->amount; + $total_ttc = $total_ttc - $obj->amount; + $subtotal_ht = $subtotal_ht + $obj->amount; + $subtotal_ttc = $subtotal_ttc + $obj->amount; - $var = !$var; - print " "; - print ''.$obj->nom.''; - if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; - print ''.price(-$obj->amount).''; - print ''; - $i++; - } - } - else { - $var = !$var; - print " "; - print ''.$langs->trans("None").''; - print ''; - } + $var = !$var; + print " "; + print ''.$obj->nom.''; + if ($modecompta == 'CREANCES-DETTES') print ''.price(-$obj->amount).''; + print ''.price(-$obj->amount).''; + print ''; + $i++; + } + } + else { + $var = !$var; + print " "; + print ''.$langs->trans("None").''; + print ''; + } } else { - dol_print_error($db); + dol_print_error($db); } print ''; if ($modecompta == 'CREANCES-DETTES') print ''.price(-$subtotal_ht).''; @@ -475,19 +479,19 @@ print ''; if ($mysoc->tva_assuj == 'franchise') // Non assujeti { - // Total - print ''; - print ' '; - print ''; + // Total + print ''; + print ' '; + print ''; - print ''.$langs->trans("Profit").''; - if ($modecompta == 'CREANCES-DETTES') print ''.price($total_ht).''; - print ''.price($total_ttc).''; - print ''; + print ''.$langs->trans("Profit").''; + if ($modecompta == 'CREANCES-DETTES') print ''.price($total_ht).''; + print ''.price($total_ttc).''; + print ''; - print ''; - print ' '; - print ''; + print ''; + print ' '; + print ''; } @@ -500,183 +504,183 @@ $subtotal_ttc = 0; if ($modecompta == 'CREANCES-DETTES') { - // TVA a payer - $amount=0; - $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.tva) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql.= " WHERE f.fk_statut in (1,2)"; - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; - $sql.= " AND f.entity = ".$conf->entity; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm DESC"; + // TVA a payer + $amount=0; + $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.tva) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm DESC"; - dol_syslog("get vat to pay sql=".$sql); - $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); + dol_syslog("get vat to pay sql=".$sql); + $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); - $amount = $amount - $obj->amount; - $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 { - dol_print_error($db); - } - print " "; - print "".$langs->trans("VATToPay")."\n"; - if ($modecompta == 'CREANCES-DETTES') print "".price($amount)."\n"; - print "".price($amount)."\n"; - print "\n"; + $amount = $amount - $obj->amount; + $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 { + dol_print_error($db); + } + print " "; + print "".$langs->trans("VATToPay")."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price($amount)."\n"; + print "".price($amount)."\n"; + print "\n"; - // TVA a recuperer - $amount=0; - $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql.= " WHERE f.fk_statut in (1,2)"; - if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; - $sql.= " AND f.entity = ".$conf->entity; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm DESC"; + // TVA a recuperer + $amount=0; + $sql = "SELECT date_format(f.datef,'%Y-%m') as dm, sum(f.total_tva) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql.= " WHERE f.fk_statut in (1,2)"; + if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm DESC"; - dol_syslog("get vat received back sql=".$sql); - $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); + dol_syslog("get vat received back sql=".$sql); + $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); - $amount = $amount + $obj->amount; - $total_ht = $total_ht + $obj->amount; - $total_ttc = $total_ttc + $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $amount = $amount + $obj->amount; + $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 { - dol_print_error($db); - } - print " "; - print "".$langs->trans("VATToCollect")."\n"; - if ($modecompta == 'CREANCES-DETTES') print "".price($amount)."\n"; - print "".price($amount)."\n"; - print "\n"; + $i++; + } + } + } else { + dol_print_error($db); + } + print " "; + print "".$langs->trans("VATToCollect")."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price($amount)."\n"; + print "".price($amount)."\n"; + print "\n"; } else { - // TVA reellement deja payee - $amount=0; - $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql.= " WHERE amount > 0"; - if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; - $sql.= " AND t.entity = ".$conf->entity; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm DESC"; + // TVA reellement deja payee + $amount=0; + $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql.= " WHERE amount > 0"; + if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; + $sql.= " AND t.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm DESC"; - dol_syslog("get vat really paid sql=".$sql); - $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); + dol_syslog("get vat really paid sql=".$sql); + $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); - $amount = $amount - $obj->amount; - $total_ht = $total_ht - $obj->amount; - $total_ttc = $total_ttc - $obj->amount; - $subtotal_ht = $subtotal_ht - $obj->amount; - $subtotal_ttc = $subtotal_ttc - $obj->amount; + $amount = $amount - $obj->amount; + $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++; - } - } - $db->free($result); - } else { - dol_print_error($db); - } - print " "; - print "".$langs->trans("VATPaid")."\n"; - if ($modecompta == 'CREANCES-DETTES') print "".price($amount)."\n"; - print "".price($amount)."\n"; - print "\n"; + $i++; + } + } + $db->free($result); + } else { + dol_print_error($db); + } + print " "; + print "".$langs->trans("VATPaid")."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price($amount)."\n"; + print "".price($amount)."\n"; + print "\n"; - // TVA recuperee - $amount=0; - $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount"; - $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql.= " WHERE amount < 0"; - if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; - $sql.= " AND t.entity = ".$conf->entity; - $sql.= " GROUP BY dm"; - $sql.= " ORDER BY dm DESC"; + // TVA recuperee + $amount=0; + $sql = "SELECT date_format(t.datev,'%Y-%m') as dm, sum(t.amount) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql.= " WHERE amount < 0"; + if ($date_start && $date_end) $sql.= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; + $sql.= " AND t.entity = ".$conf->entity; + $sql.= " GROUP BY dm"; + $sql.= " ORDER BY dm DESC"; - dol_syslog("get vat really received back sql=".$sql); - $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); + dol_syslog("get vat really received back sql=".$sql); + $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); - $amount = $amount + $obj->amount; - $total_ht = $total_ht + $obj->amount; - $total_ttc = $total_ttc + $obj->amount; - $subtotal_ht = $subtotal_ht + $obj->amount; - $subtotal_ttc = $subtotal_ttc + $obj->amount; + $amount = $amount + $obj->amount; + $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++; - } - } - $db->free($result); - } else { - dol_print_error($db); - } - print " "; - print "".$langs->trans("VATCollected")."\n"; - if ($modecompta == 'CREANCES-DETTES') print "".price($amount)."\n"; - print "".price($amount)."\n"; - print "\n"; + $i++; + } + } + $db->free($result); + } else { + dol_print_error($db); + } + print " "; + print "".$langs->trans("VATCollected")."\n"; + if ($modecompta == 'CREANCES-DETTES') print "".price($amount)."\n"; + print "".price($amount)."\n"; + print "\n"; } if ($mysoc->tva_assuj != 'franchise') // Assujeti { - print ''; - if ($modecompta == 'CREANCES-DETTES') print ''.price($subtotal_ht).''; - print ''.price($subtotal_ttc).''; - print ''; + print ''; + if ($modecompta == 'CREANCES-DETTES') print ''.price($subtotal_ht).''; + print ''.price($subtotal_ttc).''; + print ''; } if ($mysoc->tva_assuj != 'franchise') // Assujeti { - // Total - print ''; - print ' '; - print ''; + // Total + print ''; + print ' '; + print ''; - print ''.$langs->trans("Profit").''; - if ($modecompta == 'CREANCES-DETTES') print ''.price($total_ht).''; - print ''.price($total_ttc).''; - print ''; + print ''.$langs->trans("Profit").''; + if ($modecompta == 'CREANCES-DETTES') print ''.price($total_ht).''; + print ''.price($total_ttc).''; + print ''; } print "";