Skip to content

Commit 999bd52

Browse files
committed
Initial commit
0 parents  commit 999bd52

File tree

10 files changed

+222
-0
lines changed

10 files changed

+222
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

Config/config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'name' => 'InvoiceDesignExport'
5+
];

Console/InsertButtonsCommand.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Modules\InvoiceDesignExport\Console;
4+
5+
use Illuminate\Console\Command;
6+
7+
class InsertButtonsCommand extends Command
8+
{
9+
protected $name = 'invoicedesignexport:insert-buttons';
10+
protected $description = 'Install import and export buttons on customize design page';
11+
12+
const INSERT_NEW_INCLUDE = " @include('invoicedesignexport::buttons')\n";
13+
const INSERT_BEFORE = '@stop';
14+
15+
public function handle()
16+
{
17+
$filePath = base_path('resources/views/accounts/customize_design.blade.php');
18+
$fileContent = file_get_contents($filePath);
19+
20+
if(false !== strstr($fileContent, self::INSERT_NEW_INCLUDE)){
21+
$this->info('Buttons were already installed!');
22+
return;
23+
}
24+
25+
$one = 1;
26+
$newFileContent = preg_replace(
27+
'/'.preg_quote(self::INSERT_BEFORE, '/').'/',
28+
self::INSERT_NEW_INCLUDE . self::INSERT_BEFORE,
29+
$fileContent,
30+
$one
31+
);
32+
33+
file_put_contents($filePath, $newFileContent);
34+
$this->info('Buttons installed!');
35+
}
36+
}

Console/RemoveButtonsCommand.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Modules\InvoiceDesignExport\Console;
4+
5+
use Illuminate\Console\Command;
6+
7+
class RemoveButtonsCommand extends Command
8+
{
9+
protected $name = 'invoicedesignexport:remove-buttons';
10+
protected $description = 'Remove import and export buttons from customize design page';
11+
12+
public function handle()
13+
{
14+
$filePath = base_path('resources/views/accounts/customize_design.blade.php');
15+
$fileContent = file_get_contents($filePath);
16+
17+
if(false === strstr($fileContent, InsertButtonsCommand::INSERT_NEW_INCLUDE)){
18+
$this->info('Buttons were already removed!');
19+
return;
20+
}
21+
22+
$one = 1;
23+
$newFileContent = preg_replace(
24+
'/'.preg_quote(InsertButtonsCommand::INSERT_NEW_INCLUDE . InsertButtonsCommand::INSERT_BEFORE, '/').'/',
25+
InsertButtonsCommand::INSERT_BEFORE,
26+
$fileContent,
27+
$one
28+
);
29+
30+
file_put_contents($filePath, $newFileContent);
31+
$this->info('Buttons removed!');
32+
}
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Modules\InvoiceDesignExport\Providers;
4+
5+
use App\Providers\AuthServiceProvider;
6+
7+
class InvoiceDesignExportServiceProvider extends AuthServiceProvider
8+
{
9+
/**
10+
* Indicates if loading of the provider is deferred.
11+
*
12+
* @var bool
13+
*/
14+
protected $defer = false;
15+
16+
/**
17+
* Boot the application events.
18+
*
19+
* @return void
20+
*/
21+
public function boot()
22+
{
23+
parent::boot();
24+
25+
$this->commands([
26+
\Modules\InvoiceDesignExport\Console\InsertButtonsCommand::class,
27+
\Modules\InvoiceDesignExport\Console\RemoveButtonsCommand::class,
28+
]);
29+
30+
$sourcePath = __DIR__ . '/../Resources/views';
31+
$this->loadViewsFrom(array_merge(array_map(function ($path) {
32+
return $path . '/modules/invoicedesignexport';
33+
}, \Config::get('view.paths')), [$sourcePath]), 'invoicedesignexport');
34+
35+
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang/en', 'invoicedesignexport');
36+
}
37+
38+
}

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Invoice design import and export module for Invoice Ninja
2+
3+
This module adds the ability to import and export the invoice design.
4+
5+
## Installation
6+
Install the module like any other Invoice Ninja module:
7+
8+
```
9+
php artisan module:install feyst/invoicedesignexport --type=github-https
10+
```
11+
12+
After the installation is complete, you must run the Artisan command to inject the view into the relevant Invoice Ninja views:
13+
```
14+
php artisan invoicedesignexport:insert-buttons
15+
```
16+
17+
To remove the scanner from the page(s), run the following command:
18+
```
19+
php artisan invoicedesignexport:remove-buttons
20+
```
21+
22+
## Issues / Feedback
23+
All feedback or issues are welcome! Feel free to open an issue for any bugs or feature requests.

Resources/lang/en/texts.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'invoicedesignexport' => 'Invoice design exports',
5+
];

Resources/views/buttons.blade.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<script type="application/javascript">
2+
$(document).ready(function() {
3+
let exportButton = "{!! Button::primary(trans('texts.export'))->withAttributes(['onclick' => 'exportDesign()', 'style' => 'margin:2px;'])->appendIcon(Icon::create('download')) !!}";
4+
let importButton = "{!! Button::primary(trans('texts.import'))->withAttributes(['onclick' => 'importDesign()', 'style' => 'margin:2px;'])->appendIcon(Icon::create('upload')) !!}";
5+
$(exportButton).insertBefore('[onclick="showHelp()"]');
6+
$(importButton).insertAfter('[onclick="exportDesign()"]');
7+
});
8+
9+
function exportDesign(){
10+
downloadFile('{{trans('texts.invoice_design')}}.json', getDesignJavascript(), 'application/json');
11+
}
12+
13+
function downloadFile(name, content, contentType){
14+
if(null === document.getElementById('downloadFile')){
15+
$(document.body).append('<a download="' + name + '" id="downloadFile" style="display:none;"></a>');
16+
}
17+
let downloadButton = document.getElementById('downloadFile');
18+
downloadButton.download = name;
19+
downloadButton.href=window.URL.createObjectURL(new Blob([content], {type: contentType}))
20+
downloadButton.click();
21+
}
22+
23+
function importDesign(){
24+
uploadSingleFile('.json', function(json){
25+
customDesign = JSON.parse(json);
26+
loadEditor(editorSection);
27+
clearError();
28+
refreshPDF(true);
29+
});
30+
}
31+
32+
function uploadSingleFile(extensions, callback){
33+
$('#uploadSingleFile').remove();
34+
$(document.body).append('<input type="file" id="uploadSingleFile" style="display:none;" />');
35+
let uploadInput = $('#uploadSingleFile');
36+
uploadInput.attr('accept', extensions);
37+
uploadInput.on('change', function(uploadEvent){
38+
if(uploadEvent.target.files.length === 1){
39+
let reader = new FileReader();
40+
reader.readAsText(uploadEvent.target.files[0], "UTF-8");
41+
reader.onload = function(uploadLoaded){
42+
callback(uploadLoaded.target.result);
43+
uploadInput.remove();
44+
}
45+
}
46+
});
47+
uploadInput.click();
48+
}
49+
</script>

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "feyst/invoicedesignexport",
3+
"type": "invoiceninja-module",
4+
"description": "Upload or download an invoice pdf design for InvoiceNinja",
5+
"authors": [
6+
{
7+
"name": "Mark van der Feijst",
8+
"email": "mark@feyst.nl"
9+
}
10+
],
11+
"autoload": {
12+
"psr-4": {
13+
"Modules\\InvoiceDesignExport\\": ""
14+
}
15+
}
16+
}

module.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "InvoiceDesignExport",
3+
"alias": "invoicedesignexport",
4+
"description": "Upload or download an invoice pdf design for InvoiceNinja",
5+
"keywords": [],
6+
"active": 1,
7+
"order": 0,
8+
"providers": [
9+
"Modules\\InvoiceDesignExport\\Providers\\InvoiceDesignExportServiceProvider"
10+
],
11+
"aliases": [],
12+
"files":[],
13+
"icon": "th-large",
14+
"plural": "invoicedesignexport",
15+
"no-sidebar": 1
16+
}

0 commit comments

Comments
 (0)