1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Fixes for Credit PDF generation (#3417)

* Fix for design GET route

* Fixes for Credit PDF creation
This commit is contained in:
David Bomba 2020-03-04 10:51:50 +11:00 committed by GitHub
parent b8c26bb534
commit b157ee3917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 125 additions and 82 deletions

View File

@ -137,8 +137,7 @@ class DesignFilters extends QueryFilters
*/
public function entityFilter()
{
//return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->company();
return $this->builder->whereCompanyId(auth()->user()->company()->id)->orWhere('company_id',null);
}
}

View File

@ -12,6 +12,7 @@
namespace App\Http\Controllers;
use App\Models\Company;
use App\Models\Design;
use App\Models\User;
use App\Transformers\ArraySerializer;
use App\Transformers\EntityTransformer;
@ -150,7 +151,7 @@ class BaseController extends Controller
$query->with($includes);
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
} elseif ($this->entity_type == User::class) {
$query->where('id', '=', auth()->user()->id);

View File

@ -18,9 +18,11 @@ use App\Models\Filterable;
use App\Services\Credit\CreditService;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceValues;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Laracasts\Presenter\PresentableTrait;
class Credit extends BaseModel
{
@ -28,7 +30,11 @@ class Credit extends BaseModel
use Filterable;
use MakesDates;
use SoftDeletes;
use PresentableTrait;
use MakesInvoiceValues;
protected $presenter = 'App\Models\Presenters\CreditPresenter';
protected $fillable = [
'number',
'discount',

View File

@ -40,4 +40,5 @@ class Design extends BaseModel
}
}

View 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
{
}

View File

@ -139,4 +139,40 @@ class EntityPresenter extends Presenter
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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -47,7 +47,7 @@ class CreditService
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;
}

View File

@ -9,26 +9,29 @@ class MarkSent
{
private $client;
public function __construct($client)
private $credit;
public function __construct($client, $credit)
{
$this->client = $client;
$this->credit = $credit;
}
public function run($credit)
public function run()
{
/* Return immediately if status is not draft */
if ($credit->status_id != Credit::STATUS_DRAFT) {
return $credit;
if ($this->credit->status_id != Credit::STATUS_DRAFT) {
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;
}
}

View File

@ -344,6 +344,9 @@ trait MakesInvoiceValues
$data['$credit_amount'] = &$data['$total'];
$data['$credit_balance'] = &$data['$balance'];
$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['$quote_issued_to'] = ;
@ -355,6 +358,7 @@ trait MakesInvoiceValues
// $data['$quote_to'] = ;
// $data['$details'] = ;
$data['$invoice_no'] = $this->number ?: '&nbsp;';
$data['$invoice.invoice_no'] = &$data['$invoice_no'];
$data['$client1'] = $this->client->custom_value1 ?: '&nbsp;';
$data['$client2'] = $this->client->custom_value2 ?: '&nbsp;';
@ -432,7 +436,6 @@ trait MakesInvoiceValues
$data['$statement_to'] = ;
$data['$credit_note'] = ;
$data['$credit_date'] = ;
$data['$credit_number'] = ;
$data['$credit_issued_to'] = ;
$data['$credit_to'] = ;
$data['$your_credit'] = ;

View File

@ -4,6 +4,7 @@ namespace Tests\Integration;
use App\Designs\Designer;
use App\Designs\Modern;
use App\Jobs\Credit\CreateCreditPdf;
use App\Jobs\Invoice\CreateInvoicePdf;
use App\Jobs\Quote\CreateQuotePdf;
use App\Utils\Traits\GeneratesCounter;
@ -71,12 +72,40 @@ class DesignTest extends TestCase
$settings = $this->invoice->client->settings;
$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->save();
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()
{
@ -85,6 +114,10 @@ class DesignTest extends TestCase
$settings = $this->invoice->client->settings;
$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->save();

View File

@ -248,6 +248,13 @@ trait MockAccountData
$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->each(function ($contact) {