openstamanager/modules/partitario/ajax/select.php

88 lines
3.9 KiB
PHP
Raw Normal View History

<?php
include_once __DIR__.'/../../../core.php';
switch ($resource) {
case 'conti':
$query = 'SELECT co_pianodeiconti2.* FROM co_pianodeiconti2 LEFT JOIN co_pianodeiconti3 ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id |where| GROUP BY co_pianodeiconti2.id';
2018-06-23 18:35:08 +02:00
if ($search != '') {
$wh = 'WHERE (co_pianodeiconti3.descrizione LIKE '.prepare('%'.$search.'%')." OR CONCAT( co_pianodeiconti2.numero, '.', co_pianodeiconti3.numero ) LIKE ".prepare('%'.$search.'%').')';
} else {
$wh = '';
}
$query = str_replace('|where|', $wh, $query);
$rs = $dbo->fetchArray($query);
foreach ($rs as $r) {
$results[] = ['text' => $r['numero'].' '.$r['descrizione'], 'children' => []];
$subquery = 'SELECT co_pianodeiconti3.* FROM co_pianodeiconti3 INNER JOIN co_pianodeiconti2 ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id |where|';
$where = [];
$filter = [];
$search_fields = [];
foreach ($elements as $element) {
2018-06-23 18:35:08 +02:00
$filter[] = 'co_pianodeiconti3.id='.prepare($element);
}
if (!empty($filter)) {
$where[] = '('.implode(' OR ', $filter).')';
}
$where[] = 'idpianodeiconti2='.prepare($r['id']);
if (!empty($search)) {
2018-07-09 17:21:25 +02:00
$search_fields[] = '(co_pianodeiconti3.descrizione LIKE '.prepare('%'.$search.'%')." OR CONCAT(co_pianodeiconti2.numero, '.', co_pianodeiconti3.numero) LIKE ".prepare('%'.$search.'%').')';
}
if (!empty($search_fields)) {
$where[] = '('.implode(' OR ', $search_fields).')';
}
$wh = '';
if (count($where) != 0) {
$wh = 'WHERE '.implode(' AND ', $where);
}
$subquery = str_replace('|where|', $wh, $subquery);
$rs2 = $dbo->fetchArray($subquery);
foreach ($rs2 as $r2) {
2018-06-23 18:35:08 +02:00
$results[count($results) - 1]['children'][] = ['id' => $r2['id'], 'text' => $r['numero'].'.'.$r2['numero'].' '.$r2['descrizione']];
}
}
break;
case 'conti-vendite':
$query = "SELECT co_pianodeiconti3.id, CONCAT( co_pianodeiconti2.numero, '.', co_pianodeiconti3.numero, ' ', co_pianodeiconti3.descrizione ) AS descrizione FROM co_pianodeiconti3 INNER JOIN (co_pianodeiconti2 INNER JOIN co_pianodeiconti1 ON co_pianodeiconti2.idpianodeiconti1=co_pianodeiconti1.id) ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id |where| ORDER BY co_pianodeiconti3.numero ASC";
foreach ($elements as $element) {
$filter[] = 'co_pianodeiconti3.id='.prepare($element);
}
$where[] = "co_pianodeiconti1.descrizione='Economico'";
2018-05-11 18:41:37 +02:00
$where[] = "co_pianodeiconti2.dir='entrata'";
if (!empty($search)) {
$search_fields[] = "CONCAT( co_pianodeiconti2.numero, '.', co_pianodeiconti3.numero, ' ', co_pianodeiconti3.descrizione ) LIKE ".prepare('%'.$search.'%');
}
break;
case 'conti-acquisti':
$query = "SELECT co_pianodeiconti3.id, CONCAT( co_pianodeiconti2.numero, '.', co_pianodeiconti3.numero, ' ', co_pianodeiconti3.descrizione ) AS descrizione FROM co_pianodeiconti3 INNER JOIN (co_pianodeiconti2 INNER JOIN co_pianodeiconti1 ON co_pianodeiconti2.idpianodeiconti1=co_pianodeiconti1.id) ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id |where| ORDER BY co_pianodeiconti3.numero ASC";
foreach ($elements as $element) {
$filter[] = 'co_pianodeiconti3.id='.prepare($element);
}
$where[] = "co_pianodeiconti1.descrizione='Economico'";
2018-05-11 18:41:37 +02:00
$where[] = "co_pianodeiconti2.dir='uscita'";
if (!empty($search)) {
$search_fields[] = "CONCAT( co_pianodeiconti2.numero, '.', co_pianodeiconti3.numero, ' ', co_pianodeiconti3.descrizione ) LIKE ".prepare('%'.$search.'%');
}
break;
}