public static function create($params, $currentUser, $con) { // check role's permission $permission = RolePermissionQuery::create()->select('create_stock')->findOneById($currentUser->role_id, $con); if (!$permission || $permission != 1) { throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.'); } // check whether chosen product is still Active $product = ProductQuery::create()->select('status')->findOneById($params->product_id, $con); if (!$product || $product != 'Active') { throw new \Exception('Produk tidak ditemukan. Mungkin Produk itu sudah dihapus.'); } // make sure there are no duplicate (same product and unit) variant in stock $stock = StockQuery::create()->filterByStatus('Active')->leftJoin('Product')->leftJoin('Unit')->filterByProductId($params->product_id)->filterByUnitId($params->unit_id)->withColumn('Product.Name', 'product_name')->withColumn('Unit.Name', 'unit_name')->select(array('product_name', 'unit_name'))->findOne($con); if ($stock) { throw new \Exception('Gagal menyimpan karena variant ' . $stock['product_name'] . ' <strong>' . $stock['unit_name'] . '</strong> sudah ada.'); } // create new stock $stock = new Stock(); $stock->setProductId($params->product_id)->setUnitId($params->unit_id)->setAmount(isset($params->amount) ? $params->amount : 0)->setBuy($params->buy)->setSellPublic($params->sell_public)->setSellDistributor($params->sell_distributor == 0 ? $params->sell_public : $params->sell_distributor)->setSellMisc($params->sell_misc == 0 ? $params->sell_public : $params->sell_misc)->setDiscount($params->discount)->setUnlimited(isset($params->unlimited) ? $params->unlimited : 0)->setStatus('Active')->save($con); // log history $rowHistory = new RowHistory(); $rowHistory->setRowId($stock->getId())->setData('stock')->setTime(time())->setOperation('create')->setUserId($currentUser->id)->save($con); $params->id = $stock->getId(); $stock = Stocks::seeker($params, $currentUser, $con); $results['success'] = true; $results['data'] = $stock['data']; return $results; }
/** * @param ChildStock $stock The ChildStock object to add. */ protected function doAddStock(ChildStock $stock) { $this->collStocks[] = $stock; $stock->setUnit($this); }
/** * Filter the query by a related \ORM\Stock object * * @param \ORM\Stock|ObjectCollection $stock the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildProductQuery The current query, for fluid interface */ public function filterByStock($stock, $comparison = null) { if ($stock instanceof \ORM\Stock) { return $this->addUsingAlias(ProductTableMap::COL_ID, $stock->getProductId(), $comparison); } elseif ($stock instanceof ObjectCollection) { return $this->useStockQuery()->filterByPrimaryKeys($stock->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByStock() only accepts arguments of type \\ORM\\Stock or Collection'); } }
/** * Filter the query by a related \ORM\Stock object * * @param \ORM\Stock|ObjectCollection $stock The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildSalesDetailQuery The current query, for fluid interface */ public function filterByStock($stock, $comparison = null) { if ($stock instanceof \ORM\Stock) { return $this->addUsingAlias(SalesDetailTableMap::COL_STOCK_ID, $stock->getId(), $comparison); } elseif ($stock instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(SalesDetailTableMap::COL_STOCK_ID, $stock->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByStock() only accepts arguments of type \\ORM\\Stock or Collection'); } }
/** * Exclude object from result * * @param ChildStock $stock Object to remove from the list of results * * @return $this|ChildStockQuery The current query, for fluid interface */ public function prune($stock = null) { if ($stock) { $this->addUsingAlias(StockTableMap::COL_ID, $stock->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * 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->aSales) { $this->aSales->removeDetail($this); } if (null !== $this->aStock) { $this->aStock->removeSales($this); } $this->id = null; $this->sales_id = null; $this->type = null; $this->stock_id = null; $this->amount = null; $this->unit_price = null; $this->discount = null; $this->total_price = null; $this->buy = null; $this->sell_public = null; $this->sell_distributor = null; $this->sell_misc = null; $this->status = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * 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); }