diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php
index 593ab595f377..8af0d560d679 100644
--- a/app/Http/Controllers/DocumentController.php
+++ b/app/Http/Controllers/DocumentController.php
@@ -122,9 +122,19 @@ class DocumentController extends BaseController
return $response;
}
- $document = Input::all();
-
- $response = $this->documentRepo->upload($document);
- return $response;
+ $result = $this->documentRepo->upload(Input::all()['file'], $doc_array);
+
+ if(is_string($result)){
+ return Response::json([
+ 'error' => $result,
+ 'code' => 400
+ ], 400);
+ } else {
+ return Response::json([
+ 'error' => false,
+ 'document' => $doc_array,
+ 'code' => 200
+ ], 200);
+ }
}
}
diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php
index 8cd6049d0be4..70b8e66fa4f2 100644
--- a/app/Http/Controllers/InvoiceController.php
+++ b/app/Http/Controllers/InvoiceController.php
@@ -406,6 +406,7 @@ class InvoiceController extends BaseController
public function update(SaveInvoiceWithClientRequest $request)
{
$data = $request->input();
+ $data['documents'] = $request->file('documents');
if(!$this->checkUpdatePermission($data, $response)){
return $response;
diff --git a/app/Ninja/Repositories/DocumentRepository.php b/app/Ninja/Repositories/DocumentRepository.php
index 7fcd954b1ed6..78be3bf78655 100644
--- a/app/Ninja/Repositories/DocumentRepository.php
+++ b/app/Ninja/Repositories/DocumentRepository.php
@@ -57,10 +57,8 @@ class DocumentRepository extends BaseRepository
return $query;
}
- public function upload($input)
+ public function upload($uploaded, &$doc_array=null)
{
- $uploaded = $input['file'];
-
$extension = strtolower($uploaded->extension());
if(empty(Document::$types[$extension]) && !empty(Document::$extraExtensions[$extension])){
$documentType = Document::$extraExtensions[$extension];
@@ -70,10 +68,7 @@ class DocumentRepository extends BaseRepository
}
if(empty(Document::$types[$documentType])){
- return Response::json([
- 'error' => 'Unsupported extension',
- 'code' => 400
- ], 400);
+ return 'Unsupported extension';
}
$documentTypeData = Document::$types[$documentType];
@@ -83,10 +78,7 @@ class DocumentRepository extends BaseRepository
$size = filesize($filePath);
if($size/1000 > MAX_DOCUMENT_SIZE){
- return Response::json([
- 'error' => 'File too large',
- 'code' => 400
- ], 400);
+ return 'File too large';
}
@@ -183,11 +175,7 @@ class DocumentRepository extends BaseRepository
$doc_array['base64'] = 'data:'.$mime.';base64,'.$base64;
}
- return Response::json([
- 'error' => false,
- 'document' => $doc_array,
- 'code' => 200
- ], 200);
+ return $document;
}
public function getClientDatatable($contactId, $entityType, $search)
diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php
index d8aa051b6c61..a927cb068c0d 100644
--- a/app/Ninja/Repositories/InvoiceRepository.php
+++ b/app/Ninja/Repositories/InvoiceRepository.php
@@ -2,6 +2,7 @@
use DB;
use Utils;
+use Session;
use App\Models\Invoice;
use App\Models\InvoiceItem;
use App\Models\Invitation;
@@ -14,13 +15,16 @@ use App\Ninja\Repositories\BaseRepository;
class InvoiceRepository extends BaseRepository
{
+ protected $documentRepo;
+
public function getClassName()
{
return 'App\Models\Invoice';
}
- public function __construct(PaymentService $paymentService)
+ public function __construct(PaymentService $paymentService, DocumentRepository $documentRepo)
{
+ $this->documentRepo = $documentRepo;
$this->paymentService = $paymentService;
}
@@ -399,7 +403,7 @@ class InvoiceRepository extends BaseRepository
$invoice->invoice_items()->forceDelete();
}
- $document_ids = !empty($data['documents'])?array_map('intval', $data['documents']):array();;
+ $document_ids = !empty($data['document_ids'])?array_map('intval', $data['document_ids']):array();;
foreach ($document_ids as $document_id){
$document = Document::scope($document_id)->first();
if($document && !$checkSubPermissions || $document->canEdit()){
@@ -415,6 +419,25 @@ class InvoiceRepository extends BaseRepository
}
}
+ if(!empty($data['documents']) && Document::canCreate()){
+ // Fallback upload
+ $doc_errors = array();
+ foreach($data['documents'] as $upload){
+ $result = $this->documentRepo->upload($upload);
+ if(is_string($result)){
+ $doc_errors[] = $result;
+ }
+ else{
+ $result->invoice_id = $invoice->id;
+ $result->save();
+ $document_ids[] = $result->public_id;
+ }
+ }
+ if(!empty($doc_errors)){
+ Session::flash('error', implode('
',array_map('htmlentities',$doc_errors)));
+ }
+ }
+
foreach ($invoice->documents as $document){
if(!in_array($document->public_id, $document_ids)){
// Removed
diff --git a/public/css/built.css b/public/css/built.css
index 9a0d13c182fb..7278b9ed4236 100644
--- a/public/css/built.css
+++ b/public/css/built.css
@@ -3213,4 +3213,11 @@ div.panel-body div.panel-body {
object-fit: cover;
width: 100%;
height: 100%;
+}
+
+.dropzone .fallback-doc{
+ display:none;
+}
+.dropzone.dz-browser-not-supported .fallback-doc{
+ display:block;
}
\ No newline at end of file
diff --git a/public/css/style.css b/public/css/style.css
index d18c383ab2de..1499d26f573a 100644
--- a/public/css/style.css
+++ b/public/css/style.css
@@ -1084,4 +1084,11 @@ div.panel-body div.panel-body {
object-fit: cover;
width: 100%;
height: 100%;
+}
+
+.dropzone .fallback-doc{
+ display:none;
+}
+.dropzone.dz-browser-not-supported .fallback-doc{
+ display:block;
}
\ No newline at end of file
diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php
index 8bcb89a9d6e7..a383a1b0cb32 100644
--- a/resources/views/invoices/edit.blade.php
+++ b/resources/views/invoices/edit.blade.php
@@ -40,6 +40,7 @@
->method($method)
->addClass('warn-on-exit')
->autocomplete('off')
+ ->attributes(array('enctype'=>'multipart/form-data'))
->onsubmit('return onFormSubmit(event)')
->rules(array(
'client' => 'required',
@@ -308,11 +309,15 @@