/** * @dataProvider providerCalculate_cycle_next */ public function testCalculate_cycle_next($unit, $start, $result) { $deliverable = new org_openpsa_sales_salesproject_deliverable_dba(); $deliverable->unit = $unit; $scheduler = new org_openpsa_invoices_scheduler($deliverable); $next_cycle = $scheduler->calculate_cycle_next($start); $this->assertEquals(gmstrftime('%Y-%m-%d %H:%M:%S', $result), gmstrftime('%Y-%m-%d %H:%M:%S', $next_cycle), 'Wrong value for unit ' . $unit . ', start value: ' . gmstrftime('%Y-%m-%d %H:%M:%S', $start)); }
private function _get_invoices_for_subscription($deliverable, $at_entry) { if ($deliverable->invoiceByActualUnits && $at_entry->arguments['cycle'] > 1) { $invoice_sum = $deliverable->invoiced / ($at_entry->arguments['cycle'] - 1); if ($invoice_sum == 0) { return array(); } $calculation_base = sprintf($this->_l10n->get('average of %s runs'), $at_entry->arguments['cycle'] - 1); } else { $invoice_sum = $deliverable->price; $calculation_base = $this->_l10n->get('fixed price'); } $salesproject = org_openpsa_sales_salesproject_dba::get_cached($deliverable->salesproject); $scheduler = new org_openpsa_invoices_scheduler($deliverable); $invoices = array(); $time = $at_entry->start; while ($time < $this->_request_data['end'] && ($time < $deliverable->end || $deliverable->continuous)) { $invoice = new org_openpsa_invoices_invoice_dba(); $invoice->customer = $salesproject->customer; $invoice->customerContact = $salesproject->customerContact; $invoice->owner = $salesproject->owner; $invoice->sum = $invoice_sum; $invoice->sent = $time; $invoice->due = $invoice->get_default('due') * 3600 * 24 + $time; $invoice->vat = $invoice->get_default('vat'); $invoice->description = $deliverable->title . ' (' . $calculation_base . ')'; if ($this->_sales_url) { $invoice->description = '<a href="' . $this->_sales_url . 'deliverable/' . $deliverable->guid . '/">' . $invoice->description . '</a>'; } $invoice->paid = $invoice->due; $invoices[] = $invoice; if (!($time = $scheduler->calculate_cycle_next($time))) { debug_add('Failed to calculate timestamp for next cycle, exiting', MIDCOM_LOG_WARN); break; } } return $invoices; }