Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link quotes to invoices when accepting a quote and creating the invoice #228

Merged
merged 4 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/DoctrineMigrations/Version200.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public function up(Schema $schema)

$this->addSql('ALTER TABLE invoices DROP users');
$this->addSql('ALTER TABLE quotes DROP users');

$this->addSql('ALTER TABLE invoices ADD quote_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE invoices ADD CONSTRAINT FK_6A2F2F95DB805178 FOREIGN KEY (quote_id) REFERENCES quotes (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_6A2F2F95DB805178 ON invoices (quote_id)');
$this->addSql('CREATE INDEX quote ON invoices (quote_id)');
}

/**
Expand Down
37 changes: 29 additions & 8 deletions src/InvoiceBundle/Entity/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Money\Money;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use SolidInvoice\ClientBundle\Entity\Client;
use SolidInvoice\ClientBundle\Entity\Contact;
use SolidInvoice\CoreBundle\Entity\Discount;
Expand All @@ -23,19 +30,13 @@
use SolidInvoice\InvoiceBundle\Traits\InvoiceStatusTrait;
use SolidInvoice\MoneyBundle\Entity\Money as MoneyEntity;
use SolidInvoice\PaymentBundle\Entity\Payment;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use SolidInvoice\QuoteBundle\Entity\Quote;
use Symfony\Component\Serializer\Annotation as Serialize;
use Money\Money;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @ApiResource(attributes={"normalization_context"={"groups"={"invoice_api"}}, "denormalization_context"={"groups"={"create_invoice_api"}}})
* @ORM\Table(name="invoices")
* @ORM\Table(name="invoices", indexes={@ORM\Index(name="quote", columns={"quote_id"})})
* @ORM\Entity(repositoryClass="SolidInvoice\InvoiceBundle\Repository\InvoiceRepository")
* @Gedmo\Loggable()
* @Gedmo\SoftDeleteable()
Expand Down Expand Up @@ -207,6 +208,13 @@ class Invoice
*/
private $recurring;

/**
* @var Quote|null
*
* @ORM\OneToOne(targetEntity="SolidInvoice\QuoteBundle\Entity\Quote", inversedBy="invoice")
*/
private $quote;

public function __construct()
{
$this->discount = new Discount();
Expand Down Expand Up @@ -687,4 +695,17 @@ public function __clone()
$this->recurring = false;
$this->status = null;
}

public function getQuote(): ?Quote
{
return $this->quote;
}

public function setQuote(Quote $quote): self
{
$this->quote = $quote;
$quote->setInvoice($this);

return $this;
}
}
1 change: 1 addition & 0 deletions src/InvoiceBundle/Manager/InvoiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function createFromQuote(Quote $quote): Invoice
$invoice->setTerms($quote->getTerms());
$invoice->setUsers($quote->getUsers()->toArray());
$invoice->setBalance($invoice->getTotal());
$invoice->setQuote($quote);

if (null !== $quote->getTax()) {
$invoice->setTax($quote->getTax());
Expand Down
1 change: 1 addition & 0 deletions src/InvoiceBundle/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ invoice:
edit: Edit
reopen: Re-Open
clone: Clone
view_quote: View Quote
payments: Payments
clone:
success: 'Invoice cloned successfully'
Expand Down
5 changes: 5 additions & 0 deletions src/InvoiceBundle/Resources/views/Default/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<div class="pull-right no-print">
<div class="btn-toolbar">
<div class="btn-group">
{% if invoice.quote is not null %}
<a href="{{ path('_quotes_view', {'id' : invoice.quote.id}) }}" class="btn btn-default">
{{ icon('file-text-o') }} {{ "invoice.view.toolbar.view_quote"|trans }}
</a>
{% endif %}
<a href="{{ path('_invoices_clone', {'id' : invoice.id}) }}" class="btn btn-default">
{{ icon('clone') }} {{ "invoice.view.toolbar.clone"|trans }}
</a>
Expand Down
20 changes: 20 additions & 0 deletions src/QuoteBundle/Entity/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SolidInvoice\CoreBundle\Entity\Discount;
use SolidInvoice\CoreBundle\Entity\ItemInterface;
use SolidInvoice\CoreBundle\Traits\Entity;
use SolidInvoice\InvoiceBundle\Entity\Invoice;
use SolidInvoice\MoneyBundle\Entity\Money as MoneyEntity;
use SolidInvoice\QuoteBundle\Traits\QuoteStatusTrait;
use Doctrine\Common\Collections\ArrayCollection;
Expand Down Expand Up @@ -161,6 +162,13 @@ class Quote
*/
private $users;

/**
* @var Invoice|null
*
* @ORM\OneToOne(targetEntity="SolidInvoice\InvoiceBundle\Entity\Invoice", mappedBy="quote")
*/
private $invoice;

public function __construct()
{
$this->discount = new Discount();
Expand Down Expand Up @@ -472,4 +480,16 @@ public function updateItems()
}
}
}

