create order -> upload bill
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
/// Handles API calls for order-related data.
|
||||
library;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:worker/core/constants/api_constants.dart';
|
||||
import 'package:worker/core/network/dio_client.dart';
|
||||
import 'package:worker/features/orders/data/models/order_status_model.dart';
|
||||
@@ -194,4 +195,56 @@ class OrderRemoteDataSource {
|
||||
throw Exception('Failed to generate QR code: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Upload bill/invoice file
|
||||
///
|
||||
/// Calls: POST /api/method/upload_file
|
||||
/// Form-data: {
|
||||
/// "file": File,
|
||||
/// "is_private": "1",
|
||||
/// "folder": "Home/Attachments",
|
||||
/// "doctype": "Sales Order",
|
||||
/// "docname": "SAL-ORD-2025-00058-1",
|
||||
/// "optimize": "true"
|
||||
/// }
|
||||
/// Returns: { "message": { "file_url": "...", "file_name": "...", ... } }
|
||||
Future<Map<String, dynamic>> uploadBill({
|
||||
required String filePath,
|
||||
required String orderId,
|
||||
}) async {
|
||||
try {
|
||||
// Create multipart form data
|
||||
final formData = FormData.fromMap({
|
||||
'file': await MultipartFile.fromFile(
|
||||
filePath,
|
||||
filename: filePath.split('/').last,
|
||||
),
|
||||
'is_private': '1',
|
||||
'folder': 'Home/Attachments',
|
||||
'doctype': 'Sales Order',
|
||||
'docname': orderId,
|
||||
'optimize': 'true',
|
||||
});
|
||||
|
||||
final response = await _dioClient.post<Map<String, dynamic>>(
|
||||
'${ApiConstants.frappeApiMethod}${ApiConstants.uploadFile}',
|
||||
data: formData,
|
||||
);
|
||||
|
||||
final data = response.data;
|
||||
if (data == null) {
|
||||
throw Exception('No data received from uploadBill API');
|
||||
}
|
||||
|
||||
// Extract file info from Frappe response
|
||||
final message = data['message'] as Map<String, dynamic>?;
|
||||
if (message == null) {
|
||||
throw Exception('No message field in uploadBill response');
|
||||
}
|
||||
|
||||
return message;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to upload bill: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,4 +65,19 @@ class OrderRepositoryImpl implements OrderRepository {
|
||||
throw Exception('Failed to generate QR code: $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Map<String, dynamic>> uploadBill({
|
||||
required String filePath,
|
||||
required String orderId,
|
||||
}) async {
|
||||
try {
|
||||
return await _remoteDataSource.uploadBill(
|
||||
filePath: filePath,
|
||||
orderId: orderId,
|
||||
);
|
||||
} catch (e) {
|
||||
throw Exception('Failed to upload bill: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user