From 23c12f718bdb6e44bfe65d0a7442d21461b6232e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Mon, 14 Dec 2015 19:30:18 -0500 Subject: [PATCH] Add some new info to buy courses payout feature and minor changes - Refs #10614 --- app/Resources/public/css/base.css | 4 ++ main/inc/lib/api.lib.php | 1 + plugin/buycourses/lang/spanish.php | 3 ++ plugin/buycourses/resources/js/commissions.js | 20 ++++++-- .../src/buy_course_plugin.class.php | 47 ++++++++++++++++++- plugin/buycourses/src/buycourses.ajax.php | 16 +++++++ plugin/buycourses/src/configuration.php | 2 + plugin/buycourses/src/configure_course.php | 8 +++- plugin/buycourses/src/course_catalog.php | 5 ++ plugin/buycourses/src/payout_report.php | 1 + plugin/buycourses/view/payout_panel.tpl | 47 +++++++++++-------- plugin/buycourses/view/payout_report.tpl | 8 +++- 12 files changed, 136 insertions(+), 26 deletions(-) diff --git a/app/Resources/public/css/base.css b/app/Resources/public/css/base.css index 16c14629e2..7fbeb8887f 100644 --- a/app/Resources/public/css/base.css +++ b/app/Resources/public/css/base.css @@ -158,6 +158,10 @@ a.thumbnail:hover{ margin: 20px 0; } +.panelSliders .ui-slider-handle { + border-color: #000; +} + #panelSliders { width: 75%; margin: 25px auto; diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index c815c5ad2c..62b0f042a7 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -8050,6 +8050,7 @@ function api_protect_course_group($tool, $showHeader = true) } /** + * Eliminate the duplicates of a multidimensional array by sending the key * @param array $array multidimensional array * @param int $key key to find to compare * diff --git a/plugin/buycourses/lang/spanish.php b/plugin/buycourses/lang/spanish.php index c4058691ea..9dbf2e6aee 100644 --- a/plugin/buycourses/lang/spanish.php +++ b/plugin/buycourses/lang/spanish.php @@ -23,6 +23,9 @@ $strings['IndividualPayout'] = "Pago individual"; $strings['CancelPayout'] = "Cancelar Payout"; $strings['ContinuePayout'] = "Continuar con el Pago"; $strings['ProceedPayout'] = "Proceder con el Pago"; +$strings['TheActualPlatformCommissionIs'] = "La actual comisión de la plataforma es de %s, este porcentaje será descontado del total del precio del producto cuya diferencia será el monto base para aplicar estas comisiones."; +$strings['CoursesInSessionsDoesntDisplayHere'] = "Los cursos que se encuentren dentro de una sesión de formación no aparecerán en la lista de cursos a configurar como productos individuales."; +$strings['WantToSellCourses'] = "¿Quieres enseñar y ganar dinero con tus propios cursos?, Esta lista puede estar llena de tus ganancias vendiendo cursos a través de esta plataforma!. Informate con nosotros! "; $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:"; diff --git a/plugin/buycourses/resources/js/commissions.js b/plugin/buycourses/resources/js/commissions.js index e444bf447e..757a6c1ee5 100644 --- a/plugin/buycourses/resources/js/commissions.js +++ b/plugin/buycourses/resources/js/commissions.js @@ -26,21 +26,24 @@ function showSliders(maxPercentage, type, defaultValues) { beneficiaryId = $(this).val(); beneficiaryName = $(this).text(); - + var verify; + var slidersValue = defaultValues.toString().split(','); if (type === 'default') { percentage = slidersValue[sliderCounter - 1]; percentage = parseInt(percentage); - $("#panelSliders").append("" + beneficiaryName + " - [ " + percentage + " % ]
"); + $("#panelSliders").append("" + beneficiaryName + " - [ " + percentage + " % ]
"); } else if (type === 'renew') { - $("#panelSliders").append("" + beneficiaryName + " - [ " + percentage + " % ]
"); + $("#panelSliders").append("" + beneficiaryName + " - [ " + percentage + " % ]
"); } + + verifyPaypalAccountByBeneficiary(beneficiaryId); sliderCounter++; stepSlide = count - 1; @@ -127,5 +130,16 @@ function showCorrectSliderHandler() { counter++; } }); +} + +function verifyPaypalAccountByBeneficiary(userId) { + return $.ajax({ + data: 'id='+userId, + url: 'buycourses.ajax.php?a=verifyPaypal', + type: 'POST', + success: function(response) { + $("#"+userId).append(' '+response); + } + }); } diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 3c977f0264..f82cc505bf 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -1181,7 +1181,7 @@ class BuyCoursesPlugin extends Plugin "$saleTable s $innerJoins", [ 'where' => [ - 'u.id = ?' => intval($id) + 'u.id = ? AND s.status = ?' => [intval($id), BuyCoursesPlugin::SALE_STATUS_COMPLETED] ], 'order' => 'id DESC' ] @@ -1484,6 +1484,51 @@ class BuyCoursesPlugin extends Plugin return $payouts; } + /** + * Verify if the beneficiary have a paypal account + * @param int $userId + * @return true if the user have a paypal account, false if not + */ + public function verifyPaypalAccountByBeneficiary($userId) + { + $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; + } + + $paypalFieldId = $paypalExtraField['id']; + + $paypalAccount = Database::select( + "value", + $extraFieldValues, + [ + 'where' => ['field_id = ? AND item_id = ?' => [intval($paypalFieldId), intval($userId)]] + ], + 'first' + ); + + if (!$paypalAccount) { + return false; + } + + if ($paypalAccount['value'] === '') { + return false; + } + + return true; + } + /** * Register the users payouts * @param int $saleId The sale ID diff --git a/plugin/buycourses/src/buycourses.ajax.php b/plugin/buycourses/src/buycourses.ajax.php index cc7474863b..a458159975 100644 --- a/plugin/buycourses/src/buycourses.ajax.php +++ b/plugin/buycourses/src/buycourses.ajax.php @@ -20,6 +20,22 @@ $commissionsEnable = $plugin->get('commissions_enable'); $action = isset($_GET['a']) ? $_GET['a'] : null; switch ($action) { + case 'verifyPaypal': + if (api_is_anonymous()) { + break; + } + + $userId = isset($_POST['id']) ? intval($_POST['id']) : ''; + $isUserHavePaypalAccount = $plugin->verifyPaypalAccountByBeneficiary($userId); + + if ($isUserHavePaypalAccount) { + echo ''; + } else { + echo '* '.$plugin->get_lang('NoPayPalAccountDetected').''; + } + + break; + case 'saleInfo': if (api_is_anonymous()) { break; diff --git a/plugin/buycourses/src/configuration.php b/plugin/buycourses/src/configuration.php index 7a49bee247..e9f0427c2f 100644 --- a/plugin/buycourses/src/configuration.php +++ b/plugin/buycourses/src/configuration.php @@ -16,6 +16,8 @@ $includeSession = $plugin->get('include_sessions') === 'true'; api_protect_admin_script(true); +Display::addFlash(Display::return_message(get_lang('Info').' - '.$plugin->get_lang('CoursesInSessionsDoesntDisplayHere'), 'info')); + $courses = $plugin->getCoursesForConfiguration(); //view diff --git a/plugin/buycourses/src/configure_course.php b/plugin/buycourses/src/configure_course.php index 25ade61dce..6889c19307 100644 --- a/plugin/buycourses/src/configure_course.php +++ b/plugin/buycourses/src/configure_course.php @@ -223,13 +223,19 @@ if ($editingCourse) { } if ($commissionsEnable === 'true') { - + + $platformCommission = $plugin->getPlatformCommission(); + $form->addHtml( '' . '
' . '' . '
' + . Display::return_message( + sprintf($plugin->get_lang('TheActualPlatformCommissionIs'), $platformCommission['commission']. '%'), + 'info' + ) . '
' . '
' . '
' diff --git a/plugin/buycourses/src/course_catalog.php b/plugin/buycourses/src/course_catalog.php index c594d25924..f2531b54a2 100644 --- a/plugin/buycourses/src/course_catalog.php +++ b/plugin/buycourses/src/course_catalog.php @@ -55,6 +55,11 @@ if (api_is_platform_admin()) { 'url' => 'paymentsetup.php', 'name' => $plugin->get_lang('PaymentsConfiguration') ]; +} else { + $interbreadcrumb[] = [ + 'url' => 'course_panel.php', + 'name' => get_lang('TabsDashboard') + ]; } $templateName = $plugin->get_lang('CourseListOnSale'); diff --git a/plugin/buycourses/src/payout_report.php b/plugin/buycourses/src/payout_report.php index ed3465b873..28a6c144dd 100644 --- a/plugin/buycourses/src/payout_report.php +++ b/plugin/buycourses/src/payout_report.php @@ -70,6 +70,7 @@ foreach ($payouts as $payout) { 'currency' => $payout['iso_code'], 'price' => $payout['item_price'], 'commission' => $payout['commission'], + 'beneficiary' => $payout['firstname'] . ' ' . $payout['lastname'], 'paypal_account' => $payout['paypal_account'], 'status' => $payout['status'] ]; diff --git a/plugin/buycourses/view/payout_panel.tpl b/plugin/buycourses/view/payout_panel.tpl index a79b71c059..5b2b6720db 100644 --- a/plugin/buycourses/view/payout_panel.tpl +++ b/plugin/buycourses/view/payout_panel.tpl @@ -15,27 +15,34 @@ {{ 'MyPayouts'| get_plugin_lang('BuyCoursesPlugin') }} - - - - - - - - - - - - {% for payout in payout_list %} + {% if not payout_list %} +

