コード例 #1
0
 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();
         }
     }
 }
コード例 #2
0
 public function save($data, $taxRate = false)
 {
     if (!$taxRate) {
         if (isset($data['public_id'])) {
             $taxRate = TaxRate::scope($data['public_id'])->firstOrFail();
         } else {
             $taxRate = TaxRate::createNew();
         }
     }
     $taxRate->fill($data);
     $taxRate->save();
     return $taxRate;
 }
コード例 #3
0
 private function save($publicId = false)
 {
     if ($publicId) {
         $taxRate = TaxRate::scope($publicId)->firstOrFail();
     } else {
         $taxRate = TaxRate::createNew();
     }
     $taxRate->name = trim(Input::get('name'));
     $taxRate->rate = Utils::parseFloat(Input::get('rate'));
     $taxRate->save();
     $message = $publicId ? trans('texts.updated_tax_rate') : trans('texts.created_tax_rate');
     Session::flash('message', $message);
     return Redirect::to('settings/' . ACCOUNT_TAX_RATES);
 }
コード例 #4
0
 public function save($data, $taxRate = null)
 {
     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();
     }
     $taxRate->fill($data);
     $taxRate->save();
     return $taxRate;
 }