Merge branch '10563' of https://github.com/jloguercio/chamilo-lms into jloguercio-10563

1.10.x
Yannick Warnier 9 years ago
commit 73539bbbc1
  1. 10
      app/Resources/public/css/base.css
  2. 20
      main/inc/lib/api.lib.php
  3. 84
      plugin/buycourses/database.php
  4. 14
      plugin/buycourses/lang/english.php
  5. 14
      plugin/buycourses/lang/french.php
  6. 36
      plugin/buycourses/lang/spanish.php
  7. 272
      plugin/buycourses/resources/css/style.css
  8. 131
      plugin/buycourses/resources/js/comissions.js
  9. 251
      plugin/buycourses/src/buy_course_plugin.class.php
  10. 226
      plugin/buycourses/src/buycourses.ajax.php
  11. 97
      plugin/buycourses/src/configure_course.php
  12. 61
      plugin/buycourses/src/course_panel.php
  13. 2
      plugin/buycourses/src/index.buycourses.php
  14. 220
      plugin/buycourses/src/panel.ajax.php
  15. 31
      plugin/buycourses/src/paymentsetup.php
  16. 57
      plugin/buycourses/src/payout_panel.php
  17. 90
      plugin/buycourses/src/payout_report.php
  18. 55
      plugin/buycourses/src/paypal_payout.php
  19. 27
      plugin/buycourses/src/paypalfunctions.php
  20. 11
      plugin/buycourses/src/process.php
  21. 35
      plugin/buycourses/src/sales_report.php
  22. 61
      plugin/buycourses/src/session_panel.php
  23. 2
      plugin/buycourses/src/success.php
  24. 43
      plugin/buycourses/view/course_panel.tpl
  25. 18
      plugin/buycourses/view/paymentsetup.tpl
  26. 41
      plugin/buycourses/view/payout_panel.tpl
  27. 88
      plugin/buycourses/view/payout_report.tpl
  28. 121
      plugin/buycourses/view/paypal_payout.tpl
  29. 43
      plugin/buycourses/view/session_panel.tpl

@ -154,6 +154,16 @@ a.thumbnail:hover{
background: #C52D2F;
}
.panelSliders {
margin: 20px 0;
}
#panelSliders {
width: 75%;
margin: 25px auto;
text-align: center;
}
#notice_block p, #notice-block p{
color: #666;
font-size: 12px;

