mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-03 01:08:08 +01:00
Gestione modifica righe in row-list documenti
This commit is contained in:
parent
41c2d6e8a0
commit
15793d8161
@ -1133,6 +1133,10 @@ div.tip {
|
|||||||
background-color: #ff851b !important;
|
background-color: #ff851b !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.row-list .form-group {
|
||||||
|
margin-bottom: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Component: Sidebar Mini
|
* Component: Sidebar Mini
|
||||||
|
@ -568,5 +568,103 @@ switch (post('op')) {
|
|||||||
]);
|
]);
|
||||||
flash()->info($message);
|
flash()->info($message);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'add_articolo':
|
||||||
|
$id_articolo = post('id_articolo');
|
||||||
|
$barcode = post('barcode');
|
||||||
|
$dir = 'entrata';
|
||||||
|
|
||||||
|
if (!empty($barcode)) {
|
||||||
|
$id_articolo = $dbo->selectOne('mg_articoli', 'id', ['deleted_at' => null, 'barcode' => $barcode])['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($id_articolo)) {
|
||||||
|
$permetti_movimenti_sotto_zero = setting('Permetti selezione articoli con quantità minore o uguale a zero in Documenti di Vendita');
|
||||||
|
$qta_articolo = $dbo->selectOne('mg_articoli', 'qta', ['id' => $id_articolo])['qta'];
|
||||||
|
|
||||||
|
$originale = ArticoloOriginale::find($id_articolo);
|
||||||
|
|
||||||
|
if ($qta_articolo <= 0 && !$permetti_movimenti_sotto_zero && !$originale->servizio && $dir == 'entrata') {
|
||||||
|
$response['error'] = tr('Quantità a magazzino non sufficiente');
|
||||||
|
echo json_encode($response);
|
||||||
|
} else {
|
||||||
|
$articolo = Articolo::build($contratto, $originale);
|
||||||
|
$qta = 1;
|
||||||
|
|
||||||
|
$articolo->descrizione = $originale->descrizione;
|
||||||
|
$articolo->um = $originale->um;
|
||||||
|
$articolo->qta = 1;
|
||||||
|
$articolo->costo_unitario = $originale->prezzo_acquisto;
|
||||||
|
|
||||||
|
$id_iva = $originale->idiva_vendita ?: setting('Iva predefinita');
|
||||||
|
$id_anagrafica = $contratto->idanagrafica;
|
||||||
|
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
|
||||||
|
|
||||||
|
// CALCOLO PREZZO UNITARIO
|
||||||
|
$prezzo_unitario = 0;
|
||||||
|
$sconto = 0;
|
||||||
|
// Prezzi netti clienti / listino fornitore
|
||||||
|
$prezzi = $dbo->fetchArray('SELECT minimo, massimo, sconto_percentuale, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario
|
||||||
|
FROM mg_prezzi_articoli
|
||||||
|
WHERE id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND id_anagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($prezzi) {
|
||||||
|
foreach ($prezzi as $prezzo) {
|
||||||
|
if ($qta >= $prezzo['minimo'] && $qta <= $prezzo['massimo']) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prezzo['minimo'] == null && $prezzo['massimo'] == null && $prezzo['prezzo_unitario'] != null) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($prezzo_unitario)) {
|
||||||
|
// Prezzi listini clienti
|
||||||
|
$listino = $dbo->fetchOne('SELECT sconto_percentuale AS sconto_percentuale_listino, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario_listino
|
||||||
|
FROM mg_listini
|
||||||
|
LEFT JOIN mg_listini_articoli ON mg_listini.id=mg_listini_articoli.id_listino
|
||||||
|
LEFT JOIN an_anagrafiche ON mg_listini.id=an_anagrafiche.id_listino
|
||||||
|
WHERE mg_listini.data_attivazione<=NOW() AND mg_listini_articoli.data_scadenza>=NOW() AND mg_listini.attivo=1 AND id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND idanagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($listino) {
|
||||||
|
$prezzo_unitario = $listino['prezzo_unitario_listino'];
|
||||||
|
$sconto = $listino['sconto_percentuale_listino'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$prezzo_unitario = $prezzo_unitario ?: ($prezzi_ivati ? $originale->prezzo_vendita_ivato : $originale->prezzo_vendita);
|
||||||
|
|
||||||
|
$articolo->setPrezzoUnitario($prezzo_unitario, $id_iva);
|
||||||
|
$articolo->setSconto($sconto, 'PRC');
|
||||||
|
$articolo->save();
|
||||||
|
|
||||||
|
|
||||||
|
flash()->info(tr('Nuovo articolo aggiunto!'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'update_inline':
|
||||||
|
$id_riga = post('riga_id');
|
||||||
|
$riga = $riga ?: Riga::find($id_riga);
|
||||||
|
$riga = $riga ?: Articolo::find($id_riga);
|
||||||
|
|
||||||
|
if (!empty($riga)) {
|
||||||
|
$riga->qta = post('qta');
|
||||||
|
$riga->setSconto(post('sconto'), post('tipo_sconto'));
|
||||||
|
$riga->save();
|
||||||
|
|
||||||
|
flash()->info(tr('Quantità aggiornata!'));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,10 @@ include_once __DIR__.'/init.php';
|
|||||||
|
|
||||||
$block_edit = $record['is_completato'];
|
$block_edit = $record['is_completato'];
|
||||||
$righe = $contratto->getRighe();
|
$righe = $contratto->getRighe();
|
||||||
|
$colspan = ($block_edit ? '5' : '6');
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="table-responsive">
|
<div class="table-responsive row-list">
|
||||||
<table class="table table-striped table-hover table-condensed table-bordered">
|
<table class="table table-striped table-hover table-condensed table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -36,11 +37,14 @@ echo '
|
|||||||
</th>
|
</th>
|
||||||
<th width="35" class="text-center">'.tr('#').'</th>
|
<th width="35" class="text-center">'.tr('#').'</th>
|
||||||
<th>'.tr('Descrizione').'</th>
|
<th>'.tr('Descrizione').'</th>
|
||||||
<th class="text-center tip" width="150" title="'.tr('da evadere').' / '.tr('totale').'">'.tr('Q.tà').' <i class="fa fa-question-circle-o"></i></th>
|
<th class="text-center tip" width="150">'.tr('Q.tà').'</th>
|
||||||
<th class="text-center" width="150">'.tr('Prezzo unitario').'</th>
|
<th class="text-center" width="140">'.tr('Prezzo unitario').'</th>';
|
||||||
<th class="text-center" width="150">'.tr('Iva unitaria').'</th>
|
if (!$block_edit) {
|
||||||
<th class="text-center" width="150">'.tr('Importo').'</th>
|
echo '<th class="text-center" width="150">'.tr('Sconto unitario').'</th>';
|
||||||
<th width="100"></th>
|
}
|
||||||
|
echo '
|
||||||
|
<th class="text-center" width="140">'.tr('Importo').'</th>
|
||||||
|
<th width="80"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
@ -102,15 +106,24 @@ foreach ($righe as $riga) {
|
|||||||
<td></td>';
|
<td></td>';
|
||||||
} else {
|
} else {
|
||||||
// Quantità e unità di misura
|
// Quantità e unità di misura
|
||||||
|
$progress_perc = $riga->qta_evasa * 100 / $riga->qta;
|
||||||
echo '
|
echo '
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
'.numberFormat($riga->qta_rimanente, 'qta').' / '.numberFormat($riga->qta, 'qta').' '.$riga->um.'
|
{[ "type": "number", "name": "qta_'.$riga->id.'", "value": "'.$riga->qta.'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "<span class=\'tip\' title=\''.tr('Quantità evasa: _QTA_', ['_QTA_' => numberFormat($riga->qta_evasa, 'qta')]).'\'>'.($riga->um ?: ' ').'</span>", "disabled": "'.($riga->isSconto() ? 1 : 0).'", "disabled": "'.$block_edit.'" ]}
|
||||||
|
<div class="progress" style="height:4px;">
|
||||||
|
<div class="progress-bar progress-bar-primary" style="width:'.$progress_perc.'%"></div>
|
||||||
|
</div>
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Prezzi unitari
|
// Prezzi unitari
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">';
|
||||||
'.moneyFormat($riga->prezzo_unitario_corrente);
|
// Provvigione riga
|
||||||
|
if (abs($riga->provvigione_unitaria) > 0) {
|
||||||
|
$text = provvigioneInfo($riga);
|
||||||
|
echo '<span class="pull-left text-info" title="'.$text.'"><i class="fa fa-handshake-o"></i></span>';
|
||||||
|
}
|
||||||
|
echo moneyFormat($riga->prezzo_unitario_corrente);
|
||||||
|
|
||||||
if ($dir == 'entrata' && $riga->costo_unitario != 0) {
|
if ($dir == 'entrata' && $riga->costo_unitario != 0) {
|
||||||
echo '
|
echo '
|
||||||
@ -129,26 +142,23 @@ foreach ($righe as $riga) {
|
|||||||
echo '
|
echo '
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Iva
|
// Sconto unitario
|
||||||
|
if (!$block_edit) {
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-center">
|
||||||
'.moneyFormat($riga->iva_unitaria_scontata).'
|
{[ "type": "number", "name": "sconto_'.$riga->id.'", "value": "'.($riga->sconto_percentuale ?: $riga->sconto_unitario_corrente).'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.$riga->tipo_sconto.'" ]}
|
||||||
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
|
||||||
</td>';
|
</td>';
|
||||||
|
}
|
||||||
|
|
||||||
// Importo
|
// Importo
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($riga->importo);
|
'.moneyFormat($riga->importo);
|
||||||
|
|
||||||
//provvigione riga
|
// Iva
|
||||||
if (abs($riga->provvigione_unitaria) > 0) {
|
|
||||||
$text = provvigioneInfo($riga);
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<br><small class="label label-info">'.$text.'</small>';
|
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
||||||
}
|
</td>';
|
||||||
echo '</td>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Possibilità di rimuovere una riga solo se il preventivo non è stato pagato
|
// Possibilità di rimuovere una riga solo se il preventivo non è stato pagato
|
||||||
@ -192,7 +202,7 @@ $netto_a_pagare = $contratto->netto;
|
|||||||
// Totale totale imponibile
|
// Totale totale imponibile
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -205,7 +215,7 @@ echo '
|
|||||||
if (!empty($sconto)) {
|
if (!empty($sconto)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -217,7 +227,7 @@ if (!empty($sconto)) {
|
|||||||
// Totale totale imponibile
|
// Totale totale imponibile
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -230,7 +240,7 @@ if (!empty($sconto)) {
|
|||||||
// Totale iva
|
// Totale iva
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Iva', [], ['upper' => true]).':</b>
|
<b>'.tr('Iva', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -242,7 +252,7 @@ echo '
|
|||||||
// Totale contratto
|
// Totale contratto
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -255,7 +265,7 @@ echo '
|
|||||||
if (!empty($sconto_finale)) {
|
if (!empty($sconto_finale)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
|
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -269,7 +279,7 @@ if (!empty($sconto_finale)) {
|
|||||||
if ($totale != $netto_a_pagare) {
|
if ($totale != $netto_a_pagare) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -283,7 +293,7 @@ if ($totale != $netto_a_pagare) {
|
|||||||
if(!empty($contratto->provvigione)) {
|
if(!empty($contratto->provvigione)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Provvigioni', [], ['upper' => false]).':
|
'.tr('Provvigioni', [], ['upper' => false]).':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -294,7 +304,7 @@ if(!empty($contratto->provvigione)) {
|
|||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Netto da provvigioni', [], ['upper' => false]).':
|
'.tr('Netto da provvigioni', [], ['upper' => false]).':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -455,4 +465,37 @@ $("#check_all").click(function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".tipo_icon_after").on("change", function() {
|
||||||
|
aggiornaInline($(this).closest("tr").data("id"));
|
||||||
|
});
|
||||||
|
|
||||||
|
function aggiornaInline(id) {
|
||||||
|
content_was_modified = false;
|
||||||
|
var qta = input("qta_"+ id).get();
|
||||||
|
var sconto = input("sconto_"+ id).get();
|
||||||
|
var tipo_sconto = input("tipo_sconto_"+ id).get();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: globals.rootdir + "/actions.php",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
id_module: globals.id_module,
|
||||||
|
id_record: globals.id_record,
|
||||||
|
op: "update_inline",
|
||||||
|
riga_id: id,
|
||||||
|
qta: qta,
|
||||||
|
sconto: sconto,
|
||||||
|
tipo_sconto: tipo_sconto,
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
caricaRighe(id);
|
||||||
|
renderMessages();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
caricaRighe(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
init();
|
||||||
</script>';
|
</script>';
|
||||||
|
@ -55,8 +55,8 @@ switch (filter('op')) {
|
|||||||
$ddt->save();
|
$ddt->save();
|
||||||
|
|
||||||
flash()->info(tr('Aggiunto ddt in _TYPE_ numero _NUM_!', [
|
flash()->info(tr('Aggiunto ddt in _TYPE_ numero _NUM_!', [
|
||||||
'_TYPE_' => ($dir == 'entrata' ? 'uscita': 'entrata'),
|
'_TYPE_' => $dir,
|
||||||
'_NUM_' => ($dir == 'uscita' ? $ddt->numero: $ddt->numero_esterno)
|
'_NUM_' => $ddt->numero,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -531,7 +531,7 @@ switch (filter('op')) {
|
|||||||
// Duplica ddt
|
// Duplica ddt
|
||||||
case 'copy':
|
case 'copy':
|
||||||
$new = $ddt->replicate();
|
$new = $ddt->replicate();
|
||||||
$new->numero = DDT::getNextNumero($new->data, $dir, $id_segment);
|
$new->numero = DDT::getNextNumero($new->data, $dir);
|
||||||
$new->numero_esterno = DDT::getNextNumeroSecondario($new->data, $dir, $new->id_segment);
|
$new->numero_esterno = DDT::getNextNumeroSecondario($new->data, $dir, $new->id_segment);
|
||||||
|
|
||||||
$stato = Stato::where('descrizione', '=', 'Bozza')->first();
|
$stato = Stato::where('descrizione', '=', 'Bozza')->first();
|
||||||
@ -556,6 +556,104 @@ switch (filter('op')) {
|
|||||||
|
|
||||||
flash()->info(tr('DDT duplicato correttamente!'));
|
flash()->info(tr('DDT duplicato correttamente!'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'add_articolo':
|
||||||
|
$id_articolo = post('id_articolo');
|
||||||
|
$barcode = post('barcode');
|
||||||
|
$dir = 'entrata';
|
||||||
|
|
||||||
|
if (!empty($barcode)) {
|
||||||
|
$id_articolo = $dbo->selectOne('mg_articoli', 'id', ['deleted_at' => null, 'barcode' => $barcode])['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($id_articolo)) {
|
||||||
|
$permetti_movimenti_sotto_zero = setting('Permetti selezione articoli con quantità minore o uguale a zero in Documenti di Vendita');
|
||||||
|
$qta_articolo = $dbo->selectOne('mg_articoli', 'qta', ['id' => $id_articolo])['qta'];
|
||||||
|
|
||||||
|
$originale = ArticoloOriginale::find($id_articolo);
|
||||||
|
|
||||||
|
if ($qta_articolo <= 0 && !$permetti_movimenti_sotto_zero && !$originale->servizio && $dir == 'entrata') {
|
||||||
|
$response['error'] = tr('Quantità a magazzino non sufficiente');
|
||||||
|
echo json_encode($response);
|
||||||
|
} else {
|
||||||
|
$articolo = Articolo::build($ddt, $originale);
|
||||||
|
$qta = 1;
|
||||||
|
|
||||||
|
$articolo->descrizione = $originale->descrizione;
|
||||||
|
$articolo->um = $originale->um;
|
||||||
|
$articolo->qta = 1;
|
||||||
|
$articolo->costo_unitario = $originale->prezzo_acquisto;
|
||||||
|
|
||||||
|
$id_iva = $originale->idiva_vendita ?: setting('Iva predefinita');
|
||||||
|
$id_anagrafica = $ddt->idanagrafica;
|
||||||
|
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
|
||||||
|
|
||||||
|
// CALCOLO PREZZO UNITARIO
|
||||||
|
$prezzo_unitario = 0;
|
||||||
|
$sconto = 0;
|
||||||
|
// Prezzi netti clienti / listino fornitore
|
||||||
|
$prezzi = $dbo->fetchArray('SELECT minimo, massimo, sconto_percentuale, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario
|
||||||
|
FROM mg_prezzi_articoli
|
||||||
|
WHERE id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND id_anagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($prezzi) {
|
||||||
|
foreach ($prezzi as $prezzo) {
|
||||||
|
if ($qta >= $prezzo['minimo'] && $qta <= $prezzo['massimo']) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prezzo['minimo'] == null && $prezzo['massimo'] == null && $prezzo['prezzo_unitario'] != null) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($prezzo_unitario)) {
|
||||||
|
// Prezzi listini clienti
|
||||||
|
$listino = $dbo->fetchOne('SELECT sconto_percentuale AS sconto_percentuale_listino, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario_listino
|
||||||
|
FROM mg_listini
|
||||||
|
LEFT JOIN mg_listini_articoli ON mg_listini.id=mg_listini_articoli.id_listino
|
||||||
|
LEFT JOIN an_anagrafiche ON mg_listini.id=an_anagrafiche.id_listino
|
||||||
|
WHERE mg_listini.data_attivazione<=NOW() AND mg_listini_articoli.data_scadenza>=NOW() AND mg_listini.attivo=1 AND id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND idanagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($listino) {
|
||||||
|
$prezzo_unitario = $listino['prezzo_unitario_listino'];
|
||||||
|
$sconto = $listino['sconto_percentuale_listino'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$prezzo_unitario = $prezzo_unitario ?: ($prezzi_ivati ? $originale->prezzo_vendita_ivato : $originale->prezzo_vendita);
|
||||||
|
|
||||||
|
$articolo->setPrezzoUnitario($prezzo_unitario, $id_iva);
|
||||||
|
$articolo->setSconto($sconto, 'PRC');
|
||||||
|
$articolo->save();
|
||||||
|
|
||||||
|
|
||||||
|
flash()->info(tr('Nuovo articolo aggiunto!'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'update_inline':
|
||||||
|
$id_riga = post('riga_id');
|
||||||
|
$riga = $riga ?: Riga::find($id_riga);
|
||||||
|
$riga = $riga ?: Articolo::find($id_riga);
|
||||||
|
|
||||||
|
if (!empty($riga)) {
|
||||||
|
$riga->qta = post('qta');
|
||||||
|
$riga->setSconto(post('sconto'), post('tipo_sconto'));
|
||||||
|
$riga->save();
|
||||||
|
|
||||||
|
flash()->info(tr('Quantità aggiornata!'));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,10 @@ include_once __DIR__.'/init.php';
|
|||||||
|
|
||||||
$block_edit = $record['flag_completato'];
|
$block_edit = $record['flag_completato'];
|
||||||
$righe = $ddt->getRighe();
|
$righe = $ddt->getRighe();
|
||||||
|
$colspan = ($block_edit ? '5' : '6');
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="table-responsive">
|
<div class="table-responsive row-list">
|
||||||
<table class="table table-striped table-hover table-condensed table-bordered">
|
<table class="table table-striped table-hover table-condensed table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -36,11 +37,14 @@ echo '
|
|||||||
</th>
|
</th>
|
||||||
<th width="35" class="text-center">'.tr('#').'</th>
|
<th width="35" class="text-center">'.tr('#').'</th>
|
||||||
<th>'.tr('Descrizione').'</th>
|
<th>'.tr('Descrizione').'</th>
|
||||||
<th class="text-center tip" width="150" title="'.tr('da evadere').' / '.tr('totale').'">'.tr('Q.tà').' <i class="fa fa-question-circle-o"></i></th>
|
<th class="text-center tip" width="150">'.tr('Q.tà').'</th>
|
||||||
<th class="text-center" width="150">'.tr('Prezzo unitario').'</th>
|
<th class="text-center" width="140">'.tr('Prezzo unitario').'</th>';
|
||||||
<th class="text-center" width="150">'.tr('Iva unitaria').'</th>
|
if (!$block_edit) {
|
||||||
<th class="text-center" width="150">'.tr('Importo').'</th>
|
echo '<th class="text-center" width="150">'.tr('Sconto unitario').'</th>';
|
||||||
<th width="60"></th>
|
}
|
||||||
|
echo '
|
||||||
|
<th class="text-center" width="140">'.tr('Importo').'</th>
|
||||||
|
<th width="80"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
@ -65,9 +69,8 @@ foreach ($righe as $riga) {
|
|||||||
$mancanti = 0;
|
$mancanti = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'" '.$extra.'>
|
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'">
|
||||||
<td class="text-center">';
|
<td class="text-center">';
|
||||||
if (!$block_edit) {
|
if (!$block_edit) {
|
||||||
echo '
|
echo '
|
||||||
@ -140,15 +143,24 @@ foreach ($righe as $riga) {
|
|||||||
<td></td>';
|
<td></td>';
|
||||||
} else {
|
} else {
|
||||||
// Quantità e unità di misura
|
// Quantità e unità di misura
|
||||||
|
$progress_perc = $riga->qta_evasa * 100 / $riga->qta;
|
||||||
echo '
|
echo '
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
'.numberFormat($riga->qta_rimanente, 'qta').' / '.numberFormat($riga->qta, 'qta').' '.$riga->um.'
|
{[ "type": "number", "name": "qta_'.$riga->id.'", "value": "'.$riga->qta.'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "<span class=\'tip\' title=\''.tr('Quantità evasa: _QTA_', ['_QTA_' => numberFormat($riga->qta_evasa, 'qta')]).'\'>'.($riga->um ?: ' ').'</span>", "disabled": "'.($riga->isSconto() ? 1 : 0).'", "disabled": "'.$block_edit.'" ]}
|
||||||
|
<div class="progress" style="height:4px;">
|
||||||
|
<div class="progress-bar progress-bar-primary" style="width:'.$progress_perc.'%"></div>
|
||||||
|
</div>
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Prezzi unitari
|
// Prezzi unitari
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">';
|
||||||
'.moneyFormat($riga->prezzo_unitario_corrente);
|
// Provvigione riga
|
||||||
|
if (abs($riga->provvigione_unitaria) > 0) {
|
||||||
|
$text = provvigioneInfo($riga);
|
||||||
|
echo '<span class="pull-left text-info" title="'.$text.'"><i class="fa fa-handshake-o"></i></span>';
|
||||||
|
}
|
||||||
|
echo moneyFormat($riga->prezzo_unitario_corrente);
|
||||||
|
|
||||||
if ($dir == 'entrata' && $riga->costo_unitario != 0) {
|
if ($dir == 'entrata' && $riga->costo_unitario != 0) {
|
||||||
echo '
|
echo '
|
||||||
@ -167,27 +179,23 @@ foreach ($righe as $riga) {
|
|||||||
echo '
|
echo '
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Iva
|
// Sconto unitario
|
||||||
|
if (!$block_edit) {
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-center">
|
||||||
'.moneyFormat($riga->iva_unitaria_scontata).'
|
{[ "type": "number", "name": "sconto_'.$riga->id.'", "value": "'.($riga->sconto_percentuale ?: $riga->sconto_unitario_corrente).'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.$riga->tipo_sconto.'" ]}
|
||||||
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
|
||||||
</td>';
|
</td>';
|
||||||
|
}
|
||||||
|
|
||||||
// Importo
|
// Importo
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($riga->importo);
|
'.moneyFormat($riga->importo);
|
||||||
|
|
||||||
//provvigione riga
|
// Iva
|
||||||
if (abs($riga->provvigione_unitaria) > 0) {
|
|
||||||
$text = provvigioneInfo($riga);
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<br><small class="label label-info">'.$text.'</small>';
|
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
||||||
}
|
</td>';
|
||||||
|
|
||||||
echo ' </td>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Possibilità di rimuovere una riga solo se il ddt non è evaso
|
// Possibilità di rimuovere una riga solo se il ddt non è evaso
|
||||||
@ -237,17 +245,15 @@ $totale = abs($ddt->totale);
|
|||||||
$sconto_finale = $ddt->getScontoFinale();
|
$sconto_finale = $ddt->getScontoFinale();
|
||||||
$netto_a_pagare = $ddt->netto;
|
$netto_a_pagare = $ddt->netto;
|
||||||
|
|
||||||
// IMPONIBILE
|
// Totale totale imponibile
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($imponibile, 2).'
|
'.moneyFormat($imponibile, 2).'
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
@ -255,57 +261,49 @@ echo '
|
|||||||
if (!empty($sconto)) {
|
if (!empty($sconto)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($sconto, 2).'
|
'.moneyFormat($sconto, 2).'
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
// TOTALE IMPONIBILE
|
// Totale totale imponibile
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($totale_imponibile, 2).'
|
'.moneyFormat($totale_imponibile, 2).'
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// IVA
|
// Totale iva
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('IVA', [], ['upper' => true]).':</b>
|
<b>'.tr('Iva', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($iva, 2).'
|
'.moneyFormat($iva, 2).'
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
// TOTALE
|
// Totale ddt
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($totale, 2).'
|
'.moneyFormat($totale, 2).'
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
@ -313,7 +311,7 @@ echo '
|
|||||||
if (!empty($sconto_finale)) {
|
if (!empty($sconto_finale)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
|
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -327,7 +325,7 @@ if (!empty($sconto_finale)) {
|
|||||||
if ($totale != $netto_a_pagare) {
|
if ($totale != $netto_a_pagare) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -341,8 +339,8 @@ if ($totale != $netto_a_pagare) {
|
|||||||
if(!empty($ddt->provvigione)) {
|
if(!empty($ddt->provvigione)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Provvigioni').':
|
'.tr('Provvigioni', [], ['upper' => false]).':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($ddt->provvigione).'
|
'.moneyFormat($ddt->provvigione).'
|
||||||
@ -352,15 +350,14 @@ if(!empty($ddt->provvigione)) {
|
|||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Netto da provvigioni').':
|
'.tr('Netto da provvigioni', [], ['upper' => false]).':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($ddt->totale_imponibile - $ddt->provvigione).'
|
'.moneyFormat($ddt->totale_imponibile - $ddt->provvigione).'
|
||||||
</td>
|
</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
@ -530,4 +527,37 @@ $("#check_all").click(function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".tipo_icon_after").on("change", function() {
|
||||||
|
aggiornaInline($(this).closest("tr").data("id"));
|
||||||
|
});
|
||||||
|
|
||||||
|
function aggiornaInline(id) {
|
||||||
|
content_was_modified = false;
|
||||||
|
var qta = input("qta_"+ id).get();
|
||||||
|
var sconto = input("sconto_"+ id).get();
|
||||||
|
var tipo_sconto = input("tipo_sconto_"+ id).get();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: globals.rootdir + "/actions.php",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
id_module: globals.id_module,
|
||||||
|
id_record: globals.id_record,
|
||||||
|
op: "update_inline",
|
||||||
|
riga_id: id,
|
||||||
|
qta: qta,
|
||||||
|
sconto: sconto,
|
||||||
|
tipo_sconto: tipo_sconto,
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
caricaRighe(id);
|
||||||
|
renderMessages();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
caricaRighe(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
init();
|
||||||
</script>';
|
</script>';
|
||||||
|
@ -926,6 +926,97 @@ switch (post('op')) {
|
|||||||
|
|
||||||
echo json_encode($has_serial);
|
echo json_encode($has_serial);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'add_articolo':
|
||||||
|
$id_articolo = post('id_articolo');
|
||||||
|
$barcode = post('barcode');
|
||||||
|
$dir = 'entrata';
|
||||||
|
|
||||||
|
if (!empty($barcode)) {
|
||||||
|
$id_articolo = $dbo->selectOne('mg_articoli', 'id', ['deleted_at' => null, 'barcode' => $barcode])['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($id_articolo)) {
|
||||||
|
$permetti_movimenti_sotto_zero = setting('Permetti selezione articoli con quantità minore o uguale a zero in Documenti di Vendita');
|
||||||
|
$qta_articolo = $dbo->selectOne('mg_articoli', 'qta', ['id' => $id_articolo])['qta'];
|
||||||
|
|
||||||
|
$originale = ArticoloOriginale::find($id_articolo);
|
||||||
|
|
||||||
|
if ($qta_articolo <= 0 && !$permetti_movimenti_sotto_zero && !$originale->servizio && $dir == 'entrata') {
|
||||||
|
$response['error'] = tr('Quantità a magazzino non sufficiente');
|
||||||
|
echo json_encode($response);
|
||||||
|
} else {
|
||||||
|
$articolo = Articolo::build($fattura, $originale);
|
||||||
|
$qta = 1;
|
||||||
|
|
||||||
|
$articolo->descrizione = $originale->descrizione;
|
||||||
|
$articolo->um = $originale->um;
|
||||||
|
$articolo->qta = 1;
|
||||||
|
$articolo->costo_unitario = $originale->prezzo_acquisto;
|
||||||
|
|
||||||
|
$id_conto = ($fattura->direzione == 'entrata') ? setting('Conto predefinito fatture di vendita') : setting('Conto predefinito fatture di acquisto');
|
||||||
|
if ($fattura->direzione == 'entrata' && !empty($originale->idconto_vendita)) {
|
||||||
|
$id_conto = $originale->idconto_vendita;
|
||||||
|
} elseif ($fattura->direzione == 'uscita' && !empty($originale->idconto_acquisto)) {
|
||||||
|
$id_conto = $originale->idconto_acquisto;
|
||||||
|
}
|
||||||
|
$articolo->idconto = $id_conto;
|
||||||
|
|
||||||
|
$id_iva = $originale->idiva_vendita ?: setting('Iva predefinita');
|
||||||
|
$id_anagrafica = $fattura->idanagrafica;
|
||||||
|
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
|
||||||
|
|
||||||
|
// CALCOLO PREZZO UNITARIO
|
||||||
|
$prezzo_unitario = 0;
|
||||||
|
$sconto = 0;
|
||||||
|
// Prezzi netti clienti / listino fornitore
|
||||||
|
$prezzi = $dbo->fetchArray('SELECT minimo, massimo, sconto_percentuale, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario
|
||||||
|
FROM mg_prezzi_articoli
|
||||||
|
WHERE id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND id_anagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($prezzi) {
|
||||||
|
foreach ($prezzi as $prezzo) {
|
||||||
|
if ($qta >= $prezzo['minimo'] && $qta <= $prezzo['massimo']) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prezzo['minimo'] == null && $prezzo['massimo'] == null && $prezzo['prezzo_unitario'] != null) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($prezzo_unitario)) {
|
||||||
|
// Prezzi listini clienti
|
||||||
|
$listino = $dbo->fetchOne('SELECT sconto_percentuale AS sconto_percentuale_listino, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario_listino
|
||||||
|
FROM mg_listini
|
||||||
|
LEFT JOIN mg_listini_articoli ON mg_listini.id=mg_listini_articoli.id_listino
|
||||||
|
LEFT JOIN an_anagrafiche ON mg_listini.id=an_anagrafiche.id_listino
|
||||||
|
WHERE mg_listini.data_attivazione<=NOW() AND mg_listini_articoli.data_scadenza>=NOW() AND mg_listini.attivo=1 AND id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND idanagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($listino) {
|
||||||
|
$prezzo_unitario = $listino['prezzo_unitario_listino'];
|
||||||
|
$sconto = $listino['sconto_percentuale_listino'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$prezzo_unitario = $prezzo_unitario ?: ($prezzi_ivati ? $originale->prezzo_vendita_ivato : $originale->prezzo_vendita);
|
||||||
|
|
||||||
|
$articolo->setPrezzoUnitario($prezzo_unitario, $id_iva);
|
||||||
|
$articolo->setSconto($sconto, 'PRC');
|
||||||
|
$articolo->save();
|
||||||
|
|
||||||
|
|
||||||
|
flash()->info(tr('Nuovo articolo aggiunto!'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -960,5 +960,103 @@ switch (post('op')) {
|
|||||||
$dbo->query('UPDATE `in_righe_interventi` SET `order` = '.prepare($i + 1).' WHERE id='.prepare($id_riga));
|
$dbo->query('UPDATE `in_righe_interventi` SET `order` = '.prepare($i + 1).' WHERE id='.prepare($id_riga));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'add_articolo':
|
||||||
|
$id_articolo = post('id_articolo');
|
||||||
|
$barcode = post('barcode');
|
||||||
|
$dir = 'entrata';
|
||||||
|
|
||||||
|
if (!empty($barcode)) {
|
||||||
|
$id_articolo = $dbo->selectOne('mg_articoli', 'id', ['deleted_at' => null, 'barcode' => $barcode])['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($id_articolo)) {
|
||||||
|
$permetti_movimenti_sotto_zero = setting('Permetti selezione articoli con quantità minore o uguale a zero in Documenti di Vendita');
|
||||||
|
$qta_articolo = $dbo->selectOne('mg_articoli', 'qta', ['id' => $id_articolo])['qta'];
|
||||||
|
|
||||||
|
$originale = ArticoloOriginale::find($id_articolo);
|
||||||
|
|
||||||
|
if ($qta_articolo <= 0 && !$permetti_movimenti_sotto_zero && !$originale->servizio && $dir == 'entrata') {
|
||||||
|
$response['error'] = tr('Quantità a magazzino non sufficiente');
|
||||||
|
echo json_encode($response);
|
||||||
|
} else {
|
||||||
|
$articolo = Articolo::build($intervento, $originale);
|
||||||
|
$qta = 1;
|
||||||
|
|
||||||
|
$articolo->descrizione = $originale->descrizione;
|
||||||
|
$articolo->um = $originale->um;
|
||||||
|
$articolo->qta = 1;
|
||||||
|
$articolo->costo_unitario = $originale->prezzo_acquisto;
|
||||||
|
|
||||||
|
$id_iva = $originale->idiva_vendita ?: setting('Iva predefinita');
|
||||||
|
$id_anagrafica = $intervento->idanagrafica;
|
||||||
|
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
|
||||||
|
|
||||||
|
// CALCOLO PREZZO UNITARIO
|
||||||
|
$prezzo_unitario = 0;
|
||||||
|
$sconto = 0;
|
||||||
|
// Prezzi netti clienti / listino fornitore
|
||||||
|
$prezzi = $dbo->fetchArray('SELECT minimo, massimo, sconto_percentuale, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario
|
||||||
|
FROM mg_prezzi_articoli
|
||||||
|
WHERE id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND id_anagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($prezzi) {
|
||||||
|
foreach ($prezzi as $prezzo) {
|
||||||
|
if ($qta >= $prezzo['minimo'] && $qta <= $prezzo['massimo']) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prezzo['minimo'] == null && $prezzo['massimo'] == null && $prezzo['prezzo_unitario'] != null) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($prezzo_unitario)) {
|
||||||
|
// Prezzi listini clienti
|
||||||
|
$listino = $dbo->fetchOne('SELECT sconto_percentuale AS sconto_percentuale_listino, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario_listino
|
||||||
|
FROM mg_listini
|
||||||
|
LEFT JOIN mg_listini_articoli ON mg_listini.id=mg_listini_articoli.id_listino
|
||||||
|
LEFT JOIN an_anagrafiche ON mg_listini.id=an_anagrafiche.id_listino
|
||||||
|
WHERE mg_listini.data_attivazione<=NOW() AND mg_listini_articoli.data_scadenza>=NOW() AND mg_listini.attivo=1 AND id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND idanagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($listino) {
|
||||||
|
$prezzo_unitario = $listino['prezzo_unitario_listino'];
|
||||||
|
$sconto = $listino['sconto_percentuale_listino'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$prezzo_unitario = $prezzo_unitario ?: ($prezzi_ivati ? $originale->prezzo_vendita_ivato : $originale->prezzo_vendita);
|
||||||
|
|
||||||
|
$articolo->setPrezzoUnitario($prezzo_unitario, $id_iva);
|
||||||
|
$articolo->setSconto($sconto, 'PRC');
|
||||||
|
$articolo->save();
|
||||||
|
|
||||||
|
|
||||||
|
flash()->info(tr('Nuovo articolo aggiunto!'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'update_inline':
|
||||||
|
$id_riga = post('riga_id');
|
||||||
|
$riga = $riga ?: Riga::find($id_riga);
|
||||||
|
$riga = $riga ?: Articolo::find($id_riga);
|
||||||
|
|
||||||
|
if (!empty($riga)) {
|
||||||
|
$riga->qta = post('qta');
|
||||||
|
$riga->setSconto(post('sconto'), post('tipo_sconto'));
|
||||||
|
$riga->save();
|
||||||
|
|
||||||
|
flash()->info(tr('Quantità aggiornata!'));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,12 @@ include_once __DIR__.'/init.php';
|
|||||||
|
|
||||||
$block_edit = $record['flag_completato'];
|
$block_edit = $record['flag_completato'];
|
||||||
$righe = $intervento->getRighe();
|
$righe = $intervento->getRighe();
|
||||||
|
$colspan = ($block_edit ? '5' : '6');
|
||||||
|
|
||||||
$show_prezzi = Auth::user()['gruppo'] != 'Tecnici' || (Auth::user()['gruppo'] == 'Tecnici' && setting('Mostra i prezzi al tecnico'));
|
$show_prezzi = Auth::user()['gruppo'] != 'Tecnici' || (Auth::user()['gruppo'] == 'Tecnici' && setting('Mostra i prezzi al tecnico'));
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="table-responsive">
|
<div class="table-responsive row-list">
|
||||||
<table class="table table-striped table-hover table-condensed table-bordered">
|
<table class="table table-striped table-hover table-condensed table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -37,14 +38,17 @@ echo '
|
|||||||
echo '
|
echo '
|
||||||
</th>
|
</th>
|
||||||
<th>'.tr('Descrizione').'</th>
|
<th>'.tr('Descrizione').'</th>
|
||||||
<th class="text-center" width="80">'.tr('Q.tà').'</th>';
|
<th class="text-center" width="150">'.tr('Q.tà').'</th>';
|
||||||
|
|
||||||
if ($show_prezzi) {
|
if ($show_prezzi) {
|
||||||
echo '
|
echo '
|
||||||
<th class="text-center" width="150">'.tr('Prezzo di acquisto').'</th>
|
<th class="text-center" width="140">'.tr('Prezzo di acquisto').'</th>
|
||||||
<th class="text-center" width="150">'.tr('Prezzo di vendita').'</th>
|
<th class="text-center" width="140">'.tr('Prezzo di vendita').'</th>';
|
||||||
<th class="text-center" width="150">'.tr('Iva unitaria').'</th>
|
if (!$block_edit) {
|
||||||
<th class="text-center" width="150">'.tr('Importo').'</th>';
|
echo '<th class="text-center" width="150">'.tr('Sconto unitario').'</th>';
|
||||||
|
}
|
||||||
|
echo '
|
||||||
|
<th class="text-center" width="140">'.tr('Importo').'</th>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$record['flag_completato']) {
|
if (!$record['flag_completato']) {
|
||||||
@ -119,10 +123,10 @@ echo '
|
|||||||
echo '
|
echo '
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Quantità
|
// Quantità e unità di misura
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-center">
|
||||||
'.Translator::numberToLocale($riga->qta, 'qta').' '.$riga->um.'
|
{[ "type": "number", "name": "qta_'.$riga->id.'", "value": "'.$riga->qta.'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "'.($riga->um ?: ' ').'", "disabled": "'.($riga->isSconto() ? 1 : 0).'", "disabled": "'.$block_edit.'" ]}
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
if ($show_prezzi) {
|
if ($show_prezzi) {
|
||||||
@ -134,8 +138,13 @@ echo '
|
|||||||
|
|
||||||
// Prezzo unitario
|
// Prezzo unitario
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">';
|
||||||
'.moneyFormat($riga->prezzo_unitario);
|
// Provvigione riga
|
||||||
|
if (abs($riga->provvigione_unitaria) > 0) {
|
||||||
|
$text = provvigioneInfo($riga);
|
||||||
|
echo '<span class="pull-left text-info" title="'.$text.'"><i class="fa fa-handshake-o"></i></span>';
|
||||||
|
}
|
||||||
|
echo moneyFormat($riga->prezzo_unitario);
|
||||||
|
|
||||||
if (abs($riga->sconto_unitario) > 0) {
|
if (abs($riga->sconto_unitario) > 0) {
|
||||||
$text = discountInfo($riga);
|
$text = discountInfo($riga);
|
||||||
@ -147,27 +156,23 @@ echo '
|
|||||||
echo '
|
echo '
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
|
// Sconto unitario
|
||||||
|
if (!$block_edit) {
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-center">
|
||||||
'.moneyFormat($riga->iva_unitaria_scontata).'
|
{[ "type": "number", "name": "sconto_'.$riga->id.'", "value": "'.($riga->sconto_percentuale ?: $riga->sconto_unitario_corrente).'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.$riga->tipo_sconto.'" ]}
|
||||||
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
|
||||||
</td>';
|
</td>';
|
||||||
|
}
|
||||||
|
|
||||||
// Prezzo di vendita
|
// Prezzo di vendita
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($riga->importo);
|
'.moneyFormat($riga->importo);
|
||||||
|
|
||||||
|
// Iva
|
||||||
//provvigione riga
|
|
||||||
if (abs($riga->provvigione_unitaria) > 0) {
|
|
||||||
$text = provvigioneInfo($riga);
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<br><small class="label label-info">'.$text.'</small>';
|
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
||||||
}
|
</td>';
|
||||||
|
|
||||||
echo '</td>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pulsante per riportare nel magazzino centrale.
|
// Pulsante per riportare nel magazzino centrale.
|
||||||
@ -213,7 +218,7 @@ echo '
|
|||||||
// IMPONIBILE
|
// IMPONIBILE
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="'.((!$record['flag_completato']) ? 6 : 5).'" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -226,7 +231,7 @@ echo '
|
|||||||
if (!empty($intervento->sconto)) {
|
if (!empty($intervento->sconto)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="'.((!$record['flag_completato']) ? 6 : 5).'" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -238,7 +243,7 @@ echo '
|
|||||||
// Totale imponibile scontato
|
// Totale imponibile scontato
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="'.((!$record['flag_completato']) ? 6 : 5).'" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -252,7 +257,7 @@ echo '
|
|||||||
if(!empty($intervento->provvigione)) {
|
if(!empty($intervento->provvigione)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="'.((!$record['flag_completato']) ? 6 : 5).'" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Provvigioni').':
|
'.tr('Provvigioni').':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -423,4 +428,37 @@ $("#check_all").click(function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".tipo_icon_after").on("change", function() {
|
||||||
|
aggiornaInline($(this).closest("tr").data("id"));
|
||||||
|
});
|
||||||
|
|
||||||
|
function aggiornaInline(id) {
|
||||||
|
content_was_modified = false;
|
||||||
|
var qta = input("qta_"+ id).get();
|
||||||
|
var sconto = input("sconto_"+ id).get();
|
||||||
|
var tipo_sconto = input("tipo_sconto_"+ id).get();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: globals.rootdir + "/actions.php",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
id_module: globals.id_module,
|
||||||
|
id_record: globals.id_record,
|
||||||
|
op: "update_inline",
|
||||||
|
riga_id: id,
|
||||||
|
qta: qta,
|
||||||
|
sconto: sconto,
|
||||||
|
tipo_sconto: tipo_sconto,
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
caricaRighe(id);
|
||||||
|
renderMessages();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
caricaRighe(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
init();
|
||||||
</script>';
|
</script>';
|
||||||
|
@ -606,5 +606,103 @@ switch (post('op')) {
|
|||||||
'_NUM_' => $ordine->numero,
|
'_NUM_' => $ordine->numero,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'add_articolo':
|
||||||
|
$id_articolo = post('id_articolo');
|
||||||
|
$barcode = post('barcode');
|
||||||
|
$dir = 'entrata';
|
||||||
|
|
||||||
|
if (!empty($barcode)) {
|
||||||
|
$id_articolo = $dbo->selectOne('mg_articoli', 'id', ['deleted_at' => null, 'barcode' => $barcode])['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($id_articolo)) {
|
||||||
|
$permetti_movimenti_sotto_zero = setting('Permetti selezione articoli con quantità minore o uguale a zero in Documenti di Vendita');
|
||||||
|
$qta_articolo = $dbo->selectOne('mg_articoli', 'qta', ['id' => $id_articolo])['qta'];
|
||||||
|
|
||||||
|
$originale = ArticoloOriginale::find($id_articolo);
|
||||||
|
|
||||||
|
if ($qta_articolo <= 0 && !$permetti_movimenti_sotto_zero && !$originale->servizio && $dir == 'entrata') {
|
||||||
|
$response['error'] = tr('Quantità a magazzino non sufficiente');
|
||||||
|
echo json_encode($response);
|
||||||
|
} else {
|
||||||
|
$articolo = Articolo::build($ordine, $originale);
|
||||||
|
$qta = 1;
|
||||||
|
|
||||||
|
$articolo->descrizione = $originale->descrizione;
|
||||||
|
$articolo->um = $originale->um;
|
||||||
|
$articolo->qta = 1;
|
||||||
|
$articolo->costo_unitario = $originale->prezzo_acquisto;
|
||||||
|
|
||||||
|
$id_iva = $originale->idiva_vendita ?: setting('Iva predefinita');
|
||||||
|
$id_anagrafica = $ordine->idanagrafica;
|
||||||
|
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
|
||||||
|
|
||||||
|
// CALCOLO PREZZO UNITARIO
|
||||||
|
$prezzo_unitario = 0;
|
||||||
|
$sconto = 0;
|
||||||
|
// Prezzi netti clienti / listino fornitore
|
||||||
|
$prezzi = $dbo->fetchArray('SELECT minimo, massimo, sconto_percentuale, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario
|
||||||
|
FROM mg_prezzi_articoli
|
||||||
|
WHERE id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND id_anagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($prezzi) {
|
||||||
|
foreach ($prezzi as $prezzo) {
|
||||||
|
if ($qta >= $prezzo['minimo'] && $qta <= $prezzo['massimo']) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prezzo['minimo'] == null && $prezzo['massimo'] == null && $prezzo['prezzo_unitario'] != null) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($prezzo_unitario)) {
|
||||||
|
// Prezzi listini clienti
|
||||||
|
$listino = $dbo->fetchOne('SELECT sconto_percentuale AS sconto_percentuale_listino, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario_listino
|
||||||
|
FROM mg_listini
|
||||||
|
LEFT JOIN mg_listini_articoli ON mg_listini.id=mg_listini_articoli.id_listino
|
||||||
|
LEFT JOIN an_anagrafiche ON mg_listini.id=an_anagrafiche.id_listino
|
||||||
|
WHERE mg_listini.data_attivazione<=NOW() AND mg_listini_articoli.data_scadenza>=NOW() AND mg_listini.attivo=1 AND id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND idanagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($listino) {
|
||||||
|
$prezzo_unitario = $listino['prezzo_unitario_listino'];
|
||||||
|
$sconto = $listino['sconto_percentuale_listino'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$prezzo_unitario = $prezzo_unitario ?: ($prezzi_ivati ? $originale->prezzo_vendita_ivato : $originale->prezzo_vendita);
|
||||||
|
|
||||||
|
$articolo->setPrezzoUnitario($prezzo_unitario, $id_iva);
|
||||||
|
$articolo->setSconto($sconto, 'PRC');
|
||||||
|
$articolo->save();
|
||||||
|
|
||||||
|
|
||||||
|
flash()->info(tr('Nuovo articolo aggiunto!'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'update_inline':
|
||||||
|
$id_riga = post('riga_id');
|
||||||
|
$riga = $riga ?: Riga::find($id_riga);
|
||||||
|
$riga = $riga ?: Articolo::find($id_riga);
|
||||||
|
|
||||||
|
if (!empty($riga)) {
|
||||||
|
$riga->qta = post('qta');
|
||||||
|
$riga->setSconto(post('sconto'), post('tipo_sconto'));
|
||||||
|
$riga->save();
|
||||||
|
|
||||||
|
flash()->info(tr('Quantità aggiornata!'));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,10 @@ use Modules\Articoli\Articolo;
|
|||||||
|
|
||||||
$block_edit = $record['flag_completato'];
|
$block_edit = $record['flag_completato'];
|
||||||
$righe = $ordine->getRighe();
|
$righe = $ordine->getRighe();
|
||||||
|
$colspan = ($block_edit ? '6' : '7');
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="table-responsive">
|
<div class="table-responsive row-list">
|
||||||
<table class="table table-striped table-hover table-condensed table-bordered">
|
<table class="table table-striped table-hover table-condensed table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -38,15 +39,17 @@ echo '
|
|||||||
</th>
|
</th>
|
||||||
<th width="35" class="text-center" >'.tr('#').'</th>
|
<th width="35" class="text-center" >'.tr('#').'</th>
|
||||||
<th>'.tr('Descrizione').'</th>
|
<th>'.tr('Descrizione').'</th>
|
||||||
<th width="120">'.tr('Prev. evasione').'</th>
|
<th width="105">'.tr('Prev. evasione').'</th>
|
||||||
<th class="text-center tip" width="150" title="'.tr('da evadere').' / '.tr('totale').'">'.tr('Q.tà').' <i class="fa fa-question-circle-o"></i></th>
|
<th class="text-center tip" width="190">'.tr('Q.tà').'</th>
|
||||||
<th class="text-center" width="150">'.tr('Prezzo unitario').'</th>
|
<th class="text-center" width="140">'.tr('Prezzo unitario').'</th>';
|
||||||
<th class="text-center" width="150">'.tr('Iva unitaria').'</th>
|
if (!$block_edit) {
|
||||||
<th class="text-center" width="150">'.tr('Importo').'</th>
|
echo '<th class="text-center" width="150">'.tr('Sconto unitario').'</th>';
|
||||||
<th width="60"> </th>
|
}
|
||||||
|
echo '
|
||||||
|
<th class="text-center" width="140">'.tr('Importo').'</th>
|
||||||
|
<th width="80"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody class="sortable" id="righe">';
|
<tbody class="sortable" id="righe">';
|
||||||
|
|
||||||
// Righe documento
|
// Righe documento
|
||||||
@ -72,7 +75,7 @@ foreach ($righe as $riga) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'" '.$extra.'>
|
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'">
|
||||||
<td class="text-center">';
|
<td class="text-center">';
|
||||||
if (!$block_edit) {
|
if (!$block_edit) {
|
||||||
echo '
|
echo '
|
||||||
@ -192,23 +195,24 @@ foreach ($righe as $riga) {
|
|||||||
<td></td>';
|
<td></td>';
|
||||||
} else {
|
} else {
|
||||||
// Quantità e unità di misura
|
// Quantità e unità di misura
|
||||||
|
$progress_perc = $riga->qta_evasa * 100 / $riga->qta;
|
||||||
echo '
|
echo '
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<i class="'.($riga->confermato ? 'fa fa-check text-success' : 'fa fa-clock-o text-warning').'"></i>
|
{[ "type": "number", "name": "qta_'.$riga->id.'", "value": "'.$riga->qta.'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-before": "<i class=\''.($riga->confermato ? 'fa fa-check text-success' : 'fa fa-clock-o text-warning').'\'></i>", "icon-after": "<span class=\'tip\' title=\''.tr('Quantità evasa: _QTA_', ['_QTA_' => numberFormat($riga->qta_evasa, 'qta')]).'\'>'.($riga->um ?: ' ').'</span>", "disabled": "'.($riga->isSconto() ? 1 : 0).'", "disabled": "'.$block_edit.'" ]}
|
||||||
'.numberFormat($riga->qta_rimanente, 'qta').' / '.numberFormat($riga->qta, 'qta').' '.$riga->um.'
|
<div class="progress" style="height:4px;">
|
||||||
|
<div class="progress-bar progress-bar-primary" style="width:'.$progress_perc.'%"></div>
|
||||||
|
</div>
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Prezzi unitari
|
// Prezzi unitari
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">';
|
||||||
'.moneyFormat($riga->prezzo_unitario_corrente);
|
// Provvigione riga
|
||||||
|
if (abs($riga->provvigione_unitaria) > 0) {
|
||||||
if ($dir == 'entrata' && $riga->costo_unitario != 0) {
|
$text = provvigioneInfo($riga);
|
||||||
echo '
|
echo '<span class="pull-left text-info" title="'.$text.'"><i class="fa fa-handshake-o"></i></span>';
|
||||||
<br><small class="text-muted">
|
|
||||||
'.tr('Acquisto').': '.moneyFormat($riga->costo_unitario).'
|
|
||||||
</small>';
|
|
||||||
}
|
}
|
||||||
|
echo moneyFormat($riga->prezzo_unitario_corrente);
|
||||||
|
|
||||||
if (abs($riga->sconto_unitario) > 0) {
|
if (abs($riga->sconto_unitario) > 0) {
|
||||||
$text = discountInfo($riga);
|
$text = discountInfo($riga);
|
||||||
@ -220,25 +224,23 @@ foreach ($righe as $riga) {
|
|||||||
echo '
|
echo '
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Iva
|
// Sconto unitario
|
||||||
|
if (!$block_edit) {
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-center">
|
||||||
'.moneyFormat($riga->iva_unitaria_scontata).'
|
{[ "type": "number", "name": "sconto_'.$riga->id.'", "value": "'.($riga->sconto_percentuale ?: $riga->sconto_unitario_corrente).'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.$riga->tipo_sconto.'" ]}
|
||||||
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
|
||||||
</td>';
|
</td>';
|
||||||
|
}
|
||||||
|
|
||||||
// Importo
|
// Importo
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($riga->importo);
|
'.moneyFormat($riga->importo);
|
||||||
//provvigione riga
|
|
||||||
if (abs($riga->provvigione_unitaria) > 0) {
|
|
||||||
$text = provvigioneInfo($riga);
|
|
||||||
|
|
||||||
|
// Iva
|
||||||
echo '
|
echo '
|
||||||
<br><small class="label label-info">'.$text.'</small>';
|
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
||||||
}
|
</td>';
|
||||||
echo '</td>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Possibilità di rimuovere una riga solo se l'ordine non è evaso
|
// Possibilità di rimuovere una riga solo se l'ordine non è evaso
|
||||||
@ -288,10 +290,10 @@ $totale = abs($ordine->totale);
|
|||||||
$sconto_finale = $ordine->getScontoFinale();
|
$sconto_finale = $ordine->getScontoFinale();
|
||||||
$netto_a_pagare = $ordine->netto;
|
$netto_a_pagare = $ordine->netto;
|
||||||
|
|
||||||
// IMPONIBILE
|
// Totale imponibile scontato
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -304,7 +306,7 @@ echo '
|
|||||||
if (!empty($sconto)) {
|
if (!empty($sconto)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -313,10 +315,10 @@ if (!empty($sconto)) {
|
|||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
// TOTALE IMPONIBILE
|
// Totale imponibile scontato
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -326,10 +328,10 @@ if (!empty($sconto)) {
|
|||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// IVA
|
// Totale iva
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Iva', [], ['upper' => true]).':</b>
|
<b>'.tr('Iva', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -338,10 +340,10 @@ echo '
|
|||||||
<td></td>
|
<td></td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
// TOTALE
|
// Totale
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -354,7 +356,7 @@ echo '
|
|||||||
if (!empty($sconto_finale)) {
|
if (!empty($sconto_finale)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
|
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -368,7 +370,7 @@ if (!empty($sconto_finale)) {
|
|||||||
if ($totale != $netto_a_pagare) {
|
if ($totale != $netto_a_pagare) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -382,7 +384,7 @@ if ($totale != $netto_a_pagare) {
|
|||||||
if(!empty($ordine->provvigione)) {
|
if(!empty($ordine->provvigione)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Provvigioni').':
|
'.tr('Provvigioni').':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -393,7 +395,7 @@ if(!empty($ordine->provvigione)) {
|
|||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Netto da provvigioni').':
|
'.tr('Netto da provvigioni').':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -570,4 +572,37 @@ $("#check_all").click(function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".tipo_icon_after").on("change", function() {
|
||||||
|
aggiornaInline($(this).closest("tr").data("id"));
|
||||||
|
});
|
||||||
|
|
||||||
|
function aggiornaInline(id) {
|
||||||
|
content_was_modified = false;
|
||||||
|
var qta = input("qta_"+ id).get();
|
||||||
|
var sconto = input("sconto_"+ id).get();
|
||||||
|
var tipo_sconto = input("tipo_sconto_"+ id).get();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: globals.rootdir + "/actions.php",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
id_module: globals.id_module,
|
||||||
|
id_record: globals.id_record,
|
||||||
|
op: "update_inline",
|
||||||
|
riga_id: id,
|
||||||
|
qta: qta,
|
||||||
|
sconto: sconto,
|
||||||
|
tipo_sconto: tipo_sconto,
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
caricaRighe(id);
|
||||||
|
renderMessages();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
caricaRighe(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
init();
|
||||||
</script>';
|
</script>';
|
||||||
|
@ -442,5 +442,103 @@ switch (post('op')) {
|
|||||||
$dbo->query('UPDATE `co_righe_preventivi` SET `order` = '.prepare($i + 1).' WHERE id='.prepare($id_riga));
|
$dbo->query('UPDATE `co_righe_preventivi` SET `order` = '.prepare($i + 1).' WHERE id='.prepare($id_riga));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'add_articolo':
|
||||||
|
$id_articolo = post('id_articolo');
|
||||||
|
$barcode = post('barcode');
|
||||||
|
$dir = 'entrata';
|
||||||
|
|
||||||
|
if (!empty($barcode)) {
|
||||||
|
$id_articolo = $dbo->selectOne('mg_articoli', 'id', ['deleted_at' => null, 'barcode' => $barcode])['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($id_articolo)) {
|
||||||
|
$permetti_movimenti_sotto_zero = setting('Permetti selezione articoli con quantità minore o uguale a zero in Documenti di Vendita');
|
||||||
|
$qta_articolo = $dbo->selectOne('mg_articoli', 'qta', ['id' => $id_articolo])['qta'];
|
||||||
|
|
||||||
|
$originale = ArticoloOriginale::find($id_articolo);
|
||||||
|
|
||||||
|
if ($qta_articolo <= 0 && !$permetti_movimenti_sotto_zero && !$originale->servizio && $dir == 'entrata') {
|
||||||
|
$response['error'] = tr('Quantità a magazzino non sufficiente');
|
||||||
|
echo json_encode($response);
|
||||||
|
} else {
|
||||||
|
$articolo = Articolo::build($preventivo, $originale);
|
||||||
|
$qta = 1;
|
||||||
|
|
||||||
|
$articolo->descrizione = $originale->descrizione;
|
||||||
|
$articolo->um = $originale->um;
|
||||||
|
$articolo->qta = 1;
|
||||||
|
$articolo->costo_unitario = $originale->prezzo_acquisto;
|
||||||
|
|
||||||
|
$id_iva = $originale->idiva_vendita ?: setting('Iva predefinita');
|
||||||
|
$id_anagrafica = $preventivo->idanagrafica;
|
||||||
|
$prezzi_ivati = setting('Utilizza prezzi di vendita comprensivi di IVA');
|
||||||
|
|
||||||
|
// CALCOLO PREZZO UNITARIO
|
||||||
|
$prezzo_unitario = 0;
|
||||||
|
$sconto = 0;
|
||||||
|
// Prezzi netti clienti / listino fornitore
|
||||||
|
$prezzi = $dbo->fetchArray('SELECT minimo, massimo, sconto_percentuale, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario
|
||||||
|
FROM mg_prezzi_articoli
|
||||||
|
WHERE id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND id_anagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($prezzi) {
|
||||||
|
foreach ($prezzi as $prezzo) {
|
||||||
|
if ($qta >= $prezzo['minimo'] && $qta <= $prezzo['massimo']) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($prezzo['minimo'] == null && $prezzo['massimo'] == null && $prezzo['prezzo_unitario'] != null) {
|
||||||
|
$prezzo_unitario = $prezzo['prezzo_unitario'];
|
||||||
|
$sconto = $prezzo['sconto_percentuale'];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($prezzo_unitario)) {
|
||||||
|
// Prezzi listini clienti
|
||||||
|
$listino = $dbo->fetchOne('SELECT sconto_percentuale AS sconto_percentuale_listino, '.($prezzi_ivati ? 'prezzo_unitario_ivato' : 'prezzo_unitario').' AS prezzo_unitario_listino
|
||||||
|
FROM mg_listini
|
||||||
|
LEFT JOIN mg_listini_articoli ON mg_listini.id=mg_listini_articoli.id_listino
|
||||||
|
LEFT JOIN an_anagrafiche ON mg_listini.id=an_anagrafiche.id_listino
|
||||||
|
WHERE mg_listini.data_attivazione<=NOW() AND mg_listini_articoli.data_scadenza>=NOW() AND mg_listini.attivo=1 AND id_articolo = '.prepare($id_articolo).' AND dir = '.prepare($dir).' AND idanagrafica = '.prepare($id_anagrafica));
|
||||||
|
|
||||||
|
if ($listino) {
|
||||||
|
$prezzo_unitario = $listino['prezzo_unitario_listino'];
|
||||||
|
$sconto = $listino['sconto_percentuale_listino'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$prezzo_unitario = $prezzo_unitario ?: ($prezzi_ivati ? $originale->prezzo_vendita_ivato : $originale->prezzo_vendita);
|
||||||
|
|
||||||
|
$articolo->setPrezzoUnitario($prezzo_unitario, $id_iva);
|
||||||
|
$articolo->setSconto($sconto, 'PRC');
|
||||||
|
$articolo->save();
|
||||||
|
|
||||||
|
|
||||||
|
flash()->info(tr('Nuovo articolo aggiunto!'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$response['error'] = tr('Nessun articolo corrispondente a magazzino');
|
||||||
|
echo json_encode($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'update_inline':
|
||||||
|
$id_riga = post('riga_id');
|
||||||
|
$riga = $riga ?: Riga::find($id_riga);
|
||||||
|
$riga = $riga ?: Articolo::find($id_riga);
|
||||||
|
|
||||||
|
if (!empty($riga)) {
|
||||||
|
$riga->qta = post('qta');
|
||||||
|
$riga->setSconto(post('sconto'), post('tipo_sconto'));
|
||||||
|
$riga->save();
|
||||||
|
|
||||||
|
flash()->info(tr('Quantità aggiornata!'));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,10 @@ include_once __DIR__.'/init.php';
|
|||||||
|
|
||||||
$block_edit = $record['is_completato'];
|
$block_edit = $record['is_completato'];
|
||||||
$righe = $preventivo->getRighe();
|
$righe = $preventivo->getRighe();
|
||||||
|
$colspan = ($block_edit ? '6' : '7');
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="table-responsive">
|
<div class="table-responsive row-list">
|
||||||
<table class="table table-striped table-hover table-condensed table-bordered">
|
<table class="table table-striped table-hover table-condensed table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -36,12 +37,15 @@ echo '
|
|||||||
</th>
|
</th>
|
||||||
<th width="35" class="text-center" >'.tr('#').'</th>
|
<th width="35" class="text-center" >'.tr('#').'</th>
|
||||||
<th>'.tr('Descrizione').'</th>
|
<th>'.tr('Descrizione').'</th>
|
||||||
<th width="120">'.tr('Prev. evasione').'</th>
|
<th width="105">'.tr('Prev. evasione').'</th>
|
||||||
<th class="text-center tip" width="150" title="'.tr('da evadere').' / '.tr('totale').'">'.tr('Q.tà').' <i class="fa fa-question-circle-o"></i></th>
|
<th class="text-center tip" width="190">'.tr('Q.tà').'</th>
|
||||||
<th class="text-center" width="150">'.tr('Prezzo unitario').'</th>
|
<th class="text-center" width="140">'.tr('Prezzo unitario').'</th>';
|
||||||
<th class="text-center" width="150">'.tr('Iva unitaria').'</th>
|
if (!$block_edit) {
|
||||||
<th class="text-center" width="150">'.tr('Importo').'</th>
|
echo '<th class="text-center" width="150">'.tr('Sconto unitario').'</th>';
|
||||||
<th width="100"></th>
|
}
|
||||||
|
echo '
|
||||||
|
<th class="text-center" width="140">'.tr('Importo').'</th>
|
||||||
|
<th width="80"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="sortable" id="righe">';
|
<tbody class="sortable" id="righe">';
|
||||||
@ -142,23 +146,24 @@ foreach ($righe as $riga) {
|
|||||||
<td></td>';
|
<td></td>';
|
||||||
} else {
|
} else {
|
||||||
// Quantità e unità di misura
|
// Quantità e unità di misura
|
||||||
|
$progress_perc = $riga->qta_evasa * 100 / $riga->qta;
|
||||||
echo '
|
echo '
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<i class="'.($riga->confermato ? 'fa fa-check text-success' : 'fa fa-clock-o text-warning').'"></i>
|
{[ "type": "number", "name": "qta_'.$riga->id.'", "value": "'.$riga->qta.'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-before": "<i class=\''.($riga->confermato ? 'fa fa-check text-success' : 'fa fa-clock-o text-warning').'\'></i>", "icon-after": "<span class=\'tip\' title=\''.tr('Quantità evasa: _QTA_', ['_QTA_' => numberFormat($riga->qta_evasa, 'qta')]).'\'>'.($riga->um ?: ' ').'</span>", "disabled": "'.($riga->isSconto() ? 1 : 0).'", "disabled": "'.$block_edit.'" ]}
|
||||||
'.numberFormat($riga->qta_rimanente, 'qta').' / '.numberFormat($riga->qta, 'qta').' '.$riga->um.'
|
<div class="progress" style="height:4px;">
|
||||||
|
<div class="progress-bar progress-bar-primary" style="width:'.$progress_perc.'%"></div>
|
||||||
|
</div>
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Prezzi unitari
|
// Prezzi unitari
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">';
|
||||||
'.moneyFormat($riga->prezzo_unitario_corrente);
|
// Provvigione riga
|
||||||
|
if (abs($riga->provvigione_unitaria) > 0) {
|
||||||
if ($dir == 'entrata' && $riga->costo_unitario != 0) {
|
$text = provvigioneInfo($riga);
|
||||||
echo '
|
echo '<span class="pull-left text-info" title="'.$text.'"><i class="fa fa-handshake-o"></i></span>';
|
||||||
<br><small class="text-muted">
|
|
||||||
'.tr('Acquisto').': '.moneyFormat($riga->costo_unitario).'
|
|
||||||
</small>';
|
|
||||||
}
|
}
|
||||||
|
echo moneyFormat($riga->prezzo_unitario_corrente);
|
||||||
|
|
||||||
if (abs($riga->sconto_unitario) > 0) {
|
if (abs($riga->sconto_unitario) > 0) {
|
||||||
$text = discountInfo($riga);
|
$text = discountInfo($riga);
|
||||||
@ -170,27 +175,23 @@ foreach ($righe as $riga) {
|
|||||||
echo '
|
echo '
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Iva
|
// Sconto unitario
|
||||||
|
if (!$block_edit) {
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-center">
|
||||||
'.moneyFormat($riga->iva_unitaria_scontata).'
|
{[ "type": "number", "name": "sconto_'.$riga->id.'", "value": "'.($riga->sconto_percentuale ?: $riga->sconto_unitario_corrente).'", "min-value": "0", "onchange": "aggiornaInline($(this).closest(\'tr\').data(\'id\'))", "icon-after": "choice|untprc|'.$riga->tipo_sconto.'" ]}
|
||||||
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
|
||||||
</td>';
|
</td>';
|
||||||
|
}
|
||||||
|
|
||||||
// Importo
|
// Importo
|
||||||
echo '
|
echo '
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
'.moneyFormat($riga->importo);
|
'.moneyFormat($riga->importo);
|
||||||
|
|
||||||
//provvigione riga
|
// Iva
|
||||||
if (abs($riga->provvigione_unitaria) > 0) {
|
|
||||||
$text = provvigioneInfo($riga);
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<br><small class="label label-info">'.$text.'</small>';
|
<br><small class="'.(($riga->aliquota->deleted_at) ? 'text-red' : '').' text-muted">'.$riga->aliquota->descrizione.(($riga->aliquota->esente) ? ' ('.$riga->aliquota->codice_natura_fe.')' : null).'</small>
|
||||||
}
|
</td>';
|
||||||
|
|
||||||
echo '</td>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Possibilità di rimuovere una riga solo se il preventivo non è stato pagato
|
// Possibilità di rimuovere una riga solo se il preventivo non è stato pagato
|
||||||
@ -234,7 +235,7 @@ $netto_a_pagare = $preventivo->netto;
|
|||||||
// Totale imponibile scontato
|
// Totale imponibile scontato
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -247,7 +248,7 @@ echo '
|
|||||||
if (!empty($sconto)) {
|
if (!empty($sconto)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -259,7 +260,7 @@ if (!empty($sconto)) {
|
|||||||
// Totale imponibile scontato
|
// Totale imponibile scontato
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -272,7 +273,7 @@ if (!empty($sconto)) {
|
|||||||
// Totale iva
|
// Totale iva
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Iva', [], ['upper' => true]).':</b>
|
<b>'.tr('Iva', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -284,7 +285,7 @@ echo '
|
|||||||
// Totale
|
// Totale
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
<b>'.tr('Totale', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -297,7 +298,7 @@ echo '
|
|||||||
if (!empty($sconto_finale)) {
|
if (!empty($sconto_finale)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
|
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -311,7 +312,7 @@ if (!empty($sconto_finale)) {
|
|||||||
if ($totale != $netto_a_pagare) {
|
if ($totale != $netto_a_pagare) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -328,7 +329,7 @@ $margine_icon = ($margine <= 0 && $preventivo->totale > 0) ? 'warning' : 'check'
|
|||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Costi').':
|
'.tr('Costi').':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -341,7 +342,7 @@ echo '
|
|||||||
if(!empty($preventivo->provvigione)) {
|
if(!empty($preventivo->provvigione)) {
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Provvigioni').':
|
'.tr('Provvigioni').':
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
@ -353,7 +354,7 @@ echo '
|
|||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Margine (_PRC_%)', [
|
'.tr('Margine (_PRC_%)', [
|
||||||
'_PRC_' => numberFormat($preventivo->margine_percentuale),
|
'_PRC_' => numberFormat($preventivo->margine_percentuale),
|
||||||
]).':
|
]).':
|
||||||
@ -365,7 +366,7 @@ echo '
|
|||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="7" class="text-right">
|
<td colspan="'.$colspan.'" class="text-right">
|
||||||
'.tr('Ricarico (_PRC_%)', [
|
'.tr('Ricarico (_PRC_%)', [
|
||||||
'_PRC_' => numberFormat($preventivo->ricarico_percentuale),
|
'_PRC_' => numberFormat($preventivo->ricarico_percentuale),
|
||||||
]).':
|
]).':
|
||||||
@ -523,4 +524,37 @@ $("#check_all").click(function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".tipo_icon_after").on("change", function() {
|
||||||
|
aggiornaInline($(this).closest("tr").data("id"));
|
||||||
|
});
|
||||||
|
|
||||||
|
function aggiornaInline(id) {
|
||||||
|
content_was_modified = false;
|
||||||
|
var qta = input("qta_"+ id).get();
|
||||||
|
var sconto = input("sconto_"+ id).get();
|
||||||
|
var tipo_sconto = input("tipo_sconto_"+ id).get();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: globals.rootdir + "/actions.php",
|
||||||
|
type: "POST",
|
||||||
|
data: {
|
||||||
|
id_module: globals.id_module,
|
||||||
|
id_record: globals.id_record,
|
||||||
|
op: "update_inline",
|
||||||
|
riga_id: id,
|
||||||
|
qta: qta,
|
||||||
|
sconto: sconto,
|
||||||
|
tipo_sconto: tipo_sconto,
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
caricaRighe(id);
|
||||||
|
renderMessages();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
caricaRighe(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
init();
|
||||||
</script>';
|
</script>';
|
||||||
|
@ -287,7 +287,7 @@ class HTMLWrapper implements WrapperInterface
|
|||||||
|
|
||||||
$value = (empty($pieces[2]) || !in_array($pieces[2], array_column($choices, 'id'))) ? $choices[0]['id'] : $pieces[2];
|
$value = (empty($pieces[2]) || !in_array($pieces[2], array_column($choices, 'id'))) ? $choices[0]['id'] : $pieces[2];
|
||||||
|
|
||||||
$result = '{[ "type": "select", "name": "tipo_'.prepareToField($values['name']).'", "id": "tipo_'.prepareToField($values['name']).'_'.rand(0, 99).'", "value": "'.prepareToField($value).'", "values": '.json_encode($choices).', "class": "no-search", "extra": "'.$extra.'" ]}';
|
$result = '{[ "type": "select", "name": "tipo_'.prepareToField($values['name']).'", "id": "tipo_'.prepareToField($values['name']).'_'.rand(0, 99).'", "value": "'.prepareToField($value).'", "values": '.json_encode($choices).', "class": "no-search tipo_icon_after", "extra": "'.$extra.'" ]}';
|
||||||
|
|
||||||
$result = \HTMLBuilder\HTMLBuilder::replace($result);
|
$result = \HTMLBuilder\HTMLBuilder::replace($result);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user