PageSourceSearch

https://www.pasjonat-taniec.pl/assets/InvoicesManager-DQcJ_NWW.js

js pasjonat-taniec.pl collected 2026-10-09 22:03:30 UTC 9,112 bytes, 6 lines download raw bytes

1import{e as G,c as K,y as M,r,i as S,j as e,B as C,m as V,n as Y,o as Z,ak as J,q as X,L as d,I as j,l as q,K as ee,s as x,N as ae,P as se,Q as te,R as ie,W as ne,Y as T,Z as B,_ as I,$ as R,a0 as W,z as re}from"./index-BLSTqzUa.js";import{u as O}from"./useMutation-DUusf-EJ.js";import{S as U}from"./switch-BwRrTfF2.js";import{T as oe,a as ce,b as N,c as l,d as le,e as n}from"./table-dGpK9cbK.js";import{P as de}from"./plus-BTxjxw_Y.js";import{F as ue}from"./file-text-BArO4Jj1.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const me=G("RotateCw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]),he=()=>new Date().toISOString().slice(0,7),pe=({open:m,onOpenChange:f})=>{var L,P;const{toast:y}=K(),v=M(),[o,z]=r.useState(""),[g,b]=r.useState(""),[i,k]=r.useState(he()),[w,s]=r.useState(""),[t,c]=r.useState(""),[h,p]=r.useState(""),[_,A]=r.useState(""),[D,E]=r.useState(!0),Q=S({queryKey:["invoice-groups"],enabled:m,queryFn:async()=>{const{data:a,error:u}=await x.from("groups").select("id, name, city").order("name");if(u)throw u;return a}}),$=S({queryKey:["invoice-group-members",o],enabled:m&&!!o,queryFn:async()=>{const{data:a,error:u}=await x.from("group_participants").select("participant_id, participants(id, first_name, last_name)").eq("group_id",o);if(u)throw u;return(a??[]).map(H=>H.participants).filter(Boolean)}}),F=O({mutationFn:async()=>{const{data:a,error:u}=await x.functions.invoke("fakturownia-issue",{body:{action:"issue",participant_id:g,group_id:o||null,period:i||null,amount:w?Number(w):null,buyer_name:t||null,buyer_tax_no:h||null,buyer_address:_||null,send_email:D,force:!0}});if(u)throw u;if(a!=null&&a.error)throw new Error(a.error);return a},onSuccess:a=>{v.invalidateQueries({queryKey:["invoice-documents"]}),a!=null&&a.skipped?y({title:"Pominięto",description:a.reason}):y({title:"Dokument wystawiony",description:(a==null?void 0:a.number)??""}),f(!1)},onError:a=>y({title:"Błąd",description:a.message,variant:"destructive"})});return e.jsx(ae,{open:m,onOpenChange:f,children:e.jsxs(se,{className:"max-w-lg",children:[e.jsxs(te,{children:[e.jsx(ie,{children:"Wystaw dokument ręcznie"}),e.jsx(ne,{children:"Dokument zostanie wystawiony na podmiot przypisany do firmy rozliczeniowej grupy."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Grupa"}),e.jsxs(T,{value:o,onValueChange:a=>{z(a),b("")},children:[e.jsx(B,{children:e.jsx(I,{placeholder:"Wybierz grupę"})}),e.jsx(R,{children:(L=Q.data)==null?void 0:L.map(a=>e.jsxs(W,{value:a.id,children:[a.name,a.city?` — ${a.city}`:""]},a.id))})]})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Uczestnik"}),e.jsxs(T,{value:g,onValueChange:b,disabled:!o,children:[e.jsx(B,{children:e.jsx(I,{placeholder:"Wybierz uczestnika"})}),e.jsx(R,{children:(P=$.data)==null?void 0:P.map(a=>e.jsxs(W,{value:a.id,children:[a.first_name," ",a.last_name]},a.id))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Okres (RRRR-MM)"}),e.jsx(j,{value:i,onChange:a=>k(a.target.value.trim()),placeholder:"2026-09"})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Kwota (zł)"}),e.jsx(j,{value:w,onChange:a=>s(a.target.value),placeholder:"z płatności",inputMode:"decimal"})]})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Nabywca (opcjonalnie — domyślnie rodzic/uczestnik)"}),e.jsx(j,{value:t,onChange:a=>c(a.target.value),placeholder:"Imię i nazwisko lub firma"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(d,{children:"NIP nabywcy"}),e.jsx(j,{value:h,onChange:a=>p(a.target.value.trim())})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Adres nabywcy"}),e.jsx(j,{value:_,onChange:a=>A(a.target.value)})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(U,{checked:D,onCheckedChange:E}),e.jsx(d,{children:"Wyślij dokument e-mailem"})]}),e.jsx(C,{className:"w-full",onClick:()=>F.mutate(),disabled:!g||F.isPending,children:F.isPending?e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"h-4 w-4 mr-2 animate-spin"})," Wystawianie…"]}):"Wystaw dokument"})]})]})})},ve=()=>{const{toast:m}=K(),f=M(),[y,v]=r.useState(!1),[o,z]=r.useState(""),g=S({queryKey:["app-setting","fakturownia_auto_issue"],queryFn:async()=>{const{data:s,error:t}=await x.from("app_settings").select("value").eq("key","fakturownia_auto_issue").maybeSingle();if(t)throw t;return(s==null?void 0:s.value)??"true"}}),b=O({mutationFn:async s=>{const{error:t}=await x.from("app_settings").upsert({key:"fakturownia_auto_issue",value:s?"true":"false"},{onConflict:"key"});if(t)throw t},onSuccess:()=>{f.invalidateQueries({queryKey:["app-setting","fakturownia_auto_issue"]}),m({title:"Ustawienie zapisane"})},onError:s=>m({title:"Błąd",description:s.message,variant:"destructive"})}),i=S({queryKey:["invoice-documents"],queryFn:async()=>{const{data:s,error:t}=await x.from("invoice_documents").select("*, participants(first_name, last_name), groups(name), companies(name)").order("created_at",{ascending:!1}).limit(300);if(t)throw t;return s}}),k=r.useMemo(()=>{const s=o.trim().toLowerCase();return s?(i.data??[]).filter(t=>{var c,h,p;return[t.number,t.buyer_name,t.period,(c=t.participants)==null?void 0:c.first_name,(h=t.participants)==null?void 0:h.last_name,(p=t.groups)==null?void 0:p.name].filter(
6Boolean).some(_=>String(_).toLowerCase().includes(s))}):i.data??[]},[i.data,o]),w=async s=>{try{const{data:t,error:c}=await x.functions.invoke("fakturownia-issue",{body:{action:"pdf",document_id:s.id}});if(c)throw c;const h=t instanceof Blob?t:new Blob([t],{type:"application/pdf"}),p=URL.createObjectURL(h);window.open(p,"_blank"),setTimeout(()=>URL.revokeObjectURL(p),6e4)}catch(t){m({title:"Nie udało się pobrać PDF",description:t.message,variant:"destructive"})}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",style:{fontFamily:"var(--font-heading)"},children:"Rachunki i faktury"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{variant:"outline",onClick:()=>i.refetch(),disabled:i.isFetching,children:[e.jsx(me,{className:`h-4 w-4 mr-2 ${i.isFetching?"animate-spin":""}`})," Odśwież"]}),e.jsxs(C,{onClick:()=>v(!0),children:[e.jsx(de,{className:"h-4 w-4 mr-2"})," Wystaw dokument"]})]})]}),e.jsxs(V,{children:[e.jsxs(Y,{className:"pb-3",children:[e.jsxs(Z,{className:"text-base flex items-center gap-2",children:[e.jsx(ue,{className:"h-4 w-4"})," Automatyzacja"]}),e.jsx(J,{children:"Po zaksięgowaniu wpłaty system automatycznie wystawia dokument w Fakturowni i wysyła go e-mailem. Typ dokumentu i podmiot ustawiasz przy każdej firmie (Ustawienia → Firmy)."})]}),e.jsxs(X,{className:"flex items-center gap-3",children:[e.jsx(U,{checked:g.data==="true",onCheckedChange:s=>b.mutate(s)}),e.jsx(d,{children:"Automatyczne wystawianie po zaksięgowaniu wpłaty"})]})]}),e.jsx(j,{value:o,onChange:s=>z(s.target.value),placeholder:"Szukaj: numer, nabywca, uczestnik, grupa, okres…",className:"max-w-md"}),e.jsx("div",{className:"bg-card border border-border rounded-lg overflow-auto",children:e.jsxs(oe,{children:[e.jsx(ce,{children:e.jsxs(N,{children:[e.jsx(l,{children:"Numer"}),e.jsx(l,{children:"Data"}),e.jsx(l,{children:"Uczestnik"}),e.jsx(l,{children:"Grupa"}),e.jsx(l,{children:"Okres"}),e.jsx(l,{children:"Nabywca"}),e.jsx(l,{children:"Firma"}),e.jsx(l,{className:"text-right",children:"Kwota"}),e.jsx(l,{children:"Status"}),e.jsx(l,{})]})}),e.jsxs(le,{children:[i.isLoading&&e.jsx(N,{children:e.jsx(n,{colSpan:10,className:"text-center py-8 text-muted-foreground",children:"Ładowanie…"})}),!i.isLoading&&k.map(s=>{var t,c;return e.jsxs(N,{children:[e.jsx(n,{className:"font-medium",children:s.number??"—"}),e.jsx(n,{className:"text-xs",children:new Date(s.created_at).toLocaleDateString("pl-PL")}),e.jsx(n,{children:s.participants?`${s.participants.first_name} ${s.participants.last_name}`:"—"}),e.jsx(n,{children:((t=s.groups)==null?void 0:t.name)??"—"}),e.jsx(n,{children:s.period??"—"}),e.jsx(n,{children:s.buyer_name??"—"}),e.jsx(n,{children:((c=s.companies)==null?void 0:c.name)??"—"}),e.jsxs(n,{className:"text-right",children:[Number(s.amount).toFixed(2)," zł"]}),e.jsx(n,{children:s.status==="error"?e.jsx(q,{variant:"destructive",title:s.error??"",children:"Błąd"}):s.email_sent_at?e.jsx(q,{className:"bg-emerald-600 hover:bg-emerald-600",children:"Wysłano"}):e.jsx(q,{variant:"secondary",children:"Wystawiony"})}),e.jsx(n,{children:s.fakturownia_id&&e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>w(s),title:"Pobierz PDF",children:e.jsx(ee,{className:"h-4 w-4"})})})]},s.id)}),!i.isLoading&&!k.length&&e.jsx(N,{children:e.jsx(n,{colSpan:10,className:"text-center py-8 text-muted-foreground",children:"Brak dokumentów"})})]})]})}),e.jsx(pe,{open:y,onOpenChange:v})]})};export{ve as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.