Flat Zoho Books invoice view in Zoho Analytics with "Skonto" and "Storno" detection (cash discount/cancellation)
if you are trying to compile and analyze Zoho Finance invoice data in Zoho Analtics, we at CEYOND are sure this SQL query snippet can help you.
It will collate the invoices, payments, credit notes and sales. It is important that the tables from Zoho Finance and Zoho CRM are in the same workspace.
For the European and German speaking countries the view also contains two special features:
- Skonto (cash discount) detection based on a discount of 3%.
- Storno (invoice cancellation) detection based on existing 100% credit notes
We hope it helps you!
- SELECT
- i."Invoice Date" "Invoice Date",
- i."Invoice Number" "Invoice Number",
- c."Customer Name" "Customer Name",
- d."Deal Name" "Deal Name",
- if(i."Sub Total (BCY)" = i."Write Off Amount (BCY)", 'Write Off', if(i."Sub Total (BCY)" = ic."CreditNotes Sub (BCY)", 'Cancel', i."Invoice Status")) "Invoice Status",
- i."Sub Total (BCY)" "Sub Total (BCY)",
- i."Total (BCY)" "Total (BCY)",
- i."Discount (%)" "Discount (%)",
- i."Leistungszeitraum" "Leistungszeitraum",
- i."Purchase Order#" "Purchase Order#",
- concat('https://books.zoho.eu/app/200XXXXX#/invoices/', i."Invoice ID") "Invoice Link",
- concat('https://crm.zoho.eu/crm/orgXXXXXXX/tab/Potentials/', i."CRM Potential ID") "Deal Link",
- if(i."Discount (%)" = 3, i."Discount Amount", 0) "Skonto Amount",
- if(i."Discount (%)" = 3, 0, if(i."Discount Amount" = 0, i."Discount Amount (BCY)", i."Discount Amount")) "Rabatt Amount",
- i."Write Off Amount (BCY)" "Write Off Amount (BCY)",
- i."Balance (BCY)" "Balance (BCY)",
- (i."Total (BCY)" -p."Amount (BCY)") "Payment Diff",
- p."Amount (BCY)" "Payment Amount",
- i."Type" "Type",
- i."Source" "Source",
- i."Due Date" "Due Date",
- i."Expected Payment Date" "Expected Payment Date",
- i."Last Payment Date" "Last Payment Date",
- days_between(i."Last Payment Date", i."Due Date") "Payment Due Days",
- i."Payment Terms" "Payment Terms",
- i."Notes" "Notes",
- i."Terms & Conditions" "Terms & Conditions",
- a."Billing Street" "Billing Street",
- a."Billing City" "Billing City",
- a."Billing Code" "Billing Code",
- a."Billing State" "Billing State",
- a."Billing Country" "Billing Country",
- d."Deal Owner Name" "Deal Owner",
- s."Name" "Sales Person",
- d."Amount" "Deal Amount",
- d."Closing Date" "Deal Closing Date",
- i."Created Time" "Created Time",
- cr."UserName" "CreatedUser",
- i."Last Modified Time" "Last Modified Time",
- mo."UserName" "ModifiedUser",
- i."Invoice ID" "Invoice ID",
- i."CRM Potential ID" "CRM Potential ID"
- FROM Invoices i
- LEFT JOIN Customers c ON (c."Customer ID" = i."Customer ID")
- LEFT JOIN "Deals (Zoho CRM)" d ON (d."Id" = i."CRM Potential ID")
- LEFT JOIN "Sales Persons" s ON (s."Sales Person ID" = i."Sales Person ID")
- LEFT JOIN "Price lists" pr ON (pr."PriceList ID" = i."PriceList ID")
- LEFT JOIN "Subscriptions" su ON (su."Subscription ID" = i."Subscription ID")
- LEFT JOIN "Customer Addresses" a ON (a."Address ID" = i."Address ID")
- LEFT JOIN "Users" cr ON (i."Created By" = cr."User ID")
- LEFT JOIN "Users" mo ON (i."Modified By" = mo."User ID")
- LEFT JOIN( SELECT
- ip."Invoice ID" "Invoice ID",
- sum(ip."Amount (BCY)") "Amount (BCY)"
- FROM "Invoice Payments" ip
- GROUP BY "Invoice ID"
- ) p ON (p."Invoice ID" = i."Invoice ID")
- LEFT JOIN( SELECT
- ii."Invoice ID" "Invoice ID",
- sum(cn."Sub Total (BCY)") "CreditNotes Sub (BCY)",
- sum(cn."Total (BCY)") "CreditNotes Total (BCY)",
- count(1) "CreditNotes Count",
- min(cn."Credit Note Date") "CreditNotes Date First",
- max(cn."Credit Note Date") "CreditNotes Date Last"
- FROM "Creditnotes Invoice" ii
- LEFT JOIN "Credit Notes" cn ON (ii."CreditNotes ID" = cn."CreditNotes ID")
- GROUP BY ii."Invoice ID"
- ) ic ON (ic."Invoice ID" = i."Invoice ID")