Example #1
0
 public static function create($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('create_second_party')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     // create new record
     $secondParty = new SecondParty();
     $secondParty->setRegisteredDate(Date('Y-m-d'))->setName($params->name)->setAddress($params->address)->setGender($params->gender)->setPhone($params->phone)->setType($params->type)->setStatus('Active')->save($con);
     // log history
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($secondParty->getId())->setData('second_party')->setTime(time())->setOperation('create')->setUserId($currentUser->id)->save($con);
     $params->id = $secondParty->getId();
     $results['success'] = true;
     $results['data'] = $params;
     return $results;
 }
Example #2
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;
 }
Example #3
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_user')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     if ($params->id == 1 && $params->user != 'admin') {
         throw new \Exception('User ID Default Admin tidak boleh diubah.');
     }
     if ($params->id == 1 && $params->role_id != 1) {
         throw new \Exception('Role Default Admin tidak boleh diubah.');
     }
     // check whether picked username is already taken
     $user = UserQuery::create()->filterByUser($params->user)->where("User.Id not like ?", $params->id)->count($con);
     if ($user != 0) {
         throw new \Exception('User ID sudah terpakai. Pilih User ID lainnya.');
     }
     $user = UserQuery::create()->findOneById($params->id, $con);
     $detail = UserDetailQuery::create()->findOneById($params->id, $con);
     if (!$user || !$detail) {
         throw new \Exception('Data tidak ditemukan');
     }
     $user->setUser($params->user)->setRoleId($params->role_id)->save($con);
     $detail->setName($params->name)->setAddress($params->address)->setPhone($params->phone)->save($con);
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($params->id)->setData('user')->setTime(time())->setOperation('update')->setUserId($currentUser->id)->save($con);
     $results['success'] = true;
     $results['id'] = $params->id;
     return $results;
 }
Example #4
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_role')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     // check whether role is already exist
     $role = RoleQuery::create()->filterByStatus('Active')->filterByName($params->name)->where('Role.Id not like ?', $params->id)->count($con);
     if ($role != 0) {
         throw new \Exception('Jabatan ' . $params->name . ' sudah ada dalam data');
     }
     $role = RoleQuery::create()->filterByStatus('Active')->findOneById($params->id, $con);
     if (!$role) {
         throw new \Exception('Data tidak ditemukan');
     }
     $role->setName($params->name)->save($con);
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($params->id)->setData('role')->setTime(time())->setOperation('update')->setUserId($currentUser->id)->save($con);
     $results['success'] = true;
     $results['data'] = $params;
     return $results;
 }
Example #5
0
 public static function update($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('update_second_party')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     $supplier = SecondPartyQuery::create()->filterByStatus('Active')->findOneById($params->id, $con);
     if (!$supplier) {
         throw new \Exception('Data tidak ditemukan');
     }
     $supplier->setName($params->name)->setAddress($params->address)->setPhone($params->phone)->save($con);
     $rowHistory = new RowHistory();
     $rowHistory->setRowId($params->id)->setData('supplier')->setTime(time())->setOperation('update')->setUserId($currentUser->id)->save($con);
     $results['success'] = true;
     $results['data'] = $params;
     return $results;
 }
Example #6
0
 /**
  * @param ChildRowHistory $history The ChildRowHistory object to add.
  */
 protected function doAddHistory(ChildRowHistory $history)
 {
     $this->collHistories[] = $history;
     $history->setUserDetail($this);
 }
Example #7
0
 /**
  * Filter the query by a related \ORM\RowHistory object
  *
  * @param \ORM\RowHistory|ObjectCollection $rowHistory  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildUserDetailQuery The current query, for fluid interface
  */
 public function filterByHistory($rowHistory, $comparison = null)
 {
     if ($rowHistory instanceof \ORM\RowHistory) {
         return $this->addUsingAlias(UserDetailTableMap::COL_ID, $rowHistory->getUserId(), $comparison);
     } elseif ($rowHistory instanceof ObjectCollection) {
         return $this->useHistoryQuery()->filterByPrimaryKeys($rowHistory->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByHistory() only accepts arguments of type \\ORM\\RowHistory or Collection');
     }
 }
Example #8
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;
 }
Example #9
0
 /**
  * Exclude object from result
  *
  * @param   ChildRowHistory $rowHistory Object to remove from the list of results
  *
  * @return $this|ChildRowHistoryQuery The current query, for fluid interface
  */
 public function prune($rowHistory = null)
 {
     if ($rowHistory) {
         $this->addUsingAlias(RowHistoryTableMap::COL_ID, $rowHistory->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }