Exemple #1
0
 /**
  */
 public function process_deliverable(org_openpsa_sales_salesproject_deliverable_dba $deliverable, $cycle_number = null)
 {
     $this->_deliverable = $deliverable;
     // Recalculate price to catch possible unit changes
     $client_class = midcom_baseclasses_components_configuration::get('org.openpsa.sales', 'config')->get('calculator');
     $client = new $client_class();
     $client->run($this->_deliverable);
     $this_cycle_amount = $client->get_price();
     if ($this_cycle_amount == 0) {
         debug_add('Invoice sum 0, skipping invoice creation');
         return 0;
     }
     $this->_invoice = $this->_probe_invoice($cycle_number);
     if (!$this->_invoice->update()) {
         throw new midcom_error("The invoice could not be saved. Last Midgard error was: " . midcom_connection::get_error_string());
     }
     // TODO: Create invoicing task if assignee is defined
     $items = $client->get_invoice_items($this->_invoice);
     foreach ($items as $item) {
         $item->deliverable = $this->_deliverable->id;
         $item->skip_invoice_update = true;
         if ($item->id) {
             $stat = $item->update();
         } else {
             $stat = $item->create();
         }
         if (!$stat) {
             throw new midcom_error('Failed to save item to disk, ' . midcom_connection::get_error_string());
         }
     }
     org_openpsa_invoices_invoice_item_dba::update_invoice($this->_invoice);
     org_openpsa_invoices_invoice_item_dba::update_deliverable($this->_deliverable);
     return $this_cycle_amount;
 }