Browse Source

Fix variable declaration #2615

Nosolored 6 years ago
parent
commit
875dedc0f7

+ 1 - 0
plugin/buycourses/lang/english.php

@@ -49,6 +49,7 @@ $strings['PayoutStatusCompleted'] = "Payment completed";
 $strings['PayoutsTotalPending'] = "Pending payments:";
 $strings['PayoutsTotalCanceled'] = "Cancelled payments:";
 $strings['PayoutsTotalCompleted'] = "Completed payments:";
+$strings['Total'] = "Total";
 $strings['TotalAmount'] = "Total amount:";
 $strings['CourseListOnSale'] = "List of courses on sale";
 $strings['AvailableCourses'] = "Available Courses";

+ 1 - 0
plugin/buycourses/lang/spanish.php

@@ -49,6 +49,7 @@ $strings['PayoutStatusCompleted'] = "Pago completado";
 $strings['PayoutsTotalPending'] = "Pagos pendientes:";
 $strings['PayoutsTotalCanceled'] = "Pagos cancelados:";
 $strings['PayoutsTotalCompleted'] = "Pagos completados:";
+$strings['Total'] = "Total";
 $strings['TotalAmount'] = "Monto total:";
 $strings['CourseListOnSale'] = "Lista de cursos a la venta";
 $strings['AvailableCourses'] = "Cursos disponibles";

+ 10 - 4
plugin/buycourses/src/buy_course_plugin.class.php

@@ -130,6 +130,7 @@ class BuyCoursesPlugin extends Plugin
             self::TABLE_SERVICES,
             self::TABLE_SERVICES_SALE,
             self::TABLE_GLOBAL_CONFIG,
+            self::TABLE_INVOICE,
         ];
         $em = Database::getManager();
         $cn = $em->getConnection();
@@ -161,6 +162,7 @@ class BuyCoursesPlugin extends Plugin
             self::TABLE_SERVICES_SALE,
             self::TABLE_SERVICES,
             self::TABLE_GLOBAL_CONFIG,
+            self::TABLE_INVOICE,
         ];
 
         foreach ($tablesToBeDeleted as $tableToBeDeleted) {
@@ -743,6 +745,7 @@ class BuyCoursesPlugin extends Plugin
             );
 
         $price = $item['price'];
+        $taxAmount = 0;
         $taxPerc = null;
         $priceWithoutTax = $item['price'];
         $precision = 2;
@@ -833,6 +836,7 @@ class BuyCoursesPlugin extends Plugin
         ]);
 
         $price = $item['price'];
+        $taxAmount = 0;
         $taxPerc = null;
         $priceWithoutTax = $item['price'];
         $precision = 2;
@@ -971,14 +975,15 @@ class BuyCoursesPlugin extends Plugin
         $price = $item['price'];
         $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 == TAX_APPLIES_TO_ONLY_COURSE && $item['product_type'] == self::PRODUCT_TYPE_COURSE) ||
