Browse Source

Task #1040 合同支付项,无公式情况,亦受起扣金额、扣款限额、计提期限控制

MaiXinRong 9 years ago
parent
commit
b6911068b2
2 changed files with 46 additions and 33 deletions
  1. 41 29
      DataModules/DealPaymentDm.pas
  2. 5 4
      DataModules/PhasePayDm.pas

+ 41 - 29
DataModules/DealPaymentDm.pas

@@ -52,7 +52,7 @@ type
     // 扣款项是否已达起扣金额
     function CheckStartedPrice(AID: Integer): Boolean;
     function CheckReachPlan(ARec: TsdDataRecord): Boolean;
-    function GetAllowTotalPrice(AID: Integer; ATotalPrice: Double): Double;
+    function GetAllowTotalPrice(AID: Integer; ATotalPrice, APreTotalPrice: Double): Double;
     procedure UpdateTotalPrice(AID: Integer; ATotalPrice: Double);
 
     function DealPayRecord(const AName: string): TsdDataRecord;
@@ -111,7 +111,7 @@ begin
 end;
 
 function TDealPaymentData.GetAllowTotalPrice(AID: Integer;
-  ATotalPrice: Double): Double;
+  ATotalPrice, APreTotalPrice: Double): Double;
 var
   Rec: TsdDataRecord;
   fAllowPrice: Double;
@@ -119,7 +119,7 @@ begin
   Result := ATotalPrice;
   Rec := sddDealPayment.FindKey('idxID', AID);
   if Rec.ValueByName('RangePrice').AsFloat = 0 then Exit;
-  fAllowPrice := Rec.ValueByName('RangePrice').AsFloat - Rec.ValueByName('TotalPrice').AsFloat;
+  fAllowPrice := Rec.ValueByName('RangePrice').AsFloat - APreTotalPrice;
   if not CheckReachPlan(Rec) then
     Result := Min(fAllowPrice, ATotalPrice)
   else
