Invoices stuff.
このコミットが含まれているのは:
コミット
328757b8c8
|
@ -44,7 +44,8 @@ class InvoiceController extends Controller {
|
|||
'bank_name',
|
||||
'bank_recipient',
|
||||
'logo',
|
||||
'payterm'
|
||||
'payterm',
|
||||
'date_format'
|
||||
)
|
||||
->get();
|
||||
}
|
||||
|
@ -75,7 +76,8 @@ class InvoiceController extends Controller {
|
|||
'bank_name',
|
||||
'bank_recipient',
|
||||
'logo',
|
||||
'payterm'
|
||||
'payterm',
|
||||
'date_format'
|
||||
)
|
||||
->where('id', $id)
|
||||
->where('user_id', $check)
|
||||
|
@ -96,7 +98,8 @@ class InvoiceController extends Controller {
|
|||
'bank_name',
|
||||
'bank_recipient',
|
||||
'logo',
|
||||
'payterm'
|
||||
'payterm',
|
||||
'date_format'
|
||||
)
|
||||
->where('id', $id)
|
||||
->get();
|
||||
|
@ -131,7 +134,8 @@ class InvoiceController extends Controller {
|
|||
'bank_name' => $request->bank_name,
|
||||
'bank_recipient' => $request->bank_recipient,
|
||||
'logo' => ($request->logo ? $request->logo : ''),
|
||||
'payterm' => $request->payterm
|
||||
'payterm' => $request->payterm,
|
||||
'date_format' => $request->date_format
|
||||
]);
|
||||
|
||||
return $add;
|
||||
|
@ -165,7 +169,8 @@ class InvoiceController extends Controller {
|
|||
'bank_name' => $request->bank_name,
|
||||
'bank_recipient' => $request->bank_recipient,
|
||||
'logo' => ($request->logo ? $request->logo : ''),
|
||||
'payterm' => $request->payterm
|
||||
'payterm' => $request->payterm,
|
||||
'date_format' => $request->date_format
|
||||
]);
|
||||
}
|
||||
else {
|
||||
|
@ -184,7 +189,8 @@ class InvoiceController extends Controller {
|
|||
'bank_name' => $request->bank_name,
|
||||
'bank_recipient' => $request->bank_recipient,
|
||||
'logo' => ($request->logo ? $request->logo : ''),
|
||||
'payterm' => $request->payterm
|
||||
'payterm' => $request->payterm,
|
||||
'date_format' => $request->date_format
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -230,6 +236,7 @@ class InvoiceController extends Controller {
|
|||
->select(
|
||||
'id',
|
||||
'user_id',
|
||||
'company_name',
|
||||
'name',
|
||||
'address',
|
||||
'postcode',
|
||||
|
@ -244,6 +251,7 @@ class InvoiceController extends Controller {
|
|||
return DB::table('inv_contacts')
|
||||
->select(
|
||||
'id',
|
||||
'company_name',
|
||||
'name',
|
||||
'address',
|
||||
'postcode',
|
||||
|
@ -277,6 +285,7 @@ class InvoiceController extends Controller {
|
|||
->select(
|
||||
'id',
|
||||
'user_id',
|
||||
'company_name',
|
||||
'name',
|
||||
'address',
|
||||
'postcode',
|
||||
|
@ -302,6 +311,7 @@ class InvoiceController extends Controller {
|
|||
$get = DB::table('inv_contacts')
|
||||
->select(
|
||||
'id',
|
||||
'company_name',
|
||||
'name',
|
||||
'address',
|
||||
'postcode',
|
||||
|
@ -333,6 +343,7 @@ class InvoiceController extends Controller {
|
|||
$res[] = array(
|
||||
'id' => $g->id,
|
||||
'user_id' => ($valid['inv_manuser'] === 1 ? $g->user_id : $check),
|
||||
'company_name' => $g->company_name,
|
||||
'name' => $g->name,
|
||||
'address' => $g->address,
|
||||
'postcode' => $g->postcode,
|
||||
|
@ -367,6 +378,7 @@ class InvoiceController extends Controller {
|
|||
$add = DB::table('inv_contacts')
|
||||
->insertGetId([
|
||||
'user_id' => $request->user_id,
|
||||
'company_name' => $request->company_name,
|
||||
'name' => $request->name,
|
||||
'address' => $request->address,
|
||||
'postcode' => $request->postcode,
|
||||
|
@ -395,6 +407,7 @@ class InvoiceController extends Controller {
|
|||
else {
|
||||
$add = DB::table('inv_contacts')
|
||||
->insertGetId([
|
||||
'company_name' => $request->company_name,
|
||||
'name' => $request->name,
|
||||
'address' => $request->address,
|
||||
'postcode' => $request->postcode,
|
||||
|
@ -421,20 +434,6 @@ class InvoiceController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
if ($request->isCustomer) {
|
||||
DB::table('inv_clients')
|
||||
->insert([
|
||||
'contact_id' => $add
|
||||
]);
|
||||
}
|
||||
|
||||
if ($request->isEmployer) {
|
||||
DB::table('inv_employers')
|
||||
->insert([
|
||||
'contact_id' => $add
|
||||
]);
|
||||
}
|
||||
|
||||
return $add;
|
||||
}
|
||||
else {
|
||||
|
@ -458,6 +457,7 @@ class InvoiceController extends Controller {
|
|||
->where('id', $request->id)
|
||||
->update([
|
||||
'user_id' => $request->user_id,
|
||||
'company_name' => $request->company_name,
|
||||
'name' => $request->name,
|
||||
'address' => $request->address,
|
||||
'postcode' => $request->postcode,
|
||||
|
@ -472,39 +472,6 @@ class InvoiceController extends Controller {
|
|||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
|
||||
$cus = DB::table('inv_clients')
|
||||
->select('id')
|
||||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
}
|
||||
else {
|
||||
DB::table('inv_contacts')
|
||||
->where('id', $request->id)
|
||||
->where('user_id', $check)
|
||||
->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('user_id', $check)
|
||||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
|
||||
$cus = DB::table('inv_clients')
|
||||
->select('id')
|
||||
->where('user_id', $check)
|
||||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
}
|
||||
|
||||
if ($valid['inv_manuser'] == 1) {
|
||||
if ($emp->count()) {
|
||||
if (!$request->isEmployer) {
|
||||
DB::table('inv_employers')->where('contact_id', $request->id)->delete();
|
||||
|
@ -521,6 +488,11 @@ class InvoiceController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
$cus = DB::table('inv_clients')
|
||||
->select('id')
|
||||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
|
||||
if ($cus->count()) {
|
||||
if (!$request->isCustomer) {
|
||||
DB::table('inv_clients')->where('contact_id', $request->id)->delete();
|
||||
|
@ -538,6 +510,26 @@ class InvoiceController extends Controller {
|
|||
}
|
||||
}
|
||||
else {
|
||||
DB::table('inv_contacts')
|
||||
->where('id', $request->id)
|
||||
->where('user_id', $check)
|
||||
->update([
|
||||
'company_name' => $request->company_name,
|
||||
'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('user_id', $check)
|
||||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
|
||||
if ($emp->count()) {
|
||||
if (!$request->isEmployer) {
|
||||
DB::table('inv_employers')->where('contact_id', $request->id)->where('user_id', $check)->delete();
|
||||
|
@ -554,6 +546,12 @@ class InvoiceController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
$cus = DB::table('inv_clients')
|
||||
->select('id')
|
||||
->where('user_id', $check)
|
||||
->where('contact_id', $request->id)
|
||||
->get();
|
||||
|
||||
if ($cus->count()) {
|
||||
if (!$request->isCustomer) {
|
||||
DB::table('inv_clients')->where('contact_id', $request->id)->where('user_id', $check)->delete();
|
||||
|
@ -609,25 +607,361 @@ class InvoiceController extends Controller {
|
|||
}
|
||||
|
||||
// Invoices
|
||||
public function getInvoices() { // /api/rpc/invoice/invoices/getinvoices
|
||||
return DB::table('inv_invoices')
|
||||
->select('*')
|
||||
->get();
|
||||
public function getInvoices(Request $request) { // /api/rpc/invoice/invoices/getinvoices
|
||||
$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_makeinvoice'] == 1) {
|
||||
if ($valid['inv_manuser'] == 1) {
|
||||
return DB::table('inv_invoices')
|
||||
->select(
|
||||
'id',
|
||||
'user_id',
|
||||
'year',
|
||||
'inv_number',
|
||||
'revision',
|
||||
'make_date'
|
||||
)
|
||||
->get();
|
||||
|
||||
}
|
||||
else {
|
||||
return DB::table('inv_services')
|
||||
->select(
|
||||
'id',
|
||||
'year',
|
||||
'inv_number',
|
||||
'revision',
|
||||
'make_date'
|
||||
)
|
||||
->where('user_id', $check)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getInvoice($id) { // /api/rpc/invoice/invoices/getinvoice/id
|
||||
return DB::table('inv_invoices')
|
||||
->select('*')
|
||||
->where('id', $id)
|
||||
->get();
|
||||
public function getInvoice($id, Request $request) { // /api/rpc/invoice/invoices/getinvoice/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_makeinvoice'] == 1) {
|
||||
if ($valid['inv_manuser'] == 1) {
|
||||
$u = DB::table('inv_invoices')
|
||||
->select('user_id')
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
$format = DB::table('inv_company')
|
||||
->select('date_format')
|
||||
->where('user_id', $u->user_id)
|
||||
->get();
|
||||
|
||||
$invoice = DB::table('inv_invoices')
|
||||
->select(
|
||||
'id as id',
|
||||
'user_id as user_id',
|
||||
'employer as employer',
|
||||
'customer as customer',
|
||||
'year as year',
|
||||
'inv_number as inv_number',
|
||||
'revision as revision',
|
||||
'make_date as make_date'
|
||||
)
|
||||
->where('id', $id)
|
||||
->get();
|
||||
|
||||
$inv = array();
|
||||
$cus = array();
|
||||
$emp = array();
|
||||
$com = array();
|
||||
$des = array();
|
||||
|
||||
$cus = DB::table('inv_contacts')
|
||||
->select('id', 'company_name', 'name', 'address', 'postcode', 'town', 'country', 'phone', 'email')
|
||||
->where('id', $invoice[0]->customer)
|
||||
->where('user_id', $u->user_id)
|
||||
->get();
|
||||
|
||||
$emp = DB::table('inv_contacts')
|
||||
->select('id', 'company_name', 'name', 'address', 'postcode', 'town', 'country', 'phone', 'email')
|
||||
->where('id', $invoice[0]->employer)
|
||||
->where('user_id', $u->user_id)
|
||||
->get();
|
||||
|
||||
$com = DB::table('inv_company')
|
||||
->select('id', 'name', 'compreg', 'taxnr', 'bank_number', 'bank_name', 'bank_recipient', 'logo', 'payterm')
|
||||
->where('user_id', $u->user_id)
|
||||
->get();
|
||||
|
||||
$zero = '0000';
|
||||
$len = strlen($invoice[0]->inv_number);
|
||||
$num = substr($zero, $len);
|
||||
$fin = $num.$invoice[0]->inv_number;
|
||||
|
||||
$inv[] = array(
|
||||
'id' => $id,
|
||||
'user_id' => $u->user_id,
|
||||
'invoice_date' => strftime($format[0]->date_format, $invoice[0]->make_date),
|
||||
'invoice' => $invoice[0]->year.$fin.($invoice[0]->revision > 0 ? '_R'.$invoice[0]->revision : '')
|
||||
);
|
||||
|
||||
$items = DB::table('inv_invoice_items')
|
||||
->join('inv_services', 'inv_services.id', 'inv_invoice_items.service_id')
|
||||
->where('inv_invoice_items.invoice_id', $id)
|
||||
->where('inv_invoice_items.user_id', $u->user_id)
|
||||
->get(array(
|
||||
'inv_services.id',
|
||||
'inv_services.name',
|
||||
'inv_services.rate',
|
||||
'inv_invoice_items.work_date',
|
||||
'inv_invoice_items.from_time',
|
||||
'inv_invoice_items.to_time'
|
||||
));
|
||||
|
||||
foreach($items as $j) {
|
||||
$des[] = array(
|
||||
'id' => $j->id,
|
||||
'name' => $j->name,
|
||||
'rate' => $j->rate,
|
||||
'work_date' => strftime($format[0]->date_format, $j->work_date),
|
||||
'from_time' => strftime('%H:%M', $j->from_time),
|
||||
'to_time' => strftime('%H:%M', $j->to_time)
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'invoice' => $inv,
|
||||
'company' => $com,
|
||||
'employer' => $emp,
|
||||
'customer' => $cus,
|
||||
'items' => $des
|
||||
);
|
||||
}
|
||||
else {
|
||||
$format = DB::table('inv_company')
|
||||
->select('date_format')
|
||||
->where('user_id', $check)
|
||||
->get();
|
||||
|
||||
$invoice = DB::table('inv_invoices')
|
||||
->join('inv_invoice_items', 'inv_invoice_items.invoice_id', 'inv_invoices.id')
|
||||
->where('inv_invoices.id', $id)
|
||||
->where('user_id', $check)
|
||||
->get(array(
|
||||
'inv_invoices.id as id',
|
||||
'inv_invoices.user_id as user_id',
|
||||
'inv_invoices.employer as employer',
|
||||
'inv_invoices.customer as customer',
|
||||
'inv_invoices.year as year',
|
||||
'inv_invoices.inv_number as inv_number',
|
||||
'inv_invoices.revision as revision',
|
||||
'inv_invoices.make_date as make_date'
|
||||
));
|
||||
|
||||
$res = array();
|
||||
$des = array();
|
||||
|
||||
foreach($invoice as $i) {
|
||||
$customer = DB::table('inv_contacts')
|
||||
->select('id', 'company_name', 'name', 'address', 'postcode', 'town', 'country', 'phone', 'email')
|
||||
->where('id', $i->customer)
|
||||
->where('inv_invoice_items.user_id', $check)
|
||||
->get();
|
||||
|
||||
$employer = DB::table('inv_contacts')
|
||||
->select('id', 'company_name', 'name', 'address', 'postcode', 'town', 'country', 'phone', 'email')
|
||||
->where('id', $i->employer)
|
||||
->where('inv_invoice_items.user_id', $check)
|
||||
->get();
|
||||
|
||||
$items = DB::table('inv_invoice_items')
|
||||
->join('inv_services', 'inv_services.id', 'inv_invoice_items.service_id')
|
||||
->where('inv_invoice_items.invoice_id', $id)
|
||||
->where('inv_invoice_items.user_id', $check)
|
||||
->get(
|
||||
'inv_services.id',
|
||||
'inv_services.name',
|
||||
'inv_services.rate',
|
||||
'inv_invoice_items.work_date',
|
||||
'inv_invoice_items.from_time',
|
||||
'inv_invoice_items.to_time'
|
||||
);
|
||||
|
||||
$company = DB::table('inv_company')
|
||||
->select('id', 'name', 'compreg', 'taxnr', 'bank_number', 'bank_name', 'bank_recipient', 'logo', 'payterm')
|
||||
->where('user_id', $check)
|
||||
->get();
|
||||
|
||||
foreach($items as $j) {
|
||||
$des[] = array(
|
||||
'id' => $j->id,
|
||||
'name' => $j->name,
|
||||
'rate' => $j->rate,
|
||||
'work_date' => $j->work_date,
|
||||
'from_time' => $j->from_time,
|
||||
'to_time' => $j->to_time
|
||||
);
|
||||
}
|
||||
|
||||
$res[] = array(
|
||||
'id' => $id,
|
||||
'user_id' => $check,
|
||||
'employer' => $employer,
|
||||
'customer' => $customer,
|
||||
'company' => $company,
|
||||
'invoice_date' => $i->make_date,
|
||||
'invoice' => $i->year.$i->inv_number.($i->revision > 0 ? '_R'.$i->revision : ''),
|
||||
'items' => $des,
|
||||
);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function newInvoice(Request $request) { // /api/rpc/invoice/invoices/new
|
||||
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_makeinvoice'] == 1) {
|
||||
if ($valid['inv_manuser'] == 1) {
|
||||
$lastInv = DB::table('inv_invoices')
|
||||
->where('year', date('Y'))
|
||||
->where('user_id', $request->user_id)
|
||||
->count();
|
||||
|
||||
$add = DB::table('inv_invoices')
|
||||
->insertGetId([
|
||||
'user_id' => $request->user_id,
|
||||
'contact_id' => $request->contact_id,
|
||||
'year' => date('Y'),
|
||||
'inv_number' => $lastInv->inv_number + 1,
|
||||
'revision' => 0,
|
||||
'make_date' => time()
|
||||
]);
|
||||
|
||||
DB::table('inv_invoice_items')
|
||||
->insert([
|
||||
'user_id' => $request->user_id,
|
||||
'invoice_id' => $add,
|
||||
'service_id' => $request->service_id,
|
||||
'work_date' => $request->work_date,
|
||||
'from_time' => $request->from_time,
|
||||
'to_time' => $request->to_time
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$lastInv = DB::table('inv_invoices')
|
||||
->where('year', date('Y'))
|
||||
->where('user_id', $check)
|
||||
->count();
|
||||
|
||||
$add = DB::table('inv_invoices')
|
||||
->insertGetId([
|
||||
'user_id' => $check,
|
||||
'contact_id' => $request->contact_id,
|
||||
'year' => date('Y'),
|
||||
'inv_number' => $lastInv->inv_number + 1,
|
||||
'revision' => 0,
|
||||
'make_date' => time()
|
||||
]);
|
||||
|
||||
DB::table('inv_invoice_items')
|
||||
->insert([
|
||||
'user_id' => $check,
|
||||
'invoice_id' => $add,
|
||||
'service_id' => $request->service_id,
|
||||
'work_date' => $request->work_date,
|
||||
'from_time' => $request->from_time,
|
||||
'to_time' => $request->to_time
|
||||
]);
|
||||
}
|
||||
|
||||
return $add;
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function editInvoice(Request $request) { // /api/rpc/invoice/invoices/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_makeinvoice'] == 1) {
|
||||
if ($valid['inv_manuser'] == 1) {
|
||||
DB::table('inv_invoices')
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'contact_id' => $request->contact_id,
|
||||
'inv_number' => $request->revision
|
||||
]);
|
||||
|
||||
DB::table('inv_invoice_items')
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'service_id' => $request->service_id,
|
||||
'work_date' => $request->work_date,
|
||||
'from_time' => $request->from_time,
|
||||
'to_time' => $request->to_time
|
||||
]);
|
||||
}
|
||||
else {
|
||||
DB::table('inv_invoices')
|
||||
->where('id', $request->id)
|
||||
->where('user_id', $check)
|
||||
->update([
|
||||
'contact_id' => $request->contact_id,
|
||||
'inv_number' => $request->revision
|
||||
]);
|
||||
|
||||
DB::table('inv_invoice_items')
|
||||
->where('id', $request->id)
|
||||
->where('user_id', $check)
|
||||
->update([
|
||||
'service_id' => $request->service_id,
|
||||
'work_date' => $request->work_date,
|
||||
'from_time' => $request->from_time,
|
||||
'to_time' => $request->to_time
|
||||
]);
|
||||
}
|
||||
|
||||
return 'Success!';
|
||||
}
|
||||
else {
|
||||
return 'Permission denied.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteInvoice(Request $request) { // /api/rpc/invoice/invoices/delete
|
||||
|
@ -670,6 +1004,7 @@ class InvoiceController extends Controller {
|
|||
return DB::table('inv_services')
|
||||
->select(
|
||||
'id',
|
||||
'user_id',
|
||||
'name',
|
||||
'rate'
|
||||
)
|
||||
|
|
新しいイシューから参照