示例#1
0
文件: Mains.php 项目: AlvaCorp/POS-2
 function login(stdClass $params)
 {
     require 'session.php';
     $con = Propel::getConnection('pos');
     $con->beginTransaction();
     try {
         $user = UserQuery::create()->filterByUser($params->user)->count($con);
         if ($user == 0) {
             throw new Exception('User ID yang Anda masukkan salah');
         }
         $user = UserQuery::create()->filterByUser($params->user)->filterByPassword($params->pass)->select(array('id', 'user', 'role_id'))->leftJoin('Detail')->withColumn('Detail.Name', 'name')->withColumn('Detail.Address', 'address')->withColumn('Detail.Phone', 'phone')->findOne($con);
         if (!$user) {
             throw new Exception('Password tidak sesuai dengan User ID yang Anda masukkan');
         }
         if (!$user['role_id']) {
             throw new Exception('Anda belum mempunyai Jabatan. Mohon hubungi petugas berwenang dan mintalah Jabatan terlebih dahulu.');
         }
         $menu = $this->getMenu(1, $con);
         $results['success'] = true;
         $results['state'] = 1;
         $results['current_user'] = (object) $user;
         $results['menu'] = $menu;
         $session->set('pos/state', 1);
         $session->set('pos/current_user', (object) $user);
         $con->commit();
     } catch (Exception $e) {
         $con->rollBack();
         $results['success'] = false;
         $results['errmsg'] = $e->getMessage();
     }
     return $results;
 }
示例#2
0
 public static function destroy($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('destroy_role')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     if (in_array(1, $params->id)) {
         throw new Exception('Jabatan Super User tidak bisa dihapus.');
     }
     $roles = RoleQuery::create()->filterById($params->id)->find($con);
     if (!$roles) {
         throw new \Exception('Data tidak ditemukan');
     }
     foreach ($roles as $role) {
         // check users currently assigned to this role
         $users = UserQuery::create()->filterByRoleId($role->getId())->find($con);
         // if any user found, then update their role to NULL
         foreach ($users as $user) {
             $user->setRoleId(null)->save($con);
         }
         $role->setStatus('Deleted')->save($con);
         $rowHistory = new RowHistory();
         $rowHistory->setRowId($role->getId())->setData('unit')->setTime(time())->setOperation('destroy')->setUserId($currentUser->id)->save($con);
     }
     $results['success'] = true;
     $results['id'] = $params->id;
     return $results;
 }
示例#3
0
 private static function newPriceNotification($stock, $purchaseDetail, $con)
 {
     // check price change
     $priceDifference = $stock->getBuy() - $purchaseDetail->getTotalPrice() / $purchaseDetail->getAmount();
     if ($priceDifference == 0) {
         $priceStatus = 'stagnant';
     } elseif ($priceDifference < 0) {
         $priceStatus = 'up';
     } elseif ($priceDifference > 0) {
         $priceStatus = 'down';
     }
     // if price is not stagnant then make new notification
     if ($priceStatus != 'stagnant') {
         // build up notification data
         $notificationData = new \stdClass();
         $notificationData->stock_id = $stock->getId();
         $notificationData->status = $priceStatus;
         $notificationData->difference = abs($priceDifference);
         $notificationData->to_price = $stock->getBuy() - $priceDifference;
         // update stock buy price
         $stock->setBuy($notificationData->to_price)->save($con);
         // check whether price notification for this purchase detail is already there
         $oldNotification = $purchaseDetail->getNotification();
         if ($oldNotification) {
             // if yes, assign the old one
             $isNew = false;
             $notification = $oldNotification;
         } else {
             // if not, create new notification
             $isNew = true;
             $notification = new Notification();
         }
         $notification->setTime(time())->setType('price')->setData(json_encode($notificationData))->save($con);
         // if notification is new, then give notification to user
         // if not, then update notification's status to unread
         if ($isNew == true) {
             // find which role to send notification
             $roles = NotificationOptionQuery::create()->filterByType('price')->find($con);
             // iterate through each role to find users assigned to it
             foreach ($roles as $role) {
                 $users = UserQuery::create()->filterByStatus('Active')->filterByRoleId($role->getRoleId())->find($con);
                 // iterate through each user to give notification
                 foreach ($users as $user) {
                     $notifyUser = new NotificationOnUser();
                     $notifyUser->setUserId($user->getId())->setNotificationId($notification->getId())->save($con);
                 }
             }
         } else {
             $notifyUsers = NotificationOnUserQuery::create()->filterByNotificationId($notification->getId())->find($con);
             foreach ($notifyUsers as $notifyUser) {
                 $notifyUser->setStatus('Unread')->save($con);
             }
         }
         $notificationId = $notification->getId();
     } else {
         $notificationId = 0;
     }
     return $notificationId;
 }
示例#4
0
 public static function changePassword($params, $currentUser, $con)
 {
     if (!isset($params->oldPassEncrypted) || !isset($params->newPassEncrypted)) {
         throw new \Exception('Missing parameter');
     }
     $user = UserQuery::create()->filterById($currentUser->id)->filterByPassword($params->oldPassEncrypted)->findOne($con);
     if (!$user) {
         throw new \Exception('Password lama salah!');
     }
     $user->setPassword($params->newPassEncrypted)->save($con);
     $results['success'] = true;
     $results['data'] = 'Yay';
     return $results;
 }
示例#5
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;
 }
示例#6
0
文件: Role.php 项目: AlvaCorp/POS-2
 /**
  * Returns the number of related User objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      ConnectionInterface $con
  * @return int             Count of related User objects.
  * @throws PropelException
  */
 public function countUsers(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     $partial = $this->collUsersPartial && !$this->isNew();
     if (null === $this->collUsers || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collUsers) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getUsers());
         }
         $query = ChildUserQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByRole($this)->count($con);
     }
     return count($this->collUsers);
 }
示例#7
0
 /**
  * Get the associated ChildUser object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildUser The associated ChildUser object.
  * @throws PropelException
  */
 public function getUser(ConnectionInterface $con = null)
 {
     if ($this->aUser === null && ($this->id !== "" && $this->id !== null)) {
         $this->aUser = ChildUserQuery::create()->findPk($this->id, $con);
         // Because this foreign key represents a one-to-one relationship, we will create a bi-directional association.
         $this->aUser->setDetail($this);
     }
     return $this->aUser;
 }
示例#8
0
 /**
  * Returns a new ChildUserQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildUserQuery
  */
 public static function create($modelAlias = null, Criteria $criteria = null)
 {
     if ($criteria instanceof ChildUserQuery) {
         return $criteria;
     }
     $query = new ChildUserQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
示例#9
0
 /**
  * Performs an INSERT on the database, given a User or Criteria object.
  *
  * @param mixed               $criteria Criteria or User 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(UserTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from User object
     }
     if ($criteria->containsKey(UserTableMap::COL_ID) && $criteria->keyContainsValue(UserTableMap::COL_ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . UserTableMap::COL_ID . ')');
     }
     // Set the correct dbName
     $query = UserQuery::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);
     });
 }
示例#10
0
文件: init.php 项目: AlvaCorp/POS-2
     $info[$row->getName()] = $row->getValue();
 }
 $root['info'] = $info;
 // get shortcut key from database
 $shortcutKeys = [];
 $keys = OptionQuery::create()->filterByName(['sales_key', 'sales_add_key', 'sales_pay_key', 'sales_save_key', 'sales_cancel_key', 'purchase_key', 'purchase_add_key', 'purchase_pay_key', 'purchase_save_key', 'purchase_cancel_key'])->find($con);
 foreach ($keys as $key) {
     $shortcutKeys[$key->getName()] = $key->getValue();
 }
 $root['shortcutKeys'] = $shortcutKeys;
 // Check previous session
 try {
     if ($session->get('pos/state') === 0 || !isset($session->get('pos/current_user')->id)) {
         throw new Exception();
     }
     $user = UserQuery::create()->filterById($session->get('pos/current_user')->id)->select(['id', 'user', 'role_id'])->leftJoin('Detail')->withColumn('Detail.Name', 'name')->withColumn('Detail.Address', 'address')->withColumn('Detail.Phone', 'phone')->findOne($con);
     if (!$user) {
         throw new Exception();
     }
     $root['state'] = 1;
     $root['current_user'] = (object) $user;
 } catch (Exception $e) {
     $root['state'] = 0;
     $root['current_user'] = null;
 }
 // Get menu from database based on state
 $menu = [];
 $menus = MenuQuery::create()->filterByStatus('Active');
 $root['state'] == 1 || $menus->filterByState(0);
 $menus->select(array('sub', 'icon', 'text', 'action'))->orderBy('sub', 'ASC')->orderBy('order', 'ASC')->find($con);
 foreach ($menus as $row) {
示例#11
0
 /**
  * Get the associated ChildUser object
  *
  * @param  ConnectionInterface $con Optional Connection object.
  * @return ChildUser The associated ChildUser object.
  * @throws PropelException
  */
 public function getUser(ConnectionInterface $con = null)
 {
     if ($this->aUser === null && ($this->user_id !== "" && $this->user_id !== null)) {
         $this->aUser = ChildUserQuery::create()->findPk($this->user_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->aUser->addNotifications($this);
            */
     }
     return $this->aUser;
 }
示例#12
0
文件: User.php 项目: AlvaCorp/POS-2
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see User::setDeleted()
  * @see User::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(UserTableMap::DATABASE_NAME);
     }
     $con->transaction(function () use($con) {
         $deleteQuery = ChildUserQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $this->setDeleted(true);
         }
     });
 }