Forum

Ask, reply and learn. Join the community of Akaunting.

New Discussion

Create module to overide output

Yecine Dho   ( User )

Commented 3 years ago

Hi,

I'm trying to create a simple module to replace the suggested invoice number when creating a new invoice.

I would like to have the possibility to dynamically add the year and month of the current date.

I have managed to get akaunting working locally on my machine, and i have created a new module ass suggested in the documentation
https://akaunting.com/docs/developer-manual/modules

I have also followed the page
https://akaunting.com/docs/developer-manual/overriding-output

But i have an issue my code never gets called, i have put a dd inside my booth method on my service provider but it doesn"t work

```

namespace Modules\AdvancedInvoiceNumbering\Providers;

use Illuminate\Support\ServiceProvider;
use View;

class ViewComposer extends ServiceProvider
{
/**
* Register bindings in the container.
*
* @return void
*/
public function boot()
{
// View::composer(['components.documents.template.default',
// 'components.documents.template.classic',
// 'components.documents.template.modern',
// ],
// 'Modules\AmountInWords\Http\ViewComposers\Document');
dd("dieeee");
View::composer(
['sales.invoices.create'], 'Modules\AdvancedInvoiceNumbering\Http\ViewComposers\Invoice'
);
}
```

Can you help me? Do you know why it doesn't work ?

Leonardo Gomes   ( User )

Commented 3 years ago

Hi Yecine.

Open the file of your route.

You'll see that there is only components inside of it.

So in order to override the content you must override the component and not the main route.

I am not sure if it will work, because there is some elements that a component renders on the back-end that you simply wouldn't be able to override, However this is the best shot you have.

Hope you can reach you goal!

Leonardo Gomes   ( User )

Commented 3 years ago

By Route i meant = 'sales.invoices.create'

And your dd should be placed inside the ViewComposer file not on the provider.

Yecine Dho   ( User )

Commented 3 years ago

thanks for your answer i tried as you suggested without luck ....

maybe i should try another way.

I have found that the number for the invoice is return in the DocumentForm class

```
$this->getNextDocumentNumber($type);
````

This method is in the trait Document

````

namespace App\Traits;

use App\Models\Document\Document;
use App\Abstracts\View\Components\Document as DocumentComponent;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

trait Documents
{
public function getNextDocumentNumber(string $type): string
{
if ($alias = config('type.' . $type . '.alias')) {
$type = $alias . '.' . str_replace('-', '_', $type);
}

$prefix = setting("$type.number_prefix");
$next = setting("$type.number_next");
$digit = setting("$type.number_digit");

return $prefix . str_pad($next, $digit, '0', STR_PAD_LEFT);
}
````

do you think it's possible to override that method with a module ?

Leonardo Gomes   ( User )

Commented 3 years ago

I don't think so.

try to override with a view composer this view: 'components.documents.form.metadata'

You should found there $textDocumentNumber

Remember that: You'll need to override the whole file.

Please login or register to leave a response.

Showing 1 to 5 of 5 discussions