VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form IT_Expend_mtnc 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Expenditive follow up"
   ClientHeight    =   8625
   ClientLeft      =   1005
   ClientTop       =   330
   ClientWidth     =   9390
   ClipControls    =   0   'False
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   8625
   ScaleWidth      =   9390
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton ssp_save 
      Height          =   615
      Left            =   7980
      Style           =   1  'Graphical
      TabIndex        =   21
      Top             =   7935
      Width           =   615
   End
   Begin VB.CommandButton ssp_quit 
      Height          =   615
      Left            =   8700
      Style           =   1  'Graphical
      TabIndex        =   22
      Top             =   7935
      Width           =   615
   End
   Begin VB.TextBox Txt_Spare4 
      Height          =   285
      Left            =   6480
      TabIndex        =   28
      Text            =   "Txt_Spare4"
      Top             =   8040
      Visible         =   0   'False
      Width           =   1215
   End
   Begin VB.TextBox Txt_Spare3 
      Height          =   285
      Left            =   5160
      TabIndex        =   27
      Text            =   "Txt_Spare3"
      Top             =   8040
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.TextBox Txt_Spare2 
      Height          =   285
      Left            =   3960
      TabIndex        =   26
      Text            =   "Txt_Spare2"
      Top             =   8040
      Visible         =   0   'False
      Width           =   1215
   End
   Begin VB.TextBox Txt_Spare1 
      Height          =   285
      Left            =   2640
      TabIndex        =   25
      Text            =   "Txt_Spare1"
      Top             =   8040
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.Frame frm_amount 
      Caption         =   "Invoice Amount"
      Height          =   1755
      Left            =   120
      TabIndex        =   38
      Top             =   6120
      Width           =   9255
      Begin VB.ComboBox cbo_I_Currency 
         Height          =   315
         Left            =   3540
         Style           =   2  'Dropdown List
         TabIndex        =   19
         Top             =   600
         Width           =   795
      End
      Begin Project1.CDate txt_I_Date 
         Height          =   315
         Left            =   6660
         TabIndex        =   17
         Tag             =   "10"
         Top             =   240
         Visible         =   0   'False
         Width           =   2415
         _ExtentX        =   3625
         _ExtentY        =   556
      End
      Begin VB.TextBox txt_I_USD_Rate 
         Height          =   315
         Left            =   6660
         Locked          =   -1  'True
         TabIndex        =   53
         TabStop         =   0   'False
         Text            =   "txt_I_USD_Rate"
         Top             =   1320
         Width           =   2415
      End
      Begin VB.TextBox txt_I_comp_Rate 
         Height          =   315
         Left            =   6660
         Locked          =   -1  'True
         TabIndex        =   51
         TabStop         =   0   'False
         Text            =   "txt_I_comp_Rate"
         Top             =   960
         Width           =   2415
      End
      Begin VB.TextBox txt_I_Amount_USD 
         Height          =   315
         Left            =   1920
         Locked          =   -1  'True
         TabIndex        =   46
         TabStop         =   0   'False
         Text            =   "txt_I_Amount_USD"
         Top             =   1320
         Width           =   1935
      End
      Begin VB.TextBox txt_I_Amount_comp 
         Height          =   315
         Left            =   1920
         Locked          =   -1  'True
         TabIndex        =   43
         TabStop         =   0   'False
         Text            =   "txt_I_Amount_comp"
         Top             =   960
         Width           =   1935
      End
      Begin VB.TextBox txt_Invoice_Amount 
         Height          =   315
         Left            =   1920
         TabIndex        =   18
         Text            =   "txt_Invoice_Amount"
         Top             =   600
         Width           =   1575
      End
      Begin VB.TextBox txt_Invoice_nb 
         Height          =   315
         Left            =   1920
         TabIndex        =   16
         Text            =   "txt_Invoice_nb"
         Top             =   240
         Width           =   2415
      End
      Begin VB.TextBox txt_Account_Ref 
         Height          =   315
         Left            =   6660
         TabIndex        =   20
         Text            =   "txt_Account_Ref"
         Top             =   600
         Width           =   2415
      End
      Begin VB.Label lbl_I_USD_Rate 
         Caption         =   "lbl_I_USD_Rate"
         Height          =   195
         Left            =   4860
         TabIndex        =   54
         Top             =   1380
         Width           =   1815
         WordWrap        =   -1  'True
      End
      Begin VB.Label lbl_I_Comp_Rate 
         Caption         =   "lbl_I_Comp_Rate"
         Height          =   195
         Left            =   4860
         TabIndex        =   52
         Top             =   1020
         Width           =   1815
         WordWrap        =   -1  'True
      End
      Begin VB.Label lbl_I_Amount_USD 
         Caption         =   "lbl_I_Amount_USD"
         Height          =   195
         Left            =   120
         TabIndex        =   48
         Top             =   1380
         Width           =   1335
      End
      Begin VB.Label lbl_I_USD_Currency 
         Caption         =   "$"
         Height          =   195
         Left            =   3960
         TabIndex        =   47
         Top             =   1380
         Width           =   375
      End
      Begin VB.Label lbl_I_Amount_comp 
         Caption         =   "lbl_I_Amount_comp"
         Height          =   195
         Left            =   120
         TabIndex        =   45
         Top             =   1020
         Width           =   1815
      End
      Begin VB.Label lbl_I_Comp_Currency 
         Height          =   195
         Left            =   3960
         TabIndex        =   44
         Top             =   1020
         Width           =   375
      End
      Begin VB.Label lbl_Invoice_Amount 
         Caption         =   "lbl_Invoice_Amount"
         Height          =   195
         Left            =   120
         TabIndex        =   42
         Top             =   660
         Width           =   1815
      End
      Begin VB.Label lbl_Invoice_nb 
         Caption         =   "lbl_Invoice_nb"
         Height          =   195
         Left            =   120
         TabIndex        =   41
         Top             =   300
         Width           =   1815
      End
      Begin VB.Label Lbl_I_Date 
         Caption         =   "Lbl_I_Date"
         Height          =   195
         Left            =   4860
         TabIndex        =   40
         Top             =   300
         Width           =   1815
      End
      Begin VB.Label lbl_Account_Ref 
         Caption         =   "lbl_Account_Ref"
         Height          =   195
         Left            =   4860
         TabIndex        =   39
         Top             =   660
         Width           =   1815
      End
   End
   Begin VB.Frame frm_approval 
      Caption         =   "Approval"
      Height          =   1350
      Left            =   120
      TabIndex        =   36
      Top             =   4740
      Width           =   9255
      Begin VB.OptionButton Opt_AppRef 
         Caption         =   "opt_OnHold"
         Height          =   255
         Index           =   2
         Left            =   2940
         TabIndex        =   71
         Top             =   240
         Width           =   1395
      End
      Begin Project1.CDate txt_Approval_date 
         Height          =   315
         Left            =   1920
         TabIndex        =   14
         Top             =   900
         Width           =   2415
         _ExtentX        =   4260
         _ExtentY        =   556
      End
      Begin VB.TextBox Txt_Detail3 
         Height          =   795
         Left            =   4800
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   15
         Text            =   "IT_MTNC.frx":0000
         Top             =   420
         Width           =   4335
      End
      Begin VB.OptionButton Opt_AppRef 
         Caption         =   "opt_Refused"
         Height          =   255
         Index           =   1
         Left            =   1560
         TabIndex        =   12
         Top             =   240
         Width           =   1575
      End
      Begin VB.OptionButton Opt_AppRef 
         Caption         =   "opt_Approved"
         Height          =   255
         Index           =   0
         Left            =   120
         TabIndex        =   11
         Top             =   240
         Width           =   1395
      End
      Begin MSForms.ComboBox cbo_Approved_by 
         Height          =   315
         Left            =   1920
         TabIndex        =   13
         Top             =   540
         Width           =   2415
         VariousPropertyBits=   679479323
         DisplayStyle    =   7
         Size            =   "4260;556"
         MatchEntry      =   0
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin VB.Label lbl_Detail3 
         Caption         =   "lbl_Detail3"
         Height          =   255
         Left            =   4800
         TabIndex        =   67
         Top             =   180
         Width           =   2535
      End
      Begin VB.Label Lbl_Approval_date 
         Caption         =   "lbl_approval_Date"
         Height          =   255
         Left            =   120
         TabIndex        =   50
         Top             =   960
         Width           =   1815
         WordWrap        =   -1  'True
      End
      Begin VB.Label lbl_Approved_by 
         Caption         =   "lbl_Approved_by"
         Height          =   195
         Left            =   120
         TabIndex        =   37
         Top             =   600
         Width           =   1815
      End
   End
   Begin VB.Frame frm_general 
      Caption         =   "General information"
      Height          =   4695
      Left            =   120
      TabIndex        =   29
      Top             =   0
      Width           =   9255
      Begin VB.TextBox Txt_Cat 
         Enabled         =   0   'False
         Height          =   315
         Left            =   6660
         TabIndex        =   70
         Text            =   "Txt_Cat"
         Top             =   540
         Width           =   2415
      End
      Begin MSComctlLib.ImageCombo Cbo_SubCat 
         Height          =   330
         Left            =   6660
         TabIndex        =   3
         Top             =   900
         Width           =   2415
         _ExtentX        =   4260
         _ExtentY        =   582
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         Locked          =   -1  'True
         Text            =   "Cbo_SubCat"
      End
      Begin VB.CheckBox Chk_Confidential 
         Height          =   315
         Left            =   6660
         TabIndex        =   0
         Top             =   180
         Visible         =   0   'False
         Width           =   255
      End
      Begin VB.TextBox txt_Detail 
         Height          =   1575
         Left            =   120
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   9
         Text            =   "IT_MTNC.frx":000E
         Top             =   3000
         Width           =   4220
      End
      Begin Project1.CDate txt_O_Date 
         Height          =   315
         Left            =   6660
         TabIndex        =   8
         Top             =   1620
         Width           =   2415
         _ExtentX        =   4260
         _ExtentY        =   556
      End
      Begin VB.OptionButton opt_CapExp 
         Caption         =   "opt_Capital"
         Height          =   192
         Index           =   0
         Left            =   120
         TabIndex        =   23
         Top             =   240
         Width           =   1632
      End
      Begin VB.OptionButton opt_CapExp 
         Caption         =   "opt_Expenses"
         Height          =   192
         Index           =   1
         Left            =   1920
         TabIndex        =   24
         Top             =   240
         Width           =   1932
      End
      Begin VB.ComboBox cbo_O_Currency 
         Height          =   315
         Left            =   3540
         Style           =   2  'Dropdown List
         TabIndex        =   7
         Top             =   1620
         Width           =   795
      End
      Begin VB.TextBox txt_O_Amount 
         Height          =   315
         Left            =   1920
         TabIndex        =   6
         Text            =   "txt_O_Amount"
         Top             =   1620
         Width           =   1575
      End
      Begin VB.TextBox Txt_O_Amount_Comp 
         Height          =   315
         Left            =   1920
         Locked          =   -1  'True
         TabIndex        =   58
         TabStop         =   0   'False
         Text            =   "txt_O_Amount_comp"
         Top             =   1980
         Width           =   1935
      End
      Begin VB.TextBox Txt_O_Amount_USD 
         Height          =   315
         Left            =   1920
         Locked          =   -1  'True
         TabIndex        =   57
         TabStop         =   0   'False
         Text            =   "txt_O_Amount_USD"
         Top             =   2340
         Width           =   1935
      End
      Begin VB.TextBox txt_O_Comp_Rate 
         Height          =   315
         Left            =   6660
         Locked          =   -1  'True
         TabIndex        =   56
         TabStop         =   0   'False
         Text            =   "txt_O_Comp_Rate"
         Top             =   1980
         Width           =   2415
      End
      Begin VB.TextBox txt_O_USD_Rate 
         Height          =   315
         Left            =   6660
         Locked          =   -1  'True
         TabIndex        =   55
         TabStop         =   0   'False
         Text            =   "txt_O_USD_Rate"
         Top             =   2340
         Width           =   2415
      End
      Begin VB.TextBox Txt_Detail2 
         Height          =   1575
         Left            =   4860
         MultiLine       =   -1  'True
         ScrollBars      =   2  'Vertical
         TabIndex        =   10
         Text            =   "IT_MTNC.frx":0019
         Top             =   3000
         Width           =   4220
      End
      Begin VB.TextBox txt_Order_nb 
         Height          =   315
         Left            =   1920
         TabIndex        =   4
         Text            =   "txt_Order_nb"
         Top             =   1260
         Width           =   2415
      End
      Begin VB.Label Lbl_Cat 
         Caption         =   "lbl_Cat"
         Enabled         =   0   'False
         Height          =   195
         Left            =   4860
         TabIndex        =   69
         Top             =   600
         Width           =   1815
      End
      Begin VB.Label Lbl_SubCat 
         Caption         =   "lbl_SubCat"
         Height          =   195
         Left            =   4860
         TabIndex        =   66
         Top             =   960
         Width           =   1815
      End
      Begin VB.Label lbl_Confidential 
         Caption         =   "lbl_Confidential"
         Height          =   255
         Left            =   4860
         TabIndex        =   68
         Top             =   240
         Visible         =   0   'False
         Width           =   1815
      End
      Begin MSForms.ComboBox cbo_Order_by 
         Height          =   315
         Left            =   6660
         TabIndex        =   5
         Top             =   1260
         Width           =   2415
         VariousPropertyBits=   679479323
         DisplayStyle    =   7
         Size            =   "4260;556"
         MatchEntry      =   0
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin MSForms.ComboBox cbo_Project 
         Height          =   315
         Left            =   1920
         TabIndex        =   2
         Top             =   900
         Width           =   2415
         VariousPropertyBits=   679479323
         DisplayStyle    =   7
         Size            =   "4260;556"
         MatchEntry      =   0
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin MSForms.ComboBox cbo_Location 
         Height          =   315
         Left            =   1920
         TabIndex        =   1
         Top             =   540
         Width           =   2415
         VariousPropertyBits=   679479323
         DisplayStyle    =   7
         Size            =   "4260;556"
         ColumnCount     =   5
         cColumnInfo     =   5
         MatchEntry      =   0
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
         Object.Width           =   "-1;0;0;0;0"
      End
      Begin VB.Label Lbl_O_Comp_Currency 
         Height          =   195
         Left            =   3960
         TabIndex        =   65
         Top             =   2040
         Width           =   375
      End
      Begin VB.Label Lbl_O_USD_Rate 
         Caption         =   "Lbl_O_USD_Rate"
         Height          =   195
         Left            =   4860
         TabIndex        =   59
         Top             =   2400
         Width           =   1815
         WordWrap        =   -1  'True
      End
      Begin VB.Label Lbl_O_Amount 
         Caption         =   "lbl_O_Amount"
         Height          =   195
         Left            =   120
         TabIndex        =   64
         Top             =   1680
         Width           =   1815
      End
      Begin VB.Label Lbl_O_Amount_Comp 
         Caption         =   "lbl_O_Amount_comp"
         Height          =   195
         Left            =   120
         TabIndex        =   63
         Top             =   2040
         Width           =   1815
      End
      Begin VB.Label Lbl_O_USD_Currency 
         Caption         =   "$"
         Height          =   195
         Left            =   3960
         TabIndex        =   62
         Top             =   2400
         Width           =   375
      End
      Begin VB.Label Lbl_O_Amount_USD 
         Caption         =   "lbl_O_Amount_USD"
         Height          =   195
         Left            =   120
         TabIndex        =   61
         Top             =   2400
         Width           =   1815
      End
      Begin VB.Label Lbl_O_Comp_Rate 
         Caption         =   "Lbl_O_Comp_Rate"
         Height          =   195
         Left            =   4860
         TabIndex        =   60
         Top             =   2040
         Width           =   1815
         WordWrap        =   -1  'True
      End
      Begin VB.Label lbl_Detail2 
         Caption         =   "lbl_Detail2"
         Height          =   195
         Left            =   4860
         TabIndex        =   49
         Top             =   2760
         Width           =   4215
      End
      Begin VB.Label lbl_Location 
         Caption         =   "lbl_Location"
         Height          =   195
         Left            =   120
         TabIndex        =   35
         Top             =   600
         Width           =   1815
      End
      Begin VB.Label lbl_Order_nb 
         Caption         =   "lbl_Order_nb"
         Height          =   195
         Left            =   120
         TabIndex        =   34
         Top             =   1320
         Width           =   1815
      End
      Begin VB.Label lbl_Order_by 
         Caption         =   "lbl_Order_by"
         Height          =   195
         Left            =   4860
         TabIndex        =   33
         Top             =   1320
         Width           =   1815
      End
      Begin VB.Label lbl_Project 
         Caption         =   "lbl_Project"
         Height          =   195
         Left            =   120
         TabIndex        =   32
         Top             =   960
         Width           =   1815
      End
      Begin VB.Label lbl_Detail 
         Caption         =   "lbl_Detail"
         Height          =   195
         Left            =   120
         TabIndex        =   31
         Top             =   2760
         Width           =   4215
      End
      Begin VB.Label lbl_O_Date 
         Caption         =   "lbl_O_Date"
         Height          =   195
         Left            =   4860
         TabIndex        =   30
         Top             =   1680
         Width           =   1815
      End
   End
