From e17318610990cf58e48bd034a1bbd7c6926616d0 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sun, 16 Jun 2019 10:27:27 +0100 Subject: [PATCH] Temporary fix sale form cash_refund crash, other minor code changes --- application/controllers/Sales.php | 6 +-- application/helpers/dompdf_helper.php | 2 +- application/helpers/locale_helper.php | 66 +++++++++++++------------- application/helpers/tabular_helper.php | 2 +- application/helpers/tax_helper.php | 21 +++++--- 5 files changed, 53 insertions(+), 44 deletions(-) diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index fcbe2b5f3..4c836c3bf 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -822,7 +822,7 @@ class Sales extends Secure_Controller // load pdf helper $this->load->helper(array('dompdf', 'file')); $filename = sys_get_temp_dir() . '/' . $this->lang->line("sales_" . $type) . '-' . str_replace('/', '-', $number) . '.pdf'; - if(file_put_contents($filename, pdf_create($html)) !== FALSE) + if(file_put_contents($filename, create_pdf($html)) !== FALSE) { $result = $this->email_lib->sendEmail($to, $subject, $text, $filename); } @@ -1296,7 +1296,7 @@ class Sales extends Secure_Controller // To maintain tradition we will also delete any payments with 0 amount assuming these are mistakes // introduced at sale time. This is now done in Sale.php - $payments[] = array('payment_id' => $payment_id, 'payment_type' => $payment_type, 'payment_amount' => $payment_amount, 'employee_id' => $employee_id); + $payments[] = array('payment_id' => $payment_id, 'payment_type' => $payment_type, 'payment_amount' => $payment_amount, 'cash_refund' => 0, 'employee_id' => $employee_id); } $payment_id = -1; @@ -1305,7 +1305,7 @@ class Sales extends Secure_Controller if($payment_type != PAYMENT_TYPE_UNASSIGNED && $payment_amount <> 0) { - $payments[] = array('payment_id' => $payment_id, 'payment_type' => $payment_type, 'payment_amount' => $payment_amount, 'employee_id' => $employee_id); + $payments[] = array('payment_id' => $payment_id, 'payment_type' => $payment_type, 'payment_amount' => $payment_amount, 'cash_refund' => 0, 'employee_id' => $employee_id); } if($this->Sale->update($sale_id, $sale_data, $payments)) diff --git a/application/helpers/dompdf_helper.php b/application/helpers/dompdf_helper.php index 3ae9a00c3..ebb02f18f 100644 --- a/application/helpers/dompdf_helper.php +++ b/application/helpers/dompdf_helper.php @@ -4,7 +4,7 @@ * PDF helper */ -function pdf_create($html, $filename = '') +function create_pdf($html, $filename = '') { // need to enable magic quotes for the $magic_quotes_enabled = get_magic_quotes_runtime(); diff --git a/application/helpers/locale_helper.php b/application/helpers/locale_helper.php index 983624532..06f1bca05 100644 --- a/application/helpers/locale_helper.php +++ b/application/helpers/locale_helper.php @@ -4,6 +4,7 @@ const DEFAULT_LANGUAGE = 'english'; const DEFAULT_LANGUAGE_CODE = 'en-US'; define('DEFAULT_DATE', mktime(0, 0, 0, 1, 1, 2010)); +define('DEFAULT_DATETIME', mktime(0, 0, 0, 1, 1, 2010)); /** * Currency locale helper @@ -12,26 +13,27 @@ define('DEFAULT_DATE', mktime(0, 0, 0, 1, 1, 2010)); function current_language_code($load_system_language = FALSE) { $employee = get_instance()->Employee; - + // Returns the language code of the employee if set or system language code if not if($employee->is_logged_in() && $load_system_language != TRUE) { $employee_info = $employee->get_logged_in_employee_info(); - + if(property_exists($employee_info, 'language_code') && !empty($employee_info->language_code)) { return $employee_info->language_code; } } - + $language_code = get_instance()->config->item('language_code'); + return empty($language_code) ? DEFAULT_LANGUAGE_CODE : $language_code; } function current_language($load_system_language = FALSE) { $employee = get_instance()->Employee; - + // Returns the language of the employee if set or system language if not if($employee->is_logged_in() && $load_system_language != TRUE) { @@ -41,8 +43,9 @@ function current_language($load_system_language = FALSE) return $employee_info->language; } } - + $language = get_instance()->config->item('language'); + return empty($language) ? DEFAULT_LANGUAGE : $language; } @@ -79,7 +82,7 @@ function get_languages() function load_language($load_system_language = FALSE, array $lang_array) { $lang = get_instance()->lang; - + if($load_system_language = TRUE) { foreach($lang_array as $language_file) @@ -224,10 +227,10 @@ function get_payment_options() { $config = get_instance()->config; $lang = get_instance()->lang; - + $payments = array(); - - + + if($config->item('payment_options_order') == 'debitcreditcash') { $payments[$lang->line('sales_debit')] = $lang->line('sales_debit'); @@ -258,69 +261,68 @@ function get_payment_options() $payments[$lang->line('sales_debit')] = $lang->line('sales_debit'); $payments[$lang->line('sales_credit')] = $lang->line('sales_credit'); } - + $payments[$lang->line('sales_due')] = $lang->line('sales_due'); $payments[$lang->line('sales_check')] = $lang->line('sales_check'); - + // If India (list of country codes include India) then include Unified Payment Interface if (stripos(get_instance()->config->item('country_codes'), 'IN') !== false) { $payments[$lang->line('sales_upi')] = $lang->line('sales_upi'); } - - + return $payments; } function currency_side() { $config = get_instance()->config; - + $fmt = new \NumberFormatter($config->item('number_locale'), \NumberFormatter::CURRENCY); $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); - + return !preg_match('/^ยค/', $fmt->getPattern()); } function quantity_decimals() { $config = get_instance()->config; - + return $config->item('quantity_decimals') ? $config->item('quantity_decimals') : 0; } function totals_decimals() { $config = get_instance()->config; - + return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0; } function cash_decimals() { $config = get_instance()->config; - + return $config->item('cash_decimals') ? $config->item('cash_decimals') : 0; } function tax_decimals() { $config = get_instance()->config; - + return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0; } function to_date($date = DEFAULT_DATE) { $config = get_instance()->config; - + return date($config->item('dateformat'), $date); } -function to_datetime($datetime = DEFAULT_DATE) +function to_datetime($datetime = DEFAULT_DATETIME) { $config = get_instance()->config; - + return date($config->item('dateformat') . ' ' . $config->item('timeformat'), $datetime); } @@ -337,7 +339,7 @@ function to_currency_no_money($number) function to_currency_tax($number) { $config = get_instance()->config; - + if($config->item('tax_included') == '1') { return to_decimals($number, 'tax_decimals', \NumberFormatter::CURRENCY); @@ -356,7 +358,7 @@ function to_tax_decimals($number) { return $number; } - + return to_decimals($number, 'tax_decimals'); } @@ -373,7 +375,7 @@ function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL) { return $number; } - + $config = get_instance()->config; $fmt = new \NumberFormatter($config->item('number_locale'), $type); $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals)); @@ -383,7 +385,7 @@ function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL) $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); } $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); - + return $fmt->format($number); } @@ -394,17 +396,17 @@ function parse_decimals($number) { return $number; } - + $config = get_instance()->config; $fmt = new \NumberFormatter($config->item('number_locale'), \NumberFormatter::DECIMAL); - + $fmt->setAttribute(\NumberFormatter::FRACTION_DIGITS, $config->item('currency_decimals')); - + if(empty($config->item('thousands_separator'))) { $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); } - + try { return $fmt->parse($number); @@ -460,7 +462,7 @@ function dateformat_momentjs($php_format) 'r' => '', // no equivalent 'U' => 'X' ); - + return strtr($php_format, $SYMBOLS_MATCHING); } @@ -545,7 +547,7 @@ function dateformat_bootstrap($php_format) 's' => 'ss', 'u' => '' ); - + return strtr($php_format, $SYMBOLS_MATCHING); } diff --git a/application/helpers/tabular_helper.php b/application/helpers/tabular_helper.php index 37e62a652..55775acd4 100644 --- a/application/helpers/tabular_helper.php +++ b/application/helpers/tabular_helper.php @@ -156,7 +156,7 @@ function get_sales_manage_payments_summary($payments, $sales) // WARNING: the strong assumption here is that if a change is due it was a cash transaction always // therefore we remove from the total cash amount any change due - if( $payment['payment_type'] == $CI->lang->line('sales_cash') ) + if($payment['payment_type'] == $CI->lang->line('sales_cash')) { foreach($sales->result_array() as $key=>$sale) { diff --git a/application/helpers/tax_helper.php b/application/helpers/tax_helper.php index 75273ffe1..6f95a1c71 100644 --- a/application/helpers/tax_helper.php +++ b/application/helpers/tax_helper.php @@ -27,7 +27,8 @@ Get the html data row for the tax function get_tax_code_data_row($tax_code_row) { $CI =& get_instance(); - $controller_name='tax_codes'; + + $controller_name = 'tax_codes'; return array ( 'tax_code' => $tax_code_row->tax_code, @@ -37,7 +38,8 @@ function get_tax_code_data_row($tax_code_row) 'state' => $tax_code_row->state, 'edit' => anchor($controller_name."/view_tax_codes/$tax_code_row->tax_code", '', array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update_tax_codes')) - )); + ) + ); } /* @@ -62,7 +64,8 @@ Get the html data row for the tax function get_tax_categories_data_row($tax_categories_row) { $CI =& get_instance(); - $controller_name='tax_categories'; + + $controller_name = 'tax_categories'; return array ( 'tax_category_id' => $tax_categories_row->tax_category_id, @@ -71,7 +74,8 @@ function get_tax_categories_data_row($tax_categories_row) 'tax_group_sequence' => $tax_categories_row->tax_group_sequence, 'edit' => anchor($controller_name."/view/$tax_categories_row->tax_category_id", '', array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update')) - )); + ) + ); } /* @@ -104,7 +108,8 @@ function get_tax_jurisdictions_data_row($tax_jurisdiction_row) 'reporting_authority' => $tax_jurisdiction_row->reporting_authority, 'edit' => anchor($controller_name."/view/$tax_jurisdiction_row->jurisdiction_id", '', array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update')) - )); + ) + ); } /* @@ -132,7 +137,8 @@ Get the html data row for the tax function get_tax_rates_data_row($tax_rates_row) { $CI =& get_instance(); - $controller_name=strtolower(get_class($CI)); + + $controller_name = strtolower(get_class($CI)); return array ( 'tax_rate_id' => $tax_rates_row->tax_rate_id, @@ -145,7 +151,8 @@ function get_tax_rates_data_row($tax_rates_row) 'rounding_code_name' => Rounding_mode::get_rounding_code_name($tax_rates_row->tax_rounding_code), 'edit' => anchor($controller_name."/view/$tax_rates_row->tax_rate_id", '', array('class'=>'modal-dlg', 'data-btn-submit' => $CI->lang->line('common_submit'), 'title'=>$CI->lang->line($controller_name.'_update')) - )); + ) + ); } ?>