Lock Report by User: Difference between revisions

From eStream Software
(Created page with "==Introduction== <br /> ==Updates== Last Customisation Update : 06 Nov 2015 ==Criterias== ===Maintain User=== ''[Tools | Maintain User...]'' 1. User Advanced Lock. ::{| cl...")
 
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Introduction==
==Introduction==
 
For some reason, the company managers wish to let users to check and view the report by themselves. They cannot access other users data, eg. agent A cannot see agent B sales value. Therefore, we have come out this script to lock at the report according to the user rights.
<br />
<br />


==Updates==
==Updates==
Last Customisation Update : 06 Nov 2015
Last Customisation Update : 07 Nov 2015


==Criterias==
==Criterias==
Line 10: Line 10:
''[Tools | Maintain User...]''
''[Tools | Maintain User...]''


1. User Advanced Lock.
1. Advanced Lock in Maintain User.
::{| class="wikitable"
::{| class="wikitable"
|-
|-
! Types !! Field Name !! Data Types !! Length !! Usage
! Types !! Field Name !! Data Types !! Length !! Usage
|-
|-
| DIY-F || Code || String || 30 || Product Code, eg. EA 6035 (NA)
| STD || Code || String || 20 || User ID, eg. LEE
|-
| STD || Name || String || 100 || User Name
|-
|-
| STD ||Description || String || 200 || Product Name
| DIY-F || Agent_Lock || Boolean || False value: 0 <br /> True value: 1 || To lock the agent parameter in report
|-
|-
| STD || 2nd Description || String || 200 || Aluminium size to be display in sales tax invoice, eg. 38.10 x 1.80 thk
| DIY-F || Agent || String || 10 || Set an agent code to lock to this user
|-
|-
| STD || Base UOM || String || 10 || stock unit of measurement, usually either enter as PCS or KG or Roll
| DIY-F || Location_Lock || Boolean || False value: 0 <br /> True value: 1 || To lock the location parameter in report
|-
|-
| DIY || Linear Weight (Kg/M) || Float || Size :10 <br /> SubSize: 4 || Linear Weight (Kg/M) value
| DIY-F || Location || String || 10 || Set a location code to lock to this user
|}
|}
<br />
<br />


==Sales Documents Entry==
2. The above DIY fields are created at Tools | DIY | [[Maintain_DIY]]<br />
1. Sales documents entry are:-
<br />
::* Quotation
::* Sales Order
::* Delivery Order
::* Invoice
::* Debit Note
::* Credit Note


2. Insert and update the following DIY fields & Script into above mentions sales documents in Tools | DIY | SQL Control Center... <br />
==Reporting==
a) DIY Fields<br />
1. As long the report parameter has '''Project''', '''Agent''', '''Area''', or '''Location''', the reports able to lock based on user login. For instances:-
::{| class="wikitable"
::* Customer Aging (Agent, Area, Project)
|-
::* Sales/Purchase Document Listing (Agent, Area, Doc Project)
! Type !! Field Name !! Data Types !! Length
::* Outstanding Sales/Purchase Document Listing (Agent, Area, Doc Project, Item Project, Location)
|-
::* Stock Card (Location)
| DIY-F || Length || Float || Size: 10 <br />SubSize: 4
::* etc...
|-
<br />
| DIY-F || LinearWeight || Float || Size: 10 <br />SubSize: 4
2. Insert and update the following DIY Script into Script tab (Report name - Param Form) in Tools | DIY | [[Maintain DIY]] <br />
|-
 
| DIY-F || UnitPrice_Kg || Float || Size: 10 <br />SubSize: 4
For instance, apply the below script into Sales Profit & Loss By Document - Param Form.<br />
|-
::[[File:00-Maintain DIY-Script.jpg | 30PX]]
| DIY-F || UnitPrice_Pcs || Float || Size: 10 <br />SubSize: 4
|-
| DIY-F || Qty_Kg || Float || Size: 10 <br />SubSize: 4
|-
| DIY-F || Qty_Pcs || Float || Size: 10 <br />SubSize: 4
|}
<br />
<br />


b. DIY Script: '''OnGridColumnValueChange''' event<br />
  <syntaxhighlight lang="delphi">
  <syntaxhighlight lang="delphi">
  var
uses SysUtils, Dialogs, Forms, ComObj, DBClient;
    FComServer : Variant;
 
  var C, D : TWinControl;
    FComServer, lBizObj : Variant;
    lLock, lLock2 : Boolean;
    L, P : TStringList;
  function ComServer: Variant;
  function ComServer: Variant;
  begin
  begin
    if FComServer = Null then begin
  if FComServer = Null then begin
       FComServer := CreateOleObject('SQLAcc.BizApp');
       FComServer := CreateOleObject('SQLAcc.BizApp');
    end;
  end;
    Result := FComServer;
  Result := FComServer;
  end;
  end;
   
   
  var
procedure CheckLock;
    lSQL, lCode : String;
  var cdsTemp : TClientDataset;
    cdsTemp : TClientDataSet;
    lSQL : String;
    D : TDataSource;
begin
  lLock := False;
  lLock2 := False;
  FComServer := null;
  cdsTemp := TClientDataset.Create(nil);
  lSQL := Format('SELECT UDF_Location_Lock, UDF_Agent_Lock, UDF_Agent, UDF_Location FROM SY_USER WHERE Code=%s',[QuotedStr(UserID)]);
   
   
begin
  try
    FComServer  := null;
    cdsTemp.Data := ComServer.DBManager.Execute(lSQL);
    D := TDataSource(Self.FindComponent('dsDocDetail'));
    if cdsTemp.RecordCount > 0 then begin
                                                                                     
      lLock := cdsTemp.FindField('UDF_Location_Lock').Value = 1;
    cdsTemp := TClientDataSet.Create(nil);
      L.Text := cdsTemp.FindField('UDF_Location').AsString;
    lCode := D.DataSet.FindField('ItemCode').AsString;
      lLock2 := cdsTemp.FindField('UDF_Agent_Lock').Value = 1;
    lSQL := Format('SELECT UDF_LinearWeight FROM ST_ITEM WHERE Code=%s ',[QuotedStr(lCode)]);  
      P.Text := cdsTemp.FindField('UDF_Agent').AsString;
    cdsTemp.Data := ComServer.DBManager.Execute(lSQL);     
   
    //select item and batch to retrieve the linear weight from item master
    if SameText(editingfield,'ItemCode') or
    SameText(editingfield,'Batch') then begin
          D.DataSet.FindField('UDF_LinearWeight').Value := cdsTemp.FindField('UDF_LinearWeight').Value;  
          D.DataSet.FindField('UDF_Length').Value := 0;
     end;   
     end;   
                                           
    //select batch as "Length value"                                           
    if SameText(editingfield,'Batch') then begin
          D.DataSet.FindField('UDF_Length').Value := D.DataSet.FindField('Batch').Value;
    end; 
   
    //key-in unit price per kg to convert into unit price per pcs       
    if SameText(editingfield,'UDF_UnitPrice_Kg') or
    SameText(editingfield,'Batch') then begin
          D.DataSet.FindField('UDF_UnitPrice_Pcs').AsFloat := (D.DataSet.FindField('UDF_UnitPrice_Kg').AsFloat*
                                                              D.DataSet.FindField('UDF_Length').AsFloat*
                                                              D.DataSet.FindField('UDF_LinearWeight').AsFloat);
    end;
       
    //key-in unit price per pcs to convert into unit price per kg 
    if SameText(editingfield,'UDF_UnitPrice_Pcs') or
    SameText(editingfield,'Batch') then begin
          D.DataSet.FindField('UDF_UnitPrice_Kg').AsFloat := (D.DataSet.FindField('UDF_UnitPrice_Pcs').AsFloat/
                                                              D.DataSet.FindField('UDF_Length').AsFloat/
                                                              D.DataSet.FindField('UDF_LinearWeight').AsFloat);
    end; 
   
    //to compute the subtotal either based on unit price per pcs or per kg
    if (D.DataSet.FindField('UDF_Length').Value <> 0.0000) or
    (D.DataSet.FindField('UDF_LinearWeight').Value <> 0.000) or 
    (D.DataSet.FindField('UDF_Qty_Pcs').Value <> 0.0000) or
    (D.DataSet.FindField('UDF_UnitPrice_Pcs').Value <> 0.0000) then begin 
          D.DataSet.FindField('Qty').Value := D.DataSet.FindField('UDF_Qty_Pcs').AsFloat;
          D.DataSet.FindField('UnitPrice').Value := D.DataSet.FindField('UDF_UnitPrice_Pcs').AsFloat;
          D.DataSet.FindField('UDF_Qty_Kg').AsFloat := (D.DataSet.FindField('UDF_Length').AsFloat*
                                                        D.DataSet.FindField('UDF_LinearWeight').AsFloat*
                                                        D.DataSet.FindField('UDF_Qty_Pcs').AsFloat);
    end;   
   
   
  finally
    cdsTemp.Free;
    FComServer := null; 
    end;
