diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 5579b0c21a..3fd65c3de8 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -3374,9 +3374,9 @@ class SessionManager } return $sessions; - } else { - return false; } + + return false; } /** diff --git a/main/template/default/session/about.tpl b/main/template/default/session/about.tpl index 146d0ccaf8..7f268e9075 100644 --- a/main/template/default/session/about.tpl +++ b/main/template/default/session/about.tpl @@ -136,7 +136,6 @@ {% endif %} -
{% if courses|length > 1 %} @@ -153,7 +152,6 @@
{% if course_data.tags %}
-
{% endfor %} diff --git a/plugin/buycourses/lang/english.php b/plugin/buycourses/lang/english.php index bdfd7de54a..66145fcb14 100644 --- a/plugin/buycourses/lang/english.php +++ b/plugin/buycourses/lang/english.php @@ -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"; diff --git a/plugin/buycourses/src/buy_course_plugin.class.php b/plugin/buycourses/src/buy_course_plugin.class.php index 51267312dd..d0b3b4a2df 100644 --- a/plugin/buycourses/src/buy_course_plugin.class.php +++ b/plugin/buycourses/src/buy_course_plugin.class.php @@ -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 = '
'; if ($item) { $html .= ' - '.$item['iso_code'].' '.$item['price'].' + '.$item['iso_code'].' '.$item['total_price_formatted'].' '; $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([ - '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; + $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(), + ] + ); - $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_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_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) + ) ) { $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']; - - return $services; - } + $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 $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. * diff --git a/plugin/buycourses/src/buycourses.ajax.php b/plugin/buycourses/src/buycourses.ajax.php index 4efc20bcee..c8c2677633 100644 --- a/plugin/buycourses/src/buycourses.ajax.php +++ b/plugin/buycourses/src/buycourses.ajax.php @@ -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 .= '
'; $html .= '
'; $html .= '
    '; - $html .= '
  • '.$plugin->get_lang('OrderPrice').': '.$sale['price'].'
  • '; + $html .= '
  • '.$plugin->get_lang('OrderPrice').': '.$sale['total_price'].'
  • '; $html .= '
  • '.$plugin->get_lang('CurrencyType').': '.$currency['iso_code'].'
  • '; $html .= '
  • '.$plugin->get_lang('ProductType').': '.$productType.'
  • '; $html .= '
  • '.$plugin->get_lang('OrderDate').': '. @@ -472,8 +468,7 @@ switch ($action) { $html .= "
  • {$plugin->get_lang('ServiceName')}: {$serviceSale['service']['name']}
  • "; $html .= "
  • {$plugin->get_lang('Description')}: {$serviceSale['service']['description']}
  • "; $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 .= "
  • {$plugin->get_lang('AppliesTo')}: $nodeType
  • "; - $html .= "
  • {$plugin->get_lang('Price')}: {$serviceSale['service']['price']} {$serviceSale['currency']}
  • "; - $duration = $serviceSale['service']['duration_days'].' '.$plugin->get_lang('Days'); + //$html .= "
  • {$plugin->get_lang('AppliesTo')}: $nodeType
  • "; + // $html .= "
  • {$plugin->get_lang('Price')}: {$serviceSale['service']['price']} {$serviceSale['currency']}
  • "; + //$duration = $serviceSale['service']['duration_days'].' '.$plugin->get_lang('Days'); $html .= "
"; $html .= "{$plugin->get_lang('SaleInfo')}"; $html .= "
    "; $html .= "
  • {$plugin->get_lang('BoughtBy')}: {$serviceSale['buyer']['name']}
  • "; $html .= "
  • {$plugin->get_lang('PurchaserUser')}: {$serviceSale['buyer']['username']}
  • "; - $html .= "
  • {$plugin->get_lang('SalePrice')}: {$serviceSale['price']} {$serviceSale['currency']}
  • "; + + $taxEnable = $plugin->get('tax_enable') === 'true'; + if ($taxEnable) { + //$html .= "
  • {$plugin->get_lang('Price')}: {$serviceSale['price_without_tax']} {$serviceSale['currency']}
  • "; + //$html .= "
  • {$plugin->get_lang('Price')}: {$serviceSale['tax_amount']} {$serviceSale['currency']}
  • "; + } + $html .= "
  • {$plugin->get_lang('Total')}: {$serviceSale['price']} {$serviceSale['currency']}
  • "; + + + //$html .= "
  • {$plugin->get_lang('SalePrice')}: {$serviceSale['price_without_tax']} {$serviceSale['currency']}
  • "; $orderDate = api_format_date($serviceSale['buy_date'], DATE_FORMAT_LONG); $html .= "
  • {$plugin->get_lang('OrderDate')}: $orderDate
  • "; $paymentType = $serviceSale['payment_type']; @@ -525,9 +529,9 @@ switch ($action) { } } $html .= "
  • {$plugin->get_lang('PaymentMethod')}: $paymentType
  • "; - $html .= "
  • $nodeType: $nodeName
  • "; + //$html .= "
  • $nodeType: $nodeName
  • "; $status = $serviceSale['status']; - $buttons = ""; + $buttons = ''; if ($status == BuyCoursesPlugin::SERVICE_STATUS_COMPLETED) { $status = $plugin->get_lang('Active'); } else { diff --git a/plugin/buycourses/src/configure_course.php b/plugin/buycourses/src/configure_course.php index e0b47d47cf..c3e98d4dca 100644 --- a/plugin/buycourses/src/configure_course.php +++ b/plugin/buycourses/src/configure_course.php @@ -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 ).' -
    +
' ); - $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[] = [ diff --git a/plugin/buycourses/src/invoice.php b/plugin/buycourses/src/invoice.php index f26475e573..060bd1fa90 100644 --- a/plugin/buycourses/src/invoice.php +++ b/plugin/buycourses/src/invoice.php @@ -1,5 +1,6 @@ '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; diff --git a/plugin/buycourses/src/process.php b/plugin/buycourses/src/process.php index 415f4977c3..e8ab2996af 100644 --- a/plugin/buycourses/src/process.php +++ b/plugin/buycourses/src/process.php @@ -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('
'); $form->addHtml('
'); } 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); diff --git a/plugin/buycourses/src/service_information.php b/plugin/buycourses/src/service_information.php index c88be63ab0..f8f2f65222 100644 --- a/plugin/buycourses/src/service_information.php +++ b/plugin/buycourses/src/service_information.php @@ -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); diff --git a/plugin/buycourses/src/service_process.php b/plugin/buycourses/src/service_process.php index f53fc6f9cc..e22c8d5de0 100644 --- a/plugin/buycourses/src/service_process.php +++ b/plugin/buycourses/src/service_process.php @@ -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); -$form->addHtml( - Display::return_message( - $plugin->get_lang('PleaseSelectTheCorrectInfoToApplyTheService'), - 'info' - ) -); + +$infoRequired = false; +if ($typeUser || $typeCourse || $typeSession || $typeFinalLp) { + $infoRequired = true; + $form->addHtml( + Display::return_message( + $plugin->get_lang('PleaseSelectTheCorrectInfoToApplyTheService'), + 'info' + ) + ); +} + $selectOptions = [ 0 => get_lang('None'), ]; @@ -195,7 +167,7 @@ if ($typeUser) { ->getRepository('ChamiloCourseBundle:CLp') ->findBy(['sessionId' => $session->getSession()->getId()]); - //Here check all the lpItems + // Here check all the lpItems foreach ($thisLpList as $lp) { $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()]); - //Here check all the lpItems + // 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); diff --git a/plugin/buycourses/src/service_process_confirm.php b/plugin/buycourses/src/service_process_confirm.php index d91e08580d..56a5f7c710 100644 --- a/plugin/buycourses/src/service_process_confirm.php +++ b/plugin/buycourses/src/service_process_confirm.php @@ -1,6 +1,8 @@ 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 diff --git a/plugin/buycourses/src/service_sales_report.php b/plugin/buycourses/src/service_sales_report.php index 64ae3135c3..f527de1f56 100644 --- a/plugin/buycourses/src/service_sales_report.php +++ b/plugin/buycourses/src/service_sales_report.php @@ -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; } diff --git a/plugin/buycourses/src/services_edit.php b/plugin/buycourses/src/services_edit.php index f955918a88..2c1d39facb 100644 --- a/plugin/buycourses/src/services_edit.php +++ b/plugin/buycourses/src/services_edit.php @@ -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'], diff --git a/plugin/buycourses/view/catalog.tpl b/plugin/buycourses/view/catalog.tpl index cc757ae63f..c6a4de8b04 100644 --- a/plugin/buycourses/view/catalog.tpl +++ b/plugin/buycourses/view/catalog.tpl @@ -135,9 +135,10 @@
- {{ service.name }} + + {{ service.name }}

@@ -176,7 +177,7 @@

- {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }} + {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.total_price_formatted }}

diff --git a/plugin/buycourses/view/configuration.tpl b/plugin/buycourses/view/configuration.tpl index 3f4828ffcd..5e3ccaee64 100644 --- a/plugin/buycourses/view/configuration.tpl +++ b/plugin/buycourses/view/configuration.tpl @@ -85,7 +85,7 @@ {% endif %} - {{ 'Configure'|get_lang }} @@ -146,9 +146,10 @@ {% endif %} - - {{ 'Configure'|get_lang }} + + {{ 'Configure'|get_lang }} diff --git a/plugin/buycourses/view/process.tpl b/plugin/buycourses/view/process.tpl index 175849158c..06181d89b7 100644 --- a/plugin/buycourses/view/process.tpl +++ b/plugin/buycourses/view/process.tpl @@ -21,13 +21,13 @@ src="{{ course.course_img ? course.course_img : 'session_default.png'|icon() }}"> {% if course.tax_enable %} -
- {{ 'Price'|get_plugin_lang('BuyCoursesPlugin')}} : - {{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.price_without_tax }} -
- {{ course.tax_name }} ({{ course.tax_perc }}%): - {{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.tax_amount }} -
+
+ {{ 'Price'|get_plugin_lang('BuyCoursesPlugin')}} : + {{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.price_without_tax }} +
+ {{ course.tax_name }} ({{ course.tax_perc }}%): + {{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.tax_amount }} +
{% endif %}
{{ 'Total'|get_plugin_lang('BuyCoursesPlugin')}} : diff --git a/plugin/buycourses/view/process_confirm.tpl b/plugin/buycourses/view/process_confirm.tpl index 8d4598ef2f..40d73e1853 100644 --- a/plugin/buycourses/view/process_confirm.tpl +++ b/plugin/buycourses/view/process_confirm.tpl @@ -26,7 +26,10 @@ {% endfor %}

- {{ course.currency == 'BRL' ? 'R$' : course.currency }} {{ course.price }} + + {{ course.currency == 'BRL' ? 'R$' : course.currency }} + {{ course.price }} +

@@ -57,7 +60,10 @@ {% endfor %}

- {{ session.currency == 'BRL' ? 'R$' : session.currency }} {{ session.price }} + + {{ session.currency == 'BRL' ? 'R$' : session.currency }} + {{ session.price }} +

@@ -98,8 +104,10 @@ {{ 'AppliesTo'|get_plugin_lang('BuyCoursesPlugin') }} {{ 'TemplateTitleCertificate'|get_lang }} {% endif %} -
  • {{ 'Price'|get_plugin_lang('BuyCoursesPlugin') }} - : {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }} +
  • + + {{ '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.owner.name }}
  • @@ -107,8 +115,10 @@
  • {{ service.description }}
  • {% endif %} -

    {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ service.price }} +

    + + {{ service.currency == 'BRL' ? 'R$' : service.currency }} {{ price }} +