End
Attribute VB_Name = "IT_Expend_mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim mi_iConc As Integer
Dim ms_lbl_order_nb As String
Dim ms_lbl_order_amount As String
Dim ms_lbl_order_date As String
Dim ms_lbl_contract_nb As String
Dim ms_lbl_contract_amount As String
Dim ms_lbl_expense_date As String
Dim ms_txt_detail2 As String

Private Sub Set_Description()
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim li_Count As Integer
Dim ls_project_code As String
Dim ls_App_Ref As String
Dim ls_App_Ref_By As String
Dim ls_I_Currency As String

    On Error GoTo Set_Description_Err
    
    ls_Req = "EXEC IT_Expenditure_dtl " & gs_TableCode
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            If ODBCData(ll_Statement, 1) = "Y" Then
                Chk_Confidential.value = 1
            Else
                Chk_Confidential.value = 0
            End If
            If ODBCData(ll_Statement, 2) = "Capital" Then
                opt_CapExp(0).value = 1
            Else
                opt_CapExp(1).value = 1
            End If
            'Location Code and Desc
            MCombo_AddItemCode cbo_Location, ODBCData(ll_Statement, 3), ODBCData(ll_Statement, 4), OK
            'Location Currency
            cbo_Location.Column(2) = ODBCData(ll_Statement, 5)
            Lbl_O_Comp_Currency.Caption = cbo_Location.Column(2)
            lbl_I_Comp_Currency.Caption = cbo_Location.Column(2)
            'Location Confidential
            cbo_Location.Column(3) = ODBCData(ll_Statement, 6)
            If cbo_Location.Column(3) = "Y" Then
                lbl_Confidential.Visible = OK
                Chk_Confidential.Visible = OK
            End If
            'Location Approbator
            cbo_Location.Column(4) = ODBCData(ll_Statement, 7)
            Txt_Cat.Text = ODBCData(ll_Statement, 8)
            Cbo_SubCat.ComboItems.Add , "K" & ODBCData(ll_Statement, 9), ODBCData(ll_Statement, 10)
            Cbo_SubCat.ComboItems.Item(1).Tag = ODBCData(ll_Statement, 11) & ODBCData(ll_Statement, 12) & Txt_Cat.Text
            Cbo_SubCat.ComboItems.Item(1).Selected = OK
            If Mid(Cbo_SubCat.SelectedItem.Tag, 1, 1) = "Y" Then
                lbl_Order_nb.Caption = ms_lbl_contract_nb
                Lbl_O_Amount.Caption = ms_lbl_contract_amount
                lbl_O_Date.Caption = ms_lbl_expense_date
                Txt_Detail2.Text = ms_txt_detail2
            End If
            ls_project_code = ODBCData(ll_Statement, 13)
            If ls_project_code <> "" Then
                MCombo_AddItemCode cbo_Project, ls_project_code, ODBCData(ll_Statement, 14), OK
            End If
            txt_Order_nb.Text = ODBCData(ll_Statement, 15)
            MCombo_AddItemCode cbo_Order_by, ODBCData(ll_Statement, 16), ODBCData(ll_Statement, 17), OK
            txt_O_Date.SetDate = ODBCData(ll_Statement, 18)
            txt_O_Amount.Text = Formatage(ODBCData(ll_Statement, 19), 2)
            cbo_O_Currency.AddItem ODBCData(ll_Statement, 20)
            cbo_O_Currency.ListIndex = 0
            Txt_O_Amount_Comp.Text = Formatage(ODBCData(ll_Statement, 21), 2)
            Txt_O_Amount_USD.Text = Formatage(ODBCData(ll_Statement, 22), 2)
            If Val(Formatage2(txt_O_Amount.Text)) <> 0 Then
                txt_O_Comp_Rate.Text = Formatage(Formatage2(Round(Val(Formatage2(Txt_O_Amount_Comp)) / Val(Formatage2(txt_O_Amount)), 5)), 5)
                txt_O_USD_Rate.Text = Formatage(Formatage2(Round(Val(Formatage2(Txt_O_Amount_USD)) / Val(Formatage2(txt_O_Amount)), 5)), 5)
            Else
                txt_O_Comp_Rate.Text = "0.00000"
                txt_O_USD_Rate.Text = "0.00000"
            End If
            txt_Detail.Text = ODBCMemoGet(ll_Statement, 23)
            Txt_Detail2.Text = ODBCMemoGet(ll_Statement, 24)
            ls_App_Ref = ODBCData(ll_Statement, 25)
            Select Case ls_App_Ref
                Case "Approved": Opt_AppRef(0).value = OK
                Case "Refused": Opt_AppRef(1).value = OK
                Case "OnHold": Opt_AppRef(2).value = OK
            End Select
            ls_App_Ref_By = ODBCData(ll_Statement, 26)
            If ls_App_Ref_By <> "" Then
                MCombo_AddItemCode cbo_Approved_by, ls_App_Ref_By, ODBCData(ll_Statement, 27), OK
            End If
            txt_Approval_date.SetDate = ODBCData(ll_Statement, 28)
            Txt_Detail3.Text = ODBCMemoGet(ll_Statement, 29)
            txt_Invoice_nb.Text = ODBCData(ll_Statement, 30)
            txt_I_Date.SetDate = ODBCData(ll_Statement, 31)
            txt_Account_Ref.Text = ODBCData(ll_Statement, 32)
            txt_Invoice_Amount.Text = Formatage(ODBCData(ll_Statement, 33), 2)
            ls_I_Currency = ODBCData(ll_Statement, 34)
            If ls_I_Currency <> "" Then
                cbo_I_Currency.AddItem ls_I_Currency
                cbo_I_Currency.ListIndex = 0
            End If
            txt_I_Amount_comp.Text = Formatage(ODBCData(ll_Statement, 35), 2)
            txt_I_Amount_USD.Text = Formatage(ODBCData(ll_Statement, 36), 2)
            txt_spare1.Text = ODBCData(ll_Statement, 37)
            txt_spare2.Text = ODBCData(ll_Statement, 38)
            txt_spare3.Text = ODBCData(ll_Statement, 39)
            txt_spare4.Text = ODBCData(ll_Statement, 40)
            
        End If
    End If
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)

