Pular para o conteúdo principal

ST_GERALOTEPRODUTOAUTO

This code is part of a FormShow event handler for a lot/batch entry form in an ERP system. Here's what it does in plain terms:

Key Functionality​

Automatic Lot Generation Setup:

  • When ST_GERALOTEPRODUTOAUTO = 'S' (automatic lot generation is enabled), the form:
    • Sets up the manufacturing date (uses provided date if from module MEQ012, otherwise uses current date)
    • Queries the database to count existing lots for the current item and year
    • Calculates the next lot sequence number (count + 1)
    • Retrieves the product's validity period from the ITEM table
    • Shows the "Generate Lot" button (btnGerarLote)
    • Makes the validity date field editable, but keeps the document number read-only
    • Hides the button when auto-generation is disabled

Form Initialization:

  • Sets up window captions from parameters
  • Calculates and displays totals
  • Configures the form layout based on product type:
    • Seed Lot (Semente): Shows seed-related fields, hides production fields
    • Production Lot (Produção): Shows production-related fields, hides seed fields
  • Hides/shows the "production in progress" panel based on whether it's a scheduled lot

Database Connection:

  • Assigns a transaction to the lot table
  • Prepares to open the lot dataset

Technical Summary​

This is a smart initialization routine that:

  • ✅ Auto-generates sequential lot numbers per year
  • ✅ Calculates expiration dates based on product configuration
  • ✅ Adapts UI based on product type (seed vs. production)
  • ✅ Integrates with parameter MEQ001 for automatic lot generation
  • ✅ Handles both scheduled and manual lot creation