sin-titulo

Pasted Nov 9, 2026, 12:20 AM1 file251 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/zzgs9ftvacjg309a
sin-titulo
package com.negocio.desinfectantes.data

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "lotes_produccion")
data class LoteProduccionEntity(

    @PrimaryKey
    val id: String,

    val productoId: String,

    val aromaId: String,

    val fechaCreacion: Long = System.currentTimeMillis()
)


package com.negocio.desinfectantes.data

import androidx.room.Database
import androidx.room.RoomDatabase

@Database(
    entities = [
        ProductoEntity::class,
        AromaEntity::class,
        PresentacionEntity::class,
        InventarioEntity::class,
        ProduccionEntity::class,
        DistribucionProduccionEntity::class,
        MovimientoInventarioEntity::class,
        ClienteEntity::class,
        VentaEntity::class,
        DetalleVentaEntity::class,
        PagoVentaEntity::class,

        // Nuevas entidades de lotes
        LoteProduccionEntity::class,
        LoteDetalleEntity::class,
        LoteGastoEntity::class,
        LoteInventarioEntity::class,
        LoteVentaEntity::class
    ],
    version = 6,
    exportSchema = false
)
abstract class PrestigeDatabase : RoomDatabase() {
    abstract fun productoDao(): ProductoDao
}


package com.negocio.desinfectantes.data

import android.content.Context
import androidx.room.Room
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

object DatabaseProvider {

    private val MIGRATION_2_3 = object : Migration(2, 3) {
        override fun migrate(database: SupportSQLiteDatabase) {

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS producciones (
                    id TEXT NOT NULL,
                    presentacionId TEXT NOT NULL,
                    cantidadProducida INTEGER NOT NULL,
                    fechaCreacion INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS distribuciones_produccion (
                    id TEXT NOT NULL,
                    produccionId TEXT NOT NULL,
                    sede TEXT NOT NULL,
                    cantidad INTEGER NOT NULL,
                    fechaCreacion INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS movimientos_inventario (
                    id TEXT NOT NULL,
                    presentacionId TEXT NOT NULL,
                    sede TEXT NOT NULL,
                    tipoMovimiento TEXT NOT NULL,
                    cantidad INTEGER NOT NULL,
                    referenciaId TEXT,
                    observacion TEXT,
                    fechaCreacion INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)
        }
    }

    private val MIGRATION_3_4 = object : Migration(3, 4) {
        override fun migrate(database: SupportSQLiteDatabase) {

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS clientes (
                    id TEXT NOT NULL,
                    nombre TEXT NOT NULL,
                    telefono TEXT,
                    direccion TEXT,
                    observaciones TEXT,
                    activo INTEGER NOT NULL,
                    fechaCreacion INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)
        }
    }

    private val MIGRATION_4_5 = object : Migration(4, 5) {
        override fun migrate(database: SupportSQLiteDatabase) {

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS ventas (
                    id TEXT NOT NULL,
                    clienteId TEXT NOT NULL,
                    sede TEXT NOT NULL,
                    tipoVenta TEXT NOT NULL,
                    estadoEntrega TEXT NOT NULL,
                    total REAL NOT NULL,
                    fechaCreacion INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS detalles_venta (
                    id TEXT NOT NULL,
                    ventaId TEXT NOT NULL,
                    presentacionId TEXT NOT NULL,
                    cantidad INTEGER NOT NULL,
                    precioUnitario REAL NOT NULL,
                    subtotal REAL NOT NULL,
                    PRIMARY KEY(id)
                )
            """)

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS pagos_venta (
                    id TEXT NOT NULL,
                    ventaId TEXT NOT NULL,
                    monto REAL NOT NULL,
                    metodoPago TEXT NOT NULL,
                    observacion TEXT,
                    fechaCreacion INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)
        }
    }

    // Nueva migración: versión 5 a 6
    private val MIGRATION_5_6 = object : Migration(5, 6) {
        override fun migrate(database: SupportSQLiteDatabase) {

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS lotes_produccion (
                    id TEXT NOT NULL,
                    productoId TEXT NOT NULL,
                    aromaId TEXT NOT NULL,
                    fechaCreacion INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS lotes_detalle (
                    id TEXT NOT NULL,
                    loteId TEXT NOT NULL,
                    presentacionId TEXT NOT NULL,
                    cantidadFabricada INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS lotes_gastos (
                    id TEXT NOT NULL,
                    loteId TEXT NOT NULL,
                    concepto TEXT NOT NULL,
                    monto REAL NOT NULL,
                    observacion TEXT,
                    fechaCreacion INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS lotes_inventario (
                    id TEXT NOT NULL,
                    loteId TEXT NOT NULL,
                    presentacionId TEXT NOT NULL,
                    sede TEXT NOT NULL,
                    cantidadDisponible INTEGER NOT NULL,
                    cantidadReservada INTEGER NOT NULL,
                    PRIMARY KEY(id)
                )
            """)

            database.execSQL("""
                CREATE TABLE IF NOT EXISTS lotes_ventas (
                    id TEXT NOT NULL,
                    ventaId TEXT NOT NULL,
                    detalleVentaId TEXT NOT NULL,
                    loteInventarioId TEXT NOT NULL,
                    cantidad INTEGER NOT NULL,
                    estado TEXT NOT NULL,
                    PRIMARY KEY(id)
                )
            """)
        }
    }

    @Volatile
    private var INSTANCE: PrestigeDatabase? = null

    fun obtenerBaseDatos(context: Context): PrestigeDatabase {

        return INSTANCE ?: synchronized(this) {

            val instancia = Room.databaseBuilder(
                context.applicationContext,
                PrestigeDatabase::class.java,
                "prestige_clean_database"
            )
                .addMigrations(
                    MIGRATION_2_3,
                    MIGRATION_3_4,
                    MIGRATION_4_5,
                    MIGRATION_5_6
                )
                .build()

            INSTANCE = instancia

            instancia
        }
    }
}

7,729 chars · codepastes.com