Skip to content

Commit

Permalink
update ReportController
Browse files Browse the repository at this point in the history
  • Loading branch information
fakhriaunur committed Nov 28, 2019
2 parents 3e7345d + 10d3c56 commit d0f722d
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CityModel.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"cityCode":"BDG","cityName":"BANDUNG"}]
[{"cityCode":"BDG","cityName":"BANDUNG"},{"cityCode":null,"cityName":"BDG"}]
2 changes: 1 addition & 1 deletion RwRouteModel.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"route":{"departure":{"cityCode":"JKT","cityName":"Jakarta"},"arrival":{"cityCode":"BDG","cityName":"Bandung"},"routeCode":"JKT-BDG","business":{"price":30000.0},"premium":{"price":20000.0}},"rwRouteCode":"JL01","list":[{"origin":{"rwStationCode":"GMB","rwStationName":"Gambir"},"destination":{"rwStationCode":"JTR","rwStationName":"Jatinegara"},"duration":30},{"origin":{"rwStationCode":"JTR","rwStationName":"Jatinegara"},"destination":{"rwStationCode":"BKS","rwStationName":"Bekasi"},"duration":30}],"sumOfDuration":60}]
[{"route":{"departure":{"cityCode":"JKT","cityName":"Jakarta"},"arrival":{"cityCode":"BDG","cityName":"Bandung"},"routeCode":"JKT-BDG","business":{"price":30000.0},"premium":{"price":20000.0}},"rwRouteCode":"JL01","list":[{"origin":{"rwStationCode":"GMB","rwStationName":"Gambir"},"destination":{"rwStationCode":"JTR","rwStationName":"Jatinegara"},"duration":30},{"origin":{"rwStationCode":"JTR","rwStationName":"Jatinegara"},"destination":{"rwStationCode":"BKS","rwStationName":"Bekasi"},"duration":30}],"sumOfDuration":60},{"route":{"departure":{"cityCode":"BDG","cityName":"Bandung"},"arrival":{"cityCode":"JKT","cityName":"Jakarta"},"routeCode":"BDG-JKT","business":{"price":30000.0},"premium":{"price":20000.0}},"rwRouteCode":"JL02","list":[{"origin":{"rwStationCode":"KAC","rwStationName":"Kiaracondong"},"destination":{"rwStationCode":"CMH","rwStationName":"Cimahi"},"duration":40},{"origin":{"rwStationCode":"JTN","rwStationName":"Jatinegara"},"destination":{"rwStationCode":"GMB","rwStationName":"Gambir"},"duration":30}],"sumOfDuration":70}]
21 changes: 1 addition & 20 deletions RwStationModel.json
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
[{
"rwStationCode": "GMB",
"rwStationName": "Gambir"
}, {
"rwStationCode": "JTN",
"rwStationName": "Jatinegara"
}, {
"rwStationCode": "BDN",
"rwStationName": "Bandung"
}, {
"rwStationCode": "CMH",
"rwStationName": "Cimahi"
}, {
"rwStationCode": "KAC",
"rwStationName": "Kiaracondong"
}, {
"rwStationCode": "SGU",
"rwStationName": "Surabaya Gubeng"
}
]
[{"rwStationCode":"GMB","rwStationName":"Gambir"},{"rwStationCode":"JTN","rwStationName":"Jatinegara"},{"rwStationCode":"CMH","rwStationName":"Cimahi"},{"rwStationCode":"KAC","rwStationName":"Kiaracondong"},{"rwStationCode":"SGU","rwStationName":"GUBENG"},{"rwStationCode":"BDG","rwStationName":"BANDUNG"}]
51 changes: 46 additions & 5 deletions src/main/java/org/kelompok4/app/Controller/ReportController.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,73 @@
package org.kelompok4.app.Controller;

import org.kelompok4.app.Interface.ICanRead;
import org.kelompok4.app.Model.BookingModel;
import org.kelompok4.app.View.ReportView;

public class ReportController implements ICanRead {
private BookingModel bookingModel;
private BookingController bookingController;
//private TrainScheduleModel trainScheduleModel;
private ReportView reportView;


public ReportController(BookingController bookingController, ReportView reportView) {
this.bookingController = bookingController;
this.reportView = reportView;
}

public ReportController() {
this.bookingController = new BookingController();
this.reportView = new ReportView();
}

@Override
public void read() {

}



//unsolid
/**
* Bentuk belum SOLID
*/
public void showDailyReport() {

//data pemasukan harian
reportView.printHeaderDailyReport();
//total masukan harian
reportView.printDailyReportPage();
/**
* Masukin json kumpulan booking yang sudah paid
* dalam rentang satu hari
*/
bookingController.getTotalPayment();
}

public void showMonthlyReport() {
//laporan bulanan pemasukan
reportView.printMonthlyReportPage();
//data pemasukan bulanan
reportView.printHeaderMonthlyReport();
//total masukan bulanan
reportView.printTotalMonthlyReport();
/**
* Masukin json kumpulan booking yang sudah paid
* dalam rentang satu bulan
*/
bookingController.getTotalPayment();

}

public void showAnnualReport() {
//laporan tahunan pemasukan
reportView.printAnnualReportPage();
//data pemasukan tahunan
reportView.printHeaderAnualReport();
//total pemasukan tahunan
reportView.printTotalAnualReport();
/**
* Masukin json kumpulan booking yang sudah paid
* dalam rentang satu tahun
*/
bookingController.getTotalPayment();


}
}
190 changes: 190 additions & 0 deletions src/main/java/org/kelompok4/app/Controller/RwStationController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.kelompok4.app.Controller;

