Example #1
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;
    }
Example #2
0
            echo $item['cost_price_preview'];
            ?>
											</td>
											<?php 
        }
        ?>
											
												<td id="reg_item_qty">
												<?php 
        echo form_open("receivings/edit_item/{$line}", array('class' => 'line_item_form', 'autocomplete' => 'off'));
        echo form_input(array('name' => 'quantity', 'value' => to_quantity($item['quantity']), 'class' => 'input-small', 'id' => 'quantity_' . $line));
        ?>
													</form>
												</td>
												<td class="text text-warning sales_stock" id="reg_item_stock" ><?php 
        echo property_exists($cur_item_location_info, 'quantity') ? to_quantity($cur_item_location_info->quantity) : '';
        ?>
</td>
												<td id="reg_item_discount"><?php 
        echo form_open("receivings/edit_item/{$line}", array('class' => 'line_item_form', 'autocomplete' => 'off'));
        echo form_input(array('name' => 'discount', 'value' => $item['discount'], 'class' => 'input-small', 'id' => 'discount_' . $line));
        ?>
													</form>	
												</td>
												<td id="reg_item_total"><?php 
        echo to_currency($item['price'] * $item['quantity'] - $item['price'] * $item['quantity'] * $item['discount'] / 100, 10);
        ?>
</td>
											</tr>
											<tr id="reg_item_bottom" >
												<td id="reg_item_descrip_label"><?php 
Example #3
0
 function detailed_commissions($start_date, $end_date, $employee_id, $sale_type, $employee_type, $export_excel = 0, $offset = 0)
 {
     $this->check_action_permission('view_employees');
     $start_date = rawurldecode($start_date);
     $end_date = rawurldecode($end_date);
     $this->load->model('reports/Detailed_commissions');
     $model = $this->Detailed_commissions;
     $model->setParams(array('start_date' => $start_date, 'end_date' => $end_date, 'employee_id' => $employee_id, 'sale_type' => $sale_type, 'employee_type' => $employee_type, 'offset' => $offset, 'export_excel' => $export_excel));
     $this->Sale->create_sales_items_temp_table(array('start_date' => $start_date, 'end_date' => $end_date, 'employee_id' => $employee_id, 'sale_type' => $sale_type));
     $config = array();
     $config['base_url'] = site_url("reports/detailed_commissions/" . rawurlencode($start_date) . '/' . rawurlencode($end_date) . "/{$employee_id}/{$sale_type}/{$employee_type}/{$export_excel}");
     $config['total_rows'] = $model->getTotalRows();
     $config['per_page'] = $this->config->item('number_of_items_per_page') ? (int) $this->config->item('number_of_items_per_page') : 20;
     $config['uri_segment'] = 9;
     $this->pagination->initialize($config);
     $headers = $model->getDataColumns();
     $report_data = $model->getData();
     $summary_data = array();
     $details_data = array();
     foreach ($report_data['summary'] as $key => $row) {
         $summary_data_row = array();
         $summary_data_row[] = array('data' => anchor('sales/edit/' . $row['sale_id'], lang('common_edit') . ' ' . $row['sale_id'], array('target' => '_blank')), 'align' => 'left');
         $summary_data_row[] = array('data' => date(get_date_format() . '-' . get_time_format(), strtotime($row['sale_time'])), 'align' => 'left');
         $summary_data_row[] = array('data' => to_quantity($row['items_purchased']), 'align' => 'left');
         $summary_data_row[] = array('data' => $row['customer_name'], 'align' => 'left');
         $summary_data_row[] = array('data' => to_currency($row['subtotal']), 'align' => 'right');
         $summary_data_row[] = array('data' => to_currency($row['total']), 'align' => 'right');
         $summary_data_row[] = array('data' => to_currency($row['tax']), 'align' => 'right');
         if ($this->has_profit_permission) {
             $summary_data_row[] = array('data' => to_currency($row['profit']), 'align' => 'right');
         }
         $summary_data_row[] = array('data' => to_currency($row['commission']), 'align' => 'right');
         $summary_data_row[] = array('data' => $row['payment_type'], 'align' => 'right');
         $summary_data_row[] = array('data' => $row['comment'], 'align' => 'right');
         $summary_data[$key] = $summary_data_row;
         foreach ($report_data['details'][$key] as $drow) {
             $details_data_row = array();
             $details_data_row[] = array('data' => isset($drow['item_name']) ? $drow['item_name'] : $drow['item_kit_name'], 'align' => 'left');
             $details_data_row[] = array('data' => $drow['category'], 'align' => 'left');
             $details_data_row[] = array('data' => $drow['serialnumber'], 'align' => 'left');
             $details_data_row[] = array('data' => $drow['description'], 'align' => 'left');
             $details_data_row[] = array('data' => to_quantity($drow['quantity_purchased']), 'align' => 'left');
             $details_data_row[] = array('data' => to_currency($drow['subtotal']), 'align' => 'right');
             $details_data_row[] = array('data' => to_currency($drow['total']), 'align' => 'right');
             $details_data_row[] = array('data' => to_currency($drow['tax']), 'align' => 'right');
             if ($this->has_profit_permission) {
                 $details_data_row[] = array('data' => to_currency($drow['profit']), 'align' => 'right');
             }
             $details_data_row[] = array('data' => to_currency($drow['commission']), 'align' => 'right');
             $details_data_row[] = array('data' => $drow['discount_percent'] . '%', 'align' => 'left');
             $details_data[$key][] = $details_data_row;
         }
     }
     $employee_info = $this->Employee->get_info($employee_id);
     $data = array("title" => $employee_info->first_name . ' ' . $employee_info->last_name . ' ' . lang('reports_report'), "subtitle" => date(get_date_format(), strtotime($start_date)) . '-' . date(get_date_format(), strtotime($end_date)), "headers" => $model->getDataColumns(), "summary_data" => $summary_data, "details_data" => $details_data, "overall_summary_data" => $model->getSummaryData(), "export_excel" => $export_excel, "pagination" => $this->pagination->create_links());
     $this->load->view("reports/tabular_details", $data);
 }
