
###############
CustomerCompany
###############


****
NAME
****


Kernel::System::CustomerCompany - customer company lib


***********
DESCRIPTION
***********


All Customer functions. E.g. to add and update customer companies.


****************
PUBLIC INTERFACE
****************


new()
=====


Don't use the constructor directly, use the ObjectManager instead:


.. code-block:: perl

     my $CustomerCompanyObject = $Kernel::OM->Get('Kernel::System::CustomerCompany');



CustomerCompanyAdd()
====================


add a new customer company


.. code-block:: perl

     my $ID = $CustomerCompanyObject->CustomerCompanyAdd(
         CustomerID              => 'example.com',
         CustomerCompanyName     => 'New Customer Inc.',
         CustomerCompanyStreet   => '5201 Blue Lagoon Drive',
         CustomerCompanyZIP      => '33126',
         CustomerCompanyCity     => 'Miami',
         CustomerCompanyCountry  => 'USA',
         CustomerCompanyURL      => 'http://www.example.org',
         CustomerCompanyComment  => 'some comment',
         ValidID                 => 1,
         UserID                  => 123,
     );


NOTE: Actual fields accepted by this API call may differ based on
CustomerCompany mapping in your system configuration.


CustomerCompanyGet()
====================


get customer company attributes


.. code-block:: perl

     my %CustomerCompany = $CustomerCompanyObject->CustomerCompanyGet(
         CustomerID => 123,
     );


Returns:


.. code-block:: perl

     %CustomerCompany = (
         'CustomerCompanyName'    => 'Customer Inc.',
         'CustomerID'             => 'example.com',
         'CustomerCompanyStreet'  => '5201 Blue Lagoon Drive',
         'CustomerCompanyZIP'     => '33126',
         'CustomerCompanyCity'    => 'Miami',
         'CustomerCompanyCountry' => 'United States',
         'CustomerCompanyURL'     => 'http://example.com',
         'CustomerCompanyComment' => 'Some Comments',
         'ValidID'                => '1',
         'CreateTime'             => '2010-10-04 16:35:49',
         'ChangeTime'             => '2010-10-04 16:36:12',
     );


NOTE: Actual fields returned by this API call may differ based on
CustomerCompany mapping in your system configuration.


CustomerCompanyUpdate()
=======================


update customer company attributes


.. code-block:: perl

     $CustomerCompanyObject->CustomerCompanyUpdate(
         CustomerCompanyID       => 'oldexample.com', # required for CustomerCompanyID-update
         CustomerID              => 'example.com',
         CustomerCompanyName     => 'New Customer Inc.',
         CustomerCompanyStreet   => '5201 Blue Lagoon Drive',
         CustomerCompanyZIP      => '33126',
         CustomerCompanyLocation => 'Miami',
         CustomerCompanyCountry  => 'USA',
         CustomerCompanyURL      => 'http://example.com',
         CustomerCompanyComment  => 'some comment',
         ValidID                 => 1,
         UserID                  => 123,
     );



CustomerCompanySourceList()
===========================


return customer company source list


.. code-block:: perl

     my %List = $CustomerCompanyObject->CustomerCompanySourceList(
         ReadOnly => 0 # optional, 1 returns only RO backends, 0 returns writable, if not passed returns all backends
     );



CustomerCompanyList()
=====================


get list of customer companies.


.. code-block:: perl

     my %List = $CustomerCompanyObject->CustomerCompanyList();
 
     my %List = $CustomerCompanyObject->CustomerCompanyList(
         Valid => 0,
         Limit => 0,     # optional, override configured search result limit (0 means unlimited)
     );
 
     my %List = $CustomerCompanyObject->CustomerCompanyList(
         Search => 'somecompany',
     );


Returns:


.. code-block:: perl

     %List = {
         'example.com' => 'example.com Customer Inc.',
         'acme.com'    => 'acme.com Acme, Inc.',
     };



CustomerCompanySearchDetail()
=============================


To find customer companies in the system.

The search criteria are logically AND connected.
When a list is passed as criteria, the individual members are OR connected.
When an undef or a reference to an empty array is passed, then the search criteria
is ignored.

Returns either a list, as an arrayref, or a count of found customer company ids.
The count of results is returned when the parameter \ ``Result = 'COUNT'``\  is passed.


