module.exports=[64154,a=>{"use strict";var b=a.i(7402);a.s([],10217),a.i(10217),a.s(["40b2950202e96952279cbe14b3859f30bd930a8ee2",()=>b.generateReport],64154)},7402,a=>{"use strict";var b=a.i(37936),c=a.i(18558),d=a.i(66518),e=a.i(9307),f=a.i(36580);function g(a){if(null==a)return null;let b=String(a).trim();return""===b?null:b}async function h(a){let b=await (0,e.requireAccess)("systeme","write"),h=String(a.get("name")??"").trim();h&&(await d.prisma.automation.create({data:{name:h,trigger:a.get("trigger")??"CONTRAT_ECHEANCE",action:a.get("action")??"CREER_TACHE",config:g(a.get("config"))}}),await (0,f.logActivity)({userId:b.id,action:"CREATION",entity:"Automatisation",details:h}),(0,c.revalidatePath)("/settings/automations"))}async function i(a){let b=await (0,e.requireAccess)("systeme","write"),g=String(a.get("id")),h=await d.prisma.automation.findUnique({where:{id:g}});await d.prisma.automation.update({where:{id:g},data:{active:!h?.active}}),await (0,f.logActivity)({userId:b.id,action:"MODIFICATION",entity:"Automatisation",entityId:g,details:`Actif → ${!h?.active}`}),(0,c.revalidatePath)("/settings/automations")}async function j(a){let b=await (0,e.requireAccess)("systeme","write"),g=String(a.get("id"));await d.prisma.automation.delete({where:{id:g}}),await (0,f.logActivity)({userId:b.id,action:"SUPPRESSION",entity:"Automatisation",entityId:g}),(0,c.revalidatePath)("/settings/automations")}async function k(a){let b=await (0,e.requireAccess)("systeme","write");await d.prisma.template.create({data:{name:String(a.get("name")??"").trim(),type:String(a.get("type")??"CONTRAT"),content:String(a.get("content")??""),variables:g(a.get("variables"))}}),await (0,f.logActivity)({userId:b.id,action:"CREATION",entity:"Modèle"}),(0,c.revalidatePath)("/settings/templates")}async function l(a){let b=await (0,e.requireAccess)("systeme","write"),g=String(a.get("id"));await d.prisma.template.delete({where:{id:g}}),await (0,f.logActivity)({userId:b.id,action:"SUPPRESSION",entity:"Modèle",entityId:g}),(0,c.revalidatePath)("/settings/templates")}async function m(a){let b=await (0,e.requireAccess)("analyse","write"),g=String(a.get("month")??"");g&&(await d.prisma.monthlyTarget.upsert({where:{month:g},update:{revenue:Number(a.get("revenue")??0),liveRevenue:Number(a.get("liveRevenue")??0),newCreators:Number(a.get("newCreators")??0),signedCampaigns:Number(a.get("signedCampaigns")??0),deliveredProduction:Number(a.get("deliveredProduction")??0)},create:{month:g,revenue:Number(a.get("revenue")??0),liveRevenue:Number(a.get("liveRevenue")??0),newCreators:Number(a.get("newCreators")??0),signedCampaigns:Number(a.get("signedCampaigns")??0),deliveredProduction:Number(a.get("deliveredProduction")??0)}}),await (0,f.logActivity)({userId:b.id,action:"MODIFICATION",entity:"Objectif mensuel",details:g}),(0,c.revalidatePath)("/"),(0,c.revalidatePath)("/settings"),(0,c.revalidatePath)("/analytics/forecasts"))}async function n(a){let b=await (0,e.requireAccess)("analyse","write"),h=String(a.get("type")??"RAPPORT"),i=g(a.get("period")),j=String(a.get("title")??`Rapport ${h} ${i??""}`).trim(),k=await o(i);await d.prisma.report.create({data:{title:j,type:h,period:i,data:JSON.stringify(k),createdById:b.id}}),await (0,f.logActivity)({userId:b.id,action:"CREATION",entity:"Rapport",details:j}),(0,c.revalidatePath)("/reports")}async function o(a){let b=a??`${new Date().getFullYear()}-${String(new Date().getMonth()+1).padStart(2,"0")}`,[c,e,f,g]=await Promise.all([d.prisma.creator.count(),d.prisma.creatorPerformance.aggregate({_sum:{revenue:!0},where:{period:b}}),d.prisma.campaign.count(),d.prisma.invoice.findMany({where:{status:{in:["EMISE","ENVOYEE","RELANCEE","PAYEE"]}}})]);return{period:b,generatedAt:new Date().toISOString(),creators:c,liveRevenue:e._sum.revenue??0,campaigns:f,revenue:g.reduce((a,b)=>a+b.amount,0)}}(0,a.i(13095).ensureServerEntryExports)([h,i,j,k,l,m,n]),(0,b.registerServerReference)(h,"40e71ca6e6399c1ea60c37cb120dc711e0cd2a41f8",null),(0,b.registerServerReference)(i,"40d535353ac5832a92e79f71a2a4c4a535ebff2ad8",null),(0,b.registerServerReference)(j,"40c666b8142075919cc446140f96ab014be3ca2109",null),(0,b.registerServerReference)(k,"400da584ef99050d50d6f1eda119ef64f2a5c2593c",null),(0,b.registerServerReference)(l,"402f2076a7ec22fe7d665210e20c470740bc5ae245",null),(0,b.registerServerReference)(m,"40a5a4f3887983b810064f6a59bd5ae81a8b4739c2",null),(0,b.registerServerReference)(n,"40b2950202e96952279cbe14b3859f30bd930a8ee2",null),a.s(["createAutomation",0,h,"createTemplate",0,k,"deleteAutomation",0,j,"deleteTemplate",0,l,"generateReport",0,n,"saveMonthlyTarget",0,m,"toggleAutomation",0,i])},36580,a=>{"use strict";var b=a.i(66518);async function c(a){return b.prisma.activityLog.create({data:{userId:a.userId,action:a.action,entity:a.entity,entityId:a.entityId??null,details:a.details??null}})}a.s(["logActivity",0,c])}];

//# sourceMappingURL=_0_amcht._.js.map