frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register
Hello m'Managerians !
What do you think m'Manager 2.0 should be ? What features SHOULD or MUST be implemented right now ! Request or Vote here

Income by client showing 0

edited March 2018 in Bugs Report

Hi there,

Here is a fix for Income by client showing 0. Navigate to
application/helpers/functions_helper.php and locate
function income_by_client($id, $interval=null)
Replace code with this one

function income_by_client($id, $interval=null)
{
    global $db;
    switch ($interval) {
        case 'this_month':
            $query = "SELECT client_id AS clientID,
                SUM(CASE WHEN invoice_status = 'Paid'
                    THEN amount_paid ELSE 0 End) - 
                SUM(CASE WHEN invoice_status = 'Refunded'
                    THEN amount_due ELSE 0 End) AS TotalPaid
                FROM {$db->tables['invoices']}
                WHERE MONTH(date_paid) = MONTH(CURRENT_TIMESTAMP) 
                AND YEAR(date_paid) = YEAR(CURRENT_TIMESTAMP)
                AND client_id={$id}";
            return $db->get_row($query)->TotalPaid;
            break;
        case 'last_month':
            $query = "SELECT client_id AS clientID,
                SUM(CASE WHEN invoice_status = 'Paid'
                    THEN amount_paid ELSE 0 End) - 
                SUM(CASE WHEN invoice_status = 'Refunded'
                    THEN amount_due ELSE 0 End) AS TotalPaid
                FROM {$db->tables['invoices']}
                WHERE MONTH(date_paid) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH ) 
                AND YEAR(date_paid) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH )
                AND client_id={$id}";
            return $db->get_row($query)->TotalPaid;
            break;
        case 'latest_three_months':
            $query = "SELECT client_id AS clientID,
                SUM(CASE WHEN invoice_status = 'Paid'
                    THEN amount_paid ELSE 0 End) - 
                SUM(CASE WHEN invoice_status = 'Refunded'
                    THEN amount_due ELSE 0 End) AS TotalPaid
                FROM {$db->tables['invoices']}
                WHERE date_paid >= last_day(NOW()) + INTERVAL 1 DAY - INTERVAL 3 MONTH
                AND client_id={$id}";
            return $db->get_row($query)->TotalPaid;
            break;
        case 'this_year':
            $query = "SELECT client_id AS clientID,
                SUM(CASE WHEN invoice_status = 'Paid'
                    THEN amount_paid ELSE 0 End) - 
                SUM(CASE WHEN invoice_status = 'Refunded'
                    THEN amount_due ELSE 0 End) AS TotalPaid
                FROM {$db->tables['invoices']}
                WHERE YEAR(date_paid) = YEAR(CURRENT_TIMESTAMP)
                AND client_id={$id}";
            return $db->get_row($query)->TotalPaid;
            break;
        case 'last_year':
            $query = "SELECT client_id AS clientID,
                SUM(CASE WHEN invoice_status = 'Paid'
                    THEN amount_paid ELSE 0 End) - 
                SUM(CASE WHEN invoice_status = 'Refunded'
                    THEN amount_due ELSE 0 End) AS TotalPaid
                FROM {$db->tables['invoices']}
                WHERE YEAR(date_paid) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))
                AND client_id={$id}";
            return $db->get_row($query)->TotalPaid;
            break;
        case 'all_dates':
            $query = "SELECT client_id AS clientID,
                SUM(CASE WHEN invoice_status = 'Paid'
                    THEN amount_paid ELSE 0 End) - 
                SUM(CASE WHEN invoice_status = 'Refunded'
                    THEN amount_due ELSE 0 End) AS TotalPaid
                FROM {$db->tables['invoices']}
                WHERE YEAR(date_paid) IS NOT NULL
                AND client_id={$id}";
            return $db->get_row($query)->TotalPaid;
            break;
        default:
            $query = "SELECT client_id AS clientID,
                SUM(CASE WHEN invoice_status = 'Paid'
                    THEN amount_paid ELSE 0 End) - 
                SUM(CASE WHEN invoice_status = 'Refunded'
                    THEN amount_due ELSE 0 End) AS TotalPaid
                FROM {$db->tables['invoices']}
                WHERE MONTH(date_paid) = MONTH(CURRENT_TIMESTAMP) 
                AND YEAR(date_paid) = YEAR(CURRENT_TIMESTAMP)
                AND client_id={$id}";
            return $db->get_row($query)->TotalPaid;
            break;
    }
}

Then open application/libraries/M_manager.php and locate public function credit_note_invoice( $invoice_number )
Update last lines to look like this:

'invoice_status'        => 'Refunded',
'date_paid'             => $invoice->date_paid,
'sent'              => 'no',

If you have already generated credit note, don't worry. Open phpmyadmin, go to oc_invoices, find the refunded invoice and set the appropriate date so that it does not show null.
Feel free to contact me if you need help.

Thanks
Eric

This discussion has been closed.

m'Manager

| Let's Build Together a Great App !
If you are a happy user, send me a coffee.
2015 - 2107 © m'Manager.
Powered by VanillaForums, Designed by ThemeSteam

Recent Donations

  • Joni Mueller from https://pixelita.com/ - 63€
  • HeyrmanD from https://locco-palace.be - 25€
  • Patricia from Sjopz.com - 10€
  • AskinSavascisi from wolftech.com - 3€
  • Get In Touch