* Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2018 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2014 Ferran Marcet * * 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/tva/index.php * \ingroup tax * \brief Index page of VAT reports */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; $langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin")); // Date range $year=GETPOST("year","int"); if (empty($year)) { $year_current = strftime("%Y",dol_now()); $year_start = $year_current; } else { $year_current = $year; $year_start = $year; } $date_start=dol_mktime(0,0,0,GETPOST("date_startmonth"),GETPOST("date_startday"),GETPOST("date_startyear")); $date_end=dol_mktime(23,59,59,GETPOST("date_endmonth"),GETPOST("date_endday"),GETPOST("date_endyear")); // Quarter if (empty($date_start) || empty($date_end)) // We define date_start and date_end { $q=GETPOST("q"); if (empty($q)) { if (GETPOST("month")) { $date_start=dol_get_first_day($year_start,GETPOST("month"),false); $date_end=dol_get_last_day($year_start,GETPOST("month"),false); } else { $date_start=dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,false); $date_end=dol_time_plus_duree($date_start, 1, 'y') - 1; } } else { 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); } } } // Define modetax (0 or 1) // 0=normal, 1=option vat for services is on debit, 2=option on payments for products $modetax = $conf->global->TAX_MODE; if (GETPOSTISSET("modetax")) $modetax=GETPOST("modetax",'int'); if (empty($modetax)) $modetax=0; // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'tax', '', '', 'charges'); /** * print function * * @param DoliDB $db Database handler * @param string $sql SQL Request * @param string $date Date * @return void */ function pt ($db, $sql, $date) { global $conf, $bc,$langs; $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); $i = 0; $total = 0; print ''; print ''; print ''; print ''; print ''."\n"; print "\n"; while ($i < $num) { $obj = $db->fetch_object($result); print ''; print '\n"; $total = $total + $obj->mm; print '\n"; print "\n"; $i++; } print '"; print "
'.$date.''.$langs->trans("Amount").' 
'.$obj->dm."'.price($obj->mm)." 
'.$langs->trans("Total")." :".price($total)." 
"; $db->free($result); } else { dol_print_error($db); } } /* * View */ $form=new Form($db); $company_static=new Societe($db); $tva = new Tva($db); $description = ''; // Show report header $name = $langs->trans("ReportByMonth"); $calcmode=''; if ($modetax == 0) $calcmode=$langs->trans('OptionVATDefault'); if ($modetax == 1) $calcmode=$langs->trans('OptionVATDebitOption'); if ($modetax == 2) $calcmode=$langs->trans('OptionPaymentForProductAndServices'); $calcmode.='
('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')'; $description = $langs->trans("VATSummary").'
'; if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description.=$langs->trans("RulesVATDueProducts"); if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') $description.=$langs->trans("RulesVATInProducts"); if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description.='
'.$langs->trans("RulesVATDueServices"); if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description.='
'.$langs->trans("RulesVATInServices"); if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $description.='
'.$langs->trans("DepositsAreNotIncluded"); } if (! empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description.='
'.$langs->trans("ThisIsAnEstimatedValue"); $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); $builddate=dol_now(); llxHeader('', $name); //$textprevyear="".img_previous($langs->trans("Previous"), 'class="valignbottom"').""; //$textnextyear=" ".img_next($langs->trans("Next"), 'class="valignbottom"').""; //print load_fiche_titre($langs->transcountry("VAT", $mysoc->country_code), $textprevyear." ".$langs->trans("Year")." ".$year_start." ".$textnextyear, 'title_accountancy.png'); report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode); //report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode); print '
'; print '
'; print load_fiche_titre($langs->trans("VATSummary"), '', ''); print ''; print ''; print ''; print ''; print ''; print ''; print ''."\n"; print ''."\n"; $tmp=dol_getdate($date_start); $y = $tmp['year']; $m = $tmp['mon']; $tmp=dol_getdate($date_end); $yend = $tmp['year']; $mend = $tmp['mon']; $total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0; $i=0; $mcursor=0; while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop { $m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12); if ($m == 13) $y++; if ($m > 12) $m -= 12; $mcursor++; $coll_listsell = tax_by_date('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m); $coll_listbuy = tax_by_date('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m); $action = "tva"; $object = array(&$coll_listsell, &$coll_listbuy); $parameters["mode"] = $modetax; $parameters["year"] = $y; $parameters["month"] = $m; $parameters["type"] = 'vat'; // Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('externalbalance')); $reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if (! is_array($coll_listbuy) && $coll_listbuy == -1) { $langs->load("errors"); print ''; break; } if (! is_array($coll_listbuy) && $coll_listbuy == -2) { print ''; break; } print ''; print ''; $x_coll = 0; foreach($coll_listsell as $vatrate=>$val) { $x_coll+=$val['vat']; } $subtotalcoll = $subtotalcoll + $x_coll; print ""; $x_paye = 0; foreach($coll_listbuy as $vatrate=>$val) { $x_paye+=$val['vat']; } $subtotalpaye = $subtotalpaye + $x_paye; print ""; $diff = $x_coll - $x_paye; $total = $total + $diff; $subtotal = $subtotal + $diff; print "\n"; print "\n"; print "\n"; $i++; if ($i > 2) { print ''; print ''; print ''; print ''; print ''; print ''; $i = 0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0; } } print ''; print "\n"; print ''; print '
'.$langs->trans("Year")." ".$y.''.$langs->trans("VATToPay").''.$langs->trans("VATToCollect").''.$langs->trans("Balance").' 
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").'".price($x_coll)."".price($x_paye)."".price($diff)." 
'.$langs->trans("SubTotal").':'.price($subtotalcoll).''.price($subtotalpaye).''.price($subtotal).' 
'.$langs->trans("TotalToPay").':'.price($total).' 
'; print '
'; print load_fiche_titre($langs->trans("VATPaid"), '', ''); /* * Payed */ $sql = "SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as f"; $sql.= " WHERE f.entity = ".$conf->entity; $sql.= " AND f.datep >= '".$db->idate($date_start)."'"; $sql.= " AND f.datep <= '".$db->idate($date_end)."'"; $sql.= " GROUP BY dm ORDER BY dm ASC"; pt($db, $sql,$langs->trans("Year")." $y"); print '
'; if (! empty($conf->global->MAIN_FEATURES_LEVEL)) { /* * Recap */ print load_fiche_titre($langs->trans("VATRecap"), '', ''); // need to add translation $sql1 = "SELECT SUM(amount) as mm, date_format(f.datev,'%Y') as dm"; $sql1 .= " FROM " . MAIN_DB_PREFIX . "tva as f"; $sql1 .= " WHERE f.entity = " . $conf->entity; $sql1 .= " AND f.datev >= '" . $db->idate($date_start) . "'"; $sql1 .= " AND f.datev <= '" . $db->idate($date_end) . "'"; $sql1 .= " GROUP BY dm ORDER BY dm ASC"; $result = $db->query($sql1); if ($result) { $obj = $db->fetch_object($result); print ''; print ""; print ''; // need to add translation print ''; print "\n"; print ""; print ''; print '\n"; print "\n"; $restopay = $total - $obj->mm; print ""; print ''; // need to add translation print ''; print "\n"; print '
' . $langs->trans("VATDue") . '' . price(price2num($total, 'MT')) . '
' . $langs->trans("VATPaid") . '' . price(price2num($obj->mm, 'MT')) . "
' . $langs->trans("VATRestopay") . '' . price(price2num($restopay, 'MT')) . '
'; } } print '
'; llxFooter(); $db->close();