30 require 
'../../main.inc.php';
 
   31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/report.lib.php';
 
   32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/tax.lib.php';
 
   33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
 
   34 require_once DOL_DOCUMENT_ROOT.
'/compta/tva/class/tva.class.php';
 
   35 require_once DOL_DOCUMENT_ROOT.
'/compta/localtax/class/localtax.class.php';
 
   36 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
 
   37 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
 
   38 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
 
   39 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
 
   40 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
 
   41 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
 
   42 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/paymentexpensereport.class.php';
 
   45 $langs->loadLangs(array(
"other", 
"compta", 
"banks", 
"bills", 
"companies", 
"product", 
"trips", 
"admin"));
 
   47 include DOL_DOCUMENT_ROOT.
'/compta/tva/initdatesforvat.inc.php';
 
   56 $modetax = (empty($conf->global->TAX_MODE) ? 0 : $conf->global->TAX_MODE);
 
   60 if (empty($modetax)) {
 
   67   $socid = $user->socid;
 
   78 $company_static = 
new Societe($db);
 
   79 $invoice_customer = 
new Facture($db);
 
   82 $product_static = 
new Product($db);
 
   86 $user_static = 
new User($db);
 
   88 $morequerystring = 
'';
 
   89 $listofparams = array(
'date_startmonth', 
'date_startyear', 
'date_startday', 
'date_endmonth', 
'date_endyear', 
'date_endday');
 
   90 foreach ($listofparams as $param) {
 
   92     $morequerystring .= ($morequerystring ? 
'&' : 
'').$param.
'='.
GETPOST($param);
 
   96 $special_report = 
false;
 
   97 if (isset($_REQUEST[
'extra_report']) && $_REQUEST[
'extra_report'] == 1) {
 
   98   $special_report = 
true;
 
  101 llxHeader(
'', $langs->trans(
"VATReport"), 
'', 
'', 0, 0, 
'', 
'', $morequerystring);
 
  103 $fsearch = 
'<!-- hidden fields for form -->';
 
  104 $fsearch .= 
'<input type="hidden" name="token" value="'.newToken().
'">';
 
  105 $fsearch .= 
'<input type="hidden" name="modetax" value="'.$modetax.
'">';
 
  106 $fsearch .= $langs->trans(
"SalesTurnoverMinimum").
': ';
 
  107 $fsearch .= 
'<input type="text" name="min" id="min" value="'.$min.
'" size="6">';
 
  110 $name = $langs->trans(
"VATReportByThirdParties");
 
  113   $calcmode = $langs->trans(
'OptionVATDefault');
 
  116   $calcmode = $langs->trans(
'OptionVATDebitOption');
 
  119   $calcmode = $langs->trans(
'OptionPaymentForProductAndServices');
 
  121 $calcmode .= 
' <span class="opacitymedium">('.$langs->trans(
"TaxModuleSetupToModifyRules", DOL_URL_ROOT.
'/admin/taxes.php').
')</span>';
 
  123 $period = 
$form->selectDate($date_start, 
'date_start', 0, 0, 0, 
'', 1, 0).
' - '.
$form->selectDate($date_end, 
'date_end', 0, 0, 0, 
'', 1, 0);
 
  124 $prevyear = $date_start_year;
 
  126 if ($prevquarter > 1) {
 
  132 $nextyear = $date_start_year;
 
  134 if ($nextquarter < 4) {
 
  142 if ($conf->global->TAX_MODE_SELL_PRODUCT == 
'invoice') {
 
  143   $description .= $langs->trans(
"RulesVATDueProducts");
 
  145 if ($conf->global->TAX_MODE_SELL_PRODUCT == 
'payment') {
 
  146   $description .= $langs->trans(
"RulesVATInProducts");
 
  148 if ($conf->global->TAX_MODE_SELL_SERVICE == 
'invoice') {
 
  149   $description .= 
'<br>'.$langs->trans(
"RulesVATDueServices");
 
  151 if ($conf->global->TAX_MODE_SELL_SERVICE == 
'payment') {
 
  152   $description .= 
'<br>'.$langs->trans(
"RulesVATInServices");
 
  154 if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
 
  155   $description .= 
'<br>'.$langs->trans(
"DepositsAreNotIncluded");
 
  157 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
 
  158   $description .= $langs->trans(
"SupplierDepositsAreNotIncluded");
 
  160 if (!empty($conf->global->MAIN_MODULE_ACCOUNTING)) {
 
  161   $description .= 
'<br>'.$langs->trans(
"ThisIsAnEstimatedValue");
 
  165 $description .= ($description ? 
'<br>' : 
'').$fsearch;
 
  166 if (!empty($conf->global->TAX_REPORT_EXTRA_REPORT)) {
 
  167   $description .= 
'<br>';
 
  168   $description .= 
'<input type="radio" name="extra_report" value="0" '.($special_report ? 
'' : 
'checked="checked"').
'> ';
 
  169   $description .= $langs->trans(
'SimpleReport');
 
  170   $description .= 
'</input>';
 
  171   $description .= 
'<br>';
 
  172   $description .= 
'<input type="radio" name="extra_report" value="1" '.($special_report ? 
'checked="checked"' : 
'').
'> ';
 
  173   $description .= $langs->trans(
'AddExtraReport');
 
  174   $description .= 
'</input>';
 
  175   $description .= 
'<br>';
 
  178 $elementcust = $langs->trans(
"CustomersInvoices");
 
  179 $productcust = $langs->trans(
"Description");
 
  180 $namerate = $langs->trans(
"VATRate");
 
  181 $amountcust = $langs->trans(
"AmountHT");
 
  182 if ($mysoc->tva_assuj) {
 
  183   $vatcust .= 
' ('.$langs->trans(
"StatusToPay").
')';
 
  185 $elementsup = $langs->trans(
"SuppliersInvoices");
 
  186 $productsup = $langs->trans(
"Description");
 
  187 $amountsup = $langs->trans(
"AmountHT");
 
  188 if ($mysoc->tva_assuj) {
 
  189   $vatsup .= 
' ('.$langs->trans(
"ToGetBack").
')';
 
  191 report_header($name, 
'', $period, $periodlink, $description, $builddate, $exportlink, array(), $calcmode);
 
  193 $vatcust = $langs->trans(
"VATReceived");
 
  194 $vatsup = $langs->trans(
"VATPaid");
 
  198 print 
'<div class="div-table-responsive">';
 
  199 print 
"<table class=\"noborder\" width=\"100%\">";
 
  211 $x_coll = 
tax_by_thirdparty(
'vat', $db, 0, $date_start, $date_end, $modetax, 
'sell');
 
  212 $x_paye = 
tax_by_thirdparty(
'vat', $db, 0, $date_start, $date_end, $modetax, 
'buy');
 
  214 if (!is_array($x_coll) || !is_array($x_paye)) {
 
  215   $langs->load(
"errors");
 
  217     print 
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"ErrorNoAccountancyModuleLoaded").
'</td></tr>';
 
  218   } elseif ($x_coll == -2) {
 
  219     print 
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"FeatureNotYetAvailable").
'</td></tr>';
 
  221     print 
'<tr><td colspan="'.$columns.
'">'.$langs->trans(
"Error").
'</td></tr>';
 
  226   foreach (array_keys($x_coll) as $my_coll_thirdpartyid) {
 
  227     $x_both[$my_coll_thirdpartyid][
'coll'][
'totalht'] = $x_coll[$my_coll_thirdpartyid][
'totalht'];
 
  228     $x_both[$my_coll_thirdpartyid][
'coll'][
'vat'] = $x_coll[$my_coll_thirdpartyid][
'vat'];
 
  229     $x_both[$my_coll_thirdpartyid][
'paye'][
'totalht'] = 0;
 
  230     $x_both[$my_coll_thirdpartyid][
'paye'][
'vat'] = 0;
 
  231     $x_both[$my_coll_thirdpartyid][
'coll'][
'links'] = 
'';
 
  232     $x_both[$my_coll_thirdpartyid][
'coll'][
'detail'] = array();
 
  233     foreach ($x_coll[$my_coll_thirdpartyid][
'facid'] as $id => $dummy) {
 
  234       $invoice_customer->id = $x_coll[$my_coll_thirdpartyid][
'facid'][$id];
 
  235       $invoice_customer->ref = $x_coll[$my_coll_thirdpartyid][
'facnum'][$id];
 
  236       $invoice_customer->type = $x_coll[$my_coll_thirdpartyid][
'type'][$id];
 
  239       $company_static->id = $x_coll[$my_coll_thirdpartyid][
'company_id'][$id];
 
  240       $company_static->name = $x_coll[$my_coll_thirdpartyid][
'company_name'][$id];
 
  241       $company_static->name_alias = $x_coll[$my_coll_thirdpartyid][
'company_alias'][$id];
 
  242       $company_static->email = $x_coll[$my_coll_thirdpartyid][
'company_email'][$id];
 
  243       $company_static->tva_intra = $x_coll[$my_coll_thirdpartyid][
'tva_intra'][$id];
 
  244       $company_static->client = $x_coll[$my_coll_thirdpartyid][
'company_client'][$id];
 
  245       $company_static->fournisseur = $x_coll[$my_coll_thirdpartyid][
'company_fournisseur'][$id];
 
  246       $company_static->status = $x_coll[$my_coll_thirdpartyid][
'company_status'][$id];
 
  247       $company_static->code_client = $x_coll[$my_coll_thirdpartyid][
'company_customer_code'][$id];
 
  248       $company_static->code_compta_client = $x_coll[$my_coll_thirdpartyid][
'company_customer_accounting_code'][$id];
 
  249       $company_static->code_fournisseur = $x_coll[$my_coll_thirdpartyid][
'company_supplier_code'][$id];
 
  250       $company_static->code_compta_fournisseur = $x_coll[$my_coll_thirdpartyid][
'company_supplier_accounting_code'][$id];
 
  252       $x_both[$my_coll_thirdpartyid][
'coll'][
'detail'][] = array(
 
  253         'id'        =>$x_coll[$my_coll_thirdpartyid][
'facid'][$id],
 
  254         'descr'     =>$x_coll[$my_coll_thirdpartyid][
'descr'][$id],
 
  256         'pid'       =>$x_coll[$my_coll_thirdpartyid][
'pid'][$id],
 
  257         'pref'      =>$x_coll[$my_coll_thirdpartyid][
'pref'][$id],
 
  258         'ptype'     =>$x_coll[$my_coll_thirdpartyid][
'ptype'][$id],
 
  259         'pstatus'   =>$x_paye[$my_coll_thirdpartyid][
'pstatus'][$id],
 
  260         'pstatusbuy'=>$x_paye[$my_coll_thirdpartyid][
'pstatusbuy'][$id],
 
  262         'payment_id'=>$x_coll[$my_coll_thirdpartyid][
'payment_id'][$id],
 
  263         'payment_ref'=>$x_coll[$my_coll_thirdpartyid][
'payment_ref'][$id],
 
  264         'payment_amount'=>$x_coll[$my_coll_thirdpartyid][
'payment_amount'][$id],
 
  265         'ftotal_ttc'=>$x_coll[$my_coll_thirdpartyid][
'ftotal_ttc'][$id],
 
  266         'dtotal_ttc'=>$x_coll[$my_coll_thirdpartyid][
'dtotal_ttc'][$id],
 
  267         'dtype'     =>$x_coll[$my_coll_thirdpartyid][
'dtype'][$id],
 
  268         'drate'     =>$x_coll[$my_coll_thirdpartyid][
'drate'][$id],
 
  269         'datef'     =>$x_coll[$my_coll_thirdpartyid][
'datef'][$id],
 
  270         'datep'     =>$x_coll[$my_coll_thirdpartyid][
'datep'][$id],
 
  272         'company_link'=>$company_static->getNomUrl(1, 
'', 20),
 
  274         'ddate_start'=>$x_coll[$my_coll_thirdpartyid][
'ddate_start'][$id],
 
  275         'ddate_end'  =>$x_coll[$my_coll_thirdpartyid][
'ddate_end'][$id],
 
  276         'totalht'   =>$x_coll[$my_coll_thirdpartyid][
'totalht_list'][$id],
 
  277         'vat'       =>$x_coll[$my_coll_thirdpartyid][
'vat_list'][$id],
 
  278         'link'      =>$invoice_customer->getNomUrl(1, 
'', 12)
 
  283   foreach (array_keys($x_paye) as $my_paye_thirdpartyid) {
 
  284     $x_both[$my_paye_thirdpartyid][
'paye'][
'totalht'] = $x_paye[$my_paye_thirdpartyid][
'totalht'];
 
  285     $x_both[$my_paye_thirdpartyid][
'paye'][
'vat'] = $x_paye[$my_paye_thirdpartyid][
'vat'];
 
  286     if (!isset($x_both[$my_paye_thirdpartyid][
'coll'][
'totalht'])) {
 
  287       $x_both[$my_paye_thirdpartyid][
'coll'][
'totalht'] = 0;
 
  288       $x_both[$my_paye_thirdpartyid][
'coll'][
'vat'] = 0;
 
  290     $x_both[$my_paye_thirdpartyid][
'paye'][
'links'] = 
'';
 
  291     $x_both[$my_paye_thirdpartyid][
'paye'][
'detail'] = array();
 
  293     foreach ($x_paye[$my_paye_thirdpartyid][
'facid'] as $id => $dummy) {
 
  295       if ($x_paye[$my_paye_thirdpartyid][
'ptype'][$id] == 
'ExpenseReportPayment') {
 
  296         $expensereport->id = $x_paye[$my_paye_thirdpartyid][
'facid'][$id];
 
  297         $expensereport->ref = $x_paye[$my_paye_thirdpartyid][
'facnum'][$id];
 
  298         $expensereport->type = $x_paye[$my_paye_thirdpartyid][
'type'][$id];
 
  300         $x_both[$my_paye_thirdpartyid][
'paye'][
'detail'][] = array(
 
  301           'id'        =>$x_paye[$my_paye_thirdpartyid][
'facid'][$id],
 
  302           'descr'       =>$x_paye[$my_paye_thirdpartyid][
'descr'][$id],
 
  304           'pid'       =>$x_paye[$my_paye_thirdpartyid][
'pid'][$id],
 
  305           'pref'        =>$x_paye[$my_paye_thirdpartyid][
'pref'][$id],
 
  306           'ptype'       =>$x_paye[$my_paye_thirdpartyid][
'ptype'][$id],
 
  307           'pstatus'           =>$x_paye[$my_paye_thirdpartyid][
'pstatus'][$id],
 
  308           'pstatusbuy'        =>$x_paye[$my_paye_thirdpartyid][
'pstatusbuy'][$id],
 
  310           'payment_id'    =>$x_paye[$my_paye_thirdpartyid][
'payment_id'][$id],
 
  311           'payment_ref'   =>$x_paye[$my_paye_thirdpartyid][
'payment_ref'][$id],
 
  312           'payment_amount'  =>$x_paye[$my_paye_thirdpartyid][
'payment_amount'][$id],
 
  313           'ftotal_ttc'    =>
price2num($x_paye[$my_paye_thirdpartyid][
'ftotal_ttc'][$id]),
 
  314           'dtotal_ttc'    =>
price2num($x_paye[$my_paye_thirdpartyid][
'dtotal_ttc'][$id]),
 
  315           'dtype'       =>$x_paye[$my_paye_thirdpartyid][
'dtype'][$id],
 
  316           'drate'             =>$x_paye[$my_coll_thirdpartyid][
'drate'][$id],
 
  317           'ddate_start'   =>$x_paye[$my_paye_thirdpartyid][
'ddate_start'][$id],
 
  318           'ddate_end'     =>$x_paye[$my_paye_thirdpartyid][
'ddate_end'][$id],
 
  319           'totalht'     =>
price2num($x_paye[$my_paye_thirdpartyid][
'totalht_list'][$id]),
 
  320           'vat'       =>$x_paye[$my_paye_thirdpartyid][
'vat_list'][$id],
 
  321           'link'        =>$expensereport->getNomUrl(1)
 
  324         $invoice_supplier->id = $x_paye[$my_paye_thirdpartyid][
'facid'][$id];
 
  325         $invoice_supplier->ref = $x_paye[$my_paye_thirdpartyid][
'facnum'][$id];
 
  326         $invoice_supplier->type = $x_paye[$my_paye_thirdpartyid][
'type'][$id];
 
  329         $company_static->id = $x_paye[$my_paye_thirdpartyid][
'company_id'][$id];
 
  330         $company_static->name = $x_paye[$my_paye_thirdpartyid][
'company_name'][$id];
 
  331         $company_static->name_alias = $x_paye[$my_paye_thirdpartyid][
'company_alias'][$id];
 
  332         $company_static->email = $x_paye[$my_paye_thirdpartyid][
'company_email'][$id];
 
  333         $company_static->tva_intra = $x_paye[$my_paye_thirdpartyid][
'tva_intra'][$id];
 
  334         $company_static->client = $x_paye[$my_paye_thirdpartyid][
'company_client'][$id];
 
  335         $company_static->fournisseur = $x_paye[$my_paye_thirdpartyid][
'company_fournisseur'][$id];
 
  336         $company_static->status = $x_paye[$my_paye_thirdpartyid][
'company_status'][$id];
 
  337         $company_static->code_client = $x_paye[$my_paye_thirdpartyid][
'company_customer_code'][$id];
 
  338         $company_static->code_compta_client = $x_paye[$my_paye_thirdpartyid][
'company_customer_accounting_code'][$id];
 
  339         $company_static->code_fournisseur = $x_paye[$my_paye_thirdpartyid][
'company_supplier_code'][$id];
 
  340         $company_static->code_compta_fournisseur = $x_paye[$my_paye_thirdpartyid][
'company_supplier_accounting_code'][$id];
 
  342         $x_both[$my_paye_thirdpartyid][
'paye'][
'detail'][] = array(
 
  343           'id'        =>$x_paye[$my_paye_thirdpartyid][
'facid'][$id],
 
  344           'descr'     =>$x_paye[$my_paye_thirdpartyid][
'descr'][$id],
 
  346           'pid'       =>$x_paye[$my_paye_thirdpartyid][
'pid'][$id],
 
  347           'pref'      =>$x_paye[$my_paye_thirdpartyid][
'pref'][$id],
 
  348           'ptype'     =>$x_paye[$my_paye_thirdpartyid][
'ptype'][$id],
 
  349           'pstatus'   =>$x_paye[$my_paye_thirdpartyid][
'pstatus'][$id],
 
  350           'pstatusbuy'=>$x_paye[$my_paye_thirdpartyid][
'pstatusbuy'][$id],
 
  352           'payment_id'=>$x_paye[$my_paye_thirdpartyid][
'payment_id'][$id],
 
  353           'payment_ref'=>$x_paye[$my_paye_thirdpartyid][
'payment_ref'][$id],
 
  354           'payment_amount'=>$x_paye[$my_paye_thirdpartyid][
'payment_amount'][$id],
 
  355           'ftotal_ttc'=>
price2num($x_paye[$my_paye_thirdpartyid][
'ftotal_ttc'][$id]),
 
  356           'dtotal_ttc'=>
price2num($x_paye[$my_paye_thirdpartyid][
'dtotal_ttc'][$id]),
 
  357           'dtype'     =>$x_paye[$my_paye_thirdpartyid][
'dtype'][$id],
 
  358           'drate'     =>$x_paye[$my_coll_thirdpartyid][
'drate'][$id],
 
  359           'datef'     =>$x_paye[$my_paye_thirdpartyid][
'datef'][$id],
 
  360           'datep'     =>$x_paye[$my_paye_thirdpartyid][
'datep'][$id],
 
  362           'company_link'=>$company_static->getNomUrl(1, 
'', 20),
 
  364           'ddate_start'=>$x_paye[$my_paye_thirdpartyid][
'ddate_start'][$id],
 
  365           'ddate_end'  =>$x_paye[$my_paye_thirdpartyid][
'ddate_end'][$id],
 
  366           'totalht'   =>
price2num($x_paye[$my_paye_thirdpartyid][
'totalht_list'][$id]),
 
  367           'vat'       =>$x_paye[$my_paye_thirdpartyid][
'vat_list'][$id],
 
  368           'link'      =>$invoice_supplier->getNomUrl(1, 
'', 12)
 
  386   print 
'<tr class="liste_titre">';
 
  387   print 
'<td class="left">'.$elementcust.
'</td>';
 
  388   print 
'<td class="left">'.$langs->trans(
"DateInvoice").
'</td>';
 
  389   if ($conf->global->TAX_MODE_SELL_PRODUCT == 
'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 
'payment') {
 
  390     print 
'<td class="left">'.$langs->trans(
"DatePayment").
'</td>';
 
  394   print 
'<td class="right">'.$namerate.
'</td>';
 
  395   print 
'<td class="left">'.$productcust.
'</td>';
 
  397     print 
'<td class="right">'.$amountcust.
'</td>';
 
  398     print 
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
 
  400   print 
'<td class="right">'.$langs->trans(
"AmountHTVATRealReceived").
'</td>';
 
  401   print 
'<td class="right">'.$vatcust.
'</td>';
 
  404   $action = 
"tvadetail";
 
  405   $parameters[
"mode"] = $modetax;
 
  406   $parameters[
"start"] = $date_start;
 
  407   $parameters[
"end"] = $date_end;
 
  408   $parameters[
"type"] = 
'vat';
 
  410   $object = array(&$x_coll, &$x_paye, &$x_both);
 
  412   $hookmanager->initHooks(array(
'externalbalance'));
 
  413   $reshook = $hookmanager->executeHooks(
'addVatLine', $parameters, $object, $action); 
 
  415   foreach (array_keys($x_coll) as $thirdparty_id) {
 
  416     $subtot_coll_total_ht = 0;
 
  417     $subtot_coll_vat = 0;
 
  419     if ($min == 0 || ($min > 0 && $x_both[$thirdparty_id][
'coll'][
'totalht'] > $min)) {
 
  420       if (is_array($x_both[$thirdparty_id][
'coll'][
'detail'])) {
 
  423         print 
'<td class="tax_rate">';
 
  424         if (is_numeric($thirdparty_id)) {
 
  425           $company_static->fetch($thirdparty_id);
 
  426           print $langs->trans(
"ThirdParty").
': '.$company_static->getNomUrl(1);
 
  428           $tmpid = preg_replace(
'/userid_/', 
'', $thirdparty_id);
 
  429           $user_static->fetch($tmpid);
 
  430           print $langs->trans(
"User").
': '.$user_static->getNomUrl(1);
 
  432         print 
'</td><td colspan="'.($span + 1).
'"></td>';
 
  435         foreach ($x_both[$thirdparty_id][
'coll'][
'detail'] as $index => $fields) {
 
  438           $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
 
  441           if (!empty($fields[
'ddate_start'])) {
 
  444           if (!empty($fields[
'ddate_end'])) {
 
  448           print 
'<tr class="oddeven">';
 
  451           print 
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
 
  454           print 
'<td class="left">'.dol_print_date($fields[
'datef'], 
'day').
'</td>';
 
  457           if ($conf->global->TAX_MODE_SELL_PRODUCT == 
'payment' || $conf->global->TAX_MODE_SELL_SERVICE == 
'payment') {
 
  458             print 
'<td class="left">'.dol_print_date($fields[
'datep'], 
'day').
'</td>';
 
  464           print 
'<td class="right">'.$fields[
'drate'].
'</td>';
 
  467           print 
'<td class="left">';
 
  468           if ($fields[
'pid']) {
 
  469             $product_static->id = $fields[
'pid'];
 
  470             $product_static->ref = $fields[
'pref'];
 
  471             $product_static->type = $fields[
'dtype']; 
 
  472             $product_static->status = $fields[
'pstatus'];
 
  473             $product_static->status_buy = $fields[
'pstatusbuy'];
 
  475             print $product_static->getNomUrl(1);
 
  481               $text = 
img_object($langs->trans(
'Service'), 
'service');
 
  483               $text = 
img_object($langs->trans(
'Product'), 
'product');
 
  485             if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
 
  486               if ($reg[1] == 
'DEPOSIT') {
 
  487                 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
 
  488               } elseif ($reg[1] == 
'CREDIT_NOTE') {
 
  489                 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
 
  491                 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
 
  503             print 
'<td class="nowrap right"><span class="amount">';
 
  504             print 
price($fields[
'totalht']);
 
  507               $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
 
  510             print 
'</span></td>';
 
  514           $ratiopaymentinvoice = 1;
 
  516             print 
'<td class="nowrap right">';
 
  518             if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
 
  519               $payment_static->id = $fields[
'payment_id'];
 
  520               $payment_static->ref = $fields[
'payment_ref'];
 
  521               print $payment_static->getNomUrl(2, 
'', 
'', 0).
' ';
 
  523             if (($type == 0 && $conf->global->TAX_MODE_SELL_PRODUCT == 
'invoice')
 
  524               || ($type == 1 && $conf->global->TAX_MODE_SELL_SERVICE == 
'invoice')) {
 
  525                 print $langs->trans(
"NA");
 
  527               if (isset($fields[
'payment_amount']) && 
price2num($fields[
'ftotal_ttc'])) {
 
  528                 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
 
  530               print 
'<span class="amount">'.price(
price2num($fields[
'payment_amount'], 
'MT')).
'</span>';
 
  531               if (isset($fields[
'payment_amount'])) {
 
  532                 print 
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
 
  539           print 
'<td class="nowrap right"><span class="amount">';
 
  540           $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
 
  542           print 
'</span></td>';
 
  545           print 
'<td class="nowrap right"><span class="amount">';
 
  546           $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
 
  549           print 
'</span></td>';
 
  552           $subtot_coll_total_ht += $temp_ht;
 
  553           $subtot_coll_vat += $temp_vat;
 
  554           $x_coll_sum += $temp_vat;
 
  559       print 
'<tr class="liste_total">';
 
  560       print 
'<td colspan="4"></td>';
 
  561       print 
'<td class="right">'.$langs->trans(
"Total").
':</td>';
 
  563         print 
'<td class="nowrap right"> </td>';
 
  564         print 
'<td class="right"> </td>';
 
  566       print 
'<td class="right"><span class="amount">'.price(
price2num($subtot_coll_total_ht, 
'MT')).
'</span></td>';
 
  567       print 
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_coll_vat, 
'MT')).
'</span></td>';
 
  572   if (count($x_coll) == 0) {   
 
  573     print 
'<tr class="liste_total">';
 
  574     print 
'<td colspan="4"></td>';
 
  575     print 
'<td class="right">'.$langs->trans(
"Total").
':</td>';
 
  577       print 
'<td class="nowrap right"> </td>';
 
  578       print 
'<td class="right"> </td>';
 
  580     print 
'<td class="right">'.price(
price2num(0, 
'MT')).
'</td>';
 
  581     print 
'<td class="nowrap right">'.price(
price2num(0, 
'MT')).
'</td>';
 
  586   print 
'<tr><td colspan="'.($span + 1).
'"> </td></tr>';
 
  589   print 
'<tr class="liste_titre liste_titre_topborder">';
 
  590   print 
'<td class="left">'.$elementsup.
'</td>';
 
  591   print 
'<td class="left">'.$langs->trans(
"DateInvoice").
'</td>';
 
  592   if ($conf->global->TAX_MODE_BUY_PRODUCT == 
'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 
'payment') {
 
  593     print 
'<td class="left">'.$langs->trans(
"DatePayment").
'</td>';
 
  597   print 
'<td class="left">'.$namesup.
'</td>';
 
  598   print 
'<td class="left">'.$productsup.
'</td>';
 
  600     print 
'<td class="right">'.$amountsup.
'</td>';
 
  601     print 
'<td class="right">'.$langs->trans(
"Payment").
' ('.$langs->trans(
"PercentOfInvoice").
')</td>';
 
  603   print 
'<td class="right">'.$langs->trans(
"AmountHTVATRealPaid").
'</td>';
 
  604   print 
'<td class="right">'.$vatsup.
'</td>';
 
  607   foreach (array_keys($x_paye) as $thirdparty_id) {
 
  608     $subtot_paye_total_ht = 0;
 
  609     $subtot_paye_vat = 0;
 
  611     if ($min == 0 || ($min > 0 && $x_both[$thirdparty_id][
'paye'][
'totalht'] > $min)) {
 
  612       if (is_array($x_both[$thirdparty_id][
'paye'][
'detail'])) {
 
  614         print 
'<td class="tax_rate">';
 
  615         if (is_numeric($thirdparty_id)) {
 
  616           $company_static->fetch($thirdparty_id);
 
  617           print $langs->trans(
"ThirdParty").
': '.$company_static->getNomUrl(1);
 
  619           $tmpid = preg_replace(
'/userid_/', 
'', $thirdparty_id);
 
  620           $user_static->fetch($tmpid);
 
  621           print $langs->trans(
"User").
': '.$user_static->getNomUrl(1);
 
  623         print 
'<td colspan="'.($span + 1).
'"></td>';
 
  626         foreach ($x_both[$thirdparty_id][
'paye'][
'detail'] as $index => $fields) {
 
  629           $type = (isset($fields[
'dtype']) ? $fields[
'dtype'] : $fields[
'ptype']);
 
  632           if (!empty($fields[
'ddate_start'])) {
 
  635           if (!empty($fields[
'ddate_end'])) {
 
  640           print 
'<tr class="oddeven">';
 
  643           print 
'<td class="nowrap left">'.$fields[
'link'].
'</td>';
 
  646           print 
'<td class="left">'.dol_print_date($fields[
'datef'], 
'day').
'</td>';
 
  649           if ($conf->global->TAX_MODE_BUY_PRODUCT == 
'payment' || $conf->global->TAX_MODE_BUY_SERVICE == 
'payment') {
 
  650             print 
'<td class="left">'.dol_print_date($fields[
'datep'], 
'day').
'</td>';
 
  656           print 
'<td class="tdmaxoverflow150">';
 
  657           print $fields[
'company_link'];
 
  661           print 
'<td class="left">';
 
  662           if ($fields[
'pid']) {
 
  663             $product_static->id = $fields[
'pid'];
 
  664             $product_static->ref = $fields[
'pref'];
 
  665             $product_static->type = $fields[
'dtype']; 
 
  666             print $product_static->getNomUrl(1);
 
  672               $text = 
img_object($langs->trans(
'Service'), 
'service');
 
  674               $text = 
img_object($langs->trans(
'Product'), 
'product');
 
  676             if (preg_match(
'/^\((.*)\)$/', $fields[
'descr'], $reg)) {
 
  677               if ($reg[1] == 
'DEPOSIT') {
 
  678                 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'Deposit');
 
  679               } elseif ($reg[1] == 
'CREDIT_NOTE') {
 
  680                 $fields[
'descr'] = $langs->transnoentitiesnoconv(
'CreditNote');
 
  682                 $fields[
'descr'] = $langs->transnoentitiesnoconv($reg[1]);
 
  694             print 
'<td class="nowrap right"><span class="amount">';
 
  695             print 
price($fields[
'totalht']);
 
  698               $ratiolineinvoice = ($fields[
'dtotal_ttc'] / $fields[
'ftotal_ttc']);
 
  701             print 
'</span></td>';
 
  705           $ratiopaymentinvoice = 1;
 
  707             print 
'<td class="nowrap right">';
 
  708             if ($fields[
'payment_amount'] && $fields[
'ftotal_ttc']) {
 
  709               $paymentfourn_static->id = $fields[
'payment_id'];
 
  710               $paymentfourn_static->ref = $fields[
'payment_ref'];
 
  711               print $paymentfourn_static->getNomUrl(2, 
'', 
'', 0);
 
  714             if (($type == 0 && $conf->global->TAX_MODE_BUY_PRODUCT == 
'invoice')
 
  715               || ($type == 1 && $conf->global->TAX_MODE_BUY_SERVICE == 
'invoice')) {
 
  716               print $langs->trans(
"NA");
 
  718               if (isset($fields[
'payment_amount']) && $fields[
'ftotal_ttc']) {
 
  719                 $ratiopaymentinvoice = ($fields[
'payment_amount'] / $fields[
'ftotal_ttc']);
 
  721               print 
'<span class="amount">'.price(
price2num($fields[
'payment_amount'], 
'MT')).
'</span>';
 
  722               if (isset($fields[
'payment_amount'])) {
 
  723                 print 
' ('.round($ratiopaymentinvoice * 100, 2).
'%)';
 
  730           print 
'<td class="nowrap right"><span class="amount">';
 
  731           $temp_ht = $fields[
'totalht'] * $ratiopaymentinvoice;
 
  733           print 
'</span></td>';
 
  736           print 
'<td class="nowrap right"><span class="amount">';
 
  737           $temp_vat = $fields[
'vat'] * $ratiopaymentinvoice;
 
  740           print 
'</span></td>';
 
  743           $subtot_paye_total_ht += $temp_ht;
 
  744           $subtot_paye_vat += $temp_vat;
 
  745           $x_paye_sum += $temp_vat;
 
  749       print 
'<tr class="liste_total">';
 
  750       print 
'<td colspan="4"></td>';
 
  751       print 
'<td class="right">'.$langs->trans(
"Total").
':</td>';
 
  753         print 
'<td class="nowrap right"> </td>';
 
  754         print 
'<td class="right"> </td>';
 
  756       print 
'<td class="right"><span class="amount">'.price(
price2num($subtot_paye_total_ht, 
'MT')).
'</span></td>';
 
  757       print 
'<td class="nowrap right"><span class="amount">'.price(
price2num($subtot_paye_vat, 
'MT')).
'</span></td>';
 
  762   if (count($x_paye) == 0) {  
 
  763     print 
'<tr class="liste_total">';
 
  764     print 
'<td colspan="4"></td>';
 
  765     print 
'<td class="right">'.$langs->trans(
"Total").
':</td>';
 
  767       print 
'<td class="nowrap right"> </td>';
 
  768       print 
'<td class="right"> </td>';
 
  770     print 
'<td class="right">'.price(
price2num(0, 
'MT')).
'</td>';
 
  771     print 
'<td class="nowrap right">'.price(
price2num(0, 
'MT')).
'</td>';
 
  776   print 
'<tr><td colspan="'.($span + 2).
'"></td></tr>';
 
  778   $diff = $x_coll_sum - $x_paye_sum;
 
  779   print 
'<tr class="liste_total">';
 
  780   print 
'<td class="liste_total" colspan="'.($span + 1).
'">'.$langs->trans(
"TotalToPay").($q ? 
', '.$langs->trans(
"Quadri").
' '.$q : 
'').
'</td>';
 
  781   print 
'<td class="liste_total nowrap right"><b>'.price(
price2num($diff, 
'MT')).
"</b></td>\n";
 
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
 
Class to manage Trips and Expenses.
 
Class to manage suppliers invoices.
 
Class to manage invoices.
 
Class to manage payments for supplier invoices.
 
Class to manage payments of customer invoices.
 
Class to manage payments of expense report.
 
Class to manage products or services.
 
Class to manage third parties objects (customers, suppliers, prospects...)
 
Class to manage Dolibarr users.
 
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
 
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
 
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
 
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
 
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
 
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
 
dol_now($mode='auto')
Return date for now.
 
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
 
print_date_range($date_start, $date_end, $format='', $outputlangs='')
Format output for start and end date.
 
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
 
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
 
report_header($reportname, $notused, $period, $periodlink, $description, $builddate, $exportlink='', $moreparam=array(), $calcmode='', $varlink='')
Show header of a report.
 
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
 
tax_by_thirdparty($type, $db, $y, $date_start, $date_end, $modetax, $direction, $m=0, $q=0)
Look for collectable VAT clients in the chosen year (and month)