Delete Budgets

This commit is contained in:
2018-04-09 15:45:39 +02:00
parent 4c83767fe7
commit a350bc7228
8 changed files with 399 additions and 115 deletions

View File

@@ -49,7 +49,8 @@ Router::scope('/', function (RouteBuilder $routes) {
* its action called 'display', and we pass a param to select the view file * its action called 'display', and we pass a param to select the view file
* to use (in this case, src/Template/Pages/home.ctp)... * to use (in this case, src/Template/Pages/home.ctp)...
*/ */
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); //$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
$routes->connect('/', ['controller' => 'Budget', 'action' => 'overview']);
/** /**
* ...and connect the rest of 'Pages' controller's URLs. * ...and connect the rest of 'Pages' controller's URLs.

View File

@@ -82,43 +82,54 @@ class BudgetController extends AppController
public function editajax($id = null) { public function editajax($id = null) {
$this->autoRender = false; $this->autoRender = false;
$myfile = fopen(WWW_ROOT . DS . 'files' . DS . 'debug-edit.txt', "w"); $myfile = fopen(WWW_ROOT . DS . 'files' . DS . 'debug-edit.txt', "w");
fwrite($myfile,$id . PHP_EOL); //fwrite($myfile,$id . PHP_EOL);
$data = $this->request->input('json_decode'); $data = $this->request->input('json_decode');
//fwrite($myfile,json_encode($data) . PHP_EOL);
foreach($data as $line) { foreach($data as $line) {
if($line[2] > 0) {
$query = $this->Budget->find('all', [
'conditions' => array('snr' => $line[0], 'wl_budget_id' => $id)
]);
if(!($query->isEmpty())) { //fwrite($myfile,json_encode($line[0]) . PHP_EOL);
$budget = $query->first(); //$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if($budget['count'] != $line[2] ) { //preg_match_all("/$regexp/siU", $line[0], $matches);
//fwrite($myfile,json_encode($line) . PHP_EOL);
$query = $this->Budget->find('all', [
'conditions' => array('snr' => $line[0], 'wl_budget_id' => $id)
]);
if(!($query->isEmpty())) {
$budget = $query->first();
fwrite($myfile,json_encode($budget) . PHP_EOL);
if($budget['count'] != $line[2] ) {
if($line[2] > 0) {
$budget['count'] = $line[2]; $budget['count'] = $line[2];
$this->Budget->save($budget); $this->Budget->save($budget);
fwrite($myfile,'full-count' . PHP_EOL);
} }
if($budget['comment'] != $line[3] ) { else {
$budget['comment'] = $line[3]; $this->Budget->delete($budget);
$this->Budget->save($budget);
fwrite($myfile,'full-comment' . PHP_EOL);
} }
fwrite($myfile,'full-count' . PHP_EOL);
} }
else { if($budget['comment'] != $line[3] ) {
fwrite($myfile,'empty' . PHP_EOL); $budget['comment'] = $line[3];
$new = $this->Budget->newEntity(); $this->Budget->save($budget);
$new_budget['wl_schooltype_id'] = 4; fwrite($myfile,'full-comment' . PHP_EOL);
$new_budget['snr'] = $line[0];
$new_budget['wl_budget_id'] = $id;
$new_budget['count'] = $line[2];
$new_budget['comment'] = $line[3];
$new_budget['year'] = '2018';
$new = $this->Budget->patchEntity($new, $new_budget);
$this->Budget->save($new);
} }
fwrite($myfile,serialize($budget). PHP_EOL);
fwrite($myfile,$line[0] . ' ' .($i-1) . ' ' . $line[$i]. PHP_EOL);
} }
else {
fwrite($myfile,'empty' . PHP_EOL);
$new = $this->Budget->newEntity();
$new_budget['wl_schooltype_id'] = 4;
$new_budget['snr'] = $line[0];
$new_budget['wl_budget_id'] = $id;
$new_budget['count'] = $line[2];
$new_budget['comment'] = $line[3];
$new_budget['year'] = '2018';
$new = $this->Budget->patchEntity($new, $new_budget);
$this->Budget->save($new);
}
//fwrite($myfile,serialize($budget). PHP_EOL);
//fwrite($myfile,$line[0] . ' ' .($i-1) . ' ' . $line[$i]. PHP_EOL);
} }
fclose($myfile); fclose($myfile);
} }
@@ -140,11 +151,15 @@ class BudgetController extends AppController
$this->autoRender = false; $this->autoRender = false;
$myfile = fopen(WWW_ROOT . DS . 'files' . DS . 'debug.txt', "w"); $myfile = fopen(WWW_ROOT . DS . 'files' . DS . 'debug.txt', "w");
$data = $this->request->input('json_decode'); $data = $this->request->input('json_decode');
//fwrite($myfile,json_encode($data) . PHP_EOL);
//fwrite($myfile,'hallo' . PHP_EOL);
// neue und geänderte Daten eintragen
foreach($data as $line) { foreach($data as $line) {
for($i=2;$i < sizeof($line);$i++) { for($i=2;$i < sizeof($line);$i++) {
if($line[$i] > 0) { if($line[$i] > 0) {
//$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
preg_match_all("/$regexp/siU", $line[0], $matches);
//fwrite($myfile,$matches[3][0] . PHP_EOL);
$query = $this->Budget->find('all', [ $query = $this->Budget->find('all', [
'conditions' => array('snr' => $line[0], 'wl_budget_id' => $i+$wl_offset) 'conditions' => array('snr' => $line[0], 'wl_budget_id' => $i+$wl_offset)
]); ]);
@@ -155,10 +170,10 @@ class BudgetController extends AppController
$budget['count'] = $line[$i]; $budget['count'] = $line[$i];
$this->Budget->save($budget); $this->Budget->save($budget);
} }
fwrite($myfile,'full' . PHP_EOL); //fwrite($myfile,'full' . PHP_EOL);
} }
else { else {
fwrite($myfile,'empty' . PHP_EOL); //fwrite($myfile,'empty' . PHP_EOL);
$new = $this->Budget->newEntity(); $new = $this->Budget->newEntity();
$new_budget['wl_schooltype_id'] = $schooltype_id; $new_budget['wl_schooltype_id'] = $schooltype_id;
$new_budget['snr'] = $line[0]; $new_budget['snr'] = $line[0];
@@ -171,11 +186,35 @@ class BudgetController extends AppController
$this->Budget->save($new); $this->Budget->save($new);
} }
fwrite($myfile,serialize($budget). PHP_EOL); //fwrite($myfile,serialize($budget). PHP_EOL);
fwrite($myfile,$line[0] . ' ' .($i+$wl_offset) . ' ' . $line[$i]. PHP_EOL); //fwrite($myfile,$line[0] . ' ' .($i+$wl_offset) . ' ' . $line[$i]. PHP_EOL);
} }
} }
} }
// wurde etwas gelöscht?
$dbdata = $this->Budget->find('all', [
'conditions' => array('wl_schooltype_id' => $schooltype_id)
]);
foreach($dbdata as $entry) {
fwrite($myfile,json_encode($entry) . PHP_EOL);
fwrite($myfile,$entry->snr . PHP_EOL);
$value = array_search($entry->snr,array_column($data,0));
fwrite($myfile,json_encode($value). PHP_EOL);
fwrite($myfile,json_encode($data[$value]). PHP_EOL);
fwrite($myfile,json_encode($data[$value][$entry->wl_budget_id - $wl_offset]). PHP_EOL);
if($data[$value][$entry->wl_budget_id - $wl_offset] > 0) {
fwrite($myfile,'passt' . PHP_EOL);
}
else {
fwrite($myfile,'loeschen' . PHP_EOL);
//$budget = $this->Budget->get($id);
$this->Budget->delete($entry);
}
}
fclose($myfile); fclose($myfile);
} }
@@ -193,7 +232,7 @@ class BudgetController extends AppController
$offset = 1; $offset = 1;
} }
$wlBudgets = $this->Budget->wlBudgets->find('list', [ $wlBudgets = $this->Budget->wlBudgets->find('all', [
'conditions' => array('schulart' => $schulart) 'conditions' => array('schulart' => $schulart)
]); ]);
//debug($wlBudgets);die; //debug($wlBudgets);die;
@@ -305,7 +344,7 @@ class BudgetController extends AppController
$exports = $this->Budget->find('all', [ $exports = $this->Budget->find('all', [
'contain' => ['WlBudgets'], 'contain' => ['WlBudgets'],
'fields' => ['Budget.snr','WlBudgets.wl_werteliste_id','WlBudgets.wl_kurz_bezeichnung','Budget.count','Budget.comment'] 'fields' => ['Budget.snr','WlBudgets.wl_werteliste_nr','WlBudgets.wl_kurz_bezeichnung','Budget.count','Budget.comment']
]); ]);
$data = array(); $data = array();
foreach($exports as $export) { foreach($exports as $export) {

View File

@@ -21,58 +21,63 @@ class SchoolsController extends AppController
$data = $this->request->input('json_decode'); $data = $this->request->input('json_decode');
$this->loadModel('Budget'); $this->loadModel('Budget');
$this->loadModel('wl_Budgets'); $this->loadModel('wl_Budgets');
fwrite($myfile,$schooltype . PHP_EOL); //fwrite($myfile,$schooltype . PHP_EOL);
fwrite($myfile,$snr . PHP_EOL); fwrite($myfile,$snr . PHP_EOL);
foreach($data as $line) { foreach($data as $line) {
fwrite($myfile,'Size: ' . strlen($line[0]) . PHP_EOL); fwrite($myfile,json_encode($line) . PHP_EOL);
if(strlen($line[0]) > 0) { //fwrite($myfile,'Size: ' . strlen($line[0]) . PHP_EOL);
fwrite($myfile,'Budget: ' . $line[0] . PHP_EOL); if(strlen($line[0]) > 0) {
$query = $this->wl_Budgets->find('all', [ //fwrite($myfile,'Budget: ' . $line[0] . PHP_EOL);
'conditions' => array('wl_kurz_bezeichnung' => $line[0]) $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); $wl_budget = $query->first();
$query = $this->Budget->find('all', [ //fwrite($myfile,json_encode($wl_budget). PHP_EOL);
'conditions' => array('snr' => $snr, 'wl_budget_id' => $wl_budget['id']) $query = $this->Budget->find('all', [
]); 'conditions' => array('snr' => $snr, 'wl_budget_id' => $wl_budget['id'])
fwrite($myfile,$wl_budget['id'] . PHP_EOL); ]);
//fwrite($myfile,$wl_budget['id'] . PHP_EOL);
if(!($query->isEmpty())) { if(!($query->isEmpty())) {
$budget = $query->first(); $budget = $query->first();
fwrite($myfile,json_encode($budget). PHP_EOL); //fwrite($myfile,json_encode($budget). PHP_EOL);
if($budget['wl_budget_id'] != $wl_budget['id'] ) { if($budget['wl_budget_id'] != $wl_budget['id'] ) {
$budget['wl_budget_id'] = $wl_budget['id']; $budget['wl_budget_id'] = $wl_budget['id'];
$this->Budget->save($budget); $this->Budget->save($budget);
} }
elseif($budget['count'] != $line[1] ) { elseif($budget['count'] != $line[1] ) {
if($line[1] > 0) {
$budget['count'] = $line[1]; $budget['count'] = $line[1];
$this->Budget->save($budget); $this->Budget->save($budget);
} }
elseif($budget['comment'] != $line[2] ) { else {
$budget['comment'] = $line[2]; $this->Budget->delete($budget);
$this->Budget->save($budget);
} }
fwrite($myfile,'full' . PHP_EOL);
} }
else { elseif($budget['comment'] != $line[2] ) {
fwrite($myfile,'empty' . PHP_EOL); $budget['comment'] = $line[2];
$new = $this->Budget->newEntity(); $this->Budget->save($budget);
$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,'full' . PHP_EOL);
//fwrite($myfile,$line[0] . ' ' .($i+$wl_offset) . ' ' . $line[$i]. 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); fclose($myfile);
} }

View File

@@ -1,7 +1,7 @@
<?php <?php
//debug($data); //debug($data);
for($i=0;$i<sizeof($data);$i++) { for($i=0;$i<sizeof($data);$i++) {
$data[$i][0] = $this->Html->link($data[$i][0],array('controller' => 'schools', 'action' => 'showbudgets',$data[$i][0])); $data[$i][1] = $this->Html->link($data[$i][1],array('controller' => 'schools', 'action' => 'showbudgets',$data[$i][0]));
} }
echo '<h2>' . $budget['wl_kurz_bezeichnung'] .'</h2>'; echo '<h2>' . $budget['wl_kurz_bezeichnung'] .'</h2>';
//debug($data); //debug($data);
@@ -29,7 +29,7 @@ var data = <?php echo json_encode($data); ?>;
wordWrap: false, wordWrap: false,
colHeaders: ['SNR','Name','Count','Comment'] , colHeaders: ['SNR','Name','Count','Comment'] ,
colWidths: ['50','500','50','500'], colWidths: ['50','500','50','500'],
columns: [{renderer: "html", readOnly: true},{renderer: "text", readOnly: true},{renderer: "text"},{renderer: "text"}], columns: [{renderer: "text", readOnly: true},{renderer: "html", readOnly: true},{renderer: "text"},{renderer: "text"}],
filters: true, filters: true,
dropdownMenu: true dropdownMenu: true
}); });

View File

@@ -1,29 +1,39 @@
<?php <?php
//$test = '["<a href=\"test\">SNR<\/a>","Schule","RS Modellversuch","RS geb. Ganztagsklassen","RS St\u00fctzpunktschule Schulsport","RS Partnerschule Wintersport","RS Sonderp\u00e4d. F\u00f6rderbedarf","Abordnung Grundschullehrkraft","Bilingualer Unterricht","Inklusion","sonstige Budgetzuschl\u00e4ge","RS Koop. mit and. Schulart","RS Integrierte Lehrerres.","RS Bestenf\u00f6rderung","MINT","Musikrealschule"]';
$cols = array(); $cols = array();
$columns = array();
array_push($cols,'SNR'); array_push($cols,'SNR');
array_push($columns,['renderer' => 'text', 'readOnly' => true]);
array_push($cols,'Schule'); array_push($cols,'Schule');
array_push($columns,['renderer' => 'html', 'readOnly' => true]);
$col_width = array(); $col_width = array();
array_push($col_width,'50'); array_push($col_width,'50');
array_push($col_width,'300'); array_push($col_width,'300');
foreach($wlBudgets as $budget) { foreach($wlBudgets as $budget) {
array_push($cols,$budget); //debug($budget);die;
array_push($cols,$this->Html->link($budget['wl_kurz_bezeichnung'],array('controller' => 'budget', 'action' => 'edit-budget',$budget['id'])));
array_push($col_width,'30'); array_push($col_width,'30');
array_push($columns,['renderer' => 'text']);
} }
for($i=0;$i<sizeof($data);$i++) {
$data[$i][1] = $this->Html->link($data[$i][1],array('controller' => 'schools', 'action' => 'showbudgets',$data[$i][0]));
}
//debug($columns);
//debug(json_encode($columns));die;
//debug(json_encode($cols)); //debug(json_encode($cols));
?> ?>
<div class="controls"> <div class="controls">
<button name="load" id="load" class="intext-btn">Load</button> <button name="load" id="load" class="intext-btn">Load</button>
<button name="save" id="save" class="intext-btn">Save</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> </div>
<pre id="example1console" class="console">Data loaded</pre> <div id="overview"></div>
<div id="example"></div>
<script> <script>
var data = <?php echo json_encode($data); ?>; var data = <?php echo json_encode($data); ?>;
var container = document.getElementById('example'); var container = document.getElementById('overview');
var exampleConsole = document.getElementById('example1console');
var autosave = document.getElementById('autosave');
var load = document.getElementById('load'); var load = document.getElementById('load');
var save = document.getElementById('save'); var save = document.getElementById('save');
var autosaveNotification; var autosaveNotification;
@@ -35,6 +45,7 @@ var data = <?php echo json_encode($data); ?>;
height: 1000, height: 1000,
rowHeaders: true, rowHeaders: true,
wordWrap: false, wordWrap: false,
columns: <?php echo json_encode($columns) ?> ,
colHeaders: <?php echo json_encode($cols) ?> , colHeaders: <?php echo json_encode($cols) ?> ,
colWidths: <?php echo json_encode($col_width) ?>, colWidths: <?php echo json_encode($col_width) ?>,
filters: true, filters: true,
@@ -51,7 +62,8 @@ var data = <?php echo json_encode($data); ?>;
//console.log(hot.getData()); //console.log(hot.getData());
//console.log(JSON.stringify({data: hot.getData()})); //console.log(JSON.stringify({data: hot.getData()}));
$.ajax({ $.ajax({
url: "sajax", //url: "sajax",
url: "<?php echo $this->Url->build(array('controller' => 'budget', 'action' => 'sajax',$budget['id']), true); ?>",
data: JSON.stringify(hot.getData()), data: JSON.stringify(hot.getData()),
type: 'POST', type: 'POST',
success: function (res) { success: function (res) {

View File

@@ -1,4 +1,241 @@
6 {"id":11,"wl_schooltype_id":2,"snr":"0402","wl_budget_id":33,"count":5,"comment":"auto","year":"2018","created":"2018-04-04T09:10:38+00:00","modified":"2018-04-04T09:10:38+00:00"}
{"id":18,"wl_schooltype_id":2,"snr":"0403","wl_budget_id":33,"count":3,"comment":"Aichach rules","year":"2018","created":"2018-04-06T11:58:36+00:00","modified":"2018-04-09T09:23:00+00:00"}
{"id":23,"wl_schooltype_id":4,"snr":"0405","wl_budget_id":33,"count":8,"comment":"rein damit","year":"2018","created":"2018-04-09T09:33:09+00:00","modified":"2018-04-09T09:33:09+00:00"}
full-count
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty
empty empty
N;
0008 -1

View File

@@ -1,19 +1,9 @@
04 0402
0001 ["RS Modellversuch",7,"auto"]
Size: 28 ["MINT",3,"Computer"]
Budget: Partnerschule Leistungssport ["Bilingualer Unterricht",4,"auto"]
{"id":1,"wl_werteliste_nr":"1502","wl_kurz_bezeichnung":"Partnerschule Leistungssport","schulart":"GY","created":null,"modfied":null} ["RS geb. Ganztagsklassen","2","Test"]
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.