NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

// ignore_for_file: use_build_context_synchronously, unnecessary_set_literal

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:store_app/constants.dart';
import 'package:store_app/models/sap_census_sqlite/iitem_barcode_id.dart';
import 'package:store_app/models/sap_census_sqlite/sap_census_barcode_modal.dart';
import 'package:store_app/models/sap_census_sqlite/sap_census_model.dart';
import 'package:store_app/models/sap_purchase_servise/service_nomin.dart';
import 'package:store_app/models/sap_purchase_servise/service_pi_read.dart';
import 'package:store_app/provider/common.dart';
import 'package:store_app/repos/sap_census_barcode_helper.dart';
import 'package:store_app/repos/sap_census_helper.dart';
import 'package:store_app/repos/sap_census_id_helper.dart';
import 'package:store_app/screens/sap_pruchase_screen/pi_barcode_widget.dart';
import 'package:store_app/screens/sap_pruchase_screen/sap_purchase_menu.dart';
import 'package:store_app/utils/utils.dart';
import 'package:store_app/widgets/bottom_sheet_page.dart';
import 'package:store_app/widgets/customkeyboard/custom_keyboard.dart';
import 'package:store_app/models/sap_purchase_servise/service_pi_save.dart'
as service_pi_save;
import 'package:store_app/widgets/global_keys.dart';
import 'census_damage.dart';
import 'package:store_app/models/sap_purchase_servise/service_pi_read.dart'
as service_pi_read;
import 'package:store_app/models/sap_purchase_servise/service_nomin.dart'
as service_nomin;

// @author Mungunerdene
class SapCensusHome extends StatefulWidget {
final String documentNumber;
const SapCensusHome({super.key, required this.documentNumber});

@override
State<SapCensusHome> createState() => _SapCensusHomeState();
}

