StageDm.pas 33 KB

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