Exit Sub

Set_Description_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Function Control() As Boolean
    
    Control = KO
    
    If opt_CapExp(0).value = KO And opt_CapExp(1).value = KO Then
        SendMessage 137, "You must choose Capital or Expenses.", gut_LangLogin.Code
        Exit Function
    End If
    If cbo_Location.Text = "" Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        cbo_Location.SetFocus
        Exit Function
    End If
    If Cbo_SubCat.Text = "" Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        Cbo_SubCat.SetFocus
        Exit Function
    End If
    If txt_Order_nb.Text = "" Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        txt_Order_nb.SetFocus
        Exit Function
    End If
    If cbo_Order_by.Text = "" Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        cbo_Order_by.SetFocus
        Exit Function
    End If
    If txt_O_Amount.Text = "" Or Val(Formatage2(txt_O_Amount.Text)) = 0 Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        txt_O_Amount.SetFocus
        Exit Function
    End If
    If cbo_O_Currency = "" Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        cbo_O_Currency.SetFocus
        Exit Function
    End If
    If txt_O_Date.GetUSDate = "" Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        txt_O_Date.SetFocus
        Exit Function
    End If
    If txt_Detail.Text = "" Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        txt_Detail.SetFocus
        Exit Function
    End If
    If Not CheckNumericValue(Formatage2(txt_O_Amount.Text)) Then
        SendMessage 8, "Value must be a numeric", gut_LangLogin.Code
        txt_O_Amount.SetFocus
        Exit Function
    End If
    
    If gs_Action = "Update" And (Opt_AppRef(0).value = OK Or Opt_AppRef(1).value = OK Or Opt_AppRef(2).value = OK Or cbo_Approved_by.Text <> "" Or txt_Approval_date.GetUSDate <> "" Or Txt_Detail3.Text <> "") Then
        If Opt_AppRef(0).value = KO And Opt_AppRef(1).value = KO And Opt_AppRef(2).value = KO Then
            SendMessage 139, "You must choose Approved, Refused or OnHold.", gut_LangLogin.Code
            Opt_AppRef(0).SetFocus
            Exit Function
        End If
        If cbo_Approved_by.Text = "" Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            cbo_Approved_by.SetFocus
            Exit Function
        End If
        If txt_Approval_date.GetUSDate = "" Then
            SendMessage 8, "Value must be filled in", gut_LangLogin.Code
            txt_Approval_date.SetFocus
            Exit Function
        End If
    End If
    
    Control = OK

