VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Begin VB.Form Form_listado_cheques_factoring 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Listado de cheques a factoring"
   ClientHeight    =   8190
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   15300
   Icon            =   "Form_listado_cheques_factoring.frx":0000
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   8190
   ScaleWidth      =   15300
   Begin VB.Frame Frame3 
      Caption         =   "Buscar por"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   120
      TabIndex        =   8
      Top             =   120
      Width           =   1455
      Begin VB.OptionButton Option2 
         Caption         =   "Rendicion"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   120
         TabIndex        =   10
         Top             =   600
         Width           =   1215
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Fecha"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   9
         Top             =   360
         Width           =   975
      End
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Exportar Excel"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   120
      Picture         =   "Form_listado_cheques_factoring.frx":2A8B2
      Style           =   1  'Graphical
      TabIndex        =   7
      Top             =   7200
      Width           =   1575
   End
   Begin VB.CommandButton cmd_salir 
      Caption         =   "Salir"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   13560
      Picture         =   "Form_listado_cheques_factoring.frx":2AE98
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   7200
      Width           =   1575
   End
   Begin VB.Frame Frame1 
      Caption         =   "Exportar cheques a Excel"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   5415
      Left            =   120
      TabIndex        =   1
      Top             =   1440
      Width           =   15015
      Begin VB.Frame Frame2 
         Caption         =   "Frame2"
         Height          =   2175
         Left            =   2640
         TabIndex        =   2
         Top             =   1800
         Visible         =   0   'False
         Width           =   9375
         Begin VB.Label Label2 
            Caption         =   "En proceso"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   48
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   975
            Left            =   2280
            TabIndex        =   3
            Top             =   600
            Width           =   5415
         End
      End
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   5055
         Left            =   120
         TabIndex        =   4
         Top             =   240
         Width           =   14655
         _ExtentX        =   25850
         _ExtentY        =   8916
         _Version        =   393216
      End
      Begin VB.Label Label4 
         Caption         =   "Factoring"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   9480
         TabIndex        =   5
         Top             =   1080
         Width           =   855
      End
   End
   Begin VB.CommandButton Command3 
      Caption         =   "Listado Cheques a Factoring"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   1920
      TabIndex        =   0
      Top             =   7200
      Width           =   1575
   End
   Begin VB.Frame Frame_rendicion 
      Caption         =   "Rendición"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   1680
      TabIndex        =   19
      Top             =   120
      Visible         =   0   'False
      Width           =   13455
      Begin VB.CommandButton Command5 
         Caption         =   "Listar cheques"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   11400
         TabIndex        =   30
         Top             =   360
         Width           =   1695
      End
      Begin VB.ComboBox cb_encargado_r 
         Height          =   315
         Left            =   6600
         TabIndex        =   29
         Top             =   480
         Width           =   3735
      End
      Begin VB.ComboBox cb_factoring_r 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   3480
         TabIndex        =   26
         Top             =   480
         Width           =   2895
      End
      Begin VB.TextBox Text2 
         Height          =   375
         Left            =   1800
         TabIndex        =   23
         Top             =   480
         Width           =   1455
      End
      Begin VB.TextBox Text1 
         Height          =   375
         Left            =   120
         TabIndex        =   22
         Top             =   480
         Width           =   1455
      End
      Begin VB.Label Label10 
         Caption         =   "Encargado"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   6600
         TabIndex        =   28
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label9 
         Caption         =   "Factoring"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3480
         TabIndex        =   27
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label8 
         Caption         =   "Hasta"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   1800
         TabIndex        =   21
         Top             =   240
         Width           =   615
      End
      Begin VB.Label Label7 
         Caption         =   "Desde"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   20
         Top             =   240
         Width           =   615
      End
   End
   Begin VB.Frame Frame_fecha 
      Caption         =   "Fecha"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   1680
      TabIndex        =   11
      Top             =   120
      Visible         =   0   'False
      Width           =   13455
      Begin VB.ComboBox cb_encargado 
         Height          =   315
         Left            =   6600
         TabIndex        =   25
         Top             =   480
         Width           =   3735
      End
      Begin VB.CommandButton Command1 
         Caption         =   "Listar cheques"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   495
         Left            =   11400
         TabIndex        =   13
         Top             =   360
         Width           =   1695
      End
      Begin VB.ComboBox cb_factoring 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   3480
         TabIndex        =   12
         Top             =   480
         Width           =   2895
      End
      Begin MSComCtl2.DTPicker DTP_inicio 
         Height          =   375
         Left            =   120
         TabIndex        =   14
         Top             =   480
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   661
         _Version        =   393216
         Format          =   94371841
         CurrentDate     =   42103
      End
      Begin MSComCtl2.DTPicker DTP_hasta 
         Height          =   375
         Left            =   1800
         TabIndex        =   15
         Top             =   480
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   661
         _Version        =   393216
         Format          =   94371841
         CurrentDate     =   42103
      End
      Begin VB.Label Label5 
         Caption         =   "Encargado"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   6600
         TabIndex        =   24
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label6 
         Caption         =   "Factoring"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3480
         TabIndex        =   18
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label3 
         Caption         =   "Hasta"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   1800
         TabIndex        =   17
         Top             =   240
         Width           =   615
      End
      Begin VB.Label Label1 
         Caption         =   "Desde"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   16
         Top             =   240
         Width           =   615
      End
   End
   Begin ComctlLib.ProgressBar pgbar 
      Height          =   255
      Left            =   120
      TabIndex        =   31
      Top             =   6840
      Width           =   15015
      _ExtentX        =   26485
      _ExtentY        =   450
      _Version        =   327682
      Appearance      =   1
   End
