rmBillsGatherDm.pas 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. unit rmBillsGatherDm;
  2. interface
  3. uses
  4. SysUtils, Classes, DB, DBClient, MCacheTree, ProjectData,
  5. sdDB, sdIDTree, rmCacheData, rmSelectProjectFrm;
  6. type
  7. {---------------------------------
  8. bgtFx: 分项汇总模式,按树结构汇总所选项目,汇总后结果写入cdsFxBills
  9. bgtXmj: 项目节汇总模式,按树结构汇总所选项目的项目节节点,汇总后结果写入cdsFxBills
  10. bgtGcl: 工程量清单汇总模式,汇总后结果写入cdsGclBills
  11. bgtMultiXmj: bgtXmj模式的扩展,汇总展示多项目数据模式,与bgtXmj的差异在于记录了每个项目的数据,而不是单纯累加
  12. 汇总结果写入cdsProjectBills
  13. bgtEstimate: 决算02表,bgtXmj模式的扩展,
  14. 分别汇总前两个项目的0号台账为初步设计、施工图设计,其后为所有项目按bgtXmj方式汇总。
  15. 汇总结果写入cdsEstimateBills
  16. bgtEstimate1: 决算02表(部颁格式),bgtXmj模式的扩展,
  17. 汇总第一个项目的0号台账为批准的概(预)算,其后为所有项目按bgtXmj方式汇总。汇总结果写入cdsEstimateBills
  18. bgtFinal07: 决算07表,bgtGcl模式的扩展,汇总暂时多项目数据及合计数据模式
  19. 与bgtGcl的差异在于,记录了每个项目的数据,且汇总了某些固定id节点的数据在最后。汇总结果写入cdsProjectGclBills
  20. bgtFinal08: 决算08表,bgtXmj的特殊情况,仅汇总第二部分下的所有项目节节点,而非全部项目节。汇总结果写入cdsFxBills
  21. bgtFinal09: 决算09表,bgtXmj的特殊情况,汇总第三部分及气候所有项目节节点,而非全部项目节。汇总结果写入cdsFxBills
  22. bgtFinal11: 决算11表,与bgtFinal07极度相似,仅汇总固定id节点的数据处不同。汇总结果写入cdsProjectGclBills
  23. bgtFinal12: 决算12表,流水式写入每个项目的变更令数据。汇总结果写入cdsBGLFlow
  24. bgtFinal16: 决算16表,bgtMultiXmj的基础上增加了工程量清单数据,且仅汇总计日工部分(固定id40)。汇总结果写入cdsProjectBills
  25. bgtFinal17: 决算17表,bgtFx的特殊情况,仅汇总收尾工程部分(固定id47),汇总结果写入cdsFxBills
  26. bgtFinal18: 决算18表,bgtFx的特殊情况,仅汇总报废工程部分(固定id48),汇总结果吸入cdsFxBills
  27. bgtFinal19: 决算19表,bgtFinal07和bgtFinal11中去除后面的固定id节点数据,汇总结果写入cdsProjectGclBills
  28. bgtG_Final06_1: 粤竣06-1表,bgtEstimate的特殊情况,仅汇总土地(固定id21),且汇总初步设计、施工图设计
  29. 可理解为bgtEstimate扩展为Fx,然后再限制为汇总固定id下的数据,汇总后的结果写入cdsEstimateBills
  30. bgtG_Final04: 粤竣04表,在bgtXmj的基础上增加了设计数量、经济指标等数据,且增加了一行公路基本造价汇总行
  31. ----------------------------------}
  32. TbgType = (bgtFx, bgtXmj, bgtGcl, bgtMultiXmj, bgtEstimate,
  33. bgtEstimate1, bgtFinal07, bgtFinal08, bgtFinal09, bgtFinal11,
  34. bgtFinal12, bgtFinal16, bgtFinal17, bgtFinal18, bgtFinal19,
  35. bgtG_Final06_1, bgtG_Final04);
  36. TrmBillsGatherData = class(TDataModule)
  37. // 决算04, 05[竣04]
  38. cdsFxBills: TClientDataSet;
  39. cdsFxBillsXiangCode: TStringField;
  40. cdsFxBillsMuCode: TStringField;
  41. cdsFxBillsJieCode: TStringField;
  42. cdsFxBillsXiMuCode: TStringField;
  43. cdsFxBillsCode: TStringField;
  44. cdsFxBillsB_Code: TStringField;
  45. cdsFxBillsName: TWideStringField;
  46. cdsFxBillsUnits: TWideStringField;
  47. cdsFxBillsAddDealQuantity: TFloatField;
  48. cdsFxBillsAddDealTotalPrice: TFloatField;
  49. cdsFxBillsAddQcQuantity: TFloatField;
  50. cdsFxBillsAddPcQuantity: TFloatField;
  51. cdsFxBillsAddQcTotalPrice: TFloatField;
  52. cdsFxBillsAddPcTotalPrice: TFloatField;
  53. cdsFxBillsPrice: TFloatField;
  54. cdsFxBillsAddGatherQuantity: TFloatField;
  55. cdsFxBillsAddGatherTotalPrice: TFloatField;
  56. cdsFxBillsMemoStr: TWideStringField;
  57. cdsFxBillsPercent: TFloatField;
  58. cdsFxBillsQuantity: TFloatField;
  59. cdsFxBillsTotalPrice: TFloatField;
  60. cdsFxBillsDgnQuantity1: TFloatField;
  61. cdsFxBillsDgnQuantity2: TFloatField;
  62. cdsFxBillsDgnQuantity: TStringField;
  63. cdsFxBillsDgnPrice1: TFloatField;
  64. cdsFxBillsDgnPrice2: TFloatField;
  65. cdsFxBillsDgnPrice: TStringField;
  66. cdsFxBillsRatioPercent: TFloatField;
  67. cdsFxBillsAddRatioPercent: TFloatField;
  68. cdsFxBillsDealDgnQuantity1: TFloatField;
  69. cdsFxBillsDealDgnQuantity2: TFloatField;
  70. cdsFxBillsDealDgnQuantity: TStringField;
  71. cdsFxBillsDealDgnPrice1: TFloatField;
  72. cdsFxBillsDealDgnPrice2: TFloatField;
  73. cdsFxBillsDealDgnPrice: TStringField;
  74. cdsFxBillsCDgnQuantity1: TFloatField;
  75. cdsFxBillsCDgnQuantity2: TFloatField;
  76. cdsFxBillsCDgnQuantity: TStringField;
  77. cdsFxBillsCDgnPrice1: TFloatField;
  78. cdsFxBillsCDgnPrice2: TFloatField;
  79. cdsFxBillsCDgnPrice: TStringField;
  80. cdsFxBillsFinalDgnQuantity1: TFloatField;
  81. cdsFxBillsFinalDgnQuantity2: TFloatField;
  82. cdsFxBillsFinalDgnQuantity: TStringField;
  83. cdsFxBillsFinalDgnPrice1: TFloatField;
  84. cdsFxBillsFinalDgnPrice2: TFloatField;
  85. cdsFxBillsFinalDgnPrice: TStringField;
  86. // 决算05-2
  87. cdsGclBills: TClientDataSet;
  88. cdsGclBillsB_Code: TStringField;
  89. cdsGclBillsIndexCode: TStringField;
  90. cdsGclBillsName: TWideStringField;
  91. cdsGclBillsUnits: TWideStringField;
  92. cdsGclBillsPrice: TFloatField;
  93. cdsGclBillsAddDealQuantity: TFloatField;
  94. cdsGclBillsAddDealTotalPrice: TFloatField;
  95. cdsGclBillsAddQcQuantity: TFloatField;
  96. cdsGclBillsAddQcTotalPrice: TFloatField;
  97. cdsGclBillsAddPcQuantity: TFloatField;
  98. cdsGclBillsAddPcTotalPrice: TFloatField;
  99. cdsGclBillsAddGatherQuantity: TFloatField;
  100. cdsGclBillsAddGatherTotalPrice: TFloatField;
  101. cdsGclBillsPrecent: TFloatField;
  102. cdsGclBillsMemoStr: TWideStringField;
  103. // 决算04-1, 决算部颁12
  104. cdsProjectBills: TClientDataSet;
  105. cdsProjectBillsXiangCode: TStringField;
  106. cdsProjectBillsMuCode: TStringField;
  107. cdsProjectBillsJieCode: TStringField;
  108. cdsProjectBillsXiMuCode: TStringField;
  109. cdsProjectBillsCode: TStringField;
  110. cdsProjectBillsName: TWideStringField;
  111. cdsProjectBillsUnits: TWideStringField;
  112. cdsProjectBillsQuantity: TFloatField;
  113. cdsProjectBillsProjectID: TIntegerField;
  114. cdsProjectBillsTotalPrice: TFloatField;
  115. cdsProjectBillsP_Quantity: TFloatField;
  116. cdsProjectBillsP_TotalPrice: TFloatField;
  117. cdsProjectBillsEcoIndex: TFloatField;
  118. cdsProjectBillsPercent: TFloatField;
  119. cdsProjectBillsMemoStr: TWideStringField;
  120. cdsProjectBillsProjectName: TWideStringField;
  121. cdsProjectBillsSerialNo: TIntegerField;
  122. cdsProjectBillsB_Code: TStringField;
  123. cdsProjectBillsP_Price: TFloatField;
  124. // 决算02
  125. cdsEstimateBills: TClientDataSet;
  126. cdsEstimateBillsXiangCode: TStringField;
  127. cdsEstimateBillsMuCode: TStringField;
  128. cdsEstimateBillsJieCode: TStringField;
  129. cdsEstimateBillsXiMuCode: TStringField;
  130. cdsEstimateBillsCode: TStringField;
  131. cdsEstimateBillsName: TWideStringField;
  132. cdsEstimateBillsUnits: TWideStringField;
  133. cdsEstimateBillsPDQuantity: TFloatField;
  134. cdsEstimateBillsPDTotalPrice: TFloatField;
  135. cdsEstimateBillsCDDQuantity: TFloatField;
  136. cdsEstimateBillsCDDTotalPrice: TFloatField;
  137. cdsEstimateBillsAddDealQuantity: TFloatField;
  138. cdsEstimateBillsAddDealTotalPrice: TFloatField;
  139. cdsEstimateBillsAddCQuantity: TFloatField;
  140. cdsEstimateBillsAddCTotalPrice: TFloatField;
  141. cdsEstimateBillsAddGatherQuantity: TFloatField;
  142. cdsEstimateBillsAddGatherTotalPrice: TFloatField;
  143. cdsEstimateBillsQuantityAdjust: TFloatField;
  144. cdsEstimateBillsTotalPriceAdjust: TFloatField;
  145. cdsEstimateBillsMemoStr: TWideStringField;
  146. cdsEstimateBillsABQuantity: TFloatField; // 批准概算 - 数量
  147. cdsEstimateBillsABTotalPrice: TFloatField; // 批准概算 - 金额
  148. cdsEstimateBillsQuantity: TFloatField; // 0号台账 - 数量
  149. cdsEstimateBillsTotalPrice: TFloatField; // 0号台账 - 金额
  150. cdsEstimateBillsQuantityCompare1: TFloatField; // 数量比较 - (台账-批准)/批准
  151. cdsEstimateBillsTotalPriceCompare1: TFloatField; // 金额比较 - (台账-批准)/批准
  152. cdsEstimateBillsQuantityCompare2: TFloatField; // 数量比较 - (决算-批准)/批准
  153. cdsEstimateBillsQuantityCompare3: TFloatField; // 金额比较 - (决算-批准)/批准
  154. cdsEstimateBillsTotalPriceCompare2: TFloatField; // 数量比较 - (决算-合同)/合同
  155. cdsEstimateBillsTotalPriceCompare3: TFloatField; // 金额比较 - (决算-合同)/合同
  156. cdsEstimateBillsPDDgnQuantity: TStringField;
  157. cdsEstimateBillsPDDgnQuantity1: TFloatField;
  158. cdsEstimateBillsPDDgnQuantity2: TFloatField;
  159. cdsEstimateBillsCDDDgnQuantity: TStringField;
  160. cdsEstimateBillsCDDDgnQuantity1: TFloatField;
  161. cdsEstimateBillsCDDDgnQuantity2: TFloatField;
  162. cdsEstimateBillsDealDgnQuantity: TStringField;
  163. cdsEstimateBillsDealDgnQuantity1: TFloatField;
  164. cdsEstimateBillsDealDgnQuantity2: TFloatField;
  165. cdsEstimateBillsCDgnQuantity: TStringField;
  166. cdsEstimateBillsCDgnQuantity1: TFloatField;
  167. cdsEstimateBillsCDgnQuantity2: TFloatField;
  168. cdsEstimateBillsGatherDgnQuantity: TStringField;
  169. cdsEstimateBillsGatherDgnQuantity1: TFloatField;
  170. cdsEstimateBillsGatherDgnQuantity2: TFloatField;
  171. cdsEstimateBillsABDgnQuantity: TStringField;
  172. cdsEstimateBillsABDgnQuantity1: TFloatField;
  173. cdsEstimateBillsABDgnQuantity2: TFloatField;
  174. cdsEstimateBillsDgnQuantity: TStringField;
  175. cdsEstimateBillsDgnQuantity1: TFloatField;
  176. cdsEstimateBillsDgnQuantity2: TFloatField;
  177. cdsEstimateBillsDgnQuantityCompare1: TStringField;
  178. cdsEstimateBillsDgnQuantityCompare2: TStringField;
  179. cdsEstimateBillsDgnQuantityCompare3: TStringField;
  180. cdsEstimateBillsDgnQuantity1Compare1: TFloatField;
  181. cdsEstimateBillsDgnQuantity2Compare1: TFloatField;
  182. cdsEstimateBillsDgnQuantity1Compare2: TFloatField;
  183. cdsEstimateBillsDgnQuantity1Compare3: TFloatField;
  184. cdsEstimateBillsDgnQuantity2Compare2: TFloatField;
  185. cdsEstimateBillsDgnQuantity2Compare3: TFloatField;
  186. cdsEstimateBillsB_Code: TStringField;
  187. cdsEstimateBillsPrice: TFloatField;
  188. cdsEstimateBillsPDDgnPrice: TFloatField;
  189. cdsEstimateBillsCDDDgnPrice: TFloatField;
  190. cdsEstimateBillsABDgnPrice: TFloatField;
  191. cdsEstimateBillsFinalDgnQty: TStringField;
  192. cdsEstimateBillsFinalDgnQty1: TFloatField;
  193. cdsEstimateBillsFinalDgnQty2: TFloatField;
  194. // 决算部颁07, 11
  195. cdsProjectGclBills: TClientDataSet;
  196. cdsProjectGclBillsProjectID: TIntegerField;
  197. cdsProjectGclBillsProjectName: TWideStringField;
  198. cdsProjectGclBillsB_Code: TStringField;
  199. cdsProjectGclBillsIndexCode: TStringField;
  200. cdsProjectGclBillsName: TWideStringField;
  201. cdsProjectGclBillsUnits: TWideStringField;
  202. cdsProjectGclBillsQuantity: TFloatField;
  203. cdsProjectGclBillsPrice: TFloatField;
  204. cdsProjectGclBillsTotalPrice: TFloatField;
  205. cdsProjectGclBillsP_Price: TFloatField;
  206. cdsProjectGclBillsP_Quantity: TFloatField;
  207. cdsProjectGclBillsP_TotalPrice: TFloatField;
  208. cdsProjectGclBillsSerialNo: TIntegerField;
  209. cdsProjectGclBillsP_AddGatherQuantity: TFloatField;
  210. cdsProjectGclBillsP_AddGatherTotalPrice: TFloatField;
  211. cdsProjectGclBillsAddGatherQuantity: TFloatField;
  212. cdsProjectGclBillsAddGatherTotalPrice: TFloatField;
  213. // 决算部颁12
  214. cdsBGLFlow: TClientDataSet;
  215. cdsBGLFlowMergeBGLCode: TWideStringField;
  216. cdsBGLFlowBGLName: TWideStringField;
  217. cdsBGLFlowApprovalCode: TWideStringField;
  218. cdsBGLFlowSuggestion: TWideStringField;
  219. cdsBGLFlowBGReason: TWideStringField;
  220. cdsBGLFlowB_Code: TStringField;
  221. cdsBGLFlowName: TWideStringField;
  222. cdsBGLFlowUnits: TWideStringField;
  223. cdsBGLFlowQuantity: TFloatField;
  224. cdsBGLFlowPrice: TFloatField;
  225. cdsBGLFlowTotalPrice: TFloatField;
  226. cdsBGLFlowBGTotalPrice: TFloatField;
  227. private
  228. FCacheTree: TReportCacheTree;
  229. FGclList: TGclGatherList;
  230. FFixedIDList: TFixedIDBillsList;
  231. FProjectData: TProjectData;
  232. FProjectName: string;
  233. FGatherType: TbgType;
  234. FSerialNo: Integer;
  235. procedure OpenProjectData(AProject: TSelectProject; AProjectIndex: Integer);
  236. procedure FreeProjectData;
  237. function GetDgnQuantity(ANum1, ANum2: Double): string;
  238. function GetDgnPrice(ATotalPrice, ADgnQuantity: Double): Double;
  239. function GetCompare(ANum1, ANum2: Double): Double;
  240. {汇总树结构}
  241. function AddBillsNode(ANode: TsdIDTreeNode; AParent:
  242. TReportCacheNode; AProjectIndex: Integer;
  243. ASelectProject: TSelectProject): TReportCacheNode;
  244. // 递归模式(当前节点、子节点、后兄弟节点)
  245. procedure AddBills(ANode: TsdIDTreeNode; AParent: TReportCacheNode;
  246. AProjectIndex: Integer; ASelectProject: TSelectProject);
  247. // 遍历模式(当前节点、子节点)
  248. procedure AddBillsList(ANode: TsdIDTreeNode; AParent: TReportCacheNode;
  249. AProjectIndex: Integer; ASelectProject: TSelectProject);
  250. {汇总工程量清单}
  251. procedure FilterBillsNode(ANode: TsdIDTreeNode; AProjectIndex: Integer);
  252. procedure FilterBills(ANode: TsdIDTreeNode; AProjectIndex: Integer);
  253. {汇总固定ID项}
  254. procedure FilterFixedIDBills(ATree: TsdIDTree; AProjectIndex: Integer);
  255. procedure FilterSettlement(AProjectData: TProjectData; AProjectIndex: Integer);
  256. {写入流水数据}
  257. procedure WriteBGLFlowData(AProjectData: TProjectData);
  258. procedure WriteFlowData(AProjectData: TProjectData);
  259. procedure GatherProject(AProject: TSelectProject; AProjectIndex: Integer);
  260. procedure CalculateGatherData;
  261. procedure CalculateRatioPercent; // 计算各项费用所占比例,金额/总造价
  262. procedure WriteGatherCacheNode(const AGatherName: string);
  263. procedure WriteNode(ANode: TReportCacheNode);
  264. procedure WriteBillsData;
  265. procedure WriteGclNode;
  266. procedure WriteProjectsData;
  267. procedure WriteEstimateGatherNode;
  268. procedure WriteENodeData(ANode: TReportCacheNode);
  269. procedure ReWriteENodeDataAsGather(ANode: TReportCacheNode; AName: string);
  270. procedure WriteEstimateNode(ANode: TReportCacheNode);
  271. procedure WriteEstimateData;
  272. procedure WriteProjectsGclData;
  273. procedure WriteData;
  274. procedure BeforeGather(AProjects: TList);
  275. procedure AfterGather;
  276. public
  277. function AssignData(AProjects: TList): TDataSet;
  278. property GatherType: TbgType read FGatherType write FGatherType;
  279. end;
  280. implementation
  281. uses
  282. Globals, UtilMethods, Math, BGLDm;
  283. {$R *.dfm}
  284. { TrmBillsGatherData }
  285. procedure TrmBillsGatherData.AddBills(ANode: TsdIDTreeNode;
  286. AParent: TReportCacheNode; AProjectIndex: Integer; ASelectProject: TSelectProject);
  287. var
  288. ACur: TReportCacheNode;
  289. begin
  290. if not Assigned(ANode) then Exit;
  291. // 按设置的层次汇总(Level从0开始取值)
  292. case ReportConfig.GatherLevel of
  293. // 项
  294. 0: if ANode.Level > 1 then Exit;
  295. // 目
  296. 1: if ANode.Level > 2 then Exit;
  297. // 节
  298. 2: if ANode.Level > 3 then Exit;
  299. // 细目
  300. 3: if ANode.Level > 4 then Exit;
  301. // 项目节
  302. 4: if ANode.Rec.ValueByName('B_Code').AsString <> '' then Exit;
  303. end;
  304. if GatherType in [bgtXmj, bgtMultiXmj, bgtEstimate, bgtEstimate1, bgtFinal08, bgtFinal09] then
  305. if ANode.Rec.ValueByName('B_Code').AsString <> '' then Exit; // 仅汇总项目节
  306. ACur := AddBillsNode(ANode, AParent, AProjectIndex, ASelectProject);
  307. AddBills(ANode.FirstChild, ACur, AProjectIndex, ASelectProject);
  308. AddBills(ANode.NextSibling, AParent, AProjectIndex, ASelectProject);
  309. end;
  310. function TrmBillsGatherData.AddBillsNode(ANode: TsdIDTreeNode;
  311. AParent: TReportCacheNode; AProjectIndex: Integer;
  312. ASelectProject: TSelectProject): TReportCacheNode;
  313. var
  314. iGatherCompare: Integer;
  315. ANextSibling: TReportCacheNode;
  316. begin
  317. with ANode.Rec do
  318. begin
  319. if ANode.Rec.ValueByName('B_Code').AsString <> '' then
  320. iGatherCompare := ReportConfig.GclCompare
  321. else
  322. iGatherCompare := ReportConfig.XmjCompare;
  323. case iGatherCompare of
  324. // 按编号
  325. 0: if (ValueByName('Code').asString <> '') or (ValueByName('B_Code').asString <> '') then
  326. Result := FCacheTree.FindNode(AParent,
  327. ValueByName('Code').AsString, ValueByName('B_Code').AsString)
  328. else
  329. Result := FCacheTree.FindNode(AParent, ValueByName('Name').AsString);
  330. // 按名称
  331. 1: Result := FCacheTree.FindNode(AParent, ValueByName('Name').AsString);
  332. // 按编号+名称
  333. 2: Result := FCacheTree.FindNode(AParent, ValueByName('Code').AsString,
  334. ValueByName('B_Code').AsString, ValueByName('Name').AsString);
  335. end;
  336. if not Assigned(Result) then
  337. begin
  338. ANextSibling := FCacheTree.FindNextSibling(AParent,
  339. ValueByName('Code').AsString, ValueByName('B_Code').AsString);
  340. Result := FCacheTree.AddNode(AParent, ANextSibling);
  341. Result.Code := ValueByName('Code').AsString;
  342. Result.B_Code := ValueByName('B_Code').AsString;
  343. Result.Name := ValueByName('Name').AsString;
  344. Result.Units := ValueByName('Units').AsString;
  345. end;
  346. if (GatherType in [bgtEstimate, bgtG_Final06_1]) and (ASelectProject.IsPD or ASelectProject.IsCDD) then
  347. begin
  348. if ASelectProject.IsPD then
  349. begin
  350. Result.PDQuantity := ValueByName('Quantity').AsFloat;
  351. Result.PDTotalPrice := ValueByName('TotalPrice').AsFloat;
  352. Result.PDDesignQuantity1 := ValueByName('DgnQuantity1').AsFloat;
  353. Result.PDDesignQuantity2 := ValueByName('DgnQuantity2').AsFloat;
  354. Result.PDDesignPrice := ValueByName('DgnPrice').AsFloat;
  355. end
  356. else if ASelectProject.IsCDD then
  357. begin
  358. Result.CDDQuantity := ValueByName('Quantity').AsFloat;
  359. Result.CDDTotalPrice := ValueByName('TotalPrice').AsFloat;
  360. Result.CDDDesignQuantity1 := ValueByName('DgnQuantity1').AsFloat;
  361. Result.CDDDesignQuantity2 := ValueByName('DgnQuantity2').AsFloat;
  362. Result.CDDDesignPrice := ValueByName('DgnPrice').AsFloat;
  363. end
  364. end
  365. else if (GatherType = bgtEstimate1) and ASelectProject.IsAB then
  366. begin
  367. Result.ABQuantity := ValueByName('Quantity').AsFloat;
  368. Result.ABTotalPrice := ValueByName('TotalPrice').AsFloat;
  369. Result.ABDesignQuantity1 := ValueByName('DgnQuantity1').AsFloat;
  370. Result.ABDesignQuantity2 := ValueByName('DgnQuantity2').AsFloat;
  371. Result.ABDesignPrice := ValueByName('DgnPrice').AsFloat;
  372. end
  373. else
  374. begin
  375. Result.Price := ValueByName('Price').AsFloat;
  376. // 汇总的经济指标只能在汇总后计算得到
  377. Result.Quantity := Result.Quantity + ValueByName('Quantity').AsFloat;
  378. Result.TotalPrice := Result.TotalPrice + ValueByName('TotalPrice').AsFloat;
  379. Result.DesignQuantity1 := Result.DesignQuantity1 + ValueByName('DgnQuantity1').AsFloat;
  380. Result.DesignQuantity2 := Result.DesignQuantity2 + ValueByName('DgnQuantity2').AsFloat;
  381. Result.AddDealQuantity := Result.AddDealQuantity + ValueByName('AddDealQuantity').AsFloat;
  382. Result.AddDealTotalPrice := Result.AddDealTotalPrice + ValueByName('AddDealTotalPrice').AsFloat;
  383. Result.AddQcQuantity := Result.AddQcQuantity + ValueByName('AddQcQuantity').AsFloat;
  384. Result.AddQcTotalPrice := Result.AddQcTotalPrice + ValueByName('AddQcTotalPrice').AsFloat;
  385. Result.AddPcQuantity := Result.AddPcQuantity + ValueByName('AddPcQuantity').AsFloat;
  386. Result.AddPcTotalPrice := Result.AddPcTotalPrice + ValueByName('AddPcTotalPrice').AsFloat;
  387. Result.DealDesignQuantity1 := Result.DealDesignQuantity1 + ValueByName('DealDgnQuantity1').AsFloat;
  388. Result.DealDesignQuantity2 := Result.DealDesignQuantity2 + ValueByName('DealDgnQuantity2').AsFloat;
  389. Result.CDesignQuantity1 := Result.CDesignQuantity1 + ValueByName('CDgnQuantity1').AsFloat;
  390. Result.CDesignQuantity2 := Result.CDesignQuantity2 + ValueByName('CDgnQuantity2').AsFloat;
  391. Result.P_Price[AProjectIndex] := ValueByName('Price').AsFloat;
  392. Result.P_Quantity[AProjectIndex] := ValueByName('AddGatherQuantity').AsFloat;
  393. Result.P_TotalPrice[AProjectIndex] := ValueByName('AddGatherTotalPrice').AsFloat;
  394. end;
  395. end;
  396. end;
  397. procedure TrmBillsGatherData.AfterGather;
  398. begin
  399. cdsProjectBills.EnableControls;
  400. FGclList.Free;
  401. cdsGclBills.EnableControls;
  402. FCacheTree.Free;
  403. cdsFxBills.EnableControls;
  404. cdsEstimateBills.EnableControls;
  405. FFixedIDList.Free;
  406. cdsProjectGclBills.EnableControls;
  407. cdsBGLFlow.EnableControls;
  408. end;
  409. function TrmBillsGatherData.AssignData(AProjects: TList): TDataSet;
  410. var
  411. iProject: Integer;
  412. SelectProject: TSelectProject;
  413. begin
  414. BeforeGather(AProjects);
  415. try
  416. for iProject := 0 to AProjects.Count - 1 do
  417. GatherProject(TSelectProject(AProjects.Items[iProject]), iProject);
  418. CalculateGatherData;
  419. CalculateRatioPercent;
  420. WriteData;
  421. finally
  422. case GatherType of
  423. bgtFx, bgtXmj, bgtFinal08, bgtFinal09, bgtFinal17, bgtFinal18, bgtG_Final04:
  424. Result := cdsFxBills;
  425. bgtGcl: Result := cdsGclBills;
  426. bgtMultiXmj, bgtFinal16: Result := cdsProjectBills;
  427. bgtEstimate, bgtEstimate1, bgtG_Final06_1: Result := cdsEstimateBills;
  428. bgtFinal07, bgtFinal11, bgtFinal19: Result := cdsProjectGclBills;
  429. bgtFinal12: Result := cdsBGLFlow;
  430. end;
  431. AfterGather;
  432. end;
  433. end;
  434. procedure TrmBillsGatherData.BeforeGather(AProjects: TList);
  435. begin
  436. cdsFxBills.DisableControls;
  437. cdsFxBills.Active := True;
  438. cdsFxBills.EmptyDataSet;
  439. FCacheTree := TReportCacheTree.Create(AProjects.Count);
  440. cdsGclBills.DisableControls;
  441. cdsGclBills.Active := True;
  442. cdsGclBills.EmptyDataSet;
  443. if GatherType in [bgtFinal07, bgtFinal11, bgtFinal19] then
  444. FGclList := TGclGatherList.Create(AProjects.Count, False)
  445. else
  446. FGclList := TGclGatherList.Create(AProjects.Count);
  447. cdsProjectBills.DisableControls;
  448. cdsProjectBills.Active := True;
  449. cdsProjectBills.EmptyDataSet;
  450. cdsEstimateBills.DisableControls;
  451. cdsEstimateBills.Active := True;
  452. cdsEstimateBills.EmptyDataSet;
  453. cdsProjectGclBills.DisableControls;
  454. cdsProjectGclBills.Active := True;
  455. cdsProjectGclBills.EmptyDataSet;
  456. FFixedIDList := TFixedIDBillsList.Create(AProjects.Count);
  457. cdsBGLFlow.DisableControls;
  458. cdsBGLFlow.Active := True;
  459. cdsBGLFlow.EmptyDataSet;
  460. end;
  461. procedure TrmBillsGatherData.FilterBills(ANode: TsdIDTreeNode;
  462. AProjectIndex: Integer);
  463. begin
  464. if not Assigned(ANode) then Exit;
  465. if (not ANode.HasChildren) and (ANode.Rec.ValueByName('B_Code').AsString <> '') then
  466. FilterBillsNode(ANode, AProjectIndex);
  467. FilterBills(ANode.FirstChild, AProjectIndex);
  468. FilterBills(ANode.NextSibling, AProjectIndex);
  469. end;
  470. procedure TrmBillsGatherData.FilterBillsNode(ANode: TsdIDTreeNode;
  471. AProjectIndex: Integer);
  472. function CanGatherNode: Boolean;
  473. begin
  474. case GatherType of
  475. bgtFinal11: Result := ANode.Rec.ValueByName('TotalPrice').AsFloat <> 0;
  476. else Result := True;
  477. end;
  478. end;
  479. var
  480. GclNode: TGclGatherNode;
  481. begin
  482. if not Assigned(ANode) or not CanGatherNode then Exit;
  483. GclNode := FGclList.GetGclGatherNode(ANode.Rec);
  484. with ANode.Rec do
  485. begin
  486. GclNode.Quantity := GclNode.Quantity + ValueByName('Quantity').AsFloat;
  487. GclNode.TotalPrice := GclNode.TotalPrice + ValueByName('TotalPrice').AsFloat;
  488. GclNode.AddDealQuantity := GclNode.AddDealQuantity + ValueByName('AddDealQuantity').AsFloat;
  489. GclNode.AddDealTotalPrice := GclNode.AddDealTotalPrice + ValueByName('AddDealTotalPrice').AsFloat;
  490. GclNode.AddQcQuantity := GclNode.AddQcQuantity + ValueByName('AddQcQuantity').AsFloat;
  491. GclNode.AddQcTotalPrice := GclNode.AddQcTotalPrice + ValueByName('AddQcTotalPrice').AsFloat;
  492. GclNode.AddPcQuantity := GclNode.AddPcQuantity + ValueByName('AddPcQuantity').AsFloat;
  493. GclNode.AddPcTotalPrice := GclNode.AddPcTotalPrice + ValueByName('AddPcTotalPrice').AsFloat;
  494. GclNode.P_Price[AProjectIndex] := ValueByName('Price').AsFloat;
  495. GclNode.P_Quantity[AProjectIndex] := GclNode.P_Quantity[AProjectIndex] + ValueByName('Quantity').AsFloat;
  496. GclNode.P_TotalPrice[AProjectIndex] := GclNode.P_TotalPrice[AProjectIndex] + ValueByName('TotalPrice').AsFloat;
  497. GclNode.P_AddGatherQuantity[AProjectIndex] :=
  498. GclNode.P_AddGatherQuantity[AProjectIndex] + ValueByName('AddGatherQuantity').AsFloat;
  499. GclNode.P_AddGatherTotalPrice[AProjectIndex] :=
  500. GclNode.P_AddGatherTotalPrice[AProjectIndex] + ValueByName('AddGatherTotalPrice').AsFloat;
  501. end;
  502. end;
  503. procedure TrmBillsGatherData.FreeProjectData;
  504. begin
  505. if not Assigned(OpenProjectManager.FindProjectData(FProjectData.ProjectID)) then
  506. FProjectData.Free;
  507. end;
  508. procedure TrmBillsGatherData.GatherProject(AProject: TSelectProject;
  509. AProjectIndex: Integer);
  510. begin
  511. OpenProjectData(AProject, AProjectIndex);
  512. try
  513. case GatherType of
  514. bgtFinal08: // 08表 取第二部分下所有项目节
  515. AddBills(FProjectData.BillsCompileData.BillsCompileTree.FindNode(2).FirstChild, nil, AProjectIndex, AProject);
  516. bgtFinal09: // 09表 取第三部分及其后所有项目节
  517. AddBills(FProjectData.BillsCompileData.BillsCompileTree.FindNode(3), nil, AProjectIndex, AProject);
  518. bgtGcl, bgtFinal07, bgtFinal11, bgtFinal19: // 汇总工程量清单
  519. FilterBills(FProjectData.BillsCompileData.BillsCompileTree.FirstNode, AProjectIndex);
  520. bgtFinal12: // 不做数据汇总,直接流水式写入数据
  521. WriteFlowData(FProjectData);
  522. bgtFinal16: // 16表 仅汇总计日工及其子节点
  523. AddBillsList(FProjectData.BillsCompileData.BillsCompileTree.FindNode(40), nil, AProjectIndex, AProject);
  524. bgtFinal17: // 17表 仅汇总收尾工程及其子节点
  525. AddBillsList(FProjectData.BillsCompileData.BillsCompileTree.FindNode(47), nil, AProjectIndex, AProject);
  526. bgtFinal18: // 18表 仅汇总报废工程及其子节点
  527. AddBillsList(FProjectData.BillsCompileData.BillsCompileTree.FindNode(48), nil, AProjectIndex, AProject);
  528. bgtG_Final06_1: // 粤竣06-1表 仅汇总土地及其子节点
  529. AddBillsList(FProjectData.BillsCompileData.BillsCompileTree.FindNode(21), nil, AProjectIndex, AProject);
  530. else // 标准汇总方式,分项清单
  531. AddBills(FProjectData.BillsCompileData.BillsCompileTree.FirstNode, nil, AProjectIndex, AProject)
  532. end;
  533. if GatherType in [bgtFinal07, bgtFinal11, bgtFinal19] then
  534. FilterFixedIDBills(FProjectData.BillsCompileData.BillsCompileTree, AProjectIndex);
  535. if GatherType = bgtFinal11 then
  536. FilterSettlement(FProjectData, AProjectIndex);
  537. finally
  538. FreeProjectData;
  539. end;
  540. end;
  541. procedure TrmBillsGatherData.OpenProjectData(AProject: TSelectProject;
  542. AProjectIndex: Integer);
  543. var
  544. Rec: TsdDataRecord;
  545. begin
  546. FProjectData := OpenProjectManager.FindProjectData(AProject.ProjectID);
  547. Rec := ProjectManager.sddProjectsInfo.FindKey('idxID', AProject.ProjectID);
  548. if not Assigned(FProjectData) then
  549. begin
  550. FProjectData := TProjectData.Create;
  551. FProjectData.OpenForReport(GetMyProjectsFilePath + Rec.ValueByName('FileName').AsString);
  552. end;
  553. FProjectName := Rec.ValueByName('Name').AsString;
  554. FCacheTree.ProjectName[AProjectIndex] := Rec.ValueByName('Name').AsString;
  555. FGclList.ProjectName[AProjectIndex] := Rec.ValueByName('Name').AsString;
  556. end;
  557. procedure TrmBillsGatherData.WriteData;
  558. begin
  559. case GatherType of
  560. bgtFx, bgtXmj, bgtFinal08, bgtFinal09, bgtFinal17, bgtFinal18, bgtG_Final04:
  561. WriteBillsData;
  562. bgtGcl:
  563. WriteGclNode;
  564. bgtMultiXmj, bgtFinal16:
  565. WriteProjectsData;
  566. bgtEstimate, bgtEstimate1, bgtG_Final06_1:
  567. WriteEstimateData;
  568. bgtFinal07, bgtFinal11, bgtFinal19: // 07&11特别的,其中还写入了部分固定ID节点 !!丧心病狂的报表!!
  569. WriteProjectsGclData;
  570. end;
  571. end;
  572. procedure TrmBillsGatherData.WriteNode(ANode: TReportCacheNode);
  573. begin
  574. if not Assigned(ANode) then Exit;
  575. cdsFxBills.Append;
  576. cdsFxBillsXiangCode.AsString := ANode.XiangCode;
  577. cdsFxBillsMuCode.AsString := ANode.MuCode;
  578. cdsFxBillsJieCode.AsString := ANode.JieCode;
  579. cdsFxBillsXiMuCode.AsString := ANode.XiMuCode;
  580. cdsFxBillsCode.AsString := ANode.Code;
  581. cdsFxBillsB_Code.AsString := ANode.B_Code;
  582. cdsFxBillsName.AsString := ANode.Name;
  583. cdsFxBillsUnits.AsString := ANode.Units;
  584. cdsFxBillsPrice.AsFloat := ANode.Price;
  585. cdsFxBillsAddDealQuantity.AsFloat := ANode.AddDealQuantity;
  586. cdsFxBillsAddDealTotalPrice.AsFloat := ANode.AddDealTotalPrice;
  587. cdsFxBillsAddQcQuantity.AsFloat := ANode.AddQcQuantity;
  588. cdsFxBillsAddQcTotalPrice.AsFloat := ANode.AddQcTotalPrice;
  589. cdsFxBillsAddPcQuantity.AsFloat := ANode.AddPcQuantity;
  590. cdsFxBillsAddPcTotalPrice.AsFloat := ANode.AddPcTotalPrice;
  591. cdsFxBillsAddGatherQuantity.AsFloat := ANode.AddDealQuantity + ANode.AddQcQuantity;
  592. cdsFxBillsAddGatherTotalPrice.AsFloat := ANode.AddDealTotalPrice +
  593. ANode.AddQcTotalPrice + ANode.AddPcTotalPrice;
  594. cdsFxBillsAddRatioPercent.AsFloat := ANode.AddRatioPercent;
  595. cdsFxBillsQuantity.AsFloat := ANode.Quantity;
  596. cdsFxBillsTotalPrice.AsFloat := ANode.TotalPrice;
  597. cdsFxBillsRatioPercent.AsFloat := ANode.RatioPercent;
  598. cdsFxBillsDgnQuantity1.AsFloat := ANode.DesignQuantity1;
  599. cdsFxBillsDgnQuantity2.AsFloat := ANode.DesignQuantity2;
  600. cdsFxBillsDgnQuantity.AsString := GetDgnQuantity(ANode.DesignQuantity1, ANode.DesignQuantity2);
  601. if ANode.DesignQuantity1 <> 0 then
  602. cdsFxBillsDgnPrice1.AsFloat := PriceRoundTo(ANode.TotalPrice/ANode.DesignQuantity1);
  603. if ANode.DesignQuantity2 <> 0 then
  604. cdsFxBillsDgnPrice2.AsFloat := PriceRoundTo(ANode.TotalPrice/ANode.DesignQuantity2);
  605. if cdsFxBillsDgnPrice1.AsFloat <> 0 then
  606. cdsFxBillsDgnPrice.AsString := GetDgnQuantity(cdsFxBillsDgnPrice1.AsFloat, cdsFxBillsDgnPrice2.AsFloat);
  607. cdsFxBillsDealDgnQuantity1.AsFloat := ANode.DealDesignQuantity1;
  608. cdsFxBillsDealDgnQuantity2.AsFloat := ANode.DealDesignQuantity2;
  609. cdsFxBillsDealDgnQuantity.AsString := GetDgnQuantity(ANode.DealDesignQuantity1, ANode.DesignQuantity2);
  610. cdsFxBillsDealDgnPrice1.AsFloat := GetDgnPrice(cdsFxBillsAddDealTotalPrice.AsFloat, cdsFxBillsDealDgnQuantity1.AsFloat);
  611. cdsFxBillsDealDgnPrice2.AsFloat := GetDgnPrice(cdsFxBillsAddDealTotalPrice.AsFloat, cdsFxBillsDealDgnQuantity2.AsFloat);
  612. cdsFxBillsDealDgnPrice.AsString := GetDgnQuantity(cdsFxBillsDealDgnPrice1.AsFloat, cdsFxBillsDealDgnPrice2.AsFloat);
  613. cdsFxBillsCDgnQuantity1.AsFloat := ANode.CDesignQuantity1;
  614. cdsFxBillsCDgnQuantity2.AsFloat := ANode.CDesignQuantity2;
  615. cdsFxBillsCDgnQuantity.AsString := GetDgnQuantity(ANode.CDesignQuantity1, ANode.CDesignQuantity2);
  616. cdsFxBillsCDgnPrice1.AsFloat := GetDgnPrice(cdsFxBillsAddQcTotalPrice.AsFloat, cdsFxBillsCDgnQuantity1.AsFloat);
  617. cdsFxBillsCDgnPrice2.AsFloat := GetDgnPrice(cdsFxBillsAddQcTotalPrice.AsFloat, cdsFxBillsCDgnQuantity2.AsFloat);
  618. cdsFxBillsCDgnPrice.AsString := GetDgnQuantity(cdsFxBillsCDgnPrice1.AsFloat, cdsFxBillsCDgnPrice2.AsFloat);
  619. cdsFxBillsFinalDgnQuantity1.AsFloat := ANode.DealDesignQuantity1 + ANode.CDesignQuantity1;
  620. cdsFxBillsFinalDgnQuantity2.AsFloat := ANode.DealDesignQuantity2 + ANode.CDesignQuantity2;
  621. cdsFxBillsFinalDgnQuantity.AsString := GetDgnQuantity(cdsFxBillsFinalDgnQuantity1.AsFloat, cdsFxBillsFinalDgnQuantity2.AsFloat);
  622. cdsFxBillsFinalDgnPrice1.AsFloat := GetDgnPrice(cdsFxBillsAddGatherTotalPrice.AsFloat, cdsFxBillsFinalDgnQuantity1.AsFloat);
  623. cdsFxBillsFinalDgnPrice2.AsFloat := GetDgnPrice(cdsFxBillsAddGatherTotalPrice.AsFloat, cdsFxBillsFinalDgnQuantity2.AsFloat);
  624. cdsFxBillsFinalDgnPrice.AsString := GetDgnQuantity(cdsFxBillsFinalDgnPrice1.AsFloat, cdsFxBillsFinalDgnPrice2.AsFloat);
  625. cdsFxBills.Post;
  626. WriteNode(TReportCacheNode(ANode.FirstChild));
  627. WriteNode(TReportCacheNode(ANode.NextSibling));
  628. end;
  629. procedure TrmBillsGatherData.WriteGclNode;
  630. var
  631. i: Integer;
  632. GclNode: TGclGatherNode;
  633. begin
  634. for i := 0 to FGclList.Count - 1 do
  635. begin
  636. GclNode := FGclList.Node[i];
  637. cdsGclBills.Append;
  638. cdsGclBillsB_Code.AsString := GclNode.B_Code;
  639. cdsGclBillsIndexCode.AsString := GclNode.IndexCode;
  640. cdsGclBillsName.AsString := GclNode.Name;
  641. cdsGclBillsUnits.AsString := GclNode.Units;
  642. cdsGclBillsPrice.AsFloat := GclNode.Price;
  643. cdsGclBillsAddDealQuantity.AsFloat := GclNode.AddDealQuantity;
  644. cdsGclBillsAddDealTotalPrice.AsFloat := GclNode.AddDealTotalPrice;
  645. cdsGclBillsAddQcQuantity.AsFloat := GclNode.AddQcQuantity;
  646. cdsGclBillsAddQcTotalPrice.AsFloat := GclNode.AddQcTotalPrice;
  647. cdsGclBillsAddPcQuantity.AsFloat := GclNode.AddPcQuantity;
  648. cdsGclBillsAddPcTotalPrice.AsFloat := GclNode.AddPcTotalPrice;
  649. cdsGclBillsAddGatherQuantity.AsFloat := GclNode.AddDealQuantity + GclNode.AddQcQuantity;
  650. cdsGclBillsAddDealTotalPrice.AsFloat := GclNode.AddDealTotalPrice +
  651. GclNode.AddQcTotalPrice + GclNode.AddPcTotalPrice;
  652. cdsGclBillsPrecent.AsFloat := 0;
  653. cdsGclBillsMemoStr.AsString := '';
  654. cdsGclBills.Post;
  655. end;
  656. end;
  657. procedure TrmBillsGatherData.WriteProjectsData;
  658. procedure WriteProjectData(ANode: TReportCacheNode; AProjectIndex: Integer);
  659. begin
  660. if not Assigned(ANode) then Exit;
  661. cdsProjectBills.Append;
  662. cdsProjectBillsProjectID.AsInteger := AProjectIndex;
  663. cdsProjectBillsProjectName.AsString := FCacheTree.ProjectName[AProjectIndex];
  664. cdsProjectBillsXiangCode.AsString := ANode.XiangCode;
  665. cdsProjectBillsMuCode.AsString := ANode.MuCode;
  666. cdsProjectBillsJieCode.AsString := ANode.JieCode;
  667. cdsProjectBillsXiMuCode.AsString := ANode.XiMuCode;
  668. cdsProjectBillsCode.AsString := ANode.Code;
  669. cdsProjectBillsB_Code.AsString := ANode.B_Code;
  670. cdsProjectBillsName.AsString := ANode.Name;
  671. cdsProjectBillsUnits.AsString := ANode.Units;
  672. // 此处数量与金额特指所有项目的累计完成数量与金额汇总。
  673. cdsProjectBillsQuantity.AsFloat := ANode.AddDealQuantity + ANode.AddQcQuantity;
  674. cdsProjectBillsTotalPrice.AsFloat := ANode.AddDealTotalPrice + ANode.AddQcTotalPrice + ANode.AddPcTotalPrice;
  675. cdsProjectBillsP_Quantity.AsFloat := ANode.P_Quantity[AProjectIndex];
  676. cdsProjectBillsP_TotalPrice.AsFloat := ANode.P_TotalPrice[AProjectIndex];
  677. cdsProjectBillsP_Price.AsFloat := ANode.P_Price[AProjectIndex];
  678. cdsProjectBillsSerialNo.AsInteger := FSerialNo;
  679. cdsProjectBills.Post;
  680. Inc(FSerialNo);
  681. WriteProjectData(TReportCacheNode(ANode.FirstChild), AProjectIndex);
  682. WriteProjectData(TReportCacheNode(ANode.NextSibling), AProjectIndex);
  683. end;
  684. procedure WriteProjectGatherData(AProjectIndex: Integer);
  685. begin
  686. cdsProjectBills.Append;
  687. cdsProjectBillsProjectID.AsInteger := AProjectIndex;
  688. cdsProjectBillsProjectName.AsString := FCacheTree.ProjectName[AProjectIndex];
  689. cdsProjectBillsName.AsString := '金额合计';
  690. with FCacheTree.GatherCacheNode do
  691. begin
  692. cdsProjectBillsTotalPrice.AsFloat := AddDealTotalPrice + AddQcTotalPrice + AddPcTotalPrice;
  693. cdsProjectBillsP_TotalPrice.AsFloat := P_TotalPrice[AProjectIndex];
  694. end;
  695. cdsProjectBillsSerialNo.AsInteger := FSerialNo;
  696. cdsProjectBills.Post;
  697. Inc(FSerialNo);
  698. cdsProjectBills.Append;
  699. cdsProjectBillsProjectID.AsInteger := AProjectIndex;
  700. cdsProjectBillsProjectName.AsString := FCacheTree.ProjectName[AProjectIndex];
  701. cdsProjectBillsName.AsString := Format('金额总计:%f', [FCacheTree.GatherCacheNode.GatherP_TotalPrice]);
  702. cdsProjectBillsSerialNo.AsInteger := FSerialNo;
  703. cdsProjectBills.Post;
  704. Inc(FSerialNo);
  705. end;
  706. var
  707. i: Integer;
  708. begin
  709. for i := 0 to FCacheTree.ProjectCount - 1 do
  710. begin
  711. FSerialNo := 0;
  712. WriteProjectData(TReportCacheNode(FCacheTree.FirstNode), i);
  713. if GatherType = bgtFinal16 then
  714. WriteProjectGatherData(i);
  715. end;
  716. end;
  717. procedure TrmBillsGatherData.WriteEstimateNode(ANode: TReportCacheNode);
  718. begin
  719. if not Assigned(ANode) then Exit;
  720. WriteENodeData(ANode);
  721. WriteEstimateNode(TReportCacheNode(ANode.FirstChild));
  722. WriteEstimateNode(TReportCacheNode(ANode.NextSibling));
  723. end;
  724. procedure TrmBillsGatherData.FilterFixedIDBills(ATree: TsdIDTree;
  725. AProjectIndex: Integer);
  726. var
  727. iIndex: Integer;
  728. stnNode: TsdIDTreeNode;
  729. FixedIDNode: TFixedIDBillsNode;
  730. begin
  731. for iIndex := 0 to ATree.Count - 1 do
  732. begin
  733. stnNode := ATree.Items[iIndex];
  734. if stnNode.ID >= 100 then Continue;
  735. FixedIDNode := FFixedIDList.GetFixedIDBillsNode(stnNode.ID);
  736. FixedIDNode.TotalPrice := FixedIDNode.TotalPrice
  737. + stnNode.Rec.ValueByName('TotalPrice').AsFloat;
  738. FixedIDNode.TotalPrice :=
  739. + stnNode.Rec.ValueByName('TotalPrice').AsFloat;
  740. FixedIDNode.AddGatherTotalPrice := FixedIDNode.AddGatherTotalPrice
  741. + stnNode.Rec.ValueByName('AddGatherTotalPrice').AsFloat;
  742. FixedIDNode.P_AddGatherTotalPrice[AProjectIndex] :=
  743. stnNode.Rec.ValueByName('AddGatherTotalPrice').AsFloat;
  744. end;
  745. end;
  746. procedure TrmBillsGatherData.WriteProjectsGclData;
  747. procedure WriteProjectGclData(AProjectIndex: Integer);
  748. var
  749. i: Integer;
  750. GclNode: TGclGatherNode;
  751. begin
  752. for i := 0 to FGclList.Count - 1 do
  753. begin
  754. GclNode := FGclList.Node[i];
  755. cdsProjectGclBills.Append;
  756. cdsProjectGclBillsProjectID.AsInteger := AProjectIndex;
  757. cdsProjectGclBillsProjectName.AsString := FGclList.ProjectName[AProjectIndex];
  758. cdsProjectGclBillsB_Code.AsString := GclNode.B_Code;
  759. cdsProjectGclBillsIndexCode.AsString := GclNode.IndexCode;
  760. cdsProjectGclBillsName.AsString := GclNode.Name;
  761. cdsProjectGclBillsUnits.AsString := GclNode.Units;
  762. cdsProjectGclBillsQuantity.AsFloat := GclNode.Quantity;
  763. cdsProjectGclBillsTotalPrice.AsFloat := GclNode.TotalPrice;
  764. // Price须填写合计平均单价
  765. if cdsProjectGclBillsQuantity.AsFloat <> 0 then
  766. cdsProjectGclBillsPrice.AsFloat := cdsProjectGclBillsTotalPrice.AsFloat/cdsProjectGclBillsQuantity.AsFloat;
  767. cdsProjectGclBillsP_Price.AsFloat := GclNode.P_Price[AProjectIndex];
  768. cdsProjectGclBillsP_Quantity.AsFloat := GclNode.P_Quantity[AProjectIndex];
  769. cdsProjectGclBillsP_TotalPrice.AsFloat := GclNode.P_TotalPrice[AProjectIndex];
  770. cdsProjectGclBillsP_AddGatherQuantity.AsFloat := GclNode.P_AddGatherQuantity[AProjectIndex];
  771. cdsProjectGclBillsP_AddGatherTotalPrice.AsFloat := GclNode.P_AddGatherTotalPrice[AProjectIndex];
  772. cdsProjectGclBillsAddGatherQuantity.AsFloat := GclNode.AddDealQuantity + GclNode.AddQcQuantity;
  773. cdsProjectGclBillsAddGatherTotalPrice.AsFloat := GclNode.AddDealTotalPrice
  774. + GclNode.AddQcTotalPrice + GclNode.AddPcTotalPrice;
  775. cdsProjectGclBillsSerialNo.AsInteger := FSerialNo;
  776. cdsProjectGclBills.Post;
  777. end;
  778. Inc(FSerialNo);
  779. end;
  780. procedure WriteGatherNodeData(AProjectIndex: Integer);
  781. begin
  782. cdsProjectGclBills.Append;
  783. cdsProjectGclBillsProjectID.AsInteger := AProjectIndex;
  784. cdsProjectGclBillsProjectName.AsString := FGclList.ProjectName[AProjectIndex];
  785. case GatherType of
  786. bgtFinal07: cdsProjectGclBillsName.AsString := '小计';
  787. bgtFinal11: cdsProjectGclBillsName.AsString := '第100章至900章清单合计';
  788. bgtFinal19: cdsProjectGclBillsName.AsString := '合计';
  789. end;
  790. cdsProjectGclBillsTotalPrice.AsFloat := FGclList.GatherNode.TotalPrice;
  791. cdsProjectGclBillsP_TotalPrice.AsFloat := FGclList.GatherNode.P_TotalPrice[AProjectIndex];
  792. cdsProjectGclBillsAddGatherTotalPrice.AsFloat := FGclList.GatherNode.AddDealTotalPrice
  793. + FGclList.GatherNode.AddQcTotalPrice + FGclList.GatherNode.AddPcTotalPrice;
  794. cdsProjectGclBillsP_AddGatherTotalPrice.AsFloat := FGclList.GatherNode.P_AddGatherTotalPrice[AProjectIndex];
  795. cdsProjectGclBillsSerialNo.AsInteger := FSerialNo;
  796. cdsProjectGclBills.Post;
  797. Inc(FSerialNo);
  798. end;
  799. procedure WriteFixedIDData(AProjectIndex: Integer; ANode: TFixedIDBillsNode; const AName: string);
  800. begin
  801. cdsProjectGclBills.Append;
  802. cdsProjectGclBillsProjectID.AsInteger := AProjectIndex;
  803. cdsProjectGclBillsProjectName.AsString := FGclList.ProjectName[AProjectIndex];
  804. cdsProjectGclBillsName.AsString := AName;
  805. if Assigned(ANode) then
  806. begin
  807. cdsProjectGclBillsTotalPrice.AsFloat := ANode.TotalPrice;
  808. cdsProjectGclBillsP_TotalPrice.AsFloat := ANode.P_TotalPrice[AProjectIndex];
  809. cdsProjectGclBillsAddGatherTotalPrice.AsFloat := ANode.AddGatherTotalPrice;
  810. cdsProjectGclBillsP_AddGatherTotalPrice.AsFloat := ANode.P_AddGatherTotalPrice[AProjectIndex];
  811. end;
  812. cdsProjectGclBillsSerialNo.AsInteger := FSerialNo;
  813. cdsProjectGclBills.Post;
  814. end;
  815. procedure WriteFixedIDBillsData07(AProjectIndex: Integer);
  816. var
  817. fTotalPrice, fP_TotalPrice, fAddGatherTotalPrice, fP_AddGatherTotalPrice: Double;
  818. Node54, Node45, Node40, Node51: TFixedIDBillsNode;
  819. begin
  820. fTotalPrice := FGclList.GatherNode.TotalPrice;
  821. fP_TotalPrice := FGclList.GatherNode.P_TotalPrice[AProjectIndex];
  822. fAddGatherTotalPrice := FGclList.GatherNode.AddDealTotalPrice
  823. + FGclList.GatherNode.AddQcTotalPrice + FGclList.GatherNode.AddPcTotalPrice;
  824. fP_AddGatherTotalPrice := FGclList.GatherNode.P_AddGatherTotalPrice[AProjectIndex];
  825. // 变更引起调整合计 全部取0
  826. cdsProjectGclBills.Append;
  827. cdsProjectGclBillsProjectID.AsInteger := AProjectIndex;
  828. cdsProjectGclBillsProjectName.AsString := FGclList.ProjectName[AProjectIndex];
  829. cdsProjectGclBillsName.AsString := '变更引起调整合计';
  830. cdsProjectGclBillsSerialNo.AsInteger := FSerialNo;
  831. cdsProjectGclBills.Post;
  832. Inc(FSerialNo);
  833. // 工程项目调价合计
  834. Node54 := FFixedIDList.FixedIDBillsNode(54);
  835. WriteFixedIDData(AProjectIndex, Node54, '工程项目调价合计');
  836. if Assigned(Node54) then
  837. begin
  838. fTotalPrice := fTotalPrice + Node54.TotalPrice;
  839. fP_TotalPrice := fP_TotalPrice + Node54.P_TotalPrice[AProjectIndex];
  840. fAddGatherTotalPrice := fAddGatherTotalPrice + Node54.AddGatherTotalPrice;
  841. fP_AddGatherTotalPrice := fP_AddGatherTotalPrice + Node54.P_AddGatherTotalPrice[AProjectIndex];
  842. end;
  843. // 工程项目索赔合计
  844. Node45 := FFixedIDList.FixedIDBillsNode(45);
  845. WriteFixedIDData(AProjectIndex, Node45, '工程项目索赔合计');
  846. if Assigned(Node45) then
  847. begin
  848. fTotalPrice := fTotalPrice + Node45.TotalPrice;
  849. fP_TotalPrice := fP_TotalPrice + Node45.P_TotalPrice[AProjectIndex];
  850. fAddGatherTotalPrice := fAddGatherTotalPrice + Node45.AddGatherTotalPrice;
  851. fP_AddGatherTotalPrice := fP_AddGatherTotalPrice + Node45.P_AddGatherTotalPrice[AProjectIndex];
  852. end;
  853. // 计日工支出合计
  854. Node40 := FFixedIDList.FixedIDBillsNode(40);
  855. WriteFixedIDData(AProjectIndex, Node40, '计日工支出合计');
  856. if Assigned(Node40) then
  857. begin
  858. fTotalPrice := fTotalPrice + Node40.TotalPrice;
  859. fP_TotalPrice := fP_TotalPrice + Node40.P_TotalPrice[AProjectIndex];
  860. fAddGatherTotalPrice := fAddGatherTotalPrice + Node40.AddGatherTotalPrice;
  861. fP_AddGatherTotalPrice := fP_AddGatherTotalPrice + Node40.P_AddGatherTotalPrice[AProjectIndex];
  862. end;
  863. // 金额合计
  864. cdsProjectGclBills.Append;
  865. cdsProjectGclBillsProjectID.AsInteger := AProjectIndex;
  866. cdsProjectGclBillsProjectName.AsString := FGclList.ProjectName[AProjectIndex];
  867. cdsProjectGclBillsName.AsString := '金额合计';
  868. cdsProjectGclBillsTotalPrice.AsFloat := fTotalPrice;
  869. cdsProjectGclBillsP_TotalPrice.AsFloat := fP_TotalPrice;
  870. cdsProjectGclBillsAddGatherTotalPrice.AsFloat := fAddGatherTotalPrice;
  871. cdsProjectGclBillsP_AddGatherTotalPrice.AsFloat := fP_AddGatherTotalPrice;
  872. cdsProjectGclBillsSerialNo.AsInteger := FSerialNo;
  873. cdsProjectGclBills.Post;
  874. Inc(FSerialNo);
  875. // 设备费
  876. Node51 := FFixedIDList.FixedIDBillsNode(51);
  877. WriteFixedIDData(AProjectIndex, Node51, '设备费');
  878. end;
  879. procedure WriteFixedIDBillsData11(AProjectIndex: Integer);
  880. var
  881. fTotalPrice, fP_TotalPrice, fAddGatherTotalPrice, fP_AddGatherTotalPrice: Double;
  882. Node19, Node40, NodeTotal: TFixedIDBillsNode;
  883. begin
  884. fTotalPrice := FGclList.GatherNode.TotalPrice;
  885. fP_TotalPrice := FGclList.GatherNode.P_TotalPrice[AProjectIndex];
  886. fAddGatherTotalPrice := FGclList.GatherNode.AddDealTotalPrice
  887. + FGclList.GatherNode.AddQcTotalPrice + FGclList.GatherNode.AddPcTotalPrice;
  888. fP_AddGatherTotalPrice := FGclList.GatherNode.P_AddGatherTotalPrice[AProjectIndex];
  889. // 计日工合计
  890. Node40 := FFixedIDList.FixedIDBillsNode(40);
  891. WriteFixedIDData(AProjectIndex, Node40, '计日工合计');
  892. if Assigned(Node40) then
  893. begin
  894. fTotalPrice := fTotalPrice + Node40.TotalPrice;
  895. fP_TotalPrice := fP_TotalPrice + Node40.P_TotalPrice[AProjectIndex];
  896. fAddGatherTotalPrice := fTotalPrice + Node40.AddGatherTotalPrice;
  897. fP_AddGatherTotalPrice := fP_TotalPrice + Node40.P_AddGatherTotalPrice[AProjectIndex];
  898. end;
  899. // 暂列金额合计
  900. Node19 := FFixedIDList.FixedIDBillsNode(19);
  901. WriteFixedIDData(AProjectIndex, Node19, '暂列金额合计');
  902. if Assigned(Node19) then
  903. begin
  904. fTotalPrice := fTotalPrice + Node19.TotalPrice;
  905. fP_TotalPrice := fP_TotalPrice + Node19.P_TotalPrice[AProjectIndex];
  906. fAddGatherTotalPrice := fTotalPrice + Node19.AddGatherTotalPrice;
  907. fP_AddGatherTotalPrice := fP_TotalPrice + Node19.P_AddGatherTotalPrice[AProjectIndex];
  908. end;
  909. // 其他类别费用合计&金额合计
  910. NodeTotal := FFixedIDList.FixedIDBillsNode(-1);
  911. // 其他类别费用 = 金额合计 - 第100章至900章合计 - 计日工合计 - 暂列金额合计
  912. if Assigned(NodeTotal) then
  913. begin
  914. fTotalPrice := NodeTotal.TotalPrice - fTotalPrice;
  915. fP_TotalPrice := NodeTotal.P_TotalPrice[AProjectIndex] - fP_TotalPrice;
  916. fAddGatherTotalPrice := NodeTotal.AddGatherTotalPrice - fAddGatherTotalPrice;
  917. fP_AddGatherTotalPrice := NodeTotal.P_AddGatherTotalPrice[AProjectIndex] - fP_AddGatherTotalPrice;
  918. end;
  919. cdsProjectGclBills.Append;
  920. cdsProjectGclBillsProjectID.AsInteger := AProjectIndex;
  921. cdsProjectGclBillsProjectName.AsString := FGclList.ProjectName[AProjectIndex];
  922. cdsProjectGclBillsName.AsString := '其他类别费用合计';
  923. cdsProjectGclBillsTotalPrice.AsFloat := fTotalPrice;
  924. cdsProjectGclBillsP_TotalPrice.AsFloat := fP_TotalPrice;
  925. cdsProjectGclBillsAddGatherTotalPrice.AsFloat := fAddGatherTotalPrice;
  926. cdsProjectGclBillsP_AddGatherTotalPrice.AsFloat := fP_AddGatherTotalPrice;
  927. cdsProjectGclBillsSerialNo.AsInteger := FSerialNo;
  928. cdsProjectGclBills.Post;
  929. Inc(FSerialNo);
  930. WriteFixedIDData(AProjectIndex, NodeTotal, '金额合计');
  931. end;
  932. var
  933. iProject: Integer;
  934. begin
  935. for iProject := 0 to FGclList.ProjectCount - 1 do
  936. begin
  937. FSerialNo := 0;
  938. WriteProjectGclData(iProject);
  939. WriteGatherNodeData(iProject);
  940. case GatherType of
  941. bgtFinal07: WriteFixedIDBillsData07(iProject);
  942. bgtFinal11: WriteFixedIDBillsData11(iProject);
  943. end;
  944. end;
  945. end;
  946. procedure TrmBillsGatherData.FilterSettlement(AProjectData: TProjectData;
  947. AProjectIndex: Integer);
  948. var
  949. FixedIDNode: TFixedIDBillsNode;
  950. begin
  951. // -1表示项目结算价
  952. FixedIDNode := FFixedIDList.GetFixedIDBillsNode(-1);
  953. FixedIDNode.TotalPrice := FixedIDNode.TotalPrice + AProjectData.BillsData.Settlement[0];
  954. FixedIDNode.P_TotalPrice[AProjectIndex] := AProjectData.BillsData.Settlement[0];
  955. FixedIDNode.AddGatherTotalPrice := FixedIDNode.AddGatherTotalPrice
  956. + AProjectData.BillsData.Settlement[4];
  957. FixedIDNode.P_AddGatherTotalPrice[AProjectIndex] :=
  958. AProjectData.BillsData.Settlement[4];
  959. end;
  960. procedure TrmBillsGatherData.WriteFlowData(AProjectData: TProjectData);
  961. begin
  962. case GatherType of
  963. bgtFinal12: WriteBGLFlowData(AProjectData);
  964. end;
  965. end;
  966. procedure TrmBillsGatherData.WriteBGLFlowData(AProjectData: TProjectData);
  967. procedure WriteBGLData(ABGLID: Integer);
  968. begin
  969. with AProjectData.BGLData do
  970. begin
  971. cdsBGBills.Filter := 'BGID = ' + IntToStr(ABGLID);
  972. cdsBGBills.Filtered := True;
  973. try
  974. if cdsBGBills.RecordCount = 0 then
  975. begin
  976. cdsBGLFlow.Append;
  977. cdsBGLFlowMergeBGLCode.AsString := cdsBGLCode.AsString;
  978. cdsBGLFlowBGLName.AsString := cdsBGLName.AsString;
  979. cdsBGLFlowApprovalCode.AsString := cdsBGLApprovalCode.AsString;
  980. cdsBGLFlowSuggestion.AsString := '同意';
  981. cdsBGLFlowBGReason.AsString := cdsBGLPos_Reason.AsString;
  982. cdsBGLFlowBGTotalPrice.AsFloat := cdsBGLTotalPrice.AsFloat;
  983. cdsBGLFlow.Post;
  984. Exit;
  985. end;
  986. cdsBGBills.First;
  987. while not cdsBGBills.Eof do
  988. begin
  989. cdsBGLFlow.Append;
  990. cdsBGLFlowMergeBGLCode.AsString := cdsBGLCode.AsString;
  991. cdsBGLFlowBGLName.AsString := cdsBGLName.AsString;
  992. cdsBGLFlowApprovalCode.AsString := cdsBGLApprovalCode.AsString;
  993. cdsBGLFlowSuggestion.AsString := '同意';
  994. cdsBGLFlowBGReason.AsString := cdsBGLPos_Reason.AsString;
  995. cdsBGLFlowBGTotalPrice.AsFloat := cdsBGLTotalPrice.AsFloat;
  996. cdsBGLFlowB_Code.AsString := cdsBGBillsB_Code.AsString;
  997. cdsBGLFlowName.AsString := cdsBGBillsName.AsString;
  998. cdsBGLFlowUnits.AsString := cdsBGBillsUnits.AsString;
  999. cdsBGLFlowQuantity.AsFloat := cdsBGBillsQuantity.AsFloat;
  1000. cdsBGLFlowPrice.AsFloat := cdsBGBillsPrice.AsFloat;
  1001. cdsBGLFlowTotalPrice.AsFloat := cdsBGBillsTotalPrice.AsFloat;
  1002. cdsBGLFlow.Post;
  1003. cdsBGBills.Next;
  1004. end;
  1005. finally
  1006. cdsBGBills.Filtered := False;
  1007. end;
  1008. end;
  1009. end;
  1010. begin
  1011. cdsBGLFlow.Append;
  1012. cdsBGLFlowMergeBGLCode.AsString := AProjectData.ProjProperties.DealIndex;
  1013. cdsBGLFlow.Post;
  1014. with AProjectData.BGLData do
  1015. begin
  1016. cdsBGL.First;
  1017. while not cdsBGL.Eof do
  1018. begin
  1019. WriteBGLData(cdsBGLID.AsInteger);
  1020. cdsBGL.Next;
  1021. end;
  1022. end;
  1023. end;
  1024. procedure TrmBillsGatherData.AddBillsList(ANode: TsdIDTreeNode;
  1025. AParent: TReportCacheNode; AProjectIndex: Integer;
  1026. ASelectProject: TSelectProject);
  1027. var
  1028. ACur: TReportCacheNode;
  1029. begin
  1030. if not Assigned(ANode) then Exit;
  1031. // 按设置的层次汇总
  1032. case ReportConfig.GatherLevel of
  1033. // 项
  1034. 0: if ANode.Level > 2 then Exit;
  1035. // 目
  1036. 1: if ANode.Level > 3 then Exit;
  1037. // 节
  1038. 2: if ANode.Level > 4 then Exit;
  1039. // 细目
  1040. 3: if ANode.Level > 5 then Exit;
  1041. // 项目节
  1042. 4: if ANode.Rec.ValueByName('B_Code').AsString <> '' then Exit;
  1043. end;
  1044. if GatherType in [bgtXmj, bgtMultiXmj, bgtEstimate, bgtEstimate1] then
  1045. if ANode.Rec.ValueByName('B_Code').AsString <> '' then Exit;
  1046. ACur := AddBillsNode(ANode, AParent, AProjectIndex, ASelectProject);
  1047. AddBills(ANode.FirstChild, ACur, AProjectIndex, ASelectProject);
  1048. end;
  1049. procedure TrmBillsGatherData.WriteGatherCacheNode(const AGatherName: string);
  1050. begin
  1051. cdsFxBills.Append;
  1052. cdsFxBillsName.AsString := AGatherName;
  1053. with FCacheTree.GatherCacheNode do
  1054. begin
  1055. cdsFxBillsAddDealTotalPrice.AsFloat := AddDealTotalPrice;
  1056. cdsFxBillsAddQcTotalPrice.AsFloat := AddQcTotalPrice;
  1057. cdsFxBillsAddPcTotalPrice.AsFloat := AddPcTotalPrice;
  1058. cdsFxBillsAddGatherTotalPrice.AsFloat := AddDealTotalPrice +
  1059. AddQcTotalPrice + AddPcTotalPrice;
  1060. cdsFxBillsTotalPrice.AsFloat := TotalPrice;
  1061. end;
  1062. cdsFxBills.Post;
  1063. end;
  1064. procedure TrmBillsGatherData.CalculateGatherData;
  1065. begin
  1066. if GatherType in [bgtFinal08, bgtFinal16, bgtEstimate1, bgtG_Final04] then
  1067. FCacheTree.ReCalcGatherData;
  1068. if GatherType in [bgtFinal07, bgtFinal11, bgtFinal19] then
  1069. FGclList.ReCalcualteGatherNode;
  1070. end;
  1071. procedure TrmBillsGatherData.WriteBillsData;
  1072. begin
  1073. WriteNode(TReportCacheNode(FCacheTree.FirstNode));
  1074. case GatherType of
  1075. bgtFinal08: WriteGatherCacheNode('金额合计');
  1076. bgtG_Final04: WriteGatherCacheNode('公路基本造价');
  1077. end;
  1078. end;
  1079. procedure TrmBillsGatherData.WriteEstimateGatherNode;
  1080. begin
  1081. cdsEstimateBills.Append;
  1082. cdsEstimateBillsName.AsString := '公路基本造价';
  1083. with FCacheTree.GatherCacheNode do
  1084. begin
  1085. cdsEstimateBillsTotalPrice.AsFloat := TotalPrice;
  1086. cdsEstimateBillsAddDealTotalPrice.AsFloat := AddDealTotalPrice;
  1087. cdsEstimateBillsAddCTotalPrice.AsFloat := AddQcTotalPrice + AddPcTotalPrice;
  1088. cdsEstimateBillsAddGatherTotalPrice.AsFloat :=
  1089. cdsEstimateBillsAddDealTotalPrice.AsFloat + cdsEstimateBillsAddCTotalPrice.AsFloat;
  1090. cdsEstimateBillsTotalPriceAdjust.AsFloat :=
  1091. cdsEstimateBillsAddGatherTotalPrice.AsFloat - cdsEstimateBillsPDTotalPrice.AsFloat;
  1092. cdsEstimateBillsPDTotalPrice.AsFloat := PDTotalPrice;
  1093. cdsEstimateBillsCDDTotalPrice.AsFloat := CDDTotalPrice;
  1094. cdsEstimateBillsABTotalPrice.AsFloat := ABTotalPrice;
  1095. cdsEstimateBillsTotalPriceCompare1.AsFloat := GetCompare(ABTotalPrice, TotalPrice);
  1096. cdsEstimateBillsTotalPriceCompare2.AsFloat :=
  1097. GetCompare(ABTotalPrice, cdsEstimateBillsAddGatherTotalPrice.AsFloat);
  1098. cdsEstimateBillsTotalPriceCompare3.AsFloat :=
  1099. GetCompare(TotalPrice, cdsEstimateBillsAddGatherTotalPrice.AsFloat);
  1100. end;
  1101. cdsEstimateBills.Post;
  1102. end;
  1103. procedure TrmBillsGatherData.WriteEstimateData;
  1104. begin
  1105. WriteEstimateNode(TReportCacheNode(FCacheTree.FirstNode));
  1106. if GatherType = bgtG_Final06_1 then
  1107. ReWriteENodeDataAsGather(TReportCacheNode(FCacheTree.FirstNode), '土地征用及拆迁补偿费用合计');
  1108. if GatherType in [bgtEstimate, bgtEstimate1] then
  1109. WriteEstimateGatherNode;
  1110. end;
  1111. function TrmBillsGatherData.GetCompare(ANum1, ANum2: Double): Double;
  1112. begin
  1113. Result := 0;
  1114. if ANum1 <> 0 then
  1115. Result := (ANum2 - ANum1)/ANum1*100;
  1116. end;
  1117. procedure TrmBillsGatherData.WriteENodeData(ANode: TReportCacheNode);
  1118. begin
  1119. cdsEstimateBills.Append;
  1120. cdsEstimateBillsXiangCode.AsString := ANode.XiangCode;
  1121. cdsEstimateBillsMuCode.AsString := ANode.MuCode;
  1122. cdsEstimateBillsJieCode.AsString := ANode.JieCode;
  1123. cdsEstimateBillsXiMuCode.AsString := ANode.XiMuCode;
  1124. cdsEstimateBillsCode.AsString := ANode.Code;
  1125. cdsEstimateBillsB_Code.AsString := ANode.B_Code;
  1126. cdsEstimateBillsName.AsString := ANode.Name;
  1127. cdsEstimateBillsUnits.AsString := ANode.Units;
  1128. cdsEstimateBillsPrice.AsFloat := ANode.Price;
  1129. cdsEstimateBillsQuantity.AsFloat := ANode.Quantity;
  1130. cdsEstimateBillsTotalPrice.AsFloat := ANode.TotalPrice;
  1131. cdsEstimateBillsDgnQuantity1.AsFloat := ANode.DesignQuantity1;
  1132. cdsEstimateBillsDgnQuantity2.AsFloat := ANode.DesignQuantity2;
  1133. cdsEstimateBillsDgnQuantity.AsString :=
  1134. GetDgnQuantity(cdsEstimateBillsDgnQuantity1.AsFloat, cdsEstimateBillsDgnQuantity2.AsFloat);
  1135. cdsEstimateBillsAddDealQuantity.AsFloat := ANode.AddDealQuantity;
  1136. cdsEstimateBillsAddDealTotalPrice.AsFloat := ANode.AddDealTotalPrice;
  1137. cdsEstimateBillsAddCQuantity.AsFloat := ANode.AddQcQuantity;
  1138. cdsEstimateBillsAddCTotalPrice.AsFloat := ANode.AddQcTotalPrice + ANode.AddPcTotalPrice;
  1139. cdsEstimateBillsAddGatherQuantity.AsFloat :=
  1140. cdsEstimateBillsAddDealQuantity.AsFloat + cdsEstimateBillsAddCQuantity.AsFloat;
  1141. cdsEstimateBillsAddGatherTotalPrice.AsFloat :=
  1142. cdsEstimateBillsAddDealTotalPrice.AsFloat + cdsEstimateBillsAddCTotalPrice.AsFloat;
  1143. cdsEstimateBillsQuantityAdjust.AsFloat :=
  1144. cdsEstimateBillsAddGatherQuantity.AsFloat - cdsEstimateBillsPDQuantity.AsFloat;
  1145. cdsEstimateBillsTotalPriceAdjust.AsFloat :=
  1146. cdsEstimateBillsAddGatherTotalPrice.AsFloat - cdsEstimateBillsPDTotalPrice.AsFloat;
  1147. cdsEstimateBillsDealDgnQuantity1.AsFloat := ANode.DealDesignQuantity1;
  1148. cdsEstimateBillsDealDgnQuantity2.AsFloat := ANode.DealDesignQuantity2;
  1149. cdsEstimateBillsDealDgnQuantity.AsString :=
  1150. GetDgnQuantity(cdsEstimateBillsDealDgnQuantity1.AsFloat, cdsEstimateBillsDealDgnQuantity2.AsFloat);
  1151. cdsEstimateBillsCDgnQuantity1.AsFloat := ANode.CDesignQuantity1;
  1152. cdsEstimateBillsCDgnQuantity2.AsFloat := ANode.CDesignQuantity2;
  1153. cdsEstimateBillsCDgnQuantity.AsString :=
  1154. GetDgnQuantity(cdsEstimateBillsCDgnQuantity1.AsFloat, cdsEstimateBillsCDgnQuantity2.AsFloat);
  1155. cdsEstimateBillsGatherDgnQuantity1.AsFloat :=
  1156. cdsEstimateBillsDealDgnQuantity1.AsFloat + cdsEstimateBillsCDgnQuantity1.AsFloat;
  1157. cdsEstimateBillsGatherDgnQuantity2.AsFloat :=
  1158. cdsEstimateBillsDealDgnQuantity2.AsFloat + cdsEstimateBillsCDgnQuantity2.AsFloat;;
  1159. cdsEstimateBillsGatherDgnQuantity.AsString :=
  1160. GetDgnQuantity(cdsEstimateBillsGatherDgnQuantity1.AsFloat, cdsEstimateBillsGatherDgnQuantity2.AsFloat);
  1161. cdsEstimateBillsFinalDgnQty1.AsFloat := cdsEstimateBillsDgnQuantity1.AsFloat + cdsEstimateBillsCDgnQuantity1.AsFloat;
  1162. cdsEstimateBillsFinalDgnQty2.AsFloat := cdsEstimateBillsDgnQuantity2.AsFloat + cdsEstimateBillsCDgnQuantity2.AsFloat;
  1163. cdsEstimateBillsFinalDgnQty.AsString := GetDgnQuantity(
  1164. cdsEstimateBillsFinalDgnQty1.AsFloat, cdsEstimateBillsFinalDgnQty2.AsFloat);
  1165. cdsEstimateBillsPDQuantity.AsFloat := ANode.PDQuantity;
  1166. cdsEstimateBillsPDTotalPrice.AsFloat := ANode.PDTotalPrice;
  1167. cdsEstimateBillsPDDgnQuantity1.AsFloat := ANode.PDDesignQuantity1;
  1168. cdsEstimateBillsPDDgnQuantity2.AsFloat := ANode.PDDesignQuantity2;
  1169. cdsEstimateBillsPDDgnQuantity.AsString :=
  1170. GetDgnQuantity(cdsEstimateBillsPDDgnQuantity1.AsFloat, cdsEstimateBillsPDDgnQuantity2.AsFloat);
  1171. cdsEstimateBillsPDDgnPrice.AsFloat := ANode.PDDesignPrice;
  1172. cdsEstimateBillsCDDQuantity.AsFloat := ANode.CDDQuantity;
  1173. cdsEstimateBillsCDDTotalPrice.AsFloat := ANode.CDDTotalPrice;
  1174. cdsEstimateBillsCDDDgnQuantity1.AsFloat := ANode.CDDDesignQuantity1;
  1175. cdsEstimateBillsCDDDgnQuantity2.AsFloat := ANode.CDDDesignQuantity2;
  1176. cdsEstimateBillsCDDDgnQuantity.AsString :=
  1177. GetDgnQuantity(cdsEstimateBillsCDDDgnQuantity1.AsFloat, cdsEstimateBillsCDDDgnQuantity2.AsFloat);
  1178. cdsEstimateBillsCDDDgnPrice.AsFloat := ANode.CDDDesignPrice;
  1179. cdsEstimateBillsABQuantity.AsFloat := ANode.ABQuantity;
  1180. cdsEstimateBillsABTotalPrice.AsFloat := ANode.ABTotalPrice;
  1181. cdsEstimateBillsABDgnQuantity1.AsFloat := ANode.ABDesignQuantity1;
  1182. cdsEstimateBillsABDgnQuantity2.AsFloat := ANode.ABDesignQuantity2;
  1183. cdsEstimateBillsABDgnQuantity.AsString :=
  1184. GetDgnQuantity(cdsEstimateBillsABDgnQuantity1.AsFloat, cdsEstimateBillsABDgnQuantity2.AsFloat);
  1185. cdsEstimateBillsABDgnPrice.AsFloat := ANode.ABDesignPrice;
  1186. cdsEstimateBillsQuantityCompare1.AsFloat := GetCompare(ANode.ABQuantity, ANode.Quantity);
  1187. cdsEstimateBillsTotalPriceCompare1.AsFloat := GetCompare(ANode.ABTotalPrice, ANode.TotalPrice);
  1188. cdsEstimateBillsDgnQuantity1Compare1.AsFloat := GetCompare(
  1189. cdsEstimateBillsABDgnQuantity1.AsFloat, cdsEstimateBillsDgnQuantity1.AsFloat);
  1190. cdsEstimateBillsDgnQuantity2Compare1.AsFloat := GetCompare(
  1191. cdsEstimateBillsABDgnQuantity2.AsFloat, cdsEstimateBillsDgnQuantity2.AsFloat);
  1192. cdsEstimateBillsDgnQuantityCompare1.AsString := GetDgnQuantity(
  1193. cdsEstimateBillsDgnQuantity1Compare1.AsFloat, cdsEstimateBillsDgnQuantity2Compare1.AsFloat);
  1194. cdsEstimateBillsQuantityCompare2.AsFloat :=
  1195. GetCompare(ANode.ABQuantity, cdsEstimateBillsAddGatherQuantity.AsFloat);
  1196. cdsEstimateBillsTotalPriceCompare2.AsFloat :=
  1197. GetCompare(ANode.ABTotalPrice, cdsEstimateBillsAddGatherTotalPrice.AsFloat);
  1198. cdsEstimateBillsDgnQuantity1Compare2.AsFloat := GetCompare(
  1199. cdsEstimateBillsABDgnQuantity1.AsFloat, cdsEstimateBillsGatherDgnQuantity1.AsFloat);
  1200. cdsEstimateBillsDgnQuantity2Compare2.AsFloat := GetCompare(
  1201. cdsEstimateBillsABDgnQuantity2.AsFloat, cdsEstimateBillsGatherDgnQuantity2.AsFloat);
  1202. cdsEstimateBillsDgnQuantityCompare2.AsString := GetDgnQuantity(
  1203. cdsEstimateBillsDgnQuantity1Compare2.AsFloat, cdsEstimateBillsDgnQuantity2Compare2.AsFloat);
  1204. cdsEstimateBillsQuantityCompare3.AsFloat :=
  1205. GetCompare(ANode.Quantity, cdsEstimateBillsAddGatherQuantity.AsFloat);
  1206. cdsEstimateBillsTotalPriceCompare3.AsFloat :=
  1207. GetCompare(ANode.TotalPrice, cdsEstimateBillsAddGatherTotalPrice.AsFloat);
  1208. cdsEstimateBillsDgnQuantity1Compare3.AsFloat := GetCompare(
  1209. cdsEstimateBillsDgnQuantity1.AsFloat, cdsEstimateBillsGatherDgnQuantity1.AsFloat);
  1210. cdsEstimateBillsDgnQuantity2Compare3.AsFloat := GetCompare(
  1211. cdsEstimateBillsDgnQuantity2.AsFloat, cdsEstimateBillsGatherDgnQuantity2.AsFloat);
  1212. cdsEstimateBillsDgnQuantityCompare3.AsString := GetDgnQuantity(
  1213. cdsEstimateBillsDgnQuantity1Compare3.AsFloat, cdsEstimateBillsDgnQuantity2Compare3.AsFloat);
  1214. cdsEstimateBills.Post;
  1215. end;
  1216. procedure TrmBillsGatherData.ReWriteENodeDataAsGather(
  1217. ANode: TReportCacheNode; AName: string);
  1218. begin
  1219. WriteENodeData(ANode);
  1220. cdsEstimateBills.Edit;
  1221. cdsEstimateBillsXiangCode.AsString := '';
  1222. cdsEstimateBillsMuCode.AsString := '';
  1223. cdsEstimateBillsJieCode.AsString := '';
  1224. cdsEstimateBillsXiMuCode.AsString := '';
  1225. cdsEstimateBillsCode.AsString := '';
  1226. cdsEstimateBillsName.AsString := AName;
  1227. cdsEstimateBillsUnits.AsString := '';
  1228. cdsEstimateBills.Post;
  1229. end;
  1230. function TrmBillsGatherData.GetDgnQuantity(ANum1, ANum2: Double): string;
  1231. begin
  1232. Result := '';
  1233. if ANum1 <> 0 then
  1234. begin
  1235. Result := FloatToStr(ANum1);
  1236. if ANum2 <> 0 then
  1237. Result := Result + '/' + FloatToStr(ANum2);
  1238. end;
  1239. end;
  1240. procedure TrmBillsGatherData.CalculateRatioPercent;
  1241. begin
  1242. if GatherType = bgtG_Final04 then
  1243. FCacheTree.ReCalcGatherData;
  1244. end;
  1245. function TrmBillsGatherData.GetDgnPrice(ATotalPrice,
  1246. ADgnQuantity: Double): Double;
  1247. begin
  1248. if ADgnQuantity <> 0 then
  1249. Result := PriceRoundTo(ATotalPrice/ADgnQuantity)
  1250. else
  1251. Result := 0;
  1252. end;
  1253. end.