Suite rapport TVA
This commit is contained in:
parent
8a247d0680
commit
8c18002659
185
htdocs/admin/compta.php
Normal file
185
htdocs/admin/compta.php
Normal file
@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/admin/compta.php
|
||||
\ingroup tax
|
||||
\brief Page de configuration du module tax
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require('./pre.inc.php');
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
|
||||
|
||||
$langs->load('admin');
|
||||
$langs->load('compta');
|
||||
|
||||
if (!$user->admin)
|
||||
accessforbidden();
|
||||
|
||||
|
||||
llxHeader();
|
||||
|
||||
|
||||
$compta_mode = defined('COMPTA_MODE')?COMPTA_MODE:'RECETTES-DEPENSES';
|
||||
|
||||
if ($_POST['action'] == 'setcomptamode')
|
||||
{
|
||||
$compta_mode = $_POST['compta_mode'];
|
||||
if (! dolibarr_set_const($db, 'COMPTA_MODE', $compta_mode)) { print $db->error(); }
|
||||
}
|
||||
|
||||
|
||||
$form = new Form($db);
|
||||
$typeconst=array('yesno','texte','chaine');
|
||||
|
||||
|
||||
if ($_POST['action'] == 'update' || $_POST['action'] == 'add')
|
||||
{
|
||||
if (! dolibarr_set_const($db, $_POST['constname'], $_POST['constvalue'], $typeconst[$_POST['consttype']], 0, isset($_POST['constnote']) ? $_POST['constnote'] : ''));
|
||||
{
|
||||
print $db->error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($_GET['action'] == 'delete')
|
||||
{
|
||||
if (! dolibarr_del_const($db, $_GET['constname']));
|
||||
{
|
||||
print $db->error();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Affichage page
|
||||
*/
|
||||
|
||||
$html=new Form($db);
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print_fiche_titre($langs->trans('ComptaSetup'),$linkback,'setup');
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
// Cas du parametre COMPTA_MODE
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
print '<input type="hidden" name="action" value="setcomptamode">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans('OptionMode').'</td><td>'.$langs->trans('Description').'</td>';
|
||||
print '<td align="right"><input class="button" type="submit" value="'.$langs->trans('Modify').'"></td>';
|
||||
print "</tr>\n";
|
||||
print '<tr '.$bc[false].'><td width="200"><input type="radio" name="compta_mode" value="RECETTES-DEPENSES"'.($compta_mode != 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeTrue').'</td>';
|
||||
print '<td colspan="2">'.nl2br($langs->trans('OptionModeTrueDesc'));
|
||||
// Write info on way to count VAT
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
// print "<br>\n";
|
||||
// print nl2br($langs->trans('OptionModeTrueInfoModuleComptabilite'));
|
||||
}
|
||||
else
|
||||
{
|
||||
// print "<br>\n";
|
||||
// print nl2br($langs->trans('OptionModeTrueInfoExpert'));
|
||||
}
|
||||
print "</td></tr>\n";
|
||||
print '<tr '.$bc[true].'><td width="200"><input type="radio" name="compta_mode" value="CREANCES-DETTES"'.($compta_mode == 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeVirtual').'</td>';
|
||||
print '<td colspan="2">'.nl2br($langs->trans('OptionModeVirtualDesc'))."</td></tr>\n";
|
||||
print '</form>';
|
||||
|
||||
print "</table>\n";
|
||||
|
||||
print "<br>\n";
|
||||
|
||||
// Cas des autres parametres COMPTA_*
|
||||
$sql ="SELECT rowid, name, value, type, note";
|
||||
$sql.=" FROM llx_const";
|
||||
$sql.=" WHERE name like 'COMPTA_%' and name not in ('COMPTA_MODE')";
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$num = $db->num_rows($result);
|
||||
$i = 0;
|
||||
$var=true;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td colspan="3">'.$langs->trans('OtherOptions').'</td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $db->fetch_object($result);
|
||||
$var=!$var;
|
||||
|
||||
print '<form action="compta.php" method="POST">';
|
||||
print '<input type="hidden" name="action" value="update">';
|
||||
print '<input type="hidden" name="rowid" value="'.$rowid.'">';
|
||||
print '<input type="hidden" name="constname" value="'.$obj->name.'">';
|
||||
|
||||
print '<tr '.$bc[$var].' class="value">';
|
||||
|
||||
// Param
|
||||
print '<td>'.stripslashes(nl2br($obj->note));
|
||||
print $obj->name;
|
||||
print "</td>\n";
|
||||
|
||||
// Value
|
||||
print '<td>';
|
||||
if ($obj->type == 'yesno')
|
||||
{
|
||||
print $form->selectyesno('constvalue',$obj->value,1);
|
||||
}
|
||||
elseif ($obj->type == 'texte')
|
||||
{
|
||||
print '<textarea name="constvalue" cols="35" rows="5" wrap="soft">';
|
||||
print $obj->value;
|
||||
print "</textarea>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<input type="text" size="30" name="constvalue" value="'.stripslashes($obj->value).'">';
|
||||
}
|
||||
print '</td><td>';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"> ';
|
||||
print "</td></tr>\n";
|
||||
|
||||
print '</form>';
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($num)
|
||||
{
|
||||
print "</table>\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
?>
|
||||
100
htdocs/admin/taxes.php
Normal file
100
htdocs/admin/taxes.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/admin/taxes.php
|
||||
\ingroup tax
|
||||
\brief Page de configuration du module tax
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
require('./pre.inc.php');
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
|
||||
|
||||
$langs->load('admin');
|
||||
$langs->load('compta');
|
||||
$langs->load('taxes');
|
||||
|
||||
if (!$user->admin)
|
||||
accessforbidden();
|
||||
|
||||
|
||||
llxHeader();
|
||||
|
||||
|
||||
// 0=normal, 1=option vat for services is on debit
|
||||
$tax_mode = defined('TAX_MODE')?TAX_MODE:0;
|
||||
|
||||
if ($_POST['action'] == 'settaxmode')
|
||||
{
|
||||
$tax_mode = $_POST['tax_mode'];
|
||||
if (! dolibarr_set_const($db, 'TAX_MODE', $tax_mode)) { print $db->error(); }
|
||||
}
|
||||
|
||||
if ($_POST['action'] == 'update' || $_POST['action'] == 'add')
|
||||
{
|
||||
if (! dolibarr_set_const($db, $_POST['constname'], $_POST['constvalue'], $typeconst[$_POST['consttype']], 0, isset($_POST['constnote']) ? $_POST['constnote'] : ''));
|
||||
{
|
||||
print $db->error();
|
||||
}
|
||||
}
|
||||
|
||||
if ($_GET['action'] == 'delete')
|
||||
{
|
||||
if (! dolibarr_del_const($db, $_GET['constname']));
|
||||
{
|
||||
print $db->error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Affichage page
|
||||
*/
|
||||
|
||||
$html=new Form($db);
|
||||
|
||||
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
|
||||
print_fiche_titre($langs->trans('TaxSetup'),$linkback,'setup');
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
// Cas du parametre TAX_MODE
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||
print '<input type="hidden" name="action" value="settaxmode">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans('OptionVatMode').'</td><td>'.$langs->trans('Description').'</td>';
|
||||
print '<td align="right"><input class="button" type="submit" value="'.$langs->trans('Modify').'"></td>';
|
||||
print "</tr>\n";
|
||||
print '<tr '.$bc[false].'><td width="200"><input type="radio" name="tax_mode" value="0"'.($tax_mode != 1 ? ' checked' : '').'> '.$langs->trans('OptionVATDefault').'</td>';
|
||||
print '<td colspan="2">'.nl2br($langs->trans('OptionVatDefaultDesc'));
|
||||
print "</td></tr>\n";
|
||||
print '<tr '.$bc[true].'><td width="200"><input type="radio" name="tax_mode" value="1"'.($tax_mode == 1 ? ' checked' : '').'> '.$langs->trans('OptionVATDebitOption').'</td>';
|
||||
print '<td colspan="2">'.nl2br($langs->trans('OptionVatDebitOptionDesc'))."</td></tr>\n";
|
||||
print '</form>';
|
||||
|
||||
print "</table>\n";
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
?>
|
||||
@ -2041,7 +2041,7 @@ else
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf';
|
||||
$sql.= ' WHERE pf.fk_facture = '.$fac->id.' AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid';
|
||||
$sql.= ' ORDER BY dp, tms';
|
||||
|
||||
|
||||
$result = $db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -2305,7 +2305,7 @@ else
|
||||
/*
|
||||
* Lignes de factures
|
||||
*/
|
||||
$sql = 'SELECT l.fk_product, l.description, l.qty, l.rowid, l.tva_taux,';
|
||||
$sql = 'SELECT l.fk_product, l.product_type, l.description, l.qty, l.rowid, l.tva_taux,';
|
||||
$sql.= ' l.fk_remise_except,';
|
||||
$sql.= ' l.remise_percent, l.subprice, l.info_bits,';
|
||||
$sql.= ' l.total_ht, l.total_tva, l.total_ttc,';
|
||||
@ -2376,6 +2376,7 @@ else
|
||||
{
|
||||
print '<td>';
|
||||
print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
|
||||
|
||||
if (($objp->info_bits & 2) == 2)
|
||||
{
|
||||
print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$fac->socid.'">';
|
||||
@ -2397,7 +2398,9 @@ else
|
||||
}
|
||||
else
|
||||
{
|
||||
print nl2br($objp->description);
|
||||
if ($objp->product_type==1) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' '.nl2br($objp->description);
|
||||
print_date_range($objp->date_start,$objp->date_end);
|
||||
}
|
||||
print "</td>\n";
|
||||
|
||||
@ -53,9 +53,9 @@ if($min == 0 or $min!=floatval(strval($min))){
|
||||
//keep min
|
||||
}
|
||||
|
||||
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
|
||||
$modecompta = $conf->compta->mode;
|
||||
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
|
||||
// Define modetax (0 or 1)
|
||||
$modetax = $conf->global->TAX_MODE;
|
||||
if ($_GET["modetax"]) $modetax=$_GET["modetax"];
|
||||
|
||||
|
||||
|
||||
@ -77,13 +77,14 @@ $fsearch.=' <input type="submit" class="button" name="submit" value="'.$langs->
|
||||
$fsearch.='</form>';
|
||||
|
||||
// Affiche en-tête du rapport
|
||||
if ($modecompta=="CREANCES-DETTES")
|
||||
if ($modetax==1) // Caluclate on invoice for goods and services
|
||||
{
|
||||
$nom=$langs->trans("ReportByCustomers");
|
||||
//$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
|
||||
$nom=$langs->trans("VATReportByCustomersInDueDebtMode");
|
||||
$nom.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
|
||||
$period=$year_start;
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("VATReportDesc");
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("RulesVATDue");
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
|
||||
$description.=$fsearch;
|
||||
$builddate=time();
|
||||
$exportlink=$langs->trans("NotYetAvailable");
|
||||
@ -99,13 +100,14 @@ if ($modecompta=="CREANCES-DETTES")
|
||||
$vatsup=$langs->trans("VATPayed");
|
||||
if ($conf->global->FACTURE_TVAOPTION != 'franchise') $vatsup.=' ('.$langs->trans("VATToCollect").')';
|
||||
}
|
||||
else {
|
||||
$nom=$langs->trans("ReportByCustomers");
|
||||
//$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
|
||||
if ($modetax==0) // Invoice for goods, payment for services
|
||||
{
|
||||
$nom=$langs->trans("VATReportByCustomersInInputOutputMode");
|
||||
$nom.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')';
|
||||
$period=$year_start;
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("VATReportDesc");
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionModeTrueInfoModuleComptabilite');
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("RulesVATIn");
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
|
||||
$description.=$fsearch;
|
||||
$builddate=time();
|
||||
$exportlink=$langs->trans("NotYetAvailable");
|
||||
@ -138,7 +140,7 @@ print "<td align=\"right\">".$langs->trans("SalesTurnover")." ".$langs->trans("H
|
||||
print "<td align=\"right\">".$vatcust."</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
$coll_list = vat_received_by_customer($db,$year_current);
|
||||
$coll_list = vat_received_by_customer($db,$year_current,$modetax);
|
||||
if (is_array($coll_list))
|
||||
{
|
||||
$var=true;
|
||||
@ -183,7 +185,7 @@ if (is_array($coll_list))
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
|
||||
//print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
@ -205,7 +207,7 @@ print "</tr>\n";
|
||||
|
||||
$company_static=new Societe($db);
|
||||
|
||||
$coll_list = vat_payed_by_supplier($db,$year_current);
|
||||
$coll_list = vat_payed_by_supplier($db,$year_current,$modetax);
|
||||
if (is_array($coll_list))
|
||||
{
|
||||
$var=true;
|
||||
@ -250,7 +252,7 @@ if (is_array($coll_list))
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
|
||||
//print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
@ -50,9 +50,9 @@ if ($year == 0 )
|
||||
$year_start = $year;
|
||||
}
|
||||
|
||||
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
|
||||
$modecompta = $conf->compta->mode;
|
||||
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
|
||||
// Define modetax (0 or 1)
|
||||
$modetax = $conf->global->TAX_MODE;
|
||||
if ($_GET["modetax"]) $modetax=$_GET["modetax"];
|
||||
|
||||
|
||||
|
||||
@ -70,13 +70,14 @@ $product_static=new Product($db);
|
||||
print_fiche_titre($langs->trans("VAT"),"");
|
||||
|
||||
// Affiche en-tête du rapport
|
||||
if ($modecompta=="CREANCES-DETTES")
|
||||
if ($modetax==1) // Caluclate on invoice for goods and services
|
||||
{
|
||||
$nom=$langs->trans("ReportByQuarter");
|
||||
//$nom.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
|
||||
$nom=$langs->trans("VATReportByQuartersInDueDebtMode");
|
||||
$nom.='<br>('.$langs->trans("SeeVATReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=0">','</a>').')';
|
||||
$period=$year_start;
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("VATReportDesc");
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("RulesVATDue");
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
|
||||
$description.=$fsearch;
|
||||
$builddate=time();
|
||||
$exportlink=$langs->trans("NotYetAvailable");
|
||||
@ -92,13 +93,14 @@ if ($modecompta=="CREANCES-DETTES")
|
||||
$vatsup=$langs->trans("VATPayed");
|
||||
if ($conf->global->FACTURE_TVAOPTION != 'franchise') $vatsup.=' ('.$langs->trans("VATToCollect").')';
|
||||
}
|
||||
else {
|
||||
$nom=$langs->trans("ReportByQuarter");
|
||||
//$nom.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
|
||||
if ($modetax==0) // Invoice for goods, payment for services
|
||||
{
|
||||
$nom=$langs->trans("VATReportByQuartersInInputOutputMode");
|
||||
$nom.='<br>('.$langs->trans("SeeVATReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year='.$year_start.'&modetax=1">','</a>').')';
|
||||
$period=$year_start;
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modecompta=".$modecompta."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modecompta=".$modecompta."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("VATReportDesc");
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionModeTrueInfoModuleComptabilite');
|
||||
$periodlink=($year_start?"<a href='".$_SERVER["PHP_SELF"]."?year=".($year_start-1)."&modetax=".$modetax."'>".img_previous()."</a> <a href='".$_SERVER["PHP_SELF"]."?year=".($year_start+1)."&modetax=".$modetax."'>".img_next()."</a>":"");
|
||||
$description=$langs->trans("RulesVATIn");
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE) $description.='<br>'.img_warning().' '.$langs->trans('OptionVatInfoModuleComptabilite');
|
||||
$description.=$fsearch;
|
||||
$builddate=time();
|
||||
$exportlink=$langs->trans("NotYetAvailable");
|
||||
@ -131,21 +133,22 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
$subtot_paye_total = 0;
|
||||
$subtot_paye_vat = 0;
|
||||
|
||||
$x_coll = vat_received_by_quarter($db, $y, $q);
|
||||
$x_paye = vat_payed_by_quarter($db, $y, $q);
|
||||
$x_coll = vat_by_quarter($db, $y, $q, $modetax, 'sell');
|
||||
$x_paye = vat_by_quarter($db, $y, $q, $modetax, 'buy');
|
||||
|
||||
if (! is_array($x_coll))
|
||||
if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
{
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
|
||||
//print '<tr><td colspan="5">'.$langs->trans("FeatureIsSupportedInInOutModeOnly").'</td></tr>';
|
||||
break;
|
||||
}
|
||||
|
||||
$x_both = array();
|
||||
//now, from these two arrays, get another array with one rate per line
|
||||
foreach(array_keys($x_coll) as $my_coll_rate){
|
||||
foreach(array_keys($x_coll) as $my_coll_rate)
|
||||
{
|
||||
$x_both[$my_coll_rate]['coll']['totalht'] = $x_coll[$my_coll_rate]['totalht'];
|
||||
$x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
|
||||
$x_both[$my_coll_rate]['coll']['vat'] = $x_coll[$my_coll_rate]['vat'];
|
||||
$x_both[$my_coll_rate]['paye']['totalht'] = 0;
|
||||
$x_both[$my_coll_rate]['paye']['vat'] = 0;
|
||||
$x_both[$my_coll_rate]['coll']['links'] = '';
|
||||
@ -155,14 +158,19 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
|
||||
$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
|
||||
$x_both[$my_coll_rate]['coll']['detail'][] = array(
|
||||
'id'=>$x_coll[$my_coll_rate]['facid'][$id],
|
||||
'descr'=>$x_coll[$my_coll_rate]['descr'][$id],
|
||||
'pid'=>$x_coll[$my_coll_rate]['pid'][$id],
|
||||
'pref'=>$x_coll[$my_coll_rate]['pref'][$id],
|
||||
'ptype'=>$x_coll[$my_coll_rate]['ptype'][$id],
|
||||
'link'=>$invoice_customer->getNomUrl(1),
|
||||
'totalht'=>$x_coll[$my_coll_rate]['totalht_list'][$id],
|
||||
'vat'=>$x_coll[$my_coll_rate]['vat_list'][$id]);
|
||||
'id' =>$x_coll[$my_coll_rate]['facid'][$id],
|
||||
'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
|
||||
'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
|
||||
'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
|
||||
'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
|
||||
'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
|
||||
'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
|
||||
'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
|
||||
'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
|
||||
'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
|
||||
'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
|
||||
'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
|
||||
'link' =>$invoice_customer->getNomUrl(1));
|
||||
//$x_both[$my_coll_rate]['coll']['links'] .= '<a href="../facture.php?facid='.$x_coll[$my_coll_rate]['facid'][$id].'" title="'.$x_coll[$my_coll_rate]['facnum'][$id].'">..'.substr($x_coll[$my_coll_rate]['facnum'][$id],-2).'</a> ';
|
||||
}
|
||||
}
|
||||
@ -182,14 +190,19 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
|
||||
$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
|
||||
$x_both[$my_paye_rate]['paye']['detail'][] = array(
|
||||
'id'=>$x_paye[$my_paye_rate]['facid'][$id],
|
||||
'descr'=>$x_paye[$my_paye_rate]['descr'][$id],
|
||||
'pid'=>$x_paye[$my_paye_rate]['pid'][$id],
|
||||
'pref'=>$x_coll[$my_coll_rate]['pref'][$id],
|
||||
'ptype'=>$x_coll[$my_coll_rate]['ptype'][$id],
|
||||
'link'=>$invoice_supplier->getNomUrl(1),
|
||||
'totalht'=>$x_paye[$my_paye_rate]['totalht_list'][$id],
|
||||
'vat'=>$x_paye[$my_paye_rate]['vat_list'][$id]);
|
||||
'id' =>$x_paye[$my_paye_rate]['facid'][$id],
|
||||
'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
|
||||
'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
|
||||
'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
|
||||
'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
|
||||
'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
|
||||
'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
|
||||
'ftotal_ttc'=>$x_paye[$my_paye_rate]['ftotal_ttc'][$id],
|
||||
'dtotal_ttc'=>$x_paye[$my_paye_rate]['dtotal_ttc'][$id],
|
||||
'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
|
||||
'totalht' =>$x_paye[$my_paye_rate]['totalht_list'][$id],
|
||||
'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
|
||||
'link' =>$invoice_supplier->getNomUrl(1));
|
||||
//$x_both[$my_paye_rate]['paye']['links'] .= '<a href="../../fourn/facture/fiche.php?facid='.$x_paye[$my_paye_rate]['facid'][$id].'" title="'.$x_paye[$my_paye_rate]['facnum'][$id].'">..'.substr($x_paye[$my_paye_rate]['facnum'][$id],-2).'</a> ';
|
||||
}
|
||||
}
|
||||
@ -202,13 +215,21 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
$x_coll_ht = 0;
|
||||
$x_paye_sum = 0;
|
||||
$x_paye_ht = 0;
|
||||
|
||||
$span=3;
|
||||
if ($modetax == 0) $span+=2;
|
||||
|
||||
print '<tr><td colspan="4">'.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(12,0,0,(($q-1)*3)+1,1,$y)).' - '.strftime("%b %Y",dolibarr_mktime(12,0,0,($q*3),1,$y)).')</td></tr>';
|
||||
print '<tr><td colspan="'.($span+1).'">'.$langs->trans("Quadri")." $q (".strftime("%b %Y",dolibarr_mktime(12,0,0,(($q-1)*3)+1,1,$y)).' - '.strftime("%b %Y",dolibarr_mktime(12,0,0,($q*3),1,$y)).')</td></tr>';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementcust.'</td>';
|
||||
print '<td align="left">'.$productcust.'</td>';
|
||||
print '<td align="right">'.$amountcust.'</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td align="right">'.$amountcust.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' (% of invoice)</td>';
|
||||
}
|
||||
print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
|
||||
print '<td align="right">'.$vatcust.'</td>';
|
||||
print '</tr>';
|
||||
$var=true;
|
||||
@ -217,7 +238,7 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
if (is_array($x_both[$rate]['coll']['detail']))
|
||||
{
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="3"></td>';
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
|
||||
print '</tr>'."\n";
|
||||
foreach($x_both[$rate]['coll']['detail'] as $index => $fields)
|
||||
{
|
||||
@ -225,36 +246,88 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td nowrap align="left">'.$fields['link'].'</td>';
|
||||
print '<td align="left">';
|
||||
if ($fields['pid']) {
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->fk_product_type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if ($fields['descr']) print ' - ';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' ';
|
||||
}
|
||||
print dolibarr_trunc($fields['descr'],24).'</td>';
|
||||
print '<td nowrap align="right">'.price($fields['totalht']).'</td>';
|
||||
print '<td nowrap align="right">'.price($fields['vat']).'</td>';
|
||||
// Amount line
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td nowrap align="right">';
|
||||
print price($fields['totalht']);
|
||||
if ($fields['ftotal_ttc'])
|
||||
{
|
||||
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
|
||||
$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
|
||||
//print ' ('.round($ratiolineinvoice*100,2).'%)';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
// Payment
|
||||
$ratiopaymentinvoice=1;
|
||||
if ($modetax == 0)
|
||||
{
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
print '<td nowrap align="right">';
|
||||
print $fields['payment_amount'];
|
||||
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
print '</td>';
|
||||
}
|
||||
print '<td nowrap align="right">';
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
// VAT
|
||||
print '<td nowrap align="right">';
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_coll_total += $temp_ht;
|
||||
$subtot_coll_vat += $temp_vat;
|
||||
$x_coll_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
$x_coll_sum += $x_both[$rate]['coll']['vat'];
|
||||
$subtot_coll_total += $x_both[$rate]['coll']['totalht'];
|
||||
$subtot_coll_vat += $x_both[$rate]['coll']['vat'];
|
||||
}
|
||||
print '<tr class="liste_total">' .
|
||||
'<td></td>' .
|
||||
'<td align="right">'.$langs->trans("Total").':</td>' .
|
||||
'<td nowrap align="right">'.price($subtot_coll_total).'</td>' .
|
||||
'<td nowrap align="right">'.price($subtot_coll_vat).'</td>' .
|
||||
'</tr>' ;
|
||||
|
||||
print '<tr class="liste_total">';
|
||||
print '<td></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td nowrap align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num($subtot_coll_total,'MT')).'</td>';
|
||||
print '<td nowrap align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
|
||||
|
||||
//print table headers for this quadri - expenses now
|
||||
//imprime les en-tete de tables pour ce quadri - maintenant les dépenses
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementsup.'</td>';
|
||||
print '<td align="left">'.$productsup.'</td>';
|
||||
print '<td align="right">'.$amountsup.'</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td align="right">'.$amountsup.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' (% of invoice)</td>';
|
||||
}
|
||||
print '<td align="right">'.$langs->trans("AmountHTVATRealPayed").'</td>';
|
||||
print '<td align="right">'.$vatsup.'</td>';
|
||||
print '</tr>'."\n";
|
||||
$var=true;
|
||||
@ -263,46 +336,97 @@ for ($q = 1 ; $q <= 4 ; $q++ )
|
||||
if(is_array($x_both[$rate]['paye']['detail']))
|
||||
{
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="3"></td>';
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
|
||||
print '</tr>'."\n";
|
||||
foreach($x_both[$rate]['paye']['detail'] as $index=>$fields){
|
||||
foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
|
||||
{
|
||||
$var=!$var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td nowrap align="left">'.$fields['link'].'</td>';
|
||||
print '<td align="left">';
|
||||
print $fields['pid'];
|
||||
print $fields['descr'].'</td>';
|
||||
print '<td nowrap align="right">'.price($fields['totalht']).'</td>';
|
||||
print '<td nowrap align="right">'.price($fields['vat']).'</td>';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->fk_product_type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if ($fields['descr']) print ' - ';
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($fields['dtype']==1) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' ';
|
||||
}
|
||||
print dolibarr_trunc($fields['descr'],24).'</td>';
|
||||
// Amount line
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td nowrap align="right">';
|
||||
print price($fields['totalht']);
|
||||
if ($fields['ftotal_ttc'])
|
||||
{
|
||||
//print $fields['dtotal_ttc']."/".$fields['ftotal_ttc']." - ";
|
||||
$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
|
||||
//print ' ('.round($ratiolineinvoice*100,2).'%)';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
// Payment
|
||||
$ratiopaymentinvoice=1;
|
||||
if ($modetax == 0)
|
||||
{
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
print '<td nowrap align="right">';
|
||||
print $fields['payment_amount'];
|
||||
if ($fields['payment_amount'] && $ratiopaymentinvoice) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
print '</td>';
|
||||
}
|
||||
print '<td nowrap align="right">';
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($ratiopaymentinvoice) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
// VAT
|
||||
print '<td nowrap align="right">';
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_paye_total += $temp_ht;
|
||||
$subtot_paye_vat += $temp_vat;
|
||||
$x_paye_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
$x_paye_sum += $x_both[$rate]['paye']['vat'];
|
||||
$subtot_paye_total += $x_both[$rate]['paye']['totalht'];
|
||||
$subtot_paye_vat += $x_both[$rate]['paye']['vat'];
|
||||
}
|
||||
print '<tr class="liste_total">' .
|
||||
'<td></td>' .
|
||||
'<td align="right">'.$langs->trans("Total").':</td>' .
|
||||
'<td nowrap align="right">'.price($subtot_paye_total).'</td>' .
|
||||
'<td nowrap align="right">'.price($subtot_paye_vat).'</td>' .
|
||||
'</tr>';
|
||||
|
||||
print '<tr class="liste_total">';
|
||||
print '<td></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td nowrap align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num($subtot_paye_total,'MT')).'</td>';
|
||||
print '<td nowrap align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
|
||||
print '<tr>';
|
||||
print '<td colspan="3"></td><td align="right">'.$langs->trans("TotalToPay").' - '.$langs->trans("Quadri").$q.'</td>';
|
||||
print '<td colspan="'.$span.'"></td><td align="right">'.$langs->trans("TotalToPay").', '.$langs->trans("Quadri").$q.'</td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
$diff = $x_coll_sum - $x_paye_sum;
|
||||
//$total = $total + $diff;
|
||||
//$subtotal = $subtotal + $diff;
|
||||
|
||||
print "<tr>";
|
||||
print '<td colspan="3"></td>';
|
||||
//print '<td nowrap align="right"><b>'.price($total).'</b></td>' .
|
||||
print '<td nowrap align="right"><b>'.price($diff)."</b></td>\n";
|
||||
print '<td colspan="'.$span.'"></td>';
|
||||
print '<td nowrap align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
|
||||
print "</tr>\n";
|
||||
|
||||
print '</tr><tr><td colspan="4"> </td></tr>'."\n";
|
||||
print '<tr><td colspan="'.($span+1).'"> </td></tr>'."\n";
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
@ -1383,6 +1383,13 @@ class Facture extends CommonObject
|
||||
$remise = round(($pu * $remise_percent / 100),2);
|
||||
$price = ($pu - $remise);
|
||||
}
|
||||
$product_type=0;
|
||||
if ($fk_product)
|
||||
{
|
||||
$product=new Product($this->db);
|
||||
$result=$product->fetch($fk_product);
|
||||
$product_type=$product->type;
|
||||
}
|
||||
|
||||
// Insertion ligne
|
||||
$ligne=new FactureLigne($this->db);
|
||||
@ -1392,6 +1399,7 @@ class Facture extends CommonObject
|
||||
$ligne->qty=$qty;
|
||||
$ligne->tva_tx=$txtva;
|
||||
$ligne->fk_product=$fk_product;
|
||||
$ligne->product_type=$product_type;
|
||||
$ligne->remise_percent=$remise_percent;
|
||||
$ligne->subprice=$pu_ht;
|
||||
$ligne->date_start=$date_start;
|
||||
@ -2815,7 +2823,8 @@ class FactureLigne
|
||||
//! Description ligne
|
||||
var $desc;
|
||||
var $fk_product; // Id produit prédéfini
|
||||
|
||||
var $product_type = 0; // Type 0 = product, 1 = Service
|
||||
|
||||
var $qty; // Quantité (exemple 2)
|
||||
var $tva_tx; // Taux tva produit/service (exemple 19.6)
|
||||
var $subprice; // P.U. HT (exemple 100)
|
||||
@ -2864,7 +2873,7 @@ class FactureLigne
|
||||
*/
|
||||
function fetch($rowid)
|
||||
{
|
||||
$sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_product, fd.description, fd.price, fd.qty, fd.tva_taux,';
|
||||
$sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_product, fd.product_type, fd.description, fd.price, fd.qty, fd.tva_taux,';
|
||||
$sql.= ' fd.remise, fd.remise_percent, fd.fk_remise_except, fd.subprice,';
|
||||
$sql.= ' '.$this->db->pdate('fd.date_start').' as date_start,'.$this->db->pdate('fd.date_end').' as date_end,';
|
||||
$sql.= ' fd.info_bits, fd.total_ht, fd.total_tva, fd.total_ttc, fd.rang,';
|
||||
@ -2887,6 +2896,7 @@ class FactureLigne
|
||||
$this->fk_remise_except = $objp->fk_remise_except;
|
||||
$this->produit_id = $objp->fk_product; // Ne plus utiliser
|
||||
$this->fk_product = $objp->fk_product;
|
||||
$this->produc_type = $objp->product_type;
|
||||
$this->date_start = $objp->date_start;
|
||||
$this->date_end = $objp->date_end;
|
||||
$this->info_bits = $objp->info_bits;
|
||||
@ -2956,7 +2966,7 @@ class FactureLigne
|
||||
// Insertion dans base de la ligne
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet';
|
||||
$sql.= ' (fk_facture, description, qty, tva_taux,';
|
||||
$sql.= ' fk_product, remise_percent, subprice, price, remise, fk_remise_except,';
|
||||
$sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,';
|
||||
$sql.= ' date_start, date_end, fk_code_ventilation, fk_export_compta, ';
|
||||
$sql.= ' rang,';
|
||||
$sql.= ' info_bits, total_ht, total_tva, total_ttc)';
|
||||
@ -2966,6 +2976,7 @@ class FactureLigne
|
||||
$sql.= " ".price2num($this->tva_tx).",";
|
||||
if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; }
|
||||
else { $sql.='null,'; }
|
||||
$sql.= " ".$this->product_type.",";
|
||||
$sql.= " ".price2num($this->remise_percent).",";
|
||||
$sql.= " ".price2num($this->subprice).",";
|
||||
$sql.= " ".price2num($this->price).",";
|
||||
|
||||
@ -214,7 +214,7 @@ class FactureFournisseur extends Facture
|
||||
* Lignes
|
||||
*/
|
||||
$sql = 'SELECT f.rowid, f.description, f.pu_ht, f.pu_ttc, f.qty, f.tva_taux, f.tva';
|
||||
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product';
|
||||
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type';
|
||||
$sql.= ', p.ref, p.label as label, p.description as product_desc';
|
||||
//$sql.= ', pf.ref_fourn';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
|
||||
@ -248,6 +248,7 @@ class FactureFournisseur extends Facture
|
||||
$this->lignes[$i]->total_tva = $obj->total_tva;
|
||||
$this->lignes[$i]->total_ttc = $obj->total_ttc;
|
||||
$this->lignes[$i]->fk_product = $obj->fk_product;
|
||||
$this->lignes[$i]->product_type = $obj->product_type;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
@ -388,7 +389,7 @@ class FactureFournisseur extends Facture
|
||||
// Nettoyage paramètres
|
||||
if ($txtva == '') $txtva=0;
|
||||
$txtva=price2num($txtva);
|
||||
|
||||
|
||||
|
||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)';
|
||||
$sql .= ' VALUES ('.$this->id.');';
|
||||
@ -453,7 +454,14 @@ class FactureFournisseur extends Facture
|
||||
$pu_ht = $tabprice[3];
|
||||
$pu_tva = $tabprice[4];
|
||||
$pu_ttc = $tabprice[5];
|
||||
|
||||
$product_type = 0;
|
||||
if ($idproduct)
|
||||
{
|
||||
$product=new Product($this->db);
|
||||
$result=$product->fetch($idproduct);
|
||||
$product_type=$product->type;
|
||||
}
|
||||
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture_fourn_det ';
|
||||
$sql.= 'SET ';
|
||||
$sql.= 'description =\''.addslashes($label).'\'';
|
||||
@ -466,6 +474,7 @@ class FactureFournisseur extends Facture
|
||||
$sql.= ', total_ttc='.price2num($total_ttc);
|
||||
if ($idproduct) $sql.= ', fk_product='.$idproduct;
|
||||
else $sql.= ', fk_product=null';
|
||||
$sql.= ', product_type='.$product_type;
|
||||
$sql.= ' WHERE rowid = '.$id;
|
||||
|
||||
dolibarr_syslog("Fournisseur.facture::updateline sql=".$sql);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
|
||||
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
|
||||
*
|
||||
@ -17,18 +17,17 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/** \defgroup tax Module taxes
|
||||
\brief Module pour inclure des fonctions de saisies des taxes et charges sociales
|
||||
\brief Module pour inclure des fonctions de saisies des taxes (tva) et charges sociales
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/includes/modules/modTax.class.php
|
||||
\ingroup comptabilite
|
||||
\ingroup tax
|
||||
\brief Fichier de description et activation du module Taxe
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
include_once(DOL_DOCUMENT_ROOT ."/includes/modules/DolibarrModules.class.php");
|
||||
@ -64,7 +63,7 @@ class modTax extends DolibarrModules
|
||||
$this->picto='bill';
|
||||
|
||||
// Config pages
|
||||
$this->config_page_url = array();
|
||||
$this->config_page_url = array("taxes.php");
|
||||
|
||||
// D<>pendances
|
||||
$this->depends = array();
|
||||
|
||||
@ -6,9 +6,8 @@ MenuFinancial=Financial
|
||||
OptionMode=Option for accountancy
|
||||
OptionModeTrue=Option Input-Ouput
|
||||
OptionModeVirtual=Option Credits-Debits
|
||||
OptionModeTrueDesc=In this context, the turnover is calculated over paid invoices. \nThe validity of the figures is assured only if the book-keeping is scrutinized through the input/output on the accounts via invoices.
|
||||
OptionModeTrueInfoModuleComptabilite=Remarks: In this accountancy module, Dolibarr use the passed date of invoices with state 'Validated' and not passed date of real individual payments.
|
||||
OptionModeVirtualDesc=In this context, the turnover is calculated over validated invoices. When these invoices are due, whether they have been paid or not, they are listed in the turnover output.
|
||||
OptionModeTrueDesc=In this context, the turnover is calculated over paiements (date of payments). \nThe validity of the figures is assured only if the book-keeping is scrutinized through the input/output on the accounts via invoices.
|
||||
OptionModeVirtualDesc=In this context, the turnover is calculated over invoices (date of validation). When these invoices are due, whether they have been paid or not, they are listed in the turnover output.
|
||||
VATReportDesc=This report sows VAT received and payed.
|
||||
FeatureIsSupportedInInOutModeOnly=Feature only available in CREDITS-DEBTS accountancy mode (See Accountancy module configuration)
|
||||
Param=Setup
|
||||
@ -83,8 +82,17 @@ AnnualSummaryInputOutputMode=Bilan des recettes et d
|
||||
AnnualByCompaniesDueDebtMode=Bilan des recettes et dépenses, détail par tiers, en mode <b>%sCréances-Dettes%s</b> dit <b>comptabilité d'engagement</b>.
|
||||
AnnualByCompaniesInputOutputMode=Bilan des recettes et dépenses, détail par tiers, en mode <b>%sRecettes-Dépenses%s</b> dit <b>comptabilité de caisse</b>.
|
||||
SeeReportInInputOutputMode=Voir le rapport <b>%sRecettes-Dépenses%s</b> dit <b>comptabilité de caisse</b> pour un calcul sur les paiements effectivement réalisés
|
||||
SeeReportInDueDebtMode=Voir le rapport <b>%sCréances-Dettes%s</b> dit <b>comptabilité d'engagement</b> pour un calcul sur les factures non encore payées
|
||||
SeeReportInDueDebtMode=Voir le rapport <b>%sCréances-Dettes%s</b> dit <b>comptabilité d'engagement</b> pour un calcul sur les factures émises
|
||||
RulesResultDue=- Amounts shown are with all taxes included<br>- It includes outstanding invoices, expenses and VAT whether they are paid or not. <br>- It is based on the validation date of invoices and VAT and on the due date for expenses.
|
||||
RulesResultInOut=- Amounts shown are with all taxes included<br>- It includes the real payments made on invoices, expenses and VAT. <br>- It is based on the payment dates of the invoices, expenses anf VAT.<br>
|
||||
RulesCADue=- It includes the clients' due invoices whether they are paid or not. <br>- It is based on the validation date of these invoices. <br>
|
||||
RulesCAIn=- It includes all the effective payments of invoices received from clients.<br>- It is based on the payment date of these invoices<br>
|
||||
VATReportByCustomersInInputOutputMode=Rapport par trimestre des TVA collectées et payés (TVA sur encaissement)
|
||||
VATReportByCustomersInDueDebtMode=Rapport par trimestre des TVA collectées et payés (TVA sur débit)
|
||||
VATReportByQuarterInInputOutputMode=Rapport par client des TVA collectées et payés (TVA sur encaissement)
|
||||
VATReportByQuarterInDueDebtMode=Rapport par client des TVA collectées et payés (TVA sur débit)
|
||||
SeeVATReportInInputOutputMode=Voir le rapport <b>%sRecettes-Dépenses%s</b> dit <b>TVA encaissement</b> pour un calcul sur les paiements effectivement réalisés
|
||||
SeeVATReportInDueDebtMode=Voir le rapport <b>%sCréances-Dettes%s</b> dit <b>TVA sur débit</b> pour un calcul sur les factures émises
|
||||
RulesVATIn=- Il inclut les TVA sur la base des réglements effectivement reçus ou émis.<br>- Il se base sur la date du réglement.
|
||||
RulesVATDue=- Il inclut les TVA sur la base des factures clients dues, qu'elles soient payées ou non.<br>- Il se base sur la date de validation de ces factures.
|
||||
AmountHTVATQualified=HT VAT qualified
|
||||
@ -861,3 +861,10 @@ DeleteMenu=Effacer entr
|
||||
ConfirmDeleteMenu=Etes-vous sur de vouloir supprimer l'entrée de menu <b>%s</b> ?
|
||||
DeleteLine=Suppression de ligne
|
||||
ConfirmDeleteLine=Êtes-vous sûr de vouloir effacer cette ligne ?
|
||||
##### Tax #####
|
||||
TaxSetup=Configuration du module Taxes, charges sociales et dividendes
|
||||
OptionVatMode=Option d'exigibilité de TVA
|
||||
OptionVATDefault=Standard
|
||||
OptionVATDebitOption=Option services sur debit
|
||||
OptionVatDefaultDesc=L'exigibilité de la TVA est:<br>- sur livraison pour les biens<br>- sur paiement pour les services
|
||||
OptionVatDebitOptionDesc=L'exigibilité de la TVA est:<br>- sur livraison pour les biens<br>- sur facturation (débit) pour les services
|
||||
|
||||
@ -6,10 +6,8 @@ MenuFinancial=Compta/Tr
|
||||
OptionMode=Option de tenue de comptabilité
|
||||
OptionModeTrue=Option Recettes-Dépenses
|
||||
OptionModeVirtual=Option Créances-Dettes
|
||||
OptionModeTrueDesc=Dans ce mode, le CA est calculé sur la base des factures payées.\nLa validité des chiffres n'est donc assurée que si la tenue de la comptabilité passe rigoureusement par des entrées/sorties sur les comptes via des factures.
|
||||
OptionModeTrueInfoModuleComptabilite=Remarque : Dans le module comptabilite actif, Dolibarr utilise la date de passage de la facture à l'état 'Validée' et non la date des paiements individuels.
|
||||
OptionModeVirtualDesc=Dans ce mode, le CA est calculé sur la base des factures validées. Payées ou non, elles apparaissent dans le résultat dès qu'elles sont dues.
|
||||
VATReportDesc=Cet écran présente le rapport des TVA collectées et payés.
|
||||
OptionModeTrueDesc=Dans ce mode, le CA est calculé sur la base des paiements (date de réglement).\nLa validité des chiffres n'est donc assurée que si la tenue de la comptabilité passe rigoureusement par des entrées/sorties sur les comptes via des factures.
|
||||
OptionModeVirtualDesc=Dans ce mode, le CA est est calculé sur la base des factures (date de validation). Payées ou non, elles apparaissent dans le résultat dès qu'elles sont dues.
|
||||
FeatureIsSupportedInInOutModeOnly=Fonction disponible uniquement en mode compta CREANCES-DETTES (Voir configuration du module compta)
|
||||
Param=Paramétrage
|
||||
AccountsGeneral=Comptes généraux
|
||||
@ -83,8 +81,19 @@ AnnualSummaryInputOutputMode=Bilan des recettes et d
|
||||
AnnualByCompaniesDueDebtMode=Bilan des recettes et dépenses, détail par tiers, en mode <b>%sCréances-Dettes%s</b> dit <b>comptabilité d'engagement</b>.
|
||||
AnnualByCompaniesInputOutputMode=Bilan des recettes et dépenses, détail par tiers, en mode <b>%sRecettes-Dépenses%s</b> dit <b>comptabilité de caisse</b>.
|
||||
SeeReportInInputOutputMode=Voir le rapport <b>%sRecettes-Dépenses%s</b> dit <b>comptabilité de caisse</b> pour un calcul sur les paiements effectivement réalisés
|
||||
SeeReportInDueDebtMode=Voir le rapport <b>%sCréances-Dettes%s</b> dit <b>comptabilité d'engagement</b> pour un calcul sur les factures non encore payées
|
||||
SeeReportInDueDebtMode=Voir le rapport <b>%sCréances-Dettes%s</b> dit <b>comptabilité d'engagement</b> pour un calcul sur les factures émises
|
||||
RulesResultDue=- Les montants affichés sont les montants TTC<br>- Il inclut les factures, charges et tva dues, qu'elles soient payées ou non.<br>- Il se base sur la date de validation pour les factures et la tva et sur la date d'échéance pour les charges.<br>
|
||||
RulesResultInOut=- Les montants affichés sont les montants TTC<br>- Il inclut les réglements effectivement réalisés pour les factures, les charges et la TVA.<br>- Il se base sur la date de réglement de ces factures, charges et TVA.<br>
|
||||
RulesCADue=- Il inclut les factures clients dues, qu'elles soient payées ou non.<br>- Il se base sur la date de validation de ces factures.<br>
|
||||
RulesCAIn=- Il inclut les réglements effectivement reçus des factures clients.<br>- Il se base sur la date de réglement de ces factures<br>
|
||||
VATReportByCustomersInInputOutputMode=Rapport par client des TVA collectées et payés (TVA sur encaissement)
|
||||
VATReportByCustomersInDueDebtMode=Rapport par client des TVA collectées et payés (TVA sur débit)
|
||||
VATReportByQuartersInInputOutputMode=Rapport par trimestre des TVA collectées et payés (TVA sur encaissement)
|
||||
VATReportByQuartersInDueDebtMode=Rapport par trimestre des TVA collectées et payés (TVA sur débit)
|
||||
SeeVATReportInInputOutputMode=Voir le rapport <b>%sTVA encaissement%s</b> pour mode de calcul standard
|
||||
SeeVATReportInDueDebtMode=Voir le rapport <b>%sTVA sur débit%s</b> pour mode de calcul avec option sur les débits
|
||||
RulesVATIn=- Pour les services, il inclut les TVA des réglements effectivement reçus ou émis en se basant sur la date du réglement.<br>- Pour les biens matériels, il inclut les TVA des factures en se basant sur la date de validation de la facture.
|
||||
RulesVATDue=- Pour les services, il inclut les TVA des factures dues, payées ou non en se basant sur la date de validation de ces factures.<br>- Pour les biens matériels, il inclut les TVA des factures en se basant sur la date de validation de la facture.
|
||||
OptionVatInfoModuleComptabilite=Remarque : Pour les biens matériels, il faudrait utiliser la date de livraison pour être plus juste.
|
||||
AmountHTVATRealReceived=HT collectée
|
||||
AmountHTVATRealPayed=HT payé
|
||||
480
htdocs/lib/tax.lib.php
Normal file
480
htdocs/lib/tax.lib.php
Normal file
@ -0,0 +1,480 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006-2007 Yannick Warnier <ywarnier@beeznest.org>
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/lib/tax.lib.php
|
||||
\ingroup tax
|
||||
\brief Library for tax module
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* \brief Look for collectable VAT clients in the chosen year
|
||||
* \param db Database handle
|
||||
* \param y Year
|
||||
* \param modetax 0 or 1 (option vat on debit)
|
||||
* \return array List of customers third parties with vat
|
||||
*/
|
||||
function vat_received_by_customer($db, $y, $modetax)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Define sql request
|
||||
$sql='';
|
||||
if ($modetax == 1)
|
||||
{
|
||||
// If vat payed on due invoices (non draft)
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
$sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.total_tva) as tva,";
|
||||
$sql.= " s.tva_assuj as assuj, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely)
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture";
|
||||
$sql.= " GROUP BY s.rowid";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// If vat payed on payments
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
// Tva sur factures payés (should be on payment)
|
||||
/* $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.total_tva) as tva,";
|
||||
$sql.= " s.tva_assuj as assuj, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (2)"; // Payed (partially or completely)
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture";
|
||||
$sql.= " GROUP BY s.rowid";
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
if ($sql)
|
||||
{
|
||||
dolibarr_syslog("Client::tva_coll sql=".$sql);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$list = array();
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
$list[] = $assoc;
|
||||
}
|
||||
$db->free();
|
||||
return $list;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Get payable VAT
|
||||
* \param resource Database handle
|
||||
* \param y Year
|
||||
* \param modetax 0 or 1 (option vat on debit)
|
||||
* \return array List of suppliers third parties with vat
|
||||
*/
|
||||
function vat_payed_by_supplier($db, $y, $modetax)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Define sql request
|
||||
$sql='';
|
||||
if ($modetax == 1)
|
||||
{
|
||||
// If vat payed on due invoices (non draft)
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
$sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.tva) as tva,";
|
||||
$sql.= " s.tva_assuj as assuj, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."facture_fourn_det as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely)
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture_fourn";
|
||||
$sql.= " GROUP BY s.rowid";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si on paye la tva sur les payments
|
||||
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
// Tva sur factures payés
|
||||
/* $sql = "SELECT s.nom as nom, s.tva_intra as tva_intra,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(fd.tva) as tva,";
|
||||
$sql.= " s.tva_assuj as assuj, s.rowid as socid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."facture_fourn_det as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
//$sql.= " f.fk_statut in (2)"; // Payed (partially or completely)
|
||||
$sql.= " f.paye in (1)"; // Payed (completely)
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.fk_facture_fourn";
|
||||
$sql.= " GROUP BY s.rowid";
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
if ($sql)
|
||||
{
|
||||
dolibarr_syslog("Client::tva_paye sql=".$sql);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$list = array();
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
$list[] = $assoc;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Gets VAT to collect for the given month of the given year
|
||||
* 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 db Database handler object
|
||||
* \param y Year
|
||||
* \param q Year quarter (1-4)
|
||||
* \param modetax 0 or 1 (option vat on debit)
|
||||
* \param direction 'sell' or 'buy'
|
||||
* \return array List of quarters with vat
|
||||
*/
|
||||
function vat_by_quarter($db, $y, $q, $modetax, $direction)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$list=array();
|
||||
|
||||
if ($direction == 'sell')
|
||||
{
|
||||
$invoicetable='facture';
|
||||
$invoicedettable='facturedet';
|
||||
$fk_facture='fk_facture';
|
||||
$total_tva='total_tva';
|
||||
}
|
||||
if ($direction == 'buy')
|
||||
{
|
||||
$invoicetable='facture_fourn';
|
||||
$invoicedettable='facture_fourn_det';
|
||||
$fk_facture='fk_facture_fourn';
|
||||
$total_tva='tva';
|
||||
}
|
||||
|
||||
// CAS DES BIENS
|
||||
|
||||
// Define sql request
|
||||
$sql='';
|
||||
if ($modetax == 1)
|
||||
{
|
||||
// If vat payed on due invoices (non draft)
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
|
||||
$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely)
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
|
||||
$sql.= " AND d.product_type = 0"; // Limit to products
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If vat payed on payments
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
// Tva sur factures payés (should be on payment)
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
|
||||
$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely)
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
|
||||
$sql.= " AND d.product_type = 0"; // Limit to products
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
|
||||
}
|
||||
}
|
||||
|
||||
if ($sql)
|
||||
{
|
||||
dolibarr_syslog("Client::vat_by_quarter sql=".$sql);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$rate = -1;
|
||||
$oldrowid='';
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['total_ht']=0;
|
||||
if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['total_vat']=0;
|
||||
|
||||
if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid
|
||||
{
|
||||
$oldrowid=$assoc['rowid'];
|
||||
$list[$assoc['rate']]['totalht'] += $assoc['total_ht'];
|
||||
$list[$assoc['rate']]['vat'] += $assoc['total_vat'];
|
||||
}
|
||||
$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
|
||||
$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
|
||||
|
||||
$list[$assoc['rate']]['facid'][] = $assoc['facid'];
|
||||
$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
|
||||
$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
|
||||
$list[$assoc['rate']]['descr'][] = $assoc['descr'];
|
||||
|
||||
$list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
|
||||
$list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
|
||||
|
||||
$list[$assoc['rate']]['pid'][] = $assoc['pid'];
|
||||
$list[$assoc['rate']]['pref'][] = $assoc['pref'];
|
||||
$list[$assoc['rate']]['ptype'][] = $assoc['ptype'];
|
||||
|
||||
$list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
|
||||
$list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
|
||||
|
||||
$rate = $assoc['rate'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// CAS DES SERVICES
|
||||
|
||||
// Define sql request
|
||||
$sql='';
|
||||
if ($modetax == 1) // Option vat on debit
|
||||
{
|
||||
// If vat payed on due invoices (non draft)
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
|
||||
$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Validated or payed (partially or completely)
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;
|
||||
$sql.= " AND f.datef >= '".$y."0101000000' AND f.datef <= '".$y."1231235959'";
|
||||
$sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
|
||||
$sql.= " AND d.product_type = 1"; // Limit to services
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If vat payed on payments
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITEEXPERT)
|
||||
{
|
||||
// \todo a ce jour on se sait pas la compter car le montant tva d'un payment
|
||||
// n'est pas stocké dans la table des payments.
|
||||
// Seul le module compta expert peut résoudre ce problème.
|
||||
// (Il faut quand un payment a lieu, stocker en plus du montant du paiement le
|
||||
// detail part tva et part ht).
|
||||
}
|
||||
if ($conf->global->MAIN_MODULE_COMPTABILITE)
|
||||
{
|
||||
// Tva sur factures payés (should be on payment)
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.tva_taux as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
|
||||
$sql.= " f.facnumber as facnum, f.total_ttc as ftotal_ttc,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
|
||||
$sql.= " pf.fk_paiement as payment_id, pf.amount as payment_amount";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."paiement_facture as pf,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."paiement as pa,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (1,2)"; // Payed (partially or completely)
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;;
|
||||
$sql.= " AND pf.fk_facture = f.rowid";
|
||||
$sql.= " AND pa.rowid = pa.fk_paiement";
|
||||
$sql.= " AND pa.datep >= '".$y."0101000000' AND pa.datep <= '".$y."1231235959'";
|
||||
$sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
|
||||
$sql.= " AND d.product_type = 1"; // Limit to services
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
|
||||
}
|
||||
}
|
||||
|
||||
if ($sql)
|
||||
{
|
||||
dolibarr_syslog("Client::vat_by_quarter sql=".$sql);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$rate = -1;
|
||||
$oldrowid='';
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['total_ht']=0;
|
||||
if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['total_vat']=0;
|
||||
|
||||
if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid
|
||||
{
|
||||
$oldrowid=$assoc['rowid'];
|
||||
$list[$assoc['rate']]['totalht'] += $assoc['total_ht'];
|
||||
$list[$assoc['rate']]['vat'] += $assoc['total_vat'];
|
||||
}
|
||||
$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
|
||||
$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
|
||||
|
||||
$list[$assoc['rate']]['facid'][] = $assoc['facid'];
|
||||
$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
|
||||
$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
|
||||
$list[$assoc['rate']]['descr'][] = $assoc['descr'];
|
||||
|
||||
$list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
|
||||
$list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
|
||||
|
||||
$list[$assoc['rate']]['pid'][] = $assoc['pid'];
|
||||
$list[$assoc['rate']]['pref'][] = $assoc['pref'];
|
||||
$list[$assoc['rate']]['ptype'][] = $assoc['ptype'];
|
||||
|
||||
$list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
|
||||
$list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
|
||||
|
||||
$rate = $assoc['rate'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($db);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user