/** * Add method * * @return void Redirects on successful add, renders view otherwise. */ public function add() { if ($this->request->is('post')) { $data_array = array(); for ($i = 0; $i < sizeof($this->request->data['date']); $i++) { $montant = $this->request->data['montant'][$i]; if ($this->request->data['transfere'][$i] === 'Credit') { $montant = $montant * -1; } // $time = new Time($this->request->data['date'][$i]); $time = Time::createFromFormat('d/m/Y', $this->request->data['date'][$i]); $data_array[] = array('datoper' => $time, 'montant' => $montant, 'libelle' => $this->request->data['libelle'][$i], 'id_client' => $id = $this->Auth->user()['id_client'], 'id_type_compte' => trim(explode('-', $this->request->data['compte'][$i])[0])); } $entities = $this->Operations->newEntities($data_array); $this->set('entities', $entities); //debug($entities); $success = 0; $fail = 0; foreach ($entities as $entity) { // Save entity if ($this->Operations->save($entity)) { $success++; } else { $fail++; } } if ($success > 0) { if ($success == 1) { $this->Flash->success('<i class="md-icon material-icons" style="color:white"></i> ' . $success . ' operation a bien été sauvegardée.'); } else { $this->Flash->success('<i class="md-icon material-icons" style="color:white"></i> ' . $success . ' operations ont bien été sauvegardées.'); } } if ($fail > 0) { if ($fail == 1) { $this->Flash->error('<i class="md-icon material-icons" style="color:white"></i> ' . $fail . ' operation n\'a pas pu être sauvegardé, Veuillez verifier l\'historique des opérations.'); } else { $this->Flash->error('<i class="md-icon material-icons" style="color:white"></i> ' . $fail . ' operations n\'ont pas pu être sauvegardés, Veuillez verifier l\'historique des opérations.'); } } } //$this->autoRender = false ; return $this->redirect(['action' => 'index']); $this->set(compact('operation')); $this->set('_serialize', ['operation']); }
/** * Handler method that applies before dispatch. * * @param \Cake\Event\Event $event The event instance. * @return mixed */ public function handle(Event $event) { if (is_file(MAINTENANCE_CONFIG_FILE) && is_readable(MAINTENANCE_CONFIG_FILE)) { // stop event $event->stopPropagation(); $request = $event->data['request']; $response = $event->data['response']; $config = (require MAINTENANCE_CONFIG_FILE); $viewClass = $config['viewClass']; $view = new $viewClass($request, $response); $view->templatePath($config['templatePath']); $view->template($config['templateFile']); $view->layout($config['templateLayout']); $view->set('startAt', \Cake\I18n\Time::createFromFormat('YmdHis', $config['startAt'])); $view->set('endAt', \Cake\I18n\Time::createFromFormat('YmdHis', $config['endAt'])); $response->body($view->render()); return $response; } }
/** * Edit method * * @param string|null $id Shipping id. * @return void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $shipping = $this->Shippings->get($id, ['contain' => []]); if ($this->request->is(['patch', 'post', 'put'])) { if ($this->request->data['laycan_com'] != null) { $this->request->data['laycan_com'] = Time::createFromFormat('m/d/Y', $this->request->data['laycan_com'], 'UTC'); $this->request->data['laycan_end'] = Time::createFromFormat('m/d/Y', $this->request->data['laycan_end'], 'UTC'); } $shipping = $this->Shippings->patchEntity($shipping, $this->request->data); if ($this->Shippings->save($shipping)) { $this->Flash->success(__('The shipping has been saved.')); return $this->redirect(['controller' => 'Fixtures', 'action' => 'view', $shipping->fixture_id]); } else { $this->Flash->error(__('The shipping could not be saved. Please, try again.')); } } $fixtures = $this->Shippings->Fixtures->find('list', ['limit' => 200]); $this->set(compact('shipping', 'fixtures')); $this->set('_serialize', ['shipping']); }
/** * Add method * * @return void Redirects on successful add, renders view otherwise. */ public function add() { $fixture = $this->Fixtures->newEntity(); if ($this->request->is('post')) { $this->request->data['cp_date'] = Time::createFromFormat('m/d/Y', $this->request->data['cp_date'], 'UTC'); $this->request->data['period_st'] = Time::createFromFormat('m/d/Y', $this->request->data['period_st'], 'UTC'); $this->request->data['period_nd'] = Time::createFromFormat('m/d/Y', $this->request->data['period_nd'], 'UTC'); $fixture = $this->Fixtures->patchEntity($fixture, $this->request->data); if ($this->Fixtures->save($fixture)) { $this->Flash->success(__('The fixture has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The fixture could not be saved. Please, try again.')); } } $users = $this->Fixtures->Users->find('list', ['limit' => 200]); $pics = $this->Fixtures->Pics->find('list', ['limit' => 200]); $charterers = $this->Fixtures->Charterers->find('list', ['limit' => 200]); $shipowners = $this->Fixtures->Shipowners->find('list', ['limit' => 200]); $this->set(compact('fixture', 'users', 'pics', 'charterers', 'shipowners')); $this->set('_serialize', ['fixture']); }
/** * Edit method * * @param string|null $id Calendar id. * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $calendar = $this->Calendars->get($id); $this->loadModel('Shows'); $show = $this->Shows->findById($calendar->show_id)->first(); if (!$calendar) { $this->Flash->error(__('Event not found!')); return $this->redirect(['action' => 'index']); } if (!$this->UserPerm->checkShow($this->Auth->user('id'), $calendar->show_id, 'is_cal')) { $this->Flash->error(__('You do not have access to this show')); return $this->redirect(['action' => 'index']); } if ($show->is_active < 1) { $this->Flash->error(__('Sorry, this show is now closed.')); return $this->redirect(['action' => 'index']); } if ($this->request->is(['patch', 'post', 'put'])) { $time = Time::createFromFormat('Y-m-d', $this->request->data['date'], 'UTC'); $this->request->data['date'] = $time; $d_worked = $time; $time = Time::createFromFormat('H:i', $this->request->data['start_time'], 'UTC'); $this->request->data['start_time'] = $time; $time = Time::createFromFormat('H:i', $this->request->data['end_time'], 'UTC'); $this->request->data['end_time'] = $time; $calendar = $this->Calendars->patchEntity($calendar, $this->request->data); if ($this->Calendars->save($calendar)) { $this->Flash->success(__('The event has been saved.')); return $this->redirect(['action' => 'view', $calendar->show_id]); } else { $this->Flash->error(__('The event could not be saved. Please, try again.')); } } $this->set('crumby', [["/", __("Dashboard")], ["/calendars/", __("Calendars")], ["/calendars/view/" . $show->id . "/" . date("Y") . "/" . date("m"), __("{0} Calendar", $show->name)], [null, __("Edit Event")]]); $shows = [$show->id => $show->name]; $this->set(compact('calendar', 'shows')); $this->set('_serialize', ['calendar']); }
public function filter() { $this->loadModel('Campuses'); $campuses = $this->Campuses->find('list'); $this->set('campuses', $campuses); if ($this->request->is('post')) { $data = $this->request->data; $order_date = Time::createFromFormat('d/m/Y', $data['order_date']); $menu = $this->Menus->find('all')->where(['menu_date' => $order_date, 'campus_id' => $data['campus_id']])->first(); $orders = $this->Orders->find('all', ['contain' => ['Users', 'Rooms', 'Menus'], 'condition' => ['menu_id' => $menu->id]]); $this->set('orders', $orders); } }
/** * Edit method * * @param string|null $id Show id. * @return void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { if (!$this->Auth->user('is_admin')) { $this->Flash->error(__('You may not edit shows')); return $this->redirect(['action' => 'index']); } $show = $this->Shows->get($id, ['contain' => []]); if ($this->request->is(['patch', 'post', 'put'])) { $time = Time::createFromFormat('Y-m-d', $this->request->data['end_date'], 'UTC'); $this->request->data['end_date'] = $time; $show = $this->Shows->patchEntity($show, $this->request->data); if ($this->Shows->save($show)) { $this->Flash->success(__('The show has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The show could not be saved. Please, try again.')); } } $this->set('crumby', [["/", __("Dashboard")], ["/shows/", __("Shows")], ["/shows/view/" . $show->id, $show->name], [null, __("Edit Show")]]); $this->set(compact('show')); $this->set('_serialize', ['show']); }
public function statement($id = null) { if (empty($this->request->query('begin_date'))) { $this->request->query['begin_date'] = Time::now()->subMonth()->format('d/m/Y'); } if (empty($this->request->query('end_date'))) { $this->request->query['end_date'] = Time::now()->format('d/m/Y'); } $begin_date = Time::createFromFormat('d/m/Y', $this->request->query('begin_date')); $end_date = Time::createFromFormat('d/m/Y', $this->request->query('end_date')); $this->request->data['begin_date'] = $begin_date->format('d/m/Y'); $this->request->data['end_date'] = $end_date->format('d/m/Y'); if ($begin_date->isToday()) { $begin_date->subHours(12); } $account = $this->Accounts->get($id); $account_statement = $this->Accounts->Statements->findByAccountId($id)->where(['Statements.created >=' => $begin_date, 'Statements.created <' => $end_date]); $total_statement = $account_statement->sumOf('value'); $this->set(compact('account_statement', 'account', 'total_statement', 'begin_date', 'end_date')); }
protected function getBirthdate($data) { if ($data['month'] === '0' || $data['day'] === '0' || $data['year'] === '1899') { return false; } $month = $data['month']; $day = $data['day']; $year = $data['year']; $format = 'm-d-Y'; $time = $month . '-' . $day . '-' . $year; $birthdate = Time::createFromFormat($format, $time); return $birthdate; }
/** * Edit method * * @param string|null $id Budget id. * @return void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $budget = $this->Budgets->get($id, ['contain' => []]); $this->loadModel('Shows'); $show = $this->Shows->findById($budget->show_id)->first(); if (!$show) { $this->Flash->error(__('Show not found!')); return $this->redirect(['action' => 'index']); } if (!$this->UserPerm->checkShow($this->Auth->user('id'), $budget->show_id, 'is_budget')) { $this->Flash->error(__('You do not have access to this show')); return $this->redirect(['action' => 'index']); } if ($show->is_active < 1) { $this->Flash->error(__('Sorry, this show is now closed.')); return $this->redirect(['action' => 'index']); } if ($this->request->is(['patch', 'post', 'put'])) { $time = Time::createFromFormat('Y-m-d', $this->request->data['date'], 'UTC'); $this->request->data['date'] = $time; $budget = $this->Budgets->patchEntity($budget, $this->request->data, ['fieldList' => ['vendor', 'category', 'description', 'price', 'date']]); if ($this->Budgets->save($budget)) { $this->Flash->success(__('The budget has been saved.')); return $this->redirect(['action' => 'view', $show->id]); } else { $this->Flash->error(__('The budget could not be saved. Please, try again.')); } } $vendq = $this->Budgets->find()->select(['vendor'])->distinct(['vendor'])->order(['vendor' => 'ASC']); $vend = json_encode($vendq->extract('vendor')); $catq = $this->Budgets->find()->select(['category'])->distinct(['category'])->order(['category' => 'ASC']); $cat = json_encode($catq->extract('category')); $this->set('crumby', [["/", __("Dashboard")], ["/budgets/", __("Budget Lists")], ["/budgets/view/" . $show->id, __("{0} Budget", $show->name)], [null, "Edit Expense"]]); $shows = [$show->id => $show->name]; $this->set(compact('budget', 'shows', 'cat', 'vend')); $this->set('_serialize', ['budget']); }
/** * Edit method * * @param string|null $id Task id. * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { $task = $this->Tasks->get($id, ['contain' => ['Users']]); $this->set('adminTask', $this->UserPerm->checkShow($this->Auth->user('id'), $task->show_id, 'is_task_admin')); $this->loadModel('Shows'); $this->loadModel('ShowUserPerms'); $show = $this->Shows->findById($task->show_id)->first(); if (!$show) { $this->Flash->error(__('Show not found!')); return $this->redirect(['action' => 'index']); } if (!$this->UserPerm->checkShow($this->Auth->user('id'), $task->show_id, 'is_task_user') && !$this->UserPerm->checkShow($this->Auth->user('id'), $task->show_id, 'is_task_admin')) { $this->Flash->error(__('You do not have access to this show')); return $this->redirect(['action' => 'index']); } if (!$this->UserPerm->checkShow($this->Auth->user('id'), $task->show_id, 'is_task_admin') && $task->created_by != $this->Auth->user('id')) { $this->Flash->error(__('You may only edit your own tasks in this show')); return $this->redirect(['action' => 'index']); } if ($show->is_active < 1) { $this->Flash->error(__('Sorry, this show is now closed.')); return $this->redirect(['action' => 'index']); } if ($this->request->is(['patch', 'post', 'put'])) { $time = Time::createFromFormat('Y-m-d', $this->request->data['due'], 'UTC'); $this->request->data['due'] = $time; $task = $this->Tasks->patchEntity($task, $this->request->data); if ($this->Tasks->save($task)) { $this->Flash->success(__('The task has been saved.')); return $this->redirect(['action' => 'view', $show->id]); } else { $this->Flash->error(__('The task could not be saved. Please, try again.')); } } $assignee = [$task->user->id => $task->user->first . " " . $task->user->last]; $catq = $this->Tasks->find()->select(['category'])->distinct(['category'])->order(['category' => 'ASC']); $cat = json_encode($catq->extract('category')); $this->set('crumby', [["/", __("Dashboard")], ["/tasks/", __("Task Lists")], ["/tasks/view/" . $show->id, __("{0} Tasks", $show->name)], [null, __("Edit Task")]]); $shows = [$show->id => $show->name]; $this->set(compact('task', 'shows', 'assignee', 'cat')); $this->set('_serialize', ['task']); }
public function demoreset($really) { if ($really != "YES") { throw new InternalErrorException("Wrong Parameter Supplied, Please Try Again."); } if (!$this->params['really']) { throw new InternalErrorException("Wrong Parameter Supplied, Please Try Again."); } $this->out("<warning>You have really read what this does, and are totally ok with the fact that it is going to nuke all of your data!?!</warning>"); $selection = $this->in('Nuke it All, Start Over?', ['Y', 'N'], 'N'); if ($selection == "Y") { $conn = ConnectionManager::get('default'); $this->loadModel('Users'); $this->loadModel('Shows'); $this->loadModel('Budgets'); $this->loadModel('Payrolls'); $this->loadModel('Messages'); $this->loadModel('Calendars'); //$this->loadModel('Tasks'); $this->Tasks = TableRegistry::get('Tasks'); $this->loadModel('ShowUserPerms'); $this->out('Removing all records.'); if ($this->Payrolls->deleteAll([1 => 1])) { $this->out(' Delete: Payrolls'); } if ($this->Budgets->deleteAll([1 => 1])) { $this->out(' Delete: Budgets'); } if ($this->Tasks->deleteAll([1 => 1])) { $this->out(' Delete: Tasks'); } if ($this->Calendars->deleteAll([1 => 1])) { $this->out(' Delete: Calendars'); } if ($this->ShowUserPerms->deleteAll([1 => 1])) { $this->out(' Delete: ShowUserPerms'); } if ($this->Shows->deleteAll([1 => 1])) { $this->out(' Delete: Shows'); } if ($this->Messages->deleteAll([1 => 1])) { $this->out(' Delete: Messages'); } if ($this->Users->deleteAll([1 => 1])) { $this->out(' Delete: Users'); } $this->out($this->nl(1) . 'Resetting AUTO_INCREMENT'); $conn->execute('ALTER TABLE `users` AUTO_INCREMENT = 1'); $conn->execute('ALTER TABLE `payrolls` AUTO_INCREMENT = 1'); $conn->execute('ALTER TABLE `budgets` AUTO_INCREMENT = 1'); $conn->execute('ALTER TABLE `tasks` AUTO_INCREMENT = 1'); $conn->execute('ALTER TABLE `calendars` AUTO_INCREMENT = 1'); $conn->execute('ALTER TABLE `shows` AUTO_INCREMENT = 1'); $conn->execute('ALTER TABLE `messages` AUTO_INCREMENT = 1'); $conn->execute('ALTER TABLE `show_user_perms` AUTO_INCREMENT = 1'); $this->out($this->nl(1) . 'Creating Data:'); $adminUser = $this->Users->newEntity(['username' => '*****@*****.**', 'password' => 'password', 'phone' => 1234567890, 'first' => 'Administrative', 'last' => 'User', 'is_notified' => 0, 'is_admin' => 1, 'time_zone' => 'America/Detroit']); $managerUser = $this->Users->newEntity(['username' => '*****@*****.**', 'password' => 'password', 'phone' => 1234567890, 'first' => 'Manager', 'last' => 'User', 'is_notified' => 0, 'time_zone' => 'America/Detroit']); $regularUser = $this->Users->newEntity(['username' => '*****@*****.**', 'password' => 'password', 'phone' => 1234567890, 'first' => 'Regular', 'last' => 'User', 'is_notified' => 0, 'time_zone' => 'America/Detroit']); if ($this->Users->save($adminUser)) { $this->out(' Create: Admin User #' . $adminUser->id); } if ($this->Users->save($managerUser)) { $this->out(' Create: Manager User #' . $managerUser->id); } if ($this->Users->save($regularUser)) { $this->out(' Create: Regular User #' . $regularUser->id); } $show1 = $this->Shows->newEntity(['name' => 'Example Show #1', 'location' => 'Somewhere', 'end_date' => Time::createFromFormat('Y-m-d', '2020-02-14', 'UTC')]); $show2 = $this->Shows->newEntity(['name' => 'Example Show #2', 'location' => 'Somewhere', 'end_date' => Time::createFromFormat('Y-m-d', '2010-02-14', 'UTC'), 'is_active' => 0]); if ($this->Shows->save($show1)) { $this->out(' Create: Open Show - #' . $show1->id); } if ($this->Shows->save($show2)) { $this->out(' Create: Closed Show - #' . $show2->id); } $this->out(' Creating Permissions'); $insertCol = ["user_id", "show_id", "is_pay_admin", "is_paid", "is_budget", "is_task_admin", "is_task_user", "is_cal"]; $insertRow = [['user_id' => $adminUser->id, 'show_id' => $show1->id, 'is_pay_admin' => 1, 'is_paid' => 1, 'is_budget' => 1, 'is_task_admin' => 1, 'is_task_user' => 1, 'is_cal' => 1], ['user_id' => $adminUser->id, 'show_id' => $show2->id, 'is_pay_admin' => 1, 'is_paid' => 1, 'is_budget' => 1, 'is_task_admin' => 1, 'is_task_user' => 1, 'is_cal' => 1], ['user_id' => $managerUser->id, 'show_id' => $show1->id, 'is_pay_admin' => 1, 'is_paid' => 1, 'is_budget' => 1, 'is_task_admin' => 0, 'is_task_user' => 1, 'is_cal' => 1], ['user_id' => $managerUser->id, 'show_id' => $show2->id, 'is_pay_admin' => 1, 'is_paid' => 1, 'is_budget' => 1, 'is_task_admin' => 0, 'is_task_user' => 1, 'is_cal' => 1], ['user_id' => $regularUser->id, 'show_id' => $show1->id, 'is_pay_admin' => 0, 'is_paid' => 1, 'is_budget' => 0, 'is_task_admin' => 0, 'is_task_user' => 1, 'is_cal' => 1], ['user_id' => $regularUser->id, 'show_id' => $show2->id, 'is_pay_admin' => 0, 'is_paid' => 1, 'is_budget' => 0, 'is_task_admin' => 0, 'is_task_user' => 1, 'is_cal' => 1]]; $insertQuery = $this->ShowUserPerms->query(); $insertQuery->insert($insertCol); $insertQuery->clause('values')->values($insertRow); $insertQuery->execute(); $this->out(' Creating Budget Items'); $insertCol = ["show_id", "category", "vendor", "price", "description", "date"]; $insertRow = [['show_id' => $show1->id, 'category' => 'Category #1', 'vendor' => 'Random Vendor #' . rand(12, 365), 'price' => rand(2234, 355433) / 100, 'description' => 'Random Description #' . rand(12, 365), 'date' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'category' => 'Category #1', 'vendor' => 'Random Vendor #' . rand(12, 365), 'price' => rand(2234, 355433) / 100, 'description' => 'Random Description #' . rand(12, 365), 'date' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'category' => 'Category #1', 'vendor' => 'Random Vendor #' . rand(12, 365), 'price' => rand(2234, 355433) / 100, 'description' => 'Random Description #' . rand(12, 365), 'date' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'category' => 'Category #1', 'vendor' => 'Random Vendor #' . rand(12, 365), 'price' => rand(2234, 355433) / 100, 'description' => 'Random Description #' . rand(12, 365), 'date' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'category' => 'Category #2', 'vendor' => 'Random Vendor #' . rand(12, 365), 'price' => rand(2234, 355433) / 100, 'description' => 'Random Description #' . rand(12, 365), 'date' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'category' => 'Category #2', 'vendor' => 'Random Vendor #' . rand(12, 365), 'price' => rand(2234, 355433) / 100, 'description' => 'Random Description #' . rand(12, 365), 'date' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'category' => 'Category #2', 'vendor' => 'Random Vendor #' . rand(12, 365), 'price' => rand(2234, 355433) / 100, 'description' => 'Random Description #' . rand(12, 365), 'date' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')]]; $insertQuery = $this->Budgets->query(); $insertQuery->insert($insertCol); $insertQuery->clause('values')->values($insertRow); $insertQuery->execute(); $this->out(' Creating Payroll Items'); $insertCol = ["show_id", "user_id", "is_paid", "notes", "start_time", "end_time", "date_worked"]; $mins = ['00', '15', '30', '45']; $insertRow = [['show_id' => $show1->id, 'user_id' => $regularUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'user_id' => $regularUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'user_id' => $regularUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'user_id' => $regularUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'user_id' => $managerUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'user_id' => $managerUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'user_id' => $managerUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'user_id' => $adminUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')], ['show_id' => $show1->id, 'user_id' => $adminUser->id, 'is_paid' => 0, 'notes' => 'Random Note #' . rand(12, 365), 'start_time' => Time::createFromFormat('H:i', rand(8, 11) . ":" . $mins[rand(0, 3)], 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 17) . ":" . $mins[rand(0, 3)], 'UTC'), 'date_worked' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC')]]; $insertQuery = $this->Payrolls->query(); $insertQuery->insert($insertCol); $insertQuery->clause('values')->values($insertRow); $insertQuery->execute(); $this->out(' Creating Task Items'); $insertCol = ["created_by", "assigned_to", "show_id", "due", "title", "category", "note", "task_accepted", "task_done"]; $insertRow = [['assigned_to' => $adminUser->id, 'created_by' => $regularUser->id, 'show_id' => $show1->id, 'due' => Time::createFromFormat('Y-m-d', '2020-02-' . rand(10, 28), 'UTC'), 'title' => 'Random Title #' . rand(12, 365), 'category' => 'Category #1', 'note' => 'Random (not accepted, not done) Description #' . rand(12, 365), 'task_accepted' => 0, 'task_done' => 0], ['assigned_to' => $adminUser->id, 'created_by' => $regularUser->id, 'show_id' => $show1->id, 'due' => Time::createFromFormat('Y-m-d', '2010-02-' . rand(10, 28), 'UTC'), 'title' => 'Random Title #' . rand(12, 365), 'category' => 'Category #1', 'note' => 'Random (overdue) Description #' . rand(12, 365), 'task_accepted' => 0, 'task_done' => 0], ['assigned_to' => $adminUser->id, 'created_by' => $regularUser->id, 'show_id' => $show1->id, 'due' => Time::createFromFormat('Y-m-d', '2020-02-' . rand(10, 28), 'UTC'), 'title' => 'Random Title #' . rand(12, 365), 'category' => 'Category #1', 'note' => 'Random (accepted, not done) Description #' . rand(12, 365), 'task_accepted' => 1, 'task_done' => 0], ['assigned_to' => $adminUser->id, 'created_by' => $regularUser->id, 'show_id' => $show1->id, 'due' => Time::createFromFormat('Y-m-d', '2020-02-' . rand(10, 28), 'UTC'), 'title' => 'Random Title #' . rand(12, 365), 'category' => 'Category #1', 'note' => 'Random (done) Description #' . rand(12, 365), 'task_accepted' => 1, 'task_done' => 1]]; $insertQuery = $this->Tasks->query(); $insertQuery->insert($insertCol); $insertQuery->clause('values')->values($insertRow); $insertQuery->execute(); $this->out(' Creating Calendar Items'); $insertCol = ["date", "start_time", "end_time", "all_day", "show_id", "title", "category", "note"]; $thisYear = date('Y'); $thisMonth = date('m'); $insertRow = []; foreach (range(1, 8) as $counter) { foreach (range(1, 12) as $use_month) { $use_year = $thisMonth <= $use_month ? $thisYear : $thisYear + 1; $insertRow[] = ['date' => Time::createFromFormat('Y-m-d', $use_year . "-" . str_pad($use_month, 2, "0", STR_PAD_LEFT) . "-" . str_pad(rand(1, 28), 2, "0", STR_PAD_LEFT), 'UTC'), 'start_time' => Time::createFromFormat('H:i', rand(6, 11) . ":" . str_pad(rand(0, 5) * 10, 2, "0", STR_PAD_LEFT), 'UTC'), 'end_time' => Time::createFromFormat('H:i', rand(13, 22) . ":" . str_pad(rand(0, 5) * 10, 2, "0", STR_PAD_LEFT), 'UTC'), 'all_day' => rand(1, 6) % 3 < 1 ? 1 : 0, 'show_id' => $show1->id, 'title' => 'Random Title #' . rand(12, 365), 'category' => ['default', 'active', 'success', 'info', 'warning', 'danger'][rand(0, 5)], 'note' => 'Random Description #' . rand(12, 365)]; } } $insertQuery = $this->Calendars->query(); $insertQuery->insert($insertCol); $insertQuery->clause('values')->values($insertRow); $insertQuery->execute(); $this->out($this->nl(1) . 'Resetting Sessions'); $conn->execute('DELETE FROM `sessions` WHERE 1'); $this->out($this->nl(1) . 'Finished!'); } else { $this->err('Execution Stopped'); } }
/** * Add method * * @return void Redirects on successful add, renders view otherwise. */ public function add($ship = null) { //Obtencion de Parcels correspondientes al shipment a facturar $shipping = $this->Commisions->Shippings->get($ship, ['contain' => ['Fixtures', 'Parcels']]); //Entrega de la info al template $this->set('shipping', $shipping); $this->set('_serialize', ['shipping']); //declaracion de variables para calculo de valores $tot_dem = 0; $cont = 0; $tot_freight = 0; $freightsum = 0; $total_vol = 0; //calculo de cada valor por cada parcel correspondiente al shipment foreach ($shipping->parcels as $parcels) { $tot_freight = +$parcels->freight_100; if ($parcels->des_dem_char > 0) { $tot_dem = +$parcels->des_dem_char; } $port = $this->Commisions->Shippings->Parcels->Ports->get($parcels->port_id); if ($parcels->type_of_call == 'Loading Port') { $total_vol = +$parcels->volume; $load_port[] = $port->name; } else { $dis_port[] = $port->name; } $freightsum = +$parcels->dem_bro * $parcels->volume; $cont = +$parcels->volume; $cargo = $parcels->cargo; $unit = $parcels->unit; } //calculo final de variables de informacion $cargounit = [$total_vol, $unit]; $finalfreight = $freightsum / $cont; $tot_com = ($tot_freight + $tot_dem) * ($shipping->fixture->broker_com / 100); $load_ports = implode('/', $load_port); $dis_ports = implode('/', $dis_port); //obtencion de datos de Shipowner y Charterer $shipowner = $this->Commisions->Shippings->Fixtures->Shipowners->get($shipping->fixture->shipowner_id); $charterer = $this->Commisions->Shippings->Fixtures->Charterers->get($shipping->fixture->charterer_id); $com_info = ['finalfreight' => $finalfreight, 'tot_com' => $tot_com, 'load_ports' => $load_ports, 'dis_ports' => $dis_ports, 'cargo' => $cargo, 'tot_freight' => $tot_freight, 'tot_dem' => $tot_dem, 'total_vol' => $total_vol, 'client' => $shipowner->full_style, 'charterer' => $charterer->nick, 'unit' => $unit]; $this->set('com_info', $com_info); $commision = $this->Commisions->newEntity(); if ($this->request->is('post')) { $this->request->data['date_com'] = Time::createFromFormat('m/d/Y', $this->request->data['date_com'], 'UTC'); $commision = $this->Commisions->patchEntity($commision, $this->request->data); if ($this->Commisions->save($commision)) { $this->Flash->success(__('The commision has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The commision could not be saved. Please, try again.')); } } $shippings = $this->Commisions->Shippings->find('list', ['limit' => 200]); $this->set(compact('commision', 'shippings')); $this->set('_serialize', ['commision']); }
public function clockPicker($name, $label, $time = null) { if (!is_null($time)) { $time = Time::createFromFormat('H:i', $time, 'UTC'); $val = $time->i18nFormat('H:mm', 'UTC'); $pretval = $time->i18nFormat('h:mm a', 'UTC'); } else { $val = ""; $pretval = ""; } $retty = '<div class="form-group required">'; $retty .= '<label class="control-label">' . $label . '</label>'; $retty .= '<input type="text" data-role="datebox" data-datebox-mode="timeflipbox" id="' . $name . '-dbox" class="form-control" value="' . $pretval . '" data-options=\'{"linkedField": "#' . $name . '", "overrideTimeFormat": 12, "overrideTimeOutput": "%-I:%M %p", "linkedFieldFormat": "%H:%M", "minuteStep": 15 }\'>'; $retty .= '<input type="hidden" name="' . $name . '" id="' . $name . '" value="' . $val . '" /></div>'; return $retty; }
/** * Edit method * * @param string|null $id Schedule id. * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null) { if (!$this->Auth->user('is_admin')) { $this->Flash->error(__('Only administrators may access the scheduled tasks module.')); return $this->redirect("/"); } $this->loadModel('Shows'); $showsq = $this->Shows->find('all')->select(['id', 'name'])->where(['Shows.is_active' => 1]); $shows = ["** Not Applicable **"]; foreach ($showsq as $show) { $shows[$show->id] = $show->name; } $this->set('shows', $shows); $schedule = $this->Schedules->get($id, ['contain' => []]); if ($this->request->is(['patch', 'post', 'put'])) { $time = Time::createFromFormat('Y-m-d H:i:s', $this->request->data['start_time'], 'UTC'); $this->request->data['start_time'] = $time; $schedule = $this->Schedules->patchEntity($schedule, $this->request->data); if ($this->Schedules->save($schedule)) { $this->Flash->success(__('The schedule has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The schedule could not be saved. Please, try again.')); } } $this->set(compact('schedule')); $this->set('_serialize', ['schedule']); }
/** * Edit method * * @param string|null $id Payroll id. * @return void Redirects on successful edit, renders view otherwise. * @throws \Cake\Network\Exception\NotFoundException When record not found. */ public function edit($id = null, $from = 0) { $payroll = $this->Payrolls->findById($id)->first(); if (!$payroll) { $this->Flash->error(__('Record not found!')); return $this->redirect(['action' => 'index']); } if ($this->Auth->user('is_admin') || $this->UserPerm->checkShow($this->Auth->user('id'), $payroll->show_id, 'is_pay_admin')) { $this->set('isAdmin', true); $flist = ['notes', 'date_worked', 'start_time', 'end_time', 'is_paid']; } elseif ($this->Auth->user('id') == $payroll->user_id && !$payroll->is_paid) { $this->set('isAdmin', false); $flist = ['notes', 'date_worked', 'start_time', 'end_time']; } else { $this->Flash->error(__('You can not edit this payroll item')); if ($from == 1) { return $this->redirect(['action' => 'viewbyuser', $payroll->user_id]); } else { return $this->redirect(['action' => 'viewbyshow', $payroll->show_id]); } } if ($this->request->is(['patch', 'post', 'put'])) { $time = Time::createFromFormat('Y-m-d', $this->request->data['date_worked'], 'UTC'); $this->request->data['date_worked'] = $time; $time = Time::createFromFormat('H:i', $this->request->data['start_time'], 'UTC'); $this->request->data['start_time'] = $time; $time = Time::createFromFormat('H:i', $this->request->data['end_time'], 'UTC'); $this->request->data['end_time'] = $time; $payroll = $this->Payrolls->patchEntity($payroll, $this->request->data, ['fieldList' => $flist]); if ($this->Payrolls->save($payroll)) { $this->Flash->success(__('The payroll has been saved.')); if ($from == 1) { return $this->redirect(['action' => 'viewbyuser', $payroll->user_id]); } elseif ($from == 2) { return $this->redirect(['action' => 'unpaidbyshow']); } elseif ($from == 3) { return $this->redirect(['action' => 'unpaidbyuser']); } else { return $this->redirect(['action' => 'viewbyshow', $payroll->show_id]); } } else { $this->Flash->error(__('The payroll could not be saved. Please, try again.')); } } $this->loadModel('Shows'); $this->loadModel('Users'); $show = $this->Shows->findById($payroll->show_id)->first(); $user = $this->Users->findById($payroll->user_id)->first(); $users = [$user->id => $user->first . " " . $user->last]; $shows = [$show->id => $show->name]; $this->set(compact('payroll', 'users', 'shows')); $this->set('_serialize', ['payroll']); }