change login be, edit query listing mcu
This commit is contained in:
@@ -21,7 +21,7 @@ type DashboardPicServices interface {
|
||||
GetEmployeeAnalyticBreadcrumb(title string) (models.BreadCrumbV1, error)
|
||||
GetCorporateName(userID string) (string, error)
|
||||
DummyDataTest() ([]models.DashboardPic, error)
|
||||
ListingDashboardPic(search string, startdate string, enddate string, currentpage int, rowperpage int) ([]models.DashboardPic, int, error)
|
||||
ListingDashboardPic(email string, search string, startdate string, enddate string, currentpage int, rowperpage int) ([]models.DashboardPic, int, error)
|
||||
}
|
||||
|
||||
type DashboardPicHandler struct {
|
||||
@@ -45,7 +45,7 @@ func (ea *DashboardPicHandler) HandleShowEmployeeAnalyticScreen(c echo.Context)
|
||||
userID := claims["M_UserID"].(string)
|
||||
name := claims["M_StaffName"].(string)
|
||||
position := claims["M_UserGroupDashboard"].(string)
|
||||
logger.Info("jwt", zap.Any("name", name))
|
||||
email := claims["M_UserEmail"].(string)
|
||||
|
||||
title, err := ea.DashboardPicServices.GetCorporateName(userID)
|
||||
if err != nil {
|
||||
@@ -75,7 +75,7 @@ func (ea *DashboardPicHandler) HandleShowEmployeeAnalyticScreen(c echo.Context)
|
||||
sidbaruser := sidebaruserprofile.Navbaruserprofile(user)
|
||||
breadcrumb := breadcrumadmin.MainBreadcrumbAdminV1(dataBreadcrumb)
|
||||
|
||||
listingData, totalPage, err := ea.DashboardPicServices.ListingDashboardPic("", "", "", 1, 10)
|
||||
listingData, totalPage, err := ea.DashboardPicServices.ListingDashboardPic(email, "", "", "", 1, 10)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("Error get listing data", zap.Any("error", err), zap.Any("total", totalPage))
|
||||
@@ -129,6 +129,10 @@ func (ea *DashboardPicHandler) HandlePagination(c echo.Context) error {
|
||||
startdate := c.QueryParam("startdate")
|
||||
enddate := c.QueryParam("enddate")
|
||||
|
||||
userCok := c.Get("user").(*jwt.Token)
|
||||
claims := userCok.Claims.(jwt.MapClaims)
|
||||
email := claims["M_UserEmail"].(string)
|
||||
|
||||
var retVal []templ.Component
|
||||
logger, _ := zap.NewProduction()
|
||||
page, err := strconv.Atoi(pageparam)
|
||||
@@ -138,7 +142,7 @@ func (ea *DashboardPicHandler) HandlePagination(c echo.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
listdata, totalPage, err := ea.DashboardPicServices.ListingDashboardPic(search, startdate, enddate, page, 10)
|
||||
listdata, totalPage, err := ea.DashboardPicServices.ListingDashboardPic(email, search, startdate, enddate, page, 10)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("Error convert page param")
|
||||
@@ -172,7 +176,11 @@ func (ea *DashboardPicHandler) HandleFilter(c echo.Context) error {
|
||||
listID := c.QueryParam("listID")
|
||||
paginationID := c.QueryParam("paginationID")
|
||||
|
||||
dataList, totalPage, err := ea.DashboardPicServices.ListingDashboardPic(search, startdate, enddate, 1, 5)
|
||||
userCok := c.Get("user").(*jwt.Token)
|
||||
claims := userCok.Claims.(jwt.MapClaims)
|
||||
email := claims["M_UserEmail"].(string)
|
||||
|
||||
dataList, totalPage, err := ea.DashboardPicServices.ListingDashboardPic(email, search, startdate, enddate, 1, 10)
|
||||
if err != nil {
|
||||
defer logger.Sync()
|
||||
logger.Info("Error Get Listing Data", zap.Any("error", err))
|
||||
|
||||
@@ -76,21 +76,24 @@ func (ea *DashboardPicServices) GetCorporateName(userID string) (string, error)
|
||||
|
||||
q := `
|
||||
SELECT
|
||||
c.CorporateName
|
||||
FROM mgm_mcu mm
|
||||
JOIN corporate c ON c.CorporateID = mm.Mgm_McuCorporateID
|
||||
AND CorporateIsActive = 'Y'
|
||||
WHERE mm.Mgm_McuID = ?
|
||||
AND mm.Mgm_McuIsActive = 'Y'
|
||||
CorporateName
|
||||
FROM mgm_mcuuser
|
||||
JOIN mgm_mcu ON Mgm_McuID = Mgm_McuUserMgm_McuID
|
||||
JOIN corporate ON CorporateID = Mgm_McuCorporateID
|
||||
WHERE Mgm_McuUserID = ?
|
||||
`
|
||||
if err := dbx.Handlex.Get(&corpName, q, userID); err != nil {
|
||||
return "PT. ABC", err
|
||||
}
|
||||
|
||||
if corpName == "" {
|
||||
corpName = "Perusahaan A"
|
||||
}
|
||||
|
||||
return corpName, nil
|
||||
}
|
||||
|
||||
func (ea *DashboardPicServices) ListingDashboardPic(search string, startdate string, enddate string, currentpage int, rowperpage int) ([]models.DashboardPic, int, error) {
|
||||
func (ea *DashboardPicServices) ListingDashboardPic(email string, search string, startdate string, enddate string, currentpage int, rowperpage int) ([]models.DashboardPic, int, error) {
|
||||
logger, _ := zap.NewProduction()
|
||||
var ret []models.DashboardPic
|
||||
var totalData int
|
||||
@@ -104,19 +107,19 @@ func (ea *DashboardPicServices) ListingDashboardPic(search string, startdate str
|
||||
|
||||
prmLabel := "%" + search + "%"
|
||||
offset := (currentpage - 1) * rowperpage
|
||||
// q := `
|
||||
// SELECT COUNT(*)
|
||||
// FROM mgm_mcu
|
||||
// WHERE Mgm_McuIsActive = 'Y'
|
||||
// AND Mgm_McuLabel LIKE ?
|
||||
// AND Mgm_McuStartDate >= ?
|
||||
// AND Mgm_McuEndDate <= ?
|
||||
// `
|
||||
// if err := dbx.Handlex.Get(&totalData, q, prmLabel, startdate, enddate); err != nil {
|
||||
// return nil, 0, fmt.Errorf("error query get total data: %v", err)
|
||||
// }
|
||||
logger.Info("Params", zap.Any("email", email))
|
||||
q := `
|
||||
SELECT COUNT(*)
|
||||
FROM mgm_mcu
|
||||
WHERE Mgm_McuIsActive = 'Y'
|
||||
AND Mgm_McuLabel LIKE ?
|
||||
AND Mgm_McuStartDate >= ?
|
||||
AND Mgm_McuEndDate <= ?
|
||||
`
|
||||
if err := dbx.Handlex.Get(&totalData, q, prmLabel, startdate, enddate); err != nil {
|
||||
return nil, 0, fmt.Errorf("error query get total data: %v", err)
|
||||
}
|
||||
|
||||
q = `
|
||||
SELECT
|
||||
Mgm_McuID,
|
||||
Mgm_McuLabel,
|
||||
@@ -130,17 +133,20 @@ func (ea *DashboardPicServices) ListingDashboardPic(search string, startdate str
|
||||
DATE_FORMAT(Mgm_McuEndDate, '%d-%m-%Y') AS Mgm_McuEndDate,
|
||||
Mgm_McuIsActive
|
||||
FROM mgm_mcu
|
||||
WHERE Mgm_McuIsActive = 'Y'
|
||||
JOIN mgm_mcuuser ON Mgm_McuUserMgm_McuID = Mgm_McuID
|
||||
WHERE Mgm_McuUserEmail = ?
|
||||
AND Mgm_McuIsActive = 'Y'
|
||||
AND Mgm_McuLabel LIKE ?
|
||||
AND Mgm_McuStartDate >= ?
|
||||
AND Mgm_McuEndDate <= ?
|
||||
ORDER BY Mgm_McuID ASC
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
if err := dbx.Handlex.Select(&ret, q, prmLabel, startdate, enddate, rowperpage, offset); err != nil {
|
||||
if err := dbx.Handlex.Select(&ret, q, email, prmLabel, startdate, enddate, rowperpage, offset); err != nil {
|
||||
return nil, 0, fmt.Errorf("error query get data: %v", err)
|
||||
}
|
||||
logger.Info("Resp", zap.Any("Respsone", ret))
|
||||
totalData = len(ret)
|
||||
logger.Info("Response", zap.Any("data", ret), zap.Any("total data", totalData))
|
||||
|
||||
totalPage := int(math.Ceil(float64(totalData) / float64(rowperpage)))
|
||||
return ret, totalPage, nil
|
||||
|
||||
@@ -54,7 +54,7 @@ templ FilterListing(
|
||||
name="search"
|
||||
class="form-control form-control-lg bg-field border-0 rounded-lg"
|
||||
type="text"
|
||||
placeholder="nama karyawan"
|
||||
placeholder="Nama MCU"
|
||||
hx-get={ hxGet }
|
||||
hx-trigger={ hxTrigger }
|
||||
hx-include={ hxInclude }
|
||||
|
||||
@@ -221,7 +221,7 @@ func FilterListing(
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<input id=\"searchID\" name=\"search\" class=\"form-control form-control-lg bg-field border-0 rounded-lg\" type=\"text\" placeholder=\"nama karyawan\" hx-get=\"")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<input id=\"searchID\" name=\"search\" class=\"form-control form-control-lg bg-field border-0 rounded-lg\" type=\"text\" placeholder=\"Nama MCU\" hx-get=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user