Support #807
openAccounting quarterly report
0%
Description
Using the code created in ticket 806, please optimize it and create a .pl script and cron job to run it quarterly. The date ranges to query for will be Jan 1- March 31; April 1 - June 30; July 1 - September 30; October 1 - December 31. the report will need to rescheduled for 12:30A on the first day of each quarter for the previous quarter's data. Upon completion, the report and email subject line should be Quarterly Policy List <dates covered> ie "Quarterly Policy List Jan 1 2025 - March 31 2025". Upon completion, the report should be emailed to Tina.henry@nfp.com
Code to optimize:
SELECT pd.policy_num,
p.user_id,
CONCAT(pdvr.first_name, ' ', pdvr.last_name) AS client_name,
un.company_name AS carrier_name,
pc.underwriter_premium AS carrier_premium,
pc.opt_travel_premium AS mexvisit_premium,
pc.evac_premium AS tme_premium,
DATE_FORMAT(FROM_UNIXTIME(pd.sales_time), '%Y-%m') AS sales_date,
afd.business_name AS affiliate_name,
af.full_affid AS affiliate_id,
NULL AS producer_commission_amount,
ac.agent_premium AS affiliate_commission_rate,
pdvr.city AS billing_city,
s.name AS billing_state,
pdvr.zip AS billing_postalcode,
NULL AS classification,
CASE
WHEN p.leave_date < UNIX_TIMESTAMP() THEN 'Expired'
ELSE 'Active'
END AS policy_status
FROM policydetails pd
JOIN policies p ON pd.policy_id = p.id
JOIN underwriters un ON pd.underwriter_id = un.id
LEFT JOIN (
SELECT policy_id,
MAX(underwriter_premium) AS underwriter_premium,
MAX(opt_travel_premium) AS opt_travel_premium,
MAX(evac_premium) AS evac_premium
FROM policyCosts
GROUP BY policy_id
) pc ON pd.policy_id = pc.policy_id
LEFT JOIN (
SELECT aff_id, underwriter_id, sales_type, MAX(agent_premium) AS agent_premium
FROM affComm
GROUP BY aff_id, underwriter_id, sales_type
) ac ON p.aff_id = ac.aff_id AND pd.underwriter_id = ac.underwriter_id AND pd.sales_type = ac.sales_type
JOIN affDetails afd ON p.aff_id = afd.aff_id
JOIN policydrivers pdvr ON pd.policy_id = pdvr.policy_id AND pdvr.isowner = 1
JOIN states s ON pdvr.state = s.id
JOIN aff af ON p.aff_id = af.id
WHERE pd.sales_time >= 1704067200
AND pd.sales_time < 1735680000;
Files
Updated by Leo Esaki about 2 months ago
- Status changed from In Progress to QA
- Assignee changed from Leo Esaki to George Howington
Hi George.
I created a new cron job for quarterly sales report. Please take a look.
https://gitlab.com/nfp-cross-border/polmaker-v3/-/merge_requests/387
Best,
Leo
Updated by George Howington 14 days ago
- File clipboard-202504141818-fo2xk.png clipboard-202504141818-fo2xk.png added
- File clipboard-202504141821-ulmun.png clipboard-202504141821-ulmun.png added
- Status changed from QA to In Progress
- Assignee changed from George Howington to Leo Esaki
Hi Leo,
Thank you for fixing the report issue. I've discovered two more problems.
(1) When running the report for 4/1/2025, the first policy reported is from 12/31/2024
08:40:55 MST. Please see the image below
(2) All the reported 'sales dates' are pressing as "Thu Jan 1 00:33:44 1970". See image below.
(3) The report ends with policy 20173042, which is on the 30th. The final day for the report is missing.
Please let me know if you have any questions. Thank you.
--George