Example #4
0
</th>
					<th><?php 
echo lang('items_quantity');
?>
</th>
				</tr>
				
				<?php 
foreach ($suspended_receivings as $receiving_item) {
    ?>
					<tr>
						<td style="text-align: center;"><?php 
    echo anchor('receivings/receipt/' . $receiving_item['receiving_id'], 'RECV ' . $receiving_item['receiving_id'], array('target' => '_blank'));
    ?>
</td>
						<td style="text-align: center;"><?php 
    echo to_quantity($receiving_item['quantity_purchased']);
    ?>
</td>
					</tr>
				<?php 
}
?>
			</table>
		</div>
	</div>
</div>



Example #5
0
                <?php 
$current_employee_editing_self = $this->Employee->get_logged_in_employee_info()->person_id == $person_info->person_id;
echo form_open('employees/save/' . $person_info->person_id, array('id' => 'employee_form', 'class' => 'form-horizontal'));
?>

                    <?php 
$this->load->view("people/form_basic_info");
?>

<!--                <div class="form-group">	
                        <?php 
echo form_label(lang('config_commission_default_rate') . ' (' . lang('common_commission_help') . '):', 'commission_default_rate', 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('name' => 'commission_percent', 'id' => 'commission_percent', 'value' => to_quantity($person_info->commission_percent, FALSE)));
?>
%
                    </div>
                </div>-->

                <legend class="page-header text-info"> &nbsp; &nbsp; <?php 
echo lang("employees_login_info");
?>
</legend>
                <div class="form-group">	
                        <?php 
