Skip to content

Commit

Permalink
Merge branch 'master' of [email protected]:DoliCloud/DoliMods.git
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 27, 2024
2 parents c9a9439 + e3ac920 commit b7d10a6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 67 deletions.
58 changes: 25 additions & 33 deletions htdocs/helloasso/core/modules/modHelloAsso.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function __construct($db)
// A condition to hide module
$this->hidden = false;
// List of module class names that must be enabled if this module is enabled. Example: array('always'=>array('modModuleToEnable1','modModuleToEnable2'), 'FR'=>array('modModuleToEnableFR')...)
$this->depends = array();
$this->depends = array('always' => 'modBanque');
// List of module class names to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
$this->requiredby = array();
// List of module class names this module is in conflict with. Example: array('modModuleToDisable1', ...)
Expand Down Expand Up @@ -439,7 +439,30 @@ public function __construct($db)
*/
public function init($options = '')
{
global $conf, $langs;
global $conf, $langs, $mysoc;

// Create bank account HelloAsso if not exists
if (!getDolGlobalInt('HELLOASSO_BANK_ACCOUNT_FOR_PAYMENTS')) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$cashaccount = new Account($this->db);
$searchaccountid = $cashaccount->fetch(0, "CASH-POS");
if ($searchaccountid == 0) {
$cashaccount->ref = "HelloAsso";
$cashaccount->label = 'HelloAsso';
$cashaccount->courant = Account::TYPE_CURRENT; // deprecated

Check warning on line 452 in htdocs/helloasso/core/modules/modHelloAsso.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modHelloAsso.class.php: PhanDeprecatedProperty: Reference to deprecated property \Account->courant defined at dev/tools/phan/stubs/dolibarr.php:19825
$cashaccount->type = Account::TYPE_CURRENT;
$cashaccount->country_id = $mysoc->country_id ? $mysoc->country_id : 1;

Check warning on line 454 in htdocs/helloasso/core/modules/modHelloAsso.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modHelloAsso.class.php: PhanPluginDuplicateConditionalTernaryDuplication: "X ? X : Y" can usually be simplified to "X ?: Y". The duplicated expression X was $mysoc->country_id
$cashaccount->date_solde = dol_now();
$idjournal = dol_getIdFromCode($this->db, 'BQ', 'accounting_journal', 'code', 'rowid');
$cashaccount->fk_accountancy_journal = (int) $idjournal;
$searchaccountid = $cashaccount->create($user);

Check failure on line 458 in htdocs/helloasso/core/modules/modHelloAsso.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modHelloAsso.class.php: PhanTypeMismatchArgumentReal: Argument 1 ($user) is $user of type null but \Account::create() takes \User defined at dev/tools/phan/stubs/dolibarr.php:20140

Check warning on line 458 in htdocs/helloasso/core/modules/modHelloAsso.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modHelloAsso.class.php: PhanUndeclaredVariable: Variable $user is undeclared
}
if ($searchaccountid > 0) {
dolibarr_set_const($this->db, "HELLOASSO_BANK_ACCOUNT_FOR_PAYMENTS", $searchaccountid, 'chaine', 0, '', $conf->entity);
} else {
setEventMessages($cashaccount->error, $cashaccount->errors, 'errors');
}
}

//$result = $this->_load_tables('/install/mysql/', 'helloasso');
$result = $this->_load_tables('/helloasso/sql/');
Expand All @@ -461,37 +484,6 @@ public function init($options = '')

$sql = array();

// Document templates
$moduledir = dol_sanitizeFileName('helloasso');
$myTmpObjects = array();
$myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);

foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
if ($myTmpObjectArray['includerefgeneration']) {
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/' . $moduledir . '/template_myobjects.odt';
$dirodt = DOL_DATA_ROOT . '/doctemplates/' . $moduledir;
$dest = $dirodt . '/template_myobjects.odt';

if (file_exists($src) && !file_exists($dest)) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
dol_mkdir($dirodt);
$result = dol_copy($src, $dest, 0, 0);
if ($result < 0) {
$langs->load("errors");
$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
return 0;
}
}

