Posted 24 June 2021, 7:57 am EST
Did not attach code to ticket
<wj-flex-grid
ref="gridDados"
:show-selected-headers="'All'"
:show-marquee="true"
:sticky-headers="true"
:items-source="dados"
:allow-merging="'Cells'"
:is-read-only="true"
:alternating-row-step="0"
:auto-generate-columns="false"
:initialized="initializeGrid"
:selection-changed="selectionChanged"
:group-header-format="'<b>{value}</b> ( {count} itens )'"
---> :format-item="wijmoCalculoAgrupamento"
style="width: 100%; border-radius: 0"
class="grid"
allow-pinning="SingleColumn"
@mouseover.native="mouseOver"
>
wijmoCalculoAgrupamento(s, e) {
/*
Método para cálculo de agrupamento da grid
*/
if (e.panel == s.cells) {
var row = s.rows[e.row];
var col = s.columns[e.col];
var group = row instanceof wjcGrid.GroupRow ? row.dataItem : null;
var CalculoPorTotais = true;
var itens = 0;
var sumVENDA_DE = 0;
var sumVENDA_POR = 0;
var sumVLR_CUSTO = 0;
var calcCE113_PC_MARKUP_DE = 0;
var calcCE113_PC_MARKUP_POR = 0;
var calcMARGEM_LUCRO = 0;
var calcLUCRO = 0;
var calcLUCRO_INVERSO = 0;
var calcLUCRO_INVERSOPERC = 0;
var totsumVENDA_DE = this.flex.columnFooters.getCellData(0, 'ce110_vl_venda_de');
var totsumVENDA_POR = this.flex.columnFooters.getCellData(0, 'ce110_vl_venda_por');
var totsumVLR_CUSTO = this.flex.columnFooters.getCellData(0, 'vl_custo');
var totsumMARKUP_DE = this.flex.columnFooters.getCellData(0, 'ce113_pc_markup_de');
var totsumMARKUP_POR = this.flex.columnFooters.getCellData(0, 'ce113_pc_markup_por');
if (CalculoPorTotais) {
console.log("CalculoPorTotais");
// Rodapé - https://www.grapecity.com/forums/wijmo/custom-summary#good-morning-it-worked-tha
this.flex.columnFooters.setCellData(0,'ce113_pc_markup_de', ( totsumVLR_CUSTO > 0 ? (totsumVENDA_DE / totsumVLR_CUSTO) * 100 - 100 : 0));
this.flex.columnFooters.setCellData(0,'ce113_pc_markup_por', ( totsumVLR_CUSTO > 0 ? (totsumVENDA_POR / totsumVLR_CUSTO) * 100 - 100 : 0));
this.flex.columnFooters.setCellData(0,'lucro', totsumVENDA_DE - totsumVLR_CUSTO);
this.flex.columnFooters.setCellData(0,'margem_lucro', (totsumVENDA_POR > 0 ? (totsumVLR_CUSTO / totsumVENDA_POR) * 100 : 0));
this.flex.columnFooters.setCellData(0,'lucro_inverso', (totsumVENDA_POR > 0 ? (totsumVENDA_DE - totsumVLR_CUSTO) / totsumVENDA_POR : 0));
this.flex.columnFooters.setCellData(0,'lucro_inversoperc', (totsumVENDA_POR > 0 ? ((totsumVENDA_DE - totsumVLR_CUSTO) / totsumVENDA_POR) * 100 : 0));
// Cálculo das colunas agrupadas
if (group) {
// Captura os totais necessários para os cálculos
for (var i = 0; i < group.items.length; i++) {
sumVENDA_DE += group.items[i].ce110_vl_venda_de;
sumVENDA_POR += group.items[i].ce110_vl_venda_por;
sumVLR_CUSTO += group.items[i].vl_custo;
}
if (col.binding == "ce113_pc_markup_de") {
if (sumVLR_CUSTO > 0) {
calcCE113_PC_MARKUP_DE = (sumVENDA_DE / sumVLR_CUSTO) * 100 - 100;
}
e.cell.textContent = wjcCore.Globalize.format(
calcCE113_PC_MARKUP_DE,
col.format
);
}
if (col.binding == "ce113_pc_markup_por") {
if (sumVLR_CUSTO > 0) {
calcCE113_PC_MARKUP_POR =
(sumVENDA_POR / sumVLR_CUSTO) * 100 - 100;
}
e.cell.textContent = wjcCore.Globalize.format(
calcCE113_PC_MARKUP_POR,
col.format
);
}
if (col.binding == "lucro") {
calcLUCRO = sumVENDA_DE - sumVLR_CUSTO;
e.cell.textContent = wjcCore.Globalize.format(
calcLUCRO,
col.format
);
}
if (col.binding == "margem_lucro") {
if (sumVENDA_POR > 0) {
calcMARGEM_LUCRO = (sumVLR_CUSTO / sumVENDA_POR) * 100;
}
e.cell.textContent = wjcCore.Globalize.format(
calcMARGEM_LUCRO,
col.format
);
}
if (col.binding == "lucro_inverso") {
if (sumVENDA_POR > 0) {
calcLUCRO_INVERSO = (sumVENDA_DE - sumVLR_CUSTO) / sumVENDA_POR;
}
e.cell.textContent = wjcCore.Globalize.format(
calcLUCRO_INVERSO,
col.format
);
}
if (col.binding == "lucro_inversoperc") {
if (sumVENDA_POR > 0) {
calcLUCRO_INVERSOPERC =
((sumVENDA_DE - sumVLR_CUSTO) / sumVENDA_POR) * 100;
}
e.cell.textContent = wjcCore.Globalize.format(
calcLUCRO_INVERSOPERC,
col.format
);
}
}
} else {
// if (this.executado < 1000) {
// this.executado += 1;
console.log("CalculoPorMedia");
itens = this.dados.totalItemCount;
totsumMARKUP_DE = 0;
totsumMARKUP_POR = 0;
for (var j = 0; j < s.rows.length; j++) {
if ( (group) && (this.executado < 10 ) ) {
this.executado += 1;
console.log(s.rows[j]);
}
totsumMARKUP_DE += s.rows[j]._data.ce113_pc_markup_de;
totsumMARKUP_POR += s.rows[j]._data.ce113_pc_markup_por;
}
totsumMARKUP_DE = ( itens > 0 ? (totsumMARKUP_DE / itens) : 0);
totsumMARKUP_POR = ( itens > 0 ? (totsumMARKUP_POR / itens) : 10);
// Rodapé - https://www.grapecity.com/forums/wijmo/custom-summary#good-morning-it-worked-tha
this.flex.columnFooters.setCellData(0,'ce113_pc_markup_de', totsumMARKUP_DE);
this.flex.columnFooters.setCellData(0,'ce113_pc_markup_por', totsumMARKUP_POR);
this.flex.columnFooters.setCellData(0,'lucro', totsumVENDA_DE - totsumVLR_CUSTO);
this.flex.columnFooters.setCellData(0,'margem_lucro', (totsumVENDA_POR > 0 ? (totsumVLR_CUSTO / totsumVENDA_POR) * 100 : 0));
this.flex.columnFooters.setCellData(0,'lucro_inverso', (totsumVENDA_POR > 0 ? (totsumVENDA_DE - totsumVLR_CUSTO) / totsumVENDA_POR : 0));
this.flex.columnFooters.setCellData(0,'lucro_inversoperc', (totsumVENDA_POR > 0 ? ((totsumVENDA_DE - totsumVLR_CUSTO) / totsumVENDA_POR) * 100 : 0));
// }
}
}
},