Esempio n. 1
0
 public function getSummaryData()
 {
     $this->db->select('sum(amount) as amount, 
                 sum(paid_princ) as paid_princ, 
                 (sum(paid_princ)-sum(amount)) as amount_due,
                 sum(pay_rate) as rate,
                 sum(paid_rate) as paid_rate,
                 sum(pay_fine) as pay_fine,
                 sum(profit) as profit', false);
     $this->db->from('pawns_temp');
     $this->db->where('deleted', 0);
     $this->db->group_by('pawn_id');
     $return = array('amount' => 0, 'paid_princ' => 0, 'amount_due' => 0, 'rate' => 0, 'paid_rate' => 0, 'pay_fine' => 0, 'profit' => 0);
     foreach ($this->db->get()->result_array() as $row) {
         $return['amount'] += to_currency_no_money($row['amount'], 2);
         $return['paid_princ'] += to_currency_no_money($row['paid_princ'], 2);
         $return['amount_due'] += to_currency_no_money($row['amount_due'], 2);
         //$return['deposit'] += to_currency_no_money($row['deposit'], 2);
         $return['rate'] += to_currency_no_money($row['rate'], 2);
         $return['paid_rate'] += to_currency_no_money($row['paid_rate'], 2);
         //$return['late'] += $row['late'];
         $return['pay_fine'] += to_currency_no_money($row['pay_fine'], 2);
         $return['profit'] += to_currency_no_money($row['profit'], 2);
     }
     if (!$this->Employee->has_module_action_permission('reports', 'show_profit', $this->Employee->get_logged_in_employee_info()->person_id)) {
         unset($return['profit']);
     }
     return $return;
 }
 public function getSummaryData()
 {
     $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax,sum(profit) as profit', false);
     $this->db->from('sales_items_temp');
     if ($this->params['sale_type'] == 'sales') {
         $this->db->where('quantity_purchased > 0');
     } elseif ($this->params['sale_type'] == 'returns') {
         $this->db->where('quantity_purchased < 0');
     }
     $this->db->where($this->db->dbprefix('sales_items_temp') . '.deleted', 0);
     if ($this->config->item('hide_store_account_payments_from_report_totals')) {
         $this->db->where('store_account_payment', 0);
     }
     $this->db->group_by('sale_id');
     $return = array('subtotal' => 0, 'total' => 0, 'tax' => 0, 'profit' => 0);
     foreach ($this->db->get()->result_array() as $row) {
         $return['subtotal'] += to_currency_no_money($row['subtotal'], 2);
         $return['total'] += to_currency_no_money($row['total'], 2);
         $return['tax'] += to_currency_no_money($row['tax'], 2);
         $return['profit'] += to_currency_no_money($row['profit'], 2);
     }
     if (!$this->Employee->has_module_action_permission('reports', 'show_profit', $this->Employee->get_logged_in_employee_info()->person_id)) {
         unset($return['profit']);
     }
     return $return;
 }
 public function getSummaryData()
 {
     $employee_column = $this->params['employee_type'] == 'logged_in_employee' ? 'employee_id' : 'sold_by_employee_id';
     $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit,sum(commission) as commission', false);
     $this->db->from('sales_items_temp');
     $this->db->join('employees', 'employees.person_id = sales_items_temp.' . $employee_column);
     $this->db->join('people', 'employees.person_id = people.person_id');
     if ($this->params['sale_type'] == 'sales') {
         $this->db->where('quantity_purchased > 0');
     } elseif ($this->params['sale_type'] == 'returns') {
         $this->db->where('quantity_purchased < 0');
     }
     $this->db->where($this->db->dbprefix('sales_items_temp') . '.deleted', 0);
     $this->db->group_by('sale_id');
     $return = array('subtotal' => 0, 'total' => 0, 'tax' => 0, 'profit' => 0, 'commission' => 0);
     foreach ($this->db->get()->result_array() as $row) {
         $return['subtotal'] += to_currency_no_money($row['subtotal'], 2);
         $return['total'] += to_currency_no_money($row['total'], 2);
         $return['tax'] += to_currency_no_money($row['tax'], 2);
         $return['profit'] += to_currency_no_money($row['profit'], 2);
         $return['commission'] += to_currency_no_money($row['commission'], 2);
     }
     if (!$this->Employee->has_module_action_permission('reports', 'show_profit', $this->Employee->get_logged_in_employee_info()->person_id)) {
         unset($return['profit']);
     }
     return $return;
 }
Esempio n. 4
0
 public function getSummaryData()
 {
     $logged_in_location_id = $this->Employee->get_logged_in_employee_current_location_id();
     $sales_totals = array();
     $this->db->select('sale_id, SUM(total) as total', false);
     $this->db->from('sales_items_temp');
     $this->db->where('deleted', 0);
     $this->db->group_by('sale_id');
     foreach ($this->db->get()->result_array() as $sale_total_row) {
         $sales_totals[$sale_total_row['sale_id']] = to_currency_no_money($sale_total_row['total'], 2);
     }
     $this->db->select('sales_payments.sale_id, sales_payments.payment_type, payment_amount, payment_id', false);
     $this->db->from('sales_payments');
     $this->db->join('sales', 'sales.sale_id=sales_payments.sale_id');
     $this->db->where('payment_date BETWEEN ' . $this->db->escape($this->params['start_date']) . ' and ' . $this->db->escape($this->params['end_date']) . ' and location_id = ' . $this->db->escape($logged_in_location_id));
     if ($this->config->item('hide_store_account_payments_in_reports')) {
         $this->db->where('store_account_payment', 0);
     }
     if ($this->params['sale_type'] == 'sales') {
         $this->db->where('payment_amount > 0');
     } elseif ($this->params['sale_type'] == 'returns') {
         $this->db->where('payment_amount < 0');
     }
     $this->db->where($this->db->dbprefix('sales') . '.deleted', 0);
     $this->db->order_by('sale_id, payment_type');
     $sales_payments = $this->db->get()->result_array();
     $payments_by_sale = array();
     foreach ($sales_payments as $row) {
         $payments_by_sale[$row['sale_id']][] = $row;
     }
     $payment_data = $this->Sale->get_payment_data($payments_by_sale, $sales_totals);
     $return = array('total' => 0);
     foreach ($payment_data as $payment) {
         $return['total'] += $payment['payment_amount'];
     }
     return $return;
 }
Esempio n. 5
0
 function excel_export()
 {
     $data = $this->Item->get_all($this->Item->count_all())->result_object();
     $this->load->helper('report');
     $header_row = $this->_excel_get_header_row();
     $header_row[] = lang('items_item_id');
     $rows[] = $header_row;
     foreach ($data as $r) {
         $row = array();
         $row[] = $r->item_number;
         $row[] = $r->product_id;
         $row[] = $r->name;
         $row[] = $r->category;
         $row[] = $r->supplier_id;
         $row[] = to_currency_no_money($r->cost_price, 10);
         $row[] = to_currency_no_money($r->unit_price);
         foreach ($this->Tier->get_all()->result() as $tier) {
             $tier_id = $tier->id;
             $tier_row = $this->Item->get_tier_price_row($tier_id, $r->item_id);
             $value = '';
             if (is_object($tier_row) && property_exists($tier_row, 'tier_id')) {
                 $value = $tier_row->unit_price !== NULL ? to_currency_no_money($tier_row->unit_price) : $tier_row->percent_off . '%';
             }
             $row[] = $value;
         }
         $row[] = $r->tax_included ? 'y' : '';
         $row[] = $r->is_service ? 'y' : '';
         $row[] = to_quantity($r->quantity, FALSE);
         $row[] = to_quantity($r->reorder_level, fALSE);
         $row[] = $r->description;
         $row[] = $r->allow_alt_description ? 'y' : '';
         $row[] = $r->is_serialized ? 'y' : '';
         $row[] = $r->size;
         $commission = '';
         if ($r->commission_fixed) {
             $commission = to_currency_no_money($r->commission_fixed);
         } elseif ($r->commission_percent) {
             $commission = to_currency_no_money($r->commission_percent) . '%';
         }
         $row[] = $commission;
         $row[] = $r->item_id;
         $rows[] = $row;
     }
     $content = array_to_spreadsheet($rows);
     force_download('items_export.' . ($this->config->item('spreadsheet_format') == 'XLSX' ? 'xlsx' : 'csv'), $content);
     exit;
 }
Esempio n. 6
0
					</td>
					<td>
					<?php 
    echo form_dropdown('payment_type', $payment_options, array(), 'id="payment_types"');
    ?>
					</td>
				</tr>
				<tr>
					<td><span id="amount_tendered_label"><?php 
    echo $this->lang->line('sales_amount_tendered') . ': ';
    ?>
</span>
					</td>
					<td>
				<?php 
    echo form_input(array('name' => 'amount_tendered', 'id' => 'amount_tendered', 'value' => to_currency_no_money($amount_due), 'size' => '10'));
    ?>
			</td>
				</tr>
			</table>
			<div class='small_button' id='add_payment_button'
				style='float: left; margin-top: 5px;'>
				<span><?php 
    echo $this->lang->line('sales_add_payment');
    ?>
</span>
			</div>
		</form>
		</div>

		<?php 
Esempio n. 7
0
    function save($items, $customer_id, $employee_id, $sold_by_employee_id, $comment, $show_comment_on_receipt, $payments, $sale_id = false, $suspended = 0, $cc_ref_no = '', $auth_code = '', $change_sale_date = false, $balance = 0, $store_account_payment = 0)
    {
        //we need to check the sale library for deleted taxes during sale
        $this->load->library('sale_lib');
        if (count($items) == 0) {
            return -1;
        }
        $payment_types = '';
        foreach ($payments as $payment_id => $payment) {
            $payment_types = $payment_types . $payment['payment_type'] . ': ' . to_currency($payment['payment_amount']) . '<br />';
        }
        $tier_id = $this->sale_lib->get_selected_tier_id();
        if (!$tier_id) {
            $tier_id = NULL;
        }
        $sales_data = array('customer_id' => $customer_id > 0 ? $customer_id : null, 'employee_id' => $employee_id, 'sold_by_employee_id' => $sold_by_employee_id, 'payment_type' => $payment_types, 'comment' => $comment, 'show_comment_on_receipt' => $show_comment_on_receipt ? $show_comment_on_receipt : 0, 'suspended' => $suspended, 'deleted' => 0, 'deleted_by' => NULL, 'cc_ref_no' => $cc_ref_no, 'auth_code' => $auth_code, 'location_id' => $this->Employee->get_logged_in_employee_current_location_id(), 'register_id' => $this->Employee->get_logged_in_employee_current_register_id(), 'store_account_payment' => $store_account_payment, 'tier_id' => $tier_id ? $tier_id : NULL);
        if ($sale_id) {
            $old_date = $this->get_info($sale_id)->row_array();
            $sales_data['sale_time'] = $old_date['sale_time'];
            if ($change_sale_date) {
                $sale_time = strtotime($change_sale_date);
                if ($sale_time !== FALSE) {
                    $sales_data['sale_time'] = date('Y-m-d H:i:s', strtotime($change_sale_date));
                }
            }
        } else {
            $sales_data['sale_time'] = date('Y-m-d H:i:s');
        }
        $this->db->query("SET autocommit=0");
        //Lock tables invovled in sale transaction so we don't have deadlock
        $this->db->query('LOCK TABLES ' . $this->db->dbprefix('customers') . ' WRITE, ' . $this->db->dbprefix('sales') . ' WRITE, 
		' . $this->db->dbprefix('store_accounts') . ' WRITE, ' . $this->db->dbprefix('sales_payments') . ' WRITE, ' . $this->db->dbprefix('sales_items') . ' WRITE, 
		' . $this->db->dbprefix('giftcards') . ' WRITE, ' . $this->db->dbprefix('location_items') . ' WRITE, 
		' . $this->db->dbprefix('inventory') . ' WRITE, ' . $this->db->dbprefix('sales_items_taxes') . ' WRITE,
		' . $this->db->dbprefix('sales_item_kits') . ' WRITE, ' . $this->db->dbprefix('sales_item_kits_taxes') . ' WRITE,' . $this->db->dbprefix('people') . ' READ,' . $this->db->dbprefix('items') . ' READ
		,' . $this->db->dbprefix('employees_locations') . ' READ,' . $this->db->dbprefix('locations') . ' READ, ' . $this->db->dbprefix('items_tier_prices') . ' READ
		, ' . $this->db->dbprefix('location_items_tier_prices') . ' READ, ' . $this->db->dbprefix('items_taxes') . ' READ, ' . $this->db->dbprefix('item_kits') . ' READ
		, ' . $this->db->dbprefix('location_item_kits') . ' READ, ' . $this->db->dbprefix('item_kit_items') . ' READ, ' . $this->db->dbprefix('employees') . ' READ , ' . $this->db->dbprefix('item_kits_tier_prices') . ' READ
		, ' . $this->db->dbprefix('location_item_kits_tier_prices') . ' READ, ' . $this->db->dbprefix('location_items_taxes') . ' READ
		, ' . $this->db->dbprefix('location_item_kits_taxes') . ' READ, ' . $this->db->dbprefix('item_kits_taxes') . ' READ');
        $store_account_payment_amount = 0;
        if ($store_account_payment) {
            $store_account_payment_amount = $this->sale_lib->get_total();
        }
        //Only update balance + store account payments if we are NOT an estimate (suspended = 2)
        if ($suspended != 2) {
            //Update customer store account balance
            if ($customer_id > 0 && $balance) {
                $this->db->set('balance', 'balance+' . $balance, false);
                $this->db->where('person_id', $customer_id);
                if (!$this->db->update('customers')) {
                    $this->db->query("ROLLBACK");
                    $this->db->query('UNLOCK TABLES');
                    return -1;
                }
            }
            //Update customer store account if payment made
            if ($customer_id > 0 && $store_account_payment_amount) {
                $this->db->set('balance', 'balance-' . $store_account_payment_amount, false);
                $this->db->where('person_id', $customer_id);
                if (!$this->db->update('customers')) {
                    $this->db->query("ROLLBACK");
                    $this->db->query('UNLOCK TABLES');
                    return -1;
                }
            }
        }
        $previous_store_account_amount = 0;
        if ($sale_id !== FALSE) {
            $previous_store_account_amount = $this->get_store_account_payment_total($sale_id);
        }
        if ($sale_id) {
            //Delete previoulsy sale so we can overwrite data
            if (!$this->delete($sale_id, true)) {
                $this->db->query("ROLLBACK");
                $this->db->query('UNLOCK TABLES');
                return -1;
            }
            $this->db->where('sale_id', $sale_id);
            if (!$this->db->update('sales', $sales_data)) {
                $this->db->query("ROLLBACK");
                $this->db->query('UNLOCK TABLES');
                return -1;
            }
        } else {
            if (!$this->db->insert('sales', $sales_data)) {
                $this->db->query("ROLLBACK");
                $this->db->query('UNLOCK TABLES');
                return -1;
            }
            $sale_id = $this->db->insert_id();
        }
        //Only update store account payments if we are NOT an estimate (suspended = 2)
        if ($suspended != 2) {
            //insert store account transaction
            if ($customer_id > 0 && $balance) {
                $store_account_transaction = array('customer_id' => $customer_id, 'sale_id' => $sale_id, 'comment' => $comment, 'transaction_amount' => $balance - $previous_store_account_amount, 'balance' => $this->Customer->get_info($customer_id)->balance, 'date' => date('Y-m-d H:i:s'));
                if ($balance - $previous_store_account_amount) {
                    if (!$this->db->insert('store_accounts', $store_account_transaction)) {
                        $this->db->query("ROLLBACK");
                        $this->db->query('UNLOCK TABLES');
                        return -1;
                    }
                }
            } elseif ($customer_id > 0 && $previous_store_account_amount) {
                $store_account_transaction = array('customer_id' => $customer_id, 'sale_id' => $sale_id, 'comment' => $comment, 'transaction_amount' => -$previous_store_account_amount, 'balance' => $this->Customer->get_info($customer_id)->balance, 'date' => date('Y-m-d H:i:s'));
                if (!$this->db->insert('store_accounts', $store_account_transaction)) {
                    $this->db->query("ROLLBACK");
                    $this->db->query('UNLOCK TABLES');
                    return -1;
                }
            }
            //insert store account payment transaction
            if ($customer_id > 0 && $store_account_payment) {
                $store_account_transaction = array('customer_id' => $customer_id, 'sale_id' => $sale_id, 'comment' => $comment, 'transaction_amount' => -$store_account_payment_amount, 'balance' => $this->Customer->get_info($customer_id)->balance, 'date' => date('Y-m-d H:i:s'));
                if (!$this->db->insert('store_accounts', $store_account_transaction)) {
                    $this->db->query("ROLLBACK");
                    $this->db->query('UNLOCK TABLES');
                    return -1;
                }
            }
        }
        $total_giftcard_payments = 0;
        foreach ($payments as $payment_id => $payment) {
            //Only update giftcard payments if we are NOT an estimate (suspended = 2)
            if ($suspended != 2) {
                if (substr($payment['payment_type'], 0, strlen(lang('sales_giftcard'))) == lang('sales_giftcard')) {
                    /* We have a gift card and we have to deduct the used value from the total value of the card. */
                    $splitpayment = explode(':', $payment['payment_type']);
                    $cur_giftcard_value = $this->Giftcard->get_giftcard_value($splitpayment[1]);
                    $this->Giftcard->update_giftcard_value($splitpayment[1], $cur_giftcard_value - $payment['payment_amount']);
                    $total_giftcard_payments += $payment['payment_amount'];
                }
            }
            $sales_payments_data = array('sale_id' => $sale_id, 'payment_type' => $payment['payment_type'], 'payment_amount' => $payment['payment_amount'], 'payment_date' => $payment['payment_date'], 'truncated_card' => $payment['truncated_card'], 'card_issuer' => $payment['card_issuer']);
            if (!$this->db->insert('sales_payments', $sales_payments_data)) {
                $this->db->query("ROLLBACK");
                $this->db->query('UNLOCK TABLES');
                return -1;
            }
        }
        $has_added_giftcard_value_to_cost_price = $total_giftcard_payments > 0 ? false : true;
        $store_account_item_id = $this->Item->get_store_account_item_id();
        foreach ($items as $line => $item) {
            if (isset($item['item_id'])) {
                $cur_item_info = $this->Item->get_info($item['item_id']);
                $cur_item_location_info = $this->Item_location->get_info($item['item_id']);
                if ($item['item_id'] != $store_account_item_id) {
                    $cost_price = $cur_item_location_info && $cur_item_location_info->cost_price ? $cur_item_location_info->cost_price : $cur_item_info->cost_price;
                } else {
                    $cost_price = $item['price'];
                }
                if (!$this->config->item('disable_subtraction_of_giftcard_amount_from_sales')) {
                    //Add to the cost price if we are using a giftcard as we have already recorded profit for sale of giftcard
                    if (!$has_added_giftcard_value_to_cost_price) {
                        $cost_price += $total_giftcard_payments / $item['quantity'];
                        $has_added_giftcard_value_to_cost_price = true;
                    }
                }
                $reorder_level = $cur_item_location_info && $cur_item_location_info->reorder_level ? $cur_item_location_info->reorder_level : $cur_item_info->reorder_level;
                if ($cur_item_info->tax_included) {
                    $item['price'] = get_price_for_item_excluding_taxes($item['item_id'], $item['price']);
                }
                $sales_items_data = array('sale_id' => $sale_id, 'item_id' => $item['item_id'], 'line' => $item['line'], 'description' => $item['description'], 'serialnumber' => $item['serialnumber'], 'quantity_purchased' => $item['quantity'], 'discount_percent' => $item['discount'], 'item_cost_price' => to_currency_no_money($cost_price, 10), 'item_unit_price' => $item['price'], 'commission' => get_commission_for_item($item['item_id'], $item['price'], $item['quantity'], $item['discount']));
                if (!$this->db->insert('sales_items', $sales_items_data)) {
                    $this->db->query("ROLLBACK");
                    $this->db->query('UNLOCK TABLES');
                    return -1;
                }
                //Only update giftcard payments if we are NOT an estimate (suspended = 2)
                if ($suspended != 2) {
                    //create giftcard from sales
                    if ($item['name'] == lang('sales_giftcard') && !$this->Giftcard->get_giftcard_id($item['description'])) {
                        $giftcard_data = array('giftcard_number' => $item['description'], 'value' => $item['price'], 'customer_id' => $customer_id > 0 ? $customer_id : null);
                        if (!$this->Giftcard->save($giftcard_data)) {
                            $this->db->query("ROLLBACK");
                            $this->db->query('UNLOCK TABLES');
                            return -1;
                        }
                    }
                }
                //Only do stock check + inventory update if we are NOT an estimate
                if ($suspended != 2) {
                    $stock_recorder_check = false;
                    $out_of_stock_check = false;
                    $email = false;
                    $message = '';
                    //checks if the quantity is greater than reorder level
                    if (!$cur_item_info->is_service && $cur_item_location_info->quantity > $reorder_level) {
                        $stock_recorder_check = true;
                    }
                    //checks if the quantity is greater than 0
                    if (!$cur_item_info->is_service && $cur_item_location_info->quantity > 0) {
                        $out_of_stock_check = true;
                    }
                    //Update stock quantity IF not a service
                    if (!$cur_item_info->is_service) {
                        $cur_item_location_info->quantity = $cur_item_location_info->quantity !== NULL ? $cur_item_location_info->quantity : 0;
                        if (!$this->Item_location->save_quantity($cur_item_location_info->quantity - $item['quantity'], $item['item_id'])) {
                            $this->db->query("ROLLBACK");
                            $this->db->query('UNLOCK TABLES');
                            return -1;
                        }
                    }
                    //Re-init $cur_item_location_info after updating quantity
                    $cur_item_location_info = $this->Item_location->get_info($item['item_id']);
                    //checks if the quantity is out of stock
                    if ($out_of_stock_check && $cur_item_location_info->quantity <= 0) {
                        $message = $cur_item_info->name . ' ' . lang('sales_is_out_stock') . ' ' . to_quantity($cur_item_location_info->quantity);
                        $email = true;
                    } else {
                        if ($stock_recorder_check && $cur_item_location_info->quantity <= $reorder_level) {
                            $message = $cur_item_info->name . ' ' . lang('sales_hits_reorder_level') . ' ' . to_quantity($cur_item_location_info->quantity);
                            $email = true;
                        }
                    }
                    //send email
                    if ($this->Location->get_info_for_key('receive_stock_alert') && $email) {
                        $this->load->library('email');
                        $config = array();
                        $config['mailtype'] = 'text';
                        $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($this->Location->get_info_for_key('stock_alert_email') ? $this->Location->get_info_for_key('stock_alert_email') : $this->Location->get_info_for_key('email'));
                        $this->email->subject(lang('sales_stock_alert_item_name') . $this->Item->get_info($item['item_id'])->name);
                        $this->email->message($message);
                        $this->email->send();
                    }
                    if (!$cur_item_info->is_service) {
                        $qty_buy = -$item['quantity'];
                        $sale_remarks = $this->config->item('sale_prefix') . ' ' . $sale_id;
                        $inv_data = array('trans_date' => date('Y-m-d H:i:s'), 'trans_items' => $item['item_id'], 'trans_user' => $employee_id, 'trans_comment' => $sale_remarks, 'trans_inventory' => $qty_buy, 'location_id' => $this->Employee->get_logged_in_employee_current_location_id());
                        if (!$this->Inventory->insert($inv_data)) {
                            $this->db->query("ROLLBACK");
                            $this->db->query('UNLOCK TABLES');
                            return -1;
                        }
                    }
                }
            } else {
                $cur_item_kit_info = $this->Item_kit->get_info($item['item_kit_id']);
                $cur_item_kit_location_info = $this->Item_kit_location->get_info($item['item_kit_id']);
                $cost_price = $cur_item_kit_location_info && $cur_item_kit_location_info->cost_price ? $cur_item_kit_location_info->cost_price : $cur_item_kit_info->cost_price;
                if (!$this->config->item('disable_subtraction_of_giftcard_amount_from_sales')) {
                    //Add to the cost price if we are using a giftcard as we have already recorded profit for sale of giftcard
                    if (!$has_added_giftcard_value_to_cost_price) {
                        $cost_price += $total_giftcard_payments / $item['quantity'];
                        $has_added_giftcard_value_to_cost_price = true;
                    }
                }
                if ($cur_item_kit_info->tax_included) {
                    $item['price'] = get_price_for_item_kit_excluding_taxes($item['item_kit_id'], $item['price']);
                }
                $sales_item_kits_data = array('sale_id' => $sale_id, 'item_kit_id' => $item['item_kit_id'], 'line' => $item['line'], 'description' => $item['description'], 'quantity_purchased' => $item['quantity'], 'discount_percent' => $item['discount'], 'item_kit_cost_price' => $cost_price === NULL ? 0.0 : to_currency_no_money($cost_price, 10), 'item_kit_unit_price' => $item['price'], 'commission' => get_commission_for_item_kit($item['item_kit_id'], $item['price'], $item['quantity'], $item['discount']));
                if (!$this->db->insert('sales_item_kits', $sales_item_kits_data)) {
                    $this->db->query("ROLLBACK");
                    $this->db->query('UNLOCK TABLES');
                    return -1;
                }
                foreach ($this->Item_kit_items->get_info($item['item_kit_id']) as $item_kit_item) {
                    $cur_item_info = $this->Item->get_info($item_kit_item->item_id);
                    $cur_item_location_info = $this->Item_location->get_info($item_kit_item->item_id);
                    $reorder_level = $cur_item_location_info && $cur_item_location_info->reorder_level !== NULL ? $cur_item_location_info->reorder_level : $cur_item_info->reorder_level;
                    //Only do stock check + inventory update if we are NOT an estimate
                    if ($suspended != 2) {
                        $stock_recorder_check = false;
                        $out_of_stock_check = false;
                        $email = false;
                        $message = '';
                        //checks if the quantity is greater than reorder level
                        if (!$cur_item_info->is_service && $cur_item_location_info->quantity > $reorder_level) {
                            $stock_recorder_check = true;
                        }
                        //checks if the quantity is greater than 0
                        if (!$cur_item_info->is_service && $cur_item_location_info->quantity > 0) {
                            $out_of_stock_check = true;
                        }
                        //Update stock quantity IF not a service item and the quantity for item is NOT NULL
                        if (!$cur_item_info->is_service) {
                            $cur_item_location_info->quantity = $cur_item_location_info->quantity !== NULL ? $cur_item_location_info->quantity : 0;
                            if (!$this->Item_location->save_quantity($cur_item_location_info->quantity - $item['quantity'] * $item_kit_item->quantity, $item_kit_item->item_id)) {
                                $this->db->query("ROLLBACK");
                                $this->db->query('UNLOCK TABLES');
                                return -1;
                            }
                        }
                        //Re-init $cur_item_location_info after updating quantity
                        $cur_item_location_info = $this->Item_location->get_info($item_kit_item->item_id);
                        //checks if the quantity is out of stock
                        if ($out_of_stock_check && !$cur_item_info->is_service && $cur_item_location_info->quantity <= 0) {
                            $message = $cur_item_info->name . ' ' . lang('sales_is_out_stock') . ' ' . to_quantity($cur_item_location_info->quantity);
                            $email = true;
                        } else {
                            if ($stock_recorder_check && $cur_item_location_info->quantity <= $reorder_level) {
                                $message = $cur_item_info->name . ' ' . lang('sales_hits_reorder_level') . ' ' . to_quantity($cur_item_location_info->quantity);
                                $email = true;
                            }
                        }
                        //send email
                        if ($this->Location->get_info_for_key('receive_stock_alert') && $email) {
                            $this->load->library('email');
                            $config = array();
                            $config['mailtype'] = 'text';
                            $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($this->Location->get_info_for_key('stock_alert_email') ? $this->Location->get_info_for_key('stock_alert_email') : $this->Location->get_info_for_key('email'));
                            $this->email->subject(lang('sales_stock_alert_item_name') . $cur_item_info->name);
                            $this->email->message($message);
                            $this->email->send();
                        }
                        if (!$cur_item_info->is_service) {
                            $qty_buy = -$item['quantity'] * $item_kit_item->quantity;
                            $sale_remarks = $this->config->item('sale_prefix') . ' ' . $sale_id;
                            $inv_data = array('trans_date' => date('Y-m-d H:i:s'), 'trans_items' => $item_kit_item->item_id, 'trans_user' => $employee_id, 'trans_comment' => $sale_remarks, 'trans_inventory' => $qty_buy, 'location_id' => $this->Employee->get_logged_in_employee_current_location_id());
                            if (!$this->Inventory->insert($inv_data)) {
                                $this->db->query("ROLLBACK");
                                $this->db->query('UNLOCK TABLES');
                                return -1;
                            }
                        }
                    }
                }
            }
            $customer = $this->Customer->get_info($customer_id);
            if ($customer_id == -1 or $customer->taxable) {
                if (isset($item['item_id'])) {
                    foreach ($this->Item_taxes_finder->get_info($item['item_id']) as $row) {
                        $tax_name = $row['percent'] . '% ' . $row['name'];
                        //Only save sale if the tax has NOT been deleted
                        if (!in_array($tax_name, $this->sale_lib->get_deleted_taxes())) {
                            $query_result = $this->db->insert('sales_items_taxes', array('sale_id' => $sale_id, 'item_id' => $item['item_id'], 'line' => $item['line'], 'name' => $row['name'], 'percent' => $row['percent'], 'cumulative' => $row['cumulative']));
                            if (!$query_result) {
                                $this->db->query("ROLLBACK");
                                $this->db->query('UNLOCK TABLES');
                                return -1;
                            }
                        }
                    }
                } else {
                    foreach ($this->Item_kit_taxes_finder->get_info($item['item_kit_id']) as $row) {
                        $tax_name = $row['percent'] . '% ' . $row['name'];
                        //Only save sale if the tax has NOT been deleted
                        if (!in_array($tax_name, $this->sale_lib->get_deleted_taxes())) {
                            $query_result = $this->db->insert('sales_item_kits_taxes', array('sale_id' => $sale_id, 'item_kit_id' => $item['item_kit_id'], 'line' => $item['line'], 'name' => $row['name'], 'percent' => $row['percent'], 'cumulative' => $row['cumulative']));
                            if (!$query_result) {
                                $this->db->query("ROLLBACK");
                                $this->db->query('UNLOCK TABLES');
                                return -1;
                            }
                        }
                    }
                }
            }
        }
        $this->db->query("COMMIT");
        $this->db->query('UNLOCK TABLES');
        return $sale_id;
    }
 function get_total()
 {
     $total = 0;
     foreach ($this->get_cart() as $item) {
         $total += $item['price'] * $item['quantity'] - $item['price'] * $item['quantity'] * $item['discount'] / 100;
     }
     foreach ($this->get_taxes() as $tax) {
         $total += $tax;
     }
     return to_currency_no_money($total);
 }
Esempio n. 9
0
 function get_total($sale_id = false)
 {
     $total = 0;
     foreach ($this->get_cart() as $item) {
         $price_to_use = $this->_get_price_for_item_in_cart($item, $sale_id);
         $total += $price_to_use * $item['quantity'] - $price_to_use * $item['quantity'] * $item['discount'] / 100;
     }
     foreach ($this->get_taxes($sale_id) as $tax) {
         $total += $tax;
     }
     $total = $this->CI->config->item('round_cash_on_sales') && $this->is_sale_cash_payment() ? round_to_nearest_05($total) : $total;
     return to_currency_no_money($total);
 }
Esempio n. 10
0
 public function get_total()
 {
     $total = 0;
     foreach ($this->get_cart() as $item) {
         $total += $item['price'] * $item['quantity'] - $item['price'] * $item['quantity'] * $item['discount'] / 100;
     }
     $discount = 0;
     if ($this->CI->session->userdata('discounting') == 'checked') {
         $discount = $this->get_discount();
         if ($discount > 0) {
             $discount = $total * $discount / 100;
         }
     }
     if ($this->get_taxing()) {
         foreach ($this->get_taxes() as $tax) {
             $total += $tax;
         }
     }
     return to_currency_no_money($total - $discount);
 }
Esempio n. 11
0
            echo form_dropdown('locations[' . $location->location_id . '][tier_type][' . $tier->id . ']', $tier_type_options, $location_tier_prices[$location->location_id][$tier->id] !== FALSE && $location_tier_prices[$location->location_id][$tier->id]->unit_price === NULL ? 'percent_off' : 'unit_price');
            ?>
									</div>
								</div>

							<?php 
        }
        ?>

							<div class="form-group">
							<?php 
        echo form_label(lang('items_promo_price') . ':', '', array('class' => 'col-sm-3 col-md-3 col-lg-2 control-label wide'));
        ?>
							    <div class="col-sm-9 col-md-9 col-lg-10">
							    <?php 
        echo form_input(array('name' => 'locations[' . $location->location_id . '][promo_price]', 'size' => '8', 'class' => 'form-control form-inps', 'value' => $location_items[$location->location_id]->item_id !== '' && $location_items[$location->location_id]->promo_price ? to_currency_no_money($location_items[$location->location_id]->promo_price, 10) : ''));
        ?>
							    </div>
							</div>

								<div class="form-group offset1">
								<?php 
        echo form_label(lang('items_promo_start_date') . ':', '', array('class' => 'col-sm-3 col-md-3 col-lg-2 control-label text-info wide'));
        ?>
								<div class="col-sm-9 col-md-9 col-lg-10">
						
								<div class="input-group date datepicker" data-date="<?php 
        echo $location_items[$location->location_id]->item_id !== '' && $location_items[$location->location_id]->start_date ? date(get_date_format(), strtotime($location_items[$location->location_id]->start_date)) : '';
        ?>
" data-date-format=<?php 
        echo json_encode(get_js_date_format());
Esempio n. 12
0
 public function finish_cc_processing()
 {
     $return_code = $this->sales_controller->input->get("ReturnCode");
     //TODO
     //Check return code 0
     //Check return code 101: Decline
     //Only make verify payment call with the above return codes
     $service_url = (!defined("ENVIRONMENT") or ENVIRONMENT == 'development') ? 'https://hc.mercurydev.net/hcws/hcservice.asmx?WSDL' : 'https://hc.mercurypay.com/hcws/hcservice.asmx?WSDL';
     $parameters = array('request' => array('MerchantID' => $this->sales_controller->Location->get_info_for_key('merchant_id'), 'PaymentID' => $this->sales_controller->input->get('PaymentID'), 'Password' => $this->sales_controller->Location->get_info_for_key('merchant_password')));
     $client = new SoapClient($service_url, array('trace' => TRUE));
     $result = $client->VerifyPayment($parameters);
     $response_code = $result->VerifyPaymentResult->ResponseCode;
     $status = $result->VerifyPaymentResult->Status;
     $total_amount = $result->VerifyPaymentResult->Amount;
     $auth_amount = $result->VerifyPaymentResult->AuthAmount;
     $auth_code = $result->VerifyPaymentResult->AuthCode;
     $acq_ref_data = $result->VerifyPaymentResult->AcqRefData;
     $ref_no = $result->VerifyPaymentResult->RefNo;
     $token = $result->VerifyPaymentResult->Token;
     $masked_account = $result->VerifyPaymentResult->MaskedAccount;
     $process_data = $result->VerifyPaymentResult->ProcessData;
     $card_issuer = $result->VerifyPaymentResult->CardType;
     if ($response_code == 0 && $status == 'Approved') {
         $result = $client->AcknowledgePayment($parameters);
         $response_code = $result->AcknowledgePaymentResult;
         $this->sales_controller->session->set_userdata('ref_no', $ref_no);
         $this->sales_controller->session->set_userdata('auth_code', $auth_code);
         if ($response_code == 0 && $auth_amount == $total_amount) {
             $this->sales_controller->session->set_userdata('masked_account', $masked_account);
             $this->sales_controller->session->set_userdata('card_issuer', $card_issuer);
             $info = $this->sales_controller->Customer->get_info($this->sales_controller->sale_lib->get_customer());
             //We want to save/update card:
             //1. User decides to save credit card info
             //2. We already have a saved credit and need to update
             if (($this->sales_controller->sale_lib->get_save_credit_card_info() or $info->cc_token && $info->cc_preview) && $this->sales_controller->sale_lib->get_customer() != -1) {
                 $person_info = array('person_id' => $this->sales_controller->sale_lib->get_customer());
                 $customer_info = array('cc_token' => $token, 'cc_preview' => $masked_account, 'card_issuer' => $card_issuer);
                 $this->sales_controller->Customer->save($person_info, $customer_info, $this->sales_controller->sale_lib->get_customer());
             }
             //If the sale payments cover the total, redirect to complete (receipt)
             if ($this->sales_controller->_payments_cover_total()) {
                 redirect(site_url('sales/complete'));
             } else {
                 $invoice_number = substr(date('mdy') . (time() - strtotime("today")) . $this->sales_controller->Employee->get_logged_in_employee_info()->person_id, 0, 16);
                 $credit_card_amount = to_currency_no_money($this->sales_controller->sale_lib->get_payment_amount(lang('sales_credit')));
                 $partial_transaction = array('AuthCode' => $auth_code, 'Frequency' => 'OneTime', 'Memo' => 'PHP POS ' . APPLICATION_VERSION, 'Invoice' => $invoice_number, 'MerchantID' => $this->sales_controller->Location->get_info_for_key('merchant_id'), 'OperatorID' => (!defined("ENVIRONMENT") or ENVIRONMENT == 'development') ? 'test' : $this->sales_controller->Employee->get_logged_in_employee_info()->person_id, 'PurchaseAmount' => $credit_card_amount, 'RefNo' => $ref_no, 'Token' => $token, 'AcqRefData' => $acq_ref_data, 'ProcessData' => $process_data);
                 $this->sales_controller->sale_lib->delete_payment($this->sales_controller->sale_lib->get_payment_ids(lang('sales_credit')));
                 $this->sales_controller->sale_lib->add_payment(lang('sales_partial_credit'), $credit_card_amount, FALSE, $masked_account, $card_issuer);
                 $this->sales_controller->sale_lib->add_partial_transaction($partial_transaction);
                 $this->sales_controller->_reload(array('warning' => lang('sales_credit_card_partially_charged_please_complete_sale_with_another_payment_method')), false);
             }
         } elseif ($response_code == 0 && $auth_amount < $total_amount) {
             $invoice_number = substr(date('mdy') . (time() - strtotime("today")) . $this->sales_controller->Employee->get_logged_in_employee_info()->person_id, 0, 16);
             $partial_transaction = array('AuthCode' => $auth_code, 'Frequency' => 'OneTime', 'Memo' => 'PHP POS ' . APPLICATION_VERSION, 'Invoice' => $invoice_number, 'MerchantID' => $this->sales_controller->Location->get_info_for_key('merchant_id'), 'OperatorID' => (!defined("ENVIRONMENT") or ENVIRONMENT == 'development') ? 'test' : $this->sales_controller->Employee->get_logged_in_employee_info()->person_id, 'PurchaseAmount' => $auth_amount, 'RefNo' => $ref_no, 'Token' => $token, 'AcqRefData' => $acq_ref_data, 'ProcessData' => $process_data);
             $this->sales_controller->sale_lib->delete_payment($this->sales_controller->sale_lib->get_payment_ids(lang('sales_credit')));
             $this->sales_controller->sale_lib->add_payment(lang('sales_partial_credit'), $auth_amount, FALSE, $masked_account, $card_issuer);
             $this->sales_controller->sale_lib->add_partial_transaction($partial_transaction);
             $this->sales_controller->_reload(array('warning' => lang('sales_credit_card_partially_charged_please_complete_sale_with_another_payment_method')), false);
         } else {
             $this->sales_controller->_reload(array('error' => lang('sales_acknowledge_payment_failed_please_contact_support')), false);
         }
     } else {
         $client->AcknowledgePayment($parameters);
         $this->sales_controller->_reload(array('error' => $result->VerifyPaymentResult->StatusMessage . ': ' . $result->VerifyPaymentResult->DisplayMessage), false);
     }
 }
Esempio n. 13
0
    function calculate_and_update_average_cost_price_for_item($item_id, $current_receivings_items_data)
    {
        //Dont calculate averages unless we receive quanitity > 0
        if ($current_receivings_items_data['quantity_purchased'] > 0) {
            $cost_price_avg = false;
            $averaging_method = $this->config->item('averaging_method');
            $cur_item_info = $this->Item->get_info($item_id);
            $cur_item_location_info = $this->Item_location->get_info($item_id);
            if ($averaging_method == 'moving_average') {
                $current_cost_price = $cur_item_location_info && $cur_item_location_info->cost_price ? $cur_item_location_info->cost_price : $cur_item_info->cost_price;
                $current_quantity = $cur_item_location_info->quantity;
                $current_inventory_value = $current_cost_price * $current_quantity;
                $received_cost_price = $current_receivings_items_data['item_unit_price'] * (1 - $current_receivings_items_data['discount_percent'] / 100);
                $received_quantity = $current_receivings_items_data['quantity_purchased'];
                $new_inventory_value = $received_cost_price * $received_quantity;
                $cost_price_avg = ($current_inventory_value + $new_inventory_value) / ($current_quantity + $received_quantity);
            } elseif ($averaging_method == 'historical_average') {
                if ($cur_item_location_info && $cur_item_location_info->cost_price) {
                    $location_id = $this->Employee->get_logged_in_employee_current_location_id();
                    $result = $this->db->query("SELECT ROUND((SUM(item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)) / SUM(quantity_purchased),10) as cost_price_average \n\t\t\t\t\tFROM " . $this->db->dbprefix('receivings_items') . ' ' . 'JOIN ' . $this->db->dbprefix('receivings') . ' ON ' . $this->db->dbprefix('receivings') . '.receiving_id = ' . $this->db->dbprefix('receivings_items') . '.receiving_id ' . 'WHERE quantity_purchased > 0 and item_id=' . $this->db->escape($item_id) . ' and location_id = ' . $this->db->escape($location_id))->result();
                } else {
                    $result = $this->db->query("SELECT ROUND((SUM(item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)) / SUM(quantity_purchased),10) as cost_price_average \n\t\t\t\t\tFROM " . $this->db->dbprefix('receivings_items') . '
					WHERE quantity_purchased > 0 and item_id=' . $this->db->escape($item_id))->result();
                }
                $cost_price_avg = $result[0]->cost_price_average;
            }
            if ($cost_price_avg !== FALSE) {
                $cost_price_avg = to_currency_no_money($cost_price_avg, 10);
                //If we have a location cost price, update that value
                if ($cur_item_location_info && $cur_item_location_info->cost_price) {
                    $item_location_data = array('cost_price' => $cost_price_avg);
                    $this->Item_location->save($item_location_data, $item_id);
                } else {
                    //Update cost price
                    $item_data = array('cost_price' => $cost_price_avg);
                    $this->Item->save($item_data, $item_id);
                }
            }
        }
    }
Esempio n. 14
0
echo form_label($this->lang->line('items_unit_price'), 'unit_price', array('class' => 'required control-label col-xs-3'));
?>
			<div class='col-xs-4'>
				<div class="input-group input-group-sm">
					<?php 
if (!currency_side()) {
    ?>
						<span class="input-group-addon input-sm"><b><?php 
    echo $this->config->item('currency_symbol');
    ?>
</b></span>
					<?php 
}
?>
					<?php 
echo form_input(array('name' => 'unit_price', 'id' => 'unit_price', 'class' => 'form-control input-sm', 'value' => to_currency_no_money($item_info->unit_price)));
?>
					<?php 
if (currency_side()) {
    ?>
						<span class="input-group-addon input-sm"><b><?php 
    echo $this->config->item('currency_symbol');
    ?>
</b></span>
					<?php 
}
?>
				</div>
			</div>
		</div>
Esempio n. 15
0
											<label accesskey="y" for="payment_types"><?php 
        echo lang('sales_add_payment');
        ?>
:</label>
										</td>
										<td>
											<?php 
        echo form_dropdown('payment_type', $payment_options, $this->config->item('default_payment_type'), 'id="payment_types" class="input-medium"');
        ?>
										</td>
									</tr>
									<tr id="mpt_bottom" >
										<td id="tender" colspan="2">
											<div class="input-append">
												<?php 
        echo form_input(array('name' => 'amount_tendered', 'id' => 'amount_tendered', 'value' => to_currency_no_money($amount_due), 'class' => 'input-medium input_mediums', 'accesskey' => 'p'));
        ?>
												<input type="button" class="btn btn-primary" id="add_payment_button" value="<?php 
        echo lang('sales_add_payment');
        ?>
" />
											</div>

										</td>
									</tr>
									 
								</table>
							</form>
						</div>
						<?php 
    }
Esempio n. 16
0
 function get_total()
 {
     $total = $this->calculate_subtotal();
     foreach ($this->get_taxes() as $tax) {
         $total = bcadd($total, $tax, 4);
     }
     return to_currency_no_money($total);
 }
Esempio n. 17
0
										<label class='col-sm-4 text-left'><?php 
echo $this->lang->line('sales_nomerkartu');
?>
</label>
										<div class='col-sm-8'>
											<input id="nomorkartu" class="form-control ac_input" type="text" size="15" value="" name="nomorkartu" autocomplete="off">
										</div>
									</div>
									<div class="form-group">
										<label class='col-sm-4 text-left'><?php 
echo $this->lang->line('sales_amount_tendered');
?>
</label>
										<div class='col-sm-8'>
											<?php 
echo form_input(array('name' => 'amount_tendered', 'id' => 'amount_tendered', 'value' => to_currency_no_money($amount_due), 'class' => 'form-control', 'tabindex' => 4));
?>
											<br><div id='add_payment_button' >
												<button class='btn btn-block btn-success btn-sm'><?php 
echo $this->lang->line('sales_add_payment');
?>
</button>
											</div>
										</div>
									</div>
									<div class="form-group">
										<label class='col-sm-4 text-left'><?php 
echo $this->lang->line('sales_payments_total');
?>
</label>
										<div class='col-sm-8'>
Esempio n. 18
0
function get_commission_for_item_kit($item_kit_id, $price, $quantity, $discount)
{
    $CI =& get_instance();
    $CI->load->library('sale_lib');
    $employee_id = $CI->sale_lib->get_sold_by_employee_id();
    $sales_person_info = $CI->Employee->get_info($employee_id);
    $employee_id = $CI->Employee->get_logged_in_employee_info()->person_id;
    $logged_in_employee_info = $CI->Employee->get_info($employee_id);
    $item_kit_info = $CI->Item_kit->get_info($item_kit_id);
    if ($item_kit_info->commission_fixed > 0) {
        return $quantity * $item_kit_info->commission_fixed;
    } elseif ($item_kit_info->commission_percent > 0) {
        return to_currency_no_money(($price * $quantity - $price * $quantity * $discount / 100) * ($item_kit_info->commission_percent / 100));
    } elseif ($CI->config->item('select_sales_person_during_sale')) {
        if ($sales_person_info->commission_percent > 0) {
            return to_currency_no_money(($price * $quantity - $price * $quantity * $discount / 100) * ((double) $sales_person_info->commission_percent / 100));
        }
        return to_currency_no_money(($price * $quantity - $price * $quantity * $discount / 100) * ((double) $CI->config->item('commission_default_rate') / 100));
    } elseif ($logged_in_employee_info->commission_percent > 0) {
        return to_currency_no_money(($price * $quantity - $price * $quantity * $discount / 100) * ((double) $logged_in_employee_info->commission_percent / 100));
    } else {
        return to_currency_no_money(($price * $quantity - $price * $quantity * $discount / 100) * ((double) $CI->config->item('commission_default_rate') / 100));
    }
}
Esempio n. 19
0
function check_payment_type_giftcard()
{
	if ($("#payment_types").val() == "<?php 
echo $this->lang->line('sales_giftcard');
?>
")
	{
		$("#amount_tendered_label").html("<?php 
echo $this->lang->line('sales_giftcard_number');
?>
");
		$("#amount_tendered:enabled").val('').focus();
	}
	else
	{
		$("#amount_tendered_label").html("<?php 
echo $this->lang->line('sales_amount_tendered');
?>
");
		$("#amount_tendered:enabled").val('<?php 
echo to_currency_no_money($amount_due);
?>
');
	}
}

</script>

<?php 
$this->load->view("partial/footer");
Esempio n. 20
0
echo form_label($this->lang->line('customers_total'), 'total', array('class' => 'control-label col-xs-3'));
?>
			<div class="col-xs-4">
				<div class="input-group input-group-sm">
					<?php 
if (!currency_side()) {
    ?>
						<span class="input-group-addon input-sm"><b><?php 
    echo $this->config->item('currency_symbol');
    ?>
</b></span>
					<?php 
}
?>
					<?php 
echo form_input(array('name' => 'total', 'id' => 'total', 'class' => 'form-control input-sm', 'value' => to_currency_no_money($total), 'disabled' => ''));
?>
					<?php 
if (currency_side()) {
    ?>
						<span class="input-group-addon input-sm"><b><?php 
    echo $this->config->item('currency_symbol');
    ?>
</b></span>
					<?php 
}
?>
				</div>
			</div>
		</div>
		
Esempio n. 21
0
 public function getSummaryData()
 {
     if ($this->params['matched_items_only']) {
         $this->db->select('sales_items_temp.sale_id, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit,sum(quantity_purchased) as items_purchased', false);
         $this->db->from('sales_items_temp');
         $this->db->where('sales_items_temp.deleted', 0);
         $this->_searchSalesQueryParams();
         $this->db->group_by('sale_id');
         if ($this->config->item('hide_store_account_payments_from_report_totals')) {
             $this->db->where('store_account_payment', 0);
         }
         $result = $this->db->get()->result_array();
         $return = array('subtotal' => 0, 'total' => 0, 'tax' => 0, 'profit' => 0);
         foreach ($result as $row) {
             $return['subtotal'] += to_currency_no_money($row['subtotal'], 2);
             $return['total'] += to_currency_no_money($row['total'], 2);
             $return['tax'] += to_currency_no_money($row['tax'], 2);
             $return['profit'] += to_currency_no_money($row['profit'], 2);
         }
         if (!$this->Employee->has_module_action_permission('reports', 'show_profit', $this->Employee->get_logged_in_employee_info()->person_id)) {
             unset($return['profit']);
         }
         return $return;
     } else {
         $sale_ids = $this->_getMatchingSaleIds();
         $this->db->select('sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(profit) as profit', false);
         $this->db->from('sales_items_temp');
         $this->db->group_by('sale_id');
         if ($this->config->item('hide_store_account_payments_from_report_totals')) {
             $this->db->where('store_account_payment', 0);
         }
         if (!empty($sale_ids)) {
             $this->db->where_in('sale_id', $sale_ids);
         } else {
             $this->db->where('sale_id', -1);
         }
         $return = array('subtotal' => 0, 'total' => 0, 'tax' => 0, 'profit' => 0);
         $result = $this->db->get()->result_array();
         foreach ($result as $row) {
             $return['subtotal'] += to_currency_no_money($row['subtotal'], 2);
             $return['total'] += to_currency_no_money($row['total'], 2);
             $return['tax'] += to_currency_no_money($row['tax'], 2);
             $return['profit'] += to_currency_no_money($row['profit'], 2);
         }
         if (!$this->Employee->has_module_action_permission('reports', 'show_profit', $this->Employee->get_logged_in_employee_info()->person_id)) {
             unset($return['profit']);
         }
         return $return;
     }
 }
Esempio n. 22
0
        echo form_input(array('class' => 'form-control form-inps', 'name' => 'locations[' . $location->location_id . '][unit_price]', 'size' => '8', 'value' => $location_item_kits[$location->location_id]->item_kit_id !== '' && $location_item_kits[$location->location_id]->unit_price ? to_currency_no_money($location_item_kits[$location->location_id]->unit_price, 10) : ''));
        ?>
							</div>
						</div>

						<?php 
        foreach ($tiers as $tier) {
            ?>
	
							<div class="form-group">
								<?php 
            echo form_label($tier->name . ':', $tier->name, array('class' => 'col-sm-3 col-md-3 col-lg-2 control-label '));
            ?>
								<div class="col-sm-9 col-md-9 col-lg-10">
								<?php 
            echo form_input(array('class' => 'form-control form-inps margin10', 'name' => 'locations[' . $location->location_id . '][item_tier][' . $tier->id . ']', 'size' => '8', 'value' => $location_tier_prices[$location->location_id][$tier->id] !== FALSE ? $location_tier_prices[$location->location_id][$tier->id]->unit_price != NULL ? to_currency_no_money($location_tier_prices[$location->location_id][$tier->id]->unit_price, 10) : $location_tier_prices[$location->location_id][$tier->id]->percent_off : ''));
            ?>

								<?php 
            echo form_dropdown('locations[' . $location->location_id . '][tier_type][' . $tier->id . ']', $tier_type_options, $location_tier_prices[$location->location_id][$tier->id] !== FALSE && $location_tier_prices[$location->location_id][$tier->id]->unit_price === NULL ? 'percent_off' : 'unit_price');
            ?>
								</div>
							</div>

						<?php 
        }
        ?>
					</div>
					<div class="form-group override-taxes-container">
						<?php 
        echo form_label(lang('items_override_default_tax') . ':', '', array('class' => 'col-sm-3 col-md-3 col-lg-2 control-label  wide'));
Esempio n. 23
0
		total+= .01 * $("#pennies").val();
		
		$("#closing_amount").val(parseFloat(Math.round(total * 100) / 100).toFixed(2));
	}
	
	$("#100s, #50s, #20s, #10s, #5s, #1s, #half_dollars,#quarters, #dimes,#nickels,#pennies").change(calculate_total);
	$("#100s, #50s, #20s, #10s, #5s, #1s, #half_dollars,#quarters, #dimes,#nickels,#pennies").keyup(calculate_total);
});
function check_amount()
{

	if($('#closing_amount').val()=='<?php 
echo $closeout;
?>
' || $('#closing_amount').val()=='<?php 
echo to_currency_no_money($closeout);
?>
')
		{
			$('#closing_amount_form').submit();	
		}
		else
		{
			if(confirm(<?php 
echo json_encode(lang('closing_amount_not_equal'));
?>
))
			{
				$('#closing_amount_form').submit();			
			}
			
Esempio n. 24
0
							<?php 
        if ($items_module_allowed && $mode != 'requisition') {
            ?>
								<td><?php 
            echo form_input(array('name' => 'price', 'class' => 'form-control input-sm', 'value' => to_currency_no_money($item['price'])));
            ?>
</td>
							<?php 
        } else {
            ?>
								<td>
									<?php 
            echo $item['price'];
            ?>
									<?php 
            echo form_hidden('price', to_currency_no_money($item['price']));
            ?>
								</td>
							<?php 
        }
        ?>
							
							<td><?php 
        echo form_input(array('name' => 'quantity', 'class' => 'form-control input-sm', 'value' => to_quantity_decimals($item['quantity'])));
        ?>
</td>
							<?php 
        if ($item['receiving_quantity'] > 1) {
            ?>
								<td><?php 
            echo 'x' . to_quantity_decimals($item['receiving_quantity']);
Esempio n. 25
0
        echo anchor("receivings/delete_item/{$line}", '<i class="fa fa-trash-o fa fa-2x text-error"></i>', array('class' => 'delete_item'));
        ?>
												</td>
												<td id="reg_item_name"><?php 
        echo H($item['name']);
        echo $item['size'] ? ' (' . H($item['size']) . ')' : '';
        ?>
</td>
											<?php 
        if ($items_module_allowed) {
            ?>
												
												<td id="reg_item_price">
													<?php 
            echo form_open("receivings/edit_item/{$line}", array('class' => 'line_item_form', 'autocomplete' => 'off'));
            echo form_input(array('name' => 'price', 'value' => to_currency_no_money($item['price'], 10), 'class' => 'input-small', 'id' => 'price_' . $line));
            ?>
														</form>
												</td>
											<?php 
        } else {
            ?>
												<td id="reg_item_price">
													<?php 
            echo $item['price'];
            ?>
													<?php 
            echo form_open("receivings/edit_item/{$line}", array('class' => 'line_item_form', 'autocomplete' => 'off'));
            echo form_hidden('price', $item['price']);
            ?>
													</form>
Esempio n. 26
0
								<?php 
        echo $item['name'];
        ?>
<br /> <?php 
        echo '[' . to_quantity_decimals($item['in_stock']) . ' in ' . $item['stock_name'] . ']';
        ?>
								<?php 
        echo form_hidden('location', $item['item_location']);
        ?>
							</td>

							<?php 
        if ($items_module_allowed && $mode != 'requisition') {
            ?>
								<td><?php 
            echo form_input(array('name' => 'price', 'class' => 'form-control input-sm', 'value' => to_currency_no_money($item['price'])));
            ?>
</td>
							<?php 
        } else {
            ?>
								<td>
									<?php 
            echo $item['price'];
            ?>
									<?php 
            echo form_hidden('price', $item['price']);
            ?>
								</td>
							<?php 
        }
Esempio n. 27
0
 function _payments_cover_total()
 {
     $total_payments = 0;
     foreach ($this->sale_lib->get_payments() as $payment) {
         $total_payments += $payment['payment_amount'];
     }
     /* Changed the conditional to account for floating point rounding */
     if ($this->sale_lib->get_mode() == 'sale' && to_currency_no_money($this->sale_lib->get_total()) - $total_payments > 1.0E-6) {
         return false;
     }
     return true;
 }
Esempio n. 28
0
 function complete()
 {
     $data['cart'] = $this->sale_lib->get_cart();
     $data['subtotal'] = $this->sale_lib->get_subtotal();
     $data['taxes'] = $this->sale_lib->get_taxes();
     $data['total'] = $this->sale_lib->get_total();
     $data['receipt_title'] = $this->lang->line('sales_receipt');
     $data['transaction_time'] = date('m/d/Y h:i:s a');
     $customer_id = $this->sale_lib->get_customer();
     $employee_id = $this->Employee->get_logged_in_employee_info()->person_id;
     $comment = $this->input->post('comment');
     $emp_info = $this->Employee->get_info($employee_id);
     $payment_type = $this->input->post('payment_type');
     $data['payment_type'] = $this->input->post('payment_type');
     //Alain Multiple payments
     $data['payments'] = $this->sale_lib->get_payments();
     $data['amount_change'] = to_currency($this->sale_lib->get_amount_due() * -1);
     $data['employee'] = $emp_info->first_name . ' ' . $emp_info->last_name;
     if ($customer_id != -1) {
         $cust_info = $this->Customer->get_info($customer_id);
         $data['customer'] = $cust_info->first_name . ' ' . $cust_info->last_name;
     }
     $total_payments = 0;
     foreach ($data['payments'] as $payment) {
         $total_payments += $payment['payment_amount'];
     }
     /* Changed the conditional to account for floating point rounding */
     if ($this->sale_lib->get_mode() == 'sale' && to_currency_no_money($data['total']) - $total_payments > 1.0E-6) {
         $data['error'] = $this->lang->line('sales_payment_not_cover_total');
         $this->_reload($data);
         return false;
     }
     //SAVE sale to database
     $data['sale_id'] = 'POS ' . $this->Sale->save($data['cart'], $customer_id, $employee_id, $comment, $data['payments']);
     if ($data['sale_id'] == 'POS -1') {
         $data['error_message'] = $this->lang->line('sales_transaction_failed');
     }
     $this->load->view("sales/receipt", $data);
     $this->sale_lib->clear_all();
 }
Esempio n. 29
0
 function get_total()
 {
     $total = $this->calculate_subtotal(TRUE);
     if (!$this->CI->config->config['tax_included']) {
         foreach ($this->get_taxes() as $tax) {
             $total = bcadd($total, $tax, PRECISION);
         }
     }
     return to_currency_no_money($total);
 }
Esempio n. 30
0
echo form_label(lang('giftcards_giftcard_number') . ':', 'name', array('class' => 'required wide col-sm-3 col-md-3 col-lg-2 control-label required wide'));
?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								<?php 
echo form_input(array('name' => 'giftcard_number', 'size' => '8', 'id' => 'giftcard_number', 'class' => 'form-control form-inps', 'value' => $giftcard_info->giftcard_number));
?>
							</div>
						</div>

						<div class="form-group">	
							<?php 
echo form_label(lang('giftcards_card_value') . ':', 'name', array('class' => 'required wide col-sm-3 col-md-3 col-lg-2 control-label required wide'));
?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								<?php 
echo form_input(array('name' => 'value', 'size' => '8', 'class' => 'form-control form-inps ', 'id' => 'value', 'value' => $giftcard_info->value ? to_currency_no_money($giftcard_info->value, 10) : ''));
?>
							</div>
						</div>
						
						<div class="form-group">	
							<?php 
echo form_label(lang('giftcards_customer_name') . ':', 'customer_id', array('class' => 'wide col-sm-3 col-md-3 col-lg-2 control-label required wide'));
?>
							<div class="col-sm-9 col-md-9 col-lg-10">
								<?php 
echo form_dropdown('customer_id', $customers, $giftcard_info->customer_id, 'id="customer_id" class="form-control"');
?>
							</div>
						</div>