예제 #1
0
 public function invoiceRecord()
 {
     // get parameters from url route
     $parameters = $this->request->route()->parameters();
     // get billing object
     $billing = Billing::builder()->find($parameters['id']);
     if (empty($billing->price_091)) {
         $price = (double) Preference::getValue('projectsHourPrice', 6)->value_018 * $billing->hours_091;
     } else {
         $price = $billing->price_091;
     }
     $history = History::create(['user_id_093' => $billing->user_id_091, 'user_name_093' => $billing->user_name_091, 'type_id_093' => $billing->type_id_091, 'project_id_093' => null, 'customer_id_093' => $billing->customer_id_091, 'customer_name_093' => $billing->customer_name_091, 'title_093' => $billing->title_091, 'description_093' => $billing->description_091, 'price_093' => $price, 'request_date_093' => $billing->request_date_091, 'request_date_text_093' => $billing->request_date_text_091, 'end_date_093' => $billing->end_date_091, 'end_date_text_093' => $billing->end_date_text_091, 'hours_093' => $billing->hours_091]);
     // create invoiced from todo_
     Invoiced::create(['date_094' => date('U'), 'date_text_094' => date(config('pulsar.datePattern')), 'customer_id_094' => $billing->customer_id_091, 'customer_name_094' => $billing->customer_name_091, 'type_id_094' => $billing->type_id_091, 'project_id_094' => null, 'history_id_094' => $history->id_093, 'price_094' => $price]);
     // destroy billing
     Billing::destroy($billing->id_092);
     // destroy todo_ from user section
     Todo::destroy($billing->todo_id_092);
     return redirect()->route('projectsBilling', ['offset' => $parameters['offset']])->with(['msg' => 1, 'txtMsg' => trans('projects::pulsar.message_successfully_invoiced')]);
 }
예제 #2
0
 public function updateCustomRecord($parameters)
 {
     if ($this->request->has('projectId')) {
         $project = Project::builder()->find($this->request->input('projectId'));
         $customerId = $project->customer_id_090;
         $customerName = $project->customer_name_090;
     } else {
         $customerId = $this->request->input('customerId');
         $customerName = $this->request->input('customerName');
     }
     // check that has hours if endDate exist
     if ($this->request->has('endDate')) {
         $validation = History::validate(['hours' => $this->request->input('hours')], ['hoursRule' => true]);
         if ($validation->fails()) {
             return redirect()->route('edit' . ucfirst($this->routeSuffix), ['id' => $parameters['id'], 'offset' => $parameters['offset']])->withErrors($validation);
         }
     }
     // TODO, contemplar cuando se cambie las horas o de projecto, se recalcule las horas del proyecto
     // 1 - project
     //        if($this->request->input('type') == 1)
     //        {
     //            $history = History::builder()->find($parameters['id']);
     //            if($history->hours_093 != $this->request->input('hours'))
     //            {
     //                $newHours = $history->hours_093 - $this->request->input('hours');
     //            }
     //        }
     History::where('id_093', $parameters['id'])->update(['user_id_093' => $this->request->input('userId'), 'user_name_093' => $this->request->input('userName'), 'title_093' => $this->request->input('title'), 'description_093' => $this->request->has('description') ? $this->request->input('description') : null, 'type_id_093' => $this->request->input('type'), 'project_id_093' => $this->request->has('projectId') ? $this->request->input('projectId') : null, 'customer_id_093' => $customerId, 'customer_name_093' => $customerName, 'hours_093' => $this->request->has('hours') ? $this->request->input('hours') : null, 'price_093' => $this->request->has('price') ? $this->request->input('price') : null, 'request_date_093' => $this->request->has('requestDate') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $this->request->input('requestDate'))->getTimestamp() : null, 'request_date_text_093' => $this->request->has('requestDate') ? $this->request->input('requestDate') : null, 'end_date_093' => $this->request->has('endDate') ? \DateTime::createFromFormat(config('pulsar.datePattern'), $this->request->input('endDate'))->getTimestamp() : null, 'end_date_text_093' => $this->request->has('endDate') ? $this->request->input('endDate') : null]);
 }
예제 #3
0
 private function endTodo($todo)
 {
     // if has enDate, so user has finished tour todo_
     if ($todo->finished_091) {
         // 1 - project
         if ($todo->type_id_091 == 1) {
             // updates hour projects
             $project = Project::builder()->find($todo->project_id_091);
             Project::where('id_090', $todo->project_id_091)->update(['consumed_hours_090' => $project->consumed_hours_090 + $todo->hours_091, 'total_hours_090' => $project->total_hours_090 - $todo->hours_091]);
             History::create(['user_id_093' => $todo->user_id_091, 'user_name_093' => $todo->user_name_091, 'type_id_093' => $todo->type_id_091, 'project_id_093' => $todo->project_id_091, 'customer_id_093' => $todo->customer_id_091, 'customer_name_093' => $todo->customer_name_091, 'title_093' => $todo->title_091, 'description_093' => $todo->description_091, 'price_093' => $todo->price_091, 'request_date_093' => $todo->request_date_091, 'request_date_text_093' => $todo->request_date_text_091, 'end_date_093' => $todo->end_date_091, 'end_date_text_093' => $todo->end_date_text_091, 'hours_093' => $todo->hours_091]);
             // delete todo_, after register history
             Todo::destroy($todo->id_091);
         } elseif ($todo->type_id_091 == 2) {
             $billing = Billing::create(['todo_id_092' => $todo->id_091, 'user_id_092' => $todo->user_id_091, 'user_name_092' => $todo->user_name_091, 'customer_id_092' => $todo->customer_id_091, 'customer_name_092' => $todo->customer_name_091, 'title_092' => $todo->title_091, 'description_092' => $todo->description_091, 'request_date_092' => $todo->request_date_091, 'request_date_text_092' => $todo->request_date_text_091, 'end_date_092' => $todo->end_date_091, 'end_date_text_092' => $todo->end_date_text_091, 'hours_092' => $todo->hours_091, 'price_092' => $todo->price_091]);
             // envío de notificación
             $notificationsAccount = Preference::getValue('projectsNotificationsAccount', 6);
             $emailAccount = EmailAccount::find($notificationsAccount->value_018);
             if ($emailAccount == null) {
                 return null;
             }
             config(['mail.host' => $emailAccount->outgoing_server_013]);
             config(['mail.port' => $emailAccount->outgoing_port_013]);
             config(['mail.from' => ['address' => $emailAccount->email_013, 'name' => $emailAccount->name_013]]);
             config(['mail.encryption' => $emailAccount->outgoing_secure_013 == 'null' ? null : $emailAccount->outgoing_secure_013]);
             config(['mail.username' => $emailAccount->outgoing_user_013]);
             config(['mail.password' => Crypt::decrypt($emailAccount->outgoing_pass_013)]);
             $users = User::builder()->where('profile_id_010', (int) Preference::getValue('projectsBillingProfile', 6)->value_018)->where('access_010', true)->get();
             $nameTo = '';
             foreach ($users as $key => $user) {
                 $nameTo .= $user->name_010 . ' ' . $user->surname_010;
                 if ($key < count($users) - 1) {
                     $nameTo .= ', ';
                 }
             }
             $dataMessage = ['nameTo' => $nameTo, 'users' => $users, 'subject' => 'Notificación de facturación de tarea', 'billing' => $billing];
             Mail::send('projects::emails.billing_notification', $dataMessage, function ($m) use($dataMessage) {
                 $m->subject($dataMessage['subject']);
                 foreach ($dataMessage['users'] as $user) {
                     $m->to($user->email_010, $user->name_010 . ' ' . $user->surname_010);
                 }
             });
         }
     }
 }