rmHaBaiCustomizedDm.pas 54 KB

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