DealPayPlanFrm.pas 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. unit DealPayPlanFrm;
  2. interface
  3. uses
  4. sdDB,
  5. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  6. Dialogs, StdCtrls, ExtCtrls, ComCtrls, JimPages;
  7. type
  8. TDealPayPlanForm = class(TForm)
  9. lblTitle: TLabel;
  10. lblDealPayName: TLabel;
  11. lblTitle2: TLabel;
  12. btnOk: TButton;
  13. btnCancel: TButton;
  14. lblPlanType: TLabel;
  15. rbIsPlanPhase: TRadioButton;
  16. rbIsPlanPrice: TRadioButton;
  17. lblResultPre: TLabel;
  18. lblResult: TLabel;
  19. lblResultPost: TLabel;
  20. gbPhase: TGroupBox;
  21. leDeadlinePhase: TLabeledEdit;
  22. udDeadlinePhase: TUpDown;
  23. gbPrice: TGroupBox;
  24. rbAddGatherTotalPrice: TRadioButton;
  25. rbAddDealTotalPrice: TRadioButton;
  26. rbAddQCTotalPrice: TRadioButton;
  27. lePDFormula: TLabeledEdit;
  28. rbIsPlanNon: TRadioButton;
  29. lblEquar: TLabel;
  30. lblPriceDeadline: TLabel;
  31. procedure btnOkClick(Sender: TObject);
  32. procedure rbIsPlanNonClick(Sender: TObject);
  33. procedure rbAddGatherTotalPriceClick(Sender: TObject);
  34. procedure udDeadlinePhaseClick(Sender: TObject; Button: TUDBtnType);
  35. procedure leDeadlinePhaseKeyPress(Sender: TObject; var Key: Char);
  36. procedure leDeadlinePhaseChange(Sender: TObject);
  37. procedure lePDFormulaExit(Sender: TObject);
  38. private
  39. FDealPayRec: TsdDataRecord;
  40. FProjectData: TObject;
  41. FPlanType: Integer;
  42. FPlanSubType: Integer;
  43. //FFormulaSet: t
  44. procedure InitForm;
  45. procedure AssignResult;
  46. procedure SetPlanType(const Value: Integer);
  47. procedure SetPlanSubType(const Value: Integer);
  48. function GetPhaseDeadline: Integer;
  49. procedure SetPhaseDeadline(const Value: Integer);
  50. function GetPriceDeadline: Double;
  51. procedure SetPriceDeadline(const Value: Double);
  52. function GetPDFormula: string;
  53. procedure SetPDFormula(const Value: string);
  54. function GetLimitPrice: Double;
  55. function GetPlanSubTypeName: string;
  56. public
  57. constructor Create(ADealPayRec: TsdDataRecord; AProjectData: TObject);
  58. destructor Destroy; override;
  59. procedure SavePlanInfos;
  60. property PlanType: Integer read FPlanType write SetPlanType;
  61. property PlanSubType: Integer read FPlanSubType write SetPlanSubType;
  62. property PlanSubTypeName: string read GetPlanSubTypeName;
  63. property PhaseDeadline: Integer read GetPhaseDeadline write SetPhaseDeadline;
  64. property PriceDeadline: Double read GetPriceDeadline write SetPriceDeadline;
  65. property PDFormula: string read GetPDFormula write SetPDFormula;
  66. property LimitPrice: Double read GetLimitPrice;
  67. end;
  68. implementation
  69. uses
  70. UtilMethods, ProjectData, BillsDm, DealPaymentDm, ZhAPI;
  71. {$R *.dfm}
  72. { TDealPayPlanForm }
  73. constructor TDealPayPlanForm.Create(ADealPayRec: TsdDataRecord; AProjectData: TObject);
  74. begin
  75. inherited Create(nil);
  76. FDealPayRec := ADealPayRec;
  77. FProjectData := AProjectData;
  78. InitForm;
  79. end;
  80. destructor TDealPayPlanForm.Destroy;
  81. begin
  82. inherited;
  83. end;
  84. procedure TDealPayPlanForm.InitForm;
  85. begin
  86. lblDealPayName.Caption := FDealPayRec.ValueByName('Name').AsString;
  87. lblTitle2.Left := lblDealPayName.Left + lblDealPayName.Width + 6;
  88. PlanType := FDealPayRec.ValueByName('PlanType').AsInteger;
  89. if PlanType = 1 then
  90. PhaseDeadline := FDealPayRec.ValueByName('PlanDeadline').AsInteger
  91. else if PlanType = 2 then
  92. begin
  93. PlanSubType := FDealPayRec.ValueByName('PlanSubType').AsInteger;
  94. PriceDeadline := FDealPayRec.ValueByName('PlanDeadline').AsFloat;
  95. PDFormula := FDealPayRec.ValueByName('PDFormula').AsString;
  96. end;
  97. end;
  98. procedure TDealPayPlanForm.SavePlanInfos;
  99. begin
  100. FDealPayRec.ValueByName('PlanType').AsInteger := PlanType;
  101. if PlanType = 0 then
  102. begin
  103. FDealPayRec.ValueByName('PlanSubType').AsInteger := 0;
  104. FDealPayRec.ValueByName('PlanDeadline').AsFloat := 0;
  105. FDealPayRec.ValueByName('PDFormula').AsString := '';
  106. end
  107. else if PlanType = 1 then
  108. begin
  109. FDealPayRec.ValueByName('PlanSubType').AsInteger := 0;
  110. FDealPayRec.ValueByName('PlanDeadline').AsInteger := PhaseDeadline;
  111. FDealPayRec.ValueByName('PDFormula').AsString := '';
  112. end
  113. else
  114. begin
  115. FDealPayRec.ValueByName('PlanSubType').AsInteger := PlanSubType;
  116. FDealPayRec.ValueByName('PlanDeadline').AsFloat := PriceDeadline;
  117. FDealPayRec.ValueByName('PDFormula').AsString := PDFormula;
  118. end;
  119. end;
  120. procedure TDealPayPlanForm.SetPriceDeadline(const Value: Double);
  121. begin
  122. lblPriceDeadline.Caption := FloatToStr(Value);
  123. end;
  124. procedure TDealPayPlanForm.SetPlanSubType(const Value: Integer);
  125. begin
  126. FPlanSubType := Value;
  127. rbAddGatherTotalPrice.Checked := FPlanSubType = 0;
  128. rbAddDealTotalPrice.Checked := FPlanSubType = 1;
  129. rbAddQCTotalPrice.Checked := FPlanSubType = 2;
  130. AssignResult;
  131. end;
  132. procedure TDealPayPlanForm.SetPlanType(const Value: Integer);
  133. begin
  134. FPlanType := Value;
  135. rbIsPlanNon.Checked := FPlanType = 0;
  136. rbIsPlanPhase.Checked := FPlanType = 1;
  137. rbIsPlanPrice.Checked := FPlanType = 2;
  138. gbPhase.Enabled := rbIsPlanPhase.Checked;
  139. if gbPhase.Enabled then
  140. gbPhase.Font.Color := clBlack
  141. else
  142. gbPhase.Font.Color := clGray;
  143. gbPrice.Enabled := rbIsPlanPrice.Checked;
  144. if gbPrice.Enabled then
  145. gbPrice.Font.Color := clBlack
  146. else
  147. gbPrice.Font.Color := clGray;
  148. AssignResult;
  149. end;
  150. procedure TDealPayPlanForm.SetPhaseDeadline(const Value: Integer);
  151. begin
  152. udDeadlinePhase.Position := Value;
  153. end;
  154. procedure TDealPayPlanForm.btnOkClick(Sender: TObject);
  155. begin
  156. if (PlanType = 2) and (PriceDeadline < LimitPrice) then
  157. ErrorMessage(Format('当前“%s”已计量至%f,限制金额应大于该值!', [PlanSubTypeName, LimitPrice]))
  158. else
  159. ModalResult := mrOk;
  160. end;
  161. function TDealPayPlanForm.GetPhaseDeadline: Integer;
  162. begin
  163. Result := udDeadlinePhase.Position;
  164. end;
  165. function TDealPayPlanForm.GetPriceDeadline: Double;
  166. begin
  167. Result := StrToFloat(lblPriceDeadline.Caption);
  168. end;
  169. function TDealPayPlanForm.GetPDFormula: string;
  170. begin
  171. Result := lePDFormula.Text;
  172. end;
  173. procedure TDealPayPlanForm.SetPDFormula(const Value: string);
  174. begin
  175. lePDFormula.Text := Value;
  176. end;
  177. function TDealPayPlanForm.GetLimitPrice: Double;
  178. begin
  179. with TProjectData(FProjectData).BillsData do
  180. begin
  181. case PlanSubType of
  182. 0: Result := Settlement[4];
  183. 1: Result := Settlement[1];
  184. 2: Result := Settlement[2] + Settlement[3];
  185. end;
  186. end;
  187. end;
  188. procedure TDealPayPlanForm.rbIsPlanNonClick(Sender: TObject);
  189. begin
  190. if PlanType <> TRadioButton(Sender).Tag then
  191. PlanType := TRadioButton(Sender).Tag;
  192. end;
  193. procedure TDealPayPlanForm.rbAddGatherTotalPriceClick(Sender: TObject);
  194. begin
  195. if PlanSubType <> TRadioButton(Sender).Tag then
  196. PlanSubType := TRadioButton(Sender).Tag;
  197. end;
  198. procedure TDealPayPlanForm.AssignResult;
  199. procedure CalcPriceDeadline;
  200. begin
  201. if CheckStringNull(PDFormula) then
  202. PriceDeadline := 0
  203. else if CheckNumeric(PDFormula) then
  204. PriceDeadline := StrToFloatDef(PDFormula, 0)
  205. else if Pos('bqwc', PDFormula) > 0 then
  206. begin
  207. ErrorMessage('不可使用“本期完成计量”计算基数!');
  208. PriceDeadline := 0;
  209. end
  210. else
  211. PriceDeadline := TProjectData(FProjectData).DealPaymentData.PayFormula.Calculate(PDFormula);
  212. end;
  213. function GetResult: String;
  214. begin
  215. case PlanType of
  216. 0: Result := '无';
  217. 1: Result := Format('当 计量期数 > %d 时,', [PhaseDeadline]);
  218. 2: Result := Format('当 %s > %f 时', [PlanSubTypeName, PriceDeadline]);
  219. end;
  220. end;
  221. begin
  222. if PlanType = 2 then
  223. CalcPriceDeadline;
  224. lblResult.Caption := GetResult;
  225. lblResultPost.Visible := PlanType <> 0;
  226. end;
  227. function TDealPayPlanForm.GetPlanSubTypeName: string;
  228. begin
  229. case PlanSubType of
  230. 0: Result := '累计完成计量金额';
  231. 1: Result := '累计合同计量金额';
  232. 2: Result := '累计变更计量金额';
  233. end;
  234. end;
  235. procedure TDealPayPlanForm.udDeadlinePhaseClick(Sender: TObject;
  236. Button: TUDBtnType);
  237. begin
  238. AssignResult;
  239. end;
  240. procedure TDealPayPlanForm.leDeadlinePhaseKeyPress(Sender: TObject;
  241. var Key: Char);
  242. begin
  243. if Key = #13 then
  244. btnOk.SetFocus;
  245. end;
  246. procedure TDealPayPlanForm.leDeadlinePhaseChange(Sender: TObject);
  247. begin
  248. AssignResult;
  249. end;
  250. procedure TDealPayPlanForm.lePDFormulaExit(Sender: TObject);
  251. begin
  252. AssignResult;
  253. end;
  254. end.