End
Attribute VB_Name = "Form_listado_cheques_factoring"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Rec2Grid(ByRef rec As ADODB.Recordset, ByRef grid As Object, Optional ByVal Numeracion As Boolean = True)
    grid.Clear
    If rec.RecordCount > 0 Then
        grid.Cols = rec.Fields.count + 1
        grid.Rows = rec.RecordCount + 1
        grid.FixedCols = 1
        grid.FixedRows = 1
        grid.TextMatrix(0, 0) = "Nº"
        grid.ColWidth(0) = IIf(Numeracion, TextWidth(grid.TextMatrix(0, 0)) + 100, 0)
        For i = 1 To rec.Fields.count
            grid.TextMatrix(0, i) = UCase(rec.Fields(i - 1).Name)
            grid.ColWidth(i) = TextWidth(grid.TextMatrix(0, i)) + 100
        Next i
        rec.MoveFirst
        For i = 1 To rec.RecordCount
            'progreso.Value = i
            grid.TextMatrix(i, 0) = i
            grid.ColWidth(0) = IIf(Numeracion, IIf(TextWidth(grid.TextMatrix(i, 0)) + 100 > grid.ColWidth(0), TextWidth(grid.TextMatrix(i, 0)) + 100, grid.ColWidth(0)), 0)
            For j = 1 To rec.Fields.count
                grid.TextMatrix(i, j) = IIf(IsNull(rec(j - 1)), "Null", rec(j - 1))
                grid.ColWidth(j) = IIf(TextWidth(grid.TextMatrix(i, j)) + 100 > grid.ColWidth(j), TextWidth(grid.TextMatrix(i, j)) + 100, grid.ColWidth(j))
            Next j
            rec.MoveNext
        Next i
    Else
        grid.Cols = 2
        grid.Rows = 2
    End If
End Sub

Private Sub cmd_salir_Click()
    Unload Me
End Sub

Private Sub Command1_Click()
    Dim var_sql As String
    Dim conecta As Boolean
    Dim maximo_mes As Integer
    Dim dia As Integer, mes As Integer, agno As Integer
    Dim mes_palabra As String
   
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    Frame2.Visible = True
    
