Browse Source

Improve Service sale reports

José Loguercio 8 years ago
parent
commit
c8c6755c6e

+ 5 - 0
plugin/buycourses/lang/spanish.php

@@ -158,3 +158,8 @@ $strings['GlobalConfig'] = "Configuración global:";
 $strings['WriteHereTheTermsAndConditionsOfYourECommerce'] = "Escriba aquí los terminos y condiciones para su tienda virtual";
 $strings['PleaseSelectThePaymentMethodBeforeConfirmYourOrder'] = "Porfavor seleccione el método de pago de su preferencia antes de confirmar su orden";
 $strings['MyServices'] = "Mis servicios";
+$strings['ServiceId'] = "Id de servicio";
+$strings['BoughtBy'] = "Comprado por";
+$strings['PurchaserUser'] = "Usuario comprador";
+$strings['SalePrice'] = "Precio de venta";
+$strings['Pending'] = "Pendiente";

File diff suppressed because it is too large
+ 0 - 0
plugin/buycourses/resources/js/modals.js


+ 23 - 0
plugin/buycourses/src/buy_course_plugin.class.php

@@ -2222,4 +2222,27 @@ class BuyCoursesPlugin extends Plugin
         );
     }
 
+    /**
+     * Get the path
+     * @param string $var path variable
+     * @return string path
+     */
+    public function getPath($var)
+    {
+        $pluginPath = api_get_path(WEB_PLUGIN_PATH) . 'buycourses/';
+        $paths = [
+            'SERVICE_IMAGES' => $pluginPath . 'uploads/services/images/',
+            'SRC' => $pluginPath . 'src/',
+            'VIEW' => $pluginPath . 'view/',
+            'UPLOADS' => $pluginPath . 'uploads/',
+            'LANGUAGES' => $pluginPath . 'lang/',
+            'RESOURCES' => $pluginPath . 'resources/',
+            'RESOURCES_IMG' => $pluginPath . 'resources/img/',
+            'RESOURCES_CSS' => $pluginPath . 'resources/css/',
+            'RESOURCES_JS' => $pluginPath . 'resources/js/',
+        ];
+
+        return $paths[$var];
+    }
+
 }

+ 159 - 0
plugin/buycourses/src/buycourses.ajax.php

@@ -438,5 +438,164 @@ switch ($action) {
             }
         }
 
