Beispiel #1
0
     break;
 case 'hawk':
     $Invoice->setFlag(Invoice::FLAG_HAWK);
     $Invoice->save();
     Session::flash('info', 'Hawk monitoring has been added to this invoice, reminders will be according to cron schedule');
     $this->redirect('/invoice/view?i=' . $Invoice['id']);
     break;
 case 'no hawk':
     $Invoice->delFlag(Invoice::FLAG_HAWK);
     $Invoice->save();
     Session::flash('info', 'Hawk monitoring has been removed from this invoice');
     $this->redirect('/invoice/view?i=' . $Invoice['id']);
     break;
 case 'copy':
     // Copy Invoice
     $I_Copy = new Invoice();
     foreach (array('contact_id', 'requester', 'kind', 'status', 'base_rate', 'base_unit', 'bill_address_id', 'ship_address_id', 'note') as $x) {
         $I_Copy[$x] = $Invoice[$x];
     }
     $I_Copy->setFlag(Invoice::FLAG_OPEN);
     $I_Copy->save();
     // Copy Invoice Items
     $list = $Invoice->getInvoiceItems();
     foreach ($list as $II_Orig) {
         $II_Copy = new InvoiceItem(null);
         $II_Copy['invoice_id'] = $I_Copy['id'];
         foreach (array('quantity', 'rate', 'unit', 'name', 'note', 'tax_rate') as $x) {
             $II_Copy[$x] = $II_Orig[$x];
         }
         $II_Copy->save();
     }
Beispiel #2
0
 /**
 	Generate an Invoice from this WorkOrder
 	@param $iv Invoice to Add to
 	@return Invoice
 */
 function toInvoice($iv = null)
 {
     // Add Invoice Items
     $w = null;
     switch ($this['kind']) {
         case 'Monthly':
         case 'Quarterly':
         case 'Yearly':
             $w = array('woi.kind = ? ' => array('Subscription'), 'woi.status = ?' => array('Active'));
             break;
         default:
             $w = array('woi.status in (?)' => array('Active', 'Complete'));
             break;
     }
     $woi_list = $this->getWorkOrderItems($w);
     if (empty($woi_list) || !is_array($woi_list)) {
         throw new Exception('No WorkOrder Items to Generate Invoice');
     }
     // Add to Existing Invoice or Create a New one
     if (!empty($iv)) {
         if ($iv instanceof Invoice) {
             // All Good
         } elseif (is_numeric($iv)) {
             $iv = new Invoice($iv);
         }
     } else {
         $iv = new Invoice();
         $iv['auth_user_id'] = $this['auth_user_id'];
         $iv['contact_id'] = $this['contact_id'];
         $iv['note'] = $this['note'];
         $iv->save();
     }
     // Add Items
     $ivi_c = 0;
     foreach ($woi_list as $woi) {
         $ivi = new InvoiceItem();
         // array();
         $ivi['workorder_item_id'] = $woi['id'];
         $ivi['kind'] = $woi['kind'];
         $ivi['quantity'] = $woi['a_quantity'];
         $ivi['rate'] = $woi['a_rate'];
         $ivi['unit'] = $woi['a_unit'];
         $ivi['tax_rate'] = $woi['a_tax_rate'];
         $ivi['name'] = $woi['name'];
         $ivi['note'] = $woi['note'];
         $iv->addInvoiceItem($ivi);
         $ivi_c++;
         // If Complete then Mark as Billed
         // @todo needs to come from a workflow type list
         // @todo Handle WorkOrder Kind/Status too
         if ($woi['status'] == 'Complete') {
             $woi['status'] = 'Billed';
             $woi->save();
         }
     }
     $iv->save();
     // Close Single Job Work Orders
     if ($this['kind'] == 'Single') {
         $this['status'] = 'Closed';
         // Base_Diff::note($this,'Closed & converted to Invoice');
     }
     $this->save();
     // Add History
     $msg = sprintf('Invoice #%d created from Work Order #%d with %d items', $iv['id'], $this['id'], $ivi_c);
     // Base_Diff::note($this,$msg);
     // Base_Diff::note($iv,$msg);
     // $this->_d->commit();
     return $iv;
 }
Beispiel #3
0
     $I = new Invoice($ii['invoice_id']);
     $I->delInvoiceItem($ii['id']);
     // $ii->delete();
     Session::flash('warn', sprintf('Invoice Item #%d was deleted', $ii['id']));
     Radix::redirect('/invoice/view?i=' . $I['id']);
     break;
 case 'save':
     $ii['invoice_id'] = intval($_POST['invoice_id']);
     foreach (array('kind', 'date', 'quantity', 'rate', 'unit', 'name', 'note', 'tax_rate') as $x) {
         $ii[$x] = trim($_POST[$x]);
     }
     // Save to DB
     $ii->save();
     Session::flash('info', sprintf('Invoice Item #%d saved', $ii['id']));
     // @todo Update the Balance (Sloppy, should be in IV->saveItem()
     $iv = new Invoice($_POST['invoice_id']);
     $iv->save();
     Radix::redirect('/invoice/view?i=' . $ii['invoice_id']);
     break;
     // case 'create':
 // case 'create':
 default:
     // Create
     // Create
     if (empty($_GET['id']) && !empty($_GET['i']) && intval($_GET['i']) > 0) {
         $this->title = array('Invoice', 'Item', 'Create');
         $this->Invoice = new Invoice(intval($_GET['i']));
         $this->InvoiceItem = new InvoiceItem(null);
         $this->InvoiceItem['invoice_id'] = $this->Invoice['id'];
         return 0;
     }