Skip to content

Conversation

@atm-florianm
Copy link

@atm-florianm atm-florianm commented Apr 19, 2024

This is a very basic javascript tool that takes a pretty-printed pure SQL query (with llx_ etc.) and spurts PHP that you can directly copy-paste into your Dolibarr code. It keeps your line breaks and indentation to keep it readable.

Input:

SELECT product.ref, COUNT(product.ref) AS nb, SUM(tl.total_ht) AS total, AVG(tl.total_ht) AS avg
FROM llx_propal AS p,
     llx_propaldet AS tl,
     llx_product AS product
         INNER JOIN llx_societe_commerciaux AS sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = 1
WHERE p.entity IN (1)
  AND p.rowid = tl.fk_propal
  AND tl.fk_product = product.rowid
  AND p.datep BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59'
GROUP BY product.ref
ORDER BY nb DESC;

Output:

$sql = /** @lang SQL */
     "SELECT product.ref, COUNT(product.ref) AS nb, SUM(tl.total_ht) AS total, AVG(tl.total_ht) AS avg"
     . " FROM " . $db->prefix() . "propal AS p,"
     . "      " . $db->prefix() . "propaldet AS tl,"
     . "      " . $db->prefix() . "product AS product"
     . "          INNER JOIN " . $db->prefix() . "societe_commerciaux AS sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = 1"
     . " WHERE p.entity IN (1)"
     . "   AND p.rowid = tl.fk_propal"
     . "   AND tl.fk_product = product.rowid"
     . "   AND p.datep BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59'"
     . " GROUP BY product.ref"
     . " ORDER BY nb DESC;";

@eldy
Copy link
Member

eldy commented May 16, 2024

@atm-john Are you ok to be the Official merger of this project ?

@john-botella
Copy link
Member

@eldy yes

@john-botella
Copy link
Member

@atm-florianm Add your code as a tool page
see /tools and tools_list.php

@eldy
Copy link
Member

eldy commented May 17, 2024

@eldy yes

Ok, so i won't follow this repo and let you do it....

@atm-florianm
Copy link
Author

Sorry about the long delay; I'm still intent on completing this PR, I'm just not finding the necessary time at the moment.
I'll eventually do it :)

@thersane-john
Copy link
Contributor

Still alive ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants