Skip to content

Commit

Permalink
Initial Release (#1)
Browse files Browse the repository at this point in the history
* Working Navigation and new entries

* removed debug and added default font size

* created dashboard layout

* replaced Umsätze with Ausgaben

* modified css file paths

* changed card layout

* Create LICENSE

* Added License notices

* sql scripts to initialize database

* store and query database settings

* fill dashboard from database

* added unique index

* prepared tables and grants for site new entry

* fill autocomplete and dropdowns from database

* changed dashboard view

* new user she_editor

* new purchases can be added

* Added No Data behavior

* dashboard table as callable script

* added site for all entries

* better defined css tags

* split form.css in detailed and structure

* better defined detailed-form

* Purchase Details now as PopUp

* added checkForm manual start and stop

* added working gui to edit purchases

* submit hidden inputs

* purchases and contributions are now editable

* added different timestamps for created and updated

* purchase editable via all

* restructured filesystem

* new db user concept

* purchase can be deleted

* reload page on successfull edit

* write amount with comma or point

* reload to target site

* show pretty names if available and no duplicates

* fixed maintable

* using version file to display version

* gui for currency_settings.json

* apply currency settings to each page

* changet account_active to account_status

* show active users

* control submit buttons via class

* users are now editable

* corrected format issues

* new users can be created

* removed phpinfo

* correct licence strings and end of file new line

* removed exception printouts

* added docstrings and checked comments

* adjustet logo and favicon

* solved some todo

* removed space

* updated about page

* removed keywords, added description

* added robots.txt

* changed version number

* added Changelog

* first attempt readme

* finalized README

* removed meta no-cache

* added delimiter

* removed currency in contribution table

* removed test data

* catching exception when db connect didnt work

* fix for first purchase in db

* standard value for first user

* added date

* changed image url
  • Loading branch information
intragart authored Jan 1, 2023
1 parent 9e29f76 commit ec539c9
Show file tree
Hide file tree
Showing 53 changed files with 4,768 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config/db_settings.json
config/currency_settings.json
14 changes: 14 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0] - 2023-01-01

### Added

- Initial Release of the Project

[1.0]: https://github.com/intragart/Shared-Household-Expenses/releases/tag/v1.0
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

81 changes: 80 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,80 @@
# Shared-Household-Expenses
# ![Shared Household Expenses](https://github.com/intragart/Shared-Household-Expenses/raw/master/webapp/www/content/img/logo-light.png)

