Beispiel #1
0
 /**
  * setLastInvoice
  * Set the last invoice number
  * @param $current_invoice_number
  * @return Doctrine Record
  */
 public static function setLastInvoice($current_invoice_number)
 {
     $isp_id = Shineisp_Registry::get('ISP')->isp_id;
     $isp_id = intval($isp_id);
     $increment = Invoices::sequentialIncrement();
     // Try to get last invoice number
     $record = Doctrine_Query::create()->select('setting_id')->from('InvoicesSettings is')->where('is.year = ?', date('Y'))->andWhere('is.isp_id = ?', $isp_id)->limit(1)->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
     $record = array_shift($record);
     if ($record['setting_id'] > 0) {
         return Doctrine_Query::create()->update('InvoicesSettings')->set('next_number', $current_invoice_number + $increment)->where('year = ?', date('Y'))->andWhere('isp_id = ?', $isp_id)->execute();
     }
     $InvoicesSettings = new self();
     $InvoicesSettings->next_number = $current_invoice_number + $increment;
     $InvoicesSettings->year = date('Y');
     $InvoicesSettings->isp_id = $isp_id;
     $InvoicesSettings->save();
 }