Summary
Functions
Approves a requisition.
Assigns a requisition to staff member.
Calculate the number of days a transaction is overdue.
Calculate the fine amount for an overdue transaction.
Calculates membership expiry based on member type configuration.
Cancels a pending payment.
Cancels a reservation.
Creates a transaction (checkout) - respects node and member type policies.
Count active reservations (pending and available). If node_id is nil, returns count for all nodes. Reservations don't have unit_id, so we join to collection.
Count active transactions. If node_id is nil, returns count for all nodes.
Count history entries that occurred on a given date (UTC date comparison).
Count history entries for a specific event type on a given date.
Count overdue transactions. If node_id is nil, returns count for all nodes.
Creates a collection-level reservation - respects member type policies.
Creates a payment link for a fine using Xendit.
Creates a requisition.
If requested_by_id is provided, sets request_date and status.
Creates a reservation for an item - simplified version for LiveView.
Creates a reservation - respects member type reservation policies.
Expires old reservations that haven't been picked up.
Marks a requisition as fulfilled.
Fulfills a reservation (converts to checkout).
Get the active transaction for a specific item. Returns nil if no active transaction found.
Returns a map with all circulation stats for a given node. If node_id is nil, returns stats for all nodes (super admin view).
Gets a fine by transaction id if present. Returns {:ok, fine} or {:error, reason}
Gets a fine with all related details including payments. Returns {:ok, fine} or {:error, reason}
Gets circulation history for an item.
Gets circulation history for a member.
Gets member's total outstanding fine amount.
Gets recommended items for a member based on their borrowing history and member type access.
Gets member type by slug.
Gets a payment by ID with preloaded associations.
Gets a payment by external_id.
Gets pending payments for a fine.
Safe non-bang version of get_transaction/1. Returns the transaction struct preloaded or nil if not found.
Handles Xendit webhook callback for payment updates.
Checks if any holidays are configured for the library.
Checks if weekly schedule is configured for the library.
Gets all active member types.
Returns the circulation history.
Gets circulation history for a member with pagination and filters.
List circulation history paginated with filters and node filtering. Only returns history for items belonging to the specified node.
Gets expired reservations.
Lists payments for a fine.
List fines paginated with filters and node filtering. Only returns fines for items belonging to the specified node.
Gets active transactions for a member.
Lists all fines for a member (including pending, paid, and waived).
Lists paid fines for a member with pagination. Returns {[fines], total_pages}
Lists payments for a member.
Gets active reservations for a member.
Lists transaction history for a member (returned/completed transactions) with pagination. Returns {[transactions], total_pages}
Gets unpaid fines for a member.
Lists all members with active loans, grouped by member. Returns paginated results with member info and their active transaction count. Useful for librarians to see who has active loans and send manual reminders.
Gets overdue transactions.
Gets requisitions by status.
List reservations paginated with filters and node filtering. Only returns reservations for items belonging to the specified node.
List transactions paginated with filters and node filtering. Only returns transactions for items belonging to the specified node.
Gets transactions due soon (within specified days).
Manually marks a payment as paid (for in-person cash payments).
Marks a reservation as available for pickup.
Checks if a member's privileges should be suspended based on fines.
Pays a fine (full or partial payment).
Auto-renew items for member types that support it and haven't reached max renewals.
Marks overdue transactions and creates fines based on member type policies.
Rejects a requisition.
Renews a transaction - respects member type renewal policies.
Returns an item (return).
Determines whether to skip holidays in fine calculation based on library configuration. If no holidays are configured (library is open all day), skip holidays in calculation. If holidays are configured, use business days only.
Suggest items for autocomplete by item_code, collection title, or collection description. Returns a list of items (preloaded with collection) matching the query.
Calculate the total amount of unpaid fines for a member. Returns a Decimal representing the sum of all balances.
Sum outstanding fines. If node_id is nil, returns sum for all nodes.
Waives a fine.
Functions
Approves a requisition.
Assigns a requisition to staff member.
Calculate the number of days a transaction is overdue.
Options:
- skip_holidays: boolean (default: false) - when true, counts ALL calendar days; when false, excludes holidays/weekends
Examples
iex> calculate_days_for_fine(transaction, skip_holidays: true)
10 # All calendar days
iex> calculate_days_for_fine(transaction, skip_holidays: false)
7 # Business days only (excluding weekends/holidays)
Calculate the fine amount for an overdue transaction.
Options:
- skip_holidays: boolean (default: false) - when true, counts ALL calendar days; when false, excludes holidays/weekends
Returns the calculated fine amount as a Decimal, respecting the member type's fine_per_day and max_fine settings.
Examples
iex> calculate_fine_amount(transaction, member_type, skip_holidays: true)
#Decimal<50000> # 10 days × 5000/day
iex> calculate_fine_amount(transaction, member_type, skip_holidays: false)
#Decimal<35000> # 7 business days × 5000/day
Calculates membership expiry based on member type configuration.
Cancels a pending payment.
Cancels a reservation.
Creates a transaction (checkout) - respects node and member type policies.
Pass node or node_id in attrs to apply node-specific rules:
checkout_item(member_id, item_id, librarian_id, %{node: node})
checkout_item(member_id, item_id, librarian_id, %{node_id: 123})
When node_id is provided but node is not, the node will be fetched automatically.
Node rules are applied when node.override_loan_rules is true.
Count active reservations (pending and available). If node_id is nil, returns count for all nodes. Reservations don't have unit_id, so we join to collection.
Count active transactions. If node_id is nil, returns count for all nodes.
Count history entries that occurred on a given date (UTC date comparison).
Count history entries for a specific event type on a given date.
Count overdue transactions. If node_id is nil, returns count for all nodes.
Creates a collection-level reservation - respects member type policies.
Creates a payment link for a fine using Xendit.
Options
:success_redirect_url- URL to redirect after successful payment:failure_redirect_url- URL to redirect after failed payment
Examples
# Librarian creates payment link for member
iex> create_payment_link_for_fine(fine_id, librarian_id)
{:ok, %Payment{payment_url: "https://checkout.xendit.co/...", status: "pending"}}
# Member creates payment link for themselves (self-service)
iex> create_payment_link_for_fine(fine_id, member_id)
{:ok, %Payment{payment_url: "https://checkout.xendit.co/...", status: "pending"}}
Creates a requisition.
If requested_by_id is provided, sets request_date and status.
Creates a reservation for an item - simplified version for LiveView.
Creates a reservation - respects member type reservation policies.
Expires old reservations that haven't been picked up.
Marks a requisition as fulfilled.
Fulfills a reservation (converts to checkout).
Get the active transaction for a specific item. Returns nil if no active transaction found.
Returns a map with all circulation stats for a given node. If node_id is nil, returns stats for all nodes (super admin view).
Examples
iex> get_circulation_stats(1)
%{active_transactions: 10, overdue_count: 2, active_reservations: 5, outstanding_fines: 50000}
iex> get_circulation_stats(nil)
%{active_transactions: 100, overdue_count: 20, active_reservations: 50, outstanding_fines: 500000}
Gets a fine by transaction id if present. Returns {:ok, fine} or {:error, reason}
Gets a fine with all related details including payments. Returns {:ok, fine} or {:error, reason}
Gets circulation history for an item.
Gets circulation history for a member.
Gets member's total outstanding fine amount.
Gets recommended items for a member based on their borrowing history and member type access.
Gets member type by slug.
Gets a payment by ID with preloaded associations.
Gets a payment by external_id.
Gets pending payments for a fine.
Safe non-bang version of get_transaction/1. Returns the transaction struct preloaded or nil if not found.
Handles Xendit webhook callback for payment updates.
Examples
iex> handle_payment_webhook(%{
"external_id" => "payment_123",
"status" => "PAID",
"paid_amount" => 50000
})
{:ok, %Payment{status: "paid"}}
Checks if any holidays are configured for the library.
Checks if weekly schedule is configured for the library.
Gets all active member types.
Returns the circulation history.
Gets circulation history for a member with pagination and filters.
List circulation history paginated with filters and node filtering. Only returns history for items belonging to the specified node.
Gets expired reservations.
Lists payments for a fine.
List fines paginated with filters and node filtering. Only returns fines for items belonging to the specified node.
Gets active transactions for a member.
Lists all fines for a member (including pending, paid, and waived).
Lists paid fines for a member with pagination. Returns {[fines], total_pages}
Lists payments for a member.
Gets active reservations for a member.
Lists transaction history for a member (returned/completed transactions) with pagination. Returns {[transactions], total_pages}
Gets unpaid fines for a member.
Lists all members with active loans, grouped by member. Returns paginated results with member info and their active transaction count. Useful for librarians to see who has active loans and send manual reminders.
Gets overdue transactions.
Gets requisitions by status.
List reservations paginated with filters and node filtering. Only returns reservations for items belonging to the specified node.
List transactions paginated with filters and node filtering. Only returns transactions for items belonging to the specified node.
Gets transactions due soon (within specified days).
Manually marks a payment as paid (for in-person cash payments).
Marks a reservation as available for pickup.
Checks if a member's privileges should be suspended based on fines.
Pays a fine (full or partial payment).
Auto-renew items for member types that support it and haven't reached max renewals.
Marks overdue transactions and creates fines based on member type policies.
Rejects a requisition.
Renews a transaction - respects member type renewal policies.
Returns an item (return).
Options in attrs:
- skip_holidays: boolean (default: false) - when true, counts ALL calendar days for fines; when false, excludes holidays/weekends from fine calculation
- node: Node struct (optional) - for node-based fine calculation
- node_id: integer (optional) - fetch node automatically for fine calculation
Determines whether to skip holidays in fine calculation based on library configuration. If no holidays are configured (library is open all day), skip holidays in calculation. If holidays are configured, use business days only.
Suggest items for autocomplete by item_code, collection title, or collection description. Returns a list of items (preloaded with collection) matching the query.
Calculate the total amount of unpaid fines for a member. Returns a Decimal representing the sum of all balances.
Sum outstanding fines. If node_id is nil, returns sum for all nodes.
Waives a fine.