company->db); App::forgetInstance('translator'); App::setLocale($this->company->locale()); $t = app('translator'); $t->replace(Ninja::transformTranslations($this->company->settings)); $this->csv = Writer::createFromString(); $this->csv->insertOne([]); $this->csv->insertOne([]); $this->csv->insertOne([]); $this->csv->insertOne([]); $this->csv->insertOne([ctrans('texts.tax_summary')]); $this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]); if (count($this->input['report_keys']) == 0) { $this->input['report_keys'] = $this->report_keys; } $this->csv->insertOne($this->buildHeader()); $query = Invoice::query() ->where('company_id', $this->company->id) ->where('is_deleted', 0) ->orderBy('balance', 'desc'); $query = $this->addDateRange($query); $query = $this->filterByClients($query); $map = []; foreach($query->cursor() as $invoice) { $taxes = $invoice->calc()->getTaxMap(); foreach($taxes as $tax) { $key = $tax['name']; if(!isset($map[$key])) { $map[$key]['tax_amount'] = 0; // $map[$key]['taxable_amount'] = 0; } $map[$key]['tax_amount'] += $tax['total']; // $map[$key]['taxable_amount'] += $invoice->amount; } } foreach($map as $key => $value) { $this->csv->insertOne([$key, Number::formatMoney($value['tax_amount'], $this->company)]); // $this->csv->insertOne([$key, Number::formatMoney($value['taxable_amount'], $this->company), Number::formatMoney($value['tax_amount'], $this->company)]); } return $this->csv->toString(); } public function buildHeader() :array { $header = []; foreach ($this->input['report_keys'] as $value) { $header[] = ctrans("texts.{$value}"); } return $header; } }