Example #1
0
 public function run()
 {
     DB::table('inspols')->delete();
     $policies = [['loan_id' => 1, 'agent_id' => 1, 'county_id' => 1317, 'crop_id' => 1, 'practice' => 'NI', 'plc' => false, 'type' => 'RP', 'unit' => 'EU', 'options' => 'PFSE', 'ins_level' => 70, 'planting_days' => 0, 'ins_price' => 4.25, 'ins_share' => 80, 'premium' => 11.88, 'stax_loss_trigger' => 0, 'stax_desired_range' => 0, 'stax_protection_factor' => 0], ['loan_id' => 1, 'agent_id' => 1, 'county_id' => 1317, 'crop_id' => 2, 'practice' => 'NI', 'plc' => false, 'type' => 'RP', 'unit' => 'EU', 'options' => 'SE', 'ins_level' => 70, 'planting_days' => 0, 'ins_price' => 11.25, 'ins_share' => 80, 'premium' => 14.35, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 1, 'agent_id' => 1, 'county_id' => 1317, 'crop_id' => 6, 'practice' => 'NI', 'plc' => true, 'type' => 'RP', 'unit' => 'EU', 'options' => 'STAX', 'ins_level' => 70, 'ins_share' => 80, 'planting_days' => 0, 'ins_price' => 0.63, 'premium' => 19.82, 'exp_yield' => 858, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 1, 'agent_id' => 1, 'county_id' => 1317, 'crop_id' => 1, 'practice' => 'IR', 'plc' => false, 'type' => 'YP', 'unit' => 'EU', 'options' => 'PFSE', 'ins_level' => 70, 'ins_share' => 80, 'planting_days' => 0, 'ins_price' => 4.25, 'exp_yield' => 858, 'premium' => 11.88, 'stax_loss_trigger' => 0, 'stax_desired_range' => 0, 'stax_protection_factor' => 0], ['loan_id' => 1, 'agent_id' => 1, 'county_id' => 1317, 'crop_id' => 6, 'practice' => 'IR', 'plc' => false, 'type' => 'RPHPE', 'unit' => 'EU', 'options' => 'SCO', 'ins_level' => 70, 'ins_share' => 80, 'planting_days' => 0, 'ins_price' => 0.63, 'exp_yield' => 1192, 'premium' => 19.82, 'exp_yield' => 858, 'stax_loss_trigger' => 90, 'stax_desired_range' => 35, 'stax_protection_factor' => 120], ['loan_id' => 1, 'agent_id' => 2, 'county_id' => 1310, 'crop_id' => 1, 'practice' => 'NI', 'plc' => false, 'type' => 'RPHPE', 'unit' => 'EU', 'options' => 'SE', 'ins_level' => 75, 'ins_share' => 100, 'planting_days' => 0, 'ins_price' => 4.25, 'exp_yield' => 1192, 'premium' => 11.88, 'stax_loss_trigger' => 0, 'stax_desired_range' => 0, 'stax_protection_factor' => 0], ['loan_id' => 1, 'agent_id' => 2, 'county_id' => 1310, 'crop_id' => 2, 'practice' => 'NI', 'plc' => false, 'type' => 'RPHPE', 'unit' => 'EU', 'options' => 'SE', 'ins_level' => 70, 'planting_days' => 0, 'ins_price' => 11.25, 'ins_share' => 100, 'exp_yield' => 1192, 'premium' => 14.35, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 1, 'agent_id' => 2, 'county_id' => 1310, 'crop_id' => 6, 'practice' => 'NI', 'plc' => true, 'type' => 'RPHPE', 'unit' => 'EU', 'options' => 'SCO', 'ins_level' => 70, 'ins_share' => 80, 'planting_days' => 0, 'ins_price' => 0.63, 'premium' => 19.82, 'exp_yield' => 1142, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 1, 'agent_id' => 2, 'county_id' => 1310, 'crop_id' => 1, 'practice' => 'IR', 'plc' => false, 'type' => 'YP', 'unit' => 'EU', 'options' => 'SE', 'ins_level' => 75, 'ins_share' => 80, 'planting_days' => 0, 'ins_price' => 4.25, 'premium' => 11.88, 'stax_loss_trigger' => 0, 'stax_desired_range' => 0, 'stax_protection_factor' => 0], ['loan_id' => 1, 'agent_id' => 2, 'county_id' => 1310, 'crop_id' => 2, 'practice' => 'IR', 'plc' => false, 'type' => 'YP', 'unit' => 'EU', 'options' => 'SE', 'ins_level' => 70, 'planting_days' => 0, 'ins_price' => 11.25, 'ins_share' => 80, 'premium' => 14.35, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 1, 'agent_id' => 2, 'county_id' => 1310, 'crop_id' => 6, 'practice' => 'IR', 'plc' => true, 'type' => 'RP', 'unit' => 'EU', 'options' => 'SCO', 'ins_level' => 70, 'ins_share' => 80, 'planting_days' => 0, 'ins_price' => 0.63, 'exp_yield' => 1142, 'premium' => 19.82, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 2, 'agent_id' => 2, 'county_id' => 1317, 'crop_id' => 6, 'practice' => 'NI', 'plc' => true, 'type' => 'RP', 'unit' => 'EU', 'options' => 'STAX', 'ins_level' => 70, 'ins_share' => 80, 'planting_days' => 0, 'ins_price' => 0.63, 'premium' => 19.82, 'exp_yield' => 858, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 2, 'agent_id' => 2, 'county_id' => 1317, 'crop_id' => 1, 'practice' => 'NI', 'plc' => false, 'type' => 'RP', 'unit' => 'EU', 'options' => 'PFSE', 'ins_level' => 70, 'planting_days' => 0, 'ins_price' => 4.25, 'ins_share' => 80, 'premium' => 11.88, 'stax_loss_trigger' => 0, 'stax_desired_range' => 0, 'stax_protection_factor' => 0], ['loan_id' => 2, 'agent_id' => 2, 'county_id' => 1317, 'crop_id' => 2, 'practice' => 'NI', 'plc' => false, 'type' => 'RP', 'unit' => 'EU', 'options' => 'SE', 'ins_level' => 70, 'planting_days' => 0, 'ins_price' => 11.25, 'ins_share' => 80, 'premium' => 14.35, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 2, 'agent_id' => 2, 'county_id' => 1317, 'crop_id' => 4, 'practice' => 'NI', 'plc' => false, 'type' => 'RP', 'unit' => 'EU', 'options' => 'SE', 'ins_level' => 75, 'planting_days' => 0, 'ins_price' => 3.97, 'ins_share' => 80, 'premium' => 20.0, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120], ['loan_id' => 2, 'agent_id' => 2, 'county_id' => 1317, 'crop_id' => 7, 'practice' => 'NI', 'plc' => false, 'type' => 'RP', 'unit' => 'EU', 'options' => 'SE', 'ins_level' => 75, 'planting_days' => 0, 'ins_price' => 0.1125, 'ins_share' => 80, 'premium' => 20.0, 'stax_loss_trigger' => 90, 'stax_desired_range' => 15, 'stax_protection_factor' => 120]];
     foreach ($policies as $policy) {
         Inspol::create($policy);
     }
 }
Example #2
0
 public function update($id)
 {
     // save updated
     $record = $this->records->find($id);
     if (!$record) {
         Inspol::create(Input::all());
         return $this->respond($record);
     }
     $record->fill(Input::all())->save();
     return $this->respond($record);
 }
Example #3
0
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;
}