GclBillsGatherModel.pas 29 KB

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