@ -8049,6 +8049,26 @@ function api_protect_course_group($tool, $showHeader = true)
}
}
/**
* @param array $array multidimensional array
* @param int $key key to find to compare
*
*/
function api_unique_multidim_array($array, $key){
$temp_array = array();
$i = 0;
$key_array = array();
foreach($array as $val){
if(!in_array($val[$key],$key_array)){
$key_array[$i] = $val[$key];
$temp_array[$i] = $val;
}
$i++;
}
return $temp_array;
}
/**
* Limit the access to Session Admins wheen the limit_session_admin_role
* configuration variable is set to true

@ -113,6 +113,11 @@ $itemBeneficiary->addColumn(
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$itemBeneficiary->addColumn(
'comissions',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$itemBeneficiary->setPrimaryKey(['id']);
$itemBeneficiary->addForeignKeyConstraint(
$itemTable,
@ -121,6 +126,49 @@ $itemBeneficiary->addForeignKeyConstraint(
['onDelete' => 'CASCADE']
);
$comissions = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_COMISSION);
$comissions->addColumn(
'id',
\Doctrine\DBAL\Types\Type::INTEGER,
['autoincrement' => true, 'unsigned' => true]
);
$comissions->addColumn(
'comission',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$comissions->setPrimaryKey(['id']);
$saleComissions = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_PAYPAL_PAYOUTS);
$saleComissions->addColumn(
'id',
\Doctrine\DBAL\Types\Type::INTEGER,
['autoincrement' => true, 'unsigned' => true]
);
$saleComissions->addColumn('date', \Doctrine\DBAL\Types\Type::DATETIME);
$saleComissions->addColumn('payout_date', \Doctrine\DBAL\Types\Type::DATETIME);
$saleComissions->addColumn(
'sale_id',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$saleComissions->addColumn(
'user_id',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$saleComissions->addColumn(
'comission',
\Doctrine\DBAL\Types\Type::DECIMAL,
['scale' => 2]
);
$saleComissions->addColumn(
'status',
\Doctrine\DBAL\Types\Type::INTEGER,
['unsigned' => true]
);
$saleComissions->setPrimaryKey(['id']);
$saleTable = $pluginSchema->createTable(BuyCoursesPlugin::TABLE_SALE);
$saleTable->addColumn(
'id',
@ -172,6 +220,35 @@ $paypalTable = Database::get_main_table(BuyCoursesPlugin::TABLE_PAYPAL);
$currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
$itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM);
$saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
$comissionTable = Database::get_main_table(BuyCoursesPlugin::TABLE_COMISSION);
$extraFieldTable = Database::get_main_table(TABLE_EXTRA_FIELD);
$paypalExtraField = Database::select(
"*",
$extraFieldTable,
[
'where' => ['variable = ?' => 'paypal']
],
'first'
);
if (!$paypalExtraField) {
Database::insert(
$extraFieldTable,
[
'extra_field_type' => 1,
'field_type' => 1,
'variable' => 'paypal',
'display_text' => 'Paypal',
'default_value' => '',
'field_order' => 0,
'visible' => 1,
'changeable' => 1,
'filter' => 0,
'created_at' => getdate()
]
);
}
Database::insert(
$paypalTable,
@ -183,6 +260,13 @@ Database::insert(
]
);
Database::insert(
$comissionTable,
[
'comission' => 0
]
);
$currencies = [
['AD', 'Andorra', 'EUR', 'AND'],
['AE', 'United Arab Emirates', 'AED', 'ARE'],

@ -5,9 +5,20 @@ $strings['show_main_menu_tab'] = "Show tab in main menu";
$strings['show_main_menu_tab_help'] = "In case of not wanting to show the tab, you can create this link in your Chamilo homepage : %s";
$strings['include_sessions'] = "Include sessions";
$strings['paypal_enable'] = "Enable PayPal";
$strings['comissions_enable'] = "Enable Comissions";
$strings['transfer_enable'] = "Enable bank transfer";
$strings['unregistered_users_enable'] = "Allow anonymous users";
$strings['PaypalPayoutComissions'] = "Paypal Payout Comissions";
$strings['Comission'] = "Comission";
$strings['Comissions'] = "Comissions";
$strings['SetComissions'] = "Set comissions";
$strings['ComissionsConfig'] = "Configure Comissions";
$strings['InfoComissions'] = "Enter here the sales commission as a percentage (% ) , the organization that controls the platform. This percentage is deducted from the amount received by teachers for each course or Session sold on the platform.";
$strings['NeedToSelectPaymentType'] = "Need to select payment type";
$strings['IndividualPayout'] = "Individual payout";
$strings['ContinuePayout'] = "Continue Payout";
$strings['SelectOptionToProceed'] = "Select option to proceed";
$strings['BankTransfer'] = "Bank transfer";
$strings['SaleStatusPending'] = "Sale pending";
$strings['SaleStatusCanceled'] = "Sale canceled";
@ -52,6 +63,7 @@ $strings['OrderStatus'] = "Order status";
$strings['SearchByStatus'] = "Search by status";
$strings['OrderReference'] = "Order reference";
$strings['OrderDate'] = "Order date";
$strings['OrderPrice'] = "Order price";
$strings['ProductType'] = "Product type";
$strings['SubscribeUser'] = "Subscribe user";
$strings['DeleteOrder'] = "Delete order";
@ -70,6 +82,8 @@ $strings['PendingReasonByVerify'] = "<b>Pending</b>. Sorry. We are not yet verif
$strings['PendingReasonByOther'] = "<b>Pending</b>. Please contact with the platform admin.";
$strings['PayPalPaymentOKPleaseConfirm'] = "PayPal reports the transaction is ready to be executed. To acknowledge that you are OK to proceed, please click the confirmation button below. Once clicked, you will be registered to the course and the funds will be transferred from your PayPal account to our shop. You can always access your courses through the 'My courses' tab. Thank you for your custom!";
$strings['Sandbox'] = "Test environment";
$strings['PayPalAccount'] = "Paypal account";
$strings['NoPayPalAccountDetected'] = "No Paypal account detected";
$strings['PayPalConfig'] = "PayPal configuration:";
$strings['TransfersConfig'] = "Bank transfers configuration:";
$strings['PluginInstruction'] = "You can enable or disable the option to pay via PayPal or bank transfer settings in the configuration section of the plugin.";

@ -5,9 +5,20 @@ $strings['show_main_menu_tab'] = "Montrer l'onglet dans le menu principal";
$strings['show_main_menu_tab_help'] = "Dans le cas où vous ne souhaitez pas montrer l'onglet, il est possible de rajouter le lien suivant à votre portail Chamilo: %s";
$strings['include_sessions'] = "Inclure les sessions";
$strings['paypal_enable'] = "Activer PayPal";
$strings['comissions_enable'] = "Activer commissions";
$strings['transfer_enable'] = "Activer les transferts bancaires";
$strings['unregistered_users_enable'] = "Permettre l'accès aux utilisateurs non enregistrés sur la plateforme";
$strings['PaypalPayoutComissions'] = "Paypal Commissions immédiates";
$strings['Comission'] = "Commission";
$strings['Comissions'] = "Commissions";
$strings['SetComissions'] = "Établir commissions";
$strings['ComissionsConfig'] = "Configurer Commissions";
$strings['InfoComissions'] = "Saisissez ici la commission de vente en pourcentage ( % ) , l'organisation qui contrôle la plate-forme . Ce pourcentage est déduit du montant reçu par les enseignants pour chaque cours ou session vendus sur la plate-forme.";
$strings['NeedToSelectPaymentType'] = "Besoin pour sélectionner le type de paiement";
$strings['IndividualPayout'] = "Paiement individuel";
$strings['ContinuePayout'] = "Continuer Paiement";
$strings['SelectOptionToProceed'] = "Sélectionnez une option de procéder";
$strings['BankTransfer'] = "Transfert bancaire";
$strings['SaleStatusPending'] = "Vente non confirmée";
$strings['SaleStatusCanceled'] = "Vente annulée";
@ -52,6 +63,7 @@ $strings['OrderStatus'] = "Statut de commande";
$strings['SearchByStatus'] = "Recherche par statut";
$strings['OrderReference'] = "Référence de la commande";
$strings['OrderDate'] = "Date de commande";
$strings['OrderPrice'] = "Commande Prix";
$strings['ProductType'] = "Type de produit";
$strings['SubscribeUser'] = "Inscrire utilisateur";
$strings['DeleteOrder'] = "Éliminer la commande";
@ -70,6 +82,8 @@ $strings['PendingReasonByVerify'] = "<b>En attente</b>. Désolé, nous n'avons p
$strings['PendingReasonByOther'] = "<b>En attente</b>. Veuillez contacter l'administrateur.";
$strings['PayPalPaymentOKPleaseConfirm'] = "PayPal nous indique que la transaction est prête à être exécutée. Par mesure de sécurité, nous vous demandons de bien vouloir confirmer une dernière fois la transaction en cliquant sur le bouton de confirmation ci-dessous. Une fois cliqué, vous serez immédiatement enregistré au cours, et les fonds correspondants seront soustraits de votre compte PayPal. Vous pouvez accéder à vos cours à tout moment à partir de l'onglet 'Mes cours'. Merci de votre fidélité!";
$strings['Sandbox'] = "Environnement de test";
$strings['PayPalAccount'] = "Compte Paypal";
$strings['NoPayPalAccountDetected'] = "Pas de compte paypal détecté";
$strings['PayPalConfig'] = "Configuration PayPal:";
$strings['TransfersConfig'] = "Configuration des transfers bancaires:";
$strings['PluginInstruction'] = "Vous pouvez activer ou désactiver l'option de paiements via PayPal ou de transferts bancaires dans la section de configuration des plugins.";

@ -5,13 +5,45 @@ $strings['show_main_menu_tab'] = "Mostrar pestaña en el menu principal";
$strings['show_main_menu_tab_help'] = "En caso de no querer mostrar la pestaña, puede agregar el siguiente enlace a su portal Chamilo: %s";
$strings['include_sessions'] = "Incluir sesiones";
$strings['paypal_enable'] = "Habilitar PayPal";
$strings['comissions_enable'] = "Habilitar Comisiones";
$strings['transfer_enable'] = "Habilitar transferencia";
$strings['unregistered_users_enable'] = "Permitir usuarios sin registro en la plataforma";
$strings['PaypalPayoutComissions'] = "Pagar comisiones por Paypal";
$strings['MyPayouts'] = "Mis Pagos";
$strings['Comission'] = "Comisión";
$strings['Comissions'] = "Comisiones";
$strings['SetComissions'] = "Aplicar comisiones";
$strings['ComissionsConfig'] = "Configurar Comisiones";
$strings['PayoutReport'] = "Reporte de Pagos";
$strings['Stats'] = "Estadísticas";
$strings['InfoComissions'] = "Ingrese aquí la comisión de ventas, en porcentaje (%), para la organización que controla la plataforma. Este porcentaje se deducirá del monto percibido por los docentes por cada curso o sessión vendido en la plataforma.";
$strings['NeedToSelectPaymentType'] = "Necesita seleccionar el tipo de pago";
$strings['IndividualPayout'] = "Pago individual";
$strings['CancelPayout'] = "Cancelar Payout";
$strings['ContinuePayout'] = "Continuar con el Pago";
$strings['ProceedPayout'] = "Proceder con el Pago";
$strings['SelectOptionToProceed'] = "Selecciona una opción para proceder";
$strings['VerifyTotalAmountToProceedPayout'] = "Porfavor verificar el monto total para proceder con el pago de comisiones, este monto no considera cargos extras por paypal, las ventas de cursos que no cuenten con una cuenta de Paypal para el o los beneficiarios no serán consideradas.";
$strings['TotalAcounts'] = "Total de cuentas:";
$strings['TotalPayout'] = "Total a pagar:";
$strings['PayoutDate'] = "Fecha del Pago:";
$strings['CautionThisProcessCantBeCanceled'] = "<b>Precaución</b>: este proceso puede tomar unos minutos y no puede ser cancelado.";
$strings['ProcessingPayoutsDontCloseThisWindow'] = "<b>Procesando los pagos, no cierre esta ventana hasta que haya finalizado</b>";
$strings['PayoutSuccess'] = "Los pagos se han realizado con éxito";
$strings['Buyer'] = "Comprador";
$strings['BankTransfer'] = "Transferencia Bancaria";
$strings['SaleInfo'] = "Información de la venta";
$strings['SaleStatusPending'] = "Venta pendiente";
$strings['SaleStatusCanceled'] = "Venta cancelada";
$strings['SaleStatusCompleted'] = "Venta completada";
$strings['PayoutStatusPending'] = "Pago pendiente";
$strings['PayoutStatusCanceled'] = "Pago cancelado";
$strings['PayoutStatusCompleted'] = "Pago completado";
$strings['PayoutsTotalPending'] = "Pagos pendientes:";
$strings['PayoutsTotalCanceled'] = "Pagos cancelados:";
$strings['PayoutsTotalCompleted'] = "Pagos completados:";
$strings['TotalAmount'] = "Monto total:";
$strings['CourseListOnSale'] = "Lista de cursos a la venta";
$strings['AvailableCourses'] = "Cursos disponibles";
$strings['Price'] = "Precio";
@ -49,9 +81,11 @@ $strings['OnceItIsConfirmedYouWillReceiveAnEmailWithTheBankInformationAndAnOrder
$strings['SubscriptionToCourseXSuccessful'] = "Tu subscripción a \"%s\" se realizó correctamente.";
$strings['OrderCanceled'] = "Pedido cancelado";
$strings['OrderStatus'] = "Estado del pedido";
$strings['PayoutStatus'] = "Estado del pago";
$strings['SearchByStatus'] = "Buscar por estado";
$strings['OrderReference'] = "Referencia del pedido";
$strings['OrderDate'] = "Fecha del pedido";
$strings['OrderPrice'] = "Precio del pedido";
$strings['ProductType'] = "Tipo de producto";
$strings['SubscribeUser'] = "Inscribir usuario";
$strings['DeleteOrder'] = "Eliminar pedido";
@ -70,6 +104,8 @@ $strings['PendingReasonByVerify'] = "<b>Pendiente</b>. Lo sentimos. Todavía no
$strings['PendingReasonByOther'] = "<b>Pendiente</b>. Por favor contacta al administrador de la plataforma.";
$strings['PayPalPaymentOKPleaseConfirm'] = "PayPal nos indicó que todo estaba listo para ejecutar el pago. Por seguridad, le pedimos confirme una última vez su pedido dando clic en el botón de confirmación a bajo. Una vez le haya dado clic, será registrado al curso y el monto correspondiente será retirado de su cuenta PayPal. Siempre puede acceder a sus cursos a partir de la pestaña 'Mis cursos'. Gracias por su compra!";
$strings['Sandbox'] = "Entorno de Pruebas";
$strings['PayPalAccount'] = "Cuenta de Paypal";
$strings['NoPayPalAccountDetected'] = "No se ingresó una cuenta de Paypal";
$strings['PayPalConfig'] = "Configuración PayPal:";
$strings['TransfersConfig'] = "Configuraci&oacute;n de transferencias:";
$strings['PluginInstruction'] = "Puede activar o desactivar la opción de pagos vía PayPal o configuración de transferencias bancarias, en la sección del configuración del plugin.";

@ -1,3 +1,275 @@
.buy-courses-tabs {
margin-bottom: 15px;
}
// spinner wobblebar
@-moz-keyframes wobblebar-loader {
0% {
left: 4px;
}
3% {
left: 204px;
}
6% {
left: 4px;
}
9% {
left: 204px;
}
12% {
left: 4px;
}
15% {
left: 204px;
}
18% {
left: 32px;
}
27% {
left: 32px;
}
30% {
left: 204px;
}
33% {
left: 4px;
}
36% {
left: 204px;
}
39% {
left: 4px;
}
42% {
left: 204px;
}
45% {
left: 4px;
}
48% {
left: 204px;
}
51% {
left: 152px;
}
63% {
left: 152px;
}
66% {
left: 4px;
}
69% {
left: 204px;
}
72% {
left: 4px;
}
75% {
left: 204px;
}
78% {
left: 4px;
}
81% {
left: 204px;
}
84% {
left: 72px;
}
94% {
left: 72px;
}
97% {
left: 204px;
}
}
@-webkit-keyframes wobblebar-loader {
0% {
left: 4px;
}
3% {
left: 204px;
}
6% {
left: 4px;
}
9% {
left: 204px;
}
12% {
left: 4px;
}
15% {
left: 204px;
}
18% {
left: 32px;
}
27% {
left: 32px;
}
30% {
left: 204px;
}
33% {
left: 4px;
}
36% {
left: 204px;
}
39% {
left: 4px;
}
42% {
left: 204px;
}
45% {
left: 4px;
}
48% {
left: 204px;
}
51% {
left: 152px;
}
63% {
left: 152px;
}
66% {
left: 4px;
}
69% {
left: 204px;
}
72% {
left: 4px;
}
75% {
left: 204px;
}
78% {
left: 4px;
}
81% {
left: 204px;
}
84% {
left: 72px;
}
94% {
left: 72px;
}
97% {
left: 204px;
}
}
@keyframes wobblebar-loader {
0% {
left: 4px;
}
3% {
left: 204px;
}
6% {
left: 4px;
}
9% {
left: 204px;
}
12% {
left: 4px;
}
15% {
left: 204px;
}
18% {
left: 32px;
}
27% {
left: 32px;
}
30% {
left: 204px;
}
33% {
left: 4px;
}
36% {
left: 204px;
}
39% {
left: 4px;
}
42% {
left: 204px;
}
45% {
left: 4px;
}
48% {
left: 204px;
}
51% {
left: 152px;
}
63% {
left: 152px;
}
66% {
left: 4px;
}
69% {
left: 204px;
}
72% {
left: 4px;
}
75% {
left: 204px;
}
78% {
left: 4px;
}
81% {
left: 204px;
}
84% {
left: 72px;
}
94% {
left: 72px;
}
97% {
left: 204px;
}
}
/* :not(:required) hides this rule from IE9 and below */
.wobblebar-loader:not(:required) {
background: #2E6DA4;
-moz-border-radius: 10.66667px;
-webkit-border-radius: 10.66667px;
border-radius: 10.66667px;
display: inline-block;
overflow: hidden;
text-indent: -9999px;
width: 228px;
height: 21.33333px;
position: relative;
}
.wobblebar-loader:not(:required)::after {
-moz-animation: wobblebar-loader 15000ms infinite ease;
-webkit-animation: wobblebar-loader 15000ms infinite ease;
animation: wobblebar-loader 15000ms infinite ease;
background: white;
display: block;
-moz-border-radius: 7.11111px;
-webkit-border-radius: 7.11111px;
border-radius: 7.11111px;
content: '';
position: absolute;
top: 3.55556px;
left: 4px;
width: 21.33333px;
height: 14.22222px;
}

