service_sales_report.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /* For license terms, see /license.txt */
  3. /**
  4. * List of pending payments of the Buy Courses plugin.
  5. *
  6. * @package chamilo.plugin.buycourses
  7. */
  8. $cidReset = true;
  9. require_once '../config.php';
  10. api_protect_admin_script();
  11. $plugin = BuyCoursesPlugin::create();
  12. $paypalEnable = $plugin->get('paypal_enable');
  13. $commissionsEnable = $plugin->get('commissions_enable');
  14. $includeServices = $plugin->get('include_services');
  15. $invoicingEnable = $plugin->get('invoicing_enable') === 'true';
  16. $saleStatuses = $plugin->getServiceSaleStatuses();
  17. $paymentTypes = $plugin->getPaymentTypes();
  18. $selectedStatus = isset($_GET['status']) ? $_GET['status'] : BuyCoursesPlugin::SALE_STATUS_PENDING;
  19. $searchTerm = '';
  20. $form = new FormValidator('search', 'get');
  21. if ($form->validate()) {
  22. $selectedStatus = $form->getSubmitValue('status');
  23. $searchTerm = $form->getSubmitValue('user');
  24. if ($selectedStatus === false) {
  25. $selectedStatus = BuyCoursesPlugin::SALE_STATUS_PENDING;
  26. }
  27. }
  28. $form->addSelect('status', $plugin->get_lang('OrderStatus'), $saleStatuses, ['cols-size' => [0, 0, 0]]);
  29. $form->addText('user', get_lang('User'), false, ['cols-size' => [0, 0, 0]]);
  30. $form->addButtonSearch(get_lang('Search'), 'search');
  31. $servicesSales = $plugin->getServiceSale(null, null, $selectedStatus);
  32. $serviceSaleList = [];
  33. foreach ($servicesSales as $sale) {
  34. $serviceSaleList[] = [
  35. 'id' => $sale['id'],
  36. 'reference' => $sale['reference'],
  37. 'status' => $sale['status'],
  38. 'date' => api_convert_and_format_date($sale['buy_date'], DATE_TIME_FORMAT_LONG_24H),
  39. 'currency' => $sale['currency'],
  40. 'price' => $sale['price'],
  41. 'service_type' => $sale['service']['applies_to'],
  42. 'service_name' => $sale['service']['name'],
  43. 'complete_user_name' => $sale['buyer']['name'],
  44. 'invoice' => $sale['invoice'],
  45. 'num_invoice' => $plugin->getNumInvoice($sale['id'], 1),
  46. ];
  47. }
  48. //View
  49. $interbreadcrumb[] = ['url' => '../index.php', 'name' => $plugin->get_lang('plugin_title')];
  50. $templateName = $plugin->get_lang('SalesReport');
  51. $template = new Template($templateName);
  52. if ($paypalEnable == 'true' && $commissionsEnable == 'true') {
  53. $toolbar = Display::toolbarButton(
  54. $plugin->get_lang('PaypalPayoutCommissions'),
  55. api_get_path(WEB_PLUGIN_PATH).'buycourses/src/paypal_payout.php',
  56. 'paypal',
  57. 'primary',
  58. ['title' => $plugin->get_lang('PaypalPayoutCommissions')]
  59. );
  60. $template->assign(
  61. 'actions',
  62. Display::toolbarAction('toolbar', [$toolbar])
  63. );
  64. }
  65. if ($commissionsEnable == 'true') {
  66. $toolbar = Display::toolbarButton(
  67. $plugin->get_lang('PayoutReport'),
  68. api_get_path(WEB_PLUGIN_PATH).'buycourses/src/payout_report.php',
  69. 'money',
  70. 'info',
  71. ['title' => $plugin->get_lang('PayoutReport')]
  72. );
  73. $template->assign(
  74. 'actions',
  75. Display::toolbarAction('toolbar', [$toolbar])
  76. );
  77. }
  78. $template->assign('form', $form->returnForm());
  79. $template->assign('showing_services', true);
  80. $template->assign('services_are_included', $includeServices);
  81. $template->assign('sale_list', $serviceSaleList);
  82. $template->assign('sale_status_cancelled', BuyCoursesPlugin::SERVICE_STATUS_CANCELLED);
  83. $template->assign('sale_status_pending', BuyCoursesPlugin::SERVICE_STATUS_PENDING);
  84. $template->assign('sale_status_completed', BuyCoursesPlugin::SERVICE_STATUS_COMPLETED);
  85. $template->assign('invoicing_enable', $invoicingEnable);
  86. $content = $template->fetch('buycourses/view/service_sales_report.tpl');
  87. $template->assign('content', $content);
  88. $template->display_one_col_template();