Fatturazione in bulk degli interventi, aggiunta possibilità di specificare se aggiungere l'intervento alle fatture in stato bozza

This commit is contained in:
Luca 2018-07-23 12:57:46 +02:00
parent 8256bb3718
commit 10ba6960df
1 changed files with 25 additions and 11 deletions

View File

@ -62,7 +62,8 @@ switch (post('op')) {
$data = date('Y-m-d');
$dir = 'entrata';
$idtipodocumento = '2';
$accodare = post('accodare');
if (empty($_SESSION['m'.Modules::get('Fatture di vendita')['id']]['id_segment'])) {
$rs = $dbo->fetchArray('SELECT id FROM zz_segments WHERE predefined = 1 AND id_module = '.prepare(Modules::get('Fatture di vendita')['id']).'LIMIT 0,1');
$_SESSION['m'.Modules::get('Fatture di vendita')['id']]['id_segment'] = $rs[0]['id'];
@ -73,6 +74,7 @@ switch (post('op')) {
$numero = get_new_numerofattura($data);
$numero_esterno = get_new_numerosecondariofattura($data);
$idconto = get_var('Conto predefinito fatture di vendita');
$campo = ($dir == 'entrata') ? 'idpagamento_vendite' : 'idpagamento_acquisti';
@ -107,11 +109,21 @@ switch (post('op')) {
$rs = $dbo->fetchArray($q);
if (count($rs) > 0) {
//al primo ciclo preparo la fattura
if ($n_interventi == 0) {
//verifico se ho già fatture nello stato bozza per questo cliente
$iddocumento = $dbo->fetchArray('SELECT co_documenti.id AS iddocumento FROM co_documenti INNER JOIN co_statidocumento ON co_documenti.idstatodocumento = co_statidocumento.id WHERE co_statidocumento.descrizione = \'Bozza\' AND idanagrafica = '.prepare($idanagrafica))[0]['iddocumento'];
//preparo fattura
$dbo->query('INSERT INTO co_documenti (numero, numero_esterno, idanagrafica, idconto, idtipodocumento, idpagamento, data, idstatodocumento, idsede, id_segment) VALUES ('.prepare($numero).', '.prepare($numero_esterno).', '.prepare($idanagrafica).', '.prepare($idconto).', '.prepare($idtipodocumento).', '.prepare($idpagamento).', '.prepare($data).", (SELECT `id` FROM `co_statidocumento` WHERE `descrizione`='Bozza'), (SELECT idsede_fatturazione FROM an_anagrafiche WHERE idanagrafica=".prepare($idanagrafica).'), '.prepare($id_segment).')');
$iddocumento = $dbo->lastInsertedID();
if (empty($iddocumento) OR empty($accodare)){
$dbo->query('INSERT INTO co_documenti (numero, numero_esterno, idanagrafica, idconto, idtipodocumento, idpagamento, data, idstatodocumento, idsede, id_segment) VALUES ('.prepare($numero).', '.prepare($numero_esterno).', '.prepare($idanagrafica).', '.prepare($idconto).', '.prepare($idtipodocumento).', '.prepare($idpagamento).', '.prepare($data).", (SELECT `id` FROM `co_statidocumento` WHERE `descrizione`='Bozza'), (SELECT idsede_fatturazione FROM an_anagrafiche WHERE idanagrafica=".prepare($idanagrafica).'), '.prepare($id_segment).')');
$iddocumento = $dbo->lastInsertedID();
}else{
$numero_esterno = $dbo->fetchArray('SELECT numero_esterno FROM co_documenti WHERE id = '.prepare($iddocumento))[0]['numero_esterno'];
}
}
++$n_interventi;
@ -205,17 +217,17 @@ switch (post('op')) {
}
if ($n_interventi > 0) {
$_SESSION['infos'][] = tr('Fattura _NUM_ creata!', [
$_SESSION['infos'][] = tr('Fattura _NUM_.', [
'_NUM_' => $numero_esterno,
]);
$_SESSION['infos'][] = tr('_NUM_ interventi fatturati!', [
$_SESSION['infos'][] = tr('_NUM_ interventi fatturati.', [
'_NUM_' => $n_interventi,
]);
} else {
$_SESSION['warnings'][] = tr('Nessuna attività fatturata!');
$_SESSION['warnings'][] = tr('Nessuna attività fatturata.');
}
break;
}
@ -223,8 +235,9 @@ return [
'export-bulk' => [
'text' => tr('Esporta stampe'),
'data' => [
'msg' => tr('Vuoi davvero esportare queste stampe in un archivio?'),
'button' => tr('Procedi'),
'title' => tr('Vuoi davvero esportare queste stampe in un archivio?'),
'msg' => '',
'button' => tr('Crea archivio'),
'class' => 'btn btn-lg btn-warning',
'blank' => true,
],
@ -233,8 +246,9 @@ return [
'creafatturavendita' => [
'text' => tr('Crea fattura'),
'data' => [
'msg' => tr('Vuoi davvero generare le fatture per questi interventi?'),
'button' => tr('Procedi'),
'title' => tr("Vuoi davvero generare le fatture per questi interventi?"),
'msg' => '<br><lablel for=\'accodare\' >'.tr("Aggiungere alle fatture esistenti non ancora emesse?").'</label>&nbsp;<input type=\'checkbox\' name=\'accodare\' value=\'1\' checked id=\'accodare\' onclick = \' if ($(this).is(":checked")) { $(this).val(1); } else { $(this).val(0); }; \' >',
'button' => tr('Crea fatture'),
'class' => 'btn btn-lg btn-warning',
'blank' => false,
],