コード例 #1
0
ファイル: MoneyAccount.php プロジェクト: arbi/MyCode
 /**
  * @return void
  * @throws \InvalidArgumentException
  */
 public function fetchAccountData()
 {
     if (intval($this->accountId) > 0) {
         $this->account = $this->moneyAccountDao->fetchOne(['id' => $this->accountId]);
     } else {
         throw new \InvalidArgumentException('Money account id is in bad format.');
     }
 }
コード例 #2
0
ファイル: Order.php プロジェクト: arbi/MyCode
 /**
  * @param  $data
  * @return bool
  */
 public function createPOItemTransaction($data, $files)
 {
     /**
      * @var ExpenseTicket $financeService
      * @var \DDD\Domain\WHOrder\Order $order
      */
     $financeService = $this->getServiceLocator()->get('service_finance_expense_expense_ticket');
     $expenseItemDao = new ExpenseItem($this->getServiceLocator(), '\\ArrayObject');
     $orderDao = $this->getOrderDao();
     if (!is_array($data)) {
         $data = json_decode($data, true);
     }
     $order = $orderDao->fetchOne(['id' => $data['order_id']], ['po_item_id']);
     if ($order && $order->getPoItemId()) {
         try {
             $expenseItemDao->beginTransaction();
             $poItem = $expenseItemDao->fetchOne(['id' => $order->getPoItemId()], ['account_id', 'expense_id']);
             if ($poItem && $data['supplier_id'] && $poItem['expense_id']) {
                 $transactionAccountsDao = $this->getServiceLocator()->get('dao_finance_transaction_transaction_accounts');
                 $transactionAccountId = $transactionAccountsDao->fetchOne(['holder_id' => $data['supplier_id'], 'type' => 4], ['id'])->getId();
                 if (is_null($transactionAccountId)) {
                     throw new \Exception();
                 }
                 $moneyAccountDao = new MoneyAccount($this->getServiceLocator(), '\\ArrayObject');
                 $moneyAccountCurrencyId = $moneyAccountDao->getCurrencyId($data['money_account_id']);
                 $newItemAmountInOldItemCurrency = $financeService->recalculateTicketBalance($order->getPoItemId(), $data['amount'], $moneyAccountCurrencyId);
                 if ($newItemAmountInOldItemCurrency === false) {
                     $newItemAmountInOldItemCurrency = $data['amount'];
                 }
                 $expenseItemDao->save(['account_id' => $transactionAccountId, 'amount' => $newItemAmountInOldItemCurrency], ['id' => $order->getPoItemId()]);
                 $transactionData = ['poId' => $poItem['expense_id'], 'itemId' => $order->getPoItemId(), 'accountId' => $transactionAccountId, 'moneyAccount' => $data['money_account_id'], 'transactionDate' => date('Y-m-d', strtotime($data['transaction_date'])), 'amount' => $data['amount']];
                 $orderDao->save(['price' => $data['amount'], 'currency_id' => $moneyAccountCurrencyId], ['id' => $data['order_id']]);
                 $financeService->makeTransaction($transactionData);
                 //attachment processing
                 if ($files->count()) {
                     $errorMessages = $financeService->saveItemFile($files, ['itemId' => $order->getPoItemId()]);
                     if (count($errorMessages)) {
                         throw new \Exception('Cannot save item attachment. ' . print_r($errorMessages, true));
                     }
                     $expenseItemAttachmentsDao = $this->getServiceLocator()->get('dao_finance_expense_expense_item_attachments');
                     $attachmentInfo = $expenseItemAttachmentsDao->getAttachmentsToRemove($order->getPoItemId());
                     $financeService->moveTmpItem($attachmentInfo->getExpenseId(), $order->getPoItemId(), $attachmentInfo->getDateCreated(), $attachmentInfo->getFilename());
                 }
                 $expenseItemDao->commitTransaction();
                 return $moneyAccountCurrencyId;
             }
         } catch (\Exception $e) {
             $expenseItemDao->rollbackTransaction();
             return false;
         }
     }
     return false;
 }