Contract.go 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. package controllers
  2. import (
  3. "ERP_storage/Nats"
  4. "ERP_storage/Nats/NatsServer"
  5. "ERP_storage/conf"
  6. "ERP_storage/logs"
  7. "ERP_storage/models/Account"
  8. "ERP_storage/models/Basic"
  9. "ERP_storage/models/Contract"
  10. "ERP_storage/models/Stock"
  11. "fmt"
  12. "github.com/beego/beego/v2/adapter/orm"
  13. beego "github.com/beego/beego/v2/server/web"
  14. "github.com/robfig/cron/v3"
  15. "github.com/xuri/excelize/v2"
  16. natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats"
  17. userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
  18. "gogs.baozhida.cn/zoie/ERP_libs/lib"
  19. "math"
  20. "net/url"
  21. "os"
  22. "strconv"
  23. "strings"
  24. "time"
  25. )
  26. type ContractController struct {
  27. beego.Controller
  28. User userlibs.User
  29. }
  30. func (c *ContractController) Prepare() {
  31. c.User = *Account.User_r
  32. }
  33. func (c *ContractController) Contract_GenT_number() {
  34. o := orm.NewOrm()
  35. ContractDao := Contract.NewContract(o)
  36. T_number := ""
  37. rand_x := 1
  38. for true {
  39. T_number = fmt.Sprintf("GZBZD-%s%03d", time.Now().Format("20060102"), rand_x)
  40. _, err := ContractDao.Read_Contract_ByT_number(T_number)
  41. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  42. break
  43. }
  44. rand_x += 1
  45. }
  46. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  47. c.ServeJSON()
  48. return
  49. }
  50. func (c *ContractController) Contract_List() {
  51. // 分页参数 初始化
  52. page, _ := c.GetInt("page")
  53. if page < 1 {
  54. page = 1
  55. }
  56. page_z, _ := c.GetInt("page_z")
  57. if page_z < 1 {
  58. page_z = conf.Page_size
  59. }
  60. // 查询
  61. T_name := c.GetString("T_name")
  62. T_state, _ := c.GetInt("T_state")
  63. userList, _ := NatsServer.Read_User_List_All()
  64. Account.Read_User_All_Map(userList)
  65. ContractDao := Contract.NewContract(orm.NewOrm())
  66. R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, T_state, 0, page, page_z)
  67. var r_jsons lib.R_JSONS
  68. r_jsons.Num = R_cnt
  69. r_jsons.Data = R_List
  70. r_jsons.Page = page
  71. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  72. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  73. c.ServeJSON()
  74. return
  75. }
  76. func (c *ContractController) Contract_User_List() {
  77. // 分页参数 初始化
  78. page, _ := c.GetInt("page")
  79. if page < 1 {
  80. page = 1
  81. }
  82. page_z, _ := c.GetInt("page_z")
  83. if page_z < 1 {
  84. page_z = conf.Page_size
  85. }
  86. // 查询
  87. T_name := c.GetString("T_name")
  88. T_state, _ := c.GetInt("T_state")
  89. userList, _ := NatsServer.Read_User_List_All()
  90. Account.Read_User_All_Map(userList)
  91. ContractDao := Contract.NewContract(orm.NewOrm())
  92. R_List, R_cnt := ContractDao.Read_Contract_List(c.User.T_uuid, T_name, T_state, 0, page, page_z)
  93. var r_jsons lib.R_JSONS
  94. r_jsons.Num = R_cnt
  95. r_jsons.Data = R_List
  96. r_jsons.Page = page
  97. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  98. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  99. c.ServeJSON()
  100. return
  101. }
  102. func (c *ContractController) Contract_Get() {
  103. // 查询
  104. T_number := c.GetString("T_number")
  105. o := orm.NewOrm()
  106. ContractDao := Contract.NewContract(o)
  107. DeviceDao := Stock.NewDevice(o)
  108. ContractProductDao := Contract.NewContractProduct(o)
  109. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  110. if err != nil {
  111. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  112. c.ServeJSON()
  113. return
  114. }
  115. productList := ContractProductDao.Read_ContractProduct_List(contract.T_number)
  116. var pList []Contract.ContractProduct_R
  117. for _, v := range productList {
  118. p := Contract.ContractProductToContractProduct_R(v)
  119. p.T_device_list, _ = DeviceDao.Read_DeviceSn_List(T_number, v.T_product_id, "", "")
  120. pList = append(pList, p)
  121. }
  122. userList, _ := NatsServer.Read_User_List_All()
  123. Account.Read_User_All_Map(userList)
  124. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Contract.ContractToContract_Detail(contract, pList)}
  125. c.ServeJSON()
  126. return
  127. }
  128. func (c *ContractController) Contract_Add() {
  129. T_number := c.GetString("T_number")
  130. T_customer := c.GetString("T_customer")
  131. T_money, _ := c.GetFloat("T_money") // 总价
  132. T_discount, _ := c.GetFloat("T_discount") // 优惠价
  133. T_date := c.GetString("T_date")
  134. T_product := c.GetString("T_product")
  135. T_remark := c.GetString("T_remark")
  136. T_pdf := c.GetString("T_pdf")
  137. T_project := c.GetString("T_project")
  138. T_recoveries := c.GetString("T_recoveries")
  139. T_invoice := c.GetString("T_invoice")
  140. T_submit := c.GetString("T_submit")
  141. if len(T_submit) == 0 {
  142. T_submit = c.User.T_uuid
  143. }
  144. var_ := Contract.Contract{
  145. T_number: T_number,
  146. T_customer: T_customer,
  147. T_money: float32(T_money),
  148. T_discount: float32(T_discount),
  149. T_project: T_project,
  150. T_type: 1, //合同类型 1-销售合同 2-验证合同
  151. T_date: T_date,
  152. T_out: 1,
  153. T_State: 3,
  154. T_remark: T_remark,
  155. T_pdf: T_pdf,
  156. T_submit: T_submit,
  157. T_recoveries: T_recoveries,
  158. T_invoice: T_invoice,
  159. }
  160. _, var_.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  161. _, var_.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  162. o := orm.NewOrm()
  163. o.Begin()
  164. ContractDao := Contract.NewContract(o)
  165. ContractProductDao := Contract.NewContractProduct(o)
  166. _, err := ContractDao.Read_Contract_ByT_number(T_number)
  167. if err == nil {
  168. o.Rollback()
  169. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同编号重复!"}
  170. c.ServeJSON()
  171. return
  172. }
  173. _, err = ContractDao.Add_Contract(var_)
  174. if err != nil {
  175. o.Rollback()
  176. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  177. c.ServeJSON()
  178. return
  179. }
  180. if len(T_product) == 0 {
  181. o.Rollback()
  182. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同产品明细不能为空"}
  183. c.ServeJSON()
  184. return
  185. }
  186. productList := lib.SplitString(T_product, "|")
  187. for _, v := range productList {
  188. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  189. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  190. contractProduct := Contract.ContractProduct{
  191. T_contract_number: T_number,
  192. T_product_id: product_id,
  193. T_product_total: num,
  194. T_product_out: 0, // 已出库数量
  195. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  196. }
  197. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  198. if err != nil {
  199. o.Rollback()
  200. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  201. c.ServeJSON()
  202. return
  203. }
  204. }
  205. o.Commit()
  206. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "添加", var_)
  207. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  208. c.ServeJSON()
  209. return
  210. }
  211. func (c *ContractController) Contract_Approval() {
  212. T_number := c.GetString("T_number")
  213. T_state, _ := c.GetInt("T_state")
  214. o := orm.NewOrm()
  215. ContractDao := Contract.NewContract(o)
  216. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  217. if err != nil {
  218. o.Rollback()
  219. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  220. c.ServeJSON()
  221. return
  222. }
  223. // 1-已通过 2-未通过
  224. contract.T_State = T_state
  225. contract.T_approver = c.User.T_uuid
  226. err = ContractDao.Update_Contract(contract, "T_State", "T_approver")
  227. if err != nil {
  228. o.Rollback()
  229. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  230. c.ServeJSON()
  231. return
  232. }
  233. if T_state == 1 {
  234. NatsServer.AddNews(contract.T_submit, fmt.Sprintf("【合同审核】您提交的合同(%s)审核已通过", T_number), conf.ContractApprovalUrl)
  235. }
  236. if T_state == 2 {
  237. NatsServer.AddNews(contract.T_submit, fmt.Sprintf("【合同审核】您提交的合同(%s)审核未通过", T_number), conf.ContractApprovalUrl)
  238. }
  239. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "审核", contract)
  240. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  241. c.ServeJSON()
  242. return
  243. }
  244. func (c *ContractController) Contract_Edit() {
  245. T_number := c.GetString("T_number")
  246. T_customer := c.GetString("T_customer")
  247. T_money, _ := c.GetFloat("T_money")
  248. T_discount, _ := c.GetFloat("T_discount") // 优惠价
  249. T_date := c.GetString("T_date")
  250. T_product := c.GetString("T_product")
  251. T_remark := c.GetString("T_remark")
  252. T_pdf := c.GetString("T_pdf")
  253. T_project := c.GetString("T_project")
  254. T_recoveries := c.GetString("T_recoveries")
  255. T_invoice := c.GetString("T_invoice")
  256. T_submit := c.GetString("T_submit")
  257. o := orm.NewOrm()
  258. o.Begin()
  259. ContractDao := Contract.NewContract(o)
  260. ContractProductDao := Contract.NewContractProduct(o)
  261. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  262. if err != nil {
  263. o.Rollback()
  264. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  265. c.ServeJSON()
  266. return
  267. }
  268. if len(T_customer) > 0 {
  269. contract.T_customer = T_customer
  270. }
  271. if T_money > 0 {
  272. contract.T_money = float32(T_money)
  273. }
  274. if T_discount > 0 {
  275. contract.T_discount = float32(T_discount)
  276. }
  277. if len(T_date) > 0 {
  278. contract.T_date = T_date
  279. }
  280. if len(T_remark) > 0 {
  281. contract.T_remark = T_remark
  282. }
  283. if len(T_pdf) > 0 {
  284. contract.T_pdf = T_pdf
  285. }
  286. if len(T_project) > 0 {
  287. contract.T_project = T_project
  288. }
  289. if len(T_recoveries) > 0 {
  290. contract.T_recoveries = T_recoveries
  291. _, contract.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  292. }
  293. if len(T_invoice) > 0 {
  294. contract.T_invoice = T_invoice
  295. _, contract.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  296. }
  297. if len(T_submit) > 0 {
  298. contract.T_submit = T_submit
  299. }
  300. //1-已通过 2-未通过 3-待审核 合同状态为未通过,修改之后将状态更改为待审核
  301. if contract.T_State == 2 {
  302. contract.T_State = 3
  303. }
  304. err = ContractDao.Update_Contract(contract, "T_customer", "T_money", "T_discount", "T_date", "T_remark", "T_pdf", "T_State",
  305. "T_project", "T_recoveries", "T_recoveries_money", "T_invoice", "T_invoice_money", "T_submit")
  306. if err != nil {
  307. o.Rollback()
  308. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  309. c.ServeJSON()
  310. return
  311. }
  312. if len(T_product) == 0 {
  313. o.Rollback()
  314. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同产品明细不能为空"}
  315. c.ServeJSON()
  316. return
  317. }
  318. productList := lib.SplitString(T_product, "|")
  319. cpl, _ := ContractProductDao.Read_ContractProductList_ByT_number(T_number)
  320. needToDeleteList, allList := Check_NeedToDelete_Product_List(productList, cpl)
  321. // 检查编辑时需要修改的产品
  322. for k, v := range needToDeleteList {
  323. id, _ := strconv.Atoi(strings.Split(k, "-")[0])
  324. productId, _ := strconv.Atoi(strings.Split(k, "-")[1])
  325. if v > 0 {
  326. o.Rollback()
  327. product, _ := Basic.Read_Product_ById(productId)
  328. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s已(部分)出库,禁止删除!", product.T_name)}
  329. c.ServeJSON()
  330. return
  331. }
  332. cp := Contract.ContractProduct{Id: id}
  333. err = ContractProductDao.Delete_ContractProduct(cp)
  334. if err != nil {
  335. o.Rollback()
  336. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  337. c.ServeJSON()
  338. return
  339. }
  340. }
  341. for _, v := range productList {
  342. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  343. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  344. oldContractProduct, ok := allList[product_id]
  345. if !ok {
  346. contractProduct := Contract.ContractProduct{
  347. T_contract_number: T_number,
  348. T_product_id: product_id,
  349. T_product_total: num,
  350. T_product_out: 0, // 已出库数量
  351. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  352. }
  353. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  354. if err != nil {
  355. o.Rollback()
  356. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  357. c.ServeJSON()
  358. return
  359. } else {
  360. continue
  361. }
  362. }
  363. // 修改产品总数量
  364. contractProductId, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[0])
  365. oldNum, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[1])
  366. if oldNum == num {
  367. continue
  368. }
  369. cp := Contract.ContractProduct{Id: contractProductId, T_product_total: num}
  370. err = ContractProductDao.Update_ContractProduct(cp, "T_product_total")
  371. if err != nil {
  372. o.Rollback()
  373. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  374. c.ServeJSON()
  375. return
  376. }
  377. }
  378. o.Commit()
  379. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "修改", contract)
  380. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  381. c.ServeJSON()
  382. return
  383. }
  384. func (c *ContractController) Contract_Del() {
  385. T_number := c.GetString("T_number")
  386. o := orm.NewOrm()
  387. o.Begin()
  388. ContractDao := Contract.NewContract(o)
  389. ContractProductDao := Contract.NewContractProduct(o)
  390. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  391. if err != nil {
  392. o.Rollback()
  393. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  394. c.ServeJSON()
  395. return
  396. }
  397. //1-已通过 2-未通过 3-待审核 审核状态
  398. if contract.T_State == 1 {
  399. o.Rollback()
  400. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同已审核通过,禁止删除!"}
  401. c.ServeJSON()
  402. return
  403. }
  404. err = ContractDao.Delete_Contract(contract)
  405. if err != nil {
  406. o.Rollback()
  407. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  408. c.ServeJSON()
  409. return
  410. }
  411. //合同类型 1-销售合同 2-验证合同
  412. cpList := ContractProductDao.Read_ContractProduct_List(T_number)
  413. for _, v := range cpList {
  414. err = ContractProductDao.Delete_ContractProduct(v)
  415. if err != nil {
  416. o.Rollback()
  417. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  418. c.ServeJSON()
  419. return
  420. }
  421. }
  422. o.Commit()
  423. NatsServer.AddUserLogs(c.User.T_uuid, "合同", "删除", T_number)
  424. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  425. c.ServeJSON()
  426. return
  427. }
  428. func (c *ContractController) Contract_List_For_Out() {
  429. // 分页参数 初始化
  430. page, _ := c.GetInt("page")
  431. if page < 1 {
  432. page = 1
  433. }
  434. page_z, _ := c.GetInt("page_z")
  435. if page_z < 1 {
  436. page_z = conf.Page_size
  437. }
  438. // 查询
  439. T_name := c.GetString("T_name")
  440. userList, _ := NatsServer.Read_User_List_All()
  441. Account.Read_User_All_Map(userList)
  442. ContractDao := Contract.NewContract(orm.NewOrm())
  443. R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, 1, 1, page, page_z)
  444. var r_jsons lib.R_JSONS
  445. r_jsons.Num = R_cnt
  446. r_jsons.Data = R_List
  447. r_jsons.Page = page
  448. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  449. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  450. c.ServeJSON()
  451. return
  452. }
  453. // 合同下的产品列表 出库时使用
  454. func (c *ContractController) Contract_Product_List() {
  455. // 查询
  456. T_number := c.GetString("T_number")
  457. T_depot_id, _ := c.GetInt("T_depot_id")
  458. o := orm.NewOrm()
  459. ContractDao := Contract.NewContract(o)
  460. ContractProductDao := Contract.NewContractProduct(o)
  461. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  462. if err != nil {
  463. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  464. c.ServeJSON()
  465. return
  466. }
  467. productList := ContractProductDao.Read_ContractProduct_OutList(contract.T_number)
  468. Stock.Read_Stock_All_Map(T_depot_id)
  469. var pList []Contract.ContractProduct_Out
  470. for _, v := range productList {
  471. p := Contract.ContractProductToContractProduct_Out(v)
  472. p.T_stock_total = Stock.Read_Stock_Get(T_depot_id, p.T_product_id)
  473. pList = append(pList, p)
  474. }
  475. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: pList}
  476. c.ServeJSON()
  477. return
  478. }
  479. // 检查需要删除的合同产品列表
  480. func Check_NeedToDelete_Product_List(list []string, newList []Contract.ContractProduct) (needToDelete map[string]int, all map[int]string) {
  481. var productMap = map[int]int{}
  482. needToDelete = make(map[string]int)
  483. all = make(map[int]string)
  484. for _, v := range list {
  485. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  486. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  487. productMap[product_id] = num
  488. }
  489. for _, product := range newList {
  490. all[product.T_product_id] = fmt.Sprintf("%d-%d", product.Id, product.T_product_total)
  491. _, ok := productMap[product.T_product_id]
  492. if !ok {
  493. id := fmt.Sprintf("%d-%d", product.Id, product.T_product_id)
  494. needToDelete[id] = product.T_product_out
  495. }
  496. }
  497. return
  498. }
  499. // 验证合同
  500. func (c *ContractController) VerifyContract_List() {
  501. // 分页参数 初始化
  502. page, _ := c.GetInt("page")
  503. if page < 1 {
  504. page = 1
  505. }
  506. page_z, _ := c.GetInt("page_z")
  507. if page_z < 1 {
  508. page_z = conf.Page_size
  509. }
  510. T_customer_id := c.GetString("T_customer_id")
  511. // 查询
  512. T_name := c.GetString("T_name")
  513. userList, _ := NatsServer.Read_User_List_All()
  514. Account.Read_User_All_Map(userList)
  515. ContractDao := Contract.NewContract(orm.NewOrm())
  516. R_List, R_cnt := ContractDao.Read_VerifyContract_List(T_name, T_customer_id, page, page_z)
  517. var r_jsons lib.R_JSONS
  518. r_jsons.Num = R_cnt
  519. r_jsons.Data = R_List
  520. r_jsons.Page = page
  521. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  522. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  523. c.ServeJSON()
  524. return
  525. }
  526. // 验证合同呢添加
  527. func (c *ContractController) VerifyContract_Add() {
  528. T_number := c.GetString("T_number")
  529. T_customer_id := c.GetString("T_customer_id")
  530. T_money, _ := c.GetFloat("T_money")
  531. T_discount, _ := c.GetFloat("T_discount")
  532. T_date := c.GetString("T_date")
  533. T_product := c.GetString("T_product")
  534. T_submit := c.GetString("T_submit")
  535. T_remark := c.GetString("T_remark")
  536. T_pdf := c.GetString("T_pdf")
  537. T_project := c.GetString("T_project")
  538. T_recoveries := c.GetString("T_recoveries")
  539. T_invoice := c.GetString("T_invoice")
  540. T_start_date := c.GetString("T_start_date")
  541. T_end_date := c.GetString("T_end_date")
  542. T_stamping_date := c.GetString("T_stamping_date")
  543. T_payment_method := c.GetString("T_payment_method")
  544. var_ := Contract.Contract{
  545. T_number: T_number,
  546. T_customer_id: T_customer_id,
  547. T_money: float32(T_money),
  548. T_discount: float32(T_discount),
  549. T_project: T_project,
  550. T_type: 2, //合同类型 1-销售合同 2-验证合同
  551. T_date: T_date,
  552. T_State: 1,
  553. T_remark: T_remark,
  554. T_pdf: T_pdf,
  555. T_submit: T_submit,
  556. T_recoveries: T_recoveries,
  557. T_invoice: T_invoice,
  558. T_start_date: T_start_date,
  559. T_end_date: T_end_date,
  560. T_stamping_date: T_stamping_date,
  561. T_payment_method: T_payment_method,
  562. }
  563. _, var_.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  564. _, var_.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  565. o := orm.NewOrm()
  566. o.Begin()
  567. ContractDao := Contract.NewContract(o)
  568. ContractProductDao := Contract.NewContractProduct(o)
  569. _, err := ContractDao.Read_Contract_ByT_date(T_customer_id, T_start_date, T_end_date)
  570. if err == nil {
  571. o.Rollback()
  572. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同签约时间重复!"}
  573. c.ServeJSON()
  574. return
  575. }
  576. _, err = ContractDao.Read_Contract_ByT_number(T_number)
  577. if err == nil {
  578. o.Rollback()
  579. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同编号重复!"}
  580. c.ServeJSON()
  581. return
  582. }
  583. ContractID, err := ContractDao.Add_Contract(var_)
  584. if err != nil {
  585. o.Rollback()
  586. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  587. c.ServeJSON()
  588. return
  589. }
  590. if len(T_product) == 0 {
  591. o.Rollback()
  592. c.Data["json"] = lib.JSONS{Code: 202, Msg: "验证合同明细不能为空"}
  593. c.ServeJSON()
  594. return
  595. }
  596. productList := lib.SplitString(T_product, "|")
  597. ContractOut := 0
  598. for _, v := range productList {
  599. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  600. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  601. price := lib.StringToFloat64TwoDecimal(strings.Split(v, ",")[2])
  602. product, _ := Basic.Read_Product_ById(product_id)
  603. contractProduct := Contract.ContractProduct{
  604. T_contract_number: T_number,
  605. T_product_id: product_id,
  606. T_product_total: num,
  607. T_product_out: 0, // 已出库数量
  608. T_price: float32(price), // 价格
  609. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  610. }
  611. if product.T_class < 0 {
  612. contractProduct.T_State = 3
  613. }
  614. if product.T_class == 0 {
  615. ContractOut = 1
  616. }
  617. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  618. if err != nil {
  619. o.Rollback()
  620. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败"}
  621. c.ServeJSON()
  622. return
  623. }
  624. }
  625. o.Commit()
  626. o2 := orm.NewOrm()
  627. ContractDao2 := Contract.NewContract(o2)
  628. if ContractOut == 1 {
  629. err = ContractDao2.Update_Contract(Contract.Contract{Id: int(ContractID), T_out: ContractOut}, "T_out")
  630. if err != nil {
  631. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新合同出库状态失败"}
  632. c.ServeJSON()
  633. return
  634. }
  635. }
  636. err = Update_VerifyContract_State(T_customer_id, "ADD")
  637. if err != nil {
  638. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新状态失败"}
  639. c.ServeJSON()
  640. return
  641. }
  642. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "添加", var_)
  643. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  644. c.ServeJSON()
  645. return
  646. }
  647. // 验证合同呢修改
  648. func (c *ContractController) VerifyContract_Edit() {
  649. Id, _ := c.GetInt("Id")
  650. T_number := c.GetString("T_number")
  651. T_money, _ := c.GetFloat("T_money")
  652. T_discount, _ := c.GetFloat("T_discount")
  653. T_date := c.GetString("T_date")
  654. T_product := c.GetString("T_product")
  655. T_remark := c.GetString("T_remark")
  656. T_pdf := c.GetString("T_pdf")
  657. T_project := c.GetString("T_project")
  658. T_recoveries := c.GetString("T_recoveries")
  659. T_invoice := c.GetString("T_invoice")
  660. T_start_date := c.GetString("T_start_date")
  661. T_end_date := c.GetString("T_end_date")
  662. T_submit := c.GetString("T_submit")
  663. T_stamping_date := c.GetString("T_stamping_date")
  664. T_payment_method := c.GetString("T_payment_method")
  665. o := orm.NewOrm()
  666. o.Begin()
  667. ContractDao := Contract.NewContract(o)
  668. ContractProductDao := Contract.NewContractProduct(o)
  669. contract, err := ContractDao.Read_Contract_ById(Id)
  670. if err != nil || contract.T_type == 1 {
  671. o.Rollback()
  672. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  673. c.ServeJSON()
  674. return
  675. }
  676. oldT_number := contract.T_number
  677. if T_number != oldT_number {
  678. _, err1 := ContractDao.Read_Contract_ByT_number(T_number)
  679. if err1 == nil {
  680. o.Rollback()
  681. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("合同编号%s已存在!", T_number)}
  682. c.ServeJSON()
  683. return
  684. }
  685. contract.T_number = T_number
  686. }
  687. if T_money > 0 {
  688. contract.T_money = float32(T_money)
  689. }
  690. if T_discount > 0 {
  691. contract.T_discount = float32(T_discount)
  692. }
  693. if len(T_date) > 0 {
  694. contract.T_date = T_date
  695. }
  696. if len(T_remark) > 0 {
  697. contract.T_remark = T_remark
  698. }
  699. if len(T_pdf) > 0 {
  700. contract.T_pdf = T_pdf
  701. }
  702. if len(T_project) > 0 {
  703. contract.T_project = T_project
  704. }
  705. if len(T_recoveries) > 0 {
  706. contract.T_recoveries = T_recoveries
  707. _, contract.T_recoveries_money = Contract.ContractToContractFinance_R(T_recoveries)
  708. }
  709. if len(T_invoice) > 0 {
  710. contract.T_invoice = T_invoice
  711. _, contract.T_invoice_money = Contract.ContractToContractFinance_R(T_invoice)
  712. }
  713. if len(T_start_date) > 0 {
  714. contract.T_start_date = T_start_date
  715. }
  716. if len(T_end_date) > 0 {
  717. contract.T_end_date = T_end_date
  718. }
  719. if len(T_submit) > 0 {
  720. contract.T_submit = T_submit
  721. }
  722. if len(T_stamping_date) > 0 {
  723. contract.T_stamping_date = T_stamping_date
  724. }
  725. if len(T_payment_method) > 0 {
  726. contract.T_payment_method = T_payment_method
  727. }
  728. err = ContractDao.Update_Contract(contract, "T_number", "T_money", "T_discount", "T_date", "T_remark", "T_pdf", "T_State", "T_project",
  729. "T_recoveries", "T_recoveries_money", "T_invoice", "T_invoice_money", "T_start_date", "T_end_date", "T_submit", "T_stamping_date", "T_payment_method")
  730. if err != nil {
  731. o.Rollback()
  732. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  733. c.ServeJSON()
  734. return
  735. }
  736. if len(T_product) == 0 {
  737. o.Rollback()
  738. c.Data["json"] = lib.JSONS{Code: 202, Msg: "产品明细不能为空"}
  739. c.ServeJSON()
  740. return
  741. }
  742. productList := lib.SplitString(T_product, "|")
  743. cpl, _ := ContractProductDao.Read_ContractProductList_ByT_number(oldT_number)
  744. needToDeleteList, allList := Check_NeedToDelete_Product_List(productList, cpl)
  745. // 检查编辑时需要修改的产品
  746. for k, v := range needToDeleteList {
  747. id, _ := strconv.Atoi(strings.Split(k, "-")[0])
  748. productId, _ := strconv.Atoi(strings.Split(k, "-")[1])
  749. if v > 0 {
  750. o.Rollback()
  751. product, _ := Basic.Read_Product_ById(productId)
  752. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("%s已(部分)出库,禁止删除!", product.T_name)}
  753. c.ServeJSON()
  754. return
  755. }
  756. cp := Contract.ContractProduct{Id: id}
  757. err = ContractProductDao.Delete_ContractProduct(cp)
  758. if err != nil {
  759. o.Rollback()
  760. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  761. c.ServeJSON()
  762. return
  763. }
  764. }
  765. for _, v := range productList {
  766. product_id, _ := strconv.Atoi(strings.Split(v, ",")[0])
  767. num, _ := strconv.Atoi(strings.Split(v, ",")[1])
  768. price := lib.StringToFloat64TwoDecimal(strings.Split(v, ",")[2])
  769. oldContractProduct, ok := allList[product_id]
  770. if !ok {
  771. contractProduct := Contract.ContractProduct{
  772. T_contract_number: T_number,
  773. T_product_id: product_id,
  774. T_product_total: num,
  775. T_product_out: 0, // 已出库数量
  776. T_State: 1, // 1-未出库 2-已部分出库 3-已全部出库
  777. }
  778. _, err = ContractProductDao.Add_ContractProduct(contractProduct)
  779. if err != nil {
  780. o.Rollback()
  781. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  782. c.ServeJSON()
  783. return
  784. } else {
  785. continue
  786. }
  787. }
  788. // 修改产品总数量
  789. contractProductId, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[0])
  790. oldNum, _ := strconv.Atoi(strings.Split(oldContractProduct, "-")[1])
  791. if oldNum == num && T_number == oldT_number {
  792. continue
  793. }
  794. cp := Contract.ContractProduct{
  795. Id: contractProductId,
  796. T_contract_number: T_number,
  797. T_product_total: num,
  798. T_price: float32(price), // 价格
  799. }
  800. err = ContractProductDao.Update_ContractProduct(cp, "T_product_total", "T_contract_number")
  801. if err != nil {
  802. o.Rollback()
  803. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  804. c.ServeJSON()
  805. return
  806. }
  807. }
  808. o.Commit()
  809. err = Update_VerifyContract_State(contract.T_customer_id, "UPDATE")
  810. if err != nil {
  811. c.Data["json"] = lib.JSONS{Code: 202, Msg: "更新状态失败"}
  812. c.ServeJSON()
  813. return
  814. }
  815. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "修改", contract)
  816. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  817. c.ServeJSON()
  818. return
  819. }
  820. func (c *ContractController) VerifyContract_Del() {
  821. T_number := c.GetString("T_number")
  822. o := orm.NewOrm()
  823. o.Begin()
  824. ContractDao := Contract.NewContract(o)
  825. ContractProductDao := Contract.NewContractProduct(o)
  826. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  827. if err != nil {
  828. o.Rollback()
  829. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  830. c.ServeJSON()
  831. return
  832. }
  833. err = ContractDao.Delete_Contract(contract)
  834. if err != nil {
  835. o.Rollback()
  836. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  837. c.ServeJSON()
  838. return
  839. }
  840. cpList := ContractProductDao.Read_ContractProduct_List(T_number)
  841. for _, v := range cpList {
  842. err = ContractProductDao.Delete_ContractProduct(v)
  843. if err != nil {
  844. o.Rollback()
  845. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  846. c.ServeJSON()
  847. return
  848. }
  849. }
  850. o.Commit()
  851. err = Update_VerifyContract_State(contract.T_customer_id, "DELETE")
  852. if err != nil {
  853. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改状态失败"}
  854. c.ServeJSON()
  855. return
  856. }
  857. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "删除", T_number)
  858. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  859. c.ServeJSON()
  860. return
  861. }
  862. // 导出验证合同
  863. func (c *ContractController) VerifyContract_Excel() {
  864. // 分页参数 初始化
  865. page, _ := c.GetInt("page")
  866. if page < 1 {
  867. page = 1
  868. }
  869. page_z, _ := c.GetInt("page_z")
  870. if page_z < 1 {
  871. page_z = conf.Page_size
  872. }
  873. // 查询
  874. T_name := c.GetString("T_name") // 客户名称
  875. T_state, _ := c.GetInt("T_state") // 签约状态
  876. T_start_date := c.GetString("T_start_date") // 盖章开始时间
  877. T_end_date := c.GetString("T_end_date") // 盖章结束时间
  878. data := ""
  879. if len(T_start_date) > 0 || len(T_end_date) > 0 {
  880. data = fmt.Sprintf("%s - %s", T_start_date, T_end_date)
  881. }
  882. userList, _ := NatsServer.Read_User_List_All()
  883. Account.Read_User_All_Map(userList)
  884. Contract.Read_VerifyContract_All_Map()
  885. ContractDao := Contract.NewContract(orm.NewOrm())
  886. R_List := ContractDao.Read_VerifyContract_Excel(T_state, T_name, T_start_date, T_end_date)
  887. f := excelize.NewFile() //设置单元格值
  888. // 这里设置表头ÒÒ
  889. Style1, _ := f.NewStyle(
  890. &excelize.Style{
  891. Font: &excelize.Font{Size: 20, Family: "宋体"},
  892. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  893. })
  894. Style2, _ := f.NewStyle(
  895. &excelize.Style{
  896. Font: &excelize.Font{Size: 15, Family: "宋体"},
  897. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  898. Border: []excelize.Border{
  899. {Type: "left", Color: "000000", Style: 1},
  900. {Type: "top", Color: "000000", Style: 1},
  901. {Type: "bottom", Color: "000000", Style: 1},
  902. {Type: "right", Color: "000000", Style: 1},
  903. },
  904. Fill: excelize.Fill{Type: "pattern", Color: []string{"D9D9D9"}, Pattern: 1},
  905. })
  906. Style3, _ := f.NewStyle(
  907. &excelize.Style{
  908. Font: &excelize.Font{Size: 15, Family: "宋体"},
  909. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  910. Border: []excelize.Border{
  911. {Type: "left", Color: "000000", Style: 1},
  912. {Type: "top", Color: "000000", Style: 1},
  913. {Type: "bottom", Color: "000000", Style: 1},
  914. {Type: "right", Color: "000000", Style: 1},
  915. },
  916. })
  917. f.MergeCell("Sheet1", "A1", "T1")
  918. f.SetCellValue("Sheet1", "A1", data+"合同明细")
  919. f.SetCellStyle("Sheet1", "A1", "T1", Style1)
  920. // 写入表头
  921. headers := []string{"合同编号", "客户名称", "销售人员", "签订时间", "起始时间", "终止时间", "盖章时间", "合同名称", "验证明细",
  922. "合同金额", "优惠金额", "付款方式/预付款", "回款时间", "以往回款", "回款金额", "未回款金额", "开票时间", "已开票金额", "未开票金额",
  923. "状态"}
  924. for col, header := range headers {
  925. cell := fmt.Sprintf("%c%d", rune('A'+col), 2)
  926. f.SetCellValue("Sheet1", cell, header)
  927. }
  928. // 这里设置表头
  929. f.SetCellStyle("Sheet1", "A2", "T2", Style2)
  930. f.SetRowHeight("Sheet1", 1, 50)
  931. f.SetRowHeight("Sheet1", 2, 50)
  932. colsWidth := []float64{15, 15, 12, 12, 12, 12, 12, 15, 50, 12, 12, 12, 12, 25, 12, 10, 25, 10, 10, 10}
  933. // 冻结1-2行
  934. f.SetPanes("Sheet1", &excelize.Panes{
  935. Freeze: true,
  936. Split: false,
  937. XSplit: 0,
  938. YSplit: 2,
  939. TopLeftCell: "A1",
  940. ActivePane: "topRight",
  941. })
  942. for col, width := range colsWidth {
  943. cell := fmt.Sprintf("%c", rune('A'+col))
  944. f.SetColWidth("Sheet1", cell, cell, width)
  945. }
  946. line := 2
  947. for _, v := range R_List {
  948. valueList := []interface{}{
  949. v.T_number, v.T_customer, v.T_submit_name, v.T_date, v.T_start_date, v.T_end_date, v.T_stamping_date, "冷链验证合同",
  950. v.T_Product, v.T_money, v.T_discount, Contract.Get_Contract_payment_method(v.T_payment_method), v.T_recoveries_time, v.T_recoveries, v.T_discount - v.T_no_recoveries_money,
  951. v.T_no_recoveries_money, v.T_invoice, v.T_discount - v.T_no_invoice_money, v.T_no_invoice_money, v.T_verify_state,
  952. }
  953. line++
  954. for col, value := range valueList {
  955. cell := fmt.Sprintf("%c", rune('A'+col))
  956. if cell == "N" || cell == "Q" {
  957. ll := value.([]Contract.ContractFinance_R)
  958. var sv []string
  959. for _, info := range ll {
  960. sv = append(sv, fmt.Sprintf("%s %s", info.T_date, FormatFloat(float64(info.T_money))))
  961. }
  962. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", cell, line), strings.Join(sv, "\n"))
  963. continue
  964. }
  965. if cell == "I" {
  966. ll := value.([]Contract.ContractProduct_R)
  967. var sv []string
  968. for _, info := range ll {
  969. sv = append(sv, fmt.Sprintf("%s %s*%d=%s", info.T_product_name, FormatFloat(float64(info.T_price)), info.T_product_total, FormatFloat(float64(info.T_price)*float64(info.T_product_total))))
  970. }
  971. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", cell, line), strings.Join(sv, "\n"))
  972. continue
  973. }
  974. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", cell, line), value)
  975. }
  976. }
  977. f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("T%d", line), Style3)
  978. timeStr := time.Now().Format("20060102150405")
  979. fileName := fmt.Sprintf("%s合同明细%v.xlsx", data, timeStr)
  980. filePath := "ofile/" + fileName
  981. // 保存文件
  982. if err := f.SaveAs(filePath); err != nil {
  983. logs.Error("保存文件失败:", err)
  984. }
  985. defer func() {
  986. os.Remove(filePath)
  987. }()
  988. c.Ctx.Output.Header("Content-Type", "application/vnd.ms-excel;charset=utf8")
  989. c.Ctx.Output.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName))
  990. c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
  991. c.Ctx.Output.Download(filePath, fileName)
  992. }
  993. func Update_VerifyContract_State(T_customer_id, flag string) error {
  994. o := orm.NewOrm()
  995. ContractDao := Contract.NewContract(o)
  996. VerifyContractDao := Contract.NewVerifyContract(o)
  997. vcn := ContractDao.Read_VerifyContract_Newest(T_customer_id)
  998. vc, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_customer_id)
  999. if err != nil {
  1000. return err
  1001. }
  1002. if vcn.Id == 0 {
  1003. vc.T_sign_times = 0
  1004. vc.T_start_date = ""
  1005. vc.T_end_date = ""
  1006. vc.T_State = 1
  1007. err = VerifyContractDao.Update_VerifyContract(vc, "T_start_date", "T_end_date", "T_sign_times", "T_State")
  1008. return err
  1009. }
  1010. if flag == "ADD" {
  1011. vc.T_sign_times += 1
  1012. } else if flag == "DELETE" {
  1013. vc.T_sign_times -= 1
  1014. }
  1015. if len(vc.T_start_date) == 0 {
  1016. vc.T_start_date = vcn.T_start_date
  1017. }
  1018. if vc.T_end_date != vcn.T_end_date {
  1019. vc.T_end_date = vcn.T_end_date
  1020. }
  1021. nowTime := time.Now()
  1022. now := time.Date(nowTime.Year(), nowTime.Month(), nowTime.Day(), 0, 0, 0, 0, time.Local)
  1023. end, _ := lib.DateStrToTime(vcn.T_end_date)
  1024. now2Month := now.AddDate(0, 2, 0)
  1025. // 1-未签约 2-已作废 3-已签约 4-即将到期
  1026. state := 1
  1027. // 结束时间<今天 已过期
  1028. if end.Before(now) {
  1029. state = 2
  1030. } else {
  1031. // 结束时间<今天+2月 即将到期 && 结束时间>今天
  1032. if end.Before(now2Month) || end.Equal(now) {
  1033. state = 4
  1034. NatsServer.AddNews(vcn.T_approver, fmt.Sprintf("【合同即将过期提醒】%s的验证合同将于%s过期!", vc.T_customer, vc.T_end_date), conf.VerifyContractUrl)
  1035. }
  1036. // 结束时间>今天+2月 已签约
  1037. if end.After(now2Month) || end.Equal(now2Month) {
  1038. state = 3
  1039. }
  1040. }
  1041. vc.T_State = state
  1042. err = VerifyContractDao.Update_VerifyContract(vc, "T_start_date", "T_end_date", "T_sign_times", "T_State")
  1043. return err
  1044. }
  1045. // 验证合同-添加客户
  1046. func (c *ContractController) VerifyContract_Add_Customer() {
  1047. T_customer := c.GetString("T_customer")
  1048. o := orm.NewOrm()
  1049. VerifyContractDao := Contract.NewVerifyContract(o)
  1050. T_number := ""
  1051. for true {
  1052. rand_x := 1
  1053. T_number = fmt.Sprintf("YZKH-%s", lib.GetRandstring(8, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", int64(rand_x)))
  1054. _, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_number)
  1055. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  1056. break
  1057. }
  1058. rand_x += 1
  1059. }
  1060. var_ := Contract.VerifyContract{
  1061. T_customer: T_customer,
  1062. T_customer_id: T_number,
  1063. T_State: 1,
  1064. }
  1065. _, err := VerifyContractDao.Add_VerifyContract(var_)
  1066. if err != nil {
  1067. o.Rollback()
  1068. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  1069. c.ServeJSON()
  1070. return
  1071. }
  1072. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "添加客户", var_)
  1073. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_number}
  1074. c.ServeJSON()
  1075. return
  1076. }
  1077. // 验证合同-编辑客户
  1078. func (c *ContractController) VerifyContract_Update_Customer() {
  1079. T_customer_id := c.GetString("T_customer_id")
  1080. T_customer := c.GetString("T_customer")
  1081. o := orm.NewOrm()
  1082. VerifyContractDao := Contract.NewVerifyContract(o)
  1083. vc, err := VerifyContractDao.Read_VerifyContract_ByT_customer_id(T_customer_id)
  1084. vc.T_customer = T_customer
  1085. err = VerifyContractDao.Update_VerifyContract(vc)
  1086. if err != nil {
  1087. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  1088. c.ServeJSON()
  1089. return
  1090. }
  1091. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "编辑客户", vc)
  1092. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_customer_id}
  1093. c.ServeJSON()
  1094. return
  1095. }
  1096. // 验证合同-客户列表
  1097. func (c *ContractController) VerifyContract_Customer_List() {
  1098. // 分页参数 初始化
  1099. page, _ := c.GetInt("page")
  1100. if page < 1 {
  1101. page = 1
  1102. }
  1103. page_z, _ := c.GetInt("page_z")
  1104. if page_z < 1 {
  1105. page_z = conf.Page_size
  1106. }
  1107. // 查询
  1108. T_name := c.GetString("T_name")
  1109. T_state, _ := c.GetInt("T_state")
  1110. VerifyContractDao := Contract.NewVerifyContract(orm.NewOrm())
  1111. R_List, R_cnt := VerifyContractDao.Read_VerifyContract_List(T_name, T_state, page, page_z)
  1112. var r_jsons lib.R_JSONS
  1113. r_jsons.Num = R_cnt
  1114. r_jsons.Data = R_List
  1115. r_jsons.Page = page
  1116. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1117. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1118. c.ServeJSON()
  1119. return
  1120. }
  1121. // 合同回款明细列表
  1122. func (c *ContractController) Contract_List_RecoveriesMoney() {
  1123. // 分页参数 初始化
  1124. page, _ := c.GetInt("page")
  1125. if page < 1 {
  1126. page = 1
  1127. }
  1128. page_z, _ := c.GetInt("page_z")
  1129. if page_z < 1 {
  1130. page_z = conf.Page_size
  1131. }
  1132. // 查询
  1133. T_submit := c.GetString("T_submit")
  1134. T_name := c.GetString("T_name")
  1135. T_start_date := c.GetString("T_start_date") // 回款开始日期
  1136. T_end_date := c.GetString("T_end_date") // 回款结束日期
  1137. T_recoveries_state, _ := c.GetInt("T_recoveries_state") // 回款状态 1 未回款 2 部分回款 3 全部回款
  1138. T_invoice_state, _ := c.GetInt("T_invoice_state") // 开票状态 1 未开票 2 部分开票 3 全部开票
  1139. T_percentage_state, _ := c.GetInt("T_percentage_state") // 提成状态 1-未打款 2-已打款
  1140. T_mine, _ := c.GetInt("T_mine") // 我的 用于合同提成显示
  1141. userList, _ := NatsServer.Read_User_List_All()
  1142. Account.Read_User_All_Map(userList)
  1143. Contract.Read_VerifyContract_All_Map()
  1144. ContractDao := Contract.NewContract(orm.NewOrm())
  1145. R_List, R_cnt := ContractDao.Read_Contract_List_For_RecoveriesAndInvoice(c.User.T_uuid, T_submit, T_mine, T_name, T_start_date, T_end_date, T_recoveries_state, T_invoice_state, T_percentage_state, page, page_z)
  1146. var r_jsons lib.R_JSONS
  1147. r_jsons.Num = R_cnt
  1148. r_jsons.Data = R_List
  1149. r_jsons.Page = page
  1150. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1151. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1152. c.ServeJSON()
  1153. return
  1154. }
  1155. // 导出合同回款明细列表
  1156. func (c *ContractController) Contract_List_RecoveriesMoney_Export() {
  1157. // 查询
  1158. T_submit := c.GetString("T_submit")
  1159. T_name := c.GetString("T_name")
  1160. T_start_date := c.GetString("T_start_date") // 回款开始日期
  1161. T_end_date := c.GetString("T_end_date") // 回款结束日期
  1162. T_recoveries_state, _ := c.GetInt("T_recoveries_state") // 回款状态 1 未回款 2 部分回款 3 全部回款
  1163. T_invoice_state, _ := c.GetInt("T_invoice_state") // 开票状态 1 未开票 2 部分开票 3 全部开票
  1164. T_percentage_state, _ := c.GetInt("T_percentage_state") // 提成状态 1-未打款 2-已打款
  1165. T_mine, _ := c.GetInt("T_mine") // 我的 用于合同提成显示
  1166. userList, _ := NatsServer.Read_User_List_All()
  1167. Account.Read_User_All_Map(userList)
  1168. Contract.Read_VerifyContract_All_Map()
  1169. ContractDao := Contract.NewContract(orm.NewOrm())
  1170. R_List, _ := ContractDao.Read_Contract_List_For_RecoveriesAndInvoice(c.User.T_uuid, T_submit, T_mine, T_name, T_start_date, T_end_date, T_recoveries_state, T_invoice_state, T_percentage_state, 0, 9999)
  1171. title := "销售提成明细表"
  1172. if T_mine == 1 {
  1173. title = fmt.Sprintf("%s-销售提成明细表", c.User.T_name)
  1174. }
  1175. filename := fmt.Sprintf("%s(%s)", title, lib.GetRandstring(6, "0123456789", 0))
  1176. f := excelize.NewFile() // 设置单元格的值
  1177. Style1, _ := f.NewStyle(
  1178. &excelize.Style{
  1179. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  1180. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  1181. })
  1182. Style2, _ := f.NewStyle(
  1183. &excelize.Style{
  1184. Font: &excelize.Font{Bold: true, Size: 11, Family: "宋体"},
  1185. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  1186. Border: []excelize.Border{
  1187. {Type: "left", Color: "000000", Style: 1},
  1188. {Type: "top", Color: "000000", Style: 1},
  1189. {Type: "bottom", Color: "000000", Style: 1},
  1190. {Type: "right", Color: "000000", Style: 1},
  1191. },
  1192. })
  1193. Style3, _ := f.NewStyle(
  1194. &excelize.Style{
  1195. Font: &excelize.Font{Size: 11, Family: "宋体"},
  1196. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  1197. Border: []excelize.Border{
  1198. {Type: "left", Color: "000000", Style: 1},
  1199. {Type: "top", Color: "000000", Style: 1},
  1200. {Type: "bottom", Color: "000000", Style: 1},
  1201. {Type: "right", Color: "000000", Style: 1},
  1202. },
  1203. })
  1204. f.MergeCell("Sheet1", "A1", "J1")
  1205. f.SetRowStyle("Sheet1", 1, 1, Style1)
  1206. f.SetCellValue("Sheet1", "A1", title)
  1207. f.SetRowHeight("Sheet1", 1, 30)
  1208. // 这里设置表头
  1209. f.SetCellStyle("Sheet1", "A2", "J2", Style2)
  1210. f.SetRowHeight("Sheet1", 2, 20)
  1211. f.SetCellValue("Sheet1", "A2", "公司名称")
  1212. f.SetCellValue("Sheet1", "B2", "合同编号")
  1213. f.SetCellValue("Sheet1", "C2", "签约时间")
  1214. f.SetCellValue("Sheet1", "D2", "合同金额")
  1215. f.SetCellValue("Sheet1", "E2", "回款金额")
  1216. f.SetCellValue("Sheet1", "F2", "回款比例")
  1217. f.SetCellValue("Sheet1", "G2", "销售类型")
  1218. f.SetCellValue("Sheet1", "H2", "销售提成5%")
  1219. f.SetCellValue("Sheet1", "I2", "提成金额")
  1220. f.SetCellValue("Sheet1", "J2", "提成状态")
  1221. // 设置列宽
  1222. f.SetColWidth("Sheet1", "A", "A", 25)
  1223. f.SetColWidth("Sheet1", "B", "I", 15)
  1224. line := 2
  1225. for _, contract := range R_List {
  1226. line += 1
  1227. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), line-2)
  1228. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), contract.T_customer)
  1229. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), contract.T_number)
  1230. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), contract.T_date)
  1231. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), contract.T_discount)
  1232. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), contract.T_recoveries_money)
  1233. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), fmt.Sprintf("%.02f%%", contract.T_recoveries_money/contract.T_discount*100))
  1234. T_type_str := "验证合同"
  1235. if contract.T_type == 1 {
  1236. T_type_str = "销售合同"
  1237. }
  1238. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), T_type_str)
  1239. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), fmt.Sprintf("%.02f", contract.T_discount*0.05))
  1240. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("%.02f", contract.T_discount*0.05))
  1241. T_percentage_str := "未打款"
  1242. if contract.T_percentage_state == 2 {
  1243. T_percentage_str = "已打款"
  1244. }
  1245. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), T_percentage_str)
  1246. }
  1247. f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("J%d", line), Style3)
  1248. // 保存文件
  1249. if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
  1250. fmt.Println(err)
  1251. }
  1252. var url string
  1253. //// 上传 OSS
  1254. nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
  1255. url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
  1256. if !is {
  1257. c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
  1258. c.ServeJSON()
  1259. return
  1260. }
  1261. //删除目录
  1262. err := os.Remove("ofile/" + filename + ".xlsx")
  1263. if err != nil {
  1264. logs.Error(lib.FuncName(), err)
  1265. }
  1266. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  1267. c.ServeJSON()
  1268. return
  1269. }
  1270. func (c *ContractController) Contract_Stat() {
  1271. T_type, _ := c.GetInt("T_type")
  1272. T_year, _ := c.GetInt("T_year")
  1273. type R_JSONS struct {
  1274. ContractMoneyByYear interface{}
  1275. TotalMoneyByYear float32
  1276. RecoveriesMoneyByYear float32
  1277. ContractNumByYear interface{}
  1278. TotalMumByYear int64
  1279. ContractMoneyByMonth interface{}
  1280. TotalMoneyByMonth float32
  1281. RecoveriesMoneyByMonth float32
  1282. ContractNumByMonth interface{}
  1283. TotalMumByMonth int64
  1284. TotalMoneyByThisYear float32 // 今年合同总金额
  1285. RecoveriesMoneyByThisYear float32 // 今年回款总金额
  1286. TotalMumByThisYear int64 // 今年合同总数
  1287. TotalMoneyByLastYear float32 // 去年合同总金额
  1288. RecoveriesMoneyByLastYear float32 // 去年回款总金额
  1289. TotalMumByLastYear int64 // 去年合同总数
  1290. }
  1291. var r_jsons R_JSONS
  1292. thisYear := time.Now().Year()
  1293. if T_year == 0 {
  1294. T_year = thisYear
  1295. }
  1296. ContractDao := Contract.NewContract(orm.NewOrm())
  1297. monryStat, moneyTotal, moneyRecoveries := ContractDao.Stat_ContractMoney_ByYear(T_type)
  1298. numStat, numTotal := ContractDao.Stat_ContractNum_ByYear(T_type)
  1299. monryMonthStat, moneyMonthTotal, moneyMonthRecoveries := ContractDao.Stat_ContractMoney_ByMonth(T_type, T_year)
  1300. numMonthStat, numMonthTotal := ContractDao.Stat_ContractNum_ByMonth(T_type, T_year)
  1301. // 去年
  1302. _, r_jsons.TotalMoneyByLastYear, r_jsons.RecoveriesMoneyByLastYear = ContractDao.Stat_ContractMoney_ByMonth(T_type, T_year-1)
  1303. _, r_jsons.TotalMumByLastYear = ContractDao.Stat_ContractNum_ByMonth(T_type, T_year-1)
  1304. r_jsons.ContractMoneyByYear = monryStat
  1305. r_jsons.TotalMoneyByYear = moneyTotal
  1306. r_jsons.RecoveriesMoneyByYear = moneyRecoveries
  1307. r_jsons.ContractNumByYear = numStat
  1308. r_jsons.TotalMumByYear = numTotal
  1309. r_jsons.ContractMoneyByMonth = monryMonthStat
  1310. r_jsons.TotalMoneyByMonth = moneyMonthTotal
  1311. r_jsons.RecoveriesMoneyByMonth = moneyMonthRecoveries
  1312. r_jsons.ContractNumByMonth = numMonthStat
  1313. r_jsons.TotalMumByMonth = numMonthTotal
  1314. r_jsons.TotalMoneyByThisYear = moneyMonthTotal
  1315. r_jsons.RecoveriesMoneyByThisYear = moneyMonthRecoveries
  1316. r_jsons.TotalMumByThisYear = numMonthTotal
  1317. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1318. c.ServeJSON()
  1319. return
  1320. }
  1321. func Cron_VerifyContract() {
  1322. //创建一个定时任务对象
  1323. c := cron.New(cron.WithSeconds())
  1324. //给对象增加定时任务
  1325. //c.AddFunc("0 */1 * * * ?", Cron_VerifyContract_ChangeState)
  1326. c.AddFunc("@daily", Cron_VerifyContract_ChangeState)
  1327. //启动定时任务
  1328. c.Start()
  1329. defer c.Stop()
  1330. //查询语句,阻塞,让main函数不退出,保持程序运行
  1331. select {}
  1332. }
  1333. // 修改合同状态
  1334. func Cron_VerifyContract_ChangeState() {
  1335. T_date := time.Now().Format("2006-01-02")
  1336. logs.Info("开始处理" + T_date + "验证合同状态")
  1337. VerifyContractDao := Contract.NewVerifyContract(orm.NewOrm())
  1338. R_List, _ := VerifyContractDao.Read_VerifyContract_List("", 0, 0, 999)
  1339. for _, v := range R_List {
  1340. err := Update_VerifyContract_State(v.T_customer_id, "UPDATE")
  1341. if err != nil {
  1342. logs.Error("修改合同状态失败")
  1343. }
  1344. }
  1345. }
  1346. // 修改回款金额及开票金额
  1347. func UpdateVerifyContract_RecoveriesInvoice_Money() {
  1348. ContractDao := Contract.NewContract(orm.NewOrm())
  1349. R_List, _ := ContractDao.Read_VerifyContract_List("", "", 0, 9999)
  1350. for _, verify := range R_List {
  1351. R := Contract.Contract{Id: verify.Id}
  1352. _, R.T_recoveries_money = Contract.ContractToContractFinance_R(verify.T_recoveries)
  1353. _, R.T_invoice_money = Contract.ContractToContractFinance_R(verify.T_invoice)
  1354. ContractDao.Update_Contract(R, "T_recoveries_money", "T_invoice_money")
  1355. }
  1356. }
  1357. // 修改回款时间
  1358. func UpdateVerifyContract_RecoveriesInvoice_Time() {
  1359. ContractDao := Contract.NewContract(orm.NewOrm())
  1360. R_List, _ := ContractDao.Read_VerifyContract_List("", "", 0, 9999)
  1361. for _, verify := range R_List {
  1362. R := Contract.Contract{Id: verify.Id}
  1363. if verify.T_discount == verify.T_recoveries_money {
  1364. recoveriesList, _ := Contract.ContractToContractFinance_R(verify.T_recoveries)
  1365. if len(recoveriesList) > 0 {
  1366. R.T_recoveries_time = recoveriesList[len(recoveriesList)-1].T_date
  1367. ContractDao.Update_Contract(R, "T_recoveries_time")
  1368. }
  1369. }
  1370. }
  1371. }
  1372. // 合同提成打款
  1373. func (c *ContractController) Contract_Percentage_Remit() {
  1374. T_number := c.GetString("T_number")
  1375. o := orm.NewOrm()
  1376. ContractDao := Contract.NewContract(o)
  1377. contract, err := ContractDao.Read_Contract_ByT_number(T_number)
  1378. if err != nil {
  1379. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_number Err!"}
  1380. c.ServeJSON()
  1381. return
  1382. }
  1383. if contract.T_recoveries_money != contract.T_discount {
  1384. c.Data["json"] = lib.JSONS{Code: 202, Msg: "合同未回款,不可打款!"}
  1385. c.ServeJSON()
  1386. return
  1387. }
  1388. contract.T_percentage_state = 2 // 已打款
  1389. err = ContractDao.Update_Contract(contract, "T_percentage_state")
  1390. if err != nil {
  1391. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  1392. c.ServeJSON()
  1393. return
  1394. }
  1395. NatsServer.AddUserLogs(c.User.T_uuid, "验证合同", "打款", contract)
  1396. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: contract.Id}
  1397. c.ServeJSON()
  1398. return
  1399. }
  1400. func (c *ContractController) User_List() {
  1401. var r_jsons lib.R_JSONS
  1402. // 分页参数 初始化
  1403. page, _ := c.GetInt("page")
  1404. if page < 1 {
  1405. page = 1
  1406. }
  1407. page_z, _ := c.GetInt("page_z")
  1408. if page_z < 1 {
  1409. page_z = conf.Page_size
  1410. }
  1411. T_name := c.GetString("T_name")
  1412. ContractDao := Contract.NewContract(orm.NewOrm())
  1413. uuidList := ContractDao.Read_T_submit_List()
  1414. if len(uuidList) == 0 {
  1415. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  1416. c.ServeJSON()
  1417. return
  1418. }
  1419. R_List, R_cnt, err := NatsServer.Read_User_List_T_uuid(T_name, uuidList, page, page_z)
  1420. if err != nil {
  1421. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败"}
  1422. c.ServeJSON()
  1423. return
  1424. }
  1425. var U_List []userlibs.User
  1426. for _, user := range R_List {
  1427. U_List = append(U_List, user)
  1428. }
  1429. r_jsons.Num = R_cnt
  1430. r_jsons.Data = U_List
  1431. r_jsons.Page = page
  1432. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1433. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1434. c.ServeJSON()
  1435. return
  1436. }
  1437. func FormatFloat(f float64) string {
  1438. // 先判断是否为整数
  1439. if f == math.Trunc(f) {
  1440. return strconv.FormatFloat(f, 'f', 0, 64)
  1441. }
  1442. // 否则保留2位小数
  1443. return strconv.FormatFloat(f, 'f', 2, 64)
  1444. }