Skip to content

Commit

Permalink
Merge branch 'master' of [email protected]:DoliCloud/SellYourSaas.git
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 11, 2024
2 parents 8f99130 + 601d006 commit 78bf739
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
10 changes: 8 additions & 2 deletions class/sellyoursaasutils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4496,11 +4496,17 @@ public function sellyoursaasRemoteAction($remoteaction, $object, $appusername =
} elseif ($tmparray[0] === 'PHPMETHOD') {
// Keyword PHPMETHOD then : then function name to call ; args seaprated with ;
// ex: PHPMETHOD:caprelCountDoliSCANUsers;__CONTRACTREF__;__INSTANCEDBPREFIX__;
// ex: PHPMETHOD:sellyoursaasGetNbUsersContract;__CONTRACTREF__;name of extrafield;SELECT to count
// ex: PHPMETHOD:sellyoursaasGetNbUsersContract;__CONTRACT__;name of extrafield;SELECT to count
$arguments = make_substitutions($tmparray[1], $substitarray);
// @TODO LMR Replace param __OBJECTREF__ with $object contract instead of __CONTRACTREF__.
// @TODO LMR Replace param name of extrafield with $tmpobject->options['options_'.name_of_extrafield].
$argsArray = explode(';', $arguments);
// Replace __CONTRACT__ string with the object contract.
foreach ($argsArray as $key => $arg) {
if ($arg === '__CONTRACT__') {
$argsArray[$key] = $object;
continue;
}
}
$customFunctionToCall = array_shift($argsArray);

if (is_callable($customFunctionToCall)) {
Expand Down
28 changes: 15 additions & 13 deletions lib/sellyoursaas.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,23 +717,26 @@ function getRemoteCheck($remoteip, $whitelisted, $email)
/**
* Function to get nb of users for a certain contract
*
* @param string $contractref Ref of contract for user count
* @param string $codeextrafieldqtymin Code of extrafield to find minimum qty of users
* @param string $sqltoexecute SQL to execute to get nb of users in customer instance
* @param int $userproductid Id of product for user count
* @return int <0 if error or Number of users for contract
* @param string|Contrat $contractref Ref of contract for user count or contract
* @param string $codeextrafieldqtymin Code of extrafield to find minimum qty of users
* @param string $sqltoexecute SQL to execute to get nb of users in customer instance
* @param int $userproductid Id of product for user count
* @return int <0 if error or Number of users for contract
*/
function sellyoursaasGetNbUsersContract($contractref, $codeextrafieldqtymin, $sqltoexecute, $userproductid = 0)
{
global $db;

// @TODO LMR Get the object contract as parameter
require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
$contract = new Contrat($db);
$result = $contract->fetch(0, $contractref);
if ($result <= 0) {
setEventMessages($contract->error, $contract->errors, 'errors');
return -1;
if (is_object($contractref)) {
$contract = $contractref;
} else {
require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
$contract = new Contrat($db);
$result = $contract->fetch(0, $contractref);
if ($result <= 0) {
setEventMessages($contract->error, $contract->errors, 'errors');
return -1;
}
}

$server = $contract->ref_customer;
Expand Down Expand Up @@ -788,7 +791,6 @@ function sellyoursaasGetNbUsersContract($contractref, $codeextrafieldqtymin, $sq

foreach ($contractlines as $contractline) {
if (empty($userproductid) || $contractline->fk_product == $userproductid) {
$contractline->fetch_optionals(); // @TODO LMR Not alreayd done ?
if (!empty($contractline->array_options["options_".$codeextrafieldqtymin])) {
$nbuserextrafield = $contractline->array_options["options_".$codeextrafieldqtymin]; // Get qty min of user contract line
}
Expand Down

0 comments on commit 78bf739

Please sign in to comment.