function build_test_invoice($total = 0)
 {
     $user_args = array('user_login' => '*****@*****.**', 'display_name' => 'Unit Tester', 'user_pass' => wp_generate_password(), 'user_email' => '*****@*****.**');
     $user_id = SI_Clients::create_user($user_args);
     $args = array('company_name' => 'Test Client', 'user_id' => $user_id);
     $client_id = SI_Client::new_client($args);
     $args = array('subject' => 'TESTING Payments');
     $id = SI_Invoice::create_invoice($args, SI_Invoice::STATUS_TEMP);
     $this->invoice_ids[] = $id;
     $invoice = SI_Invoice::get_instance($id);
     $invoice->set_client_id($client_id);
     // No total set make them random
     if (!$total) {
         $line_items = array();
         for ($i = 0; $i < 10; $i++) {
             $rate = rand(1000, 4000);
             $qty = rand(1, 10);
             $line_items[] = array('rate' => $rate, 'qty' => $qty, 'desc' => 'This is a test line item for a test invoice.', 'type' => '', 'total' => $rate * $qty, 'tax' => 0);
         }
     } else {
         $line_items = array(array('rate' => $total, 'qty' => 1, 'desc' => 'This is a test line item for a test invoice.', 'type' => '', 'total' => $total, 'tax' => 0));
     }
     $invoice->set_line_items($line_items);
     $this->assertTrue(in_array($id, $this->invoice_ids));
     return $id;
 }
Ejemplo n.º 2
0
 function setUp()
 {
     parent::setUp();
     $user_args = array('user_login' => '*****@*****.**', 'display_name' => 'Unit Tester', 'user_pass' => wp_generate_password(), 'user_email' => '*****@*****.**');
     $user_id = SI_Clients::create_user($user_args);
     $args = array('company_name' => 'Test Client', 'user_id' => $user_id);
     $client_id = SI_Client::new_client($args);
     $args = array('subject' => 'TEST Payment');
     $this->invoice_id = SI_Invoice::create_invoice($args, SI_Invoice::STATUS_TEMP);
     $this->invoice = SI_Invoice::get_instance($this->invoice_id);
     $this->invoice->set_client_id($client_id);
     $line_items = array();
     for ($i = 0; $i < 10; $i++) {
         $rate = rand(100, 1000);
         $qty = rand(1, 10);
         $line_items[] = array('rate' => $rate, 'qty' => $qty, 'desc' => 'This is a test line item for a test invoice.', 'type' => '', 'total' => $rate * $qty, 'tax' => 0);
     }
     $this->invoice->set_line_items($line_items);
 }
Ejemplo n.º 3
0
 public static function create_contact($contact = array(), $client_id = 0)
 {
     if ($user = get_user_by('email', $contact['email'])) {
         do_action('si_error', 'Contact imported already', $contact['contact_id']);
         return $user->ID;
     }
     // Get client and confirm it's validity
     $client = SI_Client::get_instance($client_id);
     if (!is_a($client, 'SI_Client')) {
         return;
     }
     $args = array('user_login' => !is_array($contact['username']) ? $contact['username'] : $contact['email'], 'display_name' => $client->get_title(), 'user_email' => $contact['email'], 'first_name' => !is_array($contact['first_name']) ? $contact['first_name'] : '', 'last_name' => !is_array($contact['first_name']) ? $contact['first_name'] : '');
     $user_id = SI_Clients::create_user($args);
     update_user_meta($user_id, self::FRESHBOOKS_ID, $contact['contact_id']);
     if (isset($contact['phone1']) && !is_array($contact['phone1'])) {
         update_user_meta($user_id, self::USER_META_PHONE, $contact['phone1']);
     }
     if (isset($contact['phone2']) && !is_array($contact['phone2'])) {
         update_user_meta($user_id, self::USER_META_OFFICE_PHONE, $contact['phone2']);
     }
     // Assign new user to client.
     $client->add_associated_user($user_id);
     return $user_id;
 }
