dolibarr 23.0.3
mod_bookkeeping_argon.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2025 Jean-Rémi Taponier <jean-remi@netlogic.fr>
3 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * or see https://www.gnu.org/
18 */
19
25require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
26require_once DOL_DOCUMENT_ROOT.'/core/modules/accountancy/modules_accountancy.php';
27
32{
37 public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr'
38
42 public $error = '';
43
47 public $name = 'Argon';
48
52 public $position = 50;
53
54
58 public function __construct()
59 {
60 // Nothing
61 }
62
69 public function info($langs): string
70 {
71 global $langs;
72 return $langs->trans("BookkeepingNumRefModelDesc");
73 }
74
75
81 public function getExample(): string
82 {
83 return "2501VT00001";
84 }
85
86
94 public function canBeActivated($object): bool
95 {
96 global $langs;
97
98 $max = '';
99
100 if (get_class($object) !== 'BookKeeping') {
101 return false;
102 }
103
104 $prefix = $this->getPrefix($object);
105 // If prefix size is not 7, prefix is not correct (YYYYCCC)
106 if (!empty($prefix) || strlen($prefix) !== 7) {
107 $langs->load("errors");
108 $this->error = $langs->trans('ErrorNumRefModel', $max);
109 return false;
110 }
111
112 return true;
113 }
114
122 public function getNextValue(BookKeeping $object, $mode = 'next')
123 {
124 global $conf, $db;
125
126 // Get mask
127 $mask = '{yy}{mm}{jj}{00000@99}';
128
129 $where = '';
130
131 // Get entities
132 //$entity = getEntity('invoicenumber', 1, $object);
133 $entity = $conf->entity; // In accountancy, we never share entities
134 $numFinal = get_next_value($db, $mask, 'accounting_bookkeeping', 'ref', $where, null, $object->doc_date, $mode, false, null, (string) $entity, $object);
135 if (!preg_match('/([0-9])+/', $numFinal)) {
136 $this->error = $numFinal;
137 }
138
139 return $numFinal;
140 }
141
149 private function getPrefix(BookKeeping $object): string
150 {
151 $fiscalStartMonth = getDolGlobalInt('SOCIETE_FISCAL_MONTH_START', 1);
152 $docYear = (int) dol_print_date($object->doc_date, '%Y');
153 $docMonth = (int) dol_print_date($object->doc_date, '%m');
154 $docFiscalYear = $docMonth < $fiscalStartMonth ? ($docYear - 1) : $docYear;
155 return $docFiscalYear . str_pad($object->code_journal, 3, "0", STR_PAD_LEFT);
156 }
157}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class to manage Ledger (General Ledger and Subledger)
Parent class to manage numbering of Sale Orders.
Class to manage Bookkeeping numbering rules Argon.
getExample()
Return an example of numbering.
getNextValue(BookKeeping $object, $mode='next')
Return next free value.
getPrefix(BookKeeping $object)
Returns the prefix for current Bookkeeping object Year used in prefix is the beginning fiscal year.
canBeActivated($object)
Checks if the numbers already in the database do not cause conflicts that would prevent this numberin...
info($langs)
Return description of numbering module.
get_next_value($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null, $forceentity=null, $objbookkeeping=null)
Return last or next value for a mask (according to area we should not reset)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).