public static function pay($params, $currentUser, $con) { // check role's permission $permission = RolePermissionQuery::create()->select('pay_credit')->findOneById($currentUser->role_id, $con); if (!$permission || $permission != 1) { throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.'); } // make sure the credit is not fully paid already $credit = CreditQuery::create()->filterByStatus('Active')->filterById($params->credit_id)->withColumn('CONVERT(Credit.Total, SIGNED) - CONVERT(Credit.Paid, SIGNED)', 'Balance')->findOne($con); if (!$credit) { throw new \Exception('Data tidak ditemukan.'); } // if credit is already fully paid then stop paying if ($credit->getBalance() <= 0) { throw new \Exception('Piutang ini sudah dilunasi.'); } // create new payment $creditPayment = new CreditPayment(); $creditPayment->setDate($params->date)->setCreditId($params->credit_id)->setPaid($params->paid)->setCashierId($params->cashier)->setStatus('Active')->save($con); $payment = CreditPaymentQuery::create()->filterByStatus('Active')->filterByCreditId($params->credit_id)->withColumn('SUM(Paid)', 'paid')->select(array('paid'))->groupBy('CreditId')->findOne($con); $credit->setPaid($payment)->save($con); $results['success'] = true; $results['data'] = 'Yay'; return $results; }
/** * Exclude object from result * * @param ChildCreditPayment $creditPayment Object to remove from the list of results * * @return $this|ChildCreditPaymentQuery The current query, for fluid interface */ public function prune($creditPayment = null) { if ($creditPayment) { $this->addUsingAlias(CreditPaymentTableMap::COL_ID, $creditPayment->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related \ORM\CreditPayment object * * @param \ORM\CreditPayment|ObjectCollection $creditPayment the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCreditQuery The current query, for fluid interface */ public function filterByPayment($creditPayment, $comparison = null) { if ($creditPayment instanceof \ORM\CreditPayment) { return $this->addUsingAlias(CreditTableMap::COL_ID, $creditPayment->getCreditId(), $comparison); } elseif ($creditPayment instanceof ObjectCollection) { return $this->usePaymentQuery()->filterByPrimaryKeys($creditPayment->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByPayment() only accepts arguments of type \\ORM\\CreditPayment or Collection'); } }
/** * @param ChildCreditPayment $creditPayment The ChildCreditPayment object to add. */ protected function doAddCreditPayment(ChildCreditPayment $creditPayment) { $this->collCreditPayments[] = $creditPayment; $creditPayment->setCashier($this); }
/** * @param ChildCreditPayment $payment The ChildCreditPayment object to add. */ protected function doAddPayment(ChildCreditPayment $payment) { $this->collPayments[] = $payment; $payment->setCredit($this); }