Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a8cd72ed17 | |||
| adf74e2427 | |||
| 603ed9c60e | |||
| 43c337d46a | |||
| 1ef6cd9479 | |||
| f8cb7453a7 | |||
| 6e9a9292de | |||
| ec1f4ea117 | |||
| 602b538830 | |||
| 86873d2a21 | |||
| c64f3cff72 | |||
| ce50467816 | |||
| 20475ace73 | |||
| 1e63b900ab | |||
| dd29c7324f | |||
| 17f24b7733 |
+9
-2
@@ -102,7 +102,7 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)models;$(ProjectDir)controllers;$(ProjectDir)factories;$(ProjectDir)views;$(ProjectDir)services;$(ProjectDir)utilities;$(ProjectDir)core\patterns;$(ProjectDir)datastores;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)models;$(ProjectDir)controllers;$(ProjectDir)factories;$(ProjectDir)views;$(ProjectDir)services;$(ProjectDir)utilities;$(ProjectDir)core\patterns;$(ProjectDir)datastores;$(ProjectDir)datastores\sharedmemory;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -117,7 +117,7 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)models;$(ProjectDir)controllers;$(ProjectDir)factories;$(ProjectDir)views;$(ProjectDir)services;$(ProjectDir)utilities;$(ProjectDir)core\patterns;$(ProjectDir)datastores;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)models;$(ProjectDir)controllers;$(ProjectDir)factories;$(ProjectDir)views;$(ProjectDir)services;$(ProjectDir)utilities;$(ProjectDir)core\patterns;$(ProjectDir)datastores;$(ProjectDir)datastores\sharedmemory;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -129,6 +129,7 @@
|
|||||||
<ClCompile Include="core\patterns\Observer.cpp" />
|
<ClCompile Include="core\patterns\Observer.cpp" />
|
||||||
<ClCompile Include="core\patterns\Subject.cpp" />
|
<ClCompile Include="core\patterns\Subject.cpp" />
|
||||||
<ClCompile Include="datastores\DataStore.cpp" />
|
<ClCompile Include="datastores\DataStore.cpp" />
|
||||||
|
<ClCompile Include="datastores\sharedmemory\SharedMemory.cpp" />
|
||||||
<ClCompile Include="models\ComboPackage.cpp" />
|
<ClCompile Include="models\ComboPackage.cpp" />
|
||||||
<ClCompile Include="models\InventoryItem.cpp" />
|
<ClCompile Include="models\InventoryItem.cpp" />
|
||||||
<ClCompile Include="models\Invoice.cpp" />
|
<ClCompile Include="models\Invoice.cpp" />
|
||||||
@@ -156,6 +157,12 @@
|
|||||||
<ClInclude Include="core\patterns\Observer.h" />
|
<ClInclude Include="core\patterns\Observer.h" />
|
||||||
<ClInclude Include="core\patterns\Subject.h" />
|
<ClInclude Include="core\patterns\Subject.h" />
|
||||||
<ClInclude Include="datastores\DataStore.h" />
|
<ClInclude Include="datastores\DataStore.h" />
|
||||||
|
<ClInclude Include="datastores\sharedmemory\FileHeader.h" />
|
||||||
|
<ClInclude Include="datastores\sharedmemory\MappingInfo.h" />
|
||||||
|
<ClInclude Include="datastores\sharedmemory\RecordState.h" />
|
||||||
|
<ClInclude Include="datastores\sharedmemory\SerializedRecords.h" />
|
||||||
|
<ClInclude Include="datastores\sharedmemory\SharedMemory.h" />
|
||||||
|
<ClInclude Include="datastores\sharedmemory\TrackedRecord.h" />
|
||||||
<ClInclude Include="factories\Factory.h" />
|
<ClInclude Include="factories\Factory.h" />
|
||||||
<ClInclude Include="models\ComboPackage.h" />
|
<ClInclude Include="models\ComboPackage.h" />
|
||||||
<ClInclude Include="models\InventoryItem.h" />
|
<ClInclude Include="models\InventoryItem.h" />
|
||||||
|
|||||||
+27
@@ -64,6 +64,12 @@
|
|||||||
<Filter Include="Source Files\Core\Patterns">
|
<Filter Include="Source Files\Core\Patterns">
|
||||||
<UniqueIdentifier>{8057b93d-51a9-42df-b06e-01ce395f6308}</UniqueIdentifier>
|
<UniqueIdentifier>{8057b93d-51a9-42df-b06e-01ce395f6308}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Header Files\DataStores\SharedMemory">
|
||||||
|
<UniqueIdentifier>{ec639004-44c6-4bd6-9963-077adde82b5f}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Source Files\DataStores\SharedMemory">
|
||||||
|
<UniqueIdentifier>{7aa8722e-adfa-466e-8211-de63f3b7892b}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Trenser.VehicleServiceSystem.cpp">
|
<ClCompile Include="Trenser.VehicleServiceSystem.cpp">
|
||||||
@@ -141,6 +147,9 @@
|
|||||||
<ClCompile Include="models\ComboPackage.cpp">
|
<ClCompile Include="models\ComboPackage.cpp">
|
||||||
<Filter>Source Files\Models</Filter>
|
<Filter>Source Files\Models</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="datastores\sharedmemory\SharedMemory.cpp">
|
||||||
|
<Filter>Source Files\DataStores\SharedMemory</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="utilities\InputHelper.h">
|
<ClInclude Include="utilities\InputHelper.h">
|
||||||
@@ -251,5 +260,23 @@
|
|||||||
<ClInclude Include="views\MenuHelper.h">
|
<ClInclude Include="views\MenuHelper.h">
|
||||||
<Filter>Header Files\Views</Filter>
|
<Filter>Header Files\Views</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="datastores\sharedmemory\FileHeader.h">
|
||||||
|
<Filter>Header Files\DataStores\SharedMemory</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="datastores\sharedmemory\MappingInfo.h">
|
||||||
|
<Filter>Header Files\DataStores\SharedMemory</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="datastores\sharedmemory\RecordState.h">
|
||||||
|
<Filter>Header Files\DataStores\SharedMemory</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="datastores\sharedmemory\TrackedRecord.h">
|
||||||
|
<Filter>Header Files\DataStores\SharedMemory</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="datastores\sharedmemory\SerializedRecords.h">
|
||||||
|
<Filter>Header Files\DataStores\SharedMemory</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="datastores\sharedmemory\SharedMemory.h">
|
||||||
|
<Filter>Header Files\DataStores\SharedMemory</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -6,42 +6,67 @@ Date: 19-May-2026
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
|
#include "MappingInfo.h"
|
||||||
|
#include "TrackedRecord.h"
|
||||||
|
#include "SharedMemory.h"
|
||||||
class User;
|
class User;
|
||||||
|
class Notification;
|
||||||
class Service;
|
class Service;
|
||||||
class ComboPackage;
|
class ComboPackage;
|
||||||
|
class InventoryItem;
|
||||||
class ServiceBooking;
|
class ServiceBooking;
|
||||||
class JobCard;
|
class JobCard;
|
||||||
class InventoryItem;
|
|
||||||
class Invoice;
|
class Invoice;
|
||||||
class Payment;
|
class Payment;
|
||||||
|
|
||||||
class DataStore
|
class DataStore
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
util::Map<std::string, User*> m_users;
|
DataStore();
|
||||||
util::Map<std::string, Service*> m_services;
|
|
||||||
util::Map<std::string, ComboPackage*> m_comboPackages;
|
|
||||||
util::Map<std::string, ServiceBooking*> m_serviceBookings;
|
|
||||||
util::Map<std::string, JobCard*> m_jobCards;
|
|
||||||
util::Map<std::string, InventoryItem*> m_inventoryItems;
|
|
||||||
util::Map<std::string, Invoice*> m_invoices;
|
|
||||||
util::Map<std::string, Payment*> m_payments;
|
|
||||||
DataStore() {}
|
|
||||||
public:
|
|
||||||
static DataStore& getInstance();
|
|
||||||
DataStore(const DataStore&) = delete;
|
DataStore(const DataStore&) = delete;
|
||||||
DataStore& operator=(const DataStore&) = delete;
|
DataStore& operator=(const DataStore&) = delete;
|
||||||
DataStore(DataStore&&) = delete;
|
DataStore(DataStore&&) = delete;
|
||||||
DataStore& operator=(DataStore&&) = delete;
|
DataStore& operator=(DataStore&&) = delete;
|
||||||
util::Map<std::string, User*>& getUsers();
|
HANDLE m_globalMutex;
|
||||||
util::Map<std::string, Service*>& getServices();
|
MappingInfo m_users;
|
||||||
util::Map<std::string, ComboPackage*>& getComboPackages();
|
MappingInfo m_notifications;
|
||||||
util::Map<std::string, ServiceBooking*>& getServiceBookings();
|
MappingInfo m_services;
|
||||||
util::Map<std::string, JobCard*>& getJobCards();
|
MappingInfo m_comboPackages;
|
||||||
util::Map<std::string, InventoryItem*>& getInventoryItems();
|
MappingInfo m_inventoryItems;
|
||||||
util::Map<std::string, Invoice*>& getInvoices();
|
MappingInfo m_serviceBookings;
|
||||||
util::Map<std::string, Payment*>& getPayments();
|
MappingInfo m_jobCards;
|
||||||
};
|
MappingInfo m_invoices;
|
||||||
|
MappingInfo m_payments;
|
||||||
|
public:
|
||||||
|
static DataStore& getInstance();
|
||||||
|
bool initialize();
|
||||||
|
void shutdown();
|
||||||
|
util::Map<std::string, TrackedRecord<User>> getUsers();
|
||||||
|
util::Map<std::string, TrackedRecord<Notification>> getNotifications();
|
||||||
|
util::Map<std::string, TrackedRecord<Service>> getServices();
|
||||||
|
util::Map<std::string, TrackedRecord<ComboPackage>> getComboPackages();
|
||||||
|
util::Map<std::string, TrackedRecord<InventoryItem>> getInventoryItems();
|
||||||
|
util::Map<std::string, TrackedRecord<ServiceBooking>> getServiceBookings();
|
||||||
|
util::Map<std::string, TrackedRecord<JobCard>> getJobCards();
|
||||||
|
util::Map<std::string, TrackedRecord<Invoice>> getInvoices();
|
||||||
|
util::Map<std::string, TrackedRecord<Payment>> getPayments();
|
||||||
|
void saveUsers(util::Map<std::string, TrackedRecord<User>>& users);
|
||||||
|
void saveNotifications(util::Map<std::string, TrackedRecord<Notification>>& notifications);
|
||||||
|
void saveServices(util::Map<std::string, TrackedRecord<Service>>& services);
|
||||||
|
void saveComboPackages(util::Map<std::string, TrackedRecord<ComboPackage>>& comboPackages);
|
||||||
|
void saveInventoryItems(util::Map<std::string, TrackedRecord<InventoryItem>>& inventoryItems);
|
||||||
|
void saveServiceBookings(util::Map<std::string, TrackedRecord<ServiceBooking>>& bookings);
|
||||||
|
void saveJobCards(util::Map<std::string, TrackedRecord<JobCard>>& jobCards);
|
||||||
|
void saveInvoices(util::Map<std::string, TrackedRecord<Invoice>>& invoices);
|
||||||
|
void savePayments(util::Map<std::string, TrackedRecord<Payment>>& payments);
|
||||||
|
bool lockDataStore();
|
||||||
|
bool unlockDataStore();
|
||||||
|
private:
|
||||||
|
template<typename TObject, typename TSerialized>
|
||||||
|
util::Map<std::string, TrackedRecord<TObject>> loadRecords(MappingInfo& mapping);
|
||||||
|
template<typename TObject, typename TSerialized>
|
||||||
|
void saveRecords(MappingInfo& mapping, util::Map<std::string, TrackedRecord<TObject>>& records);
|
||||||
|
};
|
||||||
|
|||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
struct FileHeader
|
||||||
|
{
|
||||||
|
size_t recordCount;
|
||||||
|
size_t capacity;
|
||||||
|
};
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <windows.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct MappingInfo
|
||||||
|
{
|
||||||
|
HANDLE fileHandle;
|
||||||
|
HANDLE mappingHandle;
|
||||||
|
void* mappedView;
|
||||||
|
std::string fileName;
|
||||||
|
size_t recordSize;
|
||||||
|
size_t mappedCapacity;
|
||||||
|
MappingInfo()
|
||||||
|
: fileHandle(NULL),
|
||||||
|
mappingHandle(NULL),
|
||||||
|
mappedView(nullptr),
|
||||||
|
recordSize(0),
|
||||||
|
mappedCapacity(0) {}
|
||||||
|
};
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
enum class RecordState : int
|
||||||
|
{
|
||||||
|
CLEAN,
|
||||||
|
NEW_RECORD,
|
||||||
|
MODIFIED,
|
||||||
|
DELETED
|
||||||
|
};
|
||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Utility.h"
|
||||||
|
#include "Enums.h"
|
||||||
|
#include "Timestamp.h"
|
||||||
|
|
||||||
|
struct SerializedUser
|
||||||
|
{
|
||||||
|
char id[64];
|
||||||
|
char username[64];
|
||||||
|
char password[64];
|
||||||
|
char name[128];
|
||||||
|
char phone[32];
|
||||||
|
char email[128];
|
||||||
|
util::UserType userType;
|
||||||
|
util::State status;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SerializedNotification
|
||||||
|
{
|
||||||
|
char id[64];
|
||||||
|
char recipientUserId[64];
|
||||||
|
char title[128];
|
||||||
|
char message[1024];
|
||||||
|
util::Timestamp createdAt;
|
||||||
|
util::State state;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SerializedService
|
||||||
|
{
|
||||||
|
char id[64];
|
||||||
|
char name[128];
|
||||||
|
char inventoryItemIDs[1024];
|
||||||
|
double laborCost;
|
||||||
|
util::State status;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SerializedComboPackage
|
||||||
|
{
|
||||||
|
char id[64];
|
||||||
|
char packageName[128];
|
||||||
|
double discountPercentage;
|
||||||
|
char serviceIDs[1024];
|
||||||
|
util::State status;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SerializedInventoryItem
|
||||||
|
{
|
||||||
|
char id[64];
|
||||||
|
char partName[128];
|
||||||
|
int quantity;
|
||||||
|
double price;
|
||||||
|
util::State status;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SerializedServiceBooking
|
||||||
|
{
|
||||||
|
char id[64];
|
||||||
|
util::ServiceJobStatus status;
|
||||||
|
char serviceIDs[1024];
|
||||||
|
char customerId[64];
|
||||||
|
char vehicleNumber[64];
|
||||||
|
char vehicleBrand[64];
|
||||||
|
char vehicleModel[64];
|
||||||
|
char assignedTechnicianId[64];
|
||||||
|
double discountPercentage;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SerializedJobCard
|
||||||
|
{
|
||||||
|
char id[64];
|
||||||
|
char bookingId[64];
|
||||||
|
char serviceId[64];
|
||||||
|
char technicianId[64];
|
||||||
|
util::Timestamp assignedDate;
|
||||||
|
util::ServiceJobStatus status;
|
||||||
|
util::Timestamp completionDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SerializedInvoice
|
||||||
|
{
|
||||||
|
char id[64];
|
||||||
|
char bookingId[64];
|
||||||
|
util::Timestamp invoiceDate;
|
||||||
|
char partIDs[1024];
|
||||||
|
double laborCost;
|
||||||
|
double partsCost;
|
||||||
|
double discountPercentage;
|
||||||
|
double totalAmount;
|
||||||
|
util::Timestamp paymentDate;
|
||||||
|
util::PaymentMode paymentMethod;
|
||||||
|
util::PaymentStatus status;
|
||||||
|
};
|
||||||
+330
@@ -0,0 +1,330 @@
|
|||||||
|
#include "SharedMemory.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: invalidateMapping
|
||||||
|
Description: Releases all mapping resources and resets the mapping to an invalid state.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
Returns:
|
||||||
|
- None
|
||||||
|
*/
|
||||||
|
static void invalidateMapping(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
if (mapping.mappedView != nullptr)
|
||||||
|
{
|
||||||
|
UnmapViewOfFile(mapping.mappedView);
|
||||||
|
mapping.mappedView = nullptr;
|
||||||
|
}
|
||||||
|
if (mapping.mappingHandle != NULL)
|
||||||
|
{
|
||||||
|
CloseHandle(mapping.mappingHandle);
|
||||||
|
mapping.mappingHandle = NULL;
|
||||||
|
}
|
||||||
|
if (mapping.fileHandle != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
CloseHandle(mapping.fileHandle);
|
||||||
|
mapping.fileHandle = INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
mapping.mappedCapacity = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: createOrOpenMapping
|
||||||
|
Description: Creates or opens a file mapping and maps it into the process address space.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
Returns:
|
||||||
|
- bool: True if the mapping was successfully created/opened, otherwise false
|
||||||
|
*/
|
||||||
|
bool SharedMemory::createOrOpenMapping(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
if (mapping.recordSize == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.fileHandle =
|
||||||
|
CreateFileA(
|
||||||
|
mapping.fileName.c_str(),
|
||||||
|
GENERIC_READ | GENERIC_WRITE,
|
||||||
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
|
NULL,
|
||||||
|
OPEN_ALWAYS,
|
||||||
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
|
NULL);
|
||||||
|
if (mapping.fileHandle == INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
LARGE_INTEGER fileSize;
|
||||||
|
if (!GetFileSizeEx(mapping.fileHandle, &fileSize))
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool isNewFile = (fileSize.QuadPart == 0);
|
||||||
|
const size_t initialCapacity = config::file::INITIAL_CAPACITY;
|
||||||
|
if (isNewFile)
|
||||||
|
{
|
||||||
|
LARGE_INTEGER newSize;
|
||||||
|
newSize.QuadPart = sizeof(FileHeader) + initialCapacity * mapping.recordSize;
|
||||||
|
if (!SetFilePointerEx(mapping.fileHandle, newSize, NULL, FILE_BEGIN))
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!SetEndOfFile(mapping.fileHandle))
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mapping.mappingHandle =
|
||||||
|
CreateFileMappingA(
|
||||||
|
mapping.fileHandle,
|
||||||
|
NULL,
|
||||||
|
PAGE_READWRITE,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
if (mapping.mappingHandle == NULL)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.mappedView =
|
||||||
|
MapViewOfFile(
|
||||||
|
mapping.mappingHandle,
|
||||||
|
FILE_MAP_ALL_ACCESS,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
if (mapping.mappedView == nullptr)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
FileHeader* header = getHeader(mapping);
|
||||||
|
if (header == nullptr)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (isNewFile)
|
||||||
|
{
|
||||||
|
header->recordCount = 0;
|
||||||
|
header->capacity = initialCapacity;
|
||||||
|
}
|
||||||
|
mapping.mappedCapacity = header->capacity;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: closeMapping
|
||||||
|
Description: Unmaps and closes all resources associated with a file mapping.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping to close
|
||||||
|
Returns:
|
||||||
|
- None
|
||||||
|
*/
|
||||||
|
void SharedMemory::closeMapping(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: getHeader
|
||||||
|
Description: Returns the file header stored at the beginning of the mapped memory region.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
Returns:
|
||||||
|
- FileHeader*: Pointer to the file header, or nullptr if the mapping is not valid
|
||||||
|
*/
|
||||||
|
FileHeader* SharedMemory::getHeader(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
if (mapping.mappedView == nullptr)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return reinterpret_cast<FileHeader*>(mapping.mappedView);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: getRecordAddress
|
||||||
|
Description: Returns the address of a record at the specified index within the mapped memory region.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
- index: size_t, record index
|
||||||
|
Returns:
|
||||||
|
- void*: Pointer to the record, or nullptr if the mapping is not valid
|
||||||
|
*/
|
||||||
|
void* SharedMemory::getRecordAddress(MappingInfo& mapping, size_t index)
|
||||||
|
{
|
||||||
|
if (mapping.mappedView == nullptr)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return reinterpret_cast<char*>(mapping.mappedView) + sizeof(FileHeader) + index * mapping.recordSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: getRecordAddress
|
||||||
|
Description: Returns the address of a record at the specified index within the mapped memory region.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
- index: size_t, record index
|
||||||
|
Returns:
|
||||||
|
- void*: Pointer to the record, or nullptr if the mapping is not valid
|
||||||
|
*/
|
||||||
|
void* SharedMemory::getRecordAddress(MappingInfo& mapping, size_t index)
|
||||||
|
{
|
||||||
|
if (mapping.mappedView == nullptr)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return reinterpret_cast<char*>(mapping.mappedView) + sizeof(FileHeader) + index * mapping.recordSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: getRecordCount
|
||||||
|
Description: Returns the number of records currently stored in the mapping.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
Returns:
|
||||||
|
- size_t: Number of records in the mapping
|
||||||
|
*/
|
||||||
|
size_t SharedMemory::getRecordCount(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
FileHeader* header = getHeader(mapping);
|
||||||
|
if (header == nullptr)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return header->recordCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: setRecordCount
|
||||||
|
Description: Updates the number of records stored in the mapping.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
- count: size_t, new record count
|
||||||
|
Returns:
|
||||||
|
- None
|
||||||
|
*/
|
||||||
|
void SharedMemory::setRecordCount(MappingInfo& mapping, size_t count)
|
||||||
|
{
|
||||||
|
FileHeader* header = getHeader(mapping);
|
||||||
|
if (header == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
header->recordCount = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: getCapacity
|
||||||
|
Description: Returns the current capacity of the mapping.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
Returns:
|
||||||
|
- size_t: Maximum number of records that can be stored in the mapping
|
||||||
|
*/
|
||||||
|
size_t SharedMemory::getCapacity(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
FileHeader* header = getHeader(mapping);
|
||||||
|
if (header == nullptr)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return header->capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: resizeMapping
|
||||||
|
Description: Resizes the file mapping to the specified capacity.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
- newCapacity: size_t, new mapping capacity
|
||||||
|
Returns:
|
||||||
|
- bool: True if the resize succeeded, otherwise false
|
||||||
|
*/
|
||||||
|
bool SharedMemory::resizeMapping(MappingInfo& mapping, size_t newCapacity)
|
||||||
|
{
|
||||||
|
FileHeader* header = getHeader(mapping);
|
||||||
|
if (header == nullptr)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
header->capacity = newCapacity;
|
||||||
|
if (!FlushViewOfFile(mapping.mappedView, sizeof(FileHeader)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!UnmapViewOfFile(mapping.mappedView))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.mappedView = nullptr;
|
||||||
|
CloseHandle(mapping.mappingHandle);
|
||||||
|
mapping.mappingHandle = NULL;
|
||||||
|
LARGE_INTEGER newSize;
|
||||||
|
newSize.QuadPart = sizeof(FileHeader) + newCapacity * mapping.recordSize;
|
||||||
|
if (!SetFilePointerEx(mapping.fileHandle, newSize, NULL, FILE_BEGIN))
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!SetEndOfFile(mapping.fileHandle))
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.mappingHandle =
|
||||||
|
CreateFileMappingA(
|
||||||
|
mapping.fileHandle,
|
||||||
|
NULL,
|
||||||
|
PAGE_READWRITE,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
if (mapping.mappingHandle == NULL)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.mappedView =
|
||||||
|
MapViewOfFile(
|
||||||
|
mapping.mappingHandle,
|
||||||
|
FILE_MAP_ALL_ACCESS,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
if (mapping.mappedView == nullptr)
|
||||||
|
{
|
||||||
|
invalidateMapping(mapping);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mapping.mappedCapacity = newCapacity;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: ensureCapacityForInsert
|
||||||
|
Description: Ensures that the mapping has space for at least one additional record, growing it if necessary.
|
||||||
|
Parameters:
|
||||||
|
- mapping: MappingInfo&, mapping information and handles
|
||||||
|
Returns:
|
||||||
|
- bool: True if capacity is available, otherwise false
|
||||||
|
*/
|
||||||
|
bool SharedMemory::ensureCapacityForInsert(MappingInfo& mapping)
|
||||||
|
{
|
||||||
|
size_t recordCount = getRecordCount(mapping);
|
||||||
|
size_t capacity = getCapacity(mapping);
|
||||||
|
if (recordCount < capacity)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return resizeMapping(mapping, capacity * 2);
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstddef>
|
||||||
|
#include "MappingInfo.h"
|
||||||
|
#include "FileHeader.h"
|
||||||
|
|
||||||
|
namespace SharedMemory
|
||||||
|
{
|
||||||
|
bool createOrOpenMapping(MappingInfo& mapping);
|
||||||
|
void closeMapping(MappingInfo& mapping);
|
||||||
|
bool ensureLatestMapping(MappingInfo& mapping);
|
||||||
|
bool resizeMapping(MappingInfo& mapping, size_t newCapacity);
|
||||||
|
FileHeader* getHeader(MappingInfo& mapping);
|
||||||
|
void* getRecordAddress(MappingInfo& mapping, size_t index);
|
||||||
|
size_t getRecordCount(MappingInfo& mapping);
|
||||||
|
void setRecordCount(MappingInfo& mapping, size_t count);
|
||||||
|
size_t getCapacity(MappingInfo& mapping);
|
||||||
|
bool ensureCapacityForInsert(MappingInfo& mapping);
|
||||||
|
};
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "RecordState.h"
|
||||||
|
|
||||||
|
static const size_t INVALID_SLOT = static_cast<size_t>(-1);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct TrackedRecord
|
||||||
|
{
|
||||||
|
T* data;
|
||||||
|
RecordState state;
|
||||||
|
size_t slotIndex;
|
||||||
|
TrackedRecord()
|
||||||
|
: data(nullptr),
|
||||||
|
state(RecordState::CLEAN),
|
||||||
|
slotIndex(INVALID_SLOT) {}
|
||||||
|
TrackedRecord(
|
||||||
|
T* object,
|
||||||
|
RecordState recordState,
|
||||||
|
size_t slot)
|
||||||
|
: data(object),
|
||||||
|
state(recordState),
|
||||||
|
slotIndex(slot) {}
|
||||||
|
};
|
||||||
@@ -9,6 +9,7 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "ComboPackage.h"
|
#include "ComboPackage.h"
|
||||||
#include "Service.h"
|
#include "Service.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
@@ -270,72 +271,38 @@ static util::Vector<std::string> getServiceIDsAsVector(const std::string& servic
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the combo package into a CSV-formatted string.
|
Description: Serializes the ComboPackage object into a SerializedComboPackage record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized combo package record
|
- SerializedComboPackage: Serialized representation of the combo package
|
||||||
*/
|
*/
|
||||||
std::string ComboPackage::serialize() const
|
SerializedComboPackage ComboPackage::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedComboPackage;
|
SerializedComboPackage serialized = {};
|
||||||
serializedComboPackage << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_packageName << ','
|
strcpy_s(serialized.packageName, sizeof(serialized.packageName), m_packageName.c_str());
|
||||||
<< m_discountPercentage << ','
|
strcpy_s(serialized.serviceIDs, sizeof(serialized.serviceIDs), getServiceIDsAsString(m_serviceIDs).c_str());
|
||||||
<< getServiceIDsAsString(m_serviceIDs) << ','
|
serialized.discountPercentage = m_discountPercentage;
|
||||||
<< util::getStateString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedComboPackage.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a ComboPackage object.
|
Description: Deserializes a SerializedComboPackage record into a ComboPackage object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized combo package record
|
- serializedComboPackage: const SerializedComboPackage&, serialized combo package record
|
||||||
Returns:
|
Returns:
|
||||||
- ComboPackage*: Pointer to the deserialized ComboPackage object
|
- ComboPackage*: Pointer to the deserialized ComboPackage object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if data is invalid
|
|
||||||
*/
|
*/
|
||||||
ComboPackage* ComboPackage::deserialize(const std::string& record)
|
ComboPackage* ComboPackage::deserialize(const SerializedComboPackage& serializedComboPackage)
|
||||||
{
|
{
|
||||||
std::string id, packageName;
|
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serializedComboPackage.serviceIDs);
|
||||||
std::string discountPercentageString, serviceIDsString, statusString;
|
|
||||||
double discountPercentage;
|
|
||||||
std::istringstream serializedComboPackage(record);
|
|
||||||
getline(serializedComboPackage, id, ',');
|
|
||||||
getline(serializedComboPackage, packageName, ',');
|
|
||||||
getline(serializedComboPackage, discountPercentageString, ',');
|
|
||||||
getline(serializedComboPackage, serviceIDsString, ',');
|
|
||||||
getline(serializedComboPackage, statusString, ',');
|
|
||||||
try
|
|
||||||
{
|
|
||||||
discountPercentage = std::stod(discountPercentageString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid combo package data");
|
|
||||||
}
|
|
||||||
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serviceIDsString);
|
|
||||||
util::State status = util::getState(statusString);
|
|
||||||
return Factory::getObject<ComboPackage>(
|
return Factory::getObject<ComboPackage>(
|
||||||
id,
|
serializedComboPackage.id,
|
||||||
packageName,
|
serializedComboPackage.packageName,
|
||||||
discountPercentage,
|
serializedComboPackage.discountPercentage,
|
||||||
serviceIDs,
|
serviceIDs,
|
||||||
status
|
serializedComboPackage.status);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for combo package serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,PackageName,DiscountPercentage,ServiceIDs,Status")
|
|
||||||
*/
|
|
||||||
std::string ComboPackage::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,PackageName,DiscountPercentage,ServiceIDs,Status";
|
|
||||||
}
|
|
||||||
@@ -12,6 +12,7 @@ Date: 19-May-2026
|
|||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|
||||||
class Service;
|
class Service;
|
||||||
|
class SerializedComboPackage;
|
||||||
|
|
||||||
class ComboPackage
|
class ComboPackage
|
||||||
{
|
{
|
||||||
@@ -38,7 +39,6 @@ public:
|
|||||||
void setDiscountPercentage(double discountPercentage);
|
void setDiscountPercentage(double discountPercentage);
|
||||||
void setServices(const util::Map<std::string, Service*>& services);
|
void setServices(const util::Map<std::string, Service*>& services);
|
||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
std::string serialize() const;
|
SerializedComboPackage serialize() const;
|
||||||
static ComboPackage* deserialize(const std::string&);
|
static ComboPackage* deserialize(const SerializedComboPackage&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
+19
-54
@@ -8,6 +8,7 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
#include "InventoryItem.h"
|
#include "InventoryItem.h"
|
||||||
@@ -206,73 +207,37 @@ void InventoryItem::setState(util::State status)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the inventory item into a CSV-formatted string.
|
Description: Serializes the InventoryItem object into a SerializedInventoryItem record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized inventory item record
|
- SerializedInventoryItem: Serialized representation of the inventory item
|
||||||
*/
|
*/
|
||||||
std::string InventoryItem::serialize() const
|
SerializedInventoryItem InventoryItem::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedInventoryItem;
|
SerializedInventoryItem serialized = {};
|
||||||
serializedInventoryItem << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_partName << ','
|
strcpy_s(serialized.partName, sizeof(serialized.partName), m_partName.c_str());
|
||||||
<< m_quantity << ','
|
serialized.quantity = m_quantity;
|
||||||
<< m_price << ','
|
serialized.price = m_price;
|
||||||
<< util::getStateString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedInventoryItem.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into an InventoryItem object.
|
Description: Deserializes a SerializedInventoryItem record into an InventoryItem object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized inventory item record
|
- serializedInventoryItem: const SerializedInventoryItem&, serialized inventory item record
|
||||||
Returns:
|
Returns:
|
||||||
- InventoryItem*: Pointer to the deserialized InventoryItem object
|
- InventoryItem*: Pointer to the deserialized InventoryItem object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if data is invalid
|
|
||||||
*/
|
*/
|
||||||
InventoryItem* InventoryItem::deserialize(const std::string& record)
|
InventoryItem* InventoryItem::deserialize(const SerializedInventoryItem& serializedInventoryItem)
|
||||||
{
|
{
|
||||||
std::string id, partName;
|
|
||||||
std::string quantityString, priceString, statusString;
|
|
||||||
int quantity;
|
|
||||||
double price;
|
|
||||||
std::istringstream serializedInventoryItem(record);
|
|
||||||
getline(serializedInventoryItem, id, ',');
|
|
||||||
getline(serializedInventoryItem, partName, ',');
|
|
||||||
getline(serializedInventoryItem, quantityString, ',');
|
|
||||||
getline(serializedInventoryItem, priceString, ',');
|
|
||||||
getline(serializedInventoryItem, statusString, ',');
|
|
||||||
try
|
|
||||||
{
|
|
||||||
quantity = std::stoi(quantityString);
|
|
||||||
price = std::stod(priceString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid inventory item data");
|
|
||||||
}
|
|
||||||
util::State status = util::getState(statusString);
|
|
||||||
return Factory::getObject<InventoryItem>(
|
return Factory::getObject<InventoryItem>(
|
||||||
id,
|
serializedInventoryItem.id,
|
||||||
partName,
|
serializedInventoryItem.partName,
|
||||||
quantity,
|
serializedInventoryItem.quantity,
|
||||||
price,
|
serializedInventoryItem.price,
|
||||||
status
|
serializedInventoryItem.status);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for inventory item serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,PartName,Quantity,Price,Status")
|
|
||||||
*/
|
|
||||||
std::string InventoryItem::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,PartName,Quantity,Price,Status";
|
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,12 @@ Author: Trenser
|
|||||||
Date: 19-May-2026
|
Date: 19-May-2026
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|
||||||
|
struct SerializedInventoryItem;
|
||||||
|
|
||||||
class InventoryItem
|
class InventoryItem
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -34,7 +35,6 @@ public:
|
|||||||
void setQuantity(int quantity);
|
void setQuantity(int quantity);
|
||||||
void setPrice(double price);
|
void setPrice(double price);
|
||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
std::string serialize() const;
|
SerializedInventoryItem serialize() const;
|
||||||
static InventoryItem* deserialize(const std::string&);
|
static InventoryItem* deserialize(const SerializedInventoryItem&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
@@ -9,6 +9,7 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "Invoice.h"
|
#include "Invoice.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
#include "InventoryItem.h"
|
#include "InventoryItem.h"
|
||||||
@@ -473,100 +474,50 @@ static util::Vector<std::string> getPartIDsAsVector(const std::string& partIDsSt
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the invoice into a CSV-formatted string.
|
Description: Serializes the Invoice object into a SerializedInvoice record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized invoice record
|
- SerializedInvoice: Serialized representation of the invoice
|
||||||
*/
|
*/
|
||||||
std::string Invoice::serialize() const
|
SerializedInvoice Invoice::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedInvoice;
|
SerializedInvoice serialized = {};
|
||||||
serializedInvoice << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_bookingId << ','
|
strcpy_s(serialized.bookingId, sizeof(serialized.bookingId), m_bookingId.c_str());
|
||||||
<< m_invoiceDate.toString() << ','
|
strcpy_s(serialized.partIDs, sizeof(serialized.partIDs), getPartIDsAsString(m_partIDs).c_str());
|
||||||
<< m_laborCost << ','
|
serialized.invoiceDate = m_invoiceDate;
|
||||||
<< getPartIDsAsString(m_partIDs) << ','
|
serialized.laborCost = m_laborCost;
|
||||||
<< m_partsCost << ','
|
serialized.partsCost = m_partsCost;
|
||||||
<< m_discountPercentage << ','
|
serialized.discountPercentage = m_discountPercentage;
|
||||||
<< m_totalAmount << ','
|
serialized.totalAmount = m_totalAmount;
|
||||||
<< m_paymentDate.toString() << ','
|
serialized.paymentDate = m_paymentDate;
|
||||||
<< util::getPaymentModeString(m_paymentMethod) << ','
|
serialized.paymentMethod = m_paymentMethod;
|
||||||
<< util::getPaymentStatusString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedInvoice.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into an Invoice object.
|
Description: Deserializes a SerializedInvoice record into an Invoice object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized invoice record
|
- serializedInvoice: const SerializedInvoice&, serialized invoice record
|
||||||
Returns:
|
Returns:
|
||||||
- Invoice*: Pointer to the deserialized Invoice object
|
- Invoice*: Pointer to the deserialized Invoice object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if data is invalid
|
|
||||||
*/
|
*/
|
||||||
Invoice* Invoice::deserialize(const std::string& record)
|
Invoice* Invoice::deserialize(const SerializedInvoice& serializedInvoice)
|
||||||
{
|
{
|
||||||
std::string id, bookingId;
|
util::Vector<std::string> partIDs = getPartIDsAsVector(serializedInvoice.partIDs);
|
||||||
std::string invoiceDateString, laborCostString, partIDsString;
|
|
||||||
std::string partsCostString, discountPercentageString, totalAmountString;
|
|
||||||
std::string paymentDateString, paymentMethodString, statusString;
|
|
||||||
double laborCost, partsCost, discountPercentage, totalAmount;
|
|
||||||
std::istringstream serializedInvoice(record);
|
|
||||||
getline(serializedInvoice, id, ',');
|
|
||||||
getline(serializedInvoice, bookingId, ',');
|
|
||||||
getline(serializedInvoice, invoiceDateString, ',');
|
|
||||||
getline(serializedInvoice, laborCostString, ',');
|
|
||||||
getline(serializedInvoice, partIDsString, ',');
|
|
||||||
getline(serializedInvoice, partsCostString, ',');
|
|
||||||
getline(serializedInvoice, discountPercentageString, ',');
|
|
||||||
getline(serializedInvoice, totalAmountString, ',');
|
|
||||||
getline(serializedInvoice, paymentDateString, ',');
|
|
||||||
getline(serializedInvoice, paymentMethodString, ',');
|
|
||||||
getline(serializedInvoice, statusString, ',');
|
|
||||||
util::Timestamp invoiceDate;
|
|
||||||
util::Timestamp paymentDate;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
invoiceDate = util::Timestamp::fromString(invoiceDateString);
|
|
||||||
paymentDate = util::Timestamp::fromString(paymentDateString);
|
|
||||||
laborCost = std::stod(laborCostString);
|
|
||||||
partsCost = std::stod(partsCostString);
|
|
||||||
discountPercentage = std::stod(discountPercentageString);
|
|
||||||
totalAmount = std::stod(totalAmountString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid invoice data");
|
|
||||||
}
|
|
||||||
util::Vector<std::string> partIDs = getPartIDsAsVector(partIDsString);
|
|
||||||
util::PaymentMode paymentMethod = util::getPaymentMode(paymentMethodString);
|
|
||||||
util::PaymentStatus status = util::getPaymentStatus(statusString);
|
|
||||||
return Factory::getObject<Invoice>(
|
return Factory::getObject<Invoice>(
|
||||||
id,
|
serializedInvoice.id,
|
||||||
bookingId,
|
serializedInvoice.bookingId,
|
||||||
invoiceDate,
|
serializedInvoice.invoiceDate,
|
||||||
partIDs,
|
partIDs,
|
||||||
laborCost,
|
serializedInvoice.laborCost,
|
||||||
partsCost,
|
serializedInvoice.partsCost,
|
||||||
discountPercentage,
|
serializedInvoice.discountPercentage,
|
||||||
totalAmount,
|
serializedInvoice.totalAmount,
|
||||||
paymentDate,
|
serializedInvoice.paymentDate,
|
||||||
paymentMethod,
|
serializedInvoice.paymentMethod,
|
||||||
status
|
serializedInvoice.status);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for invoice serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,BookingID,InvoiceDate,LaborCost,PartIDs,PartsCost,DiscountPercentage,TotalAmount,PaymentDate,PaymentMethod,Status")
|
|
||||||
*/
|
|
||||||
std::string Invoice::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,BookingID,InvoiceDate,LaborCost,PartIDs,PartsCost,DiscountPercentage,TotalAmount,PaymentDate,PaymentMethod,Status";
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,7 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
class ServiceBooking;
|
class ServiceBooking;
|
||||||
class InventoryItem;
|
class InventoryItem;
|
||||||
|
struct SerializedInvoice;
|
||||||
|
|
||||||
class Invoice
|
class Invoice
|
||||||
{
|
{
|
||||||
@@ -87,7 +88,6 @@ public:
|
|||||||
void setPaymentDate(const util::Timestamp& paymentDate);
|
void setPaymentDate(const util::Timestamp& paymentDate);
|
||||||
void setPaymentMethod(util::PaymentMode paymentMethod);
|
void setPaymentMethod(util::PaymentMode paymentMethod);
|
||||||
void setStatus(util::PaymentStatus status);
|
void setStatus(util::PaymentStatus status);
|
||||||
std::string serialize() const;
|
SerializedInvoice serialize() const;
|
||||||
static Invoice* deserialize(const std::string&);
|
static Invoice* deserialize(const SerializedInvoice&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
@@ -9,6 +9,7 @@ Date:19-May-2026
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "JobCard.h"
|
#include "JobCard.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
@@ -351,79 +352,41 @@ void JobCard::setCompletionDate(const util::Timestamp& completionDate)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the job card into a CSV-formatted string.
|
Description: Serializes the JobCard object into a SerializedJobCard record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized job card record
|
- SerializedJobCard: Serialized representation of the job card
|
||||||
*/
|
*/
|
||||||
std::string JobCard::serialize() const
|
SerializedJobCard JobCard::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedJobCard;
|
SerializedJobCard serialized = {};
|
||||||
serializedJobCard << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_bookingId << ','
|
strcpy_s(serialized.bookingId, sizeof(serialized.bookingId), m_bookingId.c_str());
|
||||||
<< m_serviceId << ','
|
strcpy_s(serialized.serviceId, sizeof(serialized.serviceId), m_serviceId.c_str());
|
||||||
<< m_technicianId << ','
|
strcpy_s(serialized.technicianId, sizeof(serialized.technicianId), m_technicianId.c_str());
|
||||||
<< m_assignedDate.toString() << ','
|
serialized.assignedDate = m_assignedDate;
|
||||||
<< util::getServiceJobStatusString(m_status) << ','
|
serialized.status = m_status;
|
||||||
<< m_completionDate.toString();
|
serialized.completionDate = m_completionDate;
|
||||||
return serializedJobCard.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a JobCard object.
|
Description: Deserializes a SerializedJobCard record into a JobCard object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized job card record
|
- serializedJobCard: const SerializedJobCard&, serialized job card record
|
||||||
Returns:
|
Returns:
|
||||||
- JobCard*: Pointer to the deserialized JobCard object
|
- JobCard*: Pointer to the deserialized JobCard object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if timestamp parsing fails
|
|
||||||
*/
|
*/
|
||||||
JobCard* JobCard::deserialize(const std::string& record)
|
JobCard* JobCard::deserialize(const SerializedJobCard& serializedJobCard)
|
||||||
{
|
{
|
||||||
std::string id, bookingId, serviceId, technicianId;
|
|
||||||
std::string assignedDateString, statusString, completionDateString;
|
|
||||||
std::istringstream serializedJobCard(record);
|
|
||||||
getline(serializedJobCard, id, ',');
|
|
||||||
getline(serializedJobCard, bookingId, ',');
|
|
||||||
getline(serializedJobCard, serviceId, ',');
|
|
||||||
getline(serializedJobCard, technicianId, ',');
|
|
||||||
getline(serializedJobCard, assignedDateString, ',');
|
|
||||||
getline(serializedJobCard, statusString, ',');
|
|
||||||
getline(serializedJobCard, completionDateString, ',');
|
|
||||||
util::Timestamp assignedDate;
|
|
||||||
util::Timestamp completionDate;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
assignedDate = util::Timestamp::fromString(assignedDateString);
|
|
||||||
completionDate = util::Timestamp::fromString(completionDateString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid timestamp");
|
|
||||||
}
|
|
||||||
util::ServiceJobStatus status = util::getServiceJobStatus(statusString);
|
|
||||||
return Factory::getObject<JobCard>(
|
return Factory::getObject<JobCard>(
|
||||||
id,
|
serializedJobCard.id,
|
||||||
bookingId,
|
serializedJobCard.bookingId,
|
||||||
serviceId,
|
serializedJobCard.serviceId,
|
||||||
technicianId,
|
serializedJobCard.technicianId,
|
||||||
assignedDate,
|
serializedJobCard.assignedDate,
|
||||||
status,
|
serializedJobCard.status,
|
||||||
completionDate
|
serializedJobCard.completionDate);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for job card serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,BookingID,ServiceID,TechnicianID,AssignedDate,Status,CompletionDate")
|
|
||||||
*/
|
|
||||||
std::string JobCard::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,BookingID,ServiceID,TechnicianID,AssignedDate,Status,CompletionDate";
|
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ Date:19-May-2026
|
|||||||
class ServiceBooking;
|
class ServiceBooking;
|
||||||
class Service;
|
class Service;
|
||||||
class User;
|
class User;
|
||||||
|
struct SerializedJobCard;
|
||||||
|
|
||||||
class JobCard
|
class JobCard
|
||||||
{
|
{
|
||||||
@@ -70,7 +71,6 @@ public:
|
|||||||
void setAssignedDate(const util::Timestamp& assignedDate);
|
void setAssignedDate(const util::Timestamp& assignedDate);
|
||||||
void setStatus(util::ServiceJobStatus status);
|
void setStatus(util::ServiceJobStatus status);
|
||||||
void setCompletionDate(const util::Timestamp& completionDate);
|
void setCompletionDate(const util::Timestamp& completionDate);
|
||||||
std::string serialize() const;
|
SerializedJobCard serialize() const;
|
||||||
static JobCard* deserialize(const std::string&);
|
static JobCard* deserialize(const SerializedJobCard&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
@@ -7,6 +7,7 @@ Date: 19-May-2026
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "Notification.h"
|
#include "Notification.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
#include "Factory.h"
|
#include "Factory.h"
|
||||||
@@ -23,7 +24,7 @@ Returns:
|
|||||||
*/
|
*/
|
||||||
Notification::Notification()
|
Notification::Notification()
|
||||||
: m_id("NOT" + std::to_string(++m_uid)),
|
: m_id("NOT" + std::to_string(++m_uid)),
|
||||||
m_recipient(nullptr) {}
|
m_recipient(nullptr), m_state(util::State::ACTIVE) {}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: Notification
|
Function: Notification
|
||||||
@@ -43,7 +44,8 @@ Notification::Notification(const std::string& recipientUserId, User* recipient,
|
|||||||
m_recipient(recipient),
|
m_recipient(recipient),
|
||||||
m_title(title),
|
m_title(title),
|
||||||
m_message(message),
|
m_message(message),
|
||||||
m_createdAt(createdAt) {}
|
m_state(util::State::ACTIVE),
|
||||||
|
m_createdAt(createdAt){}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: Notification (parameterized constructor with ID)
|
Function: Notification (parameterized constructor with ID)
|
||||||
@@ -58,13 +60,14 @@ Parameters:
|
|||||||
Returns:
|
Returns:
|
||||||
- A new Notification object
|
- A new Notification object
|
||||||
*/
|
*/
|
||||||
Notification::Notification(const std::string& id, const std::string& recipientUserId, const std::string& title, const std::string& message, const util::Timestamp& createdAt)
|
Notification::Notification(const std::string& id, const std::string& recipientUserId, const std::string& title, const std::string& message, const util::Timestamp& createdAt, const util::State& state)
|
||||||
: m_id(id),
|
: m_id(id),
|
||||||
m_recipientUserId(recipientUserId),
|
m_recipientUserId(recipientUserId),
|
||||||
m_recipient(nullptr),
|
m_recipient(nullptr),
|
||||||
m_title(title),
|
m_title(title),
|
||||||
m_message(message),
|
m_message(message),
|
||||||
m_createdAt(createdAt)
|
m_createdAt(createdAt),
|
||||||
|
m_state(state)
|
||||||
{
|
{
|
||||||
int idNumber = util::extractNumber(m_id);
|
int idNumber = util::extractNumber(m_id);
|
||||||
if (idNumber > m_uid)
|
if (idNumber > m_uid)
|
||||||
@@ -219,69 +222,39 @@ void Notification::setCreatedAt(const util::Timestamp& createdAt)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the notification into a CSV-formatted string.
|
Description: Serializes the Notification object into a SerializedNotification record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized notification record
|
- SerializedNotification: Serialized representation of the notification
|
||||||
*/
|
*/
|
||||||
std::string Notification::serialize() const
|
SerializedNotification Notification::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedNotification;
|
SerializedNotification serialized = {};
|
||||||
serializedNotification << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_recipientUserId << ','
|
strcpy_s(serialized.recipientUserId, sizeof(serialized.recipientUserId), m_recipientUserId.c_str());
|
||||||
<< m_title << ','
|
strcpy_s(serialized.title, sizeof(serialized.title), m_title.c_str());
|
||||||
<< m_message << ','
|
strcpy_s(serialized.message, sizeof(serialized.message), m_message.c_str());
|
||||||
<< m_createdAt.toString();
|
serialized.createdAt = m_createdAt;
|
||||||
return serializedNotification.str();
|
serialized.state = m_state;
|
||||||
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a Notification object.
|
Description: Deserializes a SerializedNotification record into a Notification object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized notification record
|
- serializedNotification: const SerializedNotification&, serialized notification record
|
||||||
Returns:
|
Returns:
|
||||||
- Notification*: Pointer to the deserialized Notification object
|
- Notification*: Pointer to the deserialized Notification object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if timestamp parsing fails
|
|
||||||
*/
|
*/
|
||||||
Notification* Notification::deserialize(const std::string& record)
|
Notification* Notification::deserialize(const SerializedNotification& serializedNotification)
|
||||||
{
|
{
|
||||||
std::string id, recipientUserId, title, message, createdAtTimestampString;
|
|
||||||
std::istringstream serializedNotification(record);
|
|
||||||
getline(serializedNotification, id, ',');
|
|
||||||
getline(serializedNotification, recipientUserId, ',');
|
|
||||||
getline(serializedNotification, title, ',');
|
|
||||||
getline(serializedNotification, message, ',');
|
|
||||||
getline(serializedNotification, createdAtTimestampString, ',');
|
|
||||||
util::Timestamp createdAtTimestamp;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
createdAtTimestamp = util::Timestamp::fromString(createdAtTimestampString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid createdAt timestamp");
|
|
||||||
}
|
|
||||||
return Factory::getObject<Notification>(
|
return Factory::getObject<Notification>(
|
||||||
id,
|
serializedNotification.id,
|
||||||
recipientUserId,
|
serializedNotification.recipientUserId,
|
||||||
title,
|
serializedNotification.title,
|
||||||
message,
|
serializedNotification.message,
|
||||||
createdAtTimestamp
|
serializedNotification.createdAt,
|
||||||
);
|
serializedNotification.state);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for notification serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,RecipientID,Title,Message,Timestamp")
|
|
||||||
*/
|
|
||||||
std::string Notification::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,RecipientID,Title,Message,Timestamp";
|
|
||||||
}
|
}
|
||||||
@@ -9,8 +9,10 @@ Date: 19-May-2026
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
|
#include "Enums.h"
|
||||||
|
|
||||||
class User;
|
class User;
|
||||||
|
struct SerializedNotification;
|
||||||
|
|
||||||
class Notification
|
class Notification
|
||||||
{
|
{
|
||||||
@@ -22,10 +24,11 @@ private:
|
|||||||
std::string m_title;
|
std::string m_title;
|
||||||
std::string m_message;
|
std::string m_message;
|
||||||
util::Timestamp m_createdAt;
|
util::Timestamp m_createdAt;
|
||||||
|
util::State m_state;
|
||||||
public:
|
public:
|
||||||
Notification();
|
Notification();
|
||||||
Notification(const std::string& recipientUserId, User* recipient, const std::string& title, const std::string& message, const util::Timestamp& createdAt);
|
Notification(const std::string& recipientUserId, User* recipient, const std::string& title, const std::string& message, const util::Timestamp& createdAt);
|
||||||
Notification(const std::string& id, const std::string& recipientUserId, const std::string& title, const std::string& message, const util::Timestamp& createdAt);
|
Notification(const std::string& id, const std::string& recipientUserId, const std::string& title, const std::string& message, const util::Timestamp& createdAt, const util::State& state);
|
||||||
const std::string& getId() const;
|
const std::string& getId() const;
|
||||||
const std::string& getRecipientUserId() const;
|
const std::string& getRecipientUserId() const;
|
||||||
User* getRecipient() const;
|
User* getRecipient() const;
|
||||||
@@ -38,7 +41,8 @@ public:
|
|||||||
void setTitle(const std::string& title);
|
void setTitle(const std::string& title);
|
||||||
void setMessage(const std::string& message);
|
void setMessage(const std::string& message);
|
||||||
void setCreatedAt(const util::Timestamp& createdAt);
|
void setCreatedAt(const util::Timestamp& createdAt);
|
||||||
std::string serialize() const;
|
util::State getState();
|
||||||
static Notification* deserialize(const std::string&);
|
void setState(util::State state);
|
||||||
static std::string getHeaders();
|
SerializedNotification serialize() const;
|
||||||
|
static Notification* deserialize(const SerializedNotification&);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ Date: 19-May-2026
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "Service.h"
|
#include "Service.h"
|
||||||
#include "InventoryItem.h"
|
#include "InventoryItem.h"
|
||||||
#include "StringHelper.h"
|
#include "StringHelper.h"
|
||||||
@@ -266,72 +267,38 @@ static util::Vector<std::string> getInventoryItemIDsAsVector(const std::string&
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the service into a CSV-formatted string.
|
Description: Serializes the Service object into a SerializedService record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized service record
|
- SerializedService: Serialized representation of the service
|
||||||
*/
|
*/
|
||||||
std::string Service::serialize() const
|
SerializedService Service::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedService;
|
SerializedService serialized = {};
|
||||||
serializedService << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_name << ','
|
strcpy_s(serialized.name, sizeof(serialized.name), m_name.c_str());
|
||||||
<< getInventoryItemIDsAsString(m_requiredInventoryItemIDs) << ','
|
strcpy_s(serialized.inventoryItemIDs, sizeof(serialized.inventoryItemIDs), getInventoryItemIDsAsString(m_requiredInventoryItemIDs).c_str());
|
||||||
<< m_laborCost << ','
|
serialized.laborCost = m_laborCost;
|
||||||
<< util::getStateString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedService.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a Service object.
|
Description: Deserializes a SerializedService record into a Service object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized service record
|
- serializedService: const SerializedService&, serialized service record
|
||||||
Returns:
|
Returns:
|
||||||
- Service*: Pointer to the deserialized Service object
|
- Service*: Pointer to the deserialized Service object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if labor cost parsing fails
|
|
||||||
*/
|
*/
|
||||||
Service* Service::deserialize(const std::string& record)
|
Service* Service::deserialize(const SerializedService& serializedService)
|
||||||
{
|
{
|
||||||
std::string id, name;
|
util::Vector<std::string> inventoryItemIDs = getInventoryItemIDsAsVector(serializedService.inventoryItemIDs);
|
||||||
std::string inventoryItemIDsString, laborCostString, statusString;
|
|
||||||
double laborCost;
|
|
||||||
std::istringstream serializedService(record);
|
|
||||||
getline(serializedService, id, ',');
|
|
||||||
getline(serializedService, name, ',');
|
|
||||||
getline(serializedService, inventoryItemIDsString, ',');
|
|
||||||
getline(serializedService, laborCostString, ',');
|
|
||||||
getline(serializedService, statusString, ',');
|
|
||||||
util::Vector<std::string> inventoryItemIDs = getInventoryItemIDsAsVector(inventoryItemIDsString);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
laborCost = std::stod(laborCostString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid labor cost");
|
|
||||||
}
|
|
||||||
util::State status = util::getState(statusString);
|
|
||||||
return Factory::getObject<Service>(
|
return Factory::getObject<Service>(
|
||||||
id,
|
serializedService.id,
|
||||||
name,
|
serializedService.name,
|
||||||
inventoryItemIDs,
|
inventoryItemIDs,
|
||||||
laborCost,
|
serializedService.laborCost,
|
||||||
status
|
serializedService.status);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for service serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,Name,InventoryIDs,LaborCost,Status")
|
|
||||||
*/
|
|
||||||
std::string Service::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,Name,InventoryIDs,LaborCost,Status";
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ Date: 19-May-2026
|
|||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|
||||||
class InventoryItem;
|
class InventoryItem;
|
||||||
|
struct SerializedService;
|
||||||
|
|
||||||
class Service
|
class Service
|
||||||
{
|
{
|
||||||
@@ -40,7 +41,6 @@ public:
|
|||||||
void setRequiredInventoryItems(const util::Map<std::string, InventoryItem*>& requiredInventoryItems);
|
void setRequiredInventoryItems(const util::Map<std::string, InventoryItem*>& requiredInventoryItems);
|
||||||
void setLaborCost(double laborCost);
|
void setLaborCost(double laborCost);
|
||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
std::string serialize() const;
|
SerializedService serialize() const;
|
||||||
static Service* deserialize(const std::string&);
|
static Service* deserialize(const SerializedService&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
+27
-64
@@ -8,6 +8,7 @@ Date:19-May-2026
|
|||||||
*/
|
*/
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "ServiceBooking.h"
|
#include "ServiceBooking.h"
|
||||||
#include "Service.h"
|
#include "Service.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
@@ -437,84 +438,46 @@ static util::Vector<std::string> getServiceIDsAsVector(const std::string& servic
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the service booking into a CSV-formatted string.
|
Description: Serializes the ServiceBooking object into a SerializedServiceBooking record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized booking record
|
- SerializedServiceBooking: Serialized representation of the service booking
|
||||||
*/
|
*/
|
||||||
std::string ServiceBooking::serialize() const
|
SerializedServiceBooking ServiceBooking::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedBooking;
|
SerializedServiceBooking serialized = {};
|
||||||
serializedBooking << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< util::getServiceJobStatusString(m_status) << ','
|
strcpy_s(serialized.serviceIDs, sizeof(serialized.serviceIDs), getServiceIDsAsString(m_serviceIDs).c_str());
|
||||||
<< getServiceIDsAsString(m_serviceIDs) << ','
|
strcpy_s(serialized.customerId, sizeof(serialized.customerId), m_customerId.c_str());
|
||||||
<< m_customerId << ','
|
strcpy_s(serialized.vehicleNumber, sizeof(serialized.vehicleNumber), m_vehicleNumber.c_str());
|
||||||
<< m_vehicleNumber << ','
|
strcpy_s(serialized.vehicleBrand, sizeof(serialized.vehicleBrand), m_vehicleBrand.c_str());
|
||||||
<< m_vehicleBrand << ','
|
strcpy_s(serialized.vehicleModel, sizeof(serialized.vehicleModel), m_vehicleModel.c_str());
|
||||||
<< m_vehicleModel << ','
|
strcpy_s(serialized.assignedTechnicianId, sizeof(serialized.assignedTechnicianId), m_assignedTechnicianId.c_str());
|
||||||
<< m_assignedTechnicianId << ','
|
serialized.status = m_status;
|
||||||
<< m_discountPercentage << ',';
|
serialized.discountPercentage = m_discountPercentage;
|
||||||
return serializedBooking.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a ServiceBooking object.
|
Description: Deserializes a SerializedServiceBooking record into a ServiceBooking object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized booking record
|
- serializedServiceBooking: const SerializedServiceBooking&, serialized service booking record
|
||||||
Returns:
|
Returns:
|
||||||
- ServiceBooking*: Pointer to the deserialized ServiceBooking object
|
- ServiceBooking*: Pointer to the deserialized ServiceBooking object
|
||||||
Throws:
|
|
||||||
- std::runtime_error if discount percentage parsing fails
|
|
||||||
*/
|
*/
|
||||||
ServiceBooking* ServiceBooking::deserialize(const std::string& record)
|
ServiceBooking* ServiceBooking::deserialize(const SerializedServiceBooking& serializedServiceBooking)
|
||||||
{
|
{
|
||||||
std::string id, customerId, vehicleNumber, vehicleBrand, vehicleModel, assignedTechnicianId;
|
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serializedServiceBooking.serviceIDs);
|
||||||
std::string serviceJobStatusString, serviceIDsString, discountPercentageString;
|
|
||||||
double discountPercentage;
|
|
||||||
std::istringstream serializedBooking(record);
|
|
||||||
getline(serializedBooking, id, ',');
|
|
||||||
getline(serializedBooking, serviceJobStatusString, ',');
|
|
||||||
getline(serializedBooking, serviceIDsString, ',');
|
|
||||||
getline(serializedBooking, customerId, ',');
|
|
||||||
getline(serializedBooking, vehicleNumber, ',');
|
|
||||||
getline(serializedBooking, vehicleBrand, ',');
|
|
||||||
getline(serializedBooking, vehicleModel, ',');
|
|
||||||
getline(serializedBooking, assignedTechnicianId, ',');
|
|
||||||
getline(serializedBooking, discountPercentageString, ',');
|
|
||||||
util::Vector<std::string> serviceIDs = getServiceIDsAsVector(serviceIDsString);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
discountPercentage = std::stod(discountPercentageString);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid discount percentage");
|
|
||||||
}
|
|
||||||
util::ServiceJobStatus status = util::getServiceJobStatus(serviceJobStatusString);
|
|
||||||
return Factory::getObject<ServiceBooking>(
|
return Factory::getObject<ServiceBooking>(
|
||||||
id,
|
serializedServiceBooking.id,
|
||||||
status,
|
serializedServiceBooking.status,
|
||||||
serviceIDs,
|
serviceIDs,
|
||||||
customerId,
|
serializedServiceBooking.customerId,
|
||||||
vehicleNumber,
|
serializedServiceBooking.vehicleNumber,
|
||||||
vehicleBrand,
|
serializedServiceBooking.vehicleBrand,
|
||||||
vehicleModel,
|
serializedServiceBooking.vehicleModel,
|
||||||
assignedTechnicianId,
|
serializedServiceBooking.assignedTechnicianId,
|
||||||
discountPercentage
|
serializedServiceBooking.discountPercentage);
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for service booking serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,Status,ServiceIDs,CustomerID,VehicleNumber,VehicleBrand,VehicleModel,AssignedTechnicianID,DiscountPercentage")
|
|
||||||
*/
|
|
||||||
std::string ServiceBooking::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,Status,ServiceIDs,CustomerID,VehicleNumber,VehicleBrand,VehicleModel,AssignedTechnicianID,DiscountPercentage";
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ Date:19-May-2026
|
|||||||
|
|
||||||
class Service;
|
class Service;
|
||||||
class User;
|
class User;
|
||||||
|
struct SerializedServiceBooking;
|
||||||
|
|
||||||
class ServiceBooking
|
class ServiceBooking
|
||||||
{
|
{
|
||||||
@@ -78,7 +79,6 @@ public:
|
|||||||
void setAssignedTechnicianId(const std::string& assignedTechnicianId);
|
void setAssignedTechnicianId(const std::string& assignedTechnicianId);
|
||||||
void setAssignedTechnician(User* assignedTechnician);
|
void setAssignedTechnician(User* assignedTechnician);
|
||||||
void setDiscountPercentage(double discountPercentage);
|
void setDiscountPercentage(double discountPercentage);
|
||||||
std::string serialize() const;
|
SerializedServiceBooking serialize() const;
|
||||||
static ServiceBooking* deserialize(const std::string&);
|
static ServiceBooking* deserialize(const SerializedServiceBooking&);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
@@ -8,6 +8,7 @@ Date: 19-May-2026
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "SerializedRecords.h"
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
#include "Notification.h"
|
#include "Notification.h"
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
@@ -324,68 +325,43 @@ void User::setState(util::State status)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: serialize
|
Function: serialize
|
||||||
Description: Serializes the user into a CSV-formatted string.
|
Description: Serializes the User object into a SerializedUser record.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- std::string: Serialized user record
|
- SerializedUser: Serialized representation of the user
|
||||||
*/
|
*/
|
||||||
std::string User::serialize() const
|
SerializedUser User::serialize() const
|
||||||
{
|
{
|
||||||
std::ostringstream serializedUser;
|
SerializedUser serialized = {};
|
||||||
serializedUser << m_id << ','
|
strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str());
|
||||||
<< m_userName << ','
|
strcpy_s(serialized.username, sizeof(serialized.username), m_userName.c_str());
|
||||||
<< m_password << ','
|
strcpy_s(serialized.password, sizeof(serialized.password), m_password.c_str());
|
||||||
<< m_name << ','
|
strcpy_s(serialized.name, sizeof(serialized.name), m_name.c_str());
|
||||||
<< m_phone << ','
|
strcpy_s(serialized.phone, sizeof(serialized.phone), m_phone.c_str());
|
||||||
<< m_email << ','
|
strcpy_s(serialized.email, sizeof(serialized.email), m_email.c_str());
|
||||||
<< util::getUserTypeString(m_type) << ','
|
serialized.userType = m_type;
|
||||||
<< util::getStateString(m_status);
|
serialized.status = m_status;
|
||||||
return serializedUser.str();
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: deserialize
|
Function: deserialize
|
||||||
Description: Deserializes a CSV-formatted string into a User object.
|
Description: Deserializes a SerializedUser record into a User object.
|
||||||
Parameters:
|
Parameters:
|
||||||
- record: const std::string&, serialized user record
|
- serializedUser: const SerializedUser&, serialized user record
|
||||||
Returns:
|
Returns:
|
||||||
- User*: Pointer to the deserialized User object
|
- User*: Pointer to the deserialized User object
|
||||||
*/
|
*/
|
||||||
User* User::deserialize(const std::string& record)
|
User* User::deserialize(const SerializedUser& serializedUser)
|
||||||
{
|
{
|
||||||
std::string id, name, username, phone, password, email;
|
return Factory::getObject<User>(
|
||||||
std::string userTypeString, stateString;
|
serializedUser.id,
|
||||||
std::istringstream serializedUser(record);
|
serializedUser.username,
|
||||||
getline(serializedUser, id, ',');
|
serializedUser.password,
|
||||||
getline(serializedUser, username, ',');
|
serializedUser.name,
|
||||||
getline(serializedUser, password, ',');
|
serializedUser.phone,
|
||||||
getline(serializedUser, name, ',');
|
serializedUser.email,
|
||||||
getline(serializedUser, phone, ',');
|
serializedUser.userType,
|
||||||
getline(serializedUser, email, ',');
|
serializedUser.status);
|
||||||
getline(serializedUser, userTypeString, ',');
|
|
||||||
getline(serializedUser, stateString);
|
|
||||||
util::UserType userType = util::getUserType(userTypeString);
|
|
||||||
util::State status = util::getState(stateString);
|
|
||||||
return Factory::getObject<User>(id,
|
|
||||||
username,
|
|
||||||
password,
|
|
||||||
name,
|
|
||||||
phone,
|
|
||||||
email,
|
|
||||||
userType,
|
|
||||||
status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getHeaders
|
|
||||||
Description: Retrieves the CSV headers for user serialization.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- std::string: Header string ("ID,Username,Password,Name,Phone,Email,UserType,UserStatus")
|
|
||||||
*/
|
|
||||||
std::string User::getHeaders()
|
|
||||||
{
|
|
||||||
return "ID,Username,Password,Name,Phone,Email,UserType,UserStatus";
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ Date: 19-May-2026
|
|||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
|
||||||
class Notification;
|
class Notification;
|
||||||
|
struct SerializedUser;
|
||||||
|
|
||||||
class User : public Observer
|
class User : public Observer
|
||||||
{
|
{
|
||||||
@@ -51,7 +52,6 @@ public:
|
|||||||
void addNotification(Notification* notification) override;
|
void addNotification(Notification* notification) override;
|
||||||
void setRole(util::UserType role);
|
void setRole(util::UserType role);
|
||||||
void setState(util::State status);
|
void setState(util::State status);
|
||||||
std::string serialize() const;
|
SerializedUser serialize() const;
|
||||||
static User* deserialize(const std::string&);
|
static User* deserialize(const SerializedUser& serializedUser);
|
||||||
static std::string getHeaders();
|
|
||||||
};
|
};
|
||||||
|
|||||||
+52
-50
@@ -543,50 +543,65 @@ static void restoreInventory(ServiceBooking* booking)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: processBookingCancellation
|
Function: processBookingCancellation
|
||||||
Description: Cancels jobs and updates the status of a given booking. Sends notifications to the
|
Description: Handles cancellation or reassignment of a service booking based on user type.
|
||||||
specified user, resets technician assignment if needed, and restores inventory items.
|
Cancels associated job cards, updates booking status, clears technician assignments,
|
||||||
Parameter: ServiceBooking* booking - Pointer to the booking being cancelled
|
restores inventory, and sends appropriate notifications.
|
||||||
util::ServiceJobStatus newServiceBookingStatus - New status to assign to the booking
|
Parameters:
|
||||||
const std::string& notificationTitle - Title of the booking cancellation notification
|
ServiceBooking* booking - The booking to cancel or reset
|
||||||
const std::string& notificationMessage - Message body of the booking cancellation notification
|
util::Map<std::string, JobCard*>& jobs - Collection of job cards to update
|
||||||
User* notifyUser - User to notify about the cancellation
|
ServiceManagementService& currentService - Service layer for notifications
|
||||||
util::ServiceJobStatus jobCardStatus - New status to assign to associated job cards
|
util::UserType userType - Type of user initiating cancellation (CUSTOMER or TECHNICIAN)
|
||||||
const std::string& jobNotificationTitle - Title of the job cancellation notification
|
|
||||||
const std::string& jobNotificationMessage - Message body of the job cancellation notification
|
|
||||||
util::Map<std::string, JobCard*>& jobs - Collection of job cards to update
|
|
||||||
ServiceManagementService& currentService - Reference to the service for sending notifications
|
|
||||||
Return type: void
|
Return type: void
|
||||||
*/
|
*/
|
||||||
static void processBookingCancellation(ServiceBooking* booking,
|
static void processBookingCancellation(ServiceBooking* booking,
|
||||||
util::ServiceJobStatus newServiceBookingStatus,
|
util::Map<std::string, JobCard*>& jobs,
|
||||||
const std::string& notificationTitle,
|
ServiceManagementService& currentService,
|
||||||
const std::string& notificationMessage,
|
util::UserType userType)
|
||||||
User* notifyUser,
|
|
||||||
util::ServiceJobStatus jobCardStatus,
|
|
||||||
const std::string& jobNotificationTitle,
|
|
||||||
const std::string& jobNotificationMessage,
|
|
||||||
util::Map<std::string, JobCard*>& jobs, ServiceManagementService& currentService)
|
|
||||||
{
|
{
|
||||||
if (!booking || !notifyUser)
|
if (!booking)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int jobIterator = 0; jobIterator < jobs.getSize(); ++jobIterator)
|
for (int jobIterator = 0; jobIterator < jobs.getSize(); ++jobIterator)
|
||||||
{
|
{
|
||||||
JobCard* jobCard = jobs.getValueAt(jobIterator);
|
JobCard* jobCard = jobs.getValueAt(jobIterator);
|
||||||
if (jobCard && jobCard->getBookingId() == booking->getId())
|
if (!jobCard || jobCard->getBookingId() != booking->getId() || jobCard->getStatus() == util::ServiceJobStatus::CANCELLED)
|
||||||
{
|
{
|
||||||
jobCard->setStatus(jobCardStatus);
|
continue;
|
||||||
currentService.sendNotification(notifyUser, jobNotificationTitle, jobNotificationMessage);
|
}
|
||||||
|
jobCard->setStatus(util::ServiceJobStatus::CANCELLED);
|
||||||
|
if (userType == util::UserType::CUSTOMER)
|
||||||
|
{
|
||||||
|
if (User* technician = booking->getAssignedTechnician())
|
||||||
|
{
|
||||||
|
const std::string jobTitle = "Job Cancelled";
|
||||||
|
const std::string jobMessage = "Your job card has been cancelled and the inventory has been restocked.";
|
||||||
|
currentService.sendNotification(technician, jobTitle, jobMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
booking->setStatus(newServiceBookingStatus);
|
if (userType == util::UserType::CUSTOMER)
|
||||||
currentService.sendNotification(notifyUser, notificationTitle, notificationMessage);
|
|
||||||
if (newServiceBookingStatus == util::ServiceJobStatus::PENDING)
|
|
||||||
{
|
{
|
||||||
booking->setAssignedTechnician(nullptr);
|
booking->setStatus(util::ServiceJobStatus::CANCELLED);
|
||||||
booking->setAssignedTechnicianId("");
|
if (User* technician = booking->getAssignedTechnician())
|
||||||
|
{
|
||||||
|
const std::string title = "Customer Service Cancelled";
|
||||||
|
const std::string message = "Your assigned job card has been cancelled and the inventory has been restocked.";
|
||||||
|
currentService.sendNotification(technician, title, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if (userType == util::UserType::TECHNICIAN)
|
||||||
|
{
|
||||||
|
booking->setStatus(util::ServiceJobStatus::PENDING);
|
||||||
|
if (User* customer = booking->getCustomer())
|
||||||
|
{
|
||||||
|
const std::string title = "Technician Unavailable";
|
||||||
|
const std::string message = "Your booking has been reset to pending and we will reassign a new technician shortly.";
|
||||||
|
currentService.sendNotification(customer, title, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
booking->setAssignedTechnician(nullptr);
|
||||||
|
booking->setAssignedTechnicianId("");
|
||||||
restoreInventory(booking);
|
restoreInventory(booking);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -624,21 +639,13 @@ void ServiceManagementService::cancelCustomerServiceBookings(const std::string&
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (booking->getStatus() != util::ServiceJobStatus::PENDING && booking->getStatus() != util::ServiceJobStatus::STARTED)
|
if (booking->getStatus() != util::ServiceJobStatus::PENDING &&
|
||||||
|
booking->getStatus() != util::ServiceJobStatus::STARTED &&
|
||||||
|
booking->getStatus() != util::ServiceJobStatus::IN_PROGRESS)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
User* assignedTechnician = booking->getAssignedTechnician();
|
processBookingCancellation(booking, jobs, *this, util::UserType::CUSTOMER);
|
||||||
std::string titleToTechnician = "Customer Service Cancelled";
|
|
||||||
std::string messageToTechnician = "The customer has cancelled their service booking. Your assigned job card has been cancelled and the inventory has been restocked.";
|
|
||||||
std::string jobTitle = "Job Cancelled";
|
|
||||||
std::string jobMessage = "The job has been cancelled. Your job card has been cancelled and the inventory has been restocked.";
|
|
||||||
processBookingCancellation(booking,
|
|
||||||
util::ServiceJobStatus::CANCELLED,
|
|
||||||
titleToTechnician, messageToTechnician, assignedTechnician,
|
|
||||||
util::ServiceJobStatus::CANCELLED,
|
|
||||||
jobTitle, jobMessage, jobs, *this
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,7 +683,9 @@ void ServiceManagementService::cancelTechnicianJobs(const std::string& technicia
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (booking->getStatus() != util::ServiceJobStatus::PENDING && booking->getStatus() != util::ServiceJobStatus::STARTED)
|
if (booking->getStatus() != util::ServiceJobStatus::PENDING &&
|
||||||
|
booking->getStatus() != util::ServiceJobStatus::STARTED &&
|
||||||
|
booking->getStatus() != util::ServiceJobStatus::IN_PROGRESS)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -685,14 +694,7 @@ void ServiceManagementService::cancelTechnicianJobs(const std::string& technicia
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::string title = "Technician Unavailable";
|
processBookingCancellation(booking, jobs, *this, util::UserType::TECHNICIAN);
|
||||||
std::string message = "Your assigned technician is no longer available. Your booking has been reset to pending and we will reassign a new technician shortly.";
|
|
||||||
processBookingCancellation(booking,
|
|
||||||
util::ServiceJobStatus::PENDING,
|
|
||||||
title, message, customer,
|
|
||||||
util::ServiceJobStatus::CANCELLED,
|
|
||||||
title, message, jobs, *this
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ namespace config
|
|||||||
|
|
||||||
namespace file
|
namespace file
|
||||||
{
|
{
|
||||||
|
const size_t INITIAL_CAPACITY = 100;
|
||||||
constexpr const char* INVENTORYITEM_FILE = "files/InventoryItem.csv";
|
constexpr const char* INVENTORYITEM_FILE = "files/InventoryItem.csv";
|
||||||
constexpr const char* USER_FILE = "files/User.csv";
|
constexpr const char* USER_FILE = "files/User.csv";
|
||||||
constexpr const char* NOTIFICATION_FILE = "files/Notification.csv";
|
constexpr const char* NOTIFICATION_FILE = "files/Notification.csv";
|
||||||
|
|||||||
@@ -12,28 +12,28 @@ Date: 19-May-2026
|
|||||||
|
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
enum class UserType
|
enum class UserType : int
|
||||||
{
|
{
|
||||||
ADMIN,
|
ADMIN,
|
||||||
TECHNICIAN,
|
TECHNICIAN,
|
||||||
CUSTOMER
|
CUSTOMER
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class PaymentMode
|
enum class PaymentMode : int
|
||||||
{
|
{
|
||||||
ONLINE,
|
ONLINE,
|
||||||
OFFLINE,
|
OFFLINE,
|
||||||
NOTSET
|
NOTSET
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class PaymentStatus
|
enum class PaymentStatus : int
|
||||||
{
|
{
|
||||||
PENDING,
|
PENDING,
|
||||||
COMPLETED,
|
COMPLETED,
|
||||||
PAID
|
PAID
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class ServiceJobStatus
|
enum class ServiceJobStatus : int
|
||||||
{
|
{
|
||||||
PENDING,
|
PENDING,
|
||||||
STARTED,
|
STARTED,
|
||||||
@@ -42,7 +42,7 @@ namespace util
|
|||||||
CANCELLED
|
CANCELLED
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class State
|
enum class State : int
|
||||||
{
|
{
|
||||||
ACTIVE,
|
ACTIVE,
|
||||||
INACTIVE
|
INACTIVE
|
||||||
|
|||||||
@@ -116,15 +116,13 @@ bool util::isPasswordValid(const std::string& password)
|
|||||||
* usersMap - map of user objects keyed by identifier
|
* usersMap - map of user objects keyed by identifier
|
||||||
* Returns:
|
* Returns:
|
||||||
* bool - true if the username is already in use by an active user, false otherwise
|
* bool - true if the username is already in use by an active user, false otherwise
|
||||||
* Notes:
|
|
||||||
* - Only considers users with state util::State::ACTIVE
|
|
||||||
*/
|
*/
|
||||||
bool util::isUsernameDuplicate(const std::string& username, const util::Map<std::string, User*>& usersMap)
|
bool util::isUsernameDuplicate(const std::string& username, const util::Map<std::string, User*>& usersMap)
|
||||||
{
|
{
|
||||||
int index = usersMap.findIf(
|
int index = usersMap.findIf(
|
||||||
[&](const std::string&, User* user)
|
[&](const std::string&, User* user)
|
||||||
{
|
{
|
||||||
return (user->getUserName() == username && user->getState() == util::State::ACTIVE);
|
return (user->getUserName() == username);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return index != -1;
|
return index != -1;
|
||||||
|
|||||||
@@ -736,7 +736,7 @@ inline std::string selectJobCardToUpdate(util::Map<std::string, const JobCard*>&
|
|||||||
util::Map<int, const JobCard* > incompleteJobCards;
|
util::Map<int, const JobCard* > incompleteJobCards;
|
||||||
if (assignedJobCards.getSize() == 0)
|
if (assignedJobCards.getSize() == 0)
|
||||||
{
|
{
|
||||||
std::cout << "No jobs available.\n\n";
|
std::cout << "\nNo jobs available.\n\n";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
int currentIndex = 1;
|
int currentIndex = 1;
|
||||||
@@ -744,12 +744,12 @@ inline std::string selectJobCardToUpdate(util::Map<std::string, const JobCard*>&
|
|||||||
if (selectedJobStatusType == util::ServiceJobStatus::STARTED)
|
if (selectedJobStatusType == util::ServiceJobStatus::STARTED)
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
std::cout << "Select a job to update to Inprogress\n";
|
std::cout << "Select a job to mark as In Progress\n";
|
||||||
}
|
}
|
||||||
else if (selectedJobStatusType == util::ServiceJobStatus::IN_PROGRESS)
|
else if (selectedJobStatusType == util::ServiceJobStatus::IN_PROGRESS)
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
std::cout << "Select a job to update to Completed\n";
|
std::cout << "Select a job to mark as Completed\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -780,7 +780,7 @@ inline std::string selectJobCardToUpdate(util::Map<std::string, const JobCard*>&
|
|||||||
incompleteJobCards.insert(currentIndex++, currentJobCard);
|
incompleteJobCards.insert(currentIndex++, currentJobCard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Select the Job Card to Update (Index): ";
|
std::cout << "Enter the job index to update: ";
|
||||||
util::read(choice);
|
util::read(choice);
|
||||||
int selectedJobCardIndex = incompleteJobCards.find(choice);
|
int selectedJobCardIndex = incompleteJobCards.find(choice);
|
||||||
if (selectedJobCardIndex != -1)
|
if (selectedJobCardIndex != -1)
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ void TechnicianMenu::updateJobStatus()
|
|||||||
std::string selectedJobID;
|
std::string selectedJobID;
|
||||||
util::ServiceJobStatus selectedJobStatus = util::ServiceJobStatus::PENDING;
|
util::ServiceJobStatus selectedJobStatus = util::ServiceJobStatus::PENDING;
|
||||||
util::Map<std::string, const JobCard*> assignedJobCards = m_controller.getJobCardsByUser();
|
util::Map<std::string, const JobCard*> assignedJobCards = m_controller.getJobCardsByUser();
|
||||||
std::cout << "Select the type of job you want to update\n1.Started\n2.Inprogress\nChoice: ";
|
std::cout << "Select the type of job you want to update:\n1.Started\n2.In Progress\nChoice: ";
|
||||||
util::read(choice);
|
util::read(choice);
|
||||||
if (choice == 1)
|
if (choice == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user