mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:37:33 -05:00 
			
		
		
		
	Improve tax report #1351
This commit is contained in:
		
							parent
							
								
									a43b613e10
								
							
						
					
					
						commit
						6a28fc52ad
					
				@ -8,6 +8,7 @@ use Auth;
 | 
				
			|||||||
class TaxRateReport extends AbstractReport
 | 
					class TaxRateReport extends AbstractReport
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public $columns = [
 | 
					    public $columns = [
 | 
				
			||||||
 | 
					        'invoice',
 | 
				
			||||||
        'tax_name',
 | 
					        'tax_name',
 | 
				
			||||||
        'tax_rate',
 | 
					        'tax_rate',
 | 
				
			||||||
        'amount',
 | 
					        'amount',
 | 
				
			||||||
@ -22,7 +23,10 @@ class TaxRateReport extends AbstractReport
 | 
				
			|||||||
                        ->withArchived()
 | 
					                        ->withArchived()
 | 
				
			||||||
                        ->with('contacts')
 | 
					                        ->with('contacts')
 | 
				
			||||||
                        ->with(['invoices' => function ($query) {
 | 
					                        ->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) {
 | 
					                            if ($this->options['date_field'] == FILTER_INVOICE_DATE) {
 | 
				
			||||||
                                $query->where('invoice_date', '>=', $this->startDate)
 | 
					                                $query->where('invoice_date', '>=', $this->startDate)
 | 
				
			||||||
                                      ->where('invoice_date', '<=', $this->endDate)
 | 
					                                      ->where('invoice_date', '<=', $this->endDate)
 | 
				
			||||||
@ -43,11 +47,10 @@ class TaxRateReport extends AbstractReport
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        foreach ($clients->get() as $client) {
 | 
					        foreach ($clients->get() as $client) {
 | 
				
			||||||
            $currencyId = $client->currency_id ?: Auth::user()->account->getCurrencyId();
 | 
					            $currencyId = $client->currency_id ?: Auth::user()->account->getCurrencyId();
 | 
				
			||||||
            $amount = 0;
 | 
					 | 
				
			||||||
            $paid = 0;
 | 
					 | 
				
			||||||
            $taxTotals = [];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            foreach ($client->invoices as $invoice) {
 | 
					            foreach ($client->invoices as $invoice) {
 | 
				
			||||||
 | 
					                $taxTotals = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach ($invoice->getTaxes(true) as $key => $tax) {
 | 
					                foreach ($invoice->getTaxes(true) as $key => $tax) {
 | 
				
			||||||
                    if (! isset($taxTotals[$currencyId])) {
 | 
					                    if (! isset($taxTotals[$currencyId])) {
 | 
				
			||||||
                        $taxTotals[$currencyId] = [];
 | 
					                        $taxTotals[$currencyId] = [];
 | 
				
			||||||
@ -60,22 +63,20 @@ class TaxRateReport extends AbstractReport
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $amount += $invoice->amount;
 | 
					                foreach ($taxTotals as $currencyId => $taxes) {
 | 
				
			||||||
                $paid += $invoice->getAmountPaid();
 | 
					                    foreach ($taxes as $tax) {
 | 
				
			||||||
            }
 | 
					                        $this->data[] = [
 | 
				
			||||||
 | 
					                            $invoice->present()->link,
 | 
				
			||||||
 | 
					                            $tax['name'],
 | 
				
			||||||
 | 
					                            $tax['rate'] . '%',
 | 
				
			||||||
 | 
					                            $account->formatMoney($tax['amount'], $client),
 | 
				
			||||||
 | 
					                            $account->formatMoney($tax['paid'], $client),
 | 
				
			||||||
 | 
					                        ];
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            foreach ($taxTotals as $currencyId => $taxes) {
 | 
					                    $this->addToTotals($client->currency_id, 'amount', $invoice->amount);
 | 
				
			||||||
                foreach ($taxes as $tax) {
 | 
					                    $this->addToTotals($client->currency_id, 'paid', $invoice->getAmountPaid());
 | 
				
			||||||
                    $this->data[] = [
 | 
					 | 
				
			||||||
                        $tax['name'],
 | 
					 | 
				
			||||||
                        $tax['rate'] . '%',
 | 
					 | 
				
			||||||
                        $account->formatMoney($tax['amount'], $client),
 | 
					 | 
				
			||||||
                        $account->formatMoney($tax['paid'], $client),
 | 
					 | 
				
			||||||
                    ];
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					 | 
				
			||||||
                $this->addToTotals($client->currency_id, 'amount', $tax['amount']);
 | 
					 | 
				
			||||||
                $this->addToTotals($client->currency_id, 'paid', $tax['paid']);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user