2018-04-29 22:31:51 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2018-04-30 00:26:13 +09:00
|
|
|
use App\Http\Controllers\AuthController;
|
|
|
|
use App\Http\Controllers\UserController;
|
|
|
|
use App\Http\Controllers\PermissionController; // Remove permission controller soon.
|
2018-04-29 22:31:51 +09:00
|
|
|
|
2018-04-30 00:26:13 +09:00
|
|
|
class InvoiceController extends Controller {
|
|
|
|
private $objAuth;
|
|
|
|
private $objUser;
|
|
|
|
private $objPermission;
|
2018-04-29 22:31:51 +09:00
|
|
|
|
2018-04-30 00:26:13 +09:00
|
|
|
// Constructor
|
|
|
|
public function __construct() {
|
|
|
|
$this->objAuth = new AuthController();
|
|
|
|
$this->objUser = new UserController();
|
|
|
|
$this->objPermission = new PermissionController();
|
2018-04-29 22:31:51 +09:00
|
|
|
}
|
|
|
|
|
2018-04-30 00:26:13 +09:00
|
|
|
// Clients
|
2018-04-30 00:31:03 +09:00
|
|
|
public function getClients(Request $request) { // /api/rpc/invoice/clients/getclients
|
2018-04-30 00:26:13 +09:00
|
|
|
$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.';
|
|
|
|
}
|
|
|
|
}
|
2018-04-29 22:31:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// Company
|
2018-04-30 02:56:03 +09:00
|
|
|
public function getCompanies(Request $request) { // /api/rpc/invoice/company/getcompanies
|
|
|
|
$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 && $valid['inv_manuser'] == 1) {
|
|
|
|
return DB::table('inv_company')
|
|
|
|
->select(
|
|
|
|
'name',
|
|
|
|
'compreg',
|
|
|
|
'taxnr',
|
|
|
|
'bank_number',
|
|
|
|
'bank_name',
|
|
|
|
'bank_recipient',
|
|
|
|
'logo',
|
|
|
|
'payterm'
|
|
|
|
)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Permission denied.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCompany($id, Request $request) { // /api/rpc/invoice/company/getcompany/id
|
|
|
|
$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) {
|
|
|
|
$companyId = DB::table('inv_company_users')
|
|
|
|
->select('company_id')
|
|
|
|
->where('user_id', $check)
|
|
|
|
->limit(1)
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if ($companyId != 0) {
|
|
|
|
return DB::table('inv_company')
|
|
|
|
->select(
|
|
|
|
'name',
|
|
|
|
'compreg',
|
|
|
|
'taxnr',
|
|
|
|
'bank_number',
|
|
|
|
'bank_name',
|
|
|
|
'bank_recipient',
|
|
|
|
'logo',
|
|
|
|
'payterm'
|
|
|
|
)
|
|
|
|
->where('cu_id', $companyId)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Permission denied.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($valid['inv_mancompany'] == 1 && $valid['inv_manuser'] == 1) {
|
|
|
|
return DB::table('inv_company')
|
|
|
|
->select(
|
|
|
|
'name',
|
|
|
|
'compreg',
|
|
|
|
'taxnr',
|
|
|
|
'bank_number',
|
|
|
|
'bank_name',
|
|
|
|
'bank_recipient',
|
|
|
|
'logo',
|
|
|
|
'payterm'
|
|
|
|
)
|
|
|
|
->where('cu_id', $request->id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Permission denied.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newCompany(Request $request) { // /api/rpc/invoice/company/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_mancompany'] == 1 && $calid['inv_manuser'] == 1) {
|
|
|
|
$add = DB::table('inv_contacts')
|
|
|
|
->insertGetId([
|
|
|
|
'name' => $request->name,
|
|
|
|
'compreg' => $request->compreg,
|
|
|
|
'taxnr' => $request->taxnr,
|
|
|
|
'bank_number' => $request->bank_number,
|
|
|
|
'bank_name' => $request->bank_name,
|
|
|
|
'bank_recipient' => $request->bank_recipient,
|
|
|
|
'logo' => $request->logo,
|
|
|
|
'payterm' => $request->payterm
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($request->user != 0) {
|
|
|
|
DB::table('inv_company_users')
|
|
|
|
->insert([
|
|
|
|
'user_id' => $request->user,
|
|
|
|
'company_id' => $add
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'Success!';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Permission denied.';
|
|
|
|
}
|
|
|
|
}
|
2018-04-29 22:31:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function editCompany(Request $request) { // /api/rpc/invoice/company/edit
|
2018-04-30 00:26:13 +09:00
|
|
|
$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) {
|
2018-04-30 02:56:03 +09:00
|
|
|
$companyId = DB::table('inv_company_users')
|
|
|
|
->select('company_id')
|
|
|
|
->where('user_id', $check)
|
|
|
|
->limit(1)
|
|
|
|
->first();
|
|
|
|
|
|
|
|
if ($companyId != 0) {
|
|
|
|
DB::table('inv_company')
|
|
|
|
->where('cu_id', $companyId)
|
|
|
|
->update([
|
|
|
|
'name' => $request->name,
|
|
|
|
'compreg' => $request->compreg,
|
|
|
|
'taxnr' => $request->taxnr,
|
|
|
|
'bank_number' => $request->bank_number,
|
|
|
|
'bank_name' => $request->bank_name,
|
|
|
|
'bank_recipient' => $request->bank_recipient,
|
|
|
|
'logo' => $request->logo,
|
|
|
|
'payterm' => $request->payterm
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Permission denied.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($valid['inv_mancompany'] == 1 && $valid['inv_manuser'] == 1) {
|
|
|
|
DB::table('inv_company')
|
|
|
|
->where('cu_id', $request->id)
|
|
|
|
->update([
|
|
|
|
'name' => $request->name,
|
|
|
|
'compreg' => $request->compreg,
|
|
|
|
'taxnr' => $request->taxnr,
|
|
|
|
'bank_number' => $request->bank_number,
|
|
|
|
'bank_name' => $request->bank_name,
|
|
|
|
'bank_recipient' => $request->bank_recipient,
|
|
|
|
'logo' => $request->logo,
|
|
|
|
'payterm' => $request->payterm
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Permission denied.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteCompany(Request $request) { // /api/rpc/invoice/company/delete
|
|
|
|
$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 && $valid['manuser'] == 1) {
|
|
|
|
DB::table('inv_company')->where('id', $request->id)->delete();
|
|
|
|
DB::table('inv_company_users')->where('company_id', $request->id)->delete();
|
|
|
|
|
|
|
|
return 'Done.';
|
2018-04-30 00:26:13 +09:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Permission denied.';
|
|
|
|
}
|
|
|
|
}
|
2018-04-29 22:31:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// Contacts
|
2018-04-30 00:31:03 +09:00
|
|
|
public function getContacts(Request $request) { // /api/rpc/invoice/contacts/getcontacts
|
2018-04-30 00:26:13 +09:00
|
|
|
$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) {
|
2018-04-29 22:31:51 +09:00
|
|
|
return DB::table('inv_contacts')
|
|
|
|
->select('*')
|
|
|
|
->where('id', $id)
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newContact(Request $request) { // /api/rpc/invoice/contacts/new
|
2018-04-30 00:26:13 +09:00
|
|
|
$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
|
2018-04-30 00:31:03 +09:00
|
|
|
]);
|
2018-04-30 00:26:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->isEmployer) {
|
|
|
|
DB::table('inv_employers')
|
|
|
|
->insert([
|
|
|
|
'contact_id' => $add
|
2018-04-30 00:31:03 +09:00
|
|
|
]);
|
2018-04-30 00:26:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return 'Success!';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 'Permission denied.';
|
|
|
|
}
|
|
|
|
}
|
2018-04-29 22:31:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function editContact(Request $request) { // /api/rpc/invoice/contacts/edit
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleteContact(Request $request) { // /api/rpc/invoice/contacts/delete
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2018-04-29 23:16:41 +09:00
|
|
|
// Employers
|
2018-04-30 00:31:03 +09:00
|
|
|
public function getEmployers(Request $request) { // /api/rpc/invoice/employees/getemployers
|
2018-04-30 00:26:13 +09:00
|
|
|
$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.';
|
|
|
|
}
|
|
|
|
}
|
2018-04-29 22:31:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 '';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|