frmPrestamoEmpresariales.vb 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. Public Class frmPrestamoEmpresariales
  2. Dim Prestamo As New PrestamoEmpresarialCE
  3. Dim PrestamoConsulta As New PrestamoEmpresarialDAO
  4. Dim oDAOGeneral As New DAOGeneral
  5. Dim Operaciones As New Operaciones
  6. Dim Base As Integer
  7. Dim FinCarga As Boolean = False
  8. Dim Estado As String = String.Empty
  9. Dim IndexCorte As Integer = 0
  10. Dim FechaCorte As Date
  11. Const IVA = 1.13
  12. Private Sub CargarTipoTasa()
  13. If cboTipoTasa.Items.Count = 0 Or cboTipoTasa.Items.Count = 1 Then
  14. Me.cboTipoTasa.DataSource = oDAOGeneral.ListaTipoTasa
  15. Me.cboTipoTasa.DisplayMember = "Descripcion"
  16. Me.cboTipoTasa.ValueMember = "Codigo"
  17. Me.cboTipoTasa.SelectedIndex = 0
  18. End If
  19. End Sub
  20. Private Sub CargarPeriodicidades()
  21. If cboPeriodicidad.Items.Count = 0 Or cboPeriodicidad.Items.Count = 1 Then
  22. Me.cboPeriodicidad.DataSource = oDAOGeneral.ListaPeriodicidad
  23. Me.cboPeriodicidad.DisplayMember = "Descripcion"
  24. Me.cboPeriodicidad.ValueMember = "Codigo"
  25. Me.cboPeriodicidad.SelectedIndex = 0
  26. End If
  27. End Sub
  28. Sub CargarBase()
  29. If cboBase.Items.Count = 0 Or cboBase.Items.Count = 1 Then
  30. Me.cboBase.DataSource = oDAOGeneral.ListaBase
  31. Me.cboBase.DisplayMember = "Descripcion"
  32. Me.cboBase.ValueMember = "Codigo"
  33. Me.cboBase.SelectedIndex = 0
  34. End If
  35. End Sub
  36. Private Sub frmPrestamoEmpresariales_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  37. dgvDetalles.Columns.Clear()
  38. Dias()
  39. AgregarCampos()
  40. CargarTipoTasa()
  41. CargarPeriodicidades()
  42. CargarBase()
  43. CargarDato()
  44. Dim Datos = CargarDetalles()
  45. RellenarDatos()
  46. If (Not Datos) Then
  47. Calculos(False, False)
  48. End If
  49. FinCarga = True
  50. ExisteInversion()
  51. ValidarExistencia()
  52. CargarTransladoNuevo()
  53. End Sub
  54. Function ExisteInversion()
  55. Dim Codigo As String = Variables.Codigo
  56. Dim TablaINV As String = "INV0"
  57. Dim TablaPINV As String = "PIN0"
  58. Dim General As New DAOGeneral
  59. Dim InvPro = Variables.InvPro
  60. If InvPro = "I" Then
  61. Dim INV0 As Boolean = General.ExisteTitulo(Codigo, TablaINV)
  62. If INV0 Then
  63. navNuevo.Visible = True
  64. Return True
  65. Else
  66. navNuevo.Visible = False
  67. Calculos(False, False)
  68. Return False
  69. End If
  70. End If
  71. If InvPro = "P" Then
  72. Dim PINV0 As Boolean = General.ExisteTitulo(Codigo, TablaPINV)
  73. If PINV0 Then
  74. navNuevo.Visible = True
  75. Return True
  76. Else
  77. navNuevo.Visible = False
  78. Calculos(False, False)
  79. Return False
  80. End If
  81. End If
  82. Return False
  83. End Function
  84. Function CanRegistros()
  85. Dim Tabla As String = String.Empty
  86. Tabla = "PEMP1"
  87. Dim Codigo = Variables.Codigo
  88. Dim Cantidad As Integer = oDAOGeneral.CantidadRegistros(Codigo, Tabla)
  89. Return Cantidad
  90. End Function
  91. Sub ValidarExistencia()
  92. Dim General As New DAOGeneral
  93. Dim Codigo As String = Variables.Codigo
  94. Dim Tabla As String = String.Empty
  95. Tabla = "PEMP0"
  96. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  97. If (Existe) Then
  98. navNuevo.Enabled = False
  99. TbDetalles.Enabled = True
  100. navModificar.Enabled = True
  101. navEliminar.Enabled = True
  102. Else
  103. navNuevo.Enabled = True
  104. TbDetalles.Enabled = True
  105. navModificar.Enabled = False
  106. navEliminar.Enabled = False
  107. End If
  108. Estado = String.Empty
  109. btnAccion.Text = "Aceptar"
  110. End Sub
  111. Function ExisteValidacion()
  112. Dim General As New DAOGeneral
  113. Dim Codigo As String = Variables.Codigo
  114. Dim Tabla As String = String.Empty
  115. Tabla = "PEMP0"
  116. Dim Existe As Boolean = General.ExisteTitulo(Codigo, Tabla)
  117. Return Existe
  118. End Function
  119. Sub Dias()
  120. Dim fecha1, fecha2
  121. fecha1 = dtpFechaOperacion.Value.ToString
  122. fecha2 = dtpFechaVencimiento.Value.ToString
  123. txtPlazoDias.Text = Prestamo.FechaDias(fecha1, fecha2)
  124. End Sub
  125. Private Sub dtpFechaOperacion_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaOperacion.ValueChanged
  126. Formato()
  127. Dias()
  128. If (FinCarga) Then
  129. Calculos(False, False)
  130. End If
  131. End Sub
  132. Private Sub dtpFechaVencimiento_ValueChanged(sender As Object, e As EventArgs) Handles dtpFechaVencimiento.ValueChanged
  133. Formato()
  134. Dias()
  135. If (FinCarga) Then
  136. Calculos(False, False)
  137. End If
  138. End Sub
  139. Sub AgregarCampos()
  140. Dim plazo, fechapago, fechacorte, Contador, SaldoPendiente, ingresarcomision, ingresarinteres, IVA, amortizacion, montorecibir As New DataGridViewTextBoxColumn
  141. plazo.Name = "Plazo (Desembolso)"
  142. fechacorte.Name = "Fecha de corte"
  143. fechapago.Name = "Fechas de Pago"
  144. ingresarcomision.Name = "Ingreso por Comision"
  145. ingresarinteres.Name = "Ingreso por Interes"
  146. IVA.Name = "IVA"
  147. amortizacion.Name = "Amortizacion"
  148. SaldoPendiente.Name = "Saldo Pendiente"
  149. montorecibir.Name = "Monto a Recibir"
  150. Contador.Name = "Correlativo"
  151. dgvDetalles.Columns.Add(Contador)
  152. dgvDetalles.Columns.Add(plazo)
  153. dgvDetalles.Columns.Add(fechacorte)
  154. dgvDetalles.Columns.Add(fechapago)
  155. dgvDetalles.Columns.Add(ingresarcomision)
  156. dgvDetalles.Columns.Add(ingresarinteres)
  157. dgvDetalles.Columns.Add(IVA)
  158. dgvDetalles.Columns.Add(amortizacion)
  159. dgvDetalles.Columns.Add(SaldoPendiente)
  160. dgvDetalles.Columns.Add(montorecibir)
  161. End Sub
  162. Sub Formato()
  163. If (String.IsNullOrEmpty(txtMonto.Text.ToString)) Then
  164. txtMonto.Text = 0
  165. txtMonto.Text = Format(txtMonto.Text, "0.0")
  166. End If
  167. If (String.IsNullOrEmpty(txtTasa.Text.ToString.TrimEnd("%"))) Then
  168. txtTasa.Text = 0
  169. txtTasa.Text = Format(txtTasa.Text, "0.0")
  170. End If
  171. If (String.IsNullOrEmpty(txtComisionDesembolso.Text.ToString.TrimEnd("%"))) Then
  172. txtComisionDesembolso.Text = 0
  173. txtComisionDesembolso.Text = Format(txtComisionDesembolso.Text, "0.0")
  174. End If
  175. If (txtTasa.Text.ToString.IndexOf("%") = -1) Then
  176. txtTasa.Text = txtTasa.Text.ToString + "%"
  177. End If
  178. If (txtComisionDesembolso.Text.ToString.IndexOf("%") = -1) Then
  179. txtComisionDesembolso.Text = txtComisionDesembolso.Text.ToString + "%"
  180. End If
  181. End Sub
  182. Sub Calculos(ByVal Modificar As Boolean, ByVal Corte As Boolean)
  183. Dim V_txtMonto = 0.0, V_txtTasa = 0.0, V_txtComisionDesembolso = 0.0
  184. If Not String.IsNullOrEmpty(txtMonto.Text.Trim("%")) Then
  185. V_txtMonto = txtMonto.Text.Trim("%")
  186. End If
  187. If Not String.IsNullOrEmpty(txtTasa.Text.ToString.Trim("%")) Then
  188. V_txtTasa = (CDec(txtTasa.Text.ToString.Trim("%")) / 100)
  189. End If
  190. If Not String.IsNullOrEmpty(txtComisionDesembolso.Text.ToString.TrimEnd("%")) Then
  191. V_txtComisionDesembolso = (CDec(txtComisionDesembolso.Text.ToString.TrimEnd("%")) / 100)
  192. End If
  193. If (cboTipoTasa.SelectedIndex = -1) Then
  194. cboTipoTasa.SelectedIndex = 0
  195. End If
  196. If (cboBase.SelectedIndex = -1) Then
  197. cboBase.SelectedIndex = 0
  198. End If
  199. If (cboPeriodicidad.SelectedIndex = -1) Then
  200. cboPeriodicidad.SelectedIndex = 0
  201. End If
  202. Dim FechaInicial = dtpFechaOperacion.Value
  203. Dim FechaFinal = dtpFechaOperacion.Value
  204. Dim FechaVencimiento = dtpFechaOperacion.Value
  205. Dim FechaVen = dtpFechaVencimiento.Value
  206. Dim FechaAux = dtpFechaOperacion.Value
  207. Dim Index = 0
  208. Dim Contador As Integer = 0
  209. Dim Borrar As Boolean = True
  210. Dim diccionario As New Dictionary(Of String, String)
  211. While (True)
  212. If (Not Modificar And Borrar) Then
  213. Dim Cantidad As Integer = dgvDetalles.Rows.Count
  214. If (Cantidad > 1) Then
  215. Dim CantidadReal = Cantidad - 2
  216. Dim i As Integer = 0
  217. While i <= CantidadReal
  218. Dim FechaCort = dgvDetalles.Rows(i).Cells("fecha de corte").Value
  219. If Not FechaCort Is DBNull.Value Then
  220. If Not String.IsNullOrEmpty(FechaCort) Then
  221. diccionario.Add(i, FechaCort)
  222. End If
  223. End If
  224. i += 1
  225. End While
  226. dgvDetalles.Rows.Clear()
  227. End If
  228. Borrar = False
  229. End If
  230. Dim Mes As Integer
  231. If (Index = 0) Then
  232. Mes = FechaFinal.Month
  233. Else
  234. FechaFinal = FechaFinal.AddDays(1)
  235. Mes = FechaFinal.Month
  236. End If
  237. Dim Salir As Boolean = False
  238. FechaAux = FechaFinal
  239. While (Mes = FechaFinal.Month)
  240. FechaFinal = Format(FechaFinal, "dd/MM/yyyy")
  241. FechaVen = Format(FechaVen, "dd/MM/yyyy")
  242. FechaFinal = FechaFinal.AddDays(1)
  243. If (FechaFinal > FechaVen) Then
  244. Salir = True
  245. Exit While
  246. End If
  247. End While
  248. If (Corte) Then
  249. If (Index >= IndexCorte) Then
  250. While FechaFinal.Date < FechaCorte.Date
  251. FechaCorte = FechaCorte.AddDays(-1)
  252. End While
  253. FechaFinal = FechaCorte
  254. Salir = True
  255. End If
  256. End If
  257. If (Index = 0) Then
  258. FechaInicial = dtpFechaOperacion.Value
  259. FechaFinal = dtpFechaOperacion.Value
  260. FechaAux = dtpFechaOperacion.Value
  261. ElseIf (Index = 1) Then
  262. Dim MesAño, Dia As Integer
  263. FechaAux = dtpFechaOperacion.Value
  264. MesAño = FechaAux.Month
  265. Dia = FechaAux.Day
  266. If (MesAño = 12 And Dia = 31) Then
  267. FechaInicial = FechaAux.AddDays(1)
  268. End If
  269. FechaFinal = FechaFinal.AddDays(-1)
  270. Else
  271. FechaInicial = FechaAux
  272. FechaFinal = FechaFinal.AddDays(-1)
  273. End If
  274. Dim FechaProv As Date = Date.Now.Date
  275. Dim CambioFecha As Boolean = False
  276. If Not (dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Is DBNull.Value Then
  277. If Not String.IsNullOrEmpty(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Then
  278. FechaProv = FechaFinal
  279. FechaFinal = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value
  280. CambioFecha = True
  281. End If
  282. End If
  283. Dim PlazoDatos = Plazo(Index, FechaFinal)
  284. Dim IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
  285. Dim IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaFinal, V_txtTasa, V_txtMonto)
  286. Dim CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
  287. Dim CalculoAmort = CalculoAmortizacion(Salir, V_txtMonto)
  288. Dim MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
  289. Dim SaldoPendi = SaldoPendiente(Index, CalculoAmort, V_txtMonto)
  290. If CambioFecha Then
  291. FechaFinal = FechaProv
  292. CambioFecha = False
  293. End If
  294. If Modificar Then
  295. Dim Fila = dgvDetalles.CurrentRow.Index
  296. Dim SalAnterior As Double = 0
  297. Dim SumaAmortizado = 0
  298. Dim CantidadFilas As Integer = dgvDetalles.Rows.Count - 2
  299. Dim Filas As Integer = dgvDetalles.Rows.Count - 2
  300. If (Index >= Fila) Then
  301. If (SaldoPendi > V_txtMonto) Then
  302. dgvDetalles.Rows(Index).Cells("Amortizacion").Value = 0
  303. SaldoPendi = 0
  304. Else
  305. For j As Integer = 0 To CantidadFilas - 1
  306. SumaAmortizado += dgvDetalles.Rows(j).Cells("Amortizacion").Value
  307. Next
  308. SaldoPendi = SaldoPendiente(Index, SumaAmortizado, V_txtMonto)
  309. If (SumaAmortizado > V_txtMonto) Then
  310. Dim PagoPendienteAnterior = dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value
  311. SaldoPendi = PagoPendienteAnterior
  312. dgvDetalles.Rows(Index).Cells("Amortizacion").Value = SaldoPendi
  313. End If
  314. If (Index = CantidadFilas) Then
  315. Dim PagoPendienteAnterior = dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value
  316. SaldoPendi = PagoPendienteAnterior
  317. dgvDetalles.Rows(Index).Cells("Amortizacion").Value = SaldoPendi
  318. End If
  319. End If
  320. If (Salir) Then
  321. End If
  322. Dim FechaProv2 As Date = Date.Now.Date
  323. Dim CambioFecha2 As Boolean = False
  324. If Not (dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Is DBNull.Value Then
  325. If Not String.IsNullOrEmpty(dgvDetalles.Rows(Index).Cells("Fecha de corte").Value) Then
  326. FechaProv2 = FechaFinal
  327. FechaFinal = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value
  328. CambioFecha2 = True
  329. End If
  330. End If
  331. PlazoDatos = Plazo(Index, FechaFinal)
  332. IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
  333. IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaFinal, V_txtTasa, SaldoPendi)
  334. CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
  335. MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
  336. If CambioFecha2 Then
  337. FechaFinal = FechaProv2
  338. CambioFecha2 = False
  339. End If
  340. dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value = PlazoDatos
  341. dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value = IngresoCom
  342. dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value = IngresoInt
  343. dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value = SaldoPendi
  344. dgvDetalles.Rows(Index).Cells("IVA").Value = CalculosIVA
  345. dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value = MontoRecibir
  346. End If
  347. Else
  348. Dim FechaCorte As String = String.Empty
  349. For Each Valor In diccionario
  350. If Valor.Key = Index Then
  351. FechaCorte = Valor.Value
  352. End If
  353. Next
  354. If String.IsNullOrEmpty(FechaCorte) Then
  355. dgvDetalles.Rows.Add(Index + 1, PlazoDatos, "", FechaFinal, IngresoCom, IngresoInt, CalculosIVA, CalculoAmort, SaldoPendi, MontoRecibir)
  356. Else
  357. dgvDetalles.Rows.Add(Index + 1, PlazoDatos, FechaCorte, FechaFinal, IngresoCom, IngresoInt, CalculosIVA, CalculoAmort, SaldoPendi, MontoRecibir)
  358. PlazoDatos = Plazo(Index, FechaCorte)
  359. IngresoCom = IngresoComision(Index, V_txtComisionDesembolso, V_txtMonto)
  360. IngresoInt = IngresoInteres(Index, PlazoDatos, FechaInicial, FechaCorte, V_txtTasa, SaldoPendi)
  361. CalculosIVA = CalculoIVA(Index, IngresoCom, IngresoInt)
  362. MontoRecibir = MontoARecibir(IngresoCom, IngresoInt, CalculosIVA, CalculoAmort)
  363. dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value = PlazoDatos
  364. dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value = IngresoCom
  365. dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value = IngresoInt
  366. dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value = SaldoPendi
  367. dgvDetalles.Rows(Index).Cells("IVA").Value = CalculosIVA
  368. dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value = MontoRecibir
  369. End If
  370. Contador += 1
  371. End If
  372. If (Salir) Then
  373. Exit While
  374. End If
  375. Index += 1
  376. Dim IndexFin = dgvDetalles.Rows.Count - 3
  377. If (Index = IndexFin) Then
  378. Salir = True
  379. End If
  380. End While
  381. End Sub
  382. Function SaldoPendiente(ByVal Index As Integer, ByVal Amortizado As Double, ByVal Monto As Double)
  383. Dim Saldo As Double = 0
  384. Dim FilaAnterior As Integer = Index - 1
  385. Dim SaldoAnterior As Double = 0
  386. Dim PagoPendienteAnterior As Double = 0
  387. Dim PagoPendiente As Double = 0
  388. Dim Amortizacion As Double = 0
  389. If (Index = 0) Then
  390. Saldo = Monto - Amortizado
  391. ElseIf (Index > 0) Then
  392. SaldoAnterior = Monto
  393. PagoPendienteAnterior = dgvDetalles.Rows(Index - 1).Cells("Saldo Pendiente").Value
  394. Amortizacion = dgvDetalles.Rows(Index - 1).Cells("Amortizacion").Value
  395. If (SaldoAnterior = Amortizado) Then
  396. Saldo = 0
  397. ElseIf (SaldoAnterior = Amortizado) Then
  398. Saldo = PagoPendienteAnterior
  399. ElseIf (SaldoAnterior < Amortizado) Then
  400. Saldo = 0
  401. ElseIf (PagoPendienteAnterior = Amortizacion) Then
  402. Saldo = 0
  403. Else
  404. Saldo = SaldoAnterior - Amortizado
  405. End If
  406. End If
  407. If (PagoPendienteAnterior = Amortizacion And Not Amortizacion = 0) Then
  408. Saldo = 0
  409. End If
  410. Return Saldo
  411. End Function
  412. Function Plazo(ByVal Index As Integer, ByVal fecha2 As Date)
  413. Dim fecha1 As Date
  414. Dim Valor
  415. Dim Anterior = Index - 1
  416. If (Index = 0) Then
  417. Valor = 0
  418. ElseIf (Index > 0) Then
  419. fecha1 = dgvDetalles.Rows(Anterior).Cells("Fechas de Pago").Value
  420. fecha1 = Format(fecha1, "yyyy/MM/dd")
  421. fecha2 = Format(fecha2, "yyyy/MM/dd")
  422. Valor = Prestamo.FechaDias(fecha1, fecha2)
  423. Else
  424. Valor = 0
  425. End If
  426. Return Valor
  427. End Function
  428. Function IngresoComision(ByVal Index As Integer, ByVal V_txtComisionDesembolso As Double, ByVal V_txtMonto As Double)
  429. Dim Valor
  430. If (Index = 0) Then
  431. If (Not String.IsNullOrEmpty(V_txtComisionDesembolso) And Not String.IsNullOrEmpty(V_txtMonto)) Then
  432. Valor = V_txtComisionDesembolso * V_txtMonto
  433. Else
  434. Valor = 0
  435. End If
  436. Else
  437. Valor = 0
  438. End If
  439. Return Valor
  440. End Function
  441. Function IngresoInteres(ByVal Index As Integer, ByVal plazo As Integer, ByVal FechaInicial As Date, ByVal FechaFinal As Date, ByVal V_txtTasa As Double, ByVal V_txtMonto As Double)
  442. If (Index = 0) Then
  443. Return 0
  444. Else
  445. Dim CambioDeFecha As Integer = Operaciones.CambioBase(FechaInicial, FechaFinal)
  446. Dim PrimeraFechaUltima = Operaciones.PrimeraFechaCambioBase(FechaInicial)
  447. Dim UltimaFechaPrimero = Operaciones.FinalFechaCambioBase(FechaFinal)
  448. Dim DiasPrimeraFecha = 0, DiasSegundaFecha = 0
  449. Dim Valor1 = 0.0, Valor2 = 0.0, Valor = 0.0
  450. If (Not CambioDeFecha = 0) Then
  451. If CambioDeFecha = 1 Then
  452. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  453. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  454. Valor1 = V_txtMonto * V_txtTasa * DiasPrimeraFecha / 366
  455. Valor2 = V_txtMonto * V_txtTasa * DiasSegundaFecha / 365
  456. ElseIf CambioDeFecha = 2 Then
  457. DiasPrimeraFecha = Operaciones.DiasDespuesCambioPrimeraFecha365(FechaInicial, PrimeraFechaUltima, CambioDeFecha)
  458. DiasSegundaFecha = Operaciones.DiasDespuesCambioPrimeraFecha366(UltimaFechaPrimero, FechaFinal, CambioDeFecha)
  459. Valor1 = V_txtMonto * V_txtTasa * DiasPrimeraFecha / 365
  460. Valor2 = V_txtMonto * V_txtTasa * DiasSegundaFecha / 366
  461. End If
  462. Valor = Valor1 + Valor2
  463. Else
  464. If (Operaciones.AñoBisiesto(FechaInicial) = 364) Then
  465. Valor = V_txtMonto * V_txtTasa * plazo / 365
  466. End If
  467. If (Operaciones.AñoBisiesto(FechaInicial) = 365) Then
  468. Valor = V_txtMonto * V_txtTasa * plazo / 366
  469. End If
  470. End If
  471. Return Valor
  472. End If
  473. End Function
  474. Function CalculoIVA(ByVal Index As Integer, ByVal IngresoCom As Double, ByVal IngresoInteres As Double)
  475. Dim Valor
  476. If Index = 0 Then
  477. If (Not String.IsNullOrEmpty(IngresoCom) And Not String.IsNullOrEmpty(IngresoInteres)) Then
  478. Valor = IngresoCom - (IngresoCom / (1.13))
  479. End If
  480. Else
  481. If (Not String.IsNullOrEmpty(IngresoCom) And Not String.IsNullOrEmpty(IngresoInteres)) Then
  482. Valor = (IngresoCom + IngresoInteres) * 0.13
  483. Else
  484. Valor = 0
  485. End If
  486. End If
  487. Return Valor
  488. End Function
  489. Function CalculoAmortizacion(ByVal Ultimo As Integer, ByVal V_txtMonto As Double)
  490. Dim Monto As Integer = 0
  491. If (Ultimo) Then
  492. Monto = V_txtMonto
  493. End If
  494. Return Monto
  495. End Function
  496. Function MontoARecibir(ByVal IngresoComision As Double, ByVal IngresoInteres As Double, ByVal CalculoIVA As Double, ByVal Amortizacion As Double)
  497. Dim Monto As Double = 0
  498. If Not String.IsNullOrEmpty(txtMonto.Text) Then
  499. Monto = txtMonto.Text
  500. End If
  501. Dim Valor As Double = 0.0
  502. Valor = IngresoComision + IngresoInteres + CalculoIVA + Amortizacion
  503. If Amortizacion > Monto Then
  504. Valor = 0
  505. End If
  506. Return Valor
  507. End Function
  508. Function Coleccion()
  509. Dim colec As New Collection
  510. Dim fechaoper, fechaven, tasa, periodicidad, base, tipotasa, comisiondesembolso, plazodias, monto
  511. monto = txtMonto.Text
  512. fechaoper = dtpFechaOperacion.Value
  513. fechaven = dtpFechaVencimiento.Value
  514. tasa = CDec(txtTasa.Text.ToString.Trim("%")) / 100
  515. periodicidad = cboPeriodicidad.SelectedValue
  516. base = Me.Base
  517. tipotasa = cboTipoTasa.SelectedValue
  518. comisiondesembolso = txtComisionDesembolso.Text.ToString.Trim("%") / 100
  519. plazodias = txtPlazoDias.Text
  520. colec.Add(monto)
  521. colec.Add(fechaoper)
  522. colec.Add(fechaven)
  523. colec.Add(tasa)
  524. colec.Add(periodicidad)
  525. colec.Add(base)
  526. colec.Add(tipotasa)
  527. colec.Add(comisiondesembolso)
  528. colec.Add(plazodias)
  529. Return colec
  530. End Function
  531. Sub RellenarDatos()
  532. If (String.IsNullOrEmpty(txtMonto.Text.ToString)) Then
  533. txtMonto.Text = "0.0"
  534. End If
  535. If (String.IsNullOrEmpty(txtTasa.Text.TrimEnd("%").ToString)) Then
  536. txtTasa.Text = "0.0%"
  537. End If
  538. If (cboTipoTasa.SelectedIndex = -1) Then
  539. cboTipoTasa.SelectedIndex = 0
  540. End If
  541. If (cboBase.SelectedIndex = -1) Then
  542. cboBase.SelectedIndex = 0
  543. End If
  544. If (cboPeriodicidad.SelectedIndex = -1) Then
  545. cboPeriodicidad.SelectedIndex = 0
  546. End If
  547. If (String.IsNullOrEmpty(txtComisionDesembolso.Text.Trim("%").ToString)) Then
  548. txtComisionDesembolso.Text = "0.0%"
  549. End If
  550. If (String.IsNullOrEmpty(txtPlazoDias.Text.ToString)) Then
  551. txtPlazoDias.Text = "0.0"
  552. End If
  553. End Sub
  554. Function ColeccionDetalle(ByVal Index As Integer)
  555. Dim Coleccion As New Collection
  556. Dim plazo, fecha, fechacorte, ingresocomision, ingresointeres, IVA, amortizacion, montorecibir, saldopendiente, correlativo
  557. correlativo = dgvDetalles.Rows(Index).Cells("Correlativo").Value
  558. plazo = dgvDetalles.Rows(Index).Cells("Plazo (Desembolso)").Value
  559. fecha = dgvDetalles.Rows(Index).Cells("Fechas de Pago").Value
  560. ingresocomision = dgvDetalles.Rows(Index).Cells("Ingreso por Comision").Value
  561. ingresointeres = dgvDetalles.Rows(Index).Cells("Ingreso por Interes").Value
  562. IVA = dgvDetalles.Rows(Index).Cells("IVA").Value
  563. amortizacion = dgvDetalles.Rows(Index).Cells("Amortizacion").Value
  564. saldopendiente = dgvDetalles.Rows(Index).Cells("Saldo Pendiente").Value
  565. montorecibir = dgvDetalles.Rows(Index).Cells("Monto a Recibir").Value
  566. fechacorte = dgvDetalles.Rows(Index).Cells("Fecha de corte").Value
  567. Coleccion.Add(correlativo)
  568. Coleccion.Add(plazo)
  569. Coleccion.Add(fecha)
  570. Coleccion.Add(ingresocomision)
  571. Coleccion.Add(ingresointeres)
  572. Coleccion.Add(IVA)
  573. Coleccion.Add(amortizacion)
  574. Coleccion.Add(saldopendiente)
  575. Coleccion.Add(montorecibir)
  576. Coleccion.Add(fechacorte)
  577. Return Coleccion
  578. End Function
  579. Sub NuevoDetalle(ByVal AgregarModificar As Boolean, ByVal Cantidad As Integer)
  580. Dim i As Integer = 0
  581. Dim Index = dgvDetalles.Rows.Count - 2
  582. i = Cantidad
  583. While i <= Index
  584. Dim coleccion = ColeccionDetalle(i)
  585. If PrestamoConsulta.NuevoDetalle(coleccion, Codigo) Is Nothing Then
  586. Exit Sub
  587. End If
  588. i += 1
  589. End While
  590. MsgBox("Registro de ingresos actualizados")
  591. End Sub
  592. Function ColeccionCampos()
  593. Dim i As Integer = 0
  594. Dim diccionario As New Dictionary(Of String, Collection)
  595. Dim Index = dgvDetalles.Rows.Count - 2
  596. While i <= Index
  597. Dim coleccion = ColeccionDetalle(i)
  598. diccionario.Add(i, coleccion)
  599. i += 1
  600. End While
  601. Return diccionario
  602. End Function
  603. Sub EliminarDetalles(ByVal CantidadRegistros As Integer, ByVal Cantidad As Integer)
  604. Dim i As Integer = 0
  605. Dim Index = CantidadRegistros + 1
  606. i = Cantidad
  607. While i >= Index
  608. If PrestamoConsulta.EliminarDetalles(Index, Codigo) Is Nothing Then
  609. Exit Sub
  610. End If
  611. Index += 1
  612. End While
  613. End Sub
  614. Function ColeccionNuevo(ByVal codigo As String)
  615. Dim i As Integer = 0
  616. Dim diccionario As New Dictionary(Of String, Collection)
  617. Dim Index = dgvDetalles.Rows.Count - 2
  618. While i <= Index
  619. Dim coleccion = ColeccionDetalle(i)
  620. diccionario.Add(i, coleccion)
  621. i += 1
  622. End While
  623. Return diccionario
  624. End Function
  625. Function ColeccionEliminar(ByVal codigo As String)
  626. Dim CantidadRegistros As Integer = dgvDetalles.Rows.Count - 1
  627. Dim Cantidad As Integer = CanRegistros()
  628. Dim i As Integer = 0
  629. Dim diccionario As New Dictionary(Of Integer, String)
  630. Dim Index = CantidadRegistros + 1
  631. i = Cantidad
  632. While i >= Index
  633. diccionario.Add(Index, codigo)
  634. Index += 1
  635. End While
  636. Return diccionario
  637. End Function
  638. Sub EliminarDatos(ByVal codigo As String)
  639. PrestamoConsulta.Eliminar(codigo)
  640. End Sub
  641. Private Sub dgvDetalles_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellContentClick
  642. End Sub
  643. Private Sub dgvDetalles_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvDetalles.CellEndEdit
  644. Calculos(True, False)
  645. End Sub
  646. Private Sub cboBase_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboBase.SelectedIndexChanged
  647. Formato()
  648. If (cboBase.SelectedIndex = 0) Then
  649. Base = 360
  650. Else
  651. Base = 365
  652. End If
  653. End Sub
  654. Sub CargarDato()
  655. Dim codigo As String = Variables.Codigo
  656. Dim Retorno = PrestamoConsulta.CargarDato(codigo)
  657. Dim coleccion As New Collection
  658. If (TypeOf Retorno Is Boolean) Then
  659. Exit Sub
  660. Else
  661. coleccion = PrestamoConsulta.CargarDato(codigo)
  662. End If
  663. Dim Index As Integer = 0
  664. If (coleccion(6).ToString = "360") Then
  665. Index = 0
  666. Else
  667. Index = 1
  668. End If
  669. txtMonto.Text = coleccion(1)
  670. dtpFechaOperacion.Value = coleccion(2)
  671. dtpFechaVencimiento.Value = coleccion(3)
  672. txtTasa.Text = (CDec(coleccion(4).ToString.Trim("%")) * 100).ToString + "%"
  673. cboPeriodicidad.SelectedValue = coleccion(5)
  674. cboBase.SelectedIndex = Index
  675. cboTipoTasa.SelectedValue = coleccion(7)
  676. txtComisionDesembolso.Text = (CDec(coleccion(8).Trim("%")) * 100).ToString + "%"
  677. txtPlazoDias.Text = coleccion(9)
  678. End Sub
  679. Function CargarDetalles()
  680. Dim codigo As String = Variables.Codigo
  681. Dim dr = PrestamoConsulta.CargarDetalles(codigo)
  682. Dim Datos As Boolean = False
  683. If (Not dr Is Nothing) Then
  684. Dim Iterador As Integer = 0
  685. Dim ConvertirString As String
  686. While dr.Read
  687. ConvertirString = Format(dr("fechapago"), "dd/MM/yyyy")
  688. dgvDetalles.Rows.Add(dr("correlativo"), dr("plazo"), dr("fechacorte"), ConvertirString, dr("ingresarcomision"), dr("ingresarinteres"), dr("IVA"), dr("amortizacion"), dr("saldopendiente"), dr("montorecibir"))
  689. End While
  690. Datos = True
  691. End If
  692. Return Datos
  693. End Function
  694. Private Sub btnAccion_Click(sender As Object, e As EventArgs) Handles btnAccion.Click
  695. Dim codigo As String = Variables.Codigo
  696. Dim Colec As Collection = Coleccion()
  697. Dim Diccionario As Dictionary(Of Integer, String) = ColeccionEliminar(codigo)
  698. Dim Diccionario2 As Dictionary(Of String, Collection) = ColeccionNuevo(codigo)
  699. If (Estado = "N") Then
  700. PrestamoConsulta.ProcesoDatos(Colec, codigo, Diccionario2, "Nuevo")
  701. ElseIf Not ExisteValidacion() Then
  702. Variables.ColeccionPEMP = Coleccion()
  703. Variables.ColeccionPEMPDi = ColeccionCampos()
  704. Me.Close()
  705. End If
  706. If (Estado = "M") Then
  707. PrestamoConsulta.ProcesoDatos(Colec, codigo, Diccionario2, "Modificar")
  708. End If
  709. If (Estado = "B") Then
  710. EliminarDatos(codigo)
  711. End If
  712. ValidarExistencia()
  713. End Sub
  714. Private Sub navModificar_Click(sender As Object, e As EventArgs) Handles navModificar.Click
  715. Estado = "M"
  716. btnAccion.Text = "Modificar"
  717. End Sub
  718. Private Sub navNuevo_Click(sender As Object, e As EventArgs) Handles navNuevo.Click
  719. Estado = "N"
  720. btnAccion.Text = "Agregar"
  721. ' btnagregar.Text = "Agregar"
  722. End Sub
  723. Private Sub navEliminar_Click(sender As Object, e As EventArgs) Handles navEliminar.Click
  724. Estado = "B"
  725. btnAccion.Text = "Eliminar"
  726. End Sub
  727. Private Sub btnagregar_Click(sender As Object, e As EventArgs)
  728. End Sub
  729. Private Sub txtMonto_TextChanged(sender As Object, e As EventArgs) Handles txtMonto.TextChanged
  730. If (FinCarga) Then
  731. Calculos(False, False)
  732. End If
  733. End Sub
  734. Private Sub txtTasa_TextChanged(sender As Object, e As EventArgs) Handles txtTasa.TextChanged
  735. If (FinCarga) Then
  736. Calculos(False, False)
  737. End If
  738. End Sub
  739. Private Sub txtComisionDesembolso_TextChanged(sender As Object, e As EventArgs) Handles txtComisionDesembolso.TextChanged
  740. If (FinCarga) Then
  741. Calculos(False, False)
  742. End If
  743. End Sub
  744. Private Sub txtMonto_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMonto.KeyPress
  745. If String.IsNullOrEmpty(txtMonto.Text) Then
  746. If e.KeyChar = "." Then
  747. txtMonto.Text = "0"
  748. Exit Sub
  749. End If
  750. End If
  751. If (Not txtMonto.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  752. Operaciones.ValidarEntrada(sender, e, True)
  753. Else
  754. Operaciones.ValidarEntrada(sender, e, False)
  755. End If
  756. End Sub
  757. Private Sub txtTasa_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTasa.KeyPress
  758. If String.IsNullOrEmpty(txtTasa.Text) Then
  759. If e.KeyChar = "." Then
  760. txtTasa.Text = "0"
  761. Exit Sub
  762. End If
  763. End If
  764. If (Not txtTasa.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  765. Operaciones.ValidarEntrada(sender, e, True)
  766. Else
  767. Operaciones.ValidarEntrada(sender, e, False)
  768. End If
  769. End Sub
  770. Private Sub txtComisionDesembolso_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtComisionDesembolso.KeyPress
  771. If String.IsNullOrEmpty(txtComisionDesembolso.Text) Then
  772. If e.KeyChar = "." Then
  773. txtComisionDesembolso.Text = "0"
  774. Exit Sub
  775. End If
  776. End If
  777. If (Not txtComisionDesembolso.Text.ToString.IndexOf(".") = -1 And e.KeyChar = ".") Then
  778. Operaciones.ValidarEntrada(sender, e, True)
  779. Else
  780. Operaciones.ValidarEntrada(sender, e, False)
  781. End If
  782. End Sub
  783. Private Sub btnCancelar_Click(sender As Object, e As EventArgs)
  784. Cancelar()
  785. End Sub
  786. Sub Cancelar()
  787. End Sub
  788. Private Sub txtMonto_Leave(sender As Object, e As EventArgs) Handles txtMonto.Leave
  789. Formato()
  790. End Sub
  791. Private Sub txtTasa_Leave(sender As Object, e As EventArgs) Handles txtTasa.Leave
  792. Formato()
  793. End Sub
  794. Private Sub cboTipoTasa_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboTipoTasa.SelectedIndexChanged
  795. Formato()
  796. End Sub
  797. Private Sub cboPeriodicidad_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPeriodicidad.SelectedIndexChanged
  798. Formato()
  799. End Sub
  800. Private Sub txtComisionDesembolso_Leave(sender As Object, e As EventArgs) Handles txtComisionDesembolso.Leave
  801. Formato()
  802. End Sub
  803. Private Sub txtPlazoDias_Leave(sender As Object, e As EventArgs) Handles txtPlazoDias.Leave
  804. Formato()
  805. End Sub
  806. Private Sub txtMonto_KeyUp(sender As Object, e As KeyEventArgs) Handles txtMonto.KeyUp
  807. If txtMonto.Text = "." Then
  808. txtMonto.Text = ".0"
  809. End If
  810. End Sub
  811. Private Sub txtTasa_KeyUp(sender As Object, e As KeyEventArgs) Handles txtTasa.KeyUp
  812. If txtTasa.Text = "." Then
  813. txtTasa.Text = ".0"
  814. End If
  815. End Sub
  816. Private Sub txtComisionDesembolso_KeyUp(sender As Object, e As KeyEventArgs) Handles txtComisionDesembolso.KeyUp
  817. If txtComisionDesembolso.Text = "." Then
  818. txtComisionDesembolso.Text = ".0"
  819. End If
  820. End Sub
  821. Sub CargarTransladoNuevo()
  822. Dim Existe As Boolean = ExisteInversion()
  823. If Not RetCodigoInversionExiste And Not Existe Then
  824. txtMonto.Text = Variables.RetMonto
  825. txtTasa.Text = Variables.RetRendimiento
  826. End If
  827. End Sub
  828. End Class