rmHaBaiCustomizedDm.pas 48 KB

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