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. 201
      main/template/default/session/resume_session.tpl
  4. 6
      main/template/default/session/sessions_current.tpl
  5. 6
      plugin/buycourses/lang/english.php
  6. 422
      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. 118
      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. 9
      plugin/buycourses/view/catalog.tpl
  17. 7
      plugin/buycourses/view/configuration.tpl
  18. 14
      plugin/buycourses/view/process.tpl
  19. 22
      plugin/buycourses/view/process_confirm.tpl

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

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

@ -14,35 +14,33 @@
<td>{{ 'GeneralCoach' | get_lang}} :</td> <td>{{ 'GeneralCoach' | get_lang}} :</td>
<td>{{ general_coach.complete_name_with_message_link }}</td> <td>{{ general_coach.complete_name_with_message_link }}</td>
</tr> </tr>
{% if session_category %} {% if session_category %}
<tr> <tr>
<td>{{ 'SessionCategory' | get_lang}} </td> <td>{{ 'SessionCategory' | get_lang}} </td>
<td>{{ session_category }}</td> <td>{{ session_category }}</td>
</tr> </tr>
{% endif %} {% endif %}
{% if session.duration > 0 %} {% if session.duration > 0 %}
<tr> <tr>
<td>{{ 'Duration' | get_lang}} </td> <td>{{ 'Duration' | get_lang}} </td>
<td> <td>
{{ session.duration }} {{ 'Days' | get_lang }} {{ session.duration }} {{ 'Days' | get_lang }}
</td> </td>
</tr> </tr>
{% else %} {% else %}
<tr> <tr>
<td>{{ 'DisplayDates' | get_lang}} </td> <td>{{ 'DisplayDates' | get_lang}} </td>
<td>{{ session_dates.display }}</td> <td>{{ session_dates.display }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ 'AccessDates' | get_lang}} </td> <td>{{ 'AccessDates' | get_lang}} </td>
<td>{{ session_dates.access }}</td> <td>{{ session_dates.access }}</td>
</tr> </tr>
<tr> <tr>
<td>{{ 'CoachDates' | get_lang}} </td> <td>{{ 'CoachDates' | get_lang}} </td>
<td>{{ session_dates.coach }}</td> <td>{{ session_dates.coach }}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>
<td>{{ 'Description' | get_lang}} </td> <td>{{ 'Description' | get_lang}} </td>
<td> <td>
@ -83,7 +81,6 @@
</td> </td>
</tr> </tr>
{% endif %} {% endif %}
{% if url_list %} {% if url_list %}
<tr> <tr>
<td>URL</td> <td>URL</td>
@ -120,107 +117,107 @@
{{ requirements }} {{ requirements }}
{{ dependencies }} {{ dependencies }}
<script> <script>
$(function () { $(function () {
function loadFiles(courseId, sessionId) { function loadFiles(courseId, sessionId) {
return $.get('{{ _p.web_ajax }}session.ajax.php', { return $.get('{{ _p.web_ajax }}session.ajax.php', {
course: courseId, course: courseId,
session: sessionId, session: sessionId,
a: 'get_basic_course_documents_list' a: 'get_basic_course_documents_list'
}); });
} }
function loadForm(courseId, sessionId) { function loadForm(courseId, sessionId) {
return $.get('{{ _p.web_ajax }}session.ajax.php', { return $.get('{{ _p.web_ajax }}session.ajax.php', {
course: courseId, course: courseId,
session: sessionId, session: sessionId,
a: 'get_basic_course_documents_form' a: 'get_basic_course_documents_form'
}); });
} }
var c = 0; var c = 0;
$('.session-upload-file-btn').on('click', function (e) { $('.session-upload-file-btn').on('click', function (e) {
e.preventDefault(); e.preventDefault();
var $self = $(this), var $self = $(this),
$trParent = $self.parents('tr'), $trParent = $self.parents('tr'),
$trContainer = $trParent.next(), $trContainer = $trParent.next(),
courseId = $self.data('course') || 0, courseId = $self.data('course') || 0,
sessionId = $self.data('session') || 0; sessionId = $self.data('session') || 0;
$('.session-upload-file-tr').remove(); $('.session-upload-file-tr').remove();
if (courseId == c) { if (courseId == c) {
c = 0; c = 0;
return; return;
} }
c = courseId; c = courseId;
$trContainer = $('<tr>') $trContainer = $('<tr>')
.addClass('session-upload-file-tr') .addClass('session-upload-file-tr')
.html('<td colspan="4">{{ 'Loading'|get_lang }}</td>') .html('<td colspan="4">{{ 'Loading'|get_lang }}</td>')
.insertAfter($trParent); .insertAfter($trParent);
$.when $.when
.apply($, [loadFiles(courseId, sessionId), loadForm(courseId, sessionId)]) .apply($, [loadFiles(courseId, sessionId), loadForm(courseId, sessionId)])
.then(function (response1, response2) { .then(function (response1, response2) {
var filesCount = 0, var filesCount = 0,
filesUploadedCount = 0; filesUploadedCount = 0;
$trContainer.find('td:first') $trContainer.find('td:first')
.html('<div id="session-' + sessionId + '-docs">' + response1[0] + '</div>' .html('<div id="session-' + sessionId + '-docs">' + response1[0] + '</div>'
+ '<div id="session-' + sessionId + '-form">' + response2[0] + '</div>'); + '<div id="session-' + sessionId + '-form">' + response2[0] + '</div>');
$('#input_file_upload') $('#input_file_upload')
.on('fileuploadadd', function (e, data) { .on('fileuploadadd', function (e, data) {
filesCount += data.files.length; filesCount += data.files.length;
}) })
.on('fileuploaddone', function (e, data) { .on('fileuploaddone', function (e, data) {
filesUploadedCount += data.files.length; filesUploadedCount += data.files.length;
data.context.parent().remove(); data.context.parent().remove();
if (filesUploadedCount < filesCount) { if (filesUploadedCount < filesCount) {
return; return;
} }
$('#session-' + sessionId + '-docs').html('{{ 'Loading'|get_lang }}'); $('#session-' + sessionId + '-docs').html('{{ 'Loading'|get_lang }}');
loadFiles(courseId, sessionId) loadFiles(courseId, sessionId)
.then(function (response) { .then(function (response) {
filesCount = 0; filesCount = 0;
filesUploadedCount = 0; filesUploadedCount = 0;
$('#session-' + sessionId + '-docs').html(response); $('#session-' + sessionId + '-docs').html(response);
}); });
}); });
}); });
}); });
$('#session-list-course').on('click', '.delete_document', function (e) { $('#session-list-course').on('click', '.delete_document', function (e) {
e.preventDefault(); e.preventDefault();
if (!confirm('{{ 'ConfirmYourChoice'|get_lang }}')) { if (!confirm('{{ 'ConfirmYourChoice'|get_lang }}')) {
return; return;
} }
var $self = $(this), var $self = $(this),
courseId = $self.data('course') || 0, courseId = $self.data('course') || 0,
sessionId = $self.data('session') || 0; sessionId = $self.data('session') || 0;
$('#session-' + sessionId + '-docs').html('{{ 'Loading'|get_lang }}'); $('#session-' + sessionId + '-docs').html('{{ 'Loading'|get_lang }}');
$.ajax(this.href) $.ajax(this.href)
.then(function () { .then(function () {
loadFiles(courseId, sessionId) loadFiles(courseId, sessionId)
.then(function (response) { .then(function (response) {
$('#session-' + sessionId + '-docs').html(response); $('#session-' + sessionId + '-docs').html(response);
}) })
}); });
});
}); });
</script> });
</script>
{% endblock %} {% endblock %}