@ -0,0 +1,131 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
function showSliders(maxPercentage, type, defaultValues) {
defaultValues = defaultValues || "0";
var sliderCounter = 1;
var percentage = 0;
var minPercentage = 0;
$("#selectBox option:selected").each(function() {
var count = $("#selectBox option:selected").length;
percentage = maxPercentage / count;
percentage = parseInt(percentage);
verifyMaxPercentage = percentage * count;
if (verifyMaxPercentage !== maxPercentage && sliderCounter === 1) {
percentage = percentage + (maxPercentage - verifyMaxPercentage);
}
beneficiaryId = $(this).val();
beneficiaryName = $(this).text();
var slidersValue = defaultValues.toString().split(',');
if (type === 'default') {
percentage = slidersValue[sliderCounter - 1];
percentage = parseInt(percentage);
$("#panelSliders").append("<span>" + beneficiaryName + "</span> - [ <span class='value' >" + percentage + "</span> % ]<div id=" + beneficiaryId + " class='panelSliders'></div>");
} else if (type === 'renew') {
$("#panelSliders").append("<span>" + beneficiaryName + "</span> - [ <span class='value' >" + percentage + "</span> % ]<div id=" + beneficiaryId + " class='panelSliders'></div>");
}
sliderCounter++;
stepSlide = count - 1;
if (stepSlide === 0) {
(type === 'default') ? minPercentage = 0 : minPercentage = 100;
(type === 'default') ? stepSlide = 100 : stepSlide = 1;
}
$( "#panelSliders .panelSliders" ).slider({
value: percentage,
min: minPercentage,
max: maxPercentage,
step: stepSlide,
animate: true,
slide: function( event, ui ) {
$(this).prev(".value").text(ui.value);
var total = 0;
var sliders = $( "#panelSliders .panelSliders" );
sliders.not(this).each(function() {
value = $(this).slider("option", "value");
total += value;
});
total += ui.value;
var delta = 100 - total;
sliders.not(this).each(function() {
var t = $(this);
value = t.slider("option", "value");
var newValue = value + (delta/stepSlide);
if (newValue < 0 || ui.value == 100)
newValue = 0;
if (newValue > 100)
newValue = 100;
t.prev('.value').text(newValue);
t.slider('value', newValue);
});
$("[name=\'comissions\']").val(getSlidersValues());
}
});
});
$("[name=\'comissions\']").val(getSlidersValues());
showCorrectSliderHandler();
};
function getSlidersValues() {
var comissions = "";
$( "#panelSliders .panelSliders" ).each(function() {
comissions += $(this).prev(".value").text() + ',';
});
comissions = comissions.substring(0, comissions.length-1);
return comissions;
}
function showCorrectSliderHandler() {
var correctHandler = [];
$("#panelSliders > span").each(function () {
if ($(this).hasClass('value')) {
correctHandler.push($(this).text());
}
});
var counter = 0;
$("#panelSliders .panelSliders > span").each(function () {
if ($(this).hasClass('ui-slider-handle')) {
$(this).css('left', correctHandler[counter]+'%');
counter++;
}
});
}

