mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
Fixes for showing non-range invoices
This commit is contained in:
parent
dd7edcff41
commit
a87fb36cf1
@ -12,10 +12,14 @@
|
|||||||
|
|
||||||
namespace App\Services\Client;
|
namespace App\Services\Client;
|
||||||
|
|
||||||
|
use App\Factory\InvoiceFactory;
|
||||||
|
use App\Factory\InvoiceInvitationFactory;
|
||||||
|
use App\Factory\InvoiceItemFactory;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
use App\Models\Product;
|
||||||
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
||||||
use App\Services\PdfMaker\PdfMaker;
|
use App\Services\PdfMaker\PdfMaker;
|
||||||
use App\Utils\HostedPDF\NinjaPdf;
|
use App\Utils\HostedPDF\NinjaPdf;
|
||||||
@ -24,6 +28,7 @@ use App\Utils\Number;
|
|||||||
use App\Utils\PhantomJS\Phantom;
|
use App\Utils\PhantomJS\Phantom;
|
||||||
use App\Utils\Traits\Pdf\PdfMaker as PdfMakerTrait;
|
use App\Utils\Traits\Pdf\PdfMaker as PdfMakerTrait;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class Statement
|
class Statement
|
||||||
{
|
{
|
||||||
@ -38,6 +43,8 @@ class Statement
|
|||||||
|
|
||||||
protected array $options;
|
protected array $options;
|
||||||
|
|
||||||
|
protected bool $rollback = false;
|
||||||
|
|
||||||
public function __construct(Client $client, array $options)
|
public function __construct(Client $client, array $options)
|
||||||
{
|
{
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
@ -99,6 +106,10 @@ class Statement
|
|||||||
nlog(print_r($e->getMessage(), 1));
|
nlog(print_r($e->getMessage(), 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->rollback) {
|
||||||
|
DB::rollBack();
|
||||||
|
}
|
||||||
|
|
||||||
return $pdf;
|
return $pdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,9 +124,66 @@ class Statement
|
|||||||
$this->entity = $this->getInvoices()->first();
|
$this->entity = $this->getInvoices()->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\is_null($this->entity)) {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$this->rollback = true;
|
||||||
|
|
||||||
|
$invoice = InvoiceFactory::create($this->client->company->id, $this->client->user->id);
|
||||||
|
$invoice->client_id = $this->client->id;
|
||||||
|
$invoice->line_items = $this->buildLineItems();
|
||||||
|
$invoice->save();
|
||||||
|
|
||||||
|
$invitation = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
|
||||||
|
$invitation->invoice_id = $invoice->id;
|
||||||
|
$invitation->client_contact_id = $this->client->contacts->first()->id;
|
||||||
|
$invitation->save();
|
||||||
|
|
||||||
|
$this->entity = $invoice;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function buildLineItems($count = 1)
|
||||||
|
{
|
||||||
|
$line_items = [];
|
||||||
|
|
||||||
|
for ($x = 0; $x < $count; $x++) {
|
||||||
|
$item = InvoiceItemFactory::create();
|
||||||
|
$item->quantity = 1;
|
||||||
|
//$item->cost = 10;
|
||||||
|
|
||||||
|
if (rand(0, 1)) {
|
||||||
|
$item->tax_name1 = 'GST';
|
||||||
|
$item->tax_rate1 = 10.00;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rand(0, 1)) {
|
||||||
|
$item->tax_name1 = 'VAT';
|
||||||
|
$item->tax_rate1 = 17.50;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rand(0, 1)) {
|
||||||
|
$item->tax_name1 = 'Sales Tax';
|
||||||
|
$item->tax_rate1 = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
$product = Product::all()->random();
|
||||||
|
|
||||||
|
$item->cost = (float) $product->cost;
|
||||||
|
$item->product_key = $product->product_key;
|
||||||
|
$item->notes = $product->notes;
|
||||||
|
$item->custom_value1 = $product->custom_value1;
|
||||||
|
$item->custom_value2 = $product->custom_value2;
|
||||||
|
$item->custom_value3 = $product->custom_value3;
|
||||||
|
$item->custom_value4 = $product->custom_value4;
|
||||||
|
|
||||||
|
$line_items[] = $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $line_items;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup & prepare options.
|
* Setup & prepare options.
|
||||||
*
|
*
|
||||||
|
@ -40,7 +40,10 @@ trait DesignHelpers
|
|||||||
|
|
||||||
if (isset($this->context['invoices'])) {
|
if (isset($this->context['invoices'])) {
|
||||||
$this->invoices = $this->context['invoices'];
|
$this->invoices = $this->context['invoices'];
|
||||||
$this->entity = $this->invoices->first();
|
|
||||||
|
if (\count($this->invoices) >= 1) {
|
||||||
|
$this->entity = $this->invoices->first();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($this->context['payments'])) {
|
if (isset($this->context['payments'])) {
|
||||||
|
@ -82,6 +82,12 @@ class PdfMaker
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return compiled HTML.
|
||||||
|
*
|
||||||
|
* @param bool $final deprecated
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function getCompiledHTML($final = false)
|
public function getCompiledHTML($final = false)
|
||||||
{
|
{
|
||||||
$html = $this->document->saveHTML();
|
$html = $this->document->saveHTML();
|
||||||
|
Loading…
Reference in New Issue
Block a user