/
YakuninAV
/
Convertors
Обзор
Документация
Войти
/
YakuninAV
/
Convertors
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Estimate/EstResources.pas
633 строки
21 KB
YakuninAV
begin with gitflick
31 июл 2026, 15:21
31 июл 2026, 15:21
1dc0fc6
Код
Авторство
О чём код?
unit EstResources; {$I mormot.defines.inc} {$DEFINE USEWEAKREFS} interface uses {$IFDEF ISDELPHIXE2} SysUtils, Classes, Types, DateUtils, {$ELSE} SysUtils, Classes, Types, DateUtils, {$ENDIF} mormot.core.base, mormot.core.variants, mormot.core.os, mormot.core.unicode, EstTypes, EstIntfsV2, EstPrices, EstCoefficients, EstInflationRates; type /// Класс реализующий интерфейс для работы с ресурсами расценок TEstResource = class(TInterfacedObject, IEstResourceV2) private FName, FCypher, FUnitsName: string; FNum, FNumRef: Word; FConsumption,FConsumptionTotal, FLabour: Double; FCustom, FUnaccounted, FUnspecified: Boolean; FPriceB, FPriceC, FPriceF, FPriceL: Currency; FSalaryB, FSalaryC, FSalaryF, FSalaryL: Currency; FPortageB, FPortageC, FWarehouseB, FWarehouseC: Currency; FResType: TEstimateResourceType; FOwner: TEstPositionPtr; FCoefficients: TEstCoefficients; FInflationRates: TEstInflationRates; FPrice: IEstPriceV2; function GetAverageTariff: Double; function GetCoefficient(Index: Integer): IEstCoefficientV2; function GetCoefficients: TEstCoefficients; function GetConsumption: Double; function GetConsumptionTotal: Double; function GetCustom: Boolean; function GetCypher: string; function GetInflationRate(Index: Integer): IEstInflationRateV2; function GetInflationRates: TEstInflationRates; function GetLabor: Double; function GetName: string; function GetNum: Word; function GetNumRef: Word; function GetOwnerPtr: TEstPositionPtr; function GetPortageB: Currency; function GetPortageC: Currency; function GetPrice: IEstPriceV2; function GetPriceB: Currency; function GetPriceC: Currency; function GetPriceF: Currency; function GetPriceL: Currency; function GetResType: TEstimateResourceType; function GetUnaccounted: Boolean; function GetUnitsName: String; function GetUnspecified: Boolean; function GetWarehouseB: Currency; function GetWarehouseC: Currency; procedure SetAverageTariff(Value: Double); procedure SetConsumption(Value: Double); procedure SetConsumptionTotal(Value: Double); procedure SetCustom(Value: Boolean); procedure SetCypher(Value: string); procedure SetLabor(Value: Double); procedure SetName(Value: string); procedure SetNum(Value: Word); procedure SetNumRef(Value: Word); procedure SetOwnerPtr(Value: TEstPositionPtr); procedure SetPortageB(Value: Currency); procedure SetPortageC(Value: Currency); procedure SetPriceB(Value: Currency); procedure SetPriceC(Value: Currency); procedure SetPriceF(Value: Currency); procedure SetPriceL(Value: Currency); procedure SetResType(Value: TEstimateResourceType); function GetSalaryB: Currency; function GetSalaryC: Currency; function GetSalaryF: Currency; function GetSalaryL: Currency; procedure SetSalaryB(Value: Currency); procedure SetSalaryC(Value: Currency); procedure SetSalaryF(Value: Currency); procedure SetSalaryL(Value: Currency); procedure SetUnaccounted(Value: Boolean); procedure SetUnitsName(Value: string); procedure SetUnspecified(Value: Boolean); procedure SetWarehouseB(Value: Currency); procedure SetWarehouseC(Value: Currency); strict protected function FromDocCoefficients(pDoc: PDocVariantData): Boolean; function FromDocRates(PDoc: PDocVariantData): Boolean; public /// Средний разряд работ property AverageTariff: Double read GetAverageTariff write SetAverageTariff; /// Поправочные коэффициенты применённые к ресурсу property Coefficient[Index: Integer]: IEstCoefficientV2 read GetCoefficient; /// Массив коэффицентов, применённых к ресурсу property Coefficients: TEstCoefficients read GetCoefficients; /// Расход ресурса на единицу измерения property Consumption: Double read GetConsumption write SetConsumption; /// Полный расход ресурса // для подчинённых позиций на объём расценки // для свободных ресурсов определяется сметчиком property ConsumptionTotal: Double read GetConsumptionTotal write SetConsumptionTotal; /// Признак прайсовой позиции property Custom: Boolean read GetCustom write SetCustom; /// Шифр ресурса property Cypher: string read GetCypher write SetCypher; /// Индексы пересчёта применённые к ресурсу property InflationRate[Index: Integer]: IEstInflationRateV2 read GetInflationRate; /// Индексы пересчёта применённые к ресурсу property InflationRates: TEstInflationRates read GetInflationRates; /// Затраты труда property Labor: Double read GetLabor write SetLabor; /// Наименование ресурса property Name: string read GetName write SetName; /// Номер ресурса property Num: Word read GetNum write SetNum; /// Ссылка на номер ресурса в списке, к которому относится данный ресурс property NumRef: Word read GetNumRef write SetNumRef; /// Указатель на интерфейс для работы с информацией о позиции, содержащей ресурс property OwnerPtr: TEstPositionPtr read GetOwnerPtr write SetOwnerPtr; /// Инегрированный показатель стоимости ресурса property Price: IEstPriceV2 read GetPrice; /// Транспортные расходы в базисных ценах property PortageB: Currency read GetPortageB write SetPortageB; /// Транспортные расходы в текущих ценах property PortageC: Currency read GetPortageC write SetPortageC; /// Стоимость ресурса в базисном уровне цен property PriceB: Currency read GetPriceB write SetPriceB; /// Стоимость ресурса в текущем уровне цен property PriceC: Currency read GetPriceC write SetPriceC; /// Стоимость ресурса фактическая property PriceF: Currency read GetPriceF write SetPriceF; /// Стоимость ресурса местная property PriceL: Currency read GetPriceL write SetPriceL; /// Тип ресурса property ResType: TEstimateResourceType read GetResType write SetResType; /// Заработная плата машинистов в базисных ценах property SalaryB: Currency read GetSalaryB write SetSalaryB; /// Заработная плата машинистов в текущих ценах property SalaryC: Currency read GetSalaryC write SetSalaryC; /// Заработная плата машинистов фактическая property SalaryF: Currency read GetSalaryF write SetSalaryF; /// Заработная плата машинистов местная property SalaryL: Currency read GetSalaryL write SetSalaryL; /// Признак игнорирования в расчете стоимости property Unaccounted: Boolean read GetUnaccounted write SetUnaccounted; /// Единица измерения объёма property UnitsName: string read GetUnitsName write SetUnitsName; /// Признак обобщенного наименования property Unspecified: Boolean read GetUnspecified write SetUnspecified; /// Заготовительно-складские расходы в базисном уровне цен property WarehouseB: Currency read GetWarehouseB write setWarehouseB; /// Заготовительно-складские расходы в текущем уровне цен property WarehouseC: Currency read GetWarehouseC write setWarehouseC; /// конструктор constructor Create(const rt: TEstimateResourceType; const aName: string; const aNum: Word=0); /// Функция добавляет индекс пересчёта function AddIndex(Idx: IEstInflationRateV2): Integer; /// Функция добавляет поправочный коэффициент, применённый к ресурсу function AddCoefficient(Coef: IEstCoefficientV2): Integer; /// Функция добавляет к элементу стоимости работ ресурса значение function AddPriceItem(const Value: Currency; const ct:TEstimateCostType; const pt: TEstimatePriceItemType): Integer; /// Функция возвращает количество поправочных коэффициентов, применённых к ресурсу function CoefficientsCount: Integer; /// Функция возвращает количество индексов, применённых к ресурсу function InflationRatesCount: Integer; /// Функция загружает информацию из JSON-документа function FromDoc(const PDoc: PDocVariantData): Boolean; /// Функция возвращает документ JSON с информацией о ресурсе function ToDoc: Variant; end; /// Класс описывающий ресурс-материал TEstMaterialRes = class(TEstResource) private procedure SetResType(Value: TEstimateResourceType); public /// конструктор constructor Create(const aName: string; const aNum: Word=0); end; /// функция проверяет соотвествие шифра расценки шаблону // Cyp - исследуемый шифр // CypMask - шаблон соответствия function ValidateEstResourceCypher(const Cyp: string; const CypMask: string): Boolean; /// функция проверяет соотвествие шифра расценки шаблону и, если это возможно, приводит шифр в соответствие шаблону // Cyp - исследуемый шифр // CypMask - шаблон соответствия // CorrectedCyp - шифр соответствующий шаблону function CorrectEstResourceCypher(const Cyp: string; const CypMask: string; out CorrectedCyp: string): Boolean; implementation function ValidateEstResourceCypher(const Cyp: string; const CypMask: string): Boolean; begin end; function CorrectEstResourceCypher(const Cyp: string; const CypMask: string; out CorrectedCyp: string): Boolean; begin end; { TEstResource } function TEstResource.AddCoefficient(Coef: IEstCoefficientV2): Integer; begin if Coef<>nil then begin Result:= Length(FCoefficients); SetLength(FCoefficients, Result+1); FCoefficients[Result]:=Coef; end else Result:=-1 end; function TEstResource.AddIndex(Idx: IEstInflationRateV2): Integer; begin if Idx<>nil then begin Result:= Length(FInflationRates); SetLength(FInflationRates, Result+1); FInflationRates[Result]:=Idx; end else Result:=-1 end; function TEstResource.AddPriceItem(const Value: Currency; const ct: TEstimateCostType; const pt: TEstimatePriceItemType): Integer; begin FPrice.PriceValue[ct,pt]:=Value; Result:=FPrice.Count; end; function TEstResource.CoefficientsCount: Integer; begin Result:=Length(FCoefficients); end; constructor TEstResource.Create(const rt: TEstimateResourceType; const aName: string; const aNum: Word); begin inherited Create(); SetNum(aNum); SetName(aName); SetResType(rt); SetLength(FCoefficients,0); SetLength(FInflationRates,0); FPrice:= TEstPriceResource.Create; end; function TEstResource.GetAverageTariff: Double; begin end; function TEstResource.GetCoefficient(Index: Integer): IEstCoefficientV2; begin if (Low(FCoefficients)<=Index) and (High(FCoefficients)>=Index) then Result:=FCoefficients[Index] else Result:=nil; end; function TEstResource.GetCoefficients: TEstCoefficients; begin Result:=FCoefficients; end; function TEstResource.GetConsumption: Double; begin Result:=FConsumption; end; function TEstResource.GetConsumptionTotal: Double; begin Result:=FConsumptionTotal; end; function TEstResource.GetCustom: Boolean; begin Result:=FCustom; end; function TEstResource.GetCypher: string; begin Result:=FCypher; end; function TEstResource.GetInflationRate(Index: Integer): IEstInflationRateV2; begin if (Low(FInflationRates)<=Index) and (High(FInflationRates)>=Index) then Result:=FInflationRates[Index] else Result:=nil; end; function TEstResource.GetInflationRates: TEstInflationRates; begin Result:=FInflationRates; end; function TEstResource.GetLabor: Double; begin Result:=FLabour; end; function TEstResource.GetName: string; begin Result:=FName; end; function TEstResource.GetNum: Word; begin Result:=FNum; end; function TEstResource.GetNumRef: Word; begin Result:=FNumRef; end; function TEstResource.GetOwnerPtr: TEstPositionPtr; begin Result:=FOwner; end; function TEstResource.GetPortageB: Currency; begin Result:=FPrice.PriceValue[ectBase, epiPortage]; end; function TEstResource.GetPortageC: Currency; begin Result:=FPrice.PriceValue[ectCurr, epiPortage]; end; function TEstResource.GetPrice: IEstPriceV2; begin Result:=FPrice; end; function TEstResource.GetPriceB: Currency; begin Result:=FPriceB; end; function TEstResource.GetPriceC: Currency; begin Result:=FPriceC; end; function TEstResource.GetPriceF: Currency; begin Result:=FPriceF; end; function TEstResource.GetPriceL: Currency; begin Result:=FPriceL; end; function TEstResource.GetRestype: TEstimateResourceType; begin Result:=FResType; end; function TEstResource.GetSalaryB: Currency; begin Result:=FSalaryB; end; function TEstResource.GetSalaryC: Currency; begin Result:=FSalaryC; end; function TEstResource.GetSalaryF: Currency; begin Result:=FSalaryF; end; function TEstResource.GetSalaryL: Currency; begin Result:=FSalaryL; end; function TEstResource.GetUnaccounted: Boolean; begin Result:=FUnaccounted; end; function TEstResource.GetUnitsName: String; begin Result:=FUnitsName; end; function TEstResource.GetUnspecified: Boolean; begin Result:= FUnspecified; end; function TEstResource.GetWarehouseB: Currency; begin Result:=FPrice.PriceValue[ectBase, epiWarehouse]; end; function TEstResource.GetWarehouseC: Currency; begin Result:=FPrice.PriceValue[ectCurr, epiWarehouse]; end; function TEstResource.InflationRatesCount: Integer; begin Result:=Length(FInflationRates); end; procedure TEstResource.SetAverageTariff(Value: Double); begin end; procedure TEstResource.SetConsumption(Value: Double); begin FConsumption:=Value; end; procedure TEstResource.SetConsumptionTotal(Value: Double); begin FConsumptionTotal:=Value; end; procedure TEstResource.SetCustom(Value: Boolean); begin FCustom:=Value; end; procedure TEstResource.SetCypher(Value: string); begin FCypher:=Value; end; procedure TEstResource.SetLabor(Value: Double); begin FLabour:=Value; end; procedure TEstResource.SetName(Value: string); begin FName:=Value; end; procedure TEstResource.SetNum(Value: Word); begin FNum:=Value; end; procedure TEstResource.SetNumRef(Value: Word); begin FNumRef:=Value; end; procedure TEstResource.SetOwnerPtr(Value: TEstPositionPtr); begin FOwner:=Value; end; procedure TEstResource.SetPortageB(Value: Currency); begin FPrice.PriceValue[ectBase, epiPortage]:=Value; end; procedure TEstResource.SetPortageC(Value: Currency); begin FPrice.PriceValue[ectCurr, epiPortage]:=Value; end; procedure TEstResource.SetPriceB(Value: Currency); begin FPriceB:=Value; end; procedure TEstResource.SetPriceC(Value: Currency); begin FPriceC:=Value; end; procedure TEstResource.SetPriceF(Value: Currency); begin FPriceF:=Value; end; procedure TEstResource.SetPriceL(Value: Currency); begin FPriceL:=Value; end; procedure TEstResource.SetResType(Value: TEstimateResourceType); begin FResType:=Value; end; procedure TEstResource.SetSalaryB(Value: Currency); begin FSalaryB:=Value; end; procedure TEstResource.SetSalaryC(Value: Currency); begin FSalaryC:=Value; end; procedure TEstResource.SetSalaryF(Value: Currency); begin FSalaryF:=Value; end; procedure TEstResource.SetSalaryL(Value: Currency); begin FSalaryL:=Value; end; procedure TEstResource.SetUnaccounted(Value: Boolean); begin FUnaccounted:=Value; end; procedure TEstResource.SetUnitsName(Value: string); begin FUnitsName:=Value; end; procedure TEstResource.SetUnspecified(Value: Boolean); begin FUnspecified:=Value; end; procedure TEstResource.SetWarehouseB(Value: Currency); begin FPrice.PriceValue[ectBase, epiWarehouse]:=Value; end; procedure TEstResource.SetWarehouseC(Value: Currency); begin FPrice.PriceValue[ectCurr, epiWarehouse]:=Value; end; function TEstResource.FromDoc(const PDoc: PDocVariantData): Boolean; var rCyp, rName, rUName: RawUtf8; i: Integer; iCur: Int64; cCur: Currency absolute iCur; begin Result := (PDoc<>nil) and (PDoc^.Kind=dvObject) and PDoc^.GetAsRawUtf8('cyp',rCyp) and PDoc^.GetAsRawUtf8('nam',rName) and PDoc^.GetAsRawUtf8('unt',rUName) and PDoc^.GetAsDouble('qty', FConsumption) and PDoc^.GetAsInt64('prb', iCur) and PDoc^.GetAsInteger('typ', i) ; if not Result then Exit; FCypher := Utf8ToString(rCyp); FName := Utf8ToString(rName); FUnitsName := Utf8ToString(rUName); FResType := TEstimateResourceType(i); FPriceB := cCur; Result:=FromDocCoefficients(pDoc^.GetAsDocVariantSafe('cfs')); if PDoc^.GetAsInteger('num', i) then FNum := i else FNum := 0; if PDoc^.GetAsInteger('ref', i) then FNumRef := i else FNumRef := 0; if not PDoc^.GetAsDouble('tot', FConsumptionTotal) then FConsumptionTotal := 0; if not PDoc^.GetAsDouble('lab', FLabour) then FLabour := 0; if not PDoc^.GetAsBoolean('una', FUnaccounted) then FUnaccounted := False; if not PDoc^.GetAsBoolean('uns', FUnspecified) then FUnspecified := False; end; function TEstResource.FromDocCoefficients(pDoc: PDocVariantData): Boolean; var i: Integer; coef: IEstCoefficientV2; begin Result := True; if (pDoc=nil) or (pDoc^.Count=0) then Exit; Result := (pDoc^.Kind=dvArray); if not Result then Exit; for i := 0 to pDoc^.Count-1 do begin coef := TEstCoefficient.Create(eckResource,'',0); if coef.FromDoc(pDoc^._[i]) then Result := (AddCoefficient(coef)>=0) else Result := False; if not Result then Break; end; end; function TEstResource.FromDocRates(PDoc: PDocVariantData): Boolean; var i: Integer; r: IEstInflationRateV2; begin // Result := True; if (pDoc=nil) or (pDoc^.Count=0) then Exit; // Result := (pDoc^.Kind=dvArray); if not Result then Exit; // for i := 0 to PDoc^.Count-1 do begin // r := TEstInflationRate.Create(''); // if r.FromDoc(PDoc^._[i]) then Result := (AddInflationRate(r)>=0) // else REsult := False; // if not Result then Break; // end; end; function TEstResource.ToDoc: Variant; var iCur: Int64; cCur: Currency absolute iCur; idx: IEstInflationRateV2; coef: IEstCoefficientV2; a,v: Variant; begin TDocVariant.New(Result); TDocVariantData(Result).AddValue('cyp', StringToUTF8(FCypher)); TDocVariantData(Result).AddValue('nam', StringToUTF8(FName)); TDocVariantData(Result).AddValue('unt', StringToUTF8(FUnitsName)); TDocVariantData(Result).AddValue('num', FNum); TDocVariantData(Result).AddValue('ref', FNumRef); TDocVariantData(Result).AddValue('qty', FConsumption); TDocVariantData(Result).AddValue('tot', FConsumptionTotal); cCur:=FPriceB; TDocVariantData(Result).AddValue('prb', iCur); TDocVariantData(Result).AddValue('tot', FConsumptionTotal); TDocVariantData(Result).AddValue('lab', FLabour); TDocVariantData(Result).AddValue('cst', FCustom); TDocVariantData(Result).AddValue('una', FUnaccounted); TDocVariantData(Result).AddValue('uns', FUnspecified); TDocVariantData(Result).AddValue('typ', Ord(FResType)); // FPriceC, FPriceF, FPriceL: Currency; // FSalaryB, FSalaryC, FSalaryF, FSalaryL: Currency; // FOwner: TEstPositionPtr; for idx in FInflationRates do begin TDocVariantData(v).Reset; v:=idx.ToDoc; TDocVariantData(a).AddItem(v); end; TDocVariantData(Result).AddValue('idx', a); TDocVariantData(a).Reset; for coef in FCoefficients do begin TDocVariantData(v).Reset; v:=coef.ToDoc; TDocVariantData(a).AddItem(v); end; TDocVariantData(Result).AddValue('cfs', a); TDocVariantData(a).Reset; end; { TEstMaterialRes } constructor TEstMaterialRes.Create(const aName: string; const aNum: Word); begin inherited Create(ertMaterial, aName, aNum); end; procedure TEstMaterialRes.SetResType(Value: TEstimateResourceType); begin if Value<>FResType then raise Exception.Create('Для данного класса нельзя изменять значение'); end; end.