@ -7,6 +7,7 @@
* @author Imanol Losada <imanol.losada@beeznest.com>
* @author Alex Aragón <alex.aragon@beeznest.com>
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @author José Loguercio Silva <jose.loguercio@beeznest.com>
*/
class BuyCoursesPlugin extends Plugin
{
@ -16,10 +17,15 @@ class BuyCoursesPlugin extends Plugin
const TABLE_ITEM_BENEFICIARY = 'plugin_buycourses_item_rel_beneficiary';
const TABLE_SALE = 'plugin_buycourses_sale';
const TABLE_TRANSFER = 'plugin_buycourses_transfer';
const TABLE_COMISSION = 'plugin_buycourses_comission';
const TABLE_PAYPAL_PAYOUTS = 'plugin_buycourses_paypal_payouts';
const PRODUCT_TYPE_COURSE = 1;
const PRODUCT_TYPE_SESSION = 2;
const PAYMENT_TYPE_PAYPAL = 1;
const PAYMENT_TYPE_TRANSFER = 2;
const PAYOUT_STATUS_CANCELED = 2;
const PAYOUT_STATUS_PENDING = 0;
const PAYOUT_STATUS_COMPLETED = 1;
const SALE_STATUS_CANCELED = -1;
const SALE_STATUS_PENDING = 0;
const SALE_STATUS_COMPLETED = 1;
@ -39,17 +45,19 @@ class BuyCoursesPlugin extends Plugin
parent::__construct(
'1.0',
"
Jose Angel Ruiz - NoSoloRed (original author),
Francis Gonzales and Yannick Warnier - BeezNest (integration),
Alex Aragón - BeezNest (Design icons and css styles),
Imanol Losada - BeezNest (introduction of sessions purchase),
Angel Fernando Quiroz Campos - BeezNest (cleanup and new reports)
Jose Angel Ruiz - NoSoloRed (original author) <br/>
Francis Gonzales and Yannick Warnier - BeezNest (integration) <br/>
Alex Aragón - BeezNest (Design icons and css styles) <br/>
Imanol Losada - BeezNest (introduction of sessions purchase) <br/>
Angel Fernando Quiroz Campos - BeezNest (cleanup and new reports) <br/>
José Loguercio Silva - BeezNest (pay teachers and comissions)
",
array(
'show_main_menu_tab' => 'boolean',
'include_sessions' => 'boolean',
'paypal_enable' => 'boolean',
'transfer_enable' => 'boolean',
'comissions_enable' => 'boolean',
'unregistered_users_enable' => 'boolean'
)
);
@ -66,7 +74,9 @@ class BuyCoursesPlugin extends Plugin
self::TABLE_ITEM_BENEFICIARY,
self::TABLE_ITEM,
self::TABLE_SALE,
self::TABLE_CURRENCY
self::TABLE_CURRENCY,
self::TABLE_COMISSION,
self::TABLE_PAYPAL_PAYOUTS
);
$em = Database::getManager();
$cn = $em->getConnection();
@ -91,7 +101,9 @@ class BuyCoursesPlugin extends Plugin
self::TABLE_ITEM_BENEFICIARY,
self::TABLE_ITEM,
self::TABLE_SALE,
self::TABLE_CURRENCY
self::TABLE_CURRENCY,
self::TABLE_COMISSION,
self::TABLE_PAYPAL_PAYOUTS
);
foreach ($tablesToBeDeleted as $tableToBeDeleted) {
@ -760,6 +772,32 @@ class BuyCoursesPlugin extends Plugin
'first'
);
}
/**
* Get a list of sales by the payment type
* @param int $paymentType The payment type to filter (default : Paypal)
* @return array The sale list. Otherwise return false
*/
public function getSaleListByPaymentType($paymentType = self::PAYMENT_TYPE_PAYPAL)
{
$saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
$currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$innerJoins = "
INNER JOIN $currencyTable c ON s.currency_id = c.id
INNER JOIN $userTable u ON s.user_id = u.id
";
return Database::select(
['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
"$saleTable s $innerJoins",
[
'where' => ['s.payment_type = ? AND s.status = ?' => [intval($paymentType), self::SALE_STATUS_COMPLETED]],
'order' => 'id DESC'
]
);
}
/**
* Get currency data by ID
@ -894,6 +932,19 @@ class BuyCoursesPlugin extends Plugin
self::SALE_STATUS_COMPLETED => $this->get_lang('SaleStatusCompleted')
];
}
/**
* Get the statuses for Payouts
* @return array
*/
public function getPayoutStatuses()
{
return [
self::PAYOUT_STATUS_CANCELED => $this->get_lang('PayoutStatusCanceled'),
self::PAYOUT_STATUS_PENDING => $this->get_lang('PayoutStatusPending'),
self::PAYOUT_STATUS_COMPLETED => $this->get_lang('PayoutStatusCompleted')
];
}
/**
* Get the list of product types
@ -1103,6 +1154,39 @@ class BuyCoursesPlugin extends Plugin
]
);
}
/**
* Get a list of sales by the user id
* @param int $id The user id
* @return array The sale list. Otherwise return false
*/
public function getSaleListByUserId($id)
{
if (empty($id)) {
return [];
}
$saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
$currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$innerJoins = "
INNER JOIN $currencyTable c ON s.currency_id = c.id
INNER JOIN $userTable u ON s.user_id = u.id
";
return Database::select(
['c.iso_code', 'u.firstname', 'u.lastname', 's.*'],
"$saleTable s $innerJoins",
[
'where' => [
'u.id = ?' => $id
],
'order' => 'id DESC'
]
);
}
/**
* Convert the course info to array with necessary course data for save item
@ -1293,7 +1377,7 @@ class BuyCoursesPlugin extends Plugin
/**
* Register the beneficiaries users with the sale of item
* @param int $itemId The item ID
* @param array $userIds The beneficiary user ID
* @param array $userIds The beneficiary user ID and Teachers comissions if enabled
*/
public function registerItemBeneficiaries($itemId, array $userIds)
{
@ -1301,12 +1385,13 @@ class BuyCoursesPlugin extends Plugin
$this->deleteItemBeneficiaries($itemId);
foreach ($userIds as $userId) {
foreach ($userIds as $userId => $comissions) {
Database::insert(
$beneficiaryTable,
[
'item_id' => intval($itemId),
'user_id' => intval($userId)
'user_id' => intval($userId),
'comissions' => intval($comissions)
]
);
}
@ -1329,5 +1414,151 @@ class BuyCoursesPlugin extends Plugin
return false;
}
/**
* Gets the beneficiaries with comissions and current paypal accounts by sale
* @param int $saleId The sale ID
* @return array
*/
public function getBeneficiariesBySale($saleId)
{
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$beneficiaries = [];
$sale = $this->getSale($saleId);
$item = $this->getItemByProduct($sale['product_id'], $sale['product_type']);
$itemBeneficiaries = $this->getItemBeneficiaries($item['id']);
return $itemBeneficiaries;
}
/**
* gets all payouts
* @param int $status - default 0 - pending
* @param int $payoutId - for get an individual payout if want all then false
* @return array
*/
public function getPayouts($status = self::PAYOUT_STATUS_PENDING, $payoutId = false, $userId = false)
{
$condition = ($payoutId) ? 'AND p.id = '. intval($payoutId) : '';
$condition2 = ($userId) ? ' AND p.user_id = ' . intval($userId) : '';
$typeResult = ($condition) ? 'first' : 'all';
$payoutsTable = Database::get_main_table(BuyCoursesPlugin::TABLE_PAYPAL_PAYOUTS);
$saleTable = Database::get_main_table(BuyCoursesPlugin::TABLE_SALE);
$currencyTable = Database::get_main_table(BuyCoursesPlugin::TABLE_CURRENCY);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$extraFieldTable = Database::get_main_table(TABLE_EXTRA_FIELD);
$extraFieldValues = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$paypalExtraField = Database::select(
"*",
$extraFieldTable,
[
'where' => ['variable = ?' => 'paypal']
],
'first'
);
if (!$paypalExtraField) {
return false;
}
$innerJoins = "
INNER JOIN $userTable u ON p.user_id = u.id
INNER JOIN $saleTable s ON s.id = p.sale_id
INNER JOIN $currencyTable c ON s.currency_id = c.id
LEFT JOIN $extraFieldValues efv ON p.user_id = efv.item_id
AND field_id = " . intval($paypalExtraField['id']) . "
";
$payouts = Database::select(
"p.* , u.firstname, u.lastname, efv.value as paypal_account, s.reference as sale_reference, s.price as item_price, c.iso_code",
"$payoutsTable p $innerJoins",
[
'where' => ['p.status = ? '.$condition . ' ' .$condition2 => $status]
],
$typeResult
);
return $payouts;
}
/**
* Register the users payouts
* @param int $saleId The sale ID
* @return array
*/
public function storePayouts($saleId)
{
$payoutsTable = Database::get_main_table(BuyCoursesPlugin::TABLE_PAYPAL_PAYOUTS);
$platformComission = $this->getPlatformComission();
$sale = $this->getSale($saleId);
$teachersComission = number_format((floatval($sale['price']) * intval($platformComission['comission']))/100, 2);
$beneficiaries = $this->getBeneficiariesBySale($saleId);
foreach ($beneficiaries as $beneficiarie) {
Database::insert(
$payoutsTable,
[
'date' => $sale['date'],
'payout_date' => getdate(),
'sale_id' => intval($saleId),
'user_id' => $beneficiarie['user_id'],
'comission' => number_format((floatval($teachersComission) * intval($beneficiarie['comissions']))/100, 2),
'status' => self::PAYOUT_STATUS_PENDING
]
);
}
}
/**
* Register the users payouts
* @param int $payoutId The payout ID
* @param int $status The status to set (-1 to cancel, 0 to pending, 1 to completed)
* @return array
*/
public function setStatusPayouts($payoutId, $status)
{
$payoutsTable = Database::get_main_table(BuyCoursesPlugin::TABLE_PAYPAL_PAYOUTS);
Database::update(
$payoutsTable,
['status' => $status],
['id = ?' => intval($payoutId)]
);
}
/**
* Gets the stored platform comission params
* @return array
*/
public function getPlatformComission()
{
return Database::select(
'*',
Database::get_main_table(BuyCoursesPlugin::TABLE_COMISSION),
['id = ?' => 1],
'first'
);
}
/**
* Update the platform comission
* @param int $params platform comission
* @return int The number of affected rows. Otherwise return false
*/
public function updateComission($params)
{
$comissionTable = Database::get_main_table(BuyCoursesPlugin::TABLE_COMISSION);
return Database::update(
$comissionTable,
['comission' => intval($params['comission'])]
);
}
}

@ -0,0 +1,226 @@
<?php
/* For licensing terms, see /chamilo_license.txt */
/**
* Responses to AJAX calls
* @package chamilo.plugin.buycourses
*/
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
api_protect_admin_script(true);
$plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$comissionsEnable = $plugin->get('comissions_enable');
$action = isset($_GET['a']) ? $_GET['a'] : null;
switch ($action) {
case 'saleInfo':
if (api_is_anonymous()) {
break;
}
$saleId = isset($_POST['id']) ? $_POST['id'] : '';
$sale = $plugin->getSale($saleId);
$productType = ($sale['product_type'] == 1) ? get_lang('Course') : get_lang('Session');
$paymentType = ($sale['payment_type'] == 1) ? 'Paypal' : $plugin->get_lang('BankTransfer');
$productInfo = ($sale['product_type'] == 1) ? api_get_course_info_by_id($sale['product_id']) : api_get_session_info($sale['product_id']);
$currency = $plugin->getSelectedCurrency();
if ($sale['product_type'] == 1) {
$productImage = $productInfo['course_image_large'];
} else {
$productImage = ($productInfo['image']) ? $productInfo['image'] : Template::get_icon_path('session_default.png');
}
$userInfo = api_get_user_info($sale['user_id']);
$html = '<h2>' . $sale['product_name'] .'</h2>';
$html .= '<div class="row">';
$html .= '<div class="col-sm-6 col-md-6">';
$html .= '<ul>';
$html .= '<li><b>'. $plugin->get_lang('OrderPrice') . ':</b> '. $sale['price'] . '</li>';
$html .= '<li><b>'. $plugin->get_lang('CurrencyType') . ':</b> '. $currency['iso_code'] . '</li>';
$html .= '<li><b>'. $plugin->get_lang('ProductType') . ':</b> '. $productType . '</li>';
$html .= '<li><b>'. $plugin->get_lang('OrderDate') . ':</b> '. api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H) . '</li>';
$html .= '<li><b>'. $plugin->get_lang('Buyer') . ':</b> '. $userInfo['complete_name'] . '</li>';
$html .= '<li><b>'. $plugin->get_lang('PaymentMethods') . ':</b> '. $paymentType . '</li>';
$html .= '</ul>';
$html .= '</div>';
$html .= '<div class="col-sm-6 col-md-6">';
$html .= '<img class="thumbnail" src="'. $productImage .'" >';
$html .= '</div>';
$html .= '</div>';
echo $html;
break;
case 'stats':
if (api_is_anonymous()) {
break;
}
$stats = [];
$stats['completed_count'] = 0;
$stats['completed_total_amount'] = 0;
$stats['pending_count'] = 0;
$stats['pending_total_amount'] = 0;
$stats['canceled_count'] = 0;
$stats['canceled_total_amount'] = 0;
$completedPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED);
$pendingPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING);
$canceledPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_CANCELED);
$currency = $plugin->getSelectedCurrency();
foreach ($completedPayouts as $completed) {
$stats['completed_count'] = count($completedPayouts);
$stats['completed_total_amount'] += $completed['comission'];
$stats['completed_total_amount'] = number_format($stats['completed_total_amount'], 2);
}
foreach ($pendingPayouts as $pending) {
$stats['pending_count'] = count($pendingPayouts);
$stats['pending_total_amount'] += $pending['comission'];
$stats['pending_total_amount'] = number_format($stats['pending_total_amount'], 2);
}
foreach ($canceledPayouts as $canceled) {
$stats['canceled_count'] = count($canceledPayouts);
$stats['canceled_total_amount'] += $canceled['comission'];
$stats['canceled_total_amount'] = number_format($stats['canceled_total_amount'], 2);
}
$html = '<div class="row">'
. '<p>'
. '<ul>'
. '<li>'. get_plugin_lang("PayoutsTotalCompleted", "BuyCoursesPlugin") .' <b>'. $stats['completed_count'] .'</b> - '. get_plugin_lang("TotalAmount", "BuyCoursesPlugin") .' <b>'. $stats['completed_total_amount'] .' '. $currency['iso_code'] . '</b></li>'
. '<li>'. get_plugin_lang("PayoutsTotalPending", "BuyCoursesPlugin") .' <b>'. $stats['pending_count'] .'</b> - '. get_plugin_lang("TotalAmount", "BuyCoursesPlugin") .' <b>'. $stats['pending_total_amount'] .' '. $currency['iso_code'] . '</b></li>'
. '<li>'. get_plugin_lang("PayoutsTotalCanceled", "BuyCoursesPlugin") .' <b>'. $stats['canceled_count'] .'</b> - '. get_plugin_lang("TotalAmount", "BuyCoursesPlugin") .' <b>'. $stats['canceled_total_amount'] .' '. $currency['iso_code'] . '</b></li>'
. '</ul>'
. '</p>';
$html .= '</div>';
echo $html;
break;
case 'processPayout':
if (api_is_anonymous()) {
break;
}
$html = '';
$allPays = [];
$totalAccounts = 0;
$totalPayout = 0;
$payouts = isset($_POST['payouts']) ? $_POST['payouts'] : '';
if (!$payouts) {
echo Display::return_message(get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false);
break;
}
foreach($payouts as $index => $id) {
$allPays[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id);
}
foreach($allPays as $payout) {
$totalPayout += number_format($payout['comission'], 2);
$totalAccounts++;
}
$currentCurrency = $plugin->getSelectedCurrency();
$isoCode = $currentCurrency['iso_code'];
$html .= '<p>'. get_plugin_lang("VerifyTotalAmountToProceedPayout", "BuyCoursesPlugin") .'</p>';
$html .= ''
. '<p>'
. '<ul>'
. '<li>'. get_plugin_lang("TotalAcounts", "BuyCoursesPlugin") .' <b>'. $totalAccounts .'</b></li>'
. '<li>'. get_plugin_lang("TotalPayout", "BuyCoursesPlugin") .' <b>'. $isoCode .' '. $totalPayout .'</b></li>'
. '</ul>'
. '</p>';
$html .= '<p>'. get_plugin_lang("CautionThisProcessCantBeCanceled", "BuyCoursesPlugin") .'</p>';
$html .= '</br></br>';
$html .= '<div id="spinner" class="text-center"></div>';
echo $html;
break;
case 'proceedPayout':
if (api_is_anonymous()) {
break;
}
$paypalParams = $plugin->getPaypalParams();
$pruebas = $paypalParams['sandbox'] == 1;
$paypalUsername = $paypalParams['username'];
$paypalPassword = $paypalParams['password'];
$paypalSignature = $paypalParams['signature'];
require_once("paypalfunctions.php");
$allPayouts = [];
$totalAccounts = 0;
$totalPayout = 0;
$payouts = isset($_POST['payouts']) ? $_POST['payouts'] : '';
if (!$payouts) {
echo Display::return_message(get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false);
break;
}
foreach($payouts as $index => $id) {
$allPayouts[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id);
}
$currentCurrency = $plugin->getSelectedCurrency();
$isoCode = $currentCurrency['iso_code'];
$result = MassPayment($allPayouts, $isoCode);
if($result['ACK'] === 'Success') {
foreach($allPayouts as $payout) {
$plugin->setStatusPayouts($payout['id'], BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED);
}
echo Display::return_message(get_plugin_lang("PayoutSuccess", "BuyCoursesPlugin"), 'success', false);
} else {
echo Display::return_message('<b>'.$result['L_SEVERITYCODE0'].' '.$result['L_ERRORCODE0'].'</b> - '.$result['L_SHORTMESSAGE0'].'</br><ul><li>'. $result['L_LONGMESSAGE0'].'</li></ul>', 'error', false);
}
break;
case 'cancelPayout':
if (api_is_anonymous()) {
break;
}
$payoutId = isset($_POST['id']) ? $_POST['id'] : '';
$plugin->setStatusPayouts($payoutId, BuyCoursesPlugin::PAYOUT_STATUS_CANCELED);
echo '';
break;
}
exit;

