예제 #1
0
 public function postReport($id)
 {
     $visit = Visit::findorfail($id);
     $battery_water_added = isset($_POST['battery_water_added']) ? $_POST['battery_water_added'] : array();
     $battery_installation = isset($_POST['battery_installation']) ? $_POST['battery_installation'] : array();
     $ups_reports = isset($_POST['ups_main_input_voltage']) ? $_POST['ups_main_input_voltage'] : array();
     $submeterReports = isset($_POST['submeter_reading']) ? $_POST['submeter_reading'] : array();
     $cordsReports = isset($_POST['cords_reading']) ? $_POST['cords_reading'] : array();
     $battery_uninstall = isset($_POST['battery_uninstall']) ? $_POST['battery_uninstall'] : array();
     $ups_install = isset($_POST['ups_installation']) ? $_POST['ups_installation'] : array();
     $ups_uninstall = isset($_POST['ups_uninstall']) ? $_POST['ups_uninstall'] : array();
     $charger_install = isset($_POST['charger_installation']) ? $_POST['charger_installation'] : array();
     $charger_uninstall = isset($_POST['charger_uninstall']) ? $_POST['charger_uninstall'] : array();
     $charger_reports = isset($_POST['charging_ampere']) ? $_POST['charging_ampere'] : array();
     //add the existing battery report
     foreach (Input::get('battery_water_level') as $key => $water_level) {
         $visit->podBatteryReport()->attach($key, array('water_level' => $water_level));
     }
     foreach ($battery_water_added as $key => $water_added) {
         $visit->podBatteryWaterAdded()->attach($key);
     }
     foreach ($battery_installation as $key => $install) {
         foreach (Input::get('battery_brand')[$key] as $subkey => $newBattery) {
             $podBattery = new PodBattery();
             $podBattery->brand = $newBattery;
             $podBattery->installed_date = Input::get('battery_installed_date')[$key][$subkey];
             $podBattery->capacity = Input::get('battery_capacity')[$key][$subkey];
             $podBattery->pod_inventory_id = $key;
             $podBattery->save();
             $visit->podBatteryInstallLog()->attach($podBattery->id);
         }
     }
     //add the uninstall battery log
     foreach ($battery_uninstall as $key => $data) {
         $visit->podBatteryUnInstallLog()->attach($key);
         $battery = Podbattery::find($key);
         $battery->pod_inventory_id = 0;
         $battery->save();
     }
     //add  the ups report
     foreach ($ups_reports as $key => $up) {
         $visit->podupsReports()->attach($key, array('main_input_voltage' => $up, 'output_voltage_bypass' => Input::get('ups_output_voltage_bypass')[$key], 'output_voltage_backup' => Input::get('ups_output_voltage_backup')[$key], 'charging_ampere' => Input::get('ups_charging_ampere')[$key], 'discharging_ampere' => Input::get('ups_discharging_ampere')[$key]));
     }
     //add the ups install
     foreach ($ups_install as $key => $install) {
         foreach (Input::get('ups_brand')[$key] as $subkey => $newUps) {
             $podUp = new PodUp();
             $podUp->brand = $newUps;
             $podUp->installed_date = Input::get('ups_installed_date')[$key][$subkey];
             $podUp->capacity = Input::get('ups_capacity')[$key][$subkey];
             $podUp->pod_inventory_id = $key;
             $podUp->save();
             $visit->podUpsInstallLog()->attach($podUp->id);
         }
     }
     //add the ups uninstall
     foreach ($ups_uninstall as $key => $data) {
         $visit->podUpsUnInstallLog()->attach($key);
         $ups = PodUp::find($key);
         $ups->pod_inventory_id = 0;
         $ups->save();
     }
     //add the cord report
     foreach ($cordsReports as $key => $value) {
         $visit->podCordsReport()->attach($key, array('condition' => $value));
     }
     //add the submmeter report
     foreach ($submeterReports as $key => $report) {
         $visit->submeterReports()->attach($key, array('reading' => $report));
     }
     //add the charger install
     foreach ($charger_install as $key => $install) {
         foreach (Input::get('charger_brand')[$key] as $subkey => $newUps) {
             $podCharger = new Charger();
             $podCharger->brand = $newUps;
             $podCharger->installed_date = Input::get('charger_installed_date')[$key][$subkey];
             $podCharger->pod_inventory_id = $key;
             $podCharger->save();
             $visit->podChargerInstallLog()->attach($podCharger->id);
         }
     }
     //add the charger reports
     foreach ($charger_reports as $key => $up) {
         $visit->podChargerReport()->attach($key, array('charging_ampere' => $up));
     }
     //add the charger uninstall
     foreach ($charger_uninstall as $key => $data) {
         $visit->podChargerUnInstallLog()->attach($key);
         $ups = Charger::find($key);
         $ups->pod_inventory_id = 0;
         $ups->save();
     }
     //update the  visit to completed from pending
     $visit->status = 1;
     $visit->save();
     //redirect
     return Redirect::route('visits.index');
 }