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

50 lines
913 B
PHP
Raw Normal View History

2013-12-29 12:28:44 +01:00
<?php namespace ninja\repositories;
use TaxRate;
2014-01-14 12:52:56 +01:00
use Utils;
2013-12-29 12:28:44 +01:00
class TaxRateRepository
{
public function save($taxRates)
{
$taxRateIds = [];
foreach ($taxRates as $record)
{
2014-01-01 16:23:32 +01:00
if (!isset($record->rate) || (isset($record->is_deleted) && $record->is_deleted))
2013-12-29 12:28:44 +01:00
{
continue;
}
2014-04-10 21:29:01 +02:00
if (!isset($record->name) || !Utils::parseFloat($record->rate) || !trim($record->name))
2013-12-29 12:28:44 +01:00
{
continue;
}
if ($record->public_id)
{
$taxRate = TaxRate::scope($record->public_id)->firstOrFail();
}
else
{
$taxRate = TaxRate::createNew();
}
2014-01-14 12:52:56 +01:00
$taxRate->rate = Utils::parseFloat($record->rate);
2013-12-29 12:28:44 +01:00
$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();
}
}
}
}