Upload by budget

This commit is contained in:
2018-05-11 13:10:28 +02:00
parent 9ef747a51e
commit f419ce6c23
17 changed files with 749 additions and 326 deletions

View File

@@ -60,10 +60,71 @@ class BudgetController extends AppController
}
public function editBudget($id = null) {
$session = $this->request->session();
//debug($session->read('SchoolType'));die;
$schooltype = $session->read('SchoolType');
//debug($schooltype);
if($schooltype == '02') {
$schooltype_nr = 2;
}
else {
$schooltype_nr = 4;
}
//debug($this->referer());
$budget_id = $this->request->params['pass'][0];
//debug($budget_id);
$uploadData = '';
if ($this->request->is('post')) {
if(!empty($this->request->data['file']['name'])){
$result = $this->Budget->deleteAll(['wl_budget_id' => $budget_id]);
//debug($result);die;
$handle = fopen($this->request->data['file']['tmp_name'], "r");
$head = true;
$snr_arr = array();
if ($handle) {
while (($line = fgets($handle)) !== false) {
if(strlen($line) > 2) {
if($head) {
$headers = explode(';',$line);
$head = false;
}
else {
$line_arr = explode(';',$line);
if(!isset($snr_arr[$line_arr[0]])) {
$new_budget['wl_schooltype_id'] = $schooltype_nr;
$new_budget['snr'] = $line_arr[0];
$new_budget['wl_budget_id'] = $budget_id;
$new_budget['count'] = $line_arr[1];
$new_budget['comment'] = trim($line_arr[2]);
$new_budget['year'] = '2018';
$new_budget['asd'] = false;
$snr_arr[$line_arr[0]] = $new_budget;
}
else {
$snr_arr[$line_arr[0]]['count'] = $snr_arr[$line_arr[0]]['count'] + $line_arr[1];
//debug($snr_arr[$line_arr[0]]);
}
}
}
}
fclose($handle);
}
//debug($snr_arr);die;
foreach ($snr_arr as $item) {
//debug($item);
$new = $this->Budget->newEntity();
$new = $this->Budget->patchEntity($new, $item);
$result = $this->Budget->save($new);
//debug($result);die;
}
//die;
} else {
$this->Flash->error(__('Please choose a file to upload.'));
}
}
$this->set('uploadData', $uploadData);
$this->loadModel('Schools');
$schools = $this->Schools->find('all', [
'conditions' => array('dst_schulart' => $schooltype)
@@ -81,10 +142,14 @@ class BudgetController extends AppController
'conditions' => array('wl_budget_id' => $id)
]);
foreach($budgets as $budget) {
foreach($budgets as $budget) {
//debug($budget);
$data[$budget['snr']][2] = $budget['count'];
$data[$budget['snr']][3] = $budget['comment'];
$data[$budget['snr']][4] = $budget['asd'];
}
//debug($data);
//die;
$data_arr = array();
foreach($data as $entry) {
array_push($data_arr,$entry);
@@ -129,6 +194,7 @@ class BudgetController extends AppController
if($budget['count'] != $line[2] ) {
if($line[2] > 0) {
$budget['count'] = $line[2];
$budget['asd'] = 0;
$this->Budget->save($budget);
}
else {
@@ -138,6 +204,7 @@ class BudgetController extends AppController
}
if($budget['comment'] != $line[3] ) {
$budget['comment'] = $line[3];
$budget['asd'] = 0;
$this->Budget->save($budget);
fwrite($myfile,'full-comment' . PHP_EOL);
}
@@ -151,6 +218,7 @@ class BudgetController extends AppController
$new_budget['count'] = $line[2];
$new_budget['comment'] = $line[3];
$new_budget['year'] = '2018';
$new_budget['asd'] = 0;
$new = $this->Budget->patchEntity($new, $new_budget);
$this->Budget->save($new);
}
@@ -418,15 +486,50 @@ class BudgetController extends AppController
}
public function writeBudgetById($budget_id) {
//debug($budget_id);die;
$curl = new AsdUp();
$ch = $curl->init_curl_params();
$curl->login_school($ch); //Login Schulportal
$curl->login_asd($ch); //Login ASD Applikation
$budget_typ = $this->Budget->wlBudgets->get($budget_id);
//debug($budget_typ);
$curl->goto_budget($ch,$budget_typ['schulart']);
//debug($curl->html);
$output = array();
$budgets = $this->Budget->find('all',[
'conditions' => ['wl_budget_id' => $budget_id,'asd' => 0],
'limit' => 100
]);
foreach ($budgets as $budget) {
$curl->change_school($ch,$budget['snr']);
$budget['wl_werteliste_nr'] = $budget_typ['wl_werteliste_nr'];
//echo $curl->html;
$pos = strpos($curl->html,'class="hideOverflow200px" title="'. $budget_typ['wl_kurz_bezeichnung']. '"'); //ist das Budget schon eingetragen?
//debug($pos);
if(!$pos) {
$curl->write_budget($ch,$budget);
$budget->asd = true;
$this->Budget->save($budget);
array_push($output,$budget);
}
}
$this->set('output',$output);
}
public function writeAsd()
{
$curl = new AsdUp();
//debug($curl->status);
$ch = $curl->init_curl_params();
//$curl->login_school($ch); //Login Schulportal
$curl->login_asd($ch);
//debug($ch);
$curl->login_school($ch); //Login Schulportal
//debug($curl->html);
$curl->login_asd($ch);
debug($curl->html);
die;
$budget['snr'] = '9310';
$budget['budget_id'] = '1519';
$budget['count'] = '5';