'            & " ON CONCAT(cur.num_gra,cur.let_cur,cur.des_ens) = CONCAT(asi.grado,asi.letra,asi.nivel)"
                
    If cb_encargado.Text = "" Then
    var_sql = "SELECT run_tit as 'Rut Deudor',nom_tit as 'Nombre Deudor',banco as BANCO,numero as '# Cheque',verificacion as VERIFICACION,banco_plaza as 'Banco y Plaza'" _
            & ",cta_cte AS 'Cuenta Cte.',fec_venc AS Vencimiento, concat('$ ',monto) as 'Monto Docto.','" & cb_factoring.Text & "' AS FACTORING " _
            & " FROM fnza_captura_cheques" _
            & " WHERE CONCAT(MID(fec_ingreso,7,4),MID(fec_ingreso,4,2),MID(fec_ingreso,1,2)) >= '" & Year(DTP_inicio.Value) & Format(DTP_inicio.Value, "mm") & Format(DTP_inicio.Value, "dd") & "'" _
            & " and CONCAT(MID(fec_ingreso,7,4),MID(fec_ingreso,4,2),MID(fec_ingreso,1,2)) <= '" & Year(DTP_hasta.Value) & Format(DTP_hasta.Value, "mm") & Format(DTP_hasta.Value, "dd") & "'"
    Else
    var_sql = "SELECT run_tit as 'Rut Deudor',nom_tit as 'Nombre Deudor',banco as BANCO,numero as '# Cheque',verificacion as VERIFICACION,banco_plaza as 'Banco y Plaza'" _
            & ",cta_cte AS 'Cuenta Cte.',fec_venc AS Vencimiento, concat('$ ',monto) as 'Monto Docto.','" & cb_factoring.Text & "' AS FACTORING " _
            & " FROM fnza_captura_cheques" _
            & " WHERE CONCAT(MID(fec_ingreso,7,4),MID(fec_ingreso,4,2),MID(fec_ingreso,1,2)) >= '" & Year(DTP_inicio.Value) & Format(DTP_inicio.Value, "mm") & Format(DTP_inicio.Value, "dd") & "'" _
            & " and CONCAT(MID(fec_ingreso,7,4),MID(fec_ingreso,4,2),MID(fec_ingreso,1,2)) <= '" & Year(DTP_hasta.Value) & Format(DTP_hasta.Value, "mm") & Format(DTP_hasta.Value, "dd") & "'" _
            & " and usuario_ingreso = '" & cb_encargado.Text & "'"
    End If
                
            '' " AND fec_ingreso >= '2015-05-05 00:00:00' AND fec_ingreso <= '2015-06-05 23:59:59'"
                
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        Call Rec2Grid(objRS, MSFlexGrid1, True)
       ' msflex_alumnos.ColSel = 5
        var_sql = "DROP TABLE IF EXISTS temp_cheques_capturados;"
        conn.Execute var_sql
        If cb_encargado.Text = "" Then
        var_sql = "create table temp_cheques_capturados type = MyISAM select *" _
            & " FROM fnza_captura_cheques" _
            & " WHERE CONCAT(MID(fec_ingreso,7,4),MID(fec_ingreso,4,2),MID(fec_ingreso,1,2)) >= '" & Year(DTP_inicio.Value) & Format(DTP_inicio.Value, "mm") & Format(DTP_inicio.Value, "dd") & "'" _
            & " and CONCAT(MID(fec_ingreso,7,4),MID(fec_ingreso,4,2),MID(fec_ingreso,1,2)) <= '" & Year(DTP_hasta.Value) & Format(DTP_hasta.Value, "mm") & Format(DTP_hasta.Value, "dd") & "'"
        conn.Execute var_sql
        Else
        var_sql = "create table temp_cheques_capturados type = MyISAM SELECT *" _
            & " FROM fnza_captura_cheques" _
            & " WHERE CONCAT(MID(fec_ingreso,7,4),MID(fec_ingreso,4,2),MID(fec_ingreso,1,2)) >= '" & Year(DTP_inicio.Value) & Format(DTP_inicio.Value, "mm") & Format(DTP_inicio.Value, "dd") & "'" _
            & " and CONCAT(MID(fec_ingreso,7,4),MID(fec_ingreso,4,2),MID(fec_ingreso,1,2)) <= '" & Year(DTP_hasta.Value) & Format(DTP_hasta.Value, "mm") & Format(DTP_hasta.Value, "dd") & "'" _
            & " and usuario_ingreso = '" & cb_encargado.Text & "'"
        conn.Execute var_sql
        End If
    Else
       MsgBox "No se han ingresado cheques en el rango seleccionado", vbInformation
    End If
    objRS.Close
    MSFlexGrid1.Refresh
    
    Frame2.Visible = False
   
End Sub

