Skip to content

Instantly share code, notes, and snippets.

@AhmedSamy
Created June 28, 2019 12:06
Show Gist options
  • Save AhmedSamy/b1d3f7e84a90dc1b5291b75d8211ae2b to your computer and use it in GitHub Desktop.
Save AhmedSamy/b1d3f7e84a90dc1b5291b75d8211ae2b to your computer and use it in GitHub Desktop.
Publish messages manually
SELECT
CONCAT(
'bin/console ozean12:amqp:produce-message invoice.invoice_approved --payload=\'{
"uuid":"',w.uuid,'",
"customer_uuid":"',c.uuid,'",
"company_rating":"',cs.`internal_rating`,'",
"debtor_uuid":"',cd.`uuid`,'",
"debtor_name":"',debtor_snapshot.name,'",
"invoice_number":"',w.`invoice_external_nr`,'",
"discount_rate":"',w.`discount_rate`,'",
"offered_amount_gross":"',w.amount,'",
"offered_amount_net":"',w.net_amount,'",
"approved_date":"',DATE_FORMAT(NOW(),'%Y-%m-%d'),'",
"due_date":"',DATE_FORMAT(w.`due_date`,'%Y-%m-%d'),'",
"buyback_date":"",
"fee_calculation_strategy":"',fp.`fee_calculation_strategy`,'"}\'
')
FROM `webapp`.invoices w
LEFT JOIN `company_snapshots` cs ON cs.id = w.`customer_company_snapshot_id`
LEFT JOIN companies c ON c.id = cs.company_id
LEFT JOIN `customers_debtors` cd ON cd.`customer_id` = c.id AND cd.`debtor_id` = w.`debtor_company_id`
LEFT JOIN companies debtor ON debtor.id = w.`debtor_company_id`
LEFT JOIN `company_snapshots` debtor_snapshot ON debtor_snapshot.company_id = debtor.id AND debtor_snapshot.is_current=1
LEFT JOIN `invoice_factoring_plans` ifp ON ifp.invoice_id = w.id
LEFT JOIN `factoring_plans` fp ON fp.id = ifp.`factoring_plan_id`
WHERE
w.state NOT IN ("new", "data_finalized", "risk_checks_passed","financing_requested", "financing_rejected", "canceled")
AND
w.uuid NOT IN
(
SELECT DISTINCT b.uuid
FROM `borscht`.tickets b
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment