Skip to content

Commit

Permalink
Refactor and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajitbohra committed Jan 13, 2019
1 parent 064bcfc commit 4785302
Show file tree
Hide file tree
Showing 50 changed files with 95 additions and 408 deletions.
2 changes: 1 addition & 1 deletion app/ChequeDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function createdBy()
return $this->belongsTo('App\User', 'created_by');
}

public function Payment()
public function payment()
{
return $this->belongsTo('App\PaymentDetail', 'payment_id');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Expense.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Expense extends Model

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

public function Category()
public function category()
{
return $this->belongsTo('App\ExpenseCategory', 'category_id');
}
Expand Down
2 changes: 1 addition & 1 deletion app/ExpenseCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function scopeExcludeArchive($query)
return $query->where('status', '!=', \constStatus::Archive);
}

public function Expenses()
public function expenses()
{
return $this->hasMany('App\Expense', 'category_id');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Followup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Followup extends Model

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

public function Enquiry()
public function enquiry()
{
return $this->belongsTo('App\Enquiry', 'enquiry_id');
}
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/AclController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use App\User;
use App\RoleUser;
use App\Permission;
use App\Permission_role;
use App\PermissionRole;
use Illuminate\Http\Request;

class AclController extends Controller
Expand Down Expand Up @@ -88,8 +88,8 @@ public function updateUser($id, Request $request)
}
$user->save();

if ($user->role_user->role->id != $request->role_id) {
RoleUser::where('user_id', $user->id)->where('role_id', $user->role_user->role_id)->delete();
if ($user->roleUser->role->id != $request->role_id) {
RoleUser::where('user_id', $user->id)->where('role_id', $user->roleUser->role_id)->delete();
$user->attachRole($request->role_id);
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public function editRole($id)
{
$role = Role::findOrFail($id);
$permissions = Permission::all();
$permission_role = Permission_role::where('role_id', $id)->get();
$permission_role = PermissionRole::where('role_id', $id)->get();

return view('user.editRole', compact('role', 'permissions', 'permission_role'));
}
Expand All @@ -184,7 +184,7 @@ public function updateRole($id, Request $request)
]);

//Updating permissions for the role
$DBpermissions = Permission_role::where('role_id', $id)->select('permission_id')->lists('permission_id');
$DBpermissions = PermissionRole::where('role_id', $id)->select('permission_id')->lists('permission_id');
$ClientPermissions = collect($request->permissions);

$addPermissions = $ClientPermissions->diff($DBpermissions);
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/DataMigrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function migrate()
DB::commit();
} catch (\Exception $e) {
DB::rollback();
dd($e);
}
}

Expand All @@ -80,7 +79,6 @@ public function migrateMedia()
}
} catch (\Exception $e) {
DB::rollback();
dd($e);
}
}

Expand All @@ -104,7 +102,6 @@ public function migrateExcel()

$dob = Carbon::createFromFormat('d/m/Y', $line->get('dob'))->toDateString();
$gender = ($line->get('gender') == 'male' ? 'm' : 'f');
// $explodedName = explode(" ", $line->get('name'));
$email = $member_code.'@evolvegym.in';

$address = (empty($line->get('address')) ? 'Naigaon east' : $line->get('address'));
Expand Down Expand Up @@ -219,8 +216,6 @@ public function migrateExcel()
DB::commit();
} catch (\Exception $e) {
DB::rollback();
dd($e);
}
echo 'Ho gaya bc';
}
}
55 changes: 27 additions & 28 deletions app/Http/Controllers/MembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ public function store(Request $request)

// Adding media i.e. Profile & proof photo
if ($request->hasFile('photo')) {
$member->addMedia($request->file('photo'))->usingFileName('profile_'.$member->id.$request->photo->getClientOriginalExtension())->toCollection('profile');
$member->addMedia($request->file('photo'))->usingFileName('profile_'.$member->id.'.'.$request->photo->getClientOriginalExtension())->toCollection('profile');
}

if ($request->hasFile('proof_photo')) {
$member->addMedia($request->file('proof_photo'))->usingFileName('proof_'.$member->id.$request->proof_photo->getClientOriginalExtension())->toCollection('proof');
$member->addMedia($request->file('proof_photo'))->usingFileName('proof_'.$member->id.'.'.$request->proof_photo->getClientOriginalExtension())->toCollection('proof');
}

// Helper function for calculating payment status
Expand Down Expand Up @@ -223,10 +223,10 @@ public function store(Request $request)
'plan_id'=> $plan['id'],
'item_amount'=> $plan['price'], ];

$invoice_details = new InvoiceDetail($detailsData);
$invoice_details->createdBy()->associate(Auth::user());
$invoice_details->updatedBy()->associate(Auth::user());
$invoice_details->save();
$invoiceDetails = new InvoiceDetail($detailsData);
$invoiceDetails->createdBy()->associate(Auth::user());
$invoiceDetails->updatedBy()->associate(Auth::user());
$invoiceDetails->save();
}

// Store Payment Details
Expand All @@ -235,14 +235,14 @@ public function store(Request $request)
'mode'=> $request->mode,
'note'=> ' ', ];

$payment_details = new PaymentDetail($paymentData);
$payment_details->createdBy()->associate(Auth::user());
$payment_details->updatedBy()->associate(Auth::user());
$payment_details->save();
$paymentDetails = new PaymentDetail($paymentData);
$paymentDetails->createdBy()->associate(Auth::user());
$paymentDetails->updatedBy()->associate(Auth::user());
$paymentDetails->save();

if ($request->mode == 0) {
// Store Cheque Details
$chequeData = ['payment_id'=> $payment_details->id,
$chequeData = ['payment_id'=> $paymentDetails->id,
'number'=> $request->number,
'date'=> $request->date,
'status'=> \constChequeStatus::Recieved, ];
Expand Down Expand Up @@ -271,22 +271,22 @@ public function store(Request $request)
if ($invoice->status == \constPaymentStatus::Paid) {
$sms_trigger = SmsTrigger::where('alias', '=', 'member_admission_with_paid_invoice')->first();
$message = $sms_trigger->message;
$sms_text = sprintf($message, $member->name, $gym_name, $payment_details->payment_amount, $invoice->invoice_number);
$sms_text = sprintf($message, $member->name, $gym_name, $paymentDetails->payment_amount, $invoice->invoice_number);
$sms_status = $sms_trigger->status;

\Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status);
} elseif ($invoice->status == \constPaymentStatus::Partial) {
$sms_trigger = SmsTrigger::where('alias', '=', 'member_admission_with_partial_invoice')->first();
$message = $sms_trigger->message;
$sms_text = sprintf($message, $member->name, $gym_name, $payment_details->payment_amount, $invoice->invoice_number, $invoice->pending_amount);
$sms_text = sprintf($message, $member->name, $gym_name, $paymentDetails->payment_amount, $invoice->invoice_number, $invoice->pending_amount);
$sms_status = $sms_trigger->status;

\Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status);
} elseif ($invoice->status == \constPaymentStatus::Unpaid) {
if ($request->mode == 0) {
$sms_trigger = SmsTrigger::where('alias', '=', 'payment_with_cheque')->first();
$message = $sms_trigger->message;
$sms_text = sprintf($message, $member->name, $payment_details->payment_amount, $cheque_details->number, $invoice->invoice_number, $gym_name);
$sms_text = sprintf($message, $member->name, $paymentDetails->payment_amount, $cheque_details->number, $invoice->invoice_number, $gym_name);
$sms_status = $sms_trigger->status;

\Utilities::Sms($sender_id, $member->contact, $sms_text, $sms_status);
Expand All @@ -309,15 +309,15 @@ public function store(Request $request)
$invoice->updated_at = $subscription->start_date;
$invoice->save();

foreach ($invoice->invoice_details as $invoice_detail) {
$invoice_detail->created_at = $subscription->start_date;
$invoice_detail->updated_at = $subscription->start_date;
$invoice_detail->save();
foreach ($invoice->invoiceDetails as $invoiceDetail) {
$invoiceDetail->created_at = $subscription->start_date;
$invoiceDetail->updated_at = $subscription->start_date;
$invoiceDetail->save();
}

$payment_details->created_at = $subscription->start_date;
$payment_details->updated_at = $subscription->start_date;
$payment_details->save();
$paymentDetails->created_at = $subscription->start_date;
$paymentDetails->updated_at = $subscription->start_date;
$paymentDetails->save();

$subscription->created_at = $subscription->start_date;
$subscription->updated_at = $subscription->start_date;
Expand Down Expand Up @@ -361,18 +361,17 @@ public function edit($id)
*/
public function update($id, Request $request)
{
//dd($request->all());
$member = Member::findOrFail($id);
$member->update($request->all());

if ($request->hasFile('photo')) {
$member->clearMediaCollection('profile');
$member->addMedia($request->file('photo'))->usingFileName('profile_'.$member->id.$request->photo->getClientOriginalExtension())->toCollection('profile');
$member->addMedia($request->file('photo'))->usingFileName('profile_'.$member->id.'.'.$request->photo->getClientOriginalExtension())->toCollection('profile');
}

if ($request->hasFile('proof_photo')) {
$member->clearMediaCollection('proof');
$member->addMedia($request->file('proof_photo'))->usingFileName('proof_'.$member->id.$request->proof_photo->getClientOriginalExtension())->toCollection('proof');
$member->addMedia($request->file('proof_photo'))->usingFileName('proof_'.$member->id.'.'.$request->proof_photo->getClientOriginalExtension())->toCollection('proof');
}

$member->updatedBy()->associate(Auth::user());
Expand All @@ -396,11 +395,11 @@ public function archive($id, Request $request)

foreach ($invoices as $invoice) {
InvoiceDetail::where('invoice_id', $invoice->id)->delete();
$payment_details = PaymentDetail::where('invoice_id', $invoice->id)->get();
$paymentDetails = PaymentDetail::where('invoice_id', $invoice->id)->get();

foreach ($payment_details as $payment_detail) {
ChequeDetail::where('payment_id', $payment_detail->id)->delete();
$payment_detail->delete();
foreach ($paymentDetails as $paymentDetail) {
ChequeDetail::where('payment_id', $paymentDetail->id)->delete();
$paymentDetail->delete();
}

$invoice->delete();
Expand Down
78 changes: 0 additions & 78 deletions app/Http/Controllers/ReportsController.php

This file was deleted.

Loading

1 comment on commit 4785302

@firatz
Copy link

@firatz firatz commented on 4785302 Feb 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I've changed all of these codes, but adding new members doesn't work for me.

Please sign in to comment.