コード例 #1
0
ファイル: User.php プロジェクト: afiqiqmal/Web
 public function generateid($usertype = null)
 {
     if ($usertype === 'employee') {
         do {
             $genid = Date('Y') . str_pad(Crytion::randnum(6), 6, '0', STR_PAD_LEFT);
             $user = $this->_db->query("Select user_id from tbl_employee where user_id=?", array($genid));
             $count = $user->count();
         } while ($count !== 0);
         return $genid;
     } else {
         if ($usertype === 'customer') {
             $user = $this->_db->query("Select cust_id from tbl_cust Order by cust_id desc limit 1");
             if (!$user->error()) {
                 if ($user->count() == 0) {
                     return Date('Y') . "0000000001";
                 } else {
                     $num = substr($user->result()->cust_id, 4) + 1;
                     $genid = str_pad($num, 10, '0', STR_PAD_LEFT);
                     return Date('Y') . $genid;
                 }
             }
         } else {
             if ($usertype === 'supplier') {
                 $supplier = $this->_db->query("Select supplier_id from tbl_supplier Order by supplier_id desc limit 1");
                 if (!$user->error()) {
                     if ($user->count() == 0) {
                         return "S01";
                     } else {
                         $num = substr($user->result()->cust_id, 1) + 1;
                         $genid = str_pad($num, 2, '0', STR_PAD_RIGHT);
                         return "S" . $genid;
                     }
                 }
             }
         }
     }
     return false;
 }