End Function

Private Function Add_Table() As Boolean
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim ls_CapExp As String

    On Error GoTo Add_Table_Err
    
    Add_Table = KO
    
    If opt_CapExp(0).value = OK Then
        ls_CapExp = "Capital"
    Else
        ls_CapExp = "Expenses"
    End If
    
    ls_Req = gs_ParamReqIns
    If Chk_Confidential.value = 0 Then
        ls_Req = ls_Req & " 'N'"
    Else
        ls_Req = ls_Req & " 'Y'"
    End If
    ls_Req = ls_Req & ",'" & ls_CapExp & "'"
    ls_Req = ls_Req & "," & MCombo_GetCode(cbo_Location)
    ls_Req = ls_Req & "," & Mid(Cbo_SubCat.SelectedItem.Key, 2)
    If cbo_Project.ListIndex = -1 Or cbo_Project.Text = "" Then
        ls_Req = ls_Req & ",NULL"
    Else
        ls_Req = ls_Req & "," & MCombo_GetCode(cbo_Project)
    End If
    ls_Req = ls_Req & ",'" & QuoteParam(txt_Order_nb.Text) & "'"
    ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_Order_by) & "'"
    ls_Req = ls_Req & ",'" & txt_O_Date.GetUSDate & "'"
    ls_Req = ls_Req & "," & Formatage2(txt_O_Amount.Text)
    ls_Req = ls_Req & ",'" & cbo_O_Currency.Text & "'"
    ls_Req = ls_Req & "," & Formatage2(Txt_O_Amount_Comp.Text)
    ls_Req = ls_Req & "," & Formatage2(Txt_O_Amount_USD.Text)
    If txt_Detail.Text = "" Then
        ls_Req = ls_Req & ",NULL"
    Else
        ls_Req = ls_Req & ",'" & QuoteParam(txt_Detail.Text) & "'"
    End If
    If Txt_Detail2.Text = "" Then
        ls_Req = ls_Req & ",NULL"
    Else
        ls_Req = ls_Req & ",'" & QuoteParam(Txt_Detail2.Text) & "'"
    End If
    If Mid(Cbo_SubCat.SelectedItem.Tag, 2, 1) = "Y" Then
        ls_Req = ls_Req & ",'Approved'"
        ls_Req = ls_Req & ",'Automatic'"
        txt_Approval_date.SetToday
        ls_Req = ls_Req & ",'" & txt_Approval_date.GetUSDate & "'"
        ls_Req = ls_Req & ",'This sub-category is automatically approved'"
    Else
        ls_Req = ls_Req & ",NULL" 'App_Ref
        ls_Req = ls_Req & ",NULL" 'App_Ref_By
        ls_Req = ls_Req & ",NULL" 'App_Ref_Date
        ls_Req = ls_Req & ",NULL" 'App_Ref_Detail
    End If
    ls_Req = ls_Req & ",NULL" 'Invoice_nb
    ls_Req = ls_Req & ",NULL" 'Payment_date
    ls_Req = ls_Req & ",NULL" 'Account_ref
    ls_Req = ls_Req & ",NULL" 'Invoice_Amount
    ls_Req = ls_Req & ",NULL" 'Invoice_Cur
    ls_Req = ls_Req & ",NULL" 'Invoice_Comp_Cur
    ls_Req = ls_Req & ",NULL" 'Invoice_Comp_USD
    ls_Req = ls_Req & ",NULL" 'S_Spare1
    ls_Req = ls_Req & ",NULL" 'S_Spare2
    ls_Req = ls_Req & ",NULL" 'R_Spare1
    ls_Req = ls_Req & ",NULL" 'R_Spare2

    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQLRowCount(ll_Statement, ll_lngrows)
        If ll_lngrows = 0 Then
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            SendMessage 4, "Insert failed", gut_LangLogin.Code
            'C_main.FillGrid
        Else
            Add_Table = OK
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 4, "Insert failed", gut_LangLogin.Code
    End If
    Exit Function

Add_Table_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Function


Private Sub cbo_Approved_by_Click()
    txt_Approval_date.SetToday
End Sub

Private Sub cbo_Approved_by_DropButtonClick()
Dim lv_Code As Variant

    If cbo_Approved_by.Tag = UNLOADED Then
        MouseOff
        lv_Code = MCombo_GetCode(cbo_Approved_by)
        cbo_Approved_by.Clear
        MCombo_Fill cbo_Approved_by, "EXEC IT_Approved_by_cbo"
        MCombo_CodeSelect(cbo_Approved_by) = lv_Code
        cbo_Approved_by.Tag = Loaded
        MouseOn
    End If
    
End Sub

Private Sub cbo_O_Currency_Click()
    MouseOff
    Rates_Calculate
    MouseOn
End Sub

