Пересчет суммарных значений по статусам заказов

parent 7d43e037
......@@ -188,7 +188,8 @@ input[type="checkbox"]
}
/* Фильтрация строк в таблице transactions */
table.table-striped.admin.transactions .transaction-item
table.table-striped.admin.transactions .transaction-item,
table.table-striped.admin.transactions .total-orders
{
display: none;
}
......@@ -196,7 +197,11 @@ input[type="checkbox"]
table.table-striped.admin.transactions.all .transaction-item,
table.table-striped.admin.transactions.approved .transaction-item.approved,
table.table-striped.admin.transactions.confirmed .transaction-item.confirmed,
table.table-striped.admin.transactions.rejected .transaction-item.rejected
table.table-striped.admin.transactions.rejected .transaction-item.rejected,
table.table-striped.admin.transactions.all .total-orders.all,
table.table-striped.admin.transactions.approved .total-orders.approved,
table.table-striped.admin.transactions.confirmed .total-orders.confirmed,
table.table-striped.admin.transactions.rejected .total-orders.rejected
{
display: table-row;
}
......
......@@ -11,7 +11,8 @@ $(document).ready(function(){
dateTimeFields = ['Timestamp', 'period'],
trClassConfirmed = 'confirmed',
trClassRejected = 'rejected',
trClassApproved = 'approved';
trClassApproved = 'approved',
ordersStatuses = ['approved', 'confirmed', 'rejected'];
// Шаблон содержимого ячейки Basket
var templateBasketContent = _.template('\n'+
......@@ -122,7 +123,6 @@ $(document).ready(function(){
console.log('AAA dataLineChartStat = ', dataLineChartStat.ordersStatus);
}
// Подготовка данных для сортировки:
dataPeriod.forEach(function(dataTableItem, ind){
var dataTableSortItem = {};
......@@ -234,7 +234,7 @@ $(document).ready(function(){
// Добавляем строку "Всего заказов" для отчета 'transactions':
if (dataLineChartStat.report == 'transactions') {
$row = $('<tr class="total-orders">');
$row = $('<tr class="total-orders all">');
$row.append($('<td>').html("Всего заказов: " + dataPeriod.length));
activeLines.forEach(function(item){
......@@ -253,6 +253,17 @@ $(document).ready(function(){
$row.append($('<td class="'+ item +'">').html(valueFormat(totalValue)));
});
$row.appendTo($tableContent);
// Добавляем total-строки для статусов заказов:
ordersStatuses.forEach(function(item){
$row = $('<tr class="total-orders ' + item + '">');
$row.append($('<td class="count">').html("Заказов: <span></span>"));
activeLines.forEach(function(activeLine){
$row.append($('<td class="'+ activeLine +'">'));
});
$row.appendTo($tableContent);
});
}
}
......@@ -269,7 +280,6 @@ $(document).ready(function(){
//console.log('AAA TableStat render: ', dataLineChartStat);
//console.log('AAA activeLines: ', activeLines);
if (dataLineChartStat.type == 'interval') {
RenderInterval(dataLineChartStat);
......@@ -280,7 +290,6 @@ $(document).ready(function(){
}
$tableBody.html('').append($tableContent.children());
},
// Определяем список категорий, отмеченных галочками в таблице:
CheckedCategories: function() {
......@@ -292,6 +301,33 @@ $(document).ready(function(){
});
return listCats;
},
OrdersStatusReCalc: function() {
console.log('AAA OrdersStatusReCalc');
// Добавляем total-строки для статусов заказов:
ordersStatuses.forEach(function(item){
var
$trStatus = $('tr.transaction-item.'+ item, $table),
$trTotalStatus = $('tr.total-orders.'+ item, $table);
$('td.count span', $trTotalStatus).html($trStatus.length);
activeLines.forEach(function(activeLine){
currentActiveLine = activeLine;
var isNotSumValue = notFormatFields.indexOf(activeLine) > -1;
if (!isNotSumValue) {
var totalValue = 0;
$trStatus.each(function(){
var $this = $(this);
totalValue += parseFloat($('td.'+ activeLine, $this).html().replace(',',''));
});
$('td.'+ activeLine, $trTotalStatus).html(valueFormat(totalValue));
}
});
});
},
}
});
......
......@@ -280,7 +280,9 @@ $(document).ready(function(){
$tableStat = $('table.transactions'),
$ordersSwitcher = $('.b-filter__switch.category-orders .b-filter__switch-item'),
switcherActiveClass = 'm-filter__switch-item_active';
OrdersStatusReCalc();
// Переключение статусов заказов:
$ordersSwitcher.on('click', function() {
var $this = $(this);
......@@ -322,6 +324,7 @@ $(document).ready(function(){
$this.prop("checked", !$this.prop( "checked" ))
}
$this.prop("disabled", false);
OrdersStatusReCalc();
},
error: function(rew, status, err) {
console.log(status, err);
......@@ -329,15 +332,12 @@ $(document).ready(function(){
}
});
return false;
});
// Клик на Утвердить заказы:
$('a.btn.approve').on('click', function(){
if (!confirm("Утвердить заказы за выбранный период?")) return false;
var
action = $tableStat.data('link'),
......@@ -374,6 +374,7 @@ $(document).ready(function(){
$inputItem.prop("disabled", true);
$orderTr.removeClass('confirmed').removeClass('rejected').addClass('approved');
});
OrdersStatusReCalc();
}
},
error: function(rew, status, err) {
......@@ -385,7 +386,12 @@ $(document).ready(function(){
return false;
});
// Пересчет кол-ва заказов по группам
function OrdersStatusReCalc()
{
$.TableStat.OrdersStatusReCalc();
}
})();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment