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'))); }
public function delete($id) { if ($this->shouldLockIfNoPermission('data.edit')) { return; } $customerService = new Customer($this->db); if ($this->request->is('post')) { $deviceService = new Device($this->db); $devices = $deviceService->findAllByCustomerId($id); if (null === $devices) { $this->flash->error('Unable to delete customer!'); return $this->redirect('/customers'); } $customerService->deleteById($id); $partService = new Part($this->db); foreach ($devices as $device) { $partService->deleteAllByDeviceId($device['id']); } $deviceService->deleteAllByCustomerId($id); $this->flash->success('Deleted customer successfully!'); return $this->redirect('/customers'); } $item = $customerService->findById($id); $this->set('item', $item); $this->set('id', $id); }