removed invoice/bill status tables
This commit is contained in:
@ -47,17 +47,13 @@ abstract class Widget
|
||||
|
||||
$today = Date::today()->toDateString();
|
||||
|
||||
$type = ($model instanceof Invoice) ? 'invoice' : 'bill';
|
||||
|
||||
$status_field = $type . '_status_code';
|
||||
|
||||
if ($model->$status_field == 'paid') {
|
||||
if ($model->status == 'paid') {
|
||||
return [$open, $overdue];
|
||||
}
|
||||
|
||||
$payments = 0;
|
||||
|
||||
if ($model->$status_field == 'partial') {
|
||||
if ($model->status == 'partial') {
|
||||
foreach ($model->transactions as $transaction) {
|
||||
$payments += $transaction->getAmountConvertedToDefault();
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class Bills extends BulkAction
|
||||
$bills = $this->getSelectedRecords($request);
|
||||
|
||||
foreach ($bills as $bill) {
|
||||
$bill->bill_status_code = 'received';
|
||||
$bill->status = 'received';
|
||||
$bill->save();
|
||||
|
||||
$description = trans('bills.mark_recevied');
|
||||
|
@ -33,7 +33,7 @@ class BillHistories implements FromCollection, ShouldAutoSize, WithHeadings, Wit
|
||||
{
|
||||
return [
|
||||
$model->bill_id,
|
||||
$model->status_code,
|
||||
$model->status,
|
||||
$model->notify,
|
||||
$model->description,
|
||||
];
|
||||
@ -43,7 +43,7 @@ class BillHistories implements FromCollection, ShouldAutoSize, WithHeadings, Wit
|
||||
{
|
||||
return [
|
||||
'bill_id',
|
||||
'status_code',
|
||||
'status',
|
||||
'notify',
|
||||
'description',
|
||||
];
|
||||
@ -53,4 +53,4 @@ class BillHistories implements FromCollection, ShouldAutoSize, WithHeadings, Wit
|
||||
{
|
||||
return 'bill_histories';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class Bills implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping
|
||||
return [
|
||||
$model->bill_number,
|
||||
$model->order_number,
|
||||
$model->bill_status_code,
|
||||
$model->status,
|
||||
$model->billed_at,
|
||||
$model->due_at,
|
||||
$model->amount,
|
||||
@ -57,7 +57,7 @@ class Bills implements FromCollection, ShouldAutoSize, WithHeadings, WithMapping
|
||||
return [
|
||||
'bill_number',
|
||||
'order_number',
|
||||
'bill_status_code',
|
||||
'status',
|
||||
'billed_at',
|
||||
'due_at',
|
||||
'amount',
|
||||
|
@ -33,7 +33,7 @@ class InvoiceHistories implements FromCollection, ShouldAutoSize, WithHeadings,
|
||||
{
|
||||
return [
|
||||
$model->invoice_id,
|
||||
$model->status_code,
|
||||
$model->status,
|
||||
$model->notify,
|
||||
$model->description,
|
||||
];
|
||||
@ -43,7 +43,7 @@ class InvoiceHistories implements FromCollection, ShouldAutoSize, WithHeadings,
|
||||
{
|
||||
return [
|
||||
'invoice_id',
|
||||
'status_code',
|
||||
'status',
|
||||
'notify',
|
||||
'description',
|
||||
];
|
||||
@ -53,4 +53,4 @@ class InvoiceHistories implements FromCollection, ShouldAutoSize, WithHeadings,
|
||||
{
|
||||
return 'invoice_histories';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class Invoices implements FromCollection, ShouldAutoSize, WithHeadings, WithMapp
|
||||
return [
|
||||
$model->invoice_number,
|
||||
$model->order_number,
|
||||
$model->invoice_status_code,
|
||||
$model->status,
|
||||
$model->invoiced_at,
|
||||
$model->due_at,
|
||||
$model->amount,
|
||||
@ -57,7 +57,7 @@ class Invoices implements FromCollection, ShouldAutoSize, WithHeadings, WithMapp
|
||||
return [
|
||||
'invoice_number',
|
||||
'order_number',
|
||||
'invoice_status_code',
|
||||
'status',
|
||||
'invoiced_at',
|
||||
'due_at',
|
||||
'amount',
|
||||
|
@ -40,7 +40,7 @@ class Dashboard extends Controller
|
||||
$unpaid = $paid = $overdue = $partial_paid = [];
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
switch ($invoice->invoice_status_code) {
|
||||
switch ($invoice->status) {
|
||||
case 'paid':
|
||||
$paid[] = $invoice;
|
||||
break;
|
||||
|
@ -6,18 +6,18 @@ use App\Abstracts\Http\Controller;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceStatus;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Sales;
|
||||
use App\Traits\Uploads;
|
||||
use App\Utilities\Modules;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
|
||||
class Invoices extends Controller
|
||||
{
|
||||
use DateTime, Currencies, Uploads;
|
||||
use DateTime, Currencies, Sales, Uploads;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@ -32,10 +32,7 @@ class Invoices extends Controller
|
||||
|
||||
$categories = collect(Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id'));
|
||||
|
||||
$statuses = collect(InvoiceStatus::get()->each(function ($item) {
|
||||
$item->name = trans('invoices.status.' . $item->code);
|
||||
return $item;
|
||||
})->pluck('name', 'code'));
|
||||
$statuses = $this->getInvoiceStatuses();
|
||||
|
||||
return view('portal.invoices.index', compact('invoices', 'categories', 'statuses'));
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ use App\Jobs\Purchase\UpdateBill;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Purchase\BillStatus;
|
||||
use App\Models\Purchase\Bill;
|
||||
use App\Models\Purchase\BillHistory;
|
||||
use App\Models\Setting\Category;
|
||||
@ -24,12 +23,13 @@ use App\Models\Setting\Tax;
|
||||
use App\Traits\Contacts;
|
||||
use App\Traits\Currencies;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Purchases;
|
||||
use App\Traits\Uploads;
|
||||
use App\Utilities\Modules;
|
||||
|
||||
class Bills extends Controller
|
||||
{
|
||||
use Contacts, Currencies, DateTime, Uploads;
|
||||
use Contacts, Currencies, DateTime, Purchases, Uploads;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@ -44,10 +44,7 @@ class Bills extends Controller
|
||||
|
||||
$categories = Category::type('expense')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$statuses = collect(BillStatus::get()->each(function ($item) {
|
||||
$item->name = trans('bills.status.' . $item->code);
|
||||
return $item;
|
||||
})->pluck('name', 'code'));
|
||||
$statuses = $this->getBillStatuses();
|
||||
|
||||
return view('purchases.bills.index', compact('bills', 'vendors', 'categories', 'statuses'));
|
||||
}
|
||||
@ -270,14 +267,14 @@ class Bills extends Controller
|
||||
*/
|
||||
public function markReceived(Bill $bill)
|
||||
{
|
||||
$bill->bill_status_code = 'received';
|
||||
$bill->status = 'received';
|
||||
$bill->save();
|
||||
|
||||
// Add bill history
|
||||
BillHistory::create([
|
||||
'company_id' => $bill->company_id,
|
||||
'bill_id' => $bill->id,
|
||||
'status_code' => 'received',
|
||||
'status' => 'received',
|
||||
'notify' => 0,
|
||||
'description' => trans('bills.mark_received'),
|
||||
]);
|
||||
|
@ -59,7 +59,7 @@ class Vendors extends Controller
|
||||
|
||||
foreach ($bills as $item) {
|
||||
// Already in transactions
|
||||
if ($item->bill_status_code == 'paid') {
|
||||
if ($item->status == 'paid') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ class Customers extends Controller
|
||||
|
||||
foreach ($invoices as $item) {
|
||||
// Already in transactions
|
||||
if ($item->invoice_status_code == 'paid') {
|
||||
if ($item->status == 'paid') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ use App\Models\Banking\Account;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Common\Item;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Models\Sale\InvoiceStatus;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Models\Setting\Tax;
|
||||
@ -46,10 +45,7 @@ class Invoices extends Controller
|
||||
|
||||
$categories = Category::type('income')->enabled()->orderBy('name')->pluck('name', 'id');
|
||||
|
||||
$statuses = collect(InvoiceStatus::get()->each(function ($item) {
|
||||
$item->name = trans('invoices.status.' . $item->code);
|
||||
return $item;
|
||||
})->pluck('name', 'code'));
|
||||
$statuses = $this->getInvoiceStatuses();
|
||||
|
||||
return view('sales.invoices.index', compact('invoices', 'customers', 'categories', 'statuses'));
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class Bill extends FormRequest
|
||||
|
||||
return [
|
||||
'bill_number' => 'required|string|unique:bills,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'bill_status_code' => 'required|string',
|
||||
'status' => 'required|string',
|
||||
'billed_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'due_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'amount' => 'required',
|
||||
|
@ -25,7 +25,7 @@ class BillHistory extends FormRequest
|
||||
{
|
||||
return [
|
||||
'bill_id' => 'required|integer',
|
||||
'status_code' => 'required|string',
|
||||
'status' => 'required|string',
|
||||
'notify' => 'required|integer',
|
||||
];
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class Invoice extends FormRequest
|
||||
|
||||
return [
|
||||
'invoice_number' => 'required|string|unique:invoices,NULL,' . $id . ',id,company_id,' . $company_id . ',deleted_at,NULL',
|
||||
'invoice_status_code' => 'required|string',
|
||||
'status' => 'required|string',
|
||||
'invoiced_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'due_at' => 'required|date_format:Y-m-d H:i:s',
|
||||
'amount' => 'required',
|
||||
|
@ -25,7 +25,7 @@ class InvoiceHistory extends FormRequest
|
||||
{
|
||||
return [
|
||||
'invoice_id' => 'required|integer',
|
||||
'status_code' => 'required|string',
|
||||
'status' => 'required|string',
|
||||
'notify' => 'required|integer',
|
||||
];
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ class CreateDocumentTransaction extends Job
|
||||
|
||||
throw new \Exception($message);
|
||||
} else {
|
||||
$this->setStatusCode($amount_check, $total_amount_check);
|
||||
$this->model->status = ($amount_check == $total_amount_check) ? 'paid' : 'partial';
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -189,17 +189,6 @@ class CreateDocumentTransaction extends Job
|
||||
return $paid;
|
||||
}
|
||||
|
||||
protected function setStatusCode($amount_check, $total_amount_check)
|
||||
{
|
||||
$column = ($this->model instanceof Invoice) ? 'invoice_status_code' : 'bill_status_code';
|
||||
|
||||
if ($amount_check == $total_amount_check) {
|
||||
$this->model->$column = 'paid';
|
||||
} else {
|
||||
$this->model->$column = 'partial';
|
||||
}
|
||||
}
|
||||
|
||||
protected function createHistory($transaction)
|
||||
{
|
||||
$history_desc = money((double) $transaction->amount, (string) $transaction->currency_code, true)->format() . ' ' . trans_choice('general.payments', 1);
|
||||
|
@ -32,9 +32,9 @@ class DeleteCompany extends Job
|
||||
$this->authorize();
|
||||
|
||||
$this->deleteRelationships($this->company, [
|
||||
'accounts', 'bills', 'bill_histories', 'bill_items', 'bill_item_taxes', 'bill_statuses', 'bill_totals', 'categories',
|
||||
'accounts', 'bills', 'bill_histories', 'bill_items', 'bill_item_taxes', 'bill_totals', 'categories',
|
||||
'contacts', 'currencies', 'dashboards', 'email_templates', 'invoices', 'invoice_histories', 'invoice_items',
|
||||
'invoice_item_taxes', 'invoice_statuses', 'invoice_totals', 'items', 'modules', 'module_histories', 'reconciliations',
|
||||
'invoice_item_taxes', 'invoice_totals', 'items', 'modules', 'module_histories', 'reconciliations',
|
||||
'recurring', 'reports', 'settings', 'taxes', 'transactions', 'transfers', 'widgets',
|
||||
]);
|
||||
|
||||
|
@ -39,7 +39,7 @@ class CreateBillHistory extends Job
|
||||
$bill_history = BillHistory::create([
|
||||
'company_id' => $this->bill->company_id,
|
||||
'bill_id' => $this->bill->id,
|
||||
'status_code' => $this->bill->bill_status_code,
|
||||
'status' => $this->bill->status,
|
||||
'notify' => $this->notify,
|
||||
'description' => $description,
|
||||
]);
|
||||
|
@ -33,7 +33,7 @@ class DuplicateBill extends Job
|
||||
BillHistory::create([
|
||||
'company_id' => session('company_id'),
|
||||
'bill_id' => $clone->id,
|
||||
'status_code' => 'draft',
|
||||
'status' => 'draft',
|
||||
'notify' => 0,
|
||||
'description' => trans('messages.success.added', ['type' => $clone->bill_number]),
|
||||
]);
|
||||
|
@ -57,7 +57,7 @@ class UpdateBill extends Job
|
||||
unset($this->bill->reconciled);
|
||||
|
||||
if (($bill_paid) && $this->request['amount'] > $bill_paid) {
|
||||
$this->request['bill_status_code'] = 'partial';
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
$this->bill->update($this->request->input());
|
||||
|
@ -39,7 +39,7 @@ class CreateInvoiceHistory extends Job
|
||||
$invoice_history = InvoiceHistory::create([
|
||||
'company_id' => $this->invoice->company_id,
|
||||
'invoice_id' => $this->invoice->id,
|
||||
'status_code' => $this->invoice->invoice_status_code,
|
||||
'status' => $this->invoice->status,
|
||||
'notify' => $this->notify,
|
||||
'description' => $description,
|
||||
]);
|
||||
|
@ -57,7 +57,7 @@ class UpdateInvoice extends Job
|
||||
unset($this->invoice->reconciled);
|
||||
|
||||
if (($invoice_paid) && $this->request['amount'] > $invoice_paid) {
|
||||
$this->request['invoice_status_code'] = 'partial';
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
$this->invoice->update($this->request->all());
|
||||
|
@ -16,8 +16,8 @@ class MarkInvoiceSent
|
||||
public function handle(Event $event)
|
||||
{
|
||||
// Mark invoice as sent
|
||||
if ($event->invoice->invoice_status_code != 'partial') {
|
||||
$event->invoice->invoice_status_code = 'sent';
|
||||
if ($event->invoice->status != 'partial') {
|
||||
$event->invoice->status = 'sent';
|
||||
|
||||
$event->invoice->save();
|
||||
}
|
||||
@ -26,7 +26,7 @@ class MarkInvoiceSent
|
||||
InvoiceHistory::create([
|
||||
'company_id' => $event->invoice->company_id,
|
||||
'invoice_id' => $event->invoice->id,
|
||||
'status_code' => 'sent',
|
||||
'status' => 'sent',
|
||||
'notify' => 0,
|
||||
'description' => trans('invoices.mark_sent'),
|
||||
]);
|
||||
|
@ -16,13 +16,13 @@ class MarkInvoiceViewed
|
||||
{
|
||||
$invoice = $event->invoice;
|
||||
|
||||
if ($invoice->invoice_status_code != 'sent') {
|
||||
if ($invoice->status != 'sent') {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($invoice->paid);
|
||||
|
||||
$invoice->invoice_status_code = 'viewed';
|
||||
$invoice->status = 'viewed';
|
||||
$invoice->save();
|
||||
}
|
||||
}
|
||||
|
@ -63,11 +63,6 @@ class Company extends Eloquent
|
||||
return $this->hasMany('App\Models\Purchase\BillItemTax');
|
||||
}
|
||||
|
||||
public function bill_statuses()
|
||||
{
|
||||
return $this->hasMany('App\Models\Purchase\BillStatus');
|
||||
}
|
||||
|
||||
public function bill_totals()
|
||||
{
|
||||
return $this->hasMany('App\Models\Purchase\BillTotal');
|
||||
@ -133,11 +128,6 @@ class Company extends Eloquent
|
||||
return $this->hasMany('App\Models\Sale\InvoiceItemTax');
|
||||
}
|
||||
|
||||
public function invoice_statuses()
|
||||
{
|
||||
return $this->hasMany('App\Models\Sale\InvoiceStatus');
|
||||
}
|
||||
|
||||
public function invoice_totals()
|
||||
{
|
||||
return $this->hasMany('App\Models\Sale\InvoiceTotal');
|
||||
|
@ -23,7 +23,7 @@ class Bill extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid'];
|
||||
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid', 'status_label'];
|
||||
|
||||
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
|
||||
|
||||
@ -32,14 +32,14 @@ class Bill extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_number', 'order_number', 'bill_status_code', 'billed_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'contact_id', 'contact_name', 'contact_email', 'contact_tax_number', 'contact_phone', 'contact_address', 'notes', 'category_id', 'parent_id'];
|
||||
protected $fillable = ['company_id', 'bill_number', 'order_number', 'status', 'billed_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'contact_id', 'contact_name', 'contact_email', 'contact_tax_number', 'contact_phone', 'contact_address', 'notes', 'category_id', 'parent_id'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['bill_number', 'contact_name', 'amount', 'status.name', 'billed_at', 'due_at', 'bill_status_code'];
|
||||
public $sortable = ['bill_number', 'contact_name', 'amount', 'status', 'billed_at', 'due_at'];
|
||||
|
||||
/**
|
||||
* Clonable relationships.
|
||||
@ -83,11 +83,6 @@ class Bill extends Model
|
||||
return $this->morphOne('App\Models\Common\Recurring', 'recurable');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Purchase\BillStatus', 'bill_status_code', 'code');
|
||||
}
|
||||
|
||||
public function totals()
|
||||
{
|
||||
return $this->hasMany('App\Models\Purchase\BillTotal');
|
||||
@ -110,22 +105,22 @@ class Bill extends Model
|
||||
|
||||
public function scopeAccrued($query)
|
||||
{
|
||||
return $query->where('bill_status_code', '<>', 'draft');
|
||||
return $query->where('status', '<>', 'draft');
|
||||
}
|
||||
|
||||
public function scopePaid($query)
|
||||
{
|
||||
return $query->where('bill_status_code', '=', 'paid');
|
||||
return $query->where('status', '=', 'paid');
|
||||
}
|
||||
|
||||
public function scopeNotPaid($query)
|
||||
{
|
||||
return $query->where('bill_status_code', '<>', 'paid');
|
||||
return $query->where('status', '<>', 'paid');
|
||||
}
|
||||
|
||||
public function onCloning($src, $child = null)
|
||||
{
|
||||
$this->bill_status_code = 'draft';
|
||||
$this->status = 'draft';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,4 +251,30 @@ class Bill extends Model
|
||||
|
||||
return $paid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelAttribute()
|
||||
{
|
||||
switch ($this->code) {
|
||||
case 'paid':
|
||||
$label = 'success';
|
||||
break;
|
||||
case 'delete':
|
||||
$label = 'danger';
|
||||
break;
|
||||
case 'partial':
|
||||
case 'received':
|
||||
$label = 'warning';
|
||||
break;
|
||||
default:
|
||||
$label = 'info';
|
||||
break;
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
}
|
||||
|
@ -17,15 +17,10 @@ class BillHistory extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_id', 'status_code', 'notify', 'description'];
|
||||
protected $fillable = ['company_id', 'bill_id', 'status', 'notify', 'description'];
|
||||
|
||||
public function bill()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Purchase\Bill');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Purchase\BillStatus', 'status_code', 'code');
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Purchase;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
|
||||
class BillStatus extends Model
|
||||
{
|
||||
|
||||
protected $table = 'bill_statuses';
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['label'];
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'code'];
|
||||
|
||||
/**
|
||||
* Get the status label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelAttribute()
|
||||
{
|
||||
switch ($this->code) {
|
||||
case 'paid':
|
||||
$label = 'success';
|
||||
break;
|
||||
case 'delete':
|
||||
$label = 'danger';
|
||||
break;
|
||||
case 'partial':
|
||||
case 'received':
|
||||
$label = 'warning';
|
||||
break;
|
||||
default:
|
||||
$label = 'info';
|
||||
break;
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
}
|
@ -23,7 +23,7 @@ class Invoice extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid'];
|
||||
protected $appends = ['attachment', 'amount_without_tax', 'discount', 'paid', 'status_label'];
|
||||
|
||||
protected $dates = ['deleted_at', 'invoiced_at', 'due_at'];
|
||||
|
||||
@ -32,14 +32,14 @@ class Invoice extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_number', 'order_number', 'invoice_status_code', 'invoiced_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'contact_id', 'contact_name', 'contact_email', 'contact_tax_number', 'contact_phone', 'contact_address', 'notes', 'category_id', 'parent_id', 'footer'];
|
||||
protected $fillable = ['company_id', 'invoice_number', 'order_number', 'status', 'invoiced_at', 'due_at', 'amount', 'currency_code', 'currency_rate', 'contact_id', 'contact_name', 'contact_email', 'contact_tax_number', 'contact_phone', 'contact_address', 'notes', 'category_id', 'parent_id', 'footer'];
|
||||
|
||||
/**
|
||||
* Sortable columns.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $sortable = ['invoice_number', 'contact_name', 'amount', 'status' , 'invoiced_at', 'due_at', 'invoice_status_code'];
|
||||
public $sortable = ['invoice_number', 'contact_name', 'amount', 'status' , 'invoiced_at', 'due_at'];
|
||||
|
||||
protected $reconciled_amount = [];
|
||||
|
||||
@ -90,11 +90,6 @@ class Invoice extends Model
|
||||
return $this->morphOne('App\Models\Common\Recurring', 'recurable');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Sale\InvoiceStatus', 'invoice_status_code', 'code');
|
||||
}
|
||||
|
||||
public function totals()
|
||||
{
|
||||
return $this->hasMany('App\Models\Sale\InvoiceTotal');
|
||||
@ -117,22 +112,22 @@ class Invoice extends Model
|
||||
|
||||
public function scopeAccrued($query)
|
||||
{
|
||||
return $query->where('invoice_status_code', '<>', 'draft');
|
||||
return $query->where('status', '<>', 'draft');
|
||||
}
|
||||
|
||||
public function scopePaid($query)
|
||||
{
|
||||
return $query->where('invoice_status_code', '=', 'paid');
|
||||
return $query->where('status', '=', 'paid');
|
||||
}
|
||||
|
||||
public function scopeNotPaid($query)
|
||||
{
|
||||
return $query->where('invoice_status_code', '<>', 'paid');
|
||||
return $query->where('status', '<>', 'paid');
|
||||
}
|
||||
|
||||
public function onCloning($src, $child = null)
|
||||
{
|
||||
$this->invoice_status_code = 'draft';
|
||||
$this->status = 'draft';
|
||||
$this->invoice_number = $this->getNextInvoiceNumber();
|
||||
}
|
||||
|
||||
@ -264,4 +259,30 @@ class Invoice extends Model
|
||||
|
||||
return $paid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStatusLabelAttribute()
|
||||
{
|
||||
switch ($this->status) {
|
||||
case 'paid':
|
||||
$label = 'success';
|
||||
break;
|
||||
case 'delete':
|
||||
$label = 'danger';
|
||||
break;
|
||||
case 'partial':
|
||||
case 'sent':
|
||||
$label = 'warning';
|
||||
break;
|
||||
default:
|
||||
$label = 'info';
|
||||
break;
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ use App\Traits\Currencies;
|
||||
|
||||
class InvoiceHistory extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'invoice_histories';
|
||||
@ -17,15 +16,10 @@ class InvoiceHistory extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'status_code', 'notify', 'description'];
|
||||
protected $fillable = ['company_id', 'invoice_id', 'status', 'notify', 'description'];
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Sale\Invoice');
|
||||
}
|
||||
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Sale\InvoiceStatus', 'status_code', 'code');
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Sale;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
|
||||
class InvoiceStatus extends Model
|
||||
{
|
||||
|
||||
protected $table = 'invoice_statuses';
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['label'];
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'code'];
|
||||
|
||||
/**
|
||||
* Get the status label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabelAttribute()
|
||||
{
|
||||
switch ($this->code) {
|
||||
case 'paid':
|
||||
$label = 'success';
|
||||
break;
|
||||
case 'delete':
|
||||
$label = 'danger';
|
||||
break;
|
||||
case 'partial':
|
||||
case 'sent':
|
||||
$label = 'warning';
|
||||
break;
|
||||
default:
|
||||
$label = 'info';
|
||||
break;
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
}
|
@ -100,7 +100,7 @@ class PaymentReceived extends Notification
|
||||
$this->invoice->invoice_number,
|
||||
money($this->invoice->amount, $this->invoice->currency_code, true),
|
||||
$this->invoice->due_at,
|
||||
trans('invoices.status.' . $this->invoice->invoice_status_code),
|
||||
trans('invoices.statuses.' . $this->invoice->status),
|
||||
URL::signedRoute('signed.invoices.show', [$this->invoice->id, 'company_id' => $this->invoice->company_id]),
|
||||
route('invoices.show', $this->invoice->id),
|
||||
route('portal.invoices.show', $this->invoice->id),
|
||||
|
@ -32,7 +32,7 @@ class Transaction
|
||||
{
|
||||
$invoice = $transaction->invoice;
|
||||
|
||||
$invoice->invoice_status_code = ($invoice->transactions->count() > 1) ? 'partial' : 'sent';
|
||||
$invoice->status = ($invoice->transactions->count() > 1) ? 'partial' : 'sent';
|
||||
|
||||
$invoice->save();
|
||||
|
||||
@ -43,7 +43,7 @@ class Transaction
|
||||
{
|
||||
$bill = $transaction->bill;
|
||||
|
||||
$bill->bill_status_code = ($bill->transactions->count() > 1) ? 'partial' : 'received';
|
||||
$bill->status = ($bill->transactions->count() > 1) ? 'partial' : 'received';
|
||||
|
||||
$bill->save();
|
||||
|
||||
|
33
app/Traits/Purchases.php
Normal file
33
app/Traits/Purchases.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait Purchases
|
||||
{
|
||||
/**
|
||||
* Get a collection of bill statuses
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBillStatuses()
|
||||
{
|
||||
$list = [
|
||||
'draft',
|
||||
'received',
|
||||
'partial',
|
||||
'paid',
|
||||
'overdue',
|
||||
'unpaid',
|
||||
];
|
||||
|
||||
$statuses = collect($list)->each(function ($code) {
|
||||
$item = new \stdClass();
|
||||
$item->code = $code;
|
||||
$item->name = trans('bills.statuses.' . $code);
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
return $statuses;
|
||||
}
|
||||
}
|
@ -30,4 +30,33 @@ trait Sales
|
||||
setting(['invoice.number_next' => $next]);
|
||||
setting()->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection invoice statuses
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getInvoiceStatuses()
|
||||
{
|
||||
$list = [
|
||||
'draft',
|
||||
'sent',
|
||||
'viewed',
|
||||
'approved',
|
||||
'partial',
|
||||
'paid',
|
||||
'overdue',
|
||||
'unpaid',
|
||||
];
|
||||
|
||||
$statuses = collect($list)->each(function ($code) {
|
||||
$item = new \stdClass();
|
||||
$item->code = $code;
|
||||
$item->name = trans('invoices.statuses.' . $code);
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
return $statuses;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class Bill extends TransformerAbstract
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'status', 'transactions'];
|
||||
protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'transactions'];
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
@ -26,7 +26,7 @@ class Bill extends TransformerAbstract
|
||||
'company_id' => $model->company_id,
|
||||
'bill_number' => $model->bill_number,
|
||||
'order_number' => $model->order_number,
|
||||
'bill_status_code' => $model->invoice_status_code,
|
||||
'status' => $model->status,
|
||||
'billed_at' => $model->billed_at ? $model->billed_at->toIso8601String() : '',
|
||||
'due_at' => $model->due_at ? $model->due_at->toIso8601String() : '',
|
||||
'amount' => $model->amount,
|
||||
@ -81,15 +81,6 @@ class Bill extends TransformerAbstract
|
||||
return $this->collection($model->items, new BillItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Item
|
||||
*/
|
||||
public function includeStatus(Model $model)
|
||||
{
|
||||
return $this->item($model->status, new BillStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
|
@ -17,7 +17,7 @@ class BillHistories extends TransformerAbstract
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'bill_id' => $model->bill_id,
|
||||
'status_code' => $model->status_code,
|
||||
'status' => $model->status,
|
||||
'notify' => $model->notify,
|
||||
'description' => $model->description,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Purchase;
|
||||
|
||||
use App\Models\Purchase\BillStatus as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class BillStatus extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'name' => $model->name,
|
||||
'code' => $model->code,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ class Invoice extends TransformerAbstract
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'status', 'transactions'];
|
||||
protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'transactions'];
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
@ -26,7 +26,7 @@ class Invoice extends TransformerAbstract
|
||||
'company_id' => $model->company_id,
|
||||
'invoice_number' => $model->invoice_number,
|
||||
'order_number' => $model->order_number,
|
||||
'invoice_status_code' => $model->invoice_status_code,
|
||||
'status' => $model->status,
|
||||
'invoiced_at' => $model->invoiced_at ? $model->invoiced_at->toIso8601String() : '',
|
||||
'due_at' => $model->due_at ? $model->due_at->toIso8601String() : '',
|
||||
'amount' => $model->amount,
|
||||
@ -81,15 +81,6 @@ class Invoice extends TransformerAbstract
|
||||
return $this->collection($model->items, new InvoiceItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Item
|
||||
*/
|
||||
public function includeStatus(Model $model)
|
||||
{
|
||||
return $this->item($model->status, new InvoiceStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
|
@ -17,7 +17,7 @@ class InvoiceHistories extends TransformerAbstract
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'invoice_id' => $model->invoice_id,
|
||||
'status_code' => $model->status_code,
|
||||
'status' => $model->status,
|
||||
'notify' => $model->notify,
|
||||
'description' => $model->description,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Transformers\Sale;
|
||||
|
||||
use App\Models\Sale\InvoiceStatus as Model;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
|
||||
class InvoiceStatus extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* @param Model $model
|
||||
* @return array
|
||||
*/
|
||||
public function transform(Model $model)
|
||||
{
|
||||
return [
|
||||
'id' => $model->id,
|
||||
'company_id' => $model->company_id,
|
||||
'name' => $model->name,
|
||||
'code' => $model->code,
|
||||
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
|
||||
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user