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() {
|
||||
|
||||
53
src/Template/Budget/edit_budget.ctp
Normal file
53
src/Template/Budget/edit_budget.ctp
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
//debug($budget);
|
||||
echo '<h2>' . $budget['wl_kurz_bezeichnung'] .'</h2>';
|
||||
?>
|
||||
|
||||
<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;
|
||||
var rotated = false;
|
||||
|
||||
var hot = new Handsontable(container, {
|
||||
data: data,
|
||||
width: 1400,
|
||||
height: 1000,
|
||||
rowHeaders: true,
|
||||
wordWrap: false,
|
||||
colHeaders: ['SNR','Name','Count','Comment'] ,
|
||||
colWidths: ['50','500','50','500'],
|
||||
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: "editajax?id=<?php echo $budget['id']; ?>",
|
||||
url: "<?php echo $this->Url->build(array('controller' => 'budget', 'action' => 'editajax',$budget['id']), true); ?>",
|
||||
data: JSON.stringify(hot.getData()),
|
||||
type: 'POST',
|
||||
success: function (res) {
|
||||
//console.log(res);
|
||||
//var data = JSON.parse(res);
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
7
src/Template/Budget/list_budgets.ctp
Normal file
7
src/Template/Budget/list_budgets.ctp
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
foreach ($wlBudgets as $wlBudget) {
|
||||
//debug($wlBudget);
|
||||
echo '<p>' . $this->Html->link($wlBudget['wl_kurz_bezeichnung'],['controller' => 'Budget', 'action' => 'edit_budget' , $wlBudget['id']]) . '</p>';
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -12,3 +12,9 @@
|
||||
.handsontable tr {
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
div#editbudget.handsontable.htRowHeaders.htColumnHeaders thead th {
|
||||
line-height: 10px;
|
||||
padding: 0px;
|
||||
font-weight: bold;
|
||||
}
|
||||
BIN
webroot/files/debug-edit.txt
Normal file
BIN
webroot/files/debug-edit.txt
Normal file
Binary file not shown.
Reference in New Issue
Block a user