Example #1
0
 function email($entry_type, $entry_id = 0)
 {
     $this->load->model('Setting_model');
     $this->load->model('Ledger_model');
     $this->load->library('email');
     /* Check access */
     if (!check_access('email entry')) {
         $this->messages->add('Permission denied.', 'error');
         redirect('entry/show/' . $entry_type);
         return;
     }
     /* Entry Type */
     $entry_type_id = entry_type_name_to_id($entry_type);
     if (!$entry_type_id) {
         $this->messages->add('Invalid Entry type.', 'error');
         redirect('entry/show/all');
         return;
     } else {
         $current_entry_type = entry_type_info($entry_type_id);
     }
     $account_data = $this->Setting_model->get_current();
     /* Load current entry details */
     if (!($cur_entry = $this->Entry_model->get_entry($entry_id, $entry_type_id))) {
         $this->messages->add('Invalid Entry.', 'error');
         redirect('entry/show/' . $current_entry_type['label']);
         return;
     }
     $data['entry_type_id'] = $entry_type_id;
     $data['current_entry_type'] = $current_entry_type;
     $data['entry_id'] = $entry_id;
     $data['entry_number'] = $cur_entry->number;
     $data['email_to'] = array('name' => 'email_to', 'id' => 'email_to', 'size' => '40', 'value' => '');
     /* Form validations */
     $this->form_validation->set_rules('email_to', 'Email to', 'trim|valid_emails|required');
     /* Repopulating form */
     if ($_POST) {
         $data['email_to']['value'] = $this->input->post('email_to', TRUE);
     }
     if ($this->form_validation->run() == FALSE) {
         $data['error'] = validation_errors();
         $this->load->view('entry/email', $data);
         return;
     } else {
         $entry_data['entry_type_id'] = $entry_type_id;
         $entry_data['current_entry_type'] = $current_entry_type;
         $entry_data['entry_number'] = $cur_entry->number;
         $entry_data['entry_date'] = date_mysql_to_php_display($cur_entry->date);
         $entry_data['entry_dr_total'] = $cur_entry->dr_total;
         $entry_data['entry_cr_total'] = $cur_entry->cr_total;
         $entry_data['entry_narration'] = $cur_entry->narration;
         /* Getting Ledger details */
         $this->db->from('entry_items')->where('entry_id', $entry_id)->order_by('dc', 'desc');
         $ledger_q = $this->db->get();
         $counter = 0;
         $entry_data['ledger_data'] = array();
         if ($ledger_q->num_rows() > 0) {
             foreach ($ledger_q->result() as $row) {
                 $entry_data['ledger_data'][$counter] = array('id' => $row->ledger_id, 'name' => $this->Ledger_model->get_name($row->ledger_id), 'dc' => $row->dc, 'amount' => $row->amount);
                 $counter++;
             }
         }
         /* Preparing message */
         $message = $this->load->view('entry/emailpreview', $entry_data, TRUE);
         /* Getting email configuration */
         $config['smtp_timeout'] = '30';
         $config['charset'] = 'utf-8';
         $config['newline'] = "\r\n";
         $config['mailtype'] = "html";
         if ($account_data) {
             $config['protocol'] = $account_data->email_protocol;
             $config['smtp_host'] = $account_data->email_host;
             $config['smtp_port'] = $account_data->email_port;
             $config['smtp_user'] = $account_data->email_username;
             $config['smtp_pass'] = $account_data->email_password;
         } else {
             $data['error'] = 'Invalid account settings.';
         }
         $this->email->initialize($config);
         /* Sending email */
         $this->email->from('', 'Webzash');
         $this->email->to($this->input->post('email_to', TRUE));
         $this->email->subject($current_entry_type['name'] . ' Entry No. ' . full_entry_number($entry_type_id, $cur_entry->number));
         $this->email->message($message);
         if ($this->email->send()) {
             $data['message'] = "Email sent.";
             $this->logger->write_message("success", "Emailed " . $current_entry_type['name'] . " Entry number " . full_entry_number($entry_type_id, $cur_entry->number) . " [id:" . $entry_id . "]");
         } else {
             $data['error'] = "Error sending email. Check you email settings.";
             $this->logger->write_message("error", "Error emailing " . $current_entry_type['name'] . " Entry number " . full_entry_number($entry_type_id, $cur_entry->number) . " [id:" . $entry_id . "]");
         }
         $this->load->view('entry/email', $data);
         return;
     }
     return;
 }
