VERSION 5.00
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Begin VB.Form Quot_General_mtnc 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Quotation Main"
   ClientHeight    =   7185
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9810
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   7185
   ScaleWidth      =   9810
   StartUpPosition =   2  'CenterScreen
   Begin VB.ListBox lst_ToolBox 
      ForeColor       =   &H00000000&
      Height          =   2010
      ItemData        =   "Q_General_mtnc.frx":0000
      Left            =   1680
      List            =   "Q_General_mtnc.frx":0002
      TabIndex        =   28
      Top             =   600
      Visible         =   0   'False
      Width           =   1932
   End
   Begin VB.Frame Frm_Information 
      Height          =   1515
      Left            =   120
      TabIndex        =   53
      Top             =   5580
      Width           =   4695
      Begin VB.TextBox Txt_TotalSurface 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1740
         Locked          =   -1  'True
         TabIndex        =   10
         TabStop         =   0   'False
         Top             =   240
         Width           =   2715
      End
      Begin VB.TextBox Txt_TotalAmount 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1740
         Locked          =   -1  'True
         TabIndex        =   11
         TabStop         =   0   'False
         Top             =   660
         Width           =   2715
      End
      Begin VB.TextBox Txt_LeadTime 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1740
         Locked          =   -1  'True
         TabIndex        =   12
         TabStop         =   0   'False
         Top             =   1080
         Width           =   2715
      End
      Begin VB.Label Lbl_TotalSurface 
         Caption         =   "Total Surface"
         Enabled         =   0   'False
         Height          =   255
         Left            =   180
         TabIndex        =   56
         Top             =   300
         Width           =   1575
      End
      Begin VB.Label Lbl_TotalAmount 
         Caption         =   "Total Amount"
         Enabled         =   0   'False
         Height          =   255
         Left            =   180
         TabIndex        =   55
         Top             =   720
         Width           =   1575
      End
      Begin VB.Label Lbl_LeadTime 
         Caption         =   "Lead Time"
         Enabled         =   0   'False
         Height          =   255
         Left            =   180
         TabIndex        =   54
         Top             =   1140
         Width           =   1575
      End
   End
   Begin VB.Frame Frm_Quotation 
      Height          =   1215
      Left            =   4980
      TabIndex        =   50
      Top             =   5880
      Width           =   4695
      Begin VB.TextBox Txt_SapOrder 
         Height          =   315
         Left            =   1740
         TabIndex        =   20
         Top             =   765
         Width           =   2715
      End
      Begin MSForms.ComboBox Cbo_LoseReason 
         Height          =   315
         Left            =   1740
         TabIndex        =   19
         Top             =   360
         Width           =   2715
         VariousPropertyBits=   679479323
         DisplayStyle    =   7
         Size            =   "4789;556"
         MatchEntry      =   1
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin VB.Label Lbl_SapOrder 
         Caption         =   "SAP Order"
         Height          =   255
         Left            =   180
         TabIndex        =   52
         Top             =   825
         Width           =   1575
      End
      Begin VB.Label Lbl_LoseReason 
         Caption         =   "Lose Reason"
         Height          =   315
         Left            =   180
         TabIndex        =   51
         Top             =   360
         Width           =   1575
      End
   End
   Begin VB.Frame Frm_Customer 
      Height          =   1935
      Left            =   135
      TabIndex        =   44
      Top             =   3510
      Width           =   4695
      Begin VB.TextBox Txt_Contractor 
         Height          =   315
         Left            =   1740
         TabIndex        =   58
         TabStop         =   0   'False
         Top             =   1080
         Width           =   2715
      End
      Begin VB.PictureBox Pic_SalesProject 
         AutoRedraw      =   -1  'True
         BorderStyle     =   0  'None
         Enabled         =   0   'False
         FillColor       =   &H00FFFFFF&
         Height          =   345
         Left            =   4200
         ScaleHeight     =   345
         ScaleWidth      =   375
         TabIndex        =   7
         Top             =   660
         Width           =   375
      End
      Begin VB.TextBox txt_SalesProject 
         Height          =   315
         Left            =   1740
         TabIndex        =   6
         Top             =   660
         Width           =   2535
      End
      Begin VB.PictureBox Pic_Customer 
         AutoRedraw      =   -1  'True
         BorderStyle     =   0  'None
         Enabled         =   0   'False
         FillColor       =   &H00FFFFFF&
         Height          =   345
         Left            =   4185
         ScaleHeight     =   345
         ScaleWidth      =   375
         TabIndex        =   5
         Top             =   240
         Width           =   375
      End
      Begin VB.TextBox Txt_Customer 
         Height          =   315
         Left            =   1740
         TabIndex        =   4
         Top             =   240
         Width           =   2535
      End
      Begin VB.Label Lbl_Contractor 
         Caption         =   "Contractor1"
         Height          =   255
         Left            =   180
         TabIndex        =   59
         Top             =   1140
         Width           =   1575
      End
      Begin MSForms.ComboBox Cbo_Currency 
         Height          =   315
         Left            =   1740
         TabIndex        =   9
         Top             =   1500
         Width           =   2715
         VariousPropertyBits=   679479323
         DisplayStyle    =   7
         Size            =   "4789;556"
         MatchEntry      =   1
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin MSForms.ComboBox cbo_DeliveryAddress 
         Height          =   315
         Left            =   1740
         TabIndex        =   8
         Top             =   1320
         Visible         =   0   'False
         Width           =   2715
         VariousPropertyBits=   679479323
         DisplayStyle    =   7
         Size            =   "4789;556"
         MatchEntry      =   1
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin VB.Label Lbl_Customer 
         Caption         =   "Customer"
         Height          =   315
         Left            =   180
         TabIndex        =   48
         Top             =   300
         Width           =   1515
      End
      Begin VB.Label Lbl_Currency 
         Caption         =   "Currency"
         Height          =   315
         Left            =   180
         TabIndex        =   47
         Top             =   1560
         Width           =   1575
      End
      Begin VB.Label Lbl_SalesProject 
         Caption         =   "Sales Project"
         Height          =   315
         Left            =   180
         TabIndex        =   46
         Top             =   720
         Width           =   1575
      End
      Begin VB.Label Lbl_DeliveryAddress 
         Caption         =   "Delivery Address"
         Height          =   255
         Left            =   180
         TabIndex        =   45
         Top             =   1380
         Visible         =   0   'False
         Width           =   1575
      End
   End
   Begin VB.Frame Frm_Armstrong 
      Height          =   3975
      Left            =   4995
      TabIndex        =   39
      Top             =   1860
      Width           =   4695
      Begin Project1.CDate d_ValidityDate 
         Height          =   315
         Left            =   1740
         TabIndex        =   15
         Top             =   1080
         Width           =   2715
         _ExtentX        =   4895
         _ExtentY        =   556
      End
      Begin VB.CommandButton Btn_UpdSalesRep 
         Height          =   580
         Left            =   3900
         Style           =   1  'Graphical
         TabIndex        =   18
         Top             =   3240
         Width           =   580
      End
      Begin VB.ListBox Lst_SalesReps 
         Height          =   1230
         Left            =   1740
         TabIndex        =   17
         Top             =   1920
         Width           =   2715
      End
      Begin Project1.CDate d_DeliveryDate 
         Height          =   315
         Left            =   1740
         TabIndex        =   14
         Top             =   720
         Width           =   2715
         _ExtentX        =   4895
         _ExtentY        =   556
      End
      Begin MSForms.ComboBox Cbo_Plant 
         Height          =   315
         Left            =   1740
         TabIndex        =   13
         Top             =   300
         Width           =   2715
         VariousPropertyBits=   679495707
         DisplayStyle    =   7
         Size            =   "4789;556"
         MatchEntry      =   1
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin MSForms.ComboBox Cbo_SalesOffice 
         Height          =   315
         Left            =   1740
         TabIndex        =   16
         Top             =   1500
         Width           =   2715
         VariousPropertyBits=   679479323
         DisplayStyle    =   7
         Size            =   "4789;556"
         MatchEntry      =   1
         ShowDropButtonWhen=   2
         FontHeight      =   165
         FontCharSet     =   0
         FontPitchAndFamily=   2
      End
      Begin VB.Label Lbl_DeliveryDate 
         Caption         =   "Expected Delivery Date"
         Height          =   435
         Left            =   180
         TabIndex        =   42
         Top             =   600
         Width           =   1575
      End
      Begin VB.Label Lbl_SalesReps 
         Caption         =   "Sales Reps"
         Height          =   255
         Left            =   180
         TabIndex        =   49
         Top             =   1980
         Width           =   1575
      End
      Begin VB.Label Lbl_ValidityDate 
         Caption         =   "Validity Date"
         Height          =   255
         Left            =   180
         TabIndex        =   43
         Top             =   1140
         Width           =   1575
      End
      Begin VB.Label Lbl_SalesOffice 
         Caption         =   "Sales Office"
         Height          =   315
         Left            =   180
         TabIndex        =   41
         Top             =   1560
         Width           =   1575
      End
      Begin VB.Label Lbl_Plant 
         Caption         =   "Default Plant"
         Height          =   255
         Left            =   180
         TabIndex        =   40
         Top             =   300
         Width           =   1575
      End
   End
   Begin VB.Frame Frm_Users 
      Height          =   1515
      Left            =   135
      TabIndex        =   35
      Top             =   1860
      Width           =   4695
      Begin VB.TextBox Txt_ApprovalDate 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1740
         TabIndex        =   3
         TabStop         =   0   'False
         Top             =   1080
         Width           =   2715
      End
      Begin VB.TextBox Txt_Approval 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1740
         TabIndex        =   2
         TabStop         =   0   'False
         Top             =   660
         Width           =   2715
      End
      Begin VB.TextBox Txt_Creator 
         Enabled         =   0   'False
         Height          =   315
         Left            =   1740
         TabIndex        =   1
         TabStop         =   0   'False
         Top             =   240
         Width           =   2715
      End
      Begin VB.Label Lbl_ApprovalDate 
         Caption         =   "Approval Date"
         Enabled         =   0   'False
         Height          =   255
         Left            =   180
         TabIndex        =   38
         Top             =   1140
         Width           =   1575
      End
      Begin VB.Label Lbl_Approval 
         Caption         =   "Approval"
         Enabled         =   0   'False
         Height          =   255
         Left            =   180
         TabIndex        =   37
         Top             =   720
         Width           =   1575
      End
      Begin VB.Label Lbl_Creator 
         Caption         =   "Creator"
         Enabled         =   0   'False
         Height          =   255
         Left            =   180
         TabIndex        =   36
         Top             =   300
         Width           =   1575
      End
   End
   Begin VB.TextBox Txt_Version 
      Enabled         =   0   'False
      Height          =   315
      Left            =   4680
      TabIndex        =   22
      Top             =   780
      Width           =   615
   End
   Begin VB.TextBox Txt_Status 
      Enabled         =   0   'False
      Height          =   315
      Left            =   6900
      Locked          =   -1  'True
      TabIndex        =   23
      TabStop         =   0   'False
      Top             =   780
      Width           =   2775
   End
   Begin VB.Frame Line_Separator 
      Height          =   75
      Left            =   0
      TabIndex        =   31
      Top             =   1200
      Width           =   9735
   End
   Begin VB.TextBox Txt_Code 
      Enabled         =   0   'False
      Height          =   315
      Left            =   1140
      TabIndex        =   21
      TabStop         =   0   'False
      Top             =   780
      Width           =   1935
   End
   Begin VB.PictureBox ToolBar 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      ClipControls    =   0   'False
      ForeColor       =   &H80000008&
      Height          =   665
      Left            =   0
      ScaleHeight     =   630
      ScaleWidth      =   9780
      TabIndex        =   30
      Top             =   0
      Width           =   9810
      Begin VB.PictureBox Pic_ToolBox 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H00FFFFFF&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   1680
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   27
         Top             =   60
         Width           =   480
      End
      Begin VB.PictureBox Pic_Quit 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   2220
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   29
         Top             =   60
         Width           =   480
      End
      Begin VB.PictureBox Pic_Copy 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   1140
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   26
         Top             =   60
         Visible         =   0   'False
         Width           =   480
      End
      Begin VB.PictureBox Pic_Undo 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   600
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   25
         Top             =   60
         Width           =   480
      End
      Begin VB.PictureBox Pic_Save 
         Appearance      =   0  'Flat
         AutoSize        =   -1  'True
         BackColor       =   &H80000005&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   480
         Left            =   60
         ScaleHeight     =   480
         ScaleWidth      =   480
         TabIndex        =   24
         Top             =   60
         Width           =   480
      End
   End
   Begin MSForms.ComboBox Cbo_QuotationLanguage 
      Height          =   315
      Left            =   4380
      TabIndex        =   0
      Top             =   1380
      Width           =   2715
      VariousPropertyBits=   679495707
      DisplayStyle    =   7
      Size            =   "4789;556"
      MatchEntry      =   1
      ShowDropButtonWhen=   2
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
   End
   Begin VB.Label Lbl_QuotationLanguage 
      Caption         =   "Quotation Language"
      Height          =   435
      Left            =   2760
      TabIndex        =   57
      Top             =   1380
      Width           =   1575
   End
   Begin VB.Label Lbl_Code 
      Caption         =   "Code"
      Enabled         =   0   'False
      Height          =   255
      Left            =   120
      TabIndex        =   34
      Top             =   840
      Width           =   975
   End
   Begin VB.Label Lbl_Status 
      Caption         =   "Status"
      Enabled         =   0   'False
      Height          =   255
      Left            =   6060
      TabIndex        =   33
      Top             =   840
      Width           =   795
   End
   Begin VB.Label Lbl_Version 
      Caption         =   "Version"
      Enabled         =   0   'False
      Height          =   255
      Left            =   3960
      TabIndex        =   32
      Top             =   840
      Width           =   735
   End
