added billing

This commit is contained in:
Jörg Henke
2021-03-05 19:33:49 +01:00
parent 345e2fc740
commit 5ef055156b
23 changed files with 680 additions and 718 deletions

View File

@ -10,16 +10,18 @@ public class DailySummaryBean {
private final String moduleName;
private final String jobName;
private final String duration;
private final String wp;
private final String billingShortcut;
private final String billingCsskey;
private final Double durationHours;
public DailySummaryBean(String projectName, String moduleName, String jobName, String duration, String wp, Double durationHours) {
public DailySummaryBean(String projectName, String moduleName, String jobName, String duration, String billingShortcut, String billingCsskey, Double durationHours) {
super();
this.projectName = projectName;
this.moduleName = moduleName;
this.jobName = jobName;
this.duration = duration;
this.wp = wp;
this.billingShortcut = billingShortcut;
this.billingCsskey = billingCsskey;
this.durationHours = durationHours;
}
@ -40,10 +42,17 @@ public class DailySummaryBean {
}
/**
* @return the wp
* @return the billing shortcut
*/
public String getWp() {
return wp;
public String getBillingShortcut() {
return billingShortcut;
}
/**
* @return the billing csskey
*/
public String getBillingCsskey() {
return billingCsskey;
}
/**

View File

@ -7,9 +7,9 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;
import de.jottyfan.timetrack.db.done.tables.records.TBillingRecord;
import de.jottyfan.timetrack.db.done.tables.records.TDoneRecord;
import de.jottyfan.timetrack.db.done.tables.records.TJobRecord;
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
@ -32,31 +32,20 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
private TProjectRecord project;
private TModuleRecord module;
private TJobRecord activity;
private WpBean wp;
private TBillingRecord billing;
public DoneBean() {
}
public DoneBean(TDoneRecord r, Map<Integer, TProjectRecord> projectMap, Map<Integer, TModuleRecord> moduleMap,
Map<Integer, TJobRecord> jobMap) {
Map<Integer, TJobRecord> jobMap, Map<Integer, TBillingRecord> billingMap) {
this.pk = r.getPk();
this.timeFrom = r.getTimeFrom();
this.timeUntil = r.getTimeUntil();
this.project = projectMap.get(r.getFkProject());
this.module = moduleMap.get(r.getFkModule());
this.activity = jobMap.get(r.getFkJob());
List<WpBean> list = DoneGateway.getAllWps();
String key = r.getWp();
if (key != null && key.isBlank()) {
key = null;
}
if (key != null) {
for (WpBean bean : list) {
if (bean.getKey().equals(r.getWp())) {
this.wp = bean;
}
}
}
this.billing = billingMap.get(r.getFkBilling());
}
/**
@ -133,11 +122,11 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
return ldt;
}
public String getProjectNameWithWP() {
public String getProjectNameWithBilling() {
StringBuilder buf = new StringBuilder();
buf.append(project == null ? "" : project.getName());
if (wp != null) {
buf.append(" (").append(wp.getKey()).append(")");
if (billing != null) {
buf.append(" (").append(billing.getShortcut()).append(")");
}
return buf.toString();
}
@ -154,8 +143,8 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
return activity == null ? "" : activity.getName();
}
public String getWpName() {
return wp == null ? "" : wp.getName();
public String getBillingName() {
return billing == null ? "" : billing.getName();
}
public String getTimeFromString() {
@ -223,16 +212,16 @@ public class DoneBean implements Bean, Serializable, Comparable<DoneBean> {
}
/**
* @return the wp
* @return the billing
*/
public WpBean getWp() {
return wp;
public TBillingRecord getBilling() {
return billing;
}
/**
* @param wp the wp to set
* @param billing the billing to set
*/
public void setWp(WpBean wp) {
this.wp = wp;
public void setBilling(TBillingRecord billing) {
this.billing = billing;
}
}

View File

@ -4,6 +4,7 @@ import static de.jottyfan.timetrack.db.done.Tables.T_DONE;
import static de.jottyfan.timetrack.db.done.Tables.T_JOB;
import static de.jottyfan.timetrack.db.done.Tables.T_MODULE;
import static de.jottyfan.timetrack.db.done.Tables.T_PROJECT;
import static de.jottyfan.timetrack.db.done.Tables.T_BILLING;
import static de.jottyfan.timetrack.db.done.Tables.V_HAMSTERSUMMARY;
import static de.jottyfan.timetrack.db.done.Tables.V_TOTALOFDAY;
import static de.jottyfan.timetrack.db.done.Tables.V_WORKTIME;
@ -33,6 +34,7 @@ import org.jooq.Record3;
import org.jooq.Record4;
import org.jooq.Record5;
import org.jooq.Record6;
import org.jooq.Record7;
import org.jooq.SelectConditionStep;
import org.jooq.SelectJoinStep;
import org.jooq.SelectWhereStep;
@ -40,6 +42,7 @@ import org.jooq.UpdateConditionStep;
import org.jooq.exception.DataAccessException;
import de.jooqfaces.JooqFacesContext;
import de.jottyfan.timetrack.db.done.tables.records.TBillingRecord;
import de.jottyfan.timetrack.db.done.tables.records.TDoneRecord;
import de.jottyfan.timetrack.db.done.tables.records.TJobRecord;
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
@ -125,6 +128,27 @@ public class DoneGateway extends JooqGateway {
return list;
}
}
/**
* get all billings from db
*
* @return billings
* @throws SQLException
* @throws ClassNotFoundException
*/
public List<TBillingRecord> getAllBillings() throws DataAccessException, ClassNotFoundException, SQLException {
try (CloseableDSLContext jooq = getJooq()) {
List<TBillingRecord> list = new ArrayList<>();
SelectWhereStep<TBillingRecord> sql = jooq.selectFrom(T_BILLING);
LOGGER.debug(sql.toString());
for (TBillingRecord r : sql.fetch()) {
list.add(r);
}
list.sort((o1, o2) -> o1 == null || o2 == null || o1.getName() == null || o2.getName() == null ? 0
: o1.getName().compareTo(o2.getName()));
return list;
}
}
private Map<Integer, TProjectRecord> generateProjectMap(List<TProjectRecord> list) {
Map<Integer, TProjectRecord> map = new HashMap<>();
@ -150,6 +174,14 @@ public class DoneGateway extends JooqGateway {
return map;
}
private Map<Integer, TBillingRecord> generateBillingMap(List<TBillingRecord> list) {
Map<Integer, TBillingRecord> map = new HashMap<>();
for (TBillingRecord r : list) {
map.put(r.getPk(), r);
}
return map;
}
/**
* get all from t_done of the given day
*
@ -163,6 +195,7 @@ public class DoneGateway extends JooqGateway {
Map<Integer, TProjectRecord> projectMap = generateProjectMap(getAllProjects());
Map<Integer, TModuleRecord> moduleMap = generateModuleMap(getAllModules());
Map<Integer, TJobRecord> jobMap = generateJobMap(getAllActivities());
Map<Integer, TBillingRecord> billingMap = generateBillingMap(getAllBillings());
if (day == null) {
day = LocalDateTime.now();
@ -185,7 +218,7 @@ public class DoneGateway extends JooqGateway {
// @formatter:on
LOGGER.debug(sql.toString());
for (TDoneRecord r : sql.fetch()) {
list.add(new DoneBean(r, projectMap, moduleMap, jobMap));
list.add(new DoneBean(r, projectMap, moduleMap, jobMap, billingMap));
}
}
list.sort((o1, o2) -> o1 == null || o2 == null ? 0 : o1.compareTo(o2));
@ -203,11 +236,11 @@ public class DoneGateway extends JooqGateway {
Integer fkProject = bean.getProject() == null ? null : bean.getProject().getPk();
Integer fkModule = bean.getModule() == null ? null : bean.getModule().getPk();
Integer fkJob = bean.getActivity() == null ? null : bean.getActivity().getPk();
String wp = bean.getWp() == null ? null : bean.getWp().getKey();
Integer fkBilling = bean.getBilling() == null ? null : bean.getBilling().getPk();
Integer fkLogin = getFkLogin();
try (CloseableDSLContext jooq = getJooq()) {
InsertValuesStep7<TDoneRecord, LocalDateTime, LocalDateTime, Integer, Integer, Integer, String, Integer> sql = jooq
InsertValuesStep7<TDoneRecord, LocalDateTime, LocalDateTime, Integer, Integer, Integer, Integer, Integer> sql = jooq
// @formatter:off
.insertInto(T_DONE,
T_DONE.TIME_FROM,
@ -215,9 +248,9 @@ public class DoneGateway extends JooqGateway {
T_DONE.FK_PROJECT,
T_DONE.FK_MODULE,
T_DONE.FK_JOB,
T_DONE.WP,
T_DONE.FK_BILLING,
T_DONE.FK_LOGIN)
.values(bean.getTimeFrom(), bean.getTimeUntil(), fkProject, fkModule, fkJob, wp, fkLogin);
.values(bean.getTimeFrom(), bean.getTimeUntil(), fkProject, fkModule, fkJob, fkBilling, fkLogin);
// @formatter:on
LOGGER.debug(sql.toString());
sql.execute();
@ -233,7 +266,6 @@ public class DoneGateway extends JooqGateway {
*/
public void update(DoneBean bean) throws DataAccessException, ClassNotFoundException, SQLException {
try (CloseableDSLContext jooq = getJooq()) {
String wp = bean.getWp() == null ? null : bean.getWp().getKey();
UpdateConditionStep<TDoneRecord> sql = jooq
// @formatter:off
.update(T_DONE)
@ -242,7 +274,7 @@ public class DoneGateway extends JooqGateway {
.set(T_DONE.FK_PROJECT, bean.getProject() == null ? null : bean.getProject().getPk())
.set(T_DONE.FK_JOB, bean.getActivity() == null ? null : bean.getActivity().getPk())
.set(T_DONE.FK_MODULE, bean.getModule() == null ? null : bean.getModule().getPk())
.set(T_DONE.WP, wp)
.set(T_DONE.FK_BILLING, bean.getBilling() == null ? null : bean.getBilling().getPk())
.where(T_DONE.PK.eq(bean.getPk()));
// @formatter:on
LOGGER.debug(sql.toString());
@ -312,29 +344,31 @@ public class DoneGateway extends JooqGateway {
public List<DailySummaryBean> getAllJobs(java.util.Date day)
throws DataAccessException, ClassNotFoundException, SQLException {
try (CloseableDSLContext jooq = getJooq()) {
SelectConditionStep<Record6<String, Double, String, String, String, String>> sql = jooq
SelectConditionStep<Record7<String, Double, String, String, String, String, String>> sql = jooq
// @formatter:off
.select(V_WORKTIME.DURATION,
V_WORKTIME.DURATION_HOURS,
V_WORKTIME.PROJECT_NAME,
V_WORKTIME.MODULE_NAME,
V_WORKTIME.JOB_NAME,
V_WORKTIME.WP)
V_WORKTIME.BILLING_SHORTCUT,
V_WORKTIME.BILLING_CSSKEY)
.from(V_WORKTIME)
.where(V_WORKTIME.DAY.eq(new SimpleDateFormat("yyyy-MM-dd").format(day)))
.and(V_WORKTIME.FK_LOGIN.eq(getFkLogin()));
// @formatter:on
LOGGER.debug(sql.toString());
List<DailySummaryBean> list = new ArrayList<>();
for (Record6<String, Double, String, String, String, String> r : sql.fetch()) {
for (Record7<String, Double, String, String, String, String, String> r : sql.fetch()) {
String duration = r.get(V_WORKTIME.DURATION);
Double durationHours = r.get(V_WORKTIME.DURATION_HOURS);
String projectName = r.get(V_WORKTIME.PROJECT_NAME);
String moduleName = r.get(V_WORKTIME.MODULE_NAME);
String jobName = r.get(V_WORKTIME.JOB_NAME);
String wp = r.get(V_WORKTIME.WP);
String billingShortcut = r.get(V_WORKTIME.BILLING_SHORTCUT);
String billingCsskey = r.get(V_WORKTIME.BILLING_CSSKEY);
durationHours = durationHours == null ? null : new BigDecimal(durationHours).setScale(2, RoundingMode.HALF_UP).doubleValue();
list.add(new DailySummaryBean(projectName, moduleName, jobName, duration, wp, durationHours));
list.add(new DailySummaryBean(projectName, moduleName, jobName, duration, billingShortcut, billingCsskey, durationHours));
}
return list;
}
@ -354,7 +388,7 @@ public class DoneGateway extends JooqGateway {
// @formatter:off
.select(T_DONE.TIME_FROM,
T_DONE.TIME_UNTIL,
T_DONE.WP,
T_BILLING.NAME,
T_PROJECT.NAME,
T_MODULE.NAME,
T_JOB.NAME)
@ -362,6 +396,7 @@ public class DoneGateway extends JooqGateway {
.leftJoin(T_PROJECT).on(T_PROJECT.PK.eq(T_DONE.FK_PROJECT))
.leftJoin(T_MODULE).on(T_MODULE.PK.eq(T_DONE.FK_MODULE))
.leftJoin(T_JOB).on(T_JOB.PK.eq(T_DONE.FK_JOB))
.leftJoin(T_BILLING).on(T_BILLING.PK.eq(T_DONE.FK_BILLING))
.where(T_DONE.FK_LOGIN.eq(getFkLogin()));
// @formatter:on
LOGGER.debug(sql.toString());
@ -370,14 +405,14 @@ public class DoneGateway extends JooqGateway {
String projectName = r.get(T_PROJECT.NAME);
String moduleName = r.get(T_MODULE.NAME);
String jobName = r.get(T_JOB.NAME);
String wp = r.get(T_DONE.WP);
String billingName = r.get(T_BILLING.NAME);
LocalDateTime timeFrom = r.get(T_DONE.TIME_FROM);
LocalDateTime timeUntil = r.get(T_DONE.TIME_UNTIL);
StringBuilder buf = new StringBuilder();
buf.append(projectName);
if (wp != null && !wp.isBlank()) {
buf.append(" (").append(wp).append(")");
if (billingName != null && !billingName.isBlank()) {
buf.append(" (").append(billingName).append(")");
}
buf.append(", ");
buf.append(moduleName);
@ -453,18 +488,4 @@ public class DoneGateway extends JooqGateway {
}
return buf.toString();
}
/**
* dummy method to use until a table has been created
*
* @return all valid wps
*/
public static final List<WpBean> getAllWps() {
List<WpBean> list = new ArrayList<>();
list.add(new WpBean("WP2", "WP2 (eucs) - Opal/Mica/..., REST"));
list.add(new WpBean("WP4", "WP4 (eucs) - Square²"));
list.add(new WpBean("WP5", "WP5 (eucs) - SHIP-Datenbereitstellung"));
list.add(new WpBean("NFDI TA3", "TA3 (nfdi) - Mica Dev"));
return list;
}
}

View File

@ -21,6 +21,7 @@ import javax.inject.Named;
import org.jooq.exception.DataAccessException;
import de.jooqfaces.JooqFacesContext;
import de.jottyfan.timetrack.db.done.tables.records.TBillingRecord;
import de.jottyfan.timetrack.db.done.tables.records.TJobRecord;
import de.jottyfan.timetrack.db.done.tables.records.TModuleRecord;
import de.jottyfan.timetrack.db.done.tables.records.TProjectRecord;
@ -41,7 +42,7 @@ public class DoneModel implements Model, Serializable {
private List<TProjectRecord> projects;
private List<TModuleRecord> modules;
private List<TJobRecord> activities;
private List<WpBean> wps;
private List<TBillingRecord> billings;
private List<TimeBean> times;
private List<DailySummaryBean> allJobs;
private WholeDaySummaryBean daySummary;
@ -58,7 +59,7 @@ public class DoneModel implements Model, Serializable {
modules = gw.getAllModules();
activities = gw.getAllActivities();
projects = gw.getAllProjects();
wps = DoneGateway.getAllWps();
billings = gw.getAllBillings();
daySummary = gw.getDaySummary(day);
allJobs = gw.getAllJobs(day);
calendarEvents = gw.getAllCalendarEvents();
@ -211,8 +212,8 @@ public class DoneModel implements Model, Serializable {
buf.append(thatday).append("\t");
buf.append(sdb.getDuration()).append("\t");
buf.append(sdb.getProjectName());
if (sdb.getWp() != null && !sdb.getWp().isBlank()) {
buf.append(" (").append(sdb.getWp()).append(")");
if (sdb.getBillingShortcut() != null && !sdb.getBillingShortcut().isBlank()) {
buf.append(" (").append(sdb.getBillingShortcut()).append(")");
}
buf.append("\t");
buf.append(sdb.getModuleName()).append("\t");
@ -246,8 +247,8 @@ public class DoneModel implements Model, Serializable {
return activities;
}
public List<WpBean> getWps() {
return wps;
public List<TBillingRecord> getBillings() {
return billings;
}
public List<DailySummaryBean> getAllJobs() {

View File

@ -1,34 +0,0 @@
package de.jottyfan.timetrack.modules.done;
import java.io.Serializable;
/**
*
* @author jotty
*
*/
public class WpBean implements Serializable {
private static final long serialVersionUID = 1L;
private final String name;
private final String key;
public WpBean(String key, String name) {
super();
this.key = key;
this.name = name;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the key
*/
public String getKey() {
return key;
}
}