* Copyright (C) 2014 Ferran Marcet * Copyright (C) 2018 Frédéric France * * 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/localtax/clients.php * \ingroup tax * \brief Third parties localtax report */ // Load Dolibarr environment 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'; require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php'; // Load translation files required by the page $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "product", "trips", "admin")); $local = GETPOST('localTaxType', 'int'); // Date range $year = GETPOST("year", "int"); if (empty($year)) { $year_current = dol_print_date(dol_now('gmt'), "%Y", 'gmt'); $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, empty($conf->global->SOCIETE_FISCAL_MONTH_START) ? 1 : $conf->global->SOCIETE_FISCAL_MONTH_START, false); if (empty($conf->global->MAIN_INFO_VAT_RETURN) || $conf->global->MAIN_INFO_VAT_RETURN == 2) { $date_end = dol_time_plus_duree($date_start, 3, 'm') - 1; } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 3) { $date_end = dol_time_plus_duree($date_start, 1, 'y') - 1; } elseif ($conf->global->MAIN_INFO_VAT_RETURN == 1) { $date_end = dol_time_plus_duree($date_start, 1, 'm') - 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); } } } $min = price2num(GETPOST("min", "alpha")); if (empty($min)) { $min = 0; } // 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->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'tax', '', '', 'charges'); if (empty($local)) { accessforbidden('Parameter localTaxType is missing'); exit; } $calc = 0; /* * View */ $form = new Form($db); $company_static = new Societe($db); $morequerystring = ''; $listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday'); foreach ($listofparams as $param) { if (GETPOST($param) != '') { $morequerystring .= ($morequerystring ? '&' : '').$param.'='.GETPOST($param); } } llxHeader('', '', '', '', 0, 0, '', '', $morequerystring); $name = $langs->transcountry($local == 1 ? "LT1ReportByCustomers" : "LT2ReportByCustomers", $mysoc->country_code); $fsearch = ''; $fsearch .= ''; $fsearch .= ''; $fsearch .= ''; $fsearch .= $langs->trans("SalesTurnoverMinimum").': '; $fsearch .= ''; $calc = $conf->global->MAIN_INFO_LOCALTAX_CALC.$local; // Affiche en-tete du rapport if ($calc == 0 || $calc == 1) { // Calculate on invoice for goods and services $calcmode = $calc == 0 ? $langs->trans("CalcModeLT".$local) : $langs->trans("CalcModeLT".$local."Rec"); $calcmode .= ' ('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')'; $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) { $description .= '
'.$langs->trans("WarningDepositsNotIncluded"); } $description .= $fsearch; $description .= ' ('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')'; $builddate = dol_now(); $elementcust = $langs->trans("CustomersInvoices"); $productcust = $langs->trans("Description"); $amountcust = $langs->trans("AmountHT"); $elementsup = $langs->trans("SuppliersInvoices"); $productsup = $langs->trans("Description"); $amountsup = $langs->trans("AmountHT"); } if ($calc == 2) { // Invoice for goods, payment for services $calcmode = $langs->trans("CalcModeLT2Debt"); $calcmode .= ' ('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')'; $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); if (!empty($conf->global->MAIN_MODULE_COMPTABILITE)) { $description .= '
'.$langs->trans("WarningDepositsNotIncluded"); } $description .= $fsearch; $description .= '('.$langs->trans("TaxModuleSetupToModifyRulesLT", DOL_URL_ROOT.'/admin/company.php').')'; $builddate = dol_now(); $elementcust = $langs->trans("CustomersInvoices"); $productcust = $langs->trans("Description"); $amountcust = $langs->trans("AmountHT"); $elementsup = $langs->trans("SuppliersInvoices"); $productsup = $langs->trans("Description"); $amountsup = $langs->trans("AmountHT"); } report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode); $vatcust = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code); $vatsup = $langs->transcountry($local == 1 ? "LT1" : "LT2", $mysoc->country_code); print '
'; print ''; // IRPF that the customer has retained me if ($calc == 0 || $calc == 2) { print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'sell'); $action = "tvaclient"; $object = &$coll_list; $parameters["mode"] = $modetax; $parameters["start"] = $date_start; $parameters["end"] = $date_end; $parameters["direction"] = 'sell'; $parameters["type"] = 'localtax'.$local; // 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_list)) { $total = 0; $totalamount = 0; $i = 1; foreach ($coll_list as $coll) { if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0) { $intra = str_replace($find, $replace, $coll->tva_intra); if (empty($intra)) { if ($coll->assuj == '1') { $intra = $langs->trans('Unknown'); } else { $intra = ''; } } print ''; print '"; $company_static->id = $coll->socid; $company_static->name = $coll->name; print ''; $find = array(' ', '.'); $replace = array('', ''); print ''; print ''; print ''; $totalamount = $totalamount + $coll->amount; $total = $total + ($local == 1 ? $coll->localtax1 : $coll->localtax2); print "\n"; $i++; } } $x_coll_sum = $total; print ''; print ''; print ''; print ''; } else { $langs->load("errors"); if ($coll_list == -1) { print ''; } elseif ($coll_list == -2) { print ''; } else { print ''; } } } // IRPF I retained my supplier if ($calc == 0 || $calc == 1) { print ''; print '"; print '"; print ''; print ''; print ''; print "\n"; $company_static = new Societe($db); $coll_list = tax_by_thirdparty('localtax'.$local, $db, 0, $date_start, $date_end, $modetax, 'buy'); $parameters["direction"] = 'buy'; $parameters["type"] = 'localtax'.$local; $reshook = $hookmanager->executeHooks('addVatLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if (is_array($coll_list)) { $total = 0; $totalamount = 0; $i = 1; foreach ($coll_list as $coll) { if (($min == 0 || ($min > 0 && $coll->amount > $min)) && ($local == 1 ? $coll->localtax1 : $coll->localtax2) != 0) { $intra = str_replace($find, $replace, $coll->tva_intra); if (empty($intra)) { if ($coll->assuj == '1') { $intra = $langs->trans('Unknown'); } else { $intra = ''; } } print ''; print '"; $company_static->id = $coll->socid; $company_static->name = $coll->name; print ''; $find = array(' ', '.'); $replace = array('', ''); print '"; print ''; print ''; $totalamount = $totalamount + $coll->amount; $total = $total + ($local == 1 ? $coll->localtax1 : $coll->localtax2); print "\n"; $i++; } } $x_paye_sum = $total; print ''; print ''; print ''; print ''; } else { $langs->load("errors"); if ($coll_list == -1) { print ''; } elseif ($coll_list == -2) { print ''; } else { print ''; } } } if ($calc == 0) { // Total to pay print ''; $diff = $x_coll_sum - $x_paye_sum; print ''; print ''; print '\n"; print "\n"; } print '
'.$langs->trans("Num").''.$langs->trans("Customer").''.$langs->transcountry("ProfId1", $mysoc->country_code).''.$langs->trans("TotalHT").''.$vatcust.'
'.$i."'.$company_static->getNomUrl(1).''.$intra.''.price($coll->amount).''.price($local == 1 ? $coll->localtax1 : $coll->localtax2).'
'.$langs->trans("Total").':'.price($totalamount).''.price($total).'
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
'.$langs->trans("Num")."'.$langs->trans("Supplier")."'.$langs->transcountry("ProfId1", $mysoc->country_code).''.$langs->trans("TotalHT").''.$vatsup.'
'.$i."'.$company_static->getNomUrl(1).''.$intra."'.price($coll->amount).''.price($local == 1 ? $coll->localtax1 : $coll->localtax2).'
'.$langs->trans("Total").':'.price($totalamount).''.price($total).'
'.$langs->trans("ErrorNoAccountancyModuleLoaded").'
'.$langs->trans("FeatureNotYetAvailable").'
'.$langs->trans("Error").'
'.$langs->trans("TotalToPay").($q ? ', '.$langs->trans("Quadri").' '.$q : '').''.price(price2num($diff, 'MT'))."
'; print '
'; // End of page llxFooter(); $db->close();