Exemplo n.º 1
0
 /**
  * Returns a new ChildProductQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildProductQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildProductQuery) {
         return $criteria;
     }
     $query = new ChildProductQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Exemplo n.º 2
0
 public static function product($params, $currentUser, $con)
 {
     $products = ProductQuery::create()->filterByStatus('Active')->orderBy('name', 'ASC');
     if (isset($params->query)) {
         $products->condition('cond1', 'Product.Name like ?', "%{$params->query}%");
         $products->condition('cond2', 'Product.Code like ?', "%{$params->query}%");
         $products->where(array('cond1', 'cond2'), 'or');
     }
     $products = $products->select(array('id', 'code', 'name'))->limit(20)->find($con);
     $data = [];
     foreach ($products as $product) {
         $data[] = $product;
     }
     $results['success'] = true;
     $results['data'] = $data;
     return $results;
 }
Exemplo n.º 3
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_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)->where("Product.Id not like ?", $params->id)->count($con);
     if ($product != 0) {
         throw new \Exception('Kode produk sudah terpakai. Pilih kode lainnya.');
     }
     $product = ProductQuery::create()->findOneById($params->id, $con);
     if (!$product) {
         throw new \Exception('Data tidak ditemukan');
     }
     $product->setCode($params->code)->setName($params->name)->save($con);
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($params->id)->setData('product')->setTime(time())->setOperation('update')->setUserId($currentUser->id)->save($con);
     $results['success'] = true;
     $results['id'] = $params->id;
     return $results;
 }
Exemplo n.º 4
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Product::setDeleted()
  * @see Product::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(ProductTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con) {
         $deleteQuery = ChildProductQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $this->setDeleted(true);
         }
     });
 }
Exemplo n.º 5
0
 /**
  * Get the associated ChildProduct object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildProduct The associated ChildProduct object.
  * @throws PropelException
  */
 public function getProduct(ConnectionInterface $con = null)
 {
     if ($this->aProduct === null && ($this->product_id !== "" && $this->product_id !== null)) {
         $this->aProduct = ChildProductQuery::create()->findPk($this->product_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aProduct->addStocks($this);
            */
     }
     return $this->aProduct;
 }
Exemplo n.º 6
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_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.');
     }
     $stock = StockQuery::create()->findOneById($params->id, $con);
     if (!$stock) {
         throw new \Exception('Data tidak ditemukan');
     }
     $stock->setProductId($params->product_id)->setAmount($params->amount)->setUnitId($params->unit_id)->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)->save($con);
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($params->id)->setData('stock')->setTime(time())->setOperation('update')->setUserId($currentUser->id)->save($con);
     $results['success'] = true;
     $results['id'] = $params->id;
     return $results;
 }
Exemplo n.º 7
0
 /**
  * Performs an INSERT on the database, given a Product or Criteria object.
  *
  * @param mixed               $criteria Criteria or Product object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *                         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(ProductTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Product object
     }
     if ($criteria->containsKey(ProductTableMap::COL_ID) && $criteria->keyContainsValue(ProductTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . ProductTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = ProductQuery::create()->mergeWith($criteria);
     // use transaction because $criteria could contain info
     // for more than one table (I guess, conceivably)
     return $con->transaction(function () use($con, $query) {
         return $query->doInsert($con);
     });
 }