Exemplo n.º 1
0
 public static function search_data($vehicle_data, $driver = NULL)
 {
     if (!empty($vehicle_data)) {
         $vehicles_vin = $vehicle_data->vehicles_vin;
         $vehicles_model_id = $vehicle_data->vehicles_model_id;
         $vehicles_use_type_id = $vehicle_data->vehicles_use_type;
         $vehicle_color = Color::find($vehicle_data->vehicles_color)->colors_name;
         $owner = $vehicle_data->owners;
         foreach ($owner as $own) {
             $owner_names['name'][] = $own->drivers_fname . " " . $own->drivers_lname;
         }
         if (!isset($owner_names)) {
             $owner_names = null;
         }
         $model = Model::find($vehicles_model_id);
         $model_make_id = $model->model_make_id;
         $model_name = $model->model_name;
         $vehicle_use_types_name = VehicleUseType::find($vehicles_use_type_id)->vehicle_use_types_name;
         $result_data[] = array('id' => $vehicle_data->id, 'vin_number' => $vehicles_vin, 'model_make_id' => $model_make_id, 'model_name' => $model_name, 'color' => $vehicle_color, 'owner' => $owner_names, 'vehicle_use_types_name' => $vehicle_use_types_name);
         if ($driver) {
             return $result_data;
         }
         Helpers::response_data('200', 'success', $result_data);
     } else {
         Helpers::response_data('404', 'No record found', NULL);
     }
 }
 public function testFind()
 {
     self::assertEquals(Shell::GNOME, Shell::find('Gnome'));
     self::assertEquals(Shell::UNITY, Shell::find('Cinnamon'));
     self::assertNull(Color::find(Shell::GNOME));
     self::assertEquals(Color::GREY, Color::find('#808080'));
     self::assertNotEquals(Color::GRAY, Color::find('#808080'));
 }
Exemplo n.º 3
0
 /**
  * 图片分为: 链接, 名字, 图片, 类型
  */
 public function indexAction()
 {
     if (!$this->view->getCache()->exists('index')) {
         $websiteData = Website::find(array('order' => 'vote desc', 'cache' => array('key' => 'website', 'lifetime' => 3600)));
         $sightData = Sight::find(array('order' => 'RANDOM()', 'cache' => array('key' => 'sight', 'lifetime' => 3600)));
         $colorData = Color::find(array('order' => 'RANDOM()', 'cache' => array('key' => 'color', 'lifetime' => 3600)));
         $this->view->websiteData = $websiteData;
         $this->view->sightData = $sightData;
         $this->view->colorData = $colorData;
     }
     $this->view->cache(array('key' => 'index', 'lifetime' => 7200));
 }
