mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-30 20:22:58 -04:00 
			
		
		
		
	Improve tax report #1351
This commit is contained in:
		
							parent
							
								
									c2bf1b6a04
								
							
						
					
					
						commit
						556a90c8ef
					
				| @ -2,12 +2,13 @@ | ||||
| 
 | ||||
| namespace App\Ninja\Reports; | ||||
| 
 | ||||
| use Auth; | ||||
| use App\Models\Client; | ||||
| use Auth; | ||||
| 
 | ||||
| class TaxRateReport extends AbstractReport | ||||
| { | ||||
|     public $columns = [ | ||||
|         'invoice', | ||||
|         'tax_name', | ||||
|         'tax_rate', | ||||
|         'amount', | ||||
| @ -22,7 +23,10 @@ class TaxRateReport extends AbstractReport | ||||
|                         ->withArchived() | ||||
|                         ->with('contacts') | ||||
|                         ->with(['invoices' => function ($query) { | ||||
|                             $query->with('invoice_items')->withArchived(); | ||||
|                             $query->with('invoice_items') | ||||
|                                 ->withArchived() | ||||
|                                 ->invoices() | ||||
|                                 ->where('is_public', '=', true); | ||||
|                             if ($this->options['date_field'] == FILTER_INVOICE_DATE) { | ||||
|                                 $query->where('invoice_date', '>=', $this->startDate) | ||||
|                                       ->where('invoice_date', '<=', $this->endDate) | ||||
| @ -43,11 +47,10 @@ class TaxRateReport extends AbstractReport | ||||
| 
 | ||||
|         foreach ($clients->get() as $client) { | ||||
|             $currencyId = $client->currency_id ?: Auth::user()->account->getCurrencyId(); | ||||
|             $amount = 0; | ||||
|             $paid = 0; | ||||
|             $taxTotals = []; | ||||
| 
 | ||||
|             foreach ($client->invoices as $invoice) { | ||||
|                 $taxTotals = []; | ||||
| 
 | ||||
|                 foreach ($invoice->getTaxes(true) as $key => $tax) { | ||||
|                     if (! isset($taxTotals[$currencyId])) { | ||||
|                         $taxTotals[$currencyId] = []; | ||||
| @ -60,22 +63,20 @@ class TaxRateReport extends AbstractReport | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 $amount += $invoice->amount; | ||||
|                 $paid += $invoice->getAmountPaid(); | ||||
|             } | ||||
| 
 | ||||
|                 foreach ($taxTotals as $currencyId => $taxes) { | ||||
|                     foreach ($taxes as $tax) { | ||||
|                         $this->data[] = [ | ||||
|                             $invoice->present()->link, | ||||
|                             $tax['name'], | ||||
|                             $tax['rate'] . '%', | ||||
|                             $account->formatMoney($tax['amount'], $client), | ||||
|                         $account->formatMoney($tax['paid'], $client) | ||||
|                             $account->formatMoney($tax['paid'], $client), | ||||
|                         ]; | ||||
|                     } | ||||
| 
 | ||||
|                 $this->addToTotals($client->currency_id, 'amount', $tax['amount']); | ||||
|                 $this->addToTotals($client->currency_id, 'paid', $tax['paid']); | ||||
|                     $this->addToTotals($client->currency_id, 'amount', $invoice->amount); | ||||
|                     $this->addToTotals($client->currency_id, 'paid', $invoice->getAmountPaid()); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user