DealPayPlanFrm.pas 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. ClientHeight := 259;
  87. ClientWidth := 403;
  88. lblDealPayName.Caption := FDealPayRec.ValueByName('Name').AsString;
  89. lblTitle2.Left := lblDealPayName.Left + lblDealPayName.Width + 6;
  90. PlanType := FDealPayRec.ValueByName('PlanType').AsInteger;
  91. if PlanType = 1 then
  92. PhaseDeadline := FDealPayRec.ValueByName('PlanDeadline').AsInteger
  93. else if PlanType = 2 then
  94. begin
  95. PlanSubType := FDealPayRec.ValueByName('PlanSubType').AsInteger;
  96. PriceDeadline := FDealPayRec.ValueByName('PlanDeadline').AsFloat;
  97. PDFormula := FDealPayRec.ValueByName('PDFormula').AsString;
  98. end;
  99. end;
  100. procedure TDealPayPlanForm.SavePlanInfos;
  101. begin
  102. FDealPayRec.ValueByName('PlanType').AsInteger := PlanType;
  103. if PlanType = 0 then
  104. begin
  105. FDealPayRec.ValueByName('PlanSubType').AsInteger := 0;
  106. FDealPayRec.ValueByName('PlanDeadline').AsFloat := 0;
  107. FDealPayRec.ValueByName('PDFormula').AsString := '';
  108. end
  109. else if PlanType = 1 then
  110. begin
  111. FDealPayRec.ValueByName('PlanSubType').AsInteger := 0;
  112. FDealPayRec.ValueByName('PlanDeadline').AsInteger := PhaseDeadline;
  113. FDealPayRec.ValueByName('PDFormula').AsString := '';
  114. end
  115. else
  116. begin
  117. FDealPayRec.ValueByName('PlanSubType').AsInteger := PlanSubType;
  118. FDealPayRec.ValueByName('PlanDeadline').AsFloat := PriceDeadline;
  119. FDealPayRec.ValueByName('PDFormula').AsString := PDFormula;
  120. end;
  121. end;
  122. procedure TDealPayPlanForm.SetPriceDeadline(const Value: Double);
  123. begin
  124. lblPriceDeadline.Caption := FloatToStr(Value);
  125. end;
  126. procedure TDealPayPlanForm.SetPlanSubType(const Value: Integer);
  127. begin
  128. FPlanSubType := Value;
  129. rbAddGatherTotalPrice.Checked := FPlanSubType = 0;
  130. rbAddDealTotalPrice.Checked := FPlanSubType = 1;
  131. rbAddQCTotalPrice.Checked := FPlanSubType = 2;
  132. AssignResult;
  133. end;
  134. procedure TDealPayPlanForm.SetPlanType(const Value: Integer);
  135. begin
  136. FPlanType := Value;
  137. rbIsPlanNon.Checked := FPlanType = 0;
  138. rbIsPlanPhase.Checked := FPlanType = 1;
  139. rbIsPlanPrice.Checked := FPlanType = 2;
  140. gbPhase.Enabled := rbIsPlanPhase.Checked;
  141. if gbPhase.Enabled then
  142. gbPhase.Font.Color := clBlack
  143. else
  144. gbPhase.Font.Color := clGray;
  145. gbPrice.Enabled := rbIsPlanPrice.Checked;
  146. if gbPrice.Enabled then
  147. gbPrice.Font.Color := clBlack
  148. else
  149. gbPrice.Font.Color := clGray;
  150. AssignResult;
  151. end;
  152. procedure TDealPayPlanForm.SetPhaseDeadline(const Value: Integer);
  153. begin
  154. udDeadlinePhase.Position := Value;
  155. end;
  156. procedure TDealPayPlanForm.btnOkClick(Sender: TObject);
  157. begin
  158. if (PlanType = 2) and (PriceDeadline < LimitPrice) then
  159. ErrorMessage(Format('当前“%s”已计量至%f,限制金额应大于该值!', [PlanSubTypeName, LimitPrice]))
  160. else
  161. ModalResult := mrOk;
  162. end;
  163. function TDealPayPlanForm.GetPhaseDeadline: Integer;
  164. begin
  165. Result := udDeadlinePhase.Position;
  166. end;
  167. function TDealPayPlanForm.GetPriceDeadline: Double;
  168. begin
  169. Result := StrToFloat(lblPriceDeadline.Caption);
  170. end;
  171. function TDealPayPlanForm.GetPDFormula: string;
  172. begin
  173. Result := lePDFormula.Text;
  174. end;
  175. procedure TDealPayPlanForm.SetPDFormula(const Value: string);
  176. begin
  177. lePDFormula.Text := Value;
  178. end;
  179. function TDealPayPlanForm.GetLimitPrice: Double;
  180. begin
  181. with TProjectData(FProjectData).BillsData do
  182. begin
  183. case PlanSubType of
  184. 0: Result := Settlement[4];
  185. 1: Result := Settlement[1];
  186. 2: Result := Settlement[2] + Settlement[3];
  187. end;
  188. end;
  189. end;
  190. procedure TDealPayPlanForm.rbIsPlanNonClick(Sender: TObject);
  191. begin
  192. if PlanType <> TRadioButton(Sender).Tag then
  193. PlanType := TRadioButton(Sender).Tag;
  194. end;
  195. procedure TDealPayPlanForm.rbAddGatherTotalPriceClick(Sender: TObject);
  196. begin
  197. if PlanSubType <> TRadioButton(Sender).Tag then
  198. PlanSubType := TRadioButton(Sender).Tag;
  199. end;
  200. procedure TDealPayPlanForm.AssignResult;
  201. procedure CalcPriceDeadline;
  202. begin
  203. if CheckStringNull(PDFormula) then
  204. PriceDeadline := 0
  205. else if CheckNumeric(PDFormula) then
  206. PriceDeadline := StrToFloatDef(PDFormula, 0)
  207. else if Pos('bqwc', PDFormula) > 0 then
  208. begin
  209. ErrorMessage('不可使用“本期完成计量”计算基数!');
  210. PriceDeadline := 0;
  211. end
  212. else
  213. PriceDeadline := TProjectData(FProjectData).DealPaymentData.PayFormula.Calculate(PDFormula);
  214. end;
  215. function GetResult: String;
  216. begin
  217. case PlanType of
  218. 0: Result := '无';
  219. 1: Result := Format('当 计量期数 >= %d 时,', [PhaseDeadline]);
  220. 2: Result := Format('当 %s >= %f 时', [PlanSubTypeName, PriceDeadline]);
  221. end;
  222. end;
  223. begin
  224. if PlanType = 2 then
  225. CalcPriceDeadline;
  226. lblResult.Caption := GetResult;
  227. lblResultPost.Visible := PlanType <> 0;
  228. end;
  229. function TDealPayPlanForm.GetPlanSubTypeName: string;
  230. begin
  231. case PlanSubType of
  232. 0: Result := '累计完成计量金额';
  233. 1: Result := '累计合同计量金额';
  234. 2: Result := '累计变更计量金额';
  235. end;
  236. end;
  237. procedure TDealPayPlanForm.udDeadlinePhaseClick(Sender: TObject;
  238. Button: TUDBtnType);
  239. begin
  240. AssignResult;
  241. end;
  242. procedure TDealPayPlanForm.leDeadlinePhaseKeyPress(Sender: TObject;
  243. var Key: Char);
  244. begin
  245. if Key = #13 then
  246. btnOk.SetFocus;
  247. end;
  248. procedure TDealPayPlanForm.leDeadlinePhaseChange(Sender: TObject);
  249. begin
  250. AssignResult;
  251. end;
  252. procedure TDealPayPlanForm.lePDFormulaExit(Sender: TObject);
  253. begin
  254. AssignResult;
  255. end;
  256. end.