Private Sub Cbo_SubCat_Click()
    
    Txt_Cat.Text = ""
    On Error Resume Next
    Txt_Cat.Text = Mid(Cbo_SubCat.SelectedItem.Tag, 3)
    If Txt_Cat.Text = "" Then
        lbl_Order_nb.Caption = ms_lbl_order_nb
        Lbl_O_Amount.Caption = ms_lbl_order_amount
        lbl_O_Date.Caption = ms_lbl_order_date
        Txt_Detail2.Text = ""
        lbl_Order_nb.Enabled = KO
        txt_Order_nb.Enabled = KO
        lbl_Order_by.Enabled = KO
        cbo_Order_by.Enabled = KO
        Lbl_O_Amount.Enabled = KO
        txt_O_Amount.Enabled = KO
        cbo_O_Currency.Enabled = KO
        lbl_O_Date.Enabled = KO
        txt_O_Date.Enabled = KO
        Lbl_O_Amount_Comp.Enabled = KO
        Txt_O_Amount_Comp.Enabled = KO
        Lbl_O_Comp_Currency.Enabled = KO
        Lbl_O_Comp_Rate.Enabled = KO
        txt_O_Comp_Rate.Enabled = KO
        Lbl_O_Amount_USD.Enabled = KO
        Txt_O_Amount_USD.Enabled = KO
        Lbl_O_USD_Currency.Enabled = KO
        Lbl_O_USD_Rate.Enabled = KO
        txt_O_USD_Rate.Enabled = KO
        lbl_Detail.Enabled = KO
        txt_Detail.Locked = OK
        lbl_Detail2.Enabled = KO
        Txt_Detail2.Locked = OK
        MsgBox "you must select a sub-category"
    Else
        If Mid(Cbo_SubCat.SelectedItem.Tag, 1, 1) = "Y" Then
            lbl_Order_nb.Caption = ms_lbl_contract_nb
            Lbl_O_Amount.Caption = ms_lbl_contract_amount
            lbl_O_Date.Caption = ms_lbl_expense_date
            Txt_Detail2.Text = ms_txt_detail2
        Else
            lbl_Order_nb.Caption = ms_lbl_order_nb
            Lbl_O_Amount.Caption = ms_lbl_order_amount
            lbl_O_Date.Caption = ms_lbl_order_date
            Txt_Detail2.Text = ""
        End If
        If gs_Action = "Update" Then
            If cbo_Location.Column(4) = "Y" And Mid(Cbo_SubCat.SelectedItem.Tag, 2, 1) = "N" Then
                Opt_AppRef(0).Enabled = OK
                Opt_AppRef(1).Enabled = OK
                Opt_AppRef(2).Enabled = OK
                lbl_Approved_by.Enabled = OK
                cbo_Approved_by.Enabled = OK
                Lbl_Approval_date.Enabled = OK
                txt_Approval_date.Enabled = OK
                lbl_Detail3.Enabled = OK
                Txt_Detail3.Locked = KO
                Opt_AppRef(0).value = KO
                Opt_AppRef(1).value = KO
                Opt_AppRef(2).value = KO
                cbo_Approved_by.Clear
                cbo_Approved_by.Tag = UNLOADED
                txt_Approval_date.Reinit
                Txt_Detail3.Text = ""
            Else
                Opt_AppRef(0).Enabled = KO
                Opt_AppRef(1).Enabled = KO
                Opt_AppRef(2).Enabled = KO
                lbl_Approved_by.Enabled = KO
                cbo_Approved_by.Enabled = KO
                Lbl_Approval_date.Enabled = KO
                txt_Approval_date.Enabled = KO
                lbl_Detail3.Enabled = KO
                Txt_Detail3.Locked = OK
            End If
        Else
            Opt_AppRef(0).Enabled = KO
            Opt_AppRef(1).Enabled = KO
            Opt_AppRef(2).Enabled = KO
            lbl_Approved_by.Enabled = KO
            cbo_Approved_by.Enabled = KO
            Lbl_Approval_date.Enabled = KO
            txt_Approval_date.Enabled = KO
            lbl_Detail3.Enabled = KO
            Txt_Detail3.Locked = OK
        End If
        lbl_Order_nb.Enabled = OK
        txt_Order_nb.Enabled = OK
        lbl_Order_by.Enabled = OK
        cbo_Order_by.Enabled = OK
        Lbl_O_Amount.Enabled = OK
        txt_O_Amount.Enabled = OK
        cbo_O_Currency.Enabled = OK
        lbl_O_Date.Enabled = OK
        txt_O_Date.Enabled = OK
        Lbl_O_Amount_Comp.Enabled = OK
        Txt_O_Amount_Comp.Enabled = OK
        Lbl_O_Comp_Currency.Enabled = OK
        Lbl_O_Comp_Rate.Enabled = OK
        txt_O_Comp_Rate.Enabled = OK
        Lbl_O_Amount_USD.Enabled = OK
        Txt_O_Amount_USD.Enabled = OK
        Lbl_O_USD_Currency.Enabled = OK
        Lbl_O_USD_Rate.Enabled = OK
        txt_O_USD_Rate.Enabled = OK
        lbl_Detail.Enabled = OK
        txt_Detail.Locked = KO
        lbl_Detail2.Enabled = OK
        Txt_Detail2.Locked = KO
    End If
    
End Sub

Private Sub Cbo_SubCat_Dropdown()
Dim ls_Req As String
Dim li_Status As Integer
Dim ll_Statement As Long
Dim lS_Code As String
Dim ls_Description As String
Dim ls_Category As String
Dim ls_Contract As String * 1
Dim ls_Auto_Approved As String * 1
Dim li_CategoryNumber As Integer
Dim ls_CurrentCategory As String
Dim ls_CurrentKey As String
Dim i As Integer

    If Cbo_SubCat.Tag = UNLOADED Then
        MouseOff

        ls_CurrentCategory = ""
        li_CategoryNumber = 0


        On Error Resume Next
        
        ls_CurrentKey = ""
        ls_CurrentKey = Cbo_SubCat.SelectedItem.Key

        Cbo_SubCat.ComboItems.Clear

        On Error GoTo Cbo_SubCat_DropDown_Err
        
        ls_Req = "EXEC IT_SubCat_cbo"
        
        If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
            li_Status = SQL_SUCCESS
            
            Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
                li_Status = SQLFetch(ll_Statement)
                If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                
                    'read the category description
                    ls_Category = ODBCData(ll_Statement, 1)
                    'read the code
                    lS_Code = "K" & ODBCData(ll_Statement, 2)
                    'read the description
                    ls_Description = ODBCData(ll_Statement, 3)
                    'Read the type of subcategory (order or contract)
                    ls_Contract = ODBCData(ll_Statement, 4)
                    'Read auto approved of the sub category
                    ls_Auto_Approved = ODBCData(ll_Statement, 5)
                    
                    If ls_Category <> ls_CurrentCategory Then
                        li_CategoryNumber = li_CategoryNumber + 1
                        Cbo_SubCat.ComboItems.Add , "S" & Str(li_CategoryNumber), ls_Category, , , 1
                        ls_CurrentCategory = ls_Category
                    End If
                    
                    Cbo_SubCat.ComboItems.Add , lS_Code, ls_Description, , , 3
                    Cbo_SubCat.ComboItems.Item(lS_Code).Tag = ls_Contract & ls_Auto_Approved & ls_Category
                    
                End If
            Loop
        
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
            
        End If
        
        If ls_CurrentKey <> "" Then
            For i = 1 To Cbo_SubCat.ComboItems.Count
                If Cbo_SubCat.ComboItems.Item(i).Key = ls_CurrentKey Then
                    Cbo_SubCat.ComboItems.Item(i).Selected = OK
                    Set Cbo_SubCat.SelectedItem = Cbo_SubCat.ComboItems.Item(i)
                End If
            Next
        End If
    
        Cbo_SubCat.Tag = Loaded
        MouseOn
    End If
    
    Exit Sub
    
Cbo_SubCat_DropDown_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError

End Sub


Private Sub cbo_I_Currency_Click()
    MouseOff
    Rates_Calculate
    MouseOn
End Sub

Private Sub cbo_I_Currency_DropDown()
Dim ls_Text As String

If cbo_I_Currency.Tag = UNLOADED Then
    MouseOff
    If cbo_I_Currency.ListIndex <> -1 Then
        ls_Text = cbo_I_Currency
    Else
        ls_Text = ""
    End If
    cbo_I_Currency.Clear
    FillOneCbo "EXEC IT_Currency_cbo ", cbo_I_Currency
    If ls_Text <> "" Then
        cbo_I_Currency.ListIndex = ComboFindItem(cbo_I_Currency, ls_Text)
    End If
    cbo_I_Currency.Tag = Loaded
    MouseOn
End If
End Sub

Private Sub cbo_Location_Click()

    MouseOff
    
    On Error GoTo Cbo_Location_Click_Err
    
    If cbo_Location.ListIndex <> -1 Then
        lbl_I_Comp_Currency = cbo_Location.Column(2, cbo_Location.ListIndex)
        Lbl_O_Comp_Currency = lbl_I_Comp_Currency
        
        If cbo_Location.Column(4) = "Y" And gs_Action = "Update" Then
            Opt_AppRef(0).Enabled = OK
            Opt_AppRef(1).Enabled = OK
            Opt_AppRef(2).Enabled = OK
            lbl_Approved_by.Enabled = OK
            cbo_Approved_by.Enabled = OK
            Lbl_Approval_date.Enabled = OK
            txt_Approval_date.Enabled = OK
            lbl_Detail3.Enabled = OK
            Txt_Detail3.Locked = KO
        Else
            Opt_AppRef(0).Enabled = KO
            Opt_AppRef(1).Enabled = KO
            Opt_AppRef(2).Enabled = KO
            lbl_Approved_by.Enabled = KO
            cbo_Approved_by.Enabled = KO
            Lbl_Approval_date.Enabled = KO
            txt_Approval_date.Enabled = KO
            lbl_Detail3.Enabled = KO
            Txt_Detail3.Locked = OK
        End If
        
        If cbo_Location.Column(3) = "Y" Then
            lbl_Confidential.Visible = OK
            Chk_Confidential.Visible = OK
        Else
            lbl_Confidential.Visible = KO
            Chk_Confidential.Visible = KO
            Chk_Confidential.value = KO
        End If

    End If

    Rates_Calculate

Cbo_Location_Click_Err:

    MouseOn

End Sub

