Skip to content

Instantly share code, notes, and snippets.

@ipascual
Created March 19, 2018 22:36
Show Gist options
  • Save ipascual/5aa88406e48dfa74a9eab62ead07374d to your computer and use it in GitHub Desktop.
Save ipascual/5aa88406e48dfa74a9eab62ead07374d to your computer and use it in GitHub Desktop.
magento2 - delete invoices SQL
fromInvoiceId = 418
fromOrderId = 371
DELETE FROM sales_invoice WHERE entity_id >= 418;
ALTER TABLE sales_invoice AUTO_INCREMENT = 418;
DELETE FROM sales_invoice_grid WHERE entity_id >= 418;
ALTER TABLE sales_invoice_grid AUTO_INCREMENT = 418;
DELETE FROM sales_invoice_item WHERE parent_id >= 418;
ALTER TABLE sales_invoice_item AUTO_INCREMENT = 418;
DELETE FROM sequence_invoice_1 WHERE sequence_value >= 418;
ALTER TABLE sequence_invoice_1 AUTO_INCREMENT = 418;
UPDATE sales_order
SET base_discount_invoiced=0,
base_shipping_invoiced=0,
base_subtotal_invoiced=0,
base_tax_invoiced=0,
base_total_invoiced_cost=0,
base_total_invoiced=0,
discount_invoiced=0,
shipping_invoiced=0,
subtotal_invoiced=0,
tax_invoiced=0,
total_invoiced=0
WHERE entity_id >=371;
UPDATE sales_order_item
SET qty_invoiced=0,
tax_invoiced =0,
base_tax_invoiced=0,
discount_invoiced =0,
base_discount_invoiced=0,
row_invoiced = 0,
base_row_invoiced=0,
locked_do_invoice=0,
discount_tax_compensation_invoiced = 0,
base_discount_tax_compensation_invoiced = 0
WHERE order_id >= 371;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment