stgGatherGclCacheData.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. unit stgGatherGclCacheData;
  2. interface
  3. uses
  4. CacheTree, SysUtils, BillsTree, Classes, sdDB, mDataRecord;
  5. type
  6. TstgGclStageData = class
  7. private
  8. FDealQuantity: Double;
  9. FDealTotalPrice: Double;
  10. FQcQuantity: Double;
  11. FQcTotalPrice: Double;
  12. FQcBGLCode: string;
  13. FQcBGLNum: string;
  14. procedure AddBGLCodeAndNum(ACode, ANum: string);
  15. public
  16. procedure ClearData;
  17. procedure AddStageData(AStageData: TstgGclStageData);
  18. procedure AssignedData(AStageRecord: TStageRecord);
  19. property DealQuantity: Double read FDealQuantity;
  20. property DealTotalPrice: Double read FDealTotalPrice;
  21. property QcQuantity: Double read FQcQuantity;
  22. property QcTotalPrice: Double read FQcTotalPrice;
  23. property QcBGLCode: string read FQcBGLCode;
  24. property QcBGLNum: string read FQcBGLNum;
  25. end;
  26. TstgGclSubTenderDetailData = class
  27. private
  28. FSerialNo: Integer;
  29. FLeafXmjCode: string;
  30. FDetailStage: TstgGclStageData;
  31. public
  32. constructor Create(ANode: TMeasureBillsIDTreeNode);
  33. destructor Destroy; override;
  34. property SerialNo: Integer read FSerialNo;
  35. property LeafXmjCode: string read FLeafXmjCode;
  36. property DetailStage: TstgGclStageData read FDetailStage;
  37. end;
  38. TstgGclSubTenderStageData = class
  39. private
  40. FSubTenderID: Integer;
  41. FGather: TstgGclStageData;
  42. FDetails: TList;
  43. function GetDetail(AIndex: Integer): TstgGclSubTenderDetailData;
  44. function GetDetailCount: Integer;
  45. public
  46. constructor Create(ASubTenderID: Integer);
  47. destructor Destroy; override;
  48. function AddDetail(ANode: TMeasureBillsIDTreeNode): TstgGclSubTenderDetailData;
  49. procedure CalculateGather;
  50. property SubTenderID: Integer read FSubTenderID;
  51. property Gather: TstgGclStageData read FGather;
  52. property DetailCount: Integer read GetDetailCount;
  53. property Detail[AIndex: Integer]: TstgGclSubTenderDetailData read GetDetail;
  54. end;
  55. TstgGatherGcl = class
  56. private
  57. FID: Integer;
  58. FIndexCode: string;
  59. FB_Code: string;
  60. FName: string;
  61. FUnits: string;
  62. FPrice: Double;
  63. FGather: TstgGclStageData;
  64. FSubTenders: TList;
  65. function GetIsGclBills: Boolean;
  66. function GetSubTender(AIndex: Integer): TstgGclSubTenderStageData;
  67. function GetSubTenderCount: Integer;
  68. public
  69. constructor Create(AID: Integer; ARec: TBillsRecord);
  70. destructor Destroy; override;
  71. function FindSubTender(ASubTenderID: Integer): TstgGclSubTenderStageData;
  72. function SafeSubTender(ASubTenderID: Integer): TstgGclSubTenderStageData;
  73. procedure CalculateGather;
  74. property ID: Integer read FID;
  75. property B_Code: string read FB_Code;
  76. property IndexCode: string read FIndexCode;
  77. property Name: string read FName;
  78. property Units: string read FUnits;
  79. property Price: Double read FPrice;
  80. property SubTenderCount: Integer read GetSubTenderCount;
  81. property SubTender[AIndex: Integer]: TstgGclSubTenderStageData read GetSubTender;
  82. property Gather: TstgGclStageData read FGather;
  83. end;
  84. TstgGatherGclSubTender = class
  85. private
  86. FID: Integer;
  87. FRec: TsdDataRecord;
  88. public
  89. constructor Create(ARec: TsdDataRecord);
  90. property ID: Integer read FID;
  91. property Rec: TsdDataRecord read FRec;
  92. end;
  93. TstgGatherGclCacheData = class
  94. private
  95. FGatherGcls: TList;
  96. FSubTenders: TList;
  97. function GetSubTenderCount: Integer;
  98. function GetSubTender(AIndex: Integer): TstgGatherGclSubTender;
  99. function GetGatherGcl(AIndex: Integer): TstgGatherGcl;
  100. function GetGatherGclCount: Integer;
  101. public
  102. constructor Create;
  103. destructor Destroy; override;
  104. function FindSubTender(AID: Integer): TstgGatherGclSubTender;
  105. function AddSubTender(ARec: TsdDataRecord): TstgGatherGclSubTender;
  106. function FindGatherGcl(ARec: TBillsRecord): TstgGatherGcl;
  107. function AddGatherGcl(ARec: TBillsRecord): TstgGatherGcl;
  108. procedure CalculateAll;
  109. property SubTenderCount: Integer read GetSubTenderCount;
  110. property SubTender[AIndex: Integer]: TstgGatherGclSubTender read GetSubTender;
  111. property GatherGclCount: Integer read GetGatherGclCount;
  112. property GatherGcl[AIndex: Integer]: TstgGatherGcl read GetGatherGcl;
  113. end;
  114. implementation
  115. uses
  116. ZhAPI, UtilMethods, Math;
  117. { TstgGatherGcl }
  118. procedure TstgGatherGcl.CalculateGather;
  119. var
  120. i: Integer;
  121. vSubTender: TstgGclSubTenderDetailData;
  122. begin
  123. FGather.ClearData;
  124. for i := 0 to FSubTenders.Count - 1 do
  125. begin
  126. SubTender[i].CalculateGather;
  127. FGather.AddStageData(SubTender[i].Gather);
  128. end;
  129. end;
  130. constructor TstgGatherGcl.Create(AID: Integer; ARec: TBillsRecord);
  131. begin
  132. FSubTenders := TList.Create;
  133. FGather := TstgGclStageData.Create;
  134. FID := AID;
  135. FB_Code := ARec.B_Code.AsString;
  136. FIndexCode := B_CodeToIndexCode(FB_Code);
  137. FName := ARec.Name.AsString;
  138. FUnits := ARec.Units.AsString;
  139. FPrice := ARec.Price.AsFloat;
  140. end;
  141. destructor TstgGatherGcl.Destroy;
  142. begin
  143. FGather.Free;
  144. ClearObjects(FSubTenders);
  145. FSubTenders.Free;
  146. inherited;
  147. end;
  148. function TstgGatherGcl.FindSubTender(
  149. ASubTenderID: Integer): TstgGclSubTenderStageData;
  150. var
  151. i: Integer;
  152. begin
  153. Result := nil;
  154. for i := 0 to FSubTenders.Count - 1 do
  155. begin
  156. if ASubTenderID = SubTender[i].SubTenderID then
  157. begin
  158. Result := SubTender[i];
  159. Break;
  160. end;
  161. end;
  162. end;
  163. function TstgGatherGcl.GetIsGclBills: Boolean;
  164. begin
  165. Result := FB_Code <> '';
  166. end;
  167. function TstgGatherGcl.GetSubTender(
  168. AIndex: Integer): TstgGclSubTenderStageData;
  169. begin
  170. Result := TstgGclSubTenderStageData(FSubTenders.Items[AIndex]);
  171. end;
  172. function TstgGatherGcl.GetSubTenderCount: Integer;
  173. begin
  174. Result := FSubTenders.Count;
  175. end;
  176. function TstgGatherGcl.SafeSubTender(
  177. ASubTenderID: Integer): TstgGclSubTenderStageData;
  178. begin
  179. Result := FindSubTender(ASubTenderID);
  180. if not Assigned(Result) then
  181. begin
  182. Result := TstgGclSubTenderStageData.Create(ASubTenderID);
  183. FSubTenders.Add(Result);
  184. end;
  185. end;
  186. { TstgGatherGclCacheData }
  187. function TstgGatherGclCacheData.AddGatherGcl(
  188. ARec: TBillsRecord): TstgGatherGcl;
  189. begin
  190. Result := FindGatherGcl(ARec);
  191. if not Assigned(Result) then
  192. begin
  193. Result := TstgGatherGcl.Create(GatherGclCount + 1, ARec);
  194. FGatherGcls.Add(Result);
  195. end;
  196. end;
  197. function TstgGatherGclCacheData.AddSubTender(
  198. ARec: TsdDataRecord): TstgGatherGclSubTender;
  199. begin
  200. Result := FindSubTender(ARec.ValueByName('ID').AsInteger);
  201. if not Assigned(Result) then
  202. begin
  203. Result := TstgGatherGclSubTender.Create(ARec);
  204. FSubTenders.Add(Result);
  205. end;
  206. end;
  207. procedure TstgGatherGclCacheData.CalculateAll;
  208. var
  209. i: Integer;
  210. vGcl: TstgGatherGcl;
  211. begin
  212. for i := 0 to GatherGclCount - 1 do
  213. begin
  214. vGcl := GatherGcl[i];
  215. vGcl.CalculateGather;
  216. end;
  217. end;
  218. constructor TstgGatherGclCacheData.Create;
  219. begin
  220. FGatherGcls := TList.Create;
  221. FSubTenders := TList.Create;
  222. end;
  223. destructor TstgGatherGclCacheData.Destroy;
  224. begin
  225. ClearObjects(FSubTenders);
  226. FSubTenders.Free;
  227. ClearObjects(FGatherGcls);
  228. FGatherGcls.Free;
  229. inherited;
  230. end;
  231. function TstgGatherGclCacheData.FindGatherGcl(ARec: TBillsRecord): TstgGatherGcl;
  232. var
  233. i: Integer;
  234. vGcl: TstgGatherGcl;
  235. bMatch: Boolean;
  236. begin
  237. Result := nil;
  238. for i := 0 to FGatherGcls.Count - 1 do
  239. begin
  240. vGcl := TstgGatherGcl(FGatherGcls.Items[i]);
  241. bMatch := (vGcl.B_Code = ARec.B_Code.AsString) and (vGcl.Name = ARec.Name.AsString)
  242. and (vGcl.Units = ARec.Units.AsString);
  243. //and (CommonRoundTo(vGcl.Price - ARec.Price.AsFloat, -6) = 0);
  244. if bMatch then
  245. begin
  246. Result := vGcl;
  247. Break;
  248. end;
  249. end;
  250. end;
  251. function TstgGatherGclCacheData.FindSubTender(
  252. AID: Integer): TstgGatherGclSubTender;
  253. var
  254. i: Integer;
  255. begin
  256. Result := nil;
  257. for i := 0 to SubTenderCount - 1 do
  258. begin
  259. if SubTender[i].ID = AID then
  260. begin
  261. Result := SubTender[i];
  262. Break;
  263. end;
  264. end;
  265. end;
  266. function TstgGatherGclCacheData.GetGatherGcl(
  267. AIndex: Integer): TstgGatherGcl;
  268. begin
  269. Result := TstgGatherGcl(FGatherGcls.Items[AIndex]);
  270. end;
  271. function TstgGatherGclCacheData.GetGatherGclCount: Integer;
  272. begin
  273. Result := FGatherGcls.Count;
  274. end;
  275. function TstgGatherGclCacheData.GetSubTender(AIndex: Integer): TstgGatherGclSubTender;
  276. begin
  277. Result := TstgGatherGclSubTender(FSubTenders.Items[AIndex]);
  278. end;
  279. function TstgGatherGclCacheData.GetSubTenderCount: Integer;
  280. begin
  281. Result := FSubTenders.Count;
  282. end;
  283. { TstgGatherGclSubTender }
  284. constructor TstgGatherGclSubTender.Create(ARec: TsdDataRecord);
  285. begin
  286. FID := ARec.ValueByName('ID').AsInteger;
  287. FRec := ARec;
  288. end;
  289. { TstgGclStageData }
  290. procedure TstgGclStageData.AddBGLCodeAndNum(ACode, ANum: string);
  291. var
  292. sCode, sNum: string;
  293. begin
  294. sCode := FQcBGLCode;
  295. sNum := FQcBGLNum;
  296. MergeRelaBGLAndNum(sCode, sNum, ACode, ANum);
  297. FQcBGLCode := sCode;
  298. FQcBGLNum := sNum;
  299. end;
  300. procedure TstgGclStageData.AddStageData(AStageData: TstgGclStageData);
  301. begin
  302. FDealQuantity := FDealQuantity + AStageData.DealQuantity;
  303. FDealTotalPrice := FDealTotalPrice + AStageData.DealTotalPrice;
  304. FQcQuantity := FQcQuantity + AStageData.QcQuantity;
  305. FQcTotalPrice := FQcTotalPrice + AStageData.QcTotalPrice;
  306. AddBGLCodeAndNum(AStageData.QcBGLCode, AStageData.QcBGLNum);
  307. end;
  308. procedure TstgGclStageData.AssignedData(AStageRecord: TStageRecord);
  309. begin
  310. FDealQuantity := AStageRecord.DealQuantity.AsFloat;
  311. FDealTotalPrice := AStageRecord.DealTotalPrice.AsFloat;
  312. FQcQuantity := AStageRecord.QcQuantity.AsFloat;
  313. FQcTotalPrice := AStageRecord.QcTotalPrice.AsFloat;
  314. FQcBGLCode := AStageRecord.QcBGLCode.AsString;
  315. FQcBGLNum := AStageRecord.QcBGLNum.AsString;
  316. end;
  317. procedure TstgGclStageData.ClearData;
  318. begin
  319. FDealQuantity := 0;
  320. FDealTotalPrice := 0;
  321. FQcQuantity := 0;
  322. FQcTotalPrice := 0;
  323. FQcBGLCode := '';
  324. FQcBGLNum := '';
  325. end;
  326. { TstgGclSubTenderStageData }
  327. function TstgGclSubTenderStageData.AddDetail(
  328. ANode: TMeasureBillsIDTreeNode): TstgGclSubTenderDetailData;
  329. begin
  330. Result := TstgGclSubTenderDetailData.Create(ANode);
  331. FDetails.Add(Result);
  332. end;
  333. procedure TstgGclSubTenderStageData.CalculateGather;
  334. var
  335. i: Integer;
  336. begin
  337. FGather.ClearData;
  338. for i := 0 to DetailCount - 1 do
  339. FGather.AddStageData(Detail[i].DetailStage);
  340. end;
  341. constructor TstgGclSubTenderStageData.Create(ASubTenderID: Integer);
  342. begin
  343. FSubTenderID := ASubTenderID;
  344. FGather := TstgGclStageData.Create;
  345. FDetails := TList.Create;
  346. end;
  347. destructor TstgGclSubTenderStageData.Destroy;
  348. begin
  349. ClearObjects(FDetails);
  350. FDetails.Free;
  351. FGather.Free;
  352. inherited;
  353. end;
  354. function TstgGclSubTenderStageData.GetDetail(
  355. AIndex: Integer): TstgGclSubTenderDetailData;
  356. begin
  357. Result := TstgGclSubTenderDetailData(FDetails.Items[AIndex]);
  358. end;
  359. function TstgGclSubTenderStageData.GetDetailCount: Integer;
  360. begin
  361. Result := FDetails.Count;
  362. end;
  363. { TstgGclSubTenderDetailData }
  364. constructor TstgGclSubTenderDetailData.Create(ANode: TMeasureBillsIDTreeNode);
  365. begin
  366. FSerialNo := ANode.MajorIndex + 1;
  367. FDetailStage := TstgGclStageData.Create;
  368. if Assigned(ANode.StageRec) then
  369. FDetailStage.AssignedData(ANode.StageRec);
  370. end;
  371. destructor TstgGclSubTenderDetailData.Destroy;
  372. begin
  373. FDetailStage.Free;
  374. inherited;
  375. end;
  376. end.