/**
  * function to save the imported organization
  * @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 = 'organization';
     $table_entity_address = 'organization_address';
     $table_entity_custom = 'organization_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 ($field_name == 'member_of') {
             $field_value = $this->map_member_of($field_value);
         }
         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_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["idorganization"] = $id_entity;
         $addr_data_array["idorganization"] = $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, 6, 'add');
         $do_data_history->free();
         return $id_entity;
     } else {
         return false;
     }
 }
 /**
  * function to map related to (contacts) for potentials while importing
  * checks if the contact exists else adds a new contact
  * @param string $contact_name
  * @return integer idcontacts
  */
 public function map_related_to_contacts($contact_name)
 {
     if (strlen($contact_name) > 2) {
         $contact_name = trim($contact_name);
         $do_contact = new Contacts();
         $qry = "\n\t\t\tselect `idcontacts`\n\t\t\tfrom  `contacts`\n\t\t\twhere `deleted` = 0 \n\t\t\tAND iduser = "******"do_user"]->iduser . "\n\t\t\tAND \n\t\t\t(\n\t\t\t\tconcat(firstname,' ',lastname) = ?\n\t\t\t\tor\n\t\t\t\tconcat(lastname,' ',firstname) = ?\n\t\t\t)\n\t\t\t";
         $do_contact->query($qry, array($contact_name, $contact_name));
         if ($do_contact->getNumRows() > 0) {
             $do_contact->next();
             return $do_contact->idcontacts;
         } else {
             $contact_name_explode = explode(" ", $contact_name);
             $do_contact->insert("contacts", array("firstname" => CommonUtils::purify_input($contact_name_explode[0]), "lastname" => CommonUtils::purify_input($contact_name_explode[1]), "iduser" => $_SESSION["do_user"]->iduser));
             $idcontacts = $do_contact->getInsertId();
             //adding the added_on
             $q_upd = "\n\t\t\t\tupdate `contacts` \n\t\t\t\tset `added_on` = '" . date("Y-m-d H:i:s") . "'\n\t\t\t\twhere `idcontacts` = " . $idcontacts;
             $do_contact->query($q_upd);
             $do_contact->insert("contacts_custom_fld", array("idcontacts" => $idcontacts));
             $do_contact->insert("contacts_address", array("idcontacts" => $idcontacts));
             $do_data_history = new DataHistory();
             $do_data_history->add_history($idcontacts, 4, 'add');
             $do_data_history->free();
             return $idcontacts;
         }
     }
 }
Exemple #3
0
 public function map_products_vendor($vendor_name)
 {
     $security_where = $_SESSION["do_crm_action_permission"]->get_user_where_condition('vendor', 11);
     $qry = "select * from `vendor` where `vendor_name` = ? " . $security_where;
     $stmt = $this->getDbConnection()->executeQuery($qry, array($vendor_name));
     if ($stmt->rowCount() > 0) {
         $data = $stmt->fetch();
         $idvendor = $data["idvendor"];
         return $idvendor;
     } else {
         if (strlen($vendor_name) > 0) {
             $do_vendor = new Vendor();
             $data = array("vendor_name" => CommonUtils::purify_input($vendor_name), "iduser" => $_SESSION["do_user"]->iduser, "added_on" => date("Y-m-d H:i:s"));
             $do_vendor->insert("vendor", $data);
             $idvendor = $do_vendor->getInsertId();
             $do_vendor->insert("vendor_address", array("idvendor" => $idvendor));
             $do_vendor->insert("vendor_custom_fld", array("idvendor" => $idvendor));
             $do_vendor->free();
             $do_data_history = new DataHistory();
             $do_data_history->add_history($idvendor, 11, 'add');
             $do_data_history->free();
             return $idvendor;
         }
     }
 }
Exemple #4
0
 /**
  * function to map organization to contact while importing
  * checks if the organization already exists else add a new one
  * @param string $organization_name
  * @param object $import_object
  * @param array $data
  * @return integer idorganization
  */
 public function map_contact_organization($organization_name, $import_object, $data)
 {
     $qry = "\n\t\tselect idorganization \n\t\tfrom organization \n\t\twhere organization_name = ?\n\t\tAND deleted = 0\n\t\tAND iduser ="******"do_user"]->iduser;
     $stmt = $this->getDbConnection()->executeQuery($qry, array(trim($organization_name)));
     if ($stmt->rowCount() > 0) {
         $rs = $stmt->fetch();
         return $rs["idorganization"];
     } else {
         if (strlen($organization_name) > 2) {
             $mapped_fields = $import_object->get_mapped_fields();
             $do_organization = new Organization();
             $do_organization->insert("organization", array("organization_name" => CommonUtils::purify_input($organization_name), "iduser" => $_SESSION["do_user"]->iduser));
             $idorganization = $do_organization->getInsertId();
             $q_upd = "\n\t\t\t\tupdate `organization`\n\t\t\t\tset `added_on` = ?\n\t\t\t\twhere `idorganization` = ?";
             $do_organization->query($q_upd, array(date("Y-m-d H:i:s"), $idorganization));
             $do_organization->insert("organization_custom_fld", array("idorganization" => $idorganization));
             $mapped_fields = $import_object->get_mapped_fields();
             if (array_search("cnt_mail_street", $mapped_fields) !== false) {
                 $org_bill_address = $data[array_search("cnt_mail_street", $mapped_fields)];
             } else {
                 $org_bill_address = '';
             }
             if (array_search("cnt_mail_pobox", $mapped_fields) !== false) {
                 $org_bill_pobox = $data[array_search("cnt_mail_pobox", $mapped_fields)];
             } else {
                 $org_bill_pobox = '';
             }
             if (array_search("cnt_mailing_city", $mapped_fields) !== false) {
                 $org_bill_city = $data[array_search("cnt_mailing_city", $mapped_fields)];
             } else {
                 $org_bill_city = '';
             }
             if (array_search("cnt_mailing_state", $mapped_fields) !== false) {
                 $org_bill_state = $data[array_search("cnt_mailing_state", $mapped_fields)];
             } else {
                 $org_bill_state = '';
             }
             if (array_search("cnt_mailing_postalcode", $mapped_fields) !== false) {
                 $org_bill_postalcode = $data[array_search("cnt_mailing_postalcode", $mapped_fields)];
             } else {
                 $org_bill_postalcode = '';
             }
             if (array_search("cnt_mailing_country", $mapped_fields) !== false) {
                 $org_bill_country = $data[array_search("cnt_mailing_country", $mapped_fields)];
             } else {
                 $org_bill_country = '';
             }
             $do_organization->insert("organization_address", array("idorganization" => $idorganization, "org_bill_address" => CommonUtils::purify_input($org_bill_address), "org_bill_pobox" => CommonUtils::purify_input($org_bill_pobox), "org_bill_city" => CommonUtils::purify_input($org_bill_city), "org_bill_state" => CommonUtils::purify_input($org_bill_state), "org_bill_postalcode" => CommonUtils::purify_input($org_bill_postalcode), "org_bill_country" => CommonUtils::purify_input($org_bill_country)));
             $do_data_history = new DataHistory();
             $do_data_history->add_history($idorganization, 6, 'add');
             $do_data_history->free();
             return $idorganization;
         } else {
             return 0;
         }
     }
 }