<DateFieldtype="date"id="dataInicioDespesas"caption="Data inicial"width="100%"expandRatio="0.5"description="Data inicial da exibição"format="dd/MM/yyyy"/>
<DateFieldtype="date"id="dataFinalDespesas"caption="Data final"width="100%"expandRatio="0.5"description="Data final da exibição"format="dd/MM/yyyy"/>
</HorizontalLayout>
</Panel>
<ButtonWidgetid="btnFiltrar"caption="Filtrar"description="Aplica filtro de data"width="100">
<ButtonWidgetid="btnFiltrar"caption="Filtrar"description="Aplica filtro de data"width="100">
<onClickScriptlanguage="JavaScript">
<onClickScriptlanguage="JavaScript">
<![CDATA[
<![CDATA[
@ -76,37 +88,49 @@
if(engine) {
if(engine) {
var sql = "";
var sql = "";
if (engine.getField('dataInicio').getValue() && engine.getField('dataFinal').getValue()) {
if (engine.getField('dataInicio').getValue() && engine.getField('dataFinal').getValue()&& engine.getField('dataInicioDespesas').getValue() && engine.getField('dataFinalDespesas').getValue()) {
var c = java.util.Calendar.getInstance();
var c = java.util.Calendar.getInstance();
var formatter = new java.text.SimpleDateFormat("dd/MM/yyyy");
var formatter = new java.text.SimpleDateFormat("dd/MM/yyyy");
"case s.faturamento when 0 then '0,00' else replace(to_char(s.faturamento,'FM999999999.00'),'.',',') end faturado, " +
"case (s.despesa_combustivel + s.despesa_operacional) when 0 then '0,00' else replace(to_char((s.despesa_combustivel + s.despesa_operacional),'FM999999999.00'),'.',',') end despesa, " +
"case (s.faturamento - (s.despesa_combustivel + s.despesa_operacional)) when 0 then '0,00' else replace(to_char(s.faturamento - (s.despesa_combustivel + s.despesa_operacional), 'FM999999999.00'),'.',',') end liquido, " +
" case s.faturamento when 0 then '0,00' else replace(to_char(((s.faturamento - (s.despesa_combustivel + s.despesa_operacional))/s.faturamento * 100),'FM999999999.00'),'.',',') end perc_lucro " +
"case s.faturamento when 0 then 'R$ 0,00' else 'R$ ' || replace(to_char(s.faturamento,'FM999999999.00'),'.',',') end faturado, " +
"case (s.despesa_combustivel + s.despesa_operacional) when 0 then 'R$ 0,00' else 'R$ ' || replace(to_char((s.despesa_combustivel + s.despesa_operacional),'FM999999999.00'),'.',',') end despesa, " +
"case (s.faturamento - (s.despesa_combustivel + s.despesa_operacional)) when 0 then 'R$ 0,00' else 'R$ ' || replace(to_char(s.faturamento - (s.despesa_combustivel + s.despesa_operacional), 'FM999999999.00'),'.',',') end liquido, " +
" case s.faturamento when 0 then 'R$ 0,00' else 'R$ ' || replace(to_char(((s.faturamento - (s.despesa_combustivel + s.despesa_operacional))/s.faturamento * 100),'FM999999999.00'),'.',',') end perc_lucro " +
" from (Select o.codigo, o.nome, " +
" from (Select o.codigo, o.nome, " +
" (Select coalesce(sum(crf.valor_liquido),0) from controle_receitas_fretes crf where crf.chave_operacao = o.codigo and crf.data between to_date('"+dataInicio+"','dd/MM/yyyy') and to_date('"+dataFinal+"','dd/MM/yyyy')) faturamento, " +
" (Select coalesce(sum(cdb.total_combustivel),0) from controle_despesas_combustiveis cdb where cdb.chave_operacao = o.codigo and cdb.data between to_date('"+dataInicio+"','dd/MM/yyyy') and to_date('"+dataFinal+"','dd/MM/yyyy')) despesa_combustivel, " +
" (Select coalesce(sum(cdo.valor),0) from controle_despesas_operacionais cdo where cdo.chave_operacao = o.codigo and cdo.data between to_date('"+dataInicio+"','dd/MM/yyyy') and to_date('"+dataFinal+"','dd/MM/yyyy')) despesa_operacional " +
"from operacao o) s " +
" (Select coalesce(sum(crf.valor_liquido),0) from controle_receitas_fretes crf where crf.chave_cliente = o.codigo and crf.data between to_date('"+dataInicio+"','dd/MM/yyyy') and to_date('"+dataFinal+"','dd/MM/yyyy')) faturamento, " +
" (Select coalesce(sum(cdb.total_combustivel),0) from controle_despesas_combustiveis cdb where cdb.chave_cliente = o.codigo and cdb.data between to_date('"+dataInicioDespesas+"','dd/MM/yyyy') and to_date('"+dataFinalDespesas+"','dd/MM/yyyy')) despesa_combustivel, " +
" (Select coalesce(sum(cdo.valor),0) from controle_despesas_operacionais cdo where cdo.chave_cliente = o.codigo and cdo.data between to_date('"+dataInicioDespesas+"','dd/MM/yyyy') and to_date('"+dataFinalDespesas+"','dd/MM/yyyy')) despesa_operacional " +
"from clientes o) s " +
"union all " +
"union all " +
" Select 'TOTAL' nome, " +
" Select 'TOTAL' nome, " +
"case s.faturamento when 0 then '0,00' else replace(to_char(s.faturamento,'FM999999999.00'),'.',',') end faturado, " +
"case (s.despesa_combustivel + s.despesa_operacional) when 0 then '0,00' else replace(to_char((s.despesa_combustivel + s.despesa_operacional),'FM999999999.00'),'.',',') end despesa, " +
"case (s.faturamento - (s.despesa_combustivel + s.despesa_operacional)) when 0 then '0,00' else replace(to_char(s.faturamento - (s.despesa_combustivel + s.despesa_operacional), 'FM999999999.00'),'.',',') end liquido, " +
" case s.faturamento when 0 then '0,00' else replace(to_char(((s.faturamento - (s.despesa_combustivel + s.despesa_operacional))/s.faturamento * 100),'FM999999999.00'),'.',',') end perc_lucro " +
"case s.faturamento when 0 then 'R$ 0,00' else 'R$ ' || replace(to_char(s.faturamento,'FM999999999.00'),'.',',') end faturado, " +
"case (s.despesa_combustivel + s.despesa_operacional) when 0 then 'R$ 0,00' else 'R$ ' || replace(to_char((s.despesa_combustivel + s.despesa_operacional),'FM999999999.00'),'.',',') end despesa, " +
"case (s.faturamento - (s.despesa_combustivel + s.despesa_operacional)) when 0 then 'R$ 0,00' else 'R$ ' || replace(to_char(s.faturamento - (s.despesa_combustivel + s.despesa_operacional), 'FM999999999.00'),'.',',') end liquido, " +
" case s.faturamento when 0 then 'R$ 0,00' else 'R$ ' || replace(to_char(((s.faturamento - (s.despesa_combustivel + s.despesa_operacional))/s.faturamento * 100),'FM999999999.00'),'.',',') end perc_lucro " +
" from (Select " +
" from (Select " +
" (Select coalesce(sum(crf.valor_liquido),0) from controle_receitas_fretes crf where crf.data between to_date('"+dataInicio+"','dd/MM/yyyy') and to_date('"+dataFinal+"','dd/MM/yyyy')) faturamento, " +
" (Select coalesce(sum(crf.valor_liquido),0) from controle_receitas_fretes crf where crf.data between to_date('"+dataInicio+"','dd/MM/yyyy') and to_date('"+dataFinal+"','dd/MM/yyyy')) faturamento, " +
" (Select coalesce(sum(cdb.total_combustivel),0) from controle_despesas_combustiveis cdb where cdb.data between to_date('"+dataInicio+"','dd/MM/yyyy') and to_date('"+dataFinal+"','dd/MM/yyyy')) despesa_combustivel, " +
" (Select coalesce(sum(cdo.valor),0) from controle_despesas_operacionais cdo where cdo.data between to_date('"+dataInicio+"','dd/MM/yyyy') and to_date('"+dataFinal+"','dd/MM/yyyy')) despesa_operacional) s";
" (Select coalesce(sum(cdb.total_combustivel),0) from controle_despesas_combustiveis cdb where cdb.data between to_date('"+dataInicioDespesas+"','dd/MM/yyyy') and to_date('"+dataFinalDespesas+"','dd/MM/yyyy')) despesa_combustivel, " +
" (Select coalesce(sum(cdo.valor),0) from controle_despesas_operacionais cdo where cdo.data between to_date('"+dataInicioDespesas+"','dd/MM/yyyy') and to_date('"+dataFinalDespesas+"','dd/MM/yyyy')) despesa_operacional) s";
<DecimalFieldtype="decimal"id="valorLiquido"caption="Frete - Impostos (R$)"format="#,##0.00"description="Valor frete menos o valor dos impostos"width="100%"expandRatio="0.2"/>
<DecimalFieldtype="decimal"id="valorLiquido"caption="Valor Líquido (Frete - Impostos) (R$)"format="#,##0.00"description="Valor frete menos o valor dos impostos"width="100%"expandRatio="0.2"/>
<ButtonWidgetid="btnGravar"caption="Gravar"align="BOTTOM_RIGHT"description="Grava o lançamento"width="100">
<ButtonWidgetid="btnGravar"caption="Gravar"align="BOTTOM_RIGHT"description="Grava o lançamento"width="100">
<onClickScriptlanguage="JavaScript">
<onClickScriptlanguage="JavaScript">
<![CDATA[
<![CDATA[
@ -284,8 +294,8 @@
var dbVitruvio = new db('vitruvio');
var dbVitruvio = new db('vitruvio');
var sql;
var sql;
dbVitruvio.transaction(function() {
dbVitruvio.transaction(function() {
sql = "insert into controle_receitas_fretes (chave_receita_frete,data,chave_cliente,chave_veiculo,chave_funcionario,valor_frete,valor_imposto,valor_liquido,chave_tipo_frete,cte,frota_terceiro,uf_origem,uf_destino,chave_forma_pagamento) " +