Private Sub cbo_Location_DropButtonClick()
Dim lv_Code As Variant

    If cbo_Location.Tag = UNLOADED Then
        MouseOff
        lv_Code = MCombo_GetCode(cbo_Location)
        cbo_Location.Clear
        MCombo_Fill cbo_Location, "EXEC IT_Location_cbo '" & prg.LoginName & "'", , KO
        MCombo_CodeSelect(cbo_Location) = lv_Code
        cbo_Location.Tag = Loaded
        MouseOn
    End If

End Sub

Private Sub Cbo_O_Currency_DropDown()
Dim ls_Text As String

    If cbo_O_Currency.Tag = UNLOADED Then
        MouseOff
        If cbo_O_Currency.ListIndex <> -1 Then
            ls_Text = cbo_O_Currency.Text
        Else
            ls_Text = ""
        End If
        cbo_O_Currency.Clear
        FillOneCbo "EXEC IT_Currency_cbo ", cbo_O_Currency
        If ls_Text <> "" Then
            cbo_O_Currency.ListIndex = ComboFindItem(cbo_O_Currency, ls_Text)
        End If
        cbo_O_Currency.Tag = Loaded
        MouseOn
    End If

End Sub

Private Sub cbo_Order_by_DropButtonClick()
Dim lv_Code As Variant

    If cbo_Order_by.Tag = UNLOADED Then
        MouseOff
        lv_Code = MCombo_GetCode(cbo_Order_by)
        cbo_Order_by.Clear
        MCombo_Fill cbo_Order_by, "EXEC IT_Order_by_cbo"
        MCombo_CodeSelect(cbo_Order_by) = lv_Code
        cbo_Order_by.Tag = Loaded
        MouseOn
    End If

End Sub

Private Sub cbo_Project_DropButtonClick()
Dim lv_Code As Variant

    If cbo_Project.Tag = UNLOADED Then
        MouseOff
        lv_Code = MCombo_GetCode(cbo_Project)
        cbo_Project.Clear
        MCombo_AddItemCode cbo_Project, 0, ""
        MCombo_Fill cbo_Project, "EXEC IT_Project_cbo"
        MCombo_CodeSelect(cbo_Project) = lv_Code
        cbo_Project.Tag = Loaded
        MouseOn
    End If

End Sub

Private Sub txt_I_Date_LostFocus()
    MouseOff
    Rates_Calculate
    MouseOn
End Sub


Private Sub txt_O_Amount_LostFocus()
    MouseOff
    Rates_Calculate
    MouseOn
End Sub

Private Sub txt_O_Date_LostFocus()
    MouseOff
    Rates_Calculate
    MouseOn
End Sub

Private Sub Form_Load()
Dim li_Count As Integer

    MouseOff
    
    On Error GoTo Form_Load_Err
    
    If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me

    'Redesign the form without the Invoice Amount Frame
    frm_amount.Visible = KO
    ssp_save.Top = 6180
    ssp_quit.Top = 6180
    Me.Height = 7250
    
    'Load Pictures
    ssp_save.Picture = LoadResPicture(RES_OK, 1)
    ssp_quit.Picture = LoadResPicture(RES_QUIT, 1)

    Get_Constants
    
    cbo_Location.Clear
    cbo_Location.Tag = UNLOADED
    cbo_Project.Clear
    cbo_Project.Tag = UNLOADED
    Cbo_SubCat.ComboItems.Clear
    Cbo_SubCat.Tag = UNLOADED
    cbo_Order_by.Clear
    cbo_Order_by.Tag = UNLOADED
    cbo_O_Currency.Clear
    cbo_O_Currency.Tag = UNLOADED
    cbo_Approved_by.Clear
    cbo_Approved_by.Tag = UNLOADED
    cbo_I_Currency.Clear
    cbo_I_Currency.Tag = UNLOADED

    Initialize_Screen
    
    Select Case gs_Action
        Case "Add":
        Case "Update"
            Set_Description
            If Mid(Cbo_SubCat.SelectedItem.Tag, 2, 1) = "N" And cbo_Location.Column(4) = "N" And cbo_Approved_by.Text <> "" Then
                opt_CapExp(0).Enabled = KO
                opt_CapExp(1).Enabled = KO
                lbl_Confidential.Enabled = KO
                Chk_Confidential.Enabled = KO
                lbl_Location.Enabled = KO
                cbo_Location.Enabled = KO
                lbl_Project.Enabled = KO
                cbo_Project.Enabled = KO
                Lbl_SubCat.Enabled = KO
                Cbo_SubCat.Enabled = KO
                'ssp_save.Visible = KO
                ssp_save.Visible = OK
                lbl_Order_nb.Enabled = OK
                txt_Order_nb.Enabled = OK
                lbl_O_Date.Enabled = OK
                txt_O_Date.Enabled = OK
            Else
                lbl_Order_nb.Enabled = OK
                txt_Order_nb.Enabled = OK
                lbl_Order_by.Enabled = OK
                cbo_Order_by.Enabled = OK
                Lbl_O_Amount.Enabled = OK
                txt_O_Amount.Enabled = OK
                cbo_O_Currency.Enabled = OK
                lbl_O_Date.Enabled = OK
                txt_O_Date.Enabled = OK
                Lbl_O_Amount_Comp.Enabled = OK
                Txt_O_Amount_Comp.Enabled = OK
                Lbl_O_Comp_Currency.Enabled = OK
                Lbl_O_Comp_Rate.Enabled = OK
                txt_O_Comp_Rate.Enabled = OK
                Lbl_O_Amount_USD.Enabled = OK
                Txt_O_Amount_USD.Enabled = OK
                Lbl_O_USD_Currency.Enabled = OK
                Lbl_O_USD_Rate.Enabled = OK
                txt_O_USD_Rate.Enabled = OK
                lbl_Detail.Enabled = OK
                txt_Detail.Locked = KO
                lbl_Detail2.Enabled = OK
                Txt_Detail2.Locked = KO
                If cbo_Location.Column(4) = "Y" And Mid(Cbo_SubCat.SelectedItem.Tag, 2, 1) = "N" Then
                    Opt_AppRef(0).Enabled = OK
                    Opt_AppRef(1).Enabled = OK
                    Opt_AppRef(2).Enabled = OK
                    lbl_Approved_by.Enabled = OK
                    cbo_Approved_by.Enabled = OK
                    Lbl_Approval_date.Enabled = OK
                    txt_Approval_date.Enabled = OK
                    lbl_Detail3.Enabled = OK
                    Txt_Detail3.Locked = KO
                End If
            End If
            
        Case "Delete", "MoreInfo"
            opt_CapExp(0).Enabled = KO
            opt_CapExp(1).Enabled = KO
            lbl_Confidential.Enabled = KO
            Chk_Confidential.Enabled = KO
            lbl_Location.Enabled = KO
            cbo_Location.Enabled = KO
            lbl_Project.Enabled = KO
            cbo_Project.Enabled = KO
            Lbl_SubCat.Enabled = KO
            Cbo_SubCat.Enabled = KO
            Set_Description
            If gs_Action = "MoreInfo" _
               Or (Mid(Cbo_SubCat.SelectedItem.Tag, 2, 1) = "N" And cbo_Location.Column(4) = "N" And cbo_Approved_by.Text <> "") Then
                ssp_save.Visible = KO
            End If
    End Select

Caption = Caption & " - " & gs_Action

MouseOn
Exit Sub

Form_Load_Err:
    StdError
End Sub

Private Sub ssp_save_Click()

MouseOff
gb_Return = KO

If cbo_O_Currency.Text <> Lbl_O_Comp_Currency.Caption And (gs_Action = "Add" Or (gs_Action = "Update" And cbo_O_Currency.Enabled = OK)) Then
    If SendMessage(138, "The currency is different of the location currency ... Are you sure ?", gut_LangLogin.Code, vbYesNo) = vbNo Then
        MouseOn
        Exit Sub
    End If
End If

Select Case gs_Action
Case "Add":
    If Control = KO Then GoTo ssp_save_Click_End
    If Add_Table Then
        gb_Return = OK
        Initialize_Screen
    End If
Case "Update":
    If Control = KO Then GoTo ssp_save_Click_End
    If Upd_Table Then
        gb_Return = OK
        Unload Me
        Exit Sub
    End If
Case "Delete":
    If Dlt_Table Then
        gb_Return = OK
        Unload Me
        Exit Sub
    End If
End Select

ssp_save_Click_End:
    MouseOn
