Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW: tool for converting pure SQL into PHP code for Dolibar #2

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

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 ?

@atm-john
Copy link
Member

@eldy yes

@atm-john
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....

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.

None yet

3 participants