forked from hem-shrestha/SimpleBillingProjectinGolang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleBillingDemo.go
195 lines (181 loc) · 4.65 KB
/
SimpleBillingDemo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package main
import (
"bufio"
"encoding/csv"
"fmt"
"os"
"strconv"
"strings"
"time"
)
var count int = 1
var discount int = 0
var total int = 0
var asum int = 0
var servicecharge int = 0
var grand int = 0
var tax int = 0
var netTotal int = 0
type Coffee struct {
id int
itemName string
price int
}
func atoi(s string) int {
i, _ := strconv.Atoi(s)
return i
}
var iid int
var qun int
var status int
func controlunit() {
f, err := os.Open("coffeemenu.csv")
if err != nil {
panic(err)
}
reader := csv.NewReader(f)
records, err := reader.ReadAll()
if err != nil {
panic(err)
}
var coffee []Coffee
for _, record := range records {
coffee = append(coffee, Coffee{
id: atoi(record[0]),
itemName: record[1],
price: atoi(record[2]),
})
}
file, err := os.Create("store.csv")
if err != nil {
panic(err)
}
for true {
fmt.Println("Enter Item ID : ")
fmt.Scanln(&iid)
fmt.Println("Enter orderd quantity : ")
fmt.Scanln(&qun)
if iid >= 1 && iid <= 72 {
file.WriteString(coffee[iid].itemName)
file.WriteString(",")
file.WriteString(strconv.Itoa(coffee[iid].price))
file.WriteString(",")
file.WriteString(strconv.Itoa(qun))
file.WriteString("\n")
}
fmt.Println("If item is finished Enter '0' ")
fmt.Scanln(&status)
if status == 0 {
file.Close()
break
}
}
}
func calculation() {
f, err := os.Open("store.csv")
if err != nil {
panic(err)
}
reader := csv.NewReader(f)
records, err := reader.ReadAll()
if err != nil {
panic(err)
}
var coffee []Coffee
for _, record := range records {
coffee = append(coffee, Coffee{
id: atoi(record[0]),
itemName: record[1],
price: atoi(record[2]),
})
}
}
func calculationAndSimpleFormat() {
f, err := os.Open("store.csv")
if err != nil {
panic(err)
}
file, er := os.Create("DemoBill.txt")
if er != nil {
panic(er)
}
var sum int = 0
currentTime := time.Now()
scanner := bufio.NewScanner(f)
file.WriteString("----------------------------------------------------------")
file.WriteString(" Demo Cafe \n")
file.WriteString(" Kathmandu ")
file.WriteString("\n")
file.WriteString("-----------------------------------------------\n")
file.WriteString(" Invoice \t\t\tDate ")
file.WriteString(currentTime.Format("01-02-2006"))
file.WriteString("\n-----------------------------------------------\n")
file.WriteString("Invoic Number:\n")
file.WriteString("101")
file.WriteString("\n")
file.WriteString("-----------------------------------------------------\n")
file.WriteString("S.N.\t Particular \t Price \tQunatity\tTotal\n")
file.WriteString("-----------------------------------------------------\n")
for scanner.Scan() {
line := scanner.Text()
items := strings.Split(line, ",")
price, _ := strconv.Atoi(items[1])
quntity, _ := strconv.Atoi(items[2])
total = (price * quntity)
sum += total
file.WriteString(strconv.Itoa(count))
file.WriteString(" ")
file.WriteString(items[0])
file.WriteString("\t")
file.WriteString(items[1])
file.WriteString("\t")
file.WriteString(items[2])
file.WriteString(" ")
file.WriteString(strconv.Itoa(total))
file.WriteString("\n")
count++
}
label:
fmt.Println("\nWhat Discount % Available For This Bill? : : ")
fmt.Scanln(&discount)
if discount >= 0 && discount <= 30 {
discount = (sum * discount) / 100
} else {
fmt.Println("Enter valid Discount Percentage between 0 to 30 percentage")
goto label
}
asum = (sum - discount)
servicecharge = (asum * 10) / 100 //service charg
grand = asum + servicecharge //afterservice charge Total
tax = ((grand) * 13) / 100 //For tax
netTotal = asum + tax + servicecharge
file.WriteString("-----------------------------------------------------\n")
file.WriteString("\t\t\tTotal ")
file.WriteString(strconv.Itoa(sum))
file.WriteString("\n")
file.WriteString("\t\t\tDiscount\t ")
file.WriteString(strconv.Itoa(discount))
file.WriteString("\n")
file.WriteString("\t\tService Charge\t")
file.WriteString(strconv.Itoa(servicecharge))
file.WriteString("\n")
file.WriteString("\t\tGrand Total ")
file.WriteString(strconv.Itoa(grand))
file.WriteString("\n")
file.WriteString("\t\tTAX\t ")
file.WriteString(strconv.Itoa(tax))
file.WriteString("\n")
file.WriteString("\t\tNet Amount\t")
file.WriteString(strconv.Itoa(netTotal))
file.WriteString("\n-----------------------------------------------------\n")
file.WriteString("\t\t\tCashier\n")
file.WriteString("\t\t Name of Cashier")
fmt.Println("Bill created successfully")
//
fmt.Println("Bill is ready in 'DemoBill.txt' File")
fmt.Println("Thank you")
}
func main() {
controlunit()
calculationAndSimpleFormat()
}