End Sub

Private Sub ssp_quit_Click()
MouseOff
gb_Return = KO
Unload Me
End Sub

Private Sub Get_Constants()
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Field As String
Dim ls_Text As String
   
    On Error GoTo Get_Constants_Err
    
    ls_Req = gs_ParamReqCsts & ", '" & gut_LangLogin.Code & "'"
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQL_SUCCESS
    Else
        li_Status = SQL_ERROR
    End If
    
    Do While li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ls_Field = ODBCData(ll_Statement, 1)
            ls_Text = ODBCData(ll_Statement, 2)
            Select Case ls_Field
                Case "title": Me.Caption = ls_Text
                Case "opt_capital": opt_CapExp(0).Caption = ls_Text
                Case "opt_expenses": opt_CapExp(1).Caption = ls_Text
                Case "lbl_confidential": lbl_Confidential.Caption = ls_Text
                Case "lbl_location": lbl_Location.Caption = ls_Text
                Case "lbl_category": Lbl_Cat.Caption = ls_Text
                Case "lbl_project": lbl_Project.Caption = ls_Text
                Case "lbl_subcategory": Lbl_SubCat.Caption = ls_Text
                Case "lbl_order_nb1":
                        lbl_Order_nb.Caption = ls_Text
                        ms_lbl_order_nb = ls_Text
                Case "lbl_order_nb2":
                        ms_lbl_contract_nb = ls_Text
                Case "lbl_order_by": lbl_Order_by.Caption = ls_Text
                Case "lbl_o_amount1":
                        Lbl_O_Amount.Caption = ls_Text
                        ms_lbl_order_amount = ls_Text
                Case "lbl_o_amount2":
                        ms_lbl_contract_amount = ls_Text
                Case "lbl_o_date1":
                        lbl_O_Date.Caption = ls_Text
                        ms_lbl_order_date = ls_Text
                Case "lbl_o_date2":
                        ms_lbl_expense_date = ls_Text
                Case "lbl_o_amount_comp": Lbl_O_Amount_Comp.Caption = ls_Text
                Case "lbl_o_amount_usd": Lbl_O_Amount_USD.Caption = ls_Text
                Case "lbl_o_comp_rate": Lbl_O_Comp_Rate.Caption = ls_Text
                Case "lbl_o_usd_rate": Lbl_O_USD_Rate.Caption = ls_Text
                Case "lbl_detail": lbl_Detail.Caption = ls_Text
                Case "lbl_detail2": lbl_Detail2.Caption = ls_Text
                Case "txt_detail2":
                        ms_txt_detail2 = ls_Text
                Case "frm_general": frm_general.Caption = ls_Text
                Case "opt_approved": Opt_AppRef(0).Caption = ls_Text
                Case "opt_refused": Opt_AppRef(1).Caption = ls_Text
                Case "opt_onhold": Opt_AppRef(2).Caption = ls_Text
                Case "lbl_approved_by": lbl_Approved_by.Caption = ls_Text
                Case "lbl_approval_date": Lbl_Approval_date.Caption = ls_Text
                Case "lbl_detail3": lbl_Detail3.Caption = ls_Text
                Case "frm_approval": frm_approval.Caption = ls_Text
                Case "lbl_invoice_nb": lbl_Invoice_nb.Caption = ls_Text
                Case "lbl_i_date": Lbl_I_Date.Caption = ls_Text
                Case "lbl_i_amount": lbl_Invoice_Amount.Caption = ls_Text
                Case "lbl_account_ref": lbl_Account_Ref.Caption = ls_Text
                Case "lbl_i_Amount_comp": lbl_I_Amount_comp.Caption = ls_Text
                Case "lbl_i_comp_rate": lbl_I_Comp_Rate.Caption = ls_Text
                Case "lbl_i_amount_usd": lbl_I_Amount_USD.Caption = ls_Text
                Case "lbl_i_usd_rate": lbl_I_USD_Rate.Caption = ls_Text
                Case "frm_invoice": frm_amount.Caption = ls_Text
            End Select
        End If
    Loop
    
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    
    Exit Sub
    
Get_Constants_Err:
    StdError
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Sub

Private Sub Rates_Calculate()
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer

    Txt_O_Amount_USD.Text = ""
    txt_O_USD_Rate.Text = ""
    Txt_O_Amount_Comp.Text = ""
    txt_O_Comp_Rate.Text = ""
    txt_I_Amount_USD.Text = ""
    txt_I_USD_Rate.Text = ""
    txt_I_Amount_comp.Text = ""
    txt_I_comp_Rate.Text = ""
        
    On Error GoTo Rates_Calculate_Err

    If Not (Lbl_O_Comp_Currency.Caption = "" Or txt_O_Date.GetUSDate = "" Or cbo_O_Currency.Text = "" Or txt_O_Amount.Text = "") Then
        
        ls_Req = "EXEC IT_Exchange " & Formatage2(txt_O_Amount.Text) & ",'" & cbo_O_Currency.Text & "','" _
                & Lbl_O_Comp_Currency & "', '" & Mid(txt_O_Date.GetUSDate, 7, 4) & "', '" & Mid(txt_O_Date.GetUSDate, 1, 2) & "'"
    
        If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
            li_Status = SQL_SUCCESS
        Else
            li_Status = SQL_ERROR
        End If
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            Txt_O_Amount_USD.Text = Formatage(ODBCData(ll_Statement, 1), 2)
            txt_O_USD_Rate.Text = Formatage(ODBCData(ll_Statement, 2), 5)
            Txt_O_Amount_Comp.Text = Formatage(ODBCData(ll_Statement, 3), 2)
            txt_O_Comp_Rate.Text = Formatage(ODBCData(ll_Statement, 4), 5)
        End If
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)

    End If

    If Not (lbl_I_Comp_Currency.Caption = "" Or txt_I_Date.GetUSDate = "" Or cbo_I_Currency.Text = "" Or txt_Invoice_Amount.Text = "") Then
        
        ls_Req = "EXEC IT_Exchange " & Formatage2(txt_Invoice_Amount.Text) & ",'" & cbo_I_Currency.Text & "','" _
                & lbl_I_Comp_Currency & "', '" & Mid(txt_I_Date.GetUSDate, 7, 4) & "', '" & Mid(txt_I_Date.GetUSDate, 1, 2) & "'"
    
        If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
            li_Status = SQL_SUCCESS
        Else
            li_Status = SQL_ERROR
        End If
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            txt_I_Amount_USD.Text = Formatage(ODBCData(ll_Statement, 1), 2)
            txt_I_USD_Rate.Text = Formatage(ODBCData(ll_Statement, 2), 5)
            txt_I_Amount_comp.Text = Formatage(ODBCData(ll_Statement, 3), 2)
            txt_I_comp_Rate.Text = Formatage(ODBCData(ll_Statement, 4), 5)
        End If
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)

    End If

    Exit Sub

Rates_Calculate_Err:
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Sub

