rog.php
150 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * Layout variables |
| 16 | * ----------------- |
| 17 | * @var VAPStatisticsWidget $widget The instance of the widget to be displayed. |
| 18 | */ |
| 19 | extract($displayData); |
| 20 | |
| 21 | JText::script('VAP_N_ORDERS'); |
| 22 | JText::script('VAP_N_ORDERS_1'); |
| 23 | |
| 24 | ?> |
| 25 | |
| 26 | <style> |
| 27 | |
| 28 | .canvas-align-center .rog { |
| 29 | text-align: center; |
| 30 | } |
| 31 | .canvas-align-center .rog .rog-earning { |
| 32 | font-size: 40px; |
| 33 | margin-bottom: 20px; |
| 34 | color: #476799; |
| 35 | font-weight: bold; |
| 36 | } |
| 37 | .canvas-align-center .rog .rog-percent { |
| 38 | font-size: 26px; |
| 39 | color: #002243; |
| 40 | font-weight: bold; |
| 41 | } |
| 42 | .canvas-align-center .rog .rog-percent > .down { |
| 43 | color: #ec4d56; |
| 44 | } |
| 45 | .canvas-align-center .rog .rog-percent > .up { |
| 46 | color: #29a449; |
| 47 | } |
| 48 | .canvas-align-center .rog .rog-percent i { |
| 49 | margin-left: 5px; |
| 50 | } |
| 51 | |
| 52 | </style> |
| 53 | |
| 54 | <div class="canvas-align-center"> |
| 55 | |
| 56 | <div class="rog"> |
| 57 | <div class="rog-earning"></div> |
| 58 | <div class="rog-percent"></div> |
| 59 | </div> |
| 60 | |
| 61 | </div> |
| 62 | |
| 63 | <div class="no-results" style="display:none;"> |
| 64 | <?php echo VAPApplication::getInstance()->alert(JText::translate('JGLOBAL_NO_MATCHING_RESULTS')); ?> |
| 65 | </div> |
| 66 | |
| 67 | <div class="widget-floating-box"> |
| 68 | |
| 69 | <span class="badge badge-info pull-left month1" style="margin-right:4px;"></span> |
| 70 | <span class="badge badge-important pull-left month2"></span> |
| 71 | |
| 72 | </div> |
| 73 | |
| 74 | <script> |
| 75 | |
| 76 | (function($) { |
| 77 | 'use strict'; |
| 78 | |
| 79 | /** |
| 80 | * Register callback to be executed after |
| 81 | * completing the update request. |
| 82 | * |
| 83 | * @param mixed widget The widget selector. |
| 84 | * @param mixed data The AJAX response. |
| 85 | * @param object config The widget configuration. |
| 86 | * |
| 87 | * @return void |
| 88 | */ |
| 89 | WIDGET_CALLBACKS[<?php echo $widget->getID(); ?>] = (widget, data, config) => { |
| 90 | if (data.nodata) { |
| 91 | // hide rog information |
| 92 | $(widget).find('.canvas-align-center').hide(); |
| 93 | // show "no results" box |
| 94 | $(widget).find('.no-results').show(); |
| 95 | } else { |
| 96 | // hide "no results" box |
| 97 | $(widget).find('.no-results').hide(); |
| 98 | // show rog information |
| 99 | $(widget).find('.canvas-align-center').show(); |
| 100 | |
| 101 | // fetch rog |
| 102 | var rog = parseFloat(data.rogPercent); |
| 103 | var rogIcon = ''; |
| 104 | var sfx = 'equals'; |
| 105 | |
| 106 | if (rog > 0) { |
| 107 | rogIcon = '<i class="fas fa-arrow-up"></i>'; |
| 108 | sfx = 'up'; |
| 109 | } else if (rog < 0) { |
| 110 | rogIcon = '<i class="fas fa-arrow-down"></i>'; |
| 111 | sfx = 'down'; |
| 112 | } |
| 113 | |
| 114 | // strip decimals in case the rog is higher than 10 or lower than -10 |
| 115 | if (Math.abs(rog) > 10) { |
| 116 | rog = Math.round(rog); |
| 117 | } |
| 118 | |
| 119 | var rogHtml = '<span class="' + sfx + '">' + rog + '%' + rogIcon + '</span>'; |
| 120 | |
| 121 | if (config.valuetype == 'total') { |
| 122 | // update total earning |
| 123 | $(widget).find('.rog-earning').text(VAPCurrency.getInstance().format(data[data.month1].total)); |
| 124 | } else { |
| 125 | var count = parseInt(data[data.month1].total); |
| 126 | var langk = 'VAP_N_ORDERS'; |
| 127 | |
| 128 | // format label by fetching singular/plural form |
| 129 | if (count == 1) { |
| 130 | count = Joomla.JText._(langk + '_1'); |
| 131 | } else { |
| 132 | count = Joomla.JText._(langk).replace(/%d/, count); |
| 133 | } |
| 134 | |
| 135 | // update total count |
| 136 | $(widget).find('.rog-earning').text(count); |
| 137 | } |
| 138 | |
| 139 | // update rog |
| 140 | $(widget).find('.rog-percent').html(rogHtml); |
| 141 | } |
| 142 | |
| 143 | // update badges |
| 144 | $(widget).find('.badge.month1').text(data[data.month1].date); |
| 145 | $(widget).find('.badge.month2').text(data[data.month2].date); |
| 146 | } |
| 147 | })(jQuery); |
| 148 | |
| 149 | </script> |
| 150 |