瀏覽代碼

Bug #834 台账分解,金额应可输入公式

MaiXinRong 9 年之前
父節點
當前提交
f41f8a5898
共有 2 個文件被更改,包括 26 次插入14 次删除
  1. 21 12
      DataModules/BillsCompileDm.pas
  2. 5 2
      DataModules/BillsDm.pas

+ 21 - 12
DataModules/BillsCompileDm.pas

@@ -558,22 +558,33 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
     Allow := False;
   end;
 
-  procedure SetQuantity(const APre: string);
+  procedure SetQuantity(const AFieldName: string);
+  var
+    sPre: string;
   begin
-    // 0号台账改为三项合计后,不记录输入的公式,但允许公式计算
+    sPre := StringReplace(AFieldName, 'Quantity', '', [rfIgnoreCase, rfReplaceAll]);
     if CheckStringNull(Text) or CheckNumeric(Text) then
       Text := FloatToStr(QuantityRoundTo(StrToFloatDef(Text, 0)))
     else
     begin
-      ARecord.ValueByName(APre + 'Formula').AsString := Text;
+      ARecord.ValueByName(sPre + 'Formula').AsString := Text;
       Text := FloatToStr(QuantityRoundTo(EvaluateExprs(Text)));
     end;
     ARecord.ValueByName('CalcType').AsInteger := 0;
   end;
 
-  procedure SetTotalPrice;
+  procedure SetTotalPrice(const AFieldName: string);
+  var
+    sPre: string;
   begin
-    Text := FloatToStr(TotalPriceRoundTo(StrToFloatDef(Text, 0)));
+    sPre := StringReplace(AFieldName, 'TotalPrice', '', [rfIgnoreCase, rfReplaceAll]);
+    if CheckStringNull(Text) or CheckNumeric(Text) then
+      Text := FloatToStr(TotalPriceRoundTo(StrToFloatDef(Text, 0)))
+    else
+    begin
+      ARecord.ValueByName(sPre + 'Formula').AsString := Text;
+      Text := FloatToStr(TotalPriceRoundTo(EvaluateExprs(Text)));
+    end;
     ARecord.ValueByName('CalcType').AsInteger := 1;
   end;
 
@@ -589,16 +600,14 @@ procedure TBillsCompileData.sdvBillsCompileSetText(var Text: String;
 
   procedure DoCurChanged;
   begin
-    if SameText(AColumn.FieldName, 'OrgQuantity') then
-      SetQuantity('Org')
-    else if SameText(AColumn.FieldName, 'MisQuantity') then
-      SetQuantity('Mis')
-    else if SameText(AColumn.FieldName, 'OthQuantity') then
-      SetQuantity('Oth')
+    if SameText(AColumn.FieldName, 'OrgQuantity') or
+        SameText(AColumn.FieldName, 'MisQuantity') or
+        SameText(AColumn.FieldName, 'OthQuantity')then
+      SetQuantity(AColumn.FieldName)
     else if SameText(AColumn.FieldName, 'OrgTotalPrice') or
         SameText(AColumn.FieldName, 'MisTotalPrice') or
         SameText(AColumn.FieldName, 'OthTotalPrice') then
-      SetTotalPrice
+      SetTotalPrice(AColumn.FieldName)
     else if Pos('DgnQuantity', AColumn.FieldName) = 1 then
       SetDgnQuantity
     else if SameText(AColumn.FieldName, 'Price') then

+ 5 - 2
DataModules/BillsDm.pas

@@ -132,8 +132,11 @@ begin
     sddBills.AddIndex('idxID', 'ID');
     
   sddBills.FieldByName('OrgQuantity').ValidChars := sddBills.FieldByName('Quantity').ValidChars + ArithmeticCharSet;
-  sddBills.FieldByName('MisQuantity').ValidChars := sddBills.FieldByName('Quantity').ValidChars + ArithmeticCharSet;
-  sddBills.FieldByName('OthQuantity').ValidChars := sddBills.FieldByName('Quantity').ValidChars + ArithmeticCharSet;
+  sddBills.FieldByName('OrgTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
+  sddBills.FieldByName('MisQuantity').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
+  sddBills.FieldByName('MisTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
+  sddBills.FieldByName('OthQuantity').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
+  sddBills.FieldByName('OthTotalPrice').ValidChars := sddBills.FieldByName('OrgQuantity').ValidChars;
 end;
 
 procedure TBillsData.Save;