Private Sub Command2_Click()
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim ApExcel As Variant
    Set ApExcel = CreateObject("Excel.application")
    ApExcel.Workbooks.Add
          
    For i = 1 To 20
        ApExcel.Cells(1, i).Font.Size = 12
        ApExcel.Cells(1, i).Font.Bold = True
        'ApExcel.Cells(1, i).Formula = Me.MSFlexGrid1.TextMatrix(0, i - 1)
    Next i
    'ApExcel.Cells(1, 11).Font.Size = 12
    'ApExcel.Cells(1, 11).Font.Bold = True
    
    ApExcel.Cells(1, 1).Formula = UCase("run_apo")
    ApExcel.Cells(1, 2).Formula = UCase("apoderado")
    ApExcel.Cells(1, 3).Formula = UCase("rut")
    ApExcel.Cells(1, 4).Formula = UCase("titular")
    ApExcel.Cells(1, 5).Formula = UCase("telefono")
    ApExcel.Cells(1, 6).Formula = UCase("banco")
    ApExcel.Cells(1, 7).Formula = UCase("cta_cte")
    ApExcel.Cells(1, 8).Formula = UCase("serie")
    ApExcel.Cells(1, 9).Formula = UCase("numero")
    ApExcel.Cells(1, 10).Formula = UCase("fecha")
    ApExcel.Cells(1, 11).Formula = UCase("monto")
    ApExcel.Cells(1, 12).Formula = UCase("verificacion")
    ApExcel.Cells(1, 13).Formula = UCase("banco plaza")
    ApExcel.Cells(1, 14).Formula = UCase("fecha Venc.")
    ApExcel.Cells(1, 15).Formula = UCase("Fecha ingreso")
    ApExcel.Cells(1, 16).Formula = UCase("usuario_ingreso")
    ApExcel.Cells(1, 17).Formula = UCase("N° rendicion")
    ApExcel.Cells(1, 18).Formula = UCase("fecha rendicion")
    ApExcel.Cells(1, 19).Formula = UCase("Año")
    ApExcel.Cells(1, 20).Formula = UCase("rendicion")
    
   
    'ApExcel.Columns("G"). = 300
    'ApExcel.Range("G:G").ColumnWidth = 50
    ApExcel.Columns(7).Select
    'ApExcel.Selection.NumberFormat = "#"
    ApExcel.Selection.NumberFormat = "@"
    
    If cb_factoring.Text <> "" Then
        ApExcel.Cells(1, 11) = "FACTORING"
    End If
    
'    For i = 1 To MSFlexGrid1.Rows - 1
'         For j = 1 To MSFlexGrid1.Cols - 1
'            'ApExcel.Cells((i + 1), j).WrapText = True
'            ApExcel.Cells((i + 1), j) = IIf(MSFlexGrid1.TextMatrix(i, j - 1) = "Null", "", MSFlexGrid1.TextMatrix(i, j - 1))
'
''            pgbar.Value = i
'         Next j
'         If cb_factoring.Text <> "" Then
'            ApExcel.Cells((i + 1), j) = cb_factoring.Text
'         End If
'    Next i
    
    var_sql = "SELECT * FROM temp_cheques_capturados"
    objRS.Open var_sql, conn
    i = 0
    pgbar.Min = 1
    pgbar.Max = MSFlexGrid1.Rows
    pgbar.Value = pgbar.Min
    While Not objRS.EOF
        i = i + 1
        For j = 0 To 19
            ApExcel.Cells((i + 1), j + 1) = objRS(j)
        Next j
        objRS.MoveNext
        pgbar.Value = i
    Wend
    objRS.Close
            
    ApExcel.Visible = True
    'ApExcel.Range("a1:x1").Borders.color = RGB(255, 0, 0)
    Set ApExcel = Nothing
End Sub

