Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dry the code using traits #38

Merged
merged 5 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions app/ChequeDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

class ChequeDetail extends Model
{
//Eloquence Search mapping
use Eloquence;
use updatedByUser;

protected $table = 'trn_cheque_details';

protected $fillable = [
Expand All @@ -18,9 +22,6 @@ class ChequeDetail extends Model
'updated_by',
];

//Eloquence Search mapping
use Eloquence;

protected $searchableColumns = [
'number' => 20,
];
Expand All @@ -30,11 +31,6 @@ public function createdBy()
return $this->belongsTo('App\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('App\User', 'updated_by');
}

public function Payment()
{
return $this->belongsTo('App\PaymentDetail', 'payment_id');
Expand Down
22 changes: 8 additions & 14 deletions app/Enquiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

class Enquiry extends Model
{
//Eloquence Search mapping
use Eloquence;
use createdByUser, updatedByUser;

protected $table = 'mst_enquiries';

protected $fillable = [
Expand All @@ -27,9 +31,6 @@ class Enquiry extends Model
'updated_by',
];

//Eloquence Search mapping
use Eloquence;

protected $searchableColumns = [
'name' => 20,
'email' => 20,
Expand All @@ -41,16 +42,6 @@ public function Followups()
return $this->hasMany('App\Followup');
}

public function createdBy()
{
return $this->belongsTo('App\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('App\User', 'updated_by');
}

public function scopeIndexQuery($query, $sorting_field, $sorting_direction, $drp_start, $drp_end)
{
$sorting_field = ($sorting_field != null ? $sorting_field : 'created_at');
Expand All @@ -60,7 +51,10 @@ public function scopeIndexQuery($query, $sorting_field, $sorting_direction, $drp
return $query->select('id', 'name', 'contact', 'email', 'address', 'gender', 'created_at', 'status')->orderBy($sorting_field, $sorting_direction);
}

return $query->select('id', 'name', 'contact', 'email', 'address', 'gender', 'created_at', 'status')->whereBetween('created_at', [$drp_start, $drp_end])->orderBy($sorting_field, $sorting_direction);
return $query->select('id', 'name', 'contact', 'email', 'address', 'gender', 'created_at', 'status')->whereBetween('created_at', [
$drp_start,
$drp_end,
])->orderBy($sorting_field, $sorting_direction);
}

public function scopeOnlyLeads($query)
Expand Down
45 changes: 21 additions & 24 deletions app/Expense.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,31 @@

class Expense extends Model
{
//Eloquence Search mapping
use Eloquence;
use createdByUser, updatedByUser;

protected $table = 'trn_expenses';

protected $fillable = [
'name',
'category_id',
'amount',
'due_date',
'repeat',
'note',
'paid',
'created_by',
'updated_by',
'name',
'category_id',
'amount',
'due_date',
'repeat',
'note',
'paid',
'created_by',
'updated_by',
];

//Eloquence Search mapping
use Eloquence;

protected $searchableColumns = [
'name' => 20,
'amount' => 10,
];

protected $dates = ['created_at', 'updated_at', 'due_date'];

public function createdBy()
{
return $this->belongsTo('App\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('App\User', 'updated_by');
}

public function Category()
{
return $this->belongsTo('App\ExpenseCategory', 'category_id');
Expand Down Expand Up @@ -71,9 +62,15 @@ public function scopeIndexQuery($query, $category, $sorting_field, $sorting_dire
}

if ($category == 0) {
return $query->leftJoin('mst_expenses_categories', 'trn_expenses.category_id', '=', 'mst_expenses_categories.id')->select('trn_expenses.*', 'mst_expenses_categories.name as category_name')->whereBetween('trn_expenses.created_at', [$drp_start, $drp_end])->orderBy($sorting_field, $sorting_direction);
return $query->leftJoin('mst_expenses_categories', 'trn_expenses.category_id', '=', 'mst_expenses_categories.id')->select('trn_expenses.*', 'mst_expenses_categories.name as category_name')->whereBetween('trn_expenses.created_at', [
$drp_start,
$drp_end,
])->orderBy($sorting_field, $sorting_direction);
} else {
return $query->leftJoin('mst_expenses_categories', 'trn_expenses.category_id', '=', 'mst_expenses_categories.id')->select('trn_expenses.*', 'mst_expenses_categories.name as category_name')->where('category_id', $category)->whereBetween('trn_expenses.created_at', [$drp_start, $drp_end])->orderBy($sorting_field, $sorting_direction);
return $query->leftJoin('mst_expenses_categories', 'trn_expenses.category_id', '=', 'mst_expenses_categories.id')->select('trn_expenses.*', 'mst_expenses_categories.name as category_name')->where('category_id', $category)->whereBetween('trn_expenses.created_at', [
$drp_start,
$drp_end,
])->orderBy($sorting_field, $sorting_direction);
}
}
}
12 changes: 2 additions & 10 deletions app/ExpenseCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class ExpenseCategory extends Model
{
use createdByUser, updatedByUser;

protected $table = 'mst_expenses_categories';

protected $fillable = [
Expand All @@ -26,14 +28,4 @@ public function Expenses()
{
return $this->hasMany('App\Expense', 'category_id');
}

public function createdBy()
{
return $this->belongsTo('app\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('app\User', 'updated_by');
}
}
18 changes: 3 additions & 15 deletions app/Followup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class Followup extends Model
{
use createdByUser, updatedByUser;

protected $table = 'trn_enquiry_followups';

protected $fillable = [
Expand All @@ -28,20 +30,6 @@ public function Enquiry()

public function scopeReminders($query)
{
return $query->leftJoin('mst_enquiries', 'trn_enquiry_followups.enquiry_id', '=', 'mst_enquiries.id')
->select('trn_enquiry_followups.*', 'mst_enquiries.status')
->where('trn_enquiry_followups.due_date', '<=', Carbon::today())
->where('trn_enquiry_followups.status', '=', \constFollowUpStatus::Pending)
->where('mst_enquiries.status', '=', \constEnquiryStatus::Lead);
}

public function createdBy()
{
return $this->belongsTo('App\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('App\User', 'updated_by');
return $query->leftJoin('mst_enquiries', 'trn_enquiry_followups.enquiry_id', '=', 'mst_enquiries.id')->select('trn_enquiry_followups.*', 'mst_enquiries.status')->where('trn_enquiry_followups.due_date', '<=', Carbon::today())->where('trn_enquiry_followups.status', '=', \constFollowUpStatus::Pending)->where('mst_enquiries.status', '=', \constEnquiryStatus::Lead);
}
}
11 changes: 1 addition & 10 deletions app/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Invoice extends Model

//Eloquence Search mapping
use Eloquence;
use createdByUser, updatedByUser;

protected $searchableColumns = [
'invoice_number' => 20,
Expand All @@ -50,16 +51,6 @@ public function scopeIndexQuery($query, $sorting_field, $sorting_direction, $drp
return $query->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id')->select('trn_invoice.*', 'mst_members.name as member_name')->whereBetween('trn_invoice.created_at', [$drp_start, $drp_end])->orderBy($sorting_field, $sorting_direction);
}

public function createdBy()
{
return $this->belongsTo('App\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('App\User', 'updated_by');
}

public function Member()
{
return $this->belongsTo('App\Member', 'member_id');
Expand Down
28 changes: 10 additions & 18 deletions app/InvoiceDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,19 @@

class InvoiceDetail extends Model
{
use createdByUser, updatedByUser;

protected $table = 'trn_invoice_details';

protected $fillable = [
'item_name',
'plan_id',
'item_description',
'invoice_id',
'item_amount',
'created_by',
'updated_by',
];

public function createdBy()
{
return $this->belongsTo('App\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('App\User', 'updated_by');
}
'item_name',
'plan_id',
'item_description',
'invoice_id',
'item_amount',
'created_by',
'updated_by',
];

public function Invoice()
{
Expand Down
26 changes: 8 additions & 18 deletions app/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

class Member extends Model implements HasMediaConversions
{
use HasMediaTrait , Eloquence;
use HasMediaTrait, Eloquence;
use createdByUser, updatedByUser;

protected $table = 'mst_members';

Expand Down Expand Up @@ -46,26 +47,12 @@ class Member extends Model implements HasMediaConversions
// Media i.e. Image size conversion
public function registerMediaConversions()
{
$this->addMediaConversion('thumb')
->setManipulations(['w' => 50, 'h' => 50, 'q' => 100, 'fit' => 'crop'])
->performOnCollections('profile');
$this->addMediaConversion('thumb')->setManipulations(['w' => 50, 'h' => 50, 'q' => 100, 'fit' => 'crop'])->performOnCollections('profile');

$this->addMediaConversion('form')
->setManipulations(['w' => 70, 'h' => 70, 'q' => 100, 'fit' => 'crop'])
->performOnCollections('profile', 'proof');
$this->addMediaConversion('form')->setManipulations(['w' => 70, 'h' => 70, 'q' => 100, 'fit' => 'crop'])->performOnCollections('profile', 'proof');
}

//Relationships
public function createdBy()
{
return $this->belongsTo('App\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('App\User', 'updated_by');
}

public function Subscriptions()
{
return $this->hasMany('App\Subscription');
Expand All @@ -86,7 +73,10 @@ public function scopeIndexQuery($query, $sorting_field, $sorting_direction, $drp
return $query->select('mst_members.id', 'mst_members.member_code', 'mst_members.name', 'mst_members.contact', 'mst_members.created_at', 'mst_members.status')->where('mst_members.status', '!=', \constStatus::Archive)->orderBy($sorting_field, $sorting_direction);
}

return $query->select('mst_members.id', 'mst_members.member_code', 'mst_members.name', 'mst_members.contact', 'mst_members.created_at', 'mst_members.status')->where('mst_members.status', '!=', \constStatus::Archive)->whereBetween('mst_members.created_at', [$drp_start, $drp_end])->orderBy($sorting_field, $sorting_direction);
return $query->select('mst_members.id', 'mst_members.member_code', 'mst_members.name', 'mst_members.contact', 'mst_members.created_at', 'mst_members.status')->where('mst_members.status', '!=', \constStatus::Archive)->whereBetween('mst_members.created_at', [
$drp_start,
$drp_end,
])->orderBy($sorting_field, $sorting_direction);
}

// public function scopeReportQuery($query,$sorting_field,$sorting_direction,$drp_start,$drp_end)
Expand Down
45 changes: 16 additions & 29 deletions app/PaymentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@

class PaymentDetail extends Model
{
//Eloquence Search mapping
use Eloquence;
use createdByUser,updatedByUser;

protected $table = 'trn_payment_details';

protected $fillable = [
'payment_amount',
'note',
'mode',
'invoice_id',
'created_by',
'updated_by',
];

//Eloquence Search mapping
use Eloquence;
'payment_amount',
'note',
'mode',
'invoice_id',
'created_by',
'updated_by',
];

protected $searchableColumns = [
'payment_amount' => 20,
Expand All @@ -33,27 +34,13 @@ public function scopeIndexQuery($query, $sorting_field, $sorting_direction, $drp
$sorting_direction = ($sorting_direction != null ? $sorting_direction : 'desc');

if ($drp_start == null or $drp_end == null) {
return $query->leftJoin('trn_invoice', 'trn_payment_details.invoice_id', '=', 'trn_invoice.id')
->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id')
->select('trn_payment_details.id', 'trn_payment_details.created_at', 'trn_payment_details.payment_amount', 'trn_payment_details.mode', 'trn_payment_details.invoice_id', 'trn_invoice.invoice_number', 'mst_members.id as member_id', 'mst_members.name as member_name', 'mst_members.member_code')
->orderBy($sorting_field, $sorting_direction);
return $query->leftJoin('trn_invoice', 'trn_payment_details.invoice_id', '=', 'trn_invoice.id')->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id')->select('trn_payment_details.id', 'trn_payment_details.created_at', 'trn_payment_details.payment_amount', 'trn_payment_details.mode', 'trn_payment_details.invoice_id', 'trn_invoice.invoice_number', 'mst_members.id as member_id', 'mst_members.name as member_name', 'mst_members.member_code')->orderBy($sorting_field, $sorting_direction);
}

return $query->leftJoin('trn_invoice', 'trn_payment_details.invoice_id', '=', 'trn_invoice.id')
->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id')
->select('trn_payment_details.id', 'trn_payment_details.created_at', 'trn_payment_details.payment_amount', 'trn_payment_details.mode', 'trn_invoice.invoice_number', 'mst_members.name as member_name', 'mst_members.member_code')
->whereBetween('trn_payment_details.created_at', [$drp_start, $drp_end])
->orderBy($sorting_field, $sorting_direction);
}

public function createdBy()
{
return $this->belongsTo('App\User', 'created_by');
}

public function updatedBy()
{
return $this->belongsTo('App\User', 'updated_by');
return $query->leftJoin('trn_invoice', 'trn_payment_details.invoice_id', '=', 'trn_invoice.id')->leftJoin('mst_members', 'trn_invoice.member_id', '=', 'mst_members.id')->select('trn_payment_details.id', 'trn_payment_details.created_at', 'trn_payment_details.payment_amount', 'trn_payment_details.mode', 'trn_invoice.invoice_number', 'mst_members.name as member_name', 'mst_members.member_code')->whereBetween('trn_payment_details.created_at', [
$drp_start,
$drp_end,
])->orderBy($sorting_field, $sorting_direction);
}

public function Invoice()
Expand Down
Loading