@@ -321,23 +321,32 @@ procedure TDealPaymentData.sdvDealPaymentNeedLookupRecord(
 
   procedure SetNewRecData(APayRec: TsdDataRecord);
   var
-    AID: Integer;
+    iID: Integer;
     sTPField, sFField: string;
-    fTotalPrice: Double;
+    fTotalPrice, fAllow: Double;
   begin
     sTPField := 'TotalPrice' + IntToStr(TProjectData(FProjectData).PhaseData.StageIndex);
     sFField := 'Formula' + IntToStr(TProjectData(FProjectData).PhaseData.StageIndex);
     if CheckNumeric(ANewText) then
-      APayRec.ValueByName(sTPField).AsString := ANewText
+      fTotalPrice := StrToFloat(ANewText)
     else
     begin
-      AID := ARecord.ValueByName('ID').AsInteger;
       APayRec.ValueByName(sFField).AsString := ANewText;
       ARecord.ValueByName('Formula').AsString := ANewText;
-      fTotalPrice := FPayFormula.Calculate(ANewText, ARecord.ValueByName('StartedPrice').AsFloat);
-      if CheckStartedPrice(AID) then
-        APayRec.ValueByName(sTPField).AsFloat := GetAllowTotalPrice(AID, fTotalPrice);
+      fTotalPrice := FPayFormula.Calculate(ANewText);
     end;
+    iID := ARecord.ValueByName('ID').AsInteger;
+    if CheckStartedPrice(iID) then
+    begin
+      fAllow := GetAllowTotalPrice(iID, fTotalPrice, 0);
+      APayRec.ValueByName(sTPField).AsFloat := fAllow;
+      if fAllow < fTotalPrice then
+        TipMessage(Format('“%s”已达扣款限额,本期金额计%s。', [ARecord.ValueByName('Name').AsString, FloatToStr(fAllow)]))
+      else if fAllow > fTotalPrice then
+        TipMessage(Format('“%s”已达计提期限,本期金额计%s。', [ARecord.ValueByName('Name').AsString, FloatToStr(fAllow)]));
+    end
+    else
+      TipMessage(Format('“%s”未达到起扣金额,本期金额计零。', [ARecord.ValueByName('Name').AsString]));
   end;
 
 var
@@ -433,9 +442,9 @@ procedure TDealPaymentData.sdvDealPaymentSetText(var Text: string;
 
   procedure DoCurTotalPriceChanged;
   var
-    AID: Integer;
-    sFField: string;
-    fTotalPrice: Double;
+    iID: Integer;
+    sFField, sPreField: string;
+    fTotalPrice, fAllow: Double;
     Rec: TsdDataRecord;
   begin
     Rec := sddDealPayment.FindKey('idxID', ARecord.ValueByName('ID').AsInteger);
@@ -444,26 +453,29 @@ procedure TDealPaymentData.sdvDealPaymentSetText(var Text: string;
     begin
       Rec.ValueByName('Formula').AsString := '';
       AValue.Owner.ValueByName(sFField).AsString := '';
-      {AID := ARecord.ValueByName('ID').AsInteger;
-      fTotalPrice := StrToFloatDef(Text, 0) - AValue.AsFloat;
-      if CheckStartedPrice(AID) then
-        Text := FloatToStr(AValue.AsFloat + GetAllowTotalPrice(AID, fTotalPrice))
-      else
-        Text := '';}
+      fTotalPrice := StrToFloatDef(Text, 0);
     end
     else
     begin
       Rec.ValueByName('Formula').AsString := Text;
       AValue.Owner.ValueByName(sFField).AsString := Text;
-      AID := ARecord.ValueByName('ID').AsInteger;
-      if ARecord.ValueByName('Pre' + AValue.FieldName).AsFloat = 0 then
-        fTotalPrice := FPayFormula.Calculate(Text, Rec.ValueByName('StartedPrice').AsFloat) - AValue.AsFloat
-      else
-        fTotalPrice := FPayFormula.Calculate(Text) - AValue.AsFloat;
-      if CheckStartedPrice(AID) then
-        Text := FloatToStr(AValue.AsFloat + GetAllowTotalPrice(AID, fTotalPrice))
-      else
-        Text := '';
+      fTotalPrice := FPayFormula.Calculate(Text);
+    end;
+    iID := ARecord.ValueByName('ID').AsInteger;
+    if CheckStartedPrice(iID) then
+    begin
+      sPreField := StringReplace(AValue.FieldName, 'TotalPrice', 'PreTotalPrice', []);
+      fAllow := GetAllowTotalPrice(iID, fTotalPrice, ARecord.ValueByName(sPreField).AsFloat);
+      Text := FloatToStr(fAllow);
+      if fAllow < fTotalPrice then
+        TipMessage(Format('“%s”已达扣款限额,本期金额计%s。', [Rec.ValueByName('Name').AsString, Text]))
+      else if fAllow > fTotalPrice then
+        TipMessage(Format('“%s”已达计提期限,本期金额计%s。', [Rec.ValueByName('Name').AsString, Text]));
+    end
+    else
+    begin
+      Text := '';
+      TipMessage(Format('“%s”未达到起扣金额,本期金额计零。', [Rec.ValueByName('Name').AsString]));
     end;
   end;
 
@@ -494,7 +506,7 @@ begin
     DoStartedPriceChanged;
   if SameText('RangePrice', AValue.FieldName) then
     DoRangePriceChanged;
-  if Pos('TotalPrice', AValue.FieldName) = 1 then
+  if SameText('CurTotalPrice', AColumn.FieldName) then
     if TProjectData(FProjectData).ProjProperties.PhaseCount > 0 then
       DoCurTotalPriceChanged
     else

+ 5 - 4
DataModules/PhasePayDm.pas

@@ -170,13 +170,14 @@ procedure TPhasePayData.Calculate(AID: Integer);
 var
   Rec: TsdDataRecord;
   // 金额列名, 公式列名
-  sTPField, sFField: string;
+  sTPField, sFField, sPreField: string;
   iID: Integer;
   fTotalPrice, fStartedPrice: Double;
 begin
   Rec := sddPhasePay.FindKey('idxID', AID);
   sTPField := 'TotalPrice' + IntToStr(TPhaseData(FPhaseData).StageIndex);
   sFField := 'Formula' + IntToStr(TPhaseData(FPhaseData).StageIndex);
+  sPreField := 'PreTotalPrice' + IntToStr(TPhaseData(FPhaseData).StageIndex);
   if Rec.ValueByName(sFField).AsString <> '' then
   begin
     with TProjectData(TPhaseData(FPhaseData).ProjectData).DealPaymentData do
@@ -186,11 +187,11 @@ begin
       fStartedPrice :=  GetStartedPrice(iID);
       // 初次达到起扣金额时,bqwc基数值取值为累计完成计量-起扣金额
       if Rec.ValueByName('Pre'+sTPField).AsFloat = 0 then
-        fTotalPrice := FPayFormula.Calculate(Rec.ValueByName(sFField).AsString, fStartedPrice) - Rec.ValueByName(sTPField).AsFloat
+        fTotalPrice := FPayFormula.Calculate(Rec.ValueByName(sFField).AsString, fStartedPrice)
       else
-        fTotalPrice := FPayFormula.Calculate(Rec.ValueByName(sFField).AsString) - Rec.ValueByName(sTPField).AsFloat;
+        fTotalPrice := FPayFormula.Calculate(Rec.ValueByName(sFField).AsString);
       if CheckStartedPrice(iID) then
-        Rec.ValueByName(sTPField).AsFloat := Rec.ValueByName(sTPField).AsFloat + GetAllowTotalPrice(iID, fTotalPrice)
+        Rec.ValueByName(sTPField).AsFloat := GetAllowTotalPrice(iID, fTotalPrice, Rec.ValueByName(sPreField).AsFloat)
       else
         Rec.ValueByName(sTPField).AsFloat := 0;
     end;