|
@@ -3,7 +3,8 @@
|
|
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
|
|
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
|
* Copyright (C) 2006-2007 Yannick Warnier <ywarnier@beeznest.org>
|
|
|
- * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
|
|
|
+ * Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
|
|
|
+ * Copyright (C) 2016 Alexandre Spangaro <aspangaro@zendsi.com>
|
|
|
*
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
@@ -36,11 +37,14 @@ 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->load("bills");
|
|
|
$langs->load("compta");
|
|
|
$langs->load("companies");
|
|
|
$langs->load("products");
|
|
|
+$langs->load("trips");
|
|
|
$langs->load("other");
|
|
|
|
|
|
// Date range
|
|
@@ -111,9 +115,11 @@ $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"),"");
|
|
|
|
|
@@ -149,16 +155,26 @@ if ($modetax==1) // Calculate on invoice for goods and services
|
|
|
$builddate=time();
|
|
|
//$exportlink=$langs->trans("NotYetAvailable");
|
|
|
|
|
|
+ // Customers invoices
|
|
|
$elementcust=$langs->trans("CustomersInvoices");
|
|
|
$productcust=$langs->trans("ProductOrService");
|
|
|
$amountcust=$langs->trans("AmountHT");
|
|
|
$vatcust=$langs->trans("VATReceived");
|
|
|
if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
|
|
|
+
|
|
|
+ // Suppliers invoices
|
|
|
$elementsup=$langs->trans("SuppliersInvoices");
|
|
|
$productsup=$langs->trans("ProductOrService");
|
|
|
$amountsup=$langs->trans("AmountHT");
|
|
|
$vatsup=$langs->trans("VATPaid");
|
|
|
if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
|
|
|
+
|
|
|
+ // Expense reports
|
|
|
+ $elementexpensereport=$langs->trans("ExpenseReports");
|
|
|
+ $fees=$langs->trans("Fees");
|
|
|
+ $amountexpensereport=$langs->trans("AmountHT");
|
|
|
+ $vatexpensereport=$langs->trans("VATPaid");
|
|
|
+ if ($mysoc->tva_assuj) $vatexpensereport.=' ('.$langs->trans("ToGetBack").')';
|
|
|
}
|
|
|
if ($modetax==0) // Invoice for goods, payment for services
|
|
|
{
|
|
@@ -185,26 +201,35 @@ if ($modetax==0) // Invoice for goods, payment for services
|
|
|
$builddate=time();
|
|
|
//$exportlink=$langs->trans("NotYetAvailable");
|
|
|
|
|
|
+ // Customers invoices
|
|
|
$elementcust=$langs->trans("CustomersInvoices");
|
|
|
$productcust=$langs->trans("ProductOrService");
|
|
|
$amountcust=$langs->trans("AmountHT");
|
|
|
$vatcust=$langs->trans("VATReceived");
|
|
|
if ($mysoc->tva_assuj) $vatcust.=' ('.$langs->trans("ToPay").')';
|
|
|
+
|
|
|
+ // Suppliers invoices
|
|
|
$elementsup=$langs->trans("SuppliersInvoices");
|
|
|
$productsup=$langs->trans("ProductOrService");
|
|
|
$amountsup=$langs->trans("AmountHT");
|
|
|
$vatsup=$langs->trans("VATPaid");
|
|
|
if ($mysoc->tva_assuj) $vatsup.=' ('.$langs->trans("ToGetBack").')';
|
|
|
+
|
|
|
+ // Expense reports
|
|
|
+ $elementexpensereport=$langs->trans("ExpenseReports");
|
|
|
+ $fees=$langs->trans("Fees");
|
|
|
+ $amountexpensereport=$langs->trans("AmountHT");
|
|
|
+ $vatexpensereport=$langs->trans("VATPaid");
|
|
|
+ if ($mysoc->tva_assuj) $vatexpensereport.=' ('.$langs->trans("ToGetBack").')';
|
|
|
}
|
|
|
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,array(),$calcmode);
|
|
|
|
|
|
$vatcust=$langs->trans("VATReceived");
|
|
|
$vatsup=$langs->trans("VATPaid");
|
|
|
-
|
|
|
+$vatexpensereport=$langs->trans("VATPaid");
|
|
|
|
|
|
// VAT Received and paid
|
|
|
-
|
|
|
-echo '<table class="noborder" width="100%">';
|
|
|
+print '<table class="noborder" width="100%">';
|
|
|
|
|
|
$y = $year_current;
|
|
|
$total = 0;
|
|
@@ -242,21 +267,21 @@ else
|
|
|
$invoice_customer->ref=$x_coll[$my_coll_rate]['facnum'][$id];
|
|
|
$invoice_customer->type=$x_coll[$my_coll_rate]['type'][$id];
|
|
|
$x_both[$my_coll_rate]['coll']['detail'][] = array(
|
|
|
- 'id' =>$x_coll[$my_coll_rate]['facid'][$id],
|
|
|
- 'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
|
|
|
- 'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
|
|
|
- 'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
|
|
|
- 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
|
|
|
- 'payment_id'=>$x_coll[$my_coll_rate]['payment_id'][$id],
|
|
|
+ 'id' =>$x_coll[$my_coll_rate]['facid'][$id],
|
|
|
+ 'descr' =>$x_coll[$my_coll_rate]['descr'][$id],
|
|
|
+ 'pid' =>$x_coll[$my_coll_rate]['pid'][$id],
|
|
|
+ 'pref' =>$x_coll[$my_coll_rate]['pref'][$id],
|
|
|
+ 'ptype' =>$x_coll[$my_coll_rate]['ptype'][$id],
|
|
|
+ 'payment_id' =>$x_coll[$my_coll_rate]['payment_id'][$id],
|
|
|
'payment_amount'=>$x_coll[$my_coll_rate]['payment_amount'][$id],
|
|
|
- 'ftotal_ttc'=>$x_coll[$my_coll_rate]['ftotal_ttc'][$id],
|
|
|
- 'dtotal_ttc'=>$x_coll[$my_coll_rate]['dtotal_ttc'][$id],
|
|
|
- 'dtype' =>$x_coll[$my_coll_rate]['dtype'][$id],
|
|
|
- 'ddate_start'=>$x_coll[$my_coll_rate]['ddate_start'][$id],
|
|
|
- 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
|
|
|
- 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
|
|
|
- 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
|
|
|
- 'link' =>$invoice_customer->getNomUrl(1,'',12));
|
|
|
+ '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],
|
|
|
+ 'ddate_start' =>$x_coll[$my_coll_rate]['ddate_start'][$id],
|
|
|
+ 'ddate_end' =>$x_coll[$my_coll_rate]['ddate_end'][$id],
|
|
|
+ 'totalht' =>$x_coll[$my_coll_rate]['totalht_list'][$id],
|
|
|
+ 'vat' =>$x_coll[$my_coll_rate]['vat_list'][$id],
|
|
|
+ 'link' =>$invoice_customer->getNomUrl(1,'',12));
|
|
|
}
|
|
|
}
|
|
|
// tva paid
|
|
@@ -276,21 +301,21 @@ else
|
|
|
$invoice_supplier->ref=$x_paye[$my_paye_rate]['facnum'][$id];
|
|
|
$invoice_supplier->type=$x_paye[$my_paye_rate]['type'][$id];
|
|
|
$x_both[$my_paye_rate]['paye']['detail'][] = array(
|
|
|
- 'id' =>$x_paye[$my_paye_rate]['facid'][$id],
|
|
|
- 'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
|
|
|
- 'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
|
|
|
- 'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
|
|
|
- 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
|
|
|
- 'payment_id'=>$x_paye[$my_paye_rate]['payment_id'][$id],
|
|
|
+ 'id' =>$x_paye[$my_paye_rate]['facid'][$id],
|
|
|
+ 'descr' =>$x_paye[$my_paye_rate]['descr'][$id],
|
|
|
+ 'pid' =>$x_paye[$my_paye_rate]['pid'][$id],
|
|
|
+ 'pref' =>$x_paye[$my_paye_rate]['pref'][$id],
|
|
|
+ 'ptype' =>$x_paye[$my_paye_rate]['ptype'][$id],
|
|
|
+ 'payment_id' =>$x_paye[$my_paye_rate]['payment_id'][$id],
|
|
|
'payment_amount'=>$x_paye[$my_paye_rate]['payment_amount'][$id],
|
|
|
- 'ftotal_ttc'=>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
|
|
|
- 'dtotal_ttc'=>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
|
|
|
- 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
|
|
|
- 'ddate_start'=>$x_paye[$my_paye_rate]['ddate_start'][$id],
|
|
|
- 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
|
|
|
- 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
|
|
|
- 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
|
|
|
- 'link' =>$invoice_supplier->getNomUrl(1,'',12));
|
|
|
+ 'ftotal_ttc' =>price2num($x_paye[$my_paye_rate]['ftotal_ttc'][$id]),
|
|
|
+ 'dtotal_ttc' =>price2num($x_paye[$my_paye_rate]['dtotal_ttc'][$id]),
|
|
|
+ 'dtype' =>$x_paye[$my_paye_rate]['dtype'][$id],
|
|
|
+ 'ddate_start' =>$x_paye[$my_paye_rate]['ddate_start'][$id],
|
|
|
+ 'ddate_end' =>$x_paye[$my_paye_rate]['ddate_end'][$id],
|
|
|
+ 'totalht' =>price2num($x_paye[$my_paye_rate]['totalht_list'][$id]),
|
|
|
+ 'vat' =>$x_paye[$my_paye_rate]['vat_list'][$id],
|
|
|
+ 'link' =>$invoice_supplier->getNomUrl(1,'',12));
|
|
|
}
|
|
|
}
|
|
|
//now we have an array (x_both) indexed by rates for coll and paye
|
|
@@ -320,18 +345,18 @@ else
|
|
|
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 $rate)
|
|
|
{
|
|
|
$subtot_coll_total_ht = 0;
|
|
@@ -625,6 +650,156 @@ else
|
|
|
print '</tr>';
|
|
|
}
|
|
|
|
|
|
+ // Blank line
|
|
|
+ print '<tr><td colspan="'.($span+1).'"> </td></tr>';
|
|
|
+
|
|
|
+ // Expense reports
|
|
|
+ print '<tr class="liste_titre liste_titre_topborder">';
|
|
|
+ print '<td align="left">'.$elementexpensereport.'</td>';
|
|
|
+ print '<td align="left">'.$fees.'</td>';
|
|
|
+ if ($modetax == 0)
|
|
|
+ {
|
|
|
+ print '<td align="right">'.$amountexpensereport.'</td>';
|
|
|
+ print '<td align="right">'.$langs->trans("Payment").' ('.$langs->trans("PercentOfInvoice").')</td>';
|
|
|
+ }
|
|
|
+ print '<td align="right">'.$langs->trans("AmountHTVATRealPaid").'</td>';
|
|
|
+ print '<td align="right">'.$vatexpensereport.'</td>';
|
|
|
+ print '</tr>'."\n";
|
|
|
+
|
|
|
+ foreach(array_keys($x_paye) as $rate)
|
|
|
+ {
|
|
|
+ $subtot_paye_total_ht = 0;
|
|
|
+ $subtot_paye_vat = 0;
|
|
|
+
|
|
|
+ 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.'"></td>';
|
|
|
+ print '</tr>'."\n";
|
|
|
+ foreach($x_both[$rate]['paye']['detail'] as $index=>$fields)
|
|
|
+ {
|
|
|
+ // 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;
|
|
|
+
|
|
|
+ $var=!$var;
|
|
|
+ print '<tr '.$bc[$var].'>';
|
|
|
+
|
|
|
+ // Ref
|
|
|
+ print '<td class="nowrap" align="left">'.$fields['link'].'</td>';
|
|
|
+
|
|
|
+ // Description
|
|
|
+ print '<td align="left">';
|
|
|
+ if ($fields['pid'])
|
|
|
+ {
|
|
|
+ $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);
|
|
|
+
|
|
|
+ // 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 $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");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print price($fields['payment_amount']);
|
|
|
+ if (isset($fields['payment_amount'])) print ' ('.round($ratiopaymentinvoice*100,2).'%)';
|
|
|
+ }
|
|
|
+ print '</td>';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 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'),1);
|
|
|
+ print '</td>';
|
|
|
+
|
|
|
+ // VAT
|
|
|
+ print '<td class="nowrap" align="right">';
|
|
|
+ $temp_vat=$fields['vat'];
|
|
|
+ if ($type == 1) $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> </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>';
|
|
|
+ }
|
|
|
+
|
|
|
+ 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>';
|
|
|
+ }
|
|
|
+
|
|
|
print '</table>';
|
|
|
|
|
|
// Total to pay
|