|
@@ -20,7 +20,13 @@ type SupplyOrderApiController struct {
|
20
|
20
|
|
21
|
21
|
func SupplyOrderApiRegistRouters() {
|
22
|
22
|
|
23
|
|
- //初始化商品数据
|
|
23
|
+ //删除供应商及联系人
|
|
24
|
+ beego.Router("/api/supply/delsupply", &SupplyOrderApiController{}, "post:DelSupply")
|
|
25
|
+ //获取供应商编码
|
|
26
|
+ beego.Router("/api/supply/getsupplycode", &SupplyOrderApiController{}, "get:GetSupplyCode")
|
|
27
|
+ //保存供应商及联系人
|
|
28
|
+ beego.Router("/api/supply/savesupply", &SupplyOrderApiController{}, "post:SaveSupply")
|
|
29
|
+
|
24
|
30
|
beego.Router("/api/supply/getinitorder", &SupplyOrderApiController{}, "get:GetInitOrder")
|
25
|
31
|
//保存购货订单
|
26
|
32
|
beego.Router("/api/supply/savepurchaseorder", &SupplyOrderApiController{}, "post:SavePurchaseOrder")
|
|
@@ -54,6 +60,120 @@ func SupplyOrderApiRegistRouters() {
|
54
|
60
|
beego.Router("/api/supply/getreturnorder", &SupplyOrderApiController{}, "Get:GetReturnOrder")
|
55
|
61
|
}
|
56
|
62
|
|
|
63
|
+//删除供应商及联系人
|
|
64
|
+func (this *SupplyOrderApiController) DelSupply() {
|
|
65
|
+ //拿到供应商的id
|
|
66
|
+ suid, _ := this.GetInt64("id")
|
|
67
|
+ if suid == 0 {
|
|
68
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
|
|
69
|
+ return
|
|
70
|
+ }
|
|
71
|
+ supply := models.SpSupplierName{
|
|
72
|
+ ID: suid,
|
|
73
|
+ }
|
|
74
|
+ err := service.DelSupply(supply)
|
|
75
|
+ if err != nil {
|
|
76
|
+ utils.ErrorLog(err.Error())
|
|
77
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
78
|
+ return
|
|
79
|
+ }
|
|
80
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
81
|
+ "list": "删除成功",
|
|
82
|
+ })
|
|
83
|
+ return
|
|
84
|
+}
|
|
85
|
+
|
|
86
|
+//获取供应商编码
|
|
87
|
+func (this *SupplyOrderApiController) GetSupplyCode() {
|
|
88
|
+ supply, err := service.GetSuppliyCode()
|
|
89
|
+ if err != nil {
|
|
90
|
+ return
|
|
91
|
+ }
|
|
92
|
+ if len(supply) == 0 { //如果数据库中没有gys类型的编码则设置默认值
|
|
93
|
+ //supply[0].SupplierCode ="gys001"
|
|
94
|
+ supply = []*models.SpSupplierName{
|
|
95
|
+ {
|
|
96
|
+ SupplierCode: "gys001",
|
|
97
|
+ },
|
|
98
|
+ }
|
|
99
|
+ } else { //获取数据库中最大的编码值,并加一
|
|
100
|
+ tmp := supply[0].SupplierCode
|
|
101
|
+ tmp = tmp[3:]
|
|
102
|
+ var code int
|
|
103
|
+ code, err = strconv.Atoi(tmp)
|
|
104
|
+ code++
|
|
105
|
+ tmp = strconv.Itoa(code)
|
|
106
|
+ for len(tmp) < 3 {
|
|
107
|
+ tmp = "0" + tmp
|
|
108
|
+ }
|
|
109
|
+ tmp = "gys" + tmp
|
|
110
|
+ supply[0].SupplierCode = tmp
|
|
111
|
+ }
|
|
112
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
113
|
+ "supplycode": supply,
|
|
114
|
+ })
|
|
115
|
+ return
|
|
116
|
+}
|
|
117
|
+
|
|
118
|
+//保存供应商
|
|
119
|
+func (this *SupplyOrderApiController) SaveSupply() {
|
|
120
|
+ supplierName := this.GetString("suppliername") //供应商名称
|
|
121
|
+ if supplierName == "" {
|
|
122
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
|
|
123
|
+ return
|
|
124
|
+ }
|
|
125
|
+ //判断供应商名称是否有重复的
|
|
126
|
+ sbool, _ := service.FindSupplierName(supplierName)
|
|
127
|
+ if sbool { //有重复的
|
|
128
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
|
|
129
|
+ return
|
|
130
|
+ }
|
|
131
|
+ supplierCode := this.GetString("suppliercode") //供应商编码
|
|
132
|
+ if supplierCode == "" {
|
|
133
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号不能为空")
|
|
134
|
+ return
|
|
135
|
+ }
|
|
136
|
+ supplierType, _ := this.GetInt64("suppliertype") //供应商类别
|
|
137
|
+ vatRate, _ := this.GetFloat("vatrate") //增值税税率
|
|
138
|
+ number := this.GetString("number") //纳税人识别号
|
|
139
|
+ bank := this.GetString("bank") //开户银行
|
|
140
|
+ bankAccount := this.GetString("bankAccount") //银行账号
|
|
141
|
+ orgId := this.GetAdminUserInfo().CurrentOrgId
|
|
142
|
+ //contacts := this.Get("contacts")//联系人
|
|
143
|
+ dataBody := make(map[string]interface{}, 0)
|
|
144
|
+ err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
|
145
|
+ if err != nil {
|
|
146
|
+ utils.ErrorLog(err.Error())
|
|
147
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
148
|
+ return
|
|
149
|
+ }
|
|
150
|
+ //保存联系人
|
|
151
|
+ if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
|
|
152
|
+ thisStockIn, _ := dataBody["contacts"].([]interface{})
|
|
153
|
+ if len(thisStockIn) > 0 {
|
|
154
|
+ if len(thisStockIn) == 1 {
|
|
155
|
+ for _, item := range thisStockIn {
|
|
156
|
+ items := item.(map[string]interface{})
|
|
157
|
+ items["IsFirst"] = 1
|
|
158
|
+ }
|
|
159
|
+ }
|
|
160
|
+ tcreater := this.GetAdminUserInfo().AdminUser.Id
|
|
161
|
+ err = service.SaveSupplyAndContact(thisStockIn, orgId, supplierType, tcreater, supplierCode, supplierName, number, bank, bankAccount, vatRate)
|
|
162
|
+ if err != nil {
|
|
163
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
164
|
+ return
|
|
165
|
+ }
|
|
166
|
+ } else {
|
|
167
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
|
|
168
|
+ return
|
|
169
|
+ }
|
|
170
|
+ }
|
|
171
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
172
|
+ "list": "保存成功",
|
|
173
|
+ })
|
|
174
|
+ return
|
|
175
|
+}
|
|
176
|
+
|
57
|
177
|
func (this *SupplyOrderApiController) GetInitOrder() {
|
58
|
178
|
|
59
|
179
|
orgId := this.GetAdminUserInfo().CurrentOrgId
|