<?php

class Inv{
    private $_conn = null;
	private $_res = null;
	private $_userId = null;

	public function __construct($conn, $userId){
		$this->_conn = $conn;
		$this->_userId = $userId;
	}

    public function getInvoices($filter){
        
        if($filter['tableName'] == 'barrister'){

            $query_string = "SELECT barristerInvoice.*, max(`cases`.`id`) as caseId,`cases`.`barristerId`, `cases`.`clientId`, `cases`.`clientTypeId`, `cases`.`solicitorId`, `cases`.`teamId`, `cases`.`courtRef`, `cases`.`claimant`, `cases`.`defendant`, `cases`.`fundingTypeId`, `cases`.`active`,`barristers`.`fname` as barristerFName, CONCAT(`titles`.`name`, ' ', `barristers`.`fname`, ' ', `barristers`.`lname`) as barristerName,  ( `barristerInvoice`.`totalAmount` - `barristerInvoice`.`totalPaid`) as totalDue, barristerInvoiceItems.total as totalCase FROM barristerInvoice, cases, barristerInvoiceItems, barristers, titles WHERE barristerInvoiceItems.caseId = cases.id and barristerInvoice.status = 0 AND barristerInvoice.id = barristerInvoiceItems.invoiceId AND `barristers`.`id` = `cases`.`barristerId` AND barristers.titleId = titles.id";

            if($filter['barristerId'] != 'all'){
                $query_string .= " AND `barristerInvoice`.`barristerId` = '".$filter['barristerId']."' ";
            }

            if($filter['status'] != 'all'){
                $query_string .= " AND `barristerInvoice`.`status` = '".$filter['status']."' ";
            }

            if($filter['caseId'] != 'all'){
                if($filter['caseId'] == 'past'){
                    $query_string .= " AND `cases`.`endDate` < CURDATE() ";
                }else if($filter['caseId'] == 'upcoming'){
                    $query_string .= " AND `cases`.`endDate` >= CURDATE() ";
                }else{
                    $query_entry_type = $this->_conn->query("SELECT `entryType` FROM `cases` WHERE `id` = '".$filter['caseId']."'");
                    $row_entry_type = $query_entry_type->fetch_assoc();

                    if($row_entry_type['entryType'] != '0'){
                        $query_string .= " AND (`cases`.`id` = '".$filter['caseId']."' OR FIND_IN_SET(`cases`.`id`, '".$row_entry_type['entryType']."') )  ";
                    }else{
                        $query_string .= " AND `cases`.`id` = '".$filter['caseId']."'  ";
                    }
                }
            }

            if($filter['fundingTypeId'] != 'all'){
                $query_string .= " AND `cases`.`fundingTypeId` = '".$filter['fundingTypeId']."' ";
            }

            $query_string .=  " AND `barristers`.`active` = '1' AND `cases`.`active` = '1' GROUP BY barristerInvoice.id  ";

            switch ($filter['orderBy']) {
                case 'dueDate' : 
                    $query_string .= " ORDER BY barristerInvoice.dueDate";
                break;
                case 'amountLow' :
                    $query_string .= " ORDER BY totalDue ASC";
                    break;
                case 'amountHigh' :
                    $query_string .= " ORDER BY totalDue DESC";
                    break;
                case 'barrister' :
                    $query_string .= " ORDER BY barristerFName";
                    break;
                default:
                    $query_string .= " ORDER BY barristerInvoice.dueDate";
            }

            if($filter['limit'] != 'all'){
                $query_string .= " LIMIT  10";
            }

        }else if($filter['tableName'] == 'solicitor'){

            $query_string = "SELECT solicitorInvoice.*, max(`cases`.`id`) as caseId,`cases`.`barristerId`, CONCAT(`titles`.`name`, ' ', `barristers`.`fname`, ' ', `barristers`.`lname`) as barristerName, `cases`.`clientId`, `cases`.`clientTypeId`, `cases`.`solicitorId`, `cases`.`teamId`, `cases`.`courtRef`, `cases`.`claimant`, `cases`.`defendant`, `cases`.`fundingTypeId`, `cases`.`active`, `solicitorCompany`.companyName, CONCAT(solicitors.fname, ' ', solicitors.lname) as solicitorName,  ( `solicitorInvoice`.`totalAmount` - `solicitorInvoice`.`totalPaid`) as totalDue, SUM(`solicitorInvoiceItems`.`total`) as totalCase FROM solicitorInvoice, cases, solicitorInvoiceItems, barristers, solicitors, solicitorCompany, titles WHERE solicitorInvoiceItems.caseId = cases.id AND `cases`.`barristerId` = `barristers`.`id` AND `barristers`.`titleId` = `titles`.`id` AND solicitorInvoice.id = solicitorInvoiceItems.invoiceId AND `solicitors`.`id` = `cases`.`teamId` AND `solicitorCompany`.`id` = `cases`.`solicitorId`  ";
            
            if($filter['solicitorId'] != 'all'){
                $query_string .= " AND `solicitorCompany`.`id` = '".$filter['solicitorId']."' ";
            }

            if($filter['caseId'] != 'all'){
                if($filter['caseId'] == 'past'){
                    $query_string .= " AND `cases`.`endDate` > CURDATE() ";
                }else if($filter['caseId'] == 'upcoming'){
                    $query_string .= " AND `cases`.`endDate` <= CURDATE() ";
                }else{
                    $query_entry_type = $this->_conn->query("SELECT `entryType` FROM `cases` WHERE `id` = '".$filter['caseId']."'");
                    $row_entry_type = $query_entry_type->fetch_assoc();

                    if($row_entry_type['entryType'] != '0'){
                        $query_string .= " AND (`cases`.`id` = '".$filter['caseId']."' OR FIND_IN_SET(`cases`.`id`, '".$row_entry_type['entryType']."') )  ";
                    }else{
                        $query_string .= " AND `cases`.`id` = '".$filter['caseId']."'  ";
                    }
                }
            }

            if($filter['fundingTypeId'] != 'all'){
                $query_string .= " AND `cases`.`fundingTypeId` = '".$filter['fundingTypeId']."' ";
            }

            if($filter['status'] != 'all'){
                $query_string .= " AND `solicitorInvoice`.`status` = '".$filter['status']."' ";
            }

            $query_string .=  " AND `solicitors`.`active` ='1' AND `cases`.`active` = '1' GROUP BY solicitorInvoice.id ";

            switch ($filter['orderBy']) {
                case 'dueDate' : 
                    $query_string .= " ORDER BY solicitorInvoice.dueDate";
                break;
                case 'amountLow' :
                    $query_string .= " ORDER BY totalDue ASC";
                    break;
                case 'amountHigh' :
                    $query_string .= " ORDER BY totalDue DESC";
                    break;
                case 'solicitor' :
                    $query_string .= " ORDER BY companyName";
                    break;
                default:
                    $query_string .= " ORDER BY solicitorInvoice.dueDate";
            }

            if($filter['limit'] != 'all'){
                $query_string .= " LIMIT  10";
            }

        }else if($filter['tableName'] == 'client'){

            $query_string = "SELECT solicitorInvoice.*, max(`cases`.`id`) as caseId,`cases`.`barristerId`, CONCAT(`titles`.`name`, ' ', `barristers`.`fname`, ' ', `barristers`.`lname`) as barristerName, `cases`.`clientId`, `cases`.`clientTypeId`, `cases`.`solicitorId`, `cases`.`teamId`, `cases`.`courtRef`, `cases`.`claimant`, `cases`.`defendant`, `cases`.`fundingTypeId`, `cases`.`active`,clients.clientFname, CONCAT(clients.clientFname, ' ', clients.clientLname) as solicitorName, ( `solicitorInvoice`.`totalAmount` - `solicitorInvoice`.`totalPaid`) as totalDue, SUM(`solicitorInvoiceItems`.`total`) as totalCase FROM solicitorInvoice, cases, solicitorInvoiceItems, barristers, clients, titles WHERE solicitorInvoiceItems.caseId = cases.id AND `cases`.`barristerId` = `barristers`.`id` AND `barristers`.`titleId` = `titles`.`id` AND solicitorInvoice.id = solicitorInvoiceItems.invoiceId AND `clients`.`id` = `cases`.`clientId`  ";
            
            if($filter['clientId'] != 'all'){
                $query_string .= " AND `solicitorInvoice`.`clientId` = '".$filter['clientId']."' ";
            }

            if($filter['caseId'] != 'all'){
                if($filter['caseId'] == 'past'){
                    $query_string .= " AND `cases`.`endDate` < CURDATE() ";
                }else if($filter['caseId'] == 'upcoming'){
                    $query_string .= " AND `cases`.`endDate` >= CURDATE() ";
                }else{
                    $query_entry_type = $this->_conn->query("SELECT `entryType` FROM `cases` WHERE `id` = '".$filter['caseId']."'");
                    $row_entry_type = $query_entry_type->fetch_assoc();

                    if($row_entry_type['entryType'] != '0'){
                        $query_string .= " AND (`cases`.`id` = '".$filter['caseId']."' OR FIND_IN_SET(`cases`.`id`, '".$row_entry_type['entryType']."') )  ";
                    }else{
                        $query_string .= " AND `cases`.`id` = '".$filter['caseId']."'  ";
                    }
                }
            }

            if($filter['fundingTypeId'] != 'all'){
                $query_string .= " AND `cases`.`fundingTypeId` = '".$filter['fundingTypeId']."' ";
            }

            if($filter['status'] != 'all'){
                $query_string .= " AND `solicitorInvoice`.`status` = '".$filter['status']."' ";
            }

            $query_string .=  " AND `clients`.`active` = '1' AND `cases`.`active` = '1' GROUP BY `solicitorInvoice`.`id`";

            switch ($filter['orderBy']) {
                case 'dueDate' : 
                    $query_string .= " ORDER BY solicitorInvoice.dueDate";
                break;
                case 'amountLow' :
                    $query_string .= " ORDER BY totalDue ASC";
                    break;
                case 'amountHigh' :
                    $query_string .= " ORDER BY totalDue DESC";
                    break;
                case 'client' :
                    $query_string .= " ORDER BY clientFname";
                    break;
                default:
                    $query_string .= " ORDER BY solicitorInvoice.dueDate";
            }

            if($filter['limit'] != 'all'){
                $query_string .= " LIMIT  10";
            }
        }

        $query = $this->_conn->query($query_string);
        $data = [];

        if($query->num_rows > 0){

            while($row = $query->fetch_assoc()){

                switch ($row['status']) {
                    case '0' :
                        $statusColor = 'danger';
                        $statusText = "Pending";
                        break;

                    case '1' : 
                        $statusColor = 'primary';
                        $statusText = 'Closed';
                        break;

                    case '2' :
                        $statusColor = 'info';
                        $statusText = 'Disputed';
                        break;

                    default :
                        $statusColor = 'danger';
                        $statusText = 'Pending';
                        break;
                }

                $row['statusColor'] = $statusColor;
                $row['statusText'] = $statusText;

                $data[] = $row;

            }

            if(count($data) > 0){
                $this->_res = ['status'=>'ok', 'message'=>$query_string, 'data'=>$data];
            }else{
                $this->_res = ['status'=>'error', 'message'=>'No Invoice Found !', 'data'=>null];
            }

        }else{
            $this->_res = ['status'=>'error', 'message'=>'No Invoice Found', 'data'=>null];
        }
        return $this->_res;

    }

