-- ------------------------------------------------------------------------------------------------------------------------------------------------------
-- TB: actualizaciones
-- 
-- Actualizado: 2025-11-08
/*
-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_osales_orders` 
ADD COLUMN `envio_prioridad_cambio` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `envio_prioridad`,
ADD COLUMN `nota` VARCHAR(500) NULL DEFAULT '' AFTER `envio_prioridad_cambio`;

CREATE TABLE `tb_f_menvio_prioridad` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL,
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL,
  `codigo` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL,
  `nombre` VARCHAR(120) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL,
  `estado` SMALLINT NOT NULL DEFAULT '1')
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE `tb_f_oinvoice` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `fecha` DATE NULL DEFAULT '1900-01-01',
  `fecha_v` DATE NULL DEFAULT '1900-01-01',
  `fecha_r` DATE NULL DEFAULT '1900-01-01',
  `fecha_u` DATE NULL DEFAULT '1900-01-01',
  `cliente` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `purchase` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `numero_documento` VARCHAR(20) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `tracking` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `numero_so` VARCHAR(20) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `numero_item` SMALLINT NULL DEFAULT '0',
  `total_precio` DECIMAL(10,2) NULL DEFAULT '0.00',
  `envio_nombre` VARCHAR(100) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_pais` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_estado_ciudad` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_ciudad` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_zcode` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_direccion` VARCHAR(250) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_completo_req` SMALLINT NULL DEFAULT '0',
  `envio_prioridad` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_prioridad_cambio` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `nota` VARCHAR(500) NULL DEFAULT '',
  `vendedor` VARCHAR(120) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `usuario_sistema` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `estatus` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `estado` SMALLINT NULL DEFAULT '0',
  `referencia` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `bill_name` VARCHAR(100) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `moneda` VARCHAR(5) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `fecha_sync` DATE NULL DEFAULT '1900-01-01',
  `tipo_sync` SMALLINT NULL DEFAULT '0',
  `factory` SMALLINT NULL DEFAULT '0',
  PRIMARY KEY (`codemp`, `sucursal`, `numero`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE `tb_f_oinvoice_dproducts` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `producto` VARCHAR(100) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `nombre` VARCHAR(300) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `descuento_p` DECIMAL(6,2) NULL DEFAULT '0.00',
  `precio_lista` DECIMAL(10,2) NULL DEFAULT '0.00',
  `cantidad_fac` DECIMAL(10,2) NULL DEFAULT '0.00',
  `cantidad_ord` DECIMAL(10,2) NULL DEFAULT '0.00',
  `cantidad_res` DECIMAL(10,2) NULL DEFAULT '0.00',
  `cantidad_env` DECIMAL(10,2) NULL DEFAULT '0.00',
  `fecha_ent` DATE NULL DEFAULT '1900-01-01',
  `fecha_req` DATE NULL DEFAULT '1900-01-01',
  `fecha_pfe` DATE NULL DEFAULT '1900-01-01',
  `nota` VARCHAR(500) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `nuevo_usado` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `precio_venta` DECIMAL(10,2) NULL DEFAULT '0.00',
  `fecha_env` DATE NULL DEFAULT '1900-01-01',
  `impuesto_monto` DECIMAL(10,2) NULL DEFAULT '0.00',
  `costo_unitario` DECIMAL(10,2) NULL DEFAULT '0.00',
  `unidad_medida` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `invoice` VARCHAR(25) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `fecha_invoice` DATE NULL DEFAULT '1900-01-01',
  `fecha_sync` DATE NULL DEFAULT '1900-01-01',
  `tipo_sync` SMALLINT NULL DEFAULT '0',
  `item` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`item`));

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE `tb_f_ofactory` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `fecha` DATE NULL DEFAULT '1900-01-01',
  `fecha_r` DATE NULL DEFAULT '1900-01-01',
  `fecha_p` DATE NULL DEFAULT '1900-01-01',
  `fecha_u` DATE NULL DEFAULT '1900-01-01',
  `cliente` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `entidad` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `referencia` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `nota` VARCHAR(500) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `total` DECIMAL(10,2) NULL DEFAULT '0.00',
  `abono` DECIMAL(10,2) NULL DEFAULT '0.00',
  `saldo` DECIMAL(10,2) NULL DEFAULT '0.00',
  `usuario` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `estado` SMALLINT NULL DEFAULT '0',
  PRIMARY KEY (`codemp`, `sucursal`, `numero`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE `tb_f_ofactory_dfactura` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `factura` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `total_precio` DECIMAL(10,2) NULL DEFAULT '0.00',
  `marca` SMALLINT NULL DEFAULT '0',
  `item` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`item`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_mcustomers` 
ADD COLUMN `factory` SMALLINT NULL DEFAULT '0' AFTER `tipo_sync`;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE `tb_f_mseller` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL,
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL,
  `codigo` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL,
  `nombre` VARCHAR(120) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `estado` SMALLINT NOT NULL DEFAULT '1',
  PRIMARY KEY (`codemp`, `sucursal`, `codigo`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_osales_orders` 
CHANGE COLUMN `vendedor` `vendedor_nombre` VARCHAR(120) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' ;

ALTER TABLE `tb_f_osales_orders` 
ADD COLUMN `vendedor` VARCHAR(10) NULL DEFAULT '' AFTER `nota`;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
set @codigo = 0 ;
drop temporary table if exists x ;
create temporary table x
select '01' codemp, '001' sucursal, '01001000' as cod, vendedor as nombre 
	from db_usupplyit.tb_f_osales_orders 
    where coalesce(vendedor, '') <> '' 
    group by vendedor 
    order by vendedor ; 

insert into tb_f_mseller (codemp, sucursal, codigo, nombre, estado)
	select codemp, sucursal, concat(cod, @codigo := @codigo +1), nombre, 1
		from x
        order by nombre ;
        
update tb_f_osales_orders
	inner join tb_f_mseller
		on trim(tb_f_osales_orders.vendedor) = trim(tb_f_mseller.nombre)
	set
		tb_f_osales_orders.vendedor = tb_f_mseller.codigo ;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE `tb_f_obatch` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `fecha` DATE NULL DEFAULT '1900-01-01',
  `fecha_r` DATE NULL DEFAULT '1900-01-01',
  `fecha_p` DATE NULL DEFAULT '1900-01-01',
  `fecha_u` DATE NULL DEFAULT '1900-01-01',
  `cliente` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `nota` VARCHAR(500) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `total` DECIMAL(10,2) NULL DEFAULT '0.00',
  `usuario` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `estado` SMALLINT NULL DEFAULT '0',
  PRIMARY KEY (`codemp`, `sucursal`, `numero`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;


CREATE TABLE `tb_f_obatch_dsales_orders` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `numero_so` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `total_precio` DECIMAL(10,2) NULL DEFAULT '0.00',
  `item` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`item`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;
*/

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
-- ------------------------------------------------------------------------------------------------------------------------------------------------------
-- TB: actualizaciones
-- 
-- Actualizado: 2025-11-10
-- 
/*
CREATE TABLE `tb_f_mcustomers_dshipto` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `codigo` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_codigo` VARCHAR(10) NULL DEFAULT ';;',
  `envio_nombre` VARCHAR(100) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_pais` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_estado_ciudad` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_ciudad` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_zcode` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `envio_direccion` VARCHAR(250) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `item` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`item`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_mcustomers` 
ADD COLUMN `factory_dias` SMALLINT NULL DEFAULT '0' AFTER `factory`,
ADD COLUMN `factory_monto` DECIMAL(10,2) NULL DEFAULT '0.00' AFTER `factory_dias`,
CHANGE COLUMN `estado` `estado` SMALLINT NULL DEFAULT '1' AFTER `factory_monto`,
CHANGE COLUMN `pais` `pais` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL ,
CHANGE COLUMN `estado_ciudad` `estado_ciudad` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL ,
CHANGE COLUMN `ciudad` `ciudad` VARCHAR(70) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL ,
CHANGE COLUMN `zcode` `zcode` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL ,
CHANGE COLUMN `telefono` `telefono` VARCHAR(30) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL ,
CHANGE COLUMN `direccion` `direccion` VARCHAR(500) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL ,
CHANGE COLUMN `fecha_r` `fecha_r` DATE NULL DEFAULT '1900-01-01' ,
CHANGE COLUMN `fecha_u` `fecha_u` DATE NULL DEFAULT '1900-01-01' ,
CHANGE COLUMN `usuario` `usuario` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' ;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_mcustomers_dshipto` 
CHANGE COLUMN `envio_codigo` `envio_descripcion` VARCHAR(10) NULL DEFAULT ';' ;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_osales_orders` 
ADD COLUMN `ship_to` INT NULL DEFAULT '0' AFTER `cliente`;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_osales_orders` 
CHANGE COLUMN `referencia` `referencia` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `tracking`,
CHANGE COLUMN `bill_name` `bill_name` VARCHAR(100) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `referencia`,
CHANGE COLUMN `numero_documento` `numero_documento` VARCHAR(20) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `nota`,
CHANGE COLUMN `purchase` `purchase` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `numero_documento`,
CHANGE COLUMN `numero_item` `numero_item` SMALLINT NULL DEFAULT '0' AFTER `purchase`,
CHANGE COLUMN `total_precio` `total_precio` DECIMAL(10,2) NULL DEFAULT '0.00' AFTER `numero_item`,
CHANGE COLUMN `vendedor` `vendedor` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `ocultar`,
CHANGE COLUMN `vendedor_nombre` `vendedor_nombre` VARCHAR(120) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `vendedor`,
CHANGE COLUMN `usuario_sistema` `usuario_sistema` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `vendedor_nombre`,
CHANGE COLUMN `estatus` `estatus` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `usuario_sistema`,
CHANGE COLUMN `ocultar` `ocultar` SMALLINT NULL DEFAULT '0',
CHANGE COLUMN `estado` `estado` SMALLINT NULL DEFAULT '0' AFTER `estatus`;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE `tb_f_ocustomers_po` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `fecha` DATE NULL DEFAULT '1900-01-01',
  `fecha_u` DATE NULL DEFAULT '1900-01-01',
  `cliente` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `referencia` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `nota` VARCHAR(500) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `usuario` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `estado` SMALLINT NULL DEFAULT '0',
  PRIMARY KEY (`codemp`, `sucursal`, `numero`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------

drop procedure if exists `sp_f_osales_orders_c`;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE TABLE `tb_f_ocustomers_pl` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NOT NULL DEFAULT '',
  `fecha` DATE NULL DEFAULT '1900-01-01',
  `fecha_d` DATE NULL DEFAULT '1900-01-01',
  `fecha_h` DATE NULL DEFAULT '1900-01-01',
  `fecha_u` DATE NULL DEFAULT '1900-01-01',
  `cliente` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `nota` VARCHAR(500) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `usuario` VARCHAR(10) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `estado` SMALLINT NULL DEFAULT '0',
  PRIMARY KEY (`codemp`, `sucursal`, `numero`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

CREATE TABLE `tb_f_ocustomers_pl_dproducts` (
  `codemp` VARCHAR(2) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `sucursal` VARCHAR(3) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `numero` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `producto` VARCHAR(100) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '',
  `precio_lista` DECIMAL(10,2) NULL DEFAULT '0.00',
  `award` SMALLINT NULL DEFAULT '0',
  `item` INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`item`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_spanish_ci;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_osales_orders` 
CHANGE COLUMN `fecha_sync` `fecha_sync` DATE NULL DEFAULT '1900-01-01' AFTER `usuario_sistema`,
CHANGE COLUMN `tipo_sync` `tipo_sync` SMALLINT NULL DEFAULT '0' AFTER `fecha_sync`;

ALTER TABLE `tb_f_oinvoice` 
CHANGE COLUMN `numero_so` `numero_so` VARCHAR(20) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `cliente`,
CHANGE COLUMN `referencia` `referencia` VARCHAR(45) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `tracking`,
CHANGE COLUMN `bill_name` `bill_name` VARCHAR(100) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `referencia`,
CHANGE COLUMN `numero_documento` `numero_documento` VARCHAR(20) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `nota`,
CHANGE COLUMN `numero_item` `numero_item` SMALLINT NULL DEFAULT '0' AFTER `numero_documento`,
CHANGE COLUMN `purchase` `purchase` VARCHAR(15) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `numero_item`,
CHANGE COLUMN `total_precio` `total_precio` DECIMAL(10,2) NULL DEFAULT '0.00' AFTER `purchase`,
CHANGE COLUMN `moneda` `moneda` VARCHAR(5) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_spanish_ci' NULL DEFAULT '' AFTER `total_precio`,
CHANGE COLUMN `factory` `factory` SMALLINT NULL DEFAULT '0' AFTER `moneda`,
CHANGE COLUMN `fecha_sync` `fecha_sync` DATE NULL DEFAULT '1900-01-01' AFTER `usuario_sistema`,
CHANGE COLUMN `tipo_sync` `tipo_sync` SMALLINT NULL DEFAULT '0' AFTER `fecha_sync`;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
drop procedure if exists `sp_lista_f_mcliente_invoice`;

ALTER TABLE `tb_f_obatch` 
DROP COLUMN `fecha_p`,
DROP COLUMN `fecha_r`,
ADD COLUMN `fecha_d` DATE NULL DEFAULT '1900-01-01' AFTER `fecha`,
ADD COLUMN `fecha_h` DATE NULL DEFAULT '1900-01-01' AFTER `fecha_d`;

-- ------------------------------------------------------------------------------------------------------------------------------------------------------
ALTER TABLE `tb_f_obatch_dsales_orders` 
ADD COLUMN `invoice` VARCHAR(15) NULL DEFAULT '' AFTER `numero_so`;
*/


-- ------------------------------------------------------------------------------------------------------------------------------------------------------
-- ------------------------------------------------------------------------------------------------------------------------------------------------------
-- TB: actualizaciones
-- 
-- Actualizado: 2025-11-18

update tb_a_mproducts
  set nombre = REPLACE(nombre, '\t', '')
	where nombre LlikeKE '%\t%';

-- ------------------------------------------------------------------------------------------------------------------------------------------------------


-- ------------------------------------------------------------------------------------------------------------------------------------------------------


-- ------------------------------------------------------------------------------------------------------------------------------------------------------


-- ------------------------------------------------------------------------------------------------------------------------------------------------------


-- ------------------------------------------------------------------------------------------------------------------------------------------------------


-- ------------------------------------------------------------------------------------------------------------------------------------------------------
