WIP: Fix buy courses plugin when working with taxes see BT#16054

pull/2999/head
Julio Montoya 6 years ago
parent 55c21d1e6b
commit 4174a77c39
  1. 4
      main/inc/lib/sessionmanager.lib.php
  2. 40
      main/template/default/session/about.tpl
  3. 3
      main/template/default/session/resume_session.tpl
  4. 6
      main/template/default/session/sessions_current.tpl
  5. 6
      plugin/buycourses/lang/english.php
  6. 404
      plugin/buycourses/src/buy_course_plugin.class.php
  7. 38
      plugin/buycourses/src/buycourses.ajax.php
  8. 61
      plugin/buycourses/src/configure_course.php
  9. 3
      plugin/buycourses/src/invoice.php
  10. 6
      plugin/buycourses/src/process.php
  11. 2
      plugin/buycourses/src/service_information.php
  12. 102
      plugin/buycourses/src/service_process.php
  13. 18
      plugin/buycourses/src/service_process_confirm.php
  14. 6
      plugin/buycourses/src/service_sales_report.php
  15. 5
      plugin/buycourses/src/services_edit.php
  16. 5
      plugin/buycourses/view/catalog.tpl
  17. 7
      plugin/buycourses/view/configuration.tpl
  18. 22
      plugin/buycourses/view/process_confirm.tpl

