summaryrefslogtreecommitdiff
path: root/importexport.go
diff options
context:
space:
mode:
Diffstat (limited to 'importexport.go')
-rw-r--r--importexport.go60
1 files changed, 57 insertions, 3 deletions
diff --git a/importexport.go b/importexport.go
index 5dfb9f3..dde6026 100644
--- a/importexport.go
+++ b/importexport.go
@@ -17,11 +17,27 @@ const (
custfile string = "/tmp/laboravi.export.customers"
projfile string = "/tmp/laboravi.export.projects"
billfile string = "/tmp/laboravi.export.bills"
+ payfile string = "/tmp/laboravi.export.payments"
//taskfile string = "laboravi.export.tasks"
//custfile string = "laboravi.export.customers"
//projfile string = "laboravi.export.projects"
)
+func ExportPayments(in []Payment) {
+ filename := payfile
+ file ,err := os.Create(filename)
+ checkErr(err)
+ defer file.Close()
+
+ w := csv.NewWriter(file)
+ defer w.Flush()
+ for _,i := range in {
+ str := []string{Sint(i.Id),Sint(i.Customerid),Sflo(i.Amount),i.Date.Format(timeform),IntArray2String(i.Billids,";")}
+ w.Write(str)
+ //w.WriteStruct(i)
+ }
+}
+
func ExportBills(in []bill) {
filename := billfile
file ,err := os.Create(filename)
@@ -33,7 +49,7 @@ func ExportBills(in []bill) {
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}
+ 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,Sint(i.paymentid)}
w.Write(str)
//w.WriteStruct(i)
}
@@ -88,6 +104,40 @@ func ExportCustomers(in []Customer) {
}
}
+func ImportPayments() (pay []Payment) {
+ filename := payfile
+
+ f, _ := os.Open(filename)
+
+ // Create a new reader.
+ r := csv.NewReader(bufio.NewReader(f))
+ lines, err := r.ReadAll()
+ checkErr(err)
+
+ for _, line := range lines {
+ i, err := strconv.Atoi(line[0])
+ checkErr(err)
+ icu, err := strconv.Atoi(line[1])
+ checkErr(err)
+ amt,err := strconv.ParseFloat(line[2],64)
+ checkErr(err)
+ dat,err := time.Parse(timeform,line[3])
+ checkErr(err)
+ billi := String2IntArray(line[4],";")
+
+ data := Payment{
+ Id: i,
+ Customerid: icu,
+ Amount: amt,
+ Date: dat,
+ Billids: billi,
+ }
+ pay=append(pay,data)
+ }
+ return
+}
+
+
// Import an array of Bills from a csv of given filename
func ImportBills() ([]bill) {
filename := billfile
@@ -119,6 +169,9 @@ func ImportBills() ([]bill) {
dats := line[8]
hrs := line[9]
mos := line[10]
+ pid, err := strconv.Atoi(line[11])
+ checkErr(err)
+
its := strings2items(tsks,dats,hrs,mos)
data := bill{
id: i,
@@ -129,6 +182,7 @@ func ImportBills() ([]bill) {
date: dat,
paid: pai,
items: its,
+ paymentid: pid,
}
bll=append(bll,data)
@@ -259,7 +313,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,billfile}
+ args := []string{"-cf",fln,taskfile,projfile,custfile,billfile,payfile}
if cmdOut, err = exec.Command(cmd, args...).Output(); err != nil {
//panic(err)
}
@@ -299,7 +353,7 @@ func PurgeTemps() {
)
cmd := "rm"
//args := []string{"/tmp/laboravi.export.tasks","/tmp/laboravi.export.customers","/tmp/laboravi.export.projects"}
- args := []string{taskfile,projfile,custfile,billfile}
+ args := []string{taskfile,projfile,custfile,billfile,payfile}
//args := []string{"/tmp/laboravi.export.*"}
if cmdOut, err = exec.Command(cmd, args...).Output(); err != nil {
//panic(err)