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
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see RolePermission::setDeleted()
  * @see RolePermission::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(RolePermissionTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con) {
         $deleteQuery = ChildRolePermissionQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $this->setDeleted(true);
         }
     });
 }
Example #5
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 #6
0
 /**
  * Gets a single ChildRolePermission object, which is related to this object by a one-to-one relationship.
  *
  * @param  ConnectionInterface $con optional connection object
  * @return ChildRolePermission
  * @throws PropelException
  */
 public function getPermission(ConnectionInterface $con = null)
 {
     if ($this->singlePermission === null && !$this->isNew()) {
         $this->singlePermission = ChildRolePermissionQuery::create()->findPk($this->getPrimaryKey(), $con);
     }
     return $this->singlePermission;
 }
Example #7
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 #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
 public static function readPayment($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('read_credit')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     $page = isset($params->page) ? $params->page : 0;
     $limit = isset($params->limit) ? $params->limit : 100;
     $creditPayments = CreditPaymentQuery::create()->filterByStatus('Active')->leftJoin('Cashier')->withColumn('Cashier.Name', 'cashier_name')->useCreditQuery()->useSalesQuery()->leftJoin('SecondParty')->withColumn('SecondParty.Id', 'second_party_id')->withColumn('SecondParty.Name', 'second_party_name')->endUse()->endUse();
     if (isset($params->credit_id)) {
         $creditPayments->filterByCreditId($params->credit_id);
     }
     if (isset($params->second_party)) {
         $creditPayments->useCreditQuery()->useSalesQuery()->useSecondPartyQuery()->filterByName('%' . $params->second_party . '%')->endUse()->endUse()->endUse();
     }
     if (isset($params->start_date)) {
         $creditPayments->filterByDate(array('min' => $params->start_date));
     }
     if (isset($params->until_date)) {
         $creditPayments->filterByDate(array('max' => $params->until_date));
     }
     $creditPayments = $creditPayments->select(array('id', 'date', 'credit_id', 'paid', 'cashier_id', 'cashier_name', 'second_party_id', 'second_party_name'));
     foreach ($params->sort as $sorter) {
         $creditPayments->orderBy($sorter->property, $sorter->direction);
     }
     $creditPayments->orderBy('id', 'DESC');
     $creditPayments = $creditPayments->paginate($page, $limit);
     $total = $creditPayments->getNbResults();
     $data = [];
     foreach ($creditPayments as $creditPayment) {
         $data[] = $creditPayment;
     }
     $results['success'] = true;
     $results['data'] = $data;
     $results['total'] = $total;
     return $results;
 }
Example #10
0
 public static function viewDetail($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('read_sales')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     $sales = Sale::seeker($params, $currentUser, $con);
     $logData['data'] = $sales['data'];
     $logData['detail'] = $sales['detail'];
     // log history
     $salesHistory = new SalesHistory();
     $salesHistory->setUserId($currentUser->id)->setSalesId($params->id)->setTime(time())->setOperation('viewDetail')->setData(json_encode($logData))->save($con);
     $results['success'] = true;
     $results['data'] = $sales['data'];
     $results['detail'] = $sales['detail'];
     return $results;
 }
Example #11
0
 public static function viewDetail($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('read_second_party')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     $customer = Customers::seeker($params, $currentUser, $con);
     $stats = Customers::getStats($params, $currentUser, $con);
     $results['success'] = true;
     $results['detail'] = $customer['data'];
     $results['stats'] = $stats['data'];
     return $results;
 }
Example #12
0
 /**
  * Performs an INSERT on the database, given a RolePermission or Criteria object.
  *
  * @param mixed               $criteria Criteria or RolePermission 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(RolePermissionTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from RolePermission object
     }
     // Set the correct dbName
     $query = RolePermissionQuery::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);
     });
 }
Example #13
0
 /**
  * Returns a new ChildRolePermissionQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildRolePermissionQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildRolePermissionQuery) {
         return $criteria;
     }
     $query = new ChildRolePermissionQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }