


DELETE from receipt_taxes where id IN
	(
	SELECT * FROM
		(
		SELECT receipt_taxes.id as eliminar
		FROM receipt_taxes
		WHERE receipt_taxes.receipt_id IN
			(
			-- Aca agarro el ID para luego buscarlo en receipt_taxes
			SELECT IdComprobante
				from
				(
			   -- esta consulta lo que hace es listar todos los comprobantes con los filtros
				SELECT
					receipts.id as IdComprobante,
					persons.id as IdProveedorCliente,
					receipts.person_id_owner as Empresa,
					periods.id as IdPeriodo,
					periods.date_from as Desde,
					periods.date_to as Hasta,
					periods.code as Periodo,
					types.name as Operacion,
					persons.field_name1 as Proveedor,
					receipts.number as Numero,
					receipt_taxes.id as IDreceipt_taxes

				from receipts
				left join periods on receipts.period_id = periods.id
				left join receipt_types on receipts.type_receipt_id = receipt_types.id
				left join retention_types on receipts.retention_type_id =retention_types.id
				left join status on receipts.status_id = status.id
				left join persons on receipts.person_id_relationed = persons.id
				left join receipt_taxes on receipts.id = receipt_taxes.receipt_id
				left join zones on receipts.zone_id = zones.id
				left join activities on receipts.activity_id = activities.id
				left join types on receipts.type_id = types.id
				left join system_taxes on  receipt_taxes.tax_id = system_taxes.id
				left join other_taxes on  receipt_taxes.tax_id = other_taxes.id

				where 	receipts.type_id LIKE '%1'
					and receipts.person_id_owner LIKE '%2141'
					and periods.id LIKE '%'
					and periods.code LIKE '%2018-5'
					and periods.date_from LIKE '%'
					and periods.date_to LIKE '%'

				group by  1,2,3,4,5,6,7,8,9,10,11
				)foo
			)
		)
        as tablanueva
	)
