dolibarr  13.0.2
accounting.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
4  * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
5  * Copyright (C) 2019 Eric Seigne <eric.seigne@cap-rel.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
37 function is_empty($var, $allow_false = false, $allow_ws = false)
38 {
39  if (!isset($var) || is_null($var) || ($allow_ws == false && trim($var) == "" && !is_bool($var)) || ($allow_false === false && is_bool($var) && $var === false) || (is_array($var) && empty($var))) {
40  return true;
41  }
42  return false;
43 }
44 
52 {
53  global $langs, $conf;
54 
55  $h = 0;
56  $head = array();
57 
58  $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id='.$object->id;
59  $head[$h][1] = $langs->trans("AccountAccounting");
60  $head[$h][2] = 'card';
61  $h++;
62 
63  // Show more tabs from modules
64  // Entries must be declared in modules descriptor with line
65  // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
66  // $this->tabs = array('entity:-tabname); to remove a tab
67  complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account');
68 
69  complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove');
70 
71  return $head;
72 }
73 
80 function clean_account($account)
81 {
82  $account = rtrim($account, "0");
83 
84  return $account;
85 }
86 
93 function length_accountg($account)
94 {
95  global $conf;
96 
97  if ($account < 0 || is_empty($account)) return '';
98 
99  if (!empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account;
100 
101  $g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT;
102  if (!is_empty($g)) {
103  // Clean parameters
104  $i = strlen($account);
105 
106  if ($i >= 1) {
107  while ($i < $g) {
108  $account .= '0';
109 
110  $i++;
111  }
112 
113  return $account;
114  } else {
115  return $account;
116  }
117  } else {
118  return $account;
119  }
120 }
121 
128 function length_accounta($accounta)
129 {
130  global $conf;
131 
132  if ($accounta < 0 || is_empty($accounta)) return '';
133 
134  if (!empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta;
135 
136  $a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT;
137  if (!is_empty($a)) {
138  // Clean parameters
139  $i = strlen($accounta);
140 
141  if ($i >= 1) {
142  while ($i < $a) {
143  $accounta .= '0';
144 
145  $i++;
146  }
147 
148  return $accounta;
149  } else {
150  return $accounta;
151  }
152  } else {
153  return $accounta;
154  }
155 }
156 
157 
158 
174 function journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink = '', $moreparam = array(), $calcmode = '', $varlink = '')
175 {
176  global $langs;
177 
178  print "\n\n<!-- start banner journal -->\n";
179 
180  if (!is_empty($varlink)) $varlink = '?'.$varlink;
181 
182  $head = array();
183  $h = 0;
184  $head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
185  $head[$h][1] = $langs->trans("Journalization");
186  $head[$h][2] = 'journal';
187 
188  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].$varlink.'">';
189  print '<input type="hidden" name="token" value="'.newToken().'">';
190 
191  print dol_get_fiche_head($head, 'journal');
192 
193  foreach ($moreparam as $key => $value)
194  {
195  print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
196  }
197  print '<table width="100%" class="border">';
198 
199  // Ligne de titre
200  print '<tr>';
201  print '<td width="110">'.$langs->trans("Name").'</td>';
202  print '<td colspan="3">';
203  print $nom;
204  print '</td>';
205  print '</tr>';
206 
207  // Calculation mode
208  if ($calcmode)
209  {
210  print '<tr>';
211  print '<td width="110">'.$langs->trans("CalculationMode").'</td>';
212  if (!$variante) print '<td colspan="3">';
213  else print '<td>';
214  print $calcmode;
215  if ($variante) print '</td><td colspan="2">'.$variante;
216  print '</td>';
217  print '</tr>';
218  }
219 
220  // Ligne de la periode d'analyse du rapport
221  print '<tr>';
222  print '<td>'.$langs->trans("ReportPeriod").'</td>';
223  if (!$periodlink) print '<td colspan="3">';
224  else print '<td>';
225  if ($period) print $period;
226  if ($periodlink) print '</td><td colspan="2">'.$periodlink;
227  print '</td>';
228  print '</tr>';
229 
230  // Ligne de description
231  print '<tr>';
232  print '<td>'.$langs->trans("ReportDescription").'</td>';
233  print '<td colspan="3">'.$description.'</td>';
234  print '</tr>';
235 
236  print '</table>';
237 
239 
240  print '<div class="center"><input type="submit" class="button" name="submit" value="'.$langs->trans("Refresh").'"></div>';
241 
242  print '</form>';
243 
244  print "\n<!-- end banner journal -->\n\n";
245 }
246 
253 {
254  global $db, $conf;
255 
256  // Period by default on transfer (0: previous month | 1: current month | 2: fiscal year)
257  $periodbydefaultontransfer = $conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER;
258  isset($periodbydefaultontransfer) ? $periodbydefaultontransfer : 0;
259  if ($periodbydefaultontransfer == 2) {
260  $sql = "SELECT date_start, date_end from ".MAIN_DB_PREFIX."accounting_fiscalyear ";
261  $sql .= " where date_start < '".$db->idate(dol_now())."' and date_end > '".$db->idate(dol_now())."'";
262  $sql .= $db->plimit(1);
263  $res = $db->query($sql);
264  if ($res->num_rows > 0) {
265  $fiscalYear = $db->fetch_object($res);
266  $date_start = strtotime($fiscalYear->date_start);
267  $date_end = strtotime($fiscalYear->date_end);
268  } else {
269  $month_start = ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1);
270  $year_start = dol_print_date(dol_now(), '%Y');
271  $year_end = $year_start + 1;
272  $month_end = $month_start - 1;
273  if ($month_end < 1)
274  {
275  $month_end = 12;
276  $year_end--;
277  }
278  $date_start = dol_mktime(0, 0, 0, $month_start, 1, $year_start);
279  $date_end = dol_get_last_day($year_end, $month_end);
280  }
281  } elseif ($periodbydefaultontransfer == 1) {
282  $year_current = strftime("%Y", dol_now());
283  $pastmonth = strftime("%m", dol_now());
284  $pastmonthyear = $year_current;
285  if ($pastmonth == 0) {
286  $pastmonth = 12;
287  $pastmonthyear--;
288  }
289  } else {
290  $year_current = strftime("%Y", dol_now());
291  $pastmonth = strftime("%m", dol_now()) - 1;
292  $pastmonthyear = $year_current;
293  if ($pastmonth == 0) {
294  $pastmonth = 12;
295  $pastmonthyear--;
296  }
297  }
298 
299  return array(
300  'date_start' => $date_start,
301  'date_end' => $date_end,
302  'pastmonthyear' => $pastmonthyear,
303  'pastmonth' => $pastmonth
304  );
305 }
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.
getDefaultDatesForTransfer()
Return Default dates for transfer based on periodicity option in accountancy setup.
journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink= '', $moreparam=array(), $calcmode= '', $varlink= '')
Show header of a page used to transfer/dispatch data in accounting.
is_empty($var, $allow_false=false, $allow_ws=false)
Check if a value is empty with some options.
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
accounting_prepare_head(AccountingAccount $object)
Prepare array with list of tabs.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage accounting accounts.
clean_account($account)
Return accounting account without zero on the right.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode= 'add')
Complete or removed entries into a head array (used to build tabs).
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous) ...