示例#1
0
 public function getResource($resource)
 {
     if (is_string($resource)) {
         if ('amount' == $resource) {
             $country_code = Input::get('country_code');
             $mem_period = Input::get('mem_period');
             // hard coding the currency ID to query payment-heads
             if ('IND' == $country_code) {
                 $currency_id = 1;
             } else {
                 $currency_id = 2;
             }
             Log::info('In getResource: ' . $country_code . $mem_period);
             $head = PaymentHead::getHead($mem_period, $currency_id)->first();
             $data = ['amount' => $head->amount, 'service_tax' => ServiceTaxClass::find($head->service_tax_class_id)->tax_rate];
         } else {
             if ('states' == $resource) {
                 $country_code = Input::get('code');
                 Log::info('In getResource for states: ' . $country_code);
                 // querying with states of india and not regions > states;
                 $states = State::where('country_code', 'like', $country_code)->orderBy('name', 'asc')->get(['state_code', 'name'])->toarray();
                 Log::info('In getResource for states: typeof ' . gettype($states));
                 $data = $states;
             } else {
                 if ('branches' == $resource) {
                     $state_code = Input::get('code');
                     Log::info('In getResource for branches: ' . $state_code);
                     $chapters = CsiChapter::where('csi_state_code', $state_code)->get();
                     $collection = new \Illuminate\Database\Eloquent\Collection();
                     $result = new \Illuminate\Database\Eloquent\Collection();
                     foreach ($chapters as $chapter) {
                         $members = Member::where('csi_chapter_id', $chapter->id)->get();
                         if (!$members->isEmpty()) {
                             $collection = $members->filter(function ($item) {
                                 $curr = $item->subType;
                                 if ($curr->membership_type_id == 1) {
                                     if ($curr->subType->is_student_branch) {
                                         return $item;
                                     }
                                 }
                             });
                         }
                     }
                     foreach ($collection as $member) {
                         $arr = [];
                         $arr['member_id'] = $member->subType->id;
                         $arr['name'] = $member->subType->name;
                         $result->add($arr);
                     }
                     $data = $result->sortBy('name')->toarray();
                 } else {
                     if ('chapters' == $resource) {
                         $state_code = Input::get('code');
                         Log::info('In getResource for chapters: ' . $state_code);
                         $chapters = CsiChapter::where('csi_state_code', $state_code)->orderBy('name', 'asc')->get(['id', 'name'])->toarray();
                         Log::info('In getResource for chapters: typeof ' . gettype($chapters));
                         $data = $chapters;
                     } else {
                         if ('institutions' == $resource) {
                         }
                     }
                 }
             }
         }
         $response = Response::json($data, 200);
     } else {
         $response = Response::json(array('errors' => $e->getMessage()), 500);
     }
     return $response;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('service_tax_classes')->delete();
     ServiceTaxClass::create(['tax_rate' => '14']);
     ServiceTaxClass::create(['tax_rate' => '0']);
 }