Exemple #1
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_product = new org_openpsa_products_product_dba();
     $this->_request_data['up'] = $controller->formmanager->get_value('productGroup');
     $this->_product->productGroup = $this->_request_data['up'];
     if (!$this->_product->create()) {
         debug_print_r('We operated on this object:', $this->_product);
         throw new midcom_error("Failed to create a new product under product group #{$this->_request_data['up']}. Error: " . midcom_connection::get_error_string());
     }
     return $this->_product;
 }
Exemple #2
0
 public function testHandler_process_subscription()
 {
     midcom::get('auth')->request_sudo('org.openpsa.sales');
     $product = org_openpsa_products_product_dba::get_cached(self::$_product->id);
     $product->delivery = org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION;
     $product->update();
     $deliverable_attributes = array('salesproject' => self::$_salesproject->id, 'product' => self::$_product->id, 'start' => time(), 'continuous' => true, 'unit' => 'q', 'orgOpenpsaObtype' => org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION);
     $deliverable = $this->create_object('org_openpsa_sales_salesproject_deliverable_dba', $deliverable_attributes);
     $deliverable->update();
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST = array('order' => true);
     $url = $this->run_relocate_handler('org.openpsa.sales', array('deliverable', 'process', $deliverable->guid));
     $this->assertEquals($url, 'salesproject/' . self::$_salesproject->guid . '/');
     $deliverable->refresh();
     $this->assertEquals(org_openpsa_sales_salesproject_deliverable_dba::STATUS_ORDERED, $deliverable->state);
     $mc = new org_openpsa_relatedto_collector($deliverable->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_order('start', 'DESC');
     $at_entries = $mc->get_related_objects();
     $this->assertEquals(1, sizeof($at_entries));
     $this->register_object($at_entries[0]);
     $_POST = array('run_cycle' => true, 'at_entry' => $at_entries[0]->guid);
     $url = $this->run_relocate_handler('org.openpsa.sales', array('deliverable', 'process', $deliverable->guid));
     $this->assertEquals($url, 'salesproject/' . self::$_salesproject->guid . '/');
     $deliverable->refresh();
     $mc = new org_openpsa_relatedto_collector($deliverable->guid, 'midcom_services_at_entry_dba');
     $mc->add_object_order('start', 'DESC');
     $at_entries = $mc->get_related_objects();
     $this->assertEquals(1, sizeof($at_entries));
     $this->register_object($at_entries[0]);
     midcom::get('auth')->drop_sudo();
 }
Exemple #3
0
 /**
  * DM2 creation callback, binds to the current content topic.
  */
 public function &dm2_create_callback(&$controller)
 {
     $this->_productlink = new org_openpsa_products_product_link_dba();
     if (isset($_POST['productGroup'])) {
         $this->_request_data['up'] = (int) $_POST['productGroup'];
     }
     $this->_productlink->productGroup = $this->_request_data['up'];
     if (isset($_POST['product'])) {
         $this->_request_data['product'] = (int) $_POST['product'];
     }
     $this->_productlink->product = $this->_request_data['product'];
     if (!$this->_productlink->create()) {
         debug_print_r('We operated on this object:', $this->_productlink);
         throw new midcom_error("Failed to create a new productlink under product group #{$this->_request_data['up']}. Error: " . midcom_connection::get_error_string());
     }
     return $this->_productlink;
 }
Exemple #4
0
 public function testCRUD()
 {
     $code = 'PRODUCT-TEST-' . __CLASS__ . time();
     $product = new org_openpsa_products_product_dba();
     $product->code = $code;
     $product->productGroup = self::$_group->id;
     midcom::get('auth')->request_sudo('org.openpsa.products');
     $stat = $product->create();
     $this->assertTrue($stat);
     $this->register_object($product);
     $parent = $product->get_parent();
     $this->assertEquals($parent->guid, self::$_group->guid);
     $product->title = 'TEST TITLE';
     $stat = $product->update();
     $this->assertTrue($stat);
     $this->assertEquals($product->title, 'TEST TITLE');
     $stat = $product->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
Exemple #5
0
 public function testHandler_create()
 {
     midcom::get('auth')->request_sudo('org.openpsa.products');
     $data = $this->run_handler('org.openpsa.products', array('product', 'create', 'default'));
     $this->assertEquals('create_product', $data['handler_id']);
     $formdata = array('title' => 'TEST ' . __CLASS__ . ' ' . time(), 'code' => 'TEST_' . __CLASS__ . '_' . time(), 'delivery' => (string) org_openpsa_products_product_dba::DELIVERY_SINGLE, 'orgOpenpsaObtype' => (string) org_openpsa_products_product_dba::TYPE_GOODS, 'org_openpsa_products_productGroup_chooser_selections' => array((string) self::$_group->id));
     $url = $this->submit_dm2_form('controller', $formdata, 'org.openpsa.products', array('product', 'create', 'default'));
     $qb = org_openpsa_products_product_dba::new_query_builder();
     $qb->add_constraint('productGroup', '=', self::$_group->id);
     $results = $qb->execute();
     $this->register_objects($results);
     $this->assertEquals(1, sizeof($results));
     $this->assertEquals('product/' . $results[0]->guid . '/', $url);
     midcom::get('auth')->drop_sudo();
 }
Exemple #6
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_product_delete($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user('basic');
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         throw new midcom_error('Failed to delete product: POST request expected.');
     }
     $this->_product = new org_openpsa_products_product_dba($args[0]);
     if (!$this->_product->delete()) {
         throw new midcom_error('Failed to delete product: ' . midcom_connection::get_error_string());
     }
     // Update the index
     $indexer = midcom::get('indexer');
     $indexer->delete($this->_product->guid);
     $this->_send_reply('Product deleted');
 }
Exemple #7
0
 private function _load_objects_group($group_id)
 {
     $objects = array();
     $product_qb = org_openpsa_products_product_dba::new_query_builder();
     $product_qb->add_constraint('productGroup', '=', $group_id);
     $products = $product_qb->execute();
     foreach ($products as $product) {
         $objects[] = $product;
     }
     $group_qb = org_openpsa_products_product_group_dba::new_query_builder();
     $group_qb->add_constraint('up', '=', $group_id);
     $groups = $group_qb->execute();
     foreach ($groups as $group) {
         $objects[] = $group;
         $child_objects = $this->_load_objects_group($group->id);
         $objects = array_merge($objects, $child_objects);
     }
     return $objects;
 }
Exemple #8
0
 function _load_data($handler_id, &$args, &$data)
 {
     if (empty($_POST) && $data['session']->exists('POST_data')) {
         $_POST = $data['session']->get('POST_data');
         $data['session']->remove('POST_data');
     }
     $qb = org_openpsa_products_product_dba::new_query_builder();
     $qb->add_order('code');
     $qb->add_order('title');
     $products = array();
     $root_group_guid = $this->_config->get('root_group');
     if ($root_group_guid) {
         $root_group = new org_openpsa_products_product_group_dba($root_group_guid);
         if (!isset($_POST['org_openpsa_products_export_all']) || empty($_POST['org_openpsa_products_export_all'])) {
             $qb->add_constraint('productGroup', '=', $root_group->id);
             // We have data only from one product group, though this seems to be too late...
             $this->_schema_fields_to_skip[] = 'productGroup';
         } else {
             $qb_groups = org_openpsa_products_product_group_dba::new_query_builder();
             $qb_groups->add_constraint('up', 'INTREE', $root_group->id);
             $groups = $qb_groups->execute();
             $qb->begin_group('OR');
             $qb->add_constraint('productGroup', '=', $root_group->id);
             foreach ($groups as $group) {
                 $qb->add_constraint('productGroup', '=', $group->id);
             }
             $qb->end_group('OR');
         }
     }
     $all_products = $qb->execute();
     foreach ($all_products as $product) {
         $schema = $product->get_parameter('midcom.helper.datamanager2', 'schema_name');
         if ($schema != $this->_schema) {
             continue;
         }
         $products[] = $product;
     }
     return $products;
 }
Exemple #9
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');
 }
