# Base class

Inside the base class of your module you should integrate following functions to create and maintain the invoice synchronizer

### Create the synchronizer on Install()

```php
public function install(ModuleLifecycleContext $lifecycleContext) {

    // create the invoice synchronizer
    InvoiceSynchronizer::create([
        "module_name" => "HwSevdeskIntegration", // <-- Change this depending on your module Name
        "name" => "Sevdesk Integration",
        "handler" => HwSevdeskIntegrationHandler::class,
    ]);
}
```

### Delete the synchronizer on Uninstall()

```php
public function uninstall(ModuleLifecycleContext $lifecycleContext) {
    InvoiceSynchronizer::query()
        ->where("module_name", "HwSevdeskIntegration")  // <-- Change this depending on your module Name
        ->delete();
}
```

### Activate the synchronizer on activate()

It gets interesting on the activation of an invoice synchronizer. As you already know, the activate() gets triggered as soon as the administrator activates the module for a specific sales channel. \
We need to disable any other synchronizer for the requested sales channel and then enable our synchronizer.&#x20;

{% hint style="info" %}
A sales channel can only have one active synchronizer at one time
{% endhint %}

```php
public function activate(ModuleLifecycleContext $lifecycleContext) {
    // deactivate the other active module for the requested sales channel.
    InvoiceSynchronizersSalesChannel::query()
        ->where('sales_channel_id', $lifecycleContext->getSalesChannel()->id)
        ->update([
            'active' => false,
            'activated_at' => null,
        ]);


    // activate for the selected sales channel
    InvoiceSynchronizer::query()
        ->where('module_name', 'HwSevdeskIntegration') // <- Change this depending on your module Name
        ->first()
        ->salesChannelInvoiceSynchronizer()
        ->where('sales_channel_id', $lifecycleContext->getSalesChannel()->id)
        ->update([
            'active' => true,
            'activated_at' => Carbon::now(),
        ]);
}
```

### Deactivate the synchronizer on deactivate()

Vice versa, when the admin disables the synchronizer for a specific sales channel we need to disable the synchronizer in the database. We dont need to activate another synchronizer because the sales channel will be without an accounting integration until the admin enables another module.

```php
public function deactivate(ModuleLifecycleContext $lifecycleContext) {

    InvoiceSynchronizer::query()
        ->where('module_name', 'HwSevdeskIntegration') // <- Change this depending on your module Name
        ->first()
        ->salesChannelInvoiceSynchronizer()
        ->where('sales_channel_id', $lifecycleContext->getSalesChannel()->id)
        ->update([
            'active' => false,
            'activated_at' => null,
        ]);
}
```

This is the basic logic in the base class of your module to handle activation and installation of your synchronizer.
