dolibarr/htdocs/core/lib/accounting.lib.php

174 lines
4.4 KiB
PHP
Raw Normal View History

2014-08-27 07:03:42 +02:00
<?php
/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
2014-08-27 07:03:42 +02:00
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/lib/accounting.lib.php
* \ingroup Advanced accountancy
* \brief Library of accountancy functions
2014-08-27 07:03:42 +02:00
*/
/**
2014-08-30 05:44:12 +02:00
* Prepare array with list of admin tabs
2014-09-19 03:03:24 +02:00
*
* @param AccountingAccount $object Object instance we show card
2014-08-30 05:44:12 +02:00
* @return array Array of tabs to show
2014-08-27 07:03:42 +02:00
*/
function admin_accounting_prepare_head(AccountingAccount $object=null)
2014-08-30 05:44:12 +02:00
{
2014-08-27 07:03:42 +02:00
global $langs, $conf;
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
$h = 0;
$head = array ();
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
$head[$h][0] = dol_buildpath('/accountancy/admin/index.php', 1);
2016-05-12 20:45:05 +02:00
$head[$h][1] = $langs->trans("Miscellaneous");
2014-08-27 07:03:42 +02:00
$head[$h][2] = 'general';
$h ++;
2014-11-15 15:19:37 +01:00
2015-09-03 11:54:03 +02:00
$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/journal.php';
2014-08-27 07:03:42 +02:00
$head[$h][1] = $langs->trans("Journaux");
$head[$h][2] = 'journal';
$h ++;
2014-11-15 15:19:37 +01:00
2015-09-03 11:54:03 +02:00
$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/export.php';
2016-05-12 20:45:05 +02:00
$head[$h][1] = $langs->trans("ExportOptions");
2014-08-27 07:03:42 +02:00
$head[$h][2] = 'export';
$h ++;
2014-11-15 15:19:37 +01:00
2016-05-12 20:45:05 +02:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_admin');
2014-08-27 07:03:42 +02:00
complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_admin', 'remove');
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
return $head;
}
/**
2014-08-30 05:44:12 +02:00
* Prepare array with list of tabs
2014-08-27 07:03:42 +02:00
*
* @param AccountingAccount $object Accounting account
2014-08-30 05:44:12 +02:00
* @return array Array of tabs to show
2014-08-27 07:03:42 +02:00
*/
function accounting_prepare_head(AccountingAccount $object)
2014-08-30 05:44:12 +02:00
{
2014-08-27 07:03:42 +02:00
global $langs, $conf;
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
$h = 0;
$head = array ();
2014-11-15 15:19:37 +01:00
2015-09-03 11:54:03 +02:00
$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id=' . $object->id;
2014-08-27 07:03:42 +02:00
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'card';
$h ++;
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account');
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove');
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
return $head;
}
/**
* Return accounting account without zero on the right
*
* @param string $account Accounting account
* @return string String without zero on the right
*/
function clean_account($account)
{
$account = rtrim($account,"0");
return $account;
}
2014-08-27 07:03:42 +02:00
/**
2016-10-14 13:05:01 +02:00
* Return General accounting account with defined length (used for product and miscellaneous)
2014-08-27 07:03:42 +02:00
*
2014-08-30 06:05:02 +02:00
* @param string $account General accounting account
2014-11-15 15:19:37 +01:00
* @return string String with defined length
2014-08-27 07:03:42 +02:00
*/
2014-08-30 05:44:12 +02:00
function length_accountg($account)
{
2014-08-30 05:19:48 +02:00
global $conf;
2014-11-15 15:19:37 +01:00
2016-10-14 13:05:01 +02:00
if ($account < 0 || empty($account)) return '';
2016-10-06 19:59:33 +02:00
2014-08-27 07:03:42 +02:00
$g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT;
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
if (! empty($g)) {
// Clean parameters
$i = strlen($account);
2014-11-15 15:19:37 +01:00
if ($i >= 1) {
2014-08-27 07:03:42 +02:00
while ( $i < $g ) {
$account .= '0';
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
$i ++;
}
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
return $account;
} else {
return $account;
}
} else {
return $account;
}
}
/**
2016-10-14 13:05:01 +02:00
* Return Auxiliary accounting account of thirdparties with defined length
2014-08-27 07:03:42 +02:00
*
2014-08-30 06:05:02 +02:00
* @param string $accounta Auxiliary accounting account
2014-11-15 15:19:37 +01:00
* @return string String with defined length
2014-08-27 07:03:42 +02:00
*/
2014-08-30 05:44:12 +02:00
function length_accounta($accounta)
{
2016-10-06 19:59:33 +02:00
global $conf, $langs;
2014-11-15 15:19:37 +01:00
2016-10-14 13:05:01 +02:00
if ($accounta < 0 || empty($accounta)) return '';
2016-10-06 19:59:33 +02:00
2014-08-27 07:03:42 +02:00
$a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT;
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
if (! empty($a)) {
// Clean parameters
$i = strlen($accounta);
2014-11-15 15:19:37 +01:00
if ($i >= 1) {
2014-08-27 07:03:42 +02:00
while ( $i < $a ) {
$accounta .= '0';
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
$i ++;
}
2014-11-15 15:19:37 +01:00
2014-08-27 07:03:42 +02:00
return $accounta;
} else {
return $accounta;
}
} else {
return $accounta;
}
}