import com.github.freva.asciitable.AsciiTable;
import com.github.freva.asciitable.Column;
import java.util.ArrayList;
import java.util.Arrays;
import org.kelompok4.app.Interface.ICanCreate;
import org.kelompok4.app.Interface.ICanDelete;
import org.kelompok4.app.Interface.ICanRead;
import org.kelompok4.app.Interface.ICanUpdate;
import org.kelompok4.app.Interface.ICanValidateName;
import org.kelompok4.app.Interface.ICanManageRwStation;
import org.kelompok4.app.Model.RwStationModel;
import org.kelompok4.app.Repo.RwStationRepo;
import org.kelompok4.app.View.RwStationView;

/**
*
*
*/
public class RwStationController implements ICanCreate,ICanRead,ICanUpdate,ICanValidateName,ICanDelete, ICanManageRwStation{
private RwStationModel rwStationModel;
private RwStationView rwStationView;
private RwStationRepo rwStationRepo = new RwStationRepo();
public RwStationController(RwStationModel rwStationModel, RwStationView rwStationView) {
this.rwStationModel = rwStationModel;
this.rwStationView = rwStationView;
}

public RwStationModel getRwStationModel() {
return rwStationModel;
}

public void setRwStationModel(RwStationModel rwStationModel) {
this.rwStationModel = rwStationModel;
}

public RwStationView getRwStationView() {
return rwStationView;
}

public void setRwStationView(RwStationView rwStationView) {
this.rwStationView = rwStationView;
}

@Override
public void create() {
rwStationRepo.create(rwStationModel);
}

@Override
public void read() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
public void update() {
rwStationRepo.update(rwStationModel);
}

@Override
public boolean validateName() {
return ICanValidateName.NAME_REGEX.matcher(getRwStationName()).find();
}

@Override
public String getRwStationCode() {
return rwStationModel.getRwStationCode();
}

@Override
public void setRwStationCode(String rwStationCode) {
rwStationModel.setRwStationCode(rwStationCode);
}

@Override
public String getRwStationName() {
return rwStationModel.getRwStationName();
}

@Override
public void setRwStationName(String rwStationName) {
rwStationModel.setRwStationCode(rwStationName);
}
public void addStationView(){
rwStationView.printAddStationPage();
rwStationView.printAddStation();
}

public void editStationView(){
rwStationView.printEditStationPage();
rwStationView.printEditStation();
}

public void showStationView(){
rwStationView.printViewStationPage();
}

public void deleteStationView(){
rwStationView.printDeleteStationPage();
rwStationView.printDeleteStation();
}
public boolean validateCodeStation(){
RwStationModel rwStationModel = rwStationRepo.get(this.getRwStationCode());
if(rwStationModel.getRwStationCode()== null){
return true;
}else{
return false;
}
}
public boolean validateUpdateDeleteCodeStation(){
RwStationModel rwStationModel = rwStationRepo.get(this.getRwStationCode());
if(rwStationModel.getRwStationCode()!= null){
return true;
}else{
return false;
}
}
public ArrayList<RwStationModel> fetchAll(){
return rwStationRepo.getAll();
}
public String allRwStationView(ArrayList<RwStationModel> rwStationModels){
return AsciiTable.getTable(rwStationModels, Arrays.asList(
new Column().header("KODE STASIUN").with(rwStationModel ->rwStationModel.getRwStationCode()),
new Column().header("NAMA STASIUN").with(rwStationModel ->rwStationModel.getRwStationName())));
}
public void resultView(){
rwStationView.printRwStationCode(getRwStationCode());
rwStationView.printRwStationName(getRwStationName());
}
public void resultAddRwStation(boolean success){
if(success){
rwStationView.SuccessAddStation();
}else {
rwStationView.FailedAddStation();
}
}
public void resultEditStation(boolean success){
if(success){
rwStationView.SuccessEditStation();
}else {
rwStationView.FailedEditStation();
}
}

public void resultDeleteStation(boolean success){
if(success){
rwStationView.SuccessDeleteStation();
}else {
rwStationView.FailedDeleteStation();
}
}

public void stationTable(String S){
rwStationView.printShowTable(S);;
}

public boolean validateInputStation(String input) {
boolean valid;
String[] inputs=input.split("\\s+");
if(inputs.length==2){
if(inputs[0].length()==3){
rwStationModel.setRwStationCode(inputs[0]);
valid=true;
}else {
valid=false;
}
rwStationModel.setRwStationName(inputs[1]);
if (validateName()){
valid=true;
}else {
valid=false;
}
}else {
valid=false;
}
return valid;
}

@Override
public void delete() {
setRwStationModel(rwStationRepo.get(getRwStationCode()));
rwStationRepo.delete(rwStationModel);
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/kelompok4/app/Interface/ICanManageRwStation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.kelompok4.app.Interface;

/**
*
* @author Rewingw
*/
public interface ICanManageRwStation {
public String getRwStationCode();
public void setRwStationCode(String rwStationCode);
public String getRwStationName();
public void setRwStationName(String rwStationName);
}
6 changes: 5 additions & 1 deletion src/main/java/org/kelompok4/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.kelompok4.app.Presenter.CityPresenter;
import org.kelompok4.app.Presenter.CustomerMenuPresenter;
import org.kelompok4.app.Presenter.MenuPresenter;
import org.kelompok4.app.Presenter.RwStationPresenter;
import org.kelompok4.app.Presenter.TimePresenter;

public class Main {
Expand Down Expand Up @@ -83,8 +84,11 @@ public static void main(String[] args) throws IOException, InterruptedException
AdminMenuPresenter adminMenuPresenter = new AdminMenuPresenter(menuController, cityPresenter, trainPresenter);
// rwRoutePresenter.run();
MenuPresenter menuPresenter = new MenuPresenter(menuController,loginPresenter,registerPresenter,customerMenuPresenter,adminMenuPresenter);
menuPresenter.run();

// menuPresenter.run();

RwStationPresenter rwStationPresenter = new RwStationPresenter(new RwStationController(new RwStationModel(),new RwStationView()));
rwStationPresenter.run();
}

}
15 changes: 15 additions & 0 deletions src/main/java/org/kelompok4/app/Presenter/AdminMenuPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,31 @@
import org.kelompok4.app.View.TimeView;
import org.kelompok4.app.View.TrainScheduleView;

import org.kelompok4.app.Model.RwStationModel;
import org.kelompok4.app.Model.TimeModel;
import org.kelompok4.app.Model.TrainScheduleModel;
//import org.kelompok4.app.View.RouteTimeView;
//import org.kelompok4.app.View.RouteTrainView;
import org.kelompok4.app.View.RwRouteView;
import org.kelompok4.app.View.RwStationView;
import org.kelompok4.app.View.TimeView;
//import org.kelompok4.app.View.TrainScheduleView;

public class AdminMenuPresenter extends ContinuePresenter implements ICanRun {
MenuController menuController;
CityPresenter cityPresenter;
// RwStasionController rwStasionController;
TrainPresenter trainPresenter ;
TimePresenter timePresenter = new TimePresenter(new TimeController(new TimeModel(),new TimeView()));

RouteTimePresenter routeTimePresenter = new RouteTimePresenter(
new RouteTimeController(new RouteTimeModel(), new RouteTimeView()));
RouteTrainPresenter routeTrainPresenter = new RouteTrainPresenter(
new RouteTrainController(new RouteTrainModel(), new RouteTrainView()));
TrainSchedulePresenter trainSchedulePresenter = new TrainSchedulePresenter(
new TrainScheduleController(new TrainScheduleModel(), new TrainScheduleView()));
RwStationPresenter rwStationPresenter = new RwStationPresenter(new RwStationController(new RwStationModel(),new RwStationView()));

RwRoutePresenter rwRoutePresenter = new RwRoutePresenter(
new RwRouteController(new RwRouteModel(), new RwRouteView()));
// RoutePresenter routePresenter ;
Expand Down Expand Up @@ -124,6 +137,7 @@ private void menu(int choice) {
break;
case 7://Kelola Waktu Pada Rute
System.out.println("//Nyambung ke routeTimePresenter.run()");

routeTimePresenter.run();
break;
case 8://Kelola Kereta Pada Rute
Expand All @@ -133,6 +147,7 @@ private void menu(int choice) {
case 9://Generate Jadwal Kereta Api
System.out.println("//Nyambung ke trainSchedulePresenter.run()");
trainSchedulePresenter.run();

break;
case 10://Lihat Pemasukan
System.out.println("//Nyambung ke reportPresenter.run()");
Expand Down
Loading

0 comments on commit d0f722d

Please sign in to comment.