rmHaBaiCustomizedDm.pas 48 KB

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