Exemple #10
0
<?php

$view =& $data['view_deliverable'];
$status = $data['deliverable']->get_status();
$costType = $view['costType'];
$per_unit = $data['l10n']->get('per unit');
try {
    $product = org_openpsa_products_product_dba::get_cached($data['deliverable']->product);
    $unit_options = midcom_baseclasses_components_configuration::get('org.openpsa.products', 'config')->get('unit_options');
    if (array_key_exists($product->unit, $unit_options)) {
        $unit = midcom::get('i18n')->get_string($unit_options[$product->unit], 'org.openpsa.products');
        $per_unit = sprintf($data['l10n']->get('per %s'), $unit);
    }
} catch (midcom_error $e) {
    $product = false;
    $unit = $data['l10n']->get('unit');
}
?>
<div class="org_openpsa_sales_salesproject_deliverable &(status);">
    <div class="sidebar">
        <div class="contacts area">
            <?php 
echo "<h2>" . $data['l10n']->get('customer') . "</h2>\n";
$customer = $data['salesproject']->get_customer();
echo "<dl>\n<dt>\n" . $customer->render_link() . "</dl>\n</dt>\n";
$contacts = $data['salesproject']->contacts;
foreach ($contacts as $contact_id => $active) {
    $person_card = org_openpsa_widgets_contact::get($contact_id);
    $person_card->show();
}
?>
Exemple #11
0
 /**
  * Looks up a product to display.
  *
  * @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_view($handler_id, array $args, array &$data)
 {
     if (preg_match('/_raw$/', $handler_id)) {
         midcom::get()->skip_page_style = true;
     }
     $qb = org_openpsa_products_product_dba::new_query_builder();
     if (preg_match('/^view_product_intree/', $handler_id)) {
         $group_qb = org_openpsa_products_product_group_dba::new_query_builder();
         if (mgd_is_guid($args[0])) {
             $group_qb->add_constraint('guid', '=', $args[0]);
         } else {
             $group_qb->add_constraint('code', '=', $args[0]);
         }
         $groups = $group_qb->execute();
         if (empty($groups)) {
             throw new midcom_error_notfound("Product group {$args[0]} not found");
         }
         $categories_mc = org_openpsa_products_product_group_dba::new_collector('up', $groups[0]->id);
         $categories_in = $categories_mc->get_values('id');
         if (count($categories_in) == 0) {
             /* No matching categories belonging to this group
              * So we can search for the application using only
              * this group id
              */
             $qb->add_constraint('productGroup', 'INTREE', $groups[0]->id);
         } else {
             $categories_in[] = $groups[0]->id;
             $qb->add_constraint('productGroup', 'IN', $categories_in);
         }
         if (mgd_is_guid($args[1])) {
             $qb->add_constraint('guid', '=', $args[1]);
         } else {
             $qb->add_constraint('code', '=', $args[1]);
         }
     } else {
         if (mgd_is_guid($args[0])) {
             $qb->add_constraint('guid', '=', $args[0]);
         } else {
             $qb->add_constraint('code', '=', $args[0]);
         }
     }
     if ($this->_config->get('enable_scheduling')) {
         $qb->add_constraint('start', '<=', time());
         $qb->begin_group('OR');
         /*
          * List products that either have no defined end-of-market dates
          * or are still in market
          */
         $qb->add_constraint('end', '=', 0);
         $qb->add_constraint('end', '>=', time());
         $qb->end_group();
     }
     $results = $qb->execute();
     $this->_request_data['is_linked_from'] = '';
     if (!empty($results)) {
         $this->_product = $results[0];
         if ($this->_config->get('enable_productlinks') && $this->_product->productGroup != 0) {
             $root_group_guid = $this->_config->get('root_group');
             if ($root_group_guid != '') {
                 $root_group = org_openpsa_products_product_group_dba::get_cached($root_group_guid);
             }
             if ($root_group->id != $this->_product->productGroup) {
                 $product_group = new org_openpsa_products_product_group_dba($this->_product->productGroup);
                 $mc_intree = org_openpsa_products_product_group_dba::new_collector('id', $product_group->id);
                 $mc_intree->add_constraint('up', 'INTREE', $root_group->id);
                 $count = $mc_intree->count();
                 if ($count == 0) {
                     $mc_intree = org_openpsa_products_product_link_dba::new_collector('product', $this->_product->id);
                     $mc_intree->add_constraint('productGroup', 'INTREE', $root_group->id);
                     $mc_intree->execute();
                     $results = $mc_intree->list_keys();
                     if (count($results) > 0) {
                         foreach ($results as $guid => $array) {
                             $this->_request_data['is_linked_from'] = $guid;
                         }
                     }
                 }
             }
         }
     } else {
         if (preg_match('/^view_product_intree/', $handler_id)) {
             $this->_product = new org_openpsa_products_product_dba($args[1]);
         } else {
             $this->_product = new org_openpsa_products_product_dba($args[0]);
         }
     }
     if ($GLOBALS['midcom_config']['enable_ajax_editing']) {
         $data['controller'] = midcom_helper_datamanager2_controller::create('ajax');
         $data['controller']->schemadb =& $data['schemadb_product'];
         $data['controller']->set_storage($this->_product);
         $data['controller']->process_ajax();
         $data['datamanager'] =& $data['controller']->datamanager;
     } else {
         $data['controller'] = null;
         $data['datamanager'] = new midcom_helper_datamanager2_datamanager($data['schemadb_product']);
         if (!$data['datamanager']->autoset_storage($this->_product)) {
             throw new midcom_error("Failed to create a DM2 instance for product {$this->_product->guid}.");
         }
     }
     $this->_prepare_request_data();
     $this->bind_view_to_object($this->_product, $data['datamanager']->schema->name);
     if (isset($product_group)) {
         unset($product_group);
     }
     $product_group = null;
     if ($this->_request_data['is_linked_from'] != '') {
         $linked_product = new org_openpsa_products_product_link_dba($data['is_linked_from']);
         if ($linked_product->productGroup != 0) {
             $product_group = new org_openpsa_products_product_group_dba($linked_product->productGroup);
         }
     }
     $breadcrumb = org_openpsa_products_viewer::update_breadcrumb_line($this->_product, $product_group);
     midcom_core_context::get()->set_custom_key('midcom.helper.nav.breadcrumb', $breadcrumb);
     midcom::get('metadata')->set_request_metadata($this->_product->metadata->revised, $this->_product->guid);
     $title = $this->_config->get('product_page_title');
     if (strstr($title, '<PRODUCTGROUP')) {
         try {
             $productgroup = new org_openpsa_products_product_group_dba($this->_product->productGroup);
             $title = str_replace('<PRODUCTGROUP_TITLE>', $productgroup->title, $title);
             $title = str_replace('<PRODUCTGROUP_CODE>', $productgroup->code, $title);
         } catch (midcom_error $e) {
             $title = str_replace('<PRODUCTGROUP_TITLE>', '', $title);
             $title = str_replace('<PRODUCTGROUP_CODE>', '', $title);
         }
     }
     $title = str_replace('<PRODUCT_CODE>', $this->_product->code, $title);
     $title = str_replace('<PRODUCT_TITLE>', $this->_product->title, $title);
     $title = str_replace('<TOPIC_TITLE>', $this->_topic->extra, $title);
     midcom::get('head')->set_pagetitle($title);
 }
