estimate-library
Advanced tools
Comparing version 0.2.10 to 0.2.11
@@ -27,3 +27,3 @@ "use strict"; | ||
function calculateRow(row) { | ||
var costPrice = row.departments.reduce(function (acc, dep) { return acc + normalizePrice(dep.rate * dep.value); }, 0); | ||
var costPrice = row.departments.reduce(function (acc, dep) { return acc + normalizePrice(dep.rate * (dep.isDisabled ? 0 : dep.value)); }, 0); | ||
var margin = getMargin(costPrice, this.config.margin); | ||
@@ -30,0 +30,0 @@ var price = costPrice + margin; |
@@ -27,2 +27,3 @@ "use strict"; | ||
var sections_1 = require("./sections"); | ||
var row_1 = require("./row"); | ||
var initialConfig = function () { return ({ | ||
@@ -52,12 +53,16 @@ defaultRowName: 'New Row', | ||
var _this = this; | ||
this.config.departments = this.config.departments.map(function (department) { | ||
if (department.id === depId) { | ||
return __assign(__assign({}, department), { isDisabled: !department.isDisabled }); | ||
} | ||
return department; | ||
}); | ||
this.sections = this.sections.map(function (section) { | ||
return sections_1.calculateSection.call(_this, __assign(__assign({}, section), { tasks: section.tasks.map(function (row) { | ||
return calculations_1.calculateRow.call(_this, __assign(__assign({}, row), { departments: row.departments.map(function (department) { | ||
if (department.id === depId) { | ||
return __assign(__assign({}, department), { isDisabled: !department.isDisabled }); | ||
} | ||
return department; | ||
}) })); | ||
}) })); | ||
return sections_1.calculateSection.call(_this, __assign(__assign({}, section), { tasks: section.tasks.map(function (row) { return calculations_1.calculateRow.call(_this, row_1.toggleDepartmentInRow.call(_this, row, depId)); }), total: calculations_1.calculateRow.call(_this, row_1.toggleDepartmentInRow.call(_this, section.total, depId)) })); | ||
}); | ||
this.subtotal = row_1.toggleDepartmentInRow.call(this, this.subtotal, depId); | ||
this.discount = row_1.toggleDepartmentInRow.call(this, this.discount, depId); | ||
this.fees = row_1.toggleDepartmentInRow.call(this, this.fees, depId); | ||
this.taxes = row_1.toggleDepartmentInRow.call(this, this.taxes, depId); | ||
this.total = row_1.toggleDepartmentInRow.call(this, this.total, depId); | ||
core_1.calculateTable.call(this); | ||
@@ -64,0 +69,0 @@ } |
@@ -10,3 +10,4 @@ import IRow from "../types/IRow"; | ||
export declare function deleteDepartmentFromRow(this: ITable, row: IRow, depId: number): IRow; | ||
export declare function toggleDepartmentInRow(this: ITable, row: IRow, depId: number): IRow; | ||
export declare function toggleRow(this: ITable, row: IRow): IRow; | ||
export declare const resetRowDepartments: (row: IRow) => IRow; |
@@ -23,3 +23,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resetRowDepartments = exports.toggleRow = exports.deleteDepartmentFromRow = exports.updateDepartmentInRow = exports.addDepartmentToRow = exports.updateRowName = exports.duplicateRow = exports.createRow = void 0; | ||
exports.resetRowDepartments = exports.toggleRow = exports.toggleDepartmentInRow = exports.deleteDepartmentFromRow = exports.updateDepartmentInRow = exports.addDepartmentToRow = exports.updateRowName = exports.duplicateRow = exports.createRow = void 0; | ||
var uuid_1 = require("uuid"); | ||
@@ -61,2 +61,11 @@ var calculations_1 = require("./calculations"); | ||
exports.deleteDepartmentFromRow = deleteDepartmentFromRow; | ||
function toggleDepartmentInRow(row, depId) { | ||
return __assign(__assign({}, row), { departments: row.departments.map(function (department) { | ||
if (department.id === depId) { | ||
return __assign(__assign({}, department), { isDisabled: !department.isDisabled }); | ||
} | ||
return department; | ||
}) }); | ||
} | ||
exports.toggleDepartmentInRow = toggleDepartmentInRow; | ||
function toggleRow(row) { | ||
@@ -63,0 +72,0 @@ return calculations_1.calculateRow.call(this, __assign(__assign({}, row), { isDisabled: !row.isDisabled })); |
{ | ||
"name": "estimate-library", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
30442
707