114 lines
3.4 KiB
TypeScript
114 lines
3.4 KiB
TypeScript
import { apiFetch } from './client';
|
|
|
|
export interface Warehouse {
|
|
warehouse_id: string;
|
|
tenant_id: string;
|
|
name: string;
|
|
code: string;
|
|
location_address?: string;
|
|
is_active: boolean;
|
|
created_at: string;
|
|
}
|
|
|
|
export interface PosTerminal {
|
|
terminal_id: string;
|
|
tenant_id: string;
|
|
location_id: string;
|
|
code: string;
|
|
name: string;
|
|
is_active: boolean;
|
|
created_at?: string;
|
|
}
|
|
|
|
export interface PosSession {
|
|
pos_session_id?: string;
|
|
session_id?: string;
|
|
tenant_id: string;
|
|
location_id?: string;
|
|
terminal_id?: string;
|
|
warehouse_id?: string;
|
|
user_id?: string;
|
|
opened_by_user_id?: string;
|
|
cashier_user_id?: string;
|
|
opening_cash: number;
|
|
opening_balance?: number;
|
|
closing_cash?: number;
|
|
closing_balance?: number;
|
|
expected_cash?: number;
|
|
cash_variance?: number;
|
|
|
|
// Domain Sales Breakdown
|
|
ecom_sales_count?: number;
|
|
ecom_sales_amount?: number;
|
|
service_sales_count?: number;
|
|
service_sales_amount?: number;
|
|
courier_charges?: number;
|
|
|
|
// Payment Breakdown
|
|
cash_sales?: number;
|
|
upi_sales?: number;
|
|
card_sales?: number;
|
|
other_sales?: number;
|
|
|
|
status: 'OPEN' | 'CLOSED' | string;
|
|
opened_at?: string;
|
|
closed_at?: string;
|
|
notes?: string;
|
|
session_duration_minutes?: number;
|
|
expires_at?: string;
|
|
}
|
|
|
|
export const inventoryPosService = {
|
|
getWarehouses: async () => {
|
|
return apiFetch<Warehouse[]>('/api/v1/inventory-pos/warehouses');
|
|
},
|
|
|
|
createWarehouse: async (data: Partial<Warehouse>) => {
|
|
return apiFetch<Warehouse>('/api/v1/inventory-pos/warehouses', {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
});
|
|
},
|
|
|
|
getTerminals: async (locationId?: string) => {
|
|
const query = locationId ? `?location_id=${encodeURIComponent(locationId)}` : '';
|
|
return apiFetch<PosTerminal[]>(`/api/v1/inventory-pos/terminals${query}`);
|
|
},
|
|
|
|
createTerminal: async (data: { location_id: string; code: string; name: string }) => {
|
|
return apiFetch<PosTerminal>('/api/v1/inventory-pos/terminals', {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
});
|
|
},
|
|
|
|
getPosSessions: async (status?: string, locationId?: string, userId?: string) => {
|
|
const params = new URLSearchParams();
|
|
if (status) params.append('status', status);
|
|
if (locationId) params.append('location_id', locationId);
|
|
if (userId) params.append('user_id', userId);
|
|
const query = params.toString() ? `?${params.toString()}` : '';
|
|
return apiFetch<PosSession[]>(`/api/v1/inventory-pos/pos-sessions${query}`);
|
|
},
|
|
|
|
openPosSession: async (data: { location_id?: string; terminal_id?: string; warehouse_id?: string; opening_cash?: number; notes?: string }) => {
|
|
return apiFetch<PosSession>('/api/v1/inventory-pos/pos-sessions/open', {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
});
|
|
},
|
|
|
|
closePosSession: async (sessionId: string, closingCash: number, notes?: string) => {
|
|
return apiFetch<PosSession>(`/api/v1/inventory-pos/pos-sessions/${sessionId}/close`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ closing_cash: closingCash, notes }),
|
|
});
|
|
},
|
|
|
|
extendPosSession: async (sessionId: string, data: { extension_minutes: number; reason: string }) => {
|
|
return apiFetch<PosSession>(`/api/v1/inventory-pos/pos-sessions/${sessionId}/extend`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
});
|
|
}
|
|
};
|