VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "mscomctl.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "ComDlg32.OCX"
Begin VB.UserControl CapOffer 
   ClientHeight    =   11475
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   19455
   ScaleHeight     =   11475
   ScaleWidth      =   19455
   Tag             =   "Cap_Offer"
   Begin VB.Frame fraItem 
      Height          =   11280
      Left            =   435
      TabIndex        =   39
      Tag             =   "fraItem"
      Top             =   90
      Width           =   16485
      Begin VB.Frame fraItemTop 
         Height          =   8505
         Left            =   150
         TabIndex        =   44
         Tag             =   "fraItemTop"
         Top             =   975
         Width           =   16305
         Begin VB.Frame fra_Progress 
            Height          =   855
            Left            =   3990
            TabIndex        =   292
            Tag             =   "fra_Progress"
            Top             =   4320
            Visible         =   0   'False
            Width           =   6630
            Begin MSComctlLib.ProgressBar pgb_Progress 
               Height          =   300
               Left            =   225
               TabIndex        =   293
               Top             =   195
               Width           =   6210
               _ExtentX        =   10954
               _ExtentY        =   529
               _Version        =   393216
               BorderStyle     =   1
               Appearance      =   0
            End
            Begin VB.Label lbl_Progress 
               Height          =   255
               Left            =   195
               TabIndex        =   294
               Top             =   525
               Width           =   1245
            End
         End
         Begin VB.Frame fra_Header 
            Height          =   1395
            Index           =   0
            Left            =   240
            TabIndex        =   75
            Tag             =   "fra_Header"
            Top             =   2070
            Width           =   2505
            Begin Project1.A_calocx cal_COF_WshDat 
               Height          =   360
               Left            =   1515
               TabIndex        =   9
               Tag             =   "COF_WshDat"
               Top             =   1170
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   635
            End
            Begin Project1.A_calocx cal_COF_ShpDat 
               Height          =   360
               Left            =   4875
               TabIndex        =   10
               Tag             =   "COF_ShpDat"
               Top             =   1170
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   635
            End
            Begin Project1.A_calocx cal_COF_DelDat 
               Height          =   360
               Left            =   8055
               TabIndex        =   11
               Tag             =   "COF_DelDat"
               Top             =   1170
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   635
            End
            Begin Project1.A_calocx cal_COF_FoDat 
               Height          =   360
               Left            =   1515
               TabIndex        =   13
               Top             =   1500
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   635
            End
            Begin Project1.A_calocx cal_COF_ExDat 
               Height          =   345
               Left            =   4875
               TabIndex        =   14
               Top             =   1515
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   609
            End
            Begin Project1.A_calocx cal_COF_ApDat 
               Height          =   345
               Left            =   8055
               TabIndex        =   15
               Top             =   1515
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   609
            End
            Begin VB.CommandButton cmd_Info 
               Caption         =   "Info"
               Enabled         =   0   'False
               Height          =   300
               Left            =   8805
               TabIndex        =   271
               Tag             =   "cmd_Info"
               Top             =   2865
               Visible         =   0   'False
               Width           =   1245
            End
            Begin VB.CommandButton btn_ChangeUoM_M2 
               Caption         =   "Change to M2"
               Height          =   300
               Left            =   7500
               TabIndex        =   267
               Tag             =   "btn_ChangeUoM_M2"
               Top             =   2865
               Visible         =   0   'False
               Width           =   1320
            End
            Begin VB.CommandButton btn_ChangeUoM_PCS 
               Caption         =   "Change to PCS"
               Height          =   300
               Left            =   6195
               TabIndex        =   266
               Tag             =   "btn_ChangeUoM_PCS"
               Top             =   2865
               Visible         =   0   'False
               Width           =   1320
            End
            Begin VB.CommandButton btn_ExportSalesOrderCancelAddReplace 
               Caption         =   "Exports SO change"
               Enabled         =   0   'False
               Height          =   300
               Left            =   4185
               TabIndex        =   170
               Tag             =   "btn_ExportSOCancelAddReplace"
               Top             =   2865
               Width           =   2025
            End
            Begin VB.CommandButton btn_ExportActionDelete 
               Caption         =   "Action Delete"
               Height          =   300
               Left            =   9000
               TabIndex        =   173
               Top             =   3435
               Visible         =   0   'False
               Width           =   1185
            End
            Begin VB.CommandButton btn_ExportActionReplace 
               Caption         =   "Action Replace"
               Height          =   300
               Left            =   7785
               TabIndex        =   172
               Top             =   3435
               Visible         =   0   'False
               Width           =   1230
            End
            Begin VB.CommandButton btn_ExportActionAdd 
               Caption         =   "Action Add"
               Height          =   300
               Left            =   6615
               TabIndex        =   171
               Top             =   3435
               Visible         =   0   'False
               Width           =   1185
            End
            Begin VB.CommandButton btn_ExportSalesOrderCreateSim 
               Caption         =   "Export SO simulate"
               Height          =   300
               Left            =   2625
               TabIndex        =   217
               Tag             =   "btn_ExportSalesOrderCreateSim"
               Top             =   2865
               Width           =   1575
            End
            Begin VB.CommandButton btn_OfferCodeReset 
               Caption         =   "X"
               Height          =   360
               Left            =   12585
               TabIndex        =   188
               Tag             =   "_btn_OfferCodeReset"
               Top             =   180
               Width           =   300
            End
            Begin VB.TextBox txt_OfferMargin 
               Height          =   360
               Left            =   10695
               TabIndex        =   30
               TabStop         =   0   'False
               Tag             =   "txt_OfferMargin"
               Top             =   2505
               Width           =   705
            End
            Begin VB.CommandButton btn_ExportActionDeleteCancelPrereservation 
               Caption         =   "Action Delete and Cancel prereservation"
               Height          =   300
               Left            =   10185
               TabIndex        =   184
               Top             =   3435
               Visible         =   0   'False
               Width           =   3075
            End
            Begin VB.CommandButton btn_ExportActionReset 
               Caption         =   "Action Reset"
               Height          =   300
               Left            =   13275
               TabIndex        =   174
               Top             =   3435
               Visible         =   0   'False
               Width           =   1185
            End
            Begin VB.CommandButton btn_ExportSalesOrderCreate 
               Caption         =   "Export SO"
               Height          =   300
               Left            =   1320
               TabIndex        =   169
               Tag             =   "btn_ExportSalesOrderCreate"
               Top             =   2865
               Width           =   1320
            End
            Begin VB.CommandButton btn_ExportMaterialCreate 
               Caption         =   "Export materials"
               Height          =   300
               Left            =   60
               TabIndex        =   168
               Tag             =   "btn_ExportMaterialCreate"
               Top             =   2865
               Width           =   1275
            End
            Begin VB.Frame fra_OfferPriority 
               Caption         =   "#Offer priority"
               Height          =   615
               Left            =   4875
               TabIndex        =   26
               Tag             =   "fra_OfferPriority"
               Top             =   2265
               Width           =   4665
               Begin VB.OptionButton opt_OfferPriority 
                  Caption         =   "#Topspeed"
                  Height          =   390
                  Index           =   2
                  Left            =   3045
                  TabIndex        =   29
                  Tag             =   "opt_OfferPriorityTopspeed"
                  Top             =   195
                  Width           =   1575
               End
               Begin VB.OptionButton opt_OfferPriority 
                  Caption         =   "#Priority"
                  Height          =   390
                  Index           =   1
                  Left            =   1500
                  TabIndex        =   28
                  Tag             =   "opt_OfferPriorityPriority"
                  Top             =   195
                  Width           =   1575
               End
               Begin VB.OptionButton opt_OfferPriority 
                  Caption         =   "#Normal"
                  Height          =   390
                  Index           =   0
                  Left            =   105
                  TabIndex        =   27
                  Tag             =   "opt_OfferPriorityNormal"
                  Top             =   195
                  Width           =   1440
               End
            End
            Begin VB.Frame fra_OfferType 
               Caption         =   "#Offer type"
               Height          =   600
               Left            =   45
               TabIndex        =   22
               Tag             =   "fra_OfferType"
               Top             =   2265
               Width           =   4665
               Begin VB.OptionButton opt_OfferType 
                  Caption         =   "#Budget"
                  Height          =   375
                  Index           =   0
                  Left            =   60
                  TabIndex        =   23
                  Tag             =   "opt_OfferTypeBudget"
                  Top             =   195
                  Width           =   1440
               End
               Begin VB.OptionButton opt_OfferType 
                  Caption         =   "#Advanced"
                  Height          =   375
                  Index           =   1
                  Left            =   1500
                  TabIndex        =   24
                  Tag             =   "opt_OfferTypeAdvanced"
                  Top             =   180
                  Width           =   1575
               End
               Begin VB.OptionButton opt_OfferType 
                  Caption         =   "#Final"
                  Height          =   375
                  Index           =   2
                  Left            =   3045
                  TabIndex        =   25
                  Tag             =   "opt_OfferTypeFinal"
                  Top             =   180
                  Width           =   1575
               End
            End
            Begin VB.TextBox txt_COF_Code 
               Height          =   360
               Left            =   11145
               TabIndex        =   2
               TabStop         =   0   'False
               Top             =   180
               Width           =   1455
            End
            Begin VB.TextBox txt_SP_Desc 
               Height          =   360
               Left            =   1515
               TabIndex        =   1
               TabStop         =   0   'False
               Top             =   165
               Width           =   8415
            End
            Begin VB.TextBox txt_COF_ID 
               Height          =   330
               Left            =   1200
               TabIndex        =   76
               Top             =   180
               Visible         =   0   'False
               Width           =   225
            End
            Begin VB.TextBox txt_Version 
               Height          =   360
               Left            =   14010
               TabIndex        =   3
               TabStop         =   0   'False
               Top             =   165
               Width           =   585
            End
            Begin Project1.ArmCombobox cbo_SubProject 
               Height          =   345
               Left            =   1515
               TabIndex        =   4
               Top             =   510
               Width           =   8415
               _ExtentX        =   14843
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Status 
               Height          =   345
               Left            =   11145
               TabIndex        =   5
               TabStop         =   0   'False
               Top             =   525
               Width           =   1740
               _ExtentX        =   3069
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Customer 
               Height          =   345
               Left            =   1515
               TabIndex        =   7
               Top             =   840
               Width           =   8415
               _ExtentX        =   14843
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Contact 
               Height          =   345
               Left            =   11160
               TabIndex        =   8
               Top             =   855
               Width           =   3480
               _ExtentX        =   6138
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Level 
               Height          =   345
               Left            =   14010
               TabIndex        =   6
               TabStop         =   0   'False
               Top             =   525
               Width           =   630
               _ExtentX        =   1111
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_TOF1 
               Height          =   345
               Left            =   11520
               TabIndex        =   12
               Top             =   1185
               Width           =   3120
               _ExtentX        =   5503
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_TOF2 
               Height          =   345
               Left            =   11520
               TabIndex        =   16
               Top             =   1515
               Width           =   3105
               _ExtentX        =   5477
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_COF_AppBy 
               Height          =   345
               Left            =   8055
               TabIndex        =   19
               Tag             =   "cbo_ApprovedBy"
               Top             =   1845
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Template 
               Height          =   345
               Left            =   4875
               TabIndex        =   18
               Tag             =   "cbo_Language"
               Top             =   1845
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_currencies 
               Height          =   345
               Left            =   1515
               TabIndex        =   17
               Tag             =   "cbo_currencies"
               Top             =   1845
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_LegalEntity 
               Height          =   345
               Left            =   11520
               TabIndex        =   20
               Top             =   1845
               Width           =   3105
               _ExtentX        =   5477
               _ExtentY        =   609
            End
            Begin Project1.A_calocx cal_COF_DocDat 
               Height          =   360
               Left            =   12765
               TabIndex        =   214
               Tag             =   "COF_DocDat"
               Top             =   2505
               Width           =   1845
               _ExtentX        =   3254
               _ExtentY        =   635
            End
            Begin Project1.ArmCombobox cbo_PM_Office 
               Height          =   345
               Left            =   11520
               TabIndex        =   21
               Top             =   2175
               Width           =   3105
               _ExtentX        =   5477
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Probability 
               Height          =   345
               Left            =   16110
               TabIndex        =   279
               TabStop         =   0   'False
               Top             =   180
               Width           =   1740
               _ExtentX        =   3069
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_BuiltStatus 
               Height          =   345
               Left            =   16110
               TabIndex        =   281
               TabStop         =   0   'False
               Top             =   510
               Width           =   1740
               _ExtentX        =   3069
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_AltQuote 
               Height          =   345
               Left            =   16110
               TabIndex        =   284
               TabStop         =   0   'False
               Top             =   840
               Width           =   1740
               _ExtentX        =   3069
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_MainFamily 
               Height          =   345
               Left            =   16110
               TabIndex        =   286
               TabStop         =   0   'False
               Top             =   1170
               Width           =   1740
               _ExtentX        =   3069
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_MainLevel 
               Height          =   345
               Left            =   16110
               TabIndex        =   288
               TabStop         =   0   'False
               Top             =   1500
               Width           =   1740
               _ExtentX        =   3069
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_Specification 
               Height          =   345
               Left            =   16110
               TabIndex        =   290
               TabStop         =   0   'False
               Top             =   1830
               Width           =   1740
               _ExtentX        =   3069
               _ExtentY        =   609
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Specification"
               Height          =   255
               Index           =   101
               Left            =   14745
               TabIndex        =   291
               Tag             =   "lbl_Specification"
               Top             =   1890
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Main Level"
               Height          =   255
               Index           =   100
               Left            =   14745
               TabIndex        =   289
               Tag             =   "lbl_MainLevel"
               Top             =   1560
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Main Family"
               Height          =   255
               Index           =   99
               Left            =   14745
               TabIndex        =   287
               Tag             =   "lbl_MainFamily"
               Top             =   1230
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Alternative quote"
               Height          =   255
               Index           =   98
               Left            =   14745
               TabIndex        =   285
               Tag             =   "lbl_AlternativeQuote"
               Top             =   900
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Built status"
               Height          =   255
               Index           =   97
               Left            =   14745
               TabIndex        =   282
               Tag             =   "lbl_BuiltStatus"
               Top             =   570
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Probability"
               Height          =   255
               Index           =   96
               Left            =   14745
               TabIndex        =   280
               Tag             =   "lbl_Probability"
               Top             =   225
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#PM Office"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   238
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Index           =   94
               Left            =   9975
               TabIndex        =   275
               Tag             =   "lbl_PM_Office"
               Top             =   2190
               Width           =   1485
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Order date"
               Height          =   255
               Index           =   67
               Left            =   11490
               TabIndex        =   215
               Tag             =   "lbl_COF_DocDat"
               Top             =   2565
               Width           =   1275
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Margin [%]"
               Height          =   255
               Index           =   62
               Left            =   9615
               TabIndex        =   187
               Tag             =   "lbl_Margin"
               Top             =   2565
               Width           =   1485
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Legal entity"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   238
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Index           =   19
               Left            =   9975
               TabIndex        =   155
               Tag             =   "lbl_LegalEntity"
               Top             =   1890
               Width           =   1485
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Language"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   238
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Index           =   18
               Left            =   3450
               TabIndex        =   154
               Tag             =   "lbl_Language"
               Top             =   1890
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Approved by"
               Height          =   255
               Index           =   4
               Left            =   6750
               TabIndex        =   153
               Tag             =   "lbl_ApprovedBy"
               Top             =   1890
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Currency"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   238
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Index           =   20
               Left            =   30
               TabIndex        =   152
               Tag             =   "lbl_Offer_Currency"
               Top             =   1890
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Valid until"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   238
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Index           =   3
               Left            =   3450
               TabIndex        =   110
               Tag             =   "lbl_ExpiryDate"
               Top             =   1560
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Follow up"
               Height          =   255
               Index           =   28
               Left            =   30
               TabIndex        =   109
               Tag             =   "lbl_FollowUp"
               Top             =   1560
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Incoterm"
               Height          =   255
               Index           =   30
               Left            =   9975
               TabIndex        =   108
               Tag             =   "lbl_Incoterm"
               Top             =   1230
               Width           =   1485
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Payment condition"
               Height          =   255
               Index           =   31
               Left            =   9975
               TabIndex        =   107
               Tag             =   "lbl_Payment"
               Top             =   1560
               Width           =   1485
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Aproved when"
               Height          =   255
               Index           =   7
               Left            =   6750
               TabIndex        =   106
               Tag             =   "lbl_ApprovedDate"
               Top             =   1560
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Requested date"
               Height          =   255
               Index           =   23
               Left            =   30
               TabIndex        =   105
               Tag             =   "lbl_COF_WshDat"
               Top             =   1275
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Shipment date"
               Height          =   255
               Index           =   33
               Left            =   3450
               TabIndex        =   104
               Tag             =   "lbl_COF_ShpDat"
               Top             =   1230
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Delivery date"
               Height          =   255
               Index           =   34
               Left            =   6750
               TabIndex        =   103
               Tag             =   "lbl_COF_DelDat"
               Top             =   1230
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Offer Code"
               Height          =   255
               Index           =   36
               Left            =   9975
               TabIndex        =   89
               Tag             =   "lbl_COF_Code"
               Top             =   240
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Sub project"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   238
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Index           =   1
               Left            =   30
               TabIndex        =   83
               Tag             =   "lbl_SubProject"
               Top             =   570
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Project"
               Height          =   255
               Index           =   0
               Left            =   30
               TabIndex        =   82
               Tag             =   "lbl_Project"
               Top             =   240
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Status"
               Height          =   255
               Index           =   5
               Left            =   9975
               TabIndex        =   81
               Tag             =   "lbl_Status"
               Top             =   570
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Customer"
               BeginProperty Font 
                  Name            =   "Arial"
                  Size            =   8.25
                  Charset         =   238
                  Weight          =   700
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   255
               Index           =   6
               Left            =   30
               TabIndex        =   80
               Tag             =   "lbl_Customer"
               Top             =   885
               Width           =   1470
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Version"
               Height          =   255
               Index           =   26
               Left            =   12945
               TabIndex        =   79
               Tag             =   "lbl_Version"
               Top             =   225
               Width           =   915
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Contact"
               Height          =   255
               Index           =   27
               Left            =   9975
               TabIndex        =   78
               Tag             =   "lbl_Contact"
               Top             =   900
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Level"
               Height          =   255
               Index           =   29
               Left            =   12960
               TabIndex        =   77
               Tag             =   "lbl_Level"
               Top             =   540
               Width           =   1035
            End
         End
         Begin VB.Frame fra_Header 
            Height          =   1320
            Index           =   6
            Left            =   6510
            TabIndex        =   235
            Tag             =   "fra_CustomerAddress"
            Top             =   720
            Width           =   2070
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   19
               Left            =   1470
               MaxLength       =   80
               TabIndex        =   248
               Tag             =   "CUST_Code"
               Top             =   1635
               Width           =   2190
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   16
               Left            =   7785
               MaxLength       =   80
               TabIndex        =   247
               Tag             =   "CCU_CT_Desc"
               Top             =   1290
               Width           =   3135
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   11
               Left            =   1470
               MaxLength       =   70
               TabIndex        =   240
               Tag             =   "CCU_Desc"
               Top             =   285
               Width           =   9450
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   12
               Left            =   1470
               MaxLength       =   70
               TabIndex        =   239
               Tag             =   "CCU_Addr1"
               Top             =   630
               Width           =   9450
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   13
               Left            =   1470
               MaxLength       =   80
               TabIndex        =   238
               Tag             =   "CCU_Addr2"
               Top             =   960
               Width           =   9450
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   14
               Left            =   1470
               MaxLength       =   80
               TabIndex        =   237
               Tag             =   "CCU_Town"
               Top             =   1290
               Width           =   2190
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   15
               Left            =   4845
               MaxLength       =   20
               TabIndex        =   236
               Tag             =   "CCU_Zip"
               Top             =   1290
               Width           =   1200
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#SAP Code"
               Height          =   255
               Index           =   95
               Left            =   180
               TabIndex        =   276
               Tag             =   "lbl_CUST_Code"
               Top             =   1695
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Description"
               Height          =   255
               Index           =   88
               Left            =   180
               TabIndex        =   246
               Tag             =   "lbl_CCU_Desc"
               Top             =   375
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Address1"
               Height          =   255
               Index           =   87
               Left            =   180
               TabIndex        =   245
               Tag             =   "lbl_CCU_Addr1"
               Top             =   690
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Address2"
               Height          =   255
               Index           =   86
               Left            =   180
               TabIndex        =   244
               Tag             =   "lbl_CCU_Addr2"
               Top             =   1035
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Town"
               Height          =   255
               Index           =   85
               Left            =   180
               TabIndex        =   243
               Tag             =   "lbl_CCU_Town"
               Top             =   1350
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Zip"
               Height          =   255
               Index           =   84
               Left            =   3750
               TabIndex        =   242
               Tag             =   "lbl_CCU_Zip"
               Top             =   1350
               Width           =   1095
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Country"
               Height          =   255
               Index           =   83
               Left            =   6045
               TabIndex        =   241
               Tag             =   "lbl_CCU_CT_Desc"
               Top             =   1350
               Width           =   1710
            End
         End
         Begin VB.Frame fra_Header 
            Height          =   7080
            Index           =   5
            Left            =   1815
            TabIndex        =   111
            Tag             =   "fra_PosList"
            Top             =   660
            Width           =   14400
            Begin VB.Frame fra_PosListFilter 
               Height          =   1125
               Left            =   30
               TabIndex        =   120
               Tag             =   "fra_PosListFilter"
               Top             =   105
               Width           =   14730
               Begin VB.CommandButton cmd_MassEntry 
                  Caption         =   "#Mass entry"
                  Height          =   420
                  Left            =   11025
                  TabIndex        =   283
                  Tag             =   "cmd_MassEntry"
                  Top             =   660
                  Width           =   1065
               End
               Begin VB.CommandButton cmd_ShowPDF 
                  Caption         =   "#Show PDF"
                  Height          =   420
                  Left            =   12090
                  TabIndex        =   278
                  Tag             =   "cmd_ShowPDF"
                  Top             =   660
                  Width           =   1065
               End
               Begin VB.CommandButton cmd_ExportCADPDF 
                  Caption         =   "Export CAD/PDF"
                  Height          =   420
                  Left            =   13140
                  TabIndex        =   277
                  Tag             =   "cmd_ExportCADPDF"
                  Top             =   660
                  Width           =   1065
               End
               Begin VB.CommandButton cmd_TechnicsAttachments 
                  Caption         =   "#Save attachments"
                  Height          =   570
                  Left            =   13140
                  TabIndex        =   274
                  Tag             =   "cmd_TechnicsAttachments"
                  Top             =   105
                  Width           =   1065
               End
               Begin VB.CommandButton cmd_TechnicsExcel 
                  Caption         =   "#Save Excel"
                  Height          =   570
                  Left            =   12105
                  TabIndex        =   273
                  Tag             =   "cmd_TechnicsExcel"
                  Top             =   105
                  Width           =   1065
               End
               Begin VB.CommandButton cmd_TechnicsPath 
                  Caption         =   "#Open path"
                  Height          =   570
                  Left            =   11040
                  TabIndex        =   272
                  Tag             =   "cmd_TechnicsPath"
                  Top             =   105
                  Width           =   1065
               End
               Begin VB.CheckBox chk_PosListSelectAll 
                  Caption         =   "#Select all"
                  Height          =   270
                  Left            =   135
                  TabIndex        =   257
                  Tag             =   "chk_PosListSelectAll"
                  Top             =   825
                  Width           =   4110
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   0
                  Left            =   1335
                  TabIndex        =   121
                  Tag             =   "PosListPosFrom"
                  Top             =   135
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   1
                  Left            =   2775
                  TabIndex        =   123
                  Tag             =   "PosListPosTo"
                  Top             =   135
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   2
                  Left            =   1335
                  TabIndex        =   125
                  Tag             =   "PosListLevelFrom"
                  Top             =   480
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   3
                  Left            =   2775
                  TabIndex        =   127
                  Tag             =   "PosListLevelTo"
                  Top             =   480
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   4
                  Left            =   4950
                  TabIndex        =   129
                  Tag             =   "PosListCodeFrom"
                  Top             =   135
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   5
                  Left            =   6465
                  TabIndex        =   131
                  Tag             =   "PosListCodeTo"
                  Top             =   135
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   6
                  Left            =   4950
                  TabIndex        =   133
                  Tag             =   "PosListDrawNrFrom"
                  Top             =   480
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   7
                  Left            =   6465
                  TabIndex        =   135
                  Tag             =   "PosListDrawNrTo"
                  Top             =   480
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   8
                  Left            =   8595
                  TabIndex        =   137
                  Tag             =   "PosListCHFrom"
                  Top             =   135
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   9
                  Left            =   10110
                  TabIndex        =   139
                  Tag             =   "PosListCHTo"
                  Top             =   135
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   10
                  Left            =   8595
                  TabIndex        =   141
                  Tag             =   "PosListDHFrom"
                  Top             =   480
                  Width           =   855
               End
               Begin VB.TextBox txt_PosListFilter 
                  Height          =   345
                  Index           =   11
                  Left            =   10110
                  TabIndex        =   143
                  Tag             =   "PosListDHTo"
                  Top             =   480
                  Width           =   855
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Pos from"
                  Height          =   240
                  Index           =   41
                  Left            =   150
                  TabIndex        =   144
                  Tag             =   "lbl_PL_PosFrom"
                  Top             =   180
                  Width           =   1110
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#to"
                  Height          =   240
                  Index           =   42
                  Left            =   2220
                  TabIndex        =   142
                  Tag             =   "lbl_PL_PosTo"
                  Top             =   180
                  Width           =   585
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Level from"
                  Height          =   240
                  Index           =   43
                  Left            =   135
                  TabIndex        =   140
                  Tag             =   "lbl_PL_LevelFrom"
                  Top             =   525
                  Width           =   1110
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#to"
                  Height          =   240
                  Index           =   44
                  Left            =   2205
                  TabIndex        =   138
                  Tag             =   "lbl_PL_LevelTo"
                  Top             =   525
                  Width           =   585
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Code from"
                  Height          =   240
                  Index           =   45
                  Left            =   3765
                  TabIndex        =   136
                  Tag             =   "lbl_PL_CodeFrom"
                  Top             =   180
                  Width           =   1110
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#to"
                  Height          =   240
                  Index           =   46
                  Left            =   5865
                  TabIndex        =   134
                  Tag             =   "lbl_PL_CodeTo"
                  Top             =   180
                  Width           =   585
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Drawing from"
                  Height          =   240
                  Index           =   47
                  Left            =   3750
                  TabIndex        =   132
                  Tag             =   "lbl_PL_DrawNrFrom"
                  Top             =   525
                  Width           =   1110
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#to"
                  Height          =   240
                  Index           =   48
                  Left            =   5850
                  TabIndex        =   130
                  Tag             =   "lbl_PL_DrawNrTo"
                  Top             =   525
                  Width           =   585
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Side C/H from"
                  Height          =   240
                  Index           =   49
                  Left            =   7410
                  TabIndex        =   128
                  Tag             =   "lbl_PL_SideCHFrom"
                  Top             =   180
                  Width           =   1110
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#to"
                  Height          =   240
                  Index           =   50
                  Left            =   9510
                  TabIndex        =   126
                  Tag             =   "lbl_PL_SideCHTo"
                  Top             =   180
                  Width           =   585
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Side D/H from"
                  Height          =   240
                  Index           =   51
                  Left            =   7410
                  TabIndex        =   124
                  Tag             =   "lbl_PL_SideDHFrom"
                  Top             =   525
                  Width           =   1110
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#to"
                  Height          =   240
                  Index           =   52
                  Left            =   9495
                  TabIndex        =   122
                  Tag             =   "lbl_PL_SideDHTo"
                  Top             =   525
                  Width           =   585
               End
            End
            Begin VB.Frame fra_PosListToolbar 
               Height          =   855
               Left            =   30
               TabIndex        =   112
               Tag             =   "fra_PosListToolbar"
               Top             =   4290
               Width           =   19680
               Begin VB.CommandButton cmd_KillOrderB7 
                  Caption         =   "#Kill order B7"
                  Height          =   690
                  Left            =   15015
                  TabIndex        =   192
                  Tag             =   "cmd_KillOrderB7"
                  Top             =   120
                  Width           =   900
               End
               Begin VB.CommandButton btn_BaurerSOChangeExport 
                  Caption         =   "#B7 SO change"
                  Height          =   690
                  Left            =   14130
                  TabIndex        =   258
                  Tag             =   "btn_BaurerSOChangeExport"
                  Top             =   120
                  Width           =   900
               End
               Begin VB.CommandButton btn_BaurerSalesOrderExport 
                  Caption         =   "#B7 Sales order"
                  Height          =   690
                  Left            =   13245
                  TabIndex        =   191
                  Tag             =   "btn_BaurerSalesOrderExport"
                  Top             =   120
                  Width           =   900
               End
               Begin VB.CommandButton btn_BaurerSecretBoxKill 
                  Caption         =   "#Kill Planning Box"
                  Height          =   690
                  Left            =   12360
                  TabIndex        =   233
                  Tag             =   "btn_BaurerSecretBoxKill"
                  Top             =   120
                  Width           =   900
               End
               Begin VB.CommandButton btn_BaurerSecretBoxImport 
                  Caption         =   "#Import Planning Box"
                  Height          =   690
                  Left            =   11475
                  TabIndex        =   148
                  Tag             =   "btn_BaurerSecretBoxImport"
                  Top             =   120
                  Width           =   900
               End
               Begin VB.CommandButton btn_BaurerSecretBoxExport 
                  Caption         =   "#Export Planning Box"
                  Height          =   675
                  Left            =   10590
                  TabIndex        =   114
                  Tag             =   "btn_BaurerSecretBoxExport"
                  Top             =   135
                  Width           =   900
               End
               Begin VB.CommandButton btn_XmlCust 
                  Caption         =   "#Export XML Customer"
                  Height          =   690
                  Left            =   9705
                  TabIndex        =   115
                  Tag             =   "btn_XmlCust"
                  Top             =   120
                  Width           =   900
               End
               Begin VB.CommandButton btn_XmlPMaster 
                  Caption         =   "#Export XML PMaster"
                  Height          =   690
                  Left            =   8820
                  TabIndex        =   116
                  Tag             =   "btn_XmlPMaster"
                  Top             =   120
                  Width           =   900
               End
               Begin VB.CommandButton cmd_ExportRawMaterial 
                  Caption         =   "#Export raw material"
                  Height          =   690
                  Left            =   7815
                  TabIndex        =   234
                  Tag             =   "cmd_ExportRawMaterial"
                  Top             =   120
                  Width           =   1020
               End
               Begin VB.CommandButton btn_ChangeAttribute 
                  Caption         =   "#Change Attribute"
                  Height          =   690
                  Left            =   6900
                  TabIndex        =   250
                  Tag             =   "btn_ChangeAttribute"
                  Top             =   120
                  Width           =   930
               End
               Begin VB.CommandButton cmd_RecalcCost 
                  Caption         =   "#Recalculate cost"
                  Height          =   690
                  Left            =   5610
                  TabIndex        =   249
                  Tag             =   "cmd_RecalcCost"
                  Top             =   120
                  Width           =   1305
               End
               Begin VB.CommandButton btn_PrintPacking 
                  Caption         =   "#Print packing"
                  Height          =   690
                  Left            =   4710
                  TabIndex        =   270
                  Tag             =   "btn_PrintPacking"
                  Top             =   120
                  Width           =   915
               End
               Begin VB.CommandButton btn_RecalcPacking 
                  Caption         =   "#Recalculate packing"
                  Height          =   690
                  Left            =   3660
                  TabIndex        =   259
                  Tag             =   "btn_RecalcPacking"
                  Top             =   120
                  Width           =   1065
               End
               Begin VB.CommandButton btn_GenerateGroupAndCE 
                  Caption         =   "#Generate Group && CE"
                  Height          =   690
                  Left            =   2745
                  TabIndex        =   113
                  Tag             =   "btn_GenerateGroupAndCE"
                  Top             =   120
                  Width           =   930
               End
               Begin VB.CommandButton btn_PosListClearBOMBOR 
                  Caption         =   "#Clear BOM && BOR"
                  Height          =   690
                  Left            =   1785
                  TabIndex        =   117
                  Tag             =   "cmd_PosListClearBOMBOR"
                  Top             =   120
                  Width           =   975
               End
               Begin VB.CommandButton btn_PosListCalcBOMBOR 
                  Caption         =   "#Generate BOM && BOR"
                  Height          =   690
                  Left            =   825
                  TabIndex        =   118
                  Tag             =   "cmd_PosListCalcBOMBOR"
                  Top             =   120
                  Width           =   975
               End
               Begin VB.CommandButton btn_PosListEdit 
                  Caption         =   "#Edit attributes"
                  Height          =   690
                  Left            =   0
                  TabIndex        =   119
                  Tag             =   "cmd_PosListEdit"
                  Top             =   120
                  Width           =   840
               End
            End
            Begin Project1.ArmGrid grd_BOM 
               Height          =   1035
               Left            =   3420
               TabIndex        =   145
               TabStop         =   0   'False
               Tag             =   "grd_BOM"
               Top             =   1665
               Width           =   1425
               _ExtentX        =   2514
               _ExtentY        =   1826
            End
            Begin Project1.ArmGrid grd_PosList 
               Height          =   990
               Left            =   195
               TabIndex        =   146
               TabStop         =   0   'False
               Tag             =   "grd_PosList"
               Top             =   1695
               Width           =   1515
               _ExtentX        =   2672
               _ExtentY        =   1746
            End
            Begin Project1.ArmGrid grd_BOR 
               Height          =   1035
               Left            =   4995
               TabIndex        =   147
               TabStop         =   0   'False
               Tag             =   "grd_BOR"
               Top             =   1710
               Width           =   1425
               _ExtentX        =   2514
               _ExtentY        =   1826
            End
            Begin MSComctlLib.TabStrip tbs_PosList 
               Height          =   360
               Left            =   15
               TabIndex        =   149
               Tag             =   "tbs_Header"
               Top             =   1200
               Width           =   14685
               _ExtentX        =   25903
               _ExtentY        =   635
               _Version        =   393216
               BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
                  NumTabs         =   5
                  BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#Pos.list"
                     Key             =   "fra_PosList"
                     Object.Tag             =   "fra_PosList"
                     ImageVarType    =   2
                  EndProperty
                  BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#Packing"
                     Key             =   "fra_Packing"
                     Object.Tag             =   "fra_Packing"
                     ImageVarType    =   2
                  EndProperty
                  BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#BOM"
                     Key             =   "fra_BOM"
                     Object.Tag             =   "fra_BOM"
                     ImageVarType    =   2
                  EndProperty
                  BeginProperty Tab4 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#BOR"
                     Key             =   "fra_BOR"
                     Object.Tag             =   "fra_BOR"
                     ImageVarType    =   2
                  EndProperty
                  BeginProperty Tab5 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#Cost"
                     Key             =   "fra_Cost"
                     Object.Tag             =   "fra_Cost"
                     ImageVarType    =   2
                  EndProperty
               EndProperty
            End
            Begin Project1.ArmGrid grd_Packing 
               Height          =   1035
               Left            =   1815
               TabIndex        =   150
               TabStop         =   0   'False
               Tag             =   "grd_Packing"
               Top             =   1710
               Width           =   1425
               _ExtentX        =   2514
               _ExtentY        =   1826
            End
            Begin Project1.ArmGrid grd_Cost 
               Height          =   1035
               Left            =   6510
               TabIndex        =   151
               TabStop         =   0   'False
               Tag             =   "grd_Cost"
               Top             =   1770
               Width           =   1425
               _ExtentX        =   2514
               _ExtentY        =   1826
            End
         End
         Begin VB.Frame fra_Header 
            Height          =   1065
            Index           =   3
            Left            =   255
            TabIndex        =   90
            Tag             =   "fra_DeliveryAddress"
            Top             =   3780
            Width           =   2550
            Begin VB.TextBox txt_COF_CodeCus 
               Height          =   330
               Left            =   7710
               MaxLength       =   30
               TabIndex        =   189
               Tag             =   "txt_COF_CodeCus"
               Top             =   1500
               Width           =   3075
            End
            Begin VB.TextBox txt_COF_MaxWeek 
               Height          =   330
               Left            =   5385
               MaxLength       =   6
               TabIndex        =   179
               Tag             =   "txt_COF_MaxWeek"
               Top             =   1500
               Width           =   810
            End
            Begin VB.TextBox txt_COF_MinWeek 
               Height          =   330
               Left            =   3975
               MaxLength       =   6
               TabIndex        =   178
               Tag             =   "txt_COF_MinWeek"
               Top             =   1500
               Width           =   810
            End
            Begin VB.TextBox txt_COF_MaxOrd 
               Height          =   330
               Left            =   1350
               MaxLength       =   6
               TabIndex        =   158
               Tag             =   "txt_COF_MaxOrd"
               Top             =   1875
               Width           =   810
            End
            Begin VB.TextBox txt_COF_MaxLot 
               Height          =   330
               Left            =   1350
               MaxLength       =   6
               TabIndex        =   156
               Tag             =   "txt_COF_MaxLot"
               Top             =   1500
               Width           =   810
            End
            Begin VB.TextBox txt_COF_DeZip 
               Height          =   330
               Left            =   4725
               MaxLength       =   20
               TabIndex        =   95
               Tag             =   "txt_COF_DeZip"
               Top             =   1140
               Width           =   1200
            End
            Begin VB.TextBox txt_COF_DeTown 
               Height          =   330
               Left            =   1350
               MaxLength       =   80
               TabIndex        =   94
               Tag             =   "txt_COF_DeTown"
               Top             =   1140
               Width           =   2190
            End
            Begin VB.TextBox txt_COF_DeAdr2 
               Height          =   330
               Left            =   1350
               MaxLength       =   80
               TabIndex        =   93
               Tag             =   "txt_COF_DeAdr2"
               Top             =   810
               Width           =   9450
            End
            Begin VB.TextBox txt_COF_DeAdr1 
               Height          =   330
               Left            =   1350
               MaxLength       =   70
               TabIndex        =   92
               Tag             =   "txt_COF_DeAdr1"
               Top             =   480
               Width           =   9450
            End
            Begin VB.TextBox txt_COF_DeDesc 
               Height          =   330
               Left            =   1350
               MaxLength       =   70
               TabIndex        =   91
               Tag             =   "txt_COF_DeDesc"
               Top             =   135
               Width           =   9450
            End
            Begin Project1.ArmCombobox cbo_COF_DeCT 
               Height          =   345
               Left            =   7695
               TabIndex        =   96
               Tag             =   "cbo_COF_DeCT"
               Top             =   1140
               Width           =   3105
               _ExtentX        =   5477
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_U_CodeSlsRep 
               Height          =   345
               Left            =   1350
               TabIndex        =   260
               Tag             =   "cbo_U_CodeSlsRep"
               Top             =   2220
               Width           =   3105
               _ExtentX        =   5477
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_U_CodePrjMan 
               Height          =   345
               Left            =   1350
               TabIndex        =   261
               Tag             =   "cbo_U_CodePrjMan"
               Top             =   2565
               Width           =   3105
               _ExtentX        =   5477
               _ExtentY        =   609
            End
            Begin Project1.ArmCombobox cbo_U_CodePrdMan 
               Height          =   345
               Left            =   1350
               TabIndex        =   262
               Tag             =   "cbo_U_CodePrdMan"
               Top             =   2925
               Width           =   3105
               _ExtentX        =   5477
               _ExtentY        =   609
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Production man."
               Height          =   255
               Index           =   93
               Left            =   75
               TabIndex        =   265
               Tag             =   "lbl_U_CodePrdMan"
               Top             =   2955
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Project man."
               Height          =   255
               Index           =   92
               Left            =   75
               TabIndex        =   264
               Tag             =   "lbl_U_CodePrjMan"
               Top             =   2640
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Sls. rep"
               Height          =   255
               Index           =   91
               Left            =   75
               TabIndex        =   263
               Tag             =   "lbl_U_CodeSlsRep"
               Top             =   2310
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Code customer"
               Height          =   255
               Index           =   64
               Left            =   6360
               TabIndex        =   190
               Tag             =   "lbl_COF_CodeCus"
               Top             =   1545
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#to"
               Height          =   255
               Index           =   60
               Left            =   4815
               TabIndex        =   180
               Tag             =   "lbl_COF_MaxWeek"
               Top             =   1545
               Width           =   525
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Delivery weeks from"
               Height          =   255
               Index           =   59
               Left            =   2235
               TabIndex        =   177
               Tag             =   "lbl_COF_MinWeek"
               Top             =   1545
               Width           =   1695
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Max orders"
               Height          =   255
               Index           =   54
               Left            =   75
               TabIndex        =   159
               Tag             =   "lbl_COF_MaxOrd"
               Top             =   1950
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Max lots"
               Height          =   255
               Index           =   53
               Left            =   75
               TabIndex        =   157
               Tag             =   "lbl_COF_MaxLot"
               Top             =   1545
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Country"
               Height          =   255
               Index           =   40
               Left            =   5940
               TabIndex        =   102
               Tag             =   "lbl_COF_DelCountry"
               Top             =   1200
               Width           =   1710
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Zip"
               Height          =   255
               Index           =   39
               Left            =   3630
               TabIndex        =   101
               Tag             =   "lbl_COF_DelZip"
               Top             =   1200
               Width           =   1095
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Town"
               Height          =   255
               Index           =   38
               Left            =   60
               TabIndex        =   100
               Tag             =   "lbl_COF_DelTown"
               Top             =   1185
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Address2"
               Height          =   255
               Index           =   37
               Left            =   60
               TabIndex        =   99
               Tag             =   "lbl_COF_DelAddr2"
               Top             =   870
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Address1"
               Height          =   255
               Index           =   22
               Left            =   60
               TabIndex        =   98
               Tag             =   "lbl_COF_DelAddr1"
               Top             =   540
               Width           =   1320
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Description"
               Height          =   255
               Index           =   2
               Left            =   60
               TabIndex        =   97
               Tag             =   "lbl_COF_DelDesc"
               Top             =   225
               Width           =   1320
            End
         End
         Begin VB.Frame fra_Header 
            Height          =   1080
            Index           =   4
            Left            =   225
            TabIndex        =   193
            Tag             =   "fra_Intercompany"
            Top             =   645
            Width           =   2535
            Begin VB.CommandButton btn_BaeurerReference 
               Caption         =   "..."
               Height          =   330
               Index           =   5
               Left            =   9060
               TabIndex        =   212
               Tag             =   "btn_COF_Bae_PackType"
               Top             =   840
               Width           =   375
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   10
               Left            =   8340
               MaxLength       =   10
               TabIndex        =   211
               Tag             =   "COF_Bae_PackType"
               Top             =   840
               Width           =   735
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   9
               Left            =   8340
               MaxLength       =   10
               TabIndex        =   209
               Tag             =   "COF_Bae_DelType"
               Top             =   510
               Width           =   735
            End
            Begin VB.CommandButton btn_BaeurerReference 
               Caption         =   "..."
               Height          =   330
               Index           =   4
               Left            =   9060
               TabIndex        =   210
               Tag             =   "btn_COF_Bae_DelType"
               Top             =   510
               Width           =   375
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   8
               Left            =   8340
               MaxLength       =   10
               TabIndex        =   207
               Tag             =   "COF_Bae_DelCond"
               Top             =   180
               Width           =   735
            End
            Begin VB.CommandButton btn_BaeurerReference 
               Caption         =   "..."
               Height          =   330
               Index           =   3
               Left            =   9060
               TabIndex        =   208
               Tag             =   "btn_COF_Bae_DelCond"
               Top             =   180
               Width           =   375
            End
            Begin VB.CommandButton btn_BaeurerReference 
               Caption         =   "..."
               Height          =   330
               Index           =   2
               Left            =   2340
               TabIndex        =   206
               Tag             =   "btn_COF_Bae_InCharge"
               Top             =   2490
               Width           =   375
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   7
               Left            =   1620
               MaxLength       =   10
               TabIndex        =   205
               Tag             =   "COF_Bae_InCharge"
               Top             =   2490
               Width           =   735
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   6
               Left            =   1620
               MaxLength       =   30
               TabIndex        =   204
               Tag             =   "COF_Bae_BestNr2"
               Top             =   2160
               Width           =   2340
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   5
               Left            =   1620
               MaxLength       =   30
               TabIndex        =   203
               Tag             =   "COF_CodeCus"
               Top             =   1830
               Width           =   2340
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   4
               Left            =   1620
               MaxLength       =   70
               TabIndex        =   202
               Tag             =   "SP_CapKey"
               Top             =   1500
               Width           =   2340
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   3
               Left            =   1620
               MaxLength       =   10
               TabIndex        =   200
               Tag             =   "COF_Bae_Partner"
               Top             =   1170
               Width           =   735
            End
            Begin VB.CommandButton btn_BaeurerReference 
               Caption         =   "..."
               Height          =   330
               Index           =   1
               Left            =   2340
               TabIndex        =   201
               Tag             =   "btn_COF_Bae_Partner"
               Top             =   1170
               Width           =   375
            End
            Begin VB.CommandButton btn_BaeurerReference 
               Caption         =   "..."
               Height          =   330
               Index           =   0
               Left            =   2340
               TabIndex        =   199
               Tag             =   "btn_COF_Bae_OrdTyp"
               Top             =   840
               Width           =   375
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   2
               Left            =   1620
               MaxLength       =   10
               TabIndex        =   197
               Tag             =   "COF_Bae_OrdTyp"
               Top             =   840
               Width           =   735
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   1
               Left            =   1620
               MaxLength       =   70
               TabIndex        =   196
               TabStop         =   0   'False
               Tag             =   "COF_CodeBae"
               Top             =   510
               Width           =   1110
            End
            Begin VB.TextBox txt_Textbox 
               Height          =   330
               Index           =   0
               Left            =   1620
               MaxLength       =   70
               TabIndex        =   195
               TabStop         =   0   'False
               Tag             =   "COF_Bae_Konto"
               Top             =   180
               Width           =   1110
            End
            Begin VB.Label lbl_Label 
               AutoSize        =   -1  'True
               Caption         =   "#"
               Height          =   195
               Index           =   82
               Left            =   9540
               TabIndex        =   232
               Tag             =   "_COF_Bae_PackTypeDesc"
               Top             =   915
               Width           =   105
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Packing type"
               Height          =   255
               Index           =   81
               Left            =   6825
               TabIndex        =   231
               Tag             =   "lbl_COF_Bae_PackType"
               Top             =   885
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               AutoSize        =   -1  'True
               Caption         =   "#"
               Height          =   195
               Index           =   80
               Left            =   9540
               TabIndex        =   230
               Tag             =   "_COF_Bae_DelTypeDesc"
               Top             =   585
               Width           =   105
            End
            Begin VB.Label lbl_Label 
               AutoSize        =   -1  'True
               Caption         =   "#"
               Height          =   195
               Index           =   79
               Left            =   9540
               TabIndex        =   229
               Tag             =   "_COF_Bae_DelCondDesc"
               Top             =   270
               Width           =   105
            End
            Begin VB.Label lbl_Label 
               AutoSize        =   -1  'True
               Caption         =   "#"
               Height          =   195
               Index           =   78
               Left            =   2805
               TabIndex        =   228
               Tag             =   "_COF_Bae_InChargeDesc"
               Top             =   2535
               Width           =   105
            End
            Begin VB.Label lbl_Label 
               AutoSize        =   -1  'True
               Caption         =   "#"
               Height          =   195
               Index           =   77
               Left            =   2805
               TabIndex        =   227
               Tag             =   "_COF_Bae_PartnerDesc"
               Top             =   1215
               Width           =   105
            End
            Begin VB.Label lbl_Label 
               AutoSize        =   -1  'True
               Caption         =   "#"
               Height          =   195
               Index           =   76
               Left            =   2805
               TabIndex        =   226
               Tag             =   "_COF_Bae_OrdTypDesc"
               Top             =   840
               Width           =   105
            End
            Begin VB.Label lbl_Label 
               AutoSize        =   -1  'True
               Caption         =   "#"
               Height          =   195
               Index           =   75
               Left            =   2805
               TabIndex        =   225
               Tag             =   "_COF_Bae_KontoDesc"
               Top             =   285
               Width           =   105
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Delivery type"
               Height          =   255
               Index           =   74
               Left            =   6825
               TabIndex        =   224
               Tag             =   "lbl_COF_Bae_DelType"
               Top             =   555
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Delivery condition"
               Height          =   255
               Index           =   73
               Left            =   6825
               TabIndex        =   223
               Tag             =   "lbl_COF_Bae_DelCond"
               Top             =   225
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Clerk in charge"
               Height          =   255
               Index           =   72
               Left            =   105
               TabIndex        =   222
               Tag             =   "lbl_COF_Bae_InCharge"
               Top             =   2535
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Order no.1"
               Height          =   255
               Index           =   71
               Left            =   105
               TabIndex        =   220
               Tag             =   "lbl_COF_Bae_BestNr2"
               Top             =   2235
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Order no."
               Height          =   255
               Index           =   70
               Left            =   105
               TabIndex        =   219
               Tag             =   "lbl_COF_Bae_BestNr"
               Top             =   1905
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Sls.project"
               Height          =   255
               Index           =   69
               Left            =   105
               TabIndex        =   218
               Tag             =   "lbl_SP_Capkey"
               Top             =   1575
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Partner"
               Height          =   255
               Index           =   68
               Left            =   105
               TabIndex        =   216
               Tag             =   "lbl_COF_Bae_Partner"
               Top             =   1208
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Order type"
               Height          =   255
               Index           =   66
               Left            =   105
               TabIndex        =   213
               Tag             =   "lbl_COF_Bae_OrdTyp"
               Top             =   878
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Frame ord.no."
               Height          =   255
               Index           =   65
               Left            =   105
               TabIndex        =   198
               Tag             =   "lbl_COF_CodeBae"
               Top             =   585
               Width           =   1515
            End
            Begin VB.Label lbl_Label 
               Caption         =   "#Company"
               Height          =   255
               Index           =   63
               Left            =   105
               TabIndex        =   194
               Tag             =   "lbl_LEN_BaeKonto"
               Top             =   255
               Width           =   1515
            End
         End
         Begin VB.Frame fra_Header 
            Height          =   870
            Index           =   2
            Left            =   7185
            TabIndex        =   87
            Tag             =   "fra_OfferComment"
            Top             =   6540
            Width           =   1785
            Begin VB.TextBox txt_COF_Comm 
               Height          =   990
               Left            =   45
               MaxLength       =   2000
               MultiLine       =   -1  'True
               ScrollBars      =   2  'Vertical
               TabIndex        =   88
               Top             =   135
               Width           =   14130
            End
         End
         Begin VB.Frame fra_Header 
            Height          =   855
            Index           =   1
            Left            =   10455
            TabIndex        =   85
            Tag             =   "fra_InternalComment"
            Top             =   6600
            Width           =   3360
            Begin VB.TextBox txt_COF_Desc 
               Height          =   990
               Left            =   45
               MaxLength       =   250
               MultiLine       =   -1  'True
               ScrollBars      =   2  'Vertical
               TabIndex        =   86
               Top             =   135
               Width           =   14130
            End
         End
         Begin VB.Frame fraSubItemMain 
            Height          =   2940
            Left            =   4635
            TabIndex        =   53
            Tag             =   "fraSubItemMain"
            Top             =   2640
            Width           =   3240
            Begin VB.CommandButton btn_MovePrev 
               Caption         =   "ñ"
               BeginProperty Font 
                  Name            =   "Wingdings"
                  Size            =   12
                  Charset         =   2
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   330
               Left            =   12885
               TabIndex        =   269
               Tag             =   "_btn_MovePrev"
               Top             =   2115
               Width           =   675
            End
            Begin VB.CommandButton btn_MoveNext 
               Caption         =   "ò"
               BeginProperty Font 
                  Name            =   "Wingdings"
                  Size            =   12
                  Charset         =   2
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               Height          =   330
               Left            =   12225
               TabIndex        =   268
               Tag             =   "_btn_MoveNext"
               Top             =   2115
               Width           =   675
            End
            Begin Project1.ToolbarControl tlb_Subitem 
               Height          =   4995
               Left            =   13755
               TabIndex        =   71
               Tag             =   "2905"
               Top             =   180
               Width           =   690
               _ExtentX        =   1217
               _ExtentY        =   8811
            End
            Begin VB.Frame fraSubitemDetail0 
               Height          =   1965
               Left            =   90
               TabIndex        =   55
               Tag             =   "fraSubitemDetail0"
               Top             =   120
               Width           =   13560
               Begin VB.TextBox txt_S_Code 
                  Height          =   240
                  Left            =   3720
                  TabIndex        =   186
                  Tag             =   "txt_S_Code"
                  Top             =   150
                  Visible         =   0   'False
                  Width           =   435
               End
               Begin VB.TextBox txt_SKUPU 
                  Height          =   315
                  Left            =   5520
                  TabIndex        =   182
                  Top             =   975
                  Width           =   1080
               End
               Begin VB.CommandButton btn_SAPPrice 
                  Caption         =   "#Read SAP price"
                  Height          =   450
                  Left            =   11970
                  TabIndex        =   181
                  Tag             =   "btn_SAPPrice"
                  Top             =   825
                  Width           =   1395
               End
               Begin VB.TextBox txt_SKUCost 
                  Height          =   315
                  Left            =   6825
                  TabIndex        =   175
                  Top             =   975
                  Width           =   1080
               End
               Begin VB.CheckBox chk_ASFlag 
                  Caption         =   "#AS Item"
                  Height          =   225
                  Left            =   11895
                  TabIndex        =   167
                  Tag             =   "chk_ASFlag"
                  Top             =   1650
                  Width           =   1560
               End
               Begin VB.CheckBox chk_FreeOfCharge 
                  Caption         =   "#Free of charge"
                  Height          =   225
                  Left            =   11910
                  TabIndex        =   166
                  Tag             =   "chk_FreeOfCharge"
                  Top             =   1350
                  Width           =   1560
               End
               Begin VB.TextBox txt_CURR_Code 
                  Height          =   315
                  Left            =   10575
                  TabIndex        =   160
                  Tag             =   "txt_CURR_Code"
                  Top             =   975
                  Width           =   1275
               End
               Begin VB.TextBox txt_PRD_Id 
                  Height          =   240
                  Left            =   3195
                  TabIndex        =   69
                  Top             =   165
                  Visible         =   0   'False
                  Width           =   435
               End
               Begin Project1.A_calocx cal_OFD_WshDat 
                  Height          =   360
                  Left            =   90
                  TabIndex        =   65
                  Tag             =   "OFD_WshDat"
                  Top             =   1530
                  Width           =   1845
                  _ExtentX        =   3254
                  _ExtentY        =   635
               End
               Begin Project1.A_calocx cal_OFD_DelDat 
                  Height          =   360
                  Left            =   3900
                  TabIndex        =   67
                  Tag             =   "OFD_DelDat"
                  Top             =   1530
                  Width           =   1845
                  _ExtentX        =   3254
                  _ExtentY        =   635
               End
               Begin VB.TextBox txt_OFD_Pos 
                  Height          =   315
                  Left            =   135
                  TabIndex        =   33
                  Top             =   975
                  Width           =   1485
               End
               Begin VB.TextBox txt_SPANumber 
                  Height          =   315
                  Left            =   1740
                  TabIndex        =   34
                  Top             =   975
                  Width           =   1080
               End
               Begin VB.TextBox txt_SKUPriceM 
                  Height          =   315
                  Left            =   9255
                  TabIndex        =   38
                  Top             =   975
                  Width           =   1140
               End
               Begin VB.TextBox txt_SKUQty 
                  Height          =   315
                  Left            =   3285
                  TabIndex        =   35
                  Top             =   975
                  Width           =   705
               End
               Begin VB.TextBox txt_SKUPrice 
                  Height          =   315
                  Left            =   8040
                  TabIndex        =   37
                  Top             =   975
                  Width           =   1080
               End
               Begin VB.CommandButton btn_SelectProduct 
                  Caption         =   "..."
                  Height          =   360
                  Left            =   12915
                  TabIndex        =   32
                  Tag             =   "btn_SelectProduct"
                  Top             =   390
                  Width           =   435
               End
               Begin VB.TextBox txt_BI_SAP_Desc 
                  Height          =   345
                  Left            =   1740
                  TabIndex        =   31
                  TabStop         =   0   'False
                  Tag             =   "txt_BI_SAP_Code"
                  Top             =   405
                  Width           =   11145
               End
               Begin VB.TextBox txt_BI_SAP_Code 
                  Height          =   315
                  Left            =   165
                  TabIndex        =   0
                  TabStop         =   0   'False
                  Tag             =   "txt_BI_SAP_Code"
                  Top             =   420
                  Width           =   1455
               End
               Begin Project1.ArmCombobox cbo_SKUUOM 
                  Height          =   345
                  Left            =   4275
                  TabIndex        =   36
                  Tag             =   "cbo_SKUUOM"
                  Top             =   975
                  Width           =   1215
                  _ExtentX        =   2143
                  _ExtentY        =   609
               End
               Begin Project1.A_calocx cal_OFD_ShpDat 
                  Height          =   360
                  Left            =   1995
                  TabIndex        =   73
                  Tag             =   "OFD_ShpDat"
                  Top             =   1530
                  Width           =   1845
                  _ExtentX        =   3254
                  _ExtentY        =   635
               End
               Begin Project1.ArmCombobox cbo_Vendor 
                  Height          =   345
                  Left            =   5760
                  TabIndex        =   162
                  Top             =   1530
                  Width           =   2970
                  _ExtentX        =   5239
                  _ExtentY        =   609
               End
               Begin Project1.ArmCombobox cbo_ShipPoint 
                  Height          =   345
                  Left            =   8760
                  TabIndex        =   163
                  Top             =   1530
                  Width           =   2970
                  _ExtentX        =   5239
                  _ExtentY        =   609
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#PU"
                  Height          =   255
                  Index           =   61
                  Left            =   5535
                  TabIndex        =   183
                  Tag             =   "lbl_OFD_PU"
                  Top             =   735
                  Width           =   1185
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Cost"
                  Height          =   255
                  Index           =   58
                  Left            =   6810
                  TabIndex        =   176
                  Tag             =   "lbl_OFD_CostA"
                  Top             =   735
                  Width           =   1215
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Plant/Vendor"
                  BeginProperty Font 
                     Name            =   "Arial"
                     Size            =   8.25
                     Charset         =   238
                     Weight          =   700
                     Underline       =   0   'False
                     Italic          =   0   'False
                     Strikethrough   =   0   'False
                  EndProperty
                  Height          =   240
                  Index           =   57
                  Left            =   5760
                  TabIndex        =   165
                  Tag             =   "lbl_PlantVendor"
                  Top             =   1290
                  Width           =   1230
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Shipping point"
                  BeginProperty Font 
                     Name            =   "Arial"
                     Size            =   8.25
                     Charset         =   238
                     Weight          =   700
                     Underline       =   0   'False
                     Italic          =   0   'False
                     Strikethrough   =   0   'False
                  EndProperty
                  Height          =   240
                  Index           =   56
                  Left            =   8715
                  TabIndex        =   164
                  Tag             =   "lbl_ShipPoint"
                  Top             =   1290
                  Width           =   1395
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Currency"
                  Height          =   255
                  Index           =   55
                  Left            =   10560
                  TabIndex        =   161
                  Tag             =   "lbl_CURR_Code"
                  Top             =   735
                  Width           =   1215
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Shipment date"
                  Height          =   255
                  Index           =   35
                  Left            =   2010
                  TabIndex        =   74
                  Tag             =   "lbl_OFD_ShpDat"
                  Top             =   1290
                  Width           =   1470
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Delivery date"
                  Height          =   255
                  Index           =   32
                  Left            =   3900
                  TabIndex        =   68
                  Tag             =   "lbl_OFD_DelDat"
                  Top             =   1290
                  Width           =   1470
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Requested date"
                  Height          =   255
                  Index           =   25
                  Left            =   105
                  TabIndex        =   66
                  Tag             =   "lbl_OFD_WshDat"
                  Top             =   1290
                  Width           =   1470
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Position"
                  BeginProperty Font 
                     Name            =   "Arial"
                     Size            =   8.25
                     Charset         =   238
                     Weight          =   700
                     Underline       =   0   'False
                     Italic          =   0   'False
                     Strikethrough   =   0   'False
                  EndProperty
                  Height          =   255
                  Index           =   21
                  Left            =   150
                  TabIndex        =   64
                  Tag             =   "lbl_OFD_Pos"
                  Top             =   735
                  Width           =   1215
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#SPA Number"
                  Height          =   255
                  Index           =   17
                  Left            =   1755
                  TabIndex        =   63
                  Tag             =   "lbl_SPA_ID"
                  Top             =   735
                  Width           =   1215
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Price manual"
                  Height          =   255
                  Index           =   15
                  Left            =   9225
                  TabIndex        =   62
                  Tag             =   "lbl_OFD_Price"
                  Top             =   735
                  Width           =   1215
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Quantity"
                  BeginProperty Font 
                     Name            =   "Arial"
                     Size            =   8.25
                     Charset         =   238
                     Weight          =   700
                     Underline       =   0   'False
                     Italic          =   0   'False
                     Strikethrough   =   0   'False
                  EndProperty
                  Height          =   255
                  Index           =   14
                  Left            =   3270
                  TabIndex        =   61
                  Tag             =   "lbl_OFD_Qty"
                  Top             =   735
                  Width           =   810
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Price"
                  Height          =   255
                  Index           =   9
                  Left            =   8025
                  TabIndex        =   60
                  Tag             =   "lbl_OFD_PriceA"
                  Top             =   735
                  Width           =   1215
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Unit of measure"
                  BeginProperty Font 
                     Name            =   "Arial"
                     Size            =   8.25
                     Charset         =   238
                     Weight          =   700
                     Underline       =   0   'False
                     Italic          =   0   'False
                     Strikethrough   =   0   'False
                  EndProperty
                  Height          =   255
                  Index           =   8
                  Left            =   4275
                  TabIndex        =   59
                  Tag             =   "lbl_OFD_UM_Code"
                  Top             =   735
                  Width           =   1320
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Description"
                  BeginProperty Font 
                     Name            =   "Arial"
                     Size            =   8.25
                     Charset         =   238
                     Weight          =   700
                     Underline       =   0   'False
                     Italic          =   0   'False
                     Strikethrough   =   0   'False
                  EndProperty
                  Height          =   255
                  Index           =   24
                  Left            =   1785
                  TabIndex        =   57
                  Tag             =   "lbl_PRD_Name"
                  Top             =   165
                  Width           =   1215
               End
               Begin VB.Label lbl_Label 
                  Caption         =   "#Code"
                  BeginProperty Font 
                     Name            =   "Arial"
                     Size            =   8.25
                     Charset         =   238
                     Weight          =   700
                     Underline       =   0   'False
                     Italic          =   0   'False
                     Strikethrough   =   0   'False
                  EndProperty
                  Height          =   255
                  Index           =   16
                  Left            =   180
                  TabIndex        =   56
                  Tag             =   "lbl_PRD_Code"
                  Top             =   165
                  Width           =   1215
               End
            End
            Begin Project1.ArmGrid grd_Offer 
               Height          =   2280
               Left            =   105
               TabIndex        =   54
               TabStop         =   0   'False
               Tag             =   "grd_Offer"
               Top             =   2565
               Width           =   13620
               _ExtentX        =   24024
               _ExtentY        =   4022
            End
            Begin MSComctlLib.TabStrip tbs_Offer 
               Height          =   375
               Left            =   135
               TabIndex        =   58
               Tag             =   "tbs_Offer"
               Top             =   4830
               Width           =   4050
               _ExtentX        =   7144
               _ExtentY        =   661
               Placement       =   1
               _Version        =   393216
               BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
                  NumTabs         =   2
                  BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#Full price"
                     Key             =   "tbs_FullPrice"
                     Object.Tag             =   "tbs_FullPrice"
                     ImageVarType    =   2
                  EndProperty
                  BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#Master price"
                     Key             =   "tbs_MasterPrice"
                     Object.Tag             =   "tbs_MasterPrice"
                     ImageVarType    =   2
                  EndProperty
               EndProperty
            End
            Begin MSComctlLib.TabStrip tbs_OfferDetail 
               Height          =   405
               Left            =   75
               TabIndex        =   185
               Tag             =   "tbs_OfferDetail"
               Top             =   2100
               Width           =   13710
               _ExtentX        =   24183
               _ExtentY        =   714
               _Version        =   393216
               BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
                  NumTabs         =   3
                  BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#Detail"
                     Key             =   "tab_Detail"
                     Object.Tag             =   "tab_Detail"
                     ImageVarType    =   2
                  EndProperty
                  BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#Alternatives"
                     Key             =   "tab_Alt"
                     Object.Tag             =   "tab_Alt"
                     ImageVarType    =   2
                  EndProperty
                  BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                     Caption         =   "#Surcharges and Extras"
                     Key             =   "tab_Option"
                     Object.Tag             =   "tab_Option"
                     ImageVarType    =   2
                  EndProperty
               EndProperty
            End
         End
         Begin Project1.ArmGrid grd_Baeurer 
            Height          =   4560
            Left            =   12465
            TabIndex        =   221
            Tag             =   "grd_Baeurer"
            Top             =   945
            Visible         =   0   'False
            Width           =   3585
            _ExtentX        =   6324
            _ExtentY        =   8043
         End
         Begin MSComctlLib.TabStrip tbs_Header 
            Height          =   360
            Left            =   75
            TabIndex        =   84
            Tag             =   "tbs_Header"
            Top             =   135
            Width           =   9585
            _ExtentX        =   16907
            _ExtentY        =   635
            _Version        =   393216
            BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
               NumTabs         =   7
               BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Header"
                  Key             =   "fra_Header"
                  Object.Tag             =   "tab_Header"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab2 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Offer comment"
                  Key             =   "fra_OfferComment"
                  Object.Tag             =   "tab_OfferComment"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab3 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Internal comment"
                  Key             =   "fra_InternalComment"
                  Object.Tag             =   "tab_InternalComment"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab4 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Delivery"
                  Key             =   "fra_DeliveryAddress"
                  Object.Tag             =   "fra_DeliveryAddress"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab5 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Intercompany"
                  Key             =   "fra_Intercompany"
                  Object.Tag             =   "fra_Intercompany"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab6 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Customer address"
                  Key             =   "fra_CustomerAddress"
                  Object.Tag             =   "fra_CustomerAddress"
                  ImageVarType    =   2
               EndProperty
               BeginProperty Tab7 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
                  Caption         =   "#Pos.list"
                  Key             =   "fra_PosList"
                  Object.Tag             =   "fra_PosList"
                  ImageVarType    =   2
               EndProperty
            EndProperty
         End
      End
      Begin VB.Frame fraItemBottom 
         Height          =   360
         Left            =   135
         TabIndex        =   45
         Tag             =   "fraItemBottom"
         Top             =   10230
         Width           =   16110
         Begin VB.CheckBox chk_DropFlag 
            Alignment       =   1  'Right Justify
            Caption         =   "#Drop flag"
            Enabled         =   0   'False
            Height          =   255
            Left            =   13035
            TabIndex        =   254
            Tag             =   "chk_DropFlag"
            Top             =   38
            Width           =   1080
         End
         Begin VB.TextBox txt_DropDate 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   14130
            Locked          =   -1  'True
            TabIndex        =   253
            Top             =   0
            Width           =   1005
         End
         Begin VB.TextBox txt_Textbox 
            Height          =   315
            Index           =   18
            Left            =   3075
            TabIndex        =   252
            Tag             =   "SP_CapKey2"
            Top             =   8
            Width           =   1695
         End
         Begin VB.TextBox txt_Textbox 
            Height          =   315
            Index           =   17
            Left            =   1095
            TabIndex        =   251
            Tag             =   "COF_Code"
            Top             =   8
            Width           =   840
         End
         Begin VB.TextBox txt_dateUpdated 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   10110
            TabIndex        =   42
            TabStop         =   0   'False
            Tag             =   "txt_lastUpdated"
            Top             =   0
            Width           =   1005
         End
         Begin VB.TextBox txt_dateEntered 
            Alignment       =   2  'Center
            Enabled         =   0   'False
            Height          =   330
            Left            =   6000
            TabIndex        =   40
            TabStop         =   0   'False
            Tag             =   "txt_dateEntered"
            Top             =   0
            Width           =   1005
         End
         Begin VB.TextBox txt_createdBy 
            Enabled         =   0   'False
            Height          =   330
            Left            =   7920
            TabIndex        =   41
            TabStop         =   0   'False
            Tag             =   "txt_createdBy"
            Top             =   0
            Width           =   960
         End
         Begin VB.TextBox txt_updatedBy 
            Enabled         =   0   'False
            Height          =   330
            Left            =   12030
            TabIndex        =   43
            TabStop         =   0   'False
            Top             =   0
            Width           =   960
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Offer Code"
            Height          =   255
            Index           =   90
            Left            =   30
            TabIndex        =   256
            Tag             =   "lbl_COF_Code"
            Top             =   45
            Width           =   1155
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Sls.project"
            Height          =   255
            Index           =   89
            Left            =   1980
            TabIndex        =   255
            Tag             =   "lbl_SP_Capkey"
            Top             =   45
            Width           =   1110
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Date Entered"
            Enabled         =   0   'False
            Height          =   255
            Index           =   10
            Left            =   4785
            TabIndex        =   52
            Tag             =   "lbl_dateEntered"
            Top             =   45
            Width           =   1140
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#Last Updated"
            Enabled         =   0   'False
            Height          =   255
            Index           =   11
            Left            =   8940
            TabIndex        =   51
            Tag             =   "lbl_lastUpdated"
            Top             =   45
            Width           =   1140
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#By"
            Enabled         =   0   'False
            Height          =   255
            Index           =   12
            Left            =   7020
            TabIndex        =   50
            Tag             =   "lbl_createdBy"
            Top             =   45
            Width           =   900
         End
         Begin VB.Label lbl_Label 
            Caption         =   "#By"
            Enabled         =   0   'False
            Height          =   255
            Index           =   13
            Left            =   11115
            TabIndex        =   49
            Tag             =   "lbl_updatedBy"
            Top             =   45
            Width           =   900
         End
      End
      Begin MSComctlLib.TabStrip tbsEmbedded 
         Height          =   375
         Left            =   120
         TabIndex        =   46
         Tag             =   "tbsEmbedded"
         Top             =   9915
         Width           =   1695
         _ExtentX        =   2990
         _ExtentY        =   661
         Placement       =   1
         _Version        =   393216
         BeginProperty Tabs {1EFB6598-857C-11D1-B16A-00C0F0283628} 
            NumTabs         =   1
            BeginProperty Tab1 {1EFB659A-857C-11D1-B16A-00C0F0283628} 
               ImageVarType    =   2
            EndProperty
         EndProperty
      End
      Begin Project1.ToolbarControl tlb_Item 
         Height          =   690
         Left            =   120
         TabIndex        =   70
         Tag             =   "2904"
         Top             =   180
         Width           =   16230
         _ExtentX        =   28628
         _ExtentY        =   1217
      End
   End
   Begin VB.Frame fraList 
      Height          =   4125
      Left            =   690
      TabIndex        =   47
      Tag             =   "fraList"
      Top             =   300
      Width           =   6435
      Begin Project1.ToolbarControl tlb_Main 
         Height          =   690
         Left            =   90
         TabIndex        =   72
         Tag             =   "2906"
         Top             =   150
         Width           =   8835
         _ExtentX        =   15584
         _ExtentY        =   1217
      End
      Begin Project1.ArmGrid grdlst 
         Height          =   2775
         Left            =   435
         TabIndex        =   48
         Tag             =   "grdlst"
         Top             =   1140
         Width           =   5175
         _ExtentX        =   9128
         _ExtentY        =   4895
      End
   End
   Begin MSComctlLib.ImageList iml_Icons 
      Left            =   150
      Top             =   5850
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483633
      MaskColor       =   16711935
      _Version        =   393216
   End
   Begin MSComDlg.CommonDialog dlg_Common 
      Left            =   240
      Top             =   5160
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
End
Attribute VB_Name = "CapOffer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' **************************************************************************************************
' **************************************** USER DEFINED ERRORS *************************************
' **************************************************************************************************
Private Enum ArmErr
    DBCnxFailed = vbObjectError + 1             ' Unable to connect to the database
    CPTAlreadyInitialized = vbObjectError + 2   ' We try to initialize a component that is already initialized
    CPTNotInitialized = vbObjectError + 3       ' We try to use or free that is not initialized yet
    InvalidArgument = vbObjectError + 4
    PropertyNotSet = vbObjectError + 5
    SQLFailure = vbObjectError + 6               ' A SQL runtime error has occured : syntax wrong....
    SQLBadRowAffectedCount = vbObjectError + 7   ' A SQL request has not affected the expected rowcount (ex: one Update do nothing)
    SQLBadRowExpectedCount = vbObjectError + 8   ' A SQL request does not return the expected rowcount : select an item return nothing...
    DrivingError = vbObjectError + 9
    CompFncFailed = vbObjectError + 10           ' when component function fail
    GridLoadFailed = vbObjectError + 11          ' load function failed ... bad sql
    QuietException = vbObjectError + 12          ' do not display error message
    SQLTableReferenceConstraint = vbObjectError + 13 ' A SQL request cannot be executed : Table reference constraint
    DuplicityDetected = vbObjectError + 2301     ' detected row with same unique id
End Enum

Private Const CL_COLOR_ENABLED  As Long = &H80000005
Private Const CL_COLOR_DISABLED As Long = &H8000000F
Private Const CL_COLOR_Expired  As Long = 10066414          ' # EE9999
Private Const CL_COLOR_Requested    As Long = 10066414      ' # EE9999
Private Const CL_COLOR_Delivered    As Long = 10088089      ' # 99EE99

Private Const LOCALE_SDECIMAL = &HE ' Decimal separator
Private Const LOCALE_STHOUSAND = &HF ' Thousand separator
Private Const LOCALE_USER_DEFAULT = &H400
Private Const SCREEN_NAME As String = "Cap_Offer"

Const C_SAP_LOGIN As String = "NXT"
Const C_SAP_PASSW As String = "ous42pri"
Const C_A_CONFIG_Distr_Chan  As String = "ABPE_SPA_BAPI_SAP_Distr_Chan"
Const C_A_CONFIG_Division    As String = "ABPE_SPA_BAPI_SAP_Division"
Const C_A_CONFIG_Doc_Type    As String = "ABPE_SPA_BAPI_SAP_Doc_Type"
Const C_A_CONFIG_Partn_Role  As String = "ABPE_SPA_BAPI_SAP_Partn_Role"
Const C_A_CONFIG_UrlGetSalesOrder As String = "ABPE_SPA_UrlGetSalesOrder"
Const C_A_CONFIG_DPC_TO_BI_LOCKED As String = "DPC_TO_BI_LOCKED"

'******** Curseur de connexion
#If ENV = LIVE Then
Private mo_Sys As Object
Private mo_Db As Object
Private mo_FSO As Object
#Else
Private mo_Sys As ARMSYSCOMLib.ArmSYS
Private mo_Db As ARMSYSCOMLib.ArmDb
Private mo_FSO As Scripting.FileSystemObject
#End If


Private mo_Tools As DPC_Tools

Private Const SEP1 As String = "®"
Private Const SEP2 As String = "©"

Private mb_Created As Boolean
Private ms_ConnectString As String
Private ml_U_Code As Long
Private ms_LoginName As String
Private mo_A_Config As Dictionary

Private mt_CstValues As type_CstValues         ' Structure which contains constants value
Private mi_DisplayMode As Variant       ' Current display mode
Private mi_OldDisplayMode As Variant    ' Old display mode, need for know parameters
Private mi_EmbeddedIn As Long        ' Indicates the tag  of the component which embed this component
Private mi_EmbedTag As Long          ' Indicates the tag of the last component embedded
Private mi_CptTag As Long            ' Tag of the component type
Private mb_Root As Boolean              ' Indicates if the component is the focus of the user
Private ml_DisplayModeSubItem As Long       ' Current display mode

'******** Clé en cours (enreg. en cours de visu ou modif ou delete
Private m_CurrentKey1 As String
Private m_CurrentKey2 As String
Private m_CurrentKey3 As String
Private ml_iConcurrency As Long
Private mb_IsProduction As Boolean

Private ms_Language_Code As String
Private m_projectStatus As Variant

'******** Type de l'objet (1=Normal, liste longue; 2=Liste courte)
Private mi_TypeList As Long
Private mi_TypeParam As Long

Private m_Project As String 'For the property .Project, display in ShortList
Private m_Contact As String 'For the property .Contact, display in ShortList
Private m_Customer As String 'For the property .Customer, display in ShortList
Private m_Action As String 'For the property .Action, display in ShortList
Private m_Product As String 'For the property .Product, display in ShortList
Private mb_EmbeddedIsDropped As Boolean '298.2

'Ask the application to change the size of component
Public Event SwitchToView(ByVal li_View As Integer)
' Ask the application to simulate encapsulation of a component by resizing it and push it to front
Public Event Catch(ByVal li_TagEmbedded As Long, ByVal ls_Param As String)
' Ask the application to release the encapsulation : hide the component embedded
Public Event Release()
Public Event quit()
Public Event HideGrid(AParentID As Integer)
Public Event Updated() ' Indicates if user update date when it's embedded
Public Event IsOfferLocked(ByRef ab_IsLocked As Boolean) ' offer check in parent component if any other offer is locked in capture

Public Event ProjectStatusChanged(ByVal as_project As String, ByVal ae_newStatus As Variant)
Public Event OfferGridMove(ByVal al_Direction As Long)

Private p_DefaultValues(MAX_VALUE) As DefaultValue
Private p_DefaultValuesCount As Long
Private p_DefaultValuesLoaded As Boolean

Private mb_InternalInit As Boolean
Private mb_CurrentTextBoxChanged As Boolean
Private mb_TemplateDownloaded As Boolean
Private mb_grd_ProductsLoaded As Boolean
Private mo_OfferPos As DPC_OfferPos
Private md_OfferCost                  As Double
Private md_OfferPrice                 As Double
Private md_TotalCost                  As Double
Private md_TotalPrice                 As Double
Private mb_HasLevel2 As Boolean
Private mb_HasPriceMan As Boolean
Private mb_HasOfferManual As Boolean
Private mb_grd_ShowDetail As Boolean
Private ms_DecimalSeparator As String
Private ms_ThousandSeparator As String
Private mc_ScreenLabels As Long
Private mc_Toolbars As Long
Private mo_WshNetwork As Object
Private ms_ComputerName As String
Private ms_Caption As String
Private mb_Initialized As Boolean
Private ms_CT_Code As String
Private md_ValidityDate As Date
Private ms_COF_Lang As String
Private ml_COT_Id As Long
'Private md_COF_DocDat As Date
Private mo_BaeurerTextBox As VB.TextBox
Private mo_BaeurerLabel As VB.Label
Private mo_ExternalGrid As ArmGrid
'Private me_PriceBookType As eDPCPriceBookType

Private Const VALUE_FORMAT As String = "###0.00"
Private Const MONEY_FORMAT As String = "###0.00"
Private COLOR_PARENT As Long
Private COLOR_CHILD As Long

Const SIFYB_CM_ERROR_MESSAGE = 8000                 ' const for base of error messages ids

Private Enum ErrMsg
    ErrMsgNone = 0
    ErrMsgMandatoryAreEmpty = SIFYB_CM_ERROR_MESSAGE + 1
    ErrMsgDuplicateOrder = SIFYB_CM_ERROR_MESSAGE + 2
    ErrMsgDuplicateLevel = SIFYB_CM_ERROR_MESSAGE + 3
    ErrMsgNumericRequired = SIFYB_CM_ERROR_MESSAGE + 5
    ErrMsgItemIsDeleted = SIFYB_CM_ERROR_MESSAGE + 19
    ErrMsgUpdateDeletedSPA = SIFYB_CM_ERROR_MESSAGE + 27
    ErrMsg_M000 = SIFYB_CM_ERROR_MESSAGE + 0                ' undefined message
    ErrMsg_M110 = SIFYB_CM_ERROR_MESSAGE + 110              'You cannot edit this SPA because the current status is not NEW.
    ErrMsg_M120 = SIFYB_CM_ERROR_MESSAGE + 120              'You cannot delete this SPA because the current Status is not NEW or SUBMITTED for approval
    ErrMsg_M130 = SIFYB_CM_ERROR_MESSAGE + 130              'You cannot email this SPA because the status is not APPROVED
    ErrMsg_M150 = SIFYB_CM_ERROR_MESSAGE + 150              'This email address does not appear to be the correct format (User@domain)
    ErrMsg_M160 = SIFYB_CM_ERROR_MESSAGE + 160              'You cannot submit this SPA for approval because the current status is not NEW.
    ErrMsg_M170 = SIFYB_CM_ERROR_MESSAGE + 170              'You cannot submit this SPA for approval because it contains no item lines
    ErrMsg_M190 = SIFYB_CM_ERROR_MESSAGE + 190              'You do not not have rights on this customers market
    ErrMsg_M200 = SIFYB_CM_ERROR_MESSAGE + 200              'The requestor does not have rights on this customers market
    ErrMsg_M201 = SIFYB_CM_ERROR_MESSAGE + 201              'Selected requestor is not defined as owner of a customer.
    ErrMsg_M210 = SIFYB_CM_ERROR_MESSAGE + 210              'You cannot use this customer as the customer is not a buying customer
    ErrMsg_M220 = SIFYB_CM_ERROR_MESSAGE + 220              'You do not not have rights on this projects market
    ErrMsg_M230 = SIFYB_CM_ERROR_MESSAGE + 230              'The requestor does not have rights on this projects market
    ErrMsg_M240 = SIFYB_CM_ERROR_MESSAGE + 240              'The Valid from date must be less than or equal to the Valid to date
    ErrMsg_M250 = SIFYB_CM_ERROR_MESSAGE + 250              'The Valid to date must be greater than today
    ErrMsg_M260 = SIFYB_CM_ERROR_MESSAGE + 260              'The SAP Item $BI_SAP_CODE$ is not sold in the market of the customer
    ErrMsg_M270 = SIFYB_CM_ERROR_MESSAGE + 270              'The SPA requestor is not authorised to raise an SPA for SAP Item $BI_SAP_CODE$ because of authorised market restiction. Contact the SPA System administrator
    ErrMsg_M280 = SIFYB_CM_ERROR_MESSAGE + 280              'The SAP Item $BI_SAP_CODE$ is not configured in a product group for the SPA's authorisation market. Contact the SPA System administrator
    ErrMsg_M300 = SIFYB_CM_ERROR_MESSAGE + 300              'The Field $FIELD_NAME$ must be entered
    ErrMsg_M330 = SIFYB_CM_ERROR_MESSAGE + 330              'This SPA cannot be marked used because the status is not RELEASED
    ErrMsg_M340 = SIFYB_CM_ERROR_MESSAGE + 340              'This SPA must be SUBMITTED before it can be APPROVED
    ErrMsg_M350 = SIFYB_CM_ERROR_MESSAGE + 350              'This SPA does not require your approval at this time
    ErrMsg_M360 = SIFYB_CM_ERROR_MESSAGE + 360              'Do you really want to delete this record
    ErrMsg_M370 = SIFYB_CM_ERROR_MESSAGE + 370              'This SAP item cannot appear in this SPA twice
    ErrMsg_M650 = SIFYB_CM_ERROR_MESSAGE + 650              'This SPA cannot be marked used because the status is not APPROVED
    ErrMsg_M701 = SIFYB_CM_ERROR_MESSAGE + 701              'SAP say:$SAP_MSG$ /n do you want to continue without prices?
    ErrMsg_M702 = SIFYB_CM_ERROR_MESSAGE + 702              'SAP service error: $SAP_MSG$
    ErrMsg_M703 = SIFYB_CM_ERROR_MESSAGE + 703              'SAP service unexpected response: $SAP_MSG$
    ErrMsg_M704 = SIFYB_CM_ERROR_MESSAGE + 704              'SAP service not responding ($SAP_MSG$)
    ErrMsg_M705 = SIFYB_CM_ERROR_MESSAGE + 705              'Country is not linked to any market
    ErrMsg_M706 = SIFYB_CM_ERROR_MESSAGE + 706              'This phone number does not appear to be the correct format (00xxx)
    ErrMsg_M724 = SIFYB_CM_ERROR_MESSAGE + 724              'The field $FIELD_NAME$ must be between $C_MIN_VAL$ and $C_MAX_VAL$.
    ErrMsg_M725 = SIFYB_CM_ERROR_MESSAGE + 725              'You are not releaser for the market of SPA
    ErrMsg_M726 = SIFYB_CM_ERROR_MESSAGE + 726              'Sales rep is not defined as Aprrover for the country of SPA
    ErrMsg_M727 = SIFYB_CM_ERROR_MESSAGE + 727              'The Approved by date must be equal or greater than today
End Enum

Public Property Set ArmDb(ByRef ao_Db As Object)
On Error GoTo ErrorHandler

  Set mo_Db = ao_Db
  Exit Property
ErrorHandler:
  Call ErrorHandler("ArmDb.Set")
End Property

Public Property Set Tools(ByRef ao_Tools As Object)
On Error GoTo ErrorHandler

  Set mo_Tools = ao_Tools
  Exit Property
ErrorHandler:
  Call ErrorHandler("Tools.Set")
End Property

Public Property Let Language(as_Language As String)
On Error GoTo ErrHandler
  
  ms_Language_Code = as_Language
  Exit Property
ErrHandler:
  Call ErrorHandler("Language.Let")
End Property

Public Property Get Language() As String
On Error GoTo ErrHandler
  
  Language = ms_Language_Code
  Exit Property
ErrHandler:
  Call ErrorHandler("Language.Get")
End Property

Public Property Let U_Code(ByVal al_U_Code As Long)
On Error GoTo ErrorHandler

  ml_U_Code = al_U_Code
  Exit Property
ErrorHandler:
  Call ErrorHandler("U_Code.Let")
End Property

Public Property Let LoginName(ByVal as_Value As String)
On Error GoTo ErrorHandler

  ms_LoginName = as_Value
  Exit Property
ErrorHandler:
  Call ErrorHandler("LoginName.Let")
End Property

Public Property Let Caption(ByVal as_Value As String)
On Error GoTo ErrHandler
    
  ms_Caption = as_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("Caption.Let")
End Property

Public Property Get Caption() As String
On Error GoTo ErrHandler
    
  Caption = ms_Caption
  Exit Property
ErrHandler:
  Call ErrorHandler("Caption.Get")
End Property

Public Property Let Name(ByVal as_Value As String)
On Error GoTo ErrHandler
    
  UserControl.Extender.Name = as_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("Name.Let")
End Property

Public Property Get Name() As String
On Error GoTo ErrHandler
    
  Name = UserControl.Extender.Name
  Exit Property
ErrHandler:
  Call ErrorHandler("Name.Get")
End Property

Public Property Let Tag(ByVal as_Value As String)
On Error GoTo ErrHandler
    
  UserControl.Tag = as_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("Tag.Let")
End Property

Public Property Get Tag() As String
On Error GoTo ErrHandler
    
  Tag = UserControl.Tag
  Exit Property
ErrHandler:
  Call ErrorHandler("Tag.Get")
End Property

Public Property Let Visible(ByVal aVisible As Boolean)
On Error GoTo ErrHandler
    
  UserControl.Extender.Visible = aVisible
  Exit Property
ErrHandler:
  Call ErrorHandler("Visible.Let")
End Property

Public Property Get Visible() As Boolean
On Error GoTo ErrHandler
    
  Visible = UserControl.Extender.Visible
  Exit Property
ErrHandler:
  Call ErrorHandler("Visible.Get")
End Property

Public Property Let Top(ByVal aTop As Single)
On Error GoTo ErrHandler
    
  UserControl.Extender.Top = aTop
  Exit Property
ErrHandler:
  Call ErrorHandler("Top.Let")
End Property

Public Property Get Top() As Single
On Error GoTo ErrHandler
    
  Top = UserControl.Extender.Top
  Exit Property
ErrHandler:
  Call ErrorHandler("Top.Get")
End Property

Public Property Let Height(ByVal aHeight As Single)
On Error GoTo ErrHandler
    
  UserControl.Extender.Height = aHeight
  Exit Property
ErrHandler:
  Call ErrorHandler("Height.Let")
End Property

Public Property Get Height() As Single
On Error GoTo ErrHandler
    
  Height = UserControl.Extender.Height
  Exit Property
ErrHandler:
  Call ErrorHandler("Height.Get")
End Property

Public Property Let Left(ByVal aLeft As Single)
On Error GoTo ErrHandler
    
  UserControl.Extender.Left = aLeft
  Exit Property
ErrHandler:
  Call ErrorHandler("Left.Let")
End Property

Public Property Get Left() As Single
On Error GoTo ErrHandler
    
  Left = UserControl.Extender.Left
  Exit Property
ErrHandler:
  Call ErrorHandler("Left.Get")
End Property

Public Property Let Width(ByVal aWidth As Single)
On Error GoTo ErrHandler
    
  UserControl.Extender.Width = aWidth
  Exit Property
ErrHandler:
  Call ErrorHandler(".Let")
End Property

Public Property Get Width() As Single
On Error GoTo ErrHandler
    
  Width = UserControl.Extender.Width
  Exit Property
ErrHandler:
  Call ErrorHandler("Width.Get")
End Property

Public Sub Move(ByVal aLeft As Single, ByVal aTop As Single, ByVal aWidth As Single, ByVal aHeight As Single)
On Error GoTo ErrHandler
  
  Call UserControl.Extender.Move(aLeft, aTop, aWidth, aHeight)
  Exit Sub
ErrHandler:
  Call ErrorHandler("Move")
End Sub

Public Property Let Enabled(ByVal ab_Value As Boolean)
On Error GoTo ErrHandler

  UserControl.Enabled = ab_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("Enabled.Let")
End Property

Public Property Get Enabled() As Boolean
 On Error GoTo ErrHandler

   Enabled = UserControl.Enabled
  Exit Property
ErrHandler:
  Call ErrorHandler("Enabled.Get")
End Property

Public Sub Zorder()
On Error GoTo ErrHandler

    Call UserControl.Extender.Zorder
  Exit Sub
ErrHandler:
  Call ErrorHandler("Zorder")
End Sub

Public Sub Refresh()
On Error GoTo ErrHandler

    Call UserControl.Refresh
  Exit Sub
ErrHandler:
  Call ErrorHandler("Refresh")
End Sub

Public Property Get hwnd() As Long
On Error GoTo ErrHandler
  
  hwnd = UserControl.hwnd
  Exit Property
ErrHandler:
  Call ErrorHandler("hwnd.Get")
End Property

Public Property Get Initialized() As Boolean
On Error GoTo ErrHandler
    
  Initialized = mb_Initialized
  Exit Property
ErrHandler:
  Call ErrorHandler("Initialized.Get")
End Property

Public Property Let ConnectString(ByVal as_Value As String)
On Error GoTo ErrHandler
    
  ms_ConnectString = as_Value
  'Check if the connection string is valid
  ms_LoginName = ConnectionStringValidation(as_Value)
  Exit Property
ErrHandler:
  Call ErrorHandler("ConnectString.Let")
End Property

Public Property Get CT_Code() As String
    CT_Code = ms_CT_Code
End Property

Public Property Get CURR_Code() As String
  
  CURR_Code = mo_Tools.GetComboKey(cbo_currencies)
End Property

Public Property Get ValidityDate() As Date
    ValidityDate = md_ValidityDate
End Property

Public Property Get COF_DocDat() As Date
On Error GoTo ErrHandler

  If cal_COF_DocDat.date_dt = 0 Then
    COF_DocDat = Date
  Else
    COF_DocDat = cal_COF_DocDat.date_dt
  End If
  Exit Property
ErrHandler:
  Call ErrorHandler("COF_DocDat.Get")
End Property

Public Property Let IsProduction(ByVal ab_Value As Boolean)
On Error GoTo ErrHandler
  mb_IsProduction = ab_Value
  Exit Property
ErrHandler:
  Call ErrorHandler("IsProduction.Let")
End Property

Public Property Get IsProduction() As Boolean
On Error GoTo ErrHandler
  IsProduction = mb_IsProduction
  Exit Property
ErrHandler:
  Call ErrorHandler("IsProduction.Get")
End Property

Public Property Set ExternalGrid(ByVal ao_grid As ArmGrid)
On Error GoTo ErrHandler

  Set mo_ExternalGrid = ao_grid
  Exit Property
ErrHandler:
  Call ErrorHandler("ExternalGrid.Set")
End Property

Public Property Let Status(ByVal al_Value As eOfferStatus)
On Error GoTo ErrHandler

  Call cbo_Status.SearchItem(al_Value)
  Exit Property
ErrHandler:
  Call ErrorHandler("Status.Let")
End Property

Public Property Get Status() As eOfferStatus
 On Error GoTo ErrHandler

  If Not mo_Tools Is Nothing Then
    Status = mo_Tools.GetComboKey(cbo_Status)
  End If
  Exit Property
ErrHandler:
  Call ErrorHandler("Status.Get")
End Property

Public Property Get IsSalesOrder() As Boolean
 On Error GoTo ErrHandler

  IsSalesOrder = (Status = eOfferStatus.osBaeurerSalesOrder) Or (Status = eOfferStatus.osSAPSalesOrder)
  Exit Property
ErrHandler:
  Call ErrorHandler("IsSalesOrder.Get")
End Property

Public Property Get IsSalesOrderChange() As Boolean
 On Error GoTo ErrHandler

  IsSalesOrderChange = (Status = eOfferStatus.osBaeurerSalesOrderChange) Or (Status = eOfferStatus.osSAPSalesOrderChange)
  Exit Property
ErrHandler:
  Call ErrorHandler("IsSalesOrderChange.Get")
End Property


' Initialization of the component
Public Sub Load_A_COM(ab_root As Boolean)
On Error GoTo ErrHandler
  
Dim ls_req As String
Dim ll_Idx As Long

  VerifyInitialization mo_Db, ms_ConnectString, ms_Language_Code, Me
  
  If mo_Db Is Nothing Then
      Call Err.Raise(ArmErr.PropertyNotSet)
  End If
  
  If mo_Tools Is Nothing Then
      Call Err.Raise(ArmErr.PropertyNotSet)
  End If
  
  'Set mo_Tools = New DPC_Tools
  'Set mo_Tools.ArmDb = mo_Db
  'Call mo_Tools.Load_A_COM
  
  Call mo_Tools.Load_A_ComControls(UserControl.Controls, mo_Db, ms_Language_Code)
  
  ms_ThousandSeparator = mo_Tools.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND)
  ms_DecimalSeparator = Format(0, ".")
  mc_Toolbars = 0
  
  Set mo_FSO = CreateObject("Scripting.FileSystemObject")
  
#If ENV = LIVE Then
  Set mo_Sys = CreateObject("ArmSYSCOM.ArmSys")
#Else
  Set mo_Sys = New ARMSYSCOMLib.ArmSYS
#End If
  
  Set mo_WshNetwork = CreateObject("WScript.Network")
  ms_ComputerName = mo_WshNetwork.ComputerName
  
  Set mo_OfferPos = New DPC_OfferPos
  Set mo_OfferPos.Tools = mo_Tools
  
  COLOR_PARENT = RGB(220, 195, 230)
  COLOR_CHILD = vbWindowBackground
  
  mi_EmbeddedIn = -1  '   Component is not embedded by someone
  mi_EmbedTag = -1    '   Component embed none component
  
  mb_Root = False     ' Component is not the default focus
  mb_InternalInit = False
  mb_CurrentTextBoxChanged = False
  mb_grd_ShowDetail = False
  
  Set mo_A_Config = New Dictionary
  mo_A_Config.CompareMode = TextCompare
  grdlst.MultiSelect = False
  
  Call iml_Icons.ListImages.Clear
  Call iml_Icons.ListImages.Add(, , LoadResPicture("ERRORTYPE1", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("ERRORTYPE2", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("ERRORTYPE3", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("LEVEL1", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("LEVEL2", vbResBitmap))
  Call iml_Icons.ListImages.Add(, , LoadResPicture("LEVEL3", vbResBitmap))
  
  ReDim la_Columns(12)
  la_Columns(0) = "COF_ID" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "COF_ID" & CH_LDELIMIT & ""
  la_Columns(1) = "COF_Code" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Code" & CH_LDELIMIT & "#Code"
  la_Columns(2) = "Z_Creation" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Creation" & CH_LDELIMIT & "#Date"
  la_Columns(3) = "SPR_Name" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SPR_Name" & CH_LDELIMIT & "#Sub project"
  la_Columns(4) = "CCU_Desc" & CH_LDELIMIT & "3000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CCU_Desc" & CH_LDELIMIT & "#Customer"
  la_Columns(5) = "COF_TypeDesc" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_TypeDesc" & CH_LDELIMIT & "#Offer type"
  la_Columns(6) = "COF_Vers" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Vers" & CH_LDELIMIT & "#Version"
  la_Columns(7) = "COF_Stat" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_Stat" & CH_LDELIMIT & ""
  la_Columns(8) = "COF_StatDesc" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_StatDesc" & CH_LDELIMIT & "#Status"
  la_Columns(9) = "COF_ExDat" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_ExDat" & CH_LDELIMIT & "#Valid to"
  la_Columns(10) = "Z_Creator" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Creator" & CH_LDELIMIT & "#Creator"
  la_Columns(11) = "Z_Last_Upd_User" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Last_Upd_User" & CH_LDELIMIT & ""
  la_Columns(12) = "Z_Last_Upd" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Z_Last_Upd" & CH_LDELIMIT & ""
  Call grdlst.SetColumns(la_Columns)
  grdlst.AllowExcelExport = True
  grdlst.ExportOnlyVisibleColumns = True
    
  ls_req = "exec A_References_ML_Lst $GR_Code$, $Language_Code$"
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_TOF1.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferDeliveryConditions), , , vbTextCompare)
  cbo_TOF2.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferPayementConditions), , , vbTextCompare)
  cbo_Probability.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferProbability), , , vbTextCompare)
  cbo_BuiltStatus.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferBuiltStatus), , , vbTextCompare)
  cbo_AltQuote.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferAltQuote), , , vbTextCompare)
  cbo_MainFamily.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferMainFamily), , , vbTextCompare)
  cbo_MainLevel.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferMainLevel), , , vbTextCompare)
  cbo_Specification.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferSpecification), , , vbTextCompare)
    
  cbo_Status.Request = Replace(ls_req, "$GR_Code$", mo_Tools.SqlInt(eDPCReferenceML.rfOfferStatus), , , vbTextCompare)
  Call cbo_Status.Load
  
  Set cbo_Level.ImageList = iml_Icons
  cbo_Level.Request = "SELECT LEV_Id, '' as LEV_Name,(LEV_Id+3) as bitmap FROM DPC_Level WHERE Drop_Flag='' ORDER BY LEV_Order"
  Call cbo_Level.Load
  
  ls_req = "exec currencies_cbo $Language_Code$"
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_currencies.Request = ls_req
  
  ls_req = "exec countries_cbo $Language_Code$"
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_COF_DeCT.Request = ls_req
  cbo_COF_DeCT.FirstBlankItem = True
  
  ls_req = "exec Cap_OfferTemplate_cbo $CT_Code$"
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_Template.Request = ls_req
  ml_COT_Id = 0
  ms_CT_Code = ""
  ms_COF_Lang = ms_Language_Code
  
  ls_req = "exec GEN_LegalEntity_cbo"
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_LegalEntity.Request = ls_req
  
  ls_req = "exec DPC_PM_Office_cbo $COF_Lang$"
  ls_req = ReplaceCommonPlaceholders(ls_req)
  cbo_PM_Office.Request = ls_req
  
  Call InitUserCombo(cbo_COF_AppBy, "DPC_LEVEL2")
  'cbo_COF_AppBy.Request = _
  '  "SELECT GSU.U_Code,GSU.U_Login_Name " & _
  '  "FROM GEN_Systems_Users GSU " & _
  '  "INNER JOIN security_alias SA ON (GSU.U_Login_Name=SA.Login_Name) " & _
  '  "WHERE SA.Alias='DPC_LEVEL2'"
  Call InitUserCombo(cbo_U_CodeSlsRep, "")
  Call InitUserCombo(cbo_U_CodePrjMan, "")
  Call InitUserCombo(cbo_U_CodePrdMan, "DPC_PRODUCTION")
  
  mb_HasLevel2 = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_LEVEL2")
  'mb_IsProduction = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PRODUCTION")
  mb_HasPriceMan = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PRICEMAN")
  mb_HasOfferManual = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_OFFERMANUAL")
  
  'Call InitVendorCombo(cbo_Vendor)
  'Call InitShipPointCombo(cbo_ShipPoint)
  
  md_ValidityDate = Now
  'md_COF_DocDat = Now
  Call mo_Tools.SetCalendarDate(cal_COF_DocDat, Date)
  txt_SKUPrice.Locked = True
  txt_SKUPrice.BackColor = vbButtonFace
  
  ReDim la_Columns(140) As Variant
  la_Columns(0) = "OFD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "OFD_Id" & CH_LDELIMIT & ""
  la_Columns(1) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
  la_Columns(2) = "Selected" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Selected" & CH_LDELIMIT & "#Sel" & CH_LDELIMIT & "BITMAP"
  la_Columns(3) = "OFD_Pos" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(4) = "OFD_PosCus" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PosCus" & CH_LDELIMIT & "#Pos cus."
  la_Columns(5) = "LEV_IdBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEV_IdBMP" & CH_LDELIMIT & "#Level" & CH_LDELIMIT & "BITMAP"
  la_Columns(6) = "Err_TypeBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Err_TypeBMP" & CH_LDELIMIT & "#Err" & CH_LDELIMIT & "BITMAP"
  la_Columns(7) = "STA_BOMBMP" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_BOMBMP" & CH_LDELIMIT & "#BOM" & CH_LDELIMIT & "BITMAP"
  la_Columns(8) = "STA_BORBMP" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_BORBMP" & CH_LDELIMIT & "#BOR" & CH_LDELIMIT & "BITMAP"
  la_Columns(9) = "STA_Desc" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "STA_Desc" & CH_LDELIMIT & "#Status"
  
  la_Columns(10) = "RPL_DrwNr" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_DrwNr" & CH_LDELIMIT & "#Drawing Nr."
  la_Columns(11) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#AMC Code"
  la_Columns(12) = "PRD_Name" & CH_LDELIMIT & "1900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(13) = "OFD_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Qty" & CH_LDELIMIT & "#Quantity"
  la_Columns(14) = "UM_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Code" & CH_LDELIMIT & "#Unit of measure"
  la_Columns(15) = "UM_Name" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Name" & CH_LDELIMIT & "#Unit of measure"
  
  la_Columns(16) = "RPL_ModA" & CH_LDELIMIT & "750" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_ModA" & CH_LDELIMIT & "#Module (L)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(17) = "RPL_ModB" & CH_LDELIMIT & "750" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_ModB" & CH_LDELIMIT & "#Module (W)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(18) = "RPL_PanA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanA" & CH_LDELIMIT & "#Panel (L)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(19) = "RPL_PanB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PanB" & CH_LDELIMIT & "#Panel (W)" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  
  la_Columns(20) = "RPL_StdMa" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_StdMa" & CH_LDELIMIT & "#Std. mat." & CH_LDELIMIT & "BITMAP"
  la_Columns(21) = "MAT_Name" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "MAT_Name" & CH_LDELIMIT & "#Material"
  la_Columns(22) = "RPL_MatTyp" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_MatTyp" & CH_LDELIMIT & "#Mat.type"
  la_Columns(23) = "RPL_Thick" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_Thick" & CH_LDELIMIT & "#Thickness" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  
  la_Columns(24) = "RPL_SBndA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SBndA" & CH_LDELIMIT & "#St.A" & CH_LDELIMIT & "BITMAP"
  la_Columns(25) = "RPL_SUZA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SUZA" & CH_LDELIMIT & "#St.UZA" & CH_LDELIMIT & "BITMAP"
  la_Columns(26) = "RPL_SBndB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SBndB" & CH_LDELIMIT & "#St.B" & CH_LDELIMIT & "BITMAP"
  la_Columns(27) = "RPL_SUZB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SUZB" & CH_LDELIMIT & "#St.UZB" & CH_LDELIMIT & "BITMAP"
  
  la_Columns(28) = "BND_NameC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameC" & CH_LDELIMIT & "#Side C"
  la_Columns(29) = "RPL_HC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HC" & CH_LDELIMIT & "#HC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(30) = "RPL_UMinC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UMinC" & CH_LDELIMIT & "#Min.UZC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(31) = "RPL_UMaxC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UMaxC" & CH_LDELIMIT & "#Max.UZC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(32) = "RPL_UC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UC" & CH_LDELIMIT & "#UZC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(33) = "RPL_NCloC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloC" & CH_LDELIMIT & "#Notch closed C" & CH_LDELIMIT & "BITMAP"
  la_Columns(34) = "RPL_BVisC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisC" & CH_LDELIMIT & "#Bend.vis. C" & CH_LDELIMIT & "BITMAP"
  
  la_Columns(35) = "BND_NameD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameD" & CH_LDELIMIT & "#Side D"
  la_Columns(36) = "RPL_HD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HD" & CH_LDELIMIT & "#HD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(37) = "RPL_UMinD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UMinD" & CH_LDELIMIT & "#Min.UZD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(38) = "RPL_UMaxD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UMaxD" & CH_LDELIMIT & "#Max.UZD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(39) = "RPL_UD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UD" & CH_LDELIMIT & "#UZD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(40) = "RPL_NCloD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloD" & CH_LDELIMIT & "#Notch closed D" & CH_LDELIMIT & "BITMAP"
  la_Columns(41) = "RPL_BVisD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisD" & CH_LDELIMIT & "#Bend.vis. D" & CH_LDELIMIT & "BITMAP"

  la_Columns(42) = "RPL_CoWMin" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoWMin" & CH_LDELIMIT & "#Coil min." & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(43) = "RPL_CoWMax" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoWMax" & CH_LDELIMIT & "#Coil max." & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(44) = "RPL_CoilW" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoilW" & CH_LDELIMIT & "#Coil used" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(45) = "RPL_IsCoCut" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_IsCoCut" & CH_LDELIMIT & "#Coil cut" & CH_LDELIMIT & "BITMAP"
  la_Columns(46) = "RPL_CutA" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CutA" & CH_LDELIMIT & "#Cut Length" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(47) = "RPL_CutB" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CutB" & CH_LDELIMIT & "#Cut Width" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(48) = "RPL_SC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SC" & CH_LDELIMIT & "#SC" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(49) = "RPL_SD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SD" & CH_LDELIMIT & "#SD" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(50) = "RPL_IsCoF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_IsCoF" & CH_LDELIMIT & "#Coil found" & CH_LDELIMIT & "BITMAP"
  la_Columns(51) = "BND_NameE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameE" & CH_LDELIMIT & "#Side E"
  la_Columns(52) = "RPL_HE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HE" & CH_LDELIMIT & "#HE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(53) = "RPL_UE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UE" & CH_LDELIMIT & "#UZE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(54) = "RPL_SE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SE" & CH_LDELIMIT & "#SE" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(55) = "RPL_NCloE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloE" & CH_LDELIMIT & "#Notch closed E" & CH_LDELIMIT & "BITMAP"
  la_Columns(56) = "RPL_BVisE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisE" & CH_LDELIMIT & "#Bend.vis. E" & CH_LDELIMIT & "BITMAP"
  la_Columns(57) = "BND_NameF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BND_NameF" & CH_LDELIMIT & "#Side F"
  la_Columns(58) = "RPL_HF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_HF" & CH_LDELIMIT & "#HF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(59) = "RPL_UF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UF" & CH_LDELIMIT & "#UZF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(60) = "RPL_SF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_SF" & CH_LDELIMIT & "#SF" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(61) = "RPL_NCloF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NCloF" & CH_LDELIMIT & "#Notch closed F" & CH_LDELIMIT & "BITMAP"
  la_Columns(62) = "RPL_BVisF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisF" & CH_LDELIMIT & "#Bend.vis. F" & CH_LDELIMIT & "BITMAP"
  
  
  la_Columns(63) = "PRF_Name" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRF_Name" & CH_LDELIMIT & "#Perforation"
  la_Columns(64) = "PRF_Class" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRF_Class" & CH_LDELIMIT & "#Perf.class"
  la_Columns(65) = "RPL_PBordDesc" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PBordDesc" & CH_LDELIMIT & "#Perf.bord"
  la_Columns(66) = "RPL_PSpTypDesc" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PStepDesc" & CH_LDELIMIT & "#Step type"
  la_Columns(67) = "RPL_PStep" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PStep" & CH_LDELIMIT & "#Step"

  la_Columns(68) = "RPL_UBoWC" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBoWC" & CH_LDELIMIT & "#W-C" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(69) = "RPL_UBoWD" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBoWD" & CH_LDELIMIT & "#W-D" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(70) = "RPL_UBoWE" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBoWE" & CH_LDELIMIT & "#W-E" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(71) = "RPL_UBoWF" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBoWF" & CH_LDELIMIT & "#W-F" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(72) = "RPL_UBorC" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorC" & CH_LDELIMIT & "#R-C" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(73) = "RPL_UBorD" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorD" & CH_LDELIMIT & "#R-D" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(74) = "RPL_UBorE" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorE" & CH_LDELIMIT & "#R-E" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(75) = "RPL_UBorF" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_UBorF" & CH_LDELIMIT & "#R-F" & CH_LDELIMIT & "STRING" & CH_LDELIMIT & CH_LDELIMIT & "RIGHT"
  la_Columns(76) = "CUT_Name1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name1" & CH_LDELIMIT & "#Cut 1"
  la_Columns(77) = "PCT_SizeJ1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ1" & CH_LDELIMIT & "#J1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(78) = "PCT_SizeK1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK1" & CH_LDELIMIT & "#K1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(79) = "PCT_SizeD1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD1" & CH_LDELIMIT & "#D1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(80) = "PCT_SizeL1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL1" & CH_LDELIMIT & "#L1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(81) = "PCT_SizeM1" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM1" & CH_LDELIMIT & "#M1" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(82) = "CUT_Name2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name2" & CH_LDELIMIT & "#Cut 2"
  la_Columns(83) = "PCT_SizeJ2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ2" & CH_LDELIMIT & "#J2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(84) = "PCT_SizeK2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK2" & CH_LDELIMIT & "#K2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(85) = "PCT_SizeD2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD2" & CH_LDELIMIT & "#D2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(86) = "PCT_SizeL2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL2" & CH_LDELIMIT & "#L2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(87) = "PCT_SizeM2" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM2" & CH_LDELIMIT & "#M2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(88) = "CUT_Name3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name3" & CH_LDELIMIT & "#Cut 3"
  la_Columns(89) = "PCT_SizeJ3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ3" & CH_LDELIMIT & "#J3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(90) = "PCT_SizeK3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK3" & CH_LDELIMIT & "#K3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(91) = "PCT_SizeD3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD3" & CH_LDELIMIT & "#D3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(92) = "PCT_SizeL3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL3" & CH_LDELIMIT & "#L3" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(93) = "PCT_SizeM3" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM3" & CH_LDELIMIT & "#M3"
  la_Columns(94) = "CUT_Name4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CUT_Name4" & CH_LDELIMIT & "#Cut 4"
  la_Columns(95) = "PCT_SizeJ4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeJ4" & CH_LDELIMIT & "#J4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(96) = "PCT_SizeK4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeK4" & CH_LDELIMIT & "#K4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(97) = "PCT_SizeD4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeD4" & CH_LDELIMIT & "#D4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(98) = "PCT_SizeL4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeL4" & CH_LDELIMIT & "#L4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(99) = "PCT_SizeM4" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCT_SizeM4" & CH_LDELIMIT & "#M4" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(100) = "COA_Name" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COA_Name" & CH_LDELIMIT & "#Coating"
  la_Columns(101) = "RPL_CoSidDesc" & CH_LDELIMIT & "1800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_CoSidDesc" & CH_LDELIMIT & "#Coating side"
  la_Columns(102) = "RPL_BVisC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisC" & CH_LDELIMIT & "#Vis.C" & CH_LDELIMIT & "BITMAP"
  la_Columns(103) = "RPL_BVisD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisD" & CH_LDELIMIT & "#Vis.D" & CH_LDELIMIT & "BITMAP"
  la_Columns(104) = "RPL_BVisE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisE" & CH_LDELIMIT & "#Vis.E" & CH_LDELIMIT & "BITMAP"
  la_Columns(105) = "RPL_BVisF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BVisF" & CH_LDELIMIT & "#Vis.F" & CH_LDELIMIT & "BITMAP"
  la_Columns(106) = "GSK_Exist" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Exist" & CH_LDELIMIT & "#Gasket" & CH_LDELIMIT & "BITMAP"
  la_Columns(107) = "GSK_NameC" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameC" & CH_LDELIMIT & "#Gsk C"
  la_Columns(108) = "GSK_NameD" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameD" & CH_LDELIMIT & "#Gsk D"
  la_Columns(109) = "GSK_NameE" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameE" & CH_LDELIMIT & "#Gsk E"
  la_Columns(110) = "GSK_NameF" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_NameF" & CH_LDELIMIT & "#Gsk F"
  la_Columns(111) = "GSK_Exist2" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Exist2" & CH_LDELIMIT & "#Spacer" & CH_LDELIMIT & "BITMAP"
  la_Columns(112) = "GSK_Name2C" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2C" & CH_LDELIMIT & "#Spc C"
  la_Columns(113) = "GSK_Name2D" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2D" & CH_LDELIMIT & "#Spc D"
  la_Columns(114) = "GSK_Name2E" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2E" & CH_LDELIMIT & "#Spc E"
  la_Columns(115) = "GSK_Name2F" & CH_LDELIMIT & "700" & CH_LDELIMIT & "0" & CH_LDELIMIT & "GSK_Name2F" & CH_LDELIMIT & "#Spc F"
  
  la_Columns(116) = "INL_Name1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name1" & CH_LDELIMIT & "#Inlay1"
  la_Columns(117) = "INL_Code1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code1" & CH_LDELIMIT & "#Inlay code1"
  la_Columns(118) = "PIN_PurchDesc1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc1" & CH_LDELIMIT & "#Purchase1"
  la_Columns(119) = "PIN_DelivDesc1" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc1" & CH_LDELIMIT & "#Delivery1"

  la_Columns(120) = "INL_Name2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name2" & CH_LDELIMIT & "#Inlay2"
  la_Columns(121) = "INL_Code2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code2" & CH_LDELIMIT & "#Inlay code2"
  la_Columns(122) = "PIN_PurchDesc2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc2" & CH_LDELIMIT & "#Purchase2"
  la_Columns(123) = "PIN_DelivDesc2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc2" & CH_LDELIMIT & "#Delivery2"
  
  la_Columns(124) = "INL_Name3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Name3" & CH_LDELIMIT & "#Inlay3"
  la_Columns(125) = "INL_Code3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "INL_Code3" & CH_LDELIMIT & "#Inlay code3"
  la_Columns(126) = "PIN_PurchDesc3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_PurchDesc3" & CH_LDELIMIT & "#Purchase3"
  la_Columns(127) = "PIN_DelivDesc3" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PIN_DelivDesc3" & CH_LDELIMIT & "#Delivery3"

  la_Columns(128) = "PKG_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PKG_Name" & CH_LDELIMIT & "#Packing"
  la_Columns(129) = "LAB_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LAB_Name" & CH_LDELIMIT & "#Label"
  la_Columns(130) = "RPL_PU" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PU" & CH_LDELIMIT & "#Packing unit"

  la_Columns(131) = "RPL_AGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_AGroup" & CH_LDELIMIT & "#Art grp"
  la_Columns(132) = "RPL_MGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_MGroup" & CH_LDELIMIT & "#Good grp"
  la_Columns(133) = "RPL_PGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PGroup" & CH_LDELIMIT & "#Prd grp"
  la_Columns(134) = "RPL_OGroup" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_OGroup" & CH_LDELIMIT & "#Obj grp"
  la_Columns(135) = "RPL_WghPnt" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_WghPnt" & CH_LDELIMIT & "#Wgh pnt"
  la_Columns(136) = "PRD_InternalComm" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_InternalComment" & CH_LDELIMIT & "#Int.comment"
  la_Columns(137) = "SHP_Name" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SHP_Name" & CH_LDELIMIT & "#Shipment point"
  la_Columns(138) = "RPL_NWgh" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_NWgh" & CH_LDELIMIT & "#Weight" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(139) = "RPL_BaeType" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_BaeType" & CH_LDELIMIT & "#B7 BaseType" & CH_LDELIMIT & "INT"
  la_Columns(140) = "RPL_PBord" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PBord" & CH_LDELIMIT & "#PerfBord" & CH_LDELIMIT & "INT"
  
  grd_PosList.AllowExcelExport = True
  Call grd_PosList.SetColumns(la_Columns)
  grd_PosList.FixedCols = "UM_Name"
  grd_PosList.ExportOnlyVisibleColumns = True
  
  ReDim la_Columns(24) As Variant
  la_Columns(0) = "Idx" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "Idx" & CH_LDELIMIT & ""
  la_Columns(1) = "OFD_Pos" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(2) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#Code" & CH_LDELIMIT & "STRING"
  la_Columns(3) = "PRD_Name" & CH_LDELIMIT & "1900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(4) = "OFD_QtyPCS" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_QtyPCS" & CH_LDELIMIT & "#PanelQty"
  la_Columns(5) = "UM_NamePCS" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_NamePCS" & CH_LDELIMIT & "UoM"
  la_Columns(6) = "RPL_PU" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RPL_PU" & CH_LDELIMIT & "#PU"
  
  la_Columns(7) = "PPA_PkgA" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PkgA" & CH_LDELIMIT & "#PkgA" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(8) = "PPA_PkgB" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PkgB" & CH_LDELIMIT & "#PkgB" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(9) = "PPA_PkgH" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PkgH" & CH_LDELIMIT & "#PkgH" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  
  la_Columns(10) = "PPA_PkgQty" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PkgQty" & CH_LDELIMIT & "#PkgQty"
  
  la_Columns(11) = "PPA_LayQtyA" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_LayQtyA" & CH_LDELIMIT & "#Layer A"
  la_Columns(12) = "PPA_LayQtyB" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_LayQtyB" & CH_LDELIMIT & "#Layer B"
  la_Columns(13) = "PPA_LayQtyH" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_LayQtyH" & CH_LDELIMIT & "#Layer H"
  
  la_Columns(14) = "PPA_PkgPalQty" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PkgPalQty" & CH_LDELIMIT & "#Pal/Pkg Qty"
  la_Columns(15) = "PPA_PalQty" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PalQty" & CH_LDELIMIT & "#Palette Qty"
  
  la_Columns(16) = "PPA_PkgNetWgh" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PkgNetWgh" & CH_LDELIMIT & "#Pkg netto weight" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(17) = "PPA_PalNetWgh" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PalNetWgh" & CH_LDELIMIT & "#Pal netto weight" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  
  la_Columns(18) = "PPA_PalCode" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PalCode" & CH_LDELIMIT & "#Palette code"
  la_Columns(19) = "PPA_PalName" & CH_LDELIMIT & "3000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PalName" & CH_LDELIMIT & "#Palette name"
  
  la_Columns(20) = "PPA_PalB" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_PalB" & CH_LDELIMIT & "#Palette width"
  
  la_Columns(21) = "PPA_CalcPalA" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_CalcPalA" & CH_LDELIMIT & "#Calc. pal.A" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(22) = "PPA_CalcPalB" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_CalcPalB" & CH_LDELIMIT & "#Calc. pal.B" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(23) = "PPA_CalcPalH" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_CalcPalH" & CH_LDELIMIT & "#Calc. pal.H" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  
  la_Columns(24) = "PPA_VolLoad" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PPA_VolLoad" & CH_LDELIMIT & "#Volumne load" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  Call grd_Packing.SetColumns(la_Columns)
  grd_Packing.AllowExcelExport = True
  grd_Packing.ExportOnlyVisibleColumns = True
  
  ReDim la_Columns(33) As Variant
  la_Columns(0) = "Idx" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "Idx" & CH_LDELIMIT & ""
  la_Columns(1) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
  la_Columns(2) = "OFD_Pos" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(3) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#BOM Nr" & CH_LDELIMIT & "STRING"
  la_Columns(4) = "PRD_Name" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(5) = "BOM_Pos" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Pos" & CH_LDELIMIT & "#Position"
  la_Columns(6) = "BOM_IdentNr" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_IdentNr" & CH_LDELIMIT & "#Code" & CH_LDELIMIT & "STRING"
  la_Columns(7) = "BOM_Name" & CH_LDELIMIT & "3500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Name" & CH_LDELIMIT & "#Name"
  la_Columns(8) = "BOM_Material" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Material" & CH_LDELIMIT & "#Material" & CH_LDELIMIT & "STRING"
  la_Columns(9) = "BOM_Qty" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Qty" & CH_LDELIMIT & "#Qty" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.000"
  la_Columns(10) = "BOM_QtyTotal" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_QtyTotal" & CH_LDELIMIT & "#Total Qty" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.000"
  la_Columns(11) = "UM_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Code" & CH_LDELIMIT & "#UoM"
  la_Columns(12) = "UM_Name" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Name" & CH_LDELIMIT & "#UoM"
  la_Columns(13) = "BOM_Cost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Cost" & CH_LDELIMIT & "#Cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(14) = "BOM_SalesPriceUnit" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_SalesPriceUnit" & CH_LDELIMIT & "#Sales unit"
  la_Columns(15) = "BOM_DirectCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_DirectCost" & CH_LDELIMIT & "#Direct cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(16) = "BOM_WasteFactor" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_WasteFactor" & CH_LDELIMIT & "#Waste factor" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(17) = "BOM_WasteCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_WasteCost" & CH_LDELIMIT & "#Waste cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(18) = "BOM_RejectFactor" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_RejectFactor" & CH_LDELIMIT & "#Reject factor" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(19) = "BOM_RejectCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_RejectCost" & CH_LDELIMIT & "#Reject cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(20) = "BOM_InflFactor" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_InflFactor" & CH_LDELIMIT & "#Infl factor" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(21) = "BOM_InflCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_InflCost" & CH_LDELIMIT & "#Infl cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(22) = "CURR_Code" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CURR_Code" & CH_LDELIMIT & "#Currency"
  la_Columns(23) = "BOM_Status" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Status" & CH_LDELIMIT & ""
  la_Columns(24) = "BOM_StatusDesc" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_StatusDesc" & CH_LDELIMIT & "#Status"
  la_Columns(25) = "BOM_SpecWeight" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_SpecWeight" & CH_LDELIMIT & "#Density" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.000"
  la_Columns(26) = "BOM_Productivity" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Productivity" & CH_LDELIMIT & "#Productivity" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.000"
  la_Columns(27) = "BOM_CutLength" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_CutLength" & CH_LDELIMIT & "#Cut length" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(28) = "BOM_CutWidth" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_CutWidth" & CH_LDELIMIT & "#Cut width" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(29) = "BOM_BOR_Pos" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_BOR_Pos" & CH_LDELIMIT & "#BOR Pos"
  la_Columns(30) = "BOM_Manual" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Manual" & CH_LDELIMIT & "#Manual"
  la_Columns(31) = "BOM_IdentNrTmp" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_IdentNrTmp" & CH_LDELIMIT & "#Tmp Nr" & CH_LDELIMIT & "STRING"
  la_Columns(32) = "BOM_Export" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_Export" & CH_LDELIMIT & "#Export"
  la_Columns(33) = "BOM_ExpDat" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOM_ExpDat" & CH_LDELIMIT & "#Export date"
  Call grd_BOM.SetColumns(la_Columns)
  grd_BOM.AllowExcelExport = True
  grd_BOM.ExportOnlyVisibleColumns = True
  
  ReDim la_Columns(38) As Variant
  la_Columns(0) = "Idx" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "Idx" & CH_LDELIMIT & ""
  la_Columns(1) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
  la_Columns(2) = "OFD_Pos" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(3) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#BOR Nr"
  la_Columns(4) = "PRD_Name" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(5) = "BOR_Pos" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Pos" & CH_LDELIMIT & "#Position"
  la_Columns(6) = "BOR_StagNr" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_StagNr" & CH_LDELIMIT & "#Operation Nr"
  la_Columns(7) = "BOR_Name" & CH_LDELIMIT & "3500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Name" & CH_LDELIMIT & "#Name"
  la_Columns(8) = "BOR_KostSt" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_KostSt" & CH_LDELIMIT & "#Cost place"
  la_Columns(9) = "BOR_Tr" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Tr" & CH_LDELIMIT & "#Base setup time"
  la_Columns(10) = "BOR_Brtr" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Brtr" & CH_LDELIMIT & "#Width setup time"
  la_Columns(11) = "BOR_Lgtr" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Lgtr" & CH_LDELIMIT & "#Length setup time"
  la_Columns(12) = "BOR_Te" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Te" & CH_LDELIMIT & "#Operation time" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(13) = "BOR_Lgrp" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Lgrp" & CH_LDELIMIT & "#Salary group"
  la_Columns(14) = "BOR_Anz_Bedien" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Anz_Bedien" & CH_LDELIMIT & "#Operator count"
  la_Columns(15) = "BOR_VarMasFact" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_VarMasFact" & CH_LDELIMIT & "#Var masch. fact" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.000"
  la_Columns(16) = "BOR_VarPerFact" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_VarPerFact" & CH_LDELIMIT & "#Var pers. fact" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.000"
  la_Columns(17) = "BOR_VarMasCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_VarMasCost" & CH_LDELIMIT & "#Var masch. cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(18) = "BOR_VarPerCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_VarPerCost" & CH_LDELIMIT & "#Var pers. cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(19) = "BOR_Teko" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Teko" & CH_LDELIMIT & "#Outsource cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(20) = "BOR_DirectCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_DirectCost" & CH_LDELIMIT & "#Direct cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(21) = "BOR_FixMasFact" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_FixMasFact" & CH_LDELIMIT & "#Fix masch. fact" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.000"
  la_Columns(22) = "BOR_FixMasCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_FixMasCost" & CH_LDELIMIT & "#Fix. masch. cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(23) = "BOR_WasteFact" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_WasteFact" & CH_LDELIMIT & "#Waste fact" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0"
  la_Columns(24) = "BOR_WasteCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_WasteCost" & CH_LDELIMIT & "#Waste cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(25) = "BOR_DirectSetupCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_DirectSetupCost" & CH_LDELIMIT & "#Direct stp cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(26) = "BOR_SubtotalSetupCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_SubtotalSetupCost" & CH_LDELIMIT & "#Subtot stp cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(27) = "BOR_TotSetupCost" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_TotSetupCost" & CH_LDELIMIT & "#Setup cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(28) = "BOR_DirectWidSetupCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_DirectWidSetupCost" & CH_LDELIMIT & "#Direct width stp cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(29) = "BOR_SubWidSetupCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_SubtotalWidSetupCost" & CH_LDELIMIT & "#Subtot width stp cost cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(30) = "BOR_TotWidSetupCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_TotWidSetupCost" & CH_LDELIMIT & "#Width setup cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(31) = "BOR_DirectLenSetupCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_DirectLenSetupCost" & CH_LDELIMIT & "#Direct length stp cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(32) = "BOR_SubLenSetupCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_SubtotalLenSetupCost" & CH_LDELIMIT & "#Subtot length stp cost cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(33) = "BOR_TotLenSetupCost" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_TotLenSetupCost" & CH_LDELIMIT & "#Length setup cost" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.00"
  la_Columns(34) = "CURR_Code" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CURR_Code" & CH_LDELIMIT & "#Currency"
  la_Columns(35) = "BOR_Status" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Status" & CH_LDELIMIT & ""
  la_Columns(36) = "BOR_StatusDesc" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_StatusDesc" & CH_LDELIMIT & "#Status"
  la_Columns(37) = "BOR_Manual" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_Manual" & CH_LDELIMIT & "#Manual"
  la_Columns(38) = "BOR_WghPnt" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "BOR_WghPnt" & CH_LDELIMIT & "#WghPnt"
  Call grd_BOR.SetColumns(la_Columns)
  grd_BOR.AllowExcelExport = True
  grd_BOR.ExportOnlyVisibleColumns = True
  
  ReDim la_Columns(10) As Variant
  la_Columns(0) = "Idx" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "Idx" & CH_LDELIMIT & ""
  la_Columns(1) = "OFD_Pos" & CH_LDELIMIT & "500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Pos"
  la_Columns(2) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#Code" & CH_LDELIMIT & "STRING"
  la_Columns(3) = "PRD_Name" & CH_LDELIMIT & "3500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
  la_Columns(4) = "RF_Desc" & CH_LDELIMIT & "2500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "RF_Desc" & CH_LDELIMIT & "#Cost"
  la_Columns(5) = "PCC_CostPCS" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCC_CostPCS" & CH_LDELIMIT & "#Cost/PCR" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(6) = "PCC_CostM2" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCC_CostM2" & CH_LDELIMIT & "#Cost/M2" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(7) = "PCC_DirSetupCost" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCC_DirectSetupCost" & CH_LDELIMIT & "#Direct setup" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(8) = "PCC_SubSetupCost" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCC_SubSetupCost" & CH_LDELIMIT & "#Subtotal setup" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(9) = "PCC_TotSetupCost" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PCC_TotSetupCost" & CH_LDELIMIT & "#Total setup" & CH_LDELIMIT & "FLOAT" & CH_LDELIMIT & "0.0000"
  la_Columns(10) = "CURR_Code" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CURR_Code" & CH_LDELIMIT & "#Currency"
  Call grd_Cost.SetColumns(la_Columns)
  grd_Cost.AllowExcelExport = True
  grd_Cost.ExportOnlyVisibleColumns = True
  
  ReDim la_Columns(1) As Variant
  la_Columns(0) = "Code" & CH_LDELIMIT & "500" & CH_LDELIMIT & "1" & CH_LDELIMIT & "Code" & CH_LDELIMIT & "#Code"
  la_Columns(1) = "Text" & CH_LDELIMIT & "2500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Text" & CH_LDELIMIT & "#Text"
  Call grd_Baeurer.SetColumns(la_Columns)
  grd_Baeurer.AllowExcelExport = True
  grd_Baeurer.ExportOnlyVisibleColumns = True
  grd_Baeurer.UnBound = True
  
  Call mo_Tools.LoadToolbars(mo_Db, UserControl.Controls, SCREEN_NAME)
  Call InitSubitem
  
  'mb_HasLevel2
  btn_BaurerSecretBoxExport.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PLANNIGBOX_EXPORT")
  btn_BaurerSecretBoxImport.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PLANNIGBOX_IMPORT")
  btn_BaurerSecretBoxKill.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PLANNIGBOX_KILL")
  btn_BaurerSalesOrderExport.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_B7SALESORDER_EXPORT")
  btn_BaurerSOChangeExport.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_B7SALESORDERCHANGE_EXPORT")
  cmd_KillOrderB7.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_B7SALESORDER_KILL")
  btn_GenerateGroupAndCE.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_B7GROUPCE_GENERATE")
  btn_XmlCust.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_B7CUSTOMER_EXPORT")
  btn_XmlPMaster.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_B7PMASTER_EXPORT")
  btn_PosListEdit.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PRODPOS_EDIT")
  cmd_MassEntry.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_MASSENTRY")
  btn_PosListCalcBOMBOR.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_BOMBOR_CALC")
  cmd_ExportRawMaterial.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_RAWMAT_EXPORT")
  cmd_RecalcCost.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PRODCOST_CALC")
  btn_RecalcPacking.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PRODPACKING_CALC")
  btn_PrintPacking.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PRODPACKING_PRINT")
  btn_PosListClearBOMBOR.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_BOMBOR_CLEAR")
  btn_ChangeAttribute.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_PRODATTRIB_CHANGE")
  
  btn_ExportMaterialCreate.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_SAPEXPORTMATERIALCREATE") 'mb_HasLevel2
  btn_ExportSalesOrderCreate.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_SAPSALESORDERCREATE") 'mb_HasLevel2
  btn_ExportSalesOrderCreateSim.Visible = mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_SAPSALESORDERCREATESIM") 'mb_HasLevel2
  'btn_ExportSalesOrderCancelAddReplace.Visible = mb_HasLevel2
  'btn_ExportActionAdd.Visible = mb_HasLevel2
  'btn_ExportActionDelete.Visible = mb_HasLevel2
  'btn_ExportActionReplace.Visible = mb_HasLevel2
  'btn_ExportActionReset.Visible = mb_HasLevel2
  'btn_ExportActionDeleteCancelPrereservation.Visible = mb_HasLevel2
  
  cal_COF_FoDat.opening_toward_top = 1
  cal_COF_ExDat.opening_toward_top = 1
  cal_COF_ApDat.opening_toward_top = 1
  cal_COF_DocDat.opening_toward_top = 1
  cal_COF_DocDat.date_locked = True
  
  For ll_Idx = 0 To fra_Header.Count - 1
    fra_Header(ll_Idx).Visible = False
  Next
  'Screen csts
  mc_ScreenLabels = mo_Tools.LoadLabels(mo_Db, UserControl.Controls, Me, SCREEN_NAME, ms_Language_Code)
  Call mo_Tools.ChangeCharset(UserControl.Controls, gl_CodePage, mo_Tools.GetCodePageFromLanguage(mo_Db, ms_COF_Lang))
  mb_Initialized = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("Load_A_Com")
End Sub

' Release the memory used
Public Sub Unload_A_COM()
On Error GoTo ErrHandler
    
  Call mo_Tools.Unload_A_ComControls(UserControl.Controls)
  'Call mo_Tools.Unload_A_COM
  Call mo_Db.Close(mc_ScreenLabels)
  Set mo_FSO = Nothing
  Set mo_Db = Nothing
  Set mo_Tools = Nothing
  Set mo_OfferPos = Nothing
  Set mo_A_Config = Nothing
  Set mo_BaeurerTextBox = Nothing
  Set mo_BaeurerLabel = Nothing
  Exit Sub
ErrHandler:
  Call ErrorHandler("Unload_A_Com")
End Sub

Public Sub CreateOffer(ByVal al_OfferType As Long, ByVal as_SPR_Id As String, ByVal as_SPR_Name As String)
On Error GoTo ErrHandler

  Call tlb_Main_action("A", ms_Language_Code)
  Call cbo_SubProject.AddItem(Array(as_SPR_Id, as_SPR_Name), True)
  opt_OfferType(al_OfferType - 1).Value = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("CreateOffer")
End Sub

Public Sub GoToTab1()
On Error GoTo ErrHandler
    
  If UserControl.tbsEmbedded.Tabs.Count > 0 Then
      UserControl.tbsEmbedded.Tabs(1).Selected = True
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("GoToTab1")
End Sub

Private Sub Add_Resize()
On Error GoTo ErrHandler

Dim ll_Idx As Long

  With UserControl
      
    .fraItem.Left = mt_CstValues.Frm_Spacing
    .fraItem.Top = mt_CstValues.Frm_Spacing
    .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
    .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
    
    .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
    .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
    .tlb_Item.Left = mt_CstValues.Frm_Spacing
    .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
    
    .tbsEmbedded.Visible = False
    
    .fraItemTop.Left = mt_CstValues.Frm_Spacing
    .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
    .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
    .fraItemTop.Height = .fraItem.Height - .fraItemTop.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    
    .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
    .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
    .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    
    .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    .fraItemBottom.Left = mt_CstValues.Frm_Spacing
    
    .fraItem.Visible = True
    .fraItemTop.Visible = True
    .fraItemTop.BorderStyle = 0
    .fraItemBottom.Visible = True
    .fraItemBottom.BorderStyle = 0
    
    Call tbs_Header.Move(0, 0, fraItemTop.Width)
    For ll_Idx = 0 To fra_Header.Count - 1
      Call fra_Header(ll_Idx).Move(0, tbs_Header.Height, fraItemTop.Width, 3300)
    Next
    Call txt_COF_Comm.Move(0, 0, fra_Header(0).Width, fra_Header(0).Height)
    Call txt_COF_Desc.Move(0, 0, fra_Header(0).Width, fra_Header(0).Height)
    
    .fraSubItemMain.Top = tbs_Header.Height + fra_Header(0).Height
    .fraSubItemMain.Height = fraItemTop.Height - fraSubItemMain.Top
    .fraSubItemMain.Left = 0
    .fraSubItemMain.Width = fraItemTop.Width
    
    .tlb_Subitem.Top = 0
    .tlb_Subitem.Left = .fraSubItemMain.Width - .tlb_Subitem.Width
    .tlb_Subitem.Height = .fraSubItemMain.Height
    
    fra_Header(5).Height = fraItemTop.Height - tbs_Header.Height
    Call fra_PosListFilter.Move(0, 0, fra_Header(5).Width)
    Call fra_PosListToolbar.Move(0, fra_Header(5).Height - fra_PosListToolbar.Height - 2 * mt_CstValues.Frm_Spacing, fra_Header(5).Width)
    Call tbs_PosList.Move(0, fra_PosListFilter.Top + fra_PosListFilter.Height, fra_PosListFilter.Width)
    Call grd_PosList.Move(0, tbs_PosList.Top + tbs_PosList.Height, fra_Header(5).Width, fra_Header(5).Height - (fra_PosListFilter.Height + fra_PosListToolbar.Height + tbs_PosList.Height))
    Call grd_Packing.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_BOM.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_BOR.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_Cost.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
  End With
  Exit Sub
ErrHandler:
  Call ErrorHandler("Add_Resize")
End Sub

Private Sub AddDisplay()
On Error GoTo ErrHandler
    
  RaiseEvent SwitchToView(mt_CstValues.View_Full)
  
  'If the component was on short list, it does appear now in long list
'  InitControl 4
  BlankFields
  Call tlb_Item.DisplayFace("1")
  Add_Enablecontrols
  Add_Resize
  AddInitFields
  Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
  Exit Sub
ErrHandler:
  Call ErrorHandler("AddDisplay")
End Sub

Private Sub Delete_Resize()
On Error GoTo ErrHandler

Dim ll_Idx As Long
  
  With UserControl
      
    .fraItem.Left = mt_CstValues.Frm_Spacing
    .fraItem.Top = mt_CstValues.Frm_Spacing
    .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
    .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
    
    .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
    .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
    .tlb_Item.Left = mt_CstValues.Frm_Spacing
    .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
    
    .tbsEmbedded.Visible = False
    
    .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
    .fraItemTop.Left = mt_CstValues.Frm_Spacing
    .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
    .fraItemTop.Height = .fraItem.Height - .fraItemTop.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    
    .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
    .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
    .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    
    .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    .fraItemBottom.Left = mt_CstValues.Frm_Spacing
    
    .fraItem.Visible = True
    .fraItemTop.Visible = True
    .fraItemTop.BorderStyle = 0
    .fraItemBottom.Visible = True
    .fraItemBottom.BorderStyle = 0

    Call tbs_Header.Move(0, 0, fraItemTop.Width)
    For ll_Idx = 0 To fra_Header.Count - 1
      Call fra_Header(ll_Idx).Move(0, tbs_Header.Height, fraItemTop.Width, 3300)
    Next
    Call txt_COF_Comm.Move(0, 0, fra_Header(0).Width, fra_Header(0).Height)
    Call txt_COF_Desc.Move(0, 0, fra_Header(0).Width, fra_Header(0).Height)
    
    .fraSubItemMain.Top = tbs_Header.Height + fra_Header(0).Height
    .fraSubItemMain.Height = fraItemTop.Height - fraSubItemMain.Top
    .fraSubItemMain.Left = 0
    .fraSubItemMain.Width = fraItemTop.Width
  
    .tlb_Subitem.Top = 0
    .tlb_Subitem.Left = .fraSubItemMain.Width - .tlb_Subitem.Width
    .tlb_Subitem.Height = .fraSubItemMain.Height

    fra_Header(5).Height = fraItemTop.Height - tbs_Header.Height
    Call fra_PosListFilter.Move(0, 0, fra_Header(5).Width)
    Call fra_PosListToolbar.Move(0, fra_Header(5).Height - fra_PosListToolbar.Height - 2 * mt_CstValues.Frm_Spacing, fra_Header(5).Width)
    Call tbs_PosList.Move(0, fra_PosListFilter.Top + fra_PosListFilter.Height, fra_PosListFilter.Width)
    Call grd_PosList.Move(0, tbs_PosList.Top + tbs_PosList.Height, fra_Header(5).Width, fra_Header(5).Height - (fra_PosListFilter.Height + fra_PosListToolbar.Height + tbs_PosList.Height))
    Call grd_Packing.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_BOM.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_BOR.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_Cost.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
  End With
  Exit Sub
ErrHandler:
  Call ErrorHandler("Delete_Resize")
End Sub

Private Sub DeleteDisplay()
On Error GoTo ErrHandler
    
  RaiseEvent SwitchToView(mt_CstValues.View_Full)
  
  'If the component was on short list, it does appear now in long list
  'InitControl 4
  BlankFields
  Call tlb_Item.DisplayFace("3")
  Delete_EnableControls
  Delete_Resize
  ViewInitFields
  Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_View)
  Exit Sub
ErrHandler:
  Call ErrorHandler("DeleteDisplay")
End Sub

Private Sub Delete_EnableControls()
On Error GoTo ErrHandler
    
  Call mo_Tools.EnableFrame(UserControl.Controls, fraItemTop, False)
  Call mo_Tools.EnableFrame(UserControl.Controls, fraItemBottom, False)
  Call mo_Tools.EnableFrame(UserControl.Controls, fra_PosListFilter, True)
  
  tlb_Subitem.Enabled = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("Delete_EnableControls")
End Sub

Private Sub Update_Resize()
On Error GoTo ErrHandler
    
Dim ll_Idx As Long
  
  With UserControl
    .fraItem.Left = mt_CstValues.Frm_Spacing
    .fraItem.Top = mt_CstValues.Frm_Spacing
    .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
    .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
    
    .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
    .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
    .tlb_Item.Left = mt_CstValues.Frm_Spacing
    .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
    
    .tbsEmbedded.Visible = False
    
    .fraItemTop.Left = mt_CstValues.Frm_Spacing
    .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
    .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
    .fraItemTop.Height = .fraItem.Height - .fraItemTop.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    
    .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
    .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
    .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    
    .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    .fraItemBottom.Left = mt_CstValues.Frm_Spacing
    
    .fraItem.Visible = True
    .fraItemTop.Visible = True
    .fraItemTop.BorderStyle = 0
    .fraItemBottom.Visible = True
    .fraItemBottom.BorderStyle = 0
    
    Call tbs_Header.Move(0, 0, fraItemTop.Width)
    For ll_Idx = 0 To fra_Header.Count - 1
      Call fra_Header(ll_Idx).Move(0, tbs_Header.Height, fraItemTop.Width, 3300)
    Next
    Call txt_COF_Comm.Move(0, 0, fra_Header(0).Width, fra_Header(0).Height)
    Call txt_COF_Desc.Move(0, 0, fra_Header(0).Width, fra_Header(0).Height)
    
    .fraSubItemMain.Top = tbs_Header.Height + fra_Header(0).Height
    .fraSubItemMain.Height = fraItemTop.Height - fraSubItemMain.Top
    .fraSubItemMain.Left = 0
    .fraSubItemMain.Width = fraItemTop.Width
    
    .tlb_Subitem.Top = 0
    .tlb_Subitem.Left = .fraSubItemMain.Width - .tlb_Subitem.Width
    .tlb_Subitem.Height = .fraSubItemMain.Height
    
    fra_Header(5).Height = fraItemTop.Height - tbs_Header.Height
    Call fra_PosListFilter.Move(0, 0, fra_Header(5).Width)
    Call fra_PosListToolbar.Move(0, fra_Header(5).Height - fra_PosListToolbar.Height - 2 * mt_CstValues.Frm_Spacing, fra_Header(5).Width)
    Call tbs_PosList.Move(0, fra_PosListFilter.Top + fra_PosListFilter.Height, fra_PosListFilter.Width)
    Call grd_PosList.Move(0, tbs_PosList.Top + tbs_PosList.Height, fra_Header(5).Width, fra_Header(5).Height - (fra_PosListFilter.Height + fra_PosListToolbar.Height + tbs_PosList.Height))
    Call grd_Packing.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_BOM.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_BOR.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_Cost.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
  End With
  Exit Sub
ErrHandler:
  Call ErrorHandler("Update_Resize")
End Sub

Private Sub UpdateDisplay()
On Error GoTo ErrHandler
    
  RaiseEvent SwitchToView(mt_CstValues.View_Full)
  
  'If the component was on short list, it does appear now in long list
  'InitControl 4
  
  If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then BlankFields
  If mi_OldDisplayMode <> mt_CstValues.DisplayMode_View Then
      UpdateInitFields
  End If
  Update_EnableControls
  Update_Resize
  
  Call tlb_Item.DisplayFace("2")
  
  Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
  If Status = eOfferStatus.osSAPSalesOrderChange Then
    tlb_Subitem.ButtonEnabled("B") = False
    tlb_Subitem.ButtonEnabled("C") = False
    tlb_Subitem.ButtonEnabled("X") = False
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateDisplay")
End Sub

Function RecordCheck() As Boolean
On Error GoTo ErrHandler

Dim lbl_Field As Label

  RecordCheck = False
  If cbo_Customer.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_Customer")
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
      Exit Function
  End If
  If cbo_SubProject.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_SubProject")
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
      Exit Function
  End If
  If cbo_Template.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_Language")
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
    Exit Function
  End If
  If cbo_LegalEntity.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_LegalEntity")
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
    Exit Function
  End If
  If cbo_PM_Office.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_PM_Office")
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
    Exit Function
  End If
  If cbo_currencies.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_Offer_Currency")
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
      Exit Function
  End If
  If cal_COF_ExDat.date_courte = "" Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_ExpiryDate")
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", lbl_Field.Caption))
      Exit Function
  End If
  RecordCheck = True
  Exit Function
ErrHandler:
  Call ErrorHandler("RecordCheck")
End Function

Function RecordAdd() As Boolean
On Error GoTo ErrHandler
Dim ls_Request As String
Dim ll_Cursor As Long
    
  If Not RecordCheck Then Exit Function
  
  ls_Request = "exec Cap_Offer_ins "
  ls_Request = ls_Request & "$COF_Id$, $COF_Code$, $COF_CodeCus$, $SP_Capkey$, $CCU_Capkey$, $CNT_Code$,"
  ls_Request = ls_Request & "$COF_AppBy$, $COF_ApDat$, $COF_Desc$, $COF_Comm$, $SPR_Id$, $COF_Type$, $COF_Vers$, $COF_Stat$, $LEV_Id$, $COF_Lang$, $COT_Id$,"
  ls_Request = ls_Request & "$CURR_Code$, $LEN_Id$, $PMO_Id$, $COF_MaxLot$, $COF_MaxOrd$, $COF_MinWeek$, $COF_MaxWeek$, $COF_TOD1$, $COF_TOD2$, $COF_DocDat$, $COF_ExDat$,$COF_FoDat$,$COF_AllPr$, $COF_Prior$,"
  ls_Request = ls_Request & "$COF_DeDesc$, $COF_DeAdr1$, $COF_DeAdr2$, $COF_DeZip$, $COF_DeTown$, $COF_DeCT$,"
  ls_Request = ls_Request & "$COF_Bae_Konto$, $COF_Bae_KontoDesc$, $COF_Bae_OrdTyp$, $COF_Bae_OrdTypDesc$, $COF_Bae_Partner$, $COF_Bae_PartnerDesc$, $COF_Bae_BestNr$, $COF_Bae_BestNr2$, $COF_Bae_InCharge$, $COF_Bae_InChargeDesc$,"
  ls_Request = ls_Request & "$COF_Bae_DelCond$, $COF_Bae_DelCondDesc$, $COF_Bae_DelType$, $COF_Bae_DelTypeDesc$, $COF_Bae_PackType$, $COF_Bae_PackTypeDesc$, $U_CodeSlsRep$, $U_CodePrjMan$, $U_CodePrdMan$,"
  ls_Request = ls_Request & "$COF_BuiltStat$, $COF_Probability$, $COF_AltQuote$, $COF_MainFamily$, $COF_MainLevel$, $COF_Specification$, $Z_Creator$"
  
  m_CurrentKey1 = mo_Db.SQLNextID("Cap_Offer")
  txt_COF_ID.Text = m_CurrentKey1
  
  ls_Request = Replace(ls_Request, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Code$", mo_Tools.SQLStr(txt_COF_Code.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_CodeCus$", mo_Tools.SQLStr(txt_COF_CodeCus.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$SP_Capkey$", mo_Tools.SqlStrKey(m_Project), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$CCU_Capkey$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_Customer)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$CNT_Code$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_Contact)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_AppBy$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_COF_AppBy)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_ApDat$", mo_Tools.SqlDate(cal_COF_ApDat.date_dt), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Desc$", mo_Tools.SQLStr(txt_COF_Desc.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Comm$", mo_Tools.SQLStr(txt_COF_Comm.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$SPR_Id$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_SubProject)), , , vbTextCompare)
  If opt_OfferType(0).Value Then
      ls_Request = Replace(ls_Request, "$COF_Type$", mo_Tools.SqlInt(eOfferType.otBudget), , , vbTextCompare)
  ElseIf opt_OfferType(1).Value Then
      ls_Request = Replace(ls_Request, "$COF_Type$", mo_Tools.SQLStr(eOfferType.otAdvanced), , , vbTextCompare)
  Else
      ls_Request = Replace(ls_Request, "$COF_Type$", mo_Tools.SQLStr(eOfferType.otFinal), , , vbTextCompare)
  End If
  
  If opt_OfferPriority(0).Value Then
      ls_Request = Replace(ls_Request, "$COF_Prior$", mo_Tools.SqlInt(eOfferPriority.opNormal), , , vbTextCompare)
  ElseIf opt_OfferPriority(1).Value Then
      ls_Request = Replace(ls_Request, "$COF_Prior$", mo_Tools.SQLStr(eOfferPriority.opPriority), , , vbTextCompare)
  ElseIf opt_OfferPriority(2).Value Then
      ls_Request = Replace(ls_Request, "$COF_Prior$", mo_Tools.SQLStr(eOfferPriority.opTopSpeed), , , vbTextCompare)
  Else
      ls_Request = Replace(ls_Request, "$COF_Prior$", mo_Tools.SQLStr(eOfferPriority.opNone), , , vbTextCompare)
  End If
  
  ls_Request = Replace(ls_Request, "$COF_Vers$", mo_Tools.SqlInt(Val(txt_Version.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Stat$", mo_Tools.SqlInt(Status), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$LEV_Id$", mo_Tools.SqlInt(mo_Tools.GetComboKey(cbo_Level)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Lang$", mo_Tools.SQLStr(ms_COF_Lang), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$LEN_Id$", mo_Tools.SqlInt(mo_Tools.GetComboKey(cbo_LegalEntity)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$PMO_Id$", mo_Tools.SqlInt(mo_Tools.GetComboKey(cbo_PM_Office)), , , vbTextCompare)
  
  ls_Request = Replace(ls_Request, "$COF_MaxLot$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(txt_COF_MaxLot.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MaxOrd$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(txt_COF_MaxOrd.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MinWeek$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(txt_COF_MinWeek.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MaxWeek$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(txt_COF_MaxWeek.Text)), , , vbTextCompare)
  
  ls_Request = Replace(ls_Request, "$COT_Id$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_Template)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$CURR_Code$", mo_Tools.SQLStr(CURR_Code), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_TOD1$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_TOF1)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_TOD2$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_TOF2)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_ExDat$", mo_Tools.SqlDate(cal_COF_ExDat.date_dt), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_FoDat$", mo_Tools.SqlDate(cal_COF_FoDat.date_dt), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DocDat$", mo_Tools.SqlDate(COF_DocDat), , , vbTextCompare)
  If tbs_Offer.SelectedItem.Index = 1 Then
    ls_Request = Replace(ls_Request, "$COF_AllPr$", mo_Tools.SQLStr("X"), , , vbTextCompare)
  Else
    ls_Request = Replace(ls_Request, "$COF_AllPr$", mo_Tools.SQLStr(""), , , vbTextCompare)
  End If
  
  ls_Request = Replace(ls_Request, "$COF_DeDesc$", mo_Tools.SQLStr(txt_COF_DeDesc.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeAdr1$", mo_Tools.SQLStr(txt_COF_DeAdr1.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeAdr2$", mo_Tools.SQLStr(txt_COF_DeAdr2.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeTown$", mo_Tools.SQLStr(txt_COF_DeTown.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeZip$", mo_Tools.SQLStr(txt_COF_DeZip.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeCT$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_COF_DeCT)), , , vbTextCompare)
  
  ls_Request = Replace(ls_Request, "$COF_Bae_Konto$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_Konto")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_KontoDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_KontoDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_OrdTyp$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_OrdTyp")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_OrdTypDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_OrdTypDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_Partner$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_Partner")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_PartnerDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_PartnerDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_BestNr$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_CodeCus")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_BestNr2$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_BestNr2")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_InCharge$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_InCharge")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_InChargeDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_InChargeDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_DelCond$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_DelCond")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_DelCondDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_DelCondDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_DelType$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_DelType")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_DelTypeDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_DelTypeDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_PackType$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_PackType")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_PackTypeDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_PackTypeDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$U_CodeSlsRep$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_U_CodeSlsRep)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$U_CodePrjMan$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_U_CodePrjMan)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$U_CodePrdMan$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_U_CodePrdMan)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_BuiltStat$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_BuiltStatus)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Probability$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_Probability)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_AltQuote$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_AltQuote)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MainFamily$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_MainFamily)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MainLevel$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_MainLevel)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Specification$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_Specification)), , , vbTextCompare)
  
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_Request)
  Call GridUpdate(False)
  
  RaiseEvent Updated
  RecordAdd = True
  Exit Function
ErrHandler:
  Call ErrorHandler("RecordAdd")
End Function

Function RecordUpdate(ACode As String) As Boolean
On Error GoTo ErrHandler
Dim ls_Request As String
  
  If Not RecordCheck Then Exit Function
  
  ls_Request = "exec Cap_Offer_upd "
  ls_Request = ls_Request & "$COF_Id$, $COF_Code$, $COF_CodeCus$, $CCU_Capkey$, $CNT_Code$,"
  ls_Request = ls_Request & "$COF_AppBy$, $COF_ApDat$, $COF_Desc$, $COF_Comm$, $SPR_Id$, $COF_Type$, $COF_Vers$, $COF_Stat$, $LEV_Id$, $COF_Lang$, $COT_Id$,"
  ls_Request = ls_Request & "$CURR_Code$, $LEN_Id$, $PMO_Id$, $COF_MaxLot$, $COF_MaxOrd$, $COF_MinWeek$, $COF_MaxWeek$, $COF_TOD1$, $COF_TOD2$, $COF_DocDat$, $COF_ExDat$,$COF_FoDat$,$COF_AllPr$, $COF_Prior$,"
  ls_Request = ls_Request & "$COF_DeDesc$, $COF_DeAdr1$, $COF_DeAdr2$, $COF_DeZip$, $COF_DeTown$, $COF_DeCT$,"
  ls_Request = ls_Request & "$COF_Bae_Konto$, $COF_Bae_KontoDesc$, $COF_Bae_OrdTyp$, $COF_Bae_OrdTypDesc$, $COF_Bae_Partner$, $COF_Bae_PartnerDesc$, $COF_Bae_BestNr$, $COF_Bae_BestNr2$, $COF_Bae_InCharge$, $COF_Bae_InChargeDesc$,"
  ls_Request = ls_Request & "$COF_Bae_DelCond$, $COF_Bae_DelCondDesc$, $COF_Bae_DelType$, $COF_Bae_DelTypeDesc$, $COF_Bae_PackType$, $COF_Bae_PackTypeDesc$, $U_CodeSlsRep$, $U_CodePrjMan$, $U_CodePrdMan$,"
  ls_Request = ls_Request & "$COF_BuiltStat$, $COF_Probability$, $COF_AltQuote$, $COF_MainFamily$, $COF_MainLevel$, $COF_Specification$, $iConcurrency$, $Z_Last_Upd_User$"
  'The data has been updated
  ls_Request = Replace(ls_Request, "$COF_Id$", mo_Tools.SQLStr(ACode), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Code$", mo_Tools.SQLStr(txt_COF_Code.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_CodeCus$", mo_Tools.SQLStr(txt_COF_CodeCus.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$CCU_Capkey$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_Customer)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$CNT_Code$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_Contact)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Desc$", mo_Tools.SQLStr(txt_COF_Desc.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Comm$", mo_Tools.SQLStr(txt_COF_Comm.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$SPR_Id$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_SubProject)), , , vbTextCompare)
  
  If opt_OfferType(0).Value Then
      ls_Request = Replace(ls_Request, "$COF_Type$", mo_Tools.SqlInt(eOfferType.otBudget), , , vbTextCompare)
  ElseIf opt_OfferType(1).Value Then
      ls_Request = Replace(ls_Request, "$COF_Type$", mo_Tools.SqlInt(eOfferType.otAdvanced), , , vbTextCompare)
  Else
      ls_Request = Replace(ls_Request, "$COF_Type$", mo_Tools.SqlInt(eOfferType.otFinal), , , vbTextCompare)
  End If
  
  If opt_OfferPriority(0).Value Then
      ls_Request = Replace(ls_Request, "$COF_Prior$", mo_Tools.SqlInt(eOfferPriority.opNormal), , , vbTextCompare)
  ElseIf opt_OfferPriority(1).Value Then
      ls_Request = Replace(ls_Request, "$COF_Prior$", mo_Tools.SqlInt(eOfferPriority.opPriority), , , vbTextCompare)
  ElseIf opt_OfferPriority(2).Value Then
      ls_Request = Replace(ls_Request, "$COF_Prior$", mo_Tools.SqlInt(eOfferPriority.opTopSpeed), , , vbTextCompare)
  Else
      ls_Request = Replace(ls_Request, "$COF_Prior$", mo_Tools.SqlInt(eOfferPriority.opNone), , , vbTextCompare)
  End If

  ls_Request = Replace(ls_Request, "$COF_Vers$", mo_Tools.SqlInt(Val(txt_Version.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Stat$", mo_Tools.SqlInt(Status), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$LEV_Id$", mo_Tools.SqlInt(mo_Tools.GetComboKey(cbo_Level)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Lang$", mo_Tools.SQLStr(ms_COF_Lang), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$LEN_Id$", mo_Tools.SqlInt(mo_Tools.GetComboKey(cbo_LegalEntity)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$PMO_Id$", mo_Tools.SqlInt(mo_Tools.GetComboKey(cbo_PM_Office)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MaxLot$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(txt_COF_MaxLot.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MaxOrd$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(txt_COF_MaxOrd.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MinWeek$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(txt_COF_MinWeek.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MaxWeek$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(txt_COF_MaxWeek.Text)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COT_Id$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_Template)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_AppBy$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_COF_AppBy)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_ApDat$", mo_Tools.SqlDate(cal_COF_ApDat.date_dt), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$CURR_Code$", mo_Tools.SQLStr(CURR_Code), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_TOD1$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_TOF1)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_TOD2$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_TOF2)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_ExDat$", mo_Tools.SqlDate(cal_COF_ExDat.date_dt), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_FoDat$", mo_Tools.SqlDate(cal_COF_FoDat.date_dt), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DocDat$", mo_Tools.SqlDate(COF_DocDat), , , vbTextCompare)
  If tbs_Offer.SelectedItem.Index = 1 Then
    ls_Request = Replace(ls_Request, "$COF_AllPr$", mo_Tools.SQLStr("X"), , , vbTextCompare)
  Else
    ls_Request = Replace(ls_Request, "$COF_AllPr$", mo_Tools.SQLStr(""), , , vbTextCompare)
  End If
  ls_Request = Replace(ls_Request, "$COF_DeDesc$", mo_Tools.SQLStr(txt_COF_DeDesc.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeAdr1$", mo_Tools.SQLStr(txt_COF_DeAdr1.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeAdr2$", mo_Tools.SQLStr(txt_COF_DeAdr2.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeTown$", mo_Tools.SQLStr(txt_COF_DeTown.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeZip$", mo_Tools.SQLStr(txt_COF_DeZip.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_DeCT$", mo_Tools.SqlStrKey(mo_Tools.GetComboKey(cbo_COF_DeCT)), , , vbTextCompare)
  
  ls_Request = Replace(ls_Request, "$COF_Bae_Konto$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_Konto")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_KontoDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_KontoDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_OrdTyp$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_OrdTyp")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_OrdTypDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_OrdTypDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_Partner$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_Partner")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_PartnerDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_PartnerDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_BestNr$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_CodeCus")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_BestNr2$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_BestNr2")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_InCharge$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_InCharge")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_InChargeDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_InChargeDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_DelCond$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_DelCond")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_DelCondDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_DelCondDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_DelType$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_DelType")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_DelTypeDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_DelTypeDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_PackType$", mo_Tools.SQLStr(mo_Tools.GetTextValue(txt_Textbox, "COF_Bae_PackType")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Bae_PackTypeDesc$", mo_Tools.SQLStr(mo_Tools.GetLabelCaption(lbl_Label, Nothing, "_COF_Bae_PackTypeDesc")), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$U_CodeSlsRep$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_U_CodeSlsRep)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$U_CodePrjMan$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_U_CodePrjMan)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$U_CodePrdMan$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_U_CodePrdMan)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_BuiltStat$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_BuiltStatus)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Probability$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_Probability)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_AltQuote$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_AltQuote)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MainFamily$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_MainFamily)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_MainLevel$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_MainLevel)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$COF_Specification$", mo_Tools.SqlIntKey(mo_Tools.GetComboKey(cbo_Specification)), , , vbTextCompare)
  
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_Request)
  
  Call GridUpdate(True)
  RaiseEvent Updated
  RecordUpdate = True
  Exit Function
ErrHandler:
  Call ErrorHandler("RecordUpdate")
End Function

Private Sub RecordUpdateLastUser()
On Error GoTo ErrHandler
Dim ls_Request As String
  
  ls_Request = "exec Cap_Offer_upd3 $COF_Id$, $iConcurrency$, $Z_Last_Upd_User$"
  
  ls_Request = Replace(ls_Request, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_Request)
  ml_iConcurrency = ml_iConcurrency + 1
  Exit Sub
ErrHandler:
  Call ErrorHandler("RecordUpdateLastUser")
End Sub

Function RecordDelete(ByVal as_COF_Id As String) As Boolean
On Error GoTo ErrHandler
    Dim ls_Request As String

  ls_Request = "exec Cap_Offer_del $COF_ID$, $iConcurrency$, $Z_Last_Upd_User$"
  ls_Request = Replace(ls_Request, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id), , , vbTextCompare)
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_Request)
  Call grdlst.DeleteSelectedLines
  'The data has been deleted
  RaiseEvent Updated
  RecordDelete = True
  Exit Function
ErrHandler:
  Call ErrorHandler("RecordDelete")
End Function

Private Sub ViewDisplay()
On Error GoTo ErrHandler
    
  If mi_EmbeddedIn = -1 Then
      RaiseEvent SwitchToView(mt_CstValues.View_Full)
  Else
      RaiseEvent SwitchToView(mt_CstValues.View_Full)
  End If
  
  'If the component was on short list, it doues appear now in long list
'  InitControl 3
  
  BlankFields
  Call tlb_Item.DisplayFace("0")
  View_EnableControls
  ViewLoad
  View_Resize
  ViewInitFields
  Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_View)
  Exit Sub
ErrHandler:
  Call ErrorHandler("ViewDisplay")
End Sub

Private Sub View_Resize()
On Error GoTo ErrHandler
    
Dim ll_Idx As Long
  
  With UserControl
      
    If mi_EmbeddedIn = -1 And Not mb_Root Then
    
        .fraItem.Left = mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Visible = False 'true
        .tbsEmbedded.Zorder 0
        
    Else
        .fraItem.Left = mt_CstValues.Frm_Spacing
        
        .tbsEmbedded.Visible = False 'true
        .tbsEmbedded.Zorder 0
        
    End If
    
    .fraItem.Top = mt_CstValues.Frm_Spacing
    .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
    .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
    
    .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
    .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
    .tlb_Item.Left = mt_CstValues.Frm_Spacing
    .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
    
    .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
    .fraItemTop.Left = mt_CstValues.Frm_Spacing
    .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
    .fraItemTop.Height = .fraItem.Height - .fraItemTop.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    
    .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
    .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
    .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    
    .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    .fraItemBottom.Left = mt_CstValues.Frm_Spacing
    
    .fraItem.Visible = True
    .fraItemTop.Visible = True
    .fraItemTop.BorderStyle = 0
    .fraItemBottom.Visible = True
    .fraItemBottom.BorderStyle = 0
    
    Call tbs_Header.Move(0, 0, fraItemTop.Width)
    For ll_Idx = 0 To fra_Header.Count - 1
      Call fra_Header(ll_Idx).Move(0, tbs_Header.Height, fraItemTop.Width, 3300)
    Next
    Call txt_COF_Comm.Move(0, 0, fra_Header(0).Width, fra_Header(0).Height)
    Call txt_COF_Desc.Move(0, 0, fra_Header(0).Width, fra_Header(0).Height)
    
    .fraSubItemMain.Top = tbs_Header.Height + fra_Header(0).Height
    .fraSubItemMain.Height = fraItemTop.Height - fraSubItemMain.Top
    .fraSubItemMain.Left = 0
    .fraSubItemMain.Width = fraItemTop.Width
    
    .tlb_Subitem.Top = 0
    .tlb_Subitem.Left = .fraSubItemMain.Width - .tlb_Subitem.Width
    .tlb_Subitem.Height = .fraSubItemMain.Height
        
    fra_Header(5).Height = fraItemTop.Height - tbs_Header.Height
    Call fra_PosListFilter.Move(0, 0, fra_Header(5).Width)
    Call fra_PosListToolbar.Move(0, fra_Header(5).Height - fra_PosListToolbar.Height - 2 * mt_CstValues.Frm_Spacing, fra_Header(5).Width)
    Call tbs_PosList.Move(0, fra_PosListFilter.Top + fra_PosListFilter.Height, fra_PosListFilter.Width)
    Call grd_PosList.Move(0, tbs_PosList.Top + tbs_PosList.Height, fra_Header(5).Width, fra_Header(5).Height - (fra_PosListFilter.Height + fra_PosListToolbar.Height + tbs_PosList.Height))
    Call grd_Packing.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_BOM.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_BOR.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
    Call grd_Cost.Move(grd_PosList.Left, grd_PosList.Top, grd_PosList.Width, grd_PosList.Height)
  End With
  Exit Sub
ErrHandler:
  Call ErrorHandler("View_Resize")
End Sub

Public Property Get UserControlWidth() As Long
On Error GoTo ErrorHandler

  UserControlWidth = UserControl.Width
  Exit Property
ErrorHandler:
  Call ErrorHandler("UserControlWidth")
End Property

Public Property Get CurrentKey(Optional APart As Long = 0) As String
On Error GoTo ErrorHandler

  If APart = 0 Then
      CurrentKey = m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2
  ElseIf APart = 1 Then
      CurrentKey = m_CurrentKey1
  ElseIf APart = 2 Then
      CurrentKey = m_CurrentKey2
  Else
      CurrentKey = ""
  End If
  Exit Property
ErrorHandler:
  Call ErrorHandler("CurrentKey")
End Property

Public Property Let CurrentKey(Optional APart As Long = 0, AKeyValue As String)
On Error GoTo ErrorHandler

  If APart = 0 Then
      m_CurrentKey1 = AKeyValue
      m_CurrentKey2 = ""
      m_CurrentKey3 = ""
  ElseIf APart = 1 Then
      m_CurrentKey1 = AKeyValue
  ElseIf APart = 2 Then
      m_CurrentKey2 = AKeyValue
  Else
      CurrentKey = ""
  End If
  Exit Property
ErrorHandler:
  Call ErrorHandler("CurrentKey")
End Property

Public Property Let TypeList(AType As Long)
On Error GoTo ErrorHandler
    
  mi_TypeList = AType

  Exit Property
ErrorHandler:
  Call ErrorHandler("TypeList.Let")
End Property

Property Get TypeList() As Long
On Error GoTo ErrorHandler
    
  TypeList = mi_TypeList
  
  Exit Property
ErrorHandler:
  Call ErrorHandler("TypeList.Get")
End Property

Private Sub ShortList_Resize()
On Error GoTo ErrHandler
    
  With UserControl
  
    .fraList.Left = mt_CstValues.Frm_Spacing
    .fraList.Top = mt_CstValues.Frm_Spacing
    .fraList.Width = .Width - .fraList.Left - (2 * mt_CstValues.Frm_Spacing)
    .fraList.Height = .Height - .fraList.Top - (2 * mt_CstValues.Frm_Spacing)
    
    .tlb_Main.Height = mt_CstValues.View_ToolBar_Height
    .tlb_Main.Top = mt_CstValues.Frm_Spacing * 4
    .tlb_Main.Left = mt_CstValues.Frm_Spacing
    .tlb_Main.Width = .fraList.Width - .tlb_Main.Left - (2 * mt_CstValues.Frm_Spacing)
    
    .grdlst.Top = mt_CstValues.Frm_Spacing + .tlb_Main.Top + .tlb_Main.Height
    .grdlst.Left = mt_CstValues.Frm_Spacing
    .grdlst.Width = .fraList.Width - .grdlst.Left - mt_CstValues.Frm_Spacing
    .grdlst.Height = .fraList.Height - .tlb_Main.Height - .tlb_Main.Top - (2 * mt_CstValues.Frm_Spacing)
    
    .fraList.Visible = True
  End With
  Exit Sub
ErrHandler:
  Call ErrorHandler("ShortList_Resize")
End Sub

' Called when application must resize the current view
Public Sub Resize()
On Error GoTo ErrHandler

Dim ll_Idx As Long

  Call DisplayMode_None
  'If Height > fraItemTop.Height And Width > fraItemTop.Width Then
    With UserControl
    .fraItem.Left = mt_CstValues.Frm_Spacing
    .fraItem.Top = mt_CstValues.Frm_Spacing
    .fraItem.Width = .Width - .fraItem.Left - (2 * mt_CstValues.Frm_Spacing)
    .fraItem.Height = .Height - .fraItem.Top - (2 * mt_CstValues.Frm_Spacing)
    
    .tlb_Item.Height = mt_CstValues.View_ToolBar_Height
    .tlb_Item.Top = mt_CstValues.Frm_Spacing * 4
    .tlb_Item.Left = mt_CstValues.Frm_Spacing
    .tlb_Item.Width = .fraItem.Width - .tlb_Item.Left - (2 * mt_CstValues.Frm_Spacing)
    
    .fraItemTop.Left = mt_CstValues.Frm_Spacing
    .fraItemTop.Top = mt_CstValues.Frm_Spacing + .tlb_Item.Top + .tlb_Item.Height
    .fraItemTop.Width = .fraItem.Width - .fraItemTop.Left - mt_CstValues.Frm_Spacing
    
    If (.fraItem.Height - .fraItemTop.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing) > 0 Then
      .fraItemTop.Height = .fraItem.Height - .fraItemTop.Top - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    Else
      .fraItemTop.Height = mt_CstValues.Frm_Spacing
    End If
    
    .tbsEmbedded.Top = .fraItem.Height - .tbsEmbedded.Height - mt_CstValues.Frm_Spacing
    .tbsEmbedded.Left = mt_CstValues.Frm_Spacing
    .tbsEmbedded.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    
    .fraItemBottom.Width = .fraItem.Width - .tbsEmbedded.Left - mt_CstValues.Frm_Spacing
    .fraItemBottom.Top = .fraItem.Height - .fraItemBottom.Height - mt_CstValues.Frm_Spacing
    .fraItemBottom.Left = mt_CstValues.Frm_Spacing
    End With
      
    Select Case DisplayMode
      Case mt_CstValues.DisplayMode_List
             Call ShortList_Resize
    End Select
  'End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("Resize")
End Sub

Sub UnCatch()
  mi_EmbeddedIn = -1
End Sub

Public Property Let product(AProductKey As String)

    ' no product-offer navigation
End Property

Public Property Let action(AActionKey As String)

    ' no action-offer navigation
End Property

Public Property Let contact(AKey As String)

    ' no contact-offer navigation
End Property
 
Public Property Let Customer(AKey As String)

    ' no customer-offer navigation
End Property

Public Property Let project(AKey As String)
On Error GoTo ErrHandler

Dim TheKeys     As Variant
  
  'AKey represents the concatenation of several keys separated by '@'
  If AKey = "" Then Call Err.Raise(InvalidArgument, "", "AKey is empty.")

  ' First, we hide all elements
  DisplayMode_None
  
  If (Not mb_Root) And (mi_TypeList <> 1) Then
      mi_EmbedTag = -1
  End If
  
  TheKeys = Split(AKey, CH_LDELIMIT)
  'Debug.Assert (UBound(TheKeys) = 3)
  m_Customer = ""
  m_Contact = ""
  m_Project = CStr(TheKeys(0))
  m_projectStatus = "" 'CLng(TheKeys(2))

'  InitControl 2
  
  mi_EmbeddedIn = mt_CstValues.Tag_Project

  mb_EmbeddedIsDropped = False
  
  ListProjectOf CStr(TheKeys(0)), CStr(TheKeys(1))
  
  SwapToDisplayMode mt_CstValues.DisplayMode_List
  
  Exit Property
ErrHandler:
  Call ErrorHandler("project.Let")
End Property

Private Sub LoadSPAConfig()
On Error GoTo ErrHandler

' config load
Dim ll_Cursor  As Long
Dim ll_i As Long
Const C_REQ_SPA_Config As String = "EXEC SPA_Online_config_sel"
    
  If mo_A_Config.Count = 0 Then
    ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, C_REQ_SPA_Config)
    If mo_Db.RowCount(ll_Cursor) > 0 Then
        For ll_i = 0 To mo_Db.RowCount(ll_Cursor) - 1
            Call mo_A_Config.Add(mo_Db.GetFields(ll_Cursor, "CFG_Key"), mo_Db.GetFields(ll_Cursor, "CFG_Value"))
            Call mo_Db.Next(ll_Cursor)
        Next
        ' default values
        If Not mo_A_Config.Exists(C_A_CONFIG_Distr_Chan) Then Call mo_A_Config.Add(C_A_CONFIG_Distr_Chan, "BP")
        If Not mo_A_Config.Exists(C_A_CONFIG_Division) Then Call mo_A_Config.Add(C_A_CONFIG_Division, "00")
        If Not mo_A_Config.Exists(C_A_CONFIG_Doc_Type) Then Call mo_A_Config.Add(C_A_CONFIG_Doc_Type, "TA")
        If Not mo_A_Config.Exists(C_A_CONFIG_Partn_Role) Then Call mo_A_Config.Add(C_A_CONFIG_Partn_Role, "AG")
    End If
    
    Call mo_Db.Close(ll_Cursor)
  End If

  Exit Sub
ErrHandler:
  Call ErrorMessage("LoadSPAConfig")
End Sub

Private Sub btn_ChangeUoM_M2_Click()
On Error GoTo ErrHandler

  If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9864, "#Are you sure to '$OPERATION$' ?", Array("$OPERATION$", btn_ChangeUoM_M2.Caption), vbYesNo) = vbNo Then
    Exit Sub
  End If
  
  Call mo_Tools.LockScreen(Me, True)
  Call ChangeOfferUoM(eDPCQtyType.qtM2)
  Call RefreshOfferDetail
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ChangeUoM_PCS_Click")
End Sub

Private Sub btn_ChangeUoM_PCS_Click()
On Error GoTo ErrHandler

  If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9864, "#Are you sure to '$OPERATION$' ?", Array("$OPERATION$", btn_ChangeUoM_PCS.Caption), vbYesNo) = vbNo Then
    Exit Sub
  End If
  
  Call mo_Tools.LockScreen(Me, True)
  Call ChangeOfferUoM(eDPCQtyType.qtPCS)
  Call RefreshOfferDetail
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ChangeUoM_PCS_Click")
End Sub

Private Function FindPosition(ByVal al_Direction As Long, ByRef al_OFD_Pos As Long, ByRef as_OFD_IdPar As String) As Boolean
On Error GoTo ErrHandler

Dim ll_CurrentRow As Long

  FindPosition = False
  al_OFD_Pos = 0
  as_OFD_IdPar = ""
  ll_CurrentRow = grd_Offer.Row
  
  ll_CurrentRow = ll_CurrentRow + al_Direction
  Do While (ll_CurrentRow >= 0) And (ll_CurrentRow < grd_Offer.Rows)
    If (grd_Offer.Data(ll_CurrentRow, "OFD_Main") = eDPCOfferDetailMain.odMain) And _
       (grd_Offer.Data(ll_CurrentRow, "OFD_Id") = grd_Offer.Data(ll_CurrentRow, "OFD_IdPar")) Then
      al_OFD_Pos = grd_Offer.Data(ll_CurrentRow, "OFD_Pos")
      as_OFD_IdPar = grd_Offer.Data(ll_CurrentRow, "OFD_IdPar")
      FindPosition = True
      Exit Function
    End If
    ll_CurrentRow = ll_CurrentRow + al_Direction
  Loop
  Exit Function
ErrHandler:
  Call ErrorHandler("FindPosition")
End Function

Private Sub btn_MovePrev_Click()
On Error GoTo ErrHandler

Dim ll_CurrentOFD_Pos As Long, ll_NewOFD_Pos As Long
Dim ls_CurrentOFD_IdPar As String, ls_NewOFD_IdPar As String
Dim ls_req As String
Dim lb_InTran As Boolean
  
  If Not ((Status = eOfferStatus.osNew) Or _
     (Status = eOfferStatus.osOfferDefinition) Or _
     (Status = eOfferStatus.osOfferNeedApproval) Or _
     (Status = eOfferStatus.osUnderApprovalProcess)) Then
     Exit Sub
  End If
  
  If (grd_Offer.SelectedCount <> 1) Or _
     (grd_Offer.SelectedLine(0, "OFD_Main") <> eDPCOfferDetailMain.odMain) Or _
     grd_Offer.SelectedLine(0, "OFD_Id") <> grd_Offer.SelectedLine(0, "OFD_IdPar") Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9715, "#Please select one master record")
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  Call mo_Tools.LockScreen(Me, True)
  ls_CurrentOFD_IdPar = grd_Offer.SelectedLine(0, "OFD_IdPar")
  ll_CurrentOFD_Pos = grd_Offer.SelectedLine(0, "OFD_Pos")
  If FindPosition(-1, ll_NewOFD_Pos, ls_NewOFD_IdPar) Then
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "OFD_Pos_Prev")
    lb_InTran = True
    ls_req = "exec Cap_OfferDetail_OFD_Pos_upd $COF_Id$, $OFD_IdPar$, $OFD_PosDiff$"
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_IdPar$", mo_Tools.SQLStr(ls_CurrentOFD_IdPar), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_PosDiff$", mo_Tools.SqlInt(ll_NewOFD_Pos - ll_CurrentOFD_Pos), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    ls_req = "exec Cap_OfferDetail_OFD_Pos_upd $COF_Id$, $OFD_IdPar$, $OFD_PosDiff$"
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_IdPar$", mo_Tools.SQLStr(ls_NewOFD_IdPar), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_PosDiff$", mo_Tools.SqlInt(ll_CurrentOFD_Pos - ll_NewOFD_Pos), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "OFD_Pos_Prev")
    lb_InTran = False
    Call RefreshOfferDetail
    Call grd_Offer.SearchKey(True, ls_CurrentOFD_IdPar)
    grd_Offer.Col = grd_Offer.Columns("OFD_Pos").ColumnIndex
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "OFD_Pos_Prev")
  End If
  Call ErrorMessage("btn_MovePrev_Click")
End Sub

Private Sub btn_MoveNext_Click()
On Error GoTo ErrHandler

Dim ll_CurrentOFD_Pos As Long, ll_NewOFD_Pos As Long
Dim ls_CurrentOFD_IdPar As String, ls_NewOFD_IdPar As String
Dim ls_req As String
Dim lb_InTran As Boolean
  
  
  If Not ((Status = eOfferStatus.osNew) Or _
     (Status = eOfferStatus.osOfferDefinition) Or _
     (Status = eOfferStatus.osOfferNeedApproval) Or _
     (Status = eOfferStatus.osUnderApprovalProcess)) Then
     Exit Sub
  End If

  If (grd_Offer.SelectedCount <> 1) Or _
     (grd_Offer.SelectedLine(0, "OFD_Main") <> eDPCOfferDetailMain.odMain) Or _
     grd_Offer.SelectedLine(0, "OFD_Id") <> grd_Offer.SelectedLine(0, "OFD_IdPar") Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9715, "#Please select one master record")
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  Call mo_Tools.LockScreen(Me, True)
  ls_CurrentOFD_IdPar = grd_Offer.SelectedLine(0, "OFD_IdPar")
  ll_CurrentOFD_Pos = grd_Offer.SelectedLine(0, "OFD_Pos")
  If FindPosition(1, ll_NewOFD_Pos, ls_NewOFD_IdPar) Then
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "OFD_Pos_Prev")
    lb_InTran = True
    ls_req = "exec Cap_OfferDetail_OFD_Pos_upd $COF_Id$, $OFD_IdPar$, $OFD_PosDiff$"
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_IdPar$", mo_Tools.SQLStr(ls_CurrentOFD_IdPar), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_PosDiff$", mo_Tools.SqlInt(ll_NewOFD_Pos - ll_CurrentOFD_Pos), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    ls_req = "exec Cap_OfferDetail_OFD_Pos_upd $COF_Id$, $OFD_IdPar$, $OFD_PosDiff$"
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_IdPar$", mo_Tools.SQLStr(ls_NewOFD_IdPar), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_PosDiff$", mo_Tools.SqlInt(ll_CurrentOFD_Pos - ll_NewOFD_Pos), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "OFD_Pos_Prev")
    lb_InTran = False
    Call RefreshOfferDetail
    Call grd_Offer.SearchKey(True, ls_CurrentOFD_IdPar)
    grd_Offer.Col = grd_Offer.Columns("OFD_Pos").ColumnIndex
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "OFD_Pos_Prev")
  End If
  Call ErrorMessage("btn_MoveNext_Click")
End Sub

Private Sub btn_OfferCodeReset_Click()
On Error GoTo ErrHandler
    
  If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9741, "#Are you sure to reset document code ?", , vbYesNo) = vbYes Then
    If (Status = eOfferStatus.osNew) Or _
       (Status = eOfferStatus.osOfferDefinition) Or _
       (Status = eOfferStatus.osOfferNeedApproval) Or _
       (Status = eOfferStatus.osUnderApprovalProcess) Then
      Call mo_Tools.LockScreen(Me, True)
      txt_COF_Code.Text = GetCOF_Code("")
      Call mo_Tools.SetTextValue(txt_Textbox, "COF_Code", txt_COF_Code.Text)
      txt_Version.Text = "1"
      Call mo_Tools.LockScreen(Me, False)
    End If
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_OfferCodeReset_Click")
End Sub

Private Sub cal_COF_DocDat_Validate(Cancel As Boolean)
On Error GoTo ErrHandler

  If cal_COF_DocDat.date_dt = 0 Then
    Call mo_Tools.SetCalendarDate(cal_COF_DocDat, Date)
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_COF_DocDat_Validate")
End Sub

Private Sub cbo_LegalEntity_ComboItemSelected()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call mo_Tools.LockScreen(Me, True)
  Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_Konto", mo_Tools.GetComboData(cbo_LegalEntity, 2))
  Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_KontoDesc", cbo_LegalEntity.Text)
  Call InitVendorCombo(cbo_Vendor)
  Call InitShipPointCombo(cbo_ShipPoint)
  Call mo_Tools.LockScreen(Me, False)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_LegalEntity_ComboItemSelected")
End Sub

Private Sub cmd_MassEntry_Click()
On Error GoTo ErrHandler

Dim lo_DPC_MassEntry As frmDPC_MassEntry
Dim lb_Result As Boolean

  Call mo_Tools.LockScreen(Me, True)
  Set lo_DPC_MassEntry = New frmDPC_MassEntry
  Load lo_DPC_MassEntry
  Set lo_DPC_MassEntry.Tools = mo_Tools
  Set lo_DPC_MassEntry.ArmDb = mo_Db
  lo_DPC_MassEntry.Language_Code = ms_Language_Code
  lo_DPC_MassEntry.COF_Id = m_CurrentKey1
  lo_DPC_MassEntry.U_Code = ml_U_Code
  Call lo_DPC_MassEntry.Load_A_COM
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_DPC_MassEntry)
  Call Me.Refresh
  DoEvents
  Call mo_Tools.LockScreen(Me, True, False)
  lb_Result = lo_DPC_MassEntry.Result
  If lb_Result Then
    Call SaveMassEntry(lo_DPC_MassEntry)
  End If
  Call lo_DPC_MassEntry.Unload_A_COM
  Unload lo_DPC_MassEntry
  Set lo_DPC_MassEntry = Nothing
  If lb_Result Then Call tbs_Header_Click
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cmd_MassEntry_Click")
End Sub

Private Sub InitProgressBar(ByVal al_Count As Long)
  
  If al_Count > 0 Then
    If (fraItemTop.Width - fra_Progress.Width > 1000) And (fraItemTop.Height - fra_Progress.Height > 1000) Then
      Call fra_Progress.Move((fraItemTop.Width - fra_Progress.Width) / 2, (fraItemTop.Height - fra_Progress.Height) / 2)
    End If
    pgb_Progress.Value = 0
    pgb_Progress.Max = al_Count
    Call fra_Progress.Zorder
    lbl_Progress.Caption = pgb_Progress.Value & "/" & pgb_Progress.Max
    fra_Progress.Visible = True
    Call Me.Refresh
    DoEvents
  End If
End Sub

Private Sub ProgressBarSafeStep()
  If pgb_Progress.Value < pgb_Progress.Max Then
    pgb_Progress.Value = pgb_Progress.Value + 1
    lbl_Progress.Caption = pgb_Progress.Value & "/" & pgb_Progress.Max
    Call Me.Refresh
    DoEvents
  End If
End Sub

Private Sub SaveMassEntry(ByVal ao_MassEntry As frmDPC_MassEntry)
On Error GoTo ErrHandler

Dim ll_Idx As Long, ll_ColIdx As Long
Dim ll_Count As Long
Dim lo_DPC_Product As DPC_Product
Dim ls_PRD_Id As String
Dim ls_OFD_Id As String
Dim lb_InTran As Boolean
Dim ll_LEV_Id As eDPCLevel
Dim lo_Collection As Collection
Dim ll_RowStatus As Long


  ll_Count = 0
  For ll_Idx = 0 To ao_MassEntry.grd_PosList.Rows - 1
    If (ao_MassEntry.grd_PosList.Data(ll_Idx, "RowStatus") = eDPCRowStatus.rsAdd) Or _
       (ao_MassEntry.grd_PosList.Data(ll_Idx, "RowStatus") = eDPCRowStatus.rsUpdate) Or _
       (ao_MassEntry.grd_PosList.Data(ll_Idx, "RowStatus") = eDPCRowStatus.rsDrop) Then
      ll_Count = ll_Count + 1
    End If
  Next
  If (ll_Count > 0) Then
    Call InitProgressBar(ll_Count)
    For ll_Idx = 0 To ao_MassEntry.grd_PosList.Rows - 1
      Set lo_DPC_Product = Nothing
      
      ll_RowStatus = ao_MassEntry.grd_PosList.Data(ll_Idx, "RowStatus")
      ls_PRD_Id = ao_MassEntry.grd_PosList.Data(ll_Idx, "PRD_Id")
      ls_OFD_Id = ao_MassEntry.grd_PosList.Data(ll_Idx, "OFD_Id")
      
      If (ll_RowStatus = eDPCRowStatus.rsAdd) Or _
        (ll_RowStatus = eDPCRowStatus.rsUpdate) Then
        Set lo_DPC_Product = New DPC_Product
        Set lo_DPC_Product.Tools = mo_Tools
        Set lo_DPC_Product.ArmDb = mo_Db
        lo_DPC_Product.U_Code = ml_U_Code
        lo_DPC_Product.CT_Code = CT_Code
        lo_DPC_Product.CURR_Code = "EUR"
        lo_DPC_Product.ValidityDate = ValidityDate
        lo_DPC_Product.Language_Code = ms_Language_Code
        lo_DPC_Product.COF_Id = m_CurrentKey1
        Call lo_DPC_Product.Load_A_COM
        Call lo_DPC_Product.InitOffer
        Call lo_DPC_Product.Load(ls_PRD_Id)
        Call lo_DPC_Product.LoadOffer(m_CurrentKey1, ls_OFD_Id)
      End If
      
      If Not (lo_DPC_Product Is Nothing) Then
        If (ll_RowStatus = eDPCRowStatus.rsAdd) Then
          lo_DPC_Product.OFD_Pos = GetNextOFD_Pos
          Call lo_DPC_Product.Copy
        End If
        
        For ll_ColIdx = ao_MassEntry.grd_PosList.FixedCols To ao_MassEntry.grd_PosList.Cols - 1
          If (ao_MassEntry.grd_PosList.CellColor(ll_Idx, ll_ColIdx) = DPC_GRID_CHANGEDCELLCOLOR) Then
            Call lo_DPC_Product.SetAttribute(ao_MassEntry.grd_PosList.Columns(ll_ColIdx).Name, ao_MassEntry.grd_PosList.Data(ll_Idx, ll_ColIdx))
          End If
        Next
        
        Call lo_DPC_Product.CleanInlay
        Call lo_DPC_Product.CleanCutout
        
        Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "SaveMassEntry")
        lb_InTran = True
        
        If (lo_DPC_Product.LEV_Id > eDPCLevel.lvStandard) Then
          If ll_RowStatus = eDPCRowStatus.rsAdd Then
            ls_OFD_Id = ""
            Call lo_DPC_Product.Insert
            Call lo_DPC_Product.RefreshPriceWithCheck(True)
          ElseIf ll_RowStatus = eDPCRowStatus.rsUpdate Then
            Call lo_DPC_Product.Update
            Call lo_DPC_Product.RefreshPriceWithCheck(False)
          End If
          
          
          Set lo_Collection = lo_DPC_Product.GenerateOfferDetail
          If Not (lo_Collection Is Nothing) Then
            Call SaveOfferDetail(lo_Collection, ls_OFD_Id, COF_DocDat, CURR_Code, Status)
            Call mo_Tools.ClearCollection(lo_Collection)
            Set lo_Collection = Nothing
          End If
        End If
        Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "SaveMassEntry")
        lb_InTran = False
        
        Call lo_DPC_Product.Unload_A_COM
        Set lo_DPC_Product = Nothing
        
        Call ProgressBarSafeStep
      End If
    Next
    fra_Progress.Visible = False
  End If
  
  Exit Sub
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "SaveMassEntry")
  End If
  Call ErrorHandler("SaveMassEntry")
End Sub

Private Sub cmd_ExportCADPDF_Click()
On Error GoTo ErrHandler

Dim ls_PRD_Id As String, ls_OFD_Id As String, ls_PRD_Code As String
Dim ll_Idx As Long
Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrMsg As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean
Dim lo_Collection As New Collection
Dim ls_InstallDir As String

    If Not mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_CAD_PDF_GENERATOR") Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9868, "#You do not have enough rights to do this operation")
      Exit Sub
    End If

  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  lb_Result = False
  
  'check version and update generator if new version is available
  ls_InstallDir = App.Path + "\" & INI_NETAPP_PATH & "\" & INI_DPC_CAD_PDF_GENERATOR_DIR
  If mo_Tools.CheckForNewVersion(SCREEN_NAME, "DPC_CAD_PDF_GEN", INI_DPC_CAD_PDF_GENERATOR_SETUP_EXE, ls_InstallDir, INI_DPC_CAD_PDF_GENERATOR_EXE, True) = False Then
    Exit Sub
  End If
  
  For ll_Idx = 0 To grd_PosList.Rows - 1
    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
    ls_OFD_Id = grd_PosList.Data(ll_Idx, "OFD_Id")
    ls_PRD_Code = grd_PosList.Data(ll_Idx, "PRD_Code")
    Call lo_Collection.Add(ls_PRD_Id & "," & ls_OFD_Id & "," & ls_PRD_Code)
  Next
  
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.Language_Code = ms_Language_Code
  lo_XmlExport.CT_Code = ms_CT_Code
  lo_XmlExport.U_Code = ml_U_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.CAD_GeneratePDFFiles(m_CurrentKey1, lo_Collection, ls_ErrMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Export CAD/PDF was successful. $TEXT$", Array("$OPERATION$", cmd_ExportCADPDF.Caption, "$TEXT$", ""))
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Export CAD/PDF failed: $ERROR$", Array("$OPERATION$", cmd_ExportCADPDF.Caption, "$ERROR$", ls_ErrMsg))
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("cmd_ExportCADPDF")
End Sub

Private Sub cmd_ShowPDF_Click()
On Error GoTo ErrHandler

Dim lo_shell As Object
Dim ls_PDFName As String
Dim ls_ErrorMsg As String
Dim ll_RowIdx As Long

  For ll_RowIdx = 0 To grd_PosList.Rows - 1
    If StrComp(grd_PosList.Data(ll_RowIdx, "Selected"), "CHECK", vbTextCompare) = 0 Then
      ls_PDFName = grd_PosList.Data(ll_RowIdx, "PRD_Code")
      ls_PDFName = mo_Tools.GetAConfigData("DPC_CAD_DestDir") + "\" + ls_PDFName + ".pdf"
          
      If Not mo_FSO.FileExists(ls_PDFName) Then
          ls_ErrorMsg = mo_Tools.MsgText(mo_Db, ms_Language_Code, 9353, "#The file $FileName$ does not exists.", Array("$FileName$", ls_PDFName))
          Call MsgBox(ls_ErrorMsg, vbOKOnly, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
          Exit Sub
      End If
      Set lo_shell = CreateObject("Shell.Application")
      Call lo_shell.ShellExecute(ls_PDFName, "", "", "open", 1)
      Set lo_shell = Nothing
    End If
  Next
  Exit Sub
ErrHandler:
  Set lo_shell = Nothing
  Call ErrorMessage("cmd_ShowPDF_Click")
End Sub

Private Sub ExportExcelOffer(ByVal as_COF_Id As String)
Dim lo_ExcelProcessor As CExcelTemplateProcessor
Dim ls_req As String
Dim ls_filePath As String
Dim ls_ErrorMsg As String

  If Not mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_OFFEREXPORTEXCEL") Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9868, "#You do not have enough rights to do this operation")
    Exit Sub
  End If
  
  If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9864, "#Are you sure to '$OPERATION$' ?", Array("$OPERATION$", "Export Excel"), vbYesNo) = vbNo Then
    Exit Sub
  End If

  If LoadAFile("EXCEL_TMP_OFFER", "DPC_OfferExport.xlsx", App.Path & "\Download\ExcelTmp\") = False Then
      Exit Sub
  End If
  
  ls_filePath = App.Path & "\Download\ExcelTmp\DPC_OfferExport.xlsx"
  
  Set lo_ExcelProcessor = New CExcelTemplateProcessor
  Set lo_ExcelProcessor.ArmDb = mo_Db
  lo_ExcelProcessor.Language = mo_Tools.SelectValue(mo_Db, "SELECT COF_Lang FROM Cap_Offer WHERE COF_Id=" & mo_Tools.SQLStr(as_COF_Id))
  Set lo_ExcelProcessor.Tools = mo_Tools
  Call lo_ExcelProcessor.Load_A_COM
  
  ls_req = "exec Cap_OffersPrintHeader_sel $COF_ID$,$COF_Lang$"
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Lang$", mo_Tools.SQLStr(lo_ExcelProcessor.Language))
  Call lo_ExcelProcessor.AddNewOfferData(ls_req)
  
  ls_req = "exec Cap_OffersPrintHeader_sel2 $COF_ID$,$COF_Lang$,'X',''"
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Lang$", mo_Tools.SQLStr(lo_ExcelProcessor.Language))
  Call lo_ExcelProcessor.AddNewOfferData(ls_req)
  
  ls_req = "exec Cap_OffersPrintDetail_sel $COF_ID$,$COF_Lang$,'X',''"
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Lang$", mo_Tools.SQLStr(lo_ExcelProcessor.Language))
  Call lo_ExcelProcessor.AddNewOfferTable(eDPCOfferDetailIsAlt.maMain, ls_req)
  
  ls_req = "exec Cap_OffersPrintAlternative_sel $COF_ID$,$COF_Lang$,''"
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Lang$", mo_Tools.SQLStr(lo_ExcelProcessor.Language))
  Call lo_ExcelProcessor.AddNewOfferTable(eDPCOfferDetailIsAlt.maAltenative, ls_req)
  
  ls_req = "exec Cap_OffersPrintSurcharge_sel $COF_ID$,$COF_Lang$"
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id))
  ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Lang$", mo_Tools.SQLStr(lo_ExcelProcessor.Language))
  Call lo_ExcelProcessor.AddNewOfferTable(eDPCOfferDetailIsAlt.maOption, ls_req)
  
  If Not lo_ExcelProcessor.ProcessOfferFile(ls_filePath, ls_ErrorMsg) Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Export to Excel failed: $ERROR$", Array("$OPERATION$", "Export Excel", "$ERROR$", ls_ErrorMsg))
  End If
  Call lo_ExcelProcessor.Unload_A_COM
  Set lo_ExcelProcessor = Nothing
  Exit Sub
ErrHandler:
  Call ErrorMessage("ExportExcelOffer")
End Sub

Private Sub txt_SKUQty_Validate(Cancel As Boolean)
On Error GoTo ErrHandler
  
Dim ll_Decimal As Long
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  ll_Decimal = mo_Tools.GetUM_Decimal(mo_Tools.GetComboKey(cbo_SKUUOM), ms_COF_Lang)
  txt_SKUQty.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(txt_SKUQty.Text, ll_Decimal), ll_Decimal)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_SKUQty_Validate")
End Sub

Private Sub cbo_SKUUOM_ComboItemSelected()
On Error GoTo ErrHandler

Dim ll_Decimal As Long

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  ll_Decimal = mo_Tools.GetUM_Decimal(mo_Tools.GetComboKey(cbo_SKUUOM), ms_COF_Lang)
  txt_SKUQty.Text = mo_Tools.DblToScreen(mo_Tools.ScreenToDbl(txt_SKUQty.Text, ll_Decimal), ll_Decimal)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_SKUUOM_ComboItemSelected")
End Sub

Private Sub cbo_Vendor_ComboItemSelected()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call cbo_ShipPoint.Clear
  Call InitShipPointCombo(cbo_ShipPoint)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_Vendor_ComboItemSelected")
End Sub

Private Sub grd_Baeurer_ItemSelected()
On Error GoTo ErrHandler

  If Not mo_BaeurerTextBox Is Nothing Then
    mo_BaeurerTextBox.Text = grd_Baeurer.SelectedLine(0, "Code")
  End If
  If Not mo_BaeurerLabel Is Nothing Then
    mo_BaeurerLabel.Caption = grd_Baeurer.SelectedLine(0, "Text")
  End If
  Call HideBaeurerGrid
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Baeurer_ItemSelected")
End Sub

Private Sub grd_Baeurer_LostFocus()
On Error GoTo ErrHandler
  
  Call HideBaeurerGrid
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Baeurer_LostFocus")
End Sub

Private Sub ShowBaeurerGrid(ByVal ao_Command As VB.CommandButton, ByVal ao_TextBox As VB.TextBox, ByVal ao_Label As VB.Label, ByVal ae_Reference As eDPCBaeurerReference, Optional ByVal av_Param As Variant = Empty)
On Error GoTo ErrHandler

Dim lo_Baeurer As New DPC_Interface

  Call HideBaeurerGrid
  Set lo_Baeurer.Tools = mo_Tools
  Set lo_Baeurer.ArmDb = mo_Db
  lo_Baeurer.U_Code = ml_U_Code
  Call lo_Baeurer.Load_A_COM
  Call lo_Baeurer.Bae_LoadBaeurerReferenceGrid(grd_Baeurer, ae_Reference, av_Param)
  Call lo_Baeurer.Unload_A_COM
  Set lo_Baeurer = Nothing
  
  If Trim(ao_TextBox.Text) = "" Then
    grd_Baeurer.Row = 0
  Else
    Call grd_Baeurer.SearchKey(True, ao_TextBox.Text)
  End If
  Set mo_BaeurerTextBox = ao_TextBox
  Set mo_BaeurerLabel = ao_Label
  Call grd_Baeurer.Move(fra_Header(4).Left + ao_Command.Left + ao_Command.Width, fra_Header(4).Top + ao_Command.Top)
  grd_Baeurer.Zorder
  grd_Baeurer.Visible = True
  grd_Baeurer.Enabled = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("ShowBaeurerGrid")
End Sub

Private Sub HideBaeurerGrid()
On Error GoTo ErrHandler

  grd_Baeurer.Visible = False
  Set mo_BaeurerTextBox = Nothing
  Set mo_BaeurerLabel = Nothing
  Exit Sub
ErrHandler:
  Call ErrorHandler("HideBaeurerGrid")
End Sub

Private Sub btn_BaeurerReference_Click(Index As Integer)
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  Select Case btn_BaeurerReference(Index).Tag
  Case "btn_COF_Bae_OrdTyp"
    Call ShowBaeurerGrid(btn_BaeurerReference(Index), mo_Tools.GetControl(txt_Textbox, "COF_Bae_OrdTyp"), mo_Tools.GetControl(lbl_Label, "_COF_Bae_OrdTypDesc"), eDPCBaeurerReference.brOrderType)
  Case "btn_COF_Bae_Partner"
    Call ShowBaeurerGrid(btn_BaeurerReference(Index), mo_Tools.GetControl(txt_Textbox, "COF_Bae_Partner"), mo_Tools.GetControl(lbl_Label, "_COF_Bae_PartnerDesc"), eDPCBaeurerReference.brPartner, Array("$konto$", Val(mo_Tools.GetControl(txt_Textbox, "COF_Bae_Konto").Text)))
  Case "btn_COF_Bae_InCharge"
    Call ShowBaeurerGrid(btn_BaeurerReference(Index), mo_Tools.GetControl(txt_Textbox, "COF_Bae_InCharge"), mo_Tools.GetControl(lbl_Label, "_COF_Bae_InChargeDesc"), eDPCBaeurerReference.brClerkInCharge)
  Case "btn_COF_Bae_DelCond"
    Call ShowBaeurerGrid(btn_BaeurerReference(Index), mo_Tools.GetControl(txt_Textbox, "COF_Bae_DelCond"), mo_Tools.GetControl(lbl_Label, "_COF_Bae_DelCondDesc"), eDPCBaeurerReference.brDeliveryCondition)
  Case "btn_COF_Bae_DelType"
    Call ShowBaeurerGrid(btn_BaeurerReference(Index), mo_Tools.GetControl(txt_Textbox, "COF_Bae_DelType"), mo_Tools.GetControl(lbl_Label, "_COF_Bae_DelTypeDesc"), eDPCBaeurerReference.brDeliveryType)
  Case "btn_COF_Bae_PackType"
    Call ShowBaeurerGrid(btn_BaeurerReference(Index), mo_Tools.GetControl(txt_Textbox, "COF_Bae_PackType"), mo_Tools.GetControl(lbl_Label, "_COF_Bae_PackTypeDesc"), eDPCBaeurerReference.brPackType)
  Case "btn_COF_Bae_AddrNr"
    Call ShowBaeurerGrid(btn_BaeurerReference(Index), mo_Tools.GetControl(txt_Textbox, "COF_Bae_AddrNr"), mo_Tools.GetControl(lbl_Label, "_COF_Bae_AddrNrDesc"), eDPCBaeurerReference.brAddressNo)
  End Select
  Call mo_Tools.LockScreen(Me, False)
  If grd_Baeurer.Visible Then Call grd_Baeurer.SetFocus
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_BaeurerReference_Click")
End Sub

Private Sub btn_SAPPrice_Click()
On Error GoTo ErrHandler

Dim ls_req As String
Dim lc_Cursor As Long
Dim ls_ErrMsg As String
Dim ll_MsgCode As ErrMsg
Dim ls_Distr_Chan As String
Dim ls_PriceDate As String
Dim ls_SLS_Org As String
Dim ls_CUST_Code As String
Dim ls_BI_SAP_Code As String
Dim ls_SAP_Division As String
Dim ls_SAP_Doc_Type As String
Dim ls_SAP_Partn_Role As String
Dim ls_UOM As String
Dim ls_SPA_UrlGetSalesOrder As String
Dim ls_PriceGroup As String
Dim ls_Qty As String
Dim ls_CURR_Code As String
Dim ld_Price As Double

  Call mo_Tools.LockScreen(Me, True)
  Call LoadSPAConfig
  
  ls_req = "exec SPA_CustomerData_sel $CCU_CapKey$, 'E'"
  ls_req = Replace(ls_req, "$CCU_CapKey$", mo_Tools.SQLStr(mo_Tools.GetComboKey(cbo_Customer)), , , vbTextCompare)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  ls_CUST_Code = mo_Db.GetFields(lc_Cursor, "CUST_Code")
  ls_SLS_Org = mo_Db.GetFields(lc_Cursor, "SLSORG")
  Call mo_Db.Close(lc_Cursor)
  
  'ls_CUST_Code = "0000207632"
  'ls_SLS_Org = "BP05"
  
  If ls_CUST_Code = "" Then
    Call mo_Tools.LockScreen(Me, False)
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9702, "#Selected customer is not buying customer")
    Exit Sub
  End If
  
  If ls_SLS_Org = "" Then
    Call mo_Tools.LockScreen(Me, False)
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9703, "#SAP sales organisation for selected customer not found")
    Exit Sub
  End If
  
  ls_BI_SAP_Code = txt_BI_SAP_Code.Text
  
'  ls_req = "exec Cap_OfferDetail_BI_SAP_sel $S_Code$"
'  ls_req = Replace(ls_req, "$S_Code$", mo_Tools.SqlStr(txt_S_Code.Text), , , vbTextCompare)
'  ls_BI_SAP_Code = mo_Tools.SelectValue(mo_Db, ls_req)
'  If ls_BI_SAP_Code = "" Then
'    Call mo_Tools.LockScreen(Me, False)
'    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9704, "#Product SAP code not found")
'    Exit Sub
'  End If
    
  ls_PriceDate = Format(Now, "dd\/mm\/yyyy")
  ls_Distr_Chan = mo_A_Config(C_A_CONFIG_Distr_Chan)
  ls_SAP_Division = mo_A_Config(C_A_CONFIG_Division)
  ls_SAP_Doc_Type = mo_A_Config(C_A_CONFIG_Doc_Type)
  ls_SAP_Partn_Role = mo_A_Config(C_A_CONFIG_Partn_Role)
  ls_SPA_UrlGetSalesOrder = mo_A_Config(C_A_CONFIG_UrlGetSalesOrder)
  
  ls_UOM = mo_Tools.GetComboKey(cbo_SKUUOM)
  If ls_UOM = DPC_UOM_PCS Then ls_UOM = "PC"
  
  ls_PriceGroup = "11"
  ls_Qty = mo_Tools.ScreenToLong(txt_SKUQty.Text)
  ld_Price = GetSAPItemPrice(ls_SLS_Org, ls_PriceGroup, ls_PriceDate, ls_BI_SAP_Code, ls_Qty, ls_UOM, ls_CUST_Code, ls_CURR_Code, ls_ErrMsg, ll_MsgCode)

  If ll_MsgCode = ErrMsgNone Then
    txt_SKUPrice.Text = mo_Tools.DblToScreen(ld_Price)
    txt_SKUPriceM.Text = mo_Tools.DblToScreen(ld_Price)
    txt_CURR_Code.Text = ls_CURR_Code
  End If
  
  Call mo_Tools.LockScreen(Me, False)
  If ll_MsgCode <> ErrMsgNone Then
      Call MsgBox(ls_ErrMsg)
  End If
 Exit Sub
ErrHandler:
  Call ErrorMessage("btn_SAPPrice_Click")
End Sub

Private Function SelectBaseItem() As String
On Error GoTo ErrHandler
    
Dim ls_BI_SAP_Code As String
Dim lo_SearchForm As Item_sel

  ls_BI_SAP_Code = ""
  gs_CGCode = ""
  gs_Photo = ""
  Set lo_SearchForm = New Item_sel
  Load lo_SearchForm
  lo_SearchForm.ms_TypeCodeReturn = 1
  lo_SearchForm.CalledFromSPA = True
  Call lo_SearchForm.Show(1)
  
  If gb_Return = OK Then
      ls_BI_SAP_Code = gs_Photo
  End If
  
  Unload lo_SearchForm
  Set lo_SearchForm = Nothing
  SelectBaseItem = ls_BI_SAP_Code
  Exit Function
ErrHandler:
  If Not lo_SearchForm Is Nothing Then
      Unload lo_SearchForm
      Set lo_SearchForm = Nothing
  End If
  Call ErrorHandler("SelectBaseItem")
End Function

Private Function CreateSizeText(ByVal ad_Length As Double, ByVal ad_Width As Double, ByVal ad_Height As Double) As String
On Error GoTo ErrHandler

Dim ls_Text As String

  ls_Text = ""
  If ad_Length > 0 Then
    ls_Text = ls_Text & mo_Tools.DblToScreen(ad_Length)
  End If
  If ad_Width > 0 Then
    If ls_Text <> "" Then ls_Text = ls_Text & "x"
    ls_Text = ls_Text & mo_Tools.DblToScreen(ad_Width)
  End If
  If ad_Height > 0 Then
    If ls_Text <> "" Then ls_Text = ls_Text & "x"
    ls_Text = ls_Text & mo_Tools.DblToScreen(ad_Height)
  End If
  If ls_Text <> "" Then
    ls_Text = " (" & ls_Text & ")"
  End If
  CreateSizeText = ls_Text
  Exit Function
ErrHandler:
  Call ErrorHandler("CreateSizeText")
End Function

Private Function CreatePUText(ByVal al_PU As Long) As String
On Error GoTo ErrHandler

Dim ls_Text As String

  ls_Text = ""
  If al_PU > 1 Then
    ls_Text = ls_Text & " (PU=" & mo_Tools.LongToScreen(al_PU) & ")"
  End If
  CreatePUText = ls_Text
  Exit Function
ErrHandler:
  Call ErrorHandler("CreatePUText")
End Function

Private Sub btn_SelectProduct_Click()
On Error GoTo ErrHandler

Dim ls_SelectedItemCode As String
Dim ls_SelectedItemDesc As String
Dim ld_Price As Double
Dim lc_Cursor As Long
Dim ls_CG_code As String
Dim ls_Request As String
Dim ls_UM_Code As String

  Call mo_Tools.LockScreen(Me, True)
  
  ls_SelectedItemCode = SelectBaseItem
    
  txt_BI_SAP_Code.Text = ls_SelectedItemCode
  If ls_SelectedItemCode <> "" Then
    ls_Request = "exec DPC_Base_Item_sel $BI_SAP_Code$, $COF_Lang$"
    ls_Request = Replace(ls_Request, "$BI_SAP_Code$", mo_Tools.SQLStr(ls_SelectedItemCode), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    
    lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
    If mo_Db.RowCount(lc_Cursor) = 1 Then
      txt_BI_SAP_Desc.Text = mo_Db.GetFields(lc_Cursor, "BI_Desc") & _
                            CreateSizeText(mo_Db.GetFields(lc_Cursor, "BI_Length"), mo_Db.GetFields(lc_Cursor, "BI_Width"), mo_Db.GetFields(lc_Cursor, "BI_Height")) & _
                            CreatePUText(mo_Db.GetFields(lc_Cursor, "LI_piecepercart"))
      txt_PRD_Id.Text = mo_Db.GetFields(lc_Cursor, "PRD_Id")
      txt_S_Code.Text = mo_Db.GetFields(lc_Cursor, "S_Code")
      ls_UM_Code = mo_Db.GetFields(lc_Cursor, "UM_Code")
      ls_CG_code = mo_Db.GetFields(lc_Cursor, "CG_Code")
      txt_SKUQty.Text = "1"
      If mo_Db.GetFields(lc_Cursor, "LI_piecepercart") = 0 Then
        txt_SKUPU.Text = "1"
      Else
        txt_SKUPU.Text = mo_Db.GetFields(lc_Cursor, "LI_piecepercart")
      End If
      ld_Price = 0
      If txt_PRD_Id.Text <> "" Then
        ld_Price = GetSKUPrice(txt_PRD_Id.Text, 1, CT_Code, CURR_Code, ValidityDate)
      End If
      txt_SKUPrice.Text = mo_Tools.DblToScreen(ld_Price)
      txt_SKUPriceM.Text = mo_Tools.DblToScreen(ld_Price)
      If cbo_SKUUOM.Count = 0 Then Call cbo_SKUUOM.Load
      If ls_UM_Code = "" Then
        If StrComp(ls_CG_code, "C001", vbTextCompare) = 0 Then
          Call cbo_SKUUOM.SearchItem(DPC_UOM_PU)
        ElseIf StrComp(ls_CG_code, "C002", vbTextCompare) = 0 Then
          Call cbo_SKUUOM.SearchItem("BOX")
        Else
          Call cbo_SKUUOM.SearchItem(DPC_UOM_PCS)
        End If
      Else
        Call cbo_SKUUOM.SearchItem(ls_UM_Code)
      End If
    End If
    Call mo_Db.Close(lc_Cursor)
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_SelectProduct_Click")
End Sub

Private Sub cal_COF_FoDat_changeposition(y As Integer)
On Error GoTo ErrHandler
  
  If y >= 0 Then
    Call cal_COF_FoDat.Zorder(1)
  Else
    Call cal_COF_FoDat.Zorder
  End If
  cal_COF_FoDat.Top = cal_COF_FoDat.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_COF_FoDat_changeposition")
End Sub

Private Sub cal_COF_ExDat_changeposition(y As Integer)
On Error GoTo ErrHandler
  
  If y >= 0 Then
    Call cal_COF_ExDat.Zorder(1)
  Else
    Call cal_COF_ExDat.Zorder
  End If
  cal_COF_ExDat.Top = cal_COF_ExDat.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_COF_ExDat_changeposition")
End Sub

Private Sub cal_COF_ApDat_changeposition(y As Integer)
On Error GoTo ErrHandler
  
  If y >= 0 Then
    Call cal_COF_ApDat.Zorder(1)
  Else
    Call cal_COF_ApDat.Zorder
  End If
  cal_COF_ApDat.Top = cal_COF_ApDat.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_COF_ApDat_changeposition")
End Sub

Private Sub cal_OFD_DelDat_changeposition(y As Integer)
On Error GoTo ErrHandler

  Call cal_OFD_DelDat.Zorder
  cal_OFD_DelDat.Top = cal_OFD_DelDat.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_OFD_DelDat_changeposition")
End Sub

Private Sub cal_COF_DocDat_changeposition(y As Integer)
On Error GoTo ErrHandler

  Call cal_COF_DocDat.Zorder
  cal_COF_DocDat.Top = cal_COF_DocDat.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_COF_DocDat_changeposition")
End Sub

Private Sub cal_OFD_WshDat_changeposition(y As Integer)
On Error GoTo ErrHandler

  Call cal_OFD_WshDat.Zorder
  cal_OFD_WshDat.Top = cal_OFD_WshDat.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_OFD_WshDat_changeposition")
End Sub

Private Sub cal_OFD_ShpDat_changeposition(y As Integer)
On Error GoTo ErrHandler

  Call cal_OFD_ShpDat.Zorder
  cal_OFD_ShpDat.Top = cal_OFD_ShpDat.Top + y
  Exit Sub
ErrHandler:
  Call ErrorMessage("cal_OFD_ShpDat_changeposition")
End Sub

Private Sub chk_FreeOfCharge_Click()
On Error GoTo ErrHandler

  If chk_FreeOfCharge.Value = vbChecked Then
    Call mo_Tools.EnableControl(txt_SKUPriceM, False)
    txt_SKUPriceM.Text = mo_Tools.DblToScreen(0)
  Else
    txt_SKUPriceM.Text = txt_SKUPrice.Text
    Call mo_Tools.EnableControl(txt_SKUPriceM, True)
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("chk_FreeOfCharge_Click")
End Sub

Private Sub cbo_currencies_ComboItemSelected()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call mo_Tools.LockScreen(Me, True)
  
  Call CalculateExchangeRate(mo_Tools.GetComboKey(cbo_currencies))
  Call RefreshOfferDetail
  
  Call mo_Tools.LockScreen(Me, False)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_currencies_ComboItemSelected")
End Sub

Private Function LoadBaeurerReferenceText(ByVal ae_Reference As eDPCBaeurerReference, ByVal as_Code As String, Optional ByVal av_Param As Variant = Empty) As String
On Error GoTo ErrHandler

Dim lo_Baeurer As New DPC_Interface
Dim ls_Text As String

  LoadBaeurerReferenceText = ""
  Set lo_Baeurer.Tools = mo_Tools
  Set lo_Baeurer.ArmDb = mo_Db
  lo_Baeurer.U_Code = ml_U_Code
  Call lo_Baeurer.Load_A_COM
  If lo_Baeurer.Bae_LoadBaeurerReferenceText(ae_Reference, as_Code, av_Param, ls_Text) Then
    LoadBaeurerReferenceText = ls_Text
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9849, "#Record not found")
  End If
  Call lo_Baeurer.Unload_A_COM
  Set lo_Baeurer = Nothing
  Exit Function
ErrHandler:
  Call ErrorHandler("LoadBaeurerReferenceText")
End Function

Private Sub txt_COF_CodeCus_Validate(Cancel As Boolean)
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  Call mo_Tools.SetTextValue(txt_Textbox, "COF_CodeCus", txt_COF_CodeCus.Text)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_COF_CodeCus_Validate")
End Sub

Private Sub txt_Textbox_Change(Index As Integer)
On Error GoTo ErrHandler
  
  If mb_InternalInit Then Exit Sub
  mb_CurrentTextBoxChanged = True
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_TextBox_Change")
End Sub

Private Sub txt_Textbox_Validate(Index As Integer, Cancel As Boolean)
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  If Not mb_CurrentTextBoxChanged Then Exit Sub
  
  Call mo_Tools.LockScreen(Me, True)
  mb_InternalInit = True
  
  Select Case txt_Textbox(Index).Tag
  Case "COF_Bae_Konto"
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_KontoDesc", LoadBaeurerReferenceText(eDPCBaeurerReference.brKonto, Val(txt_Textbox(Index).Text)))
  Case "COF_Bae_OrdTyp"
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_OrdTypDesc", LoadBaeurerReferenceText(eDPCBaeurerReference.brOrderType, Val(txt_Textbox(Index).Text)))
  Case "COF_Bae_Partner"
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_PartnerDesc", LoadBaeurerReferenceText(eDPCBaeurerReference.brPartner, Val(txt_Textbox(Index).Text), Array("$konto$", mo_Tools.GetControl(txt_Textbox, "COF_Bae_Konto").Text)))
  Case "COF_Bae_InCharge"
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_InChargeDesc", LoadBaeurerReferenceText(eDPCBaeurerReference.brClerkInCharge, Val(txt_Textbox(Index).Text)))
  Case "COF_Bae_DelCond"
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_DelCondDesc", LoadBaeurerReferenceText(eDPCBaeurerReference.brDeliveryCondition, Val(txt_Textbox(Index).Text)))
  Case "COF_Bae_DelType"
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_DelTypeDesc", LoadBaeurerReferenceText(eDPCBaeurerReference.brDeliveryType, Val(txt_Textbox(Index).Text)))
  Case "COF_Bae_PackType"
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_PackTypeDesc", LoadBaeurerReferenceText(eDPCBaeurerReference.brPackType, Val(txt_Textbox(Index).Text)))
  Case "COF_CodeCus"
    txt_COF_CodeCus.Text = txt_Textbox(Index).Text
  Case Else
    'Err.Raise ArmErr.InvalidArgument, "txt_TextBox(" & Index & ").Tag", "Unknown textbox tag:" & txt_Textbox(Index).Tag
  End Select
  
  mb_InternalInit = False
  mb_CurrentTextBoxChanged = False
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_TextBox_Validate")
End Sub

Private Sub btn_ExportMaterialCreate_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As DPC_Interface
Dim ls_ErrorMsg As String
Dim ll_Count As Long
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  ll_Count = 0
  Set lo_XmlExport = New DPC_Interface
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.U_Code = ml_U_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.SAP_OfferMaterialCreate(m_CurrentKey1, ll_Count, ls_ErrorMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Export Material to SAP was successful. $TEXT$", Array("$OPERATION$", btn_ExportMaterialCreate.Caption, "$TEXT$", " Count: (" & ll_Count & ")" & vbCrLf & ls_ErrorMsg))
    'Call MsgBox("Export Material to SAP was successful. Number of exported products: " & ll_Count & vbCrLf & ls_ErrorMsg)
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Export material to SAP failed: $ERROR$", Array("$OPERATION$", btn_ExportMaterialCreate.Caption, "$ERROR$", ls_ErrorMsg & vbCrLf & " Count: (" & ll_Count & ")"))
    'Call MsgBox("Export material to SAP failed: " & ls_ErrorMsg & vbCrLf & " Number of successful exported products: " & ll_Count)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_ExportMaterialCreate_Click")
End Sub

Private Sub btn_ExportSalesOrderCreate_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrorMsg As String
Dim ls_warning As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

'Dim le_SAP_Sta As eDPCInterfaceStatus
'Dim lc_Cursor As Long
'Dim ll_LinesCount As Long
'Dim lo_XmlExportBae As New DPC_Interface

'  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, "SELECT COF_DeDesc, COF_DeAdr1, COF_DeAdr2, COF_DeTown, COF_DeZip, COF_DeCT FROM Cap_Offer WHERE COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1))
'  If (mo_Db.GetFields(lc_Cursor, "COF_DeDesc") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeAdr1") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeAdr2") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeTown") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeZip") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeCT") <> "") Then
'
'    If (mo_Db.GetFields(lc_Cursor, "COF_DeDesc") = "") Or _
'       (mo_Db.GetFields(lc_Cursor, "COF_DeAdr1") = "") Or _
'       (mo_Db.GetFields(lc_Cursor, "COF_DeTown") = "") Or _
'       (mo_Db.GetFields(lc_Cursor, "COF_DeZip") = "") Or _
'       (mo_Db.GetFields(lc_Cursor, "COF_DeCT") = "") Then
'      Call MsgBox("Delivery Name, Street, Town and Country is mandatory. (Save any changes before export !)")
'      Call mo_Db.Close(lc_Cursor)
'      Exit Sub
'    End If
'  End If
'  Call mo_Db.Close(lc_Cursor)
'  If mo_Tools.SelectValue(mo_Db, "SELECT CCU.CUST_Code FROM Cap_Offer COF INNER JOIN claim_customer CCU ON (CCU.CCU_CapKey=COF.CCU_CapKey) WHERE COF.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1)) = "" Then
'    Call MsgBox("Customer must be SAP buying customer")
'    Exit Sub
'  End If
'
'  If mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD INNER JOIN DPC_PrdCommon PRD ON (OFD.PRD_Id=PRD.PRD_Id) WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Main=1 AND OFD.OFD_Valid='X' AND (OFD.DOF_Id IN (1,37)) AND (OFD.CAT_Id IN (1,20)) AND PRD.PRD_StaSAP<>1 AND OFD.Drop_Flag=''") > 0 Then
'    Call MsgBox("Not all custom materials inside sales order were successfuly exported to SAP")
'    Exit Sub
'  End If
'
'  If mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Main=1 AND OFD.OFD_Valid='X' AND OFD.DOF_Id=1 AND (OFD.CAT_Id IN (1,21)) AND OFD.OFD_PosB7=0 AND OFD.Drop_Flag=''") > 0 Then
'    Call MsgBox("Not all standard and custom metal materials inside sales order were successfuly send and received from B7 planning box")
'    Exit Sub
'  End If
'
'  If mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Main=1 AND OFD.OFD_Valid='X' AND (OFD.DOF_Id IN (1,37)) AND (OFD.CAT_Id IN (1,15,20,21)) AND OFD.OFD_Price=0 AND OFD.OFD_IsFree='' AND OFD.Drop_Flag=''") > 0 Then
'    Call MsgBox("Price of item is 0, but is not marked as free of charge")
'    Exit Sub
'  End If
'
'  If mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Main=1 AND OFD.OFD_Valid='X' AND OFD.OFD_Price>0 AND OFD.OFD_IsFree='X' AND OFD.Drop_Flag=''") > 0 Then
'    Call MsgBox("Price of item greater than 0, but is marked as free of charge")
'    Exit Sub
'  End If
'
'  ll_LinesCount = mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Valid='X' AND ((OFD.CAT_Id <> 10 AND OFD.OFD_Main=1) OR (OFD.CAT_Id = 10 AND OFD.OFD_Main=2)) AND OFD.Drop_Flag=''")
'  If ll_LinesCount > 166 Then
'    Call MsgBox("Order contain more than 166 lines. Pleas split order into more documents.")
'    Exit Sub
'  End If
  
  Call mo_Tools.LockScreen(Me, True)
  Call LoadSPAConfig
  
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.U_Code = ml_U_Code
  lo_XmlExport.CT_Code = ms_CT_Code
  lo_XmlExport.Language_Code = ms_Language_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.SAP_SalesOrderCreate(m_CurrentKey1, False, ls_ErrorMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call ViewInitFields
  ' generate the items into base_item
  ls_warning = ""
  If lb_Result Then
      If mo_A_Config(C_A_CONFIG_DPC_TO_BI_LOCKED) <> "X" Then
          ls_warning = GenerateBase_item(m_CurrentKey1)
      Else
          ls_warning = mo_Tools.MsgText(mo_Db, ms_Language_Code, 9937, "#(Base_Items creation BLOCKED by a_config DCP_TO_BI_LOCKED)!")
      End If
  End If
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Export Sales Order to SAP was successful. $TEXT$", Array("$OPERATION$", btn_ExportSalesOrderCreate.Caption, "$TEXT$", ls_ErrorMsg & ls_warning))
    'Call MsgBox("Export Sales Order to SAP was successful. " & ls_ErrorMsg)
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Export Sales Order to SAP failed: $ERROR$", Array("$OPERATION$", btn_ExportSalesOrderCreate.Caption, "$ERROR$", ls_ErrorMsg & ls_warning))
    'Call MsgBox("Export Sales Order to SAP failed: " & ls_ErrorMsg)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_ExportSalesOrderCreate_Click")
End Sub

Private Sub btn_ExportSalesOrderCreateSim_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrorMsg As String
Dim ls_warning As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

'Dim le_SAP_Sta As eDPCInterfaceStatus
'Dim lc_Cursor As Long
'Dim ll_LinesCount As Long
'Dim lo_XmlExportBae As New DPC_Interface

'  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, "SELECT COF_DeDesc, COF_DeAdr1, COF_DeAdr2, COF_DeTown, COF_DeZip, COF_DeCT FROM Cap_Offer WHERE COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1))
'  If (mo_Db.GetFields(lc_Cursor, "COF_DeDesc") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeAdr1") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeAdr2") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeTown") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeZip") <> "") Or _
'     (mo_Db.GetFields(lc_Cursor, "COF_DeCT") <> "") Then
'
'    If (mo_Db.GetFields(lc_Cursor, "COF_DeDesc") = "") Or _
'       (mo_Db.GetFields(lc_Cursor, "COF_DeAdr1") = "") Or _
'       (mo_Db.GetFields(lc_Cursor, "COF_DeTown") = "") Or _
'       (mo_Db.GetFields(lc_Cursor, "COF_DeZip") = "") Or _
'       (mo_Db.GetFields(lc_Cursor, "COF_DeCT") = "") Then
'      Call MsgBox("Delivery Name, Street, Town and Country is mandatory. (Save any changes before export !)")
'      Call mo_Db.Close(lc_Cursor)
'      Exit Sub
'    End If
'  End If
'  Call mo_Db.Close(lc_Cursor)
'  If mo_Tools.SelectValue(mo_Db, "SELECT CCU.CUST_Code FROM Cap_Offer COF INNER JOIN claim_customer CCU ON (CCU.CCU_CapKey=COF.CCU_CapKey) WHERE COF.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1)) = "" Then
'    Call MsgBox("Customer must be SAP buying customer")
'    Exit Sub
'  End If
'
'  If mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD INNER JOIN DPC_PrdCommon PRD ON (OFD.PRD_Id=PRD.PRD_Id) WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Main=1 AND OFD.OFD_Valid='X' AND (OFD.DOF_Id IN (1,37)) AND (OFD.CAT_Id IN (1,20)) AND PRD.PRD_StaSAP<>1 AND OFD.Drop_Flag=''") > 0 Then
'    Call MsgBox("Not all custom materials inside sales order were successfuly exported to SAP")
'    Exit Sub
'  End If
'
'  If mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Main=1 AND OFD.OFD_Valid='X' AND OFD.DOF_Id=1 AND (OFD.CAT_Id IN (1,21)) AND OFD.OFD_PosB7=0 AND OFD.Drop_Flag=''") > 0 Then
'    Call MsgBox("Not all standard and custom metal materials inside sales order were successfuly send and received from B7 planning box")
'    Exit Sub
'  End If
'
'  If mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Main=1 AND OFD.OFD_Valid='X' AND (OFD.DOF_Id IN (1,37)) AND (OFD.CAT_Id IN (1,15,20,21)) AND OFD.OFD_Price=0 AND OFD.OFD_IsFree='' AND OFD.Drop_Flag=''") > 0 Then
'    Call MsgBox("Price of item is 0, but is not marked as free of charge")
'    Exit Sub
'  End If
'
'  If mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Main=1 AND OFD.OFD_Valid='X' AND OFD.OFD_Price>0 AND OFD.OFD_IsFree='X' AND OFD.Drop_Flag=''") > 0 Then
'    Call MsgBox("Price of item greater than 0, but is marked as free of charge")
'    Exit Sub
'  End If
'
'  ll_LinesCount = mo_Tools.SelectValue(mo_Db, "SELECT COUNT(*) FROM Cap_OfferDetail OFD WHERE OFD.COF_Id =" & mo_Tools.SQLStr(m_CurrentKey1) & " AND OFD.OFD_Valid='X' AND ((OFD.CAT_Id <> 10 AND OFD.OFD_Main=1) OR (OFD.CAT_Id = 10 AND OFD.OFD_Main=2)) AND OFD.Drop_Flag=''")
'  If ll_LinesCount > 166 Then
'    Call MsgBox("Order contain more than 166 lines. Pleas split order into more documents.")
'    Exit Sub
'  End If
'
  Call mo_Tools.LockScreen(Me, True)
  Call LoadSPAConfig
  
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  Set lo_XmlExport.ArmDb = mo_Db
  lo_XmlExport.U_Code = ml_U_Code
  Set lo_XmlExport.Tools = mo_Tools
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.SAP_SalesOrderCreate(m_CurrentKey1, True, ls_ErrorMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  ' generate the items into base_item
  ls_warning = ""
  If mo_A_Config(C_A_CONFIG_DPC_TO_BI_LOCKED) <> "X" Then
      ls_warning = GenerateBase_item_simulate(m_CurrentKey1)
  Else
      ls_warning = mo_Tools.MsgText(mo_Db, ms_Language_Code, 9937, "#(Base_Items creation BLOCKED by a_config DCP_TO_BI_LOCKED)!") & vbCrLf & GenerateBase_item_simulate(m_CurrentKey1)
  End If

  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Sales Order simulate to SAP was successful. $TEXT$", Array("$OPERATION$", btn_ExportSalesOrderCreateSim.Caption, "$TEXT$", ls_ErrorMsg & ls_warning))
    'Call MsgBox("Sales Order simulate to SAP was successful. " & ls_ErrorMsg)
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Export Sales Order simulate to SAP failed: $ERROR$", Array("$OPERATION$", btn_ExportSalesOrderCreateSim.Caption, "$ERROR$", ls_ErrorMsg & ls_warning))
    'Call MsgBox("Sales Order simulate to SAP failed: " & ls_ErrorMsg)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_ExportSalesOrderCreateSim_Click")
End Sub

Private Sub btn_ExportSalesOrderCancelAddReplace_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrorMsg As String
Dim ls_warning As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  Call LoadSPAConfig
  
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  Set lo_XmlExport.ArmDb = mo_Db
  lo_XmlExport.U_Code = ml_U_Code
  Set lo_XmlExport.Tools = mo_Tools
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.SAP_SalesOrderLineCancelAddReplace(m_CurrentKey1, ls_ErrorMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call ViewInitFields
  ' generate the items into base_item
  ls_warning = ""
  If lb_Result Then
      If mo_A_Config(C_A_CONFIG_DPC_TO_BI_LOCKED) <> "X" Then
          ls_warning = GenerateBase_item(m_CurrentKey1)
      Else
          ls_warning = mo_Tools.MsgText(mo_Db, ms_Language_Code, 9937, "#(Base_Items creation BLOCKED by a_config DCP_TO_BI_LOCKED)!")
      End If
  End If

  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Export Sales Order change to SAP was successful. $TEXT$", Array("$OPERATION$", btn_ExportSalesOrderCancelAddReplace.Caption, "$TEXT$", ls_ErrorMsg & ls_warning))
    'Call MsgBox("Export Sales Order change to SAP was successful. " & ls_ErrorMsg)
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Export Sales Order change to SAP failed: $ERROR$", Array("$OPERATION$", btn_ExportSalesOrderCancelAddReplace.Caption, "$ERROR$", ls_ErrorMsg & ls_warning))
    'Call MsgBox("Export Sales Order change to SAP failed: " & ls_ErrorMsg)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_ExportSalesOrderCancelAddReplace_Click")
End Sub

'Private Function OpenXMLFile() As String
'On Error GoTo ErrHandler
'
'Dim lo_dlg As Object
'Dim ls_Filename As String
'
'    Set lo_dlg = CreateObject("MSComDlg.CommonDialog.1")
'
'    lo_dlg.Filter = "XML files (*.XML)|*.XML"
'    lo_dlg.CancelError = False
'    Call lo_dlg.ShowOpen
'    OpenXMLFile = lo_dlg.FileName
'
'    Set lo_dlg = Nothing
'    Exit Function
'ErrHandler:
'    Call ErrorMessage("OpenXMLFile")
'End Function

Private Sub SAPChangeLineAction(ByVal as_Action As String)
On Error GoTo ErrHandler

Dim ls_OFD_Id As String
Dim le_OFD_Main As eDPCOfferDetailMain
Dim le_CAT_Id As eDPCCategory
Dim ls_req As String

  If grd_Offer.SelectedCount <> 1 Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9715, "#Please select one master record")
    Exit Sub
  End If
  
  ls_OFD_Id = grd_Offer.SelectedLine(0, "OFD_Id")
  le_OFD_Main = grd_Offer.SelectedLine(0, "OFD_Main")
  le_CAT_Id = grd_Offer.SelectedLine(0, "CAT_Id")
  If (le_OFD_Main = eDPCOfferDetailMain.odMain) Or ((le_OFD_Main = eDPCOfferDetailMain.odChild) And (le_CAT_Id = eDPCCategory.cgSubconstruction)) Then
    ls_req = "UPDATE Cap_OfferDetail SET OFD_SAPAct=$OFD_SAPAct$ WHERE COF_Id=$COF_Id$ AND OFD_Id=$OFD_Id$"
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_Id$", mo_Tools.SQLStr(ls_OFD_Id), , , vbTextCompare)
    ls_req = Replace(ls_req, "$OFD_SAPAct$", mo_Tools.SQLStr(as_Action), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    Call RefreshOfferDetail
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9715, "#Please select one master record")
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("SAPChangeLineAction")
End Sub

Private Sub btn_ExportActionAdd_Click()
On Error GoTo ErrHandler
  
  Call mo_Tools.LockScreen(Me, True)
  Call SAPChangeLineAction("A")
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ExportActionAdd_Click")
End Sub

Private Sub btn_ExportActionReplace_Click()
On Error GoTo ErrHandler

  Call mo_Tools.LockScreen(Me, True)
  Call SAPChangeLineAction("R")
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ExportActionReplace_Click")
End Sub

Private Sub btn_ExportActionDelete_Click()
On Error GoTo ErrHandler

  Call mo_Tools.LockScreen(Me, True)
  Call SAPChangeLineAction("D")
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ExportActionDelete_Click")
End Sub

Private Sub btn_ExportActionDeleteCancelPrereservation_Click()
On Error GoTo ErrHandler

  Call mo_Tools.LockScreen(Me, True)
  Call SAPChangeLineAction("K")
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ExportActionDeleteCancelPrereservation_Click")
End Sub

Private Sub btn_ExportActionReset_Click()
On Error GoTo ErrHandler

  Call mo_Tools.LockScreen(Me, True)
  Call SAPChangeLineAction("")
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_ExportActionReset_Click")
End Sub


Private Sub grd_PosList_ItemSelected()
On Error GoTo ErrHandler
  
  If btn_PosListEdit.Enabled Then
    Call btn_PosListEdit_Click
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_ItemSelected")
End Sub

Private Sub txt_PosListFilter_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
On Error GoTo ErrHandler
  
  If KeyCode = 13 Then
    Call tbs_PosList_Click
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("txt_PosListFilter_KeyDown")
End Sub

'Private Sub grd_PosList_Click()
'On Error GoTo ErrHandler

'Dim ll_Row As Long
'
'  If mb_InternalInit Then Exit Sub
'  mb_InternalInit = True
'  ll_Row = grd_PosList.Row
'
'  If ll_Row >= 0 And grd_PosList.Col = grd_PosList.Columns("Selected").ColumnIndex Then
'    If StrComp(grd_PosList.Data(ll_Row, "Selected"), "UNCHECK", vbTextCompare) = 0 Then
'      grd_PosList.Data(ll_Row, "Selected") = "CHECK"
'    Else
'      grd_PosList.Data(ll_Row, "Selected") = "UNCHECK"
'    End If
'  End If
'  mb_InternalInit = False
'  Exit Sub
'ErrHandler:
'  Call ErrorMessage("grd_PosList_Click")
'End Sub

Private Sub grd_PosList_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single, ByVal al_Row As Long, ByVal al_Col As Long)
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  
  If al_Row >= 0 And al_Col = grd_PosList.Columns("Selected").ColumnIndex Then
    If StrComp(grd_PosList.Data(al_Row, "Selected"), "UNCHECK", vbTextCompare) = 0 Then
      grd_PosList.Data(al_Row, "Selected") = "CHECK"
    Else
      grd_PosList.Data(al_Row, "Selected") = "UNCHECK"
    End If
  End If
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_MouseDown")
End Sub

Private Sub chk_PosListSelectAll_Click()
On Error GoTo ErrHandler

Dim ll_Idx As Long

  If mb_InternalInit Then Exit Sub
  mb_InternalInit = True
  grd_PosList.Redraw = False
  For ll_Idx = 0 To grd_PosList.Rows - 1
    If chk_PosListSelectAll.Value = vbChecked Then
      grd_PosList.Data(ll_Idx, "Selected") = "CHECK"
    Else
      grd_PosList.Data(ll_Idx, "Selected") = "UNCHECK"
    End If
  Next
  grd_PosList.Redraw = True
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_MouseDown")
End Sub

Private Function ConfirmCheckList(ByVal ao_ErrCol As Collection) As Boolean
On Error GoTo ErrHandler

Dim lo_ErrorMsg As frmDPC_ErrorMsg
  
  ConfirmCheckList = True
  If ao_ErrCol.Count > 0 Then
    Set lo_ErrorMsg = New frmDPC_ErrorMsg
    Load lo_ErrorMsg
    Set lo_ErrorMsg.Tools = mo_Tools
    Set lo_ErrorMsg.ArmDb = mo_Db
    lo_ErrorMsg.Language_Code = ms_Language_Code
    lo_ErrorMsg.U_Code = ml_U_Code
    Set lo_ErrorMsg.ErrCollection = ao_ErrCol
    Call lo_ErrorMsg.Load_A_COM
    
    Call mo_Tools.LockScreen(Me, False)
    Call mo_Tools.ShowModalForm(lo_ErrorMsg)
    Call mo_Tools.LockScreen(Me, True)
    
    If lo_ErrorMsg.Result = False Then
      ConfirmCheckList = False
    End If
    Call lo_ErrorMsg.Unload_A_COM
    Unload lo_ErrorMsg
  End If
  Exit Function
ErrHandler:
  Call ErrorHandler("ConfirmCheckList")
End Function

Private Sub btn_PosListCalcBOMBOR_Click()
On Error GoTo ErrHandler

Dim ls_PRD_Id As String, ls_OFD_Id As String
Dim ls_req As String, ls_Key As String
Dim lo_DPC_Generate As New DPC_Generate
Dim lo_DPC_Product As DPC_Product
Dim lc_Cursor As Long
Dim ll_Idx As Long
Dim lo_PrdCollection As New Collection
Dim lo_ErrCollection As New Collection
Dim lb_inTransaction As Boolean
Dim ld_LoadTime As Date, ld_GenerateTime As Date, ld_StoreTime As Date
Dim ld_Time1 As Date, ld_Time2 As Date

  ld_LoadTime = Now
  lb_inTransaction = False
  mo_Tools.CalcExecutionTime = True
  mo_Db.TransactionTable = "Sifyb2"
  Call mo_Tools.LockScreen(Me, True)
  
  lo_DPC_Generate.CT_Code = CT_Code
  lo_DPC_Generate.CURR_Code = "EUR"
  lo_DPC_Generate.ValidityDate = ValidityDate
  lo_DPC_Generate.Language_Code = ms_Language_Code
  lo_DPC_Generate.U_Code = ml_U_Code
  Set lo_DPC_Generate.ArmDb = mo_Db
  Set lo_DPC_Generate.Tools = mo_Tools
  Call lo_DPC_Generate.Load_A_COM
  
  ls_Key = ""
  For ll_Idx = 0 To grd_PosList.Rows - 1
    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
    If (ls_Key <> "") Then ls_Key = ls_Key & ","
    ls_Key = ls_Key & ls_PRD_Id
  Next
  ls_req = "exec DPC_RectPanel_sel $PRD_Id$,$Language_Code$"
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SQLStr(ls_Key), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  For ll_Idx = 0 To grd_PosList.Rows - 1
    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
    ls_OFD_Id = grd_PosList.Data(ll_Idx, "OFD_Id")
    Set lo_DPC_Product = New DPC_Product
    Set lo_DPC_Product.Tools = mo_Tools
    Set lo_DPC_Product.ArmDb = mo_Db
    lo_DPC_Product.U_Code = ml_U_Code
    lo_DPC_Product.CT_Code = CT_Code
    lo_DPC_Product.CURR_Code = "EUR"
    lo_DPC_Product.ValidityDate = ValidityDate
    lo_DPC_Product.Language_Code = ms_Language_Code
    lo_DPC_Product.COF_Id = m_CurrentKey1
    lo_DPC_Product.OFD_IdPar = ls_OFD_Id
    Call lo_DPC_Product.Load_A_COM
    Call lo_DPC_Product.InitOffer
    Call lo_DPC_Product.Load(ls_PRD_Id, lc_Cursor)
    Call lo_DPC_Product.LoadBOM
    Call lo_DPC_Product.LoadBOR
    Call lo_DPC_Product.LoadOffer(m_CurrentKey1, ls_OFD_Id)
    Call lo_PrdCollection.Add(lo_DPC_Product)
  Next
  Call mo_Db.Close(lc_Cursor)
  ld_LoadTime = Now - ld_LoadTime
  
  ld_GenerateTime = Now
  If lo_DPC_Generate.GenerateBOMandBOR(lo_PrdCollection, lo_ErrCollection) Then
    ld_GenerateTime = Now - ld_GenerateTime
    If ConfirmCheckList(lo_ErrCollection) Then
      ld_StoreTime = Now
      For ll_Idx = lo_PrdCollection.Count To 1 Step -1
        Set lo_DPC_Product = lo_PrdCollection(ll_Idx)
        
        Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "SaveBOMBOR")
        lb_inTransaction = True
        Call RecordUpdateLastUser
        Call lo_DPC_Product.Update
        Call lo_DPC_Product.UpdateCostCalcOffer
        Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "SaveBOMBOR")
        lb_inTransaction = False

      Next
      ld_StoreTime = Now - ld_StoreTime
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#BOM/BOR saved successfuly.", Array("$OPERATION$", btn_PosListCalcBOMBOR.Caption, "$TEXT$", "Time: " & Format(ld_GenerateTime, "hh:mm:ss") & " Store time: " & Format(ld_StoreTime, "hh:mm:ss")))
      'Call MsgBox("BOM/BOR saved successfuly. Load: " & Format(ld_LoadTime, "hh:mm:ss") & "Generate: " & Format(ld_GenerateTime, "hh:mm:ss") & " Save: " & Format(ld_StoreTime, "hh:mm:ss"))
      
      
    End If
  End If
  Call mo_Tools.LogExecutionTime(mo_Db, SCREEN_NAME, "CalculateBOMBOR", m_CurrentKey1, mo_Tools.GetExecutionTime("Sifyb2"), "Sifyb2", ls_Key)
  Call mo_Tools.LogExecutionTime(mo_Db, SCREEN_NAME, "CalculateBOMBOR", m_CurrentKey1, mo_Tools.GetExecutionTime("B7"), "B7", ls_Key)
  
  Call lo_DPC_Generate.Unload_A_COM
  Set lo_DPC_Generate = Nothing
  
  For ll_Idx = lo_PrdCollection.Count To 1 Step -1
    Set lo_DPC_Product = lo_PrdCollection(ll_Idx)
    Call lo_DPC_Product.Unload_A_COM
    Call lo_PrdCollection.Remove(ll_Idx)
    Set lo_DPC_Product = Nothing
  Next
  Set lo_PrdCollection = Nothing
  Call tbs_Header_Click
  Call mo_Tools.LockScreen(Me, False)
  mo_Tools.CalcExecutionTime = False
  Exit Sub
ErrHandler:
  If lb_inTransaction Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "SaveBOMBOR")
  End If
  mo_Tools.CalcExecutionTime = False
  Call ErrorMessage("btn_PosListCalcBOMBOR_Click")
End Sub

Private Sub btn_PosListClearBOMBOR_Click()
On Error GoTo ErrHandler

Dim lo_DPC_Product As DPC_Product
Dim ls_PRD_Id As String, ls_OFD_Id As String
Dim lo_Collection As New Collection
Dim ll_Idx As Long
Dim lb_inTransaction As Boolean

  Call mo_Tools.LockScreen(Me, True)
  lb_inTransaction = False
  For ll_Idx = 0 To grd_PosList.Rows - 1
    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
    ls_OFD_Id = grd_PosList.Data(ll_Idx, "OFD_Id")
    
    Set lo_DPC_Product = New DPC_Product
    Set lo_DPC_Product.Tools = mo_Tools
    Set lo_DPC_Product.ArmDb = mo_Db
    lo_DPC_Product.U_Code = ml_U_Code
    lo_DPC_Product.CT_Code = CT_Code
    lo_DPC_Product.CURR_Code = "EUR"
    lo_DPC_Product.ValidityDate = ValidityDate
    lo_DPC_Product.Language_Code = ms_Language_Code
    lo_DPC_Product.COF_Id = m_CurrentKey1
    lo_DPC_Product.OFD_IdPar = ls_OFD_Id
    Call lo_DPC_Product.Load_A_COM
    Call lo_DPC_Product.InitOffer
    Call lo_DPC_Product.Load(ls_PRD_Id)
    Call lo_DPC_Product.LoadOffer(m_CurrentKey1, ls_OFD_Id)
    Call lo_Collection.Add(lo_DPC_Product)
  Next
  
  Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "DeleteBOMBOR")
  lb_inTransaction = True
  Call RecordUpdateLastUser
  For Each lo_DPC_Product In lo_Collection
    Call lo_DPC_Product.ResetOfferCost
    Call lo_DPC_Product.DeleteBOMBOR
    Call lo_DPC_Product.UpdateCostCalcOffer
    ' update status BOM/BOR
  Next
  Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "DeleteBOMBOR")
  lb_inTransaction = False
  
  For ll_Idx = lo_Collection.Count To 1 Step -1
    Set lo_DPC_Product = lo_Collection(ll_Idx)
    Call lo_DPC_Product.Unload_A_COM
    Call lo_Collection.Remove(ll_Idx)
    Set lo_DPC_Product = Nothing
  Next
  Set lo_Collection = Nothing
  Call tbs_Header_Click
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Clear BOM/BOR successful", Array("$OPERATION$", btn_PosListClearBOMBOR.Caption, "$TEXT$", ""))
  'Call MsgBox("Clear BOM/BOR successful")
  Exit Sub
ErrHandler:
  If lb_inTransaction Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "DeleteBOMBOR")
  End If
  Call ErrorMessage("btn_PosListClearBOMBOR_Click")
End Sub

Private Sub btn_GenerateGroupAndCE_Click()
On Error GoTo ErrHandler

Dim lo_DPC_Product As New DPC_Product
Dim lo_XmlExport As New DPC_Interface
Dim ls_PRD_Id As String
Dim ls_OFD_Id As String
Dim ll_OFD_Type As Long
Dim ll_OFD_Main As Long
Dim ll_Idx As Long
Dim ls_ErrMessage As String
Dim lb_ExportOK As Boolean
Dim ll_Count As Long
Dim lb_inTransaction As Boolean
Dim lo_ErrCollection As New Collection

  Call mo_Tools.LockScreen(Me, True)
  lb_ExportOK = True
  ls_ErrMessage = ""
  ll_Count = 0
  For ll_Idx = 0 To grd_PosList.Rows - 1
    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
    ll_OFD_Type = grd_PosList.Data(ll_Idx, "OFD_Type")
    ll_OFD_Main = grd_PosList.Data(ll_Idx, "OFD_Main")
    ls_OFD_Id = grd_PosList.Data(ll_Idx, "OFD_Id")
    Call mo_Tools.ClearCollection(lo_ErrCollection)
    
    Set lo_DPC_Product.Tools = mo_Tools
    Set lo_DPC_Product.ArmDb = mo_Db
    lo_DPC_Product.U_Code = ml_U_Code
    lo_DPC_Product.CT_Code = CT_Code
    lo_DPC_Product.CURR_Code = "EUR"
    lo_DPC_Product.ValidityDate = ValidityDate
    lo_DPC_Product.Language_Code = ms_Language_Code
    Call lo_DPC_Product.Load_A_COM
    Call lo_DPC_Product.InitOffer
    Call lo_DPC_Product.Load(ls_PRD_Id)
    Call lo_DPC_Product.LoadOffer(m_CurrentKey1, ls_OFD_Id)
    Call lo_DPC_Product.LoadBOM
    Call lo_DPC_Product.LoadBOR
    Call lo_DPC_Product.CalculateGroup(lo_ErrCollection)
    Call lo_DPC_Product.CalculateWeightPoints(lo_ErrCollection)
    Call lo_DPC_Product.CalculateCEValues(lo_ErrCollection)
    If ConfirmCheckList(lo_ErrCollection) Then
      Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateGroupAndCE")
      lb_inTransaction = True
      Call RecordUpdateLastUser
      Call lo_DPC_Product.UpdatePrdRectPanel
      Call lo_DPC_Product.UpdatePrdCE
      Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateGroupAndCE")
      lb_inTransaction = False
      ll_Count = ll_Count + 1
    End If
    Call lo_DPC_Product.Unload_A_COM
  Next
  Call mo_Tools.LockScreen(Me, False)
  If lb_ExportOK Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Recalculate succeeded for $TEXT$", Array("$OPERATION$", btn_GenerateGroupAndCE.Caption, "$TEXT$", "Count: (" & ll_Count & ")"))
    'Call MsgBox("Recalculate succeeded for " & ll_Count & " articles")
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Recalculate failed for products: $ERROR$", Array("$OPERATION$", btn_GenerateGroupAndCE.Caption, "$ERROR$", ls_ErrMessage))
    'Call MsgBox("Recalculate failed for products: " & ls_ErrMessage)
  End If
  Exit Sub
ErrHandler:
  If lb_inTransaction Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateGroupAndCE")
  End If
  Call ErrorMessage("btn_GenerateGroupAndCE_Click")
End Sub

Private Sub cmd_ExportRawMaterial_Click()
On Error GoTo ErrHandler

Dim lo_frmDPC_ExportRawMat As frmDPC_ExportRawMat

  Call mo_Tools.LockScreen(Me, True)
  Set lo_frmDPC_ExportRawMat = New frmDPC_ExportRawMat
  Load lo_frmDPC_ExportRawMat
  Set lo_frmDPC_ExportRawMat.Tools = mo_Tools
  Set lo_frmDPC_ExportRawMat.ArmDb = mo_Db
  lo_frmDPC_ExportRawMat.Language_Code = ms_Language_Code
  lo_frmDPC_ExportRawMat.U_Code = ml_U_Code
  Call lo_frmDPC_ExportRawMat.Load_A_COM
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_frmDPC_ExportRawMat)
  Call mo_Tools.LockScreen(Me, True)
    
  Call lo_frmDPC_ExportRawMat.Unload_A_COM
  Unload lo_frmDPC_ExportRawMat
  Set lo_frmDPC_ExportRawMat = Nothing
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cmd_ExportRawMaterial_Click")
End Sub

Private Sub cmd_RecalcCost_Click()
On Error GoTo ErrHandler

Dim lo_DPC_Product As New DPC_Product
Dim lo_XmlExport As New DPC_Interface
Dim ls_PRD_Id As String
Dim ls_OFD_Id As String
Dim ll_OFD_Type As Long
Dim ll_OFD_Main As Long
Dim ll_Idx As Long
Dim ls_req As String
Dim ls_ErrMessage As String
Dim lb_ExportOK As Boolean
Dim ll_Count As Long
Dim lb_inTransaction As Boolean
Dim lb_GenerateOfferDetail As Boolean
Dim lo_Collection As Collection

  Call mo_Tools.LockScreen(Me, True)
  lb_ExportOK = True
  ls_ErrMessage = ""
  ll_Count = 0
  For ll_Idx = 0 To grd_PosList.Rows - 1
    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
    ll_OFD_Type = grd_PosList.Data(ll_Idx, "OFD_Type")
    ll_OFD_Main = grd_PosList.Data(ll_Idx, "OFD_Main")
    ls_OFD_Id = grd_PosList.Data(ll_Idx, "OFD_Id")
    
    Set lo_DPC_Product.Tools = mo_Tools
    Set lo_DPC_Product.ArmDb = mo_Db
    lo_DPC_Product.U_Code = ml_U_Code
    lo_DPC_Product.CT_Code = CT_Code
    lo_DPC_Product.CURR_Code = "EUR"
    lo_DPC_Product.ValidityDate = ValidityDate
    lo_DPC_Product.Language_Code = ms_Language_Code
    Call lo_DPC_Product.Load_A_COM
    Call lo_DPC_Product.InitOffer
    Call lo_DPC_Product.Load(ls_PRD_Id)
    Call lo_DPC_Product.LoadOffer(m_CurrentKey1, ls_OFD_Id)
    Call lo_DPC_Product.LoadBOM
    Call lo_DPC_Product.LoadBOR
    lb_GenerateOfferDetail = False
    If (Not lo_DPC_Product.HasBOM) And (Not lo_DPC_Product.HasBOR) Then
      Call lo_DPC_Product.RefreshPriceWithCheck(False)
      lb_GenerateOfferDetail = True
    ElseIf lo_DPC_Product.HasBOMError Or (Not lo_DPC_Product.HasBOM) Or lo_DPC_Product.HasBORError Or (Not lo_DPC_Product.HasBOR) Then
      Call lo_DPC_Product.InitCostParameters
      Call lo_DPC_Product.InitCostCalc
      Call lo_DPC_Product.ResetOfferCost
      lb_GenerateOfferDetail = False
    Else
      Call lo_DPC_Product.InitCostParameters
      Call lo_DPC_Product.InitCostCalc
      Call lo_DPC_Product.CalculateCost
      lb_GenerateOfferDetail = False
    End If
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateCost")
    lb_inTransaction = True
    If lb_GenerateOfferDetail Then
      Set lo_Collection = lo_DPC_Product.GenerateOfferDetail
      If Not (lo_Collection Is Nothing) Then
        Call SaveOfferDetail(lo_Collection, ls_OFD_Id, COF_DocDat, CURR_Code, Status)
        Call mo_Tools.ClearCollection(lo_Collection)
        Set lo_Collection = Nothing
      End If
    Else
      Call RecordUpdateLastUser
      Call lo_DPC_Product.Update
      Call lo_DPC_Product.UpdateCostCalcOffer
    End If
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateCost")
    lb_inTransaction = False
    ll_Count = ll_Count + 1
    Call lo_DPC_Product.Unload_A_COM
  Next
  Call mo_Tools.LockScreen(Me, False)
  If lb_ExportOK Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Recalculate succeeded for $TEXT$", Array("$OPERATION$", cmd_RecalcCost.Caption, "$TEXT$", "Count: (" & ll_Count & ")"))
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Recalculate failed for products: $ERROR$", Array("$OPERATION$", cmd_RecalcCost.Caption, "$ERROR$", ls_ErrMessage))
  End If
  Exit Sub
ErrHandler:
  If lb_inTransaction Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateCost")
  End If
  Call ErrorMessage("cmd_RecalcCost_Click")
End Sub

Private Sub btn_RecalcPacking_Click()
On Error GoTo ErrHandler

Dim lo_DPC_Product As New DPC_Product
Dim ls_PRD_Id As String
Dim ls_OFD_Id As String
Dim ll_Idx As Long
Dim ls_ErrMessage As String
Dim lb_ExportOK As Boolean
Dim ll_Count As Long
Dim lb_inTransaction As Boolean
Dim lo_DPC_Generate As New DPC_Generate
Dim lo_Collection As New Collection
Dim lo_ErrCollection As New Collection

  Call mo_Tools.LockScreen(Me, True)
  lo_DPC_Generate.CT_Code = CT_Code
  lo_DPC_Generate.CURR_Code = "EUR"
  lo_DPC_Generate.ValidityDate = ValidityDate
  lo_DPC_Generate.Language_Code = ms_Language_Code
  lo_DPC_Generate.U_Code = ml_U_Code
  Set lo_DPC_Generate.ArmDb = mo_Db
  Set lo_DPC_Generate.Tools = mo_Tools
  Call lo_DPC_Generate.Load_A_COM
  
  lb_ExportOK = True
  ls_ErrMessage = ""
  ll_Count = 0
  For ll_Idx = 0 To grd_PosList.Rows - 1
    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
    ls_OFD_Id = grd_PosList.Data(ll_Idx, "OFD_Id")
    
    Set lo_DPC_Product.Tools = mo_Tools
    Set lo_DPC_Product.ArmDb = mo_Db
    lo_DPC_Product.U_Code = ml_U_Code
    lo_DPC_Product.CT_Code = CT_Code
    lo_DPC_Product.CURR_Code = "EUR"
    lo_DPC_Product.ValidityDate = ValidityDate
    lo_DPC_Product.Language_Code = ms_Language_Code
    lo_DPC_Product.COF_Id = m_CurrentKey1
    lo_DPC_Product.OFD_IdPar = ls_OFD_Id
    Call lo_DPC_Product.Load_A_COM
    Call lo_DPC_Product.InitOffer
    Call lo_DPC_Product.Load(ls_PRD_Id)
    Call lo_DPC_Product.LoadBOM
    Call lo_DPC_Product.LoadBOR
    Call lo_DPC_Product.LoadOffer(m_CurrentKey1, ls_OFD_Id)
    
    If lo_DPC_Product.HasBOMError Or (Not lo_DPC_Product.HasBOM) Or lo_DPC_Product.HasBORError Or (Not lo_DPC_Product.HasBOR) Then
      Call MsgBox("You cannot recalculate article " & lo_DPC_Product.PRD_Code & " which has empty or error BOM/BOR")
      lb_ExportOK = False
      ls_ErrMessage = ls_ErrMessage & " " & lo_DPC_Product.PRD_Code
    Else
      Call lo_Collection.Add(lo_DPC_Product)
      
      'Call lo_DPC_Product.DeletePackingCalculation
      Call lo_DPC_Generate.GeneratePrdPacking(lo_Collection, lo_ErrCollection)
      If ConfirmCheckList(lo_ErrCollection) Then
        Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculatePacking")
        lb_inTransaction = True
        Call RecordUpdateLastUser
        Call lo_DPC_Product.SavePrdPacking
        Call lo_DPC_Product.UpdatePrdRectPanel
        Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculatePacking")
        lb_inTransaction = False
        ll_Count = ll_Count + 1
      Else
        ls_ErrMessage = ls_ErrMessage & " " & lo_DPC_Product.PRD_Code
        lb_ExportOK = False
      End If
      
    End If
    
    Call mo_Tools.ClearCollection(lo_Collection)
    Call mo_Tools.ClearCollection(lo_ErrCollection)
    Call lo_DPC_Product.Unload_A_COM
  Next
  
  
  Call lo_DPC_Generate.Unload_A_COM
  Set lo_DPC_Generate = Nothing
  Set lo_DPC_Product = Nothing
  Set lo_Collection = Nothing
  Set lo_ErrCollection = Nothing
  
  Call mo_Tools.LockScreen(Me, False)
  If lb_ExportOK Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Recalculate succeeded for $TEXT$", Array("$OPERATION$", btn_RecalcPacking.Caption, "$TEXT$", "Count: (" & ll_Count & ")"))
    'Call MsgBox("Recalculate succeeded for " & ll_Count & " articles")
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Recalculate failed for products: $ERROR$", Array("$OPERATION$", btn_RecalcPacking.Caption, "$ERROR$", ls_ErrMessage))
    'Call MsgBox("Recalculate failed for products: " & ls_ErrMessage)
  End If
  Exit Sub
ErrHandler:
  If lb_inTransaction Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculatePacking")
  End If
  Call ErrorMessage("btn_RecalcPacking_Click")
End Sub

'Private Sub btn_BaurerSalesOrderChangeExport_Click()
'On Error GoTo ErrHandler
'
'Dim lo_XmlExport2 As New DPC_SAP
'Dim ls_ErrorMsg As String
'
'  Set lo_XmlExport2.ArmDb = mo_Db
'  lo_XmlExport2.U_Code = ml_U_Code
'  Call lo_XmlExport2.Load_A_COM
'  Call lo_XmlExport2.SalesOrderLineCancelAddReplace_v2(m_CurrentKey1, ls_ErrorMsg)
'  If (Len(ls_ErrorMsg) > 0) Then
'      MsgBox (ls_ErrorMsg)
'  End If
'  Exit Sub
'ErrHandler:
'  Call ErrorMessage("btn_BaurerSalesOrderChangeExport")
'End Sub

Private Sub btn_PosListEdit_Click()
On Error GoTo ErrHandler

  If Not ((mi_DisplayMode = mt_CstValues.DisplayMode_Add) Or (mi_DisplayMode = mt_CstValues.DisplayMode_Update)) Then Exit Sub
  If Not CanUpdateSubitem Then Exit Sub
  
  If grd_PosList.SelectedCount <> 1 Then Exit Sub
  
  Call mo_Tools.LockScreen(Me, True)
  
  Call mo_OfferPos.Load(mo_Db, m_CurrentKey1, grd_PosList.SelectedLine(0, "OFD_Id"), ms_Language_Code)
  If ItemConfigSpc(eDPCScreenMode.smUpdate, mo_OfferPos) Then
    Call RefreshPosList
    If grd_PosList.Rows > 0 Then
      grd_PosList.Row = grd_PosList.Rows - 1
    End If
  End If
  
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_PosListEdit_Click")
End Sub

Private Sub btn_ChangeAttribute_Click()
On Error GoTo ErrHandler

Dim ls_PRD_Id As String, ls_OFD_Id As String, ls_RPL_DrwNr As String
Dim ll_Idx As Long, ll_LEV_Id As Long, ll_Count As Long
Dim ls_req As String
Dim ls_ReqUpd As String
Dim lo_DPC_Value As frmDPC_Value
Dim lo_DPC_Product As DPC_Product
Dim lo_Collection As Collection
Dim lb_InTran As Boolean

  lb_InTran = False
  If Not ((mi_DisplayMode = mt_CstValues.DisplayMode_Add) Or (mi_DisplayMode = mt_CstValues.DisplayMode_Update)) Then Exit Sub
  If Not CanUpdateSubitem Then Exit Sub
  
  ll_Count = 0
  For ll_Idx = 0 To grd_PosList.Rows - 1
    If StrComp(grd_PosList.Data(ll_Idx, "Selected"), "CHECK", vbTextCompare) = 0 Then
      ll_Count = ll_Count + 1
    End If
  Next
  If ll_Count = 0 Then Exit Sub
  
  Call mo_Tools.LockScreen(Me, True)
  
  Set lo_DPC_Value = New frmDPC_Value
  Load lo_DPC_Value
  Set lo_DPC_Value.Tools = mo_Tools
  Set lo_DPC_Value.ArmDb = mo_Db
  lo_DPC_Value.Language_Code = ms_Language_Code
  lo_DPC_Value.U_Code = ml_U_Code
  Call lo_DPC_Value.Load_A_COM
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_DPC_Value)
  Call mo_Tools.LockScreen(Me, True)
    
  If lo_DPC_Value.Result Then
  
    For ll_Idx = 0 To grd_PosList.Rows - 1
      If StrComp(grd_PosList.Data(ll_Idx, "Selected"), "CHECK", vbTextCompare) = 0 Then
      
      
        ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
        ls_OFD_Id = grd_PosList.Data(ll_Idx, "OFD_Id")
        ll_LEV_Id = Val(right(grd_PosList.Data(ll_Idx, "LEV_IdBMP"), 1))
        
        Set lo_DPC_Product = New DPC_Product
        Set lo_DPC_Product.Tools = mo_Tools
        Set lo_DPC_Product.ArmDb = mo_Db
        lo_DPC_Product.COF_Id = m_CurrentKey1
        lo_DPC_Product.U_Code = ml_U_Code
        lo_DPC_Product.CT_Code = CT_Code
        lo_DPC_Product.CURR_Code = "EUR"
        lo_DPC_Product.ValidityDate = ValidityDate
        lo_DPC_Product.Language_Code = ms_Language_Code
        Call lo_DPC_Product.Load_A_COM
        Call lo_DPC_Product.InitOffer
        Call lo_DPC_Product.Load(ls_PRD_Id)
        Call lo_DPC_Product.LoadOffer(m_CurrentKey1, ls_OFD_Id)
        
        Call lo_DPC_Product.SetAttribute(lo_DPC_Value.AttributeName, lo_DPC_Value.AttributeValue)
        
        Set lo_Collection = lo_DPC_Product.GenerateOfferDetail

        Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeAttributes")
        lb_InTran = True
        
        If (ll_LEV_Id > eDPCLevel.lvStandard) Then
          Call lo_DPC_Product.Update
        End If
       
        If Not (lo_Collection Is Nothing) Then
          Call SaveOfferDetail(lo_Collection, ls_OFD_Id, COF_DocDat, CURR_Code, Status)
          Call mo_Tools.ClearCollection(lo_Collection)
          Set lo_Collection = Nothing
        End If
        Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeAttributes")
        lb_InTran = False
        
        Call lo_DPC_Product.Unload_A_COM
        Set lo_DPC_Product = Nothing
        
        'If (InStr(1, lo_DPC_Value.AttributeTable, "Cap_OfferDetail", vbTextCompare) > 0) Then
        '  Call lo_OfferPos.Update(mo_Db, ml_U_Code)
        'End If
        'Set lo_OfferPos = Nothing
        'ls_ReqUpd = Replace(ls_Req, "$PRD_Id$", mo_Tools.SQLStr(ls_PRD_Id), , , vbTextCompare)
        'Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_ReqUpd)
      End If
    Next
    Call RefreshPosList
  End If
  Call lo_DPC_Value.Unload_A_COM
  Unload lo_DPC_Value
  Set lo_DPC_Value = Nothing
  
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeAttributes")
  End If
  Call ErrorMessage("btn_ChangeDrawNr_Click")
End Sub


'Private Sub btn_ChangeDrawNr_Click()
'On Error GoTo ErrHandler
'
'Dim ls_PRD_Id As String, ls_RPL_DrwNr As String
'Dim ll_Idx As Long, ll_LEV_Id As Long, ll_Count As Long
'Dim ls_req As String
'
'
'  ls_RPL_DrwNr = Left(InputBox(mo_Tools.MsgText(mo_Db, ms_Language_Code, 666, "#Enter Drawing number"), prg.ApplicationName & prg.ApplicationVersion, ""), 30)
'  If Trim(ls_RPL_DrwNr) = "" Then Exit Sub
'
'  Call mo_Tools.LockScreen(Me, True)
'
'  For ll_Idx = 0 To grd_PosList.Rows - 1
'    If StrComp(grd_PosList.Data(ll_Idx, "Selected"), "CHECK", vbTextCompare) = 0 Then
'      ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
'      ll_LEV_Id = Val(right(grd_PosList.Data(ll_Idx, "LEV_IdBMP"), 1))
'      If ll_LEV_Id > eDPCLevel.lvStandard Then
'        ls_req = "exec DPC_RectPanel_upd3 $PRD_Id$, $RPL_DrwNr$, $Z_Last_Upd_User$"
'        ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SQLStr(ls_PRD_Id), , , vbTextCompare)
'        ls_req = Replace(ls_req, "$RPL_DrwNr$", mo_Tools.SQLStr(ls_RPL_DrwNr), , , vbTextCompare)
'        ls_req = ReplaceCommonPlaceholders(ls_req)
'        Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
'      End If
'    End If
'  Next
'  Call RefreshPosList
'  Call mo_Tools.LockScreen(Me, False)
'  Exit Sub
'ErrHandler:
'  Call ErrorMessage("btn_ChangeDrawNr_Click")
'End Sub


'Dim lo_XmlExport As New DPC_Interface
'
'
'  Set lo_XmlExport.ArmDb = mo_Db
'  Set lo_XmlExport.Tools = mo_Tools
'  lo_XmlExport.U_Code = ml_U_Code
'  Call lo_XmlExport.Load_A_COM
'  Call lo_XmlExport.SaveXml
'  Call lo_XmlExport.Unload_A_COM

Private Sub cmd_Info_Click()
On Error GoTo ErrHandler

Dim lo_Info As frmInfo

  Set lo_Info = New frmInfo
  Load lo_Info
  lo_Info.LoginName = ms_LoginName
  Call lo_Info.CreateInfo
  Call mo_Tools.ShowModalForm(lo_Info)
  Unload lo_Info
  Set lo_Info = Nothing
  Exit Sub
ErrHandler:
  Call ErrorMessage("cmd_Info_Click")
End Sub


Private Sub btn_XmlPMaster_Click()
On Error GoTo ErrHandler

'Dim lo_DPC_Product As New DPC_Product
Dim lo_XmlExport As New DPC_Interface
Dim ll_Idx As Long
Dim ls_req As String
Dim ls_ErrMessage As String
Dim lb_Result As Boolean
Dim lo_Collection As New Collection
Dim ls_PRD_Id As String
Dim ll_LEV_Id As Long
Dim lb_OfferLocked As Boolean
Dim ld_ExportTime As Date

  ld_ExportTime = Now
  'Screen.MousePointer = vbHourglass
  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  ls_ErrMessage = ""
  For ll_Idx = 0 To grd_PosList.Rows - 1
    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
    ll_LEV_Id = Val(right(grd_PosList.Data(ll_Idx, "LEV_IdBMP"), 1))
    If ll_LEV_Id > eDPCLevel.lvStandard Then
      Call lo_Collection.Add(ls_PRD_Id)
    End If
  Next
  
  If lo_Collection.Count <= 0 Then
    Call ReleaseOfferLock(m_CurrentKey1)
    lb_OfferLocked = False
    Call mo_Tools.LockScreen(Me, False)
    Call MsgBox("There are no articles to export")
    Exit Sub
  End If
  
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.U_Code = ml_U_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.Bae_ExportArticleCollection(lo_Collection, ls_ErrMessage)
  Call lo_XmlExport.Unload_A_COM
  
'  For ll_Idx = 0 To grd_PosList.Rows - 1
'    ls_PRD_Id = grd_PosList.Data(ll_Idx, "PRD_Id")
'
'    Set lo_DPC_Product.Tools = mo_Tools
'    Set lo_DPC_Product.ArmDb = mo_Db
'    lo_DPC_Product.U_Code = ml_U_Code
'    lo_DPC_Product.CT_Code = CT_Code
'    lo_DPC_Product.CURR_Code = "EUR"
'    lo_DPC_Product.ValidityDate = ValidityDate
'    lo_DPC_Product.Language_Code = ms_Language_Code
'    Call lo_DPC_Product.Load_A_COM
'    Call lo_DPC_Product.Load(ls_PRD_Id)
'    Call lo_DPC_Product.LoadBOM
'    Call lo_DPC_Product.LoadBOR
'    If lo_DPC_Product.HasBOMError Or (Not lo_DPC_Product.HasBOM) Then
'      Call MsgBox("You cannot export article " & lo_DPC_Product.PRD_Code & " which has empty or error BOM")
'      ls_PRD_Id = ""
'    End If
'    If lo_DPC_Product.HasBORError Or (Not lo_DPC_Product.HasBOR) Then
'      Call MsgBox("You cannot export article " & lo_DPC_Product.PRD_Code & " which has empty or error BOR")
'      ls_PRD_Id = ""
'    End If
'    Call lo_DPC_Product.Unload_A_COM
'
'    If ls_PRD_Id <> "" Then
'      If lo_XmlExport.Bae_ExportArticle(lo_DPC_Product) > 0 Then
'        ll_Count = ll_Count + 1
'      Else
'        lb_ExportOK = False
'        ls_ErrMessage = ls_ErrMessage & " " & lo_DPC_Product.PRD_Code
'      End If
'    End If
'  Next
  
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  ld_ExportTime = Now - ld_ExportTime
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Export PMaster to B7 succeeded $TEXT$", Array("$OPERATION$", btn_XmlPMaster.Caption, "$TEXT$", " Count: (" & lo_Collection.Count & ") Time: " & Format(ld_ExportTime, "hh:mm:ss")))
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Export PMaster to B7 failed: $ERROR$", Array("$OPERATION$", btn_XmlPMaster.Caption, "$ERROR$", ls_ErrMessage))
    'Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "Export PMaster to B7 failed: $ERROR$", Array("$OPERATION$", btn_XmlPMaster.Caption, "$ERROR$", ls_ErrMessage))
  End If
  Call mo_Tools.ClearCollection(lo_Collection)
  Set lo_Collection = Nothing
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_XmlPMaster_Click")
End Sub

Private Sub btn_XmlCust_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As New DPC_Interface
Dim ls_CCU_Capkey As String
Dim lb_Result As Boolean
Dim ls_ErrorMsg As String
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  lb_Result = False
  ls_CCU_Capkey = GetCodeFromCombo(cbo_Customer)
  If ls_CCU_Capkey <> "" Then
    Set lo_XmlExport.ArmDb = mo_Db
    Set lo_XmlExport.Tools = mo_Tools
    lo_XmlExport.Language_Code = ms_Language_Code
    lo_XmlExport.CT_Code = ms_CT_Code
    lo_XmlExport.U_Code = ml_U_Code
    Call lo_XmlExport.Load_A_COM
    lb_Result = lo_XmlExport.Bae_ExportCustomer(cbo_Customer.SelectedItem.Key, ls_ErrorMsg)
    Call lo_XmlExport.Unload_A_COM
  End If
  
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Customer exported successfuly. $TEXT$", Array("$OPERATION$", btn_XmlCust.Caption, "$TEXT$", ""))
    'Call MsgBox("Customer exported successfuly")
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Customer export failed: $ERROR$", Array("$OPERATION$", btn_XmlCust.Caption, "$ERROR$", ls_ErrorMsg))
    'Call MsgBox("Customer export failed: " & ls_ErrorMsg)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_XmlCust_Click")
End Sub

Private Sub btn_BaurerSecretBoxExport_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrMessage As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  lb_Result = False
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.Language_Code = ms_Language_Code
  lo_XmlExport.CT_Code = ms_CT_Code
  lo_XmlExport.U_Code = ml_U_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.Bae_ExportSecretBox(m_CurrentKey1, ls_ErrMessage)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Export to planning box successful. $TEXT$", Array("$OPERATION$", btn_BaurerSecretBoxExport.Caption, "$TEXT$", ""))
    'Call MsgBox("Export to planning box successful")
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Export to planning box failed: $ERROR$", Array("$OPERATION$", btn_BaurerSecretBoxExport.Caption, "$ERROR$", ls_ErrMessage))
    'Call MsgBox("Export to planning box failed: " & ls_ErrMessage)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_BaurerSecretBoxExport_Click")
End Sub

Private Sub btn_BaurerSecretBoxImport_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrMsg As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  lb_Result = False
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.Language_Code = ms_Language_Code
  lo_XmlExport.CT_Code = ms_CT_Code
  lo_XmlExport.U_Code = ml_U_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.Bae_ImportSecretBox(m_CurrentKey1, ls_ErrMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call RefreshOfferDetail
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Import from planning box successful. $TEXT$", Array("$OPERATION$", btn_BaurerSecretBoxImport.Caption, "$TEXT$", ""))
    'Call MsgBox("Import from planning box successful")
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Ixport from planning box failed: $ERROR$", Array("$OPERATION$", btn_BaurerSecretBoxImport.Caption, "$ERROR$", ls_ErrMsg))
    'Call MsgBox("Import from planning box failed: " & ls_ErrMsg)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_BaurerSecretBoxImport_Click")
End Sub

Private Sub btn_BaurerSecretBoxKill_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As New DPC_Interface
Dim ls_COF_Code As String
Dim ls_ErrMsg As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  lb_Result = False
  ls_COF_Code = txt_COF_Code.Text
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.Language_Code = ms_Language_Code
  lo_XmlExport.CT_Code = ms_CT_Code
  lo_XmlExport.U_Code = ml_U_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.Bae_KillSecretBox(m_CurrentKey1, ls_ErrMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call RefreshOfferDetail
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If lb_Result Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Delete from planning box successful. $TEXT$", Array("$OPERATION$", btn_BaurerSecretBoxKill.Caption, "$TEXT$", ""))
    'Call MsgBox("Delete from planning box successful")
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Delete from planning box failed: $ERROR$", Array("$OPERATION$", btn_BaurerSecretBoxKill.Caption, "$ERROR$", ls_ErrMsg))
    'Call MsgBox("Delete from planning box failed: " & ls_ErrMsg)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_BaurerSecretBoxKill_Click")
End Sub

Private Sub btn_BaurerSalesOrderExport_Click()
On Error GoTo ErrHandler
    
Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrorMsg As String
Dim ls_warning As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  Call LoadSPAConfig
  
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  lb_Result = False
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.Language_Code = ms_Language_Code
  lo_XmlExport.CT_Code = ms_CT_Code
  lo_XmlExport.U_Code = ml_U_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.Bae_SalesOrderExport(m_CurrentKey1, ls_ErrorMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call ViewInitFields
  ' generate the items into base_item
  ls_warning = ""
  If lb_Result Then
      If mo_A_Config(C_A_CONFIG_DPC_TO_BI_LOCKED) <> "X" Then
          ls_warning = GenerateBase_item(m_CurrentKey1)
      Else
          ls_warning = mo_Tools.MsgText(mo_Db, ms_Language_Code, 9937, "#(Base_Items creation BLOCKED by a_config DCP_TO_BI_LOCKED)!")
      End If
  End If
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  
  Call mo_Tools.LockScreen(Me, False)
  
  If (Not lb_Result) Or (Len(ls_ErrorMsg) > 0) Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Sales order export failed: $ERROR$", Array("$OPERATION$", btn_BaurerSalesOrderExport.Caption, "$ERROR$", ls_ErrorMsg & ls_warning))
    'Call MsgBox("Sales order export failed: " & ls_ErrorMsg & ls_warning)
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Sales order exported successfuly. $TEXT$", Array("$OPERATION$", btn_BaurerSalesOrderExport.Caption, "$TEXT$", ls_warning))
    'Call MsgBox("Sales order exported successfuly." & ls_warning)
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_BaurerSalesOrderExport")
End Sub

Private Function GenerateBase_item_simulate(ByVal as_COF_Id As String) As String
On Error GoTo ErrHandler
    Dim ls_warning As String
    Dim ll_items_count As Long
    GenerateBase_item_simulate = ""

Const C_REQ As String = "EXEC DPCItemTOBI_lst '$COF_ID$'"

    Dim ls_req As String
    Dim ll_Cursor As Long
    ls_req = Replace(C_REQ, "$COF_ID$", as_COF_Id, , , vbTextCompare)
    
    ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    
    ll_items_count = 0
    
    ls_warning = vbCrLf
    
    While Not mo_Db.EOF(ll_Cursor)
        If CreateBaseItem_simulate(ll_Cursor, ls_warning) Then
            ll_items_count = ll_items_count + 1
        Else
            ls_warning = ls_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9905, "#Failed to simulate creation of item $PRD_Code$!" & vbCrLf, Array("$PRD_Code$", mo_Db.GetFields(ll_Cursor, "PRD_Code")))
        End If
        Call mo_Db.Next(ll_Cursor)
    Wend
    
    Call mo_Db.Close(ll_Cursor)
    ll_Cursor = 0
    
    If ll_items_count > 0 Then
        ls_warning = ls_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9906, "#Base Items to be created: $COUNT$!", Array("$COUNT$", ll_items_count))
    Else
        ls_warning = ls_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9907, "#No Base Item to be created.")
    End If
    
    GenerateBase_item_simulate = ls_warning
    Exit Function
ErrHandler:
    If ll_Cursor <> 0 Then
        Call mo_Db.Close(ll_Cursor)
        ll_Cursor = 0
    End If
    Call ErrorHandler("GenerateBase_item_simulate")
End Function

Private Function CreateBaseItem_simulate(ByVal al_Cursor As Long, ByRef as_warning As String) As Boolean
On Error GoTo ErrHandler
    CreateBaseItem_simulate = True
    
    ' get SMB_Code and BM_Code from BML_Code
    Dim ll_Cursor As Long
    
    ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, "SELECT SBM_CODE, BM_CODE FROM Base_Material_Link WHERE Language_code='E' AND CG_Code='" & mo_Db.GetFields(al_Cursor, "CG_Code") & "' AND BML_Code='" & mo_Db.GetFields(al_Cursor, "BML_Code") & "'")
    Dim ls_SBM_Code As String
    Dim ls_BM_Code As String
    
    ls_SBM_Code = mo_Db.GetFields(ll_Cursor, "SBM_Code")
    ls_BM_Code = mo_Db.GetFields(ll_Cursor, "BM_Code")
    
    Call mo_Db.Close(ll_Cursor)
    ll_Cursor = 0
    
    ' height not relevant for categories C001 and C006 - check in Base_Item_ins
    Dim ld_Height As Double
    ld_Height = mo_Db.GetFields(al_Cursor, "RPL_HD")
    If ld_Height < mo_Db.GetFields(al_Cursor, "RPL_HC") Then ld_Height = mo_Db.GetFields(al_Cursor, "RPL_HC")
    If ld_Height < mo_Db.GetFields(al_Cursor, "RPL_HE") Then ld_Height = mo_Db.GetFields(al_Cursor, "RPL_HE")
    If ld_Height < mo_Db.GetFields(al_Cursor, "RPL_HF") Then ld_Height = mo_Db.GetFields(al_Cursor, "RPL_HF")
    
    If Trim(mo_Db.GetFields(al_Cursor, "PRD_Code")) = "" Then
        
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9911, "#PRD_Code missing.") & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "CG_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9912, "#CG_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "PRD_Name")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9913, "#PRD_Name missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "Origin_type")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9914, "#Origin_type missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "PF_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9915, "#PF_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(ls_BM_Code) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9916, "#BM_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "PE_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9917, "#PE_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "SF_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9918, "#SF_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "COLOUR_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9919, "#COLOUR_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "PS_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9920, "#PS_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "SH_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9921, "#SH_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "BI_perf_ind")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9922, "#BI_perf_ind missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "PP_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9923, "#PP_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "MS_Code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9924, "#MS_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
'    If Trim(mo_Db.GetFields(al_Cursor, "BI_drawn")) = "" Then
'        as_warning = as_warning & "BI_drawn missing." & vbCrLf
'        CreateBaseItem_simulate = False
'    End If
    If Trim(mo_Db.GetFields(al_Cursor, "BI_armstrong")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9925, "#BI_armstrong missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "BI_type")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9926, "#BI_type missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "BI_length")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9927, "#BI_length missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "BI_width")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9928, "#BI_width missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If ld_Height = 0 Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9929, "#Height missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "RPL_Thick")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9930, "#RPL_Thick missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "RPL_NWgh")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9931, "#RPL_NWgh missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "DED_code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9932, "#DED_code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(ls_SBM_Code) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9933, "#SBM_Code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "IsASProduct")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9934, "#IsASProduct missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "MFGP_code")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9935, "#MFGP_code missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    If Trim(mo_Db.GetFields(al_Cursor, "YEAR")) = "" Then
        as_warning = as_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9936, "#YEAR missing. ($PRD_Code$)", Array("$PRD_Code$", mo_Db.GetFields(al_Cursor, "PRD_Code"))) & vbCrLf
        CreateBaseItem_simulate = False
    End If
    
    Exit Function
ErrHandler:
    Call ErrorHandler("CreateBaseItem_simulate")
End Function



Private Function GenerateBase_item(ByVal as_COF_Id As String) As String
On Error GoTo ErrHandler
    Dim ls_warning As String
    Dim ll_items_count As Long
    GenerateBase_item = ""

Const C_REQ As String = "EXEC DPCItemTOBI_lst '$COF_ID$'"
Const C_REQ_DPC_UPD As String = "EXEC DPCItemTOBI_upd $PRD_CODE$, $BI_SAP_CODE$"

    Dim ls_req As String
    Dim ll_Cursor As Long
    ls_req = Replace(C_REQ, "$COF_ID$", as_COF_Id, , , vbTextCompare)
    
    ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    
    ll_items_count = 0
    
    ls_warning = vbCrLf
    
    While Not mo_Db.EOF(ll_Cursor)
        If CreateBaseItem(ll_Cursor) Then
            ll_items_count = ll_items_count + 1
            ' UPDATE DPC
            ls_req = Replace(C_REQ_DPC_UPD, "$PRD_CODE$", mo_Tools.SQLStr(mo_Db.GetFields(ll_Cursor, "PRD_Code"), 30), , , vbTextCompare)
            ls_req = Replace(ls_req, "$BI_SAP_CODE$", mo_Tools.SQLStr(mo_Db.GetFields(ll_Cursor, "PRD_Code"), 20), , , vbTextCompare)
            Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
        Else
            ls_warning = ls_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9908, "#Failed to save item $PRD_Code$!" & vbCrLf, Array("$PRD_Code$", mo_Db.GetFields(ll_Cursor, "PRD_Code")))
        End If
        Call mo_Db.Next(ll_Cursor)
    Wend
    
    Call mo_Db.Close(ll_Cursor)
    ll_Cursor = 0
    
    If ll_items_count > 0 Then
        ls_warning = ls_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9909, "#Base Items created: $COUNT$!", Array("$COUNT$", ll_items_count))
    Else
        ls_warning = ls_warning & mo_Tools.MsgText(mo_Db, ms_Language_Code, 9910, "#No Base Item created.")
    End If

    GenerateBase_item = ls_warning
    Exit Function
ErrHandler:
    If ll_Cursor <> 0 Then
        Call mo_Db.Close(ll_Cursor)
        ll_Cursor = 0
    End If
    Call ErrorHandler("GenerateBase_item")
End Function

Private Function CreateBaseItem(ByVal al_Cursor As Long) As Boolean
On Error GoTo ErrHandler
    CreateBaseItem = False
    
    ' get SMB_Code and BM_Code from BML_Code
    Dim ll_Cursor As Long
    
    ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, "SELECT SBM_CODE, BM_CODE FROM Base_Material_Link WHERE Language_code='E' AND CG_Code='" & mo_Db.GetFields(al_Cursor, "CG_Code") & "' AND BML_Code='" & mo_Db.GetFields(al_Cursor, "BML_Code") & "'")
    Dim ls_SBM_Code As String
    Dim ls_BM_Code As String
    
    ls_SBM_Code = mo_Db.GetFields(ll_Cursor, "SBM_Code")
    ls_BM_Code = mo_Db.GetFields(ll_Cursor, "BM_Code")
    
    Call mo_Db.Close(ll_Cursor)
    ll_Cursor = 0
    
    ' height not relevant for categories C001 and C006 - check in Base_Item_ins
    Dim ld_Height As Double
    ld_Height = mo_Db.GetFields(al_Cursor, "RPL_HD")
    If ld_Height < mo_Db.GetFields(al_Cursor, "RPL_HC") Then ld_Height = mo_Db.GetFields(al_Cursor, "RPL_HC")
    If ld_Height < mo_Db.GetFields(al_Cursor, "RPL_HE") Then ld_Height = mo_Db.GetFields(al_Cursor, "RPL_HE")
    If ld_Height < mo_Db.GetFields(al_Cursor, "RPL_HF") Then ld_Height = mo_Db.GetFields(al_Cursor, "RPL_HF")
    
    If SaveBI(mo_Db.GetFields(al_Cursor, "PRD_Code"), mo_Db.GetFields(al_Cursor, "CG_Code"), "", mo_Db.GetFields(al_Cursor, "PRD_Name"), _
            mo_Db.GetFields(al_Cursor, "Origin_type"), "", mo_Db.GetFields(al_Cursor, "PF_Code"), ls_BM_Code, "", mo_Db.GetFields(al_Cursor, "PE_Code"), _
            mo_Db.GetFields(al_Cursor, "SF_Code"), mo_Db.GetFields(al_Cursor, "COLOUR_Code"), mo_Db.GetFields(al_Cursor, "PS_Code"), _
            mo_Db.GetFields(al_Cursor, "SH_Code"), mo_Db.GetFields(al_Cursor, "BI_perf_ind"), mo_Db.GetFields(al_Cursor, "PP_Code"), _
            mo_Db.GetFields(al_Cursor, "MS_Code"), mo_Db.GetFields(al_Cursor, "launch_date"), mo_Db.GetFields(al_Cursor, "BI_drawn"), _
            mo_Db.GetFields(al_Cursor, "BI_armstrong"), "", "N", mo_Db.GetFields(al_Cursor, "BI_type"), mo_Db.GetFields(al_Cursor, "BI_length"), _
            mo_Db.GetFields(al_Cursor, "BI_width"), ld_Height, mo_Db.GetFields(al_Cursor, "RPL_Thick"), mo_Db.GetFields(al_Cursor, "RPL_NWgh"), _
            "", 0, mo_Db.GetFields(al_Cursor, "DED_code"), ls_SBM_Code, "", mo_Db.GetFields(al_Cursor, "IsASProduct"), mo_Db.GetFields(al_Cursor, "MFGP_code"), _
            mo_Db.GetFields(al_Cursor, "YEAR")) Then
        CreateBaseItem = True
    End If
    
    Exit Function
ErrHandler:
    Call ErrorHandler("CreateBaseItem")
End Function

Private Function SaveBI(ByVal as_BI_SAP_Code As String, ByVal as_CG_Code As String, ByVal as_BI_short_code As String, ByVal as_BI_desc As String, _
                    ByVal as_origin_type As String, ByVal as_PV_code As String, ByVal as_pf_code As String, ByVal as_BM_Code As String, _
                    ByVal as_PD_code As String, ByVal as_pe_code As String, ByVal as_SF_code As String, ByVal as_COLOUR_code As String, _
                    ByVal as_PS_code As String, ByVal as_SH_Code As String, ByVal as_BI_perf_ind As String, ByVal as_PP_code As String, _
                    ByVal as_MS_Code As String, ByVal ad_launch_date As Date, ByVal as_BI_drawn As String, ByVal as_BI_armstrong As String, _
                    ByVal ad_drop_date As Variant, ByVal as_drop_flag As String, ByVal as_BI_type As String, ByVal ad_BI_length As Double, _
                    ByVal ad_BI_width As Double, ByVal ad_BI_height As Double, ByVal ad_BI_thickness As Double, ByVal ad_BI_weight As Double, _
                    ByVal as_BI_GR_cor As String, ByVal ad_BI_gauge As Double, ByVal as_DED_code As String, ByVal as_SBM_Code As String, _
                    ByVal as_internet As String, ByVal as_BI_A_Free1 As String, ByVal as_MFGP_code As String, ByVal as_YEAR As String) As Boolean

On Error GoTo ErrHandler
Const C_REQ As String = "EXEC Base_Item_ins $BI_SAP_code$,$CG_code$,$BI_short_code$,$BI_desc$,$origin_type$,$PV_code$,$PF_code$,$BM_code$,$PD_code$,$PE_code$," & _
                        "$SF_code$,$COLOUR_code$,$PS_code$,$SH_code$,$BI_perf_ind$,$PP_code$,$MS_code$,$launch_date$,$BI_drawn$,$BI_armstrong$,$drop_date$," & _
                        "$drop_flag$,$BI_type$,$BI_length$,$BI_width$,$BI_height$,$BI_thickness$,$BI_weight$,$BI_GR_cor$,$BI_gauge$,$DED_code$,$SBM_code$," & _
                        "$internet$,$BI_A_Free1$"
                        
Const C_REQ_LM As String = "EXEC BI_Logistic_Market_ins2 $BI_SAP_code$"

Const C_REQ_SPA As String = "EXEC SPA_PGAMBI_Link_Default_ins $BI_SAP_code$"

Const C_REQ_PLNT As String = "EXEC Base_Item_Plants_ins $BI_SAP_code$, $MFGP_code$, 0"

Const C_REQ_YEAR As String = "EXEC Item_Activity_ins $BI_SAP_code$, $YEAR$"

    SaveBI = False
    
    Dim ls_req As String
    Dim lb_InTran As Boolean
    
    lb_InTran = False
    
    ' Base_Item, Base_item_desc
    
    ls_req = Replace(C_REQ, "$BI_SAP_code$", mo_Tools.SQLStr(as_BI_SAP_Code, 20), , , vbTextCompare)
    ls_req = Replace(ls_req, "$CG_code$", mo_Tools.SQLStr(as_CG_Code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_short_code$", mo_Tools.SQLStr(as_BI_short_code, 10), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_desc$", mo_Tools.SQLStr(as_BI_desc, 150), , , vbTextCompare)
    ls_req = Replace(ls_req, "$origin_type$", mo_Tools.SQLStr(as_origin_type, 20), , , vbTextCompare)
    ls_req = Replace(ls_req, "$PV_code$", mo_Tools.SQLStr(as_PV_code, 2), , , vbTextCompare)
    ls_req = Replace(ls_req, "$PF_code$", mo_Tools.SQLStr(as_pf_code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BM_code$", mo_Tools.SQLStr(as_BM_Code, 3), , , vbTextCompare)
    ls_req = Replace(ls_req, "$PD_code$", mo_Tools.SQLStr(as_PD_code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$PE_code$", mo_Tools.SQLStr(as_pe_code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SF_code$", mo_Tools.SQLStr(as_SF_code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$COLOUR_code$", mo_Tools.SQLStr(as_COLOUR_code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$PS_code$", mo_Tools.SQLStr(as_PS_code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SH_code$", mo_Tools.SQLStr(as_SH_Code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_perf_ind$", mo_Tools.SQLStr(as_BI_perf_ind, 1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$PP_code$", mo_Tools.SQLStr(as_PP_code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$MS_code$", mo_Tools.SQLStr(as_MS_Code, 1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$launch_date$", mo_Tools.SqlDate(ad_launch_date), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_drawn$", mo_Tools.SQLStr(as_BI_drawn, 3), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_armstrong$", mo_Tools.SQLStr(as_BI_armstrong, 3), , , vbTextCompare)
    ls_req = Replace(ls_req, "$drop_date$", mo_Tools.SqlDate(ad_drop_date), , , vbTextCompare)
    ls_req = Replace(ls_req, "$drop_flag$", mo_Tools.SQLStr(as_drop_flag, 1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_type$", mo_Tools.SQLStr(as_BI_type, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_length$", mo_Tools.SqlDbl(ad_BI_length), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_width$", mo_Tools.SqlDbl(ad_BI_width), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_height$", mo_Tools.SqlDbl(ad_BI_height), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_thickness$", mo_Tools.SqlDbl(ad_BI_thickness), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_weight$", mo_Tools.SqlDbl(ad_BI_weight), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_GR_cor$", mo_Tools.SQLStr(as_BI_GR_cor, 10), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_gauge$", mo_Tools.SqlDbl(ad_BI_gauge), , , vbTextCompare)
    ls_req = Replace(ls_req, "$DED_code$", mo_Tools.SQLStr(as_DED_code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$SBM_code$", mo_Tools.SQLStr(as_SBM_Code, 4), , , vbTextCompare)
    ls_req = Replace(ls_req, "$internet$", mo_Tools.SQLStr(as_internet, 1), , , vbTextCompare)
    ls_req = Replace(ls_req, "$BI_A_Free1$", mo_Tools.SQLStr(as_BI_A_Free1, 1), , , vbTextCompare)
    
    Call mo_Tools.BeginTran(mo_Db, ml_U_Code, SCREEN_NAME, "base_item_create")
    lb_InTran = True
    
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    
    ' "Not sold" for all Logistic Markets:
    ls_req = Replace(C_REQ_LM, "$BI_SAP_code$", mo_Tools.SQLStr(as_BI_SAP_Code, 20), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
            
    ' SPA system assignement:
    ls_req = Replace(C_REQ_SPA, "$BI_SAP_code$", mo_Tools.SQLStr(as_BI_SAP_Code, 20), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    
    ' Plant
    ls_req = Replace(C_REQ_PLNT, "$BI_SAP_code$", mo_Tools.SQLStr(as_BI_SAP_Code, 20), , , vbTextCompare)
    ls_req = Replace(ls_req, "$MFGP_code$", mo_Tools.SQLStr(as_MFGP_code, 10), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    
    ' Year of activity
    ls_req = Replace(C_REQ_YEAR, "$BI_SAP_code$", mo_Tools.SQLStr(as_BI_SAP_Code, 20), , , vbTextCompare)
    ls_req = Replace(ls_req, "$YEAR$", mo_Tools.SQLStr(as_YEAR, 4), , , vbTextCompare)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    
    Call mo_Tools.CommitTran(mo_Db, ml_U_Code, SCREEN_NAME, "base_item_create")
    lb_InTran = False
     
    SaveBI = True
    Exit Function
ErrHandler:
    If lb_InTran Then
        Call mo_Tools.RollbackTran(mo_Db, ml_U_Code, SCREEN_NAME, "base_item_create")
        lb_InTran = False
        ' do not raise error but return false
        Call mo_Tools.LogMessage(mo_Db, ml_U_Code, SCREEN_NAME, " exception. Nr:" & Err.Number & ",Desc: " & Err.Description & ",Src:" & "SaveBI" & SEP1 & Err.Source & "@", "I")
        Exit Function
    End If

    Call ErrorHandler("SaveBI")
End Function

Private Sub btn_BaurerSOChangeExport_Click()
On Error GoTo ErrHandler
    
Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrorMsg As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  lb_Result = False
  Set lo_XmlExport.ArmDb = mo_Db
  Set lo_XmlExport.Tools = mo_Tools
  lo_XmlExport.Language_Code = ms_Language_Code
  lo_XmlExport.CT_Code = ms_CT_Code
  lo_XmlExport.U_Code = ml_U_Code
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.Bae_SalesOrderChangeExport(m_CurrentKey1, ls_ErrorMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call ViewInitFields
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If (Not lb_Result) Or (Len(ls_ErrorMsg) > 0) Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Sales order change export failed: $ERROR$", Array("$OPERATION$", btn_BaurerSOChangeExport.Caption, "$ERROR$", ls_ErrorMsg))
    'Call MsgBox("Sales order change export failed: " & ls_ErrorMsg)
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Sales order change exported successfuly. $TEXT$", Array("$OPERATION$", btn_BaurerSOChangeExport.Caption, "$TEXT$", ""))
    'Call MsgBox("Sales order change exported successfuly")
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("btn_BaurerSOChangeExport")
End Sub

Private Sub cmd_KillOrderB7_Click()
On Error GoTo ErrHandler

Dim lo_XmlExport As New DPC_Interface
Dim ls_ErrorMsg As String
Dim lb_Result As Boolean
Dim lb_OfferLocked As Boolean

  Call mo_Tools.LockScreen(Me, True)
  lb_OfferLocked = GetOfferLock(m_CurrentKey1)
  If Not lb_OfferLocked Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  lb_Result = False
  Set lo_XmlExport.ArmDb = mo_Db
  lo_XmlExport.U_Code = ml_U_Code
  Set lo_XmlExport.Tools = mo_Tools
  Call lo_XmlExport.Load_A_COM
  lb_Result = lo_XmlExport.Bae_SalesOrderKill(m_CurrentKey1, ls_ErrorMsg)
  Call lo_XmlExport.Unload_A_COM
  Set lo_XmlExport = Nothing
  
  Call RefreshOfferDetail
  Call ReleaseOfferLock(m_CurrentKey1)
  lb_OfferLocked = False
  Call mo_Tools.LockScreen(Me, False)
  
  If (Not lb_Result) Or (Len(ls_ErrorMsg) > 0) Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9863, "#Sales order kill export failed: $ERROR$", Array("$OPERATION$", cmd_KillOrderB7.Caption, "$ERROR$", ls_ErrorMsg))
    'Call MsgBox("Sales order kill export failed: " & ls_ErrorMsg)
  Else
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Sales order kill exported successfuly. $TEXT$", Array("$OPERATION$", cmd_KillOrderB7.Caption, "$TEXT$", ""))
    'Call MsgBox("Sales order kill exported successfuly")
  End If
  Exit Sub
ErrHandler:
  If lb_OfferLocked Then
    Call mo_Tools.UpdateError(True)
    Call ReleaseOfferLock(m_CurrentKey1)
    Call mo_Tools.UpdateError(False)
  End If
  Call ErrorMessage("cmd_KillOrderB7_Click")
End Sub

Private Function CreateTechnicsPath(ByRef as_Path As String) As Boolean
On Error GoTo ErrHandler

Dim ls_TechPath As String
  
  CreateTechnicsPath = False
  ls_TechPath = mo_Tools.GetAConfigData("DPC_RNK_TECH_PATH")
  
  If (Left(ls_TechPath, 1) <> "\") And (Left(ls_TechPath, 1) <> "") Then
    If Not mo_FSO.DriveExists(Left(ls_TechPath, 1)) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9865, "#Folder do not exists: $folder$", Array("$folder$", ls_TechPath))
      Exit Function
    End If
  End If
  
  If (Trim(ls_TechPath) = "") Or (Not mo_FSO.FolderExists(ls_TechPath)) Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9865, "#Folder do not exists: $folder$", Array("$folder$", ls_TechPath))
    Exit Function
  End If
  
  If right(ls_TechPath, 1) <> "\" Then ls_TechPath = ls_TechPath & "\"
  ls_TechPath = ls_TechPath & m_Project
  
  If Not mo_FSO.FolderExists(ls_TechPath) Then
    Call mo_FSO.CreateFolder(ls_TechPath)
  End If
  
  'If ab_AddOfferCode Then
  '  If right(ls_TechPath, 1) <> "\" Then ls_TechPath = ls_TechPath & "\"
  '  ls_TechPath = ls_TechPath & txt_COF_Code.Text
 '
 '   If Not mo_FSO.FolderExists(ls_TechPath) Then
 '     Call mo_FSO.CreateFolder(ls_TechPath)
 '   End If
 ' End If
  as_Path = ls_TechPath
  CreateTechnicsPath = True
  Exit Function
ErrHandler:
  CreateTechnicsPath = False
End Function

Private Sub cmd_TechnicsPath_Click()
On Error GoTo ErrHandler

Dim ls_TechPath As String
Dim lo_shell As Object

  Call mo_Tools.LockScreen(Me, True)
  
  If Not CreateTechnicsPath(ls_TechPath) Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  Set lo_shell = CreateObject("Shell.Application")
  Call lo_shell.ShellExecute(ls_TechPath, "", "", "open", 1)
  Set lo_shell = Nothing
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cmd_TechnicsPath_Click")
End Sub

Private Function OpenExcelDocument(ByVal as_Name As String, ByRef ao_ExcelApp As Object, ByRef ao_ExcelBook) As Boolean
On Error GoTo ErrHandler

    OpenExcelDocument = False
    
    On Error GoTo Err_NotLoaded
    
    Set ao_ExcelApp = Nothing
    Set ao_ExcelBook = Nothing
    
    Set ao_ExcelApp = GetObject(, "Excel.Application")
    
    If ao_ExcelApp Is Nothing Then
      Set ao_ExcelApp = CreateObject("Excel.Application")
    End If
    
    If ao_ExcelApp Is Nothing Then GoTo ErrHandler
    
    On Error GoTo ErrHandler
    
    ao_ExcelApp.Application.Visible = False
    Set ao_ExcelBook = ao_ExcelApp.Workbooks.Open(as_Name)
    OpenExcelDocument = True
    Exit Function
Err_NotLoaded:
    If Err.Number = 429 Then
        Resume Next
    End If
ErrHandler:
    Call MsgBox("Error opening Excel: " & Err.Description)
    Set ao_ExcelApp = Nothing
    Set ao_ExcelBook = Nothing
End Function

Private Function SetCell(ByVal ao_ExcelSheet As Object, ByVal al_Row As Long, ByVal al_Col As Long, ByVal av_Value As Variant, ByVal al_CodePage As Long)
On Error GoTo ErrHandler
  
  If VarType(av_Value) = vbString Then
    ao_ExcelSheet.Cells(al_Row, al_Col) = ConvertCodePageFromAnsi("'" & Trim(CStr(av_Value)), al_CodePage)
  ElseIf VarType(av_Value) = vbDate Then
    If av_Value = 0 Then
      ao_ExcelSheet.Cells(al_Row, al_Col) = Empty
    Else
      ao_ExcelSheet.Cells(al_Row, al_Col) = av_Value
    End If
  Else
    ao_ExcelSheet.Cells(al_Row, al_Col) = av_Value
  End If
  Exit Function
ErrHandler:
End Function

Private Sub AddGasketInfo(ByVal ao_Dictionary As Dictionary, ByVal ac_Cursor As Long, ByVal as_FieldID As String, ByVal as_FieldName As String)
On Error GoTo ErrHandler

  If mo_Db.GetFields(ac_Cursor, as_FieldID) <> "" Then
    If Not ao_Dictionary.Exists(mo_Db.GetFields(ac_Cursor, as_FieldID)) Then
      Call ao_Dictionary.Add(mo_Db.GetFields(ac_Cursor, as_FieldID), mo_Db.GetFields(ac_Cursor, as_FieldName))
    End If
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("AddGasketInfo")
End Sub

Public Function GetGasketName(ByVal ac_Cursor As Long) As String
On Error GoTo ErrHandler

Dim lo_GSK As New Dictionary
Dim ll_Idx As Long
Dim ls_Gasket As String

  Call AddGasketInfo(lo_GSK, ac_Cursor, "GSK_IdC", "GSK_NameC")
  Call AddGasketInfo(lo_GSK, ac_Cursor, "GSK_IdD", "GSK_NameD")
  Call AddGasketInfo(lo_GSK, ac_Cursor, "GSK_IdE", "GSK_NameE")
  Call AddGasketInfo(lo_GSK, ac_Cursor, "GSK_IdF", "GSK_NameF")
  ls_Gasket = ""
  For ll_Idx = 0 To lo_GSK.Count - 1
    If ls_Gasket <> "" Then ls_Gasket = ls_Gasket & vbCrLf
    ls_Gasket = ls_Gasket & lo_GSK.Items(ll_Idx)
  Next
  Call lo_GSK.RemoveAll
  Set lo_GSK = Nothing
  GetGasketName = ls_Gasket
  Exit Function
ErrHandler:
  Call ErrorHandler("GetGasketName")
End Function

Public Function GetSpacerName(ByVal ac_Cursor As Long) As String
On Error GoTo ErrHandler

Dim lo_GSK As New Dictionary
Dim ll_Idx As Long
Dim ls_Gasket As String

  Call AddGasketInfo(lo_GSK, ac_Cursor, "GSK_Id2C", "GSK_Name2C")
  Call AddGasketInfo(lo_GSK, ac_Cursor, "GSK_Id2D", "GSK_Name2D")
  Call AddGasketInfo(lo_GSK, ac_Cursor, "GSK_Id2E", "GSK_Name2E")
  Call AddGasketInfo(lo_GSK, ac_Cursor, "GSK_Id2F", "GSK_Name2F")
  ls_Gasket = ""
  For ll_Idx = 0 To lo_GSK.Count - 1
    If ls_Gasket <> "" Then ls_Gasket = ls_Gasket & vbCrLf
    ls_Gasket = ls_Gasket & lo_GSK.Items(ll_Idx)
  Next
  Call lo_GSK.RemoveAll
  Set lo_GSK = Nothing
  GetSpacerName = ls_Gasket
  Exit Function
  Exit Function
ErrHandler:
  Call ErrorHandler("GetSpacerName")
End Function

Private Function SetRowData(ByVal ao_ExcelSheet As Object, ByVal ac_Cursor As Long, ByVal al_CodePage As Long) As Boolean
On Error GoTo ErrorHandler
Dim ll_Idx As Long
Dim ls_SepFields As String
Dim lsa_Fields() As String
Dim lv_Value As Variant
Dim ll_CutIdx As Long

  ls_SepFields = "OFD_Pos" & SEP1 & "OFD_PosCus" & SEP1 & "RPL_DrwNr" & SEP1 & "PRD_Code" & SEP1 & "PRD_Name" & SEP1 & "RPL_BaeType" & SEP1 & "OFD_Qty" & SEP1 & "RPL_MatTyp" & SEP1 & "RPL_Thick"
  ls_SepFields = ls_SepFields & SEP1 & "COA_ExName" & SEP1 & "COA_Code" & SEP1 & "COA_AppDesc" & SEP1 & "RPL_CoSidDesc"
  ls_SepFields = ls_SepFields & SEP1 & "CustomGSK" & SEP1 & "GSK_Pos" & SEP1 & "CustomGSK2" & SEP1 & "GSK_Pos2"
  ls_SepFields = ls_SepFields & SEP1 & "INL_Excel1" & SEP1 & "INL_Excel2" & SEP1 & "INL_Excel3"
  ls_SepFields = ls_SepFields & SEP1 & "PRD_InternalComment" & SEP1 & "RPL_CoilW" & SEP1 & "RPL_ModA" & SEP1 & "RPL_ModB" & SEP1 & "RPL_PanA" & SEP1 & "RPL_PanB"
  ls_SepFields = ls_SepFields & SEP1 & "PRF_Name" & SEP1 & "RPL_PBordDesc" & SEP1 & "RPL_UBoWC" & SEP1 & "RPL_UBoWD" & SEP1 & "RPL_UBoWE" & SEP1 & "RPL_UBoWF"
  ls_SepFields = ls_SepFields & SEP1 & "RPL_UBorC" & SEP1 & "RPL_UBorD" & SEP1 & "RPL_UBorE" & SEP1 & "RPL_UBorF"
  ls_SepFields = ls_SepFields & SEP1 & "BND_DescC" & SEP1 & "RPL_HC" & SEP1 & "RPL_UC" & SEP1 & "RPL_SC" & SEP1 & "RPL_NCloC" & SEP1 & "RPL_BVisC"
  ls_SepFields = ls_SepFields & SEP1 & "BND_DescD" & SEP1 & "RPL_HD" & SEP1 & "RPL_UD" & SEP1 & "RPL_SD" & SEP1 & "RPL_NCloD" & SEP1 & "RPL_BVisD"
  ls_SepFields = ls_SepFields & SEP1 & "BND_DescE" & SEP1 & "RPL_HE" & SEP1 & "RPL_UE" & SEP1 & "RPL_SE" & SEP1 & "RPL_NCloE" & SEP1 & "RPL_BVisE"
  ls_SepFields = ls_SepFields & SEP1 & "BND_DescF" & SEP1 & "RPL_HF" & SEP1 & "RPL_UF" & SEP1 & "RPL_SF" & SEP1 & "RPL_NCloF" & SEP1 & "RPL_BVisF"
  ls_SepFields = ls_SepFields & SEP1 & "CUT_Name1" & SEP1 & "PCT_SizeJ1" & SEP1 & "PCT_SizeK1" & SEP1 & "PCT_SizeD1" & SEP1 & "PCT_SizeL1" & SEP1 & "PCT_SizeM1"
  ls_SepFields = ls_SepFields & SEP1 & "CUT_Name2" & SEP1 & "PCT_SizeJ2" & SEP1 & "PCT_SizeK2" & SEP1 & "PCT_SizeD2" & SEP1 & "PCT_SizeL2" & SEP1 & "PCT_SizeM2"
  ls_SepFields = ls_SepFields & SEP1 & "CUT_Name3" & SEP1 & "PCT_SizeJ3" & SEP1 & "PCT_SizeK3" & SEP1 & "PCT_SizeD3" & SEP1 & "PCT_SizeL3" & SEP1 & "PCT_SizeM3"
  ls_SepFields = ls_SepFields & SEP1 & "CUT_Name4" & SEP1 & "PCT_SizeJ4" & SEP1 & "PCT_SizeK4" & SEP1 & "PCT_SizeD4" & SEP1 & "PCT_SizeL4" & SEP1 & "PCT_SizeM4"
  
  lsa_Fields = Split(ls_SepFields, SEP1)
  For ll_Idx = 0 To UBound(lsa_Fields)
    lv_Value = ""
    If mo_Db.GetFieldIndex(ac_Cursor, lsa_Fields(ll_Idx)) > 0 Then
      
      lv_Value = mo_Db.GetFields(ac_Cursor, lsa_Fields(ll_Idx))
      
      If StrComp(Left(lsa_Fields(ll_Idx), 8), "PCT_Size", vbTextCompare) = 0 Then
        ll_CutIdx = Val(right(lsa_Fields(ll_Idx), 1))
        If mo_Db.GetFields(ac_Cursor, "CUT_Name" & ll_CutIdx) = "" Then
          lv_Value = ""
        End If
      ElseIf (StrComp(Left(lsa_Fields(ll_Idx), 8), "RPL_BVis", vbTextCompare) = 0) Or ((StrComp(Left(lsa_Fields(ll_Idx), 8), "RPL_NClo", vbTextCompare) = 0)) Then
        If StrComp(CStr(lv_Value), "CHECK", vbTextCompare) = 0 Then
          lv_Value = "X"
        Else
          lv_Value = ""
        End If
      ElseIf StrComp(Left(lsa_Fields(ll_Idx), 7), "RPL_UBo", vbTextCompare) = 0 Then
        If (StrComp(Trim(mo_Db.GetFields(ac_Cursor, "PRF_Id")), mo_Tools.GetAConfigData("DPC_Default_PRF0"), vbTextCompare) = 0) Then
          lv_Value = ""
        End If
      ElseIf StrComp(lsa_Fields(ll_Idx), "RPL_MatTyp", vbTextCompare) = 0 Then
        If lv_Value = "" Then lv_Value = mo_Db.GetFields(ac_Cursor, "MAT_Name")
      End If
    Else
      Select Case lsa_Fields(ll_Idx)
      Case "CustomGSK"
        lv_Value = GetGasketName(ac_Cursor)
      Case "CustomGSK2"
        lv_Value = GetSpacerName(ac_Cursor)
      Case "INL_Excel1"
        If mo_Db.GetFields(ac_Cursor, "INL_Id1") <> "" Then
          lv_Value = mo_Db.GetFields(ac_Cursor, "INL_Code1") + " [" & mo_Db.GetFields(ac_Cursor, "INL_Name1") & "]" & "\" & mo_Db.GetFields(ac_Cursor, "PIN_DelivDesc1")
        End If
      Case "INL_Excel2"
        If mo_Db.GetFields(ac_Cursor, "INL_Id2") <> "" Then
          lv_Value = mo_Db.GetFields(ac_Cursor, "INL_Code2") + " [" & mo_Db.GetFields(ac_Cursor, "INL_Name2") & "]" & "\" & mo_Db.GetFields(ac_Cursor, "PIN_DelivDesc2")
        End If
      Case "INL_Excel3"
        If mo_Db.GetFields(ac_Cursor, "INL_Id3") <> "" Then
          lv_Value = mo_Db.GetFields(ac_Cursor, "INL_Code3") + " [" & mo_Db.GetFields(ac_Cursor, "INL_Name3") & "]" & "\" & mo_Db.GetFields(ac_Cursor, "PIN_DelivDesc3")
        End If
      Case Else
        Call MsgBox("Field not found: " & lsa_Fields(ll_Idx))
      End Select
    End If
    
    Call SetCell(ao_ExcelSheet, mo_Db.Position(ac_Cursor) + 4, ll_Idx + 1, lv_Value, al_CodePage)
  Next
  SetRowData = True
  Exit Function
ErrorHandler:
End Function

Private Sub cmd_TechnicsExcel_Click()
On Error GoTo ErrHandler

Dim ls_TechPath As String
Dim ls_TechFile As String
Dim lo_ExcelApp As Object
Dim lo_ExcelWorkBook As Object
Dim lo_ExcelSheet As Object
Dim lc_Cursor As Long
Dim ls_req As String
Dim ll_CodePage As Long

  Call mo_Tools.LockScreen(Me, True)
  
  If Not CreateTechnicsPath(ls_TechPath) Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  
  ll_CodePage = mo_Tools.GetCodePageFromLanguage(mo_Db, ms_COF_Lang)
  ls_TechFile = ls_TechPath & "\" & Trim(txt_COF_Code.Text) & ".xlsx"
  
  If mo_FSO.FileExists(ls_TechFile) Then
    If Not mo_Tools.DeleteFile(mo_FSO, ls_TechFile) Then
      Err.Raise ArmErr.CompFncFailed, "DeleteFile", "Delete file failed: " & ls_TechFile
    End If
  End If
  
  If Not mo_Db.BlobToFileSQL("SELECT F_Data_File from A_Files WHERE F_File_Key='DPC_TECH_XLSX'", ls_TechFile, True, False) Then
    Err.Raise ArmErr.CompFncFailed, "BlobToFileSQL", mo_Db.LastErrorMessage
  End If
  
  If OpenExcelDocument(ls_TechFile, lo_ExcelApp, lo_ExcelWorkBook) Then
    
    lo_ExcelApp.ScreenUpdating = False
    Call lo_ExcelWorkBook.Activate
    Set lo_ExcelSheet = lo_ExcelWorkBook.Worksheets(1)
    Call lo_ExcelSheet.Activate
    Call SetCell(lo_ExcelSheet, 2, 5, txt_COF_Comm.Text & vbCrLf & txt_COF_Desc.Text, ll_CodePage)
    Call SetCell(lo_ExcelSheet, 2, 11, ls_TechPath, ll_CodePage)
    
    ls_req = "exec Cap_OfferPosList_lst $COF_Id$, $COF_Lang$, 0, 0, 0, 0, '', '', '', '', 0, 0, 0, 0"
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
    ls_req = Replace(ls_req, "$COF_Lang$", mo_Tools.SQLStr("G"), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    Do While Not mo_Db.EOF(lc_Cursor)
      Call SetRowData(lo_ExcelSheet, lc_Cursor, ll_CodePage)
      Call mo_Db.Next(lc_Cursor)
    Loop
    Call mo_Db.Close(lc_Cursor)
    
    'lo_ExcelApp.CutCopyMode = False
    Call lo_ExcelWorkBook.Save
    Call lo_ExcelWorkBook.Close(True)
    lo_ExcelApp.ScreenUpdating = True
    Call lo_ExcelApp.quit
    Set lo_ExcelSheet = Nothing
    Set lo_ExcelWorkBook = Nothing
    Set lo_ExcelApp = Nothing
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Export Excel succeeded for: $TEXT$", Array("$OPERATION$", cmd_TechnicsExcel.Caption, "$TEXT$", ""))
  End If
  
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Set lo_ExcelSheet = Nothing
  Set lo_ExcelWorkBook = Nothing
  Set lo_ExcelApp = Nothing
  Call MsgBox("Excel export failed: " & Err.Number & ",Desc: " & Err.Description & ",Src:" & Err.Source)
  Call mo_Tools.LockScreen(Me, False)
End Sub

Private Sub cmd_TechnicsAttachments_Click()
On Error GoTo ErrHandler

Dim ls_TechPath As String
Dim ll_FIL_Id As Long
Dim lc_Cursor As Long
Dim ls_Filename As String
Dim ls_req As String
Dim ll_Count As Long
Dim ld_ExportTime As Date

  Call mo_Tools.LockScreen(Me, True)
  
  If Not CreateTechnicsPath(ls_TechPath) Then
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End If
  ld_ExportTime = Now
  ll_Count = 0
  ls_req = "exec Cap_OfferProdFile_lst $Language_Code$,$COF_Id$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  While Not mo_Db.EOF(lc_Cursor)
    ll_FIL_Id = mo_Db.GetFields(lc_Cursor, "FIL_Id")
    ls_req = "SELECT FIL_File FROM DPC_File WHERE FIL_Id=$FIL_Id$"
    ls_req = Replace(ls_req, "$FIL_Id$", mo_Tools.SqlInt(ll_FIL_Id), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    
    ls_Filename = ls_TechPath
    If right(ls_Filename, 1) <> "\" Then ls_Filename = ls_Filename & "\"
    ls_Filename = ls_Filename & mo_Db.GetFields(lc_Cursor, "FIL_FileName")
    If mo_Db.BlobToFileSQL(ls_req, ls_Filename, True, False) Then
      ll_Count = ll_Count + 1
    Else
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9843, "#Cannot download the file from db: " & ll_FIL_Id & " - " & ls_Filename)
    End If
    Call mo_Db.Next(lc_Cursor)
  Wend
  Call mo_Db.Close(lc_Cursor)
  ld_ExportTime = Now - ld_ExportTime
  Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9862, "#Export attachements succeeded for: $TEXT$", Array("$OPERATION$", cmd_TechnicsAttachments.Caption, "$TEXT$", "Count: (" & ll_Count & ") Time: " & Format(ld_ExportTime, "hh:mm:ss")))
  'Call MsgBox("Export attachements succeeded for " & ll_Count & " files. Export time: " & Format(ld_ExportTime, "hh:mm:ss"))
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cmd_TechnicsAttachments_Click")
End Sub

Private Sub cbo_customer_ComboItemSelected()
On Error GoTo ErrHandler
Dim ls_Request As String
    
  If mb_InternalInit Then Exit Sub
  
  mb_InternalInit = True
  Call mo_Tools.LockScreen(Me, True)
  txt_Version.Text = "1"
  Call InitContactCombo(cbo_Contact, m_Project, mo_Tools.GetComboKey(cbo_Customer))
  Call mo_Tools.EnableControl(cbo_Contact, Not (cbo_Customer.SelectedItem Is Nothing))
  If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
    Call SetDefaultTemplate(mo_Tools.GetComboKey(cbo_Customer))
    Call mo_Tools.EnableControl(cbo_Template, (Not (cbo_Customer.SelectedItem Is Nothing)))
    Call DisplayCountryDefaultValues(ms_CT_Code)
  End If
  Call mo_Tools.LockScreen(Me, False)
  mb_InternalInit = False
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_customer_ComboItemSelected")
End Sub

Private Sub cbo_template_ComboItemSelected()
On Error GoTo ErrHandler

  If mb_InternalInit Then Exit Sub
  Call mo_Tools.LockScreen(Me, True)
  mb_InternalInit = True
  If RecordCheck Then
    If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9850, "#Are you sure to change offer language ? This process may take several minutes.", , vbYesNo) = vbYes Then
      ml_COT_Id = mo_Tools.GetComboKey(cbo_Template)
      ms_COF_Lang = mo_Tools.GetComboData(cbo_Template, 2)
      Call ChangeOfferLanguage(ms_COF_Lang)
      Call ViewInitFields
      Call mo_Tools.ChangeCharset(UserControl.Controls, gl_CodePage, mo_Tools.GetCodePageFromLanguage(mo_Db, ms_COF_Lang))
      mb_InternalInit = False
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    End If
  End If
  ' put back the combo value ! - is record check needed ?
  If ml_COT_Id = 0 Then
    Set cbo_Template.SelectedItem = Nothing
  Else
    Call cbo_Template.SearchItem(ml_COT_Id)
  End If
  mb_InternalInit = False
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("cbo_customer_ComboItemSelected")
End Sub

Private Sub ChangeOfferLanguage(ByVal as_COF_Lang As String)
On Error GoTo ErrHandler

Dim lo_PrdCollection As Collection
Dim lo_Collection As Collection
Dim lo_OfferPos As DPC_OfferPos, lo_OfferTranslate As DPC_OfferPos
'Dim ld_COF_DocDat As Date
Dim ls_req As String
Dim lb_InTran As Boolean
Dim lc_Cursor As Long
Dim lo_Product As DPC_Product
Dim lo_SubSys As New DPC_SubSys
Dim ll_SepPos As Long
Dim ls_AddText As String
  
  ' load ALL detail main records of offer
  Set lo_PrdCollection = LoadOfferDetail(m_CurrentKey1, "", eDPCOfferDetailMain.odMain)
  
  Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeOfferLanguage")
  lb_InTran = True
  Call RecordUpdate(m_CurrentKey1)
  For Each lo_OfferPos In lo_PrdCollection
    If (StrComp(lo_OfferPos.OFD_Id, lo_OfferPos.OFD_IdPar, vbTextCompare) = 0) Then
      If ((lo_OfferPos.OFD_Type = eDPCPriceBookType.eStockMetal) Or _
          (lo_OfferPos.OFD_Type = eDPCPriceBookType.eCustomMetal) Or _
          (lo_OfferPos.OFD_Type = eDPCPriceBookType.eEngMetal)) And _
         (lo_OfferPos.CAT_Id <> eDPCCategory.cgOption) Then
        Set lo_Product = New DPC_Product
        Set lo_Product.Tools = mo_Tools
        Set lo_Product.ArmDb = mo_Db
        lo_Product.U_Code = ml_U_Code
        lo_Product.COF_Id = lo_OfferPos.COF_Id
        lo_Product.CT_Code = CT_Code
        lo_Product.CURR_Code = CURR_Code
        lo_Product.ValidityDate = ValidityDate
        lo_Product.Language_Code = as_COF_Lang
        Call lo_Product.Load_A_COM
        Call lo_Product.InitOffer
        Call lo_Product.Load(lo_OfferPos.PRD_Id)
        Call lo_Product.LoadOffer(lo_OfferPos.COF_Id, lo_OfferPos.OFD_IdPar)
        Set lo_Collection = lo_Product.GenerateOfferDetail
        Call lo_Product.Unload_A_COM
        Set lo_Product = Nothing
      ElseIf lo_OfferPos.OFD_Type = eDPCPriceBookType.eSubconstruction Then
        Set lo_SubSys = New DPC_SubSys
        lo_SubSys.U_Code = ml_U_Code
        lo_SubSys.Language_Code = as_COF_Lang
        lo_SubSys.CURR_Code = "EUR"
        Set lo_SubSys.ArmDb = mo_Db
        Set lo_SubSys.Tools = mo_Tools
        Call lo_SubSys.Load_A_COM
        Call lo_SubSys.Load(lo_OfferPos.PRD_Id)
        Call lo_SubSys.LoadOffer(lo_OfferPos.COF_Id, lo_OfferPos.OFD_IdPar)
        Set lo_Collection = lo_SubSys.GenerateOfferDetail
        Call lo_SubSys.Unload_A_COM
        Set lo_SubSys = Nothing
      ElseIf lo_OfferPos.OFD_Type = eDPCPriceBookType.eManualLine Then
        'do nothing
        Set lo_Collection = LoadOfferDetail(m_CurrentKey1, lo_OfferPos.OFD_Id, eDPCOfferDetailMain.odUnknown)
        For Each lo_OfferTranslate In lo_Collection
          ll_SepPos = InStr(1, lo_OfferTranslate.PRD_Name, ":")
          If ll_SepPos > 0 Then
            ls_AddText = right(lo_OfferTranslate.PRD_Name, Len(lo_OfferTranslate.PRD_Name) - ll_SepPos)
            If InStr(1, lo_OfferTranslate.DOF_Name, ":") = 0 Then
              lo_OfferTranslate.PRD_Name = lo_OfferTranslate.DOF_Name & " : " & ls_AddText
            Else
              lo_OfferTranslate.PRD_Name = lo_OfferTranslate.DOF_Name & ls_AddText
            End If
          End If
        Next
      ElseIf lo_OfferPos.OFD_Type = eDPCPriceBookType.eServiceItem Then
        ls_req = "exec DPC_PrdDesc_sel $PRD_Id$, $COF_Lang$"
        ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SQLStr(lo_OfferPos.PRD_Id), , , vbTextCompare)
        ls_req = ReplaceCommonPlaceholders(ls_req)
        lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
        ll_SepPos = InStr(1, lo_OfferPos.PRD_Name, ":")
        If ll_SepPos = 0 Then
          lo_OfferPos.PRD_Name = mo_Db.GetFields(lc_Cursor, "PRD_Name")
        Else
          ls_AddText = right(lo_OfferPos.PRD_Name, Len(lo_OfferPos.PRD_Name) - ll_SepPos - 1)
          If InStr(1, mo_Db.GetFields(lc_Cursor, "PRD_Name"), ":") = 0 Then
            lo_OfferPos.PRD_Name = mo_Db.GetFields(lc_Cursor, "PRD_Name") & " : " & ls_AddText
          Else
            lo_OfferPos.PRD_Name = mo_Db.GetFields(lc_Cursor, "PRD_Name") & ls_AddText
          End If
        End If
        Set lo_Collection = New Collection
        Call lo_Collection.Add(lo_OfferPos)
        Call mo_Db.Close(lc_Cursor)
      ElseIf lo_OfferPos.OFD_Type = eDPCPriceBookType.eStockCapture Then
        ls_req = "exec DPC_Base_Item_sel $BI_SAP_Code$, $COF_Lang$"
        ls_req = Replace(ls_req, "$BI_SAP_Code$", mo_Tools.SQLStr(lo_OfferPos.PRD_Code), , , vbTextCompare)
        ls_req = ReplaceCommonPlaceholders(ls_req)
        lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
        If mo_Db.RowCount(lc_Cursor) = 1 Then
          lo_OfferPos.PRD_Name = mo_Db.GetFields(lc_Cursor, "BI_Desc") & _
                                CreateSizeText(mo_Db.GetFields(lc_Cursor, "BI_Length"), mo_Db.GetFields(lc_Cursor, "BI_Width"), mo_Db.GetFields(lc_Cursor, "BI_Height")) & _
                                CreatePUText(mo_Db.GetFields(lc_Cursor, "LI_piecepercart"))
          Set lo_Collection = New Collection
          Call lo_Collection.Add(lo_OfferPos)
        End If
        Call mo_Db.Close(lc_Cursor)
      ElseIf lo_OfferPos.CAT_Id = eDPCCategory.cgOption Then
        ls_req = "exec DPC_PrdDesc_sel $PRD_Id$, $COF_Lang$"
        ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SQLStr(lo_OfferPos.PRD_Id), , , vbTextCompare)
        ls_req = ReplaceCommonPlaceholders(ls_req)
        lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
        lo_OfferPos.PRD_Name = mo_Db.GetFields(lc_Cursor, "PRD_Name")
        lo_OfferPos.RowStatus = eDPCRowStatus.rsUpdate
        Set lo_Collection = New Collection
        Call lo_Collection.Add(lo_OfferPos)
        Call mo_Db.Close(lc_Cursor)
      Else
        Debug.Print "Unknown product"
        Debug.Assert True
      End If
      If Not (lo_Collection Is Nothing) Then
        Call SaveOfferDetail(lo_Collection, lo_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
        Call mo_Tools.ClearCollection(lo_Collection)
        Set lo_Collection = Nothing
      End If
    End If
  Next
  Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeOfferLanguage")
  lb_InTran = False
  Call mo_Tools.ClearCollection(lo_PrdCollection)
  Set lo_PrdCollection = Nothing
  Exit Sub
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeOfferLanguage")
  End If
  Call ErrorHandler("ChangeOfferLanguage")
End Sub

Private Sub CalculateOfferSummary()
On Error GoTo ErrHandler

Dim ll_Idx As Long
Dim lb_HasNoCost As Boolean

  lb_HasNoCost = False
  md_OfferCost = 0
  md_OfferPrice = 0
  md_TotalCost = 0
  md_TotalPrice = 0
  For ll_Idx = 0 To grd_Offer.Rows - 1
    If (grd_Offer.Data(ll_Idx, "OFD_Main") = eDPCOfferDetailMain.odMain) And _
       (grd_Offer.Data(ll_Idx, "OFD_IsAlt") = eDPCOfferDetailIsAlt.maMain) Then
      If Round(grd_Offer.Data(ll_Idx, "OFD_TotalC"), 3) <= 0 Then
        lb_HasNoCost = True
      End If
      md_TotalCost = md_TotalCost + grd_Offer.Data(ll_Idx, "OFD_TotalC")
      md_TotalPrice = md_TotalPrice + grd_Offer.Data(ll_Idx, "OFD_TotalP")
    End If
  Next
  ' if any cost is 0, then do not calculate margin/discount
  If lb_HasNoCost Then
    md_OfferCost = 0
    md_OfferPrice = 0
  Else
    md_OfferCost = md_TotalCost
    md_OfferPrice = md_TotalPrice
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("CalculateOfferSummary")
End Sub

Private Sub CalculateExchangeRate(ByVal as_CURR_Code As String)
On Error GoTo ErrHandler

Dim ls_req As String
Dim lc_Cursor As Long
Dim ls_CURR_Code As String
Dim ld_ExchRate As Double
Dim lb_InTran As Boolean


  ls_req = "exec Cap_Offer_CURR_lst $COF_Id$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  If mo_Db.RowCount(lc_Cursor) > 0 Then
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateExchangeRate")
    lb_InTran = True
    
    ls_req = "UPDATE Cap_Offer SET CURR_Code=$CURR_Code$, Z_Last_Upd=getdate(), Z_Last_Upd_User=$U_Code$, iConcurrency=iConcurrency+1 WHERE COF_Id=$COF_Id$"
    ls_req = Replace(ls_req, "$CURR_Code$", mo_Tools.SQLStr(as_CURR_Code), , , vbTextCompare)
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
    
    Call mo_Db.First(lc_Cursor)
    While Not mo_Db.EOF(lc_Cursor)
      ls_CURR_Code = mo_Db.GetFields(lc_Cursor, "CURR_Code")
      ld_ExchRate = mo_Tools.SelectExchangeRate(mo_Db, ls_CURR_Code, as_CURR_Code, Now)
      
      ls_req = "exec Cap_OfferDetail_EXCH_upd $COF_Id$, $CURR_Code$, $OFD_Rate$, $U_Code$"
      ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
      ls_req = Replace(ls_req, "$CURR_Code$", mo_Tools.SQLStr(ls_CURR_Code), , , vbTextCompare)
      ls_req = Replace(ls_req, "$OFD_Rate$", mo_Tools.SqlDbl(ld_ExchRate), , , vbTextCompare)
      ls_req = ReplaceCommonPlaceholders(ls_req)
      Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
      
      Call mo_Db.Next(lc_Cursor)
    Wend
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateExchangeRate")
    lb_InTran = False
  End If
  Call mo_Db.Close(lc_Cursor)
  Exit Sub
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "CalculateExchangeRate")
  End If
  Call ErrorHandler("CalculateExchangeRate")
End Sub

Private Sub InitContactCombo(ByVal ao_Combo As ArmCombobox, ByVal as_SP_Capkey As String, ByVal as_CCU_Capkey As String)
On Error GoTo ErrHandler

Dim ls_Request As String

  Call cbo_Contact.Clear
  If cbo_Customer.SelectedItem Is Nothing Then
    cbo_Contact.Request = ""
  Else
    ls_Request = "exec Cap_Offer_Contact_cbo $SP_CapKey$,$CCU_CapKey$,$Language_Code$"
    ls_Request = Replace(ls_Request, "$CCU_CapKey$", mo_Tools.SQLStr(as_CCU_Capkey), , , vbTextCompare)
    ls_Request = Replace(ls_Request, "$SP_CapKey$", mo_Tools.SQLStr(as_SP_Capkey), , , vbTextCompare)
    ls_Request = Replace(ls_Request, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
    cbo_Contact.Request = ls_Request
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitContactCombo")
End Sub

Private Sub InitTemplateCombo(ByVal ao_Combo As ArmCombobox, ByVal as_CT_Code As String)
On Error GoTo ErrHandler

Dim ls_req As String

  Call cbo_Template.Clear
  If cbo_Customer.SelectedItem Is Nothing Then
    cbo_Template.Request = ""
  Else
    ls_req = "exec Cap_OfferTemplate_cbo $CT_Code$"
    ls_req = Replace(ls_req, "$CT_Code$", mo_Tools.SQLStr(as_CT_Code), , , vbTextCompare)
    ls_req = ReplaceCommonPlaceholders(ls_req)
    cbo_Template.Request = ls_req
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitTemplateCombo")
End Sub

Private Sub grd_Offer_DataLoaded(ByVal ab_FullDataLoaded As Boolean)
On Error GoTo ErrHandler
  
  'Call mo_Tools.LockScreen(Me, True)
  Call grd_Offer.SetAutoRowHeight("PRD_Name")
  'Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Offer_DataLoaded")
End Sub

Private Sub grd_Offer_ItemSelected()
On Error GoTo ErrHandler
    
  If ml_DisplayModeSubItem = mt_CstValues.DisplayMode_List Then
    Call tlb_Subitem_action("B", ms_Language_Code)
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Offer_ItemSelected")
End Sub

Private Sub grd_Offer_RowLoaded(ByVal al_Row As Long)
On Error GoTo ErrHandler

  If grd_Offer.Data(al_Row, "OFD_Main") = eDPCOfferDetailMain.odChild Then
    grd_Offer.Data(al_Row, "OFD_PriceMain") = ""
    grd_Offer.Data(al_Row, "OFD_TotalPMain") = ""
  End If
  If grd_Offer.Data(al_Row, "OFD_OrdNrB7") = "" Then
    grd_Offer.Data(al_Row, "OFD_PosB7") = ""
  End If
  If (grd_Offer.Data(al_Row, "OFD_SAPAct") = "") Then
  ElseIf (grd_Offer.Data(al_Row, "OFD_SAPAct") = "D") Or (grd_Offer.Data(al_Row, "OFD_SAPAct") = "K") Then
    grd_Offer.LineColor(al_Row) = vbRed
  ElseIf (grd_Offer.Data(al_Row, "OFD_SAPAct") = "R") Then
    grd_Offer.LineColor(al_Row) = vbYellow
  ElseIf (grd_Offer.Data(al_Row, "OFD_SAPAct") = "A") Then
    grd_Offer.LineColor(al_Row) = vbGreen
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_Offer_RowLoaded")
End Sub

Private Sub grd_PosList_RowLoaded(ByVal al_Row As Long)
On Error GoTo ErrHandler
  
  If grd_PosList.Data(al_Row, "RPL_PBord") = 0 Then
    grd_PosList.Data(al_Row, "RPL_UBorC") = ""
    grd_PosList.Data(al_Row, "RPL_UBorD") = ""
    grd_PosList.Data(al_Row, "RPL_UBorE") = ""
    grd_PosList.Data(al_Row, "RPL_UBorF") = ""
    grd_PosList.Data(al_Row, "RPL_UBoWC") = ""
    grd_PosList.Data(al_Row, "RPL_UBoWD") = ""
    grd_PosList.Data(al_Row, "RPL_UBoWE") = ""
    grd_PosList.Data(al_Row, "RPL_UBoWF") = ""
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("grd_PosList_RowLoaded")
End Sub

Private Sub grdLst_ItemSelected()
On Error GoTo ErrHandler
    
  Call mo_Tools.LockScreen(Me, True)
  If (grdlst.SelectedCount = 1) Then
    m_CurrentKey1 = grdlst.CurrentKey(0)
    DisplayMode = mt_CstValues.DisplayMode_View
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("grdLst_ItemSelected")
End Sub

' Get the root state
Public Property Get Root() As Boolean
On Error GoTo ErrorHandler
    
  Root = mb_Root

  Exit Property
ErrorHandler:
  Call ErrorHandler("Root.Get")
End Property

Public Property Let Root(ByVal ab_root As Boolean)
On Error GoTo ErrorHandler
    
  mb_Root = ab_root
  If mb_Root = True Then
      mi_EmbeddedIn = -1
  End If

  Exit Property
ErrorHandler:
  Call ErrorHandler("Root.Let")
End Property

Private Sub tbs_Header_Click()
On Error GoTo ErrHandler

Dim ll_Idx As Long

  Call mo_Tools.LockScreen(Me, True)
  For ll_Idx = 0 To fra_Header.Count - 1
    If ll_Idx < fra_Header.Count Then
      If StrComp(fra_Header(ll_Idx).Tag, tbs_Header.SelectedItem.Key, vbTextCompare) = 0 Then
        fra_Header(ll_Idx).Visible = True
        Call fra_Header(ll_Idx).Zorder
      Else
        fra_Header(ll_Idx).Visible = False
      End If
    End If
  Next
  If StrComp("fra_PosList", tbs_Header.SelectedItem.Key, vbTextCompare) = 0 Then
    Call tbs_PosList_Click
  ElseIf StrComp("fra_Header", tbs_Header.SelectedItem.Key, vbTextCompare) = 0 Then
    Call RefreshOfferDetail
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("tbs_Header_Click")
End Sub

Private Sub EnableInterfaceFunction()
On Error GoTo ErrHandler

Dim lb_Enabled As Boolean

  lb_Enabled = (StrComp("fra_PosList", tbs_PosList.SelectedItem.Key, vbTextCompare) = 0) And _
              mb_HasLevel2 And _
              (DisplayMode = mt_CstValues.DisplayMode_Update)
  
  btn_PosListEdit.Enabled = lb_Enabled
  cmd_MassEntry.Enabled = lb_Enabled
  btn_PosListCalcBOMBOR.Enabled = lb_Enabled
  btn_PosListClearBOMBOR.Enabled = lb_Enabled
  btn_GenerateGroupAndCE.Enabled = lb_Enabled
  cmd_RecalcCost.Enabled = lb_Enabled
  btn_RecalcPacking.Enabled = lb_Enabled
  btn_PrintPacking.Enabled = True
  btn_ChangeAttribute.Enabled = lb_Enabled
  
  lb_Enabled = (StrComp("fra_PosList", tbs_PosList.SelectedItem.Key, vbTextCompare) = 0) And _
              mb_HasLevel2 And _
              (DisplayMode = mt_CstValues.DisplayMode_View)
  
  cmd_ExportRawMaterial.Enabled = lb_Enabled
  btn_XmlPMaster.Enabled = lb_Enabled
  btn_XmlCust.Enabled = lb_Enabled
  btn_BaurerSecretBoxExport.Enabled = lb_Enabled
  btn_BaurerSecretBoxImport.Enabled = lb_Enabled
  btn_BaurerSecretBoxKill.Enabled = lb_Enabled
  cmd_KillOrderB7.Enabled = lb_Enabled
  btn_BaurerSalesOrderExport.Enabled = lb_Enabled
  btn_BaurerSOChangeExport.Enabled = lb_Enabled
  lb_Enabled = mb_HasLevel2 And _
              (DisplayMode = mt_CstValues.DisplayMode_View)
  btn_ExportMaterialCreate.Enabled = lb_Enabled
  btn_ExportSalesOrderCreate.Enabled = lb_Enabled
  btn_ExportSalesOrderCreateSim.Enabled = lb_Enabled
  btn_ExportSalesOrderCancelAddReplace.Enabled = lb_Enabled
  btn_ExportActionAdd.Enabled = lb_Enabled
  btn_ExportActionDelete.Enabled = lb_Enabled
  btn_ExportActionReplace.Enabled = lb_Enabled
  btn_ExportActionReset.Enabled = lb_Enabled
  btn_ExportActionDeleteCancelPrereservation.Enabled = lb_Enabled
  cmd_Info.Enabled = True

  Exit Sub
ErrHandler:
  Call ErrorHandler("EnableInterfaceFunction")
End Sub

Private Sub tbs_PosList_Click()

  Call mo_Tools.LockScreen(Me, True)
  Call EnableInterfaceFunction
  
  grd_PosList.Visible = False
  grd_Packing.Visible = False
  grd_BOM.Visible = False
  grd_BOR.Visible = False
  grd_Cost.Visible = False
  chk_PosListSelectAll.Visible = False
  
  If StrComp("fra_PosList", tbs_PosList.SelectedItem.Key, vbTextCompare) = 0 Then
    grd_PosList.Visible = True
    chk_PosListSelectAll.Visible = True
    Call RefreshPosList
    If grd_PosList.Rows > 0 Then
      grd_PosList.Row = grd_PosList.Rows - 1
    End If
  ElseIf StrComp("fra_Packing", tbs_PosList.SelectedItem.Key, vbTextCompare) = 0 Then
    grd_Packing.Visible = True
    Call RefreshPacking
  ElseIf StrComp("fra_BOM", tbs_PosList.SelectedItem.Key, vbTextCompare) = 0 Then
    grd_BOM.Visible = True
    Call RefreshBOM
  ElseIf StrComp("fra_BOR", tbs_PosList.SelectedItem.Key, vbTextCompare) = 0 Then
    grd_BOR.Visible = True
    Call RefreshBOR
  ElseIf StrComp("fra_Cost", tbs_PosList.SelectedItem.Key, vbTextCompare) = 0 Then
    grd_Cost.Visible = True
    Call RefreshCost
  End If
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("tbs_PosList_Click")
End Sub

Private Sub tlb_Item_action(ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler

Dim lb_Result   As Boolean
Dim ls_auxStr   As String
Dim ls_serialStr As String
Dim ls_Request As String
Dim le_NewOfferStatus As eOfferStatus
Dim ls_NewOfferStatusDesc As String

  Call mo_Tools.LockScreen(Me, True)
    
  Select Case as_Role
  Case "A"
    CurrentKey = ""
    DisplayMode = mt_CstValues.DisplayMode_Add
  
  Case "B"
    If m_CurrentKey1 <> "" Then
      If CanUpdateOffer(m_Project, m_CurrentKey1) Then
        DisplayMode = mt_CstValues.DisplayMode_Update
      Else
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9705, "#You cannot update this offer")
      End If
    End If
  
  Case "C"
    If m_CurrentKey1 <> "" Then
      If CanDeleteOffer(m_Project, m_CurrentKey1) Then
          DisplayMode = mt_CstValues.DisplayMode_Delete
      Else
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9706, "#You cannot delete this offer")
      End If
    End If
  
  Case "m"
    If CanPriceMgrOffer(m_Project, m_CurrentKey1) Then
      Call ItemPriceManager
      Call ReleaseOfferLock(m_CurrentKey1)
    End If
  
  Case "D"
      If CanSendOffer(m_CurrentKey1) Then
          Call PrintOffer(m_CurrentKey1, False)
      End If
      
  Case "G"
      If CanSendOffer(m_CurrentKey1) Then
          Call ExportExcelOffer(m_CurrentKey1)
      End If
'  Case "Mail"
'    If m_CurrentKey1 <> "" Then
'      Debug.Assert (Not cbo_Status.SelectedItem Is Nothing)
'      If StrComp(PrintOfferPreview(m_CurrentKey1, False, ls_serialStr), "Valid", vbTextCompare) = 0 Then
'          Call MailOffer(m_CurrentKey1, Status, ls_serialStr, False)
'      End If
'    End If
'
'  Case "Fax"
'    If m_CurrentKey1 <> "" Then
'      Debug.Assert (Not cbo_Status.SelectedItem Is Nothing)
'      If StrComp(PrintOfferPreview(m_CurrentKey1, False, ls_serialStr), "Valid", vbTextCompare) = 0 Then
'          Call FaxOffer(m_CurrentKey1, Status, ls_serialStr, False)
'      End If
'    End If
  
  Case "X"
    If m_CurrentKey1 <> "" And CanAddOffer(m_Project) Then
      If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9708, "#Are you sure you want to copy selected offer to new version ?", , vbYesNo) = vbYes Then
        Call CopyOffer(m_CurrentKey1)
      End If
    End If
  
  Case "T"
    If (DisplayMode = mt_CstValues.DisplayMode_Update) Or (DisplayMode = mt_CstValues.DisplayMode_Delete) Then
      Call ReleaseOfferLock(m_CurrentKey1)
    End If
    If mi_EmbedTag <> -1 Then
        RaiseEvent Release
        mi_EmbedTag = -1
    End If
    
    DisplayMode = mt_CstValues.DisplayMode_List
      
  Case "H"
    lb_Result = False
    Select Case DisplayMode
        Case mt_CstValues.DisplayMode_Add
            lb_Result = RecordAdd
        Case mt_CstValues.DisplayMode_Update
            lb_Result = RecordUpdate(m_CurrentKey1)
        Case mt_CstValues.DisplayMode_Delete
            lb_Result = RecordDelete(m_CurrentKey1)
    End Select
    If lb_Result Then
        'Call RefreshGridSafe(grdlst)
        If DisplayMode = mt_CstValues.DisplayMode_Add Then
          Call grdlst.SearchKey(True, m_CurrentKey1)
        ElseIf (DisplayMode = mt_CstValues.DisplayMode_Update) Or (DisplayMode = mt_CstValues.DisplayMode_Delete) Then
          Call ReleaseOfferLock(m_CurrentKey1)
        End If
        DisplayMode = mt_CstValues.DisplayMode_List
    End If
      
  Case "I"
    BlankFields
    'DisplayMode = mt_CstValues.DisplayMode_List
    If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
        AddInitFields
    Else
        ViewInitFields
    End If
      
  Case "J"
    If IsProduction Then
      RaiseEvent OfferGridMove(-1)
    Else
      If grdlst.Row = 0 Then
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 927, "#No more previous item.")
      Else
        grdlst.Row = grdlst.Row - 1
        m_CurrentKey1 = grdlst.CurrentKey(0)
        BlankFields
        ViewInitFields
      End If
    End If
  Case "K"
    If IsProduction Then
      RaiseEvent OfferGridMove(1)
    Else
      If grdlst.Row = grdlst.Rows - 1 And grdlst.AllDataLoaded = True Then
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 928, "#No more next item.")
      Else
        grdlst.Row = grdlst.Row + 1
        m_CurrentKey1 = grdlst.CurrentKey(0)
        BlankFields
        ViewInitFields
      End If
    End If
  Case "q"
    le_NewOfferStatus = GetNextOfferStatus(Status)
    Call ChangeOfferStatus(Status, le_NewOfferStatus)
    'If Status = eOfferStatus.osOfferDefinition Then
    '  le_NewOfferStatus = eOfferStatus.osPlanningProcess
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9709, "#Are you sure to move offer to Baeurer and planning process ?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osPlanningProcess
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf Status = eOfferStatus.osOfferNeedApproval Then
    '  le_NewOfferStatus = eOfferStatus.osUnderApprovalProcess
    
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9710, "#Are you sure to move offer to approval process ?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osUnderApprovalProcess
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf (Status = eOfferStatus.osUnderApprovalProcess) Or (Status = eOfferStatus.osApproved) Then
    '  le_NewOfferStatus = eOfferStatus.osPlanningProcess
      
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9711, "#Are you sure to approve offer and move to planning process ?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osPlanningProcess
      '  cal_COF_ApDat.date_courte = Format(Now, "dd\/mm\/yyyy")
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf (Status = eOfferStatus.osPlanningProcess) Then
    '  le_NewOfferStatus = eOfferStatus.osWaitCustConfirmation
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Are you sure to move offer to status Wait customer confirmation ?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osWaitCustConfirmation
      '  cal_COF_ApDat.date_courte = Format(Now, "dd\/mm\/yyyy")
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf Status = eOfferStatus.osWaitCustConfirmation Then
      'le_NewOfferStatus = eOfferStatus.osSAPSalesOrder
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9712, "#Are you sure to create order and move to SAP ?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osSAPSalesOrder
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf Status = eOfferStatus.osSAPSalesOrderChange Then
      'le_NewOfferStatus = eOfferStatus.osSAPSalesOrder
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Are you sure to send changed sales order ?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osSAPSalesOrder
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf Status = eOfferStatus.osBaeurerSalesOrderChange Then
      'le_NewOfferStatus = eOfferStatus.osBaeurerSalesOrder
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Are you sure to send changed sales order ?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osBaeurerSalesOrder
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'End If
    'If le_NewOfferStatus <> eOfferStatus.osNone Then
    '  ls_NewOfferStatusDesc = mo_Tools.GetAReferenceData(eDPCReferenceML.rfOfferStatus, le_NewOfferStatus, ms_Language_Code)
    '  If mo_Tools.HasSecurityAlias(ms_LoginName, "CAP_OFFERSTATUS" & le_NewOfferStatus) Then
    '    If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9742, "#Are you sure to move offer to status $OfferStatusDesc$ ?", , Array("$OfferStatusDesc$", ls_NewOfferStatusDesc), vbYesNo) = vbYes Then
    '      Status = le_NewOfferStatus
    '      Call DisplayProcessButtons
    '    End If
    '  Else
    '    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9743, "#You do not have rights to move offer to status: $OfferStatusDesc$", Array("$OfferStatusDesc$", ls_NewOfferStatusDesc))
    '  End If
    'End If
  Case "r"
    le_NewOfferStatus = GetPrevOfferStatus(Status)
    Call ChangeOfferStatus(Status, le_NewOfferStatus)
    'If (Status = eOfferStatus.osUnderApprovalProcess) Or (Status = eOfferStatus.osApproved) Then
    '  le_NewOfferStatus = eOfferStatus.osRejected
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9713, "#Are you sure to reject offer ?", , vbYesNo) = vbYes Then
      '  Call cbo_Status.SearchItem(eOfferStatus.osRejected)
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf (Status = eOfferStatus.osPlanningProcess) Then
    '  le_NewOfferStatus = eOfferStatus.osOfferDefinition
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Are you sure to move offer to status offer definition ?", , vbYesNo) = vbYes Then
      '  Call cbo_Status.SearchItem(eOfferStatus.osOfferDefinition)
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf Status = eOfferStatus.osWaitCustConfirmation Then
    '  le_NewOfferStatus = eOfferStatus.osDropped
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9714, "#Are you sure to drop offer by customer ?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osDropped
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf Status = eOfferStatus.osSAPSalesOrder Then
    '  le_NewOfferStatus = eOfferStatus.osSAPSalesOrderChange
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Are you sure to allow Sales order change?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osSAPSalesOrderChange
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'ElseIf Status = eOfferStatus.osBaeurerSalesOrder Then
    '  le_NewOfferStatus = eOfferStatus.osBaeurerSalesOrderChange
      'If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "#Are you sure to allow Sales order change?", , vbYesNo) = vbYes Then
      '  Status = eOfferStatus.osBaeurerSalesOrderChange
      '  Call RecordUpdate(m_CurrentKey1)
      'End If
    'End If
  Case Else
      Err.Raise ArmErr.InvalidArgument, "as_Role", "Invalid role: " & as_Role
  End Select
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Select Case Err.Number
  Case ArmErr.SQLBadRowExpectedCount
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2138, "#The record you try to open has been deleted by an other user. Please refresh the grid.", , vbInformation)
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
  Case ArmErr.SQLBadRowAffectedCount
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 916, "#This data has been updated by another user. Data will be reloaded. Please check the data and try again.", , vbInformation)
      ViewInitFields
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
  End Select
  Call ErrorMessage("tlb_Item_action")
End Sub

Private Function GetNextOfferStatus(ByVal as_OldOfferStatus As eOfferStatus) As eOfferStatus
On Error GoTo ErrHandler

  GetNextOfferStatus = eOfferStatus.osNone
  If as_OldOfferStatus = eOfferStatus.osNew Then
    GetNextOfferStatus = eOfferStatus.osPlanningProcess
  ElseIf as_OldOfferStatus = eOfferStatus.osOfferDefinition Then
    GetNextOfferStatus = eOfferStatus.osPlanningProcess
  ElseIf as_OldOfferStatus = eOfferStatus.osOfferNeedApproval Then
    GetNextOfferStatus = eOfferStatus.osPlanningProcess
  ElseIf (as_OldOfferStatus = eOfferStatus.osUnderApprovalProcess) Or (as_OldOfferStatus = eOfferStatus.osApproved) Then
    GetNextOfferStatus = eOfferStatus.osPlanningProcess
  ElseIf (as_OldOfferStatus = eOfferStatus.osPlanningProcess) Then
    GetNextOfferStatus = eOfferStatus.osWaitCustConfirmation
  ElseIf (as_OldOfferStatus = eOfferStatus.osBaeurerSalesOrderChange) Then
    GetNextOfferStatus = eOfferStatus.osBaeurerSalesOrder
  ElseIf (as_OldOfferStatus = eOfferStatus.osSAPSalesOrder) Then
    GetNextOfferStatus = eOfferStatus.osSAPChangedAfterSO
  End If
  Exit Function
ErrHandler:
  Call ErrorHandler("GetNextOfferStatus")
End Function

Private Function GetPrevOfferStatus(ByVal as_OldOfferStatus As eOfferStatus) As eOfferStatus
On Error GoTo ErrHandler

  GetPrevOfferStatus = eOfferStatus.osNone
  If (as_OldOfferStatus = eOfferStatus.osUnderApprovalProcess) Or (as_OldOfferStatus = eOfferStatus.osApproved) Then
    GetPrevOfferStatus = eOfferStatus.osRejected
  ElseIf (as_OldOfferStatus = eOfferStatus.osPlanningProcess) Then
    GetPrevOfferStatus = eOfferStatus.osOfferDefinition
  ElseIf (as_OldOfferStatus = eOfferStatus.osDropped) Then
    GetPrevOfferStatus = eOfferStatus.osOfferDefinition
  ElseIf as_OldOfferStatus = eOfferStatus.osWaitCustConfirmation Then
    GetPrevOfferStatus = eOfferStatus.osDropped
  ElseIf as_OldOfferStatus = eOfferStatus.osSAPSalesOrder Then
    GetPrevOfferStatus = eOfferStatus.osSAPSalesOrderChange
  ElseIf as_OldOfferStatus = eOfferStatus.osBaeurerSalesOrder Then
    GetPrevOfferStatus = eOfferStatus.osBaeurerSalesOrderChange
  End If
  Exit Function
ErrHandler:
  Call ErrorHandler("GetPrevOfferStatus")
End Function

Private Sub ChangeOfferStatus(ByVal ae_OldOfferStatus As eOfferStatus, ByVal ae_NewOfferStatus As eOfferStatus)
On Error GoTo ErrHandler

Dim ls_NewOfferStatusDesc As String
Dim ls_req As String

    If ae_NewOfferStatus <> eOfferStatus.osNone Then
      ls_NewOfferStatusDesc = mo_Tools.GetAReferenceData(eDPCReferenceML.rfOfferStatus, ae_NewOfferStatus, ms_Language_Code)
      If mo_Tools.HasSecurityAlias(ms_LoginName, "CAP_OFFERSTATUS" & ae_OldOfferStatus & "_" & ae_NewOfferStatus) Then
        If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9742, "#Are you sure to move offer to status $OfferStatusDesc$ ?", Array("$OfferStatusDesc$", ls_NewOfferStatusDesc), vbYesNo) = vbYes Then
          If GetOfferLock(m_CurrentKey1, True) Then
            ls_req = "exec Cap_Offer_upd4 $COF_Id$, $COF_Stat$, $Z_Last_Upd_User$"
            ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
            ls_req = Replace(ls_req, "$COF_Stat$", mo_Tools.SqlInt(ae_NewOfferStatus), , , vbTextCompare)
            ls_req = ReplaceCommonPlaceholders(ls_req)
            Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
            Status = ae_NewOfferStatus
            Call GridUpdate(True)
            Call DisplayProcessButtons
            Call ReleaseOfferLock(m_CurrentKey1)
          End If
        End If
      Else
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9743, "#You do not have rights to move offer to status: $OfferStatusDesc$", Array("$OfferStatusDesc$", ls_NewOfferStatusDesc))
      End If
    End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("ChangeOfferStatus")
End Sub

Private Sub tlb_Main_action(ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler

Dim ls_serialStr As String

  Call mo_Tools.LockScreen(Me, True)
  
  Select Case as_Role
  
  Case "A"
    CurrentKey = ""
    Call BlankFields
    If CanAddOffer(m_Project) Then
        DisplayMode = mt_CstValues.DisplayMode_Add
    End If
      
  Case "B"
    If (grdlst.SelectedCount = 1) Then
      CurrentKey = grdlst.CurrentKey(0)
      If CanUpdateOffer(m_Project, m_CurrentKey1) Then
        DisplayMode = mt_CstValues.DisplayMode_Update
      Else
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9705, "#You cannot update this offer")
      End If
    End If
      
  Case "C"
    If (grdlst.SelectedCount = 1) Then
      CurrentKey = grdlst.CurrentKey(0)
      If CanDeleteOffer(m_Project, m_CurrentKey1) Then
          DisplayMode = mt_CstValues.DisplayMode_Delete
      Else
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9706, "#You cannot delete this offer")
      End If
    End If
  
  Case "F"
      grdlst.Refresh
      
  Case "D"
    If (grdlst.SelectedCount = 1) Then
      CurrentKey = grdlst.CurrentKey(0)
      If CanSendOffer(m_CurrentKey1) Then
          Call PrintOffer(m_CurrentKey1, False)
      End If
    End If
  
  Case "G"
    If (grdlst.SelectedCount = 1) Then
      CurrentKey = grdlst.CurrentKey(0)
      If CanSendOffer(m_CurrentKey1) Then
          Call ExportExcelOffer(m_CurrentKey1)
      End If
    End If
    
  Case "X"
    If (grdlst.SelectedCount = 1) Then
      CurrentKey = grdlst.CurrentKey(0)
      If CanAddOffer(m_Project) Then
        If mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9708, "#Are you sure you want to copy selected offer to new version ?", , vbYesNo) = vbYes Then
          Call CopyOffer(m_CurrentKey1)
        End If
      End If
    End If
  Case "m"
    If (grdlst.SelectedCount = 1) Then
      CurrentKey = grdlst.CurrentKey(0)
      If CanPriceMgrOffer(m_Project, m_CurrentKey1) Then
        Call ItemPriceManager
        Call ReleaseOfferLock(m_CurrentKey1)
      End If
    End If
  Case "T"
    Call mo_Tools.LockScreen(Me, False)
    RaiseEvent quit
    Exit Sub
  Case Else
    Err.Raise ArmErr.InvalidArgument, "as_Role", "Invalid role: " & as_Role
  End Select
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("tlb_Main_action")
End Sub

Private Sub btn_PrintPacking_Click()
On Error GoTo ErrHandler
  
  Call mo_Tools.LockScreen(Me, True)
  Call PrintOfferPacking(m_CurrentKey1, Status, False)
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("btn_PrintPacking_Click")
End Sub


Private Sub View_EnableControls()
On Error GoTo ErrHandler
  
  Call mo_Tools.EnableFrame(UserControl.Controls, fraItemTop, False)
  Call mo_Tools.EnableFrame(UserControl.Controls, fraItemBottom, False)
  Call mo_Tools.EnableFrame(UserControl.Controls, fra_PosListFilter, True)
  Call EnableInterfaceFunction
  tlb_Subitem.Enabled = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("View_EnableControls")
End Sub

Sub Add_Enablecontrols()
On Error GoTo ErrHandler
    
  Call mo_Tools.EnableFrame(UserControl.Controls, fraItemTop, True)
  Call mo_Tools.EnableFrame(UserControl.Controls, fraItemBottom, False)
  Call mo_Tools.EnableFrame(UserControl.Controls, fra_Header(6), False)
  
  Call EnableInterfaceFunction
  Call mo_Tools.EnableControl(txt_SP_Desc, False)
  Call mo_Tools.EnableControl(txt_COF_ID, False)
  Call mo_Tools.EnableControl(txt_COF_Code, False)
  Call mo_Tools.EnableControl(txt_Version, False)
  Call mo_Tools.EnableControl(cbo_Status, False)
  Call mo_Tools.EnableControl(cbo_Level, False)
  Call mo_Tools.EnableControl(cal_COF_ApDat, False)
  Call mo_Tools.EnableControl(txt_OfferMargin, False)
  Call mo_Tools.EnableControl(cal_COF_DocDat, False)
  'Call mo_Tools.SetTextEnabled(txt_Textbox, "COF_Bae_Konto", False)
  Call mo_Tools.SetTextEnabled(txt_Textbox, "COF_CodeBae", False)
  Call mo_Tools.SetTextEnabled(txt_Textbox, "SP_CapKey", False)
  Exit Sub
ErrHandler:
  Call ErrorHandler("Add_Enablecontrols")
End Sub

Sub Update_EnableControls()
On Error GoTo ErrHandler
    
  Call mo_Tools.EnableFrame(UserControl.Controls, fraItemTop, True)
  Call mo_Tools.EnableFrame(UserControl.Controls, fraItemBottom, False)
  Call mo_Tools.EnableFrame(UserControl.Controls, fra_Header(6), False)
  
  Call EnableInterfaceFunction
  Call mo_Tools.EnableControl(txt_SP_Desc, False)
  Call mo_Tools.EnableControl(txt_COF_ID, False)
  Call mo_Tools.EnableControl(txt_COF_Code, False)
  Call mo_Tools.EnableControl(txt_Version, False)
  Call mo_Tools.EnableControl(cbo_Status, False)
  Call mo_Tools.EnableControl(cbo_Level, False)
  Call mo_Tools.EnableControl(cal_COF_ApDat, False)
  Call mo_Tools.EnableControl(txt_OfferMargin, False)
  Call mo_Tools.EnableControl(cbo_Template, (Not (cbo_Customer.SelectedItem Is Nothing)))
  'Call mo_Tools.EnableControl(cal_COF_DocDat, False)
  'Call mo_Tools.SetTextEnabled(txt_Textbox, "COF_Bae_Konto", False)
  Call mo_Tools.SetTextEnabled(txt_Textbox, "COF_CodeBae", False)
  Call mo_Tools.SetTextEnabled(txt_Textbox, "SP_CapKey", False)
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("Update_EnableControls")
End Sub

Sub UpdateInitFields()
On Error GoTo ErrHandler
    
  'idem
  ViewInitFields
  
  ' update UI according to selected data
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateInitFields")
End Sub


Private Sub InitControl(Optional aMode As Long = 0)
On Error GoTo ErrHandler
Dim ConnectData As Variant
   
   
  Select Case aMode
      Case 0
  'If No mode then exit
          Exit Sub
  
      Case 1
  'If already initialized then exit
      If mi_TypeList <> 1 Then
          mi_TypeList = 1
      Else
          'tlb_Main.PictureDisplayed = "P_Quit=-1"
          Exit Sub
      End If
      Case 2
      If mi_TypeList <> 1 And mi_TypeList <> 2 Then
          mi_TypeList = 2
      End If
  End Select
  
  UserControl.ScaleMode = 1
  
  'Object unvisble
  ObjectVisible False
  
  Select Case aMode
      Case 3
  
'          tlb_Item.PictureDisplayed = "P_Update=2 P_Previous=4 P_Next=5 P_OpGT=7 P_OpLT=8 P_Print=10 P_Copy=11 P_Quit=-1"
  
      Case 4
  
      'Toolbar
'      tlb_Item.ClearAllIcons
'      tlb_Item.PictureDisplayed = "P_Valid=1 P_UnDo=2 P_OpGT=7 P_OpLT=8 P_Quit=-1"
  End Select
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitControl")
End Sub
Private Sub ObjectVisible(Optional aVisible As Boolean = True)
On Error GoTo ErrHandler
    
  UserControl.fraItem.Visible = aVisible
  UserControl.fraList.Visible = aVisible
  Exit Sub
ErrHandler:
  Call ErrorHandler("ObjectVisible")
End Sub

Public Sub FrameWorkInit(ByRef lt_CstValues As type_CstValues, ByVal ls_InstanceName As String, Optional ATypeList As Long = 0)
On Error GoTo ErrHandler
    
  'Restriction of initialsation
  mi_TypeParam = ATypeList
      
  Set mt_CstValues = lt_CstValues
  
  mi_CptTag = mt_CstValues.Tag_Offer
  
  ' Add the tabulation for the embedded controls
  With UserControl
    .ScaleMode = 1
    .tbsEmbedded.Tabs.Clear
    .tbsEmbedded.TabFixedWidth = 150
    Dim lt_Tab As Object
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Project", "#Project")
    lt_Tab.Tag = mt_CstValues.Tag_Project
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Action", "#Action")
    lt_Tab.Tag = mt_CstValues.Tag_Action
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Customer", "#Customer")
    lt_Tab.Tag = mt_CstValues.Tag_Customer
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Contact", "#Contact")
    lt_Tab.Tag = mt_CstValues.Tag_Contact
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Product", "#Product")
    lt_Tab.Tag = mt_CstValues.Tag_Product
    Set lt_Tab = Nothing
    Set lt_Tab = .tbsEmbedded.Tabs.Add(.tbsEmbedded.Tabs.Count + 1, "Memo", "#Memo")
    lt_Tab.Tag = mt_CstValues.Tag_Memo
    Set lt_Tab = Nothing
  End With
  
  mi_DisplayMode = mt_CstValues.DisplayMode_None
  mi_OldDisplayMode = mi_DisplayMode
  Exit Sub
ErrHandler:
  Call ErrorHandler("FrameWorkInit")
End Sub

' Properties for let application access to critical data
Public Property Get CptTag()
    
  CptTag = mi_CptTag
End Property

' Give the tag of the component which embed this instance
Public Property Get EmbeddedIn() As Long
    
  EmbeddedIn = mi_EmbeddedIn
End Property

' Give the tag of the component embed by this
Public Property Get EmbedTag() As Long
    
  EmbedTag = mi_EmbedTag
End Property

' Give the actual display mode
Public Property Get DisplayMode() As Long
    
  DisplayMode = mi_DisplayMode
End Property

' Change the actual display mode
Public Property Let DisplayMode(ByVal li_DisplayMode As Long)
    
  SwapToDisplayMode li_DisplayMode
End Property

' when a component embed this instance
Public Sub CatchBy(ByVal li_TagCaller, ByVal ls_Params As String)
On Error GoTo ErrHandler
    
  mi_EmbeddedIn = li_TagCaller
  mb_Root = False
  mi_EmbedTag = -1
  
  If mi_EmbeddedIn <> -1 Then
      ' When a component is embedded, it always appears in short list
      SwapToDisplayMode mt_CstValues.DisplayMode_List, ls_Params
  End If
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("CatchBy")
End Sub

' Change the display mode
Private Sub SwapToDisplayMode(li_DisplayMode As Long, Optional ls_Params As String = "")
On Error GoTo ErrHandler
  
  mi_OldDisplayMode = mi_DisplayMode
  
  'When a component is root, it can't select the list mode
  If mb_Root And (li_DisplayMode = mt_CstValues.DisplayMode_List) And (EmbeddedIn = -1) Then
      li_DisplayMode = mt_CstValues.DisplayMode_View
  End If
  mi_DisplayMode = li_DisplayMode
  
  'We should hide all graphics frames before resize and move it
  DisplayMode_None
  
  Select Case mi_DisplayMode
  Case mt_CstValues.DisplayMode_List
      'the component is embedded
      ShortListDisplay ls_Params
  
  Case mt_CstValues.DisplayMode_View
          ViewDisplay
      
  Case mt_CstValues.DisplayMode_Update
          UpdateDisplay
      
  Case mt_CstValues.DisplayMode_Add
          AddDisplay
      
  Case mt_CstValues.DisplayMode_Delete
          DeleteDisplay
  End Select
  
  Exit Sub
ErrHandler:
  mb_InternalInit = False
  Call ErrorHandler("SwapToDisplayMode")
End Sub

' Hide all graphics elements
Private Sub DisplayMode_None()
On Error GoTo ErrHandler
    
  With UserControl
    .fraItem.Visible = False
    .fraList.Visible = False
   End With
   Exit Sub
ErrHandler:
   Call ErrorHandler("DisplayMode_None")
End Sub

Private Sub ViewLoad()
End Sub

Private Sub ShortListDisplay(ByVal ls_Params As String)
On Error GoTo ErrHandler
    
 RaiseEvent SwitchToView(mt_CstValues.View_Embedded)

 ShortList_Resize
     
 Exit Sub
ErrHandler:
 Call ErrorHandler("ShortListDisplay")
End Sub

Private Function ItemPriceManager() As Boolean
On Error GoTo ErrHandler

Dim lo_frmDPC_PriceMgr As frmDPC_PriceMgr

  ItemPriceManager = False
  Set lo_frmDPC_PriceMgr = New frmDPC_PriceMgr
  Load lo_frmDPC_PriceMgr
  Set lo_frmDPC_PriceMgr.Tools = mo_Tools
  Set lo_frmDPC_PriceMgr.ArmDb = mo_Db
  lo_frmDPC_PriceMgr.Language_Code = ms_Language_Code
  lo_frmDPC_PriceMgr.COF_Id = CurrentKey(1)
  lo_frmDPC_PriceMgr.SP_CapKey = m_Project
  lo_frmDPC_PriceMgr.U_Code = ml_U_Code
  lo_frmDPC_PriceMgr.LoginName = ms_LoginName
  Call lo_frmDPC_PriceMgr.Load_A_COM
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_frmDPC_PriceMgr)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_frmDPC_PriceMgr.Result Then
    ItemPriceManager = True
    Call RefreshOfferDetail
  End If
  
  Call lo_frmDPC_PriceMgr.Unload_A_COM
  Unload lo_frmDPC_PriceMgr
  Exit Function
ErrHandler:
  Call ErrorHandler("ItemPriceManager")
End Function

Private Sub InitVendorCombo(ByVal ao_Combo As ArmCombobox)
On Error GoTo ErrHandler

  Dim ls_Request As String
  ls_Request = "exec DPC_Vendor_SAP_View_lst $LEN_Id$, $COF_Lang$"
  ls_Request = Replace(ls_Request, "$LEN_Id$", mo_Tools.SqlInt(mo_Tools.GetComboKey(cbo_LegalEntity)), , , vbTextCompare)
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  ao_Combo.Request = ls_Request
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitVendorCombo")
End Sub

Private Sub InitShipPointCombo(ByVal ao_Combo As ArmCombobox)
On Error GoTo ErrHandler

  Dim ls_Request As String
  ls_Request = "exec DPC_ShipPoint_SAP_View_lst $LEN_Id$, $VEN_Id$, $COF_Lang$"
  ls_Request = Replace(ls_Request, "$LEN_Id$", mo_Tools.SqlInt(mo_Tools.GetComboKey(cbo_LegalEntity)), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$VEN_Id$", mo_Tools.SQLStr(mo_Tools.GetComboKey(cbo_Vendor)), , , vbTextCompare)
  ls_Request = ReplaceCommonPlaceholders(ls_Request)
  ao_Combo.Request = ls_Request
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitShipPointCombo")
End Sub

Private Sub InitUnitOfMeasureCombo(ByVal ao_Combo As ArmCombobox)
On Error GoTo ErrHandler

  Dim ls_req As String
  
  ls_req = "exec DPC_Unit_Of_Measure_cbo2 $COF_Lang$"
  ls_req = ReplaceCommonPlaceholders(ls_req)
  ao_Combo.Request = ls_req
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitUnitOfMeasureCombo")
End Sub

Private Sub InitUserCombo(ByVal ao_Combo As ArmCombobox, ByVal as_Alias As String)
On Error GoTo ErrHandler

  Dim ls_req As String
  
  ls_req = _
    "SELECT DISTINCT GSU.U_Code,GSU.U_Login_Name " & _
    "FROM GEN_Systems_Users GSU " & _
    "INNER JOIN security_alias SA ON (GSU.U_Login_Name=SA.Login_Name) " & _
    "WHERE ((SA.Alias=$Alias$) OR ($Alias$='')) AND " & _
    "(GSU.Drop_Flag='N') AND " & _
    "(GSU.U_Login_Name<>'') " & _
    "ORDER BY GSU.U_Login_Name" ':todo remove empty and dropped,  sort alfabetically

  ls_req = Replace(ls_req, "$Alias$", mo_Tools.SQLStr(as_Alias), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  ao_Combo.Request = ls_req
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitUserCombo")
End Sub

Private Sub InitOfferDetailStockCapture(ByVal ao_OfferPos As DPC_OfferPos)
On Error GoTo ErrHandler

  Call ao_OfferPos.Init(0, 0, eDPCQtyType.qtUnknown, 0, 0, 0)
  ao_OfferPos.COF_Id = m_CurrentKey1
  ao_OfferPos.LEN_Id = mo_Tools.GetComboKey(cbo_LegalEntity)
  ao_OfferPos.OFD_Main = eDPCOfferDetailMain.odMain
  ao_OfferPos.OFD_Id = ""
  ao_OfferPos.OFD_IdPar = ""
  ao_OfferPos.Language_Code = "E"
  ao_OfferPos.OFD_Type = eDPCPriceBookType.eStockCapture
  ao_OfferPos.OFD_TypeDesc = ""
  ao_OfferPos.OFD_IsAlt = 0
  ao_OfferPos.OFD_AltPa = ""
  ao_OfferPos.OFD_AltPaName = ""
  ao_OfferPos.PRD_Id = ""
  ao_OfferPos.PRD_Code = ""
  ao_OfferPos.PRD_CodeC = ""
  ao_OfferPos.OFD_PosCus = ""
  ao_OfferPos.PRD_Name = ""
  ao_OfferPos.PRD_Desc = ""
  ao_OfferPos.LEV_Id = eDPCLevel.lvStandard
  ao_OfferPos.ERR_Type = eDPCErrorType.etNone
  ao_OfferPos.DOF_Id = eDPCOfferDetail.odPosition
  ao_OfferPos.CAT_Id = eDPCCategory.cgCaptureSystemItem
  ao_OfferPos.OFD_WshDat = cal_COF_WshDat.date_dt
  ao_OfferPos.OFD_ShpDat = cal_COF_ShpDat.date_dt
  ao_OfferPos.OFD_DelDat = cal_COF_DelDat.date_dt
  ao_OfferPos.OFD_Valid = True
  ao_OfferPos.OFD_Found = 0
  ao_OfferPos.S_Code = ""
  ao_OfferPos.OFD_Rate = 1
  ao_OfferPos.CURR_Code = mo_Tools.GetComboKey(cbo_currencies)
  ao_OfferPos.OFD_HasPrice = True
  ao_OfferPos.OFD_HasQty = True
  ao_OfferPos.OFD_HasTotal = True
  ao_OfferPos.OFD_SAPAct = ""
  'Call ao_OfferPos.LoadVendor(mo_Db, CT_Code)
  'Call ao_OfferPos.LoadShipPoint(mo_Db, CT_Code)
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitOfferDetailStockCapture")
End Sub

Private Sub InitOfferDetail(ByVal ao_OfferPos As DPC_OfferPos)
On Error GoTo ErrHandler

  Call ao_OfferPos.Init(0, 0, eDPCQtyType.qtUnknown, 0, 0, 0)
  ao_OfferPos.COF_Id = m_CurrentKey1
  ao_OfferPos.LEN_Id = mo_Tools.GetComboKey(cbo_LegalEntity)
  ao_OfferPos.SAE_Id = 0
  ao_OfferPos.SHP_Id = 0
  ao_OfferPos.VEN_Id = ""
  ao_OfferPos.SAE_Name = ""
  ao_OfferPos.SHP_Name = ""
  ao_OfferPos.VEN_Name = ""
  ao_OfferPos.OFD_Main = eDPCOfferDetailMain.odMain
  ao_OfferPos.OFD_Id = ""
  ao_OfferPos.OFD_IdPar = ""
  ao_OfferPos.Language_Code = "E"
  ao_OfferPos.OFD_Type = eDPCPriceBookType.eUnknown
  ao_OfferPos.OFD_TypeDesc = ""
  ao_OfferPos.OFD_IsAlt = 0
  ao_OfferPos.OFD_AltPa = ""
  ao_OfferPos.OFD_AltPaName = ""
  ao_OfferPos.PRD_Id = ""
  ao_OfferPos.PRD_Code = ""
  ao_OfferPos.PRD_CodeC = ""
  ao_OfferPos.PRD_Name = ""
  ao_OfferPos.PRD_Desc = ""
  ao_OfferPos.LEV_Id = eDPCLevel.lvStandard
  ao_OfferPos.ERR_Type = eDPCErrorType.etNone
  ao_OfferPos.OFD_Pos = 0
  ao_OfferPos.OFD_PosCus = ""
  ao_OfferPos.OFD_Order = 0
  ao_OfferPos.OFD_WshDat = cal_COF_WshDat.date_dt
  ao_OfferPos.OFD_ShpDat = cal_COF_ShpDat.date_dt
  ao_OfferPos.OFD_DelDat = cal_COF_DelDat.date_dt
  ao_OfferPos.CAT_Id = eDPCCategory.cgNone
  ao_OfferPos.CAT_Name = ""
  ao_OfferPos.DOF_Id = eDPCOfferDetail.odNone
  ao_OfferPos.OFD_Valid = True
  ao_OfferPos.OFD_Found = 0
  ao_OfferPos.SPA_Id = 0
  ao_OfferPos.S_Code = ""
  
  ao_OfferPos.OFD_HPrice = 0
  ao_OfferPos.OFD_IctpPCS = 0
  ao_OfferPos.OFD_IctpM2 = 0
  ao_OfferPos.OFD_Ictp = 0
  ao_OfferPos.OFD_MarginS = 0
  ao_OfferPos.OFD_GTN = 0
  ao_OfferPos.OFD_MarginMin = 0
  ao_OfferPos.OFD_Rate = 1
  ao_OfferPos.CURR_CodeCOF = mo_Tools.GetComboKey(cbo_currencies)
  ao_OfferPos.CURR_Code = mo_Tools.GetComboKey(cbo_currencies)
  Call ao_OfferPos.ResetInterfaceInfo
  
  ao_OfferPos.OFD_AppBy = 0
  ao_OfferPos.OFD_ApDat = 0
  ao_OfferPos.OFD_PlaDat = 0
  ao_OfferPos.OFD_PlaUsr = ""
  ao_OfferPos.OFD_IsFree = False
  ao_OfferPos.OFD_IsAsItem = False
  
  ao_OfferPos.COF_IdOff = ""
  ao_OfferPos.OFD_IdOff = ""
  ao_OfferPos.SCR_Id = 0
  ao_OfferPos.DOF_Tag = ""
  ao_OfferPos.DOF_Name = ""
  ao_OfferPos.DOF_Desc = ""
  ao_OfferPos.DOF_Order = 0
  ao_OfferPos.DOF_NTemp = ""
  ao_OfferPos.DOF_DTemp = ""
  ao_OfferPos.DOF_IsVal = False
  ao_OfferPos.DOF_IsVal0 = False
  ao_OfferPos.DOF_DefVal = False
  ao_OfferPos.DOF_IsTxt = False
  ao_OfferPos.DOF_IsSchg = False
  ao_OfferPos.DOF_IsStp = False
  ao_OfferPos.DOF_CanInv = False
  
  ao_OfferPos.SCH_Id = ""
  ao_OfferPos.SCH_Code = ""
  ao_OfferPos.SCH_Name = ""
  ao_OfferPos.SCH_Desc = ""
  ao_OfferPos.UM_CodeQ = ""
  ao_OfferPos.ValidManual = False
  Exit Sub
ErrHandler:
  Call ErrorHandler("InitOfferDetail")
End Sub

Private Function ItemSubconstruction(ByVal ae_Mode As eDPCScreenMode, ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler

Dim lo_DPC_Subconstruction As frmDPC_Subconstruction
Dim lo_Collection As Collection
Dim lb_InTran As Boolean

  ItemSubconstruction = False
  Set lo_DPC_Subconstruction = New frmDPC_Subconstruction
  Load lo_DPC_Subconstruction
  Set lo_DPC_Subconstruction.Tools = mo_Tools
  Set lo_DPC_Subconstruction.ArmDb = mo_Db
  lo_DPC_Subconstruction.COF_Id = m_CurrentKey1
  lo_DPC_Subconstruction.LEN_Id = mo_Tools.GetComboKey(cbo_LegalEntity)
  lo_DPC_Subconstruction.CURR_Code = "EUR"
  lo_DPC_Subconstruction.CT_Code = CT_Code
  lo_DPC_Subconstruction.ValidityDate = ValidityDate
  lo_DPC_Subconstruction.CanChangeManualPrice = False 'mb_HasLevel2
  lo_DPC_Subconstruction.OFD_Pos = ao_OfferPos.OFD_Pos
  lo_DPC_Subconstruction.Language_Code = ms_Language_Code
  lo_DPC_Subconstruction.COF_Lang = ms_COF_Lang
  lo_DPC_Subconstruction.OFD_WshDat = ao_OfferPos.OFD_WshDat
  lo_DPC_Subconstruction.OFD_ShpDat = ao_OfferPos.OFD_ShpDat
  lo_DPC_Subconstruction.OFD_DelDat = ao_OfferPos.OFD_DelDat
  lo_DPC_Subconstruction.IsProduction = mb_IsProduction
  Call lo_DPC_Subconstruction.Load_A_COM
  If ae_Mode = eDPCScreenMode.smAdd Then
    Call lo_DPC_Subconstruction.ItemAdd
  ElseIf ae_Mode = eDPCScreenMode.smUpdate Then
    Call lo_DPC_Subconstruction.ItemUpdate(ao_OfferPos.PRD_Id)
    Call lo_DPC_Subconstruction.LoadOffer(m_CurrentKey1, ao_OfferPos.OFD_IdPar)
  End If
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_DPC_Subconstruction)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_DPC_Subconstruction.Result Then
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemSubconstruction")
    lb_InTran = True
    Call RecordUpdateLastUser
    Call lo_DPC_Subconstruction.ItemSave
    Set lo_Collection = lo_DPC_Subconstruction.GenerateOfferDetail
    Call SaveOfferDetail(lo_Collection, ao_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemSubconstruction")
    lb_InTran = False
    ItemSubconstruction = True
  End If
  Call lo_DPC_Subconstruction.Unload_A_COM
  Unload lo_DPC_Subconstruction
  Set lo_DPC_Subconstruction = Nothing
  Exit Function
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemSubconstruction")
  End If
  Call ErrorHandler("ItemSubconstruction")
End Function

Private Function ItemConfig(ByVal ae_Mode As eDPCScreenMode, ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler

Dim lo_DPC_Config As frmDPC_Config
Dim lo_Collection As Collection
Dim lb_InTran As Boolean
  
  ItemConfig = False
  Set lo_DPC_Config = New frmDPC_Config
  Load lo_DPC_Config
  Set lo_DPC_Config.Tools = mo_Tools
  Set lo_DPC_Config.ArmDb = mo_Db
  lo_DPC_Config.Language_Code = ms_Language_Code
  lo_DPC_Config.U_Code = ml_U_Code
  lo_DPC_Config.COF_Lang = ms_COF_Lang
  lo_DPC_Config.CURR_CodeCOF = mo_Tools.GetComboKey(cbo_currencies)
  lo_DPC_Config.CT_Code = CT_Code
  lo_DPC_Config.ValidityDate = ValidityDate
  lo_DPC_Config.COF_Id = m_CurrentKey1
  lo_DPC_Config.LEN_Id = mo_Tools.GetComboKey(cbo_LegalEntity)
  lo_DPC_Config.CanChangeManualPrice = False 'mb_HasLevel2
  lo_DPC_Config.OFD_Pos = ao_OfferPos.OFD_Pos
  lo_DPC_Config.OFD_WshDat = ao_OfferPos.OFD_WshDat
  lo_DPC_Config.OFD_ShpDat = ao_OfferPos.OFD_ShpDat
  lo_DPC_Config.OFD_DelDat = ao_OfferPos.OFD_DelDat
  lo_DPC_Config.IsProduction = mb_IsProduction
  lo_DPC_Config.IsTemplate = False
  Call lo_DPC_Config.Load_A_COM
  If ae_Mode = eDPCScreenMode.smAdd Then
    Call lo_DPC_Config.ItemAdd(ao_OfferPos.PRD_Id)
  ElseIf ae_Mode = eDPCScreenMode.smUpdate Then
    Call lo_DPC_Config.ItemUpdate(ao_OfferPos.PRD_Id)
    Call lo_DPC_Config.LoadOffer(m_CurrentKey1, ao_OfferPos.OFD_IdPar)
  End If
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_DPC_Config)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_DPC_Config.Result Then
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfig")
    lb_InTran = True
    Call RecordUpdateLastUser
    Call lo_DPC_Config.ItemSave
    Set lo_Collection = lo_DPC_Config.GenerateOfferDetail
    Call SaveOfferDetail(lo_Collection, ao_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfig")
    lb_InTran = False
    ItemConfig = True
  End If
  
  Call lo_DPC_Config.Unload_A_COM
  Unload lo_DPC_Config
  Set lo_DPC_Config = Nothing
  Exit Function
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfig")
  End If
  Call ErrorHandler("ItemConfig")
End Function

Private Function ItemConfigFree(ByVal ae_Mode As eDPCScreenMode, ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler

Dim lo_DPC_ConfigFree As frmDPC_ConfigFree
Dim lo_Collection As Collection
Dim lb_InTran As Boolean

  ItemConfigFree = False
  Set lo_DPC_ConfigFree = New frmDPC_ConfigFree
  Load lo_DPC_ConfigFree
  Set lo_DPC_ConfigFree.Tools = mo_Tools
  Set lo_DPC_ConfigFree.ArmDb = mo_Db
  lo_DPC_ConfigFree.Language_Code = ms_Language_Code
  lo_DPC_ConfigFree.U_Code = ml_U_Code
  lo_DPC_ConfigFree.COF_Lang = ms_COF_Lang
  lo_DPC_ConfigFree.CURR_Code = "EUR"
  lo_DPC_ConfigFree.CT_Code = CT_Code
  lo_DPC_ConfigFree.ValidityDate = ValidityDate
  lo_DPC_ConfigFree.COF_Id = m_CurrentKey1
  lo_DPC_ConfigFree.LEN_Id = mo_Tools.GetComboKey(cbo_LegalEntity)
  'lo_DPC_ConfigFree.CanChangeManualPrice = False 'mb_HasLevel2
  lo_DPC_ConfigFree.OFD_Pos = ao_OfferPos.OFD_Pos
  lo_DPC_ConfigFree.OFD_WshDat = ao_OfferPos.OFD_WshDat
  lo_DPC_ConfigFree.OFD_ShpDat = ao_OfferPos.OFD_ShpDat
  lo_DPC_ConfigFree.OFD_DelDat = ao_OfferPos.OFD_DelDat
  lo_DPC_ConfigFree.IsProduction = mb_IsProduction
  lo_DPC_ConfigFree.IsTemplate = False
  Call lo_DPC_ConfigFree.Load_A_COM
  If ae_Mode = eDPCScreenMode.smAdd Then
    Call lo_DPC_ConfigFree.ItemAdd(ao_OfferPos.PRD_Id)
  ElseIf ae_Mode = eDPCScreenMode.smUpdate Then
    Call lo_DPC_ConfigFree.ItemUpdate(ao_OfferPos.PRD_Id)
    Call lo_DPC_ConfigFree.LoadOffer(m_CurrentKey1, ao_OfferPos.OFD_IdPar)
  End If
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_DPC_ConfigFree)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_DPC_ConfigFree.Result Then
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfigFree")
    lb_InTran = True
    Call RecordUpdateLastUser
    Call lo_DPC_ConfigFree.ItemSave
    Set lo_Collection = lo_DPC_ConfigFree.GenerateOfferDetail
    Call SaveOfferDetail(lo_Collection, ao_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfigFree")
    lb_InTran = False
    ItemConfigFree = True
  End If
  
  Call lo_DPC_ConfigFree.Unload_A_COM
  Unload lo_DPC_ConfigFree
  Set lo_DPC_ConfigFree = Nothing
  Exit Function
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfigFree")
  End If
  Call ErrorHandler("ItemConfigFree")
End Function

Private Function ItemConfigSpc(ByVal ae_Mode As eDPCScreenMode, ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler

Dim lo_DPC_ConfigSpc As frmDPC_ConfigSpc
Dim lo_Collection As Collection
Dim lb_InTran As Boolean

  ItemConfigSpc = False
  Set lo_DPC_ConfigSpc = New frmDPC_ConfigSpc
  Load lo_DPC_ConfigSpc
  Set lo_DPC_ConfigSpc.Tools = mo_Tools
  Set lo_DPC_ConfigSpc.ArmDb = mo_Db
  lo_DPC_ConfigSpc.Language_Code = ms_Language_Code
  lo_DPC_ConfigSpc.U_Code = ml_U_Code
  lo_DPC_ConfigSpc.COF_Lang = ms_COF_Lang
  lo_DPC_ConfigSpc.CURR_Code = "EUR"
  lo_DPC_ConfigSpc.CT_Code = CT_Code
  lo_DPC_ConfigSpc.ValidityDate = ValidityDate
  lo_DPC_ConfigSpc.COF_Id = m_CurrentKey1
  lo_DPC_ConfigSpc.LEN_Id = mo_Tools.GetComboKey(cbo_LegalEntity)
  'lo_DPC_ConfigSpc.CanChangeManualPrice = False 'mb_HasLevel2
  lo_DPC_ConfigSpc.OFD_Pos = ao_OfferPos.OFD_Pos
  lo_DPC_ConfigSpc.OFD_WshDat = ao_OfferPos.OFD_WshDat
  lo_DPC_ConfigSpc.OFD_ShpDat = ao_OfferPos.OFD_ShpDat
  lo_DPC_ConfigSpc.OFD_DelDat = ao_OfferPos.OFD_DelDat
  lo_DPC_ConfigSpc.IsProduction = mb_IsProduction
  lo_DPC_ConfigSpc.IsTemplate = False
  Call lo_DPC_ConfigSpc.Load_A_COM
  If ae_Mode = eDPCScreenMode.smAdd Then
    Call lo_DPC_ConfigSpc.ItemAdd(ao_OfferPos.PRD_Id)
  ElseIf ae_Mode = eDPCScreenMode.smUpdate Then
    Call lo_DPC_ConfigSpc.ItemUpdate(ao_OfferPos.PRD_Id)
    Call lo_DPC_ConfigSpc.LoadOffer(m_CurrentKey1, ao_OfferPos.OFD_IdPar)
  End If
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_DPC_ConfigSpc)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_DPC_ConfigSpc.Result Then
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfigSpc")
    lb_InTran = True
    Call RecordUpdateLastUser
    Call lo_DPC_ConfigSpc.ItemSave
    Set lo_Collection = lo_DPC_ConfigSpc.GenerateOfferDetail
    Call SaveOfferDetail(lo_Collection, ao_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfigSpc")
    lb_InTran = False
    ItemConfigSpc = True
  End If
  
  Call lo_DPC_ConfigSpc.Unload_A_COM
  Unload lo_DPC_ConfigSpc
  Set lo_DPC_ConfigSpc = Nothing
  Exit Function
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemConfigSpc")
  End If
  Call ErrorHandler("ItemConfigSpc")
End Function

Private Function ItemManual(ByVal ae_Mode As eDPCScreenMode, ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler

Dim lo_OfferManual As frmOfferManual
Dim lo_Collection As Collection
Dim lb_InTran As Boolean
  
  ItemManual = False
  If Not mb_HasOfferManual Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9739, "#You do not have enough right to do this operation")
    Exit Function
  End If
  Set lo_OfferManual = New frmOfferManual
  Load lo_OfferManual
  Set lo_OfferManual.Tools = mo_Tools
  Set lo_OfferManual.ArmDb = mo_Db
  lo_OfferManual.Language_Code = ms_Language_Code
  lo_OfferManual.U_Code = ml_U_Code
  lo_OfferManual.COF_Lang = ms_COF_Lang
  If ae_Mode = eDPCScreenMode.smAdd Then
    lo_OfferManual.CURR_Code = CURR_Code
  Else
    lo_OfferManual.CURR_Code = ao_OfferPos.CURR_Code
  End If
  lo_OfferManual.CT_Code = CT_Code
  lo_OfferManual.COF_Id = m_CurrentKey1
  lo_OfferManual.LEN_Id = mo_Tools.GetComboKey(cbo_LegalEntity)
  lo_OfferManual.PRD_Code = ao_OfferPos.PRD_Code
  lo_OfferManual.OFD_Pos = ao_OfferPos.OFD_Pos
  lo_OfferManual.OFD_WshDat = ao_OfferPos.OFD_WshDat
  lo_OfferManual.OFD_ShpDat = ao_OfferPos.OFD_ShpDat
  lo_OfferManual.OFD_DelDat = ao_OfferPos.OFD_DelDat
  lo_OfferManual.VEN_Id = ao_OfferPos.VEN_Id
  lo_OfferManual.VEN_Name = ao_OfferPos.VEN_Name
  lo_OfferManual.SHP_Id = ao_OfferPos.SHP_Id
  lo_OfferManual.SHP_Name = ao_OfferPos.SHP_Name
  lo_OfferManual.OFD_IsAsItem = ao_OfferPos.OFD_IsAsItem
  lo_OfferManual.OFD_IsFree = ao_OfferPos.OFD_IsFree
  Call lo_OfferManual.Load_A_COM
  
  If ae_Mode = eDPCScreenMode.smAdd Then
    Call lo_OfferManual.ItemAdd
  ElseIf ae_Mode = eDPCScreenMode.smUpdate Then
    Call lo_OfferManual.ItemUpdate(m_CurrentKey1, ao_OfferPos.OFD_IdPar)
  End If
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_OfferManual)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_OfferManual.Result Then
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemManual")
    lb_InTran = True
    Call RecordUpdateLastUser
    Call lo_OfferManual.ItemSave
    Set lo_Collection = lo_OfferManual.GenerateOfferDetail
    Call SaveOfferDetail(lo_Collection, ao_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemManual")
    lb_InTran = False
    ItemManual = True
  End If
  Call lo_OfferManual.Unload_A_COM
  Unload lo_OfferManual
  Set lo_OfferManual = Nothing
  Exit Function
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemManual")
  End If
  Call ErrorHandler("ItemManual")
End Function

Private Function ItemService(ByVal ae_Mode As eDPCScreenMode, ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler

Dim lo_OfferService As frmOfferService
Dim lo_Collection As Collection
Dim lb_InTran As Boolean
  
  ItemService = False
  Set lo_OfferService = New frmOfferService
  Load lo_OfferService
  Set lo_OfferService.Tools = mo_Tools
  Set lo_OfferService.ArmDb = mo_Db
  lo_OfferService.Language_Code = ms_Language_Code
  lo_OfferService.U_Code = ml_U_Code
  lo_OfferService.COF_Lang = ms_COF_Lang
  If ae_Mode = eDPCScreenMode.smAdd Then
    lo_OfferService.CURR_Code = CURR_Code
  Else
    lo_OfferService.CURR_Code = ao_OfferPos.CURR_Code
  End If
  lo_OfferService.CT_Code = CT_Code
  lo_OfferService.COF_Id = m_CurrentKey1
  lo_OfferService.LEN_Id = mo_Tools.GetComboKey(cbo_LegalEntity)
  lo_OfferService.PRD_Code = ao_OfferPos.PRD_Code
  lo_OfferService.OFD_Pos = ao_OfferPos.OFD_Pos
  lo_OfferService.OFD_WshDat = ao_OfferPos.OFD_WshDat
  lo_OfferService.OFD_ShpDat = ao_OfferPos.OFD_ShpDat
  lo_OfferService.OFD_DelDat = ao_OfferPos.OFD_DelDat
  lo_OfferService.VEN_Id = ao_OfferPos.VEN_Id
  lo_OfferService.VEN_Name = ao_OfferPos.VEN_Name
  lo_OfferService.SHP_Id = ao_OfferPos.SHP_Id
  lo_OfferService.SHP_Name = ao_OfferPos.SHP_Name
  lo_OfferService.IsAsItem = ao_OfferPos.OFD_IsAsItem
  lo_OfferService.IsFree = ao_OfferPos.OFD_IsFree
  Call lo_OfferService.Load_A_COM
  
  If ae_Mode = eDPCScreenMode.smAdd Then
    Call lo_OfferService.ItemAdd
  ElseIf ae_Mode = eDPCScreenMode.smUpdate Then
    Call lo_OfferService.ItemUpdate(m_CurrentKey1, ao_OfferPos.OFD_IdPar)
  End If
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_OfferService)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_OfferService.Result Then
    Set lo_Collection = lo_OfferService.GenerateOfferDetail
    Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemService")
    lb_InTran = True
    Call RecordUpdateLastUser
    Call SaveOfferDetail(lo_Collection, ao_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
    Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemService")
    lb_InTran = False
    ItemService = True
  End If
  Call lo_OfferService.Unload_A_COM
  Unload lo_OfferService
  Set lo_OfferService = Nothing
  Exit Function
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ItemService")
  End If
  Call ErrorHandler("ItemService")
End Function

Private Function ItemProdType(ByVal ao_OfferPos As DPC_OfferPos) As eDPCPriceBookType
On Error GoTo ErrHandler

Dim lo_OfferProdType As frmOfferProdType

  ItemProdType = eDPCPriceBookType.eUnknown
  ao_OfferPos.OFD_Type = eDPCPriceBookType.eUnknown
  ao_OfferPos.OFD_TypeDesc = ""
  
  Set lo_OfferProdType = New frmOfferProdType
  Load lo_OfferProdType
  lo_OfferProdType.Language_Code = ms_Language_Code
  lo_OfferProdType.U_Code = ml_U_Code
  lo_OfferProdType.OfferStatus = Status
  Set lo_OfferProdType.Tools = mo_Tools
  Set lo_OfferProdType.ArmDb = mo_Db
  Call lo_OfferProdType.Load_A_COM
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_OfferProdType)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_OfferProdType.Result Then
    ao_OfferPos.OFD_Type = lo_OfferProdType.ProductType
    ao_OfferPos.OFD_TypeDesc = lo_OfferProdType.ProductTypeDesc
    ItemProdType = lo_OfferProdType.ProductType
  End If
  Call lo_OfferProdType.Unload_A_COM
  Unload lo_OfferProdType
  Set lo_OfferProdType = Nothing
  Exit Function
ErrHandler:
  Call ErrorHandler("ItemProdType")
End Function

Private Function ItemPrdSel(ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler

Dim lo_DPC_PrdSel As frmDPC_PrdSel

  ItemPrdSel = False
  ao_OfferPos.PRD_Id = ""
  ao_OfferPos.LEV_Id = eDPCLevel.lvNone
  
  Set lo_DPC_PrdSel = New frmDPC_PrdSel
  Load lo_DPC_PrdSel
  Set lo_DPC_PrdSel.Tools = mo_Tools
  Set lo_DPC_PrdSel.ArmDb = mo_Db
  lo_DPC_PrdSel.Language_Code = ms_Language_Code
  lo_DPC_PrdSel.U_Code = ml_U_Code
  lo_DPC_PrdSel.OfferStatus = Status
  Call lo_DPC_PrdSel.Load_A_COM
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_DPC_PrdSel)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_DPC_PrdSel.Result Then
    ao_OfferPos.PRD_Id = lo_DPC_PrdSel.PRD_Id
    ao_OfferPos.LEV_Id = lo_DPC_PrdSel.LEV_Id
    ao_OfferPos.PRD_Code = lo_DPC_PrdSel.PRD_Code
    ItemPrdSel = True
  End If
  Call lo_DPC_PrdSel.Unload_A_COM
  Unload lo_DPC_PrdSel
  Set lo_DPC_PrdSel = Nothing
  Exit Function
ErrHandler:
  Call ErrorHandler("ItemPrdSel")
End Function

Private Function ItemPrdMainAlt(ByVal ao_OfferPos As DPC_OfferPos, ByRef ab_FromOtherOffer As Boolean, ByVal ao_Collection As Collection) As Boolean
On Error GoTo ErrHandler
    
Dim lo_OfferPrdMainAlt As frmOfferPrdMainAlt
    
  ItemPrdMainAlt = False
  Set lo_OfferPrdMainAlt = New frmOfferPrdMainAlt
  Load lo_OfferPrdMainAlt
  Set lo_OfferPrdMainAlt.Tools = mo_Tools
  Set lo_OfferPrdMainAlt.ArmDb = mo_Db
  lo_OfferPrdMainAlt.Language_Code = ms_Language_Code
  lo_OfferPrdMainAlt.U_Code = ml_U_Code
  lo_OfferPrdMainAlt.COF_Id = ao_OfferPos.COF_Id
  lo_OfferPrdMainAlt.OFD_Id = ao_OfferPos.OFD_Id
  Call lo_OfferPrdMainAlt.Load_A_COM
  
  If ab_FromOtherOffer Then
    Set lo_OfferPrdMainAlt.tbs_Main.SelectedItem = lo_OfferPrdMainAlt.tbs_Main.Tabs(lo_OfferPrdMainAlt.fra_OfferCopy.Name)
    lo_OfferPrdMainAlt.tbs_Main.Enabled = False
  End If
  
  Call mo_Tools.LockScreen(Me, False)
  Call mo_Tools.ShowModalForm(lo_OfferPrdMainAlt)
  Call mo_Tools.LockScreen(Me, True)
  
  If lo_OfferPrdMainAlt.Result Then
    If StrComp(lo_OfferPrdMainAlt.tbs_Main.SelectedItem.Key, lo_OfferPrdMainAlt.fra_OfferCopy.Name, vbTextCompare) = 0 Then
      ab_FromOtherOffer = True
      Call lo_OfferPrdMainAlt.InitCollection(ao_Collection)
    Else
      ab_FromOtherOffer = False
      ao_OfferPos.OFD_IsAlt = IIf(lo_OfferPrdMainAlt.IsAlt, eDPCOfferDetailIsAlt.maAltenative, eDPCOfferDetailIsAlt.maMain)
      ao_OfferPos.OFD_AltPa = lo_OfferPrdMainAlt.AltParent
      ao_OfferPos.OFD_AltPaName = lo_OfferPrdMainAlt.AltParentName
      If lo_OfferPrdMainAlt.ResetQty Then
        ao_OfferPos.OFD_Qty = 0
        ao_OfferPos.OFD_QtyA = 0
      End If
    End If
    ItemPrdMainAlt = True
  End If
  Call lo_OfferPrdMainAlt.Unload_A_COM
  Unload lo_OfferPrdMainAlt
  Set lo_OfferPrdMainAlt = Nothing
  Exit Function
ErrHandler:
  Call ErrorHandler("ItemPrdMainAlt")
End Function

Private Sub tlb_Subitem_action(ByVal as_Role As String, as_Language As String)
On Error GoTo ErrHandler

Dim lo_Collection As New Collection
Dim le_ProdType As eDPCPriceBookType
Dim ll_OFD_Pos As Long
Dim lb_Result As Boolean

  Call mo_Tools.LockScreen(Me, True)
  
  Select Case as_Role

  Case "A"
    If Not CanAddSubitem Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
    End If
    
    If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
      If Not RecordAdd Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
      
      If GetOfferLock(m_CurrentKey1, False) Then
        mi_DisplayMode = mt_CstValues.DisplayMode_Update
      Else
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
    End If
    
    Call InitOfferDetail(mo_OfferPos)
    mo_OfferPos.OFD_Pos = GetNextOFD_Pos
    
    le_ProdType = ItemProdType(mo_OfferPos)
    If (le_ProdType = eDPCPriceBookType.eStockMetal) Or _
       (le_ProdType = eDPCPriceBookType.eCustomMetal) Or _
       (le_ProdType = eDPCPriceBookType.eEngMetal) Then
      
      If mo_OfferPos.OFD_Pos > MAX_OFD_POS Then
          Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9866, "#You cannot add metal item with position number greater than $MAX_OFD_POS$", Array("$MAX_OFD_POS$", MAX_OFD_POS))
          Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
      
      If Not ItemPrdSel(mo_OfferPos) Then
          Call mo_Tools.LockScreen(Me, False)
          Exit Sub
      End If
      
      If mo_OfferPos.LEV_Id = eDPCLevel.lvEngineered Then
        If mo_OfferPos.PRD_Code = "0900" Then
          If Not ItemConfig(eDPCScreenMode.smAdd, mo_OfferPos) Then
            Call mo_Tools.LockScreen(Me, False)
            Exit Sub
          End If
        Else
          If Not ItemConfigFree(eDPCScreenMode.smAdd, mo_OfferPos) Then
            Call mo_Tools.LockScreen(Me, False)
            Exit Sub
          End If
        End If
      Else
        If Not ItemConfig(eDPCScreenMode.smAdd, mo_OfferPos) Then
          Call mo_Tools.LockScreen(Me, False)
          Exit Sub
        End If
        
      End If
    ElseIf (le_ProdType = eDPCPriceBookType.eSubconstruction) Then
      If Not ItemSubconstruction(eDPCScreenMode.smAdd, mo_OfferPos) Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
    ElseIf (le_ProdType = eDPCPriceBookType.eStockCapture) Then
      Call InitOfferDetailStockCapture(mo_OfferPos)
      Call AddDisplaySubItem(mo_OfferPos)
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    ElseIf (le_ProdType = eDPCPriceBookType.eWood) Then
'      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "Submit request Wood Product")
    ElseIf (le_ProdType = eDPCPriceBookType.eVendor) Then
'      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "Submit request to vendor X")
    ElseIf (le_ProdType = eDPCPriceBookType.eManualLine) Then
      
      If Not ItemManual(eDPCScreenMode.smAdd, mo_OfferPos) Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
    ElseIf (le_ProdType = eDPCPriceBookType.eServiceItem) Then
      
      If Not ItemService(eDPCScreenMode.smAdd, mo_OfferPos) Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
    End If
    Call RefreshOfferDetail
    Call RefreshOfferHeader
    
  Case "B"
    If Not CanUpdateSubitem Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
    End If
    
    If (grd_Offer.SelectedCount <> 1) Or _
       (grd_Offer.SelectedLine(0, "OFD_Main") <> eDPCOfferDetailMain.odMain) Or _
       grd_Offer.SelectedLine(0, "OFD_Id") <> grd_Offer.SelectedLine(0, "OFD_IdPar") Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9715, "#Please select one master record")
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    End If
    Call mo_OfferPos.Load(mo_Db, m_CurrentKey1, grd_Offer.SelectedLine(0, "OFD_Id"), ms_Language_Code)
    
    If (IsSalesOrder Or IsSalesOrderChange) And (StrComp(mo_OfferPos.OFD_SAPAct, "A", vbTextCompare) <> 0) Then
      Call UpdateDisplaySubItem
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    ElseIf (mo_OfferPos.OFD_Type = eDPCPriceBookType.eStockMetal) Or _
       (mo_OfferPos.OFD_Type = eDPCPriceBookType.eCustomMetal) Or _
       (mo_OfferPos.OFD_Type = eDPCPriceBookType.eEngMetal) Then
      If mo_OfferPos.LEV_Id = eDPCLevel.lvEngineered Then
        If mo_Tools.SelectValue(mo_Db, "SELECT PRC2.BI_SAP_Code FROM DPC_PrdCommon PRC1 INNER JOIN DPC_PrdCommon PRC2 ON (PRC1.PRD_IdPar=PRC2.PRD_Id) WHERE PRC1.PRD_Id=" & mo_Tools.SQLStr(mo_OfferPos.PRD_Id)) = "0900" Then
          If Not ItemConfig(eDPCScreenMode.smUpdate, mo_OfferPos) Then
            Call mo_Tools.LockScreen(Me, False)
            Exit Sub
          End If
        Else
          If Not ItemConfigFree(eDPCScreenMode.smUpdate, mo_OfferPos) Then
            Call mo_Tools.LockScreen(Me, False)
            Exit Sub
          End If
        End If
      Else
        If Not ItemConfig(eDPCScreenMode.smUpdate, mo_OfferPos) Then
          Call mo_Tools.LockScreen(Me, False)
          Exit Sub
        End If
      End If
    ElseIf (mo_OfferPos.OFD_Type = eDPCPriceBookType.eSubconstruction) Then
      If Not ItemSubconstruction(eDPCScreenMode.smUpdate, mo_OfferPos) Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
      
    ElseIf (mo_OfferPos.OFD_Type = eDPCPriceBookType.eWood) Then
'      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "Edit wood product")
    ElseIf (mo_OfferPos.OFD_Type = eDPCPriceBookType.eVendor) Then
'      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 666, "Edit vendor product")
    ElseIf (mo_OfferPos.OFD_Type = eDPCPriceBookType.eStockCapture) Then
      Call UpdateDisplaySubItem
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    ElseIf (mo_OfferPos.OFD_Type = eDPCPriceBookType.eManualLine) Then
      If Not ItemManual(eDPCScreenMode.smUpdate, mo_OfferPos) Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
    ElseIf (mo_OfferPos.OFD_Type = eDPCPriceBookType.eServiceItem) Then
      If Not ItemService(eDPCScreenMode.smUpdate, mo_OfferPos) Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
    End If
    
    Call RefreshOfferDetail
    Call grd_Offer.SearchKey(True, mo_OfferPos.OFD_Id)
    grd_Offer.Col = grd_Offer.Columns("PRD_Name").ColumnIndex
    Call RefreshOfferHeader
    
    If HasAlternateProduct(mo_OfferPos) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9716, "#This product has alternate product(s), please update all alternate products if quantity has changed")
    End If
    If mo_OfferPos.OFD_IsAlt Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9717, "#This product is alternate product, please update main product if quantity has changed")
    End If
  Case "C"
    If Not CanDeleteSubitem Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
    End If
    
    If (grd_Offer.SelectedCount <> 1) Or _
       (grd_Offer.SelectedLine(0, "OFD_Main") <> eDPCOfferDetailMain.odMain) Or _
       grd_Offer.SelectedLine(0, "OFD_Id") <> grd_Offer.SelectedLine(0, "OFD_IdPar") Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9715, "#Please select one master record")
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    End If
    Call mo_OfferPos.Load(mo_Db, m_CurrentKey1, grd_Offer.SelectedLine(0, "OFD_Id"), ms_Language_Code)
    If HasAlternateProduct(mo_OfferPos) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9718, "#This product has alternate product(s), please delete all alternate products first")
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    End If
    Call DeleteDisplaySubItem
  
  Case "D"
    If (grd_Offer.SelectedCount <> 1) Or (grd_Offer.SelectedLine(0, "OFD_Main") <> eDPCOfferDetailMain.odMain) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9715, "#Please select one master record")
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    End If
    If (grd_Offer.SelectedLine(0, "OFD_Type") <> eDPCPriceBookType.eSubconstruction) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9719, "#Please select subconstruction")
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    End If
    Call GenerateTemplate(m_CurrentKey1, grd_Offer.SelectedLine(0, "OFD_Id"), grd_Offer.SelectedLine(0, "PRD_Id"))
    
  Case "X"
  
    Dim lb_FromOtherOffer As Boolean
    Dim ls_COF_ID As String, ls_OFD_Id As String, lsa_item() As String
    Dim ll_Idx As Long
    
    If Not CanUpdateSubitem Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
    End If
    
    If mi_DisplayMode = mt_CstValues.DisplayMode_Add Then
      If Not RecordAdd Then
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
      
      If GetOfferLock(m_CurrentKey1, False) Then
        mi_DisplayMode = mt_CstValues.DisplayMode_Update
      Else
        Call mo_Tools.LockScreen(Me, False)
        Exit Sub
      End If
    End If
    
    lb_FromOtherOffer = False
    If (grd_Offer.SelectedCount <> 1) Or _
       (grd_Offer.SelectedLine(0, "OFD_Main") <> eDPCOfferDetailMain.odMain) Or _
       grd_Offer.SelectedLine(0, "OFD_Id") <> grd_Offer.SelectedLine(0, "OFD_IdPar") Then
      lb_FromOtherOffer = True
      'Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9715, "#Please select one master record")
      'Call mo_Tools.LockScreen(Me, False)
      'Exit Sub
    Else
      lb_FromOtherOffer = False
      Call mo_OfferPos.Load(mo_Db, m_CurrentKey1, grd_Offer.SelectedLine(0, "OFD_Id"), ms_Language_Code)
    End If
    
    'Call mo_OfferPos.Load(mo_Db, m_CurrentKey1, grd_Offer.SelectedLine(0, "OFD_Id"), ms_Language_Code)
    
    If Not ItemPrdMainAlt(mo_OfferPos, lb_FromOtherOffer, lo_Collection) Then
      Call mo_Tools.LockScreen(Me, False)
      Exit Sub
    End If
    
    If lb_FromOtherOffer Then
      For ll_Idx = 1 To lo_Collection.Count
        lsa_item = Split(lo_Collection(ll_Idx), SEP)
        ls_COF_ID = lsa_item(0)
        ls_OFD_Id = lsa_item(1)
        Call mo_OfferPos.Load(mo_Db, ls_COF_ID, ls_OFD_Id, ms_Language_Code)
        ll_OFD_Pos = GetNextOFD_Pos
        If (ll_OFD_Pos > MAX_OFD_POS) And _
           ((mo_OfferPos.OFD_Type = eDPCPriceBookType.eStockMetal) Or _
            (mo_OfferPos.OFD_Type = eDPCPriceBookType.eCustomMetal) Or _
            (mo_OfferPos.OFD_Type = eDPCPriceBookType.eEngMetal)) Then
          Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9866, "You cannot add metal item with position number greater than $MAX_OFD_POS$", Array("$MAX_OFD_POS$", MAX_OFD_POS))
          Call mo_Tools.LockScreen(Me, False)
          Exit Sub
        End If
        Call SubRecordCopy(mo_OfferPos, m_CurrentKey1, ll_OFD_Pos, COF_DocDat, ms_COF_Lang, CURR_Code, True, Status)
      Next
    Else
      If mo_OfferPos.OFD_IsAlt = eDPCOfferDetailIsAlt.maMain Then
        ll_OFD_Pos = GetNextOFD_Pos
      Else
        ll_OFD_Pos = 0
      End If
        If (ll_OFD_Pos > MAX_OFD_POS) And _
           ((mo_OfferPos.OFD_Type = eDPCPriceBookType.eStockMetal) Or _
            (mo_OfferPos.OFD_Type = eDPCPriceBookType.eCustomMetal) Or _
            (mo_OfferPos.OFD_Type = eDPCPriceBookType.eEngMetal)) Then
          Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9866, "You cannot add metal item with position number greater than $MAX_OFD_POS$", Array("$MAX_OFD_POS$", MAX_OFD_POS))
          Call mo_Tools.LockScreen(Me, False)
          Exit Sub
        End If
      Call SubRecordCopy(mo_OfferPos, m_CurrentKey1, ll_OFD_Pos, COF_DocDat, ms_COF_Lang, CURR_Code, False, Status)
    End If
    Call RefreshOfferDetail
    Call grd_Offer.SearchKey(True, mo_OfferPos.OFD_Id)
    grd_Offer.Col = grd_Offer.Columns("PRD_Name").ColumnIndex
    Call RefreshOfferHeader
  Case "T"
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
    If DisplayMode = mt_CstValues.DisplayMode_Add Then
        Call Add_Enablecontrols
    End If

  Case "F"
      Call RefreshOfferDetail
      
  Case "c"
    mb_grd_ShowDetail = False
    Call RefreshOfferDetail
  Case "b"
    mb_grd_ShowDetail = True
    Call RefreshOfferDetail
    
  Case "H"
    lb_Result = False
    Select Case ml_DisplayModeSubItem
    Case mt_CstValues.DisplayMode_Add
      If SubRecordCheck(mo_OfferPos) Then
        Call lo_Collection.Add(mo_OfferPos)
        Call SaveOfferDetail(lo_Collection, "", COF_DocDat, CURR_Code, Status)
        Call RefreshOfferDetail
        Call RefreshOfferHeader
        lb_Result = True
      End If
    Case mt_CstValues.DisplayMode_Update
      If SubRecordCheck(mo_OfferPos) Then
        Call lo_Collection.Add(mo_OfferPos)
        Call SaveOfferDetail(lo_Collection, mo_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
        Call RefreshOfferDetail
        Call RefreshOfferHeader
        If HasAlternateProduct(mo_OfferPos) Then
          Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9716, "#This product has alternate product(s), please update all alternate products if quantity has changed")
        End If
        If mo_OfferPos.OFD_IsAlt Then
          Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9717, "#This product is alternate product, please update main product if quantity has changed")
        End If
        lb_Result = True
      End If
    Case mt_CstValues.DisplayMode_Delete
      If grd_Offer.SelectedCount = 1 Then
        If (IsSalesOrder Or IsSalesOrderChange) And (StrComp(mo_OfferPos.OFD_SAPAct, "A", vbTextCompare) <> 0) Then
          mo_OfferPos.OFD_SAPAct = "K"
          Call SubRecordUpdate(mo_OfferPos)
        Else
          Call SubRecordDrop(mo_OfferPos.OFD_IdPar)
        End If
        Call RefreshOfferDetail
        Call RefreshOfferHeader
        lb_Result = True
      End If
    End Select
    If lb_Result Then
      If ml_DisplayModeSubItem = mt_CstValues.DisplayMode_Add Then
          Call InitOfferDetailStockCapture(mo_OfferPos)
          mo_OfferPos.OFD_Pos = GetNextOFD_Pos
          Call AddDisplaySubItem(mo_OfferPos)
      Else
          Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
      End If
    End If
  Case "I"
    Select Case ml_DisplayModeSubItem
    Case mt_CstValues.DisplayMode_Add
      Debug.Assert (Not cbo_Customer.SelectedItem Is Nothing)
      Call AddDisplaySubItem(mo_OfferPos)
    Case mt_CstValues.DisplayMode_Update
      Debug.Assert (grd_Offer.SelectedCount = 1)
      Call UpdateDisplaySubItem
    Case Else
      Debug.Assert (False)
    End Select
      
  Case Else
    Err.Raise ArmErr.InvalidArgument, "as_Role", "Invalid role: " & as_Role
  End Select
  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Select Case Err.Number
  Case ArmErr.SQLBadRowExpectedCount
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 2138, "#The record you try to open has been deleted by an other user. Please refresh the grid.", , vbInformation)
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  Case ArmErr.SQLBadRowAffectedCount
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 916, "#This data has been updated by another user. Data will be reloaded. Please check the data and try again.", , vbInformation)
    Dim lv_Key As Variant
    lv_Key = grd_Offer.SelectedKey(0)
    Call grd_Offer.Refresh
    If grd_Offer.SearchKey(True, lv_Key) Then
      Call ViewInitFieldsSubItem
    Else
      Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_List)
    End If
    Call mo_Tools.LockScreen(Me, False)
    Exit Sub
  End Select
  Call ErrorMessage("tlb_Subitem_action")
End Sub

Private Sub UpdateDetailDate(ByVal as_Column As String, ByVal ao_Cal As A_calocx)
On Error GoTo ErrHandler

Dim ld_Date As Date
Dim ll_Idx As Long

  ld_Date = 0
  If grd_Offer.Rows > 0 Then
    For ll_Idx = 0 To grd_Offer.Rows - 1
      If grd_Offer.Data(ll_Idx, "OFD_Main") = eDPCOfferDetailMain.odMain Then
        If (grd_Offer.Data(ll_Idx, as_Column) <> 0) Then
          If ld_Date = 0 Then
            ld_Date = grd_Offer.Data(ll_Idx, as_Column)
          Else
            If ld_Date <> grd_Offer.Data(ll_Idx, as_Column) Then
              ld_Date = 0
              Exit For
            End If
          End If
        End If
      End If
    Next
  End If
  Call mo_Tools.SetCalendarDate(ao_Cal, ld_Date)
  Exit Sub
ErrHandler:
  Call ErrorHandler("UpdateDetailDate")
End Sub

Private Sub RefreshOfferDetail()
On Error GoTo ErrHandler

Dim ls_Request As String
Dim ls_TabKey As String
  
  ls_TabKey = tbs_OfferDetail.SelectedItem.Key
  ls_Request = "exec Cap_OfferDetail_lst2 $COF_Id$, $Language_Code$, $OFD_Main$, $OFD_IdPar$, $OFD_Valid$, $OFD_Id$, $OFD_IsAlt$"
  ls_Request = Replace(ls_Request, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$OFD_Valid$", mo_Tools.SQLStr("X"), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$OFD_IdPar$", "NULL", , , vbTextCompare)
  If mb_grd_ShowDetail Then
    ls_Request = Replace(ls_Request, "$OFD_Main$", "NULL", , , vbTextCompare)
  Else
    ls_Request = Replace(ls_Request, "$OFD_Main$", mo_Tools.SqlInt(eDPCOfferDetailMain.odMain), , , vbTextCompare)
  End If
  ls_Request = Replace(ls_Request, "$OFD_Id$", "NULL", , , vbTextCompare)
  If (StrComp(ls_TabKey, "tab_Detail", vbTextCompare) = 0) Then
    ls_Request = Replace(ls_Request, "$OFD_IsAlt$", mo_Tools.SqlInt(eDPCOfferDetailIsAlt.maMain), , , vbTextCompare)
  ElseIf (StrComp(ls_TabKey, "tab_Alt", vbTextCompare) = 0) Then
    ls_Request = Replace(ls_Request, "$OFD_IsAlt$", mo_Tools.SqlInt(eDPCOfferDetailIsAlt.maAltenative), , , vbTextCompare)
  ElseIf (StrComp(ls_TabKey, "tab_Option", vbTextCompare) = 0) Then
    ls_Request = Replace(ls_Request, "$OFD_IsAlt$", mo_Tools.SqlInt(eDPCOfferDetailIsAlt.maOption), , , vbTextCompare)
  End If
  grd_Offer.RequestLoadDetails = mb_grd_ShowDetail
  
  grd_Offer.Redraw = False
  Call grd_Offer.Load(ls_Request, True)
  grd_Offer.Redraw = True
  
  Call UpdateDetailDate("OFD_WshDat", cal_COF_WshDat)
  Call UpdateDetailDate("OFD_ShpDat", cal_COF_ShpDat)
  Call UpdateDetailDate("OFD_DelDat", cal_COF_DelDat)

  ls_Request = "exec Cap_OfferDetail_lst2 $COF_Id$, $Language_Code$, $OFD_Main$, '$OFD_IdPar$', $OFD_Valid$, $OFD_Id$, $OFD_IsAlt$"
  ls_Request = Replace(ls_Request, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$OFD_Valid$", mo_Tools.SQLStr("X"), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$OFD_Main$", mo_Tools.SqlInt(eDPCOfferDetailMain.odChild), , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$OFD_Id$", "NULL", , , vbTextCompare)
  ls_Request = Replace(ls_Request, "$OFD_IsAlt$", "NULL", , , vbTextCompare)
  grd_Offer.MasterDetailRequest = ls_Request
  
  Call CalculateOfferSummary
  Call DisplayOfferSummary
  Exit Sub
ErrHandler:
  Call ErrorHandler("RefreshOfferDetail")
End Sub

Private Sub DisplayOfferSummary()
On Error GoTo ErrHandler

Dim ld_OfferMargin As Double
  
  If md_OfferCost > 0 Then
    ld_OfferMargin = mo_OfferPos.GetDiscountMargin(md_OfferCost, md_OfferPrice)
    txt_OfferMargin.Text = mo_Tools.DblToScreen(ld_OfferMargin)
  Else
    txt_OfferMargin.Text = ""
  End If
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("DisplayOfferSummary")
End Sub

Private Sub RefreshPosList()
On Error GoTo ErrHandler

Dim ls_req As String
  
  ls_req = "exec Cap_OfferPosList_lst $COF_Id$, $COF_Lang$, $PosListPosFrom$, $PosListPosTo$, $PosListLevelFrom$, $PosListLevelTo$," & _
    "$PosListCodeFrom$, $PosListCodeTo$, $PosListDrawNrFrom$, $PosListDrawNrTo$, $PosListCHFrom$, $PosListCHTo$, $PosListDHFrom$, $PosListDHTo$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
  
  ls_req = Replace(ls_req, "$PosListPosFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHTo").Text)), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call grd_PosList.Load(ls_req, True)
  chk_PosListSelectAll.Value = vbUnchecked
  Exit Sub
ErrHandler:
  Call ErrorHandler("RefreshPosList")
End Sub

Private Sub RefreshPacking()
On Error GoTo ErrHandler

Dim ls_req As String
  
  ls_req = "exec Cap_OfferPacking_lst $COF_Id$, $Language_Code$, $PosListPosFrom$, $PosListPosTo$, $PosListLevelFrom$, $PosListLevelTo$," & _
    "$PosListCodeFrom$, $PosListCodeTo$, $PosListDrawNrFrom$, $PosListDrawNrTo$, $PosListCHFrom$, $PosListCHTo$, $PosListDHFrom$, $PosListDHTo$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHTo").Text)), , , vbTextCompare)
  Call grd_Packing.Load(ls_req, True)
  Exit Sub
ErrHandler:
  Call ErrorHandler("RefreshPacking")
End Sub

Private Sub CalculateSubtotal(ByVal ao_grid As ArmGrid, ByVal as_GroupColumn As String, ByVal av_SumColumns As Variant)
On Error GoTo ErrHandler

  Dim ld_Values() As Double
  Dim ll_RowIdx As Long
  Dim ll_ColIdx As Long
  Dim lv_LastGroupValue As Variant
  Dim ll_Count As Long
  
  ll_Count = ao_grid.Rows
  If ll_Count > 0 Then
  
    If IsArray(av_SumColumns) Then
      ReDim ld_Values(UBound(av_SumColumns))
    Else
      ReDim ld_Values(-1 To -1)
    End If
    
    For ll_ColIdx = 0 To UBound(ld_Values)
      ld_Values(ll_ColIdx) = 0
    Next
    lv_LastGroupValue = ao_grid.Data(0, as_GroupColumn)

    While ll_RowIdx < ll_Count
    
      If ao_grid.Data(ll_RowIdx, as_GroupColumn) = lv_LastGroupValue Then
        For ll_ColIdx = 0 To UBound(ld_Values)
          ld_Values(ll_ColIdx) = ld_Values(ll_ColIdx) + ao_grid.Data(ll_RowIdx, av_SumColumns(ll_ColIdx))
        Next
      End If
      
      If ll_RowIdx > 0 Then
        If ao_grid.Data(ll_RowIdx, as_GroupColumn) <> lv_LastGroupValue Then
          Call ao_grid.InsertLine(ll_RowIdx)
          ll_Count = ll_Count + 1
          ao_grid.LineColor(ll_RowIdx) = vbButtonFace
          For ll_ColIdx = 0 To UBound(ld_Values)
            ao_grid.Data(ll_RowIdx, av_SumColumns(ll_ColIdx)) = ld_Values(ll_ColIdx)
            ld_Values(ll_ColIdx) = 0
          Next
          lv_LastGroupValue = ao_grid.Data(ll_RowIdx + 1, as_GroupColumn)
        End If
      End If
      ll_RowIdx = ll_RowIdx + 1
    Wend
    Call ao_grid.AddLine
    ll_RowIdx = ao_grid.Rows - 1
    ao_grid.LineColor(ll_RowIdx) = vbButtonFace
    For ll_ColIdx = 0 To UBound(ld_Values)
      ao_grid.Data(ll_RowIdx, av_SumColumns(ll_ColIdx)) = ld_Values(ll_ColIdx)
    Next
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("CalculateSubtotal")
End Sub

Private Sub MarkGridRows(ByVal ao_grid As ArmGrid, ByVal as_TestCol As String, ByVal as_TestValue As String, ByVal as_MarkCol As String, ByVal al_Color As Long)
On Error GoTo ErrHandler

Dim ll_Idx As Long
  
  For ll_Idx = 0 To ao_grid.Rows - 1
    If StrComp(ao_grid.Data(ll_Idx, as_TestCol), as_TestValue, vbTextCompare) = 0 Then
      ao_grid.CellColor(ll_Idx, as_MarkCol) = al_Color
    End If
  Next
  Exit Sub
ErrHandler:
  Call ErrorHandler("MarkGridRows")
End Sub

Private Sub RefreshBOM()
On Error GoTo ErrHandler

Dim ls_req As String

  
  ls_req = "exec Cap_OfferBOM_lst $COF_Id$, $Language_Code$, $PosListPosFrom$, $PosListPosTo$, $PosListLevelFrom$, $PosListLevelTo$," & _
    "$PosListCodeFrom$, $PosListCodeTo$, $PosListDrawNrFrom$, $PosListDrawNrTo$, $PosListCHFrom$, $PosListCHTo$, $PosListDHFrom$, $PosListDHTo$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHTo").Text)), , , vbTextCompare)
  
  grd_BOM.Redraw = False
  Call grd_BOM.Load(ls_req, True)
  Call CalculateSubtotal(grd_BOM, "OFD_Pos", Array("BOM_DirectCost", "BOM_WasteCost", "BOM_RejectCost", "BOM_InflCost"))
  Call MarkGridRows(grd_BOM, "BOM_IdentNr", DPC_BOM_NEW_IDENTNR, "BOM_Pos", vbYellow)
  Call MarkGridRows(grd_BOM, "BOM_Status", eDPCBOMBORStatus.boGeneratedError, "BOM_Pos", vbRed)
  grd_BOM.Row = 0
  Call grd_BOM.DeselectRow
  grd_BOM.Redraw = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("RefreshBOM")
End Sub

Private Sub RefreshBOR()
On Error GoTo ErrHandler

Dim ls_req As String
Dim ll_Idx As Long

  ls_req = "exec Cap_OfferBOR_lst $COF_Id$, $Language_Code$, $PosListPosFrom$, $PosListPosTo$, $PosListLevelFrom$, $PosListLevelTo$," & _
    "$PosListCodeFrom$, $PosListCodeTo$, $PosListDrawNrFrom$, $PosListDrawNrTo$, $PosListCHFrom$, $PosListCHTo$, $PosListDHFrom$, $PosListDHTo$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHTo").Text)), , , vbTextCompare)
  
  grd_BOR.Redraw = False
  Call grd_BOR.Load(ls_req, True)
  Call CalculateSubtotal(grd_BOR, "OFD_Pos", Array("BOR_VarMasCost", "BOR_VarPerCost", "BOR_Teko", "BOR_DirectCost", "BOR_FixMasCost", "BOR_WasteCost", _
                        "BOR_DirectSetupCost", "BOR_SubtotalSetupCost", "BOR_TotSetupCost", _
                        "BOR_DirectWidSetupCost", "BOR_SubWidSetupCost", "BOR_TotWidSetupCost", _
                        "BOR_DirectLenSetupCost", "BOR_SubLenSetupCost", "BOR_TotLenSetupCost"))
  Call MarkGridRows(grd_BOR, "BOR_Status", eDPCBOMBORStatus.boGeneratedError, "BOR_Pos", vbRed)
  grd_BOR.Row = 0
  Call grd_BOR.DeselectRow
  grd_BOR.Redraw = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("RefreshBOR")
End Sub

Private Sub RefreshCost()
On Error GoTo ErrHandler

Dim ls_req As String
  
  ls_req = "exec Cap_OfferCost_lst $COF_Id$, $Language_Code$, $PosListPosFrom$, $PosListPosTo$, $PosListLevelFrom$, $PosListLevelTo$," & _
    "$PosListCodeFrom$, $PosListCodeTo$, $PosListDrawNrFrom$, $PosListDrawNrTo$, $PosListCHFrom$, $PosListCHTo$, $PosListDHFrom$, $PosListDHTo$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListPosTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListPosTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelFrom$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListLevelTo$", mo_Tools.SqlInt(mo_Tools.ScreenToLong(mo_Tools.GetControl(txt_PosListFilter, "PosListLevelTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCodeTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListCodeTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrFrom$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrFrom").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDrawNrTo$", mo_Tools.SQLStr(mo_Tools.GetControl(txt_PosListFilter, "PosListDrawNrTo").Text), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListCHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListCHTo").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHFrom$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHFrom").Text)), , , vbTextCompare)
  ls_req = Replace(ls_req, "$PosListDHTo$", mo_Tools.SqlDbl(mo_Tools.ScreenToDbl(mo_Tools.GetControl(txt_PosListFilter, "PosListDHTo").Text)), , , vbTextCompare)
  grd_Cost.Redraw = False
  Call grd_Cost.Load(ls_req, True)
  Call CalculateSubtotal(grd_Cost, "OFD_Pos", "")
  grd_Cost.Row = 0
  Call grd_Cost.DeselectRow
  grd_Cost.Redraw = True
  Exit Sub
ErrHandler:
  Call ErrorHandler("RefreshCost")
End Sub

Private Sub RefreshOfferHeader()
On Error GoTo ErrHandler

Dim ll_RowIdx As Long
Dim le_LEV_Id As eDPCLevel
Dim le_ErrType As eDPCErrorType

  le_LEV_Id = eDPCLevel.lvStandard
  For ll_RowIdx = 0 To grd_Offer.Rows - 1
    If grd_Offer.Data(ll_RowIdx, "OFD_Main") = eDPCOfferDetailMain.odMain Then
      If grd_Offer.Data(ll_RowIdx, "LEV_Id") > le_LEV_Id Then
        le_LEV_Id = grd_Offer.Data(ll_RowIdx, "LEV_Id")
      End If
    End If
  Next
  
  le_ErrType = eDPCErrorType.etNone
  For ll_RowIdx = 0 To grd_Offer.Rows - 1
    If grd_Offer.Data(ll_RowIdx, "OFD_Main") = eDPCOfferDetailMain.odMain Then
      If grd_Offer.Data(ll_RowIdx, "ERR_Type") > le_ErrType Then
        le_ErrType = grd_Offer.Data(ll_RowIdx, "ERR_Type")
      End If
    End If
  Next
  

  Call cbo_Level.SearchItem(le_LEV_Id)
  
  If (Status = eOfferStatus.osNew) Or (Status = eOfferStatus.osOfferDefinition) Or (Status = eOfferStatus.osOfferNeedApproval) Or (Status = eOfferStatus.osApproved) Then
    If le_ErrType >= eDPCErrorType.etNeedApproval Then
      Status = eOfferStatus.osOfferNeedApproval
    Else
      Status = eOfferStatus.osOfferDefinition
    End If
  End If
  
  If mi_DisplayMode = mt_CstValues.DisplayMode_Update Then
    Call RecordUpdate(m_CurrentKey1)
    txt_updatedBy.Text = ms_LoginName
    txt_dateUpdated.Text = Format(Date, "dd\/mm\/yyyy")
  End If
  
  If (mi_DisplayMode = mt_CstValues.DisplayMode_Update) Or (mi_DisplayMode = mt_CstValues.DisplayMode_Add) Then
    Call mo_Tools.EnableControl(cbo_Template, (Not (cbo_Customer.SelectedItem Is Nothing)))
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("RefreshOfferHeader")
End Sub

Private Sub SetDefaultTemplate(ByVal as_CCU_Capkey As String)
On Error GoTo ErrHandler
    Const C_REQ As String = "SELECT TOP 1 CCU.CT_Code, COFT.COT_ID, COFT.Language_Code " & vbCrLf & _
                            "FROM Claim_Customer CCU" & vbCrLf & _
                            "LEFT JOIN Cap_OfferTemplate COFT ON (COFT.CT_Code = CCU.CT_Code AND COFT.COT_Type=$COT_Type$)" & vbCrLf & _
                            "WHERE CCU.CCU_Capkey = $ccu_capkey$" & vbCrLf
    
    Dim ls_req As String
    Dim lc_Template As Long
    
    
    Call cbo_Template.Clear
    ml_COT_Id = 0
    ms_COF_Lang = ms_Language_Code
    ms_CT_Code = ""
    
    ls_req = C_REQ
    ls_req = Replace(ls_req, "$ccu_capkey$", mo_Tools.SQLStr(as_CCU_Capkey), , , vbTextCompare)
    ls_req = Replace(ls_req, "$COT_Type$", mo_Tools.SqlInt(eOfferTemplate.otOffer), , , vbTextCompare)
    
    lc_Template = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    If mo_Db.RowCount(lc_Template) = 1 Then ' template found
      ms_CT_Code = mo_Db.GetFields(lc_Template, "CT_Code")
      ms_COF_Lang = mo_Db.GetFields(lc_Template, "Language_Code")
      ml_COT_Id = mo_Db.GetFields(lc_Template, "COT_ID")
      Call InitTemplateCombo(cbo_Template, ms_CT_Code)
      If ml_COT_Id > 0 Then
        Call cbo_Template.Load
        Call cbo_Template.SearchItem(ml_COT_Id)
      End If
    End If
    Call mo_Db.Close(lc_Template)
    Exit Sub
ErrHandler:
    Call mo_Db.Close(lc_Template)
    Call ErrorHandler("SetDefaultTemplate")
End Sub

Private Function GetCOF_Code(ByVal as_COF_Code As String) As String
On Error GoTo ErrHandler

Dim ls_COF_CodeNew As String
Dim ls_COF_CodeMax As String
Dim ls_Code() As String
Dim ls_CodeMax() As String
Dim ls_Ver As String

  If Trim(as_COF_Code) = "" Then
    ls_COF_CodeNew = mo_Tools.GetNextID(mo_Db, "COF_Code") & ".A"
  Else
    ls_Code = Split(as_COF_Code, ".")
    If UBound(ls_Code) = 0 Then
      ls_COF_CodeNew = ls_Code(0) & ".A"
    Else
      ls_COF_CodeMax = mo_Tools.SelectValue(mo_Db, "SELECT MAX(COF_Code) FROM Cap_Offer WHERE COF_Code LIKE " & mo_Tools.SQLStr(ls_Code(0) & ".%"))
      ls_CodeMax = Split(ls_COF_CodeMax, ".")
      ls_Ver = right(ls_CodeMax(1), 1)
      If Asc(ls_Ver) >= Asc("Z") Then
        ls_COF_CodeNew = mo_Tools.GetNextID(mo_Db, "COF_Code") & ".A"
      Else
        ls_Ver = Chr(Asc(ls_Ver) + 1)
        ls_COF_CodeNew = ls_Code(0) & "." & ls_Ver
      End If
    End If
  End If
  GetCOF_Code = ls_COF_CodeNew
  Exit Function
ErrHandler:
  Call ErrorHandler("GetCOF_Code")
End Function

Private Function GetNextOFD_Pos() As Long
On Error GoTo ErrHandler

Dim ls_req As String
Dim ll_Pos As Long

  ls_req = "exec Cap_OfferDetail_NextOFD_Pos $COF_Id$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
  ll_Pos = Val(mo_Tools.SelectValue(mo_Db, ls_req))
  If (ll_Pos Mod 100) > 0 Then
    ll_Pos = 100 * (ll_Pos \ 100)
  End If
  GetNextOFD_Pos = ll_Pos
  Exit Function
ErrHandler:
  Call ErrorHandler("GetNextOFD_Pos")
End Function

Private Function HasAlternateProduct(ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler

Dim ls_req As String
  
  'ls_req = "SELECT TOP 1 OFD_Id FROM Cap_OfferDetail WHERE COF_Id=$COF_Id$ AND OFD_AltPa=$OFD_AltPa$ AND Drop_Flag=''"
  ls_req = "exec Cap_OfferDetail_HasAlt $COF_Id$, $OFD_AltPa$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_AltPa$", mo_Tools.SQLStr(ao_OfferPos.OFD_Id), , , vbTextCompare)
  HasAlternateProduct = mo_Tools.ExistsRecord(mo_Db, ls_req)
  Exit Function
ErrHandler:
  Call ErrorHandler("HasAlternateProduct")
End Function

Public Sub LoadOfferGrid(ByVal as_COF_Code As String)
On Error GoTo ErrHandler

  Call grdlst.Load("SELECT * FROM Cap_Offer WHERE COF_Code=" & mo_Tools.SQLStr(as_COF_Code), True)
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadOfferGrid")
End Sub

Public Sub LoadOfferProductCodeGrid(ByVal as_PRD_Code As String)
On Error GoTo ErrHandler

  Call grdlst.Load("SELECT * FROM Cap_Offer WHERE COF_Id IN (SELECT COF_Id FROM Cap_OfferDetail WHERE PRD_Code=" & mo_Tools.SQLStr(as_PRD_Code) & ")", True)
  Exit Sub
ErrHandler:
  Call ErrorHandler("LoadOfferProductCodeGrid")
End Sub

Private Function LoadOfferDetail(ByVal as_COF_Id As String, ByVal as_OFD_IdPar As String, ByVal ae_Main As eDPCOfferDetailMain) As Collection
On Error GoTo ErrHandler

Dim lo_Offer As DPC_OfferPos
Dim lo_Collection As Collection
Dim ls_req As String
Dim lc_Cursor As Long
  
  Set lo_Collection = New Collection
  ls_req = "exec Cap_OfferDetail_lst2 $COF_Id$, $COF_Lang$, $OFD_Main$, $OFD_IdPar$, $OFD_Valid$, $OFD_Id$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_Main$", mo_Tools.SqlIntKey(ae_Main), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_IdPar$", mo_Tools.SqlStrKey(as_OFD_IdPar), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_Valid$", "NULL", , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_Id$", "NULL", , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  While Not mo_Db.EOF(lc_Cursor)
    Set lo_Offer = New DPC_OfferPos
    Set lo_Offer.Tools = mo_Tools
    Call lo_Offer.Init(0, 0, eDPCQtyType.qtUnknown, 0, 0, 0)
    Call lo_Offer.ReadOfferPos(mo_Db, lc_Cursor)
    Call lo_Collection.Add(lo_Offer)
    Call mo_Db.Next(lc_Cursor)
  Wend
  Call mo_Db.Close(lc_Cursor)
  Set LoadOfferDetail = lo_Collection
  Exit Function
ErrHandler:
  Call ErrorHandler("LoadOfferDetail")
End Function

Private Function SaveOfferDetail(ByVal ao_Collection As Collection, ByVal as_OFD_IdPar As String, ByVal ad_COF_DocDat As Date, ByVal as_COF_CURR_Code, ByVal ae_DstOfferStatus As eOfferStatus) As String
On Error GoTo ErrHandler

Dim lo_Offer As DPC_OfferPos
Dim ls_Request As String
Dim ld_rate As Double
Dim ls_OFD_CURR_Code As String
Dim ls_OFD_IdPar As String

  SaveOfferDetail = ""
  If ao_Collection Is Nothing Then
    Err.rase ArmErr.InvalidArgument, "ao_Collection", "Invalid collection"
  End If
  
  If ao_Collection.Count = 0 Then
    Err.rase ArmErr.InvalidArgument, "ao_Collection", "Empty collection"
  End If
  
  If as_OFD_IdPar = "" Then
    ls_OFD_IdPar = mo_Tools.GetNextID(mo_Db, "Cap_OfferDetail")
  Else
    ls_OFD_IdPar = as_OFD_IdPar
    ' delete all existing child records and keep main, because possible existing relationship link to alternate product
    Call SubRecordChildDelete(ls_OFD_IdPar)
  End If
  ls_OFD_CURR_Code = ao_Collection(1).CURR_Code
  ld_rate = mo_Tools.SelectExchangeRate(mo_Db, ls_OFD_CURR_Code, as_COF_CURR_Code, ad_COF_DocDat)
  
  For Each lo_Offer In ao_Collection
    lo_Offer.OFD_Rate = ld_rate
    If (lo_Offer.DOF_Id = eDPCOfferDetail.odPosition) Or _
       (lo_Offer.DOF_Id = eDPCOfferDetail.odSubconstPosition) Or _
       (lo_Offer.DOF_Id = eDPCOfferDetail.odManualPosition) Then
      lo_Offer.OFD_IdPar = ls_OFD_IdPar
      lo_Offer.OFD_Id = ls_OFD_IdPar
      
      If (lo_Offer.LEV_Id > eDPCLevel.lvStandard) And (mb_HasLevel2) Then
        lo_Offer.OFD_AppBy = ml_U_Code
        lo_Offer.OFD_ApDat = Date
      End If
      If as_OFD_IdPar = "" Then
        If (ae_DstOfferStatus = eOfferStatus.osBaeurerSalesOrder) Or _
           (ae_DstOfferStatus = eOfferStatus.osSAPSalesOrder) Or _
           (ae_DstOfferStatus = eOfferStatus.osBaeurerSalesOrderChange) Or _
           (ae_DstOfferStatus = eOfferStatus.osSAPSalesOrderChange) Then
          lo_Offer.OFD_SAPAct = "A"
        End If
        Call SubRecordAdd(lo_Offer)
      Else
        If (ae_DstOfferStatus = eOfferStatus.osBaeurerSalesOrder) Or _
           (ae_DstOfferStatus = eOfferStatus.osSAPSalesOrder) Or _
           (ae_DstOfferStatus = eOfferStatus.osBaeurerSalesOrderChange) Or _
           (ae_DstOfferStatus = eOfferStatus.osSAPSalesOrderChange) Then
          If StrComp(lo_Offer.OFD_SAPAct, "A") <> 0 Then
            lo_Offer.OFD_SAPAct = "R"
          End If
        End If
        ' update main record, because possible existing relationship link to alternate product
        Call SubRecordUpdate(lo_Offer)
      End If
    ElseIf lo_Offer.DOF_Id = eDPCOfferDetail.odOption Then
      If lo_Offer.RowStatus = eDPCRowStatus.rsAdd Then
        lo_Offer.OFD_Id = mo_Tools.GetNextID(mo_Db, "Cap_OfferDetail")
        lo_Offer.OFD_IdPar = lo_Offer.OFD_Id
        Call SubRecordAdd(lo_Offer)
      ElseIf lo_Offer.RowStatus = eDPCRowStatus.rsUpdate Then
        Call SubRecordUpdate(lo_Offer)
      ElseIf lo_Offer.RowStatus = eDPCRowStatus.rsDrop Then
        Call SubRecordDrop(lo_Offer.OFD_IdPar)
      End If
    Else
      lo_Offer.OFD_IdPar = ls_OFD_IdPar
      lo_Offer.OFD_Id = mo_Tools.GetNextID(mo_Db, "Cap_OfferDetail")
      lo_Offer.OFD_WshDat = 0
      lo_Offer.OFD_ShpDat = 0
      lo_Offer.OFD_DelDat = 0
      Call SubRecordAdd(lo_Offer)
    End If
  Next
  SaveOfferDetail = ls_OFD_IdPar
  Exit Function
ErrHandler:
  Call ErrorHandler("SaveOfferDetail")
End Function

Private Sub tbs_OfferDetail_Click()
On Error GoTo ErrHandler

  If StrComp(tbs_OfferDetail.SelectedItem.Key, "tab_Detail", vbTextCompare) = 0 Then
    grd_Offer.Columns("OFD_Pos").Width = 600
    tlb_Subitem.ButtonEnabled("A") = True
    tlb_Subitem.ButtonEnabled("B") = True
    tlb_Subitem.ButtonEnabled("X") = True
  ElseIf StrComp(tbs_OfferDetail.SelectedItem.Key, "tab_Alt", vbTextCompare) = 0 Then
    grd_Offer.Columns("OFD_Pos").Width = 0
    tlb_Subitem.ButtonEnabled("A") = False
    tlb_Subitem.ButtonEnabled("B") = True
    tlb_Subitem.ButtonEnabled("X") = True
  Else
    grd_Offer.Columns("OFD_Pos").Width = 0
    tlb_Subitem.ButtonEnabled("A") = False
    tlb_Subitem.ButtonEnabled("B") = False
    tlb_Subitem.ButtonEnabled("X") = False
  End If
  
  tbs_Offer.Visible = StrComp(tbs_OfferDetail.SelectedItem.Key, "tab_Detail", vbTextCompare) = 0
  Call RefreshOfferDetail
  Exit Sub
ErrHandler:
  Call ErrorMessage("tbs_OfferDetail_Click")
End Sub

Private Sub tbs_Offer_Click()
On Error GoTo ErrHandler
  
  grd_Offer.Visible = False
  'fra_PosList.Visible = False
  If tbs_Offer.SelectedItem.Index = 1 Then
    grd_Offer.Visible = True
    grd_Offer.Columns("OFD_Price").Width = 1100
    grd_Offer.Columns("OFD_TotalP").Width = 1100
    grd_Offer.Columns("OFD_PriceR").Width = 1100
    grd_Offer.Columns("OFD_TotalR").Width = 1100
    grd_Offer.Columns("OFD_PriceMain").Width = 0
    grd_Offer.Columns("OFD_TotalPMain").Width = 0
    grd_Offer.Columns("OFD_PriceRMain").Width = 0
    grd_Offer.Columns("OFD_TotalRMain").Width = 0
  ElseIf tbs_Offer.SelectedItem.Index = 2 Then
    grd_Offer.Visible = True
    grd_Offer.Columns("OFD_Price").Width = 0
    grd_Offer.Columns("OFD_TotalP").Width = 0
    grd_Offer.Columns("OFD_PriceR").Width = 0
    grd_Offer.Columns("OFD_TotalR").Width = 0
    grd_Offer.Columns("OFD_PriceMain").Width = 1100
    grd_Offer.Columns("OFD_TotalPMain").Width = 1100
    grd_Offer.Columns("OFD_PriceRMain").Width = 1100
    grd_Offer.Columns("OFD_TotalRMain").Width = 1100
  ElseIf tbs_Offer.SelectedItem.Index = 3 Then
    'Call RefreshPosList
    'fra_PosList.Visible = True
  End If
  Exit Sub
ErrHandler:
  Call ErrorMessage("tbs_Offer_Click")
End Sub

' Embed a component
Private Sub tbsEmbedded_Click()
On Error GoTo ErrHandler
    
  If mi_EmbedTag = UserControl.tbsEmbedded.SelectedItem.Tag Then Exit Sub
  
  Call mo_Tools.LockScreen(Me, True)
  With UserControl
      
      If mi_EmbedTag <> -1 Then
          RaiseEvent Release
          mi_EmbedTag = -1
      End If
      
      If .tbsEmbedded.SelectedItem.Index = 1 Then
          If mi_EmbeddedIn <> -1 Then
               RaiseEvent SwitchToView(mt_CstValues.View_Medium)
          End If
          .fraItemBottom.Visible = True
      Else
          .fraItemBottom.Visible = False
          If mi_EmbeddedIn <> -1 Then
              If .tbsEmbedded.SelectedItem.Tag = mt_CstValues.Tag_Memo Then
                   RaiseEvent SwitchToView(mt_CstValues.View_Medium)
              Else
                  RaiseEvent SwitchToView(mt_CstValues.View_Full)
              End If
          End If
          mi_EmbedTag = .tbsEmbedded.SelectedItem.Tag
          RaiseEvent Catch(mi_EmbedTag, m_CurrentKey1 & CH_LDELIMIT & m_CurrentKey2)
      End If
  End With

  Call mo_Tools.LockScreen(Me, False)
  Exit Sub
ErrHandler:
  Call ErrorMessage("tbsEmbedded_Click")
End Sub


Private Sub AddInitFields()
On Error GoTo ErrHandler
    Dim ls_Request As String
    
    
    ms_COF_Lang = ms_Language_Code
    ml_COT_Id = 0
    ms_CT_Code = ""
    
    ls_Request = "SELECT SP_Desc FROM sales_project WHERE SP_Capkey=$SP_Capkey$"
    ls_Request = Replace(ls_Request, "$SP_Capkey$", mo_Tools.SQLStr(m_Project), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    txt_SP_Desc.Text = mo_Tools.SelectValue(mo_Db, ls_Request)
   
    txt_COF_ID.Text = "NEW"
    txt_COF_Code.Text = GetCOF_Code("")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Code", txt_COF_Code.Text)
    Call mo_Tools.SetTextValue(txt_Textbox, "SP_Capkey", m_Project)
    Call mo_Tools.SetTextValue(txt_Textbox, "SP_Capkey2", m_Project)
    txt_COF_Desc.Text = ""
    txt_COF_Comm.Text = ""
    
    Status = eOfferStatus.osNew
    Call cbo_Level.SearchItem(eDPCLevel.lvStandard)
    txt_Version.Text = "1"
    opt_OfferType(0).Value = True
    opt_OfferPriority(0).Value = True
    
    ls_Request = "exec Cap_Subproject_cbo $SP_Capkey$, $Language_Code$"
    ls_Request = Replace(ls_Request, "$SP_Capkey$", mo_Tools.SQLStr(m_Project), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    cbo_SubProject.Request = ls_Request
    
    ls_Request = _
      "SELECT CCU.CCU_Capkey, CCU.CCU_Desc " & _
      "FROM claim_customer CCU " & _
      "INNER JOIN Cap_ProjectCompany PC ON (CCU.CCU_Capkey=PC.CCU_Capkey AND PC.SP_Capkey=$SP_Capkey$) " & _
      "WHERE CCU.Drop_Flag = ''"
      
    ls_Request = Replace(ls_Request, "$SP_Capkey$", mo_Tools.SQLStr(m_Project), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    cbo_Customer.Request = ls_Request

    cbo_Contact.Enabled = False
    Call InitTemplateCombo(cbo_Template, ms_CT_Code)
    
    If cbo_LegalEntity.Count = 0 Then
      Call cbo_LegalEntity.Load
    End If
    'Call cbo_LegalEntity.SearchItem(1)
    
    txt_createdBy.Text = ms_LoginName
    txt_updatedBy.Text = ms_LoginName
    txt_dateEntered.Text = Format(Date, "dd\/mm\/yyyy")
    txt_dateUpdated.Text = Format(Date, "dd\/mm\/yyyy")
    Call mo_Tools.SetCalendarDate(cal_COF_DocDat, Date)
    If Not cbo_currencies.SearchItem("EUR") Then
      Call cbo_currencies.AddItem(Array("EUR", "EUR"), True)
    End If
    
    Set tbs_Offer.SelectedItem = tbs_Offer.Tabs(1)
'    cal_COF_ExDat.date_courte = Format(Date + 30, "dd\/mm\/yyyy")
'
'    txt_COF_MaxLot.Text = "1"
'    txt_COF_MaxOrd.Text = "1"
'
'    txt_COF_MinWeek.Text = "6"
'    txt_COF_MaxWeek.Text = "8"
    
    chk_DropFlag.Visible = False
    txt_DropDate.Visible = False

    DisplayDefaultValues
    
    Call InitVendorCombo(cbo_Vendor)
    Call InitShipPointCombo(cbo_ShipPoint)
    Exit Sub
ErrHandler:
    Call ErrorHandler("AddInitFields")
End Sub

Private Sub BlankFields()
On Error GoTo ErrHandler
    Dim ls_req As String
    
    mb_InternalInit = True
    Set tbs_Header.SelectedItem = tbs_Header.Tabs(1)
    Call tbs_Header_Click
    txt_SP_Desc.Text = ""
    txt_COF_Desc.Text = ""
    txt_COF_Comm.Text = ""

    Set cbo_Customer.SelectedItem = Nothing
    Set cbo_Contact.SelectedItem = Nothing
    Set cbo_SubProject.SelectedItem = Nothing
    Set cbo_Status.SelectedItem = Nothing
    Set cbo_currencies.SelectedItem = Nothing
    Set cbo_Level.SelectedItem = Nothing
    Set cbo_TOF1.SelectedItem = Nothing
    Set cbo_TOF2.SelectedItem = Nothing
    Set cbo_Probability.SelectedItem = Nothing
    Set cbo_BuiltStatus.SelectedItem = Nothing
    Set cbo_AltQuote.SelectedItem = Nothing
    Set cbo_MainFamily.SelectedItem = Nothing
    Set cbo_MainLevel.SelectedItem = Nothing
    Set cbo_Specification.SelectedItem = Nothing

    
    Set cbo_LegalEntity.SelectedItem = Nothing
    Set cbo_PM_Office.SelectedItem = Nothing
    
    opt_OfferType(0).Value = True
    opt_OfferPriority(0).Value = True
    txt_Version.Text = ""
    
    cal_COF_ExDat.reinit_cal
    cal_COF_FoDat.reinit_cal
    cal_COF_WshDat.reinit_cal
    cal_COF_ShpDat.reinit_cal
    cal_COF_DelDat.reinit_cal
    cal_COF_ApDat.reinit_cal
    cal_COF_DocDat.reinit_cal
    
    txt_COF_DeDesc.Text = ""
    txt_COF_DeAdr1.Text = ""
    txt_COF_DeAdr2.Text = ""
    txt_COF_DeTown.Text = ""
    txt_COF_DeZip.Text = ""
    Set cbo_COF_DeCT.SelectedItem = Nothing
    txt_COF_CodeCus.Text = ""
    
    txt_COF_MaxLot.Text = ""
    txt_COF_MinWeek.Text = ""
    txt_COF_MaxWeek.Text = ""
    txt_COF_MaxOrd.Text = ""
    
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Code", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_Konto", "")
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_KontoDesc", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "SP_Capkey", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "SP_Capkey2", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_CodeBae", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_OrdTyp", "")
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_OrdTypDesc", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_Partner", "")
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_PartnerDesc", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_CodeCus", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_BestNr2", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_InCharge", "")
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_InChargeDesc", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_DelCond", "")
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_DelCondDesc", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_DelType", "")
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_DelTypeDesc", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_PackType", "")
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_PackTypeDesc", "")
    
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Desc", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Addr1", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Addr2", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Town", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Zip", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_CT_Desc", "")
    Call mo_Tools.SetTextValue(txt_Textbox, "CUST_Code", "")
    
    chk_DropFlag.Value = 0
    txt_DropDate.Text = ""
    
    Call grd_Offer.ClearGrid
    mb_grd_ProductsLoaded = False
    mb_InternalInit = False
    Exit Sub
    
ErrHandler:
    Call ErrorHandler("BlankFields")
End Sub

Private Sub DisplayDefaultValues()
On Error GoTo ErrHandler
    Dim TheControl As Control
    Dim TheControlName As String
    
    If p_DefaultValuesLoaded = False Then
        p_DefaultValuesCount = GetScreenDefaultValues(mo_Db, ms_LoginName, ms_Language_Code, "Cap_Offer_Detail", p_DefaultValues)
        p_DefaultValuesLoaded = True
    End If
    DisplayScreenDefaultValues UserControl.Controls, p_DefaultValues, p_DefaultValuesCount

    Exit Sub
ErrHandler:
    Call ErrorHandler("DisplayDefaultValues")
End Sub


Private Sub DisplayCountryDefaultValues(ByVal as_CT_Code As String)
On Error GoTo ErrHandler

Dim ls_req As String
Dim lc_Cursor As Long

  ls_req = "exec DPC_DefaultValue_lst $DFT_ScreenName$, $CT_Code$, $Language_Code$"
  ls_req = Replace(ls_req, "$DFT_ScreenName$", mo_Tools.SQLStr("Offer_Cfg"), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CT_Code$", mo_Tools.SQLStr(as_CT_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$Language_Code$", mo_Tools.SQLStr("E"), , , vbTextCompare)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  
  If mo_Db.Find(lc_Cursor, "DFT_FieldName", "ExpiryDateInc", , 1) >= 0 Then
    cal_COF_ExDat.date_courte = Format(Date + Val(mo_Db.GetFields(lc_Cursor, "DFT_Code")), "dd\/mm\/yyyy")
  End If
  If mo_Db.Find(lc_Cursor, "DFT_FieldName", "MaxLot", , 1) >= 0 Then
    txt_COF_MaxLot.Text = mo_Db.GetFields(lc_Cursor, "DFT_Code")
  End If
  If mo_Db.Find(lc_Cursor, "DFT_FieldName", "MaxOrd", , 1) >= 0 Then
    txt_COF_MaxOrd.Text = mo_Db.GetFields(lc_Cursor, "DFT_Code")
  End If
  If mo_Db.Find(lc_Cursor, "DFT_FieldName", "MinWeek", , 1) >= 0 Then
    txt_COF_MinWeek.Text = mo_Db.GetFields(lc_Cursor, "DFT_Code")
  End If
  If mo_Db.Find(lc_Cursor, "DFT_FieldName", "MaxWeek", , 1) >= 0 Then
    txt_COF_MaxWeek.Text = mo_Db.GetFields(lc_Cursor, "DFT_Code")
  End If
  
  Call mo_Db.Close(lc_Cursor)
  Exit Sub
ErrHandler:
  Call ErrorHandler("DisplayCountryDefaultValues")
End Sub

Private Sub ViewInitFields()
On Error GoTo ErrHandler

Dim ls_Request As String
Dim ll_Cursor As Long
'Dim le_ZipExport As eDPCBaeurerZipExport
'Dim lsa_Zip2Countries() As String
'Dim ll_Idx As Long
    
    If m_CurrentKey1 = "" Then Exit Sub
    
    mb_InternalInit = True
    txt_COF_ID.Text = m_CurrentKey1
        
    ls_Request = "exec Cap_Offer_sel $COF_Id$, $Language_Code$"
    ls_Request = Replace(ls_Request, "$COF_Id$", mo_Tools.SQLStr(txt_COF_ID.Text), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_Request)
    
    If IsProduction Then
      m_Project = mo_Db.GetFields(ll_Cursor, "SP_CapKey")
    End If
    
    ml_iConcurrency = mo_Db.GetFields(ll_Cursor, "iConcurrency")
    txt_COF_Code.Text = mo_Db.GetFields(ll_Cursor, "COF_Code")
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Code", mo_Db.GetFields(ll_Cursor, "COF_Code"))
    txt_COF_CodeCus.Text = mo_Db.GetFields(ll_Cursor, "COF_CodeCus")
    txt_Version.Text = mo_Db.GetFields(ll_Cursor, "COF_Vers")
    txt_COF_Desc.Text = mo_Db.GetFields(ll_Cursor, "COF_Desc")
    txt_COF_Comm.Text = mo_Db.GetFields(ll_Cursor, "COF_Comm")
    txt_SP_Desc.Text = mo_Db.GetFields(ll_Cursor, "SP_Desc")
    Call mo_Tools.SetCalendarDate(cal_COF_ExDat, mo_Db.GetFields(ll_Cursor, "COF_ExDat"))
    Call mo_Tools.SetCalendarDate(cal_COF_FoDat, mo_Db.GetFields(ll_Cursor, "COF_FoDat"))
    Call mo_Tools.SetCalendarDate(cal_COF_ApDat, mo_Db.GetFields(ll_Cursor, "COF_ApDat"))
    Call mo_Tools.SetCalendarDate(cal_COF_DocDat, mo_Db.GetFields(ll_Cursor, "COF_DocDat"))
    
    If StrComp(mo_Db.GetFields(ll_Cursor, "COF_AllPr"), "X", vbTextCompare) = 0 Then
      Set tbs_Offer.SelectedItem = tbs_Offer.Tabs(1)
    Else
      Set tbs_Offer.SelectedItem = tbs_Offer.Tabs(2)
    End If
    
    If mo_Db.GetFields(ll_Cursor, "COF_Type") = eOfferType.otBudget Then
        opt_OfferType(0).Value = True
    ElseIf mo_Db.GetFields(ll_Cursor, "COF_Type") = eOfferType.otAdvanced Then
        opt_OfferType(1).Value = True
    ElseIf mo_Db.GetFields(ll_Cursor, "COF_Type") = eOfferType.otFinal Then
        opt_OfferType(2).Value = True
    End If
        
    If mo_Db.GetFields(ll_Cursor, "COF_Prior") = eOfferPriority.opNormal Then
        opt_OfferPriority(0).Value = True
    ElseIf mo_Db.GetFields(ll_Cursor, "COF_Prior") = eOfferPriority.opPriority Then
        opt_OfferPriority(1).Value = True
    ElseIf mo_Db.GetFields(ll_Cursor, "COF_Prior") = eOfferPriority.opTopSpeed Then
        opt_OfferPriority(2).Value = True
    End If
    
    ls_Request = "exec Cap_SubProject_cbo $SP_Capkey$,$Language_Code$"
    ls_Request = Replace(ls_Request, "$SP_CapKey$", mo_Tools.SQLStr(m_Project), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    cbo_SubProject.Request = ls_Request
    
    Call cbo_SubProject.AddItem(Array(mo_Db.GetFields(ll_Cursor, "SPR_Id"), mo_Db.GetFields(ll_Cursor, "SPR_Name")), True)
    
    Call cbo_COF_AppBy.Clear
    Call cbo_COF_AppBy.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_AppBy"), mo_Db.GetFields(ll_Cursor, "COF_AppByDesc")), True)
    
    ls_Request = "exec Cap_OfferCompany_cbo $SP_Capkey$,$Language_Code$"
    ls_Request = Replace(ls_Request, "$SP_CapKey$", mo_Tools.SQLStr(m_Project), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    cbo_Customer.Request = ls_Request
    Call cbo_Customer.AddItem(Array(mo_Db.GetFields(ll_Cursor, "CCU_CapKey"), mo_Db.GetFields(ll_Cursor, "CCU_Desc")), True)
    ms_CT_Code = mo_Db.GetFields(ll_Cursor, "CT_Code")
    ml_COT_Id = mo_Db.GetFields(ll_Cursor, "COT_Id")
    ms_COF_Lang = mo_Db.GetFields(ll_Cursor, "COF_Lang")
    'md_COF_DocDat = mo_Db.GetFields(ll_Cursor, "COF_DocDat")
    
    Call InitTemplateCombo(cbo_Template, ms_CT_Code)
    Call cbo_Template.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COT_Id"), mo_Db.GetFields(ll_Cursor, "COT_Desc"), mo_Db.GetFields(ll_Cursor, "COF_Lang")), True)
    Call InitContactCombo(cbo_Contact, m_Project, mo_Db.GetFields(ll_Cursor, "CCU_CapKey"))
    Call cbo_Contact.AddItem(Array(mo_Db.GetFields(ll_Cursor, "CNT_Code"), mo_Db.GetFields(ll_Cursor, "CNT_Desc")), True)
    
    If Not cbo_Status.SearchItem(mo_Db.GetFields(ll_Cursor, "COF_Stat")) Then
      Call cbo_Status.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_Stat"), mo_Db.GetFields(ll_Cursor, "COF_StatDesc")), True)
    End If
    
    Call cbo_Level.SearchItem(mo_Db.GetFields(ll_Cursor, "LEV_Id"))
    
    If Not cbo_currencies.SearchItem(mo_Db.GetFields(ll_Cursor, "CURR_Code")) Then
      Call cbo_currencies.AddItem(Array(mo_Db.GetFields(ll_Cursor, "CURR_Code"), mo_Db.GetFields(ll_Cursor, "CURR_Desc")), True)
    End If
      
    Call cbo_TOF1.Clear
    If mo_Db.GetFields(ll_Cursor, "COF_TOD1") <> 0 Then
      Call cbo_TOF1.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_TOD1"), mo_Db.GetFields(ll_Cursor, "COF_TOD1Desc")), True)
    End If
    
    Call cbo_TOF2.Clear
    If mo_Db.GetFields(ll_Cursor, "COF_TOD2") <> 0 Then
      Call cbo_TOF2.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_TOD2"), mo_Db.GetFields(ll_Cursor, "COF_TOD2Desc")), True)
    End If
    
    Call cbo_Probability.Clear
    If mo_Db.GetFields(ll_Cursor, "COF_Probability") <> 0 Then
      Call cbo_Probability.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_Probability"), mo_Db.GetFields(ll_Cursor, "COF_ProbabilityDesc")), True)
    End If
    Call cbo_BuiltStatus.Clear
    If mo_Db.GetFields(ll_Cursor, "COF_BuiltStat") <> 0 Then
      Call cbo_BuiltStatus.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_BuiltStat"), mo_Db.GetFields(ll_Cursor, "COF_BuiltStatDesc")), True)
    End If
    Call cbo_AltQuote.Clear
    If mo_Db.GetFields(ll_Cursor, "COF_AltQuote") <> 0 Then
      Call cbo_AltQuote.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_AltQuote"), mo_Db.GetFields(ll_Cursor, "COF_AltQuoteDesc")), True)
    End If
    Call cbo_MainFamily.Clear
    If mo_Db.GetFields(ll_Cursor, "COF_MainFamily") <> 0 Then
      Call cbo_MainFamily.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_MainFamily"), mo_Db.GetFields(ll_Cursor, "COF_MainFamilyDesc")), True)
    End If
    Call cbo_MainLevel.Clear
    If mo_Db.GetFields(ll_Cursor, "COF_MainLevel") <> 0 Then
      Call cbo_MainLevel.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_MainLevel"), mo_Db.GetFields(ll_Cursor, "COF_MainLevelDesc")), True)
    End If
    Call cbo_Specification.Clear
    If mo_Db.GetFields(ll_Cursor, "COF_Specification") <> 0 Then
      Call cbo_Specification.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_Specification"), mo_Db.GetFields(ll_Cursor, "COF_SpecificationDesc")), True)
    End If
    Call cbo_LegalEntity.Clear
    If mo_Db.GetFields(ll_Cursor, "LEN_Id") <> 0 Then
      Call cbo_LegalEntity.AddItem(Array(mo_Db.GetFields(ll_Cursor, "LEN_Id"), mo_Db.GetFields(ll_Cursor, "LEN_ShortName")), True)
    End If
    Call cbo_PM_Office.Clear
    If mo_Db.GetFields(ll_Cursor, "PMO_Id") <> 0 Then
      Call cbo_PM_Office.AddItem(Array(mo_Db.GetFields(ll_Cursor, "PMO_Id"), mo_Db.GetFields(ll_Cursor, "PMO_ShortName")), True)
    End If
    
    txt_COF_DeDesc.Text = mo_Db.GetFields(ll_Cursor, "COF_DeDesc")
    txt_COF_DeAdr1.Text = mo_Db.GetFields(ll_Cursor, "COF_DeAdr1")
    txt_COF_DeAdr2.Text = mo_Db.GetFields(ll_Cursor, "COF_DeAdr2")
    txt_COF_DeTown.Text = mo_Db.GetFields(ll_Cursor, "COF_DeTown")
    txt_COF_DeZip.Text = mo_Db.GetFields(ll_Cursor, "COF_DeZip")
    txt_COF_MaxLot.Text = mo_Tools.LongToScreen(mo_Db.GetFields(ll_Cursor, "COF_MaxLot"))
    txt_COF_MaxOrd.Text = mo_Tools.LongToScreen(mo_Db.GetFields(ll_Cursor, "COF_MaxOrd"))
    txt_COF_MinWeek.Text = mo_Tools.LongToScreen(mo_Db.GetFields(ll_Cursor, "COF_MinWeek"))
    txt_COF_MaxWeek.Text = mo_Tools.LongToScreen(mo_Db.GetFields(ll_Cursor, "COF_MaxWeek"))
    
    If Not cbo_COF_DeCT.SearchItem(mo_Db.GetFields(ll_Cursor, "COF_DeCT")) Then
      Call cbo_COF_DeCT.AddItem(Array(mo_Db.GetFields(ll_Cursor, "COF_DeCT"), mo_Db.GetFields(ll_Cursor, "COF_DeCTDesc")), True)
    End If
    Call cbo_U_CodeSlsRep.Clear
    Call cbo_U_CodeSlsRep.AddItem(Array(mo_Db.GetFields(ll_Cursor, "U_CodeSlsRep"), mo_Db.GetFields(ll_Cursor, "U_CodeSlsRepDesc")), True)
    Call cbo_U_CodePrjMan.Clear
    Call cbo_U_CodePrjMan.AddItem(Array(mo_Db.GetFields(ll_Cursor, "U_CodePrjMan"), mo_Db.GetFields(ll_Cursor, "U_CodePrjManDesc")), True)
    Call cbo_U_CodePrdMan.Clear
    Call cbo_U_CodePrdMan.AddItem(Array(mo_Db.GetFields(ll_Cursor, "U_CodePrdMan"), mo_Db.GetFields(ll_Cursor, "U_CodePrdManDesc")), True)
    
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_Konto", mo_Db.GetFields(ll_Cursor, "COF_Bae_Konto"))
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_KontoDesc", mo_Db.GetFields(ll_Cursor, "COF_Bae_KontoDesc"))
    Call mo_Tools.SetTextValue(txt_Textbox, "SP_Capkey", mo_Db.GetFields(ll_Cursor, "SP_Capkey"))
    Call mo_Tools.SetTextValue(txt_Textbox, "SP_CapKey2", mo_Db.GetFields(ll_Cursor, "SP_CapKey"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_CodeBae", mo_Db.GetFields(ll_Cursor, "COF_CodeBae"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_OrdTyp", mo_Db.GetFields(ll_Cursor, "COF_Bae_OrdTyp"))
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_OrdTypDesc", mo_Db.GetFields(ll_Cursor, "COF_Bae_OrdTypDesc"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_Partner", mo_Db.GetFields(ll_Cursor, "COF_Bae_Partner"))
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_PartnerDesc", mo_Db.GetFields(ll_Cursor, "COF_Bae_PartnerDesc"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_CodeCus", mo_Db.GetFields(ll_Cursor, "COF_CodeCus"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_BestNr2", mo_Db.GetFields(ll_Cursor, "COF_Bae_BestNr2"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_InCharge", mo_Db.GetFields(ll_Cursor, "COF_Bae_InCharge"))
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_InChargeDesc", mo_Db.GetFields(ll_Cursor, "COF_Bae_InChargeDesc"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_DelCond", mo_Db.GetFields(ll_Cursor, "COF_Bae_DelCond"))
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_DelCondDesc", mo_Db.GetFields(ll_Cursor, "COF_Bae_DelCondDesc"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_DelType", mo_Db.GetFields(ll_Cursor, "COF_Bae_DelType"))
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_DelTypeDesc", mo_Db.GetFields(ll_Cursor, "COF_Bae_DelTypeDesc"))
    Call mo_Tools.SetTextValue(txt_Textbox, "COF_Bae_PackType", mo_Db.GetFields(ll_Cursor, "COF_Bae_PackType"))
    Call mo_Tools.SetLabelText(lbl_Label, "_COF_Bae_PackTypeDesc", mo_Db.GetFields(ll_Cursor, "COF_Bae_PackTypeDesc"))
    
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Desc", mo_Db.GetFields(ll_Cursor, "CCU_Desc"))
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Addr1", mo_Db.GetFields(ll_Cursor, "CCU_Addr1"))
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Addr2", mo_Db.GetFields(ll_Cursor, "CCU_Addr2"))
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Town", mo_Db.GetFields(ll_Cursor, "CCU_Town"))
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_Zip", mo_Db.GetFields(ll_Cursor, "CCU_Zip"))
    Call mo_Tools.SetTextValue(txt_Textbox, "CCU_CT_Desc", mo_Db.GetFields(ll_Cursor, "CCU_CT_Desc"))
    Call mo_Tools.SetTextValue(txt_Textbox, "CUST_Code", mo_Db.GetFields(ll_Cursor, "CUST_Code"))
    
    txt_dateEntered.Text = Format(mo_Db.GetFields(ll_Cursor, "Z_Creation"), "dd\/mm\/yyyy")
    txt_dateUpdated.Text = Format(mo_Db.GetFields(ll_Cursor, "Z_Last_Upd"), "dd\/mm\/yyyy")
    txt_createdBy.Text = mo_Db.GetFields(ll_Cursor, "Z_CreatorDesc")
    txt_updatedBy.Text = mo_Db.GetFields(ll_Cursor, "Z_Last_Upd_UserDesc")

    chk_DropFlag.Value = IIf(mo_Db.GetFields(ll_Cursor, "drop_flag") = "X", 1, 0)
    txt_DropDate.Text = Cap_FormatDate(mo_Db.GetFields(ll_Cursor, "drop_date"))

    Call mo_Db.Close(ll_Cursor)
    
    chk_DropFlag.Visible = chk_DropFlag.Value
    txt_DropDate.Visible = chk_DropFlag.Value
    
    Call DisplayProcessButtons
    Call InitVendorCombo(cbo_Vendor)
    Call InitShipPointCombo(cbo_ShipPoint)
    Call RefreshOfferDetail
    mb_InternalInit = False
    Exit Sub
ErrHandler:
    Call mo_Db.Close(ll_Cursor)
    Call ErrorHandler("ViewInitFields")
End Sub

Private Sub DisplayProcessButtons()
On Error GoTo ErrHandler

Dim le_Status As eOfferStatus

    le_Status = GetNextOfferStatus(Status)
    If le_Status = eOfferStatus.osNone Then
      tlb_Item.ButtonTooltip("q") = "UNDEF"
    Else
      tlb_Item.ButtonTooltip("q") = mo_Tools.GetAReferenceData(eDPCReferenceML.rfOfferStatus, le_Status, ms_Language_Code)
    End If
    
    le_Status = GetPrevOfferStatus(Status)
    If le_Status = eOfferStatus.osNone Then
      tlb_Item.ButtonTooltip("r") = "UNDEF"
    Else
      tlb_Item.ButtonTooltip("r") = mo_Tools.GetAReferenceData(eDPCReferenceML.rfOfferStatus, le_Status, ms_Language_Code)
    End If
    tlb_Item.ButtonVisible("q") = (Status = eOfferStatus.osNew) Or _
                                  (Status = eOfferStatus.osOfferDefinition) Or _
                                  (Status = eOfferStatus.osOfferNeedApproval) Or _
                                  (Status = eOfferStatus.osUnderApprovalProcess) Or _
                                  (Status = eOfferStatus.osPlanningProcess) Or _
                                  (Status = eOfferStatus.osBaeurerSalesOrderChange) Or _
                                  (Status = eOfferStatus.osSAPSalesOrder)
    tlb_Item.ButtonVisible("r") = (Status = eOfferStatus.osUnderApprovalProcess) Or _
                                  (Status = eOfferStatus.osPlanningProcess) Or _
                                  (Status = eOfferStatus.osWaitCustConfirmation) Or _
                                  (Status = eOfferStatus.osDropped) Or _
                                  (Status = eOfferStatus.osSAPSalesOrder) Or _
                                  (Status = eOfferStatus.osBaeurerSalesOrder)
    Exit Sub
ErrHandler:
    Call ErrorHandler("DisplayProcessButtons")
End Sub

Private Sub ListProjectOf(ByVal AProjectKey1 As String, ByVal AProjectKey2 As String)
On Error GoTo ErrHandler

Dim ls_Request As String

    If Not (AProjectKey1 <> "" And AProjectKey2 <> "") Then Exit Sub
    Call grdlst.ClearGrid
    ls_Request = "exec Cap_Offer_lst $SP_Capkey$, NULL, $Language_Code$"
    ls_Request = Replace(ls_Request, "$SP_Capkey$", mo_Tools.SQLStr(AProjectKey1), , , vbTextCompare)
    ls_Request = ReplaceCommonPlaceholders(ls_Request)
    If Not grdlst.Load(ls_Request, True) Then
      Err.Raise ArmErr.CompFncFailed, "grdlst.Load", "Grid load failed: " & ls_Request
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("ListProjectOf")
End Sub

Private Sub ListCustomerOf(ACustomerkey1 As String, ACustomerkey2 As String)
  ' no Customer - Offer navigation link
End Sub

Private Sub ListContactOf(AContactKey1 As String, AContactKey2 As String, AContactKey3 As String)
  ' no Contact - Offer navigation link
End Sub

' This function is called by the application when the component embedded is updated
Public Sub Embedded_Updated()
' DO NOTHING
End Sub


Private Sub SwapToDisplayModeSubitem(ByVal al_Mode As Long)
On Error GoTo ErrHandler

    fraSubItemMain.Visible = al_Mode <> mt_CstValues.DisplayMode_None
    
    'update toolbar
    Select Case al_Mode
    Case mt_CstValues.DisplayMode_View
      Call tlb_Subitem.DisplayFace("4")
    Case mt_CstValues.DisplayMode_List
      Call tlb_Subitem.DisplayFace("0")
    Case mt_CstValues.DisplayMode_Add
      Call tlb_Subitem.DisplayFace("1")
    Case mt_CstValues.DisplayMode_Update
      Call tlb_Subitem.DisplayFace("2")
    Case mt_CstValues.DisplayMode_Delete
      Call tlb_Subitem.DisplayFace("3")
    End Select
    
    Call fraSubitemDetail0.Move(0, 0)
    
    ' update subitem frame
    Select Case al_Mode
    Case mt_CstValues.DisplayMode_View, mt_CstValues.DisplayMode_List
      fraSubitemDetail0.Visible = False
      Call tbs_OfferDetail.Move(mt_CstValues.Frm_Margin, mt_CstValues.Frm_Margin, fraSubItemMain.Width)
      Call btn_MoveNext.Move(btn_MoveNext.Left, tbs_OfferDetail.Top)
      Call btn_MovePrev.Move(btn_MovePrev.Left, tbs_OfferDetail.Top)
      Call grd_Offer.Move(mt_CstValues.Frm_Margin, _
                          tbs_OfferDetail.Top + tbs_OfferDetail.Height + mt_CstValues.Frm_Spacing, _
                          fraSubItemMain.Width - tlb_Subitem.Width - 6 * mt_CstValues.Frm_Spacing, _
                          fraSubItemMain.Height - 6 * mt_CstValues.Frm_Spacing - tbs_Offer.Height - tbs_OfferDetail.Height)
      tlb_Item.Enabled = True
      grd_Offer.Enabled = True
      tbs_Header.Enabled = True
      tbs_OfferDetail.Enabled = True
      btn_MoveNext.Enabled = (al_Mode = mt_CstValues.DisplayMode_List)
      btn_MovePrev.Enabled = (al_Mode = mt_CstValues.DisplayMode_List)
      cbo_Customer.Enabled = (al_Mode = mt_CstValues.DisplayMode_List)
      cbo_SubProject.Enabled = (al_Mode = mt_CstValues.DisplayMode_List)
    Case mt_CstValues.DisplayMode_Add, mt_CstValues.DisplayMode_Update, mt_CstValues.DisplayMode_Delete
      fraSubitemDetail0.Visible = True
      Call tbs_OfferDetail.Move(mt_CstValues.Frm_Margin, fraSubitemDetail0.Top + fraSubitemDetail0.Height, fraSubItemMain.Width)
      Call btn_MoveNext.Move(btn_MoveNext.Left, tbs_OfferDetail.Top)
      Call btn_MovePrev.Move(btn_MovePrev.Left, tbs_OfferDetail.Top)
      Call grd_Offer.Move(mt_CstValues.Frm_Margin, _
                          tbs_OfferDetail.Top + tbs_OfferDetail.Height + mt_CstValues.Frm_Spacing, _
                          fraSubItemMain.Width - tlb_Subitem.Width - 6 * mt_CstValues.Frm_Spacing, _
                          fraSubItemMain.Height - fraSubitemDetail0.Height - 6 * mt_CstValues.Frm_Spacing - tbs_Offer.Height - tbs_OfferDetail.Height)
      tlb_Item.Enabled = False
      grd_Offer.Enabled = False
      tbs_Header.Enabled = False
      tbs_OfferDetail.Enabled = False
      btn_MoveNext.Enabled = False
      btn_MovePrev.Enabled = False
    End Select
    Call tbs_Offer.Move(grd_Offer.Left, grd_Offer.Top + grd_Offer.Height, fraSubItemMain.Width)
    ml_DisplayModeSubItem = al_Mode
    Call fraSubItemMain.Refresh
    Exit Sub
ErrHandler:
    Call ErrorHandler("SwapToDisplayModeSubitem")
End Sub

Private Sub InitSubitem()
On Error GoTo ErrHandler

Dim la_Columns() As String
Dim ls_req As String

    cal_OFD_WshDat.opening_toward_top = 1
    cal_OFD_ShpDat.opening_toward_top = 1
    cal_OFD_DelDat.opening_toward_top = 1
    
    grd_Offer.ResetGrid
    grd_Offer.MultiSelect = False
    grd_Offer.AllowSort = False
    grd_Offer.FreeSelect = True
    grd_Offer.AllowExcelExport = True
    grd_Offer.ExportOnlyVisibleColumns = True
    grd_Offer.ExportTitles = True
    grd_Offer.WordWrap = True
    
    ReDim la_Columns(58)
    la_Columns(0) = "OFD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "1" & CH_LDELIMIT & "OFD_Id" & CH_LDELIMIT & ""
    la_Columns(1) = "OFD_Main" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Main" & CH_LDELIMIT & ""
    la_Columns(2) = "OFD_MainCount" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_MainCount" & CH_LDELIMIT & ""
    la_Columns(3) = "OFD_IdPar" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_IdPar" & CH_LDELIMIT & ""
    la_Columns(4) = "MasterDetail®©250®©0®©MasterDetail®©®©BITMAP"
    la_Columns(5) = "OFD_Pos" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Pos" & CH_LDELIMIT & "#Position"
    la_Columns(6) = "OFD_Order" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Order" & CH_LDELIMIT & "#OFD_Order"
    la_Columns(7) = "DOF_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "DOF_Id" & CH_LDELIMIT & ""
    la_Columns(8) = "CAT_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CAT_Id" & CH_LDELIMIT & ""
    la_Columns(9) = "OFD_Type" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Type" & CH_LDELIMIT & ""
    la_Columns(10) = "OFD_TypeDesc" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_TypeDesc" & CH_LDELIMIT & "#Type"
    la_Columns(11) = "OFD_SAPAct" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_SAPAct" & CH_LDELIMIT & "#Action"
    la_Columns(12) = "LEV_IdBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEV_IdBMP" & CH_LDELIMIT & "#Level" & CH_LDELIMIT & "BITMAP"
    la_Columns(13) = "LEV_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "LEV_Id" & CH_LDELIMIT & ""
    la_Columns(14) = "Err_Type" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Err_Type" & CH_LDELIMIT & ""
    la_Columns(15) = "Err_TypeBMP" & CH_LDELIMIT & "400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "Err_TypeBMP" & CH_LDELIMIT & "#Err" & CH_LDELIMIT & "BITMAP"
    la_Columns(16) = "PRD_Id" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Id" & CH_LDELIMIT & ""
    la_Columns(17) = "PRD_Code" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Code" & CH_LDELIMIT & "#Code"
    la_Columns(18) = "OFD_PosCus" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PosCus" & CH_LDELIMIT & "#Code cst."
    la_Columns(19) = "PRD_Name" & CH_LDELIMIT & "4000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "PRD_Name" & CH_LDELIMIT & "#Name"
    la_Columns(20) = "OFD_Qty" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Qty" & CH_LDELIMIT & "#Quantity"
    la_Columns(21) = "UM_Code" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Code" & CH_LDELIMIT & "#Unit of measure"
    la_Columns(22) = "UM_Name" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "UM_Name" & CH_LDELIMIT & "#Unit of measure"
    la_Columns(23) = "OFD_Cost" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Cost" & CH_LDELIMIT & "#Cost (module)" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(24) = "OFD_TotalC" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_TotalC" & CH_LDELIMIT & "#Total cost (module)" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(25) = "OFD_Ictp" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Ictp" & CH_LDELIMIT & "#ICTP Price (panel)" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(26) = "OFD_TotalI" & CH_LDELIMIT & "1500" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_TotalI" & CH_LDELIMIT & "#Total ICTP cost (panel)" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(27) = "OFD_Price" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Price" & CH_LDELIMIT & "#Price" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(28) = "OFD_PriceMain" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PriceMain" & CH_LDELIMIT & "#Price" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(29) = "OFD_PriceA" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PriceA" & CH_LDELIMIT & "#Price A" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(30) = "OFD_TotalP" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_TotalP" & CH_LDELIMIT & "#Total price" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(31) = "OFD_TotalPMain" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_TotalPMain" & CH_LDELIMIT & "#Total price" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(32) = "CURR_Code" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CURR_Code" & CH_LDELIMIT & "#Currency"
    la_Columns(33) = "OFD_Rate" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Rate" & CH_LDELIMIT & "#Exch.rate" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00000"
    la_Columns(34) = "OFD_PriceR" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PriceR" & CH_LDELIMIT & "#Price R" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(35) = "OFD_PriceRMain" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PriceRMain" & CH_LDELIMIT & "#Price R" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(36) = "OFD_TotalR" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_TotalR" & CH_LDELIMIT & "#Total price R" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(37) = "OFD_TotalRMain" & CH_LDELIMIT & "1100" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_TotalRMain" & CH_LDELIMIT & "#Total price R" & CH_LDELIMIT & "Float" & CH_LDELIMIT & "0.00"
    la_Columns(38) = "CURR_CodeCOF" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "CURR_CodeCOF" & CH_LDELIMIT & "#Currency"
    
    la_Columns(39) = "VEN_Name" & CH_LDELIMIT & "2400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "VEN_Name" & CH_LDELIMIT & "#Vendor"
    la_Columns(40) = "SHP_Name" & CH_LDELIMIT & "2400" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SHP_Name" & CH_LDELIMIT & "#Ship.point"
    
    la_Columns(41) = "OFD_AppByDesc" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_AppByDesc" & CH_LDELIMIT & "#Approved by"
    la_Columns(42) = "OFD_ApDat" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_ApDat" & CH_LDELIMIT & "#Approved date"
    la_Columns(43) = "SPA_Id" & CH_LDELIMIT & "600" & CH_LDELIMIT & "0" & CH_LDELIMIT & "SPA_Id" & CH_LDELIMIT & "#SPA Number"
    la_Columns(44) = "OFD_IsAlt" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_IsAlt" & CH_LDELIMIT & ""
    la_Columns(45) = "OFD_AltPa" & CH_LDELIMIT & "0" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_AltPa" & CH_LDELIMIT & ""
    la_Columns(46) = "MainAlt" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "MainAlt" & CH_LDELIMIT & "#Main/Alt"
    la_Columns(47) = "OFD_AltPaName" & CH_LDELIMIT & "2000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_AltPaName" & CH_LDELIMIT & "#Main name"
    la_Columns(48) = "OFD_WshDat" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_WshDat" & CH_LDELIMIT & "#Requested date"
    la_Columns(49) = "OFD_ShpDat" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_ShpDat" & CH_LDELIMIT & "#Shipment date"
    la_Columns(50) = "OFD_DelDat" & CH_LDELIMIT & "900" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_DelDat" & CH_LDELIMIT & "#Delivery date"
    
    la_Columns(51) = "OFD_OrdNrB7" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_OrdNrB7" & CH_LDELIMIT & "#Baeurer Order Nr."
    la_Columns(52) = "OFD_PosB7" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PosB7" & CH_LDELIMIT & "#Baeurer Pos"
    la_Columns(53) = "OFD_InfoB7" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_InfoB7" & CH_LDELIMIT & "#Baeurer Info"
    la_Columns(54) = "OFD_Bae_Fklz" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Bae_Fklz" & CH_LDELIMIT & "#B7 prod.order"
    la_Columns(55) = "OFD_Bae_Fkfs" & CH_LDELIMIT & "1200" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_Bae_Fkfs" & CH_LDELIMIT & "#B7 prod.status"
    la_Columns(56) = "COF_CodeSAP" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "COF_CodeSAP" & CH_LDELIMIT & "#SAP Order Nr."
    la_Columns(57) = "OFD_PosSAP" & CH_LDELIMIT & "800" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_PosSAP" & CH_LDELIMIT & "#SAP Pos"
    la_Columns(58) = "OFD_SAPInfo" & CH_LDELIMIT & "1000" & CH_LDELIMIT & "0" & CH_LDELIMIT & "OFD_SAPInfo" & CH_LDELIMIT & "#SAP Info"
    Call grd_Offer.SetColumns(la_Columns)
    If Not IsProduction Then
      grd_Offer.Columns("OFD_Ictp").Width = 0
      grd_Offer.Columns("OFD_TotalI").Width = 0
    End If
    
    grd_Offer.MasterDetailSetting = "OFD_Main®©MasterDetail®©OFD_MainCount®©" & eDPCOfferDetailMain.odMain & SEP & eDPCOfferDetailMain.odChild & SEP & COLOR_PARENT & SEP & COLOR_CHILD & "®©MINUS®©PLUS®©®©True"
    Call mo_Tools.EnableControl(txt_BI_SAP_Code, False)
    Call mo_Tools.EnableControl(txt_BI_SAP_Desc, False)
    
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_None)
    Exit Sub
ErrHandler:
    Call ErrorHandler("InitSubitem")
End Sub

Private Sub RefreshGridSafe(ByRef ao_grd As ArmGrid)
On Error GoTo ErrHandler
    Dim lv_Key As Variant
    If ao_grd.SelectedCount > 0 Then
        lv_Key = ao_grd.SelectedKey(0)
    Else
        lv_Key = Empty
    End If
    Call ao_grd.Refresh
    If Not IsEmpty(lv_Key) Then
        Call ao_grd.SearchKey(True, lv_Key)
    End If
    Exit Sub
ErrHandler:
    Call ErrorHandler("RefreshGridSafe")
End Sub

Private Sub BlankFieldsSubItem()
On Error GoTo ErrHandler
    Dim ls_req As String
  
    txt_PRD_Id.Text = ""
    txt_S_Code.Text = ""
    txt_BI_SAP_Code.Text = ""
    txt_BI_SAP_Desc.Text = ""
    txt_SKUPrice.Text = ""
    txt_SKUPriceM.Text = ""
    txt_SKUCost.Text = ""
    txt_SKUQty.Text = mo_Tools.DblToScreen(0)
    txt_SKUPU.Text = ""
    Call InitUnitOfMeasureCombo(cbo_SKUUOM)
    Set cbo_SKUUOM.SelectedItem = Nothing
    Set cbo_Vendor.SelectedItem = Nothing
    Set cbo_ShipPoint.SelectedItem = Nothing
    txt_SPANumber.Text = ""
    txt_OFD_Pos.Text = "0"
    Call cal_OFD_WshDat.reinit_cal
    Call cal_OFD_ShpDat.reinit_cal
    Call cal_OFD_DelDat.reinit_cal
    chk_ASFlag.Value = vbUnchecked
    chk_FreeOfCharge.Value = vbUnchecked
    Exit Sub
ErrHandler:
    Call ErrorHandler("BlankFieldsSubItem")
End Sub

Private Sub ViewInitFieldsSubItem()
On Error GoTo ErrHandler

    txt_PRD_Id.Text = mo_OfferPos.PRD_Id
    txt_S_Code.Text = mo_OfferPos.S_Code
    txt_BI_SAP_Code.Text = mo_OfferPos.PRD_Code
    txt_BI_SAP_Desc.Text = mo_OfferPos.PRD_Name
    If mo_OfferPos.SPA_Id > 0 Then
      txt_SPANumber.Text = mo_OfferPos.SPA_Id
    End If
    txt_OFD_Pos.Text = mo_OfferPos.OFD_Pos
    txt_SKUPrice.Text = mo_Tools.DblToScreen(mo_OfferPos.OFD_PriceA)
    txt_SKUPriceM.Text = mo_Tools.DblToScreen(mo_OfferPos.OFD_Price)
    txt_SKUCost.Text = mo_Tools.DblToScreen(mo_OfferPos.OFD_Cost)
    txt_SKUQty.Text = mo_Tools.DblToScreen(mo_OfferPos.OFD_Qty)
    txt_SKUPU.Text = mo_Tools.LongToScreen(mo_OfferPos.OFD_PU)
    txt_CURR_Code.Text = mo_OfferPos.CURR_Code
    
    Set cbo_SKUUOM.SelectedItem = Nothing
    If mo_OfferPos.UM_Code <> "" Then
      If Not cbo_SKUUOM.SearchItem(mo_OfferPos.UM_Code) Then
        Call cbo_SKUUOM.AddItem(Array(mo_OfferPos.UM_Code, mo_OfferPos.UM_Name), True)
      End If
    End If
    
    If (mo_OfferPos.VEN_Id <> "") And (Not cbo_Vendor.SearchItem(mo_OfferPos.VEN_Id)) Then
      Call cbo_Vendor.AddItem(Array(mo_OfferPos.VEN_Id, mo_OfferPos.VEN_Name), True)
    End If
    If (mo_OfferPos.SHP_Id > 0) And (Not cbo_ShipPoint.SearchItem(mo_OfferPos.SHP_Id)) Then
      Call cbo_ShipPoint.AddItem(Array(mo_OfferPos.SHP_Id, mo_OfferPos.SHP_Name), True)
    End If
    
    Call mo_Tools.SetCalendarDate(cal_OFD_WshDat, mo_OfferPos.OFD_WshDat)
    Call mo_Tools.SetCalendarDate(cal_OFD_ShpDat, mo_OfferPos.OFD_ShpDat)
    Call mo_Tools.SetCalendarDate(cal_OFD_DelDat, mo_OfferPos.OFD_DelDat)
    
    chk_ASFlag.Value = IIf(mo_OfferPos.OFD_IsAsItem, vbChecked, vbUnchecked)
    chk_FreeOfCharge.Value = IIf(mo_OfferPos.OFD_IsFree, vbChecked, vbUnchecked)
    Call mo_Tools.EnableControl(txt_SKUPriceM, chk_FreeOfCharge.Value = vbUnchecked)
    Exit Sub
ErrHandler:
    Call ErrorHandler("ViewInitFieldsSubItem")
End Sub

Private Sub AddDisplaySubItem(ByVal ao_OfferPos As DPC_OfferPos)
On Error GoTo ErrHandler
    
    Call BlankFieldsSubItem
    Call mo_Tools.EnableFrame(UserControl.Controls, fraSubitemDetail0, True)
    cbo_Customer.Enabled = False
    cbo_SubProject.Enabled = False
    Call mo_Tools.EnableControl(txt_BI_SAP_Code, False)
    Call mo_Tools.EnableControl(txt_BI_SAP_Desc, False)
    Call mo_Tools.EnableControl(txt_SKUPrice, False)
    Call mo_Tools.EnableControl(txt_CURR_Code, False)
    Call mo_Tools.EnableControl(txt_SKUPU, False)
    Call mo_Tools.EnableControl(txt_OFD_Pos, False)
    Call ViewInitFieldsSubItem
    
    Call grd_Offer.DeselectRow
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_Add)
    Exit Sub
ErrHandler:
    Call ErrorHandler("AddDisplaySubItem")
End Sub

Private Sub UpdateDisplaySubItem()
On Error GoTo ErrHandler
    
    Call BlankFieldsSubItem
    
    Call mo_Tools.EnableFrame(UserControl.Controls, fraSubitemDetail0, True)
    cbo_Customer.Enabled = False
    cbo_SubProject.Enabled = False
    Call mo_Tools.EnableControl(txt_BI_SAP_Code, False)
    Call mo_Tools.EnableControl(txt_BI_SAP_Desc, False)
    Call mo_Tools.EnableControl(txt_SKUPrice, False)
    Call mo_Tools.EnableControl(txt_CURR_Code, False)
    Call mo_Tools.EnableControl(txt_SKUPU, False)
    Call mo_Tools.EnableControl(txt_OFD_Pos, False)
    If IsSalesOrder Or IsSalesOrderChange Then
      Call mo_Tools.EnableControl(btn_SelectProduct, False)
      Call mo_Tools.EnableControl(cbo_SKUUOM, False)
      Call mo_Tools.EnableControl(cbo_Vendor, False)
      Call mo_Tools.EnableControl(cbo_ShipPoint, False)
      Call mo_Tools.EnableControl(txt_SKUCost, False)
    End If
    
    Call ViewInitFieldsSubItem
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_Update)
    Exit Sub
ErrHandler:
    Call ErrorHandler("UpdateDisplaySubItem")
End Sub

Private Sub DeleteDisplaySubItem()
On Error GoTo ErrHandler
    
    Call BlankFieldsSubItem
    
    Call mo_Tools.EnableFrame(UserControl.Controls, fraSubitemDetail0, False)
    cbo_Customer.Enabled = False
    cbo_SubProject.Enabled = False
    Call ViewInitFieldsSubItem
    Call SwapToDisplayModeSubitem(mt_CstValues.DisplayMode_Delete)
    Exit Sub
ErrHandler:
    Call ErrorHandler("DeleteDisplaySubItem")
End Sub

Private Function SubRecordCheck(ByVal ao_OfferPos As DPC_OfferPos) As Boolean
On Error GoTo ErrHandler
Dim ll_SPA_Id As Long
Dim ls_req As String
Dim ls_FieldName As String
Dim lbl_Field As Label

    SubRecordCheck = True
    
    If txt_BI_SAP_Code.Text = "" Or txt_BI_SAP_Desc.Text = "" Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_PRD_Code")
      ls_FieldName = IIf(lbl_Field Is Nothing, "#S Code", lbl_Field.Caption)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", ls_FieldName))
      SubRecordCheck = False
      Exit Function
    End If
    If Val(txt_OFD_Pos.Text) = 0 Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_OFD_Pos")
      ls_FieldName = IIf(lbl_Field Is Nothing, "#Position", lbl_Field.Caption)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", ls_FieldName))
      SubRecordCheck = False
      Exit Function
    End If
    If mo_Tools.ScreenToDbl(txt_SKUQty.Text) = 0 Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_OFD_Qty")
      ls_FieldName = IIf(lbl_Field Is Nothing, "#Quantity", lbl_Field.Caption)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", ls_FieldName))
      SubRecordCheck = False
      Exit Function
    End If
    If (mo_Tools.ScreenToDbl(txt_SKUPriceM.Text) = 0) And (chk_FreeOfCharge.Value = vbUnchecked) Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_OFD_Price")
      ls_FieldName = IIf(lbl_Field Is Nothing, "#Price Manual", lbl_Field.Caption)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", ls_FieldName))
      SubRecordCheck = False
      Exit Function
    End If
    If mo_Tools.ScreenToDbl(txt_SKUCost.Text) = 0 Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_OFD_CostA")
      ls_FieldName = IIf(lbl_Field Is Nothing, "#Price Manual", lbl_Field.Caption)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", ls_FieldName))
      SubRecordCheck = False
      Exit Function
    End If
    If cbo_SKUUOM.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_OFD_UM_Code")
      ls_FieldName = IIf(lbl_Field Is Nothing, "#UoM", lbl_Field.Caption)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", ls_FieldName))
      SubRecordCheck = False
      Exit Function
    End If
    If cbo_Vendor.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_PlantVendor")
      ls_FieldName = IIf(lbl_Field Is Nothing, "#Plant/Vendor", lbl_Field.Caption)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", ls_FieldName))
      SubRecordCheck = False
      Exit Function
    End If
    If cbo_ShipPoint.SelectedItem Is Nothing Then
      Set lbl_Field = mo_Tools.GetControl(lbl_Label, "lbl_ShipPoint")
      ls_FieldName = IIf(lbl_Field Is Nothing, "#Shipping point", lbl_Field.Caption)
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9701, "#Please, enter mandatory field: $fieldname$", Array("$fieldname$", ls_FieldName))
      SubRecordCheck = False
      Exit Function
    End If
    
    ls_req = "exec Cap_OfferDetail_BI_SAP_Code_chk $BI_SAP_Code$"
    ls_req = Replace(ls_req, "$BI_SAP_Code$", mo_Tools.SQLStr(txt_BI_SAP_Code.Text), , , vbTextCompare)
    If mo_Tools.SelectValue(mo_Db, ls_req) <> "" Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9720, "#This is Metal panel SKU, please use option Metal Products / Standard")
      SubRecordCheck = False
      Exit Function
    End If
    
    ao_OfferPos.PRD_Code = txt_BI_SAP_Code.Text
    ao_OfferPos.S_Code = txt_S_Code.Text
    ao_OfferPos.PRD_Id = txt_PRD_Id.Text
    ao_OfferPos.PRD_Name = txt_BI_SAP_Desc.Text
    ao_OfferPos.UM_Code = mo_Tools.GetComboKey(cbo_SKUUOM)
    ao_OfferPos.UM_Name = cbo_SKUUOM.Text
    ao_OfferPos.OFD_Qty = mo_Tools.ScreenToDbl(txt_SKUQty.Text)
    ao_OfferPos.OFD_PU = mo_Tools.ScreenToLong(txt_SKUPU.Text)
    If ao_OfferPos.OFD_PU = 0 Then ao_OfferPos.OFD_PU = 1
    ao_OfferPos.OFD_PriceA = mo_Tools.ScreenToDbl(txt_SKUPrice.Text)
    ao_OfferPos.OFD_Price = mo_Tools.ScreenToDbl(txt_SKUPriceM.Text)
    If ao_OfferPos.OFD_PriceA = 0 Then
      ao_OfferPos.OFD_PriceA = ao_OfferPos.OFD_Price
    End If
    ao_OfferPos.OFD_CostA = mo_Tools.ScreenToDbl(txt_SKUCost.Text)
    ao_OfferPos.OFD_Cost = mo_Tools.ScreenToDbl(txt_SKUCost.Text)
    ao_OfferPos.CURR_Code = txt_CURR_Code.Text
    ao_OfferPos.OFD_Pos = mo_Tools.ScreenToLong(txt_OFD_Pos.Text)
    ao_OfferPos.OFD_WshDat = cal_OFD_WshDat.date_dt
    ao_OfferPos.OFD_ShpDat = cal_OFD_ShpDat.date_dt
    ao_OfferPos.OFD_DelDat = cal_OFD_DelDat.date_dt
    ao_OfferPos.CURR_Code = txt_CURR_Code.Text
    ao_OfferPos.VEN_Id = mo_Tools.GetComboKey(cbo_Vendor)
    ao_OfferPos.VEN_Name = cbo_Vendor.Text
    ao_OfferPos.SHP_Id = mo_Tools.GetComboKey(cbo_ShipPoint)
    ao_OfferPos.SHP_Name = cbo_ShipPoint.Text
    ao_OfferPos.OFD_IsFree = chk_FreeOfCharge.Value = vbChecked
    ao_OfferPos.OFD_IsAsItem = chk_ASFlag.Value = vbChecked
    
    ao_OfferPos.SPA_Id = 0
    ll_SPA_Id = Val(txt_SPANumber.Text)
    If ll_SPA_Id <> 0 Then
      ls_req = "SELECT SPA_Id FROM SPA_Header WHERE SPA_Id=$SPA_Id$"
      ls_req = Replace(ls_req, "$SPA_Id$", mo_Tools.SqlInt(ll_SPA_Id), , , vbTextCompare)
      ao_OfferPos.SPA_Id = Val(mo_Tools.SelectValue(mo_Db, ls_req))
      If ao_OfferPos.SPA_Id = 0 Then
        Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9721, "#SPA Number is not valid")
        SubRecordCheck = False
      End If
    End If
    Exit Function
ErrHandler:
    Call ErrorHandler("SubRecordCheck")
End Function

Private Sub SubRecordAdd(ByVal ao_OfferPos As DPC_OfferPos)
On Error GoTo ErrHandler
    
    Call ao_OfferPos.Insert(mo_Db, ml_U_Code)
    Exit Sub
ErrHandler:
    Call ErrorHandler("SubRecordAdd")
End Sub

Private Sub SubRecordUpdate(ByVal ao_OfferPos As DPC_OfferPos)
On Error GoTo ErrHandler

    Call ao_OfferPos.Update(mo_Db, ml_U_Code)
    Exit Sub
ErrHandler:
    Call ErrorHandler("SubRecordUpdate")
End Sub

Private Sub SubRecordChildDelete(ByVal as_OFD_IdPar As String)
On Error GoTo ErrHandler
    
Dim ls_req As String

  ls_req = "exec Cap_OfferDetail_del3 $COF_ID$, $OFD_IDPar$"
  
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_IdPar$", mo_Tools.SQLStr(as_OFD_IdPar), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
  Exit Sub
ErrHandler:
  Call ErrorHandler("SubRecordChildDelete")
End Sub

Private Sub SubRecordDrop(ByVal as_OFD_IdPar As String)
On Error GoTo ErrHandler
    
Dim ls_req As String

  ls_req = "exec Cap_OfferDetail_del2 $COF_ID$, $OFD_IdPar$, $OFD_Id$, $Z_Last_Upd_User$"
  
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(m_CurrentKey1), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_IdPar$", mo_Tools.SQLStr(as_OFD_IdPar), , , vbTextCompare)
  ls_req = Replace(ls_req, "$OFD_Id$", "NULL", , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req)
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("SubRecordDrop")
End Sub

Private Sub SubRecordCopy(ByVal ao_OfferPos As DPC_OfferPos, ByVal as_COF_IdDst As String, ByVal al_OFD_Pos As Long, _
  ByVal ad_COF_DocDat As Date, ByVal as_COF_Lang As String, ByVal as_COF_CURR_Code As String, ByVal ab_CopyBOMBORCost As Boolean, ByVal ae_DstOfferStatus As eOfferStatus)
On Error GoTo ErrHandler

Dim lo_Product As DPC_Product
Dim lo_SubSys As DPC_SubSys
Dim lo_PrdManual As DPC_PrdManual
Dim lo_Collection As Collection
Dim ls_Request As String
Dim lb_ResetQty As Boolean
Dim lo_OfferPos As DPC_OfferPos

  lb_ResetQty = (ao_OfferPos.OFD_Qty = 0)
  If ((ao_OfferPos.OFD_Type = eDPCPriceBookType.eCustomMetal) Or _
     (ao_OfferPos.OFD_Type = eDPCPriceBookType.eStockMetal) Or _
     (ao_OfferPos.OFD_Type = eDPCPriceBookType.eEngMetal)) And _
     (ao_OfferPos.CAT_Id <> eDPCCategory.cgOption) Then
    Set lo_Product = New DPC_Product
    Set lo_Product.Tools = mo_Tools
    Set lo_Product.ArmDb = mo_Db
    lo_Product.U_Code = ml_U_Code
    lo_Product.COF_Id = ao_OfferPos.COF_Id
    lo_Product.CT_Code = CT_Code
    lo_Product.CURR_Code = CURR_Code
    lo_Product.ValidityDate = ValidityDate
    lo_Product.Language_Code = as_COF_Lang
    Call lo_Product.Load_A_COM
    Call lo_Product.InitOffer
    Call lo_Product.Load(ao_OfferPos.PRD_Id)
    Call lo_Product.LoadOffer(ao_OfferPos.COF_Id, ao_OfferPos.OFD_IdPar)
    
    If ab_CopyBOMBORCost Then
      Call lo_Product.LoadBOM
      Call lo_Product.LoadBOR
      Call lo_Product.LoadCostCalc
    End If
    
    If lb_ResetQty Then
      If lo_Product.QtyType = eDPCQtyType.qtPCS Then
        lo_Product.PanelQtyPCS = 0
      Else
        lo_Product.PanelQtyM2 = 0
      End If
    End If
    lo_Product.COF_Id = as_COF_IdDst
    lo_Product.OFD_Pos = al_OFD_Pos
    Call lo_Product.Copy
    lo_Product.Insert
    ao_OfferPos.PRD_Id = lo_Product.PRD_Id
    Call lo_Product.RefreshPrice
    Set lo_Collection = lo_Product.GenerateOfferDetail
    Call lo_Product.Unload_A_COM
    Set lo_Product = Nothing
  ElseIf ao_OfferPos.OFD_Type = eDPCPriceBookType.eSubconstruction Then
    Set lo_SubSys = New DPC_SubSys
    lo_SubSys.U_Code = ml_U_Code
    lo_SubSys.Language_Code = as_COF_Lang
    lo_SubSys.CURR_Code = "EUR"
    Set lo_SubSys.ArmDb = mo_Db
    Set lo_SubSys.Tools = mo_Tools
    Call lo_SubSys.Load_A_COM
    Call lo_SubSys.Load(ao_OfferPos.PRD_Id)
    Call lo_SubSys.LoadOffer(ao_OfferPos.COF_Id, ao_OfferPos.OFD_IdPar)
    lo_SubSys.COF_Id = as_COF_IdDst
    lo_SubSys.OFD_Pos = al_OFD_Pos
    Call lo_SubSys.Copy
    If lb_ResetQty Then
      lo_SubSys.PUS_QtyM2 = 0
    End If
    Call lo_SubSys.Insert
    Set lo_Collection = lo_SubSys.GenerateOfferDetail
    Call lo_SubSys.Unload_A_COM
    Set lo_SubSys = Nothing
  ElseIf ao_OfferPos.OFD_Type = eDPCPriceBookType.eManualLine Then
    Set lo_PrdManual = New DPC_PrdManual
    Set lo_PrdManual.Tools = mo_Tools
    Set lo_PrdManual.ArmDb = mo_Db
    lo_PrdManual.U_Code = ml_U_Code
    lo_PrdManual.COF_Id = ao_OfferPos.COF_Id
    lo_PrdManual.CT_Code = CT_Code
    lo_PrdManual.CURR_Code = CURR_Code
    lo_PrdManual.Language_Code = as_COF_Lang
    Call lo_PrdManual.Load_A_COM
    Call lo_PrdManual.LoadPrdManual(ao_OfferPos.PRD_Id)
    Call lo_PrdManual.LoadOffer(ao_OfferPos.COF_Id, ao_OfferPos.OFD_IdPar)
    Call lo_PrdManual.Copy
    lo_PrdManual.COF_Id = as_COF_IdDst
    lo_PrdManual.OFD_Pos = al_OFD_Pos
    Call lo_PrdManual.Insert
    Set lo_Collection = lo_PrdManual.GenerateOfferDetail
    For Each lo_OfferPos In lo_Collection
      If lb_ResetQty And Not (lo_OfferPos.DOF_IsStp) Then
        lo_OfferPos.OFD_Qty = 0
        lo_OfferPos.OFD_QtyA = 0
      End If
    Next
  Else
    Set lo_Collection = LoadOfferDetail(ao_OfferPos.COF_Id, ao_OfferPos.OFD_IdPar, eDPCOfferDetailMain.odUnknown)
    For Each lo_OfferPos In lo_Collection
      lo_OfferPos.COF_Id = as_COF_IdDst
      lo_OfferPos.OFD_Pos = al_OFD_Pos
      If lb_ResetQty Then
        lo_OfferPos.OFD_Qty = 0
        lo_OfferPos.OFD_QtyA = 0
      End If
      If ao_OfferPos.OFD_IsAlt = eDPCOfferDetailIsAlt.maOption Then
        lo_OfferPos.RowStatus = eDPCRowStatus.rsAdd
      End If
      Call lo_OfferPos.ResetInterfaceInfo
    Next
  End If
  
  If Not lo_Collection Is Nothing Then
    If (ao_OfferPos.OFD_IsAlt = eDPCOfferDetailIsAlt.maAltenative) Then
      For Each lo_OfferPos In lo_Collection
        lo_OfferPos.OFD_IsAlt = eDPCOfferDetailIsAlt.maAltenative
        If ao_OfferPos.AlternateParent Is Nothing Then
          lo_OfferPos.OFD_AltPa = ao_OfferPos.OFD_AltPa
          lo_OfferPos.OFD_AltPaName = ao_OfferPos.OFD_AltPaName
        Else
          lo_OfferPos.OFD_AltPa = ao_OfferPos.AlternateParent.OFD_Id
          lo_OfferPos.OFD_AltPaName = ao_OfferPos.AlternateParent.PRD_Name
        End If
      Next
    End If
    ao_OfferPos.OFD_Id = SaveOfferDetail(lo_Collection, "", ad_COF_DocDat, as_COF_CURR_Code, ae_DstOfferStatus)
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("SubRecordCopy")
End Sub

Private Sub CopyOffer(ByVal as_CurrentKey As String)
On Error GoTo ErrHandler

Dim ls_COF_IdNew As String
Dim ll_Cursor As Long

  If as_CurrentKey = "" Then Exit Sub
  
  ls_COF_IdNew = mo_Tools.GetNextID(mo_Db, "Cap_Offer")
  Call RecordCopy(as_CurrentKey, ls_COF_IdNew)
  DisplayMode = mt_CstValues.DisplayMode_List
  ' add line into main grid
  Call RefreshGridSafe(grdlst)
  If grdlst.SearchKey(True, ls_COF_IdNew) Then

    m_CurrentKey1 = ls_COF_IdNew
    If CanUpdateOffer(m_Project, m_CurrentKey1) Then
      DisplayMode = mt_CstValues.DisplayMode_Update
      ml_iConcurrency = 1                           ' reset iconcurrency
    End If
  End If
  Exit Sub
ErrHandler:
  Call ErrorHandler("CopyOffer")
End Sub

Public Sub PrintOffer(ByVal as_COF_Id As String, Optional ab_SaveAsPDF As Boolean = False)
On Error GoTo ErrHandler
    
Dim lo_OfferPrint As frmOfferPrint
Dim lo_PrintFrm As Cap_Print
Dim ll_COT_ID As Long, ll_COTZ_ID As Long
Dim ls_req As String
Dim lc_Cursor As Long
Dim lb_PrintResult As Boolean
Dim lb_PrintPicture As Boolean
Dim lb_PrintReps As Boolean
Dim lb_PrintTotal As Boolean
Dim lb_InterCompany As Boolean
Dim lb_PrintGeneralTerms As Boolean
Dim lb_PrintASItemMessage As Boolean
  
  If IsProduction Then
    lb_PrintResult = True
    lb_PrintPicture = False
    lb_PrintTotal = False
    lb_PrintReps = True
    lb_InterCompany = True
    lb_PrintASItemMessage = False
  Else
    Set lo_OfferPrint = New frmOfferPrint
    Load lo_OfferPrint
    Set lo_OfferPrint.Tools = mo_Tools
    Set lo_OfferPrint.ArmDb = mo_Db
    lo_OfferPrint.COF_Id = as_COF_Id
    Call lo_OfferPrint.Load_A_COM
    
    Call mo_Tools.LockScreen(Me, False)
    Call mo_Tools.ShowModalForm(lo_OfferPrint)
    Call mo_Tools.LockScreen(Me, True)
    
    lb_PrintResult = lo_OfferPrint.Result
    lb_PrintPicture = lo_OfferPrint.PrintPictures
    lb_PrintTotal = lo_OfferPrint.PrintTotal
    lb_PrintReps = lo_OfferPrint.PrintReps
    lb_InterCompany = False
    lb_PrintGeneralTerms = lo_OfferPrint.PrintGeneralTerms
    lb_PrintASItemMessage = lo_OfferPrint.PrintASItemMessage
    
    Call lo_OfferPrint.Unload_A_COM
    Unload lo_OfferPrint
    Set lo_OfferPrint = Nothing
  End If
  
  If lb_PrintResult Then
  
    ls_req = "SELECT COF.COT_Id, COT.COTZ_Id "
    ls_req = ls_req & "FROM Cap_Offer COF "
    ls_req = ls_req & "INNER JOIN Cap_OfferTemplate COT ON (COF.COT_Id=COT.COT_Id)"
    ls_req = ls_req & "WHERE COF.COF_Id=$COF_Id$"
    ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id), , , vbTextCompare)
    lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    ll_COT_ID = mo_Db.GetFields(lc_Cursor, "COT_Id")
    ll_COTZ_ID = mo_Db.GetFields(lc_Cursor, "COTZ_Id")
    Call mo_Db.Close(lc_Cursor)
    
    Set lo_PrintFrm = New Cap_Print
    Load lo_PrintFrm
    Set lo_PrintFrm.ArmDb = mo_Db
    Set lo_PrintFrm.Tools = mo_Tools
    lo_PrintFrm.ConnectString = ms_ConnectString
    lo_PrintFrm.U_Code = ml_U_Code
    lo_PrintFrm.Language = ms_Language_Code
    Call lo_PrintFrm.Load_A_COM
    
    Call lo_PrintFrm.PrintOffer(as_COF_Id, lb_PrintPicture, lb_PrintTotal, lb_PrintReps, lb_InterCompany, ab_SaveAsPDF, lb_PrintGeneralTerms, lb_PrintASItemMessage)
    
    If ab_SaveAsPDF = False Then
      Call mo_Tools.LockScreen(Me, False)
      Call mo_Tools.ShowModalForm(lo_PrintFrm)
      Call mo_Tools.LockScreen(Me, True)
      Call lo_PrintFrm.Hide
    End If
    
    Call lo_PrintFrm.Unload_A_COM
    Unload lo_PrintFrm
    Set lo_PrintFrm = Nothing
  End If
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("PrintOffer")
End Sub

Public Sub PrintOfferPacking(ByVal as_COF_Id As String, ByVal al_status As eOfferStatus, Optional ab_SaveAsPDF As Boolean)
On Error GoTo ErrHandler
    
Dim lo_OfferPrint As frmOfferPrint
Dim lo_PrintFrm As Cap_Print
Dim ll_COT_ID As Long, ll_COTZ_ID As Long
Dim ls_req As String
Dim lc_Cursor As Long
Dim lb_InterCompany As Boolean


    lb_InterCompany = False
    Set lo_PrintFrm = New Cap_Print
    Load lo_PrintFrm
    Set lo_PrintFrm.ArmDb = mo_Db
    Set lo_PrintFrm.Tools = mo_Tools
    lo_PrintFrm.ConnectString = ms_ConnectString
    lo_PrintFrm.U_Code = ml_U_Code
    lo_PrintFrm.Language = ms_Language_Code
    Call lo_PrintFrm.Load_A_COM
    
    Call lo_PrintFrm.PrintOfferPacking(as_COF_Id, ab_SaveAsPDF)
    
    If ab_SaveAsPDF = False Then
      Call mo_Tools.LockScreen(Me, False)
      Call mo_Tools.ShowModalForm(lo_PrintFrm)
      Call mo_Tools.LockScreen(Me, True)
      Call lo_PrintFrm.Hide
    End If
    
    Call lo_PrintFrm.Unload_A_COM
    Unload lo_PrintFrm
    Set lo_PrintFrm = Nothing
  
  Exit Sub
ErrHandler:
  Call ErrorHandler("PrintOfferPacking")
End Sub

'Public Function PrintOfferPreview(ByVal as_COF_Id As String, ByVal ab_PrintPictures As Boolean, ByVal ab_OfferConfirmation As Boolean, ByRef as_serialString As String) As String
'On Error GoTo ErrHandler
'  PrintOfferPreview = ""
'  as_serialString = ""
'
'  Dim lo_printFrm As Cap_Print
'  Set lo_printFrm = New Cap_Print
'
'  Set lo_printFrm.ArmDb = mo_Db
'  lo_printFrm.ConnectString = ms_ConnectString
'  lo_printFrm.U_Code = ml_U_Code
'  lo_printFrm.Language = ms_Language_Code
'
'  Call lo_printFrm.Load_A_Com
'
'  If Not lo_printFrm.PrintOfferPreview(as_COF_Id, 4, 4, ab_PrintPictures, ab_OfferConfirmation) Then
'      PrintOfferPreview = ""
'      Exit Function
'  End If
'
'  Call mo_Tools.UpdateMouse(True)
'  Call lo_printFrm.Show(vbModal)
'  Call mo_Tools.UpdateMouse(False)
'
'  If lo_printFrm.ms_Action <> "" Then
'      as_serialString = lo_printFrm.SerializedReprintString
'  End If
'
'  PrintOfferPreview = lo_printFrm.ms_Action
'  Call lo_printFrm.Unload_A_Com
'  Unload lo_printFrm
'  Set lo_printFrm = Nothing
'
'  Exit Function
'ErrHandler:
'  Call ErrorHandler("PrintOfferPreview")
'End Function

Private Sub MailOffer(ByVal as_COF_Id As String, ByVal as_serialStr As String, ByVal ab_OfferConfirmation As Boolean)
On Error GoTo ErrHandler
  Exit Sub
ErrHandler:
  Call ErrorHandler("MailOffer")
End Sub

Private Sub FaxOffer(ByVal as_COF_Id As String, ByVal as_serialStr As String, ByVal ab_OfferConfirmation As Boolean)
On Error GoTo ErrHandler

  Exit Sub
ErrHandler:
  Call ErrorHandler("FaxOffer")
End Sub

Private Function GridUpdate(ByVal ab_Update As Boolean)
On Error GoTo ErrHandler
Dim ls_COF_ID As String
Dim ls_Customer As String, ls_Subproject As String
Dim ls_ExpiryDate As String
Dim ll_Version As Long
Dim ls_Status As String
Dim ls_OfferType As String
Dim lo_Grid As ArmGrid

  If IsProduction And (Not (mo_ExternalGrid Is Nothing)) Then
    Set lo_Grid = mo_ExternalGrid
  Else
    Set lo_Grid = grdlst
  End If

  ls_COF_ID = txt_COF_ID.Text
  ls_Customer = cbo_Customer.Text
  ls_Subproject = cbo_SubProject.Text
  ls_ExpiryDate = cal_COF_ExDat.date_courte
  ll_Version = Val(txt_Version.Text)
  ls_Status = cbo_Status.Text
  If opt_OfferType(0).Value = True Then
    ls_OfferType = opt_OfferType(0).Caption
  ElseIf opt_OfferType(1).Value = True Then
    ls_OfferType = opt_OfferType(1).Caption
  ElseIf opt_OfferType(2).Value = True Then
    ls_OfferType = opt_OfferType(2).Caption
  End If
  
  If ab_Update Then
    lo_Grid.SelectedLine(0, "COF_Code") = txt_COF_Code.Text
    lo_Grid.SelectedLine(0, "SPR_Name") = ls_Subproject
    lo_Grid.SelectedLine(0, "CCU_Desc") = ls_Customer
    lo_Grid.SelectedLine(0, "COF_ExDat") = ls_ExpiryDate
    lo_Grid.SelectedLine(0, "COF_Vers") = ll_Version
    lo_Grid.SelectedLine(0, "COF_StatDesc") = ls_Status
    lo_Grid.SelectedLine(0, "COF_TypeDesc") = ls_OfferType
    lo_Grid.SelectedLine(0, "Z_Last_Upd_User") = ml_U_Code
    lo_Grid.SelectedLine(0, "Z_Last_Upd") = Format(Date, "dd\/mm\/yyyy")
  Else
    Call grdlst.InsertLine(0)
    lo_Grid.Row = 0
    lo_Grid.SelectedLine(0, "COF_ID") = ls_COF_ID
    lo_Grid.SelectedLine(0, "COF_Code") = txt_COF_Code.Text
    lo_Grid.SelectedLine(0, "Z_Creation") = Format(Date, "dd\/mm\/yyyy")
    lo_Grid.SelectedLine(0, "SPR_Name") = ls_Subproject
    lo_Grid.SelectedLine(0, "CCU_Desc") = ls_Customer
    lo_Grid.SelectedLine(0, "COF_ExDat") = ls_ExpiryDate
    lo_Grid.SelectedLine(0, "COF_Vers") = ll_Version
    lo_Grid.SelectedLine(0, "COF_StatDesc") = ls_Status
    lo_Grid.SelectedLine(0, "COF_TypeDesc") = ls_OfferType
    lo_Grid.SelectedLine(0, "Z_Creator") = ml_U_Code
    lo_Grid.SelectedLine(0, "Z_Last_Upd_User") = ml_U_Code
    lo_Grid.SelectedLine(0, "Z_Last_Upd") = Format(Date, "dd\/mm\/yyyy")
  End If
  Exit Function
ErrHandler:
  Call ErrorHandler("GridUpdate")
End Function

Private Sub CreateAlternateLink(ByVal ao_Collection As Collection)
Dim ao_OfferPos As DPC_OfferPos
Dim lo_OfferMain As DPC_OfferPos

  For Each ao_OfferPos In ao_Collection
    If ao_OfferPos.OFD_IsAlt = eDPCOfferDetailIsAlt.maAltenative Then
      Set ao_OfferPos.AlternateParent = Nothing
      For Each lo_OfferMain In ao_Collection
        If (lo_OfferMain.OFD_IsAlt = eDPCOfferDetailIsAlt.maMain) And (StrComp(ao_OfferPos.OFD_AltPa, lo_OfferMain.OFD_Id, vbTextCompare) = 0) Then
          Set ao_OfferPos.AlternateParent = lo_OfferMain
          Exit For
        End If
      Next
      Debug.Assert Not ao_OfferPos.AlternateParent Is Nothing
    End If
  Next
  Set ao_OfferPos = Nothing
  Set lo_OfferMain = Nothing
  Exit Sub
ErrHandler:
  Call ErrorHandler("CreateAlternateLink")
End Sub

Private Sub ChangeOfferUoM(ByVal ae_Qtytype As eDPCQtyType)
On Error GoTo ErrHandler

Dim lo_OfferCol As Collection
Dim lo_Collection As Collection
Dim lo_OfferPos As DPC_OfferPos
Dim lb_InTran As Boolean
Dim lo_Product As DPC_Product
Dim lo_Offer As DPC_OfferPos
  
  ' load ALL detail main records of offer
  Set lo_OfferCol = LoadOfferDetail(m_CurrentKey1, "", eDPCOfferDetailMain.odMain)
  
  Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeOfferUoM")
  lb_InTran = True
  
  For Each lo_OfferPos In lo_OfferCol
    If (lo_OfferPos.DOF_Id = eDPCOfferDetail.odPosition) Then
      Set lo_Product = New DPC_Product
      Set lo_Product.Tools = mo_Tools
      Set lo_Product.ArmDb = mo_Db
      lo_Product.U_Code = ml_U_Code
      lo_Product.COF_Id = m_CurrentKey1
      lo_Product.CT_Code = CT_Code
      lo_Product.CURR_Code = CURR_Code
      lo_Product.ValidityDate = ValidityDate
      lo_Product.Language_Code = ms_COF_Lang
      Call lo_Product.Load_A_COM
      Call lo_Product.InitOffer
      Call lo_Product.Load(lo_OfferPos.PRD_Id)
      Call lo_Product.LoadOffer(lo_OfferPos.COF_Id, lo_OfferPos.OFD_IdPar)
      If (lo_Product.QtyType <> ae_Qtytype) And ((ae_Qtytype = eDPCQtyType.qtPCS) Or (ae_Qtytype = eDPCQtyType.qtM2)) Then
        'If ae_QtyType = eDPCQtyType.qtPCS Then
        '  lo_Product.PanelQtyPCS = lo_Product.PanelQtyPCS
        'ElseIf ae_QtyType = eDPCQtyType.qtM2 Then
        '  lo_Product.PanelQtyM2 = lo_Product.PanelQtyM2
        'End If
        'Call lo_Product.LoadPrice
        Call lo_Product.ChangeUoM(ae_Qtytype)
        Set lo_Collection = lo_Product.GenerateOfferDetail
        Call SaveOfferDetail(lo_Collection, lo_OfferPos.OFD_IdPar, COF_DocDat, CURR_Code, Status)
        Call mo_Tools.ClearCollection(lo_Collection)
      End If
      Call lo_Product.Unload_A_COM
      Set lo_Product = Nothing
    End If
  Next
  Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeOfferUoM")
  lb_InTran = False
  Call mo_Tools.ClearCollection(lo_OfferCol)
  Set lo_Collection = Nothing
  Exit Sub
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "ChangeOfferUoM")
  End If
  Call ErrorHandler("ChangeOfferUoM")
End Sub

Private Sub RecordCopy(ByVal as_COF_IdSrc As String, ByVal as_COF_IdDst As String)
On Error GoTo ErrHandler

Dim lo_Collection As Collection
Dim lo_OfferPos As DPC_OfferPos
Dim ld_COF_DocDat As Date
Dim ls_req As String
Dim lb_InTran As Boolean
Dim ls_COF_CodeDst As String, ls_COF_CodeSrc As String, ls_COF_Lang As String, ls_COF_CURR_Code As String
Dim lc_Cursor As Long
Dim le_DstOfferStatus  As eOfferStatus

  le_DstOfferStatus = eOfferStatus.osNew
  ls_req = "exec Cap_Offer_sel $COF_Id$, $Language_Code$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_IdSrc))
  ls_req = Replace(ls_req, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code))
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    ls_COF_CodeSrc = mo_Db.GetFields(lc_Cursor, "COF_Code")
    ld_COF_DocDat = mo_Db.GetFields(lc_Cursor, "COF_DocDat")
    ls_COF_Lang = mo_Db.GetFields(lc_Cursor, "COF_Lang")
    ls_COF_CURR_Code = mo_Db.GetFields(lc_Cursor, "CURR_Code")
  Call mo_Db.Close(lc_Cursor)
  
  ls_COF_CodeDst = GetCOF_Code(ls_COF_CodeSrc)
  
  Call mo_Tools.BeginBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "RecordCopy")
  lb_InTran = True
  ls_req = "exec Cap_Offer_cpy $COF_Id$, $COF_IdNew$, $COF_CodeNew$, $COF_StatNew$, $Z_Creator$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_IdSrc), , , vbTextCompare)
  ls_req = Replace(ls_req, "$COF_IdNew$", mo_Tools.SQLStr(as_COF_IdDst), , , vbTextCompare)
  ls_req = Replace(ls_req, "$COF_CodeNew$", mo_Tools.SQLStr(ls_COF_CodeDst), , , vbTextCompare)
  ls_req = Replace(ls_req, "$COF_StatNew$", mo_Tools.SqlInt(le_DstOfferStatus), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  Call mo_Tools.ExecuteSQLSafe(mo_Db, ls_req, 1)
  ' load ALL detail main records of offer
  Set lo_Collection = LoadOfferDetail(as_COF_IdSrc, "", eDPCOfferDetailMain.odMain)
  
  Call CreateAlternateLink(lo_Collection)
  
  For Each lo_OfferPos In lo_Collection
    If (StrComp(lo_OfferPos.OFD_Id, lo_OfferPos.OFD_IdPar, vbTextCompare) = 0) And _
      (lo_OfferPos.OFD_IsAlt = eDPCOfferDetailIsAlt.maMain) Then
      Call SubRecordCopy(lo_OfferPos, as_COF_IdDst, lo_OfferPos.OFD_Pos, ld_COF_DocDat, ls_COF_Lang, ls_COF_CURR_Code, False, le_DstOfferStatus)
    End If
  Next
  For Each lo_OfferPos In lo_Collection
    If (StrComp(lo_OfferPos.OFD_Id, lo_OfferPos.OFD_IdPar, vbTextCompare) = 0) And _
      (lo_OfferPos.OFD_IsAlt = eDPCOfferDetailIsAlt.maAltenative) Then
      Call SubRecordCopy(lo_OfferPos, as_COF_IdDst, lo_OfferPos.OFD_Pos, ld_COF_DocDat, ls_COF_Lang, ls_COF_CURR_Code, False, le_DstOfferStatus)
    End If
  Next
  For Each lo_OfferPos In lo_Collection
    If (StrComp(lo_OfferPos.OFD_Id, lo_OfferPos.OFD_IdPar, vbTextCompare) = 0) And _
      (lo_OfferPos.OFD_IsAlt = eDPCOfferDetailIsAlt.maOption) Then
      Call SubRecordCopy(lo_OfferPos, as_COF_IdDst, lo_OfferPos.OFD_Pos, ld_COF_DocDat, ls_COF_Lang, ls_COF_CURR_Code, False, le_DstOfferStatus)
    End If
  Next
  Call mo_Tools.CommitBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "RecordCopy")
  lb_InTran = False
  For Each lo_OfferPos In lo_Collection
    Set lo_OfferPos.AlternateParent = Nothing
  Next
  Call mo_Tools.ClearCollection(lo_Collection)
  Set lo_Collection = Nothing
  Exit Sub
ErrHandler:
  If lb_InTran Then
    Call mo_Tools.RollbackBatchTran(mo_Db, ml_U_Code, SCREEN_NAME, "RecordCopy")
  End If
  Call ErrorHandler("RecordCopy")
End Sub

Public Function GetSKUPrice(ByVal as_PRD_Id As String, ByVal al_Qty As Long, ByVal as_CT_Code As String, ByVal as_CURR_Code As String, ByVal ad_VDate As Date) As Double
On Error GoTo ErrHandler

Dim ls_req As String

  ls_req = "exec DPC_Price_sel2 $PRD_Id$,$CT_Code$,$CURR_Code$,$UM_CodeC$,$VDate$,$Qty$,$UM_CodeQ$"
  
  ls_req = Replace(ls_req, "$PRD_Id$", mo_Tools.SQLStr(as_PRD_Id), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CT_Code$", mo_Tools.SQLStr(as_CT_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$CURR_Code$", mo_Tools.SQLStr(as_CURR_Code), , , vbTextCompare)
  ls_req = Replace(ls_req, "$UM_CodeC$", mo_Tools.SQLStr(DPC_UOM_M2), , , vbTextCompare)
  ls_req = Replace(ls_req, "$VDate$", mo_Tools.SqlDate(ad_VDate), , , vbTextCompare)
  ls_req = Replace(ls_req, "$Qty$", mo_Tools.SqlDbl(al_Qty), , , vbTextCompare)
  ls_req = Replace(ls_req, "$UM_CodeQ$", mo_Tools.SQLStr(DPC_UOM_M2), , , vbTextCompare)
  GetSKUPrice = mo_Tools.SelectValue(mo_Db, ls_req, "PRC_Cost")
  Exit Function
ErrHandler:
  Call ErrorHandler("GetSKUPrice")
End Function

Public Function LoadAFile(ByVal as_FIL_Key As String, ByVal as_FileName As String, ByVal as_Path As String) As Boolean
On Error GoTo ErrHandler

'Dim ls_path As String
Dim lc_Cursor As Long
Dim ls_Request As String
Dim ls_Filename As String

  LoadAFile = False
    
  'ls_path = App.Path & "\Download\WordTmp\"
    
  If Not mo_FSO.FolderExists(as_Path) Then
    Call mo_FSO.CreateFolder(as_Path)
  End If
  
  ls_Filename = as_Path & as_FileName
  ' always download template... todo: create some new version download possibility
  'If Not mo_FSO.FileExists(ls_FileName) Then
    If Not mo_Db.BlobToFileSQL("SELECT F_Data_File FROM A_Files WHERE F_File_Key='" & as_FIL_Key & "'", ls_Filename, True, False) Then
      Err.Raise ArmErr.CompFncFailed, "BlobToFileSQL", "File download failed A_File_Key:" & as_FIL_Key & "," & mo_Db.LastErrorMessage
      Exit Function
    End If
  'End If
  
  LoadAFile = True
  Exit Function
  
ErrHandler:
  
  If lc_Cursor <> 0 Then
      Call mo_Db.Close(lc_Cursor)
  End If

  LoadAFile = False
  Call ErrorHandler("LoadAFile")
End Function

Private Sub GenerateTemplate(ByVal as_COF_Id As String, ByVal as_OFD_Id As String, ByVal as_PUS_Id As String)
On Error GoTo ErrHandler

Const c_PrdSub_req As String = "exec DPC_PrdSub_sel1 '$COF_Id$', '$OFD_Id$', '$PUS_Id$', $language_code$"
Const c_PrdSubArt_req As String = "exec DPC_PrdSubArt_lst '$COF_Id$', '$OFD_Id$', '$PUS_Id$', $language_code$"

Dim ls_filePath As String
Dim lo_oWordTmpProcessor As CWordTemplateProcessor
Dim ls_req As String
Dim ll_Cursor As Long
Dim ls_DPCImagePath As String
Dim ls_PDFFileName As String

    ls_PDFFileName = SavePDFFileName()

    Set lo_oWordTmpProcessor = New CWordTemplateProcessor
    
    If LoadAFile("WORD_TMP_PRDSUB", "DPC_PrdSub_Template.dot", App.Path & "\Download\WordTmp\") = False Then
        Exit Sub
    End If
    
    ls_filePath = App.Path & "\Download\WordTmp\DPC_PrdSub_Template.dot"
        
    Screen.MousePointer = vbHourglass
    
    'init (creates winword.exe process in memory)
    Call lo_oWordTmpProcessor.Init
    Set lo_oWordTmpProcessor.ArmDb = mo_Db
    
    'add data values where BookmarkRefName is defined in Word template as first part of bookmark
    ls_req = ReplaceCommonPlaceholders(c_PrdSub_req)
    ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", as_COF_Id)
    ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$OFD_Id$", as_OFD_Id)
    ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$PUS_Id$", as_PUS_Id)
    Call lo_oWordTmpProcessor.AddNewData("DPC_PrdSub", "DPC_SubconstructionPDF", ls_req, ms_Language_Code)
    
    'add pictures
    ls_DPCImagePath = prg.AppCache_Dir & DPC_IMAGE_CACHE
    
    ll_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
    If mo_Db.GetFields(ll_Cursor, "IMG_Id") > 0 Then
        Call mo_Tools.LoadDPCImage(mo_Db, mo_FSO, ls_DPCImagePath, mo_Db.GetFields(ll_Cursor, "IMG_Id"))
        Call lo_oWordTmpProcessor.AddNewPicture("DPC_PrdSub_IMG_1", ls_DPCImagePath & "IMG" & mo_Db.GetFields(ll_Cursor, "IMG_Id") & ".jpg")
    End If
    If mo_Db.GetFields(ll_Cursor, "IMG_IdSht") > 0 Then
        Call mo_Tools.LoadDPCImage(mo_Db, mo_FSO, ls_DPCImagePath, mo_Db.GetFields(ll_Cursor, "IMG_IdSht"))
        Call lo_oWordTmpProcessor.AddNewPicture("DPC_PrdSub_IMG_2", ls_DPCImagePath & "IMG" & mo_Db.GetFields(ll_Cursor, "IMG_IdSht") & ".jpg")
    End If
    Call mo_Db.Close(ll_Cursor)
    
    'add table where Table_1 is defined in Word with appropriate index
    ls_req = ReplaceCommonPlaceholders(c_PrdSubArt_req)
    ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$COF_Id$", as_COF_Id)
    ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$OFD_Id$", as_OFD_Id)
    ls_req = mo_Tools.ReplacePlaceHolder(ls_req, "$PUS_Id$", as_PUS_Id)
    Call lo_oWordTmpProcessor.AddNewTable("DPC_PrdSub", "DPC_SubconstructionPDF", "grd_Article", ls_req, ms_Language_Code)
        
    'create the new word document based on previous settings
    Call lo_oWordTmpProcessor.ProcessFile(ls_filePath, False)
    
    Screen.MousePointer = vbDefault
    
    Call lo_oWordTmpProcessor.SavePDFAndClose(ls_PDFFileName)
       
    Set lo_oWordTmpProcessor = Nothing
    
    Exit Sub
ErrHandler:
    Call ErrorHandler("GenerateTemplate()")
End Sub

Private Function SavePDFFileName() As String
On Error GoTo ErrHandler
    
Dim lo_dlg As Object
Dim ls_Filename As String
Dim ll_Ret As Long
    
    SavePDFFileName = ""
    
    dlg_Common.Filter = "PDF files (*.PDF)|*.PDF"
    dlg_Common.CancelError = True
    Call dlg_Common.ShowSave
    
    SavePDFFileName = dlg_Common.FileName
    
    Exit Function
ErrHandler:
    If Err.Number = 32755 Then 'Cancel button clicked
        Err.Clear
    Else
        Call ErrorMessage("SavePDFFileName")
    End If
    
End Function

Public Function CanApproveOffer(ByVal as_Login As String) As Boolean
On Error GoTo ErrHandler
  CanApproveOffer = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanApproveOffer")
End Function

Public Function GetOfferLock(ByVal as_COF_Id As String, Optional ByVal ab_CheckOfferEdited As Boolean = True) As Boolean
On Error GoTo ErrHandler

Dim ls_LockOwner As String
  
  GetOfferLock = False
  
  If ab_CheckOfferEdited Then
    If IsOfferLocked Then
      Exit Function
    End If
  End If
  
  If mo_Tools.GetApplicationLock(mo_Db, "Cap_Offer:" & as_COF_Id) Then
    Call mo_Tools.ExecuteSQLSafe(mo_Db, "UPDATE Cap_Offer SET Z_LockOwn=" & mo_Tools.SQLStr(ms_LoginName) & ",Z_LockDate=getdate(),Z_LockProc=@@SPID WHERE COF_Id=" & mo_Tools.SQLStr(as_COF_Id))
    GetOfferLock = True
  Else
    ls_LockOwner = mo_Tools.SelectValue(mo_Db, "SELECT Z_LockOwn FROM Cap_Offer WHERE COF_Id=" & mo_Tools.SQLStr(as_COF_Id))
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9722, "This offer is locked by user '$LockOwner$', please try again later.", Array("$LockOwner$", ls_LockOwner))
  End If
  Exit Function
ErrHandler:
  Call ErrorHandler("GetOfferLock")
End Function

Public Sub ReleaseOfferLock(ByVal as_COF_Id As String)
On Error GoTo ErrHandler

  Call mo_Tools.ReleaseApplicationLock(mo_Db, "Cap_Offer:" & as_COF_Id)
  'update only owner with special character # on begining, so we can see who has it last time.
  Call mo_Tools.ExecuteSQLSafe(mo_Db, "UPDATE Cap_Offer SET Z_LockOwn='#' + Z_LockOwn  WHERE COF_Id=" & mo_Tools.SQLStr(as_COF_Id))
  Exit Sub
ErrHandler:
  Call ErrorHandler("ReleaseOfferLock")
End Sub

Private Function IsOfferLocked() As Boolean
On Error GoTo ErrHandler
   
Dim lb_IsLocked As Boolean

  lb_IsLocked = False
  RaiseEvent IsOfferLocked(lb_IsLocked)
  If lb_IsLocked Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9851, "#Offer is open for add/update/delete in different component. Please, close it first.")
  End If
  IsOfferLocked = lb_IsLocked
  Exit Function
ErrHandler:
  Call ErrorHandler("IsOfferLocked")
End Function

Private Function GetOfferStatus(ByVal as_COF_Id As String, ByRef as_STA_Name As String) As eOfferStatus
On Error GoTo ErrHandler

Dim lc_Cursor As Long
Dim ls_req As String

  GetOfferStatus = eOfferStatus.osNone
  as_STA_Name = ""
  
  ls_req = "SELECT COF.COF_Stat, RST.RF_Desc "
  ls_req = ls_req & "FROM Cap_Offer COF "
  ls_req = ls_req & "LEFT JOIN A_References_ML RST ON (RST.GR_Code=802 AND RST.Language_Code=$Language_Code$ AND COF.COF_Stat=RST.RF_Code) "
  ls_req = ls_req & "WHERE COF_Id=$COF_Id$"
  ls_req = Replace(ls_req, "$COF_Id$", mo_Tools.SQLStr(as_COF_Id), , , vbTextCompare)
  ls_req = ReplaceCommonPlaceholders(ls_req)
  lc_Cursor = mo_Tools.OpenSQLSafe(mo_Db, ls_req)
  If mo_Db.RowCount(lc_Cursor) = 1 Then
    GetOfferStatus = mo_Db.GetFields(lc_Cursor, "COF_Stat")
    as_STA_Name = mo_Db.GetFields(lc_Cursor, "RF_Desc")
  End If
  Call mo_Db.Close(lc_Cursor)
  Exit Function
ErrHandler:
  Call ErrorHandler("GetOfferStatus")
End Function

Public Function CanAddOffer(ByVal as_SP_Capkey As String) As Boolean
On Error GoTo ErrHandler

  CanAddOffer = False
  If IsOfferLocked Then
    Exit Function
  End If
  CanAddOffer = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanAddOffer")
End Function

Public Function CanUpdateOffer(ByVal as_SP_Capkey As String, ByVal as_COF_Id As String) As Boolean
On Error GoTo ErrHandler

Dim le_STA_Id As eOfferStatus
Dim ls_STA_Name As String

  CanUpdateOffer = False
  le_STA_Id = GetOfferStatus(as_COF_Id, ls_STA_Name)
  If IsProduction Then
    If (le_STA_Id = eOfferStatus.osWaitCustConfirmation) Or (le_STA_Id = eOfferStatus.osBaeurerSalesOrder) Or (le_STA_Id = eOfferStatus.osSAPSalesOrder) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9867, "#You cannot update offer with status '$STATUS$'", Array("$STATUS$", ls_STA_Name))
      Exit Function
    End If
  Else
    If (le_STA_Id = eOfferStatus.osPlanningProcess) Or (le_STA_Id = eOfferStatus.osBaeurerSalesOrder) Or (le_STA_Id = eOfferStatus.osSAPSalesOrder) Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9867, "#You cannot update offer with status '$STATUS$'", Array("$STATUS$", ls_STA_Name))
      Exit Function
    End If
  End If
  
  If (le_STA_Id = eOfferStatus.osBaeurerSalesOrderChange) Or (le_STA_Id = eOfferStatus.osSAPSalesOrderChange) Then
    If Not mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_SALESORDERCHANGE") Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9868, "#You do not have enough rights to do this operation")
      Exit Function
    End If
  End If

  If (le_STA_Id = eOfferStatus.osSAPChangedAfterSO) Then
    If Not mo_Tools.HasSecurityAlias(ms_LoginName, "DPC_SALESORDERAFTERSO") Then
      Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9868, "#You do not have enough rights to do this operation")
      Exit Function
    End If
  End If
  
  If Not GetOfferLock(as_COF_Id) Then
    Exit Function
  End If
  'If IsProduction Then
  '  CanUpdateOffer = (al_COF_Stat = eOfferStatus.osUnderApprovalProcess)
  'Else
  '  CanUpdateOffer = (al_COF_Stat = eOfferStatus.osNew) Or (al_COF_Stat = eOfferStatus.osOfferDefinition) Or (al_COF_Stat = eOfferStatus.osOfferNeedApproval)
  'End If
  CanUpdateOffer = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanUpdateOffer")
End Function

Private Function CanDeleteOffer(ByVal as_SP_Capkey As String, ByVal as_COF_Id As String) As Boolean
On Error GoTo ErrHandler

Dim le_STA_Id As eOfferStatus
Dim ls_STA_Name As String

  CanDeleteOffer = False
  If Not CanUpdateOffer(as_SP_Capkey, as_COF_Id) Then
    Exit Function
  End If
  
  le_STA_Id = GetOfferStatus(as_COF_Id, ls_STA_Name)
  If (le_STA_Id = eOfferStatus.osSAPSalesOrderChange) Or (le_STA_Id = eOfferStatus.osSAPSalesOrder) Or (le_STA_Id = eOfferStatus.osSAPChangedAfterSO) Then
    Exit Function
  End If
  CanDeleteOffer = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanDeleteOffer")
End Function

Private Function CanAddSubitem() As Boolean
On Error GoTo ErrHandler

  CanAddSubitem = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanAddSubitem")
End Function

Private Function CanUpdateSubitem() As Boolean
On Error GoTo ErrHandler

  CanUpdateSubitem = False
  If Status = eOfferStatus.osSAPSalesOrderChange Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9867, "#You cannot update offer with status '$STATUS$'", Array("$STATUS$", cbo_Status.Text))
    Exit Function
  End If
  CanUpdateSubitem = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanUpdateSubitem")
End Function

Private Function CanDeleteSubitem() As Boolean
On Error GoTo ErrHandler

  CanDeleteSubitem = False
  If Status = eOfferStatus.osSAPSalesOrderChange Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9867, "#You cannot update offer with status '$STATUS$'", Array("$STATUS$", cbo_Status.Text))
    Exit Function
  End If
  CanDeleteSubitem = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanDeleteSubitem")
End Function

Public Function CanPriceMgrOffer(ByVal as_SP_Capkey As String, ByVal as_COF_Id As String) As Boolean
On Error GoTo ErrHandler

Dim le_STA_Id As eOfferStatus
Dim ls_STA_Name As String
  
  CanPriceMgrOffer = False
  
  le_STA_Id = GetOfferStatus(as_COF_Id, ls_STA_Name)
  If Not GetOfferLock(as_COF_Id) Then
    Exit Function
  End If
  CanPriceMgrOffer = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanPriceMgrOffer")
End Function

Public Function CanSendOffer(ByVal as_COF_Id As String) As Boolean
On Error GoTo ErrHandler

Dim le_STA_Id As eOfferStatus
Dim ls_STA_Name As String

  CanSendOffer = False
  le_STA_Id = GetOfferStatus(as_COF_Id, ls_STA_Name)
  
  'if (le_STA_Id = eOfferStatus.osWaitCustConfirmation) Or _
  '                (le_STA_Id = eOfferStatus.osSentToCustomer) Or _
  '                (le_STA_Id = eOfferStatus.osSAP)
  If Not mo_Tools.HasSecurityAlias(ms_LoginName, "Cap_OfferPrint") Then
    Call mo_Tools.ShowMsg(mo_Db, ms_Language_Code, 9868, "#You do not have enough rights to do this operation")
    Exit Function
  End If
  
  CanSendOffer = True
  Exit Function
ErrHandler:
  Call ErrorHandler("CanSendOffer")
End Function

Public Function CanSendOfferConfirmation(ByVal as_COF_Id As String) As Boolean
On Error GoTo ErrHandler

Dim le_STA_Id As eOfferStatus
Dim ls_STA_Name As String

  CanSendOfferConfirmation = True
  le_STA_Id = GetOfferStatus(as_COF_Id, ls_STA_Name)
  Exit Function
ErrHandler:
  Call ErrorHandler("CanSendOfferConfirmation")
End Function

Private Function IsTelNum(ByVal as_telNum As String) As Boolean
On Error GoTo ErrHandler
  Dim ll_i  As Long
  IsTelNum = False
  ' must start with 00XXY
  If Len(as_telNum) < 5 Then Exit Function
  If Left(as_telNum, 2) <> "00" Then Exit Function
  
  ' tel number must containt only digits 0..9
  For ll_i = 1 To Len(as_telNum)
      If Mid(as_telNum, ll_i, 1) < "0" Then Exit Function
      If Mid(as_telNum, ll_i, 1) > "9" Then Exit Function
  Next
  IsTelNum = True
  Exit Function
ErrHandler:
  Call ErrorHandler("IsTelNum")
End Function

Private Function GetSAPItemPrice(ByVal as_slsorg As String, ByVal as_priceGroup As String, ByVal ad_price_date As Date, _
                                 ByVal as_BI_SAP_Code As String, ByVal ad_Qty As Double, ByVal as_UOM As String, _
                                 ByVal as_CUST_Code As String, _
                                 ByRef as_CURR_Code As String, ByRef as_ErrMessage As String, ByRef at_ErrMsg) As Double
On Error GoTo ErrHandler
    Dim ls_retContent   As String
    Dim ls_retHeader    As String
    Dim lo_XMLParam     As SvcXMLParam
    Dim ll_i            As Long

    at_ErrMsg = ErrMsgNone

    GetSAPItemPrice = -1
    as_CURR_Code = ""
    If as_BI_SAP_Code = "" Then Exit Function

    'A130
    Set lo_XMLParam = New SvcXMLParam
    Call SAP_ORDER_HEADER_IN_add(lo_XMLParam, _
                                 as_slsorg, as_priceGroup, ad_price_date)

    Call lo_XMLParam.AddTable("ORDER_ITEMS_IN")

    Call SAP_ORDER_ITEMS_IN_add(lo_XMLParam, as_BI_SAP_Code, ad_Qty, as_UOM)

    Call ORDER_PARTNERS_add(lo_XMLParam, as_CUST_Code)

    If mo_Sys.CallWebservice(mo_A_Config(C_A_CONFIG_UrlGetSalesOrder), C_SAP_LOGIN, C_SAP_PASSW, lo_XMLParam.SerializedXML, "text/xml", "", ls_retContent, ls_retHeader) Then
        If lo_XMLParam.CheckHTTPResponse(ls_retHeader) Then
            ' OK
            If lo_XMLParam.TestContentType(ls_retHeader, "text/xml") Then
                ' we have response type of xml
#If LIVE = 1 Then
                Dim lo_retXML As Object
#Else
                Dim lo_retXML As MSXML2.DOMDocument
#End If
                Set lo_retXML = CreateObject("MSXML2.DOMDocument")
                If lo_retXML.loadXML(ls_retContent) Then
                    Dim ls_SAPCode As String
                    Dim lo_XMLItem As MSXML2.IXMLDOMNode

                    ' update item prices
                    Set lo_XMLItem = lo_retXML.selectSingleNode("/Return/ORDER_ITEMS_OUT/ROW")

                    While Not lo_XMLItem Is Nothing
                        'Debug.Print (lo_XMLItem.xml)
                        as_CURR_Code = lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "CURRENCY")    ' take currency of product
                        GetSAPItemPrice = GetSAPPrice(lo_XMLParam, lo_XMLItem)
                        Set lo_XMLItem = lo_XMLItem.nextSibling
                    Wend

                    ' check if message is occured
                    Set lo_XMLItem = lo_retXML.selectSingleNode("/Return/MESSAGETABLE/ROW")
                    If Not lo_XMLItem Is Nothing Then
                        ' record messages per item
                        at_ErrMsg = ErrMsg_M701
                        as_ErrMessage = vbCrLf
                    End If

                    ' record messages per item
                    While Not lo_XMLItem Is Nothing
                        'Debug.Print (lo_XMLItem.xml)
                        ll_i = -1

                        Select Case lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "TYPE")
                        Case "E"        ' error
                            If lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "NUMBER") = "384" Then

                                ' get l_li based on line number ( not deleted )
                                If IsNumeric(lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "MESSAGE_V2")) Then

'                                    ll_X = lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "MESSAGE_V2") / 10 - 1
                                    ll_i = 0
                                End If
                            Else
                                ' get l_li based on item number
                                If as_BI_SAP_Code = lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "MESSAGE_V1") Then
                                    ll_i = 0
                                End If
                            End If
                        Case "W"        ' warning
                            ' get l_li based on line number ( not deleted )
                            If IsNumeric(lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "MESSAGE_V1")) Then
'                                ll_X = lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "MESSAGE_V1") / 10 - 1
                                ll_i = 0
                            End If

                        End Select
                        as_ErrMessage = as_ErrMessage & lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "NUMBER") & " " & lo_XMLParam.GetXMLNodeValue(lo_XMLItem, "MESSAGE") & vbCrLf

                        Set lo_XMLItem = lo_XMLItem.nextSibling
                    Wend
                Else
                    at_ErrMsg = ErrMsg_M703
                    as_ErrMessage = ls_retContent
                End If
                Set lo_retXML = Nothing
            Else
                ' not axpected answer from the server, probably fatal error in server routine
                as_ErrMessage = ls_retContent
                at_ErrMsg = ErrMsg_M703
            End If
        Else
            ' not axpected answer from the server, probably fatal error in server routine
            as_ErrMessage = ls_retContent
            at_ErrMsg = ErrMsg_M702
        End If
'        Debug.Print ls_retContent
'        Debug.Print ls_retHeader
    Else
'        If txt_SPA_ApprovalStatus.Text = eSPA_ApprovalStatus.SPAS_Submited Then
            ' need to raise exception
            as_ErrMessage = "Webservice on '" & mo_A_Config(C_A_CONFIG_UrlGetSalesOrder) & "' call failed"
            at_ErrMsg = ErrMsg_M704
'        End If
    End If

    Set lo_XMLParam = Nothing

    Exit Function
ErrHandler:
    Set lo_XMLParam = Nothing
    Call ErrorHandler("GetSAPItemPrice")
End Function


Private Sub SAP_ORDER_HEADER_IN_add(ByRef ao_XMLparam As SvcXMLParam, ByVal as_slsorg As String, ByVal as_priceGroup As String, ByVal ad_price_date As Date)
On Error GoTo ErrHandler

    Call ao_XMLparam.AddStruct("ORDER_HEADER_IN")
    Call ao_XMLparam.AddParameter("ORDER_HEADER_IN", "DOC_TYPE", mo_A_Config(C_A_CONFIG_Doc_Type))
    Call ao_XMLparam.AddParameter("ORDER_HEADER_IN", "SALES_ORG", as_slsorg)
    Call ao_XMLparam.AddParameter("ORDER_HEADER_IN", "DISTR_CHAN", mo_A_Config(C_A_CONFIG_Distr_Chan))
    Call ao_XMLparam.AddParameter("ORDER_HEADER_IN", "DIVISION", mo_A_Config(C_A_CONFIG_Division))
    Call ao_XMLparam.AddParameter("ORDER_HEADER_IN", "PRICE_DATE", Format(ad_price_date, "dd\/mm\/yyyy"))
    If as_priceGroup <> "" Then
        Call ao_XMLparam.AddParameter("ORDER_HEADER_IN", "PRICE_GRP", as_priceGroup)
    End If

    Exit Sub
ErrHandler:
    Call ErrorHandler("SAP_ORDER_HEADER_IN_add")
End Sub

Private Sub SAP_ORDER_ITEMS_IN_add(ByRef ao_XMLparam As SvcXMLParam, ByVal as_SAP_Code As String, ByVal ad_Qty As Double, ByVal as_UOM As String)
On Error GoTo ErrHandler
    Call ao_XMLparam.AddTableRow("ORDER_ITEMS_IN", _
            Array( _
                    Array("MATERIAL", as_SAP_Code), _
                    Array("REQ_QTY", CLng(ad_Qty * 1000)), _
                    Array("SALES_UNIT", as_UOM) _
            ))
    Exit Sub
ErrHandler:
    Call ErrorHandler("SAP_ORDER_ITEMS_IN")
End Sub

Private Sub ORDER_PARTNERS_add(ByRef ao_XMLparam As SvcXMLParam, ByVal as_CUST_Code As String)
On Error GoTo ErrHandler
    Call ao_XMLparam.AddTable("ORDER_PARTNERS")
    Call ao_XMLparam.AddTableRow("ORDER_PARTNERS", _
            Array( _
                    Array("PARTN_ROLE", mo_A_Config(C_A_CONFIG_Partn_Role)), _
                    Array("PARTN_NUMB", as_CUST_Code) _
            ))
    Exit Sub
ErrHandler:
    Call ErrorHandler("ORDER_PARTNERS_add")
End Sub

Private Function GetSAPPrice(ByRef ao_XMLparam As SvcXMLParam, ByRef ao_dataSrc As MSXML2.IXMLDOMNode) As Double
On Error GoTo ErrHandler

    Dim ls_SAPCode As String
    Dim ld_sapPrice As Double
    Dim ld_spa_Price As Double
    Dim ld_Qty_Req As Double  ' special number, divide subtotal by this number
    Dim ls_val As String

    GetSAPPrice = -1

    ls_SAPCode = ao_XMLparam.GetXMLNodeValue(ao_dataSrc, "MATERIAL")
    ls_val = Replace(ao_XMLparam.GetXMLNodeValue(ao_dataSrc, "SUBTOTAL_2"), ".", ms_DecimalSeparator, , , vbTextCompare)
    If IsNumeric(ls_val) Then
        ld_sapPrice = CDbl(ls_val)

        'ls_val = Replace(ao_XMLParam.GetXMLNodeValue(ao_dataSrc, "REQ_QTY"), ".", ms_DecimalSeparator, , , vbTextCompare)
        ls_val = Replace(ao_XMLparam.GetXMLNodeValue(ao_dataSrc, "QTY_REQ_DT"), ".", ms_DecimalSeparator, , , vbTextCompare)
        If IsNumeric(ls_val) Then
            ld_Qty_Req = CDbl(ls_val) / 10
        Else
            ld_Qty_Req = 0
        End If

        If ld_Qty_Req > 0 Then
            ld_sapPrice = Round((ld_sapPrice / ld_Qty_Req), 2)      ' 16.4. round sap_price to 2 decimal places
        Else
            ld_sapPrice = 0
        End If
    Else
        ld_sapPrice = 0
    End If
    GetSAPPrice = ld_sapPrice
    Exit Function
ErrHandler:
    Call ErrorHandler("GetSAPPrice")
End Function


Private Function ReplaceCommonPlaceholders(ByVal as_Request As String) As String
On Error GoTo ErrHandler

  as_Request = Replace(as_Request, "$Z_Creator$", mo_Tools.SqlInt(ml_U_Code), , , vbTextCompare)
  as_Request = Replace(as_Request, "$U_Code$", mo_Tools.SqlInt(ml_U_Code), , , vbTextCompare)
  as_Request = Replace(as_Request, "$Z_Last_Upd_User$", mo_Tools.SqlInt(ml_U_Code), , , vbTextCompare)
  as_Request = Replace(as_Request, "$iConcurrency$", mo_Tools.SqlInt(ml_iConcurrency), , , vbTextCompare)
  as_Request = Replace(as_Request, "$Language_Code$", mo_Tools.SQLStr(ms_Language_Code), , , vbTextCompare)
  as_Request = Replace(as_Request, "$COF_Lang$", mo_Tools.SQLStr(ms_COF_Lang), , , vbTextCompare)
  ReplaceCommonPlaceholders = as_Request
  Exit Function
ErrHandler:
  Call ErrorHandler("ReplaceCommonPlaceholders")
End Function


' display standard error message
Public Sub ErrorMessage(ByVal as_Fct As String)
  Dim ls_ErrSource As String
  Dim ls_errDescription As String
  Dim ls_Message As String
  
  ls_ErrSource = as_Fct & SEP1 & Err.Source
  ls_errDescription = Err.Description
  ls_Message = SCREEN_NAME & " exception. Nr:" & Err.Number & ",Desc: " & ls_errDescription & ",Src:" & ls_ErrSource & "@"
  Call mo_Tools.LogMessage(mo_Db, ml_U_Code, SCREEN_NAME, ls_Message, "E")
  Call MsgBox("Error occured, please contact IT. Application will now shutdown." & vbCrLf & ls_ErrSource & vbCrLf & "Description: " & ls_errDescription, vbCritical, App.Title & " " & App.Major & "." & App.Minor & "." & App.Revision)
  End
End Sub

' Standard error handler
Private Sub ErrorHandler(ByVal as_Fct As String)
  
  Call Err.Raise(Err.Number, UserControl.Name & "." & as_Fct & SEP1 & Err.Source, Err.Description)
End Sub

