Skip to content

Commit

Permalink
Merge branch 'develop' into allow-deductible-tax-accounting
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy authored Nov 23, 2023
2 parents 793bb08 + 5d3087b commit b592968
Show file tree
Hide file tree
Showing 157 changed files with 1,920 additions and 1,120 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ WARNING:
--------

The following changes may create regressions for some external modules, but were necessary to make Dolibarr better:
* The hook changeHelpURL is replaced by llxHeader
* The property ->brouillon has been removed from all classes. It was not reliable and was a duplicate of ->status == self::STATUS_DRAFT.
* The duplicated and deprecated property ->date_livraison that was renamed into ->delivery_date has been completely removed.
* The property ->user_close to store ID of closing user has been renamed into ->user_closing_id.
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog)
- Batches / Lots / Serials
- Product Variants
- Bill of Materials (BOM)
- Manufacturing Orders
- Manufacturing Orders (MO)

Customer/Sales Management

Expand All @@ -114,7 +114,8 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog)
- Customer Orders management
- Contracts/Subscription management
- Interventions management
- Ticket System
- Ticket System (+ Knowledge management)
- Partnership management
- Shipping management
- Customer Invoices/Credit notes and payment management
- Point of Sale (POS)
Expand Down Expand Up @@ -143,14 +144,16 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog)

- Shared calendar/agenda (with ical and vcal import/export for third-party tools integration)
- Projects & Tasks management
- Event organization
- Ticket System
- Surveys

HR
HR - Human Resources Management

- Employee's leaves management
- Expense reports
- Recruitment management
- Employee/staff management
- Timesheets

### Other application/modules
Expand All @@ -168,7 +171,7 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog)
- Payment platforms integration (PayPal, Stripe, Paybox...)
- Email-Collector

(around 100 modules available by default, 1000+ on the addon marketplace)
(around 100 modules available by default, 1000+ addons at the official marketplace Dolistore.com)

### Other general features

Expand Down
13 changes: 7 additions & 6 deletions dev/tools/apstats.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@

$html = '<html>'."\n";
$html .= '<meta charset="utf-8">'."\n";
$html .= '<meta http-equiv="refresh" content="300">'."\n";
$html .= '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
$html .= '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css" integrity="sha512-q3eWabyZPc1XTCmF+8/LuE1ozpg5xxn7iO89yfSOd5/oKvyqLngoNGsx8jq92Y8eXJ/IRxQbEC+FGSYxtk2oiw==" crossorigin="anonymous" referrerpolicy="no-referrer" />'."\n";
$html .= '<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>'."\n";
Expand Down Expand Up @@ -295,21 +296,21 @@
$html .= '<span class="opacity">Generated on '.$currentDate.'</span>'."\n";
$html .= '</header>'."\n";

$html .= '<section class="chapter">'."\n";
$html .= '<section class="chapter" id="linesofcode">'."\n";
$html .= '<h2>Lines of code</h2>'."\n";

$html .= '<div class="div-table-responsive">'."\n";
$html .= '<table class="centpercent">';
$html .= '<tr class="loc">';
$html .= '<th class="left">Language</td>';
$html .= '<th class="left">Language</th>';
$html .= '<th class="right">Bytes</th>';
$html .= '<th class="right">Files</th>';
$html .= '<th class="right">Lines</th>';
$html .= '<th class="right">Blanks</th>';
$html .= '<th class="right">Comments</th>';
$html .= '<th class="right">Code</th>';
//$html .= '<td class="right">'.$val['Complexity'].'</td>';
$html .= '</th>';
$html .= '</tr>';
foreach (array('proj', 'dep') as $source) {
$html .= '<tr class="trgroup" id="source'.$source.'">';
if ($source == 'proj') {
Expand Down Expand Up @@ -359,7 +360,7 @@

$html .= '</section>'."\n";

$html .= '<section class="chapter">'."\n";
$html .= '<section class="chapter" id="projectvalue">'."\n";
$html .= '<h2>Project value</h2><br>'."\n";
$html .= '<div class="box inline-box back1">';
$html .= 'COCOMO (Basic organic model) value:<br>';
Expand All @@ -371,7 +372,7 @@
$html .= ' monthes people</b><br>';
$html .= '</section>'."\n";

$html .= '<section class="chapter">'."\n";
$html .= '<section class="chapter" id="technicaldebt">'."\n";
$html .= '<h2>Technical debt ('.count($output_arrtd).')</h2><br>'."\n";
$html .= '<div class="div-table-responsive">'."\n";
$html .= '<table class="list_technical_debt">'."\n";
Expand Down Expand Up @@ -399,7 +400,7 @@
});
</script>
';
$html .= '</boby>';
$html .= '</body>';
$html .= '</html>';

