working on invoice labels and template values

This commit is contained in:
David Bomba 2019-09-02 15:08:26 +10:00
parent 019cc09dbb
commit d99443806a
10 changed files with 160 additions and 161 deletions

View File

@ -151,10 +151,10 @@ class InvoiceCalc
{
// custom fields charged taxes
if (isset($this->invoice->custom_value1) && $this->settings->custom_taxes1) {
if (isset($this->invoice->custom_value1) && isset($this->settings->custom_taxes1)) {
$this->total += $this->invoice->custom_value1;
}
if (isset($this->invoice->custom_value2) && $this->settings->custom_taxes2) {
if (isset($this->invoice->custom_value2) && isset($this->settings->custom_taxes2)) {
$this->total += $this->invoice->custom_value2;
}

View File

@ -91,7 +91,9 @@ class CreateInvoicePdf
$data['invoice'] = $invoice;
return view($design, $data)->render();
$template_variables = array_merge($invoice->makeLabels(), $invoice->makeValues());
return view($design, array_merge($data, $template_variables))->render();
}
}

View File

@ -15,6 +15,8 @@ use App\Models\Currency;
use App\Models\Filterable;
use App\Utils\Number;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesInvoiceLabels;
use App\Utils\Traits\MakesInvoiceValues;
use App\Utils\Traits\NumberFormatter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@ -29,7 +31,8 @@ class Invoice extends BaseModel
use NumberFormatter;
use MakesDates;
use PresentableTrait;
use MakesInvoiceValues;
use MakesInvoiceLabels;
protected $presenter = 'App\Models\Presenters\InvoicePresenter';
protected $hidden = [
@ -248,92 +251,4 @@ class Invoice extends BaseModel
return $this->settings->design ?: 'pdf.design1';
}
public function makeInvoiceValues()
{
$data = [];
$data['invoice'] = ;
$data['invoice_date'] = $this->invoice_date;
// $data['due_date'] = ;
$data['invoice_number'] = $this->invoice_number;
$data['po_number'] = $this->po_number;
// $data['discount'] = ;
// $data['taxes'] = ;
// $data['tax'] = ;
// $data['item'] = ;
// $data['description'] = ;
// $data['unit_cost'] = ;
// $data['quantity'] = ;
// $data['line_total'] = ;
// $data['subtotal'] = ;
// $data['paid_to_date'] = ;
$data['balance_due'] = Number::formatMoney($this->balance, $this->client->currency, $this->client->country, $this->client->settings);
$data['partial_due'] = Number::formatMoney($this->partial, $this->client->currency, $this->client->country, $this->client->settings);
// $data['terms'] = $this->terms;
// $data['your_invoice'] = ;
// $data['quote'] = ;
// $data['your_quote'] = ;
// $data['quote_date'] = ;
// $data['quote_number'] = ;
$data['total'] = Number::formatMoney($this->amount, $this->client->currency, $this->client->country, $this->client->settings);
// $data['invoice_issued_to'] = ;
// $data['quote_issued_to'] = ;
// $data['rate'] = ;
// $data['hours'] = ;
// $data['balance'] = ;
// $data['from'] = ;
// $data['to'] = ;
// $data['invoice_to'] = ;
// $data['quote_to'] = ;
// $data['details'] = ;
$data['invoice_no'] = $this->invoice_number;
// $data['quote_no'] = ;
// $data['valid_until'] = ;
$data['client_name'] = $this->present()->clientName();
$data['address1'] = $this->client->address1;
$data['address2'] = $this->client->address2;
$data['id_number'] = $this->client->id_number;
$data['vat_number'] = $this->client->vat_number;
$data['city_state_postal'] = ;
$data['postal_city_state'] = ;
$data['country'] = ;
$data['email'] = ;
$data['contact_nae'] = ;
$data['company_name'] = ;
$data['website'] = ;
$data['phone'] = ;
$data['blank'] = ;
$data['surcharge'] = ;
$data['tax_invoice'] =
$data['tax_quote'] =
$data['statement'] = ;
$data['statement_date'] = ;
$data['your_statement'] = ;
$data['statement_issued_to'] = ;
$data['statement_to'] = ;
$data['credit_note'] = ;
$data['credit_date'] = ;
$data['credit_number'] = ;
$data['credit_issued_to'] = ;
$data['credit_to'] = ;
$data['your_credit'] = ;
$data['work_phone'] = ;
$data['invoice_total'] = ;
$data['outstanding'] = ;
$data['invoice_due_date'] = ;
$data['quote_due_date'] = ;
$data['service'] = ;
$data['product_key'] = ;
$data['unit_cost'] = ;
$data['custom_value1'] = ;
$data['custom_value2'] = ;
$data['delivery_note'] = ;
$data['date'] = ;
$data['method'] = ;
$data['payment_date'] = ;
$data['reference'] = ;
$data['amount'] = ;
$data['amount_paid'] =;
}
}

View File

@ -51,6 +51,10 @@ class Payment extends BaseModel
'transaction_reference'
];
protected $casts = [
'settings' => 'object'
];
public function client()
{
return $this->belongsTo(Client::class);

View File

@ -26,6 +26,11 @@ class ClientPresenter extends EntityPresenter
return $this->entity->name ?: $this->entity->primary_contact->first()->first_name . ' '. $this->entity->primary_contact->first()->last_name;
}
public function primary_contact_name()
{
return $this->entity->primary_contact->first()->first_name . ' '. $this->entity->primary_contact->first()->last_name;;
}
public function address()
{
$str = '';

View File

@ -53,7 +53,7 @@ class InvoicePresenter extends EntityPresenter
public function companyName()
{
return $this->company->present()->name()
return $this->company->present()->name();
}
public function companyAddress()

View File

@ -151,3 +151,4 @@ trait MakesInvoiceLabels
return $data;
}
}

View File

@ -0,0 +1,116 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Utils\Traits;
use App\Utils\Number;
use Illuminate\Support\Facades\Log;
/**
* Class MakesInvoiceValues
* @package App\Utils\Traits
*/
trait MakesInvoiceValues
{
public function makeValues()
{
$data = [];
//$data['invoice'] = ;
$data['invoice_date'] = $this->invoice_date;
$data['due_date'] = $this->due_date;
$data['invoice_number'] = $this->invoice_number;
$data['po_number'] = $this->po_number;
// $data['discount'] = ;
// $data['taxes'] = ;
// $data['tax'] = ;
// $data['item'] = ;
// $data['description'] = ;
// $data['unit_cost'] = ;
// $data['quantity'] = ;
// $data['line_total'] = ;
// $data['subtotal'] = ;
// $data['paid_to_date'] = ;
$data['balance_due'] = Number::formatMoney($this->balance, $this->client->currency(), $this->client->country, $this->client->settings);
$data['partial_due'] = Number::formatMoney($this->partial, $this->client->currency(), $this->client->country, $this->client->settings);
$data['terms'] = $this->terms;
// $data['your_invoice'] = ;
// $data['quote'] = ;
// $data['your_quote'] = ;
// $data['quote_date'] = ;
// $data['quote_number'] = ;
$data['total'] = Number::formatMoney($this->amount, $this->client->currency(), $this->client->country, $this->client->settings);
// $data['invoice_issued_to'] = ;
// $data['quote_issued_to'] = ;
// $data['rate'] = ;
// $data['hours'] = ;
// $data['balance'] = ;
// $data['from'] = ;
// $data['to'] = ;
// $data['invoice_to'] = ;
// $data['quote_to'] = ;
// $data['details'] = ;
$data['invoice_no'] = $this->invoice_number;
// $data['quote_no'] = ;
// $data['valid_until'] = ;
$data['client_name'] = $this->present()->clientName();
$data['address1'] = $this->client->address1;
$data['address2'] = $this->client->address2;
$data['id_number'] = $this->client->id_number;
$data['vat_number'] = $this->client->vat_number;
$data['city_state_postal'] = $this->present()->cityStateZip($this->client->city, $this->client->state, $this->client->postal_code, FALSE);
$data['postal_city_state'] = $this->present()->cityStateZip($this->client->city, $this->client->state, $this->client->postal_code, TRUE);
$data['country'] = $this->client->country->name;
$data['email'] = isset($this->client->primary_contact()->first()->email) ?: 'no primary contact set';
$data['contact_name'] = $this->client->present()->primary_contact_name();
$data['company_name'] = $this->company->name;
$data['website'] = $this->client->website;
$data['phone'] = $this->client->primary_contact->first()->phone;
//$data['blank'] = ;
//$data['surcharge'] = ;
/*
$data['tax_invoice'] =
$data['tax_quote'] =
$data['statement'] = ;
$data['statement_date'] = ;
$data['your_statement'] = ;
$data['statement_issued_to'] = ;
$data['statement_to'] = ;
$data['credit_note'] = ;
$data['credit_date'] = ;
$data['credit_number'] = ;
$data['credit_issued_to'] = ;
$data['credit_to'] = ;
$data['your_credit'] = ;
$data['work_phone'] = ;
$data['invoice_total'] = ;
$data['outstanding'] = ;
$data['invoice_due_date'] = ;
$data['quote_due_date'] = ;
$data['service'] = ;
$data['product_key'] = ;
$data['unit_cost'] = ;
$data['custom_value1'] = ;
$data['custom_value2'] = ;
$data['delivery_note'] = ;
$data['date'] = ;
$data['method'] = ;
$data['payment_date'] = ;
$data['reference'] = ;
$data['amount'] = ;
$data['amount_paid'] =;
*/
return $data;
}
}

