public function index(Manager $fractal, InspolTransformer $inspolTransformer) { // show all $records = Inspol::with('agent.agency', 'county', 'databases')->get(); $collection = new Collection($records, $inspolTransformer); $data = $fractal->createData($collection)->toArray(); return $this->respond($data); }
function processFarmUnit($unit, $loan) { $cash_rent = (double) $unit->farm->cash_rent; $dist_rent = (double) $unit->farm->dist_rent; $total_acres = (double) $unit->acres; $farm_acres = (double) ($unit->farm->IR + $unit->farm->NI); $acres_percent = (double) $total_acres / $farm_acres; $fsa_pay = (double) $unit->farm->fsa_paid * $acres_percent; $retro = ['id' => $unit->id, 'state' => $unit->farm->county->state->abr, 'county' => $unit->farm->county->county, 'fsn' => $unit->farm->fsn, 'owner' => $unit->farm->owner, 'practice' => $unit->practice, 'total_acres' => $total_acres, 'farm_acres' => $farm_acres, 'acres_percent' => $acres_percent, 'rent_ovr' => (double) $unit->farm->share_rent, 'share_rent' => (double) $unit->farm->share_rent, 'perm2ins' => $unit->farm->perm_to_insure ? 'Y' : 'N', 'cash_rent' => $cash_rent, 'dist_rent' => $dist_rent, 'waived' => (double) $unit->farm->waived, 'when_due' => $unit->farm->when_due, 'fsa_paid' => $fsa_pay, 'cash_rent_acre_ARM' => $cash_rent / $total_acres, 'cash_rent_acre_dist' => $dist_rent / $total_acres, 'cash_rent_acre_other' => 0, 'fsa_acre' => $fsa_pay / $total_acres, 'waived_acre' => (double) $unit->farm->waived / $total_acres, 'crops' => []]; foreach ($unit->practices as $upc) { foreach ($loan->loancrops as $lc) { $cropID = $lc->crop->id; $crop = $lc->crop->crop; $lp = App\Loanpractice::where('farmunit_id', $unit->id)->where('crop_id', $cropID)->first(); $policy = Inspol::with('databases')->where('county_id', $unit->farm->county_id)->where('crop_id', $cropID)->where('practice', $upc->practice)->first(); $newb[$crop] = ['id' => $cropID, 'crop' => $crop, 'practice' => $upc->practice, 'acres' => (double) $lp['acres'], 'var_harvst' => (double) $lc->var_harvest, 'rebate' => (double) $lc->rebates, 'prod_yield' => (double) $lp['prod_yield'], 'prod_share' => (double) $lp['prod_share'], 'prod_price' => (double) $lp['prod_price'], 'aph' => (double) (count($policy['databases']) > 0 ? $policy['databases'][0]['aph'] : 0), 'override' => (double) $policy['ins_share'], 'ins_share' => (double) (count($policy['databases']) > 0 ? $policy['databases'][0]['ins_share'] : 0), 'ins_type' => $policy['type'], 'ins_opts' => $policy['options'], 'ins_level' => (double) $policy['ins_level'], 'ins_price' => (double) $policy['ins_price'], 'ins_premium' => (double) $policy['premium'], 'PLC' => (bool) $policy['plc'], 'loss_trigger' => (double) $policy['stax_loss_trigger'], 'cov_range' => (double) $policy['stax_desired_range'], 'prot_factor' => (double) $policy['stax_protection_factor'], 'cov_err_check' => (double) $policy['ins_level'] + (double) $policy['stax_desired_range'], 'exp_yield' => (double) $policy['exp_yield'], 'planting_days' => (int) $policy['planting_days']]; } } array_push($retro['crops'], $newb); return $retro; }