*
* 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/stats/byratecountry.php
* \brief VAT by rate
*/
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';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
// Load translation files required by the page
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin","accountancy"));
$modecompta = GETPOST('modecompta','alpha');
// Date range
$year=GETPOST("year",'int');
$month=GETPOST("month",'int');
if (empty($year))
{
$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;
}
$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","int");
if (empty($q))
{
// We define date_start and date_end
$month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
$year_end=$year_start;
$month_end=$month_start;
if (! GETPOST("month")) // If month not forced
{
if (! GETPOST('year') && $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);
}
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); }
}
}
// $date_start and $date_end are defined. We force $year_start and $nbofyear
$tmps=dol_getdate($date_start);
$year_start = $tmps['year'];
$tmpe=dol_getdate($date_end);
$year_end = $tmpe['year'];
$tmp_date_end = dol_time_plus_duree($date_start, 1, 'y') - 1;
if ($tmp_date_end < $date_end || $date_end < $date_start) $date_end = $tmp_date_end;
$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->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges');
/*
* View
*/
$form=new Form($db);
$company_static=new Societe($db);
$invoice_customer=new Facture($db);
$invoice_supplier=new FactureFournisseur($db);
$expensereport=new ExpenseReport($db);
$product_static=new Product($db);
$payment_static=new Paiement($db);
$paymentfourn_static=new PaiementFourn($db);
$paymentexpensereport_static=new PaymentExpenseReport($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('',$langs->trans("TurnoverReport"),'','',0,0,'','',$morequerystring);
//print load_fiche_titre($langs->trans("VAT"),"");
//$fsearch.=' ';
$fsearch.=' ';
$fsearch.=' ';
//$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
//$fsearch.=' ';
// Show report header
$name=$langs->trans("xxx");
$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').')';
// Set period
$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);
$prevyear=$year_start; $prevquarter=$q;
if ($prevquarter > 1) {
$prevquarter--;
} else {
$prevquarter=4; $prevyear--;
}
$nextyear=$year_start; $nextquarter=$q;
if ($nextquarter < 4) {
$nextquarter++;
} else {
$nextquarter=1; $nextyear++;
}
$description.=$fsearch;
$builddate=dol_now();
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");
// Customers invoices
$elementcust=$langs->trans("CustomersInvoices");
$productcust=$langs->trans("ProductOrService");
$amountcust=$langs->trans("AmountHT");
// Suppliers invoices
$elementsup=$langs->trans("SuppliersInvoices");
$productsup=$productcust;
$amountsup=$amountcust;
$namesup=$namecust;
// TODO Report from bookkeeping not yet available, so we switch on report on business events
if ($modecompta=="BOOKKEEPING") $modecompta="CREANCES-DETTES";
if ($modecompta=="BOOKKEEPINGCOLLECTED") $modecompta="RECETTES-DEPENSES";
// Show report header
if ($modecompta=="CREANCES-DETTES") {
$name=$langs->trans("Turnover").', '.$langs->trans("ByVatRate");
$calcmode=$langs->trans("CalcModeDebt");
//$calcmode.=' ('.$langs->trans("SeeReportInInputOutputMode",'','').')';
$description=$langs->trans("RulesCADue");
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
$description.= $langs->trans("DepositsAreNotIncluded");
} else {
$description.= $langs->trans("DepositsAreIncluded");
}
$builddate=dol_now();
}
else if ($modecompta=="RECETTES-DEPENSES")
{
$name=$langs->trans("TurnoverCollected").', '.$langs->trans("ByVatRate");
$calcmode=$langs->trans("CalcModeEngagement");
//$calcmode.=' ('.$langs->trans("SeeReportInDueDebtMode",'','').')';
$description=$langs->trans("RulesCAIn");
$description.= $langs->trans("DepositsAreIncluded");
$builddate=dol_now();
}
else if ($modecompta=="BOOKKEEPING")
{
}
else if ($modecompta=="BOOKKEEPINGCOLLECTED")
{
}
$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);
if ($date_end == dol_time_plus_duree($date_start, 1, 'y') - 1) $periodlink=''.img_previous().''.img_next().'';
else $periodlink = '';
$description.=' ';
report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
if (! empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING')
{
print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1);
}
if ($modecompta == 'CREANCES-DETTES')
{
print '
';
} else {
print $db->lasterror(); // Show last sql error
}
print "
\n";
} else {
// $modecompta != 'CREANCES-DETTES'
// "Calculation of part of each product for accountancy in this mode is not possible. When a partial payment (for example 5 euros) is done on an
// invoice with 2 product (product A for 10 euros and product B for 20 euros), what is part of paiment for product A and part of paiment for product B ?
// Because there is no way to know this, this report is not relevant.
print ' '.$langs->trans("TurnoverPerSaleTaxRateInCommitmentAccountingNotRelevant") . ' ';
}
llxFooter();
$db->close();