.. code-block:: perl

     my $CustomerCompanyIDsRef = $CustomerCompanyObject->CustomerCompanySearchDetail(
 
         # all search fields possible which are defined in CustomerCompany::EnhancedSearchFields
         CustomerID          => 'example*',                                  # (optional)
         CustomerCompanyName => 'Name*',                                     # (optional)
 
         # array parameters are used with logical OR operator (all values are possible which
         are defined in the config selection hash for the field)
         CustomerCompanyCountry => [ 'Austria', 'Germany', ],                # (optional)
 
         # DynamicFields
         #   At least one operator must be specified. Operators will be connected with AND,
         #       values in an operator with OR.
         #   You can also pass more than one argument to an operator: ['value1', 'value2']
         DynamicField_FieldNameX => {
             Equals            => 123,
             Like              => 'value*',                # "equals" operator with wildcard support
             GreaterThan       => '2001-01-01 01:01:01',
             GreaterThanEquals => '2001-01-01 01:01:01',
             SmallerThan       => '2002-02-02 02:02:02',
             SmallerThanEquals => '2002-02-02 02:02:02',
         }
 
         OrderBy => [ 'CustomerID', 'CustomerCompanyCountry' ],              # (optional)
         # ignored if the result type is 'COUNT'
         # default: [ 'CustomerID' ]
         # (all search fields possible which are defined in
         CustomerCompany::EnhancedSearchFields)
 
         # Additional information for OrderBy:
         # The OrderByDirection can be specified for each OrderBy attribute.
         # The pairing is made by the array indices.
 
         OrderByDirection => [ 'Down', 'Up' ],                               # (optional)
         # ignored if the result type is 'COUNT'
         # (Down | Up) Default: [ 'Down' ]
 
         Result => 'ARRAY' || 'COUNT',                                       # (optional)
         # default: ARRAY, returns an array of change ids
         # COUNT returns a scalar with the number of found changes
 
         Limit => 100,                                                       # (optional)
         # ignored if the result type is 'COUNT'
     );


Returns:

Result: 'ARRAY'


.. code-block:: perl

     @CustomerIDs = ( 1, 2, 3 );


Result: 'COUNT'


.. code-block:: perl

     $CustomerIDs = 10;



CustomerCompanySearchFields()
=============================


Get a list of defined search fields (optional only the relevant fields for the given source).


.. code-block:: perl

     my @SeachFields = $CustomerCompanyObject->CustomerCompanySearchFields(
         Source => 'CustomerCompany', # optional, but important in the CustomerCompanySearchDetail to get the right database fields
     );


Returns an array of hash references.


.. code-block:: perl

     @SeachFields = (
         {
             Name  => 'CustomerID',
             Label => 'CustomerID',
             Type  => 'Input',
         },
         {
             Name           => 'CustomerCompanyCountry',
             Label          => 'Country',
             Type           => 'Selection',
             SelectionsData => {
                 'Germany'        => 'Germany',
                 'United Kingdom' => 'United Kingdom',
                 'United States'  => 'United States',
                 # ...
             },
         },
         {
             Name          => 'DynamicField_Branch',
             Label         => '',
             Type          => 'DynamicField',
             DatabaseField => 'Branch',
         },
     );



GetFieldConfig()
================


This function collect some field config information from the customer user map.


.. code-block:: perl

     my %FieldConfig = $CustomerCompanyObject->GetFieldConfig(
         FieldName => 'CustomerCompanyName',
         Source    => 'CustomerCompany', # optional
     );


Returns some field config information:


.. code-block:: perl

     my %FieldConfig = (
         Label         => 'Name',
         DatabaseField => 'name',
         StorageType   => 'var',
     );



GetFieldSelections()
====================


This function collect the selections for the given field name, if the field has some selections.


.. code-block:: perl

     my %SelectionsData = $CustomerCompanyObject->GetFieldSelections(
         FieldName => 'CustomerCompanyCountry',
     );


Returns the selections for the given field name (merged from all sources) or a empty hash:


.. code-block:: perl

     my %SelectionData = (
         'Germany'        => 'Germany',
         'United Kingdom' => 'United Kingdom',
         'United States'  => 'United States',
     );





