@ -43,7 +43,8 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
importClass(Packages.br.com.davinti.base.vaadin.components.resources.icons16x16.IconLibraryAPISmall);
importClass(Packages.java.util.Calendar);
importClass(Packages.br.com.davinti.base.vaadin.components.layout.MessageBox);
importClass(Packages.com.vaadin.ui.Notification);
importClass(Packages.com.vaadin.ui.Notification);
importClass(Packages.com.vaadin.server.FontAwesome);
var getDataAtual = function() {
@ -62,6 +63,10 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
var config = engine.getGlobalVariable('config');
var lib = libService.loadScript('lib_cadastro_padrao');
var retorno = lib.fncLimpaCampos(config);
engine.getField('percentualSocio')['setValue(java.lang.String)'](null);
engine.getField('socioLista').getContainerDataSource().removeAllItems();
engine.getField('socioPercentual').getContainerDataSource().removeAllItems();
engine.getField('twinUsuario')["setValue(java.lang.Object)"](null);
};
var habilitaCampos = function(lHabilita){
@ -113,6 +118,21 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
var config = engine.getGlobalVariable('config');
var lib = libService.loadScript('lib_cadastro_padrao');
var sql = lib.fncCarregarCampos(config, id);
var sql = "Select s.nome, os.participacao from operacao_socio os inner join operacao o on o.codigo = os.codigo_operacao inner join socios s on s.codigo = os.codigo_socio where os.codigo_operacao = " + id;
var db = libService.loadScript('db');
var dbVitruvio = new db('vitruvio');
var containerPercentual = engine.getField("socioPercentual").getContainerDataSource();
var containerSocio = engine.getField("socioLista").getContainerDataSource();
dbVitruvio.query(sql).each(function (r) {
containerSocio.addItem(r.nome).getItemProperty("caption").setValue(r.nome);
containerPercentual.addItem(r.nome).getItemProperty("caption").setValue(String(r.participacao));
});
sql = "Select codigo_usuario from operacao_usuario where codigo_operacao = " + id;
var ids = new java.util.ArrayList();
dbVitruvio.query(sql).each(function (r) {
ids.add(r.codigo_usuario);
});
engine.getField('twinUsuario').setValue(ids);
};
@ -148,10 +168,14 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
var db = libService.loadScript('db');
var dbVitruvio = new db('vitruvio');
var row = dbVitruvio.queryRow(sql);
if (row.ct == 0) {
if (row.ct == 0 ) {
return false;
} else {
return true
if (engine.getField('idChave').getValue()) {
return false;
} else {
return true;
}
}
}
@ -170,6 +194,7 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
engine.setGlobalVariable('deletarRegistro', deletarRegistro);
engine.setGlobalVariable('validarDuplicidade', validarDuplicidade);
engine.setGlobalVariable('painelLista',1);
engine.getField('socioPercentual').setEnabled(false);
//fncLimpaCampos();
habilitaCampos(false);
@ -178,6 +203,8 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
engine.getWidgetController('btnNovo').getButton().setIcon(IconFactory.instance().getIconAsResource(IconLibraryAPISmall.CRIAR));
engine.getWidgetController('btnExcluir').getButton().setIcon(IconFactory.instance().getIconAsResource(IconLibraryAPISmall.REMOVER));
engine.getWidgetController('btnVoltar').getButton().setIcon(IconFactory.instance().getIconAsResource(IconLibraryAPISmall.VOLTAR));
engine.getWidgetController('btnPercentual').getButton().setIcon(FontAwesome.PLUS);
engine.getWidgetController('btnRemoverPercentual').getButton().setIcon(FontAwesome.MINUS);
//engine.getFieldLocked('idAjuda', false); // pode ser erro no componente, aberto caso Eduardo = 20108
telaInicial();
@ -276,7 +303,7 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
engine.getGlobalVariable('carregarCampos')(id);
engine.getGlobalVariable('habilitaCampos')(true);
engine.getLayout('pnlInclusao').getRootComposition().setVisible(true);
engine.getLayout('pnlTitulo').getRootComposition().setVisible(false);
engine.getLayout('pnlTitulo').getRootComposition().setVisible(false);
}
}, 'pencil');
@ -385,12 +412,135 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
<HorizontalLayout spacing= "true" width= "100%" >
<TextField type= "number" id= "idChave" width= "100%" caption= "Código" expandRatio= "0.08" />
<TextField type= "string" id= "idDescricao" text-transform= "uppercase" caption= "Descrição" required= "true" width= "100%" expandRatio= "1" />
</HorizontalLayout>
</HorizontalLayout>
<TabLayout compact= "true" width= "100%" >
<Tab caption= "Sócios" >
<VerticalLayout spacing= "true" width= "100%" >
<Label id= "lb1" >
<value >
</value>
</Label>
<HorizontalLayout spacing= "true" width= "420" >
<DBComboBox type= "string" id= "socios" caption= "Sócio" width= "100%" expandRatio= "0.8" description= "Selecione um sócio" allowNullSelection= "true" searchCaption= "Digite para localizar..." >
<datasource >
<freeQuery connection-key= "vitruvio" >
< ![CDATA[
Select nome from socios where not exists (Select 1 from operacao_socio where codigo_operacao = ${op}) and despesas_particulares = 0
]]>
</freeQuery>
</datasource>
<key-field > NOME</key-field>
<caption-field > NOME</caption-field>
<bind >
<parameter value-type= "number" defaultValue= "-1" parameterName= "op" field-ref= "idChave" />
</bind>
</DBComboBox>
<DecimalField caption= "% Participação" expandRatio= "0.2" maximumValue= "100" maxLength= "6" type= "decimal" id= "percentualSocio" width= "100%" align= "TOP_LEFT" description= "Percentual de participação do sócio" />
<ButtonWidget id= "btnPercentual" description= "Adicionar percentual" height= "25" align= "BOTTOM_LEFT" >
<onClickScript language= "JavaScript" >
< ![CDATA[
importClass(Packages.br.com.davinti.base.vaadin.components.layout.MessageBox);
function run() {
var containerPercentual = engine.getField("socioPercentual").getContainerDataSource();
var containerSocio = engine.getField("socioLista").getContainerDataSource();
var ids = engine.getField('socioLista').getContainerDataSource().getItemIds();
var iter = ids.iterator();
var total = 0.00;
var definido = 0;
while (iter.hasNext()) {
var value = iter.next();
if (engine.getField('socios').getValue() == value) {
MessageBox.show(MessageBox.BoxType.INFO, 'Atenção', 'O sócio já possui percentual definido.');
definido = 1;
}
total = parseFloat(total) + parseFloat(String(engine.getField('socioPercentual').getContainerDataSource().getItem(value)).replace(',','.'));
}
if (engine.getField('socioPercentual').getContainerDataSource().getItem(value)) {
var valor = String(engine.getField('percentualSocio').getValue());
total = (parseFloat(total) + parseFloat(engine.getField('percentualSocio').getConvertedValue()));
} else {
total = engine.getField('percentualSocio').getConvertedValue();
}
if (definido == 0) {
if (total < = 100.00) {
containerSocio.addItem(engine.getField('socios').getValue()).getItemProperty("caption").setValue(engine.getField('socios').getValue());
containerPercentual.addItem(engine.getField('socios').getValue()).getItemProperty("caption").setValue(String(engine.getField('percentualSocio').getValue()));
} else {
MessageBox.show(MessageBox.BoxType.INFO, 'Atenção', 'Percentual não pode ultrapassar 100%.');
}
}
}
]]>
</onClickScript>
</ButtonWidget>
<ButtonWidget id= "btnRemoverPercentual" description= "Remover percentual" height= "25" align= "BOTTOM_LEFT" >
<onClickScript language= "JavaScript" >
< ![CDATA[
importClass(Packages.br.com.davinti.base.vaadin.components.layout.MessageBox);
function run() {
var texto = engine.getField('socioLista').getValue();
if (texto != '') {
try {
var container = engine.getField("socioLista").getContainerDataSource();
container.removeItem(texto);
var container2 = engine.getField("socioPercentual").getContainerDataSource();
container2.removeItem(texto);
} catch(e) {
MessageBox.show('Alerta', 'Dados inválidos!');
}
}
};
]]>
</onClickScript>
</ButtonWidget>
</HorizontalLayout>
<HorizontalLayout width= "420" >
<ListSelect type= "string" id= "socioLista" readOnly= "true" width= "100%" expandRatio= "0.8" allowNullSelection= "true" rows= "5" >
<events >
<valueChange >
<script language= "JavaScript" >
< ![CDATA[
function run() {
engine.getField('socioPercentual').setValue(engine.getField('socioLista').getValue());
}
]]>
</script>
</valueChange>
</events>
</ListSelect>
<ListSelect type= "string" id= "socioPercentual" readOnly= "true" width= "100%" expandRatio= "0.2" allowNullSelection= "true" rows= "5" >
</ListSelect>
</HorizontalLayout>
</VerticalLayout>
</Tab>
<Tab caption= "Usuários" >
<VerticalLayout margin= "false" width= "100%" >
<Label id= "lb2" >
<value >
</value>
</Label>
<DBTwinColSelect type= "number" id= "twinUsuario" allowNullSelection= "true" multivalue= "true" width= "70%" align= "TOP_LEFT" >
<datasource >
<freeQuery connection-key= "vitruvio" >
< ![CDATA[
Select usuario_id, nome from nauth.usuario where ativo = true
]]>
</freeQuery>
</datasource>
<key-field > USUARIO_ID</key-field>
<caption-field > NOME</caption-field>
</DBTwinColSelect>
</VerticalLayout>
</Tab>
</TabLayout>
</VerticalLayout>
</Tab>
</TabLayout>
</VerticalLayout>
</Panel>
<Panel width= "100%" margin= "false" id= "pnlBotoes" >
<VerticalLayout width= "100%" >
@ -404,14 +554,79 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
if (engine.getGlobalVariable('validarDuplicidade')(engine.getField('idDescricao').getValue())) {
MessageBox.show(MessageBox.BoxType.INFO, 'Atenção', 'Já existe uma operação cadastrada com este nome.');
} else {
var config = engine.getGlobalVariable('config');
var id = engine.getField('idChave').getConvertedValue();
var lib = libService.loadScript('lib_cadastro_padrao');
var retorno = lib.fncGravarRegistro(config, id);
if (retorno) {
engine.getGlobalVariable('fncLimpaCampos')();
}
var containerSocio = engine.getField("socioLista").getContainerDataSource();
var containerPercentual = engine.getField("socioPercentual").getContainerDataSource();
var ids = engine.getField('socioLista').getContainerDataSource().getItemIds();
var iter = ids.iterator();
var total = 0.00;
while (iter.hasNext()) {
var value = iter.next();
total = parseFloat(total) + parseFloat(String(engine.getField('socioPercentual').getContainerDataSource().getItem(value)).replace(',','.'));
}
if (total != 100.00) {
MessageBox.show(MessageBox.BoxType.INFO, 'Atenção', 'Percentual deve ser igual a 100%.');
} else {
var config = engine.getGlobalVariable('config');
var id = engine.getField('idChave').getConvertedValue();
var lib = libService.loadScript('lib_cadastro_padrao');
var retorno = lib.fncGravarRegistro(config, id);
var db = libService.loadScript('db');
var dbVitruvio = new db('vitruvio');
var sql;
var socio;
var percentual;
var iter2 = ids.iterator();
dbVitruvio.transaction(function() {
sql = "delete from operacao_socio where codigo_operacao = :operacao";
this.update(sql, {
operacao: Number(retorno)
});
});
while (iter2.hasNext()) {
var value = iter2.next();
var row = dbVitruvio.queryRow("Select codigo from socios where nome = '" + String(engine.getField('socioLista').getContainerDataSource().getItem(value)) + "'");
if (row.codigo) {
socio = row.codigo
}
percentual = parseFloat(String(engine.getField('socioPercentual').getContainerDataSource().getItem(value)).replace(',','.'));
dbVitruvio.transaction(function() {
sql = "insert into operacao_socio (codigo,codigo_operacao,codigo_socio,participacao) values (" + dbVitruvio.getSequenceNextValSql('operacao_socios_seq') + ",:operacao,:socio,:participacao)";
this.update(sql, {
operacao: Number(retorno),
socio: Number(socio),
participacao: percentual
});
});
}
dbVitruvio.transaction(function() {
sql = "delete from operacao_usuario where codigo_operacao = :operacao";
this.update(sql, {
operacao: Number(retorno)
});
});
var u = engine.getField('twinUsuario').getValue();
var i = u.iterator();
while (i.hasNext()) {
dbVitruvio.transaction(function() {
sql = "insert into operacao_usuario (codigo,codigo_operacao,codigo_usuario) values (" + dbVitruvio.getSequenceNextValSql('operacao_usuario_seq') + ",:operacao,:usuario)";
this.update(sql, {
operacao: Number(retorno),
usuario: Number(i.next())
});
});
}
if (retorno) {
engine.getGlobalVariable('fncLimpaCampos')();
}
}
}
}
}
@ -422,8 +637,9 @@ xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbuc
<onClickScript language= "JavaScript" >
< ![CDATA[
function run() {
engine.setGlobalVariable('painelLista',0);
engine.getGlobalVariable('novoRegistro')();
//engine.setGlobalVariable('painelLista',0);
//engine.getGlobalVariable('novoRegistro')();
engine.debug(engine.getField('twinUsuario').getValue());
}
]]>
</onClickScript>