initSearchInfo(form, siteId);
ActionForward actionForward = actionMapping.findForward("error");
return actionForward;
}
Customer customer = CustomerDAO.load(siteId, getCustomer(request).getCustId());
CustomerAddress custAddress = customer.getCustAddress();
if (custAddress == null) {
custAddress = new CustomerAddress();
customer.setCustAddress(custAddress);
custAddress.setCustAddressType(Constants.CUSTOMER_ADDRESS_CUST);
customer.getCustAddresses().add(custAddress);
custAddress.setRecCreateBy(Constants.USERNAME_CUSTOMER);
custAddress.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
custAddress.setCustUseAddress(Constants.CUST_ADDRESS_USE_OWN);
custAddress.setCustFirstName(form.getCustFirstName());
custAddress.setCustMiddleName(form.getCustMiddleName());
custAddress.setCustLastName(form.getCustLastName());
custAddress.setCustSuffix(form.getCustSuffix());
custAddress.setCustAddressLine1(form.getCustAddressLine1());
custAddress.setCustAddressLine2(form.getCustAddressLine2());
custAddress.setCustCityName(form.getCustCityName());
if (Format.isNullOrEmpty(form.getCustStateName())) {
custAddress.setCustStateCode(form.getCustStateCode());
custAddress.setCustStateName(Utility.getStateName(siteId, form.getCustStateCode()));
}
else {
custAddress.setCustStateCode("");
custAddress.setCustStateName(form.getCustStateName());
}
custAddress.setCustCountryCode(form.getCustCountryCode());
custAddress.setCustCountryName(Utility.getCountryName(siteId, form.getCustCountryCode()));
custAddress.setCustZipCode(form.getCustZipCode());
custAddress.setCustPhoneNum(form.getCustPhoneNum());
custAddress.setCustFaxNum(form.getCustFaxNum());
custAddress.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
custAddress.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
custAddress.setState(StateDAO.loadByStateCode(siteId, form.getCustStateCode()));
custAddress.setCountry(CountryDAO.loadByCountryCode(siteId, form.getCustCountryCode()));
custAddress.setRecCreateBy(Constants.USERNAME_CUSTOMER);
custAddress.setRecCreateDatetime(new Date(System.currentTimeMillis()));
if (custAddress.getCustAddressId() == null) {
em.persist(custAddress);
}
CustomerAddress billingAddress = null;
for (CustomerAddress address : customer.getCustAddresses()) {
if (address.getCustAddressType().equals(Constants.CUSTOMER_ADDRESS_BILLING)) {
billingAddress = address;
break;
}
}
if (billingAddress == null) {
billingAddress = new CustomerAddress();
billingAddress.setCustAddressType(Constants.CUSTOMER_ADDRESS_BILLING);
customer.getCustAddresses().add(billingAddress);
billingAddress.setRecCreateBy(Constants.USERNAME_CUSTOMER);
billingAddress.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
billingAddress.setCustUseAddress(form.getBillingUseAddress());
if (form.billingUseAddress.equals(Constants.CUST_ADDRESS_USE_OWN)) {
billingAddress.setCustUseAddress(Constants.CUST_ADDRESS_USE_OWN);
billingAddress.setCustPrefix(form.getBillingCustPrefix());
billingAddress.setCustFirstName(form.getBillingCustFirstName());
billingAddress.setCustMiddleName(form.getBillingCustMiddleName());
billingAddress.setCustLastName(form.getBillingCustLastName());
billingAddress.setCustSuffix(form.getBillingCustSuffix());
billingAddress.setCustAddressLine1(form.getBillingCustAddressLine1());
billingAddress.setCustAddressLine2(form.getBillingCustAddressLine2());
billingAddress.setCustCityName(form.getBillingCustCityName());
if (Format.isNullOrEmpty(form.getBillingCustStateName())) {
billingAddress.setCustStateCode(form.getBillingCustStateCode());
billingAddress.setCustStateName(Utility.getStateName(siteId, form.getBillingCustStateCode()));
}
else {
billingAddress.setCustStateCode("");
billingAddress.setCustStateName(form.getBillingCustStateName());
}
billingAddress.setCustCountryCode(form.getBillingCustCountryCode());
billingAddress.setCustCountryName(Utility.getCountryName(siteId, form.getBillingCustCountryCode()));
billingAddress.setCustZipCode(form.getBillingCustZipCode());
billingAddress.setCustPhoneNum(form.getBillingCustPhoneNum());
billingAddress.setCustFaxNum(form.getBillingCustFaxNum());
billingAddress.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
billingAddress.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
billingAddress.setState(StateDAO.loadByStateCode(siteId, form.getBillingCustStateCode()));
billingAddress.setCountry(CountryDAO.loadByCountryCode(siteId, form.getBillingCustCountryCode()));
}
billingAddress.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
billingAddress.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (billingAddress.getCustAddressId() == null) {
em.persist(billingAddress);
}
CustomerAddress shippingAddress = null;
for (CustomerAddress address : customer.getCustAddresses()) {
if (address.getCustAddressType().equals(Constants.CUSTOMER_ADDRESS_SHIPPING)) {
shippingAddress = address;
break;
}
}
if (shippingAddress == null) {
shippingAddress = new CustomerAddress();
shippingAddress.setCustAddressType(Constants.CUSTOMER_ADDRESS_SHIPPING);
customer.getCustAddresses().add(shippingAddress);
shippingAddress.setRecCreateBy(Constants.USERNAME_CUSTOMER);
shippingAddress.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
shippingAddress.setCustUseAddress(form.getShippingUseAddress());
if (form.shippingUseAddress.equals(Constants.CUST_ADDRESS_USE_OWN)) {
shippingAddress.setCustUseAddress(Constants.CUST_ADDRESS_USE_OWN);
shippingAddress.setCustPrefix(form.getShippingCustPrefix());
shippingAddress.setCustFirstName(form.getShippingCustFirstName());
shippingAddress.setCustMiddleName(form.getShippingCustMiddleName());
shippingAddress.setCustLastName(form.getShippingCustLastName());
shippingAddress.setCustSuffix(form.getShippingCustSuffix());
shippingAddress.setCustAddressLine1(form.getShippingCustAddressLine1());
shippingAddress.setCustAddressLine2(form.getShippingCustAddressLine2());
shippingAddress.setCustCityName(form.getShippingCustCityName());
if (Format.isNullOrEmpty(form.getShippingCustStateName())) {
shippingAddress.setCustStateCode(form.getShippingCustStateCode());
shippingAddress.setCustStateName(Utility.getStateName(siteId, form.getShippingCustStateCode()));
}
else {
shippingAddress.setCustStateCode("");
shippingAddress.setCustStateName(form.getShippingCustStateName());
}
shippingAddress.setCustCountryCode(form.getShippingCustCountryCode());
shippingAddress.setCustCountryName(Utility.getCountryName(siteId, form.getShippingCustCountryCode()));
shippingAddress.setCustZipCode(form.getShippingCustZipCode());
shippingAddress.setCustPhoneNum(form.getShippingCustPhoneNum());
shippingAddress.setCustFaxNum(form.getShippingCustFaxNum());
shippingAddress.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
shippingAddress.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
shippingAddress.setState(StateDAO.loadByStateCode(siteId, form.getShippingCustStateCode()));
shippingAddress.setCountry(CountryDAO.loadByCountryCode(siteId, form.getShippingCustCountryCode()));
}
shippingAddress.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
shippingAddress.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
if (shippingAddress.getCustAddressId() == null) {
em.persist(shippingAddress);
}
customer.setRecUpdateBy(Constants.USERNAME_CUSTOMER);
customer.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
em.persist(customer);
ContentLookupDispatchAction.setCustId(request, customer.getCustId());
messages.add("message", new ActionMessage("content.text.information.updated"));
saveMessages(request, messages);
init(request, form);
initSearchInfo(form, siteId);