Exemplo n.º 4
0
 /**
  * Store a newly created vehicle in database.
  *
  * @return Response
  */
 public function store()
 {
     //VEHICLE DATA
     $vehicles_year = trim(Input::get('vehicles_year'));
     $vehicles_make_id = trim(Input::get('vehicles_make_id'));
     $vehicles_name_trim = trim(Input::get('vehicles_name_trim'));
     $vehicles_name_trim_ar = explode(',', $vehicles_name_trim);
     $model_name = trim($vehicles_name_trim_ar[0]);
     if (count($vehicles_name_trim_ar) > 1) {
         $model_trim = trim($vehicles_name_trim_ar[1]);
     } else {
         $model_trim = "";
     }
     $vehicles_body = trim(Input::get('vehicles_body'));
     if ($vehicles_body == -1) {
         $vehicles_body = "";
     }
     $vehicles_weight_kg = trim(Input::get('vehicles_weight_kg'));
     // BEGIN ADDING NEW WEIGHT TO MODEL
     if (Input::get('new_wt') == 1) {
         // IF BODY IS NULL (SOME MODELS HAS NULL BODY)
         if ($vehicles_body == "") {
             // GETTING MODEL
             $model = Model::where('model_year', $vehicles_year)->where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->whereNull('model_body')->where('model_weight_kg', NULL)->first();
         } else {
             $model = Model::where('model_year', $vehicles_year)->where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->where('model_body', $vehicles_body)->where('model_weight_kg', NULL)->first();
         }
         $model->model_weight_kg = $vehicles_weight_kg;
         $model->save();
     }
     // END ADDING NEW WEIGHT TO MODEL
     // BEGIN ADDING NEW MODEL INTO DATABASE
     if (Input::get('new_model') == 1) {
         // IF BOTH ARE NOT BLANK
         if ($model_trim != "" && $vehicles_body != "") {
             $newModel = Model::create(['model_make_id' => $vehicles_make_id, 'model_name' => $model_name, 'model_trim' => $model_trim, 'model_year' => $vehicles_year, 'model_body' => $vehicles_body, 'model_weight_kg' => $vehicles_weight_kg]);
         } else {
             if ($model_trim == "" && $vehicles_body != "") {
                 $newModel = Model::create(['model_make_id' => $vehicles_make_id, 'model_name' => $model_name, 'model_trim' => $model_trim, 'model_year' => $vehicles_year, 'model_body' => $vehicles_body, 'model_weight_kg' => $vehicles_weight_kg]);
             } else {
                 if ($model_trim != "" && $vehicles_body == "") {
                     $newModel = Model::create(['model_make_id' => $vehicles_make_id, 'model_name' => $model_name, 'model_trim' => $model_trim, 'model_year' => $vehicles_year, 'model_weight_kg' => $vehicles_weight_kg]);
                 } else {
                     $newModel = Model::create(['model_make_id' => $vehicles_make_id, 'model_name' => $model_name, 'model_trim' => $model_trim, 'model_year' => $vehicles_year, 'model_weight_kg' => $vehicles_weight_kg]);
                 }
             }
         }
         $newModelId = $newModel->id;
     }
     // END ADDING NEW MODEL INTO DATABASE
     // BEGIN VEHICLE
     if ($vehicles_body != "") {
         $vehicle = Input::only(['vehicles_vin', 'vehicles_year', 'vehicles_make_id', 'vehicles_name_trim', 'vehicles_body', 'vehicles_weight_kg', 'vehicles_use_type', 'vehicles_use_type', 'vehicles_class', 'vehicles_color', 'vehicles_status', 'vehicles_odometer']);
     } else {
         $vehicle = Input::only(['vehicles_vin', 'vehicles_year', 'vehicles_make_id', 'vehicles_name_trim', 'vehicles_weight_kg', 'vehicles_use_type', 'vehicles_use_type', 'vehicles_class', 'vehicles_color', 'vehicles_status', 'vehicles_odometer']);
     }
     $validator_vehicle = Validator::make($vehicle, Vehicle::$rules);
     if ($validator_vehicle->passes()) {
         // GETTING AND ADDING MODEL ID
         // IF NEW MODEL WAS CREATED
         if (isset($newModelId) && $newModelId != "") {
             $vehicle['vehicles_model_id'] = $newModelId;
         } else {
             // IF BODY IS NULL
             if ($vehicles_body == "") {
                 // GETTING MODEL
                 $vehicle['vehicles_model_id'] = Model::where('model_year', $vehicles_year)->where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->whereNull('model_body')->first()->id;
             } else {
                 $vehicle['vehicles_model_id'] = Model::where('model_year', $vehicles_year)->where('model_make_id', $vehicles_make_id)->where('model_name', $model_name)->where('model_trim', $model_trim)->where('model_body', $vehicles_body)->first()->id;
             }
         }
         // INSERT VEHICLE DATA AND GET ID
         $vehicle_inserted_id = Vehicle::create($vehicle)->id;
     } else {
         return Redirect::route('vehicle.create')->withErrors($validator_vehicle)->withInput();
     }
     // END VEHICLE
     // BEGIN OWNERS
     $owners_index = Input::get('owners_index');
     $owners_index_arr = array_filter(explode(',', $owners_index));
     // LOOP THROUGH EACH OWNER AND ASSOCIATE WITH DRIVERS
     foreach ($owners_index_arr as $owners_index_id) {
         $drivers_license_no = Input::get('drivers_license_no' . $owners_index_id);
         if (trim($drivers_license_no) != "") {
             $drivers_status = Driver::where('drivers_license_no', $drivers_license_no)->first();
             // IF DRIVER DOESN'T EXISTS, CREATE DRIVER
             if ($drivers_status == NULL) {
                 $owner_info['drivers_fname'] = Input::get('drivers_fname' . $owners_index_id);
                 $owner_info['drivers_mname'] = Input::get('drivers_mname' . $owners_index_id);
                 $owner_info['drivers_lname'] = Input::get('drivers_lname' . $owners_index_id);
                 $owner_info['drivers_nin'] = Input::get('drivers_nin' . $owners_index_id);
                 $owner_info['drivers_license_no'] = Input::get('drivers_license_no' . $owners_index_id);
                 $owner_info['drivers_street'] = Input::get('drivers_street' . $owners_index_id);
                 $owner_info['drivers_city'] = Input::get('drivers_city' . $owners_index_id);
                 $owner_info['drivers_po_box'] = Input::get('drivers_po_box' . $owners_index_id);
                 $owner_info['drivers_country'] = Input::get('drivers_country' . $owners_index_id);
                 $owner_info['drivers_cell1'] = Input::get('drivers_cell1' . $owners_index_id);
                 $owner_info['drivers_cell2'] = Input::get('drivers_cell2' . $owners_index_id);
                 $owner_info['drivers_email'] = Input::get('drivers_email' . $owners_index_id);
                 $owner_info['drivers_driving_status'] = Input::get('drivers_driving_status' . $owners_index_id);
                 $insert_owner_into_driver_table = Driver::create($owner_info);
                 // USED TO ASSOCIATE WITH VEHICLE
                 $owner_ids[] = $insert_owner_into_driver_table->id;
                 // USED TO SEND SMS
                 $ownerNamePh[$owner_info['drivers_cell1']]['name'] = $owner_info['drivers_fname'] . " " . $owner_info['drivers_lname'];
                 $ownerNamePh[$owner_info['drivers_cell1']]['address'] = $owner_info['drivers_street'] . ", " . $owner_info['drivers_city'] . " - " . $owner_info['drivers_po_box'];
                 $ownerNamePh[$owner_info['drivers_cell1']]['email'] = $owner_info['drivers_email'];
             } else {
                 $driverExist = Driver::where('drivers_license_no', $drivers_license_no)->first();
                 // USED TO ASSOCIATE WITH VEHICLE
                 $owner_ids[] = $driverExist->id;
                 // USED TO SEND SMS
                 $ownerNamePh[$driverExist->drivers_cell1]['name'] = $driverExist->drivers_fname . " " . $driverExist->drivers_lname;
                 $ownerNamePh[$driverExist->drivers_cell1]['address'] = $driverExist->drivers_street . " " . $driverExist->drivers_city . " - " . $driverExist->drivers_po_box;
                 $ownerNamePh[$driverExist->drivers_cell1]['email'] = $driverExist->drivers_email;
             }
         }
     }
     // LINK VEHICLE WITH OWNERS
     if (!empty($owner_ids)) {
         foreach ($owner_ids as $owner_ids_fet) {
             $owner_ids_fet = (int) $owner_ids_fet;
             Vehicle::find($vehicle_inserted_id)->owners()->attach($owner_ids_fet);
         }
     }
     // END OWNERS
     //BEGIN AUTHORIZED DRIVERS
     $authorized_index = Input::get('authorized_index');
     // IF AUTHORIZED DRIVERS EXIST, ASSOCIATE WITH DRIVERS.(CHECKING USING LICENSE)
     if ($authorized_index != "") {
         $authorized_index_arr = explode(',', $authorized_index);
         foreach ($authorized_index_arr as $authorized_index_id) {
             $authorized_license_no = Input::get('authorized_license_no' . $authorized_index_id);
             $authorized_status = Driver::where('drivers_license_no', $authorized_license_no)->first();
             //IF DRIVER DOESN'T EXISTS, CREATE DRIVER
             if ($authorized_status == NULL) {
                 $authorized_info['drivers_fname'] = Input::get('authorized_fname' . $authorized_index_id);
                 $authorized_info['drivers_mname'] = Input::get('authorized_mname' . $authorized_index_id);
                 $authorized_info['drivers_lname'] = Input::get('authorized_lname' . $authorized_index_id);
                 $authorized_info['drivers_nin'] = Input::get('authorized_nin' . $authorized_index_id);
                 $authorized_info['drivers_license_no'] = Input::get('authorized_license_no' . $authorized_index_id);
                 $authorized_info['drivers_street'] = Input::get('authorized_street' . $authorized_index_id);
                 $authorized_info['drivers_city'] = Input::get('authorized_city' . $authorized_index_id);
                 $authorized_info['drivers_po_box'] = Input::get('authorized_po_box' . $authorized_index_id);
                 $authorized_info['drivers_country'] = Input::get('authorized_country' . $authorized_index_id);
                 $authorized_info['drivers_cell1'] = Input::get('authorized_cell1' . $authorized_index_id);
                 $authorized_info['drivers_cell2'] = Input::get('authorized_cell2' . $authorized_index_id);
                 $authorized_info['drivers_email'] = Input::get('authorized_email' . $authorized_index_id);
                 $authorized_info['drivers_driving_status'] = Input::get('authorized_driving_status' . $authorized_index_id);
                 $insert_authorized_into_driver_table = Driver::create($authorized_info);
                 $authorized_ids[] = $insert_authorized_into_driver_table->id;
             } else {
                 $authorized_ids[] = Driver::where('drivers_license_no', $authorized_license_no)->first()->id;
             }
         }
         // LINK VEHICLE WITH AUTHORIZED DRIVERS
         foreach ($authorized_ids as $authorized_ids_fet) {
             $authorized_ids_fet = (int) $authorized_ids_fet;
             Vehicle::find($vehicle_inserted_id)->authorizedDrivers()->attach($authorized_ids_fet);
         }
     }
     // END AUTHORIZED DRIVERS
     // BEGIN INSURANCE
     if (Input::get('insurances_company') != "") {
         $insurance_arr = new Insurance(Input::only('insurances_company', 'insurances_policy_no', 'insurances_exp_date', 'insurances_agent_fname', 'insurances_agent_lname', 'insurances_agent_cell', 'insurances_agent_city', 'insurances_agent_email'));
         Vehicle::find($vehicle_inserted_id)->insurance()->save($insurance_arr);
     }
     // END INSURANCE
     // BEGIN LIEN HOLDER
     if (Input::get('lien_index')) {
         $lien_arr = new Lien(Input::only('liens_collateral_id', 'liens_collateral_value', 'liens_bank_name', 'liens_bank_branch', 'liens_bank_street', 'liens_bank_city'));
         //$lien_arr['liens_vehicle_id'] = $vehicle_inserted_id;
         //Lien::create($lien_arr);
         Vehicle::find($vehicle_inserted_id)->lien()->save($lien_arr);
     }
     // END LIEN HOLDER
     // BEGIN FILES
     $files_col = Input::file();
     $files_count = count(array_filter($files_col['files']));
     // IF FILES EXISTS
     if ($files_count) {
         foreach ($files_col['files'] as $files) {
             $filename_ar = explode('.', $files->getClientOriginalName());
             $document_ext = end($filename_ar);
             $path = public_path() . '/vehicledata/documents';
             // GENERATE RANDOM FILE NAME AND ADD EXTENSION
             $randName = md5(rand() * time());
             $document_name = $randName . '.' . $document_ext;
             // MOVE FILE AND ENTRY INTO DATABASE
             if ($files->move($path, $document_name)) {
                 //Document::create(['documents_vehicle_id' => $vehicle_inserted_id, 'documents_name' => $document_name]);
                 Vehicle::find($vehicle_inserted_id)->documents()->save(new Document(['documents_name' => $document_name]));
             }
         }
     }
     // END FILES
     // BEGIN REGISTRATION
     if (isset($vehicle_inserted_id) && $vehicle_inserted_id != "") {
         $registrations_vehicle_id = $vehicle_inserted_id;
         $registrations_no = Input::get('registrations_no');
         $registrations_licence_plate_no = Input::get('registrations_licence_plate_no');
         if ($registrations_no != "" && $registrations_licence_plate_no != "" && $registrations_vehicle_id != "") {
             $vehicles_use_type = Input::get('vehicles_use_type');
             $vehicles_class = Input::get('vehicles_class');
             if ($vehicles_use_type != "" && $vehicles_class != "") {
                 $vehicles_use_type_table_name = VehicleUseType::find($vehicles_use_type)->vehicle_use_types_table_name;
                 //REGISTRATION FEES
                 $vehicles_class_col_name = $vehicles_use_type_table_name . '_total';
                 $registrations_fees = DB::table($vehicles_use_type_table_name)->find($vehicles_class)->{$vehicles_class_col_name};
                 // INCREMENT REGISTRATION SEQUENCE
                 $vehicles_sequence_col_name = $vehicles_use_type_table_name . '_sequence';
                 $currentSequence = DB::table($vehicles_use_type_table_name)->find($vehicles_class)->{$vehicles_sequence_col_name};
                 $newSequence = $currentSequence + 1;
                 DB::table($vehicles_use_type_table_name)->where('id', $vehicles_class)->update([$vehicles_sequence_col_name => $newSequence]);
                 $registration_ar = compact('registrations_vehicle_id', 'registrations_no', 'registrations_licence_plate_no', 'registrations_fees');
                 //Registration::create($registration_ar);
                 Vehicle::find($vehicle_inserted_id)->registration()->save(new Registration($registration_ar));
                 // BEGIN TAKE LOGS
                 $newVehiclesStatus = Input::get('vehicles_status');
                 $newVehicleColor = Input::get('vehicles_color');
                 $newVehicleUseType = Input::get('vehicles_use_type');
                 $newVehiclesRegistrationNo = Input::get('registrations_no');
                 $vehicles_odometer = Input::get('vehicles_odometer');
                 LogVehicleStatus::create(['log_vehicle_status_vehicle_id' => $registrations_vehicle_id, 'log_vehicle_status_vehicle_status_id' => $newVehiclesStatus]);
                 LogVehicleColor::create(['log_vehicle_color_vehicle_id' => $registrations_vehicle_id, 'log_vehicle_color_color_id' => $newVehicleColor]);
                 LogVehicleUseType::create(['log_vehicle_use_type_vehicle_id' => $registrations_vehicle_id, 'log_vehicle_use_type_use_type' => $newVehicleUseType, 'log_vehicle_use_type_registration_no' => $newVehiclesRegistrationNo]);
                 LogVehicleOdometer::create(['log_vehicle_odometer_vehicle_id' => $registrations_vehicle_id, 'log_vehicle_odometer_old_odometer' => $vehicles_odometer, 'log_vehicle_odometer_status' => 1]);
                 // END TAKE LOGS
                 // BEGIN ASSOCIATE TEMPORARY VEHICLE FINES(IF ANY)
                 $vehicles_vin = Input::get('vehicles_vin');
                 $vehicleTemp = VehicleTemp::whereVehiclesVin($vehicles_vin)->first();
                 if ($vehicleTemp) {
                     // VEHICLE FINES
                     $violateVehicleTemp = $vehicleTemp->tempVehicleViolatile;
                     if ($violateVehicleTemp->count()) {
                         foreach ($violateVehicleTemp as $violateVehicleTempFet) {
                             ViolateVehicle::create(['vehicle_id' => $registrations_vehicle_id, 'driver_id' => $violateVehicleTempFet->driver_id, 'vehicle_fine_id' => $violateVehicleTempFet->vehicle_fine_id, 'vehicle_fine_unique_id' => $violateVehicleTempFet->vehicle_fine_unique_id, 'officer_id' => $violateVehicleTempFet->officer_id, 'geo_location' => $violateVehicleTempFet->geo_location, 'location_name' => $violateVehicleTempFet->location_name, 'longitude' => $violateVehicleTempFet->longitude, 'latitude' => $violateVehicleTempFet->latitude, 'status' => 2]);
                             ViolateVehicleTemp::find($violateVehicleTempFet->id)->update(['status' => 1]);
                         }
                     }
                     //DRIVER FINES
                     $violateDriverTemp = $vehicleTemp->tempDriverViolatile;
                     if ($violateDriverTemp->count()) {
                         foreach ($violateDriverTemp as $violateDriverTempFet) {
                             ViolateDriver::create(['vehicle_id' => $registrations_vehicle_id, 'driver_id' => $owner_ids[0], 'driver_fine_id' => $violateDriverTempFet->driver_fine_id, 'driver_fine_unique_id' => $violateDriverTempFet->driver_fine_unique_id, 'officer_id' => $violateDriverTempFet->officer_id, 'geo_location' => $violateDriverTempFet->geo_location, 'location_name' => $violateDriverTempFet->location_name, 'longitude' => $violateDriverTempFet->longitude, 'latitude' => $violateDriverTempFet->latitude, 'status' => 2]);
                             ViolateDriverTemp::find($violateDriverTempFet->id)->update(['status' => 1]);
                         }
                     }
                 }
                 //BEGIN SEND EMAIL
                 $owners = Driver::find($owner_ids);
                 $namesAr = $owners->lists('drivers_lname', 'drivers_fname');
                 foreach ($namesAr as $fname => $lname) {
                     $names[] = $fname . " " . $lname;
                 }
                 $names = implode(', ', $names);
                 $emails = $owners->lists('drivers_email');
                 $model = Model::find($vehicle['vehicles_model_id']);
                 $color = Color::find($newVehicleColor)->colors_name;
                 $data = compact('names', 'owners', 'model', 'color', 'newVehiclesRegistrationNo', 'registrations_licence_plate_no');
                 Mail::send('emails.vehicle.registration', $data, function ($message) use($emails) {
                     $message->to($emails)->subject('New vehicle Registration');
                 });
                 //END SEND EMAIL
                 // RETURN TO PRINT OUT
                 return Redirect::route('vehicle.print', [$registrations_vehicle_id]);
             }
         }
     } else {
         echo "Nothing is saved because fields are not filled";
         die;
     }
     // END REGISTRATION
 }
