diff --git a/main/lp/lp_final_item.php b/main/lp/lp_final_item.php
index 22fd1a5a0d..7872454bdf 100644
--- a/main/lp/lp_final_item.php
+++ b/main/lp/lp_final_item.php
@@ -36,8 +36,7 @@ $plugin = BuyCoursesPlugin::create();
$checker = $plugin->isEnabled() && $plugin->get('include_services');
if ($checker) {
- $userServiceSale = $plugin->getServiceSale(
- null,
+ $userServiceSale = $plugin->getServiceSales(
$userId,
BuyCoursesPlugin::SERVICE_STATUS_COMPLETED,
BuyCoursesPlugin::SERVICE_TYPE_LP_FINAL_ITEM,
diff --git a/main/session/session_edit.php b/main/session/session_edit.php
index 9b44ac6638..4b25d316ee 100644
--- a/main/session/session_edit.php
+++ b/main/session/session_edit.php
@@ -81,8 +81,6 @@ if (api_is_multiple_url_enabled()) {
$result = Database::query($sql);
$coaches = Database::store_result($result);
-$thisYear = date('Y');
-
$coachesOption = [
'' => '----- '.get_lang('None').' -----',
];
diff --git a/plugin/buycourses/lang/english.php b/plugin/buycourses/lang/english.php
index 66145fcb14..887a11c6e0 100644
--- a/plugin/buycourses/lang/english.php
+++ b/plugin/buycourses/lang/english.php
@@ -188,3 +188,4 @@ $strings['AdditionalInfoRequired'] = 'More information needed';
$strings['SubscriptionToServiceXSuccessful'] = "Subscription to service %s completed.";
$strings['ClickHereToFinish'] = "Click here to finish";
$strings['OrderCancelled'] = "Order cancelled";
+$strings['use_currency_symbol'] = "Use currency symbol";
diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php
index 3124ed8448..006c0b44db 100644
--- a/plugin/buycourses/src/buy_course_plugin.class.php
+++ b/plugin/buycourses/src/buy_course_plugin.class.php
@@ -56,7 +56,7 @@ class BuyCoursesPlugin extends Plugin
const TAX_APPLIES_TO_ONLY_COURSE = 2;
const TAX_APPLIES_TO_ONLY_SESSION = 3;
const TAX_APPLIES_TO_ONLY_SERVICES = 4;
- const PAGINATION_PAGE_SIZE = 2;
+ const PAGINATION_PAGE_SIZE = 5;
public $isAdminPlugin = true;
@@ -89,6 +89,7 @@ class BuyCoursesPlugin extends Plugin
'hide_free_text' => 'boolean',
'invoicing_enable' => 'boolean',
'tax_enable' => 'boolean',
+ 'use_currency_symbol' => 'boolean',
]
);
}
@@ -673,8 +674,7 @@ class BuyCoursesPlugin extends Plugin
'title' => $course->getTitle(),
'code' => $course->getCode(),
'course_img' => null,
- 'price' => $item['total_price'],
- 'currency' => $item['iso_code'],
+ 'item' => $item,
'teachers' => [],
'enrolled' => $this->getUserStatusForCourse(api_get_user_id(), $course),
];
@@ -698,6 +698,31 @@ class BuyCoursesPlugin extends Plugin
return $courseCatalog;
}
+ /**
+ * @param $price
+ * @param $isoCode
+ *
+ * @return string
+ */
+ public function getPriceWithCurrencyFromIsoCode($price, $isoCode)
+ {
+ $useSymbol = $this->get('use_currency_symbol') === 'true';
+
+ $result = $isoCode.' '.$price;
+ if ($useSymbol) {
+ if ($isoCode === 'BRL') {
+ $symbol = 'R$';
+ } else {
+ $symbol = Symfony\Component\Intl\Intl::getCurrencyBundle()->getCurrencySymbol($isoCode);
+ }
+ $result = $symbol.' '.$price;
+ }
+
+ return $result;
+ }
+
+
+
/**
* Get course info.
*
@@ -742,13 +767,9 @@ class BuyCoursesPlugin extends Plugin
'code' => $course->getCode(),
'visual_code' => $course->getVisualCode(),
'teachers' => [],
- 'price' => $item['total_price_formatted'],
- 'price_without_tax' => $item['price_formatted'],
- 'tax_amount' => $item['tax_amount_formatted'],
- 'tax_perc' => $item['tax_perc_show'],
+ 'item' => $item,
'tax_name' => $globalParameters['tax_name'],
'tax_enable' => $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_COURSE),
- 'currency' => $item['iso_code'],
'course_img' => null,
];
@@ -815,16 +836,12 @@ class BuyCoursesPlugin extends Plugin
'description' => $session->getDescription(),
'dates' => $sessionDates,
'courses' => [],
- 'price' => $item['total_price_formatted'],
- 'price_without_tax' => $item['price_formatted'],
- 'tax_amount' => $item['tax_amount_formatted'],
- 'tax_perc' => $item['tax_perc_show'],
'tax_name' => $globalParameters['tax_name'],
'tax_enable' => $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_SESSION),
- 'currency' => $item['iso_code'],
'image' => null,
'nbrCourses' => $session->getNbrCourses(),
'nbrUsers' => $session->getNbrUsers(),
+ 'item' => $item
];
$fieldValue = new ExtraFieldValue('session');
@@ -888,6 +905,7 @@ class BuyCoursesPlugin extends Plugin
return false;
}
+ $productName = '';
if ($item['product_type'] == self::PRODUCT_TYPE_COURSE) {
$course = $entityManager->find('ChamiloCoreBundle:Course', $item['product_id']);
@@ -1014,31 +1032,15 @@ class BuyCoursesPlugin extends Plugin
*/
public function getDataSaleInvoice($saleId, $isService)
{
- $sale = [];
if ($isService) {
$sale = $this->getServiceSale($saleId);
$sale['reference'] = $sale['reference'];
$sale['product_name'] = $sale['service']['name'];
$sale['payment_type'] = $sale['payment_type'];
$sale['user_id'] = $sale['buyer']['id'];
- // $data['price'] = $sale['price'];
- //$data['price_without_tax'] = $sale['price_without_tax'];
- //$data['tax_perc'] = $sale['tax_perc'];
- //$data['tax_amount'] = $sale['tax_amount'];
- //$data['currency_id'] = $sale['currency_id'];
$sale['date'] = $sale['buy_date'];
} else {
$sale = $this->getSale($saleId);
- //$data['reference'] = $sale['reference'];
- //$data['product_name'] = $sale['product_name'];
- //$data['payment_type'] = $sale['payment_type'];
- //$data['user_id'] = $sale['user_id'];
- //$data['price'] = $sale['price'];
- //$data['price_without_tax'] = $sale['price_without_tax'];
- //$data['tax_perc'] = $sale['tax_perc'];
- //$data['tax_amount'] = $sale['tax_amount'];
- //$data['currency_id'] = $sale['currency_id'];
- //$data['date'] = $sale['date'];
}
return $sale;
@@ -1073,7 +1075,7 @@ class BuyCoursesPlugin extends Plugin
* @param int $saleId The sale id
* @param int $isService Check if a service
*
- * @return array The invoice numbers
+ * @return string
*/
public function getNumInvoice($saleId, $isService)
{
@@ -1380,7 +1382,7 @@ class BuyCoursesPlugin extends Plugin
public function generateReference($userId, $productType, $productId)
{
return vsprintf(
- "%d-%d-%d-%s",
+ '%d-%d-%d-%s',
[$userId, $productType, $productId, self::randomText()]
);
}
@@ -1792,7 +1794,7 @@ class BuyCoursesPlugin extends Plugin
$extraFieldValues = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$paypalExtraField = Database::select(
- "*",
+ '*',
$extraFieldTable,
[
'where' => ['variable = ?' => 'paypal'],
@@ -1806,7 +1808,7 @@ class BuyCoursesPlugin extends Plugin
$paypalFieldId = $paypalExtraField['id'];
$paypalAccount = Database::select(
- "value",
+ 'value',
$extraFieldValues,
[
'where' => ['field_id = ? AND item_id = ?' => [(int) $paypalFieldId, (int) $userId]],
@@ -2038,18 +2040,33 @@ class BuyCoursesPlugin extends Plugin
$product['tax_amount'] = 0;
$precision = 2;
if ($this->checkTaxEnabledInProduct($productType)) {
- $globalParameters = $this->getGlobalParameters();
- $globalTaxPerc = $globalParameters['global_tax_perc'];
- $taxPerc = is_null($product['tax_perc']) ? $globalTaxPerc : $product['tax_perc'];
+ if (is_null($product['tax_perc'])) {
+ $globalParameters = $this->getGlobalParameters();
+ $globalTaxPerc = $globalParameters['global_tax_perc'];
+ $taxPerc = $globalTaxPerc;
+ } else {
+ $taxPerc = $product['tax_perc'];
+ }
+ //$taxPerc = is_null($product['tax_perc']) ? $globalTaxPerc : $product['tax_perc'];
+
$taxAmount = round($priceWithoutTax * $taxPerc / 100, $precision);
$product['tax_amount'] = $taxAmount;
$priceWithTax = $priceWithoutTax + $taxAmount;
$product['total_price'] = $priceWithTax;
}
+
$product['tax_perc_show'] = $taxPerc;
- $product['total_price_formatted'] = number_format($product['total_price'], $precision);
- $product['price_formatted'] = number_format($product['price'], $precision);
+ $product['price_formatted'] = $this->getPriceWithCurrencyFromIsoCode(
+ number_format($product['price'], $precision),
+ $product['iso_code']
+ );
+
$product['tax_amount_formatted'] = number_format($product['tax_amount'], $precision);
+
+ $product['total_price_formatted'] = $this->getPriceWithCurrencyFromIsoCode(
+ number_format($product['total_price'], $precision),
+ $product['iso_code']
+ );
}
/**
@@ -2079,12 +2096,11 @@ class BuyCoursesPlugin extends Plugin
$showData
);
+ $service['iso_code'] = $isoCode;
$globalParameters = $this->getGlobalParameters();
$this->setPriceSettings($service, self::TAX_APPLIES_TO_ONLY_SERVICES);
- $service['price_with_tax'] = $service['total_price_formatted'];
- $service['price_without_tax'] = $service['price_formatted'];
$service['tax_name'] = $globalParameters['tax_name'];
$service['tax_enable'] = $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_SERVICES);
$service['owner_name'] = api_get_person_name($service['firstname'], $service['lastname']);
@@ -2144,55 +2160,44 @@ class BuyCoursesPlugin extends Plugin
/**
* List services sales.
*
- * @param int $id service id
* @param int $buyerId buyer id
* @param int $status status
* @param int $nodeType The node Type ( User = 1 , Course = 2 , Session = 3 )
* @param int $nodeId the nodeId
- * @param bool $hot enable hot services
*
* @return array
*/
- public function getServiceSale(
- $id = 0,
+ public function getServiceSales(
$buyerId = 0,
$status = 0,
$nodeType = 0,
- $nodeId = 0,
- $hot = false
+ $nodeId = 0
) {
- $servicesTable = Database::get_main_table(self::TABLE_SERVICES);
- $servicesSaleTable = Database::get_main_table(self::TABLE_SERVICES_SALE);
-
$conditions = null;
- $showData = 'all';
$groupBy = '';
- $id = (int) $id;
$buyerId = (int) $buyerId;
$status = (int) $status;
$nodeType = (int) $nodeType;
$nodeId = (int) $nodeId;
- if (!empty($id)) {
- $conditions = ['WHERE' => ['ss.id = ?' => $id]];
- $showData = 'first';
- }
+ $defaultOrder = 'ss.id ASC';
if (!empty($buyerId)) {
- $conditions = ['WHERE' => ['ss.buyer_id = ?' => $buyerId], 'ORDER' => 'id ASC'];
+ $conditions = ['WHERE' => ['ss.buyer_id = ?' => $buyerId], 'ORDER' => $defaultOrder];
}
- if (is_numeric($status) && empty($id)) {
- $conditions = ['WHERE' => ['ss.status = ?' => $status], 'ORDER' => 'id ASC'];
+ if (is_numeric($status)) {
+ $conditions = ['WHERE' => ['ss.status = ?' => $status], 'ORDER' => $defaultOrder];
}
- if ($id && $buyerId) {
- $conditions = ['WHERE' => ['ss.id = ? AND ss.buyer_id = ?' => [$id, $buyerId]], 'ORDER' => 'id ASC'];
+ if ($buyerId) {
+ $conditions = ['WHERE' => ['ss.buyer_id = ?' => [$buyerId]], 'ORDER' => $defaultOrder];
}
if ($nodeType && $nodeId) {
$conditions = [
- 'WHERE' => ['ss.node_type = ? AND ss.node_id = ?' => [$nodeType, $nodeId]], 'ORDER' => 'id ASC',
+ 'WHERE' => ['ss.node_type = ? AND ss.node_id = ?' => [$nodeType, $nodeId]],
+ 'ORDER' => $defaultOrder,
];
}
@@ -2206,101 +2211,79 @@ class BuyCoursesPlugin extends Plugin
$status,
],
],
- 'ORDER' => 'id ASC',
+ 'ORDER' => 'ss.service_id ASC',
];
}
- if ($hot) {
- $hot = 'count(ss.service_id) as hot, ';
- $conditions = ['ORDER' => 'hot DESC', 'LIMIT' => '6'];
- $groupBy = 'GROUP BY ss.service_id';
- 'clean_teacher_files.php';
- }
+ $servicesTable = Database::get_main_table(self::TABLE_SERVICES);
+ $servicesSaleTable = Database::get_main_table(self::TABLE_SERVICES_SALE);
$innerJoins = "INNER JOIN $servicesTable s ON ss.service_id = s.id $groupBy";
- $currency = $this->getSelectedCurrency();
- $isoCode = $currency['iso_code'];
$return = Database::select(
- "ss.*, s.name, s.description, s.price as service_price, s.duration_days, s.applies_to, s.owner_id, s.visibility, s.image, $hot '$isoCode' as currency",
+ 'DISTINCT ss.id ',
"$servicesSaleTable ss $innerJoins",
- $conditions,
- $showData
+ $conditions
+ //, "all", null, true
);
- $servicesSale = [];
-
- if ($id) {
- $owner = api_get_user_info($return['owner_id']);
- $buyer = api_get_user_info($return['buyer_id']);
-
- $servicesSale['id'] = $return['id'];
- $servicesSale['service']['id'] = $return['service_id'];
- $servicesSale['service']['name'] = $return['name'];
- $servicesSale['service']['description'] = $return['description'];
- $servicesSale['service']['price'] = $return['service_price'];
- $servicesSale['service']['currency'] = $return['currency'];
- $servicesSale['service']['duration_days'] = $return['duration_days'];
- $servicesSale['service']['applies_to'] = $return['applies_to'];
- $servicesSale['service']['owner']['id'] = $return['owner_id'];
- $servicesSale['service']['owner']['name'] = api_get_person_name($owner['firstname'], $owner['lastname']);
- $servicesSale['service']['visibility'] = $return['visibility'];
- $servicesSale['service']['image'] = $return['image'];
- $servicesSale['reference'] = $return['reference'];
- $servicesSale['currency_id'] = $return['currency_id'];
- $servicesSale['currency'] = $return['currency'];
- $servicesSale['price'] = $return['price'];
- $servicesSale['price_without_tax'] = $return['price_without_tax'];
- $servicesSale['tax_perc'] = $return['tax_perc'];
- $servicesSale['tax_amount'] = $return['tax_amount'];
- $servicesSale['node_type'] = $return['node_type'];
- $servicesSale['node_id'] = $return['node_id'];
- $servicesSale['buyer']['id'] = $buyer['user_id'];
- $servicesSale['buyer']['name'] = api_get_person_name($buyer['firstname'], $buyer['lastname']);
- $servicesSale['buyer']['username'] = $buyer['username'];
- $servicesSale['buy_date'] = $return['buy_date'];
- $servicesSale['date_start'] = $return['date_start'];
- $servicesSale['date_end'] = $return['date_end'];
- $servicesSale['status'] = $return['status'];
- $servicesSale['payment_type'] = $return['payment_type'];
- $servicesSale['invoice'] = $return['invoice'];
-
- return $servicesSale;
+
+ $list = [];
+ foreach ($return as $service) {
+ $list[] = $this->getServiceSale($service['id']);
}
- foreach ($return as $index => $service) {
- $owner = api_get_user_info($service['owner_id']);
- $buyer = api_get_user_info($service['buyer_id']);
-
- $servicesSale[$index]['id'] = $service['id'];
- $servicesSale[$index]['service']['id'] = $service['service_id'];
- $servicesSale[$index]['service']['name'] = $service['name'];
- $servicesSale[$index]['service']['description'] = $service['description'];
- $servicesSale[$index]['service']['price'] = $service['service_price'];
- $servicesSale[$index]['service']['duration_days'] = $service['duration_days'];
- $servicesSale[$index]['service']['applies_to'] = $service['applies_to'];
- $servicesSale[$index]['service']['owner']['id'] = $service['owner_id'];
- $servicesSale[$index]['service']['owner']['name'] = api_get_person_name(
- $owner['firstname'],
- $owner['lastname']
- );
- $servicesSale[$index]['service']['visibility'] = $service['visibility'];
- $servicesSale[$index]['service']['image'] = $service['image'];
- $servicesSale[$index]['reference'] = $service['reference'];
- $servicesSale[$index]['currency_id'] = $service['currency_id'];
- $servicesSale[$index]['currency'] = $service['currency'];
- $servicesSale[$index]['price'] = $service['price'];
- $servicesSale[$index]['node_type'] = $service['node_type'];
- $servicesSale[$index]['node_id'] = $service['node_id'];
- $servicesSale[$index]['buyer']['id'] = $service['buyer_id'];
- $servicesSale[$index]['buyer']['name'] = api_get_person_name($buyer['firstname'], $buyer['lastname']);
- $servicesSale[$index]['buyer']['username'] = $buyer['username'];
- $servicesSale[$index]['buy_date'] = $service['buy_date'];
- $servicesSale[$index]['date_start'] = $service['date_start'];
- $servicesSale[$index]['date_end'] = $service['date_end'];
- $servicesSale[$index]['status'] = $service['status'];
- $servicesSale[$index]['payment_type'] = $service['payment_type'];
- $servicesSale[$index]['invoice'] = $service['invoice'];
+ return $list;
+ }
+
+ /**
+ * @param int $id service sale id
+ *
+ * @return array
+ */
+ public function getServiceSale($id)
+ {
+ $servicesTable = Database::get_main_table(self::TABLE_SERVICES);
+ $servicesSaleTable = Database::get_main_table(self::TABLE_SERVICES_SALE);
+
+ if (empty($id)) {
+ return [];
}
+ $conditions = ['WHERE' => ['ss.id = ?' => $id]];
+ $innerJoins = "INNER JOIN $servicesTable s ON ss.service_id = s.id ";
+ $currency = $this->getSelectedCurrency();
+ $isoCode = $currency['iso_code'];
+
+ $servicesSale = Database::select(
+ 'ss.*, s.name, s.description, s.price as service_price, s.duration_days, s.applies_to, s.owner_id, s.visibility, s.image',
+ "$servicesSaleTable ss $innerJoins",
+ $conditions,
+ 'first'
+ );
+ $owner = api_get_user_info($servicesSale['owner_id']);
+ $buyer = api_get_user_info($servicesSale['buyer_id']);
+
+ $servicesSale['service']['id'] = $servicesSale['service_id'];
+ $servicesSale['service']['name'] = $servicesSale['name'];
+ $servicesSale['service']['description'] = $servicesSale['description'];
+ $servicesSale['service']['price'] = $servicesSale['service_price'];
+ $servicesSale['service']['currency'] = $isoCode;
+
+ $servicesSale['service']['total_price'] = $this->getPriceWithCurrencyFromIsoCode(
+ $servicesSale['price'],
+ $isoCode
+ );
+
+ $servicesSale['service']['duration_days'] = $servicesSale['duration_days'];
+ $servicesSale['service']['applies_to'] = $servicesSale['applies_to'];
+ $servicesSale['service']['owner']['id'] = $servicesSale['owner_id'];
+ $servicesSale['service']['owner']['name'] = api_get_person_name($owner['firstname'], $owner['lastname']);
+ $servicesSale['service']['visibility'] = $servicesSale['visibility'];
+ $servicesSale['service']['image'] = $servicesSale['image'];
+ $servicesSale['item'] = $this->getService($servicesSale['service_id']);
+ $servicesSale['buyer']['id'] = $buyer['user_id'];
+ $servicesSale['buyer']['name'] = api_get_person_name($buyer['firstname'], $buyer['lastname']);
+ $servicesSale['buyer']['username'] = $buyer['username'];
+
return $servicesSale;
}
@@ -2411,11 +2394,10 @@ class BuyCoursesPlugin extends Plugin
* @param int $serviceId The service ID
* @param int $paymentType The payment type
* @param int $infoSelect The ID for Service Type
- * @param int $trial trial mode
*
* @return bool
*/
- public function registerServiceSale($serviceId, $paymentType, $infoSelect, $trial = null)
+ public function registerServiceSale($serviceId, $paymentType, $infoSelect)
{
if (!in_array(
$paymentType,
@@ -2436,10 +2418,11 @@ class BuyCoursesPlugin extends Plugin
$price = $service['price'];
$priceWithoutTax = null;
$taxPerc = null;
-
$taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
+ $taxAmount = 0;
+
if ($taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SERVICES)
) {
diff --git a/plugin/buycourses/src/buycourses.ajax.php b/plugin/buycourses/src/buycourses.ajax.php
index 7045151b7d..1cb8de59f5 100644
--- a/plugin/buycourses/src/buycourses.ajax.php
+++ b/plugin/buycourses/src/buycourses.ajax.php
@@ -31,15 +31,13 @@ switch ($action) {
break;
}
- $userId = isset($_POST['id']) ? intval($_POST['id']) : '';
+ $userId = isset($_POST['id']) ? (int) $_POST['id'] : '';
$isUserHavePaypalAccount = $plugin->verifyPaypalAccountByBeneficiary($userId);
-
if ($isUserHavePaypalAccount) {
echo '';
} else {
echo '* '.$plugin->get_lang('NoPayPalAccountDetected').'';
}
-
break;
case 'saleInfo':
if (api_is_anonymous()) {
@@ -249,9 +247,7 @@ switch ($action) {
false
);
}
-
break;
-
case 'cancelPayout':
if (api_is_anonymous()) {
break;
@@ -278,16 +274,14 @@ switch ($action) {
if (!$tokenId || !$saleId) {
break;
}
-
$sale = $plugin->getSale($saleId);
-
if (!$sale) {
break;
}
- require_once "Requests.php";
+ require_once 'Requests.php';
Requests::register_autoloader();
- require_once "culqi.php";
+ require_once 'culqi.php';
$culqiParams = $plugin->getCulqiParams();
@@ -374,10 +368,9 @@ switch ($action) {
break;
}
- require_once "Requests.php";
+ require_once 'Requests.php';
Requests::register_autoloader();
- require_once "culqi.php";
-
+ require_once 'culqi.php';
$culqiParams = $plugin->getCulqiParams();
// API Key y autenticación
@@ -451,7 +444,7 @@ switch ($action) {
}
break;
case 'service_sale_info':
- $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
+ $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
$serviceSale = $plugin->getServiceSale($id);
$isAdmin = api_is_platform_admin();
if (!$serviceSale) {
@@ -464,7 +457,6 @@ switch ($action) {
$html .= "
";
$html .= "";
$html .= "