StageDm.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. unit StageDm;
  2. // 原报、审核数据通用
  3. // 原报 - Refer
  4. // 审核 - Audit1, Audit2 ...
  5. interface
  6. uses
  7. mDataRecord, BillsTree,
  8. SysUtils, Classes, sdDB, sdProvider, ADODB, ZhAPI, sdIDTree;
  9. type
  10. TStageData = class(TDataModule)
  11. sdpStage: TsdADOProvider;
  12. sddStage: TsdDataSet;
  13. procedure sddStageAfterValueChanged(AValue: TsdValue);
  14. procedure sddStageBeforeValueChange(AValue: TsdValue;
  15. const NewValue: Variant; var Allow: Boolean);
  16. procedure sddStageGetRecordClass(var ARecordClass: TsdRecordClass);
  17. private
  18. FPhaseData: TObject;
  19. FIndex: Integer;
  20. FBeforeChangeQuantity: Double;
  21. FBeforeChangeTotalPrice: Double;
  22. procedure BeforeBatchOperation;
  23. procedure AfterBatchOperation;
  24. procedure UpdateParentRecord(ABillsID: Integer; ATotalPrice: Double; const AFieldName: string);
  25. procedure UpdateComplete(ABillsID: Integer; AQuantity, ATotalPrice: Double);
  26. function HasPriceMarginBills: Boolean;
  27. // 向父项增量--PM_TotalPrice
  28. procedure UpdateParentPriceMargin(ABillsID: Integer; ADiffer: Double);
  29. // 向价差调整节点增量--GatherTotalPrice
  30. procedure UpdatePriceMarginNode(ADiffer: Double);
  31. // 重新计算相关的项目工料的价差数据
  32. procedure UpdateProjectGL(ABillsID: Integer);
  33. procedure CalculateDeal(ABillsID: Integer);
  34. procedure CalculateQuantityChange(ABillsID: Integer);
  35. procedure CalculatePriceChange(ABillsID: Integer);
  36. procedure CalculateParent(ANode: TBillsIDTreeNode);
  37. procedure CalculateLeaf(ANode: TBillsIDTreeNode);
  38. procedure CalculateSpecialLeaf(ANode: TBillsIDTreeNode);
  39. function GetTotalPrice(ABillsID, AType, AStageIndex: Integer): Double;
  40. function GetBillsUnitPriceMargin(ABillsID: Integer): Double;
  41. function GetBillsPrice(ABillsID: Integer): Double;
  42. function GetBillsNewPrice(ABillsID: Integer): Double;
  43. function GetBillsPriceDiffer(ABillsID: Integer): Double;
  44. function GetMainBillsTree: TBillsIDTree;
  45. function GetBuildLoadInterest(AType, AIndex: Integer): Double;
  46. function GetFirstPart(AType, AIndex: Integer): Double;
  47. function GetOtherFee(AType, AIndex: Integer): Double;
  48. function GetOtherProjectFee(AType, AIndex: Integer): Double;
  49. function GetRecyclingFee(AType, AIndex: Integer): Double;
  50. function GetReservedFee(AType, AIndex: Integer): Double;
  51. function GetSecondPart(AType, AIndex: Integer): Double;
  52. function GetStageSettlement(AType, AIndex: Integer): Double;
  53. function GetThirdPart(AType, AIndex: Integer): Double;
  54. function GetActive: Boolean;
  55. procedure SetTableName(const Value: string);
  56. function GetChapterStageGather(AChapter: Integer): Double;
  57. public
  58. constructor Create(APhaseData: TObject);
  59. destructor Destroy; override;
  60. procedure Open(AConnection: TADOConnection);
  61. procedure Save;
  62. // 计算任一清单节点的价差金额,并增量汇总至父项
  63. procedure CalculatePriceMargin(ABillsID: Integer);
  64. // 计算材料调差节点
  65. procedure CalculatePriceMarginNode;
  66. procedure CalculateNode(ANode: TsdIDTreeNode);
  67. procedure CalculateAll;
  68. function AddPhaseData(ABillsID: Integer;
  69. const AField, ANewValue: string): Boolean;
  70. function AddStageRecord(ABillsID: Integer): TStageRecord;
  71. procedure DeletePhaseRecord(ABillsID: Integer);
  72. procedure ReCalculate(ABillsID: Integer);
  73. procedure UpdateBGLInfo(ARec: TsdDataRecord; const AType: string);
  74. // 查找
  75. function StageRecord(ABillsID: Integer): TStageRecord;
  76. // 查找,如未找到则新增
  77. function StageRecordWithAdd(ABillsID: Integer): TStageRecord;
  78. // 将Bills表中存的累计计量数据拷贝至截止本期计量、截止上期计量,除新增一期计量外不可调用
  79. procedure CopyPrePhaseData;
  80. property Active: Boolean read GetActive;
  81. property TableName: string Write SetTableName;
  82. property MainBillsTree: TBillsIDTree read GetMainBillsTree;
  83. {可选计算数}
  84. // AType表示不同类型,取值如下:
  85. // 1: 本期数据 2: 截止本期数据 3: 截止上期数据
  86. // AIndex表示AType下不同数据类型,取值如下:
  87. // 1: 合同计量 2: 数量变更计量 3: 单价变更计量 4: 完成计量
  88. // 第一部分
  89. property FirstPart[AType, AIndex: Integer]: Double read GetFirstPart;
  90. // 第二部分
  91. property SecondPart[AType, AIndex: Integer]: Double read GetSecondPart;
  92. // 第三部分
  93. property ThirdPart[AType, AIndex: Integer]: Double read GetThirdPart;
  94. // 预留费用
  95. property ReservedFee[AType, AIndex: Integer]: Double read GetReservedFee;
  96. // 其他费用项目
  97. property OtherFee[AType, AIndex: Integer]: Double read GetOtherFee;
  98. // 建设期贷款利息
  99. property BuildLoadInterest[AType, AIndex: Integer]: Double read GetBuildLoadInterest;
  100. // 回收金额
  101. property RecyclingFee[AType, AIndex: Integer]: Double read GetRecyclingFee;
  102. // 公路工程以外的工程费用
  103. property OtherProjectFee[AType, AIndex: Integer]: Double read GetOtherProjectFee;
  104. // 本期结算价
  105. property StageSettlement[AType, AIndex: Integer]: Double read GetStageSettlement;
  106. // 100/200/.../900章本期完成计量
  107. property ChapterStageGather[AChapter: Integer]: Double read GetChapterStageGather;
  108. end;
  109. implementation
  110. uses
  111. ProjectData, BillsDm, PhaseData, Math, BGLDm, BillsMeasureDm,
  112. UtilMethods, ConditionalDefines, FormulaCalc, DetailGLDm, ConstUnit,
  113. ProjectGLDm;
  114. {$R *.dfm}
  115. { TPhaseData }
  116. function TStageData.AddPhaseData(ABillsID: Integer;
  117. const AField, ANewValue: string): Boolean;
  118. procedure SetPhaseRecord(ARec: TsdDataRecord; const AField, AValue: string);
  119. begin
  120. if CheckNumeric(ANewValue) then
  121. ARec.ValueByName(AField).AsString := AValue
  122. else
  123. begin
  124. ARec.ValueByName(AField).AsFloat := EvaluateExprs(AValue);
  125. ARec.ValueByName(StringReplace(AField, 'Quantity', 'Flag', [])).AsInteger := 1;
  126. ARec.ValueByName(StringReplace(AField, 'Quantity', 'Formula', [])).AsString := AValue;
  127. end;
  128. end;
  129. var
  130. Rec: TsdDataRecord;
  131. begin
  132. if Assigned(sddStage.FindKey('idxBID', ABillsID)) then Exit;
  133. Rec := sddStage.Add;
  134. Rec.ValueByName('BillsID').AsInteger := ABillsID;
  135. SetPhaseRecord(Rec, AField, ANewValue);
  136. end;
  137. function TStageData.AddStageRecord(ABillsID: Integer): TStageRecord;
  138. begin
  139. Result := TStageRecord(sddStage.FindKey('idxBID', ABillsID));
  140. if Assigned(Result) then Exit;
  141. Result := TStageRecord(sddStage.Add(True));
  142. try
  143. Result.ValueByName('BillsID').AsInteger := ABillsID;
  144. finally
  145. Result.EndUpdate;
  146. end;
  147. end;
  148. procedure TStageData.CalculateDeal(ABillsID: Integer);
  149. var
  150. Rec: TsdDataRecord;
  151. fQtyDiffer, fTPDiffer: Double;
  152. begin
  153. Rec := sddStage.FindKey('idxBID', ABillsID);
  154. if Rec.ValueByName('DealFlag').AsInteger < 2 then
  155. Rec.ValueByName('DealTotalPrice').AsFloat :=
  156. TotalPriceRoundTo(Rec.ValueByName('DealQuantity').AsFloat * GetBillsPrice(ABillsID));
  157. fQtyDiffer := Rec.ValueByName('DealQuantity').AsFloat - FBeforeChangeQuantity;
  158. fTPDiffer := Rec.ValueByName('DealTotalPrice').AsFloat - FBeforeChangeTotalPrice;
  159. Rec.ValueByName('EndDealQuantity').AsFloat := QuantityRoundTo(
  160. Rec.ValueByName('EndDealQuantity').AsFloat + fQtyDiffer);
  161. Rec.ValueByName('EndDealTotalPrice').AsFloat := TotalPriceRoundTo(
  162. Rec.ValueByName('EndDealTotalPrice').AsFloat + fTPDiffer);
  163. UpdateParentRecord(ABillsID, fTPDiffer, 'DealTotalPrice');
  164. UpdateComplete(ABillsID, fQtyDiffer, fTPDiffer);
  165. if TPhaseData(FPhaseData).IsLastStage then
  166. with TProjectData(TPhaseData(FPhaseData).ProjectData).BillsMeasureData do
  167. UpdateRecordDeal(ABillsID, fQtyDiffer, fTPDiffer);
  168. CalculatePriceMargin(ABillsID);
  169. TPhaseData(FPhaseData).PhasePayData.CalculateAll;
  170. end;
  171. procedure TStageData.CalculatePriceChange(ABillsID: Integer);
  172. var
  173. Rec: TsdDataRecord;
  174. fQtyDiffer, fTPDiffer: Double;
  175. begin
  176. Rec := sddStage.FindKey('idxBID', ABillsID);
  177. if Rec.ValueByName('PcFlag').AsInteger < 2 then
  178. Rec.ValueByName('PcTotalPrice').AsFloat :=
  179. TotalPriceRoundTo(Rec.ValueByName('PcQuantity').AsFloat * GetBillsPriceDiffer(ABillsID));
  180. fQtyDiffer := Rec.ValueByName('PcQuantity').AsFloat - FBeforeChangeQuantity;
  181. fTPDiffer := Rec.ValueByName('PcTotalPrice').AsFloat - FBeforeChangeTotalPrice;
  182. Rec.ValueByName('EndPcQuantity').AsFloat := QuantityRoundTo(
  183. Rec.ValueByName('EndPcQuantity').AsFloat + fQtyDiffer);
  184. Rec.ValueByName('EndPcTotalPrice').AsFloat := TotalPriceRoundTo(
  185. Rec.ValueByName('EndPcTotalPrice').AsFloat + fTPDiffer);
  186. UpdateParentRecord(ABillsID, fTPDiffer, 'PcTotalPrice');
  187. UpdateComplete(ABillsID, 0, fTPDiffer);
  188. if TPhaseData(FPhaseData).IsLastStage then
  189. with TProjectData(TPhaseData(FPhaseData).ProjectData).BillsMeasureData do
  190. UpdateRecordPc(ABillsID, fQtyDiffer, fTPDiffer);
  191. TPhaseData(FPhaseData).PhasePayData.CalculateAll;
  192. end;
  193. procedure TStageData.CalculateQuantityChange(ABillsID: Integer);
  194. var
  195. Rec: TsdDataRecord;
  196. fQtyDiffer, fTPDiffer: Double;
  197. begin
  198. Rec := sddStage.FindKey('idxBID', ABillsID);
  199. if Rec.ValueByName('QcFlag').AsInteger < 2 then
  200. Rec.ValueByName('QcTotalPrice').AsFloat :=
  201. TotalPriceRoundTo(Rec.ValueByName('QcQuantity').AsFloat * GetBillsPrice(ABillsID));
  202. fQtyDiffer := Rec.ValueByName('QcQuantity').AsFloat - FBeforeChangeQuantity;
  203. fTPDiffer := Rec.ValueByName('QcTotalPrice').AsFloat - FBeforeChangeTotalPrice;
  204. Rec.ValueByName('EndQcQuantity').AsFloat := QuantityRoundTo(
  205. Rec.ValueByName('EndQcQuantity').AsFloat + fQtyDiffer);
  206. Rec.ValueByName('EndQcTotalPrice').AsFloat := TotalPriceRoundTo(
  207. Rec.ValueByName('EndQcTotalPrice').AsFloat + fTPDiffer);
  208. UpdateParentRecord(ABillsID, fTPDiffer, 'QcTotalPrice');
  209. UpdateComplete(ABillsID, fQtyDiffer, fTPDiffer);
  210. if TPhaseData(FPhaseData).IsLastStage then
  211. with TProjectData(TPhaseData(FPhaseData).ProjectData).BillsMeasureData do
  212. UpdateRecordQc(ABillsID, fQtyDiffer, fTPDiffer);
  213. CalculatePriceMargin(ABillsID);
  214. TPhaseData(FPhaseData).PhasePayData.CalculateAll;
  215. end;
  216. constructor TStageData.Create(APhaseData: TObject);
  217. begin
  218. inherited Create(nil);
  219. FPhaseData := APhaseData;
  220. end;
  221. procedure TStageData.DeletePhaseRecord(ABillsID: Integer);
  222. var
  223. Rec: TsdDataRecord;
  224. begin
  225. Rec := sddStage.FindKey('idxBID', ABillsID);
  226. if Assigned(Rec) then
  227. sddStage.Remove(Rec);
  228. end;
  229. destructor TStageData.Destroy;
  230. begin
  231. inherited;
  232. end;
  233. function TStageData.GetBillsNewPrice(ABillsID: Integer): Double;
  234. begin
  235. Result := MainBillsTree.FindNode(ABillsID).Rec.ValueByName('NewPrice').AsFloat;
  236. end;
  237. function TStageData.GetBillsPrice(ABillsID: Integer): Double;
  238. begin
  239. Result := MainBillsTree.FindNode(ABillsID).Rec.ValueByName('Price').AsFloat;
  240. end;
  241. procedure TStageData.Open(AConnection: TADOConnection);
  242. begin
  243. sdpStage.Connection := AConnection;
  244. sddStage.Open;
  245. if not Assigned(sddStage.IndexList.FindByName('idxBID')) then
  246. sddStage.AddIndex('idxBID', 'BillsID');
  247. sddStage.FieldByName('DealQuantity').ValidChars := sddStage.FieldByName('DealQuantity').ValidChars + ArithmeticCharSet;
  248. end;
  249. function TStageData.StageRecord(ABillsID: Integer): TStageRecord;
  250. begin
  251. Result := nil;
  252. if Assigned(sddStage.IndexList.FindByName('idxBID')) then
  253. Result := TStageRecord(sddStage.FindKey('idxBID', ABillsID));
  254. end;
  255. procedure TStageData.ReCalculate(ABillsID: Integer);
  256. var
  257. Rec: TsdDataRecord;
  258. fDiffer: Double;
  259. begin
  260. Rec := sddStage.FindKey('idxBID', ABillsID);
  261. if not Assigned(Rec) then Exit;
  262. if Rec.ValueByName('DealFlag').AsInteger = 1 then
  263. Rec.ValueByName('DealQuantity').AsFloat := QuantityRoundTo(
  264. EvaluateExprs(Rec.ValueByName('DealFormula').AsString));
  265. if Rec.ValueByName('DealFlag').AsInteger < 2 then
  266. begin
  267. fDiffer := Rec.ValueByName('DealQuantity').AsFloat * GetBillsPrice(ABillsID)
  268. - Rec.ValueByName('DealTotalPrice').AsFloat;
  269. Rec.ValueByName('DealTotalPrice').AsFloat := TotalPriceRoundTo(
  270. Rec.ValueByName('DealQuantity').AsFloat * GetBillsPrice(ABillsID));
  271. end;
  272. Rec.ValueByName('EndDealQuantity').AsFloat := QuantityRoundTo(
  273. Rec.ValueByName('PreDealQuantity').AsFloat + Rec.ValueByName('DealQuantity').AsFloat);
  274. Rec.ValueByName('EndDealTotalPrice').AsFloat := TotalPriceRoundTo(
  275. Rec.ValueByName('PreDealTotalPrice').AsFloat + Rec.ValueByName('DealTotalPrice').AsFloat);
  276. if Rec.ValueByName('QcFlag').AsInteger = 1 then
  277. Rec.ValueByName('QcQuantity').AsFloat := QuantityRoundTo(
  278. EvaluateExprs(Rec.ValueByName('QcFormula').AsString));
  279. if Rec.ValueByName('QcFlag').AsInteger < 2 then
  280. begin
  281. fDiffer := Rec.ValueByName('QcQuantity').AsFloat * GetBillsPrice(ABillsID)
  282. - Rec.ValueByName('QcTotalPrice').AsFloat;
  283. Rec.ValueByName('QcTotalPrice').AsFloat := TotalPriceRoundTo(
  284. Rec.ValueByName('QcQuantity').AsFloat * GetBillsPrice(ABillsID));
  285. end;
  286. Rec.ValueByName('EndQcQuantity').AsFloat := QuantityRoundTo(
  287. Rec.ValueByName('PreQcQuantity').AsFloat + Rec.ValueByName('QcQuantity').AsFloat);
  288. Rec.ValueByName('EndQcTotalPrice').AsFloat := TotalPriceRoundTo(
  289. Rec.ValueByName('PreQcTotalPrice').AsFloat + Rec.ValueByName('QcTotalPrice').AsFloat);
  290. if Rec.ValueByName('PcFlag').AsInteger = 1 then
  291. Rec.ValueByName('PcQuantity').AsFloat := QuantityRoundTo(
  292. EvaluateExprs(Rec.ValueByName('PcFormula').AsString));
  293. if Rec.ValueByName('DealFlag').AsInteger < 2 then
  294. begin
  295. fDiffer := Rec.ValueByName('PcQuantity').AsFloat * GetBillsNewPrice(ABillsID)
  296. - Rec.ValueByName('PcTotalPrice').AsFloat;
  297. Rec.ValueByName('PcTotalPrice').AsFloat := TotalPriceRoundTo(
  298. Rec.ValueByName('PcQuantity').AsFloat * GetBillsNewPrice(ABillsID));
  299. end;
  300. Rec.ValueByName('EndPcQuantity').AsFloat := QuantityRoundTo(
  301. Rec.ValueByName('PrePcQuantity').AsFloat + Rec.ValueByName('PcQuantity').AsFloat);
  302. Rec.ValueByName('EndPcTotalPrice').AsFloat := TotalPriceRoundTo(
  303. Rec.ValueByName('PrePcTotalPrice').AsFloat + Rec.ValueByName('PcTotalPrice').AsFloat);
  304. end;
  305. procedure TStageData.Save;
  306. begin
  307. sddStage.Save;
  308. end;
  309. procedure TStageData.sddStageAfterValueChanged(AValue: TsdValue);
  310. var
  311. iBillsID: Integer;
  312. stnNode: TsdIDTreeNode;
  313. begin
  314. iBillsID := AValue.Owner.ValueByName('BillsID').AsInteger;
  315. stnNode := MainBillsTree.FindNode(iBillsID);
  316. if not Assigned(stnNode) or stnNode.HasChildren then Exit;
  317. if (AValue.FieldName = 'DealQuantity') or
  318. (AValue.FieldName = 'DealFormula') or
  319. (AValue.FieldName = 'DealTotalPrice') then
  320. CalculateDeal(iBillsID);
  321. if (AValue.FieldName = 'QcQuantity') or
  322. (AValue.FieldName = 'QcFormula') or
  323. (AValue.FieldName = 'QcTotalPrice') then
  324. CalculateQuantityChange(iBillsID);
  325. if (AValue.FieldName = 'PcQuantity') or
  326. (AValue.FieldName = 'PcFormula') or
  327. (AValue.FieldName = 'PcTotalPrice') then
  328. CalculatePriceChange(iBillsID);
  329. if (AValue.FieldName = 'DealQuantity') or
  330. (AValue.FieldName = 'QcQuantity') then
  331. UpdateProjectGL(iBillsID);
  332. end;
  333. function TStageData.GetMainBillsTree: TBillsIDTree;
  334. begin
  335. with TProjectData(TPhaseData(FPhaseData).ProjectData) do
  336. Result := BillsMeasureData.BillsMeasureTree;
  337. end;
  338. procedure TStageData.sddStageBeforeValueChange(AValue: TsdValue;
  339. const NewValue: Variant; var Allow: Boolean);
  340. procedure SetBeforeChangeValue(const AType: string);
  341. begin
  342. if SameText(AValue.FieldName, AType + 'Quantity') or
  343. SameText(AValue.FieldName, AType + 'Formula') or
  344. SameText(AValue.FieldName, AType + 'TotalPrice') then
  345. begin
  346. FBeforeChangeQuantity := AValue.Owner.ValueByName(AType + 'Quantity').AsFloat;
  347. FBeforeChangeTotalPrice := AValue.Owner.ValueByName(AType + 'TotalPrice').AsFloat;
  348. end;
  349. end;
  350. procedure CheckOverRange;
  351. var
  352. vNode: TsdIDTreeNode;
  353. fAvailableQty: Double;
  354. begin
  355. if SameText(AValue.FieldName, 'DealQuantity') then
  356. begin
  357. vNode := MainBillsTree.FindNode(AValue.Owner.ValueByName('BillsID').AsInteger);
  358. fAvailableQty := vNode.Rec.ValueByName('Quantity').AsFloat
  359. - vNode.Rec.ValueByName('AddDealQuantity').AsFloat + AValue.AsFloat;
  360. if VarToFloatDef(NewValue, 0) > fAvailableQty then
  361. DataSetErrorMessage(Allow, '不可超过0号台账合同数量!');
  362. end;
  363. end;
  364. begin
  365. // 不检查超计
  366. //CheckOverRange;
  367. SetBeforeChangeValue('Deal');
  368. SetBeforeChangeValue('Qc');
  369. SetBeforeChangeValue('Pc');
  370. end;
  371. procedure TStageData.AfterBatchOperation;
  372. begin
  373. sddStage.BeforeValueChange := sddStageBeforeValueChange;
  374. sddStage.AfterValueChanged := sddStageAfterValueChanged;
  375. end;
  376. procedure TStageData.BeforeBatchOperation;
  377. begin
  378. sddStage.BeforeValueChange := nil;
  379. sddStage.AfterValueChanged := nil;
  380. end;
  381. function TStageData.GetBillsPriceDiffer(ABillsID: Integer): Double;
  382. begin
  383. with MainBillsTree.FindNode(ABillsID).Rec do
  384. Result := ValueByName('NewPrice').AsFloat - ValueByName('Price').AsFloat;
  385. end;
  386. procedure TStageData.UpdateComplete(ABillsID: Integer; AQuantity,
  387. ATotalPrice: Double);
  388. var
  389. Rec: TsdDataRecord;
  390. begin
  391. if ABillsID = -1 then Exit;
  392. Rec := StageRecord(ABillsID);
  393. Rec.ValueByName('GatherQuantity').AsFloat := QuantityRoundTo(
  394. Rec.ValueByName('GatherQuantity').AsFloat + AQuantity);
  395. Rec.ValueByName('GatherTotalPrice').AsFloat := TotalPriceRoundTo(
  396. Rec.ValueByName('GatherTotalPrice').AsFloat + ATotalPrice);
  397. Rec.ValueByName('EndGatherQuantity').AsFloat := QuantityRoundTo(
  398. Rec.ValueByName('EndGatherQuantity').AsFloat + AQuantity);
  399. Rec.ValueByName('EndGatherTotalPrice').AsFloat := TotalPriceRoundTo(
  400. Rec.ValueByName('EndGatherTotalPrice').AsFloat + ATotalPrice);
  401. // 数量不向上汇总
  402. UpdateParentRecord(ABillsID, ATotalPrice, 'GatherTotalPrice');
  403. end;
  404. procedure TStageData.UpdateParentRecord(ABillsID: Integer;
  405. ATotalPrice: Double; const AFieldName: string);
  406. var
  407. iParentID: Integer;
  408. Rec: TsdDataRecord;
  409. begin
  410. iParentID := MainBillsTree.FindNode(ABillsID).ParentID;
  411. if iParentID = -1 then Exit;
  412. Rec := StageRecordWithAdd(iParentID);
  413. Rec.ValueByName(AFieldName).AsFloat := TotalPriceRoundTo(
  414. Rec.ValueByName(AFieldName).AsFloat + ATotalPrice);
  415. Rec.ValueByName('End' + AFieldName).AsFloat := TotalPriceRoundTo(
  416. Rec.ValueByName('End' + AFieldName).AsFloat + ATotalPrice);
  417. UpdateParentRecord(iParentID, ATotalPrice, AFieldName);
  418. end;
  419. function TStageData.GetBuildLoadInterest(AType, AIndex: Integer): Double;
  420. begin
  421. Result := GetTotalPrice(34, AType, AIndex);
  422. end;
  423. function TStageData.GetFirstPart(AType, AIndex: Integer): Double;
  424. begin
  425. Result := GetTotalPrice(1, AType, AIndex);
  426. end;
  427. function TStageData.GetOtherFee(AType, AIndex: Integer): Double;
  428. begin
  429. Result := GetTotalPrice(15, AType, AIndex);
  430. end;
  431. function TStageData.GetOtherProjectFee(AType, AIndex: Integer): Double;
  432. begin
  433. Result := GetTotalPrice(9, AType, AIndex);
  434. end;
  435. function TStageData.GetRecyclingFee(AType, AIndex: Integer): Double;
  436. begin
  437. Result := GetTotalPrice(16, AType, AIndex);
  438. end;
  439. function TStageData.GetReservedFee(AType, AIndex: Integer): Double;
  440. begin
  441. Result := GetTotalPrice(7, AType, AIndex);
  442. end;
  443. function TStageData.GetSecondPart(AType, AIndex: Integer): Double;
  444. begin
  445. Result := GetTotalPrice(2, AType, AIndex);
  446. end;
  447. function TStageData.GetStageSettlement(AType, AIndex: Integer): Double;
  448. begin
  449. // 全国
  450. // 第一部分+第二部分+第三部分+预备费+新增加费用项目(其他费用_广东)-回收金额
  451. Result := FirstPart[AType, AIndex] + SecondPart[AType, AIndex] + ThirdPart[AType, AIndex]
  452. + ReservedFee[AType, AIndex] + OtherFee[AType, AIndex] - RecyclingFee[AType, AIndex];
  453. // 广东
  454. // 全国的基础上+建设期贷款利息+公路功能以外的项目
  455. if _IsGuangDong then
  456. Result := Result + BuildLoadInterest[AType, AIndex] + OtherProjectFee[AType, AIndex]
  457. end;
  458. function TStageData.GetThirdPart(AType, AIndex: Integer): Double;
  459. begin
  460. Result := GetTotalPrice(3, AType, AIndex);
  461. end;
  462. function TStageData.GetTotalPrice(ABillsID, AType, AStageIndex: Integer): Double;
  463. var
  464. Rec: TsdDataRecord;
  465. sFieldName: string;
  466. begin
  467. Result := 0;
  468. Rec := StageRecord(ABillsID);
  469. if not Assigned(Rec) then Exit;
  470. case AType of
  471. 1: sFieldName := '';
  472. 2: sFieldName := 'End';
  473. 3: sFieldName := 'Pre';
  474. end;
  475. case AStageIndex of
  476. 1: sFieldName := sFieldName + 'DealTotalPrice';
  477. 2: sFieldName := sFieldName + 'QcTotalPrice';
  478. 3: sFieldName := sFieldName + 'PcTotalPrice';
  479. 4: sFieldName := sFieldName + 'GatherTotalPrice';
  480. end;
  481. Result := Rec.ValueByName(sFieldName).AsFloat;
  482. end;
  483. procedure TStageData.CopyPrePhaseData;
  484. var
  485. iRecord: Integer;
  486. Rec, NewRec: TsdDataRecord;
  487. begin
  488. BeforeBatchOperation;
  489. try
  490. with TProjectData(TPhaseData(FPhaseData).ProjectData).BillsData do
  491. for iRecord := 0 to sddBills.RecordCount - 1 do
  492. begin
  493. Rec := sddBills.Records[iRecord];
  494. if (Rec.ValueByName('AddGatherTotalPrice').AsFloat = 0) and
  495. (Rec.ValueByName('AddDealTotalPrice').AsFloat = 0) and
  496. (Rec.ValueByName('AddQcTotalPrice').AsFloat = 0) and
  497. (Rec.ValueByName('AddPcTotalPrice').AsFloat = 0) and
  498. (Rec.ValueByName('PM_AddTotalPrice').AsFloat = 0) then Continue;
  499. NewRec := sddStage.Add;
  500. NewRec.ValueByName('BillsID').AsInteger := Rec.ValueByName('ID').AsInteger;
  501. NewRec.ValueByName('EndDealQuantity').AsFloat := Rec.ValueByName('AddDealQuantity').AsFloat;
  502. NewRec.ValueByName('EndDealTotalPrice').AsFloat := Rec.ValueByName('AddDealTotalPrice').AsFloat;
  503. NewRec.ValueByName('EndQcQuantity').AsFloat := Rec.ValueByName('AddQcQuantity').AsFloat;
  504. NewRec.ValueByName('EndQcTotalPrice').AsFloat := Rec.ValueByName('AddQcTotalPrice').AsFloat;
  505. NewRec.ValueByName('EndQcBGLCode').AsString := Rec.ValueByName('AddQcBGLCode').AsString;
  506. NewRec.ValueByName('EndQcBGLNum').AsString := Rec.ValueByName('AddQcBGLNum').AsString;
  507. NewRec.ValueByName('EndPcQuantity').AsFloat := Rec.ValueByName('AddPcQuantity').AsFloat;
  508. NewRec.ValueByName('EndPcTotalPrice').AsFloat := Rec.ValueByName('AddPcTotalPrice').AsFloat;
  509. NewRec.ValueByName('EndPcBGLCode').AsString := Rec.ValueByName('AddPcBGLCode').AsString;
  510. NewRec.ValueByName('EndPcBGLNum').AsString := Rec.ValueByName('AddPcBGLNum').AsString;
  511. NewRec.ValueByName('EndGatherQuantity').AsFloat := Rec.ValueByName('AddGatherQuantity').AsFloat;
  512. NewRec.ValueByName('EndGatherTotalPrice').AsFloat := Rec.ValueByName('AddGatherTotalPrice').AsFloat;
  513. NewRec.ValueByName('PreDealQuantity').AsFloat := Rec.ValueByName('AddDealQuantity').AsFloat;
  514. NewRec.ValueByName('PreDealTotalPrice').AsFloat := Rec.ValueByName('AddDealTotalPrice').AsFloat;
  515. NewRec.ValueByName('PreQcQuantity').AsFloat := Rec.ValueByName('AddQcQuantity').AsFloat;
  516. NewRec.ValueByName('PreQcTotalPrice').AsFloat := Rec.ValueByName('AddQcTotalPrice').AsFloat;
  517. NewRec.ValueByName('PreQcBGLCode').AsString := Rec.ValueByName('AddQcBGLCode').AsString;
  518. NewRec.ValueByName('PreQcBGLNum').AsString := Rec.ValueByName('AddQcBGLNum').AsString;
  519. NewRec.ValueByName('PrePcQuantity').AsFloat := Rec.ValueByName('AddPcQuantity').AsFloat;
  520. NewRec.ValueByName('PrePcTotalPrice').AsFloat := Rec.ValueByName('AddPcTotalPrice').AsFloat;
  521. NewRec.ValueByName('PrePcBGLCode').AsString := Rec.ValueByName('AddPcBGLCode').AsString;
  522. NewRec.ValueByName('PrePcBGLNum').AsString := Rec.ValueByName('AddPcBGLNum').AsString;
  523. NewRec.ValueByName('PreGatherQuantity').AsFloat := Rec.ValueByName('AddGatherQuantity').AsFloat;
  524. NewRec.ValueByName('PreGatherTotalPrice').AsFloat := Rec.ValueByName('AddGatherTotalPrice').AsFloat;
  525. NewRec.ValueByName('PM_PreTotalPrice').AsFloat := Rec.ValueByName('PM_AddTotalPrice').AsFloat;
  526. end;
  527. finally
  528. AfterBatchOperation;
  529. end;
  530. end;
  531. procedure TStageData.UpdateBGLInfo(ARec: TsdDataRecord; const AType: string);
  532. var
  533. sPreBGLCode, sPreBGLNum, sCurBGLCode, sCurBGLNum: string;
  534. begin
  535. sPreBGLCode := ARec.ValueByName('Pre' + AType + 'BGLCode').AsString;
  536. sPreBGLNum := ARec.ValueByName('Pre' + AType + 'BGLNum').AsString;
  537. sCurBGLCode := ARec.ValueByName(AType + 'BGLCode').AsString;
  538. sCurBGLNum := ARec.ValueByName(AType + 'BGLNum').AsString;
  539. MergeRelaBGLAndNum(sPreBGLCode, sPreBGLNum, sCurBGLCode, sCurBGLNum);
  540. ARec.ValueByName('End' + AType + 'BGLCode').AsString := sPreBGLCode;
  541. ARec.ValueByName('End' + AType + 'BGLNum').AsString := sPreBGLNum;
  542. end;
  543. procedure TStageData.CalculateAll;
  544. begin
  545. BeforeBatchOperation;
  546. CalculateNode(MainBillsTree.FirstNode);
  547. AfterBatchOperation;
  548. end;
  549. procedure TStageData.CalculateNode(ANode: TsdIDTreeNode);
  550. function IsSpecialNode: Boolean;
  551. begin
  552. Result := ANode.ID = iPriceMarginID;
  553. end;
  554. begin
  555. if not Assigned(ANode) then Exit;
  556. if ANode.HasChildren then
  557. begin
  558. CalculateNode(ANode.FirstChild);
  559. CalculateParent(TBillsIDTreeNode(ANode));
  560. end
  561. else
  562. begin
  563. if IsSpecialNode then
  564. CalculateSpecialLeaf(TBillsIDTreeNode(ANode))
  565. else
  566. CalculateLeaf(TBillsIDTreeNode(ANode));
  567. end;
  568. CalculateNode(ANode.NextSibling);
  569. end;
  570. procedure TStageData.CalculateParent(ANode: TBillsIDTreeNode);
  571. var
  572. iChild: Integer;
  573. ChildNode: TBillsIDTreeNode;
  574. fDeal, fQc, fPc, fPM: Double;
  575. begin
  576. if not Assigned(ANode.StageRec) then Exit;
  577. fDeal := 0;
  578. fQc := 0;
  579. fPc := 0;
  580. fPM := 0;
  581. for iChild := 0 to ANode.ChildCount - 1 do
  582. begin
  583. ChildNode := TBillsIDTreeNode(ANode.ChildNodes[iChild]);
  584. if not Assigned(ChildNode.StageRec) then Continue;
  585. fDeal := TotalPriceRoundTo(fDeal + ChildNode.StageRec.DealTotalPrice.AsFloat);
  586. fQc := TotalPriceRoundTo(fQc + ChildNode.StageRec.QcTotalPrice.AsFloat);
  587. fPc := TotalPriceRoundTo(fPc + ChildNode.StageRec.PcTotalPrice.AsFloat);
  588. fPM := TotalPriceRoundTo(fPM + ChildNode.StageRec.PM_TotalPrice.AsFloat);
  589. end;
  590. with ANode.StageRec do
  591. begin
  592. if (DealTotalPrice.AsFloat <> fDeal) or
  593. (QcTotalPrice.AsFloat <> fQc) or
  594. (PcTotalPrice.AsFloat <> fPc) then
  595. begin
  596. DealTotalPrice.AsFloat := fDeal;
  597. QcTotalPrice.AsFloat := fQc;
  598. PcTotalPrice.AsFloat := fPc;
  599. GatherTotalPrice.AsFloat := TotalPriceRoundTo(fDeal + fQc + fPc);
  600. EndDealTotalPrice.AsFloat := TotalPriceRoundTo(PreDealTotalPrice.AsFloat + fDeal);
  601. EndQcTotalPrice.AsFloat := TotalPriceRoundTo(PreQcTotalPrice.AsFloat + fQc);
  602. EndPcTotalPrice.AsFloat := TotalPriceRoundTo(PrePcTotalPrice.AsFloat + fPc);
  603. EndGatherTotalPrice.AsFloat := TotalPriceRoundTo(
  604. PreGatherTotalPrice.AsFloat + GatherTotalPrice.AsFloat);
  605. end;
  606. if PM_TotalPrice.AsFloat <> fPM then
  607. PM_TotalPrice.AsFloat := fPM;
  608. end;
  609. end;
  610. procedure TStageData.CalculateLeaf(ANode: TBillsIDTreeNode);
  611. procedure CalculateMeasure(ARec: TsdDataRecord; const AType: string);
  612. var
  613. fPrice: Double;
  614. begin
  615. if ARec.ValueByName(AType + 'Flag').AsInteger = 1 then
  616. ARec.ValueByName(AType + 'Quantity').AsFloat := QuantityRoundTo(
  617. EvaluateExprs(ARec.ValueByName(AType + 'Formula').AsString));
  618. if ARec.ValueByName(AType + 'Flag').AsInteger < 2 then
  619. begin
  620. fPrice := GetBillsPrice(ARec.ValueByName('BillsID').AsInteger);
  621. ARec.ValueByName(AType + 'TotalPrice').AsFloat := TotalPriceRoundTo(
  622. ARec.ValueByName(AType + 'Quantity').AsFloat * fPrice);
  623. end;
  624. ARec.ValueByName('End' + AType + 'Quantity').AsFloat := QuantityRoundTo(
  625. ARec.ValueByName('Pre' + AType + 'Quantity').AsFloat + ARec.ValueByName(AType + 'Quantity').AsFloat);
  626. ARec.ValueByName('End' + AType + 'TotalPrice').AsFloat := TotalPriceRoundTo(
  627. ARec.ValueByName('Pre' + AType + 'TotalPrice').AsFloat + ARec.ValueByName(AType + 'TotalPrice').AsFloat);
  628. end;
  629. procedure CalculatePriceMargin(ARec: TStageRecord);
  630. var
  631. fPrice: Double;
  632. begin
  633. fPrice := GetBillsUnitPriceMargin(ARec.BillsID.AsInteger);
  634. ARec.SetFloatValue(ARec.PM_TotalPrice, TotalPriceRoundTo(ARec.GatherQuantity.AsFloat * fPrice));
  635. end;
  636. var
  637. Rec: TStageRecord;
  638. begin
  639. Rec := ANode.StageRec;
  640. if not Assigned(Rec) then Exit;
  641. CalculateMeasure(Rec, 'Deal');
  642. CalculateMeasure(Rec, 'Pc');
  643. CalculateMeasure(Rec, 'Qc');
  644. Rec.GatherQuantity.AsFloat := QuantityRoundTo(
  645. Rec.DealQuantity.AsFloat + Rec.QcQuantity.AsFloat);
  646. Rec.GatherTotalPrice.AsFloat := TotalPriceRoundTo(
  647. Rec.DealTotalPrice.AsFloat + Rec.QcTotalPrice.AsFloat + Rec.PcTotalPrice.AsFloat);
  648. Rec.EndGatherQuantity.AsFloat := QuantityRoundTo(
  649. Rec.PreGatherQuantity.AsFloat + Rec.GatherQuantity.AsFloat);
  650. Rec.EndGatherTotalPrice.AsFloat := TotalPriceRoundTo(
  651. Rec.PreGatherTotalPrice.AsFloat + Rec.GatherTotalPrice.AsFloat);
  652. CalculatePriceMargin(Rec);
  653. end;
  654. function TStageData.GetActive: Boolean;
  655. begin
  656. Result := sddStage.Active;
  657. end;
  658. procedure TStageData.SetTableName(const Value: string);
  659. begin
  660. sdpStage.TableName := Value;
  661. end;
  662. procedure TStageData.sddStageGetRecordClass(
  663. var ARecordClass: TsdRecordClass);
  664. begin
  665. ARecordClass := TStageRecord;
  666. end;
  667. function TStageData.GetChapterStageGather(AChapter: Integer): Double;
  668. function CheckCodeChapter(const ACode: string): Boolean;
  669. var
  670. iFirst: Integer;
  671. sgs: TStrings;
  672. begin
  673. sgs := TStringList.Create;
  674. try
  675. sgs.Delimiter := '-';
  676. sgs.DelimitedText := ACode;
  677. if sgs.Count > 1 then
  678. begin
  679. iFirst := StrToIntDef(sgs[0], 0) div 100;
  680. Result := iFirst = AChapter;
  681. end
  682. else
  683. Result := False;
  684. finally
  685. sgs.Free;
  686. end;
  687. end;
  688. var
  689. iIndex: Integer;
  690. Rec: TsdDataRecord;
  691. stnNode: TsdIDTreeNode;
  692. begin
  693. Result := 0;
  694. for iIndex := 0 to sddStage.RecordCount - 1 do
  695. begin
  696. Rec := sddStage.Records[iIndex];
  697. stnNode := MainBillsTree.FindNode(Rec.ValueByName('BillsID').AsInteger);
  698. if not stnNode.HasChildren and CheckCodeChapter(stnNode.Rec.ValueByName('B_Code').AsString) then
  699. Result := Result + Rec.ValueByName('GatherTotalPrice').AsFloat;
  700. end;
  701. end;
  702. procedure TStageData.CalculatePriceMarginNode;
  703. var
  704. Rec: TStageRecord;
  705. fDiffer: Double;
  706. begin
  707. if not HasPriceMarginBills then Exit;
  708. with TProjectData(TPhaseData(FPhaseData).ProjectData) do
  709. begin
  710. Rec := StageRecord(iPriceMarginID);
  711. if not Assigned(Rec) then
  712. Rec := AddStageRecord(iPriceMarginID);
  713. fDiffer := TotalPriceRoundTo(ProjectGLData.PM_TotalPrice - Rec.GatherTotalPrice.AsFloat);
  714. if fDiffer <> 0 then
  715. begin
  716. Rec.AddDifferValue(Rec.GatherTotalPrice, fDiffer);
  717. Rec.AddDifferValue(Rec.EndGatherTotalPrice, fDiffer);
  718. UpdateParentRecord(Rec.BillsID.AsInteger, fDiffer, 'GatherTotalPrice');
  719. end;
  720. end;
  721. end;
  722. function TStageData.GetBillsUnitPriceMargin(ABillsID: Integer): Double;
  723. var
  724. vGLs: TList;
  725. iGL: Integer;
  726. GLRec: TDetailGLRecord;
  727. begin
  728. Result := 0;
  729. vGLs := TList.Create;
  730. try
  731. with TProjectData(TPhaseData(FPhaseData).ProjectData).DetailGLData do
  732. LoadDetailGLs(ABillsID, vGLs);
  733. for iGL := 0 to vGLs.Count - 1 do
  734. begin
  735. GLRec := TDetailGLRecord(vGLs.Items[iGL]);
  736. Result := Result + GLRec.Quantity.AsFloat * GLRec.RelaProjectGL.ValidDeltaPrice.AsFloat;
  737. end;
  738. finally
  739. vGLs.Free;
  740. end;
  741. end;
  742. procedure TStageData.CalculatePriceMargin(ABillsID: Integer);
  743. var
  744. Rec: TStageRecord;
  745. fPM, fPMDiffer: Double;
  746. begin
  747. if not HasPriceMarginBills then Exit;
  748. Rec := StageRecord(ABillsID);
  749. if not Assigned(Rec) then Exit;
  750. fPM := TotalPriceRoundTo(Rec.GatherQuantity.AsFloat * GetBillsUnitPriceMargin(ABillsID));
  751. if fPM <> Rec.PM_TotalPrice.AsFloat then
  752. begin
  753. fPMDiffer := fPM - Rec.PM_TotalPrice.AsFloat;
  754. Rec.PM_TotalPrice.AsFloat := fPM;
  755. UpdateParentPriceMargin(ABillsID, fPMDiffer);
  756. UpdatePriceMarginNode(fPMDiffer);
  757. with TProjectData(TPhaseData(FPhaseData).ProjectData).BillsMeasureData do
  758. UpdateRecordPM(ABillsID, fPMDiffer);
  759. end;
  760. end;
  761. procedure TStageData.UpdatePriceMarginNode(ADiffer: Double);
  762. var
  763. Rec: TStageRecord;
  764. begin
  765. Rec := StageRecordWithAdd(iPriceMarginID);
  766. Rec.AddDifferValue(Rec.GatherTotalPrice, ADiffer);
  767. Rec.AddDifferValue(Rec.EndGatherTotalPrice, ADiffer);
  768. UpdateParentRecord(iPriceMarginID, ADiffer, 'GatherTotalPrice');
  769. with TProjectData(TPhaseData(FPhaseData).ProjectData).BillsMeasureData do
  770. UpdateGather(Rec.BillsID.AsInteger, ADiffer);
  771. end;
  772. procedure TStageData.UpdateParentPriceMargin(ABillsID: Integer; ADiffer: Double);
  773. var
  774. iParentID: Integer;
  775. Rec: TStageRecord;
  776. begin
  777. iParentID := MainBillsTree.FindNode(ABillsID).ParentID;
  778. if iParentID = -1 then Exit;
  779. Rec := StageRecordWithAdd(iParentID);
  780. Rec.PM_TotalPrice.AsFloat := TotalPriceRoundTo(Rec.PM_TotalPrice.AsFloat + ADiffer);
  781. UpdateParentPriceMargin(iParentID, ADiffer);
  782. end;
  783. function TStageData.StageRecordWithAdd(ABillsID: Integer): TStageRecord;
  784. begin
  785. Result := StageRecord(ABillsID);
  786. if not Assigned(Result) then
  787. Result := AddStageRecord(ABillsID);
  788. end;
  789. procedure TStageData.UpdateProjectGL(ABillsID: Integer);
  790. var
  791. vGLs: TList;
  792. iGL: Integer;
  793. GLRec: TDetailGLRecord;
  794. begin
  795. vGLs := TList.Create;
  796. try
  797. with TProjectData(TPhaseData(FPhaseData).ProjectData) do
  798. begin
  799. DetailGLData.LoadDetailGLs(ABillsID, vGLs);
  800. ProjectGLData.CalculateGLs_PM(vGLs);
  801. end;
  802. finally
  803. vGLs.Free;
  804. end;
  805. end;
  806. procedure TStageData.CalculateSpecialLeaf(ANode: TBillsIDTreeNode);
  807. procedure GatherPriceMargin(ARec: TStageRecord);
  808. begin
  809. with TProjectData(TPhaseData(FPhaseData).ProjectData).ProjectGLData do
  810. ARec.SetFloatValue(ARec.GatherTotalPrice, PM_TotalPrice);
  811. ARec.SetFloatValue(ARec.EndGatherTotalPrice,
  812. ARec.PreGatherTotalPrice.AsFloat + ARec.GatherTotalPrice.AsFloat);
  813. end;
  814. var
  815. StageRec: TStageRecord;
  816. begin
  817. StageRec := ANode.StageRec;
  818. if not Assigned(StageRec) then Exit;
  819. case ANode.ID of
  820. iPriceMarginID: GatherPriceMargin(StageRec);
  821. end;
  822. end;
  823. function TStageData.HasPriceMarginBills: Boolean;
  824. var
  825. vPM_Node: TsdIDTreeNode;
  826. begin
  827. vPM_Node := MainBillsTree.FindNode(iPriceMarginID);
  828. Result := Assigned(vPM_Node);
  829. end;
  830. end.