Sort data by Date in Collection

Sort data by Date in Collection

Hello,

I am fetching data from multiple forms and i am trying to sort the data by date wise.But i am unable to get success in that. 
Following Eg. is the way i want
Invoice No.      Invoice Date      Purchase Qty      Sale Qty
      15                  17/10/2020              20
      15                  18/10/2020                                      15
      16                  19/10/2020              15
      16                  20/10/2020                                      10

What i received as data is as follows:
Invoice No.      Invoice Date      Purchase Qty      Sale Qty
      15                  17/10/2020              20
      16                  19/10/2020              15
      15                  18/10/2020                                      15
      16                  20/10/2020                                     10

Code:
  1. inventoryItem = Collection();
  2. for each  rec_Inventory in Inventory[Product_Code == input.Item] sort by Added_Time desc
  3. {
  4. inventoryNewRow = Item_Report.Item_Details();
  5. for each  item in inventoryNewRow
  6. {
  7. for each  rec_Purchase in Purchase_Invoice[Invoice_Date >= input.From_Date && Invoice_Date <= input.To_Date] sort by Added_Time desc
  8. {
  9. for each  rec_Purchase_Sub in rec_Purchase.Product_Details
  10. {
  11. if(rec_Purchase_Sub.Item == input.Item && rec_Purchase_Sub.Bin == rec_Inventory.Bin && rec_Purchase_Sub.Sub_Bin == rec_Inventory.Sub_Bin && rec_Purchase_Sub.Warehouse_Location.Warehouse_Location == rec_Inventory.Warehouse_Location)
  12. {
  13. purchaseNewRow = Item_Report.Item_Details();
  14. for each  item_Purchase in purchaseNewRow
  15. {
  16. item_Purchase.Client_Name=rec_Purchase.Vendor.M_s;
  17. item_Purchase.Invoice_No=rec_Purchase.Invoice_No;
  18. item_Purchase.Invoice_Date=rec_Purchase.Invoice_Date.toString();
  19. item_Purchase.Purchase_Quantity=rec_Purchase_Sub.Quantity.toString();
  20. }
  21. inventoryItem.insert(purchaseNewRow);
  22. }
  23. }
  24. for each  rec_Sale in Sales_Invoice[Invoice_Date >= input.From_Date && Invoice_Date <= input.To_Date && Product_Details.Item == input.Item] sort by Added_Time desc
  25. {
  26. for each  rec_Sale_Sub in rec_Sale.Product_Details
  27. {
  28. info rec_Sale_Sub;
  29. if(rec_Sale_Sub.Bin == rec_Inventory.Bin && rec_Sale_Sub.Sub_Bin == rec_Inventory.Sub_Bin && rec_Sale_Sub.Warehouse_Location == rec_Inventory.Warehouse_Location)
  30. {
  31. salesNewRow = Item_Report.Item_Details();
  32. for each  item_Sales in salesNewRow
  33. {
  34. item_Sales.Client_Name=rec_Sale.M_s.M_s;
  35. item_Sales.Invoice_No=rec_Sale.Invoice_No;
  36. item_Sales.Invoice_Date=rec_Sale.Invoice_Date.toString();
  37. item_Sales.Sale_Quantity=rec_Sale_Sub.Quantity.toString();
  38. }
  39. inventoryItem.insert(salesNewRow);
  40. }
  41. }
  42. }
  43. }
  44. item.Bin=rec_Inventory.Bin.Bin;
  45. item.Sub_Bin=rec_Inventory.Sub_Bin.Sub_Bin;
  46. item.Warehouse_Location=rec_Inventory.Warehouse_Location;
  47. item.Inward_Quantity=rec_Inventory.Inward_Quantity.toString();
  48. item.Outward_Quantity=rec_Inventory.Outward_Quantity.toString();
  49. item.Balance_Quantity=rec_Inventory.Balance_Quantity.toString();
  50. }
  51. inventoryItem.insert(inventoryNewRow);
  52. }
  53. input.Item_Details.insert(inventoryItem);
I am trying to fetch the data and store it inside the Subform Since i want that data to be in excel sheet together. If there is any alternative do suggest me, i am open to suggestions.