step 9 : absensi clock out, revisi clock in add jam clock in
This commit is contained in:
@@ -191,6 +191,14 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
|
||||
if isSelfie != "TRUE" {
|
||||
T_TransactionSelfiePhoto = ""
|
||||
varProsesFotoSelfie = ""
|
||||
|
||||
// setting jam absen
|
||||
currentTime := time.Now()
|
||||
jam := currentTime.Hour()
|
||||
menit := currentTime.Minute()
|
||||
detik := currentTime.Second()
|
||||
|
||||
jamClockIn = fmt.Sprintf("%02d:%02d:%02d", jam, menit, detik)
|
||||
}
|
||||
|
||||
// selfie true
|
||||
@@ -320,3 +328,194 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
|
||||
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
// fungsi untuk absen keluar clock out
|
||||
func (transabsensi *TransAbsensiResponse) ClockOutAbsensi(T_TransactionM_StaffID string, T_TransactionM_CompanyID string, T_TransactionCurrentLatitude string, T_TransactionCurrentLongitude string, T_TransactionCurrentDistance string, T_TransactionSelfiePhoto string, token string, isSelfie string) (*model.TransAbsensiResponse, error) {
|
||||
// inisialisasi
|
||||
var err error
|
||||
var ret model.TransAbsensiResponse
|
||||
var varGetToken string
|
||||
var varGetM_StaffNIP string
|
||||
var varProsesFotoSelfie string
|
||||
var jamClockOut string
|
||||
var varFileName string
|
||||
|
||||
// check user token
|
||||
qCheckTokenStaff := `SELECT
|
||||
M_StaffToken,
|
||||
LOWER(M_StaffNIP) AS M_StaffNIP
|
||||
FROM m_staff
|
||||
WHERE M_StaffIsActive = 'Y'
|
||||
AND M_StaffToken = ?
|
||||
`
|
||||
|
||||
rowCheckTokenStaff := db.Handle.QueryRow(
|
||||
qCheckTokenStaff,
|
||||
token,
|
||||
)
|
||||
db.LogSQL(qCheckTokenStaff)
|
||||
err = rowCheckTokenStaff.Scan(
|
||||
&varGetToken,
|
||||
&varGetM_StaffNIP,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error m_staff select token: %v", err)
|
||||
log.Printf("Executing query: %s\n", qCheckTokenStaff)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// check varGetToken jk M_StaffToken kosong
|
||||
if varGetToken == "" {
|
||||
log.Printf("Error Token Kosong, Silahkan Login Dulu: %v", err)
|
||||
log.Printf("Executing query: %s\n", qCheckTokenStaff)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.Status = new(string)
|
||||
ret.Message = new(string)
|
||||
|
||||
// lanjut proses absen
|
||||
if varGetToken != "" {
|
||||
|
||||
// tanpa selfie T_TransactionSelfiePhoto di set kosong
|
||||
if isSelfie != "TRUE" {
|
||||
T_TransactionSelfiePhoto = ""
|
||||
varProsesFotoSelfie = ""
|
||||
|
||||
// setting jam absen
|
||||
currentTime := time.Now()
|
||||
jam := currentTime.Hour()
|
||||
menit := currentTime.Minute()
|
||||
detik := currentTime.Second()
|
||||
|
||||
jamClockOut = fmt.Sprintf("%02d:%02d:%02d", jam, menit, detik)
|
||||
}
|
||||
|
||||
// selfie true
|
||||
if isSelfie == "TRUE" {
|
||||
|
||||
// pecah string
|
||||
strToArrayFoto := strings.Split(T_TransactionSelfiePhoto, ",")
|
||||
|
||||
// check apakah sudah sesuai apa belum
|
||||
if len(strToArrayFoto) == 0 {
|
||||
log.Printf("Eror Tidak Sesuai Format %v", err)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
// jika sesuai ambil strToArrayFoto ke 1 atau index ke 1
|
||||
if len(strToArrayFoto) > 0 {
|
||||
base64DataFoto := strToArrayFoto[1]
|
||||
T_TransactionSelfiePhoto = base64DataFoto
|
||||
}
|
||||
|
||||
currentTime := time.Now()
|
||||
|
||||
// setting jam absen
|
||||
jam := currentTime.Hour()
|
||||
menit := currentTime.Minute()
|
||||
detik := currentTime.Second()
|
||||
|
||||
jamClockOut = fmt.Sprintf("%02d:%02d:%02d", jam, menit, detik)
|
||||
|
||||
formattedTime := currentTime.Format("2006-01-02_15_04_05")
|
||||
// buat nama file
|
||||
varProsesFotoSelfie = "clockout_" + varGetM_StaffNIP + "_" + formattedTime
|
||||
strPhoto := varProsesFotoSelfie + ".jpg"
|
||||
|
||||
// folder upload file nya selfie_attachment akan otomatis sesuai bulan dan tahun
|
||||
folderName := currentTime.Format("200601")
|
||||
folder := "selfie_attachment/" + folderName + "/"
|
||||
photoPath := config.Data.Get("document") + folder
|
||||
|
||||
log.Printf("documentPath: %s", photoPath)
|
||||
|
||||
// create folder selfie_attachment jika belum ada
|
||||
if _, err := os.Stat(photoPath); errors.Is(err, os.ErrNotExist) {
|
||||
err = os.MkdirAll(photoPath, os.ModePerm.Perm())
|
||||
if err != nil {
|
||||
log.Printf("here %v", err)
|
||||
return &ret, err
|
||||
}
|
||||
}
|
||||
|
||||
photoPath = photoPath + strPhoto
|
||||
|
||||
// proses decode
|
||||
decodedByte, err := base64.StdEncoding.DecodeString(T_TransactionSelfiePhoto)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("here %v", err)
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
fs, err := os.Create(photoPath)
|
||||
if err != nil {
|
||||
log.Printf("here %v", err)
|
||||
return &ret, err
|
||||
}
|
||||
defer fs.Close()
|
||||
fs.Write(decodedByte)
|
||||
fs.Sync()
|
||||
|
||||
varProsesFotoSelfie = "selfie_attachment/" + folderName + "/" + strPhoto
|
||||
varFileName = strPhoto
|
||||
}
|
||||
|
||||
qInsertClockIn := `INSERT INTO t_transaction (
|
||||
T_TransactionM_AbsensiTypeID,
|
||||
T_TransactionM_StaffID,
|
||||
T_TransactionM_CompanyID,
|
||||
T_TransactionClockAbsensi,
|
||||
T_TransactionDate,
|
||||
T_TransactionCurrentLatitude,
|
||||
T_TransactionCurrentLongitude,
|
||||
T_TransactionCurrentDistance,
|
||||
T_TransactionFileName,
|
||||
T_TransactionSelfiePhotoPath,
|
||||
T_TransactionIsActive,
|
||||
T_TransactionCreated
|
||||
) VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW(),
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
NOW()
|
||||
)`
|
||||
|
||||
_, err = db.Handle.Exec(qInsertClockIn,
|
||||
"2",
|
||||
T_TransactionM_StaffID,
|
||||
T_TransactionM_CompanyID,
|
||||
&jamClockOut,
|
||||
T_TransactionCurrentLatitude,
|
||||
T_TransactionCurrentLongitude,
|
||||
T_TransactionCurrentDistance,
|
||||
&varFileName,
|
||||
&varProsesFotoSelfie,
|
||||
"Y",
|
||||
)
|
||||
|
||||
// set status jika tidak error
|
||||
if err == nil {
|
||||
*ret.Status = "OK"
|
||||
*ret.Message = "Proses Absensi Pulang Berhasil"
|
||||
}
|
||||
|
||||
// set status jika error
|
||||
if err != nil {
|
||||
*ret.Status = "ERR"
|
||||
*ret.Message = "ERROR : " + err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
return &ret, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user