From a8dfa2dbe874e4852344df5300adc7d667d21df0 Mon Sep 17 00:00:00 2001 From: pappastech Date: Tue, 5 Mar 2013 03:09:38 +0000 Subject: [PATCH] * Ver. 2.0.2 + Fixed multiple giftcards issue per Bug #4 reported on Sourceforge where a second giftcard added would have its balance set to $0 even if the sale did not require the total of the second giftcard to pay the remaining amount due. + Small code cleanup git-svn-id: svn+ssh://jekkos@svn.code.sf.net/p/opensourcepos/code/@58 c3eb156b-1dc0-44e1-88ae-e38439141b53 --- WHATS_NEW.txt | 6 ++++ application/config/config.php | 2 +- application/controllers/sales.php | 37 +++++++++++++------------ application/hooks/load_config.php | 12 ++++---- application/libraries/Sale_lib.php | 20 ++++++------- application/views/reports/graphical.php | 2 +- 6 files changed, 43 insertions(+), 36 deletions(-) diff --git a/WHATS_NEW.txt b/WHATS_NEW.txt index 6baeac41c..cf6fd5718 100644 --- a/WHATS_NEW.txt +++ b/WHATS_NEW.txt @@ -1,2 +1,8 @@ +* Ver. 2.0.2 ++ Fixed multiple giftcards issue per Bug #4 reported on Sourceforge where a + second giftcard added would have its balance set to $0 even if the sale did + not require the total of the second giftcard to pay the remaining amount due. ++ Small code cleanup +------------------------------------------------------------------------------- * Upgrade to CodeIgniter 2.1.0 * Various small improvements \ No newline at end of file diff --git a/application/config/config.php b/application/config/config.php index 9cc5aec95..67218b6a7 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -9,7 +9,7 @@ | | */ -$config['application_version'] = '2.0.1'; +$config['application_version'] = '2.0.2'; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 4d93e163d..3e6ddd7f5 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -53,42 +53,43 @@ class Sales extends Secure_area //Alain Multiple Payments function add_payment() { - $data=array(); - $this->form_validation->set_rules('amount_tendered', 'lang:sales_amount_tendered', 'numeric'); + $data = array(); + $this->form_validation->set_rules( 'amount_tendered', 'lang:sales_amount_tendered', 'numeric' ); - if ($this->form_validation->run() == FALSE) + if ( $this->form_validation->run() == FALSE ) { - if ( $this->input->post('payment_type') == $this->lang->line('sales_gift_card') ) + if ( $this->input->post( 'payment_type' ) == $this->lang->line( 'sales_gift_card' ) ) $data['error']=$this->lang->line('sales_must_enter_numeric_giftcard'); else $data['error']=$this->lang->line('sales_must_enter_numeric'); - $this->_reload($data); + $this->_reload( $data ); return; } - $payment_type=$this->input->post('payment_type'); - if ( $payment_type == $this->lang->line('sales_giftcard') ) + $payment_type = $this->input->post( 'payment_type' ); + if ( $payment_type == $this->lang->line( 'sales_giftcard' ) ) { $payments = $this->sale_lib->get_payments(); - $payment_type=$this->input->post('payment_type').':'.$payment_amount=$this->input->post('amount_tendered'); - $current_payments_with_giftcard = isset($payments[$payment_type]) ? $payments[$payment_type]['payment_amount'] : 0; - $cur_giftcard_value = $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) - $current_payments_with_giftcard; + $payment_type = $this->input->post( 'payment_type' ) . ':' . $payment_amount = $this->input->post( 'amount_tendered' ); + $current_payments_with_giftcard = isset( $payments[$payment_type] ) ? $payments[$payment_type]['payment_amount'] : 0; + $cur_giftcard_value = $this->Giftcard->get_giftcard_value( $this->input->post( 'amount_tendered' ) ) - $current_payments_with_giftcard; + if ( $cur_giftcard_value <= 0 ) { - $data['error']='Giftcard balance is '.to_currency( $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) ).' !'; - $this->_reload($data); + $data['error'] = 'Giftcard balance is ' . to_currency( $this->Giftcard->get_giftcard_value( $this->input->post( 'amount_tendered' ) ) ) . ' !'; + $this->_reload( $data ); return; } - elseif ( ( $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) - $this->sale_lib->get_total() ) > 0 ) - { - $data['warning']='Giftcard balance is '.to_currency( $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) - $this->sale_lib->get_total() ).' !'; - } - $payment_amount=min( $this->sale_lib->get_total(), $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) ); + + $new_giftcard_value = $this->Giftcard->get_giftcard_value( $this->input->post( 'amount_tendered' ) ) - $this->sale_lib->get_amount_due( ); + $new_giftcard_value = ( $new_giftcard_value >= 0 ) ? $new_giftcard_value : 0; + $data['warning'] = 'Giftcard ' . $this->input->post( 'amount_tendered' ) . ' balance is ' . to_currency( $new_giftcard_value ) . ' !'; + $payment_amount = min( $this->sale_lib->get_amount_due( ), $this->Giftcard->get_giftcard_value( $this->input->post( 'amount_tendered' ) ) ); } else { - $payment_amount=$this->input->post('amount_tendered'); + $payment_amount = $this->input->post( 'amount_tendered' ); } if( !$this->sale_lib->add_payment( $payment_type, $payment_amount ) ) diff --git a/application/hooks/load_config.php b/application/hooks/load_config.php index 33ccfbb77..7f24ea02c 100644 --- a/application/hooks/load_config.php +++ b/application/hooks/load_config.php @@ -3,12 +3,12 @@ function load_config() { $CI =& get_instance(); - foreach($CI->Appconfig->get_all()->result() as $app_config) + foreach( $CI->Appconfig->get_all()->result() as $app_config ) { - $CI->config->set_item($app_config->key,$app_config->value); + $CI->config->set_item( $app_config->key, $app_config->value ); } - if ($CI->config->item('language')) + if ( $CI->config->item( 'language' ) ) { $CI->config->set_item( 'language', $CI->config->item( 'language' ) ); $loaded = $CI->lang->is_loaded; @@ -20,13 +20,13 @@ function load_config() } } - if ($CI->config->item('timezone')) + if ( $CI->config->item( 'timezone' ) ) { - date_default_timezone_set($CI->config->item('timezone')); + date_default_timezone_set( $CI->config->item( 'timezone' ) ); } else { - date_default_timezone_set('America/New_York'); + date_default_timezone_set( 'America/New_York' ); } } ?> \ No newline at end of file diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 3240b0e76..f7c75eb44 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -66,28 +66,28 @@ class Sale_lib $this->CI->session->unset_userdata('email_receipt'); } - function add_payment($payment_id,$payment_amount) + function add_payment( $payment_id, $payment_amount ) { - $payments=$this->get_payments(); - $payment = array($payment_id=> + $payments = $this->get_payments(); + $payment = array( $payment_id=> array( - 'payment_type'=>$payment_id, - 'payment_amount'=>$payment_amount + 'payment_type' => $payment_id, + 'payment_amount' => $payment_amount ) ); //payment_method already exists, add to payment_amount - if(isset($payments[$payment_id])) + if( isset( $payments[$payment_id] ) ) { - $payments[$payment_id]['payment_amount']+=$payment_amount; + $payments[$payment_id]['payment_amount'] += $payment_amount; } else { //add to existing array - $payments+=$payment; + $payments += $payment; } - $this->set_payments($payments); + $this->set_payments( $payments ); return true; } @@ -484,7 +484,7 @@ class Sale_lib $total = 0; foreach($this->get_cart() as $item) { - $total+=($item['price']*$item['quantity']-$item['price']*$item['quantity']*$item['discount']/100); + $total += ( $item['price'] * $item['quantity'] - $item['price'] * $item['quantity'] * $item['discount'] / 100); } foreach($this->get_taxes() as $tax) diff --git a/application/views/reports/graphical.php b/application/views/reports/graphical.php index f185fa8c9..3a89407ee 100644 --- a/application/views/reports/graphical.php +++ b/application/views/reports/graphical.php @@ -9,7 +9,7 @@ $this->load->view("partial/header"); swfobject.embedSWF( "open-flash-chart.swf", "chart", "800", "400", "9.0.0", "expressInstall.swf", -{"data-file":""} ) +{"data-file":""} );