BillsMeasureDm.pas 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  1. unit BillsMeasureDm;
  2. interface
  3. uses
  4. BillsDm, BillsTree, FormulaCalc, sdIDTree, StageDm,
  5. SysUtils, Classes, sdDB, DB;
  6. type
  7. TBillsMeasureData = class(TDataModule)
  8. sdvBillsMeasure: TsdDataView;
  9. procedure sdvBillsMeasureAfterOpen(Sender: TObject);
  10. procedure sdvBillsMeasureAfterAddRecord(ARecord: TsdDataRecord);
  11. procedure sdvBillsMeasureGetText(var Text: String;
  12. ARecord: TsdDataRecord; AValue: TsdValue; AColumn: TsdViewColumn;
  13. DisplayText: Boolean);
  14. procedure sdvBillsMeasureSetText(var Text: String;
  15. ARecord: TsdDataRecord; AValue: TsdValue; AColumn: TsdViewColumn;
  16. var Allow: Boolean);
  17. procedure sdvBillsMeasureNeedLookupRecord(ARecord: TsdDataRecord;
  18. AColumn: TsdViewColumn; ANewText: String);
  19. procedure sdvBillsMeasureAfterClose(Sender: TObject);
  20. procedure sdvBillsMeasureAfterValueChanged(AValue: TsdValue);
  21. procedure sdvBillsMeasureCurrentChanged(ARecord: TsdDataRecord);
  22. private
  23. FProjectData: TObject;
  24. FBillsData: TBillsData;
  25. FBillsMeasureTree: TMeasureBillsIDTree;
  26. FFormulaCalc: TFormulaCalc;
  27. FShowParentData: Boolean;
  28. FOnRecChange: TRecChangeEvent;
  29. function OnGetCardinalNum(const ACardinalNum: string): Double;
  30. procedure CalcAddCompleteRate(ANode: TsdIDTreeNode);
  31. procedure CalcAddDgnPrice(ANode: TsdIDTreeNode);
  32. function SelectAndUpdateBGL(ABillsID: Integer; ARec: TsdDataRecord;
  33. ANewValue: Double; const AType: string): Boolean;
  34. procedure CalculateNode(ANode: TMeasureBillsIDTreeNode);
  35. procedure UpdateRecordGather(ANode: TsdIDTreeNode; AQuantity, ATotalPrice: Double);
  36. function GetStageData: TStageData;
  37. procedure SetOnRecChange(const Value: TRecChangeEvent);
  38. public
  39. constructor Create(AProjectData: TObject);
  40. destructor Destroy; override;
  41. procedure Open;
  42. procedure Close;
  43. procedure ReConnectTree;
  44. procedure CalculateAll;
  45. procedure ResetPhaseStageLink;
  46. procedure ResetTreeNodeStageRec;
  47. procedure ExpandNodeTo(ALevel: Integer);
  48. procedure ExpandXmjNode;
  49. procedure ExpandCurPhase;
  50. function GatherRelaBGL(ANode: TsdIDTreeNode): string;
  51. // 计算 修改各期原报审核数据时,需对累计数据做增量
  52. procedure UpdateRecordDeal(ABillsID: Integer; AQuantity, ATotalPrice: Double);
  53. procedure UpdateRecordQc(ABillsID: Integer; AQuantity, ATotalPrice: Double);
  54. procedure UpdateRecordPc(ABillsID: Integer; AQuantity, ATotalPrice: Double);
  55. procedure UpdateRecordPM(ABillsID: Integer; ADiffer: Double);
  56. procedure UpdateGather(ABillsID: Integer; ADiffer: Double);
  57. procedure UpdateBGLInfo(ABillsID: Integer; ARec: TsdDataRecord; const AType: string);
  58. property ProjectData: TObject read FProjectData;
  59. property BillsData: TBillsData read FBillsData;
  60. property BillsMeasureTree: TMeasureBillsIDTree read FBillsMeasureTree;
  61. property StageData: TStageData read GetStageData;
  62. property ShowParentData: Boolean read FShowParentData write FShowParentData;
  63. property OnRecChange: TRecChangeEvent read FOnRecChange write SetOnRecChange;
  64. end;
  65. implementation
  66. uses
  67. ProjectData, PhaseData, Math, ZhAPI, BillsCommand, BGLSelectFrm,
  68. BGLDm, UtilMethods, mDataRecord, ConstUnit, Variants;
  69. {$R *.dfm}
  70. { TBillsMeasureData }
  71. constructor TBillsMeasureData.Create(AProjectData: TObject);
  72. begin
  73. inherited Create(nil);
  74. FProjectData := AProjectData;
  75. FBillsData := TProjectData(FProjectData).BillsData;
  76. FBillsMeasureTree := TMeasureBillsIDTree.Create;
  77. FBillsMeasureTree.KeyFieldName := 'ID';
  78. FBillsMeasureTree.ParentFieldName := 'ParentID';
  79. FBillsMeasureTree.NextSiblingFieldName := 'NextSiblingID';
  80. FBillsMeasureTree.AutoCreateKeyID := True;
  81. FBillsMeasureTree.AutoExpand := True;
  82. FBillsMeasureTree.DataView := sdvBillsMeasure;
  83. FBillsMeasureTree.SeedID := Max(FBillsMeasureTree.SeedID, 100);
  84. FBillsMeasureTree.Link(TProjectData(FProjectData).BillsCompileData.BillsCompileTree, True);
  85. FBillsMeasureTree.CompileTree := TProjectData(FProjectData).BillsCompileData.BillsCompileTree;
  86. FFormulaCalc := TFormulaCalc.Create(FBillsMeasureTree);
  87. FFormulaCalc.OnGetValue := OnGetCardinalNum;
  88. end;
  89. destructor TBillsMeasureData.Destroy;
  90. begin
  91. FFormulaCalc.Free;
  92. FBillsMeasureTree.Free;
  93. inherited;
  94. end;
  95. procedure TBillsMeasureData.Open;
  96. begin
  97. sdvBillsMeasure.DataSet := TProjectData(FProjectData).BillsData.sddBills;
  98. sdvBillsMeasure.Open;
  99. end;
  100. procedure TBillsMeasureData.ReConnectTree;
  101. begin
  102. FBillsMeasureTree.DataView := nil;
  103. FBillsMeasureTree.DataView := sdvBillsMeasure;
  104. FBillsMeasureTree.Link(TProjectData(FProjectData).BillsCompileData.BillsCompileTree, True);
  105. end;
  106. procedure TBillsMeasureData.ResetPhaseStageLink;
  107. begin
  108. with TProjectData(FProjectData).PhaseData do
  109. begin
  110. sdvBillsMeasure.Columns.FindColumn('CurDealQuantity').LookupDataSet := StageData.sddStage;
  111. sdvBillsMeasure.Columns.FindColumn('CurDealTotalPrice').LookupDataSet := StageData.sddStage;
  112. sdvBillsMeasure.Columns.FindColumn('CurQcQuantity').LookupDataSet := StageData.sddStage;
  113. sdvBillsMeasure.Columns.FindColumn('CurQcTotalPrice').LookupDataSet := StageData.sddStage;
  114. sdvBillsMeasure.Columns.FindColumn('CurQcBGLCode').LookupDataSet := StageData.sddStage;
  115. sdvBillsMeasure.Columns.FindColumn('CurPcQuantity').LookupDataSet := StageData.sddStage;
  116. sdvBillsMeasure.Columns.FindColumn('CurPcTotalPrice').LookupDataSet := StageData.sddStage;
  117. sdvBillsMeasure.Columns.FindColumn('CurPcBGLCode').LookupDataSet := StageData.sddStage;
  118. sdvBillsMeasure.Columns.FindColumn('CurGatherQuantity').LookupDataSet := StageData.sddStage;
  119. sdvBillsMeasure.Columns.FindColumn('CurGatherTotalPrice').LookupDataSet := StageData.sddStage;
  120. sdvBillsMeasure.Columns.FindColumn('EndDealQuantity').LookupDataSet := StageData.sddStage;
  121. sdvBillsMeasure.Columns.FindColumn('EndDealTotalPrice').LookupDataSet := StageData.sddStage;
  122. sdvBillsMeasure.Columns.FindColumn('EndQcQuantity').LookupDataSet := StageData.sddStage;
  123. sdvBillsMeasure.Columns.FindColumn('EndQcTotalPrice').LookupDataSet := StageData.sddStage;
  124. sdvBillsMeasure.Columns.FindColumn('EndPcQuantity').LookupDataSet := StageData.sddStage;
  125. sdvBillsMeasure.Columns.FindColumn('EndPcTotalPrice').LookupDataSet := StageData.sddStage;
  126. sdvBillsMeasure.Columns.FindColumn('EndGatherQuantity').LookupDataSet := StageData.sddStage;
  127. sdvBillsMeasure.Columns.FindColumn('EndGatherTotalPrice').LookupDataSet := StageData.sddStage;
  128. sdvBillsMeasure.Columns.FindColumn('PM_PreTotalPrice').LookupDataSet := StageData.sddStage;
  129. sdvBillsMeasure.Columns.FindColumn('PM_TotalPrice').LookupDataSet := StageData.sddStage;
  130. end;
  131. end;
  132. procedure TBillsMeasureData.sdvBillsMeasureAfterOpen(Sender: TObject);
  133. begin
  134. FBillsMeasureTree.Active := True;
  135. end;
  136. procedure TBillsMeasureData.sdvBillsMeasureAfterAddRecord(
  137. ARecord: TsdDataRecord);
  138. begin
  139. if TProjectData(FProjectData).PhaseData.Active then
  140. ARecord.ValueByName('IsMeasureAdd').AsBoolean := True;
  141. end;
  142. procedure TBillsMeasureData.sdvBillsMeasureGetText(var Text: String;
  143. ARecord: TsdDataRecord; AValue: TsdValue; AColumn: TsdViewColumn;
  144. DisplayText: Boolean);
  145. function GetQuantityValueOrFormula(const AQtyType: string): string;
  146. begin
  147. with AValue.Owner do
  148. begin
  149. if ValueByName(AQtyType + 'Flag').AsInteger = 1 then
  150. Result := ValueByName(AQtyType + 'Formula').AsString
  151. else
  152. Result := Text;
  153. end;
  154. end;
  155. function GetTotalPriceValueOrFormula(const AQtyType: string): string;
  156. begin
  157. with AValue.Owner do
  158. begin
  159. if ValueByName(AQtyType + 'Formula').AsString <> '' then
  160. Result := ValueByName(AQtyType + 'Formula').AsString
  161. else
  162. Result := Text;
  163. end;
  164. end;
  165. procedure GetDisplayText(var AText: string; AValue: TsdValue;
  166. AColumn: TsdViewColumn);
  167. var
  168. stnNode: TsdIDTreeNode;
  169. begin
  170. if Assigned(AValue) and (AValue.DataType = ftFloat) and (AValue.AsFloat = 0) then
  171. begin
  172. Text := '';
  173. Exit;
  174. end;
  175. // 所有本期数据,当节点为父节点时,不显示值(实际上需要计算其中的金额值,但又不能显示)
  176. // 有病。每天都在变。
  177. if not ShowParentData and (Pos('Cur', AColumn.FieldName) > 0) and (Pos('Gather', AColumn.FieldName) = 0) then
  178. begin
  179. stnNode := BillsMeasureTree.FindNode(AValue.Owner.ValueByName('BillsID').AsInteger);
  180. if stnNode.HasChildren then
  181. Text := '';
  182. end;
  183. end;
  184. procedure GetEditText(var AText: string; AValue: TsdValue;
  185. AColumn: TsdViewColumn);
  186. begin
  187. if SameText(AColumn.FieldName, 'Quantity') then
  188. Text := GetQuantityValueOrFormula('Qty')
  189. else if SameText(AColumn.FieldName, 'CurDealQuantity') then
  190. Text := GetQuantityValueOrFormula('Deal')
  191. else if SameText(AColumn.FieldName, 'CurQcQuantity') then
  192. Text := GetQuantityValueOrFormula('Qc')
  193. else if SameText(AColumn.FieldName, 'CurPcQuantity') then
  194. Text := GetQuantityValueOrFormula('Pc')
  195. else if SameText(AColumn.FieldName, 'CurDealTotalPrice') then
  196. Text := GetTotalPriceValueOrFormula('Deal')
  197. else if SameText(AColumn.FieldName, 'CurQcTotalPrice') then
  198. Text := GetTotalPriceValueOrFormula('Qc')
  199. else if SameText(AColumn.FieldName, 'CurPcTotalPrice') then
  200. Text := GetTotalPriceValueOrFormula('Pc');
  201. end;
  202. var
  203. fPercent: Double;
  204. begin
  205. if not Assigned(AValue) then Exit;
  206. if DisplayText then
  207. GetDisplayText(Text, AValue, AColumn)
  208. else
  209. GetEditText(Text, AValue, AColumn);
  210. end;
  211. procedure TBillsMeasureData.sdvBillsMeasureSetText(var Text: String;
  212. ARecord: TsdDataRecord; AValue: TsdValue; AColumn: TsdViewColumn;
  213. var Allow: Boolean);
  214. function GetBillsID: Integer;
  215. begin
  216. if Pos('Cur', AColumn.FieldName) = 1 then
  217. Result := AValue.Owner.ValueByName('BillsID').AsInteger
  218. else
  219. Result := ARecord.ValueByName('ID').AsInteger;
  220. end;
  221. procedure CheckLockedData;
  222. begin
  223. if SameText(AColumn.FieldName, 'Code') or
  224. SameText(AColumn.FieldName, 'B_Code') or
  225. SameText(AColumn.FieldName, 'Name') or
  226. SameText(AColumn.FieldName, 'Units') or
  227. SameText(AColumn.FieldName, 'Price') then
  228. if ARecord.ValueByName('LockedInfo').AsBoolean then
  229. DataSetErrorMessage(Allow, '清单信息已被锁定,不允许修改编号、名称、单位、清单单价!');
  230. if not Allow then Exit;
  231. if SameText(AColumn.FieldName, 'NewPrice') then
  232. if ARecord.ValueByName('LockedNewPrice').AsBoolean then
  233. DataSetErrorMessage(Allow, '变更单价已被锁定,不允许修改!');
  234. end;
  235. procedure CheckNodeWritable(ANode: TBillsIDTreeNode);
  236. var
  237. iCreatePhase: Integer;
  238. begin
  239. iCreatePhase := ANode.Rec.ValueByName('CreatePhaseID').AsInteger;
  240. if ANode.ID = iPriceMarginID then
  241. DataSetErrorMessage(Allow, sBills_PMHint);
  242. if SameText('B_Code', AColumn.FieldName) or
  243. SameText('Name', AColumn.FieldName) or
  244. SameText('Units', AColumn.FieldName) then
  245. if ANode.Rec.ValueByName('AddQcQuantity').AsFloat <> 0 then
  246. DataSetErrorMessage(Allow, '该清单已进行过变更,不可修改清单编号、名称、单位!');
  247. if not Allow then Exit;
  248. if SameText('Price', AColumn.FieldName) then
  249. if ANode.Rec.ValueByName('AddGatherTotalPrice').AsFloat <> 0 then
  250. DataSetErrorMessage(Allow, '该清单已经计量,不可修改清单单价!');
  251. if not Allow then Exit;
  252. if SameText('NewPrice', AColumn.FieldName) then
  253. if ANode.Rec.ValueByName('AddPcTotalPrice').AsFloat <> 0 then
  254. DataSetErrorMessage(Allow, '该清单已经计量,不可修改清单变更单价!');
  255. if not Allow then Exit;
  256. if ANode.HasChildren then
  257. begin
  258. if Text = '' then
  259. Exit
  260. else if ((Pos('Quantity', AColumn.FieldName) > 0) and (Pos('Dgn', AColumn.FieldName) <=0)) or
  261. (Pos('TotalPrice', AColumn.FieldName) > 0) then
  262. DataSetErrorMessage(Allow, '该清单有子计算项,不能直接修改!')
  263. else if (Pos('Price', AColumn.FieldName) > 0) then
  264. DataSetErrorMessage(Allow, '仅最底层清单可输入单价!');
  265. end
  266. else
  267. begin
  268. // 目前仅允许本期合同计量,可直接输入金额
  269. if SameText('CurDealTotalPrice', AColumn.FieldName) then
  270. begin
  271. if not ANode.TotalPriceEnable then
  272. DataSetErrorMessage(Allow, '该清单不可直接输入金额,如需直接输入金额,请先清空所有数量、单价!');
  273. end
  274. else if SameText('CurDealQuantity', AColumn.FieldName) or
  275. SameText('CurQcQuantity', AColumn.FieldName) or
  276. SameText('CurPcQuantity', AColumn.FieldName) or
  277. SameText('Price', AColumn.FieldName) then
  278. begin
  279. if not ANode.CountPriceEnable then
  280. DataSetErrorMessage(Allow, '该清单不可输入数量单价,如需使用数量×单价计算,请先清空所有直接输入的金额!');
  281. end;
  282. end;
  283. if not Allow then Exit;
  284. // 变更清单允许填写本期合同计量,按超计论
  285. {if vNode.Rec.ValueByName('IsMeasureAdd').AsBoolean and (iCreatePhase > 0) and
  286. (SameText('CurDealQuantity', AColumn.FieldName) or
  287. SameText('CurDealTotalPrice', AColumn.FieldName)) then
  288. DataSetErrorMessage(Allow, Format('该清单为第%d期新增清单,不可填写本期合同计量数据!', [iCreatePhase]));}
  289. end;
  290. procedure SetQuantity(ANode: TBillsIDTreeNode; const AField: string);
  291. var
  292. vNode: TBillsIDTreeNode;
  293. begin
  294. // 变更应选择变更令
  295. if SameText(AField , 'Qc') or SameText(AField , 'Pc') then
  296. Allow := SelectAndUpdateBGL(GetBillsID, AValue.Owner, StrToFloatDef(Text, 0), AField);
  297. if not Allow then Exit;
  298. if CheckStringNull(Text) or CheckNumeric(Text) then
  299. begin
  300. AValue.Owner.ValueByName(AField + 'Flag').AsInteger := 0;
  301. AValue.Owner.ValueByName(AField + 'Formula').AsString := '';
  302. Text := FloatToStr(QuantityRoundTo(StrToFloatDef(Text, 0)));
  303. end
  304. else
  305. begin
  306. AValue.Owner.ValueByName(AField + 'Flag').AsInteger := 1;
  307. AValue.Owner.ValueByName(AField + 'Formula').AsString := Text;
  308. Text := FloatToStr(QuantityRoundTo(EvaluateExprs(Text)));
  309. end;
  310. ANode.Rec.SetIntValue(ANode.Rec.CalcType, 0);
  311. end;
  312. procedure SetTotalPrice(ANode: TBillsIDTreeNode; const AField: string);
  313. begin
  314. // 变更应选择变更令
  315. if SameText(AField , 'Qc') or SameText(AField , 'Pc') then
  316. Allow := SelectAndUpdateBGL(GetBillsID, AValue.Owner, StrToFloatDef(Text, 0), AField);
  317. if not Allow then Exit;
  318. AValue.Owner.ValueByName(AField + 'Flag').AsInteger := 2;
  319. AValue.Owner.ValueByName(AField + 'Quantity').AsString := '';
  320. if CheckStringNull(Text) or CheckNumeric(Text) then
  321. begin
  322. AValue.Owner.ValueByName(AField + 'Formula').AsString := '';
  323. Text := FloatToStr(TotalPriceRoundTo(StrToFloatDef(Text, 0)));
  324. end
  325. else
  326. begin
  327. AValue.Owner.ValueByName(AField + 'Formula').AsString := Text;
  328. Text := FloatToStr(TotalPriceRoundTo(EvaluateExprs(Text)));
  329. end;
  330. ANode.Rec.SetIntValue(ANode.Rec.CalcType, 1);
  331. end;
  332. procedure DoCurChanged(ANode: TBillsIDTreeNode);
  333. begin
  334. if SameText(AColumn.FieldName, 'CurDealQuantity') then
  335. SetQuantity(ANode, 'Deal')
  336. else if SameText(AColumn.FieldName, 'CurQcQuantity') then
  337. SetQuantity(ANode, 'Qc')
  338. else if SameText(AColumn.FieldName, 'CurPcQuantity') then
  339. SetQuantity(ANode, 'Pc')
  340. else if SameText(AColumn.FieldName, 'CurDealTotalPrice') then
  341. SetTotalPrice(ANode, 'Deal')
  342. else if SameText(AColumn.FieldName, 'CurQcTotalPrice') then
  343. SetTotalPrice(ANode, 'Qc')
  344. else if SameText(AColumn.FieldName, 'CurPcTotalPrice') then
  345. SetTotalPrice(ANode, 'Pc')
  346. else if (Pos('DgnQuantity', AColumn.FieldName) > 0) or
  347. SameText(AColumn.FieldName, 'Quantity') then
  348. Text := FloatToStr(QuantityRoundTo(StrToFloatDef(Text, 0)))
  349. else if SameText(AColumn.FieldName, 'NewPrice') or
  350. SameText(AColumn.FieldName, 'Price') then
  351. Text := FloatToStr(PriceRoundTo(StrToFloatDef(Text, 0)))
  352. else if SameText(AColumn.FieldName, 'Code') then
  353. BillsMeasureTree.RecodeChildrenCode(ANode, AValue.AsString, Text)
  354. else if SameText(AColumn.FieldName, 'B_Code') then
  355. BillsMeasureTree.RecodeChildrenB_Code(ANode, AValue.AsString, Text);
  356. end;
  357. function CheckValidData: Boolean;
  358. begin
  359. Result := (AValue.AsString <> Text);
  360. if (Pos('Quantity', AColumn.FieldName) > 0) or
  361. (Pos('Price', AColumn.FieldName) > 0) then
  362. begin
  363. if (AValue.AsFloat = 0) and (Text = '') then
  364. Result := False;
  365. end;
  366. end;
  367. var
  368. vNode: TBillsIDTreeNode;
  369. begin
  370. if not Assigned(AValue) then Exit;
  371. // 修改后数据与原数据相同则不提交
  372. if not CheckValidData then
  373. Allow := False;
  374. if not Allow then Exit;
  375. vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(GetBillsID));
  376. CheckLockedData;
  377. if not Allow then Exit;
  378. CheckNodeWritable(vNode);
  379. if not Allow then Exit;
  380. Text := Trim(Text);
  381. if Pos('=', Text) = 1 then
  382. Text := Copy(Text, 2, Length(Text) - 1);
  383. DoCurChanged(vNode);
  384. end;
  385. procedure TBillsMeasureData.sdvBillsMeasureNeedLookupRecord(
  386. ARecord: TsdDataRecord; AColumn: TsdViewColumn; ANewText: String);
  387. function CheckNeedAddPhaseRecord(ANode: TMeasureBillsIDTreeNode): Boolean;
  388. begin
  389. Result := SameText(AColumn.FieldName, 'CurDealQuantity') or
  390. SameText(AColumn.FieldName, 'CurQcQuantity') or
  391. SameText(AColumn.FieldName, 'CurPcQuantity') or
  392. SameText(AColumn.FieldName, 'CurDealTotalPrice') or
  393. SameText(AColumn.FieldName, 'CurQcTotalPrice') or
  394. SameText(AColumn.FieldName, 'CurPcTotalPrice');
  395. Result := Result and not ANode.HasChildren;
  396. Result := Result and not Assigned(ANode.StageRec);
  397. end;
  398. function HasCardinalNum(AFormula: string): Boolean;
  399. var
  400. iCharIndex: Integer;
  401. begin
  402. Result := False;
  403. iCharIndex := 1;
  404. while ((iCharIndex <= Length(AFormula)) and not Result) do
  405. begin
  406. if AFormula[iCharIndex] in ['A'..'D', 'a'..'d'] then
  407. Result := True;
  408. Inc(iCharIndex);
  409. end;
  410. end;
  411. procedure SetQuantityRec(ANode: TBillsIDTreeNode; APhaseRec: TsdDataRecord; const AType: string);
  412. var
  413. bAllow: Boolean;
  414. begin
  415. bAllow := True;
  416. // 变更应选择变更令
  417. if SameText(AType , 'Qc') or SameText(AType , 'Pc') then
  418. bAllow := SelectAndUpdateBGL(ARecord.ValueByName('ID').AsInteger,
  419. APhaseRec, StrToFloatDef(ANewText, 0), AType);
  420. if bAllow then
  421. begin
  422. if ANode.Rec.CalcType.AsInteger <> 0 then
  423. ANode.Rec.CalcType.AsInteger := 0;
  424. <<<<<<< HEAD
  425. =======
  426. >>>>>>> 3.1.5
  427. if CheckNumeric(ANewText) then
  428. APhaseRec.ValueByName(AType + 'Quantity').AsFloat := QuantityRoundTo(StrToFloatDef(ANewText, 0))
  429. else
  430. begin
  431. APhaseRec.ValueByName(AType + 'Flag').AsInteger := 1;
  432. APhaseRec.ValueByName(AType + 'Quantity').AsFloat := QuantityRoundTo(EvaluateExprs(ANewText));
  433. APhaseRec.ValueByName(AType + 'Formula').AsString := ANewText;
  434. end;
  435. end;
  436. end;
  437. procedure SetTotalPriceRec(ANode: TBillsIDTreeNode; APhaseRec: TsdDataRecord; const AType: string);
  438. <<<<<<< HEAD
  439. begin
  440. =======
  441. begin
  442. >>>>>>> 3.1.5
  443. if ANode.Rec.CalcType.AsInteger <> 1 then
  444. ANode.Rec.CalcType.AsInteger := 1;
  445. APhaseRec.ValueByName(AType + 'Flag').AsInteger := 2;
  446. if CheckNumeric(ANewText) then
  447. APhaseRec.ValueByName(AType + 'TotalPrice').AsFloat := TotalPriceRoundTo(StrToFloatDef(ANewText, 0))
  448. else
  449. begin
  450. APhaseRec.ValueByName(AType + 'TotalPrice').AsFloat := TotalPriceRoundTo(EvaluateExprs(ANewText));
  451. APhaseRec.ValueByName(AType + 'Formula').AsString := ANewText;
  452. end;
  453. end;
  454. procedure SetNewRecValue(ANode: TBillsIDTreeNode; APhaseRec: TsdDataRecord);
  455. begin
  456. if SameText(AColumn.FieldName, 'CurDealQuantity') then
  457. SetQuantityRec(ANode, APhaseRec, 'Deal')
  458. else if SameText(AColumn.FieldName, 'CurQcQuantity') then
  459. SetQuantityRec(ANode, APhaseRec, 'Qc')
  460. else if SameText(AColumn.FieldName, 'CurPcQuantity') then
  461. SetQuantityRec(ANode, APhaseRec, 'Pc')
  462. else if SameText(AColumn.FieldName, 'CurDealTotalPrice') then
  463. SetTotalPriceRec(ANode, APhaseRec, 'Deal')
  464. else if SameText(AColumn.FieldName, 'CurQcTotalPrice') then
  465. SetTotalPriceRec(ANode, APhaseRec, 'Qc')
  466. else if SameText(AColumn.FieldName, 'CurPcTotalPrice') then
  467. SetTotalPriceRec(ANode, APhaseRec, 'Pc');
  468. end;
  469. function CheckNodeWritable(ANode: TBillsIDTreeNode): Boolean;
  470. var
  471. iCreatePhase: Integer;
  472. begin
  473. Result := True;
  474. if ANode.ID = iPriceMarginID then
  475. DataSetErrorMessage(Result, sBills_PMHint);
  476. if ANode.HasChildren then
  477. begin
  478. if ANewText = '' then
  479. Result := False
  480. else
  481. DataSetErrorMessage(Result, '该清单有子计算项,不能直接修改!');
  482. end
  483. else
  484. begin
  485. // 目前仅允许本期合同计量,可直接输入金额
  486. if SameText('CurDealTotalPrice', AColumn.FieldName) then
  487. begin
  488. if not ANode.TotalPriceEnable then
  489. DataSetErrorMessage(Result, '该清单不可直接输入金额,如需直接输入金额,请先清空所有数量、单价!');
  490. end
  491. else if SameText('CurDealQuantity', AColumn.FieldName) or
  492. SameText('CurQcQuantity', AColumn.FieldName) or
  493. SameText('CurPcQuantity', AColumn.FieldName) then
  494. begin
  495. if not ANode.CountPriceEnable then
  496. DataSetErrorMessage(Result, '该清单不可输入数量单价,如需使用数量×单价计算,请先清空所有直接输入的金额!');
  497. end;
  498. end;
  499. // 变更清单允许填写本期合同计量,按超计论
  500. {iCreatePhase := ANode.Rec.ValueByName('CreatePhaseID').AsInteger;
  501. if ANode.Rec.ValueByName('IsMeasureAdd').AsBoolean and (iCreatePhase > 0) and
  502. (SameText('CurDealQuantity', AColumn.FieldName) or
  503. SameText('CurDealTotalPrice', AColumn.FieldName)) then
  504. begin
  505. ErrorMessage(Format('该清单为第%d期新增清单,不可填写本期合同计量数据!', [iCreatePhase]));
  506. Exit;
  507. end; }
  508. end;
  509. var
  510. NewRec: TStageRecord;
  511. vNode: TMeasureBillsIDTreeNode;
  512. begin
  513. vNode := TMeasureBillsIDTreeNode(BillsMeasureTree.FindNode(ARecord.ValueByName('ID').AsInteger));
  514. if not CheckNodeWritable(vNode) then
  515. Exit;
  516. if CheckNeedAddPhaseRecord(vNode) then
  517. begin
  518. <<<<<<< HEAD
  519. if (Pos('Quantity', AColumn.FieldName) > 0) or (Pos('TotalPrice', AColumn.FieldName) > 0) then
  520. =======
  521. if(Pos('Quantity', AColumn.FieldName) > 0) or (Pos('TotalPrice', AColumn.FieldName) > 0) then
  522. >>>>>>> 3.1.5
  523. if HasCardinalNum(ANewText) then
  524. raise Exception.Create('公式不可输入参数');
  525. NewRec := StageData.AddStageRecord(ARecord.ValueByName('ID').AsInteger);
  526. vNode.StageRec := NewRec;
  527. SetNewRecValue(vNode, NewRec);
  528. end;
  529. end;
  530. procedure TBillsMeasureData.sdvBillsMeasureAfterClose(Sender: TObject);
  531. begin
  532. FBillsMeasureTree.Active := False;
  533. end;
  534. function TBillsMeasureData.OnGetCardinalNum(
  535. const ACardinalNum: string): Double;
  536. {
  537. function GetTotalPrice(ABillsID: Integer): Double;
  538. var
  539. stnNode: TsdIDTreeNode;
  540. begin
  541. stnNode := FBillsTree.FindNode(ABillsID);
  542. if Assigned(stnNode) then
  543. Result := stnNode.Rec.ValueByName('TotalPrice').AsFloat;
  544. end;
  545. function GetPhaseTotalPrice(ABillsID: Integer; const AType: string): Double;
  546. var
  547. Rec: TsdDataRecord;
  548. begin
  549. Rec := CurPhaseData.PhaseRecord(ABillsID);
  550. if Assigned(Rec) then
  551. Result := Rec.ValueByName(AType + 'TotalPrice').AsFloat;
  552. end;
  553. }
  554. function GetTotalPrice(ANode: TsdIDTreeNode): Double;
  555. var
  556. iChild: Integer;
  557. begin
  558. Result := 0;
  559. if not Assigned(ANode) then Exit;
  560. if ANode.HasChildren then
  561. for iChild := 0 to ANode.ChildCount - 1 do
  562. Result := Result + GetTotalPrice(ANode.ChildNodes[iChild])
  563. else
  564. Result := ANode.Rec.ValueByName('TotalPrice').AsFloat;
  565. end;
  566. function GetPhaseTotalPrice(ANode: TsdIDTreeNode; const AType: string): Double;
  567. var
  568. iChild: Integer;
  569. Rec: TsdDataRecord;
  570. begin
  571. Result := 0;
  572. if not Assigned(ANode) then Exit;
  573. if ANode.HasChildren then
  574. for iChild := 0 to ANode.ChildCount - 1 do
  575. Result := Result + GetPhaseTotalPrice(ANode.ChildNodes[iChild], AType)
  576. else
  577. begin
  578. Rec := StageData.StageRecord(ANode.ID);
  579. if Assigned(Rec) then
  580. Result := Rec.ValueByName(AType + 'TotalPrice').AsFloat;
  581. end;
  582. end;
  583. var
  584. iNodeID: Integer;
  585. begin
  586. Result := 0;
  587. iNodeID := StrToIntDef(Copy(ACardinalNum, 2, Length(ACardinalNum) - 1), -1);
  588. case ACardinalNum[1] of
  589. 'A','a': Result := GetTotalPrice(BillsMeasureTree.FindNode(iNodeID));
  590. 'B','b': Result := GetPhaseTotalPrice(BillsMeasureTree.FindNode(iNodeID), 'Deal');
  591. 'C','c': Result := GetPhaseTotalPrice(BillsMeasureTree.FindNode(iNodeID), 'Qc');
  592. 'D','d': Result := GetPhaseTotalPrice(BillsMeasureTree.FindNode(iNodeID), 'Pc');
  593. {'A','a': Result := GetTotalPrice(iNodeID);
  594. 'B','b': Result := GetPhaseTotalPrice(iNodeID, 'Deal');
  595. 'C','c': Result := GetPhaseTotalPrice(iNodeID, 'Qc');
  596. 'D','d': Result := GetPhaseTotalPrice(iNodeID, 'Pc');}
  597. end;
  598. end;
  599. function TBillsMeasureData.GetStageData: TStageData;
  600. begin
  601. Result := TProjectData(FProjectData).PhaseData.StageData;
  602. end;
  603. procedure TBillsMeasureData.ExpandNodeTo(ALevel: Integer);
  604. begin
  605. BillsMeasureTree.ExpandLevel := ALevel;
  606. end;
  607. procedure TBillsMeasureData.ExpandXmjNode;
  608. var
  609. iIndex: Integer;
  610. stnNode: TBillsIDTreeNode;
  611. begin
  612. for iIndex := 0 to BillsMeasureTree.Count - 1 do
  613. begin
  614. stnNode := TBillsIDTreeNode(BillsMeasureTree.Items[iIndex]);
  615. if (stnNode.ParentID <> -1) then
  616. stnNode.Parent.Expanded := stnNode.Rec.B_Code.AsString = '';
  617. end;
  618. end;
  619. procedure TBillsMeasureData.CalculateAll;
  620. var
  621. //Cacl: TBillsCalculate;
  622. i: Integer;
  623. begin
  624. if not TProjectData(FProjectData).StageDataReadOnly then
  625. for i := 0 to BillsMeasureTree.Count - 1 do
  626. CalculateNode(TMeasureBillsIDTreeNode(BillsMeasureTree.Items[i]));
  627. {Cacl := TBillsCalculate.Create(Self);
  628. try
  629. Cacl.Execute;
  630. finally
  631. Cacl.Free;
  632. end;}
  633. end;
  634. procedure TBillsMeasureData.UpdateRecordDeal(ABillsID: Integer; AQuantity,
  635. ATotalPrice: Double);
  636. var
  637. stnNode: TsdIDTreeNode;
  638. begin
  639. stnNode := BillsMeasureTree.FindNode(ABillsID);
  640. if not Assigned(stnNode) then Exit;
  641. with stnNode.Rec do
  642. begin
  643. if not stnNode.HasChildren then
  644. ValueByName('AddDealQuantity').AsFloat := QuantityRoundTo(
  645. ValueByName('AddDealQuantity').AsFloat + AQuantity);
  646. ValueByName('AddDealTotalPrice').AsFloat := TotalPriceRoundTo(
  647. ValueByName('AddDealTotalPrice').AsFloat + ATotalPrice);
  648. end;
  649. UpdateRecordGather(stnNode, AQuantity, ATotalPrice);
  650. UpdateRecordDeal(stnNode.ParentID, AQuantity, ATotalPrice);
  651. end;
  652. procedure TBillsMeasureData.UpdateRecordPc(ABillsID: Integer; AQuantity,
  653. ATotalPrice: Double);
  654. var
  655. stnNode: TsdIDTreeNode;
  656. begin
  657. stnNode := BillsMeasureTree.FindNode(ABillsID);
  658. if not Assigned(stnNode) then Exit;
  659. with stnNode.Rec do
  660. begin
  661. if not stnNode.HasChildren then
  662. ValueByName('AddPcQuantity').AsFloat := QuantityRoundTo(
  663. ValueByName('AddPcQuantity').AsFloat + AQuantity);
  664. ValueByName('AddPcTotalPrice').AsFloat := TotalPriceRoundTo(
  665. ValueByName('AddPcTotalPrice').AsFloat + ATotalPrice);
  666. end;
  667. UpdateRecordGather(stnNode, 0, ATotalPrice);
  668. UpdateRecordPc(stnNode.ParentID, AQuantity, ATotalPrice);
  669. end;
  670. procedure TBillsMeasureData.UpdateRecordQc(ABillsID: Integer; AQuantity,
  671. ATotalPrice: Double);
  672. var
  673. stnNode: TsdIDTreeNode;
  674. begin
  675. stnNode := BillsMeasureTree.FindNode(ABillsID);
  676. if not Assigned(stnNode) then Exit;
  677. with stnNode.Rec do
  678. begin
  679. if not stnNode.HasChildren then
  680. ValueByName('AddQcQuantity').AsFloat := QuantityRoundTo(
  681. ValueByName('AddQcQuantity').AsFloat + AQuantity);
  682. ValueByName('AddQcTotalPrice').AsFloat := TotalPriceRoundTo(
  683. ValueByName('AddQcTotalPrice').AsFloat + ATotalPrice);
  684. end;
  685. UpdateRecordGather(stnNode, AQuantity, ATotalPrice);
  686. UpdateRecordQc(stnNode.ParentID, AQuantity, ATotalPrice);
  687. end;
  688. procedure TBillsMeasureData.UpdateRecordGather(ANode: TsdIDTreeNode;
  689. AQuantity, ATotalPrice: Double);
  690. begin
  691. with ANode.Rec do
  692. begin
  693. if not ANode.HasChildren then
  694. ValueByName('AddGatherQuantity').AsFloat := QuantityRoundTo(
  695. ValueByName('AddGatherQuantity').AsFloat + AQuantity);
  696. ValueByName('AddGatherTotalPrice').AsFloat := TotalPriceRoundTo(
  697. ValueByName('AddGatherTotalPrice').AsFloat + ATotalPrice);
  698. end;
  699. CalcAddDgnPrice(ANode);
  700. CalcAddCompleteRate(ANode);
  701. end;
  702. function TBillsMeasureData.GatherRelaBGL(ANode: TsdIDTreeNode): string;
  703. var
  704. iChild: Integer;
  705. Rec: TsdDataRecord;
  706. begin
  707. Result := '';
  708. if not Assigned(ANode) then Exit;
  709. if ANode.HasChildren then
  710. begin
  711. for iChild := 0 to ANode.ChildCount - 1 do
  712. Result := MergeRelaBGL(Result, GatherRelaBGL(ANode.ChildNodes[iChild]));
  713. end
  714. else
  715. begin
  716. with TProjectData(FProjectData).PhaseData.StageData do
  717. Rec := StageRecord(ANode.ID);
  718. if Assigned(Rec) then
  719. Result := MergeRelaBGL(Rec.ValueByName('QcBGLCode').AsString, Rec.ValueByName('PcBGLCode').AsString);
  720. end;
  721. end;
  722. procedure TBillsMeasureData.sdvBillsMeasureAfterValueChanged(
  723. AValue: TsdValue);
  724. var
  725. vNode: TBillsIDTreeNode;
  726. begin
  727. if TProjectData(FProjectData).PhaseData.Active then
  728. begin
  729. if AValue.FieldName = 'Price' then
  730. StageData.ReCalculate(AValue.Owner.ValueByName('ID').AsInteger);
  731. if AValue.FieldName = 'NewPrice' then
  732. StageData.ReCalculate(AValue.Owner.ValueByName('ID').AsInteger);
  733. end;
  734. if Pos('DgnQuantity1', AValue.FieldName) > 0 then
  735. begin
  736. vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(AValue.Owner.ValueByName('ID').AsInteger));
  737. CalcAddDgnPrice(vNode);
  738. end;
  739. if (AValue.FieldName = 'Code') then
  740. begin
  741. vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(AValue.Owner.ValueByName('ID').AsInteger));
  742. BillsMeasureTree.RecodeChildrenCode(vNode, VarToStrDef(AValue.OldValue, ''), AValue.AsString);
  743. end
  744. else if (AValue.FieldName = 'B_Code') then
  745. begin
  746. vNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(AValue.Owner.ValueByName('ID').AsInteger));
  747. BillsMeasureTree.RecodeChildrenB_Code(vNode, VarToStrDef(AValue.OldValue, ''), AValue.AsString);
  748. end;
  749. end;
  750. procedure TBillsMeasureData.ExpandCurPhase;
  751. var
  752. iIndex: Integer;
  753. stnNode: TsdIDTreeNode;
  754. StageRec: TStageRecord;
  755. begin
  756. for iIndex := 0 to BillsMeasureTree.Count - 1 do
  757. begin
  758. stnNode := BillsMeasureTree.Items[iIndex];
  759. StageRec := TMeasureBillsIDTreeNode(stnNode).StageRec;
  760. if (stnNode.ParentID <> -1) then
  761. if Assigned(StageRec) then
  762. stnNode.Expanded := StageRec.GatherTotalPrice.AsFloat <> 0
  763. else
  764. stnNode.Expanded := False;
  765. end;
  766. end;
  767. procedure TBillsMeasureData.UpdateBGLInfo(ABillsID: Integer;
  768. ARec: TsdDataRecord; const AType: string);
  769. var
  770. stnNode: TsdIDTreeNode;
  771. begin
  772. stnNode := BillsMeasureTree.FindNode(ABillsID);
  773. if not Assigned(stnNode) then Exit;
  774. stnNode.Rec.ValueByName('Add' + AType + 'BGLCode').AsString :=
  775. ARec.ValueByName('End' + AType + 'BGLCode').AsString;
  776. stnNode.Rec.ValueByName('Add' + AType + 'BGLNum').AsString :=
  777. ARec.ValueByName('End' + AType + 'BGLNum').AsString;
  778. end;
  779. function TBillsMeasureData.SelectAndUpdateBGL(ABillsID: Integer;
  780. ARec: TsdDataRecord; ANewValue: Double; const AType: string): Boolean;
  781. var
  782. AOrgBGL, ANewBGL: TBGLSelectInfo;
  783. ACurNode: TsdIDTreeNode;
  784. procedure UpdateBGL;
  785. begin
  786. ARec.ValueByName(AType + 'BGLCode').AsString := ANewBGL.MergedCode;
  787. ARec.ValueByName(AType + 'BGLNum').AsString := ANewBGL.MergedNum;
  788. TProjectData(ProjectData).BGLData.ApplyBGL(AOrgBGL, ANewBGL);
  789. end;
  790. begin
  791. Result := True;
  792. ACurNode := BillsMeasureTree.FindNode(ABillsID);
  793. AOrgBGL := TBGLSelectInfo.Create(ACurNode.Rec,
  794. ARec.ValueByName(AType + 'Quantity').AsFloat, True);
  795. AOrgBGL.MergedCode := ARec.ValueByName(AType + 'BGLCode').AsString;
  796. AOrgBGL.MergedNum := ARec.ValueByName(AType + 'BGLNum').AsString;
  797. ANewBGL := TBGLSelectInfo.Create(ACurNode.Rec, ANewValue, False);
  798. try
  799. if ANewBGL.TotalNum <> 0 then
  800. begin
  801. Result := SelectBGL(AOrgBGL, ANewBGL, ProjectData);
  802. if Result then
  803. UpdateBGL;
  804. end
  805. else
  806. UpdateBGL;
  807. StageData.UpdateBGLInfo(ARec, AType);
  808. UpdateBGLInfo(ABillsID, ARec, AType);
  809. finally
  810. AOrgBGL.Free;
  811. ANewBGL.Free;
  812. end;
  813. end;
  814. procedure TBillsMeasureData.Close;
  815. begin
  816. sdvBillsMeasure.Close;
  817. end;
  818. procedure TBillsMeasureData.CalcAddCompleteRate(ANode: TsdIDTreeNode);
  819. var
  820. fDividend, fDivisor: Double;
  821. begin
  822. with ANode.Rec do
  823. begin
  824. fDividend := ValueByName('AddGatherTotalPrice').AsFloat;
  825. fDivisor := ValueByName('TotalPrice').AsFloat + ValueByName('AddQcTotalPrice').AsFloat
  826. + ValueByName('AddPcTotalPrice').AsFloat;
  827. if fDivisor <> 0 then
  828. ValueByName('AddCompleteRate').AsFloat := AdvRoundTo(fDividend/fDivisor*100)
  829. else
  830. ValueByName('AddCompleteRate').Clear;
  831. end;
  832. end;
  833. procedure TBillsMeasureData.CalcAddDgnPrice(ANode: TsdIDTreeNode);
  834. var
  835. fDividend, fDivisor: Double;
  836. begin
  837. with ANode.Rec do
  838. begin
  839. fDividend := ValueByName('AddGatherTotalPrice').AsFloat;
  840. fDivisor := ValueByName('DealDgnQuantity1').AsFloat + ValueByName('CDgnQuantity1').AsFloat;
  841. if fDivisor <> 0 then
  842. ValueByName('AddDgnPrice').AsFloat := AdvRoundTo(fDividend/fDivisor);
  843. end;
  844. end;
  845. procedure TBillsMeasureData.SetOnRecChange(const Value: TRecChangeEvent);
  846. begin
  847. FOnRecChange := Value;
  848. end;
  849. procedure TBillsMeasureData.sdvBillsMeasureCurrentChanged(
  850. ARecord: TsdDataRecord);
  851. begin
  852. if Assigned(FOnRecChange) then
  853. FOnRecChange(ARecord);
  854. end;
  855. procedure TBillsMeasureData.ResetTreeNodeStageRec;
  856. var
  857. i: Integer;
  858. vNode: TMeasureBillsIDTreeNode;
  859. begin
  860. if not StageData.Active then Exit;
  861. for i := 0 to BillsMeasureTree.Count - 1 do
  862. begin
  863. vNode := TMeasureBillsIDTreeNode(BillsMeasureTree.Items[i]);
  864. vNode.StageRec := StageData.StageRecord(vNode.ID);
  865. end;
  866. end;
  867. procedure TBillsMeasureData.UpdateRecordPM(ABillsID: Integer;
  868. ADiffer: Double);
  869. var
  870. stnNode: TBillsIDTreeNode;
  871. begin
  872. stnNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(ABillsID));
  873. if not Assigned(stnNode) then Exit;
  874. stnNode.Rec.PM_AddTotalPrice.AsFloat := stnNode.Rec.PM_AddTotalPrice.AsFloat + ADiffer;
  875. UpdateRecordPM(stnNode.ParentID, ADiffer);
  876. end;
  877. procedure TBillsMeasureData.CalculateNode(ANode: TMeasureBillsIDTreeNode);
  878. begin
  879. if Assigned(ANode.StageRec) then
  880. begin
  881. if not ANode.HasChildren then
  882. begin
  883. ANode.Rec.AddDealQuantity.AsFloat := ANode.StageRec.EndDealQuantity.AsFloat;
  884. ANode.Rec.AddQcQuantity.AsFloat := ANode.StageRec.EndQcQuantity.AsFloat;
  885. ANode.Rec.AddQcBGLCode.AsString := ANode.StageRec.EndQcBGLCode.AsString;
  886. ANode.Rec.AddQcBGLNum.AsString := ANode.StageRec.EndQcBGLNum.AsString;
  887. ANode.Rec.AddPcQuantity.AsFloat := ANode.StageRec.EndPcQuantity.AsFloat;
  888. ANode.Rec.AddPcBGLCode.AsString := ANode.StageRec.EndPcBGLCode.AsString;
  889. ANode.Rec.AddPcBGLNum.AsString := ANode.StageRec.EndPcBGLNum.AsString;
  890. ANode.Rec.AddGatherQuantity.AsFloat := ANode.StageRec.EndGatherQuantity.AsFloat;
  891. end;
  892. ANode.Rec.AddDealTotalPrice.AsFloat := ANode.StageRec.EndDealTotalPrice.AsFloat;
  893. ANode.Rec.AddQcTotalPrice.AsFloat := ANode.StageRec.EndQcTotalPrice.AsFloat;
  894. ANode.Rec.AddPcTotalPrice.AsFloat := ANode.StageRec.EndPcTotalPrice.AsFloat;
  895. ANode.Rec.AddGatherTotalPrice.AsFloat := ANode.StageRec.EndGatherTotalPrice.AsFloat;
  896. ANode.Rec.PM_AddTotalPrice.AsFloat := ANode.StageRec.PM_PreTotalPrice.AsFloat + ANode.StageRec.PM_TotalPrice.AsFloat;
  897. end;
  898. end;
  899. procedure TBillsMeasureData.UpdateGather(ABillsID: Integer;
  900. ADiffer: Double);
  901. var
  902. stnNode: TBillsIDTreeNode;
  903. begin
  904. stnNode := TBillsIDTreeNode(BillsMeasureTree.FindNode(ABillsID));
  905. if not Assigned(stnNode) then Exit;
  906. with stnNode.Rec do
  907. AddDifferValue(AddGatherTotalPrice, ADiffer);
  908. UpdateGather(stnNode.ParentID, ADiffer);
  909. end;
  910. end.