diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 576ea53c4477..079e8f6c3d63 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -115,6 +115,8 @@ class Invoice extends EntityModel implements BalanceAffecting 'terms', 'product', 'quantity', + 'tax1', + 'tax2', ]; } @@ -135,6 +137,7 @@ class Invoice extends EntityModel implements BalanceAffecting 'notes' => 'notes', 'product|item' => 'product', 'quantity|qty' => 'quantity', + 'tax' => 'tax1', ]; } diff --git a/app/Ninja/Import/BaseTransformer.php b/app/Ninja/Import/BaseTransformer.php index d136b159f1ff..9d6c95138fb3 100644 --- a/app/Ninja/Import/BaseTransformer.php +++ b/app/Ninja/Import/BaseTransformer.php @@ -156,6 +156,30 @@ class BaseTransformer extends TransformerAbstract return isset($this->maps['countries2'][$name]) ? $this->maps['countries2'][$name] : null; } + /** + * @param $name + * + * @return null + */ + public function getTaxRate($name) + { + $name = strtolower(trim($name)); + + return isset($this->maps['tax_rates'][$name]) ? $this->maps['tax_rates'][$name] : 0; + } + + /** + * @param $name + * + * @return null + */ + public function getTaxName($name) + { + $name = strtolower(trim($name)); + + return isset($this->maps['tax_names'][$name]) ? $this->maps['tax_names'][$name] : ''; + } + /** * @param $name * diff --git a/app/Ninja/Import/CSV/InvoiceTransformer.php b/app/Ninja/Import/CSV/InvoiceTransformer.php index 0692badfb3fc..198b2ef139c2 100644 --- a/app/Ninja/Import/CSV/InvoiceTransformer.php +++ b/app/Ninja/Import/CSV/InvoiceTransformer.php @@ -41,6 +41,10 @@ class InvoiceTransformer extends BaseTransformer 'notes' => $this->getString($data, 'notes') ?: $this->getProductNotes($this->getString($data, 'product')), 'cost' => $this->getFloat($data, 'amount') ?: $this->getProductCost($this->getString($data, 'product')), 'qty' => $this->getFloat($data, 'quantity') ?: 1, + 'tax_name1' => $this->getTaxName($this->getString($data, 'tax1')), + 'tax_rate1' => $this->getTaxRate($this->getString($data, 'tax1')), + 'tax_name2' => $this->getTaxName($this->getString($data, 'tax2')), + 'tax_rate2' => $this->getTaxRate($this->getString($data, 'tax2')), ], ], ]; diff --git a/app/Ninja/Repositories/TaxRateRepository.php b/app/Ninja/Repositories/TaxRateRepository.php index d16973941b50..2bfea8dbc72b 100644 --- a/app/Ninja/Repositories/TaxRateRepository.php +++ b/app/Ninja/Repositories/TaxRateRepository.php @@ -13,6 +13,11 @@ class TaxRateRepository extends BaseRepository return 'App\Models\TaxRate'; } + public function all() + { + return TaxRate::scope()->get(); + } + public function find($accountId) { return DB::table('tax_rates') diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 9fd7fea6f8ca..cc089210b82e 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -19,6 +19,7 @@ use App\Ninja\Repositories\InvoiceRepository; use App\Ninja\Repositories\PaymentRepository; use App\Ninja\Repositories\ProductRepository; use App\Ninja\Repositories\VendorRepository; +use App\Ninja\Repositories\TaxRateRepository; use App\Ninja\Serializers\ArraySerializer; use Auth; use Cache; @@ -126,7 +127,8 @@ class ImportService ProductRepository $productRepo, ExpenseRepository $expenseRepo, VendorRepository $vendorRepo, - ExpenseCategoryRepository $expenseCategoryRepo + ExpenseCategoryRepository $expenseCategoryRepo, + TaxRateRepository $taxRateRepository ) { $this->fractal = $manager; $this->fractal->setSerializer(new ArraySerializer()); @@ -139,6 +141,7 @@ class ImportService $this->expenseRepo = $expenseRepo; $this->vendorRepo = $vendorRepo; $this->expenseCategoryRepo = $expenseCategoryRepo; + $this->taxRateRepository = $taxRateRepository; } /** @@ -849,6 +852,8 @@ class ImportService 'invoice_ids' => [], 'vendors' => [], 'expense_categories' => [], + 'tax_rates' => [], + 'tax_names' => [], ]; $clients = $this->clientRepo->all(); @@ -886,6 +891,13 @@ class ImportService foreach ($expenseCaegories as $category) { $this->addExpenseCategoryToMaps($category); } + + $taxRates = $this->taxRateRepository->all(); + foreach ($taxRates as $taxRate) { + $name = trim(strtolower($taxRate->name)); + $this->maps['tax_rates'][$name] = $taxRate->rate; + $this->maps['tax_names'][$name] = $taxRate->name; + } } /** diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index ca224373f276..aece56618f6f 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2389,6 +2389,8 @@ $LANG = array( 'currency_peruvian_sol' => 'Peruvian Sol', 'use_english_version' => 'Make sure to use the English version of the files.
We use the column headers to match the fields.', + 'tax1' => 'First Tax', + 'tax2' => 'Second Tax', );