Exemplo n.º 5
0
 public function delete_destroy($palette_id, $color_id)
 {
     $delete = Color::find($color_id)->delete();
     if ($delete) {
         return Redirect::to('litmus/palettes/' . $palette_id . '/colors')->with('status', 'Your palette was deleted successfully!');
     } else {
         return Redirect::back()->with('error', "There was an error deleting the record!  Please try again.");
     }
 }
 /**
  *
  * @param type $report_items
  * @param type $count
  * @param type $door_id
  * @param type $width
  * @param type $height
  * @param type $is_it_drawer
  * @param type $cabinet_count
  */
 function report_door_manufacturing_list(&$report_items, $cabinet_order, $count, $door_id, $width, $height, $cabinet_count = 1, $is_it_drawer = false)
 {
     if ($count > 0) {
         $count *= $cabinet_count;
         $index_key = "{$door_id}|{$width}X{$height}";
         if (isset($report_items[$index_key]['quantity'])) {
             $report_items[$index_key]['quantity'] += $count;
         } else {
             App::import("Model", "Inventory.Door");
             $door = new Door();
             $door->recursive = -1;
             $door_info = $door->find('first', array('conditions' => array('Door.id' => $door_id)));
             $door_detail = $door_info['Door'];
             App::import("Model", "Inventory.Color");
             $color = new Color();
             $color->recursive = -1;
             $color_info = $color->find('first', array('conditions' => array('Color.id' => $cabinet_order['door_color'])));
             $door_color_detail = $color_info['Color'];
             $color_info = $color->find('first', array('conditions' => array('Color.id' => $cabinet_order['cabinet_color'])));
             $cabinet_color_detail = $color_info['Color'];
             $width_code = $this->InventoryLookupValue2Name($width);
             $width_code = empty($width_code) ? '--' : $width_code;
             $height_code = $this->InventoryLookupValue2Name($height);
             $height_code = empty($height_code) ? '--' : $height_code;
             if ($is_it_drawer) {
                 $report_items[$index_key]['code'] = "DR{$width_code}{$height_code}";
             } else {
                 $height_code_door_only = $this->InventoryLookupValue2Name($height);
                 if (!is_null($height_code_door_only)) {
                     $height_code = $height_code_door_only;
                     $height_code = empty($height_code) ? '--' : $height_code;
                 }
                 $report_items[$index_key]['code'] = "DO{$width_code}{$height_code}";
             }
             $report_items[$index_key]['cabinet_color'] = $cabinet_color_detail['name'];
             $report_items[$index_key]['door_style'] = $door_detail['door_style'];
             $report_items[$index_key]['door_color'] = $door_color_detail['name'];
             $report_items[$index_key]['outside_profile'] = $door_detail['outside_profile'];
             $report_items[$index_key]['router_cope'] = $door_detail['router_cope'];
             $report_items[$index_key]['router_panel'] = $door_detail['router_panel'];
             $report_items[$index_key]['wood_species'] = $this->InventoryLookupReverse($door_detail['wood_species']);
             $report_items[$index_key]['quantity'] = $count;
             $report_items[$index_key]['width'] = $width;
             $report_items[$index_key]['height'] = $height;
             $report_items[$index_key]['stile_quantity'] = $report_items[$index_key]['quantity'] * 2;
             $report_items[$index_key]['stile_width'] = $door_detail['door_stile_width'];
             if (!$is_it_drawer || $is_it_drawer && $height >= 170) {
                 $report_items[$index_key]['stile_height'] = $height + $door_detail['door_stile_offset'];
             } else {
                 $report_items[$index_key]['stile_height'] = $height + $door_detail['drawer_stile_offset'];
             }
             $report_items[$index_key]['rail_quantity'] = $report_items[$index_key]['quantity'] * 2;
             $report_items[$index_key]['rail_width'] = $door_detail['door_rail_width'];
             if (!$is_it_drawer || $is_it_drawer && $height >= 170) {
                 $report_items[$index_key]['rail_height'] = $report_items[$index_key]['height'] + $door_detail['door_rail_offset'];
             } else {
                 $report_items[$index_key]['rail_height'] = $height + $door_detail['drawer_rail_offset'];
             }
             $report_items[$index_key]['panel_quantity'] = $report_items[$index_key]['quantity'];
             $report_items[$index_key]['panel_width'] = $report_items[$index_key]['width'] + $door_detail['door_panel_width_offset'];
             if (!$is_it_drawer || $is_it_drawer && $height >= 170) {
                 $report_items[$index_key]['panel_height'] = $report_items[$index_key]['height'] + $door_detail['door_panel_height_offset'];
             } else {
                 $report_items[$index_key]['panel_height'] = $height + $door_detail['drawer_panel_height_offset'];
             }
         }
     }
 }
 public function calculateCabinetPriceForBuilder($cabinet_id, $cabinet_color, $material_id, $door_id, $door_color, $drawer_id, $drawer_slide_id, $quantity = 1, $delivery_option = '', $delivery_charge = 0)
 {
     App::import("Model", "Inventory.Cabinet");
     App::uses("Material", "Inventory.Model");
     App::uses("Door", "Inventory.Model");
     App::uses("Color", "Inventory.Model");
     App::import("Model", "Inventory.Item");
     App::import("Model", "Inventory.CabinetsItem");
     App::import("Model", "Inventory.InventoryLookup");
     $cabinet_id = Sanitize::escape($cabinet_id);
     $material_id = Sanitize::escape($material_id);
     $door_id = Sanitize::escape($door_id);
     $door_color = Sanitize::escape($door_color);
     $cabinet_color = Sanitize::escape($cabinet_color);
     $drawer_id = Sanitize::escape($drawer_id);
     $drawer_slide_id = Sanitize::escape($drawer_slide_id);
     $debug_calculation = '';
     $cabinets_items_model = new CabinetsItem();
     $cabinets_items_model->recursive = 1;
     $cabinets_items = $cabinets_items_model->find('all', array('conditions' => array('cabinet_id' => $cabinet_id, 'accessories' => '0')));
     $cabinets_accessories = $cabinets_items_model->find('all', array('conditions' => array('cabinet_id' => $cabinet_id, 'accessories' => '1')));
     if (!empty($cabinet_id)) {
         $cabinet = new Cabinet();
         $cabinet_detail = $cabinet->find('first', array('conditions' => array('id' => $cabinet_id)));
     }
     // predefined values
     $debug_calculation .= "Blum Up Charge = {$this->bulm_up_charge} <br />";
     $debug_calculation .= "Default Markup Factor = {$this->default_markup} <br />";
     $debug_calculation .= "<br />";
     // calculate cabinet sqft
     $item_model = new Item();
     $cabinet_sqft = $this->calculateCabinetSQFTForBuilder($cabinets_items, $item_model, $material_id);
     $debug_calculation .= "Cabinet SQFT = {$cabinet_sqft} <br />";
     $debug_calculation .= "<br />";
     // calculate cabinet sqft
     $panel_sqft = $this->calculatePanelSQFTForBuilder($cabinets_items);
     $debug_calculation .= "Panel SQFT = {$panel_sqft} <br />";
     $debug_calculation .= "<br />";
     // calculate cabinet sqft
     $box_total = $this->calculateBoxTotalForBuilder($cabinets_items, $door_id, $drawer_id, $drawer_slide_id);
     $debug_calculation .= "<b>Box Total Price = {$box_total} </b><br />";
     $debug_calculation .= "<br />";
     // get door color price
     $door_color_price = 0;
     $door_color_detail = array();
     if (!empty($door_color)) {
         $color = new Color();
         $door_color_detail = $color->find('first', array('conditions' => array('id' => $door_color)));
         if (isset($door_color_detail['ColorSection']) && !empty($door_color_detail['ColorSection']) && is_array($door_color_detail['ColorSection'])) {
             foreach ($door_color_detail['ColorSection'] as $color_section) {
                 if ($color_section['type'] == 'door_material') {
                     $door_color_price = $color_section['price'];
                     break;
                 }
             }
         }
         unset($door_color_detail);
         // clean up
         unset($color);
         // clean up
     }
     // get cabinet color price
     $cabinet_color_price = 0;
     $cabinet_price_color = 0;
     $panel_price_color = 0;
     $cabinet_color_detail = array();
     if (!empty($cabinet_color)) {
         $color = new Color();
         $cabinet_color_detail = $color->find('first', array('conditions' => array('id' => $cabinet_color)));
         if (isset($cabinet_color_detail['ColorSection']) && !empty($cabinet_color_detail['ColorSection']) && is_array($cabinet_color_detail['ColorSection'])) {
             foreach ($cabinet_color_detail['ColorSection'] as $color_section) {
                 //          if ($color_section['type'] == 'cabinet_material') {
                 if ($color_section['type'] == 'cabinate_material') {
                     $cabinet_color_price = $color_section['price'];
                     $cabinet_price_color = $cabinet_color_price * $cabinet_sqft;
                     $debug_calculation .= "Cabinet Color Price = {$cabinet_color_price} <br />";
                     $debug_calculation .= "<b>Cabinet Price (Color) = {$cabinet_price_color} </b><br />";
                     $panel_price_color = $cabinet_color_price * $panel_sqft;
                     $debug_calculation .= "<b>Panel Price (Color) = {$panel_price_color} </b><br />";
                     $debug_calculation .= "<br />";
                     break;
                 }
             }
         }
         unset($cabinet_color_detail);
         // clean up
         unset($color);
         // clean up
     }
     $doors_drawers_price = 0;
     if (!empty($door_id)) {
         $door = new Door();
         $door_detail = $door->find('first', array('conditions' => array('Door.id' => $door_id)));
         $door_cost_markup = $door_detail['Door']['cost_markup_factor'];
         $door_drawers = array();
         $debug_calculation .= "Door/Drawer Cost Markup = {$door_cost_markup} <br />";
         $debug_calculation .= "<br />";
         $door_drawers['top_door'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['top_door_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['top_door_height'];
             $width = (double) $cabinet_detail['Cabinet']['top_door_width'];
             $count = (double) $cabinet_detail['Cabinet']['top_door_count'];
             $price_sqft = (double) $door_detail['Door']['wall_door_price'];
             $price_each = (double) $door_detail['Door']['wall_door_price_each'];
             $label = 'Top Door';
             $door_drawers['top_door'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each);
             $debug_calculation .= "<br />";
         }
         $door_drawers['bottom_door'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['bottom_door_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['bottom_door_height'];
             $width = (double) $cabinet_detail['Cabinet']['bottom_door_width'];
             $count = (double) $cabinet_detail['Cabinet']['bottom_door_count'];
             $price_sqft = (double) $door_detail['Door']['door_price'];
             $price_each = (double) $door_detail['Door']['door_price_each'];
             $label = 'Bottom Door';
             $door_drawers['bottom_door'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each);
             $debug_calculation .= "<br />";
         }
         $door_drawers['top_drawer_front'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['top_drawer_front_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['top_drawer_front_height'];
             $width = (double) $cabinet_detail['Cabinet']['top_drawer_front_width'];
             $count = (double) $cabinet_detail['Cabinet']['top_drawer_front_count'];
             $price_sqft = (double) $door_detail['Door']['drawer_price'];
             $price_each = (double) $door_detail['Door']['drawer_price_each'];
             $label = 'Top Drawer Front';
             $door_drawers['top_drawer_front'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each, true);
             $debug_calculation .= "<br />";
         }
         $door_drawers['middle_drawer_front'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['middle_drawer_front_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['middle_drawer_front_height'];
             $width = (double) $cabinet_detail['Cabinet']['middle_drawer_front_width'];
             $count = (double) $cabinet_detail['Cabinet']['middle_drawer_front_count'];
             $price_sqft = (double) $door_detail['Door']['lower_drawer_price'];
             $price_each = (double) $door_detail['Door']['lower_drawer_price_each'];
             $label = 'Middle Drawer Front';
             $door_drawers['middle_drawer_front'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each, true);
             $debug_calculation .= "<br />";
         }
         $door_drawers['bottom_drawer_front'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['bottom_drawer_front_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['bottom_drawer_front_height'];
             $width = (double) $cabinet_detail['Cabinet']['bottom_drawer_front_width'];
             $count = (double) $cabinet_detail['Cabinet']['bottom_drawer_front_count'];
             $price_sqft = (double) $door_detail['Door']['lower_drawer_price'];
             $price_each = (double) $door_detail['Door']['lower_drawer_price_each'];
             $label = 'Bottom Drawer Front';
             $door_drawers['bottom_drawer_front'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each, true);
             $debug_calculation .= "<br />";
         }
         $door_drawers['dummy_drawer_front'] = array('sqft' => 0, 'price' => 0);
         if (!empty($cabinet_detail['Cabinet']['dummy_drawer_front_count'])) {
             $height = (double) $cabinet_detail['Cabinet']['dummy_drawer_front_height'];
             $width = (double) $cabinet_detail['Cabinet']['dummy_drawer_front_width'];
             $count = (double) $cabinet_detail['Cabinet']['dummy_drawer_front_count'];
             $price_sqft = (double) $door_detail['Door']['drawer_price'];
             $price_each = (double) $door_detail['Door']['drawer_price_each'];
             $label = 'Dummy Drawer Front';
             $door_drawers['dummy_drawer_front'] = $this->calculateDoorDrawerForBuilder($debug_calculation, $label, $height, $width, $count, $door_cost_markup, $price_sqft, $price_each, true);
             $debug_calculation .= "<br />";
         }
         //      $debug = var_export($door_drawers, true);
         //      $debug_calculation .= "Door/Drawer Price = {$debug} <br />";
         $doors_drawers_price = $this->sumDoorDrawer($door_drawers);
         $debug_calculation .= "<b>Door/Drawer Price = {$doors_drawers_price} </b><br />";
         $debug_calculation .= "<b>Bulm up Charge Total Price = {$this->bulm_up_charge_total} </b><br />";
         $debug_calculation .= "<br />";
         if ($door_color_price) {
             $debug_calculation .= "Door Color Price = {$door_color_price} <br />";
             $debug_calculation .= "<br />";
             $doors_drawers_price_color = $this->sumDoorDrawerColorForBuilder($debug_calculation, $door_drawers, $door_color_price);
             $doors_drawers_price += $doors_drawers_price_color;
             $debug_calculation .= "<br />";
             $debug_calculation .= "<b>Door/Drawer Price (Color) = {$doors_drawers_price_color} </b><br />";
             $debug_calculation .= "<br />";
         }
         unset($door);
         // clean up
     }
     $inventory_lookup = new InventoryLookup();
     $inventory_lookup->recursive = -1;
     $drawer_departments = array();
     $inventory_lookup_detail = $inventory_lookup->find('all', array('conditions' => array('InventoryLookup.lookup_type' => 'drawer')));
     foreach ($inventory_lookup_detail as $inventory_lookup_row) {
         $departments = $inventory_lookup->SearchCache2Array($inventory_lookup_row['InventoryLookup']['department_id']);
         foreach ($departments as $department) {
             if (isset($drawer_departments[$department])) {
                 $drawer_departments[$department][] = $inventory_lookup_row['InventoryLookup']['id'];
             } else {
                 $drawer_departments[$department] = array($inventory_lookup_row['InventoryLookup']['id']);
             }
         }
     }
     $item = new Item();
     $items_price = 0;
     $discount = 0;
     $items = array();
     if (!empty($cabinet_detail['CabinetsItem'])) {
         foreach ($cabinet_detail['CabinetsItem'] as $cabinet_item) {
             if ($cabinet_item['accessories']) {
                 continue;
             }
             // skip the accessories
             $item_detail = $item->find('first', array('conditions' => array('Item.id' => $cabinet_item['item_id'])));
             if (array_key_exists($item_detail['Item']['item_department_id'], $drawer_departments)) {
                 if (!in_array($drawer_id, $drawer_departments[$item_detail['Item']['item_department_id']])) {
                     continue;
                     // skip the un-selected drawer
                 }
             }
             $item_price = $item_detail['Item']['builder_price'];
             //				$item_price = $item_detail['Item']['price'];
             $ItemMaterialPrice = null;
             if (isset($material_id) && !empty($material_id)) {
                 $ItemMaterialPrice = $this->getItemMaterialPriceForBuilder($item, $cabinet_item['item_id'], $material_id, $debug_calculation);
                 $item_price = $ItemMaterialPrice['item_price'];
             }
             //Discount
             //                if( $delivery_option == '5 – 10 Weeks Delivery' ) {
             //                    $discount = $item_price * $this->default_discount;
             //                    $item_price = $item_price - $discount;
             //                }
             $item_calculated_price = $cabinet_item['item_quantity'] * $item_price;
             $items_price += $item_calculated_price;
             if ($ItemMaterialPrice['sub_item']) {
                 $debug_calculation .= "Cabinet Item ({$ItemMaterialPrice['sub_item']['Item']['item_title']}) Price = {$ItemMaterialPrice['material_data']['Material']['price']} => Quantity = {$cabinet_item['item_quantity']} => Total = {$item_calculated_price} <br />";
             } else {
                 $debug_calculation .= "Cabinet Item ({$item_detail['Item']['item_title']}) Price = {$item_price} => Quantity = {$cabinet_item['item_quantity']} => Total = {$item_calculated_price} <br />";
             }
             //        $items[] = array(
             //            'id' => $item_detail['Item']['id'],
             //            'item_title' => $item_detail['Item']['item_title'],
             //            'price' => $item_price,
             //            'base_price' => $item_detail['Item']['price'],
             //            'quantity' => $cabinet_item['item_quantity'],
             //        );
         }
         $debug_calculation .= "<b>Cabinet Item Price = {$items_price} </b><br />";
         $debug_calculation .= "<br />";
         unset($cabinet_detail);
         // clean up
     }
     $total_price = ($items_price + $cabinet_price_color + $panel_price_color + $doors_drawers_price + $this->bulm_up_charge_total) * $this->default_markup * $quantity;
     $discount_rate = $this->getProductionTime($delivery_option);
     $discount = $total_price * $discount_rate;
     $total_price = $total_price - $discount;
     $debug_calculation .= "<b>Discount = {$discount} </b><br />";
     $debug_calculation .= "<b>Total Price = {$total_price} </b><br />";
     $result = array('items_price' => $items_price, 'doors_price' => $doors_drawers_price, 'cabinet_color_price_color' => $cabinet_price_color, 'total_price' => $total_price, 'debug_calculation' => $debug_calculation, 'conditions' => array('resource_id' => $cabinet_id, 'resource_type' => 'cabinet', 'material_id' => $material_id, 'door_id' => $door_id, 'door_color' => $door_color, 'cabinet_color' => $cabinet_color, 'drawer_slide_id' => $drawer_slide_id, 'drawer_id' => $drawer_id, 'quantity' => $quantity));
     return $result;
 }