rmBillsGatherDm.pas 61 KB

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