dolibarr 24.0.0-beta
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@easya.solutions>
5 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
43require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
44
45// Load translation files required by the page
46$langs->loadLangs(array("compta", "bills", "other", "accountancy"));
47
48$validatemonth = GETPOSTINT('validatemonth');
49$validateyear = GETPOSTINT('validateyear');
50
51$accountingAccount = new AccountingAccount($db);
52
53$month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
54if (GETPOSTINT("year")) {
55 $year_start = GETPOSTINT("year");
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;
64if ($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$error = 0;
72
73// Validate History
74$action = GETPOST('action', 'aZ09');
75
76$chartaccountcode = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
77
78// Security check
79if (!isModEnabled('accounting')) {
81}
82if ($user->socid > 0) {
84}
85if (!$user->hasRight('accounting', 'bind', 'write')) {
87}
88
89
90/*
91 * Actions
92 */
93
94if (($action == 'clean' || $action == 'validatehistory') && $user->hasRight('accounting', 'bind', 'write')) {
95 // Clean database by removing binding done on non existing or no more existing accounts
96 $db->begin();
97 $sql1 = "UPDATE ".$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 ".$db->prefix()."accounting_account as accnt";
102 $sql1 .= " INNER JOIN ".$db->prefix()."accounting_system as syst";
103 $sql1 .= " ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid = ".getDolGlobalInt('CHARTOFACCOUNTS')." AND accnt.entity = ".((int) $conf->entity).")";
104 $sql1 .= " AND fd.fk_facture_fourn IN (SELECT rowid FROM ".$db->prefix()."facture_fourn WHERE entity = ".((int) $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
119if ($action == 'validatehistory' && $user->hasRight('accounting', 'bind', 'write')) {
120 $error = 0;
121 $nbbinddone = 0;
122 $nbbindfailed = 0;
123 $notpossible = 0;
124
125 $db->begin();
126
127 // Now make the binding. Bind automatically only for product with a dedicated account that exists into chart of account, others need a manual bind
128 // Supplier Invoice Lines (must be same request than into page list.php for manual binding)
129 $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,";
130 $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,";
131 $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,";
132 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
133 $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,";
134 } else {
135 $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,";
136 }
137 $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
138 $sql .= " co.code as country_code, co.label as country_label,";
139 $sql .= " s.tva_intra,";
140 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
141 $sql .= " spe.accountancy_code_buy as company_code_buy";
142 } else {
143 $sql .= " s.accountancy_code_buy as company_code_buy";
144 }
145 $sql .= " FROM ".$db->prefix()."facture_fourn as f";
146 $sql .= " INNER JOIN ".$db->prefix()."societe as s ON s.rowid = f.fk_soc";
147 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
148 $sql .= " LEFT JOIN " . $db->prefix() . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
149 }
150 $sql .= " LEFT JOIN ".$db->prefix()."c_country as co ON co.rowid = s.fk_pays ";
151 $sql .= " INNER JOIN ".$db->prefix()."facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
152 $sql .= " LEFT JOIN ".$db->prefix()."product as p ON p.rowid = l.fk_product";
153 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
154 $sql .= " LEFT JOIN " . $db->prefix() . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
155 }
156 $alias_societe_perentity = !getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED') ? "s" : "spe";
157 $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
158 $sql .= " LEFT JOIN ".$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;
159 $sql .= " LEFT JOIN ".$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;
160 $sql .= " LEFT JOIN ".$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;
161 $sql .= " LEFT JOIN ".$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;
162 $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
163 $sql .= " AND l.product_type <= 2";
164 $sql .= " AND f.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
165 if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
166 $sql .= " AND f.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
167 }
168 if ($validatemonth && $validateyear) {
169 $sql .= dolSqlDateFilter('f.datef', 0, $validatemonth, $validateyear);
170 }
171
172 dol_syslog('htdocs/accountancy/supplier/index.php');
173
174 $result = $db->query($sql);
175 if (!$result) {
176 $error++;
177 setEventMessages($db->lasterror(), null, 'errors');
178 } else {
179 $num_lines = $db->num_rows($result);
180
181 $isBuyerInEEC = isInEEC($mysoc);
182
183 $thirdpartystatic = new Societe($db);
184 $facture_static = new FactureFournisseur($db);
185 $facture_static_det = new SupplierInvoiceLine($db);
186 $product_static = new Product($db);
187
188 $i = 0;
189 while ($i < min($num_lines, 10000)) { // No more than 10000 at once
190 $objp = $db->fetch_object($result);
191
192 $thirdpartystatic->id = !empty($objp->socid) ? $objp->socid : 0;
193 $thirdpartystatic->name = !empty($objp->name) ? $objp->name : "";
194 $thirdpartystatic->client = !empty($objp->client) ? $objp->client : "";
195 $thirdpartystatic->fournisseur = !empty($objp->fournisseur) ? $objp->fournisseur : "";
196 $thirdpartystatic->code_client = !empty($objp->code_client) ? $objp->code_client : "";
197 $thirdpartystatic->code_compta_client = !empty($objp->code_compta_client) ? $objp->code_compta_client : "";
198 $thirdpartystatic->code_fournisseur = !empty($objp->code_fournisseur) ? $objp->code_fournisseur : "";
199 $thirdpartystatic->code_compta_fournisseur = !empty($objp->code_compta_fournisseur) ? $objp->code_compta_fournisseur : "";
200 $thirdpartystatic->email = !empty($objp->email) ? $objp->email : "";
201 $thirdpartystatic->country_code = !empty($objp->country_code) ? $objp->country_code : "";
202 $thirdpartystatic->tva_intra = !empty($objp->tva_intra) ? $objp->tva_intra : "";
203 $thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion)
204
205 $product_static->ref = $objp->product_ref;
206 $product_static->id = $objp->product_id;
207 $product_static->type = $objp->type;
208 $product_static->label = $objp->product_label;
209 $product_static->status = !empty($objp->status) ? $objp->status : 0;
210 $product_static->status_buy = !empty($objp->status_buy) ? $objp->status_buy : 0;
211 $product_static->accountancy_code_sell = !empty($objp->code_sell)? $objp->code_sell : "";
212 $product_static->accountancy_code_sell_intra = !empty($objp->code_sell_intra)? $objp->code_sell_intra : "";
213 $product_static->accountancy_code_sell_export = !empty($objp->code_sell_export)? $objp->code_sell_export : "";
214 $product_static->accountancy_code_buy = !empty($objp->code_buy) ? $objp->code_buy : "";
215 $product_static->accountancy_code_buy_intra = !empty($objp->code_buy_intra) ? $objp->code_buy_intra : "";
216 $product_static->accountancy_code_buy_export = !empty($objp->code_buy_export) ? $objp->code_buy_export : "";
217 $product_static->tva_tx = $objp->tva_tx_prod;
218
219 $facture_static->ref = $objp->ref;
220 $facture_static->id = $objp->facid;
221 $facture_static->type = $objp->ftype;
222 $facture_static->ref_supplier = $objp->ref_supplier;
223 $facture_static->label = $objp->invoice_label;
224 $facture_static->date = $db->jdate($objp->datef);
225 $facture_static->fk_facture_source = $objp->fk_facture_source;
226
227 $facture_static_det->id = $objp->rowid;
228 $facture_static_det->total_ht = $objp->total_ht;
229 $facture_static_det->tva_tx = $objp->tva_tx_line;
230 $facture_static_det->vat_src_code = $objp->vat_src_code;
231 $facture_static_det->product_type = $objp->type_l;
232 $facture_static_det->desc = $objp->description;
233
234 $accountingAccountArray = array(
235 'dom' => $objp->aarowid,
236 'intra' => $objp->aarowid_intra,
237 'export' => $objp->aarowid_export,
238 'thirdparty' => $objp->aarowid_thirdparty);
239
240 $code_buy_p_notset = '';
241 $code_buy_t_notset = '';
242
243 $suggestedid = 0;
244
245 $return = $accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'supplier');
246 if (!is_array($return) && $return < 0) {
247 setEventMessage($accountingAccount->error, 'errors');
248 } else {
249 $suggestedid = $return['suggestedid'];
250 $suggestedaccountingaccountfor = $return['suggestedaccountingaccountfor'];
251
252 if (!empty($suggestedid) && $suggestedaccountingaccountfor != '' && $suggestedaccountingaccountfor != 'eecwithoutvatnumber') {
253 $suggestedid = $return['suggestedid'];
254 } else {
255 $suggestedid = 0;
256 }
257 }
258
259 if ($suggestedid > 0) {
260 $sqlupdate = "UPDATE ".$db->prefix()."facture_fourn_det";
261 $sqlupdate .= " SET fk_code_ventilation = ".((int) $suggestedid);
262 $sqlupdate .= " WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id);
263
264 $resqlupdate = $db->query($sqlupdate);
265 if (!$resqlupdate) {
266 $error++;
267 setEventMessages($db->lasterror(), null, 'errors');
268 $nbbindfailed++;
269 break;
270 } else {
271 $nbbinddone++;
272 }
273 } else {
274 $notpossible++;
275 $nbbindfailed++;
276 }
277
278 $i++;
279 }
280 if ($num_lines > 10000) {
281 $notpossible += ($num_lines - 10000);
282 }
283 }
284
285 if ($error) {
286 $db->rollback();
287 } else {
288 $db->commit();
289 setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone, $notpossible), null, ($notpossible ? 'warnings' : 'mesgs'));
290 if ($nbbindfailed) {
291 setEventMessages($langs->trans('DoManualBindingForFailedRecord', $nbbindfailed), null, 'warnings');
292 }
293 }
294}
295
296
297/*
298 * View
299 */
300
301$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double#Liaisons_comptables';
302
303llxHeader('', $langs->trans("SuppliersVentilation"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-supplier page-index');
304
305$textprevyear = '<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_current - 1).'">'.img_previous().'</a>';
306$textnextyear = '&nbsp;<a href="'.$_SERVER["PHP_SELF"].'?year='.($year_current + 1).'">'.img_next().'</a>';
307
308print load_fiche_titre($langs->trans("SuppliersVentilation")." ".$textprevyear."&nbsp;".$langs->trans("Year")."&nbsp;".$year_start."&nbsp;".$textnextyear, '', 'title_accountancy');
309
310print '<div class="info">';
311print '<span class="">'.$langs->trans("DescVentilSupplier").'</span><br>';
312print '<span class="hideonsmartphone">'.$langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")).'<br>';
313print '</span>';
314print '</div>';
315
316$y = $year_current;
317
318$buttonbind = '<a class="button small" href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&token='.newToken().'&year='.$year_current.'">'.img_picto($langs->trans("ValidateHistory"), 'link', 'class="pictofixedwidth fa-color-unset"').$langs->trans("ValidateHistory").'</a>';
319
320
321print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind);
322//print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
323
324print '<div class="div-table-responsive-no-min">';
325print '<table class="noborder centpercent">';
326print '<tr class="liste_titre"><td class="minwidth100">'.$langs->trans("Account").'</td>';
327for ($i = 1; $i <= 12; $i++) {
328 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
329 if ($j > 12) {
330 $j -= 12;
331 }
332 $cursormonth = $j;
333 if ($cursormonth > 12) {
334 $cursormonth -= 12;
335 }
336 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
337 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
338
339 print '<td width="60" class="right">';
340 if (!empty($tmp['mday'])) {
341 $param = 'search_date_startday=1&search_date_startmonth='.$cursormonth.'&search_date_startyear='.$cursoryear;
342 $param .= '&search_date_endday='.$tmp['mday'].'&search_date_endmonth='.$tmp['mon'].'&search_date_endyear='.$tmp['year'];
343 print '<a href="'.DOL_URL_ROOT.'/accountancy/supplier/list.php?'.$param.'">';
344 }
345 print $langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT));
346 if (!empty($tmp['mday'])) {
347 print '</a>';
348 }
349 print '</td>';
350}
351print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
352
353$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number')." AS codecomptable,";
354$sql .= " ".$db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label')." AS intitule,";
355for ($i = 1; $i <= 12; $i++) {
356 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
357 if ($j > 12) {
358 $j -= 12;
359 }
360 $sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((int) $j), "ffd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
361 $sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((string) $j), "1", "0").") AS nbmonth".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
362}
363$sql .= " SUM(ffd.total_ht) as total, COUNT(ffd.rowid) as nb";
364$sql .= " FROM ".$db->prefix()."facture_fourn_det as ffd";
365$sql .= " LEFT JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
366$sql .= " LEFT JOIN ".$db->prefix()."accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
367$sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
368$sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
369// Define begin binding date
370if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
371 $sql .= " AND ff.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
372}
373$sql .= " AND ff.fk_statut > 0";
374$sql .= " AND ffd.product_type <= 2";
375$sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
376$sql .= " AND aa.account_number IS NULL";
377if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
378 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.")";
379} else {
380 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_DEPOSIT.")";
381}
382$sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
383
384dol_syslog('htdocs/accountancy/supplier/index.php', LOG_DEBUG);
385$resql = $db->query($sql);
386if ($resql) {
387 $num = $db->num_rows($resql);
388
389 while ($row = $db->fetch_row($resql)) {
390 print '<tr class="oddeven">';
391 print '<td>';
392 if ($row[0] == 'tobind') {
393 //print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
394 } else {
395 print length_accountg($row[0]).' - ';
396 }
397 //print '</td>';
398 //print '<td>';
399 if ($row[0] == 'tobind') {
400 $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
401 if ($startmonth > 12) {
402 $startmonth -= 12;
403 }
404 $startyear = ($startmonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
405 $endmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) + 11;
406 if ($endmonth > 12) {
407 $endmonth -= 12;
408 }
409 $endyear = ($endmonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
410 print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/supplier/list.php?search_date_startday=1&search_date_startmonth='.((int) $startmonth).'&search_date_startyear='.((int) $startyear).'&search_date_endday=&search_date_endmonth='.((int) $endmonth).'&search_date_endyear='.((int) $endyear), $langs->transnoentitiesnoconv("ToBind"));
411 } else {
412 print $row[1];
413 }
414 print '</td>';
415 for ($i = 2; $i <= 13; $i++) {
416 $cursormonth = (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
417 if ($cursormonth > 12) {
418 $cursormonth -= 12;
419 }
420 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
421 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
422
423 print '<td class="right nowraponall amount" title="'.price($row[2 * $i - 2]).' - '.$row[2 * $i - 1].' lines">';
424 print price($row[2 * $i - 2]);
425 // Add link to make binding
426 if (!empty(price2num($row[2 * $i - 2])) || !empty($row[2 * $i - 1])) {
427 print '<a href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&year='.$y.'&validatemonth='.((int) $cursormonth).'&validateyear='.((int) $cursoryear).'&token='.newToken().'">';
428 print img_picto($langs->trans("ValidateHistory").' ('.$langs->trans('Month'.str_pad((string) $cursormonth, 2, '0', STR_PAD_LEFT)).' '.$cursoryear.')', 'link', 'class="marginleft2"');
429 print '</a>';
430 }
431 print '</td>';
432 }
433 print '<td class="right nowraponall amount"><b>'.price($row[26]).'</b></td>';
434 print '</tr>';
435 }
436 $db->free($resql);
437
438 if ($num == 0) {
439 print '<tr class="oddeven"><td colspan="15">';
440 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
441 print '</td></tr>';
442 }
443} else {
444 print $db->lasterror(); // Show last sql error
445}
446print "</table>\n";
447print '</div>';
448
449
450print '<br>';
451
452
453print_barre_liste(img_picto('', 'link', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesBound"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
454//print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), '', '');
455
456print '<div class="div-table-responsive-no-min">';
457print '<table class="noborder centpercent">';
458print '<tr class="liste_titre"><td class="minwidth100">'.$langs->trans("Account").'</td>';
459for ($i = 1; $i <= 12; $i++) {
460 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
461 if ($j > 12) {
462 $j -= 12;
463 }
464 $cursormonth = $j;
465 if ($cursormonth > 12) {
466 $cursormonth -= 12;
467 }
468 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
469 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
470
471 print '<td width="60" class="right">';
472 if (!empty($tmp['mday'])) {
473 $param = 'search_date_startday=1&search_date_startmonth='.$cursormonth.'&search_date_startyear='.$cursoryear;
474 $param .= '&search_date_endday='.$tmp['mday'].'&search_date_endmonth='.$tmp['mon'].'&search_date_endyear='.$tmp['year'];
475 print '<a href="'.DOL_URL_ROOT.'/accountancy/supplier/lines.php?'.$param.'">';
476 }
477 print $langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT));
478 if (!empty($tmp['mday'])) {
479 print '</a>';
480 }
481 print '</td>';
482}
483print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
484
485$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number')." AS codecomptable,";
486$sql .= " ".$db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label')." AS intitule,";
487for ($i = 1; $i <= 12; $i++) {
488 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
489 if ($j > 12) {
490 $j -= 12;
491 }
492 $sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((int) $j), "ffd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
493}
494$sql .= " SUM(ffd.total_ht) as total";
495$sql .= " FROM ".$db->prefix()."facture_fourn_det as ffd";
496$sql .= " LEFT JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
497$sql .= " LEFT JOIN ".$db->prefix()."accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
498$sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
499$sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
500// Define begin binding date
501if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
502 $sql .= " AND ff.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
503}
504$sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
505$sql .= " AND ff.fk_statut > 0";
506$sql .= " AND ffd.product_type <= 2";
507if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
508 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.")";
509} else {
510 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.", ".FactureFournisseur::TYPE_DEPOSIT.")";
511}
512$sql .= " AND aa.account_number IS NOT NULL";
513$sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
514$sql .= ' ORDER BY aa.account_number';
515
516dol_syslog('htdocs/accountancy/supplier/index.php');
517$resql = $db->query($sql);
518if ($resql) {
519 $num = $db->num_rows($resql);
520
521 while ($row = $db->fetch_row($resql)) {
522 print '<tr class="oddeven">';
523 print '<td class="tdoverflowmax300"'.(empty($row[1]) ? '' : ' title="'.dol_escape_htmltag($row[1]).'"').'>';
524 if ($row[0] == 'tobind') {
525 //print $langs->trans("Unknown");
526 } else {
527 print length_accountg($row[0]).' - ';
528 }
529 //print '</td>';
530
531 //print '<td class="tdoverflowmax300"'.(empty($row[1]) ? '' : ' title="'.dol_escape_htmltag($row[1]).'"').'>';
532 if ($row[0] == 'tobind') {
533 print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/supplier/list.php?search_year='.((int) $y), $langs->transnoentitiesnoconv("ToBind"));
534 } else {
535 print dol_escape_htmltag($row[1]);
536 }
537 print '</td>';
538
539 for ($i = 2; $i <= 13; $i++) {
540 print '<td class="right nowraponall amount">';
541 print price($row[$i]);
542 print '</td>';
543 }
544 print '<td class="right nowraponall amount"><b>'.price($row[14]).'</b></td>';
545 print '</tr>';
546 }
547 $db->free($resql);
548
549 if ($num == 0) {
550 print '<tr class="oddeven"><td colspan="15">';
551 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
552 print '</td></tr>';
553 }
554} else {
555 print $db->lasterror(); // Show last sql error
556}
557print "</table>\n";
558print '</div>';
559
560
561if (getDolGlobalString('SHOW_TOTAL_OF_PREVIOUS_LISTS_IN_LIN_PAGE')) { // This part of code looks strange. Why showing a report that should rely on result of this step ?
562 print '<br>';
563 print '<br>';
564
565 print_barre_liste($langs->trans("OtherInfo"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
566 //print load_fiche_titre($langs->trans("OtherInfo"), '', '');
567
568 print '<div class="div-table-responsive-no-min">';
569 print '<table class="noborder centpercent">';
570 print '<tr class="liste_titre"><td>'.$langs->trans("Total").'</td>';
571 for ($i = 1; $i <= 12; $i++) {
572 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
573 if ($j > 12) {
574 $j -= 12;
575 }
576 print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT)).'</td>';
577 }
578 print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
579
580 $sql = "SELECT '".$db->escape($langs->trans("CAHTF"))."' AS label,";
581 for ($i = 1; $i <= 12; $i++) {
582 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
583 if ($j > 12) {
584 $j -= 12;
585 }
586 $sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((int) $j), "ffd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
587 }
588 $sql .= " SUM(ffd.total_ht) as total";
589 $sql .= " FROM ".$db->prefix()."facture_fourn_det as ffd";
590 $sql .= " LEFT JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
591 $sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
592 $sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
593 // Define begin binding date
594 if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
595 $sql .= " AND ff.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
596 }
597 $sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
598 $sql .= " AND ff.fk_statut > 0";
599 $sql .= " AND ffd.product_type <= 2";
600 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
601 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.")";
602 } else {
603 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.", ".FactureFournisseur::TYPE_DEPOSIT.")";
604 }
605
606 dol_syslog('htdocs/accountancy/supplier/index.php');
607 $resql = $db->query($sql);
608 if ($resql) {
609 $num = $db->num_rows($resql);
610
611 while ($row = $db->fetch_row($resql)) {
612 print '<tr><td>'.$row[0].'</td>';
613 for ($i = 1; $i <= 12; $i++) {
614 print '<td class="right nowraponall amount">'.price($row[$i]).'</td>';
615 }
616 print '<td class="right nowraponall amount"><b>'.price($row[13]).'</b></td>';
617 print '</tr>';
618 }
619 $db->free($resql);
620 } else {
621 print $db->lasterror(); // Show last sql error
622 }
623 print "</table>\n";
624 print '</div>';
625}
626
627// End of page
628llxFooter();
629$db->close();
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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)
global $mysoc
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:386
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:623
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message 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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
img_next($titlealt='default', $moreatt='')
Show next logo.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.