Ejemplo n.º 1
0
 /**
  *
  * @param mixed $handler_id The ID of the handler.
  * @param array &$data The local request data.
  */
 public function _show_generator($handler_id, array &$data)
 {
     midcom_show_style('sales_report-deliverable-start');
     // Quick workaround to Bergies lazy determination of whether this is user's or everyone's report...
     if ($this->_request_data['query_data']['resource'] == 'user:'******'auth')->user->guid) {
         // My report
         $data['handler_id'] = 'deliverable_report';
     } else {
         // Generic report
         $data['handler_id'] = 'sales_report';
     }
     /*** Copied from sales/handler/deliverable/report.php ***/
     midcom_show_style('sales_report-deliverable-header');
     $invoices_node = midcom_helper_misc::find_node_by_component('org.openpsa.invoices');
     $sums_per_person = array();
     $sums_all = array('price' => 0, 'cost' => 0, 'profit' => 0);
     $odd = true;
     foreach ($data['invoices'] as $deliverable_guid => $invoices) {
         if (count($invoices) == 0) {
             // No invoices sent in this project, skip
             continue;
         }
         try {
             $deliverable = org_openpsa_sales_salesproject_deliverable_dba::get_cached($deliverable_guid);
             $product = org_openpsa_products_product_dba::get_cached($deliverable->product);
             $salesproject = org_openpsa_sales_salesproject_dba::get_cached($deliverable->salesproject);
             $customer = midcom_db_group::get_cached($salesproject->customer);
         } catch (midcom_error $e) {
             continue;
         }
         if (!array_key_exists($salesproject->owner, $sums_per_person)) {
             $sums_per_person[$salesproject->owner] = array('price' => 0, 'cost' => 0, 'profit' => 0);
         }
         // Calculate the price and cost from invoices
         $invoice_price = 0;
         $data['invoice_string'] = '';
         $invoice_cycle_numbers = array();
         foreach ($invoices as $invoice) {
             $invoice_price += $invoice->sum;
             $invoice_class = $invoice->get_status();
             if ($invoices_node) {
                 $invoice_label = "<a class=\"{$invoice_class}\" href=\"{$invoices_node[MIDCOM_NAV_FULLURL]}invoice/{$invoice->guid}/\">" . $invoice->get_label() . "</a>";
             } else {
                 $invoice_label = $invoice->get_label();
             }
             if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
                 $invoice_cycle_numbers[] = (int) $invoice->parameter('org.openpsa.sales', 'cycle_number');
             }
             $data['invoice_string'] .= "<li class=\"{$invoice_class}\">{$invoice_label}</li>\n";
         }
         if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
             // This is a subscription, it should be shown only if it is the first invoice
             if (!in_array(1, $invoice_cycle_numbers)) {
                 continue;
                 // This will skip to next deliverable
             }
             $scheduler = new org_openpsa_invoices_scheduler($deliverable);
             if ($deliverable->end == 0) {
                 // Subscription doesn't have an end date, use specified amount of months for calculation
                 $cycles = $scheduler->calculate_cycles($this->_config->get('subscription_profit_months'));
                 $data['calculation_basis'] = sprintf($data['l10n']->get('%s cycles in %s months'), $cycles, $this->_config->get('subscription_profit_months'));
             } else {
                 $cycles = $scheduler->calculate_cycles();
                 $data['calculation_basis'] = sprintf($data['l10n']->get('%s cycles, %s - %s'), $cycles, strftime('%x', $deliverable->start), strftime('%x', $deliverable->end));
             }
             $price = $deliverable->price * $cycles;
             $cost = $deliverable->cost * $cycles;
         } else {
             // This is a single delivery, calculate cost as percentage as it may be invoiced in pieces
             if ($deliverable->price) {
                 $cost_percentage = 100 / $deliverable->price * $invoice_price;
                 $cost = $deliverable->cost / 100 * $cost_percentage;
             } else {
                 $cost_percentage = 100;
                 $cost = $deliverable->cost;
             }
             $price = $invoice_price;
             $data['calculation_basis'] = sprintf($data['l10n']->get('%s%% of %s'), round($cost_percentage), $deliverable->price);
         }
         // And now just count the profit
         $profit = $price - $cost;
         $data['customer'] = $customer;
         $data['salesproject'] = $salesproject;
         $data['deliverable'] = $deliverable;
         $data['price'] = $price;
         $sums_per_person[$salesproject->owner]['price'] += $price;
         $sums_all['price'] += $price;
         $data['cost'] = $cost;
         $sums_per_person[$salesproject->owner]['cost'] += $cost;
         $sums_all['cost'] += $cost;
         $data['profit'] = $profit;
         $sums_per_person[$salesproject->owner]['profit'] += $profit;
         $sums_all['profit'] += $profit;
         if ($odd) {
             $data['row_class'] = '';
             $odd = false;
         } else {
             $data['row_class'] = ' class="even"';
             $odd = true;
         }
         midcom_show_style('sales_report-deliverable-item');
     }
     $data['sums_per_person'] = $sums_per_person;
     $data['sums_all'] = $sums_all;
     midcom_show_style('sales_report-deliverable-footer');
     /*** /Copied from sales/handler/deliverable/report.php ***/
     midcom_show_style('sales_report-deliverable-end');
 }
