2025-11-05 17:43:40 +00:00
# =========================
2025-11-06 19:18:37 +00:00
# MYSQL (constantes)
2025-11-05 17:43:40 +00:00
# =========================
SELECT_CUSTOMER_BY_FACTUGES = (
" SELECT customers.id FROM customers WHERE customers.factuges_id= %s "
)
INSERT_CUSTOMER = (
" INSERT INTO customers (id, name, tin, street, city, province, postal_code, country, "
" phone_primary, phone_secondary, mobile_primary, mobile_secondary, "
" email_primary, email_secondary, website, factuges_id, company_id, is_company, "
" language_code, currency_code, status, created_at, updated_at) "
" VALUES ( %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s ,1, ' es ' , ' EUR ' , ' active ' ,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP) "
)
UPDATE_CUSTOMER = (
" UPDATE customers SET name= %s , tin= %s , street= %s , city= %s , province= %s , postal_code= %s , country= %s , "
" phone_primary= %s , phone_secondary= %s , mobile_primary= %s , mobile_secondary= %s , "
" email_primary= %s , email_secondary= %s , website= %s , updated_at=CURRENT_TIMESTAMP "
" WHERE (id= %s ) "
)
SELECT_PAYMENT_METHOD_BY_FACTUGES = (
" SELECT payment_methods.id FROM payment_methods WHERE payment_methods.factuges_id= %s "
)
INSERT_PAYMENT_METHOD = (
" INSERT INTO payment_methods (id, description, factuges_id, created_at, updated_at) "
" VALUES ( %s , %s , %s ,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP) "
)
INSERT_INVOICE = (
2025-11-06 19:18:37 +00:00
" INSERT INTO customer_invoices (id, company_id, invoice_number, status, series, reference, invoice_date, operation_date, description, "
" subtotal_amount_value, discount_amount_value, discount_percentage_value, taxable_amount_value, taxes_amount_value, total_amount_value, "
" customer_id, customer_tin, customer_name, customer_street, customer_city, customer_province, customer_postal_code, customer_country, "
" payment_method_id, payment_method_description, factuges_id, "
" subtotal_amount_scale, discount_amount_scale, discount_percentage_scale, taxable_amount_scale, taxes_amount_scale, total_amount_scale, "
" language_code, currency_code, created_at, updated_at) "
" SELECT "
" %s AS id, "
" %s AS company_id, "
" COALESCE(MAX(invoice_number + 0),0)+1 AS invoice_number, "
" %s AS status, %s AS series, %s AS reference, %s AS invoice_date, %s AS operation_date, %s AS description, "
" %s AS subtotal_amount_value, %s AS discount_amount_value, %s AS discount_percentage_value, %s AS taxable_amount_value, %s AS taxes_amount_value, %s AS total_amount_value, "
" %s AS customer_id, %s AS customer_tin, %s AS customer_name, %s AS customer_street, %s AS customer_city, %s AS customer_province, %s AS customer_postal_code, %s AS customer_country, "
" %s AS payment_method_id, %s AS payment_method_description, %s AS factuges_id, "
" 2,2,2,2,2,2, ' es ' , ' EUR ' , CURRENT_TIMESTAMP, CURRENT_TIMESTAMP "
" FROM customer_invoices "
" WHERE company_id = %s "
" AND deleted_at is null "
)
INSERT_INVOICE_BAK = (
2025-11-05 17:43:40 +00:00
" INSERT INTO customer_invoices (id, company_id, invoice_number, status, series, reference, invoice_date, operation_date, description, "
" subtotal_amount_value, discount_amount_value, discount_percentage_value, taxable_amount_value, taxes_amount_value, total_amount_value, "
" customer_id, customer_tin, customer_name, customer_street, customer_city, customer_province, customer_postal_code, customer_country, "
" payment_method_id, payment_method_description, "
" subtotal_amount_scale, discount_amount_scale, discount_percentage_scale, taxable_amount_scale, taxes_amount_scale, total_amount_scale, "
" language_code, currency_code, created_at, updated_at) "
" VALUES ( %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s , %s ,2,2,2,2,2,2, ' es ' , ' EUR ' ,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP) "
)
2025-11-06 19:18:37 +00:00
2025-11-05 17:43:40 +00:00
INSERT_INVOICE_ITEM = (
" INSERT INTO customer_invoice_items "
" (item_id, invoice_id, position, description, quantity_value, unit_amount_value, "
" discount_percentage_value, discount_amount_value, total_amount_value, "
" quantity_scale, unit_amount_scale, discount_amount_scale, total_amount_scale, discount_percentage_scale, created_at, updated_at) "
" VALUES ( %s , %s , %s , %s , %s , %s , %s , %s , %s ,2,4,2,4,2,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP) "
)
INSERT_INVOICE_TAX = (
" INSERT INTO customer_invoice_taxes (tax_id, invoice_id, tax_code, taxable_amount_value, taxes_amount_value, "
" taxable_amount_scale, taxes_amount_scale, created_at, updated_at) "
" VALUES ( %s , %s , %s , %s , %s ,2,2,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP) "
)
INSERT_INVOICE_ITEM_TAX = (
" INSERT INTO customer_invoice_item_taxes "
" (tax_id, item_id, tax_code, taxable_amount_value, taxes_amount_value, taxable_amount_scale, taxes_amount_scale, created_at, updated_at) "
" VALUES ( %s , %s , %s , %s , %s ,4,2,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP) "
)
2025-11-06 19:18:37 +00:00
SELECT_INVOICES_DELETED = (
" SELECT ci.id "
" FROM customer_invoices as ci "
" WHERE "
" (ci.deleted_at is not null) "
)
# =========================
# FIREBIRD (constantes)
# =========================
SELECT_FACTUGES_FACTURAS_CLIENTE = (
f " SELECT fac.VERIFACTU, fac.ID_VERIFACTU, fac.ID || ' ' AS ID, fac.ID_EMPRESA || ' ' AS ID_EMPRESA, fac.REFERENCIA, fac.FECHA_FACTURA, fac.ID_CLIENTE || ' ' as ID_CLIENTE, fac.NIF_CIF, fac.NOMBRE, "
f " fac.CALLE, fac.POBLACION, fac.PROVINCIA, fac.CODIGO_POSTAL, fac.FECHA_ALTA, "
f " fac.IMPORTE_NETO, fac.DESCUENTO, fac.IMPORTE_DESCUENTO, fac.BASE_IMPONIBLE, fac.IVA, fac.IMPORTE_IVA, fac.IMPORTE_TOTAL, "
f " fac.ID_FORMA_PAGO, fp.DESCRIPCION as DES_FORMA_PAGO, fac.ID_TIPO_IVA, ti.REFERENCIA as DES_TIPO_IVA, fac.RECARGO_EQUIVALENCIA, fac.RE, fac.IMPORTE_RE, "
f " fac.ID_CLIENTE, fac.NIF_CIF, fac.NOMBRE, fac.CALLE, fac.POBLACION, fac.PROVINCIA, fac.CODIGO_POSTAL, "
f " cc.TELEFONO_1, cc.TELEFONO_2, cc.MOVIL_1, cc.MOVIL_2, cc.EMAIL_1, cc.EMAIL_2, cc.PAGINA_WEB, "
f " facdet.ID || ' ' as ID_DET, facdet.ID_FACTURA, facdet.POSICION, facdet.TIPO_DETALLE, facdet.ID_ARTICULO, facdet.CONCEPTO, facdet.CANTIDAD, "
f " facdet.IMPORTE_UNIDAD, facdet.DESCUENTO as DESCUENTO_DET, facdet.IMPORTE_TOTAL as IMPORTE_TOTAL_DET, facdet.VISIBLE, facdet.FECHA_ALTA as FECHA_ALTA_DET, facdet.FECHA_MODIFICACION as FECHA_MODIFICACION_DET "
f " FROM FACTURAS_CLIENTE AS fac "
f " LEFT JOIN CONTACTOS AS cc ON fac.ID_CLIENTE = cc.ID "
f " LEFT JOIN FORMAS_PAGO AS fp ON fac.ID_FORMA_PAGO = fp.ID "
f " LEFT JOIN TIPOS_IVA AS ti ON fac.ID_TIPO_IVA = ti.ID "
f " LEFT JOIN FACTURAS_CLIENTE_DETALLES as facdet ON fac.ID = facdet.ID_FACTURA "
f " WHERE "
f " (fac.VERIFACTU > 0) "
f " AND (fac.ID_VERIFACTU is null) "
f " ORDER BY (fac.ID) "
)
2025-11-05 17:43:40 +00:00
UPDATE_FACTUGES_LINK = (
" UPDATE FACTURAS_CLIENTE "
" SET ID_VERIFACTU=? "
" WHERE ID=? "
)
LIMPIAR_FACTUGES_LINK = (
" UPDATE FACTURAS_CLIENTE "
" SET ID_VERIFACTU = NULL, "
" VERIFACTU = 0 "
" WHERE (ID_VERIFACTU = ?) "
2025-11-06 19:18:37 +00:00
)