Merge pull request #851 from AngelFQC/7768
Add filter to sale report, register sale datetime, register beneficiaries - refs #77681.10.x
commit
0ed8c25f0f
@ -1,36 +0,0 @@ |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* JS library for the Chamilo buy-courses plugin |
||||
* @package chamilo.plugin.buycourses |
||||
*/ |
||||
$(document).ready(function () { |
||||
$(".bc-button-save").click(function () { |
||||
var currentRow = $(this).closest("tr"); |
||||
var courseOrSessionObject = { |
||||
tab: "save_mod", |
||||
visible: currentRow.find("[name='visible']").is(':checked') ? 1 : 0, |
||||
price: currentRow.find("[name='price']").val() |
||||
}; |
||||
|
||||
var itemField = currentRow.data('type') + '_id'; |
||||
|
||||
courseOrSessionObject[itemField] = currentRow.data('item') || 0; |
||||
|
||||
$.post( |
||||
"function.php", |
||||
courseOrSessionObject, |
||||
function (data) { |
||||
if (!data.status) { |
||||
return; |
||||
} |
||||
|
||||
currentRow.addClass('success'); |
||||
|
||||
window.setTimeout(function () { |
||||
currentRow.removeClass('success'); |
||||
}, 3000); |
||||
}, |
||||
"json" |
||||
); |
||||
}); |
||||
}); |
@ -0,0 +1,220 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
/** |
||||
* Configuration script for the Buy Courses plugin |
||||
* @package chamilo.plugin.buycourses |
||||
*/ |
||||
/** |
||||
* Initialization |
||||
*/ |
||||
$cidReset = true; |
||||
|
||||
require_once '../config.php'; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
if (!isset($_REQUEST['t'], $_REQUEST['i'])) { |
||||
die; |
||||
} |
||||
|
||||
$plugin = BuyCoursesPlugin::create(); |
||||
|
||||
|
||||
$includeSession = $plugin->get('include_sessions') === 'true'; |
||||
|
||||
$editingCourse = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_COURSE; |
||||
$editingSession = intval($_REQUEST['t']) === BuyCoursesPlugin::PRODUCT_TYPE_SESSION; |
||||
|
||||
$entityManager = Database::getManager(); |
||||
$userRepo = $entityManager->getRepository('ChamiloUserBundle:User'); |
||||
|
||||
$currency = $plugin->getSelectedCurrency(); |
||||
$currencyIso = null; |
||||
|
||||
if ($editingCourse) { |
||||
$course = $entityManager->find('ChamiloCoreBundle:Course', $_REQUEST['i']); |
||||
|
||||
if (!$course) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
if (!$plugin->isValidCourse($course)) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$courseItem = $plugin->getCourseForConfiguration($course, $currency); |
||||
$defaultBeneficiaries = []; |
||||
$teachers = $course->getTeachers(); |
||||
$teachersOptions = []; |
||||
|
||||
foreach ($teachers as $courseTeacher) { |
||||
$teacher = $courseTeacher->getUser(); |
||||
|
||||
$teachersOptions[] = [ |
||||
'text' => $teacher->getCompleteName(), |
||||
'value' => $teacher->getId() |
||||
]; |
||||
|
||||
$defaultBeneficiaries[] = $teacher->getId(); |
||||
} |
||||
|
||||
$currentBeneficiaries = $plugin->getItemBeneficiaries($courseItem['item_id']); |
||||
|
||||
if (!empty($currentBeneficiaries)) { |
||||
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); |
||||
} |
||||
|
||||
$currencyIso = $courseItem['currency']; |
||||
$formDefaults = [ |
||||
'product_type' => get_lang('Course'), |
||||
'i' => $courseItem['course_id'], |
||||
't' => BuyCoursesPlugin::PRODUCT_TYPE_COURSE, |
||||
'name' => $courseItem['course_title'], |
||||
'visible' => $courseItem['visible'], |
||||
'price' => $courseItem['price'], |
||||
'beneficiaries' => $defaultBeneficiaries |
||||
]; |
||||
} elseif ($editingSession) { |
||||
if (!$includeSession) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$session = $entityManager->find('ChamiloCoreBundle:Session', $_REQUEST['i']); |
||||
|
||||
if (!$session) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$sessionItem = $plugin->getSessionForConfiguration($session, $currency); |
||||
$generalCoach = $session->getGeneralCoach(); |
||||
$generalCoachOption = [ |
||||
'text' => $generalCoach->getCompleteName(), |
||||
'value' => $generalCoach->getId() |
||||
]; |
||||
$defaultBeneficiaries = [ |
||||
$generalCoach->getId() |
||||
]; |
||||
$courseCoachesOptions = []; |
||||
$sessionCourses = $session->getCourses(); |
||||
|
||||
foreach ($sessionCourses as $sessionCourse) { |
||||
$courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse->getCourse()); |
||||
|
||||
foreach ($courseCoaches as $courseCoach) { |
||||
if ($generalCoach->getId() === $courseCoach->getId()) { |
||||
continue; |
||||
} |
||||
|
||||
$courseCoachesOptions[] = [ |
||||
'text' => $courseCoach->getCompleteName(), |
||||
'value' => $courseCoach->getId() |
||||
]; |
||||
$defaultBeneficiaries[] = $courseCoach->getId(); |
||||
} |
||||
} |
||||
|
||||
$currentBeneficiaries = $plugin->getItemBeneficiaries($sessionItem['item_id']); |
||||
|
||||
if (!empty($currentBeneficiaries)) { |
||||
$defaultBeneficiaries = array_column($currentBeneficiaries, 'user_id'); |
||||
} |
||||
|
||||
$currencyIso = $sessionItem['currency']; |
||||
$formDefaults = [ |
||||
'product_type' => get_lang('Session'), |
||||
'i' => $session->getId(), |
||||
't' => BuyCoursesPlugin::PRODUCT_TYPE_SESSION, |
||||
'name' => $sessionItem['session_name'], |
||||
'visible' => $sessionItem['visible'], |
||||
'price' => $sessionItem['price'], |
||||
'beneficiaries' => $defaultBeneficiaries |
||||
]; |
||||
} else { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$form = new FormValidator('beneficiaries'); |
||||
$form->addText('product_type', $plugin->get_lang('ProductType'), false); |
||||
$form->addText('name', get_lang('Name'), false); |
||||
$visibleCheckbox = $form->addCheckBox( |
||||
'visible', |
||||
$plugin->get_lang('VisibleInCatalog'), |
||||
$plugin->get_lang('ShowOnCourseCatalog') |
||||
); |
||||
$form->addElement( |
||||
'number', |
||||
'price', |
||||
[$plugin->get_lang('Price'), null, $currencyIso], |
||||
['step' => 0.01] |
||||
); |
||||
$beneficiariesSelect = $form->addSelect( |
||||
'beneficiaries', |
||||
$plugin->get_lang('Beneficiaries'), |
||||
null, |
||||
['multiple' => 'multiple'] |
||||
); |
||||
|
||||
if ($editingCourse) { |
||||
$beneficiariesSelect->addOptGroup($teachersOptions, get_lang('Teachers')); |
||||
} elseif ($editingSession) { |
||||
$beneficiariesSelect->addOptGroup([$generalCoachOption], get_lang('SessionGeneralCoach')); |
||||
$beneficiariesSelect->addOptGroup($courseCoachesOptions, get_lang('SessionCourseCoach')); |
||||
} |
||||
|
||||
$form->addHidden('t', null); |
||||
$form->addHidden('i', null); |
||||
$form->addButtonSave(get_lang('Save')); |
||||
$form->freeze(['product_type', 'name']); |
||||
|
||||
if ($form->validate()) { |
||||
$formValues = $form->exportValues(); |
||||
$productItem = $plugin->getItemByProduct($formValues['i'], $formValues['t']); |
||||
|
||||
if (isset($formValues['visible'])) { |
||||
if (!empty($productItem)) { |
||||
$plugin->updateItem( |
||||
['price' => floatval($formValues['price'])], |
||||
$formValues['i'], |
||||
$formValues['t'] |
||||
); |
||||
} else { |
||||
$itemId = $plugin->registerItem([ |
||||
'currency_id' => $currency['id'], |
||||
'product_type' => $formValues['t'], |
||||
'product_id' => intval($formValues['i']), |
||||
'price' => floatval($_POST['price']) |
||||
]); |
||||
$productItem['id'] = $itemId; |
||||
} |
||||
|
||||
$plugin->deleteItemBeneficiaries($productItem['id']); |
||||
|
||||
if (isset($formValues['beneficiaries'])) { |
||||
$plugin->registerItemBeneficiaries($productItem['id'], $formValues['beneficiaries']); |
||||
} |
||||
} else { |
||||
$plugin->deleteItem($productItem['id']); |
||||
} |
||||
|
||||
header('Location: ' . api_get_path(WEB_PLUGIN_PATH) . 'buycourses/src/configuration.php'); |
||||
exit; |
||||
} |
||||
|
||||
$form->setDefaults($formDefaults); |
||||
|
||||
//View |
||||
$templateName = $plugin->get_lang('AvailableCourse'); |
||||
|
||||
$interbreadcrumb[] = [ |
||||
'url' => 'paymentsetup.php', |
||||
'name' => get_lang('Configuration') |
||||
]; |
||||
$interbreadcrumb[] = [ |
||||
'url' => 'configuration.php', |
||||
'name' => $plugin->get_lang('AvailableCourses') |
||||
]; |
||||
|
||||
$template = new Template($templateName); |
||||
$template->assign('header', $templateName); |
||||
$template->assign('content', $form->returnForm()); |
||||
$template->display_one_col_template(); |
@ -1,85 +0,0 @@ |
||||
<?php |
||||
/* For license terms, see /license.txt */ |
||||
/** |
||||
* Functions for the Buy Courses plugin |
||||
* @package chamilo.plugin.buycourses |
||||
*/ |
||||
/** |
||||
* Init |
||||
*/ |
||||
require_once '../config.php'; |
||||
|
||||
$itemTable = Database::get_main_table(BuyCoursesPlugin::TABLE_ITEM); |
||||
|
||||
$plugin = BuyCoursesPlugin::create(); |
||||
$currency = $plugin->getSelectedCurrency(); |
||||
|
||||
if ($_REQUEST['tab'] == 'save_mod') { |
||||
if (isset($_REQUEST['course_id'])) { |
||||
$productId = $_REQUEST['course_id']; |
||||
$productType = BuyCoursesPlugin::PRODUCT_TYPE_COURSE; |
||||
} else { |
||||
$productId = $_REQUEST['session_id']; |
||||
$productType = BuyCoursesPlugin::PRODUCT_TYPE_SESSION; |
||||
} |
||||
|
||||
$affectedRows = false; |
||||
|
||||
if ($_POST['visible'] == 1) { |
||||
$item = Database::select( |
||||
'COUNT(1) AS qty', |
||||
$itemTable, |
||||
[ |
||||
'where' => [ |
||||
'product_id = ? AND ' => intval($productId), |
||||
'product_type = ?' => $productType |
||||
] |
||||
], |
||||
'first' |
||||
); |
||||
|
||||
if ($item['qty'] > 0) { |
||||
$affectedRows = Database::update( |
||||
$itemTable, |
||||
['price' => floatval($_POST['price'])], |
||||
[ |
||||
'product_id = ? AND ' => intval($productId), |
||||
'product_type' => $productType |
||||
] |
||||
); |
||||
} else { |
||||
$affectedRows = Database::insert( |
||||
$itemTable, |
||||
[ |
||||
'currency_id' => $currency['id'], |
||||
'product_type' => $productType, |
||||
'product_id' => intval($productId), |
||||
'price' => floatval($_POST['price']) |
||||
] |
||||
); |
||||
} |
||||
} else { |
||||
$affectedRows = Database::delete( |
||||
$itemTable, |
||||
[ |
||||
'product_id = ? AND ' => intval($productId), |
||||
'product_type = ?' => $productType |
||||
] |
||||
); |
||||
} |
||||
|
||||
if ($affectedRows > 0) { |
||||
$jsonResult = [ |
||||
"status" => true, |
||||
"itemId" => $productId |
||||
]; |
||||
} else { |
||||
$jsonResult = [ |
||||
"status" => false, |
||||
"content" => $plugin->get_lang('ItemNotSaved') |
||||
]; |
||||
} |
||||
|
||||
echo json_encode($jsonResult); |
||||
exit; |
||||
} |
@ -1,80 +1,75 @@ |
||||
<link rel="stylesheet" type="text/css" href="resources/css/style.css"/> |
||||
{% if _u.is_admin %} |
||||
<div class="row"> |
||||
<div class="col-md-12"> |
||||
<article class="jumbotron"> |
||||
<h3>{{ 'TitlePlugin'|get_plugin_lang('BuyCoursesPlugin') }}</h3> |
||||
<p>{{ 'PluginPresentation'|get_plugin_lang('BuyCoursesPlugin') }}</p> |
||||
<ul class="list-unstyled"> |
||||
<li> |
||||
{{ 'Instructions'|get_plugin_lang('BuyCoursesPlugin') }} |
||||
<ul> |
||||
<li>{{ 'InstructionsStepOne'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
<li>{{ 'InstructionsStepTwo'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
<li>{{ 'InstructionsStepThree'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
</ul> |
||||
</li> |
||||
</ul> |
||||
</article> |
||||
</div> |
||||
</div> |
||||
{% endif %} |
||||
|
||||
<div class="row"> |
||||
<div class="col-md-12"> |
||||
{% if _u.is_admin %} |
||||
<div class="help-bycourse"> |
||||
<div class="row"> |
||||
<div class="col-md-7"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-body"> |
||||
<h3>{{ 'TitlePlugin'|get_plugin_lang('BuyCoursesPlugin') }}</h3> |
||||
<p>{{ 'PluginPresentation'|get_plugin_lang('BuyCoursesPlugin') }}</p> |
||||
<p> </p> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-5"> |
||||
<div class="panel panel-default"> |
||||
<div class="panel-heading"> |
||||
{{ 'Instructions'|get_plugin_lang('BuyCoursesPlugin') }} |
||||
</div> |
||||
<div class="panel-body"> |
||||
<ul> |
||||
<li>{{ 'InstructionsStepOne'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
<li>{{ 'InstructionsStepTwo'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
<li>{{ 'InstructionsStepThree'|get_plugin_lang('BuyCoursesPlugin') }}</li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/course_catalog.php"> |
||||
<img src="resources/img/128/buycourses.png"> |
||||
</a> |
||||
<div class="caption"> |
||||
<p class="text-center"> |
||||
<a class="btn btn-default btn-sm" href="src/course_catalog.php">{{ 'BuyCourses'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</p> |
||||
</div> |
||||
{% endif %} |
||||
</div> |
||||
</div> |
||||
|
||||
<div class="row"> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/course_catalog.php"> |
||||
<img src="resources/img/128/buycourses.png"> |
||||
</a> |
||||
<div class="caption" align="center"> |
||||
<a class="btn btn-default btn-sm" href="src/course_catalog.php">{{ 'BuyCourses'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</div> |
||||
{% if _u.is_admin %} |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/configuration.php"> |
||||
<img src="resources/img/128/settings.png"> |
||||
</a> |
||||
<div class="caption"> |
||||
<p class="text-center"> |
||||
<a class="btn btn-default btn-sm" href="src/configuration.php">{{ 'ConfigurationOfCoursesAndPrices'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</p> |
||||
</div> |
||||
</div> |
||||
|
||||
{% if _u.is_admin %} |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/configuration.php"> |
||||
<img src="resources/img/128/settings.png"> |
||||
</a> |
||||
<div class="caption" align="center"> |
||||
<a class="btn btn-default btn-sm" href="src/configuration.php">{{ 'ConfigurationOfCoursesAndPrices'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/paymentsetup.php"> |
||||
<img src="resources/img/128/paymentsettings.png"> |
||||
</a> |
||||
<div class="caption" align="center"> |
||||
<a class="btn btn-default btn-sm" href="src/paymentsetup.php">{{ 'PaymentsConfiguration'|get_plugin_lang('BuyCoursesPlugin') }} </a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/paymentsetup.php"> |
||||
<img src="resources/img/128/paymentsettings.png"> |
||||
</a> |
||||
<div class="caption"> |
||||
<p class="text-center"> |
||||
<a class="btn btn-default btn-sm" href="src/paymentsetup.php">{{ 'PaymentsConfiguration'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</p> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/sales_report.php"> |
||||
<img src="resources/img/128/backlogs.png"> |
||||
</a> |
||||
<div class="caption" align="center"> |
||||
<a class="btn btn-default btn-sm" href="src/sales_report.php"> {{ 'SalesReport'|get_plugin_lang('BuyCoursesPlugin') }} </a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<div class="col-md-3"> |
||||
<div class="thumbnail"> |
||||
<a href="src/sales_report.php"> |
||||
<img src="resources/img/128/backlogs.png"> |
||||
</a> |
||||
<div class="caption"> |
||||
<p class="text-center"> |
||||
<a class="btn btn-default btn-sm" href="src/sales_report.php"> {{ 'SalesReport'|get_plugin_lang('BuyCoursesPlugin') }}</a> |
||||
</p> |
||||
</div> |
||||
{% endif %} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
{% endif %} |
||||
</div> |
||||
|
Loading…
Reference in new issue