Fix log and duplicate vat_by_date function

This commit is contained in:
Laurent Destailleur 2018-03-27 14:37:29 +02:00
parent f9ee2930e2
commit 51cd793d80
5 changed files with 25 additions and 47 deletions

View File

@ -45,14 +45,14 @@ if ($year == 0)
// Security check
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
if ($user->societe_id)
if ($user->societe_id)
$socid=$user->societe_id;
$result = restrictedArea($user, 'tax', '', '', 'charges');
// Define modetax (0 or 1)
// 0=normal, 1=option vat for services is on debit
$modetax = $conf->global->TAX_MODE;
if (isset($_GET["modetax"]))
if (isset($_GET["modetax"]))
$modetax=$_GET["modetax"];
/**
@ -81,7 +81,7 @@ function pt ($db, $sql, $date)
$var=True;
while ($i < $num) {
$obj = $db->fetch_object($result);
print '<tr class="oddeven">';
print '<td class="nowrap">'.$obj->dm."</td>\n";
$total = $total + $obj->mm;
@ -166,16 +166,16 @@ $var=True;
$total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
$i=0;
for ($m = 1 ; $m < 13 ; $m++ ) {
$coll_listsell = vat_by_date($db, $y, 0, 0, 0, $modetax, 'sell', $m);
$coll_listbuy = vat_by_date($db, $y, 0, 0, 0, $modetax, 'buy', $m);
$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"] = 'localtax'.$localTaxType;
// 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
@ -190,7 +190,7 @@ for ($m = 1 ; $m < 13 ; $m++ ) {
break;
}
print '<tr class="oddeven">';
print '<td class="nowrap">'.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").'</td>';
if($CalcLT==0) {
@ -221,7 +221,7 @@ for ($m = 1 ; $m < 13 ; $m++ ) {
}
$subtotalcoll = $subtotalcoll + $x_coll;
print "<td class=\"nowrap\" align=\"right\">".price($x_coll)."</td><td></td>";
}
if($CalcLT==0) {
@ -231,7 +231,7 @@ for ($m = 1 ; $m < 13 ; $m++ ) {
} elseif($CalcLT==2) {
$diff= $x_coll;
}
$total = $total + $diff;
$subtotal = $subtotal + $diff;

View File

@ -144,8 +144,8 @@ $total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
$i=0;
for ($m = 1 ; $m < 13 ; $m++ )
{
$coll_listsell = vat_by_date($db, $y, 0, 0, 0, $modetax, 'sell', $m);
$coll_listbuy = vat_by_date($db, $y, 0, 0, 0, $modetax, 'buy', $m);
$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);

View File

@ -224,8 +224,8 @@ $total = 0;
$i=0;
// Load arrays of datas
$x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');
$x_coll = tax_by_date('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = tax_by_date('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
if (! is_array($x_coll) || ! is_array($x_paye))
{

View File

@ -260,8 +260,8 @@ $i=0;
$columns = 6;
// Load arrays of datas
$x_coll = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = vat_by_date($db, 0, 0, $date_start, $date_end, $modetax, 'buy');
$x_coll = tax_by_date('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
$x_paye = tax_by_date('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
if (!is_array($x_coll) || !is_array($x_paye)) {
$langs->load("errors");

View File

@ -32,7 +32,7 @@
* Prepare array with list of tabs
*
* @param ChargeSociales $object Object related to tabs
* @return array Array of tabs to show
* @return array Array of tabs to show
*/
function tax_prepare_head(ChargeSociales $object)
{
@ -184,7 +184,6 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction
* Gets Tax to collect for the given year (and given quarter or month)
* The function gets the Tax in split results, as the Tax declaration asks
* to report the amounts for different Tax rates as different lines.
* This function also accounts recurrent invoices.
*
* @param string $type Tax type, either 'vat', 'localtax1' or 'localtax2'
* @param DoliDB $db Database handler object
@ -236,7 +235,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$total_localtax1='total_localtax1';
$total_localtax2='total_localtax2';
// CAS DES BIENS
// Define sql request
@ -318,7 +317,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
if ($sql == 'TODO') return -2;
if ($sql != 'TODO')
{
dol_syslog("Tax.lib.php::vat_by_date", LOG_DEBUG);
dol_syslog("Tax.lib.php::tax_by_date", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
@ -414,7 +413,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
$sql.= " AND (d.product_type = 1"; // Limit to services
$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
}
else // Option vat on delivery for goods (payments) and payments for services
{
@ -458,13 +457,13 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
if (! $sql)
{
dol_syslog("Tax.lib.php::vat_by_date no accountancy module enabled".$sql,LOG_ERR);
dol_syslog("Tax.lib.php::tax_by_date no accountancy module enabled".$sql,LOG_ERR);
return -1; // -1 = Not accountancy module enabled
}
if ($sql == 'TODO') return -2; // -2 = Feature not yet available
if ($sql != 'TODO')
{
dol_syslog("Tax.lib.php::vat_by_date", LOG_DEBUG);
dol_syslog("Tax.lib.php::tax_by_date", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
@ -550,19 +549,19 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
}
if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
$sql.= " AND (d.product_type = -1";
$sql.= " AND (d.product_type = -1";
$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service
$sql.= " ORDER BY e.rowid";
if (! $sql)
{
dol_syslog("Tax.lib.php::vat_by_date no accountancy module enabled".$sql,LOG_ERR);
dol_syslog("Tax.lib.php::tax_by_date no accountancy module enabled".$sql,LOG_ERR);
return -1; // -1 = Not accountancy module enabled
}
if ($sql == 'TODO') return -2; // -2 = Feature not yet available
if ($sql != 'TODO')
{
dol_syslog("Tax.lib.php::vat_by_date", LOG_DEBUG);
dol_syslog("Tax.lib.php::tax_by_date", LOG_DEBUG);
$resql = $db->query($sql);
if ($resql)
{
@ -624,24 +623,3 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
return $list;
}
/**
* Gets VAT to collect for the given year (and given quarter or month)
* The function gets the VAT in split results, as the VAT declaration asks
* to report the amounts for different VAT rates as different lines.
* This function also accounts recurrent invoices.
*
* @param DoliDB $db Database handler object
* @param int $y Year
* @param int $q Quarter
* @param string $date_start Start date
* @param string $date_end End date
* @param int $modetax 0 or 1 (option vat on debit)
* @param int $direction 'sell' (customer invoice) or 'buy' (supplier invoices)
* @param int $m Month
* @return array List of quarters with vat
*/
function vat_by_date ($db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
{
return tax_by_date('vat', $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m);
}