Work on rewriting VAT reports
This commit is contained in:
parent
c35a190f1d
commit
257dc1cf77
@ -26,6 +26,7 @@ require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
|
||||
|
||||
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin"));
|
||||
@ -163,7 +164,7 @@ if($calc ==0 || $calc == 2)
|
||||
print "<td align=\"right\">".$vatcust."</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell');
|
||||
$coll_list = tax_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell');
|
||||
|
||||
$action = "tvaclient";
|
||||
$object = &$coll_list;
|
||||
@ -247,7 +248,7 @@ if($calc ==0 || $calc == 1){
|
||||
|
||||
$company_static=new Societe($db);
|
||||
|
||||
$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
|
||||
$coll_list = tax_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
|
||||
$parameters["direction"] = 'buy';
|
||||
$parameters["type"] = 'localtax'.$local;
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
|
||||
|
||||
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin"));
|
||||
|
||||
@ -212,8 +213,8 @@ while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcu
|
||||
if ($m > 12) $m -= 12;
|
||||
$mcursor++;
|
||||
|
||||
$coll_listsell = tax_by_date('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
|
||||
$coll_listbuy = tax_by_date('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
|
||||
$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);
|
||||
|
||||
$action = "tva";
|
||||
$object = array(&$coll_listsell, &$coll_listbuy);
|
||||
@ -241,7 +242,7 @@ while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcu
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td class="nowrap"><a href="quadri_detail.php?leftmenu=tax_vat&month='.$m.'&year='.$y.'">'.dol_print_date(dol_mktime(0,0,0,$m,1,$y),"%b %Y").'</a></td>';
|
||||
|
||||
|
||||
if ($CalcLT==0) {
|
||||
$x_coll = 0;
|
||||
foreach($coll_listsell as $vatrate=>$val) {
|
||||
|
||||
@ -22,8 +22,7 @@
|
||||
/**
|
||||
* \file htdocs/compta/tva/quadri_detail.php
|
||||
* \ingroup tax
|
||||
* \brief Trimestrial page - detailed version
|
||||
* TODO Deal with recurrent invoices as well
|
||||
* \brief Local tax by rate
|
||||
*/
|
||||
global $mysoc;
|
||||
|
||||
@ -31,18 +30,21 @@ require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
|
||||
|
||||
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin"));
|
||||
|
||||
$local=GETPOST('localTaxType', 'int');
|
||||
// Date range
|
||||
$year=GETPOST("year");
|
||||
$year=GETPOST("year","int");
|
||||
if (empty($year))
|
||||
{
|
||||
$year_current = strftime("%Y",dol_now());
|
||||
@ -51,16 +53,15 @@ if (empty($year))
|
||||
$year_current = $year;
|
||||
$year_start = $year;
|
||||
}
|
||||
|
||||
$date_start = dol_mktime( 0, 0, 0, GETPOST( "date_startmonth" ), GETPOST( "date_startday" ), GETPOST( "date_startyear" ) );
|
||||
$date_end = dol_mktime( 23, 59, 59, GETPOST( "date_endmonth" ), GETPOST( "date_endday" ), GETPOST( "date_endyear" ) );
|
||||
$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,$_REQUEST["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,empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START,false);
|
||||
@ -83,7 +84,9 @@ if (empty($min)) $min = 0;
|
||||
|
||||
// Define modetax (0 or 1)
|
||||
// 0=normal, 1=option vat for services is on debit, 2=option on payments for products
|
||||
$modetax = $conf->global->TAX_MODE;
|
||||
//$modetax = $conf->global->TAX_MODE;
|
||||
$calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
|
||||
$modetax=$conf->global->$calc;
|
||||
if (GETPOSTISSET("modetax")) $modetax=GETPOST("modetax",'int');
|
||||
if (empty($modetax)) $modetax=0;
|
||||
|
||||
@ -92,121 +95,123 @@ $socid = GETPOST('socid','int');
|
||||
if ($user->societe_id) $socid=$user->societe_id;
|
||||
$result = restrictedArea($user, 'tax', '', '', 'charges');
|
||||
|
||||
/**
|
||||
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
$form=new Form($db);
|
||||
$company_static=new Societe($db);
|
||||
$invoice_customer=new Facture($db);
|
||||
$invoice_supplier=new FactureFournisseur($db);
|
||||
$expensereport=new ExpenseReport($db);
|
||||
$product_static=new Product($db);
|
||||
$payment_static=new Paiement($db);
|
||||
$paymentfourn_static=new PaiementFourn($db);
|
||||
$paymentexpensereport_static=new PaymentExpenseReport($db);
|
||||
|
||||
$morequerystring='';
|
||||
$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
|
||||
foreach($listofparams as $param)
|
||||
foreach ($listofparams as $param)
|
||||
{
|
||||
if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
|
||||
}
|
||||
|
||||
llxHeader('','','','',0,0,'','',$morequerystring);
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
$company_static=new Societe($db);
|
||||
$invoice_customer=new Facture($db);
|
||||
$invoice_supplier=new FactureFournisseur($db);
|
||||
$product_static=new Product($db);
|
||||
$payment_static=new Paiement($db);
|
||||
$paymentfourn_static=new PaiementFourn($db);
|
||||
llxHeader('',$langs->trans("LocalTaxReport"),'','',0,0,'','',$morequerystring);
|
||||
|
||||
$fsearch.=' <input type="hidden" name="year" value="'.$year.'">';
|
||||
$fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
|
||||
$fsearch.=' <input type="hidden" name="localTaxType" value="'.$local.'">';
|
||||
|
||||
$name=$langs->transcountry($local==1?"LT1ReportByQuarters":"LT2ReportByQuarters", $mysoc->country_code);
|
||||
$calc=$conf->global->MAIN_INFO_LOCALTAX_CALC.$local;
|
||||
|
||||
if ($conf->global->$calc==0 || $conf->global->$calc==1) // Calculate on invoice for goods and services
|
||||
{
|
||||
$calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT".$local."Rec");
|
||||
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')';
|
||||
$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
|
||||
$prevyear=$year_start; $prevquarter=$q;
|
||||
if ($prevquarter > 1) $prevquarter--;
|
||||
else { $prevquarter=4; $prevyear--; }
|
||||
$nextyear=$year_start; $nextquarter=$q;
|
||||
if ($nextquarter < 4) $nextquarter++;
|
||||
else { $nextquarter=1; $nextyear++; }
|
||||
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.='<br>'.$langs->trans("DepositsAreNotIncluded");
|
||||
else $description.='<br>'.$langs->trans("DepositsAreIncluded");
|
||||
$description.=$fsearch;
|
||||
$builddate=dol_now();
|
||||
|
||||
$elementcust=$langs->trans("CustomersInvoices");
|
||||
$productcust=$langs->trans("ProductOrService");
|
||||
$amountcust=$langs->trans("AmountHT");
|
||||
$vatcust=$langs->trans("VATReceived");
|
||||
if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
|
||||
$elementsup=$langs->trans("SuppliersInvoices");
|
||||
$productsup=$langs->trans("ProductOrService");
|
||||
$amountsup=$langs->trans("AmountHT");
|
||||
$vatsup=$langs->trans("VATPaid");
|
||||
if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
|
||||
$calcmode='';
|
||||
if ($modetax == 0) $calcmode=$langs->trans('OptionVATDefault');
|
||||
if ($modetax == 1) $calcmode=$langs->trans('OptionVATDebitOption');
|
||||
if ($modetax == 2) $calcmode=$langs->trans('OptionPaymentForProductAndServices');
|
||||
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
|
||||
// Set period
|
||||
$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
|
||||
$prevyear=$year_start; $prevquarter=$q;
|
||||
if ($prevquarter > 1) {
|
||||
$prevquarter--;
|
||||
} else {
|
||||
$prevquarter=4; $prevyear--;
|
||||
}
|
||||
if ($conf->global->$calc==2) // Invoice for goods, payment for services
|
||||
{
|
||||
$calcmode=$calc==0?$langs->trans("CalcModeLT".$local):$langs->trans("CalcModeLT".$local."Rec");
|
||||
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRulesLT",DOL_URL_ROOT.'/admin/company.php').')';
|
||||
$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
|
||||
$prevyear=$year_start; $prevquarter=$q;
|
||||
if ($prevquarter > 1) $prevquarter--;
|
||||
else { $prevquarter=4; $prevyear--; }
|
||||
$nextyear=$year_start; $nextquarter=$q;
|
||||
if ($nextquarter < 4) $nextquarter++;
|
||||
else { $nextquarter=1; $nextyear++; }
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $description.=' '.$langs->trans("DepositsAreNotIncluded");
|
||||
else $description.=' '.$langs->trans("DepositsAreIncluded");
|
||||
$description.=$fsearch;
|
||||
$builddate=dol_now();
|
||||
|
||||
$elementcust=$langs->trans("CustomersInvoices");
|
||||
$productcust=$langs->trans("ProductOrService");
|
||||
$amountcust=$langs->trans("AmountHT");
|
||||
$vatcust=$langs->trans("VATReceived");
|
||||
if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
|
||||
$elementsup=$langs->trans("SuppliersInvoices");
|
||||
$productsup=$langs->trans("ProductOrService");
|
||||
$amountsup=$langs->trans("AmountHT");
|
||||
$vatsup=$langs->trans("VATPaid");
|
||||
if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
|
||||
$nextyear=$year_start; $nextquarter=$q;
|
||||
if ($nextquarter < 4) {
|
||||
$nextquarter++;
|
||||
} else {
|
||||
$nextquarter=1; $nextyear++;
|
||||
}
|
||||
$description.=$fsearch;
|
||||
$builddate=dol_now();
|
||||
|
||||
/*if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description.=$langs->trans("RulesVATDueProducts");
|
||||
if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') $description.=$langs->trans("RulesVATInProducts");
|
||||
if ($conf->global->TAX_MODE_SELL_SERVICE == 'invoice') $description.='<br>'.$langs->trans("RulesVATDueServices");
|
||||
if ($conf->global->TAX_MODE_SELL_SERVICE == 'payment') $description.='<br>'.$langs->trans("RulesVATInServices");
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
||||
$description.='<br>'.$langs->trans("DepositsAreNotIncluded");
|
||||
}
|
||||
*/
|
||||
if (! empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description.='<br>'.$langs->trans("ThisIsAnEstimatedValue");
|
||||
|
||||
// Customers invoices
|
||||
$elementcust=$langs->trans("CustomersInvoices");
|
||||
$productcust=$langs->trans("ProductOrService");
|
||||
$amountcust=$langs->trans("AmountHT");
|
||||
$vatcust=$langs->trans("VATReceived");
|
||||
$namecust=$langs->trans("Name");
|
||||
if ($mysoc->tva_assuj) {
|
||||
$vatcust.=' ('.$langs->trans("ToPay").')';
|
||||
}
|
||||
|
||||
// Suppliers invoices
|
||||
$elementsup=$langs->trans("SuppliersInvoices");
|
||||
$productsup=$productcust;
|
||||
$amountsup=$amountcust;
|
||||
$vatsup=$langs->trans("VATPaid");
|
||||
$namesup=$namecust;
|
||||
if ($mysoc->tva_assuj) {
|
||||
$vatsup.=' ('.$langs->trans("ToGetBack").')';
|
||||
}
|
||||
|
||||
|
||||
report_header($name,'',$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
|
||||
|
||||
|
||||
if($local==1){
|
||||
$vatcust=$langs->transcountry("LocalTax1", $mysoc->country_code);
|
||||
$vatsup=$langs->transcountry("LocalTax1", $mysoc->country_code);
|
||||
$vatexpensereport=$langs->transcountry("LocalTax1", $mysoc->country_code);
|
||||
}else{
|
||||
$vatcust=$langs->transcountry("LocalTax2", $mysoc->country_code);
|
||||
$vatsup=$langs->transcountry("LocalTax2", $mysoc->country_code);
|
||||
$vatexpensereport=$langs->transcountry("LocalTax2", $mysoc->country_code);
|
||||
}
|
||||
|
||||
// VAT Received and paid
|
||||
echo '<table class="noborder" width="100%">';
|
||||
|
||||
$y = $year_current;
|
||||
$total = 0;
|
||||
$i=0;
|
||||
$columns = 5;
|
||||
|
||||
// Load arrays of datas
|
||||
$x_coll = tax_by_date('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
|
||||
$x_paye = tax_by_date('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
|
||||
|
||||
echo '<table class="noborder" width="100%">';
|
||||
$x_coll = tax_by_rate('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
|
||||
$x_paye = tax_by_rate('localtax' . $local, $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
|
||||
|
||||
if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
{
|
||||
$langs->load("errors");
|
||||
if ($x_coll == -1)
|
||||
print '<tr><td colspan="5">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
|
||||
print '<tr><td colspan="'.$columns.'">'.$langs->trans("ErrorNoAccountancyModuleLoaded").'</td></tr>';
|
||||
else if ($x_coll == -2)
|
||||
print '<tr><td colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
|
||||
print '<tr><td colspan="'.$columns.'">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>';
|
||||
else
|
||||
print '<tr><td colspan="5">'.$langs->trans("Error").'</td></tr>';
|
||||
print '<tr><td colspan="'.$columns.'">'.$langs->trans("Error").'</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -226,6 +231,7 @@ else
|
||||
$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],
|
||||
@ -237,20 +243,24 @@ else
|
||||
'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],
|
||||
'localtax1'=> $x_coll[$my_coll_rate]['localtax1_list'][$id],
|
||||
'localtax2'=> $x_coll[$my_coll_rate]['localtax2_list'][$id],
|
||||
'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
|
||||
'link' =>$invoice_customer->getNomUrl(1,'',12));
|
||||
'link' =>$invoice_customer->getNomUrl(1,'',12)
|
||||
);
|
||||
}
|
||||
}
|
||||
// tva paid
|
||||
foreach(array_keys($x_paye) as $my_paye_rate){
|
||||
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'])){
|
||||
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;
|
||||
}
|
||||
@ -273,35 +283,39 @@ else
|
||||
'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]),
|
||||
'localtax1'=> $x_paye[$my_paye_rate]['localtax1_list'][$id],
|
||||
'localtax2'=> $x_paye[$my_paye_rate]['localtax2_list'][$id],
|
||||
'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
|
||||
'link' =>$invoice_supplier->getNomUrl(1,'',12));
|
||||
'link' =>$invoice_supplier->getNomUrl(1,'',12)
|
||||
);
|
||||
}
|
||||
}
|
||||
//now we have an array (x_both) indexed by rates for coll and paye
|
||||
|
||||
//print table headers for this quadri - incomes first
|
||||
|
||||
$x_coll_sum = 0;
|
||||
$x_coll_ht = 0;
|
||||
$x_paye_sum = 0;
|
||||
$x_paye_ht = 0;
|
||||
|
||||
$span=3;
|
||||
if ($modetax == 0) $span+=2;
|
||||
$span=$columns;
|
||||
if ($modetax != 1) $span+=2;
|
||||
|
||||
if($conf->global->$calc ==0 || $conf->global->$calc == 2){
|
||||
//if ($modetax == 0 || $modetax == 2)
|
||||
//{
|
||||
// Customers invoices
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementcust.'</td>';
|
||||
print '<td align="left">'.$productcust.'</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td align="right">'.$amountcust.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
|
||||
}
|
||||
if ($modetax != 2) print '<td align="right">'.$amountcust.'</td>';
|
||||
if ($modetax != 1) print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
|
||||
print '<td align="right">'.$langs->trans("BI").'</td>';
|
||||
print '<td align="right">'.$vatcust.'</td>';
|
||||
print '</tr>';
|
||||
@ -317,8 +331,6 @@ else
|
||||
if (is_array($x_both[$rate]['coll']['detail']))
|
||||
{
|
||||
// VAT Rate
|
||||
$var=true;
|
||||
|
||||
if($rate!=0){
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
|
||||
@ -326,116 +338,116 @@ else
|
||||
}
|
||||
foreach($x_both[$rate]['coll']['detail'] as $index => $fields)
|
||||
{
|
||||
if(($local==1 && $fields['localtax1']!=0) || ($local==2 && $fields['localtax2']!=0)){
|
||||
// Define type
|
||||
$type=($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;
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Ref
|
||||
print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
|
||||
|
||||
// Description
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
if(($local==1 && $fields['localtax1']!=0) || ($local==2 && $fields['localtax2']!=0))
|
||||
{
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($type) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg))
|
||||
{
|
||||
if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit');
|
||||
elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
|
||||
else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
|
||||
}
|
||||
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
|
||||
// Define type
|
||||
$type=($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;
|
||||
|
||||
// Show range
|
||||
print_date_range($fields['ddate_start'],$fields['ddate_end']);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Total HT
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
print price($fields['totalht']);
|
||||
if (price2num($fields['ftotal_ttc']))
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Ref
|
||||
print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
|
||||
|
||||
// Description
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($type) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg))
|
||||
{
|
||||
if ($reg[1]=='DEPOSIT') $fields['descr']=$langs->transnoentitiesnoconv('Deposit');
|
||||
elseif ($reg[1]=='CREDIT_NOTE') $fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
|
||||
else $fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
|
||||
}
|
||||
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
|
||||
|
||||
// Show range
|
||||
print_date_range($fields['ddate_start'],$fields['ddate_end']);
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Payment
|
||||
$ratiopaymentinvoice=1;
|
||||
if ($modetax == 0)
|
||||
{
|
||||
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
// Total HT
|
||||
if ($modetax != 2)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
print price($fields['totalht']);
|
||||
if (price2num($fields['ftotal_ttc']))
|
||||
{
|
||||
$ratiolineinvoice=($fields['dtotal_ttc']/$fields['ftotal_ttc']);
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Payment
|
||||
$ratiopaymentinvoice=1;
|
||||
if ($modetax != 1)
|
||||
{
|
||||
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
print '<td class="nowrap" align="right">';
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$payment_static->id=$fields['payment_id'];
|
||||
print $payment_static->getNomUrl(2);
|
||||
}
|
||||
if ($type == 0)
|
||||
{
|
||||
print $langs->trans("NotUsedForGoods");
|
||||
}
|
||||
else {
|
||||
print price($fields['payment_amount']);
|
||||
if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Total collected
|
||||
print '<td class="nowrap" align="right">';
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$payment_static->id=$fields['payment_id'];
|
||||
print $payment_static->getNomUrl(2);
|
||||
}
|
||||
if ($type == 0)
|
||||
{
|
||||
print $langs->trans("NotUsedForGoods");
|
||||
}
|
||||
else {
|
||||
print price($fields['payment_amount']);
|
||||
if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
}
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
|
||||
// Localtax
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_vat= $local==1?$fields['localtax1']:$fields['localtax2'];
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_coll_total_ht += $temp_ht;
|
||||
$subtot_coll_vat += $temp_vat;
|
||||
$x_coll_sum += $temp_vat;
|
||||
}
|
||||
|
||||
// Total collected
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
|
||||
// Localtax
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_vat= $local==1?$fields['localtax1']:$fields['localtax2'];
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_coll_total_ht += $temp_ht;
|
||||
$subtot_coll_vat += $temp_vat;
|
||||
$x_coll_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($rate!=0){
|
||||
// Total customers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
// Total customers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (count($x_coll) == 0) // Show a total ine if nothing shown
|
||||
@ -457,15 +469,15 @@ else
|
||||
print '<tr><td colspan="'.($span+1).'"> </td></tr>';
|
||||
print '</table>';
|
||||
$diff=$x_coll_sum;
|
||||
}
|
||||
//}
|
||||
|
||||
if($conf->global->$calc ==0 || $conf->global->$calc == 1){
|
||||
//if($conf->global->$calc ==0 || $conf->global->$calc == 1){
|
||||
echo '<table class="noborder" width="100%">';
|
||||
//print table headers for this quadri - expenses now
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementsup.'</td>';
|
||||
print '<td align="left">'.$productsup.'</td>';
|
||||
if ($modetax == 0)
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td align="right">'.$amountsup.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
|
||||
@ -479,9 +491,8 @@ else
|
||||
$subtot_paye_total_ht = 0;
|
||||
$subtot_paye_vat = 0;
|
||||
|
||||
if(is_array($x_both[$rate]['paye']['detail']))
|
||||
if (is_array($x_both[$rate]['paye']['detail']))
|
||||
{
|
||||
$var=true;
|
||||
if($rate!=0){
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.$span.'"></td>';
|
||||
@ -489,149 +500,144 @@ else
|
||||
}
|
||||
foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
|
||||
{
|
||||
if(($local==1 && $fields['localtax1']!=0) || ($local==2 && $fields['localtax2']!=0)){
|
||||
// Define type
|
||||
$type=($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;
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Ref
|
||||
print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
|
||||
|
||||
// Description
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
if(($local==1 && $fields['localtax1']!=0) || ($local==2 && $fields['localtax2']!=0))
|
||||
{
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($type) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
|
||||
// Define type
|
||||
$type=($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;
|
||||
|
||||
// Show range
|
||||
print_date_range($fields['ddate_start'],$fields['ddate_end']);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Total HT
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
print price($fields['totalht']);
|
||||
if (price2num($fields['ftotal_ttc']))
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Ref
|
||||
print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
|
||||
|
||||
// Description
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
//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 (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
print '<td class="nowrap" align="right">';
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$paymentfourn_static->id=$fields['payment_id'];
|
||||
print $paymentfourn_static->getNomUrl(2);
|
||||
}
|
||||
if ($type == 0)
|
||||
{
|
||||
print $langs->trans("NotUsedForGoods");
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->type=$fields['ptype'];
|
||||
print $product_static->getNomUrl(1);
|
||||
if (dol_string_nohtmltag($fields['descr'])) print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
|
||||
}
|
||||
else
|
||||
{
|
||||
print price($fields['payment_amount']);
|
||||
if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
if ($type) $text = img_object($langs->trans('Service'),'service');
|
||||
else $text = img_object($langs->trans('Product'),'product');
|
||||
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),16);
|
||||
|
||||
// Show range
|
||||
print_date_range($fields['ddate_start'],$fields['ddate_end']);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Total HT
|
||||
if ($modetax != 2)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
print price($fields['totalht']);
|
||||
if (price2num($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 != 1)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) $ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$paymentfourn_static->id=$fields['payment_id'];
|
||||
print $paymentfourn_static->getNomUrl(2);
|
||||
}
|
||||
if ($type == 0)
|
||||
{
|
||||
print $langs->trans("NA");
|
||||
}
|
||||
else
|
||||
{
|
||||
print price(price2num($fields['payment_amount'],'MT'));
|
||||
if (isset($fields['payment_amount'])) {
|
||||
print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
}
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// VAT paid
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'),1);
|
||||
print '</td>';
|
||||
|
||||
// Localtax
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_vat=($local==1?$fields['localtax1']:$fields['localtax2'])*$ratiopaymentinvoice;;
|
||||
print price(price2num($temp_vat,'MT'),1);
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_paye_total_ht += $temp_ht;
|
||||
$subtot_paye_vat += $temp_vat;
|
||||
$x_paye_sum += $temp_vat;
|
||||
}
|
||||
|
||||
// VAT paid
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_ht=$fields['totalht'];
|
||||
if ($type == 1) $temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'));
|
||||
print '</td>';
|
||||
|
||||
// Localtax
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_vat= $local==1?$fields['localtax1']:$fields['localtax2'];
|
||||
print price(price2num($temp_vat,'MT'));
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_paye_total_ht += $temp_ht;
|
||||
$subtot_paye_vat += $temp_vat;
|
||||
$x_paye_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($rate!=0){
|
||||
// Total suppliers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td> </td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
// Total suppliers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td> </td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (count($x_paye) == 0) // Show a total ine if nothing shown
|
||||
{
|
||||
print '<tr class="liste_total">';
|
||||
print '<td> </td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax == 0)
|
||||
{
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num(0,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
if (count($x_paye) == 0) { // Show a total line if nothing shown
|
||||
print '<tr class="liste_total">';
|
||||
print '<td> </td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num(0,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
$diff=$x_paye_sum;
|
||||
}
|
||||
//}
|
||||
|
||||
if($conf->global->$calc ==0){$diff=$x_coll_sum - $x_paye_sum;}
|
||||
echo '<table class="noborder" width="100%">';
|
||||
// Total to pay
|
||||
print '<br><br>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
//$diff = $local==1?$x_coll_sum:$x_paye_sum;
|
||||
print '<tr class="liste_total">';
|
||||
print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
|
||||
print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
|
||||
print "</tr>\n";
|
||||
|
||||
echo '</table>';
|
||||
// Total to pay
|
||||
print '<br><br>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
$diff = $x_coll_sum - $x_paye_sum;
|
||||
print '<tr class="liste_total">';
|
||||
print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
|
||||
print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
|
||||
print "</tr>\n";
|
||||
|
||||
$i++;
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
llxFooter();
|
||||
$db->close();
|
||||
|
||||
@ -30,7 +30,14 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
|
||||
|
||||
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin"));
|
||||
|
||||
@ -84,10 +91,6 @@ $socid = GETPOST('socid','int');
|
||||
if ($user->societe_id) $socid=$user->societe_id;
|
||||
$result = restrictedArea($user, 'tax', '', '', 'charges');
|
||||
|
||||
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
|
||||
$modecompta = $conf->global->ACCOUNTING_MODE;
|
||||
if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta");
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@ -96,13 +99,19 @@ if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta");
|
||||
|
||||
$form=new Form($db);
|
||||
$company_static=new Societe($db);
|
||||
$invoice_customer=new Facture($db);
|
||||
$invoice_supplier=new FactureFournisseur($db);
|
||||
$expensereport=new ExpenseReport($db);
|
||||
$product_static=new Product($db);
|
||||
$payment_static=new Paiement($db);
|
||||
$paymentfourn_static=new PaiementFourn($db);
|
||||
$paymentexpensereport_static=new PaymentExpenseReport($db);
|
||||
|
||||
$morequerystring='';
|
||||
$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
|
||||
foreach($listofparams as $param) {
|
||||
if (GETPOST($param)!='') {
|
||||
$morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
|
||||
}
|
||||
foreach ($listofparams as $param)
|
||||
{
|
||||
if (GETPOST($param)!='') $morequerystring.=($morequerystring?'&':'').$param.'='.GETPOST($param);
|
||||
}
|
||||
|
||||
$special_report = false;
|
||||
@ -118,15 +127,28 @@ $fsearch.=' <input type="hidden" name="modetax" value="'.$modetax.'">';
|
||||
$fsearch.=' '.$langs->trans("SalesTurnoverMinimum").': ';
|
||||
$fsearch.=' <input type="text" name="min" id="min" value="'.$min.'" size="6">';
|
||||
|
||||
$description='';
|
||||
|
||||
// Show report header
|
||||
$name=$langs->trans("VATReportByCustomers");
|
||||
$name=$langs->trans("VATReportByThirdParties");
|
||||
$calcmode='';
|
||||
if ($modetax == 0) $calcmode=$langs->trans('OptionVATDefault');
|
||||
if ($modetax == 1) $calcmode=$langs->trans('OptionVATDebitOption');
|
||||
if ($modetax == 2) $calcmode=$langs->trans('OptionPaymentForProductAndServices');
|
||||
$calcmode.='<br>('.$langs->trans("TaxModuleSetupToModifyRules",DOL_URL_ROOT.'/admin/taxes.php').')';
|
||||
// Set period
|
||||
$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
|
||||
$prevyear=$year_start; $prevquarter=$q;
|
||||
if ($prevquarter > 1) {
|
||||
$prevquarter--;
|
||||
} else {
|
||||
$prevquarter=4; $prevyear--;
|
||||
}
|
||||
$nextyear=$year_start; $nextquarter=$q;
|
||||
if ($nextquarter < 4) {
|
||||
$nextquarter++;
|
||||
} else {
|
||||
$nextquarter=1; $nextyear++;
|
||||
}
|
||||
$builddate=dol_now();
|
||||
|
||||
if ($conf->global->TAX_MODE_SELL_PRODUCT == 'invoice') $description.=$langs->trans("RulesVATDueProducts");
|
||||
if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment') $description.=$langs->trans("RulesVATInProducts");
|
||||
@ -137,23 +159,24 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
||||
}
|
||||
if (! empty($conf->global->MAIN_MODULE_ACCOUNTING)) $description.='<br>'.$langs->trans("ThisIsAnEstimatedValue");
|
||||
|
||||
$period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1);
|
||||
//$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.=$fsearch;
|
||||
$description.='<br>'
|
||||
. '<input type="radio" name="extra_report" value="0" '.($special_report?'':'checked="checked"').'> '
|
||||
. $langs->trans('SimpleReport')
|
||||
. '</input>'
|
||||
. '<br>'
|
||||
. '<input type="radio" name="extra_report" value="1" '.($special_report?'checked="checked"':'').'> '
|
||||
. $langs->trans('AddExtraReport')
|
||||
. '</input>'
|
||||
. '<br>';
|
||||
$builddate=dol_now();
|
||||
//$exportlink=$langs->trans("NotYetAvailable");
|
||||
if (! empty($conf->global->TAX_REPORT_EXTRA_REPORT))
|
||||
{
|
||||
$description.='<br>'
|
||||
. '<input type="radio" name="extra_report" value="0" '.($special_report?'':'checked="checked"').'> '
|
||||
. $langs->trans('SimpleReport')
|
||||
. '</input>'
|
||||
. '<br>'
|
||||
. '<input type="radio" name="extra_report" value="1" '.($special_report?'checked="checked"':'').'> '
|
||||
. $langs->trans('AddExtraReport')
|
||||
. '</input>'
|
||||
. '<br>';
|
||||
}
|
||||
|
||||
$elementcust=$langs->trans("CustomersInvoices");
|
||||
$productcust=$langs->trans("Description");
|
||||
$namerate=$langs->trans("VATRate");
|
||||
$amountcust=$langs->trans("AmountHT");
|
||||
if ($mysoc->tva_assuj) {
|
||||
$vatcust.=' ('.$langs->trans("ToPay").')';
|
||||
@ -172,152 +195,547 @@ $vatsup=$langs->trans("VATPaid");
|
||||
|
||||
// VAT Received
|
||||
|
||||
//print "<br>";
|
||||
//print load_fiche_titre($vatcust);
|
||||
|
||||
print "<table class=\"noborder\" width=\"100%\">";
|
||||
print "<tr class=\"liste_titre\">";
|
||||
print '<td align="left">'.$langs->trans("Num")."</td>";
|
||||
print '<td align="left">'.$langs->trans("Customer")."</td>";
|
||||
print "<td>".$langs->trans("VATIntra")."</td>";
|
||||
print "<td align=\"right\">".$langs->trans("AmountHTVATRealReceived")."</td>";
|
||||
print "<td align=\"right\">".$vatcust."</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'sell');
|
||||
$y = $year_current;
|
||||
$total = 0;
|
||||
$i=0;
|
||||
$columns = 5;
|
||||
|
||||
$action = "tvaclient";
|
||||
$object = &$coll_list;
|
||||
$parameters["mode"] = $modetax;
|
||||
$parameters["start"] = $date_start;
|
||||
$parameters["end"] = $date_end;
|
||||
$parameters["direction"] = 'sell';
|
||||
$parameters["type"] = 'vat';
|
||||
// Load arrays of datas
|
||||
$x_coll = tax_by_thirdparty('vat', $db, 0, $date_start, $date_end, $modetax, 'sell');
|
||||
$x_paye = tax_by_thirdparty('vat', $db, 0, $date_start, $date_end, $modetax, 'buy');
|
||||
|
||||
// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
|
||||
$hookmanager->initHooks(array('externalbalance'));
|
||||
$reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
|
||||
if (is_array($coll_list)) {
|
||||
$var=true;
|
||||
$total = 0; $totalamount = 0;
|
||||
$i = 1;
|
||||
foreach ($coll_list as $coll) {
|
||||
if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
|
||||
|
||||
$intra = str_replace($find,$replace,$coll->tva_intra);
|
||||
if(empty($intra)) {
|
||||
if($coll->assuj == '1') {
|
||||
$intra = $langs->trans('Unknown');
|
||||
} else {
|
||||
//$intra = $langs->trans('NotRegistered');
|
||||
$intra = '';
|
||||
}
|
||||
}
|
||||
print '<tr class="oddeven">';
|
||||
print '<td class="nowrap">'.$i."</td>";
|
||||
$company_static->id=$coll->socid;
|
||||
$company_static->name=$coll->name;
|
||||
$company_static->client=1;
|
||||
print '<td class="nowrap">'.$company_static->getNomUrl(1,'customer').'</td>';
|
||||
$find = array(' ','.');
|
||||
$replace = array('','');
|
||||
print '<td class="nowrap">'.$intra."</td>";
|
||||
print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
|
||||
print "<td class=\"nowrap\" align=\"right\">".price($coll->tva)."</td>";
|
||||
$totalamount = $totalamount + $coll->amount;
|
||||
$total = $total + $coll->tva;
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$x_coll_sum = $total;
|
||||
|
||||
print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
|
||||
print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price($total).'</td>';
|
||||
print '</tr>';
|
||||
} else {
|
||||
if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
{
|
||||
$langs->load("errors");
|
||||
if ($coll_list == -1) {
|
||||
if ($modecompta == 'CREANCES-DETTES')
|
||||
{
|
||||
print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
}
|
||||
} else if ($coll_list == -2) {
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
if ($x_coll == -1) {
|
||||
print '<tr><td colspan="' . $columns . '">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
|
||||
} else if ($x_coll == -2) {
|
||||
print '<tr><td colspan="' . $columns . '">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
} else {
|
||||
print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
|
||||
print '<tr><td colspan="' . $columns . '">' . $langs->trans("Error") . '</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
//print '</table>';
|
||||
|
||||
|
||||
// VAT Paid
|
||||
|
||||
//print "<br>";
|
||||
//print load_fiche_titre($vatsup);
|
||||
|
||||
//print "<table class=\"noborder\" width=\"100%\">";
|
||||
print "<tr class=\"liste_titre liste_titre_topborder\">";
|
||||
print '<td align="left">'.$langs->trans("Num")."</td>";
|
||||
print '<td align="left">'.$langs->trans("Supplier")."</td>";
|
||||
print "<td>".$langs->trans("VATIntra")."</td>";
|
||||
print "<td align=\"right\">".$langs->trans("AmountHTVATRealPaid")."</td>";
|
||||
print "<td align=\"right\">".$vatsup."</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
$company_static=new Societe($db);
|
||||
|
||||
$coll_list = vat_by_thirdparty($db,0,$date_start,$date_end,$modetax,'buy');
|
||||
|
||||
$parameters["direction"] = 'buy';
|
||||
$reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
if (is_array($coll_list)) {
|
||||
$var=true;
|
||||
$total = 0; $totalamount = 0;
|
||||
$i = 1;
|
||||
foreach ($coll_list as $coll) {
|
||||
if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
|
||||
|
||||
$intra = str_replace($find,$replace,$coll->tva_intra);
|
||||
if (empty($intra)) {
|
||||
if ($coll->assuj == '1') {
|
||||
$intra = $langs->trans('Unknown');
|
||||
} else {
|
||||
//$intra = $langs->trans('NotRegistered');
|
||||
$intra = '';
|
||||
}
|
||||
}
|
||||
print '<tr class="oddeven">';
|
||||
print '<td class="nowrap">'.$i."</td>";
|
||||
$company_static->id=$coll->socid;
|
||||
$company_static->name=$coll->name;
|
||||
$company_static->fournisseur=1;
|
||||
print '<td class="nowrap">'.$company_static->getNomUrl(1,'supplier').'</td>';
|
||||
$find = array(' ','.');
|
||||
$replace = array('','');
|
||||
print '<td class="nowrap">'.$intra."</td>";
|
||||
print "<td class=\"nowrap\" align=\"right\">".price($coll->amount)."</td>";
|
||||
print "<td class=\"nowrap\" align=\"right\">".price($coll->tva)."</td>";
|
||||
$totalamount = $totalamount + $coll->amount;
|
||||
$total = $total + $coll->tva;
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
} else {
|
||||
$x_both = array();
|
||||
//now, from these two arrays, get another array with one rate per line
|
||||
foreach(array_keys($x_coll) as $my_coll_thirdpartyid)
|
||||
{
|
||||
$x_both[$my_coll_thirdpartyid]['coll']['totalht'] = $x_coll[$my_coll_thirdpartyid]['totalht'];
|
||||
$x_both[$my_coll_thirdpartyid]['coll']['vat'] = $x_coll[$my_coll_thirdpartyid]['vat'];
|
||||
$x_both[$my_coll_thirdpartyid]['paye']['totalht'] = 0;
|
||||
$x_both[$my_coll_thirdpartyid]['paye']['vat'] = 0;
|
||||
$x_both[$my_coll_thirdpartyid]['coll']['links'] = '';
|
||||
$x_both[$my_coll_thirdpartyid]['coll']['detail'] = array();
|
||||
foreach($x_coll[$my_coll_thirdpartyid]['facid'] as $id=>$dummy) {
|
||||
$invoice_customer->id=$x_coll[$my_coll_thirdpartyid]['facid'][$id];
|
||||
$invoice_customer->ref=$x_coll[$my_coll_thirdpartyid]['facnum'][$id];
|
||||
$invoice_customer->type=$x_coll[$my_coll_thirdpartyid]['type'][$id];
|
||||
$company_static->fetch($x_coll[$my_coll_thirdpartyid]['company_id'][$id]);
|
||||
$x_both[$my_coll_thirdpartyid]['coll']['detail'][] = array(
|
||||
'id' =>$x_coll[$my_coll_thirdpartyid]['facid'][$id],
|
||||
'descr' =>$x_coll[$my_coll_thirdpartyid]['descr'][$id],
|
||||
'pid' =>$x_coll[$my_coll_thirdpartyid]['pid'][$id],
|
||||
'pref' =>$x_coll[$my_coll_thirdpartyid]['pref'][$id],
|
||||
'ptype' =>$x_coll[$my_coll_thirdpartyid]['ptype'][$id],
|
||||
'payment_id'=>$x_coll[$my_coll_thirdpartyid]['payment_id'][$id],
|
||||
'payment_amount'=>$x_coll[$my_coll_thirdpartyid]['payment_amount'][$id],
|
||||
'ftotal_ttc'=>$x_coll[$my_coll_thirdpartyid]['ftotal_ttc'][$id],
|
||||
'dtotal_ttc'=>$x_coll[$my_coll_thirdpartyid]['dtotal_ttc'][$id],
|
||||
'dtype' =>$x_coll[$my_coll_thirdpartyid]['dtype'][$id],
|
||||
'drate' =>$x_coll[$my_coll_thirdpartyid]['drate'][$id],
|
||||
'datef' =>$x_coll[$my_coll_thirdpartyid]['datef'][$id],
|
||||
'datep' =>$x_coll[$my_coll_thirdpartyid]['datep'][$id],
|
||||
'company_link'=>$company_static->getNomUrl(1,'',20),
|
||||
'ddate_start'=>$x_coll[$my_coll_thirdpartyid]['ddate_start'][$id],
|
||||
'ddate_end' =>$x_coll[$my_coll_thirdpartyid]['ddate_end'][$id],
|
||||
'totalht' =>$x_coll[$my_coll_thirdpartyid]['totalht_list'][$id],
|
||||
'vat' =>$x_coll[$my_coll_thirdpartyid]['vat_list'][$id],
|
||||
'link' =>$invoice_customer->getNomUrl(1,'',12)
|
||||
);
|
||||
}
|
||||
}
|
||||
$x_paye_sum = $total;
|
||||
// tva paid
|
||||
foreach (array_keys($x_paye) as $my_paye_thirdpartyid) {
|
||||
$x_both[$my_paye_thirdpartyid]['paye']['totalht'] = $x_paye[$my_paye_thirdpartyid]['totalht'];
|
||||
$x_both[$my_paye_thirdpartyid]['paye']['vat'] = $x_paye[$my_paye_thirdpartyid]['vat'];
|
||||
if (!isset($x_both[$my_paye_thirdpartyid]['coll']['totalht'])) {
|
||||
$x_both[$my_paye_thirdpartyid]['coll']['totalht'] = 0;
|
||||
$x_both[$my_paye_thirdpartyid]['coll']['vat'] = 0;
|
||||
}
|
||||
$x_both[$my_paye_thirdpartyid]['paye']['links'] = '';
|
||||
$x_both[$my_paye_thirdpartyid]['paye']['detail'] = array();
|
||||
|
||||
print '<tr class="liste_total"><td align="right" colspan="3">'.$langs->trans("Total").':</td>';
|
||||
print '<td class="nowrap" align="right">'.price($totalamount).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price($total).'</td>';
|
||||
foreach ($x_paye[$my_paye_thirdpartyid]['facid'] as $id=>$dummy)
|
||||
{
|
||||
// ExpenseReport
|
||||
if ($x_paye[$my_paye_thirdpartyid]['ptype'][$id] == 'ExpenseReportPayment')
|
||||
{
|
||||
$expensereport->id=$x_paye[$my_paye_thirdpartyid]['facid'][$id];
|
||||
$expensereport->ref=$x_paye[$my_paye_thirdpartyid]['facnum'][$id];
|
||||
$expensereport->type=$x_paye[$my_paye_thirdpartyid]['type'][$id];
|
||||
|
||||
$x_both[$my_paye_thirdpartyid]['paye']['detail'][] = array(
|
||||
'id' =>$x_paye[$my_paye_thirdpartyid]['facid'][$id],
|
||||
'descr' =>$x_paye[$my_paye_thirdpartyid]['descr'][$id],
|
||||
'pid' =>$x_paye[$my_paye_thirdpartyid]['pid'][$id],
|
||||
'pref' =>$x_paye[$my_paye_thirdpartyid]['pref'][$id],
|
||||
'ptype' =>$x_paye[$my_paye_thirdpartyid]['ptype'][$id],
|
||||
'payment_id' =>$x_paye[$my_paye_thirdpartyid]['payment_id'][$id],
|
||||
'payment_amount' =>$x_paye[$my_paye_thirdpartyid]['payment_amount'][$id],
|
||||
'ftotal_ttc' =>price2num($x_paye[$my_paye_thirdpartyid]['ftotal_ttc'][$id]),
|
||||
'dtotal_ttc' =>price2num($x_paye[$my_paye_thirdpartyid]['dtotal_ttc'][$id]),
|
||||
'dtype' =>$x_paye[$my_paye_thirdpartyid]['dtype'][$id],
|
||||
'drate' =>$x_paye[$my_coll_thirdpartyid]['drate'][$id],
|
||||
'ddate_start' =>$x_paye[$my_paye_thirdpartyid]['ddate_start'][$id],
|
||||
'ddate_end' =>$x_paye[$my_paye_thirdpartyid]['ddate_end'][$id],
|
||||
'totalht' =>price2num($x_paye[$my_paye_thirdpartyid]['totalht_list'][$id]),
|
||||
'vat' =>$x_paye[$my_paye_thirdpartyid]['vat_list'][$id],
|
||||
'link' =>$expensereport->getNomUrl(1)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$invoice_supplier->id=$x_paye[$my_paye_thirdpartyid]['facid'][$id];
|
||||
$invoice_supplier->ref=$x_paye[$my_paye_thirdpartyid]['facnum'][$id];
|
||||
$invoice_supplier->type=$x_paye[$my_paye_thirdpartyid]['type'][$id];
|
||||
$company_static->fetch($x_paye[$my_paye_thirdpartyid]['company_id'][$id]);
|
||||
$x_both[$my_paye_thirdpartyid]['paye']['detail'][] = array(
|
||||
'id' =>$x_paye[$my_paye_thirdpartyid]['facid'][$id],
|
||||
'descr' =>$x_paye[$my_paye_thirdpartyid]['descr'][$id],
|
||||
'pid' =>$x_paye[$my_paye_thirdpartyid]['pid'][$id],
|
||||
'pref' =>$x_paye[$my_paye_thirdpartyid]['pref'][$id],
|
||||
'ptype' =>$x_paye[$my_paye_thirdpartyid]['ptype'][$id],
|
||||
'payment_id'=>$x_paye[$my_paye_thirdpartyid]['payment_id'][$id],
|
||||
'payment_amount'=>$x_paye[$my_paye_thirdpartyid]['payment_amount'][$id],
|
||||
'ftotal_ttc'=>price2num($x_paye[$my_paye_thirdpartyid]['ftotal_ttc'][$id]),
|
||||
'dtotal_ttc'=>price2num($x_paye[$my_paye_thirdpartyid]['dtotal_ttc'][$id]),
|
||||
'dtype' =>$x_paye[$my_paye_thirdpartyid]['dtype'][$id],
|
||||
'drate' =>$x_paye[$my_coll_thirdpartyid]['drate'][$id],
|
||||
'datef' =>$x_paye[$my_paye_thirdpartyid]['datef'][$id],
|
||||
'datep' =>$x_paye[$my_paye_thirdpartyid]['datep'][$id],
|
||||
'company_link'=>$company_static->getNomUrl(1,'',20),
|
||||
'ddate_start'=>$x_paye[$my_paye_thirdpartyid]['ddate_start'][$id],
|
||||
'ddate_end' =>$x_paye[$my_paye_thirdpartyid]['ddate_end'][$id],
|
||||
'totalht' =>price2num($x_paye[$my_paye_thirdpartyid]['totalht_list'][$id]),
|
||||
'vat' =>$x_paye[$my_paye_thirdpartyid]['vat_list'][$id],
|
||||
'link' =>$invoice_supplier->getNomUrl(1,'',12)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
//now we have an array (x_both) indexed by rates for coll and paye
|
||||
|
||||
|
||||
//print table headers for this quadri - incomes first
|
||||
|
||||
$x_coll_sum = 0;
|
||||
$x_coll_ht = 0;
|
||||
$x_paye_sum = 0;
|
||||
$x_paye_ht = 0;
|
||||
|
||||
$span=$columns;
|
||||
if ($modetax != 1) $span+=2;
|
||||
|
||||
//print '<tr><td colspan="'.($span+1).'">'..')</td></tr>';
|
||||
|
||||
// Customers invoices
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td align="left">'.$elementcust.'</td>';
|
||||
print '<td align="left">'.$langs->trans("DateInvoice").'</td>';
|
||||
if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '<td align="left">'.$langs->trans("DatePayment").'</td>';
|
||||
else print '<td></td>';
|
||||
print '<td align="right">'.$namerate.'</td>';
|
||||
print '<td align="left">'.$productcust.'</td>';
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td align="right">'.$amountcust.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
|
||||
}
|
||||
print '<td align="right">'.$langs->trans("AmountHTVATRealReceived").'</td>';
|
||||
print '<td align="right">'.$vatcust.'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$action = "tvadetail";
|
||||
$parameters["mode"] = $modetax;
|
||||
$parameters["start"] = $date_start;
|
||||
$parameters["end"] = $date_end;
|
||||
$parameters["type"] = 'vat';
|
||||
|
||||
$object = array(&$x_coll, &$x_paye, &$x_both);
|
||||
// Initialize technical object to manage hooks of expenses. Note that conf->hooks_modules contains array array
|
||||
$hookmanager->initHooks(array('externalbalance'));
|
||||
$reshook=$hookmanager->executeHooks('addVatLine',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
|
||||
|
||||
foreach (array_keys($x_coll) as $thirdparty_id) {
|
||||
$subtot_coll_total_ht = 0;
|
||||
$subtot_coll_vat = 0;
|
||||
|
||||
if (is_array($x_both[$thirdparty_id]['coll']['detail']))
|
||||
{
|
||||
|
||||
// VAT Rate
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">';
|
||||
if (is_numeric($thirdparty_id))
|
||||
{
|
||||
$company_static->fetch($thirdparty_id);
|
||||
print $langs->trans("ThirdParty").': '.$company_static->getNomUrl(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmpid = preg_replace('/userid_/','',$thirdparty_id);
|
||||
$user_static->fetch($tmpid);
|
||||
print $langs->trans("User").': '.$user_static->getNomUrl(1);
|
||||
}
|
||||
print '</td><td colspan="'.($span+1).'"></td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
foreach ($x_both[$thirdparty_id]['coll']['detail'] as $index => $fields) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Ref
|
||||
print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
|
||||
|
||||
// Invoice date
|
||||
print '<td align="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
|
||||
|
||||
// Payment date
|
||||
if ($conf->global->TAX_MODE_SELL_PRODUCT == 'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 'payment') print '<td align="left">' . dol_print_date($fields['datep'], 'day') . '</td>';
|
||||
else print '<td></td>';
|
||||
|
||||
// Rate
|
||||
print '<td align="right">' . $fields['drate'] . '</td>';
|
||||
|
||||
// Description
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->type=$fields['dtype']; // We force with the type of line to have type how line is registered
|
||||
print $product_static->getNomUrl(1);
|
||||
if (dol_string_nohtmltag($fields['descr'])) {
|
||||
print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),24);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($type) {
|
||||
$text = img_object($langs->trans('Service'),'service');
|
||||
} else {
|
||||
$text = img_object($langs->trans('Product'),'product');
|
||||
}
|
||||
if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) {
|
||||
if ($reg[1]=='DEPOSIT') {
|
||||
$fields['descr']=$langs->transnoentitiesnoconv('Deposit');
|
||||
} elseif ($reg[1]=='CREDIT_NOTE') {
|
||||
$fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
|
||||
} else {
|
||||
$fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
|
||||
}
|
||||
}
|
||||
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),24);
|
||||
|
||||
// Show range
|
||||
print_date_range($fields['ddate_start'],$fields['ddate_end']);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Total HT
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
print price($fields['totalht']);
|
||||
if (price2num($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 != 1)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
//print $fields['totalht']."-".$fields['payment_amount']."-".$fields['ftotal_ttc'];
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$payment_static->id=$fields['payment_id'];
|
||||
print $payment_static->getNomUrl(2);
|
||||
}
|
||||
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']);
|
||||
}
|
||||
print price(price2num($fields['payment_amount'],'MT'));
|
||||
if (isset($fields['payment_amount'])) {
|
||||
print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
}
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Total collected
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'),1);
|
||||
print '</td>';
|
||||
|
||||
// VAT
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat,'MT'),1);
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_coll_total_ht += $temp_ht;
|
||||
$subtot_coll_vat += $temp_vat;
|
||||
$x_coll_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
// Total customers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num($subtot_coll_total_ht,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num($subtot_coll_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (count($x_coll) == 0) // Show a total ine if nothing shown
|
||||
{
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num(0,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
// Blank line
|
||||
print '<tr><td colspan="'.($span+1).'"> </td></tr>';
|
||||
|
||||
// Print table headers for this quadri - expenses now
|
||||
print '<tr class="liste_titre liste_titre_topborder">';
|
||||
print '<td align="left">'.$elementsup.'</td>';
|
||||
print '<td align="left">'.$langs->trans("DateInvoice").'</td>';
|
||||
if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td align="left">'.$langs->trans("DatePayment").'</td>';
|
||||
else print '<td></td>';
|
||||
print '<td align="left">'.$namesup.'</td>';
|
||||
print '<td align="left">'.$productsup.'</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td align="right">'.$amountsup.'</td>';
|
||||
print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
|
||||
}
|
||||
print '<td align="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
|
||||
print '<td align="right">'.$vatsup.'</td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
foreach (array_keys($x_paye) as $thirdparty_id)
|
||||
{
|
||||
$subtot_paye_total_ht = 0;
|
||||
$subtot_paye_vat = 0;
|
||||
|
||||
if (is_array($x_both[$thirdparty_id]['paye']['detail']))
|
||||
{
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">';
|
||||
if (is_numeric($thirdparty_id))
|
||||
{
|
||||
$company_static->fetch($thirdparty_id);
|
||||
print $langs->trans("ThirdParty").': '.$company_static->getNomUrl(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmpid = preg_replace('/userid_/','',$thirdparty_id);
|
||||
$user_static->fetch($tmpid);
|
||||
print $langs->trans("User").': '.$user_static->getNomUrl(1);
|
||||
}
|
||||
print '<td colspan="'.($span+1).'"></td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
foreach ($x_both[$thirdparty_id]['paye']['detail'] as $index=>$fields) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
|
||||
// Ref
|
||||
print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
|
||||
|
||||
// Invoice date
|
||||
print '<td align="left">' . dol_print_date($fields['datef'], 'day') . '</td>';
|
||||
|
||||
// Payment date
|
||||
if ($conf->global->TAX_MODE_BUY_PRODUCT == 'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 'payment') print '<td align="left">' . dol_print_date($fields['datep'], 'day') . '</td>';
|
||||
else print '<td></td>';
|
||||
|
||||
// Company name
|
||||
print '<td align="left">' . $fields['company_link'] . '</td>';
|
||||
|
||||
// Description
|
||||
print '<td align="left">';
|
||||
if ($fields['pid'])
|
||||
{
|
||||
$product_static->id=$fields['pid'];
|
||||
$product_static->ref=$fields['pref'];
|
||||
$product_static->type=$fields['dtype']; // We force with the type of line to have type how line is registered
|
||||
print $product_static->getNomUrl(1);
|
||||
if (dol_string_nohtmltag($fields['descr'])) {
|
||||
print ' - '.dol_trunc(dol_string_nohtmltag($fields['descr']),24);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($type) {
|
||||
$text = img_object($langs->trans('Service'),'service');
|
||||
} else {
|
||||
$text = img_object($langs->trans('Product'),'product');
|
||||
}
|
||||
if (preg_match('/^\((.*)\)$/',$fields['descr'],$reg)) {
|
||||
if ($reg[1]=='DEPOSIT') {
|
||||
$fields['descr']=$langs->transnoentitiesnoconv('Deposit');
|
||||
} elseif ($reg[1]=='CREDIT_NOTE') {
|
||||
$fields['descr']=$langs->transnoentitiesnoconv('CreditNote');
|
||||
} else {
|
||||
$fields['descr']=$langs->transnoentitiesnoconv($reg[1]);
|
||||
}
|
||||
}
|
||||
print $text.' '.dol_trunc(dol_string_nohtmltag($fields['descr']),24);
|
||||
|
||||
// Show range
|
||||
print_date_range($fields['ddate_start'],$fields['ddate_end']);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Total HT
|
||||
if ($modetax != 1)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
print price($fields['totalht']);
|
||||
if (price2num($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 != 1)
|
||||
{
|
||||
print '<td class="nowrap" align="right">';
|
||||
if ($fields['payment_amount'] && $fields['ftotal_ttc'])
|
||||
{
|
||||
$paymentfourn_static->id=$fields['payment_id'];
|
||||
print $paymentfourn_static->getNomUrl(2);
|
||||
}
|
||||
|
||||
if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice')
|
||||
|| ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
|
||||
{
|
||||
print $langs->trans("NA");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($fields['payment_amount']) && $fields['ftotal_ttc']) {
|
||||
$ratiopaymentinvoice=($fields['payment_amount']/$fields['ftotal_ttc']);
|
||||
}
|
||||
print price(price2num($fields['payment_amount'],'MT'));
|
||||
if (isset($fields['payment_amount'])) {
|
||||
print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
||||
}
|
||||
}
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// VAT paid
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_ht=$fields['totalht']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_ht,'MT'),1);
|
||||
print '</td>';
|
||||
|
||||
// VAT
|
||||
print '<td class="nowrap" align="right">';
|
||||
$temp_vat=$fields['vat']*$ratiopaymentinvoice;
|
||||
print price(price2num($temp_vat,'MT'),1);
|
||||
//print price($fields['vat']);
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
$subtot_paye_total_ht += $temp_ht;
|
||||
$subtot_paye_vat += $temp_vat;
|
||||
$x_paye_sum += $temp_vat;
|
||||
}
|
||||
}
|
||||
// Total suppliers for this vat rate
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num($subtot_paye_total_ht,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num($subtot_paye_vat,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (count($x_paye) == 0) { // Show a total line if nothing shown
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
print '<td align="right">'.$langs->trans("Total").':</td>';
|
||||
if ($modetax != 1) {
|
||||
print '<td class="nowrap" align="right"> </td>';
|
||||
print '<td align="right"> </td>';
|
||||
}
|
||||
print '<td align="right">'.price(price2num(0,'MT')).'</td>';
|
||||
print '<td class="nowrap" align="right">'.price(price2num(0,'MT')).'</td>';
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
// Total to pay
|
||||
@ -325,198 +743,15 @@ if (is_array($coll_list)) {
|
||||
print '<table class="noborder" width="100%">';
|
||||
$diff = $x_coll_sum - $x_paye_sum;
|
||||
print '<tr class="liste_total">';
|
||||
print '<td class="liste_total" colspan="4">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
|
||||
print '<td class="liste_total" colspan="'.$span.'">'.$langs->trans("TotalToPay").($q?', '.$langs->trans("Quadri").' '.$q:'').'</td>';
|
||||
print '<td class="liste_total nowrap" align="right"><b>'.price(price2num($diff,'MT'))."</b></td>\n";
|
||||
print "</tr>\n";
|
||||
|
||||
} else {
|
||||
$langs->load("errors");
|
||||
if ($coll_list == -1) {
|
||||
if ($modecompta == 'CREANCES-DETTES')
|
||||
{
|
||||
print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
}
|
||||
} else if ($coll_list == -2) {
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
} else {
|
||||
print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
||||
if ($special_report) {
|
||||
// Get country 2-letters code
|
||||
global $mysoc;
|
||||
$country_id = $mysoc->country_id;
|
||||
$country = new Ccountry($db);
|
||||
$country->fetch($country_id);
|
||||
|
||||
// Print listing of other-country customers as additional report
|
||||
// This matches tax requirements to list all same-country customers (only)
|
||||
print '<h3>'.$langs->trans('OtherCountriesCustomersReport').'</h3>';
|
||||
print $langs->trans('BasedOnTwoFirstLettersOfVATNumberBeingDifferentFromYourCompanyCountry');
|
||||
$coll_list = vat_by_thirdparty($db, 0, $date_start, $date_end, $modetax, 'sell');
|
||||
|
||||
print "<table class=\"noborder\" width=\"100%\">";
|
||||
print "<tr class=\"liste_titre\">";
|
||||
print '<td align="left">' . $langs->trans("Num") . "</td>";
|
||||
print '<td align="left">' . $langs->trans("Customer") . "</td>";
|
||||
print "<td>" . $langs->trans("VATIntra") . "</td>";
|
||||
print "<td align=\"right\">" . $langs->trans("AmountHTVATRealReceived") . "</td>";
|
||||
print "<td align=\"right\">" . $vatcust . "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
if (is_array($coll_list)) {
|
||||
$var = true;
|
||||
$total = 0;
|
||||
$totalamount = 0;
|
||||
$i = 1;
|
||||
foreach ($coll_list as $coll) {
|
||||
if (substr($coll->tva_intra, 0, 2) == $country->code) {
|
||||
// Only use different-country VAT codes
|
||||
continue;
|
||||
}
|
||||
if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
|
||||
$var = !$var;
|
||||
$intra = str_replace($find, $replace, $coll->tva_intra);
|
||||
if (empty($intra)) {
|
||||
if ($coll->assuj == '1') {
|
||||
$intra = $langs->trans('Unknown');
|
||||
} else {
|
||||
//$intra = $langs->trans('NotRegistered');
|
||||
$intra = '';
|
||||
}
|
||||
}
|
||||
print "<tr " . $bc[$var] . ">";
|
||||
print '<td class="nowrap">' . $i . "</td>";
|
||||
$company_static->id = $coll->socid;
|
||||
$company_static->name = $coll->name;
|
||||
$company_static->client = 1;
|
||||
print '<td class="nowrap">' . $company_static->getNomUrl(1,
|
||||
'customer') . '</td>';
|
||||
$find = array(' ', '.');
|
||||
$replace = array('', '');
|
||||
print '<td class="nowrap">' . $intra . "</td>";
|
||||
print "<td class=\"nowrap\" align=\"right\">" . price($coll->amount) . "</td>";
|
||||
print "<td class=\"nowrap\" align=\"right\">" . price($coll->tva) . "</td>";
|
||||
$totalamount = $totalamount + $coll->amount;
|
||||
$total = $total + $coll->tva;
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$x_coll_sum = $total;
|
||||
|
||||
print '<tr class="liste_total"><td align="right" colspan="3">' . $langs->trans("Total") . ':</td>';
|
||||
print '<td class="nowrap" align="right">' . price($totalamount) . '</td>';
|
||||
print '<td class="nowrap" align="right">' . price($total) . '</td>';
|
||||
print '</tr>';
|
||||
} else {
|
||||
$langs->load("errors");
|
||||
if ($coll_list == -1) {
|
||||
if ($modecompta == 'CREANCES-DETTES')
|
||||
{
|
||||
print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
}
|
||||
} else {
|
||||
if ($coll_list == -2) {
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
} else {
|
||||
print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
// Print listing of same-country customers as additional report
|
||||
// This matches tax requirements to list all same-country customers (only)
|
||||
print '<h3>'.$langs->trans('SameCountryCustomersWithVAT').'</h3>';
|
||||
print $langs->trans('BasedOnTwoFirstLettersOfVATNumberBeingTheSameAsYourCompanyCountry');
|
||||
$coll_list = vat_by_thirdparty($db, 0, $date_start, $date_end, $modetax, 'sell');
|
||||
|
||||
print "<table class=\"noborder\" width=\"100%\">";
|
||||
print "<tr class=\"liste_titre\">";
|
||||
print '<td align="left">' . $langs->trans("Num") . "</td>";
|
||||
print '<td align="left">' . $langs->trans("Customer") . "</td>";
|
||||
print "<td>" . $langs->trans("VATIntra") . "</td>";
|
||||
print "<td align=\"right\">" . $langs->trans("AmountHTVATRealReceived") . "</td>";
|
||||
print "<td align=\"right\">" . $vatcust . "</td>";
|
||||
print "</tr>\n";
|
||||
|
||||
if (is_array($coll_list)) {
|
||||
$var = true;
|
||||
$total = 0;
|
||||
$totalamount = 0;
|
||||
$i = 1;
|
||||
foreach ($coll_list as $coll) {
|
||||
if (substr($coll->tva_intra, 0, 2) != $country->code) {
|
||||
// Only use same-country VAT codes
|
||||
continue;
|
||||
}
|
||||
if ($min == 0 or ($min > 0 && $coll->amount > $min)) {
|
||||
$var = !$var;
|
||||
$intra = str_replace($find, $replace, $coll->tva_intra);
|
||||
if (empty($intra)) {
|
||||
if ($coll->assuj == '1') {
|
||||
$intra = $langs->trans('Unknown');
|
||||
} else {
|
||||
//$intra = $langs->trans('NotRegistered');
|
||||
$intra = '';
|
||||
}
|
||||
}
|
||||
print "<tr " . $bc[$var] . ">";
|
||||
print '<td class="nowrap">' . $i . "</td>";
|
||||
$company_static->id = $coll->socid;
|
||||
$company_static->name = $coll->name;
|
||||
$company_static->client = 1;
|
||||
print '<td class="nowrap">' . $company_static->getNomUrl(1, 'customer') . '</td>';
|
||||
$find = array(' ', '.');
|
||||
$replace = array('', '');
|
||||
print '<td class="nowrap">' . $intra . "</td>";
|
||||
print "<td class=\"nowrap\" align=\"right\">" . price($coll->amount) . "</td>";
|
||||
print "<td class=\"nowrap\" align=\"right\">" . price($coll->tva) . "</td>";
|
||||
$totalamount = $totalamount + $coll->amount;
|
||||
$total = $total + $coll->tva;
|
||||
print "</tr>\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$x_coll_sum = $total;
|
||||
|
||||
print '<tr class="liste_total"><td align="right" colspan="3">' . $langs->trans("Total") . ':</td>';
|
||||
print '<td class="nowrap" align="right">' . price($totalamount) . '</td>';
|
||||
print '<td class="nowrap" align="right">' . price($total) . '</td>';
|
||||
print '</tr>';
|
||||
} else {
|
||||
$langs->load("errors");
|
||||
if ($coll_list == -1) {
|
||||
if ($modecompta == 'CREANCES-DETTES')
|
||||
{
|
||||
print '<tr><td colspan="5">' . $langs->trans("ErrorNoAccountancyModuleLoaded") . '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
}
|
||||
} else {
|
||||
if ($coll_list == -2) {
|
||||
print '<tr><td colspan="5">' . $langs->trans("FeatureNotYetAvailable") . '</td></tr>';
|
||||
} else {
|
||||
print '<tr><td colspan="5">' . $langs->trans("Error") . '</td></tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
print '</table>';
|
||||
}
|
||||
|
||||
llxFooter();
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
|
||||
|
||||
$langs->loadLangs(array("other","compta","banks","bills","companies","product","trips","admin"));
|
||||
|
||||
@ -199,8 +200,8 @@ while ((($y < $yend) || ($y == $yend && $m < $mend)) && $mcursor < 1000) // $mcu
|
||||
if ($m > 12) $m -= 12;
|
||||
$mcursor++;
|
||||
|
||||
$coll_listsell = tax_by_date('vat', $db, $y, 0, 0, 0, $modetax, 'sell', $m);
|
||||
$coll_listbuy = tax_by_date('vat', $db, $y, 0, 0, 0, $modetax, 'buy', $m);
|
||||
$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);
|
||||
|
||||
$action = "tva";
|
||||
$object = array(&$coll_listsell, &$coll_listbuy);
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
/**
|
||||
* \file htdocs/compta/tva/quadri_detail.php
|
||||
* \ingroup tax
|
||||
* \brief Trimestrial page - detailed version
|
||||
* \brief VAT by rate
|
||||
*/
|
||||
|
||||
require '../../main.inc.php';
|
||||
@ -30,6 +30,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
|
||||
@ -55,10 +56,10 @@ $date_end=dol_mktime(23,59,59,GETPOST("date_endmonth"),GETPOST("date_endday"),GE
|
||||
// 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,empty($conf->global->SOCIETE_FISCAL_MONTH_START)?1:$conf->global->SOCIETE_FISCAL_MONTH_START,false);
|
||||
@ -96,6 +97,16 @@ $result = restrictedArea($user, 'tax', '', '', 'charges');
|
||||
* View
|
||||
*/
|
||||
|
||||
$form=new Form($db);
|
||||
$company_static=new Societe($db);
|
||||
$invoice_customer=new Facture($db);
|
||||
$invoice_supplier=new FactureFournisseur($db);
|
||||
$expensereport=new ExpenseReport($db);
|
||||
$product_static=new Product($db);
|
||||
$payment_static=new Paiement($db);
|
||||
$paymentfourn_static=new PaiementFourn($db);
|
||||
$paymentexpensereport_static=new PaymentExpenseReport($db);
|
||||
|
||||
$morequerystring='';
|
||||
$listofparams=array('date_startmonth','date_startyear','date_startday','date_endmonth','date_endyear','date_endday');
|
||||
foreach ($listofparams as $param)
|
||||
@ -105,16 +116,6 @@ foreach ($listofparams as $param)
|
||||
|
||||
llxHeader('',$langs->trans("VATReport"),'','',0,0,'','',$morequerystring);
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
$company_static=new Societe($db);
|
||||
$invoice_customer=new Facture($db);
|
||||
$invoice_supplier=new FactureFournisseur($db);
|
||||
$expensereport=new ExpenseReport($db);
|
||||
$product_static=new Product($db);
|
||||
$payment_static=new Paiement($db);
|
||||
$paymentfourn_static=new PaiementFourn($db);
|
||||
$paymentexpensereport_static=new PaymentExpenseReport($db);
|
||||
|
||||
//print load_fiche_titre($langs->trans("VAT"),"");
|
||||
|
||||
@ -185,6 +186,7 @@ $vatcust=$langs->trans("VATReceived");
|
||||
$vatsup=$langs->trans("VATPaid");
|
||||
$vatexpensereport=$langs->trans("VATPaid");
|
||||
|
||||
|
||||
// VAT Received and paid
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
@ -194,8 +196,8 @@ $i=0;
|
||||
$columns = 5;
|
||||
|
||||
// Load arrays of datas
|
||||
$x_coll = tax_by_date('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
|
||||
$x_paye = tax_by_date('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
|
||||
$x_coll = tax_by_rate('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'sell');
|
||||
$x_paye = tax_by_rate('vat', $db, 0, 0, $date_start, $date_end, $modetax, 'buy');
|
||||
|
||||
if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
{
|
||||
@ -362,7 +364,6 @@ if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
if (is_array($x_both[$rate]['coll']['detail']))
|
||||
{
|
||||
// VAT Rate
|
||||
$var=true;
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.($span+1).'"></td>';
|
||||
print '</tr>'."\n";
|
||||
@ -504,7 +505,7 @@ if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
print '</tr>';
|
||||
}
|
||||
|
||||
if (count($x_coll) == 0) // Show a total ine if nothing shown
|
||||
if (count($x_coll) == 0) // Show a total line if nothing shown
|
||||
{
|
||||
print '<tr class="liste_total">';
|
||||
print '<td colspan="4"></td>';
|
||||
@ -544,7 +545,6 @@ if (! is_array($x_coll) || ! is_array($x_paye))
|
||||
|
||||
if (is_array($x_both[$rate]['paye']['detail']))
|
||||
{
|
||||
$var=true;
|
||||
print "<tr>";
|
||||
print '<td class="tax_rate">'.$langs->trans("Rate").': '.vatrate($rate).'%</td><td colspan="'.($span+1).'"></td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
@ -77,107 +77,467 @@ function tax_prepare_head(ChargeSociales $object)
|
||||
/**
|
||||
* Look for collectable VAT clients in the chosen year (and month)
|
||||
*
|
||||
* @param string $type Tax type, either 'vat', 'localtax1' or 'localtax2'
|
||||
* @param DoliDB $db Database handle
|
||||
* @param int $y Year
|
||||
* @param string $date_start Start date
|
||||
* @param string $date_end End date
|
||||
* @param int $modetax 0 or 1 (option vat on debit, 1 => $modecompta = 'CREANCES-DETTES')
|
||||
* @param int $modetax Not used
|
||||
* @param string $direction 'sell' or 'buy'
|
||||
* @param int $m Month
|
||||
* @return array List of customers third parties with vat, -1 if no accountancy module, -2 if not yet developped, -3 if error
|
||||
* @param int $q Quarter
|
||||
* @return array Array with details of VATs (per third parties), -1 if no accountancy module, -2 if not yet developped, -3 if error
|
||||
*/
|
||||
function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction, $m=0)
|
||||
function tax_by_thirdparty($type='vat', $db, $y, $date_start, $date_end, $modetax, $direction, $m=0, $q=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$list=array();
|
||||
// If we use date_start and date_end, we must not use $y, $m, $q
|
||||
if (($date_start || $date_end) && (! empty($y) || ! empty($m) || ! empty($q)))
|
||||
{
|
||||
dol_print_error('', 'Bad value of input parameter for tax_by_rate');
|
||||
}
|
||||
|
||||
$list=array();
|
||||
if ($direction == 'sell')
|
||||
{
|
||||
$invoicetable='facture';
|
||||
$total_ht='total';
|
||||
$total_tva='tva';
|
||||
$invoicetable='facture';
|
||||
$invoicedettable='facturedet';
|
||||
$fk_facture='fk_facture';
|
||||
$fk_facture2='fk_facture';
|
||||
$fk_payment='fk_paiement';
|
||||
$total_tva='total_tva';
|
||||
$paymenttable='paiement';
|
||||
$paymentfacturetable='paiement_facture';
|
||||
$invoicefieldref='facnumber';
|
||||
}
|
||||
if ($direction == 'buy')
|
||||
{
|
||||
$invoicetable='facture_fourn';
|
||||
$total_ht='total_ht';
|
||||
$total_tva='total_tva';
|
||||
$invoicetable='facture_fourn';
|
||||
$invoicedettable='facture_fourn_det';
|
||||
$fk_facture='fk_facture_fourn';
|
||||
$fk_facture2='fk_facturefourn';
|
||||
$fk_payment='fk_paiementfourn';
|
||||
$total_tva='tva';
|
||||
$paymenttable='paiementfourn';
|
||||
$paymentfacturetable='paiementfourn_facturefourn';
|
||||
$invoicefieldref='ref';
|
||||
}
|
||||
|
||||
if ( strpos( $type, 'localtax' ) === 0 ) {
|
||||
$f_rate = $type . '_tx';
|
||||
} else {
|
||||
$f_rate = 'tva_tx';
|
||||
}
|
||||
|
||||
$total_localtax1='total_localtax1';
|
||||
$total_localtax2='total_localtax2';
|
||||
|
||||
|
||||
// CAS DES BIENS/PRODUITS
|
||||
|
||||
// Define sql request
|
||||
$sql='';
|
||||
if ($modetax == 1)
|
||||
if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
|
||||
|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice'))
|
||||
{
|
||||
// If vat paid on due invoices (non draft)
|
||||
$sql = "SELECT s.rowid as socid, s.nom as name, s.tva_intra as tva_intra, s.tva_assuj as assuj,";
|
||||
$sql.= " sum(f.$total_ht) as amount, sum(f.".$total_tva.") as tva,";
|
||||
$sql.= " sum(f.localtax1) as localtax1,";
|
||||
$sql.= " sum(f.localtax2) as localtax2";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE f.entity = " . $conf->entity;
|
||||
$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
|
||||
else $sql.= " AND f.type IN (0,1,2,3,5)";
|
||||
if ($y && $m)
|
||||
{
|
||||
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
|
||||
$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
|
||||
}
|
||||
else if ($y)
|
||||
{
|
||||
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
|
||||
$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
|
||||
}
|
||||
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND s.rowid = f.fk_soc";
|
||||
$sql.= " GROUP BY s.rowid, s.nom, s.tva_intra, s.tva_assuj";
|
||||
// Count on delivery date (use invoice date as delivery is unknown)
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate 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 .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
|
||||
$sql.= " d.date_start as date_start, d.date_end as date_end,";
|
||||
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
|
||||
$sql.= " 0 as payment_id, 0 as payment_amount";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE f.entity = " . $conf->entity;
|
||||
$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
|
||||
else $sql.= " AND f.type IN (0,1,2,3,5)";
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;
|
||||
$sql.= " AND s.rowid = f.fk_soc";
|
||||
if ($y && $m)
|
||||
{
|
||||
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
|
||||
$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
|
||||
}
|
||||
else if ($y)
|
||||
{
|
||||
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
|
||||
$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
|
||||
}
|
||||
if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
|
||||
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = 0"; // Limit to products
|
||||
$sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Tva sur factures payes (should be on payment)
|
||||
/* $sql = "SELECT s.rowid as socid, s.nom as nom, s.tva_intra as tva_intra, s.tva_assuj as assuj,";
|
||||
$sql.= " sum(fd.total_ht) as amount, sum(".$total_tva.") as tva";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f, ".MAIN_DB_PREFIX.$invoicetable." as fd, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " WHERE ";
|
||||
$sql.= " f.fk_statut in (2)"; // Paid (partially or completely)
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
|
||||
else $sql.= " AND f.type IN (0,1,2,3,5)";
|
||||
if ($y && $m)
|
||||
{
|
||||
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
|
||||
$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
|
||||
}
|
||||
else if ($y)
|
||||
{
|
||||
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
|
||||
$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
|
||||
}
|
||||
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND s.rowid = f.fk_soc AND f.rowid = fd.".$fk_facture;
|
||||
$sql.= " GROUP BY s.rowid as socid, s.nom as nom, s.tva_intra as tva_intra, s.tva_assuj as assuj";
|
||||
*/
|
||||
// Count on payments date
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate 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 .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
|
||||
$sql.= " d.date_start as date_start, d.date_end as date_end,";
|
||||
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
|
||||
$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
|
||||
$sql.= " pa.datep as datep";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE f.entity = " . $conf->entity;
|
||||
$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
|
||||
else $sql.= " AND f.type IN (0,1,2,3,5)";
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;
|
||||
$sql.= " AND s.rowid = f.fk_soc";
|
||||
$sql.= " AND pf.".$fk_facture2." = f.rowid";
|
||||
$sql.= " AND pa.rowid = pf.".$fk_payment;
|
||||
if ($y && $m)
|
||||
{
|
||||
$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
|
||||
$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
|
||||
}
|
||||
else if ($y)
|
||||
{
|
||||
$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
|
||||
$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
|
||||
}
|
||||
if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
|
||||
if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = 0"; // Limit to products
|
||||
$sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
|
||||
}
|
||||
|
||||
if (! $sql) return -1;
|
||||
|
||||
dol_syslog("Tax.lib:thirdparty", LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
if ($sql == 'TODO') return -2;
|
||||
if ($sql != 'TODO')
|
||||
{
|
||||
while($assoc = $db->fetch_object($resql))
|
||||
{
|
||||
$list[] = $assoc;
|
||||
}
|
||||
$db->free($resql);
|
||||
return $list;
|
||||
dol_syslog("Tax.lib.php::tax_by_thirdparty", LOG_DEBUG);
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$company_id = -1;
|
||||
$oldrowid='';
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0;
|
||||
if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0;
|
||||
if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0;
|
||||
if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0;
|
||||
|
||||
if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid
|
||||
{
|
||||
$oldrowid=$assoc['rowid'];
|
||||
$list[$assoc['company_id']]['totalht'] += $assoc['total_ht'];
|
||||
$list[$assoc['company_id']]['vat'] += $assoc['total_vat'];
|
||||
$list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1'];
|
||||
$list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2'];
|
||||
}
|
||||
$list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
|
||||
$list[$assoc['company_id']]['dtype'][] = $assoc['dtype'];
|
||||
$list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']);
|
||||
$list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']);
|
||||
$list[$assoc['company_id']]['company_name'][] = $assoc['company_name'];
|
||||
$list[$assoc['company_id']]['company_id'][] = $assoc['company_id'];
|
||||
$list[$assoc['company_id']]['drate'][] = $assoc['rate'];
|
||||
$list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
|
||||
$list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
|
||||
|
||||
$list[$assoc['company_id']]['facid'][] = $assoc['facid'];
|
||||
$list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
|
||||
$list[$assoc['company_id']]['type'][] = $assoc['type'];
|
||||
$list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
|
||||
$list[$assoc['company_id']]['descr'][] = $assoc['descr'];
|
||||
|
||||
$list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
|
||||
$list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
|
||||
$list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
|
||||
$list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2'];
|
||||
|
||||
$list[$assoc['company_id']]['pid'][] = $assoc['pid'];
|
||||
$list[$assoc['company_id']]['pref'][] = $assoc['pref'];
|
||||
$list[$assoc['company_id']]['ptype'][] = $assoc['ptype'];
|
||||
|
||||
$list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
|
||||
$list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
|
||||
|
||||
$company_id = $assoc['company_id'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// CAS DES SERVICES
|
||||
|
||||
// Define sql request
|
||||
$sql='';
|
||||
if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')
|
||||
|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
|
||||
{
|
||||
// Count on invoice date
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate 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 .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
|
||||
$sql.= " d.date_start as date_start, d.date_end as date_end,";
|
||||
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
|
||||
$sql.= " 0 as payment_id, 0 as payment_amount";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE f.entity = " . $conf->entity;
|
||||
$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
|
||||
else $sql.= " AND f.type IN (0,1,2,3,5)";
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;
|
||||
$sql.= " AND s.rowid = f.fk_soc";
|
||||
if ($y && $m)
|
||||
{
|
||||
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
|
||||
$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
|
||||
}
|
||||
else if ($y)
|
||||
{
|
||||
$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
|
||||
$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
|
||||
}
|
||||
if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
|
||||
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = 1"; // Limit to services
|
||||
$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -3;
|
||||
// Count on payments date
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate 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 .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
|
||||
$sql.= " d.date_start as date_start, d.date_end as date_end,";
|
||||
$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
|
||||
$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
|
||||
$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
|
||||
$sql.= " pa.datep as datep";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."societe as s,";
|
||||
$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
|
||||
$sql.= " WHERE f.entity = " . $conf->entity;
|
||||
$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
|
||||
if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
|
||||
else $sql.= " AND f.type IN (0,1,2,3,5)";
|
||||
$sql.= " AND f.rowid = d.".$fk_facture;
|
||||
$sql.= " AND s.rowid = f.fk_soc";
|
||||
$sql.= " AND pf.".$fk_facture2." = f.rowid";
|
||||
$sql.= " AND pa.rowid = pf.".$fk_payment;
|
||||
if ($y && $m)
|
||||
{
|
||||
$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
|
||||
$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
|
||||
}
|
||||
else if ($y)
|
||||
{
|
||||
$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
|
||||
$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
|
||||
}
|
||||
if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
|
||||
if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = 1"; // Limit to services
|
||||
$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
|
||||
}
|
||||
|
||||
if (! $sql)
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
|
||||
return -1; // -1 = Not accountancy module enabled
|
||||
}
|
||||
if ($sql == 'TODO') return -2; // -2 = Feature not yet available
|
||||
if ($sql != 'TODO')
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$company_id = -1;
|
||||
$oldrowid='';
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0;
|
||||
if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0;
|
||||
if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0;
|
||||
if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0;
|
||||
|
||||
if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid
|
||||
{
|
||||
$oldrowid=$assoc['rowid'];
|
||||
$list[$assoc['company_id']]['totalht'] += $assoc['total_ht'];
|
||||
$list[$assoc['company_id']]['vat'] += $assoc['total_vat'];
|
||||
$list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1'];
|
||||
$list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2'];
|
||||
}
|
||||
$list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
|
||||
$list[$assoc['company_id']]['dtype'][] = $assoc['dtype'];
|
||||
$list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']);
|
||||
$list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']);
|
||||
$list[$assoc['company_id']]['company_name'][] = $assoc['company_name'];
|
||||
$list[$assoc['company_id']]['company_id'][] = $assoc['company_id'];
|
||||
$list[$assoc['company_id']]['drate'][] = $assoc['rate'];
|
||||
$list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
|
||||
$list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
|
||||
|
||||
$list[$assoc['company_id']]['facid'][] = $assoc['facid'];
|
||||
$list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
|
||||
$list[$assoc['company_id']]['type'][] = $assoc['type'];
|
||||
$list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
|
||||
$list[$assoc['company_id']]['descr'][] = $assoc['descr'];
|
||||
|
||||
$list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
|
||||
$list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
|
||||
$list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
|
||||
$list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2'];
|
||||
|
||||
$list[$assoc['company_id']]['pid'][] = $assoc['pid'];
|
||||
$list[$assoc['company_id']]['pref'][] = $assoc['pref'];
|
||||
$list[$assoc['company_id']]['ptype'][] = $assoc['ptype'];
|
||||
|
||||
$list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
|
||||
$list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
|
||||
|
||||
$company_id = $assoc['company_id'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// CASE OF EXPENSE REPORT
|
||||
|
||||
if ($direction == 'buy') // buy only for expense reports
|
||||
{
|
||||
// Define sql request
|
||||
$sql='';
|
||||
|
||||
// Count on payments date
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
|
||||
$sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
|
||||
$sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
|
||||
$sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
|
||||
$sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
|
||||
$sql.= " WHERE e.entity = " . $conf->entity;
|
||||
$sql.= " AND e.fk_statut in (6)";
|
||||
if ($y && $m)
|
||||
{
|
||||
$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
|
||||
$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
|
||||
}
|
||||
else if ($y)
|
||||
{
|
||||
$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
|
||||
$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
|
||||
}
|
||||
if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
|
||||
if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = -1";
|
||||
$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
|
||||
$sql.= " ORDER BY e.rowid";
|
||||
|
||||
if (! $sql)
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
|
||||
return -1; // -1 = Not accountancy module enabled
|
||||
}
|
||||
if ($sql == 'TODO') return -2; // -2 = Feature not yet available
|
||||
if ($sql != 'TODO')
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$company_id = -1;
|
||||
$oldrowid='';
|
||||
while($assoc = $db->fetch_array($resql))
|
||||
{
|
||||
if (! isset($list[$assoc['company_id']]['totalht'])) $list[$assoc['company_id']]['totalht']=0;
|
||||
if (! isset($list[$assoc['company_id']]['vat'])) $list[$assoc['company_id']]['vat']=0;
|
||||
if (! isset($list[$assoc['company_id']]['localtax1'])) $list[$assoc['company_id']]['localtax1']=0;
|
||||
if (! isset($list[$assoc['company_id']]['localtax2'])) $list[$assoc['company_id']]['localtax2']=0;
|
||||
|
||||
if ($assoc['rowid'] != $oldrowid) // Si rupture sur d.rowid
|
||||
{
|
||||
$oldrowid=$assoc['rowid'];
|
||||
$list[$assoc['company_id']]['totalht'] += $assoc['total_ht'];
|
||||
$list[$assoc['company_id']]['vat'] += $assoc['total_vat'];
|
||||
$list[$assoc['company_id']]['localtax1'] += $assoc['total_localtax1'];
|
||||
$list[$assoc['company_id']]['localtax2'] += $assoc['total_localtax2'];
|
||||
}
|
||||
|
||||
$list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
|
||||
$list[$assoc['company_id']]['dtype'][] = 'ExpenseReportPayment';
|
||||
$list[$assoc['company_id']]['datef'][] = $assoc['datef'];
|
||||
$list[$assoc['company_id']]['company_name'][] = '';
|
||||
$list[$assoc['company_id']]['company_id'][] = '';
|
||||
$list[$assoc['company_id']]['user_id'][] = $assoc['fk_user_author'];
|
||||
$list[$assoc['company_id']]['drate'][] = $assoc['rate'];
|
||||
$list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
|
||||
$list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
|
||||
|
||||
$list[$assoc['company_id']]['facid'][] = $assoc['facid'];
|
||||
$list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
|
||||
$list[$assoc['company_id']]['type'][] = $assoc['type'];
|
||||
$list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
|
||||
$list[$assoc['company_id']]['descr'][] = $assoc['descr'];
|
||||
|
||||
$list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
|
||||
$list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
|
||||
$list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
|
||||
$list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2'];
|
||||
|
||||
$list[$assoc['company_id']]['pid'][] = $assoc['pid'];
|
||||
$list[$assoc['company_id']]['pref'][] = $assoc['pref'];
|
||||
$list[$assoc['company_id']]['ptype'][] = 'ExpenseReportPayment';
|
||||
|
||||
$list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
|
||||
$list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
|
||||
|
||||
$company_id = $assoc['company_id'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,19 +551,19 @@ function vat_by_thirdparty($db, $y, $date_start, $date_end, $modetax, $direction
|
||||
* @param int $q Quarter
|
||||
* @param string $date_start Start date
|
||||
* @param string $date_end End date
|
||||
* @param int $modetax 0 or 1 (option vat on debit)
|
||||
* @param int $modetax Not used
|
||||
* @param int $direction 'sell' (customer invoice) or 'buy' (supplier invoices)
|
||||
* @param int $m Month
|
||||
* @return array List of quarters with vat
|
||||
* @return array Array with details of VATs (per rate), -1 if no accountancy module, -2 if not yet developped, -3 if error
|
||||
*/
|
||||
function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
|
||||
function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// If we use date_start and date_end, we must not use $y, $m, $q
|
||||
if (($date_start || $date_end) && (! empty($y) || ! empty($m) || ! empty($q)))
|
||||
{
|
||||
dol_print_error('', 'Bad value of input parameter for tax_by_date');
|
||||
dol_print_error('', 'Bad value of input parameter for tax_by_rate');
|
||||
}
|
||||
|
||||
$list=array();
|
||||
@ -242,6 +602,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
$total_localtax1='total_localtax1';
|
||||
$total_localtax2='total_localtax2';
|
||||
|
||||
|
||||
// CAS DES BIENS/PRODUITS
|
||||
|
||||
// Define sql request
|
||||
@ -280,6 +641,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = 0"; // Limit to products
|
||||
$sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
|
||||
}
|
||||
else
|
||||
@ -320,6 +682,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = 0"; // Limit to products
|
||||
$sql.= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
|
||||
}
|
||||
|
||||
@ -327,7 +690,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
if ($sql == 'TODO') return -2;
|
||||
if ($sql != 'TODO')
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_date", LOG_DEBUG);
|
||||
dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
|
||||
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
@ -425,6 +788,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = 1"; // Limit to services
|
||||
$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture;
|
||||
}
|
||||
else
|
||||
@ -465,18 +829,19 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = 1"; // Limit to services
|
||||
$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
|
||||
$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
|
||||
}
|
||||
|
||||
if (! $sql)
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_date no accountancy module enabled".$sql,LOG_ERR);
|
||||
dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
|
||||
return -1; // -1 = Not accountancy module enabled
|
||||
}
|
||||
if ($sql == 'TODO') return -2; // -2 = Feature not yet available
|
||||
if ($sql != 'TODO')
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_date", LOG_DEBUG);
|
||||
dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -534,8 +899,10 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
}
|
||||
}
|
||||
|
||||
// Expense Report
|
||||
if ($direction == 'buy')
|
||||
|
||||
// CASE OF EXPENSE REPORT
|
||||
|
||||
if ($direction == 'buy') // buy only for expense reports
|
||||
{
|
||||
// Define sql request
|
||||
$sql='';
|
||||
@ -543,7 +910,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
// Count on payments date
|
||||
$sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
|
||||
$sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
|
||||
$sql.= " e.date_debut as date_start, e.date_fin as date_end,";
|
||||
$sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
|
||||
$sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
|
||||
$sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e ";
|
||||
@ -565,17 +932,18 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
|
||||
$sql.= " AND (d.product_type = -1";
|
||||
$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service
|
||||
$sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
|
||||
$sql.= " ORDER BY e.rowid";
|
||||
|
||||
if (! $sql)
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_date no accountancy module enabled".$sql,LOG_ERR);
|
||||
dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
|
||||
return -1; // -1 = Not accountancy module enabled
|
||||
}
|
||||
if ($sql == 'TODO') return -2; // -2 = Feature not yet available
|
||||
if ($sql != 'TODO')
|
||||
{
|
||||
dol_syslog("Tax.lib.php::tax_by_date", LOG_DEBUG);
|
||||
dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -602,6 +970,7 @@ function tax_by_date($type, $db, $y, $q, $date_start, $date_end, $modetax, $dire
|
||||
$list[$assoc['rate']]['datef'][] = $assoc['datef'];
|
||||
$list[$assoc['rate']]['company_name'][] = '';
|
||||
$list[$assoc['rate']]['company_id'][] = '';
|
||||
$list[$assoc['rate']]['user_id'][] = $assoc['fk_user_author'];
|
||||
$list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']);
|
||||
$list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']);
|
||||
|
||||
|
||||
@ -903,7 +903,6 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
|
||||
if ($usemenuhider || empty($leftmenu) || preg_match('/^tax_vat/i',$leftmenu)) $newmenu->add("/compta/tva/quadri_detail.php?leftmenu=tax_vat", $langs->trans("ReportByQuarter"), 2, $user->rights->tax->charges->lire);
|
||||
global $mysoc;
|
||||
|
||||
//Local Taxes
|
||||
//Local Taxes 1
|
||||
if($mysoc->useLocalTax(1) && (isset($mysoc->localtax1_assuj) && $mysoc->localtax1_assuj=="1"))
|
||||
{
|
||||
|
||||
@ -171,6 +171,7 @@ LT1ReportByCustomersES=Report by third party RE
|
||||
LT2ReportByCustomersES=Report by third party IRPF
|
||||
VATReport=Sale tax report
|
||||
VATReportByPeriods=Sale tax report by period
|
||||
VATReportByThirdParties=Sale tax report by third parties
|
||||
VATReportByCustomers=Sale tax report by customer
|
||||
VATReportByCustomersInInputOutputMode=Report by the customer VAT collected and paid
|
||||
VATReportByQuartersInInputOutputMode=Report by Sale tax rate of the tax collected and paid
|
||||
|
||||
Loading…
Reference in New Issue
Block a user