2015-03-24 09:21:12 +01:00
|
|
|
<?php namespace App\Ninja\Repositories;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-11-05 23:37:04 +01:00
|
|
|
use DB;
|
2015-03-16 22:45:25 +01:00
|
|
|
use Utils;
|
2015-11-05 23:37:04 +01:00
|
|
|
use App\Models\TaxRate;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-11-05 23:37:04 +01:00
|
|
|
class TaxRateRepository extends BaseRepository
|
2015-03-16 22:45:25 +01:00
|
|
|
{
|
2015-11-05 23:37:04 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2016-05-02 19:42:13 +02:00
|
|
|
public function save($data, $taxRate = null)
|
2016-02-03 15:03:56 +01:00
|
|
|
{
|
2016-05-02 19:42:13 +02:00
|
|
|
if ($taxRate) {
|
|
|
|
// do nothing
|
|
|
|
} elseif (isset($data['public_id'])) {
|
|
|
|
$taxRate = TaxRate::scope($data['public_id'])->firstOrFail();
|
|
|
|
\Log::warning('Entity not set in tax rate repo save');
|
|
|
|
} else {
|
|
|
|
$taxRate = TaxRate::createNew();
|
2016-02-03 15:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$taxRate->fill($data);
|
|
|
|
$taxRate->save();
|
|
|
|
|
|
|
|
return $taxRate;
|
|
|
|
}
|
|
|
|
|
2015-10-21 13:11:08 +02:00
|
|
|
/*
|
2015-03-16 22:45:25 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 13:11:08 +02:00
|
|
|
*/
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|