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;
 }
Exemple #2
0
midcom::get('auth')->require_admin_user();
// Ensure this is not buffered
midcom::get('cache')->content->enable_live_mode();
while (@ob_end_flush()) {
    midcom::get()->disable_limits();
}
echo "<h1>Invalidating deliverable caches:</h1>\n";
$qb = org_openpsa_sales_salesproject_deliverable_dba::new_query_builder();
$qb->add_constraint('state', '>=', org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED);
$deliverables = $qb->execute();
echo "<pre>\n";
flush();
foreach ($deliverables as $deliverable) {
    $start = microtime(true);
    echo "Update caches for deliverable #{$deliverable->id} " . $deliverable->title . "\n";
    echo "units: {$deliverable->units} uninvoiceable: {$deliverable->uninvoiceableUnits} price: {$deliverable->price} cost: {$deliverable->cost} invoiced: {$deliverable->invoiced}\n";
    flush();
    $deliverable->calculate_price(false);
    org_openpsa_invoices_invoice_item_dba::update_deliverable($deliverable);
    $deliverable->update_units();
    $deliverable->update();
    $time_consumed = round(microtime(true) - $start, 2);
    echo "OK ({$time_consumed} secs), new units:\n";
    echo "units: {$deliverable->units} uninvoiceable: {$deliverable->uninvoiceableUnits} price: {$deliverable->price} cost: {$deliverable->cost} invoiced: {$deliverable->invoiced}\n";
    flush();
}
?>
</pre>
<p>All done</p>