Fix to Gift card totals issue #159

Various indentation adjustments
This commit is contained in:
FrancescoUK
2015-09-19 09:22:24 +01:00
parent ad948ac81e
commit dc45b77573
8 changed files with 172 additions and 137 deletions

View File

@@ -1,6 +1,7 @@
<?php
require_once ("secure_area.php");
require_once ("interfaces/idata_controller.php");
class Giftcards extends Secure_area implements iData_controller
{
function __construct()
@@ -10,13 +11,13 @@ class Giftcards extends Secure_area implements iData_controller
function index($limit_from=0)
{
$data['controller_name']=$this->get_controller_name();
$data['form_width']=$this->get_form_width();
$data['controller_name'] = $this->get_controller_name();
$data['form_width'] = $this->get_form_width();
$lines_per_page = $this->Appconfig->get('lines_per_page');
$giftcards = $this->Giftcard->get_all($lines_per_page,$limit_from);
$data['links'] = $this->_initialize_pagination($this->Giftcard,$lines_per_page,$limit_from);
$data['manage_table']=get_giftcards_manage_table($giftcards,$this);
$this->load->view('giftcards/manage',$data);
$giftcards = $this->Giftcard->get_all($lines_per_page, $limit_from);
$data['links'] = $this->_initialize_pagination($this->Giftcard, $lines_per_page, $limit_from);
$data['manage_table'] = get_giftcards_manage_table($giftcards, $this);
$this->load->view('giftcards/manage', $data);
}
function search()
@@ -26,8 +27,8 @@ class Giftcards extends Secure_area implements iData_controller
$lines_per_page = $this->Appconfig->get('lines_per_page');
$giftcards = $this->Giftcard->search($search, $lines_per_page, $limit_from);
$total_rows = $this->Giftcard->get_found_rows($search);
$links = $this->_initialize_pagination($this->Giftcard,$lines_per_page, $limit_from, $total_rows);
$data_rows=get_giftcards_manage_table_data_rows($giftcards,$this);
$links = $this->_initialize_pagination($this->Giftcard, $lines_per_page, $limit_from, $total_rows);
$data_rows = get_giftcards_manage_table_data_rows($giftcards, $this);
echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links));
}
@@ -36,7 +37,7 @@ class Giftcards extends Secure_area implements iData_controller
*/
function suggest()
{
$suggestions = $this->Giftcard->get_search_suggestions($this->input->post('q'),$this->input->post('limit'));
$suggestions = $this->Giftcard->get_search_suggestions($this->input->post('q'), $this->input->post('limit'));
echo implode("\n",$suggestions);
}
@@ -45,14 +46,14 @@ class Giftcards extends Secure_area implements iData_controller
*/
function person_search()
{
$suggestions = $this->Customer->get_customer_search_suggestions($this->input->post('q'),$this->input->post('limit'));
$suggestions = $this->Customer->get_customer_search_suggestions($this->input->post('q'), $this->input->post('limit'));
echo implode("\n",$suggestions);
}
function get_row()
{
$giftcard_id = $this->input->post('row_id');
$data_row=get_giftcard_data_row($this->Giftcard->get_info($giftcard_id),$this);
$data_row = get_giftcard_data_row($this->Giftcard->get_info($giftcard_id), $this);
echo $data_row;
}
@@ -61,7 +62,7 @@ class Giftcards extends Secure_area implements iData_controller
$giftcard_info = $this->Giftcard->get_info($giftcard_id);
$person_name=$giftcard_id > 0? $giftcard_info->first_name . ' ' . $giftcard_info->last_name : '';
$data['selected_person'] = $giftcard_id > 0 && isset($giftcard_info->person_id) ? $giftcard_info->person_id . "|" . $person_name : "";
$data['giftcard_number']= $giftcard_id > 0 ? $giftcard_info->giftcard_number : $this->Giftcard->get_max_number()->giftcard_number + 1;
$data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : $this->Giftcard->get_max_number()->giftcard_number + 1;
$data['giftcard_info'] = $giftcard_info;
$this->load->view("giftcards/form",$data);
}
@@ -70,9 +71,9 @@ class Giftcards extends Secure_area implements iData_controller
{
$giftcard_data = array(
'record_time' => date('Y-m-d H:i:s'),
'giftcard_number'=>$this->input->post('giftcard_number',TRUE),
'value'=>$this->input->post('value',TRUE),
'person_id'=>$this->input->post('person_id',TRUE)?$this->input->post('person_id'):NULL
'giftcard_number'=>$this->input->post('giftcard_number', TRUE),
'value'=>$this->input->post('value', TRUE),
'person_id'=>$this->input->post('person_id', TRUE) ? $this->input->post('person_id') : NULL
);
if( $this->Giftcard->save( $giftcard_data, $giftcard_id ) )
@@ -80,20 +81,20 @@ class Giftcards extends Secure_area implements iData_controller
//New giftcard
if($giftcard_id==-1)
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('giftcards_successful_adding').' '.
$giftcard_data['giftcard_number'],'giftcard_id'=>$giftcard_data['giftcard_id']));
echo json_encode(array('success'=>true, 'message'=>$this->lang->line('giftcards_successful_adding').' '.
$giftcard_data['giftcard_number'], 'giftcard_id'=>$giftcard_data['giftcard_id']));
$giftcard_id = $giftcard_data['giftcard_id'];
}
else //previous giftcard
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('giftcards_successful_updating').' '.
$giftcard_data['giftcard_number'],'giftcard_id'=>$giftcard_id));
echo json_encode(array('success'=>true, 'message'=>$this->lang->line('giftcards_successful_updating').' '.
$giftcard_data['giftcard_number'], 'giftcard_id'=>$giftcard_id));
}
}
else//failure
{
echo json_encode(array('success'=>false,'message'=>$this->lang->line('giftcards_error_adding_updating').' '.
$giftcard_data['giftcard_number'],'giftcard_id'=>-1));
$giftcard_data['giftcard_number'], 'giftcard_id'=>-1));
}
}
@@ -103,12 +104,12 @@ class Giftcards extends Secure_area implements iData_controller
if($this->Giftcard->delete_list($giftcards_to_delete))
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('giftcards_successful_deleted').' '.
count($giftcards_to_delete).' '.$this->lang->line('giftcards_one_or_multiple')));
echo json_encode(array('success'=>true, 'message'=>$this->lang->line('giftcards_successful_deleted').' '.
count($giftcards_to_delete).' '.$this->lang->line('giftcards_one_or_multiple')));
}
else
{
echo json_encode(array('success'=>false,'message'=>$this->lang->line('giftcards_cannot_be_deleted')));
echo json_encode(array('success'=>false, 'message'=>$this->lang->line('giftcards_cannot_be_deleted')));
}
}

