rmHaBaiCustomizedDm.pas 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482
  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: TMeasureBillsIDTreeNode; 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: TMeasureBillsIDTreeNode;
  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 := TMeasureBillsIDTreeNode(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. var
  520. iIndex: Integer;
  521. begin
  522. for iIndex := 0 to FGclControl.GclChapterCount - 1 do
  523. WriteGclChapter(FGclControl.GclChapter[iIndex]);
  524. WriteGclChapter(FGclControl.GclChapterGather);
  525. WriteGclChapter(FGclControl.GclChapterGather, '小 计');
  526. WriteBlankRecord('价格调整');
  527. WriteBlankRecord('违约罚金');
  528. WriteBlankRecord('迟付款利息');
  529. for iIndex := 0 to FDealPayControl.PlusPayCount - 1 do
  530. WritePayNode(FDealPayControl.PlusPayNode[iIndex]);
  531. WriteSpecialRecord;
  532. for iIndex := 0 to FDealPayControl.MinusPayCount - 1 do
  533. WritePayNode(FDealPayControl.MinusPayNode[iIndex]);
  534. WritePayNode(FDealPayControl.GatherPayNode, '支 付');
  535. end;
  536. procedure TrmHaBaiCustomizedData.WriteReport3;
  537. procedure WriteChapterName(AGclChapter: TGclChapter);
  538. begin
  539. cdsCustom3.Append;
  540. cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
  541. cdsCustom3InnerPartID.AsInteger := 1;
  542. cdsCustom3B_Code.AsString := AGclChapter.ChapterName;
  543. cdsCustom3Name.AsString := AGclChapter.Name;
  544. cdsCustom3.Post;
  545. end;
  546. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  547. begin
  548. cdsCustom3.Append;
  549. cdsCustom3ChapterID.AsInteger := AChapterID;
  550. cdsCustom3InnerPartID.AsInteger := 2;
  551. cdsCustom3IndexCode.AsString := AGclNode.IndexCode;
  552. cdsCustom3B_Code.AsString := AGclNode.B_Code;
  553. cdsCustom3Name.AsString := AGclNode.Name;
  554. cdsCustom3Units.AsString := AGclNode.Units;
  555. cdsCustom3Price.AsFloat := AGclNode.Price;
  556. cdsCustom3Quantity.AsFloat := AGclNode.Quantity;
  557. cdsCustom3TotalPrice.AsFloat := AGclNode.TotalPrice;
  558. cdsCustom3CurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  559. cdsCustom3CurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  560. cdsCustom3EndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  561. cdsCustom3EndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  562. cdsCustom3PreGatherQuantity.AsFloat := AGclNode.PreGatherQuantity;
  563. cdsCustom3PreGatherTotalPrice.AsFloat := AGclNode.PreGatherTotalPrice;
  564. cdsCustom3Percent.AsFloat := AGclNode.EndPercent;
  565. cdsCustom3.Post;
  566. end;
  567. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  568. begin
  569. cdsCustom3.Append;
  570. cdsCustom3ChapterID.AsInteger := AGclChapter.ChapterID;
  571. cdsCustom3InnerPartID.AsInteger := 3;
  572. if AName = '' then
  573. cdsCustom3Name.AsString := AGclChapter.Name
  574. else
  575. cdsCustom3Name.AsString := AName;
  576. cdsCustom3TotalPrice.AsFloat := AGclChapter.TotalPrice;
  577. cdsCustom3CurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  578. cdsCustom3EndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  579. cdsCustom3PreGatherTotalPrice.AsFloat := AGclChapter.PreGatherTotalPrice;
  580. cdsCustom3Percent.AsFloat := AGclChapter.EndPercent;
  581. cdsCustom3.Post;
  582. end;
  583. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  584. var
  585. iGcl: Integer;
  586. begin
  587. if AGclChapter.GclNodeCount = 0 then Exit;
  588. WriteChapterName(AGclChapter);
  589. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  590. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  591. WriteChapterGather(AGclChapter, Format('%s 小计', [AGclChapter.ChapterName]));
  592. end;
  593. var
  594. iIndex: Integer;
  595. begin
  596. for iIndex := 0 to FGclControl.GclChapterCount - 1 do
  597. WriteGclChapterData(FGclControl.GclChapter[iIndex]);
  598. WriteChapterGather(FGclControl.GclChapterGather, '第100章~第900章 合计');
  599. end;
  600. procedure TrmHaBaiCustomizedData.WriteReport3_1;
  601. var
  602. iProject, iChapter: Integer;
  603. sProjectName: string;
  604. procedure WriteChapterName(AGclChapter: TGclChapter);
  605. begin
  606. cdsCustomProj.Append;
  607. cdsCustomProjProjectID.AsInteger := iProject;
  608. cdsCustomProjProjectName.AsString := sProjectName;
  609. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  610. cdsCustomProjInnerPartID.AsInteger := 1;
  611. cdsCustomProjB_Code.AsString := AGclChapter.ChapterName;
  612. cdsCustomProjName.AsString := AGclChapter.Name;
  613. cdsCustomProj.Post;
  614. end;
  615. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  616. begin
  617. cdsCustomProj.Append;
  618. cdsCustomProjProjectID.AsInteger := iProject;
  619. cdsCustomProjProjectName.AsString := sProjectName;
  620. cdsCustomProjChapterID.AsInteger := AChapterID;
  621. cdsCustomProjInnerPartID.AsInteger := 2;
  622. cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
  623. cdsCustomProjB_Code.AsString := AGclNode.B_Code;
  624. cdsCustomProjName.AsString := AGclNode.Name;
  625. cdsCustomProjUnits.AsString := AGclNode.Units;
  626. cdsCustomProjPrice.AsFloat := AGclNode.Price;
  627. cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
  628. cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
  629. cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  630. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  631. cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  632. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  633. cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
  634. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
  635. cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
  636. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
  637. cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
  638. cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
  639. cdsCustomProj.Post;
  640. end;
  641. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  642. begin
  643. cdsCustomProj.Append;
  644. cdsCustomProjProjectID.AsInteger := iProject;
  645. cdsCustomProjProjectName.AsString := sProjectName;
  646. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  647. cdsCustomProjInnerPartID.AsInteger := 3;
  648. if AName = '' then
  649. cdsCustomProjName.AsString := AGclChapter.Name
  650. else
  651. cdsCustomProjName.AsString := AName;
  652. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  653. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  654. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  655. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  656. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  657. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  658. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  659. cdsCustomProj.Post;
  660. end;
  661. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  662. var
  663. iGcl: Integer;
  664. begin
  665. if AGclChapter.GclNodeCount = 0 then Exit;
  666. WriteChapterName(AGclChapter);
  667. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  668. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  669. WriteChapterGather(AGclChapter, Format('%s 小计', [AGclChapter.ChapterName]));
  670. end;
  671. begin
  672. for iProject := 0 to FGclControl.ProjectCount - 1 do
  673. begin
  674. sProjectName := FGclControl.ProjectName[iProject];
  675. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  676. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  677. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  678. end;
  679. end;
  680. procedure TrmHaBaiCustomizedData.WriteReport4_1;
  681. var
  682. iProject, iChapter, iSerial: Integer;
  683. sProjectName: string;
  684. procedure WriteGclNodeData(AGclNode: TGclNode; AChapterID: Integer);
  685. begin
  686. cdsCustomProj.Append;
  687. cdsCustomProjProjectID.AsInteger := iProject;
  688. cdsCustomProjProjectName.AsString := sProjectName;
  689. cdsCustomProjChapterID.AsInteger := AChapterID;
  690. cdsCustomProjInnerPartID.AsInteger := 2;
  691. cdsCustomProjIndexCode.AsString := AGclNode.IndexCode;
  692. cdsCustomProjB_Code.AsString := AGclNode.B_Code;
  693. cdsCustomProjName.AsString := AGclNode.Name;
  694. cdsCustomProjUnits.AsString := AGclNode.Units;
  695. cdsCustomProjPrice.AsFloat := AGclNode.Price;
  696. cdsCustomProjQuantity.AsFloat := AGclNode.Quantity;
  697. cdsCustomProjTotalPrice.AsFloat := AGclNode.TotalPrice;
  698. cdsCustomProjCurGatherQuantity.AsFloat := AGclNode.CurGatherQuantity;
  699. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclNode.CurGatherTotalPrice;
  700. cdsCustomProjEndGatherQuantity.AsFloat := AGclNode.EndGatherQuantity;
  701. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclNode.EndGatherTotalPrice;
  702. cdsCustomProjP_CurGatherQuantity.AsFloat := AGclNode.P_CurGatherQuantity[iProject];
  703. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclNode.P_CurGatherTotalPrice[iProject];
  704. cdsCustomProjP_EndGatherQuantity.AsFloat := AGclNode.P_EndGatherQuantity[iProject];
  705. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclNode.P_EndGatherTotalPrice[iProject];
  706. cdsCustomProjCurPercent.AsFloat := AGclNode.CurPercent;
  707. cdsCustomProjEndPercent.AsFloat := AGclNode.EndPercent;
  708. cdsCustomProj.Post;
  709. end;
  710. procedure WriteGclChapterData(AGclChapter: TGclChapter);
  711. var
  712. iGcl: Integer;
  713. begin
  714. if AGclChapter.GclNodeCount = 0 then Exit;
  715. for iGcl := 0 to AGclChapter.GclNodeCount - 1 do
  716. WriteGclNodeData(AGclChapter.GclNode[iGcl], AGclChapter.ChapterID);
  717. end;
  718. procedure WriteChapterGather(AGclChapter: TGclChapter; const AName: string = '');
  719. begin
  720. cdsCustomProj.Append;
  721. cdsCustomProjProjectID.AsInteger := iProject;
  722. cdsCustomProjProjectName.AsString := sProjectName;
  723. cdsCustomProjChapterID.AsInteger := AGclChapter.ChapterID;
  724. cdsCustomProjInnerPartID.AsInteger := 3;
  725. if AName = '' then
  726. cdsCustomProjName.AsString := AGclChapter.Name
  727. else
  728. cdsCustomProjName.AsString := AName;
  729. cdsCustomProjTotalPrice.AsFloat := AGclChapter.TotalPrice;
  730. cdsCustomProjCurGatherTotalPrice.AsFloat := AGclChapter.CurGatherTotalPrice;
  731. cdsCustomProjEndGatherTotalPrice.AsFloat := AGclChapter.EndGatherTotalPrice;
  732. cdsCustomProjP_CurGatherTotalPrice.AsFloat := AGclChapter.P_CurGatherTotalPrice[iProject];
  733. cdsCustomProjP_EndGatherTotalPrice.AsFloat := AGclChapter.P_EndGatherTotalPrice[iProject];
  734. cdsCustomProjCurPercent.AsFloat := AGclChapter.CurPercent;
  735. cdsCustomProjEndPercent.AsFloat := AGclChapter.EndPercent;
  736. cdsCustomProj.Post;
  737. end;
  738. procedure ResortSerialNo;
  739. var
  740. iSerialNo, iProject: Integer;
  741. begin
  742. iSerialNo := 1;
  743. cdsCustomProj.First;
  744. iProject := cdsCustomProjProjectID.AsInteger;
  745. while not cdsCustomProj.Eof do
  746. begin
  747. if iProject <> cdsCustomProjProjectID.AsInteger then
  748. begin
  749. iProject := cdsCustomProjProjectID.AsInteger;
  750. iSerialNo := 1;
  751. end;
  752. cdsCustomProj.Edit;
  753. cdsCustomProjSerialNo.AsInteger := iSerialNo;
  754. cdsCustomProj.Post;
  755. Inc(iSerialNo);
  756. cdsCustomProj.Next;
  757. end;
  758. end;
  759. begin
  760. for iProject := 0 to FGclControl.ProjectCount - 1 do
  761. begin
  762. sProjectName := FGclControl.ProjectName[iProject];
  763. for iChapter := 0 to FGclControl.GclChapterCount - 1 do
  764. WriteGclChapterData(FGclControl.GclChapter[iChapter]);
  765. WriteChapterGather(FGclControl.GclChapterGather, '第100章至第900章 合计');
  766. end;
  767. ResortSerialNo;
  768. end;
  769. procedure TrmHaBaiCustomizedData.WriteFlowData;
  770. procedure AddNodeData(ANode: TMeasureBillsIDTreeNode);
  771. begin
  772. cdsCustom14.Append;
  773. cdsCustom14IndexCode.AsString := ANode.Rec.IndexCode.AsString;
  774. cdsCustom14B_Code.AsString := ANode.Rec.B_Code.AsString;
  775. cdsCustom14Name.AsString := ANode.Rec.Name.AsString;
  776. cdsCustom14Units.AsString := ANode.Rec.Units.AsString;
  777. cdsCustom14Price.AsFloat := ANode.Rec.Price.AsFloat;
  778. cdsCustom14Quantity.AsFloat := ANode.StageRec.GatherQuantity.AsFloat;
  779. cdsCustom14TotalPrice.AsFloat := ANode.StageRec.GatherTotalPrice.AsFloat;
  780. with FProjectData.PhaseData.ZJJLData do
  781. if cdsZJJL.Locate('BillsID', ANode.ID, []) then
  782. cdsCustom14CertificateCode.AsString := cdsZJJLCertificateCode.AsString;
  783. cdsCustom14.Post;
  784. end;
  785. var
  786. iIndex: Integer;
  787. vNode: TMeasureBillsIDTreeNode;
  788. begin
  789. for iIndex := 0 to FProjectData.BillsMeasureData.BillsMeasureTree.Count - 1 do
  790. begin
  791. vNode := TMeasureBillsIDTreeNode(FProjectData.BillsMeasureData.BillsMeasureTree.Items[iIndex]);
  792. if (not vNode.HasChildren) and (vNode.Rec.B_Code.AsString <> '') and
  793. Assigned(vNode.StageRec) and (vNode.StageRec.GatherTotalPrice.AsFloat <> 0) then
  794. AddNodeData(vNode);
  795. end;
  796. end;
  797. function TrmHaBaiCustomizedData.AssignAssistantData(
  798. AhbGatherType: THaBaiGatherType): TDataSet;
  799. begin
  800. Result := nil;
  801. if (AhbGatherType = hbgt_CS) and (FhbGatherType = hbgt_CS) then
  802. Result := cdsCustomCS_2;
  803. end;
  804. procedure TrmHaBaiCustomizedData.WriteReportCounterSign;
  805. procedure WriteCounterSign1;
  806. var
  807. i: Integer;
  808. PayNode: TPayNode;
  809. begin
  810. cdsCustomCS_1.Append;
  811. cdsCustomCS_1PulsPayName.AsString := '本期完成金额';
  812. cdsCustomCS_1PulsPayTotalPrice.AsFloat := FDealPayControl.CompletePayNode.CurTotalPrice;
  813. cdsCustomCS_1.Post;
  814. for i := 0 to FDealPayControl.PlusPayCount - 1 do
  815. begin
  816. PayNode := FDealPayControl.PlusPayNode[i];
  817. cdsCustomCS_1.Append;
  818. cdsCustomCS_1PulsPayName.AsString := PayNode.Name;
  819. cdsCustomCS_1PulsPayTotalPrice.AsFloat := PayNode.CurTotalPrice;
  820. cdsCustomCS_1.Post;
  821. end;
  822. cdsCustomCS_1.Append;
  823. cdsCustomCS_1PulsPayName.AsString := '迟付款利息';
  824. cdsCustomCS_1.Post;
  825. cdsCustomCS_1.First;
  826. for i := 0 to FDealPayControl.MinusPayCount - 1 do
  827. begin
  828. PayNode := FDealPayControl.MinusPayNode[i];
  829. if cdsCustomCS_1.Eof then
  830. cdsCustomCS_1.Append
  831. else
  832. cdsCustomCS_1.Edit;
  833. cdsCustomCS_1MinusPayName.AsString := PayNode.Name;
  834. cdsCustomCS_1MinusPayTotalPrice.AsFloat := PayNode.CurTotalPrice;
  835. cdsCustomCS_1.Post;
  836. cdsCustomCS_1.Next;
  837. end;
  838. end;
  839. procedure WriteCounterSign2;
  840. begin
  841. cdsCustomCS_2.Append;
  842. cdsCustomCS_2DealTotalPrice.AsFloat := FDealTotalPrice;
  843. cdsCustomCS_2EndCompleteTotalPrice.AsFloat := FDealPayControl.CompletePayNode.EndTotalPrice;
  844. cdsCustomCS_2PreCompleteTotalPrice.AsFloat := FDealPayControl.CompletePayNode.PreTotalPrice;
  845. cdsCustomCS_2CurPayTotalPrice.AsFloat := FDealPayControl.GatherPayNode.CurTotalPrice;
  846. cdsCustomCS_2.Post;
  847. end;
  848. begin
  849. WriteCounterSign1;
  850. WriteCounterSign2;
  851. end;
  852. { TGclNode }
  853. procedure TGclNode.Calculate;
  854. var
  855. i: Integer;
  856. begin
  857. FTotalPrice := FPrice * FQuantity;
  858. FCurGatherTotalPrice := FPrice * FCurGatherQuantity;
  859. FEndGatherTotalPrice := FPrice * FEndGatherQuantity;
  860. FPreGatherTotalPrice := FPrice * FPreGatherQuantity;
  861. for i := 0 to FProjectCount - 1 do
  862. begin
  863. FP_TotalPrice[i] := FPrice * FP_Quantity[i];
  864. FP_CurGatherTotalPrice[i] := FPrice * FP_CurGatherQuantity[i];
  865. FP_EndGatherTotalPrice[i] := FPrice * FP_EndGatherQuantity[i];
  866. end;
  867. end;
  868. constructor TGclNode.Create(AProjectCount: Integer);
  869. begin
  870. FProjectCount := AProjectCount;
  871. SetLength(FP_Quantity, FProjectCount);
  872. SetLength(FP_TotalPrice, FProjectCount);
  873. SetLength(FP_CurGatherQuantity, FProjectCount);
  874. SetLength(FP_CurGatherTotalPrice, FProjectCount);
  875. SetLength(FP_EndGatherQuantity, FProjectCount);
  876. SetLength(FP_EndGatherTotalPrice, FProjectCount);
  877. end;
  878. function TGclNode.GetCurPercent: Double;
  879. begin
  880. if TotalPrice <> 0 then
  881. Result := CurGatherTotalPrice/TotalPrice*100
  882. else
  883. Result := 0;
  884. end;
  885. function TGclNode.GetEndPercent: Double;
  886. begin
  887. if TotalPrice <> 0 then
  888. Result := EndGatherTotalPrice/TotalPrice*100
  889. else
  890. Result := 0;
  891. end;
  892. procedure TGclNode.SetB_Code(const Value: string);
  893. begin
  894. FB_Code := Value;
  895. FIndexCode := B_CodeToIndexCode(FB_Code);
  896. end;
  897. { TGclControl }
  898. function TGclControl.AddGclNode(ANode: TMeasureBillsIDTreeNode; AProjectIndex: Integer): TGclNode;
  899. begin
  900. Result := FindGclNode(ANode.Rec);
  901. if not Assigned(Result) then
  902. Result := NewGclNode(ANode.Rec);
  903. with ANode.Rec do
  904. begin
  905. Result.Quantity := Result.Quantity + Quantity.AsFloat;
  906. Result.TotalPrice := Result.TotalPrice + TotalPrice.AsFloat;
  907. Result.P_Quantity[AProjectIndex] := Result.P_Quantity[AProjectIndex] + Quantity.AsFloat;
  908. Result.P_TotalPrice[AProjectIndex] := Result.P_TotalPrice[AProjectIndex] + TotalPrice.AsFloat;
  909. end;
  910. if Assigned(ANode.StageRec) then
  911. with ANode.StageRec do
  912. begin
  913. Result.CurGatherQuantity := Result.CurGatherQuantity + GatherQuantity.AsFloat;
  914. Result.CurGatherTotalPrice := Result.CurGatherTotalPrice + GatherTotalPrice.AsFloat;
  915. Result.P_CurGatherQuantity[AProjectIndex] := Result.P_CurGatherQuantity[AProjectIndex] + GatherQuantity.AsFloat;
  916. Result.P_CurGatherTotalPrice[AProjectIndex] := Result.P_CurGatherTotalPrice[AProjectIndex] + GatherTotalPrice.AsFloat;
  917. Result.EndGatherQuantity := Result.EndGatherQuantity + EndGatherQuantity.AsFloat;
  918. Result.EndGatherTotalPrice := Result.EndGatherTotalPrice + EndGatherTotalPrice.AsFloat;
  919. Result.P_EndGatherQuantity[AProjectIndex] := Result.P_EndGatherQuantity[AProjectIndex] + EndGatherQuantity.AsFloat;
  920. Result.P_EndGatherTotalPrice[AProjectIndex] := Result.P_EndGatherTotalPrice[AProjectIndex] + EndGatherTotalPrice.AsFloat;
  921. Result.PreGatherQuantity := Result.PreGatherQuantity + PreGatherQuantity.AsFloat;
  922. Result.PreGatherTotalPrice := Result.PreGatherTotalPrice + PreGatherTotalPrice.AsFloat;
  923. end;
  924. end;
  925. function TGclControl.B_CodeToChapter(const AB_Code: string): Integer;
  926. var
  927. sgs: TStrings;
  928. iFirst, iSecond: Integer;
  929. begin
  930. Result := 0;
  931. sgs := TStringList.Create;
  932. try
  933. sgs.Delimiter := '-';
  934. sgs.DelimitedText := AB_Code;
  935. iFirst := StrToIntDef(sgs.Strings[0], 0);
  936. Result := Trunc(iFirst/100);
  937. if (Result >= 90) and (Result < 100) then
  938. Result := 9;
  939. finally
  940. sgs.Free;
  941. end;
  942. end;
  943. procedure TGclControl.CalculateChapterGather;
  944. var
  945. iIndex, iProject: Integer;
  946. vGclChapter: TGclChapter;
  947. begin
  948. FGclChapterGather.TotalPrice := 0;
  949. FGclChapterGather.CurGatherTotalPrice := 0;
  950. FGclChapterGather.EndGatherTotalPrice := 0;
  951. FGclChapterGather.PreGatherTotalPrice := 0;
  952. for iProject := 0 to FProjectCount - 1 do
  953. begin
  954. FGclChapterGather.P_TotalPrice[iProject] := 0;
  955. FGclChapterGather.P_CurGatherTotalPrice[iProject] := 0;
  956. FGclChapterGather.P_EndGatherTotalPrice[iProject] := 0;
  957. end;
  958. for iIndex := 0 to FGclChapters.Count - 1 do
  959. begin
  960. vGclChapter := TGclChapter(FGclChapters.Items[iIndex]);
  961. with FGclChapterGather do
  962. begin
  963. TotalPrice := TotalPrice + vGclChapter.TotalPrice;
  964. CurGatherTotalPrice := CurGatherTotalPrice + vGclChapter.CurGatherTotalPrice;
  965. EndGatherTotalPrice := EndGatherTotalPrice + vGclChapter.EndGatherTotalPrice;
  966. PreGatherTotalPrice := PreGatherTotalPrice + vGclChapter.PreGatherTotalPrice;
  967. for iProject := 0 to FProjectCount - 1 do
  968. begin
  969. P_TotalPrice[iProject] := P_TotalPrice[iProject] + vGclChapter.P_TotalPrice[iProject];
  970. P_CurGatherTotalPrice[iProject] := P_CurGatherTotalPrice[iProject] + vGclChapter.P_CurGatherTotalPrice[iProject];
  971. P_EndGatherTotalPrice[iProject] := P_EndGatherTotalPrice[iProject] + vGclChapter.P_EndGatherTotalPrice[iProject];
  972. end;
  973. end;
  974. end;
  975. end;
  976. constructor TGclControl.Create(AProjectCount: Integer);
  977. function CreateGclChapter(AChapterID: Integer; const AName: string): TGclChapter;
  978. begin
  979. Result := TGclChapter.Create(AChapterID, AName, FProjectCount);
  980. FGclChapters.Add(Result);
  981. end;
  982. begin
  983. FProjectCount := AProjectCount;
  984. SetLength(FProjectName, AProjectCount);
  985. FGclNodes := TList.Create;
  986. FGclChapters := TList.Create;
  987. CreateGclChapter(1, '总 则');
  988. CreateGclChapter(2, '路 基');
  989. CreateGclChapter(3, '路 面');
  990. CreateGclChapter(4, '桥梁、涵洞工程');
  991. CreateGclChapter(5, '隧 道');
  992. CreateGclChapter(6, '安全设计及预埋管线');
  993. CreateGclChapter(7, '绿化及环境保护工程');
  994. CreateGclChapter(8, '房建工程');
  995. CreateGclChapter(9, '机电工程');
  996. FOtherGcl := TGclChapter.Create(19, '非标准清单', FProjectCount);
  997. FGclChapterGather := TGclChapter.Create(20, '第100章至900章合计', FProjectCount);
  998. end;
  999. destructor TGclControl.Destroy;
  1000. begin
  1001. FOtherGcl.Free;
  1002. FGclChapterGather.Free;
  1003. ClearObjects(FGclChapters);
  1004. FGclChapters.Free;
  1005. ClearObjects(FGclNodes);
  1006. FGclNodes.Free;
  1007. end;
  1008. function TGclControl.FindGclNode(ARec: TBillsRecord): TGclNode;
  1009. var
  1010. iIndex: Integer;
  1011. vGclNode: TGclNode;
  1012. bSameCode, bSameName, bSameUnits, bSamePrice: Boolean;
  1013. begin
  1014. Result := nil;
  1015. for iIndex := 0 to FGclNodes.Count - 1 do
  1016. begin
  1017. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  1018. if (vGclNode.B_Code = ARec.B_Code.AsString) and
  1019. (vGclNode.Name = ARec.Name.AsString) and
  1020. (vGclNode.Units = ARec.Units.AsString) and
  1021. (vGclNode.Price = ARec.Price.AsFloat) then
  1022. begin
  1023. Result := vGclNode;
  1024. Break;
  1025. end;
  1026. end;
  1027. end;
  1028. function TGclControl.FindGclChapter(AChapterID: Integer): TGclChapter;
  1029. var
  1030. iIndex: Integer;
  1031. vChapter: TGclChapter;
  1032. begin
  1033. Result := nil;
  1034. for iIndex := 0 to FGclChapters.Count - 1 do
  1035. begin
  1036. vChapter := TGclChapter(FGclChapters.Items[iIndex]);
  1037. if vChapter.ChapterID = AChapterID then
  1038. begin
  1039. Result := vChapter;
  1040. Break;
  1041. end;
  1042. end;
  1043. end;
  1044. function TGclControl.GetGclChapter(AIndex: Integer): TGclChapter;
  1045. begin
  1046. Result := TGclChapter(FGclChapters.Items[AIndex]);
  1047. end;
  1048. function TGclControl.GetGclChapterCount: Integer;
  1049. begin
  1050. Result := FGclChapters.Count;
  1051. end;
  1052. procedure TGclControl.LinkGclChapter(AGclNode: TGclNode);
  1053. var
  1054. iChapterID: Integer;
  1055. vChapter: TGclChapter;
  1056. begin
  1057. iChapterID := B_CodeToChapter(AGclNode.B_Code);
  1058. vChapter := FindGclChapter(iChapterID);
  1059. if Assigned(vChapter) then
  1060. vChapter.AddGclNode(AGclNode)
  1061. else
  1062. FOtherGcl.AddGclNode(AGclNode);
  1063. end;
  1064. function TGclControl.NewGclNode(ARec: TBillsRecord): TGclNode;
  1065. begin
  1066. Result := TGclNode.Create(FProjectCount);
  1067. FGclNodes.Add(Result);
  1068. Result.B_Code := ARec.B_Code.AsString;
  1069. Result.Name := ARec.Name.AsString;
  1070. Result.Units := ARec.Units.AsString;
  1071. Result.Price := ARec.Price.AsFloat;
  1072. LinkGclChapter(Result);
  1073. end;
  1074. procedure TGclControl.Calculate;
  1075. var
  1076. i: Integer;
  1077. begin
  1078. for i := 0 to GclChapterCount - 1 do
  1079. GclChapter[i].CalculateChapter;
  1080. CalculateChapterGather;
  1081. end;
  1082. procedure TGclControl.ReCalculateTotalPrice;
  1083. var
  1084. iGcl: Integer;
  1085. begin
  1086. for iGcl := 0 to FGclNodes.Count - 1 do
  1087. TGclNode(FGclNodes[iGcl]).Calculate;
  1088. end;
  1089. { TGclChapter }
  1090. procedure TGclChapter.AddGclNode(AGclNode: TGclNode);
  1091. begin
  1092. FGclNodes.Add(AGclNode);
  1093. end;
  1094. procedure TGclChapter.CalculateChapter;
  1095. var
  1096. iIndex, iProject: Integer;
  1097. vGclNode: TGclNode;
  1098. begin
  1099. FTotalPrice := 0;
  1100. FCurGatherTotalPrice := 0;
  1101. FEndGatherTotalPrice := 0;
  1102. FPreGatherTotalPrice := 0;
  1103. for iProject := 0 to FProjectCount - 1 do
  1104. begin
  1105. FP_TotalPrice[iProject] := 0;
  1106. FP_CurGatherTotalPrice[iProject] := 0;
  1107. FP_EndGatherTotalPrice[iProject] := 0;
  1108. end;
  1109. for iIndex := 0 to FGclNodes.Count - 1 do
  1110. begin
  1111. vGclNode := TGclNode(FGclNodes.Items[iIndex]);
  1112. FTotalPrice := FTotalPrice + vGclNode.TotalPrice;
  1113. FCurGatherTotalPrice := FCurGatherTotalPrice + vGclNode.FCurGatherTotalPrice;
  1114. FEndGatherTotalPrice := FEndGatherTotalPrice + vGclNode.FEndGatherTotalPrice;
  1115. FPreGatherTotalPrice := FPreGatherTotalPrice + vGclNode.FPreGatherTotalPrice;
  1116. for iProject := 0 to FProjectCount - 1 do
  1117. begin
  1118. FP_TotalPrice[iProject] := FP_TotalPrice[iProject] + vGclNode.P_TotalPrice[iProject];
  1119. FP_CurGatherTotalPrice[iProject] := FP_CurGatherTotalPrice[iProject] + vGclNode.P_CurGatherTotalPrice[iProject];
  1120. FP_EndGatherTotalPrice[iProject] := FP_EndGatherTotalPrice[iProject] + vGclNode.P_EndGatherTotalPrice[iProject];
  1121. end;
  1122. end;
  1123. end;
  1124. constructor TGclChapter.Create(AChapterID: Integer; const AName: string;
  1125. AProjectCount: Integer);
  1126. begin
  1127. FGclNodes := TList.Create;
  1128. FChapterID := AChapterID;
  1129. if FChapterID < 19 then
  1130. begin
  1131. FChapterBegin := FChapterID * 100;
  1132. FChapterEnd := FChapterBegin + 99;
  1133. FChapterName := Format('第%d章', [FChapterBegin]);
  1134. end;
  1135. FName := AName;
  1136. FProjectCount := AProjectCount;
  1137. SetLength(FP_TotalPrice, FProjectCount);
  1138. SetLength(FP_CurGatherTotalPrice, FProjectCount);
  1139. SetLength(FP_EndGatherTotalPrice, FProjectCount);
  1140. end;
  1141. destructor TGclChapter.Destroy;
  1142. begin
  1143. FGclNodes.Free;
  1144. inherited;
  1145. end;
  1146. function TGclChapter.GetCurPercent: Double;
  1147. begin
  1148. if TotalPrice <> 0 then
  1149. Result := CurGatherTotalPrice/TotalPrice*100
  1150. else
  1151. Result := 0;
  1152. end;
  1153. function TGclChapter.GetEndPercent: Double;
  1154. begin
  1155. if TotalPrice <> 0 then
  1156. Result := EndGatherTotalPrice/TotalPrice*100
  1157. else
  1158. Result := 0;
  1159. end;
  1160. function TGclChapter.GetGclNode(AIndex: Integer): TGclNode;
  1161. begin
  1162. Result := TGclNode(FGclNodes.Items[AIndex]);
  1163. end;
  1164. function TGclChapter.GetGclNodeCount: Integer;
  1165. begin
  1166. Result := FGclNodes.Count;
  1167. end;
  1168. { TDealPayControl }
  1169. function TDealPayControl.AddMinusPayNode(const AName: string): TPayNode;
  1170. begin
  1171. Result := FindMinusPayNode(AName);
  1172. if not Assigned(Result) then
  1173. Result := NewMinusPayNode(AName);
  1174. end;
  1175. function TDealPayControl.AddPayNode(const AName: string;
  1176. AIsMinus: Boolean): TPayNode;
  1177. begin
  1178. if AIsMinus then
  1179. Result := AddMinusPayNode(AName)
  1180. else
  1181. Result := AddPlusPayNode(AName);
  1182. end;
  1183. function TDealPayControl.AddPlusPayNode(const AName: string): TPayNode;
  1184. begin
  1185. Result := FindPlusPayNode(AName);
  1186. if not Assigned(Result) then
  1187. Result := NewPlusPayNode(AName);
  1188. end;
  1189. procedure TDealPayControl.CalculateAll;
  1190. begin
  1191. CalculateGather(FPlusGather, FPlusPayNodes);
  1192. CalculateGather(FMinusGather, FMinusPayNodes);
  1193. end;
  1194. procedure TDealPayControl.CalculateGather(AGather: TPayNode; ANodes: TList);
  1195. var
  1196. i: Integer;
  1197. vPayNode: TPayNode;
  1198. begin
  1199. AGather.CurTotalPrice := 0;
  1200. AGather.EndTotalPrice := 0;
  1201. AGather.PreTotalPrice := 0;
  1202. for i := 0 to ANodes.Count - 1 do
  1203. begin
  1204. vPayNode := TPayNode(ANodes.Items[i]);
  1205. AGather.CurTotalPrice := AGather.CurTotalPrice + vPayNode.CurTotalPrice;
  1206. AGather.EndTotalPrice := AGather.EndTotalPrice + vPayNode.EndTotalPrice;
  1207. AGather.PreTotalPrice := AGather.PreTotalPrice + vPayNode.PreTotalPrice;
  1208. end;
  1209. end;
  1210. constructor TDealPayControl.Create;
  1211. begin
  1212. FPlusPayNodes := TList.Create;
  1213. FMinusPayNodes := TList.Create;
  1214. FPlusGather := TPayNode.Create;
  1215. FMinusGather := TPayNode.Create;
  1216. FGatherPayNode := TPayNode.Create;
  1217. FGatherPayNode.Name := '本期应付';
  1218. FCompletePayNode :=TPayNode.Create;
  1219. FCompletePayNode.Name := '本期完成计量';
  1220. end;
  1221. destructor TDealPayControl.Destroy;
  1222. begin
  1223. FCompletePayNode.Free;
  1224. FGatherPayNode.Free;
  1225. FMinusGather.Free;
  1226. FPlusGather.Free;
  1227. ClearObjects(FMinusPayNodes);
  1228. FMinusPayNodes.Free;
  1229. ClearObjects(FPlusPayNodes);
  1230. FPlusPayNodes.Free;
  1231. inherited;
  1232. end;
  1233. function TDealPayControl.FindMinusPayNode(const AName: string): TPayNode;
  1234. var
  1235. iIndex: Integer;
  1236. vPayNode: TPayNode;
  1237. begin
  1238. Result := nil;
  1239. for iIndex := 0 to FMinusPayNodes.Count -1 do
  1240. begin
  1241. vPayNode := TPayNode(FMinusPayNodes.Items[iIndex]);
  1242. if (vPayNode.Name = AName) then
  1243. begin
  1244. Result := vPayNode;
  1245. Break;
  1246. end;
  1247. end;
  1248. end;
  1249. function TDealPayControl.FindPlusPayNode(const AName: string): TPayNode;
  1250. var
  1251. iIndex: Integer;
  1252. vPayNode: TPayNode;
  1253. begin
  1254. Result := nil;
  1255. for iIndex := 0 to FPlusPayNodes.Count -1 do
  1256. begin
  1257. vPayNode := TPayNode(FPlusPayNodes.Items[iIndex]);
  1258. if (vPayNode.Name = AName) then
  1259. begin
  1260. Result := vPayNode;
  1261. Break;
  1262. end;
  1263. end;
  1264. end;
  1265. function TDealPayControl.GetMinusPayCount: Integer;
  1266. begin
  1267. Result := FMinusPayNodes.Count;
  1268. end;
  1269. function TDealPayControl.GetMinusPayNode(AIndex: Integer): TPayNode;
  1270. begin
  1271. Result := TPayNode(FMinusPayNodes.Items[AIndex]);
  1272. end;
  1273. function TDealPayControl.GetPlusPayCount: Integer;
  1274. begin
  1275. Result := FPlusPayNodes.Count;
  1276. end;
  1277. function TDealPayControl.GetPlusPayNode(AIndex: Integer): TPayNode;
  1278. begin
  1279. Result := TPayNode(FPlusPayNodes.Items[AIndex]);
  1280. end;
  1281. function TDealPayControl.NewMinusPayNode(const AName: string): TPayNode;
  1282. begin
  1283. Result := TPayNode.Create;
  1284. FMinusPayNodes.Add(Result);
  1285. Result.Name := AName;
  1286. Result.IsMinus := True;
  1287. end;
  1288. function TDealPayControl.NewPlusPayNode(const AName: string): TPayNode;
  1289. begin
  1290. Result := TPayNode.Create;
  1291. FPlusPayNodes.Add(Result);
  1292. Result.Name := AName;
  1293. Result.IsMinus := False;
  1294. end;
  1295. end.