public function setInvoice(Invoice $invoice): self
{
$this->invoice = $invoice;

return $this;
}

public function getInvoice(): ?Invoice
{
return $this->invoice;
}
}
1 change: 1 addition & 0 deletions src/QuoteBundle/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ quote:
edit: Edit
reopen: Re-Open
clone: Clone
view_invoice: View Invoice
online: 'View this quote online at: %url%'
clone:
success: 'Quote cloned successfully'
Expand Down
5 changes: 5 additions & 0 deletions src/QuoteBundle/Resources/views/Default/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
<div class="pull-right no-print">
<div class="btn-toolbar">
<div class="btn-group">
{% if quote.invoice is not null %}
<a href="{{ path('_invoices_view', {'id' : quote.invoice.id}) }}" class="btn btn-default">
{{ icon('file-text-o') }} {{ "quote.view.toolbar.view_invoice"|trans }}
</a>
{% endif %}
<a href="{{ path('_quotes_clone', {'id' : quote.id}) }}" class="btn btn-default">
{{ icon('clone') }} {{ "quote.view.toolbar.clone"|trans }}
</a>
Expand Down
3 changes: 3 additions & 0 deletions src/QuoteBundle/Tests/Form/Handler/QuoteCreateHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use SolidInvoice\CoreBundle\Response\FlashResponse;
use SolidInvoice\CoreBundle\Templating\Template;
use SolidInvoice\FormBundle\Test\FormHandlerTestCase;
use SolidInvoice\InvoiceBundle\Entity\Invoice;
use SolidInvoice\InvoiceBundle\Listener\WorkFlowSubscriber as InvoiceWorkFlowSubscriber;
use SolidInvoice\InvoiceBundle\Manager\InvoiceManager;
use SolidInvoice\MoneyBundle\Entity\Money;
Expand Down Expand Up @@ -130,6 +131,7 @@ protected function getEntityNamespaces(): array
{
return [
'SolidInvoiceClientBundle' => 'SolidInvoice\ClientBundle\Entity',
'SolidInvoiceInvoiceBundle' => 'SolidInvoice\InvoiceBundle\Entity',
'SolidInvoiceQuoteBundle' => 'SolidInvoice\QuoteBundle\Entity',
'SolidInvoicePaymentBundle' => 'SolidInvoice\PaymentBundle\Entity',
'SolidInvoiceTaxBundle' => 'SolidInvoice\TaxBundle\Entity',
Expand All @@ -140,6 +142,7 @@ protected function getEntities(): array
{
return [
Client::class,
Invoice::class,
Quote::class,
Tax::class,
];
Expand Down
3 changes: 3 additions & 0 deletions src/QuoteBundle/Tests/Form/Handler/QuoteEditHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use SolidInvoice\CoreBundle\Response\FlashResponse;
use SolidInvoice\CoreBundle\Templating\Template;
use SolidInvoice\FormBundle\Test\FormHandlerTestCase;
use SolidInvoice\InvoiceBundle\Entity\Invoice;
use SolidInvoice\InvoiceBundle\Listener\WorkFlowSubscriber as InvoiceWorkFlowSubscriber;
use SolidInvoice\InvoiceBundle\Manager\InvoiceManager;
use SolidInvoice\MoneyBundle\Entity\Money;
Expand Down Expand Up @@ -152,6 +153,7 @@ protected function getEntityNamespaces(): array
{
return [
'SolidInvoiceClientBundle' => 'SolidInvoice\ClientBundle\Entity',
'SolidInvoiceInvoiceBundle' => 'SolidInvoice\InvoiceBundle\Entity',
'SolidInvoiceQuoteBundle' => 'SolidInvoice\QuoteBundle\Entity',
'SolidInvoicePaymentBundle' => 'SolidInvoice\PaymentBundle\Entity',
'SolidInvoiceTaxBundle' => 'SolidInvoice\TaxBundle\Entity',
Expand All @@ -162,6 +164,7 @@ protected function getEntities(): array
{
return [
Client::class,
Invoice::class,
Quote::class,
Tax::class,
];
Expand Down