Private Sub Command3_Click()
    Dim facto As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim ApExcel As Variant
    Set ApExcel = CreateObject("Excel.application")
    ApExcel.Workbooks.Add
          
    For i = 1 To Me.MSFlexGrid1.Cols - 1
        ApExcel.Cells(1, i).Font.Size = 12
        ApExcel.Cells(1, i).Font.Bold = True
        ApExcel.Cells(1, i).Formula = Me.MSFlexGrid1.TextMatrix(0, i - 1)
    Next i
    ApExcel.Cells(1, 11).Font.Size = 12
    ApExcel.Cells(1, 11).Font.Bold = True
    

    'ApExcel.Columns("G"). = 300
    ApExcel.Range("A:A").ColumnWidth = 5
    ApExcel.Range("B:B").ColumnWidth = 14
    ApExcel.Range("C:C").ColumnWidth = 38
    ApExcel.Range("D:D").ColumnWidth = 38
    ApExcel.Range("E:E").ColumnWidth = 10
    ApExcel.Range("F:F").ColumnWidth = 15
    ApExcel.Range("G:G").ColumnWidth = 15
    ApExcel.Range("H:H").ColumnWidth = 15
    ApExcel.Range("I:I").ColumnWidth = 15
    ApExcel.Range("J:J").ColumnWidth = 15
    ApExcel.Range("L:L").ColumnWidth = 15
    ApExcel.Columns(7).Select
    'ApExcel.Selection.NumberFormat = "#"
    ApExcel.Selection.NumberFormat = "@"
    
    'If cb_factoring.Text <> "" Then
        ApExcel.Cells(1, 11) = "FACTORING"
    'End If
    facto = ""
    If Option1.Value = True Then
        facto = cb_factoring.Text
        accion = "Impresion a Factoring"
    End If
    If Option2.Value = True Then
        facto = cb_factoring_r.Text
           accion = "Impresion a Factoring"
           accion_detalle = "Se han impreso a factoring las rendiciones desde la " & Text1.Text & " a la " & Text2.Text
           Call Inserta_Vitacora_Finanza("11111111-1", "11111111-1", CStr(accion), CStr(accion_detalle), 0, 0)
    End If
    
    pgbar.Min = 1
    pgbar.Max = MSFlexGrid1.Rows
    pgbar.Value = pgbar.Min
    
    For i = 1 To MSFlexGrid1.Rows - 1
         For j = 1 To MSFlexGrid1.Cols '- 1
            'ApExcel.Cells((i + 1), j).WrapText = True
            ApExcel.Cells((i + 1), j) = IIf(MSFlexGrid1.TextMatrix(i, j - 1) = "Null", "", MSFlexGrid1.TextMatrix(i, j - 1))
        
            
         Next j
         var_sql = "update fnza_captura_cheques set factoring = '" & facto & "'" _
                 & " WHERE RUN_TIT = '" & MSFlexGrid1.TextMatrix(i, 1) & "' AND BANCO = '" & MSFlexGrid1.TextMatrix(i, 3) & "'" _
                 & " AND NUMERO = " & MSFlexGrid1.TextMatrix(i, 4) & " AND CTA_CTE = '" & MSFlexGrid1.TextMatrix(i, 7) & "'"
         conn.Execute var_sql
         pgbar.Value = i
         If facto <> "" Then
            ApExcel.Cells((i + 1), j - 1) = facto
         End If
         If facto <> "" Then
            accion_detalle = "Se han impreso al factoring " & facto & " el cheque numero " & MSFlexGrid1.TextMatrix(i, 4) _
                           & ", con Cta Cte " & MSFlexGrid1.TextMatrix(i, 7) & ", con Banco " & MSFlexGrid1.TextMatrix(i, 3) _
                           & " y fecha vencimiento " & MSFlexGrid1.TextMatrix(i, 8) & "."
            Call Inserta_Vitacora_Finanza(CStr(MSFlexGrid1.TextMatrix(i, 1)), CStr(MSFlexGrid1.TextMatrix(i, 1)), CStr(accion), CStr(accion_detalle), 0, 0)
         End If
    Next i
                
    'Insertar log
   

    'MsgBox "Carga fue realizada con exito. Se han insertado " & contador & " cheques, con un monto de " & monto, vbInformation
            
            
    ApExcel.Visible = True
    'ApExcel.Range("a1:x1").Borders.color = RGB(255, 0, 0)
    Set ApExcel = Nothing
End Sub

Private Sub Command5_Click()
    Dim var_sql As String
    Dim conecta As Boolean
    Dim maximo_mes As Integer
    Dim dia As Integer, mes As Integer, agno As Integer
    Dim mes_palabra As String
   
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    If val(Text1.Text) = 0 Or val(Text2.Text) = 0 Then
        MsgBox "Debe seleccionar antes el rango de rendiciones", vbInformation
        Exit Sub
    End If
    
    
    Frame2.Visible = True
    