View File

@@ -408,8 +408,7 @@ class Items extends Secure_area implements iData_controller
{
$success &= $this->Item_quantity->save($location_detail, $item_id, $location_data['location_id']);
$inv_data = array
(
$inv_data = array(
'trans_date'=>date('Y-m-d H:i:s'),
'trans_items'=>$item_id,
'trans_user'=>$employee_id,
@@ -417,6 +416,7 @@ class Items extends Secure_area implements iData_controller
'trans_comment'=>$this->lang->line('items_manually_editing_of_quantity'),
'trans_inventory'=>$updated_quantity - $item_quantity->quantity
);
$success &= $this->Inventory->insert($inv_data);
}
}
@@ -473,8 +473,7 @@ class Items extends Secure_area implements iData_controller
$employee_id=$this->Employee->get_logged_in_employee_info()->person_id;
$cur_item_info = $this->Item->get_info($item_id);
$location_id = $this->input->post('stock_location');
$inv_data = array
(
$inv_data = array(
'trans_date'=>date('Y-m-d H:i:s'),
'trans_items'=>$item_id,
'trans_user'=>$employee_id,
@@ -482,16 +481,17 @@ class Items extends Secure_area implements iData_controller
'trans_comment'=>$this->input->post('trans_comment'),
'trans_inventory'=>$this->input->post('newquantity')
);
$this->Inventory->insert($inv_data);
//Update stock quantity
$item_quantity= $this->Item_quantity->get_item_quantity($item_id,$location_id);
$item_quantity_data = array(
'item_id'=>$item_id,
'location_id'=>$location_id,
'quantity'=>$item_quantity->quantity + $this->input->post('newquantity')
'item_id'=>$item_id,
'location_id'=>$location_id,
'quantity'=>$item_quantity->quantity + $this->input->post('newquantity')
);
if($this->Item_quantity->save($item_quantity_data,$item_id,$location_id))
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_updating').' '.
@@ -668,13 +668,14 @@ class Items extends Secure_area implements iData_controller
);
$this->Item_quantity->save($item_quantity_data, $item_data['item_id'], $location_id);
$excel_data = array (
$excel_data = array(
'trans_items'=>$item_data['item_id'],
'trans_user'=>$employee_id,
'trans_comment'=>$comment,
'trans_location'=>$data[$col],
'trans_inventory'=>$data[$col + 1]
);
$this->Inventory->insert($excel_data);
unset($allowed_locations[$location_id]);
}

