$criteria->select = 'MAX(CONVERT(SUBSTR(t.' . $fieldName . ',' . ($prefix_code_length + 1) . '),SIGNED)) as MAX_ID'; $criteria->compare("t.{$fieldName}", $prefix_code, true); $model_ = call_user_func(array($className, 'model')); $model = $model_->find($criteria); $max_id = null == $model->MAX_ID ? 0 : $model->MAX_ID; $max_id++; $addition_zero_num = $length_max_id - strlen($max_id) - strlen($prefix_code); $code = $prefix_code; for ($i = 1; $i <= $addition_zero_num; $i++) { $code .= '0'; } $code .= $max_id; return $code; } /** ANH DUNG MAR 09, 2014 @param: $date: format: 09-03-2014 15:21 @return: date format: 2014-03-09 15:21 */ public static function InvoiceDateToDbDate($date) { if (empty($date)) { return ''; } $temp = explode(' ', $date); if (count($temp) > 1) { $date = MyFormat::dateConverDmyToYmd($temp[0]); $date = $date . " {$temp['1']}"; } return $date; }