Esempio n. 1
0
 function send_po_email($so_id = null, $po_id = 0)
 {
     $this->_CI->load->model('sales_order_model');
     $this->_CI->load->model('purchase_model');
     $this->_CI->load->model('vendor_model');
     $this->_CI->load->model('purchase_order_prices_model');
     $this->_CI->load->library('encrypt');
     $this->_CI->config->load('support');
     if ($po_id) {
         $po_details = $this->_CI->purchase_model->get_where(array('id' => $po_id))->row_array();
         if (!count($po_details)) {
             return FALSE;
         }
         $pos = array($po_id => $po_details['vendor_id']);
     } else {
         //get external vendors po_id as key and vendor_id as value
         $pos = $this->_CI->sales_order_model->get_external_vendors($so_id);
     }
     $result = $this->_CI->sales_order_model->get_where(array('id' => $so_id));
     if (!$result->num_rows() && (int) $so_id) {
         return FALSE;
     }
     if (!count($pos)) {
         return FALSE;
     }
     $inc = 1;
     $so_details = array();
     $shipping_address = '';
     foreach ($pos as $po_id => $vid) {
         $rows = $this->_CI->purchase_model->get_po_item_details($po_id);
         if (!count($rows)) {
             continue;
         }
         //check if the sales order status is HOLD
         $temp = current($rows);
         if ($inc == 1) {
             $so_id = (int) $temp['sales_order_id'];
             if ($so_id) {
                 $so_details = $this->_CI->sales_order_model->get_where(array('id' => $so_id))->row_array();
                 if (strcmp($so_details['order_status'], 'HOLD') === 0) {
                     return FALSE;
                 }
             }
             $shipping_address = get_address_by_contact_id($temp['shipping_address_id'], 'html');
             if (!count($shipping_address)) {
                 return FALSE;
             }
         }
         if (strcmp($temp['po_type'], 'AUTO') === 0 and strcmp($temp['ship_type'], 'STOCKED') === 0) {
             continue;
         }
         if (strcmp($temp['po_type'], 'MANUAL') === 0 && !(int) $temp['sales_order_id']) {
             $path = 'email/manual_po/';
             $this->_sales_channel_id = 1;
         } else {
             //check expected ship-date flag
             $this->_CI->load->helper('shipping');
             $shipment_flags = get_shipments_flag_by_ESD($temp['sales_order_id'], $vid);
             if (in_array(0, $shipment_flags)) {
                 return TRUE;
             }
             $sales_channel_id = $so_details['sales_channel_id'];
             $path = is_null($sales_channel_id) ? 'email/' : "email/{$sales_channel_id}/";
         }
         if (!$this->_sales_channel_id) {
             $this->_sales_channel_id = $so_details['sales_channel_id'];
         }
         $vendor = $this->_CI->vendor_model->get_where(array('id' => $vid))->row_array();
         $data = array();
         $data['po_id'] = $po_id;
         $data['product_details'] = $rows;
         $data['shipping_address'] = $shipping_address;
         $data['shipment_service'] = $temp['shipment_service'];
         $data['shipping_type'] = $temp['shipment_method'];
         $enc_data = $this->_CI->encrypt->encode($so_id . "," . $po_id . "," . $temp['shipment_id']);
         $admin_url = $this->_CI->config->item('admin_url', 'support');
         $general_settings = get_settings($this->_sales_channel_id, 'general');
         $data['admin_url'] = "{$general_settings['admin_url']}/vendor_respond/add/{$enc_data}";
         $data['attachments'] = $this->get_po_attachements($po_id);
         $data['po_info'] = $vendor['po_info'];
         $data['vendor'] = $vendor;
         $this->_CI->load->model('purchase_model');
         $po_details = $this->_CI->purchase_model->get_where(array('id' => $po_id))->row_array();
         $data['po_message'] = $po_details['po_message'];
         $data['message'] = $this->_CI->load->view('email/po/hh-purchase-order', $data, TRUE);
         $total = 0;
         foreach ($data['product_details'] as $row) {
             $total += $row['quantity'] * $row['unit_price'];
         }
         $data['sub_total'] = (double) $total;
         //get reconciled charges
         $data['reconciled_charges'] = $this->_CI->purchase_order_prices_model->get_total_charge_by_po($po_id);
         //get drop-ship fee
         $data['dropship_fee'] = $this->_CI->purchase_model->get_dropship_fee($po_id);
         $data['order_total'] = $data['sub_total'] + $data['reconciled_charges'] + $data['dropship_fee'];
         $this->data = array('channel_details' => $general_settings, 'po_details' => $po_details, 'shipping_address' => $data['shipping_address'], 'billing_address' => $data['shipping_address'], 'item_details' => $data['product_details'], 'sub_total' => $data['sub_total'], 'dropship_fee' => $data['dropship_fee'], 'order_total' => $data['order_total'], 'po_message' => $data['po_message'], 'vendor' => $vendor);
         $content = $this->_CI->load->view('print/invoice_po', $this->data, TRUE);
         $this->_CI->load->library('pdf');
         $pdf = $this->_CI->pdf->load();
         $pdf_path = BASEPATH_HTDOCS . 'images/temp/' . 'PO' . time() . '.pdf';
         $pdf->WriteHTML($content);
         // write the HTML into the PDF
         $pdf->Output($pdf_path, 'F');
         // save to file
         //Based on Sourced list
         $sourced_list = array('HH', 'HL', 'ZING');
         if (isset($vendor['sourced']) && in_array($vendor['sourced'], $sourced_list)) {
             $tmplat_path = 'email/po/' . $vendor['sourced'] . '_';
         } else {
             $tmplat_path = 'email/po/HH_';
         }
         $message = $this->_CI->load->view($tmplat_path . 'email_template', $data, TRUE);
         //sales channel id change based on vendor sourced
         if (isset($vendor['sourced']) && $vendor['sourced'] == 'HL') {
             $this->_sales_channel_id = 12;
         } elseif (isset($vendor['sourced']) && $vendor['sourced'] == 'ZING') {
             $this->_sales_channel_id = 3;
         } else {
             $this->_sales_channel_id = 1;
         }
         //get email details
         $email_details = get_settings($this->_sales_channel_id, 'general');
         if (strcmp($temp['vendor_order_type'], 'email') === 0 && $temp['order_email']) {
             $cc_email = array($email_details['email_id'], '*****@*****.**');
             if (strcmp($temp['po_type'], 'MANUAL') === 0) {
                 $admin_email = get_adminuser_details_by_id(getAdminUserId());
                 if ($admin_email) {
                     $cc_email[] = $admin_email['email'];
                 }
             }
             $attachments = array();
             $attachments[] = $pdf_path;
             $this->send_email($temp['order_email'], '', $email_details['email_id'], $email_details['from_name'], "{$email_details['site_name']} - Purchase Order#{$po_id}", $message, $cc_email, $attachments);
             actionLogAdd('purchase', "PO#{$po_id} : Purchase order mail has been sent to vendor \"{$temp['vendor_name']}\".", $po_id);
         }
         //unlink($pdf_path);
         $inc++;
     }
     return TRUE;
 }
