public function getJournalEntriesGroupedByPlBsCategoryByOrganizationAndByFiscalYear($plBsCategory, $organizationId, $fiscalYearId, $databaseConnectionName = null)
  {
    // $this->DB->connection()->enableQueryLog();

    // $Entries = $this->DB->table('ACCT_Journal_Entry AS je')
    //     				->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')
    //     				->join('ACCT_Period AS p', 'p.id', '=', 'jv.period_id')
    //             ->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id')
    //     				->join('ACCT_Account_Type AS at', 'at.id', '=', 'c.account_type_id')
    //     				->where('jv.status', '=', 'B')
    //     				->where('jv.organization_id', '=', $organizationId)
    //     				->where('p.fiscal_year_id', '=', $fiscalYearId)
    //     				// ->where('c.is_group', '=', 0)
    //     				->where('at.pl_bs_category', '=', $plBsCategory)
    //     				->whereNull('je.deleted_at')
    //     				->whereNull('jv.deleted_at')
    //             // ->groupBy('journal_voucher_id', 'je.cost_center_id', 'je.account_id')
    //             ->groupBy('journal_voucher_id', 'je.cost_center_id', 'je.account_id')
    //             ->select(array($this->DB->raw('SUM(je.debit) as debit'), $this->DB->raw('SUM(je.credit) as credit'),
    //                     //  $this->DB->raw("$journalVoucherId AS journal_voucher_id"), 'je.cost_center_id', 'je.account_id'
    //                      $this->DB->raw("$journalVoucherId AS journal_voucher_id"), 'je.cost_center_id', 'je.account_id'
    //                   )
    //                   )->get();

    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }

    return $this->DB->connection($databaseConnectionName)
            ->table('ACCT_Journal_Entry AS je')
        		->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')
            ->join('ACCT_Account AS c', 'c.id', '=', 'je.account_id')
            ->join('ACCT_Period AS p', 'p.id', '=', 'jv.period_id')
            ->join('ACCT_Account_Type AS at', 'at.id', '=', 'c.account_type_id')
        		->where('jv.organization_id', '=', $organizationId)
            ->where('p.fiscal_year_id', '=', $fiscalYearId)
            ->where('jv.status', '=', 'B')
            ->whereIn('at.pl_bs_category', $plBsCategory)
            ->whereNull('je.deleted_at')
            ->whereNull('jv.deleted_at')
            ->groupBy('je.cost_center_id', 'je.account_id', 'c.balance_type')
            ->select(array($this->DB->raw('SUM(je.debit) as debit'), $this->DB->raw('SUM(je.credit) as credit'), 'je.cost_center_id', 'je.account_id', 'c.balance_type'))
            ->get();

    // var_dump($this->DB->getQueryLog(), $Entries);die();
  }
public function getJournalEntriesGroupedByPlBsCategoryByOrganizationAndByFiscalYear($plBsCategory, $organizationId, $fiscalYearId, $databaseConnectionName = null)
  {
    // $this->DB->connection()->enableQueryLog();

    // $Entries = $this->DB->table('ACCT_Journal_Entry AS je')
    //     				->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')
    //     				->join('ACCT_Period AS p', 'p.id', '=', 'jv.period_id')
    //             ->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id')
    //     				->join('ACCT_Account_Type AS at', 'at.id', '=', 'c.account_type_id')
    //     				->where('jv.status', '=', 'B')
    //     				->where('jv.organization_id', '=', $organizationId)
    //     				->where('p.fiscal_year_id', '=', $fiscalYearId)
    //     				// ->where('c.is_group', '=', 0)
    //     				->where('at.pl_bs_category', '=', $plBsCategory)
    //     				->whereNull('je.deleted_at')
    //     				->whereNull('jv.deleted_at')
    //             // ->groupBy('journal_voucher_id', 'je.cost_center_id', 'je.account_id')
    //             ->groupBy('journal_voucher_id', 'je.cost_center_id', 'je.account_id')
    //             ->select(array($this->DB->raw('SUM(je.debit) as debit'), $this->DB->raw('SUM(je.credit) as credit'),
    //                     //  $this->DB->raw("$journalVoucherId AS journal_voucher_id"), 'je.cost_center_id', 'je.account_id'
    //                      $this->DB->raw("$journalVoucherId AS journal_voucher_id"), 'je.cost_center_id', 'je.account_id'
    //                   )
    //                   )->get();

    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }

    return $this->DB->connection($databaseConnectionName)
            ->table('ACCT_Journal_Entry AS je')
        		->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id')
            ->join('ACCT_Account AS c', 'c.id', '=', 'je.account_id')
            ->join('ACCT_Period AS p', 'p.id', '=', 'jv.period_id')
            ->join('ACCT_Account_Type AS at', 'at.id', '=', 'c.account_type_id')
        		->where('jv.organization_id', '=', $organizationId)
            ->where('p.fiscal_year_id', '=', $fiscalYearId)
            ->where('jv.status', '=', 'B')
            ->whereIn('at.pl_bs_category', $plBsCategory)
            ->whereNull('je.deleted_at')
            ->whereNull('jv.deleted_at')
            ->groupBy('je.cost_center_id', 'je.account_id', 'c.balance_type')
            ->select(array($this->DB->raw('SUM(je.debit) as debit'), $this->DB->raw('SUM(je.credit) as credit'), 'je.cost_center_id', 'je.account_id', 'c.balance_type'))
            ->get();

    // var_dump($this->DB->getQueryLog(), $Entries);die();
  }
public function getJournalEntriesGroupedByPlBsCategoryByOrganizationAndByFiscalYear ( $ plBsCategory , $ organizationId , $ fiscalYearId , $ databaseConnectionName = null ) { // $this->DB->connection()->enableQueryLog(); // $Entries = $this->DB->table('ACCT_Journal_Entry AS je') //     				->join('ACCT_Journal_Voucher AS jv', 'jv.id', '=', 'je.journal_voucher_id') //     				->join('ACCT_Period AS p', 'p.id', '=', 'jv.period_id') //             ->join('ACCT_Account AS c', 'je.account_id', '=', 'c.id') //     				->join('ACCT_Account_Type AS at', 'at.id', '=', 'c.account_type_id') //     				->where('jv.status', '=', 'B') //     				->where('jv.organization_id', '=', $organizationId) //     				->where('p.fiscal_year_id', '=', $fiscalYearId) //     				// ->where('c.is_group', '=', 0) //     				->where('at.pl_bs_category', '=', $plBsCategory) //     				->whereNull('je.deleted_at') //     				->whereNull('jv.deleted_at') //             // ->groupBy('journal_voucher_id', 'je.cost_center_id', 'je.account_id') //             ->groupBy('journal_voucher_id', 'je.cost_center_id', 'je.account_id') //             ->select(array($this->DB->raw('SUM(je.debit) as debit'), $this->DB->raw('SUM(je.credit) as credit'), //                     //  $this->DB->raw("$journalVoucherId AS journal_voucher_id"), 'je.cost_center_id', 'je.account_id' //                      $this->DB->raw("$journalVoucherId AS journal_voucher_id"), 'je.cost_center_id', 'je.account_id' //                   ) //                   )->get(); if ( empty ( $ databaseConnectionName ) ) { $ databaseConnectionName = $ this -> databaseConnectionName ; } return $ this -> DB -> connection ( $ databaseConnectionName ) -> table ( 'ACCT_Journal_Entry AS je' ) -> join ( 'ACCT_Journal_Voucher AS jv' , 'jv.id' , '=' , 'je.journal_voucher_id' ) -> join ( 'ACCT_Account AS c' , 'c.id' , '=' , 'je.account_id' ) -> join ( 'ACCT_Period AS p' , 'p.id' , '=' , 'jv.period_id' ) -> join ( 'ACCT_Account_Type AS at' , 'at.id' , '=' , 'c.account_type_id' ) -> where ( 'jv.organization_id' , '=' , $ organizationId ) -> where ( 'p.fiscal_year_id' , '=' , $ fiscalYearId ) -> where ( 'jv.status' , '=' , 'B' ) -> whereIn ( 'at.pl_bs_category' , $ plBsCategory ) -> whereNull ( 'je.deleted_at' ) -> whereNull ( 'jv.deleted_at' ) -> groupBy ( 'je.cost_center_id' , 'je.account_id' , 'c.balance_type' ) -> select ( array ( $ this -> DB -> raw ( 'SUM(je.debit) as debit' ) , $ this -> DB -> raw ( 'SUM(je.credit) as credit' ) , 'je.cost_center_id' , 'je.account_id' , 'c.balance_type' ) ) -> get ( ) ; // var_dump($this->DB->getQueryLog(), $Entries);die(); }
Get the credit sum of all entries of a journal voucher

@param  int $id Journal Voucher id

@return array of stdClass
Get the credit sum of all entries of a journal voucher