Skip to content

Commit

Permalink
Merge pull request #221 from wanderlust-group-project-1/adminstyles
Browse files Browse the repository at this point in the history
admin-complains
  • Loading branch information
Sandali-Upekha authored Apr 24, 2024
2 parents 2c74e26 + 842abb7 commit c0a69e1
Show file tree
Hide file tree
Showing 13 changed files with 1,304 additions and 629 deletions.
50 changes: 50 additions & 0 deletions app/controllers/Admin/Complains.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

class Complains
{
use Controller;

public function index(string $a = '', string $b = '', string $c = ''): void
{
$this->view('admin/complains');
}

public function listComplains(string $a = '', string $b = '', string $c = ''): void
{
$complain = new RentReturnComplaintModel;
$data['complaints'] = $complain->getAdminRentalComplaints($b);

$this->view('admin/components/complainlist', $data);
}



public function viewComplaint(string $a = '', string $b = '', string $c = ''): void
{
$rentreturncomplaint = new RentReturnComplaintModel;
$complaint = $rentreturncomplaint->getComplaint($a);
// show($complaint);
$rent = new RentModel;
$order = $rent->getRental($complaint->rent_id);
$items = $rent->getItemListbyRentId($complaint->rent_id);

// add complaint details to items
foreach ($items as $item) {
$item->complaint = null;
$item->charge = 0;
// show(json_decode($complaint->complains));
foreach (json_decode($complaint->complains) as $complain) {
if ($item->equipment_id == $complain->equipment_id) {
$item->complaint = $complain;
$item->charge = $complain->charge;
}
}
}



// show(['complaint' => $complaint, 'order' => $order, 'items' => $items]);

$this->view('admin/components/complaint', ['complaint' => $complaint, 'order' => $order, 'items' => $items]);
}
}
48 changes: 30 additions & 18 deletions app/models/RentReturnComplaint.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php


class RentReturnComplaintModel {
class RentReturnComplaintModel
{
use Model;


Expand All @@ -20,7 +21,7 @@ class RentReturnComplaintModel {
// complaint_descriptions: [],
// charges: []
// };



protected string $table = 'rent_return_complaints';
Expand All @@ -31,22 +32,13 @@ class RentReturnComplaintModel {
'charge'
];

public function createReturnComplaint($data) {
public function createReturnComplaint($data)
{
$data = array_filter($data, function ($key) {
return in_array($key, $this->allowedColumns);
}, ARRAY_FILTER_USE_KEY);

$this->insert($data);










}

public function getComplaintsByRentalId($rental_id, $status='pending') {
Expand All @@ -61,20 +53,22 @@ public function getComplaintsByRentalId($rental_id, $status='pending') {
->where('rent_return_complaints.status', $status);

// echo $q->getQuery();
return $this->query($q->getQuery(),$q->getData());
return $this->query($q->getQuery(), $q->getData());
}

public function getComplaint($id) {
public function getComplaint($id)
{
$q = new QueryBuilder;
$q->setTable('rent_return_complaints');
$q->select('rent_return_complaints.*,rent.id as rent_id')
->join('rent', 'rent_return_complaints.rent_id', 'rent.id')
->where('rent_return_complaints.id', $id);

return $this->query($q->getQuery(),$q->getData())[0];
return $this->query($q->getQuery(), $q->getData())[0];
}

public function cancelComplaint($id) {
public function cancelComplaint($id)
{
$q = new QueryBuilder;
$q->setTable('rent_return_complaints');

Expand All @@ -98,4 +92,22 @@ public function getComplaintsByCustomerId($id) {
}


}




public function getAdminRentalComplaints($status = "pending"){

$q = new QueryBuilder;
// join rent table to get rental
$q->setTable('rent_return_complaints');
$q->select('rent_return_complaints.*,rent.id as rent_id')
->setTable('rent_return_complaints')
->join('rent', 'rent_return_complaints.rent_id', 'rent.id')
->where('rent_return_complaints.status', $status);

// echo $q->getQuery();
return $this->query($q->getQuery(), $q->getData());
}

}
Loading

0 comments on commit c0a69e1

Please sign in to comment.