end;
begin
   
   
    FComServer := null;
  C := Self.FindChildControl('edLocation_Panel') as TWinControl;
    cdsTemp.Free;     
  D := Self.FindChildControl('edAgent_Panel') as TWinControl;
   
  L := TStringList.Create;   
  P := TStringList.Create;                                   
 
  CheckLock;
  try
    if C <> nil then C.Enabled := not lLock;
      if lLock then begin
      C := TWinControl(C).FindChildControl('edLocation_Edit') as TWinControl;     
      (C as TControl).SetTextBuf(L.CommaText);      
    end; 
 
    if D <> nil then D.Enabled := not lLock2;
      if lLock2 then begin
      D := TWinControl(D).FindChildControl('edAgent_Edit') as TWinControl;     
      (D as TControl).SetTextBuf(P.CommaText);     
    end;
 
  finally
    L.Free;
    P.Free;
   end;             
  end.
  end.
  </syntaxhighlight>
  </syntaxhighlight>
<br />
<br />
'''Formula:''' <br />
1. Unit price per Pcs = Unit price per Kg x Length x Linear Weight
2. Unit price per Kg = Unit price per Pcs / Length / Linear Weight
3. Total Weight = Length x Linear Weight x No of Pcs
<br />
''Both formula results are rounding up to 4 decimals.''


==See also==
==See also==
* Others [[Customisation]]
* Others [[Customisation]]

Latest revision as of 02:06, 7 November 2015

Introduction

For some reason, the company managers wish to let users to check and view the report by themselves. They cannot access other users data, eg. agent A cannot see agent B sales value. Therefore, we have come out this script to lock at the report according to the user rights.

Updates

Last Customisation Update : 07 Nov 2015

Criterias

Maintain User

[Tools | Maintain User...]

1. Advanced Lock in Maintain User.

Types Field Name Data Types Length Usage
STD Code String 20 User ID, eg. LEE
STD Name String 100 User Name
DIY-F Agent_Lock Boolean False value: 0
True value: 1
To lock the agent parameter in report
DIY-F Agent String 10 Set an agent code to lock to this user
DIY-F Location_Lock Boolean False value: 0
True value: 1
To lock the location parameter in report
DIY-F Location String 10 Set a location code to lock to this user


2. The above DIY fields are created at Tools | DIY | Maintain_DIY

Reporting

1. As long the report parameter has Project, Agent, Area, or Location, the reports able to lock based on user login. For instances:-

  • Customer Aging (Agent, Area, Project)
  • Sales/Purchase Document Listing (Agent, Area, Doc Project)
  • Outstanding Sales/Purchase Document Listing (Agent, Area, Doc Project, Item Project, Location)
  • Stock Card (Location)
  • etc...


2. Insert and update the following DIY Script into Script tab (Report name - Param Form) in Tools | DIY | Maintain DIY

For instance, apply the below script into Sales Profit & Loss By Document - Param Form.

30PX


 uses SysUtils, Dialogs, Forms, ComObj, DBClient;
 
 var C, D : TWinControl;
     FComServer, lBizObj : Variant;
     lLock, lLock2 : Boolean;
     L, P : TStringList;
 
 function ComServer: Variant;
 begin
   if FComServer = Null then begin
      FComServer := CreateOleObject('SQLAcc.BizApp');
   end;
   Result := FComServer;
 end;
 
 procedure CheckLock;
 var cdsTemp : TClientDataset;
     lSQL : String;
 begin
   lLock := False; 
   lLock2 := False;
   FComServer := null;
   cdsTemp := TClientDataset.Create(nil);
   lSQL := Format('SELECT UDF_Location_Lock, UDF_Agent_Lock, UDF_Agent, UDF_Location FROM SY_USER WHERE Code=%s',[QuotedStr(UserID)]);
 
   try
     cdsTemp.Data := ComServer.DBManager.Execute(lSQL);
     if cdsTemp.RecordCount > 0 then begin
       lLock := cdsTemp.FindField('UDF_Location_Lock').Value = 1;
       L.Text := cdsTemp.FindField('UDF_Location').AsString;
       lLock2 := cdsTemp.FindField('UDF_Agent_Lock').Value = 1;
       P.Text := cdsTemp.FindField('UDF_Agent').AsString;
    end;  
 
   finally 
     cdsTemp.Free;
     FComServer := null;   
     end;
 end;
 
 begin
 
   C := Self.FindChildControl('edLocation_Panel') as TWinControl;
   D := Self.FindChildControl('edAgent_Panel') as TWinControl;
   L := TStringList.Create;    
   P := TStringList.Create;                                    
   
   CheckLock;
   try
     if C <> nil then C.Enabled := not lLock;
       if lLock then begin
       C := TWinControl(C).FindChildControl('edLocation_Edit') as TWinControl;      
       (C as TControl).SetTextBuf(L.CommaText);       
     end;   

     if D <> nil then D.Enabled := not lLock2;
       if lLock2 then begin
       D := TWinControl(D).FindChildControl('edAgent_Edit') as TWinControl;      
       (D as TControl).SetTextBuf(P.CommaText);       
     end; 
   
   finally 
     L.Free;
     P.Free; 
   end;              
 end.


See also