private function _get_deliverable_invoices($id) { $mc = org_openpsa_invoices_invoice_item_dba::new_collector('deliverable', $id); $ids = $mc->get_values('invoice'); if (sizeof($ids) < 1) { return array(); } $qb = org_openpsa_invoices_invoice_dba::new_query_builder(); $qb->add_constraint('id', 'IN', $ids); $qb->add_constraint('sent', '>=', $this->_request_data['start']); $qb->add_constraint('sent', '<=', $this->_request_data['end']); return $qb->execute(); }
/** * 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); }
private function _verify_invoice($values, $cycle_number) { $mc = org_openpsa_invoices_invoice_item_dba::new_collector('deliverable', $this->_deliverable->id); $mc->add_constraint('invoice.sent', '=', 0); $mc->add_value_property('invoice'); $mc->set_limit(1); $mc->execute(); $result = $mc->list_keys(); if ($values == false) { $this->assertEquals(0, sizeof($result), 'Invoice was created, which shouldn\'t have happened'); } else { $this->assertEquals(1, sizeof($result), 'Invoice was not created'); $invoice = new org_openpsa_invoices_invoice_dba($mc->get_subkey(key($result), 'invoice')); $this->register_object($invoice); foreach ($values as $field => $value) { if ($field == 'invoice_items') { $this->_verify_invoice_item($invoice, $value); continue; } $this->assertEquals($value, $invoice->{$field}, 'Difference in invoice field ' . $field); } $this->assertEquals($cycle_number, (int) $invoice->parameter('org.openpsa.sales', 'cycle_number'), 'Incorrect cycle number'); } }
private function _find_tasks() { $qb = org_openpsa_projects_task_dba::new_query_builder(); $qb->add_constraint('agreement', '=', $this->_deliverable->id); if ($this->_deliverable->invoiceByActualUnits) { $qb->add_constraint('invoiceableHours', '>', 0); } else { $item_mc = org_openpsa_invoices_invoice_item_dba::new_collector('deliverable', $this->_deliverable->id); $skip_ids = $item_mc->get_values('task'); if (sizeof($skip_ids) > 0) { $qb->add_constraint('id', 'NOT IN', $skip_ids); } } return $qb->execute(); }
/** * Helper that adds a customer/deliverable constraints to list QBs * * @param midcom_core_querybuilder &$qb th QB we're working with */ private function _add_filters(&$qb) { if ($this->_customer) { if (is_a($this->_customer, 'org_openpsa_contacts_group_dba')) { $qb->add_constraint('customer', '=', $this->_customer->id); } else { $qb->add_constraint('customerContact', '=', $this->_customer->id); } } if ($this->_deliverable) { $mc = org_openpsa_invoices_invoice_item_dba::new_collector('deliverable', $this->_deliverable->id); $invoice_ids = $mc->get_values('invoice'); if (!empty($invoice_ids)) { $qb->add_constraint('id', 'IN', $invoice_ids); } else { $qb->add_constraint('id', '=', 0); } } }