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());
 }
Exemple #2
0
 /**
  * @param Request $request
  * @param Client  $client
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function addAction(Request $request, Client $client)
 {
     $form = $this->createForm(new CreditType(), null, array('action' => $this->generateUrl('_clients_add_credit', array('id' => $client->getId()))));
     $form->handleRequest($request);
     if ($form->isValid()) {
         /** @var CreditRepository $clientRepository */
         $clientRepository = $this->getRepository('CSBillClientBundle:Credit');
         /** @var Money $amount */
         $amount = $form->get('amount')->getData();
         $credit = $clientRepository->addCredit($client, $amount);
         return $this->json(array('status' => 'success', 'amount' => $this->get('csbill.money.formatter')->format($credit->getValue())));
     }
     $content = $this->renderView('CSBillClientBundle:Ajax:credit_add.html.twig', array('form' => $form->createView()));
     return $this->json(array('content' => $content));
 }
Exemple #3
0
 /**
  * @ApiDoc(
  *     statusCodes={
  *         204="Returned when successful",
  *         403="Returned when the user is not authorized",
  *         404="Returned when the contact does not exist on the client",
  *     },
  *     resource=true,
  *     description="Delete a contact",
  *     authentication=true,
  * )
  *
  * @param Entity\Client  $client
  * @param Entity\Contact $contact
  *
  * @Rest\Delete(path="/client/{clientId}/contact/{contactId}")
  *
  * @ParamConverter("client", class="CSBillClientBundle:Client", options={"id" : "clientId"})
  * @ParamConverter("contact", class="CSBillClientBundle:Contact", options={"id" : "contactId"})
  *
  * @return Response
  */
 public function deleteContactAction(Entity\Client $client, Entity\Contact $contact)
 {
     if (!$client->getContacts()->contains($contact)) {
         throw $this->createNotFoundException();
     }
     return $this->deleteEntity($contact);
 }
Exemple #4
0
 /**
  * @param Client $client
  * @param Money  $amount
  *
  * @return \CSBill\ClientBundle\Entity\Credit
  */
 public function deductCredit(Client $client, Money $amount)
 {
     $credit = $client->getCredit();
     $credit->setValue($credit->getValue()->subtract($amount));
     return $this->save($credit);
 }
Exemple #5
0
 /**
  * @param Client $client
  * @param array  $originalAddresses
  */
 private function removeClientAddresses(Client $client, array $originalAddresses)
 {
     $entityManager = $this->getEm();
     foreach ($client->getAddresses() as $originalAddress) {
         foreach ($originalAddresses as $key => $toDel) {
             if ($toDel->getId() === $originalAddress->getId()) {
                 unset($originalAddresses[$key]);
             }
         }
     }
     foreach ($originalAddresses as $address) {
         $client->removeAddress($address);
         $entityManager->remove($address);
     }
 }
Exemple #6
0
 /**
  * @param Client $client
  * @param array  $originalContactsDetails
  */
 private function removeClientContacts(Client $client, array $originalContactsDetails)
 {
     $entityManager = $this->getEm();
     $originalContacts = $client->getContacts()->toArray();
     foreach ($client->getContacts() as $originalContact) {
         foreach ($originalContacts as $key => $toDel) {
             if ($toDel->getId() === $originalContact->getId()) {
                 unset($originalContacts[$key]);
             }
         }
     }
     foreach ($originalContacts as $contact) {
         $entityManager->remove($contact);
         $client->removeContact($contact);
     }
     unset($contact, $key, $toDel);
     foreach ($client->getContacts() as $contact) {
         foreach ($contact->getAdditionalDetails() as $originalContactDetail) {
             foreach ($originalContactsDetails[$contact->getId()] as $key => $toDel) {
                 if ($toDel->getId() === $originalContactDetail->getId()) {
                     unset($originalContactsDetails[$contact->getId()][$key]);
                 }
             }
         }
         foreach ($originalContactsDetails[$contact->getId()] as $contactDetail) {
             $entityManager->remove($contactDetail);
             $contact->removeAdditionalDetail($contactDetail);
         }
     }
 }
Exemple #7
0
 /**
  * @param Client $client
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function getCreditAction(Client $client)
 {
     $credit = $client->getCredit();
     return $this->json(['credit' => $this->get('csbill.money.formatter')->toFloat($credit->getValue()), 'id' => $credit->getId()]);
 }