<?php

namespace RxConnexionBundle\Repository;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr;


class PurchaseInvoiceCreditPaymentRepository extends EntityRepository
{
    public function validate($purchaseInvoiceCreditPayment_form) {

        $errors = array();

        if($purchaseInvoiceCreditPayment_form['action'] != 'd'){

            if(empty($purchaseInvoiceCreditPayment_form['purchaseInvoice'])){
                $errors[] = 'Invalid transaction. Please try again or contact the administrator.';
            }

            if(empty($purchaseInvoiceCreditPayment_form['amount'])){
                $errors[] = 'Amount should not be blank.';
            }

            if(empty($purchaseInvoiceCreditPayment_form['paymentDate'])){
                $errors[] = 'Payment date should not be blank.';
            }

            if(empty($purchaseInvoiceCreditPayment_form['payment_method'])){
                $errors[] = 'Payment method should not be blank';
            }

            if($purchaseInvoiceCreditPayment_form['payment_method'] == 'Check'){
                if(empty($purchaseInvoiceCreditPayment_form['checkDate']) || empty($purchaseInvoiceCreditPayment_form['bank'])){
                    $errors[] = 'There are error on check detail .';
                }
            }
        }

        return $errors;
    }


}