dolibarr  17.0.4
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2021 Florian Henry <florian.henry@open-concept.pro>
4  * Copyright (C) 2013-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
5  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 // Load Dolibarr environment
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array("compta", "bills", "other", "accountancy"));
37 
38 $validatemonth = GETPOST('validatemonth', 'int');
39 $validateyear = GETPOST('validateyear', 'int');
40 
41 // Security check
42 if (!isModEnabled('accounting')) {
44 }
45 if ($user->socid > 0) {
47 }
48 if (empty($user->rights->accounting->bind->write)) {
50 }
51 
52 $accountingAccount = new AccountingAccount($db);
53 
54 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
55 if (GETPOST("year", 'int')) {
56  $year_start = GETPOST("year", 'int');
57 } else {
58  $year_start = dol_print_date(dol_now(), '%Y');
59  if (dol_print_date(dol_now(), '%m') < $month_start) {
60  $year_start--; // If current month is lower that starting fiscal month, we start last year
61  }
62 }
63 $year_end = $year_start + 1;
64 $month_end = $month_start - 1;
65 if ($month_end < 1) {
66  $month_end = 12;
67  $year_end--;
68 }
69 $search_date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
70 $search_date_end = dol_get_last_day($year_end, $month_end);
71 $year_current = $year_start;
72 
73 // Validate History
74 $action = GETPOST('action', 'aZ09');
75 
76 $chartaccountcode = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version');
77 
78 // Security check
79 if (!isModEnabled('accounting')) {
81 }
82 if ($user->socid > 0) {
84 }
85 if (empty($user->rights->accounting->mouvements->lire)) {
87 }
88 
89 
90 /*
91  * Actions
92  */
93 
94 if (($action == 'clean' || $action == 'validatehistory') && $user->rights->accounting->bind->write) {
95  // Clean database
96  $db->begin();
97  $sql1 = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det as fd";
98  $sql1 .= " SET fk_code_ventilation = 0";
99  $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN';
100  $sql1 .= ' (SELECT accnt.rowid ';
101  $sql1 .= ' FROM '.MAIN_DB_PREFIX.'accounting_account as accnt';
102  $sql1 .= ' INNER JOIN '.MAIN_DB_PREFIX.'accounting_system as syst';
103  $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid='.$conf->global->CHARTOFACCOUNTS.' AND accnt.entity = '.$conf->entity.')';
104  $sql1 .= ' AND fd.fk_facture_fourn IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_fourn WHERE entity = '.$conf->entity.')';
105  $sql1 .= ' AND fk_code_ventilation <> 0';
106 
107  dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
108  $resql1 = $db->query($sql1);
109  if (!$resql1) {
110  $error++;
111  $db->rollback();
112  setEventMessages($db->lasterror(), null, 'errors');
113  } else {
114  $db->commit();
115  }
116  // End clean database
117 }
118 
119 if ($action == 'validatehistory') {
120  $error = 0;
121  $nbbinddone = 0;
122  $notpossible = 0;
123 
124  $db->begin();
125 
126  // Now make the binding. Bind automatically only for product with a dedicated account that exists into chart of account, others need a manual bind
127  /*if ($db->type == 'pgsql') {
128  $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det";
129  $sql1 .= " SET fk_code_ventilation = accnt.rowid";
130  $sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
131  $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facture_fourn_det.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . ((int) $conf->global->CHARTOFACCOUNTS).' AND accnt.entity = '.$conf->entity;
132  $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number";
133  $sql1 .= " AND " . MAIN_DB_PREFIX . "facture_fourn_det.fk_code_ventilation = 0";
134  } else {
135  $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst";
136  $sql1 .= " SET fk_code_ventilation = accnt.rowid";
137  $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . ((int) $conf->global->CHARTOFACCOUNTS).' AND accnt.entity = '.$conf->entity;
138  $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number";
139  $sql1 .= " AND fd.fk_code_ventilation = 0";
140  }*/
141 
142  // Supplier Invoice Lines (must be same request than into page list.php for manual binding)
143  $sql = "SELECT f.rowid as facid, f.ref, f.ref_supplier, f.libelle as invoice_label, f.datef, f.type as ftype, f.fk_facture_source,";
144  $sql .= " l.rowid, l.fk_product, l.description, l.total_ht, l.fk_code_ventilation, l.product_type as type_l, l.tva_tx as tva_tx_line, l.vat_src_code,";
145  $sql .= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.fk_product_type as type, p.tva_tx as tva_tx_prod,";
146  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
147  $sql .= " ppe.accountancy_code_buy as code_buy, ppe.accountancy_code_buy_intra as code_buy_intra, ppe.accountancy_code_buy_export as code_buy_export,";
148  } else {
149  $sql .= " p.accountancy_code_buy as code_buy, p.accountancy_code_buy_intra as code_buy_intra, p.accountancy_code_buy_export as code_buy_export,";
150  }
151  $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
152  $sql .= " co.code as country_code, co.label as country_label,";
153  $sql .= " s.tva_intra,";
154  if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
155  $sql .= " spe.accountancy_code_buy as company_code_buy";
156  } else {
157  $sql .= " s.accountancy_code_buy as company_code_buy";
158  }
159  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
160  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc";
161  if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
162  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
163  }
164  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays ";
165  $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
166  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product";
167  if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
168  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
169  }
170  $alias_societe_perentity = empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED) ? "s" : "spe";
171  $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p" : "ppe";
172  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON " . $alias_product_perentity . ".accountancy_code_buy = aa.account_number AND aa.active = 1 AND aa.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa.entity = ".$conf->entity;
173  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_perentity . ".accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity;
174  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_perentity . ".accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity;
175  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa4 ON " . $alias_product_perentity . ".accountancy_code_buy = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa4.entity = ".$conf->entity;
176  $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
177  $sql .= " AND l.product_type <= 2";
178  $sql .= " AND f.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
179  if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
180  $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
181  }
182  if ($validatemonth && $validateyear) {
183  $sql .= dolSqlDateFilter('f.datef', 0, $validatemonth, $validateyear);
184  }
185 
186  dol_syslog('htdocs/accountancy/supplier/index.php');
187 
188  $result = $db->query($sql);
189  if (!$result) {
190  $error++;
191  setEventMessages($db->lasterror(), null, 'errors');
192  } else {
193  $num_lines = $db->num_rows($result);
194 
195  $isBuyerInEEC = isInEEC($mysoc);
196 
197  $thirdpartystatic = new Societe($db);
198  $facture_static = new FactureFournisseur($db);
199  $facture_static_det = new SupplierInvoiceLine($db);
200  $product_static = new Product($db);
201 
202  $i = 0;
203  while ($i < min($num_lines, 10000)) { // No more than 10000 at once
204  $objp = $db->fetch_object($result);
205 
206  $thirdpartystatic->id = $objp->socid;
207  $thirdpartystatic->name = $objp->name;
208  $thirdpartystatic->client = $objp->client;
209  $thirdpartystatic->fournisseur = $objp->fournisseur;
210  $thirdpartystatic->code_client = $objp->code_client;
211  $thirdpartystatic->code_compta_client = $objp->code_compta_client;
212  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
213  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
214  $thirdpartystatic->email = $objp->email;
215  $thirdpartystatic->country_code = $objp->country_code;
216  $thirdpartystatic->tva_intra = $objp->tva_intra;
217  $thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion)
218 
219  $product_static->ref = $objp->product_ref;
220  $product_static->id = $objp->product_id;
221  $product_static->type = $objp->type;
222  $product_static->label = $objp->product_label;
223  $product_static->status = $objp->status;
224  $product_static->status_buy = $objp->status_buy;
225  $product_static->accountancy_code_sell = $objp->code_sell;
226  $product_static->accountancy_code_sell_intra = $objp->code_sell_intra;
227  $product_static->accountancy_code_sell_export = $objp->code_sell_export;
228  $product_static->accountancy_code_buy = $objp->code_buy;
229  $product_static->accountancy_code_buy_intra = $objp->code_buy_intra;
230  $product_static->accountancy_code_buy_export = $objp->code_buy_export;
231  $product_static->tva_tx = $objp->tva_tx_prod;
232 
233  $facture_static->ref = $objp->ref;
234  $facture_static->id = $objp->facid;
235  $facture_static->type = $objp->ftype;
236  $facture_static->ref_supplier = $objp->ref_supplier;
237  $facture_static->label = $objp->invoice_label;
238  $facture_static->date = $db->jdate($objp->datef);
239  $facture_static->fk_facture_source = $objp->fk_facture_source;
240 
241  $facture_static_det->id = $objp->rowid;
242  $facture_static_det->total_ht = $objp->total_ht;
243  $facture_static_det->tva_tx = $objp->tva_tx_line;
244  $facture_static_det->vat_src_code = $objp->vat_src_code;
245  $facture_static_det->product_type = $objp->type_l;
246  $facture_static_det->desc = $objp->description;
247 
248  $accountingAccountArray = array(
249  'dom'=>$objp->aarowid,
250  'intra'=>$objp->aarowid_intra,
251  'export'=>$objp->aarowid_export,
252  'thirdparty' =>$objp->aarowid_thirdparty);
253 
254  $code_buy_p_notset = '';
255  $code_buy_t_notset = '';
256 
257  $suggestedid = 0;
258 
259  $return = $accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'supplier');
260  if (!is_array($return) && $return<0) {
261  setEventMessage($accountingAccount->error, 'errors');
262  } else {
263  $suggestedid = $return['suggestedid'];
264  $suggestedaccountingaccountfor = $return['suggestedaccountingaccountfor'];
265 
266  if (!empty($suggestedid) && $suggestedaccountingaccountfor != '' && $suggestedaccountingaccountfor != 'eecwithoutvatnumber') {
267  $suggestedid = $return['suggestedid'];
268  } else {
269  $suggestedid = 0;
270  }
271  }
272 
273  if ($suggestedid > 0) {
274  $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det";
275  $sqlupdate .= " SET fk_code_ventilation = ".((int) $suggestedid);
276  $sqlupdate .= " WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id);
277 
278  $resqlupdate = $db->query($sqlupdate);
279  if (!$resqlupdate) {
280  $error++;
281  setEventMessages($db->lasterror(), null, 'errors');
282  break;
283  } else {
284  $nbbinddone++;
285  }
286  } else {
287  $notpossible++;
288  }
289 
290  $i++;
291  }
292  if ($num_lines > 10000) {
293  $notpossible += ($num_lines - 10000);
294  }
295  }
296 
297  if ($error) {
298  $db->rollback();
299  } else {
300  $db->commit();
301  setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone, $notpossible), null, 'mesgs');
302  }
303 }
304 
305 
306 /*
307  * View
308  */
309 
310 llxHeader('', $langs->trans("SuppliersVentilation"));
311 
312 $textprevyear = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_current - 1).'">'.img_previous().'</a>';
313 $textnextyear = '&nbsp;<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_current + 1).'">'.img_next().'</a>';
314 
315 print load_fiche_titre($langs->trans("SuppliersVentilation")." ".$textprevyear."&nbsp;".$langs->trans("Year")."&nbsp;".$year_start."&nbsp;".$textnextyear, '', 'title_accountancy');
316 
317 print '<span class="opacitymedium">'.$langs->trans("DescVentilSupplier").'</span><br>';
318 print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")).'<br>';
319 print '</span><br>';
320 
321 $y = $year_current;
322 
323 $buttonbind = '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'">'.$langs->trans("ValidateHistory").'</a>';
324 
325 
326 print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1);
327 //print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
328 
329 print '<div class="div-table-responsive-no-min">';
330 print '<table class="noborder centpercent">';
331 print '<tr class="liste_titre"><td class="minwidth100">'.$langs->trans("Account").'</td>';
332 print '<td>'.$langs->trans("Label").'</td>';
333 for ($i = 1; $i <= 12; $i++) {
334  $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
335  if ($j > 12) {
336  $j -= 12;
337  }
338  $cursormonth = $j;
339  if ($cursormonth > 12) {
340  $cursormonth -= 12;
341  }
342  $cursoryear = ($cursormonth < ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1)) ? $y + 1 : $y;
343  $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
344 
345  print '<td width="60" class="right">';
346  if (!empty($tmp['mday'])) {
347  $param = 'search_date_startday=1&search_date_startmonth='.$cursormonth.'&search_date_startyear='.$cursoryear;
348  $param .= '&search_date_endday='.$tmp['mday'].'&search_date_endmonth='.$tmp['mon'].'&search_date_endyear='.$tmp['year'];
349  print '<a href="'.DOL_URL_ROOT.'/accountancy/supplier/list.php?'.$param.'">';
350  }
351  print $langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT));
352  if (!empty($tmp['mday'])) {
353  print '</a>';
354  }
355  print '</td>';
356 }
357 print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
358 
359 $sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number')." AS codecomptable,";
360 $sql .= " ".$db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label')." AS intitule,";
361 for ($i = 1; $i <= 12; $i++) {
362  $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
363  if ($j > 12) {
364  $j -= 12;
365  }
366  $sql .= " SUM(".$db->ifsql("MONTH(ff.datef)=".$j, "ffd.total_ht", "0").") AS month".str_pad($j, 2, "0", STR_PAD_LEFT).",";
367 }
368 $sql .= " SUM(ffd.total_ht) as total";
369 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as ffd";
370 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
371 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
372 $sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
373 $sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
374 // Define begin binding date
375 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
376  $sql .= " AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
377 }
378 $sql .= " AND ff.fk_statut > 0";
379 $sql .= " AND ffd.product_type <= 2";
380 $sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
381 $sql .= " AND aa.account_number IS NULL";
382 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
383  $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.")";
384 } else {
385  $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_DEPOSIT.")";
386 }
387 $sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
388 
389 dol_syslog('htdocs/accountancy/supplier/index.php', LOG_DEBUG);
390 $resql = $db->query($sql);
391 if ($resql) {
392  $num = $db->num_rows($resql);
393 
394  while ($row = $db->fetch_row($resql)) {
395  print '<tr class="oddeven">';
396  print '<td>';
397  if ($row[0] == 'tobind') {
398  print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
399  } else {
400  print length_accountg($row[0]);
401  }
402  print '</td>';
403  print '<td>';
404  if ($row[0] == 'tobind') {
405  print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/supplier/list.php?search_year='.((int) $y), $langs->transnoentitiesnoconv("ToBind"));
406  } else {
407  print $row[1];
408  }
409  print '</td>';
410  for ($i = 2; $i <= 13; $i++) {
411  print '<td class="right nowraponall amount">';
412  print price($row[$i]);
413  print '</td>';
414  }
415  print '<td class="right nowraponall amount"><b>'.price($row[14]).'</b></td>';
416  print '</tr>';
417  }
418  $db->free($resql);
419 
420  if ($num == 0) {
421  print '<tr class="oddeven"><td colspan="16">';
422  print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
423  print '</td></tr>';
424  }
425 } else {
426  print $db->lasterror(); // Show last sql error
427 }
428 print "</table>\n";
429 print '</div>';
430 
431 
432 print '<br>';
433 
434 
435 print_barre_liste(img_picto('', 'link', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesBound"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
436 //print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), '', '');
437 
438 print '<div class="div-table-responsive-no-min">';
439 print '<table class="noborder centpercent">';
440 print '<tr class="liste_titre"><td class="minwidth100">'.$langs->trans("Account").'</td>';
441 print '<td>'.$langs->trans("Label").'</td>';
442 for ($i = 1; $i <= 12; $i++) {
443  $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
444  if ($j > 12) {
445  $j -= 12;
446  }
447  $cursormonth = $j;
448  if ($cursormonth > 12) {
449  $cursormonth -= 12;
450  }
451  $cursoryear = ($cursormonth < ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1)) ? $y + 1 : $y;
452  $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
453 
454  print '<td width="60" class="right">';
455  if (!empty($tmp['mday'])) {
456  $param = 'search_date_startday=1&search_date_startmonth='.$cursormonth.'&search_date_startyear='.$cursoryear;
457  $param .= '&search_date_endday='.$tmp['mday'].'&search_date_endmonth='.$tmp['mon'].'&search_date_endyear='.$tmp['year'];
458  print '<a href="'.DOL_URL_ROOT.'/accountancy/supplier/lines.php?'.$param.'">';
459  }
460  print $langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT));
461  if (!empty($tmp['mday'])) {
462  print '</a>';
463  }
464  print '</td>';
465 }
466 print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
467 
468 $sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number')." AS codecomptable,";
469 $sql .= " ".$db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label')." AS intitule,";
470 for ($i = 1; $i <= 12; $i++) {
471  $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
472  if ($j > 12) {
473  $j -= 12;
474  }
475  $sql .= " SUM(".$db->ifsql("MONTH(ff.datef)=".$j, "ffd.total_ht", "0").") AS month".str_pad($j, 2, "0", STR_PAD_LEFT).",";
476 }
477 $sql .= " SUM(ffd.total_ht) as total";
478 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as ffd";
479 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
480 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
481 $sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
482 $sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
483 // Define begin binding date
484 if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
485  $sql .= " AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
486 }
487 $sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
488 $sql .= " AND ff.fk_statut > 0";
489 $sql .= " AND ffd.product_type <= 2";
490 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
491  $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.")";
492 } else {
493  $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.", ".FactureFournisseur::TYPE_DEPOSIT.")";
494 }
495 $sql .= " AND aa.account_number IS NOT NULL";
496 $sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
497 $sql .= ' ORDER BY aa.account_number';
498 
499 dol_syslog('htdocs/accountancy/supplier/index.php');
500 $resql = $db->query($sql);
501 if ($resql) {
502  $num = $db->num_rows($resql);
503 
504  while ($row = $db->fetch_row($resql)) {
505  print '<tr class="oddeven">';
506  print '<td>';
507  if ($row[0] == 'tobind') {
508  print $langs->trans("Unknown");
509  } else {
510  print length_accountg($row[0]);
511  }
512  print '</td>';
513 
514  print '<td class="left">';
515  if ($row[0] == 'tobind') {
516  print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/supplier/list.php?search_year='.((int) $y), $langs->transnoentitiesnoconv("ToBind"));
517  } else {
518  print $row[1];
519  }
520  print '</td>';
521 
522  for ($i = 2; $i <= 13; $i++) {
523  print '<td class="right nowraponall amount">';
524  print price($row[$i]);
525  print '</td>';
526  }
527  print '<td class="right nowraponall amount"><b>'.price($row[14]).'</b></td>';
528  print '</tr>';
529  }
530  $db->free($resql);
531 
532  if ($num == 0) {
533  print '<tr class="oddeven"><td colspan="16">';
534  print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
535  print '</td></tr>';
536  }
537 } else {
538  print $db->lasterror(); // Show last sql error
539 }
540 print "</table>\n";
541 print '</div>';
542 
543 
544 if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange. Why showing a report that should rely on result of this step ?
545  print '<br>';
546  print '<br>';
547 
548  print_barre_liste($langs->trans("OtherInfo"), '', '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
549  //print load_fiche_titre($langs->trans("OtherInfo"), '', '');
550 
551  print '<div class="div-table-responsive-no-min">';
552  print '<table class="noborder centpercent">';
553  print '<tr class="liste_titre"><td>'.$langs->trans("Total").'</td>';
554  for ($i = 1; $i <= 12; $i++) {
555  $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
556  if ($j > 12) {
557  $j -= 12;
558  }
559  print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).'</td>';
560  }
561  print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
562 
563  $sql = "SELECT '".$db->escape($langs->trans("CAHTF"))."' AS label,";
564  for ($i = 1; $i <= 12; $i++) {
565  $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1;
566  if ($j > 12) {
567  $j -= 12;
568  }
569  $sql .= " SUM(".$db->ifsql("MONTH(ff.datef)=".$j, "ffd.total_ht", "0").") AS month".str_pad($j, 2, "0", STR_PAD_LEFT).",";
570  }
571  $sql .= " SUM(ffd.total_ht) as total";
572  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as ffd";
573  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
574  $sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
575  $sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
576  // Define begin binding date
577  if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) {
578  $sql .= " AND ff.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'";
579  }
580  $sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
581  $sql .= " AND ff.fk_statut > 0";
582  $sql .= " AND ffd.product_type <= 2";
583  if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) {
584  $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.")";
585  } else {
586  $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.", ".FactureFournisseur::TYPE_DEPOSIT.")";
587  }
588 
589  dol_syslog('htdocs/accountancy/supplier/index.php');
590  $resql = $db->query($sql);
591  if ($resql) {
592  $num = $db->num_rows($resql);
593 
594  while ($row = $db->fetch_row($resql)) {
595  print '<tr><td>'.$row[0].'</td>';
596  for ($i = 1; $i <= 12; $i++) {
597  print '<td class="right nowraponall amount">'.price($row[$i]).'</td>';
598  }
599  print '<td class="right nowraponall amount"><b>'.price($row[13]).'</b></td>';
600  print '</tr>';
601  }
602  $db->free($resql);
603  } else {
604  print $db->lasterror(); // Show last sql error
605  }
606  print "</table>\n";
607  print '</div>';
608 }
609 
610 // End of page
611 llxFooter();
612 $db->close();
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
Class to manage accounting accounts.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage line invoices.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $excludefirstand=0, $gm=false)
Generate a SQL string to make a filter into a range (for second of date until last second of date).
Definition: date.lib.php:358
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:594
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
img_previous($titlealt='default', $moreatt='')
Show previous logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessage($mesgs, $style='mesgs')
Set event message in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_next($titlealt='default', $moreatt='')
Show next logo.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
llxFooter()
Footer empty.
Definition: index.php:71
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.