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


import jingrow


# this should probably be run via server scripts
def execute():
	"""Mark invoices that are unpaid for more than 6 months as Uncollectible"""
	six_months_ago = jingrow.utils.add_to_date(None, months=-6)
	invoices = jingrow.db.get_all(
		"Invoice",
		filters={"due_date": ("<", six_months_ago), "status": "Unpaid", "pagestatus": 0},
	)

	for inv in invoices:
		invoice = jingrow.get_pg("Invoice", inv)
		invoice.status = "Uncollectible"
		invoice.save()
