public function destroy($id) { $renter = Renter::findOrFail($id); $contract = Contract::where('renter_id', '=', $id)->delete(); $renter->delete(); return redirect('renters'); }
public function destroy($id) { $property = Property::findOrFail($id); $contract = Contract::where('property_id', '=', $id)->delete(); $property->delete(); return redirect('properties'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $ret['status'] = 1; $this->validate($request, ['id' => 'required|numeric', 'name' => 'required|max:255', 'type' => 'required|numeric', 'assign_type' => 'required|numeric', 'fee' => 'required|numeric', 'alert' => 'required|numeric'], ['required' => 'The :attribute field is required', 'numeric' => 'The :attribute field must be numeric', 'max' => 'The length of :attribute can not bigger than 255']); $feePlanInput = $request->all(); if ($feePlanInput['assign_type'] == 1) { $allContracts = Contract::all(); } else { if ($feePlanInput['assign_type'] == 2) { $allContracts = Contract::where('building_id', $feePlanInput['building_id'])->get(); } } $feePlansArr = array(); foreach ($allContracts as $contract) { $feePlan['feemeta_id'] = $feePlanInput['id']; $feePlan['rent_id'] = $contract['id']; $feePlan['room_id'] = $contract['room_id']; $feePlan['building_id'] = $contract['building_id']; $feePlan['fee_name'] = $feePlanInput['name']; $feePlan['fee'] = $feePlanInput['fee']; $feePlan['status'] = 0; $feePlan['user_id'] = $this->user['id']; $feePlan['type'] = $feePlanInput['type']; if (FeeMeta::isYearlyType($feePlan['type'])) { $feePlan['fee_start_date'] = $contract['start_time']; $feePlan['fee_end_date'] = $contract['end_time']; $alertDate = new \DateTime($feePlan['fee_start_date']); $alertDate->add(new \DateInterval('P' . $feePlanInput['days'] . 'D')); $feePlan['fee_alert_date'] = $alertDate; } else { $feePlan['fee_alert_date'] = $feePlanInput['fee_alert_date']; $feePlan['fee_start_date'] = $feePlanInput['fee_start_date']; $feePlan['fee_end_date'] = $feePlanInput['fee_end_date']; } if (FeePlan::checkNotExistPlanned($feePlan)) { //build up the feeplan data and push to a array array_push($feePlansArr, $feePlan); } } if (count($feePlansArr) > 0) { $ret['status'] = FeePlan::insert($feePlansArr); if (!$ret['status']) { abort(500, 'Could not save fee plans'); } } else { $ret['status'] = 0; $ret['desc'] = "All of the room has this kind of fee already"; } return $ret; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($buildingId) { // $rooms = Room::with("building") $rooms = Room::where('building_id', $buildingId)->get(); $today = new \DateTime('today'); foreach ($rooms as &$room) { $contract = Contract::where('room_id', $room['id'])->where('end_time', '>=', $today)->get(); if ($contract->count() > 0) { $room['hasContract'] = 1; $room['contract'] = $contract[0]; } else { $room['hasContract'] = 0; } } return $rooms; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $rooms = Room::with(["building" => function ($query) { $query->select('name', 'id', 'building_sn'); }])->get(); $today = new \DateTime('today'); foreach ($rooms as &$room) { $contract = Contract::where('room_id', $room['id'])->where('end_time', '>=', $today)->get(); if ($contract->count() > 0) { $room['hasContract'] = 1; $room['contract'] = $contract[0]; } else { $room['hasContract'] = 0; } } return $rooms; }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $buildings = Building::all(); $today = new \DateTime('today'); foreach ($buildings as &$building) { $roomsCount = Room::where("building_id", $building['id'])->count(); $contractsCount = Contract::where('building_id', $building['id'])->where('end_time', '>=', $today)->count(); $building['contractsNumber'] = $contractsCount; $building['emptyNumber'] = $roomsCount - $contractsCount; $building['rooms_count'] = $roomsCount; if ($building['emptyNumber'] > 0) { $building['hasEmptyRoom'] = 1; } else { $building['hasEmptyRoom'] = 0; } } return $buildings; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['room_name' => 'required|max:255', 'room_sn' => 'required|max:255', 'building_sn' => 'required|max:255', 'contractor_name' => 'required|max:255', 'contractor_location' => 'max:255', 'id_number' => 'required|max:255', 'room_id' => 'required|numeric', 'phone' => 'required|numeric', 'water_degree' => 'required|numeric', 'electric_degree' => 'required|numeric', 'building_id' => 'required|numeric', 'start_time' => 'required|date', 'end_time' => 'required|date'], ['required' => 'The :attribute field is required', 'numeric' => 'The :attribute field must be numeric', 'max' => 'The length of :attribute can not bigger than 255', 'date' => 'The :attribute field must be date format']); $contractInput = $request->all(); $startTime = new \DateTime($contractInput['start_time']); $contract_number = $startTime->format('Ymd') . '-' . $contractInput['building_sn'] . $contractInput['room_sn']; unset($contractInput['building_sn']); unset($contractInput['room_sn']); $contract = new Contract($contractInput); $contract['user_id'] = $this->user['id']; $contract['contractor_number'] = $contract_number; //Just confirm no dirty data, a room can't contract with more than one user, so delete old ones. Contract::where("room_id", $contract['room_id'])->delete(); //Do the save action. if (!$contract->save()) { abort(500, 'Could not save contract'); } return $contract; }
public function destroy($id) { $contract = Contract::where($id, '=', 'id')->delete(); return redirect('contracts'); }
/** * Execute the console command. * * @return mixed */ public function handle() { // Get contracts that are still active. $contracts = Contract::where('State', '!=', 'used')->where('State', '!=', 'cancelled')->where('State', '!=', 'paid')->get(); foreach ($contracts as $contract) { // Check if we have visited this month. if ($contract->Visited) { // Check if we should reset this. if ($contract->QuotaInterval == 'mensuales') { if ('01' == date('d')) { $contract->Visited = false; $contract->save(); } } else { if ($contract->QuotaInterval == 'quincenales') { if ('01' == date('d')) { $contract->Visited = false; $contract->save(); } else { if ('16' == date('d')) { $contract->Visited = false; $contract->save(); } } } else { if (date('D') == 'Mon') { $contract->Visited = false; $contract->save(); } } } } // Check if we need to organize a visit for this contract. if (!$contract->Visited) { if ($contract->StartDate < date('Y-m-d')) { $visitDates = explode(',', $contract->PaymentDates); foreach ($visitDates as $date) { if ($date == date('d', strtotime("+3 days"))) { // Check if we already have a visit programmed for this contract. $transports = Transport::where('Type', '=', '8')->where('ReasonId', '=', $contract->Id)->where('Date', '=', date('Y-m-d', strtotime("+3 days")))->get(); if (count($transports) == 0) { // Get an appropriate vehicle for this. $vehicles = Vehicle::where('BranchId', '=', $contract->BranchId)->where('Repair', '=', false)->get(); $vehicle = null; foreach ($vehicles as $v) { if (!$vehicle) { $vehicle = $v; } // In this case the smaller the vehicle the more suitable it should be. // TODO: This could be improved. if ($v->Type < $vehicle->Type) { $vehicle = $v; } } if (!$vehicle) { // In this case we don't have a vehicle and the provider doesn't provide delivery so we must notify an administrator. $users = User::where('UserLevel', '=', 1)->get(); foreach ($users as $admin) { Notification::create(array('UserId' => $admin->Id, 'Created' => date('Y-m-d H:i:s'), 'Reason' => 'Aergia no fue capaz de organizar el cobro para el contrato ' . $contract->Code . '. Por favor revisar y organizar el cobro de la cuota de este contrato.', 'Url' => '/contract/' . $contract->Id, 'Seen' => false)); } } else { // Get location of client. $client = Client::find($contract->ClientId); $location = Location::find($client->LocationId); $transport = Transport::create(array('Date' => date('Y-m-d', strtotime("+3 day")), 'Time' => '00:00:00', 'VehicleId' => $vehicle->Id, 'DriverId' => 0, 'StartLatitude' => 0, 'StartLongitude' => 0, 'Journey' => '[]', 'EndLatitude' => $location->Latitude, 'EndLongitude' => $location->Longitude, 'EndAddress' => $client->Address, 'Distance' => 0, 'ReasonId' => $contract->Id, 'Type' => 8, 'State' => 2, 'Order' => 0, 'Depreciation' => 0)); // Inform creditor of when you shall collect payment. if ($client->Email != '') { Mail::send('emails.ai.contractReminder', ['contract' => $contract, 'transport' => $transport], function ($message) use($contract, $client) { $message->to($client->Email); $message->subject('Cobro de Cuota de Contrato: ' . $contract->Code); }); } } } } } } } // TODO: Not sure if I want to do something in these cases. switch ($contract->State) { case 'usedpending': break; case 'late': break; } } }
<?php use App\Contract; use App\Client; use App\CashReceipt; // Get contracts. $contracts = array(); if (isset($contractCode) && $contractCode != '') { $contracts = Contract::where('Code', '=', $contractCode)->get(); } else { if (isset($contractClient) && $contractClient != '') { $client = Client::where('Cedula', '=', $contractClient)->first(); $contracts = Contract::where('ClientId', '=', $client->Id)->get(); } else { if (isset($contractState) && $contractState != '') { $contracts = Contract::where('State', '=', $contractState)->get(); } } } function contractInterval($interval) { // Default will be Monthly. $intervalC = 'Mensual'; // Check if it is anything but monthly and assign text accordingly. if ($interval == 'quincenales') { $intervalC = 'Quincenal'; } else { if ($interval == 'semanales') { $intervalC = 'Semanal'; } }