+ {{ 'WantToSellCourses'|get_plugin_lang('BuyCoursesPlugin') }} + {{ 'ClickHere'|get_plugin_lang('BuyCoursesPlugin') }} +

+ {% endif %} + + {% if payout_list %} +
{{ 'OrderReference'| get_plugin_lang('BuyCoursesPlugin') }}{{ 'PayoutDate'| get_plugin_lang('BuyCoursesPlugin') }}{{ 'Commission'| get_plugin_lang('BuyCoursesPlugin') }}{{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }}
+ - - - - + + + + - {% endfor %} - -
{{ payout.reference }}{{ payout.payout_date }}{{ payout.currency ~ ' ' ~ payout.commission }}{{ payout.paypal_account }}{{ 'OrderReference'| get_plugin_lang('BuyCoursesPlugin') }}{{ 'PayoutDate'| get_plugin_lang('BuyCoursesPlugin') }}{{ 'Commission'| get_plugin_lang('BuyCoursesPlugin') }}{{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }}
- + + + {% for payout in payout_list %} + + {{ payout.reference }} + {{ payout.payout_date }} + {{ payout.currency ~ ' ' ~ payout.commission }} + {{ payout.paypal_account }} + + {% endfor %} + + + {% endif %} diff --git a/plugin/buycourses/view/payout_report.tpl b/plugin/buycourses/view/payout_report.tpl index 0759b5c78d..da639fb1a1 100644 --- a/plugin/buycourses/view/payout_report.tpl +++ b/plugin/buycourses/view/payout_report.tpl @@ -6,6 +6,7 @@ {{ 'OrderReference'| get_plugin_lang('BuyCoursesPlugin') }} {{ 'PayoutDate'| get_plugin_lang('BuyCoursesPlugin') }} {{ 'Commission'| get_plugin_lang('BuyCoursesPlugin') }} + {{ 'Names'| get_lang }} {{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }} @@ -15,7 +16,12 @@ {{ payout.reference }} {{ payout.payout_date }} {{ payout.currency ~ ' ' ~ payout.commission }} - {{ payout.paypal_account }} + {{ payout.beneficiary }} + {% if payout.paypal_account %} + {{ payout.paypal_account }} + {% else %} + {{ 'NoPayPalAccountDetected'| get_plugin_lang('BuyCoursesPlugin') }} + {% endif %} {% endfor %}