mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:34:34 -04:00
Fixes for ClientContact CRUD (#3317)
* Fixes for downloading invoice PDF * Fixes for client contact CRUD
This commit is contained in:
parent
cd961e2098
commit
162580bcd3
@ -59,7 +59,5 @@ class ArtisanUpgrade extends Command
|
|||||||
\Log::error("I wasn't able to optimize.");
|
\Log::error("I wasn't able to optimize.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
\Log::error("finished upgrade post");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -652,16 +652,59 @@ class InvoiceController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @OA\Get(
|
||||||
|
* path="/api/v1/invoice/{invitation_key}/download",
|
||||||
|
* operationId="downloadInvoice",
|
||||||
|
* tags={"invoices"},
|
||||||
|
* summary="Download a specific invoice by invitation key",
|
||||||
|
* description="Downloads a specific invoice",
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
|
* @OA\Parameter(ref="#/components/parameters/include"),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="invitation_key",
|
||||||
|
* in="path",
|
||||||
|
* description="The Invoice Invitation Key",
|
||||||
|
* example="D2J234DFA",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="string",
|
||||||
|
* format="string",
|
||||||
|
* ),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=200,
|
||||||
|
* description="Returns the invoice pdf",
|
||||||
|
* @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||||
|
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response=422,
|
||||||
|
* description="Validation error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||||
|
*
|
||||||
|
* ),
|
||||||
|
* @OA\Response(
|
||||||
|
* response="default",
|
||||||
|
* description="Unexpected Error",
|
||||||
|
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||||
|
* ),
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
*/
|
||||||
public function downloadPdf($invitation_key) {
|
public function downloadPdf($invitation_key) {
|
||||||
|
|
||||||
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
|
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
|
||||||
$contact = $invitation->contact;
|
$contact = $invitation->contact;
|
||||||
$invoice = $invitation->invoice;
|
$invoice = $invitation->invoice;
|
||||||
|
|
||||||
$file_path = $invoice->service()->getInvoicePdf(); //CreateInvoicePdf::dispatchNow($invoice, $invoice->company, $contact);
|
$file_path = $invoice->service()->getInvoicePdf($contact);
|
||||||
|
|
||||||
return response()->download($file_path);
|
return response()->download($file_path);
|
||||||
|
|
||||||
//return response()->json($invitation_key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ class MigrationController extends BaseController
|
|||||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Password"), // Needs verification.
|
* @OA\Parameter(ref="#/components/parameters/X-Api-Password"),
|
||||||
* @OA\Parameter(
|
* @OA\Parameter(
|
||||||
* name="migration",
|
* name="migration",
|
||||||
* in="path",
|
* in="path",
|
||||||
@ -160,7 +160,7 @@ class MigrationController extends BaseController
|
|||||||
* example="migration.zip",
|
* example="migration.zip",
|
||||||
* required=true,
|
* required=true,
|
||||||
* @OA\Schema(
|
* @OA\Schema(
|
||||||
* type="file",
|
* type="object",
|
||||||
* format="file",
|
* format="file",
|
||||||
* ),
|
* ),
|
||||||
* ),
|
* ),
|
||||||
|
@ -33,6 +33,16 @@
|
|||||||
* example="HcRvs0oCvYbY5g3RzgBZrSBOChCiq8u4AL0ieuFN5gn4wUV14t0clVhfPc5OX99q"
|
* example="HcRvs0oCvYbY5g3RzgBZrSBOChCiq8u4AL0ieuFN5gn4wUV14t0clVhfPc5OX99q"
|
||||||
* )
|
* )
|
||||||
* ),
|
* ),
|
||||||
|
* @OA\Parameter(
|
||||||
|
* name="X-Api-Password",
|
||||||
|
* in="header",
|
||||||
|
* description="The login password when challenged",
|
||||||
|
* required=true,
|
||||||
|
* @OA\Schema(
|
||||||
|
* type="string",
|
||||||
|
* example="supersecretpassword"
|
||||||
|
* )
|
||||||
|
* ),
|
||||||
*
|
*
|
||||||
* @OA\Parameter(
|
* @OA\Parameter(
|
||||||
* name="include",
|
* name="include",
|
||||||
|
@ -43,14 +43,14 @@ class StoreClientRequest extends Request
|
|||||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||||
$rules['contacts.*.email'] = 'nullable|distinct';
|
$rules['contacts.*.email'] = 'nullable|distinct';
|
||||||
|
|
||||||
$contacts = request('contacts');
|
// $contacts = request('contacts');
|
||||||
|
|
||||||
if (is_array($contacts)) {
|
// if (is_array($contacts)) {
|
||||||
for ($i = 0; $i < count($contacts); $i++) {
|
// for ($i = 0; $i < count($contacts); $i++) {
|
||||||
|
|
||||||
//$rules['contacts.' . $i . '.email'] = 'nullable|email|distinct';
|
// //$rules['contacts.' . $i . '.email'] = 'nullable|email|distinct';
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
@ -68,6 +68,17 @@ class StoreClientRequest extends Request
|
|||||||
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
|
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($input['contacts']))
|
||||||
|
{
|
||||||
|
foreach($input['contacts'] as $contact)
|
||||||
|
{
|
||||||
|
if(is_numeric($contact['id']))
|
||||||
|
unset($contact['id']);
|
||||||
|
elseif(is_string($contact['id']))
|
||||||
|
$contact['id'] = $this->decodePrimaryKey($contact['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,11 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\Client;
|
namespace App\Http\Requests\Client;
|
||||||
|
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
use App\Http\Requests\Request;
|
use App\Http\Requests\Request;
|
||||||
use App\Http\ValidationRules\IsDeletedRule;
|
use App\Http\ValidationRules\IsDeletedRule;
|
||||||
use App\Http\ValidationRules\ValidClientGroupSettingsRule;
|
use App\Http\ValidationRules\ValidClientGroupSettingsRule;
|
||||||
|
use App\Http\ValidationRules\ValidSettingsRule;
|
||||||
use App\Utils\Traits\ChecksEntityStatus;
|
use App\Utils\Traits\ChecksEntityStatus;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@ -48,14 +50,14 @@ class UpdateClientRequest extends Request
|
|||||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||||
$rules['contacts.*.email'] = 'nullable|distinct';
|
$rules['contacts.*.email'] = 'nullable|distinct';
|
||||||
|
|
||||||
$contacts = request('contacts');
|
// $contacts = request('contacts');
|
||||||
|
|
||||||
if (is_array($contacts)) {
|
// if (is_array($contacts)) {
|
||||||
// for ($i = 0; $i < count($contacts); $i++) {
|
// // for ($i = 0; $i < count($contacts); $i++) {
|
||||||
// // $rules['contacts.' . $i . '.email'] = 'nullable|email|unique:client_contacts,email,' . isset($contacts[$i]['id'].',company_id,'.$this->company_id);
|
// // // $rules['contacts.' . $i . '.email'] = 'nullable|email|unique:client_contacts,email,' . isset($contacts[$i]['id'].',company_id,'.$this->company_id);
|
||||||
// //$rules['contacts.' . $i . '.email'] = 'nullable|email';
|
// // //$rules['contacts.' . $i . '.email'] = 'nullable|email';
|
||||||
// }
|
// // }
|
||||||
}
|
// }
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,11 +75,21 @@ class UpdateClientRequest extends Request
|
|||||||
{
|
{
|
||||||
$input = $this->all();
|
$input = $this->all();
|
||||||
|
|
||||||
|
|
||||||
if (isset($input['group_settings_id'])) {
|
if (isset($input['group_settings_id'])) {
|
||||||
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
|
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(isset($input['contacts']))
|
||||||
|
{
|
||||||
|
foreach($input['contacts'] as $contact)
|
||||||
|
{
|
||||||
|
if(is_numeric($contact['id']))
|
||||||
|
unset($contact['id']);
|
||||||
|
elseif(is_string($contact['id']))
|
||||||
|
$contact['id'] = $this->decodePrimaryKey($contact['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->replace($input);
|
$this->replace($input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ use Illuminate\Support\Facades\Storage;
|
|||||||
use Spatie\Browsershot\Browsershot;
|
use Spatie\Browsershot\Browsershot;
|
||||||
|
|
||||||
class CreateInvoicePdf implements ShouldQueue {
|
class CreateInvoicePdf implements ShouldQueue {
|
||||||
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml;
|
||||||
|
|
||||||
public $invoice;
|
public $invoice;
|
||||||
@ -41,12 +42,13 @@ class CreateInvoicePdf implements ShouldQueue {
|
|||||||
public $contact;
|
public $contact;
|
||||||
|
|
||||||
private $disk;
|
private $disk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(Invoice $invoice, Company $company, ClientContact $contact, $disk = 'public')
|
public function __construct(Invoice $invoice, Company $company, ClientContact $contact = null, $disk = 'public')
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->invoice = $invoice;
|
$this->invoice = $invoice;
|
||||||
@ -63,11 +65,16 @@ class CreateInvoicePdf implements ShouldQueue {
|
|||||||
|
|
||||||
MultiDB::setDB($this->company->db);
|
MultiDB::setDB($this->company->db);
|
||||||
|
|
||||||
|
$this->invoice->load('client');
|
||||||
|
|
||||||
|
if(!$this->contact)
|
||||||
|
$this->contact = $this->invoice->client->primary_contact()->first();
|
||||||
|
|
||||||
App::setLocale($this->contact->preferredLocale());
|
App::setLocale($this->contact->preferredLocale());
|
||||||
|
|
||||||
$this->invoice->load('client');
|
|
||||||
$path = $this->invoice->client->client_hash . '/invoices/';
|
$path = $this->invoice->client->client_hash . '/invoices/';
|
||||||
$file_path = $path . $this->invoice->number . '.pdf';
|
|
||||||
|
$file_path = $path . $this->invoice->number . '-' . $this->contact->contact_key .'.pdf';
|
||||||
|
|
||||||
$modern = new Modern();
|
$modern = new Modern();
|
||||||
$designer = new Designer($modern, $this->invoice->client->getSetting('invoice_variables'));
|
$designer = new Designer($modern, $this->invoice->client->getSetting('invoice_variables'));
|
||||||
@ -83,13 +90,10 @@ class CreateInvoicePdf implements ShouldQueue {
|
|||||||
$pdf = $this->makePdf(null, null, $html);
|
$pdf = $this->makePdf(null, null, $html);
|
||||||
|
|
||||||
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
|
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
|
||||||
|
|
||||||
\Log::error($instance);
|
|
||||||
|
|
||||||
//$instance = Storage::disk($this->disk)->putFileAs($path, $pdf, $this->invoice->number . '.pdf');
|
//$instance= Storage::disk($this->disk)->path($file_path);
|
||||||
//$instance = Storage::putFileAs($path, $pdf, $this->invoice->number . '.pdf');
|
|
||||||
|
|
||||||
return $instance;
|
return $file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +28,8 @@ class ClientContactRepository extends BaseRepository
|
|||||||
|
|
||||||
/* Get array of IDs which have been removed from the contacts array and soft delete each contact */
|
/* Get array of IDs which have been removed from the contacts array and soft delete each contact */
|
||||||
collect($client->contacts->pluck('id'))->diff($contacts->pluck('id'))->each(function ($contact) {
|
collect($client->contacts->pluck('id'))->diff($contacts->pluck('id'))->each(function ($contact) {
|
||||||
|
//ClientContact::find($contact)->delete();
|
||||||
|
|
||||||
ClientContact::destroy($contact);
|
ClientContact::destroy($contact);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -44,7 +46,7 @@ class ClientContactRepository extends BaseRepository
|
|||||||
$update_contact = null;
|
$update_contact = null;
|
||||||
|
|
||||||
if (isset($contact['id'])) {
|
if (isset($contact['id'])) {
|
||||||
$update_contact = ClientContact::find($this->decodePrimaryKey($contact['id']));
|
$update_contact = ClientContact::find($contact['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$update_contact) {
|
if (!$update_contact) {
|
||||||
|
@ -57,7 +57,7 @@ class ClientRepository extends BaseRepository
|
|||||||
*/
|
*/
|
||||||
public function save(array $data, Client $client) : ?Client
|
public function save(array $data, Client $client) : ?Client
|
||||||
{
|
{
|
||||||
|
\Log::error($data);
|
||||||
$client->fill($data);
|
$client->fill($data);
|
||||||
|
|
||||||
$client->save();
|
$client->save();
|
||||||
@ -68,6 +68,8 @@ class ClientRepository extends BaseRepository
|
|||||||
|
|
||||||
$client->save();
|
$client->save();
|
||||||
|
|
||||||
|
// \Log::error($client);
|
||||||
|
|
||||||
if (isset($data['contacts'])) {
|
if (isset($data['contacts'])) {
|
||||||
$contacts = $this->contact_repo->save($data['contacts'], $client);
|
$contacts = $this->contact_repo->save($data['contacts'], $client);
|
||||||
}
|
}
|
||||||
|
@ -17,24 +17,20 @@ use Illuminate\Support\Facades\Storage;
|
|||||||
class GetInvoicePdf
|
class GetInvoicePdf
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __invoke($invoice, $contact = null)
|
public function __invoke($invoice, $contact = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(!$contact)
|
||||||
|
$contact = $invoice->client->primary_contact()->first();
|
||||||
|
|
||||||
$path = $invoice->client->client_hash . '/invoices/';
|
$path = $invoice->client->client_hash . '/invoices/';
|
||||||
|
|
||||||
$file_path = $path . $invoice->number . '.pdf';
|
$file_path = $path . $invoice->number . '-' . $contact->contact_key . '.pdf';
|
||||||
|
|
||||||
$disk = config('filesystems.default');
|
$disk = config('filesystems.default');
|
||||||
|
|
||||||
$file = Storage::disk($disk)->exists($file_path);
|
$file = Storage::disk($disk)->exists($file_path);
|
||||||
|
|
||||||
if(!$contact)
|
|
||||||
$contact = $invoice->client->primary_contact()->first();
|
|
||||||
|
|
||||||
if(!$file)
|
if(!$file)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -113,11 +113,11 @@ class InvoiceService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInvoicePdf()
|
public function getInvoicePdf($contact)
|
||||||
{
|
{
|
||||||
$get_invoice_pdf = new GetInvoicePdf();
|
$get_invoice_pdf = new GetInvoicePdf();
|
||||||
|
|
||||||
return $get_invoice_pdf($this->invoice);
|
return $get_invoice_pdf($this->invoice, $contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class InvoiceUploadTest extends TestCase
|
|||||||
|
|
||||||
CreateInvoicePdf::dispatchNow($this->invoice, $this->invoice->company, $this->invoice->client->primary_contact()->first());
|
CreateInvoicePdf::dispatchNow($this->invoice, $this->invoice->company, $this->invoice->client->primary_contact()->first());
|
||||||
|
|
||||||
$this->assertNotNull($this->invoice->service()->getInvoicePdf());
|
$this->assertNotNull($this->invoice->service()->getInvoicePdf($this->invoice->client->primary_contact()->first()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user