You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			297 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			297 lines
		
	
	
		
			9.8 KiB
		
	
	
	
		
			Dart
		
	
import 'dart:typed_data';
 | 
						|
 | 
						|
import 'package:flutter/cupertino.dart';
 | 
						|
import 'package:fluttertoast/fluttertoast.dart';
 | 
						|
import 'package:test_sa/extensions/context_extension.dart';
 | 
						|
import 'package:test_sa/models/lookup.dart';
 | 
						|
import 'package:test_sa/models/new_models/assigned_employee.dart';
 | 
						|
import 'package:test_sa/models/new_models/building.dart';
 | 
						|
import 'package:test_sa/models/new_models/department.dart';
 | 
						|
import 'package:test_sa/models/new_models/floor.dart';
 | 
						|
import 'package:test_sa/models/new_models/site.dart';
 | 
						|
import 'package:test_sa/models/timer_model.dart';
 | 
						|
 | 
						|
class GasRefillModel {
 | 
						|
  GasRefillModel({
 | 
						|
    this.id,
 | 
						|
    this.gazRefillNo,
 | 
						|
    this.expectedDate,
 | 
						|
    this.expectedTime,
 | 
						|
    this.startDate,
 | 
						|
    this.startTime,
 | 
						|
    this.endDate,
 | 
						|
    this.endTime,
 | 
						|
    this.engSignature,
 | 
						|
    this.nurseSignature,
 | 
						|
    this.workingHours,
 | 
						|
    this.site,
 | 
						|
    this.building,
 | 
						|
    this.floor,
 | 
						|
    this.department,
 | 
						|
    this.assignedEmployee,
 | 
						|
    this.status,
 | 
						|
    this.comment,
 | 
						|
    this.gazRefillDetails,
 | 
						|
    this.localEngineerSignature,
 | 
						|
    this.localNurseSignature,
 | 
						|
    this.timer,
 | 
						|
  });
 | 
						|
 | 
						|
  GasRefillModel.fromJson(dynamic json) {
 | 
						|
    id = json['id'];
 | 
						|
    gazRefillNo = json['gazRefillNo'];
 | 
						|
    expectedDate = json['expectedDate'];
 | 
						|
    expectedTime = json['expectedTime'];
 | 
						|
    startDate = json['startDate'];
 | 
						|
    startTime = json['startTime'];
 | 
						|
    endDate = json['endDate'];
 | 
						|
    endTime = json['endTime'];
 | 
						|
    comment = json['comment'];
 | 
						|
    workingHours = json['workingHours'];
 | 
						|
    try {
 | 
						|
      final sd = DateTime.tryParse(startDate ?? "");
 | 
						|
      final st = DateTime.tryParse(startTime ?? "");
 | 
						|
      final ed = DateTime.tryParse(endDate ?? "");
 | 
						|
      final et = DateTime.tryParse(endTime ?? "");
 | 
						|
      timer = TimerModel(
 | 
						|
        startAt: st == null ? sd : sd.add(Duration(hours: st.hour, minutes: st.minute, seconds: st.second)),
 | 
						|
        endAt: et == null ? ed : ed.add(Duration(hours: et.hour, minutes: et.minute, seconds: et.second)),
 | 
						|
      );
 | 
						|
      if (timer.endAt != null && timer.startAt != null) {
 | 
						|
        timer.durationInSecond = (timer.endAt.difference(timer.startAt))?.inSeconds;
 | 
						|
        workingHours = (((timer.durationInSecond ?? 0) / 60) / 60);
 | 
						|
      }
 | 
						|
    } catch (e) {
 | 
						|
      print(e);
 | 
						|
    }
 | 
						|
    engSignature = json['engSignature'];
 | 
						|
    nurseSignature = json['nurseSignature'];
 | 
						|
    site = json['site'] != null ? Site.fromJson(json['site']) : null;
 | 
						|
    building = json['building'] != null ? Building.fromJson(json['building']) : null;
 | 
						|
    floor = json['floor'] != null ? Floor.fromJson(json['floor']) : null;
 | 
						|
    department = json['department'] != null ? Department.fromJson(json['department']) : null;
 | 
						|
    assignedEmployee = json['assignedEmployee'] != null ? AssignedEmployee.fromJson(json['assignedEmployee']) : null;
 | 
						|
    status = json['status'] != null ? Lookup.fromJson(json['status']) : null;
 | 
						|
    if (json['gazRefillDetails'] != null) {
 | 
						|
      gazRefillDetails = [];
 | 
						|
      json['gazRefillDetails'].forEach((v) {
 | 
						|
        gazRefillDetails.add(GasRefillDetails.fromJson(v));
 | 
						|
      });
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  num id;
 | 
						|
  String gazRefillNo;
 | 
						|
  String expectedDate;
 | 
						|
  String expectedTime;
 | 
						|
  String startDate;
 | 
						|
  String startTime;
 | 
						|
  String endDate;
 | 
						|
  String endTime;
 | 
						|
  String engSignature;
 | 
						|
  String nurseSignature;
 | 
						|
  num workingHours;
 | 
						|
  Site site;
 | 
						|
  Building building;
 | 
						|
  Floor floor;
 | 
						|
  Department department;
 | 
						|
  AssignedEmployee assignedEmployee;
 | 
						|
  Lookup status;
 | 
						|
  String comment;
 | 
						|
  List<GasRefillDetails> gazRefillDetails;
 | 
						|
  Uint8List localNurseSignature;
 | 
						|
  Uint8List localEngineerSignature;
 | 
						|
  TimerModel timer = TimerModel();
 | 
						|
 | 
						|
  GasRefillModel copyWith({
 | 
						|
    num id,
 | 
						|
    String gazRefillNo,
 | 
						|
    String expectedDate,
 | 
						|
    String expectedTime,
 | 
						|
    String startDate,
 | 
						|
    String startTime,
 | 
						|
    String endDate,
 | 
						|
    String endTime,
 | 
						|
    String engSignature,
 | 
						|
    String nurseSignature,
 | 
						|
    num workingHours,
 | 
						|
    Site site,
 | 
						|
    Building building,
 | 
						|
    Floor floor,
 | 
						|
    Department department,
 | 
						|
    AssignedEmployee assignedEmployee,
 | 
						|
    Lookup status,
 | 
						|
    String comment,
 | 
						|
    List<GasRefillDetails> gazRefillDetails,
 | 
						|
    TimerModel timer,
 | 
						|
  }) =>
 | 
						|
      GasRefillModel(
 | 
						|
        id: id ?? this.id,
 | 
						|
        gazRefillNo: gazRefillNo ?? this.gazRefillNo,
 | 
						|
        expectedDate: expectedDate ?? this.expectedDate,
 | 
						|
        expectedTime: expectedTime ?? this.expectedTime,
 | 
						|
        startDate: startDate ?? this.startDate,
 | 
						|
        startTime: startTime ?? this.startTime,
 | 
						|
        endDate: endDate ?? this.endDate,
 | 
						|
        endTime: endTime ?? this.endTime,
 | 
						|
        engSignature: engSignature ?? this.engSignature,
 | 
						|
        nurseSignature: nurseSignature ?? this.nurseSignature,
 | 
						|
        workingHours: workingHours ?? this.workingHours,
 | 
						|
        site: site ?? this.site,
 | 
						|
        building: building ?? this.building,
 | 
						|
        floor: floor ?? this.floor,
 | 
						|
        department: department ?? this.department,
 | 
						|
        assignedEmployee: assignedEmployee ?? this.assignedEmployee,
 | 
						|
        status: status ?? this.status,
 | 
						|
        comment: comment ?? this.comment,
 | 
						|
        gazRefillDetails: gazRefillDetails ?? this.gazRefillDetails,
 | 
						|
        timer: timer ?? this.timer,
 | 
						|
      );
 | 
						|
 | 
						|
  Map<String, dynamic> toJson() {
 | 
						|
    final map = <String, dynamic>{};
 | 
						|
    map['id'] = id ?? 0;
 | 
						|
    map['gazRefillNo'] = "GR-${DateTime.now().toString().split(" ").first}";
 | 
						|
    map['expectedDate'] = expectedDate;
 | 
						|
    map['expectedTime'] = expectedTime;
 | 
						|
    map['startDate'] = startDate;
 | 
						|
    map['startTime'] = startTime;
 | 
						|
    map['endDate'] = endDate;
 | 
						|
    map['endTime'] = endTime;
 | 
						|
    map['engSignature'] = engSignature;
 | 
						|
    map['nurseSignature'] = nurseSignature;
 | 
						|
    map['workingHours'] = workingHours;
 | 
						|
    map['comment'] = comment;
 | 
						|
    if (site != null) {
 | 
						|
      map['site'] = site.toJson(addBuildings: false);
 | 
						|
    }
 | 
						|
    if (building != null) {
 | 
						|
      map['building'] = building.toJson(addFloor: false);
 | 
						|
    }
 | 
						|
    if (floor != null) {
 | 
						|
      map['floor'] = floor.toJson(addDepartments: false);
 | 
						|
    }
 | 
						|
    if (department != null) {
 | 
						|
      map['department'] = department.toJson();
 | 
						|
    }
 | 
						|
    if (assignedEmployee != null) {
 | 
						|
      map['assignedEmployee'] = assignedEmployee.toJson();
 | 
						|
    }
 | 
						|
    if (status != null) {
 | 
						|
      map['status'] = status.toJson();
 | 
						|
    }
 | 
						|
    if (gazRefillDetails != null) {
 | 
						|
      map['gazRefillDetails'] = gazRefillDetails.map((v) => v.toJson()).toList();
 | 
						|
    }
 | 
						|
    return map;
 | 
						|
  }
 | 
						|
 | 
						|
  Future<bool> validate(BuildContext context) async {
 | 
						|
    if (site == null) {
 | 
						|
      await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.destinationSite}");
 | 
						|
      return false;
 | 
						|
    } else if (building == null) {
 | 
						|
      await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.building}");
 | 
						|
      return false;
 | 
						|
    } else if (floor == null) {
 | 
						|
      await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.floor}");
 | 
						|
      return false;
 | 
						|
    } else if (department == null) {
 | 
						|
      await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.department}");
 | 
						|
      return false;
 | 
						|
    }
 | 
						|
    return true;
 | 
						|
  }
 | 
						|
 | 
						|
  fromGasRefillModel(GasRefillModel model) {
 | 
						|
    id = model.id;
 | 
						|
    //userId = model.userId;
 | 
						|
    site = model.site;
 | 
						|
    gazRefillNo = model.gazRefillNo;
 | 
						|
    status = Lookup.fromStatus(model.status);
 | 
						|
    gazRefillDetails = model.gazRefillDetails;
 | 
						|
    building = model.building;
 | 
						|
    floor = model.floor;
 | 
						|
    department = model.department;
 | 
						|
    startDate = model.startDate;
 | 
						|
    endDate = model.endDate;
 | 
						|
    expectedDate = model.expectedDate;
 | 
						|
    comment = model.comment;
 | 
						|
    assignedEmployee = model.assignedEmployee;
 | 
						|
    localEngineerSignature = model.localEngineerSignature;
 | 
						|
    localNurseSignature = model.localNurseSignature;
 | 
						|
    engSignature = model.engSignature;
 | 
						|
    nurseSignature = model.nurseSignature;
 | 
						|
    workingHours = model.workingHours;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
class GasRefillDetails {
 | 
						|
  GasRefillDetails({this.id, this.gasType, this.cylinderType, this.cylinderSize, this.requestedQty, this.deliverdQty, this.selectedForEditing});
 | 
						|
 | 
						|
  GasRefillDetails.fromJson(dynamic json) {
 | 
						|
    id = json['id'];
 | 
						|
    gasType = json['gasType'] != null ? Lookup.fromJson(json['gasType']) : null;
 | 
						|
    cylinderType = json['cylinderType'] != null ? Lookup.fromJson(json['cylinderType']) : null;
 | 
						|
    cylinderSize = json['cylinderSize'] != null ? Lookup.fromJson(json['cylinderSize']) : null;
 | 
						|
    requestedQty = json['requestedQty'];
 | 
						|
    deliverdQty = json['deliverdQty'];
 | 
						|
  }
 | 
						|
 | 
						|
  num id;
 | 
						|
  Lookup gasType;
 | 
						|
  Lookup cylinderType;
 | 
						|
  Lookup cylinderSize;
 | 
						|
  num requestedQty;
 | 
						|
  num deliverdQty;
 | 
						|
  bool selectedForEditing;
 | 
						|
 | 
						|
  GasRefillDetails copyWith({
 | 
						|
    num id,
 | 
						|
    Lookup gasType,
 | 
						|
    Lookup cylinderType,
 | 
						|
    Lookup cylinderSize,
 | 
						|
    num requestedQty,
 | 
						|
    num deliverdQty,
 | 
						|
  }) =>
 | 
						|
      GasRefillDetails(
 | 
						|
        id: id ?? this.id,
 | 
						|
        gasType: gasType ?? this.gasType,
 | 
						|
        cylinderType: cylinderType ?? this.cylinderType,
 | 
						|
        cylinderSize: cylinderSize ?? this.cylinderSize,
 | 
						|
        requestedQty: requestedQty ?? this.requestedQty,
 | 
						|
        deliverdQty: deliverdQty ?? this.deliverdQty,
 | 
						|
      );
 | 
						|
 | 
						|
  Map<String, dynamic> toJson() {
 | 
						|
    final map = <String, dynamic>{};
 | 
						|
    map['id'] = id ?? 0;
 | 
						|
    if (gasType != null) {
 | 
						|
      map['gasType'] = gasType.toJson();
 | 
						|
    }
 | 
						|
    if (cylinderType != null) {
 | 
						|
      map['cylinderType'] = cylinderType.toJson();
 | 
						|
    }
 | 
						|
    if (cylinderSize != null) {
 | 
						|
      map['cylinderSize'] = cylinderSize.toJson();
 | 
						|
    }
 | 
						|
    map['requestedQty'] = requestedQty;
 | 
						|
    map['deliverdQty'] = deliverdQty;
 | 
						|
    return map;
 | 
						|
  }
 | 
						|
 | 
						|
  Future<bool> validate(BuildContext context) async {
 | 
						|
    if (gasType == null) {
 | 
						|
      await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.gasType}");
 | 
						|
      return false;
 | 
						|
    } else if (cylinderType == null) {
 | 
						|
      await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.cylinderType}");
 | 
						|
      return false;
 | 
						|
    } else if (cylinderSize == null) {
 | 
						|
      await Fluttertoast.showToast(msg: "${context.translation.youHaveToSelect} ${context.translation.cylinderSize}");
 | 
						|
      return false;
 | 
						|
    }
 | 
						|
    return true;
 | 
						|
  }
 | 
						|
}
 |