+        break;
+
+    case 'service_sale_info':
+
+        $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
+        $serviceSale = $plugin->getServiceSale($id);
+
+        $isAdmin = api_is_platform_admin();
+
+        if (!$serviceSale) {
+            break;
+        }
+
+        $ajaxCallFile = $plugin->getPath('SRC') . 'buycourses.ajax.php';
+
+        $serviceImg = $plugin->getPath('SERVICE_IMAGES') . $serviceSale['service']['image'];
+        $html = "<img class='img-responsive text-center' src='$serviceImg'>";
+        $html .= "<br />";
+        $html .= "<legend>{$plugin->get_lang('ServiceInformation')}</legend>";
+        $html .= "<ul>";
+        $html .= "<li><b>{$plugin->get_lang('ServiceId')}:</b> {$serviceSale['id']}</li> ";
+        $html .= "<li><b>{$plugin->get_lang('ServiceName')}:</b> {$serviceSale['service']['name']}</li> ";
+        $html .= "<li><b>{$plugin->get_lang('Description')}:</b> {$serviceSale['service']['description']}</li> ";
+        $nodeType = $serviceSale['node_type'];
+        $nodeName = "";
+        $nodeTitle = "";
+        if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_USER) {
+            $nodeType = get_lang('User');
+        } else if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_COURSE) {
+            $nodeType = get_lang('Course');
+        } else if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_SESSION) {
+            $nodeType = get_lang('Session');
+        }
+        $html .= "<li><b>{$plugin->get_lang('AppliesTo')}:</b> $nodeType</li> ";
+        $html .= "<li><b>{$plugin->get_lang('Price')}:</b> {$serviceSale['service']['price']} {$serviceSale['currency']}</li> ";
+        $duration = $serviceSale['service']['duration_days'] . ' ' . $plugin->get_lang('Days');
+        $html .= "</ul>";
+        $html .= "<legend>{$plugin->get_lang('SaleInfo')}</legend>";
+        $html .= "<ul>";
+        $html .= "<li><b>{$plugin->get_lang('BoughtBy')}:</b> {$serviceSale['buyer']['name']}</li> ";
+        $html .= "<li><b>{$plugin->get_lang('PurchaserUser')}:</b> {$serviceSale['buyer']['username']}</li> ";
+        $html .= "<li><b>{$plugin->get_lang('SalePrice')}:</b> {$serviceSale['price']} {$serviceSale['currency']}</li> ";
+        $orderDate = api_format_date($serviceSale['buy_date'], DATE_FORMAT_LONG);
+        $html .= "<li><b>{$plugin->get_lang('OrderDate')}:</b> $orderDate</li> ";
+        $paymentType = $serviceSale['payment_type'];
+        if ($paymentType == BuyCoursesPlugin::PAYMENT_TYPE_PAYPAL) {
+            $paymentType = 'PayPal';
+        } else if ($paymentType == BuyCoursesPlugin::PAYMENT_TYPE_TRANSFER) {
+            $paymentType = $plugin->get_lang('BankTransfer');
+        } else if ($paymentType == BuyCoursesPlugin::PAYMENT_TYPE_CULQI) {
+            $paymentType = 'Culqi';
+        }
+        $html .= "<li><b>{$plugin->get_lang('PaymentMethod')}:</b> $paymentType</li> ";
+        $html .= "<li><b>$nodeType:</b> $nodeName</li> ";
+        $status = $serviceSale['status'];
+        $buttons = "";
+        if ($status == BuyCoursesPlugin::SERVICE_STATUS_COMPLETED) {
+            $status = $plugin->get_lang('Active');
+        } else if ($status == BuyCoursesPlugin::SERVICE_STATUS_PENDING) {
+            $status = $plugin->get_lang('Pending');
+            if ($isAdmin) {
+                $buttons .= "<a id='{$serviceSale['id']}' tag='service_sale_confirm' class='btn btn-success pull-left'>{$plugin->get_lang('ConfirmOrder')}</a>";
+                $buttons .= "<a id='{$serviceSale['id']}' tag='service_sale_cancel' class='btn btn-danger pull-right'>{$plugin->get_lang('CancelOrder')}</a>";
+            }
+        } else if ($status == BuyCoursesPlugin::SERVICE_STATUS_CANCELLED) {
+            $status = $plugin->get_lang('Cancelled');
+        }
+        $html .= "<li><b>{$plugin->get_lang('Status')}:</b> $status</li> ";
+        $html .= "</ul>";
+        $html .= "<br />";
+        $html .= "<div class='row'>";
+        $html .= "<div class='col-md-2'></div>";
+        $html .= "<div class='col-md-8 text-center'>";
+        $html .= "<div class='bc-action-buttons'>";
+        $html .= $buttons;
+        $html .= "</div>";
+        $html .= "</div>";
+        $html .= "<div class='col-md-2'></div>";
+        $html .= "<script>";
+        $html .= "$('.bc-action-buttons a').click(function() {";
+        $html .= "var id = $(this).attr('id');";
+        $html .= "var action = $(this).attr('tag');";
+        $html .= "$.ajax({";
+        $html .= "data: 'id='+id,";
+        $html .= "url: '$ajaxCallFile?a='+action,";
+        $html .= "type: 'POST',";
+        $html .= "beforeSend: function() {";
+        $processingLoaderText = $plugin->get_lang('ProcessingDontCloseThisWindow');
+        $html .= "$('.bootbox-close-button').remove();";
+        $html .= "$('.btn-default').attr('disabled', true);";
+        $html .= "$('.bc-action-buttons').html('<div class=\"wobblebar-loader\"></div><p> $processingLoaderText</p>');";
+        $html .= "},";
+        $html .= "success: function(response) {";
+        $html .= "$('.bc-action-buttons').html(response);";
+        $html .= "},";
+        $html .= "});";
+        $html .= "});";
+        $html .= "</script>";
+
+        echo $html;
+
+        break;
+    case 'service_sale_confirm':
+
+        $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
+
+        $serviceSale = $plugin->getServiceSale($id);
+        $response = $plugin->completeServiceSale($id);
+        $html = "";
+        $html .= "<div class='text-center'>";
+
+        if ($response) {
+            $html .= Display::return_message(
+                sprintf($plugin->get_lang('SubscriptionToServiceXSuccessful'), $serviceSale['service']['name']),
+                'success'
+            );
+        } else {
+            $html .= Display::return_message('Error - ' . $plugin->get_lang('ErrorContactPlatformAdmin'), 'error');
+        }
+
+        $html .= "<a id='finish-button' class='btn btn-primary'>" . $plugin->get_lang('ClickHereToFinish') . "</a>";
+        $html .= "</div>";
+        $html .= "<script>";
+        $html .= "$('#finish-button').click(function() {";
+        $html .= "location.reload();";
+        $html .= "});";
+        $html .= "</script>";
+
+        echo $html;
+
+        break;
+    case 'service_sale_cancel':
+
+        $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
+
+        $serviceSale = $plugin->getServiceSale($id);
+        $response = $plugin->cancelServiceSale($id);
+        $html = "";
+        $html .= "<div class='text-center'>";
+
+        if ($response) {
+            $html .= Display::return_message(
+                $plugin->get_lang('OrderCancelled'),
+                'warning'
+            );
+        } else {
+            $html .= Display::return_message('Error - ' . $plugin->get_lang('ErrorContactPlatformAdmin'), 'error');
+        }
+
+        $html .= "<a id='finish-button' class='btn btn-primary'>" . $plugin->get_lang('ClickHereToFinish') . "</a>";
+        $html .= "</div>";
+        $html .= "<script>";
+        $html .= "$('#finish-button').click(function() {";
+        $html .= "location.reload();";
+        $html .= "});";
+        $html .= "</script>";
+
+        echo $html;
+
         break;
 }

