/**
   * @see
   *     org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService#loadCustomerAddressesForCustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument)
   */
  @Override
  public void loadCustomerAddressesForCustomerInvoiceDocument(
      CustomerInvoiceDocument customerInvoiceDocument) {
    // if address identifier is provided, try to refresh customer address data
    if (ObjectUtils.isNotNull(customerInvoiceDocument.getAccountsReceivableDocumentHeader())) {
      CustomerAddress customerShipToAddress =
          customerAddressService.getByPrimaryKey(
              customerInvoiceDocument.getAccountsReceivableDocumentHeader().getCustomerNumber(),
              customerInvoiceDocument.getCustomerShipToAddressIdentifier());
      CustomerAddress customerBillToAddress =
          customerAddressService.getByPrimaryKey(
              customerInvoiceDocument.getAccountsReceivableDocumentHeader().getCustomerNumber(),
              customerInvoiceDocument.getCustomerBillToAddressIdentifier());

      if (ObjectUtils.isNotNull(customerShipToAddress)) {
        customerInvoiceDocument.setCustomerShipToAddress(customerShipToAddress);
        customerInvoiceDocument.setCustomerShipToAddressOnInvoice(customerShipToAddress);
      }

      if (ObjectUtils.isNotNull(customerBillToAddress)) {
        customerInvoiceDocument.setCustomerBillToAddress(customerBillToAddress);
        customerInvoiceDocument.setCustomerBillToAddressOnInvoice(customerBillToAddress);
      }
    }
  }
  /**
   * @see
   *     org.kuali.kfs.module.ar.document.service.AccountsReceivableTaxService#getPostalCodeForTaxation(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument)
   */
  @Override
  public String getPostalCodeForTaxation(CustomerInvoiceDocument document) {

    String postalCode = null;
    String customerNumber = document.getAccountsReceivableDocumentHeader().getCustomerNumber();
    Integer shipToAddressIdentifier = document.getCustomerShipToAddressIdentifier();

    // if customer number or ship to address id isn't provided, go to org options
    if (ObjectUtils.isNotNull(shipToAddressIdentifier) && StringUtils.isNotEmpty(customerNumber)) {

      CustomerAddressService customerAddressService =
          SpringContext.getBean(CustomerAddressService.class);
      CustomerAddress customerShipToAddress =
          customerAddressService.getByPrimaryKey(customerNumber, shipToAddressIdentifier);
      if (ObjectUtils.isNotNull(customerShipToAddress)) {
        postalCode = customerShipToAddress.getCustomerZipCode();
      }
    } else {
      Map<String, String> criteria = new HashMap<String, String>();
      criteria.put("chartOfAccountsCode", document.getBillByChartOfAccountCode());
      criteria.put("organizationCode", document.getBilledByOrganizationCode());
      OrganizationOptions organizationOptions =
          (OrganizationOptions)
              businessObjectService.findByPrimaryKey(OrganizationOptions.class, criteria);

      if (ObjectUtils.isNotNull(organizationOptions)) {
        postalCode = organizationOptions.getOrganizationPostalZipCode();
      }
    }
    return postalCode;
  }