Ejemplo n.º 2
0
 public function _on_deleted()
 {
     $this->_invalidate_person_cache();
     if (!midcom::get('auth')->request_sudo('midcom')) {
         return;
     }
     // Create an Activity Log entry for the membership addition
     try {
         $actor = midcom_db_person::get_cached($this->uid);
         $target = midcom_db_group::get_cached($this->gid);
     } catch (midcom_error $e) {
         $e->log();
         return;
     }
     $activity = new midcom_helper_activitystream_activity_dba();
     $activity->target = $target->guid;
     $activity->actor = $actor->id;
     $activity->verb = 'http://community-equity.org/schema/1.0/leave';
     if (midcom::get('auth')->is_valid_user() && $actor->guid == midcom::get('auth')->user->guid) {
         $activity->summary = sprintf(midcom::get('i18n')->get_string('%s left group %s', 'midcom'), $actor->name, $target->official);
     } else {
         $activity->summary = sprintf(midcom::get('i18n')->get_string('%s was removed from group %s', 'midcom'), $actor->name, $target->official);
     }
     $activity->create();
     midcom::get('auth')->drop_sudo();
 }
Ejemplo n.º 3
0
    $paid = ", " . midcom::get('i18n')->get_string('paid', 'org.openpsa.invoices') . ": " . strftime('%x', $invoice->paid);
} else {
    if ($invoice->due < time()) {
        $paid = ", " . midcom::get('i18n')->get_string('not paid', 'org.openpsa.invoices');
    }
}
?>

<li class="invoice" id="org_openpsa_relatedto_line_&(link['guid']);">
    <span class="icon">&(data['icon']:h);</span>
    <span class="title">&(data['title']:h);</span>
    <ul class="metadata">
    <?php 
// Customer
if ($invoice->customer) {
    $customer = midcom_db_group::get_cached($invoice->customer);
    echo "<li>" . midcom::get('i18n')->get_string('customer', 'org.openpsa.invoices') . ": {$customer->official}</li>";
}
echo "<li>" . midcom::get('i18n')->get_string('sum', 'org.openpsa.invoices') . ": " . org_openpsa_helpers::format_number($invoice->sum) . " (" . midcom::get('i18n')->get_string('due', 'org.openpsa.invoices') . ": " . strftime('%x', $invoice->due) . "{$paid})</li>";
?>
    </ul>

    <div id="org_openpsa_relatedto_details_&(invoice.guid);" class="details hidden" style="display: none;">
    </div>

  <?php 
//TODO: necessary JS stuff to load details (which should in turn include the invoice's own relatedtos) via AHAH
echo org_openpsa_relatedto_handler_relatedto::render_line_controls($link, $data['other_obj']);
?>
</li>
<?php

$link =& $data['link'];
$salesproject =& $data['other_obj'];
$owner_card = org_openpsa_widgets_contact::get($salesproject->owner);
$customer = midcom_db_group::get_cached($salesproject->customer);
?>

<li class="salesproject" id="org_openpsa_relatedto_line_&(link['guid']);">
  <span class="icon">&(data['icon']:h);</span>
  <span class="title">&(data['title']:h);</span>
  <ul class="metadata">
    <?php 
// Owner
echo "<li>" . midcom::get('i18n')->get_string('owner', 'midcom') . ": ";
echo $owner_card->show_inline() . "</li>";
// Customer
if ($customer) {
    echo "<li>" . midcom::get('i18n')->get_string('customer', 'org.openpsa.sales') . ": ";
    echo $customer->official;
    echo "</li>";
}
?>
  </ul>

  <div id="org_openpsa_relatedto_details_&(salesproject.guid);" class="details hidden" style="display: none;">
  </div>
  <?php 
//TODO: necessary JS stuff to load details (which should in turn include the invoice's own relatedtos) via AHAH
echo org_openpsa_relatedto_handler_relatedto::render_line_controls($link, $data['other_obj']);
?>