import axios from "../../../config/axios";
import { CreateReceiptType } from "../types/ReceiptTypes";

export const getInvoces = async (
  status: string,
  customerId: string,
  search: string,
  date: string,
  endDate: string
) => {
  const params = new URLSearchParams();
  if (status) params.append("status", status);
  if (customerId) params.append("companyId", customerId);
  if (search) params.append("q", search);
  if (date) params.append("since", date);
  if (endDate) params.append("to", endDate);
  const query = params.toString();
  const { data } = await axios.get(`/invoices?${query}`);
  return data;
};

export const createInvoice = async (params: CreateReceiptType) => {
  const { data } = await axios.post(`/invoices`, params);
  return data;
};