'            & " ON CONCAT(cur.num_gra,cur.let_cur,cur.des_ens) = CONCAT(asi.grado,asi.letra,asi.nivel)"
                
    If cb_encargado_r.Text = "" Then
    var_sql = "SELECT run_tit as 'Rut Deudor',nom_tit as 'Nombre Deudor',banco as BANCO,numero as '# Cheque',verificacion as VERIFICACION,banco_plaza as 'Banco y Plaza'" _
            & ",cta_cte AS 'Cuenta Cte.',fec_venc AS Vencimiento, concat('$ ',monto) as 'Monto Docto.','" & cb_factoring_r.Text & "' AS FACTORING " _
            & " FROM fnza_captura_cheques" _
            & " WHERE num_rendicion >= " & Text1.Text & " and num_rendicion <= " & Text2.Text
    Else
    var_sql = "SELECT run_tit as 'Rut Deudor',nom_tit as 'Nombre Deudor',banco as BANCO,numero as '# Cheque',verificacion as VERIFICACION,banco_plaza as 'Banco y Plaza'" _
            & ",cta_cte AS 'Cuenta Cte.',fec_venc AS Vencimiento, concat('$ ',monto) as 'Monto Docto.','" & cb_factoring_r.Text & "' AS FACTORING " _
            & " FROM fnza_captura_cheques" _
            & " WHERE num_rendicion >= " & Text1.Text & " and num_rendicion <= " & Text2.Text _
            & " and usuario_ingreso = '" & cb_encargado_r.Text & "'"
    End If
                
            '' " AND fec_ingreso >= '2015-05-05 00:00:00' AND fec_ingreso <= '2015-06-05 23:59:59'"
                
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        Call Rec2Grid(objRS, MSFlexGrid1, True)
       ' msflex_alumnos.ColSel = 5
        var_sql = "DROP TABLE IF EXISTS temp_cheques_capturados;"
        conn.Execute var_sql
        If cb_encargado_r.Text = "" Then
        var_sql = "create table temp_cheques_capturados type = MyISAM select *" _
            & " FROM fnza_captura_cheques" _
            & " WHERE num_rendicion >= " & Text1.Text & " and num_rendicion <= " & Text2.Text
        conn.Execute var_sql
        Else
        var_sql = "create table temp_cheques_capturados type = MyISAM SELECT *" _
            & " FROM fnza_captura_cheques" _
            & " WHERE num_rendicion >= " & Text1.Text & " and num_rendicion <= " & Text2.Text _
            & " and usuario_ingreso = '" & cb_encargado_r.Text & "'"
        conn.Execute var_sql
        End If
    Else
       MsgBox "No se han ingresado cheques en el rango seleccionado", vbInformation
    End If
    objRS.Close
    MSFlexGrid1.Refresh
    
    Frame2.Visible = False
End Sub

Private Sub Form_Load()
    DTP_inicio.Value = Date
    DTP_hasta.Value = Date
    
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    var_sql = "SELECT cod_fac,factoring as factoring FROM fnza_factoring"
    objRS.Open var_sql, conn
    cb_factoring.Clear
    While Not objRS.EOF
        cb_factoring.Tag = objRS("cod_fac")
        cb_factoring.AddItem objRS("factoring")
        cb_factoring_r.Tag = objRS("cod_fac")
        cb_factoring_r.AddItem objRS("factoring")
        objRS.MoveNext
    Wend
    objRS.Close
    
    var_sql = "SELECT DISTINCT usuario_ingreso FROM fnza_cheques_recibidos WHERE usuario_ingreso <> ''"
    objRS.Open var_sql, conn
    cb_encargado.Clear
    cb_encargado.AddItem ""
    cb_encargado_r.AddItem ""
    While Not objRS.EOF
        cb_encargado.AddItem objRS("usuario_ingreso")
        cb_encargado.Text = objRS("usuario_ingreso")
        cb_encargado_r.AddItem objRS("usuario_ingreso")
        cb_encargado_r.Text = objRS("usuario_ingreso")
        objRS.MoveNext
    Wend
    cb_encargado_r.Text = ""
    objRS.Close
End Sub

Private Sub Option1_Click()
    If Option1.Value = True Then
        Frame_fecha.Visible = True
        Frame_rendicion.Visible = False
    End If
End Sub

Private Sub Option2_Click()
       If Option2.Value = True Then
        Frame_fecha.Visible = False
        Frame_rendicion.Visible = True
    End If
End Sub

Private Sub Text1_Change()
    Text2.Text = Text1.Text
End Sub

Private Sub Text1_Click()
    Text2.Text = Text1.Text
End Sub
