stgGatherGclCacheData.pas 11 KB

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