1 5 package com.openedit.store.customer; 6 7 import org.openedit.money.Fraction; 8 9 import com.openedit.store.PaymentMethod; 10 import com.openedit.users.User; 11 import com.openedit.users.filesystem.FileSystemUser; 12 13 18 public class Customer 19 { 20 public static final String PHONE1 = "Phone1"; 21 public static final String FAX = "Fax"; 22 public static final String TITLE = "Title"; 23 public static final String ALLOW_EMAIL = "AllowEmail"; 24 public static final String REFERENCE = "ReferenceNumber"; 25 public static final String TAX_RATE = "TaxRate"; 26 public static final String TAX_EXEMPT_ID = "TaxExemptId"; 27 public static final String COMPANY = "Company"; 28 public static final String USERFIELD1 = "userfield1"; 29 public static final String USERFIELD2 = "userfield2"; 30 31 protected User fieldUser; protected PaymentMethod fieldPaymentMethod; 33 protected Address fieldBillingAddress; 34 protected Address fieldShippingAddress; 35 protected String fieldUserName; 36 37 41 public Customer(User inUser) 42 { 43 fieldUser = inUser; 44 } 45 46 public Customer() 47 { 48 FileSystemUser user = new FileSystemUser(); 49 fieldUser = user; 50 } 51 public User getUser() 52 { 53 return fieldUser; 54 } 55 56 public String getUserName() 57 { 58 return getUser().getUserName(); 59 } 60 61 public String getFirstName() 62 { 63 return getUser().getFirstName(); 64 } 65 66 public void setFirstName( String inFirstName ) 67 { 68 getUser().setFirstName( inFirstName ); 69 } 70 71 public String getLastName() 72 { 73 return getUser().getLastName(); 74 } 75 76 public void setLastName( String inLastName ) 77 { 78 getUser().setLastName( inLastName ); 79 } 80 81 public String getEmail() 82 { 83 return getUser().getEmail(); 84 } 85 86 public void setEmail( String inEmail ) 87 { 88 getUser().setEmail( inEmail ); 89 } 90 91 public String getPassword() 92 { 93 return getUser().getPassword(); 94 } 95 96 public boolean isAllowEmail() 97 { 98 return getUser().getBoolean(ALLOW_EMAIL); 99 } 100 101 public void setAllowEmail(boolean inValue) 102 { 103 getUser().safePut(ALLOW_EMAIL,String.valueOf(inValue)); 104 } 105 106 public String getTaxExemptId() 107 { 108 return getUser().getString(TAX_EXEMPT_ID); 109 } 110 111 public void setTaxExemptId(String inString) 112 { 113 getUser().safePut(TAX_EXEMPT_ID, inString); 114 } 115 116 public String getName() 117 { 118 return getFirstName() + " " + getLastName(); 119 } 120 121 public PaymentMethod getPaymentMethod() 122 { 123 return fieldPaymentMethod; 124 } 125 126 public void setPaymentMethod(PaymentMethod inPaymentMethod) 127 { 128 fieldPaymentMethod = inPaymentMethod; 129 } 130 131 public String getPhone1() 132 { 133 return getUser().getString(PHONE1); 134 } 135 136 public void setPhone1(String inPhone1) 137 { 138 getUser().safePut(PHONE1, inPhone1); 139 } 140 141 public String getCompany() 142 { 143 return getUser().getString( COMPANY ); 144 } 145 146 public void setCompany( String inCompany ) 147 { 148 getUser().safePut( COMPANY, inCompany ); 149 } 150 151 public Fraction getTaxRate() 152 { 153 String taxRateString = getUser().getString(TAX_RATE); 154 if (taxRateString == null) 155 { 156 taxRateString = Fraction.ZERO.toString(); 157 getUser().safePut(TAX_RATE, taxRateString); 158 } 159 return new Fraction(taxRateString); 160 } 161 162 public void setTaxRate(Fraction inTaxRate) 163 { 164 if (inTaxRate == null) 165 { 166 inTaxRate = Fraction.ZERO; 167 } 168 getUser().safePut(TAX_RATE, inTaxRate.toString()); 169 } 170 171 public String getReferenceNumber() 172 { 173 return getUser().getString(REFERENCE); 174 } 175 public void setReferenceNumber(String inReferenceNumber) 176 { 177 getUser().safePut(REFERENCE,inReferenceNumber); 178 } 179 public String getTitle() 180 { 181 return getUser().getString(TITLE); 182 } 183 public void setTitle(String inTitle) 184 { 185 getUser().safePut(TITLE, inTitle); 186 } 187 public String cleanPhoneNumber() 189 { 190 String phoneNumber = getPhone1(); 191 if ( phoneNumber != null ) 192 { 193 StringBuffer out = new StringBuffer (); 194 for (int i = 0; i < phoneNumber.length(); i++) 195 { 196 if ( Character.isDigit(phoneNumber.charAt(i))) 197 { 198 out.append(phoneNumber.charAt(i)); 199 } 200 } 201 phoneNumber = out.toString(); 202 } 203 return phoneNumber; 204 } 205 206 public Address getBillingAddress() 207 { 208 if ( fieldBillingAddress == null ) 209 { 210 fieldBillingAddress = new Address(getUser()); 211 fieldBillingAddress.setPrefix("billing."); } 213 return fieldBillingAddress; 214 } 215 216 public void setBillingAddress(Address inAddress) 217 { 218 fieldBillingAddress = inAddress; 219 } 220 public Address getShippingAddress() 221 { 222 if ( fieldShippingAddress == null ) 223 { 224 fieldShippingAddress = new Address(getUser()); 225 fieldShippingAddress.setPrefix(""); 226 } 227 return fieldShippingAddress; 228 } 229 public void setShippingAddress(Address inShippingAddress) 230 { 231 fieldShippingAddress = inShippingAddress; 232 } 233 public String getFax() 234 { 235 return getUser().getString(FAX); 236 } 237 public void setFax(String inFax) 238 { 239 getUser().safePut(FAX, inFax); 240 } 241 242 public String getUserField1() 243 { 244 return getUser().getString( USERFIELD1 ); 245 } 246 247 public void setUserField1( String inUserField1 ) 248 { 249 getUser().safePut( USERFIELD1, inUserField1 ); 250 } 251 252 public String getUserField2() 253 { 254 return getUser().getString( USERFIELD2 ); 255 } 256 257 public void setUserField2( String inUserField2 ) 258 { 259 getUser().safePut( USERFIELD2, inUserField2 ); 260 } 261 262 public void setUserName(String inUserName) 263 { 264 getUser().setUserName(inUserName); 265 } 266 267 public void setPassword(String inPassword) 268 { 269 getUser().setPassword(inPassword); 270 } 271 } 272 | Popular Tags |