@ -19,6 +19,15 @@ if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
$plugin = BuyCoursesPlugin::create();
$comissionsEnable = $plugin->get('comissions_enable');
if ($comissionsEnable == "true") {
$htmlHeadXtra[] = '<script type="text/javascript" src="' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/resources/js/comissions.js"></script>';
$defaultComissions = [];
$comissions = "";
}
$includeSession = $plugin->get('include_sessions') === 'true';
@ -62,6 +71,16 @@ if ($editingCourse) {
if (!empty($currentBeneficiaries)) {
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
if ($comissionsEnable == "true") {
$defaultComissions = array_column($currentBeneficiaries, 'comissions');
foreach ($defaultComissions as $defaultComission) {
$comissions .= $defaultComission.',';
}
$comissions = substr($comissions, 0, -1);
}
}
$currencyIso = $courseItem['currency'];
@ -72,7 +91,8 @@ if ($editingCourse) {
'name' => $courseItem['course_title'],
'visible' => $courseItem['visible'],
'price' => $courseItem['price'],
'beneficiaries' => $defaultBeneficiaries
'beneficiaries' => $defaultBeneficiaries,
($comissionsEnable == "true") ? 'comissions' : '' => ($comissionsEnable == "true") ? $comissions : ''
];
} elseif ($editingSession) {
if (!$includeSession) {
@ -117,6 +137,16 @@ if ($editingCourse) {
if (!empty($currentBeneficiaries)) {
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
if ($comissionsEnable == "true") {
$defaultComissions = array_column($currentBeneficiaries, 'comissions');
foreach ($defaultComissions as $defaultComission) {
$comissions .= $defaultComission.',';
}
$comissions = substr($comissions, 0, -1);
}
}
$currencyIso = $sessionItem['currency'];
@ -127,12 +157,41 @@ if ($editingCourse) {
'name' => $sessionItem['session_name'],
'visible' => $sessionItem['visible'],
'price' => $sessionItem['price'],
'beneficiaries' => $defaultBeneficiaries
'beneficiaries' => $defaultBeneficiaries,
($comissionsEnable == "true") ? 'comissions' : '' => ($comissionsEnable == "true") ? $comissions : ''
];
} else {
api_not_allowed(true);
}
if ($comissionsEnable == "true") {
$htmlHeadXtra[] = ''
. '<script>'
. '$(function(){'
. 'if ($("[name=\'comissions\']").val() === "") {'
. '$("#panelSliders").html("<button id=\"setComissionsButton\" class=\"btn btn-warning\">' . get_plugin_lang("SetComissions", "BuyCoursesPlugin") . '</button>");'
. '} else {'
. 'showSliders(100, "default", "' . $comissions . '");'
. '}'
. '});'
. '$(document).ready(function() {'
. 'var maxPercentage = 100;'
. '$("#selectBox").on("change", function() {'
. ' $("#panelSliders").html("");'
. 'showSliders(maxPercentage, "renew");'
. '});'
. '$("#setComissionsButton").on("click", function() {'
. ' $("#panelSliders").html("");'
. 'showSliders(maxPercentage, "renew");'
. '});'
. '});'
. '</script>';
}
$form = new FormValidator('beneficiaries');
$form->addText('product_type', $plugin->get_lang('ProductType'), false);
$form->addText('name', get_lang('Name'), false);
@ -151,16 +210,35 @@ $beneficiariesSelect = $form->addSelect(
'beneficiaries',
$plugin->get_lang('Beneficiaries'),
null,
['multiple' => 'multiple']
['multiple' => 'multiple', 'id' => 'selectBox']
);
if ($editingCourse) {
$teachersOptions = api_unique_multidim_array($teachersOptions, 'value');
$beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers'));
} elseif ($editingSession) {
$courseCoachesOptions = api_unique_multidim_array($courseCoachesOptions, 'value');
$beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach'));
$beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach'));
}
if ($comissionsEnable == "true") {
$form->addHtml( ''
. '<div class="form-group">'
. '<label for="sliders" class="col-sm-2 control-label">'
. get_plugin_lang('Comissions', 'BuyCoursesPlugin')
. '</label>'
. '<div class="col-sm-8">'
. '<div class="" id="panelSliders"></div>'
. '</div>'
. '</div>'
);
$form->addHidden('comissions', '');
}
$form->addHidden('t', null);
$form->addHidden('i', null);
$form->addButtonSave(get_lang('Save'));
@ -190,7 +268,18 @@ if ($form->validate()) {
$plugin->deleteItemBeneficiaries($productItem['id']);
if (isset($formValues['beneficiaries'])) {
$plugin->registerItemBeneficiaries($productItem['id'], $formValues['beneficiaries']);
if ($comissionsEnable == "true") {
$usersId = $formValues['beneficiaries'];
$comissions = explode(",", $formValues['comissions']);
$comissions = (count($usersId) != count($comissions)) ? array_fill(0, count($usersId), 0) : $comissions;
$beneficiaries = array_combine($usersId, $comissions);
} else {
$usersId = $formValues['beneficiaries'];
$comissions = array_fill(0, count($usersId), 0);
$beneficiaries = array_combine($usersId, $comissions);
}
$plugin->registerItemBeneficiaries($productItem['id'], $beneficiaries);
}
} else {
$plugin->deleteItem($productItem['id']);

@ -0,0 +1,61 @@
<?php
/**
* User Panel
* @package chamilo.plugin.buycourses
*/
/**
* Initialization
*/
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
$plugin = BuyCoursesPlugin::create();
$includeSessions = $plugin->get('include_sessions') === 'true';
$userInfo = api_get_user_info();
$productTypes = $plugin->getProductTypes();
$saleStatuses = $plugin->getSaleStatuses();
$paymentTypes = $plugin->getPaymentTypes();
$sales = $plugin->getSaleListByUserId($userInfo['id']);
$saleList = [];
foreach ($sales as $sale) {
if ($sale['product_type'] == 1) {
$saleList[] = [
'id' => $sale['id'],
'reference' => $sale['reference'],
'date' => api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H),
'currency' => $sale['iso_code'],
'price' => $sale['price'],
'product_name' => $sale['product_name'],
'product_type' => $productTypes[$sale['product_type']],
'payment_type' => $paymentTypes[$sale['payment_type']]
];
}
}
$toolbar = Display::toolbarButton(
$plugin->get_lang('CourseListOnSale'),
'course_catalog.php',
'search-plus',
'primary',
['title' => $plugin->get_lang('CourseListOnSale')]
);
$templateName = get_lang('TabsDashboard');
$tpl = new Template($templateName);
$tpl->assign('showing_courses', true);
$tpl->assign('sessions_are_included', $includeSessions);
$tpl->assign('sale_list', $saleList);
$content = $tpl->fetch('buycourses/view/course_panel.tpl');
$tpl->assign('actions', $toolbar);
$tpl->assign('header', $templateName);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -13,7 +13,7 @@ $guess_enable = $plugin->get('unregistered_users_enable');
if ($guess_enable == "true" || isset($_SESSION['_user'])) {
// If the user is NOT an administrator, redirect it to course/session buy list
if (!api_is_platform_admin()) {
header('Location: src/course_catalog.php');
header('Location: src/course_panel.php');
exit;
}

@ -0,0 +1,220 @@
<?php
/* For licensing terms, see /chamilo_license.txt */
/**
* Responses to AJAX calls
* @package chamilo.plugin.buycourses
*/
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
api_protect_admin_script(true);
$plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$comissionsEnable = $plugin->get('comissions_enable');
$action = isset($_GET['a']) ? $_GET['a'] : null;
switch ($action) {
case 'saleInfo':
$saleId = isset($_POST['id']) ? $_POST['id'] : '';
$sale = $plugin->getSale($saleId);
$productType = ($sale['product_type'] == 1) ? get_lang('Course') : get_lang('Session');
$paymentType = ($sale['payment_type'] == 1) ? 'Paypal' : $plugin->get_lang('BankTransfer');
$productInfo = ($sale['product_type'] == 1) ? api_get_course_info_by_id($sale['product_id']) : api_get_session_info($sale['product_id']);
$currency = $plugin->getSelectedCurrency();
if ($sale['product_type'] == 1) {
$productImage = $productInfo['course_image_large'];
} else {
$productImage = ($productInfo['image']) ? $productInfo['image'] : Template::get_icon_path('session_default.png');
}
$userInfo = api_get_user_info($sale['user_id']);
$html = '<h2>' . $sale['product_name'] .'</h2>';
$html .= '<div class="row">';
$html .= '<div class="col-sm-6 col-md-6">';
$html .= '<ul>';
$html .= '<li><b>'. $plugin->get_lang('OrderPrice') . ':</b> '. $sale['price'] . '</li>';
$html .= '<li><b>'. $plugin->get_lang('CurrencyType') . ':</b> '. $currency['iso_code'] . '</li>';
$html .= '<li><b>'. $plugin->get_lang('ProductType') . ':</b> '. $productType . '</li>';
$html .= '<li><b>'. $plugin->get_lang('OrderDate') . ':</b> '. api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H) . '</li>';
$html .= '<li><b>'. $plugin->get_lang('Buyer') . ':</b> '. $userInfo['complete_name'] . '</li>';
$html .= '<li><b>'. $plugin->get_lang('PaymentMethods') . ':</b> '. $paymentType . '</li>';
$html .= '</ul>';
$html .= '</div>';
$html .= '<div class="col-sm-6 col-md-6">';
$html .= '<img class="thumbnail" src="'. $productImage .'" >';
$html .= '</div>';
$html .= '</div>';
echo $html;
break;
case 'stats':
$stats = [];
$stats['completed_count'] = 0;
$stats['completed_total_amount'] = 0;
$stats['pending_count'] = 0;
$stats['pending_total_amount'] = 0;
$stats['canceled_count'] = 0;
$stats['canceled_total_amount'] = 0;
$completedPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED);
$pendingPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING);
$canceledPayouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_CANCELED);
$currency = $plugin->getSelectedCurrency();
foreach ($completedPayouts as $completed) {
$stats['completed_count'] = count($completedPayouts);
$stats['completed_total_amount'] += $completed['comission'];
$stats['completed_total_amount'] = number_format($stats['completed_total_amount'], 2);
}
foreach ($pendingPayouts as $pending) {
$stats['pending_count'] = count($pendingPayouts);
$stats['pending_total_amount'] += $pending['comission'];
$stats['pending_total_amount'] = number_format($stats['pending_total_amount'], 2);
}
foreach ($canceledPayouts as $canceled) {
$stats['canceled_count'] = count($canceledPayouts);
$stats['canceled_total_amount'] += $canceled['comission'];
$stats['canceled_total_amount'] = number_format($stats['canceled_total_amount'], 2);
}
$html = '<div class="row">'
. '<p>'
. '<ul>'
. '<li>'. get_plugin_lang("PayoutsTotalCompleted", "BuyCoursesPlugin") .' <b>'. $stats['completed_count'] .'</b> - '. get_plugin_lang("TotalAmount", "BuyCoursesPlugin") .' <b>'. $stats['completed_total_amount'] .' '. $currency['iso_code'] . '</b></li>'
. '<li>'. get_plugin_lang("PayoutsTotalPending", "BuyCoursesPlugin") .' <b>'. $stats['pending_count'] .'</b> - '. get_plugin_lang("TotalAmount", "BuyCoursesPlugin") .' <b>'. $stats['pending_total_amount'] .' '. $currency['iso_code'] . '</b></li>'
. '<li>'. get_plugin_lang("PayoutsTotalCanceled", "BuyCoursesPlugin") .' <b>'. $stats['canceled_count'] .'</b> - '. get_plugin_lang("TotalAmount", "BuyCoursesPlugin") .' <b>'. $stats['canceled_total_amount'] .' '. $currency['iso_code'] . '</b></li>'
. '</ul>'
. '</p>';
$html .= '</div>';
echo $html;
break;
case 'processPayout':
if (api_is_anonymous()) {
break;
}
$html = '';
$allPays = [];
$totalAccounts = 0;
$totalPayout = 0;
$payouts = isset($_POST['payouts']) ? $_POST['payouts'] : '';
if (!$payouts) {
echo Display::return_message(get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false);
break;
}
foreach($payouts as $index => $id) {
$allPays[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id);
}
foreach($allPays as $payout) {
$totalPayout += number_format($payout['comission'], 2);
$totalAccounts++;
}
$currentCurrency = $plugin->getSelectedCurrency();
$isoCode = $currentCurrency['iso_code'];
$html .= '<p>'. get_plugin_lang("VerifyTotalAmountToProceedPayout", "BuyCoursesPlugin") .'</p>';
$html .= ''
. '<p>'
. '<ul>'
. '<li>'. get_plugin_lang("TotalAcounts", "BuyCoursesPlugin") .' <b>'. $totalAccounts .'</b></li>'
. '<li>'. get_plugin_lang("TotalPayout", "BuyCoursesPlugin") .' <b>'. $isoCode .' '. $totalPayout .'</b></li>'
. '</ul>'
. '</p>';
$html .= '<p>'. get_plugin_lang("CautionThisProcessCantBeCanceled", "BuyCoursesPlugin") .'</p>';
$html .= '</br></br>';
$html .= '<div id="spinner" class="text-center"></div>';
echo $html;
break;
case 'proceedPayout':
if (api_is_anonymous()) {
break;
}
$paypalParams = $plugin->getPaypalParams();
$pruebas = $paypalParams['sandbox'] == 1;
$paypalUsername = $paypalParams['username'];
$paypalPassword = $paypalParams['password'];
$paypalSignature = $paypalParams['signature'];
require_once("paypalfunctions.php");
$allPayouts = [];
$totalAccounts = 0;
$totalPayout = 0;
$payouts = isset($_POST['payouts']) ? $_POST['payouts'] : '';
if (!$payouts) {
echo Display::return_message(get_plugin_lang("SelectOptionToProceed", "BuyCoursesPlugin"), 'error', false);
break;
}
foreach($payouts as $index => $id) {
$allPayouts[] = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_PENDING, $id);
}
$currentCurrency = $plugin->getSelectedCurrency();
$isoCode = $currentCurrency['iso_code'];
$result = MassPayment($allPayouts, $isoCode);
if($result['ACK'] === 'Success') {
foreach($allPayouts as $payout) {
$plugin->setStatusPayouts($payout['id'], BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED);
}
echo Display::return_message(get_plugin_lang("PayoutSuccess", "BuyCoursesPlugin"), 'success', false);
} else {
echo Display::return_message('<b>'.$result['L_SEVERITYCODE0'].' '.$result['L_ERRORCODE0'].'</b> - '.$result['L_SHORTMESSAGE0'].'</br><ul><li>'. $result['L_LONGMESSAGE0'].'</li></ul>', 'error', false);
}
break;
case 'cancelPayout':
if (api_is_anonymous()) {
break;
}
$payoutId = isset($_POST['id']) ? $_POST['id'] : '';
$plugin->setStatusPayouts($payoutId, BuyCoursesPlugin::PAYOUT_STATUS_CANCELED);
echo '';
break;
}
exit;