-            ($taxAppliesTo == 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'];
             $globalTaxPerc = $globalParameters['global_tax_perc'];
@@ -1281,9 +1286,10 @@ class BuyCoursesPlugin extends Plugin
 
         // Record invoice in the sales table
         $table = Database::get_main_table(self::TABLE_SALE);
-        if (empty($isService)) {
+        if (!empty($isService)) {
             $table = Database::get_main_table(self::TABLE_SERVICES_SALE);
         }
+
         Database::update(
             $table,
             ['invoice' => 1],
@@ -2518,7 +2524,7 @@ class BuyCoursesPlugin extends Plugin
         $globalParameters = $this->getGlobalParameters();
         $taxAppliesTo = $globalParameters['tax_applies_to'];
         if ($taxEnable &&
-            ($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == TAX_APPLIES_TO_ONLY_SERVICES)
+            ($taxAppliesTo == self::TAX_APPLIES_TO_ALL || $taxAppliesTo == self::TAX_APPLIES_TO_ONLY_SERVICES)
         ) {
             $priceWithoutTax = $service['price'];
             $globalTaxPerc = $globalParameters['global_tax_perc'];

+ 41 - 21
plugin/buycourses/src/invoice.php

@@ -29,6 +29,13 @@ $buyer = api_get_user_info($infoSale['user_id']);
 $extraUserInfoData = UserManager::get_extra_user_data($infoSale['user_id']);
 $infoInvoice = $plugin->getDataInvoice($saleId, $isService);
 
+$taxAppliesTo = $globalParameters['tax_applies_to'];
+$taxEnable = $plugin->get('tax_enable') === 'true' &&
+    ($taxAppliesTo == BuyCoursesPlugin::TAX_APPLIES_TO_ALL ||
+    ($taxAppliesTo == BuyCoursesPlugin::TAX_APPLIES_TO_ONLY_COURSE && !$isService) ||
+    ($taxAppliesTo == BuyCoursesPlugin::TAX_APPLIES_TO_ONLY_SESSION && $isService)
+);
+
 $htmlText = '<html>';
 $htmlText .= '<link rel="stylesheet" type="text/css" href="plugin.css">';
 $htmlText .= '<link rel="stylesheet" type="text/css" href="'.api_get_path(WEB_CSS_PATH).'base.css">';
@@ -68,39 +75,52 @@ $htmlText .= '</table>';
 
 $htmlText .= '<br><br>';
 $htmlText .= '<p>';
-$htmlText .= $plugin->get_lang('InvoiceDate').': <span style="font-weight:bold;">'.api_format_date($infoInvoice['date_invoice'], DATE_TIME_FORMAT_LONG_24H).'</span><br>';
-$htmlText .= $plugin->get_lang('InvoiceNumber').': <span style="font-weight:bold;">'.$infoInvoice['serie'].$infoInvoice['year'].'/'.$infoInvoice['num_invoice'].'</span><br>';
+$htmlText .= $plugin->get_lang('InvoiceDate').': <span style="font-weight:bold;">'
+    .api_convert_and_format_date($infoInvoice['date_invoice'], DATE_TIME_FORMAT_LONG_24H).'</span><br>';
+$htmlText .= $plugin->get_lang('InvoiceNumber').': <span style="font-weight:bold;">'
+    .$infoInvoice['serie'].$infoInvoice['year'].'/'.$infoInvoice['num_invoice'].'</span><br>';
 $htmlText .= '</p><br><br>';
 
 $header = [
-        $plugin->get_lang('OrderReference'),
-        $plugin->get_lang('ProductType'),
-        $plugin->get_lang('Price'),
-        $globalParameters['tax_name'],
-        $plugin->get_lang('TotalPayout'),
+    $plugin->get_lang('OrderReference'),
+    $plugin->get_lang('ProductType'),
+    $plugin->get_lang('Price'),
 ];
 
+if ($taxEnable) {
+    $header[] = $globalParameters['tax_name'];
+    $header[] = $plugin->get_lang('Total');
+}
+
 $data = [];
 $row = [
     $infoSale['reference'],
     $infoSale['product_name'],
-    $plugin->getCurrency($infoSale['currency_id'])['iso_code'].
-        ' '.$infoSale['price_without_tax'],
-    $plugin->getCurrency($infoSale['currency_id'])['iso_code'].
-        ' '.$infoSale['tax_amount'].
-        ' ('.(int) $infoSale['tax_perc'].'%)',
-    $plugin->getCurrency($infoSale['currency_id'])['iso_code'].
-        ' '.$infoSale['price'],
 ];
+if ($taxEnable) {
+    $row[] = $plugin->getCurrency($infoSale['currency_id'])['iso_code'].' '.$infoSale['price_without_tax'];
+    $row[] = $plugin->getCurrency($infoSale['currency_id'])['iso_code'].
+        ' '.$infoSale['tax_amount'].
+        ' ('.(int) $infoSale['tax_perc'].'%)';
+}
+$row[] = $plugin->getCurrency($infoSale['currency_id'])['iso_code'].' '.$infoSale['price'];
 $data[] = $row;
 
-$row = [
-    '',
-    '',
-    '',
-    $plugin->get_lang('TotalPayout'),
-    $plugin->getCurrency($infoSale['currency_id'])['iso_code'].' '.$infoSale['price'],
-];
+if ($taxEnable) {
+    $row = [
+        '',
+        '',
+        '',
+        $plugin->get_lang('TotalPayout'),
+        $plugin->getCurrency($infoSale['currency_id'])['iso_code'].' '.$infoSale['price'],
+    ];
+} else {
+    $row = [
+        '',
+        $plugin->get_lang('TotalPayout'),
+        $plugin->getCurrency($infoSale['currency_id'])['iso_code'].' '.$infoSale['price'],
+    ];
+}
 $data[] = $row;
 $attr = [];
 $attr['class'] = "table data_table";

+ 1 - 1
plugin/buycourses/src/sales_report.php

@@ -121,7 +121,7 @@ foreach ($sales as $sale) {
         'id' => $sale['id'],
         'reference' => $sale['reference'],
         'status' => $sale['status'],
-        'date' => api_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H),
+        'date' => api_convert_and_format_date($sale['date'], DATE_TIME_FORMAT_LONG_24H),
         'currency' => $sale['iso_code'],
         'price' => $sale['price'],
         'product_name' => $sale['product_name'],

+ 1 - 1
plugin/buycourses/src/service_sales_report.php

@@ -48,7 +48,7 @@ foreach ($servicesSales as $sale) {
         'id' => $sale['id'],
         'reference' => $sale['reference'],
         'status' => $sale['status'],
-        'date' => api_format_date($sale['buy_date'], DATE_TIME_FORMAT_LONG_24H),
+        'date' => api_convert_and_format_date($sale['buy_date'], DATE_TIME_FORMAT_LONG_24H),
         'currency' => $sale['currency'],
         'price' => $sale['price'],
         'service_type' => $sale['service']['applies_to'],