Files
BordroRobot/app/lib/srv/srv.go

129 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package srv
import (
"bordrobot/lib/bot"
"bordrobot/lib/company"
"bordrobot/lib/model"
"bordrobot/lib/run"
"fmt"
"log/slog"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/xuri/excelize/v2"
)
type Srv struct {
xlsFileName string
}
func (s *Srv) Companies() ([]company.Company, error) {
var res []company.Company
err := run.DB.Select(&res, "SELECT * FROM company order by 1")
return res, err
}
func (s *Srv) CreateCompany(name, memberNumber, username, password string) error {
c := &company.Company{
Name: name,
MemberNumber: memberNumber,
Username: username,
Password: password,
}
return c.Create()
}
func (s *Srv) UploadExcel() string {
dialog := application.OpenFileDialog()
dialog.AddFilter("Excel Dosyaları", "*.xls;*.xlsx")
dialog.SetTitle("Bordro Excel Dosyası Yükleme")
file, err := dialog.PromptForSingleSelection()
if err != nil {
return ""
}
s.xlsFileName = file
return file
}
type userInfo struct {
userName string
password string
accountNo string
}
func getUser(userId string) *userInfo {
// user, ok := userDB[userId]
//
// if !ok {
// return nil
// }
info := userInfo{accountNo: "3197485", userName: "NOTİTEK01", password: "Notitek2025."}
//info := userInfo{accountNo: "3197485", userName: "NOTİTEK01", password: "sdaasd."}
return &info
}
func (s *Srv) Rpa(companyName string, month float64, year float64) error {
user, err := company.GetCompany(companyName)
if err != nil {
}
//todo: readb company details by name
b := bot.NewLucaBot()
err = b.Login(user)
if err != nil {
//todo: inform user about process and errors
emitLog("Şifreniz Hatalı")
return nil
}
slog.Debug("inputs", "year", year, "month", month)
f, err := excelize.OpenFile(s.xlsFileName)
if err != nil {
slog.Error(err.Error())
return err
}
defer func() {
// Close the spreadsheet.
if err := f.Close(); err != nil {
slog.Error(err.Error())
//return err
}
}()
sheets := f.GetSheetList()
rows, err := f.GetRows(sheets[0])
fmt.Println(rows)
if err != nil {
slog.Error(err.Error())
return err
}
if rows[0][0] == "" {
rows = rows[1:]
}
data := make([]*model.Bordro, 0) // []*Bordro türünde bir dilim oluştur
for i := 1; i < len(rows); i++ {
bordroSatiri, err := model.NewFromExcelLine(rows[i])
data = append(data, bordroSatiri)
//
fmt.Println(bordroSatiri, err)
}
err = b.BordroYaz(data, month, year)
if err != nil {
//emitLog(err.message)
return err
} else {
emitLog("işlem başarılı")
}
return nil
}
func emitLog(logMessage string) {
run.APP.Events.Emit(&application.WailsEvent{
Name: "logProcess",
Data: logMessage,
})
}