@ -17,6 +17,7 @@ $plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$transferEnable = $plugin->get('transfer_enable');
$comissionsEnable = $plugin->get('comissions_enable');
if (isset($_GET['action'], $_GET['id'])) {
if ($_GET['action'] == 'delete_taccount') {
@ -113,6 +114,34 @@ $paypalForm->addCheckBox('sandbox', null, $plugin->get_lang('Sandbox'));
$paypalForm->addButtonSave(get_lang('Save'));
$paypalForm->setDefaults($plugin->getPaypalParams());
// Platform Comissions
$comissionForm = new FormValidator('comissions');
if ($comissionForm->validate()) {
$comissionFormValues = $comissionForm->getSubmitValues();
$plugin->updateComission($comissionFormValues);
Display::addFlash(
Display::return_message(get_lang('Saved'), 'success')
);
header('Location:' . api_get_self());
exit;
}
$comissionForm->addElement(
'number',
'comission',
[$plugin->get_lang('Comission'), null, '%'],
['step' => 1, 'cols-size' => [3, 7, 1], 'min' => 0, 'max' => 100]
);
$comissionForm->addButtonSave(get_lang('Save'));
$comissionForm->setDefaults($plugin->getPlatformComission());
$transferForm = new FormValidator('transfer_account');
if ($transferForm->validate()) {
@ -165,9 +194,11 @@ $tpl = new Template($templateName);
$tpl->assign('header', $templateName);
$tpl->assign('curency_form', $currencyForm->returnForm());
$tpl->assign('paypal_form', $paypalForm->returnForm());
$tpl->assign('comission_form', $comissionForm->returnForm());
$tpl->assign('transfer_form', $transferForm->returnForm());
$tpl->assign('transfer_accounts', $transferAccounts);
$tpl->assign('paypal_enable', $paypalEnable);
$tpl->assign('comissions_enable', $comissionsEnable);
$tpl->assign('transfer_enable', $transferEnable);
$content = $tpl->fetch('buycourses/view/paymentsetup.tpl');

@ -0,0 +1,57 @@
<?php
/**
* User Panel
* @package chamilo.plugin.buycourses
*/
/**
* Initialization
*/
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
$plugin = BuyCoursesPlugin::create();
$includeSessions = $plugin->get('include_sessions') === 'true';
$userInfo = api_get_user_info();
$payouts = $plugin->getPayouts(BuyCoursesPlugin::PAYOUT_STATUS_COMPLETED, false, $userInfo['id']);
$payoutList = [];
foreach ($payouts as $payout) {
$payoutList[] = [
'id' => $payout['id'],
'sale_id' => $payout['sale_id'],
'reference' => $payout['sale_reference'],
'date' => api_format_date($payout['date'], DATE_TIME_FORMAT_LONG_24H),
'payout_date' => ($payout['payout_date'] === '0000-00-00 00:00:00') ? '-' : api_format_date($payout['payout_date'], DATE_TIME_FORMAT_LONG_24H),
'currency' => $payout['iso_code'],
'price' => $payout['item_price'],
'comission' => $payout['comission'],
'paypal_account' => $payout['paypal_account'],
'status' => $payout['status']
];
}
$toolbar = Display::toolbarButton(
$plugin->get_lang('CourseListOnSale'),
'course_catalog.php',
'search-plus',
'primary',
['title' => $plugin->get_lang('CourseListOnSale')]
);
$templateName = get_lang('TabsDashboard');
$tpl = new Template($templateName);
$tpl->assign('showing_courses', true);
$tpl->assign('sessions_are_included', $includeSessions);
$tpl->assign('payout_list', $payoutList);
$content = $tpl->fetch('buycourses/view/payout_panel.tpl');
$tpl->assign('actions', $toolbar);
$tpl->assign('header', $templateName);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -0,0 +1,90 @@
<?php
/* For license terms, see /license.txt */
/**
* List of pending payments of the Buy Courses plugin
* @package chamilo.plugin.buycourses
*/
//Initialization
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
$htmlHeadXtra[] = '<link rel="stylesheet" href="../resources/css/style.css" type="text/css">';
$htmlHeadXtra[] = '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>';
api_protect_admin_script(true);
$plugin = BuyCoursesPlugin::create();
$comissionsEnable = $plugin->get('comissions_enable');
$payoutStatuses = $plugin->getPayoutStatuses();
$selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_COMPLETED;
if ($comissionsEnable !== "true") {
api_not_allowed(true);
}
$form = new FormValidator('search', 'get');
if ($form->validate()) {
$selectedStatus = $form->getSubmitValue('status');
if ($selectedStatus === false) {
$selectedStatus = BuyCoursesPlugin::PAYOUT_STATUS_PENDING;
}
}
$form->addSelect('status', $plugin->get_lang('PayoutStatus'), $payoutStatuses);
$form->addButtonFilter(get_lang('Search'));
$form->setDefaults([
'status' => $selectedStatus
]);
switch ($selectedStatus) {
case '2':
$payouts = $plugin->getPayouts($selectedStatus);
break;
case '1':
$payouts = $plugin->getPayouts($selectedStatus);
break;
case '0':
//no break
default:
$payouts = $plugin->getPayouts();
break;
}
$payoutList = [];
foreach ($payouts as $payout) {
$payoutList[] = [
'id' => $payout['id'],
'sale_id' => $payout['sale_id'],
'reference' => $payout['sale_reference'],
'date' => api_format_date($payout['date'], DATE_TIME_FORMAT_LONG_24H),
'payout_date' => ($payout['payout_date'] === '0000-00-00 00:00:00') ? '-' : api_format_date($payout['payout_date'], DATE_TIME_FORMAT_LONG_24H),
'currency' => $payout['iso_code'],
'price' => $payout['item_price'],
'comission' => $payout['comission'],
'paypal_account' => $payout['paypal_account'],
'status' => $payout['status']
];
}
$templateName = $plugin->get_lang('PayoutReport');
$template = new Template($templateName);
$template->assign('form', $form->returnForm());
$template->assign('payout_list', $payoutList);
$template->assign('selected_status', $selectedStatus);
$content = $template->fetch('buycourses/view/payout_report.tpl');
$template->assign('header', $templateName);
$template->assign('content', $content);
$template->display_one_col_template();

@ -0,0 +1,55 @@
<?php
/* For license terms, see /license.txt */
/**
* List page for Paypal Payout for the Buy Courses plugin
* @package chamilo.plugin.buycourses
*/
/**
* Initialization
*/
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
$htmlHeadXtra[] = '<link rel="stylesheet" href="../resources/css/style.css" type="text/css">';
api_protect_admin_script(true);
$plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$comissionsEnable = $plugin->get('comissions_enable');
if ($paypalEnable !== "true" && $comissionsEnable !== "true") {
api_not_allowed(true);
}
$payouts = $plugin->getPayouts();
$payoutList = [];
foreach ($payouts as $payout) {
$payoutList[] = [
'id' => $payout['id'],
'reference' => $payout['sale_reference'],
'date' => api_format_date($payout['date'], DATE_TIME_FORMAT_LONG_24H),
'currency' => $payout['iso_code'],
'price' => $payout['item_price'],
'comission' => $payout['comission'],
'paypal_account' => $payout['paypal_account']
];
}
$templateName = $plugin->get_lang('PaypalPayoutComissions');
$template = new Template($templateName);
$template->assign('payout_list', $payoutList);
$content = $template->fetch('buycourses/view/paypal_payout.tpl');
$template->assign('header', $templateName);
$template->assign('content', $content);
$template->display_one_col_template();

@ -290,6 +290,33 @@ function DirectPayment($paymentType, $paymentAmount, $creditCardType, $creditCar
}
/**
* Purpose: This function makes a MassPay API call
* Inputs:
* Beneficiarie: Array that contains the Beneficiearie paypal account and the payout amount
* Currency Code: The currency Iso code
* Returns:
* The NVP Collection object of the MassPay Call Response.
*/
function MassPayment(array $beneficiaries, $currencyCode) {
$nvpstr = "&RECEIVERTYPE=EmailAddress";
$nvpstr .= "&CURRENCYCODE=".$currencyCode;
$index = 0;
foreach($beneficiaries as $beneficiarie) {
$nvpstr .= "&L_EMAIL".$index."=".$beneficiarie['paypal_account'];
$nvpstr .= "&L_AMT".$index."=".$beneficiarie['comission'];
$index++;
}
$resArray = hash_call("MassPay", $nvpstr);
return $resArray;
}
/**
*
* hash_call: Function to perform the API call to PayPal using API signature

@ -27,6 +27,7 @@ if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
$buyingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
$buyingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
$queryString = 'i=' . intval($_REQUEST['i']) . '&t=' . intval($_REQUEST['t']);
if ($buyingCourse) {
$courseInfo = $plugin->getCourseInfo($_REQUEST['i']);
@ -42,7 +43,15 @@ $form = new FormValidator('confirm_sale');
if ($form->validate()) {
$formValues = $form->getSubmitValues();
if (!$formValues['payment_type']) {
Display::addFlash(
Display::return_message($plugin->get_lang('NeedToSelectPaymentType'), 'error', false)
);
header('Location:' . api_get_self() . '?' . $queryString);
exit;
}
$saleId = $plugin->registerSale($item['id'], $formValues['payment_type']);
if ($saleId !== false) {

@ -14,6 +14,9 @@ api_protect_admin_script();
$plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$comissionsEnable = $plugin->get('comissions_enable');
if (isset($_GET['order'])) {
$sale = $plugin->getSale($_GET['order']);
@ -26,7 +29,7 @@ if (isset($_GET['order'])) {
switch ($_GET['action']) {
case 'confirm':
$plugin->completeSale($sale['id']);
$plugin->storePayouts($sale['id']);
Display::addFlash(
Display::return_message(
sprintf($plugin->get_lang('SubscriptionToCourseXSuccessful'), $sale['product_name']),
@ -134,6 +137,36 @@ $interbreadcrumb[] = ['url' => '../index.php', 'name' => $plugin->get_lang('plug
$templateName = $plugin->get_lang('SalesReport');
$template = new Template($templateName);
$toolbar = '';
if ($paypalEnable == "true" && $comissionsEnable == "true") {
$toolbar .= Display::toolbarButton(
$plugin->get_lang('PaypalPayoutComissions'),
api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/paypal_payout.php',
'paypal',
'primary',
['title' => $plugin->get_lang('PaypalPayoutComissions')]
);
$template->assign('actions', $toolbar);
}
if ($comissionsEnable == "true") {
$toolbar .= Display::toolbarButton(
$plugin->get_lang('PayoutReport'),
api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/payout_report.php',
'money',
'info',
['title' => $plugin->get_lang('PayoutReport')]
);
$template->assign('actions', $toolbar);
}
$template->assign('form', $form->returnForm());
$template->assign('selected_sale', $selectedSale);
$template->assign('selected_status', $selectedStatus);

@ -0,0 +1,61 @@
<?php
/**
* User Panel
* @package chamilo.plugin.buycourses
*/
/**
* Initialization
*/
$cidReset = true;
require_once '../../../main/inc/global.inc.php';
$plugin = BuyCoursesPlugin::create();
$includeSessions = $plugin->get('include_sessions') === 'true';
$userInfo = api_get_user_info();
$productTypes = $plugin->getProductTypes();
$saleStatuses = $plugin->getSaleStatuses();
$paymentTypes = $plugin->getPaymentTypes();
$sales = $plugin->getSaleListByUserId($userInfo['id']);
$saleList = [];
foreach ($sales as $sale) {
if ($sale['product_type'] == 2) {
$saleList[] = [
'id' => $sale['id'],
'reference' => $sale['reference'],
'date' => api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H),
'currency' => $sale['iso_code'],
'price' => $sale['price'],
'product_name' => $sale['product_name'],
'product_type' => $productTypes[$sale['product_type']],
'payment_type' => $paymentTypes[$sale['payment_type']]
];
}
}
$toolbar = Display::toolbarButton(
$plugin->get_lang('CourseListOnSale'),
'course_catalog.php',
'search-plus',
'primary',
['title' => $plugin->get_lang('CourseListOnSale')]
);
$templateName = get_lang('TabsDashboard');
$tpl = new Template($templateName);
$tpl->assign('showing_courses', true);
$tpl->assign('sessions_are_included', $includeSessions);
$tpl->assign('sale_list', $saleList);
$content = $tpl->fetch('buycourses/view/session_panel.tpl');
$tpl->assign('actions', $toolbar);
$tpl->assign('header', $templateName);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -89,6 +89,7 @@ if ($form->validate()) {
'success'
)
);
$plugin->storePayouts($sale['id']);
break;
}
@ -99,6 +100,7 @@ if ($form->validate()) {
'success'
)
);
$plugin->storePayouts($sale['id']);
break;
}