Example #2
0
 function email($entry_type, $entry_id = 0)
 {
     $this->load->model('Setting_model');
     $this->load->library('email');
     /* Check access */
     if (!check_access('email inventory entry')) {
         $this->messages->add('Permission denied.', 'error');
         redirect('inventory/transfer/show/' . $entry_type);
         return;
     }
     /* Entry Type */
     $entry_type_id = entry_type_name_to_id($entry_type);
     if (!$entry_type_id) {
         $this->messages->add('Invalid Entry type.', 'error');
         redirect('entry/show/all');
         return;
     } else {
         $current_entry_type = entry_type_info($entry_type_id);
     }
     $account_data = $this->Setting_model->get_current();
     /* Load current entry details */
     if (!($cur_entry = $this->Entry_model->get_entry($entry_id, $entry_type_id))) {
         $this->messages->add('Invalid Entry.', 'error');
         redirect('entry/show/' . $current_entry_type['label']);
         return;
     }
     /* Load current inventory items details */
     $this->db->from('inventory_entry_items')->where('entry_id', $entry_id)->where('type', 1)->order_by('id', 'asc');
     $cur_entry_source_inventory_items = $this->db->get();
     if ($cur_entry_source_inventory_items->num_rows() < 1) {
         $this->messages->add('Entry has no associated source inventory items.', 'error');
     }
     $this->db->from('inventory_entry_items')->where('entry_id', $entry_id)->where('type', 2)->order_by('id', 'asc');
     $cur_entry_dest_inventory_items = $this->db->get();
     if ($cur_entry_dest_inventory_items->num_rows() < 1) {
         $this->messages->add('Entry has no associated destination inventory items.', 'error');
     }
     $data['entry_type_id'] = $entry_type_id;
     $data['current_entry_type'] = $current_entry_type;
     $data['entry_id'] = $entry_id;
     $data['entry_number'] = $cur_entry->number;
     $data['email_to'] = array('name' => 'email_to', 'id' => 'email_to', 'size' => '40', 'value' => '');
     /* Form validations */
     $this->form_validation->set_rules('email_to', 'Email to', 'trim|valid_emails|required');
     /* Repopulating form */
     if ($_POST) {
         $data['email_to']['value'] = $this->input->post('email_to', TRUE);
     }
     if ($this->form_validation->run() == FALSE) {
         $data['error'] = validation_errors();
         $this->load->view('inventory/transfer/email', $data);
         return;
     } else {
         $data['cur_entry'] = $cur_entry;
         $data['cur_entry_source_inventory_items'] = $cur_entry_source_inventory_items;
         $data['cur_entry_dest_inventory_items'] = $cur_entry_dest_inventory_items;
         /* Preparing message */
         $message = $this->load->view('inventory/transfer/emailpreview', $data, TRUE);
         /* Getting email configuration */
         $config['smtp_timeout'] = '30';
         $config['charset'] = 'utf-8';
         $config['newline'] = "\r\n";
         $config['mailtype'] = "html";
         if ($account_data) {
             $config['protocol'] = $account_data->email_protocol;
             $config['smtp_host'] = $account_data->email_host;
             $config['smtp_port'] = $account_data->email_port;
             $config['smtp_user'] = $account_data->email_username;
             $config['smtp_pass'] = $account_data->email_password;
         } else {
             $data['error'] = 'Invalid account settings.';
         }
         $this->email->initialize($config);
         /* Sending email */
         $this->email->from('', 'Webzash');
         $this->email->to($this->input->post('email_to', TRUE));
         $this->email->subject($current_entry_type['name'] . ' Entry No. ' . full_entry_number($entry_type_id, $cur_entry->number));
         $this->email->message($message);
         if ($this->email->send()) {
             $data['message'] = "Email sent.";
             $this->logger->write_message("success", "Emailed " . $current_entry_type['name'] . " Entry number " . full_entry_number($entry_type_id, $cur_entry->number) . " [id:" . $entry_id . "]");
         } else {
             $data['error'] = "Error sending email. Check you email settings.";
             $this->logger->write_message("error", "Error emailing " . $current_entry_type['name'] . " Entry number " . full_entry_number($entry_type_id, $cur_entry->number) . " [id:" . $entry_id . "]");
         }
         $this->load->view('inventory/transfer/email', $data);
         return;
     }
     return;
 }