feat: update profit shareing
Build & Deploy iOS to TestFlight / build-and-deploy (push) Canceled after 0s

This commit is contained in:
efrilm
2026-10-04 22:31:01 +07:00
parent 288d0d75a0
commit 243b7e02aa
23 changed files with 1349 additions and 451 deletions
@@ -15656,8 +15656,6 @@ ProfitSharingPercentageDto _$ProfitSharingPercentageDtoFromJson(
/// @nodoc
mixin _$ProfitSharingPercentageDto {
@JsonKey(name: 'purchase')
num? get purchase => throw _privateConstructorUsedError;
@JsonKey(name: 'owner')
num? get owner => throw _privateConstructorUsedError;
@JsonKey(name: 'team')
@@ -15685,7 +15683,6 @@ abstract class $ProfitSharingPercentageDtoCopyWith<$Res> {
>;
@useResult
$Res call({
@JsonKey(name: 'purchase') num? purchase,
@JsonKey(name: 'owner') num? owner,
@JsonKey(name: 'team') num? team,
});
@@ -15708,17 +15705,9 @@ class _$ProfitSharingPercentageDtoCopyWithImpl<
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? purchase = freezed,
Object? owner = freezed,
Object? team = freezed,
}) {
$Res call({Object? owner = freezed, Object? team = freezed}) {
return _then(
_value.copyWith(
purchase: freezed == purchase
? _value.purchase
: purchase // ignore: cast_nullable_to_non_nullable
as num?,
owner: freezed == owner
? _value.owner
: owner // ignore: cast_nullable_to_non_nullable
@@ -15743,7 +15732,6 @@ abstract class _$$ProfitSharingPercentageDtoImplCopyWith<$Res>
@override
@useResult
$Res call({
@JsonKey(name: 'purchase') num? purchase,
@JsonKey(name: 'owner') num? owner,
@JsonKey(name: 'team') num? team,
});
@@ -15766,17 +15754,9 @@ class __$$ProfitSharingPercentageDtoImplCopyWithImpl<$Res>
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? purchase = freezed,
Object? owner = freezed,
Object? team = freezed,
}) {
$Res call({Object? owner = freezed, Object? team = freezed}) {
return _then(
_$ProfitSharingPercentageDtoImpl(
purchase: freezed == purchase
? _value.purchase
: purchase // ignore: cast_nullable_to_non_nullable
as num?,
owner: freezed == owner
? _value.owner
: owner // ignore: cast_nullable_to_non_nullable
@@ -15794,7 +15774,6 @@ class __$$ProfitSharingPercentageDtoImplCopyWithImpl<$Res>
@JsonSerializable()
class _$ProfitSharingPercentageDtoImpl extends _ProfitSharingPercentageDto {
const _$ProfitSharingPercentageDtoImpl({
@JsonKey(name: 'purchase') this.purchase,
@JsonKey(name: 'owner') this.owner,
@JsonKey(name: 'team') this.team,
}) : super._();
@@ -15803,9 +15782,6 @@ class _$ProfitSharingPercentageDtoImpl extends _ProfitSharingPercentageDto {
Map<String, dynamic> json,
) => _$$ProfitSharingPercentageDtoImplFromJson(json);
@override
@JsonKey(name: 'purchase')
final num? purchase;
@override
@JsonKey(name: 'owner')
final num? owner;
@@ -15815,7 +15791,7 @@ class _$ProfitSharingPercentageDtoImpl extends _ProfitSharingPercentageDto {
@override
String toString() {
return 'ProfitSharingPercentageDto(purchase: $purchase, owner: $owner, team: $team)';
return 'ProfitSharingPercentageDto(owner: $owner, team: $team)';
}
@override
@@ -15823,15 +15799,13 @@ class _$ProfitSharingPercentageDtoImpl extends _ProfitSharingPercentageDto {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProfitSharingPercentageDtoImpl &&
(identical(other.purchase, purchase) ||
other.purchase == purchase) &&
(identical(other.owner, owner) || other.owner == owner) &&
(identical(other.team, team) || other.team == team));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, purchase, owner, team);
int get hashCode => Object.hash(runtimeType, owner, team);
/// Create a copy of ProfitSharingPercentageDto
/// with the given fields replaced by the non-null parameter values.
@@ -15852,7 +15826,6 @@ class _$ProfitSharingPercentageDtoImpl extends _ProfitSharingPercentageDto {
abstract class _ProfitSharingPercentageDto extends ProfitSharingPercentageDto {
const factory _ProfitSharingPercentageDto({
@JsonKey(name: 'purchase') final num? purchase,
@JsonKey(name: 'owner') final num? owner,
@JsonKey(name: 'team') final num? team,
}) = _$ProfitSharingPercentageDtoImpl;
@@ -15861,9 +15834,6 @@ abstract class _ProfitSharingPercentageDto extends ProfitSharingPercentageDto {
factory _ProfitSharingPercentageDto.fromJson(Map<String, dynamic> json) =
_$ProfitSharingPercentageDtoImpl.fromJson;
@override
@JsonKey(name: 'purchase')
num? get purchase;
@override
@JsonKey(name: 'owner')
num? get owner;
@@ -15895,8 +15865,6 @@ mixin _$ProfitSharingPeriodDto {
num? get revenue => throw _privateConstructorUsedError;
@JsonKey(name: 'order_count')
num? get orderCount => throw _privateConstructorUsedError;
@JsonKey(name: 'limit_purchase')
num? get limitPurchase => throw _privateConstructorUsedError;
@JsonKey(name: 'sdl')
num? get sdl => throw _privateConstructorUsedError;
@JsonKey(name: 'limit_team')
@@ -15928,7 +15896,6 @@ abstract class $ProfitSharingPeriodDtoCopyWith<$Res> {
@JsonKey(name: 'period_end') DateTime? periodEnd,
@JsonKey(name: 'revenue') num? revenue,
@JsonKey(name: 'order_count') num? orderCount,
@JsonKey(name: 'limit_purchase') num? limitPurchase,
@JsonKey(name: 'sdl') num? sdl,
@JsonKey(name: 'limit_team') num? limitTeam,
@JsonKey(name: 'month') String? month,
@@ -15958,7 +15925,6 @@ class _$ProfitSharingPeriodDtoCopyWithImpl<
Object? periodEnd = freezed,
Object? revenue = freezed,
Object? orderCount = freezed,
Object? limitPurchase = freezed,
Object? sdl = freezed,
Object? limitTeam = freezed,
Object? month = freezed,
@@ -15982,10 +15948,6 @@ class _$ProfitSharingPeriodDtoCopyWithImpl<
? _value.orderCount
: orderCount // ignore: cast_nullable_to_non_nullable
as num?,
limitPurchase: freezed == limitPurchase
? _value.limitPurchase
: limitPurchase // ignore: cast_nullable_to_non_nullable
as num?,
sdl: freezed == sdl
? _value.sdl
: sdl // ignore: cast_nullable_to_non_nullable
@@ -16022,7 +15984,6 @@ abstract class _$$ProfitSharingPeriodDtoImplCopyWith<$Res>
@JsonKey(name: 'period_end') DateTime? periodEnd,
@JsonKey(name: 'revenue') num? revenue,
@JsonKey(name: 'order_count') num? orderCount,
@JsonKey(name: 'limit_purchase') num? limitPurchase,
@JsonKey(name: 'sdl') num? sdl,
@JsonKey(name: 'limit_team') num? limitTeam,
@JsonKey(name: 'month') String? month,
@@ -16049,7 +16010,6 @@ class __$$ProfitSharingPeriodDtoImplCopyWithImpl<$Res>
Object? periodEnd = freezed,
Object? revenue = freezed,
Object? orderCount = freezed,
Object? limitPurchase = freezed,
Object? sdl = freezed,
Object? limitTeam = freezed,
Object? month = freezed,
@@ -16073,10 +16033,6 @@ class __$$ProfitSharingPeriodDtoImplCopyWithImpl<$Res>
? _value.orderCount
: orderCount // ignore: cast_nullable_to_non_nullable
as num?,
limitPurchase: freezed == limitPurchase
? _value.limitPurchase
: limitPurchase // ignore: cast_nullable_to_non_nullable
as num?,
sdl: freezed == sdl
? _value.sdl
: sdl // ignore: cast_nullable_to_non_nullable
@@ -16106,7 +16062,6 @@ class _$ProfitSharingPeriodDtoImpl extends _ProfitSharingPeriodDto {
@JsonKey(name: 'period_end') this.periodEnd,
@JsonKey(name: 'revenue') this.revenue,
@JsonKey(name: 'order_count') this.orderCount,
@JsonKey(name: 'limit_purchase') this.limitPurchase,
@JsonKey(name: 'sdl') this.sdl,
@JsonKey(name: 'limit_team') this.limitTeam,
@JsonKey(name: 'month') this.month,
@@ -16129,9 +16084,6 @@ class _$ProfitSharingPeriodDtoImpl extends _ProfitSharingPeriodDto {
@JsonKey(name: 'order_count')
final num? orderCount;
@override
@JsonKey(name: 'limit_purchase')
final num? limitPurchase;
@override
@JsonKey(name: 'sdl')
final num? sdl;
@override
@@ -16146,7 +16098,7 @@ class _$ProfitSharingPeriodDtoImpl extends _ProfitSharingPeriodDto {
@override
String toString() {
return 'ProfitSharingPeriodDto(periodStart: $periodStart, periodEnd: $periodEnd, revenue: $revenue, orderCount: $orderCount, limitPurchase: $limitPurchase, sdl: $sdl, limitTeam: $limitTeam, month: $month, weekCount: $weekCount)';
return 'ProfitSharingPeriodDto(periodStart: $periodStart, periodEnd: $periodEnd, revenue: $revenue, orderCount: $orderCount, sdl: $sdl, limitTeam: $limitTeam, month: $month, weekCount: $weekCount)';
}
@override
@@ -16161,8 +16113,6 @@ class _$ProfitSharingPeriodDtoImpl extends _ProfitSharingPeriodDto {
(identical(other.revenue, revenue) || other.revenue == revenue) &&
(identical(other.orderCount, orderCount) ||
other.orderCount == orderCount) &&
(identical(other.limitPurchase, limitPurchase) ||
other.limitPurchase == limitPurchase) &&
(identical(other.sdl, sdl) || other.sdl == sdl) &&
(identical(other.limitTeam, limitTeam) ||
other.limitTeam == limitTeam) &&
@@ -16179,7 +16129,6 @@ class _$ProfitSharingPeriodDtoImpl extends _ProfitSharingPeriodDto {
periodEnd,
revenue,
orderCount,
limitPurchase,
sdl,
limitTeam,
month,
@@ -16210,7 +16159,6 @@ abstract class _ProfitSharingPeriodDto extends ProfitSharingPeriodDto {
@JsonKey(name: 'period_end') final DateTime? periodEnd,
@JsonKey(name: 'revenue') final num? revenue,
@JsonKey(name: 'order_count') final num? orderCount,
@JsonKey(name: 'limit_purchase') final num? limitPurchase,
@JsonKey(name: 'sdl') final num? sdl,
@JsonKey(name: 'limit_team') final num? limitTeam,
@JsonKey(name: 'month') final String? month,
@@ -16234,9 +16182,6 @@ abstract class _ProfitSharingPeriodDto extends ProfitSharingPeriodDto {
@JsonKey(name: 'order_count')
num? get orderCount;
@override
@JsonKey(name: 'limit_purchase')
num? get limitPurchase;
@override
@JsonKey(name: 'sdl')
num? get sdl;
@override
@@ -1251,18 +1251,13 @@ Map<String, dynamic> _$$ProfitSharingBudgetDtoImplToJson(
_$ProfitSharingPercentageDtoImpl _$$ProfitSharingPercentageDtoImplFromJson(
Map<String, dynamic> json,
) => _$ProfitSharingPercentageDtoImpl(
purchase: json['purchase'] as num?,
owner: json['owner'] as num?,
team: json['team'] as num?,
);
Map<String, dynamic> _$$ProfitSharingPercentageDtoImplToJson(
_$ProfitSharingPercentageDtoImpl instance,
) => <String, dynamic>{
'purchase': instance.purchase,
'owner': instance.owner,
'team': instance.team,
};
) => <String, dynamic>{'owner': instance.owner, 'team': instance.team};
_$ProfitSharingPeriodDtoImpl _$$ProfitSharingPeriodDtoImplFromJson(
Map<String, dynamic> json,
@@ -1275,7 +1270,6 @@ _$ProfitSharingPeriodDtoImpl _$$ProfitSharingPeriodDtoImplFromJson(
: DateTime.parse(json['period_end'] as String),
revenue: json['revenue'] as num?,
orderCount: json['order_count'] as num?,
limitPurchase: json['limit_purchase'] as num?,
sdl: json['sdl'] as num?,
limitTeam: json['limit_team'] as num?,
month: json['month'] as String?,
@@ -1289,7 +1283,6 @@ Map<String, dynamic> _$$ProfitSharingPeriodDtoImplToJson(
'period_end': instance.periodEnd?.toIso8601String(),
'revenue': instance.revenue,
'order_count': instance.orderCount,
'limit_purchase': instance.limitPurchase,
'sdl': instance.sdl,
'limit_team': instance.limitTeam,
'month': instance.month,
@@ -1,6 +1,7 @@
import 'dart:developer';
import 'package:data_channel/data_channel.dart';
import 'package:dio/dio.dart' show Response;
import 'package:injectable/injectable.dart';
import '../../../common/api/api_client.dart';
@@ -291,7 +292,12 @@ class AnalyticRemoteDataProvider {
return DC.data(dto);
} on ApiFailure catch (e, s) {
log('fetchExclusiveSummaryError', name: _logName, error: e, stackTrace: s);
log(
'fetchExclusiveSummaryError',
name: _logName,
error: e,
stackTrace: s,
);
return DC.error(AnalyticFailure.serverError(e));
}
}
@@ -310,17 +316,18 @@ class AnalyticRemoteDataProvider {
};
if (outletId != null) params['outlet_id'] = outletId;
final response = await _apiClient.get(
ApiPath.parentCategoryAnalytic,
params: params,
headers: getAuthorizationHeader(),
);
final response = await _getProfitSharing('', params);
if (response.data['data'] == null) {
final failure = _profitSharingFailure(response);
if (failure != null) return DC.error(failure);
final body = response.data;
final data = body is Map ? body['data'] : null;
if (data == null) {
return DC.error(AnalyticFailure.empty());
}
final dto = ProfitSharingDto.fromJson(response.data['data']);
final dto = ProfitSharingDto.fromJson(data);
return DC.data(dto);
} on ApiFailure catch (e, s) {
@@ -342,17 +349,18 @@ class AnalyticRemoteDataProvider {
};
if (outletId != null) params['outlet_id'] = outletId;
final response = await _apiClient.get(
'${ApiPath.parentCategoryAnalytic}/$parentCategoryId',
params: params,
headers: getAuthorizationHeader(),
);
final response = await _getProfitSharing('/$parentCategoryId', params);
if (response.data['data'] == null) {
final failure = _profitSharingFailure(response);
if (failure != null) return DC.error(failure);
final body = response.data;
final data = body is Map ? body['data'] : null;
if (data == null) {
return DC.error(AnalyticFailure.empty());
}
final dto = ProfitSharingDetailDto.fromJson(response.data['data']);
final dto = ProfitSharingDetailDto.fromJson(data);
return DC.data(dto);
} on ApiFailure catch (e, s) {
@@ -365,4 +373,43 @@ class AnalyticRemoteDataProvider {
return DC.error(AnalyticFailure.serverError(e));
}
}
/// GET ke endpoint profit sharing. Selama backend lama masih jalan path baru
/// mengembalikan 404, jadi dicoba sekali lagi ke path lama.
Future<Response> _getProfitSharing(
String subPath,
Map<String, dynamic> params,
) async {
Future<Response> request(String basePath) => _apiClient.get(
'$basePath$subPath',
params: params,
headers: getAuthorizationHeader(),
// Status 5xx tidak dilempar supaya `cause` di body masih bisa dibaca.
validateStatus: (status) => status != null && status < 600,
);
final response = await request(ApiPath.profitSharingAnalytic);
if (response.statusCode != 404) return response;
return request(ApiPath.profitSharingAnalyticLegacy);
}
/// Failure dari status error endpoint profit sharing, null kalau berhasil.
/// Detail kategori non-team ditolak 500 dengan `cause` "... is not a team".
AnalyticFailure? _profitSharingFailure(Response response) {
final status = response.statusCode ?? 0;
if (status == 404) {
return const AnalyticFailure.serverError(ApiFailure.notFound(null));
}
if (status < 500) return null;
final body = response.data;
final errors = body is Map ? body['errors'] : null;
final isNotTeam =
errors is List &&
errors.any(
(e) => e is Map && '${e['cause']}'.contains('is not a team'),
);
if (isNotTeam) return const AnalyticFailure.notTeam();
return const AnalyticFailure.serverError(ApiFailure.internalServerError());
}
}
@@ -121,7 +121,6 @@ class ProfitSharingPercentageDto with _$ProfitSharingPercentageDto {
const ProfitSharingPercentageDto._();
const factory ProfitSharingPercentageDto({
@JsonKey(name: 'purchase') num? purchase,
@JsonKey(name: 'owner') num? owner,
@JsonKey(name: 'team') num? team,
}) = _ProfitSharingPercentageDto;
@@ -130,7 +129,6 @@ class ProfitSharingPercentageDto with _$ProfitSharingPercentageDto {
_$ProfitSharingPercentageDtoFromJson(json);
ProfitSharingPercentage toDomain() => ProfitSharingPercentage(
purchase: purchase?.toDouble() ?? 0,
owner: owner?.toDouble() ?? 0,
team: team?.toDouble() ?? 0,
);
@@ -145,7 +143,6 @@ class ProfitSharingPeriodDto with _$ProfitSharingPeriodDto {
@JsonKey(name: 'period_end') DateTime? periodEnd,
@JsonKey(name: 'revenue') num? revenue,
@JsonKey(name: 'order_count') num? orderCount,
@JsonKey(name: 'limit_purchase') num? limitPurchase,
@JsonKey(name: 'sdl') num? sdl,
@JsonKey(name: 'limit_team') num? limitTeam,
@JsonKey(name: 'month') String? month,
@@ -161,7 +158,6 @@ class ProfitSharingPeriodDto with _$ProfitSharingPeriodDto {
periodEnd: periodEnd?.toLocal() ?? DateTime.fromMillisecondsSinceEpoch(0),
revenue: revenue?.toInt() ?? 0,
orderCount: orderCount?.toInt() ?? 0,
limitPurchase: limitPurchase?.toInt() ?? 0,
sdl: sdl?.toInt() ?? 0,
limitTeam: limitTeam?.toInt() ?? 0,
month: month ?? '',