public function createLead(Request $request) { $lead = new Lead(); $lead->name = $request->name; $lead->activity_setting = $request->setting; if ($request->next_action) { $lead->next_action = Carbon::createFromFormat('m/d/Y g:i A', $request->next_action)->toDateTimeString(); } else { $lead->next_action = null; } $lead->active = 1; $lead->progress = 0; $lead->level = 0; $lead->save(); $entity = new Entity(); $entity->name = $request->entity['name']; $entity->type = $request->entity['type']; $entity->save(); $lead->entity_id = $entity->id; $lead->save(); $user = User::find($request->userId); $user->leads()->attach($lead); $account = Account::find($user->account_id); $account->entities()->attach($entity); foreach ($request->entity['entity_data'] as $eData) { $entityData = new EntityData(); $entityData->key = $eData['key']; $entityData->value = $eData['value']; $entityData->name = $eData['name']; $entityData->entity_id = $entity->id; $entityData->type = strtolower($eData['type']); //TODO $entityData->save(); } foreach ($request->entity['contacts'] as $cntct) { $contact = new Contact(); $contact->email = $cntct['email']; $contact->first_name = $cntct['first_name']; $contact->last_name = $cntct['last_name']; $contact->title = $cntct['title']; $contact->type = $cntct['type']; $contact->entity_id = $entity->id; $contact->save(); foreach ($cntct['addresses'] as $adr) { $address = new Address(); $address->name = $adr['name']; $address->full_string = $adr['full_string']; $address->contact_id = $contact->id; $address->save(); foreach ($adr['phones'] as $ph) { $phone = new Phone(); $phone->number = $ph['number']; $phone->available_from = $ph['available_from']; $phone->available_to = $ph['available_to']; $phone->type = $ph['type']; $phone->address_id = $address->id; $phone->save(); } } } $activity = new Activity(); $activity->lead_id = $lead->id; $activity->user_id = $user->id; $activity->type = 'info'; $activity->status = 'done'; $activity->name = 'Created'; $activity->visible = 1; $activity->note = $request->note; $activity->schedule_time = Carbon::now()->toDateTimeString(); $activity->save(); }
public function entity_data($num, $entity_id) { for ($i = 0; $i < $num; $i++) { $item = new EntityData(); $item->type = $this->faker->randomElement($array = array('input', 'select', 'text')); if ($item->type == 'input') { $item->name = $this->faker->randomElement($array = array('Sales Volume', 'License', 'Group', 'Product Type', 'Credit Rating', 'Service')); $item->key = strtolower($item->name); $item->value = $this->faker->word(); } elseif ($item->type == 'select') { $item->name = $this->faker->randomElement($array = array('Sales Volume', 'License', 'Group', 'Product Type', 'Credit Rating', 'Service')); $item->key = strtolower($item->name); $item->value = $this->faker->word(); } else { $item->name = 'about'; $item->key = strtolower($item->name); $item->value = $this->faker->text(30); } $item->entity_id = $entity_id; $item->save(); } }
public function changeLeadInfo(Request $request) { $item = EntityData::find($request->entity); $item->value = $request->value; $item->save(); }