1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-18 09:04:35 +01:00
invoiceninja/app/ninja/repositories/TaxRateRepository.php
Hillel Coren d1d3d75915 bug fixes
2014-01-14 11:52:56 +00:00

50 lines
888 B
PHP
Executable File

<?php namespace ninja\repositories;
use TaxRate;
use Utils;
class TaxRateRepository
{
public function save($taxRates)
{
$taxRateIds = [];
foreach ($taxRates as $record)
{
if (!isset($record->rate) || (isset($record->is_deleted) && $record->is_deleted))
{
continue;
}
if (!Utils::parseFloat($record->rate) || !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();
}
}
}
}