mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for Credit PDF generation (#3417)
* Fix for design GET route * Fixes for Credit PDF creation
This commit is contained in:
parent
b8c26bb534
commit
b157ee3917
@ -137,8 +137,7 @@ class DesignFilters extends QueryFilters
|
|||||||
*/
|
*/
|
||||||
public function entityFilter()
|
public function entityFilter()
|
||||||
{
|
{
|
||||||
|
|
||||||
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
|
||||||
return $this->builder->company();
|
return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id',null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
use App\Models\Design;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Transformers\ArraySerializer;
|
use App\Transformers\ArraySerializer;
|
||||||
use App\Transformers\EntityTransformer;
|
use App\Transformers\EntityTransformer;
|
||||||
@ -150,7 +151,7 @@ class BaseController extends Controller
|
|||||||
$query->with($includes);
|
$query->with($includes);
|
||||||
|
|
||||||
if (auth()->user()->cannot('view_'.$this->entity_type)) {
|
if (auth()->user()->cannot('view_'.$this->entity_type)) {
|
||||||
if ($this->entity_type == Company::class) {
|
if ($this->entity_type == Company::class || $this->entity_type == Design::class ) {
|
||||||
//no user keys exist on the company table, so we need to skip
|
//no user keys exist on the company table, so we need to skip
|
||||||
} elseif ($this->entity_type == User::class) {
|
} elseif ($this->entity_type == User::class) {
|
||||||
$query->where('id', '=', auth()->user()->id);
|
$query->where('id', '=', auth()->user()->id);
|
||||||
|
@ -18,9 +18,11 @@ use App\Models\Filterable;
|
|||||||
use App\Services\Credit\CreditService;
|
use App\Services\Credit\CreditService;
|
||||||
use App\Utils\Traits\MakesDates;
|
use App\Utils\Traits\MakesDates;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use App\Utils\Traits\MakesInvoiceValues;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Laracasts\Presenter\PresentableTrait;
|
||||||
|
|
||||||
class Credit extends BaseModel
|
class Credit extends BaseModel
|
||||||
{
|
{
|
||||||
@ -28,7 +30,11 @@ class Credit extends BaseModel
|
|||||||
use Filterable;
|
use Filterable;
|
||||||
use MakesDates;
|
use MakesDates;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
use PresentableTrait;
|
||||||
|
use MakesInvoiceValues;
|
||||||
|
|
||||||
|
protected $presenter = 'App\Models\Presenters\CreditPresenter';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'number',
|
'number',
|
||||||
'discount',
|
'discount',
|
||||||
|
@ -40,4 +40,5 @@ class Design extends BaseModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
21
app/Models/Presenters/CreditPresenter.php
Normal file
21
app/Models/Presenters/CreditPresenter.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Models\Presenters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CreditPresenter
|
||||||
|
* @package App\Models\Presenters
|
||||||
|
*/
|
||||||
|
class CreditPresenter extends EntityPresenter
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -139,4 +139,40 @@ class EntityPresenter extends Presenter
|
|||||||
return $str . ' ' . $postalCode;
|
return $str . ' ' . $postalCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function clientName()
|
||||||
|
{
|
||||||
|
return $this->client->present()->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function address()
|
||||||
|
{
|
||||||
|
return $this->client->present()->address();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shippingAddress()
|
||||||
|
{
|
||||||
|
return $this->client->present()->shipping_address();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function companyLogo()
|
||||||
|
{
|
||||||
|
return $this->company->logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function clientLogo()
|
||||||
|
{
|
||||||
|
return $this->client->logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function companyName()
|
||||||
|
{
|
||||||
|
return $this->company->present()->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function companyAddress()
|
||||||
|
{
|
||||||
|
return $this->company->present()->address();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -45,38 +45,4 @@ class InvoicePresenter extends EntityPresenter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clientName()
|
|
||||||
{
|
|
||||||
return $this->client->present()->name();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function address()
|
|
||||||
{
|
|
||||||
return $this->client->present()->address();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function shippingAddress()
|
|
||||||
{
|
|
||||||
return $this->client->present()->shipping_address();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function companyLogo()
|
|
||||||
{
|
|
||||||
return $this->company->logo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function clientLogo()
|
|
||||||
{
|
|
||||||
return $this->client->logo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function companyName()
|
|
||||||
{
|
|
||||||
return $this->company->present()->name();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function companyAddress()
|
|
||||||
{
|
|
||||||
return $this->company->present()->address();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -45,38 +45,5 @@ class QuotePresenter extends EntityPresenter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clientName()
|
|
||||||
{
|
|
||||||
return $this->client->present()->name();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function address()
|
|
||||||
{
|
|
||||||
return $this->client->present()->address();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function shippingAddress()
|
|
||||||
{
|
|
||||||
return $this->client->present()->shipping_address();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function companyLogo()
|
|
||||||
{
|
|
||||||
return $this->company->logo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function clientLogo()
|
|
||||||
{
|
|
||||||
return $this->client->logo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function companyName()
|
|
||||||
{
|
|
||||||
return $this->company->present()->name();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function companyAddress()
|
|
||||||
{
|
|
||||||
return $this->company->present()->address();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class CreditService
|
|||||||
|
|
||||||
public function markSent()
|
public function markSent()
|
||||||
{
|
{
|
||||||
$this->credit = (new MarkSent($this->credit->client))->run($this->credit);
|
$this->credit = (new MarkSent($this->credit->client, $this->credit))->run();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -9,26 +9,29 @@ class MarkSent
|
|||||||
{
|
{
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
public function __construct($client)
|
private $credit;
|
||||||
|
|
||||||
|
public function __construct($client, $credit)
|
||||||
{
|
{
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
|
$this->credit = $credit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run($credit)
|
public function run()
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Return immediately if status is not draft */
|
/* Return immediately if status is not draft */
|
||||||
if ($credit->status_id != Credit::STATUS_DRAFT) {
|
if ($this->credit->status_id != Credit::STATUS_DRAFT) {
|
||||||
return $credit;
|
return $this->credit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$credit->markInvitationsSent();
|
$this->credit->markInvitationsSent();
|
||||||
|
|
||||||
event(new CreditWasMarkedSent($credit, $credit->company));
|
event(new CreditWasMarkedSent($this->credit, $this->credit->company));
|
||||||
|
|
||||||
$credit->service()->setStatus(Credit::STATUS_SENT)->applyNumber()->save();
|
$this->credit->service()->setStatus(Credit::STATUS_SENT)->applyNumber()->save();
|
||||||
|
|
||||||
return $credit;
|
return $this->credit;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,6 +344,9 @@ trait MakesInvoiceValues
|
|||||||
$data['$credit_amount'] = &$data['$total'];
|
$data['$credit_amount'] = &$data['$total'];
|
||||||
$data['$credit_balance'] = &$data['$balance'];
|
$data['$credit_balance'] = &$data['$balance'];
|
||||||
$data['$credit.amount'] = &$data['$total'];
|
$data['$credit.amount'] = &$data['$total'];
|
||||||
|
$data['$credit_number'] = &$data['$number'];
|
||||||
|
$data['$credit_no'] = &$data['$number'];
|
||||||
|
$data['$credit.credit_no'] = &$data['$number'];
|
||||||
|
|
||||||
// $data['$invoice_issued_to'] = ;
|
// $data['$invoice_issued_to'] = ;
|
||||||
// $data['$quote_issued_to'] = ;
|
// $data['$quote_issued_to'] = ;
|
||||||
@ -355,6 +358,7 @@ trait MakesInvoiceValues
|
|||||||
// $data['$quote_to'] = ;
|
// $data['$quote_to'] = ;
|
||||||
// $data['$details'] = ;
|
// $data['$details'] = ;
|
||||||
$data['$invoice_no'] = $this->number ?: ' ';
|
$data['$invoice_no'] = $this->number ?: ' ';
|
||||||
|
|
||||||
$data['$invoice.invoice_no'] = &$data['$invoice_no'];
|
$data['$invoice.invoice_no'] = &$data['$invoice_no'];
|
||||||
$data['$client1'] = $this->client->custom_value1 ?: ' ';
|
$data['$client1'] = $this->client->custom_value1 ?: ' ';
|
||||||
$data['$client2'] = $this->client->custom_value2 ?: ' ';
|
$data['$client2'] = $this->client->custom_value2 ?: ' ';
|
||||||
@ -432,7 +436,6 @@ trait MakesInvoiceValues
|
|||||||
$data['$statement_to'] = ;
|
$data['$statement_to'] = ;
|
||||||
$data['$credit_note'] = ;
|
$data['$credit_note'] = ;
|
||||||
$data['$credit_date'] = ;
|
$data['$credit_date'] = ;
|
||||||
$data['$credit_number'] = ;
|
|
||||||
$data['$credit_issued_to'] = ;
|
$data['$credit_issued_to'] = ;
|
||||||
$data['$credit_to'] = ;
|
$data['$credit_to'] = ;
|
||||||
$data['$your_credit'] = ;
|
$data['$your_credit'] = ;
|
||||||
|
@ -4,6 +4,7 @@ namespace Tests\Integration;
|
|||||||
|
|
||||||
use App\Designs\Designer;
|
use App\Designs\Designer;
|
||||||
use App\Designs\Modern;
|
use App\Designs\Modern;
|
||||||
|
use App\Jobs\Credit\CreateCreditPdf;
|
||||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||||
use App\Jobs\Quote\CreateQuotePdf;
|
use App\Jobs\Quote\CreateQuotePdf;
|
||||||
use App\Utils\Traits\GeneratesCounter;
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
@ -71,12 +72,40 @@ class DesignTest extends TestCase
|
|||||||
$settings = $this->invoice->client->settings;
|
$settings = $this->invoice->client->settings;
|
||||||
$settings->quote_design_id = "6";
|
$settings->quote_design_id = "6";
|
||||||
|
|
||||||
|
$this->quote->client_id = $this->client->id;
|
||||||
|
$this->quote->setRelation('client', $this->client);
|
||||||
|
$this->quote->save();
|
||||||
|
|
||||||
$this->client->settings = $settings;
|
$this->client->settings = $settings;
|
||||||
$this->client->save();
|
$this->client->save();
|
||||||
|
|
||||||
CreateQuotePdf::dispatchNow($this->quote, $this->quote->company, $this->quote->client->primary_contact()->first());
|
CreateQuotePdf::dispatchNow($this->quote, $this->quote->company, $this->quote->client->primary_contact()->first());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreditDesignExists()
|
||||||
|
{
|
||||||
|
|
||||||
|
$modern = new Modern();
|
||||||
|
|
||||||
|
$designer = new Designer($modern, $this->company->settings->pdf_variables, 'credit');
|
||||||
|
|
||||||
|
$html = $designer->build($this->credit)->getHtml();
|
||||||
|
|
||||||
|
$this->assertNotNull($html);
|
||||||
|
|
||||||
|
$settings = $this->invoice->client->settings;
|
||||||
|
$settings->quote_design_id = "6";
|
||||||
|
|
||||||
|
$this->credit->client_id = $this->client->id;
|
||||||
|
$this->credit->setRelation('client', $this->client);
|
||||||
|
$this->credit->save();
|
||||||
|
|
||||||
|
$this->client->settings = $settings;
|
||||||
|
$this->client->save();
|
||||||
|
|
||||||
|
CreateCreditPdf::dispatchNow($this->credit, $this->credit->company, $this->credit->client->primary_contact()->first());
|
||||||
|
}
|
||||||
|
|
||||||
public function testAllDesigns()
|
public function testAllDesigns()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -85,6 +114,10 @@ class DesignTest extends TestCase
|
|||||||
|
|
||||||
$settings = $this->invoice->client->settings;
|
$settings = $this->invoice->client->settings;
|
||||||
$settings->quote_design_id = (string)$x;
|
$settings->quote_design_id = (string)$x;
|
||||||
|
|
||||||
|
$this->quote->client_id = $this->client->id;
|
||||||
|
$this->quote->setRelation('client', $this->client);
|
||||||
|
$this->quote->save();
|
||||||
|
|
||||||
$this->client->settings = $settings;
|
$this->client->settings = $settings;
|
||||||
$this->client->save();
|
$this->client->save();
|
||||||
|
@ -248,6 +248,13 @@ trait MockAccountData
|
|||||||
|
|
||||||
$this->credit->save();
|
$this->credit->save();
|
||||||
|
|
||||||
|
|
||||||
|
$this->credit_calc = new InvoiceSum($this->credit);
|
||||||
|
$this->credit_calc->build();
|
||||||
|
|
||||||
|
$this->credit = $this->credit_calc->getCredit();
|
||||||
|
$this->credit->service()->markSent();
|
||||||
|
|
||||||
$contacts = $this->invoice->client->contacts;
|
$contacts = $this->invoice->client->contacts;
|
||||||
|
|
||||||
$contacts->each(function ($contact) {
|
$contacts->each(function ($contact) {
|
||||||
|
Loading…
Reference in New Issue
Block a user