End
Attribute VB_Name = "Quot_General_mtnc"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

' MultiComboBox: The parameter Tag says if the information have been loaded from the Database or not
' Text: The code is not stored in a text object but in a module variable

Dim mb_SalesProjectChanged As Boolean
Dim mb_CustomerChanged As Boolean
Dim mb_SalesProjectLostFocus As Boolean
Dim mb_CustomerLostFocus As Boolean

Public Enum QuotationAction
    QA_New = 1
    QA_NewVersion = 2
    QA_Update = 3
    QA_StatusChange = 4
    QA_Copy = 5
End Enum

Private Enum ObjectList
    OL_Language = 0
    OL_New = 1 'Must be the same as QuotationAction
    OL_NewVersion = 2 'Must be the same as QuotationAction
    OL_Update = 3 'Must be the same as QuotationAction
    QL_Status_Waiting_Plant_Confirmation = Quotation_Status.Waiting_Plant_Confirmation + 10 '12 Must be the same as Status + 10
    QL_Status_Send_to_customer = Quotation_Status.Send_to_customer + 10 '13 Must be the same as Status + 10
    QL_Status_Refused_Notify_Customer = Quotation_Status.Refused_Notify_customer + 10 '14 Must be the same as Status + 10
    QL_Status_Closed = Quotation_Status.closed + 10 '15 Must be the same as Status + 10
    QL_Status_Waiting_Customer_Confirmation = Quotation_Status.Waiting_Customer_Confirmation + 10 '16 Must be the same as Status + 10
    QL_Status_Enter_Customer_order = Quotation_Status.Enter_customer_order + 10 '18 Must be the same as Status + 10
    QL_Status_Ordered_to_Plant = Quotation_Status.Ordered_to_plant + 10 '19 Must be the same as Status + 10
    QL_Status_Archived = Quotation_Status.Archived + 10 '20 Must be the same as Status + 10
    QL_Status_Customer_Changes_Quotation = Quotation_Status.Customer_changes_Quotation + 10 '21 Must be the same as Status + 10
End Enum

'Input only
Public mi_Action As QuotationAction
Public mi_OldStatus As Integer
Public mb_SalesRepLoaded As Boolean

Public ml_TotalSurface As Long
Public mr_TotalAmount As Single
Public mr_LeadTime As Single

'Input/Output
Public mb_Return As Boolean

Public mi_iConcurrency As Integer
Public ms_LanguageCode As String
Public ms_LanguageDesc As String
Public ml_ClaimCustomerCode As Long
Public ms_ClaimCustomerDesc As String
Public mi_DeliveryAddressCode As Integer
Public ms_DeliveryAddressDesc As String
Public ms_PlantCode As String
Public ms_PlantDesc As String
Public ml_SalesProjectCode As Long
Public ms_SalesProjectDesc As String
Public ms_Contractor As String
Public ms_SalesOfficeCode As String
Public ms_SalesOfficeDesc As String
Public ms_CurrencyCode As String
Public ms_currencyDesc As String
Public mo_SalesRepCode As New Collection
Public mo_SalesRepDesc As New Collection
Public mi_QuotationCode As Integer
Public ms_QuotationDesc As String
Public mi_QuotationVersion As Integer
Public mi_QuotationStatusCode As Integer
Public mi_QuotationStatusDesc As String
Public ms_Creator As String
Public ms_Approval As String
Public ms_DeliveryDate As String
Public ms_ValidityDate As String
Public ms_ApprovalDate As String
Public ms_InternetFlag As Boolean
Public ms_DropFlag As String
Public ms_DropDate As String
'May be Input only with creator update
Public ms_SAPOrder As String
Public mi_LoseReasonCode As Integer
Public ms_LoseReasonDesc As String

Private ml_Q_CustomerCode As Long
Private mo_Q_SalesRepsCode As New Collection
Private mi_Q_StatusCode As Integer

Private Function Control() As Boolean
Dim lo_SetFocus As Object
    
    Control = KO
    
    Set lo_SetFocus = Nothing
    
