diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 92bb9990c..19c3378c4 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -14,20 +14,41 @@ class Sales extends Secure_area $this->_reload(); } - function manage($payment_type = 0, $limit_from = 0) + function manage($only_invoices = FALSE, $limit_from = 0) { - $data['controller_name']=strtolower($this->uri->segment(1)); - $data['payment_types'] = array($this->lang->line('sales_no_filter'), $this->lang->line('sales_invoice')); - $data['search_section_state']=$this->input->post('search_section_state'); - + $model = $this->Sale; + + // Create the temp tables to work with the data + $model->create_sales_items_temp_table(); + + $data['controller_name'] = strtolower($this->uri->segment(1)); + $data['only_invoices'] = array($this->lang->line('sales_no_filter'), $this->lang->line('sales_invoice')); + $data['search_section_state'] = $this->input->post('search_section_state'); $lines_per_page = $this->Appconfig->get('lines_per_page'); - $sales = $this->Sale->get_all($payment_type,$lines_per_page,$limit_from); - $total_rows = $this->Sale->get_found_rows($payment_type); - $data['payment_type'] = $payment_type; - $data['links'] = $this->_initialize_pagination($this->Sale, $lines_per_page, $limit_from, -1, 'manage', $payment_type); - - $data['manage_table']=get_sales_manage_table($sales,$this); - $this->load->view($data['controller_name'] . '/manage',$data); + + $today = date('Y-m-d'); +// $yesterday = date('Y-m-d', mktime(0,0,0,date("m"),date("d")-1,date("Y"))); +// $tomorrow = date('Y-m-d', mktime(0,0,0,date("m"),date("d")+1,date("Y"))); + $start_of_time = date('Y-m-d', 0); + + $start_date = $start_of_time; + $end_date = $today; + $sale_type = 'sales'; + $location_id = 'all'; + + $report_data = $model->get_data(array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id, + 'only_invoices' => $only_invoices, 'lines_per_page' => $lines_per_page, 'limit_from' => $limit_from)); + + $sales = $report_data['summary']; + $payments = $report_data['payments']; + $details = $report_data['details']; + $payments_summary = $report_data['payments_summary']; + + $data['only_invoices'] = $only_invoices; + $data['links'] = $this->_initialize_pagination($model, $lines_per_page, $limit_from, -1, 'manage', $only_invoices); + $data['manage_table'] = get_sales_manage_table($sales, $payments, $details, $this); + $data['payments_summary_data'] = get_sales_manage_payments_summary($payments_summary, $this); + $this->load->view($data['controller_name'] . '/manage', $data); $this->_remove_duplicate_cookies(); } @@ -51,16 +72,7 @@ class Sales extends Secure_area function search() { - $payment_type = $this->input->post('payment_type', TRUE); - $limit_from = $this->input->post('limit_from', TRUE); - $search = $this->input->post('search', TRUE); - $lines_per_page = $this->Appconfig->get('lines_per_page'); - $sales = $this->Sale->search($search, $payment_type, $lines_per_page, $limit_from, $search); - $total_rows = $this->Sale->get_found_rows($search); - $links = $this->_initialize_pagination($this->Sale,$lines_per_page,$limit_from,$total_rows,'search',$payment_type); - $data_rows=get_sales_manage_table_data_rows($sales,$this); - echo json_encode(array('total_rows' => $total_rows, 'rows' => $data_rows, 'pagination' => $links)); - $this->_remove_duplicate_cookies(); + $this->manage($this->input->post('only_invoices', TRUE)); } function item_search() @@ -81,14 +93,6 @@ class Sales extends Secure_area echo implode("\n",$suggestions); } - function suggest() - { - $search = $this->input->post('q', TRUE); - $limit = $this->input->post('limit', TRUE); - $suggestions = $this->Sale->get_search_suggestions($search, $limit); - echo implode("\n",$suggestions); - } - function select_customer() { $customer_id = $this->input->post("customer"); @@ -133,7 +137,7 @@ class Sales extends Secure_area function set_email_receipt() { - $this->sale_lib->set_email_receipt($this->input->post('email_receipt')); + $this->sale_lib->set_email_receipt($this->input->post('email_receipt')); } //Alain Multiple Payments @@ -318,10 +322,10 @@ class Sales extends Secure_area $data['customer_location'] = $cust_info->zip . ' ' . $cust_info->city; $data['account_number'] = $cust_info->account_number; $data['customer_info'] = implode("\n", array( - $data['customer'], - $data['customer_address'], - $data['customer_location'], - $data['account_number'] + $data['customer'], + $data['customer_address'], + $data['customer_location'], + $data['account_number'] )); } $invoice_number=$this->_substitute_invoice_number($cust_info); @@ -399,7 +403,8 @@ class Sales extends Secure_area return $filename; } - function invoice_email($sale_id) { + function invoice_email($sale_id) + { $sale_data = $this->_load_sale_data($sale_id); $sale_data['image_prefix'] = base_url(); $this->load->view('sales/invoice_email', $sale_data); @@ -407,7 +412,8 @@ class Sales extends Secure_area $this->_remove_duplicate_cookies(); } - function send_invoice($sale_id) { + function send_invoice($sale_id) + { $sale_data = $this->_load_sale_data($sale_id); $text = $this->config->item('invoice_email_message'); $text = str_replace('$INV', $sale_data['invoice_number'], $text); @@ -485,7 +491,8 @@ class Sales extends Secure_area return $invoice_number; } - function _load_sale_data($sale_id) { + function _load_sale_data($sale_id) + { $this->sale_lib->clear_all(); $sale_info = $this->Sale->get_info($sale_id)->row_array(); $this->sale_lib->copy_entire_sale($sale_id); @@ -526,19 +533,19 @@ class Sales extends Secure_area $data['customer_email'] = $cust_info->email; $data['account_number'] = $cust_info->account_number; $data['customer_info'] = implode("\n", array( - $data['customer'], - $data['customer_address'], - $data['customer_location'], - $data['account_number'] + $data['customer'], + $data['customer_address'], + $data['customer_location'], + $data['account_number'] )); } $data['sale_id']='POS '.$sale_id; $data['comments'] = $sale_info[ 'comment' ]; $data['invoice_number'] = $sale_info['invoice_number']; $data['company_info'] = implode("\n", array( - $this->config->item('address'), - $this->config->item('phone'), - $this->config->item('account_number') + $this->config->item('address'), + $this->config->item('phone'), + $this->config->item('account_number') )); // static barcode config for receipts + invoices $barcode_config=array('barcode_type'=>2,'barcode_width'=>200, 'barcode_height'=>30, 'barcode_quality'=>100); @@ -583,7 +590,8 @@ class Sales extends Secure_area $this->load->view('sales/form', $data); } - function delete($sale_id = -1, $update_inventory=TRUE) { + function delete($sale_id = -1, $update_inventory=TRUE) + { $employee_id=$this->Employee->get_logged_in_employee_info()->person_id; $sale_ids= $sale_id == -1 ? $this->input->post('ids') : array($sale_id); diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index 59b46c3c2..89b99bf86 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -1,16 +1,18 @@ '; $headers = array(' ', + $CI->lang->line('sales_receipt_number'), $CI->lang->line('sales_sale_time'), $CI->lang->line('customers_customer'), $CI->lang->line('sales_amount_tendered'), $CI->lang->line('sales_amount_due'), - $CI->lang->line('sales_receipt_number'), + $CI->lang->line('sales_change_due'), + $CI->lang->line('sales_payment'), $CI->lang->line('sales_invoice_number'), ' '); @@ -20,45 +22,87 @@ function get_sales_manage_table($sales,$controller) $table.="$header"; } $table.=''; - $table.=get_sales_manage_table_data_rows($sales,$controller); + $table.=get_sales_manage_table_data_rows($sales, $payments, $details, $controller); $table.=''; + return $table; } /* - Gets the html data rows for the people. + Gets the html data rows for the sales. */ -function get_sales_manage_table_data_rows($sales,$controller) +function get_sales_manage_table_data_rows($sales, $payments, $details, $controller) { $CI =& get_instance(); $table_data_rows=''; + $sum_amount_tendered = 0; + $sum_amount_due = 0; + $sum_change_due = 0; - foreach($sales->result_array() as $sale) + foreach($sales as $key=>$sale) { - $table_data_rows.=get_sale_data_row($sale,$controller); + $table_data_rows.=get_sales_manage_sale_data_row($sale, $payments[$key], $controller); + + $sum_amount_tendered += $sale['amount_tendered']; + $sum_amount_due += $sale['amount_due']; + $sum_change_due += $sale['change_due']; } - if($sales->num_rows()==0) + if($table_data_rows == '') { $table_data_rows.="
".$CI->lang->line('sales_no_sales_to_display')."
"; } + else + { + // show a line in bold with the totals + $table_data_rows.=" ".$CI->lang->line('sales_total')."  ".to_currency($sum_amount_tendered)."".to_currency($sum_amount_due)."".to_currency($sum_change_due).""; + } return $table_data_rows; } -function get_sale_data_row($sale,$controller) +function get_sales_manage_sale_data_row($sale, $payments, $controller) { $CI =& get_instance(); - $controller_name=$CI->uri->segment(1); + $controller_name = $CI->uri->segment(1); $width = $controller->get_form_width(); + $payment = ''; + + // set in one string all the payments type and amount + foreach( $payments as $key=>$row ) + { + $payment.= $row['payment_type'] . " "; + + // the assumption here is that any change due is deducted from the cash amount paid, not from any other form of payment + if( $row['payment_type'] == $CI->lang->line('sales_cash') ) + { + $payment.= to_currency($row['payment_amount'] - $sale['change_due']); + } + else + { + $payment.= to_currency($row['payment_amount']); + } + + $payment.= ", "; + } + + // make sure we have something in the string + if( $payment != '' ) + { + // remove the last ", " from the string + $payment = substr($payment, 0, strlen($payment) - 2 ); + } + $table_data_row=''; $table_data_row.=''; + $table_data_row.=''.'POS ' . $sale[ 'sale_id' ]. ''; $table_data_row.=''.date($CI->config->item('dateformat').' '.$CI->config->item('timeformat'), strtotime($sale[ 'sale_time' ])).''; - $table_data_row.=''.character_limiter( $sale[ 'last_name' ] . " " . $sale[ 'first_name' ] ,25).''; + $table_data_row.=''.character_limiter( $sale[ 'customer_name' ], 25).''; $table_data_row.=''.to_currency( $sale[ 'amount_tendered' ] ).''; $table_data_row.=''.to_currency( $sale[ 'amount_due' ] ).''; - $table_data_row.=''.'Ticket ' . $sale[ 'sale_id' ]. ''; + $table_data_row.=''.to_currency( $sale[ 'change_due' ] ).''; + $table_data_row.=''.$payment.''; $table_data_row.=''.$sale[ 'invoice_number' ].''; $table_data_row.=''; $table_data_row.=anchor($controller_name."/edit/" . $sale[ 'sale_id' ] . "/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))); @@ -72,6 +116,31 @@ function get_sale_data_row($sale,$controller) return $table_data_row; } +/* +Get the sales payments summary +*/ +function get_sales_manage_payments_summary($payments_summary, $controller) +{ + $CI =& get_instance(); + $table=''; + + $table.=''; + $table.=''; + foreach($payments_summary as $key=>$summary) + { + $table.=''; + } + $table.=''; + $table.=''; + foreach($payments_summary as $key=>$summary) + { + $table.=''; + } + $table.='
 '.$summary['payment_type'].'
'.$CI->lang->line('sales_total').''.to_currency( $summary['payment_amount'] ).'
'; + + return $table; +} + /* Gets the html table to manage people. */ @@ -95,6 +164,7 @@ function get_people_manage_table($people,$controller) $table.=''; $table.=get_people_manage_table_data_rows($people,$controller); $table.=''; + return $table; } @@ -148,6 +218,7 @@ function get_detailed_data_row($row, $controller) $table_data_row.=''; } $table_data_row.=''; + return $table_data_row; } @@ -177,6 +248,7 @@ function get_supplier_manage_table($suppliers,$controller) $table.=''; $table.=get_supplier_manage_table_data_rows($suppliers,$controller); $table.=''; + return $table; } @@ -252,6 +324,7 @@ function get_items_manage_table($items,$controller) $table.=''; $table.=get_items_manage_table_data_rows($items,$controller); $table.=''; + return $table; } @@ -318,6 +391,7 @@ function get_item_data_row($item,$controller) $table_data_row.=''*/'    '.anchor($controller_name."/count_details/$item->item_id/width:$width", $CI->lang->line('common_det'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_details_count'))).'';//inventory details $table_data_row.=''; + return $table_data_row; } @@ -327,7 +401,6 @@ Gets the html table to manage giftcards. function get_giftcards_manage_table( $giftcards, $controller ) { $CI =& get_instance(); - $table=''; $headers = array('', @@ -346,6 +419,7 @@ function get_giftcards_manage_table( $giftcards, $controller ) $table.=''; $table.=get_giftcards_manage_table_data_rows( $giftcards, $controller ); $table.='
'; + return $table; } @@ -383,9 +457,9 @@ function get_giftcard_data_row($giftcard,$controller) $table_data_row.=''.$giftcard->first_name.''; $table_data_row.=''.$giftcard->giftcard_number.''; $table_data_row.=''.to_currency($giftcard->value).''; - $table_data_row.=''.anchor($controller_name."/view/$giftcard->giftcard_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).''; - + $table_data_row.=''.anchor($controller_name."/view/$giftcard->giftcard_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).''; $table_data_row.=''; + return $table_data_row; } /** END GARRISON MODIFIED **/ @@ -396,7 +470,6 @@ Gets the html table to manage item kits. function get_item_kits_manage_table( $item_kits, $controller ) { $CI =& get_instance(); - $table=''; $headers = array('', @@ -413,6 +486,7 @@ function get_item_kits_manage_table( $item_kits, $controller ) $table.=''; $table.=get_item_kits_manage_table_data_rows( $item_kits, $controller ); $table.='
'; + return $table; } @@ -447,9 +521,9 @@ function get_item_kit_data_row($item_kit,$controller) $table_data_row.=""; $table_data_row.=''.$item_kit->name.''; $table_data_row.=''.character_limiter($item_kit->description, 25).''; - $table_data_row.=''.anchor($controller_name."/view/$item_kit->item_kit_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).''; - + $table_data_row.=''.anchor($controller_name."/view/$item_kit->item_kit_id/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'))).''; $table_data_row.=''; + return $table_data_row; } diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 2c1ea8507..a812f0e0e 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -333,9 +333,9 @@ class Sale_lib //$item = $this->CI->Item->get_info($item_id); $item_quantity = $this->CI->Item_quantities->get_item_quantity($item_id,$item_location)->quantity; - $quanity_added = $this->get_quantity_already_added($item_id,$item_location); + $quantity_added = $this->get_quantity_already_added($item_id,$item_location); - if ($item_quantity - $quanity_added < 0) + if ($item_quantity - $quantity_added < 0) { return true; } diff --git a/application/models/sale.php b/application/models/sale.php index 8d46818b6..50e85baf2 100644 --- a/application/models/sale.php +++ b/application/models/sale.php @@ -18,69 +18,83 @@ class Sale extends CI_Model $this->db->where('sales.sale_id',$sale_id); $this->db->order_by('sale_time', 'desc'); $this->db->group_by('sale_id'); + return $this->db->get(); } - function get_all($only_invoices = 0, $rows = 0, $limit_from = 0) + // get the sales data for the takings table + function get_data($inputs) { - $this->db->select('first_name, last_name, invoice_number, amount_tendered, sale_time'); - $this->db->select("DATE_FORMAT( sale_time, '%d-%m-%Y' ) AS sale_date", FALSE); - $this->db->select("sales.sale_id AS sale_id"); - $this->db->select("SUM(item_unit_price * quantity_purchased * (1 - discount_percent / 100)) AS amount_due"); - $this->db->from('sales'); - $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); - $this->db->join('sales_items', 'sales_items.sale_id = sales.sale_id'); - $this->db->join("(SELECT sale_id, SUM(payment_amount) AS amount_tendered " . - " FROM " . $this->db->dbprefix('sales_payments') ." WHERE payment_type <> '" . - $this->lang->line('sales_check') . "' GROUP BY sale_id) AS payments", - "payments.sale_id = sales.sale_id", 'left'); - $this->db->order_by('sale_time', 'desc'); - $this->db->group_by('sale_id'); - if ($rows > 0) { - $this->db->limit($rows, $limit_from); + $this->db->select('sale_id, sale_date, sale_time, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, + CONCAT(customer.first_name," ",customer.last_name) as customer_name, sum(subtotal) as subtotal, sum(total) as total, sum(tax) as tax, sum(cost) as cost, sum(profit) as profit, + sale_payment_amount as amount_tendered, total as amount_due, (sale_payment_amount - total) as change_due, invoice_number', false); + $this->db->from('sales_items_temp'); + $this->db->join('people as employee', 'sales_items_temp.employee_id = employee.person_id'); + $this->db->join('people as customer', 'sales_items_temp.customer_id = customer.person_id', 'left'); + $this->db->where('sale_date BETWEEN '. $this->db->escape($inputs['start_date']). ' and '. $this->db->escape($inputs['end_date'])); + + if ($inputs['location_id'] != 'all') + { + $this->db->where('item_location', $inputs['location_id']); } - if ($only_invoices != 0) { + + if ($inputs['sale_type'] == 'sales') + { + $this->db->where('quantity_purchased > 0'); + } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('quantity_purchased < 0'); + } + + if ($inputs['only_invoices'] != FALSE) + { $this->db->where('invoice_number <> ', 'NULL'); } - return $this->db->get(); - } - - function search($search, $only_invoices = FALSE, $rows = 0, $limit_from = 0) - { - $valid_receipt = $this->sale_lib->is_valid_receipt($search); - $this->db->select('first_name, last_name, invoice_number, amount_tendered, sale_time'); - $this->db->select("DATE_FORMAT( sale_time, '%d-%m-%Y' ) AS sale_date", FALSE); - $this->db->select("sales.sale_id AS sale_id"); - $this->db->select("SUM(item_unit_price * quantity_purchased * (1 - discount_percent / 100)) AS amount_due"); - $this->db->from('sales'); - $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); - $this->db->join('sales_items', 'sales_items.sale_id = sales.sale_id'); - $this->db->join("(SELECT sale_id, SUM(payment_amount) AS amount_tendered " . - " FROM " . $this->db->dbprefix('sales_payments') ." WHERE payment_type <> '" . - $this->lang->line('sales_check') . "' GROUP BY sale_id) AS payments", - "payments.sale_id = sales.sale_id", 'left'); + $this->db->group_by('sale_id'); - if (!empty($search)) { - // if barcode scanned, explode and search for second term which will be the id - if ($valid_receipt) { - $pieces = explode(' ',$search); - $this->db->where('sales.sale_id', $pieces[1]); - } else { - // open parentheses - $this->db->where("( last_name LIKE '%" . $search . "%' OR ". - "first_name LIKE '%" . $search . "%' OR " . - "CONCAT( first_name,' ',last_name ) LIKE '%" . $search . "%')"); - // close parentheses - } + $this->db->order_by('sale_date', 'desc'); + + if ($inputs['lines_per_page'] > 0) + { + $this->db->limit($inputs['lines_per_page'], $inputs['limit_from']); } - if ($only_invoices != 0) { + + $data = array(); + $data['summary'] = $this->db->get()->result_array(); + $data['details'] = array(); + $data['payments'] = array(); + + foreach($data['summary'] as $key=>$value) + { + $data['payments'][$key] = $this->get_sale_payments($value['sale_id'])->result_array(); + } + + // get payment summary + $this->db->select('sales_payments.payment_type, count(*) as count, sum(payment_amount) as payment_amount', false); + $this->db->from('sales_payments'); + $this->db->join('sales_items_temp', 'sales_items_temp.sale_id=sales_payments.sale_id'); + $this->db->where('date(sale_time) BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"'); + + if ($inputs['sale_type'] == 'sales') + { + $this->db->where('payment_amount > 0'); + } + elseif ($inputs['sale_type'] == 'returns') + { + $this->db->where('payment_amount < 0'); + } + + if ($inputs['only_invoices'] != FALSE) + { $this->db->where('invoice_number <> ', 'NULL'); } - $this->db->order_by('sale_time DESC'); - if ($rows > 0) { - $this->db->limit($rows, $limit_from); - } - return $this->db->get(); + + $this->db->group_by("payment_type"); + + $data['payments_summary'] = $this->db->get()->result_array(); + + return $data; } function get_total_rows() @@ -89,59 +103,6 @@ class Sale extends CI_Model return $this->db->count_all_results(); } - function get_search_suggestions($search,$limit=25) - { - $suggestions = array(); - - if (!$this->sale_lib->is_valid_receipt($search)) { - $this->db->distinct(); - $this->db->select('first_name, last_name, invoice_number, sale_time'); - $this->db->select("DATE_FORMAT( sale_time, '%d-%m-%Y' ) AS sale_date", FALSE); - $this->db->select("sales.sale_id AS sale_id"); - $this->db->from('sales'); - $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); - $this->db->where("( last_name LIKE '%" . $search . "%' OR ". - "first_name LIKE '%" . $search . "%' OR " . - "CONCAT( first_name, last_name ))"); - $this->db->order_by('last_name', "asc"); - - foreach($this->db->get()->result_array() as $result) - { - $suggestions[]=$result[ 'first_name' ].' '.$result[ 'last_name' ]; - } - - } else { - $suggestions[]=$search; - } - return $suggestions; - } - - function get_found_rows($search, $only_invoices = FALSE) - { - $valid_receipt = $this->sale_lib->is_valid_receipt($search); - $this->db->from('sales'); - $this->db->join('sales_items', 'sales_items.sale_id = sales.sale_id'); - $this->db->join('people', 'people.person_id = sales.customer_id', 'left'); - $this->db->group_by('sales.sale_id'); - if (!empty($search)) { - // if barcode scanned, explode and search for second term which will be the id - $pieces = explode(' ',$search); - if ($valid_receipt && count($pieces) == 2) { - $this->db->where('sales.sale_id', $pieces[1]); - } else { - // open parentheses - $this->db->where("( last_name LIKE '%" . $search . "%' OR ". - "first_name LIKE '%" . $search . "%' OR " . - "CONCAT( first_name,' ',last_name ) LIKE '%" . $search . "%')"); - // close parentheses - } - } - if ($only_invoices != 0) { - $this->db->where('invoice_number <> ', 'NULL'); - } - return $this->db->get()->num_rows(); - } - function get_invoice_count() { $this->db->from('sales'); @@ -184,7 +145,7 @@ class Sale extends CI_Model return $success; } - function save ($items,$customer_id,$employee_id,$comment,$invoice_number,$payments,$sale_id=false) + function save($items, $customer_id, $employee_id, $comment, $invoice_number, $payments, $sale_id=false) { if(count($items)==0) return -1; @@ -244,7 +205,7 @@ class Sale extends CI_Model //Update stock quantity $item_quantity = $this->Item_quantities->get_item_quantity($item['item_id'], $item['item_location']); - $this->Item_quantities->save(array('quantity'=>$item_quantity->quantity - $item['quantity'], + $this->Item_quantities->save(array('quantity'=>$item_quantity->quantity - $item['quantity'], 'item_id'=>$item['item_id'], 'location_id'=>$item['item_location']), $item['item_id'], $item['item_location']); @@ -290,7 +251,7 @@ class Sale extends CI_Model return $sale_id; } - function delete_list($sale_ids, $employee_id,$update_inventory=TRUE) + function delete_list($sale_ids, $employee_id, $update_inventory=TRUE) { $result = TRUE; foreach($sale_ids as $sale_id) { @@ -299,7 +260,7 @@ class Sale extends CI_Model return $result; } - function delete($sale_id,$employee_id,$update_inventory=TRUE) + function delete($sale_id, $employee_id, $update_inventory=TRUE) { // start a transaction to assure data integrity $this->db->trans_start(); @@ -381,29 +342,29 @@ class Sale extends CI_Model //We create a temp table that allows us to do easy report/sales queries public function create_sales_items_temp_table() { - - if ($this->config->item('tax_included')) - { - $total = "1"; - $subtotal = "(1 - (SUM(1 - 100/(100+percent))))"; - $tax="(SUM(1 - 100/(100+percent)))"; - } - else - { - $tax = "(SUM(percent)/100)"; - $total = "(1+(SUM(percent/100)))"; - $subtotal = "1"; - } + if ($this->config->item('tax_included')) + { + $total = "1"; + $subtotal = "(1 - (SUM(1 - 100/(100+percent))))"; + $tax="(SUM(1 - 100/(100+percent)))"; + } + else + { + $tax = "(SUM(percent)/100)"; + $total = "(1+(SUM(percent/100)))"; + $subtotal = "1"; + } $this->db->query("CREATE TEMPORARY TABLE IF NOT EXISTS ".$this->db->dbprefix('sales_items_temp')." - (SELECT date(sale_time) as sale_date, sale_time, ".$this->db->dbprefix('sales_items').".sale_id, comment,payments.payment_type, item_location, customer_id, employee_id, + (SELECT date(sale_time) as sale_date, sale_time, ".$this->db->dbprefix('sales_items').".sale_id, comment, payments.payment_type, payments.sale_payment_amount, item_location, customer_id, employee_id, ".$this->db->dbprefix('items').".item_id, supplier_id, quantity_purchased, item_cost_price, item_unit_price, SUM(percent) as item_tax_percent, discount_percent, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*$subtotal,2) as subtotal, ".$this->db->dbprefix('sales_items').".line as line, serialnumber, ".$this->db->dbprefix('sales_items').".description as description, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*$total, 2) as total, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)*$tax, 2) as tax, ROUND((item_unit_price*quantity_purchased-item_unit_price*quantity_purchased*discount_percent/100)- (item_cost_price*quantity_purchased), 2) as profit, - (item_cost_price*quantity_purchased) as cost + (item_cost_price*quantity_purchased) as cost, + invoice_number FROM ".$this->db->dbprefix('sales_items')." INNER JOIN ".$this->db->dbprefix('sales')." ON ".$this->db->dbprefix('sales_items').'.sale_id='.$this->db->dbprefix('sales').'.sale_id'." INNER JOIN ".$this->db->dbprefix('items')." ON ".$this->db->dbprefix('sales_items').'.item_id='.$this->db->dbprefix('items').'.item_id'." diff --git a/application/views/reports/tabular_details.php b/application/views/reports/tabular_details.php index 6d255029f..dec00f1e2 100644 --- a/application/views/reports/tabular_details.php +++ b/application/views/reports/tabular_details.php @@ -119,7 +119,6 @@ function expand_handler(event) if ($(event.target).text() == '+') { - $(event.target).text('-'); } else diff --git a/application/views/sales/manage.php b/application/views/sales/manage.php index aba96d64a..d7eca4671 100755 --- a/application/views/sales/manage.php +++ b/application/views/sales/manage.php @@ -1,4 +1,5 @@ load->view("partial/header"); ?> +
@@ -151,20 +149,14 @@ function init_table_sorting()
'search_form')); ?>
- lang->line('sales_invoice_filter').' '.':', 'invoices_filter');?> -   - + lang->line('sales_invoice_filter').' '.':', 'invoices_filter');?> + 'only_invoices','id'=>'only_invoices','value'=>1,'checked'=> isset($only_invoices)? ( ($only_invoices)? 1 : 0) : 0));?>
@@ -172,5 +164,10 @@ function init_table_sorting()
+ +
+ +
+
load->view("partial/footer"); ?> \ No newline at end of file