View File

@@ -33,8 +33,8 @@ class Sales extends Secure_area
$location_id = 'all';
$inputs = array('start_date' => $start_date_formatter->format('Y-m-d'), 'end_date' => $end_date_formatter->format('Y-m-d'),
'sale_type' => $sale_type, 'location_id' => $location_id, 'only_invoices' => $only_invoices, 'lines_per_page' => $lines_per_page,
'limit_from' => $limit_from, 'only_cash' => $only_cash);
'sale_type' => $sale_type, 'location_id' => $location_id, 'only_invoices' => $only_invoices,
'lines_per_page' => $lines_per_page, 'limit_from' => $limit_from, 'only_cash' => $only_cash);
$sales = $this->Sale->get_all($inputs);
$payments = $this->Sale->get_payments_summary($inputs);
$data['only_invoices'] = $only_invoices;
@@ -43,7 +43,9 @@ class Sales extends Secure_area
$data['links'] = $this->_initialize_pagination($this->Sale, $lines_per_page, $limit_from, count($sales), 'manage', $only_invoices);
$data['manage_table'] = get_sales_manage_table($sales, $this);
$data['payments_summary'] = get_sales_manage_payments_summary($payments, $sales, $this);
$this->load->view($data['controller_name'] . '/manage', $data);
$this->_remove_duplicate_cookies();
}
@@ -53,7 +55,8 @@ class Sales extends Secure_area
$sale_id = $this->input->post('row_id');
$sale_info = $this->Sale->get_info($sale_id)->result_array();
$data_row=get_sales_manage_sale_data_row($sale_info[0],$this);
$data_row = get_sales_manage_sale_data_row($sale_info[0],$this);
echo $data_row;
}

View File