'    If mb_SalesProjectChanged Then
'        If FoundUniqueSalesProject Then
'            mb_SalesProjectChanged = KO
'            lo_SetFocus = txt_SalesProject
'        End If
'    End If


    If mb_SalesProjectChanged Then
        If Not FoundUniqueSalesProject Then
            gut_Param2.Str1 = "Quotation_Project"
            gut_Param.Str1 = ""
            gut_Param.Str2 = ""
            gut_Param.Str4 = "EXEC screen_csts 'Project_C_Sel','" & gut_LangLogin.Code & "'"
            gut_Param.Str3 = " EXEC Sales_Project_del "
            C_Selection.s_OldCode = CStr(ml_SalesProjectCode)
            C_Selection.s_InitialLike = txt_SalesProject
            C_Selection.show 1
            If gb_Return = OK Then
                mb_SalesProjectChanged = KO
                mb_SalesProjectLostFocus = KO
                ml_SalesProjectCode = CLng(gut_Param2.Str4)
                txt_SalesProject = gut_Param2.Str6
            Else
                Set lo_SetFocus = txt_SalesProject
                GoTo Signal_Error
            End If
        Else
            mb_SalesProjectChanged = KO
            mb_SalesProjectLostFocus = KO
        End If
    End If

    If mb_CustomerChanged Then
        If Not FoundUniqueCustomer Then
            gut_Param2.Str1 = "Quotation_Customer"
            gut_Param.Str1 = "SAP"
            gut_Param.Str2 = "Quotation"
            gut_Param.Str4 = "EXEC screen_csts 'Cust_sel','" & gut_LangLogin.Code & "'"
            gut_Param2.Str3 = "EXEC screen_csts 'Mtnc_Claim_Cust','" & gut_LangWork.Code & "'"
            gut_Param.Str3 = " EXEC Claim_Customer_del "
            C_Selection.s_OldCode = CStr(ml_Q_CustomerCode)
            C_Selection.s_InitialLike = Txt_Customer
            C_Selection.show 1
            If gb_Return = OK Then
                If mi_Action = QA_New Or mi_Action = QA_Copy Then
                    DefaultValues
                End If
        
                ml_Q_CustomerCode = CLng(gut_Param2.Str4)
                Txt_Customer.Text = gut_Param2.Str6
                mb_CustomerChanged = KO
            Else
                Set lo_SetFocus = Txt_Customer
                GoTo Signal_Error
            End If
        Else
            mb_CustomerChanged = KO
            mb_CustomerLostFocus = KO
        End If
    End If
    
    If Cbo_QuotationLanguage.ListIndex = -1 And TypeName(lo_SetFocus) = "Nothing" Then Set lo_SetFocus = Cbo_QuotationLanguage
    If Txt_Customer.Text = "" And TypeName(lo_SetFocus) = "Nothing" Then Set lo_SetFocus = Txt_Customer
    If (cbo_currency.ListIndex = -1 Or cbo_currency.value = "") And TypeName(lo_SetFocus) = "Nothing" Then Set lo_SetFocus = cbo_currency
    If Cbo_SalesOffice.ListIndex = -1 And TypeName(lo_SetFocus) = "Nothing" Then Set lo_SetFocus = Cbo_SalesOffice
    
    If d_ValidityDate.isDateEntered Then
        If Not (d_ValidityDate.isDateValid) And TypeName(lo_SetFocus) = "Nothing" Then
            SendMessage 131, "Invalid Date.", gut_LangLogin.Code
            d_ValidityDate.SetFocus
            Exit Function
        End If
    Else
        If TypeName(lo_SetFocus) = "Nothing" Then Set lo_SetFocus = d_ValidityDate
    End If
        
    If d_DeliveryDate.isDateEntered Then
        If Not (d_DeliveryDate.isDateValid) And TypeName(lo_SetFocus) = "Nothing" Then
            SendMessage 131, "Invalid Date.", gut_LangLogin.Code
            d_DeliveryDate.SetFocus
            Exit Function
        End If
    End If
    
    
    If Lst_SalesReps.ListCount < 1 And TypeName(lo_SetFocus) = "Nothing" Then Set lo_SetFocus = Lst_SalesReps
    
    If Cbo_LoseReason.ListIndex = -1 And mi_Action = QA_StatusChange And mi_QuotationStatusCode = 5 And TypeName(lo_SetFocus) = "Nothing" Then Set lo_SetFocus = Cbo_LoseReason
        
Signal_Error:
    If TypeName(lo_SetFocus) <> "Nothing" Then
        SendMessage 8, "Value must be filled in", gut_LangLogin.Code
        lo_SetFocus.SetFocus
    Else
        Control = OK
    End If
    
End Function


Private Sub Btn_UpdSalesRep_Click()
Dim i As Integer

    Quot_SalesReps.ms_DBRequest = "Exec Sales_Reps_Assignement_t_lst2 " & CStr(ml_Q_CustomerCode) & ",'" & gut_LangLogin.Code & "'"
    If ml_Q_CustomerCode <> 0 Then Quot_SalesReps.ms_DBRequestAll = "Exec Sales_Reps_Assignement_t_lst2 0,'" & gut_LangLogin.Code & "'"
    Quot_SalesReps.ms_ScreenName = "Quot_SalesReps"
    Quot_SalesReps.ms_LanguageCode = gut_LangLogin.Code
    
    For i = Quot_SalesReps.mo_SelectedCode.Count To 1 Step -1
        Quot_SalesReps.mo_SelectedCode.Remove i
        Quot_SalesReps.mo_SelectedDesc.Remove i
    Next
    
    For i = 1 To mo_Q_SalesRepsCode.Count
        Quot_SalesReps.mo_SelectedCode.Add mo_Q_SalesRepsCode.Item(i)
        Quot_SalesReps.mo_SelectedDesc.Add Lst_SalesReps.List(i - 1)
    Next
   
    Quot_SalesReps.show 1
    
    If Quot_SalesReps.mb_Return = OK Then
        
        For i = mo_Q_SalesRepsCode.Count To 1 Step -1
            mo_Q_SalesRepsCode.Remove i
            Lst_SalesReps.RemoveItem i - 1
        Next
        
        For i = 1 To Quot_SalesReps.mo_SelectedCode.Count
            
            mo_Q_SalesRepsCode.Add Quot_SalesReps.mo_SelectedCode.Item(i)
            Lst_SalesReps.AddItem Quot_SalesReps.mo_SelectedDesc.Item(i)
        Next
    End If

End Sub

Private Sub cbo_currency_DropButtonclick()
Dim ls_Req As String
Dim lv_ActualCode

    If cbo_currency.Tag = UNLOADED Then
        MouseOff
        
        lv_ActualCode = MCombo_GetCode(cbo_currency)
        
        cbo_currency.Clear
                
        ls_Req = "EXEC currencies_cbo2 '" & gut_LangLogin.Code & "'"
        MCombo_Fill cbo_currency, ls_Req
        
        MCombo_CodeSelect(cbo_currency) = lv_ActualCode
        
        cbo_currency.Tag = Loaded
        
        MouseOn
    End If

End Sub

Private Sub Cbo_LoseReason_DropButtonClick()
Dim ls_Req As String
Dim lv_ActualCode
    
    If Cbo_LoseReason.Tag = UNLOADED Then
    
        lv_ActualCode = MCombo_GetCode(Cbo_LoseReason)
        Cbo_LoseReason.Clear
        
        ls_Req = "Exec Quot_LoseReason_Cbo '" & gut_LangLogin.Code & "'"
        MCombo_Fill Cbo_LoseReason, ls_Req
        
        MCombo_CodeSelect(Cbo_LoseReason) = lv_ActualCode
    
        Cbo_LoseReason.Tag = Loaded
    End If

End Sub

Private Sub Cbo_plant_DropButtonClick()
Dim ls_Req As String
Dim lv_ActualCode
    
    If cbo_Plant.Tag = UNLOADED Then
        MouseOff
    
        lv_ActualCode = MCombo_GetCode(cbo_Plant)
        cbo_Plant.Clear
    
        'Add a free element to free the combo choice
        MCombo_AddItemCode cbo_Plant, 0, ""
            
        ls_Req = "Exec Plants_Cbo '" & gut_LangLogin.Code & "'"
        MCombo_Fill cbo_Plant, ls_Req
            
        MCombo_CodeSelect(cbo_Plant) = lv_ActualCode
        
        cbo_Plant.Tag = Loaded
        
        MouseOn
    End If

End Sub

Private Sub Cbo_QuotationLanguage_Click()
        
    If Cbo_QuotationLanguage.ListIndex <> -1 Then
        If mi_Action = QA_New Then
            DisableObjects OL_New
        End If
    End If

End Sub

Private Sub Cbo_QuotationLanguage_DropButtonClick()
Dim ls_Req As String
Dim lv_ActualCode
    
    If Cbo_QuotationLanguage.Tag = UNLOADED Then
        MouseOff
        
        lv_ActualCode = MCombo_GetCode(Cbo_QuotationLanguage)
        Cbo_QuotationLanguage.Clear
        
        ls_Req = "EXEC language_cbo"
        MCombo_Fill Cbo_QuotationLanguage, ls_Req
        
        MCombo_CodeSelect(Cbo_QuotationLanguage) = lv_ActualCode
        
        Cbo_QuotationLanguage.Tag = Loaded
        MouseOn
    End If

End Sub

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

Dim ll_Count As Long 'count possible sales project
Dim ll_CountValid As Long 'count possible sales project that are valid (got town and country)
Dim ls_CustomerCode As String
Dim ls_CustomerDesc As String

On Error GoTo Err_FoundUniqueCustomer

FoundUniqueCustomer = KO

ls_Req = "Exec Customer_cnt '" & gut_LangLogin.Code & "',  '" & Txt_Customer & "'"

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
    'Get the row of data
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ll_Count = ODBCData(ll_Statement, 1)
            ll_CountValid = ODBCData(ll_Statement, 2)
            ls_CustomerCode = ODBCData(ll_Statement, 3)
            ls_CustomerDesc = ODBCData(ll_Statement, 4)
            If ll_Count = 1 And ll_CountValid = 1 Then
                ml_ClaimCustomerCode = CLng(ls_CustomerCode)
                Txt_Customer = ls_CustomerDesc
                FoundUniqueCustomer = OK
            End If
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End If

Exit Function

Err_FoundUniqueCustomer:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Function

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

Dim ll_Count As Long 'count possible sales project
Dim ll_CountValid As Long 'count possible sales project that are valid (got town and country)
Dim ls_SalesProjectCode As String
Dim ls_SalesProjectDesc As String

On Error GoTo Err_CountPossibleSalesProject

FoundUniqueSalesProject = KO

ls_Req = "Exec Sales_Project_cnt '" & gut_LangLogin.Code & "',  '" & txt_SalesProject & "'"

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
    'Get the row of data
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            ll_Count = ODBCData(ll_Statement, 1)
            ll_CountValid = ODBCData(ll_Statement, 2)
            ls_SalesProjectCode = ODBCData(ll_Statement, 3)
            ls_SalesProjectDesc = ODBCData(ll_Statement, 4)
            If ll_Count = 1 And ll_CountValid = 1 Then
                ml_SalesProjectCode = CLng(ls_SalesProjectCode)
                txt_SalesProject = ls_SalesProjectDesc
                FoundUniqueSalesProject = OK
            End If
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End If

Exit Function

Err_CountPossibleSalesProject:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Function



Private Sub DefaultValues()
Dim ls_Req As String
Dim lS_Code As String
Dim ls_Desc As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim i As Integer


On Error GoTo Err_DefaultValues
MouseOff
Cbo_SalesOffice.Clear
Cbo_SalesOffice.Tag = UNLOADED
cbo_currency.Clear
For i = mo_Q_SalesRepsCode.Count To 1 Step -1
    mo_Q_SalesRepsCode.Remove i
