Hello everyone, need help to create one function node
below is the given flow
[{"id":"4476fe10.e2765","type":"simpletime","z":"1f149e22.43a482","name":"","mydate":true,"myymd":true,"myyear":true,"mymonth":true,"mymonthn":true,"mydom":true,"mydoy":true,"myday":true,"myhourpm":true,"myhour":true,"mytime":true,"mytimes":true,"myminute":true,"myminutes":true,"mysecond":true,"mymillis":true,"myepoch":true,"myrawdate":true,"mypm":true,"x":450,"y":960,"wires":[["ed99652.1402f98"]]},{"id":"ed99652.1402f98","type":"template","z":"1f149e22.43a482","name":"date","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"from 01-{{mymonthn}}-{{myyear}} to {{mydom}}-{{mymonthn}}-{{myyear}}","output":"str","x":610,"y":960,"wires":[["e352cec1.fb968"]]},{"id":"e352cec1.fb968","type":"function","z":"1f149e22.43a482","name":"date, time","func":"msg.payload = msg.payload;\nmsg.topic='date';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":760,"y":960,"wires":[["1d1920d3.2a95ef"]]},{"id":"e2a56fda.b415","type":"MSSQL","z":"1f149e22.43a482","mssqlCN":"898d2a6f.9fb7b8","name":"A, P, Q, OEE (all machines)","query":"SELECT \n(((SUM (CAST([MACHINE SHIFT TIME (X)(Min.)] AS FLOAT))- SUM (CAST([AVAILABILITY LOSS TIME(Min.)] AS FLOAT)))/SUM (CAST([MACHINE SHIFT TIME (X)(Min.)] AS FLOAT)))*100) \nAS availability,\n((SUM(CAST([OK PRODUCTION] AS FLOAT)) / SUM(COALESCE((((CAST([MACHINE SHIFT TIME (X)(Min.)] AS FLOAT)-CAST([AVAILABILITY LOSS TIME(Min.)] AS FLOAT))/(NULLIF(CAST([TOTAL STANDARD CYCLE TIME(Sec.)] AS FLOAT),0)))*60*CAST([PARTS PER CYCLE (U)] AS FLOAT)),0)))*100)\nAS performance,\n((SUM(CAST([OK PRODUCTION] AS FLOAT)) / SUM(CAST([TOTAL PRODUCTION] AS FLOAT)))*100) \nAS quality,\n(((((SUM (CAST([MACHINE SHIFT TIME (X)(Min.)] AS FLOAT))- SUM (CAST([AVAILABILITY LOSS TIME(Min.)] AS FLOAT)))/SUM (CAST([MACHINE SHIFT TIME (X)(Min.)] AS FLOAT)))*100) \n*((SUM(CAST([OK PRODUCTION] AS FLOAT)) / SUM(COALESCE((((CAST([MACHINE SHIFT TIME (X)(Min.)] AS FLOAT)-CAST([AVAILABILITY LOSS TIME(Min.)] AS FLOAT))/(NULLIF(CAST([TOTAL STANDARD CYCLE TIME(Sec.)] AS FLOAT),0)))*60*CAST([PARTS PER CYCLE (U)] AS FLOAT)),0)))*100)\n*((SUM(CAST([OK PRODUCTION] AS FLOAT)) / SUM(CAST([TOTAL PRODUCTION] AS FLOAT)))*100))/10000)\nAS oee\nFROM dbo.SHIFT_DATA \nWHERE \ndatepart(mm,DATE) =month(getdate()) \nAND datepart(yyyy,DATE) =year(getdate()) \n AND [MACHINE CODE]='M02CN001'\n OR [MACHINE CODE]='M02CN002'\n OR [MACHINE CODE]='M02CN003'\n OR [MACHINE CODE]='M02CN004'\n OR [MACHINE CODE]='M02CN005'\n OR [MACHINE CODE]='M02CN006'\n OR [MACHINE CODE]='M02CN007'\n OR [MACHINE CODE]='M02CN008'\n OR [MACHINE CODE]='M02CN009'\n OR [MACHINE CODE]='M02CN010'\n OR [MACHINE CODE]='M02CN011'\n OR [MACHINE CODE]='M02CN012'\n OR [MACHINE CODE]='M02CN013'\n OR [MACHINE CODE]='M02HB001'\n OR [MACHINE CODE]='M02HB002'\n OR [MACHINE CODE]='M02HB004'\n OR [MACHINE CODE]='M02HB006'","outField":"payload","x":500,"y":860,"wires":[["78e7f81e.b0a038","a5820e64.dc55c","48ac6140.2c50c","17534980.bcb117","26cbf43b.40eaec","d95f858f.451bb8"]]},{"id":"78e7f81e.b0a038","type":"debug","z":"1f149e22.43a482","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":850,"y":860,"wires":[]},{"id":"5a910858.f025a8","type":"inject","z":"1f149e22.43a482","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":860,"wires":[["e2a56fda.b415","4476fe10.e2765"]]},{"id":"a5820e64.dc55c","type":"ui_gauge","z":"1f149e22.43a482","name":"","group":"1c20b4b1.269adb","order":1,"width":"3","height":"3","gtype":"donut","title":"availability","label":"% age","format":"{{msg.payload[0].availability | number: 0}} %","min":0,"max":"100","colors":["#ff0000","#e6e600","#2ed600"],"seg1":"50","seg2":"70","x":850,"y":700,"wires":[]},{"id":"48ac6140.2c50c","type":"ui_gauge","z":"1f149e22.43a482","name":"","group":"1c20b4b1.269adb","order":1,"width":"3","height":"3","gtype":"donut","title":"performance","label":"% age","format":"{{msg.payload[0].performance | number: 0}} %","min":0,"max":"100","colors":["#ff0000","#e6e600","#2ed600"],"seg1":"50","seg2":"70","x":850,"y":740,"wires":[]},{"id":"17534980.bcb117","type":"ui_gauge","z":"1f149e22.43a482","name":"","group":"1c20b4b1.269adb","order":1,"width":"3","height":"3","gtype":"donut","title":"quality","label":"% age","format":"{{msg.payload[0].quality | number: 0}} %","min":0,"max":"100","colors":["#ff0000","#e6e600","#2ed600"],"seg1":"50","seg2":"70","x":830,"y":780,"wires":[]},{"id":"26cbf43b.40eaec","type":"ui_gauge","z":"1f149e22.43a482","name":"","group":"1c20b4b1.269adb","order":1,"width":"3","height":"3","gtype":"donut","title":"oee","label":"% age","format":"{{msg.payload[0].oee | number: 0}} %","min":0,"max":"100","colors":["#ff0000","#e6e600","#2ed600"],"seg1":"50","seg2":"70","x":830,"y":820,"wires":[]},{"id":"1d1920d3.2a95ef","type":"join","z":"1f149e22.43a482","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":930,"y":940,"wires":[["594910d.0957ef"]]},{"id":"d95f858f.451bb8","type":"function","z":"1f149e22.43a482","name":"","func":"msg.payload.availability=a;\nmsg.topic='availability';\nmsg.payload.performance=b;\nmsg.topic='performance';\nmsg.payload.quality=c;\nmsg.topic='quality';\nmsg.payload.oee=d;\nmsg.tpoic=e;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":760,"y":920,"wires":[["1d1920d3.2a95ef"]]},{"id":"594910d.0957ef","type":"template","z":"1f149e22.43a482","name":"mail","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Hello! This is an auto generated test mail from Node Red.\n<div>OEE for MT-2's Small Shed from date {{payload.date}} is observed to be {{d}} %</div>\n<div>where</div>\n<div>Availability = {{a}} % </div>\n<div>Performance = {{a}} % </div>\n<div>Quality = {{c}} % </div>","output":"str","x":1050,"y":940,"wires":[["deb014af.7400a8"]]},{"id":"deb014af.7400a8","type":"debug","z":"1f149e22.43a482","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1190,"y":980,"wires":[]},{"id":"898d2a6f.9fb7b8","type":"MSSQL-CN","tdsVersion":"7_3_B","name":"MT02","server":"192.168.21.169\\SCADASQL","port":"1433","encyption":false,"database":"MT02","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5"},{"id":"1c20b4b1.269adb","type":"ui_group","name":"Group 2","tab":"5074feb8.5be66","order":3,"disp":true,"width":6},{"id":"5074feb8.5be66","type":"ui_tab","name":"home","icon":"dashboard","order":13,"disabled":false,"hidden":false}]
I don't want to use multiple function nodes can any one help. Also I'm not able to make the first function node to work as my coding skills are not good.