1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Ninja/Repositories/TaxRateRepository.php
2015-11-06 00:37:04 +02:00

60 lines
1.5 KiB
PHP

<?php namespace App\Ninja\Repositories;
use DB;
use Utils;
use App\Models\TaxRate;
use App\Ninja\Repositories\BaseRepository;
class TaxRateRepository extends BaseRepository
{
public function getClassName()
{
return 'App\Models\TaxRate';
}
public function find($accountId)
{
return DB::table('tax_rates')
->where('tax_rates.account_id', '=', $accountId)
->where('tax_rates.deleted_at', '=', null)
->select('tax_rates.public_id', 'tax_rates.name', 'tax_rates.rate', 'tax_rates.deleted_at');
}
/*
public function save($taxRates)
{
$taxRateIds = [];
foreach ($taxRates as $record) {
if (!isset($record->rate) || (isset($record->is_deleted) && $record->is_deleted)) {
continue;
}
if (!isset($record->name) || !trim($record->name)) {
continue;
}
if ($record->public_id) {
$taxRate = TaxRate::scope($record->public_id)->firstOrFail();
} else {
$taxRate = TaxRate::createNew();
}
$taxRate->rate = Utils::parseFloat($record->rate);
$taxRate->name = trim($record->name);
$taxRate->save();
$taxRateIds[] = $taxRate->public_id;
}
$taxRates = TaxRate::scope()->get();
foreach ($taxRates as $taxRate) {
if (!in_array($taxRate->public_id, $taxRateIds)) {
$taxRate->delete();
}
}
}
*/
}