    public function getInvoice($filter){

        if($filter['tableName'] == 'client'){
            $filter['tableName'] = 'solicitor';
        }
        $tableName = $filter['tableName'].'Invoice';
        $tableNameItems = $filter['tableName'].'InvoiceItems';

        $query_string = "SELECT `".$tableName."`.* FROM `".$tableName."` WHERE `".$tableName."`.`id` = '".$filter['id']."' ";

        $query = $this->_conn->query($query_string);

        $data = [];
        if($query->num_rows == 1){
            $row = $query->fetch_assoc();

            $query_cases = $this->_conn->query("SELECT  `cases`.`id`, `cases`.`entryType`, `cases`.`solicitorRef`, `cases`.`claimant`, `cases`.`defendant`, `cases`.`courtRef`, `cases`.`clientTypeId`,`cases`.`courtDate`,  `cases`.`endDate`,  `caseTypes`.`name` as caseTypeName, `fundingTypes`.`name` as fundingTypeName, `courts`.`courtName`, CONCAT(`titles`.`name`, ' ', `barristers`.`fname`, ' ', `barristers`.`lname`) as barristerName, `barristers`.`vatNo`, `barristers`.`legalAidNumber` FROM `cases`, `barristers`, `caseTypes`, `fundingTypes`, `courts`, `titles` WHERE  `cases`.`id` = '".$filter['caseId']."' AND `cases`.`barristerId` = `barristers`.`id` AND `cases`.`courtId` = `courts`.`id` AND `cases`.`caseTypeId` = `caseTypes`.`id` AND `cases`.`fundingTypeId` = `fundingTypes`.`id` AND `barristers`.`titleId` = `titles`.`id` AND `cases`.`active` = '1'");
            $row_case = $query_cases->fetch_assoc();

            $row = array_merge($row, $row_case);

            if($row['clientTypeId'] == 'Solicitor'){

                $query_solicitors = $this->_conn->query("SELECT CONCAT(`titles`.`name`, ' ', `solicitors`.`fname`,' ', `solicitors`.`lname`) as solicitorName, `solicitorCompany`.`companyName`, `solicitorCompany`.`address`, `solicitorCompany`.`address1`, `solicitorCompany`.`city`, `solicitorCompany`.`postcode` FROM `solicitors`, `solicitorCompany`, `titles` WHERE `solicitors`.`id` = '".$row['teamId']."' AND `solicitors`.`companyId` = `solicitorCompany`.`id` AND `solicitors`.`titleId` = `titles`.`id`");
                $row_solicitors = $query_solicitors->fetch_assoc();
                $row['solicitor'] = $row_solicitors;

            }else{

                $query_client = $this->_conn->query("SELECT CONCAT(`titles`.`name`, ' ', `clients`.`clientFname`, ' ', `clients`.`clientLname`) as clientName, `clients`.`clientAddress`, `clients`.`clientPostcode` FROM `clients`, `titles` WHERE `clients`.`id` = '".$row['clientId']."' and `clients`.`clientTitle` = `titles`.`id`");
                $row_client = $query_client->fetch_assoc();
                $row['client'] = $row_client;

            }

            switch ($row['status']) {

                case '0' :
                    $statusColor = 'danger';
                    $statusText = "Pending";
                    break;

                case '1' : 
                    $statusColor = 'primary';
                    $statusText = 'Closed';
                    break;

                case '2' :
                    $statusColor = 'info';
                    $statusText = 'Disputed';
                    break;

                default :
                    $statusColor = 'dander';
                    $statusText = 'Pending';
                    break;

            }

            $row['statusColor'] = $statusColor;
            $row['statusText'] = $statusText;
            
            //invoiceTable and payment Table 
            $invoiceTable = $filter['tableName'].'Invoice';
            $invoiceItemTable = $filter['tableName'].'InvoiceItems';
            $paymentTable = $filter['tableName'].'Payments';

            if($row_case['entryType'] != 0){
                $query_payments_string = "SELECT * FROM ( SELECT  `".$invoiceItemTable."`.`id`, `".$invoiceItemTable."`.`invoiceId`, `".$invoiceItemTable."`.`details`, `".$invoiceItemTable."`.`amount`, `".$invoiceItemTable."`.`vat` as vat, `".$invoiceItemTable."`.`total` as total, `".$invoiceItemTable."`.`dueDate`, 'charge' as invoiceType,  `cases`.`courtDate`, `cases`.`endDate`  FROM `".$invoiceItemTable."`, `".$invoiceTable."`, `cases`  WHERE `".$invoiceItemTable."`.`invoiceId` = '".$filter['id']."' AND `".$invoiceItemTable."`.`invoiceId` = `".$invoiceTable."`.`id` AND `".$invoiceItemTable."`.`caseId` = `cases`.`id` AND (`cases`.`id` = '".$row_case['id']."' OR FIND_IN_SET(`cases`.`id`,  '".$row_case['entryType']."')) AND `".$invoiceItemTable."`.`active` = 1 UNION SELECT `".$paymentTable."`.`id`, `".$paymentTable."`.`invoiceId`, CONCAT(`".$paymentTable."`.`note`, ' | Paid By : ', `".$paymentTable."`.`paymentMethod`) as details, `".$paymentTable."`.`paymentAmount` as amount, `".$paymentTable."`.`vatAmount` as vat, `".$paymentTable."`.`totalAmount` as total, `".$paymentTable."`.`paymentDate` as dueDate, 'payment' as invoiceType, `cases`.`courtDate`, `cases`.`endDate` FROM `".$paymentTable."`, `".$invoiceItemTable."`, `cases` WHERE `".$paymentTable."`.`invoiceId` = '".$filter['id']."' AND `".$paymentTable."`.`invoiceId` =  `".$invoiceItemTable."`.`invoiceId` AND `cases`.`id` =  `".$invoiceItemTable."`.`caseId` AND (`cases`.`id` = '".$row_case['id']."' OR FIND_IN_SET(`cases`.`id`,  '".$row_case['entryType']."')) AND `".$invoiceItemTable."`.`active` = 1  GROUP BY `".$paymentTable."`.`id`) x ORDER BY dueDate";
            }else{
                $query_payments_string = "SELECT * FROM ( SELECT  `".$invoiceItemTable."`.`id`, `".$invoiceItemTable."`.`invoiceId`, `".$invoiceItemTable."`.`details`, `".$invoiceItemTable."`.`amount`, `".$invoiceItemTable."`.`vat` as vat, `".$invoiceItemTable."`.`total` as total, `".$invoiceItemTable."`.`dueDate`, 'charge' as invoiceType,  `cases`.`courtDate`, `cases`.`endDate`  FROM `".$invoiceItemTable."`, `".$invoiceTable."`, `cases`  WHERE `".$invoiceItemTable."`.`invoiceId` = '".$filter['id']."' AND `".$invoiceItemTable."`.`invoiceId` = `".$invoiceTable."`.`id` AND `".$invoiceItemTable."`.`caseId` = `cases`.`id` AND `cases`.`id` = '".$row_case['id']."' AND `".$invoiceItemTable."`.`active` = 1 UNION SELECT `".$paymentTable."`.`id`, `".$paymentTable."`.`invoiceId`, CONCAT(`".$paymentTable."`.`note`, ' | Paid By : ', `".$paymentTable."`.`paymentMethod`) as details, `".$paymentTable."`.`paymentAmount` as amount, `".$paymentTable."`.`vatAmount` as vat, `".$paymentTable."`.`totalAmount` as total, `".$paymentTable."`.`paymentDate` as dueDate, 'payment' as invoiceType, `cases`.`courtDate`, `cases`.`endDate` FROM `".$paymentTable."`, `".$invoiceItemTable."`, `cases` WHERE `".$paymentTable."`.`invoiceId` = '".$filter['id']."' AND `".$paymentTable."`.`invoiceId` =  `".$invoiceItemTable."`.`invoiceId` AND `cases`.`id` =  `".$invoiceItemTable."`.`caseId` AND `cases`.`id` = '".$row_case['id']."' AND `".$invoiceItemTable."`.`active` = 1 GROUP BY `".$paymentTable."`.`id`) x ORDER BY dueDate";
            }


            $query_payments = $this->_conn->query($query_payments_string);
            $payments = [];

            $totalAmount = 0.00;
            $totalVat = 0.00;
            $totalDue = 0.00;

            while($row_payments = $query_payments->fetch_assoc()){
        
                if($row_payments['invoiceType'] == 'charge'){
                    $totalDue = $totalDue + $row_payments['total'];
                    $totalAmount = $totalAmount + $row_payments['amount'];
                    $totalVat = $totalVat + $row_payments['vat'];

                }else{
                    $totalDue = $totalDue - $row_payments['total'];
                    $totalAmount = $totalAmount - $row_payments['amount'];
                    $totalVat = $totalVat - $row_payments['vat'];
                }

                $payments[] = $row_payments;    
            }

            $row['payments'] = $payments;
            // $row['payments'] = $query_payments_string;
            $balance = [];
            $balance['totalAmount'] = $totalAmount;
            $balance['totalVat'] = $totalVat;
            $balance['totalDue'] = $totalDue;
            $row['balance'] = $balance;

            $this->_res = ['status'=>'ok', 'message'=>$query_payments_string, 'data'=>$row];

        }else{
            $this->_res = ['status'=>'error', 'message'=>$query_string, 'data'=>$query_payments_string];
        }
        return $this->_res;
    }

