diff options
| -rw-r--r-- | config.go | 10 | ||||
| -rw-r--r-- | sqlite.go | 177 |
2 files changed, 112 insertions, 75 deletions
@@ -31,6 +31,7 @@ type Config struct { Bankname string //`toml:"bankname"` Iban string //`toml:"iban"` Bic string //`toml:"bic"` + CSign string //`toml:"csign"` Ust float64 //`toml:"ust"` } @@ -89,7 +90,7 @@ func makeNewTOML(gibts bool) { n := "" file, err := homedir.Expand("~/.mywork.db") checkErr(err) - config = Config{file, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n,0.0} + config = Config{file, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n,0.0} } //fmt.Println("Whats Your Namecount\n") database := getNewInterInput("DB File Path: ", config.Database, nli) @@ -104,6 +105,7 @@ func makeNewTOML(gibts bool) { mobile := getNewInterInput("Mobile number: ", config.Mobile, nli) mail := getNewInterInput("Email: ", config.Mail, nli) url := getNewInterInput("URL: ", config.Url, nli) + curr := getNewInterInput("CurrencySymbol: ", config.CSign, nli) taxid := getNewInterInput("Tax ID: ", config.Taxid, nli) uid := getNewInterInput("UID: ", config.Uid, nli) var ust float64 @@ -111,8 +113,8 @@ func makeNewTOML(gibts bool) { uststr := getNewInterInput("USt %: ", fmt.Sprint(config.Ust), nli) ust, err = strconv.ParseFloat(uststr, 64) if err != nil { - //fmt.Println(nli,uststr, boldRed("can not be Parsed as a Float."), "Try a sh ape of X.X") - fmt.Println(nli,uststr, "can not be Parsed as a Float.", "Try a sh ape of X.X") + //fmt.Println(nli,uststr, boldRed("can not be Parsed as a Float."), "Try a shape of X.X") + fmt.Println(nli,uststr, "can not be Parsed as a Float.", "Try a shape of X.X") } else { break } @@ -123,7 +125,7 @@ func makeNewTOML(gibts bool) { iban := getNewInterInput("IBAN: ", config.Iban, nli) bic := getNewInterInput("BIC: ", config.Bic, nli) - conf := Config{database, folder, prefix, name, street, zip, city, country, telefon, mobile, mail, url, taxid, uid, bankacc, banklz, bankname, iban, bic, ust} + conf := Config{database, folder, prefix, name, street, zip, city, country, telefon, mobile, mail, url, taxid, uid, bankacc, banklz, bankname, iban, bic, curr, ust} buf := new(bytes.Buffer) err = toml.NewEncoder(buf).Encode(conf) @@ -449,9 +449,9 @@ func showLastBills(count int) { msum := sumFloatArray(string2FloatArray(moneystr, ";")) tx := msum * ust / 100 if (ust == 0) { - fmt.Printf("%s %v:%s - %s (%v) %.1f[h]: %.2f[€] - ",nli, id, ident, prn, date.Local().Format("2006.01.02"), hsum, msum) + fmt.Printf("%s %v:%s - %s (%v) %.1f[h]: %.2f[%s] - ",nli, id, ident, prn, date.Local().Format("2006.01.02"), hsum, msum,config.CSign) }else{ - fmt.Printf("%s %v:%s - %s (%v) %.1f[h]: %.2f[€] (excl. %.2f[€] USt) - ",nli, id, ident, prn, date.Local().Format("2006.01.02"), hsum, msum, tx) + fmt.Printf("%s %v:%s - %s (%v) %.1f[h]: %.2f[%s] (excl. %.2f[%s] USt) - ",nli, id, ident, prn, date.Local().Format("2006.01.02"), hsum, msum,config.CSign, tx,config.CSign) } //p := fmt.Sprintf("%v", paid.Local().Format("2006.01.02")) //fmt.Println(p) @@ -503,7 +503,7 @@ func ShowBill(in bill,fullest bool) { fmt.Printf("%sFor: %s\n",nli,custn) fmt.Printf("%sProject: %s\n",nli,projn) fmt.Println(sub("Bill Items")) - fmt.Println(StrLines(ShowItems(in.items),nli)) + fmt.Println(StrLines(ShowItems(in.items,in.ust),nli)) if fullest { fmt.Println(sub("Billed Tasks")) fmt.Print(addText) @@ -746,19 +746,23 @@ func GetMapId(id int, idm []IdMap) (int) { fmt.Println(frame("",false)) */ -func ShowItems(itms []billitem) (out []string) { +func ShowItems(itms []billitem, ust float64) (out []string) { out = append(out, "SomeShit") //doneinfo2 := "" - sumh,summ := 0.0, 0.0 + sumh,summ,sumt := 0.0, 0.0, 0.0 cnt := 0 for _,itm := range itms { - out = append(out, fmt.Sprintf(" %s (%s) - %v(h) - %v€",itm.Task,itm.Time,itm.Hours,itm.Money)) + out = append(out, fmt.Sprintf(" %s (%s) - %v(h) - %v[%s]",itm.Task,itm.Time,itm.Hours,itm.Money,config.CSign)) sumh += itm.Hours summ += itm.Money + sumt += itm.Money*ust/100 cnt += 1 } - out[0] = fmt.Sprintf("Summary: %v Items, %v (h), %v€",cnt,sumh,summ) - + if ust>0 { + out[0] = fmt.Sprintf("Summary: %v Items, %v (h), %v[%s] (+%v tax)",cnt,sumh,summ,config.CSign,sumt) + }else{ + out[0] = fmt.Sprintf("Summary: %v Items, %v (h), %v[%s]",cnt,sumh,summ,config.CSign) + } return } @@ -1559,7 +1563,7 @@ func showProject(prj Project,cus Customer) { fmt.Println(frame(boldGreen("Project "+prj.Name),true)) fmt.Println(nli,prj.Id, ":", prj.Name, "- Started:", prj.First.Local().Format("Mon _2 Jan 2006")) fmt.Println(nli," Last Changes", prj.Last.Local().Format("2006 Mon Jan _2 15:04")) - fmt.Println(nli," For:", cus.Company,"-",cus.Name," Hourly Rate:",cus.Satz,"[€/h]") + fmt.Printf("%s For: %s - %s Hourly Rate: %.2f [%s/h]",nli, cus.Company, cus.Name, cus.Satz, config.CSign) } func showOpenProject(alone bool) { @@ -1630,33 +1634,41 @@ func AddPayment(dat string) { } mybills := loadBills(selids) sum := 0.0 + tsum := 0.0 for _,bill := range mybills { for _,it := range bill.items { sum += it.Money + tsum += it.Money*bill.ust/100 } } fmt.Println(frame(boldGreen("New Payment"),true)) - fmt.Println(nli," Amount:",amtfl,"[€]") + fmt.Println(nli," Amount:",amtfl,"["+config.CSign+"]") fmt.Println(nli," Date:",date.Format("2006-01-02")) fmt.Println(nli,"Customer:",getCustomerName(icust)) fmt.Println(sub("Invoices")) for _,bi := range mybills{ bsum := 0.0 hsum := 0.0 + txsm := 0.0 for _,it := range bi.items { bsum += it.Money hsum += it.Hours + txsm += it.Money*bi.ust/100 + } + if bi.ust > 0.0 { + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s] (+ %.2f[%s] tax)\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bsum,config.CSign,txsm,config.CSign) + }else{ + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bsum,config.CSign) } - fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bsum) } - if amtfl != sum { - fmt.Println(sli,boldRed(" The sum of the bills (",sum,"€) does not match Payment amount!")) - if amtfl > sum { - fmt.Printf("%s %.2f € Overpaid\n",nli,(amtfl-sum) ) + if amtfl != ( sum + tsum ) { + fmt.Println(sli,boldRed(" The sum of the bills (",(sum+tsum), config.CSign+") does not match Payment amount!")) + if amtfl > (sum+tsum) { + fmt.Printf("%s %.2f[%s] Overpaid\n",nli,(amtfl-sum),config.CSign) } - if amtfl < sum { - fmt.Printf("%s %.2f € Underpaid\n",nli,(amtfl-sum) ) + if amtfl < (sum+tsum) { + fmt.Printf("%s %.2f[%s] Underpaid\n",nli,(amtfl-sum),config.CSign ) } } if isInterSure(sli+"Do you want to continue?") { @@ -1927,7 +1939,7 @@ func GetPaymentList() (outint []int, outstr []string) { for _,bi := range mybills{ } */ - st := fmt.Sprintf("%v: (%s) %s : %.2f[€] - Bills: %s",id, dat.Local().Format("2006-01-02"),cun, amt,bills) + st := fmt.Sprintf("%v: (%s) %s : %.2f[%s] - Bills: %s",id, dat.Local().Format("2006-01-02"),cun, amt,config.CSign,bills) outint = append(outint, id) outstr = append(outstr, st) } @@ -1979,7 +1991,7 @@ func allCustomers(inline bool) { lstr = "Never" } if uid > 0 { - fmt.Printf("%s %v:%s: %s, Rate: %.2f[€/h] , Last Paid Bill: %s\n", nli, uid, comp, name, satz, lstr) + fmt.Printf("%s %v:%s: %s, Rate: %.2f[%s/h] , Last Paid Bill: %s\n", nli, uid, comp, name, satz,config.CSign, lstr) } } if cnt==0 { @@ -2076,7 +2088,7 @@ func DeletePayment(id int) { checkErr(err) rows.Close() //good habit to close custr := getCustomerName(cuid) - fmt.Printf("%s From %s Amount %.2f [€]\n",nli,custr,amount) + fmt.Printf("%s From %s Amount %.2f [%s]\n",nli,custr,amount,config.CSign) fmt.Printf("%s Date: %s\n",nli,date.Local().Format("2006 Mon Jan _2")) fmt.Println(sub("Bills")) biids := String2IntArray(billstr,";") @@ -2084,22 +2096,32 @@ func DeletePayment(id int) { bsum := 0.0 hsum := 0.0 + tsum := 0.0 for _,bi := range mybills{ bisum := 0.0 + hisum := 0.0 + tisum := 0.0 for _,it := range bi.items { bisum += it.Money - hsum += it.Hours + hisum += it.Hours + tisum += it.Money*bi.ust/100 + } + if bi.ust > 0 { + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s] (+ %.2f[%s] tax)\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hisum,bisum,config.CSign,tisum,config.CSign) + }else{ + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hisum,bisum,config.CSign) } - fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bsum) bsum += bisum + hsum += hisum + tsum += tisum } - if amount != bsum { - fmt.Println(sli,boldRed(" The sum of the bills (",bsum,"€ for",hsum,"h) does not match Payment amount!")) - if amount > bsum { - fmt.Printf("%s %.2f € Overpaid\n",nli,(amount-bsum) ) + if amount != (bsum+tsum) { + fmt.Println(sli,boldRed(" The sum of the bills (",bsum+tsum,config.CSign+" for",hsum,"h) does not match Payment amount!")) + if amount > (bsum+tsum) { + fmt.Printf("%s %.2f[%s] Overpaid\n",nli,(amount-bsum-tsum),config.CSign ) } - if amount < bsum { - fmt.Printf("%s %.2f € Underpaid\n",nli,(amount-bsum) ) + if amount < (bsum+tsum) { + fmt.Printf("%s %.2f[%s] Underpaid\n",nli,(amount-bsum-tsum),config.CSign ) } } if isInterSure(sli+"Are You Sure?") { @@ -2111,7 +2133,7 @@ func DeletePayment(id int) { _, err = stmt.Exec(id) checkErr(err) fmt.Println(nli,boldGreen("Payment ", id, " deleted successfully!")) - //TODO Remove Bill Paed?!? + //TODO Remove Bill Paid?!? } }else{ fmt.Println(nli,boldRed("There is no Payment "),id) @@ -2127,17 +2149,22 @@ func deleteBill(id int) { var prj int var identity, moneys, hours string var date time.Time + var ust float64 - rows, err := db.Query("SELECT project, date, identity, hours, moneys FROM bills WHERE id = $1", id) + rows, err := db.Query("SELECT project, date, identity, hours, moneys, ust FROM bills WHERE id = $1", id) checkErr(err) if rows.Next() { - err = rows.Scan(&prj, &date, &identity, &hours, &moneys) + err = rows.Scan(&prj, &date, &identity, &hours, &moneys, &ust) checkErr(err) rows.Close() //good habit to close prstr, custr := getProjectName(prj) hsum := sumFloatArray(string2FloatArray(hours, ";")) msum := sumFloatArray(string2FloatArray(moneys, ";")) - fmt.Printf("%s %v: For %v- %v (%v) - %.1f[h] : %.2f[€]\n", nli, identity, custr, prstr, date.Local().Format("2006 Mon Jan _2"), hsum, msum) + if ust > 0 { + fmt.Printf("%s %v: For %v- %v (%v) - %.1f[h] : %.2f[%s] (+ %.2f[%s] %v%% tax)\n", nli, identity, custr, prstr, date.Local().Format("2006 Mon Jan _2"), hsum, msum,config.CSign,(msum*ust/100),config.CSign,ust) + }else{ + fmt.Printf("%s %v: For %v- %v (%v) - %.1f[h] : %.2f[%s] (no tax)\n", nli, identity, custr, prstr, date.Local().Format("2006 Mon Jan _2"), hsum, msum,config.CSign) + } if isInterSure(sli+"Are You Sure?") { uncheckTasks(id) //Set corresponding Tasks to checkout=0 stmt, err := db.Prepare("DELETE FROM bills WHERE id = ?") @@ -2206,7 +2233,7 @@ func ShowPayment(id int) { rows.Close() //good habit to close //custr := getCustomerName(cuid) custr := getCustomerName(cuid) - fmt.Printf("%s From %s Amount %.2f [€]\n",nli,custr,amount) + fmt.Printf("%s From %s Amount %.2f [%s]\n",nli,custr,amount,config.CSign) fmt.Printf("%s Date: %s\n",nli,date.Local().Format("2006 Mon Jan _2")) fmt.Println(sub("Bills")) biids := String2IntArray(billstr,";") @@ -2214,22 +2241,32 @@ func ShowPayment(id int) { bsum := 0.0 hsum := 0.0 + tsum := 0.0 for _,bi := range mybills{ bisum := 0.0 + hisum := 0.0 + tisum := 0.0 for _,it := range bi.items { bisum += it.Money - hsum += it.Hours + hisum += it.Hours + tisum += it.Money*bi.ust/100 + } + if bi.ust > 0.0 { + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s] (+ %.2f[%s] tax)\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hisum,bisum,config.CSign,tisum,config.CSign) + }else{ + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hisum,bisum,config.CSign) } - fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bisum) bsum += bisum + hsum += hisum + tsum += tisum } - if amount != bsum { - fmt.Println(sli,boldRed(" The sum of the bills (",bsum,"€ for",hsum,"h) does not match Payment amount!")) - if amount > bsum { - fmt.Printf("%s %.2f € Overpaid\n",nli,(amount-bsum) ) + if amount != (bsum+tsum) { + fmt.Println(sli,boldRed(" The sum of the bills (",(bsum+tsum),config.CSign+" for",hsum,"h) does not match Payment amount!")) + if amount > (bsum+tsum) { + fmt.Printf("%s %.2f[%s] Overpaid\n",nli,(amount-bsum-tsum),config.CSign ) } - if amount < bsum { - fmt.Printf("%s %.2f € Underpaid\n",nli,(amount-bsum) ) + if amount < (bsum+tsum) { + fmt.Printf("%s %.2f[%s] Underpaid\n",nli,(amount-bsum-tsum),config.CSign ) } } } else { @@ -2307,21 +2344,30 @@ func EditPayment(id int) { //hsum := 0.0 for _,bi := range mybills{ bisum := 0.0 + hisum := 0.0 + tisum := 0.0 for _,it := range bi.items { bisum += it.Money - hsum += it.Hours + hisum += it.Hours + tisum += it.Money*bi.ust/100 + } + if bi.ust > 0.0 { + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s] (+ %.2f[%s] tax)\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hisum,bisum,config.CSign,tisum,config.CSign) + }else{ + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hisum,bisum,config.CSign) } - fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bisum) bsum += bisum + hsum += hisum + tsum += tisum } - if amount != bsum { + if amount != (bsum+tsum) { fmt.Println(sub("")) - fmt.Println(nli,boldRed(" The sum of the bills (",bsum,"€ for",hsum,"h) does not match Payment amount!")) - if amount > bsum { - fmt.Printf("%s %.2f € Overpaid\n",nli,(amount-bsum) ) + fmt.Println(nli,boldRed(" The sum of the bills (",(bsum+tsum),config.CSign+" for",hsum,"h) does not match Payment amount!")) + if amount > (bsum+tsum) { + fmt.Printf("%s %.2f[%s] Overpaid\n",nli,(amount-bsum-tsum),config.CSign ) } - if amount < bsum { - fmt.Printf("%s %.2f € Underpaid\n",nli,(amount-bsum) ) + if amount < (bsum+tsum) { + fmt.Printf("%s %.2f[%s] Underpaid\n",nli,(amount-bsum-tsum),config.CSign ) } } }else{ @@ -2368,33 +2414,34 @@ func EditPayment(id int) { mybills = loadBills(biids) fmt.Println(frame(boldGreen("Editing Payment ", id),true)) - fmt.Printf("%s From %s Amount %.2f [€]\n",nli,custr,amount) + fmt.Printf("%s From %s Amount %.2f [%s]\n",nli,custr,amount,config.CSign) fmt.Printf("%s Date: %s\n",nli,date.Local().Format("2006 Mon Jan _2")) fmt.Println(sub("Bills")) - fmt.Printf("%s %vx Sums: %.2f[€] %.2f[h]\n",nli,len(mybills),bsum,hsum) + fmt.Printf("%s %vx Sums: %.2f[%s] %.2f[h]\n",nli,len(mybills),bsum,config.CSign,hsum) hsum = 0.0 bsum = 0.0 tsum = 0.0 for _,bi := range mybills{ bisum := 0.0 + hisum := 0.0 for _,it := range bi.items { bisum += it.Money - hsum += it.Hours + hisum += it.Hours } - fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[€]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hsum,bisum) + fmt.Printf("%s %s : %s (%s) %.1f[h] %.2f[%s]\n",nli,bi.identity,bi.projectname,bi.date.Format("2006-01-02 15:04"),hisum,bisum,config.CSign) bsum += bisum tsum += bisum * bi.ust / 100 } if amount != (bsum + tsum) { fmt.Println(sub("")) - fmt.Println(nli,boldRed(" The sum of the bills (",bsum,"€ +",tsum,"€ Tax for",hsum,"h) does not match Payment amount!")) + fmt.Println(nli,boldRed(" The sum of the bills (",(bsum+tsum),config.CSign+" for",hsum,"h) does not match Payment amount!")) if amount > (bsum + tsum) { - fmt.Printf("%s %.2f € Overpaid\n",nli,(amount-bsum-tsum) ) + fmt.Printf("%s %.2f[%s] Overpaid\n",nli,(amount-bsum-tsum),config.CSign ) } if amount < (bsum + tsum) { - fmt.Printf("%s %.2f € Underpaid\n",nli,(amount-bsum-tsum) ) + fmt.Printf("%s %.2f[%s] Underpaid\n",nli,(amount-bsum-tsum),config.CSign ) } } @@ -2474,19 +2521,7 @@ func editBill(id int) { break } } - /*if paiyr == "1791-09-30" { - fmt.Println(nli,boldRed("Open")) - }else{ - for { - newpaistr := getNewInterInput("New Paid date: ", paistr, nli) - if !isDateTime(newpaistr) { - fmt.Println(nli, newpaistr, boldRed("is Not a Valid Timestring!"), "use: 'YYYY-MM-DD HH:MM'") - } else { - paistr = newpaistr - break - } - } - }*/ + for { fmt.Printf("%s !!Setting a different project id will not change the corresponding Tasks.\n%s Delete Bill to renew Task selection!!\n",nli,nli) newprj := getNewInterInput("New Project id: ", fmt.Sprint(prj), nli) @@ -2512,7 +2547,7 @@ func editBill(id int) { } fmt.Println(sli,"Current Items:") itms := strings2items(taskstr,timesstr,hoursstr,moneysstr) - fmt.Println(StrLines(ShowItems(itms),nli)) + fmt.Println(StrLines(ShowItems(itms,ust),nli)) if isInterSure(sli+"Do You Want to edit them?") { for i,_ := range itms { @@ -2528,7 +2563,7 @@ func editBill(id int) { } } for { - monstr := getNewInterInput("New Sum: ", fmt.Sprintf("%.2f €", itms[i].Money), nli) + monstr := getNewInterInput("New Sum: ", fmt.Sprintf("%.2f[%s]", itms[i].Money,config.CSign), nli) itms[i].Money, err = strconv.ParseFloat(monstr, 64) if err != nil { fmt.Println(nli,monstr, boldRed("can not be Parsed as a Float."), "Try a shape of X.X") |
