mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 15:47:32 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			49 lines
		
	
	
		
			859 B
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			859 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) || (isset($record->is_deleted) && $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();
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| } |