openstamanager/modules/pagamenti/ajax/select.php

86 lines
4.0 KiB
PHP
Raw Normal View History

2019-07-22 12:52:48 +02: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/>.
*/
2019-07-22 12:52:48 +02:00
include_once __DIR__.'/../../../core.php';
switch ($resource) {
/*
* Opzioni utilizzate:
* - codice_modalita_pagamento_fe
*/
2019-07-22 12:52:48 +02:00
case 'pagamenti':
2021-09-13 09:30:30 +02:00
// Filtri per banche dell'Azienda
$id_azienda = setting('Azienda predefinita');
2024-02-08 13:10:46 +01:00
$query = "SELECT
`co_pagamenti`.`id`,
2024-04-18 17:44:05 +02:00
CONCAT_WS(' - ', `codice_modalita_pagamento_fe`, `title`) AS descrizione,
2024-02-08 13:10:46 +01:00
`codice_modalita_pagamento_fe`,
`banca_vendite`.`id` AS id_banca_vendite,
CONCAT(`banca_vendite`.`nome`, ' - ', `banca_vendite`.`iban`) AS descrizione_banca_vendite,
`banca_acquisti`.`id` AS id_banca_acquisti,
CONCAT(`banca_acquisti`.`nome`, ' - ', `banca_acquisti`.`iban`) AS descrizione_banca_acquisti,
`banca_cliente`.`id` AS id_banca_cliente
FROM `co_pagamenti`
2024-03-22 15:52:24 +01:00
LEFT JOIN `co_pagamenti_lang` ON (`co_pagamenti_lang`.`id_record` = `co_pagamenti`.`id` AND `co_pagamenti_lang`.`id_lang` = ".prepare(Models\Locale::getDefault()->id).')
2024-02-08 13:10:46 +01:00
LEFT JOIN `co_banche` banca_cliente ON `banca_cliente`.`id_anagrafica` = '.prepare($superselect['idanagrafica']).' AND `banca_cliente`.`deleted_at` IS NULL
LEFT JOIN `co_banche` banca_vendite ON `co_pagamenti`.`idconto_vendite` = `banca_vendite`.`id_pianodeiconti3` AND `banca_vendite`.`id_anagrafica` = '.prepare($id_azienda).' AND `banca_vendite`.`deleted_at` IS NULL
LEFT JOIN `co_banche` banca_acquisti ON `co_pagamenti`.`idconto_acquisti` = `banca_acquisti`.`id_pianodeiconti3` AND `banca_acquisti`.`id_anagrafica` = '.prepare($id_azienda).' AND `banca_acquisti`.`deleted_at` IS NULL
|where|
GROUP BY
2024-04-18 17:44:05 +02:00
`co_pagamenti_lang`.`title` ORDER BY `co_pagamenti_lang`.`title` ASC';
2019-07-22 12:52:48 +02:00
foreach ($elements as $element) {
2024-02-08 13:10:46 +01:00
$filter[] = '`co_pagamenti`.`id` = '.prepare($element);
2019-07-22 12:52:48 +02:00
}
2021-09-01 10:30:18 +02:00
2019-07-22 12:52:48 +02:00
if (!empty($superselect['codice_modalita_pagamento_fe'])) {
2024-02-08 13:10:46 +01:00
$where[] = '`codice_modalita_pagamento_fe` = '.prepare($superselect['codice_modalita_pagamento_fe']);
2019-07-22 12:52:48 +02:00
}
if (!empty($search)) {
2024-02-08 13:10:46 +01:00
$search_fields[] = '`descrizione` LIKE '.prepare('%'.$search.'%');
2019-07-22 12:52:48 +02:00
}
$data = AJAX::selectResults($query, $where,
$filter,
$search_fields,
$limit,
$custom
);
$rs = $data['results'];
foreach ($rs as $k => $r) {
2024-01-15 15:30:45 +01:00
// Controllo metodi di pagamento con ri.ba. solo per i documenti con dir entrata
2023-08-04 14:54:28 +02:00
if ($dbo->fetchOne('SELECT `co_tipidocumento`.`dir` AS dir FROM `co_tipidocumento` WHERE `co_tipidocumento`.`id`='.prepare($superselect['idtipodocumento']))['dir'] == 'entrata') {
$rs[$k] = array_merge($r, [
2023-08-04 14:54:28 +02:00
'text' => (($r['codice_modalita_pagamento_fe'] == 'MP12' && empty($r['id_banca_cliente'])) ? $r['descrizione'].' '.tr('(Informazioni bancarie mancanti)') : $r['descrizione']),
'disabled' => (($r['codice_modalita_pagamento_fe'] == 'MP12' && empty($r['id_banca_cliente'])) ? 1 : 0),
]);
}
}
$results = [
'results' => $rs,
'recordsFiltered' => $data['recordsFiltered'],
];
2019-07-22 12:52:48 +02:00
break;
}