Next
Lst_SalesReps.Clear

cbo_SalesOffice_DropButtonClick

ls_Req = "Exec Sales_Office_cbo4 '" & gut_LangLogin.Code & "', " & CLng(gut_Param2.Str4)

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
    'Get the row of data
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            lS_Code = ODBCData(ll_Statement, 1)
            ls_Desc = ODBCData(ll_Statement, 2)
            MCombo_CodeSelect(Cbo_SalesOffice) = lS_Code
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End If

ls_Req = "Exec Currencies_cbo3 '" & gut_LangLogin.Code & "', " & CLng(gut_Param2.Str4)

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
    'Get the row of data
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            lS_Code = ODBCData(ll_Statement, 1)
            ls_Desc = ODBCData(ll_Statement, 2)
            MCombo_AddItemCode cbo_currency, lS_Code, ls_Desc
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End If

ls_Req = "Exec Sales_Reps_cbo2 " & CLng(gut_Param2.Str4)

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
    'Get the row of data
        li_Status = SQLFetch(ll_Statement)
        If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
            lS_Code = ODBCData(ll_Statement, 1)
            ls_Desc = ODBCData(ll_Statement, 2)
            Quot_SalesReps.mo_SelectedCode.Add lS_Code
            Quot_SalesReps.mo_SelectedDesc.Add ls_Desc
            mo_Q_SalesRepsCode.Add lS_Code
            Lst_SalesReps.AddItem ls_Desc
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End If

cbo_currency.Tag = UNLOADED
MouseOn
Exit Sub

Err_DefaultValues:
li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
MouseOn
End Sub

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

    If Cbo_SalesOffice.ListIndex <> -1 And (d_ValidityDate.isDateEntered = KO Or d_ValidityDate.isDateValid = KO) Then
        ls_Req = "Exec Sales_Office_sel2 '" & MCombo_GetCode(Cbo_SalesOffice) & "'"
        
        ls_Value = 0
        
        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
            'Get the row of data
                li_Status = SQLFetch(ll_Statement)
                If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                    ls_Value = ODBCDataInt(ll_Statement, 1)
                End If
            Loop
            li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
        End If
        
        If ls_Value <> "" Then
            d_ValidityDate.SetToday
            d_ValidityDate.AddDay Val(ls_Value)
        End If
        
    End If

End Sub

Private Sub cbo_SalesOffice_DropButtonClick()
Dim ls_Req As String
Dim lv_ActualCode

    If Cbo_SalesOffice.Tag = UNLOADED Then
        MouseOff
        
        lv_ActualCode = MCombo_GetCode(Cbo_SalesOffice)
        Cbo_SalesOffice.Clear
        
        ls_Req = "Exec Sales_Office_cbo5 '" & gut_LangLogin.Code & "','" & prg.LoginName & "'"
        MCombo_Fill Cbo_SalesOffice, ls_Req
    
        MCombo_CodeSelect(Cbo_SalesOffice) = lv_ActualCode
    
        Cbo_SalesOffice.Tag = Loaded
        
        MouseOn
    End If

End Sub



Private Sub Form_Click()
    lst_toolbox.Visible = KO
End Sub

Private Sub Form_Load()

    MouseOff
    
    If gl_CodePage <> 1252 And gl_CodePage <> 0 Then ChangeCharset Me

    mb_Return = KO
    mb_SalesProjectChanged = KO
    mb_SalesProjectLostFocus = KO
    mb_CustomerChanged = KO
    mb_CustomerLostFocus = KO
    
    'Initialize the pictures
    pic_Save.Picture = LoadResPicture(RES_OK, 1)
    pic_Undo.Picture = LoadResPicture(RES_CANCEL, 1)
    Pic_Copy.Picture = LoadResPicture(RES_PHOTO, 1)
'    pic_Toolbox.Picture = LoadResPicture(RES_TOOL, 1)
    pic_Toolbox.Visible = False
    pic_quit.Picture = LoadResPicture(RES_QUIT, 1)
    Pic_Customer.Picture = LoadResPicture(RES_COMBOCOPY, 1)
    Pic_SalesProject.Picture = LoadResPicture(RES_COMBOCOPY, 1)
    Btn_UpdSalesRep.Picture = LoadResPicture(RES_MODIFY, 1)

    'Initialize the combobox to unloaded status
    cbo_currency.Tag = UNLOADED
    Cbo_LoseReason.Tag = UNLOADED
    cbo_Plant.Tag = UNLOADED
    Cbo_QuotationLanguage.Tag = UNLOADED
    Cbo_SalesOffice.Tag = UNLOADED

    GetCaptions
    FillObjects mi_Action
    
    'Initialize the object in function of the action
    Select Case mi_Action
        Case QA_NewVersion
            
            DisableObjects OL_NewVersion
        
        Case QA_Copy
        
            DisableObjects OL_New
        
        Case QA_Update
        
            DisableObjects OL_Update
        
        Case QA_StatusChange
        
            If mi_QuotationStatusCode = Quotation_Status.closed Then
                DisableObjects ObjectList.QL_Status_Closed
            Else
                DisableObjects 10 + mi_OldStatus
            End If
            
        Case Else 'QA_New
    
    End Select

    MouseOn

End Sub

Private Sub Lst_SalesReps_LostFocus()
    lst_toolbox.Visible = KO
End Sub

