Esempio n. 1
0
 /**
  * Filter the query by a related \ORM\Credit object
  *
  * @param \ORM\Credit|ObjectCollection $credit The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCreditPaymentQuery The current query, for fluid interface
  */
 public function filterByCredit($credit, $comparison = null)
 {
     if ($credit instanceof \ORM\Credit) {
         return $this->addUsingAlias(CreditPaymentTableMap::COL_CREDIT_ID, $credit->getId(), $comparison);
     } elseif ($credit instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CreditPaymentTableMap::COL_CREDIT_ID, $credit->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByCredit() only accepts arguments of type \\ORM\\Credit or Collection');
     }
 }
Esempio n. 2
0
 /**
  * Exclude object from result
  *
  * @param   ChildCredit $credit Object to remove from the list of results
  *
  * @return $this|ChildCreditQuery The current query, for fluid interface
  */
 public function prune($credit = null)
 {
     if ($credit) {
         $this->addUsingAlias(CreditTableMap::COL_ID, $credit->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Esempio n. 3
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_sales')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     $sales = SalesQuery::create()->findOneById($params->id, $con);
     if (!$sales) {
         throw new \Exception('Data tidak ditemukan');
     }
     $sales->setDate($params->date)->setSecondPartyId($params->second_party_id)->setBuyPrice($params->buy_price)->setTotalPrice($params->total_price)->setPaid($params->paid)->setCashierId($params->cashier_id)->setNote($params->note)->setStatus('Active')->save($con);
     // check wether this transaction is credit or not
     $balance = $params->paid - $params->total_price;
     if ($balance < 0) {
         $credit = CreditQuery::create()->filterBySalesId($sales->getId())->findOne($con);
         if (!$credit) {
             $credit = new Credit();
         }
         $credit->setSalesId($sales->getId())->setTotal(abs($balance))->setStatus('Active')->save($con);
     } else {
         $credit = CreditQuery::create()->filterBySalesId($sales->getId())->findOne($con);
         if ($credit) {
             $credit->setSalesId($sales->getId())->setTotal(0)->setStatus('Canceled')->save($con);
         }
     }
     $products = json_decode($params->products);
     // iterate through every product on this sales operation
     foreach ($products as $product) {
         $newDetail = SalesDetailQuery::create()->findOneById($product->id);
         // check whether current detail iteration is brand new or just updating the old one
         if (!$newDetail) {
             $isNew = true;
             $newDetail = new SalesDetail();
         } else {
             $isNew = false;
             $oldDetail = $newDetail->copy();
         }
         $newDetail->setSalesId($sales->getId())->setType($product->type)->setStockId($product->stock_id)->setAmount($product->amount)->setUnitPrice($product->unit_price)->setDiscount($product->discount)->setTotalPrice($product->total_price)->setBuy($product->buy)->setSellPublic($product->sell_public)->setSellDistributor($product->sell_distributor)->setSellMisc($product->sell_misc)->setStatus('Active')->save($con);
         // make stock dance ^_^
         if ($isNew) {
             $stock = StockQuery::create()->findOneById($newDetail->getStockId(), $con);
             if ($stock->getUnlimited() == false) {
                 $stock->setAmount($stock->getAmount() - $newDetail->getAmount())->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 give back oldTransAmount to old-stock, and take newTransAmount from 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);
                 }
             }
         }
     }
     // if there are any sales detail removed then make sure the stocks get what it deserve... 'gimme amount'
     $removeds = SalesDetailQuery::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);
     }
     $logData['params'] = $params;
     // log history
     $salesHistory = new SalesHistory();
     $salesHistory->setUserId($currentUser->id)->setSalesId($params->id)->setTime(time())->setOperation('update')->setData(json_encode($logData))->save($con);
     $results['success'] = true;
     $results['id'] = $params->id;
     return $results;
 }
Esempio n. 4
0
 /**
  * @param ChildCredit $credit The ChildCredit object to add.
  */
 protected function doAddCredit(ChildCredit $credit)
 {
     $this->collCredits[] = $credit;
     $credit->setSales($this);
 }
Esempio n. 5
0
 /**
  * Filter the query by a related \ORM\Credit object
  *
  * @param \ORM\Credit|ObjectCollection $credit  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildSalesQuery The current query, for fluid interface
  */
 public function filterByCredit($credit, $comparison = null)
 {
     if ($credit instanceof \ORM\Credit) {
         return $this->addUsingAlias(SalesTableMap::COL_ID, $credit->getSalesId(), $comparison);
     } elseif ($credit instanceof ObjectCollection) {
         return $this->useCreditQuery()->filterByPrimaryKeys($credit->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByCredit() only accepts arguments of type \\ORM\\Credit or Collection');
     }
 }
Esempio n. 6
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->aCredit) {
         $this->aCredit->removePayment($this);
     }
     if (null !== $this->aCashier) {
         $this->aCashier->removeCreditPayment($this);
     }
     $this->id = null;
     $this->date = null;
     $this->credit_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);
 }