class _SapCensusHomeState extends State<SapCensusHome> {
final _barCodeController = TextEditingController();
service_pi_read.ZnmmmfmMatphysinvPostingResponse? _pi;
service_pi_read.ZnmmmfmMatphysinvPostingResponse? _piAll;
bool isLoading = false;
final SapCensusBarCodeHelper censusNominBarCodeHelper =
SapCensusBarCodeHelper(); // Nomin barcode
final SapCensusIdHelper censusSapBarCOdeHelper =
SapCensusIdHelper(); // sap barcode --
String loginName = Provider.of<CommonProvider>(
GlobalKeys.navigatorKey.currentContext!,
listen: false)
.userInfo!
.loginName ??
'';

@override
void initState() {
getSapDataFunction();
super.initState();
}

getSapDataFunction() async {
// MM012-аас дата авчирах
try {
setState(() {
isLoading = true;
});
// all pi doc
_piAll = await service_pi_read.readPIDocument(
"", widget.documentNumber, "", "");
_pi = await service_pi_read.readPIDocument(
"", widget.documentNumber, "", "");
if (_pi!.iitembarcode == null) {
IItembarcode iItembarcode = IItembarcode(
itemBarcode: [],
);
_pi!.iitembarcode = iItembarcode;
}
List<IItemBarcodeId> selectBarCodes = await censusSapBarCOdeHelper
.selectSapCensusIdItems(widget.documentNumber);
if (selectBarCodes.isNotEmpty) {
_pi!.iitembarcode!.itemBarcode = [];
}
if (_pi!.ereturn!.status == "E") {
Utils.showSnackBar(
context, "${_pi!.ereturn!.messageText}", "Алдаа", kRedColor, 4);
Navigator.pop(context);
return;
}

// nomin service --------------------------------
final dio = Dio(BaseOptions(contentType: "application/json"));
service_nomin.RestClient client =
service_nomin.RestClient(dio, baseUrl: serviceGoodsMovementBaseUrl);
final List<String> itemIds = [];
GetSapPriceResponse sapPriceResponse;
String locationKey = Provider.of<CommonProvider>(
GlobalKeys.navigatorKey.currentContext!,
listen: false)
.location
?.locationKey ??
'';

for (var tmp in _pi?.iitem?.items ?? []) {
itemIds.add(tmp.matnr);
}

final payload = {"itemId": itemIds, "location": locationKey};
sapPriceResponse = await client.getSapPrice(payload);
print(sapPriceResponse.toString());

List<SapCensusBarcodeModel> censusBarCodeModels = [];
for (var tmp in sapPriceResponse.list!) {
_pi!.iitem!.items!
.where((element) => element.matnr == tmp.itemId)
.forEach((element) {
element.cost = tmp.purchasePrice ?? "0.0";
element.price = tmp.salePrice ?? "0.0";
element.barCodeId = tmp.barCodeIds;
});
// Nomin barcode sqlLite hadgalah
for (var data in tmp.barCodeIds) {
SapCensusBarcodeModel modal = SapCensusBarcodeModel(
barcodeId: data.barCodeID,
qty: 0,
itemId: tmp.itemId,
documentNumber: widget.documentNumber);
censusBarCodeModels.add(modal);
}
}
// Nomin barcode sqlLite hadgalah
List<SapCensusBarcodeModel> selectBarCode = await censusNominBarCodeHelper
.selectSapCensusBarCodeItems(widget.documentNumber);
if (selectBarCode.isEmpty) {
await censusNominBarCodeHelper
.insertSapCensusBarcodeItems(censusBarCodeModels);
}
setSqlLite(sapPriceResponse.list!);
} catch (ex) {
Utils.showSnackBar(context, '$ex', "Алдаа гарсан", kRedColor, 2);
Navigator.pop(context);
} finally {
List<IItemBarcodeId> selectBarCodes = await censusSapBarCOdeHelper
.selectSapCensusIdItems(widget.documentNumber);
if (selectBarCodes.isEmpty) {
setState(() {
isLoading = false;
});
}
}
}

void setSqlLite(List<SapPriceList> sapPriceLists) async {
List<IItemBarcodeId> selectBarCodes = await censusSapBarCOdeHelper
.selectSapCensusIdItems(widget.documentNumber);
List<IItemBarcodeId> itemBarCodes = [];

if (selectBarCodes.isEmpty) {
for (var tmp in _pi?.iitembarcode?.itemBarcode ?? []) {
IItemBarcodeId iItemBarcodeId = IItemBarcodeId(
ean11: tmp.ean11,
gjahr: formatterYear,
matnr: tmp.matnr,
zeili: tmp.zeili,
znMenge: "1",
documentNumber: widget.documentNumber,
zuname: loginName,
);
itemBarCodes.add(iItemBarcodeId);
}
await censusSapBarCOdeHelper.insertSapCensusIdItems(itemBarCodes);
} else {
for (var tmp in selectBarCodes) {
IItemItemBarcode itemBarCode = IItemItemBarcode(
ean11: tmp.ean11,
gjahr: tmp.gjahr,
iblnr: tmp.iblnr,
matnr: tmp.matnr,
menge: tmp.menge,
zeili: tmp.zeili,
znMenge: tmp.znMenge,
zuname: tmp.zuname,
info: tmp.itemInfo);
_pi?.iitembarcode?.itemBarcode?.add(itemBarCode);
// znMenge, zdMenge бодох

_pi!.iitem!.items!
.where((element) => tmp.matnr == element.matnr)
.forEach((element) {
element.znMenge = "0";
element.barcodeQty = (double.parse(element.barcodeQty ?? "0") +
double.parse(tmp.znMenge ?? "0"))
.toString();
element.menge = (double.parse(element.barcodeQty ?? "0") +
double.parse(element.zdMenge ?? "0"))
.toString();
});
}
setState(() {
isLoading = false;
});
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: BackButton(
onPressed: () {
Navigator.pop(context);
},
),
backgroundColor: kPrimaryColor,
title: const Text("Тооллого scan"),
actions: [
PopupMenuButton<String>(
onSelected: (String? value) async {
if (value == null) return; // Add null check to handle null value
try {
// Your existing code inside onSelected callback
final service_pi_save.ZnmmmfmMatphysinvCount iitems =
service_pi_save.ZnmmmfmMatphysinvCount();
iitems.iitem ??= service_pi_save.IItem(items: []);
// ------------------------
final service_pi_save.ZnmmmfmMatphysinvCount defectiveItems =
service_pi_save.ZnmmmfmMatphysinvCount();
defectiveItems.iitemDefective ??=
service_pi_save.IItemDefective(items: []);
// -----------------
final service_pi_save.ZnmmmfmMatphysinvCount barcodeSendItems =
service_pi_save.ZnmmmfmMatphysinvCount();
barcodeSendItems.iitembarcode ??=
service_pi_save.IItembarcode(items: []);

String piDocumentNumber = _pi!.iitem!.items!.first.iblnr!;
final now = DateTime.now();
String formatterYear = DateFormat('yyyy').format(now);

// ------------------------------------------------- service iitems
for (var tmp in _pi!.iitem!.items ?? []) {
String? menge = "0";
var formatNumber = NumberFormat("###0.00", "en_US")
.format(double.parse(tmp.cost ?? "0.00"));
var formatNumberPrice = NumberFormat("###0.00", "en_US")
.format(double.parse(tmp.price ?? "0.00"));

menge = (_pi!.iitembarcode != null
? (double.parse(tmp.barcodeQty ?? '0') +
double.parse(tmp.zdMenge ?? '0'))
.toString()
: (double.parse(tmp.znMenge ?? '0') +
double.parse(tmp.zdMenge ?? '0'))
.toString());

iitems.iitem?.items?.add(service_pi_save.IItemItem(
meins: tmp.meins,
menge: menge,
xnull: menge != "0.0" ? "" : "X",
zdMenge: tmp.zdMenge ?? "0.00",
zeili: tmp.zeili,
znMenge: _pi!.iitembarcode != null
? tmp.barcodeQty ??= "0.0"
: tmp.znMenge ??= "0.0",
cost: formatNumber,
price: formatNumberPrice,
zuname: menge == "0.0" ? "" : loginName,
salesVal: "0"));

// defect ----------
if (tmp.dmgTime != null && tmp.dmgTime != "0.0") {
defectiveItems.iitemDefective!.items!.add(
service_pi_save.IItemDefectiveItem(
zeili: tmp.zeili,
meins: tmp.meins,
xnull: "",
zdMenge: tmp.dmgTime ?? "0.00",
zdRs: "101",
zrn: "01",
salesVal: "0.00"));
}
if (tmp.dmgPhysical != null && tmp.dmgPhysical != "0.0") {
defectiveItems.iitemDefective!.items!.add(
service_pi_save.IItemDefectiveItem(
zeili: tmp.zeili,
meins: tmp.meins,
xnull: "",
zdMenge: tmp.dmgPhysical ?? "0.00",
zdRs: "102",
zrn: "02",
salesVal: "0.00"));
}
if (tmp.dmgPackage != null && tmp.dmgPackage != "0.0") {
defectiveItems.iitemDefective!.items!.add(
service_pi_save.IItemDefectiveItem(
zeili: tmp.zeili,
meins: tmp.meins,
xnull: "",
zdMenge: tmp.dmgPackage ?? "0.00",
zdRs: "103",
zrn: "03",
salesVal: "0.00"));
}
if (tmp.dmgShortage != null && tmp.dmgShortage != "0.0") {
defectiveItems.iitemDefective!.items!.add(
service_pi_save.IItemDefectiveItem(
zeili: tmp.zeili,
meins: tmp.meins,
xnull: "",
zdMenge: tmp.dmgShortage ?? "0.00",
zdRs: "104",
zrn: "04",
salesVal: "0.00"));
}
}

// barcode -----------
for (var item in _pi?.iitembarcode?.itemBarcode ?? []) {
barcodeSendItems.iitembarcode?.items?.add(
service_pi_save.IItembarcodeItem(
iblnr: _pi!.iitem!.items!.first.iblnr!,
gjahr: "2024",
zeili: item.zeili,
ean11: item.ean11,
zuname: item.znMenge == null ? "" : loginName,
matnr: item.matnr,
menge: item.znMenge,
znMenge: item.znMenge));
}

var response = await service_pi_save.savePIDocument(
piDocumentNumber,
iitems.iitem!.items!,
barcodeSendItems.iitembarcode!.items!,
defectiveItems.iitemDefective!.items!,
loginName,
formatterYear);

if (response == null) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text("Тооллого илгээхэд алдаа гарлаа")));
return;
}

if (response.ereturn == null ||
response.ereturn!.status != "S") {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"Тооллого илгээхэд алдаа гарлаа: ${response.ereturn!.messageText}")));
return;
}
setState(() {
print(
"************************response*******************************");
print(response.ereturn!.messageText!);
success(response.ereturn!.messageText!);
});
} catch (ex) {
Utils.showSnackBar(
context,
"$ex Алдаа гарсан байна!!!",
"Анхаар",
kRedColor,
4,
);
print(ex);
}
},
itemBuilder: (BuildContext context) => [
const PopupMenuItem<String>(
value: 'perform_purchase_order',
child: Row(
children: [
Icon(
Icons.send,
color: kPrimaryColor,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 5),
child: Text('илгээх'),
)
],
),
),
],
)
],
),
floatingActionButton: FloatingActionButton(
backgroundColor: kPrimaryColor,
child: const Icon(Icons.barcode_reader),
onPressed: () async {
String barcode = await FlutterBarcodeScanner.scanBarcode(
"#ff6666", "Цуцлах", true, ScanMode.BARCODE);
if (barcode.contains("]C1")) {
barcode = barcode.substring(3, barcode.length);
}
// Бар кодоор унших function
getBarCodeId(barcode);
},
),
body: isLoading == true
? const Center(
child: CircularProgressIndicator(),
)
: Column(
children: [
searchBarcodeAndItemId(),
content(),
],
),
);
}

Widget searchBarcodeAndItemId() {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Card(
elevation: 0,
child: TextFormField(
onEditingComplete: () {
// _getBarCodeId(_barCodeController.text);
// _barCodeController.clear();
},
autofocus: true,
controller: _barCodeController,
maxLength: 100,
decoration: InputDecoration(
icon: IconButton(
icon: const FaIcon(FontAwesomeIcons.barcode),
onPressed: () {
// searchValue("");
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (context) {
return BottomSheetPage(
labelText: "хайх",
helperText: "Бар кодоо бичнэ үү",
buttonHandler: searchValue);
},
);
},
),
labelText: "Баркод & дотоод ",
labelStyle: const TextStyle(
color: kTextColor,
),
suffixIcon: IconButton(
onPressed: () {
getBarCodeId(_barCodeController.text);
_barCodeController.clear();
},
icon: const Icon(Icons.send)),
),
),
),
);
}

Widget content() {
return Expanded(
child: ListView.builder(
itemCount: _pi!.iitem!.items!.length,
itemBuilder: (context, index) {
// size = MEd
return Container(
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: _pi!.iitem!.items![index].tileColor == true
? kGreenColor
: kWhiteColor,
borderRadius: BorderRadius.circular(10)),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
_pi!.iitem!.items![index].maktx,
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.w500),
),
),
IconButton.outlined(
onPressed: () {
// defect(index);
defectBottomSheetButton(
context, _pi!.iitem!.items![index], index);
},
icon: const Icon(
Icons.more_vert,
color: kPrimaryColor,
))
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
color: kPrimaryColor),
child: Row(children: [
const Icon(
Icons.numbers,
size: 16,
color: Colors.white,
),
Text(
_pi!.iitem!.items![index].matnr,
style: const TextStyle(color: Colors.white),
),
]),
),
Row(
children: [
Text(
"menge: ",
style: TextStyle(
color: _pi!.iitem!.items![index].tileColor == true
? kWhiteColor
: kTextColor,
),
),
// scanned by barcode
Text(
_pi!.iitem!.items![index].menge ?? "0.0",
style: TextStyle(
color: _pi!.iitem!.items![index].tileColor == true
? kYellowColor
: kGreenColor,
),
)
],
)
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
"zdMenge: ",
style: TextStyle(
color: _pi!.iitem!.items![index].tileColor == true
? kWhiteColor
: kTextColor,
),
),
Text(
_pi!.iitem!.items![index].zdMenge ?? "0.0",
style: TextStyle(
color: _pi!.iitem!.items![index].tileColor == true
? kWhiteColor
: kGreenColor,
),
),
],
),
const SizedBox(
height: 3,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
style: TextStyle(
color: _pi!.iitem!.items![index].tileColor == true
? kWhiteColor
: kGreenColor,
fontSize: 20),
NumberFormat.currency(locale: 'mn', decimalDigits: 2)
.format(double.parse(
_pi!.iitem!.items![index].price ?? "0.00")),
)
],
),
Row(
children: [
Text(
"znMenge: ",
style: TextStyle(
color: _pi!.iitem!.items![index].tileColor == true
? kWhiteColor
: kTextColor,
),
),
Text(
'${(double.parse(_pi!.iitem!.items![index].znMenge?.padLeft(2, '0') ?? "0")) + (double.parse(_pi!.iitem!.items![index].barcodeQty ?? "0"))}',
style: TextStyle(
color: _pi!.iitem!.items![index].tileColor == true
? kWhiteColor
: kGreenColor,
),
),
],
)
],
),
// _pi!.iitembarcode == null
// ? Container()
// :
Text("${_pi?.iitembarcode?.itemBarcode}"),
_pi!.iitembarcode == null
? Container()
: _pi?.iitembarcode?.itemBarcode
?.where((element) =>
element.matnr ==
_pi!.iitem!.items![index].matnr)
.toList()
.isEmpty ??
true
? Container()
: barcodeReadButton(index)
],
),
);
},
));
}

// -------------------barcode Reader------
Widget barcodeReadButton(int index) {
// Баркод уншсан хэсэг харах function
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton.icon(
onPressed: () {
customModalBottomSheet(context,
child: BarCodeWidget(
bacodeList: _pi!.iitembarcode!.itemBarcode!
.where((element) =>
element.matnr == _pi!.iitem!.items![index].matnr)
.toList(),
updateItemBarcode: saveFunction,
index: index,
));
},
icon: const Icon(Icons.barcode_reader),
label: const Text("scanned by barcode"))
],
);
}

saveFunction(List<IItemItemBarcode> iItemItemBarcode, int index) async {
// print("баркод хадгалах");
_pi!.iitem!.items![index].barcodeQty = "0";
_pi!.iitem!.items![index].znMenge = "0";
_pi!.iitem!.items![index].menge = "0";
for (var tmp in iItemItemBarcode) {
_pi!.iitem!.items![index].barcodeQty =
(double.parse(_pi!.iitem!.items![index].barcodeQty ?? "0") +
double.parse(tmp.znMenge ?? "0"))
.toString();
// --------------------- нийт тоо олгох
_pi!.iitem!.items![index].menge =
(double.parse(_pi!.iitem!.items![index].barcodeQty ?? "0") +
double.parse(_pi!.iitem!.items![index].zdMenge ?? "0"))
.toString();
// sqlLite utga hadgalah eswel zasah
List<IItemBarcodeId> iitemBarCodeId = await censusSapBarCOdeHelper
.selectSapCensusIdItems(widget.documentNumber);
if (iitemBarCodeId.isNotEmpty) {
for (var item in iitemBarCodeId) {
if (item.ean11 == tmp.ean11) {
item.znMenge = double.parse(tmp.znMenge!).toString();
item.itemInfo = tmp.info;
await censusSapBarCOdeHelper
.updateSapCensusItemByBarcodeIdANDdocument(item);
}
}
}
setState(() {});
}
}

