manageSubsectionStockTake method

Future<List<ManageSubSectionStockTake>> manageSubsectionStockTake(
  1. List<ManageSubSectionStockTake> manageSubsectionstocktake,
  2. String action,
  3. ManageSubSectionStockTake manageSubSectionStockTakeDetail
)

Implementation

Future<List<stockCount.ManageSubSectionStockTake>> manageSubsectionStockTake(List<stockCount.ManageSubSectionStockTake> manageSubsectionstocktake,String action,stockCount.ManageSubSectionStockTake manageSubSectionStockTakeDetail) async{
  var api = await ExternalApiClassHelper.load('external_api');
  var externalApi = tasks. ExternalApiClass(
    externalWebApiToken: api?.externalWebApiToken ?? "",
    externalWebApiTokenName: api?.externalWebApiTokenName ?? "",
    licenseKey: api?.licenseKey ?? "",
    licenseKeyId: api?.licenseKeyId ?? "",
    employeeId: api?.employeeId ?? "",
  );
  List<stockCount.ManageSubSectionStockTake> manageStockTake = [];
  List<tasks.ManageSubSectionStockTake> GrpcManageSubSectionStockTake = [];

  for(var s in manageSubsectionstocktake){
    List<tasks.ManageSubSectionStockTakeInventory> GrpcManageSubSectionStockTakeInventory = [];
    for(var l in s.manageSubSectionStockTakeInventory){

      GrpcManageSubSectionStockTakeInventory.add(tasks.ManageSubSectionStockTakeInventory(
        qtyCounted: l.qtyCounted,
        manageSubSectionStockTakeInventoryId: l.manageSubSectionStockTakeInventoryId,
        inventoryManagement: tasks.InventoryManagement(
          inventoryId : l.inventoryManagement.inventoryId,
          productItem: tasks.ProductItem(
            newItemNumber: l.inventoryManagement.item!.newItemNumber,
          ),
        )
      ));
    }
    GrpcManageSubSectionStockTake.add(tasks.ManageSubSectionStockTake(
      manageSubSectionStockTakeName: s.manageSubSectionStockTakeName,

      iCEmployeeDTO: tasks.ICEmployee(
        icEmployeeId: s.icEmployeeDTO!.id, employeeId: '', name: '',
    ),
      manageStockCountSession:  tasks.ManageStockCountSession(
        manageStockSessionId: s.manageStockCountSession!.manageStockSessionId
      ),
      manageSubSectionStockTakeInventory: GrpcManageSubSectionStockTakeInventory, manageSubSectionStockTakeId: null
    ));
    List<stockCount.ManageSubSectionStockTakeInventory> manageSubSectionstockTakeInventory = [];
    for(var l in s.manageSubSectionStockTakeInventory){
      manageSubSectionstockTakeInventory.add(stockCount.ManageSubSectionStockTakeInventory(
          inventoryManagement: stock.Inventory(
            inventoryId: l.inventoryManagement.inventoryId,
            item: stock.Item(
              newItemNumber:l.inventoryManagement.item!.newItemNumber,


            ),

          ),
          qtyCounted: l.qtyCounted, manageSubSectionStockTakeInventoryId: 0
      ));
    }
  }


  // print(manageSubsectionstocktake.icEmployeeDTO!.id);
  var request = tasks.ManageSubSectionStockTakeRequest(
    externalApiClass:  externalApi,
    action: action,
    manageSubSectionStockTake: GrpcManageSubSectionStockTake,
    manageSubSectionStockTakeDetail: tasks. ManageSubSectionStockTake(
      iCEmployeeDTO: tasks. ICEmployee(
        icEmployeeId: manageSubSectionStockTakeDetail.icEmployeeDTO!.id,

      ),
      manageStockCountSession: tasks. ManageStockCountSession(
        manageStockSessionId: manageSubSectionStockTakeDetail.manageStockCountSession!.manageStockSessionId
      )
    )
  );
  final plainBytes = request.writeToBuffer();
  final result = GrpcEncryptedHelper.encrypt(plainBytes);
  final Uint8List iv = result["iv"]!;
  final Uint8List cipherText = result["ciphertext"]!;
  var response = await  taskServiceClient.manageSubSectionStockTakeService( tasks. EncryptedMessage(iv: iv,ciphertext: cipherText));
  final decryptedBytes = GrpcEncryptedHelper.decrypted(Uint8List.fromList(response.iv), Uint8List.fromList(response.ciphertext));
  final responses = tasks. ManageSubSectionStockTakeResponse.fromBuffer(decryptedBytes);
  // DateTime? _parseDate(String? value) {
  //   if (value == null || value.isEmpty) return null;
  //   return DateTime.parse(value);
  // }
  if(responses.success){
    if(responses.manageSubSectionStockTake.isNotEmpty){


      for(var s in responses.manageSubSectionStockTake){

        List<stockCount.ManageSubSectionStockTakeInventory> lis = [];
        if(s.manageSubSectionStockTakeInventory.isNotEmpty ){

          for(var l in s.manageSubSectionStockTakeInventory){

              lis.add(stockCount.ManageSubSectionStockTakeInventory(
                  manageSubSectionStockTakeInventoryId: l.manageSubSectionStockTakeInventoryId,
                  inventoryManagement: stock.Inventory(inventoryId:  l.inventoryManagement.inventoryId,
                     item:  stock.Item(
                          newItemNumber: l.inventoryManagement.productItem.newItemNumber,
                          itemName1: l.inventoryManagement.productItem.itemName1,
                          itemName2: l.inventoryManagement.productItem.itemName2,
                          modelName: l.inventoryManagement.productItem.modelName
                      ),icProject:  icproject.ICProject(projectGroup: icproject.ProjectGroup(),organization: icproject.Organization(organizationid: 0)), qtyOnHand:  l.qtyCounted),
                  // dateAdd: _parseDate(l.dateadd),
                  // dateEdit: _parseDate(l.dateadd),
                  qtyCounted: l.qtyCounted));

          }
          manageStockTake.add(stockCount.ManageSubSectionStockTake(
              manageSubSectionStockTakeInventory: lis,
              icEmployeeDTO: employee. Employee(employeeId: "", name: s.iCEmployeeDTO.name,id: s.iCEmployeeDTO.icEmployeeId),
              manageSubSectionStockTakeId: s.manageSubSectionStockTakeId,
              manageSubSectionStockTakeName: s.manageSubSectionStockTakeName,
              manageStockCountSession: stockCount.ManageStockCountSession(
                manageStockSessionId: s.manageStockCountSession.manageStockSessionId,
                manageStockCountSessionName: "", useradd: "", useredit: "",
                )
          )
          );

        }
      }



    }

    return manageStockTake;
  }
  return [];
}