254 行
7.6 KiB
PHP
254 行
7.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
use App\Http\Controllers\AuthController;
|
|
use App\Http\Controllers\UserController;
|
|
use App\Http\Controllers\PermissionController; // Remove permission controller soon.
|
|
|
|
class InvoiceController extends Controller {
|
|
private $objAuth;
|
|
private $objUser;
|
|
private $objPermission;
|
|
|
|
// Constructor
|
|
public function __construct() {
|
|
$this->objAuth = new AuthController();
|
|
$this->objUser = new UserController();
|
|
$this->objPermission = new PermissionController();
|
|
}
|
|
|
|
// Clients
|
|
public function getClients(Request $request) { // /api/rpc/invoice/clients/getclients
|
|
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
|
|
|
if ($check == 0) {
|
|
return 'Err!';
|
|
}
|
|
else {
|
|
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
|
|
|
if ($valid['inv_mancontact'] == 1) {
|
|
return DB::table('inv_clients')
|
|
->join('inv_contacts', 'inv_contacts.id', 'inv_clients.contact_id')
|
|
->get(array(
|
|
'inv_clients.id as id',
|
|
'inv_contacts.id as cid',
|
|
'inv_contacts.name',
|
|
'inv_contacts.address',
|
|
'inv_contacts.postcode',
|
|
'inv_contacts.town',
|
|
'inv_contacts.country',
|
|
'inv_contacts.phone',
|
|
'inv_contacts.email'
|
|
));
|
|
}
|
|
else {
|
|
return 'Permission denied.';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Company
|
|
public function getCompany() {
|
|
return DB::table('inv_company')
|
|
->select(
|
|
'contact_id as cid',
|
|
'name',
|
|
'compreg',
|
|
'taxnr',
|
|
'bank_number',
|
|
'bank_name',
|
|
'bank_recipient',
|
|
'logo',
|
|
'payterm'
|
|
)
|
|
->get();
|
|
}
|
|
|
|
public function editCompany(Request $request) { // /api/rpc/invoice/company/edit
|
|
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
|
|
|
if ($check == 0) {
|
|
return 'Err!';
|
|
}
|
|
else {
|
|
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
|
|
|
if ($valid['inv_mancompany'] == 1) {
|
|
return '';
|
|
}
|
|
else {
|
|
return 'Permission denied.';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Contacts
|
|
public function getContacts(Request $request) { // /api/rpc/invoice/contacts/getcontacts
|
|
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
|
|
|
if ($check == 0) {
|
|
return 'Err!';
|
|
}
|
|
else {
|
|
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
|
|
|
if ($valid['inv_mancontact'] == 1) {
|
|
return DB::table('inv_contacts')
|
|
->select('*')
|
|
->get();
|
|
}
|
|
else {
|
|
return 'Permission denied.';
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getContact($id) {
|
|
return DB::table('inv_contacts')
|
|
->select('*')
|
|
->where('id', $id)
|
|
->get();
|
|
}
|
|
|
|
public function newContact(Request $request) { // /api/rpc/invoice/contacts/new
|
|
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
|
|
|
if ($check == 0) {
|
|
return 'Err!';
|
|
}
|
|
else {
|
|
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
|
|
|
if ($valid['inv_mancontact'] == 1) {
|
|
$add = DB::table('inv_contacts')
|
|
->insertGetId([
|
|
'name' => $request->name,
|
|
'address' => $request->address,
|
|
'postcode' => $request->postcode,
|
|
'town' => $request->town,
|
|
'country' => $request->country,
|
|
'phone' => $request->phone,
|
|
'email' => $request->email
|
|
]);
|
|
|
|
if ($request->isClient) {
|
|
DB::table('inv_clients')
|
|
->insert([
|
|
'contact_id' => $add
|
|
]);
|
|
}
|
|
|
|
if ($request->isEmployer) {
|
|
DB::table('inv_employers')
|
|
->insert([
|
|
'contact_id' => $add
|
|
]);
|
|
}
|
|
|
|
return 'Success!';
|
|
}
|
|
else {
|
|
return 'Permission denied.';
|
|
}
|
|
}
|
|
}
|
|
|
|
public function editContact(Request $request) { // /api/rpc/invoice/contacts/edit
|
|
return '';
|
|
}
|
|
|
|
public function deleteContact(Request $request) { // /api/rpc/invoice/contacts/delete
|
|
return '';
|
|
}
|
|
|
|
// Employers
|
|
public function getEmployers(Request $request) { // /api/rpc/invoice/employees/getemployers
|
|
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
|
|
|
if ($check == 0) {
|
|
return 'Err!';
|
|
}
|
|
else {
|
|
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
|
|
|
if ($valid['inv_mancontact'] == 1) {
|
|
return DB::table('inv_employers')
|
|
->join('inv_contacts', 'inv_employers.contact_id', 'inv_contacts.id')
|
|
->get(array(
|
|
'inv_employers.id as id',
|
|
'inv_contacts.id as cid',
|
|
'inv_contacts.name',
|
|
'inv_contacts.address',
|
|
'inv_contacts.postcode',
|
|
'inv_contacts.town',
|
|
'inv_contacts.country',
|
|
'inv_contacts.phone',
|
|
'inv_contacts.email'
|
|
));
|
|
}
|
|
else {
|
|
return 'Permission denied.';
|
|
}
|
|
}
|
|
}
|
|
|
|
// Invoices
|
|
public function getInvoices() { // /api/rpc/invoice/invoices/getinvoices
|
|
return DB::table('inv_invoices')
|
|
->select('*')
|
|
->get();
|
|
}
|
|
|
|
public function getInvoice($id) { // /api/rpc/invoice/invoices/getinvoice/id
|
|
return DB::table('inv_invoices')
|
|
->select('*')
|
|
->where('id', $id)
|
|
->get();
|
|
}
|
|
|
|
public function newInvoice(Request $request) { // /api/rpc/invoice/invoices/new
|
|
return '';
|
|
}
|
|
|
|
public function editInvoice(Request $request) { // /api/rpc/invoice/invoices/edit
|
|
return '';
|
|
}
|
|
|
|
public function deleteInvoice(Request $request) { // /api/rpc/invoice/invoices/delete
|
|
return '';
|
|
}
|
|
|
|
// Services
|
|
public function getServices() { // /api/rpc/invoice/service/getservices
|
|
return DB::table('inv_services')
|
|
->select('*')
|
|
->get();
|
|
}
|
|
|
|
public function getService($id) { // /api/rpc/invoice/services/getservice/id
|
|
return DB::table('inv_services')
|
|
->select('*')
|
|
->where('id', $id)
|
|
->get();
|
|
}
|
|
|
|
public function newService(Request $request) { // /api/rpc/invoice/services/new
|
|
return '';
|
|
}
|
|
|
|
public function editService(Request $request) { // /api/rpc/invoice/services/edit
|
|
return '';
|
|
}
|
|
|
|
public function deleteService(Request $request) { // /api/rpc/invoice/services/delete
|
|
return '';
|
|
}
|
|
|
|
}
|