Example #1
0
 /**
  * Exclude object from result
  *
  * @param   ChildDebit $debit Object to remove from the list of results
  *
  * @return $this|ChildDebitQuery The current query, for fluid interface
  */
 public function prune($debit = null)
 {
     if ($debit) {
         $this->addUsingAlias(DebitTableMap::COL_ID, $debit->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #2
0
 /**
  * Filter the query by a related \ORM\Debit object
  *
  * @param \ORM\Debit|ObjectCollection $debit The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildDebitPaymentQuery The current query, for fluid interface
  */
 public function filterByDebit($debit, $comparison = null)
 {
     if ($debit instanceof \ORM\Debit) {
         return $this->addUsingAlias(DebitPaymentTableMap::COL_DEBIT_ID, $debit->getId(), $comparison);
     } elseif ($debit instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(DebitPaymentTableMap::COL_DEBIT_ID, $debit->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByDebit() only accepts arguments of type \\ORM\\Debit or Collection');
     }
 }
Example #3
0
 /**
  * Filter the query by a related \ORM\Debit object
  *
  * @param \ORM\Debit|ObjectCollection $debit  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildPurchaseQuery The current query, for fluid interface
  */
 public function filterByDebit($debit, $comparison = null)
 {
     if ($debit instanceof \ORM\Debit) {
         return $this->addUsingAlias(PurchaseTableMap::COL_ID, $debit->getPurchaseId(), $comparison);
     } elseif ($debit instanceof ObjectCollection) {
         return $this->useDebitQuery()->filterByPrimaryKeys($debit->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByDebit() only accepts arguments of type \\ORM\\Debit or Collection');
     }
 }
Example #4
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aDebit) {
         $this->aDebit->removePayment($this);
     }
     if (null !== $this->aCashier) {
         $this->aCashier->removeDebitPayment($this);
     }
     $this->id = null;
     $this->date = null;
     $this->debit_id = null;
     $this->cashier_id = null;
     $this->paid = null;
     $this->status = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Example #5
0
 /**
  * @param ChildDebit $debit The ChildDebit object to add.
  */
 protected function doAddDebit(ChildDebit $debit)
 {
     $this->collDebits[] = $debit;
     $debit->setPurchase($this);
 }
Example #6
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_purchase')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     $purchase = PurchaseQuery::create()->findOneById($params->id, $con);
     if (!$purchase) {
         throw new \Exception('Data tidak ditemukan');
     }
     $purchase->setDate($params->date)->setSecondPartyId($params->second_party_id)->setTotalPrice($params->total_price)->setPaid($params->paid)->setNote($params->note)->setStatus('Active')->save($con);
     // check wether this transaction is debit or not, then if yes, create new debit record
     $balance = $params->paid - $params->total_price;
     if ($balance < 0) {
         $debit = DebitQuery::create()->filterByPurchaseId($purchase->getId())->findOne($con);
         if (!$debit) {
             $debit = new Debit();
         }
         $debit->setPurchaseId($purchase->getId())->setTotal(abs($balance))->setStatus('Active')->save($con);
     } else {
         $debit = DebitQuery::create()->filterByPurchaseId($purchase->getId())->findOne($con);
         if ($debit) {
             $debit->setPurchaseId($purchase->getId())->setTotal(0)->setStatus('Canceled')->save($con);
         }
     }
     $products = json_decode($params->products);
     foreach ($products as $product) {
         // check whether current detail iteration is brand new or just updating the old one
         $newDetail = PurchaseDetailQuery::create()->findOneById($product->id);
         if (!$newDetail) {
             $isNew = true;
             $newDetail = new PurchaseDetail();
         } else {
             $isNew = false;
             $oldDetail = $newDetail->copy();
         }
         $newDetail->setPurchaseId($purchase->getId())->setStockId($product->stock_id)->setAmount($product->amount)->setTotalPrice($product->total_price)->setStatus('Active')->save($con);
         // make stock dance ^_^
         if ($isNew) {
             $stock = StockQuery::create()->findOneById($newDetail->getStockId(), $con);
             if ($stock->getUnlimited() == false) {
                 $stock->setAmount($stock->getAmount() + $product->amount)->save($con);
             }
         } else {
             // check whether updated detail stock is the same old one or not
             if ($newDetail->getStockId() == $oldDetail->getStockId()) {
                 // and if actually the same, then set stock amount like this
                 // amount = currentAmount - oldTransAmount + newTransAmount
                 $stock = StockQuery::create()->findOneById($newDetail->getStockId(), $con);
                 if ($stock->getUnlimited() == false) {
                     $stock->setAmount($stock->getAmount() - $oldDetail->getAmount() + $newDetail->getAmount())->save($con);
                 }
             } else {
                 // but if two stocks is not the same,
                 // then take back oldTransAmount from old-stock, and give newTransAmount to new-stock
                 $stock = StockQuery::create()->findOneById($oldDetail->getStockId(), $con);
                 if ($stock->getUnlimited() == false) {
                     $stock->setAmount($stock->getAmount() - $oldDetail->getAmount())->save($con);
                 }
                 $stock = StockQuery::create()->findOneById($newDetail->getStockId(), $con);
                 if ($stock->getUnlimited() == false) {
                     $stock->setAmount($stock->getAmount() + $newDetail->getAmount())->save($con);
                 }
             }
         }
         $notificationId = Purchases::newPriceNotification($stock, $newDetail, $con);
         if ($isNew || !($notificationId == 0)) {
             $newDetail->setNotificationId($notificationId)->save($con);
         }
     }
     // if there are any sales detail removed then make sure the stocks give back something they own... 'give back amount'
     $removeds = PurchaseDetailQuery::create()->filterById($params->removed_id)->find($con);
     foreach ($removeds as $removed) {
         $stock = StockQuery::create()->findOneById($removed->getStockId(), $con);
         if ($stock->getUnlimited() == false) {
             $stock->setAmount($stock->getAmount() - $removed->getAmount())->save($con);
         }
         $removed->setStatus('Deleted')->save($con);
         $notification = $removed->getNotification();
         if ($notification) {
             $notification->delete($con);
         }
     }
     $logData['params'] = $params;
     // log history
     $purchaseHistory = new PurchaseHistory();
     $purchaseHistory->setUserId($currentUser->id)->setPurchaseId($params->id)->setTime(time())->setOperation('update')->setData(json_encode($logData))->save($con);
     $results['success'] = true;
     $results['id'] = $params->id;
     return $results;
 }