@ -0,0 +1,43 @@
<link rel="stylesheet" type="text/css" href="../resources/css/style.css"/>
<div id="buy-courses-tabs">
<ul class="nav nav-tabs buy-courses-tabs" role="tablist">
<li id="buy-courses-tab" class="active" role="presentation">
<a href="course_panel.php" aria-controls="buy-courses" role="tab">{{ 'MyCourses'| get_lang }}</a>
</li>
{% if sessions_are_included %}
<li id="buy-sessions-tab" class="" role="presentation">
<a href="session_panel.php" aria-controls="buy-sessions" role="tab">{{ 'MySessions'| get_lang }}</a>
</li>
{% endif %}
<li id="buy-courses-tab" class="" role="presentation">
<a href="payout_panel.php" aria-controls="buy-courses" role="tab">{{ 'MyPayouts'| get_plugin_lang('BuyCoursesPlugin') }}</a>
</li>
</ul>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>{{ 'Course'|get_lang }}</th>
<th class="text-center">{{ 'PaymentMethod'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'OrderDate'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'OrderReference'|get_plugin_lang('BuyCoursesPlugin') }}</th>
</tr>
</thead>
<tbody>
{% for sale in sale_list %}
<tr>
<td>{{ sale.product_name }}</td>
<td class="text-center">{{ sale.payment_type }}</td>
<td class="text-right">{{ sale.currency ~ ' ' ~ sale.price }}</td>
<td class="text-center">{{ sale.date }}</td>
<td class="text-center">{{ sale.reference }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

@ -32,6 +32,24 @@
</div>
{% endif %}
{% if comissions_enable == "true" %}
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{{ 'ComissionsConfig'|get_plugin_lang('BuyCoursesPlugin') }}</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-5">
<p>{{ 'InfoComissions'|get_plugin_lang('BuyCoursesPlugin') }}</p>
</div>
<div class="col-md-7">
{{ comission_form }}
</div>
</div>
</div>
</div>
{% endif %}
{% if transfer_enable == "true" %}
<div class="panel panel-default">
<div class="panel-heading">

@ -0,0 +1,41 @@
<link rel="stylesheet" type="text/css" href="../resources/css/style.css"/>
<div id="buy-courses-tabs">
<ul class="nav nav-tabs buy-courses-tabs" role="tablist">
<li id="buy-courses-tab" class="" role="presentation">
<a href="course_panel.php" aria-controls="buy-courses" role="tab">{{ 'MyCourses'| get_lang }}</a>
</li>
{% if sessions_are_included %}
<li id="buy-sessions-tab" class="" role="presentation">
<a href="session_panel.php" aria-controls="buy-sessions" role="tab">{{ 'MySessions'| get_lang }}</a>
</li>
{% endif %}
<li id="buy-courses-tab" class="active" role="presentation">
<a href="payout_panel.php" aria-controls="buy-courses" role="tab">{{ 'MyPayouts'| get_plugin_lang('BuyCoursesPlugin') }}</a>
</li>
</ul>
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="text-center">{{ 'OrderReference'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'PayoutDate'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'Comission'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }}</th>
</tr>
</thead>
<tbody>
{% for payout in payout_list %}
<tr>
<td class="text-center" style="vertical-align:middle"><a id="{{ payout.sale_id }}" class="saleInfo" data-toggle="modal" data-target="#saleInfo" href="#">{{ payout.reference }}</a></td>
<td class="text-center" style="vertical-align:middle">{{ payout.payout_date }}</td>
<td class="text-right" style="vertical-align:middle">{{ payout.currency ~ ' ' ~ payout.comission }}</td>
<td class="text-right" style="vertical-align:middle">{{ payout.paypal_account }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

@ -0,0 +1,88 @@
{{ form }}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="text-center">{{ 'OrderReference'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'PayoutDate'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'Comission'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }}</th>
</tr>
</thead>
<tbody>
{% for payout in payout_list %}
<tr>
<td class="text-center" style="vertical-align:middle"><a id="{{ payout.sale_id }}" class="saleInfo" data-toggle="modal" data-target="#saleInfo" href="#">{{ payout.reference }}</a></td>
<td class="text-center" style="vertical-align:middle">{{ payout.payout_date }}</td>
<td class="text-right" style="vertical-align:middle">{{ payout.currency ~ ' ' ~ payout.comission }}</td>
<td class="text-right" style="vertical-align:middle">{{ payout.paypal_account }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div id="saleInfo" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{ 'SaleInfo'| get_plugin_lang('BuyCoursesPlugin') }}</h4>
</div>
<div class="modal-body" id="contentSale">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ 'Close' | get_lang }}</button>
</div>
</div>
</div>
</div>
<div id="reportStats" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{ 'Stats'| get_plugin_lang('BuyCoursesPlugin') }}</h4>
</div>
<div class="modal-body" id="contentStats">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ 'Close' | get_lang }}</button>
</div>
</div>
</div>
</div>
</div>
<div>
<button id="stats" type="button" class="btn btn-primary fa fa-line-chart" data-toggle="modal" data-target="#reportStats"> {{ 'Stats'|get_plugin_lang('BuyCoursesPlugin') }}</button>
</div>
<script>
$(document).ready(function() {
$(".saleInfo").click(function() {
var id = this.id;
$.ajax({
data: 'id='+id,
url: '{{ _p.web_plugin ~ 'buycourses/src/buycourses.ajax.php?' ~ { 'a': 'saleInfo' } | url_encode() }}',
type: 'POST',
success: function(response) {
$("#contentSale").html(response);
}
});
});
$("#stats").click(function() {
var id = this.id;
$.ajax({
data: 'id='+id,
url: '{{ _p.web_plugin ~ 'buycourses/src/buycourses.ajax.php?' ~ { 'a': 'stats' } | url_encode() }}',
type: 'POST',
success: function(response) {
$("#contentStats").html(response);
}
});
});
});
</script>

