27 require
'../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/bookkeeping.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancyexport.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
40 $langs->loadLangs(array(
"accountancy",
"compta"));
42 $action =
GETPOST(
'action',
'aZ09');
43 $optioncss =
GETPOST(
'optioncss',
'alpha');
44 $contextpage =
GETPOST(
'contextpage',
'aZ09');
47 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
48 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
49 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
51 if (empty($page) || $page == -1 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha') || (empty($toselect) && $massaction ===
'0')) {
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
60 $show_subgroup =
GETPOST(
'show_subgroup',
'alpha');
63 $search_ledger_code =
GETPOST(
'search_ledger_code',
'array');
64 $search_accountancy_code_start =
GETPOST(
'search_accountancy_code_start',
'alpha');
65 if ($search_accountancy_code_start == - 1) {
66 $search_accountancy_code_start =
'';
68 $search_accountancy_code_end =
GETPOST(
'search_accountancy_code_end',
'alpha');
69 if ($search_accountancy_code_end == - 1) {
70 $search_accountancy_code_end =
'';
75 $hookmanager->initHooks(array(
'balancelist'));
81 if (empty($search_date_start) && !
GETPOSTISSET(
'formfilteraction')) {
82 $sql =
"SELECT date_start, date_end from ".MAIN_DB_PREFIX.
"accounting_fiscalyear ";
83 $sql .=
" WHERE date_start < '".$db->idate(
dol_now()).
"' AND date_end > '".$db->idate(
dol_now()).
"'";
84 $sql .= $db->plimit(1);
85 $res = $db->query($sql);
86 if ($res->num_rows > 0) {
87 $fiscalYear = $db->fetch_object($res);
88 $search_date_start = strtotime($fiscalYear->date_start);
89 $search_date_end = strtotime($fiscalYear->date_end);
91 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
96 $year_end = $year_start + 1;
97 $month_end = $month_start - 1;
102 $search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
106 if ($sortorder ==
"") {
109 if ($sortfield ==
"") {
110 $sortfield =
"t.numero_compte";
115 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
116 $param .=
'&contextpage='.urlencode($contextpage);
118 if ($limit > 0 && $limit != $conf->liste_limit) {
119 $param .=
'&limit='.urlencode($limit);
123 if (!empty($search_date_start)) {
124 $filter[
't.doc_date>='] = $search_date_start;
125 $param .=
'&date_startmonth='.GETPOST(
'date_startmonth',
'int').
'&date_startday='.
GETPOST(
'date_startday',
'int').
'&date_startyear='.
GETPOST(
'date_startyear',
'int');
127 if (!empty($search_date_end)) {
128 $filter[
't.doc_date<='] = $search_date_end;
129 $param .=
'&date_endmonth='.GETPOST(
'date_endmonth',
'int').
'&date_endday='.
GETPOST(
'date_endday',
'int').
'&date_endyear='.
GETPOST(
'date_endyear',
'int');
131 if (!empty($search_accountancy_code_start)) {
132 $filter[
't.numero_compte>='] = $search_accountancy_code_start;
133 $param .=
'&search_accountancy_code_start='.urlencode($search_accountancy_code_start);
135 if (!empty($search_accountancy_code_end)) {
136 $filter[
't.numero_compte<='] = $search_accountancy_code_end;
137 $param .=
'&search_accountancy_code_end='.urlencode($search_accountancy_code_end);
139 if (!empty($search_ledger_code)) {
140 $filter[
't.code_journal'] = $search_ledger_code;
141 foreach ($search_ledger_code as $code) {
142 $param .=
'&search_ledger_code[]='.urlencode($code);
149 if ($user->socid > 0) {
152 if (empty($user->rights->accounting->mouvements->lire)) {
162 $parameters = array();
163 $arrayfields = array();
164 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
169 if (empty($reshook)) {
170 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
172 $search_date_start =
'';
173 $search_date_end =
'';
174 $search_accountancy_code_start =
'';
175 $search_accountancy_code_end =
'';
176 $search_ledger_code = array();
185 if ($action ==
'export_csv') {
186 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
188 $filename =
'balance';
189 $type_export =
'balance';
190 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
192 $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, 0, $filter);
197 foreach ($object->lines as $line) {
198 print
'"'.length_accountg($line->numero_compte).
'"'.$sep;
199 print
'"'.$object->get_compte_desc($line->numero_compte).
'"'.$sep;
200 print
'"'.price($line->debit).
'"'.$sep;
201 print
'"'.price($line->credit).
'"'.$sep;
202 print
'"'.price($line->debit - $line->credit).
'"'.$sep;
210 $title_page = $langs->trans(
"AccountBalance");
215 if ($action !=
'export_csv') {
217 $nbtotalofrecords =
'';
218 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
219 $nbtotalofrecords = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter);
220 if ($nbtotalofrecords < 0) {
225 $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, $offset, $filter);
230 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
231 if ($optioncss !=
'') {
232 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
234 print
'<input type="hidden" name="token" value="'.newToken().
'">';
235 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
236 print
'<input type="hidden" name="action" id="action" value="list">';
237 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
238 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
239 print
'<input type="hidden" name="page" value="'.$page.
'">';
241 $parameters = array();
242 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtonsList', $parameters, $object, $action);
243 if (empty($reshook)) {
244 $button =
'<input type="button" id="exportcsvbutton" name="exportcsvbutton" class="butAction" value="'.$langs->trans(
"Export").
' ('.$conf->global->ACCOUNTING_EXPORT_FORMAT.
')" />';
246 print
'<script type="text/javascript">
247 jQuery(document).ready(function() {
248 jQuery("#exportcsvbutton").click(function() {
249 event.preventDefault();
250 console.log("Set action to export_csv");
251 jQuery("#action").val("export_csv");
252 jQuery("#searchFormList").submit();
253 jQuery("#action").val("list");
259 print_barre_liste($title_page, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $button, $result, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
261 $selectedfields =
'';
265 $moreforfilter .=
'<div class="divsearchfield">';
266 $moreforfilter .= $langs->trans(
'DateStart').
': ';
267 $moreforfilter .=
$form->selectDate($search_date_start ? $search_date_start : -1,
'date_start', 0, 0, 1,
'', 1, 0);
268 $moreforfilter .= $langs->trans(
'DateEnd').
': ';
269 $moreforfilter .=
$form->selectDate($search_date_end ? $search_date_end : -1,
'date_end', 0, 0, 1,
'', 1, 0);
271 $moreforfilter .=
' - ';
272 $moreforfilter .=
'<label for="show_subgroup">'.$langs->trans(
'ShowSubtotalByGroup').
'</label>: ';
273 $moreforfilter .=
'<input type="checkbox" name="show_subgroup" id="show_subgroup" value="show_subgroup"'.($show_subgroup ==
'show_subgroup' ?
' checked' :
'').
'>';
275 $moreforfilter .=
'</div>';
277 $moreforfilter .=
'<div class="divsearchfield">';
279 $moreforfilter .= $langs->trans(
"Journal");
280 $moreforfilter .= $formaccounting->multi_select_journal($search_ledger_code,
'search_ledger_code', 0, 1, 1, 1);
282 $moreforfilter .=
'</div>';
284 if (!empty($moreforfilter)) {
285 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
286 print $moreforfilter;
287 $parameters = array();
288 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
289 print $hookmanager->resPrint;
294 $colspan = (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE) ? 5 : 4);
296 print
'<table class="liste '.($moreforfilter ?
"listwithfilterbefore" :
"").
'">';
298 print
'<tr class="liste_titre_filter">';
299 print
'<td class="liste_titre" colspan="'.$colspan.
'">';
300 print $formaccounting->select_account($search_accountancy_code_start,
'search_accountancy_code_start', $langs->trans(
'From'), array(), 1, 1,
'',
'accounts');
302 print $formaccounting->select_account($search_accountancy_code_end,
'search_accountancy_code_end', $langs->trans(
'to'), array(), 1, 1,
'',
'accounts');
306 $parameters = array(
'arrayfields'=>$arrayfields);
307 $reshook = $hookmanager->executeHooks(
'printFieldListOption', $parameters, $object);
308 print $hookmanager->resPrint;
311 print
'<td class="liste_titre maxwidthsearch">';
312 $searchpicto =
$form->showFilterButtons();
317 print
'<tr class="liste_titre">';
318 print_liste_field_titre(
"AccountAccounting", $_SERVER[
'PHP_SELF'],
"t.numero_compte",
"", $param,
"", $sortfield, $sortorder);
319 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
320 print_liste_field_titre(
"OpeningBalance", $_SERVER[
'PHP_SELF'],
"", $param,
"",
'class="right"', $sortfield, $sortorder);
322 print_liste_field_titre(
"Debit", $_SERVER[
'PHP_SELF'],
"t.debit",
"", $param,
'class="right"', $sortfield, $sortorder);
323 print_liste_field_titre(
"Credit", $_SERVER[
'PHP_SELF'],
"t.credit",
"", $param,
'class="right"', $sortfield, $sortorder);
324 print_liste_field_titre(
"Balance", $_SERVER[
"PHP_SELF"],
"", $param,
"",
'class="right"', $sortfield, $sortorder);
327 $parameters = array(
'arrayfields'=>$arrayfields,
'param'=>$param,
'sortfield'=>$sortfield,
'sortorder'=>$sortorder);
328 $reshook = $hookmanager->executeHooks(
'printFieldListTitle', $parameters, $object);
329 print $hookmanager->resPrint;
331 print
getTitleFieldOfList($selectedfields, 0, $_SERVER[
"PHP_SELF"],
'',
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ').
"\n";
336 $sous_total_debit = 0;
337 $sous_total_credit = 0;
338 $total_opening_balance = 0;
339 $sous_total_opening_balance = 0;
340 $displayed_account =
"";
346 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
347 $sql =
"SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance";
348 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping as t";
349 $sql .=
" WHERE t.entity = " . $conf->entity;
350 $sql .=
" AND t.doc_date < '" . $db->idate($search_date_start) .
"'";
351 $sql .=
" GROUP BY t.numero_compte";
353 $resql = $db->query($sql);
354 $nrows = $db->num_rows(
$resql);
355 $opening_balances = array();
356 for ($i = 0; $i < $nrows; $i++) {
357 $arr =
$resql->fetch_array();
358 $opening_balances[
"'" . $arr[
'numero_compte'] .
"'"] = $arr[
'opening_balance'];
362 foreach ($object->lines as $line) {
364 $accountingaccountstatic->id = 0;
365 $accountingaccountstatic->account_number =
'';
367 $accountingaccountstatic->fetch(null, $line->numero_compte,
true);
368 if (!empty($accountingaccountstatic->account_number)) {
369 $accounting_account = $accountingaccountstatic->getNomUrl(0, 1, 0,
'', 0, -1, 0,
'accountcard');
375 $total_debit += $line->debit;
376 $total_credit += $line->credit;
377 $opening_balance = isset($opening_balances[
"'".$line->numero_compte.
"'"]) ? $opening_balances[
"'".$line->numero_compte.
"'"] : 0;
378 $total_opening_balance += $opening_balance;
380 $tmparrayforrootaccount = $object->getRootAccount($line->numero_compte);
381 $root_account_description = $tmparrayforrootaccount[
'label'];
382 $root_account_number = $tmparrayforrootaccount[
'account_number'];
387 if (empty($accountingaccountstatic->label) && $accountingaccountstatic->id > 0) {
388 $link =
'<a class="editfielda reposition" href="' . DOL_URL_ROOT .
'/accountancy/admin/card.php?action=update&token=' .
newToken() .
'&id=' . $accountingaccountstatic->id .
'">' .
img_edit() .
'</a>';
389 } elseif ($accounting_account ==
'NotDefined') {
390 $link =
'<a href="' . DOL_URL_ROOT .
'/accountancy/admin/card.php?action=create&token=' .
newToken() .
'&accountingaccount=' .
length_accountg($line->numero_compte) .
'">' .
img_edit_add() .
'</a>';
391 } elseif (empty($tmparrayforrootaccount[
'label'])) {
399 if (!empty($show_subgroup)) {
401 if (empty($displayed_account) || $root_account_number != $displayed_account) {
403 if ($displayed_account !=
"") {
404 print
'<tr class="liste_total">';
405 print
'<td class="right">'.$langs->trans(
"SubTotal").
':</td>';
406 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
407 print
'<td class="right nowraponall amount">'.price($sous_total_opening_balance).
'</td>';
409 print
'<td class="right nowraponall amount">'.price($sous_total_debit).
'</td>';
410 print
'<td class="right nowraponall amount">'.price($sous_total_credit).
'</td>';
411 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
412 print
'<td class="right nowraponall amount">'.price(
price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit)).
'</td>';
414 print
'<td class="right nowraponall amount">'.price(
price2num($sous_total_debit - $sous_total_credit)).
'</td>';
421 print
'<tr class="trforbreak">';
422 print
'<td colspan="'.($colspan+1).
'" class="tdforbreak">'.$line->numero_compte.($root_account_description ?
' - '.$root_account_description :
'').
'</td>';
425 $displayed_account = $root_account_number;
426 $sous_total_debit = 0;
427 $sous_total_credit = 0;
428 $sous_total_opening_balance = 0;
432 print
'<tr class="oddeven">';
433 print
'<td>'.$accounting_account.
'</td>';
434 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
435 print
'<td class="right nowraponall amount">'.price(
price2num($opening_balance,
'MT')).
'</td>';
439 if ($line->numero_compte) {
440 $urlzoom = DOL_URL_ROOT.
'/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start='.urlencode($line->numero_compte).
'&search_accountancy_code_end='.urlencode($line->numero_compte);
442 $urlzoom .=
'&search_date_startmonth='.GETPOST(
'date_startmonth',
'int').
'&search_date_startday='.
GETPOST(
'date_startday',
'int').
'&search_date_startyear='.
GETPOST(
'date_startyear',
'int');
445 $urlzoom .=
'&search_date_endmonth='.GETPOST(
'date_endmonth',
'int').
'&search_date_endday='.
GETPOST(
'date_endday',
'int').
'&search_date_endyear='.
GETPOST(
'date_endyear',
'int');
449 print
'<td class="right nowraponall amount"><a href="'.$urlzoom.
'">'.
price(
price2num($line->debit,
'MT')).
'</a></td>';
451 print
'<td class="right nowraponall amount"><a href="'.$urlzoom.
'">'.
price(
price2num($line->credit,
'MT')).
'</a></td>';
453 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
454 print
'<td class="right nowraponall amount">'.price(
price2num($opening_balance + $line->debit - $line->credit,
'MT')).
'</td>';
456 print
'<td class="right nowraponall amount">'.price(
price2num($line->debit - $line->credit,
'MT')).
'</td>';
458 print
'<td class="center">';
464 $sous_total_debit += $line->debit;
465 $sous_total_credit += $line->credit;
466 $sous_total_opening_balance += $opening_balance;
469 if (!empty($show_subgroup)) {
470 print
'<tr class="liste_total"><td class="right">'.$langs->trans(
"SubTotal").
':</td>';
471 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
472 print
'<td class="right nowraponall amount">'.price(
price2num($sous_total_opening_balance,
'MT')).
'</td>';
474 print
'<td class="right nowraponall amount">'.price(
price2num($sous_total_debit,
'MT')).
'</td>';
475 print
'<td class="right nowraponall amount">'.price(
price2num($sous_total_credit,
'MT')).
'</td>';
476 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
477 print
'<td class="right nowraponall amount">' .
price(
price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit,
'MT')) .
'</td>';
479 print
'<td class="right nowraponall amount">' .
price(
price2num($sous_total_debit - $sous_total_credit,
'MT')) .
'</td>';
485 print
'<tr class="liste_total"><td class="right">'.$langs->trans(
"AccountBalance").
':</td>';
486 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
487 print
'<td class="nowrap right">'.price(
price2num($total_opening_balance,
'MT')).
'</td>';
489 print
'<td class="right nowraponall amount">'.price(
price2num($total_debit,
'MT')).
'</td>';
490 print
'<td class="right nowraponall amount">'.price(
price2num($total_credit,
'MT')).
'</td>';
491 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
492 print
'<td class="right nowraponall amount">' .
price(
price2num($total_opening_balance + $total_debit - $total_credit,
'MT')) .
'</td>';
494 print
'<td class="right nowraponall amount">' .
price(
price2num($total_debit - $total_credit,
'MT')) .
'</td>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
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...
dol_now($mode= 'auto')
Return date for now.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
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...
Class to manage Ledger (General Ledger and Subledger)
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
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 ...
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.
img_edit_add($titlealt= 'default', $other= '')
Show logo +.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
isModEnabled($module)
Is Dolibarr module enabled.
Class to manage accounting accounts.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip= '', $forcenowrapcolumntitle=0)
Get title line of an array.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...