rmHaBaiCustomizedDm.pas 44 KB

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