summaryrefslogtreecommitdiff
path: root/importexport.go
diff options
context:
space:
mode:
Diffstat (limited to 'importexport.go')
-rw-r--r--importexport.go70
1 files changed, 68 insertions, 2 deletions
diff --git a/importexport.go b/importexport.go
index 92d028e..5dfb9f3 100644
--- a/importexport.go
+++ b/importexport.go
@@ -16,11 +16,29 @@ const (
taskfile string = "/tmp/laboravi.export.tasks"
custfile string = "/tmp/laboravi.export.customers"
projfile string = "/tmp/laboravi.export.projects"
+ billfile string = "/tmp/laboravi.export.bills"
//taskfile string = "laboravi.export.tasks"
//custfile string = "laboravi.export.customers"
//projfile string = "laboravi.export.projects"
)
+func ExportBills(in []bill) {
+ filename := billfile
+ file ,err := os.Create(filename)
+ checkErr(err)
+ defer file.Close()
+
+ w := csv.NewWriter(file)
+ defer w.Flush()
+ for _,i := range in {
+ tsks, tms, hours, mnys := items2strings(i.items)
+ //str := []string{Sint(i.Id),Sint(i.Projectid),i.Start.Format(time.RFC3339),i.Stop.Format(time.RFC3339),i.Taskname,i.Comment,Sint(i.Checkout)}
+ str := []string{Sint(i.id),i.identity,i.timerange,Sint(i.project),i.projectname,i.date.Format(timeform),i.paid.Format(timeform),tsks,tms,hours,mnys}
+ w.Write(str)
+ //w.WriteStruct(i)
+ }
+}
+
func ExportTasks(in []Task) {
filename := taskfile
file ,err := os.Create(filename)
@@ -70,6 +88,54 @@ func ExportCustomers(in []Customer) {
}
}
+// Import an array of Bills from a csv of given filename
+func ImportBills() ([]bill) {
+ filename := billfile
+ //file ,err := os.Create(filename)
+ var bll []bill
+ //w := NewReader(strings.NewReader())
+ f, _ := os.Open(filename)
+
+ // Create a new reader.
+ r := csv.NewReader(bufio.NewReader(f))
+ //err := r.ReadStructAll(&cust)
+ //checkErr(err)
+ lines, err := r.ReadAll()
+ checkErr(err)
+
+ for _, line := range lines {
+ i, err := strconv.Atoi(line[0])
+ checkErr(err)
+ ide := line[1]
+ timr := line[2]
+ pr, err := strconv.Atoi(line[3])
+ checkErr(err)
+ prn := line[4]
+ dat,err := time.Parse(timeform,line[6])
+ checkErr(err)
+ pai,err := time.Parse(timeform,line[5])
+ checkErr(err)
+ tsks := line[7]
+ dats := line[8]
+ hrs := line[9]
+ mos := line[10]
+ its := strings2items(tsks,dats,hrs,mos)
+ data := bill{
+ id: i,
+ identity: ide,
+ timerange: timr,
+ project: pr,
+ projectname: prn,
+ date: dat,
+ paid: pai,
+ items: its,
+ }
+ bll=append(bll,data)
+
+ }
+ return bll
+}
+
// Import an array of Tasks from a csv of given filename
func ImportTasks() ([]Task) {
filename := taskfile
@@ -193,7 +259,7 @@ func TarExports(filename string) {
cmd := "tar"
fln := fmt.Sprintf("/tmp/%s",filename)
//args := []string{"-cf",filename,"/tmp/laboravi.export.tasks","/tmp/laboravi.export.customers","/tmp/laboravi.export.projects"}
- args := []string{"-cf",fln,taskfile,projfile,custfile}
+ args := []string{"-cf",fln,taskfile,projfile,custfile,billfile}
if cmdOut, err = exec.Command(cmd, args...).Output(); err != nil {
//panic(err)
}
@@ -233,7 +299,7 @@ func PurgeTemps() {
)
cmd := "rm"
//args := []string{"/tmp/laboravi.export.tasks","/tmp/laboravi.export.customers","/tmp/laboravi.export.projects"}
- args := []string{taskfile,projfile,custfile}
+ args := []string{taskfile,projfile,custfile,billfile}
//args := []string{"/tmp/laboravi.export.*"}
if cmdOut, err = exec.Command(cmd, args...).Output(); err != nil {
//panic(err)