Ejemplo n.º 4
0
 public static function create_contact($client = array(), $client_id = 0)
 {
     $contact = array('username' => isset($client['Email Address']) ? $client['Email Address'] : '', 'email' => isset($client['Email Address']) ? $client['Email Address'] : '', 'first_name' => isset($client['First Name']) ? $client['First Name'] : '', 'last_name' => isset($client['Last Name']) ? $client['Last Name'] : '');
     $user_id = 0;
     if ($user = get_user_by('email', $contact['email'])) {
         do_action('si_error', 'Contact/user imported already', $contact);
         $user_id = $user->ID;
     }
     // Get client and confirm it's validity
     $client = SI_Client::get_instance($client_id);
     if (!is_a($client, 'SI_Client')) {
         return;
     }
     if (!$user_id) {
         $args = array('user_login' => $contact['username'] ? $contact['username'] : $contact['email'], 'display_name' => $client->get_title(), 'user_email' => $contact['email'], 'first_name' => $contact['first_name'] ? $contact['first_name'] : '', 'last_name' => $contact['last_name'] ? $contact['last_name'] : '');
         $user_id = SI_Clients::create_user($args);
     }
     // Assign new user to client.
     $client->add_associated_user($user_id);
     return $user_id;
 }
 /**
  * Maybe create a client from submission
  * @param  SI_Estimate $estimate 
  * @param  array       $args     * email - required
  *                               * client_id - if client_id is passed than just assign estimate
  *                               * client_name - required
  *                               * full_name - 
  *                               * website
  *                               * contact_street
  *                               * contact_city
  *                               * contact_zone
  *                               * contact_postal_code
  *                               * contact_country
  *                               
  */
 public static function maybe_create_client(SI_Estimate $estimate, $args = array())
 {
     $args = apply_filters('si_afi_maybe_create_client', $args);
     $client_id = isset($args['client_id']) && get_post_type($args['client_id']) == SI_Client::POST_TYPE ? $args['client_id'] : 0;
     $user_id = get_current_user_id();
     // check to see if the user exists by email
     if (isset($args['email']) && $args['email'] != '') {
         if ($user = get_user_by('email', $args['email'])) {
             $user_id = $user->ID;
         }
     }
     // Check to see if the user is assigned to a client already
     if (!$client_id) {
         $client_ids = SI_Client::get_clients_by_user($user_id);
         if (!empty($client_ids)) {
             $client_id = array_pop($client_ids);
         }
     }
     // Create a user for the submission if an email is provided.
     if (!$user_id) {
         // email is critical
         if (isset($args['email']) && $args['email'] != '') {
             $user_args = array('user_login' => self::esc__($args['email']), 'display_name' => isset($args['client_name']) ? self::esc__($args['client_name']) : self::esc__($args['email']), 'user_pass' => wp_generate_password(), 'user_email' => isset($args['email']) ? self::esc__($args['email']) : '', 'first_name' => si_split_full_name(self::esc__($args['full_name']), 'first'), 'last_name' => si_split_full_name(self::esc__($args['full_name']), 'last'), 'user_url' => isset($args['website']) ? self::esc__($args['website']) : '');
             $user_id = SI_Clients::create_user($user_args);
         }
     }
     // create the client based on what's submitted.
     if (!$client_id) {
         $address = array('street' => isset($args['contact_street']) ? self::esc__($args['contact_street']) : '', 'city' => isset($args['contact_city']) ? self::esc__($args['contact_city']) : '', 'zone' => isset($args['contact_zone']) ? self::esc__($args['contact_zone']) : '', 'postal_code' => isset($args['contact_postal_code']) ? self::esc__($args['contact_postal_code']) : '', 'country' => isset($args['contact_country']) ? self::esc__($args['contact_country']) : '');
         $args = array('company_name' => isset($args['client_name']) ? self::esc__($args['client_name']) : '', 'website' => isset($args['website']) ? self::esc__($args['website']) : '', 'address' => $address, 'user_id' => $user_id);
         $client_id = SI_Client::new_client($args);
         // History
         do_action('si_new_record', sprintf('Client Created & Assigned: %s', get_the_title($client_id)), self::SUBMISSION_UPDATE, $estimate->get_id(), sprintf('Client Created & Assigned: %s', get_the_title($client_id)), 0, false);
     }
     // Set the estimates client
     $estimate->set_client_id($client_id);
 }
Ejemplo n.º 6
0
 public static function create_contact(Harvest_Contact $contact)
 {
     if ($user = get_user_by('email', $contact->email)) {
         do_action('si_error', 'Contact imported already', $contact->id);
         return $user->ID;
     }
     $clients = SI_Post_Type::find_by_meta(SI_Client::POST_TYPE, array(self::HARVEST_ID => $contact->client_id));
     // Only create a contact if a client was already created.
     if (empty($clients)) {
         return;
     }
     // Get client and confirm it's validity
     $client = SI_Client::get_instance($clients[0]);
     if (!is_a($client, 'SI_Client')) {
         return;
     }
     $args = array('user_login' => $contact->email, 'display_name' => $client->get_title(), 'user_email' => $contact->email, 'first_name' => $contact->first_name, 'last_name' => $contact->last_name);
     $user_id = SI_Clients::create_user($args);
     update_user_meta($user_id, self::HARVEST_ID, $contact->id);
     update_user_meta($user_id, self::USER_META_TITLE, $contact->title);
     update_user_meta($user_id, self::USER_META_PHONE, $contact->phone_mobile);
     update_user_meta($user_id, self::USER_META_OFFICE_PHONE, $contact->phone_office);
     // Assign new user to client.
     $client->add_associated_user($user_id);
     return $user_id;
 }