|
1
|
|
|
<?php |
|
2
|
|
|
/* Copyright (C) 2017 Alexandre Spangaro <[email protected]> |
|
3
|
|
|
* |
|
4
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
5
|
|
|
* it under the terms of the GNU General Public License as published by |
|
6
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
7
|
|
|
* (at your option) any later version. |
|
8
|
|
|
* |
|
9
|
|
|
* This program is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU General Public License for more details. |
|
13
|
|
|
* |
|
14
|
|
|
* You should have received a copy of the GNU General Public License |
|
15
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* \file htdocs/accountancy/class/accountingjournal.class.php |
|
20
|
|
|
* \ingroup Advanced accountancy |
|
21
|
|
|
* \brief File of class to manage accounting journals |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class to manage accounting accounts |
|
26
|
|
|
*/ |
|
27
|
|
|
class AccountingJournal extends CommonObject |
|
28
|
|
|
{ |
|
29
|
|
|
public $element='accounting_journal'; |
|
30
|
|
|
public $table_element='accounting_journal'; |
|
31
|
|
|
public $fk_element = ''; |
|
32
|
|
|
protected $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
33
|
|
|
|
|
34
|
|
|
var $rowid; |
|
35
|
|
|
|
|
36
|
|
|
var $code; |
|
37
|
|
|
var $label; |
|
38
|
|
|
var $nature; // 0:various operations, 1:sale, 2:purchase, 3:bank, 9: has-new |
|
39
|
|
|
var $active; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Constructor |
|
43
|
|
|
* |
|
44
|
|
|
* @param DoliDB $db Database handle |
|
45
|
|
|
*/ |
|
46
|
|
|
function __construct($db) { |
|
47
|
|
|
$this->db = $db; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Load an object from database |
|
52
|
|
|
* |
|
53
|
|
|
* @param int $rowid Id of record to load |
|
54
|
|
|
* @param string $journal_code Journal code |
|
55
|
|
|
* @return int <0 if KO, Id of record if OK and found |
|
56
|
|
|
*/ |
|
57
|
|
|
function fetch($rowid = null, $journal_code = null) |
|
58
|
|
|
{ |
|
59
|
|
|
if ($rowid || $journal_code) |
|
60
|
|
|
{ |
|
61
|
|
|
$sql = "SELECT rowid, code, label, nature, active"; |
|
62
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; |
|
63
|
|
|
$sql .= " WHERE"; |
|
64
|
|
|
if ($rowid) { |
|
65
|
|
|
$sql .= " rowid = '" . $rowid . "'"; |
|
66
|
|
|
} elseif ($journal_code) { |
|
67
|
|
|
$sql .= " code = '" . $journal_code . "'"; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
dol_syslog(get_class($this)."::fetch sql=" . $sql, LOG_DEBUG); |
|
71
|
|
|
$result = $this->db->query($sql); |
|
72
|
|
|
if ($result) |
|
73
|
|
|
{ |
|
74
|
|
|
$obj = $this->db->fetch_object($result); |
|
75
|
|
|
|
|
76
|
|
|
if ($obj) { |
|
77
|
|
|
$this->id = $obj->rowid; |
|
78
|
|
|
$this->rowid = $obj->rowid; |
|
79
|
|
|
|
|
80
|
|
|
$this->code = $obj->code; |
|
81
|
|
|
$this->ref = $obj->code; |
|
82
|
|
|
$this->label = $obj->label; |
|
83
|
|
|
$this->nature = $obj->nature; |
|
84
|
|
|
$this->active = $obj->active; |
|
85
|
|
|
|
|
86
|
|
|
return $this->id; |
|
87
|
|
|
} else { |
|
88
|
|
|
return 0; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
else |
|
92
|
|
|
{ |
|
93
|
|
|
$this->error = "Error " . $this->db->lasterror(); |
|
94
|
|
|
$this->errors[] = "Error " . $this->db->lasterror(); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
return -1; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Return clicable name (with picto eventually) |
|
102
|
|
|
* |
|
103
|
|
|
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
|
104
|
|
|
* @param int $withlabel 0=No label, 1=Include label of journal |
|
105
|
|
|
* @param int $nourl 1=Disable url |
|
106
|
|
|
* @param string $moretitle Add more text to title tooltip |
|
107
|
|
|
* @param int $notooltip 1=Disable tooltip |
|
108
|
|
|
* @return string String with URL |
|
109
|
|
|
*/ |
|
110
|
|
|
function getNomUrl($withpicto = 0, $withlabel = 0, $nourl = 0, $moretitle='',$notooltip=0) |
|
111
|
|
|
{ |
|
112
|
|
|
global $langs, $conf, $user; |
|
113
|
|
|
|
|
114
|
|
|
if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips |
|
115
|
|
|
|
|
116
|
|
|
$result = ''; |
|
117
|
|
|
|
|
118
|
|
|
$url = DOL_URL_ROOT . '/accountancy/admin/journals_list.php?id=35'; |
|
119
|
|
|
|
|
120
|
|
|
$picto = 'billr'; |
|
121
|
|
|
$label=''; |
|
122
|
|
|
|
|
123
|
|
|
$label = '<u>' . $langs->trans("ShowAccountingJournal") . '</u>'; |
|
124
|
|
|
if (! empty($this->code)) |
|
125
|
|
|
$label .= '<br><b>'.$langs->trans('Code') . ':</b> ' . $this->code; |
|
126
|
|
|
if (! empty($this->label)) |
|
127
|
|
|
$label .= '<br><b>'.$langs->trans('Label') . ':</b> ' . $this->label; |
|
128
|
|
|
if ($moretitle) $label.=' - '.$moretitle; |
|
129
|
|
|
|
|
130
|
|
|
$linkclose=''; |
|
131
|
|
|
if (empty($notooltip)) |
|
132
|
|
|
{ |
|
133
|
|
|
if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
134
|
|
|
{ |
|
135
|
|
|
$label=$langs->trans("ShowAccoutingJournal"); |
|
136
|
|
|
$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
137
|
|
|
} |
|
138
|
|
|
$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
139
|
|
|
$linkclose.=' class="classfortooltip"'; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
$linkstart='<a href="'.$url.'"'; |
|
143
|
|
|
$linkstart.=$linkclose.'>'; |
|
144
|
|
|
$linkend='</a>'; |
|
145
|
|
|
|
|
146
|
|
|
if ($nourl) |
|
147
|
|
|
{ |
|
148
|
|
|
$linkstart = ''; |
|
149
|
|
|
$linkclose = ''; |
|
150
|
|
|
$linkend = ''; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
$label_link = $this->code; |
|
154
|
|
|
if ($withlabel) $label_link .= ' - ' . $this->label; |
|
155
|
|
|
|
|
156
|
|
|
if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); |
|
157
|
|
|
if ($withpicto && $withpicto != 2) $result .= ' '; |
|
158
|
|
|
if ($withpicto != 2) $result.=$linkstart . $label_link . $linkend; |
|
159
|
|
|
return $result; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Retourne le libelle du statut d'un user (actif, inactif) |
|
164
|
|
|
* |
|
165
|
|
|
* @param int $mode 0=libelle long, 1=libelle court |
|
166
|
|
|
* @return string Label of type |
|
167
|
|
|
*/ |
|
168
|
|
|
function getLibType($mode=0) |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->LibType($this->nature,$mode); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Return type of an accounting journal |
|
175
|
|
|
* |
|
176
|
|
|
* @param int $nature Id type |
|
177
|
|
|
* @param int $mode 0=libelle long, 1=libelle court |
|
178
|
|
|
* @return string Label of type |
|
179
|
|
|
*/ |
|
180
|
|
|
function LibType($nature,$mode=0) |
|
181
|
|
|
{ |
|
182
|
|
|
global $langs; |
|
183
|
|
|
|
|
184
|
|
|
$langs->load("accountancy"); |
|
185
|
|
|
|
|
186
|
|
|
if ($mode == 0) |
|
187
|
|
|
{ |
|
188
|
|
|
$prefix=''; |
|
189
|
|
|
if ($nature == 9) return $langs->trans('AccountingJournalType9'); |
|
190
|
|
|
if ($nature == 4) return $langs->trans('AccountingJournalType4'); |
|
191
|
|
|
if ($nature == 3) return $langs->trans('AccountingJournalType3'); |
|
192
|
|
|
if ($nature == 2) return $langs->trans('AccountingJournalType2'); |
|
193
|
|
|
if ($nature == 1) return $langs->trans('AccountingJournalType1'); |
|
194
|
|
|
} |
|
195
|
|
|
if ($mode == 1) |
|
196
|
|
|
{ |
|
197
|
|
|
if ($nature == 9) return $langs->trans('AccountingJournalType9'); |
|
198
|
|
|
if ($nature == 4) return $langs->trans('AccountingJournalType4'); |
|
199
|
|
|
if ($nature == 3) return $langs->trans('AccountingJournalType3'); |
|
200
|
|
|
if ($nature == 2) return $langs->trans('AccountingJournalType2'); |
|
201
|
|
|
if ($nature == 1) return $langs->trans('AccountingJournalType1'); |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|