mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-12 14:12:44 +01:00
Updates for structure of payment entities
This commit is contained in:
parent
a9fd7d4a54
commit
9fee3c538c
@ -31,14 +31,8 @@ class EmailPayment implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $payment;
|
||||
|
||||
public $email_builder;
|
||||
|
||||
private $contact;
|
||||
|
||||
private $company;
|
||||
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
@ -49,11 +43,8 @@ class EmailPayment implements ShouldQueue
|
||||
* @param $contact
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct(Payment $payment, Company $company, ?ClientContact $contact)
|
||||
public function __construct(public Payment $payment, private Company $company, private ?ClientContact $contact)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
$this->contact = $contact;
|
||||
$this->company = $company;
|
||||
$this->settings = $payment->client->getMergedSettings();
|
||||
}
|
||||
|
||||
|
@ -32,14 +32,8 @@ class EmailRefundPayment implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $payment;
|
||||
|
||||
public $email_builder;
|
||||
|
||||
private $contact;
|
||||
|
||||
private $company;
|
||||
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
@ -50,11 +44,8 @@ class EmailRefundPayment implements ShouldQueue
|
||||
* @param $contact
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct(Payment $payment, Company $company, ClientContact $contact)
|
||||
public function __construct(public Payment $payment, private Company $company, private ?ClientContact $contact)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
$this->contact = $contact;
|
||||
$this->company = $company;
|
||||
$this->settings = $payment->client->getMergedSettings();
|
||||
}
|
||||
|
||||
@ -84,7 +75,9 @@ class EmailRefundPayment implements ShouldQueue
|
||||
$template_data['body'] = ctrans('texts.refunded_payment').' $payment.refunded <br><br>$invoices';
|
||||
$template_data['subject'] = ctrans('texts.refunded_payment');
|
||||
|
||||
$email_builder = (new PaymentEmailEngine($this->payment, $this->contact, $template_data))->build();
|
||||
$email_builder = new PaymentEmailEngine($this->payment, $this->contact, $template_data);
|
||||
$email_builder->is_refund = true;
|
||||
$email_builder->build();
|
||||
|
||||
$invitation = null;
|
||||
|
||||
|
@ -15,12 +15,14 @@ use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\Helpers;
|
||||
use App\Models\Account;
|
||||
use App\Models\Payment;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use App\Jobs\Entity\CreateRawPdf;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\DataMapper\EmailTemplateDefaults;
|
||||
use App\Services\Template\TemplateAction;
|
||||
|
||||
class PaymentEmailEngine extends BaseEmailEngine
|
||||
{
|
||||
@ -44,6 +46,8 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
|
||||
private $payment_template_subject;
|
||||
|
||||
public bool $is_refund = false;
|
||||
|
||||
public function __construct($payment, $contact, $template_data = null)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
@ -92,9 +96,44 @@ class PaymentEmailEngine extends BaseEmailEngine
|
||||
|
||||
if ($this->client->getSetting('pdf_email_attachment') !== false && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) {
|
||||
$this->payment->invoices->each(function ($invoice) {
|
||||
$pdf = ((new CreateRawPdf($invoice->invitations->first(), $invoice->company->db))->handle());
|
||||
|
||||
$this->setAttachments([['file' => base64_encode($pdf), 'name' => $invoice->numberFormatter().'.pdf']]);
|
||||
if($this->is_refund && strlen($invoice->client->getSetting('payment_refund_design_id')) > 2) {
|
||||
$pdf = (new TemplateAction(
|
||||
[$this->payment->hashed_id],
|
||||
$invoice->client->getSetting('payment_refund_design_id'),
|
||||
Payment::class,
|
||||
$this->payment->user_id,
|
||||
$this->payment->company,
|
||||
$this->payment->company->db,
|
||||
'nohash',
|
||||
false
|
||||
))->handle();
|
||||
|
||||
$file_name = ctrans('texts.payment_refund_receipt', ['number' => $this->payment->number ]) . '.pdf';
|
||||
$file_name = str_replace(' ', '_', $file_name);
|
||||
|
||||
}
|
||||
elseif(!$this->is_refund && strlen($invoice->client->getSetting('payment_receipt_design_id')) > 2){
|
||||
$pdf = (new TemplateAction(
|
||||
[$this->payment->hashed_id],
|
||||
$invoice->client->getSetting('payment_refund_design_id'),
|
||||
Payment::class,
|
||||
$this->payment->user_id,
|
||||
$this->payment->company,
|
||||
$this->payment->company->db,
|
||||
'nohash',
|
||||
false))->handle();
|
||||
|
||||
$file_name = ctrans('texts.payment_receipt', ['number' => $this->payment->number ]) . '.pdf';
|
||||
$file_name = str_replace(' ', '_', $file_name);
|
||||
|
||||
}
|
||||
else {
|
||||
$pdf = ((new CreateRawPdf($invoice->invitations->first(), $invoice->company->db))->handle());
|
||||
$file_name = $invoice->numberFormatter().'.pdf';
|
||||
}
|
||||
|
||||
$this->setAttachments([['file' => base64_encode($pdf), 'name' => $file_name]]);
|
||||
|
||||
//attach invoice documents also to payments
|
||||
if ($this->client->getSetting('document_email_attachment') !== false) {
|
||||
|
@ -74,7 +74,8 @@ class TemplateAction implements ShouldQueue
|
||||
*
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
{ nlog("inside template action");
|
||||
|
||||
MultiDB::setDb($this->db);
|
||||
|
||||
$key = $this->resolveEntityString();
|
||||
@ -85,16 +86,22 @@ class TemplateAction implements ShouldQueue
|
||||
|
||||
$template_service = new TemplateService($template);
|
||||
|
||||
if($this->entity == Invoice::class) {
|
||||
$resource->with('payments', 'client');
|
||||
}
|
||||
match($this->entity){
|
||||
Invoice::class => $resource->with('payments', 'client'),
|
||||
Quote::class => $resource->with('client'),
|
||||
Task::class => $resource->with('client'),
|
||||
Credit::class => $resource->with('client'),
|
||||
RecurringInvoice::class => $resource->with('client'),
|
||||
Project::class => $resource->with('client'),
|
||||
Expense::class => $resource->with('client'),
|
||||
Payment::class => $resource->with('invoices', 'client'),
|
||||
};
|
||||
|
||||
$result = $resource->withTrashed()
|
||||
->whereIn('id', $this->transformKeys($this->ids))
|
||||
->where('company_id', $this->company->id)
|
||||
->get();
|
||||
|
||||
|
||||
if($result->count() <= 1)
|
||||
$data[$key] = collect($result);
|
||||
else
|
||||
@ -103,15 +110,16 @@ class TemplateAction implements ShouldQueue
|
||||
$ts = $template_service->build($data);
|
||||
|
||||
nlog($ts->getHtml());
|
||||
$pdf = $ts->getPdf();
|
||||
|
||||
if($this->send_email)
|
||||
if($this->send_email) {
|
||||
$pdf = $ts->getPdf();
|
||||
$this->sendEmail($pdf, $template);
|
||||
}
|
||||
else {
|
||||
|
||||
$pdf = $ts->getPdf();
|
||||
$filename = "templates/{$this->hash}.pdf";
|
||||
Storage::disk(config('filesystems.default'))->put($filename, $pdf);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -514,6 +514,8 @@ class TemplateService
|
||||
'custom_value2' => $payment->custom_value2 ?? '',
|
||||
'custom_value3' => $payment->custom_value3 ?? '',
|
||||
'custom_value4' => $payment->custom_value4 ?? '',
|
||||
'created_at' => $this->translateDate($payment->created_at, $payment->client->date_format(), $payment->client->locale()),
|
||||
'updated_at' => $this->translateDate($payment->updated_at, $payment->client->date_format(), $payment->client->locale()),
|
||||
'client' => [
|
||||
'name' => $payment->client->present()->name(),
|
||||
'balance' => $payment->client->balance,
|
||||
@ -587,27 +589,11 @@ class TemplateService
|
||||
{
|
||||
|
||||
$payments = $payments->map(function ($payment) {
|
||||
// nlog(microtime(true));
|
||||
return $this->transformPayment($payment);
|
||||
})->toArray();
|
||||
|
||||
|
||||
return $payments;
|
||||
// $it = new PaymentTransformer();
|
||||
// $it->setDefaultIncludes(['client','invoices','paymentables']);
|
||||
// $manager = new Manager();
|
||||
// $manager->parseIncludes(['client','invoices','paymentables']);
|
||||
// $resource = new \League\Fractal\Resource\Collection($payments, $it, null);
|
||||
// $resources = $manager->createData($resource)->toArray();
|
||||
|
||||
// foreach($resources['data'] as $key => $resource) {
|
||||
|
||||
// $resources['data'][$key]['client'] = $resource['client']['data'] ?? [];
|
||||
// $resources['data'][$key]['client']['contacts'] = $resource['client']['data']['contacts']['data'] ?? [];
|
||||
// $resources['data'][$key]['invoices'] = $invoice['invoices']['data'] ?? [];
|
||||
|
||||
// }
|
||||
|
||||
// return $resources['data'];
|
||||
|
||||
}
|
||||
|
||||
|
@ -5161,6 +5161,8 @@ $LANG = array(
|
||||
'show_document_preview' => 'Show Document Preview',
|
||||
'cash_accounting' => 'Cash accounting',
|
||||
'click_or_drop_files_here' => 'Click or drop files here',
|
||||
'payment_refund_receipt' => 'Payment Refund Receipt # :number',
|
||||
'payment_receipt' => 'Payment Receipt # :number',
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
Loading…
Reference in New Issue
Block a user