# Copyright (c) 2020, JINGROW
# For license information, please see license.txt


import jingrow


def execute():
	jingrow.reload_pg("jcloud", "pagetype", "invoice")
	invoices = jingrow.db.get_all(
		"Invoice",
		{"status": "Paid", "pagestatus": 1, "amount_paid": (">", 0), "transaction_amount": 0},
		pluck="name",
	)
	for name in invoices:
		print(f"Updating transaction details for {name}")
		invoice = jingrow.get_pg("Invoice", name)
		invoice.flags.skip_jingrow_invoice = True
		updated = invoice.update_transaction_details()
		if updated:
			print("✅ Done")
			jingrow.db.commit()
