mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -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("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) {
|
||||
|
||||
$invitation = $this->invoice_repo->getInvitationByKey($invitation_key);
|
||||
$contact = $invitation->contact;
|
||||
$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()->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-Token"),
|
||||
* @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(
|
||||
* name="migration",
|
||||
* in="path",
|
||||
@ -160,7 +160,7 @@ class MigrationController extends BaseController
|
||||
* example="migration.zip",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="file",
|
||||
* type="object",
|
||||
* format="file",
|
||||
* ),
|
||||
* ),
|
||||
|
@ -33,6 +33,16 @@
|
||||
* 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(
|
||||
* name="include",
|
||||
|
@ -43,14 +43,14 @@ class StoreClientRequest extends Request
|
||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||
$rules['contacts.*.email'] = 'nullable|distinct';
|
||||
|
||||
$contacts = request('contacts');
|
||||
// $contacts = request('contacts');
|
||||
|
||||
if (is_array($contacts)) {
|
||||
for ($i = 0; $i < count($contacts); $i++) {
|
||||
// if (is_array($contacts)) {
|
||||
// for ($i = 0; $i < count($contacts); $i++) {
|
||||
|
||||
//$rules['contacts.' . $i . '.email'] = 'nullable|email|distinct';
|
||||
}
|
||||
}
|
||||
// //$rules['contacts.' . $i . '.email'] = 'nullable|email|distinct';
|
||||
// }
|
||||
// }
|
||||
|
||||
return $rules;
|
||||
}
|
||||
@ -68,6 +68,17 @@ class StoreClientRequest extends Request
|
||||
$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);
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,11 @@
|
||||
|
||||
namespace App\Http\Requests\Client;
|
||||
|
||||
use App\DataMapper\ClientSettings;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Http\ValidationRules\IsDeletedRule;
|
||||
use App\Http\ValidationRules\ValidClientGroupSettingsRule;
|
||||
use App\Http\ValidationRules\ValidSettingsRule;
|
||||
use App\Utils\Traits\ChecksEntityStatus;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -48,14 +50,14 @@ class UpdateClientRequest extends Request
|
||||
$rules['settings'] = new ValidClientGroupSettingsRule();
|
||||
$rules['contacts.*.email'] = 'nullable|distinct';
|
||||
|
||||
$contacts = request('contacts');
|
||||
// $contacts = request('contacts');
|
||||
|
||||
if (is_array($contacts)) {
|
||||
// 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';
|
||||
// }
|
||||
}
|
||||
// if (is_array($contacts)) {
|
||||
// // 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';
|
||||
// // }
|
||||
// }
|
||||
return $rules;
|
||||
}
|
||||
|
||||
@ -73,11 +75,21 @@ class UpdateClientRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
|
||||
if (isset($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);
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ use Illuminate\Support\Facades\Storage;
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
|
||||
class CreateInvoicePdf implements ShouldQueue {
|
||||
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml;
|
||||
|
||||
public $invoice;
|
||||
@ -41,12 +42,13 @@ class CreateInvoicePdf implements ShouldQueue {
|
||||
public $contact;
|
||||
|
||||
private $disk;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @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;
|
||||
@ -63,11 +65,16 @@ class CreateInvoicePdf implements ShouldQueue {
|
||||
|
||||
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());
|
||||
|
||||
$this->invoice->load('client');
|
||||
$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();
|
||||
$designer = new Designer($modern, $this->invoice->client->getSetting('invoice_variables'));
|
||||
@ -83,13 +90,10 @@ class CreateInvoicePdf implements ShouldQueue {
|
||||
$pdf = $this->makePdf(null, null, $html);
|
||||
|
||||
$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::putFileAs($path, $pdf, $this->invoice->number . '.pdf');
|
||||
//$instance= Storage::disk($this->disk)->path($file_path);
|
||||
|
||||
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 */
|
||||
collect($client->contacts->pluck('id'))->diff($contacts->pluck('id'))->each(function ($contact) {
|
||||
//ClientContact::find($contact)->delete();
|
||||
|
||||
ClientContact::destroy($contact);
|
||||
});
|
||||
|
||||
@ -44,7 +46,7 @@ class ClientContactRepository extends BaseRepository
|
||||
$update_contact = null;
|
||||
|
||||
if (isset($contact['id'])) {
|
||||
$update_contact = ClientContact::find($this->decodePrimaryKey($contact['id']));
|
||||
$update_contact = ClientContact::find($contact['id']);
|
||||
}
|
||||
|
||||
if (!$update_contact) {
|
||||
|
@ -57,7 +57,7 @@ class ClientRepository extends BaseRepository
|
||||
*/
|
||||
public function save(array $data, Client $client) : ?Client
|
||||
{
|
||||
|
||||
\Log::error($data);
|
||||
$client->fill($data);
|
||||
|
||||
$client->save();
|
||||
@ -68,6 +68,8 @@ class ClientRepository extends BaseRepository
|
||||
|
||||
$client->save();
|
||||
|
||||
// \Log::error($client);
|
||||
|
||||
if (isset($data['contacts'])) {
|
||||
$contacts = $this->contact_repo->save($data['contacts'], $client);
|
||||
}
|
||||
|
@ -17,24 +17,20 @@ use Illuminate\Support\Facades\Storage;
|
||||
class GetInvoicePdf
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function __invoke($invoice, $contact = null)
|
||||
{
|
||||
|
||||
if(!$contact)
|
||||
$contact = $invoice->client->primary_contact()->first();
|
||||
|
||||
$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');
|
||||
|
||||
$file = Storage::disk($disk)->exists($file_path);
|
||||
|
||||
if(!$contact)
|
||||
$contact = $invoice->client->primary_contact()->first();
|
||||
|
||||
if(!$file)
|
||||
{
|
||||
|
||||
|
@ -113,11 +113,11 @@ class InvoiceService
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInvoicePdf()
|
||||
public function getInvoicePdf($contact)
|
||||
{
|
||||
$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());
|
||||
|
||||
$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