public function addFor($id) { if ($this->shouldLockIfNoPermission('data.edit')) { return; } $modelPart = new Part($this->db); if ($this->request->is('post')) { $user = $this->session->get('user'); if ($modelPart->addToDevice($_POST['description'], $id, $user['username'])) { $this->flash->success('Added part successfully!'); return $this->redirect('/parts/view/' . $modelPart->lastInsertId()); } else { $this->flash->addMany($modelPart->getAllMessages(), 'warning'); } return $this->redirect('/parts/view/' . $id); } $modelDevice = new Device($this->db); $device = $modelDevice->findById($id); if (null === $device) { $this->flash->error('Unable to get device information!'); return $this->redirect('/parts/view/' . $id); } $this->set('device', $device); }
public function generateInvoice($id) { $modelDevice = new Device($this->db); $device = $modelDevice->findById($id); if ($device === null) { $this->flash->error('Unable to generate invoice!'); return $this->redirect('/devices/view/' . $id); } $modelCustomer = new Customer($this->db); $customer = $modelCustomer->findById($device['customer_id']); if ($customer === null) { $this->flash->error('Unable to generate invoice!'); return $this->redirect('/devices/view/' . $id); } $modelPart = new Part($this->db); $parts = $modelPart->findAllByDeviceId($device['id']); if ($parts === null) { $this->flash->error('Unable to generate invoice!'); return $this->redirect('/devices/view/' . $id); } $infoShop = [$customer['shop'], $customer['shop_periods']]; $infoAddress = [\ICanBoogie\titleize($customer['address']), strtoupper($customer['state']) . ' ' . \ICanBoogie\titleize($customer['zip'])]; $infoStaff = []; if (strlen(trim($customer['room_number'])) > 0) { $infoStaff[] = 'Room #' . $customer['room_number']; } if (strlen(trim($customer['phone_ext'])) > 0) { $infoStaff[] = 'Ext.' . $customer['phone_ext']; } $this->set('now', date('n/j/Y', time())); $this->set('parts', $parts); $this->set('device', $device); $this->set('customer', $customer); $this->set('infoShop', implode(', ', array_filter(array_map('trim', $infoShop), 'strlen'))); $this->set('infoStaff', implode(', ', array_filter(array_map('trim', $infoStaff), 'strlen'))); $this->set('infoAddress', implode(', ', array_filter(array_map('trim', $infoAddress), 'strlen'))); }