244 lines
10 KiB
VB.net
244 lines
10 KiB
VB.net
Imports Extensiones
|
|
Imports System.Data
|
|
Imports System.Drawing
|
|
Imports Microsoft.Reporting.WebForms
|
|
Imports System.IO
|
|
Imports System.Xml
|
|
|
|
Partial Class Nomina_ReportePTU
|
|
Inherits ClsPaginas
|
|
#Region "Propiedades"
|
|
Dim dtPeriodos As DataTable
|
|
Private Property DTUtilidades As DataTable
|
|
Get
|
|
Return CType(ViewState("DTUtilidades"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DTUtilidades") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property utilimporte As Double
|
|
Get
|
|
Return ViewState("utilimporte").ToString().ToDouble()
|
|
End Get
|
|
Set(value As Double)
|
|
ViewState("utilimporte") = value
|
|
End Set
|
|
End Property
|
|
Private Property utilimporteAnt As Double
|
|
Get
|
|
Return ViewState("utilimporteAnt").ToString().ToDouble()
|
|
End Get
|
|
Set(value As Double)
|
|
ViewState("utilimporteAnt") = value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
|
|
If Not IsPostBack Then
|
|
Dim objnom As New ClsNominas()
|
|
objnom.GetEjercicios(UsuarioActual.CveEmpresa)
|
|
DdlEjercicios.DataSource = objnom.DtResultados
|
|
'DdlTipoPeriodo.DataSource = GlobalDTTipoPeriodo.FiltraParametros("Estatus = 'Activo'")
|
|
'DdlTipoPeriodo.DataBind()
|
|
'DdlTipoPeriodo.SelectedValueExist("6")
|
|
'DdlTipoPeriodo.Enabled = False
|
|
|
|
objnom.Dispose()
|
|
DdlEjercicios.DataBind()
|
|
If (DdlEjercicios.Items.Count > 0) Then
|
|
DdlEjercicios.SelectedIndex = 0
|
|
DdlEjercicios_SelectedIndexChanged(Nothing, Nothing)
|
|
End If
|
|
End If
|
|
|
|
End Sub
|
|
Protected Sub BtnCalcular_Click(sender As Object, e As EventArgs)
|
|
Dim ejercicio As Integer = DdlEjercicios.SelectedValue.ToEntero()
|
|
utilimporte = TxtPA_Nimporte.Text.ToDouble()
|
|
utilimporteAnt = TxtPA_NimporteA.Text.ToDouble()
|
|
|
|
Using objnom As New ClsNominas()
|
|
objnom.GetCalculoUtilidades(ejercicio, UsuarioActual.CveEmpresa, utilimporte, utilimporteAnt)
|
|
DTUtilidades = objnom.DtResultados
|
|
End Using
|
|
|
|
cargaEjercicio(DTUtilidades)
|
|
LnkAutorizarModal.Visible = True
|
|
upDatosPA_N.Update()
|
|
End Sub
|
|
|
|
Private Sub CargaPeriodos()
|
|
Dim ObjPeriodos As New ClsNominas()
|
|
If ObjPeriodos.GetPeriodos(-1, UsuarioActual.CveEmpresa, DdlEjercicios.SelectedValue.ToEntero(), -1, -1) Then
|
|
dtPeriodos = ObjPeriodos.DtResultados.FiltraParametros("Estatus IN (0,1)")
|
|
End If
|
|
ObjPeriodos.Dispose()
|
|
Dim listaCveTipoPeriodo As New StringBuilder("-1")
|
|
Dim dt As DataTable = DTUtilidades.FiltraParametros("", "", {"CveTipoPeriodo"})
|
|
For Each rowp As DataRow In dt.Rows
|
|
listaCveTipoPeriodo.Append(",")
|
|
listaCveTipoPeriodo.Append(rowp("CveTipoPeriodo"))
|
|
Next
|
|
|
|
|
|
GVTipoPeriodo.DataSource = GlobalDTTipoPeriodo.FiltraParametros($"Estatus = 'Activo' AND CveTipoPeriodo IN({listaCveTipoPeriodo.ToString()})")
|
|
GVTipoPeriodo.DataBind()
|
|
|
|
If (Not IsNothing(dtPeriodos) AndAlso dtPeriodos.Rows.Count() > 0) Then
|
|
DdlPeriodo.DataSource = dtPeriodos.FiltraParametros("CveTipoPeriodo=6")
|
|
|
|
End If
|
|
DdlPeriodo.DataBind()
|
|
DdlPeriodo.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
UpModalAutorizar.Update()
|
|
End Sub
|
|
|
|
Protected Sub DdlPeriodo_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
PnlTipoPeriodos.Visible = (DdlPeriodo.SelectedValue.ToEntero() <= 0)
|
|
UpModalAutorizar.Update()
|
|
End Sub
|
|
'Protected Sub DdlTipoPeriodo_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
' CargaPeriodos()
|
|
'End Sub
|
|
Protected Sub LnkAutorizarModal_Click(sender As Object, e As EventArgs)
|
|
CargaPeriodos()
|
|
RegistraScript("$('#ModalAutorizar').modal();")
|
|
End Sub
|
|
Protected Sub LnkAutorizar_Click(sender As Object, e As EventArgs)
|
|
|
|
Dim continuar As Boolean = True
|
|
Dim mensaje As String = ""
|
|
Dim DiasLaborados As Integer
|
|
Dim SueldoTotal As Double
|
|
Dim Importe As Double
|
|
Dim CveMoneda As Integer = 1
|
|
Dim CvePeriodoSeleccionado = DdlPeriodo.SelectedValue.ToEntero()
|
|
Dim ejercicio As Integer = DdlEjercicios.SelectedValue.ToEntero()
|
|
Dim CvePersonal As Integer
|
|
Dim CvePeriodo As Integer
|
|
Dim listaperiodos As New List(Of Periodos)
|
|
If CvePeriodoSeleccionado <= 0 Then
|
|
|
|
For Each gvRow As GridViewRow In GVTipoPeriodo.Rows
|
|
Dim periodo As New Periodos
|
|
periodo.CveTipoPeriodo = gvRow.DataKey("CveTipoPeriodo").ToString().ToEntero()
|
|
periodo.CvePeriodo = gvRow.FCDropDownList("ddlPeriodo").SelectedValue.ToEntero()
|
|
If periodo.CvePeriodo <= 0 Then
|
|
continuar = False
|
|
mensaje = "debe seleccionar un periodo Extraordinario o el periodo para los distintos tipo de periodos del personal!"
|
|
Exit For
|
|
End If
|
|
listaperiodos.Add(periodo)
|
|
Next
|
|
End If
|
|
'Dim ImporteGravado As Double
|
|
'Dim ImporteExento As Double
|
|
''Dim NombrePersonal As String
|
|
'Dim CveMetodoPago As Integer
|
|
'Dim CveNomina As Integer
|
|
Dim CveConcepto As Integer = 0
|
|
If continuar Then
|
|
Dim objNomina As New ClsNominas()
|
|
objNomina.IniciaTransacSQL()
|
|
If continuar Then
|
|
continuar = objNomina.UpADDdUtilidadesEjercicio(UsuarioActual.CveEmpresa, ejercicio, utilimporte, utilimporteAnt, False)
|
|
If continuar Then
|
|
If objNomina.DtResultados.Rows.Count < 0 OrElse objNomina.DtResultados.Rows(0)("CONTimbrado").ToString() = "1" Then
|
|
continuar = False
|
|
End If
|
|
End If
|
|
End If
|
|
If continuar Then continuar = objNomina.GetConceptos(UsuarioActual.CveEmpresa)
|
|
If continuar Then
|
|
Dim rowc As DataRow = objNomina.DtResultados.FiltroPrimero("Concepto='Utilidades' AND Tipo='P'")
|
|
If Not IsNothing(rowc) Then
|
|
CveConcepto = rowc("CveConcepto").ToString().ToEntero()
|
|
Else
|
|
CveConcepto = objNomina.AddConcepto("PTU", "Utilidades", "P", "", True, True, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, False, -1, -1, -1, 0, -1, 0, 0, 0, 0, 0)
|
|
End If
|
|
If CveConcepto < 1 Then
|
|
continuar = False
|
|
End If
|
|
End If
|
|
For Each row As DataRow In DTUtilidades.Rows
|
|
Importe = row("Importe").ToString().ToDouble()
|
|
SueldoTotal = row("SueldoTotal").ToString().ToDouble()
|
|
DiasLaborados = row("DiasLaborados").ToString().ToEntero()
|
|
CvePersonal = row("CvePersonal").ToString().ToEntero()
|
|
CvePeriodo = CvePeriodoSeleccionado
|
|
|
|
If continuar Then
|
|
continuar = objNomina.AddUtilidad(CvePersonal, Importe, CvePeriodo, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, ejercicio, DiasLaborados, SueldoTotal)
|
|
End If
|
|
If Not continuar Then
|
|
Exit For
|
|
End If
|
|
|
|
Next
|
|
If continuar And CvePeriodoSeleccionado > 0 Then
|
|
|
|
continuar = objNomina.CambiaEstatusPeriodo(CvePeriodoSeleccionado, enumNominasEstatus.Activa, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa)
|
|
End If
|
|
If continuar Then
|
|
objNomina.Commit()
|
|
Else
|
|
objNomina.RollBack()
|
|
End If
|
|
objNomina.Dispose()
|
|
End If
|
|
If mensaje.Length > 0 Then
|
|
Alert(mensaje, TipoMensaje.MsgAdvertencia)
|
|
continuar = False
|
|
End If
|
|
If continuar Then
|
|
RegistraScript("$('#ModalAutorizar').modal('hide');")
|
|
Alert("Se han generado las utilidades")
|
|
End If
|
|
End Sub
|
|
Private Class Periodos
|
|
Public Property CveTipoPeriodo As Integer
|
|
Public Property CvePeriodo As Integer
|
|
|
|
|
|
End Class
|
|
Protected Sub DdlEjercicios_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
Dim ejercicio As Integer = DdlEjercicios.SelectedValue.ToEntero()
|
|
Dim objnom As New ClsNominas()
|
|
Dim dt As DataTable = Nothing
|
|
objnom.GetUtilidadesEjercicio(UsuarioActual.CveEmpresa, ejercicio)
|
|
If (objnom.DtResultados.Rows.Count > 0) Then
|
|
TxtPA_Nimporte.Text = $"{objnom.DtResultados.Rows(0)("Importe"):N2}"
|
|
TxtPA_NimporteA.Text = $"${objnom.DtResultados.Rows(0)("ImporteAnterior"):N2}"
|
|
objnom.GetUtilidad(-1, -1, UsuarioActual.CveEmpresa, ejercicio)
|
|
dt = objnom.DtResultados
|
|
End If
|
|
objnom.Dispose()
|
|
cargaEjercicio(dt)
|
|
End Sub
|
|
Private Sub cargaEjercicio(dt As DataTable)
|
|
If Not IsNothing(dt) AndAlso dt.Rows.Count > 0 Then
|
|
pnlTotales.Visible = True
|
|
LblNumeroDias.Text = $"{dt.SUM("DiasLaborados"):N0}"
|
|
LblSueldos.Text = $"{dt.SUM("SueldoTotal"):N0}"
|
|
Else
|
|
pnlTotales.Visible = False
|
|
End If
|
|
GVCalcularUtilidades.DataSource = dt
|
|
GVCalcularUtilidades.DataBind()
|
|
upDatosPA_N.Update()
|
|
|
|
End Sub
|
|
Protected Sub GVTipoPeriodo_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
If (Not IsNothing(dtPeriodos) AndAlso dtPeriodos.Rows.Count()) Then
|
|
Dim dddlperiodo As DropDownList = e.Row.FCDropDownList("ddlPeriodo")
|
|
dddlperiodo.DataSource = dtPeriodos.FiltraParametros(String.Format("CveTipoPeriodo={0}", e.Row.DataKey("CveTipoPeriodo")))
|
|
dddlperiodo.DataBind()
|
|
dddlperiodo.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
End If
|
|
End If
|
|
End Sub
|
|
End Class
|