@@ -70,7 +70,7 @@ class Barcode_lib
try
{
$barcode = $this->get_barcode_instance($barcode_config['barcode_type']);
$barcode_content = $barcode_config['barcode_content'] !== "id" && isset($item['item_number']) ? $item['item_number'] : $item['item_id'];
$barcode->setData($barcode_content);
$barcode->setQuality($barcode_config['barcode_quality']);

View File

@@ -4,20 +4,20 @@ class Giftcard extends CI_Model
/*
Determines if a given giftcard_id is an giftcard
*/
function exists( $giftcard_id )
function exists($giftcard_id)
{
$this->db->from('giftcards');
$this->db->where('giftcard_id',$giftcard_id);
$this->db->where('deleted',0);
$query = $this->db->get();
$this->db->where('giftcard_id', $giftcard_id);
$this->db->where('deleted', 0);
return ($query->num_rows()==1);
return ($this->db->get()->num_rows()==1);
}
function get_max_number ( )
function get_max_number()
{
$this->db->select_max('giftcard_number');
$query = $this->db->get('giftcards');
return $query->row();
}
@@ -25,25 +25,29 @@ class Giftcard extends CI_Model
{
return $this->db->count_all('giftcards');
}
/*
Returns all the giftcards
*/
function get_all($rows=0, $limit_from=0)
{
$this->db->from('giftcards');
$this->db->join('people','people.person_id=giftcards.person_id', 'left');
$this->db->where('deleted',0);
$this->db->order_by("giftcard_number");
if ($rows > 0) {
$this->db->join('people', 'people.person_id=giftcards.person_id', 'left');
$this->db->where('deleted', 0);
$this->db->order_by('giftcard_number');
if ($rows > 0)
{
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
function count_all()
{
$this->db->from('giftcards');
$this->db->where('deleted',0);
$this->db->where('deleted', 0);
return $this->db->count_all_results();
}
@@ -54,8 +58,8 @@ class Giftcard extends CI_Model
{
$this->db->from('giftcards');
$this->db->join('people', 'people.person_id = giftcards.person_id', 'left');
$this->db->where('giftcard_id',$giftcard_id);
$this->db->where('deleted',0);
$this->db->where('giftcard_id', $giftcard_id);
$this->db->where('deleted', 0);
$query = $this->db->get();
@@ -66,7 +70,7 @@ class Giftcard extends CI_Model
else
{
//Get empty base parent object, as $giftcard_id is NOT an giftcard
$giftcard_obj=new stdClass();
$giftcard_obj = new stdClass();
//Get all the fields from giftcards table
$fields = $this->db->list_fields('giftcards');
@@ -86,8 +90,8 @@ class Giftcard extends CI_Model
function get_giftcard_id($giftcard_number)
{
$this->db->from('giftcards');
$this->db->where('giftcard_number',$giftcard_number);
$this->db->where('deleted',0);
$this->db->where('giftcard_number', $giftcard_number);
$this->db->where('deleted', 0);
$query = $this->db->get();
@@ -105,38 +109,43 @@ class Giftcard extends CI_Model
function get_multiple_info($giftcard_ids)
{
$this->db->from('giftcards');
$this->db->where_in('giftcard_id',$giftcard_ids);
$this->db->where('deleted',0);
$this->db->order_by("giftcard_number", "asc");
$this->db->where_in('giftcard_id', $giftcard_ids);
$this->db->where('deleted', 0);
$this->db->order_by('giftcard_number', 'asc');
return $this->db->get();
}
/*
Inserts or updates a giftcard
*/
function save(&$giftcard_data,$giftcard_id=false)
function save(&$giftcard_data, $giftcard_id=false)
{
if (!$giftcard_id or !$this->exists($giftcard_id))
{
if($this->db->insert('giftcards',$giftcard_data))
if($this->db->insert('giftcards', $giftcard_data))
{
$giftcard_data['giftcard_id']=$this->db->insert_id();
$giftcard_data['giftcard_id'] = $this->db->insert_id();
return true;
}
return false;
}
$this->db->where('giftcard_id', $giftcard_id);
return $this->db->update('giftcards',$giftcard_data);
}
/*
Updates multiple giftcards at once
*/
function update_multiple($giftcard_data,$giftcard_ids)
function update_multiple($giftcard_data, $giftcard_ids)
{
$this->db->where_in('giftcard_id',$giftcard_ids);
return $this->db->update('giftcards',$giftcard_data);
$this->db->where_in('giftcard_id', $giftcard_ids);
return $this->db->update('giftcards', $giftcard_data);
}
/*
@@ -145,6 +154,7 @@ class Giftcard extends CI_Model
function delete($giftcard_id)
{
$this->db->where('giftcard_id', $giftcard_id);
return $this->db->update('giftcards', array('deleted' => 1));
}
@@ -153,21 +163,22 @@ class Giftcard extends CI_Model
*/
function delete_list($giftcard_ids)
{
$this->db->where_in('giftcard_id',$giftcard_ids);
$this->db->where_in('giftcard_id', $giftcard_ids);
return $this->db->update('giftcards', array('deleted' => 1));
}
/*
Get search suggestions to find giftcards
*/
function get_search_suggestions($search,$limit=25)
function get_search_suggestions($search, $limit=25)
{
$suggestions = array();
$this->db->from('giftcards');
$this->db->like('giftcard_number', $search);
$this->db->where('deleted',0);
$this->db->order_by("giftcard_number", "asc");
$this->db->where('deleted', 0);
$this->db->order_by('giftcard_number', 'asc');
$by_number = $this->db->get();
foreach($by_number->result() as $row)
@@ -176,12 +187,12 @@ class Giftcard extends CI_Model
}
$this->db->from('customers');
$this->db->join('people','customers.person_id=people.person_id', 'left');
$this->db->like("first_name",$this->db->escape_like_str($search));
$this->db->or_like("last_name",$this->db->escape_like_str($search));
$this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search));
$this->db->where("deleted","0");
$this->db->order_by("last_name", "asc");
$this->db->join('people', 'customers.person_id = people.person_id', 'left');
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_like("last_name", $this->db->escape_like_str($search));
$this->db->or_like("CONCAT(`first_name`, ' ' , `last_name`)", $this->db->escape_like_str($search));
$this->db->where('deleted', 0);
$this->db->order_by('last_name', 'asc');
$by_name = $this->db->get();
foreach($by_name->result() as $row)
@@ -192,8 +203,9 @@ class Giftcard extends CI_Model
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
$suggestions = array_slice($suggestions, 0, $limit);
}
return $suggestions;
}
@@ -206,12 +218,12 @@ class Giftcard extends CI_Model
$this->db->select('person_id');
$this->db->from('people');
$this->db->like('person_id',$this->db->escape_like_str($search));
$this->db->or_like('first_name',$this->db->escape_like_str($search));
$this->db->or_like('last_name',$this->db->escape_like_str($search));
$this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search));
$this->db->or_like('email',$this->db->escape_like_str($search));
$this->db->or_like('phone_number',$this->db->escape_like_str($search));
$this->db->like('person_id', $this->db->escape_like_str($search));
$this->db->or_like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like("CONCAT(`first_name`, ' ', `last_name`)", $this->db->escape_like_str($search));
$this->db->or_like('email', $this->db->escape_like_str($search));
$this->db->or_like('phone_number', $this->db->escape_like_str($search));
$this->db->order_by('person_id', 'asc');
$by_person_id = $this->db->get();
@@ -220,11 +232,12 @@ class Giftcard extends CI_Model
$suggestions[]=$row->person_id;
}
//only return $limit suggestions
//only return $limit suggestions
if(count($suggestions > $limit))
{
$suggestions = array_slice($suggestions, 0,$limit);
}
}
return $suggestions;
}
@@ -234,40 +247,46 @@ class Giftcard extends CI_Model
function search($search, $rows = 0, $limit_from = 0)
{
$this->db->from('giftcards');
$this->db->join('people','giftcards.person_id=people.person_id', 'left');
$this->db->like("first_name",$this->db->escape_like_str($search));
$this->db->or_like("last_name",$this->db->escape_like_str($search));
$this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search));
$this->db->or_like("giftcard_number",$this->db->escape_like_str($search));
$this->db->or_like("giftcards.person_id",$this->db->escape_like_str($search));
$this->db->where('deleted','0');
$this->db->order_by("giftcard_number", "asc");
if ($rows > 0) {
$this->db->join('people', 'giftcards.person_id=people.person_id', 'left');
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like("CONCAT(`first_name`, ' ', `last_name`)", $this->db->escape_like_str($search));
$this->db->or_like('giftcard_number', $this->db->escape_like_str($search));
$this->db->or_like('giftcards.person_id', $this->db->escape_like_str($search));
$this->db->where('deleted', 0);
$this->db->order_by('giftcard_number', 'asc');
if ($rows > 0)
{
$this->db->limit($rows, $limit_from);
}
}
return $this->db->get();
}
function get_found_rows($search)
{
$this->db->from('giftcards');
$this->db->join('people','giftcards.person_id=people.person_id', 'left');
$this->db->like("first_name",$this->db->escape_like_str($search));
$this->db->or_like("last_name",$this->db->escape_like_str($search));
$this->db->or_like("CONCAT(`first_name`,' ',`last_name`)",$this->db->escape_like_str($search));
$this->db->or_like("giftcard_number",$this->db->escape_like_str($search));
$this->db->or_like("giftcards.person_id",$this->db->escape_like_str($search));
$this->db->join('people', 'giftcards.person_id=people.person_id', 'left');
$this->db->like('first_name', $this->db->escape_like_str($search));
$this->db->or_like('last_name', $this->db->escape_like_str($search));
$this->db->or_like("CONCAT(`first_name`, ' ', `last_name`)", $this->db->escape_like_str($search));
$this->db->or_like('giftcard_number', $this->db->escape_like_str($search));
$this->db->or_like('giftcards.person_id', $this->db->escape_like_str($search));
$this->db->where('deleted', 0);
return $this->db->get()->num_rows();
}
public function get_giftcard_value( $giftcard_number )
{
if ( !$this->exists( $this->get_giftcard_id($giftcard_number)))
if ( !$this->exists( $this->get_giftcard_id($giftcard_number) ) )
{
return 0;
}
$this->db->from('giftcards');
$this->db->where('giftcard_number',$giftcard_number);
$this->db->where('giftcard_number', $giftcard_number);
return $this->db->get()->row()->value;
}

