gest366/modules/contratti_tipo/add_articolo.php

287 lines
9.7 KiB
PHP

<?php
include_once(__DIR__."/../../core.php");
include($docroot."/config.inc.php");
$module_name = 'Tipi di canone';
$iddocumento = $html->form('iddocumento');
$dir = "entrata";
$filtra_art = $html->form('filtra_art');
//Info tipologia canone
$q = "SELECT * FROM co_contratti_tipi WHERE id='".$iddocumento."'";
$rs = $dbo->fetchArray($q);
$desc_canone=$rs[0]['descrizione'];
$query = "SELECT * FROM mg_articoli WHERE attivo=1 and servizio=1 ORDER BY id_categoria ASC, id_sottocategoria ASC";
$rs = $dbo->fetchArray( $query );
$n = sizeof($rs);
$um = $rs[0]['um'];
/*
Form di inserimento riga
*/
echo "<label>Tipologia canone $desc_canone</label><br><br>\n";
echo "<form id=\"link_form\" action=\"".$rootdir."/editor.php?id_module=".$modules_info[$module_name]['id']."&id_record=".$iddocumento."\" method=\"post\">\n";
echo " <input type='hidden' name='op' value='addarticolo'>\n";
echo " <input type='hidden' name='dir' value='".$dir."'>\n";
echo " <input type='hidden' name='backto' value='record-edit'>\n";
echo " <div class='row'>\n";
//Seleziona articolo
echo " <div class='col-md-6'>\n";
echo " <label>Articolo di Servizio</label>\n";
if( $n==0 ){
echo " "._("Non ci sono articoli")."\n";
echo " <input type=\"hidden\" id=\"idarticolo\" value=\"0\">\n";
}
else{
$other_js = " $('#idiva').val( $(this).find('option:selected').attr('idiva_vendita') ); $('#idiva').trigger('liszt:updated'); ";
$other_js = '';
//Elenco articoli raggruppati per gruppi e sottogruppi
echo " <select id=\"idarticolo\" name=\"idarticolo\" class=\"superselectajax\" data-source=\"articoli_filtro_servizi\" onchange=\"$('#prezzi').html(''); $('#qta').keyup(); $.get( '".$rootdir."/ajax_autocomplete.php?module=Articoli&op=getlotti&idarticolo='+$(this).find('option:selected').val(), function(data){ $('#lotto').html(data); update_jchosen('#lotto'); }); $('textarea[name=descrizione]').val( $(this).find('option:selected').attr('descrizione') ); $other_js\">\n";
echo " <option value=\"0\">- Seleziona un articolo -</option>\n";
for( $i=0; $i<$n; $i++ ){
if( $rs[$i-1]['categoria'] != $rs[$i]['categoria'] ){
echo " <optgroup label='".$rs[$i]['categoria']."'>\n";
}
if( $rs[$i-1]['subcategoria'] != $rs[$i]['subcategoria'] ){
echo " <optgroup label='&nbsp;&nbsp;".$rs[$i]['subcategoria']."'>\n";
}
//Cerco listino personalizzato
$rslist = $dbo->fetchArray("SELECT prc_guadagno FROM mg_listini_art WHERE idlistino='".$id_listino."' and idarticolo='".$rs[$i]['id']."'");
if( $rslist[0]['prc_guadagno'] <> '0' && sizeof($rslist)>0 ){
$prc_guadagno_new = - $rslist[0]['prc_guadagno'];
}
else{
$prc_guadagno_new = -$prc_guadagno;
}
if( $dir == 'entrata' ){
echo " <option value=\"".$rs[$i]['id']."\" sconto='".$prc_guadagno_new."' idconto_riga='".$rs[$i]['id_conto']."' qta_magazzino='".floatval($rs[$i]['qta'])."' prezzo=\"".floatval($rs[$i]['prezzo_vendita'])."\" guadagno=\"".($rs[$i]['prezzo_vendita']/100*$prc_guadagno)."\" idiva=\"".intval($rs[$i]['idiva_vendita'])."\" descrizione=\"".$rs[$i]['descrizione']."\">".$rs[$i]['codice']." - ".$rs[$i]['descrizione']." (".floatval($rs[$i]['qta']).")</option>\n";
}
else{
echo " <option value=\"".$rs[$i]['id']."\" sconto='".$prc_guadagno_new."' idconto_riga='".$rs[$i]['id_conto']."' qta_magazzino='".floatval($rs[$i]['qta'])."' prezzo=\"".floatval($rs[$i]['prezzo_acquisto'])."\" guadagno=\"".($rs[$i]['prezzo_vendita']/100*$prc_guadagno)."\" idiva=\"".intval($rs[$i]['idiva_vendita'])."\" descrizione=\"".$rs[$i]['descrizione']."\">".$rs[$i]['codice']." - ".$rs[$i]['descrizione']." (".floatval($rs[$i]['qta']).")</option>\n";
}
if( $rs[$i]['categoria'] != $rs[$i+1]['categoria'] ){
echo " </optgroup>\n";
}
if( $rs[$i]['subcategoria'] != $rs[$i+1]['subcategoria'] ){
echo " </optgroup>\n";
}
}
}
echo " </select>\n";
echo " </div>\n";
//Fltra per Categoria
$query = "SELECT * FROM mg_categorie where parent='0' order by nome";
$rs_cat = $dbo->fetchArray($query);
echo " <div class='col-md-4'>\n";
echo " <label>Categoria articolo</label>\n";
echo " <select id='idcategoria' class='superselect' name=\"idcategoria\">\n";
echo " <option value='0'>Nessun Filtro</option>\n";
for( $i=0; $i<sizeof($rs); $i++ ){
echo " <option value='".$rs_cat[$i]['id']."' $attr>".$rs_cat[$i]['nome']."</option>\n";
}
echo " </select>\n";
echo " </div>\n";
echo " </div>\n";
//Descrizione
echo " <div class='row'>\n";
echo " <div class='col-md-12'>\n";
echo " <label>Descrizione</label>\n";
echo " <textarea name='descrizione' id='descrizione_art' class='form-control'></textarea>\n";
echo " </div>\n";
echo " </div>\n";
echo "<br>";
echo "<div class='panel panel-primary'>";
echo "<div class='panel-body'>";
echo " <div class='row'>\n";
//Quantità
echo " <div class='col-md-3'>\n";
echo " <div class='form-group'>\n";
echo " <label>Q.t&agrave;</label>\n";
echo " <div class='input-group'>\n";
echo " <input type='text' class='form-control inputmask-decimal' id='qta' maxlength='8' name='qta' value=\"1\"><span class='input-group-addon'>".$um."</span>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
//Costo unitario
echo " <div class='col-md-3'>\n";
echo " <div class='form-group'>\n";
echo " <label>Costo unitario</label>\n";
echo " <div class='input-group'>\n";
echo " <input type='text' class='form-control inputmask-decimal' id='prezzo' name='prezzo' value=\"0,00\"><span class='input-group-addon'>&euro;</span>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo "<div class='panel panel-primary'>";
echo "<div class='panel-body'>";
echo " <div class='row'>\n";
//Sconto
echo " <div class='col-md-3'>\n";
echo " <div class='form-group'>\n";
echo " <label>Sconto</label>\n";
echo " <div class='input-group'>\n";
echo " <input type='text' class='form-control inputmask-decimal' id='sconto' name='sconto' value=\"0,00\" /><span class='input-group-addon'></span>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
//Sconto Extra
echo " <div class='col-md-3'>\n";
echo " <div class='form-group'>\n";
echo " <label>Extra Sconto</label>\n";
echo " <div class='input-group'>\n";
echo " <input type='text' class='form-control inputmask-decimal' id='sconto_extra' name='sconto_extra' value=\"0,00\" /><span class='input-group-addon'></span>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
//Sconto Extra1
echo " <div class='col-md-3'>\n";
echo " <div class='form-group'>\n";
echo " <label>Extra Sconto</label>\n";
echo " <div class='input-group'>\n";
echo " <input type='text' class='form-control inputmask-decimal' id='sconto_extra1' name='sconto_extra1' value=\"0,00\" /><span class='input-group-addon'></span>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
//Tipo Sconto
$query = "SELECT * FROM co_tipisconto";
$rs = $dbo->fetchArray($query);
echo " <div class='col-md-3'>\n";
echo " <label>Tipologia Sconto</label>\n";
echo " <select id='idtiposconto' class='superselect' name=\"idtiposconto\">\n";
echo " <option value='2'>Percentuale</option>\n";
for( $i=0; $i<sizeof($rs); $i++ ){
echo " <option value='".$rs[$i]['id']."' $attr>".$rs[$i]['descrizione']."</option>\n";
}
echo " </select>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
?>
<script type="text/javascript">
dir = '<?php echo $dir ?>';
$('#idcategoria').change( function(){
$.get('<?php echo $rootdir ?>/ajax_autocomplete.php?module=FiltroCat&idcategoria='+this.value+'&idmodulo='+id_module , function(data,response){
start_jquerychosen();
start_inputmask();
});
});
function addarticolo(){
if( $('#idarticolo').val()!='' && $('#idiva option:selected').val()!='' ){
$("#link_form").submit();
}
}
function addarticolo_vendita(){
if( $('#idarticolo').val()!='' && $('#idiva option:selected').val()!='' ){
$("#link_form").submit();
}
}
function addarticolo_acquisto(){
if( $('#idarticolo').val()!='' && $('#idiva option:selected').val()!='' ){
$("#link_form").submit();
}
}
function ricalcola_totale( dir ){
max_qta = $('#idarticolo option:selected').attr('qta_magazzino');
max_qta = force_decimal( max_qta );
qta = $('#qta').val();
qta_commas = qta.replace('.', ',');
qta=1;
prezzo = $('#idarticolo').find('option:selected').attr('prezzo');
prezzo = force_decimal( prezzo );
sconto = $('#idarticolo').find('option:selected').attr('sconto');
sconto = force_decimal( sconto );
$('#prezzo').val( decimals_with_commas( prezzo, 2 ) );
$('#sconto').val( decimals_with_commas( sconto, 2 ) );
}
$(document).ready( function(){
$('#qta, #idarticolo').keyup( function(){
ricalcola_totale( '<?php echo $dir ?>' );
});
});
</script>
<script src="<?php echo $rootdir; ?>/lib/init.js"></script>
<?php
if( $dir=='entrata' )
echo "<a onclick=\"addarticolo_vendita();\" class=\"btn btn-primary pull-right\"><i class=\"fa fa-plus\"></i> Aggiungi</a>\n";
else
echo "<a onclick=\"addarticolo_acquisto();\" class=\"btn btn-primary pull-right\"><i class=\"fa fa-plus\"></i> Aggiungi</a>\n";
echo "</form>\n";
?>
<div class="clearfix"></div>