GclBillsGatherModel.pas 33 KB

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