Example #1
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_generator($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     $this->_generator_load_redirect($args);
     $this->_handler_generator_style();
     $data['invoices'] = array();
     // Calculate time range
     $data['start'] = $this->_request_data['query_data']['start'];
     $data['end'] = $this->_request_data['query_data']['end'];
     // List sales projects
     $salesproject_mc = org_openpsa_sales_salesproject_dba::new_collector('metadata.deleted', false);
     $salesproject_mc->add_constraint('status', '<>', org_openpsa_sales_salesproject_dba::STATUS_LOST);
     if ($this->_request_data['query_data']['resource'] != 'all') {
         $this->_request_data['query_data']['resource_expanded'] = $this->_expand_resource($this->_request_data['query_data']['resource']);
         $salesproject_mc->begin_group('OR');
         foreach ($this->_request_data['query_data']['resource_expanded'] as $pid) {
             $salesproject_mc->add_constraint('owner', '=', $pid);
         }
         $salesproject_mc->end_group();
     }
     $salesprojects = $salesproject_mc->get_values('id');
     // List deliverables related to the sales projects
     $deliverable_mc = org_openpsa_sales_salesproject_deliverable_dba::new_collector('metadata.deleted', false);
     $deliverable_mc->add_constraint('state', '<>', org_openpsa_sales_salesproject_deliverable_dba::STATUS_DECLINED);
     $deliverable_mc->add_constraint('salesproject', 'IN', $salesprojects);
     $deliverables = $deliverable_mc->get_values('id');
     foreach ($deliverables as $guid => $id) {
         $data['invoices'][$guid] = $this->_get_deliverable_invoices($id);
     }
     $this->add_stylesheet(MIDCOM_STATIC_URL . "/org.openpsa.core/list.css");
 }
Example #2
0
 /**
  * Marks the salesproject as invoiced if no pending deliverables are left
  */
 public function mark_invoiced()
 {
     if ($this->status >= self::STATUS_INVOICED) {
         return;
     }
     $mc = org_openpsa_sales_salesproject_deliverable_dba::new_collector('salesproject', $this->id);
     $mc->add_constraint('state', '<', org_openpsa_sales_salesproject_deliverable_dba::STATUS_INVOICED);
     $mc->add_constraint('state', '<>', org_openpsa_sales_salesproject_deliverable_dba::STATUS_DECLINED);
     $mc->execute();
     if ($mc->count() == 0) {
         $this->status = self::STATUS_INVOICED;
         $this->update();
     }
 }
Example #3
0
 /**
  * Helper function that tries to locate unsent invoices for deliverables in the same salesproject
  *
  * Example use case: A support contract with multiple hourly rates (defined
  * as deliverables) for different types of work. Instead of sending the customer
  * one invoice per hourly rate per month, one composite invoice for all fees is generated
  */
 private function _probe_invoice($cycle_number)
 {
     $deliverable_mc = org_openpsa_sales_salesproject_deliverable_dba::new_collector('salesproject', $this->_deliverable->salesproject);
     $deliverable_mc->add_constraint('state', '>', org_openpsa_sales_salesproject_deliverable_dba::STATUS_DECLINED);
     $deliverable_mc->add_constraint('product.delivery', '=', org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION);
     $deliverables = $deliverable_mc->get_values('id');
     $item_mc = org_openpsa_invoices_invoice_item_dba::new_collector('metadata.deleted', false);
     $item_mc->add_constraint('deliverable.salesproject', '=', $this->_deliverable->salesproject);
     $item_mc->add_constraint('invoice.sent', '=', 0);
     $suspects = $item_mc->get_values('invoice');
     if (sizeof($suspects) > 0) {
         return new org_openpsa_invoices_invoice_dba(array_pop($suspects));
     }
     //Nothing found, create a new invoice
     return $this->_create_invoice($cycle_number);
 }