// Copyright (c) 2024, Company and contributors
// For license information, please see license.txt

frappe.query_reports["Customer Outstanding Balance"] = {
	"filters": [
		{
			"fieldname": "company",
			"label": __("Company"),
			"fieldtype": "Link",
			"options": "Company",
			"reqd": 1,
			"default": frappe.defaults.get_user_default("Company")
		},
		{
			"fieldname": "from_date",
			"label": __("From Date"),
			"fieldtype": "Date",
			"default": frappe.datetime.add_months(frappe.datetime.get_today(), -1),
			"reqd": 1
		},
		{
			"fieldname": "to_date",
			"label": __("To Date"),
			"fieldtype": "Date",
			"default": frappe.datetime.get_today(),
			"reqd": 1
		},
		{
			"fieldname": "customer_group",
			"label": __("Customer Group"),
			"fieldtype": "Link",
			"options": "Customer Group"
		}
	],

	"formatter": function (value, row, column, data, default_formatter) {
		value = default_formatter(value, row, column, data);

		if (!data) return value;

		// Original columns highlighting
		if (column.fieldname == "opening_balance" && data.opening_balance > 0) {
			value = "<span style='color: #1f77b4; font-weight: bold;'>" + value + "</span>";
		}

		if (column.fieldname == "payments" && data.payments > 0) {
			value = "<span style='color: #2ca02c; font-weight: bold;'>" + value + "</span>";
		}

		if (column.fieldname == "new_invoices" && data.new_invoices > 0) {
			value = "<span style='color: #ff7f0e; font-weight: bold;'>" + value + "</span>";
		}

		if (column.fieldname == "closing_balance" && data.closing_balance > 0) {
			value = "<span style='color: #d62728; font-weight: bold;'>" + value + "</span>";
		}

		// Tax template columns highlighting
		// ƏDV 18% - Purple tones
		if (column.fieldname == "edv_18_opening" && data.edv_18_opening > 0) {
			value = "<span style='color: #9467bd; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_18_plus" && data.edv_18_plus > 0) {
			value = "<span style='color: #ff7f0e; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_18_minus" && data.edv_18_minus > 0) {
			value = "<span style='color: #2ca02c; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_18_closing" && data.edv_18_closing > 0) {
			value = "<span style='color: #8c564b; font-weight: bold;'>" + value + "</span>";
		}

		// ƏDV daxil 18% - Blue-green tones
		if (column.fieldname == "edv_daxil_18_opening" && data.edv_daxil_18_opening > 0) {
			value = "<span style='color: #17becf; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_daxil_18_plus" && data.edv_daxil_18_plus > 0) {
			value = "<span style='color: #ff7f0e; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_daxil_18_minus" && data.edv_daxil_18_minus > 0) {
			value = "<span style='color: #2ca02c; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_daxil_18_closing" && data.edv_daxil_18_closing > 0) {
			value = "<span style='color: #1f77b4; font-weight: bold;'>" + value + "</span>";
		}

		// ƏDV 0% - Green tones
		if (column.fieldname == "edv_0_opening" && data.edv_0_opening > 0) {
			value = "<span style='color: #bcbd22; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_0_plus" && data.edv_0_plus > 0) {
			value = "<span style='color: #ff7f0e; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_0_minus" && data.edv_0_minus > 0) {
			value = "<span style='color: #2ca02c; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_0_closing" && data.edv_0_closing > 0) {
			value = "<span style='color: #7f7f7f; font-weight: bold;'>" + value + "</span>";
		}

		// ƏDV-dən azadolma - Pink-red tones
		if (column.fieldname == "edv_azadolma_opening" && data.edv_azadolma_opening > 0) {
			value = "<span style='color: #e377c2; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_azadolma_plus" && data.edv_azadolma_plus > 0) {
			value = "<span style='color: #ff7f0e; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_azadolma_minus" && data.edv_azadolma_minus > 0) {
			value = "<span style='color: #2ca02c; font-weight: bold;'>" + value + "</span>";
		}
		if (column.fieldname == "edv_azadolma_closing" && data.edv_azadolma_closing > 0) {
			value = "<span style='color: #d62728; font-weight: bold;'>" + value + "</span>";
		}

		return value;
	}
};