option_pill.dart
parent
8b4379a495
commit
9486186973
|
|
@ -6,11 +6,13 @@ const String transactionColumnStatus = 'status';
|
|||
const String transactionColumnData = 'data';
|
||||
const String transactionColumnAppCompanyId = 'appCompanyId';
|
||||
const String transactionColumnCreatedAt = 'createdAt';
|
||||
const String transactionColumnUpdatedAt = 'updatedAt';
|
||||
|
||||
const int transactionTypeSell = 1;
|
||||
const int transactionTypeBuy = 2;
|
||||
|
||||
const int transactionStatusPrepare = 0;
|
||||
const int transactionStatusFinish = 7;
|
||||
|
||||
|
||||
class Transaction {
|
||||
|
|
@ -25,6 +27,7 @@ class Transaction {
|
|||
appCompanyId = map[transactionColumnAppCompanyId] as int;
|
||||
data = map[transactionColumnData] as String;
|
||||
createdAt = map[transactionColumnCreatedAt] as String;
|
||||
updatedAt = map[transactionColumnUpdatedAt] as String;
|
||||
}
|
||||
|
||||
int? id;
|
||||
|
|
@ -34,6 +37,7 @@ class Transaction {
|
|||
String? data;
|
||||
int? appCompanyId;
|
||||
String? createdAt;
|
||||
String? updatedAt;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
final Map<String, dynamic> map = <String, dynamic>{
|
||||
|
|
@ -43,6 +47,7 @@ class Transaction {
|
|||
transactionColumnData: data,
|
||||
transactionColumnAppCompanyId: appCompanyId,
|
||||
transactionColumnCreatedAt: createdAt,
|
||||
transactionColumnUpdatedAt: updatedAt,
|
||||
};
|
||||
if (id != null) {
|
||||
map[transactionColumnId] = id;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:satu/core/models/flow/sell_response.dart';
|
||||
import 'package:satu/core/utils/utils_parse.dart';
|
||||
|
||||
class TransactionData {
|
||||
|
|
@ -7,16 +8,23 @@ class TransactionData {
|
|||
contragentName = map['contragentName'] as String;
|
||||
card = map['card'] as double;
|
||||
nal = map['nal'] as double;
|
||||
sellResponse = map['sellResponse'] != null
|
||||
? SellResponse.fromMap(map['sellResponse'])
|
||||
: null;
|
||||
}
|
||||
|
||||
String contragentName = '';
|
||||
double card = 0;
|
||||
double nal = 0;
|
||||
double total = 0;
|
||||
SellResponse? sellResponse;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
final Map<String, dynamic> map = <String, dynamic>{
|
||||
'contragentName': contragentName,
|
||||
'card' : card,
|
||||
'nal' : nal,
|
||||
'card': card,
|
||||
'nal': nal,
|
||||
'sellResponse': sellResponse
|
||||
};
|
||||
return map;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
class TransactionState {
|
||||
String? uuid;
|
||||
String? contragentName = 'Частное лицо';
|
||||
String? sectionName = 'Основной';
|
||||
int? transactionId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ ThunkAction<AppState> addSellItem({required Good good, String? excise}) {
|
|||
}
|
||||
|
||||
if (transaction == null) {
|
||||
final DateTime now = DateTime.now();
|
||||
const uuidTool = Uuid();
|
||||
final String uuid = uuidTool.v4();
|
||||
final TransactionData transactionData = TransactionData();
|
||||
|
|
@ -88,7 +89,8 @@ ThunkAction<AppState> addSellItem({required Good good, String? excise}) {
|
|||
..status = transactionStatusPrepare
|
||||
..appCompanyId = appCompanyId
|
||||
..type = transactionTypeSell
|
||||
..createdAt = DateTime.now().toIso8601String()
|
||||
..createdAt = now.toIso8601String()
|
||||
..updatedAt = now.toIso8601String()
|
||||
..data = jsonEncode(transactionData.toMap());
|
||||
final int returnKey =
|
||||
await _dbService.insert(transactionTableName, transaction.toMap());
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:satu/core/base/base_service.dart';
|
||||
import 'package:satu/core/entity/transaction_entity.dart';
|
||||
import 'package:satu/core/models/entity_data/transaction_data.dart';
|
||||
import 'package:satu/core/models/flow/items_bean.dart';
|
||||
import 'package:satu/core/models/flow/operator_bean.dart';
|
||||
import 'package:satu/core/models/flow/product_dao.dart';
|
||||
import 'package:satu/core/models/flow/sell_request.dart';
|
||||
import 'package:satu/core/models/flow/sell_response.dart';
|
||||
import 'package:satu/core/models/flow/transaction_state.dart';
|
||||
import 'package:satu/core/redux/actions/sell_actions.dart';
|
||||
import 'package:satu/core/redux/state/sell_state.dart';
|
||||
import 'package:satu/core/redux/store.dart';
|
||||
import 'package:satu/core/utils/locator.dart';
|
||||
|
|
@ -23,40 +25,73 @@ class DataService extends BaseService {
|
|||
|
||||
final DialogService _dialogService = locator<DialogService>();
|
||||
|
||||
|
||||
|
||||
Future<bool> sellBtnHandler({double card = 0, double nal = 0}) async {
|
||||
Future<bool> sellBtnHandler(
|
||||
{double card = 0, double nal = 0, double total = 0}) async {
|
||||
final SellRequest request = SellRequest();
|
||||
final SellState sellState = Redux.store!.state.sellState!;
|
||||
final TransactionState transactionState = sellState.transactionState!;
|
||||
final List<ProductDao> items = sellState.items!;
|
||||
for(final ProductDao item in items){
|
||||
for (final ProductDao item in items) {
|
||||
request.items.add(_productToItemBean(item));
|
||||
}
|
||||
request.card = card;
|
||||
request.nal = nal;
|
||||
request.invoiceId = transactionState.uuid;
|
||||
request.section = 'section';
|
||||
request.contragent = 'contragent';
|
||||
final OperatorBean operator = OperatorBean()..name='operator'..code=1;
|
||||
request.section = transactionState.sectionName;
|
||||
request.contragent = transactionState.contragentName;
|
||||
final OperatorBean operator = OperatorBean()
|
||||
..name = 'operator'
|
||||
..code = 1;
|
||||
request.operator = operator;
|
||||
SellResponse response = await _api.sell(request);
|
||||
final String msg = '${response.operation} - ${response.message}';
|
||||
log.w(response.toJson());
|
||||
_dialogService.showDialog(description: msg);
|
||||
final SellResponse response = await _api.sell(request);
|
||||
if (response.operation == false) {
|
||||
_dialogService.showDialog(description: response.message);
|
||||
return false;
|
||||
}
|
||||
await _updateTransaction(
|
||||
transactionState: transactionState,
|
||||
total: total,
|
||||
card: card,
|
||||
nal: nal,
|
||||
sellResponse: response);
|
||||
|
||||
await Redux.store!.dispatch(loadSellData);
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> _updateTransaction(
|
||||
{required TransactionState transactionState,
|
||||
required double card,
|
||||
required double nal,
|
||||
required double total,
|
||||
SellResponse? sellResponse}) async {
|
||||
final Map<String, dynamic>? map = await _db.queryById(
|
||||
transactionTableName, transactionState.uuid,
|
||||
idColumnName: transactionColumnUuid);
|
||||
|
||||
final DateTime now = DateTime.now();
|
||||
final Transaction transaction = Transaction.fromMap(map!);
|
||||
final TransactionData data =
|
||||
TransactionData.fromMap(jsonDecode(transaction.data!));
|
||||
transaction.status = transactionStatusFinish;
|
||||
transaction.updatedAt = now.toIso8601String();
|
||||
data.sellResponse = sellResponse;
|
||||
data.contragentName = transactionState.contragentName ?? '';
|
||||
data.card = card;
|
||||
data.nal = nal;
|
||||
data.total = total;
|
||||
transaction.data = jsonEncode(data.toMap());
|
||||
await _db.update(transactionTableName, transaction.toMap());
|
||||
}
|
||||
|
||||
ItemBean _productToItemBean(ProductDao product) {
|
||||
final ItemBean item = ItemBean()
|
||||
..id = product.id
|
||||
..price = product.price
|
||||
..cnt = product.count
|
||||
..name = product.productName
|
||||
..excise = product.excise
|
||||
..articul = product.article?.toString();
|
||||
..price = product.price
|
||||
..cnt = product.count
|
||||
..name = product.productName
|
||||
..excise = product.excise
|
||||
..articul = product.article?.toString();
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ class DbService extends BaseService {
|
|||
$transactionColumnAppCompanyId integer not null,
|
||||
$transactionColumnStatus integer not null,
|
||||
$transactionColumnData text,
|
||||
$transactionColumnCreatedAt text not null
|
||||
$transactionColumnCreatedAt text not null,
|
||||
$transactionColumnUpdatedAt text not null
|
||||
);
|
||||
''');
|
||||
await db.execute('''
|
||||
|
|
@ -139,7 +140,7 @@ class DbService extends BaseService {
|
|||
return result;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> queryById(String table, int id,
|
||||
Future<Map<String, dynamic>?> queryById(String table, dynamic id,
|
||||
{String? idColumnName}) async {
|
||||
final Database db = await instance.database;
|
||||
final List<Map<String, dynamic>> result = await db
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class OptionPill extends StatelessWidget {
|
||||
|
||||
final String text;
|
||||
final bool selected;
|
||||
|
||||
OptionPill({required this.text, required this.selected});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
color: selected ? Colors.black : Colors.transparent,
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: selected ? Colors.white : Colors.grey[400],
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +1,67 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:satu/widgets/bar/products_app_bar.dart';
|
||||
|
||||
import 'component/custom_field.dart';
|
||||
import 'component/option_pill.dart';
|
||||
import 'package:satu/widgets/buttons/option_pill.dart';
|
||||
import 'component/transaction_item.dart';
|
||||
|
||||
|
||||
class JournalView extends StatelessWidget {
|
||||
class JournalView extends StatefulWidget {
|
||||
@override
|
||||
_JournalViewState createState() => _JournalViewState();
|
||||
}
|
||||
|
||||
class _JournalViewState extends State<JournalView> {
|
||||
|
||||
int tabIndex = 0;
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: ProductsAppBar(title: 'Журнал транзакции',),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 24),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
||||
// CustomField(
|
||||
// hintText: "Name, Email or Mobile number",
|
||||
// iconData: Icons.search,
|
||||
// ),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
OptionPill(
|
||||
text: 'Все',
|
||||
selected: tabIndex == 0,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
tabIndex = 0;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
OptionPill(
|
||||
text: "Все",
|
||||
selected: true,
|
||||
),
|
||||
OptionPill(
|
||||
text: 'Приход',
|
||||
selected: tabIndex == 1,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
tabIndex = 1;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
OptionPill(
|
||||
text: "Приход",
|
||||
selected: false,
|
||||
),
|
||||
OptionPill(
|
||||
text: 'Расход',
|
||||
selected: tabIndex == 2,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
tabIndex = 2;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
OptionPill(
|
||||
text: "Расход",
|
||||
selected: false,
|
||||
),
|
||||
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
|
|
@ -60,7 +80,7 @@ class JournalView extends StatelessWidget {
|
|||
),
|
||||
|
||||
Text(
|
||||
"03/06/2020",
|
||||
'03/06/2020',
|
||||
style: TextStyle(
|
||||
//color: kGreyColor,
|
||||
fontSize: 14,
|
||||
|
|
@ -73,16 +93,16 @@ class JournalView extends StatelessWidget {
|
|||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 52021 13:03:05",
|
||||
status: "Частное лицо",
|
||||
amount: "2706.00",
|
||||
fullName: 'Чек № 52021 13:03:05',
|
||||
status: 'Частное лицо',
|
||||
amount: '2706.00',
|
||||
received: true,
|
||||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 52020 13:01:05",
|
||||
status: "ИП Иванов В.И.",
|
||||
amount: "19000.63",
|
||||
fullName: 'Чек № 52020 13:01:05',
|
||||
status: 'ИП Иванов В.И.',
|
||||
amount: '19000.63',
|
||||
received: false,
|
||||
),
|
||||
|
||||
|
|
@ -101,7 +121,7 @@ class JournalView extends StatelessWidget {
|
|||
),
|
||||
|
||||
Text(
|
||||
"02/06/2020",
|
||||
'02/06/2020',
|
||||
style: TextStyle(
|
||||
//color: kGreyColor,
|
||||
fontSize: 14,
|
||||
|
|
@ -114,16 +134,16 @@ class JournalView extends StatelessWidget {
|
|||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 5019 13:03:05",
|
||||
status: "Частное лицо",
|
||||
amount: "114.00",
|
||||
fullName: 'Чек № 5019 13:03:05',
|
||||
status: 'Частное лицо',
|
||||
amount: '114.00',
|
||||
received: true,
|
||||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 5019 13:03:05",
|
||||
status: "Частное лицо",
|
||||
amount: "70.16",
|
||||
fullName: 'Чек № 5019 13:03:05',
|
||||
status: 'Частное лицо',
|
||||
amount: '70.16',
|
||||
received: true,
|
||||
),
|
||||
|
||||
|
|
@ -132,7 +152,7 @@ class JournalView extends StatelessWidget {
|
|||
),
|
||||
|
||||
Text(
|
||||
"29/05/2020",
|
||||
'29/05/2020',
|
||||
style: TextStyle(
|
||||
//color: kGreyColor,
|
||||
fontSize: 14,
|
||||
|
|
@ -145,44 +165,44 @@ class JournalView extends StatelessWidget {
|
|||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 5019 13:03:05",
|
||||
status: "Частное лицо",
|
||||
amount: "44.50",
|
||||
fullName: 'Чек № 5019 13:03:05',
|
||||
status: 'Частное лицо',
|
||||
amount: '44.50',
|
||||
received: true,
|
||||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 5019 13:03:05",
|
||||
status: "ТОО Рога и копыта",
|
||||
amount: "85.50",
|
||||
fullName: 'Чек № 5019 13:03:05',
|
||||
status: 'ТОО Рога и копыта',
|
||||
amount: '85.50',
|
||||
received: false,
|
||||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 5019 13:03:05",
|
||||
status: "Частное лицо",
|
||||
amount: "155.00",
|
||||
fullName: 'Чек № 5019 13:03:05',
|
||||
status: 'Частное лицо',
|
||||
amount: '155.00',
|
||||
received: true,
|
||||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 5019 13:03:05",
|
||||
status: "Частное лицо",
|
||||
amount: "23.50",
|
||||
fullName: 'Чек № 5019 13:03:05',
|
||||
status: 'Частное лицо',
|
||||
amount: '23.50',
|
||||
received: true,
|
||||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 5019 13:03:05",
|
||||
status: "Частное лицо",
|
||||
amount: "11.50",
|
||||
fullName: 'Чек № 5019 13:03:05',
|
||||
status: 'Частное лицо',
|
||||
amount: '11.50',
|
||||
received: true,
|
||||
),
|
||||
|
||||
TransactionItem(
|
||||
fullName: "Чек № 5019 13:03:05",
|
||||
status: "Частное лицо",
|
||||
amount: "36.00",
|
||||
fullName: 'Чек № 5019 13:03:05',
|
||||
status: 'Частное лицо',
|
||||
amount: '36.00',
|
||||
received: true,
|
||||
),
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:satu/core/redux/state/sell_state.dart';
|
||||
import 'package:satu/core/redux/store.dart';
|
||||
import 'package:satu/core/services/navigator_service.dart';
|
||||
import 'package:satu/core/utils/locator.dart';
|
||||
import 'package:satu/core/utils/utils_parse.dart';
|
||||
import 'package:satu/shared/app_colors.dart';
|
||||
|
|
@ -23,9 +24,10 @@ class PaymentView extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _PaymentViewState extends State<PaymentView> {
|
||||
DataService _dataService = locator<DataService>();
|
||||
final DataService _dataService = locator<DataService>();
|
||||
final NavigatorService _navigatorService = locator<NavigatorService>();
|
||||
|
||||
bool combine = true;
|
||||
bool combine = false;
|
||||
late double _sum;
|
||||
double _bankSum = 0;
|
||||
double _cashSum = 0;
|
||||
|
|
@ -133,18 +135,7 @@ class _PaymentViewState extends State<PaymentView> {
|
|||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 45, vertical: 30),
|
||||
child: BusyButton(
|
||||
title: 'ОПЛАТА',
|
||||
busy: loading,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
loading = true;
|
||||
});
|
||||
_dataService.sellBtnHandler(
|
||||
card: _bankSum, nal: _cashSum);
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}),
|
||||
title: 'ОПЛАТА', busy: loading, onPressed: _payment),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
@ -152,6 +143,34 @@ class _PaymentViewState extends State<PaymentView> {
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> _payment() async {
|
||||
setState(() {
|
||||
loading = true;
|
||||
});
|
||||
|
||||
double card = 0;
|
||||
double nal = 0;
|
||||
if (combine == false) {
|
||||
if (isCard) {
|
||||
card = _sum;
|
||||
} else {
|
||||
nal = _sum;
|
||||
}
|
||||
} else {
|
||||
card = _bankSum;
|
||||
nal = _cashSum;
|
||||
}
|
||||
|
||||
bool result =
|
||||
await _dataService.sellBtnHandler(card: card, nal: nal, total: _sum);
|
||||
if(result) {
|
||||
_navigatorService.pop();
|
||||
}
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
Column buildPaymentSelect() {
|
||||
if (combine) {
|
||||
return Column(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:satu/shared/app_colors.dart';
|
||||
import 'package:satu/shared/shared_styles.dart';
|
||||
|
||||
|
||||
class OptionPill extends StatelessWidget {
|
||||
|
||||
const OptionPill({required this.text, required this.selected, this.onTap});
|
||||
|
||||
final String text;
|
||||
final bool selected;
|
||||
final Function()? onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(5),
|
||||
),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 100.0
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 7, horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: !selected ? null : primaryGradient,
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(5),
|
||||
),
|
||||
color: selected ? Colors.black : Colors.transparent,
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: selected ? blackColor : placeholderColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue