GclBillsGatherModel.pas 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. unit GclBillsGatherModel;
  2. // 单项目的工程量清单汇总
  3. interface
  4. uses
  5. Classes, mDataRecord, BillsTree, CalcDecimal;
  6. type
  7. TLeafXmjNode = class
  8. private
  9. FID: Integer;
  10. FXmjCode: string;
  11. FXmjName: string;
  12. FXmjUnits: string;
  13. FPeg: string;
  14. FNameDanWei: string;
  15. FNameFenBu: string;
  16. FNameFenXiang: string;
  17. FNameUnit: string;
  18. FPosition: string;
  19. FDrawingCode: string;
  20. public
  21. constructor Create(ALeafXmj, APeg: TBillsIDTreeNode);
  22. property ID: Integer read FID;
  23. property XmjCode: string read FXmjCode;
  24. property XmjName: string read FXmjName;
  25. property XmjUnits: string read FXmjUnits;
  26. property Peg: string read FPeg;
  27. property NameDanWei: string read FNameDanWei;
  28. property NameFenBu: string read FNameFenBu;
  29. property NameFenXiang: string read FNameFenXiang;
  30. property NameUnit: string read FNameUnit;
  31. property Position: string read FPosition;
  32. property DrawingCode: string read FDrawingCode;
  33. end;
  34. TDetailGclNode = class
  35. private
  36. FID: Integer;
  37. FBillsID: Integer;
  38. FTreeSerialNo: Integer;
  39. FOrgQuantity: Double;
  40. FOrgTotalPrice: Double;
  41. FMisQuantity: Double;
  42. FMisTotalPrice: Double;
  43. FOthQuantity: Double;
  44. FOthTotalPrice: Double;
  45. FQuantity: Double;
  46. FTotalPrice: Double;
  47. FCurDealQuantity: Double;
  48. FCurDealTotalPrice: Double;
  49. FCurQcQuantity: Double;
  50. FCurQcTotalPrice: Double;
  51. FCurGatherQuantity: Double;
  52. FCurGatherTotalPrice: Double;
  53. FPreDealQuantity: Double;
  54. FPreDealTotalPrice: Double;
  55. FPreQcQuantity: Double;
  56. FPreQcTotalPrice: Double;
  57. FPreGatherQuantity: Double;
  58. FPreGatherTotalPrice: Double;
  59. FEndDealQuantity: Double;
  60. FEndDealTotalPrice: Double;
  61. FEndQcQuantity: Double;
  62. FEndQcTotalPrice: Double;
  63. FEndGatherQuantity: Double;
  64. FEndGatherTotalPrice: Double;
  65. FAddDealQuantity: Double;
  66. FAddDealTotalPrice: Double;
  67. FAddQcQuantity: Double;
  68. FAddQcTotalPrice: Double;
  69. FAddGatherQuantity: Double;
  70. FAddGatherTotalPrice: Double;
  71. FPM_PreTotalPrice: Double;
  72. FPM_TotalPrice: Double;
  73. FLeafXmj: TLeafXmjNode;
  74. function GetPercent: Double;
  75. public
  76. constructor Create(AID: Integer);
  77. property ID: Integer read FID;
  78. property BillsID: Integer read FBillsID write FBillsID;
  79. property TreeSerialNo: Integer read FTreeSerialNo write FTreeSerialNo;
  80. property OrgQuantity: Double read FOrgQuantity write FOrgQuantity;
  81. property OrgTotalPrice: Double read FOrgTotalPrice write FOrgTotalPrice;
  82. property MisQuantity: Double read FMisQuantity write FMisQuantity;
  83. property MisTotalPrice: Double read FMisTotalPrice write FMisTotalPrice;
  84. property OthQuantity: Double read FOthQuantity write FOthQuantity;
  85. property OthTotalPrice: Double read FOthTotalPrice write FOthTotalPrice;
  86. property Quantity: Double read FQuantity write FQuantity;
  87. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  88. property CurDealQuantity: Double read FCurDealQuantity write FCurDealQuantity;
  89. property CurDealTotalPrice: Double read FCurDealTotalPrice write FCurDealTotalPrice;
  90. property CurQcQuantity: Double read FCurQcQuantity write FCurQcQuantity;
  91. property CurQcTotalPrice: Double read FCurQcTotalPrice write FCurQcTotalPrice;
  92. property CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
  93. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  94. property PreDealQuantity: Double read FPreDealQuantity write FPreDealQuantity;
  95. property PreDealTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  96. property PreQcQuantity: Double read FPreQcQuantity write FPreQcQuantity;
  97. property PreQcTotalPrice: Double read FPreQcTotalPrice write FPreQcTotalPrice;
  98. property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
  99. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  100. property EndDealQuantity: Double read FEndDealQuantity write FEndDealQuantity;
  101. property EndDealTotalPrice: Double read FEndDealTotalPrice write FEndDealTotalPrice;
  102. property EndQcQuantity: Double read FEndQcQuantity write FEndQcQuantity;
  103. property EndQcTotalPrice: Double read FEndQcTotalPrice write FEndQcTotalPrice;
  104. property EndGatherQuantity: Double read FEndGatherQuantity write FEndGatherQuantity;
  105. property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
  106. property Percent: Double read GetPercent;
  107. property AddDealQuantity: Double read FAddDealQuantity write FAddDealQuantity;
  108. property AddDealTotalPrice: Double read FAddDealTotalPrice write FAddDealTotalPrice;
  109. property AddQcQuantity: Double read FAddQcQuantity write FAddQcQuantity;
  110. property AddQcTotalPrice: Double read FAddQcTotalPrice write FAddQcTotalPrice;
  111. property AddGatherQuantity: Double read FAddGatherQuantity write FAddGatherQuantity;
  112. property AddGatherTotalPrice: Double read FAddGatherTotalPrice write FAddGatherTotalPrice;
  113. property PM_PreTotalPrice: Double read FPM_PreTotalPrice write FPM_PreTotalPrice;
  114. property PM_TotalPrice: Double read FPM_TotalPrice write FPM_TotalPrice;
  115. property LeafXmj: TLeafXmjNode read FLeafXmj write FLeafXmj;
  116. end;
  117. TDetailDealNode = class
  118. private
  119. FID: Integer;
  120. FDealID: Integer;
  121. FQuantity: Double;
  122. FTotalPrice: Double;
  123. public
  124. constructor Create(AID: Integer);
  125. property ID: Integer read FID;
  126. property DealID: Integer read FDealID write FDealID;
  127. property Quantity: Double read FQuantity write FQuantity;
  128. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  129. end;
  130. TDetailBGLNode = class
  131. private
  132. FID: Integer;
  133. FBGBillsID: Integer;
  134. FBGLID: Integer;
  135. FBGLCode: string;
  136. FBGLName: string;
  137. FBGLApprovalCode: string;
  138. FBGLDrawingCode: string;
  139. FQuantity: Double;
  140. FTotalPrice: Double;
  141. public
  142. constructor Create(AID: Integer);
  143. property ID: Integer read FID;
  144. property BGBillsID: Integer read FBGBillsID write FBGBillsID;
  145. property BGLID: Integer read FBGLID write FBGLID;
  146. property BGLCode: string read FBGLCode write FBGLCode;
  147. property BGLName: string read FBGLName write FBGLName;
  148. property BGLApprovalCode: string read FBGLApprovalCode write FBGLApprovalCode;
  149. property BGLDrawingCode: string read FBGLDrawingCode write FBGLDrawingCode;
  150. property Quantity: Double read FQuantity write FQuantity;
  151. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  152. end;
  153. TGclNode = class
  154. private
  155. FDetailGcls: TList;
  156. FDetailDeals: TList;
  157. FDetailBGLs: TList;
  158. FLeafXmjs: TList;
  159. FID: Integer;
  160. FB_Code: string;
  161. FIndexCode: string;
  162. FName: string;
  163. FUnits: string;
  164. FPrice: Double;
  165. FOrgQuantity: Double;
  166. FOrgTotalPrice: Double;
  167. FMisQuantity: Double;
  168. FMisTotalPrice: Double;
  169. FOthQuantity: Double;
  170. FOthTotalPrice: Double;
  171. FQuantity: Double;
  172. FTotalPrice: Double;
  173. FCurDealQuantity: Double;
  174. FCurDealTotalPrice: Double;
  175. FCurQcQuantity: Double;
  176. FCurQcTotalPrice: Double;
  177. FCurGatherQuantity: Double;
  178. FCurGatherTotalPrice: Double;
  179. FPreDealQuantity: Double;
  180. FPreDealTotalPrice: Double;
  181. FPreQcQuantity: Double;
  182. FPreQcTotalPrice: Double;
  183. FPreGatherQuantity: Double;
  184. FPreGatherTotalPrice: Double;
  185. FEndDealQuantity: Double;
  186. FEndDealTotalPrice: Double;
  187. FEndQcQuantity: Double;
  188. FEndQcTotalPrice: Double;
  189. FEndGatherQuantity: Double;
  190. FEndGatherTotalPrice: Double;
  191. FAddDealQuantity: Double;
  192. FAddDealTotalPrice: Double;
  193. FAddQcQuantity: Double;
  194. FAddQcTotalPrice: Double;
  195. FAddGatherQuantity: Double;
  196. FAddGatherTotalPrice: Double;
  197. FDealQuantity: Double;
  198. FDealTotalPrice: Double;
  199. FBGLQuantity: Double;
  200. FBGLTotalPrice: Double;
  201. FDeal_BGLQuantity: Double;
  202. FDeal_BGLTotalPrice: Double;
  203. FDeal_BGLPercent: Double;
  204. FDecimal: TCalcDecimal;
  205. procedure InitCalculate;
  206. procedure GatherDetailGcl;
  207. procedure GatherDetailDeal;
  208. procedure GatherDetailBGL;
  209. procedure CalculateOther;
  210. procedure SetB_Code(const Value: string);
  211. function GetDetailBGL(AIndex: Integer): TDetailBGLNode;
  212. function GetDetailBGLCount: Integer;
  213. function GetDetailDeal(AIndex: Integer): TDetailDealNode;
  214. function GetDetailDealCount: Integer;
  215. function GetDetailGcl(AIndex: Integer): TDetailGclNode;
  216. function GetDetailGclCount: Integer;
  217. function GetLeafXmjCount: Integer;
  218. function GetLeafXmj(AIndex: Integer): TLeafXmjNode;
  219. public
  220. constructor Create(AID: Integer; ADecimal: TCalcDecimal);
  221. destructor Destroy; override;
  222. procedure AddLeafXmj(ALeafXmj: TLeafXmjNode);
  223. function AddDetailGcl(AID: Integer): TDetailGclNode;
  224. function AddDetailDeal(AID: Integer): TDetailDealNode;
  225. function AddDetailBGL(AID: Integer): TDetailBGLNode;
  226. procedure Calculate;
  227. property ID: Integer read FID;
  228. property B_Code: string read FB_Code write SetB_Code;
  229. property IndexCode: string read FIndexCode;
  230. property Name: string read FName write FName;
  231. property Units: string read FUnits write FUnits;
  232. property Price: Double read FPrice write FPrice;
  233. property OrgQuantity: Double read FOrgQuantity;
  234. property OrgTotalPrice: Double read FOrgTotalPrice;
  235. property MisQuantity: Double read FMisQuantity;
  236. property MisTotalPrice: Double read FMisTotalPrice;
  237. property OthQuantity: Double read FOthQuantity;
  238. property OthTotalPrice: Double read FOthTotalPrice;
  239. property Quantity: Double read FQuantity;
  240. property TotalPrice: Double read FTotalPrice;
  241. property CurDealQuantity: Double read FCurDealQuantity;
  242. property CurDealTotalPrice: Double read FCurDealTotalPrice;
  243. property CurQcQuantity: Double read FCurQcQuantity;
  244. property CurQcTotalPrice: Double read FCurQcTotalPrice;
  245. property CurGatherQuantity: Double read FCurGatherQuantity;
  246. property CurGatherTotalPrice: Double read FCurGatherTotalPrice;
  247. property PreDealQuantity: Double read FPreDealQuantity;
  248. property PreDealTotalPrice: Double read FPreGatherTotalPrice;
  249. property PreQcQuantity: Double read FPreQcQuantity;
  250. property PreQcTotalPrice: Double read FPreQcTotalPrice;
  251. property PreGatherQuantity: Double read FPreGatherQuantity;
  252. property PreGatherTotalPrice: Double read FPreGatherTotalPrice;
  253. property EndDealQuantity: Double read FEndDealQuantity;
  254. property EndDealTotalPrice: Double read FEndDealTotalPrice;
  255. property EndQcQuantity: Double read FEndQcQuantity;
  256. property EndQcTotalPrice: Double read FEndQcTotalPrice;
  257. property EndGatherQuantity: Double read FEndGatherQuantity;
  258. property EndGatherTotalPrice: Double read FEndGatherTotalPrice;
  259. property AddDealQuantity: Double read FAddDealQuantity;
  260. property AddDealTotalPrice: Double read FAddGatherTotalPrice;
  261. property AddQcQuantity: Double read FAddQcQuantity;
  262. property AddQcTotalPrice: Double read FAddQcTotalPrice;
  263. property AddGatherQuantity: Double read FAddGatherQuantity;
  264. property AddGatherTotalPrice: Double read FAddGatherTotalPrice;
  265. property DealQuantity: Double read FDealQuantity;
  266. property DealTotalPrice: Double read FDealTotalPrice;
  267. property BGLQuantity: Double read FBGLQuantity;
  268. property BGLTotalPrice: Double read FBGLTotalPrice;
  269. // ---------- Calculate --------------
  270. property Deal_BGLQuantity: Double read FDeal_BGLQuantity;
  271. property Deal_BGLTotalPrice: Double read FDeal_BGLTotalPrice;
  272. property Deal_BGLPercent: Double read FDeal_BGLPercent;
  273. // -----------------------------------
  274. property DetailGclCount: Integer read GetDetailGclCount;
  275. property DetailGcl[AIndex: Integer]: TDetailGclNode read GetDetailGcl;
  276. property LeafXmjCount: Integer read GetLeafXmjCount;
  277. property LeafXmj[AIndex: Integer]: TLeafXmjNode read GetLeafXmj;
  278. property DetailDealCount: Integer read GetDetailDealCount;
  279. property DetailDeal[AIndex: Integer]: TDetailDealNode read GetDetailDeal;
  280. property DetailBGLCount: Integer read GetDetailBGLCount;
  281. property DetailBGL[AIndex: Integer]: TDetailBGLNode read GetDetailBGL;
  282. property Decimal: TCalcDecimal read FDecimal;
  283. end;
  284. TGatherNode = class
  285. private
  286. FID: Integer;
  287. FOrgTotalPrice: Double;
  288. FMisTotalPrice: Double;
  289. FOthTotalPrice: Double;
  290. FTotalPrice: Double;
  291. FCurDealTotalPrice: Double;
  292. FCurQcTotalPrice: Double;
  293. FCurGatherTotalPrice: Double;
  294. FPreDealTotalPrice: Double;
  295. FPreQcTotalPrice: Double;
  296. FPreGatherTotalPrice: Double;
  297. FEndDealTotalPrice: Double;
  298. FEndQcTotalPrice: Double;
  299. FEndGatherTotalPrice: Double;
  300. FAddDealTotalPrice: Double;
  301. FAddQcTotalPrice: Double;
  302. FAddGatherTotalPrice: Double;
  303. FDealTotalPrice: Double;
  304. FBGLTotalPrice: Double;
  305. FDeal_BGLTotalPrice: Double;
  306. FDeal_BGLPercent: Double;
  307. public
  308. property ID: Integer read FID write FID;
  309. property OrgTotalPrice: Double read FOrgTotalPrice write FOrgTotalPrice;
  310. property MisTotalPrice: Double read FMisTotalPrice write FMisTotalPrice;
  311. property OthTotalPrice: Double read FOthTotalPrice write FOthTotalPrice;
  312. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  313. property CurDealTotalPrice: Double read FCurDealTotalPrice write FCurDealTotalPrice;
  314. property CurQcTotalPrice: Double read FCurQcTotalPrice write FCurQcTotalPrice;
  315. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  316. property PreDealTotalPrice: Double read FPreGatherTotalPrice write FPreDealTotalPrice;
  317. property PreQcTotalPrice: Double read FPreQcTotalPrice write FPreQcTotalPrice;
  318. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  319. property EndDealTotalPrice: Double read FEndDealTotalPrice write FEndDealTotalPrice;
  320. property EndQcTotalPrice: Double read FEndQcTotalPrice write FEndQcTotalPrice;
  321. property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
  322. property AddDealTotalPrice: Double read FAddGatherTotalPrice write FAddDealTotalPrice;
  323. property AddQcTotalPrice: Double read FAddQcTotalPrice write FAddQcTotalPrice;
  324. property AddGatherTotalPrice: Double read FAddGatherTotalPrice write FAddGatherTotalPrice;
  325. property DealTotalPrice: Double read FDealTotalPrice write FDealTotalPrice;
  326. property BGLTotalPrice: Double read FBGLTotalPrice write FBGLTotalPrice;
  327. // ---------- Calculate --------------
  328. property Deal_BGLTotalPrice: Double read FDeal_BGLTotalPrice write FDeal_BGLTotalPrice;
  329. property Deal_BGLPercent: Double read FDeal_BGLPercent write FDeal_BGLPercent;
  330. // -----------------------------------
  331. end;
  332. TGatherDataWriteEvent = procedure (AGcls, AXmjs: TList; AGather: TGatherNode) of object;
  333. TGclGatherModel = class
  334. private
  335. FProjectData: TObject;
  336. FBillsTree: TBillsIDTree;
  337. FMergeDetailGcl: Boolean;
  338. FGatherDeal: Boolean;
  339. FGatherBGL: Boolean;
  340. FGcls: TList;
  341. FXmjs: TList;
  342. FNewGclID: Integer;
  343. FNewDetailGclID: Integer;
  344. FNewDetailDealID: Integer;
  345. FNewDetailBGLID: Integer;
  346. FGather: TGatherNode;
  347. FWriteGatherData: TGatherDataWriteEvent;
  348. FDecimal: TCalcDecimal;
  349. procedure BeginGather;
  350. procedure EndGather;
  351. function FindLeafXmj(ALeafXmj: TBillsIDTreeNode): TLeafXmjNode;
  352. function NewLeafXmj(ALeafXmj: TBillsIDTreeNode): TLeafXmjNode;
  353. function GetLeafXmj(ANode: TBillsIDTreeNode): TLeafXmjNode;
  354. function FindGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode;
  355. function NewGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode;
  356. function GetGclNode(const AB_Code, AName, AUnits: string; APrice: Double): TGclNode; overload;
  357. function GetGclNode(ARec: TBillsRecord): TGclNode; overload;
  358. procedure AddBillsNode(ANode: TMeasureBillsIDTreeNode);
  359. procedure GatherBillsData;
  360. procedure GatherDealData;
  361. procedure GatherBGLData;
  362. procedure CalculateGather;
  363. procedure CalculateAll;
  364. function GetNewDetailBGLID: Integer;
  365. function GetNewDetailDealID: Integer;
  366. function GetNewDetailGclID: Integer;
  367. public
  368. constructor Create(AProjectData: TObject);
  369. destructor Destroy; override;
  370. procedure Execute;
  371. property GatherDeal: Boolean read FGatherDeal write FGatherDeal;
  372. property GatherBGL: Boolean read FGatherBGL write FGatherBGL;
  373. property NewDetailGclID: Integer read GetNewDetailGclID;
  374. property NewDetailDealID: Integer read GetNewDetailDealID;
  375. property NewDetailBGLID: Integer read GetNewDetailBGLID;
  376. // 在使用汇总模型的数据单元创建数据库写入方法,并赋值,否则汇总数据不写入
  377. property WriteGatherData: TGatherDataWriteEvent read FWriteGatherData write FWriteGatherData;
  378. property Decimal: TCalcDecimal read FDecimal;
  379. end;
  380. implementation
  381. uses
  382. ZhAPI, SysUtils, ProjectData, UtilMethods, sdDB, sdIDTree, BGLDm, DB,
  383. Math;
  384. { TGclGatherModel }
  385. procedure TGclGatherModel.AddBillsNode(ANode: TMeasureBillsIDTreeNode);
  386. var
  387. vGclNode: TGclNode;
  388. vDetailGclNode: TDetailGclNode;
  389. vLeafXmj: TLeafXmjNode;
  390. begin
  391. vGclNode := GetGclNode(ANode.Rec);
  392. vDetailGclNode := vGclNode.AddDetailGcl(NewDetailGclID);
  393. vDetailGclNode.BillsID := ANode.ID;
  394. vDetailGclNode.TreeSerialNo := ANode.MajorIndex;
  395. vDetailGclNode.OrgQuantity := ANode.Rec.OrgQuantity.AsFloat;
  396. vDetailGclNode.OrgTotalPrice := ANode.Rec.OrgTotalPrice.AsFloat;
  397. vDetailGclNode.MisQuantity := ANode.Rec.MisQuantity.AsFloat;
  398. vDetailGclNode.MisTotalPrice := ANode.Rec.MisTotalPrice.AsFloat;
  399. vDetailGclNode.OthQuantity := ANode.Rec.OthQuantity.AsFloat;
  400. vDetailGclNode.OthTotalPrice := ANode.Rec.OthTotalPrice.AsFloat;
  401. vDetailGclNode.Quantity := ANode.Rec.Quantity.AsFloat;
  402. vDetailGclNode.TotalPrice := ANode.Rec.TotalPrice.AsFloat;
  403. if Assigned(ANode.StageRec) then
  404. begin
  405. vDetailGclNode.CurDealQuantity := ANode.StageRec.DealQuantity.AsFloat;
  406. vDetailGclNode.CurDealTotalPrice := ANode.StageRec.DealTotalPrice.AsFloat;
  407. vDetailGclNode.CurQcQuantity := ANode.StageRec.QcQuantity.AsFloat;
  408. vDetailGclNode.CurQcTotalPrice := ANode.StageRec.QcTotalPrice.AsFloat;
  409. vDetailGclNode.CurGatherQuantity := ANode.StageRec.GatherQuantity.AsFloat;
  410. vDetailGclNode.CurGatherTotalPrice := ANode.StageRec.GatherTotalPrice.AsFloat;
  411. vDetailGclNode.PreDealQuantity := ANode.StageRec.PreDealQuantity.AsFloat;
  412. vDetailGclNode.PreDealTotalPrice := ANode.StageRec.PreDealTotalPrice.AsFloat;
  413. vDetailGclNode.PreQcQuantity := ANode.StageRec.PreQcQuantity.AsFloat;
  414. vDetailGclNode.PreQcTotalPrice := ANode.StageRec.PreQcTotalPrice.AsFloat;
  415. vDetailGclNode.PreGatherQuantity := ANode.StageRec.PreGatherQuantity.AsFloat;
  416. vDetailGclNode.PreGatherTotalPrice := ANode.StageRec.PreGatherTotalPrice.AsFloat;
  417. vDetailGclNode.EndDealQuantity := ANode.StageRec.EndDealQuantity.AsFloat;
  418. vDetailGclNode.EndDealTotalPrice := ANode.StageRec.EndDealTotalPrice.AsFloat;
  419. vDetailGclNode.EndQcQuantity := ANode.StageRec.EndQcQuantity.AsFloat;
  420. vDetailGclNode.EndQcTotalPrice := ANode.StageRec.EndQcTotalPrice.AsFloat;
  421. vDetailGclNode.EndGatherQuantity := ANode.StageRec.EndGatherQuantity.AsFloat;
  422. vDetailGclNode.EndGatherTotalPrice := ANode.StageRec.EndGatherTotalPrice.AsFloat;
  423. vDetailGclNode.PM_PreTotalPrice := ANode.StageRec.PM_PreTotalPrice.AsFloat;
  424. vDetailGclNode.PM_TotalPrice := ANode.StageRec.PM_TotalPrice.AsFloat;
  425. end;
  426. vDetailGclNode.AddDealQuantity := ANode.Rec.AddDealQuantity.AsFloat;
  427. vDetailGclNode.AddDealTotalPrice := ANode.Rec.AddDealTotalPrice.AsFloat;
  428. vDetailGclNode.AddQcQuantity := ANode.Rec.AddQcQuantity.AsFloat;
  429. vDetailGclNode.AddQcTotalPrice := ANode.Rec.AddQcTotalPrice.AsFloat;
  430. vDetailGclNode.AddGatherQuantity := ANode.Rec.AddGatherQuantity.AsFloat;
  431. vDetailGclNode.AddGatherTotalPrice := ANode.Rec.AddGatherTotalPrice.AsFloat;
  432. vDetailGclNode.LeafXmj := GetLeafXmj(ANode);
  433. vGclNode.AddLeafXmj(vDetailGclNode.LeafXmj);
  434. end;
  435. procedure TGclGatherModel.BeginGather;
  436. begin
  437. FGcls := TList.Create;
  438. FXmjs := TList.Create;
  439. FGather := TGatherNode.Create;
  440. end;
  441. procedure TGclGatherModel.CalculateAll;
  442. var
  443. iGcl: Integer;
  444. begin
  445. for iGcl := 0 to FGcls.Count - 1 do
  446. TGclNode(FGcls.Items[iGcl]).Calculate;
  447. CalculateGather;
  448. end;
  449. procedure TGclGatherModel.CalculateGather;
  450. var
  451. i: Integer;
  452. vGcl: TGclNode;
  453. begin
  454. FGather.ID := FNewGclID + 1;
  455. for i := 0 to FGcls.Count - 1 do
  456. begin
  457. vGcl := TGclNode(FGcls.Items[i]);
  458. if (PriceRoundTo(vGcl.Price) = 0) then Continue;
  459. FGather.TotalPrice := FGather.TotalPrice + vGcl.TotalPrice;
  460. FGather.OrgTotalPrice := FGather.OrgTotalPrice + vGcl.OrgTotalPrice;
  461. FGather.MisTotalPrice := FGather.MisTotalPrice + vGcl.MisTotalPrice;
  462. FGather.OthTotalPrice := FGather.OthTotalPrice + vGcl.OthTotalPrice;
  463. FGather.CurDealTotalPrice := FGather.CurDealTotalPrice + vGcl.CurDealTotalPrice;
  464. FGather.CurQcTotalPrice := FGather.CurQcTotalPrice + vGcl.CurQcTotalPrice;
  465. FGather.CurGatherTotalPrice := FGather.CurGatherTotalPrice + vGcl.CurGatherTotalPrice;
  466. FGather.PreDealTotalPrice := FGather.PreDealTotalPrice + vGcl.PreDealTotalPrice;
  467. FGather.PreQcTotalPrice := FGather.PreQcTotalPrice + vGcl.PreQcTotalPrice;
  468. FGather.PreGatherTotalPrice := FGather.PreGatherTotalPrice + vGcl.PreGatherTotalPrice;
  469. FGather.EndDealTotalPrice := FGather.EndDealTotalPrice + vGcl.EndDealTotalPrice;
  470. FGather.EndQcTotalPrice := FGather.EndQcTotalPrice + vGcl.EndQcTotalPrice;
  471. FGather.EndGatherTotalPrice := FGather.EndGatherTotalPrice + vGcl.EndGatherTotalPrice;
  472. FGather.AddDealTotalPrice := FGather.AddDealTotalPrice + vGcl.AddDealTotalPrice;
  473. FGather.AddQcTotalPrice := FGather.AddQcTotalPrice + vGcl.AddQcTotalPrice;
  474. FGather.AddGatherTotalPrice := FGather.AddGatherTotalPrice + vGcl.AddGatherTotalPrice;
  475. FGather.DealTotalPrice := FGather.DealTotalPrice + vGcl.DealTotalPrice;
  476. FGather.BGLTotalPrice := FGather.BGLTotalPrice + vGcl.BGLTotalPrice;
  477. end;
  478. FGather.Deal_BGLTotalPrice := Decimal.TotalPrice.RoundTo(FGather.TotalPrice + FGather.BGLTotalPrice);
  479. if FGather.Deal_BGLTotalPrice <> 0 then
  480. FGather.Deal_BGLPercent := CommonRoundTo(FGather.EndGatherTotalPrice/FGather.Deal_BGLTotalPrice*100, -2)
  481. else
  482. FGather.Deal_BGLPercent := 0;
  483. end;
  484. constructor TGclGatherModel.Create(AProjectData: TObject);
  485. begin
  486. FProjectData := AProjectData;
  487. FBillsTree := TProjectData(FProjectData).BillsMeasureData.BillsMeasureTree;
  488. FGatherDeal := False;
  489. FGatherBGL := False;
  490. FDecimal := TProjectData(FProjectData).ProjProperties.DecimalManager.Common;
  491. end;
  492. destructor TGclGatherModel.Destroy;
  493. begin
  494. inherited;
  495. end;
  496. procedure TGclGatherModel.EndGather;
  497. begin
  498. ClearObjects(FXmjs);
  499. FXmjs.Free;
  500. ClearObjects(FGcls);
  501. FGcls.Free;
  502. FGather.Free;
  503. end;
  504. procedure TGclGatherModel.Execute;
  505. begin
  506. BeginGather;
  507. try
  508. GatherBillsData;
  509. GatherDealData;
  510. GatherBGLData;
  511. CalculateAll;
  512. if Assigned(FWriteGatherData) then
  513. FWriteGatherData(FGcls, FXmjs, FGather);
  514. finally
  515. EndGather;
  516. end;
  517. end;
  518. function TGclGatherModel.FindGclNode(const AB_Code, AName, AUnits: string;
  519. APrice: Double): TGclNode;
  520. var
  521. i: Integer;
  522. vGcl: TGclNode;
  523. begin
  524. Result := nil;
  525. for i := 0 to FGcls.Count - 1 do
  526. begin
  527. vGcl := TGclNode(FGcls.Items[i]);
  528. if SameText(vGcl.B_Code, TrimRight(AB_Code)) and
  529. SameText(vGcl.Name, TrimRight(AName)) and
  530. SameText(vGcl.Units, TrimRight(AUnits)) and
  531. (abs(vGcl.Price - APrice) < 0.001) then
  532. begin
  533. Result := vGcl;
  534. Break;
  535. end;
  536. end;
  537. end;
  538. function TGclGatherModel.FindLeafXmj(
  539. ALeafXmj: TBillsIDTreeNode): TLeafXmjNode;
  540. var
  541. iXmj: Integer;
  542. vLeafXmj: TLeafXmjNode;
  543. begin
  544. Result := nil;
  545. for iXmj := 0 to FXmjs.Count - 1 do
  546. begin
  547. vLeafXmj := TLeafXmjNode(FXmjs.Items[iXmj]);
  548. if vLeafXmj.ID = ALeafXmj.ID then
  549. begin
  550. Result := vLeafXmj;
  551. Break;
  552. end;
  553. end;
  554. end;
  555. procedure TGclGatherModel.GatherBGLData;
  556. var
  557. vGclNode: TGclNode;
  558. DetailBGL: TDetailBGLNode;
  559. begin
  560. if not FGatherBGL then Exit;
  561. with TProjectData(FProjectData).BGLData do
  562. begin
  563. cdsBGBills.First;
  564. while not cdsBGBills.Eof do
  565. begin
  566. vGclNode := GetGclNode(cdsBGBillsB_Code.AsString, cdsBGBillsName.AsString,
  567. cdsBGBillsUnits.AsString, cdsBGBillsPrice.AsFloat);
  568. if cdsBGL.FindKey([cdsBGBillsBGID.AsInteger]) then
  569. begin
  570. DetailBGL := vGclNode.AddDetailBGL(NewDetailBGLID);
  571. DetailBGL.BGBillsID := cdsBGBillsID.AsInteger;
  572. DetailBGL.BGLCode := cdsBGLCode.AsString;
  573. DetailBGL.BGLName := cdsBGLName.AsString;
  574. DetailBGL.BGLApprovalCode := cdsBGLApprovalCode.AsString;
  575. DetailBGL.BGLDrawingCode := cdsBGLDrawingCode.AsString;
  576. DetailBGL.BGLID := cdsBGBillsBGID.AsInteger;
  577. DetailBGL.Quantity := cdsBGBillsQuantity.AsFloat;
  578. DetailBGL.TotalPrice := cdsBGBillsTotalPrice.AsFloat;
  579. end;
  580. cdsBGBills.Next;
  581. end;
  582. end;
  583. end;
  584. procedure TGclGatherModel.GatherBillsData;
  585. var
  586. i: Integer;
  587. vNode: TMeasureBillsIDTreeNode;
  588. begin
  589. for i := 0 to FBillsTree.Count - 1 do
  590. begin
  591. vNode := TMeasureBillsIDTreeNode(FBillsTree.Items[i]);
  592. if not vNode.HasChildren and (vNode.Rec.B_Code.AsString <> '') then
  593. AddBillsNode(vNode);
  594. end;
  595. end;
  596. procedure TGclGatherModel.GatherDealData;
  597. var
  598. vGclNode: TGclNode;
  599. vDetailDeal: TDetailDealNode;
  600. iDeal: Integer;
  601. Rec: TsdDataRecord;
  602. begin
  603. if not FGatherDeal then Exit;
  604. with TProjectData(FProjectData).DealBillsData do
  605. for iDeal := 0 to sddDealBills.RecordCount - 1 do
  606. begin
  607. Rec := sddDealBills.Records[iDeal];
  608. vGclNode := GetGclNode(Rec.ValueByName('B_Code').AsString, Rec.ValueByName('Name').AsString,
  609. Rec.ValueByName('Units').AsString, Rec.ValueByName('Price').AsFloat);
  610. vDetailDeal := vGclNode.AddDetailDeal(NewDetailDealID);
  611. vDetailDeal.Quantity := Rec.ValueByName('Quantity').AsFloat;
  612. vDetailDeal.TotalPrice := Rec.ValueByName('TotalPrice').AsFloat;
  613. end;
  614. end;
  615. function TGclGatherModel.GetGclNode(ARec: TBillsRecord): TGclNode;
  616. begin
  617. Result := GetGclNode(ARec.B_Code.AsString, ARec.Name.AsString,
  618. ARec.Units.AsString, ARec.Price.AsFloat);
  619. end;
  620. function TGclGatherModel.GetGclNode(const AB_Code, AName, AUnits: string;
  621. APrice: Double): TGclNode;
  622. begin
  623. Result := FindGclNode(AB_Code, AName, AUnits, APrice);
  624. if not Assigned(Result) then
  625. Result := NewGclNode(AB_Code, AName, AUnits, APrice);
  626. end;
  627. function TGclGatherModel.GetLeafXmj(
  628. ANode: TBillsIDTreeNode): TLeafXmjNode;
  629. function GetFirstXmjParent: TBillsIDTreeNode;
  630. begin
  631. Result := ANode;
  632. while Assigned(Result) and (Result.Rec.B_Code.AsString <> '') do
  633. Result := TBillsIDTreeNode(Result.Parent);
  634. end;
  635. var
  636. vFirstXmjParent: TBillsIDTreeNode;
  637. begin
  638. vFirstXmjParent := GetFirstXmjParent;
  639. Result := nil;
  640. if not Assigned(vFirstXmjParent) then Exit;
  641. Result := FindLeafXmj(vFirstXmjParent);
  642. if not Assigned(Result) then
  643. Result := NewLeafXmj(vFirstXmjParent);
  644. end;
  645. function TGclGatherModel.GetNewDetailBGLID: Integer;
  646. begin
  647. Result := FNewDetailBGLID;
  648. Inc(FNewDetailBGLID)
  649. end;
  650. function TGclGatherModel.GetNewDetailDealID: Integer;
  651. begin
  652. Result := FNewDetailDealID;
  653. Inc(FNewDetailDealID);
  654. end;
  655. function TGclGatherModel.GetNewDetailGclID: Integer;
  656. begin
  657. Result := FNewDetailGclID;
  658. Inc(FNewDetailGclID);
  659. end;
  660. function TGclGatherModel.NewGclNode(const AB_Code, AName, AUnits: string;
  661. APrice: Double): TGclNode;
  662. begin
  663. Result := TGclNode.Create(FNewGclID, FDecimal);
  664. FGcls.Add(Result);
  665. Result.B_Code := TrimRight(AB_Code);
  666. Result.Name := TrimRight(AName);
  667. Result.Units := TrimRight(AUnits);
  668. Result.Price := APrice;
  669. Inc(FNewGclID);
  670. end;
  671. function TGclGatherModel.NewLeafXmj(
  672. ALeafXmj: TBillsIDTreeNode): TLeafXmjNode;
  673. function GetPegNode(ANode: TBillsIDTreeNode): TBillsIDTreeNode;
  674. begin
  675. Result := nil;
  676. if not Assigned(ANode) then Exit;
  677. if CheckPeg(ANode.Rec.Name.AsString) then
  678. Result := ANode
  679. else
  680. Result := GetPegNode(TBillsIDTreeNode(ANode.Parent));
  681. end;
  682. var
  683. vPeg: TBillsIDTreeNode;
  684. begin
  685. vPeg := GetPegNode(ALeafXmj);
  686. Result := TLeafXmjNode.Create(ALeafXmj, vPeg);
  687. FXmjs.Add(Result);
  688. end;
  689. { TGclNode }
  690. function TGclNode.AddDetailBGL(AID: Integer): TDetailBGLNode;
  691. begin
  692. Result := TDetailBGLNode.Create(AID);
  693. FDetailBGLs.Add(Result);
  694. end;
  695. function TGclNode.AddDetailDeal(AID: Integer): TDetailDealNode;
  696. begin
  697. Result := TDetailDealNode.Create(AID);
  698. FDetailDeals.Add(Result);
  699. end;
  700. function TGclNode.AddDetailGcl(AID: Integer): TDetailGclNode;
  701. begin
  702. Result := TDetailGclNode.Create(AID);
  703. FDetailGcls.Add(Result);
  704. end;
  705. procedure TGclNode.AddLeafXmj(ALeafXmj: TLeafXmjNode);
  706. begin
  707. if FLeafXmjs.IndexOf(ALeafXmj) = -1 then
  708. FLeafXmjs.Add(ALeafXmj);
  709. end;
  710. procedure TGclNode.Calculate;
  711. begin
  712. InitCalculate;
  713. GatherDetailGcl;
  714. GatherDetailDeal;
  715. GatherDetailBGL;
  716. CalculateOther;
  717. end;
  718. procedure TGclNode.CalculateOther;
  719. begin
  720. FDeal_BGLQuantity := Decimal.Quantity.RoundTo(FQuantity + FBGLQuantity);
  721. FDeal_BGLTotalPrice := Decimal.TotalPrice.RoundTo(FTotalPrice + FBGLTotalPrice);
  722. if FDeal_BGLTotalPrice <> 0 then
  723. FDeal_BGLPercent := CommonRoundTo(FEndGatherTotalPrice/FDeal_BGLTotalPrice*100, -2)
  724. else
  725. FDeal_BGLPercent := 0;
  726. end;
  727. constructor TGclNode.Create(AID: Integer; ADecimal: TCalcDecimal);
  728. begin
  729. FID := AID;
  730. FDetailGcls := TList.Create;
  731. FDetailDeals := TList.Create;
  732. FDetailBGLs := TList.Create;
  733. FLeafXmjs := TList.Create;
  734. FDecimal := ADecimal;
  735. end;
  736. destructor TGclNode.Destroy;
  737. begin
  738. FLeafXmjs.Free;
  739. ClearObjects(FDetailBGLs);
  740. FDetailBGLs.Free;
  741. ClearObjects(FDetailDeals);
  742. FDetailDeals.Free;
  743. ClearObjects(FDetailGcls);
  744. FDetailGcls.Free;
  745. inherited;
  746. end;
  747. procedure TGclNode.GatherDetailBGL;
  748. var
  749. iBGL: Integer;
  750. vDetailBGL: TDetailBGLNode;
  751. begin
  752. for iBGL := 0 to DetailBGLCount - 1 do
  753. begin
  754. vDetailBGL := DetailBGL[iBGL];
  755. FBGLQuantity := FBGLQuantity + vDetailBGL.Quantity;
  756. FBGLTotalPrice := FBGLTotalPrice + vDetailBGL.TotalPrice;
  757. end;
  758. end;
  759. procedure TGclNode.GatherDetailDeal;
  760. var
  761. iDeal: Integer;
  762. vDetailDeal: TDetailDealNode;
  763. begin
  764. for iDeal := 0 to DetailDealCount - 1 do
  765. begin
  766. vDetailDeal := DetailDeal[iDeal];
  767. FDealQuantity := FDealQuantity + vDetailDeal.Quantity;
  768. FDealTotalPrice := FDealTotalPrice + vDetailDeal.TotalPrice;
  769. end;
  770. end;
  771. procedure TGclNode.GatherDetailGcl;
  772. var
  773. iGcl: Integer;
  774. vDetailGcl: TDetailGclNode;
  775. begin
  776. for iGcl := 0 to DetailGclCount - 1 do
  777. begin
  778. vDetailGcl := DetailGcl[iGcl];
  779. FOrgQuantity := FOrgQuantity + vDetailGcl.OrgQuantity;
  780. FOrgTotalPrice := FOrgTotalPrice + vDetailGcl.OrgTotalPrice;
  781. FMisQuantity := FMisQuantity + vDetailGcl.MisQuantity;
  782. FMisTotalPrice := FMisTotalPrice + vDetailGcl.MisTotalPrice;
  783. FOthQuantity := FOthQuantity + vDetailGcl.OthQuantity;
  784. FOthTotalPrice := FOthTotalPrice + vDetailGcl.OthTotalPrice;
  785. FQuantity := FQuantity + vDetailGcl.Quantity;
  786. FTotalPrice := FTotalPrice + vDetailGcl.TotalPrice;
  787. FCurDealQuantity := FCurDealQuantity + vDetailGcl.CurDealQuantity;
  788. FCurDealTotalPrice := FCurDealTotalPrice + vDetailGcl.CurDealTotalPrice;
  789. FCurQcQuantity := FCurQcQuantity + vDetailGcl.CurQcQuantity;
  790. FCurQcTotalPrice := FCurQcTotalPrice + vDetailGcl.CurQcTotalPrice;
  791. FCurGatherQuantity := FCurGatherQuantity + vDetailGcl.CurGatherQuantity;
  792. FCurGatherTotalPrice := FCurGatherTotalPrice + vDetailGcl.CurGatherTotalPrice;
  793. FPreDealQuantity := FPreDealQuantity + vDetailGcl.PreDealQuantity;
  794. FPreDealTotalPrice := FPreDealTotalPrice + vDetailGcl.PreDealTotalPrice;
  795. FPreQcQuantity := FPreQcQuantity + vDetailGcl.PreQcQuantity;
  796. FPreQcTotalPrice := FPreQcTotalPrice + vDetailGcl.PreQcTotalPrice;
  797. FPreGatherQuantity := FPreGatherQuantity + vDetailGcl.PreGatherQuantity;
  798. FPreGatherTotalPrice := FPreGatherTotalPrice + vDetailGcl.PreGatherTotalPrice;
  799. FEndDealQuantity := FEndDealQuantity + vDetailGcl.EndDealQuantity;
  800. FEndDealTotalPrice := FEndDealTotalPrice + vDetailGcl.EndDealTotalPrice;
  801. FEndQcQuantity := FEndQcQuantity + vDetailGcl.EndQcQuantity;
  802. FEndQcTotalPrice := FEndQcTotalPrice + vDetailGcl.EndQcTotalPrice;
  803. FEndGatherQuantity := FEndGatherQuantity + vDetailGcl.EndGatherQuantity;
  804. FEndGatherTotalPrice := FEndGatherTotalPrice + vDetailGcl.EndGatherTotalPrice;
  805. FAddDealQuantity := FAddDealQuantity + vDetailGcl.AddDealQuantity;
  806. FAddDealTotalPrice := FAddDealTotalPrice + vDetailGcl.AddDealTotalPrice;
  807. FAddQcQuantity := FAddQcQuantity + vDetailGcl.AddQcQuantity;
  808. FAddQcTotalPrice := FAddQcTotalPrice + vDetailGcl.AddQcTotalPrice;
  809. FAddGatherQuantity := FAddGatherQuantity + vDetailGcl.AddGatherQuantity;
  810. FAddGatherTotalPrice := FAddGatherTotalPrice + vDetailGcl.AddGatherTotalPrice;
  811. end;
  812. end;
  813. function TGclNode.GetDetailBGL(AIndex: Integer): TDetailBGLNode;
  814. begin
  815. Result := TDetailBGLNode(FDetailBGLs.Items[AIndex]);
  816. end;
  817. function TGclNode.GetDetailBGLCount: Integer;
  818. begin
  819. Result := FDetailBGLs.Count;
  820. end;
  821. function TGclNode.GetDetailDeal(AIndex: Integer): TDetailDealNode;
  822. begin
  823. Result := TDetailDealNode(FDetailDeals.Items[AIndex]);
  824. end;
  825. function TGclNode.GetDetailDealCount: Integer;
  826. begin
  827. Result := FDetailDeals.Count;
  828. end;
  829. function TGclNode.GetDetailGcl(AIndex: Integer): TDetailGclNode;
  830. begin
  831. Result := TDetailGclNode(FDetailGcls.Items[AIndex]);
  832. end;
  833. function TGclNode.GetDetailGclCount: Integer;
  834. begin
  835. Result := FDetailGcls.Count;
  836. end;
  837. function TGclNode.GetLeafXmj(AIndex: Integer): TLeafXmjNode;
  838. begin
  839. Result := TLeafXmjNode(FLeafXmjs.Items[AIndex]);
  840. end;
  841. function TGclNode.GetLeafXmjCount: Integer;
  842. begin
  843. Result := FLeafXmjs.Count;
  844. end;
  845. procedure TGclNode.InitCalculate;
  846. begin
  847. FOrgQuantity := 0;
  848. FOrgTotalPrice := 0;
  849. FMisQuantity := 0;
  850. FMisTotalPrice := 0;
  851. FOthQuantity := 0;
  852. FOthTotalPrice := 0;
  853. FQuantity := 0;
  854. FTotalPrice := 0;
  855. FCurDealQuantity := 0;
  856. FCurDealTotalPrice := 0;
  857. FCurQcQuantity := 0;
  858. FCurQcTotalPrice := 0;
  859. FCurGatherQuantity := 0;
  860. FCurGatherTotalPrice := 0;
  861. FPreDealQuantity := 0;
  862. FPreDealTotalPrice := 0;
  863. FPreQcQuantity := 0;
  864. FPreQcTotalPrice := 0;
  865. FPreGatherQuantity := 0;
  866. FPreGatherTotalPrice := 0;
  867. FEndDealQuantity := 0;
  868. FEndDealTotalPrice := 0;
  869. FEndQcQuantity := 0;
  870. FEndQcTotalPrice := 0;
  871. FEndGatherQuantity := 0;
  872. FEndGatherTotalPrice := 0;
  873. FAddDealQuantity := 0;
  874. FAddDealTotalPrice := 0;
  875. FAddQcQuantity := 0;
  876. FAddQcTotalPrice := 0;
  877. FAddGatherQuantity := 0;
  878. FAddGatherTotalPrice := 0;
  879. FDealQuantity := 0;
  880. FDealTotalPrice := 0;
  881. FBGLQuantity := 0;
  882. FBGLTotalPrice := 0;
  883. FDeal_BGLQuantity := 0;
  884. FDeal_BGLTotalPrice := 0;
  885. FDeal_BGLPercent := 0;
  886. end;
  887. procedure TGclNode.SetB_Code(const Value: string);
  888. begin
  889. FB_Code := Value;
  890. FIndexCode := B_CodeToIndexCode(FB_Code);
  891. end;
  892. { TDetailGclNode }
  893. constructor TDetailGclNode.Create(AID: Integer);
  894. begin
  895. FID := AID;
  896. end;
  897. function TDetailGclNode.GetPercent: Double;
  898. var
  899. fTotal: Double;
  900. begin
  901. fTotal := abs(FQuantity + FEndQcQuantity);
  902. if fTotal <> 0 then
  903. Result := CommonRoundTo(abs(FEndGatherQuantity) / fTotal * 100, -2)
  904. else
  905. Result := 0;
  906. end;
  907. { TDetailBGLNode }
  908. constructor TDetailBGLNode.Create(AID: Integer);
  909. begin
  910. FID := AID;
  911. end;
  912. { TDetailDealNode }
  913. constructor TDetailDealNode.Create(AID: Integer);
  914. begin
  915. FID := AID;
  916. end;
  917. { TLeafXmjNode }
  918. constructor TLeafXmjNode.Create(ALeafXmj, APeg: TBillsIDTreeNode);
  919. function GetPegName: string;
  920. begin
  921. if Assigned(APeg) then
  922. Result := APeg.Rec.Name.AsString
  923. else
  924. Result := '';
  925. end;
  926. // 取树结构的第ALevel层节点的名称(level从0开始)
  927. function GetNameByLevel(ANode: TBillsIDTreeNode; ALevel: Integer): string;
  928. begin
  929. Result := '';
  930. if not Assigned(ANode) then Exit;
  931. if ANode.Level = ALevel then
  932. Result := ANode.Rec.Name.AsString
  933. else if ANode.Level > ALevel then
  934. Result := GetNameByLevel(TBillsIDTreeNode(ANode.Parent), ALevel);
  935. end;
  936. function GetNameDanWei(ANode: TBillsIDTreeNode): string;
  937. begin
  938. // 取树结构的第二层节点的名称
  939. Result := GetNameByLevel(ANode, 1);
  940. end;
  941. // ANode为计量单元节点,APegNode为桩号节点
  942. function GetNameFenBu(ANode, APegNode: TBillsIDTreeNode): string;
  943. var
  944. vCurNode: TBillsIDTreeNode;
  945. begin
  946. // 如果计量单元节点的名称为桩号(转化为判断计量单元节点与桩号节点为同一个)
  947. if not Assigned(APegNode) or (ANode.ID = APegNode.ID) then
  948. // 取树结构的第三层节点的名称
  949. Result := GetNameByLevel(ANode, 2)
  950. // 否则,取桩号节点的子节点的名称
  951. else
  952. begin
  953. vCurNode := ANode;
  954. while vCurNode.Level > APegNode.Level + 1 do
  955. vCurNode := TBillsIDTreeNode(vCurNode.Parent);
  956. Result := vCurNode.Rec.Name.AsString;
  957. end;
  958. end;
  959. // ANode为计量单元节点,APegNode为桩号节点
  960. function GetNameFenXiang(ANode, APegNode: TBillsIDTreeNode): string;
  961. var
  962. iTopLevel: Integer;
  963. vCurNode: TBillsIDTreeNode;
  964. begin
  965. if Assigned(APegNode) then
  966. begin
  967. iTopLevel := 3;
  968. if APegNode.ID <> ANode.ID then
  969. iTopLevel := APegNode.Level + 2;
  970. Result := '';
  971. vCurNode := TBillsIDTreeNode(ANode.Parent);
  972. while vCurNode.Level >= iTopLevel do
  973. begin
  974. Result := vCurNode.Rec.Name.AsString + ';' + Result;
  975. vCurNode := TBillsIDTreeNode(vCurNode.Parent);
  976. end;
  977. end
  978. else
  979. Result := GetNameByLevel(ANode, 3);
  980. end;
  981. function GetNameUnit(ANode: TBillsIDTreeNode): string;
  982. begin
  983. Result := ANode.Rec.Name.AsString;
  984. end;
  985. function GetDrawingCode(ANode: TBillsIDTreeNode): string;
  986. begin
  987. Result := '';
  988. if not Assigned(ANode) then Exit;
  989. Result := ANode.Rec.DrawingCode.AsString;
  990. if Result = '' then
  991. Result := GetDrawingCode(TBillsIDTreeNode(ANode.Parent));
  992. end;
  993. function GetPosition(ANode, APegNode: TBillsIDTreeNode): string;
  994. begin
  995. // 如果计量单元节点的名称为桩号(转化为判断计量单元节点与桩号节点为同一个)
  996. if not Assigned(APegNode) or (ANode.ID = APegNode.ID) then
  997. // 取分项工程
  998. Result := GetNameFenXiang(ANode, APegNode)
  999. // 反之,取分项工程+计量单元
  1000. else
  1001. Result := GetNameFenXiang(ANode, APegNode) + GetNameUnit(ANode);
  1002. end;
  1003. begin
  1004. if not Assigned(ALeafXmj) then Exit;
  1005. FID := ALeafXmj.ID;
  1006. FXmjCode := ALeafXmj.Rec.Code.AsString;
  1007. FXmjName := ALeafXmj.Rec.Name.AsString;
  1008. FXmjUnits := ALeafXmj.Rec.Units.AsString;
  1009. FPeg := GetPegName;
  1010. FNameDanWei := GetNameDanWei(ALeafXmj);
  1011. FNameFenBu := GetNameFenBu(ALeafXmj, APeg);
  1012. FNameFenXiang := GetNameFenXiang(ALeafXmj, APeg);
  1013. FNameUnit := GetNameUnit(ALeafXmj);
  1014. FPosition := GetPosition(ALeafXmj, APeg);
  1015. FDrawingCode := GetDrawingCode(ALeafXmj);
  1016. end;
  1017. end.