Skip to content

Commit

Permalink
Konten: #10 : Feld für Detailbeschreibung zu Konten hinzugefügt
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgang-wiedermann committed Jan 4, 2020
1 parent 87110c5 commit 4515224
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 17 deletions.
58 changes: 41 additions & 17 deletions controller/KontoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getKonto($id) {
$erg = mysqli_fetch_object($rs);
mysqli_close($db);
return wrap_response($erg);
} else throw Exception("Kontonummer nicht numerisch");
} else throw new Exception("Kontonummer nicht numerisch");
}

# Ermittelt den aktuellen Saldo des Kontos
Expand All @@ -62,7 +62,7 @@ function getSaldo($id) {
$erg = mysqli_fetch_object($rs);
mysqli_close($db);
return wrap_response($erg->saldo);
} else throw Exception("Kontonummer nicht numerisch");
} else throw new Exception("Kontonummer nicht numerisch");
}

# Erstellt eine Liste aller Kontenarten
Expand All @@ -79,34 +79,57 @@ function getKonten() {

# Speichert das als JSON-Objekt übergebene Konto
function saveKonto($request) {
$db = getDbConnection();
$db = getPdoConnection();
$inputJSON = file_get_contents('php://input');
$input = json_decode( $inputJSON, TRUE );
if($this->isValidKonto($input)) {
$sql = "update fi_konto set bezeichnung = '".$input['bezeichnung']."', kontenart_id = ".$input['kontenart_id']
." where kontonummer = ".$input['kontonummer']." and mandant_id = ".$this->mandant_id;
mysqli_query($db, $sql);
mysqli_close($db);
$void = array();
return wrap_response($void);
$sql = "update fi_konto set bezeichnung = :bezeichnung, kontenart_id = :kontenart_id, beschreibung = :beschreibung "
."where mandant_id = :mandant_id and kontonummer = :kontonummer";

$stmt = $db->prepare($sql);
$stmt->bindParam(":mandant_id", $this->mandant_id);
$stmt->bindParam(":kontonummer", $input['kontonummer']);
$stmt->bindParam(":bezeichnung", $input['bezeichnung']);
$stmt->bindParam(":beschreibung", $input['beschreibung']);
$stmt->bindParam(":kontenart_id", $input['kontenart_id']);

try {
$stmt->execute();
$void = array();
return wrap_response($void);
} catch(Exception $e) {
return wrap_response("ERROR: ". $e);
}
} else {
throw new Exception("Kontenobjekt enthaelt ungueltige Zeichen");
}
}

# legt das als JSON-Objekt übergebene Konto an
function createKonto($request) {
$db = getDbConnection();
$db = getPdoConnection();
$inputJSON = file_get_contents('php://input');
$input = json_decode( $inputJSON, TRUE );
if($this->isValidKonto($input)) {
$sql = "insert into fi_konto (kontonummer, bezeichnung, kontenart_id, mandant_id) values ('"
.$input['kontonummer']."', '".$input['bezeichnung']
."', ".$input['kontenart_id'].", ".$this->mandant_id.")";
mysqli_query($db, $sql);
mysqli_close($db);
$void = array();
return wrap_response($void);
$sql = "insert into fi_konto "
."(kontonummer, bezeichnung, beschreibung, kontenart_id, mandant_id) "
."values "
."(:kontonummer, :bezeichnung, :beschreibung, :kontenart_id, :mandant_id)";

$stmt = $db->prepare($sql);
$stmt->bindParam(":mandant_id", $this->mandant_id);
$stmt->bindParam(":kontonummer", $input['kontonummer']);
$stmt->bindParam(":bezeichnung", $input['bezeichnung']);
$stmt->bindParam(":beschreibung", $input['beschreibung']);
$stmt->bindParam(":kontenart_id", $input['kontenart_id']);

try {
$stmt->execute();
$void = array();
return wrap_response($void);
} catch(Exception $e) {
return wrap_response("ERROR: ". $e);
}
} else {
throw new Exception("Kontenobjekt enthaelt ungueltige Zeichen");
}
Expand All @@ -132,6 +155,7 @@ function isValidFieldAndValue($key, $value) {
case 'mandant_id':
return is_numeric($value);
case 'bezeichnung':
case 'beschreibung':
case 'tostring':
$pattern = '/[\']/';
preg_match($pattern, $value, $results);
Expand Down
2 changes: 2 additions & 0 deletions html/forms/konten/konten_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<input type="text" id="k_kontonummer" data-bind="value: kontonummer">
<label for="k_bezeichnung" data-bind="text:$root.i18n.konten.konto_bezeichnung"></label>
<input type="text" id="k_bezeichnung" data-bind="value: bezeichnung">
<label for="k_beschreibung" data-bind="text:$root.i18n.konten.konto_beschreibung"></label>
<input type="text" id="k_beschreibung" data-bind="value: beschreibung">
<label for="k_kontenart" data-bind="text:$root.i18n.konten.konto_art"></label>
<select id="k_kontenart" data-bind="value: kontenart_id, options: $root.kontenarten,
optionsValue: 'kontenart_id', optionsText: 'bezeichnung'"></select>
Expand Down
2 changes: 2 additions & 0 deletions html/forms/konten/konten_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ hhb.model.types.Konto = function(config) {

self.kontonummer = ko.observable("0000");
self.bezeichnung = ko.observable("");
self.beschreibung = ko.observable("");
self.kontenart_id = ko.observable(0);
self.mandant_id = ko.observable(0);

Expand All @@ -41,6 +42,7 @@ hhb.model.types.Konto = function(config) {
if(!!config) {
self.kontonummer(config.kontonummer);
self.bezeichnung(config.bezeichnung);
self.beschreibung(config.beschreibung);
self.kontenart_id(config.kontenart_id);
self.mandant_id(config.mandant_id);
}
Expand Down
1 change: 1 addition & 0 deletions html/i18n/lang-de.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ hhb.i18n = {
speichern_button:'Speichern',
konto_nummer:'Kontonummer',
konto_bezeichnung:'Bezeichnung',
konto_beschreibung: 'Beschreibung',
konto_art:'Kontenart',
error_on_load:'Fehler beim Laden der Konten aufgetreten',
error_on_load_entries:'Fehler beim Laden der Buchungen des Kontos aufgetreten',
Expand Down
1 change: 1 addition & 0 deletions html/i18n/lang-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ hhb.i18n = {
speichern_button:'Save',
konto_nummer:'Account ID',
konto_bezeichnung:'Description',
konto_beschreibung: 'Details',
konto_art:'Type of account',
error_on_load:'Error loading accounts',
error_on_load_entries:'Error loading the booking entries of the account',
Expand Down
1 change: 1 addition & 0 deletions sql/alter_tables_add_kontodetails.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table `fi_konto` add `beschreibung` varchar(1024) NOT NULL default '';
1 change: 1 addition & 0 deletions sql/create-tables-and-views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ CREATE TABLE IF NOT EXISTS `fi_konto` (
`mandant_id` int(11) NOT NULL,
`kontonummer` varchar(20) NOT NULL,
`bezeichnung` varchar(256) NOT NULL,
`beschreibung` varchar(1024) NOT NULL default '',
`kontenart_id` int(11) NOT NULL,
PRIMARY KEY (`mandant_id`, `kontonummer`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Expand Down

0 comments on commit 4515224

Please sign in to comment.