Update ai exports

This commit is contained in:
Michał Zieliński
2025-09-15 19:40:04 +02:00
parent f9b7c2462b
commit 91e6a206cb

View File

@@ -1,5 +1,6 @@
<?php
function sendInvoice($record) {
function sendInvoice($record)
{
require_once('modules/EcmInvoiceOuts/EcmInvoiceOut.php');
$inv = new EcmInvoiceOut();
$inv->retrieve($record);
@@ -17,7 +18,9 @@ function sendInvoice($record) {
);
echo json_encode($response);
}
function sendProduct($record) {
function sendProduct($record)
{
require_once('modules/EcmProducts/EcmProduct.php');
$prod = new EcmProduct();
$prod->retrieve($record);
@@ -32,7 +35,9 @@ function sendProduct($record) {
);
echo json_encode($response);
}
function copySaleFromTwinpol($record) {
function copySaleFromTwinpol($record)
{
$db = $GLOBALS['db'];
// check if sale exists
@@ -50,7 +55,10 @@ function copySaleFromTwinpol($record) {
$gotAllProducts = true; // hope :)
$newPositionList = array();
$total_netto = 0; $total_brutto = 0; $total_discount = 0; $vats = array();
$total_netto = 0;
$total_brutto = 0;
$total_discount = 0;
$vats = array();
foreach ($sale->position_list as $product) {
echo 'Produkt: ' . $product->product_code;
$p = getProduct(trim($product->product_code));
@@ -209,7 +217,8 @@ ILN: ".$sale->shipping_iln;
}
// local helpers
function getProduct($code) {
function getProduct($code)
{
$db = $GLOBALS['db'];
$res = $db->fetchByAssoc($db->query("SELECT * FROM ecmproducts WHERE code='$code' AND deleted=0"));
if (!$res) {
@@ -222,7 +231,8 @@ function getProduct($code) {
}
}
function makeCUrlRequest($url) {
function makeCUrlRequest($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl, CURLOPT_VERBOSE, 1);
@@ -233,7 +243,8 @@ function makeCUrlRequest($url) {
return curl_exec($curl);
}
function brecho($msg) {
function brecho($msg)
{
echo '<br><br>';
var_dump($msg);
echo '<br><br>';
@@ -497,13 +508,50 @@ ORDER BY i.register_date DESC;
SELECT
ss.product_code,
ss.product_name,
ss.product_id,
COALESCE(NULLIF(ss.quantity, ''), 0) AS quantity,
s.name
s.name,
COALESCE(si.ordered_quantity, 0) AS ordered_quantity
FROM ecmstockstates AS ss
JOIN ecmstocks AS s ON ss.stock_id = s.id
LEFT JOIN (
SELECT
i.ecmproduct_id,
SUM(i.quantity) AS ordered_quantity
FROM ecmsaleitems AS i
JOIN ecmsales AS es ON es.id = i.ecmsale_id
WHERE es.status IN ('s10','s20','s30')
GROUP BY i.ecmproduct_id
) AS si ON si.ecmproduct_id = ss.product_id
ORDER BY quantity + 0 DESC;",
'filename' => 'stocks.csv',
],// stocks
[
'sql' => "
SELECT
i.code AS product_code,
i.name AS product_name,
i.quantity,
i.price_netto,
es.document_no,
CASE es.status
WHEN 's10' THEN 'Planowany'
WHEN 's20' THEN 'Oczekujący'
WHEN 's30' THEN 'Zaakceptowany'
ELSE 'Nieznane'
END AS status,
es.register_date,
es.delivery_date,
es.send_date
FROM ecmsaleitems AS i
JOIN ecmsales AS es ON es.id = i.ecmsale_id
WHERE es.status IN ('s10','s20','s30')
AND es.deleted = '0'
AND i.deleted = '0'
ORDER BY es.register_date DESC, i.position;
",
'filename' => 'sales.csv',
], //sales
];
$report = [];
@@ -528,6 +576,7 @@ ORDER BY i.register_date DESC;
exit;
}
}
function exportToCSVFile($res, $fullpath, array $headers = null, $delimiter = ';', $withBom = true)
{
$db = $GLOBALS['db'];
@@ -574,14 +623,18 @@ function exportToCSVFile($res, $fullpath, array $headers = null, $delimiter = ';
// zapisz pierwszy wiersz w kolejności nagłówków
$line = [];
foreach ($headers as $h) { $line[] = isset($first[$h]) ? $first[$h] : ''; }
foreach ($headers as $h) {
$line[] = isset($first[$h]) ? $first[$h] : '';
}
fputcsv($fp, $line, $delimiter);
$count = 1;
// pozostałe wiersze
while ($row = $db->fetchByAssoc($res)) {
$line = [];
foreach ($headers as $h) { $line[] = isset($row[$h]) ? $row[$h] : ''; }
foreach ($headers as $h) {
$line[] = isset($row[$h]) ? $row[$h] : '';
}
fputcsv($fp, $line, $delimiter);
$count++;
}