function complete() { $data['is_sale'] = TRUE; $data['cart'] = $this->sale_lib->get_cart(); if (empty($data['cart'])) { redirect('sales'); } if (!$this->_payments_cover_total()) { $this->_reload(array('error' => lang('sales_cannot_complete_sale_as_payments_do_not_cover_total')), false); return; } $tier_id = $this->sale_lib->get_selected_tier_id(); $tier_info = $this->Tier->get_info($tier_id); $data['tier'] = $tier_info->name; $data['register_name'] = $this->Register->get_register_name($this->Employee->get_logged_in_employee_current_register_id()); $data['subtotal'] = $this->sale_lib->get_subtotal(); $data['taxes'] = $this->sale_lib->get_taxes(); $data['total'] = $this->sale_lib->get_total(); $data['receipt_title'] = lang('sales_receipt'); $customer_id = $this->sale_lib->get_customer(); $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; $sold_by_employee_id = $this->sale_lib->get_sold_by_employee_id(); $data['comment'] = $this->sale_lib->get_comment(); $data['show_comment_on_receipt'] = $this->sale_lib->get_comment_on_receipt(); $emp_info = $this->Employee->get_info($employee_id); $sale_emp_info = $this->Employee->get_info($sold_by_employee_id); $data['payments'] = $this->sale_lib->get_payments(); $data['is_sale_cash_payment'] = $this->sale_lib->is_sale_cash_payment(); $data['amount_change'] = $this->sale_lib->get_amount_due() * -1; $data['balance'] = $this->sale_lib->get_payment_amount(lang('sales_store_account')); $data['employee'] = $emp_info->first_name . ' ' . $emp_info->last_name . ($sold_by_employee_id && $sold_by_employee_id != $employee_id ? '/' . $sale_emp_info->first_name . ' ' . $sale_emp_info->last_name : ''); $data['ref_no'] = $this->session->userdata('ref_no') ? $this->session->userdata('ref_no') : ''; $data['auth_code'] = $this->session->userdata('auth_code') ? $this->session->userdata('auth_code') : ''; $data['discount_exists'] = $this->_does_discount_exists($data['cart']); $masked_account = $this->session->userdata('masked_account') ? $this->session->userdata('masked_account') : ''; $card_issuer = $this->session->userdata('card_issuer') ? $this->session->userdata('card_issuer') : ''; if ($masked_account) { $cc_payment_id = current($this->sale_lib->get_payment_ids(lang('sales_credit'))); $cc_payment = $data['payments'][$cc_payment_id]; $this->sale_lib->edit_payment($cc_payment_id, $cc_payment['payment_type'], $cc_payment['payment_amount'], $cc_payment['payment_date'], $masked_account, $card_issuer); //Make sure our payments has the latest change to masked_account $data['payments'] = $this->sale_lib->get_payments(); } $data['change_sale_date'] = $this->sale_lib->get_change_sale_date_enable() ? $this->sale_lib->get_change_sale_date() : false; $old_date = $this->sale_lib->get_change_sale_id() ? $this->Sale->get_info($this->sale_lib->get_change_sale_id())->row_array() : false; $old_date = $old_date ? date(get_date_format() . ' ' . get_time_format(), strtotime($old_date['sale_time'])) : date(get_date_format() . ' ' . get_time_format()); $data['transaction_time'] = $this->sale_lib->get_change_sale_date_enable() ? date(get_date_format() . ' ' . get_time_format(), strtotime($this->sale_lib->get_change_sale_date())) : $old_date; if ($customer_id != -1) { $cust_info = $this->Customer->get_info($customer_id); $data['customer'] = $cust_info->first_name . ' ' . $cust_info->last_name . ($cust_info->company_name == '' ? '' : ' - ' . $cust_info->company_name) . ($cust_info->account_number == '' ? '' : ' - ' . $cust_info->account_number); $data['customer_address_1'] = $cust_info->address_1; $data['customer_address_2'] = $cust_info->address_2; $data['customer_city'] = $cust_info->city; $data['customer_state'] = $cust_info->state; $data['customer_zip'] = $cust_info->zip; $data['customer_country'] = $cust_info->country; $data['customer_phone'] = $cust_info->phone_number; $data['customer_email'] = $cust_info->email; } $suspended_change_sale_id = $this->sale_lib->get_suspended_sale_id() ? $this->sale_lib->get_suspended_sale_id() : $this->sale_lib->get_change_sale_id(); //If we have a previous sale make sure we get the ref_no unless we already have it set if ($suspended_change_sale_id && !$data['ref_no']) { $sale_info = $this->Sale->get_info($suspended_change_sale_id)->row_array(); $data['ref_no'] = $sale_info['cc_ref_no']; } //If we have a previous sale make sure we get the auth_code unless we already have it set if ($suspended_change_sale_id && !$data['auth_code']) { $sale_info = $this->Sale->get_info($suspended_change_sale_id)->row_array(); $data['auth_code'] = $sale_info['auth_code']; } //If we have a suspended sale, update the date for the sale if ($this->sale_lib->get_suspended_sale_id() && $this->config->item('change_sale_date_when_completing_suspended_sale')) { $data['change_sale_date'] = date('Y-m-d H:i:s'); } $data['store_account_payment'] = $this->sale_lib->get_mode() == 'store_account_payment' ? 1 : 0; //SAVE sale to database $sale_id_raw = $this->Sale->save($data['cart'], $customer_id, $employee_id, $sold_by_employee_id, $data['comment'], $data['show_comment_on_receipt'], $data['payments'], $suspended_change_sale_id, 0, $data['ref_no'], $data['auth_code'], $data['change_sale_date'], $data['balance'], $data['store_account_payment']); $data['sale_id'] = $this->config->item('sale_prefix') . ' ' . $sale_id_raw; $data['sale_id_raw'] = $sale_id_raw; if ($customer_id != -1) { $cust_info = $this->Customer->get_info($customer_id); if ($cust_info->balance != 0) { $data['customer_balance_for_sale'] = $cust_info->balance; } } //If we don't have any taxes, run a check for items so we don't show the price including tax on receipt if (empty($data['taxes'])) { foreach (array_keys($data['cart']) as $key) { if (isset($data['cart'][$key]['item_id'])) { $item_info = $this->Item->get_info($data['cart'][$key]['item_id']); if ($item_info->tax_included) { $price_to_use = get_price_for_item_excluding_taxes($data['cart'][$key]['item_id'], $data['cart'][$key]['price']); $data['cart'][$key]['price'] = $price_to_use; } } elseif (isset($data['cart'][$key]['item_kit_id'])) { $item_info = $this->Item_kit->get_info($data['cart'][$key]['item_kit_id']); if ($item_info->tax_included) { $price_to_use = get_price_for_item_kit_excluding_taxes($data['cart'][$key]['item_kit_id'], $data['cart'][$key]['price']); $data['cart'][$key]['price'] = $price_to_use; } } } } if ($data['sale_id'] == $this->config->item('sale_prefix') . ' -1') { $data['error_message'] = ''; if (is_sale_integrated_cc_processing()) { $data['error_message'] .= lang('sales_credit_card_transaction_completed_successfully') . '. '; } $data['error_message'] .= lang('sales_transaction_failed'); } else { if ($this->sale_lib->get_email_receipt() && !empty($cust_info->email)) { $this->load->library('email'); $config['mailtype'] = 'html'; $this->email->initialize($config); $this->email->from($this->Location->get_info_for_key('email') ? $this->Location->get_info_for_key('email') : '*****@*****.**', $this->config->item('company')); $this->email->to($cust_info->email); $this->email->subject(lang('sales_receipt')); $this->email->message($this->load->view("sales/receipt_email", $data, true)); $this->email->send(); } } $this->load->view("sales/receipt", $data); $this->sale_lib->clear_all(); }
<?php $this->load->view("partial/header"); $is_integrated_credit_sale = is_sale_integrated_cc_processing(); if (isset($error_message)) { echo '<h1 style="text-align: center;">' . $error_message . '</h1>'; exit; } ?> <div id="receipt_wrapper" class="receipt_<?php echo $this->config->item('receipt_text_size'); ?> "> <div id="receipt_header"> <div id="company_name"><?php echo $this->config->item('company'); ?> </div> <?php if ($this->config->item('company_logo')) { ?> <div id="company_logo"><?php echo img(array('src' => $this->Appconfig->get_logo_image())); ?> </div> <?php } ?> <div id="company_address"><?php echo nl2br($this->Location->get_info_for_key('address')); ?>
echo "<input type='button' class='btn btn-success btn-large btn-block' id='finish_sale_button' value='" . lang('sales_complete_sale') . "' />"; } ?> </div> </form> <?php } elseif (count($payments) > 0) { ?> <div id="finish_sale"> <?php echo form_open("sales/start_cc_processing", array('id' => 'finish_sale_form', 'autocomplete' => 'off')); ?> <?php if ($payments_cover_total && $customer_required_check || is_sale_integrated_cc_processing()) { echo "<input type='button' class='btn btn-success btn-large btn-block' id='finish_sale_button' value='" . lang('sales_process_credit_card') . "' />"; if (is_sale_integrated_cc_processing()) { if (isset($customer) && $customer_cc_token && $customer_cc_preview) { echo '<label id="sales_use_saved_cc_label" for="use_saved_cc_info" class="checkbox">'; echo lang('sales_use_saved_cc_info') . ' ' . $customer_cc_preview; echo form_checkbox(array('name' => 'use_saved_cc_info', 'id' => 'use_saved_cc_info', 'value' => '1', 'checked' => (bool) $use_saved_cc_info)); echo '</label> '; } elseif (isset($customer)) { echo '<label id="sales_save_credit_card_label" for="save_credit_card_info" class="checkbox">'; echo lang('sales_save_credit_card_info'); echo form_checkbox(array('name' => 'save_credit_card_info', 'id' => 'save_credit_card_info', 'value' => '1', 'checked' => (bool) $save_credit_card_info)); echo '</label> '; } } } ?> </div>