Ejemplo n.º 1
0
 /**
  * function to save the imported contacts
  * @param object $import_object
  * @param object $do_crm_fields
  * @param array $data
  * @return integer inseted recordid
  */
 public function import_save($import_object, $crm_fields, $data)
 {
     $mapped_fields = $import_object->get_mapped_fields();
     $table_entity = 'contacts';
     $table_entity_address = 'contacts_address';
     $table_entity_custom = 'contacts_custom_fld';
     $entity_data_array = array();
     $custom_data_array = array();
     $addr_data_array = array();
     foreach ($crm_fields as $crm_fields) {
         $field_name = $crm_fields["field_name"];
         $mapped_field_key = array_search($field_name, $mapped_fields);
         if ($mapped_field_key !== false) {
             $field_value = $data[$mapped_field_key];
             $field_value = $import_object->format_data_before_save($crm_fields["field_type"], $field_value);
         } else {
             $field_value = '';
         }
         if ($field_name == 'assigned_to') {
             $field_name = 'iduser';
             $field_value = $_SESSION["do_user"]->iduser;
         }
         if ($crm_fields["table_name"] == $table_entity && $crm_fields["idblock"] > 0) {
             if ($field_name == 'reports_to') {
                 $field_value = $this->map_contact_report_to($field_value);
             } elseif ($field_name == 'idorganization') {
                 // get the idorganization by val else gets a new id by adding the record
                 $field_value = $this->map_contact_organization($field_value, $import_object, $data);
             }
             $entity_data_array[$field_name] = $field_value;
         }
         if ($crm_fields["table_name"] == $table_entity_address && $crm_fields["idblock"] > 0) {
             $addr_data_array[$field_name] = $field_value;
         }
         if ($crm_fields["table_name"] == $table_entity_custom && $crm_fields["idblock"] > 0) {
             $custom_data_array[$field_name] = $field_value;
         }
     }
     $this->insert($table_entity, $entity_data_array);
     $id_entity = $this->getInsertId();
     if ($id_entity > 0) {
         //adding the added_on
         $q_upd = "\n\t\t\tupdate `" . $this->getTable() . "` \n\t\t\tset `added_on` = ? \n\t\t\twhere `" . $this->primary_key . "` = ?";
         $this->query($q_upd, array(date("Y-m-d H:i:s"), $id_entity));
         $custom_data_array["idcontacts"] = $id_entity;
         $addr_data_array["idcontacts"] = $id_entity;
         $this->insert($table_entity_custom, $custom_data_array);
         $this->insert($table_entity_address, $addr_data_array);
         $do_data_history = new DataHistory();
         $do_data_history->add_history($id_entity, 4, 'add');
         $do_data_history->free();
         return $id_entity;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * function to save the imported potentials
  * @param object $import_object
  * @param object $do_crm_fields
  * @param array $data
  * @return integer inseted recordid
  */
 public function import_save($import_object, $crm_fields, $data)
 {
     $mapped_fields = $import_object->get_mapped_fields();
     //print_r($crm_fields);
     $table_entity = 'potentials';
     $table_entity_custom = 'potentials_custom_fld';
     $table_entity_to_grp = 'pot_to_grp_rel';
     $table_entity_related_to = 'potentials_related_to';
     $entity_data_array = array();
     $custom_data_array = array();
     $addr_data_array = array();
     $related_to_field = false;
     foreach ($crm_fields as $crm_fields) {
         $field_name = $crm_fields["field_name"];
         if ($field_name == 'related_to') {
             $mapped_field_key = array_search("pot_related_to_organization", $mapped_fields);
             if ($mapped_field_key === false) {
                 $mapped_field_key = array_search("pot_related_to_contact", $mapped_fields);
                 if ($mapped_field_key !== false) {
                     $field_value = $data[$mapped_field_key];
                     if ($field_value != '') {
                         $related_to_cnt_map = true;
                     }
                 }
             } else {
                 $field_value = $data[$mapped_field_key];
                 if ($field_value !== '') {
                     $related_to_org_map = true;
                 } else {
                     $mapped_field_key = array_search("pot_related_to_contact", $mapped_fields);
                     if ($mapped_field_key !== false) {
                         $field_value = $data[$mapped_field_key];
                         if ($field_value != '') {
                             $related_to_cnt_map = true;
                         }
                     }
                 }
             }
             if ($related_to_cnt_map === false && $related_to_org_map === false) {
                 return false;
             }
         } else {
             $mapped_field_key = array_search($field_name, $mapped_fields);
             if ($mapped_field_key !== false) {
                 $field_value = $data[$mapped_field_key];
                 $field_value = $import_object->format_data_before_save($crm_fields["field_type"], $field_value);
             } else {
                 $field_value = '';
             }
         }
         if ($field_name == 'assigned_to') {
             $field_name = 'iduser';
             $field_value = $_SESSION["do_user"]->iduser;
         }
         if ($crm_fields["table_name"] == $table_entity_related_to && $crm_fields["idblock"] > 0) {
             if ($field_name == 'related_to') {
                 if ($related_to_org_map === true) {
                     $related_to = $this->map_related_to_organization($field_value);
                     $idmodule_rel_to = 6;
                     $related_to_field = true;
                 } elseif ($related_to_cnt_map === true) {
                     $related_to = $this->map_related_to_contacts($field_value);
                     $idmodule_rel_to = 4;
                     $related_to_field = true;
                 }
             }
         }
         if ($crm_fields["table_name"] == $table_entity && $crm_fields["idblock"] > 0) {
             $entity_data_array[$field_name] = $field_value;
         }
         if ($crm_fields["table_name"] == $table_entity_custom && $crm_fields["idblock"] > 0) {
             $custom_data_array[$field_name] = $field_value;
         }
     }
     $this->insert($table_entity, $entity_data_array);
     $id_entity = $this->getInsertId();
     if ($id_entity > 0) {
         //adding the added_on
         $q_upd = "\n\t\t\tupdate `" . $this->getTable() . "` \n\t\t\tset `added_on` = ? \n\t\t\twhere `" . $this->primary_key . "` = ?";
         $this->query($q_upd, array(date("Y-m-d H:i:s"), $id_entity));
         $custom_data_array["idpotentials"] = $id_entity;
         $this->insert($table_entity_custom, $custom_data_array);
         if ($related_to_field === true && (int) $related_to_field > 0) {
             $this->insert($table_entity_related_to, array("idpotentials" => $id_entity, "related_to" => $related_to, "idmodule" => $idmodule_rel_to));
         }
         $do_data_history = new DataHistory();
         $do_data_history->add_history($id_entity, 5, 'add');
         $do_data_history->free();
         return $id_entity;
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * function to save the imported vendor
  * @param object $import_object
  * @param object $do_crm_fields
  * @param array $data
  * @return integer inseted recordid
  */
 public function import_save($import_object, $crm_fields, $data)
 {
     $mapped_fields = $import_object->get_mapped_fields();
     $table_entity = 'products';
     $table_entity_custom = 'products_custom_fld';
     $table_entity_to_grp = 'products_to_grp_rel';
     $table_products_pricing = 'products_pricing';
     $table_products_stock = 'products_stock';
     $table_product_tax = 'products_tax';
     $entity_data_array = array();
     $custom_data_array = array();
     $product_stock_data_array = array();
     $product_pricing_data_array = array();
     $product_tax_data_array = array();
     $tax_settings = new TaxSettings();
     $product_service_tax = $tax_settings->product_service_tax();
     foreach ($crm_fields as $crm_fields) {
         $field_name = $crm_fields["field_name"];
         if ($crm_fields["field_type"] == 165) {
             foreach ($product_service_tax as $key => $val) {
                 $mapped_field_key = array_search($val["tax_name"], $mapped_fields);
                 if ($mapped_field_key !== false) {
                     $product_tax_data_array[$val["tax_name"]] = $data[$mapped_field_key];
                 }
             }
         } else {
             $mapped_field_key = array_search($field_name, $mapped_fields);
             if ($mapped_field_key !== false) {
                 $field_value = $data[$mapped_field_key];
                 $field_value = $import_object->format_data_before_save($crm_fields["field_type"], $field_value);
             } else {
                 $field_value = '';
             }
             if ($field_name == 'assigned_to') {
                 $field_name = 'iduser';
                 $field_value = $_SESSION["do_user"]->iduser;
             }
             if ($crm_fields["table_name"] == $table_entity && $crm_fields["idblock"] > 0) {
                 if ($field_name == 'idvendor') {
                     $field_value = $this->map_products_vendor($field_value);
                 }
                 $entity_data_array[$field_name] = $field_value;
             } elseif ($crm_fields["table_name"] == $table_entity_custom && $crm_fields["idblock"] > 0) {
                 $custom_data_array[$field_name] = $field_value;
             } elseif ($crm_fields["table_name"] == $table_products_stock && $crm_fields["idblock"] > 0) {
                 $product_stock_data_array[$field_name] = $field_value;
             } elseif ($crm_fields["table_name"] == $table_products_pricing && $crm_fields["idblock"] > 0) {
                 $product_pricing_data_array[$field_name] = $field_value;
             }
         }
     }
     //print_r($product_tax_data_array);exit;
     $this->insert($table_entity, $entity_data_array);
     $id_entity = $this->getInsertId();
     if ($id_entity > 0) {
         //adding the added_on
         $q_upd = "\n\t\t\tupdate `" . $this->getTable() . "` \n\t\t\tset `added_on` = ? \n\t\t\twhere `" . $this->primary_key . "` = ?";
         $this->query($q_upd, array(date("Y-m-d H:i:s"), $id_entity));
         $custom_data_array["idproducts"] = $id_entity;
         $product_stock_data_array["idproducts"] = $id_entity;
         $product_pricing_data_array["idproducts"] = $id_entity;
         $this->insert($table_entity_custom, $custom_data_array);
         $this->insert($table_products_stock, $product_stock_data_array);
         $this->insert($table_products_pricing, $product_pricing_data_array);
         if (is_array($product_tax_data_array) && count($product_tax_data_array) > 0) {
             foreach ($product_tax_data_array as $tax_name => $tax_value) {
                 $q_ins = "\n\t\t\t\t\tinsert into `{$table_product_tax}` (`idproducts`,`tax_name`,`tax_value`) \n\t\t\t\t\tvalues\n\t\t\t\t\t(?,?,?)\n\t\t\t\t\t";
                 $this->query($q_ins, array($id_entity, $tax_name, $tax_value));
             }
         }
         $do_data_history = new DataHistory();
         $do_data_history->add_history($id_entity, 12, 'add');
         $do_data_history->free();
         return $id_entity;
     } else {
         return false;
     }
 }