Esempio n. 1
0
 /**
  * @param  Invoice $invoice
  * @return string
  */
 protected function getIssueDateAddition(Invoice $invoice)
 {
     switch ($invoice->getStatus()) {
         case Invoice::STATUS_DRAFT:
         case Invoice::STATUS_SENT:
             if ($invoice->getDueDate() === null) {
                 return 'No due date';
             }
             $dueTime = $invoice->getDueDate()->diff($invoice->getIssueDate())->days;
             return sprintf('Due in %d %s', $dueTime, $dueTime === 1 ? 'day' : 'days');
         case Invoice::STATUS_LATE:
             $lateTime = $invoice->getDueDate()->diff($invoice->getIssueDate())->days;
             return sprintf('%d %s late', $lateTime, $lateTime === 1 ? 'day' : 'days');
         case Invoice::STATUS_PAID:
             $payTime = $invoice->getPayDate()->diff($invoice->getIssueDate())->days;
             return sprintf('Paid in %d %s', $payTime, $payTime === 1 ? 'day' : 'days');
     }
     throw new RuntimeException(sprintf('Invalid invoice status "%s"', $invoice->getStatus()));
 }
Esempio n. 2
0
 /**
  * @param Invoice $invoice
  * @param string  $status
  */
 public function changeStatus(Invoice $invoice, $status)
 {
     switch ($status) {
         case 'draft':
             $invoice->setSendDate(null);
             $invoice->setPayDate(null);
             break;
         case 'sent':
             if ($invoice->getSendDate() === null) {
                 $invoice->setSendDate(new DateTime());
             }
             $invoice->setPayDate(null);
             break;
         case 'paid':
             if ($invoice->getSendDate() === null) {
                 $invoice->setSendDate(new DateTime());
             }
             if ($invoice->getPayDate() === null) {
                 $invoice->setPayDate(new DateTime());
             }
             break;
         default:
             throw new RuntimeException(sprintf('Invalid status: %s', $status));
     }
     $this->persist($invoice);
 }