========================================================================
  SQLITE TO EXCEL
  Didactic Python code · Kardex Tauro · kardex-tauro.muisca.co
========================================================================
openpyxl library: 3.1.5

========================================================================
STEP 1: PREPARE THE DATABASE
========================================================================
The sample database is built: salida/ejemplo.db
Rows inserted from the CSV into table products: 8
Rows inserted from the CSV into table movements: 14

========================================================================
STEP 2: READ THE SCHEMA (TABLES AND COLUMNS)
========================================================================
User tables in the database: 2
TABLE movements (columns: 7)
-------------------------------------
Column           Type       Key      
-------------------------------------
id               INTEGER    PK       
date             TEXT       -        
code             TEXT       -        
type             TEXT       -        
units            INTEGER    -        
unit_price       INTEGER    -        
document         TEXT       -        
-------------------------------------
TABLE products (columns: 5)
-------------------------------------
Column           Type       Key      
-------------------------------------
code             TEXT       PK       
product          TEXT       -        
category         TEXT       -        
price            INTEGER    -        
stock            INTEGER    -        
-------------------------------------

========================================================================
STEP 3: READ THE ROWS
========================================================================
Rows read from movements: 14
Rows read from products: 8
ROWS AND COLUMNS PER TABLE
------------------------------------------
Table                      Rows    Columns
------------------------------------------
movements                    14          7
products                      8          5
------------------------------------------

========================================================================
STEP 4: WRITE THE EXCEL WORKBOOK
========================================================================
Sheets written in the workbook: 3
Workbook sheets: Index, movements, products
Excel file written: salida/inventario.xlsx

========================================================================
STEP 5: EXPORT ONE QUERY TO CSV
========================================================================
Sample query with the movements of type: out
SQL: SELECT p."category" AS "Category", COUNT(*) AS "Movements", SUM(m."units") AS "Units", SUM(m."units" * m."unit_price") AS "Amount" FROM "movements" m JOIN "products" p ON p."code" = m."code" WHERE m."type" = ? GROUP BY p."category" ORDER BY "Amount" DESC, "Category"
Query exported to CSV: salida/resumen_categorias.csv
CSV rows: 3

========================================================================
STEP 6: CLOSE
========================================================================
Connection closed.

========================================================================
CLOSING
========================================================================
  Database read: salida/ejemplo.db
  User tables: 2
  Workbook sheets: 3
  Excel file: salida/inventario.xlsx
  CSV file: salida/resumen_categorias.csv
