예제 #1
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);
 }