git-svn-id: https://192.168.0.254/svn/Proyectos.AbetoDesign_FactuGES/trunk@2 93f398dd-4eb6-7a46-baf6-13f46f578da2
140 lines
4.2 KiB
Plaintext
140 lines
4.2 KiB
Plaintext
delete from new_table;
|
|
CREATE TABLE NEW_TABLE (
|
|
ID INTEGER,
|
|
SS INTEGER);
|
|
|
|
|
|
CREATE PROCEDURE PROC_CREATE_SUBCUENTAS_CLI
|
|
as
|
|
declare variable id_cliente integer;
|
|
declare variable ref_cliente varchar(255);
|
|
declare variable id_subcuenta integer;
|
|
declare variable nombre_cliente varchar(255);
|
|
declare variable id_subcuenta_inser integer;
|
|
begin
|
|
|
|
|
|
for select GEN_ID(gen_cont_subcuentas_id, 1), contactos.ID, '430' || coalesce(empresas_tiendas.codigo_contable, '00') || substr(contactos.REFERENCIA,6,12),
|
|
contactos.nombre
|
|
from contactos
|
|
left join contactos_categorias on (contactos_categorias.id_contacto = contactos.id)
|
|
left join empresas_tiendas on (empresas_tiendas.id = contactos.id_tienda)
|
|
where contactos_categorias.id_categoria = 1 /*solo clientes*/
|
|
order by contactos.ID
|
|
into :id_subcuenta_inser, :id_cliente, :ref_cliente, :nombre_cliente do
|
|
begin
|
|
id_subcuenta = null;
|
|
select cont_subcuentas.ID
|
|
from cont_subcuentas
|
|
where cont_subcuentas.ID_CONTACTO = :id_cliente
|
|
into :id_subcuenta;
|
|
|
|
if (id_subcuenta is null) then
|
|
begin
|
|
insert into new_table (id, ss)
|
|
values (:id_cliente, 0);
|
|
|
|
insert into CONT_SUBCUENTAS (ID, REF_SUBCUENTA, DESCRIPCION, ID_EJERCICIO, ID_CUENTA, ID_CONTACTO)
|
|
values (:id_subcuenta_inser, :ref_cliente, 'Cuenta cliente: ' || :nombre_cliente, 3, 1434, :id_cliente);
|
|
|
|
update clientes_datos
|
|
set ignorar_contabilidad = 0,
|
|
tiene_subcuenta = 1
|
|
where id_cliente = :id_cliente;
|
|
end
|
|
else
|
|
begin
|
|
insert into new_table (id, ss)
|
|
values (:id_cliente, 1);
|
|
|
|
update cont_subcuentas
|
|
set ref_subcuenta = :ref_cliente
|
|
where cont_subcuentas.ID = :id_subcuenta;
|
|
|
|
update clientes_datos
|
|
set ignorar_contabilidad = 0,
|
|
tiene_subcuenta = 1
|
|
where id_cliente = :id_cliente;
|
|
end
|
|
end
|
|
|
|
suspend;
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
select ref_subcuenta, count(id)
|
|
from cont_subcuentas
|
|
group by ref_subcuenta
|
|
|
|
//mas de 3
|
|
|
|
select cont_subcuentas.id_ejercicio, cont_subcuentas.ID, cont_subcuentas.ref_subcuenta, cont_subcuentas.descripcion, cont_subcuentas.ID_CONTACTO
|
|
from cont_subcuentas
|
|
where cont_subcuentas.ref_subcuenta = '4300000000'
|
|
|
|
|
|
|
|
|
|
|
|
CREATE PROCEDURE PROC_CREATE_SUBCUENTAS_PRO
|
|
as
|
|
declare variable id_proveedor integer;
|
|
declare variable ref_proveedor varchar(255);
|
|
declare variable id_subcuenta integer;
|
|
declare variable nombre_proveedor varchar(255);
|
|
declare variable id_subcuenta_inser integer;
|
|
begin
|
|
|
|
|
|
for select GEN_ID(gen_cont_subcuentas_id, 1), contactos.ID, '400' || coalesce(empresas_tiendas.codigo_contable, '00') || substr(contactos.REFERENCIA,6,12),
|
|
contactos.nombre
|
|
from contactos
|
|
left join contactos_categorias on (contactos_categorias.id_contacto = contactos.id)
|
|
left join empresas_tiendas on (empresas_tiendas.id = contactos.id_tienda)
|
|
where contactos_categorias.id_categoria = 2 /*solo proveedores*/
|
|
order by contactos.ID
|
|
into :id_subcuenta_inser, :id_proveedor, :ref_proveedor, :nombre_proveedor do
|
|
begin
|
|
id_subcuenta = null;
|
|
select cont_subcuentas.ID
|
|
from cont_subcuentas
|
|
where cont_subcuentas.ID_CONTACTO = :id_proveedor
|
|
into :id_subcuenta;
|
|
|
|
if (id_subcuenta is null) then
|
|
begin
|
|
insert into new_table (id, ss)
|
|
values (:id_proveedor, 0);
|
|
|
|
insert into CONT_SUBCUENTAS (ID, REF_SUBCUENTA, DESCRIPCION, ID_EJERCICIO, ID_CUENTA, ID_CONTACTO)
|
|
values (:id_subcuenta_inser, :ref_proveedor, 'Cuenta proveedor: ' || :nombre_proveedor, 3, 1434, :id_proveedor);
|
|
|
|
update proveedores_datos
|
|
set ignorar_contabilidad = 0,
|
|
tiene_subcuenta = 1,
|
|
es_Acreedor = 0
|
|
where id_proveedor = :id_proveedor;
|
|
end
|
|
else
|
|
begin
|
|
insert into new_table (id, ss)
|
|
values (:id_proveedor, 1);
|
|
|
|
update cont_subcuentas
|
|
set ref_subcuenta = :ref_proveedor
|
|
where cont_subcuentas.ID = :id_subcuenta;
|
|
|
|
update proveedores_datos
|
|
set ignorar_contabilidad = 0,
|
|
tiene_subcuenta = 1,
|
|
es_Acreedor = 0
|
|
where id_proveedor = :id_proveedor;
|
|
end
|
|
end
|
|
|
|
suspend;
|
|
end
|
|
|