echo form_label(lang('employees_username') . '* :', 'username', 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 
Example #6
0
?>
 <?php 
echo lang('sales_total');
?>

---------------------------------------
<?php 
foreach (array_reverse($cart, true) as $line => $item) {
    echo character_limiter($item['name'], 14, '...');
    echo strlen($item['name']) < 14 ? str_repeat(' ', 14 - strlen($item['name'])) : '';
    ?>
 <?php 
    echo str_replace('&#8209;', '-', to_currency($item['price']));
    ?>
 <?php 
    echo to_quantity($item['quantity']);
    if ($discount_exists) {
        echo ' ' . $item['discount'];
    }
    ?>
 <?php 
    echo str_replace('&#8209;', '-', to_currency($item['price'] * $item['quantity'] - $item['price'] * $item['quantity'] * $item['discount'] / 100));
    ?>

  <?php 
    echo $item['description'];
    ?>
  <?php 
    echo isset($item['serialnumber']) ? $item['serialnumber'] : '';
    ?>
	
Example #7
0
foreach ($this->Inventory->get_inventory_data_for_item($item_info->item_id)->result_array() as $row) {
    ?>
										<tr  align="center">
											<td><?php 
    echo date(get_date_format() . ' ' . get_time_format(), strtotime($row['trans_date']));
    ?>
</td>
											<td>
												<?php 
    $person_id = $row['trans_user'];
    $employee = $this->Employee->get_info($person_id);
    echo $employee->first_name . " " . $employee->last_name;
    ?>
											</td>
											<td align="right"><?php 
    echo to_quantity($row['trans_inventory']);
    ?>
</td>
											
											<?php 
    $row['trans_comment'] = preg_replace('/' . $this->config->item('sale_prefix') . ' ([0-9]+)/', anchor('sales/receipt/$1', $row['trans_comment']), $row['trans_comment']);
    $row['trans_comment'] = preg_replace('/RECV ([0-9]+)/', anchor('receivings/receipt/$1', $row['trans_comment']), $row['trans_comment']);
    ?>
											<td><?php 
    echo $row['trans_comment'];
    ?>
</td>
										</tr>
									<?php 
}
?>
Example #8
0
				</tr>
			<?php 
            $current_category = $item['category'];
        }
        ?>
			<tr>
			<td style="text-align:left;"><?php 
        echo $item['name'];
        ?>
</td>
			<td style="text-align:left;"><?php 
        echo to_currency($item['item_kit_unit_price']);
        ?>
</td>
			<td style='text-align:left;'><?php 
        echo to_quantity($item['quantity_purchased']);
        ?>
</td>
			<?php 
        if ($discount_exists) {
            ?>
			<td style='text-align:left;'><?php 
            echo $item['discount_percent'];
            ?>
</td>
			<?php 
        }
        ?>
			<td style='text-align:right;'><?php 
        echo to_currency($item['item_kit_unit_price'] * $item['quantity_purchased'] - $item['item_kit_unit_price'] * $item['quantity_purchased'] * $item['discount_percent'] / 100);
        ?>
Example #9
0
if (!($item_kit_info->commission_percent > 0) && !($item_kit_info->commission_fixed > 0)) {
    echo 'hidden';
}
?>
">
			<p style="margin-top: 10px;"><?php 
echo lang('common_commission_help');
?>
</p>
				<div class="form-group">
				<?php 
echo form_label(lang('reports_commission'), 'commission_value', 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' => 'commission_value', 'size' => '8', 'class' => 'form-control margin10 form-inps', 'value' => $item_kit_info->commission_fixed > 0 ? to_quantity($item_kit_info->commission_fixed, FALSE) : to_quantity($item_kit_info->commission_percent, FALSE)));
?>

				<?php 
echo form_dropdown('commission_type', array('percent' => lang('common_percentage'), 'fixed' => lang('common_fixed_amount')), $item_kit_info->commission_fixed > 0 ? 'fixed' : 'percent');
?>
				</div>
			</div>

		</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'));
?>
			
Example #10
0
					
					<?php 
    if ($this->Location->count_all() > 1) {
        ?>
						<div class="form-group reorder-input <?php 
        if ($item_info->is_service) {
            echo 'hidden';
        }
        ?>
">
						<?php 
        echo form_label(lang('items_reorder_level') . ':', '', 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 . '][reorder_level]', 'value' => $location_items[$location->location_id]->item_id !== '' && $location_items[$location->location_id]->reorder_level !== NULL ? to_quantity($location_items[$location->location_id]->reorder_level) : '', 'class' => 'form-control form-inps'));
        ?>
							</div>
						</div>
					<?php 
    }
    ?>
					<div class="form-group">
					<?php 
    echo form_label(lang('items_location_at_store') . ':', '', 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 . '][location]', 'class' => 'form-control form-inps', 'value' => $location_items[$location->location_id]->item_id !== '' ? $location_items[$location->location_id]->location : ''));
    ?>
						</div>