@ -0,0 +1,121 @@
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="text-center"><input type="checkbox" id="checkAll"></th>
<th class="text-center">{{ 'OrderReference'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'OrderDate'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'Comission'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-right">{{ 'Options'| get_lang }}</th>
</tr>
</thead>
<tbody>
{% for payout in payout_list %}
<tr style="{{ payout.paypal_account ? '' : 'color: red;' }}">
<td class="text-center" style="vertical-align:middle">{% if payout.paypal_account %} <input id="{{ payout.id }}" type="checkbox" name="data[]" value="{{ payout.comission }}"> {% endif %}</td>
<td class="text-center" style="vertical-align:middle">{{ payout.reference }}</td>
<td class="text-center" style="vertical-align:middle">{{ payout.date }}</td>
<td class="text-right" style="vertical-align:middle">{{ payout.currency ~ ' ' ~ payout.comission }}</td>
{% if payout.paypal_account %}
<td class="text-right" style="vertical-align:middle">{{ payout.paypal_account }}</td>
{% else %}
<td class="text-right" style="vertical-align:middle">{{ 'NoPayPalAccountDetected'| get_plugin_lang('BuyCoursesPlugin') }}</td>
{% endif %}
<td class="text-right" style="vertical-align:middle"><button id="{{ payout.id }}" type="button" class="btn btn-danger fa fa-ban cancelPayout"> {{ 'CancelPayout'| get_plugin_lang('BuyCoursesPlugin') }}</button></td>
</tr>
{% endfor %}
</tbody>
</table>
<div id="startPayout" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{ 'PaypalPayoutComissions'|get_plugin_lang('BuyCoursesPlugin') }}</h4>
</div>
<div class="modal-body" id="content">
</div>
<div class="modal-footer">
<button id="proceedPayout" type="button" class="btn btn-success fa fa-paypal"> {{ 'ProceedPayout' | get_plugin_lang('BuyCoursesPlugin') }}</button>
<button id="cancelPayout" type="button" class="btn btn-danger" data-dismiss="modal">{{ 'Cancel' | get_lang }}</button>
<button id="responseButton" type="button" class="btn btn-primary">{{ 'Confirm' | get_lang }}</button>
</div>
</div>
</div>
</div>
</div>
<div>
<button id="continuePayout" type="button" class="btn btn-primary fa fa-caret-square-o-right" data-toggle="modal" data-target="#startPayout" data-backdrop="static" data-keyboard="false"> {{ 'ContinuePayout'|get_plugin_lang('BuyCoursesPlugin') }}</button>
</div>
<script>
$(document).ready(function() {
$("#responseButton").hide();
$("#checkAll").click(function() {
$(':checkbox').prop('checked', this.checked);
});
$('#continuePayout').click(function() {
var val = [];
$(':checkbox:checked').not('#checkAll').each(function(i) {
val[i] = $(this).attr("id");
});
$.ajax({
data: { payouts : val },
url: '{{ _p.web_plugin ~ 'buycourses/src/buycourses.ajax.php?' ~ { 'a': 'processPayout' } | url_encode() }}',
type: 'POST',
success: function(response) {
$("#content").html(response);
(jQuery.isEmptyObject(val)) ? $('#proceedPayout').prop( "disabled", true ) : $('#proceedPayout').prop( "disabled", false );
}
});
});
$('#proceedPayout').click(function() {
var val = [];
$(':checkbox:checked').not('#checkAll').each(function(i) {
val[i] = $(this).attr("id");
});
$.ajax({
data: { payouts : val },
url: '{{ _p.web_plugin ~ 'buycourses/src/buycourses.ajax.php?' ~ { 'a': 'proceedPayout' } | url_encode() }}',
type: 'POST',
beforeSend: function() {
$("#proceedPayout").hide();
$("#cancelPayout").hide();
$("#spinner").html('</br></br><div class="wobblebar-loader"></div><p> {{ 'ProcessingPayoutsDontCloseThisWindow' | get_plugin_lang('BuyCoursesPlugin') }} </p>');
},
success: function(response) {
$("#content").html(response);
$("#responseButton").show();
}
});
});
$(".cancelPayout").click(function() {
var id = this.id;
$.ajax({
data: 'id='+id,
url: '{{ _p.web_plugin ~ 'buycourses/src/buycourses.ajax.php?' ~ { 'a': 'cancelPayout' } | url_encode() }}',
type: 'POST',
success: function() {
window.location.reload();
}
});
});
$('#responseButton').click(function() {
window.location.reload();
});
});
</script>

@ -0,0 +1,43 @@
<link rel="stylesheet" type="text/css" href="../resources/css/style.css"/>
<div id="buy-courses-tabs">
<ul class="nav nav-tabs buy-courses-tabs" role="tablist">
<li id="buy-courses-tab" class="" role="presentation">
<a href="course_panel.php" aria-controls="buy-courses" role="tab">{{ 'MyCourses'| get_lang }}</a>
</li>
{% if sessions_are_included %}
<li id="buy-sessions-tab" class="active" role="presentation">
<a href="session_panel.php" aria-controls="buy-sessions" role="tab">{{ 'MySessions'| get_lang }}</a>
</li>
{% endif %}
<li id="buy-courses-tab" class="" role="presentation">
<a href="payout_panel.php" aria-controls="buy-courses" role="tab">{{ 'MyPayouts'| get_plugin_lang('BuyCoursesPlugin') }}</a>
</li>
</ul>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>{{ 'Session'|get_lang }}</th>
<th class="text-center">{{ 'PaymentMethod'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'OrderDate'|get_plugin_lang('BuyCoursesPlugin') }}</th>
<th class="text-center">{{ 'OrderReference'|get_plugin_lang('BuyCoursesPlugin') }}</th>
</tr>
</thead>
<tbody>
{% for sale in sale_list %}
<tr>
<td>{{ sale.product_name }}</td>
<td class="text-center">{{ sale.payment_type }}</td>
<td class="text-right">{{ sale.currency ~ ' ' ~ sale.price }}</td>
<td class="text-center">{{ sale.date }}</td>
<td class="text-center">{{ sale.reference }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
Loading…
Cancel
Save