adding functionality to export sales report in XLS #3020

pull/3023/head
Alex Aragón 6 years ago
parent 980326b897
commit a9c54a8d80
  1. 2
      plugin/buycourses/lang/brazilian.php
  2. 2
      plugin/buycourses/lang/english.php
  3. 2
      plugin/buycourses/lang/french.php
  4. 3
      plugin/buycourses/lang/spanish.php
  5. 92
      plugin/buycourses/src/buy_course_plugin.class.php
  6. 63
      plugin/buycourses/src/export_report.php
  7. 13
      plugin/buycourses/src/sales_report.php
  8. 1
      plugin/buycourses/view/export_report.tpl

@ -94,3 +94,5 @@ $strings['ByUser'] = "Por usuário";
$strings['PaymentMethod'] = "Método de pagamento";
$strings['SWIFT'] = "Código SWIFT";
$strings['SWIFT_help'] = "Formato padrão de Códigos de Identificação Bancária (BIC) e serve como um identificador exclusivo de um banco ou instituição financeira";
$strings['ExportReport'] = "Exportar Relatório de Vendas";
$strings['SelectDateRange'] = "Selecione uma data de início e uma data de término para o relatório";

@ -189,3 +189,5 @@ $strings['SubscriptionToServiceXSuccessful'] = "Subscription to service %s compl
$strings['ClickHereToFinish'] = "Click here to finish";
$strings['OrderCancelled'] = "Order cancelled";
$strings['use_currency_symbol'] = "Use currency symbol";
$strings['ExportReport'] = "Export Sales Report";
$strings['SelectDateRange'] = "Select a <strong>start date</strong> and <strong>end date</strong> for the report";

@ -161,3 +161,5 @@ $strings['BoughtBy'] = "Acheté par";
$strings['PurchaserUser'] = "Utilisateur acheteur";
$strings['Pending'] = "En attente";
$strings['Names'] = "Nom";
$strings['ExportReport'] = "Rapport des ventes à l'exportation";
$strings['SelectDateRange'] = "Sélectionnez une date de début et une date de fin pour le rapport";

@ -210,3 +210,6 @@ $strings['PurchaseDetailsEnd'] = "Atentamente";
$strings['ProductName'] = "Nombre producto";
$strings['BankAccountIntro'] = "Información cuentas bancarias";
$strings['CurrencyIsNotConfigured'] = "Por favor, confogure una moneda antes de continuar.";
$strings['ExportReport'] = "Exportar reporte de ventas";
$strings['OrderTime'] = "Hora de pedido";
$strings['SelectDateRange'] = "Seleccione una <strong>fecha de inicio</strong> y <strong>fecha de fin</strong> para el reporte";

