2020-08-05 18:40:47 +02:00
|
|
|
class APIEntreprise::EffectifsJob < APIEntreprise::Job
|
2020-05-14 10:56:26 +02:00
|
|
|
def perform(etablissement_id, procedure_id)
|
2023-10-17 13:24:41 +02:00
|
|
|
etablissement = Etablissement.find(etablissement_id)
|
|
|
|
etablissement_params = APIEntreprise::EffectifsAdapter.new(etablissement.siret, procedure_id, *get_current_valid_month_for_effectif).to_params
|
2020-05-14 10:56:26 +02:00
|
|
|
etablissement.update!(etablissement_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_current_valid_month_for_effectif
|
|
|
|
today = Date.today
|
|
|
|
date_update = Date.new(today.year, today.month, 15)
|
|
|
|
|
|
|
|
if today >= date_update
|
|
|
|
[today.strftime("%Y"), today.strftime("%m")]
|
|
|
|
else
|
|
|
|
date = today - 1.month
|
|
|
|
[date.strftime("%Y"), date.strftime("%m")]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|