 ###
 
-  isAccountType
+  requiredIfNotFieldSet
 
-  @example check to see if schema is of a certain AccountType
+  @example check to see if schema is representing the given state
 
-    isAccountType(schema, type)
+    requiredIfNotFieldSet(schema, fieldName, value)
 
   @param schema [SimpleSchema] generally passed as @ or this
-  @param type [String] the type of account compared to the schema's AccountType
+  @param fieldName [String] the name of a field within the schema
+  @param value [String|Number] the value to check that the field is set to or,
+  if ommitted, indicates that the field should simply be falsey
 
 ###
-isAccountType = (schema, type) ->
-  isCredit = schema.field('AccountType').value == type
-  if isCredit and !schema.isSet and (!schema.operator or schemavalue == null or schema.value == '')
-    'required'
+requiredIfNotFieldSet = (schema, fieldName, value) ->
+  if value?
+    isOfType = schema.field(fieldName).value == value
+  else
+    isOfType = not schema.field(fieldName).value?
+
+  if isOfType and !schema.isSet and (!schema.operator or schemavalue == null or schema.value == '')
+    return "required"
+
 
 ###
   Schema used for validating give transaction data
 ###
+amountDetail = new SimpleSchema
+  Amount:
+    type: Number
+  TargetAccountId:
+    type: Number
+    decimal: false
+
 giveTransactionSchema = new SimpleSchema(
+  SourceAccountId:
+    decimal: false
+    type: Number
+    optional: true
   Email:
     type: String
     regEx: Apollos.regex.email
   AccountType:
     type: String
+    optional: true
     regEx: /^(checking|savings|credit)$/
-  'AmountDetails.TargetAccountId':
-    type: Number
-  'AmountDetails.Amount':
-    type: Number
+    custom: ->
+      requiredIfNotFieldSet @, "SourceAccountId"
+  AmountDetails:
+    type: [amountDetail]
   AccountNumber:
     type: String
+    optional: true
+    custom: ->
+      requiredIfNotFieldSet @, "SourceAccountId"
   RoutingNumber:
     type: String
     optional: true
     custom: ->
-      'required' if isAccountType(@, 'checking') or isAccountType(@, 'savings')
+      requiredIfNotFieldSet(@, "AccountType", "checking") or requiredIfNotFieldSet @, "AccountType", "savings"
   CCV:
     type: String
     optional: true
     custom: ->
-      'required' if isAccountType(@, 'credit')
+      requiredIfNotFieldSet @, "AccountType", "credit"
   ExpirationMonth:
     type: Number
     optional: true
     custom: ->
-      'required' if isAccountType(@, 'credit')
+      requiredIfNotFieldSet @, "AccountType", "credit"
   ExpirationYear:
     type: Number
     optional: true
     custom: ->
-      'required' if isAccountType(@, 'credit')
-  AccountId:
-    type: Number
-    optional: true
+      requiredIfNotFieldSet @, "AccountType", "credit"
   PersonId:
     type: Number
+    decimal: false
     optional: true
   FirstName:
     type: String

      return false

    return true


  PhoneNumber:
    type: String
  CampusId:
    decimal: false
    type: Number
)

