* Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/compta/charges/index.php * \ingroup compta * \brief Page to list payments of social contributions and vat */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $langs->load("compta"); $langs->load("bills"); // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', '', '', 'charges'); $year=$_GET["year"]; $filtre=$_GET["filtre"]; if (! $year && $_GET["mode"] != 'sconly') { $year=date("Y", time()); } $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; $page = $_GET["page"]; if ($page < 0) $page = 0; //$limit = $conf->liste_limit; //$offset = $limit * $page ; if (! $sortfield) $sortfield="cs.date_ech"; if (! $sortorder) $sortorder="DESC"; /* * View */ $tva_static = new Tva($db); $socialcontrib=new ChargeSociales($db); $payment_sc_static=new PaymentSocialContribution($db); llxHeader('',$langs->trans("TaxAndDividendsArea")); $title=$langs->trans("TaxAndDividendsArea"); if ($_GET["mode"] == 'sconly') $title=$langs->trans("SocialContributionsPayments"); print_fiche_titre($title,($year?"".img_previous()." ".$langs->trans("Year")." $year ".img_next()."":"")); if ($_GET["mode"] != 'sconly') { print $langs->trans("DescTaxAndDividendsArea").'
'; print "
"; } // Social contributions if ($_GET["mode"] != 'sconly') { print_titre($langs->trans("SocialContributionsPayments")); } if ($_GET["mode"] == 'sconly') { $param='&mode=sconly'; } print ''; print ""; print_liste_field_titre($langs->trans("PeriodEndDate"),$_SERVER["PHP_SELF"],"cs.date_ech","",$param,'width="120"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"c.libelle","",$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"cs.fk_type","",$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("ExpectedToPay"),$_SERVER["PHP_SELF"],"cs.amount","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("RefPayment"),$_SERVER["PHP_SELF"],"pc.rowid","",$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DatePayment"),$_SERVER["PHP_SELF"],"pc.datep","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"pc.amount","",$param,'align="right"',$sortfield,$sortorder); print "\n"; $sql = "SELECT c.id, c.libelle as lib,"; $sql.= " cs.rowid, cs.libelle, cs.fk_type as type, cs.periode, cs.date_ech, cs.amount as total,"; $sql.= " pc.rowid as pid, pc.datep, pc.amount as totalpaye"; $sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; $sql.= " ".MAIN_DB_PREFIX."chargesociales as cs"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiementcharge as pc ON pc.fk_charge = cs.rowid"; $sql.= " WHERE cs.fk_type = c.id"; $sql.= " AND cs.entity = ".$conf->entity; if ($year > 0) { $sql .= " AND ("; // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire $sql .= " (cs.periode IS NOT NULL AND cs.periode between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')"; $sql .= "OR (cs.periode IS NULL AND cs.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')"; $sql .= ")"; } $sql.= $db->order($sortfield,$sortorder); //$sql.= $db->plimit($limit+1,$offset); //print $sql; dol_syslog("compta/charges/index.php: select payment sql=".$sql); $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $total = 0; $totalnb = 0; $totalpaye = 0; $var=true; while ($i < $num) { $obj = $db->fetch_object($resql); $var = !$var; print ""; // Date $date=$obj->periode; if (empty($date)) $date=$obj->date_ech; print ''; // Label print ''; // Type print ''; // Expected to pay print ''; // Ref payment $payment_sc_static->id=$obj->pid; $payment_sc_static->ref=$obj->pid; print '\n"; // Date payment print ''; // Paid print ''; print ''; $total = $total + $obj->total; $totalnb = $totalnb + $obj->nb; $totalpaye = $totalpaye + $obj->totalpaye; $i++; } print ''; print '"; print ''; print ''; print '"; print ""; } else { dol_print_error($db); } print '
'.dol_print_date($date,'day').''; $socialcontrib->id=$obj->rowid; $socialcontrib->ref=$obj->libelle; $socialcontrib->lib=$obj->libelle; print $socialcontrib->getNomUrl(1,'20'); print ''.$obj->lib.''.price($obj->total).''.$payment_sc_static->getNomUrl(1)."'.dol_print_date($db->jdate($obj->datep),'day').''.price($obj->totalpaye).'
'.$langs->trans("Total").''.price($total)."  '.price($totalpaye)."
'; // VAT if (empty($_GET["mode"]) || $_GET["mode"] != 'sconly') { print "
"; $tva = new Tva($db); print_titre($langs->trans("VATPayments")); $sql = "SELECT f.rowid, f.amount, f.label, f.datev as dm"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as f "; $sql.= " WHERE f.entity = ".$conf->entity; if ($year > 0) { // Si period renseignee on l'utilise comme critere de date, sinon on prend date echeance, // ceci afin d'etre compatible avec les cas ou la periode n'etait pas obligatoire $sql.= " AND f.datev between '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; } $sql.= " ORDER BY dm DESC"; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; $total = 0 ; print ''; print ''; print ''; print ""; print '"; print '"; print '"; print '"; print "\n"; $var=1; while ($i < $num) { $obj = $db->fetch_object($result); $total = $total + $obj->amount; $var=!$var; print ""; print ''."\n"; print "\n"; print '"; $tva_static->id=$obj->rowid; $tva_static->ref=$obj->rowid; print '\n"; print '\n"; print ""; print "\n"; $i++; } print ''; print '"; print ''; print ''; print '"; print ""; print "
'.$langs->trans("PeriodEndDate").'".$langs->trans("Label")."'.$langs->trans("ExpectedToPay")."'.$langs->trans("RefPayment")."'.$langs->trans("DatePayment")."'.$langs->trans("PayedByThisPayment")."
'.dol_print_date($db->jdate($obj->dm),'day').' ? ".$obj->label."'.price($obj->amount)."'.$tva_static->getNomUrl(1)."'.dol_print_date($db->jdate($obj->dm),'day')."".price($obj->amount)."
'.$langs->trans("Total").''.price($total)."  '.price($total)."
"; $db->free($result); } else { dol_print_error($db); } } $db->close(); llxFooter(); ?>