1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
| Public Function VUE_ETAT(vardaterappro As Date, VarSociete As String, VarCompte As String, VarStatut As String, FichierDest As String) As ADODB.Recordset
On Error GoTo vue_etat_err
'Déclaration des variables
Dim strSqlbnk, strSqlacc As String
Dim daterappro As String
Dim VarTempSociete As String
Dim VarTempComptes As String
Dim VarTempStatut As String
Dim sWhere As String
Dim flow_bnk, flow_acc As New ADODB.Recordset
Dim tmpligne As String
Dim Deb As Boolean
Dim NbrBank As Integer
Dim NbrCompta As Integer
Dim ValTemp1, ValTemp2, ValTemp3 As String
Dim ValTemp4, ValTemp5, ValTemp6 As String
Dim ggg As Integer
daterappro = Format(vardaterappro, "YYYY-MM-DD")
VarTempSociete = VarSociete
VarTempComptes = VarCompte
VarTempStatut = VarStatut
ggg = FreeFile
' Close #ggg
'selection des ecritures rapprochées de la vue bancaires
'strSqlbnk = "SELECT v.*, ss.SOLDE_CTRV, ss.SOLDE_TRN FROM V_ETAT_BNK v,(select s.acc_code,(s.bank_bal_amount-sum(r.bank_cur_amount)) as SOLDE_CTRV, " & _
' " (s.bank_bal_amount-sum(r.trn_amount)) as SOLDE_TRN " & _
' " from rec_bank r, spe_rap_accounts s " & _
' " Where s.acc_code = r.acc_code " & _
' " and (r.book_date> {d '2004-01-19'}) " & _
' " group by s.acc_code, s.bank_bal_amount) ss " & _
' " Where v.acc_code = ss.acc_code"
strSqlbnk = "SELECT v.*, ss.soldeBancaire as SOLDE_CTRV, ss.soldeBancaire SOLDE_TRN FROM V_ETAT_BNK v,(" & _
SoldeBancaire(daterappro) & ") ss " & _
" Where v.acc_code = ss.acc_code " & _
" and (v.REC_DATE IS NULL OR v.REC_DATE = {d '" & daterappro & "'}) AND "
If VarTempStatut <> "" Then sWhere = sWhere & "v.STATUT in ('" & VarTempStatut & "' ) AND "
If VarTempSociete <> "" Then sWhere = sWhere & "v.CMP_CODE in ('" & VarTempSociete & "') AND "
If VarTempComptes <> "" Then sWhere = sWhere & "v.ACC_CODE in ('" & VarTempComptes & "') AND "
strSqlbnk = strSqlbnk & Left(sWhere, Len(sWhere) - 4)
Debug.Print strSqlbnk
'selection des ecritures rapprochées de la vue comptable
'strSqlacc = " SELECT v.*, ss.SOLDE_CTRV, ss.SOLDE_TRN FROM V_ETAT_ACC v,(select s.acc_code,(s.abk_bal_amount-sum(r.abk_cur_amount)) as SOLDE_CTRV," & _
' "(s.abk_bal_amount-sum(r.trn_amount)) as SOLDE_TRN " & _
' " from rec_acc r, spe_rap_accounts s " & _
' " Where s.acc_code = R.acc_code " & _
' " and (r.book_date> {d '2004-01-19'})" & _
' " group by s.acc_code, s.abk_bal_amount) ss " & _
' " Where v.acc_code = ss.acc_code"
strSqlacc = " SELECT v.*, ss.soldeComptable as SOLDE_CTRV, ss.soldeComptable SOLDE_TRN FROM V_ETAT_ACC v,(" & _
SoldeComptable(daterappro) & ") ss " & _
" Where v.acc_code = ss.acc_code " & _
" and (v.REC_DATE IS NULL OR v.REC_DATE = {d '" & daterappro & "'}) AND "
If VarTempStatut <> "" Then sWhere = sWhere & "v.STATUT in ('" & VarTempStatut & "') AND "
If VarTempSociete <> "" Then sWhere = sWhere & "v.CMP_CODE in ('" & VarTempSociete & "') AND "
If VarTempComptes <> "" Then sWhere = sWhere & "v.ACC_CODE in ('" & VarTempComptes & "') AND "
strSqlacc = strSqlacc & Left(sWhere, Len(sWhere) - 4)
Debug.Print strSqlacc
'ouverture de la connexion
Set Conn = New ADODB.Connection
Conn.ConnectionString = RechercheConnectionString
Conn.Open
ggg = FreeFile
Open FichierDest For Append As #ggg
Set flow_bnk = New ADODB.Recordset
Set flow_acc = New ADODB.Recordset
flow_bnk.Open strSqlbnk, Conn, adOpenKeyset, adLockReadOnly, adCmdText
Deb = True
flow_acc.Open strSqlacc, Conn, adOpenKeyset, adLockReadOnly, adCmdText
If (flow_acc.EOF) Then
NbrCompta = 0
Else
flow_acc.MoveLast
NbrCompta = flow_acc.RecordCount
flow_acc.MoveFirst
End If
If (flow_bnk.EOF) Then
NbrBank = 0
Else
flow_bnk.MoveLast
NbrBank = flow_bnk.RecordCount
flow_bnk.MoveFirst
End If
ValTemp1 = ""
ValTemp2 = ""
ValTemp3 = ""
ValTemp4 = ""
ValTemp5 = ""
ValTemp6 = ""
Do While Not flow_acc.EOF
If (Deb) Then
tmpligne = ""
'ecritures des entêtes de colonnes dans le fichier
For i = 0 To flow_acc.Fields.Count - 1
tmpligne = tmpligne & flow_acc.Fields(i).Name & ";"
Next i
For i = 0 To flow_bnk.Fields.Count - 1
tmpligne = tmpligne & flow_bnk.Fields(i).Name & ";"
Next i
Print #ggg, tmpligne
'initialisation des variables comptables
ValTemp1 = Trim(flow_acc.Fields("STATUT").Value)
ValTemp2 = Trim(flow_acc.Fields("ACC_CODE").Value)
ValTemp3 = Trim(flow_acc.Fields("CMP_CODE").Value)
'initialisation des variables bancaires
If (flow_bnk.EOF) Then
ValTemp4 = ""
ValTemp5 = ""
ValTemp6 = ""
Else
ValTemp4 = Trim(flow_bnk.Fields("STATUT").Value)
ValTemp5 = Trim(flow_bnk.Fields("ACC_CODE").Value)
ValTemp6 = Trim(flow_bnk.Fields("CMP_CODE").Value)
End If
End If
tmpligne = ""
'-----------------------------------------------------------------------------------
' Lecture des écritures comptables
'-----------------------------------------------------------------------------------
For i = 0 To flow_acc.Fields.Count - 1
If (Trim(flow_acc.Fields(i).Name) = "ACCOUNT_ID") Then
tmpligne = tmpligne & "'" & flow_acc.Fields(i).Value & ";"
ElseIf (Trim(flow_acc.Fields(i).Name) = "SOLDE_CTRV" Or Trim(flow_acc.Fields(i).Name) = "SOLDE_TRN") Then
If (Deb) Then
tmpligne = tmpligne & flow_acc.Fields(i).Value & ";"
ValTemp1 = Trim(flow_acc.Fields("STATUT").Value)
ValTemp2 = Trim(flow_acc.Fields("ACC_CODE").Value)
ValTemp3 = Trim(flow_acc.Fields("CMP_CODE").Value)
Else
If (ValTemp2 = Trim(flow_acc.Fields("ACC_CODE").Value) And ValTemp3 = Trim(flow_acc.Fields("CMP_CODE").Value)) Then
tmpligne = tmpligne & "0;"
Else
tmpligne = tmpligne & flow_acc.Fields(i).Value & ";"
If Trim(flow_acc.Fields(i).Name) = "SOLDE_TRN" Then
ValTemp1 = Trim(flow_acc.Fields("STATUT").Value)
ValTemp2 = Trim(flow_acc.Fields("ACC_CODE").Value)
ValTemp3 = Trim(flow_acc.Fields("CMP_CODE").Value)
End If
End If
End If
Else
tmpligne = tmpligne & flow_acc.Fields(i).Value & ";"
End If
Next i
Debug.Print tmpligne
'------------------------------------------------------------------------------------
'Lecture des ecritures bancaires
'------------------------------------------------------------------------------------
If (Not flow_bnk.EOF) Then
For i = 0 To flow_bnk.Fields.Count - 1
If (Trim(flow_bnk.Fields(i).Name) = "ACCOUNT_ID") Then
tmpligne = tmpligne & "'" & flow_bnk.Fields(i).Value & ";"
ElseIf (Trim(flow_bnk.Fields(i).Name) = "SOLDE_CTRV" Or Trim(flow_bnk.Fields(i).Name) = "SOLDE_TRN") Then
If (Deb) Then
tmpligne = tmpligne & flow_bnk.Fields(i).Value & ";"
ValTemp4 = Trim(flow_bnk.Fields("STATUT").Value)
ValTemp5 = Trim(flow_bnk.Fields("ACC_CODE").Value)
ValTemp6 = Trim(flow_bnk.Fields("CMP_CODE").Value)
Else
If (ValTemp5 = Trim(flow_bnk.Fields("ACC_CODE").Value) And ValTemp6 = Trim(flow_bnk.Fields("CMP_CODE").Value)) Then
tmpligne = tmpligne & "0;"
Else
tmpligne = tmpligne & flow_bnk.Fields(i).Value & ";"
If Trim(flow_acc.Fields(i).Name) = "SOLDE_TRN" Then
ValTemp4 = Trim(flow_bnk.Fields("STATUT").Value)
ValTemp5 = Trim(flow_bnk.Fields("ACC_CODE").Value)
ValTemp6 = Trim(flow_bnk.Fields("CMP_CODE").Value)
End If
End If
End If
Else
tmpligne = tmpligne & flow_bnk.Fields(i).Value & ";"
End If
Next i
flow_bnk.MoveNext
End If
Debug.Print tmpligne
Print #ggg, tmpligne
If (Deb) Then
Deb = False
End If
flow_acc.MoveNext
Loop |
Partager