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