Exemple #12
0
 private function _import_product($productdata)
 {
     $data =& $this->_request_data;
     // Convert fields from latin-1 to MidCOM charset (usually utf-8)
     foreach ($productdata as $key => $value) {
         // FIXME: It would be immensely more efficient to do this per-file or even per row rather than per field
         $productdata[$key] = $this->_charset_convert($value);
     }
     $product = null;
     $new = false;
     // GUID has precedence
     if (isset($productdata['GUID']) && !empty($productdata['GUID'])) {
         $product = new org_openpsa_products_product_dba($productdata['GUID']);
         if ($product->guid != $productdata['GUID']) {
             // Could not fetch correct product
             unset($product);
         }
     } else {
         if (isset($productdata['code'])) {
             // FIXME: the product group should be taken into account here, codes are quaranteed to be unique only within the group
             $qb = org_openpsa_products_product_dba::new_query_builder();
             $qb->add_constraint('code', '=', (string) $productdata['code']);
             $products = $qb->execute();
             if (count($products) > 0) {
                 // Match found, use it
                 $product = $products[0];
             }
         }
     }
     if (!$product) {
         // We didn't have group matching the code in DB. Create a new one.
         $product = new org_openpsa_products_product_dba();
         $product->productGroup = $data['new_products_product_group'];
         if (!$product->create()) {
             debug_add("Failed to create product, reason " . midcom_connection::get_error_string());
             $this->_request_data['import_status']['failed_create']++;
             return false;
             // This will skip to next
         }
         $product->set_parameter('midcom.helper.datamanager2', 'schema_name', $data['schema']);
         $new = true;
     }
     // Map products without group to the "new products" group
     if (empty($product->productGroup) && !empty($data['new_products_product_group'])) {
         $product->productGroup = $data['new_products_product_group'];
     }
     if (!$this->_datamanager_process($productdata, $product)) {
         if ($new) {
             $product->delete();
             $this->_request_data['import_status']['failed_create']++;
         } else {
             $this->_request_data['import_status']['failed_update']++;
         }
         return false;
     }
     $this->_products_processed[$product->code] = $product;
     if ($new) {
         $this->_request_data['import_status']['created']++;
     } else {
         $this->_request_data['import_status']['updated']++;
     }
     return $product;
 }
