dolibarr 23.0.3
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';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
36
46// Load translation files required by the page
47$langs->loadLangs(array("compta", "bills", "other", "accountancy"));
48
49$validatemonth = GETPOSTINT('validatemonth');
50$validateyear = GETPOSTINT('validateyear');
51
52$accountingAccount = new AccountingAccount($db);
53
54$month_start = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
55if (GETPOSTINT("year")) {
56 $year_start = GETPOSTINT("year");
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;
65if ($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$error = 0;
73
74// Validate History
75$action = GETPOST('action', 'aZ09');
76
77$chartaccountcode = dol_getIdFromCode($db, getDolGlobalString('CHARTOFACCOUNTS'), 'accounting_system', 'rowid', 'pcg_version');
78
79// Security check
80if (!isModEnabled('accounting')) {
82}
83if ($user->socid > 0) {
85}
86if (!$user->hasRight('accounting', 'bind', 'write')) {
88}
89
90
91/*
92 * Actions
93 */
94
95if (($action == 'clean' || $action == 'validatehistory') && $user->hasRight('accounting', 'bind', 'write')) {
96 // Clean database by removing binding done on non existing or no more existing accounts
97 $db->begin();
98 $sql1 = "UPDATE ".$db->prefix()."facture_fourn_det as fd";
99 $sql1 .= " SET fk_code_ventilation = 0";
100 $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN';
101 $sql1 .= ' (SELECT accnt.rowid ';
102 $sql1 .= " FROM ".$db->prefix()."accounting_account as accnt";
103 $sql1 .= " INNER JOIN ".$db->prefix()."accounting_system as syst";
104 $sql1 .= " ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid = ".getDolGlobalInt('CHARTOFACCOUNTS')." AND accnt.entity = ".((int) $conf->entity).")";
105 $sql1 .= " AND fd.fk_facture_fourn IN (SELECT rowid FROM ".$db->prefix()."facture_fourn WHERE entity = ".((int) $conf->entity).")";
106 $sql1 .= " AND fk_code_ventilation <> 0";
107
108 dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG);
109 $resql1 = $db->query($sql1);
110 if (!$resql1) {
111 $error++;
112 $db->rollback();
113 setEventMessages($db->lasterror(), null, 'errors');
114 } else {
115 $db->commit();
116 }
117 // End clean database
118}
119
120if ($action == 'validatehistory' && $user->hasRight('accounting', 'bind', 'write')) {
121 $error = 0;
122 $nbbinddone = 0;
123 $nbbindfailed = 0;
124 $notpossible = 0;
125
126 $db->begin();
127
128 // Now make the binding. Bind automatically only for product with a dedicated account that exists into chart of account, others need a manual bind
129 // Supplier Invoice Lines (must be same request than into page list.php for manual binding)
130 $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,";
131 $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,";
132 $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,";
133 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
134 $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,";
135 } else {
136 $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,";
137 }
138 $sql .= " aa.rowid as aarowid, aa2.rowid as aarowid_intra, aa3.rowid as aarowid_export, aa4.rowid as aarowid_thirdparty,";
139 $sql .= " co.code as country_code, co.label as country_label,";
140 $sql .= " s.tva_intra,";
141 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
142 $sql .= " spe.accountancy_code_buy as company_code_buy";
143 } else {
144 $sql .= " s.accountancy_code_buy as company_code_buy";
145 }
146 $sql .= " FROM ".$db->prefix()."facture_fourn as f";
147 $sql .= " INNER JOIN ".$db->prefix()."societe as s ON s.rowid = f.fk_soc";
148 if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
149 $sql .= " LEFT JOIN " . $db->prefix() . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
150 }
151 $sql .= " LEFT JOIN ".$db->prefix()."c_country as co ON co.rowid = s.fk_pays ";
152 $sql .= " INNER JOIN ".$db->prefix()."facture_fourn_det as l ON f.rowid = l.fk_facture_fourn";
153 $sql .= " LEFT JOIN ".$db->prefix()."product as p ON p.rowid = l.fk_product";
154 if (getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED')) {
155 $sql .= " LEFT JOIN " . $db->prefix() . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
156 }
157 $alias_societe_perentity = !getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED') ? "s" : "spe";
158 $alias_product_perentity = !getDolGlobalString('MAIN_PRODUCT_PERENTITY_SHARED') ? "p" : "ppe";
159 $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;
160 $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;
161 $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;
162 $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;
163 $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0";
164 $sql .= " AND l.product_type <= 2";
165 $sql .= " AND f.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
166 if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
167 $sql .= " AND f.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
168 }
169 if ($validatemonth && $validateyear) {
170 $sql .= dolSqlDateFilter('f.datef', 0, $validatemonth, $validateyear);
171 }
172
173 dol_syslog('htdocs/accountancy/supplier/index.php');
174
175 $result = $db->query($sql);
176 if (!$result) {
177 $error++;
178 setEventMessages($db->lasterror(), null, 'errors');
179 } else {
180 $num_lines = $db->num_rows($result);
181
182 $isBuyerInEEC = isInEEC($mysoc);
183
184 $thirdpartystatic = new Societe($db);
185 $facture_static = new FactureFournisseur($db);
186 $facture_static_det = new SupplierInvoiceLine($db);
187 $product_static = new Product($db);
188
189 $i = 0;
190 while ($i < min($num_lines, 10000)) { // No more than 10000 at once
191 $objp = $db->fetch_object($result);
192
193 $thirdpartystatic->id = !empty($objp->socid) ? $objp->socid : 0;
194 $thirdpartystatic->name = !empty($objp->name) ? $objp->name : "";
195 $thirdpartystatic->client = !empty($objp->client) ? $objp->client : "";
196 $thirdpartystatic->fournisseur = !empty($objp->fournisseur) ? $objp->fournisseur : "";
197 $thirdpartystatic->code_client = !empty($objp->code_client) ? $objp->code_client : "";
198 $thirdpartystatic->code_compta_client = !empty($objp->code_compta_client) ? $objp->code_compta_client : "";
199 $thirdpartystatic->code_fournisseur = !empty($objp->code_fournisseur) ? $objp->code_fournisseur : "";
200 $thirdpartystatic->code_compta_fournisseur = !empty($objp->code_compta_fournisseur) ? $objp->code_compta_fournisseur : "";
201 $thirdpartystatic->email = !empty($objp->email) ? $objp->email : "";
202 $thirdpartystatic->country_code = !empty($objp->country_code) ? $objp->country_code : "";
203 $thirdpartystatic->tva_intra = !empty($objp->tva_intra) ? $objp->tva_intra : "";
204 $thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion)
205
206 $product_static->ref = $objp->product_ref;
207 $product_static->id = $objp->product_id;
208 $product_static->type = $objp->type;
209 $product_static->label = $objp->product_label;
210 $product_static->status = !empty($objp->status) ? $objp->status : 0;
211 $product_static->status_buy = !empty($objp->status_buy) ? $objp->status_buy : 0;
212 $product_static->accountancy_code_sell = !empty($objp->code_sell)? $objp->code_sell : "";
213 $product_static->accountancy_code_sell_intra = !empty($objp->code_sell_intra)? $objp->code_sell_intra : "";
214 $product_static->accountancy_code_sell_export = !empty($objp->code_sell_export)? $objp->code_sell_export : "";
215 $product_static->accountancy_code_buy = !empty($objp->code_buy) ? $objp->code_buy : "";
216 $product_static->accountancy_code_buy_intra = !empty($objp->code_buy_intra) ? $objp->code_buy_intra : "";
217 $product_static->accountancy_code_buy_export = !empty($objp->code_buy_export) ? $objp->code_buy_export : "";
218 $product_static->tva_tx = $objp->tva_tx_prod;
219
220 $facture_static->ref = $objp->ref;
221 $facture_static->id = $objp->facid;
222 $facture_static->type = $objp->ftype;
223 $facture_static->ref_supplier = $objp->ref_supplier;
224 $facture_static->label = $objp->invoice_label;
225 $facture_static->date = $db->jdate($objp->datef);
226 $facture_static->fk_facture_source = $objp->fk_facture_source;
227
228 $facture_static_det->id = $objp->rowid;
229 $facture_static_det->total_ht = $objp->total_ht;
230 $facture_static_det->tva_tx = $objp->tva_tx_line;
231 $facture_static_det->vat_src_code = $objp->vat_src_code;
232 $facture_static_det->product_type = $objp->type_l;
233 $facture_static_det->desc = $objp->description;
234
235 $accountingAccountArray = array(
236 'dom' => $objp->aarowid,
237 'intra' => $objp->aarowid_intra,
238 'export' => $objp->aarowid_export,
239 'thirdparty' => $objp->aarowid_thirdparty);
240
241 $code_buy_p_notset = '';
242 $code_buy_t_notset = '';
243
244 $suggestedid = 0;
245
246 $return = $accountingAccount->getAccountingCodeToBind($mysoc, $thirdpartystatic, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'supplier');
247 if (!is_array($return) && $return < 0) {
248 setEventMessage($accountingAccount->error, 'errors');
249 } else {
250 $suggestedid = $return['suggestedid'];
251 $suggestedaccountingaccountfor = $return['suggestedaccountingaccountfor'];
252
253 if (!empty($suggestedid) && $suggestedaccountingaccountfor != '' && $suggestedaccountingaccountfor != 'eecwithoutvatnumber') {
254 $suggestedid = $return['suggestedid'];
255 } else {
256 $suggestedid = 0;
257 }
258 }
259
260 if ($suggestedid > 0) {
261 $sqlupdate = "UPDATE ".$db->prefix()."facture_fourn_det";
262 $sqlupdate .= " SET fk_code_ventilation = ".((int) $suggestedid);
263 $sqlupdate .= " WHERE fk_code_ventilation <= 0 AND product_type <= 2 AND rowid = ".((int) $facture_static_det->id);
264
265 $resqlupdate = $db->query($sqlupdate);
266 if (!$resqlupdate) {
267 $error++;
268 setEventMessages($db->lasterror(), null, 'errors');
269 $nbbindfailed++;
270 break;
271 } else {
272 $nbbinddone++;
273 }
274 } else {
275 $notpossible++;
276 $nbbindfailed++;
277 }
278
279 $i++;
280 }
281 if ($num_lines > 10000) {
282 $notpossible += ($num_lines - 10000);
283 }
284 }
285
286 if ($error) {
287 $db->rollback();
288 } else {
289 $db->commit();
290 setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone, $notpossible), null, ($notpossible ? 'warnings' : 'mesgs'));
291 if ($nbbindfailed) {
292 setEventMessages($langs->trans('DoManualBindingForFailedRecord', $nbbindfailed), null, 'warnings');
293 }
294 }
295}
296
297
298/*
299 * View
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 '<span class="opacitymedium">'.$langs->trans("DescVentilSupplier").'</span><br>';
311print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")).'<br>';
312print '</span><br>';
313
314$y = $year_current;
315
316$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>';
317
318
319print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1, 0, $buttonbind);
320//print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, '');
321
322print '<div class="div-table-responsive-no-min">';
323print '<table class="noborder centpercent">';
324print '<tr class="liste_titre"><td class="minwidth100">'.$langs->trans("Account").'</td>';
325for ($i = 1; $i <= 12; $i++) {
326 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
327 if ($j > 12) {
328 $j -= 12;
329 }
330 $cursormonth = $j;
331 if ($cursormonth > 12) {
332 $cursormonth -= 12;
333 }
334 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
335 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
336
337 print '<td width="60" class="right">';
338 if (!empty($tmp['mday'])) {
339 $param = 'search_date_startday=1&search_date_startmonth='.$cursormonth.'&search_date_startyear='.$cursoryear;
340 $param .= '&search_date_endday='.$tmp['mday'].'&search_date_endmonth='.$tmp['mon'].'&search_date_endyear='.$tmp['year'];
341 print '<a href="'.DOL_URL_ROOT.'/accountancy/supplier/list.php?'.$param.'">';
342 }
343 print $langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT));
344 if (!empty($tmp['mday'])) {
345 print '</a>';
346 }
347 print '</td>';
348}
349print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
350
351$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number')." AS codecomptable,";
352$sql .= " ".$db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label')." AS intitule,";
353for ($i = 1; $i <= 12; $i++) {
354 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
355 if ($j > 12) {
356 $j -= 12;
357 }
358 $sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((int) $j), "ffd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
359 $sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((string) $j), "1", "0").") AS nbmonth".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
360}
361$sql .= " SUM(ffd.total_ht) as total, COUNT(ffd.rowid) as nb";
362$sql .= " FROM ".$db->prefix()."facture_fourn_det as ffd";
363$sql .= " LEFT JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
364$sql .= " LEFT JOIN ".$db->prefix()."accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
365$sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
366$sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
367// Define begin binding date
368if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
369 $sql .= " AND ff.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
370}
371$sql .= " AND ff.fk_statut > 0";
372$sql .= " AND ffd.product_type <= 2";
373$sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
374$sql .= " AND aa.account_number IS NULL";
375if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
376 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.")";
377} else {
378 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.",".FactureFournisseur::TYPE_REPLACEMENT.",".FactureFournisseur::TYPE_CREDIT_NOTE.",".FactureFournisseur::TYPE_DEPOSIT.")";
379}
380$sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
381
382dol_syslog('htdocs/accountancy/supplier/index.php', LOG_DEBUG);
383$resql = $db->query($sql);
384if ($resql) {
385 $num = $db->num_rows($resql);
386
387 while ($row = $db->fetch_row($resql)) {
388 print '<tr class="oddeven">';
389 print '<td>';
390 if ($row[0] == 'tobind') {
391 //print '<span class="opacitymedium">'.$langs->trans("Unknown").'</span>';
392 } else {
393 print length_accountg($row[0]).' - ';
394 }
395 //print '</td>';
396 //print '<td>';
397 if ($row[0] == 'tobind') {
398 $startmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
399 if ($startmonth > 12) {
400 $startmonth -= 12;
401 }
402 $startyear = ($startmonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
403 $endmonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) + 11;
404 if ($endmonth > 12) {
405 $endmonth -= 12;
406 }
407 $endyear = ($endmonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
408 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"));
409 } else {
410 print $row[1];
411 }
412 print '</td>';
413 for ($i = 2; $i <= 13; $i++) {
414 $cursormonth = (getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) + $i - 2);
415 if ($cursormonth > 12) {
416 $cursormonth -= 12;
417 }
418 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
419 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
420
421 print '<td class="right nowraponall amount" title="'.price($row[2 * $i - 2]).' - '.$row[2 * $i - 1].' lines">';
422 print price($row[2 * $i - 2]);
423 // Add link to make binding
424 if (!empty(price2num($row[2 * $i - 2])) || !empty($row[2 * $i - 1])) {
425 print '<a href="'.$_SERVER['PHP_SELF'].'?action=validatehistory&year='.$y.'&validatemonth='.((int) $cursormonth).'&validateyear='.((int) $cursoryear).'&token='.newToken().'">';
426 print img_picto($langs->trans("ValidateHistory").' ('.$langs->trans('Month'.str_pad((string) $cursormonth, 2, '0', STR_PAD_LEFT)).' '.$cursoryear.')', 'link', 'class="marginleft2"');
427 print '</a>';
428 }
429 print '</td>';
430 }
431 print '<td class="right nowraponall amount"><b>'.price($row[26]).'</b></td>';
432 print '</tr>';
433 }
434 $db->free($resql);
435
436 if ($num == 0) {
437 print '<tr class="oddeven"><td colspan="15">';
438 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
439 print '</td></tr>';
440 }
441} else {
442 print $db->lasterror(); // Show last sql error
443}
444print "</table>\n";
445print '</div>';
446
447
448print '<br>';
449
450
451print_barre_liste(img_picto('', 'link', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesBound"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
452//print load_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), '', '');
453
454print '<div class="div-table-responsive-no-min">';
455print '<table class="noborder centpercent">';
456print '<tr class="liste_titre"><td class="minwidth100">'.$langs->trans("Account").'</td>';
457for ($i = 1; $i <= 12; $i++) {
458 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
459 if ($j > 12) {
460 $j -= 12;
461 }
462 $cursormonth = $j;
463 if ($cursormonth > 12) {
464 $cursormonth -= 12;
465 }
466 $cursoryear = ($cursormonth < getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1)) ? $y + 1 : $y;
467 $tmp = dol_getdate(dol_get_last_day($cursoryear, $cursormonth, 'gmt'), false, 'gmt');
468
469 print '<td width="60" class="right">';
470 if (!empty($tmp['mday'])) {
471 $param = 'search_date_startday=1&search_date_startmonth='.$cursormonth.'&search_date_startyear='.$cursoryear;
472 $param .= '&search_date_endday='.$tmp['mday'].'&search_date_endmonth='.$tmp['mon'].'&search_date_endyear='.$tmp['year'];
473 print '<a href="'.DOL_URL_ROOT.'/accountancy/supplier/lines.php?'.$param.'">';
474 }
475 print $langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT));
476 if (!empty($tmp['mday'])) {
477 print '</a>';
478 }
479 print '</td>';
480}
481print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
482
483$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'tobind'", 'aa.account_number')." AS codecomptable,";
484$sql .= " ".$db->ifsql('aa.label IS NULL', "'tobind'", 'aa.label')." AS intitule,";
485for ($i = 1; $i <= 12; $i++) {
486 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
487 if ($j > 12) {
488 $j -= 12;
489 }
490 $sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((int) $j), "ffd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
491}
492$sql .= " SUM(ffd.total_ht) as total";
493$sql .= " FROM ".$db->prefix()."facture_fourn_det as ffd";
494$sql .= " LEFT JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
495$sql .= " LEFT JOIN ".$db->prefix()."accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation";
496$sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
497$sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
498// Define begin binding date
499if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
500 $sql .= " AND ff.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
501}
502$sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
503$sql .= " AND ff.fk_statut > 0";
504$sql .= " AND ffd.product_type <= 2";
505if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
506 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.")";
507} else {
508 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.", ".FactureFournisseur::TYPE_DEPOSIT.")";
509}
510$sql .= " AND aa.account_number IS NOT NULL";
511$sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label";
512$sql .= ' ORDER BY aa.account_number';
513
514dol_syslog('htdocs/accountancy/supplier/index.php');
515$resql = $db->query($sql);
516if ($resql) {
517 $num = $db->num_rows($resql);
518
519 while ($row = $db->fetch_row($resql)) {
520 print '<tr class="oddeven">';
521 print '<td class="tdoverflowmax300"'.(empty($row[1]) ? '' : ' title="'.dol_escape_htmltag($row[1]).'"').'>';
522 if ($row[0] == 'tobind') {
523 //print $langs->trans("Unknown");
524 } else {
525 print length_accountg($row[0]).' - ';
526 }
527 //print '</td>';
528
529 //print '<td class="tdoverflowmax300"'.(empty($row[1]) ? '' : ' title="'.dol_escape_htmltag($row[1]).'"').'>';
530 if ($row[0] == 'tobind') {
531 print $langs->trans("UseMenuToSetBindindManualy", DOL_URL_ROOT.'/accountancy/supplier/list.php?search_year='.((int) $y), $langs->transnoentitiesnoconv("ToBind"));
532 } else {
533 print dol_escape_htmltag($row[1]);
534 }
535 print '</td>';
536
537 for ($i = 2; $i <= 13; $i++) {
538 print '<td class="right nowraponall amount">';
539 print price($row[$i]);
540 print '</td>';
541 }
542 print '<td class="right nowraponall amount"><b>'.price($row[14]).'</b></td>';
543 print '</tr>';
544 }
545 $db->free($resql);
546
547 if ($num == 0) {
548 print '<tr class="oddeven"><td colspan="15">';
549 print '<span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span>';
550 print '</td></tr>';
551 }
552} else {
553 print $db->lasterror(); // Show last sql error
554}
555print "</table>\n";
556print '</div>';
557
558
559if (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 ?
560 print '<br>';
561 print '<br>';
562
563 print_barre_liste($langs->trans("OtherInfo"), 0, '', '', '', '', '', -1, '', '', 0, '', '', 0, 1, 1);
564 //print load_fiche_titre($langs->trans("OtherInfo"), '', '');
565
566 print '<div class="div-table-responsive-no-min">';
567 print '<table class="noborder centpercent">';
568 print '<tr class="liste_titre"><td>'.$langs->trans("Total").'</td>';
569 for ($i = 1; $i <= 12; $i++) {
570 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
571 if ($j > 12) {
572 $j -= 12;
573 }
574 print '<td width="60" class="right">'.$langs->trans('MonthShort'.str_pad((string) $j, 2, '0', STR_PAD_LEFT)).'</td>';
575 }
576 print '<td width="60" class="right"><b>'.$langs->trans("Total").'</b></td></tr>';
577
578 $sql = "SELECT '".$db->escape($langs->trans("CAHTF"))."' AS label,";
579 for ($i = 1; $i <= 12; $i++) {
580 $j = $i + getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1) - 1;
581 if ($j > 12) {
582 $j -= 12;
583 }
584 $sql .= " SUM(".$db->ifsql("MONTH(ff.datef) = ".((int) $j), "ffd.total_ht", "0").") AS month".str_pad((string) $j, 2, "0", STR_PAD_LEFT).",";
585 }
586 $sql .= " SUM(ffd.total_ht) as total";
587 $sql .= " FROM ".$db->prefix()."facture_fourn_det as ffd";
588 $sql .= " LEFT JOIN ".$db->prefix()."facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn";
589 $sql .= " WHERE ff.datef >= '".$db->idate($search_date_start)."'";
590 $sql .= " AND ff.datef <= '".$db->idate($search_date_end)."'";
591 // Define begin binding date
592 if (getDolGlobalInt('ACCOUNTING_DATE_START_BINDING')) {
593 $sql .= " AND ff.datef >= '".$db->idate(getDolGlobalInt('ACCOUNTING_DATE_START_BINDING'))."'";
594 }
595 $sql .= " AND ff.entity IN (".getEntity('facture_fourn', 0).")"; // We don't share object for accountancy
596 $sql .= " AND ff.fk_statut > 0";
597 $sql .= " AND ffd.product_type <= 2";
598 if (getDolGlobalString('FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS')) {
599 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.")";
600 } else {
601 $sql .= " AND ff.type IN (".FactureFournisseur::TYPE_STANDARD.", ".FactureFournisseur::TYPE_REPLACEMENT.", ".FactureFournisseur::TYPE_CREDIT_NOTE.", ".FactureFournisseur::TYPE_DEPOSIT.")";
602 }
603
604 dol_syslog('htdocs/accountancy/supplier/index.php');
605 $resql = $db->query($sql);
606 if ($resql) {
607 $num = $db->num_rows($resql);
608
609 while ($row = $db->fetch_row($resql)) {
610 print '<tr><td>'.$row[0].'</td>';
611 for ($i = 1; $i <= 12; $i++) {
612 print '<td class="right nowraponall amount">'.price($row[$i]).'</td>';
613 }
614 print '<td class="right nowraponall amount"><b>'.price($row[13]).'</b></td>';
615 print '</tr>';
616 }
617 $db->free($resql);
618 } else {
619 print $db->lasterror(); // Show last sql error
620 }
621 print "</table>\n";
622 print '</div>';
623}
624
625// End of page
626llxFooter();
627$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:385
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:622
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.
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.
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.