public function getPaidAmountByInvoice(Document $invoice)
 {
     $paidAmount = 0;
     $payments = $this->entityManager->getRepository(BankTransaction::getClass())->findBy(array('document' => $invoice));
     foreach ($payments as $payment) {
         $paidAmount += $payment->getSum();
     }
     if ($invoice instanceof Invoice) {
         return (double) $paidAmount;
     } else {
         return abs((double) $paidAmount);
     }
 }
Beispiel #2
0
 /**
  * @param ArrayCollection $rows
  */
 public function addTransaction(BankTransaction $transaction)
 {
     $this->transactions[] = $transaction;
     $transaction->setDocument($this);
 }
Beispiel #3
0
 public function saveTransactionWithParams(BankTransaction $transaction = null, User $user, array $data)
 {
     if (!$transaction) {
         $transaction = new BankTransaction();
         $transaction->setUser($user);
     }
     if (isset($data['paymentType'])) {
         $transaction->setPaymentType($data['paymentType']);
     }
     if (isset($data['type'])) {
         if (in_array($data['type'], BankTransaction::$types)) {
             $transaction->setType($data['type']);
         } else {
             return null;
         }
     }
     if (isset($data['invoiceId']) && $data['invoiceId'] > 0) {
         $invoice = $this->invoiceService->getInvoiceById($data['invoiceId']);
         if ($invoice) {
             $transaction->setDocument($invoice);
             $transaction->setStatus(BankTransaction::STATUS_ASSOCIATED);
         }
     }
     if (isset($data['paymentDate'])) {
         $date = \DateTime::createFromFormat('d.m.Y', $data['paymentDate']);
         if ($date) {
             $transaction->setPaymentDate($date);
         } else {
             return null;
         }
     }
     if (isset($data['name'])) {
         $transaction->setName($data['name']);
     }
     if (isset($data['referenceNumber'])) {
         $transaction->setReferenceNumber($data['referenceNumber']);
     }
     if (isset($data['sum'])) {
         if (is_numeric($data['sum'])) {
             $transaction->setSum($data['sum']);
         } else {
             return null;
         }
     }
     if (isset($data['description'])) {
         $transaction->setDescription($data['description']);
     }
     if (isset($data['payerIban'])) {
         $transaction->setPayerIban($data['payerIban']);
     }
     return $this->saveTransaction($transaction);
 }