Exemple #13
0
 /**
  * @todo Check if we already have an open task for this delivery?
  */
 function create_task($start, $end, $title, $source_task = null)
 {
     $salesproject = org_openpsa_sales_salesproject_dba::get_cached($this->_deliverable->salesproject);
     $product = org_openpsa_products_product_dba::get_cached($this->_deliverable->product);
     // Check if we already have a project for the sales project
     $project = $salesproject->get_project();
     // Create the task
     $task = new org_openpsa_projects_task_dba();
     $task->agreement = $this->_deliverable->id;
     $task->customer = $salesproject->customer;
     $task->title = $title;
     $task->description = $this->_deliverable->description;
     $task->start = $start;
     $task->end = $end;
     $task->plannedHours = $this->_deliverable->plannedUnits;
     $task->manager = $salesproject->owner;
     if ($project) {
         $task->project = $project->id;
         $task->orgOpenpsaAccesstype = $project->orgOpenpsaAccesstype;
         $task->orgOpenpsaOwnerWg = $project->orgOpenpsaOwnerWg;
     }
     if (!empty($source_task)) {
         $task->priority = $source_task->priority;
         $task->manager = $source_task->manager;
     }
     // TODO: Figure out if we really want to keep this
     $task->hoursInvoiceableDefault = true;
     if ($task->create()) {
         $task->add_members('contacts', array_keys($salesproject->contacts));
         if (!empty($source_task)) {
             $source_task->get_members();
             $task->add_members('resources', array_keys($source_task->resources));
         }
         org_openpsa_relatedto_plugin::create($task, 'org.openpsa.projects', $product, 'org.openpsa.products');
         // Copy tags from deliverable so we can seek resources
         $tagger = new net_nemein_tag_handler();
         $tagger->copy_tags($this->_deliverable, $task);
         midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.sales', 'org.openpsa.sales'), sprintf(midcom::get('i18n')->get_string('created task "%s"', 'org.openpsa.sales'), $task->title), 'ok');
         return $task;
     } else {
         throw new midcom_error("The task for this cycle could not be created. Last Midgard error was: " . midcom_connection::get_error_string());
     }
 }
