Пример #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
 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);
                 }
             });
         }
     }
 }