<?php
namespace App\Model\Table;

use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * RegistrationPayments Model

 * @method \App\Model\Entity\RegistrationPayment get($primaryKey, $options = [])
 * @method \App\Model\Entity\RegistrationPayment newEntity($data = null, array $options = [])
 * @method \App\Model\Entity\RegistrationPayment[] newEntities(array $data, array $options = [])
 * @method \App\Model\Entity\RegistrationPayment|false save(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\RegistrationPayment saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = [])
 * @method \App\Model\Entity\RegistrationPayment patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
 * @method \App\Model\Entity\RegistrationPayment[] patchEntities($entities, array $data, array $options = [])
 * @method \App\Model\Entity\RegistrationPayment findOrCreate($search, callable $callback = null, $options = [])
 */
class RegistrationPaymentsTable extends Table
{
    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->setTable('registration_payments');
        $this->setPrimaryKey('id');

    }

    /**
     * Default validation rules.
     *
     * @param \Cake\Validation\Validator $validator Validator instance.
     * @return \Cake\Validation\Validator
     */
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmptyString('id', null, 'create');

        $validator
            ->integer('student_id')
            ->requirePresence('student_id', 'create')
            ->notEmptyString('student_id');

        $validator
            ->integer('letter_type')
            ->requirePresence('letter_type', 'create')
            ->notEmptyString('letter_type');


        $validator
            ->decimal('registration_fee')
            ->requirePresence('registration_fee', 'create')
            ->notEmptyString('registration_fee');

        $validator
            ->decimal('tuition_fees')
            ->requirePresence('tuition_fees', 'create')
            ->notEmptyString('tuition_fees');

        $validator
            ->decimal('total_fees_paid')
            ->requirePresence('total_fees_paid', 'create')
            ->notEmptyString('total_fees_paid');

        $validator
            ->decimal('total_fees')
            ->requirePresence('total_fees', 'create')
            ->notEmptyString('total_fees');

        $validator
            ->decimal('outstanding_fees')
            ->requirePresence('outstanding_fees', 'create')
            ->notEmptyString('outstanding_fees');

        $validator
            ->scalar('bank_details')
            ->allowEmptyString('bank_details');

        $validator
            ->scalar('iban')
            ->allowEmptyString('iban');

        $validator
            ->scalar('account_no')
            ->allowEmptyString('account_no');

        $validator
            ->integer('created_by_id')
            ->allowEmptyString('created_by_id');

        $validator
            ->integer('updated_by_id')
            ->allowEmptyString('updated_by_id');

        $validator
            ->dateTime('created_at')
            ->allowEmptyDateTime('created_at');

        $validator
            ->dateTime('updated_at')
            ->allowEmptyDateTime('updated_at');

        return $validator;
    }
}