Exemple #14
0
 function deliver($update_deliveries = true)
 {
     if ($this->state > org_openpsa_sales_salesproject_deliverable_dba::STATUS_DELIVERED) {
         return false;
     }
     $product = org_openpsa_products_product_dba::get_cached($this->product);
     if ($product->delivery == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
         // Subscriptions are ongoing, not one delivery
         return false;
     }
     // Check if we need to create task or ship goods
     if ($update_deliveries) {
         switch ($product->orgOpenpsaObtype) {
             case org_openpsa_products_product_dba::TYPE_SERVICE:
                 // Change status of tasks connected to the deliverable
                 $task_qb = org_openpsa_projects_task_dba::new_query_builder();
                 $task_qb->add_constraint('agreement', '=', $this->id);
                 $task_qb->add_constraint('status', '<', org_openpsa_projects_task_status_dba::CLOSED);
                 $tasks = $task_qb->execute();
                 foreach ($tasks as $task) {
                     org_openpsa_projects_workflow::close($task, sprintf(midcom::get('i18n')->get_string('completed from deliverable %s', 'org.openpsa.sales'), $this->title));
                 }
                 break;
             case org_openpsa_products_product_dba::TYPE_GOODS:
                 // TODO: Warehouse management: mark product as shipped
             // TODO: Warehouse management: mark product as shipped
             default:
                 break;
         }
     }
     $this->state = org_openpsa_sales_salesproject_deliverable_dba::STATUS_DELIVERED;
     $this->end = time();
     if ($this->update()) {
         // Update sales project and mark as delivered (if no other deliverables are active)
         $salesproject = new org_openpsa_sales_salesproject_dba($this->salesproject);
         $salesproject->mark_delivered();
         midcom::get('uimessages')->add(midcom::get('i18n')->get_string('org.openpsa.sales', 'org.openpsa.sales'), sprintf(midcom::get('i18n')->get_string('marked deliverable "%s" delivered', 'org.openpsa.sales'), $this->title), 'ok');
         return true;
     }
     return false;
 }
