Skip to content

Commit f3f7bcb

Browse files
authored
Merge pull request #438 from Hystepik/new-area-for-module-owner
New implements billing and instance page for module supplier
2 parents ed008cb + cfcf4a7 commit f3f7bcb

File tree

4 files changed

+1364
-3
lines changed

4 files changed

+1364
-3
lines changed

langs/en_US/sellyoursaas.lang

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,3 +943,6 @@ HelpOnOnlyThoseServers=Keep empty to allow deployment on any qualified server. E
943943
DolibarrDeployment=Dolibarr specific
944944
OnlyForCountry=Only for Country
945945
OnlyForCountryHelp=Country code list allowing installation of the product or service.To have several countries, add a comma between the country codes.<br>Exemple : fr,us,es
946+
MyModuleCustomersInstances=My module customer instances
947+
MyModuleCustomersBilling=My module customer billing
948+
SupplierModule=Module

myaccount/index.php

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
$lastrecord=GETPOST('lastrecord', 'int');
152152
$search_instance_name=GETPOST('search_instance_name', 'alphanohtml');
153153
$search_customer_name=GETPOST('search_customer_name', 'alphanohtml');
154+
$search_module_name=GETPOST('search_module_name', 'alphanohtml');
154155
$reasonundeploy=GETPOST('reasonundeploy', 'alpha');
155156
$commentundeploy=GETPOST('commentundeploy', 'alpha');
156157

@@ -186,6 +187,7 @@
186187
if (GETPOSTISSET('reset')) {
187188
$search_instance_name = '';
188189
$search_customer_name = '';
190+
$search_module_name = '';
189191
}
190192
$fromsocid=GETPOST('fromsocid', 'int');
191193

@@ -318,6 +320,24 @@
318320
if (getDolGlobalInt('SELLYOURSAAS_ALLOW_MODULE_PROVIDER_PROGRAM') > 0) {
319321
// TODO Read if there is some product prices in supplier tab of the thirdparty. If yes it is a module provider and we have the list of provided modules
320322
//$mythirdpartyaccount->isamoduleprovider = array('aa', 'bbb');
323+
$sql = "SELECT p.rowid FROM ".MAIN_DB_PREFIX."product as p";
324+
$sql.= " JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
325+
$sql.= " ON pfp.fk_product = p.rowid";
326+
$sql.= " WHERE pfp.fk_soc = ".$mythirdpartyaccount->id;
327+
$resql=$db->query($sql);
328+
if ($resql) {
329+
$num_rows = $db->num_rows($resql);
330+
$i = 0;
331+
while ($i < $num_rows) {
332+
$obj = $db->fetch_object($resql);
333+
if ($obj) {
334+
$mythirdpartyaccount->isamoduleprovider[] = $obj->rowid;
335+
}
336+
$i++;
337+
}
338+
} else {
339+
dol_print_error($db);
340+
}
321341
}
322342

323343
$nbtotalofrecords = 0;
@@ -401,6 +421,48 @@
401421
}
402422
//var_dump(array_keys($listofcontractidreseller));
403423

424+
$listofcontractidmodulesupplier = array();
425+
// Load list of child instance for module supplier
426+
if (!empty($mythirdpartyaccount->isamoduleprovider) && in_array($mode, array('mymodulecustomerinstances', 'mymodulecustomerbilling'))) {
427+
$sql = 'SELECT DISTINCT c.rowid';
428+
$sql.= ' FROM '.MAIN_DB_PREFIX.'contrat as c';
429+
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as d ON d.fk_contrat = c.rowid';
430+
$sql.= ', '.MAIN_DB_PREFIX.'product as p';
431+
$sql.= " WHERE d.fk_product = p.rowid";
432+
$sql.= " AND d.fk_product IN (".(implode(",", $mythirdpartyaccount->isamoduleprovider)).")";
433+
$sql.= " AND d.statut = 4";
434+
435+
if ($search_instance_name) {
436+
$sql.=natural_search(array('c.ref_customer'), $search_instance_name);
437+
}
438+
if ($search_module_name) {
439+
$sql.=natural_search(array('p.ref','p.label'), $search_module_name);
440+
}
441+
442+
$resql=$db->query($sql);
443+
if ($resql) {
444+
$num_rows = $db->num_rows($resql);
445+
$i = 0;
446+
while ($i < $num_rows) {
447+
$obj = $db->fetch_object($resql);
448+
if ($obj) {
449+
if (empty($listofcontractidmodulesupplier[$obj->rowid])) {
450+
$contract=new Contrat($db);
451+
$contract->fetch($obj->rowid); // This load also lines
452+
$listofcontractidmodulesupplier[$obj->rowid] = $contract;
453+
}
454+
}
455+
$i++;
456+
}
457+
if (empty($lastrecord) || $lastrecord > $num_rows) {
458+
$lastrecord = $num_rows;
459+
}
460+
} else {
461+
dol_print_error($db);
462+
}
463+
464+
}
465+
404466
// Define environment of payment modes
405467
$servicestatusstripe = 0;
406468
if (isModEnabled('stripe')) {
@@ -2401,13 +2463,13 @@
24012463

24022464
if (count($mythirdpartyaccount->isamoduleprovider) > 0) {
24032465
print '
2404-
<li class="nav-item'.($mode == 'moduleprovider' ? ' active' : '').' dropdown">
2466+
<li class="nav-item'.(($mode == 'mymodulecustomerinstances' || $mode == 'mymodulecustomerbilling') ? ' active' : '').' dropdown">
24052467
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#"><i class="fa fa-suitcase"></i> '.$langs->trans("ModuleProviderArea").'</a>
24062468
<ul class="dropdown-menu">';
24072469
// Module provider stats
2408-
//print '<li><a class="dropdown-item" href="'.$_SERVER["PHP_SELF"].'?mode=mycustomerinstances"><i class="fa fa-server pictofixedwidth"></i> '.$langs->trans("MyCustomersInstances").'</a></li>';
2470+
print '<li><a class="dropdown-item" href="'.$_SERVER["PHP_SELF"].'?mode=mymodulecustomerinstances"><i class="fa fa-server pictofixedwidth"></i> '.$langs->trans("MyModuleCustomersInstances").'</a></li>';
24092471
// Divider
2410-
//print '<li class="dropdown-divider"></li>';
2472+
print '<li class="dropdown-divider"></li>';
24112473
// Customers ofmy module area
24122474
print '<li><a class="dropdown-item" href="'.$_SERVER["PHP_SELF"].'?mode=mymodulecustomerbilling"><i class="fa fa-usd"></i> '.$langs->trans("MyModuleCustomersBilling").'</a></li>';
24132475
print '

0 commit comments

Comments
 (0)