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/accountingaccount.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancyexport.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
39 $langs->loadLangs(array(
"accountancy",
"compta"));
42 $sortorder =
GETPOST(
"sortorder",
'alpha');
43 $sortfield =
GETPOST(
"sortfield",
'alpha');
44 $action =
GETPOST(
'action',
'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')) { $page = 0; }
52 $offset = $limit * $page;
53 $pageprev = $page - 1;
54 $pagenext = $page + 1;
58 $show_subgroup =
GETPOST(
'show_subgroup',
'alpha');
62 $search_accountancy_code_start =
GETPOST(
'search_accountancy_code_start',
'alpha');
63 if ($search_accountancy_code_start == - 1) {
64 $search_accountancy_code_start =
'';
66 $search_accountancy_code_end =
GETPOST(
'search_accountancy_code_end',
'alpha');
67 if ($search_accountancy_code_end == - 1) {
68 $search_accountancy_code_end =
'';
75 $form =
new Form($db);
77 if (empty($search_date_start) && !
GETPOSTISSET(
'formfilteraction'))
79 $sql =
"SELECT date_start, date_end from ".MAIN_DB_PREFIX.
"accounting_fiscalyear ";
80 $sql .=
" WHERE date_start < '".$db->idate(
dol_now()).
"' AND date_end > '".$db->idate(
dol_now()).
"'";
81 $sql .= $db->plimit(1);
82 $res = $db->query($sql);
83 if ($res->num_rows > 0) {
84 $fiscalYear = $db->fetch_object($res);
85 $search_date_start = strtotime($fiscalYear->date_start);
86 $search_date_end = strtotime($fiscalYear->date_end);
88 $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
91 $year_end = $year_start + 1;
92 $month_end = $month_start - 1;
98 $search_date_start =
dol_mktime(0, 0, 0, $month_start, 1, $year_start);
102 if ($sortorder ==
"") $sortorder =
"ASC";
103 if ($sortfield ==
"") $sortfield =
"t.numero_compte";
107 if (!empty($contextpage) && $contextpage !=
$_SERVER[
"PHP_SELF"]) $param .=
'&contextpage='.urlencode($contextpage);
108 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
111 if (!empty($search_date_start)) {
112 $filter[
't.doc_date>='] = $search_date_start;
113 $param .=
'&date_startmonth='.GETPOST(
'date_startmonth',
'int').
'&date_startday='.
GETPOST(
'date_startday',
'int').
'&date_startyear='.
GETPOST(
'date_startyear',
'int');
115 if (!empty($search_date_end)) {
116 $filter[
't.doc_date<='] = $search_date_end;
117 $param .=
'&date_endmonth='.GETPOST(
'date_endmonth',
'int').
'&date_endday='.
GETPOST(
'date_endday',
'int').
'&date_endyear='.
GETPOST(
'date_endyear',
'int');
119 if (!empty($search_accountancy_code_start)) {
120 $filter[
't.numero_compte>='] = $search_accountancy_code_start;
121 $param .=
'&search_accountancy_code_start='.$search_accountancy_code_start;
123 if (!empty($search_accountancy_code_end)) {
124 $filter[
't.numero_compte<='] = $search_accountancy_code_end;
125 $param .=
'&search_accountancy_code_end='.$search_accountancy_code_end;
132 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha'))
135 $search_date_start =
'';
136 $search_date_end =
'';
137 $search_accountancy_code_start =
'';
138 $search_accountancy_code_end =
'';
147 if ($action ==
'export_csv')
149 $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
151 $filename =
'balance';
152 $type_export =
'balance';
153 include DOL_DOCUMENT_ROOT.
'/accountancy/tpl/export_journal.tpl.php';
155 $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, 0, $filter);
160 foreach ($object->lines as $line)
163 print $object->get_compte_desc($line->numero_compte).$sep;
166 print price($line->debit - $line->credit).$sep;
174 $title_page = $langs->trans(
"AccountBalance");
179 if ($action !=
'export_csv')
182 $nbtotalofrecords =
'';
183 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
185 $nbtotalofrecords = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter);
186 if ($nbtotalofrecords < 0) {
191 $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, $offset, $filter);
196 print '<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
197 if ($optioncss !=
'')
print '<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
198 print '<input type="hidden" name="token" value="'.newToken().
'">';
199 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
200 print '<input type="hidden" name="action" id="action" value="list">';
201 print '<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
202 print '<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
203 print '<input type="hidden" name="page" value="'.$page.
'">';
205 $button =
'<input type="button" id="exportcsvbutton" name="exportcsvbutton" class="butAction" value="'.$langs->trans(
"Export").
' ('.$conf->global->ACCOUNTING_EXPORT_FORMAT.
')" />';
207 print '<script type="text/javascript" language="javascript">
208 jQuery(document).ready(function() {
209 jQuery("#exportcsvbutton").click(function() {
210 event.preventDefault();
211 console.log("Set action to export_csv");
212 jQuery("#action").val("export_csv");
213 jQuery("#searchFormList").submit();
214 jQuery("#action").val("list");
219 print_barre_liste($title_page, $page,
$_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder, $button, $result, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit);
223 $moreforfilter .=
'<div class="divsearchfield">';
224 $moreforfilter .= $langs->trans(
'DateStart').
': ';
225 $moreforfilter .= $form->selectDate($search_date_start ? $search_date_start : -1,
'date_start', 0, 0, 1,
'', 1, 0);
226 $moreforfilter .= $langs->trans(
'DateEnd').
': ';
227 $moreforfilter .= $form->selectDate($search_date_end ? $search_date_end : -1,
'date_end', 0, 0, 1,
'', 1, 0);
229 $moreforfilter .=
' - ';
230 $moreforfilter .=
'<label for="show_subgroup">'.$langs->trans(
'ShowSubtotalByGroup').
'</label>: ';
231 $moreforfilter .=
'<input type="checkbox" name="show_subgroup" id="show_subgroup" value="show_subgroup"'.($show_subgroup ==
'show_subgroup' ?
' checked' :
'').
'>';
234 $moreforfilter .=
'</div>';
236 if (!empty($moreforfilter)) {
237 print '<div class="liste_titre liste_titre_bydiv centpercent">';
238 print $moreforfilter;
239 $parameters = array();
240 $reshook = $hookmanager->executeHooks(
'printFieldPreListTitle', $parameters);
241 print $hookmanager->resPrint;
245 $colspan = (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE) ? 5 : 4);
247 print '<table class="liste '.($moreforfilter ?
"listwithfilterbefore" :
"").
'">';
249 print '<tr class="liste_titre_filter">';
250 print
'<td class="liste_titre" colspan="'.$colspan.
'">';
251 print $langs->trans(
'From');
252 print $formaccounting->select_account($search_accountancy_code_start,
'search_accountancy_code_start', 1, array(), 1, 1,
'');
254 print $langs->trans(
'to');
255 print $formaccounting->select_account($search_accountancy_code_end,
'search_accountancy_code_end', 1, array(), 1, 1,
'');
257 print
'<td class="liste_titre center">';
258 $searchpicto = $form->showFilterButtons();
264 print
'<tr class="liste_titre">';
266 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE))
print_liste_field_titre(
"OpeningBalance",
$_SERVER[
'PHP_SELF'],
"", $param,
"",
'class="right"', $sortfield, $sortorder);
275 $sous_total_debit = 0;
276 $sous_total_credit = 0;
277 $total_opening_balance = 0;
278 $sous_total_opening_balance = 0;
279 $displayed_account =
"";
285 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
286 $sql =
"SELECT t.numero_compte, (SUM(t.debit) - SUM(t.credit)) as opening_balance";
287 $sql .=
" FROM " . MAIN_DB_PREFIX .
"accounting_bookkeeping as t";
288 $sql .=
" WHERE t.entity = " . $conf->entity;
289 $sql .=
" AND t.doc_date < '" . $db->idate($search_date_start) .
"'";
290 $sql .=
" GROUP BY t.numero_compte";
292 $resql = $db->query($sql);
293 $nrows =
$resql->num_rows;
294 $opening_balances = array();
295 for ($i = 0; $i < $nrows; $i++) {
296 $arr =
$resql->fetch_array();
297 $opening_balances[
"'" . $arr[
'numero_compte'] .
"'"] = $arr[
'opening_balance'];
301 foreach ($object->lines as $line)
304 $accountingaccountstatic->id = 0;
305 $accountingaccountstatic->account_number =
'';
307 $accountingaccountstatic->fetch(null, $line->numero_compte,
true);
308 if (!empty($accountingaccountstatic->account_number)) {
309 $accounting_account = $accountingaccountstatic->getNomUrl(0, 1, 0,
'', 0, -1, 0,
'accountcard');
315 $total_debit += $line->debit;
316 $total_credit += $line->credit;
317 $opening_balance = isset($opening_balances[
"'".$line->numero_compte.
"'"]) ? $opening_balances[
"'".$line->numero_compte.
"'"] : 0;
318 $total_opening_balance += $opening_balance;
320 $tmparrayforrootaccount = $object->getRootAccount($line->numero_compte);
321 $root_account_description = $tmparrayforrootaccount[
'label'];
322 $root_account_number = $tmparrayforrootaccount[
'account_number'];
327 if (empty($accountingaccountstatic->label) && $accountingaccountstatic->id > 0) {
328 $link =
'<a class="editfielda reposition" href="' . DOL_URL_ROOT .
'/accountancy/admin/card.php?action=update&token=' .
newToken() .
'&id=' . $accountingaccountstatic->id .
'">' .
img_edit() .
'</a>';
329 } elseif ($accounting_account ==
'NotDefined') {
330 $link =
'<a href="' . DOL_URL_ROOT .
'/accountancy/admin/card.php?action=create&token=' .
newToken() .
'&accountingaccount=' .
length_accountg($line->numero_compte) .
'">' .
img_edit_add() .
'</a>';
331 } elseif (empty($tmparrayforrootaccount[
'label'])) {
339 if (!empty($show_subgroup))
342 if (empty($displayed_account) || $root_account_number != $displayed_account) {
344 if ($displayed_account !=
"") {
345 print
'<tr class="liste_total">';
346 print
'<td class="right">'.$langs->trans(
"SubTotal").
':</td>';
347 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print
'<td class="nowrap right">'.price($sous_total_opening_balance).
'</td>';
348 print
'<td class="nowrap right">'.price($sous_total_debit).
'</td>';
349 print
'<td class="nowrap right">'.price($sous_total_credit).
'</td>';
350 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
351 print
'<td class="nowrap right">'.price(
price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit)).
'</td>';
353 print
'<td class="nowrap right">'.price(
price2num($sous_total_debit - $sous_total_credit)).
'</td>';
360 print
'<tr class="trforbreak">';
361 print
'<td colspan="'.($colspan+1).
'" style="font-weight:bold; border-bottom: 1pt solid black;">'.$line->numero_compte.($root_account_description ?
' - '.$root_account_description :
'').
'</td>';
364 $displayed_account = $root_account_number;
365 $sous_total_debit = 0;
366 $sous_total_credit = 0;
367 $sous_total_opening_balance = 0;
371 print
'<tr class="oddeven">';
372 print
'<td>'.$accounting_account.
'</td>';
373 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print
'<td class="nowraponall right">'.
price($opening_balance).
'</td>';
376 if ($line->numero_compte) {
377 $urlzoom = DOL_URL_ROOT.
'/accountancy/bookkeeping/listbyaccount.php?search_accountancy_code_start='.urlencode($line->numero_compte).
'&search_accountancy_code_end='.urlencode($line->numero_compte);
379 $urlzoom .=
'&search_date_startmonth='.GETPOST(
'date_startmonth',
'int').
'&search_date_startday='.
GETPOST(
'date_startday',
'int').
'&search_date_startyear='.
GETPOST(
'date_startyear',
'int');
382 $urlzoom .=
'&search_date_endmonth='.GETPOST(
'date_endmonth',
'int').
'&search_date_endday='.
GETPOST(
'date_endday',
'int').
'&search_date_endyear='.
GETPOST(
'date_endyear',
'int');
386 print
'<td class="nowraponall right"><a href="'.$urlzoom.
'">'.
price($line->debit).
'</a></td>';
388 print
'<td class="nowraponall right"><a href="'.$urlzoom.
'">'.
price($line->credit).
'</a></td>';
390 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
391 print
'<td class="nowraponall right">'.price(
price2num($opening_balance + $line->debit - $line->credit,
'MT')).
'</td>';
393 print
'<td class="nowraponall right">'.price(
price2num($line->debit - $line->credit,
'MT')).
'</td>';
395 print
'<td class="center">'.$link;
400 $sous_total_debit += $line->debit;
401 $sous_total_credit += $line->credit;
402 $sous_total_opening_balance += $opening_balance;
405 if (!empty($show_subgroup))
407 print
'<tr class="liste_total"><td class="right">'.$langs->trans(
"SubTotal").
':</td>';
408 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print
'<td class="nowrap right">'.price($sous_total_opening_balance).
'</td>';
409 print
'<td class="nowrap right">'.price($sous_total_debit).
'</td>';
410 print
'<td class="nowrap right">'.price($sous_total_credit).
'</td>';
411 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
412 print
'<td class="nowrap right">' .
price(
price2num($sous_total_opening_balance + $sous_total_debit - $sous_total_credit,
'MT')) .
'</td>';
414 print
'<td class="nowrap right">' .
price(
price2num($sous_total_debit - $sous_total_credit,
'MT')) .
'</td>';
420 print
'<tr class="liste_total"><td class="right">'.$langs->trans(
"AccountBalance").
':</td>';
421 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) print
'<td class="nowrap right">'.price($total_opening_balance).
'</td>';
422 print
'<td class="nowrap right">'.price($total_debit).
'</td>';
423 print
'<td class="nowrap right">'.price($total_credit).
'</td>';
424 if (!empty($conf->global->ACCOUNTANCY_SHOW_OPENING_BALANCE)) {
425 print
'<td class="nowrap right">' .
price(
price2num($total_opening_balance + $total_debit - $total_credit,
'MT')) .
'</td>';
427 print
'<td class="nowrap right">' .
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.
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.
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.
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 '...
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Class to manage accounting accounts.
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...