3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.mensaplan;
17 import java.text.DateFormat;
18 import java.text.DecimalFormat;
19 import java.text.ParseException;
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
22 import java.util.Locale;
23 import java.util.zip.CRC32;
25 import de.dhbwloe.campusapp.CampusAppContext;
26 import de.dhbwloe.campusapp.R;
29 * Created by pk910 on 22.01.2016.
31 public class MensaTagesplan {
32 private long iPlanDate;
34 private String sMenuName, sName, sNameHtml, sAdditional, sNotes;
35 private int[] aPriceArray = new int[4];
37 private boolean bIsNew = false;
39 public MensaTagesplan(long plandate, String menuname, long chksum, String name, String namehtml, String additional, String notes, int price1, int price2, int price3, int price4) {
45 sAdditional = (additional == null ? "" : additional);
47 aPriceArray[0] = price1; // Student
48 aPriceArray[1] = price2; // Employees
49 aPriceArray[2] = price3; // Guest
50 aPriceArray[3] = price4; // School
53 public long calculateChkSum() {
54 CRC32 crc = new CRC32();
55 crc.update(sMenuName.getBytes());
57 crc.update(sName.getBytes());
59 crc.update(sNameHtml.getBytes());
60 if(sAdditional!= null)
61 crc.update(sAdditional.getBytes());
63 crc.update(sNotes.getBytes());
64 crc.update(aPriceArray[0]);
65 crc.update(aPriceArray[1]);
66 crc.update(aPriceArray[2]);
67 crc.update(aPriceArray[3]);
69 long crcvalue = crc.getValue();
74 public long getPlanDate() {
78 public String getFormatedDate() {
79 DateFormat df = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
80 return df.format(new Date(iPlanDate * 1000));
83 public long getChkSum() {
87 public String getMenuName() {
91 public String getName() {
95 public String getNameHtml() {
99 public String getAdditional() {
103 public String getNotes() {
107 public int[] getPlainPrice() {
111 public double getStudentPrice() {
112 double price = (aPriceArray[0] / 100.0);
116 public double getEmployeePrice() {
117 double price = (aPriceArray[1] / 100.0);
121 public double getGuestPrice() {
122 double price = (aPriceArray[2] / 100.0);
126 public double getSchoolPrice() {
127 double price = (aPriceArray[3] / 100.0);
131 public String getFormatedRolePrice() {
132 String mensaRoleName = CampusAppContext.getInstance().getDatabaseManager().getRuntimeCache("MensaRole");
133 if (mensaRoleName == null || mensaRoleName.isEmpty())
135 int mensaRole = Integer.parseInt(mensaRoleName);
136 double price = (aPriceArray[mensaRole] / 100.0);
138 DecimalFormat df = new DecimalFormat(CampusAppContext.getInstance().getResString(R.string.mensaformat_price));
139 String formatedPrice = df.format(price);
140 return formatedPrice;
143 public void setIsNew() {
147 public boolean getIsNew(boolean reset) {
148 boolean isnew = bIsNew;