Private Sub Initialize_Screen()

    opt_CapExp(0).value = KO
    opt_CapExp(1).value = KO
    Chk_Confidential.value = KO
    Chk_Confidential.Visible = KO
    lbl_Confidential.Visible = KO
    cbo_Location.ListIndex = -1
    Txt_Cat.Text = ""
    cbo_Project.ListIndex = -1
    Set Cbo_SubCat.SelectedItem = Nothing
    Cbo_SubCat.Text = ""
    lbl_Order_nb.Enabled = KO
    txt_Order_nb.Enabled = KO
    txt_Order_nb.Text = ""
    lbl_Order_by.Enabled = KO
    cbo_Order_by.Enabled = KO
    cbo_Order_by.ListIndex = -1
    Lbl_O_Amount.Enabled = KO
    txt_O_Amount.Enabled = KO
    txt_O_Amount.Text = ""
    cbo_O_Currency.Enabled = KO
    cbo_O_Currency.ListIndex = -1
    lbl_O_Date.Enabled = KO
    txt_O_Date.Enabled = KO
    txt_O_Date.SetDate = ""
    Lbl_O_Amount_Comp.Enabled = KO
    Txt_O_Amount_Comp.Enabled = KO
    Lbl_O_Comp_Currency.Enabled = KO
    Txt_O_Amount_Comp.Text = ""
    Lbl_O_Comp_Rate.Enabled = KO
    txt_O_Comp_Rate.Enabled = KO
    txt_O_Comp_Rate.Text = ""
    Lbl_O_Amount_USD.Enabled = KO
    Txt_O_Amount_USD.Enabled = KO
    Lbl_O_USD_Currency.Enabled = KO
    Txt_O_Amount_USD.Text = ""
    Lbl_O_USD_Rate.Enabled = KO
    txt_O_USD_Rate.Enabled = KO
    txt_O_USD_Rate.Text = ""
    lbl_Detail.Enabled = KO
    txt_Detail.Locked = OK
    txt_Detail.Text = ""
    lbl_Detail2.Enabled = KO
    Txt_Detail2.Locked = OK
    Txt_Detail2.Text = ""
    Opt_AppRef(0).Enabled = KO
    Opt_AppRef(1).Enabled = KO
    Opt_AppRef(2).Enabled = KO
    Opt_AppRef(0).value = KO
    Opt_AppRef(1).value = KO
    Opt_AppRef(2).value = KO
    lbl_Approved_by.Enabled = KO
    cbo_Approved_by.Enabled = KO
    cbo_Approved_by.ListIndex = -1
    Lbl_Approval_date.Enabled = KO
    txt_Approval_date.Enabled = KO
    txt_Approval_date.SetDate = ""
    lbl_Detail3.Enabled = KO
    Txt_Detail3.Locked = OK
    Txt_Detail3.Text = ""
    txt_Invoice_nb.Text = ""
    txt_Invoice_Amount.Text = ""
    cbo_I_Currency.ListIndex = -1
    txt_I_Amount_comp.Text = ""
    txt_I_Amount_USD.Text = ""
    txt_I_Date.SetDate = ""
    txt_Account_Ref.Text = ""
    txt_I_comp_Rate.Text = ""
    txt_I_USD_Rate.Text = ""
    txt_spare1.Text = ""
    txt_spare2.Text = ""
    txt_spare3.Text = ""
    txt_spare4.Text = ""

    On Error Resume Next
    cbo_Location.SetFocus
End Sub

Private Function Dlt_Table() As Boolean
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long

Dlt_Table = KO

On Error GoTo suite

gs_message = MsgText(5, gut_LangLogin.Code)
If gs_message = "" Then
    gs_message = "Delete record ?"
End If
MouseOn
If MsgBox(gs_message, vbQuestion + vbYesNo, "Delete ") = vbYes Then
    MouseOff
    ls_Req = gs_ParamReqDel & " " _
     & gs_TableCode & ", " _
     & gs_TableCode9
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQLRowCount(ll_Statement, ll_lngrows)
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        If ll_lngrows = 0 Then
            SendMessage 7, "Delete failed : concurrency problem ?", gut_LangLogin.Code
            C_main.FillGrid
        Else
            Dlt_Table = OK
            C_main.Grid.RemoveItem C_main.Grid.Row
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 6, "Delete failed ", gut_LangLogin.Code
    End If
End If
MouseOff
Exit Function

suite:
Select Case Err
Case 30015
    C_main.FillGrid
Case Else
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    StdError
End Select
End Function

Private Function Upd_Table() As Boolean
Dim ls_Req As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ll_lngrows As Long
Dim ls_CapExp As String
Dim ls_AppRef As String
Dim ls_Date As String

    Upd_Table = KO
    
    On Error GoTo Upd_Table_Err

    If opt_CapExp(0).value = OK Then
        ls_CapExp = "Capital"
    Else
        ls_CapExp = "Expenses"
    End If
    
    ls_AppRef = ""
    If Opt_AppRef(0).value = OK Then
        ls_AppRef = "Approved"
    End If
    If Opt_AppRef(1).value = OK Then
        ls_AppRef = "Refused"
    End If
    If Opt_AppRef(2).value = OK Then
        ls_AppRef = "OnHold"
    End If
    
    ls_Req = gs_ParamReqUpd & " "
    ls_Req = ls_Req & gs_TableCode
    ls_Req = ls_Req & "," & gs_TableCode9
    If Chk_Confidential.value = 0 Then
        ls_Req = ls_Req & ",'N'"
    Else
        ls_Req = ls_Req & ",'Y'"
    End If
    ls_Req = ls_Req & ",'" & ls_CapExp & "'"
    ls_Req = ls_Req & "," & MCombo_GetCode(cbo_Location)
    ls_Req = ls_Req & "," & Mid(Cbo_SubCat.SelectedItem.Key, 2)
    If cbo_Project.ListIndex = -1 Or cbo_Project.Text = "" Then
        ls_Req = ls_Req & ",NULL"
    Else
        ls_Req = ls_Req & "," & MCombo_GetCode(cbo_Project)
    End If
    ls_Req = ls_Req & ",'" & QuoteParam(txt_Order_nb.Text) & "'"
    ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_Order_by) & "'"
    ls_Req = ls_Req & ",'" & txt_O_Date.GetUSDate & "'"
    ls_Req = ls_Req & "," & Formatage2(txt_O_Amount.Text)
    ls_Req = ls_Req & ",'" & cbo_O_Currency.Text & "'"
    ls_Req = ls_Req & "," & Formatage2(Txt_O_Amount_Comp.Text)
    ls_Req = ls_Req & "," & Formatage2(Txt_O_Amount_USD.Text)
    If txt_Detail.Text = "" Then
        ls_Req = ls_Req & ",NULL"
    Else
        ls_Req = ls_Req & ",'" & QuoteParam(txt_Detail.Text) & "'"
    End If
    If Txt_Detail2.Text = "" Then
        ls_Req = ls_Req & ",NULL"
    Else
        ls_Req = ls_Req & ",'" & QuoteParam(Txt_Detail2.Text) & "'"
    End If
    If Mid(Cbo_SubCat.SelectedItem.Tag, 2, 1) = "Y" Then
        ls_Req = ls_Req & ",'Approved'"
        ls_Req = ls_Req & ",'Automatic'"
        txt_Approval_date.SetToday
        ls_Req = ls_Req & ",'" & txt_Approval_date.GetUSDate & "'"
        ls_Req = ls_Req & ",'This sub-category is automatically approved'"
    Else
        If ls_AppRef = "" Then
            ls_Req = ls_Req & ",NULL"
        Else
            ls_Req = ls_Req & ",'" & ls_AppRef & "'"
        End If
        If cbo_Approved_by.ListIndex = -1 Then
            ls_Req = ls_Req & ",NULL"
        Else
            ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_Approved_by) & "'"
        End If
        If txt_Approval_date.GetUSDate = "" Then
            ls_Req = ls_Req & ",NULL"
        Else
            ls_Req = ls_Req & ",'" & txt_Approval_date.GetUSDate & "'"
        End If
        If Txt_Detail3.Text = "" Then
            ls_Req = ls_Req & ",NULL"
        Else
            ls_Req = ls_Req & ",'" & QuoteParam(Txt_Detail3.Text) & "'"
        End If
    End If
    ls_Req = ls_Req & ",NULL" 'Invoice_nb
    ls_Req = ls_Req & ",NULL" 'Payment_date
    ls_Req = ls_Req & ",NULL" 'Account_ref
    ls_Req = ls_Req & ",NULL" 'Invoice_Amount
    ls_Req = ls_Req & ",NULL" 'Invoice_Cur
    ls_Req = ls_Req & ",NULL" 'Invoice_Comp_Cur
    ls_Req = ls_Req & ",NULL" 'Invoice_Comp_USD
    ls_Req = ls_Req & ",NULL" 'S_Spare1
    ls_Req = ls_Req & ",NULL" 'S_Spare2
    ls_Req = ls_Req & ",NULL" 'R_Spare1
    ls_Req = ls_Req & ",NULL" 'R_Spare2

    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        li_Status = SQLRowCount(ll_Statement, ll_lngrows)
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        If ll_lngrows = 0 Then
            SendMessage 2, "Another user change the record", gut_LangLogin.Code
        Else
            Upd_Table = OK
        End If
    Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        SendMessage 3, "Update failed", gut_LangLogin.Code
    End If

    Exit Function

Upd_Table_Err:
    Select Case Err
    Case 30015

    Case Else
        li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        StdError
    End Select
End Function

Private Sub txt_Invoice_Amount_LostFocus()
    MouseOff
    Rates_Calculate
    MouseOn
End Sub

