コード例 #1
0
ファイル: InvoiceManagerTest.php プロジェクト: Codixis/CSBill
 public function testCreateFromQuote()
 {
     $currency = new Currency('USD');
     $this->dispatcher->shouldReceive('dispatch')->withAnyArgs();
     $client = new Client();
     $client->setName('Test Client');
     $client->setWebsite('http://example.com');
     $client->setCreated(new \DateTime('NOW'));
     $tax = new Tax();
     $tax->setName('VAT');
     $tax->setRate('14');
     $tax->setType(Tax::TYPE_INCLUSIVE);
     $item = new Item();
     $item->setTax($tax);
     $item->setDescription('Item Description');
     $item->setCreated(new \DateTime('now'));
     $item->setPrice(new Money(120, $currency));
     $item->setQty(10);
     $item->setTotal(new Money(12 * 10, $currency));
     $quote = new Quote();
     $quote->setBaseTotal(new Money(123, $currency));
     $quote->setDiscount(new Money(12, $currency));
     $quote->setNotes('Notes');
     $quote->setTax(new Money(432, $currency));
     $quote->setTerms('Terms');
     $quote->setTotal(new Money(987, $currency));
     $quote->setClient($client);
     $quote->addItem($item);
     $invoice = $this->manager->createFromQuote($quote);
     $this->assertSame($quote->getTotal(), $invoice->getTotal());
     $this->assertSame($quote->getBaseTotal(), $invoice->getBaseTotal());
     $this->assertSame($quote->getDiscount(), $invoice->getDiscount());
     $this->assertSame($quote->getNotes(), $invoice->getNotes());
     $this->assertSame($quote->getTerms(), $invoice->getTerms());
     $this->assertSame($quote->getTax(), $invoice->getTax());
     $this->assertSame($client, $invoice->getClient());
     $this->assertSame('new', $invoice->getStatus());
     $this->assertNotSame($quote->getUuid(), $invoice->getUuid());
     $this->assertNull($invoice->getId());
     $this->assertCount(1, $invoice->getItems());
     /** @var \CSBill\InvoiceBundle\Entity\item[] $invoiceItem */
     $invoiceItem = $invoice->getItems();
     $this->assertInstanceOf('CSBill\\InvoiceBundle\\Entity\\item', $invoiceItem[0]);
     $this->assertSame($item->getTax(), $invoiceItem[0]->getTax());
     $this->assertSame($item->getDescription(), $invoiceItem[0]->getDescription());
     $this->assertInstanceOf('DateTime', $invoiceItem[0]->getCreated());
     $this->assertSame($item->getPrice(), $invoiceItem[0]->getPrice());
     $this->assertSame($item->getQty(), $invoiceItem[0]->getQty());
 }
コード例 #2
0
ファイル: ItemRepository.php プロジェクト: Codixis/CSBill
 /**
  * Removes all tax rates from invoices.
  *
  * @param Tax $tax
  */
 public function removeTax(Tax $tax)
 {
     if (Tax::TYPE_EXCLUSIVE === $tax->getType()) {
         $qb = $this->createQueryBuilder('i');
         $query = $qb->where('i.tax = :tax')->setParameter('tax', $tax)->groupBy('i.quote')->getQuery();
         /** @var Quote $quote */
         foreach ($query->execute() as $quote) {
             $quote->setTotal($quote->getBaseTotal() + $quote->getTax());
             $quote->setTax(null);
             $this->getEntityManager()->persist($quote);
         }
         $this->getEntityManager()->flush();
     }
     $qb = $this->createQueryBuilder('q')->update()->set('q.tax', 'NULL')->where('q.tax = :tax')->setParameter('tax', $tax);
     $qb->getQuery()->execute();
 }
コード例 #3
0
ファイル: TaxType.php プロジェクト: csbill/csbill
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('name');
     $builder->add('rate', PercentType::class, ['precision' => 2]);
     $types = Tax::getTypes();
     array_walk($types, function (&$value) {
         $value = ucwords($value);
     });
     $builder->add('type', Select2::class, ['choices' => $types, 'help' => 'tax.rates.explanation', 'placeholder' => 'tax.rates.type.select']);
 }
コード例 #4
0
ファイル: TaxType.php プロジェクト: Codixis/CSBill
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('name');
     $builder->add('rate', 'percent', array('precision' => 2));
     $types = Tax::getTypes();
     array_walk($types, function (&$value) {
         $value = ucwords($value);
     });
     $builder->add('type', 'select2', array('choices' => $types, 'choices_as_values' => false, 'help' => 'tax.rates.explanation', 'placeholder' => 'tax.rates.type.select'));
 }
コード例 #5
0
ファイル: DefaultController.php プロジェクト: Codixis/CSBill
 /**
  * @param Tax $tax
  *
  * @return JsonResponse
  */
 public function getAction(Tax $tax)
 {
     $result = array('id' => $tax->getId(), 'name' => $tax->getName(), 'type' => $tax->getType(), 'rate' => $tax->getRate());
     return new JsonResponse($result);
 }
コード例 #6
0
ファイル: DefaultController.php プロジェクト: csbill/csbill
 /**
  * @param Tax $tax
  *
  * @return JsonResponse
  */
 public function getAction(Tax $tax)
 {
     $result = ['id' => $tax->getId(), 'name' => $tax->getName(), 'type' => $tax->getType(), 'rate' => $tax->getRate()];
     return $this->json($result);
 }