![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/intragart/Shared-Household-Expenses?include_prereleases)
![GitHub last commit](https://img.shields.io/github/last-commit/intragart/Shared-Household-Expenses)
![GitHub license](https://img.shields.io/github/license/intragart/Shared-Household-Expenses)

With this project you can track the household expenses per person. The idea is to achive that each person contributing to the household spends the same amount of money without any need for spreadsheets or shared bank accounts.

## Table of contents

- [Installation](#installation)
- [Database](#database)
- [Webserver](#webserver)
- [Configuration](#configuration)
- [License](#license)

## Installation

### Database

The data is stored in a relational database like MariaDB or MySQL. Create a new database called 'shared_household_expenses' by executing the sql scripts in the follwoing order.

1. database/create_database.sql
1. database/create_tables.sql
1. database/create_views.sql
1. database/create_functions.sql
1. database/create_users.sql

Please make sure use proper passwords when executing 'database/create_users.sql'. You also might want to enable ssl communication to your database server.

### Webserver

Install any webserver that's able to communicate with the database you've choosen and clone this repository. Document root for the webserver is 'webapp/www'. The project doesn't work with file extensions (e. g. .php). Therefore, please configure the webserver to search for .php files with the same name if file/folder couldn't be found.

Example configuration for Apache webserver:

```text
<Directory "/path/to/Shared-Household-Expenses/webapp/www">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
</ifModule>
</Directory>
```

### Configuration

Please find 'db_settings.template.json' in the 'config' folder, copy the json file and rename it to 'db_settings.json'. Fill in the information to access the database within the newly generated file.

Any additional configurations that might be generated by the application during usage will be saved in folder 'config' as well.

## License

Shared Household Expenses\
Copyright (C) 2023 Marco Weingart

This program is free software: you can redistribute it and/or modify\
it under the terms of the GNU General Public License as published by\
the Free Software Foundation, either version 3 of the License, or\
(at your option) any later version.

This program is distributed in the hope that it will be useful,\
but WITHOUT ANY WARRANTY; without even the implied warranty of\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\
GNU General Public License for more details.

You should have received a copy of the GNU General Public License\
along with this program. If not, see <https://www.gnu.org/licenses/>.
19 changes: 19 additions & 0 deletions config/db_settings.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"general" : {
"fqdn" : "127.0.0.1",
"port" : 3306,
"database" : "shared_household_expenses",
"socket" : "ssl"
},

"users" : {
"login" : {
"username" : "she_login",
"password" : "1234"
},
"admin" : {
"username" : "she_admin",
"password" : "1234"
}
}
}
20 changes: 20 additions & 0 deletions database/create_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Shared Household Expenses
Copyright (C) 2023 Marco Weingart
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

DROP DATABASE IF EXISTS `shared_household_expenses`;
CREATE DATABASE `shared_household_expenses` CHARACTER SET `utf8mb4` COLLATE `utf8mb4_unicode_ci`;
50 changes: 50 additions & 0 deletions database/create_functions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Shared Household Expenses
Copyright (C) 2023 Marco Weingart
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

USE `shared_household_expenses`;

DELIMITER $$

CREATE FUNCTION `login`(
`try_username` VARCHAR(255),
`try_password` VARCHAR(255)
)
RETURNS INT
LANGUAGE SQL
DETERMINISTIC
READS SQL DATA
SQL SECURITY DEFINER
COMMENT 'Checks if the given username and password match and returns the user_id. If no match was found or password is incorrect 0 is returned.'
BEGIN

DECLARE returned_user_id INT;

SELECT user_id INTO returned_user_id
FROM user
WHERE username = try_username AND passwd_hash = PASSWORD(try_password)
LIMIT 1;

IF returned_user_id IS NULL THEN
SET returned_user_id = 0;
END IF;

RETURN returned_user_id;

END;
$$
DELIMITER ;
76 changes: 76 additions & 0 deletions database/create_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Shared Household Expenses
Copyright (C) 2023 Marco Weingart
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

USE `shared_household_expenses`;

CREATE TABLE IF NOT EXISTS `retailer` (
`retailer_id` INT(11) NOT NULL AUTO_INCREMENT,
`retailer` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
PRIMARY KEY (`retailer_id`) USING BTREE,
UNIQUE INDEX `retailer` (`retailer`) USING BTREE
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;

CREATE TABLE IF NOT EXISTS `purchase` (
`purchase_id` INT(11) NOT NULL AUTO_INCREMENT,
`timestamp_created` TIMESTAMP NOT NULL DEFAULT current_timestamp(),
`timestamp_updated` TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`article` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`date` DATE NOT NULL,
`retailer_id` INT(11) NOT NULL,
PRIMARY KEY (`purchase_id`) USING BTREE,
INDEX `fk_retailer` (`retailer_id`) USING BTREE,
CONSTRAINT `fk_retailer` FOREIGN KEY (`retailer_id`) REFERENCES `shared_household_expenses`.`retailer` (`retailer_id`) ON UPDATE CASCADE ON DELETE RESTRICT
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;

CREATE TABLE IF NOT EXISTS `user` (
`user_id` INT(11) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`pretty_name` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
`passwd_hash` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_unicode_ci',
`start_value` DECIMAL(20,2) NOT NULL DEFAULT '0.00',
`account_status` SET('READ_WRITE','READ_ONLY','LOCKED','DEACTIVATED') NOT NULL DEFAULT 'READ_WRITE' COLLATE 'utf8mb4_unicode_ci',
PRIMARY KEY (`user_id`) USING BTREE,
UNIQUE INDEX `username` (`username`) USING BTREE,
UNIQUE INDEX `pretty_name` (`pretty_name`) USING BTREE
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;

CREATE TABLE IF NOT EXISTS `contribution` (
`purchase_id` INT(11) NOT NULL,
`contribution_id` INT(11) NOT NULL,
`user_id` INT(11) NOT NULL,
`timestamp_created` TIMESTAMP NOT NULL DEFAULT current_timestamp(),
`timestamp_updated` TIMESTAMP NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`amount` DECIMAL(20,2) NOT NULL,
`comment` VARCHAR(500) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_ci',
PRIMARY KEY (`purchase_id`, `contribution_id`) USING BTREE,
INDEX `fk_user` (`user_id`) USING BTREE,
CONSTRAINT `fk_purchase` FOREIGN KEY (`purchase_id`) REFERENCES `shared_household_expenses`.`purchase` (`purchase_id`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `fk_user` FOREIGN KEY (`user_id`) REFERENCES `shared_household_expenses`.`user` (`user_id`) ON UPDATE CASCADE ON DELETE RESTRICT
)
COLLATE='utf8mb4_unicode_ci'
ENGINE=InnoDB
;
43 changes: 43 additions & 0 deletions database/create_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Shared Household Expenses
Copyright (C) 2023 Marco Weingart
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

USE `shared_household_expenses`;

DROP USER IF EXISTS 'she_login'@'localhost';
CREATE USER 'she_login'@'localhost' IDENTIFIED BY '1234';
GRANT EXECUTE ON FUNCTION shared_household_expenses.login TO 'she_login'@'localhost';

DROP USER IF EXISTS 'she_admin'@'localhost';
CREATE USER 'she_admin'@'localhost' IDENTIFIED BY '1234';
GRANT DELETE ON shared_household_expenses.contribution TO 'she_admin'@'localhost';
GRANT DELETE ON shared_household_expenses.purchase TO 'she_admin'@'localhost';
GRANT INSERT ON shared_household_expenses.contribution TO 'she_admin'@'localhost';
GRANT INSERT ON shared_household_expenses.purchase TO 'she_admin'@'localhost';
GRANT INSERT ON shared_household_expenses.retailer TO 'she_admin'@'localhost';
GRANT INSERT ON shared_household_expenses.user TO 'she_admin'@'localhost';
GRANT SELECT ON shared_household_expenses.article_list TO 'she_admin'@'localhost';
GRANT SELECT ON shared_household_expenses.contribution TO 'she_admin'@'localhost';
GRANT SELECT ON shared_household_expenses.dashboard TO 'she_admin'@'localhost';
GRANT SELECT ON shared_household_expenses.dashboard_detail TO 'she_admin'@'localhost';
GRANT SELECT ON shared_household_expenses.purchase TO 'she_admin'@'localhost';
GRANT SELECT ON shared_household_expenses.retailer TO 'she_admin'@'localhost';
GRANT SELECT ON shared_household_expenses.user TO 'she_admin'@'localhost';
GRANT SELECT ON shared_household_expenses.user_contribution TO 'she_admin'@'localhost';
GRANT UPDATE ON shared_household_expenses.contribution TO 'she_admin'@'localhost';
GRANT UPDATE ON shared_household_expenses.purchase TO 'she_admin'@'localhost';
GRANT UPDATE ON shared_household_expenses.user TO 'she_admin'@'localhost';
65 changes: 65 additions & 0 deletions database/create_views.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Shared Household Expenses
Copyright (C) 2023 Marco Weingart
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

USE `shared_household_expenses`;

CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `dashboard` AS
SELECT purchase.purchase_id, purchase.article, retailer.retailer, purchase.date, SUM(contribution.amount) AS amount,
group_concat(DISTINCT CASE
WHEN user.pretty_name IS NULL THEN user.username
ELSE user.pretty_name
END SEPARATOR ' & ') AS contributor
FROM purchase
LEFT JOIN contribution ON purchase.purchase_id = contribution.purchase_id
LEFT JOIN retailer ON purchase.retailer_id = retailer.retailer_id
LEFT JOIN user ON contribution.user_id = user.user_id
GROUP BY purchase.purchase_id
ORDER BY purchase.date DESC, purchase.article ASC;

CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `user_contribution` AS
SELECT user.user_id, user.username, user.pretty_name,
CASE
WHEN user.pretty_name IS NULL THEN user.username
ELSE user.pretty_name
END display_name,
user.start_value,
CASE
WHEN SUM(contribution.amount) IS NULL THEN 0
ELSE SUM(contribution.amount)
END sum_contributions,
CASE
WHEN SUM(contribution.amount) IS NULL THEN user.start_value
ELSE user.start_value + SUM(contribution.amount)
END sum_user,
user.account_status
FROM user
LEFT JOIN contribution ON user.user_id = contribution.user_id
GROUP BY contribution.user_id
ORDER BY user.username;

CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `dashboard_detail` AS
SELECT contribution.purchase_id, contribution.contribution_id, user.username, contribution.amount, contribution.comment
FROM contribution
LEFT JOIN user ON contribution.user_id = user.user_id
ORDER BY purchase_id ASC, username ASC, contribution_id ASC;

CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `article_list` AS
SELECT article, COUNT(*) AS quantity
FROM purchase
GROUP BY article
ORDER BY article ASC;
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.0
Loading

0 comments on commit ec539c9

Please sign in to comment.