Esempio n. 2
0
function update_usermeta($key = '', $value = '', $user_id = '')
{
    if (!$key || !$user_id) {
        return false;
    }
    $CI =& get_instance();
    $CI->load->model('user_model');
    $meta_row = $CI->user_model->get_where(array('meta_key' => $key, 'user_id' => $user_id), "*", 'usermeta');
    $data = $return_data = array();
    $data['meta_value'] = $value;
    $data['updated_id'] = getAdminUserId();
    $data['updated_time'] = date('Y-m-d', local_to_gmt());
    if ($meta_row->num_rows() > 0) {
        $meta_row_data = $meta_row->row_array();
        $return_data['prev_value'] = $meta_row_data['meta_value'];
        $CI->user_model->update(array('umeta_id' => $meta_row_data['umeta_id']), $data, 'usermeta');
        $return_data['id'] = $meta_row_data['umeta_id'];
        $return_data['status'] = "update";
    } else {
        $data['meta_key'] = $key;
        $data['user_id'] = $user_id;
        $data['created_id'] = getAdminUserId();
        $data['created_time'] = date('Y-m-d', local_to_gmt());
        $umeta_id = $CI->user_model->insert($data, 'usermeta');
        $return_data['id'] = $umeta_id;
        $return_data['status'] = "add";
    }
    return $return_data;
}
Esempio n. 3
0
 function create_profile()
 {
     $this->CI->load->library('authorize_net');
     //create or fetch customer prfile_id
     $profile_id = $this->CI->authorize_net->create_customer_profile($this->_user_id);
     if (!$profile_id) {
         $this->error_message = $this->CI->error_message;
         return FALSE;
     }
     //update profile ID
     update_usermeta('authorize_profile_id', $profile_id, $this->_user_id);
     $args = array();
     if (isset($this->_billing_info['name'])) {
         $args['firstName'] = $this->_billing_info['name'];
     }
     if (isset($this->_billing_info['address'])) {
         $args['address'] = $this->_billing_info['address'];
     }
     if (isset($this->_billing_info['city'])) {
         $args['city'] = $this->_billing_info['city'];
     }
     if (isset($this->_billing_info['state'])) {
         $args['state'] = $this->_billing_info['state'];
     }
     if (isset($this->_billing_info['zip_code'])) {
         $args['zip'] = $this->_billing_info['zip_code'];
     }
     if (isset($this->_billing_info['country'])) {
         $args['country'] = $this->_billing_info['country'];
     }
     $args['customerProfileId'] = $profile_id;
     $args['merchantCustomerId'] = $this->_user_id;
     $args['payment_type'] = "credit_card";
     //credit_card
     if (isset($this->_card_details['cc_number'])) {
         $args['cardNumber'] = $this->_card_details['cc_number'];
     }
     if (isset($this->_card_details['cc_year']) && isset($this->_card_details['cc_month'])) {
         $args['expirationDate'] = $this->_card_details['cc_year'] . '-' . sprintf("%02s", $this->_card_details['cc_month']);
     }
     //"2015-10"
     if (isset($this->_card_details['cc_ccd'])) {
         $args['cardCode'] = $this->_card_details['cc_ccd'];
     }
     //echo '<pre>';print_r($args);die;
     $payment_profile_id = $this->CI->authorize_net->add_payment_profile($args);
     if (!$payment_profile_id) {
         $this->error_message = $this->CI->error_message;
         return FALSE;
     }
     //insert into user table
     $insert_data = array();
     $insert_data['profile_id'] = $payment_profile_id;
     $insert_data['type'] = 'payment';
     $insert_data['user_id'] = $this->_user_id;
     $insert_data['card_no'] = substr($this->_card_details['cc_number'], -4);
     $insert_data['created_id'] = getAdminUserId();
     $insert_data['created_time'] = date("Y-m-d H:i:s", local_to_gmt());
     $insert_data['updated_id'] = getAdminUserId();
     $insert_data['updated_time'] = date("Y-m-d H:i:s", local_to_gmt());
     $this->CI->db->insert('authorize_cim', $insert_data);
     return TRUE;
 }
Esempio n. 4
0
function get_followup_uesr($followup, $followed_by)
{
    if (empty($followup) || $followup == 'no') {
        return FALSE;
    }
    if (empty($followed_by)) {
        return FALSE;
    }
    $followd_array = explode(",", $followed_by);
    if ($followup == 'yes' && in_array(getAdminUserId(), $followd_array)) {
        return TRUE;
    } else {
        return FALSE;
    }
}