From d74cbf8b2f5887af817495d8e061a5f27fed293b Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@hostsharing.net>
Date: Tue, 24 May 2011 15:22:25 +0200
Subject: [PATCH] member.delete moeglich nach Pruefungen member.add legt billdata und bankaccount an

---
 hsarback/src/de/hsadmin/mods/cust/CustomerModuleImpl.java |   55 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/hsarback/src/de/hsadmin/mods/cust/CustomerModuleImpl.java b/hsarback/src/de/hsadmin/mods/cust/CustomerModuleImpl.java
index 5c8ad07..34c4e27 100644
--- a/hsarback/src/de/hsadmin/mods/cust/CustomerModuleImpl.java
+++ b/hsarback/src/de/hsadmin/mods/cust/CustomerModuleImpl.java
@@ -1,13 +1,16 @@
 package de.hsadmin.mods.cust;
 
-import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
+import java.util.Set;
 
 import de.hsadmin.core.model.AbstractEntity;
 import de.hsadmin.core.model.AbstractModuleImpl;
+import de.hsadmin.core.model.AuthorisationException;
 import de.hsadmin.core.model.GenericModuleImpl;
 import de.hsadmin.core.model.HSAdminException;
 import de.hsadmin.core.util.TextUtil;
+import de.hsadmin.mods.pac.Pac;
 import de.hsadmin.mods.user.UnixUser;
 
 public class CustomerModuleImpl extends AbstractModuleImpl {
@@ -15,7 +18,7 @@
 	@Override
 	public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
 		if (!getLoginUser().hasHostmasterRole()) {
-			throw new HSAdminException("role hostmaster required to create new customer");
+			throw new AuthorisationException(getLoginUser(), "add", newEntity);
 		}
 		Customer newCustomer = (Customer) newEntity;
 		assertNotNull("membercode", newCustomer.getName());
@@ -25,6 +28,17 @@
 		String custComment = contact.getLastName();
 		if (contact.getFirstName() != null && contact.getFirstName().length() > 0) {
 			custComment = contact.getFirstName() + " " + contact.getLastName();
+		}
+		BankAccount bankAccount = newCustomer.getBankAccount();
+		if (bankAccount == null) {
+			bankAccount = new BankAccount();
+			bankAccount.setCustomer(newCustomer);
+			newCustomer.setBankAccount(bankAccount);
+		}
+		CustomersTariff billData = newCustomer.getBillData();
+		if (billData == null) {
+			billData = new CustomersTariff(newCustomer);
+			newCustomer.setBillData(billData);
 		}
 		GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
 		UnixUser custAccount = new UnixUser();
@@ -49,7 +63,7 @@
 	public AbstractEntity update(AbstractEntity existingEntity)
 			throws HSAdminException {
 		if (!getLoginUser().hasHostmasterRole()) {
-			throw new HSAdminException("role hostmaster required to update customers");
+			throw new AuthorisationException(getLoginUser(), "update", existingEntity);
 		}
 		return super.update(existingEntity);
 	}
@@ -57,22 +71,29 @@
 	@Override
 	public void delete(AbstractEntity existingEntity) throws HSAdminException {
 		if (!getLoginUser().hasHostmasterRole()) {
-			throw new HSAdminException("role hostmaster required to delete customers");
+			throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
 		}
 		Customer cust = (Customer) existingEntity;
-//		Diese Zeilen loeschen den hsh00-Mitglieds-Account 
-//		GenericModuleImpl helper = new GenericModuleImpl(getTransaction());
-//		AbstractEntity custAccount = helper.findByString(UnixUser.class, cust.getName());
-//		helper.delete(custAccount);
-		Calendar cal = Calendar.getInstance();
-		cal.setTimeInMillis(System.currentTimeMillis());
-		cal.set(Calendar.MONTH, Calendar.DECEMBER);
-		cal.set(Calendar.DAY_OF_MONTH, 31);
-		cal.set(Calendar.HOUR_OF_DAY, 23);
-		cal.set(Calendar.MINUTE, 59);
-		cal.set(Calendar.SECOND, 59);
-		cust.setMemberUntil(cal.getTime());
-		super.update(existingEntity);
+		
+		// Pruefe, ob geloescht werden kann..
+		// member_until < heute (nicht mehr Mitglied) oder member_since leer (nie Mitglied geworden) 
+		Date memberSince = cust.getMemberSince();
+		Date memberUntil = cust.getMemberUntil();
+		if (memberSince != null) {
+			if (memberUntil == null || memberUntil.after(new Date())) {
+				throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
+			}
+		}
+		// keine Pakete mehr!
+		Set<Pac> pacs = cust.getPacs();
+		if (pacs != null && pacs.size() > 0) {
+			throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
+		}
+		
+		GenericModuleImpl helper = new GenericModuleImpl(getTransaction());
+		AbstractEntity custAccount = helper.findByString(UnixUser.class, cust.getName());
+		helper.delete(custAccount);
+		super.delete(existingEntity);
 	}
 
 	private void assertNotNull(String name, String value) throws HSAdminException {

--
Gitblit v1.9.3