<?xml version="1.0" encoding="UTF-8" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<simple-map-processors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd">
  <simple-map-processor name="deletePaymentMethod">
    <process field="paymentMethodId"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingPaymentMethodIdMissing"/></not-empty></process>
  </simple-map-processor>

  <!-- CreditCard map procs -->
  <simple-map-processor name="createCreditCard">
    <make-in-string field="expireDate">
      <in-field field="expMonth"/>
      <constant>/</constant>
      <in-field field="expYear"/>
    </make-in-string>
    <process field="partyId"><copy/></process>
    <process field="companyNameOnCard"><copy/></process>
    <process field="titleOnCard"><copy/></process>
    <process field="firstNameOnCard"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingFirstNameOnCardMissing"/></not-empty></process>
    <process field="middleNameOnCard"><copy/></process>
    <process field="lastNameOnCard"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingLastNameOnCardMissing"/></not-empty></process>
    <process field="suffixOnCard"><copy/></process>
    <process field="cardType"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingCardTypeMissing"/></not-empty></process>
    <process field="cardNumber">
        <copy/>
        <not-empty>
            <fail-property resource="AccountingUiLabels" property="AccountingCardNumberMissing"/>
        </not-empty>
        <validate-method method="isAnyCard" class="org.apache.ofbiz.base.util.UtilValidate">
            <fail-property resource="AccountingUiLabels" property="AccountingCardNumberIncorrect"/>
        </validate-method>
    </process>
    <process field="contactMechId"><copy/></process>
    <process field="description"><copy/></process>
    <process field="expMonth"><not-empty><fail-property resource="AccountingUiLabels" property="AccountingExpirationMonthMissing"/></not-empty></process>
    <process field="expYear"><not-empty><fail-property resource="AccountingUiLabels" property="AccountingExpirationYearMissing"/></not-empty></process>
    <process field="expireDate">
        <copy/>
        <validate-method method="isDateAfterToday"><fail-property resource="AccountingUiLabels" property="AccountingExpirationDateIsBeforeToday"/></validate-method>
    </process>
  </simple-map-processor>

  <simple-map-processor name="updateCreditCard">
    <make-in-string field="expireDate">
      <in-field field="expMonth"/>
      <constant>/</constant>
      <in-field field="expYear"/>
    </make-in-string>
    <process field="paymentMethodId"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingCreditCardPaymentMethodIdMissing"/></not-empty></process>
    <process field="partyId"><copy/></process>
    <process field="companyNameOnCard"><copy/></process>
    <process field="titleOnCard"><copy/></process>
    <process field="firstNameOnCard"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingFirstNameOnCardMissing"/></not-empty></process>
    <process field="middleNameOnCard"><copy/></process>
    <process field="lastNameOnCard"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingLastNameOnCardMissing"/></not-empty></process>
    <process field="suffixOnCard"><copy/></process>
    <process field="cardType"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingCardTypeMissing"/></not-empty></process>
    <process field="cardNumber">
        <copy/>
        <not-empty>
            <fail-property resource="AccountingUiLabels" property="AccountingCardNumberMissing"/>
        </not-empty>
        <!-- FIXME Commented out because of OFBIZ-6920, a better solution would be do encrypt the card number when showing screen and decrypt when validating data
             Anyway the only reason of changing a card number while this card is still valid 
             is because the number have been wrongly entered. Then better to delete and create a new one -->
        <!-- <validate-method method="isAnyCard" class="org.apache.ofbiz.base.util.UtilValidate">
            <fail-property resource="AccountingUiLabels" property="AccountingCardNumberIncorrect"/>
        </validate-method> -->
    </process>
    <process field="contactMechId"><copy/></process>
    <process field="description"><copy/></process>
    <process field="expMonth"><not-empty><fail-property resource="AccountingUiLabels" property="AccountingExpirationMonthMissing"/></not-empty></process>
    <process field="expYear"><not-empty><fail-property resource="AccountingUiLabels" property="AccountingExpirationYearMissing"/></not-empty></process>
    <process field="expireDate">
        <copy/>
        <validate-method method="isDateAfterToday"><fail-property resource="AccountingUiLabels" property="AccountingExpirationDateIsBeforeToday"/></validate-method>
    </process>
  </simple-map-processor>

  <!-- EftAccount map procs -->
  <simple-map-processor name="createEftAccount">
    <process field="partyId"><copy/></process>
    <process field="description"><copy/></process>
    <process field="bankName"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingBankNameMissing"/></not-empty></process>
    <process field="routingNumber"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingRoutingNumberMissing"/></not-empty></process>
    <process field="accountType"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingAccountTypeMissing"/></not-empty></process>
    <process field="accountNumber"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingAccountNumberMissing"/></not-empty></process>
    <process field="nameOnAccount"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingNameOnAccountMissing"/></not-empty></process>
    <process field="companyNameOnAccount"><copy/></process>
    <process field="contactMechId"><copy/></process>
  </simple-map-processor>
  <simple-map-processor name="updateEftAccount">
    <process field="paymentMethodId"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingEFTAccountPaymentMethodIdMissing"/></not-empty></process>
    <process field="description"><copy/></process>
    <!-- also call createEftAccount after calling updateEftAccount -->
  </simple-map-processor>
  
  <!-- Check map procs -->
  <simple-map-processor name="createCheckAccount">
    <process field="partyId"><copy/></process>
    <process field="bankName"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingBankNameMissing"/></not-empty></process>
    <process field="paymentMethodTypeId"><copy/><not-empty><fail-property resource="AccountingPaymentMethodTypeMissing" property="AccountingAccountTypeMissing"/></not-empty></process>
    <process field="description"><copy/></process>
    <process field="routingNumber"><copy/></process>
    <process field="accountType"><copy/></process>
    <process field="accountNumber"><copy/></process>
    <process field="nameOnAccount"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingNameOnAccountMissing"/></not-empty></process>
    <process field="companyNameOnAccount"><copy/></process>
    <process field="contactMechId"><copy/></process>
  </simple-map-processor>
  <simple-map-processor name="updateCheckAccount">
    <process field="paymentMethodId"><copy/><not-empty><fail-property resource="AccountingUiLabels" property="AccountingCheckPaymentMethodIdMissing"/></not-empty></process>
  </simple-map-processor>
</simple-map-processors>
