mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on supporting statements and variables
This commit is contained in:
parent
d4ab212dbc
commit
ed3560a637
@ -28,18 +28,25 @@ class StoreProjectRequest extends Request
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('create', Project::class);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('create', Project::class);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$rules = [];
|
||||
|
||||
$rules['name'] = 'required';
|
||||
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
|
||||
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
|
||||
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('projects')->where('company_id', auth()->user()->company()->id);
|
||||
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id);
|
||||
}
|
||||
|
||||
if ($this->file('documents') && is_array($this->file('documents'))) {
|
||||
|
@ -26,15 +26,23 @@ class UpdateProjectRequest extends Request
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->project);
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('edit', $this->project);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$rules = [];
|
||||
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('projects')->where('company_id', auth()->user()->company()->id)->ignore($this->project->id);
|
||||
$rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id)->ignore($this->project->id);
|
||||
}
|
||||
|
||||
if ($this->file('documents') && is_array($this->file('documents'))) {
|
||||
|
@ -11,15 +11,16 @@
|
||||
|
||||
namespace App\Services\Client;
|
||||
|
||||
use App\Utils\Number;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Services\Email\Email;
|
||||
use App\Services\Email\EmailObject;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Email\EmailObject;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
|
||||
class ClientService
|
||||
{
|
||||
@ -42,16 +43,12 @@ class ClientService
|
||||
$this->client->saveQuietly();
|
||||
}, 2);
|
||||
} catch (\Throwable $throwable) {
|
||||
nlog("DB ERROR " . $throwable->getMessage());
|
||||
DB::connection(config('database.default'))->rollBack();
|
||||
|
||||
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
|
||||
DB::connection(config('database.default'))->rollBack();
|
||||
}
|
||||
|
||||
} catch(\Exception $exception) {
|
||||
nlog("DB ERROR " . $exception->getMessage());
|
||||
DB::connection(config('database.default'))->rollBack();
|
||||
|
||||
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
|
||||
DB::connection(config('database.default'))->rollBack();
|
||||
@ -240,8 +237,13 @@ class ClientService
|
||||
|
||||
}
|
||||
|
||||
$invoice = $this->client->invoices()->whereHas('invitations')->first();
|
||||
|
||||
$email_object->attachments = [['file' => base64_encode($pdf), 'name' => ctrans('texts.statement') . ".pdf"]];
|
||||
$email_object->client_id = $this->client->id;
|
||||
$email_object->entity_class = Invoice::class;
|
||||
$email_object->entity_id = $invoice->id ?? null;
|
||||
$email_object->invitation_id = $invoice->invitations->first()->id ?? null;
|
||||
$email_object->email_template_subject = 'email_subject_statement';
|
||||
$email_object->email_template_body = 'email_template_statement';
|
||||
$email_object->variables = [
|
||||
|
@ -46,6 +46,8 @@ class Statement
|
||||
|
||||
protected bool $rollback = false;
|
||||
|
||||
private array $variables = [];
|
||||
|
||||
public function __construct(protected Client $client, public array $options)
|
||||
{
|
||||
}
|
||||
@ -108,8 +110,6 @@ class Statement
|
||||
'process_markdown' => $this->entity->client->company->markdown_enabled,
|
||||
];
|
||||
|
||||
|
||||
|
||||
$maker = new PdfMaker($state);
|
||||
|
||||
$maker
|
||||
@ -118,7 +118,6 @@ class Statement
|
||||
|
||||
$pdf = null;
|
||||
$html = $maker->getCompiledHTML(true);
|
||||
|
||||
|
||||
if ($this->rollback) {
|
||||
\DB::connection(config('database.default'))->rollBack();
|
||||
@ -126,12 +125,26 @@ class Statement
|
||||
|
||||
$pdf = $this->convertToPdf($html);
|
||||
|
||||
$this->setVariables($variables);
|
||||
|
||||
$maker = null;
|
||||
$state = null;
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
public function setVariables($variables): self
|
||||
{
|
||||
$this->variables = $variables;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getVariables(): array
|
||||
{
|
||||
return $this->variables;
|
||||
}
|
||||
|
||||
private function templateStatement($variables)
|
||||
{
|
||||
if(isset($this->options['template'])) {
|
||||
|
@ -156,7 +156,7 @@ class Email implements ShouldQueue
|
||||
|
||||
/**
|
||||
* Generates the correct set of variables
|
||||
*
|
||||
* @todo handle payment engine here also
|
||||
* @return self
|
||||
*/
|
||||
private function resolveVariables(): self
|
||||
|
@ -17209,7 +17209,7 @@ components:
|
||||
type: object
|
||||
properties:
|
||||
quantity:
|
||||
type: integer
|
||||
type: number
|
||||
example: 1
|
||||
description: 'The quantity of the product offered for this line item'
|
||||
cost:
|
||||
|
@ -2,7 +2,7 @@
|
||||
type: object
|
||||
properties:
|
||||
quantity:
|
||||
type: integer
|
||||
type: number
|
||||
example: 1
|
||||
description: 'The quantity of the product offered for this line item'
|
||||
cost:
|
||||
|
Loading…
x
Reference in New Issue
Block a user