2018-02-04 09:41:46 +01:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
2018-02-04 09:41:46 +01:00
include_once __DIR__ . '/../../../core.php' ;
switch ( $resource ) {
case 'conti' :
2020-08-11 17:56:53 +02:00
$query = 'SELECT co_pianodeiconti2.* FROM co_pianodeiconti2 LEFT JOIN co_pianodeiconti3 ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id |where| GROUP BY co_pianodeiconti2.id ORDER BY co_pianodeiconti2.numero ASC, co_pianodeiconti3.numero ASC' ;
2018-04-12 15:31:22 +02:00
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 = '' ;
2018-04-12 15:31:22 +02:00
}
$query = str_replace ( '|where|' , $wh , $query );
2018-02-04 09:41:46 +01:00
$rs = $dbo -> fetchArray ( $query );
foreach ( $rs as $r ) {
$results [] = [ 'text' => $r [ 'numero' ] . ' ' . $r [ 'descrizione' ], 'children' => []];
2018-06-01 17:49:55 +02:00
$subquery = 'SELECT co_pianodeiconti3.* FROM co_pianodeiconti3 INNER JOIN co_pianodeiconti2 ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id |where|' ;
2018-02-04 09:41:46 +01:00
$where = [];
$filter = [];
$search_fields = [];
foreach ( $elements as $element ) {
2018-06-23 18:35:08 +02:00
$filter [] = 'co_pianodeiconti3.id=' . prepare ( $element );
2018-02-04 09:41:46 +01:00
}
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 . '%' ) . ')' ;
2018-02-04 09:41:46 +01:00
}
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' ]];
2018-02-04 09:41:46 +01:00
}
}
break ;
case 'conti-vendite' :
2020-08-11 17:56:53 +02:00
$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_pianodeiconti2.numero ASC, co_pianodeiconti3.numero ASC " ;
2018-02-04 09:41:46 +01:00
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' " ;
2018-02-04 09:41:46 +01:00
if ( ! empty ( $search )) {
2018-06-01 17:49:55 +02:00
$search_fields [] = " CONCAT( co_pianodeiconti2.numero, '.', co_pianodeiconti3.numero, ' ', co_pianodeiconti3.descrizione ) LIKE " . prepare ( '%' . $search . '%' );
2018-02-04 09:41:46 +01:00
}
break ;
case 'conti-acquisti' :
2020-08-11 17:56:53 +02:00
$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_pianodeiconti2.numero ASC, co_pianodeiconti3.numero ASC " ;
2018-02-04 09:41:46 +01:00
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' " ;
2018-02-04 09:41:46 +01:00
if ( ! empty ( $search )) {
2018-06-01 17:49:55 +02:00
$search_fields [] = " CONCAT( co_pianodeiconti2.numero, '.', co_pianodeiconti3.numero, ' ', co_pianodeiconti3.descrizione ) LIKE " . prepare ( '%' . $search . '%' );
2018-02-04 09:41:46 +01:00
}
break ;
2019-04-11 16:04:08 +02:00
case 'conti-modelliprimanota' :
$query = 'SELECT co_pianodeiconti2.* FROM co_pianodeiconti2 LEFT JOIN co_pianodeiconti3 ON co_pianodeiconti3.idpianodeiconti2=co_pianodeiconti2.id |where| GROUP BY co_pianodeiconti2.id' ;
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 ) {
$filter [] = 'co_pianodeiconti3.id=' . prepare ( $element );
}
if ( ! empty ( $filter )) {
$where [] = '(' . implode ( ' OR ' , $filter ) . ')' ;
}
$where [] = 'idpianodeiconti2=' . prepare ( $r [ 'id' ]);
if ( ! empty ( $search )) {
$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 ) {
$results [ count ( $results ) - 1 ][ 'children' ][] = [ 'id' => $r2 [ 'id' ], 'text' => $r [ 'numero' ] . '.' . $r2 [ 'numero' ] . ' ' . $r2 [ 'descrizione' ]];
}
$results [] = [ 'text' => 'Conto cliente/fornitore fattura' , 'children' => []];
$results [ count ( $results ) - 1 ][ 'children' ][] = [ 'id' => '-1' , 'text' => '{Conto cliente/fornitore fattura}' ];
}
break ;
2018-02-04 09:41:46 +01:00
}