Private Sub lst_toolbox_Click()
Dim li_Count As Integer
On Error GoTo suite
    If lst_toolbox.ListIndex = -1 Then Exit Sub
    MouseOff
    lst_toolbox.Visible = KO
    
    BeforeToolbox
    
    gs_TableName = "SalesProject"
    gs_ParamReq1 = "EXEC Sales_Project_t_lst1 '" & Left(Replace(QuotMain.tv_Outline.GetPath, "\Project\", ""), 2) & "', '"
    gs_ParamReq2 = "EXEC Screen_Csts 'Main_Sales_Proj', '" & gut_LangLogin.Code & "'"
    gs_ParamReq3 = "EXEC Check_Security 'Sales_Project', " & prg.LoginName
    gi_TranslateType = 4
    gi_GridWidth(0) = 1     ' SP_Code
    gi_GridWidth(1) = 1     ' iConcurrency
    gi_GridWidth(2) = 2500  ' Description
    gi_GridWidth(3) = 1000  ' Start date
    gi_GridWidth(4) = 1000  ' Size
    gi_GridWidth(5) = 1000  ' Unit of measure code
    gi_GridWidth(6) = 1     ' Unit of measure desc
    gi_GridWidth(7) = 1     ' Zip
    gi_GridWidth(8) = 2000  ' Town
    gi_GridWidth(9) = 1     ' Country code
    gi_GridWidth(10) = 2000 ' Country desc
    gi_GridWidth(11) = 3500 ' Addr1
    gi_GridWidth(12) = 3500 ' Addr2
    gi_GridWidth(13) = 1    ' Comment
    gi_GridWidth(14) = 1    ' internet flag
    gi_GridWidth(15) = 1    ' drop flag
    For li_Count = 16 To 29
        gi_GridWidth(li_Count) = 1
    Next li_Count
    C_main.show 1
    
    AfterToolbox
    
    MouseOn
    Exit Sub
    
suite:
    StdError
End Sub

Private Sub Pic_Customer_Click()
    If mb_SalesProjectLostFocus Then Exit Sub
    If mb_CustomerLostFocus Then Exit Sub
'    If mb_CustomerChanged Then
'        If FoundUniqueCustomer Then
'            mb_CustomerChanged = KO
'            Exit Sub
'        End If
'    End If
  '  gut_Param2.Str1 = "Claim_Customer"
    gut_Param2.Str1 = "Quotation_Customer"
    gut_Param.Str1 = "SAP"
    gut_Param.Str2 = "Quotation"
    gut_Param.Str4 = "EXEC screen_csts 'Cust_sel','" & gut_LangLogin.Code & "'"
    gut_Param2.Str3 = "EXEC screen_csts 'Mtnc_Claim_Cust','" & gut_LangWork.Code & "'"
    gut_Param.Str3 = " EXEC Claim_Customer_del "
    C_Selection.s_OldCode = CStr(ml_Q_CustomerCode)
    C_Selection.s_InitialLike = Txt_Customer
    C_Selection.show 1
    If gb_Return = OK Then
        If mi_Action = QA_New Or mi_Action = QA_Copy Then
            DefaultValues
        End If
        
        ml_Q_CustomerCode = CLng(gut_Param2.Str4)
        Txt_Customer.Text = gut_Param2.Str6
    End If
End Sub


Private Sub pic_quit_Click()
    Unload Me
End Sub

Private Sub Pic_SalesProject_Click()
    If mb_SalesProjectLostFocus Then Exit Sub
    If mb_CustomerLostFocus Then Exit Sub
'    If mb_SalesProjectChanged Then
'        If FoundUniqueSalesProject Then
'            mb_SalesProjectChanged = KO
'            Exit Sub
'        End If
'    End If
    gut_Param2.Str1 = "Quotation_Project"
    gut_Param.Str1 = ""
    gut_Param.Str2 = ""
    gut_Param.Str4 = "EXEC screen_csts 'Project_C_Sel','" & gut_LangLogin.Code & "'"
    'gut_Param2.Str3 = "EXEC screen_csts 'Mtnc_Claim_Cust','" & gut_LangWork.Code & "'"
    gut_Param.Str3 = " EXEC Sales_Project_del "
    C_Selection.s_OldCode = CStr(ml_SalesProjectCode)
    C_Selection.s_InitialLike = txt_SalesProject
    C_Selection.show 1
    If gb_Return = OK Then
        mb_SalesProjectChanged = KO
'        If mi_Action = QA_New Or mi_Action = QA_Copy Then
'            DefaultValues
'        End If
        
        ml_SalesProjectCode = CLng(gut_Param2.Str4)
        txt_SalesProject = gut_Param2.Str6
        
    End If
End Sub



Private Sub pic_Save_Click()
Dim lb_status As Boolean
Dim lb_End As Boolean

    If mb_SalesProjectLostFocus = OK Then Exit Sub
    If mb_CustomerLostFocus = OK Then Exit Sub
    
    If Control = KO Then Exit Sub
    
    MouseOff
    
    'Open a transaction
    BeginTran gl_Environment, gl_Database
            
    lb_End = KO
    
    On Error GoTo Pic_Save_Click_Err
            
    Select Case mi_Action
        Case QA_NewVersion
            
            'Modify the status of the last version in old version
            lb_status = Quotation_ChangeStatus(mi_QuotationCode, CInt(Txt_Version) - 1, 7)
            
            'Insert the new version
            If lb_status = OK Then lb_status = InsertNewVersion
            
            'Modify the status of the new version
            If lb_status = OK Then lb_status = Quotation_ChangeStatus(mi_QuotationCode, CInt(Txt_Version), mi_Q_StatusCode)
                
            'Duplicate the SalesReps
            If lb_status = OK Then lb_status = DuplicateSalesReps
            
            'Duplicate the lines
            If lb_status = OK Then lb_status = DuplicateLines(mi_QuotationCode, CInt(Txt_Version.Text) - 1, mi_QuotationCode, CInt(Txt_Version.Text))
            
            'Duplicate the comments
            If lb_status = OK Then lb_status = DuplicateComments(mi_QuotationCode, CInt(Txt_Version.Text) - 1, mi_QuotationCode, CInt(Txt_Version.Text))
            
            'Duplicate the products
            If lb_status = OK Then lb_status = DuplicateProducts(mi_QuotationCode, CInt(Txt_Version.Text) - 1, mi_QuotationCode, CInt(Txt_Version.Text))
            
            'Duplicates the new products
            If lb_status = OK Then lb_status = DuplicateNewProducts(mi_QuotationCode, CInt(Txt_Version.Text) - 1, mi_QuotationCode, CInt(Txt_Version.Text))
            
            'Duplicates the Metal products
            If lb_status = OK Then lb_status = DuplicateMetalProducts(mi_QuotationCode, CInt(Txt_Version.Text) - 1, mi_QuotationCode, CInt(Txt_Version.Text))
                
        Case QA_Update
        
            'Update the quotation
            lb_status = UpdateQuotation
            
            'Update the sales reps
            If lb_status = OK Then lb_status = UpdateSalesReps
            
        Case QA_StatusChange
        
            'Change the status
            lb_status = Quotation_ChangeStatus(mi_QuotationCode, CInt(Txt_Version), mi_QuotationStatusCode)
            
            'Update the quotation
            If lb_status = OK Then lb_status = UpdateQuotation
        
        Case QA_Copy
        
            'Insert the new quotation
            lb_status = InsertQuotation
            
            'Modify the status of the new version
            If lb_status = OK Then lb_status = Quotation_ChangeStatus(mi_QuotationCode, CInt(Txt_Version), mi_Q_StatusCode)
        
            'Duplicate the SalesReps
            If lb_status = OK Then lb_status = DuplicateSalesReps
            
            'Duplicate the lines
            If lb_status = OK Then lb_status = DuplicateLines(gi_QuotationCode, gi_QuotationVersion, mi_QuotationCode, mi_QuotationVersion)
            
            'Duplicate the comments
            If lb_status = OK Then lb_status = DuplicateComments(gi_QuotationCode, gi_QuotationVersion, mi_QuotationCode, mi_QuotationVersion)
            
            'Duplicate the products
            If lb_status = OK Then lb_status = DuplicateProducts(gi_QuotationCode, gi_QuotationVersion, mi_QuotationCode, mi_QuotationVersion)
            
            'Duplicates the new products
            If lb_status = OK Then lb_status = DuplicateNewProducts(gi_QuotationCode, gi_QuotationVersion, mi_QuotationCode, mi_QuotationVersion)
            
            'Duplicates the Metal products
            If lb_status = OK Then lb_status = DuplicateMetalProducts(gi_QuotationCode, gi_QuotationVersion, mi_QuotationCode, mi_QuotationVersion)
        
        Case Else 'QA_New
        
            'Insert the new quotation
            lb_status = InsertQuotation
            
            'Modify the status of the new version
            If lb_status = OK Then lb_status = Quotation_ChangeStatus(mi_QuotationCode, CInt(Txt_Version), mi_Q_StatusCode)
            
            'Duplicate the SalesReps
            If lb_status = OK Then lb_status = UpdateSalesReps
            
    End Select
    
    lb_End = OK
    
Pic_Save_Click_Err:
    
    'Close the transaction
    If lb_status = OK And lb_End = OK Then
        CommitTran gl_Environment, gl_Database
        mb_Return = OK
    Else
        RollbackTran gl_Environment, gl_Database
        mb_Return = KO
    End If

    'If one error occurs, send a message to the user
    If lb_status = KO Then
        Select Case mi_Action
            Case QA_New, QA_NewVersion
                SendMessage 4, "Insert failed", gut_LangLogin.Code
            Case QA_Update, QA_StatusChange
                SendMessage 3, "Update failed", gut_LangLogin.Code
        End Select
        MouseOn
    Else
        MouseOn
        Unload Me
    End If
    
    
End Sub

Private Sub pic_ToolBox_Click()
    If lst_toolbox.Visible = OK Then
        lst_toolbox.Visible = KO
    Else
        lst_toolbox.Visible = OK
        lst_toolbox.ListIndex = -1
        lst_toolbox.SetFocus
    End If
End Sub

Private Sub pic_UnDo_Click()
    MouseOff
    FillObjects mi_Action
    MouseOn
End Sub


Private Sub FillObjects(mi_What As QuotationAction)
Dim i As Integer

    If mi_What = QA_New Or mi_What = QA_Copy Then
        Txt_Code.Text = ""
        Txt_Version.Text = "1"
        mi_Q_StatusCode = Quotation_Status.opened
        txt_Status.Text = Quotation_Status_Desc(Quotation_Status.opened, "E")
    Else
        Txt_Code.Text = ms_QuotationDesc
        Txt_Version.Text = mi_QuotationVersion
        mi_Q_StatusCode = mi_QuotationStatusCode
        txt_Status.Text = mi_QuotationStatusDesc
    End If
    
    Lst_SalesReps.Clear
    For i = mo_Q_SalesRepsCode.Count To 1 Step -1
        mo_Q_SalesRepsCode.Remove i
    Next
    
    'If the salesrep are not loaded, we loaded there
    If mb_SalesRepLoaded = KO Then
        'We read the information of the actual quotation (not the new version if it is the case)
        Quotation_ReadSalesRep gi_QuotationCode, gi_QuotationVersion, mo_Q_SalesRepsCode, Lst_SalesReps
        
        For i = mo_SalesRepCode.Count To 1 Step -1
            mo_SalesRepCode.Remove i
            mo_SalesRepDesc.Remove i
        Next
        
        For i = 1 To mo_Q_SalesRepsCode.Count
            mo_SalesRepCode.Add mo_Q_SalesRepsCode.Item(i)
            mo_SalesRepDesc.Add Lst_SalesReps.List(i - 1)
        Next
        
        mb_SalesRepLoaded = OK
    Else
        For i = 1 To mo_SalesRepCode.Count
            Lst_SalesReps.AddItem mo_SalesRepDesc.Item(i)
            mo_Q_SalesRepsCode.Add mo_SalesRepCode.Item(i)
        Next
    End If
        
    If mi_What = QA_New Then
        Cbo_QuotationLanguage.Clear
        'Fill the combobox
        Cbo_QuotationLanguage_DropButtonClick
        MCombo_CodeSelect(Cbo_QuotationLanguage) = gut_LangLogin.Code
        
        cbo_currency.Clear
        
        ml_Q_CustomerCode = 0
        Txt_Customer.Text = ""
        
        cbo_DeliveryAddress.Clear
        
        cbo_Plant.Clear
        
        Cbo_LoseReason.Clear
        
        'Cbo_SalesProject.Clear
        
        Txt_Contractor.Text = ""
        
        Cbo_SalesOffice.Clear
        
        Txt_Creator.Text = prg.LoginName
        Txt_Approval.Text = ""
        Txt_ApprovalDate.Text = ""
        d_DeliveryDate.Reinit
        d_ValidityDate.Reinit
        Txt_SapOrder.Text = ""
        
        Txt_TotalSurface.Text = "0"
        Txt_TotalAmount.Text = "0"
        txt_LeadTime.Text = "0"
        
    Else
        'We write all the informations in input
        MCombo_AddItemCode Cbo_QuotationLanguage, ms_LanguageCode, ms_LanguageDesc
        MCombo_AddItemCode cbo_currency, ms_CurrencyCode, ms_currencyDesc
        
        ml_Q_CustomerCode = ml_ClaimCustomerCode
        Txt_Customer.Text = ms_ClaimCustomerDesc
        
        If ms_DeliveryAddressDesc <> "" Then MCombo_AddItemCode cbo_DeliveryAddress, mi_DeliveryAddressCode, ms_DeliveryAddressDesc
        If ms_PlantDesc <> "" Then MCombo_AddItemCode cbo_Plant, ms_PlantCode, ms_PlantDesc
        If ms_LoseReasonDesc <> "" Then MCombo_AddItemCode Cbo_LoseReason, mi_LoseReasonCode, ms_LoseReasonDesc
        If ms_SalesProjectDesc <> "" Then txt_SalesProject = ms_SalesProjectDesc 'MCombo_AddItemCode Cbo_SalesProject, ml_SalesProjectCode, ms_SalesProjectDesc
        
        MCombo_AddItemCode Cbo_SalesOffice, ms_SalesOfficeCode, ms_SalesOfficeDesc
        
        Txt_Creator.Text = ms_Creator
        Txt_Approval.Text = ms_Approval
        Txt_ApprovalDate.Text = ms_ApprovalDate
        Txt_Contractor.Text = ms_Contractor
        d_DeliveryDate.SetDate = ms_DeliveryDate
        d_ValidityDate.SetDate = ms_ValidityDate
        Txt_SapOrder.Text = ms_SAPOrder
        If ml_TotalSurface <> 0 Then
            Txt_TotalSurface.Text = CStr(ml_TotalSurface)
        Else
            Txt_TotalSurface.Text = "0"
        End If
        If mr_TotalAmount <> 0 Then
            Txt_TotalAmount.Text = CStr(mr_TotalAmount)
        Else
            Txt_TotalAmount.Text = "0"
        End If
        If mr_LeadTime <> 0 Then
            txt_LeadTime.Text = CStr(mr_LeadTime)
        Else
            txt_LeadTime.Text = "0"
        End If

    End If
End Sub

Private Sub DisableObjects(mi_What As ObjectList)

    Select Case mi_What
        Case OL_Language, QL_Status_Waiting_Plant_Confirmation, QL_Status_Send_to_customer, QL_Status_Refused_Notify_Customer, QL_Status_Closed, QL_Status_Waiting_Customer_Confirmation, QL_Status_Enter_Customer_order, QL_Status_Ordered_to_Plant, QL_Status_Archived, QL_Status_Customer_Changes_Quotation, IIf(mi_What = OL_Update And mi_QuotationStatusCode = Quotation_Status.Archived, 3, 0)
            
            lbl_Plant.Enabled = KO
            cbo_Plant.Enabled = KO
        
            Lbl_SalesProject.Enabled = KO
            'Cbo_SalesProject.Enabled = KO
            Pic_SalesProject.Enabled = KO
            Pic_SalesProject.Picture = LoadResPicture(RES_COMBOCOPYGRAY, 1)
            txt_SalesProject.Enabled = KO
        
            Lbl_SalesOffice.Enabled = KO
            Cbo_SalesOffice.Enabled = KO
    
            Lbl_Currency.Enabled = KO
            cbo_currency.Enabled = KO
    
            Lbl_ValidityDate.Enabled = KO
            d_ValidityDate.Enabled = KO
    
            Lbl_SalesReps.Enabled = KO
            Lst_SalesReps.Enabled = KO
            Btn_UpdSalesRep.Enabled = KO
        
            Lbl_DeliveryAddress.Enabled = KO
            cbo_DeliveryAddress.Enabled = KO
            
            Lbl_Contractor.Enabled = KO
            Txt_Contractor.Enabled = KO
            
        Case Else
            lbl_Plant.Enabled = OK
            cbo_Plant.Enabled = OK
    
            Lbl_SalesProject.Enabled = OK
            'Cbo_SalesProject.Enabled = OK
            Pic_SalesProject.Enabled = OK
            Pic_SalesProject.Picture = LoadResPicture(RES_COMBOCOPY, 1)
            txt_SalesProject.Enabled = OK
            
            Lbl_SalesOffice.Enabled = OK
            Cbo_SalesOffice.Enabled = OK
            
            Lbl_Currency.Enabled = OK
            cbo_currency.Enabled = OK
    
            Lbl_ValidityDate.Enabled = OK
            d_ValidityDate.Enabled = OK
    
            Lbl_SalesReps.Enabled = OK
            Lst_SalesReps.Enabled = OK
            Btn_UpdSalesRep.Enabled = OK
        
            Lbl_DeliveryAddress.Enabled = OK
            cbo_DeliveryAddress.Enabled = OK
               
            Lbl_Contractor.Enabled = OK
            Txt_Contractor.Enabled = OK
               
    End Select
    
    If mi_What = OL_New Or mi_What = OL_Language Then
        Lbl_QuotationLanguage.Enabled = OK
        Cbo_QuotationLanguage.Enabled = OK
    Else
        Lbl_QuotationLanguage.Enabled = KO
        Cbo_QuotationLanguage.Enabled = KO
    End If
    
    If mi_What = QL_Status_Closed Then
        Lbl_LoseReason.Enabled = OK
        Cbo_LoseReason.Enabled = OK
    Else
        Lbl_LoseReason.Enabled = KO
        Cbo_LoseReason.Enabled = KO
    End If
        
    If mi_What = OL_New Or mi_What = OL_NewVersion Or mi_What = QL_Status_Waiting_Plant_Confirmation Or mi_What = QL_Status_Enter_Customer_order Or (mi_What = OL_Update And mi_QuotationStatusCode <> Quotation_Status.Archived And mi_QuotationStatusCode <> Quotation_Status.Customer_changes_Quotation) Then
        Lbl_DeliveryDate.Enabled = OK
        d_DeliveryDate.Enabled = OK
    Else
        Lbl_DeliveryDate.Enabled = KO
        d_DeliveryDate.Enabled = KO
    End If
    
    If mi_What = QL_Status_Enter_Customer_order Or (mi_What = OL_Update And mi_QuotationStatusCode = Quotation_Status.Archived) Then
        Lbl_SapOrder.Enabled = OK
        Txt_SapOrder.Enabled = OK
    Else
        Lbl_SapOrder.Enabled = KO
        Txt_SapOrder.Enabled = KO
    End If
    
    If mi_What = OL_New Or (mi_What = OL_Update And mi_QuotationStatusCode = Quotation_Status.opened) Then
        Lbl_Customer.Enabled = OK
        Txt_Customer.Enabled = OK
        Pic_Customer.Enabled = OK
        Pic_Customer.Picture = LoadResPicture(RES_COMBOCOPY, 1)
    Else
        Lbl_Customer.Enabled = KO
        Txt_Customer.Enabled = KO
        Pic_Customer.Enabled = KO
        Pic_Customer.Picture = LoadResPicture(RES_COMBOCOPYGRAY, 1)
    End If
    
End Sub

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

    InsertNewVersion = KO

    On Error GoTo InsertNewVersion_Err

    ls_Req = "exec Quotation_ins2 " & CStr(mi_QuotationCode)
    ls_Req = ls_Req & "," & CStr(mi_QuotationVersion)
    ls_Req = ls_Req & "," & CStr(ml_Q_CustomerCode)
    ls_Req = ls_Req & "," & CStr(ml_ClaimCustomerCode)
    If cbo_DeliveryAddress.ListIndex <> -1 Then
        ls_Req = ls_Req & "," & CStr(MCombo_GetCode(cbo_DeliveryAddress))
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If cbo_Plant.ListIndex <> -1 And cbo_Plant.value <> "" Then
        ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_Plant) & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If Cbo_LoseReason.ListIndex <> -1 Then
        ls_Req = ls_Req & "," & CStr(MCombo_GetCode(Cbo_LoseReason))
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If ml_SalesProjectCode <> 0 Then
        ls_Req = ls_Req & "," & ml_SalesProjectCode
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    ls_Req = ls_Req & ",'" & MCombo_GetCode(Cbo_SalesOffice) & "'"
    ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_currency) & "'"
    ls_Req = ls_Req & ",'" & Txt_Code & "'"
    ls_Req = ls_Req & ",'" & MCombo_GetCode(Cbo_QuotationLanguage) & "'"
    ls_Req = ls_Req & ",'" & Txt_Creator.Text & "'"
    ls_Req = ls_Req & ",'" & Txt_Approval.Text & "'"
    ls_Req = ls_Req & ",'" & QuoteParam(Txt_Contractor.Text) & "'"
    If d_DeliveryDate.GetUSDate <> "" Then
        ls_Req = ls_Req & ",'" & d_DeliveryDate.GetUSDate & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If d_ValidityDate.GetUSDate <> "" Then
        ls_Req = ls_Req & ",'" & d_ValidityDate.GetUSDate & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    
    If Txt_ApprovalDate.Text <> "" Then
        ls_Req = ls_Req & ",'" & FormatD(Txt_ApprovalDate.Text, "mm/dd/yyyy") & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    ls_Req = ls_Req & ",'" & QuoteParam(Txt_SapOrder.Text) & "'"
    'JC BEGIN
    If Txt_TotalSurface.Text <> "" Then
        ls_Req = ls_Req & "," & Txt_TotalSurface.Text
    Else
        ls_Req = ls_Req & "," & "0"
    End If
    If Txt_TotalAmount.Text <> "" Then
        ls_Req = ls_Req & "," & Formatage2(Txt_TotalAmount.Text)
    Else
        ls_Req = ls_Req & "," & "0"
    End If
    If txt_LeadTime.Text <> "" Then
        ls_Req = ls_Req & "," & Formatage2(txt_LeadTime.Text)
    Else
        ls_Req = ls_Req & "," & "0"
    End If
    'JC BEGIN
    ls_Req = ls_Req & "," & CStr(mi_Q_StatusCode)
    ls_Req = ls_Req & ",''"
    ls_Req = ls_Req & ",'',NULL"
    
    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
        'Get the row of data
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                mi_QuotationCode = Formatage2(ODBCDataInt(ll_Statement, 1))
                ms_QuotationDesc = ODBCData(ll_Statement, 2)
            End If
        Loop
        
        SQLFreeStatement ll_Statement, SQL_DROP
        
        InsertNewVersion = OK
    End If
    SQLFreeStatement ll_Statement, SQL_DROP

    Exit Function

