Skip to content

Instantly share code, notes, and snippets.

@itsyosefali
Last active January 8, 2023 12:08
Show Gist options
  • Select an option

  • Save itsyosefali/63e9fbae852e44b9f06a124843bb6d2e to your computer and use it in GitHub Desktop.

Select an option

Save itsyosefali/63e9fbae852e44b9f06a124843bb6d2e to your computer and use it in GitHub Desktop.
تقرير المبيعات اليومي
branch=""
if filters.get("branch"):
escaped_input = frappe.db.escape(filters.get("branch"))
branch = f" Where `tabSales Invoice`.branch = {escaped_input}"
mode_of_payment=""
if filters.get("mode_of_payment"):
escaped_input = frappe.db.escape(filters.get("mode_of_payment"))
mode_of_payment = f" AND `tabPayment Entry`.mode_of_payment = {escaped_input}"
sql_day_date_cond = ""
if filters.get("day_date"):
day_date = frappe.db.escape(filters.get("day_date"))
sql_day_date_cond = f" and `tabSales Invoice`.posting_date = {day_date}"
res = frappe.db.sql(f"""select
`tabSales Invoice`.name,
`tabSales Invoice`.customer,
`tabSales Invoice`.branch,
`tabPayment Entry`.name As 'Name',
`tabPayment Entry`.paid_amount,
`tabPayment Entry`.mode_of_payment,
`tabSales Invoice`.total,
`tabPayment Entry`.owner,
`tabSales Invoice`.posting_date,
`tabSales Invoice`.party_account_currency
from `tabPayment Entry Reference`
inner join `tabPayment Entry`
on `tabPayment Entry Reference`.parent = `tabPayment Entry`.name
inner join `tabSales Invoice`
on `tabPayment Entry Reference`.reference_name = `tabSales Invoice`.name
{branch}
{mode_of_payment}
{sql_day_date_cond}
""", as_dict=True)
result = res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment