Edit stuff.
このコミットが含まれているのは:
コミット
362ea5db41
|
@ -22,37 +22,6 @@ class InvoiceController extends Controller {
|
|||
$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 getCompanies(Request $request) { // /api/rpc/invoice/company/getcompanies
|
||||
$check = $this->objAuth->checkLegit($request->username, $request->password);
|
||||
|
@ -94,16 +63,30 @@ class InvoiceController extends Controller {
|
|||
$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) {
|
||||
if ($valid['inv_manuser'] == 0) {
|
||||
if ($id == $check) {
|
||||
return DB::table('inv_company')
|
||||
->select(
|
||||
'name',
|
||||
'compreg',
|
||||
'taxnr',
|
||||
'bank_number',
|
||||
'bank_name',
|
||||
'bank_recipient',
|
||||
'logo',
|
||||
'payterm'
|
||||
)
|
||||
->where('id', $id)
|
||||
->get();
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
else if ($valid['inv_manuser'] == 1) {
|
||||
return DB::table('inv_company')
|
||||
->select(
|
||||
'id',
|
||||
'cu_id',
|
||||
'name',
|
||||
'compreg',
|
||||
'taxnr',
|
||||
|
@ -113,28 +96,13 @@ class InvoiceController extends Controller {
|
|||
'logo',
|
||||
'payterm'
|
||||
)
|
||||
->where('cu_id', $companyId)
|
||||
->where('id', $id)
|
||||
->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.';
|
||||
}
|
||||
|
@ -192,43 +160,52 @@ class InvoiceController extends Controller {
|
|||
$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 ($valid['inv_manuser'] == 0) {
|
||||
$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)
|
||||
if ($companyId != 0) {
|
||||
DB::table('inv_company')
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'name' => $request->name,
|
||||
'compreg' => ($request->compreg ? $request->compreg : ''),
|
||||
'taxnr' => ($request->taxnr ? $request->taxnr : ''),
|
||||
'bank_number' => $request->bank_number,
|
||||
'bank_name' => $request->bank_name,
|
||||
'bank_recipient' => $request->bank_recipient,
|
||||
'logo' => ($request->logo ? $request->logo : ''),
|
||||
'payterm' => $request->payterm
|
||||
]);
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
else if ($valid['inv_manuser'] == 1) {
|
||||
DB::table('inv_company_users')
|
||||
->where('company_id', $request->id)
|
||||
->update([
|
||||
'user_id' => $request->cu_id
|
||||
]);
|
||||
|
||||
DB::table('inv_company')
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'cu_id' => $request->cu_id,
|
||||
'name' => $request->name,
|
||||
'compreg' => $request->compreg,
|
||||
'taxnr' => $request->taxnr,
|
||||
'compreg' => ($request->compreg ? $request->compreg : ''),
|
||||
'taxnr' => ($request->taxnr ? $request->taxnr : ''),
|
||||
'bank_number' => $request->bank_number,
|
||||
'bank_name' => $request->bank_name,
|
||||
'bank_recipient' => $request->bank_recipient,
|
||||
'logo' => $request->logo,
|
||||
'logo' => ($request->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.';
|
||||
|
@ -245,7 +222,7 @@ class InvoiceController extends Controller {
|
|||
else {
|
||||
$valid = $this->objAuth->getPermissions($request->username, $request->password);
|
||||
|
||||
if ($valid['inv_mancompany'] == 1 && $valid['manuser'] == 1) {
|
||||
if ($valid['inv_mancompany'] == 1 && $valid['inv_manuser'] == 1) {
|
||||
DB::table('inv_company')->where('id', $request->id)->delete();
|
||||
DB::table('inv_company_users')->where('company_id', $request->id)->delete();
|
||||
|
||||
|
@ -278,11 +255,54 @@ class InvoiceController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
public function getContact($id) {
|
||||
return DB::table('inv_contacts')
|
||||
->select('*')
|
||||
->where('id', $id)
|
||||
->get();
|
||||
public function getContact($id, Request $request) { // /api/rpc/invoice/contacts/getcontact/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_mancontact'] == 1) {
|
||||
$get = DB::table('inv_contacts')
|
||||
->select('*')
|
||||
->where('id', $id)
|
||||
->get();
|
||||
|
||||
$emp = DB::table('inv_employers')
|
||||
->select('id')
|
||||
->where('contact_id', $id)
|
||||
->get();
|
||||
|
||||
$cus = DB::table('inv_clients')
|
||||
->select('id')
|
||||
->where('contact_id', $id)
|
||||
->get();
|
||||
|
||||
$res = array();
|
||||
|
||||
foreach($get as $g) {
|
||||
$res[] = array(
|
||||
'id' => $g->id,
|
||||
'name' => $g->name,
|
||||
'address' => $g->address,
|
||||
'postcode' => $g->postcode,
|
||||
'town' => $g->town,
|
||||
'country' => $g->country,
|
||||
'phone' => $g->phone,
|
||||
'email' => $g->email,
|
||||
'isEmployer' => ($emp->count() ? true : false),
|
||||
'isCustomer' => ($cus->count() ? true : false)
|
||||
);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function newContact(Request $request) { // /api/rpc/invoice/contacts/new
|
||||
|
@ -329,7 +349,73 @@ class InvoiceController extends Controller {
|
|||
}
|
||||
|
||||
public function editContact(Request $request) { // /api/rpc/invoice/contacts/edit
|
||||
return '';
|
||||
$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) {
|
||||
DB::table('inv_contacts')
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'name' => $request->name,
|
||||
'address' => $request->address,
|
||||
'postcode' => $request->postcode,
|
||||
'town' => $request->town,
|
||||
'country' => $request->country,
|
||||
'phone' => $request->phone,
|
||||
'email' => $request->email
|
||||
]);
|
||||
|
||||
$emp = DB::table('inv_employers')
|
||||
->select('id')
|
||||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
|
||||
$cus = DB::table('inv_clients')
|
||||
->select('id')
|
||||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
|
||||
if ($emp->count()) {
|
||||
if (!$request->isEmployer) {
|
||||
DB::table('inv_employers')->where('contact_id', $request->id)->delete();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($request->isEmployer) {
|
||||
DB::table('inv_employers')
|
||||
->where('id', $request->id)
|
||||
->insert([
|
||||
'contact_id' => $request->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($cus->count()) {
|
||||
if (!$request->isCustomer) {
|
||||
DB::table('inv_clients')->where('contact_id', $request->id)->delete();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($request->isCustomer) {
|
||||
DB::table('inv_clients')
|
||||
->where('id', $request->id)
|
||||
->insert([
|
||||
'contact_id' => $request->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return 'Success!';
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteContact(Request $request) { // /api/rpc/invoice/contacts/delete
|
||||
|
@ -343,6 +429,8 @@ class InvoiceController extends Controller {
|
|||
|
||||
if ($valid['inv_mancontact'] == 1) {
|
||||
DB::table('inv_contacts')->where('id', $request->id)->delete();
|
||||
DB::table('inv_employers')->where('contact_id', $request->id)->delete();
|
||||
DB::table('inv_clients')->where('contact_id', $request->id)->delete();
|
||||
|
||||
return 'Done.';
|
||||
}
|
||||
|
@ -352,37 +440,6 @@ class InvoiceController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
// 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')
|
||||
|
|
|
@ -11,16 +11,15 @@
|
|||
|
||||
// Management
|
||||
Route::get('/api/rpc/invoice/company/getcompanies', 'InvoiceController@getCompanies');
|
||||
Route::get('/api/rpc/invoice/company/getcompany', 'InvoiceController@getCompany');
|
||||
Route::get('/api/rpc/invoice/company/getcompany/{id}', 'InvoiceController@getCompany');
|
||||
|
||||
Route::post('/api/rpc/invoice/company/new', 'InvoiceController@newCompany');
|
||||
Route::post('/api/rpc/invoice/company/edit', 'InvoiceController@editCompany');
|
||||
Route::post('/api/rpc/invoice/company/delete', 'InvoiceController@deleteCompany');
|
||||
|
||||
// Relations
|
||||
Route::get('/api/rpc/invoice/clients/getclients', 'InvoiceController@getClients');
|
||||
Route::get('/api/rpc/invoice/contacts/getcontacts', 'InvoiceController@getContacts');
|
||||
Route::get('/api/rpc/invoice/employers/getemployers', 'InvoiceController@getEmployers');
|
||||
Route::get('/api/rpc/invoice/contacts/getcontact/{id}', 'InvoiceController@getContact');
|
||||
|
||||
Route::post('/api/rpc/invoice/contacts/new', 'InvoiceController@newContact');
|
||||
Route::post('/api/rpc/invoice/contacts/edit', 'InvoiceController@editContact');
|
||||
|
|
新しいイシューから参照