Upgrade to 721 Script Error: Difference between revisions

From eStream Software
 
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:
==Problem==
==Problem==
You will get below error when you either selecting itemcode or changes value in you UDF which trigger the function.
You will get below error when you either selecting itemcode or changes value in you UDF which trigger the function.
::[[File:Error-721-TaxRate-01.jpg]]
::[[File:Error-721-TaxRate-01.jpg|center]]


==Solution==
==Solution==
Below is example error happen at '''Sales Invoice'''<br />
Below is example error happen at '''Sales Invoice'''<br />
01. Click '''Tools | DIY | SQL Control Center...'''<br />
01. Click '''Tools | DIY | SQL Control Center...'''<br />
02. At the left panel look for '''Sales Invoice | OnGridColumnValuechange'''<br />
02. At the left panel look for '''Sales Invoice | OnGridColumnValuechange''' and/or '''OnBeforeSave'''<br />
::[[File:Error-721-TaxRate-02.jpg|750px]]
[[File:Error-721-TaxRate-02.jpg|750px|center]]
03. Look for the script like '''function GetTaxedValue(AValue: Variant; lTaxRate: string): Variant;'''. Something like above<br />
03. Look for the script like '''function GetTaxedValue(AValue: Variant; lTaxRate: string): Variant;'''. Something like above<br />
04. Change all to below new script<br />
04. Change all to below new script<br />
===For OnGridColumnValueChange Script===
<syntaxhighlight lang="delphi">
<syntaxhighlight lang="delphi">
function GetTaxedValue(AValue: Variant; lTaxRate: string): Variant;
function GetTaxedValue(AValue: Variant; lTaxRate: string): Variant;
Line 25: Line 26:
   lStrLst := TStringList.Create;
   lStrLst := TStringList.Create;
   TaxRate := DataSet.FindField('TaxRate').AsString;
   TaxRate := DataSet.FindField('TaxRate').AsString;
  try
    try
      lStrLst.Delimiter := '&';
      S := Trim(StringReplace(TaxRate, '+', '&', [rfReplaceAll]));
      lStrLst.DelimitedText := Trim(StringReplace(s, 'E', '', [rfReplaceAll]));
      for I := 0 to lStrLst.Count - 1 do
      begin
        S := Trim(lStrLst.Strings[I]);
        if S[Length(S)] = '%' then
        begin
          S := Trim(Copy(S, 1, Length(S) - 1));
          AValue := AValue * ((100 + StrToFloat(S)) / 100);
        end
        else
          AValue := AValue + StrToFloat(S);
      end;
      Result := AValue;
    except
      RaiseException(ExceptionType, 'Tax Rate formatting error ');
    end;
  finally
    lStrLst.Free;
  end;
end;
</syntaxhighlight>
===For OnBeforeSave Script===
<syntaxhighlight lang="delphi">
function GetTaxedValue(AValue: Variant; lTaxRate: string): Variant;
var lStrLst: TStringList;
    TaxRate, S: string;
    I: Integer;
begin
  Result  := Null;
  lStrLst := TStringList.Create;
  TaxRate := D.DataSet.FindField('TaxRate').AsString;
   try
   try
     try
     try

Latest revision as of 08:17, 13 November 2015

Introduction

This happen if you had write script to get the TaxRate from Maintain Tax on

  • OnGridColumnValueChange Script and/or
  • OnBeforeSave Script

This due to changing SQLAccounting Coding Structure to cater future Changes in Tax Rate

Problem

You will get below error when you either selecting itemcode or changes value in you UDF which trigger the function.

Error-721-TaxRate-01.jpg

Solution

Below is example error happen at Sales Invoice
01. Click Tools | DIY | SQL Control Center...
02. At the left panel look for Sales Invoice | OnGridColumnValuechange and/or OnBeforeSave

Error-721-TaxRate-02.jpg

03. Look for the script like function GetTaxedValue(AValue: Variant; lTaxRate: string): Variant;. Something like above
04. Change all to below new script

For OnGridColumnValueChange Script

function GetTaxedValue(AValue: Variant; lTaxRate: string): Variant;
var lStrLst: TStringList;
    TaxRate, S: string;
    I: Integer;
begin
  Result  := Null;
  lStrLst := TStringList.Create;
  TaxRate := DataSet.FindField('TaxRate').AsString;
  try
    try
      lStrLst.Delimiter := '&'; 
      S := Trim(StringReplace(TaxRate, '+', '&', [rfReplaceAll]));
      lStrLst.DelimitedText := Trim(StringReplace(s, 'E', '', [rfReplaceAll])); 
      for I := 0 to lStrLst.Count - 1 do
      begin
        S := Trim(lStrLst.Strings[I]);
        if S[Length(S)] = '%' then
        begin
          S := Trim(Copy(S, 1, Length(S) - 1));
          AValue := AValue * ((100 + StrToFloat(S)) / 100);
        end
        else
          AValue := AValue + StrToFloat(S);
      end;
      Result := AValue;
    except
      RaiseException(ExceptionType, 'Tax Rate formatting error ');
    end;
  finally
    lStrLst.Free;
  end;
end;

For OnBeforeSave Script

function GetTaxedValue(AValue: Variant; lTaxRate: string): Variant;
var lStrLst: TStringList;
    TaxRate, S: string;
    I: Integer;
begin
  Result  := Null;
  lStrLst := TStringList.Create;
  TaxRate := D.DataSet.FindField('TaxRate').AsString;
  try
    try
      lStrLst.Delimiter := '&'; 
      S := Trim(StringReplace(TaxRate, '+', '&', [rfReplaceAll]));
      lStrLst.DelimitedText := Trim(StringReplace(s, 'E', '', [rfReplaceAll])); 
      for I := 0 to lStrLst.Count - 1 do
      begin
        S := Trim(lStrLst.Strings[I]);
        if S[Length(S)] = '%' then
        begin
          S := Trim(Copy(S, 1, Length(S) - 1));
          AValue := AValue * ((100 + StrToFloat(S)) / 100);
        end
        else
          AValue := AValue + StrToFloat(S);
      end;
      Result := AValue;
    except
      RaiseException(ExceptionType, 'Tax Rate formatting error ');
    end;
  finally
    lStrLst.Free;
  end;
end;

See also