Skip to content

Commit

Permalink
Select default client and contact when creating a new quote or invoice (
Browse files Browse the repository at this point in the history
#224)

Fixes #138
  • Loading branch information
LillyMich authored and pierredup committed Nov 6, 2018
1 parent aec5cb8 commit c8b5dae
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/ClientBundle/Resources/public/js/view/client_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ define(
if (!this.model.isEmpty()) {
this.ui.clientSelect.hide();
}
this.selectDefaultClientContact();
},
clientChange: function(event) {
event.preventDefault();
Expand Down Expand Up @@ -59,7 +60,8 @@ define(
);
},
_toggleContactInfo: function(show) {
let clientSelect = this.$('#client-select');
const clientSelect = this.$('#client-select');
const clientSelectContainer = this.$('#client-select-container');
clientSelect.toggle();

if (clientSelect.is(':visible')) {
Expand All @@ -68,12 +70,19 @@ define(

if (!_.isUndefined(show)) {
if (true === show) {
this.$('#client-select-container').show();
clientSelectContainer.show();
} else {
this.$('#client-select-container').hide();
clientSelectContainer.hide();
}
} else {
this.$('#client-select-container').toggle();
clientSelectContainer.toggle();
}
},
selectDefaultClientContact: function () {
const clientSelectContainer = this.$('#client-select-container');
const clientSelectContainerCheckbox = clientSelectContainer.find('input[type="checkbox"]');
if (clientSelectContainerCheckbox.length === 1){
clientSelectContainerCheckbox.prop("checked", true);
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion src/ClientBundle/Resources/views/Ajax/info.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<li class="item">
<div class="checkbox">
<label for="client-contact-{{ contact.id }}">
<input type="checkbox" name="{{ type }}[users][]" value="{{ contact.id }}" id="client-contact-{{ contact.id }}" />
<input type="checkbox" name="{{ type }}[users][]" value="{{ contact.id }}" id="client-contact-{{ contact.id }}"
{{ client.contacts|length == 1 ? "checked" : ""}}/>
{{ contact }}
</label>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/InvoiceBundle/Action/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ public function __construct(FormHandler $handler, ClientRepository $clientReposi

public function __invoke(Request $request, Client $client = null)
{
if (!$this->clientRepository->getTotalClients()) {
$totalClientsCount = $this->clientRepository->getTotalClients();
if (!$totalClientsCount) {
return new Template('@SolidInvoiceInvoice/Default/empty_clients.html.twig');
}
if (1 === $totalClientsCount && null === $client) {
$client = $this->clientRepository->findOneBy([]);
}

$invoice = new Invoice();
$invoice->setClient($client);
Expand Down
6 changes: 5 additions & 1 deletion src/QuoteBundle/Action/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ public function __construct(ClientRepository $repository, FormHandler $handler)

public function __invoke(Request $request, Client $client = null)
{
if (!$this->repository->getTotalClients()) {
$totalClientsCount = $this->repository->getTotalClients();
if (!$totalClientsCount) {
return new Template('@SolidInvoiceQuote/Default/empty_clients.html.twig');
}
if (1 === $totalClientsCount && null === $client) {
$client = $this->repository->findOneBy([]);
}

$quote = new Quote();
$quote->setClient($client);
Expand Down

0 comments on commit c8b5dae

Please sign in to comment.