Esempio n. 1
0
 public static function create($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('create_product')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     // check whether picked code is already used
     $product = ProductQuery::create()->filterByCode($params->code)->count($con);
     if ($product != 0) {
         throw new \Exception('Kode produk sudah terpakai. Pilih kode lainnya.');
     }
     // create new record
     $product = new Product();
     $product->setCode($params->code)->setName($params->name)->setStatus('Active')->save($con);
     // log history
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($product->getId())->setData('product')->setTime(time())->setOperation('create')->setUserId($currentUser->id)->save($con);
     $params->id = $product->getId();
     $results['success'] = true;
     $results['data'] = $params;
     return $results;
 }
Esempio n. 2
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->aProduct) {
         $this->aProduct->removeStock($this);
     }
     if (null !== $this->aUnit) {
         $this->aUnit->removeStock($this);
     }
     $this->id = null;
     $this->product_id = null;
     $this->amount = null;
     $this->unit_id = null;
     $this->buy = null;
     $this->sell_public = null;
     $this->sell_distributor = null;
     $this->sell_misc = null;
     $this->discount = null;
     $this->unlimited = null;
     $this->status = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Esempio n. 3
0
 /**
  * Exclude object from result
  *
  * @param   ChildProduct $product Object to remove from the list of results
  *
  * @return $this|ChildProductQuery The current query, for fluid interface
  */
 public function prune($product = null)
 {
     if ($product) {
         $this->addUsingAlias(ProductTableMap::COL_ID, $product->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Esempio n. 4
0
 /**
  * Filter the query by a related \ORM\Product object
  *
  * @param \ORM\Product|ObjectCollection $product The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildStockQuery The current query, for fluid interface
  */
 public function filterByProduct($product, $comparison = null)
 {
     if ($product instanceof \ORM\Product) {
         return $this->addUsingAlias(StockTableMap::COL_PRODUCT_ID, $product->getId(), $comparison);
     } elseif ($product instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(StockTableMap::COL_PRODUCT_ID, $product->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByProduct() only accepts arguments of type \\ORM\\Product or Collection');
     }
 }