Exemple #15
0
 public function _on_reindex_tree_iterator(&$indexer, &$dms, &$topic, &$group, &$topic, &$config)
 {
     if ($dms['group']->autoset_storage($group)) {
         if ($config->get('index_groups')) {
             org_openpsa_products_viewer::index($dms['group'], $indexer, $topic, $config);
         }
     } else {
         debug_add("Warning, failed to initialize datamanager for product group {$group->id}. Skipping it.", MIDCOM_LOG_WARN);
     }
     if ($config->get('index_products')) {
         $qb_products = org_openpsa_products_product_dba::new_query_builder();
         $qb_products->add_constraint('productGroup', '=', $group->id);
         $products = $qb_products->execute();
         unset($qb_products);
         if (is_array($products)) {
             foreach ($products as $product) {
                 if (!$dms['product']->autoset_storage($product)) {
                     debug_add("Warning, failed to initialize datamanager for product {$product->id}. Skipping it.", MIDCOM_LOG_WARN);
                     continue;
                 }
                 org_openpsa_products_viewer::index($dms['product'], $indexer, $topic, $config);
                 unset($product);
             }
         }
         unset($products);
     }
     $subgroups = array();
     $qb_groups = org_openpsa_products_product_group_dba::new_query_builder();
     $qb_groups->add_constraint('up', '=', $group->id);
     $subgroups = $qb_groups->execute();
     unset($qb_groups);
     if (!is_array($subgroups)) {
         return true;
     }
     foreach ($subgroups as $subgroup) {
         $this->_on_reindex_tree_iterator($indexer, $dms, $topic, $subgroup, $topic, $config);
         unset($subgroup);
     }
     unset($subgroups);
     return true;
 }