InsertNewVersion_Err:
    SQLFreeStatement ll_Statement, SQL_DROP
    StdError
End Function

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

    InsertQuotation = KO

    On Error GoTo InsertQuotation_Err

    ls_Req = "exec Quotation_ins "
    ls_Req = ls_Req & CStr(ml_Q_CustomerCode)
    If cbo_DeliveryAddress.ListIndex <> -1 Then
        ls_Req = ls_Req & "," & CStr(MCombo_GetCode(cbo_DeliveryAddress))
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If cbo_Plant.ListIndex <> -1 And cbo_Plant.value <> "" Then
        ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_Plant) & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If Cbo_LoseReason.ListIndex <> -1 Then
        ls_Req = ls_Req & "," & CStr(MCombo_GetCode(Cbo_LoseReason))
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If ml_SalesProjectCode <> 0 Then
        ls_Req = ls_Req & "," & CStr(ml_SalesProjectCode)
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    ls_Req = ls_Req & ",'" & MCombo_GetCode(Cbo_SalesOffice) & "'"
    ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_currency) & "'"
    ls_Req = ls_Req & ",'" & MCombo_GetCode(Cbo_QuotationLanguage) & "'"
    ls_Req = ls_Req & ",'" & Txt_Creator.Text & "'"
    ls_Req = ls_Req & ",'" & Txt_Approval.Text & "'"
    ls_Req = ls_Req & ",'" & QuoteParam(Txt_Contractor.Text) & "'"
    If d_DeliveryDate.GetUSDate <> "" Then
        ls_Req = ls_Req & ",'" & d_DeliveryDate.GetUSDate & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If d_ValidityDate.GetUSDate <> "" Then
        ls_Req = ls_Req & ",'" & d_ValidityDate.GetUSDate & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    
    If Txt_ApprovalDate.Text <> "" Then
        ls_Req = ls_Req & ",'" & FormatD(Txt_ApprovalDate.Text, "mm/dd/yyyy") & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    ls_Req = ls_Req & ",'" & QuoteParam(Txt_SapOrder.Text) & "'"
    ls_Req = ls_Req & ",0"
    ls_Req = ls_Req & ",0"
    ls_Req = ls_Req & ",0"
    ls_Req = ls_Req & "," & CStr(mi_Q_StatusCode)
    ls_Req = ls_Req & ",''"
    ls_Req = ls_Req & ",'',NULL"
    
    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
        'Get the row of data
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                mi_QuotationCode = Formatage2(ODBCDataInt(ll_Statement, 1))
                ms_QuotationDesc = ODBCData(ll_Statement, 2)
                mi_QuotationVersion = 1
            End If
        Loop
        
        SQLFreeStatement ll_Statement, SQL_DROP
    
        InsertQuotation = OK
    
    End If
    
    Exit Function

