1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-23 01:41:34 +02:00
invoiceninja/app/ninja/repositories/TaxRateRepository.php
Hillel Coren 4ff55936d7 bug fixes
2013-12-29 13:28:44 +02:00

49 lines
827 B
PHP
Executable File

<?php namespace ninja\repositories;
use TaxRate;
class TaxRateRepository
{
public function save($taxRates)
{
$taxRateIds = [];
foreach ($taxRates as $record)
{
if (!isset($record->rate) || $record->is_deleted)
{
continue;
}
if (!floatval($record->rate) || !trim($record->name))
{
continue;
}
if ($record->public_id)
{
$taxRate = TaxRate::scope($record->public_id)->firstOrFail();
}
else
{
$taxRate = TaxRate::createNew();
}
$taxRate->rate = floatval($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();
}
}
}
}