-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Import E-Invoice as Expense #9493
base: v5-develop
Are you sure you want to change the base?
Conversation
@turbo124 can you maybe give me a little help. I'm currently stuck, in transfering the file from the curl-requests to the handling-part of the code. Can you maybe have a look at the classes and advise, what to change so, that the class zugferdedocument recieve the given xml-file? |
I would suggest extracting the files in the request and then passing each file into the handling clas()->handle(). I would not pass the entire request into the next method. |
Hi @turbo124 , This is my "test-code":
Can you maybe assisst? |
@LarsK1 I am assuming that you create the expense from the contents of the .xml ? If this is the case, you will need to create the expense itself, and then attach the .xml file to that expense. It appears you are attempting to upload the doc first, and then process the expense.. however the documents table requires the entity ID, (which you don't have at this stage) |
Hi @turbo124 , |
@LarsK1 Are using the PUT verb or POST for this? To upload, you need to ensure you use the POST verb and add the _method = PUT |
Hi, See the code above for reference |
@LarsK1 I meant this line:
try s.post() the route file should remain ::put |
@turbo124 , |
I see the issue here: couple of changes needed. In your api.php file Route::resource('expenses', ExpenseController::class); // name = (expenses. index / create / show / update / destroy / edit
Route::put('expenses/{expense}/upload', [ExpenseController::class, 'upload']);
Route::post('expenses/bulk', [ExpenseController::class, 'bulk'])->name('expenses.bulk');
Route::post('export', [ExportController::class, 'index'])->name('export.index');
Route::put('expenses/edocument/upload', [ExpenseController::class, "edocument"])->name("expenses.edocument"); move the route to the bottom, and change it by appending /upload the system is trying to resolve edocument as a model. also, in edocument request, change return $user->can('edit', $this->expense); to return $user->isAdmin(); |
routes/api.php
Outdated
Route::post('export', [ExportController::class, 'index'])->name('export.index'); | ||
Route::put('expenses/edocument/upload', [ExpenseController::class, "edocument"])->name("expenses.edocument"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @turbo124 ,
changed the files according to your help. But still getting 404 not found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this and it works as expected, have you run php artisan optimize
to update the routes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Can you send me your curl command to mitigate any incompatibility between python and PHP...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curl -X POST
http://ninja.test:8000/api/v1/expenses/edocument/upload
-H 'Content-Type: multipart/form-data'
-H 'X-API-TOKEN: company-token-test'
-H 'X-Requested-With: XMLHttpRequest'
-F _method=PUT
-F documents[]=@/path/Invoice.xml;
/** | ||
* @throws Exception | ||
*/ | ||
public function run(): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please let it return the expense, so it can be reused by the InboundMailEngine :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// TODO find vendor | ||
$vendors_registration = VendorRepository::class; | ||
$vendor = $vendors_registration->findVendorByNumber($this->document->getDocumentSeller()->getGlobalID()); | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@turbo124 when creating an expense through the api the following events are thrown:
event(new ExpenseWasCreated($expense, $expense->company, Ninja::eventVars(null))); // @turbo124 please check, I copied from API-Controller
event('eloquent.created: App\Models\Expense', $expense); // @turbo124 please check, I copied from API-Controller
should they also be present here?
@turbo124 @LarsK1 an additional thought about this topic from me: |
$expense->public_notes = $documentno; | ||
$expense->currency_id = Currency::whereCode($invoiceCurrency)->first()->id; | ||
$expense->save(); | ||
$expense->documents()->create(["content" => $visualizer->renderPdf()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@turbo124 I'm having my difficulties with this line. How can I save a string-file to the documents of an expense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from my perspective i think you should just use the UploadedFile object from the request instead of a stringfile. (because its not job within a queue and can be passed to saveDocuments function directly)
i also added some helperclasses with my PR at:
app/Utils/TempFile.php
No description provided.