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

@@ -21,58 +21,63 @@ class SchoolsController extends AppController
$data = $this->request->input('json_decode');
$this->loadModel('Budget');
$this->loadModel('wl_Budgets');
fwrite($myfile,$schooltype . PHP_EOL);
//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);
foreach($data as $line) {
fwrite($myfile,json_encode($line) . PHP_EOL);
//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] ) {
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] ) {
if($line[1] > 0) {
$budget['count'] = $line[1];
$this->Budget->save($budget);
}
elseif($budget['comment'] != $line[2] ) {
$budget['comment'] = $line[2];
$this->Budget->save($budget);
else {
$this->Budget->delete($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);
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);
}