import 'package:siopas/models/m_asset_status_model.dart'; import 'package:siopas/models/warehouse_mode.dart'; import '../connection/connection.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; import 'dart:async'; import '../models/asset_status_model.dart'; class AssetStatusService { Future> getAssetStatus() async { // var url = Uri.parse('$baseUrl/products'); var url = Uri.parse(await getBaseUrl() + "/asset-status"); var headers = {'Content-Type': 'application/json'}; var response = await http.get(url, headers: headers); print(response.body); print("SUCCESS GET DATA Asset Status"); if (response.statusCode == 200) { List data = jsonDecode(response.body)['data']['asset_status']; List assetStatus = []; if (data != null) { for (var item in data) { assetStatus.add(AssetStatusModel.fromJson(item)); } } return assetStatus; } else { throw Exception('Gagal Get Asset Status SERVICE!'); } } Future storePeminjaman({ // int? asset_id, DateTime? exit_at, String? exit_pic, // int? exit_warehouse, String? token, }) async { var url = Uri.parse(await getBaseUrl() + 'asset-status/store'); var headers = { 'Content-Type': 'application/json', 'Authorization': token!, }; var body = jsonEncode({ // 'asset_id': asset_id, 'exit_at': exit_at, 'exit_pic': exit_pic, // 'exit_warehouse': exit_warehouse, }); var response = await http.post( url, headers: headers, body: body, ); print('Response from server: ${response.statusCode}'); print('Body: ${response.body}'); if (response.statusCode == 200) { var data = jsonDecode(response.body)['data']['peminjam']; AssetStatusModel assetPeminjaman = AssetStatusModel.fromJson(data); print("SUCCESS STORE DATA Peminjaman SERVICE"); return assetPeminjaman; } else { throw Exception('Failed to store data peminjaman service'); } } }