@ -1278,6 +1278,98 @@ class BuyCoursesPlugin extends Plugin
);
}
/**
* Get the list statuses for sales.
*
* @param null $dateStart
* @param null $dateEnd
* @return array
*/
public function getSaleListReport($dateStart = null, $dateEnd = null)
{
$saleTable = Database::get_main_table(self::TABLE_SALE);
$currencyTable = Database::get_main_table(self::TABLE_CURRENCY);
$userTable = Database::get_main_table(TABLE_MAIN_USER);
$innerJoins = "
INNER JOIN $currencyTable c ON s.currency_id = c.id
INNER JOIN $userTable u ON s.user_id = u.id
";
$list = Database::select(
['c.iso_code', 'u.firstname', 'u.lastname', 'u.email' , 's.*'],
"$saleTable s $innerJoins",
[
'order' => 'id DESC',
]
);
$listExportTemp = [];
$listExport = [];
$textStatus = null;
$paymentTypes = $this->getPaymentTypes();
$productTypes = $this->getProductTypes();
foreach($list as $item){
$statusSaleOrder = $item['status'];
switch ($statusSaleOrder){
case 0:
$textStatus = $this->get_lang('SaleStatusPending');
break;
case 1:
$textStatus = $this->get_lang('SaleStatusCompleted');
break;
case -1:
$textStatus = $this->get_lang('SaleStatusCanceled');
break;
}
$dateFilter = new DateTime($item['date']);
$listExportTemp[] = [
'id' => $item['id'],
'reference' => $item['reference'],
'status' => $textStatus,
'status_filter' => $item['status'],
'date' => $dateFilter->format('Y-m-d'),
'order_time' => $dateFilter->format('H:i:s'),
'price' => $item['iso_code'].' '.$item['price'],
'product_type' => $productTypes[$item['product_type']],
'product_name' => $item['product_name'],
'payment_type' => $paymentTypes[$item['payment_type']],
'complete_user_name' => api_get_person_name($item['firstname'], $item['lastname']),
'email' => $item['email'],
];
}
$listExport[] = [
get_lang('Number'),
$this->get_lang('OrderStatus'),
$this->get_lang('OrderDate'),
$this->get_lang('OrderTime'),
$this->get_lang('PaymentMethod'),
$this->get_lang('SalePrice'),
$this->get_lang('ProductType'),
$this->get_lang('ProductName'),
$this->get_lang('UserName'),
get_lang('Email')
];
//Validation Export
$dateStart = strtotime($dateStart);
$dateEnd = strtotime($dateEnd);
foreach ($listExportTemp as $item){
$dateFilter = strtotime($item['date']);
if(($dateFilter >= $dateStart) && ($dateFilter <= $dateEnd)){
$listExport[] = [
'id' => $item['id'],
'status' => $item['status'],
'date' => $item['date'],
'order_time' => $item['order_time'],
'payment_type' => $item['payment_type'],
'price' => $item['price'],
'product_type' => $item['product_type'],
'product_name' => $item['product_name'],
'complete_user_name' => $item['complete_user_name'],
'email' => $item['email'],
];
}
}
return $listExport;
}
/**
* Get the statuses for sales.
*

@ -0,0 +1,63 @@
<?php
//Initialization
$cidReset = true;
require_once '../config.php';
api_protect_admin_script();
$plugin = BuyCoursesPlugin::create();
$form = new FormValidator('export_validate');
$form->addDatePicker('date_start', get_lang('DateStart'), false);
$form->addDatePicker('date_end', get_lang('DateEnd'), false);
$form->addButton('export_sales',get_lang('ExportExcel'),'check','primary');
$salesStatus = [];
if ($form->validate()) {
$reportValues = $form->getSubmitValues();
$dateStart = $reportValues['date_start'];
$dateEnd = $reportValues['date_end'];
if($dateStart == null || $dateEnd == null){
Display::addFlash(
Display::return_message($plugin->get_lang('SelectDateRange'),'error', false)
);
} else if($dateStart>$dateEnd) {
Display::addFlash(
Display::return_message(get_lang('EndDateCannotBeBeforeTheStartDate'),'error', false)
);
} else {
$salesStatus = $plugin->getSaleListReport($dateStart,$dateEnd);
}
}
if(!empty($salesStatus)){
$archiveFile = 'export_report_sales_'.api_get_local_time();
Export::arrayToXls($salesStatus, $archiveFile);
}
$interbreadcrumb[] = [
'url' => '../index.php', 'name' => $plugin->get_lang('plugin_title')
];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_PLUGIN_PATH).'buycourses/src/sales_report.php',
'name' => $plugin->get_lang('SalesReport')
];
$templateName = $plugin->get_lang('ExportReport');
$toolbar = Display::url(
Display::return_icon('back.png',get_lang('GoBack'),[],ICON_SIZE_MEDIUM),
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/sales_report.php'
);
$template = new Template($templateName);
$template->assign(
'actions',
Display::toolbarAction('toolbar', [$toolbar])
);
$template->assign('form', $form->returnForm());
$content = $template->fetch('buycourses/view/export_report.tpl');
$template->assign('header', $templateName);
$template->assign('content', $content);
$template->display_one_col_template();

@ -124,7 +124,14 @@ foreach ($sales as &$sale) {
$interbreadcrumb[] = ['url' => '../index.php', 'name' => $plugin->get_lang('plugin_title')];
$templateName = $plugin->get_lang('SalesReport');
$template = new Template($templateName);
$toolbar = '';
$toolbar = Display::url(
Display::returnFontAwesomeIcon('file-excel-o').
get_lang('GenerateReport'),
api_get_path(WEB_PLUGIN_PATH).'buycourses/src/export_report.php',
['class' => 'btn btn-primary']
);
if ($paypalEnable === 'true' && $commissionsEnable === 'true') {
$toolbar .= Display::toolbarButton(
$plugin->get_lang('PaypalPayoutCommissions'),
@ -154,6 +161,10 @@ if ($commissionsEnable === 'true') {
Display::toolbarAction('toolbar', [$toolbar])
);
}
$template->assign(
'actions',
Display::toolbarAction('toolbar', [$toolbar])
);
$template->assign('form', $form->returnForm());
$template->assign('selected_sale', $selectedSale);
$template->assign('selected_status', $selectedStatus);

Loading…
Cancel
Save