@ -34,7 +34,10 @@
<div class="toolbar"> <div class="toolbar">
<div class="buycourses-price"> <div class="buycourses-price">
<span class="label label-primary label-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> </span>
</div> </div>
</div> </div>
@ -49,7 +52,6 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}

@ -159,7 +159,7 @@ $strings['PleaseSelectTheCorrectInfoToApplyTheService'] = "Please select the cor
$strings['SaleStatusCancelled'] = "Sale cancelled"; $strings['SaleStatusCancelled'] = "Sale cancelled";
$strings['ServiceSaleInfo'] = "Service sale info"; $strings['ServiceSaleInfo'] = "Service sale info";
$strings['ServiceId'] = "Service Id"; $strings['ServiceId'] = "Service Id";
$strings['BoughtBy'] = "BoughtBy"; $strings['BoughtBy'] = "Bought by";
$strings['PurchaserUser'] = "Purchaser user"; $strings['PurchaserUser'] = "Purchaser user";
$strings['Pending'] = "Pending"; $strings['Pending'] = "Pending";
$strings['Names'] = "Names"; $strings['Names'] = "Names";
@ -184,3 +184,7 @@ $strings['PurchaseDetailsIntro'] = "Purchase details";
$strings['PurchaseDetailsEnd'] = "Regards"; $strings['PurchaseDetailsEnd'] = "Regards";
$strings['ProductName'] = "Product name"; $strings['ProductName'] = "Product name";
$strings['BankAccountIntro'] = "Bank Account Info"; $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, date_invoice datetime NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
)"; )";
$res = Database::query($sql); Database::query($sql);
Display::addFlash( Display::addFlash(
Display::return_message( Display::return_message(
@ -296,6 +296,7 @@ class BuyCoursesPlugin extends Plugin
UserManager::create_extra_field($fieldlabel, $fieldtype, $fieldtitle, $fielddefault); UserManager::create_extra_field($fieldlabel, $fieldtype, $fieldtitle, $fielddefault);
header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses'); header('Location: '.api_get_path(WEB_PLUGIN_PATH).'buycourses');
exit;
} }
/** /**
@ -320,7 +321,7 @@ class BuyCoursesPlugin extends Plugin
$html = '<div class="buycourses-price">'; $html = '<div class="buycourses-price">';
if ($item) { if ($item) {
$html .= '<span class="label label-primary label-price"> $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>'; </span>';
$return['verificator'] = true; $return['verificator'] = true;
} else { } 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. * Get the item data.
* *
@ -512,7 +532,7 @@ class BuyCoursesPlugin extends Plugin
ON i.currency_id = c.id ON i.currency_id = c.id
"; ";
return Database::select( $product = Database::select(
['i.*', 'c.iso_code'], ['i.*', 'c.iso_code'],
$fakeItemFrom, $fakeItemFrom,
[ [
@ -525,6 +545,14 @@ class BuyCoursesPlugin extends Plugin
], ],
'first' '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(); $user = $userCourseSubscription->getUser();
$sessionCourseData['coaches'][] = $user->getCompleteName(); $sessionCourseData['coaches'][] = $user->getCompleteName();
} }
$sessionData['courses'][] = $sessionCourseData; $sessionData['courses'][] = $sessionCourseData;
} }
@ -653,10 +680,6 @@ class BuyCoursesPlugin extends Plugin
return []; return [];
} }
$taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to'];
$courseCatalog = []; $courseCatalog = [];
foreach ($courses as $course) { foreach ($courses as $course) {
$item = $this->getItemByProduct( $item = $this->getItemByProduct(
@ -668,25 +691,12 @@ class BuyCoursesPlugin extends Plugin
continue; 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 = [ $courseItem = [
'id' => $course->getId(), 'id' => $course->getId(),
'title' => $course->getTitle(), 'title' => $course->getTitle(),
'code' => $course->getCode(), 'code' => $course->getCode(),
'course_img' => null, 'course_img' => null,
'price' => $price, 'price' => $item['total_price'],
'currency' => $item['iso_code'], 'currency' => $item['iso_code'],
'teachers' => [], 'teachers' => [],
'enrolled' => $this->getUserStatusForCourse(api_get_user_id(), $course), 'enrolled' => $this->getUserStatusForCourse(api_get_user_id(), $course),
@ -705,7 +715,6 @@ class BuyCoursesPlugin extends Plugin
if (file_exists($possiblePath)) { if (file_exists($possiblePath)) {
$courseItem['course_img'] = api_get_path(WEB_COURSE_PATH).$course->getDirectory().'/course-pic.png'; $courseItem['course_img'] = api_get_path(WEB_COURSE_PATH).$course->getDirectory().'/course-pic.png';
} }
$courseCatalog[] = $courseItem; $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(); $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 = [ $courseInfo = [
'id' => $course->getId(), 'id' => $course->getId(),
'title' => $course->getTitle(), 'title' => $course->getTitle(),
@ -774,13 +765,12 @@ class BuyCoursesPlugin extends Plugin
'code' => $course->getCode(), 'code' => $course->getCode(),
'visual_code' => $course->getVisualCode(), 'visual_code' => $course->getVisualCode(),
'teachers' => [], 'teachers' => [],
'price' => number_format($price, $precision), 'price' => $item['total_price_formatted'],
'price_without_tax' => number_format($priceWithoutTax, $precision), 'price_without_tax' => $item['price_formatted'],
'tax_amount' => number_format($taxAmount, $precision), 'tax_amount' => $item['tax_amount_formatted'],
'tax_perc' => $taxPerc, 'tax_perc' => $item['tax_perc_show'],
'tax_name' => $globalParameters['tax_name'], 'tax_name' => $globalParameters['tax_name'],
'tax_enable' => $taxEnable && 'tax_enable' => $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_COURSE),
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_COURSE),
'currency' => $item['iso_code'], 'currency' => $item['iso_code'],
'course_img' => null, 'course_img' => null,
]; ];
@ -830,46 +820,30 @@ class BuyCoursesPlugin extends Plugin
return []; return [];
} }
$sessionDates = SessionManager::parseSessionDates([ $sessionDates = SessionManager::parseSessionDates(
'display_start_date' => $session->getDisplayStartDate(), [
'display_end_date' => $session->getDisplayEndDate(), 'display_start_date' => $session->getDisplayStartDate(),
'access_start_date' => $session->getAccessStartDate(), 'display_end_date' => $session->getDisplayEndDate(),
'access_end_date' => $session->getAccessEndDate(), 'access_start_date' => $session->getAccessStartDate(),
'coach_access_start_date' => $session->getCoachAccessStartDate(), 'access_end_date' => $session->getAccessEndDate(),
'coach_access_end_date' => $session->getCoachAccessEndDate(), '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(); $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 = [ $sessionInfo = [
'id' => $session->getId(), 'id' => $session->getId(),
'name' => $session->getName(), 'name' => $session->getName(),
'description' => $session->getDescription(), 'description' => $session->getDescription(),
'dates' => $sessionDates, 'dates' => $sessionDates,
'courses' => [], 'courses' => [],
'price' => number_format($price, $precision), 'price' => $item['total_price_formatted'],
'price_without_tax' => number_format($priceWithoutTax, $precision), 'price_without_tax' => $item['price_formatted'],
'tax_amount' => number_format($taxAmount, $precision), 'tax_amount' => $item['tax_amount_formatted'],
'tax_perc' => $taxPerc, 'tax_perc' => $item['tax_perc_show'],
'tax_name' => $globalParameters['tax_name'], 'tax_name' => $globalParameters['tax_name'],
'tax_enable' => $taxEnable && 'tax_enable' => $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_SESSION),
($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SESSION),
'currency' => $item['iso_code'], 'currency' => $item['iso_code'],
'image' => null, 'image' => null,
'nbrCourses' => $session->getNbrCourses(), 'nbrCourses' => $session->getNbrCourses(),
@ -887,10 +861,8 @@ class BuyCoursesPlugin extends Plugin
} }
$sessionCourses = $session->getCourses(); $sessionCourses = $session->getCourses();
foreach ($sessionCourses as $sessionCourse) { foreach ($sessionCourses as $sessionCourse) {
$course = $sessionCourse->getCourse(); $course = $sessionCourse->getCourse();
$sessionCourseData = [ $sessionCourseData = [
'title' => $course->getTitle(), 'title' => $course->getTitle(),
'coaches' => [], 'coaches' => [],
@ -914,25 +886,6 @@ class BuyCoursesPlugin extends Plugin
return $sessionInfo; 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. * Register a sale.
* *
@ -980,14 +933,16 @@ class BuyCoursesPlugin extends Plugin
$priceWithoutTax = null; $priceWithoutTax = null;
$taxPerc = null; $taxPerc = null;
$taxAmount = 0; $taxAmount = 0;
$taxEnable = $this->get('tax_enable') === 'true'; $taxEnable = $this->get('tax_enable') === 'true';
$globalParameters = $this->getGlobalParameters(); $globalParameters = $this->getGlobalParameters();
$taxAppliesTo = $globalParameters['tax_applies_to']; $taxAppliesTo = $globalParameters['tax_applies_to'];
if ($taxEnable && if ($taxEnable &&
($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_ALL ||
($taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SESSION && $item['product_type'] == self::PRODUCT_TYPE_SESSION)) ($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)
)
) { ) {
$priceWithoutTax = $item['price']; $priceWithoutTax = $item['price'];
$globalTaxPerc = $globalParameters['global_tax_perc']; $globalTaxPerc = $globalParameters['global_tax_perc'];
@ -1082,34 +1037,34 @@ class BuyCoursesPlugin extends Plugin
*/ */
public function getDataSaleInvoice($saleId, $isService) public function getDataSaleInvoice($saleId, $isService)
{ {
$data = []; $sale = [];
if ($isService) { if ($isService) {
$sale = $this->getServiceSale($saleId); $sale = $this->getServiceSale($saleId);
$data['reference'] = $sale['reference']; $sale['reference'] = $sale['reference'];
$data['product_name'] = $sale['service']['name']; $sale['product_name'] = $sale['service']['name'];
$data['payment_type'] = $sale['payment_type']; $sale['payment_type'] = $sale['payment_type'];
$data['user_id'] = $sale['buyer']['id']; $sale['user_id'] = $sale['buyer']['id'];
$data['price'] = $sale['price']; // $data['price'] = $sale['price'];
$data['price_without_tax'] = $sale['price_without_tax']; //$data['price_without_tax'] = $sale['price_without_tax'];
$data['tax_perc'] = $sale['tax_perc']; //$data['tax_perc'] = $sale['tax_perc'];
$data['tax_amount'] = $sale['tax_amount']; //$data['tax_amount'] = $sale['tax_amount'];
$data['currency_id'] = $sale['currency_id']; //$data['currency_id'] = $sale['currency_id'];
$data['date'] = $sale['buy_date']; $sale['date'] = $sale['buy_date'];
} else { } else {
$sale = $this->getSale($saleId); $sale = $this->getSale($saleId);
$data['reference'] = $sale['reference']; //$data['reference'] = $sale['reference'];
$data['product_name'] = $sale['product_name']; //$data['product_name'] = $sale['product_name'];
$data['payment_type'] = $sale['payment_type']; //$data['payment_type'] = $sale['payment_type'];
$data['user_id'] = $sale['user_id']; //$data['user_id'] = $sale['user_id'];
$data['price'] = $sale['price']; //$data['price'] = $sale['price'];
$data['price_without_tax'] = $sale['price_without_tax']; //$data['price_without_tax'] = $sale['price_without_tax'];
$data['tax_perc'] = $sale['tax_perc']; //$data['tax_perc'] = $sale['tax_perc'];
$data['tax_amount'] = $sale['tax_amount']; //$data['tax_amount'] = $sale['tax_amount'];
$data['currency_id'] = $sale['currency_id']; //$data['currency_id'] = $sale['currency_id'];
$data['date'] = $sale['date']; //$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
*
* @param int $id service id
* *
* @return array * @return array
*/ */
public function getServices($id = null) public function getService($id)
{ {
$servicesTable = Database::get_main_table(self::TABLE_SERVICES); $id = (int) $id;
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$conditions = null;
$showData = "all";
if ($id) { if (empty($id)) {
$conditions = ['WHERE' => ['s.id = ?' => $id]]; return [];
$showData = "first";
} }
$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"; $innerJoins = "INNER JOIN $userTable u ON s.owner_id = u.id";
$currency = $this->getSelectedCurrency(); $currency = $this->getSelectedCurrency();
$isoCode = $currency['iso_code']; $isoCode = $currency['iso_code'];
$return = Database::select( $service = Database::select(
"s.*, '$isoCode' as currency, u.firstname, u.lastname", "s.*, '$isoCode' as currency, u.firstname, u.lastname",
"$servicesTable s $innerJoins", "$servicesTable s $innerJoins",
$conditions, $conditions,
$showData $showData
); );
$services = []; $globalParameters = $this->getGlobalParameters();
if ($id) { $this->setPriceSettings($service, self::TAX_APPLIES_TO_ONLY_SERVICES);
$price = $return['price']; /*$service['tax_perc'] = $return['tax_perc'];
$taxPerc = null; $service['price_with_tax'] = $return['total_price_formatted'];
$priceWithoutTax = $priceWithTax = $return['price']; $service['price_without_tax'] = $return['price_formatted'];
$precision = 2; $service['tax_amount'] = $return['tax_amount_formatted'];
$service['tax_perc_show'] = $return['tax_perc_show'];*/
$taxEnable = $this->get('tax_enable') === 'true'; $service['price_with_tax'] = $service['total_price_formatted'];
$globalParameters = $this->getGlobalParameters(); $service['price_without_tax'] = $service['price_formatted'];
$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;
}
$services['id'] = $return['id']; $service['tax_name'] = $globalParameters['tax_name'];
$services['name'] = $return['name']; $service['tax_enable'] = $this->checkTaxEnabledInProduct(self::TAX_APPLIES_TO_ONLY_SERVICES);
$services['description'] = $return['description']; $service['owner_name'] = api_get_person_name($service['firstname'], $service['lastname']);
$services['price'] = $price; $service['image'] = !empty($service['image']) ? api_get_path(WEB_PLUGIN_PATH).'buycourses/uploads/services/images/'.$service['image'] : null;
$services['tax_perc'] = $return['tax_perc'];
$services['price_with_tax'] = number_format($priceWithTax, $precision); return $service;
$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'];
return $services;
}
/**
* 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) { foreach ($return as $index => $service) {
$services[$index]['id'] = $service['id']; $services[$index] = $this->getService($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'];
} }
return $services; return $services;
@ -2272,10 +2228,10 @@ class BuyCoursesPlugin extends Plugin
} }
if ($hot) { if ($hot) {
$hot = "count(ss.service_id) as hot, "; $hot = 'count(ss.service_id) as hot, ';
$conditions = ['ORDER' => 'hot DESC', 'LIMIT' => '6']; $conditions = ['ORDER' => 'hot DESC', 'LIMIT' => '6'];
$groupBy = "GROUP BY ss.service_id"; $groupBy = 'GROUP BY ss.service_id';
"clean_teacher_files.php"; 'clean_teacher_files.php';
} }
$innerJoins = "INNER JOIN $servicesTable s ON ss.service_id = s.id $groupBy"; $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"; $innerJoins = "INNER JOIN $userTable u ON s.owner_id = u.id";
$currency = $this->getSelectedCurrency();
$isoCode = $currency['iso_code'];
$return = Database::select( $return = Database::select(
"s.*, '$isoCode' as currency, u.firstname, u.lastname", 's.*',
"$servicesTable s $innerJoins", "$servicesTable s $innerJoins",
['WHERE' => $whereConditions] ['WHERE' => $whereConditions]
); );
$services = []; $services = [];
foreach ($return as $index => $service) { foreach ($return as $index => $service) {
$price = $service['price']; $services[$index] = $this->getService($service['id']);
$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'];
} }
return $services; return $services;
@ -2513,7 +2435,7 @@ class BuyCoursesPlugin extends Plugin
} }
$userId = api_get_user_id(); $userId = api_get_user_id();
$service = $this->getServices($serviceId); $service = $this->getService($serviceId);
if (empty($service)) { if (empty($service)) {
return false; 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. * Get the path.
* *

@ -20,11 +20,7 @@ if (api_is_anonymous()) {
} }
$plugin = BuyCoursesPlugin::create(); $plugin = BuyCoursesPlugin::create();
$paypalEnable = $plugin->get('paypal_enable');
$commissionsEnable = $plugin->get('commissions_enable');
$culqiEnable = $plugin->get('culqi_enable'); $culqiEnable = $plugin->get('culqi_enable');
$action = isset($_GET['a']) ? $_GET['a'] : null; $action = isset($_GET['a']) ? $_GET['a'] : null;
$em = Database::getManager(); $em = Database::getManager();
@ -50,11 +46,11 @@ switch ($action) {
break; break;
} }
$saleId = isset($_POST['id']) ? intval($_POST['id']) : ''; $saleId = isset($_POST['id']) ? (int) $_POST['id'] : '';
$sale = $plugin->getSale($saleId); $sale = $plugin->getSale($saleId);
$productType = ($sale['product_type'] == 1) ? get_lang('Course') : get_lang('Session'); $productType = $sale['product_type'] == 1 ? get_lang('Course') : get_lang('Session');
$paymentType = ($sale['payment_type'] == 1) ? 'Paypal' : $plugin->get_lang('BankTransfer'); $paymentType = $sale['payment_type'] == 1 ? 'Paypal' : $plugin->get_lang('BankTransfer');
$productInfo = ($sale['product_type'] == 1) $productInfo = $sale['product_type'] == 1
? api_get_course_info_by_id($sale['product_id']) ? api_get_course_info_by_id($sale['product_id'])
: api_get_session_info($sale['product_id']); : api_get_session_info($sale['product_id']);
$currency = $plugin->getSelectedCurrency(); $currency = $plugin->getSelectedCurrency();
@ -72,7 +68,7 @@ switch ($action) {
$html .= '<div class="row">'; $html .= '<div class="row">';
$html .= '<div class="col-sm-6 col-md-6">'; $html .= '<div class="col-sm-6 col-md-6">';
$html .= '<ul>'; $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('CurrencyType').':</b> '.$currency['iso_code'].'</li>';
$html .= '<li><b>'.$plugin->get_lang('ProductType').':</b> '.$productType.'</li>'; $html .= '<li><b>'.$plugin->get_lang('ProductType').':</b> '.$productType.'</li>';
$html .= '<li><b>'.$plugin->get_lang('OrderDate').':</b> '. $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('ServiceName')}:</b> {$serviceSale['service']['name']}</li> ";
$html .= "<li><b>{$plugin->get_lang('Description')}:</b> {$serviceSale['service']['description']}</li> "; $html .= "<li><b>{$plugin->get_lang('Description')}:</b> {$serviceSale['service']['description']}</li> ";
$nodeType = $serviceSale['node_type']; $nodeType = $serviceSale['node_type'];
$nodeName = ""; $nodeName = '';
$nodeTitle = "";
if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_USER) { if ($nodeType == BuyCoursesPlugin::SERVICE_TYPE_USER) {
$nodeType = get_lang('User'); $nodeType = get_lang('User');
/** @var User $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('AppliesTo')}:</b> $nodeType</li> ";
$html .= "<li><b>{$plugin->get_lang('Price')}:</b> {$serviceSale['service']['price']} {$serviceSale['currency']}</li> "; // $html .= "<li><b>{$plugin->get_lang('Price')}:</b> {$serviceSale['service']['price']} {$serviceSale['currency']}</li> ";
$duration = $serviceSale['service']['duration_days'].' '.$plugin->get_lang('Days'); //$duration = $serviceSale['service']['duration_days'].' '.$plugin->get_lang('Days');
$html .= "</ul>"; $html .= "</ul>";
$html .= "<legend>{$plugin->get_lang('SaleInfo')}</legend>"; $html .= "<legend>{$plugin->get_lang('SaleInfo')}</legend>";
$html .= "<ul>"; $html .= "<ul>";
$html .= "<li><b>{$plugin->get_lang('BoughtBy')}:</b> {$serviceSale['buyer']['name']}</li> "; $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('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); $orderDate = api_format_date($serviceSale['buy_date'], DATE_FORMAT_LONG);
$html .= "<li><b>{$plugin->get_lang('OrderDate')}:</b> $orderDate</li> "; $html .= "<li><b>{$plugin->get_lang('OrderDate')}:</b> $orderDate</li> ";
$paymentType = $serviceSale['payment_type']; $paymentType = $serviceSale['payment_type'];
@ -525,9 +529,9 @@ switch ($action) {
} }
} }
$html .= "<li><b>{$plugin->get_lang('PaymentMethod')}:</b> $paymentType</li> "; $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']; $status = $serviceSale['status'];
$buttons = ""; $buttons = '';
if ($status == BuyCoursesPlugin::SERVICE_STATUS_COMPLETED) { if ($status == BuyCoursesPlugin::SERVICE_STATUS_COMPLETED) {
$status = $plugin->get_lang('Active'); $status = $plugin->get_lang('Active');
} else { } else {

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

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

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

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

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

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

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

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

@ -85,7 +85,7 @@
</td> </td>
{% endif %} {% endif %}
<td class="text-right"> <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"> 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> </a>
@ -146,9 +146,10 @@
</td> </td>
{% endif %} {% endif %}
<td class="text-right"> <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"> 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> </a>
</td> </td>
</tr> </tr>

@ -21,13 +21,13 @@
src="{{ course.course_img ? course.course_img : 'session_default.png'|icon() }}"> src="{{ course.course_img ? course.course_img : 'session_default.png'|icon() }}">
</a> </a>
{% if course.tax_enable %} {% if course.tax_enable %}
<div class="price-details-tax"> <div class="price-details-tax">
{{ 'Price'|get_plugin_lang('BuyCoursesPlugin')}} : {{ 'Price'|get_plugin_lang('BuyCoursesPlugin')}} :
{{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.price_without_tax }} {{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.price_without_tax }}
<br> <br>
{{ course.tax_name }} ({{ course.tax_perc }}%): {{ course.tax_name }} ({{ course.tax_perc }}%):
{{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.tax_amount }} {{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.tax_amount }}
</div> </div>
{% endif %} {% endif %}
<div class="price"> <div class="price">
{{ 'Total'|get_plugin_lang('BuyCoursesPlugin')}} : {{ 'Total'|get_plugin_lang('BuyCoursesPlugin')}} :

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

Loading…
Cancel
Save