Example #1
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->aPurchase) {
         $this->aPurchase->removeDebit($this);
     }
     $this->id = null;
     $this->purchase_id = null;
     $this->total = null;
     $this->paid = null;
     $this->status = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Example #2
0
 /**
  * Filter the query by a related \ORM\Purchase object
  *
  * @param \ORM\Purchase|ObjectCollection $purchase The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildDebitQuery The current query, for fluid interface
  */
 public function filterByPurchase($purchase, $comparison = null)
 {
     if ($purchase instanceof \ORM\Purchase) {
         return $this->addUsingAlias(DebitTableMap::COL_PURCHASE_ID, $purchase->getId(), $comparison);
     } elseif ($purchase instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(DebitTableMap::COL_PURCHASE_ID, $purchase->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByPurchase() only accepts arguments of type \\ORM\\Purchase or Collection');
     }
 }
Example #3
0
 /**
  * Filter the query by a related \ORM\Purchase object
  *
  * @param \ORM\Purchase|ObjectCollection $purchase  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildSecondPartyQuery The current query, for fluid interface
  */
 public function filterByPurchase($purchase, $comparison = null)
 {
     if ($purchase instanceof \ORM\Purchase) {
         return $this->addUsingAlias(SecondPartyTableMap::COL_ID, $purchase->getSecondPartyId(), $comparison);
     } elseif ($purchase instanceof ObjectCollection) {
         return $this->usePurchaseQuery()->filterByPrimaryKeys($purchase->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByPurchase() only accepts arguments of type \\ORM\\Purchase or Collection');
     }
 }
Example #4
0
 /**
  * Exclude object from result
  *
  * @param   ChildPurchase $purchase Object to remove from the list of results
  *
  * @return $this|ChildPurchaseQuery The current query, for fluid interface
  */
 public function prune($purchase = null)
 {
     if ($purchase) {
         $this->addUsingAlias(PurchaseTableMap::COL_ID, $purchase->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #5
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->aPurchase) {
         $this->aPurchase->removeDetail($this);
     }
     if (null !== $this->aStock) {
         $this->aStock->removePurchase($this);
     }
     if (null !== $this->aNotification) {
         $this->aNotification->removePurchaseDetail($this);
     }
     $this->id = null;
     $this->purchase_id = null;
     $this->stock_id = null;
     $this->amount = null;
     $this->total_price = null;
     $this->notification_id = null;
     $this->status = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Example #6
0
 public static function create($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('create_purchase')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     // create new purchase
     $purchase = new Purchase();
     $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 = new Debit();
         $debit->setPurchaseId($purchase->getId())->setTotal(abs($balance))->setStatus('Active')->save($con);
     }
     $products = json_decode($params->products);
     foreach ($products as $product) {
         // create new record representing product stock which is being purchased
         $purchaseDetail = new PurchaseDetail();
         $purchaseDetail->setPurchaseId($purchase->getId())->setStockId($product->stock_id)->setAmount($product->amount)->setTotalPrice($product->total_price)->setStatus('Active')->save($con);
         // add stock amount
         $stock = StockQuery::create()->findOneById($product->stock_id, $con);
         if ($stock->getUnlimited() == false) {
             $stock->setAmount($stock->getAmount() + $product->amount)->save($con);
         }
         $notification = Purchases::newPriceNotification($stock, $purchaseDetail, $con);
         $purchaseDetail->setNotificationId($notification)->save($con);
     }
     $logData['params'] = $params;
     // log history
     $purchaseHistory = new PurchaseHistory();
     $purchaseHistory->setUserId($currentUser->id)->setPurchaseId($purchase->getId())->setTime(time())->setOperation('create')->setData(json_encode($logData))->save($con);
     $results['success'] = true;
     $results['id'] = $purchase->getId();
     return $results;
 }
Example #7
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->aUserDetail) {
         $this->aUserDetail->removePurchaseHistory($this);
     }
     if (null !== $this->aPurchase) {
         $this->aPurchase->removeHistory($this);
     }
     $this->id = null;
     $this->user_id = null;
     $this->purchase_id = null;
     $this->time = null;
     $this->operation = null;
     $this->data = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }