Created
April 28, 2017 14:08
-
-
Save ntorgov/aa3bf04a29551063ead0cc35500ebdfb to your computer and use it in GitHub Desktop.
calculator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path='../../typings/index.d.ts' /> | |
/// <reference path='../../server/classes/calculator.d.ts' /> | |
/// <reference path='../../lib/collections/collections.d.ts' /> | |
'use strict'; | |
import {Material} from './material'; | |
import {Constants} from '../../lib/collections/constants'; | |
import {Factors} from '../../lib/collections/factors'; | |
import {Knifes} from '../../lib/collections/knifes'; | |
import {Materials} from '../../lib/collections/materials'; | |
import {Polishes} from '../../lib/collections/polishes'; | |
import {Rates} from '../../lib/collections/rates'; | |
/** | |
* Модуль для работы с вычислениями заказа | |
* @version 5.0.0 | |
* @name Order | |
* @implements CalculatorFunctionsInterface | |
*/ | |
export class Order implements CalculatorFunctionsInterface { | |
/** | |
* Экземпляр вычислителя | |
* @type {ComputationClassInterface} | |
*/ | |
private computer: ComputationClassInterface; | |
/** | |
* Данные заказа | |
* @type {IOrderStructure} | |
*/ | |
private Order: IOrderStructure; | |
/** | |
* Коллекция констант | |
* @type {ConstantCollectionStructure} | |
*/ | |
private constantsCollection: ConstantCollectionStructure[]; | |
/** | |
* Коллекция ценовых ставок | |
* @type {IRateStructure} | |
*/ | |
private usedPriceRate: IRateStructure; | |
/** | |
* Документ из коллекции ножей | |
* @type {IKnifeStricture} | |
*/ | |
private usedKnife: IKnifeStricture; | |
/** | |
* Используемый маткриал | |
* @type {IMaterialStructure} | |
*/ | |
private usedMaterial: IMaterialStructure; | |
/** | |
* Используемый лак | |
* @type IPolishStructure | |
*/ | |
private usedPolish: IPolishStructure; | |
/** | |
* Используемый дизайн. | |
* Обычно тут всегда 0 | |
* @type {number} | |
*/ | |
private usedDesign: number; | |
/** | |
* Используемый ценовой коэффициент | |
* @type IFactorStricture | |
*/ | |
private usedFactorRate: IFactorStricture; | |
/** | |
* Конструктор | |
* @param {SourceOrderStructure} order данные заказа | |
*/ | |
constructor(order: SourceOrderStructure) { | |
/** | |
* Создание пустого экземпляра заказа | |
* @type {IOrderStructure} | |
*/ | |
this.Order = Order.createEmptyOrder(); | |
this.computer = new Computation(); | |
/** | |
* Коллекция констант | |
* @type {ConstantCollectionStructure} | |
*/ | |
this.constantsCollection = <ConstantCollectionStructure[]>Constants.find({}, { | |
fields: { | |
title: 0, | |
comment: 0, | |
_id: 0 | |
} | |
}).fetch(); | |
if (typeof order.colors != 'undefined') { | |
this.Order.order.colors = order.colors; | |
} else { | |
this.Order.order.colors = 1; | |
} | |
if (typeof order.pantones != 'undefined') { | |
this.Order.order.pantones = order.pantones; | |
} else { | |
this.Order.order.pantones = 0; | |
} | |
if (order.kinds) { | |
this.Order.order.kinds = order.kinds; | |
} else { | |
this.Order.order.kinds = 1; | |
} | |
if (order.quantity) { | |
this.Order.order.quantity = order.quantity; | |
} else { | |
this.Order.order.quantity = 1000; | |
} | |
// this.orderData = order; | |
if (order.euroPrice) { | |
this.Order.order.euroPrice = order.euroPrice; | |
} else { | |
this.Order.order.euroPrice = _.findWhere(this.constantsCollection, {'code': 'EuroPrice'}).value; | |
} | |
this.Order.order.knife = order.knife; | |
// this.priceRateId = (this.orderData.rate) ? this.orderData.rate : 0; | |
this.usedKnife = <IKnifeStricture>Knifes.findOne({'_id': this.Order.order.knife}, { | |
fields: { | |
_id: 1, | |
material: 1, | |
quantityPerStamp: 1, | |
rapport: 1 | |
} | |
}); | |
// Если установлена ширина материала, то использовать ее. Иначе - взять из ножа | |
// if (order.material.elements && (order.material.elements.length > 0) && order.material.elements[0].width) { | |
// this.Order.order.material.elements = order.material.elements; | |
// } else { | |
this.Order.order.material.elements[0].width = this.usedKnife.material; | |
// } | |
// console.log(this.Order.order.material); | |
if (order.material && order.material.vendorId) { | |
this.Order.order.material.vendorId = order.material.vendorId; | |
} | |
if (order.material && order.material.id) { | |
this.usedMaterial = <IMaterialStructure>Materials.findOne({'_id': order.material.id}); | |
} | |
this.Order.order.material.price = this.usedMaterial.price; | |
this.Order.order.material.id = order.material.id; | |
// Небольшой костыль, на случай, если лак не указан | |
if (order.polish) { | |
this.usedPolish = Polishes.findOne({_id: order.polish}, {fields: {_id: 1, isCustom: 1, price: 1}}); | |
} else { | |
this.usedPolish = Polishes.findOne({}, { | |
fields: {_id: 1, isCustom: 1, price: 1}, | |
sort: {$sortOrder: 1} | |
}); | |
} | |
this.Order.order.polish = this.usedPolish._id; | |
this.usedDesign = 0; | |
// console.log(this.orderData.rate); | |
if (order.rate) { | |
this.usedPriceRate = Rates.findOne({_id: order.rate}); | |
} else { | |
this.usedPriceRate = Rates.findOne({'isDefault': true}); | |
} | |
this.Order.order.rate = this.usedPriceRate._id; | |
// console.log('Rate Object:'); | |
// console.log(this.usedPriceRate); | |
// Назначение ценовой ставки, если ее нет | |
// this.orderData.rate = this.usedPriceRate._id; | |
} | |
/** | |
* Функция создания пустого объекта заказа | |
* @returns {IOrderStructure} | |
*/ | |
private static createEmptyOrder(): IOrderStructure { | |
let newOrderObject: IOrderStructure; | |
newOrderObject = { | |
order: { | |
knife: '', | |
material: {id: '', elements: [{width: 0}]}, | |
colors: 0, | |
polish: '', | |
pantones: 0, | |
rate: '', | |
quantity: 0, | |
kinds: 0 | |
}, | |
calculation: {} | |
}; | |
return newOrderObject; | |
} | |
/** | |
* Функция расчета заказа. Самая важная. | |
* @returns {{}} | |
*/ | |
compute() { | |
let materialAdviser: Material.Adviser = new Material.Adviser(); | |
/** | |
* Счетчик для цикла | |
* @type {number} | |
*/ | |
let counter: number; | |
/** | |
* Локальная переменная для работы с длиной тиража | |
* @type {number} | |
*/ | |
let localPrintingLength: number; | |
/** | |
* Локальная переменная для работы с частичной длиной тиража | |
* @type {number} | |
*/ | |
let currentLength: number; | |
/** | |
* Объект для расчета полной длины печати | |
* @type {LengthPrintObjectInterface} | |
*/ | |
let totalPrintLengthObject: LengthPrintObjectInterface; | |
/** | |
* Объект для расчета стоимости флексоформ и верстки | |
* @type {PriceOfFormObjectStructure} | |
*/ | |
let priceOfFormAndPageMakingObject: PriceOfFormObjectStructure; | |
/** | |
* Объект для расчета времени на подготовку дополнительных видов | |
* @type {PrepareAdditionKindsObjectInterface} | |
*/ | |
let timePrepareAdditionKindsObject: PrepareAdditionKindsObjectInterface; | |
/** | |
* Константа 'Метраж на приладку цвета' | |
* @type {number} | |
*/ | |
const constantLengthToColorCalibration: number = _.findWhere(this.constantsCollection, {'code': 'CCalibration'}).value; | |
/** | |
* Константу 'Метраж на приладку цвета для доп вида' | |
* LTCAK - Length To Calibrate Additional Kinds | |
* @type {number} | |
*/ | |
const constantLTCAK: number = _.findWhere(this.constantsCollection, {'code': 'CCalibrationDop'}).value; | |
/** | |
* Константа 'Норматив доп. расходов' | |
* ACN - Additional Consumes Normative | |
* @type {number} | |
*/ | |
const constantACN: number = _.findWhere(this.constantsCollection, {'code': 'DopConsumeNorm'}).value; | |
/** | |
* Константа 'Средняя рабочая скорость' | |
* @type {number} | |
*/ | |
const constantMiddleWorkSpeed: number = _.findWhere(this.constantsCollection, {'code': 'MiddleWorkSpeed'}).value; | |
/** | |
* Константа 'Дополнительное время на пантон' | |
* @type {number} | |
*/ | |
const constantTimeForPantones: number = _.findWhere(this.constantsCollection, {'code': 'TimeForPantones'}).value; | |
/** | |
* Константа 'Стоимость см2 полимера форм' | |
* @type {number} | |
*/ | |
const constantPolymerPrice: number = _.findWhere(this.constantsCollection, {'code': 'PolymerPrice'}).value; | |
/** | |
* Константа 'Стоимость верстки 1-ой формы' | |
* @type {number} | |
*/ | |
const constantVerstkaPrice: number = _.findWhere(this.constantsCollection, {'code': 'VerstkaPrice'}).value; | |
/** | |
* Константа 'Длина приладки на нож' | |
* @type {number} | |
*/ | |
const constantCalibrateKnifeLength: number = _.findWhere(this.constantsCollection, {'code': 'CalibrateKnifeLength'}).value; | |
/** | |
* Константа 'Длина приладки на выборочный лак' | |
* @type {number} | |
*/ | |
const constantCalibratePolishLength: number = _.findWhere(this.constantsCollection, {'code': 'CalibratePolishLength'}).value; | |
/** | |
* Константа 'Время на подготовку одной секции к работе' | |
* @date 23.01.2017 | |
* @version 1.0.0 | |
* @type {number} | |
*/ | |
const constantTimeToSectionPrepare: number = _.findWhere(this.constantsCollection, {'code': 'TimeToSectionPrepare'}).value; | |
/** | |
* Константа 'Время на переклейку одной формы' | |
* @name constantTimeToFormRestick | |
* @date 23.01.2017 | |
* @version 1.0.0 | |
* @type {number} | |
*/ | |
const constantTimeToFormRestick: number = _.findWhere(this.constantsCollection, {'code': 'TimeToFormRestick'}).value; | |
/** | |
* Константа 'Время на настройку дополнительных видов' | |
* @name constantTimeToCalibrateAdditionalKinds | |
* @date 23.01.2017 | |
* @version 1.0.0 | |
* @type {number} | |
*/ | |
const constantTimeToCalibrateAdditionalKinds: number = _.findWhere(this.constantsCollection, {'code': 'TimeToCalibrateAdditionalKinds'}).value; | |
/** | |
* Константа 'Среднее время на перемотку одного роля' | |
* @name constantTimeToRerollAverage | |
* @date 23.01.2017 | |
* @version 1.0.0 | |
* @type {number} | |
*/ | |
const constantTimeToRerollAverage: number = _.findWhere(this.constantsCollection, {'code': 'TimeToRerollAverage'}).value; | |
/** | |
* Константа 'Средняя длина перемотки на ролик' | |
* @name constantLengthToRerollAverage | |
* @date 23.01.2017 | |
* @version 1.0.0 | |
* @type {number} | |
*/ | |
const constantLengthToRerollAverage: number = _.findWhere(this.constantsCollection, {'code': 'LengthToRerollAverage'}).value; | |
// Вычисление длины тиража: Тираж в штуках * Количество этикеток в штампе * Раппор / 1000 | |
this.Order.calculation.printingLength = this.computer.printingLength(this.Order.order.quantity, this.usedKnife.quantityPerStamp, this.usedKnife.rapport); | |
// Вычисление длины приладки: Количество цветов * Константу 'Метраж на приладку цвета' | |
this.Order.calculation.calibrationLength = this.computer.calibrationLength(this.Order.order.colors, constantLengthToColorCalibration); | |
// Вычисление длины приладки на дополнительные виды: Количество цветов * (Выбранное количество видов - 1) * Константу 'Метраж на приладку цвета для доп вида' | |
this.Order.calculation.additionKindsCalibrationLength = this.computer.additionKindsCalibrationLength(this.Order.order.colors, this.Order.order.kinds, constantLTCAK); | |
// Вычисление резервной длины печати: (Длина тиража + Длина приладки + Длина приладки на доп виды) * Константу 'Норматив доп. Расходов' / 100 | |
this.Order.calculation.reservedLength = this.computer.reservedLength(this.Order.calculation.printingLength, this.Order.calculation.calibrationLength, this.Order.calculation.additionKindsCalibrationLength, constantACN); | |
// Вычисление длины приладки на выборочный лак | |
this.Order.calculation.customPolishCalibrationLength = this.computer.customPolishCalibrationLength(this.Order.order.kinds, constantCalibratePolishLength, this.usedPolish.isCustom); | |
// Вычисление полной длины печати: Длина тиража + Длина приладки + Длина приладки на доп виды + Резервная длина печати | |
totalPrintLengthObject = { | |
printingLength: this.Order.calculation.printingLength, | |
calibrationLength: this.Order.calculation.calibrationLength, | |
additionKindsCalibrationLength: this.Order.calculation.additionKindsCalibrationLength, | |
reservedLength: this.Order.calculation.reservedLength, | |
polishCalibrationLength: this.Order.calculation.customPolishCalibrationLength, | |
constCalibrateKnifeLength: constantCalibrateKnifeLength | |
}; | |
this.Order.calculation.totalPrintingLength = this.computer.totalPrintingLength(totalPrintLengthObject); | |
// Вычисление площади тиража | |
this.Order.calculation.totalPrintingSquare = this.computer.totalPrintingSquare(this.Order.calculation.totalPrintingLength, this.Order.order.material.elements[0].width); | |
// Вычисление времени на подготовку основного тиража (вида) | |
this.Order.calculation.timePrepareBaseKind = this.computer.timePrepareBaseKind(this.Order.order.colors, constantTimeToSectionPrepare); | |
// Вычисление времени на подготовку пантонов | |
this.Order.calculation.timePreparePantones = this.computer.timePreparePantones(this.Order.order.pantones, constantTimeForPantones); | |
// Время на подготовку дополнительных видов | |
timePrepareAdditionKindsObject = { | |
colors: this.Order.order.colors, | |
kinds: this.Order.order.kinds, | |
constTimeToFormRestick: constantTimeToFormRestick, | |
constTimeToCalibrateAdditionalKinds: constantTimeToCalibrateAdditionalKinds | |
}; | |
this.Order.calculation.timePrepareAdditionKinds = this.computer.timePrepareAdditionKinds(timePrepareAdditionKindsObject); | |
// Вычисление времени печати: Полная длина печати / Константа 'Средняя рабочая скорость' | |
this.Order.calculation.timePrinting = this.computer.timePrinting(this.Order.calculation.totalPrintingLength, constantMiddleWorkSpeed); | |
// Вычисление времени на перемотку | |
this.Order.calculation.timeReRoll = this.computer.timeReRoll(this.Order.calculation.printingLength, constantTimeToRerollAverage, constantLengthToRerollAverage); | |
// Полное время печати: Время на подготовку + Время печати + Время на пантоны + Время на перемотку | |
this.Order.calculation.totalPrintingTime = this.Order.calculation.timePrepareBaseKind + this.Order.calculation.timePreparePantones + this.Order.calculation.timePrepareAdditionKinds + this.Order.calculation.timePrinting; | |
// Стоимость флексоформ и верстки: (Раппорт * Используемая ширина материала / 100 * Константа 'Стоимость см2 полимера форм') + | |
// (Константа 'Стоимость верстки 1-ой формы' * (Количество цветов + (Количество видов - 1) * Количество цветов) | |
// this.Order.priceOfFormAndPageMaking = (this.usedKnife.rapport * this.usedMaterialWidth / 100 * parseFloat(_.findWhere(this.constantsCollection, {'code': 'PolymerPrice'}).value)) + | |
// (parseFloat(_.findWhere(this.constantsCollection, {'code': 'VerstkaPrice'}).value) * (this.orderData.colors + (this.orderData.kinds - 1) * this.orderData.colors)); | |
priceOfFormAndPageMakingObject = { | |
rapport: this.usedKnife.rapport, | |
materialWidth: this.Order.order.material.elements[0].width, | |
colors: this.Order.order.colors, | |
kinds: this.Order.order.kinds, | |
constPolymerPrice: constantPolymerPrice, | |
constVerstkaPrice: constantVerstkaPrice | |
}; | |
this.Order.calculation.priceOfFormAndPageMaking = this.computer.priceOfFormAndPageMaking(priceOfFormAndPageMakingObject); | |
// Стоимость дизайна: (Используемый дизайн = 0) / Стоимость евро | |
this.Order.calculation.priceOfDesign = this.usedDesign / _.findWhere(this.constantsCollection, {'code': 'EuroPrice'}).value; | |
// Стоимость материала: Цена материала * Полная площадь печати | |
this.Order.calculation.materialCost = this.Order.order.material.price * this.Order.calculation.totalPrintingSquare; | |
// Стоимость краски: Полная площадь печати * Константа 'Нормативный расход краски' * Количество цветов * Константа 'Средняя цена краски' | |
this.Order.calculation.colourCost = this.Order.calculation.totalPrintingSquare * _.findWhere(this.constantsCollection, {'code': 'ColourConsume'}).value * this.Order.order.colors * _.findWhere(this.constantsCollection, {'code': 'ColourPrice'}).value; | |
// Стоимость лака: Полная площадь печати * Константа 'Нормативный расход лака' * Стоимость используемого лака | |
this.Order.calculation.polishCost = this.Order.calculation.totalPrintingSquare * _.findWhere(this.constantsCollection, {'code': 'PolishConsume'}).value * this.usedPolish.price; | |
// Вычисление дополнительных расходов: ((Стоимость материала + Стоимость краски + Стоимость лака) * Константа 'Норматив доп. Расходов') / 100 | |
// this.Order.calculation.additionConsumeCost = (this.Order.calculation.materialCost + this.Order.calculation.colourCost + this.Order.calculation.polishCost) * _.findWhere(this.constantsCollection, {'code': 'DopConsumeNorm'}).value / 100; | |
// Вычисление стоимости электричества: Константа 'Потребляемая мощность машины' * Константа 'Стоимость за 1 квт' * Полное время печати | |
// this.Order.calculation.energyCost = _.findWhere(this.constantsCollection, {'code': 'EnergyConsume'}).value * _.findWhere(this.constantsCollection, {'code': 'Energy'}).value * this.Order.calculation.totalPrintingTime; | |
// this.Order.calculation.energyCost = _.findWhere(this.constantsCollection, {'code': 'MonthEnergyConsume'}).value / _.findWhere(this.constantsCollection, {'code': 'EuroPrice'}).value; | |
// Вычисление зарплатной составляющей: Константа 'Месячный ФОТ' + (Константа 'Месячные налоговые отчисления' / Константа 'Чистое месячное рабочее время') * Полное время печати | |
// this.Order.calculation.payingPartCost = (_.findWhere(this.constantsCollection, {'code': 'MonthFOT'}).value + _.findWhere(this.constantsCollection, {'code': 'MonthTax'}).value) / _.findWhere(this.constantsCollection, {'code': 'ClearMonthWorkTime'}).value * this.Order.calculation.totalPrintingTime; | |
// this.Order.calculation.payingPartCost = (_.findWhere(this.constantsCollection, {'code': 'MonthFOT'}).value + _.findWhere(this.constantsCollection, {'code': 'MonthTax'}).value) / _.findWhere(this.constantsCollection, {'code': 'ClearMonthWorkTime'}).value * this.Order.calculation.totalPrintingTime; | |
// Вычисление арендной составляющей: Константа 'Месячные арендные расходы' / Константа 'Чистое месячное рабочее время' * Полное время печати | |
// this.Order.calculation.rentalPartCost = _.findWhere(this.constantsCollection, {'code': 'MonthRental'}).value / _.findWhere(this.constantsCollection, {'code': 'ClearMonthWorkTime'}).value * this.Order.calculation.totalPrintingTime; | |
this.Order.calculation.productionConsumes = (_.findWhere(this.constantsCollection, {'code': 'MonthFOT'}).value / _.findWhere(this.constantsCollection, {'code': 'EuroPrice'}).value + | |
_.findWhere(this.constantsCollection, {'code': 'MonthTax'}).value / _.findWhere(this.constantsCollection, {'code': 'EuroPrice'}).value + | |
_.findWhere(this.constantsCollection, {'code': 'MonthRental'}).value / _.findWhere(this.constantsCollection, {'code': 'EuroPrice'}).value + | |
_.findWhere(this.constantsCollection, {'code': 'MonthEnergyConsume'}).value / _.findWhere(this.constantsCollection, {'code': 'EuroPrice'}).value) / | |
_.findWhere(this.constantsCollection, {'code': 'ClearMonthWorkTime'}).value * | |
this.Order.calculation.totalPrintingTime; | |
// Вычисление прибыли | |
// Если стоимость используемого материала < 0.6, то считать стоимость бумаги для выбранной ценовой ставки * Полное время печати | |
// Иначе: Стоимость другого * Полное время печати | |
if (this.Order.order.material.price < 0.45) { | |
this.Order.calculation.income = this.usedPriceRate.paper * this.Order.calculation.totalPrintingTime; | |
} else { | |
this.Order.calculation.income = this.usedPriceRate.other * this.Order.calculation.totalPrintingTime; | |
} | |
// Выбор коэффициента в зависимости от длины тиража | |
this.usedFactorRate = (<any>Factors).findOne({ | |
end: {'$gte': this.Order.calculation.printingLength}, | |
start: {'$lte': this.Order.calculation.printingLength} | |
}); | |
// Продолжение вычисления прибыли. То, что насчитали с бумагой * коэффициент | |
this.Order.calculation.income *= this.usedFactorRate.value; | |
// Вычисление полной стоимости печати: | |
// Стоимость форм и верстки + Стоимость дизайна + Стоимость материала + Стоимость краски + Стоимость лака + | |
// Стоимость дополнительных расходов + Стоимость электричества + Стоимость зарплатной составляющей + Стоимость арендной составляющей + Стоимость прибыли (как бы странно это ни звучало) | |
this.Order.calculation.totalPriceOfPrinting = this.Order.calculation.priceOfFormAndPageMaking + | |
this.Order.calculation.priceOfDesign + this.Order.calculation.materialCost + | |
this.Order.calculation.colourCost + this.Order.calculation.polishCost + | |
/* this.Order.calculation.additionConsumeCost */ +this.Order.calculation.productionConsumes + | |
this.Order.calculation.income; | |
// console.log(this.Order); | |
// console.log(this.Order.order.material); | |
return this.Order; | |
} | |
/** | |
* Функция возвращает полные данные по расчитанному заказу | |
* @returns {IOrderCalculationPublicStructure} Данные расчитанного заказа | |
*/ | |
formDataFull(): IOrderCalculationPublicStructure { | |
/** | |
* Стоимость евро | |
* @type {number} | |
*/ | |
const currentEuroPrice: number = _.findWhere(this.constantsCollection, {'code': 'EuroPrice'}).value; | |
/** | |
* Результат вычисления заказа в человечесом виде | |
* @type {IOrderCalculationPublicStructure} | |
*/ | |
let calculatedOrder: IOrderCalculationPublicStructure = { | |
TotalCost: Math.floor(this.Order.calculation.totalPriceOfPrinting * currentEuroPrice).toFixed(2), | |
StickerCost: ((this.Order.calculation.totalPriceOfPrinting * currentEuroPrice) / this.Order.order.quantity).toFixed(2), | |
TotalTime: this.Order.calculation.totalPrintingTime, | |
TotalLength: this.Order.calculation.totalPrintingLength.toFixed(2), | |
TotalSquare: this.Order.calculation.totalPrintingSquare.toFixed(2), | |
TimeToReroll: this.Order.calculation.timeReRoll, | |
ClearLength: this.Order.calculation.printingLength.toFixed(0), | |
SecondPrintingCost: Math.floor((this.Order.calculation.totalPriceOfPrinting - this.Order.calculation.priceOfFormAndPageMaking) * currentEuroPrice).toFixed(2), | |
SecondPrintingStickerCost: ((this.Order.calculation.totalPriceOfPrinting - this.Order.calculation.priceOfFormAndPageMaking) * currentEuroPrice / this.Order.order.quantity).toFixed(2), | |
FlexFormCost: (this.Order.calculation.priceOfFormAndPageMaking * currentEuroPrice).toFixed(2), | |
TotalWeight: (this.Order.calculation.totalPrintingSquare * 0.27).toFixed(2) | |
}; | |
this.Order.calculation = _.extend(this.Order.calculation, calculatedOrder); | |
return calculatedOrder; | |
} | |
/** | |
* Функция заполнения данных для записи в базу | |
* @return {IOrderStructure} | |
*/ | |
getOrderRecord(): IOrderStructure { | |
// let resultData: any = {}; | |
// resultData.order = this.orderData; | |
this.formDataFull(); | |
// resultData.order.material = { | |
// id: this.usedMaterial._id, | |
// price: this.usedMaterial.price, | |
// }; | |
return this.Order; | |
} | |
} | |
/** | |
* Модуль для работы с вычислениями заказа | |
* @project АгропринтCRM | |
* @link https://github.com/ntorgov/agroprint-crm | |
* @link https://gist.github.com/ntorgov/8ec02c92caabf9b03947260900e9fc8a | |
* @version 4.0.0 | |
* @name Computation | |
* @implements ComputationClassInterface | |
*/ | |
export class Computation implements ComputationClassInterface { | |
/** | |
* Функция вычисления длины печати | |
* @param {number} orderQuantity Количество этикеток | |
* @param {number} knifeQuantityPerStamp Количество этикеток в штампе | |
* @param {number} knifeRapport Раппорт | |
* @returns {number} | |
*/ | |
printingLength(orderQuantity: number, knifeQuantityPerStamp: number, knifeRapport: number): number { | |
/** | |
* Результат выполнения функции | |
* @type {number} | |
*/ | |
let result: number; | |
result = orderQuantity / knifeQuantityPerStamp * knifeRapport / 1000; | |
return result; | |
} | |
/** | |
* Функция вычисления длины приладки | |
* @param {number} colors Количество цветов | |
* @param {number} colorsLength Константа 'Метраж на приладку цвета' | |
* @returns {number} | |
*/ | |
calibrationLength(colors: number, colorsLength: number): number { | |
/** | |
* Результат выполнения функции | |
* @type {number} | |
*/ | |
let result: number; | |
result = colors * colorsLength; | |
return result; | |
} | |
/** | |
* Вычисление длины приладки на дополнительные виды | |
* @param {number} colors Количество цветов | |
* @param {number} kinds Количество видов | |
* @param {number} length Константа 'Метраж на приладку цвета для доп вида' | |
* @returns {number} | |
*/ | |
additionKindsCalibrationLength(colors: number, kinds: number, length: number): number { | |
/** | |
* Результат выполнения функции | |
* @type {number} | |
*/ | |
let result: number = 0; | |
if (kinds > 1) { | |
result = colors * (kinds - 1) * length; | |
} | |
return result; | |
} | |
/** | |
* Вычисление резервной длины печати | |
* @param {number} printingLength Длина печати | |
* @param {number} calibrationLength Длина приладки | |
* @param {number} additionalKindsLength Длина на дополнительные виды | |
* @param {number} normative Константа 'Норматив доп. Расходов' | |
* @returns {number} | |
*/ | |
reservedLength(printingLength: number, calibrationLength: number, additionalKindsLength: number, normative: number): number { | |
let result: number; | |
result = (printingLength + calibrationLength + additionalKindsLength) * normative / 100; | |
return result; | |
} | |
/** | |
* Вычисление длины приладки на выборочный лак | |
* Только на выборочный | |
* @todo Дописать функцонал, если нужно будет делать расчет полной лакировки | |
* @param {number} kinds Количество видов | |
* @param {number} polishConstant Константа 'Приладка на выборочный лак' | |
* @param {boolean} customPolishFlag Является ли лак выборочным | |
* @returns {number} | |
*/ | |
customPolishCalibrationLength(kinds: number, polishConstant: number, customPolishFlag: boolean): number { | |
let result: number = 0; | |
if (customPolishFlag === true) { | |
result = kinds * polishConstant; | |
} | |
return result; | |
} | |
/** | |
* Вычисление полной длины печати | |
* @param {LengthPrintObjectInterface} lengthObject Объект для расчета | |
* @returns {number} | |
*/ | |
totalPrintingLength(lengthObject: LengthPrintObjectInterface): number { | |
let result: number; | |
result = lengthObject.printingLength + lengthObject.calibrationLength + | |
lengthObject.additionKindsCalibrationLength + lengthObject.reservedLength + | |
lengthObject.polishCalibrationLength + lengthObject.constCalibrateKnifeLength; | |
return result; | |
} | |
/** | |
* Вычисление полной площади тиража | |
* @param {number} totalPrintingLength Полная длина тиража | |
* @param {number} materialWidth Ширина используемого материала | |
* @returns {number} | |
*/ | |
totalPrintingSquare(totalPrintingLength: number, materialWidth: number): number { | |
let result: number; | |
result = totalPrintingLength * materialWidth / 1000; | |
return result; | |
} | |
/** | |
* Время на подготовку основного тиража (вида) | |
* @param {number} colors Количество цветов | |
* @param {number} timeToSectionPrepare Константа 'Время на подготовку одной секции к работе' | |
* @returns {number} | |
*/ | |
timePrepareBaseKind(colors: number, timeToSectionPrepare: number): number { | |
let result: number = 0; | |
if (colors > 0) { | |
result = colors * timeToSectionPrepare; | |
} | |
return result; | |
} | |
/** | |
* Вычисление времени печати | |
* @param {number} length Длина печати | |
* @param {number} speed Скорость печати | |
* @returns {number} | |
*/ | |
timePrinting(length: number, speed: number): number { | |
let result: number; | |
result = length / speed; | |
return result; | |
} | |
/** | |
* Вычисление времени на пантоны | |
* @name timePreparePantones | |
* @param {number} pantones | |
* @param {number} constantTimeForPantones | |
* @returns {number} | |
*/ | |
timePreparePantones(pantones: number, constantTimeForPantones: number): number { | |
let result: number = 0; | |
if (pantones > 0) { | |
result = pantones * constantTimeForPantones; | |
} | |
return result; | |
} | |
/** | |
* Вычисление времени на подготовку дополнительных видов | |
* @name timePrepareAdditionKinds | |
* @param {PrepareAdditionKindsObjectInterface} timeObject Объект расчетов | |
* @returns {number} | |
*/ | |
timePrepareAdditionKinds(timeObject: PrepareAdditionKindsObjectInterface): number { | |
let result: number = 0; | |
let additionalKinds: number = 0; | |
if (timeObject.kinds > 1) { | |
additionalKinds = timeObject.kinds - 1; | |
result = additionalKinds * timeObject.constTimeToCalibrateAdditionalKinds; | |
if (timeObject.colors > 0) { | |
result = result + (additionalKinds * timeObject.colors * timeObject.constTimeToFormRestick); | |
} | |
} | |
return result; | |
} | |
/** | |
* Вычисление времени на перемотку | |
* @param {number} totalPrintingLength Полная длина тиража | |
* @param {number} constantTimeToRerollAverage Константа 'Среднее время на перемотку одного роля' | |
* @param {number} constantLengthToRerollAverage Константа 'Средняя длина перемотки на ролик' | |
* @returns {number} | |
*/ | |
timeReRoll(printingLength: number, constantTimeToRerollAverage: number, constantLengthToRerollAverage: number): number { | |
let result: number; | |
result = printingLength / constantLengthToRerollAverage * constantTimeToRerollAverage; | |
return result; | |
} | |
/** | |
* Вычисление стоимости флексоформ и верстки | |
* @param {PriceOfFormObjectStructure} data | |
* @returns {number} | |
*/ | |
priceOfFormAndPageMaking(data: PriceOfFormObjectStructure): number { | |
let result: number; | |
let additionalKinds: number = 0; | |
if (data.kinds > 1) { | |
additionalKinds = data.kinds - 1; | |
} | |
result = ((data.rapport * data.materialWidth / 100 * data.constPolymerPrice) + data.constVerstkaPrice) * | |
(data.colors + (additionalKinds * data.colors)); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment