rmHaBaiCustomizedDm.pas 49 KB

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