InsertQuotation_Err:
    SQLFreeStatement ll_Statement, SQL_DROP
    StdError
End Function

Private Function DuplicateLines(li_ReferenceQuotationCode As Integer, li_ReferenceQuotationVersion As Integer, li_DestinationQuotationCode As Integer, li_DestinationQuotationVersion As Integer) As Boolean
Dim ls_Req As String
Dim ll_Statement As Long

    DuplicateLines = KO

    On Error GoTo DuplicateLines_Err

    ls_Req = "exec Quot_Line_ins2 " & CStr(li_ReferenceQuotationCode) & "," & CStr(li_ReferenceQuotationVersion) & "," & CStr(li_DestinationQuotationCode) & "," & CStr(li_DestinationQuotationVersion)
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        DuplicateLines = OK
    
        SQLFreeStatement ll_Statement, SQL_DROP
    End If

    Exit Function

DuplicateLines_Err:
    SQLFreeStatement ll_Statement, SQL_DROP
    StdError
End Function

Private Function DuplicateComments(li_ReferenceQuotationCode As Integer, li_ReferenceQuotationVersion As Integer, li_DestinationQuotationCode As Integer, li_DestinationQuotationVersion As Integer) As Boolean
Dim ls_Req As String
Dim ll_Statement As Long

    DuplicateComments = KO

    On Error GoTo DuplicateComments_Err

    ls_Req = "exec Quot_CommentLine_ins2 " & CStr(li_ReferenceQuotationCode) & "," & CStr(li_ReferenceQuotationVersion) & "," & CStr(li_DestinationQuotationCode) & "," & CStr(li_DestinationQuotationVersion)
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        DuplicateComments = OK
    
        SQLFreeStatement ll_Statement, SQL_DROP
    End If

    Exit Function

DuplicateComments_Err:
    SQLFreeStatement ll_Statement, SQL_DROP
    StdError
End Function

Private Function DuplicateProducts(li_ReferenceQuotationCode As Integer, li_ReferenceQuotationVersion As Integer, li_DestinationQuotationCode As Integer, li_DestinationQuotationVersion As Integer) As Boolean
Dim ls_Req As String
Dim ll_Statement As Long

    DuplicateProducts = KO

    On Error GoTo DuplicateProducts_Err

    ls_Req = "exec Quot_Product_ins2 " & CStr(li_ReferenceQuotationCode) & "," & CStr(li_ReferenceQuotationVersion) & "," & CStr(li_DestinationQuotationCode) & "," & CStr(li_DestinationQuotationVersion)
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        DuplicateProducts = OK
    
        SQLFreeStatement ll_Statement, SQL_DROP
    End If

    Exit Function

DuplicateProducts_Err:
    SQLFreeStatement ll_Statement, SQL_DROP
    StdError
End Function

Private Function DuplicateNewProducts(li_ReferenceQuotationCode As Integer, li_ReferenceQuotationVersion As Integer, li_DestinationQuotationCode As Integer, li_DestinationQuotationVersion As Integer) As Boolean
Dim ls_Req As String
Dim ll_Statement As Long

    DuplicateNewProducts = KO

    On Error GoTo DuplicateNewProducts_Err

    ls_Req = "exec Quot_NewProduct_ins2 " & CStr(li_ReferenceQuotationCode) & "," & CStr(li_ReferenceQuotationVersion) & "," & CStr(li_DestinationQuotationCode) & "," & CStr(li_DestinationQuotationVersion)
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        DuplicateNewProducts = OK
    
        SQLFreeStatement ll_Statement, SQL_DROP
    End If

    Exit Function

DuplicateNewProducts_Err:
    SQLFreeStatement ll_Statement, SQL_DROP
    StdError
End Function

Private Function DuplicateMetalProducts(li_ReferenceQuotationCode As Integer, li_ReferenceQuotationVersion As Integer, li_DestinationQuotationCode As Integer, li_DestinationQuotationVersion As Integer) As Boolean
Dim ls_Req As String
Dim ll_Statement As Long

    DuplicateMetalProducts = KO

    On Error GoTo DuplicateMetalProducts_Err

    ls_Req = "exec Quot_MetalProduct_ins2 " & CStr(li_ReferenceQuotationCode) & "," & CStr(li_ReferenceQuotationVersion) & "," & CStr(li_DestinationQuotationCode) & "," & CStr(li_DestinationQuotationVersion)
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
        DuplicateMetalProducts = OK
    
        SQLFreeStatement ll_Statement, SQL_DROP
    End If

    Exit Function

DuplicateMetalProducts_Err:
    SQLFreeStatement ll_Statement, SQL_DROP
    StdError
End Function

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

    UpdateQuotation = KO
    
    On Error GoTo UpdateQuotation_Err
    
    ls_Req = "exec Quotation_upd "
    ls_Req = ls_Req & CStr(mi_QuotationCode)
    ls_Req = ls_Req & "," & CStr(mi_QuotationVersion)
    ls_Req = ls_Req & ",'" & QuoteParam(ms_QuotationDesc) & "'"
    ls_Req = ls_Req & "," & CStr(ml_ClaimCustomerCode)
    ls_Req = ls_Req & "," & CStr(ml_Q_CustomerCode)
    If cbo_DeliveryAddress.ListIndex <> -1 Then
        ls_Req = ls_Req & "," & CStr(MCombo_GetCode(cbo_DeliveryAddress))
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If cbo_Plant.ListIndex <> -1 And cbo_Plant.value <> "" Then
        ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_Plant) & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If Cbo_LoseReason.ListIndex <> -1 Then
        ls_Req = ls_Req & "," & CStr(MCombo_GetCode(Cbo_LoseReason))
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If ml_SalesProjectCode <> 0 Then
        ls_Req = ls_Req & "," & CStr(ml_SalesProjectCode)
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    ls_Req = ls_Req & ",'" & MCombo_GetCode(Cbo_SalesOffice) & "'"
    ls_Req = ls_Req & ",'" & MCombo_GetCode(cbo_currency) & "'"
    ls_Req = ls_Req & ",'" & MCombo_GetCode(Cbo_QuotationLanguage) & "'"
    ls_Req = ls_Req & ",'" & Txt_Approval.Text & "'"
    ls_Req = ls_Req & ",'" & QuoteParam(Txt_Contractor.Text) & "'"
    If d_DeliveryDate.GetUSDate <> "" Then
        ls_Req = ls_Req & ",'" & d_DeliveryDate.GetUSDate & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    
    If d_ValidityDate.GetUSDate <> "" Then
        ls_Req = ls_Req & ",'" & d_ValidityDate.GetUSDate & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    If Txt_ApprovalDate.Text <> "" Then
        ls_Req = ls_Req & ",'" & FormatD(Txt_ApprovalDate.Text, "mm/dd/yyyy") & "'"
    Else
        ls_Req = ls_Req & ",NULL"
    End If
    ls_Req = ls_Req & ",'" & QuoteParam(Txt_SapOrder.Text) & "'"
    ls_Req = ls_Req & "," & CStr(mi_iConcurrency)
    
    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
        'Get the row of data
            li_Status = SQLFetch(ll_Statement)
            If li_Status = SQL_SUCCESS Or li_Status = SQL_SUCCESS_WITH_INFO Then
                mi_QuotationCode = Formatage2(ODBCDataInt(ll_Statement, 1))
                ms_QuotationDesc = ODBCData(ll_Statement, 2)
            End If
        Loop
        
        SQLFreeStatement ll_Statement, SQL_DROP
        
        UpdateQuotation = OK
    
    End If
    
    Exit Function
    
UpdateQuotation_Err:
    SQLFreeStatement ll_Statement, SQL_DROP
End Function

Private Function DuplicateSalesReps() As Boolean
Dim i As Integer

    DuplicateSalesReps = KO
    
    On Error GoTo DuplicateSalesReps_Err
    
    For i = 1 To mo_Q_SalesRepsCode.Count
        If AddSalesReps(mo_Q_SalesRepsCode.Item(i)) = KO Then Exit Function
    Next
    
    DuplicateSalesReps = OK
    
    Exit Function
    
