Browse Source

Merge pull request #952 from jloguercio/10614

Add some new info to buy courses payout feature and minor changes - Refs #10614
Yannick Warnier 9 years ago
parent
commit
65602fb5c9

+ 4 - 0
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;

+ 1 - 0
main/inc/lib/api.lib.php

@@ -8049,6 +8049,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
  *

+ 3 - 0
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['TheActualPlatformCommissionIsX'] = "La actual comisión de la plataforma es de <b> %s </b>, 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:";

+ 17 - 3
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("<span>" + beneficiaryName + "</span> - [ <span class='value' >" + percentage + "</span> % ]<div id=" + beneficiaryId + " class='panelSliders'></div>");
+            $("#panelSliders").append("<span id=" + beneficiaryId + ">" + beneficiaryName + "</span> - [ <span class='value' >" + percentage + "</span> % ] <div class='panelSliders'></div>");
 
         } else if (type === 'renew') {
 
-            $("#panelSliders").append("<span>" + beneficiaryName + "</span> - [ <span class='value' >" + percentage + "</span> % ]<div id=" + beneficiaryId + " class='panelSliders'></div>");
+            $("#panelSliders").append("<span id=" + beneficiaryId + " >" + beneficiaryName + "</span> - [ <span class='value' >" + percentage + "</span> % ] <div class='panelSliders'></div>");
             
         }
+        
+        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);
+        }
+    });
 }

+ 46 - 1
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

+ 16 - 0
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 '<b style="color: red; font-size: 70%;">* '.$plugin->get_lang('NoPayPalAccountDetected').'</b>';
+        }
+        
+        break;
+        
     case 'saleInfo':
         if (api_is_anonymous()) {
             break;

+ 2 - 0
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

+ 8 - 1
plugin/buycourses/src/configure_course.php

@@ -223,13 +223,20 @@ if ($editingCourse) {
 }
 
 if ($commissionsEnable === 'true') {
-
+    
+    $platformCommission = $plugin->getPlatformCommission();
+    
     $form->addHtml( ''
             . '<div class="form-group">'
                 . '<label for="sliders" class="col-sm-2 control-label">'
                     . get_plugin_lang('Commissions', 'BuyCoursesPlugin')
                 . '</label>'
                 . '<div class="col-sm-8">'
+                    . Display::return_message(
+                        sprintf($plugin->get_lang('TheActualPlatformCommissionIsX'), $platformCommission['commission']. '%'),
+                        'info',
+                        false
+                    )
                     . '<div class="" id="panelSliders"></div>'
                 . '</div>'
             . '</div>'

+ 5 - 0
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');

+ 1 - 0
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' => api_get_person_name($payout['firstname'], $payout['lastname']),
         'paypal_account' => $payout['paypal_account'],
         'status' => $payout['status']
     ];

+ 27 - 20
plugin/buycourses/view/payout_panel.tpl

@@ -15,27 +15,34 @@
             <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">{{ 'Commission'| get_plugin_lang('BuyCoursesPlugin') }}</th>
-                <th class="text-right">{{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }}</th>
-            </tr>
-        </thead>
-        <tbody>
-            {% for payout in payout_list %}
+    {% if not payout_list %}
+        <p class="alert alert-info">
+            {{ 'WantToSellCourses'|get_plugin_lang('BuyCoursesPlugin') }}
+            <a href="#">{{ 'ClickHere'|get_plugin_lang('BuyCoursesPlugin') }}</a>
+        </p>
+    {% endif %}
+    
+    {% if payout_list %}
+        <table class="table table-striped table-hover">
+            <thead>
                 <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.commission }}</td>
-                    <td class="text-right" style="vertical-align:middle">{{ payout.paypal_account }}</td>
+                    <th class="text-center">{{ 'OrderReference'| get_plugin_lang('BuyCoursesPlugin') }}</th>
+                    <th class="text-center">{{ 'PayoutDate'| get_plugin_lang('BuyCoursesPlugin') }}</th>
+                    <th class="text-right">{{ 'Commission'| get_plugin_lang('BuyCoursesPlugin') }}</th>
+                    <th class="text-right">{{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }}</th>
                 </tr>
-            {% endfor %}
-        </tbody>
-    </table>
-
+            </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.commission }}</td>
+                        <td class="text-right" style="vertical-align:middle">{{ payout.paypal_account }}</td>
+                    </tr>
+                {% endfor %}
+            </tbody>
+        </table>
+    {% endif %}
   
 </div>

+ 7 - 1
plugin/buycourses/view/payout_report.tpl

@@ -6,6 +6,7 @@
                 <th class="text-center">{{ 'OrderReference'| get_plugin_lang('BuyCoursesPlugin') }}</th>
                 <th class="text-center">{{ 'PayoutDate'| get_plugin_lang('BuyCoursesPlugin') }}</th>
                 <th class="text-right">{{ 'Commission'| get_plugin_lang('BuyCoursesPlugin') }}</th>
+                <th class="text-right">{{ 'Names'| get_lang }}</th>
                 <th class="text-right">{{ 'PayPalAccount'| get_plugin_lang('BuyCoursesPlugin') }}</th>
             </tr>
         </thead>
@@ -15,7 +16,12 @@
                     <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.commission }}</td>
-                    <td class="text-right" style="vertical-align:middle">{{ payout.paypal_account }}</td>
+                    <td class="text-right" style="vertical-align:middle">{{ payout.beneficiary }}</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 %}
                 </tr>
             {% endfor %}
         </tbody>