Beispiel #1
0
 /**
  *
  * Proses Simpan Locations
  *
  * @throws \Exception
  * @return mixed
  */
 public function store()
 {
     if (!$this->hasAccess()) {
         return Response::json(array('success' => false, 'reason' => 'Action Need Login First', 'results' => null))->setCallback();
     }
     //        return Input::all();
     if (!Input::has('type')) {
         throw new \Exception('No Type Parameter');
     }
     $type = Input::get('type');
     $level = $this->convertTypeToLevel($type);
     //        $level = Input::get('level');
     /**
      * Control Control Name
      */
     $name = Input::get('name');
     if ($level == 1) {
         /*Nama Negara Tidak Boleh Sama */
         $exist = $this->locations->whereName($name)->count();
         if ($exist > 0) {
             return Response::json(array('success' => true, 'error' => true, 'reason' => 'Nama Negara harus Unique, sepertinya Negara Sudah ada'), 500);
         }
         $parentId = 0;
     } else {
         $parentId = Input::get('parent_id');
     }
     /*Proses Saving*/
     $uid = \Auth::user()->id;
     $newRecord = ['name' => $name, 'level' => $level, 'info' => Input::get('info'), 'uuid' => uniqid('New_'), 'parent_id' => $parentId, 'parent_type' => '\\Emayk\\Ics\\Repo\\Locations\\Locations', 'createby_id' => $uid, 'lastupdateby_id' => $uid, 'created_at' => Carbon::create(), 'updated_at' => Carbon::create()];
     $saved = $this->locations->create($newRecord);
     return Response::json(array('success' => $saved, 'error' => !$saved, 'results' => $saved->toArray(), 'reason' => $saved ? 'Saved' : 'Error Saved'))->setCallback();
 }
Beispiel #2
0
 /**
  * @param bool $resultIds
  *
  * @return array|string
  * @throws \Exception
  */
 public static function generateMassive($resultIds = false)
 {
     $countries = Locations::where('level', 1);
     if (!$countries->count()) {
         throw new Exception('Negara Masih Kosong , Isi Dl');
     }
     $fake = static::getFake()->getCurrency();
     $ListCurrency = $fake->getCurrencies();
     $ids = array();
     foreach ($ListCurrency as $curr) {
         /*dapatkan ID*/
         $countryName = $curr['country'];
         $currName = $curr['name'];
         $currSymbol = $curr['symbol'];
         $country = Locations::whereName($countryName);
         if ($country->count()) {
             /*Jika Country Ada*/
             $countryId = $country->pluck('id');
             $record = $fake->createRecordCurrency($countryId, $currName, $currSymbol);
             $newrecord = static::createRecord($record);
             $ids[] = $newrecord->id;
         }
     }
     return $resultIds ? $ids : "Generate Currency with " . count($ids) . " records";
 }