Exemple #16
0
 public static function list_products()
 {
     $component_list = array();
     $qb = org_openpsa_products_product_dba::new_query_builder();
     $qb->add_order('productGroup');
     $qb->add_order('code');
     $qb->add_order('title');
     $qb->add_constraint('start', '<=', time());
     $qb->begin_group('OR');
     /*
      * List products that either have no defined end-of-market dates
      * or are still in market
      */
     $qb->add_constraint('end', '=', 0);
     $qb->add_constraint('end', '>=', time());
     $qb->end_group();
     $components = $qb->execute();
     foreach ($components as $component) {
         $component_list[$component->id] = "{$component->code} {$component->title}";
     }
     return $component_list;
 }
Exemple #17
0
    <p>You can import product images that have the product code in their filename/URL here.
    Type the address format below with string <code>__PRODUCT_CODE__</code> showing where the code should go to.</p>

    <form method="post">
        <label>
            URL/path
            <input type="text" name="address" value="/tmp/__PRODUCT_CODE__.jpg" />
        </label>
        <input type="submit" value="Import images" />
    </form>
    <?php 
} else {
    midcom::get()->disable_limits();
    // Import product images
    $qb = org_openpsa_products_product_dba::new_query_builder();
    $qb->add_constraint('code', '<>', '');
    $products = $qb->execute();
    $schemadb = midcom_baseclasses_components_configuration::get('org.openpsa.products', 'config')->get('schemadb_product');
    $schema = midcom_helper_datamanager2_schema::load_database($schema);
    $datamanager = new midcom_helper_datamanager2_datamanager($schema);
    foreach ($products as $product) {
        // Get old image
        $image = file_get_contents(str_replace('__PRODUCT_CODE__', $product->code, $_POST['address']));
        if (empty($image)) {
            continue;
        }
        // Save image to a temp file
        $tmp_name = tempnam($GLOBALS['midcom_config']['midcom_tempdir'], 'org_openpsa_products_product_oldimage_');
        $fp = fopen($tmp_name, 'w');
        if (!fwrite($fp, $image)) {
Exemple #18
0
 /**
  * Shows the loaded salesproject.
  *
  * @param mixed $handler_id The ID of the handler.
  * @param array &$data The local request data.
  */
 public function _show_view($handler_id, array &$data)
 {
     // For AJAX handling it is the controller that renders everything
     $data['view_salesproject'] = $data['controller']->get_content_html();
     midcom_show_style('show-salesproject');
     if (count($data['products']) > 0) {
         asort($data['products']);
         // We have products defined in the system, add deliverable support
         midcom_show_style('show-salesproject-deliverables-header');
         if (array_key_exists('deliverables_objects', $data)) {
             foreach ($data['deliverables_objects'] as $deliverable) {
                 $data['deliverable'] = $this->_controllers[$deliverable->id]->get_content_html();
                 $data['deliverable_object'] =& $deliverable;
                 $data['deliverable_toolbar'] = $this->_build_deliverable_toolbar($deliverable);
                 try {
                     $data['product'] = org_openpsa_products_product_dba::get_cached($deliverable->product);
                 } catch (midcom_error $e) {
                     $data['product'] = false;
                 }
                 if ($deliverable->orgOpenpsaObtype == org_openpsa_products_product_dba::DELIVERY_SUBSCRIPTION) {
                     midcom_show_style('show-salesproject-deliverables-subscription');
                 } else {
                     midcom_show_style('show-salesproject-deliverables-item');
                 }
             }
         }
         midcom_show_style('show-salesproject-deliverables-footer');
     }
     midcom_show_style('show-salesproject-related');
 }