Example #11
0
function get_item_data_row($item, $controller)
{
    $CI =& get_instance();
    static $has_cost_price_permission;
    if (!$has_cost_price_permission) {
        $has_cost_price_permission = $CI->Employee->has_module_action_permission('items', 'see_cost_price', $CI->Employee->get_logged_in_employee_info()->person_id);
    }
    $controller_name = strtolower(get_class($CI));
    $avatar_url = $item->image_id ? site_url('app_files/view/' . $item->image_id) : false;
    $table_data_row = '<tr>';
    $table_data_row .= "<td width='3%'><input type='checkbox' id='item_{$item->item_id}' value='" . $item->item_id . "'/></td>";
    $table_data_row .= '<td width="10%">' . $item->item_id . '</td>';
    $table_data_row .= '<td width="13%">' . H($item->item_number) . '</td>';
    $table_data_row .= '<td width="13%"><a href="' . site_url('home/view_item_modal') . '/' . $item->item_id . '" data-toggle="modal" data-target="#myModal">' . H($item->name) . '</a></td>';
    $table_data_row .= '<td width="9%">' . H($item->category) . '</td>';
    $table_data_row .= '<td width="9%">' . $item->size . '</td>';
    if ($has_cost_price_permission) {
        $table_data_row .= '<td width="9%" align="right">' . to_currency($item->location_cost_price ? $item->location_cost_price : $item->cost_price, 10) . '</td>';
    }
    $table_data_row .= '<td width="9%" align="right">' . to_currency($item->location_unit_price ? $item->location_unit_price : $item->unit_price, 10) . '</td>';
    $table_data_row .= '<td width="9%">' . to_quantity($item->quantity) . '</td>';
    if (!$item->is_service) {
        $table_data_row .= '<td width="12%">' . anchor($controller_name . "/inventory/{$item->item_id}/", lang('common_inv'), array('class' => '', 'title' => lang($controller_name . '_count'))) . '</td>';
        //inventory details
    } else {
        $table_data_row .= '<td width="12%">&nbsp;</td>';
    }
    $table_data_row .= '<td width="4%" class="rightmost">' . anchor($controller_name . "/clone_item/{$item->item_id}\t", lang('items_clone'), array('class' => '', 'title' => lang($controller_name . '_update'))) . '</td>';
    $table_data_row .= '<td width="4%" class="rightmost">' . anchor($controller_name . "/view/{$item->item_id}/2\t", lang('common_edit'), array('class' => '', 'title' => lang($controller_name . '_update'))) . '</td>';
    if ($avatar_url) {
        $table_data_row .= "<td width='55px' align='center'><a href='{$avatar_url}' class='rollover'><img id='avatar' src='" . $avatar_url . "' class='img-polaroid' width='45' /></a></td>";
    }
    $table_data_row .= '</tr>';
    return $table_data_row;
}
Example #12
0
								</tr>
								
								<?php 
    foreach ($recent_sales as $sale) {
        ?>
									<tr>
										<td align="center"><?php 
        echo date(get_date_format() . ' @ ' . get_time_format(), strtotime($sale['sale_time']));
        ?>
</td>
										<td align="center"><?php 
        echo $sale['payment_type'];
        ?>
</td>
										<td align="center"><?php 
        echo to_quantity($sale['items_purchased']);
        ?>
</td>
										<td align="center"><?php 
        echo anchor('sales/receipt/' . $sale['sale_id'], lang('sales_receipt'), array('target' => '_blank'));
        ?>
</td>
									</tr>
								<?php 
    }
    ?>
							</table>
						</div>
						<?php 
}
?>
Example #13
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;
 }