$sql = array_merge($sql, array(
"DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = 'standard_" . strtolower($myTmpObjectKey) . "' AND type = '" . $this->db->escape(strtolower($myTmpObjectKey)) . "' AND entity = " . ((int) $conf->entity),
"INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('standard_" . strtolower($myTmpObjectKey) . "', '" . $this->db->escape(strtolower($myTmpObjectKey)) . "', " . ((int) $conf->entity) . ")",
"DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = 'generic_" . strtolower($myTmpObjectKey) . "_odt' AND type = '" . $this->db->escape(strtolower($myTmpObjectKey)) . "' AND entity = " . ((int) $conf->entity),
"INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('generic_" . strtolower($myTmpObjectKey) . "_odt', '" . $this->db->escape(strtolower($myTmpObjectKey)) . "', " . ((int) $conf->entity) . ")"
));
}
}

return $this->_init($sql, $options);
}

Expand Down
57 changes: 23 additions & 34 deletions htdocs/stancer/core/modules/modStancer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,29 @@ public function init($options = '')
{
global $conf, $langs;

// Create bank account HelloAsso if not exists
if (!getDolGlobalInt('STANCER_BANK_ACCOUNT_FOR_PAYMENTS')) {
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$cashaccount = new Account($this->db);
$searchaccountid = $cashaccount->fetch(0, "STANCER");
if ($searchaccountid == 0) {
$cashaccount->ref = "Stancer";
$cashaccount->label = 'Stancer';
$cashaccount->courant = Account::TYPE_CURRENT; // deprecated
$cashaccount->type = Account::TYPE_CURRENT;
$cashaccount->country_id = $mysoc->country_id ? $mysoc->country_id : 1;
$cashaccount->date_solde = dol_now();
$idjournal = dol_getIdFromCode($this->db, 'BQ', 'accounting_journal', 'code', 'rowid');
$cashaccount->fk_accountancy_journal = (int) $idjournal;
$searchaccountid = $cashaccount->create($user);

Check failure on line 458 in htdocs/stancer/core/modules/modStancer.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

modStancer.class.php: PhanTypeMismatchArgumentReal: Argument 1 ($user) is $user of type null but \Account::create() takes \User defined at dev/tools/phan/stubs/dolibarr.php:20140
}
if ($searchaccountid > 0) {
dolibarr_set_const($this->db, "STANCER_BANK_ACCOUNT_FOR_PAYMENTS", $searchaccountid, 'chaine', 0, '', $conf->entity);
} else {
setEventMessages($cashaccount->error, $cashaccount->errors, 'errors');
}
}

//$result = $this->_load_tables('/install/mysql/', 'stancer');
$result = $this->_load_tables('/stancer/sql/');
if ($result < 0) {
Expand All @@ -461,40 +484,6 @@ public function init($options = '')

$sql = array();

// Document templates
$moduledir = dol_sanitizeFileName('stancer');
$myTmpObjects = array();
$myTmpObjects['MyObject'] = array('includerefgeneration' => 0, 'includedocgeneration' => 0);

foreach ($myTmpObjects as $myTmpObjectKey => $myTmpObjectArray) {
if ($myTmpObjectKey == 'MyObject') {
continue;
}
if ($myTmpObjectArray['includerefgeneration']) {
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/' . $moduledir . '/template_myobjects.odt';
$dirodt = DOL_DATA_ROOT . '/doctemplates/' . $moduledir;
$dest = $dirodt . '/template_myobjects.odt';

if (file_exists($src) && !file_exists($dest)) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
dol_mkdir($dirodt);
$result = dol_copy($src, $dest, 0, 0);
if ($result < 0) {
$langs->load("errors");
$this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
return 0;
}
}

$sql = array_merge($sql, array(
"DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = 'standard_" . strtolower($myTmpObjectKey) . "' AND type = '" . $this->db->escape(strtolower($myTmpObjectKey)) . "' AND entity = " . ((int) $conf->entity),
"INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('standard_" . strtolower($myTmpObjectKey) . "', '" . $this->db->escape(strtolower($myTmpObjectKey)) . "', " . ((int) $conf->entity) . ")",
"DELETE FROM " . MAIN_DB_PREFIX . "document_model WHERE nom = 'generic_" . strtolower($myTmpObjectKey) . "_odt' AND type = '" . $this->db->escape(strtolower($myTmpObjectKey)) . "' AND entity = " . ((int) $conf->entity),
"INSERT INTO " . MAIN_DB_PREFIX . "document_model (nom, type, entity) VALUES('generic_" . strtolower($myTmpObjectKey) . "_odt', '" . $this->db->escape(strtolower($myTmpObjectKey)) . "', " . ((int) $conf->entity) . ")"
));
}
}

return $this->_init($sql, $options);
}

Expand Down

0 comments on commit b7d10a6

Please sign in to comment.