Schulsicht

This commit is contained in:
2018-04-04 17:35:13 +02:00
parent 1e9a4e65c5
commit 4c83767fe7
11 changed files with 266 additions and 21 deletions

View File

@@ -27,15 +27,32 @@ class BudgetController extends AppController
public function listBudgets() {
$session = $this->request->session();
//debug($session->read('SchoolType'));die;
$schooltype = $session->read('SchoolType');
if ($schooltype == '02') {
$schulart = 'RS';
}
else {
$schulart = 'GY';
}
$wlBudgets = $this->Budget->wlBudgets->find('all', [
'conditions' => array('schulart' => 'GY')
'conditions' => array('schulart' => $schulart)
]);
$this->set('wlBudgets',$wlBudgets);
}
public function editBudget($id = null) {
$session = $this->request->session();
//debug($session->read('SchoolType'));die;
$schooltype = $session->read('SchoolType');
$this->loadModel('Schools');
$schools = $this->Schools->find('all');
$schools = $this->Schools->find('all', [
'conditions' => array('dst_schulart' => $schooltype)
]);
$data = array();
foreach($schools as $school) {
$line = array();
@@ -107,15 +124,29 @@ class BudgetController extends AppController
}
public function sajax() {
$session = $this->request->session();
//debug($session->read('SchoolType'));die;
$schooltype = $session->read('SchoolType');
if ($schooltype == '02') {
$wl_offset = 31;
$schooltype_id = '2';
}
else {
$schooltype_id = '4';
$wl_offset = -1;
}
$this->autoRender = false;
$myfile = fopen(WWW_ROOT . DS . 'files' . DS . 'debug.txt', "w");
$data = $this->request->input('json_decode');
foreach($data as $line) {
for($i=2;$i < sizeof($line);$i++) {
if($line[$i] > 0) {
$query = $this->Budget->find('all', [
'conditions' => array('snr' => $line[0], 'wl_budget_id' => $i-1)
'conditions' => array('snr' => $line[0], 'wl_budget_id' => $i+$wl_offset)
]);
if(!($query->isEmpty())) {
@@ -129,9 +160,9 @@ class BudgetController extends AppController
else {
fwrite($myfile,'empty' . PHP_EOL);
$new = $this->Budget->newEntity();
$new_budget['wl_schooltype_id'] = 4;
$new_budget['wl_schooltype_id'] = $schooltype_id;
$new_budget['snr'] = $line[0];
$new_budget['wl_budget_id'] = $i-1;
$new_budget['wl_budget_id'] = $i+$wl_offset;
$new_budget['count'] = $line[$i];
$new_budget['comment'] = 'auto';
$new_budget['year'] = '2018';
@@ -141,7 +172,7 @@ class BudgetController extends AppController
$this->Budget->save($new);
}
fwrite($myfile,serialize($budget). PHP_EOL);
fwrite($myfile,$line[0] . ' ' .($i-1) . ' ' . $line[$i]. PHP_EOL);
fwrite($myfile,$line[0] . ' ' .($i+$wl_offset) . ' ' . $line[$i]. PHP_EOL);
}
}
}
@@ -149,13 +180,28 @@ class BudgetController extends AppController
}
public function overview() {
$session = $this->request->session();
//debug($session->read('SchoolType'));die;
$schooltype = $session->read('SchoolType');
if ($schooltype == '02') {
$schulart = 'RS';
$offset = -31;
}
else {
$schulart = 'GY';
$offset = 1;
}
$wlBudgets = $this->Budget->wlBudgets->find('list', [
'conditions' => array('schulart' => 'GY')
'conditions' => array('schulart' => $schulart)
]);
//debug($wlBudgets);
//debug($wlBudgets);die;
$this->loadModel('Schools');
$schools = $this->Schools->find('all');
$schools = $this->Schools->find('all', [
'conditions' => array('dst_schulart' => $schooltype)
]);
$data = array();
foreach($schools as $school) {
$line = array();
@@ -168,9 +214,12 @@ class BudgetController extends AppController
$data[$school['dst_schluessel']] = $line;
}
$budgets = $this->Budget->find('all');
$budgets = $this->Budget->find('all', [
'contain' => ['WlSchooltypes'],
'conditions' => array('WlSchooltypes.key_value' => $schooltype)
]);
foreach($budgets as $budget) {
$i = $budget['wl_budget_id']+1;
$i = $budget['wl_budget_id']+$offset;
$data[$budget['snr']][$i] = $budget['count'];
}
$data_arr = array();

View File

@@ -12,6 +12,126 @@ use App\Controller\AppController;
*/
class SchoolsController extends AppController
{
public function showajax($snr = null) {
$session = $this->request->session();
$schooltype = $session->read('SchoolType');
$this->autoRender = false;
$myfile = fopen(WWW_ROOT . DS . 'files' . DS . 'debug-single.txt', "w");
$data = $this->request->input('json_decode');
$this->loadModel('Budget');
$this->loadModel('wl_Budgets');
fwrite($myfile,$schooltype . PHP_EOL);
fwrite($myfile,$snr . PHP_EOL);
foreach($data as $line) {
fwrite($myfile,'Size: ' . strlen($line[0]) . PHP_EOL);
if(strlen($line[0]) > 0) {
fwrite($myfile,'Budget: ' . $line[0] . PHP_EOL);
$query = $this->wl_Budgets->find('all', [
'conditions' => array('wl_kurz_bezeichnung' => $line[0])
]);
$wl_budget = $query->first();
fwrite($myfile,json_encode($wl_budget). PHP_EOL);
$query = $this->Budget->find('all', [
'conditions' => array('snr' => $snr, 'wl_budget_id' => $wl_budget['id'])
]);
fwrite($myfile,$wl_budget['id'] . PHP_EOL);
if(!($query->isEmpty())) {
$budget = $query->first();
fwrite($myfile,json_encode($budget). PHP_EOL);
if($budget['wl_budget_id'] != $wl_budget['id'] ) {
$budget['wl_budget_id'] = $wl_budget['id'];
$this->Budget->save($budget);
}
elseif($budget['count'] != $line[1] ) {
$budget['count'] = $line[1];
$this->Budget->save($budget);
}
elseif($budget['comment'] != $line[2] ) {
$budget['comment'] = $line[2];
$this->Budget->save($budget);
}
fwrite($myfile,'full' . PHP_EOL);
}
else {
fwrite($myfile,'empty' . PHP_EOL);
$new = $this->Budget->newEntity();
$new_budget['wl_schooltype_id'] = $schooltype;
$new_budget['snr'] = $snr;
$new_budget['wl_budget_id'] = $wl_budget['id'];
$new_budget['count'] = $line[1];
$new_budget['comment'] = $line[2];
$new_budget['year'] = '2018';
fwrite($myfile,'New: ' . json_encode($new_budget). PHP_EOL);
$new = $this->Budget->patchEntity($new, $new_budget);
$this->Budget->save($new);
}
//fwrite($myfile,serialize($budget). PHP_EOL);
//fwrite($myfile,$line[0] . ' ' .($i+$wl_offset) . ' ' . $line[$i]. PHP_EOL);
}
}
fclose($myfile);
}
public function showbudgets($snr = null) {
$session = $this->request->session();
//debug($session->read('SchoolType'));die;
$schooltype = $session->read('SchoolType');
if ($schooltype == '02') {
$schulart = 'RS';
}
else {
$schulart = 'GY';
}
$query = $this->Schools->find('all', [
'conditions' => array('dst_schluessel' => $snr)
]);
$school = $query->first();
$this->loadModel('Budget');
$budgets = $this->Budget->find('all', [
'conditions' => ['snr' => $snr]
]);
$this->loadModel('wl_Budgets');
$data = array();
foreach($budgets as $budget) {
$line = array();
//debug($budget);
$wl_budget = $this->wl_Budgets->get($budget['wl_budget_id']);
//debug($wl_budget);
array_push($line,$wl_budget['wl_kurz_bezeichnung']);
array_push($line,$budget['count']);
array_push($line,$budget['comment']);
array_push($data,$line);
}
for($i=0;$i<5;$i++) {
$line = array();
array_push($line,'');
array_push($line,'');
array_push($line,'');
array_push($data,$line);
}
$query = $this->wl_Budgets->find('list', [
'conditions' => array('schulart' => $schulart),
'valueField' => 'wl_kurz_bezeichnung'
]);
$wl_budgets = $query->toArray();
$budgets_arr = array();
foreach ($wl_budgets as $wl_budget) {
array_push($budgets_arr,$wl_budget);
}
//debug(json_encode($budgets_arr));die;
$this->set('budgets_arr',$budgets_arr);
$this->set('school',$school);
$this->set('data',$data);
}
public function show() {
$results = $this->Schools->find('all');

View File

@@ -1,21 +1,21 @@
<?php
//debug($budget);
//debug($data);
for($i=0;$i<sizeof($data);$i++) {
$data[$i][0] = $this->Html->link($data[$i][0],array('controller' => 'schools', 'action' => 'showbudgets',$data[$i][0]));
}
echo '<h2>' . $budget['wl_kurz_bezeichnung'] .'</h2>';
//debug($data);
?>
<div class="controls">
<button name="load" id="load" class="intext-btn">Load</button>
<button name="save" id="save" class="intext-btn">Save</button>
<label><input name="autosave" id="autosave" checked="checked" autocomplete="off" type="checkbox">Autosave</label>
</div>
<pre id="example1console" class="console">Data loaded</pre>
<div id="editbudget"></div>
<script>
var data = <?php echo json_encode($data); ?>;
var container = document.getElementById('editbudget');
var exampleConsole = document.getElementById('example1console');
var autosave = document.getElementById('autosave');
var load = document.getElementById('load');
var save = document.getElementById('save');
var autosaveNotification;
@@ -24,11 +24,12 @@ var data = <?php echo json_encode($data); ?>;
var hot = new Handsontable(container, {
data: data,
width: 1400,
height: 1000,
height: 800,
rowHeaders: true,
wordWrap: false,
colHeaders: ['SNR','Name','Count','Comment'] ,
colWidths: ['50','500','50','500'],
columns: [{renderer: "html", readOnly: true},{renderer: "text", readOnly: true},{renderer: "text"},{renderer: "text"}],
filters: true,
dropdownMenu: true
});

View File

@@ -1,7 +1,9 @@
<?php
echo '<h1>Wählen Sie eine Budgetart aus.</h1>';
echo '<ul>';
foreach ($wlBudgets as $wlBudget) {
//debug($wlBudget);
echo '<p>' . $this->Html->link($wlBudget['wl_kurz_bezeichnung'],['controller' => 'Budget', 'action' => 'edit_budget' , $wlBudget['id']]) . '</p>';
echo '<li>' . $this->Html->link($wlBudget['wl_kurz_bezeichnung'],['controller' => 'Budget', 'action' => 'edit_budget' , $wlBudget['id']]) . '</li>';
}
echo '</ul>';
?>

View File

@@ -13,7 +13,7 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
$cakeDescription = 'CakePHP: the rapid development php framework';
$cakeDescription = 'KM Bayern';
?>
<!DOCTYPE html>
<html>

View File

@@ -0,0 +1,48 @@
<?php
echo '<h1>'. $school->dst_schluessel . ' ' . $school->dst_name .'</h1>';
?>
<div class="controls">
<button name="load" id="load" class="intext-btn">Load</button>
<button name="save" id="save" class="intext-btn">Save</button>
</div>
<div id="showbudget"></div>
<script>
var data = <?php echo json_encode($data); ?>;
var container = document.getElementById('showbudget');
var load = document.getElementById('load');
var save = document.getElementById('save');
var autosaveNotification;
var rotated = false;
var hot = new Handsontable(container, {
data: data,
width: 1400,
height: 800,
rowHeaders: true,
wordWrap: false,
colHeaders: ['Name','Count','Comment'] ,
colWidths: ['500','50','500'],
columns: [{type: 'dropdown', source: <?php echo json_encode($budgets_arr); ?>},{renderer: "text"},{renderer: "text"}],
filters: true,
dropdownMenu: true
});
Handsontable.dom.addEvent(save, 'click', function() {
// save all cell's data
//console.log(hot.getData());
//console.log(JSON.stringify({data: hot.getData()}));
$.ajax({
url: "<?php echo $this->Url->build(array('controller' => 'schools', 'action' => 'showajax',$school->dst_schluessel), true); ?>",
data: JSON.stringify(hot.getData()),
type: 'POST',
success: function (res) {
//console.log(res);
//var data = JSON.parse(res);
}
});
});
</script>

View File

@@ -1,3 +1,3 @@
h1 {
nav.top-bar.expanded h1 {
color: aliceblue;
}

View File

@@ -18,3 +18,9 @@ div#editbudget.handsontable.htRowHeaders.htColumnHeaders thead th {
padding: 0px;
font-weight: bold;
}
div#showbudget.handsontable.htRowHeaders.htColumnHeaders thead th {
line-height: 10px;
padding: 0px;
font-weight: bold;
}

Binary file not shown.

View File

@@ -0,0 +1,19 @@
04
0001
Size: 28
Budget: Partnerschule Leistungssport
{"id":1,"wl_werteliste_nr":"1502","wl_kurz_bezeichnung":"Partnerschule Leistungssport","schulart":"GY","created":null,"modfied":null}
1
{"id":9,"wl_schooltype_id":4,"snr":"0001","wl_budget_id":1,"count":3,"comment":"Test Edith","year":"2018","created":"2018-04-02T17:29:13+00:00","modified":"2018-04-02T17:33:09+00:00"}
full
Size: 23
Budget: offenes Ganztagsangebot
{"id":4,"wl_werteliste_nr":"1505","wl_kurz_bezeichnung":"offenes Ganztagsangebot","schulart":"GY","created":null,"modfied":null}
4
empty
New: {"wl_schooltype_id":"04","snr":"0001","wl_budget_id":4,"count":"7","comment":"ohne Auto","year":"2018"}
Size: 0
Size: 0
Size: 0
Size: 0
Size: 0

Binary file not shown.