View File

@ -98,12 +98,15 @@ class RandomDataSeeder extends Seeder
factory(\App\Models\Product::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id]);
/** Invoice Factory */
factory(\App\Models\Invoice::class,500)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
factory(\App\Models\Invoice::class,500)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
/** Recurring Invoice Factory */
factory(\App\Models\RecurringInvoice::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
// factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id, 'settings' => ClientSettings::buildClientSettings($company->settings, $client->settings)]);
factory(\App\Models\Payment::class,20)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
$clients = Client::all();

View File

@ -139,6 +139,23 @@
John Doe<br>
john@example.com
</td>
<td>
{{$client_name}}<br>
{{$address1}}<br>
{{$address2}}<br>
{{$id_number}}<br>
{{$vat_number}}<br>
{{$city_state_postal}}<br>
{{$postal_city_state}}<br>
{{$country}}<br>
{{$email}}<br>
{{$contact_name}}<br>
{{$company_name}}<br>
{{$website}}<br>
{{$phone}}<br>
{{$terms}}<br>
</td>
</tr>
</table>
</td>
@ -168,71 +185,7 @@
$300.00
</td>
</tr>
<tr class="item">
<td>
Website design
</td>
<td>
$300.00
</td>
</tr> <tr class="item">
<td>
Website design
</td>
<td>
$300.00
</td>
</tr> <tr class="item">
<td>
Website design
</td>
<td>
$300.00
</td>
</tr> <tr class="item">
<td>
Website design
</td>
<td>
$300.00
</td>
</tr> <tr class="item">
<td>
Website design
</td>
<td>
$300.00
</td>
</tr> <tr class="item">
<td>
Website design
</td>
<td>
$300.00
</td>
</tr> <tr class="item">
<td>
Website design
</td>
<td>
$300.00
</td>
</tr> <tr class="item">
<td>
Website design
</td>
<td>
$300.00
</td>
</tr> <tr class="item">
<tr class="item">
<td>
Website design
</td>