+ 2 - 7
plugin/buycourses/view/service_panel.tpl

@@ -62,19 +62,14 @@
                 url: '{{ _p.web_plugin }}buycourses/src/buycourses.ajax.php?a='+action,
                 type: 'POST',
                 beforeSend: function() {
-                    if (action == 'renewable_info') {
-                        $('a[name=r_'+id+']').html('<em class="fa fa-spinner fa-pulse"></em> {{ 'Loading' | get_lang }}');
-                    } else if (action == 'service_sale_info') {
+                    if (action == 'service_sale_info') {
                         $('a[name=s_'+id+']').html('<em class="fa fa-spinner fa-pulse"></em> {{ 'Loading' | get_lang }}');
                     }
                 },
                 success: function(response) {
-                    $('a[name=r_'+id+']').html('{{ 'Info' | get_lang }}');
                     $('a[name=s_'+id+']').html('{{ 'Info' | get_lang }}');
                     var title = "";
-                    if (action == "renewable_info") {
-                        title = "{{ 'RecurringPaymentProfilePaypalInformation' | get_plugin_lang('BuyCoursesPlugin') }}";
-                    } else if (action == 'service_sale_info') {
+                    if (action == 'service_sale_info') {
                         title = "{{ 'ServiceSaleInfo' | get_plugin_lang('BuyCoursesPlugin') }}";
                     }
                     bootbox.dialog({

Some files were not shown because too many files changed in this diff