After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 58 KiB |
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
<background android:drawable="@color/ic_launcher_background"/> |
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/> |
||||
</adaptive-icon> |
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 4.7 KiB |
Before Width: | Height: | Size: 442 B After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<resources> |
||||
<color name="ic_launcher_background">#ffffff</color> |
||||
</resources> |
After Width: | Height: | Size: 83 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 212 KiB |
Before Width: | Height: | Size: 295 B After Width: | Height: | Size: 869 B |
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 450 B After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 462 B After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 704 B After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 586 B After Width: | Height: | Size: 5.4 KiB |
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 9.1 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 762 B After Width: | Height: | Size: 5.1 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 14 KiB |
@ -1,4 +1,25 @@
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter/cupertino.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
|
||||
String baseUrl = 'http://192.168.0.20:8000/api/v1'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
|
||||
Future<String> getBaseUrl() async { |
||||
try { |
||||
SharedPreferences prefs = await SharedPreferences.getInstance(); |
||||
String ipAddress = |
||||
prefs.getString('ipAddress') ?? '192.168.0.18'; // Default value |
||||
String port = prefs.getString('port') ?? '8000'; // Default value |
||||
|
||||
String baseUrl = 'http://$ipAddress:$port/api/v1'; |
||||
|
||||
return baseUrl; |
||||
} catch (e) { |
||||
// Penanganan kesalahan |
||||
print('Error reading SharedPreferences: $e'); |
||||
return ''; // Atau nilai default lainnya jika terjadi kesalahan |
||||
} |
||||
} |
||||
|
||||
// return 'http://$ipAddress:$port/api/v1'; |
||||
// String baseUrl = 'http://192.168.0.18:8000/api/v1'; |
||||
// Gunakan fungsi ini saat diperlukan, misalnya di tempat-tempat yang membutuhkan baseUrl |
||||
// Contoh penggunaan: String url = await getBaseUrl(); |
||||
|
@ -0,0 +1,265 @@
|
||||
import 'dart:io'; |
||||
|
||||
import 'package:path_provider/path_provider.dart'; |
||||
import 'package:sqflite/sqflite.dart'; |
||||
import 'package:path/path.dart'; |
||||
|
||||
import '../models/warehouse_mode.dart'; |
||||
|
||||
class SqfliteDatabaseHelper { |
||||
SqfliteDatabaseHelper.internal(); |
||||
static final SqfliteDatabaseHelper instance = |
||||
SqfliteDatabaseHelper.internal(); |
||||
factory SqfliteDatabaseHelper() => instance; |
||||
|
||||
static final warehouseTable = 'm_warehouses'; |
||||
static final typePetiTable = 'type_petis'; |
||||
static final conditionPetiTable = 'kondisi_petis'; |
||||
static final customerTable = 'customers'; |
||||
static final petiTable = 'petis'; |
||||
static final transferPetiTable = 'transfers'; |
||||
static final disposalTable = 'disposals'; |
||||
|
||||
static final asset_statusesTable = 'asset_statuses'; |
||||
// static final assetLocalTable = 'asset_statuses_local'; |
||||
|
||||
static final peminjamanTable = 'peminjamans'; |
||||
static final pengembalianTable = 'pengembalians'; |
||||
|
||||
static final _version = 1; // Versi database ditingkatkan |
||||
|
||||
Database? _db; |
||||
|
||||
Future<Database?> get db async { |
||||
if (_db != null) { |
||||
return _db; |
||||
} |
||||
_db = await initDb(); |
||||
return _db; |
||||
} |
||||
|
||||
Future<void> saveWarehouseList(List<WarehouseModel> warehouseList) async { |
||||
final dbClient = await db; |
||||
try { |
||||
await dbClient!.transaction((txn) async { |
||||
var batch = txn.batch(); |
||||
for (var warehouse in warehouseList) { |
||||
batch.insert( |
||||
warehouseTable, |
||||
warehouse.toJson(), |
||||
conflictAlgorithm: ConflictAlgorithm.replace, |
||||
); |
||||
} |
||||
await batch.commit(); |
||||
}); |
||||
} catch (e) { |
||||
print('Error saving warehouse list to SQLite: $e'); |
||||
} |
||||
} |
||||
|
||||
Future<Database> initDb() async { |
||||
final Directory directory = await getApplicationDocumentsDirectory(); |
||||
String dbPath = join(directory.path, 'siopas.db'); |
||||
print(dbPath); |
||||
var openDb = await openDatabase(dbPath, version: _version, |
||||
onCreate: (Database db, int version) async { |
||||
await db.execute(""" |
||||
CREATE TABLE $peminjamanTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
mobile_id INTEGER NULL, |
||||
peti_id INTEGER NULL, |
||||
customer_id INTEGER NULL, |
||||
warehouse_id INTEGER NULL, |
||||
exit_at DATETIME NULL, |
||||
est_pengembalian DATETIME NULL, |
||||
exit_pic TEXT NULL, |
||||
exit_warehouse INTEGER NULL, |
||||
enter_at DATETIME NULL, |
||||
enter_pic TEXT NULL, |
||||
enter_warehouse INTEGER NULL, |
||||
kondisi_peti_id INTEGER NULL, |
||||
status INTEGER NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $pengembalianTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
mobile_id INTEGER NULL, |
||||
peti_id INTEGER NULL, |
||||
customer_id INTEGER NULL, |
||||
warehouse_id INTEGER NULL, |
||||
exit_at DATETIME NULL, |
||||
est_pengembalian DATETIME NULL, |
||||
exit_pic TEXT NULL, |
||||
exit_warehouse INTEGER NULL, |
||||
enter_at DATETIME NULL, |
||||
enter_pic TEXT NULL, |
||||
enter_warehouse INTEGER NULL, |
||||
kondisi_peti_id INTEGER NULL, |
||||
status INTEGER NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $asset_statusesTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
mobile_id INTEGER NOT NULL, |
||||
peti_id INTEGER NULL, |
||||
customer_id INTEGER NULL, |
||||
warehouse_id INTEGER NULL, |
||||
exit_at DATETIME NULL, |
||||
est_pengembalian DATETIME NULL, |
||||
exit_pic TEXT NULL, |
||||
exit_warehouse INTEGER NULL, |
||||
enter_at DATETIME NULL, |
||||
enter_pic TEXT NULL, |
||||
enter_warehouse INTEGER NULL, |
||||
kondisi_peti_id INTEGER NULL, |
||||
status INTEGER NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $warehouseTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
mobile_id TEXT NULL, |
||||
name TEXT NULL, |
||||
description TEXT NULL, |
||||
address TEXT NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $typePetiTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
type TEXT NULL, |
||||
size_peti TEXT NULL, |
||||
description TEXT NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $conditionPetiTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
nama_kondisi TEXT NULL, |
||||
deskripsi_kondisi TEXT NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $customerTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
name TEXT NULL, |
||||
code_customer TEXT NULL, |
||||
lot_no TEXT NULL, |
||||
no_tlp TEXT NULL, |
||||
address TEXT NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $petiTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
tipe_peti_id INTEGER NULL, |
||||
warna TEXT NULL, |
||||
fix_lot TEXT NULL, |
||||
packing_no INTEGER NULL, |
||||
customer_id INTEGER NULL, |
||||
jumlah INTEGER NULL, |
||||
date_pembuatan DATETIME NULL, |
||||
warehouse_id INTEGER NULL, |
||||
kondisipeti_id INTEGER NULL, |
||||
status TEXT NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL, |
||||
FOREIGN KEY (tipe_peti_id) REFERENCES $typePetiTable(id), |
||||
FOREIGN KEY (customer_id) REFERENCES $customerTable(id), |
||||
FOREIGN KEY (warehouse_id) REFERENCES $warehouseTable(id) |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $transferPetiTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
mobile_id TEXT NULL, |
||||
peti_id INTEGER NULL, |
||||
name_customer INTEGER NULL, |
||||
source_warehouse INTEGER NULL, |
||||
destination_warehouse INTEGER NULL, |
||||
date DATETIME NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
await db.execute(""" |
||||
CREATE TABLE $disposalTable ( |
||||
id INTEGER PRIMARY KEY AUTOINCREMENT, |
||||
mobile_id TEXT NULL, |
||||
peti_id INTEGER NULL, |
||||
customer_id INTEGER NULL, |
||||
warehouse_id INTEGER NULL, |
||||
date_disposal DATETIME NULL, |
||||
description LONGTEXT NULL, |
||||
status_disposal TEXT NULL, |
||||
created_at TIMESTAMP NULL, |
||||
updated_at TIMESTAMP NULL, |
||||
deleted_at TIMESTAMP NULL, |
||||
created_by TEXT NULL, |
||||
updated_by TEXT NULL |
||||
); |
||||
"""); |
||||
|
||||
// Tambahkan CREATE TABLE untuk tabel-tabel lainnya di sini |
||||
}, onUpgrade: (Database db, int oldversion, int newversion) async { |
||||
if (oldversion < newversion) { |
||||
print("Version Upgrade"); |
||||
// Tambahkan pernyataan ALTER TABLE jika diperlukan |
||||
} |
||||
}); |
||||
print('db initialize'); |
||||
return openDb; |
||||
} |
||||
} |
@ -0,0 +1,56 @@
|
||||
class ConditionPetiModel { |
||||
int? id; |
||||
String? nama_kondisi; |
||||
String? deskripsi_kondisi; |
||||
DateTime? created_at; |
||||
DateTime? updated_at; |
||||
DateTime? deleted_at; |
||||
String? created_by; |
||||
String? updated_by; |
||||
|
||||
ConditionPetiModel({ |
||||
this.id, |
||||
this.nama_kondisi, |
||||
this.deskripsi_kondisi, |
||||
this.created_at, |
||||
this.updated_at, |
||||
this.deleted_at, |
||||
this.created_by, |
||||
this.updated_by, |
||||
}); |
||||
|
||||
factory ConditionPetiModel.fromJson(Map<String, dynamic> json) { |
||||
return ConditionPetiModel( |
||||
id: json['id'], |
||||
nama_kondisi: json['nama_kondisi'], |
||||
deskripsi_kondisi: json['deskripsi_kondisi'], |
||||
created_at: parseDateTime(json['created_at']), |
||||
updated_at: parseDateTime(json['updated_at']), |
||||
deleted_at: parseDateTime(json['deleted_at']), |
||||
created_by: json['created_by'].toString(), |
||||
updated_by: json['updated_by'].toString(), |
||||
); |
||||
} |
||||
|
||||
Map<String, dynamic> toJson() => { |
||||
'id': id, |
||||
'nama_kondisi': nama_kondisi, |
||||
'deskripsi_kondisi': deskripsi_kondisi, |
||||
'created_by': created_by.toString(), |
||||
'updated_by': updated_by.toString(), |
||||
'created_at': created_at?.toIso8601String(), |
||||
'updated_at': updated_at?.toIso8601String(), |
||||
'deleted_at': deleted_at?.toIso8601String(), |
||||
}; |
||||
|
||||
static DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString != null && dateTimeString.isNotEmpty) { |
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,84 @@
|
||||
class DisposalPetiModel { |
||||
int? id; |
||||
String? mobile_id; |
||||
int? peti_id; |
||||
int? customer_id; |
||||
int? warehouse_id; |
||||
DateTime? date_disposal; |
||||
String? description; |
||||
String? status_disposal; |
||||
DateTime? created_at; |
||||
DateTime? updated_at; |
||||
DateTime? deleted_at; |
||||
String? created_by; |
||||
String? updated_by; |
||||
|
||||
DisposalPetiModel({ |
||||
this.id, |
||||
this.mobile_id, |
||||
this.peti_id, |
||||
this.customer_id, |
||||
this.warehouse_id, |
||||
this.date_disposal, |
||||
this.description, |
||||
this.status_disposal, |
||||
this.created_at, |
||||
this.updated_at, |
||||
this.deleted_at, |
||||
this.created_by, |
||||
this.updated_by, |
||||
}); |
||||
|
||||
factory DisposalPetiModel.fromJson(Map<String, dynamic> json) => |
||||
DisposalPetiModel( |
||||
id: json['id'], |
||||
mobile_id: |
||||
json['mobile_id'] != null ? json['mobile_id'].toString() : null, |
||||
peti_id: json['peti_id'] != null |
||||
? int.parse(json['peti_id'].toString()) |
||||
: null, |
||||
customer_id: json['customer_id'] != null |
||||
? int.parse(json['customer_id'].toString()) |
||||
: null, |
||||
warehouse_id: json['warehouse_id'] != null |
||||
? int.parse(json['warehouse_id'].toString()) |
||||
: null, |
||||
date_disposal: json['date_disposal'] != null |
||||
? DateTime.parse(json['date_disposal']) |
||||
: null, |
||||
description: |
||||
json['description'] != null ? json['description'].toString() : null, |
||||
status_disposal: json['status_disposal'] != null |
||||
? json['status_disposal'].toString() |
||||
: null, |
||||
created_at: json['created_at'] != null |
||||
? DateTime.parse(json['created_at']) |
||||
: null, |
||||
updated_at: json['updated_at'] != null |
||||
? DateTime.parse(json['updated_at']) |
||||
: null, |
||||
deleted_at: json['deleted_at'] != null |
||||
? DateTime.parse(json['deleted_at']) |
||||
: null, |
||||
created_by: |
||||
json['created_by'] != null ? json['created_by'].toString() : null, |
||||
updated_by: |
||||
json['updated_by'] != null ? json['updated_by'].toString() : null, |
||||
); |
||||
|
||||
Map<String, dynamic> toJson() => { |
||||
"id": id, |
||||
"mobile_id": mobile_id, |
||||
"peti_id": peti_id, |
||||
"customer_id": customer_id, |
||||
"warehouse_id": warehouse_id, |
||||
"date_disposal": date_disposal, |
||||
"description": description, |
||||
"status_disposal": status_disposal, |
||||
"created_at": created_at, |
||||
"updated_at": updated_at, |
||||
"deleted_at": deleted_at, |
||||
"created_by": created_by, |
||||
"updated_by": updated_by, |
||||
}; |
||||
} |
@ -0,0 +1,84 @@
|
||||
class TransferPetiModel { |
||||
int? id; |
||||
String? mobile_id; |
||||
int? peti_id; |
||||
int? name_customer; |
||||
int? source_warehouse; |
||||
int? destination_warehouse; |
||||
DateTime? date; |
||||
|
||||
String? created_by; |
||||
String? updated_by; |
||||
|
||||
DateTime? created_at; |
||||
DateTime? updated_at; |
||||
DateTime? deleted_at; |
||||
|
||||
TransferPetiModel({ |
||||
this.id, |
||||
this.mobile_id, |
||||
this.peti_id, |
||||
this.name_customer, |
||||
this.source_warehouse, |
||||
this.destination_warehouse, |
||||
this.date, |
||||
this.created_by, |
||||
this.updated_by, |
||||
this.created_at, |
||||
this.updated_at, |
||||
this.deleted_at, |
||||
}); |
||||
|
||||
factory TransferPetiModel.fromJson(Map<String, dynamic> json) { |
||||
return TransferPetiModel( |
||||
id: json['id'], |
||||
mobile_id: json['mobile_id'] != null ? json['mobile_id'] : null, |
||||
peti_id: json['peti_id'] != null |
||||
? int.parse(json['peti_id'].toString()) |
||||
: null, |
||||
name_customer: json['name_customer'] != null |
||||
? int.parse(json['name_customer'].toString()) |
||||
: null, |
||||
source_warehouse: json['source_warehouse'] != null |
||||
? int.parse(json['source_warehouse'].toString()) |
||||
: null, |
||||
destination_warehouse: json['destination_warehouse'] != null |
||||
? int.parse(json['destination_warehouse'].toString()) |
||||
: null, |
||||
date: parseDateTime(json['date']), |
||||
created_by: json['created_by'] != null ? json['created_by'] : null, |
||||
updated_by: json['updated_by'] != null ? json['updated_by'] : null, |
||||
created_at: parseDateTime(json['created_at']), |
||||
updated_at: parseDateTime(json['updated_at']), |
||||
deleted_at: parseDateTime(json['deleted_at']), |
||||
); |
||||
} |
||||
|
||||
Map<String, dynamic> toJson() { |
||||
return { |
||||
'id': id, |
||||
'mobile_id': mobile_id, |
||||
'peti_id': peti_id, |
||||
'name_customer': name_customer, |
||||
'source_warehouse': source_warehouse, |
||||
'destination_warehouse': destination_warehouse, |
||||
'date': date?.toIso8601String(), |
||||
'created_by': created_by, |
||||
'updated_by': updated_by, |
||||
'created_at': created_at?.toIso8601String(), |
||||
'updated_at': updated_at?.toIso8601String(), |
||||
'deleted_at': deleted_at?.toIso8601String(), |
||||
}; |
||||
} |
||||
|
||||
static DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString != null && dateTimeString.isNotEmpty) { |
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,259 @@
|
||||
import 'dart:convert'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:siopas/models/transfer_peti_model.dart'; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import '../../../connection/connection.dart'; |
||||
import '../../../migrations/databasehelper.dart'; |
||||
import '../../../models/asset_status_model.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
class SyncronizationGlobalData { |
||||
Future<int> addData(AssetStatusModel assetStatusModel) async { |
||||
final dbClient = await conn.db; |
||||
late int result; |
||||
try { |
||||
result = await dbClient!.insert( |
||||
SqfliteDatabaseHelper.peminjamanTable, assetStatusModel.toJson()); |
||||
} catch (e) { |
||||
print('Error adding data to local SQLite: $e'); |
||||
result = 0; // Handle the error appropriately |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<List> fetchData() async { |
||||
var dbclient = await conn.db; |
||||
List assetStatusList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.peminjamanTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
assetStatusList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return assetStatusList; |
||||
} |
||||
|
||||
static Future<bool> isInternet() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data or WIFI detected, not internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
Future<List<AssetStatusModel>> fetchAllPeminjamanInfo() async { |
||||
final dbClient = await conn.db; |
||||
List<AssetStatusModel> peminjamanList = []; |
||||
try { |
||||
final maps = await dbClient!.query(SqfliteDatabaseHelper.peminjamanTable); |
||||
for (var item in maps) { |
||||
peminjamanList.add(AssetStatusModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return peminjamanList; |
||||
} |
||||
|
||||
Future<List<AssetStatusModel>> fetchAllPengembalianInfo() async { |
||||
final dbClient = await conn.db; |
||||
List<AssetStatusModel> pengembalianList = []; |
||||
try { |
||||
final maps = |
||||
await dbClient!.query(SqfliteDatabaseHelper.pengembalianTable); |
||||
for (var item in maps) { |
||||
pengembalianList.add(AssetStatusModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return pengembalianList; |
||||
} |
||||
|
||||
Future<List<TransferPetiModel>> fetchAllTransferInfo() async { |
||||
final dbClient = await conn.db; |
||||
List<TransferPetiModel> transferList = []; |
||||
try { |
||||
final maps = |
||||
await dbClient!.query(SqfliteDatabaseHelper.transferPetiTable); |
||||
for (var item in maps) { |
||||
transferList.add(TransferPetiModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return transferList; |
||||
} |
||||
|
||||
Future<void> deleteAllPeminjamanData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.peminjamanTable); |
||||
} |
||||
|
||||
Future<void> deleteAllPengembalianData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.pengembalianTable); |
||||
} |
||||
|
||||
Future<void> deleteAllTransferData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.transferPetiTable); |
||||
} |
||||
|
||||
Future saveToMysqlWith(List<AssetStatusModel> assetStatusesLocalList) async { |
||||
for (var i = 0; i < assetStatusesLocalList.length; i++) { |
||||
DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString == null || dateTimeString.isEmpty) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
// Format tanggal sesuai kebutuhan |
||||
String formattedCreatedAt = assetStatusesLocalList[i].created_at != null |
||||
? DateFormat('yyyy-MM-dd HH:mm:ss.SSS') |
||||
.format(assetStatusesLocalList[i].created_at!) |
||||
: DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(DateTime.now()); |
||||
|
||||
Map<String, dynamic> data = { |
||||
"mobile_id": assetStatusesLocalList[i].mobile_id.toString(), |
||||
"peti_id": assetStatusesLocalList[i].peti_id.toString(), |
||||
"exit_at": assetStatusesLocalList[i].exit_at.toString(), |
||||
"est_pengembalian": |
||||
assetStatusesLocalList[i].est_pengembalian.toString(), |
||||
"exit_pic": assetStatusesLocalList[i].exit_pic.toString(), |
||||
"exit_warehouse": assetStatusesLocalList[i].exit_warehouse.toString(), |
||||
// "status": assetStatusesLocalList[i].status.toString(), |
||||
"created_by": assetStatusesLocalList[i].created_by.toString(), |
||||
"created_at": formattedCreatedAt, |
||||
}; |
||||
|
||||
final response = await http.post( |
||||
Uri.parse(await getBaseUrl() + '/asset-status/store'), |
||||
body: data, |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
// print("Data uploaded successfully for index $i:"); |
||||
// print("Response body: ${response.body}"); |
||||
print("Saving Data saveToMysqlWith"); |
||||
} else { |
||||
print( |
||||
"Failed to upload data for index $i. Status code: ${response.statusCode}"); |
||||
print("Response body: ${response.body}"); |
||||
} |
||||
} |
||||
|
||||
return true; // Pengunggahan berhasil |
||||
} |
||||
|
||||
Future<List> fetchAllCustomerInfo() async { |
||||
final dbClient = await conn.db; |
||||
List contactList = []; |
||||
try { |
||||
final maps = await dbClient!.query(SqfliteDatabaseHelper.peminjamanTable); |
||||
for (var item in maps) { |
||||
contactList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return contactList; |
||||
} |
||||
|
||||
Future saveToMysql(List assetStatusesLocalList) async { |
||||
DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString == null || dateTimeString.isEmpty) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
for (var i = 0; i < assetStatusesLocalList.length; i++) { |
||||
// Format tanggal sesuai kebutuhan |
||||
String formattedCreatedAt = |
||||
assetStatusesLocalList[i]['created_at'] != null |
||||
? DateFormat('yyyy-MM-dd HH:mm:ss.SSS') |
||||
.format(assetStatusesLocalList[i]['created_at']) |
||||
: DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(DateTime.now()); |
||||
|
||||
Map<String, dynamic> data = { |
||||
"mobile_id": assetStatusesLocalList[i]['mobile_id'].toString(), |
||||
"peti_id": assetStatusesLocalList[i]['peti_id'].toString(), |
||||
"exit_at": assetStatusesLocalList[i]['exit_at'].toString(), |
||||
"est_pengembalian": |
||||
assetStatusesLocalList[i]['est_pengembalian'].toString(), |
||||
"exit_pic": assetStatusesLocalList[i]['exit_pic'].toString(), |
||||
"exit_warehouse": |
||||
assetStatusesLocalList[i]['exit_warehouse'].toString(), |
||||
"status": assetStatusesLocalList[i]['status'].toString(), |
||||
"created_by": assetStatusesLocalList[i]['created_by'].toString(), |
||||
"created_at": formattedCreatedAt, |
||||
}; |
||||
|
||||
final response = await http.post( |
||||
Uri.parse(await getBaseUrl() + '/asset-status/store'), |
||||
body: data); |
||||
if (response.statusCode == 200) { |
||||
print(response.body); |
||||
print("Saving Data saveToMysql"); |
||||
} else { |
||||
print(response.statusCode); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Future<List<AssetStatusModel>> fetchFromApi() async { |
||||
final response = await http.get( |
||||
Uri.parse(await getBaseUrl() + '/asset-status'), |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['asset_status']; |
||||
List<AssetStatusModel> contactDBList = data |
||||
.map( |
||||
(item) => AssetStatusModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return contactDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Asset Status'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
|
||||
import 'dart:async'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:sqflite/sqflite.dart'; |
||||
|
||||
import '../../../migrations/databasehelper.dart'; |
||||
|
||||
class ControllerHome { |
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
Future<int> getPeminjamanCount() async { |
||||
final dbClient = await conn.db; |
||||
final count = Sqflite.firstIntValue(await dbClient! |
||||
.query(SqfliteDatabaseHelper.peminjamanTable, columns: ['COUNT(*)'])); |
||||
return count ?? 0; |
||||
} |
||||
|
||||
Future<int> getPengembalianCount() async { |
||||
final dbClient = await conn.db; |
||||
final count = Sqflite.firstIntValue( |
||||
await dbClient!.query(SqfliteDatabaseHelper.pengembalianTable, |
||||
columns: ['COUNT(*)']), |
||||
); |
||||
return count ?? 0; |
||||
} |
||||
|
||||
Future<int> getTransferCount() async { |
||||
final dbClient = await conn.db; |
||||
final count = Sqflite.firstIntValue( |
||||
await dbClient!.query(SqfliteDatabaseHelper.transferPetiTable, |
||||
columns: ['COUNT(*)']), |
||||
); |
||||
return count ?? 0; |
||||
} |
||||
|
||||
static Future<bool> isInternet() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data nor WIFI detected, no internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,222 @@
|
||||
import 'dart:convert'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import '../../../connection/connection.dart'; |
||||
import '../../../migrations/databasehelper.dart'; |
||||
import '../../../models/asset_status_model.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
class SyncronizationPeminjamanData { |
||||
Future<int> addData(AssetStatusModel assetStatusModel) async { |
||||
final dbClient = await conn.db; |
||||
late int result; |
||||
try { |
||||
result = await dbClient!.insert( |
||||
SqfliteDatabaseHelper.peminjamanTable, assetStatusModel.toJson()); |
||||
} catch (e) { |
||||
print('Error adding data to local SQLite: $e'); |
||||
result = 0; // Handle the error appropriately |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<List> fetchData() async { |
||||
var dbclient = await conn.db; |
||||
List assetStatusList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.peminjamanTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
assetStatusList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return assetStatusList; |
||||
} |
||||
|
||||
static Future<bool> isInternet() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data or WIFI detected, not internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
Future<List<AssetStatusModel>> fetchAllInfo() async { |
||||
final dbClient = await conn.db; |
||||
List<AssetStatusModel> assetStatusList = []; |
||||
try { |
||||
final maps = await dbClient!.query(SqfliteDatabaseHelper.peminjamanTable); |
||||
for (var item in maps) { |
||||
assetStatusList.add(AssetStatusModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return assetStatusList; |
||||
} |
||||
|
||||
Future<void> deleteAllAssetStatusData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.peminjamanTable); |
||||
} |
||||
|
||||
Future saveToPeminjamanWith( |
||||
List<AssetStatusModel> assetStatusesLocalList) async { |
||||
for (var i = 0; i < assetStatusesLocalList.length; i++) { |
||||
DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString == null || dateTimeString.isEmpty) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
// Format tanggal sesuai kebutuhan |
||||
String formattedCreatedAt = assetStatusesLocalList[i].created_at != null |
||||
? DateFormat('yyyy-MM-dd HH:mm:ss.SSS') |
||||
.format(assetStatusesLocalList[i].created_at!) |
||||
: DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(DateTime.now()); |
||||
|
||||
Map<String, dynamic> data = { |
||||
"mobile_id": assetStatusesLocalList[i].mobile_id.toString(), |
||||
"peti_id": assetStatusesLocalList[i].peti_id.toString(), |
||||
"customer_id": assetStatusesLocalList[i].customer_id.toString(), |
||||
"warehouse_id": assetStatusesLocalList[i].warehouse_id.toString(), |
||||
"exit_at": assetStatusesLocalList[i].exit_at.toString(), |
||||
"est_pengembalian": |
||||
assetStatusesLocalList[i].est_pengembalian.toString(), |
||||
"exit_pic": assetStatusesLocalList[i].exit_pic.toString(), |
||||
"exit_warehouse": assetStatusesLocalList[i].exit_warehouse.toString(), |
||||
"created_by": assetStatusesLocalList[i].created_by.toString(), |
||||
"created_at": formattedCreatedAt, |
||||
}; |
||||
|
||||
final response = await http.post( |
||||
Uri.parse(await getBaseUrl() + '/asset-status/store'), |
||||
body: data, |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
// print("Data uploaded successfully for index $i:"); |
||||
// print("Response body: ${response.body}"); |
||||
print("Saving Data saveToMysqlWith"); |
||||
} else { |
||||
print( |
||||
"Failed to upload data for index $i. Status code: ${response.statusCode}"); |
||||
print("Response body: ${response.body}"); |
||||
} |
||||
} |
||||
|
||||
return true; // Pengunggahan berhasil |
||||
} |
||||
|
||||
Future<List> fetchAllCustomerInfo() async { |
||||
final dbClient = await conn.db; |
||||
List contactList = []; |
||||
try { |
||||
final maps = await dbClient!.query(SqfliteDatabaseHelper.peminjamanTable); |
||||
for (var item in maps) { |
||||
contactList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return contactList; |
||||
} |
||||
|
||||
Future saveToMysql(List assetStatusesLocalList) async { |
||||
DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString == null || dateTimeString.isEmpty) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
for (var i = 0; i < assetStatusesLocalList.length; i++) { |
||||
// Format tanggal sesuai kebutuhan |
||||
String formattedCreatedAt = |
||||
assetStatusesLocalList[i]['created_at'] != null |
||||
? DateFormat('yyyy-MM-dd HH:mm:ss.SSS') |
||||
.format(assetStatusesLocalList[i]['created_at']) |
||||
: DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(DateTime.now()); |
||||
|
||||
Map<String, dynamic> data = { |
||||
"mobile_id": assetStatusesLocalList[i]['mobile_id'].toString(), |
||||
"peti_id": assetStatusesLocalList[i]['peti_id'].toString(), |
||||
"customer_id": assetStatusesLocalList[i]['customer_id'].toString(), |
||||
"warehouse_id": assetStatusesLocalList[i]['warehouse_id'].toString(), |
||||
"exit_at": assetStatusesLocalList[i]['exit_at'].toString(), |
||||
"est_pengembalian": |
||||
assetStatusesLocalList[i]['est_pengembalian'].toString(), |
||||
"exit_pic": assetStatusesLocalList[i]['exit_pic'].toString(), |
||||
"exit_warehouse": |
||||
assetStatusesLocalList[i]['exit_warehouse'].toString(), |
||||
"status": assetStatusesLocalList[i]['status'].toString(), |
||||
"created_by": assetStatusesLocalList[i]['created_by'].toString(), |
||||
"created_at": formattedCreatedAt, |
||||
}; |
||||
|
||||
final response = await http.post( |
||||
Uri.parse(await getBaseUrl() + '/asset-status/store'), |
||||
body: data); |
||||
if (response.statusCode == 200) { |
||||
print(response.body); |
||||
print("Saving Data saveToMysql"); |
||||
} else { |
||||
print(response.statusCode); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Future<List<AssetStatusModel>> fetchFromApi() async { |
||||
final response = await http.get( |
||||
Uri.parse(await getBaseUrl() + '/asset-status'), |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['asset_status']; |
||||
List<AssetStatusModel> contactDBList = data |
||||
.map( |
||||
(item) => AssetStatusModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return contactDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Asset Status'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,204 @@
|
||||
import 'dart:async'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:sqflite/sqflite.dart'; |
||||
|
||||
import '../../../migrations/databasehelper.dart'; |
||||
|
||||
class Controller { |
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
Future<List<AssetStatusModel>> fetchAllPeminjamanInfo() async { |
||||
final dbClient = await conn.db; |
||||
List<AssetStatusModel> assetStatusList = []; |
||||
try { |
||||
final maps = await dbClient!.query(SqfliteDatabaseHelper.peminjamanTable); |
||||
for (var item in maps) { |
||||
assetStatusList.add(AssetStatusModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return assetStatusList; |
||||
} |
||||
|
||||
static Future<bool> isInternet() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data or WIFI detected, not internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
Future<int> addPeminjamanData(AssetStatusModel peminjamanAddModel) async { |
||||
var dbclient = await conn.db; |
||||
int result = 0; // Provide an initial value |
||||
try { |
||||
result = await dbclient!.insert( |
||||
SqfliteDatabaseHelper.peminjamanTable, peminjamanAddModel.toJson()); |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<int> updatePeminjamanData(AssetStatusModel peminjamanAddModel) async { |
||||
var dbclient = await conn.db; |
||||
late int result; |
||||
try { |
||||
result = await dbclient!.update( |
||||
SqfliteDatabaseHelper.peminjamanTable, |
||||
peminjamanAddModel.toJson(), |
||||
where: 'id=?', |
||||
whereArgs: [peminjamanAddModel.id], |
||||
); |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<List> fetchAssetStatusLocalController() async { |
||||
var dbclient = await conn.db; |
||||
List peminjamanStatusList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.peminjamanTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
peminjamanStatusList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return peminjamanStatusList; |
||||
} |
||||
|
||||
Future<List<AssetStatusModel>> fetchPeminjamanDataId() async { |
||||
var dbclient = await conn.db; |
||||
List<AssetStatusModel> peminjamanList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.peminjamanTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
peminjamanList.add(AssetStatusModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return peminjamanList; |
||||
} |
||||
|
||||
Future<void> deleteAllData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.peminjamanTable); |
||||
} |
||||
|
||||
Future<void> addAllData(List<AssetStatusModel> contactList) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var contact in contactList) { |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.peminjamanTable, |
||||
contact.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
|
||||
Future<List> fetchPetiData() async { |
||||
var dbclient = await conn.db; |
||||
List petiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.petiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
petiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return petiList; |
||||
} |
||||
|
||||
Future<List> fetchTipePetiData() async { |
||||
var dbclient = await conn.db; |
||||
List tipePetiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.typePetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
tipePetiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return tipePetiList; |
||||
} |
||||
|
||||
Future<List> fetchCustomerData() async { |
||||
var dbclient = await conn.db; |
||||
List customerList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.customerTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
customerList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return customerList; |
||||
} |
||||
|
||||
Future<List> fetchWarehouseData() async { |
||||
var dbclient = await conn.db; |
||||
List warehouseList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.warehouseTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
warehouseList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return warehouseList; |
||||
} |
||||
|
||||
Future<List> fetchDisposalData() async { |
||||
var dbclient = await conn.db; |
||||
List disposalList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.disposalTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
disposalList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return disposalList; |
||||
} |
||||
} |
@ -0,0 +1,218 @@
|
||||
import 'dart:convert'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import '../../../connection/connection.dart'; |
||||
import '../../../migrations/databasehelper.dart'; |
||||
import '../../../models/asset_status_model.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
class SyncronizationPengembalianData { |
||||
Future<int> addData(AssetStatusModel assetStatusModel) async { |
||||
final dbClient = await conn.db; |
||||
late int result; |
||||
try { |
||||
result = await dbClient!.insert( |
||||
SqfliteDatabaseHelper.pengembalianTable, assetStatusModel.toJson()); |
||||
} catch (e) { |
||||
print('Error adding data to local SQLite: $e'); |
||||
result = 0; // Handle the error appropriately |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<List> fetchData() async { |
||||
var dbclient = await conn.db; |
||||
List assetStatusList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.pengembalianTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
assetStatusList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return assetStatusList; |
||||
} |
||||
|
||||
static Future<bool> isInternet() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data or WIFI detected, not internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
Future<List<AssetStatusModel>> fetchAllInfo() async { |
||||
final dbClient = await conn.db; |
||||
List<AssetStatusModel> assetStatusList = []; |
||||
try { |
||||
final maps = |
||||
await dbClient!.query(SqfliteDatabaseHelper.pengembalianTable); |
||||
for (var item in maps) { |
||||
assetStatusList.add(AssetStatusModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return assetStatusList; |
||||
} |
||||
|
||||
Future<void> deleteAllAssetStatusData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.pengembalianTable); |
||||
} |
||||
|
||||
Future savePengembalianToServerWith( |
||||
List<AssetStatusModel> assetStatusesLocalList) async { |
||||
for (var i = 0; i < assetStatusesLocalList.length; i++) { |
||||
DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString == null || dateTimeString.isEmpty) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
// Format tanggal sesuai kebutuhan |
||||
String formattedCreatedAt = assetStatusesLocalList[i].created_at != null |
||||
? DateFormat('yyyy-MM-dd HH:mm:ss.SSS') |
||||
.format(assetStatusesLocalList[i].created_at!) |
||||
: DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(DateTime.now()); |
||||
|
||||
Map<String, dynamic> data = { |
||||
"peti_id": assetStatusesLocalList[i].peti_id.toString(), |
||||
"enter_at": assetStatusesLocalList[i].enter_at.toString(), |
||||
"enter_pic": assetStatusesLocalList[i].enter_pic.toString(), |
||||
"enter_warehouse": assetStatusesLocalList[i].enter_warehouse.toString(), |
||||
"kondisi_peti_id": assetStatusesLocalList[i].kondisi_peti_id.toString(), |
||||
"updated_by": assetStatusesLocalList[i].updated_by.toString(), |
||||
"updated_at": formattedCreatedAt, |
||||
}; |
||||
|
||||
final response = await http.post( |
||||
Uri.parse(await getBaseUrl() + '/asset-status/update'), |
||||
body: data, |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
// print("Data uploaded successfully for index $i:"); |
||||
// print("Response body: ${response.body}"); |
||||
print("Saving Data saveToPengembalianWith"); |
||||
} else { |
||||
print( |
||||
"Failed to upload data for index $i. Status code: ${response.statusCode}"); |
||||
print("Response body: ${response.body}"); |
||||
} |
||||
} |
||||
|
||||
return true; // Pengunggahan berhasil |
||||
} |
||||
|
||||
Future<List> fetchAllCustomerInfo() async { |
||||
final dbClient = await conn.db; |
||||
List contactList = []; |
||||
try { |
||||
final maps = |
||||
await dbClient!.query(SqfliteDatabaseHelper.pengembalianTable); |
||||
for (var item in maps) { |
||||
contactList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return contactList; |
||||
} |
||||
|
||||
Future saveToMysql(List assetStatusesLocalList) async { |
||||
DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString == null || dateTimeString.isEmpty) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
for (var i = 0; i < assetStatusesLocalList.length; i++) { |
||||
// Format tanggal sesuai kebutuhan |
||||
String formattedCreatedAt = |
||||
assetStatusesLocalList[i]['created_at'] != null |
||||
? DateFormat('yyyy-MM-dd HH:mm:ss.SSS') |
||||
.format(assetStatusesLocalList[i]['created_at']) |
||||
: DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(DateTime.now()); |
||||
|
||||
Map<String, dynamic> data = { |
||||
"peti_id": assetStatusesLocalList[i]['peti_id'].toString(), |
||||
"enter_at": assetStatusesLocalList[i]['enter_at'].toString(), |
||||
"enter_pic": assetStatusesLocalList[i]['enter_pic'].toString(), |
||||
"enter_warehouse": |
||||
assetStatusesLocalList[i]['enter_warehouse'].toString(), |
||||
"kondisi_peti_id": |
||||
assetStatusesLocalList[i]['kondisi_peti_id'].toString(), |
||||
"updated_by": assetStatusesLocalList[i]['updated_by'].toString(), |
||||
"updated_at": formattedCreatedAt, |
||||
}; |
||||
|
||||
final response = await http.post( |
||||
Uri.parse(await getBaseUrl() + '/asset-status/update'), |
||||
body: data); |
||||
if (response.statusCode == 200) { |
||||
print(response.body); |
||||
print("Saving Data saveToMysql"); |
||||
} else { |
||||
print(response.statusCode); |
||||
print( |
||||
"Failed to upload data for index $i. Status code: ${response.statusCode}"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Future<List<AssetStatusModel>> fetchFromApi() async { |
||||
final response = await http.get( |
||||
Uri.parse(await getBaseUrl() + '/asset-status'), |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['asset_status']; |
||||
List<AssetStatusModel> contactDBList = data |
||||
.map( |
||||
(item) => AssetStatusModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return contactDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Asset Status'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,221 @@
|
||||
import 'dart:async'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:sqflite/sqflite.dart'; |
||||
|
||||
import '../../../migrations/databasehelper.dart'; |
||||
|
||||
class ControllerPengembalian { |
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
Future<List<AssetStatusModel>> fetchAllPengembalianInfo() async { |
||||
final dbClient = await conn.db; |
||||
List<AssetStatusModel> pengembalianList = []; |
||||
try { |
||||
final maps = |
||||
await dbClient!.query(SqfliteDatabaseHelper.pengembalianTable); |
||||
for (var item in maps) { |
||||
pengembalianList.add(AssetStatusModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return pengembalianList; |
||||
} |
||||
|
||||
static Future<bool> isInternet() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data or WIFI detected, not internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
Future<int> addPengembalianData(AssetStatusModel pengembalianAddModel) async { |
||||
var dbclient = await conn.db; |
||||
int result = 0; // Provide an initial value |
||||
try { |
||||
result = await dbclient!.insert(SqfliteDatabaseHelper.pengembalianTable, |
||||
pengembalianAddModel.toJson()); |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<int> updatePengembalianData( |
||||
AssetStatusModel pengembalianAddModel) async { |
||||
var dbclient = await conn.db; |
||||
late int result; |
||||
try { |
||||
result = await dbclient!.update( |
||||
SqfliteDatabaseHelper.pengembalianTable, |
||||
pengembalianAddModel.toJson(), |
||||
where: 'id=?', |
||||
whereArgs: [pengembalianAddModel.id], |
||||
); |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<List> fetchPengembalianLocalController() async { |
||||
var dbclient = await conn.db; |
||||
List pengembalianStatusList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.pengembalianTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
pengembalianStatusList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return pengembalianStatusList; |
||||
} |
||||
|
||||
Future<List<AssetStatusModel>> fetchPengembalianDataId() async { |
||||
var dbclient = await conn.db; |
||||
List<AssetStatusModel> pengembalianList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.pengembalianTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
pengembalianList.add(AssetStatusModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return pengembalianList; |
||||
} |
||||
|
||||
Future<void> deleteAllData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.pengembalianTable); |
||||
} |
||||
|
||||
Future<void> addAllData(List<AssetStatusModel> pengembalianList) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var pengembalian in pengembalianList) { |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.pengembalianTable, |
||||
pengembalian.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
|
||||
Future<List> fetchPetiData() async { |
||||
var dbclient = await conn.db; |
||||
List petiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.petiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
petiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return petiList; |
||||
} |
||||
|
||||
Future<List> fetchTipePetiData() async { |
||||
var dbclient = await conn.db; |
||||
List tipePetiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.typePetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
tipePetiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return tipePetiList; |
||||
} |
||||
|
||||
Future<List> fetchCustomerData() async { |
||||
var dbclient = await conn.db; |
||||
List customerList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.customerTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
customerList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return customerList; |
||||
} |
||||
|
||||
Future<List> fetchWarehouseData() async { |
||||
var dbclient = await conn.db; |
||||
List warehouseList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.warehouseTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
warehouseList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return warehouseList; |
||||
} |
||||
|
||||
Future<List> fetchConditionData() async { |
||||
var dbclient = await conn.db; |
||||
List conditionList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.conditionPetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
conditionList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return conditionList; |
||||
} |
||||
|
||||
Future<List> fetchDisposalData() async { |
||||
var dbclient = await conn.db; |
||||
List disposalList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.disposalTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
disposalList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return disposalList; |
||||
} |
||||
} |
@ -0,0 +1,801 @@
|
||||
import 'dart:async'; |
||||
import 'dart:convert'; |
||||
import 'dart:developer'; |
||||
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:data_table_2/data_table_2.dart'; |
||||
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
||||
import 'package:siopas/models/condition_peti_model.dart'; |
||||
import 'package:siopas/models/customer_model.dart'; |
||||
import 'package:siopas/models/disposal_model.dart'; |
||||
import 'package:siopas/models/m_asset_status_model.dart'; |
||||
import 'package:siopas/models/type_peti_model.dart'; |
||||
import 'package:siopas/models/warehouse_mode.dart'; |
||||
import 'package:siopas/pages/pengembalian_barang/conn/syncronize.dart'; |
||||
import 'package:siopas/pages/pengembalian_barang/controller/pengembalian_controller.dart'; |
||||
import 'package:siopas/pages/pengembalian_barang/show.dart'; |
||||
import 'package:siopas/services/syncronizeAPI.dart'; |
||||
import 'package:siopas/services/controllerApi.dart'; |
||||
import 'package:siopas/pages/peminjaman_barang/controller/peminjaman_controller.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:collection/collection.dart'; |
||||
|
||||
import '../peminjaman_barang/show.dart'; |
||||
// import 'show.dart'; |
||||
|
||||
class PengembalianBarangPage extends StatefulWidget { |
||||
const PengembalianBarangPage({super.key}); |
||||
|
||||
@override |
||||
State<PengembalianBarangPage> createState() => PengembalianBarangPageState(); |
||||
} |
||||
|
||||
class PengembalianBarangPageState extends State<PengembalianBarangPage> { |
||||
String? token; |
||||
bool loading = true; |
||||
|
||||
// Reinit atau Upload Only |
||||
WarehouseModel? warehouseSqfliteApi; |
||||
List<TypePetiModel>? typePetiSqfliteApi; |
||||
List<CustomerModel>? customerSqfliteApi; |
||||
PetiAssetModel? petiSqfliteApi; |
||||
ConditionPetiModel? conditionPetiSqfliteApi; |
||||
DisposalPetiModel? disposalSqfliteApi; |
||||
|
||||
List<PetiAssetModel>? _valpeti; // Change this line |
||||
List<WarehouseModel>? _valwarehouse; |
||||
List<ConditionPetiModel>? _valconditionPeti; |
||||
List<DisposalPetiModel>? _valdisposal; |
||||
|
||||
// Datatable |
||||
int _currentPage = 1; |
||||
int _pageSize = 10; |
||||
List<AssetStatusModel>? _data; |
||||
List<PetiAssetModel>? _petiData; |
||||
List<TypePetiModel>? _tipePetiData; |
||||
List<CustomerModel>? _customerData; |
||||
List<WarehouseModel>? _warehouseData; |
||||
List<ConditionPetiModel>? _conditionData; |
||||
bool _isLoading = false; |
||||
Timer? _timer; |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
_getUserToken(); |
||||
|
||||
warehouseListAPI(); |
||||
conditionPetiListAPI(); |
||||
typePetiListAPI(); |
||||
customerListAPI(); |
||||
petiListAPI(); |
||||
// disposalListAPI(); |
||||
|
||||
// Tampil data Datatables |
||||
datatablesPengembalianList(); |
||||
datatablesPetiList(); |
||||
datatablesTipePetiList(); |
||||
datatablesCustomerList(); |
||||
datatablesWarehouseList(); |
||||
datatablesConditionList(); |
||||
_data = <AssetStatusModel>[]; |
||||
} |
||||
|
||||
void _getUserToken() async { |
||||
SharedPreferences prefs = await SharedPreferences.getInstance(); |
||||
if (mounted) { |
||||
setState(() { |
||||
token = prefs.getString('token'); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
// Reinit atau Upload Only ------------------------------------------------------------------------ |
||||
Future warehouseListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchWarehouseDataAPI().then((value) { |
||||
setState(() { |
||||
_valwarehouse = (value as List<dynamic>) |
||||
.map((item) => WarehouseModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
// Future disposalListAPI() async { |
||||
// if (mounted) { |
||||
// await ControllerApi().fetchDisposalDataAPI().then((value) { |
||||
// setState(() { |
||||
// _valdisposal = (value as List<dynamic>) |
||||
// .map((item) => DisposalPetiModel.fromJson(item)) |
||||
// .toList(); |
||||
// loading = false; |
||||
// }); |
||||
// }); |
||||
// } |
||||
// } |
||||
|
||||
Future typePetiListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchTipePetiDataAPI().then((value) { |
||||
setState(() { |
||||
typePetiSqfliteApi = (value as List<dynamic>) |
||||
.map((item) => TypePetiModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
Future customerListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchCustomerDataAPI().then((value) { |
||||
setState(() { |
||||
customerSqfliteApi = (value as List<dynamic>) |
||||
.map((item) => CustomerModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
Future petiListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchPetiDataAPI().then((value) { |
||||
setState(() { |
||||
_valpeti = (value as List<dynamic>) |
||||
.map((item) => PetiAssetModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
Future conditionPetiListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchKondisiPetiDataAPI().then((value) { |
||||
setState(() { |
||||
_valconditionPeti = (value as List<dynamic>) |
||||
.map((item) => ConditionPetiModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
// Future<void> reinitAssetStatusApi() async { |
||||
// List<AssetStatusModel> assetStatusApiData = |
||||
// await SyncronizationDataAPI().fetchAssetStatusFromApi(); |
||||
// await ControllerApi() |
||||
// .deleteAllAssetStatusDataAPI(); // Clear existing data in SQLite |
||||
// await ControllerApi() |
||||
// .addAllAssetStatusDataAPI(assetStatusApiData); // Add new data to SQLite |
||||
// } |
||||
|
||||
Future<void> reinitWarehouseApi() async { |
||||
EasyLoading.show(status: 'Mengambil data Warehouse...'); |
||||
List<WarehouseModel> warehouseApiData = |
||||
await SyncronizationDataAPI().fetchWarehouseFromApi(); |
||||
await ControllerApi() |
||||
.deleteAllWarehouseDataAPI(); // Clear existing data in SQLite |
||||
await ControllerApi() |
||||
.addAllWarehouseDataAPI(warehouseApiData); // Add new data to SQLite |
||||
EasyLoading.dismiss(); |
||||
} |
||||
|
||||
Future<void> reinitPetiApi() async { |
||||
EasyLoading.show(status: 'Mengambil data Peti...'); |
||||
List<PetiAssetModel> petiApiData = |
||||
await SyncronizationDataAPI().fetchPetiFromApi(); |
||||
await ControllerApi() |
||||
.deleteAllPetiDataAPI(); // Clear existing data in SQLite |
||||
await ControllerApi() |
||||
.addAllPetiDataAPI(petiApiData); // Add new data to SQLite |
||||
EasyLoading.dismiss(); |
||||
} |
||||
|
||||
Future<void> reinitCustomerApi() async { |
||||
EasyLoading.show(status: 'Mengambil data Customer...'); |
||||
List<CustomerModel> customerApiData = |
||||
await SyncronizationDataAPI().fetchCustomerFromApi(); |
||||
await ControllerApi() |
||||
.deleteAllCustomerDataAPI(); // Clear existing data in SQLite |
||||
await ControllerApi() |
||||
.addAllCustomerDataAPI(customerApiData); // Add new data to SQLite |
||||
EasyLoading.dismiss(); |
||||
} |
||||
|
||||
Future<void> reinitConditionPetiApi() async { |
||||
EasyLoading.show(status: 'Mengambil data Condition Peti...'); |
||||
List<ConditionPetiModel> conditionPetiApiData = |
||||
await SyncronizationDataAPI().fetchKondisiPetiFromApi(); |
||||
await ControllerApi() |
||||
.deleteAllKondisiPetiDataAPI(); // Clear existing data in SQLite |
||||
await ControllerApi().addAllKondisiPetiDataAPI( |
||||
conditionPetiApiData); // Add new data to SQLite |
||||
EasyLoading.dismiss(); |
||||
} |
||||
// Future<void> reinitDisposalApi() async { |
||||
// List<DisposalPetiModel> disposalApiData = |
||||
// await SyncronizationDataAPI().fetchDisposalFromApi(); |
||||
// await ControllerApi() |
||||
// .deleteAllDisposalDataAPI(); // Clear existing data in SQLite |
||||
// await ControllerApi() |
||||
// .addAllDisposalDataAPI(disposalApiData); // Add new data to SQLite |
||||
// } |
||||
|
||||
Future<void> fetchDataFromApiAndSync() async { |
||||
EasyLoading.show(status: 'Mengambil data dari Server...'); |
||||
try { |
||||
await syncToMysql(); |
||||
|
||||
// await reinitAssetStatusApi(); |
||||
await reinitWarehouseApi(); |
||||
await reinitPetiApi(); |
||||
await reinitCustomerApi(); |
||||
// await reinitTypePetiApi(); |
||||
await reinitConditionPetiApi(); |
||||
// await reinitDisposalApi(); |
||||
|
||||
await datatablesPengembalianList(); |
||||
EasyLoading.showSuccess('Data berhasil diperbarui'); |
||||
} catch (e) { |
||||
EasyLoading.showError('Gagal memperbarui data: $e'); |
||||
} finally { |
||||
EasyLoading.dismiss(); |
||||
} |
||||
} |
||||
|
||||
Future syncToMysql() async { |
||||
await SyncronizationPengembalianData() |
||||
.fetchAllInfo() |
||||
.then((assetList) async { |
||||
EasyLoading.show( |
||||
status: 'Jangan tutup aplikasi. Kami sedang menyinkronkan...'); |
||||
await Future.delayed(Duration(seconds: 3)); |
||||
|
||||
// Tambahkan penanganan pengunggahan |
||||
bool uploadSuccess = await SyncronizationPengembalianData() |
||||
.savePengembalianToServerWith(assetList); |
||||
|
||||
// Jika pengunggahan berhasil, hapus data lokal |
||||
if (uploadSuccess) { |
||||
await SyncronizationPengembalianData().deleteAllAssetStatusData(); |
||||
// Setelah selesai, tampilkan pesan sukses |
||||
await datatablesPengembalianList(); |
||||
EasyLoading.showSuccess('Berhasil disinkronkan dengan Server'); |
||||
} else { |
||||
// Tampilkan pesan gagal jika pengunggahan tidak berhasil |
||||
EasyLoading.showError('Gagal disinkronkan dengan Server'); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
// Future syncToMysql() async { |
||||
// await SyncronizationData().fetchAllInfo().then((assetList) async { |
||||
// EasyLoading.show(status: 'Don\'t close app. We are syncing...'); |
||||
// await SyncronizationData().saveToMysqlWith(assetList); |
||||
// await SyncronizationData().deleteAllAssetStatusData(); |
||||
// // EasyLoading.showSuccess('Successfully saved to MySQL'); |
||||
// }); |
||||
// } |
||||
|
||||
Future<void> isInteret() async { |
||||
await SyncronizationPengembalianData.isInternet().then((connection) { |
||||
if (connection) { |
||||
print("Internet connection available"); |
||||
} else { |
||||
ScaffoldMessenger.of(context) |
||||
.showSnackBar(SnackBar(content: Text("No Internet"))); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
// Datatables ------------------------------------------------------------------------ |
||||
Future datatablesPengembalianList() async { |
||||
await ControllerPengembalian() |
||||
.fetchPengembalianLocalController() |
||||
.then((value) { |
||||
setState(() { |
||||
_data = (value as List<dynamic>) |
||||
.map((e) => AssetStatusModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesPetiList() async { |
||||
await ControllerPengembalian().fetchPetiData().then((value) { |
||||
setState(() { |
||||
_petiData = (value as List<dynamic>) |
||||
.map((e) => PetiAssetModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesTipePetiList() async { |
||||
await ControllerPengembalian().fetchTipePetiData().then((value) { |
||||
setState(() { |
||||
_tipePetiData = (value as List<dynamic>) |
||||
.map((e) => TypePetiModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesCustomerList() async { |
||||
await ControllerPengembalian().fetchCustomerData().then((value) { |
||||
setState(() { |
||||
_customerData = (value as List<dynamic>) |
||||
.map((e) => CustomerModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesWarehouseList() async { |
||||
await ControllerPengembalian().fetchWarehouseData().then((value) { |
||||
setState(() { |
||||
_warehouseData = (value as List<dynamic>) |
||||
.map((e) => WarehouseModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesConditionList() async { |
||||
await ControllerPengembalian().fetchConditionData().then((value) { |
||||
setState(() { |
||||
_conditionData = (value as List<dynamic>) |
||||
.map((e) => ConditionPetiModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
void _loadMoreData() { |
||||
if (mounted && !_isLoading) { |
||||
setState(() { |
||||
_currentPage++; |
||||
}); |
||||
datatablesPengembalianList(); |
||||
} |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
// Add this function outside the build method |
||||
void showSyncDialog(BuildContext context) { |
||||
showDialog( |
||||
context: context, |
||||
builder: (BuildContext context) { |
||||
return Dialog( |
||||
// Dialog shape and style |
||||
shape: RoundedRectangleBorder( |
||||
borderRadius: BorderRadius.circular(16), |
||||
), |
||||
backgroundColor: Colors.grey[100], |
||||
elevation: 0, |
||||
|
||||
// Dialog content |
||||
child: Column( |
||||
mainAxisSize: MainAxisSize.min, |
||||
children: [ |
||||
// Dialog title with close button |
||||
Container( |
||||
width: double.infinity, |
||||
color: Colors.indigo[700], // Indigo background |
||||
child: Row( |
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
||||
children: [ |
||||
Padding( |
||||
padding: const EdgeInsets.all(16.0), |
||||
child: Text( |
||||
"Sync Server Pengembalian", |
||||
style: TextStyle( |
||||
color: Colors.white, |
||||
fontWeight: FontWeight.bold, |
||||
fontSize: 16.0, |
||||
), |
||||
), |
||||
), |
||||
IconButton( |
||||
icon: Icon( |
||||
Icons.close, |
||||
color: Colors.white, |
||||
), |
||||
onPressed: () { |
||||
Navigator.pop(context); // Close dialog |
||||
}, |
||||
), |
||||
], |
||||
), |
||||
), |
||||
|
||||
// Divider |
||||
Divider( |
||||
height: 1, |
||||
thickness: 1, |
||||
color: Colors.black, // Black divider |
||||
), |
||||
|
||||
// Re-init Button |
||||
Container( |
||||
width: double.infinity, |
||||
child: TextButton( |
||||
onPressed: () { |
||||
Navigator.pop(context); // Close dialog |
||||
fetchDataFromApiAndSync(); |
||||
}, |
||||
child: Text( |
||||
"Upload + Download", |
||||
style: TextStyle( |
||||
color: Colors.black, |
||||
fontSize: 16.0, |
||||
fontFamily: 'Poppins', |
||||
), |
||||
), |
||||
), |
||||
), |
||||
|
||||
// Divider |
||||
// Divider( |
||||
// height: 1, |
||||
// thickness: 1, |
||||
// color: Colors.black, // Black divider |
||||
// ), |
||||
|
||||
// Upload Only Button |
||||
// Container( |
||||
// width: double.infinity, |
||||
// child: TextButton( |
||||
// onPressed: () { |
||||
// Navigator.pop(context); // Close dialog |
||||
// syncToMysql(); |
||||
// }, |
||||
// child: Text( |
||||
// "Upload Only", |
||||
// style: TextStyle( |
||||
// color: Colors.black, |
||||
// fontSize: 16.0, |
||||
// fontFamily: 'Poppins', |
||||
// ), |
||||
// ), |
||||
// ), |
||||
// ), |
||||
], |
||||
), |
||||
); |
||||
}, |
||||
); |
||||
} |
||||
|
||||
return DefaultTabController( |
||||
length: 1, |
||||
child: Scaffold( |
||||
appBar: AppBar( |
||||
backgroundColor: Colors.indigo[700], |
||||
elevation: 0, |
||||
title: Text('Data Pengembalian Barang', |
||||
style: TextStyle( |
||||
fontSize: 16, |
||||
)), |
||||
actions: [ |
||||
IconButton( |
||||
icon: Icon(Icons.backup), |
||||
onPressed: () async { |
||||
if (await SyncronizationPengembalianData.isInternet()) { |
||||
// Display custom dialog when the IconButton is pressed |
||||
showSyncDialog(context); |
||||
} else { |
||||
ScaffoldMessenger.of(context).showSnackBar( |
||||
SnackBar(content: Text("No internet connection")), |
||||
); |
||||
} |
||||
}, |
||||
), |
||||
], |
||||
leading: IconButton( |
||||
icon: Icon(Icons.arrow_back, color: Colors.white), |
||||
onPressed: () { |
||||
Navigator.pushNamed(context, '/home'); |
||||
}, |
||||
), |
||||
bottom: TabBar( |
||||
indicator: BoxDecoration(color: Color.fromARGB(255, 50, 39, 122)), |
||||
tabs: [ |
||||
Tab(text: 'Pengembalian Peti Hari ini'), |
||||
], |
||||
), |
||||
), |
||||
body: _isLoading |
||||
? const Center(child: CircularProgressIndicator()) |
||||
: TabBarView( |
||||
children: [ |
||||
SingleChildScrollView( |
||||
child: Column( |
||||
children: [ |
||||
SizedBox( |
||||
width: double.infinity, |
||||
child: PaginatedDataTable( |
||||
// header: Text('Searching'), // Removed const |
||||
rowsPerPage: _pageSize, |
||||
availableRowsPerPage: [10, 25, 50], // Removed const |
||||
onRowsPerPageChanged: (value) { |
||||
setState(() { |
||||
_pageSize = value!; |
||||
}); |
||||
}, |
||||
columns: [ |
||||
DataColumn(label: Text('No')), |
||||
DataColumn(label: Text('')), |
||||
DataColumn(label: Text('Kode Peti')), |
||||
DataColumn(label: Text('Tgl Pengembalian')), |
||||
DataColumn(label: Text('PJ Pengembalian')), |
||||
DataColumn(label: Text('Tujuan WH Pengembalian')), |
||||
DataColumn(label: Text('Kondisi Peti')), |
||||
], |
||||
source: _DataSourceLokal( |
||||
data: _data!, |
||||
context: context, |
||||
petiData: _petiData != null ? _petiData : [], |
||||
tipePetiData: |
||||
_tipePetiData != null ? _tipePetiData : [], |
||||
customerData: |
||||
_customerData != null ? _customerData : [], |
||||
warehouseData: |
||||
_warehouseData != null ? _warehouseData : [], |
||||
conditionData: |
||||
_conditionData != null ? _conditionData : [], |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
], |
||||
), |
||||
bottomNavigationBar: BottomAppBar( |
||||
color: Color.fromARGB(255, 5, 28, 158), // Warna latar belakang |
||||
child: Container( |
||||
height: 65.0, |
||||
child: Row( |
||||
mainAxisSize: MainAxisSize.max, |
||||
mainAxisAlignment: MainAxisAlignment.center, |
||||
children: <Widget>[ |
||||
InkWell( |
||||
customBorder: CircleBorder(), |
||||
onTap: () { |
||||
// Aksi ketika ikon diklik |
||||
Navigator.pushNamed(context, '/pengembalian-barang/edit'); |
||||
}, |
||||
child: Container( |
||||
width: 45, |
||||
height: 45, |
||||
decoration: BoxDecoration( |
||||
shape: BoxShape.circle, |
||||
color: Colors.greenAccent[700], |
||||
), |
||||
child: Icon( |
||||
Icons.add, |
||||
size: 30, |
||||
color: Colors.white, |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
), |
||||
), |
||||
); |
||||
} |
||||
} |
||||
|
||||
class _DataSourceLokal extends DataTableSource { |
||||
final List<AssetStatusModel> data; |
||||
List<PetiAssetModel>? petiData; |
||||
List<TypePetiModel>? tipePetiData; |
||||
List<CustomerModel>? customerData; |
||||
List<WarehouseModel>? warehouseData; |
||||
List<ConditionPetiModel>? conditionData; |
||||
final BuildContext context; |
||||
|
||||
_DataSourceLokal({ |
||||
required this.data, |
||||
required this.petiData, |
||||
required this.tipePetiData, |
||||
required this.customerData, |
||||
required this.warehouseData, |
||||
required this.conditionData, |
||||
required this.context, |
||||
}); |
||||
@override |
||||
DataRow? getRow(int index) { |
||||
if (index >= data.length) { |
||||
return null; |
||||
} |
||||
|
||||
data.sort((a, b) { |
||||
if (a.created_at == null && b.created_at == null) { |
||||
return 0; // Both dates are null, consider them equal |
||||
} else if (a.created_at == null) { |
||||
return 1; // Null is considered greater than non-null |
||||
} else if (b.created_at == null) { |
||||
return -1; // Non-null is considered smaller than null |
||||
} else { |
||||
return b.created_at!.compareTo(a.created_at!); // Compare non-null dates |
||||
} |
||||
}); |
||||
|
||||
final item = data[index]; |
||||
|
||||
// Menemukan data peti yang sesuai dengan asset |
||||
PetiAssetModel? petiSqfliteApi; |
||||
if (item.peti_id != null) { |
||||
petiSqfliteApi = petiData!.firstWhere( |
||||
(peti) => peti.id == item.peti_id, |
||||
orElse: () => PetiAssetModel( |
||||
id: null, |
||||
tipe_peti_id: null, |
||||
warna: 'null', |
||||
packing_no: null, |
||||
customer_id: null, |
||||
warehouse_id: null, |
||||
kondisipeti_id: null, |
||||
jumlah: null, |
||||
date_pembuatan: DateTime.now(), |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
fix_lot: '', |
||||
), |
||||
); |
||||
} |
||||
|
||||
TypePetiModel? tipePetiSqfliteApi; |
||||
if (petiSqfliteApi != null && petiSqfliteApi.tipe_peti_id != null) { |
||||
tipePetiSqfliteApi = tipePetiData?.firstWhere( |
||||
(tipePeti) => tipePeti.id == petiSqfliteApi?.tipe_peti_id, |
||||
orElse: () => TypePetiModel( |
||||
id: null, |
||||
type: 'null', |
||||
size_peti: 'null', |
||||
description: 'null', |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
), |
||||
); |
||||
} |
||||
|
||||
CustomerModel? customerSqfliteApi; |
||||
if (petiSqfliteApi != null && petiSqfliteApi.customer_id != null) { |
||||
customerSqfliteApi = customerData?.firstWhere( |
||||
(customer) => customer.id == petiSqfliteApi?.customer_id, |
||||
orElse: () => CustomerModel( |
||||
id: null, |
||||
name: 'null', |
||||
code_customer: 'null', |
||||
lot_no: 'null', |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
), |
||||
); |
||||
} |
||||
|
||||
ConditionPetiModel? conditionSqfliteApi; |
||||
if (item.kondisi_peti_id != null) { |
||||
conditionSqfliteApi = conditionData?.firstWhere( |
||||
(warehouse) => warehouse.id == item.kondisi_peti_id, |
||||
orElse: () => ConditionPetiModel( |
||||
id: null, |
||||
nama_kondisi: 'null', |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
), |
||||
); |
||||
} |
||||
|
||||
WarehouseModel? warehouseSqfliteApi; |
||||
if (item.enter_warehouse != null) { |
||||
warehouseSqfliteApi = warehouseData?.firstWhere( |
||||
(warehouse) => warehouse.id == item.enter_warehouse, |
||||
orElse: () => WarehouseModel( |
||||
id: null, |
||||
name: 'null', |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
), |
||||
); |
||||
} |
||||
|
||||
return DataRow(cells: [ |
||||
DataCell( |
||||
Text( |
||||
(index + 1).toString(), |
||||
), |
||||
), |
||||
DataCell( |
||||
GestureDetector( |
||||
onTap: () { |
||||
if (item.id != null) { |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => DetailPengembalianBarangPage( |
||||
pengembalianId: item.id.toString(), |
||||
), |
||||
), |
||||
); |
||||
|
||||
// print('asset id: ${item.id}'); |
||||
} |
||||
}, |
||||
child: Icon(Icons.article, |
||||
size: 40, |
||||
color: Colors.indigo[700]), // Ganti ikon sesuai kebutuhan |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
petiSqfliteApi != null && petiSqfliteApi.fix_lot != null |
||||
? petiSqfliteApi!.fix_lot.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.enter_at != null |
||||
? DateFormat('dd-MM-yyyy').format(item.enter_at!) |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.enter_pic.toString() != 'null' ? item.enter_pic.toString() : '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
(item.enter_warehouse != null && item.enter_warehouse != 'null') |
||||
? warehouseSqfliteApi != null && |
||||
warehouseSqfliteApi.id == item.enter_warehouse |
||||
? warehouseSqfliteApi.name.toString() |
||||
: '-' |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
conditionSqfliteApi != null && |
||||
conditionSqfliteApi.nama_kondisi != null |
||||
? conditionSqfliteApi!.nama_kondisi.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
]); |
||||
} |
||||
|
||||
@override |
||||
bool get isRowCountApproximate => false; |
||||
|
||||
@override |
||||
int get rowCount => data.length; |
||||
|
||||
@override |
||||
int get selectedRowCount => 0; |
||||
} |
@ -1,296 +0,0 @@
|
||||
import 'dart:convert'; |
||||
import 'dart:developer'; |
||||
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:data_table_2/data_table_2.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import 'package:provider/provider.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:siopas/pages/pengembalian_barang/show.dart'; |
||||
import 'package:siopas/providers/asset_status_provider.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
import '../../connection/connection.dart'; |
||||
import '../peminjaman_barang/show.dart'; |
||||
|
||||
class PengembalianBarangPage extends StatefulWidget { |
||||
const PengembalianBarangPage({super.key}); |
||||
|
||||
@override |
||||
State<PengembalianBarangPage> createState() => PengembalianBarangPageState(); |
||||
} |
||||
|
||||
class PengembalianBarangPageState extends State<PengembalianBarangPage> { |
||||
String? token; |
||||
int _currentPage = 1; |
||||
int _pageSize = 10; |
||||
List<AssetStatusModel> _data = []; |
||||
bool _isLoading = false; |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
_getUserToken(); |
||||
fetchData(); |
||||
} |
||||
|
||||
void _getUserToken() async { |
||||
SharedPreferences prefs = await SharedPreferences.getInstance(); |
||||
if (mounted) { |
||||
setState(() { |
||||
token = prefs.getString('token'); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
Future<void> fetchData() async { |
||||
if (mounted) { |
||||
setState(() { |
||||
_isLoading = true; |
||||
}); |
||||
|
||||
try { |
||||
final response = |
||||
await http.get(Uri.parse('$baseUrl/asset-status/pengembalian')); |
||||
|
||||
if (response.statusCode == 200) { |
||||
final jsonData = json.decode(response.body)['data']['asset_status']; |
||||
|
||||
final List<AssetStatusModel> newData = (jsonData as List) |
||||
.map((item) => AssetStatusModel.fromJson(item)) |
||||
.toList(); |
||||
|
||||
if (mounted) { |
||||
setState(() { |
||||
_data.addAll(newData); |
||||
_isLoading = false; |
||||
}); |
||||
} |
||||
} else { |
||||
if (mounted) { |
||||
setState(() { |
||||
_isLoading = false; |
||||
}); |
||||
} |
||||
throw Exception('Failed to fetch data'); |
||||
} |
||||
} catch (e) { |
||||
if (mounted) { |
||||
setState(() { |
||||
_isLoading = false; |
||||
}); |
||||
} |
||||
print('Error fetching data: $e'); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void _loadMoreData() { |
||||
if (mounted && !_isLoading) { |
||||
setState(() { |
||||
_currentPage++; |
||||
}); |
||||
fetchData(); |
||||
} |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Scaffold( |
||||
appBar: AppBar( |
||||
backgroundColor: Colors.indigo[700], |
||||
elevation: 0, |
||||
title: Text('Data Pengembalian Barang', |
||||
style: TextStyle( |
||||
fontSize: 16, |
||||
)), |
||||
leading: IconButton( |
||||
icon: Icon(Icons.arrow_back, color: Colors.white), |
||||
onPressed: () { |
||||
Navigator.pushNamed(context, '/home'); |
||||
}, |
||||
), |
||||
), |
||||
body: _isLoading |
||||
? const Center(child: CircularProgressIndicator()) |
||||
: SingleChildScrollView( |
||||
child: SizedBox( |
||||
width: double.infinity, |
||||
child: PaginatedDataTable( |
||||
header: const Text('Pengembalian Barang'), |
||||
rowsPerPage: _pageSize, |
||||
availableRowsPerPage: const [10, 25, 50], |
||||
onRowsPerPageChanged: (value) { |
||||
setState(() { |
||||
_pageSize = value!; |
||||
}); |
||||
}, |
||||
columns: const [ |
||||
DataColumn(label: Text('No')), |
||||
DataColumn(label: Text('')), |
||||
DataColumn(label: Text('Kode Peti')), |
||||
DataColumn(label: Text('Tgl Peminjaman')), |
||||
DataColumn(label: Text('Estimasi Pengembalian')), |
||||
DataColumn(label: Text('PJ Peminjaman')), |
||||
DataColumn(label: Text('Asal WH Peminjaman')), |
||||
DataColumn(label: Text('Tgl Pengembalian')), |
||||
DataColumn(label: Text('PJ Pengembalian')), |
||||
DataColumn(label: Text('Tujuan WH Pengembalian')), |
||||
DataColumn(label: Text('Kondisi Peti')), |
||||
DataColumn(label: Text('Status')), |
||||
], |
||||
source: _DataSource(data: _data, context: context), |
||||
), |
||||
), |
||||
), |
||||
bottomNavigationBar: BottomAppBar( |
||||
color: Color.fromARGB(255, 5, 28, 158), // Warna latar belakang |
||||
child: Container( |
||||
height: 65.0, |
||||
child: Row( |
||||
mainAxisSize: MainAxisSize.max, |
||||
mainAxisAlignment: MainAxisAlignment.center, |
||||
children: <Widget>[ |
||||
InkWell( |
||||
customBorder: CircleBorder(), |
||||
onTap: () { |
||||
// Aksi ketika ikon diklik |
||||
Navigator.pushNamed(context, '/pengembalian-barang/create'); |
||||
}, |
||||
child: Container( |
||||
width: 45, |
||||
height: 45, |
||||
decoration: BoxDecoration( |
||||
shape: BoxShape.circle, |
||||
color: Colors.greenAccent[700], |
||||
), |
||||
child: Icon( |
||||
Icons.add, |
||||
size: 30, |
||||
color: Colors.white, |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
), |
||||
); |
||||
} |
||||
} |
||||
|
||||
class _DataSource extends DataTableSource { |
||||
final List<AssetStatusModel> data; |
||||
final BuildContext context; |
||||
|
||||
_DataSource({required this.data, required this.context}); |
||||
@override |
||||
DataRow? getRow(int index) { |
||||
if (index >= data.length) { |
||||
return null; |
||||
} |
||||
|
||||
final item = data[index]; |
||||
|
||||
return DataRow(cells: [ |
||||
DataCell( |
||||
Text( |
||||
(index + 1).toString(), |
||||
), |
||||
), |
||||
DataCell( |
||||
GestureDetector( |
||||
onTap: () { |
||||
if (item.id != null) { |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => DetailPengembalianBarangPage( |
||||
pengembalianId: item.id!, |
||||
), |
||||
), |
||||
); |
||||
|
||||
print('asset id: ${item.id}'); |
||||
} |
||||
}, |
||||
child: Icon( |
||||
Icons.article_outlined, |
||||
size: 30, |
||||
color: Colors.indigo[700], |
||||
), |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
// item.asset.exit_at.toString(), |
||||
item.peti!.customer!.code_customer.toString() + |
||||
'-' + |
||||
item.peti!.tipe_peti!.type.toString(), |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.exit_at != null |
||||
? DateFormat('dd-MM-yyyy').format(item.exit_at!) |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
// item.asset.exit_at.toString(), |
||||
item.est_pengembalian != null |
||||
? DateFormat('dd-MM-yyyy').format(item.est_pengembalian!) |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.exit_pic.toString() != 'null' ? item.exit_pic.toString() : '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text(item.warehouse!.name.toString() != 'null' |
||||
? item.warehouse!.name.toString() |
||||
: '-'), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.enter_at != null |
||||
? DateFormat('dd-MM-yyyy').format(item.enter_at!) |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.enter_pic.toString() != 'null' ? item.enter_pic.toString() : '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.warehouse_enter!.id == item.enter_warehouse |
||||
? item.warehouse_enter!.name.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text(item.kondisi_peti.toString() != 'null' |
||||
? item.kondisi_peti.toString() |
||||
: '-'), |
||||
), |
||||
DataCell( |
||||
Text(item.warehouse_enter!.name == 'null' ? '-' : 'Sudah Dikembalikan'), |
||||
), |
||||
]); |
||||
} |
||||
|
||||
@override |
||||
bool get isRowCountApproximate => false; |
||||
|
||||
@override |
||||
int get rowCount => data.length; |
||||
|
||||
@override |
||||
int get selectedRowCount => 0; |
||||
} |
@ -0,0 +1,224 @@
|
||||
import 'dart:convert'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:siopas/models/transfer_peti_model.dart'; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import '../../../connection/connection.dart'; |
||||
import '../../../migrations/databasehelper.dart'; |
||||
import '../../../models/asset_status_model.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
class SyncronizationTransferPetiData { |
||||
Future<int> addData(TransferPetiModel transferPetiModel) async { |
||||
final dbClient = await conn.db; |
||||
late int result; |
||||
try { |
||||
result = await dbClient!.insert( |
||||
SqfliteDatabaseHelper.transferPetiTable, transferPetiModel.toJson()); |
||||
} catch (e) { |
||||
print('Error adding data to local SQLite: $e'); |
||||
result = 0; // Handle the error appropriately |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<List> fetchData() async { |
||||
var dbclient = await conn.db; |
||||
List transferPetiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.transferPetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
transferPetiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return transferPetiList; |
||||
} |
||||
|
||||
static Future<bool> isInternet() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data or WIFI detected, not internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
Future<List<TransferPetiModel>> fetchAllInfoTransferPeti() async { |
||||
final dbClient = await conn.db; |
||||
List<TransferPetiModel> transferPetiList = []; |
||||
try { |
||||
final maps = |
||||
await dbClient!.query(SqfliteDatabaseHelper.transferPetiTable); |
||||
for (var item in maps) { |
||||
transferPetiList.add(TransferPetiModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return transferPetiList; |
||||
} |
||||
|
||||
Future<void> deleteAllTransferPetiData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.transferPetiTable); |
||||
} |
||||
|
||||
Future saveTransferPetiServerWith( |
||||
List<TransferPetiModel> transferPetiLocalList) async { |
||||
for (var i = 0; i < transferPetiLocalList.length; i++) { |
||||
DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString == null || dateTimeString.isEmpty) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
// Format tanggal sesuai kebutuhan |
||||
String formattedCreatedAt = transferPetiLocalList[i].created_at != null |
||||
? DateFormat('yyyy-MM-dd HH:mm:ss.SSS') |
||||
.format(transferPetiLocalList[i].created_at!) |
||||
: DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(DateTime.now()); |
||||
|
||||
Map<String, dynamic> data = { |
||||
"mobile_id": transferPetiLocalList[i].mobile_id.toString(), // "id": "1 |
||||
"peti_id": transferPetiLocalList[i].peti_id.toString(), |
||||
"name_customer": transferPetiLocalList[i].name_customer.toString(), |
||||
"source_warehouse": |
||||
transferPetiLocalList[i].source_warehouse.toString(), |
||||
"destination_warehouse": |
||||
transferPetiLocalList[i].destination_warehouse.toString(), |
||||
"date": transferPetiLocalList[i].date.toString(), |
||||
"created_by": transferPetiLocalList[i].created_by.toString(), |
||||
"created_at": formattedCreatedAt, |
||||
}; |
||||
|
||||
final response = await http.post( |
||||
Uri.parse(await getBaseUrl() + '/m-transfer-peti/store'), |
||||
body: data, |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
// print("Data uploaded successfully for index $i:"); |
||||
// print("Response body: ${response.body}"); |
||||
print("Saving Data saveToTransferPetiWith"); |
||||
} else { |
||||
print( |
||||
"Failed to upload data for index $i. Status code: ${response.statusCode}"); |
||||
print("Response body: ${response.body}"); |
||||
} |
||||
} |
||||
|
||||
return true; // Pengunggahan berhasil |
||||
} |
||||
|
||||
Future<List> fetchAllPetiTransferInfo() async { |
||||
final dbClient = await conn.db; |
||||
List transferPetiList = []; |
||||
try { |
||||
final maps = |
||||
await dbClient!.query(SqfliteDatabaseHelper.transferPetiTable); |
||||
for (var item in maps) { |
||||
transferPetiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return transferPetiList; |
||||
} |
||||
|
||||
Future saveToMysql(List transferPetiLocalList) async { |
||||
DateTime? parseDateTime(String? dateTimeString) { |
||||
if (dateTimeString == null || dateTimeString.isEmpty) { |
||||
return null; |
||||
} |
||||
|
||||
try { |
||||
return DateTime.parse(dateTimeString); |
||||
} catch (e) { |
||||
print('Error parsing DateTime: $e'); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
for (var i = 0; i < transferPetiLocalList.length; i++) { |
||||
// Format tanggal sesuai kebutuhan |
||||
String formattedCreatedAt = transferPetiLocalList[i]['created_at'] != null |
||||
? DateFormat('yyyy-MM-dd HH:mm:ss.SSS') |
||||
.format(transferPetiLocalList[i]['created_at']) |
||||
: DateFormat('yyyy-MM-dd HH:mm:ss.SSS').format(DateTime.now()); |
||||
|
||||
Map<String, dynamic> data = { |
||||
"mobile_id": |
||||
transferPetiLocalList[i]['mobile_id'].toString(), // "id": "1 |
||||
"peti_id": transferPetiLocalList[i]['peti_id'].toString(), |
||||
"name_customer": transferPetiLocalList[i]['name_customer'].toString(), |
||||
"source_warehouse": |
||||
transferPetiLocalList[i]['source_warehouse'].toString(), |
||||
"destination_warehouse": |
||||
transferPetiLocalList[i]['destination_warehouse'].toString(), |
||||
"date": transferPetiLocalList[i]['date'].toString(), |
||||
"created_by": |
||||
transferPetiLocalList[i]['created_by'].toString(), // "id": "1 |
||||
"created_at": formattedCreatedAt, |
||||
}; |
||||
|
||||
final response = await http.post( |
||||
Uri.parse(await getBaseUrl() + '/m-transfer-peti/store'), |
||||
body: data); |
||||
if (response.statusCode == 200) { |
||||
print(response.body); |
||||
print("Saving Data Transfer Peti"); |
||||
} else { |
||||
print(response.statusCode); |
||||
print( |
||||
"Failed to upload data for index $i. Status code: ${response.statusCode}"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Future<List<TransferPetiModel>> fetchTransferPetiFromApi() async { |
||||
final response = await http.get( |
||||
Uri.parse(await getBaseUrl() + '/m-transfer-peti'), |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['transfer_peti']; |
||||
List<TransferPetiModel> transferPetiDBList = data |
||||
.map((item) => |
||||
TransferPetiModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return transferPetiDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Transfer Peti'); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,191 @@
|
||||
import 'dart:async'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
// import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:siopas/models/transfer_peti_model.dart'; |
||||
// import 'package:http/http.dart' as http; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:sqflite/sqflite.dart'; |
||||
|
||||
import '../../../migrations/databasehelper.dart'; |
||||
|
||||
class ControllerTransferPeti { |
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
Future<List<TransferPetiModel>> fetchAllInfo() async { |
||||
final dbClient = await conn.db; |
||||
List<TransferPetiModel> transferPetiList = []; |
||||
try { |
||||
final maps = |
||||
await dbClient!.query(SqfliteDatabaseHelper.transferPetiTable); |
||||
for (var item in maps) { |
||||
transferPetiList.add(TransferPetiModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return transferPetiList; |
||||
} |
||||
|
||||
static Future<bool> isInternet() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data or WIFI detected, not internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
Future<int> addData(TransferPetiModel transferPetiAddModel) async { |
||||
var dbclient = await conn.db; |
||||
int result = 0; // Provide an initial value |
||||
try { |
||||
result = await dbclient!.insert(SqfliteDatabaseHelper.transferPetiTable, |
||||
transferPetiAddModel.toJson()); |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<int> updateData(TransferPetiModel transferPetiAddModel) async { |
||||
var dbclient = await conn.db; |
||||
late int result; |
||||
try { |
||||
result = await dbclient!.update( |
||||
SqfliteDatabaseHelper.transferPetiTable, |
||||
transferPetiAddModel.toJson(), |
||||
where: 'id=?', |
||||
whereArgs: [transferPetiAddModel.id], |
||||
); |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
Future<List> fetchTransferPetiLocalController() async { |
||||
var dbclient = await conn.db; |
||||
List transferPetiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.transferPetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
transferPetiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return transferPetiList; |
||||
} |
||||
|
||||
Future<List<TransferPetiModel>> fetchDataId() async { |
||||
var dbclient = await conn.db; |
||||
List<TransferPetiModel> transferPetiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.transferPetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
transferPetiList.add(TransferPetiModel.fromJson(item)); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return transferPetiList; |
||||
} |
||||
|
||||
Future<void> deleteAllData() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.transferPetiTable); |
||||
} |
||||
|
||||
Future<void> addAllData(List<TransferPetiModel> transferPetiList) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var transferPeti in transferPetiList) { |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.transferPetiTable, |
||||
transferPeti.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
|
||||
Future<List> fetchPetiData() async { |
||||
var dbclient = await conn.db; |
||||
List petiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.petiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
petiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return petiList; |
||||
} |
||||
|
||||
Future<List> fetchTipePetiData() async { |
||||
var dbclient = await conn.db; |
||||
List tipePetiList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.typePetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
tipePetiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return tipePetiList; |
||||
} |
||||
|
||||
Future<List> fetchCustomerData() async { |
||||
var dbclient = await conn.db; |
||||
List customerList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.customerTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
customerList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return customerList; |
||||
} |
||||
|
||||
Future<List> fetchWarehouseData() async { |
||||
var dbclient = await conn.db; |
||||
List warehouseList = []; |
||||
try { |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.warehouseTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
warehouseList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print(e.toString()); |
||||
} |
||||
return warehouseList; |
||||
} |
||||
} |
@ -0,0 +1,751 @@
|
||||
import 'dart:async'; |
||||
import 'dart:convert'; |
||||
import 'dart:developer'; |
||||
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:data_table_2/data_table_2.dart'; |
||||
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
||||
import 'package:siopas/models/customer_model.dart'; |
||||
import 'package:siopas/models/disposal_model.dart'; |
||||
import 'package:siopas/models/m_asset_status_model.dart'; |
||||
import 'package:siopas/models/transfer_peti_model.dart'; |
||||
import 'package:siopas/models/type_peti_model.dart'; |
||||
import 'package:siopas/models/warehouse_mode.dart'; |
||||
import 'package:siopas/pages/peminjaman_barang/conn/syncronize.dart'; |
||||
import 'package:siopas/pages/transfer_peti/conn/syncronize.dart'; |
||||
import 'package:siopas/pages/transfer_peti/controller/transfer_peti_controller.dart'; |
||||
import 'package:siopas/services/syncronizeAPI.dart'; |
||||
import 'package:siopas/services/controllerApi.dart'; |
||||
import 'package:siopas/pages/peminjaman_barang/controller/peminjaman_controller.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import 'package:provider/provider.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:siopas/providers/asset_status_provider.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
import '../../connection/connection.dart'; |
||||
import '../../models/condition_peti_model.dart'; |
||||
|
||||
class TransferPetiPage extends StatefulWidget { |
||||
const TransferPetiPage({super.key}); |
||||
|
||||
@override |
||||
State<TransferPetiPage> createState() => TransferPetiPageState(); |
||||
} |
||||
|
||||
class TransferPetiPageState extends State<TransferPetiPage> { |
||||
String? token; |
||||
bool loading = true; |
||||
|
||||
// Reinit atau Upload Only |
||||
WarehouseModel? warehouseSqfliteApi; |
||||
List<TypePetiModel>? typePetiSqfliteApi; |
||||
List<CustomerModel>? customerSqfliteApi; |
||||
PetiAssetModel? petiSqfliteApi; |
||||
DisposalPetiModel? disposalSqfliteApi; |
||||
|
||||
List<PetiAssetModel>? _valpeti; // Change this line |
||||
List<WarehouseModel>? _valwarehouse; |
||||
List<DisposalPetiModel>? _valdisposal; |
||||
|
||||
// Datatable |
||||
int _currentPage = 1; |
||||
int _pageSize = 10; |
||||
List<TransferPetiModel>? _data; |
||||
List<PetiAssetModel>? _petiData; |
||||
List<TypePetiModel>? _tipePetiData; |
||||
List<CustomerModel>? _customerData; |
||||
List<WarehouseModel>? _warehouseData; |
||||
bool _isLoading = false; |
||||
Timer? _timer; |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
_getUserToken(); |
||||
|
||||
warehouseListAPI(); |
||||
typePetiListAPI(); |
||||
customerListAPI(); |
||||
petiListAPI(); |
||||
// disposalListAPI(); |
||||
|
||||
// Tampil data Datatables |
||||
// datatablesAssetStatusList(); |
||||
datatablesTransferPetiList(); |
||||
datatablesPetiList(); |
||||
datatablesTipePetiList(); |
||||
datatablesCustomerList(); |
||||
datatablesWarehouseList(); |
||||
_data = <TransferPetiModel>[]; |
||||
} |
||||
|
||||
void _getUserToken() async { |
||||
SharedPreferences prefs = await SharedPreferences.getInstance(); |
||||
if (mounted) { |
||||
setState(() { |
||||
token = prefs.getString('token'); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
// Reinit atau Upload Only ------------------------------------------------------------------------ |
||||
Future warehouseListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchWarehouseDataAPI().then((value) { |
||||
setState(() { |
||||
_valwarehouse = (value as List<dynamic>) |
||||
.map((item) => WarehouseModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
// Future disposalListAPI() async { |
||||
// if (mounted) { |
||||
// await ControllerApi().fetchDisposalDataAPI().then((value) { |
||||
// setState(() { |
||||
// _valdisposal = (value as List<dynamic>) |
||||
// .map((item) => DisposalPetiModel.fromJson(item)) |
||||
// .toList(); |
||||
// loading = false; |
||||
// }); |
||||
// }); |
||||
// } |
||||
// } |
||||
|
||||
Future typePetiListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchTipePetiDataAPI().then((value) { |
||||
setState(() { |
||||
typePetiSqfliteApi = (value as List<dynamic>) |
||||
.map((item) => TypePetiModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
Future customerListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchCustomerDataAPI().then((value) { |
||||
setState(() { |
||||
customerSqfliteApi = (value as List<dynamic>) |
||||
.map((item) => CustomerModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
Future petiListAPI() async { |
||||
if (mounted) { |
||||
await ControllerApi().fetchPetiDataAPI().then((value) { |
||||
setState(() { |
||||
_valpeti = (value as List<dynamic>) |
||||
.map((item) => PetiAssetModel.fromJson(item)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
// Future<void> reinitAssetStatusApi() async { |
||||
// List<AssetStatusModel> assetStatusApiData = |
||||
// await SyncronizationDataAPI().fetchAssetStatusFromApi(); |
||||
// await ControllerApi() |
||||
// .deleteAllAssetStatusDataAPI(); // Clear existing data in SQLite |
||||
// await ControllerApi() |
||||
// .addAllAssetStatusDataAPI(assetStatusApiData); // Add new data to SQLite |
||||
// } |
||||
|
||||
Future<void> reinitWarehouseApi() async { |
||||
EasyLoading.show(status: 'Mengambil data Warehouse...'); |
||||
List<WarehouseModel> warehouseApiData = |
||||
await SyncronizationDataAPI().fetchWarehouseFromApi(); |
||||
await ControllerApi() |
||||
.deleteAllWarehouseDataAPI(); // Clear existing data in SQLite |
||||
await ControllerApi() |
||||
.addAllWarehouseDataAPI(warehouseApiData); // Add new data to SQLite |
||||
EasyLoading.dismiss(); |
||||
} |
||||
|
||||
Future<void> reinitPetiApi() async { |
||||
EasyLoading.show(status: 'Mengambil data Peti...'); |
||||
List<PetiAssetModel> petiApiData = |
||||
await SyncronizationDataAPI().fetchPetiFromApi(); |
||||
await ControllerApi() |
||||
.deleteAllPetiDataAPI(); // Clear existing data in SQLite |
||||
await ControllerApi() |
||||
.addAllPetiDataAPI(petiApiData); // Add new data to SQLite |
||||
EasyLoading.dismiss(); |
||||
} |
||||
|
||||
Future<void> reinitCustomerApi() async { |
||||
EasyLoading.show(status: 'Mengambil data Customer...'); |
||||
List<CustomerModel> customerApiData = |
||||
await SyncronizationDataAPI().fetchCustomerFromApi(); |
||||
await ControllerApi() |
||||
.deleteAllCustomerDataAPI(); // Clear existing data in SQLite |
||||
await ControllerApi() |
||||
.addAllCustomerDataAPI(customerApiData); // Add new data to SQLite |
||||
EasyLoading.dismiss(); |
||||
} |
||||
|
||||
Future<void> reinitConditionPetiApi() async { |
||||
EasyLoading.show(status: 'Mengambil data Condition Peti...'); |
||||
List<ConditionPetiModel> conditionPetiApiData = |
||||
await SyncronizationDataAPI().fetchKondisiPetiFromApi(); |
||||
await ControllerApi() |
||||
.deleteAllKondisiPetiDataAPI(); // Clear existing data in SQLite |
||||
await ControllerApi().addAllKondisiPetiDataAPI( |
||||
conditionPetiApiData); // Add new data to SQLite |
||||
EasyLoading.dismiss(); |
||||
} |
||||
// Future<void> reinitDisposalApi() async { |
||||
// List<DisposalPetiModel> disposalApiData = |
||||
// await SyncronizationDataAPI().fetchDisposalFromApi(); |
||||
// await ControllerApi() |
||||
// .deleteAllDisposalDataAPI(); // Clear existing data in SQLite |
||||
// await ControllerApi() |
||||
// .addAllDisposalDataAPI(disposalApiData); // Add new data to SQLite |
||||
// } |
||||
|
||||
Future<void> fetchDataFromApiAndSync() async { |
||||
EasyLoading.show(status: 'Mengambil data dari Server...'); |
||||
try { |
||||
await syncToMysql(); |
||||
|
||||
// await reinitAssetStatusApi(); |
||||
await reinitWarehouseApi(); |
||||
await reinitPetiApi(); |
||||
await reinitCustomerApi(); |
||||
// await reinitTypePetiApi(); |
||||
await reinitConditionPetiApi(); |
||||
// await reinitDisposalApi(); |
||||
|
||||
// await datatablesAssetStatusList(); |
||||
await datatablesTransferPetiList(); |
||||
EasyLoading.showSuccess('Data berhasil diperbarui'); |
||||
} catch (e) { |
||||
EasyLoading.showError('Gagal memperbarui data: $e'); |
||||
} finally { |
||||
EasyLoading.dismiss(); |
||||
} |
||||
} |
||||
|
||||
Future syncToMysql() async { |
||||
await SyncronizationTransferPetiData() |
||||
.fetchAllInfoTransferPeti() |
||||
.then((transferPetiList) async { |
||||
EasyLoading.show( |
||||
status: 'Jangan tutup aplikasi. Kami sedang menyinkronkan...'); |
||||
await Future.delayed(Duration(seconds: 3)); |
||||
|
||||
// Tambahkan penanganan pengunggahan |
||||
bool uploadSuccess = await SyncronizationTransferPetiData() |
||||
.saveTransferPetiServerWith(transferPetiList); |
||||
|
||||
// Jika pengunggahan berhasil, hapus data lokal |
||||
if (uploadSuccess) { |
||||
await SyncronizationTransferPetiData().deleteAllTransferPetiData(); |
||||
// Setelah selesai, tampilkan pesan sukses |
||||
EasyLoading.showSuccess('Berhasil disinkronkan dengan Server'); |
||||
// await datatablesAssetStatusList(); |
||||
await datatablesTransferPetiList(); |
||||
} else { |
||||
// Tampilkan pesan gagal jika pengunggahan tidak berhasil |
||||
EasyLoading.showError('Gagal disinkronkan dengan Server'); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
// Future syncToMysql() async { |
||||
// await SyncronizationData().fetchAllInfo().then((assetList) async { |
||||
// EasyLoading.show(status: 'Don\'t close app. We are syncing...'); |
||||
// await SyncronizationData().saveToMysqlWith(assetList); |
||||
// await SyncronizationData().deleteAllAssetStatusData(); |
||||
// // EasyLoading.showSuccess('Successfully saved to MySQL'); |
||||
// }); |
||||
// } |
||||
|
||||
Future<void> isInteret() async { |
||||
await SyncronizationPeminjamanData.isInternet().then((connection) { |
||||
if (connection) { |
||||
print("Internet connection available"); |
||||
} else { |
||||
ScaffoldMessenger.of(context) |
||||
.showSnackBar(SnackBar(content: Text("No Internet"))); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
// Datatables ------------------------------------------------------------------------ |
||||
Future datatablesTransferPetiList() async { |
||||
await ControllerTransferPeti() |
||||
.fetchTransferPetiLocalController() |
||||
.then((value) { |
||||
setState(() { |
||||
_data = (value as List<dynamic>) |
||||
.map((e) => TransferPetiModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesPetiList() async { |
||||
await Controller().fetchPetiData().then((value) { |
||||
setState(() { |
||||
_petiData = (value as List<dynamic>) |
||||
.map((e) => PetiAssetModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesTipePetiList() async { |
||||
await Controller().fetchTipePetiData().then((value) { |
||||
setState(() { |
||||
_tipePetiData = (value as List<dynamic>) |
||||
.map((e) => TypePetiModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesCustomerList() async { |
||||
await Controller().fetchCustomerData().then((value) { |
||||
setState(() { |
||||
_customerData = (value as List<dynamic>) |
||||
.map((e) => CustomerModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
Future datatablesWarehouseList() async { |
||||
await Controller().fetchWarehouseData().then((value) { |
||||
setState(() { |
||||
_warehouseData = (value as List<dynamic>) |
||||
.map((e) => WarehouseModel.fromJson(e)) |
||||
.toList(); |
||||
loading = false; |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
void _loadMoreData() { |
||||
if (mounted && !_isLoading) { |
||||
setState(() { |
||||
_currentPage++; |
||||
}); |
||||
// datatablesAssetStatusList(); |
||||
datatablesTransferPetiList(); |
||||
} |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
// Add this function outside the build method |
||||
void showSyncDialog(BuildContext context) { |
||||
showDialog( |
||||
context: context, |
||||
builder: (BuildContext context) { |
||||
return Dialog( |
||||
// Dialog shape and style |
||||
shape: RoundedRectangleBorder( |
||||
borderRadius: BorderRadius.circular(16), |
||||
), |
||||
backgroundColor: Colors.grey[100], |
||||
elevation: 0, |
||||
|
||||
// Dialog content |
||||
child: Column( |
||||
mainAxisSize: MainAxisSize.min, |
||||
children: [ |
||||
// Dialog title with close button |
||||
Container( |
||||
width: double.infinity, |
||||
color: Colors.indigo[700], // Indigo background |
||||
child: Row( |
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
||||
children: [ |
||||
Padding( |
||||
padding: const EdgeInsets.all(16.0), |
||||
child: Text( |
||||
"Sync Server Transfer Peti", |
||||
style: TextStyle( |
||||
color: Colors.white, |
||||
fontWeight: FontWeight.bold, |
||||
fontSize: 16.0, |
||||
), |
||||
), |
||||
), |
||||
IconButton( |
||||
icon: Icon( |
||||
Icons.close, |
||||
color: Colors.white, |
||||
), |
||||
onPressed: () { |
||||
Navigator.pop(context); // Close dialog |
||||
}, |
||||
), |
||||
], |
||||
), |
||||
), |
||||
|
||||
// Divider |
||||
Divider( |
||||
height: 1, |
||||
thickness: 1, |
||||
color: Colors.black, // Black divider |
||||
), |
||||
|
||||
// Re-init Button |
||||
Container( |
||||
width: double.infinity, |
||||
child: TextButton( |
||||
onPressed: () { |
||||
Navigator.pop(context); // Close dialog |
||||
fetchDataFromApiAndSync(); |
||||
}, |
||||
child: Text( |
||||
"Upload + Download", |
||||
style: TextStyle( |
||||
color: Colors.black, |
||||
fontSize: 16.0, |
||||
fontFamily: 'Poppins', |
||||
), |
||||
), |
||||
), |
||||
), |
||||
|
||||
// Divider |
||||
// Divider( |
||||
// height: 1, |
||||
// thickness: 1, |
||||
// color: Colors.black, // Black divider |
||||
// ), |
||||
|
||||
// Upload Only Button |
||||
// Container( |
||||
// width: double.infinity, |
||||
// child: TextButton( |
||||
// onPressed: () { |
||||
// Navigator.pop(context); // Close dialog |
||||
// syncToMysql(); |
||||
// }, |
||||
// child: Text( |
||||
// "Upload Only", |
||||
// style: TextStyle( |
||||
// color: Colors.black, |
||||
// fontSize: 16.0, |
||||
// fontFamily: 'Poppins', |
||||
// ), |
||||
// ), |
||||
// ), |
||||
// ), |
||||
], |
||||
), |
||||
); |
||||
}, |
||||
); |
||||
} |
||||
|
||||
return DefaultTabController( |
||||
length: 1, |
||||
child: Scaffold( |
||||
appBar: AppBar( |
||||
backgroundColor: Colors.indigo[700], |
||||
elevation: 0, |
||||
title: Text('Data Transfer Peti', |
||||
style: TextStyle( |
||||
fontSize: 16, |
||||
)), |
||||
actions: [ |
||||
IconButton( |
||||
icon: Icon(Icons.backup), |
||||
onPressed: () async { |
||||
if (await SyncronizationPeminjamanData.isInternet()) { |
||||
// Display custom dialog when the IconButton is pressed |
||||
showSyncDialog(context); |
||||
} else { |
||||
ScaffoldMessenger.of(context).showSnackBar( |
||||
SnackBar(content: Text("No internet connection")), |
||||
); |
||||
} |
||||
}, |
||||
), |
||||
], |
||||
leading: IconButton( |
||||
icon: Icon(Icons.arrow_back, color: Colors.white), |
||||
onPressed: () { |
||||
Navigator.pushNamed(context, '/home'); |
||||
}, |
||||
), |
||||
bottom: TabBar( |
||||
indicator: BoxDecoration(color: Color.fromARGB(255, 50, 39, 122)), |
||||
tabs: [ |
||||
Tab(text: 'Transfer Peti Hari ini'), |
||||
], |
||||
), |
||||
), |
||||
body: _isLoading |
||||
? const Center(child: CircularProgressIndicator()) |
||||
: TabBarView( |
||||
children: [ |
||||
SingleChildScrollView( |
||||
child: Column( |
||||
children: [ |
||||
SizedBox( |
||||
width: double.infinity, |
||||
child: PaginatedDataTable( |
||||
// header: Text('Searching'), // Removed const |
||||
rowsPerPage: _pageSize, |
||||
availableRowsPerPage: [10, 25, 50], // Removed const |
||||
onRowsPerPageChanged: (value) { |
||||
setState(() { |
||||
_pageSize = value!; |
||||
}); |
||||
}, |
||||
columns: [ |
||||
DataColumn(label: Text('No')), |
||||
DataColumn(label: Text('Kode Peti')), |
||||
DataColumn(label: Text('Customer')), |
||||
DataColumn(label: Text('Tgl Transfer')), |
||||
DataColumn(label: Text('Asal Gudang')), |
||||
DataColumn(label: Text('Tujuan Gudang')), |
||||
], |
||||
source: _DataSourceLokal( |
||||
// data: _data!, |
||||
data: _data != null ? _data! : [], |
||||
context: context, |
||||
petiData: _petiData != null ? _petiData : [], |
||||
tipePetiData: |
||||
_tipePetiData != null ? _tipePetiData : [], |
||||
customerData: |
||||
_customerData != null ? _customerData : [], |
||||
warehouseData: |
||||
_warehouseData != null ? _warehouseData : [], |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
], |
||||
), |
||||
bottomNavigationBar: BottomAppBar( |
||||
color: Color.fromARGB(255, 5, 28, 158), // Warna latar belakang |
||||
child: Container( |
||||
height: 65.0, |
||||
child: Row( |
||||
mainAxisSize: MainAxisSize.max, |
||||
mainAxisAlignment: MainAxisAlignment.center, |
||||
children: <Widget>[ |
||||
InkWell( |
||||
customBorder: CircleBorder(), |
||||
onTap: () { |
||||
// Aksi ketika ikon diklik |
||||
Navigator.pushNamed(context, '/transfer-peti/edit'); |
||||
}, |
||||
child: Container( |
||||
width: 45, |
||||
height: 45, |
||||
decoration: BoxDecoration( |
||||
shape: BoxShape.circle, |
||||
color: Colors.greenAccent[700], |
||||
), |
||||
child: Icon( |
||||
Icons.add, |
||||
size: 30, |
||||
color: Colors.white, |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
), |
||||
), |
||||
); |
||||
} |
||||
} |
||||
|
||||
class _DataSourceLokal extends DataTableSource { |
||||
final List<TransferPetiModel> data; |
||||
List<PetiAssetModel>? petiData; |
||||
List<TypePetiModel>? tipePetiData; |
||||
List<CustomerModel>? customerData; |
||||
List<WarehouseModel>? warehouseData; |
||||
final BuildContext context; |
||||
|
||||
_DataSourceLokal({ |
||||
required this.data, |
||||
required this.petiData, |
||||
required this.tipePetiData, |
||||
required this.customerData, |
||||
required this.warehouseData, |
||||
required this.context, |
||||
}); |
||||
@override |
||||
DataRow? getRow(int index) { |
||||
if (index >= data.length) { |
||||
return null; |
||||
} |
||||
|
||||
data.sort((a, b) { |
||||
if (a.created_at == null && b.created_at == null) { |
||||
return 0; // Both dates are null, consider them equal |
||||
} else if (a.created_at == null) { |
||||
return 1; // Null is considered greater than non-null |
||||
} else if (b.created_at == null) { |
||||
return -1; // Non-null is considered smaller than null |
||||
} else { |
||||
return b.created_at!.compareTo(a.created_at!); // Compare non-null dates |
||||
} |
||||
}); |
||||
|
||||
final item = data[index]; |
||||
|
||||
// Menemukan data peti yang sesuai dengan asset |
||||
PetiAssetModel? petiSqfliteApi; |
||||
if (item.peti_id != null) { |
||||
petiSqfliteApi = petiData!.firstWhere( |
||||
(peti) => peti.id == item.peti_id, |
||||
orElse: () => PetiAssetModel( |
||||
id: null, |
||||
tipe_peti_id: null, |
||||
warna: 'null', |
||||
packing_no: null, |
||||
customer_id: null, |
||||
warehouse_id: null, |
||||
kondisipeti_id: null, |
||||
jumlah: null, |
||||
date_pembuatan: DateTime.now(), |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
fix_lot: '', |
||||
), |
||||
); |
||||
} |
||||
|
||||
TypePetiModel? tipePetiSqfliteApi; |
||||
if (petiSqfliteApi != null && petiSqfliteApi.tipe_peti_id != null) { |
||||
tipePetiSqfliteApi = tipePetiData?.firstWhere( |
||||
(tipePeti) => tipePeti.id == petiSqfliteApi?.tipe_peti_id, |
||||
orElse: () => TypePetiModel( |
||||
id: null, |
||||
type: 'null', |
||||
size_peti: 'null', |
||||
description: 'null', |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
), |
||||
); |
||||
} |
||||
|
||||
CustomerModel? customerSqfliteApi; |
||||
if (petiSqfliteApi != null && petiSqfliteApi.customer_id != null) { |
||||
customerSqfliteApi = customerData?.firstWhere( |
||||
(customer) => customer.id == petiSqfliteApi?.customer_id, |
||||
orElse: () => CustomerModel( |
||||
id: null, |
||||
name: 'null', |
||||
code_customer: 'null', |
||||
lot_no: 'null', |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
), |
||||
); |
||||
} |
||||
|
||||
WarehouseModel? warehouseAsalGudangSqfliteApi; |
||||
if (item.source_warehouse != null) { |
||||
warehouseAsalGudangSqfliteApi = warehouseData?.firstWhere( |
||||
(warehouse) => warehouse.id == item.source_warehouse, |
||||
orElse: () => WarehouseModel( |
||||
id: null, |
||||
name: 'null', |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
), |
||||
); |
||||
} |
||||
|
||||
WarehouseModel? warehouseTujuanGudangSqfliteApi; |
||||
if (item.destination_warehouse != null) { |
||||
warehouseTujuanGudangSqfliteApi = warehouseData?.firstWhere( |
||||
(warehouse) => warehouse.id == item.destination_warehouse, |
||||
orElse: () => WarehouseModel( |
||||
id: null, |
||||
name: 'null', |
||||
created_by: 'null', |
||||
updated_by: 'null', |
||||
), |
||||
); |
||||
} |
||||
|
||||
return DataRow(cells: [ |
||||
DataCell( |
||||
Text( |
||||
(index + 1).toString(), |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
petiSqfliteApi != null && petiSqfliteApi.fix_lot != null |
||||
? petiSqfliteApi!.fix_lot.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
customerSqfliteApi != null && customerSqfliteApi.name != null |
||||
? customerSqfliteApi!.name.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.date != null ? DateFormat('dd-MM-yyyy').format(item.date!) : '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
warehouseAsalGudangSqfliteApi != null && |
||||
warehouseAsalGudangSqfliteApi.name != null |
||||
? warehouseAsalGudangSqfliteApi!.name.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
warehouseTujuanGudangSqfliteApi != null && |
||||
warehouseTujuanGudangSqfliteApi.name != null |
||||
? warehouseTujuanGudangSqfliteApi!.name.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
]); |
||||
} |
||||
|
||||
@override |
||||
bool get isRowCountApproximate => false; |
||||
|
||||
@override |
||||
int get rowCount => data.length; |
||||
|
||||
@override |
||||
int get selectedRowCount => 0; |
||||
} |
@ -1,175 +0,0 @@
|
||||
import 'dart:convert'; |
||||
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import 'package:siopas/connection/connection.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
class DetailTransferPetiPage extends StatefulWidget { |
||||
final int petiId; |
||||
const DetailTransferPetiPage({Key? key, required this.petiId}) |
||||
: super(key: key); |
||||
|
||||
@override |
||||
State<DetailTransferPetiPage> createState() => _DetailTransferPetiPageState(); |
||||
} |
||||
|
||||
class _DetailTransferPetiPageState extends State<DetailTransferPetiPage> { |
||||
Map<String, dynamic>? petiStatusData; |
||||
String _formatDate(String date) { |
||||
DateTime parsedDate = DateTime.parse(date); |
||||
String formattedDate = |
||||
DateFormat('EEEE, dd MMMM yyyy', 'id_ID').format(parsedDate); |
||||
return formattedDate; |
||||
} |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
_fetchAssetStatusDataPengembalian(); |
||||
} |
||||
|
||||
Future<void> _fetchAssetStatusDataPengembalian() async { |
||||
try { |
||||
final response = await http.get( |
||||
Uri.parse('$baseUrl/peti-asset/show/${widget.petiId}'), |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
}, |
||||
); |
||||
|
||||
if (response.statusCode == 200) { |
||||
setState(() { |
||||
petiStatusData = json.decode(response.body)['data']['peti']; |
||||
}); |
||||
} else { |
||||
throw Exception('Failed to load data'); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data: $e'); |
||||
} |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Scaffold( |
||||
backgroundColor: Colors.grey[200], |
||||
appBar: AppBar( |
||||
backgroundColor: Colors.indigo[700], |
||||
elevation: 0, |
||||
title: Text('Detail Peti', |
||||
style: TextStyle( |
||||
color: Colors.white, |
||||
fontSize: 16, |
||||
)), |
||||
leading: IconButton( |
||||
icon: Icon(Icons.arrow_back, color: Colors.white), |
||||
onPressed: () { |
||||
Navigator.pushNamed(context, '/transfer-peti'); |
||||
}, |
||||
), |
||||
), |
||||
body: Padding( |
||||
padding: EdgeInsets.all(16.0), |
||||
child: Card( |
||||
shape: RoundedRectangleBorder( |
||||
borderRadius: BorderRadius.circular(15.0), |
||||
), |
||||
elevation: 5, |
||||
child: Column( |
||||
children: [ |
||||
Card( |
||||
shape: RoundedRectangleBorder( |
||||
borderRadius: |
||||
BorderRadius.vertical(top: Radius.circular(15.0)), |
||||
), |
||||
elevation: 0, |
||||
margin: EdgeInsets.all(0), |
||||
color: Colors.indigo[700], |
||||
child: Padding( |
||||
padding: const EdgeInsets.all(16.0), |
||||
child: Row( |
||||
children: [ |
||||
Icon(Icons.article, |
||||
size: 40, |
||||
color: Colors.white), // Ganti ikon sesuai kebutuhan |
||||
SizedBox(width: 10), |
||||
Text( |
||||
'ID: ${widget.petiId}', |
||||
style: TextStyle( |
||||
fontSize: 20, |
||||
fontWeight: FontWeight.bold, |
||||
color: Colors.white, |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
), |
||||
SizedBox(height: 10), |
||||
if (petiStatusData != null) ...[ |
||||
_buildDetailItem( |
||||
'Tipe Peti', |
||||
petiStatusData!['tipe_peti']['type'], |
||||
), |
||||
Divider(thickness: 1), |
||||
_buildDetailItem( |
||||
'Warna Peti', |
||||
petiStatusData!['warna'] != null |
||||
? petiStatusData!['warna'].toString() |
||||
: '-'), |
||||
Divider(thickness: 1), |
||||
_buildDetailItem( |
||||
'Customer', |
||||
petiStatusData!['customer']['name'] != null |
||||
? petiStatusData!['customer']['name'].toString() |
||||
: '-'), |
||||
Divider(thickness: 1), |
||||
_buildDetailItem( |
||||
'Warehouse', |
||||
petiStatusData!['warehouse']['name'] != null |
||||
? petiStatusData!['warehouse']['name'].toString() |
||||
: '-'), |
||||
Divider(thickness: 1), |
||||
_buildDetailItem( |
||||
'Status Peti', |
||||
petiStatusData!['status_disposal'] != null |
||||
? petiStatusData!['status_disposal'].toString() |
||||
: '-'), |
||||
Divider(thickness: 1), |
||||
_buildDetailItem( |
||||
'Jumlah Peti', |
||||
petiStatusData!['jumlah'] != null |
||||
? petiStatusData!['jumlah'].toString() |
||||
: '-', |
||||
), |
||||
Divider(thickness: 1), |
||||
_buildDetailItem( |
||||
'Tgl Pembuatan Peti', |
||||
petiStatusData!['created_at'] != null |
||||
? _formatDate(petiStatusData!['created_at']) |
||||
: '-'), |
||||
], |
||||
], |
||||
), |
||||
), |
||||
), |
||||
); |
||||
} |
||||
|
||||
Widget _buildDetailItem(String label, String value) { |
||||
return Padding( |
||||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0), |
||||
child: Row( |
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
||||
children: [ |
||||
Text( |
||||
label, |
||||
style: TextStyle(fontSize: 12.5, fontWeight: FontWeight.bold), |
||||
), |
||||
Text(value), |
||||
], |
||||
), |
||||
); |
||||
} |
||||
} |
@ -1,287 +0,0 @@
|
||||
import 'dart:convert'; |
||||
import 'dart:developer'; |
||||
|
||||
import 'package:flutter/material.dart'; |
||||
import 'package:data_table_2/data_table_2.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import 'package:provider/provider.dart'; |
||||
import 'package:shared_preferences/shared_preferences.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:siopas/models/m_asset_status_model.dart'; |
||||
import 'package:siopas/pages/pengembalian_barang/show.dart'; |
||||
import 'package:siopas/pages/transfer_peti/show.dart'; |
||||
import 'package:siopas/providers/asset_status_provider.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
import '../../connection/connection.dart'; |
||||
import '../peminjaman_barang/show.dart'; |
||||
|
||||
class TransferPetiPage extends StatefulWidget { |
||||
const TransferPetiPage({super.key}); |
||||
|
||||
@override |
||||
State<TransferPetiPage> createState() => TransferPetiPageState(); |
||||
} |
||||
|
||||
class TransferPetiPageState extends State<TransferPetiPage> { |
||||
String? token; |
||||
int _currentPage = 1; |
||||
int _pageSize = 10; |
||||
List<PetiAssetModel> _data = []; |
||||
bool _isLoading = false; |
||||
|
||||
@override |
||||
void initState() { |
||||
super.initState(); |
||||
_getUserToken(); |
||||
fetchData(); |
||||
} |
||||
|
||||
void _getUserToken() async { |
||||
SharedPreferences prefs = await SharedPreferences.getInstance(); |
||||
if (mounted) { |
||||
setState(() { |
||||
token = prefs.getString('token'); |
||||
}); |
||||
} |
||||
} |
||||
|
||||
Future<void> fetchData() async { |
||||
if (mounted) { |
||||
setState(() { |
||||
_isLoading = true; |
||||
}); |
||||
|
||||
try { |
||||
final response = await http.get(Uri.parse('$baseUrl/peti-asset')); |
||||
|
||||
if (response.statusCode == 200) { |
||||
final jsonData = json.decode(response.body)['data']['petis']; |
||||
|
||||
final List<PetiAssetModel> newData = (jsonData as List) |
||||
.map((item) => PetiAssetModel.fromJson(item)) |
||||
.toList(); |
||||
|
||||
if (mounted) { |
||||
setState(() { |
||||
_data.addAll(newData); |
||||
_isLoading = false; |
||||
}); |
||||
} |
||||
} else { |
||||
if (mounted) { |
||||
setState(() { |
||||
_isLoading = false; |
||||
}); |
||||
} |
||||
throw Exception('Failed to fetch data'); |
||||
} |
||||
} catch (e) { |
||||
if (mounted) { |
||||
setState(() { |
||||
_isLoading = false; |
||||
}); |
||||
} |
||||
print('Error fetching data: $e'); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void _loadMoreData() { |
||||
if (mounted && !_isLoading) { |
||||
setState(() { |
||||
_currentPage++; |
||||
}); |
||||
fetchData(); |
||||
} |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Scaffold( |
||||
appBar: AppBar( |
||||
backgroundColor: Colors.indigo[700], |
||||
elevation: 0, |
||||
title: Text('Data Peti (Transfer Peti)', |
||||
style: TextStyle( |
||||
fontSize: 16, |
||||
)), |
||||
leading: IconButton( |
||||
icon: Icon(Icons.arrow_back, color: Colors.white), |
||||
onPressed: () { |
||||
Navigator.pushNamed(context, '/home'); |
||||
}, |
||||
), |
||||
), |
||||
body: _isLoading |
||||
? const Center(child: CircularProgressIndicator()) |
||||
: SingleChildScrollView( |
||||
child: SizedBox( |
||||
width: double.infinity, |
||||
child: PaginatedDataTable( |
||||
header: const Text('Menu Peti'), |
||||
rowsPerPage: _pageSize, |
||||
availableRowsPerPage: const [10, 25, 50], |
||||
onRowsPerPageChanged: (value) { |
||||
setState(() { |
||||
_pageSize = value!; |
||||
}); |
||||
}, |
||||
columns: const [ |
||||
DataColumn(label: Text('No')), |
||||
DataColumn(label: Text('')), |
||||
DataColumn(label: Text('Customer')), |
||||
DataColumn(label: Text('Gudang')), |
||||
DataColumn(label: Text('Fix Lot')), |
||||
DataColumn(label: Text('Tipe Peti')), |
||||
DataColumn(label: Text('Ukuran Peti')), |
||||
DataColumn(label: Text('Lot No')), |
||||
DataColumn(label: Text('Status Peti')), |
||||
DataColumn(label: Text('Packing No')), |
||||
], |
||||
source: _DataSource(data: _data, context: context), |
||||
), |
||||
), |
||||
), |
||||
bottomNavigationBar: BottomAppBar( |
||||
color: Color.fromARGB(255, 5, 28, 158), // Warna latar belakang |
||||
child: Container( |
||||
height: 65.0, |
||||
child: Row( |
||||
mainAxisSize: MainAxisSize.max, |
||||
mainAxisAlignment: MainAxisAlignment.center, |
||||
children: <Widget>[ |
||||
InkWell( |
||||
customBorder: CircleBorder(), |
||||
onTap: () { |
||||
// Aksi ketika ikon diklik |
||||
Navigator.pushNamed(context, '/transfer-peti/edit'); |
||||
}, |
||||
child: Container( |
||||
width: 45, |
||||
height: 45, |
||||
decoration: BoxDecoration( |
||||
shape: BoxShape.circle, |
||||
color: Colors.yellow[800], |
||||
), |
||||
child: Icon( |
||||
Icons.local_shipping, |
||||
size: 30, |
||||
color: Colors.white, |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
), |
||||
), |
||||
); |
||||
} |
||||
} |
||||
|
||||
class _DataSource extends DataTableSource { |
||||
final List<PetiAssetModel> data; |
||||
final BuildContext context; |
||||
|
||||
_DataSource({required this.data, required this.context}); |
||||
@override |
||||
DataRow? getRow(int index) { |
||||
if (index >= data.length) { |
||||
return null; |
||||
} |
||||
|
||||
final item = data[index]; |
||||
|
||||
return DataRow(cells: [ |
||||
DataCell( |
||||
Text( |
||||
(index + 1).toString(), |
||||
), |
||||
), |
||||
DataCell( |
||||
GestureDetector( |
||||
onTap: () { |
||||
if (item.id != null) { |
||||
Navigator.push( |
||||
context, |
||||
MaterialPageRoute( |
||||
builder: (context) => DetailTransferPetiPage( |
||||
petiId: item.id!, |
||||
), |
||||
), |
||||
); |
||||
|
||||
print('asset id: ${item.id}'); |
||||
} |
||||
}, |
||||
child: Icon( |
||||
Icons.article_outlined, |
||||
size: 30, |
||||
color: Colors.indigo[700], |
||||
), |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.customer!.name!.toString() != 'null' |
||||
? item.customer!.name.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.warehouse!.name!.toString() != 'null' |
||||
? item.warehouse!.name.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.fix_lot.toString() != 'null' ? item.fix_lot.toString() : '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.tipe_peti!.type.toString() != 'null' |
||||
? item.tipe_peti!.type.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text(item.tipe_peti!.size_peti.toString() != 'null' |
||||
? item.tipe_peti!.size_peti.toString() |
||||
: '-'), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.customer!.lot_no.toString() != 'null' |
||||
? item.customer!.lot_no.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.status_disposal.toString() != 'null' |
||||
? item.status_disposal.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
DataCell( |
||||
Text( |
||||
item.packing_no.toString() != 'null' |
||||
? item.packing_no.toString() |
||||
: '-', |
||||
), |
||||
), |
||||
]); |
||||
} |
||||
|
||||
@override |
||||
bool get isRowCountApproximate => false; |
||||
|
||||
@override |
||||
int get rowCount => data.length; |
||||
|
||||
@override |
||||
int get selectedRowCount => 0; |
||||
} |
@ -0,0 +1,372 @@
|
||||
import 'dart:async'; |
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:siopas/models/customer_model.dart'; |
||||
import 'package:siopas/models/disposal_model.dart'; |
||||
import 'package:siopas/models/m_asset_status_model.dart'; |
||||
import 'package:siopas/models/warehouse_mode.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import 'package:sqflite/sqflite.dart'; |
||||
|
||||
import '../migrations/databasehelper.dart'; |
||||
import '../models/condition_peti_model.dart'; |
||||
import '../models/type_peti_model.dart'; |
||||
|
||||
class ControllerApi { |
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
static Future<bool> isInternetApi() async { |
||||
var connectivityResult = await (Connectivity().checkConnectivity()); |
||||
if (connectivityResult == ConnectivityResult.mobile) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("Mobile data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else if (connectivityResult == ConnectivityResult.wifi) { |
||||
if (await InternetConnectionChecker().hasConnection) { |
||||
print("wifi data detected & internet connection confirmed."); |
||||
return true; |
||||
} else { |
||||
print('No internet :( Reason:'); |
||||
return false; |
||||
} |
||||
} else { |
||||
print( |
||||
"Neither mobile data or WIFI detected, not internet connection found."); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
// Asset Status ------------------------------------------------------------------------------------------------------------------ |
||||
|
||||
Future<List> fetchAssetStatusLocalControllerApi() async { |
||||
var dbclient = await conn.db; |
||||
List assetStatusApiList = []; |
||||
try { |
||||
// Ensure that the table name is correct |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.asset_statusesTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
assetStatusApiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data from SQLite: $e'); |
||||
} |
||||
return assetStatusApiList; |
||||
} |
||||
|
||||
Future<void> deleteAllAssetStatusDataAPI() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.asset_statusesTable); |
||||
} |
||||
|
||||
Future<void> addAllAssetStatusDataAPI( |
||||
List<AssetStatusModel> assetStatusListApi) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var assetStatus in assetStatusListApi) { |
||||
// Ensure that toJson() correctly converts the model to a map |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.asset_statusesTable, |
||||
assetStatus.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
// End Asset Status ------------------------------------------------------------------------------------------------------------------ |
||||
|
||||
// Peti ------------------------------------------------------------------------------------------------------------------ |
||||
Future<List> fetchPetiDataAPI() async { |
||||
var dbclient = await conn.db; |
||||
List petiApiList = []; |
||||
try { |
||||
// Ensure that the table name is correct |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.petiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
petiApiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data from SQLite: $e'); |
||||
} |
||||
return petiApiList; |
||||
} |
||||
|
||||
Future<void> deleteAllPetiDataAPI() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.petiTable); |
||||
} |
||||
|
||||
Future<void> addAllPetiDataAPI(List<PetiAssetModel> petiListApi) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var peti in petiListApi) { |
||||
// Ensure that toJson() correctly converts the model to a map |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.petiTable, |
||||
peti.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
// End Peti ------------------------------------------------------------------------------------------------------------------ |
||||
|
||||
// Warehouse ------------------------------------------------------------------------------------------------------------------ |
||||
Future<List> fetchWarehouseDataAPI() async { |
||||
var dbclient = await conn.db; |
||||
List warehouseApiList = []; |
||||
try { |
||||
// Ensure that the table name is correct |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.warehouseTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
warehouseApiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data from SQLite: $e'); |
||||
} |
||||
return warehouseApiList; |
||||
} |
||||
|
||||
Future<void> deleteAllWarehouseDataAPI() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.warehouseTable); |
||||
} |
||||
|
||||
Future<void> addAllWarehouseDataAPI( |
||||
List<WarehouseModel> warehouseListApi) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var warehouse in warehouseListApi) { |
||||
// Ensure that toJson() correctly converts the model to a map |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.warehouseTable, |
||||
warehouse.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
// End Warehouse ------------------------------------------------------------------------------------------------------------------ |
||||
|
||||
// Customer ------------------------------------------------------------------------------------------------------------------ |
||||
Future<List> fetchCustomerDataAPI() async { |
||||
var dbclient = await conn.db; |
||||
List customerApiList = []; |
||||
try { |
||||
// Ensure that the table name is correct |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.customerTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
customerApiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data from SQLite: $e'); |
||||
} |
||||
return customerApiList; |
||||
} |
||||
|
||||
Future<void> deleteAllCustomerDataAPI() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.customerTable); |
||||
} |
||||
|
||||
Future<void> addAllCustomerDataAPI( |
||||
List<CustomerModel> customerApiList) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var customer in customerApiList) { |
||||
// Ensure that toJson() correctly converts the model to a map |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.customerTable, |
||||
customer.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
// End Customer ------------------------------------------------------------------------------------------------------------------ |
||||
|
||||
// Tipe Peti ------------------------------------------------------------------------------------------------------------------ |
||||
Future<List> fetchTipePetiDataAPI() async { |
||||
var dbclient = await conn.db; |
||||
List tipePetiApiList = []; |
||||
try { |
||||
// Ensure that the table name is correct |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.typePetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
tipePetiApiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data from SQLite: $e'); |
||||
} |
||||
return tipePetiApiList; |
||||
} |
||||
|
||||
Future<void> deleteAllTipePetiDataAPI() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.typePetiTable); |
||||
} |
||||
|
||||
Future<void> addAllTipePetiDataAPI( |
||||
List<TypePetiModel> tipePetiApiList) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var tipePeti in tipePetiApiList) { |
||||
// Ensure that toJson() correctly converts the model to a map |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.typePetiTable, |
||||
tipePeti.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
// End Tipe Peti ------------------------------------------------------------------------------------------------------------------ |
||||
|
||||
// Tipe Kondisi ------------------------------------------------------------------------------------------------------------------ |
||||
// Future<List> fetchKondisiPetiDataAPI() async { |
||||
// var dbclient = await conn.db; |
||||
// List kondisiPetiApiList = []; |
||||
// try { |
||||
// // Ensure that the table name is correct |
||||
// List<Map<String, dynamic>> maps = await dbclient! |
||||
// .query(SqfliteDatabaseHelper.conditionPetiTable, orderBy: 'id DESC'); |
||||
// for (var item in maps) { |
||||
// kondisiPetiApiList.add(item); |
||||
// } |
||||
// } catch (e) { |
||||
// print('Error fetching data from SQLite: $e'); |
||||
// } |
||||
// return kondisiPetiApiList; |
||||
// } |
||||
|
||||
Future<List> fetchKondisiPetiDataAPI() async { |
||||
var dbclient = await conn.db; |
||||
List conditionApiList = []; |
||||
try { |
||||
// Ensure that the table name is correct |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.conditionPetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
conditionApiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data from SQLite: $e'); |
||||
} |
||||
return conditionApiList; |
||||
} |
||||
|
||||
Future<void> deleteAllKondisiPetiDataAPI() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.conditionPetiTable); |
||||
} |
||||
|
||||
Future<void> addAllKondisiPetiDataAPI( |
||||
List<ConditionPetiModel> kondisiPetiApiList) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var kondisiPeti in kondisiPetiApiList) { |
||||
// Ensure that toJson() correctly converts the model to a map |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.conditionPetiTable, |
||||
kondisiPeti.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
// End Kondisi Peti ------------------------------------------------------------------------------------------------------------------ |
||||
|
||||
// Transfer Kondisi ------------------------------------------------------------------------------------------------------------------ |
||||
Future<List> fetchTransferPetiDataAPI() async { |
||||
var dbclient = await conn.db; |
||||
List transferPetiApiList = []; |
||||
try { |
||||
// Ensure that the table name is correct |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.transferPetiTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
transferPetiApiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data from SQLite: $e'); |
||||
} |
||||
return transferPetiApiList; |
||||
} |
||||
|
||||
Future<void> deleteAllTransferPetiDataAPI() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.transferPetiTable); |
||||
} |
||||
|
||||
Future<void> addAllTransferPetiDataAPI( |
||||
List<ConditionPetiModel> transferPetiApiList) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var transferPeti in transferPetiApiList) { |
||||
// Ensure that toJson() correctly converts the model to a map |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.transferPetiTable, |
||||
transferPeti.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
// End Transfer Peti ------------------------------------------------------------------------------------------------------------------ |
||||
|
||||
// Disposal ------------------------------------------------------------------------------------------------------------------ |
||||
Future<List> fetchDisposalDataAPI() async { |
||||
var dbclient = await conn.db; |
||||
List disposalApiList = []; |
||||
try { |
||||
// Ensure that the table name is correct |
||||
List<Map<String, dynamic>> maps = await dbclient! |
||||
.query(SqfliteDatabaseHelper.disposalTable, orderBy: 'id DESC'); |
||||
for (var item in maps) { |
||||
disposalApiList.add(item); |
||||
} |
||||
} catch (e) { |
||||
print('Error fetching data from SQLite: $e'); |
||||
} |
||||
return disposalApiList; |
||||
} |
||||
|
||||
Future<void> deleteAllDisposalDataAPI() async { |
||||
var dbClient = await conn.db; |
||||
await dbClient!.delete(SqfliteDatabaseHelper.disposalTable); |
||||
} |
||||
|
||||
Future<void> addAllDisposalDataAPI( |
||||
List<DisposalPetiModel> disposalApiList) async { |
||||
var dbclient = await conn.db; |
||||
Batch batch = dbclient!.batch(); |
||||
|
||||
for (var disposal in disposalApiList) { |
||||
// Ensure that toJson() correctly converts the model to a map |
||||
batch.insert( |
||||
SqfliteDatabaseHelper.disposalTable, |
||||
disposal.toJson(), |
||||
); |
||||
} |
||||
|
||||
await batch.commit(); |
||||
} |
||||
// End Disposal ------------------------------------------------------------------------------------------------------------------ |
||||
} |
@ -0,0 +1,224 @@
|
||||
import 'dart:convert'; |
||||
import 'package:connectivity_plus/connectivity_plus.dart'; |
||||
import 'package:siopas/connection/connection.dart'; |
||||
import 'package:siopas/models/asset_status_model.dart'; |
||||
import 'package:siopas/models/condition_peti_model.dart'; |
||||
import 'package:siopas/models/customer_model.dart'; |
||||
import 'package:siopas/models/transfer_peti_model.dart'; |
||||
import 'package:siopas/models/type_peti_model.dart'; |
||||
import 'package:siopas/models/warehouse_mode.dart'; |
||||
import 'package:internet_connection_checker/internet_connection_checker.dart'; |
||||
import '../migrations/databasehelper.dart'; |
||||
import 'package:http/http.dart' as http; |
||||
|
||||
import '../models/disposal_model.dart'; |
||||
import '../models/m_asset_status_model.dart'; |
||||
|
||||
class SyncronizationDataAPI { |
||||
final conn = SqfliteDatabaseHelper.instance; |
||||
|
||||
Future<List<AssetStatusModel>> fetchAssetStatusFromApi() async { |
||||
final apiURL = '${await getBaseUrl()}/asset-status'; |
||||
|
||||
final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['asset_status']; |
||||
print('Success Fetch Data API Asset Status'); |
||||
List<AssetStatusModel> assetStatusApiList = data |
||||
.map( |
||||
(item) => AssetStatusModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return assetStatusApiList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Peti'); |
||||
} |
||||
} |
||||
|
||||
Future<List<PetiAssetModel>> fetchPetiFromApi() async { |
||||
final apiURL = '${await getBaseUrl()}/peti-asset'; |
||||
|
||||
final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['petis']; |
||||
print('Success Fetch Data Peti'); |
||||
List<PetiAssetModel> petiDBList = data |
||||
.map((item) => PetiAssetModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return petiDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Peti'); |
||||
} |
||||
} |
||||
|
||||
// Future<List<PetiAssetModel>> fetchPetiFromApi() async { |
||||
// final apiURL = 'http://192.168.0.18:8000/api/v1/peti-asset'; |
||||
|
||||
// final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
// if (response.statusCode == 200) { |
||||
// List<dynamic> data = json.decode(response.body)['data']['petis']; |
||||
// print('Success Fetch Data Peti'); |
||||
|
||||
// List<PetiAssetModel> petiList = data.map((item) { |
||||
// // Extracting and transforming data from JSON |
||||
// String id = item['id'].toString(); |
||||
// String tipePetiId = item['tipe_peti_id'].toString(); |
||||
// String warna = item['warna'].toString(); |
||||
// int? packingNo = item['packing_no'] != null |
||||
// ? int.parse(item['packing_no'].toString()) |
||||
// : null; |
||||
// String customerID = item['customer_id'].toString(); |
||||
// String warehouseID = item['warehouse_id'].toString(); |
||||
// String kondisiPetiID = item['kondisipeti_id'].toString(); |
||||
// int? jumlah = item['jumlah'] != null |
||||
// ? int.parse(item['jumlah'].toString()) |
||||
// : null; |
||||
// DateTime datePembuatan = DateTime.parse(item['date_pembuatan']); |
||||
|
||||
// // Creating an instance of PetiAssetModel |
||||
// PetiAssetModel peti = PetiAssetModel( |
||||
// id: id, |
||||
// tipe_peti_id: tipePetiId, |
||||
// warna: warna, |
||||
// packing_no: packingNo, |
||||
// customer_id: customerID, |
||||
// warehouse_id: warehouseID, |
||||
// kondisipeti_id: kondisiPetiID, |
||||
// jumlah: jumlah, |
||||
// date_pembuatan: datePembuatan, |
||||
// created_by: |
||||
// item['created_by'] != null ? item['created_by'].toString() : null, |
||||
// updated_by: |
||||
// item['updated_by'] != null ? item['updated_by'].toString() : null, |
||||
// ); |
||||
|
||||
// return peti; |
||||
// }).toList(); |
||||
|
||||
// return petiList; |
||||
// } else { |
||||
// throw Exception('Failed to fetch data from API Peti'); |
||||
// } |
||||
// } |
||||
|
||||
Future<List<WarehouseModel>> fetchWarehouseFromApi() async { |
||||
final apiURL = '${await getBaseUrl()}/m-warehouse'; |
||||
|
||||
final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['warehouse']; |
||||
print('Success Fetch Data Warehouse'); |
||||
|
||||
List<WarehouseModel> warehouseDBList = data |
||||
.map((item) => WarehouseModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return warehouseDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Warehouse'); |
||||
} |
||||
} |
||||
|
||||
Future<List<CustomerModel>> fetchCustomerFromApi() async { |
||||
final apiURL = '${await getBaseUrl()}/m-customer'; |
||||
|
||||
final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['customers']; |
||||
print('Success Fetch Data Customer'); |
||||
|
||||
List<CustomerModel> customerDBList = data |
||||
.map((item) => CustomerModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return customerDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Customer'); |
||||
} |
||||
} |
||||
|
||||
Future<List<TypePetiModel>> fetchTipePetiFromApi() async { |
||||
final apiURL = '${await getBaseUrl()}/m-type-peti'; |
||||
|
||||
final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['tipe_peti']; |
||||
print('Success Fetch Data Tipe Peti'); |
||||
|
||||
List<TypePetiModel> tipePetiDBList = data |
||||
.map((item) => TypePetiModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return tipePetiDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Tipe Peti'); |
||||
} |
||||
} |
||||
|
||||
Future<List<ConditionPetiModel>> fetchKondisiPetiFromApi() async { |
||||
final apiURL = '${await getBaseUrl()}/m-kondisi-peti'; |
||||
|
||||
final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['kondisi_peti']; |
||||
print('Success Fetch Data Master Kondisi Peti'); |
||||
|
||||
List<ConditionPetiModel> kondisiPetiDBList = data |
||||
.map((item) => |
||||
ConditionPetiModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return kondisiPetiDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Master Kondisi Peti'); |
||||
} |
||||
} |
||||
|
||||
Future<List<TransferPetiModel>> fetchTransferPetiFromApi() async { |
||||
final apiURL = '${await getBaseUrl()}/m-transfer-peti'; |
||||
|
||||
final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['transfer_peti']; |
||||
print('Success Fetch Data Transfer Peti'); |
||||
|
||||
List<TransferPetiModel> transferPetiDBList = data |
||||
.map((item) => |
||||
TransferPetiModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return transferPetiDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Transfer Peti'); |
||||
} |
||||
} |
||||
|
||||
Future<List<DisposalPetiModel>> fetchDisposalFromApi() async { |
||||
final apiURL = '${await getBaseUrl()}/m-disposal-peti'; |
||||
|
||||
final response = await http.get(Uri.parse(apiURL)); |
||||
|
||||
if (response.statusCode == 200) { |
||||
List<dynamic> data = json.decode(response.body)['data']['disposals']; |
||||
print('Success Fetch Data Disposal Peti'); |
||||
|
||||
List<DisposalPetiModel> disposalPetiDBList = data |
||||
.map((item) => |
||||
DisposalPetiModel.fromJson(item as Map<String, dynamic>)) |
||||
.toList(); |
||||
|
||||
return disposalPetiDBList; |
||||
} else { |
||||
throw Exception('Failed to fetch data from API Disposal Peti'); |
||||
} |
||||
} |
||||
} |