$fh = fopen($outputpath, 'w');
Expand Down
196 changes: 141 additions & 55 deletions htdocs/accountancy/class/bookkeeping.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,6 @@ class BookKeeping extends CommonObject
*/
public $picto = 'generic';

/**
* @var array List of active fiscal periods cached [[date_start, date_end], ...]
*/
public static $active_fiscal_period_cached;
/**
* @var string[] SQL filter used for check if the bookkeeping record can be created/inserted/modified/deleted (cached)
*/
Expand Down Expand Up @@ -301,7 +297,11 @@ public function create(User $user, $notrigger = false)
if ($result < 0) {
return -1;
} elseif ($result == 0) {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') == 'blockedonclosed') {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
} else {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
}
return -1;
}

Expand Down Expand Up @@ -654,7 +654,11 @@ public function createStd(User $user, $notrigger = false, $mode = '')
if ($result < 0) {
return -1;
} elseif ($result == 0) {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') == 'blockedonclosed') {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
} else {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
}
return -1;
}

Expand Down Expand Up @@ -1372,7 +1376,11 @@ public function update(User $user, $notrigger = false, $mode = '')
if ($result < 0) {
return -1;
} elseif ($result == 0) {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') == 'blockedonclosed') {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
} else {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
}
return -1;
}

Expand Down Expand Up @@ -1497,7 +1505,11 @@ public function delete(User $user, $notrigger = false, $mode = '')
if ($result < 0) {
return -1;
} elseif ($result == 0) {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') == 'blockedonclosed') {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateIsOnAClosedFiscalPeriod');
} else {
$this->errors[] = $langs->trans('ErrorBookkeepingDocDateNotOnActiveFiscalPeriod');
}
return -1;
}

