mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 04:01:10 -04:00
Implement PHP CS Fixer and a coding standard to follow (#471)
* Create PHP CS Fixer config and add to CI workflow * Run php cs fixer on project * Add newline at end of file * Update to use PHP CS Fixer v3 * Run v3 config on project * Run seperate config in CI
This commit is contained in:
@ -1,17 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\User;
|
||||
use Crater\Models\Country;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Address extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
const BILLING_TYPE = 'billing';
|
||||
const SHIPPING_TYPE = 'shipping';
|
||||
public const BILLING_TYPE = 'billing';
|
||||
public const SHIPPING_TYPE = 'shipping';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
|
||||
@ -2,13 +2,10 @@
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\User;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
class Company extends Model implements HasMedia
|
||||
{
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@ -32,7 +32,7 @@ class CompanySetting extends Model
|
||||
[
|
||||
'option' => $key,
|
||||
'company_id' => $company_id,
|
||||
'value' => $value
|
||||
'value' => $value,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@ -15,6 +16,6 @@ class Currency extends Model
|
||||
'precision',
|
||||
'thousand_separator',
|
||||
'decimal_separator',
|
||||
'position'
|
||||
'position',
|
||||
];
|
||||
}
|
||||
|
||||
@ -3,26 +3,23 @@
|
||||
namespace Crater\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Crater\Models\CustomFieldValue;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Company;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomField extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [
|
||||
'id'
|
||||
'id',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'defaultAnswer'
|
||||
'defaultAnswer',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'options' => 'array'
|
||||
'options' => 'array',
|
||||
];
|
||||
|
||||
public function setDateAnswerAttribute($value)
|
||||
@ -76,8 +73,8 @@ class CustomField extends Model
|
||||
public function scopeWhereSearch($query, $search)
|
||||
{
|
||||
$query->where(function ($query) use ($search) {
|
||||
$query->where('label', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('name', 'LIKE', '%' . $search . '%');
|
||||
$query->where('label', 'LIKE', '%'.$search.'%')
|
||||
->orWhere('name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
}
|
||||
|
||||
@ -135,7 +132,7 @@ class CustomField extends Model
|
||||
'estimate_shipping_address_format',
|
||||
'estimate_billing_address_format',
|
||||
'payment_company_address_format',
|
||||
'payment_from_customer_address_format'
|
||||
'payment_from_customer_address_format',
|
||||
];
|
||||
|
||||
$settings = CompanySetting::getSettings($settings, $this->company_id);
|
||||
|
||||
@ -3,21 +3,19 @@
|
||||
namespace Crater\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CustomField;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CustomFieldValue extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [
|
||||
'id'
|
||||
'id',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'defaultAnswer'
|
||||
'defaultAnswer',
|
||||
];
|
||||
|
||||
public function setDateAnswerAttribute($value)
|
||||
|
||||
@ -3,44 +3,42 @@
|
||||
namespace Crater\Models;
|
||||
|
||||
use App;
|
||||
use Crater\Models\EstimateTemplate;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Barryvdh\DomPDF\Facade as PDF;
|
||||
use Carbon\Carbon;
|
||||
use Crater\Mail\SendEstimateMail;
|
||||
use Crater\Traits\GeneratesPdfTrait;
|
||||
use Crater\Traits\HasCustomFieldsTrait;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Crater\Traits\GeneratesPdfTrait;
|
||||
use Barryvdh\DomPDF\Facade as PDF;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class Estimate extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory, InteractsWithMedia, GeneratesPdfTrait;
|
||||
use HasFactory;
|
||||
use InteractsWithMedia;
|
||||
use GeneratesPdfTrait;
|
||||
use HasCustomFieldsTrait;
|
||||
|
||||
const STATUS_DRAFT = 'DRAFT';
|
||||
const STATUS_SENT = 'SENT';
|
||||
const STATUS_VIEWED = 'VIEWED';
|
||||
const STATUS_EXPIRED = 'EXPIRED';
|
||||
const STATUS_ACCEPTED = 'ACCEPTED';
|
||||
const STATUS_REJECTED = 'REJECTED';
|
||||
public const STATUS_DRAFT = 'DRAFT';
|
||||
public const STATUS_SENT = 'SENT';
|
||||
public const STATUS_VIEWED = 'VIEWED';
|
||||
public const STATUS_EXPIRED = 'EXPIRED';
|
||||
public const STATUS_ACCEPTED = 'ACCEPTED';
|
||||
public const STATUS_REJECTED = 'REJECTED';
|
||||
|
||||
protected $dates = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at'
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'formattedExpiryDate',
|
||||
'formattedEstimateDate',
|
||||
'estimatePdfUrl'
|
||||
'estimatePdfUrl',
|
||||
];
|
||||
|
||||
protected $guarded = ['id'];
|
||||
@ -69,13 +67,13 @@ class Estimate extends Model implements HasMedia
|
||||
|
||||
public function getEstimatePdfUrlAttribute()
|
||||
{
|
||||
return url('/estimates/pdf/' . $this->unique_hash);
|
||||
return url('/estimates/pdf/'.$this->unique_hash);
|
||||
}
|
||||
|
||||
public static function getNextEstimateNumber($value)
|
||||
{
|
||||
// Get the last created order
|
||||
$lastOrder = Estimate::where('estimate_number', 'LIKE', $value . '-%')
|
||||
$lastOrder = Estimate::where('estimate_number', 'LIKE', $value.'-%')
|
||||
->orderBy('estimate_number', 'desc')
|
||||
->first();
|
||||
|
||||
@ -83,7 +81,7 @@ class Estimate extends Model implements HasMedia
|
||||
$numberLength = CompanySetting::getSetting('estimate_number_length', request()->header('company'));
|
||||
$numberLengthText = "%0{$numberLength}d";
|
||||
|
||||
if (!$lastOrder) {
|
||||
if (! $lastOrder) {
|
||||
// We get here if there is no order at all
|
||||
// If there is no number set it to 0, which will be 1 at the end.
|
||||
$number = 0;
|
||||
@ -140,12 +138,14 @@ class Estimate extends Model implements HasMedia
|
||||
public function getEstimateNumAttribute()
|
||||
{
|
||||
$position = $this->strposX($this->estimate_number, "-", 1) + 1;
|
||||
|
||||
return substr($this->estimate_number, $position);
|
||||
}
|
||||
|
||||
public function getEstimatePrefixAttribute()
|
||||
{
|
||||
$prefix = explode("-", $this->estimate_number)[0];
|
||||
|
||||
return $prefix;
|
||||
}
|
||||
|
||||
@ -167,12 +167,14 @@ class Estimate extends Model implements HasMedia
|
||||
public function getFormattedExpiryDateAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->expiry_date)->format($dateFormat);
|
||||
}
|
||||
|
||||
public function getFormattedEstimateDateAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->estimate_date)->format($dateFormat);
|
||||
}
|
||||
|
||||
@ -203,9 +205,9 @@ class Estimate extends Model implements HasMedia
|
||||
{
|
||||
foreach (explode(' ', $search) as $term) {
|
||||
$query->whereHas('user', function ($query) use ($term) {
|
||||
$query->where('name', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('contact_name', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('company_name', 'LIKE', '%' . $term . '%');
|
||||
$query->where('name', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('contact_name', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('company_name', 'LIKE', '%'.$term.'%');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -300,7 +302,7 @@ class Estimate extends Model implements HasMedia
|
||||
|
||||
self::createItems($estimate, $request);
|
||||
|
||||
if ($request->has('taxes') && (!empty($request->taxes))) {
|
||||
if ($request->has('taxes') && (! empty($request->taxes))) {
|
||||
self::createTaxes($estimate, $request);
|
||||
}
|
||||
|
||||
@ -314,7 +316,7 @@ class Estimate extends Model implements HasMedia
|
||||
'items.taxes',
|
||||
'user',
|
||||
'estimateTemplate',
|
||||
'taxes'
|
||||
'taxes',
|
||||
])
|
||||
->find($estimate->id);
|
||||
}
|
||||
@ -330,7 +332,7 @@ class Estimate extends Model implements HasMedia
|
||||
|
||||
self::createItems($this, $request);
|
||||
|
||||
if ($request->has('taxes') && (!empty($request->taxes))) {
|
||||
if ($request->has('taxes') && (! empty($request->taxes))) {
|
||||
self::createTaxes($this, $request);
|
||||
}
|
||||
|
||||
@ -342,7 +344,7 @@ class Estimate extends Model implements HasMedia
|
||||
'items.taxes',
|
||||
'user',
|
||||
'estimateTemplate',
|
||||
'taxes'
|
||||
'taxes',
|
||||
])
|
||||
->find($this->id);
|
||||
}
|
||||
@ -394,7 +396,7 @@ class Estimate extends Model implements HasMedia
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@ -407,9 +409,9 @@ class Estimate extends Model implements HasMedia
|
||||
if ($this->tax_per_item === 'YES') {
|
||||
foreach ($this->items as $item) {
|
||||
foreach ($item->taxes as $tax) {
|
||||
if (!in_array($tax->name, $taxTypes)) {
|
||||
if (! in_array($tax->name, $taxTypes)) {
|
||||
array_push($taxTypes, $tax->name);
|
||||
array_push($labels, $tax->name . ' (' . $tax->percent . '%)');
|
||||
array_push($labels, $tax->name.' ('.$tax->percent.'%)');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -446,10 +448,10 @@ class Estimate extends Model implements HasMedia
|
||||
'billing_address' => $this->getCustomerBillingAddress(),
|
||||
'notes' => $this->getNotes(),
|
||||
'labels' => $labels,
|
||||
'taxes' => $taxes
|
||||
'taxes' => $taxes,
|
||||
]);
|
||||
|
||||
return PDF::loadView('app.pdf.estimate.' . $estimateTemplate->view);
|
||||
return PDF::loadView('app.pdf.estimate.'.$estimateTemplate->view);
|
||||
}
|
||||
|
||||
public function getCompanyAddress()
|
||||
@ -505,7 +507,7 @@ class Estimate extends Model implements HasMedia
|
||||
'{ESTIMATE_EXPIRY_DATE}' => $this->formattedExpiryDate,
|
||||
'{ESTIMATE_NUMBER}' => $this->estimate_number,
|
||||
'{ESTIMATE_REF_NUMBER}' => $this->reference_number,
|
||||
'{ESTIMATE_LINK}' => url('/customer/estimates/pdf/' . $this->unique_hash)
|
||||
'{ESTIMATE_LINK}' => url('/customer/estimates/pdf/'.$this->unique_hash),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\Item;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EstimateItem extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'estimate_id',
|
||||
'name',
|
||||
@ -32,7 +31,7 @@ class EstimateItem extends Model
|
||||
'discount' => 'float',
|
||||
'quantity' => 'float',
|
||||
'discount_val' => 'integer',
|
||||
'tax' => 'integer'
|
||||
'tax' => 'integer',
|
||||
];
|
||||
|
||||
public function estimate()
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Estimate;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EstimateTemplate extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['path', 'view', 'name'];
|
||||
|
||||
public function estimates()
|
||||
|
||||
@ -2,29 +2,27 @@
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Crater\Models\ExpenseCategory;
|
||||
use Crater\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Crater\Traits\HasCustomFieldsTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
class Expense extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory;
|
||||
use InteractsWithMedia, HasCustomFieldsTrait;
|
||||
use InteractsWithMedia;
|
||||
use HasCustomFieldsTrait;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $appends = [
|
||||
'formattedExpenseDate',
|
||||
'formattedCreatedAt',
|
||||
'receipt'
|
||||
'receipt',
|
||||
];
|
||||
|
||||
public function setExpenseDateAttribute($value)
|
||||
@ -52,12 +50,14 @@ class Expense extends Model implements HasMedia
|
||||
public function getFormattedExpenseDateAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->expense_date)->format($dateFormat);
|
||||
}
|
||||
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
|
||||
@ -83,14 +83,14 @@ class Expense extends Model implements HasMedia
|
||||
{
|
||||
foreach (explode(' ', $search) as $term) {
|
||||
$query->whereHas('category', function ($query) use ($term) {
|
||||
$query->where('name', 'LIKE', '%' . $term . '%');
|
||||
$query->where('name', 'LIKE', '%'.$term.'%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function scopeWhereNotes($query, $search)
|
||||
{
|
||||
$query->where('notes', 'LIKE', '%' . $search . '%');
|
||||
$query->where('notes', 'LIKE', '%'.$search.'%');
|
||||
}
|
||||
|
||||
public function scopeWhereCategory($query, $categoryId)
|
||||
@ -145,9 +145,9 @@ class Expense extends Model implements HasMedia
|
||||
{
|
||||
foreach (explode(' ', $search) as $term) {
|
||||
$query->whereHas('category', function ($query) use ($term) {
|
||||
$query->where('name', 'LIKE', '%' . $term . '%');
|
||||
$query->where('name', 'LIKE', '%'.$term.'%');
|
||||
})
|
||||
->orWhere('notes', 'LIKE', '%' . $term . '%');
|
||||
->orWhere('notes', 'LIKE', '%'.$term.'%');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Expense;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ExpenseCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'company_id', 'description'];
|
||||
|
||||
/**
|
||||
@ -27,6 +27,7 @@ class ExpenseCategory extends Model
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
|
||||
@ -47,7 +48,7 @@ class ExpenseCategory extends Model
|
||||
|
||||
public function scopeWhereSearch($query, $search)
|
||||
{
|
||||
$query->where('name', 'LIKE', '%' . $search . '%');
|
||||
$query->where('name', 'LIKE', '%'.$search.'%');
|
||||
}
|
||||
|
||||
public function scopeApplyFilters($query, array $filters)
|
||||
|
||||
@ -3,18 +3,17 @@
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FileDisk extends Model
|
||||
{
|
||||
CONST DISK_TYPE_SYSTEM = 'SYSTEM';
|
||||
CONST DISK_TYPE_REMOTE = 'REMOTE';
|
||||
|
||||
use HasFactory;
|
||||
public const DISK_TYPE_SYSTEM = 'SYSTEM';
|
||||
public const DISK_TYPE_REMOTE = 'REMOTE';
|
||||
|
||||
protected $guarded = [
|
||||
'id'
|
||||
'id',
|
||||
];
|
||||
|
||||
public function setCredentialsAttribute($value)
|
||||
@ -22,12 +21,12 @@ class FileDisk extends Model
|
||||
$this->attributes['credentials'] = json_encode($value);
|
||||
}
|
||||
|
||||
public function scopeWhereOrder($query, $orderByField, $orderBy)
|
||||
public function scopeWhereOrder($query, $orderByField, $orderBy)
|
||||
{
|
||||
$query->orderBy($orderByField, $orderBy);
|
||||
}
|
||||
|
||||
public function scopeFileDisksBetween($query, $start, $end)
|
||||
public function scopeFileDisksBetween($query, $start, $end)
|
||||
{
|
||||
return $query->whereBetween(
|
||||
'file_disks.created_at',
|
||||
@ -38,8 +37,8 @@ class FileDisk extends Model
|
||||
public function scopeWhereSearch($query, $search)
|
||||
{
|
||||
foreach (explode(' ', $search) as $term) {
|
||||
$query->where('name', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('driver', 'LIKE', '%' . $term . '%');
|
||||
$query->where('name', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('driver', 'LIKE', '%'.$term.'%');
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +47,7 @@ class FileDisk extends Model
|
||||
if ($limit == 'all') {
|
||||
return collect(['data' => $query->get()]);
|
||||
}
|
||||
|
||||
return $query->paginate($limit);
|
||||
}
|
||||
|
||||
@ -89,18 +89,17 @@ class FileDisk extends Model
|
||||
{
|
||||
$prefix = env('DYNAMIC_DISK_PREFIX', 'temp_');
|
||||
|
||||
config(['filesystems.default' => $prefix . $driver]);
|
||||
config(['filesystems.default' => $prefix.$driver]);
|
||||
|
||||
$disks = config('filesystems.disks.' . $driver);
|
||||
$disks = config('filesystems.disks.'.$driver);
|
||||
|
||||
foreach ($disks as $key => $value) {
|
||||
|
||||
if ($credentials->has($key)) {
|
||||
$disks[$key] = $credentials[$key];
|
||||
}
|
||||
}
|
||||
|
||||
config(['filesystems.disks.' . $prefix . $driver => $disks]);
|
||||
config(['filesystems.disks.'.$prefix.$driver => $disks]);
|
||||
}
|
||||
|
||||
public static function validateCredentials($credentials, $disk)
|
||||
@ -113,16 +112,16 @@ class FileDisk extends Model
|
||||
|
||||
try {
|
||||
$root = '';
|
||||
if($disk == 'dropbox'){
|
||||
if ($disk == 'dropbox') {
|
||||
$root = $credentials['root'].'/';
|
||||
}
|
||||
\Storage::disk($prefix . $disk)->put($root.'crater_temp.text', 'Check Credentials');
|
||||
\Storage::disk($prefix.$disk)->put($root.'crater_temp.text', 'Check Credentials');
|
||||
|
||||
if(\Storage::disk($prefix . $disk)->exists($root.'crater_temp.text')) {
|
||||
if (\Storage::disk($prefix.$disk)->exists($root.'crater_temp.text')) {
|
||||
$exists = true;
|
||||
\Storage::disk($prefix . $disk)->delete($root.'crater_temp.text');
|
||||
\Storage::disk($prefix.$disk)->delete($root.'crater_temp.text');
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$exists = false;
|
||||
}
|
||||
|
||||
@ -165,7 +164,7 @@ class FileDisk extends Model
|
||||
'driver' => $request->driver,
|
||||
];
|
||||
|
||||
if(!$this->setAsDefault()) {
|
||||
if (! $this->setAsDefault()) {
|
||||
if ($request->set_as_default) {
|
||||
self::updateDefaultDisks();
|
||||
}
|
||||
|
||||
@ -3,44 +3,40 @@
|
||||
namespace Crater\Models;
|
||||
|
||||
use App;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\InvoiceTemplate;
|
||||
use Crater\Models\Payment;
|
||||
use Barryvdh\DomPDF\Facade as PDF;
|
||||
use Carbon\Carbon;
|
||||
use Crater\Traits\HasCustomFieldsTrait;
|
||||
use Crater\Mail\SendInvoiceMail;
|
||||
use Crater\Traits\GeneratesPdfTrait;
|
||||
use Crater\Traits\HasCustomFieldsTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
use Crater\Traits\GeneratesPdfTrait;
|
||||
use Barryvdh\DomPDF\Facade as PDF;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class Invoice extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory, InteractsWithMedia, GeneratesPdfTrait;
|
||||
use HasFactory;
|
||||
use InteractsWithMedia;
|
||||
use GeneratesPdfTrait;
|
||||
use HasCustomFieldsTrait;
|
||||
|
||||
const STATUS_DRAFT = 'DRAFT';
|
||||
const STATUS_SENT = 'SENT';
|
||||
const STATUS_VIEWED = 'VIEWED';
|
||||
const STATUS_OVERDUE = 'OVERDUE';
|
||||
const STATUS_COMPLETED = 'COMPLETED';
|
||||
public const STATUS_DRAFT = 'DRAFT';
|
||||
public const STATUS_SENT = 'SENT';
|
||||
public const STATUS_VIEWED = 'VIEWED';
|
||||
public const STATUS_OVERDUE = 'OVERDUE';
|
||||
public const STATUS_COMPLETED = 'COMPLETED';
|
||||
|
||||
const STATUS_DUE = 'DUE';
|
||||
const STATUS_UNPAID = 'UNPAID';
|
||||
const STATUS_PARTIALLY_PAID = 'PARTIALLY_PAID';
|
||||
const STATUS_PAID = 'PAID';
|
||||
public const STATUS_DUE = 'DUE';
|
||||
public const STATUS_UNPAID = 'UNPAID';
|
||||
public const STATUS_PARTIALLY_PAID = 'PARTIALLY_PAID';
|
||||
public const STATUS_PAID = 'PAID';
|
||||
|
||||
protected $dates = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at'
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -52,14 +48,14 @@ class Invoice extends Model implements HasMedia
|
||||
];
|
||||
|
||||
protected $guarded = [
|
||||
'id'
|
||||
'id',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'formattedCreatedAt',
|
||||
'formattedInvoiceDate',
|
||||
'formattedDueDate',
|
||||
'invoicePdfUrl'
|
||||
'invoicePdfUrl',
|
||||
];
|
||||
|
||||
public function setInvoiceDateAttribute($value)
|
||||
@ -79,7 +75,7 @@ class Invoice extends Model implements HasMedia
|
||||
public static function getNextInvoiceNumber($value)
|
||||
{
|
||||
// Get the last created order
|
||||
$lastOrder = Invoice::where('invoice_number', 'LIKE', $value . '-%')
|
||||
$lastOrder = Invoice::where('invoice_number', 'LIKE', $value.'-%')
|
||||
->orderBy('invoice_number', 'desc')
|
||||
->first();
|
||||
|
||||
@ -87,7 +83,7 @@ class Invoice extends Model implements HasMedia
|
||||
$numberLength = CompanySetting::getSetting('invoice_number_length', request()->header('company'));
|
||||
$numberLengthText = "%0{$numberLength}d";
|
||||
|
||||
if (!$lastOrder) {
|
||||
if (! $lastOrder) {
|
||||
// We get here if there is no order at all
|
||||
// If there is no number set it to 0, which will be 1 at the end.
|
||||
$number = 0;
|
||||
@ -152,7 +148,7 @@ class Invoice extends Model implements HasMedia
|
||||
|
||||
public function getInvoicePdfUrlAttribute()
|
||||
{
|
||||
return url('/invoices/pdf/' . $this->unique_hash);
|
||||
return url('/invoices/pdf/'.$this->unique_hash);
|
||||
}
|
||||
|
||||
public function getPreviousStatus()
|
||||
@ -186,30 +182,35 @@ class Invoice extends Model implements HasMedia
|
||||
public function getInvoiceNumAttribute()
|
||||
{
|
||||
$position = $this->strposX($this->invoice_number, "-", 1) + 1;
|
||||
|
||||
return substr($this->invoice_number, $position);
|
||||
}
|
||||
|
||||
public function getInvoicePrefixAttribute()
|
||||
{
|
||||
$prefix = explode("-", $this->invoice_number)[0];
|
||||
|
||||
return $prefix;
|
||||
}
|
||||
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
|
||||
public function getFormattedDueDateAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->due_date)->format($dateFormat);
|
||||
}
|
||||
|
||||
public function getFormattedInvoiceDateAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->invoice_date)->format($dateFormat);
|
||||
}
|
||||
|
||||
@ -227,13 +228,13 @@ class Invoice extends Model implements HasMedia
|
||||
{
|
||||
return $query->whereIn('invoices.paid_status', [
|
||||
self::STATUS_UNPAID,
|
||||
self::STATUS_PARTIALLY_PAID
|
||||
self::STATUS_PARTIALLY_PAID,
|
||||
]);
|
||||
}
|
||||
|
||||
public function scopeWhereInvoiceNumber($query, $invoiceNumber)
|
||||
{
|
||||
return $query->where('invoices.invoice_number', 'LIKE', '%' . $invoiceNumber . '%');
|
||||
return $query->where('invoices.invoice_number', 'LIKE', '%'.$invoiceNumber.'%');
|
||||
}
|
||||
|
||||
public function scopeInvoicesBetween($query, $start, $end)
|
||||
@ -248,9 +249,9 @@ class Invoice extends Model implements HasMedia
|
||||
{
|
||||
foreach (explode(' ', $search) as $term) {
|
||||
$query->whereHas('user', function ($query) use ($term) {
|
||||
$query->where('name', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('contact_name', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('company_name', 'LIKE', '%' . $term . '%');
|
||||
$query->where('name', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('contact_name', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('company_name', 'LIKE', '%'.$term.'%');
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -356,7 +357,7 @@ class Invoice extends Model implements HasMedia
|
||||
|
||||
self::createItems($invoice, $request);
|
||||
|
||||
if ($request->has('taxes') && (!empty($request->taxes))) {
|
||||
if ($request->has('taxes') && (! empty($request->taxes))) {
|
||||
self::createTaxes($invoice, $request);
|
||||
}
|
||||
|
||||
@ -368,7 +369,7 @@ class Invoice extends Model implements HasMedia
|
||||
'items',
|
||||
'user',
|
||||
'invoiceTemplate',
|
||||
'taxes'
|
||||
'taxes',
|
||||
])
|
||||
->find($invoice->id);
|
||||
|
||||
@ -393,7 +394,7 @@ class Invoice extends Model implements HasMedia
|
||||
$data['paid_status'] = Invoice::STATUS_PAID;
|
||||
} elseif ($this->due_amount < 0 && $this->paid_status != Invoice::STATUS_UNPAID) {
|
||||
return response()->json([
|
||||
'error' => 'invalid_due_amount'
|
||||
'error' => 'invalid_due_amount',
|
||||
]);
|
||||
} elseif ($data['due_amount'] != 0 && $this->paid_status == Invoice::STATUS_PAID) {
|
||||
$data['status'] = $this->getPreviousStatus();
|
||||
@ -408,7 +409,7 @@ class Invoice extends Model implements HasMedia
|
||||
|
||||
self::createItems($this, $request);
|
||||
|
||||
if ($request->has('taxes') && (!empty($request->taxes))) {
|
||||
if ($request->has('taxes') && (! empty($request->taxes))) {
|
||||
self::createTaxes($this, $request);
|
||||
}
|
||||
|
||||
@ -420,7 +421,7 @@ class Invoice extends Model implements HasMedia
|
||||
'items',
|
||||
'user',
|
||||
'invoiceTemplate',
|
||||
'taxes'
|
||||
'taxes',
|
||||
])
|
||||
->find($this->id);
|
||||
|
||||
@ -444,7 +445,7 @@ class Invoice extends Model implements HasMedia
|
||||
\Mail::to($data['to'])->send(new SendInvoiceMail($data));
|
||||
|
||||
return [
|
||||
'success' => true
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@ -469,7 +470,7 @@ class Invoice extends Model implements HasMedia
|
||||
|
||||
public static function createTaxes($invoice, $request)
|
||||
{
|
||||
if ($request->has('taxes') && (!empty($request->taxes))) {
|
||||
if ($request->has('taxes') && (! empty($request->taxes))) {
|
||||
foreach ($request->taxes as $tax) {
|
||||
$tax['company_id'] = $request->header('company');
|
||||
|
||||
@ -489,9 +490,9 @@ class Invoice extends Model implements HasMedia
|
||||
if ($this->tax_per_item === 'YES') {
|
||||
foreach ($this->items as $item) {
|
||||
foreach ($item->taxes as $tax) {
|
||||
if (!in_array($tax->name, $taxTypes)) {
|
||||
if (! in_array($tax->name, $taxTypes)) {
|
||||
array_push($taxTypes, $tax->name);
|
||||
array_push($labels, $tax->name . ' (' . $tax->percent . '%)');
|
||||
array_push($labels, $tax->name.' ('.$tax->percent.'%)');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -528,10 +529,10 @@ class Invoice extends Model implements HasMedia
|
||||
'notes' => $this->getNotes(),
|
||||
'logo' => $logo ?? null,
|
||||
'labels' => $labels,
|
||||
'taxes' => $taxes
|
||||
'taxes' => $taxes,
|
||||
]);
|
||||
|
||||
return PDF::loadView('app.pdf.invoice.' . $invoiceTemplate->view);
|
||||
return PDF::loadView('app.pdf.invoice.'.$invoiceTemplate->view);
|
||||
}
|
||||
|
||||
public function getEmailAttachmentSetting()
|
||||
@ -587,7 +588,7 @@ class Invoice extends Model implements HasMedia
|
||||
'{INVOICE_DUE_DATE}' => $this->formattedDueDate,
|
||||
'{INVOICE_NUMBER}' => $this->invoice_number,
|
||||
'{INVOICE_REF_NUMBER}' => $this->reference_number,
|
||||
'{INVOICE_LINK}' => url('/customer/invoices/pdf/' . $this->unique_hash)
|
||||
'{INVOICE_LINK}' => url('/customer/invoices/pdf/'.$this->unique_hash),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\Tax;
|
||||
use Crater\Models\Item;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class InvoiceItem extends Model
|
||||
@ -35,7 +33,7 @@ class InvoiceItem extends Model
|
||||
'discount' => 'float',
|
||||
'quantity' => 'float',
|
||||
'discount_val' => 'integer',
|
||||
'tax' => 'integer'
|
||||
'tax' => 'integer',
|
||||
];
|
||||
|
||||
public function invoice()
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Invoice;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class InvoiceTemplate extends Model
|
||||
{
|
||||
|
||||
@ -1,14 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Tax;
|
||||
use Crater\Models\Unit;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class Item extends Model
|
||||
@ -18,11 +14,11 @@ class Item extends Model
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $casts = [
|
||||
'price' => 'integer'
|
||||
'price' => 'integer',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'formattedCreatedAt'
|
||||
'formattedCreatedAt',
|
||||
];
|
||||
|
||||
public function unit()
|
||||
@ -99,14 +95,15 @@ class Item extends Model
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
|
||||
public function taxes()
|
||||
{
|
||||
return $this->hasMany(Tax::class)
|
||||
->where('invoice_item_id', NULL)
|
||||
->where('estimate_item_id', NULL);
|
||||
->where('invoice_item_id', null)
|
||||
->where('estimate_item_id', null);
|
||||
}
|
||||
|
||||
public function scopeWhereCompany($query, $company_id)
|
||||
@ -121,7 +118,7 @@ class Item extends Model
|
||||
|
||||
public function estimateItems()
|
||||
{
|
||||
return $this->hasMany( EstimateItem::class);
|
||||
return $this->hasMany(EstimateItem::class);
|
||||
}
|
||||
|
||||
public static function createItem($request)
|
||||
|
||||
@ -26,7 +26,7 @@ class Note extends Model
|
||||
|
||||
public function scopeWhereSearch($query, $search)
|
||||
{
|
||||
$query->where('name', 'LIKE', '%' . $search . '%');
|
||||
$query->where('name', 'LIKE', '%'.$search.'%');
|
||||
}
|
||||
|
||||
public function scopeWhereType($query, $type)
|
||||
|
||||
@ -2,35 +2,31 @@
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use App;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\User;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\Company;
|
||||
use Barryvdh\DomPDF\Facade as PDF;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\PaymentMethod;
|
||||
use Crater\Traits\HasCustomFieldsTrait;
|
||||
use Crater\Jobs\GeneratePaymentPdfJob;
|
||||
use Crater\Mail\SendPaymentMail;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
use Crater\Traits\GeneratesPdfTrait;
|
||||
use Crater\Traits\HasCustomFieldsTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Crater\Traits\GeneratesPdfTrait;
|
||||
use Barryvdh\DomPDF\Facade as PDF;
|
||||
use Crater\Jobs\GeneratePaymentPdfJob;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class Payment extends Model implements HasMedia
|
||||
{
|
||||
use HasFactory, InteractsWithMedia, GeneratesPdfTrait;
|
||||
use HasFactory;
|
||||
use InteractsWithMedia;
|
||||
use GeneratesPdfTrait;
|
||||
use HasCustomFieldsTrait;
|
||||
|
||||
const PAYMENT_MODE_CHECK = 'CHECK';
|
||||
const PAYMENT_MODE_OTHER = 'OTHER';
|
||||
const PAYMENT_MODE_CASH = 'CASH';
|
||||
const PAYMENT_MODE_CREDIT_CARD = 'CREDIT_CARD';
|
||||
const PAYMENT_MODE_BANK_TRANSFER = 'BANK_TRANSFER';
|
||||
public const PAYMENT_MODE_CHECK = 'CHECK';
|
||||
public const PAYMENT_MODE_OTHER = 'OTHER';
|
||||
public const PAYMENT_MODE_CASH = 'CASH';
|
||||
public const PAYMENT_MODE_CREDIT_CARD = 'CREDIT_CARD';
|
||||
public const PAYMENT_MODE_BANK_TRANSFER = 'BANK_TRANSFER';
|
||||
|
||||
protected $dates = ['created_at', 'updated_at'];
|
||||
|
||||
@ -39,7 +35,7 @@ class Payment extends Model implements HasMedia
|
||||
protected $appends = [
|
||||
'formattedCreatedAt',
|
||||
'formattedPaymentDate',
|
||||
'paymentPdfUrl'
|
||||
'paymentPdfUrl',
|
||||
];
|
||||
|
||||
protected static function booted()
|
||||
@ -63,29 +59,33 @@ class Payment extends Model implements HasMedia
|
||||
public function getPaymentPrefixAttribute()
|
||||
{
|
||||
$prefix = explode("-", $this->payment_number)[0];
|
||||
|
||||
return $prefix;
|
||||
}
|
||||
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
|
||||
public function getFormattedPaymentDateAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->payment_date)->format($dateFormat);
|
||||
}
|
||||
|
||||
public function getPaymentPdfUrlAttribute()
|
||||
{
|
||||
return url('/payments/pdf/' . $this->unique_hash);
|
||||
return url('/payments/pdf/'.$this->unique_hash);
|
||||
}
|
||||
|
||||
public function getPaymentNumAttribute()
|
||||
{
|
||||
$position = $this->strposX($this->payment_number, "-", 1) + 1;
|
||||
|
||||
return substr($this->payment_number, $position);
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ class Payment extends Model implements HasMedia
|
||||
\Mail::to($data['to'])->send(new SendPaymentMail($data));
|
||||
|
||||
return [
|
||||
'success' => true
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
@ -151,10 +151,10 @@ class Payment extends Model implements HasMedia
|
||||
$invoice->due_amount = (int)$invoice->due_amount - (int)$request->amount;
|
||||
if ($invoice->due_amount < 0) {
|
||||
return [
|
||||
'error' => 'invalid_amount'
|
||||
'error' => 'invalid_amount',
|
||||
];
|
||||
}
|
||||
$invoice->paid_status = Invoice::STATUS_PARTIALLY_PAID;
|
||||
$invoice->paid_status = Invoice::STATUS_PARTIALLY_PAID;
|
||||
}
|
||||
$invoice->save();
|
||||
}
|
||||
@ -192,7 +192,7 @@ class Payment extends Model implements HasMedia
|
||||
|
||||
if ($invoice->due_amount < 0) {
|
||||
return [
|
||||
'error' => 'invalid_amount'
|
||||
'error' => 'invalid_amount',
|
||||
];
|
||||
}
|
||||
|
||||
@ -251,6 +251,7 @@ class Payment extends Model implements HasMedia
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function strposX($haystack, $needle, $number)
|
||||
{
|
||||
if ($number == '1') {
|
||||
@ -269,7 +270,7 @@ class Payment extends Model implements HasMedia
|
||||
public static function getNextPaymentNumber($value)
|
||||
{
|
||||
// Get the last created order
|
||||
$payment = Payment::where('payment_number', 'LIKE', $value . '-%')
|
||||
$payment = Payment::where('payment_number', 'LIKE', $value.'-%')
|
||||
->orderBy('payment_number', 'desc')
|
||||
->first();
|
||||
|
||||
@ -277,7 +278,7 @@ class Payment extends Model implements HasMedia
|
||||
$numberLength = CompanySetting::getSetting('payment_number_length', request()->header('company'));
|
||||
$numberLengthText = "%0{$numberLength}d";
|
||||
|
||||
if (!$payment) {
|
||||
if (! $payment) {
|
||||
// We get here if there is no order at all
|
||||
// If there is no number set it to 0, which will be 1 at the end.
|
||||
$number = 0;
|
||||
@ -299,16 +300,16 @@ class Payment extends Model implements HasMedia
|
||||
{
|
||||
foreach (explode(' ', $search) as $term) {
|
||||
$query->whereHas('user', function ($query) use ($term) {
|
||||
$query->where('name', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('contact_name', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('company_name', 'LIKE', '%' . $term . '%');
|
||||
$query->where('name', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('contact_name', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('company_name', 'LIKE', '%'.$term.'%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function scopePaymentNumber($query, $paymentNumber)
|
||||
{
|
||||
return $query->where('payments.payment_number', 'LIKE', '%' . $paymentNumber . '%');
|
||||
return $query->where('payments.payment_number', 'LIKE', '%'.$paymentNumber.'%');
|
||||
}
|
||||
|
||||
public function scopePaymentMethod($query, $paymentMethodId)
|
||||
@ -390,7 +391,7 @@ class Payment extends Model implements HasMedia
|
||||
'company_address' => $this->getCompanyAddress(),
|
||||
'billing_address' => $this->getCustomerBillingAddress(),
|
||||
'notes' => $this->getNotes(),
|
||||
'logo' => $logo ?? null
|
||||
'logo' => $logo ?? null,
|
||||
]);
|
||||
|
||||
return PDF::loadView('app.pdf.payment.payment');
|
||||
@ -442,7 +443,7 @@ class Payment extends Model implements HasMedia
|
||||
'{PAYMENT_MODE}' => $this->paymentMethod ? $this->paymentMethod->name : null,
|
||||
'{PAYMENT_NUMBER}' => $this->payment_number,
|
||||
'{PAYMENT_AMOUNT}' => $this->reference_number,
|
||||
'{PAYMENT_LINK}' => $this->paymentPdfUrl
|
||||
'{PAYMENT_LINK}' => $this->paymentPdfUrl,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\Payment;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
@ -35,7 +33,7 @@ class PaymentMethod extends Model
|
||||
|
||||
public function scopeWhereSearch($query, $search)
|
||||
{
|
||||
$query->where('name', 'LIKE', '%' . $search . '%');
|
||||
$query->where('name', 'LIKE', '%'.$search.'%');
|
||||
}
|
||||
|
||||
public function scopeApplyFilters($query, array $filters)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@ -15,6 +16,7 @@ class Setting extends Model
|
||||
if ($old) {
|
||||
$old->value = $setting;
|
||||
$old->save();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -1,20 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\TaxType;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\Item;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class Tax extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'amount',
|
||||
@ -24,12 +20,12 @@ class Tax extends Model
|
||||
'invoice_id',
|
||||
'estimate_id',
|
||||
'item_id',
|
||||
'compound_tax'
|
||||
'compound_tax',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'amount' => 'integer',
|
||||
'percent' => 'float'
|
||||
'percent' => 'float',
|
||||
];
|
||||
|
||||
public function taxType()
|
||||
@ -82,7 +78,7 @@ class Tax extends Model
|
||||
'invoice_date',
|
||||
[$start->format('Y-m-d'), $end->format('Y-m-d')]
|
||||
);
|
||||
})
|
||||
})
|
||||
->orWhereHas('invoiceItem.invoice', function ($query) use ($start, $end) {
|
||||
$query->where('paid_status', Invoice::STATUS_PAID)
|
||||
->whereBetween(
|
||||
|
||||
@ -2,24 +2,24 @@
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class TaxType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'percent',
|
||||
'company_id',
|
||||
'compound_tax',
|
||||
'collective_tax',
|
||||
'description'
|
||||
'description',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'percent' => 'float'
|
||||
'percent' => 'float',
|
||||
];
|
||||
|
||||
public function taxes()
|
||||
@ -67,7 +67,7 @@ class TaxType extends Model
|
||||
|
||||
public function scopeWhereSearch($query, $search)
|
||||
{
|
||||
$query->where('name', 'LIKE', '%' . $search . '%');
|
||||
$query->where('name', 'LIKE', '%'.$search.'%');
|
||||
}
|
||||
|
||||
public function scopePaginateData($query, $limit)
|
||||
|
||||
@ -2,14 +2,13 @@
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Unit extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'company_id'];
|
||||
|
||||
public function items()
|
||||
|
||||
@ -2,30 +2,24 @@
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\CompanySetting;
|
||||
use Crater\Models\Currency;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\UserSetting;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Carbon\Carbon;
|
||||
use Crater\Models\Address;
|
||||
use Crater\Models\Payment;
|
||||
use Crater\Models\Expense;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Traits\HasCustomFieldsTrait;
|
||||
use Crater\Notifications\MailResetPasswordNotification;
|
||||
use Crater\Traits\HasCustomFieldsTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
class User extends Authenticatable implements HasMedia
|
||||
{
|
||||
use HasApiTokens, Notifiable, InteractsWithMedia, HasCustomFieldsTrait;
|
||||
use HasApiTokens;
|
||||
use Notifiable;
|
||||
use InteractsWithMedia;
|
||||
use HasCustomFieldsTrait;
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
@ -49,7 +43,7 @@ class User extends Authenticatable implements HasMedia
|
||||
'contact_name',
|
||||
'website',
|
||||
'enable_portal',
|
||||
'creator_id'
|
||||
'creator_id',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -63,12 +57,12 @@ class User extends Authenticatable implements HasMedia
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'currency'
|
||||
'currency',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'formattedCreatedAt',
|
||||
'avatar'
|
||||
'avatar',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -99,12 +93,14 @@ class User extends Authenticatable implements HasMedia
|
||||
$remember = $request->remember;
|
||||
$email = $request->email;
|
||||
$password = $request->password;
|
||||
return (\Auth::attempt(array('email' => $email, 'password' => $password), $remember));
|
||||
|
||||
return (\Auth::attempt(['email' => $email, 'password' => $password], $remember));
|
||||
}
|
||||
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
|
||||
@ -180,31 +176,31 @@ class User extends Authenticatable implements HasMedia
|
||||
{
|
||||
foreach (explode(' ', $search) as $term) {
|
||||
$query->where(function ($query) use ($term) {
|
||||
$query->where('name', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('email', 'LIKE', '%' . $term . '%')
|
||||
->orWhere('phone', 'LIKE', '%' . $term . '%');
|
||||
$query->where('name', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('email', 'LIKE', '%'.$term.'%')
|
||||
->orWhere('phone', 'LIKE', '%'.$term.'%');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function scopeWhereContactName($query, $contactName)
|
||||
{
|
||||
return $query->where('contact_name', 'LIKE', '%' . $contactName . '%');
|
||||
return $query->where('contact_name', 'LIKE', '%'.$contactName.'%');
|
||||
}
|
||||
|
||||
public function scopeWhereDisplayName($query, $displayName)
|
||||
{
|
||||
return $query->where('name', 'LIKE', '%' . $displayName . '%');
|
||||
return $query->where('name', 'LIKE', '%'.$displayName.'%');
|
||||
}
|
||||
|
||||
public function scopeWherePhone($query, $phone)
|
||||
{
|
||||
return $query->where('phone', 'LIKE', '%' . $phone . '%');
|
||||
return $query->where('phone', 'LIKE', '%'.$phone.'%');
|
||||
}
|
||||
|
||||
public function scopeWhereEmail($query, $email)
|
||||
{
|
||||
return $query->where('email', 'LIKE', '%' . $email . '%');
|
||||
return $query->where('email', 'LIKE', '%'.$email.'%');
|
||||
}
|
||||
|
||||
public function scopeCustomer($query)
|
||||
@ -290,7 +286,6 @@ class User extends Authenticatable implements HasMedia
|
||||
public static function deleteCustomers($ids)
|
||||
{
|
||||
foreach ($ids as $id) {
|
||||
|
||||
$customer = self::find($id);
|
||||
|
||||
if ($customer->estimates()->exists()) {
|
||||
@ -335,7 +330,7 @@ class User extends Authenticatable implements HasMedia
|
||||
'company_name',
|
||||
'contact_name',
|
||||
'website',
|
||||
'enable_portal'
|
||||
'enable_portal',
|
||||
]);
|
||||
|
||||
$data['creator_id'] = Auth::id();
|
||||
@ -374,7 +369,7 @@ class User extends Authenticatable implements HasMedia
|
||||
'company_name',
|
||||
'contact_name',
|
||||
'website',
|
||||
'enable_portal'
|
||||
'enable_portal',
|
||||
]);
|
||||
|
||||
$data['role'] = 'customer';
|
||||
@ -410,7 +405,7 @@ class User extends Authenticatable implements HasMedia
|
||||
],
|
||||
[
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
'value' => $value,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
namespace Crater\Models;
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user