/**
   * @see
   *     org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService#setupDefaultValuesForCopiedCustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument)
   */
  @Override
  public void setupDefaultValuesForCopiedCustomerInvoiceDocument(CustomerInvoiceDocument document) {

    setupBasicDefaultValuesForCustomerInvoiceDocument(document);

    // Save customer number since it will get overwritten when we retrieve the accounts receivable
    // document header from service
    String customerNumber = document.getAccountsReceivableDocumentHeader().getCustomerNumber();

    // Set up the default values for the AR DOC Header
    AccountsReceivableDocumentHeader accountsReceivableDocumentHeader =
        accountsReceivableDocumentHeaderService
            .getNewAccountsReceivableDocumentHeaderForCurrentUser();
    accountsReceivableDocumentHeader.setDocumentNumber(document.getDocumentNumber());
    accountsReceivableDocumentHeader.setCustomerNumber(customerNumber);
    document.setAccountsReceivableDocumentHeader(accountsReceivableDocumentHeader);

    // set up the primary key for AR_INV_RCURRNC_DTL_T
    CustomerInvoiceRecurrenceDetails recurrenceDetails = new CustomerInvoiceRecurrenceDetails();
    recurrenceDetails.setInvoiceNumber(document.getDocumentNumber());
    // recurrenceDetails.setCustomerNumber(document.getAccountsReceivableDocumentHeader().getCustomerNumber());
    document.setCustomerInvoiceRecurrenceDetails(recurrenceDetails);

    // make open invoice indicator to true
    document.setOpenInvoiceIndicator(true);
    document.setPrintDate(null);
    document.setBillingDate(dateTimeService.getCurrentSqlDateMidnight());
  }
  /**
   * This method creates a payment application document based on the passed in fixture array
   *
   * @param paymentFixture
   * @param customerInvoiceDetailFixtures
   * @return
   */
  public PaymentApplicationDocument createPaymentApplicationDocument() {

    PaymentApplicationDocument paymentApplicationDocument = null;
    try {
      paymentApplicationDocument =
          (PaymentApplicationDocument)
              DocumentTestUtils.createDocument(
                  SpringContext.getBean(DocumentService.class), PaymentApplicationDocument.class);
    } catch (WorkflowException e) {
      throw new RuntimeException("Document creation failed.");
    }

    // set AR doc Header
    AccountsReceivableDocumentHeader arDocHeader = new AccountsReceivableDocumentHeader();
    AccountsReceivableDocumentHeaderService accountsReceivableDocumentHeaderService =
        SpringContext.getBean(AccountsReceivableDocumentHeaderService.class);
    arDocHeader.setDocumentNumber(paymentApplicationDocument.getDocumentNumber());
    arDocHeader.setCustomerNumber(customerNumber);
    arDocHeader.setDocumentNumber(paymentApplicationDocument.getDocumentNumber());
    paymentApplicationDocument.setAccountsReceivableDocumentHeader(arDocHeader);

    return paymentApplicationDocument;
  }
  /**
   * Refactor to have all the setters in here.
   *
   * @see
   *     org.kuali.kfs.module.ar.document.service.CustomerInvoiceDocumentService#setupDefaultValuesForNewCustomerInvoiceDocument(org.kuali.kfs.module.ar.document.CustomerInvoiceDocument)
   */
  @Override
  public void setupDefaultValuesForNewCustomerInvoiceDocument(CustomerInvoiceDocument document) {

    setupBasicDefaultValuesForCustomerInvoiceDocument(document);

    // set up the default values for the AR DOC Header

    AccountsReceivableDocumentHeader accountsReceivableDocumentHeader =
        accountsReceivableDocumentHeaderService
            .getNewAccountsReceivableDocumentHeaderForCurrentUser();
    accountsReceivableDocumentHeader.setDocumentNumber(document.getDocumentNumber());
    document.setAccountsReceivableDocumentHeader(accountsReceivableDocumentHeader);

    // set up the primary key for AR_INV_RCURRNC_DTL_T
    CustomerInvoiceRecurrenceDetails recurrenceDetails = new CustomerInvoiceRecurrenceDetails();
    recurrenceDetails.setInvoiceNumber(document.getDocumentNumber());
    // recurrenceDetails.setCustomerNumber(document.getCustomer().getCustomerNumber());
    document.setCustomerInvoiceRecurrenceDetails(recurrenceDetails);

    Map<String, String> criteria = new HashMap<String, String>();
    criteria.put(
        KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, document.getBillByChartOfAccountCode());
    criteria.put(KFSPropertyConstants.ORGANIZATION_CODE, document.getBilledByOrganizationCode());
    OrganizationOptions organizationOptions =
        businessObjectService.findByPrimaryKey(OrganizationOptions.class, criteria);

    if (ObjectUtils.isNotNull(organizationOptions)) {
      document.setPrintInvoiceIndicator(organizationOptions.getPrintInvoiceIndicator());
      document.setInvoiceTermsText(organizationOptions.getOrganizationPaymentTermsText());
    }

    // If document is using receivable option, set receivable accounting line for customer invoice
    // document
    String receivableOffsetOption =
        parameterService.getParameterValueAsString(
            CustomerInvoiceDocument.class, ArConstants.GLPE_RECEIVABLE_OFFSET_GENERATION_METHOD);
    boolean isUsingReceivableFAU =
        ArConstants.GLPE_RECEIVABLE_OFFSET_GENERATION_METHOD_FAU.equals(receivableOffsetOption);
    if (isUsingReceivableFAU) {
      receivableAccountingLineService.setReceivableAccountingLineForCustomerInvoiceDocument(
          document);
    }
  }