    public function savePayment($data){

        if($data['tableName'] == 'client'){
            $data['tableName'] = 'solicitor';
        }

        $invoiceTable = $data['tableName'].'Invoice';
        $invoiceTableItems = $data['tableName'].'InvoiceItems';
        $paymentTable = $data['tableName'].'Payments';
        $string_query = "SELECT `totalAmount`, `totalPaid`, (`totalAmount`- `totalPaid`) as balanceDue FROM `".$invoiceTable."` WHERE `id` = '".$data['invoiceId']."' ";
        $query_invoice = $this->_conn->query($string_query);

        if($query_invoice->num_rows == 1){

            $row_invoice = $query_invoice->fetch_assoc();
            $balanceDue = $row_invoice['balanceDue'];

            //get case id and vat
            $query_vat = $this->_conn->query("SELECT `cases`.`id`, `cases`.`vat`  FROM `cases`, `".$invoiceTableItems."` WHERE `".$invoiceItemTable."`.`invoiceId` = '".$data['invoiceId']."' AND `".$invoiceTableItems."`.`caseId` = `cases`.`id` GROUP BY `cases`.`id`");
            $row_vat = $query_vat->fetch_assoc();

            $vatDivision = 1 + ($row_vat['vat'] / 100);
            $paymentBeforeVat = $data['amount'] / $vatDivision;
            $vatAmount = $data['amount'] - $paymentBeforeVat;

            $query_insert = $this->_conn->query("INSERT INTO `".$paymentTable."` (`invoiceId`, `paymentAmount`, `vatAmount`, `totalAmount`, `paymentMethod`, `note`, `paymentDate`, `addedBy`) VALUES('".$data['invoiceId']."','".$paymentBeforeVat."', '".$vatAmount."', '".$data['amount']."', '".$data['paymentMethod']."', '".$data['details']."','".$data['paymentDate']."', '".$this->_userId."')");
            if($query_insert){
                $payment_id = $this->_conn->insert_id;
                //update the invoice
                if($balanceDue <= $data['amount']){
                    $status = '1';
                }else{
                    $status = '0';
                }

                $query_update = $this->_conn->query("UPDATE `".$invoiceTable."` SET `totalPaid` = `totalPaid` + '".$data['amount']."', `status` = '".$status."' WHERE `id`= '".$data['invoiceId']."'");
                if($query_update){
                    $this->_res = ['status'=>'ok', 'message'=>'Payment saved, Invoice updated!', 'data'=>null];
                }else{
                    //remove payment
                    $this->_conn->query("DELETE FROM `".$paymentTable."` WHERE `id` = '".$payment_id."'");
                    $this->_res = ['status'=>'error', 'message'=>'Could not update invoice, Internal server error!', 'data'=>null];
                }

            }else{
                $this->_res = ['status'=>'error', 'message'=>'Could not save payment, Internal server error!', 'data'=>null];
            }
            
        }else{
            $this->_res = ['status'=>'error', 'message'=>'No invoice found to add payment!', 'data'=>$string_query];
        }
        return $this->_res;
    }

    public function removePayment($data){

        if($data['tableName'] == 'client'){
            $data['tableName'] = 'solicitor';
        }

        $tableName = $data['tableName'].'Invoice';
        $tablePayment = $data['tableName'].'Payments';
        $query_auth = $this->_conn->query("SELECT `password` FROM `users` WHERE `id` = '".$this->_userId."'");
        $row_auth = $query_auth->fetch_assoc();
        $password = md5($data['password']);

        if($password == $row_auth['password']){

            $query_check = $this->_conn->query("SELECT `invoiceId`, `totalAmount` FROM `".$tablePayment."` WHERE `id` = '".$data['id']."'");
            $row_check = $query_check->fetch_assoc();
            //remove payments

            $query_delete = $this->_conn->query("DELETE FROM `".$tablePayment."` WHERE `id` = '".$data['id']."'");

            if($query_delete){
                //update invoice
                $query_update = $this->_conn->query("UPDATE `".$tableName."` SET `totalPaid` = `totalPaid` - '".$row_check['totalAmount']."', `status`= '0' WHERE `id` = '".$row_check['invoiceId']."'");

                if($query_update){

                    $this->_res = ['status'=>'ok', 'message'=>'Payment record deleted!', 'data'=>null];

                }else{
                    $this->_res = ['status'=>'ok', 'message'=>'Payment record deleted but could not update Invoice!', 'data'=>null];
                }

            }else{
                $this->_res = ['status'=>'error', 'message'=>'Could not delete payment record!', 'data'=>null];
            }
        }else{
            $this->_res = ['status'=>'error', 'message'=>'Authorisation failed. Password did not match!', 'data'=>null];
        }

        return $this->_res;

    }

}

?>