create procedure ZPLT_CALCSLVBL1 ( PRSNID integer, BDATE timestamp, EDATE timestamp, BLDATE date, SUBTYP integer = 0) returns ( MONTH__SUMMA double precision, MONTH_DAYS double precision, MONTH_HLDDAYS integer, MONTH_WKNDAYS integer, MONTH_FCTDAYS double precision, WTIME double precision, MONTH_BLDAYS integer, DAYWITHOUTPAY double precision) as declare variable XDATE date; declare variable DAYOFWEEK integer; declare variable XDAYS double precision; declare variable CDATE timestamp; declare variable DATE1 timestamp; declare variable DATE2 timestamp; declare variable K double precision; declare variable MZPID integer; begin MONTH__SUMMA =0.0; MONTH_HLDDAYS =0.0; MONTH_FCTDAYS =0.0; WTIME =0.0; MONTH_BLDAYS =0; DAYWITHOUTPAY =0.0; /* праздничные дни за расчетный период */ select Days from Zplt_HldDays(:bDate, :eDate) into :Month_HLDDays; --кол-во календарных дней month_days=0.0; --кол-во выходных дней month_wkndays=0.0; xDate = :bDate; while (:xDate <= :eDate) do begin Month_Days = Month_Days + 1; Select Result from F_DayOfWeek(:xDate) into :DayOfWeek; if (:DayOfWeek in (5,6)) then Month_WknDays = Month_WknDays + 1; xDate = :xDate + 1; end Month_FctDays=:Month_Days; /*Больничные дни за текущий месяц*/ for select CI.blDate, CI.elDate from ZpltCalcSlv S join ZpltCalcIncr CI on CI.SlvID=S.ID and CI.blDate <= :eDate and CI.elDate >= :bDate and CI.blDate is not Null and CI.elDate is not Null join ZpltIncr I on I.ID=CI.IncrID and I.System_Flag in (3, 8, 9) where S.PrsnID=:PrsnID into :Date1, :Date2 do begin if (:Date1 < :bDate) then Date1 = :bDate; if (:Date2 > :eDate) then Date2 = :eDate; select Result + 1 from F_ElapsedDays(:Date1, :Date2) into :XDays; Month_FctDays = :Month_FctDays - :XDays; Month_Bldays = :Month_Bldays + :XDays; end for select V.bDate, V.eDate from ZpltSertVacat V where V.PrsnID=:PrsnID and V.Typ=1 and V.bDate <= :eDate and V.eDate >= :bDate and V.bDate is not Null and V.eDate is not Null into :Date1, :Date2 do begin if (:Date1 < :bDate) then Date1 = :bDate; if (:Date2 > :eDate) then Date2 = :eDate; select Result + 1 from F_ElapsedDays(:Date1, :Date2) into :XDays; DayWithOutPay = :DayWithOutPay + :XDays; Month_FctDays = :Month_FctDays - :DayWithOutPay; end Select xDate from F_MONTHLASTDAY(:edate) into :CDate; if (:edate<>:cdate) then edate=:cdate; --отработанное за месяц время Select coalesce((Sum(S.wTime)),0.0) from ZpltCalcMst M, ZpltCalcSlv S where M.DAT_ >= :BDATE and M.DAT_ <= :EDATE and M.Avans=0 and S.MstID=M.ID and S.PrsnID = :PrsnID into :WTime; --сумма начислений за месяц MONTH__SUMMA=0.0; Select coalesce(Sum(C.cSumma),0.0) from ZpltCalcMst M, ZpltCalcSlv S, ZpltCalcIncr C, ZpltIncr I where M.DAT_ >= :BDATE and M.DAT_ <= :EDATE and M.Avans=0 and S.MstID=M.ID and S.PrsnID = :PrsnID and C.SlvID=S.ID and I.ID=C.IncrID -- прочие начисления, оклад, индексация and (I.System_Flag in (0, 1, 7, 15) or I.System_Flag is Null or (I.System_Flag = 5 and :blDate >= '04.07.2015') ) into :month__summa; --Расчет суммы начислений при отработанном неполном месяце(второй месяц работы на предприятиии -- как правило текущий для расчета зп) if (SubTyp=2) then begin select Result + 1 from F_ElapsedDays(:bdate, :CDate) into :XDays; Select coalesce(Sum(C.cSumma),0.0) from ZpltCalcMst M, ZpltCalcSlv S, ZpltCalcIncr C, ZpltIncr I where M.DAT_ >= :BDATE and M.DAT_ <= :CDate and M.Avans=0 and S.MstID=M.ID and S.PrsnID = :PrsnID and C.SlvID=S.ID and I.ID=C.IncrID -- прочие начисления, оклад, индексация and (I.System_Flag in (0, 1, 7, 15) or I.System_Flag is Null or (I.System_Flag = 5 and :blDate >= '04.07.2015') ) -- and not upper(i.name) like '%ПРЕМИ%' -- исключить начисление премия, которая начисляется по итогам месяца into :month__summa; k=(:month_days)/(:xdays); Month__Summa = round(:Month__Summa*:k,2); end -- Расчет по минимальной зп if (:SubTyp = 3) then begin select ID from CurrTyp where Sys_Flag = 3 into :mzpID; select Val from Currency_GetValue(:mzpID, :eDate) into :Month__Summa; Month_Days= 30.44; Month_FctDays=:Month_Days; end Suspend; end