Skip to content

Commit

Permalink
do some work for dinero intergration with new invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
Bottelet committed Sep 1, 2017
1 parent b7cae6c commit 727932f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 77 deletions.
14 changes: 7 additions & 7 deletions app/Dinero.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ public static function sendInvoice($invoiceGuid, $timestamp)
return $res;
}

public function getContacts()
{
$res = self::getClient()->request('GET', 'https://api.dinero.dk/v1/'
. self::$organizationId . '/contacts?field=Name,ContactGuid', [
'verify' => false,
'headers' => [
'Authorization' => 'Bearer ' . self::$accessToken
public function getContacts($filter = "")
{
$res = self::getClient()->request("GET", "https://api.dinero.dk/v1/"
. self::$organizationId . "/contacts?field=Name,ContactGuid&queryFilter=Email+contains+" . "'" . $filter . "'", [
"verify" => false,
"headers" => [
"Authorization" => "Bearer " . self::$accessToken
]
]);

Expand Down
21 changes: 20 additions & 1 deletion app/Http/Controllers/InvoicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Http\Request;
use App\Repositories\Invoice\InvoiceRepositoryContract;
use App\Repositories\Client\ClientRepositoryContract;
use App\Models\Integration;

class InvoicesController extends Controller
{
Expand Down Expand Up @@ -50,8 +51,26 @@ public function create()
*/
public function show($id)
{
$integrationCheck = Integration::first();
$invoice = $this->invoices->find($id);
if ($integrationCheck) {
$api = Integration::getApi('billing');
$apiConnected = true;
$invoiceContacts = $api->getContacts($invoice->client->email);
// If we can't find a client in the integration, show all
if (!$invoiceContacts) {
$invoiceContacts = $api->getContacts();
}

} else {
$apiConnected = false;
$invoiceContacts = [];
}

return view('invoices.show')
->withInvoice($this->invoices->find($id));
->withInvoice($invoice)
->withApiconnected($apiConnected)
->withContacts($invoiceContacts);
}

/**
Expand Down
15 changes: 1 addition & 14 deletions app/Http/Controllers/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,11 @@ public function store(StoreTaskRequest $request) // uses __contrust request
*/
public function show(Request $request, $id)
{
$integrationCheck = Integration::first();

if ($integrationCheck) {
$api = Integration::getApi('billing');
$apiConnected = true;
$invoiceContacts = $api->getContacts();
} else {
$apiConnected = false;
$invoiceContacts = [];
}

return view('tasks.show')
->withTasks($this->tasks->find($id))
->withUsers($this->users->getAllUsersWithDepartments())
->withContacts($invoiceContacts)
->withInvoiceLines($this->tasks->getInvoiceLines($id))
->withCompanyname($this->settings->getCompanyName())
->withApiconnected($apiConnected);
->withCompanyname($this->settings->getCompanyName());
}


Expand Down
18 changes: 7 additions & 11 deletions app/Repositories/Invoice/InvoiceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\Task;
use Session;
use App\Models\InvoiceLine;
use App\Models\Activity;

class InvoiceRepository implements InvoiceRepositoryContract
{
Expand All @@ -29,16 +30,18 @@ public function find($id)
public function invoice($id, $requestData)
{
$contatGuid = $requestData->invoiceContact;
$invoice_lines = Invoice::find($id)->invoiceLines;

$invoice = Invoice::find($id);
$invoice_lines = $invoice->invoiceLines;
$sendMail = $requestData->sendMail;
$productlines = [];

foreach ($invoice_lines as $invoice_line) {
$productlines[] = [
'Description' => $invoice_line->title,
'Comments' => $invoice_line->comment,
'BaseAmountValue' => $invoice_line->value,
'Quantity' => $invoice_line->time,
'BaseAmountValue' => $invoice_line->price,
'Quantity' => $invoice_line->quantity,
'AccountNumber' => 1000,
'Unit' => 'hours'];
}
Expand All @@ -47,17 +50,10 @@ public function invoice($id, $requestData)

$results = $api->createInvoice([
'currency' => 'DKK',
'description' => $task->title,
'description' => $invoice->title,
'contact_id' => $contatGuid,
'product_lines' => $productlines]);

Activity::create([
'text' => "user has created, a invoice draft for this task",
'user_id' => Auth()->id(),
'source_type' => Invoice::class,
'source_id' => $invoice->id,
'action' => "sent_invoice"
]);
if ($sendMail == true) {
$booked = $api->bookInvoice($results->Guid, $results->TimeStamp);
$bookGuid = $booked->Guid;
Expand Down
4 changes: 3 additions & 1 deletion resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,7 @@
"Create lead": "Creat lead",
"Insert task title (will be shown on invoice": "Insert task title (will be shown on invoice",
"A short description, as to what is being billed": "A short description, as to what is being billed",
"Can't insert new invoice line, to already sent invoice": "Can't insert new invoice line, to already sent invoice"
"Can't insert new invoice line, to already sent invoice": "Can't insert new invoice line, to already sent invoice",
"Once a invoice has been send, no new invoice lines can be added": "Once a invoice has been send, no new invoice lines can be added",
"We have found this contact from your, billing integration, do you wish for us to send it to your billing system aswell?": "We have found this contact from your, billing integration, do you wish for us to send it to your billing system aswell?"
}
42 changes: 35 additions & 7 deletions resources/views/invoices/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,47 @@
{{ date('d-m-Y', strtotime($invoice->payment_received_at))}}
@endif
<br/><br/>
@if(!$invoice->sent_at)
<button type="button" class="btn btn-success form-control closebtn" value="add_time_modal" data-toggle="modal" data-target="#SendInvoiceModalConfirm" >
{{ __('Set invoice as sent') }}
</button>

@if(!$invoice->sent_at)
{!! Form::open([
</div>


<div class="modal fade" id="SendInvoiceModalConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">
{{ __('Are you sure?') }}
</h4>
<p>{{ __('Once a invoice has been send, no new invoice lines can be added') }}</p>
{!! Form::open([
'method' => 'post',
'route' => ['invoice.sent', $invoice->id],
]) !!}

@if($apiconnected)
<p>{{ __('We have found this contact from your, billing integration, do you wish for us to send it to your billing system aswell?') }}</p>
@foreach ($contacts as $key => $contact)
{!! Form::radio('invoiceContact', $contact['guid']) !!}
{{$contact['name']}}
<br/>
@endforeach
{!! Form::label('mail', __('Send mail with invoice to Customer?(Cheked = Yes):'), ['class' => 'control-label']) !!}
{!! Form::checkbox('sendMail', true) !!}
@endif
{!! Form::submit('Set invoice as sent', ['class' => 'btn btn-success form-control closebtn']) !!}
</div>

{!! Form::close() !!}
@endif


</div>

</div>
</div>
</div>
@endif
@if($invoice->sent_at)

@if(!$invoice->payment_received_at)
Expand Down
36 changes: 0 additions & 36 deletions resources/views/tasks/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,42 +106,6 @@
</div>

@include('invoices._invoiceLineModal', ['title' => $tasks->title, 'id' => $tasks->id, 'type' => 'task'])

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">{{ __('Create invoice')}} </h4>
</div>

{!! Form::model($tasks, [
'method' => 'POST',
'url' => ['tasks/invoice', $tasks->id],
]) !!}
<div class="modal-body">
@if($apiconnected)
@foreach ($contacts as $key => $contact)
{!! Form::radio('invoiceContact', $contact['guid']) !!}
{{$contact['name']}}
<br/>
@endforeach
{!! Form::label('mail', __('Send mail with invoice to Customer?(Cheked = Yes):'), ['class' => 'control-label']) !!}
{!! Form::checkbox('sendMail', true) !!}
@endif
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default col-lg-6"
data-dismiss="modal">{{ __('Close') }}</button>
<div class="col-lg-6">
{!! Form::submit(__('Create'), ['class' => 'btn btn-success form-control closebtn']) !!}
</div>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
</div>
@stop

0 comments on commit 727932f

Please sign in to comment.