1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Refactor for invoices/quotes/credit transformers (#3100)

* Refactor Invoices / Quotes / Credits to use the same transformer

* Add contact_key to factories
This commit is contained in:
David Bomba 2019-11-27 21:27:24 +11:00 committed by GitHub
parent 4bc92a7aa1
commit 9702dc741c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 116 additions and 91 deletions

View File

@ -21,6 +21,7 @@ class ClientContactFactory
$client_contact->first_name = ""; $client_contact->first_name = "";
$client_contact->user_id = $user_id; $client_contact->user_id = $user_id;
$client_contact->company_id = $company_id; $client_contact->company_id = $company_id;
$client_contact->contact_key = \Illuminate\Support\Str::random(40);
$client_contact->id = 0; $client_contact->id = 0;
return $client_contact; return $client_contact;

View File

@ -19,8 +19,8 @@ class CloneInvoiceFactory
{ {
$clone_invoice = $invoice->replicate(); $clone_invoice = $invoice->replicate();
$clone_invoice->status_id = Invoice::STATUS_DRAFT; $clone_invoice->status_id = Invoice::STATUS_DRAFT;
$clone_invoice->invoice_number = NULL; $clone_invoice->number = NULL;
$clone_invoice->invoice_date = null; $clone_invoice->date = null;
$clone_invoice->due_date = null; $clone_invoice->due_date = null;
$clone_invoice->partial_due_date = null; $clone_invoice->partial_due_date = null;
$clone_invoice->user_id = $user_id; $clone_invoice->user_id = $user_id;

View File

@ -22,7 +22,7 @@ class InvoiceFactory
{ {
$invoice = new Invoice(); $invoice = new Invoice();
$invoice->status_id = Invoice::STATUS_DRAFT; $invoice->status_id = Invoice::STATUS_DRAFT;
$invoice->invoice_number = null; $invoice->number = null;
$invoice->discount = 0; $invoice->discount = 0;
$invoice->is_amount_discount = true; $invoice->is_amount_discount = true;
$invoice->po_number = ''; $invoice->po_number = '';
@ -30,7 +30,7 @@ class InvoiceFactory
$invoice->terms = ''; $invoice->terms = '';
$invoice->public_notes = ''; $invoice->public_notes = '';
$invoice->private_notes = ''; $invoice->private_notes = '';
$invoice->invoice_date = null; $invoice->date = null;
$invoice->due_date = null; $invoice->due_date = null;
$invoice->partial_due_date = null; $invoice->partial_due_date = null;
$invoice->is_deleted = false; $invoice->is_deleted = false;
@ -49,7 +49,7 @@ class InvoiceFactory
$invoice->partial = 0; $invoice->partial = 0;
$invoice->user_id = $user_id; $invoice->user_id = $user_id;
$invoice->company_id = $company_id; $invoice->company_id = $company_id;
$invoice->recurring_invoice_id = null; $invoice->recurring_id = null;
return $invoice; return $invoice;
} }

View File

@ -25,14 +25,14 @@ class InvoiceToRecurringInvoiceFactory
$recurring_invoice->status_id = RecurringInvoice::STATUS_DRAFT; $recurring_invoice->status_id = RecurringInvoice::STATUS_DRAFT;
$recurring_invoice->discount = $invoice->discount; $recurring_invoice->discount = $invoice->discount;
$recurring_invoice->invoice_number = ''; $recurring_invoice->number = '';
$recurring_invoice->is_amount_discount = $invoice->is_amount_discount; $recurring_invoice->is_amount_discount = $invoice->is_amount_discount;
$recurring_invoice->po_number = $invoice->po_number; $recurring_invoice->po_number = $invoice->po_number;
$recurring_invoice->footer = $invoice->footer; $recurring_invoice->footer = $invoice->footer;
$recurring_invoice->terms = $invoice->terms; $recurring_invoice->terms = $invoice->terms;
$recurring_invoice->public_notes = $invoice->public_notes; $recurring_invoice->public_notes = $invoice->public_notes;
$recurring_invoice->private_notes = $invoice->private_notes; $recurring_invoice->private_notes = $invoice->private_notes;
$recurring_invoice->invoice_date = date_create()->format($invoice->client->date_format()); $recurring_invoice->date = date_create()->format($invoice->client->date_format());
$recurring_invoice->due_date = $invoice->due_date; //todo calculate based on terms $recurring_invoice->due_date = $invoice->due_date; //todo calculate based on terms
$recurring_invoice->is_deleted = $invoice->is_deleted; $recurring_invoice->is_deleted = $invoice->is_deleted;
$recurring_invoice->line_items = $invoice->line_items; $recurring_invoice->line_items = $invoice->line_items;

View File

@ -24,12 +24,12 @@ class RecurringInvoiceFactory
$invoice->discount = 0; $invoice->discount = 0;
$invoice->is_amount_discount = true; $invoice->is_amount_discount = true;
$invoice->po_number = ''; $invoice->po_number = '';
$invoice->invoice_number = ''; $invoice->number = '';
$invoice->footer = ''; $invoice->footer = '';
$invoice->terms = ''; $invoice->terms = '';
$invoice->public_notes = ''; $invoice->public_notes = '';
$invoice->private_notes = ''; $invoice->private_notes = '';
$invoice->invoice_date = null; $invoice->date = null;
$invoice->due_date = null; $invoice->due_date = null;
$invoice->partial_due_date = null; $invoice->partial_due_date = null;
$invoice->is_deleted = false; $invoice->is_deleted = false;

View File

@ -30,7 +30,7 @@ class recurring_invoiceToInvoiceFactory
$invoice->terms = $recurring_invoice->terms; $invoice->terms = $recurring_invoice->terms;
$invoice->public_notes = $recurring_invoice->public_notes; $invoice->public_notes = $recurring_invoice->public_notes;
$invoice->private_notes = $recurring_invoice->private_notes; $invoice->private_notes = $recurring_invoice->private_notes;
$invoice->invoice_date = date_create()->format($client->date_format()); $invoice->date = date_create()->format($client->date_format());
$invoice->due_date = $recurring_invoice->due_date; //todo calculate based on terms $invoice->due_date = $recurring_invoice->due_date; //todo calculate based on terms
$invoice->is_deleted = $recurring_invoice->is_deleted; $invoice->is_deleted = $recurring_invoice->is_deleted;
$invoice->line_items = $recurring_invoice->line_items; $invoice->line_items = $recurring_invoice->line_items;
@ -47,7 +47,7 @@ class recurring_invoiceToInvoiceFactory
$invoice->balance = $recurring_invoice->balance; $invoice->balance = $recurring_invoice->balance;
$invoice->user_id = $recurring_invoice->user_id; $invoice->user_id = $recurring_invoice->user_id;
$invoice->company_id = $recurring_invoice->company_id; $invoice->company_id = $recurring_invoice->company_id;
$invoice->recurring_invoice_id = $recurring_invoice->id; $invoice->recurring_id = $recurring_invoice->id;
return $invoice; return $invoice;
} }

View File

@ -28,8 +28,8 @@ class RecurringQuoteFactory
$quote->terms = ''; $quote->terms = '';
$quote->public_notes = ''; $quote->public_notes = '';
$quote->private_notes = ''; $quote->private_notes = '';
$quote->quote_date = null; $quote->date = null;
$quote->valid_until = null; $quote->due_date = null;
$quote->partial_due_date = null; $quote->partial_due_date = null;
$quote->is_deleted = false; $quote->is_deleted = false;
$quote->line_items = json_encode([]); $quote->line_items = json_encode([]);

View File

@ -79,9 +79,9 @@ class InvoiceFilters extends QueryFilters
return $this->builder; return $this->builder;
return $this->builder->where(function ($query) use ($filter) { return $this->builder->where(function ($query) use ($filter) {
$query->where('invoices.invoice_number', 'like', '%'.$filter.'%') $query->where('invoices.number', 'like', '%'.$filter.'%')
->orWhere('invoices.po_number', 'like', '%'.$filter.'%') ->orWhere('invoices.po_number', 'like', '%'.$filter.'%')
->orWhere('invoices.invoice_date', 'like', '%'.$filter.'%') ->orWhere('invoices.date', 'like', '%'.$filter.'%')
->orWhere('invoices.amount', 'like', '%'.$filter.'%') ->orWhere('invoices.amount', 'like', '%'.$filter.'%')
->orWhere('invoices.balance', 'like', '%'.$filter.'%') ->orWhere('invoices.balance', 'like', '%'.$filter.'%')
->orWhere('invoices.custom_value1', 'like', '%'.$filter.'%') ->orWhere('invoices.custom_value1', 'like', '%'.$filter.'%')

View File

@ -60,8 +60,8 @@ class InvoiceController extends Controller
}) })
->editColumn('status_id', function ($invoice){ ->editColumn('status_id', function ($invoice){
return Invoice::badgeForStatus($invoice->status); return Invoice::badgeForStatus($invoice->status);
})->editColumn('invoice_date', function ($invoice){ })->editColumn('date', function ($invoice){
return $this->formatDate($invoice->invoice_date, $invoice->client->date_format()); return $this->formatDate($invoice->date, $invoice->client->date_format());
})->editColumn('due_date', function ($invoice){ })->editColumn('due_date', function ($invoice){
return $this->formatDate($invoice->due_date, $invoice->client->date_format()); return $this->formatDate($invoice->due_date, $invoice->client->date_format());
})->editColumn('balance', function ($invoice) { })->editColumn('balance', function ($invoice) {

View File

@ -62,7 +62,7 @@ class RecurringInvoiceController extends Controller
return RecurringInvoice::badgeForStatus($invoice->status); return RecurringInvoice::badgeForStatus($invoice->status);
}) })
->editColumn('start_date', function ($invoice){ ->editColumn('start_date', function ($invoice){
return $this->formatDate($invoice->invoice_date, $invoice->client->date_format()); return $this->formatDate($invoice->date, $invoice->client->date_format());
}) })
->editColumn('next_send_date', function ($invoice){ ->editColumn('next_send_date', function ($invoice){
return $this->formatDate($invoice->next_send_date, $invoice->client->date_format()); return $this->formatDate($invoice->next_send_date, $invoice->client->date_format());

View File

@ -9,7 +9,7 @@
* @OA\Property(property="client_id", type="string", example="", description="________"), * @OA\Property(property="client_id", type="string", example="", description="________"),
* @OA\Property(property="status_id", type="string", example="", description="________"), * @OA\Property(property="status_id", type="string", example="", description="________"),
* @OA\Property(property="invoice_type_id", type="string", example="", description="________"), * @OA\Property(property="invoice_type_id", type="string", example="", description="________"),
* @OA\Property(property="invoice_number", type="string", example="", description="________"), * @OA\Property(property="number", type="string", example="INV_101", description="The invoice number - is a unique alpha numeric number per invoice per company"),
* @OA\Property(property="po_number", type="string", example="", description="________"), * @OA\Property(property="po_number", type="string", example="", description="________"),
* @OA\Property(property="terms", type="string", example="", description="________"), * @OA\Property(property="terms", type="string", example="", description="________"),
* @OA\Property(property="public_notes", type="string", example="", description="________"), * @OA\Property(property="public_notes", type="string", example="", description="________"),
@ -33,7 +33,7 @@
* @OA\Property(property="is_amount_discount", type="boolean", example=true, description="_________"), * @OA\Property(property="is_amount_discount", type="boolean", example=true, description="_________"),
* @OA\Property(property="is_deleted", type="boolean", example=true, description="_________"), * @OA\Property(property="is_deleted", type="boolean", example=true, description="_________"),
* @OA\Property(property="uses_inclusive_taxes", type="boolean", example=true, description="Defines the type of taxes used as either inclusive or exclusive"), * @OA\Property(property="uses_inclusive_taxes", type="boolean", example=true, description="Defines the type of taxes used as either inclusive or exclusive"),
* @OA\Property(property="invoice_date", type="string", format="date", example="1994-07-30", description="_________"), * @OA\Property(property="date", type="string", format="date", example="1994-07-30", description="The Invoice Date"),
* @OA\Property(property="partial_due_date", type="string", format="date", example="1994-07-30", description="_________"), * @OA\Property(property="partial_due_date", type="string", format="date", example="1994-07-30", description="_________"),
* @OA\Property(property="due_date", type="string", format="date", example="1994-07-30", description="_________"), * @OA\Property(property="due_date", type="string", format="date", example="1994-07-30", description="_________"),
* @OA\Property(property="settings",ref="#/components/schemas/CompanySettings"), * @OA\Property(property="settings",ref="#/components/schemas/CompanySettings"),

View File

@ -54,16 +54,16 @@ class ApplyInvoiceNumber implements ShouldQueue
public function handle() public function handle()
{ {
//return early //return early
if($this->invoice->invoice_number != '') if($this->invoice->number != '')
return $this->invoice; return $this->invoice;
switch ($this->settings->counter_number_applied) { switch ($this->settings->counter_number_applied) {
case 'when_saved': case 'when_saved':
$this->invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client); $this->invoice->number = $this->getNextInvoiceNumber($this->invoice->client);
break; break;
case 'when_sent': case 'when_sent':
if($this->invoice->status_id == Invoice::STATUS_SENT) if($this->invoice->status_id == Invoice::STATUS_SENT)
$this->invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client); $this->invoice->number = $this->getNextInvoiceNumber($this->invoice->client);
break; break;
default: default:

View File

@ -53,7 +53,7 @@ class CreateInvoicePdf implements ShouldQueue
$this->invoice->load('client'); $this->invoice->load('client');
$path = 'public/' . $this->invoice->client->client_hash . '/invoices/'; $path = 'public/' . $this->invoice->client->client_hash . '/invoices/';
$file_path = $path . $this->invoice->invoice_number . '.pdf'; $file_path = $path . $this->invoice->number . '.pdf';
//get invoice design //get invoice design
$html = $this->generateInvoiceHtml($this->invoice->design(), $this->invoice); $html = $this->generateInvoiceHtml($this->invoice->design(), $this->invoice);

View File

@ -53,7 +53,7 @@ class SendRecurring
// Generate Standard Invoice // Generate Standard Invoice
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice); $invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice);
$invoice->invoice_number = $this->getNextRecurringInvoiceNumber($this->recurring_invoice->client); $invoice->number = $this->getNextRecurringInvoiceNumber($this->recurring_invoice->client);
$invoice->status_id = Invoice::STATUS_SENT; $invoice->status_id = Invoice::STATUS_SENT;
$invoice->save(); $invoice->save();

View File

@ -41,7 +41,7 @@ class BouncedEmail extends Mailable implements ShouldQueue
{ {
$entity_type = class_basename(lcfirst($this->invitation->getEntityType())); $entity_type = class_basename(lcfirst($this->invitation->getEntityType()));
$subject = ctrans("texts.notification_{$entity_type}_bounced_subject", ['invoice' => $invoice->invoice_number]); $subject = ctrans("texts.notification_{$entity_type}_bounced_subject", ['invoice' => $invoice->number]);
return return
$this->from($invitation->user->email) $this->from($invitation->user->email)

View File

@ -54,10 +54,10 @@ class Invoice extends BaseModel
]; ];
protected $fillable = [ protected $fillable = [
'invoice_number', 'number',
'discount', 'discount',
'po_number', 'po_number',
'invoice_date', 'date',
'due_date', 'due_date',
'terms', 'terms',
'public_notes', 'public_notes',
@ -288,9 +288,9 @@ class Invoice extends BaseModel
/** TODO// DOCUMENT THIS FUNCTIONALITY */ /** TODO// DOCUMENT THIS FUNCTIONALITY */
public function pdf_url() public function pdf_url()
{ {
$public_path = 'storage/' . $this->client->client_hash . '/invoices/'. $this->invoice_number . '.pdf'; $public_path = 'storage/' . $this->client->client_hash . '/invoices/'. $this->number . '.pdf';
$storage_path = 'public/' . $this->client->client_hash . '/invoices/'. $this->invoice_number . '.pdf'; $storage_path = 'public/' . $this->client->client_hash . '/invoices/'. $this->number . '.pdf';
if(!Storage::exists($storage_path)) { if(!Storage::exists($storage_path)) {
event(new InvoiceWasUpdated($this)); event(new InvoiceWasUpdated($this));
@ -301,7 +301,7 @@ class Invoice extends BaseModel
public function pdf_file_path() public function pdf_file_path()
{ {
$storage_path = 'storage/' . $this->client->client_hash . '/invoices/'. $this->invoice_number . '.pdf'; $storage_path = 'storage/' . $this->client->client_hash . '/invoices/'. $this->number . '.pdf';
if(!Storage::exists($storage_path)) { if(!Storage::exists($storage_path)) {
CreateInvoicePdf::dispatchNow($this); CreateInvoicePdf::dispatchNow($this);

View File

@ -40,6 +40,19 @@ class RecurringInvoice extends BaseModel
/** /**
* Recurring intervals //todo MAP WHEN WE MIGRATE * Recurring intervals //todo MAP WHEN WE MIGRATE
*/ */
/* Make sure we support overflow!!!!!!!!!!
$start = Carbon::today();
$subscription = Carbon::parse('2017-12-31');
foreach (range(1, 12) as $month) {
$day = $start->addMonthNoOverflow()->thisDayOrLast($subscription->day);
echo "You will be billed on {$day} in month {$month}\n";
}
*/
const FREQUENCY_DAILY = 1; const FREQUENCY_DAILY = 1;
const FREQUENCY_WEEKLY = 2; const FREQUENCY_WEEKLY = 2;
const FREQUENCY_TWO_WEEKS = 3; const FREQUENCY_TWO_WEEKS = 3;
@ -57,11 +70,11 @@ class RecurringInvoice extends BaseModel
protected $fillable = [ protected $fillable = [
'client_id', 'client_id',
'invoice_number', 'number',
'discount', 'discount',
'is_amount_discount', 'is_amount_discount',
'po_number', 'po_number',
'invoice_date', 'date',
'due_date', 'due_date',
'line_items', 'line_items',
'settings', 'settings',
@ -120,7 +133,7 @@ class RecurringInvoice extends BaseModel
public function invoices() public function invoices()
{ {
return $this->hasMany(Invoice::class, "id", "recurring_invoice_id")->withTrashed(); return $this->hasMany(Invoice::class, "id", "recurring_id")->withTrashed();
} }
public function invitations() public function invitations()

View File

@ -64,7 +64,7 @@ class ClientContactRequestCancellation extends Notification implements ShouldQue
$client_contact_name = $this->client_contact->present()->name(); $client_contact_name = $this->client_contact->present()->name();
$client_name = $this->client_contact->client->present()->name(); $client_name = $this->client_contact->client->present()->name();
$recurring_invoice_number = $this->recurring_invoice->invoice_number; $recurring_invoice_number = $this->recurring_invoice->number;
return (new MailMessage) return (new MailMessage)
@ -93,7 +93,7 @@ class ClientContactRequestCancellation extends Notification implements ShouldQue
$name = $this->client_contact->present()->name(); $name = $this->client_contact->present()->name();
$client_name = $this->client_contact->client->present()->name(); $client_name = $this->client_contact->client->present()->name();
$recurring_invoice_number = $this->recurring_invoice->invoice_number; $recurring_invoice_number = $this->recurring_invoice->number;
return (new SlackMessage) return (new SlackMessage)
->success() ->success()

View File

@ -35,8 +35,8 @@ use Omnipay\Omnipay;
'currency' => $invoice->getCurrencyCode(), 'currency' => $invoice->getCurrencyCode(),
'returnUrl' => $completeUrl, 'returnUrl' => $completeUrl,
'cancelUrl' => $this->invitation->getLink(), 'cancelUrl' => $this->invitation->getLink(),
'description' => trans('texts.' . $invoice->getEntityType()) . " {$invoice->invoice_number}", 'description' => trans('texts.' . $invoice->getEntityType()) . " {$invoice->number}",
'transactionId' => $invoice->invoice_number, 'transactionId' => $invoice->number,
'transactionType' => 'Purchase', 'transactionType' => 'Purchase',
'clientIp' => Request::getClientIp(), 'clientIp' => Request::getClientIp(),
]; ];

View File

@ -213,7 +213,7 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
foreach($input['invoices'] as $invoice) foreach($input['invoices'] as $invoice)
{ {
$invoice_numbers .= $invoice->invoice_number." "; $invoice_numbers .= $invoice->number." ";
} }
return ctrans('texts.invoice_number'). ": {$invoice_numbers}"; return ctrans('texts.invoice_number'). ": {$invoice_numbers}";

View File

@ -35,10 +35,10 @@ class InvoiceTransformer extends EntityTransformer
'status_id' => (int) ($invoice->status_id ?: 1), 'status_id' => (int) ($invoice->status_id ?: 1),
'updated_at' => $invoice->updated_at, 'updated_at' => $invoice->updated_at,
'archived_at' => $invoice->deleted_at, 'archived_at' => $invoice->deleted_at,
'invoice_number' => $invoice->invoice_number, 'number' => $invoice->number,
'discount' => (float) $invoice->discount, 'discount' => (float) $invoice->discount,
'po_number' => $invoice->po_number, 'po_number' => $invoice->po_number,
'invoice_date' => $invoice->invoice_date ?: '', 'date' => $invoice->date ?: '',
'due_date' => $invoice->due_date ?: '', 'due_date' => $invoice->due_date ?: '',
'terms' => $invoice->terms ?: '', 'terms' => $invoice->terms ?: '',
'public_notes' => $invoice->public_notes ?: '', 'public_notes' => $invoice->public_notes ?: '',

View File

@ -92,10 +92,10 @@ class InvoiceTransformer extends EntityTransformer
'design_id' => (string) ($invoice->design_id ?: 1), 'design_id' => (string) ($invoice->design_id ?: 1),
'updated_at' => $invoice->updated_at, 'updated_at' => $invoice->updated_at,
'archived_at' => $invoice->deleted_at, 'archived_at' => $invoice->deleted_at,
'invoice_number' => $invoice->invoice_number ?: '', 'number' => $invoice->number ?: '',
'discount' => (float) $invoice->discount, 'discount' => (float) $invoice->discount,
'po_number' => $invoice->po_number ?: '', 'po_number' => $invoice->po_number ?: '',
'invoice_date' => $invoice->invoice_date ?: '', 'date' => $invoice->date ?: '',
'due_date' => $invoice->due_date ?: '', 'due_date' => $invoice->due_date ?: '',
'terms' => $invoice->terms ?: '', 'terms' => $invoice->terms ?: '',
'public_notes' => $invoice->public_notes ?: '', 'public_notes' => $invoice->public_notes ?: '',

View File

@ -91,7 +91,7 @@ class RecurringInvoiceTransformer extends EntityTransformer
'archived_at' => $invoice->deleted_at, 'archived_at' => $invoice->deleted_at,
'discount' => (float) $invoice->discount ?: '', 'discount' => (float) $invoice->discount ?: '',
'po_number' => $invoice->po_number ?: '', 'po_number' => $invoice->po_number ?: '',
'invoice_date' => $invoice->invoice_date ?: '', 'date' => $invoice->date ?: '',
'due_date' => $invoice->due_date ?: '', 'due_date' => $invoice->due_date ?: '',
'terms' => $invoice->terms ?: '', 'terms' => $invoice->terms ?: '',
'public_notes' => $invoice->public_notes ?: '', 'public_notes' => $invoice->public_notes ?: '',

View File

@ -196,13 +196,13 @@ trait GeneratesCounter
$number = $this->applyNumberPattern($client, $number, $pattern); $number = $this->applyNumberPattern($client, $number, $pattern);
if($class == Invoice::class || $class == RecurringInvoice::class) if($class == Invoice::class || $class == RecurringInvoice::class)
$check = $class::whereCompanyId($client->company_id)->whereInvoiceNumber($number)->withTrashed()->first(); $check = $class::whereCompanyId($client->company_id)->whereNumber($number)->withTrashed()->first();
elseif($class == Client::class) elseif($class == Client::class)
$check = $class::whereCompanyId($client->company_id)->whereIdNumber($number)->withTrashed()->first(); $check = $class::whereCompanyId($client->company_id)->whereIdNumber($number)->withTrashed()->first();
elseif($class == Credit::class) elseif($class == Credit::class)
$check = $class::whereCompanyId($client->company_id)->whereCreditNumber($number)->withTrashed()->first(); $check = $class::whereCompanyId($client->company_id)->whereNumber($number)->withTrashed()->first();
elseif($class == Quote::class) elseif($class == Quote::class)
$check = $class::whereCompanyId($client->company_id)->whereQuoteNumber($number)->withTrashed()->first(); $check = $class::whereCompanyId($client->company_id)->whereNumber($number)->withTrashed()->first();
$counter++; $counter++;

View File

@ -46,9 +46,9 @@ trait MakesInvoiceValues
* @var array * @var array
*/ */
private static $labels = [ private static $labels = [
'invoice_date', 'date',
'due_date', 'due_date',
'invoice_number', 'number',
'po_number', 'po_number',
'discount', 'discount',
'taxes', 'taxes',
@ -161,9 +161,9 @@ trait MakesInvoiceValues
$data = []; $data = [];
$data['$invoice_date'] = $this->invoice_date; $data['$date'] = $this->date;
$data['$due_date'] = $this->due_date; $data['$due_date'] = $this->due_date;
$data['$invoice_number'] = $this->invoice_number; $data['$invoice_number'] = $this->number;
$data['$po_number'] = $this->po_number; $data['$po_number'] = $this->po_number;
$data['$line_taxes'] = $this->makeLineTaxes(); $data['$line_taxes'] = $this->makeLineTaxes();
$data['$total_taxes'] = $this->makeTotalTaxes(); $data['$total_taxes'] = $this->makeTotalTaxes();
@ -196,7 +196,7 @@ trait MakesInvoiceValues
// $data['$invoice_to'] = ; // $data['$invoice_to'] = ;
// $data['$quote_to'] = ; // $data['$quote_to'] = ;
// $data['$details'] = ; // $data['$details'] = ;
$data['$invoice_no'] = $this->invoice_number; $data['$invoice_no'] = $this->number;
// $data['$quote_no'] = ; // $data['$quote_no'] = ;
// $data['$valid_until'] = ; // $data['$valid_until'] = ;
$data['$client_name'] = $this->present()->clientName(); $data['$client_name'] = $this->present()->clientName();

View File

@ -22,7 +22,7 @@ $factory->define(App\Models\ClientContact::class, function (Faker $faker) {
'email' => $faker->unique()->safeEmail, 'email' => $faker->unique()->safeEmail,
'password' => bcrypt('password'), 'password' => bcrypt('password'),
'remember_token' => \Illuminate\Support\Str::random(10), 'remember_token' => \Illuminate\Support\Str::random(10),
'token' => \Illuminate\Support\Str::random(64), 'contact_key' => \Illuminate\Support\Str::random(40),
]; ];
}); });

View File

@ -8,7 +8,7 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Invoice::class, function (Faker $faker) { $factory->define(App\Models\Invoice::class, function (Faker $faker) {
return [ return [
'status_id' => App\Models\Invoice::STATUS_SENT, 'status_id' => App\Models\Invoice::STATUS_SENT,
'invoice_number' => $faker->ean13(), 'number' => $faker->ean13(),
'discount' => $faker->numberBetween(1,10), 'discount' => $faker->numberBetween(1,10),
'is_amount_discount' => (bool)random_int(0,1), 'is_amount_discount' => (bool)random_int(0,1),
'tax_name1' => 'GST', 'tax_name1' => 'GST',
@ -23,7 +23,7 @@ $factory->define(App\Models\Invoice::class, function (Faker $faker) {
// 'custom_value4' => $faker->numberBetween(1,4), // 'custom_value4' => $faker->numberBetween(1,4),
'is_deleted' => false, 'is_deleted' => false,
'po_number' => $faker->text(10), 'po_number' => $faker->text(10),
'invoice_date' => $faker->date(), 'date' => $faker->date(),
'due_date' => $faker->date(), 'due_date' => $faker->date(),
'line_items' => InvoiceItemFactory::generate(5), 'line_items' => InvoiceItemFactory::generate(5),
'backup' => '', 'backup' => '',

View File

@ -7,7 +7,7 @@ use Faker\Generator as Faker;
$factory->define(App\Models\Quote::class, function (Faker $faker) { $factory->define(App\Models\Quote::class, function (Faker $faker) {
return [ return [
'status_id' => App\Models\Quote::STATUS_DRAFT, 'status_id' => App\Models\Quote::STATUS_DRAFT,
'quote_number' => $faker->text(256), 'number' => $faker->text(256),
'discount' => $faker->numberBetween(1,10), 'discount' => $faker->numberBetween(1,10),
'is_amount_discount' => $faker->boolean(), 'is_amount_discount' => $faker->boolean(),
'tax_name1' => 'GST', 'tax_name1' => 'GST',
@ -22,8 +22,8 @@ $factory->define(App\Models\Quote::class, function (Faker $faker) {
'custom_value4' => $faker->numberBetween(1,4), 'custom_value4' => $faker->numberBetween(1,4),
'is_deleted' => false, 'is_deleted' => false,
'po_number' => $faker->text(10), 'po_number' => $faker->text(10),
'quote_date' => $faker->date(), 'date' => $faker->date(),
'valid_until' => $faker->date(), 'due_date' => $faker->date(),
'line_items' => false, 'line_items' => false,
'backup' => '', 'backup' => '',
]; ];

View File

@ -21,7 +21,7 @@ $factory->define(App\Models\RecurringInvoice::class, function (Faker $faker) {
'custom_value4' => $faker->numberBetween(1,4), 'custom_value4' => $faker->numberBetween(1,4),
'is_deleted' => false, 'is_deleted' => false,
'po_number' => $faker->text(10), 'po_number' => $faker->text(10),
'invoice_date' => $faker->date(), 'date' => $faker->date(),
'due_date' => $faker->date(), 'due_date' => $faker->date(),
'line_items' => false, 'line_items' => false,
'backup' => '', 'backup' => '',

View File

@ -7,7 +7,7 @@ use Faker\Generator as Faker;
$factory->define(App\Models\RecurringQuote::class, function (Faker $faker) { $factory->define(App\Models\RecurringQuote::class, function (Faker $faker) {
return [ return [
'status_id' => App\Models\RecurringQuote::STATUS_DRAFT, 'status_id' => App\Models\RecurringQuote::STATUS_DRAFT,
'quote_number' => $faker->text(256), 'number' => $faker->text(256),
'discount' => $faker->numberBetween(1,10), 'discount' => $faker->numberBetween(1,10),
'is_amount_discount' => $faker->boolean(), 'is_amount_discount' => $faker->boolean(),
'tax_name1' => 'GST', 'tax_name1' => 'GST',
@ -22,8 +22,8 @@ $factory->define(App\Models\RecurringQuote::class, function (Faker $faker) {
'custom_value4' => $faker->numberBetween(1,4), 'custom_value4' => $faker->numberBetween(1,4),
'is_deleted' => false, 'is_deleted' => false,
'po_number' => $faker->text(10), 'po_number' => $faker->text(10),
'quote_date' => $faker->date(), 'date' => $faker->date(),
'valid_until' => $faker->date(), 'due_date' => $faker->date(),
'line_items' => false, 'line_items' => false,
'backup' => '', 'backup' => '',
'frequency_id' => App\Models\RecurringQuote::FREQUENCY_MONTHLY, 'frequency_id' => App\Models\RecurringQuote::FREQUENCY_MONTHLY,

View File

@ -407,21 +407,20 @@ class CreateUsersTable extends Migration
$t->unsignedInteger('company_id')->index(); $t->unsignedInteger('company_id')->index();
$t->unsignedInteger('status_id'); $t->unsignedInteger('status_id');
$t->unsignedInteger('recurring_invoice_id')->nullable(); $t->unsignedInteger('recurring_id')->nullable();
$t->unsignedInteger('design_id')->nullable(); $t->unsignedInteger('design_id')->nullable();
$t->string('invoice_number')->nullable(); $t->string('number')->nullable();
$t->float('discount')->default(0); $t->float('discount')->default(0);
$t->boolean('is_amount_discount')->default(0); $t->boolean('is_amount_discount')->default(0);
$t->string('po_number')->nullable(); $t->string('po_number')->nullable();
$t->date('invoice_date')->nullable(); $t->date('date')->nullable();
$t->datetime('due_date')->nullable(); $t->datetime('due_date')->nullable();
$t->boolean('is_deleted')->default(false); $t->boolean('is_deleted')->default(false);
$t->mediumText('line_items')->nullable(); $t->mediumText('line_items')->nullable();
//$t->text('settings')->nullable();
$t->mediumText('backup')->nullable(); $t->mediumText('backup')->nullable();
$t->text('footer')->nullable(); $t->text('footer')->nullable();
@ -468,7 +467,7 @@ class CreateUsersTable extends Migration
$t->timestamps(6); $t->timestamps(6);
$t->softDeletes('deleted_at', 6); $t->softDeletes('deleted_at', 6);
$t->unique(['company_id', 'invoice_number']); $t->unique(['company_id', 'number']);
}); });
Schema::create('recurring_invoices', function ($t) { Schema::create('recurring_invoices', function ($t) {
@ -479,13 +478,13 @@ class CreateUsersTable extends Migration
$t->unsignedInteger('company_id')->index(); $t->unsignedInteger('company_id')->index();
$t->unsignedInteger('status_id')->index(); $t->unsignedInteger('status_id')->index();
$t->text('invoice_number')->nullable(); $t->text('number')->nullable();
$t->float('discount')->default(0); $t->float('discount')->default(0);
$t->boolean('is_amount_discount')->default(false); $t->boolean('is_amount_discount')->default(false);
$t->string('po_number')->nullable(); $t->string('po_number')->nullable();
$t->date('invoice_date')->nullable(); $t->date('date')->nullable();
$t->datetime('due_date')->nullable(); $t->datetime('due_date')->nullable();
$t->boolean('is_deleted')->default(false); $t->boolean('is_deleted')->default(false);
@ -545,11 +544,11 @@ class CreateUsersTable extends Migration
$t->float('discount')->default(0); $t->float('discount')->default(0);
$t->boolean('is_amount_discount')->default(false); $t->boolean('is_amount_discount')->default(false);
$t->string('quote_number')->nullable(); $t->string('number')->nullable();
$t->string('po_number')->nullable(); $t->string('po_number')->nullable();
$t->date('quote_date')->nullable(); $t->date('date')->nullable();
$t->datetime('valid_until')->nullable(); $t->datetime('due_date')->nullable();
$t->boolean('is_deleted')->default(false); $t->boolean('is_deleted')->default(false);
@ -602,15 +601,17 @@ class CreateUsersTable extends Migration
$t->unsignedInteger('assigned_user_id')->nullable(); $t->unsignedInteger('assigned_user_id')->nullable();
$t->unsignedInteger('company_id')->index(); $t->unsignedInteger('company_id')->index();
$t->unsignedInteger('status_id'); $t->unsignedInteger('status_id');
$t->unsignedInteger('design_id');
$t->string('quote_number')->nullable(); $t->unsignedInteger('recurring_id')->nullable();
$t->unsignedInteger('design_id')->nullable();
$t->string('number')->nullable();
$t->float('discount')->default(0); $t->float('discount')->default(0);
$t->boolean('is_amount_discount')->default(false); $t->boolean('is_amount_discount')->default(0);
$t->string('po_number')->nullable(); $t->string('po_number')->nullable();
$t->date('quote_date')->nullable(); $t->date('date')->nullable();
$t->datetime('valid_until')->nullable(); $t->datetime('due_date')->nullable();
$t->boolean('is_deleted')->default(false); $t->boolean('is_deleted')->default(false);
@ -622,7 +623,6 @@ class CreateUsersTable extends Migration
$t->text('private_notes')->nullable(); $t->text('private_notes')->nullable();
$t->text('terms')->nullable(); $t->text('terms')->nullable();
$t->string('tax_name1')->nullable(); $t->string('tax_name1')->nullable();
$t->decimal('tax_rate1', 13, 3)->default(0); $t->decimal('tax_rate1', 13, 3)->default(0);
@ -632,13 +632,24 @@ class CreateUsersTable extends Migration
$t->string('tax_name3')->nullable(); $t->string('tax_name3')->nullable();
$t->decimal('tax_rate3', 13, 3)->default(0); $t->decimal('tax_rate3', 13, 3)->default(0);
$t->boolean('uses_inclusive_taxes')->default(0);
$t->string('custom_value1')->nullable(); $t->string('custom_value1')->nullable();
$t->string('custom_value2')->nullable(); $t->string('custom_value2')->nullable();
$t->string('custom_value3')->nullable(); $t->string('custom_value3')->nullable();
$t->string('custom_value4')->nullable(); $t->string('custom_value4')->nullable();
$t->decimal('amount', 16, 4)->default(0); $t->string('custom_surcharge1')->nullable();
$t->decimal('balance', 16, 4)->default(0); $t->string('custom_surcharge2')->nullable();
$t->string('custom_surcharge3')->nullable();
$t->string('custom_surcharge4')->nullable();
$t->boolean('custom_surcharge_tax1')->default(false);
$t->boolean('custom_surcharge_tax2')->default(false);
$t->boolean('custom_surcharge_tax3')->default(false);
$t->boolean('custom_surcharge_tax4')->default(false);
$t->decimal('amount', 16, 4);
$t->decimal('balance', 16, 4);
$t->decimal('partial', 16, 4)->nullable(); $t->decimal('partial', 16, 4)->nullable();
$t->datetime('partial_due_date')->nullable(); $t->datetime('partial_due_date')->nullable();
@ -651,7 +662,7 @@ class CreateUsersTable extends Migration
$t->timestamps(6); $t->timestamps(6);
$t->softDeletes('deleted_at', 6); $t->softDeletes('deleted_at', 6);
$t->unique(['company_id', 'quote_number']); $t->unique(['company_id', 'number']);
}); });
Schema::create('invoice_invitations', function ($t) { Schema::create('invoice_invitations', function ($t) {

View File

@ -16,7 +16,7 @@
@foreach($invoices as $invoice) @foreach($invoices as $invoice)
<a class="list-group-item list-group-item-action flex-column align-items-start" href="javascript:void(0);"> <a class="list-group-item list-group-item-action flex-column align-items-start" href="javascript:void(0);">
<div class="d-flex w-100 justify-content-between"> <div class="d-flex w-100 justify-content-between">
<h5 class="mr-4"># {{ $invoice->invoice_number }}</h5> <h5 class="mr-4"># {{ $invoice->number }}</h5>
<small>{{ $invoice->due_date }}</small> <small>{{ $invoice->due_date }}</small>
</div> </div>
<p class="mb-1 pull-right">{{ $invoice->balance }}</p> <p class="mb-1 pull-right">{{ $invoice->balance }}</p>

View File

@ -29,7 +29,7 @@
@foreach($invoices as $invoice) @foreach($invoices as $invoice)
<a class="list-group-item list-group-item-action flex-column align-items-start" href="javascript:void(0);"> <a class="list-group-item list-group-item-action flex-column align-items-start" href="javascript:void(0);">
<div class="d-flex w-100 justify-content-between"> <div class="d-flex w-100 justify-content-between">
<h5 class="mr-4"># {{ $invoice->invoice_number }}</h5> <h5 class="mr-4"># {{ $invoice->number }}</h5>
<small>{{ $invoice->due_date }}</small> <small>{{ $invoice->due_date }}</small>
</div> </div>
<p class="mb-1 pull-right">{{ $invoice->balance }}</p> <p class="mb-1 pull-right">{{ $invoice->balance }}</p>

View File

@ -22,7 +22,7 @@
<table class="table table-responsive-sm table-sm"> <table class="table table-responsive-sm table-sm">
@foreach($payment->invoices as $invoice) @foreach($payment->invoices as $invoice)
<tr><td style="text-align: right;">{{ ctrans('texts.invoice_number')}}</td><td><a href="{{ route('client.invoice.show', ['invoice' => $invoice->hashed_id])}}">{{ $invoice->invoice_number }}</a></td></tr> <tr><td style="text-align: right;">{{ ctrans('texts.invoice_number')}}</td><td><a href="{{ route('client.invoice.show', ['invoice' => $invoice->hashed_id])}}">{{ $invoice->number }}</a></td></tr>
@endforeach @endforeach
</table> </table>
</div> </div>

View File

@ -144,7 +144,7 @@ class InvoiceTest extends TestCase
{ {
$invoice = [ $invoice = [
'status_id' => 1, 'status_id' => 1,
'invoice_number' => 'dfdfd', 'number' => 'dfdfd',
'discount' => 0, 'discount' => 0,
'is_amount_discount' => 1, 'is_amount_discount' => 1,
'po_number' => '3434343', 'po_number' => '3434343',

View File

@ -164,7 +164,7 @@ trait MockAccountData
$recurring_invoice->start_date = Carbon::now(); $recurring_invoice->start_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -174,7 +174,7 @@ trait MockAccountData
$recurring_invoice->start_date = Carbon::now(); $recurring_invoice->start_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -184,7 +184,7 @@ trait MockAccountData
$recurring_invoice->start_date = Carbon::now(); $recurring_invoice->start_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -194,7 +194,7 @@ trait MockAccountData
$recurring_invoice->start_date = Carbon::now(); $recurring_invoice->start_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client);
$recurring_invoice->save(); $recurring_invoice->save();
@ -205,7 +205,7 @@ trait MockAccountData
$recurring_invoice->start_date = Carbon::now(); $recurring_invoice->start_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client);
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice); $recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
@ -215,7 +215,7 @@ trait MockAccountData
$recurring_invoice->start_date = Carbon::now(); $recurring_invoice->start_date = Carbon::now();
$recurring_invoice->save(); $recurring_invoice->save();
$recurring_invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client); $recurring_invoice->number = $this->getNextInvoiceNumber($this->invoice->client);
$recurring_invoice->save(); $recurring_invoice->save();
$gs = new GroupSetting; $gs = new GroupSetting;