rmHaBaiCustomizedDm.pas 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  1. unit rmHaBaiCustomizedDm;
  2. // 内蒙古 哈白项目定制汇总表 严禁任何其他项目或标表调用该单元
  3. // 包括支表2/3/14/3-1/4-1
  4. interface
  5. uses
  6. SysUtils, Classes, DB, rmSelectProjectFrm, ProjectData, mDataRecord,
  7. BillsTree, DBClient;
  8. type
  9. TDoubleArray = array of Double;
  10. TStringArray = array of string;
  11. TGclNode = class
  12. private
  13. FB_Code: string;
  14. FIndexCode: string;
  15. FName: string;
  16. FUnits: string;
  17. FPrice: Double;
  18. FQuantity: Double;
  19. FTotalPrice: Double;
  20. FCurGatherQuantity: Double;
  21. FCurGatherTotalPrice: Double;
  22. FEndGatherQuantity: Double;
  23. FEndGatherTotalPrice: Double;
  24. FPreGatherQuantity: Double;
  25. FPreGatherTotalPrice: Double;
  26. FP_Quantity: TDoubleArray;
  27. FP_TotalPrice: TDoubleArray;
  28. FP_CurGatherQuantity: TDoubleArray;
  29. FP_CurGatherTotalPrice: TDoubleArray;
  30. FP_EndGatherQuantity: TDoubleArray;
  31. FP_EndGatherTotalPrice: TDoubleArray;
  32. procedure SetB_Code(const Value: string);
  33. function GetCurPercent: Double;
  34. function GetEndPercent: Double;
  35. public
  36. constructor Create(AProjectCount: Integer);
  37. property B_Code: string read FB_Code write SetB_Code;
  38. property IndexCode: string read FIndexCode;
  39. property Name: string read FName write FName;
  40. property Units: string read FUnits write FUnits;
  41. property Price: Double read FPrice write FPrice;
  42. property Quantity: Double read FQuantity write FQuantity;
  43. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  44. property CurGatherQuantity: Double read FCurGatherQuantity write FCurGatherQuantity;
  45. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  46. property EndGatherQuantity: Double read FEndGatherQuantity write FEndGatherQuantity;
  47. property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
  48. property PreGatherQuantity: Double read FPreGatherQuantity write FPreGatherQuantity;
  49. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  50. property P_Quantity: TDoubleArray read FP_Quantity write FP_Quantity;
  51. property P_TotalPrice: TDoubleArray read FP_TotalPrice write FP_TotalPrice;
  52. property P_CurGatherQuantity: TDoubleArray read FP_CurGatherQuantity write FP_CurGatherQuantity;
  53. property P_CurGatherTotalPrice: TDoubleArray read FP_CurGatherTotalPrice write FP_CurGatherTotalPrice;
  54. property P_EndGatherQuantity: TDoubleArray read FP_EndGatherQuantity write FP_EndGatherQuantity;
  55. property P_EndGatherTotalPrice: TDoubleArray read FP_EndGatherTotalPrice write FP_EndGatherTotalPrice;
  56. property CurPercent: Double read GetCurPercent;
  57. property EndPercent: Double read GetEndPercent;
  58. end;
  59. TGclChapter = class
  60. private
  61. FProjectCount: Integer;
  62. FGclNodes: TList;
  63. FChapterID: Integer;
  64. FChapterBegin: Integer;
  65. FChapterEnd: Integer;
  66. FChapterName: string;
  67. FName: string;
  68. FTotalPrice: Double;
  69. FCurGatherTotalPrice: Double;
  70. FEndGatherTotalPrice: Double;
  71. FPreGatherTotalPrice: Double;
  72. FP_TotalPrice: TDoubleArray;
  73. FP_CurGatherTotalPrice: TDoubleArray;
  74. FP_EndGatherTotalPrice: TDoubleArray;
  75. function GetGclNode(AIndex: Integer): TGclNode;
  76. function GetGclNodeCount: Integer;
  77. function GetCurPercent: Double;
  78. function GetEndPercent: Double;
  79. public
  80. constructor Create(AChapterID: Integer; const AName: string; AProjectCount: Integer);
  81. destructor Destroy; override;
  82. procedure AddGclNode(AGclNode: TGclNode);
  83. procedure CalculateChapter;
  84. property ChapterID: Integer read FChapterID;
  85. property ChapterBegin: Integer read FChapterBegin;
  86. property ChapterEnd: Integer read FChapterEnd;
  87. property ChapterName: string read FChapterName;
  88. property Name: string read FName;
  89. property TotalPrice: Double read FTotalPrice write FTotalPrice;
  90. property CurGatherTotalPrice: Double read FCurGatherTotalPrice write FCurGatherTotalPrice;
  91. property EndGatherTotalPrice: Double read FEndGatherTotalPrice write FEndGatherTotalPrice;
  92. property PreGatherTotalPrice: Double read FPreGatherTotalPrice write FPreGatherTotalPrice;
  93. property P_TotalPrice: TDoubleArray read FP_TotalPrice write FP_TotalPrice;
  94. property P_CurGatherTotalPrice: TDoubleArray read FP_CurGatherTotalPrice write FP_CurGatherTotalPrice;
  95. property P_EndGatherTotalPrice: TDoubleArray read FP_EndGatherTotalPrice write FP_EndGatherTotalPrice;
  96. property CurPercent: Double read GetCurPercent;
  97. property EndPercent: Double read GetEndPercent;
  98. property GclNodeCount: Integer read GetGclNodeCount;
  99. property GclNode[AIndex: Integer]: TGclNode read GetGclNode;
  100. end;
  101. TGclControl = class
  102. private
  103. FProjectCount: Integer;
  104. FProjectName: TStringArray;
  105. FGclNodes: TList;
  106. FGclChapters: TList;
  107. FGclChapterGather: TGclChapter;
  108. FOtherGcl: TGclChapter;
  109. function FindGclNode(ARec: TBillsRecord): TGclNode;
  110. function NewGclNode(ARec: TBillsRecord): TGclNode;
  111. function B_CodeToChapter(const AB_Code: string): Integer;
  112. procedure LinkGclChapter(AGclNode: TGclNode);
  113. function FindGclChapter(AChapterID: Integer): TGclChapter;
  114. procedure CalculateChapterGather;
  115. function GetGclChapterCount: Integer;
  116. function GetGclChapter(AIndex: Integer): TGclChapter;
  117. public
  118. constructor Create(AProjectCount: Integer);
  119. destructor Destroy;
  120. function AddGclNode(ANode: TBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
  121. procedure Calculate;
  122. property GclChapterCount: Integer read GetGclChapterCount;
  123. property GclChapter[AIndex: Integer]: TGclChapter read GetGclChapter;
  124. property GclChapterGather: TGclChapter read FGclChapterGather;
  125. property ProjectName: TStringArray read FProjectName write FProjectName;
  126. property ProjectCount: Integer read FProjectCount;
  127. end;
  128. TPayNode = class
  129. private
  130. FName: string;
  131. FIsMinus: Boolean;
  132. FCurTotalPrice: Double;
  133. FEndTotalPrice: Double;
  134. FPreTotalPrice: Double;
  135. public
  136. property Name: string read FName write FName;
  137. property IsMinus: Boolean read FIsMinus write FisMinus;
  138. property CurTotalPrice: Double read FCurTotalPrice write FCurTotalPrice;
  139. property EndTotalPrice: Double read FEndTotalPrice write FEndTotalPrice;
  140. property PreTotalPrice: Double read FPreTotalPrice write FPreTotalPrice;
  141. end;
  142. TDealPayControl = class
  143. private
  144. FPayNodes: TList;
  145. FGatherPayNode: TPayNode;
  146. function FindPayNode(const AName: string; AIsMinus: Boolean): TPayNode;
  147. function NewPayNode(const AName: string; AIsMinus: Boolean): TPayNode;
  148. function GetPayCount: Integer;
  149. function GetPayNode(AIndex: Integer): TPayNode;
  150. public
  151. constructor Create;
  152. destructor Destroy; override;
  153. function AddPayNode(const AName: string; AIsMinus: Boolean): TPayNode;
  154. property PayCount: Integer read GetPayCount;
  155. property PayNode[AIndex: Integer]: TPayNode read GetPayNode;
  156. property GatherPayNode: TPayNode read FGatherPayNode;
  157. end;
  158. // 分别对应5张定制汇总表的编号,详见文档
  159. THaBaiGatherType = (hbgt2, hbgt3, hbgt14, hbgt3_1, hbgt4_1);
  160. TrmHaBaiCustomizedData = class(TDataModule)
  161. cdsCustom2: TClientDataSet;
  162. cdsCustom2Chapter: TIntegerField;
  163. cdsCustom2Name: TWideStringField;
  164. cdsCustom2TotalPrice: TFloatField;
  165. cdsCustom2CTotalPrice: TFloatField;
  166. cdsCustom2GTotalPrice: TFloatField;
  167. cdsCustom2EndGatherTotalPrice: TFloatField;
  168. cdsCustom2PreGatherTotalPrice: TFloatField;
  169. cdsCustom2CurGatherTotalPrice: TFloatField;
  170. cdsCustom2Percent: TFloatField;
  171. cdsCustom3: TClientDataSet;
  172. cdsCustom3ChapterID: TIntegerField;
  173. cdsCustom3InnerPartID: TIntegerField;
  174. cdsCustom3IndexCode: TStringField;
  175. cdsCustom3B_Code: TWideStringField;
  176. cdsCustom3Name: TWideStringField;
  177. cdsCustom3Units: TWideStringField;
  178. cdsCustom3Price: TFloatField;
  179. cdsCustom3Quantity: TFloatField;
  180. cdsCustom3TotalPrice: TFloatField;
  181. cdsCustom3PreGatherQuantity: TFloatField;
  182. cdsCustom3PreGatherTotalPrice: TFloatField;
  183. cdsCustom3EndGatherQuantity: TFloatField;
  184. cdsCustom3EndGatherTotalPrice: TFloatField;
  185. cdsCustom3CurGatherQuantity: TFloatField;
  186. cdsCustom3CurGatherTotalPrice: TFloatField;
  187. cdsCustom3Percent: TFloatField;
  188. cdsCustom14: TClientDataSet;
  189. cdsCustom14IndexCode: TWideStringField;
  190. cdsCustom14B_Code: TWideStringField;
  191. cdsCustom14Name: TWideStringField;
  192. cdsCustom14Units: TWideStringField;
  193. cdsCustom14Price: TFloatField;
  194. cdsCustom14Quantity: TFloatField;
  195. cdsCustom14TotalPrice: TFloatField;
  196. cdsCustom14CertificateCode: TWideStringField;
  197. cdsCustomProj: TClientDataSet;
  198. cdsCustomProjProjectID: TIntegerField;
  199. cdsCustomProjProjectName: TWideStringField;
  200. cdsCustomProjChapterID: TIntegerField;
  201. cdsCustomProjInnerPartID: TIntegerField;
  202. cdsCustomProjIndexCode: TWideStringField;
  203. cdsCustomProjB_Code: TWideStringField;
  204. cdsCustomProjName: TWideStringField;
  205. cdsCustomProjUnits: TWideStringField;
  206. cdsCustomProjPrice: TFloatField;
  207. cdsCustomProjQuantity: TFloatField;
  208. cdsCustomProjTotalPrice: TFloatField;
  209. cdsCustomProjCurGatherQuantity: TFloatField;
  210. cdsCustomProjCurGatherTotalPrice: TFloatField;
  211. cdsCustomProjEndGatherQuantity: TFloatField;
  212. cdsCustomProjEndGatherTotalPrice: TFloatField;
  213. cdsCustomProjP_CurGatherQuantity: TFloatField;
  214. cdsCustomProjP_CurGatherTotalPrice: TFloatField;
  215. cdsCustomProjP_EndGatherQuantity: TFloatField;
  216. cdsCustomProjP_EndGatherTotalPrice: TFloatField;
  217. cdsCustomProjCurPercent: TFloatField;
  218. cdsCustomProjEndPercent: TFloatField;
  219. private
  220. FhbGatherType: THaBaiGatherType;
  221. FProjectData: TProjectData;
  222. FProjectName: string;
  223. FGclControl: TGclControl;
  224. FDealPayControl: TDealPayControl;
  225. procedure BeforeGather(AProjectCount: Integer);
  226. procedure AfterGather;
  227. procedure OpenProjectData(AProject: TSelectProject);
  228. procedure FreeProjectData;
  229. procedure GatherProject(AProject: TSelectProject; AProjectIndex: Integer);
  230. procedure FilterGcl(AProjectIndex: Integer);
  231. procedure FilterDealPay;
  232. procedure WriteFlowData;
  233. procedure WriteReport2;
  234. procedure WriteReport3;
  235. procedure WriteReport3_1;
  236. procedure WriteReport4_1;
  237. procedure WriteData;
  238. public
  239. function AssignData(AProjects: TList; AhbGatherType: THaBaiGatherType): TDataSet;
  240. end;
  241. implementation
  242. uses
  243. UtilMethods, ZhAPI, BillsCompileDm, sdDB, Globals, Math, BillsMeasureDm,
  244. ZJJLDm;
  245. {$R *.dfm}
  246. { TrmHaBaiCustomizedData }
  247. function TrmHaBaiCustomizedData.AssignData(AProjects: TList;
  248. AhbGatherType: THaBaiGatherType): TDataSet;
  249. var
  250. iProject: Integer;
  251. begin
  252. FhbGatherType := AhbGatherType;
  253. BeforeGather(AProjects.Count);
  254. try
  255. for iProject := 0 to AProjects.Count - 1 do
  256. GatherProject(TSelectProject(AProjects.Items[iProject]), iProject);
  257. FGclControl.Calculate;
  258. WriteData;
  259. finally
  260. AfterGather;
  261. case FhbGatherType of
  262. hbgt2: Result := cdsCustom2;
  263. hbgt3: Result := cdsCustom3;
  264. hbgt14: Result := cdsCustom14;
  265. hbgt3_1, hbgt4_1: Result := cdsCustomProj;
  266. end;
  267. end;
  268. end;
  269. procedure TrmHaBaiCustomizedData.BeforeGather(AProjectCount: Integer);
  270. begin
  271. cdsCustom2.DisableControls;
  272. cdsCustom2.Active := True;
  273. cdsCustom2.EmptyDataSet;
  274. cdsCustom3.DisableControls;
  275. cdsCustom3.Active := True;
  276. cdsCustom3.EmptyDataSet;
  277. cdsCustom14.DisableControls;
  278. cdsCustom14.Active := True;
  279. cdsCustom14.EmptyDataSet;
  280. cdsCustomProj.DisableControls;
  281. cdsCustomProj.Active := True;
  282. cdsCustomProj.EmptyDataSet;
  283. FGclControl := TGclControl.Create(AProjectCount);
  284. FDealPayControl := TDealPayControl.Create;
  285. end;
  286. procedure TrmHaBaiCustomizedData.AfterGather;
  287. begin
  288. FDealPayControl.Free;
  289. FGclControl.Free;
  290. cdsCustomProj.EnableControls;
  291. cdsCustom14.EnableControls;
  292. cdsCustom3.EnableControls;
  293. cdsCustom2.EnableControls;
  294. end;
  295. procedure TrmHaBaiCustomizedData.FreeProjectData;
  296. begin
  297. if not Assigned(OpenProjectManager.FindProjectData(FProjectData.ProjectID)) then
  298. FProjectData.Free;
  299. end;
  300. procedure TrmHaBaiCustomizedData.OpenProjectData(AProject: TSelectProject);
  301. var
  302. Rec: TsdDataRecord;
  303. begin
  304. FProjectData := OpenProjectManager.FindProjectData(AProject.ProjectID);
  305. Rec := ProjectManager.sddProjectsInfo.FindKey('idxID', AProject.ProjectID);
  306. if not Assigned(FProjectData) then
  307. begin
  308. FProjectData := TProjectData.Create;
  309. FProjectData.OpenForReport3(GetMyProjectsFilePath + Rec.ValueByName('FileName').AsString);
  310. end;
  311. FProjectName := Rec.ValueByName('Name').AsString;
  312. end;
  313. procedure TrmHaBaiCustomizedData.GatherProject(AProject: TSelectProject;
  314. AProjectIndex: Integer);
  315. begin
  316. OpenProjectData(AProject);
  317. try
  318. FGclControl.ProjectName[AProjectIndex] := FProjectName;
  319. if FhbGatherType in [hbgt2, hbgt3, hbgt3_1, hbgt4_1] then
  320. FilterGcl(AProjectIndex);
  321. if FhbGatherType = hbgt2 then
  322. FilterDealPay;
  323. if FhbGatherType = hbgt14 then
  324. WriteFlowData;
  325. finally
  326. FreeProjectData;
  327. end;
  328. end;
  329. procedure TrmHaBaiCustomizedData.FilterGcl(AProjectIndex: Integer);
  330. var
  331. i: Integer;
  332. vNode: TBillsIDTreeNode;
  333. GclNode: TGclNode;
  334. begin
  335. with FProjectData.BillsMeasureData do
  336. begin
  337. for i := 0 to BillsMeasureTree.Count - 1 do
  338. begin
  339. vNode := TBillsIDTreeNode(BillsMeasureTree.Items[i]);
  340. if not vNode.HasChildren and (vNode.Rec.B_Code.AsString <> '') then
  341. GclNode := FGclControl.AddGclNode(vNode, AProjectIndex);
  342. end;
  343. end;
  344. end;
  345. procedure TrmHaBaiCustomizedData.FilterDealPay;
  346. var
  347. sCurField, sPreField, sEndField: string;
  348. procedure GatherCommonDealPayData;
  349. var
  350. iRec: Integer;
  351. Rec, StageRec: TsdDataRecord;
  352. DealPay: TPayNode;
  353. begin
  354. with FProjectData.DealPaymentData do
  355. begin
  356. for iRec := 0 to sddDealPayment.RecordCount - 1 do
  357. begin
  358. Rec := sddDealPayment.Records[iRec];
  359. if SameText(Rec.ValueByName('Name').AsString, '本期完成计量') or
  360. SameText(Rec.ValueByName('Name').AsString, '本期应付') or
  361. SameText(Rec.ValueByName('Name').AsString, '本期实付') then
  362. Continue;
  363. StageRec := FProjectData.PhaseData.PhasePayData.PayRecord(Rec.ValueByName('ID').AsInteger);
  364. DealPay := FDealPayControl.AddPayNode(Rec.ValueByName('Name').AsString, Rec.ValueByName('IsMinus').AsBoolean);
  365. DealPay.CurTotalPrice := DealPay.CurTotalPrice + StageRec.ValueByName(sCurField).AsFloat;
  366. DealPay.PreTotalPrice := DealPay.PreTotalPrice + StageRec.ValueByName(sPreField).AsFloat;
  367. DealPay.EndTotalPrice := DealPay.EndTotalPrice + StageRec.ValueByName(sEndField).AsFloat;
  368. end;
  369. end;
  370. end;
  371. procedure GatherPayData;
  372. var
  373. Rec, StageRec: TsdDataRecord;
  374. begin
  375. Rec := FProjectData.DealPaymentData.DealPayRecord('本期应付');
  376. StageRec := FProjectData.PhaseData.PhasePayData.PayRecord(Rec.ValueByName('ID').AsInteger);
  377. with FDealPayControl.GatherPayNode do
  378. begin
  379. CurTotalPrice := CurTotalPrice + StageRec.ValueByName(sCurField).AsFloat;
  380. PreTotalPrice := PreTotalPrice + StageRec.ValueByName(sPreField).AsFloat;
  381. EndTotalPrice := EndTotalPrice + StageRec.ValueByName(sEndField).AsFloat;
  382. end;
  383. end;
  384. begin
  385. sCurField := 'TotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
  386. sPreField := 'PreTotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
  387. sEndField := 'EndTotalPrice' + IntToStr(FProjectData.PhaseData.AuditCount);
  388. GatherCommonDealPayData;
  389. GatherPayData;
  390. end;
  391. procedure TrmHaBaiCustomizedData.WriteData;
  392. begin
  393. case FhbGatherType of
  394. hbgt2: WriteReport2;
  395. hbgt3: WriteReport3;
  396. hbgt3_1: WriteReport3_1;
  397. hbgt4_1: WriteReport4_1;
  398. end;
  399. end;
  400. procedure TrmHaBaiCustomizedData.WriteReport2;
  401. procedure WriteGclChapter(AGclChapter: TGclChapter; const AName: string = '');
  402. begin
  403. cdsCustom2.Append;
  404. if AGclChapter.ChapterBegin > 0 then
  405. cdsCustom2Chapter.AsInteger := AGclChapter.ChapterBegin;
  406. if AName = '' then
  407. cdsCustom2Name.AsString := AGclChapter.Name
  408. else
  409. cdsCustom2Name.AsString := AName;
  410. cdsCustom2TotalPrice.AsFloat := AGclChapter.TotalPrice;
  411. cdsCustom2GTotalPrice.AsFloat := AGclChapter.TotalPrice;
  412. cdsCustom2EndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  413. cdsCustom2PreGatherTotalPrice.AsFloat := AGclChapter.PreGatherTotalPrice;
  414. cdsCustom2CurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  415. cdsCustom2.Post;
  416. end;
  417. procedure WriteBlankRecord(const AName: string);
  418. begin
  419. cdsCustom2.Append;
  420. cdsCustom2Name.AsString := AName;
  421. cdsCustom2.Post;
  422. end;
  423. procedure WritePayNode(APayNode: TPayNode; const AName: string = '');
  424. begin
  425. cdsCustom2.Append;
  426. if AName = '' then
  427. cdsCustom2Name.AsString := APayNode.Name
  428. else
  429. cdsCustom2Name.AsString := AName;
  430. cdsCustom2EndGatherTotalPrice.AsFloat := APayNode.EndTotalPrice;
  431. cdsCustom2PreGatherTotalPrice.AsFloat := APayNode.PreTotalPrice;
  432. cdsCustom2CurGatherTotalPrice.AsFloat := APayNode.CurTotalPrice;
  433. cdsCustom2.Post;
  434. end;
  435. var
  436. iIndex: Integer;
  437. begin
  438. for iIndex := 0 to FGclControl.GclChapterCount - 1 do
  439. WriteGclChapter(FGclControl.GclChapter[iIndex]);
  440. WriteGclChapter(FGclControl.GclChapterGather);
  441. WriteGclChapter(FGclControl.GclChapterGather, '小 计');
  442. WriteBlankRecord('价格调整');
  443. WriteBlankRecord('违约罚金');
  444. WriteBlankRecord('迟付款利息');
  445. WriteGclChapter(FGclControl.GclChapterGather, '合 计');
  446. for iIndex := 0 to FDealPayControl.PayCount - 1 do
  447. WritePayNode(FDealPayControl.PayNode[iIndex]);
  448. WritePayNode(FDealPayControl.GatherPayNode, '支 付');
  449. end;
  450. procedure TrmHaBaiCustomizedData.WriteReport3;
  451. procedure WriteChapterName(AGclChapter: TGclChapter);
  452. begin
  453. cdsCustom3.Append;
  454. cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
  455. cdsCustom3InnerPartID.AsInteger := 1;
  456. cdsCustom3B_Code.AsString := AGclChapter.ChapterName;
  457. cdsCustom3Name.AsString := AGclChapter.Name;
  458. cdsCustom3.Post;
  459. end;
  460. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  461. begin
  462. cdsCustom3.Append;
  463. cdsCustom3ChapterID.AsInteger := AChapterID;
  464. cdsCustom3InnerPartID.AsInteger := 2;
  465. cdsCustom3IndexCode.AsString := AGclNode.IndexCode;
  466. cdsCustom3B_Code.AsString := AGclNode.B_Code;
  467. cdsCustom3Name.AsString := AGclNode.Name;
  468. cdsCustom3Units.AsString := AGclNode.Units;
  469. cdsCustom3Price.AsFloat := AGclNode.Price;
  470. cdsCustom3Quantity.AsFloat := AGclNode.Quantity;
  471. cdsCustom3TotalPrice.AsFloat := AGclNode.TotalPrice;
  472. cdsCustom3CurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  473. cdsCustom3CurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  474. cdsCustom3EndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  475. cdsCustom3EndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  476. cdsCustom3PreGatherQuantity.AsFloat := AGclNode.PreGatherQuantity;
  477. cdsCustom3PreGatherTotalPrice.AsFloat := AGclNode.PreGatherTotalPrice;
  478. cdsCustom3.Post;
  479. end;
  480. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  481. begin
  482. cdsCustom3.Append;
  483. cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
  484. cdsCustom3InnerPartID.AsInteger := 3;
  485. if AName = '' then
  486. cdsCustom3Name.AsString := AGclChapter.Name
  487. else
  488. cdsCustom3Name.AsString := AName;
  489. cdsCustom3TotalPrice.AsFloat := AGclChapter.TotalPrice;
  490. cdsCustom3CurGatherQuantity.AsFloat := AGclChapter.CurGatherTotalPrice;
  491. cdsCustom3EndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  492. cdsCustom3PreGatherTotalPrice.AsFloat := AGclChapter.PreGatherTotalPrice;
  493. cdsCustom3.Post;
  494. end;
  495. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  496. var
  497. iGcl: Integer;
  498. begin
  499. if AGclChapter.GclNodeCount = 0 then Exit;
  500. WriteChapterName(AGclChapter);
  501. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  502. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  503. WriteChapterGather(AGclChapter, Format('%s 小计', [AGclChapter.ChapterName]));
  504. end;
  505. var
  506. iIndex: Integer;
  507. begin
  508. for iIndex := 0 to FGclControl.GclChapterCount - 1 do
  509. WriteGclChapterData(FGclControl.GclChapter[iIndex]);
  510. WriteChapterGather(FGclControl.GclChapterGather, '第100章~第900章 合计');
  511. end;
  512. procedure TrmHaBaiCustomizedData.WriteReport3_1;
  513. var
  514. iProject, iChapter: Integer;
  515. sProjectName: string;
  516. procedure WriteChapterName(AGclChapter: TGclChapter);
  517. begin
  518. cdsCustomProj.Append;
  519. cdsCustomProjProjectID.AsInteger := iProject;
  520. cdsCustomProjProjectName.AsString := sProjectName;
  521. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  522. cdsCustomProjInnerPartID.AsInteger := 1;
  523. cdsCustomProjB_Code.AsString := AGclChapter.ChapterName;
  524. cdsCustomProjName.AsString := AGclChapter.Name;
  525. cdsCustomProj.Post;
  526. end;
  527. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  528. begin
  529. cdsCustomProj.Append;
  530. cdsCustomProjProjectID.AsInteger := iProject;
  531. cdsCustomProjProjectName.AsString := sProjectName;
  532. cdsCustomProjChapterID.AsInteger := AChapterID;
  533. cdsCustomProjInnerPartID.AsInteger := 2;
  534. cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
  535. cdsCustomProjB_Code.AsString := AGclNode.B_Code;
  536. cdsCustomProjName.AsString := AGclNode.Name;
  537. cdsCustomProjUnits.AsString := AGclNode.Units;
  538. cdsCustomProjPrice.AsFloat := AGclNode.Price;
  539. cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
  540. cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
  541. cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  542. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  543. cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  544. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  545. cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
  546. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
  547. cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
  548. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
  549. cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
  550. cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
  551. cdsCustomProj.Post;
  552. end;
  553. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  554. begin
  555. cdsCustomProj.Append;
  556. cdsCustomProjProjectID.AsInteger := iProject;
  557. cdsCustomProjProjectName.AsString := sProjectName;
  558. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  559. cdsCustomProjInnerPartID.AsInteger := 3;
  560. if AName = '' then
  561. cdsCustomProjName.AsString := AGclChapter.Name
  562. else
  563. cdsCustomProjName.AsString := AName;
  564. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  565. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  566. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  567. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  568. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  569. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  570. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  571. cdsCustomProj.Post;
  572. end;
  573. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  574. var
  575. iGcl: Integer;
  576. begin
  577. if AGclChapter.GclNodeCount = 0 then Exit;
  578. WriteChapterName(AGclChapter);
  579. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  580. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  581. WriteChapterGather(AGclChapter, Format('%s 小计', [AGclChapter.ChapterName]));
  582. end;
  583. begin
  584. for iProject := 0 to FGclControl.ProjectCount - 1 do
  585. begin
  586. sProjectName := FGclControl.ProjectName[iProject];
  587. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  588. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  589. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  590. end;
  591. end;
  592. procedure TrmHaBaiCustomizedData.WriteReport4_1;
  593. var
  594. iProject, iChapter: Integer;
  595. sProjectName: string;
  596. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  597. begin
  598. cdsCustomProj.Append;
  599. cdsCustomProjProjectID.AsInteger := iProject;
  600. cdsCustomProjProjectName.AsString := sProjectName;
  601. cdsCustomProjChapterID.AsInteger := AChapterID;
  602. cdsCustomProjInnerPartID.AsInteger := 2;
  603. cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
  604. cdsCustomProjB_Code.AsString := AGclNode.B_Code;
  605. cdsCustomProjName.AsString := AGclNode.Name;
  606. cdsCustomProjUnits.AsString := AGclNode.Units;
  607. cdsCustomProjPrice.AsFloat := AGclNode.Price;
  608. cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
  609. cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
  610. cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  611. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  612. cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  613. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  614. cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
  615. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
  616. cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
  617. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
  618. cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
  619. cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
  620. cdsCustomProj.Post;
  621. end;
  622. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  623. var
  624. iGcl: Integer;
  625. begin
  626. if AGclChapter.GclNodeCount = 0 then Exit;
  627. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  628. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  629. end;
  630. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  631. begin
  632. cdsCustomProj.Append;
  633. cdsCustomProjProjectID.AsInteger := iProject;
  634. cdsCustomProjProjectName.AsString := sProjectName;
  635. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  636. cdsCustomProjInnerPartID.AsInteger := 3;
  637. if AName = '' then
  638. cdsCustomProjName.AsString := AGclChapter.Name
  639. else
  640. cdsCustomProjName.AsString := AName;
  641. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  642. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  643. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  644. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  645. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  646. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  647. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  648. cdsCustomProj.Post;
  649. end;
  650. begin
  651. for iProject := 0 to FGclControl.ProjectCount - 1 do
  652. begin
  653. sProjectName := FGclControl.ProjectName[iProject];
  654. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  655. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  656. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  657. end;
  658. end;
  659. procedure TrmHaBaiCustomizedData.WriteFlowData;
  660. procedure AddNodeData(ANode: TBillsIDTreeNode);
  661. begin
  662. cdsCustom14.Append;
  663. cdsCustom14IndexCode.AsString := ANode.Rec.IndexCode.AsString;
  664. cdsCustom14B_Code.AsString := ANode.Rec.B_Code.AsString;
  665. cdsCustom14Name.AsString := ANode.Rec.Name.AsString;
  666. cdsCustom14Units.AsString := ANode.Rec.Units.AsString;
  667. cdsCustom14Price.AsFloat := ANode.Rec.Price.AsFloat;
  668. cdsCustom14Quantity.AsFloat := ANode.StageRec.GatherQuantity.AsFloat;
  669. cdsCustom14TotalPrice.AsFloat := ANode.StageRec.GatherTotalPrice.AsFloat;
  670. with FProjectData.PhaseData.ZJJLData do
  671. if cdsZJJL.Locate('BillsID', ANode.ID, []) then
  672. cdsCustom14CertificateCode.AsString := cdsZJJLCertificateCode.AsString;
  673. cdsCustom14.Post;
  674. end;
  675. var
  676. iIndex: Integer;
  677. vNode: TBillsIDTreeNode;
  678. begin
  679. for iIndex := 0 to FProjectData.BillsMeasureData.BillsMeasureTree.Count - 1 do
  680. begin
  681. vNode := TBillsIDTreeNode(FProjectData.BillsMeasureData.BillsMeasureTree.Items[iIndex]);
  682. if (not vNode.HasChildren) and (vNode.Rec.B_Code.AsString <> '') and
  683. Assigned(vNode.StageRec) and (vNode.StageRec.GatherTotalPrice.AsFloat <> 0) then
  684. AddNodeData(vNode);
  685. end;
  686. end;
  687. { TGclNode }
  688. constructor TGclNode.Create(AProjectCount: Integer);
  689. begin
  690. SetLength(FP_Quantity, AProjectCount);
  691. SetLength(FP_TotalPrice, AProjectCount);
  692. SetLength(FP_CurGatherQuantity, AProjectCount);
  693. SetLength(FP_CurGatherTotalPrice, AProjectCount);
  694. SetLength(FP_EndGatherQuantity, AProjectCount);
  695. SetLength(FP_EndGatherTotalPrice, AProjectCount);
  696. end;
  697. function TGclNode.GetCurPercent: Double;
  698. begin
  699. if TotalPrice <> 0 then
  700. Result := CurGatherTotalPrice/TotalPrice*100
  701. else
  702. Result := 0;
  703. end;
  704. function TGclNode.GetEndPercent: Double;
  705. begin
  706. if TotalPrice <> 0 then
  707. Result := EndGatherTotalPrice/TotalPrice*100
  708. else
  709. Result := 0;
  710. end;
  711. procedure TGclNode.SetB_Code(const Value: string);
  712. begin
  713. FB_Code := Value;
  714. FIndexCode := B_CodeToIndexCode(FB_Code);
  715. end;
  716. { TGclControl }
  717. function TGclControl.AddGclNode(ANode: TBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
  718. begin
  719. Result := FindGclNode(ANode.Rec);
  720. if not Assigned(Result) then
  721. Result := NewGclNode(ANode.Rec);
  722. with ANode.Rec do
  723. begin
  724. Result.Quantity := Result.Quantity + Quantity.AsFloat;
  725. Result.TotalPrice := Result.TotalPrice + TotalPrice.AsFloat;
  726. Result.P_Quantity[AProjectIndex] := Result.P_Quantity[AProjectIndex] + Quantity.AsFloat;
  727. Result.P_TotalPrice[AProjectIndex] := Result.P_TotalPrice[AProjectIndex] + TotalPrice.AsFloat;
  728. end;
  729. if Assigned(ANode.StageRec) then
  730. with ANode.StageRec do
  731. begin
  732. Result.CurGatherQuantity := Result.CurGatherQuantity + GatherQuantity.AsFloat;
  733. Result.CurGatherTotalPrice := Result.CurGatherTotalPrice + GatherTotalPrice.AsFloat;
  734. Result.P_CurGatherQuantity[AProjectIndex] := Result.P_CurGatherQuantity[AProjectIndex] + GatherQuantity.AsFloat;
  735. Result.P_CurGatherTotalPrice[AProjectIndex] := Result.P_CurGatherTotalPrice[AProjectIndex] + GatherTotalPrice.AsFloat;
  736. Result.EndGatherQuantity := Result.EndGatherQuantity + EndGatherQuantity.AsFloat;
  737. Result.EndGatherTotalPrice := Result.EndGatherTotalPrice + EndGatherTotalPrice.AsFloat;
  738. Result.P_EndGatherQuantity[AProjectIndex] := Result.P_EndGatherQuantity[AProjectIndex] + EndGatherQuantity.AsFloat;
  739. Result.P_EndGatherTotalPrice[AProjectIndex] := Result.P_EndGatherTotalPrice[AProjectIndex] + EndGatherTotalPrice.AsFloat;
  740. Result.PreGatherQuantity := Result.PreGatherQuantity + PreGatherQuantity.AsFloat;
  741. Result.PreGatherTotalPrice := Result.PreGatherTotalPrice + PreGatherTotalPrice.AsFloat;
  742. end;
  743. end;
  744. function TGclControl.B_CodeToChapter(const AB_Code: string): Integer;
  745. var
  746. sgs: TStrings;
  747. iFirst, iSecond: Integer;
  748. begin
  749. Result := 0;
  750. sgs := TStringList.Create;
  751. try
  752. sgs.Delimiter := '-';
  753. sgs.DelimitedText := AB_Code;
  754. iFirst := StrToIntDef(sgs.Strings[0], 0);
  755. Result := Trunc(iFirst/100);
  756. finally
  757. sgs.Free;
  758. end;
  759. end;
  760. procedure TGclControl.CalculateChapterGather;
  761. var
  762. iIndex, iProject: Integer;
  763. vGclChapter: TGclChapter;
  764. begin
  765. FGclChapterGather.TotalPrice := 0;
  766. FGclChapterGather.CurGatherTotalPrice := 0;
  767. FGclChapterGather.EndGatherTotalPrice := 0;
  768. FGclChapterGather.PreGatherTotalPrice := 0;
  769. for iProject := 0 to FProjectCount - 1 do
  770. begin
  771. FGclChapterGather.P_TotalPrice[iProject] := 0;
  772. FGclChapterGather.P_CurGatherTotalPrice[iProject] := 0;
  773. FGclChapterGather.P_EndGatherTotalPrice[iProject] := 0;
  774. end;
  775. for iIndex := 0 to FGclChapters.Count - 1 do
  776. begin
  777. vGclChapter := TGclChapter(FGclChapters.Items[iIndex]);
  778. with FGclChapterGather do
  779. begin
  780. TotalPrice := TotalPrice + vGclChapter.TotalPrice;
  781. CurGatherTotalPrice := CurGatherTotalPrice + vGclChapter.CurGatherTotalPrice;
  782. EndGatherTotalPrice := EndGatherTotalPrice + vGclChapter.EndGatherTotalPrice;
  783. PreGatherTotalPrice := PreGatherTotalPrice + vGclChapter.PreGatherTotalPrice;
  784. for iProject := 0 to FProjectCount - 1 do
  785. begin
  786. P_TotalPrice[iProject] := P_TotalPrice[iProject] + vGclChapter.P_TotalPrice[iProject];
  787. P_CurGatherTotalPrice[iProject] := P_CurGatherTotalPrice[iProject] + vGclChapter.P_CurGatherTotalPrice[iProject];
  788. P_EndGatherTotalPrice[iProject] := P_EndGatherTotalPrice[iProject] + vGclChapter.P_EndGatherTotalPrice[iProject];
  789. end;
  790. end;
  791. end;
  792. end;
  793. constructor TGclControl.Create(AProjectCount: Integer);
  794. function CreateGclChapter(AChapterID: Integer; const AName: string): TGclChapter;
  795. begin
  796. Result := TGclChapter.Create(AChapterID, AName, FProjectCount);
  797. FGclChapters.Add(Result);
  798. end;
  799. begin
  800. FProjectCount := AProjectCount;
  801. SetLength(FProjectName, AProjectCount);
  802. FGclNodes := TList.Create;
  803. FGclChapters := TList.Create;
  804. CreateGclChapter(1, '总 则');
  805. CreateGclChapter(2, '路 基');
  806. CreateGclChapter(3, '路 面');
  807. CreateGclChapter(4, '桥梁、涵洞工程');
  808. CreateGclChapter(5, '隧 道');
  809. CreateGclChapter(6, '安全设计及预埋管线');
  810. CreateGclChapter(7, '绿化及环境保护工程');
  811. CreateGclChapter(8, '房建工程');
  812. CreateGclChapter(9, '机电工程');
  813. FOtherGcl := TGclChapter.Create(19, '非标准清单', FProjectCount);
  814. FGclChapterGather := TGclChapter.Create(20, '第100章至900章合计', FProjectCount);
  815. end;
  816. destructor TGclControl.Destroy;
  817. begin
  818. FOtherGcl.Free;
  819. FGclChapterGather.Free;
  820. ClearObjects(FGclChapters);
  821. FGclChapters.Free;
  822. ClearObjects(FGclNodes);
  823. FGclNodes.Free;
  824. end;
  825. function TGclControl.FindGclNode(ARec: TBillsRecord): TGclNode;
  826. var
  827. iIndex: Integer;
  828. vGclNode: TGclNode;
  829. bSameCode, bSameName, bSameUnits, bSamePrice: Boolean;
  830. begin
  831. Result := nil;
  832. for iIndex := 0 to FGclNodes.Count - 1 do
  833. begin
  834. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  835. if (vGclNode.B_Code = ARec.B_Code.AsString) and
  836. (vGclNode.Name = ARec.Name.AsString) and
  837. (vGclNode.Units = ARec.Units.AsString) and
  838. (vGclNode.Price = ARec.Price.AsFloat) then
  839. begin
  840. Result := vGclNode;
  841. Break;
  842. end;
  843. end;
  844. end;
  845. function TGclControl.FindGclChapter(AChapterID: Integer): TGclChapter;
  846. var
  847. iIndex: Integer;
  848. vChapter: TGclChapter;
  849. begin
  850. Result := nil;
  851. for iIndex := 0 to FGclChapters.Count - 1 do
  852. begin
  853. vChapter := TGclChapter(FGclChapters.Items[iIndex]);
  854. if vChapter.ChapterID = AChapterID then
  855. begin
  856. Result := vChapter;
  857. Break;
  858. end;
  859. end;
  860. end;
  861. function TGclControl.GetGclChapter(AIndex: Integer): TGclChapter;
  862. begin
  863. Result := TGclChapter(FGclChapters.Items[AIndex]);
  864. end;
  865. function TGclControl.GetGclChapterCount: Integer;
  866. begin
  867. Result := FGclChapters.Count;
  868. end;
  869. procedure TGclControl.LinkGclChapter(AGclNode: TGclNode);
  870. var
  871. iChapterID: Integer;
  872. vChapter: TGclChapter;
  873. begin
  874. iChapterID := B_CodeToChapter(AGclNode.B_Code);
  875. vChapter := FindGclChapter(iChapterID);
  876. if Assigned(vChapter) then
  877. vChapter.AddGclNode(AGclNode)
  878. else
  879. FOtherGcl.AddGclNode(AGclNode);
  880. end;
  881. function TGclControl.NewGclNode(ARec: TBillsRecord): TGclNode;
  882. begin
  883. Result := TGclNode.Create(FProjectCount);
  884. FGclNodes.Add(Result);
  885. Result.B_Code := ARec.B_Code.AsString;
  886. Result.Name := ARec.Name.AsString;
  887. Result.Units := ARec.Units.AsString;
  888. Result.Price := ARec.Price.AsFloat;
  889. LinkGclChapter(Result);
  890. end;
  891. procedure TGclControl.Calculate;
  892. var
  893. i: Integer;
  894. begin
  895. for i := 0 to GclChapterCount - 1 do
  896. GclChapter[i].CalculateChapter;
  897. CalculateChapterGather;
  898. end;
  899. { TGclChapter }
  900. procedure TGclChapter.AddGclNode(AGclNode: TGclNode);
  901. begin
  902. FGclNodes.Add(AGclNode);
  903. end;
  904. procedure TGclChapter.CalculateChapter;
  905. var
  906. iIndex, iProject: Integer;
  907. vGclNode: TGclNode;
  908. begin
  909. FTotalPrice := 0;
  910. FCurGatherTotalPrice := 0;
  911. FEndGatherTotalPrice := 0;
  912. FPreGatherTotalPrice := 0;
  913. for iProject := 0 to FProjectCount - 1 do
  914. begin
  915. FP_TotalPrice[iProject] := 0;
  916. FP_CurGatherTotalPrice[iProject] := 0;
  917. FP_EndGatherTotalPrice[iProject] := 0;
  918. end;
  919. for iIndex := 0 to FGclNodes.Count - 1 do
  920. begin
  921. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  922. FTotalPrice := FTotalPrice + vGclNode.TotalPrice;
  923. FCurGatherTotalPrice := FCurGatherTotalPrice + vGclNode.FCurGatherTotalPrice;
  924. FEndGatherTotalPrice := FEndGatherTotalPrice + vGclNode.FEndGatherTotalPrice;
  925. FPreGatherTotalPrice := FPreGatherTotalPrice + vGclNode.FPreGatherTotalPrice;
  926. for iProject := 0 to FProjectCount - 1 do
  927. begin
  928. FP_TotalPrice[iProject] := FP_TotalPrice[iProject] + vGclNode.P_TotalPrice[iProject];
  929. FP_CurGatherTotalPrice[iProject] := FP_CurGatherTotalPrice[iProject] + vGclNode.P_CurGatherTotalPrice[iProject];
  930. FP_EndGatherTotalPrice[iProject] := FP_EndGatherTotalPrice[iProject] + vGclNode.P_EndGatherTotalPrice[iProject];
  931. end;
  932. end;
  933. end;
  934. constructor TGclChapter.Create(AChapterID: Integer; const AName: string;
  935. AProjectCount: Integer);
  936. begin
  937. FGclNodes := TList.Create;
  938. FChapterID := AChapterID;
  939. if FChapterID < 19 then
  940. begin
  941. FChapterBegin := FChapterID * 100;
  942. FChapterEnd := FChapterBegin + 99;
  943. FChapterName := Format('第%d章', [FChapterBegin]);
  944. end;
  945. FName := AName;
  946. FProjectCount := AProjectCount;
  947. SetLength(FP_TotalPrice, FProjectCount);
  948. SetLength(FP_CurGatherTotalPrice, FProjectCount);
  949. SetLength(FP_EndGatherTotalPrice, FProjectCount);
  950. end;
  951. destructor TGclChapter.Destroy;
  952. begin
  953. FGclNodes.Free;
  954. inherited;
  955. end;
  956. function TGclChapter.GetCurPercent: Double;
  957. begin
  958. if TotalPrice <> 0 then
  959. Result := CurGatherTotalPrice/TotalPrice*100
  960. else
  961. Result := 0;
  962. end;
  963. function TGclChapter.GetEndPercent: Double;
  964. begin
  965. if TotalPrice <> 0 then
  966. Result := EndGatherTotalPrice/TotalPrice*100
  967. else
  968. Result := 0;
  969. end;
  970. function TGclChapter.GetGclNode(AIndex: Integer): TGclNode;
  971. begin
  972. Result := TGclNode(FGclNodes.Items[AIndex]);
  973. end;
  974. function TGclChapter.GetGclNodeCount: Integer;
  975. begin
  976. Result := FGclNodes.Count;
  977. end;
  978. { TDealPayControl }
  979. function TDealPayControl.AddPayNode(const AName: string;
  980. AIsMinus: Boolean): TPayNode;
  981. begin
  982. Result := FindPayNode(AName, AIsMinus);
  983. if not Assigned(Result) then
  984. Result := NewPayNode(AName, AIsMinus);
  985. end;
  986. constructor TDealPayControl.Create;
  987. begin
  988. FPayNodes := TList.Create;
  989. FGatherPayNode := TPayNode.Create;
  990. end;
  991. destructor TDealPayControl.Destroy;
  992. begin
  993. FGatherPayNode.Free;
  994. ClearObjects(FPayNodes);
  995. FPayNodes.Free;
  996. inherited;
  997. end;
  998. function TDealPayControl.FindPayNode(const AName: string;
  999. AIsMinus: Boolean): TPayNode;
  1000. var
  1001. iIndex: Integer;
  1002. vPayNode: TPayNode;
  1003. begin
  1004. Result := nil;
  1005. for iIndex := 0 to FPayNodes.Count -1 do
  1006. begin
  1007. vPayNode := TPayNode(FPayNodes.Items[iIndex]);
  1008. if (vPayNode.Name = AName) and (vPayNode.IsMinus = AIsMinus) then
  1009. begin
  1010. Result := vPayNode;
  1011. Break;
  1012. end;
  1013. end;
  1014. end;
  1015. function TDealPayControl.GetPayCount: Integer;
  1016. begin
  1017. Result := FPayNodes.Count;
  1018. end;
  1019. function TDealPayControl.GetPayNode(AIndex: Integer): TPayNode;
  1020. begin
  1021. Result := TPayNode(FPayNodes.Items[AIndex]);
  1022. end;
  1023. function TDealPayControl.NewPayNode(const AName: string;
  1024. AIsMinus: Boolean): TPayNode;
  1025. begin
  1026. Result := TPayNode.Create;
  1027. FPayNodes.Add(Result);
  1028. Result.Name := AName;
  1029. Result.IsMinus := AIsMinus;
  1030. end;
  1031. end.