DuplicateSalesReps_Err:

End Function

Private Function UpdateSalesReps() As Boolean
Dim i As Integer
Dim j As Integer
Dim lb_Found As Boolean

    UpdateSalesReps = KO
    
    On Error GoTo UpdateSalesReps_Err
    
    For i = mo_SalesRepCode.Count To 1 Step -1
        lb_Found = KO
        For j = 1 To mo_Q_SalesRepsCode.Count
            If mo_SalesRepCode.Item(i) = mo_Q_SalesRepsCode.Item(j) Then
                lb_Found = OK
                Exit For
            End If
        Next
        If lb_Found = KO Then
            If DeleteSalesReps(mo_SalesRepCode.Item(i)) = KO Then Exit Function
            mo_SalesRepCode.Remove i
            mo_SalesRepDesc.Remove i
        End If
    Next
    
    For i = mo_Q_SalesRepsCode.Count To 1 Step -1
        lb_Found = KO
        For j = 1 To mo_SalesRepCode.Count
            If mo_Q_SalesRepsCode.Item(i) = mo_SalesRepCode.Item(j) Then
                lb_Found = OK
                Exit For
            End If
        Next
        If lb_Found = KO Then
            If AddSalesReps(mo_Q_SalesRepsCode.Item(i)) = KO Then Exit Function
            mo_SalesRepCode.Add mo_Q_SalesRepsCode.Item(i)
            mo_SalesRepDesc.Add Lst_SalesReps.List(i - 1)
        End If
    Next
  
    UpdateSalesReps = OK
    
    Exit Function
    
UpdateSalesReps_Err:

End Function

Private Function AddSalesReps(lo_code As String) As Boolean
Dim ll_Statement As Long
Dim ls_Req As String

    AddSalesReps = KO
    
    On Error GoTo AddSalesReps_Err
    
    ls_Req = "Exec Quot_SalesReps_ins " & CStr(mi_QuotationCode) & "," & CStr(mi_QuotationVersion) & ",'" & lo_code & "'"
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
    
        AddSalesReps = OK
        SQLFreeStatement ll_Statement, SQL_DROP
    End If
    
    Exit Function

AddSalesReps_Err:
    SQLFreeStatement ll_Statement, SQL_DROP

End Function

Private Function DeleteSalesReps(lo_code As String) As Boolean
Dim ll_Statement As Long
Dim ls_Req As String

    DeleteSalesReps = KO
    
    On Error GoTo DeleteSalesReps_Err
    
    ls_Req = "Exec Quot_SalesReps_del " & CStr(mi_QuotationCode) & "," & CStr(mi_QuotationVersion) & ",'" & lo_code & "'"
    
    If SQLSubmit(gl_Environment, gl_Database, ll_Statement, ls_Req) Then
    
        DeleteSalesReps = OK
        SQLFreeStatement ll_Statement, SQL_DROP
    End If
    
    Exit Function
    
DeleteSalesReps_Err:
    SQLFreeStatement ll_Statement, SQL_DROP

End Function

Private Sub GetCaptions()
Dim ls_Field As String
Dim ls_Text As String
Dim ll_Statement As Long
Dim li_Status As Integer
Dim ls_Req As String

    On Error GoTo suite
    ls_Req = "EXEC Screen_Csts 'Quot_gen_mtnc', '" & 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": Quot_General_mtnc.Caption = ls_Text
                Case "lbl_code": lbl_Code.Caption = ls_Text
                Case "lbl_version": lbl_Version.Caption = ls_Text
                Case "lbl_status": lbl_Status.Caption = ls_Text
                Case "lbl_qlanguage": Lbl_QuotationLanguage.Caption = ls_Text
                Case "lbl_creator": Lbl_Creator.Caption = ls_Text
                Case "lbl_approval": Lbl_Approval.Caption = ls_Text
                Case "lbl_appdate": Lbl_ApprovalDate.Caption = ls_Text
                Case "lbl_customer": Lbl_Customer.Caption = ls_Text
                Case "lbl_salesproject":
                        Lbl_SalesProject.Caption = ls_Text
'                        If lst_toolbox.ListCount = 0 Then
'                            lst_toolbox.AddItem ls_Text
'                            lst_toolbox.ItemData(lst_toolbox.NewIndex) = 1
'                        End If
                Case "lbl_delivaddress": Lbl_DeliveryAddress.Caption = ls_Text
                Case "lbl_currency": Lbl_Currency.Caption = ls_Text
                Case "lbl_totsurface": Lbl_TotalSurface.Caption = ls_Text
                Case "lbl_totamount": Lbl_TotalAmount.Caption = ls_Text
                Case "lbl_leadtime": lbl_leadTime.Caption = ls_Text
                Case "lbl_defplant": lbl_Plant.Caption = ls_Text
                Case "lbl_expdeldate": Lbl_DeliveryDate.Caption = ls_Text
                Case "lbl_valdate": Lbl_ValidityDate.Caption = ls_Text
                Case "lbl_salesoff": Lbl_SalesOffice.Caption = ls_Text
                Case "btn_salesreps": Lbl_SalesReps.Caption = ls_Text
                Case "lbl_losereason": Lbl_LoseReason.Caption = ls_Text
                Case "lbl_saporder": Lbl_SapOrder.Caption = ls_Text
                Case "lbl_Contractor": Lbl_Contractor.Caption = ls_Text
            End Select
        End If
    Loop
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
    Exit Sub
suite:
    StdError
    li_Status = SQLFreeStatement(ll_Statement, SQL_DROP)
End Sub







Private Sub Txt_Customer_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode >= 65 Or KeyCode = 32 Or KeyCode = 8 Then
        mb_CustomerChanged = OK
    End If
End Sub

Private Sub Txt_Customer_LostFocus()
Dim lb_SaveClick As Boolean

    If LCase(Me.ActiveControl.Name) = "pic_quit" Then Exit Sub

    If mb_SalesProjectLostFocus Then Exit Sub
    
    lb_SaveClick = KO
    mb_CustomerLostFocus = OK
    
    If LCase(Me.ActiveControl.Name) = "Pic_Quit" Then Exit Sub
    If LCase(Me.ActiveControl.Name) = "pic_Save" Then lb_SaveClick = OK
    
    If mb_CustomerChanged Then
        If Trim(Txt_Customer) <> "" Then
            If Not FoundUniqueCustomer Then
                gut_Param2.Str1 = "Quotation_Customer"
                gut_Param.Str1 = "SAP"
                gut_Param.Str2 = "Quotation"
                gut_Param.Str4 = "EXEC screen_csts 'Cust_sel','" & gut_LangLogin.Code & "'"
                gut_Param2.Str3 = "EXEC screen_csts 'Mtnc_Claim_Cust','" & gut_LangWork.Code & "'"
                gut_Param.Str3 = " EXEC Claim_Customer_del "
                C_Selection.s_OldCode = CStr(ml_Q_CustomerCode)
                C_Selection.s_InitialLike = Txt_Customer
                C_Selection.show 1
                If gb_Return = OK Then
                    If mi_Action = QA_New Or mi_Action = QA_Copy Then
                        DefaultValues
                    End If
            
                    ml_Q_CustomerCode = CLng(gut_Param2.Str4)
                    Txt_Customer.Text = gut_Param2.Str6
                    mb_CustomerChanged = KO
                    mb_CustomerLostFocus = KO
                    If lb_SaveClick = OK Then pic_Save_Click
                End If
            Else
                mb_CustomerChanged = KO
                mb_CustomerLostFocus = KO
                If lb_SaveClick = OK Then pic_Save_Click
            End If
        End If
    End If
    
    mb_CustomerLostFocus = KO
End Sub

Private Sub txt_SalesProject_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode >= 65 Or KeyCode = 32 Or KeyCode = 8 Then
        ' 16 shift, 20 ctrl, 18 ALt, 17 Alt gr, 13 return, 37,38,39 fleches
        ' 32 space
        mb_SalesProjectChanged = OK
        ml_SalesProjectCode = 0
    End If
End Sub

Private Sub txt_SalesProject_LostFocus()
'    If mb_SalesProjectChanged Then
'        If FoundUniqueSalesProject Then
'            mb_SalesProjectChanged = KO
'        End If
'    End If
    
    Dim lb_SaveClick As Boolean

    If LCase(Me.ActiveControl.Name) = "pic_quit" Then Exit Sub
    If mb_CustomerLostFocus Then Exit Sub
    
    mb_SalesProjectLostFocus = OK
    lb_SaveClick = KO
    
    
    If LCase(Me.ActiveControl.Name) = "Pic_Quit" Then Exit Sub
    If LCase(Me.ActiveControl.Name) = "pic_Save" Then lb_SaveClick = OK
    
    If mb_SalesProjectChanged Then
        If Trim(txt_SalesProject) <> "" Then
            If Not FoundUniqueSalesProject Then
                gut_Param2.Str1 = "Quotation_Project"
                gut_Param.Str1 = ""
                gut_Param.Str2 = ""
                gut_Param.Str4 = "EXEC screen_csts 'Project_C_Sel','" & gut_LangLogin.Code & "'"
                gut_Param.Str3 = " EXEC Sales_Project_del "
                C_Selection.s_OldCode = CStr(ml_SalesProjectCode)
                C_Selection.s_InitialLike = txt_SalesProject
                C_Selection.show 1
                If gb_Return = OK Then
                    mb_SalesProjectChanged = KO
                    mb_SalesProjectLostFocus = KO
                    ml_SalesProjectCode = CLng(gut_Param2.Str4)
                    txt_SalesProject = gut_Param2.Str6
                    If lb_SaveClick = OK Then pic_Save_Click
                End If
            Else
                mb_SalesProjectChanged = KO
                mb_SalesProjectLostFocus = KO
                If lb_SaveClick = OK Then pic_Save_Click
            End If
        End If
    End If
    mb_SalesProjectLostFocus = KO
            
End Sub
