budget listBudgets editBudget editajax
This commit is contained in:
@@ -13,13 +13,92 @@ use AsdCurl\AsdUp;
|
||||
*/
|
||||
class BudgetController extends AppController
|
||||
{
|
||||
public function listBudgets() {
|
||||
$wlBudgets = $this->Budget->wlBudgets->find('all', [
|
||||
'conditions' => array('schulart' => 'GY')
|
||||
]);
|
||||
$this->set('wlBudgets',$wlBudgets);
|
||||
}
|
||||
|
||||
public function editBudget($id = null) {
|
||||
$this->loadModel('Schools');
|
||||
$schools = $this->Schools->find('all');
|
||||
$data = array();
|
||||
foreach($schools as $school) {
|
||||
$line = array();
|
||||
array_push($line,$school['dst_schluessel']);
|
||||
array_push($line,$school['dst_name']);
|
||||
array_push($line,'','');
|
||||
$data[$school['dst_schluessel']] = $line;
|
||||
}
|
||||
|
||||
$budgets = $this->Budget->find('all', [
|
||||
'conditions' => array('wl_budget_id' => $id)
|
||||
]);
|
||||
|
||||
foreach($budgets as $budget) {
|
||||
$data[$budget['snr']][2] = $budget['count'];
|
||||
$data[$budget['snr']][3] = $budget['comment'];
|
||||
}
|
||||
$data_arr = array();
|
||||
foreach($data as $entry) {
|
||||
array_push($data_arr,$entry);
|
||||
}
|
||||
$budget = $this->Budget->wlBudgets->get($id);
|
||||
$this->set('budget',$budget);
|
||||
$this->set('data',$data_arr);
|
||||
}
|
||||
|
||||
public function editajax($id = null) {
|
||||
$this->autoRender = false;
|
||||
$myfile = fopen(WWW_ROOT . DS . 'files' . DS . 'debug-edit.txt', "w");
|
||||
fwrite($myfile,$id . PHP_EOL);
|
||||
$data = $this->request->input('json_decode');
|
||||
|
||||
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())) {
|
||||
$budget = $query->first();
|
||||
if($budget['count'] != $line[2] ) {
|
||||
$budget['count'] = $line[2];
|
||||
$this->Budget->save($budget);
|
||||
fwrite($myfile,'full-count' . PHP_EOL);
|
||||
}
|
||||
if($budget['comment'] != $line[3] ) {
|
||||
$budget['comment'] = $line[3];
|
||||
$this->Budget->save($budget);
|
||||
fwrite($myfile,'full-comment' . 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);
|
||||
}
|
||||
|
||||
public function sajax() {
|
||||
$this->autoRender = false;
|
||||
$myfile = fopen(WWW_ROOT . DS . 'files' . DS . 'debug.txt', "w");
|
||||
$data = $this->request->input('json_decode');
|
||||
|
||||
foreach($data as $line) {
|
||||
//fwrite($myfile,json_encode($line). PHP_EOL);
|
||||
for($i=2;$i < sizeof($line);$i++) {
|
||||
if($line[$i] > 0) {
|
||||
$query = $this->Budget->find('all', [
|
||||
@@ -54,9 +133,6 @@ class BudgetController extends AppController
|
||||
}
|
||||
}
|
||||
fclose($myfile);
|
||||
//debug(json_encode($this->request->data));
|
||||
//debug($this->request);
|
||||
//return(true);
|
||||
}
|
||||
|
||||
public function overview() {
|
||||
|
||||
Reference in New Issue
Block a user