@ -3374,9 +3374,9 @@ class SessionManager
}
return $sessions;
} else {
return false;
}
return false;
}
/**

@ -136,7 +136,6 @@
<img src="{{ course_data.image }}" class="img-rounded img-responsive" width="100%">
</div>
{% endif %}
</div>
<div class="col-sm-7">
{% if courses|length > 1 %}
@ -153,7 +152,6 @@
</div>
{% if course_data.tags %}
<div class="panel-tags">
<ul class="list-inline course-tags">
<li>{{ 'Tags'|get_lang }} :</li>
{% for tag in course_data.tags %}
@ -176,20 +174,21 @@
{% if course_data.objectives %}
{% for objectives in course_data.objectives %}
<div class="topics">
<h4 class="title-info"><em
class="fa fa-book"></em> {{ objectives.title }}</h4>
<h4 class="title-info">
<em class="fa fa-book"></em> {{ objectives.title }}
</h4>
<div class="content-info">
{{ objectives.content }}
</div>
</div>
{% endfor %}
{% endif %}
{% if course_data.topics %}
{% for topics in course_data.topics %}
<div class="topics">
<h4 class="title-info"><em
class="fa fa-book"></em> {{ topics.title }}</h4>
<h4 class="title-info">
<em class="fa fa-book"></em> {{ topics.title }}
</h4>
<div class="content-info">
{{ topics.content }}
</div>
@ -200,8 +199,10 @@
{% if course_data.methodology %}
{% for methodology in course_data.methodology %}
<div class="topics">
<h4 class="title-info"><em
class="fa fa-book"></em> {{ methodology.title }}</h4>
<h4 class="title-info">
<em class="fa fa-book"></em>
{{ methodology.title }}
</h4>
<div class="content-info">
{{ methodology.content }}
</div>
@ -224,8 +225,10 @@
{% if course_data.resources %}
{% for resources in course_data.resources %}
<div class="topics">
<h4 class="title-info"><em
class="fa fa-book"></em> {{ resources.title }}</h4>
<h4 class="title-info">
<em class="fa fa-book"></em>
{{ resources.title }}
</h4>
<div class="content-info">
{{ resources.content }}
</div>
@ -236,8 +239,9 @@
{% if course_data.assessment %}
{% for assessment in course_data.assessment %}
<div class="topics">
<h4 class="title-info"><em
class="fa fa-book"></em> {{ assessment.title }}</h4>
<h4 class="title-info">
<em class="fa fa-book"></em> {{ assessment.title }}
</h4>
<div class="content-info">
{{ assessment.content }}
</div>
@ -248,7 +252,8 @@
{% if course_data.custom %}
{% for custom in course_data.custom %}
<div class="topics">
<h4 class="title-info"><em class="fa fa-book"></em> {{ custom.title }}
<h4 class="title-info">
<em class="fa fa-book"></em> {{ custom.title }}
</h4>
<div class="content-info">
{{ custom.content }}
@ -259,12 +264,10 @@
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-body">
{% if course_data.coaches %}
<div class="panel-teachers">
<h3 class="sub-title">{{ "Coaches"|get_lang }}</h3>
@ -301,7 +304,6 @@
{% endfor %}
</div>
{% endif %}
</div>
</div>
</div>
@ -311,8 +313,8 @@
</div>
</section>
<script type="text/javascript">
$(document).ready(function () {
<script>
$(function () {
$('.course-information').readmore({
speed: 100,
lessLink: '<a class="hide-content" href="#">{{ 'SetInvisible' | get_lang }}</a>',

@ -20,7 +20,6 @@
<td>{{ session_category }}</td>
</tr>
{% endif %}
{% if session.duration > 0 %}
<tr>
<td>{{ 'Duration' | get_lang}} </td>
@ -42,7 +41,6 @@
<td>{{ session_dates.coach }}</td>
</tr>
{% endif %}
<tr>
<td>{{ 'Description' | get_lang}} </td>
<td>
@ -83,7 +81,6 @@
</td>
</tr>
{% endif %}
{% if url_list %}
<tr>
<td>URL</td>

@ -34,7 +34,10 @@
<div class="toolbar">
<div class="buycourses-price">
<span class="label label-primary label-price">
<strong>{{ session.on_sale.iso_code }} {{ session.on_sale.price }}</strong>
<strong>
{{ session.on_sale.iso_code }}
{{ session.on_sale.total_price_formatted }}
</strong>
</span>
</div>
</div>
@ -49,7 +52,6 @@
{% endif %}
{% endif %}
</div>
</div>
</div>
{% endfor %}

@ -159,7 +159,7 @@ $strings['PleaseSelectTheCorrectInfoToApplyTheService'] = "Please select the cor
$strings['SaleStatusCancelled'] = "Sale cancelled";
$strings['ServiceSaleInfo'] = "Service sale info";
$strings['ServiceId'] = "Service Id";
$strings['BoughtBy'] = "BoughtBy";
$strings['BoughtBy'] = "Bought by";
$strings['PurchaserUser'] = "Purchaser user";
$strings['Pending'] = "Pending";
$strings['Names'] = "Names";
@ -184,3 +184,7 @@ $strings['PurchaseDetailsIntro'] = "Purchase details";
$strings['PurchaseDetailsEnd'] = "Regards";
$strings['ProductName'] = "Product name";
$strings['BankAccountIntro'] = "Bank Account Info";
$strings['AdditionalInfoRequired'] = 'More information needed';
$strings['SubscriptionToServiceXSuccessful'] = "Subscription to service %s completed.";
$strings['ClickHereToFinish'] = "Click here to finish";
$strings['OrderCancelled'] = "Order cancelled";

@ -267,7 +267,7 @@ class BuyCoursesPlugin extends Plugin
date_invoice datetime NOT NULL,
PRIMARY KEY (id)
)";
$res = Database::query($sql);
Database::query($sql);
Display::addFlash(
Display::return_message(
@ -296,6 +296,7 @@ class BuyCoursesPlugin extends Plugin
UserManager::create_extra_field($fieldlabel, $fieldtype, $fieldtitle, $fielddefault);
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses');
exit;
}
/**
@ -320,7 +321,7 @@ class BuyCoursesPlugin extends Plugin
$html = '<div class="buycourses-price">';
if ($item) {
$html .= '<span class="label label-primary label-price">
<strong>'.$item['iso_code'].' '.$item['price'].'</strong>
<strong>'.$item['iso_code'].' '.$item['total_price_formatted'].'</strong>
</span>';
$return['verificator'] = true;
} else {
@ -493,6 +494,25 @@ class BuyCoursesPlugin extends Plugin
);
}
/**
* Get registered item data.
*
* @param int $itemId The item ID
*
* @return array
*/
public function getItem($itemId)
{
return Database::select(
'*',
Database::get_main_table(self::TABLE_ITEM),
[
'where' => ['id = ?' => (int) $itemId],
],
'first'
);
}
/**
* Get the item data.
*
@ -512,7 +532,7 @@ class BuyCoursesPlugin extends Plugin
ON i.currency_id = c.id
";
return Database::select(
$product = Database::select(
['i.*', 'c.iso_code'],
$fakeItemFrom,
[
@ -525,6 +545,14 @@ class BuyCoursesPlugin extends Plugin
],
'first'
);
if (empty($product)) {
return false;
}
$this->setPriceSettings($product, self::TAX_APPLIES_TO_ONLY_COURSE);
return $product;
}
/**
@ -626,7 +654,6 @@ class BuyCoursesPlugin extends Plugin
$user = $userCourseSubscription->getUser();
$sessionCourseData['coaches'][] = $user->getCompleteName();
}
$sessionData['courses'][] = $sessionCourseData;
}
@ -653,10 +680,6 @@ class BuyCoursesPlugin extends Plugin
return [];
}
$taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
$courseCatalog = [];
foreach ($courses as $course) {
$item = $this->getItemByProduct(
@ -668,25 +691,12 @@ class BuyCoursesPlugin extends Plugin
continue;
}
$price = $item['price'];
$taxPerc = null;
$priceWithoutTax = $item['price'];
if ($taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_COURSE)
) {
$globalTaxPerc = $globalParameters['global_tax_perc'];
$precision = 2;
$taxPerc = is_null($item['tax_perc']) ? $globalTaxPerc : $item['tax_perc'];
$taxAmount = round($priceWithoutTax * $taxPerc / 100, $precision);
$price = $priceWithoutTax + $taxAmount;
}
$courseItem = [
'id' => $course->getId(),
'title' => $course->getTitle(),
'code' => $course->getCode(),
'course_img' => null,
'price' => $price,
'price' => $item['total_price'],
'currency' => $item['iso_code'],
'teachers' => [],
'enrolled' => $this->getUserStatusForCourse(api_get_user_id(), $course),
@ -705,7 +715,6 @@ class BuyCoursesPlugin extends Plugin
if (file_exists($possiblePath)) {
$courseItem['course_img'] = api_get_path(WEB_COURSE_PATH).$course->getDirectory().'/course-pic.png';
}
$courseCatalog[] = $courseItem;
}
@ -748,25 +757,7 @@ class BuyCoursesPlugin extends Plugin
]
);
$price = $item['price'];
$taxAmount = 0;
$taxPerc = null;
$priceWithoutTax = $item['price'];
$precision = 2;
$taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
if ($taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_COURSE)
) {
$globalTaxPerc = $globalParameters['global_tax_perc'];
$precision = 2;
$taxPerc = is_null($item['tax_perc']) ? $globalTaxPerc : $item['tax_perc'];
$taxAmount = round($priceWithoutTax * $taxPerc / 100, $precision);
$price = $priceWithoutTax + $taxAmount;
}
$courseInfo = [
'id' => $course->getId(),
'title' => $course->getTitle(),
@ -774,13 +765,12 @@ class BuyCoursesPlugin extends Plugin
'code' => $course->getCode(),
'visual_code' => $course->getVisualCode(),
'teachers' => [],
'price' => number_format($price, $precision),
'price_without_tax' => number_format($priceWithoutTax, $precision),
'tax_amount' => number_format($taxAmount, $precision),
'tax_perc' => $taxPerc,
'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' => $taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_COURSE),
'tax_enable' => $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_COURSE),
'currency' => $item['iso_code'],
'course_img' => null,
];
@ -830,46 +820,30 @@ class BuyCoursesPlugin extends Plugin
return [];
}
$sessionDates = SessionManager::parseSessionDates([
$sessionDates = SessionManager::parseSessionDates(
[
'display_start_date' => $session->getDisplayStartDate(),
'display_end_date' => $session->getDisplayEndDate(),
'access_start_date' => $session->getAccessStartDate(),
'access_end_date' => $session->getAccessEndDate(),
'coach_access_start_date' => $session->getCoachAccessStartDate(),
'coach_access_end_date' => $session->getCoachAccessEndDate(),
]);
$price = $item['price'];
$taxAmount = 0;
$taxPerc = null;
$priceWithoutTax = $item['price'];
$precision = 2;
]
);
$taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
if ($taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SESSION)
) {
$globalTaxPerc = $globalParameters['global_tax_perc'];
$taxPerc = is_null($item['tax_perc']) ? $globalTaxPerc : $item['tax_perc'];
$taxAmount = round($priceWithoutTax * $taxPerc / 100, $precision);
$price = $priceWithoutTax + $taxAmount;
}
$sessionInfo = [
'id' => $session->getId(),
'name' => $session->getName(),
'description' => $session->getDescription(),
'dates' => $sessionDates,
'courses' => [],
'price' => number_format($price, $precision),
'price_without_tax' => number_format($priceWithoutTax, $precision),
'tax_amount' => number_format($taxAmount, $precision),
'tax_perc' => $taxPerc,
'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' => $taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SESSION),
'tax_enable' => $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_SESSION),
'currency' => $item['iso_code'],
'image' => null,
'nbrCourses' => $session->getNbrCourses(),
@ -887,10 +861,8 @@ class BuyCoursesPlugin extends Plugin
}
$sessionCourses = $session->getCourses();
foreach ($sessionCourses as $sessionCourse) {
$course = $sessionCourse->getCourse();
$sessionCourseData = [
'title' => $course->getTitle(),
'coaches' => [],
@ -914,25 +886,6 @@ class BuyCoursesPlugin extends Plugin
return $sessionInfo;
}
/**
* Get registered item data.
*
* @param int $itemId The item ID
*
* @return array
*/
public function getItem($itemId)
{
return Database::select(
'*',
Database::get_main_table(self::TABLE_ITEM),
[
'where' => ['id = ?' => (int) $itemId],
],
'first'
);
}
/**
* Register a sale.
*
@ -980,14 +933,16 @@ class BuyCoursesPlugin extends Plugin
$priceWithoutTax = null;
$taxPerc = null;
$taxAmount = 0;
$taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
if ($taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL ||
(
$taxAppliesTo == self::TAX_APPLIES_TO_ALL ||
($taxAppliesTo == self::TAX_APPLIES_TO_ONLY_COURSE && $item['product_type'] == self::PRODUCT_TYPE_COURSE) ||
($taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SESSION && $item['product_type'] == self::PRODUCT_TYPE_SESSION))
($taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SESSION && $item['product_type'] == self::PRODUCT_TYPE_SESSION)
)
) {
$priceWithoutTax = $item['price'];
$globalTaxPerc = $globalParameters['global_tax_perc'];
@ -1082,34 +1037,34 @@ class BuyCoursesPlugin extends Plugin
*/
public function getDataSaleInvoice($saleId, $isService)
{
$data = [];
$sale = [];
if ($isService) {
$sale = $this->getServiceSale($saleId);
$data['reference'] = $sale['reference'];
$data['product_name'] = $sale['service']['name'];
$data['payment_type'] = $sale['payment_type'];
$data['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'];
$data['date'] = $sale['buy_date'];
$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'];
//$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 $data;
return $sale;
}
/**
@ -2088,101 +2043,102 @@ class BuyCoursesPlugin extends Plugin
);
}
public function setPriceSettings(&$product, $productType)
{
if (empty($product)) {
return false;
}
$taxPerc = null;
$priceWithoutTax = $product['price'];
$product['total_price'] = $product['price'];
$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'];
$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['tax_amount_formatted'] = number_format($product['tax_amount'], $precision);
}
/**
* List additional services.
*
* @param int $id service id
* @param int $id
*
* @return array
*/
public function getServices($id = null)
public function getService($id)
{
$servicesTable = Database::get_main_table(self::TABLE_SERVICES);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$conditions = null;
$showData = "all";
$id = (int) $id;
if ($id) {
$conditions = ['WHERE' => ['s.id = ?' => $id]];
$showData = "first";
if (empty($id)) {
return [];
}
$servicesTable = Database::get_main_table(self::TABLE_SERVICES);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$conditions = ['WHERE' => ['s.id = ?' => $id]];
$showData = 'first';
$innerJoins = "INNER JOIN $userTable u ON s.owner_id = u.id";
$currency = $this->getSelectedCurrency();
$isoCode = $currency['iso_code'];
$return = Database::select(
$service = Database::select(
"s.*, '$isoCode' as currency, u.firstname, u.lastname",
"$servicesTable s $innerJoins",
$conditions,
$showData
);
$services = [];
$globalParameters = $this->getGlobalParameters();
if ($id) {
$price = $return['price'];
$taxPerc = null;
$priceWithoutTax = $priceWithTax = $return['price'];
$precision = 2;
$this->setPriceSettings($service, self::TAX_APPLIES_TO_ONLY_SERVICES);
/*$service['tax_perc'] = $return['tax_perc'];
$service['price_with_tax'] = $return['total_price_formatted'];
$service['price_without_tax'] = $return['price_formatted'];
$service['tax_amount'] = $return['tax_amount_formatted'];
$service['tax_perc_show'] = $return['tax_perc_show'];*/
$taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
if ($taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SERVICES)
) {
$globalTaxPerc = $globalParameters['global_tax_perc'];
$precision = 2;
$taxPerc = is_null($return['tax_perc']) ? $globalTaxPerc : $return['tax_perc'];
$taxAmount = round($priceWithoutTax * $taxPerc / 100, $precision);
$priceWithTax = $priceWithoutTax + $taxAmount;
}
$service['price_with_tax'] = $service['total_price_formatted'];
$service['price_without_tax'] = $service['price_formatted'];
$services['id'] = $return['id'];
$services['name'] = $return['name'];
$services['description'] = $return['description'];
$services['price'] = $price;
$services['tax_perc'] = $return['tax_perc'];
$services['price_with_tax'] = number_format($priceWithTax, $precision);
$services['price_without_tax'] = number_format($priceWithoutTax, $precision);
$services['tax_amount'] = number_format($taxAmount, $precision);
$services['tax_perc_show'] = $taxPerc;
$services['tax_name'] = $globalParameters['tax_name'];
$services['tax_enable'] = $taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SERVICES);
$services['currency'] = $return['currency'];
$services['duration_days'] = $return['duration_days'];
$services['applies_to'] = $return['applies_to'];
$services['owner_id'] = $return['owner_id'];
$services['owner_name'] = api_get_person_name($return['firstname'], $return['lastname']);
$services['visibility'] = $return['visibility'];
$services['image'] = !empty($return['image']) ? api_get_path(
WEB_PLUGIN_PATH
).'buycourses/uploads/services/images/'.$return['image'] : null;
$services['video_url'] = $return['video_url'];
$services['service_information'] = $return['service_information'];
$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']);
$service['image'] = !empty($service['image']) ? api_get_path(WEB_PLUGIN_PATH).'buycourses/uploads/services/images/'.$service['image'] : null;
return $services;
return $service;
}
/**
* List additional services.
*
* @return array
*/
public function getServices()
{
$servicesTable = Database::get_main_table(self::TABLE_SERVICES);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$conditions = null;
$showData = 'all';
$innerJoins = "INNER JOIN $userTable u ON s.owner_id = u.id";
$return = Database::select(
's.id',
"$servicesTable s $innerJoins",
$conditions,
$showData
);
$services = [];
foreach ($return as $index => $service) {
$services[$index]['id'] = $service['id'];
$services[$index]['name'] = $service['name'];
$services[$index]['description'] = $service['description'];
$services[$index]['price'] = $service['price'];
$services[$index]['tax_perc'] = $service['tax_perc'];
$services[$index]['currency'] = $service['currency'];
$services[$index]['duration_days'] = $service['duration_days'];
$services[$index]['applies_to'] = $service['applies_to'];
$services[$index]['owner_id'] = $service['owner_id'];
$services[$index]['owner_name'] = api_get_person_name($service['firstname'], $service['lastname']);
$services[$index]['visibility'] = $service['visibility'];
$services[$index]['image'] = !empty($service['image']) ? api_get_path(
WEB_PLUGIN_PATH
).'buycourses/uploads/services/images/'.$service['image'] : null;
$services[$index]['video_url'] = $service['video_url'];
$services[$index]['service_information'] = $service['service_information'];
$services[$index] = $this->getService($service['id']);
}
return $services;
@ -2272,10 +2228,10 @@ class BuyCoursesPlugin extends Plugin
}
if ($hot) {
$hot = "count(ss.service_id) as hot, ";
$hot = 'count(ss.service_id) as hot, ';
$conditions = ['ORDER' => 'hot DESC', 'LIMIT' => '6'];
$groupBy = "GROUP BY ss.service_id";
"clean_teacher_files.php";
$groupBy = 'GROUP BY ss.service_id';
'clean_teacher_files.php';
}
$innerJoins = "INNER JOIN $servicesTable s ON ss.service_id = s.id $groupBy";
@ -2444,49 +2400,15 @@ class BuyCoursesPlugin extends Plugin
}
$innerJoins = "INNER JOIN $userTable u ON s.owner_id = u.id";
$currency = $this->getSelectedCurrency();
$isoCode = $currency['iso_code'];
$return = Database::select(
"s.*, '$isoCode' as currency, u.firstname, u.lastname",
's.*',
"$servicesTable s $innerJoins",
['WHERE' => $whereConditions]
);
$services = [];
foreach ($return as $index => $service) {
$price = $service['price'];
$taxPerc = null;
$priceWithoutTax = $service['price'];
$taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
if ($taxEnable &&
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SERVICES)
) {
$globalTaxPerc = $globalParameters['global_tax_perc'];
$precision = 2;
$taxPerc = is_null($service['tax_perc']) ? $globalTaxPerc : $service['tax_perc'];
$taxAmount = round($priceWithoutTax * $taxPerc / 100, $precision);
$price = $priceWithoutTax + $taxAmount;
}
$services[$index]['id'] = $service['id'];
$services[$index]['name'] = $service['name'];
$services[$index]['description'] = $service['description'];
$services[$index]['price'] = number_format($price, $precision);
$services[$index]['currency'] = $service['currency'];
$services[$index]['duration_days'] = $service['duration_days'];
$services[$index]['applies_to'] = $service['applies_to'];
$services[$index]['owner_id'] = $service['owner_id'];
$services[$index]['owner_name'] = api_get_person_name($service['firstname'], $service['lastname']);
$services[$index]['visibility'] = $service['visibility'];
$services[$index]['image'] = !empty($service['image'])
? api_get_path(WEB_PLUGIN_PATH).'buycourses/uploads/services/images/'.$service['image']
: null;
$services[$index]['video_url'] = $service['video_url'];
$services[$index]['service_information'] = $service['service_information'];
$services[$index] = $this->getService($service['id']);
}
return $services;
@ -2513,7 +2435,7 @@ class BuyCoursesPlugin extends Plugin
}
$userId = api_get_user_id();
$service = $this->getServices($serviceId);
$service = $this->getService($serviceId);
if (empty($service)) {
return false;
@ -2657,6 +2579,30 @@ class BuyCoursesPlugin extends Plugin
);
}
/**
* @param int $productType
*
* @return bool
*/
public function checkTaxEnabledInProduct($productType)
{
if (empty($this->get('tax_enable') === 'true')) {
return false;
}
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
if ($taxAppliesTo == self::TAX_APPLIES_TO_ALL) {
return true;
}
if ($taxAppliesTo == $productType) {
return true;
}
return false;
}
/**
* Get the path.
*

@ -20,11 +20,7 @@ if (api_is_anonymous()) {
}
$plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$commissionsEnable = $plugin->get('commissions_enable');
$culqiEnable = $plugin->get('culqi_enable');
$action = isset($_GET['a']) ? $_GET['a'] : null;
$em = Database::getManager();
@ -50,11 +46,11 @@ switch ($action) {
break;
}
$saleId = isset($_POST['id']) ? intval($_POST['id']) : '';
$saleId = isset($_POST['id']) ? (int) $_POST['id'] : '';
$sale = $plugin->getSale($saleId);
$productType = ($sale['product_type'] == 1) ? get_lang('Course') : get_lang('Session');
$paymentType = ($sale['payment_type'] == 1) ? 'Paypal' : $plugin->get_lang('BankTransfer');
$productInfo = ($sale['product_type'] == 1)
$productType = $sale['product_type'] == 1 ? get_lang('Course') : get_lang('Session');
$paymentType = $sale['payment_type'] == 1 ? 'Paypal' : $plugin->get_lang('BankTransfer');
$productInfo = $sale['product_type'] == 1
? api_get_course_info_by_id($sale['product_id'])
: api_get_session_info($sale['product_id']);
$currency = $plugin->getSelectedCurrency();
@ -72,7 +68,7 @@ switch ($action) {
$html .= '<div class="row">';
$html .= '<div class="col-sm-6 col-md-6">';
$html .= '<ul>';
$html .= '<li><b>'.$plugin->get_lang('OrderPrice').':</b> '.$sale['price'].'</li>';
$html .= '<li><b>'.$plugin->get_lang('OrderPrice').':</b> '.$sale['total_price'].'</li>';
$html .= '<li><b>'.$plugin->get_lang('CurrencyType').':</b> '.$currency['iso_code'].'</li>';
$html .= '<li><b>'.$plugin->get_lang('ProductType').':</b> '.$productType.'</li>';
$html .= '<li><b>'.$plugin->get_lang('OrderDate').':</b> '.
@ -472,8 +468,7 @@ switch ($action) {
$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 = "";
$nodeName = '';
if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_USER) {
$nodeType = get_lang('User');
/** @var User $user */
@ -501,15 +496,24 @@ switch ($action) {
}
}
}
$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 .= "<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> ";
$taxEnable = $plugin->get('tax_enable') === 'true';
if ($taxEnable) {
//$html .= "<li><b>{$plugin->get_lang('Price')}:</b> {$serviceSale['price_without_tax']} {$serviceSale['currency']}</li> ";
//$html .= "<li><b>{$plugin->get_lang('Price')}:</b> {$serviceSale['tax_amount']} {$serviceSale['currency']}</li> ";
}
$html .= "<li><b>{$plugin->get_lang('Total')}:</b> {$serviceSale['price']} {$serviceSale['currency']}</li> ";
//$html .= "<li><b>{$plugin->get_lang('SalePrice')}:</b> {$serviceSale['price_without_tax']} {$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'];
@ -525,9 +529,9 @@ switch ($action) {
}
}
$html .= "<li><b>{$plugin->get_lang('PaymentMethod')}:</b> $paymentType</li> ";
$html .= "<li><b>$nodeType:</b> $nodeName</li> ";
//$html .= "<li><b>$nodeType:</b> $nodeName</li> ";
$status = $serviceSale['status'];
$buttons = "";
$buttons = '';
if ($status == BuyCoursesPlugin::SERVICE_STATUS_COMPLETED) {
$status = $plugin->get_lang('Active');
} else {

@ -12,12 +12,14 @@ require_once '../config.php';
api_protect_admin_script();
if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
die;
$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0;
$type = isset($_REQUEST['type']) ? (int) $_REQUEST['type'] : 0;
if (empty($id) || empty($type)) {
api_not_allowed();
}
$plugin = BuyCoursesPlugin::create();
$commissionsEnable = $plugin->get('commissions_enable');
if ($commissionsEnable == 'true') {
@ -28,13 +30,11 @@ if ($commissionsEnable == 'true') {
}
$includeSession = $plugin->get('include_sessions') === 'true';
$editingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
$editingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
$editingCourse = $type === BuyCoursesPlugin::PRODUCT_TYPE_COURSE;
$editingSession = $type === BuyCoursesPlugin::PRODUCT_TYPE_SESSION;
$entityManager = Database::getManager();
$userRepo = UserManager::getRepository();
$currency = $plugin->getSelectedCurrency();
if (empty($currency)) {
@ -46,7 +46,7 @@ if (empty($currency)) {
$currencyIso = null;
if ($editingCourse) {
$course = $entityManager->find('ChamiloCoreBundle:Course', $_REQUEST['i']);
$course = $entityManager->find('ChamiloCoreBundle:Course', $id);
if (!$course) {
api_not_allowed(true);
@ -67,22 +67,17 @@ if ($editingCourse) {
'text' => $teacher->getCompleteName(),
'value' => $teacher->getId(),
];
$defaultBeneficiaries[] = $teacher->getId();
}
$currentBeneficiaries = $plugin->getItemBeneficiaries($courseItem['item_id']);
if (!empty($currentBeneficiaries)) {
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
if ($commissionsEnable === 'true') {
$defaultCommissions = array_column($currentBeneficiaries, 'commissions');
foreach ($defaultCommissions as $defaultCommission) {
$commissions .= $defaultCommission.',';
}
$commissions = substr($commissions, 0, -1);
}
}
@ -90,22 +85,21 @@ if ($editingCourse) {
$currencyIso = $courseItem['currency'];
$formDefaults = [
'product_type' => get_lang('Course'),
'i' => $courseItem['course_id'],
't' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE,
'id' => $courseItem['course_id'],
'type' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE,
'name' => $courseItem['course_title'],
'visible' => $courseItem['visible'],
'price' => $courseItem['price'],
'tax_perc' => $courseItem['tax_perc'],
'beneficiaries' => $defaultBeneficiaries,
($commissionsEnable == "true") ? 'commissions' : '' => ($commissionsEnable == "true") ? $commissions : '',
$commissionsEnable == 'true' ? 'commissions' : '' => $commissionsEnable == 'true' ? $commissions : '',
];
} elseif ($editingSession) {
if (!$includeSession) {
api_not_allowed(true);
}
$session = $entityManager->find('ChamiloCoreBundle:Session', $_REQUEST['i']);
$session = $entityManager->find('ChamiloCoreBundle:Session', $id);
if (!$session) {
api_not_allowed(true);
}
@ -143,7 +137,7 @@ if ($editingCourse) {
if (!empty($currentBeneficiaries)) {
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id');
if ($commissionsEnable == "true") {
if ($commissionsEnable == 'true') {
$defaultCommissions = array_column($currentBeneficiaries, 'commissions');
foreach ($defaultCommissions as $defaultCommission) {
@ -157,14 +151,14 @@ if ($editingCourse) {
$currencyIso = $sessionItem['currency'];
$formDefaults = [
'product_type' => get_lang('Session'),
'i' => $session->getId(),
't' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION,
'id' => $session->getId(),
'type' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION,
'name' => $sessionItem['session_name'],
'visible' => $sessionItem['visible'],
'price' => $sessionItem['price'],
'tax_perc' => $sessionItem['tax_perc'],
'beneficiaries' => $defaultBeneficiaries,
($commissionsEnable == "true") ? 'commissions' : '' => ($commissionsEnable == "true") ? $commissions : '',
$commissionsEnable == 'true' ? 'commissions' : '' => $commissionsEnable == 'true' ? $commissions : '',
];
} else {
api_not_allowed(true);
@ -182,9 +176,7 @@ if ($commissionsEnable === 'true') {
} else {
showSliders(100, 'default', '".$commissions."');
}
});
$(document).ready(function () {
var maxPercentage = 100;
$('#selectBox').on('change', function() {
$('#panelSliders').html('');
@ -204,7 +196,7 @@ $globalSettingsParams = $plugin->getGlobalParameters();
$form = new FormValidator('beneficiaries');
$form->addText('product_type', $plugin->get_lang('ProductType'), false);
$form->addText('name', get_lang('Name'), false);
$visibleCheckbox = $form->addCheckBox(
$form->addCheckBox(
'visible',
$plugin->get_lang('VisibleInCatalog'),
$plugin->get_lang('ShowOnCourseCatalog')
@ -251,16 +243,15 @@ if ($commissionsEnable === 'true') {
'info',
false
).'
<div class="" id="panelSliders"></div>
<div id="panelSliders"></div>
</div>
</div>'
);
$form->addHidden('commissions', '');
}
$form->addHidden('t', null);
$form->addHidden('i', null);
$form->addHidden('type', null);
$form->addHidden('id', null);
$button = $form->addButtonSave(get_lang('Save'));
if (empty($currency)) {
@ -271,8 +262,8 @@ $form->freeze(['product_type', 'name']);
if ($form->validate()) {
$formValues = $form->exportValues();
$productItem = $plugin->getItemByProduct($formValues['i'], $formValues['t']);
$id = $formValues['id'];
$productItem = $plugin->getItemByProduct($id, $formValues['type']);
if (isset($formValues['visible'])) {
$taxPerc = $formValues['tax_perc'] != '' ? (int) $formValues['tax_perc'] : null;
if (!empty($productItem)) {
@ -287,8 +278,8 @@ if ($form->validate()) {
} else {
$itemId = $plugin->registerItem([
'currency_id' => (int) $currency['id'],
'product_type' => $formValues['t'],
'product_id' => intval($formValues['i']),
'product_type' => $formValues['type'],
'product_id' => $id,
'price' => floatval($_POST['price']),
'tax_perc' => $taxPerc,
]);
@ -300,7 +291,7 @@ if ($form->validate()) {
if (isset($formValues['beneficiaries'])) {
if ($commissionsEnable === 'true') {
$usersId = $formValues['beneficiaries'];
$commissions = explode(",", $formValues['commissions']);
$commissions = explode(',', $formValues['commissions']);
$commissions = (count($usersId) != count($commissions))
? array_fill(0, count($usersId), 0)
: $commissions;
@ -310,7 +301,6 @@ if ($form->validate()) {
$commissions = array_fill(0, count($usersId), 0);
$beneficiaries = array_combine($usersId, $commissions);
}
$plugin->registerItemBeneficiaries($productItem['id'], $beneficiaries);
}
} else {
@ -323,7 +313,6 @@ if ($form->validate()) {
$form->setDefaults($formDefaults);
// View
$templateName = $plugin->get_lang('AvailableCourse');
$interbreadcrumb[] = [

@ -1,5 +1,6 @@
<?php
/* For license terms, see /license.txt */
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
/**
@ -137,5 +138,5 @@ $params = [
'orientation' => 'P',
];
$pdf = new PDF($params['format'], $params['orientation'], $params);
$pdf->content_to_pdf($htmlText, '', $fileName, null, 'D', false, null, false, false, false);
@$pdf->content_to_pdf($htmlText, '', $fileName, null, 'D', false, null, false, false, false);
exit;

@ -47,10 +47,7 @@ if ($buyingCourse) {
$item = $plugin->getItemByProduct($_REQUEST['i'], BuyCoursesPlugin::PRODUCT_TYPE_SESSION);
}
$userInfo = api_get_user_info();
$form = new FormValidator('confirm_sale');
if ($form->validate()) {
$formValues = $form->getSubmitValues();
@ -92,7 +89,6 @@ if ($count === 0) {
$form->addHtml('<br />');
$form->addHtml('<br />');
} elseif ($count === 1) {
$text = '';
// get the only array item
foreach ($paymentTypesOptions as $type => $value) {
$form->addHtml(sprintf($plugin->get_lang('XIsOnlyPaymentMethodAvailable'), $value));
@ -116,7 +112,7 @@ $form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success'
// View
$templateName = $plugin->get_lang('PaymentMethods');
$interbreadcrumb[] = ["url" => "course_catalog.php", "name" => $plugin->get_lang('CourseListOnSale')];
$interbreadcrumb[] = ['url' => "course_catalog.php", 'name' => $plugin->get_lang('CourseListOnSale')];
$tpl = new Template($templateName);
$tpl->assign('buying_course', $buyingCourse);

@ -25,7 +25,7 @@ if (!$includeServices) {
api_not_allowed(true);
}
$service = $plugin->getServices($serviceId);
$service = $plugin->getService($serviceId);
if (!$service['id']) {
api_not_allowed(true);

@ -16,10 +16,12 @@ require_once '../config.php';
if (!isset($_REQUEST['t'], $_REQUEST['i'])) {
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
exit;
}
$currentUserId = api_get_user_id();
$serviceId = intval($_REQUEST['i']);
$serviceId = (int) $_REQUEST['i'];
$type = (int) $_REQUEST['t'];
if (empty($currentUserId)) {
api_not_allowed(true);
@ -33,57 +35,21 @@ $includeServices = $plugin->get('include_services');
$paypalEnabled = $plugin->get('paypal_enable') === 'true';
$transferEnabled = $plugin->get('transfer_enable') === 'true';
$culqiEnabled = $plugin->get('culqi_enable') === 'true';
$wizard = true;
$additionalQueryString = '';
if ($includeServices !== 'true') {
api_not_allowed(true);
}
$typeUser = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_USER;
$typeCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_COURSE;
$typeSession = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_SESSION;
$typeFinalLp = intval($_REQUEST['t']) === BuyCoursesPlugin::SERVICE_TYPE_LP_FINAL_ITEM;
$queryString = 'i='.intval($_REQUEST['i']).'&t='.intval($_REQUEST['t']).$additionalQueryString;
$typeUser = $type === BuyCoursesPlugin::SERVICE_TYPE_USER;
$typeCourse = $type === BuyCoursesPlugin::SERVICE_TYPE_COURSE;
$typeSession = $type === BuyCoursesPlugin::SERVICE_TYPE_SESSION;
$typeFinalLp = $type === BuyCoursesPlugin::SERVICE_TYPE_LP_FINAL_ITEM;
$queryString = 'i='.$serviceId.'&t='.$type.$additionalQueryString;
$serviceInfo = $plugin->getServices(intval($_REQUEST['i']));
$serviceInfo = $plugin->getService($serviceId);
$userInfo = api_get_user_info($currentUserId);
$form = new FormValidator('confirm_sale');
if ($form->validate()) {
$formValues = $form->getSubmitValues();
if (!$formValues['payment_type']) {
Display::addFlash(
Display::return_message($plugin->get_lang('NeedToSelectPaymentType'), 'error', false)
);
header('Location:'.api_get_self().'?'.$queryString);
exit;
}
if (!$formValues['info_select']) {
Display::addFlash(
Display::return_message($plugin->get_lang('AdditionalInfoRequired'), 'error', false)
);
header('Location:'.api_get_self().'?'.$queryString);
exit;
}
$serviceSaleId = $plugin->registerServiceSale(
$serviceId,
$formValues['payment_type'],
$formValues['info_select'],
$formValues['enable_trial']
);
if ($serviceSaleId !== false) {
$_SESSION['bc_service_sale_id'] = $serviceSaleId;
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_process_confirm.php');
}
exit;
}
$paymentTypesOptions = $plugin->getPaymentTypes();
if (!$paypalEnabled) {
@ -105,12 +71,18 @@ $form->addHtml(
)
);
$form->addRadio('payment_type', null, $paymentTypesOptions);
$infoRequired = false;
if ($typeUser || $typeCourse || $typeSession || $typeFinalLp) {
$infoRequired = true;
$form->addHtml(
Display::return_message(
$plugin->get_lang('PleaseSelectTheCorrectInfoToApplyTheService'),
'info'
)
);
}
$selectOptions = [
0 => get_lang('None'),
];
@ -213,7 +185,6 @@ if ($typeUser) {
// Here check all the lpItems
foreach ($thisLpList as $lp) {
$thisLpItems = $em->getRepository('ChamiloCourseBundle:CLpItem')->findBy(['lpId' => $lp->getId()]);
foreach ($thisLpItems as $item) {
//Now only we need the final item and return the current LP
if ($item->getItemType() == TOOL_LP_FINAL_ITEM) {
@ -225,7 +196,6 @@ if ($typeUser) {
}
$selectOptions = $selectOptions + $courseLpList + $sessionLpList;
if (!$checker) {
$form->addHtml(
Display::return_message(
@ -239,14 +209,50 @@ if ($typeUser) {
$form->addHidden('t', intval($_GET['t']));
$form->addHidden('i', intval($_GET['i']));
$form->addButton('submit', $plugin->get_lang('ConfirmOrder'), 'check', 'success');
if ($form->validate()) {
$formValues = $form->getSubmitValues();
if (!isset($formValues['payment_type'])) {
Display::addFlash(
Display::return_message($plugin->get_lang('NeedToSelectPaymentType'), 'error', false)
);
header('Location:'.api_get_self().'?'.$queryString);
exit;
}
$infoSelected = [];
if ($infoRequired) {
if (isset($formValues['info_select'])) {
$infoSelected = $formValues['info_select'];
} else {
Display::addFlash(
Display::return_message($plugin->get_lang('AdditionalInfoRequired'), 'error', false)
);
header('Location:'.api_get_self().'?'.$queryString);
exit;
}
}
$serviceSaleId = $plugin->registerServiceSale(
$serviceId,
$formValues['payment_type'],
$infoSelected
);
if ($serviceSaleId !== false) {
$_SESSION['bc_service_sale_id'] = $serviceSaleId;
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_process_confirm.php');
}
exit;
}
// View
$templateName = $plugin->get_lang('PaymentMethods');
$interbreadcrumb[] = [
"url" => "service_catalog.php",
"name" => $plugin->get_lang('ListOfServicesOnSale'),
'url' => 'service_catalog.php',
'name' => $plugin->get_lang('ListOfServicesOnSale'),
];
$tpl = new Template($templateName);

@ -1,6 +1,8 @@
<?php
/* For license terms, see /license.txt */
use ChamiloSession as Session;
/**
* Process purchase confirmation script for the Buy Courses plugin.
*
@ -9,15 +11,13 @@
require_once '../config.php';
$plugin = BuyCoursesPlugin::create();
$serviceSaleId = $_SESSION['bc_service_sale_id'];
$serviceSaleId = Session::read('bc_service_sale_id');
if (empty($serviceSaleId)) {
api_not_allowed(true);
}
$serviceSale = $plugin->getServiceSale($serviceSaleId);
$userInfo = api_get_user_info($serviceSale['buyer']['id']);
if (empty($serviceSale)) {
@ -46,8 +46,7 @@ switch ($serviceSale['payment_type']) {
// The extra params for handle the hard job, this var is VERY IMPORTANT !!
$extra = '';
require_once "paypalfunctions.php";
require_once 'paypalfunctions.php';
$extra .= "&L_PAYMENTREQUEST_0_NAME0={$serviceSale['service']['name']}";
$extra .= "&L_PAYMENTREQUEST_0_QTY0=1";
@ -63,7 +62,7 @@ switch ($serviceSale['payment_type']) {
$extra
);
if ($expressCheckout["ACK"] !== 'Success') {
if ($expressCheckout['ACK'] !== 'Success') {
$erroMessage = vsprintf(
$plugin->get_lang('ErrorOccurred'),
[$expressCheckout['L_ERRORCODE0'], $expressCheckout['L_LONGMESSAGE0']]
@ -72,8 +71,7 @@ switch ($serviceSale['payment_type']) {
Display::return_message($erroMessage, 'error', false)
);
$plugin->cancelServiceSale(intval($serviceSale['id']));
$plugin->cancelServiceSale($serviceSale['id']);
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses/src/service_catalog.php');
exit;
}
@ -118,7 +116,7 @@ switch ($serviceSale['payment_type']) {
$formValues = $form->getSubmitValues();
if (isset($formValues['cancel'])) {
$plugin->cancelServiceSale(intval($serviceSale['id']));
$plugin->cancelServiceSale($serviceSale['id']);
unset($_SESSION['bc_service_sale_id']);
Display::addFlash(
@ -209,7 +207,6 @@ switch ($serviceSale['payment_type']) {
);
$template = new Template();
$template->assign('terms', $globalParameters['terms_and_conditions']);
$template->assign('title', $serviceSale['service']['name']);
$template->assign('price', $serviceSale['price']);
@ -225,7 +222,6 @@ switch ($serviceSale['payment_type']) {
$template->assign('content', $content);
$template->display_one_col_template();
break;
case BuyCoursesPlugin::PAYMENT_TYPE_CULQI:
// We need to include the main online script, acording to the Culqi documentation the JS needs to be loeaded
// directly from the main url "https://integ-pago.culqi.com" because a local copy of this JS is not supported

@ -20,17 +20,11 @@ $includeServices = $plugin->get('include_services');
$invoicingEnable = $plugin->get('invoicing_enable') === 'true';
$saleStatuses = $plugin->getServiceSaleStatuses();
$paymentTypes = $plugin->getPaymentTypes();
$selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING;
$searchTerm = '';
$form = new FormValidator('search', 'get');
if ($form->validate()) {
$selectedStatus = $form->getSubmitValue('status');
$searchTerm = $form->getSubmitValue('user');
if ($selectedStatus === false) {
$selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING;
}

@ -10,7 +10,7 @@ $cidReset = true;
require_once '../../../main/inc/global.inc.php';
$serviceId = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
$serviceId = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : null;
if (!$serviceId) {
header('Location: configuration.php');
@ -18,7 +18,6 @@ if (!$serviceId) {
$plugin = BuyCoursesPlugin::create();
$currency = $plugin->getSelectedCurrency();
$em = Database::getManager();
$users = UserManager::getRepository()->findAll();
$userOptions = [];
if (!empty($users)) {
@ -38,7 +37,7 @@ $interbreadcrumb[] = [
];
$globalSettingsParams = $plugin->getGlobalParameters();
$service = $plugin->getServices($serviceId);
$service = $plugin->getService($serviceId);
$formDefaultValues = [
'name' => $service['name'],

@ -135,7 +135,8 @@
<div class="col-md-4 col-sm-6">
<div class="items-course">
<div class="items-course-image">
<a href="{{ _p.web }}service/{{ service.id }}"><img alt="{{ service.name }}"
<a href="{{ _p.web }}service/{{ service.id }}">
<img alt="{{ service.name }}"
class="img-responsive"
src="{{ service.image ? service.image : 'session_default.png'|icon() }}"></a>
</div>
@ -176,7 +177,7 @@
</ul>
<p class="text-right">
<span class="label label-primary">
{{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}
{{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.total_price_formatted }}
</span>
</p>
<div class="toolbar">

@ -85,7 +85,7 @@
</td>
{% endif %}
<td class="text-right">
<a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'i': item.course_id, 't':product_type_course}|url_encode() }}"
<a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'id': item.course_id, 'type':product_type_course}|url_encode() }}"
class="btn btn-info btn-sm">
<em class="fa fa-wrench fa-fw"></em> {{ 'Configure'|get_lang }}
</a>
@ -146,9 +146,10 @@
</td>
{% endif %}
<td class="text-right">
<a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'i': item.session_id, 't': product_type_session}|url_encode() }}"
<a href="{{ _p.web_plugin ~ 'buycourses/src/configure_course.php?' ~ {'id': item.session_id, 'type': product_type_session}|url_encode() }}"
class="btn btn-info btn-sm">
<em class="fa fa-wrench fa-fw"></em> {{ 'Configure'|get_lang }}
<em class="fa fa-wrench fa-fw"></em>
{{ 'Configure'|get_lang }}
</a>
</td>
</tr>

@ -26,7 +26,10 @@
{% endfor %}
</ul>
<p id="n-price" class="lead text-right" style="color: white;">
<span class="label label-primary">{{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.price }}</span>
<span class="label label-primary">
{{ course.currency == 'BRL' ? 'R$' : course.currency }}
{{ course.price }}
</span>
</p>
<p id="s-price" class="lead text-right"></p>
</div>
@ -57,7 +60,10 @@
{% endfor %}
</ul>
<p id="n-price" class="lead text-right" style="color: white;">
<span class="label label-primary">{{ session.currency == 'BRL' ? 'R$' : session.currency }} {{ session.price }}</span>
<span class="label label-primary">
{{ session.currency == 'BRL' ? 'R$' : session.currency }}
{{ session.price }}
</span>
</p>
<p id="s-price" class="lead text-right"></p>
</div>
@ -98,8 +104,10 @@
<em class="fa fa-hand-o-right"></em> {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'TemplateTitleCertificate'|get_lang }}
</li>
{% endif %}
<li><em class="fa fa-money"></em> {{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}
: {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}
<li>
<em class="fa fa-money"></em>
{{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }}
: {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ price }}
/ {{ service.duration_days == 0 ? 'NoLimit'|get_lang : service.duration_days ~ ' ' ~ 'Days'|get_lang }}
</li>
<li><em class="fa fa-user"></em> {{ service.owner.name }}</li>
@ -107,8 +115,10 @@
<li><em class="fa fa-align-justify"></em> {{ service.description }}</li>
{% endif %}
</ul>
<p id="n-price" class="lead text-right" style="color: white;"><span
class="label label-primary">{{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }}</span>
<p id="n-price" class="lead text-right" style="color: white;">
<span class="label label-primary">
{{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ price }}
</span>
</p>
<p id="s-price" class="lead text-right"></p>
</div>

Loading…
Cancel
Save