Commit 3951a5c0 authored by Aspasia Katsi's avatar Aspasia Katsi Committed by Σταύρος Παπαδάκης

Updated CSV exports for old and new applications

parent 23ea9a1f
...@@ -134,7 +134,6 @@ class ApplicationForm { ...@@ -134,7 +134,6 @@ class ApplicationForm {
$items_version = array_values($appForm['items'])[0]['version']; $items_version = array_values($appForm['items'])[0]['version'];
} }
$this->container['logger']->info("DO THE MIGRATION CHECK TO VERSION [{$this->version}] FROM VERSION [{$items_version}]");
if ($this->version != $items_version && if ($this->version != $items_version &&
isset($appForm['items']) && isset($appForm['items']) &&
isset($this->container['settings']['application_form']['itemcategory']['map']) && isset($this->container['settings']['application_form']['itemcategory']['map']) &&
......
...@@ -53,8 +53,6 @@ class SchoolApplicationForm ...@@ -53,8 +53,6 @@ class SchoolApplicationForm
$items_version = array_values($appForm['items'])[0]['version']; $items_version = array_values($appForm['items'])[0]['version'];
} }
$this->container['logger']->info("DO THE MIGRATION CHECK TO VERSION [{$currentVersion}] FROM VERSION [{$items_version}]");
$appForm['items'] = array_reduce($appForm['items'], function ($aggr, $item) use ($currentVersion, $items_version) { $appForm['items'] = array_reduce($appForm['items'], function ($aggr, $item) use ($currentVersion, $items_version) {
$category = $item['itemcategory_id']; $category = $item['itemcategory_id'];
if (!isset($aggr[$category])) { if (!isset($aggr[$category])) {
......
...@@ -67,6 +67,19 @@ return function (App $app) { ...@@ -67,6 +67,19 @@ return function (App $app) {
'Ονομασία σχολείου', 'Ονομασία σχολείου',
'Σχόλια - Παρατηρήσεις', 'Σχόλια - Παρατηρήσεις',
], ],
],
'software' => [
'data_callback' => 'csv_export_software',
'headers' => [
'Τύπος',
'Κωδικός σχολείου',
'Ονομασία σχολείου',
'ID χώρου',
'Τύπος χώρου',
'Ονομασία',
'Κατασκευαστής',
'URL',
],
], ],
'appforms' => [ 'appforms' => [
'data_callback' => 'csv_export_appforms', 'data_callback' => 'csv_export_appforms',
...@@ -78,6 +91,19 @@ return function (App $app) { ...@@ -78,6 +91,19 @@ return function (App $app) {
'Σχόλια - Παρατηρήσεις', 'Σχόλια - Παρατηρήσεις',
], ],
], ],
'appnewforms' => [
'data_callback' => 'csv_export_appnewforms',
'headers' => [
'ID',
'Κωδικός σχολείου',
'Ονομασία σχολείου',
'Ημερομηνία υποβολής',
'Σχόλια - Παρατηρήσεις',
],
],
'appforms_items' => [ 'appforms_items' => [
'data_callback' => 'csv_export_appforms_items', 'data_callback' => 'csv_export_appforms_items',
'headers' => [ 'headers' => [
...@@ -93,19 +119,6 @@ return function (App $app) { ...@@ -93,19 +119,6 @@ return function (App $app) {
'Αιτιολογία χρήσης', 'Αιτιολογία χρήσης',
], ],
], ],
'software' => [
'data_callback' => 'csv_export_software',
'headers' => [
'Τύπος',
'Κωδικός σχολείου',
'Ονομασία σχολείου',
'ID χώρου',
'Τύπος χώρου',
'Ονομασία',
'Κατασκευαστής',
'URL',
],
],
'newapplication' => [ 'newapplication' => [
'data_callback' => 'csv_export_newapplication', 'data_callback' => 'csv_export_newapplication',
'headers' => [ 'headers' => [
...@@ -115,6 +128,7 @@ return function (App $app) { ...@@ -115,6 +128,7 @@ return function (App $app) {
'Είδος', 'Είδος',
'Πλήθος Υπαρχόντων που λειτουργούν', 'Πλήθος Υπαρχόντων που λειτουργούν',
'Πλήθος Αιτουμένων', 'Πλήθος Αιτουμένων',
'Αιτιολογία χρήσης',
], ],
], ],
]; ];
...@@ -235,60 +249,145 @@ return function (App $app) { ...@@ -235,60 +249,145 @@ return function (App $app) {
}; };
}; };
$c['csv_export_appforms'] = function ($c) {
$c['csv_export_software'] = function ($c) {
return function () { return function () {
$sql = 'SELECT applicationform.id AS id, ' $sql = 'SELECT softwarecategory.name AS name, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, '
. ' lab.id AS lab_id, '
. ' TRIM(labtype.name) AS lab_type, '
. ' TRIM(software.title) AS title, '
. ' TRIM(software.vendor) AS vendor, '
. ' TRIM(software.url) AS url '
. ' FROM software '
. ' LEFT JOIN softwarecategory ON software.softwarecategory_id = softwarecategory.id '
. ' LEFT JOIN school ON software.school_id = school.id '
. ' LEFT JOIN lab ON software.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' ORDER BY school_name ';
$software = R::getAll($sql);
$software = array_map(function ($row) {
$row['url'] = strtolower($row['url']);
$row['url'] = str_replace('\\', '/', $row['url']);
$row['url'] = urldecode($row['url']);
return $row;
}, $software);
return $software;
};
};
$c['csv_export_appforms'] = function ($c) {
//return function () {
return function () use ($c) {
$settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion'];
$appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted)IN (SELECT MAX( submitted )FROM applicationform '
. ' LEFT JOIN applicationformitem ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id'
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id'
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id'
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id'
. ' WHERE itemcategory.groupflag NOT IN(' . $version . ')'
. ' GROUP BY school.id)';
$appFormIds = R::getCol($appFormIdsSql);
if (empty($appFormIds)) {
return [];
}
$in = implode(',', array_fill(0, count($appFormIds), '?'));
$sql = 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, ' . ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' TRIM(applicationform.comments) AS comments ' . ' TRIM(applicationform.comments) AS comments'
. ' FROM applicationform ' . ' FROM applicationformitem '
. ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id ' . ' LEFT JOIN school ON applicationform.school_id = school.id '
. ' GROUP BY school.id ' . ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id '
. ' HAVING MAX(applicationform.submitted)'; . ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' WHERE applicationform.id IN(' . $in . ')'
. ' GROUP BY school.id ';
$appForms = R::getAll($sql); $appForms = R::getAll($sql, $appFormIds);
return $appForms; return $appForms;
// $sql = 'SELECT applicationform.id AS id, '
// . ' school.registry_no AS school_registry_no, '
// . ' school.name AS school_name, '
// . ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
// . ' TRIM(applicationform.comments) AS comments '
// . ' FROM applicationform '
// . ' LEFT JOIN school ON applicationform.school_id = school.id '
// . ' GROUP BY school.id '
// . ' HAVING MAX(applicationform.submitted)';
// $appForms = R::getAll($sql);
// return $appForms;
}; };
}; };
$c['csv_export_appforms_items'] = function ($c) {
return function () { $c['csv_export_appnewforms'] = function ($c) {
$appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted) IN( SELECT MAX(submitted) FROM applicationform GROUP BY school_id)'; return function () use ($c) {
//$appFormIdsSql = 'SELECT applicationform.id '
// . ' FROM applicationform ' $appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted) IN( SELECT MAX(submitted) FROM applicationform GROUP BY school_id)';
// . ' GROUP BY school_id '
// . ' HAVING MAX(applicationform.submitted)';
$appFormIds = R::getCol($appFormIdsSql); $appFormIds = R::getCol($appFormIdsSql);
if (empty($appFormIds)) { if (empty($appFormIds)) {
return []; return [];
} }
$in = implode(',', array_fill(0, count($appFormIds), '?')); $in = implode(',', array_fill(0, count($appFormIds), '?'));
$settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion'];
$sql = 'SELECT applicationform.id AS id, ' $sql = 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, ' . ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' lab.id AS lab_id, ' . ' TRIM(applicationform.comments) AS comments'
. ' TRIM(labtype.name) AS lab_type, '
. ' IF(lab.is_new = 1, "ΝΑΙ", "ΟΧΙ") AS is_new, '
. ' TRIM(itemcategory.name) AS category, '
. ' applicationformitem.qty AS qty, '
. ' TRIM(applicationformitem.reasons) AS reasons '
. ' FROM applicationformitem ' . ' FROM applicationformitem '
. ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id ' . ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id ' . ' LEFT JOIN school ON applicationform.school_id = school.id '
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id ' . ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id '
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id ' . ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' WHERE applicationform.id IN(' . $in . ') '; . ' WHERE applicationform.id IN(' . $in . ')'
. ' AND itemcategory.groupflag IN(' . $version . ')'
. ' GROUP BY school.id ';
$appForms = R::getAll($sql, $appFormIds); $appForms = R::getAll($sql, $appFormIds);
...@@ -296,39 +395,64 @@ return function (App $app) { ...@@ -296,39 +395,64 @@ return function (App $app) {
}; };
}; };
$c['csv_export_software'] = function ($c) {
return function () {
$sql = 'SELECT softwarecategory.name AS name, ' $c['csv_export_appforms_items'] = function ($c) {
return function () use ($c){
$settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion'];
$appFormIdsSql = 'SELECT id FROM applicationform WHERE (submitted)IN (SELECT MAX( submitted )FROM applicationform '
. ' LEFT JOIN applicationformitem ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN school ON applicationform.school_id = school.id'
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id'
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id'
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id'
. ' WHERE itemcategory.groupflag NOT IN(' . $version . ')'
. ' GROUP BY school.id)';
// $appFormIdsSql = 'SELECT applicationform.id '
// . ' FROM applicationform '
// . ' GROUP BY school_id '
// . ' HAVING MAX(applicationform.submitted)';
$appFormIds = R::getCol($appFormIdsSql);
if (empty($appFormIds)) {
return [];
}
$in = implode(',', array_fill(0, count($appFormIds), '?'));
$sql = 'SELECT applicationform.id AS id, '
. ' school.registry_no AS school_registry_no, ' . ' school.registry_no AS school_registry_no, '
. ' school.name AS school_name, ' . ' school.name AS school_name, '
. ' FROM_UNIXTIME(applicationform.submitted) AS submitted, '
. ' lab.id AS lab_id, ' . ' lab.id AS lab_id, '
. ' TRIM(labtype.name) AS lab_type, ' . ' TRIM(labtype.name) AS lab_type, '
. ' TRIM(software.title) AS title, ' . ' IF(lab.is_new = 1, "ΝΑΙ", "ΟΧΙ") AS is_new, '
. ' TRIM(software.vendor) AS vendor, ' . ' TRIM(itemcategory.name) AS category, '
. ' TRIM(software.url) AS url ' . ' applicationformitem.qty AS qty, '
. ' FROM software ' . ' TRIM(applicationformitem.reasons) AS reasons '
. ' LEFT JOIN softwarecategory ON software.softwarecategory_id = softwarecategory.id ' . ' FROM applicationformitem '
. ' LEFT JOIN school ON software.school_id = school.id ' . ' LEFT JOIN applicationform ON applicationformitem.applicationform_id = applicationform.id '
. ' LEFT JOIN lab ON software.lab_id = lab.id ' . ' LEFT JOIN school ON applicationform.school_id = school.id '
. ' LEFT JOIN itemcategory ON applicationformitem.itemcategory_id = itemcategory.id '
. ' LEFT JOIN lab ON applicationformitem.lab_id = lab.id '
. ' LEFT JOIN labtype ON lab.labtype_id = labtype.id ' . ' LEFT JOIN labtype ON lab.labtype_id = labtype.id '
. ' ORDER BY school_name '; . ' WHERE applicationform.id IN(' . $in . ') ';
$software = R::getAll($sql);
$software = array_map(function ($row) {
$row['url'] = strtolower($row['url']);
$row['url'] = str_replace('\\', '/', $row['url']);
$row['url'] = urldecode($row['url']);
return $row; $appForms = R::getAll($sql, $appFormIds);
}, $software);
return $software; return $appForms;
}; };
}; };
$c['csv_export_newapplication'] = function ($c) { $c['csv_export_newapplication'] = function ($c) {
return function () use ($c) { return function () use ($c) {
...@@ -345,8 +469,6 @@ return function (App $app) { ...@@ -345,8 +469,6 @@ return function (App $app) {
$in = implode(',', array_fill(0, count($appFormIds), '?')); $in = implode(',', array_fill(0, count($appFormIds), '?'));
// $version = container['settings']['application_form']['itemcategory']['currentversion'];
// echo "lalalala".$version . "lalalala";
$settings = $c->get('settings'); $settings = $c->get('settings');
$version = $settings['application_form']['itemcategory']['currentversion']; $version = $settings['application_form']['itemcategory']['currentversion'];
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th colspan="2">Λίστα αρχείων</th> <th>Δεδομένα</th>
<th>Μεταφόρτωση αρχείου</th>
<tr> <tr>
</thead> </thead>
<tbody> <tbody>
...@@ -21,16 +22,16 @@ ...@@ -21,16 +22,16 @@
<td> <td>
<a href="{{ path_for('export.csv', {type: 'schools'}) }}"> <a href="{{ path_for('export.csv', {type: 'schools'}) }}">
<i class="fa fa-download"></i> <i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv Αρχείο .csv
</a> </a>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Χώροι μονάδων που καταγράφηκαν από τη δράση</td> <td>Χώροι μονάδων που καταγράφηκαν από τη δράση</td>
<td> <td>
<a href="{{ path_for('export.csv', {type: 'labs'}) }}"> <a href="{{ path_for('export.csv', {type: 'labs'}) }}">
<i class="fa fa-download"></i> <i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv Αρχείο .csv
</a> </a>
</td> </td>
</tr> </tr>
...@@ -39,7 +40,7 @@ ...@@ -39,7 +40,7 @@
<td> <td>
<a href="{{ path_for('export.csv', {type: 'assets'}) }}"> <a href="{{ path_for('export.csv', {type: 'assets'}) }}">
<i class="fa fa-download"></i> <i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv Αρχείο .csv
</a> </a>
</td> </td>
</tr> </tr>
...@@ -48,7 +49,7 @@ ...@@ -48,7 +49,7 @@
<td> <td>
<a href="{{ path_for('export.csv', {type: 'software'}) }}"> <a href="{{ path_for('export.csv', {type: 'software'}) }}">
<i class="fa fa-download"></i> <i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv Αρχείο .csv
</a> </a>
</td> </td>
</tr> </tr>
...@@ -57,21 +58,35 @@ ...@@ -57,21 +58,35 @@
<td> <td>
<a href="{{ path_for('export.csv', {type: 'appforms'}) }}"> <a href="{{ path_for('export.csv', {type: 'appforms'}) }}">
<i class="fa fa-download"></i> <i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv Αρχείο .csv
</a> </a>
</td> </td>
</tr> </tr>
<tr>
<tr>
<td>Εξοπλισμός που αιτήθηκαν οι μονάδες</td> <td>Εξοπλισμός που αιτήθηκαν οι μονάδες</td>
<td> <td>
<a href="{{ path_for('export.csv', {type: 'appforms_items'}) }}"> <a href="{{ path_for('export.csv', {type: 'appforms_items'}) }}">
<i class="fa fa-download"></i> <i class="fa fa-download"></i>
Μεταφόρτωση αρχείου .csv Αρχείο .csv
</a>
</td>
</tr>
<tr>
<td>Νές αιτήσεις που συγκεντρώθηκαν από τις μονάδες</td>
<td>
<a href="{{ path_for('export.csv', {type: 'appnewforms'}) }}">
<i class="fa fa-download"></i>
Αρχείο .csv
</a> </a>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>Εξοπλισμός που αιτήθηκαν οι μονάδες με τις νέες αιτήσεις</td> <td>Εξοπλισμός που αιτήθηκαν οι μονάδες με τις νέες αιτήσεις</td>
<td> <td>
<a href="{{ path_for('export.csv', {type: 'newapplication'}) }}"> <a href="{{ path_for('export.csv', {type: 'newapplication'}) }}">
...@@ -81,6 +96,8 @@ ...@@ -81,6 +96,8 @@
</td> </td>
</tr> </tr>
</tbody> </tbody>
<tfoot> <tfoot>
<tr><th colspan="2"></th><tr> <tr><th colspan="2"></th><tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment