mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 05:27:33 -05:00 
			
		
		
		
	Fixes for chart queries
This commit is contained in:
		
							parent
							
								
									9668f6ceb7
								
							
						
					
					
						commit
						a66c9cc046
					
				@ -35,12 +35,8 @@ class ChartService
 | 
				
			|||||||
        $currencies = Client::withTrashed()
 | 
					        $currencies = Client::withTrashed()
 | 
				
			||||||
            ->where('company_id', $this->company->id)
 | 
					            ->where('company_id', $this->company->id)
 | 
				
			||||||
            ->where('is_deleted', 0)
 | 
					            ->where('is_deleted', 0)
 | 
				
			||||||
            ->distinct();
 | 
					            ->distinct()
 | 
				
			||||||
 | 
					            ->pluck('settings->currency_id as id');
 | 
				
			||||||
            if(!$this->is_admin)
 | 
					 | 
				
			||||||
                $currencies->where('user_id', $this->user->id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $currencies->pluck('settings->currency_id as id');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Push the company currency on also */
 | 
					        /* Push the company currency on also */
 | 
				
			||||||
        $currencies->push((int) $this->company->settings->currency_id);
 | 
					        $currencies->push((int) $this->company->settings->currency_id);
 | 
				
			||||||
@ -49,14 +45,8 @@ class ChartService
 | 
				
			|||||||
        $expense_currencies = Expense::withTrashed()
 | 
					        $expense_currencies = Expense::withTrashed()
 | 
				
			||||||
            ->where('company_id', $this->company->id)
 | 
					            ->where('company_id', $this->company->id)
 | 
				
			||||||
            ->where('is_deleted', 0)
 | 
					            ->where('is_deleted', 0)
 | 
				
			||||||
            ->distinct();
 | 
					            ->distinct()
 | 
				
			||||||
 | 
					            ->pluck('currency_id as id');
 | 
				
			||||||
            
 | 
					 | 
				
			||||||
        if (!$this->is_admin) {
 | 
					 | 
				
			||||||
            $expense_currencies->where('user_id', $this->user->id);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        $expense_currencies->pluck('currency_id as id');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Merge and filter by unique */
 | 
					        /* Merge and filter by unique */
 | 
				
			||||||
        $currencies = $currencies->merge($expense_currencies)->unique();
 | 
					        $currencies = $currencies->merge($expense_currencies)->unique();
 | 
				
			||||||
 | 
				
			|||||||
@ -50,7 +50,7 @@ class ChartCurrencyTest extends TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $this->assertDatabaseHas('invoices', ['number' => 'db_record']);
 | 
					        $this->assertDatabaseHas('invoices', ['number' => 'db_record']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $cs = new ChartService($this->company);
 | 
					        $cs = new ChartService($this->company, $this->user, true);
 | 
				
			||||||
        // nlog($cs->getRevenueQuery(now()->subDays(20)->format('Y-m-d'), now()->addDays(100)->format('Y-m-d')));
 | 
					        // nlog($cs->getRevenueQuery(now()->subDays(20)->format('Y-m-d'), now()->addDays(100)->format('Y-m-d')));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $data = [
 | 
					        $data = [
 | 
				
			||||||
@ -86,7 +86,7 @@ class ChartCurrencyTest extends TestCase
 | 
				
			|||||||
            'settings' => $settings,
 | 
					            'settings' => $settings,
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $cs = new ChartService($this->company);
 | 
					        $cs = new ChartService($this->company, $this->user, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->assertTrue(is_array($cs->getCurrencyCodes()));
 | 
					        $this->assertTrue(is_array($cs->getCurrencyCodes()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -131,7 +131,7 @@ class ChartCurrencyTest extends TestCase
 | 
				
			|||||||
            ],
 | 
					            ],
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $cs = new ChartService($this->company);
 | 
					        $cs = new ChartService($this->company, $this->user, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // nlog($cs->totals(now()->subYears(10), now()));
 | 
					        // nlog($cs->totals(now()->subYears(10), now()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user