Skip to content

Commit

Permalink
Merge pull request #18 from lakasir/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheenazien8 authored Jun 19, 2024
2 parents 63f4be5 + b022c86 commit 6d9d8f1
Show file tree
Hide file tree
Showing 50 changed files with 1,515 additions and 2,543 deletions.
1 change: 0 additions & 1 deletion lib/api/api_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:lakasir/Exceptions/unauthenticated.dart';
Expand Down
11 changes: 10 additions & 1 deletion lib/api/requests/payment_request.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class PaymentRequest {
double? payedMoney;
double discountPrice;
bool? friendPrice;
int? memberId;
double? tax;
Expand All @@ -13,13 +14,15 @@ class PaymentRequest {
this.memberId,
this.tax,
this.note,
this.discountPrice = 0,
});

Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['payed_money'] = payedMoney;
data['friend_price'] = friendPrice;
data['note'] = note;
data['discount_price'] = discountPrice;
if (memberId != null) data['member_id'] = memberId;
if (tax != null) data['tax'] = tax;
if (products != null) {
Expand All @@ -32,12 +35,18 @@ class PaymentRequest {
class PaymentRequestItem {
int? productId;
int? qty;
double discountPrice;

PaymentRequestItem({this.productId, this.qty});
PaymentRequestItem({
this.productId,
this.qty,
this.discountPrice = 0,
});

Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
data['product_id'] = productId;
data['discount_price'] = discountPrice;
data['qty'] = qty;
return data;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/api/requests/product_request.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:lakasir/utils/utils.dart';

class ProductRequest {
String? name;
String? categoryId;
Expand All @@ -11,7 +13,6 @@ class ProductRequest {
String? sku;
String? barcode;


ProductRequest({
this.name,
this.categoryId,
Expand Down Expand Up @@ -60,7 +61,9 @@ class ProductRequest {
if (unit != null) {
query.add('filter[unit]=$unit');
}
if (stock != null) {
query.add('filter[stock-gt]=$stock');
}
return query.join('&');
}
}

30 changes: 30 additions & 0 deletions lib/api/responses/notifications/notification_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:lakasir/api/responses/notifications/stock_runs_out_response.dart';

class NotificationResponse {
String? uuid;
String? type;
List<dynamic>? data;
String? createdAt;

NotificationResponse({
this.uuid,
this.type,
this.data,
this.createdAt,
});

factory NotificationResponse.fromJson(Map<String, dynamic> json) {
dynamic data;
if (json['type'] == 'App\\Notifications\\StockRunsOut') {
data = json['data'] != null
? (json['data'] as List).map((e) => StockRunsOut.fromJson(e)).toList()
: [];
}
return NotificationResponse(
uuid: json['id'],
type: json['type'],
data: data,
createdAt: json['created_at'],
);
}
}
22 changes: 22 additions & 0 deletions lib/api/responses/notifications/stock_runs_out_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class StockRunsOut {
int? id;
String? name;
String? stock;
String? route;

StockRunsOut({
this.id,
this.name,
this.stock,
this.route,
});

factory StockRunsOut.fromJson(Map<String, dynamic> json) {
return StockRunsOut(
id: json['id'],
name: json['name'],
stock: json['stock'],
route: json['route'],
);
}
}
4 changes: 4 additions & 0 deletions lib/api/responses/transactions/selling_detail.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:lakasir/api/responses/products/product_response.dart';
import 'package:lakasir/utils/utils.dart';

class SellingDetail {
int id;
int sellingId;
int productId;
double price;
double discountPrice;
int quantity;
ProductResponse? product;

Expand All @@ -14,6 +16,7 @@ class SellingDetail {
required this.productId,
required this.price,
required this.quantity,
required this.discountPrice,
this.product,
});

Expand All @@ -23,6 +26,7 @@ class SellingDetail {
sellingId: json['selling_id'],
productId: json['product_id'],
price: double.parse(json['price'].toString()),
discountPrice: double.parse(json['discount_price'].toString()),
quantity: json['qty'],
product: json['product'] != null
? ProductResponse.fromJson(json['product'])
Expand Down
45 changes: 10 additions & 35 deletions lib/controllers/notification_controller.dart
Original file line number Diff line number Diff line change
@@ -1,61 +1,36 @@
import 'dart:convert';

import 'package:get/get.dart';
import 'package:lakasir/models/lakasir_database.dart';
import 'package:lakasir/models/notification.dart';
import 'package:lakasir/api/responses/notifications/notification_response.dart';
import 'package:lakasir/services/notification_service.dart';
import 'package:lakasir/utils/utils.dart';

class NotificationController extends GetxController {
RxList<NotificationModel> notifications = <NotificationModel>[].obs;
RxList<NotificationResponse> notifications = <NotificationResponse>[].obs;
final NotificationService _notificationService = NotificationService();

void fetch() async {
var results = await LakasirDatabase().notification.fetch();
var response = await _notificationService.get();

notifications.assignAll(results);
notifications.value = response;
}

void create(NotificationRequest request) async {
NotificationModel notification = fillModel(request);

LakasirDatabase().notification.create(notification);

fetch();
}

void clear() async {
await LakasirDatabase().notification.clear();
await show('Notification cleared');
await _notificationService.clear();
fetch();
show('notification_cleared'.tr);
}

void delete(NotificationModel notification) async {
LakasirDatabase().notification.delete(notification);
void delete(NotificationResponse notification, int id) async {
await _notificationService.delete(notification, id);
fetch();
}

void createMany(List<NotificationRequest> request) {
for (var req in request) {
NotificationModel notification = fillModel(req);

LakasirDatabase().notification.create(notification);
}
fetch();
}

NotificationModel fillModel(NotificationRequest req) {
var notification = NotificationModel()
..title = req.title
..body = req.body
..data = req.data
..isReaded = false
..route = jsonEncode({
'route': '/menu/product/stock',
'arguments': req.data,
})
..createdAt = DateTime.now();

return notification;
}
}

class NotificationRequest {
Expand Down
50 changes: 39 additions & 11 deletions lib/controllers/transactions/cart_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ class CartController extends GetxController {
return false;
}

void addCartSession(CartSession cartSession) {
void addCartSession(CartSession cartSession, BuildContext context) {
cartSessions.value = cartSession;
Get.toNamed('/menu/transaction/cashier/cart');
if (!context.isPhone) {
Get.toNamed('/menu/transaction/cashier/payment');
} else {
Get.toNamed('/menu/transaction/cashier/cart');
}
}

void addToCart(CartItem cartItem) async {
Expand All @@ -65,11 +69,18 @@ class CartController extends GetxController {
Get.back();
}

void removeQty(CartItem cartItem) {
void calculateDiscountPrice(CartItem cartItem, double discountPrice) {
cartSessions.value.cartItems[cartSessions.value.cartItems.indexOf(cartItem)]
.discountPrice = discountPrice;
cartSessions.refresh();
}

void removeQty(CartItem cartItem, BuildContext context) {
if (cartItem.qty == 1) {
cartSessions.value.cartItems.remove(cartItem);
cartSessions.refresh();
if (cartSessions.value.cartItems.isEmpty) {
debug(context.isPhone);
if (cartSessions.value.cartItems.isEmpty && context.isPhone) {
Get.back();
}
return;
Expand Down Expand Up @@ -160,6 +171,7 @@ class CartController extends GetxController {

class CartSession {
double? totalPrice;
double discountPrice;
double? payedMoney;
MemberResponse? member;
int? customerNumber;
Expand All @@ -183,6 +195,7 @@ class CartSession {
this.paymentMethod,
this.customerNumber,
this.note,
this.discountPrice = 0,
required this.cartItems,
});

Expand All @@ -199,13 +212,15 @@ class CartSession {

double get getTotalPrice {
var tax = this.tax ?? 0;
return cartItems.fold(
0,
(previousValue, element) =>
previousValue +
(element.qty * element.product.sellingPrice!.toInt()) *
(1 + (tax / 100)),
);
double totalPrice = cartItems.fold(
0,
(previousValue, element) =>
previousValue +
(element.qty * element.product.sellingPrice!.toInt()) *
(1 + (tax / 100)));
totalPrice = totalPrice - getDiscountPrice;

return totalPrice;
}

double get getSubTotalPrice {
Expand All @@ -216,6 +231,13 @@ class CartSession {
);
}

double get getDiscountPrice {
return discountPrice +
cartItems.fold(0, (previousValue, element) {
return previousValue + element.discountPrice;
});
}

int get getTotalQty {
return cartItems.fold(
0,
Expand All @@ -239,10 +261,12 @@ class CartSession {
class CartItem {
ProductResponse product;
int qty;
double discountPrice;

CartItem({
required this.product,
required this.qty,
this.discountPrice = 0,
});

@override
Expand All @@ -266,4 +290,8 @@ class CartItem {
(product.sellingPrice! * qty).toDouble(),
);
}

String buildDiscountPerItem() {
return formatPrice(discountPrice);
}
}
Loading

0 comments on commit 6d9d8f1

Please sign in to comment.