2020-07-06 13:19:20 +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/>.
|
|
|
|
*/
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2020-07-06 14:16:16 +02:00
|
|
|
include_once __DIR__.'/../../core.php';
|
2020-07-06 13:19:20 +02:00
|
|
|
|
|
|
|
use Modules\DDT\DDT;
|
2024-03-01 11:32:13 +01:00
|
|
|
use Modules\DDT\Stato as StatoDDT;
|
2024-03-22 15:52:24 +01:00
|
|
|
use Modules\Ordini\Ordine;
|
2024-03-01 11:32:13 +01:00
|
|
|
use Modules\Ordini\Stato as StatoOrdine;
|
2020-07-06 13:19:20 +02:00
|
|
|
|
|
|
|
// Informazioni generali sulla riga
|
|
|
|
$source_type = filter('riga_type');
|
|
|
|
$source_id = filter('riga_id');
|
2020-07-06 14:16:16 +02:00
|
|
|
if (empty($source_type) || empty($source_id)) {
|
2020-07-06 13:19:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$source = $source_type::find($source_id);
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<p>'.tr('Informazioni per i riferimenti di: _DESC_', [
|
|
|
|
'_DESC_' => $source->descrizione,
|
|
|
|
]).'</p>
|
|
|
|
|
|
|
|
<div id="righe_riferimenti">';
|
|
|
|
|
|
|
|
include_once __DIR__.'/righe_riferimenti.php';
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="alert alert-info" id="box-loading-riferimenti">
|
|
|
|
<i class="fa fa-spinner fa-spin"></i> '.tr('Caricamento in corso').'...
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
$documenti_disponibili = collect();
|
2020-09-22 20:28:37 +02:00
|
|
|
$direzione_richiesta = $source->getDocument()->direzione == 'entrata' ? 'uscita' : 'entrata';
|
2020-07-06 13:19:20 +02:00
|
|
|
|
|
|
|
// Individuazione DDT disponibili
|
|
|
|
$ddt = DDT::whereHas('stato', function ($query) {
|
2024-04-18 17:44:05 +02:00
|
|
|
$id_stato = (new StatoDDT())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id);
|
2024-03-01 11:32:13 +01:00
|
|
|
$query->where('id', '!=', $id_stato);
|
2020-07-06 14:16:16 +02:00
|
|
|
})->whereHas('tipo', function ($query) use ($direzione_richiesta) {
|
2020-07-06 13:19:20 +02:00
|
|
|
$query->where('dir', '=', $direzione_richiesta);
|
|
|
|
})->get();
|
|
|
|
foreach ($ddt as $elemento) {
|
|
|
|
$documenti_disponibili->push([
|
|
|
|
'id' => get_class($elemento).'|'.$elemento->id,
|
2020-10-15 17:00:43 +02:00
|
|
|
'text' => $elemento->getReference(1),
|
|
|
|
'optgroup' => tr('Ddt in ').$source->getDocument()->direzione,
|
2020-07-06 13:19:20 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Individuazione ordini disponibili
|
2020-10-15 17:00:43 +02:00
|
|
|
$tipo_ordini = $direzione_richiesta == 'entrata' ? 'cliente' : 'fornitore';
|
2020-07-06 13:19:20 +02:00
|
|
|
$ordini = Ordine::whereHas('stato', function ($query) {
|
2024-04-18 17:44:05 +02:00
|
|
|
$id_stato = (new StatoOrdine())->getByField('title', 'Bozza', Models\Locale::getPredefined()->id);
|
2024-03-01 11:32:13 +01:00
|
|
|
$query->where('id', '!=', $id_stato);
|
2023-01-17 15:07:50 +01:00
|
|
|
})->whereHas('tipo', function ($query) use ($direzione_richiesta) {
|
|
|
|
$query->where('dir', '=', $direzione_richiesta);
|
2020-07-06 13:19:20 +02:00
|
|
|
})->get();
|
|
|
|
foreach ($ordini as $elemento) {
|
|
|
|
$documenti_disponibili->push([
|
|
|
|
'id' => get_class($elemento).'|'.$elemento->id,
|
2020-10-15 17:00:43 +02:00
|
|
|
'text' => $elemento->getReference(1),
|
|
|
|
'optgroup' => tr('Ordini ').$tipo_ordini,
|
2020-07-06 13:19:20 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="box">
|
|
|
|
<div class="box-header">
|
|
|
|
<h3 class="box-title">'.tr('Nuovo riferimento').'</h3>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="box-body">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-12">
|
|
|
|
{[ "type": "select", "label": "'.tr('Documento').'", "name": "documento_riferimento", "required": 1, "values": '.$documenti_disponibili->toJson().' ]}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="righe_documento"></div>
|
|
|
|
|
|
|
|
<div class="alert alert-info" id="box-loading">
|
|
|
|
<i class="fa fa-spinner fa-spin"></i> '.tr('Caricamento in corso').'...
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
$file = basename(__FILE__);
|
|
|
|
echo '
|
|
|
|
<script>$(document).ready(init)</script>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
$(document).ready(function(){
|
|
|
|
$("#box-loading").hide();
|
|
|
|
$("#box-loading-riferimenti").hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
var riferimenti = JSON.parse(\''.json_encode($elenco_riferimenti).'\');
|
|
|
|
var source_type = "'.addslashes($source_type).'";
|
|
|
|
var source_id = "'.$source_id.'";
|
|
|
|
|
|
|
|
$("#documento_riferimento").on("change", function(){
|
2020-10-16 17:23:44 +02:00
|
|
|
let value = $(this).val();
|
2020-07-06 13:19:20 +02:00
|
|
|
if (value) {
|
2020-10-16 17:23:44 +02:00
|
|
|
let pieces = value.split("|");
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2020-10-16 17:23:44 +02:00
|
|
|
let type = pieces[0];
|
|
|
|
let id = pieces[1];
|
2020-07-06 13:19:20 +02:00
|
|
|
caricaRighe(type, id);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function caricaRiferimenti() {
|
2020-10-16 17:23:44 +02:00
|
|
|
let loader = $("#box-loading-riferimenti");
|
|
|
|
let content = $("#righe_riferimenti");
|
2020-07-06 13:19:20 +02:00
|
|
|
|
|
|
|
loader.show();
|
|
|
|
|
|
|
|
content.html("");
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
cache: false,
|
|
|
|
type: "GET",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
id_record: globals.id_record,
|
|
|
|
op: "visualizza_righe_riferimenti",
|
|
|
|
source_type: source_type,
|
|
|
|
source_id: source_id,
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
loader.hide();
|
|
|
|
|
|
|
|
content.html(data);
|
|
|
|
$("#documento_riferimento").trigger("change");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function caricaRighe(tipo_documento, id_documento){
|
2020-10-16 17:23:44 +02:00
|
|
|
let content = $("#righe_documento");
|
|
|
|
let loader = $("#box-loading");
|
2020-07-06 13:19:20 +02:00
|
|
|
|
|
|
|
loader.show();
|
|
|
|
content.html("");
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
cache: false,
|
|
|
|
type: "GET",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
id_record: globals.id_record,
|
|
|
|
op: "visualizza_righe_documento",
|
|
|
|
source_type: source_type,
|
|
|
|
source_id: source_id,
|
|
|
|
id_documento: id_documento,
|
|
|
|
tipo_documento: tipo_documento,
|
|
|
|
riferimenti: riferimenti,
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
loader.hide();
|
|
|
|
|
|
|
|
content.html(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function salvaRiferimento(btn, source_type, source_id) {
|
|
|
|
$("#main_loading").show();
|
|
|
|
|
2020-10-16 17:23:44 +02:00
|
|
|
let row = $(btn).closest("tr");
|
|
|
|
let target_type = row.data("type");
|
|
|
|
let target_id = row.data("id");
|
2020-07-06 13:19:20 +02:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
cache: false,
|
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
id_record: globals.id_record,
|
|
|
|
op: "salva_riferimento_riga",
|
|
|
|
source_type: source_type,
|
|
|
|
source_id: source_id,
|
|
|
|
target_type: target_type,
|
|
|
|
target_id: target_id,
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$("#main_loading").fadeOut();
|
|
|
|
|
|
|
|
// Aggiunta del riferimento in memoria
|
2020-10-16 17:23:44 +02:00
|
|
|
let riferimento_locale = target_type + "|" + target_id;
|
2020-07-06 13:19:20 +02:00
|
|
|
riferimenti.push(riferimento_locale);
|
|
|
|
|
|
|
|
$(btn).removeClass("btn-info").addClass("btn-success");
|
|
|
|
|
|
|
|
caricaRiferimenti();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-18 17:46:38 +01:00
|
|
|
function rimuoviRiferimento(btn, source_type, source_id, idriferimento) {
|
2020-07-06 13:19:20 +02:00
|
|
|
$("#main_loading").show();
|
|
|
|
|
2020-10-16 17:23:44 +02:00
|
|
|
let row = $(btn).closest("tr");
|
|
|
|
let target_type = row.data("type");
|
|
|
|
let target_id = row.data("id");
|
2020-07-06 13:19:20 +02:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: globals.rootdir + "/actions.php",
|
|
|
|
cache: false,
|
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
id_module: globals.id_module,
|
|
|
|
id_record: globals.id_record,
|
|
|
|
op: "rimuovi_riferimento_riga",
|
|
|
|
source_type: source_type,
|
|
|
|
source_id: source_id,
|
|
|
|
target_type: target_type,
|
|
|
|
target_id: target_id,
|
2021-02-18 17:46:38 +01:00
|
|
|
idriferimento: idriferimento,
|
2020-07-06 13:19:20 +02:00
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$("#main_loading").fadeOut();
|
|
|
|
|
|
|
|
// Rimozione del riferimento dalla memoria
|
2020-10-16 17:23:44 +02:00
|
|
|
let riferimento_locale = target_type + "|" + target_id;
|
|
|
|
let index = riferimenti.indexOf(riferimento_locale);
|
2020-07-06 13:19:20 +02:00
|
|
|
if (index > -1) {
|
2020-10-16 17:23:44 +02:00
|
|
|
riferimenti.splice(index, 1);
|
2020-07-06 13:19:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
caricaRiferimenti();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>';
|