Expand Down Expand Up @@ -2264,18 +2276,20 @@ public function get_compte_desc($account = null)
*/
public function getCanModifyBookkeepingSQL($alias = '', $force = false)
{
global $conf;

$alias = trim($alias);
$alias = !empty($alias) && strpos($alias, '.') < 0 ? $alias . "." : $alias;

if (!isset(self::$can_modify_bookkeeping_sql_cached[$alias]) || $force) {
$result = $this->loadActiveFiscalPeriods($force);
$result = $this->loadFiscalPeriods($force, 'active');
if ($result < 0) {
return null;
}

$sql_list = array();
if (is_array(self::$active_fiscal_period_cached)) {
foreach (self::$active_fiscal_period_cached as $fiscal_period) {
if (!empty($conf->cache['active_fiscal_period_cached']) && is_array($conf->cache['active_fiscal_period_cached'])) {
foreach ($conf->cache['active_fiscal_period_cached'] as $fiscal_period) {
$sql_list[] = "('" . $this->db->idate($fiscal_period['date_start']) . "' <= {$alias}doc_date AND {$alias}doc_date <= '" . $this->db->idate($fiscal_period['date_end']) . "')";
}
}
Expand All @@ -2293,82 +2307,154 @@ public function getCanModifyBookkeepingSQL($alias = '', $force = false)
*/
public function canModifyBookkeeping($id)
{
$result = $this->loadActiveFiscalPeriods();
if ($result < 0) {
return -1;
}
global $conf;

$bookkeeping = new BookKeeping($this->db);
$result = $bookkeeping->fetch($id);
if ($result <= 0) {
return $result;
}
if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') == 'blockedonclosed') {
$result = $this->loadFiscalPeriods(false, 'closed');

if ($result < 0) {
return -1;
}

$bookkeeping = new BookKeeping($this->db);
$result = $bookkeeping->fetch($id);
if ($result <= 0) {
return $result;
}

if (is_array(self::$active_fiscal_period_cached)) {
foreach (self::$active_fiscal_period_cached as $fiscal_period) {
if ($fiscal_period['date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period['date_end']) {
return 1;
if (!empty($conf->cache['closed_fiscal_period_cached']) && is_array($conf->cache['closed_fiscal_period_cached'])) {
foreach ($conf->cache['closed_fiscal_period_cached'] as $fiscal_period) {
if ($fiscal_period['date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period['date_end']) {
return 0;
}
}
}

return 1;
} else {
$result = $this->loadFiscalPeriods(false, 'active');
if ($result < 0) {
return -1;
}

$bookkeeping = new BookKeeping($this->db);
$result = $bookkeeping->fetch($id);
if ($result <= 0) {
return $result;
}

if (!empty($conf->cache['active_fiscal_period_cached']) && is_array($conf->cache['active_fiscal_period_cached'])) {
foreach ($conf->cache['active_fiscal_period_cached'] as $fiscal_period) {
if ($fiscal_period['date_start'] <= $bookkeeping->doc_date && $bookkeeping->doc_date <= $fiscal_period['date_end']) {
return 1;
}
}
}
}

return 0;
return 0;
}
}

/**
* Is the bookkeeping date is valid ?
* Is the bookkeeping date valid (on an open period or not on a closed period) ?
*
* @param int $date Bookkeeping date
* @return int <0 if KO, == 0 if No, == 1 if Yes
* @return int <0 if KO, == 0 if No, == 1 if date is valid for a transfer
*/
public function validBookkeepingDate($date)
{
$result = $this->loadActiveFiscalPeriods();
if ($result < 0) {
return -1;
}
global $conf;

if (getDolGlobalString('ACCOUNTANCY_FISCAL_PERIOD_MODE') == 'blockedonclosed') {
$result = $this->loadFiscalPeriods(false, 'closed');

if ($result < 0) {
return -1;
}

if (is_array(self::$active_fiscal_period_cached)) {
foreach (self::$active_fiscal_period_cached as $fiscal_period) {
if ($fiscal_period['date_start'] <= $date && $date <= $fiscal_period['date_end']) {
return 1;
if (!empty($conf->cache['closed_fiscal_period_cached']) && is_array($conf->cache['closed_fiscal_period_cached'])) {
foreach ($conf->cache['closed_fiscal_period_cached'] as $fiscal_period) {
if ($fiscal_period['date_start'] <= $date && $date <= $fiscal_period['date_end']) {
return 0;
}
}
}

return 1;
} else {
$result = $this->loadFiscalPeriods(false, 'active');
if ($result < 0) {
return -1;
}

if (!empty($conf->cache['active_fiscal_period_cached']) && is_array($conf->cache['active_fiscal_period_cached'])) {
foreach ($conf->cache['active_fiscal_period_cached'] as $fiscal_period) {
if ($fiscal_period['date_start'] <= $date && $date <= $fiscal_period['date_end']) {
return 1;
}
}
}
}

return 0;
return 0;
}
}

/**
* Load list of active fiscal period
*
* @param bool $force Force reload
* @param string $mode active or closed ?
* @return int <0 if KO, >0 if OK
*/
public function loadActiveFiscalPeriods($force = false)
public function loadFiscalPeriods($force = false, $mode = 'active')
{
global $conf;

if (!isset(self::$active_fiscal_period_cached) || $force) {
$sql = "SELECT date_start, date_end";
$sql .= " FROM " . $this->db->prefix() . "accounting_fiscalyear";
$sql .= " WHERE entity = " . ((int) $conf->entity);
$sql .= " AND statut = 0";
if ($mode == 'active') {
if (!isset($conf->cache['active_fiscal_period_cached']) || $force) {
$sql = "SELECT date_start, date_end";
$sql .= " FROM " . $this->db->prefix() . "accounting_fiscalyear";
$sql .= " WHERE entity = " . ((int) $conf->entity);
$sql .= " AND statut = 0";

$resql = $this->db->query($sql);
if (!$resql) {
$this->errors[] = $this->db->lasterror();
return -1;
$resql = $this->db->query($sql);
if (!$resql) {
$this->errors[] = $this->db->lasterror();
return -1;
}

$list = array();
while ($obj = $this->db->fetch_object($resql)) {
$list[] = array(
'date_start' => $this->db->jdate($obj->date_start),
'date_end' => $this->db->jdate($obj->date_end),
);
}
$conf->cache['active_fiscal_period_cached'] = $list;
}
}
if ($mode == 'closed') {
if (!isset($conf->cache['closed_fiscal_period_cached']) || $force) {
$sql = "SELECT date_start, date_end";
$sql .= " FROM " . $this->db->prefix() . "accounting_fiscalyear";
$sql .= " WHERE entity = " . ((int) $conf->entity);
$sql .= " AND statut = 1";

$list = array();
while ($obj = $this->db->fetch_object($resql)) {
$list[] = array(
'date_start' => $this->db->jdate($obj->date_start),
'date_end' => $this->db->jdate($obj->date_end),
);
$resql = $this->db->query($sql);
if (!$resql) {
$this->errors[] = $this->db->lasterror();
return -1;
}

$list = array();
while ($obj = $this->db->fetch_object($resql)) {
$list[] = array(
'date_start' => $this->db->jdate($obj->date_start),
'date_end' => $this->db->jdate($obj->date_end),
);
}
$conf->cache['closed_fiscal_period_cached'] = $list;
}
self::$active_fiscal_period_cached = $list;
}

return 1;
Expand Down
Loading

0 comments on commit b592968

Please sign in to comment.