Files
BordroRobot/app/lib/srv/srv.go
2024-03-30 15:26:57 +03:00

143 lines
3.2 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()
b.Login(user)
//b.BordroYaz(data,b.page,,)
//err := b.Login()
//err := b.Login(şirket, accoun no, parola vsç..)
//şirket login bilgilerini sqlite'tan oku
//ardında BOT init et (global değişken de olmayabilir) init fonksyionu bot'u dönebilir
//bot'ta login ol
//bot'ta olması gereken veri yazma sayfasına browse et
//todo: save xls to application folder as /name/year/month.xlsx
//wails nümerik değerleri float gönderiyor.. int gönderimi araştırılmalı
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)
}
b.BordroYaz(data)
//for _, row := range rows {
// //todo: process excel and do data input
// fmt.Println(row)
// // satır satır execli oku,
//
// //yukarıda init edilen bot'ta' yazma kodunu çalıştır..
//
// bordroSatiri, err := model.NewFromExcelLine(row)
// fmt.Println(bordroSatiri, err)
// b.BordroYaz(bordroSatiri)
//
// //todo: inform user about process and errors
// emitLog(row[1])
//}
return nil
}
func emitLog(logMessage string) {
run.APP.Events.Emit(&application.WailsEvent{
Name: "logProcess",
Data: logMessage,
})
}