Skip to content

Commit

Permalink
#12 added getNextNumber test #9 status values updated in fixtures #3
Browse files Browse the repository at this point in the history
…added 'getNextNumber" method
  • Loading branch information
JoeZ99 committed Feb 13, 2012
1 parent e5d72ee commit 0441446
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Siwapp/CoreBundle/Entity/AbstractInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AbstractInvoice
/**
* @var smallint $status
*
* @ORM\Column(name="status", type="smallint", nullable="true")
* @ORM\Column(name="status", type="smallint", nullable="true", columnDefinition="SMALLINT NULL DEFAULT 0")
*/
private $status;

Expand Down
8 changes: 8 additions & 0 deletions src/Siwapp/CoreBundle/Tests/Model/SiwappBaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class SiwappBaseTest extends \PHPUnit_Framework_TestCase
protected $em;

protected $_tax_repo;
protected $_serie_repo;
protected $_invoice_repo;
protected $_recurring_invoice_repo;
protected $_estimate_repo;
Expand Down Expand Up @@ -52,6 +53,13 @@ protected function getRepo($repo_name)
}
return $this->_tax_repo;
break;
case 'serie':
if(!$this->_serie_repo)
{
$this->_serie_repo = $this->em->getRepository('SiwappCoreBundle:Serie');
}
return $this->_serie_repo;
break;
case 'invoice':
if(!$this->_invoice_repo)
{
Expand Down
38 changes: 19 additions & 19 deletions src/Siwapp/InvoiceBundle/DataFixtures/invoices.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Invoice:
Invoice_1:
draft: false
status: 1 # closed
sent_by_email: false
Serie: Serie_2
number: 1
Expand All @@ -17,7 +17,7 @@ Invoice:
created_at: '2009-04-17 09:45:36'
updated_at: '2009-08-25 10:27:12'
Invoice_2:
draft: false
status: 2 # open
sent_by_email: false
Serie: Serie_1
number: 1
Expand All @@ -34,7 +34,7 @@ Invoice:
created_at: '2009-04-17 09:45:36'
updated_at: '2009-08-25 10:27:12'
Invoice_3:
draft: true
status: 0 # draft
sent_by_email: false
Serie: Serie_2
customer_name: 'Western Gas & Electric'
Expand All @@ -50,7 +50,7 @@ Invoice:
created_at: '2009-04-17 09:45:36'
updated_at: '2009-08-25 10:27:12'
Invoice_4:
draft: false
status: 3 # overdue
sent_by_email: false
Serie: Serie_3
number: 1
Expand All @@ -67,7 +67,7 @@ Invoice:
created_at: '2009-04-17 09:45:36'
updated_at: '2009-08-25 10:27:12'
Invoice_5:
draft: true
status: 0 # draft
sent_by_email: false
Serie: Serie_3
customer_name: '123 Warehousing'
Expand Down Expand Up @@ -100,7 +100,7 @@ Invoice:
created_at: '2009-04-17 09:45:36'
updated_at: '2009-08-25 10:27:12'
Invoice_7:
draft: false
status: 1 # closed
sent_by_email: false
Serie: Serie_1
number: 3
Expand All @@ -117,7 +117,7 @@ Invoice:
created_at: '2009-04-17 09:45:36'
updated_at: '2009-08-25 10:27:13'
Invoice_8:
draft: false
status: 2 # opened
sent_by_email: false
Serie: Serie_1
number: 4
Expand All @@ -134,7 +134,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:13'
Invoice_9:
draft: false
status: 3 # overdue
sent_by_email: false
Serie: Serie_2
number: 2
Expand All @@ -151,7 +151,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:13'
Invoice_10:
draft: false
status: 1 # closed
sent_by_email: false
Serie: Serie_3
number: 2
Expand All @@ -168,7 +168,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:13'
Invoice_11:
draft: false
status: 2 # opened
sent_by_email: false
Serie: Serie_3
number: 3
Expand All @@ -185,7 +185,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:13'
Invoice_12:
draft: false
status: 2 # opened
sent_by_email: false
Serie: Serie_3
number: 4
Expand All @@ -202,7 +202,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:14'
Invoice_13:
draft: false
status: 2 #opened
sent_by_email: false
Serie: Serie_2
number: 3
Expand All @@ -219,7 +219,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:14'
Invoice_14:
draft: true
status: 0 # draft
sent_by_email: false
Serie: Serie_1
customer_name: 'Fake Brothers'
Expand All @@ -235,7 +235,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:14'
Invoice_15:
draft: false
status: 1 # closed
sent_by_email: false
Serie: Serie_1
number: 5
Expand All @@ -252,7 +252,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:14'
Invoice_16:
draft: false
status: 2 # opened
sent_by_email: false
Serie: Serie_1
number: 6
Expand All @@ -269,7 +269,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:14'
Invoice_17:
draft: false
status: 3 # overdue
sent_by_email: false
Serie: Serie_3
number: 5
Expand All @@ -286,7 +286,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:15'
Invoice_18:
draft: false
status: 2 # opened
sent_by_email: false
Serie: Serie_1
number: 7
Expand All @@ -304,7 +304,7 @@ Invoice:
created_at: '2009-04-17 09:45:37'
updated_at: '2009-08-25 10:27:15'
Invoice_19:
draft: false
status: 1 # closed
sent_by_email: false
Serie: Serie_2
number: 4
Expand All @@ -321,7 +321,7 @@ Invoice:
created_at: '2009-04-17 09:45:38'
updated_at: '2009-08-25 10:27:15'
Invoice_20:
draft: false
status: 1 # closed
sent_by_email: false
Serie: Serie_1
number: 8
Expand Down
23 changes: 23 additions & 0 deletions src/Siwapp/InvoiceBundle/Repository/InvoiceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use Siwapp\CoreBundle\Repository\AbstractInvoiceRepository;

use Siwapp\InvoiceBundle\Entity\Invoice;


/**
* InvoiceRepository
*
Expand All @@ -14,4 +17,24 @@
*/
class InvoiceRepository extends AbstractInvoiceRepository
{
/**
* getNextNumber
* Obtain the next numer available for the provided series
* @param \Siwapp\CoreBundle\Entity\Serie @serie
* @return integer
*/
public function getNextNumber($serie)
{
$em = $this->getEntityManager();
$number = $em->createQuery('SELECT MAX(i.number)
FROM \Siwapp\InvoiceBundle\Entity\Invoice i JOIN i.serie s
WHERE i.status!=:draft AND i.serie=:serie')
->setParameters(array(
'draft'=>Invoice::DRAFT,
'serie'=>$serie))
->getSingleScalarResult();

return $number ? intval($number) + 1: $serie->getFirstNumber();

}
}
15 changes: 15 additions & 0 deletions src/Siwapp/InvoiceBundle/Tests/Model/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ public function testTrial()
$this->assertEquals($test_invoice->getGrossAmount(),6903.01);

// TODO: check number generation
$internet_serie = $this->getRepo('serie')->findOneBy(array('name'=>'Internet'));
$design_serie = $this->getRepo('serie')->findOneBy(array('name'=>'Design'));
$others_serie = $this->getRepo('serie')->findOneBy(array('name'=>'Others'));
$this->assertEquals(
$this->getRepo('invoice')->getNextNumber($internet_serie),
9
);
$this->assertEquals(
$this->getRepo('invoice')->getNextNumber($design_serie),
5
);
$this->assertEquals(
$this->getRepo('invoice')->getNextNumber($others_serie),
6
);

// TODO: check that when changing series, the number changes

Expand Down

0 comments on commit 0441446

Please sign in to comment.