Future<dynamic> customModalBottomSheet(
BuildContext context, {
bool isDismissible = false,
double? height,
VoidCallback? closeEvent,
required Widget child,
}) {
return showModalBottomSheet(
context: context,
clipBehavior: Clip.hardEdge,
isScrollControlled: true,
isDismissible: isDismissible,
enableDrag: isDismissible,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10 * 2),
topRight: Radius.circular(10 * 2),
),
),
builder: (context) => SizedBox(
height: height ?? MediaQuery.of(context).size.height * 0.75,
child: child,
),
);
}

// -------------------------defect button---------------
defectBottomSheetButton(
BuildContext context, service_pi_read.IItemItem iItemItem, int index) {
// Defect Бараа гараас оруулах дуудах
showModalBottomSheet(
enableDrag: false,
isDismissible: false,
useRootNavigator: true,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),
)),
context: context,
builder: (context) {
return SapCensusDmgSheet(
dPackageQty: iItemItem.dmgPackage ?? "",
dPhysicalQty: iItemItem.dmgPhysical ?? "",
dShortageQty: iItemItem.dmgShortage ?? "",
dTimeQty: iItemItem.dmgTime ?? "",
buttonHandler: _getDamagedQty,
index: index);
});
}

// defect барааны ширхэг хадгалах function
void _getDamagedQty(int index, double timeQty, double physicalQty,
double packageQty, double shortageQty) async {
double damageQty = timeQty + physicalQty + packageQty + shortageQty;
_pi!.iitem!.items![index].zdMenge = damageQty.toString();
_pi!.iitem!.items![index].dmgTime = timeQty.toString();
_pi!.iitem!.items![index].dmgPhysical = physicalQty.toString();
_pi!.iitem!.items![index].dmgPackage = packageQty.toString();
_pi!.iitem!.items![index].dmgShortage = shortageQty.toString();
_pi!.iitem!.items![index].zdRs = "reason";
_pi!.iitem!.items![index].menge =
(double.parse(_pi!.iitem!.items![index].menge ?? "0") + damageQty)
.toString();
setState(() {});
// SapCensusModel model = SapCensusModel(
// piNumber: item[index].iblnr,
// matnr: item[index].matnr,
// zdMenge: item[index].zdMenge,
// normalQty: item[index].znMenge,
// totalQty: item[index].menge,
// timeQty: item[index].dmgTime,
// physicalQty: item[index].dmgPhysical,
// packageQty: item[index].dmgPackage,
// documentNumber: widget.documentNumber,
// info: item[index].info,
// shortageQty: item[index].dmgShortage,
// );
// await censusHelper.updateSapCensusItemByBarcodeANDdocument(model);
}