View File

@@ -42,11 +42,12 @@ class Summary_payments extends Report
$gift_card_count += $payment['count'];
$gift_card_amount += $payment['payment_amount'];
// remove the "Gift Card: 1", "Gift Card: 2", etc. payment string
unset($payments[$key]);
}
}
if( $gift_card_count > 0 && $gift_card_amount > 0 )
if( $gift_card_count > 0 )
{
$payments[] = array('payment_type' => $this->lang->line('sales_giftcard'), 'count' => $gift_card_count, 'payment_amount' => $gift_card_amount);
}

View File

@@ -101,7 +101,6 @@ class Sale extends CI_Model
$pieces = explode(' ',$inputs['search']);
$this->db->where('sales.sale_id', $pieces[1]);
}
else
{
$this->db->like('last_name', $inputs['search']);
@@ -110,7 +109,6 @@ class Sale extends CI_Model
}
}
if ($inputs['sale_type'] == 'sales')
{
$this->db->where('payment_amount > 0');
@@ -144,11 +142,12 @@ class Sale extends CI_Model
$gift_card_count += $payment['count'];
$gift_card_amount += $payment['payment_amount'];
// remove the "Gift Card: 1", "Gift Card: 2", etc. payment string
unset($payments[$key]);
}
}
if( $gift_card_count > 0 && $gift_card_amount > 0 )
if( $gift_card_count > 0 )
{
$payments[] = array('payment_type' => $this->lang->line('sales_giftcard'), 'count' => $gift_card_count, 'payment_amount' => $gift_card_amount);
}
@@ -162,11 +161,12 @@ class Sale extends CI_Model
return $this->db->count_all_results();
}
function get_search_suggestions($search,$limit=25)
function get_search_suggestions($search, $limit=25)
{
$suggestions = array();
if (!$this->sale_lib->is_valid_receipt($search)) {
if (!$this->sale_lib->is_valid_receipt($search))
{
$this->db->distinct();
$this->db->select('first_name, last_name');
$this->db->from('sales');
@@ -180,18 +180,20 @@ class Sale extends CI_Model
{
$suggestions[]=$result[ 'first_name' ].' '.$result[ 'last_name' ];
}
} else {
}
else
{
$suggestions[]=$search;
}
return $suggestions;
}
function get_invoice_count()
{
$this->db->from('sales');
$this->db->where('invoice_number is not null');
return $this->db->count_all_results();
}
@@ -199,6 +201,7 @@ class Sale extends CI_Model
{
$this->db->from('sales');
$this->db->where('invoice_number', $invoice_number);
return $this->db->get();
}
@@ -210,22 +213,22 @@ class Sale extends CI_Model
$this->db->where("DATE_FORMAT(sale_time, '%Y' ) = ", $year, FALSE);
$this->db->where("invoice_number IS NOT ", "NULL", FALSE);
$result = $this->db->get()->row_array();
return ($start_from + $result[ 'invoice_number_year']);
}
function exists($sale_id)
{
$this->db->from('sales');
$this->db->where('sale_id',$sale_id);
$query = $this->db->get();
$this->db->where('sale_id', $sale_id);
return ($query->num_rows()==1);
return ($this->db->get()->num_rows()==1);
}
function update($sale_data, $sale_id)
{
$this->db->where('sale_id', $sale_id);
$success = $this->db->update('sales',$sale_data);
$success = $this->db->update('sales', $sale_data);
return $success;
}
@@ -233,7 +236,9 @@ class Sale extends CI_Model
function save($items, $customer_id, $employee_id, $comment, $invoice_number, $payments, $sale_id=false)
{
if(count($items)==0)
{
return -1;
}
$sales_data = array(
'sale_time' => date('Y-m-d H:i:s'),
@@ -259,8 +264,7 @@ class Sale extends CI_Model
$this->Giftcard->update_giftcard_value( $splitpayment[1], $cur_giftcard_value - $payment['payment_amount'] );
}
$sales_payments_data = array
(
$sales_payments_data = array(
'sale_id'=>$sale_id,
'payment_type'=>$payment['payment_type'],
'payment_amount'=>$payment['payment_amount']
@@ -272,8 +276,7 @@ class Sale extends CI_Model
{
$cur_item_info = $this->Item->get_info($item['item_id']);
$sales_items_data = array
(
$sales_items_data = array(
'sale_id'=>$sale_id,
'item_id'=>$item['item_id'],
'line'=>$item['line'],
@@ -336,9 +339,12 @@ class Sale extends CI_Model
function delete_list($sale_ids, $employee_id, $update_inventory=TRUE)
{
$result = TRUE;
foreach($sale_ids as $sale_id) {
foreach($sale_ids as $sale_id)
{
$result &= $this->delete($sale_id, $employee_id, $update_inventory);
}
return $result;
}
@@ -371,9 +377,7 @@ class Sale extends CI_Model
$this->Inventory->insert($inv_data);
// update quantities
$this->Item_quantity->change_quantity($item['item_id'],
$item['item_location'],
$item['quantity_purchased']);
$this->Item_quantity->change_quantity($item['item_id'], $item['item_location'], $item['quantity_purchased']);
}
}
@@ -391,25 +395,28 @@ class Sale extends CI_Model
function get_sale_items($sale_id)
{
$this->db->from('sales_items');
$this->db->where('sale_id',$sale_id);
$this->db->where('sale_id', $sale_id);
return $this->db->get();
}
function get_sale_payments($sale_id)
{
$this->db->from('sales_payments');
$this->db->where('sale_id',$sale_id);
$this->db->where('sale_id', $sale_id);
return $this->db->get();
}
function get_customer($sale_id)
{
$this->db->from('sales');
$this->db->where('sale_id',$sale_id);
$this->db->where('sale_id', $sale_id);
return $this->Customer->get_info($this->db->get()->row()->customer_id);
}
function invoice_number_exists($invoice_number,$sale_id='')
function invoice_number_exists($invoice_number, $sale_id='')
{
$this->db->from('sales');
$this->db->where('invoice_number', $invoice_number);
@@ -417,8 +424,21 @@ class Sale extends CI_Model
{
$this->db->where('sale_id !=', $sale_id);
}
$query=$this->db->get();
return ($query->num_rows()==1);
return ($this->db->get()->num_rows()==1);
}
function get_giftcard_value( $giftcardNumber )
{
if ( !$this->Giftcard->exists( $this->Giftcard->get_giftcard_id($giftcardNumber) ) )
{
return 0;
}
$this->db->from('giftcards');
$this->db->where('giftcard_number', $giftcardNumber);
return $this->db->get()->row()->value;
}
//We create a temp table that allows us to do easy report/sales queries
@@ -471,15 +491,5 @@ class Sale extends CI_Model
//Update null subtotals to be equal to the total as these don't have tax
$this->db->query('UPDATE '.$this->db->dbprefix('sales_items_temp'). ' SET total=subtotal WHERE total IS NULL');
}
function get_giftcard_value( $giftcardNumber )
{
if ( !$this->Giftcard->exists( $this->Giftcard->get_giftcard_id($giftcardNumber)))
return 0;
$this->db->from('giftcards');
$this->db->where('giftcard_number',$giftcardNumber);
return $this->db->get()->row()->value;
}
}
?>

View File

@@ -149,10 +149,10 @@ function show_hide_search_filter(search_filter_section, switchImgTag)
<div style="float:left;vertical-align:text-top;"><?php echo $this->lang->line('common_search_options'); ?> :</div>
<a id="imageDivLink" href="javascript:show_hide_search_filter('search_filter_section', 'imageDivLink');" style="outline:none;">
<img src="
<?php echo isset($search_section_state)? ( ($search_section_state)? base_url().'images/minus.png' : base_url().'images/plus.png') : base_url().'images/plus.png';?>" style="border:0;outline:none;padding:0px;margin:0px;position:relative;top:-5px;"></a>
<?php echo isset($search_section_state)? ( ($search_section_state)? base_url().'images/minus.png' : base_url().'images/plus.png') : base_url().'images/plus.png';?>" style="border:0;outline:none;padding:0px;margin:0px;position:relative;top:-5px;"></a>
</div>
<?php echo form_open("$controller_name/search",array('id'=>'search_form')); ?>
<div id="search_filter_section" style="display: <?php echo isset($search_section_state)? ( ($search_section_state)? 'block' : 'none') : 'none';?>;background-color:#EEEEEE;">
<div id="search_filter_section" style="display: <?php echo isset($search_section_state)? ( ($search_section_state)? 'block' : 'none') : 'none';?>; background-color:#EEEEEE;">
<?php echo form_label($this->lang->line('items_empty_upc_items').' '.':', 'empty_upc');?>
<?php echo form_checkbox(array('name'=>'empty_upc','id'=>'empty_upc','value'=>1,'checked'=> isset($empty_upc)? ( ($empty_upc)? 1 : 0) : 0)).' | ';?>
<?php echo form_label($this->lang->line('items_low_inventory_items').' '.':', 'low_inventory');?>