diff --git a/htdocs/compta/localtax/index.php b/htdocs/compta/localtax/index.php
index 2364290403b..36e6abf5fb7 100644
--- a/htdocs/compta/localtax/index.php
+++ b/htdocs/compta/localtax/index.php
@@ -45,13 +45,12 @@ if (empty($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");
+ $q=GETPOST("q","int");
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); }
+ if (GETPOST("month","int")) { $date_start=dol_get_first_day($year_start,GETPOST("month","int"),false); $date_end=dol_get_last_day($year_start,GETPOST("month","int"),false); }
else
{
$date_start=dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,false);
@@ -150,11 +149,12 @@ if($localTaxType==1) {
$CalcLT= $conf->global->MAIN_INFO_LOCALTAX_CALC2;
}
-$description = '';
+$fsearch.=' ';
+$description = $fsearch;
// Show report header
$name = $langs->trans("ReportByMonth");
-$description = $langs->trans($LT);
+$description .= $langs->trans($LT);
$calcmode = $langs->trans("LTReportBuildWithOptionDefinedInModule").' ';
$calcmode.= '('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')
';
@@ -174,6 +174,7 @@ llxHeader('', $name);
report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
//report_header($name,'',$textprevyear.$langs->trans("Year")." ".$year_start.$textnextyear,'',$description,$builddate,$exportlink,array(),$calcmode);
+
print '
';
print '
';
@@ -208,16 +209,141 @@ $total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
$i=0; $mcursor=0;
while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop
{
- $m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
+ //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
if ($m == 13) $y++;
if ($m > 12) $m -= 12;
$mcursor++;
- $coll_listsell = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
- $coll_listbuy = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
+ // Get array with details of each line
+ $x_coll = tax_by_rate(($localTaxType==1?'localtax1':'localtax2'), $db, $y, 0, 0, 0, $modetax, 'sell', $m);
+ $x_paye = tax_by_rate(($localTaxType==1?'localtax1':'localtax2'), $db, $y, 0, 0, 0, $modetax, 'buy', $m);
+
+ $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)
+ {
+ $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']['localtax1'] = $x_coll[$my_coll_rate]['localtax1'];
+ $x_both[$my_coll_rate]['coll']['localtax2'] = $x_coll[$my_coll_rate]['localtax2'];
+ $x_both[$my_coll_rate]['paye']['totalht'] = 0;
+ $x_both[$my_coll_rate]['paye']['vat'] = 0;
+ $x_both[$my_coll_rate]['paye']['localtax1'] = 0;
+ $x_both[$my_coll_rate]['paye']['localtax2'] = 0;
+ $x_both[$my_coll_rate]['coll']['links'] = '';
+ $x_both[$my_coll_rate]['coll']['detail'] = array();
+ foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) {
+ //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
+ //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
+ //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
+ //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$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],
+ '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],
+ 'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
+ 'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
+ //'company_link'=>$company_static->getNomUrl(1,'',20),
+ 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
+ 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
+
+ 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
+ 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
+ 'localtax1' =>$x_coll[$my_coll_rate]['localtax1_list'][$id],
+ 'localtax2' =>$x_coll[$my_coll_rate]['localtax2_list'][$id],
+ //'link' =>$invoice_customer->getNomUrl(1,'',12)
+ );
+ }
+ }
+
+ // tva paid
+ foreach (array_keys($x_paye) as $my_paye_rate) {
+ $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
+ $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
+ $x_both[$my_paye_rate]['paye']['localtax1'] = $x_paye[$my_paye_rate]['localtax1'];
+ $x_both[$my_paye_rate]['paye']['localtax2'] = $x_paye[$my_paye_rate]['localtax2'];
+ if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
+ $x_both[$my_paye_rate]['coll']['totalht'] = 0;
+ $x_both[$my_paye_rate]['coll']['vat'] = 0;
+ $x_both[$my_paye_rate]['coll']['localtax1'] = 0;
+ $x_both[$my_paye_rate]['coll']['localtax2'] = 0;
+ }
+ $x_both[$my_paye_rate]['paye']['links'] = '';
+ $x_both[$my_paye_rate]['paye']['detail'] = array();
+
+ foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
+ {
+ // ExpenseReport
+ if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment')
+ {
+ //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
+ //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
+ //$expensereport->type=$x_paye[$my_paye_rate]['type'][$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_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' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
+ 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
+ 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
+ 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
+ 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
+
+ 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
+ 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
+ 'localtax1' =>$x_paye[$my_paye_rate]['localtax1_list'][$id],
+ 'localtax2' =>$x_paye[$my_paye_rate]['localtax2_list'][$id],
+ //'link' =>$expensereport->getNomUrl(1)
+ );
+ }
+ else
+ {
+ //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
+ //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
+ //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
+ //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$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_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'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
+ 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
+ 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
+ 'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
+ 'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
+ //'company_link'=>$company_static->getNomUrl(1,'',20),
+ 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
+ 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
+
+ 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
+ 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
+ 'localtax1' =>$x_paye[$my_paye_rate]['localtax1_list'][$id],
+ 'localtax2' =>$x_paye[$my_paye_rate]['localtax2_list'][$id],
+ //'link' =>$invoice_supplier->getNomUrl(1,'',12)
+ );
+ }
+ }
+ }
+ //now we have an array (x_both) indexed by rates for coll and paye
$action = "tva";
- $object = array(&$coll_listsell, &$coll_listbuy);
+ $object = array(&$x_coll, &$x_paye, &$x_both);
$parameters["mode"] = $modetax;
$parameters["year"] = $y;
$parameters["month"] = $m;
@@ -227,13 +353,13 @@ while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcu
$hookmanager->initHooks(array('externalbalance'));
$reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
- if (! is_array($coll_listbuy) && $coll_listbuy == -1)
+ if (! is_array($x_coll) && $coll_listbuy == -1)
{
$langs->load("errors");
print '
| '.$langs->trans("ErrorNoAccountancyModuleLoaded").' |
';
break;
}
- if (! is_array($coll_listbuy) && $coll_listbuy == -2)
+ if (! is_array($x_paye) && $coll_listbuy == -2)
{
print '
| '.$langs->trans("FeatureNotYetAvailable").' |
';
break;
@@ -241,76 +367,121 @@ while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcu
print '
';
- print '| '.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").' | ';
+ print ''.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").' | ';
- if ($CalcLT==0) {
- $x_coll = 0;
- foreach($coll_listsell as $vatrate=>$val) {
- $x_coll+=$val[$localTaxType==1?'localtax1':'localtax2'];
- }
- $subtotalcoll = $subtotalcoll + $x_coll;
- print "".price($x_coll)." | ";
+ $x_coll_sum = 0;
+ foreach (array_keys($x_coll) as $rate)
+ {
+ $subtot_coll_total_ht = 0;
+ $subtot_coll_vat = 0;
- $x_paye = 0;
- foreach($coll_listbuy as $vatrate=>$val) {
- $x_paye+=$val[$localTaxType==1?'localtax1':'localtax2'];
- }
- $subtotalpaye = $subtotalpaye + $x_paye;
- print "".price($x_paye)." | ";
- } elseif($CalcLT==1) {
- $x_paye = 0;
- foreach($coll_listbuy as $vatrate=>$val) {
- $x_paye+=$val[$localTaxType==1?'localtax1':'localtax2'];
+ foreach ($x_both[$rate]['coll']['detail'] as $index => $fields)
+ {
+ // Payment
+ $ratiopaymentinvoice=1;
+ if ($modetax != 1)
+ {
+ // Define type
+ // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
+ $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']);
+ // Try to enhance type detection using date_start and date_end for free lines where type
+ // was not saved.
+ if (!empty($fields['ddate_start'])) {
+ $type=1;
+ }
+ if (!empty($fields['ddate_end'])) {
+ $type=1;
+ }
+
+ if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
+ || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
+ {
+ //print $langs->trans("NA");
+ } else {
+ if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
+ $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
+ }
+ }
+ }
+ //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
+ $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
+ $temp_vat=$fields['localtax'.$localTaxType]*$ratiopaymentinvoice;
+ $subtot_coll_total_ht += $temp_ht;
+ $subtot_coll_vat += $temp_vat;
+ $x_coll_sum += $temp_vat;
}
- $subtotalpaye = $subtotalpaye + $x_paye;
- print "".price($x_paye)." | | ";
- } elseif($CalcLT==2) {
- $x_coll = 0;
- foreach($coll_listsell as $vatrate=>$val) {
- $x_coll+=$val[$localTaxType==1?'localtax1':'localtax2'];
+ }
+ print "".price(price2num($x_coll_sum,'MT'))." | ";
+
+ $x_paye_sum = 0;
+ foreach (array_keys($x_paye) as $rate)
+ {
+ $subtot_paye_total_ht = 0;
+ $subtot_paye_vat = 0;
+
+ foreach ($x_both[$rate]['paye']['detail'] as $index => $fields)
+ {
+ // Payment
+ $ratiopaymentinvoice=1;
+ if ($modetax != 1)
+ {
+ // Define type
+ // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
+ $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']);
+ // Try to enhance type detection using date_start and date_end for free lines where type
+ // was not saved.
+ if (!empty($fields['ddate_start'])) {
+ $type=1;
+ }
+ if (!empty($fields['ddate_end'])) {
+ $type=1;
+ }
+
+ if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
+ || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
+ {
+ //print $langs->trans("NA");
+ } else {
+ if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
+ $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
+ }
+ }
+ }
+ //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
+ $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
+ $temp_vat=$fields['localtax'.$localTaxType]*$ratiopaymentinvoice;
+ $subtot_paye_total_ht += $temp_ht;
+ $subtot_paye_vat += $temp_vat;
+ $x_paye_sum += $temp_vat;
}
- $subtotalcoll = $subtotalcoll + $x_coll;
- print "".price($x_coll)." | | ";
-
}
+ print "".price(price2num($x_paye_sum,'MT'))." | ";
- if($CalcLT==0) {
- $diff= $x_coll - $x_paye;
- } elseif($CalcLT==1) {
- $diff= $x_paye;
- } elseif($CalcLT==2) {
- $diff= $x_coll;
- }
+ $subtotalcoll = $subtotalcoll + $x_coll_sum;
+ $subtotalpaye = $subtotalpaye + $x_paye_sum;
+ $diff = $x_coll_sum - $x_paye_sum;
$total = $total + $diff;
- $subtotal = $subtotal + $diff;
+ $subtotal = price2num($subtotal + $diff, 'MT');
- print "".price($diff)." | \n";
+ print "".price(price2num($diff,'MT'))." | \n";
print " | \n";
print "
\n";
- $i++;
+ $i++; $m++;
if ($i > 2)
{
- print '
';
- print '| '.$langs->trans("SubTotal").': | ';
- if($CalcLT==0) {
- print ''.price($subtotalcoll).' | ';
- print ''.price($subtotalpaye).' | ';
- print ''.price($subtotal).' | ';
- } elseif($CalcLT==1) {
- print ''.price($subtotalpaye).' | | ';
- print ''.price($subtotal).' | ';
- } elseif($CalcLT==2) {
- print ''.price($subtotalcoll).' | | ';
- print ''.price($subtotal).' | ';
- }
- print ' |
';
- $i = 0;
- $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
+ print '
';
+ print '| '.$langs->trans("SubTotal").': | ';
+ print ''.price(price2num($subtotalcoll,'MT')).' | ';
+ print ''.price(price2num($subtotalpaye,'MT')).' | ';
+ print ''.price(price2num($subtotal,'MT')).' | ';
+ print ' |
';
+ $i = 0;
+ $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
}
}
-print '
| '.$langs->trans("TotalToPay").': | '.price($total).' | ';
+print '
| '.$langs->trans("TotalToPay").': | '.price(price2num($total, 'MT')).' | ';
print " | \n";
print '
';
@@ -319,12 +490,14 @@ print '';
print '
';
-print load_fiche_titre($langs->transcountry($LTPaid,$mysoc->country_code), '', '');
+
/*
* Payed
*/
+print load_fiche_titre($langs->transcountry($LTPaid,$mysoc->country_code), '', '');
+
$sql = "SELECT SUM(amount) as mm, date_format(f.datev,'%Y-%m') as dm";
$sql.= " FROM ".MAIN_DB_PREFIX."localtax as f";
$sql.= " WHERE f.entity = ".$conf->entity;
@@ -336,10 +509,10 @@ $sql.= " ORDER BY dm ASC";
pt($db, $sql,$langs->trans("Year")." $y");
+
print '
';
print '
';
-
llxFooter();
$db->close();
diff --git a/htdocs/compta/tva/index.php b/htdocs/compta/tva/index.php
index d22d252f39c..c1a61fea540 100644
--- a/htdocs/compta/tva/index.php
+++ b/htdocs/compta/tva/index.php
@@ -45,13 +45,12 @@ if (empty($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");
+ $q=GETPOST("q","int");
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); }
+ if (GETPOST("month","int")) { $date_start=dol_get_first_day($year_start,GETPOST("month","int"),false); $date_end=dol_get_last_day($year_start,GETPOST("month","int"),false); }
else
{
$date_start=dol_get_first_day($year_start, $conf->global->SOCIETE_FISCAL_MONTH_START,false);
@@ -190,21 +189,128 @@ $m = $tmp['mon'];
$tmp=dol_getdate($date_end);
$yend = $tmp['year'];
$mend = $tmp['mon'];
-
+//var_dump($m);
$total=0; $subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
$i=0; $mcursor=0;
while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcursor is to avoid too large loop
{
- $m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
+ //$m = $conf->global->SOCIETE_FISCAL_MONTH_START + ($mcursor % 12);
if ($m == 13) $y++;
if ($m > 12) $m -= 12;
$mcursor++;
- $coll_listsell = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
- $coll_listbuy = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
+ $x_coll = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
+ $x_paye = tax_by_rate('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
+
+ $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)
+ {
+ $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]['paye']['totalht'] = 0;
+ $x_both[$my_coll_rate]['paye']['vat'] = 0;
+ $x_both[$my_coll_rate]['coll']['links'] = '';
+ $x_both[$my_coll_rate]['coll']['detail'] = array();
+ foreach($x_coll[$my_coll_rate]['facid'] as $id=>$dummy) {
+ //$invoice_customer->id=$x_coll[$my_coll_rate]['facid'][$id];
+ //$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
+ //$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
+ //$company_static->fetch($x_coll[$my_coll_rate]['company_id'][$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],
+ '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],
+ 'datef' =>$x_coll[$my_coll_rate]['datef'][$id],
+ 'datep' =>$x_coll[$my_coll_rate]['datep'][$id],
+ //'company_link'=>$company_static->getNomUrl(1,'',20),
+ 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
+ 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
+ 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
+ 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
+ //'link' =>$invoice_customer->getNomUrl(1,'',12)
+ );
+ }
+ }
+
+ // tva paid
+ foreach (array_keys($x_paye) as $my_paye_rate) {
+ $x_both[$my_paye_rate]['paye']['totalht'] = $x_paye[$my_paye_rate]['totalht'];
+ $x_both[$my_paye_rate]['paye']['vat'] = $x_paye[$my_paye_rate]['vat'];
+ if (!isset($x_both[$my_paye_rate]['coll']['totalht'])) {
+ $x_both[$my_paye_rate]['coll']['totalht'] = 0;
+ $x_both[$my_paye_rate]['coll']['vat'] = 0;
+ }
+ $x_both[$my_paye_rate]['paye']['links'] = '';
+ $x_both[$my_paye_rate]['paye']['detail'] = array();
+
+ foreach ($x_paye[$my_paye_rate]['facid'] as $id=>$dummy)
+ {
+ // ExpenseReport
+ if ($x_paye[$my_paye_rate]['ptype'][$id] == 'ExpenseReportPayment')
+ {
+ //$expensereport->id=$x_paye[$my_paye_rate]['facid'][$id];
+ //$expensereport->ref=$x_paye[$my_paye_rate]['facnum'][$id];
+ //$expensereport->type=$x_paye[$my_paye_rate]['type'][$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_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' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
+ 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
+ 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
+ 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
+ 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
+ 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
+ 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
+ //'link' =>$expensereport->getNomUrl(1)
+ );
+ }
+ else
+ {
+ //$invoice_supplier->id=$x_paye[$my_paye_rate]['facid'][$id];
+ //$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
+ //$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
+ //$company_static->fetch($x_paye[$my_paye_rate]['company_id'][$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_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'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
+ 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
+ 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
+ 'datef' =>$x_paye[$my_paye_rate]['datef'][$id],
+ 'datep' =>$x_paye[$my_paye_rate]['datep'][$id],
+ //'company_link'=>$company_static->getNomUrl(1,'',20),
+ 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
+ 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
+ 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
+ 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
+ //'link' =>$invoice_supplier->getNomUrl(1,'',12)
+ );
+ }
+ }
+ }
+ //now we have an array (x_both) indexed by rates for coll and paye
$action = "tva";
- $object = array(&$coll_listsell, &$coll_listbuy);
+ $object = array(&$x_coll, &$x_paye, &$x_both);
$parameters["mode"] = $modetax;
$parameters["year"] = $y;
$parameters["month"] = $m;
@@ -214,13 +320,13 @@ while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcu
$hookmanager->initHooks(array('externalbalance'));
$reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
- if (! is_array($coll_listbuy) && $coll_listbuy == -1)
+ if (! is_array($x_coll) && $coll_listbuy == -1)
{
$langs->load("errors");
print '
| '.$langs->trans("ErrorNoAccountancyModuleLoaded").' |
';
break;
}
- if (! is_array($coll_listbuy) && $coll_listbuy == -2)
+ if (! is_array($x_paye) && $coll_listbuy == -2)
{
print '
| '.$langs->trans("FeatureNotYetAvailable").' |
';
break;
@@ -228,46 +334,121 @@ while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcu
print '
';
- print '| '.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").' | ';
+ print ''.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").' | ';
- $x_coll = 0;
- foreach($coll_listsell as $vatrate=>$val)
+ $x_coll_sum = 0;
+ foreach (array_keys($x_coll) as $rate)
{
- $x_coll+=$val['vat'];
- }
- $subtotalcoll = $subtotalcoll + $x_coll;
- print "".price($x_coll)." | ";
+ $subtot_coll_total_ht = 0;
+ $subtot_coll_vat = 0;
- $x_paye = 0;
- foreach($coll_listbuy as $vatrate=>$val)
+ foreach ($x_both[$rate]['coll']['detail'] as $index => $fields)
+ {
+ // Payment
+ $ratiopaymentinvoice=1;
+ if ($modetax != 1)
+ {
+ // Define type
+ // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
+ $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']);
+ // Try to enhance type detection using date_start and date_end for free lines where type
+ // was not saved.
+ if (!empty($fields['ddate_start'])) {
+ $type=1;
+ }
+ if (!empty($fields['ddate_end'])) {
+ $type=1;
+ }
+
+ if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
+ || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
+ {
+ //print $langs->trans("NA");
+ } else {
+ if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
+ $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
+ }
+ }
+ }
+ //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
+ $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
+ $temp_vat=$fields['vat']*$ratiopaymentinvoice;
+ $subtot_coll_total_ht += $temp_ht;
+ $subtot_coll_vat += $temp_vat;
+ $x_coll_sum += $temp_vat;
+ }
+ }
+ print "".price(price2num($x_coll_sum,'MT'))." | ";
+
+ $x_paye_sum = 0;
+ foreach (array_keys($x_paye) as $rate)
{
- $x_paye+=$val['vat'];
- }
- $subtotalpaye = $subtotalpaye + $x_paye;
- print "".price($x_paye)." | ";
+ $subtot_paye_total_ht = 0;
+ $subtot_paye_vat = 0;
- $diff = $x_coll - $x_paye;
+ foreach ($x_both[$rate]['paye']['detail'] as $index => $fields)
+ {
+ // Payment
+ $ratiopaymentinvoice=1;
+ if ($modetax != 1)
+ {
+ // Define type
+ // We MUST use dtype (type in line). We can use something else, only if dtype is really unknown.
+ $type=(isset($fields['dtype'])?$fields['dtype']:$fields['ptype']);
+ // Try to enhance type detection using date_start and date_end for free lines where type
+ // was not saved.
+ if (!empty($fields['ddate_start'])) {
+ $type=1;
+ }
+ if (!empty($fields['ddate_end'])) {
+ $type=1;
+ }
+
+ if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
+ || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice'))
+ {
+ //print $langs->trans("NA");
+ } else {
+ if (isset($fields['payment_amount']) && price2num($fields['ftotal_ttc'])) {
+ $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
+ }
+ }
+ }
+ //var_dump('type='.$type.' '.$fields['totalht'].' '.$ratiopaymentinvoice);
+ $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
+ $temp_vat=$fields['vat']*$ratiopaymentinvoice;
+ $subtot_paye_total_ht += $temp_ht;
+ $subtot_paye_vat += $temp_vat;
+ $x_paye_sum += $temp_vat;
+ }
+ }
+ print "".price(price2num($x_paye_sum,'MT'))." | ";
+
+ $subtotalcoll = $subtotalcoll + $x_coll_sum;
+ $subtotalpaye = $subtotalpaye + $x_paye_sum;
+
+ $diff = $x_coll_sum - $x_paye_sum;
$total = $total + $diff;
- $subtotal = $subtotal + $diff;
+ $subtotal = price2num($subtotal + $diff, 'MT');
- print "".price($diff)." | \n";
+ print "".price(price2num($diff,'MT'))." | \n";
print " | \n";
print "
\n";
- $i++;
+ $i++; $m++;
if ($i > 2)
{
print '
';
print '| '.$langs->trans("SubTotal").': | ';
- print ''.price($subtotalcoll).' | ';
- print ''.price($subtotalpaye).' | ';
- print ''.price($subtotal).' | ';
+ print ''.price(price2num($subtotalcoll,'MT')).' | ';
+ print ''.price(price2num($subtotalpaye,'MT')).' | ';
+ print ''.price(price2num($subtotal,'MT')).' | ';
print ' |
';
$i = 0;
$subtotalcoll=0; $subtotalpaye=0; $subtotal=0;
}
}
-print '
| '.$langs->trans("TotalToPay").': | '.price($total).' | ';
+print '
| '.$langs->trans("TotalToPay").': | '.price(price2num($total, 'MT')).' | ';
print " | \n";
print '
';
@@ -277,12 +458,13 @@ print '';
print '
';
-print load_fiche_titre($langs->trans("VATPaid"), '', '');
/*
* Payed
*/
+print load_fiche_titre($langs->trans("VATPaid"), '', '');
+
$sql = "SELECT SUM(amount) as mm, date_format(f.datep,'%Y-%m') as dm";
$sql.= " FROM ".MAIN_DB_PREFIX."tva as f";
$sql.= " WHERE f.entity = ".$conf->entity;
diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php
index 28b2878998f..0866bafad0c 100644
--- a/htdocs/compta/tva/quadri_detail.php
+++ b/htdocs/compta/tva/quadri_detail.php
@@ -127,7 +127,7 @@ $fsearch.=' ';
// Show report header
-$name=$langs->trans("VATReportByPeriods");
+$name=$langs->trans("VATReportByRates");
$calcmode='';
if ($modetax == 0) $calcmode=$langs->trans('OptionVATDefault');
if ($modetax == 1) $calcmode=$langs->trans('OptionVATDebitOption');
diff --git a/htdocs/core/lib/tax.lib.php b/htdocs/core/lib/tax.lib.php
index 216b2c7ea33..e432b741929 100644
--- a/htdocs/core/lib/tax.lib.php
+++ b/htdocs/core/lib/tax.lib.php
@@ -699,18 +699,19 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$oldrowid='';
while($assoc = $db->fetch_array($resql))
{
- if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0;
- if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0;
- if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
- if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
+ // Code to avoid warnings when array entry not defined
+ if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0;
+ if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0;
+ if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
+ if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=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']]['localtax1'] += $assoc['total_localtax1'];
- $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
+ $list[$assoc['rate']]['totalht'] += $assoc['total_ht'];
+ $list[$assoc['rate']]['vat'] += $assoc['total_vat'];
+ $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
+ $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
}
$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
@@ -730,7 +731,7 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
$list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
$list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1'];
- $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2'];
+ $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2'];
$list[$assoc['rate']]['pid'][] = $assoc['pid'];
$list[$assoc['rate']]['pref'][] = $assoc['pref'];
@@ -849,18 +850,19 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$oldrowid='';
while($assoc = $db->fetch_array($resql))
{
- if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0;
- if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0;
- if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
- if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
+ // Code to avoid warnings when array entry not defined
+ if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0;
+ if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0;
+ if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
+ if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=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']]['localtax1'] += $assoc['total_localtax1'];
- $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
+ $list[$assoc['rate']]['totalht'] += $assoc['total_ht'];
+ $list[$assoc['rate']]['vat'] += $assoc['total_vat'];
+ $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
+ $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
}
$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
$list[$assoc['rate']]['dtype'][] = $assoc['dtype'];
@@ -951,18 +953,19 @@ function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
$oldrowid='';
while($assoc = $db->fetch_array($resql))
{
- if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0;
- if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0;
- if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
- if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
+ // Code to avoid warnings when array entry not defined
+ if (! isset($list[$assoc['rate']]['totalht'])) $list[$assoc['rate']]['totalht']=0;
+ if (! isset($list[$assoc['rate']]['vat'])) $list[$assoc['rate']]['vat']=0;
+ if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
+ if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=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']]['localtax1'] += $assoc['total_localtax1'];
- $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
+ $list[$assoc['rate']]['totalht'] += $assoc['total_ht'];
+ $list[$assoc['rate']]['vat'] += $assoc['total_vat'];
+ $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
+ $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
}
$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 0b192e96429..9b4079281b9 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -548,8 +548,8 @@ Module400Name=Projects/Opportunities/Leads
Module400Desc=Management of projects, opportunities/leads and/or tasks. You can also assign any element (invoice, order, proposal, intervention, ...) to a project and get a transversal view from the project view.
Module410Name=Webcalendar
Module410Desc=Webcalendar integration
-Module500Name=Special expenses
-Module500Desc=Management of special expenses (taxes, social or fiscal taxes, dividends)
+Module500Name=Taxes and Special expenses
+Module500Desc=Management of special expenses (sale taxes, social or fiscal taxes, dividends, ...)
Module510Name=Payment of employee wages
Module510Desc=Record and follow payment of your employee wages
Module520Name=Loan