// хайх баркод болон нэрээр
void searchValue(String value) {
setState(() {
// _piAll!.iitem!.items = _pi!.iitem!.items;
if (value.isEmpty) {
_pi!.iitem!.items = _piAll!.iitem!.items!;
} else {
value = value.toLowerCase();
_pi!.iitem!.items = _piAll!.iitem!.items!
.where((element) =>
element.maktx.toLowerCase().contains(value) ||
element.matnr.toLowerCase().contains(value))
.toList();
}
});
}

void getBarCodeId(String barCode) async {
// bool isBarcode = false;
// for (var item in _pi!.iitembarcode!.itemBarcode!) {
// print("barcode : ${item.ean11}");
// }8714800003124

final filterBarcode = _pi?.iitembarcode?.itemBarcode
?.where((element) => element.ean11 == barCode) ??
[];
// filteredItem.first.tileColor = true;
// if (filterBarcode.isEmpty) {
// Utils.showSnackBar(
// context,
// "Зөвхөн documentNumber - т байгаа барааг л уншуулна уу?",
// "Санамж",
// kRedColor,
// 2);
// return;
// }
if (filterBarcode.isNotEmpty) {
filterBarcode.forEach((element) {
element.znMenge = (double.parse(element.znMenge ?? "0") + 1).toString();
bottomBarcodeFunciton(element);
});
print("баркод тэнцсэн");
} else {
var nominModal = await censusNominBarCodeHelper
.selectSapCensusBarCodeItems(widget.documentNumber);
bool isNotNull = false;
for (var tmp in nominModal) {
if (tmp.barcodeId == barCode) {
List<IItemBarcodeId> itemLists = [];
isNotNull = true;
List<IItemItemBarcode> items = [];
IItemItemBarcode itemBarCode = IItemItemBarcode(
ean11: tmp.barcodeId,
gjahr: "2024",
iblnr: widget.documentNumber,
matnr: tmp.itemId,
znMenge: "1",
zuname: loginName);
items.add(itemBarCode);
IItemBarcodeId sqlLiteItem = IItemBarcodeId(
ean11: tmp.barcodeId,
gjahr: "2024",
iblnr: widget.documentNumber,
matnr: tmp.itemId,
znMenge: "1",
documentNumber: widget.documentNumber,
itemInfo: "",
zdMenge: "",
zuname: loginName);
itemLists.add(sqlLiteItem);
setState(() {});
return;
}
}

if (isNotNull == false) {
Utils.showSnackBar(
context,
"Зөвхөн documentNumber - т байгаа барааг л уншуулна уу?",
"Санамж",
kYellowColor,
2);
}
print("баркод тэнцээгүй");
}
setState(() {});
}

bottomBarcodeFunciton(IItemItemBarcode iItemItemBarcode) {
print(iItemItemBarcode.ean11);
final filteredItem = _pi!.iitem!.items!
.where((element) => element.matnr == iItemItemBarcode.matnr);
print(
"lenght ${_pi?.iitembarcode?.itemBarcode?.where((element) => element.matnr == iItemItemBarcode.matnr).toList().length}");
IItemItem iitem = filteredItem.first;
iitem.tileColor = true;
_pi!.iitem!.items!.remove(filteredItem.first);
_pi!.iitem!.items!.insert(0, iitem);
_piAll!.iitem!.items = _pi!.iitem!.items;
customModalBottomSheet(
context,
child: BarCodeWidget(
updateItemBarcode: saveFunction,
bacodeList: _pi?.iitembarcode?.itemBarcode
?.where((element) => element.matnr == iItemItemBarcode.matnr)
.toList() ??
[],
),
);
}

// Амжилттай бүртгэх alert
void success(String messsage) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Амжилттай бүртгэлээ"),
content: Text(
messsage,
style: const TextStyle(color: kPrimaryColor),
),
actions: [
TextButton(
onPressed: () async {
deleteByDocumentNumber();
deleteByBarcodeList();
Navigator.of(context).pop();
Navigator.of(context).pop(MaterialPageRoute(
builder: (context) => const SapPurchaseMenu()));
},
child: const Text('Тийм'),
),
],
),
);
}

void deleteByDocumentNumber() async {
await censusSapBarCOdeHelper.deleteSapCensusIdItems(widget.documentNumber);
}

void deleteByBarcodeList() async {
await censusNominBarCodeHelper
.deleteCensusBarcodeByDocumentNumber(widget.documentNumber);
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.