diff --git a/docs/404.html b/docs/404.html index 509d6f2db..b0cc1b2d4 100644 --- a/docs/404.html +++ b/docs/404.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Appconfig.html b/docs/class-Appconfig.html index 1ff955fdf..51c80dcb9 100644 --- a/docs/class-Appconfig.html +++ b/docs/class-Appconfig.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Barcode_lib.html b/docs/class-Barcode_lib.html index 0fcedf458..fd092f1e9 100644 --- a/docs/class-Barcode_lib.html +++ b/docs/class-Barcode_lib.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Config.html b/docs/class-Config.html index ed09bf0b6..a311093df 100644 --- a/docs/class-Config.html +++ b/docs/class-Config.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,7 +242,7 @@ CI_Controller - Located at controllers/Config.php + Located at controllers/Config.php
    @@ -685,7 +686,7 @@ CI_Controller
    # - save_tables( ) + save_tables( )
    @@ -715,7 +716,7 @@ CI_Controller
    # - save_rewards( ) + save_rewards( )
    @@ -745,7 +746,7 @@ CI_Controller
    # - save_barcode( ) + save_barcode( )
    @@ -775,7 +776,7 @@ CI_Controller
    # - save_receipt( ) + save_receipt( )
    @@ -805,7 +806,7 @@ CI_Controller
    # - save_invoice( ) + save_invoice( )
    @@ -835,7 +836,7 @@ CI_Controller
    # - remove_logo( ) + remove_logo( )
    @@ -865,7 +866,7 @@ CI_Controller
    # - backup_db( ) + backup_db( )
    diff --git a/docs/class-Customer.html b/docs/class-Customer.html index 2ec9f5310..5fff6f104 100644 --- a/docs/class-Customer.html +++ b/docs/class-Customer.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Customer_rewards.html b/docs/class-Customer_rewards.html index ed4ff71d9..c7272f636 100644 --- a/docs/class-Customer_rewards.html +++ b/docs/class-Customer_rewards.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Customers.html b/docs/class-Customers.html index 21dc16ccc..c3df79581 100644 --- a/docs/class-Customers.html +++ b/docs/class-Customers.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Detailed_receivings.html b/docs/class-Detailed_receivings.html index 4392aca9f..8371f1bb2 100644 --- a/docs/class-Detailed_receivings.html +++ b/docs/class-Detailed_receivings.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Detailed_sales.html b/docs/class-Detailed_sales.html index 86811d194..043bfb264 100644 --- a/docs/class-Detailed_sales.html +++ b/docs/class-Detailed_sales.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Dinner_table.html b/docs/class-Dinner_table.html index 28f72aaf5..4ba7e239e 100644 --- a/docs/class-Dinner_table.html +++ b/docs/class-Dinner_table.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Email_lib.html b/docs/class-Email_lib.html index 0bb8c1ce1..60075c614 100644 --- a/docs/class-Email_lib.html +++ b/docs/class-Email_lib.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Employee.html b/docs/class-Employee.html index 155954094..450d9a727 100644 --- a/docs/class-Employee.html +++ b/docs/class-Employee.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Employees.html b/docs/class-Employees.html index d92e0c549..2e8b4de5e 100644 --- a/docs/class-Employees.html +++ b/docs/class-Employees.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Giftcard.html b/docs/class-Giftcard.html index 1291a915c..6f837b530 100644 --- a/docs/class-Giftcard.html +++ b/docs/class-Giftcard.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Giftcards.html b/docs/class-Giftcards.html index f14595419..3747dce8f 100644 --- a/docs/class-Giftcards.html +++ b/docs/class-Giftcards.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Home.html b/docs/class-Home.html index 6efe2b519..60e2aeb80 100644 --- a/docs/class-Home.html +++ b/docs/class-Home.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Inventory.html b/docs/class-Inventory.html index 883980545..2c96107dd 100644 --- a/docs/class-Inventory.html +++ b/docs/class-Inventory.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Inventory_low.html b/docs/class-Inventory_low.html index e8634c267..4c1b0b72d 100644 --- a/docs/class-Inventory_low.html +++ b/docs/class-Inventory_low.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Inventory_summary.html b/docs/class-Inventory_summary.html index fb1b4eced..0834f7771 100644 --- a/docs/class-Inventory_summary.html +++ b/docs/class-Inventory_summary.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Item.html b/docs/class-Item.html index c77a3f578..43a4478aa 100644 --- a/docs/class-Item.html +++ b/docs/class-Item.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Item_kit.html b/docs/class-Item_kit.html index e5fb301bb..f78ef3aeb 100644 --- a/docs/class-Item_kit.html +++ b/docs/class-Item_kit.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Item_kit_items.html b/docs/class-Item_kit_items.html index 40f2c61d5..276b4b96c 100644 --- a/docs/class-Item_kit_items.html +++ b/docs/class-Item_kit_items.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Item_kits.html b/docs/class-Item_kits.html index b1bb75f1c..3dc641ea4 100644 --- a/docs/class-Item_kits.html +++ b/docs/class-Item_kits.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Item_lib.html b/docs/class-Item_lib.html index 234808cd6..aade3ab30 100644 --- a/docs/class-Item_lib.html +++ b/docs/class-Item_lib.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Item_quantity.html b/docs/class-Item_quantity.html index d6b2ae675..1936146ec 100644 --- a/docs/class-Item_quantity.html +++ b/docs/class-Item_quantity.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Item_taxes.html b/docs/class-Item_taxes.html index dc79bf451..240377779 100644 --- a/docs/class-Item_taxes.html +++ b/docs/class-Item_taxes.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Items.html b/docs/class-Items.html index bf6e42310..14ac4455c 100644 --- a/docs/class-Items.html +++ b/docs/class-Items.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Login.html b/docs/class-Login.html index 126b4e359..6e2ff93ff 100644 --- a/docs/class-Login.html +++ b/docs/class-Login.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-MY_Lang.html b/docs/class-MY_Lang.html index 03631e5cb..6e5b8a15c 100644 --- a/docs/class-MY_Lang.html +++ b/docs/class-MY_Lang.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-MailchimpConnector.html b/docs/class-MailchimpConnector.html index 577979d1b..35af10dcf 100644 --- a/docs/class-MailchimpConnector.html +++ b/docs/class-MailchimpConnector.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Mailchimp_lib.html b/docs/class-Mailchimp_lib.html index 77a599ee0..a45768a7e 100644 --- a/docs/class-Mailchimp_lib.html +++ b/docs/class-Mailchimp_lib.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Messages.html b/docs/class-Messages.html index 4e0856067..38e489806 100644 --- a/docs/class-Messages.html +++ b/docs/class-Messages.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Migrate.html b/docs/class-Migrate.html index 903e94a61..5b3e118b9 100644 --- a/docs/class-Migrate.html +++ b/docs/class-Migrate.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Migration_Sales_Tax_Data.html b/docs/class-Migration_Sales_Tax_Data.html index 4bc3c28f8..3434aa32f 100644 --- a/docs/class-Migration_Sales_Tax_Data.html +++ b/docs/class-Migration_Sales_Tax_Data.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Module.html b/docs/class-Module.html index 2e2b2fb10..65e4a2d17 100644 --- a/docs/class-Module.html +++ b/docs/class-Module.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-No_Access.html b/docs/class-No_Access.html index e85c04220..5c5ed1d29 100644 --- a/docs/class-No_Access.html +++ b/docs/class-No_Access.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Person.html b/docs/class-Person.html index b0d0e86d9..cce11105c 100644 --- a/docs/class-Person.html +++ b/docs/class-Person.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Persons.html b/docs/class-Persons.html index 5df205e43..368e31411 100644 --- a/docs/class-Persons.html +++ b/docs/class-Persons.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Receiving.html b/docs/class-Receiving.html index 4c832868a..fc7640e71 100644 --- a/docs/class-Receiving.html +++ b/docs/class-Receiving.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Receiving_lib.html b/docs/class-Receiving_lib.html index f1c74be6d..8eb6b4a13 100644 --- a/docs/class-Receiving_lib.html +++ b/docs/class-Receiving_lib.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Receivings.html b/docs/class-Receivings.html index c74525ce8..13acbc61b 100644 --- a/docs/class-Receivings.html +++ b/docs/class-Receivings.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Report.html b/docs/class-Report.html index fa68ee2c9..668235a4b 100644 --- a/docs/class-Report.html +++ b/docs/class-Report.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Reports.html b/docs/class-Reports.html index d80aec2ff..5963c7f7e 100644 --- a/docs/class-Reports.html +++ b/docs/class-Reports.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Rewards.html b/docs/class-Rewards.html index 8241416b6..846e53c1e 100644 --- a/docs/class-Rewards.html +++ b/docs/class-Rewards.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Rounding_code.html b/docs/class-Rounding_code.html index f45d12e30..59b3ecb2d 100644 --- a/docs/class-Rounding_code.html +++ b/docs/class-Rounding_code.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • diff --git a/docs/class-Sale.html b/docs/class-Sale.html index 0da946969..fbea55672 100644 --- a/docs/class-Sale.html +++ b/docs/class-Sale.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -243,7 +244,7 @@ CI_Model 1.0
    Link: github.com/jekkos/opensourcepos
    - Located at models/Sale.php + Located at models/Sale.php
    @@ -263,7 +264,7 @@ CI_Model
    # - get_info( $sale_id ) + get_info( $sale_id )

    Get sale info

    @@ -293,7 +294,7 @@ CI_Model
    # - get_found_rows( $search, $filters ) + get_found_rows( $search, $filters )

    Get number of rows for the takings (sales/manage) view

    @@ -323,7 +324,7 @@ CI_Model
    # - search( $search, $filters, $rows = 0, $limit_from = 0, $sort = 'sale_time', $order = 'desc' ) + search( $search, $filters, $rows = 0, $limit_from = 0, $sort = 'sale_time', $order = 'desc' )

    Get the sales data for the takings (sales/manage) view

    @@ -353,7 +354,7 @@ CI_Model
    # - get_payments_summary( $search, $filters ) + get_payments_summary( $search, $filters )

    Get the payment summary for the takings (sales/manage) view

    @@ -383,7 +384,7 @@ CI_Model
    # - get_total_rows( ) + get_total_rows( )

    Gets total of rows

    @@ -413,7 +414,7 @@ CI_Model
    # - get_search_suggestions( $search, $limit = 25 ) + get_search_suggestions( $search, $limit = 25 )

    Gets search suggestions

    @@ -443,7 +444,7 @@ CI_Model
    # - get_invoice_count( ) + get_invoice_count( )

    Gets total of invoice rows

    @@ -473,7 +474,7 @@ CI_Model
    # - get_sale_by_invoice_number( $invoice_number ) + get_sale_by_invoice_number( $invoice_number )

    Gets sale by invoice number

    @@ -503,7 +504,7 @@ CI_Model
    # - get_invoice_number_for_year( $year = '', $start_from = 0 ) + get_invoice_number_for_year( $year = '', $start_from = 0 )

    Gets invoice number by year

    @@ -533,7 +534,7 @@ CI_Model
    # - is_valid_receipt( & $receipt_sale_id ) + is_valid_receipt( & $receipt_sale_id )

    Checks if valid receipt

    @@ -563,7 +564,7 @@ CI_Model
    # - exists( $sale_id ) + exists( $sale_id )

    Checks if sale exists

    @@ -593,7 +594,7 @@ CI_Model
    # - update( $sale_id, $sale_data, $payments ) + update( $sale_id, $sale_data, $payments )

    Update sale

    @@ -623,7 +624,7 @@ CI_Model
    # - save( & $sale_status, & $items, $customer_id, $employee_id, $comment, $invoice_number, $quote_number, $payments, $dinner_table, & $sales_taxes, $sale_id = FALSE ) + save( & $sale_status, & $items, $customer_id, $employee_id, $comment, $invoice_number, $quote_number, $payments, $dinner_table, & $sales_taxes, $sale_id = FALSE )

    Save the sale information after the sales is complete but before the final document is printed @@ -655,7 +656,7 @@ The sales_taxes variable needs to be initialized to an empty array before callin

    # - save_sales_item_tax( & $customer, & $sale_id, & $item, $tax_basis, & $sales_taxes, & $sequence, $tax_category_id ) + save_sales_item_tax( & $customer, & $sale_id, & $item, $tax_basis, & $sales_taxes, & $sequence, $tax_category_id )

    Apply customer sales tax if the customer sales tax is enabledl @@ -693,7 +694,7 @@ as a separate tax entry on the invoice.

    # - save_sales_tax( & $sales_taxes ) + save_sales_tax( & $sales_taxes )

    Saves sale tax

    @@ -723,7 +724,7 @@ as a separate tax entry on the invoice.

    # - delete_list( $sale_ids, $employee_id, $update_inventory = TRUE ) + delete_list( $sale_ids, $employee_id, $update_inventory = TRUE )

    Deletes list of sales

    @@ -753,7 +754,7 @@ as a separate tax entry on the invoice.

    # - delete( $sale_id, $employee_id, $update_inventory = TRUE ) + delete( $sale_id, $employee_id, $update_inventory = TRUE )

    Delete sale

    @@ -783,7 +784,7 @@ as a separate tax entry on the invoice.

    # - get_sale_items( $sale_id ) + get_sale_items( $sale_id )

    Gets sale item

    @@ -813,7 +814,7 @@ as a separate tax entry on the invoice.

    # - get_sale_items_ordered( $sale_id ) + get_sale_items_ordered( $sale_id )

    Used by the invoice and receipt programs

    @@ -843,7 +844,7 @@ as a separate tax entry on the invoice.

    # - get_sale_payments( $sale_id ) + get_sale_payments( $sale_id )

    Gets sale payments

    @@ -873,7 +874,7 @@ as a separate tax entry on the invoice.

    # - get_payment_options( $giftcard = TRUE, $reward_points = FALSE ) + get_payment_options( $giftcard = TRUE, $reward_points = FALSE )

    Gets sale payment options

    @@ -903,7 +904,7 @@ as a separate tax entry on the invoice.

    # - get_customer( $sale_id ) + get_customer( $sale_id )

    Gets sale customer name

    @@ -933,7 +934,7 @@ as a separate tax entry on the invoice.

    # - get_employee( $sale_id ) + get_employee( $sale_id )

    Gets sale employee name

    @@ -963,7 +964,7 @@ as a separate tax entry on the invoice.

    # - check_quote_number_exists( $quote_number, $sale_id = '' ) + check_quote_number_exists( $quote_number, $sale_id = '' )
    @@ -993,7 +994,7 @@ as a separate tax entry on the invoice.

    # - check_invoice_number_exists( $invoice_number, $sale_id = '' ) + check_invoice_number_exists( $invoice_number, $sale_id = '' )

    Checks if invoice number exists

    @@ -1023,7 +1024,7 @@ as a separate tax entry on the invoice.

    # - get_giftcard_value( $giftcardNumber ) + get_giftcard_value( $giftcardNumber )

    Gets Giftcard value

    @@ -1053,7 +1054,7 @@ as a separate tax entry on the invoice.

    # - create_temp_table( array $inputs ) + create_temp_table( array $inputs )

    Creates sales temporary dimentional table @@ -1085,7 +1086,7 @@ We create a temp table that allows us to do easy report/sales queries

    # - get_all_suspended( $customer_id = NULL ) + get_all_suspended( $customer_id = NULL )

    Retrieves all sales that are in a suspended state

    @@ -1115,7 +1116,7 @@ We create a temp table that allows us to do easy report/sales queries

    # - get_dinner_table( $sale_id ) + get_dinner_table( $sale_id )

    Gets the dinner table for the selected sale

    @@ -1145,7 +1146,7 @@ We create a temp table that allows us to do easy report/sales queries

    # - get_quote_number( $sale_id ) + get_quote_number( $sale_id )

    Gets the quote_number for the selected sale

    @@ -1175,7 +1176,7 @@ We create a temp table that allows us to do easy report/sales queries

    # - get_comment( $sale_id ) + get_comment( $sale_id )

    Gets the quote_number for the selected sale

    @@ -1205,7 +1206,7 @@ We create a temp table that allows us to do easy report/sales queries

    # - get_suspended_invoice_count( ) + get_suspended_invoice_count( )

    Gets total of suspended invoices rows

    @@ -1235,7 +1236,7 @@ We create a temp table that allows us to do easy report/sales queries

    # - delete_suspended_sale( $sale_id ) + delete_suspended_sale( $sale_id )

    Removes a selected sale from the sales table. @@ -1267,7 +1268,7 @@ This function should only be called for suspended sales that are being restored

    # - get_suspended_sale_info( $sale_id ) + get_suspended_sale_info( $sale_id )

    Gets suspended sale info

    diff --git a/docs/class-Sale_lib.html b/docs/class-Sale_lib.html index c53001529..9a520df5a 100644 --- a/docs/class-Sale_lib.html +++ b/docs/class-Sale_lib.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -232,7 +233,7 @@ 1.0
    Link: github.com/jekkos/opensourcepos
    - Located at libraries/Sale_lib.php + Located at libraries/Sale_lib.php
    @@ -1302,14 +1303,16 @@
    # - get_totals( ) + get_totals( )
    - +

    Returns 'subtotal', 'total', 'cash_total', 'payment_total', 'amount_due', 'cash_amount_due', 'paid_in_full' +'subtotal', 'discounted_subtotal', 'tax_exclusive_subtotal'

    - + diff --git a/docs/function-get_sales_manage_table_headers.html b/docs/function-get_sales_manage_table_headers.html index 784f71a39..0e415fb61 100644 --- a/docs/function-get_sales_manage_table_headers.html +++ b/docs/function-get_sales_manage_table_headers.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -228,6 +229,6 @@
    - + diff --git a/docs/function-get_supplier_data_row.html b/docs/function-get_supplier_data_row.html index cdcd0adfb..93d8e5793 100644 --- a/docs/function-get_supplier_data_row.html +++ b/docs/function-get_supplier_data_row.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,6 +242,6 @@
    - + diff --git a/docs/function-get_suppliers_manage_table_headers.html b/docs/function-get_suppliers_manage_table_headers.html index aba6bb0b9..c5e639f8e 100644 --- a/docs/function-get_suppliers_manage_table_headers.html +++ b/docs/function-get_suppliers_manage_table_headers.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -228,6 +229,6 @@
    - + diff --git a/docs/function-get_tax_data_row.html b/docs/function-get_tax_data_row.html index c5615b2ce..69c3f6526 100644 --- a/docs/function-get_tax_data_row.html +++ b/docs/function-get_tax_data_row.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,6 +242,6 @@
    - + diff --git a/docs/function-get_taxes_manage_table_headers.html b/docs/function-get_taxes_manage_table_headers.html index 8af64be8d..90485779e 100644 --- a/docs/function-get_taxes_manage_table_headers.html +++ b/docs/function-get_taxes_manage_table_headers.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -228,6 +229,6 @@
    - + diff --git a/docs/function-load_config.html b/docs/function-load_config.html index 0b8b1ef30..4f69d88e5 100644 --- a/docs/function-load_config.html +++ b/docs/function-load_config.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -228,6 +229,6 @@
    - + diff --git a/docs/function-load_language_files.html b/docs/function-load_language_files.html index 9eb72cb03..71e4df47e 100644 --- a/docs/function-load_language_files.html +++ b/docs/function-load_language_files.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,6 +242,6 @@
    - + diff --git a/docs/function-load_stats.html b/docs/function-load_stats.html index c0f83f25e..f798eeb98 100644 --- a/docs/function-load_stats.html +++ b/docs/function-load_stats.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -228,6 +229,6 @@
    - + diff --git a/docs/function-parse_decimals.html b/docs/function-parse_decimals.html index d1bac804a..f7b27a6f1 100644 --- a/docs/function-parse_decimals.html +++ b/docs/function-parse_decimals.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -211,7 +212,7 @@ Located at - + helpers/locale_helper.php
    @@ -236,6 +237,6 @@
    - + diff --git a/docs/function-pdf_create.html b/docs/function-pdf_create.html index 06b71aa7f..df2fcf52d 100644 --- a/docs/function-pdf_create.html +++ b/docs/function-pdf_create.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,6 +242,6 @@
    - + diff --git a/docs/function-quantity_decimals.html b/docs/function-quantity_decimals.html index fc0716d26..65d16934c 100644 --- a/docs/function-quantity_decimals.html +++ b/docs/function-quantity_decimals.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -211,7 +212,7 @@ Located at - + helpers/locale_helper.php
    @@ -228,6 +229,6 @@
    - + diff --git a/docs/function-show_report.html b/docs/function-show_report.html index 60f816dd1..d4d660607 100644 --- a/docs/function-show_report.html +++ b/docs/function-show_report.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -246,6 +247,6 @@
    - + diff --git a/docs/function-show_report_if_allowed.html b/docs/function-show_report_if_allowed.html index 41538bbf3..35f3caadc 100644 --- a/docs/function-show_report_if_allowed.html +++ b/docs/function-show_report_if_allowed.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -251,6 +252,6 @@
    - + diff --git a/docs/function-tax_decimals.html b/docs/function-tax_decimals.html new file mode 100644 index 000000000..c4b94f932 --- /dev/null +++ b/docs/function-tax_decimals.html @@ -0,0 +1,234 @@ + + + + + + Function tax_decimals + + + + + + +
    + +
    + +
    + + + + + + diff --git a/docs/function-to_currency.html b/docs/function-to_currency.html index 1f192c20f..c41c83212 100644 --- a/docs/function-to_currency.html +++ b/docs/function-to_currency.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -211,7 +212,7 @@ Located at - + helpers/locale_helper.php
    @@ -236,6 +237,6 @@
    - + diff --git a/docs/function-to_currency_no_money.html b/docs/function-to_currency_no_money.html index e1724b861..c0c318dad 100644 --- a/docs/function-to_currency_no_money.html +++ b/docs/function-to_currency_no_money.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -211,7 +212,7 @@ Located at - + helpers/locale_helper.php
    @@ -236,6 +237,6 @@
    - + diff --git a/docs/function-to_decimals.html b/docs/function-to_decimals.html index ef8af27ec..ec39c85de 100644 --- a/docs/function-to_decimals.html +++ b/docs/function-to_decimals.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -211,7 +212,7 @@ Located at - + helpers/locale_helper.php
    @@ -246,6 +247,6 @@
    - + diff --git a/docs/function-to_quantity_decimals.html b/docs/function-to_quantity_decimals.html index 6503fe8d9..9f83d9e4e 100644 --- a/docs/function-to_quantity_decimals.html +++ b/docs/function-to_quantity_decimals.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -211,7 +212,7 @@ Located at - + helpers/locale_helper.php
    @@ -236,6 +237,6 @@
    - + diff --git a/docs/function-to_tax_decimals.html b/docs/function-to_tax_decimals.html index 2e180c4f0..45c1eaeea 100644 --- a/docs/function-to_tax_decimals.html +++ b/docs/function-to_tax_decimals.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -211,7 +212,7 @@ Located at - + helpers/locale_helper.php
    @@ -236,6 +237,6 @@
    - + diff --git a/docs/function-totals_decimals.html b/docs/function-totals_decimals.html index b94507677..25c2c9980 100644 --- a/docs/function-totals_decimals.html +++ b/docs/function-totals_decimals.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -211,7 +212,7 @@ Located at - + helpers/locale_helper.php
    @@ -228,6 +229,6 @@
    - + diff --git a/docs/function-transform_headers.html b/docs/function-transform_headers.html index 058678f91..95b824a69 100644 --- a/docs/function-transform_headers.html +++ b/docs/function-transform_headers.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -246,6 +247,6 @@
    - + diff --git a/docs/function-transform_headers_readonly.html b/docs/function-transform_headers_readonly.html index f4b49054f..c87255fd5 100644 --- a/docs/function-transform_headers_readonly.html +++ b/docs/function-transform_headers_readonly.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -236,6 +237,6 @@
    - + diff --git a/docs/index.html b/docs/index.html index b5d8ac3aa..2f21d4dd9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -166,6 +166,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -230,6 +231,6 @@
    - + diff --git a/docs/namespace-None.html b/docs/namespace-None.html index 36f499026..1a91ffec0 100644 --- a/docs/namespace-None.html +++ b/docs/namespace-None.html @@ -162,6 +162,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -656,6 +657,10 @@ show_report_if_allowed + + tax_decimals + + to_currency @@ -697,6 +702,6 @@
    - + diff --git a/docs/namespace-emberlabs.Barcode.html b/docs/namespace-emberlabs.Barcode.html index 636857b71..34339f03d 100644 --- a/docs/namespace-emberlabs.Barcode.html +++ b/docs/namespace-emberlabs.Barcode.html @@ -131,6 +131,6 @@
    - + diff --git a/docs/namespace-emberlabs.html b/docs/namespace-emberlabs.html index efe5aa5f7..b990231af 100644 --- a/docs/namespace-emberlabs.html +++ b/docs/namespace-emberlabs.html @@ -100,6 +100,6 @@
    - + diff --git a/docs/source-class-Appconfig.html b/docs/source-class-Appconfig.html index c07c28f4c..646382ce3 100644 --- a/docs/source-class-Appconfig.html +++ b/docs/source-class-Appconfig.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -317,6 +318,6 @@
    - + diff --git a/docs/source-class-Barcode_lib.html b/docs/source-class-Barcode_lib.html index 78d132af4..566aa34a5 100644 --- a/docs/source-class-Barcode_lib.html +++ b/docs/source-class-Barcode_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -459,6 +460,6 @@
    - + diff --git a/docs/source-class-Config.html b/docs/source-class-Config.html index 0c24b50bc..0aac05c01 100644 --- a/docs/source-class-Config.html +++ b/docs/source-class-Config.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@
    -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821: 822: 823: 824: 825: 826: 827: 828: 829: 830: 831: 832: 833: 834: 835: 836: 837: 838: 839: 840: 841: 842: 843: 844: 845: 846: 847: 848: 849: 850: 851: 852: 853: 854: 855: 856: 857: 858: 859: 860: 861: 862: 863: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     require_once("Secure_Controller.php");
    @@ -762,301 +763,315 @@
         {
             $this->db->trans_start();
     
    -        $this->Appconfig->save('dinner_table_enable',$this->input->post('dinner_table_enable'));
    +        $dinner_table_enable = $this->input->post('dinner_table_enable') != NULL;
     
    -        $deleted_tables = $this->Dinner_table->get_all()->result_array();
    -        $not_to_delete = array();
    -        foreach($this->input->post() as $key => $value)
    +        $this->Appconfig->save('dinner_table_enable', $dinner_table_enable);
    +
    +        if($dinner_table_enable)
             {
    -            if(strstr($key, 'dinner_table') && $key != 'dinner_table_enable')
    -            {
    -
    -                $dinner_table_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
    -                $not_to_delete[] = $dinner_table_id;
    -
    -                // save or update
    -                $table_data = array('name' => $value);
    -                if($this->Dinner_table->save($table_data, $dinner_table_id))
    -                {
    -                    $this->_clear_session_state();
    -                }
    -            }
    -        }
    -
    -        // all locations not available in post will be deleted now
    -        foreach($deleted_tables as $dinner_table)
    -        {
    -            if(!in_array($dinner_table['dinner_table_id'],$not_to_delete))
    -            {
    -                $this->Dinner_table->delete($dinner_table['dinner_table_id']);
    -            }
    -        }
    -
    -        $this->db->trans_complete();
    -
    -        $success = $this->db->trans_status();
    -
    -        echo json_encode(array(
    -            'success' => $success,
    -            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    -        ));
    -    }
    -
    -    public function save_rewards()
    -    {
    -        $this->db->trans_start();
    -
    -        $this->Appconfig->save('customer_reward_enable', $this->input->post('customer_reward_enable'));
    -
    -        $deleted_packages = $this->Customer_rewards->get_all()->result_array();
    -        $not_to_delete = array();
    -        $array_save = array();
    -        foreach($this->input->post() as $key => $value)
    -        {
    -            if(strstr($key, 'reward_points') && $key != 'customer_reward_enable')
    -            {
    -                $customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
    -                $not_to_delete[] = $customer_reward_id;
    -                $array_save[$customer_reward_id]['points_percent'] = $value;
    -            }
    -
    -            if(strstr($key, 'customer_reward') && $key != 'customer_reward_enable')
    -            {
    -                $customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
    -                $not_to_delete[] = $customer_reward_id;
    -                $array_save[$customer_reward_id]['package_name'] = $value;
    -            }
    -        }
    -
    -        if(!empty($array_save))
    -        {
    -            foreach($array_save as $key => $value)
    -            {
    -                // save or update
    -                $table_data = array('package_name' => $value['package_name'], 'points_percent' => $value['points_percent']);
    -                if($this->Customer_rewards->save($table_data, $key))
    -                {
    -                    $this->_clear_session_state();
    -                }
    -            }
    -        }
    -
    -        // all locations not available in post will be deleted now
    -        foreach($deleted_packages as $customer_reward)
    -        {
    -            if(!in_array($customer_reward['customer_reward_id'], $not_to_delete))
    -            {
    -                $this->Customer_rewards->delete($customer_reward['customer_reward_id']);
    -            }
    -        }
    -
    -        $this->db->trans_complete();
    +            $not_to_delete = array();
    +            foreach($this->input->post() as $key => $value)
    +            {
    +                if(strstr($key, 'dinner_table') && $key != 'dinner_table_enable')
    +                {
    +                    $dinner_table_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
    +                    $not_to_delete[] = $dinner_table_id;
    +
    +                    // save or update
    +                    $table_data = array('name' => $value);
    +                    if($this->Dinner_table->save($table_data, $dinner_table_id))
    +                    {
    +                        $this->_clear_session_state();
    +                    }
    +                }
    +            }
    +
    +            // all locations not available in post will be deleted now
    +            $deleted_tables = $this->Dinner_table->get_all()->result_array();
    +
    +            foreach($deleted_tables as $dinner_table)
    +            {
    +                if(!empty($customer_reward['dinner_table_id']) && !in_array($dinner_table['dinner_table_id'], $not_to_delete))
    +                {
    +                    $this->Dinner_table->delete($dinner_table['dinner_table_id']);
    +                }
    +            }
    +        }
    +
    +        $this->db->trans_complete();
    +
    +        $success = $this->db->trans_status();
    +
    +        echo json_encode(array(
    +            'success' => $success,
    +            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    +        ));
    +    }
    +
    +    public function save_rewards()
    +    {
    +        $this->db->trans_start();
    +
    +        $customer_reward_enable = $this->input->post('customer_reward_enable') != NULL;
    +
    +        $this->Appconfig->save('customer_reward_enable', $customer_reward_enable);
    +
    +        if($customer_reward_enable)
    +        {
    +            $not_to_delete = array();
    +            $array_save = array();
    +            foreach($this->input->post() as $key => $value)
    +            {
    +                if(strstr($key, 'customer_reward_enable'))
    +                {
    +                    // skip the check box
    +                }
    +                elseif(strstr($key, 'customer_reward'))
    +                {
    +                    $customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
    +                    $not_to_delete[] = $customer_reward_id;
    +                    $array_save[$customer_reward_id]['package_name'] = $value;
    +                }
    +                elseif(strstr($key, 'reward_points'))
    +                {
    +                    $customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key);
    +                    $not_to_delete[] = $customer_reward_id;
    +                    $array_save[$customer_reward_id]['points_percent'] = $value;
    +                }
    +            }
    +
    +            if(!empty($array_save))
    +            {
    +                foreach($array_save as $key => $value)
    +                {
    +                    // save or update
    +                    $table_data = array('package_name' => $value['package_name'], 'points_percent' => $value['points_percent']);
    +                    if($this->Customer_rewards->save($table_data, $key))
    +                    {
    +                        $this->_clear_session_state();
    +                    }
    +                }
    +            }
     
    -        $success = $this->db->trans_status();
    -
    -        echo json_encode(array(
    -            'success' => $success,
    -            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    -        ));
    -    }
    -
    -    public function save_barcode()
    -    {
    -        $batch_save_data = array(
    -            'barcode_type' => $this->input->post('barcode_type'),
    -            'barcode_quality' => $this->input->post('barcode_quality'),
    -            'barcode_width' => $this->input->post('barcode_width'),
    -            'barcode_height' => $this->input->post('barcode_height'),
    -            'barcode_font' => $this->input->post('barcode_font'),
    -            'barcode_font_size' => $this->input->post('barcode_font_size'),
    -            'barcode_first_row' => $this->input->post('barcode_first_row'),
    -            'barcode_second_row' => $this->input->post('barcode_second_row'),
    -            'barcode_third_row' => $this->input->post('barcode_third_row'),
    -            'barcode_num_in_row' => $this->input->post('barcode_num_in_row'),
    -            'barcode_page_width' => $this->input->post('barcode_page_width'),
    -            'barcode_page_cellspacing' => $this->input->post('barcode_page_cellspacing'),
    -            'barcode_generate_if_empty' => $this->input->post('barcode_generate_if_empty') != NULL,
    -            'barcode_content' => $this->input->post('barcode_content')
    -        );
    -
    -        $result = $this->Appconfig->batch_save($batch_save_data);
    -        $success = $result ? TRUE : FALSE;
    -
    -        echo json_encode(array(
    -            'success' => $success,
    -            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    -        ));
    -    }
    -
    -    public function save_receipt()
    -    {
    -        $batch_save_data = array (
    -            'receipt_template' => $this->input->post('receipt_template'),
    -            'receipt_show_company_name' => $this->input->post('receipt_show_company_name') != NULL,
    -            'receipt_show_taxes' => $this->input->post('receipt_show_taxes') != NULL,
    -            'receipt_show_total_discount' => $this->input->post('receipt_show_total_discount') != NULL,
    -            'receipt_show_description' => $this->input->post('receipt_show_description') != NULL,
    -            'receipt_show_serialnumber' => $this->input->post('receipt_show_serialnumber') != NULL,
    -            'print_silently' => $this->input->post('print_silently') != NULL,
    -            'print_header' => $this->input->post('print_header') != NULL,
    -            'print_footer' => $this->input->post('print_footer') != NULL,
    -            'print_top_margin' => $this->input->post('print_top_margin'),
    -            'print_left_margin' => $this->input->post('print_left_margin'),
    -            'print_bottom_margin' => $this->input->post('print_bottom_margin'),
    -            'print_right_margin' => $this->input->post('print_right_margin')
    -        );
    -
    -        $result = $this->Appconfig->batch_save($batch_save_data);
    -        $success = $result ? TRUE : FALSE;
    -
    -        echo json_encode(array(
    -            'success' => $success,
    -            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    -        ));
    -    }
    -
    -    public function save_invoice()
    -    {
    -        $batch_save_data = array (
    -            'invoice_enable' => $this->input->post('invoice_enable') != NULL,
    -            'default_register_mode' => $this->input->post('default_register_mode'),
    -            'sales_invoice_format' => $this->input->post('sales_invoice_format'),
    -            'sales_quote_format' => $this->input->post('sales_quote_format'),
    -            'recv_invoice_format' => $this->input->post('recv_invoice_format'),
    -            'invoice_default_comments' => $this->input->post('invoice_default_comments'),
    -            'invoice_email_message' => $this->input->post('invoice_email_message'),
    -            'line_sequence' => $this->input->post('line_sequence'),
    -            'last_used_invoice_number' =>$this->input->post('last_used_invoice_number'),
    -            'last_used_quote_number' =>$this->input->post('last_used_quote_number')
    -        );
    -
    -        $result = $this->Appconfig->batch_save($batch_save_data);
    -        $success = $result ? TRUE : FALSE;
    -
    -        // Update the register mode with the latest change so that if the user
    -        // switches immediately back to the register the mode reflects the change
    -        if($success == TRUE)
    -        {
    -            if($this->config->item('invoice_enable') == '1')
    -            {
    -                $this->sale_lib->set_mode($batch_save_data['default_register_mode']);
    -            }
    -            else
    -            {
    -                $this->sale_lib->set_mode('sale');
    -            }
    -        }
    +            // all locations not available in post will be deleted now
    +            $deleted_packages = $this->Customer_rewards->get_all()->result_array();
    +
    +            foreach($deleted_packages as $customer_reward)
    +            {
    +                if(!empty($customer_reward['customer_reward_id']) && !in_array($customer_reward['customer_reward_id'], $not_to_delete))
    +                {
    +                    $this->Customer_rewards->delete($customer_reward['customer_reward_id']);
    +                }
    +            }
    +        }
    +
    +        $this->db->trans_complete();
    +
    +        $success = $this->db->trans_status();
    +
    +        echo json_encode(array(
    +            'success' => $success,
    +            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    +        ));
    +    }
    +
    +    public function save_barcode()
    +    {
    +        $batch_save_data = array(
    +            'barcode_type' => $this->input->post('barcode_type'),
    +            'barcode_quality' => $this->input->post('barcode_quality'),
    +            'barcode_width' => $this->input->post('barcode_width'),
    +            'barcode_height' => $this->input->post('barcode_height'),
    +            'barcode_font' => $this->input->post('barcode_font'),
    +            'barcode_font_size' => $this->input->post('barcode_font_size'),
    +            'barcode_first_row' => $this->input->post('barcode_first_row'),
    +            'barcode_second_row' => $this->input->post('barcode_second_row'),
    +            'barcode_third_row' => $this->input->post('barcode_third_row'),
    +            'barcode_num_in_row' => $this->input->post('barcode_num_in_row'),
    +            'barcode_page_width' => $this->input->post('barcode_page_width'),
    +            'barcode_page_cellspacing' => $this->input->post('barcode_page_cellspacing'),
    +            'barcode_generate_if_empty' => $this->input->post('barcode_generate_if_empty') != NULL,
    +            'barcode_content' => $this->input->post('barcode_content')
    +        );
    +
    +        $result = $this->Appconfig->batch_save($batch_save_data);
    +        $success = $result ? TRUE : FALSE;
    +
    +        echo json_encode(array(
    +            'success' => $success,
    +            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    +        ));
    +    }
    +
    +    public function save_receipt()
    +    {
    +        $batch_save_data = array (
    +            'receipt_template' => $this->input->post('receipt_template'),
    +            'receipt_show_company_name' => $this->input->post('receipt_show_company_name') != NULL,
    +            'receipt_show_taxes' => $this->input->post('receipt_show_taxes') != NULL,
    +            'receipt_show_total_discount' => $this->input->post('receipt_show_total_discount') != NULL,
    +            'receipt_show_description' => $this->input->post('receipt_show_description') != NULL,
    +            'receipt_show_serialnumber' => $this->input->post('receipt_show_serialnumber') != NULL,
    +            'print_silently' => $this->input->post('print_silently') != NULL,
    +            'print_header' => $this->input->post('print_header') != NULL,
    +            'print_footer' => $this->input->post('print_footer') != NULL,
    +            'print_top_margin' => $this->input->post('print_top_margin'),
    +            'print_left_margin' => $this->input->post('print_left_margin'),
    +            'print_bottom_margin' => $this->input->post('print_bottom_margin'),
    +            'print_right_margin' => $this->input->post('print_right_margin')
    +        );
    +
    +        $result = $this->Appconfig->batch_save($batch_save_data);
    +        $success = $result ? TRUE : FALSE;
    +
    +        echo json_encode(array(
    +            'success' => $success,
    +            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    +        ));
    +    }
    +
    +    public function save_invoice()
    +    {
    +        $batch_save_data = array (
    +            'invoice_enable' => $this->input->post('invoice_enable') != NULL,
    +            'default_register_mode' => $this->input->post('default_register_mode'),
    +            'sales_invoice_format' => $this->input->post('sales_invoice_format'),
    +            'sales_quote_format' => $this->input->post('sales_quote_format'),
    +            'recv_invoice_format' => $this->input->post('recv_invoice_format'),
    +            'invoice_default_comments' => $this->input->post('invoice_default_comments'),
    +            'invoice_email_message' => $this->input->post('invoice_email_message'),
    +            'line_sequence' => $this->input->post('line_sequence'),
    +            'last_used_invoice_number' =>$this->input->post('last_used_invoice_number'),
    +            'last_used_quote_number' =>$this->input->post('last_used_quote_number')
    +        );
    +
    +        $result = $this->Appconfig->batch_save($batch_save_data);
    +        $success = $result ? TRUE : FALSE;
     
    -        echo json_encode(array(
    -            'success' => $success,
    -            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    -        ));
    -    }
    -
    -    public function remove_logo()
    -    {
    -        $result = $this->Appconfig->batch_save(array('company_logo' => ''));
    -
    -        echo json_encode(array('success' => $result));
    -    }
    -
    -    private function _handle_logo_upload()
    -    {
    -        $this->load->helper('directory');
    -
    -        // load upload library
    -        $config = array('upload_path' => './uploads/',
    -                'allowed_types' => 'gif|jpg|png',
    -                'max_size' => '1024',
    -                'max_width' => '800',
    -                'max_height' => '680',
    -                'file_name' => 'company_logo');
    -        $this->load->library('upload', $config);
    -        $this->upload->do_upload('company_logo');
    +        // Update the register mode with the latest change so that if the user
    +        // switches immediately back to the register the mode reflects the change
    +        if($success == TRUE)
    +        {
    +            if($this->config->item('invoice_enable') == '1')
    +            {
    +                $this->sale_lib->set_mode($batch_save_data['default_register_mode']);
    +            }
    +            else
    +            {
    +                $this->sale_lib->set_mode('sale');
    +            }
    +        }
    +
    +        echo json_encode(array(
    +            'success' => $success,
    +            'message' => $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')
    +        ));
    +    }
    +
    +    public function remove_logo()
    +    {
    +        $result = $this->Appconfig->batch_save(array('company_logo' => ''));
    +
    +        echo json_encode(array('success' => $result));
    +    }
     
    -        return strlen($this->upload->display_errors()) == 0 || !strcmp($this->upload->display_errors(), '<p>'.$this->lang->line('upload_no_file_selected').'</p>');
    -    }
    -
    -    private function _check_encryption()
    -    {
    -        $encryption_key = $this->config->item('encryption_key');
    -
    -        // check if the encryption_key config item is the default one
    -        if($encryption_key == '' || $encryption_key == 'YOUR KEY')
    -        {
    -            // Config path
    -            $config_path = APPPATH . 'config/config.php';
    -
    -            // Open the file
    -            $config = file_get_contents($config_path);
    -
    -            // $key will be assigned a 32-byte (256-bit) hex-encoded random key
    -            $key = bin2hex($this->encryption->create_key(32));
    -
    -            // set the encryption key in the config item
    -            $this->config->set_item('encryption_key', $key);
    -
    -            // replace the empty placeholder with a real randomly generated encryption key
    -            $config = preg_replace("/(.*encryption_key.*)('');/", "$1'$key';", $config);
    -
    -            $result = FALSE;
    +    private function _handle_logo_upload()
    +    {
    +        $this->load->helper('directory');
    +
    +        // load upload library
    +        $config = array('upload_path' => './uploads/',
    +                'allowed_types' => 'gif|jpg|png',
    +                'max_size' => '1024',
    +                'max_width' => '800',
    +                'max_height' => '680',
    +                'file_name' => 'company_logo');
    +        $this->load->library('upload', $config);
    +        $this->upload->do_upload('company_logo');
    +
    +        return strlen($this->upload->display_errors()) == 0 || !strcmp($this->upload->display_errors(), '<p>'.$this->lang->line('upload_no_file_selected').'</p>');
    +    }
    +
    +    private function _check_encryption()
    +    {
    +        $encryption_key = $this->config->item('encryption_key');
    +
    +        // check if the encryption_key config item is the default one
    +        if($encryption_key == '' || $encryption_key == 'YOUR KEY')
    +        {
    +            // Config path
    +            $config_path = APPPATH . 'config/config.php';
     
    -            // Chmod the file
    -            @chmod($config_path, 0777);
    +            // Open the file
    +            $config = file_get_contents($config_path);
     
    -            // Write the new config.php file
    -            $handle = fopen($config_path, 'w+');
    +            // $key will be assigned a 32-byte (256-bit) hex-encoded random key
    +            $key = bin2hex($this->encryption->create_key(32));
     
    -            // Verify file permissions
    -            if(is_writable($config_path))
    -            {
    -                // Write the file
    -                $result = (fwrite($handle, $config) === FALSE) ? FALSE : TRUE;
    -            }
    -
    -            fclose($handle);
    -
    -            // Chmod the file
    -            @chmod($config_path, 0444);
    -
    -            return $result;
    -        }
    -
    -        return TRUE;
    -    }
    -
    -    public function backup_db()
    -    {
    -        $employee_id = $this->Employee->get_logged_in_employee_info()->person_id;
    -        if($this->Employee->has_module_grant('config', $employee_id))
    -        {
    -            $this->load->dbutil();
    -
    -            $prefs = array(
    -                'format' => 'zip',
    -                'filename' => 'ospos.sql'
    -            );
    -
    -            $backup = $this->dbutil->backup($prefs);
    +            // set the encryption key in the config item
    +            $this->config->set_item('encryption_key', $key);
    +
    +            // replace the empty placeholder with a real randomly generated encryption key
    +            $config = preg_replace("/(.*encryption_key.*)('');/", "$1'$key';", $config);
    +
    +            $result = FALSE;
    +
    +            // Chmod the file
    +            @chmod($config_path, 0777);
    +
    +            // Write the new config.php file
    +            $handle = fopen($config_path, 'w+');
    +
    +            // Verify file permissions
    +            if(is_writable($config_path))
    +            {
    +                // Write the file
    +                $result = (fwrite($handle, $config) === FALSE) ? FALSE : TRUE;
    +            }
    +
    +            fclose($handle);
    +
    +            // Chmod the file
    +            @chmod($config_path, 0444);
    +
    +            return $result;
    +        }
    +
    +        return TRUE;
    +    }
     
    -            $file_name = 'ospos-' . date("Y-m-d-H-i-s") .'.zip';
    -            $save = 'uploads/' . $file_name;
    -            $this->load->helper('download');
    -            while(ob_get_level())
    -            {
    -                ob_end_clean();
    -            }
    -
    -            force_download($file_name, $backup);
    -        }
    -        else
    -        {
    -            redirect('no_access/config');
    -        }
    -    }
    -}
    -?>
    -
    + public function backup_db() + { + $employee_id = $this->Employee->get_logged_in_employee_info()->person_id; + if($this->Employee->has_module_grant('config', $employee_id)) + { + $this->load->dbutil(); + + $prefs = array( + 'format' => 'zip', + 'filename' => 'ospos.sql' + ); + + $backup = $this->dbutil->backup($prefs); + + $file_name = 'ospos-' . date("Y-m-d-H-i-s") .'.zip'; + $save = 'uploads/' . $file_name; + $this->load->helper('download'); + while(ob_get_level()) + { + ob_end_clean(); + } + + force_download($file_name, $backup); + } + else + { + redirect('no_access/config'); + } + } +} +?> +
    - + diff --git a/docs/source-class-Customer.html b/docs/source-class-Customer.html index a80519bbd..632471c51 100644 --- a/docs/source-class-Customer.html +++ b/docs/source-class-Customer.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -571,6 +572,6 @@
    - + diff --git a/docs/source-class-Customer_rewards.html b/docs/source-class-Customer_rewards.html index 751f4e122..33883a041 100644 --- a/docs/source-class-Customer_rewards.html +++ b/docs/source-class-Customer_rewards.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -308,6 +309,6 @@
    - + diff --git a/docs/source-class-Customers.html b/docs/source-class-Customers.html index e184aafe6..3170a42a5 100644 --- a/docs/source-class-Customers.html +++ b/docs/source-class-Customers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -627,6 +628,6 @@
    - + diff --git a/docs/source-class-Detailed_receivings.html b/docs/source-class-Detailed_receivings.html index b28e1ab4f..37d7b1a19 100644 --- a/docs/source-class-Detailed_receivings.html +++ b/docs/source-class-Detailed_receivings.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -354,6 +355,6 @@
    - + diff --git a/docs/source-class-Detailed_sales.html b/docs/source-class-Detailed_sales.html index b537db1cd..ff123cfd4 100644 --- a/docs/source-class-Detailed_sales.html +++ b/docs/source-class-Detailed_sales.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -358,6 +359,6 @@
    - + diff --git a/docs/source-class-Dinner_table.html b/docs/source-class-Dinner_table.html index d91dfee64..e6284e9a4 100644 --- a/docs/source-class-Dinner_table.html +++ b/docs/source-class-Dinner_table.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -327,6 +328,6 @@
    - + diff --git a/docs/source-class-Email_lib.html b/docs/source-class-Email_lib.html index b9ca5c329..0ed801dd3 100644 --- a/docs/source-class-Email_lib.html +++ b/docs/source-class-Email_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -284,6 +285,6 @@
    - + diff --git a/docs/source-class-Employee.html b/docs/source-class-Employee.html index 8ef58870c..a4b59b8e4 100644 --- a/docs/source-class-Employee.html +++ b/docs/source-class-Employee.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -683,6 +684,6 @@
    - + diff --git a/docs/source-class-Employees.html b/docs/source-class-Employees.html index 22c486fe3..d2833636a 100644 --- a/docs/source-class-Employees.html +++ b/docs/source-class-Employees.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -426,6 +427,6 @@
    - + diff --git a/docs/source-class-Giftcard.html b/docs/source-class-Giftcard.html index 4493fda20..9c31c062f 100644 --- a/docs/source-class-Giftcard.html +++ b/docs/source-class-Giftcard.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -535,6 +536,6 @@ - + diff --git a/docs/source-class-Giftcards.html b/docs/source-class-Giftcards.html index 02c391e34..71660803f 100644 --- a/docs/source-class-Giftcards.html +++ b/docs/source-class-Giftcards.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -363,6 +364,6 @@ - + diff --git a/docs/source-class-Home.html b/docs/source-class-Home.html index 6588583fe..7226c127a 100644 --- a/docs/source-class-Home.html +++ b/docs/source-class-Home.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -235,6 +236,6 @@ - + diff --git a/docs/source-class-Inventory.html b/docs/source-class-Inventory.html index 0687bff6c..1fe726086 100644 --- a/docs/source-class-Inventory.html +++ b/docs/source-class-Inventory.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -276,6 +277,6 @@ - + diff --git a/docs/source-class-Inventory_low.html b/docs/source-class-Inventory_low.html index d64e9317e..be74909fb 100644 --- a/docs/source-class-Inventory_low.html +++ b/docs/source-class-Inventory_low.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -253,6 +254,6 @@ - + diff --git a/docs/source-class-Inventory_summary.html b/docs/source-class-Inventory_summary.html index 5e685c776..43f0799e5 100644 --- a/docs/source-class-Inventory_summary.html +++ b/docs/source-class-Inventory_summary.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -295,6 +296,6 @@ - + diff --git a/docs/source-class-Item.html b/docs/source-class-Item.html index bf00d6f00..c60aad698 100644 --- a/docs/source-class-Item.html +++ b/docs/source-class-Item.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -1045,6 +1046,6 @@ - + diff --git a/docs/source-class-Item_kit.html b/docs/source-class-Item_kit.html index f4d1cbb10..9b24b4e72 100644 --- a/docs/source-class-Item_kit.html +++ b/docs/source-class-Item_kit.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -462,6 +463,6 @@ - + diff --git a/docs/source-class-Item_kit_items.html b/docs/source-class-Item_kit_items.html index 967d46464..2bc210081 100644 --- a/docs/source-class-Item_kit_items.html +++ b/docs/source-class-Item_kit_items.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -292,6 +293,6 @@ - + diff --git a/docs/source-class-Item_kits.html b/docs/source-class-Item_kits.html index 7f41713bd..971e32548 100644 --- a/docs/source-class-Item_kits.html +++ b/docs/source-class-Item_kits.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -445,6 +446,6 @@ - + diff --git a/docs/source-class-Item_lib.html b/docs/source-class-Item_lib.html index e531a3ca3..b6a7d2b40 100644 --- a/docs/source-class-Item_lib.html +++ b/docs/source-class-Item_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -260,6 +261,6 @@ - + diff --git a/docs/source-class-Item_quantity.html b/docs/source-class-Item_quantity.html index 63f5e3dc1..c9fd6670e 100644 --- a/docs/source-class-Item_quantity.html +++ b/docs/source-class-Item_quantity.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -308,6 +309,6 @@ - + diff --git a/docs/source-class-Item_taxes.html b/docs/source-class-Item_taxes.html index 4328e7f02..ed7ff1601 100644 --- a/docs/source-class-Item_taxes.html +++ b/docs/source-class-Item_taxes.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -302,6 +303,6 @@ - + diff --git a/docs/source-class-Items.html b/docs/source-class-Items.html index ba1158ea3..6282713bf 100644 --- a/docs/source-class-Items.html +++ b/docs/source-class-Items.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -1071,6 +1072,6 @@ - + diff --git a/docs/source-class-Login.html b/docs/source-class-Login.html index 6b3975370..2db71cacf 100644 --- a/docs/source-class-Login.html +++ b/docs/source-class-Login.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -289,6 +290,6 @@ - + diff --git a/docs/source-class-MY_Lang.html b/docs/source-class-MY_Lang.html index e754541fd..ae2e1ea65 100644 --- a/docs/source-class-MY_Lang.html +++ b/docs/source-class-MY_Lang.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -305,6 +306,6 @@ - + diff --git a/docs/source-class-MailchimpConnector.html b/docs/source-class-MailchimpConnector.html index fba02e019..e5768a166 100644 --- a/docs/source-class-MailchimpConnector.html +++ b/docs/source-class-MailchimpConnector.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -581,6 +582,6 @@ - + diff --git a/docs/source-class-Mailchimp_lib.html b/docs/source-class-Mailchimp_lib.html index fba02e019..e5768a166 100644 --- a/docs/source-class-Mailchimp_lib.html +++ b/docs/source-class-Mailchimp_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -581,6 +582,6 @@ - + diff --git a/docs/source-class-Messages.html b/docs/source-class-Messages.html index 4aa9d7ea2..f3e07e504 100644 --- a/docs/source-class-Messages.html +++ b/docs/source-class-Messages.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -281,6 +282,6 @@ - + diff --git a/docs/source-class-Migrate.html b/docs/source-class-Migrate.html index 7ff90d163..d7970964a 100644 --- a/docs/source-class-Migrate.html +++ b/docs/source-class-Migrate.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -247,6 +248,6 @@ - + diff --git a/docs/source-class-Migration_Sales_Tax_Data.html b/docs/source-class-Migration_Sales_Tax_Data.html index c6cf8db7e..26c750c10 100644 --- a/docs/source-class-Migration_Sales_Tax_Data.html +++ b/docs/source-class-Migration_Sales_Tax_Data.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -356,6 +357,6 @@ - + diff --git a/docs/source-class-Module.html b/docs/source-class-Module.html index c8c5f6299..2b4742845 100644 --- a/docs/source-class-Module.html +++ b/docs/source-class-Module.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -293,6 +294,6 @@ - + diff --git a/docs/source-class-No_Access.html b/docs/source-class-No_Access.html index 5f32aa9be..b248a0aa6 100644 --- a/docs/source-class-No_Access.html +++ b/docs/source-class-No_Access.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -231,6 +232,6 @@ - + diff --git a/docs/source-class-Person.html b/docs/source-class-Person.html index 503bd0a0a..d3b363dbf 100644 --- a/docs/source-class-Person.html +++ b/docs/source-class-Person.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -413,6 +414,6 @@ - + diff --git a/docs/source-class-Persons.html b/docs/source-class-Persons.html index ed18c83b9..d499b8bf5 100644 --- a/docs/source-class-Persons.html +++ b/docs/source-class-Persons.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -271,6 +272,6 @@ - + diff --git a/docs/source-class-Receiving.html b/docs/source-class-Receiving.html index 491cca681..3e534d039 100644 --- a/docs/source-class-Receiving.html +++ b/docs/source-class-Receiving.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -508,6 +509,6 @@ - + diff --git a/docs/source-class-Receiving_lib.html b/docs/source-class-Receiving_lib.html index d0363e220..c5c08b556 100644 --- a/docs/source-class-Receiving_lib.html +++ b/docs/source-class-Receiving_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -574,6 +575,6 @@ - + diff --git a/docs/source-class-Receivings.html b/docs/source-class-Receivings.html index 585c94541..60df450c7 100644 --- a/docs/source-class-Receivings.html +++ b/docs/source-class-Receivings.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -619,6 +620,6 @@ - + diff --git a/docs/source-class-Report.html b/docs/source-class-Report.html index 979b7ab33..efb46f01b 100644 --- a/docs/source-class-Report.html +++ b/docs/source-class-Report.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,6 +242,6 @@ - + diff --git a/docs/source-class-Reports.html b/docs/source-class-Reports.html index f4c70566f..3373a2133 100644 --- a/docs/source-class-Reports.html +++ b/docs/source-class-Reports.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -1431,6 +1432,6 @@ - + diff --git a/docs/source-class-Rewards.html b/docs/source-class-Rewards.html index 2e792e45d..ec16f8cfd 100644 --- a/docs/source-class-Rewards.html +++ b/docs/source-class-Rewards.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -251,6 +252,6 @@ - + diff --git a/docs/source-class-Rounding_code.html b/docs/source-class-Rounding_code.html index a3c4074cc..aab31ba8f 100644 --- a/docs/source-class-Rounding_code.html +++ b/docs/source-class-Rounding_code.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -304,6 +305,6 @@ - + diff --git a/docs/source-class-Sale.html b/docs/source-class-Sale.html index 68202677b..aa8a483f5 100644 --- a/docs/source-class-Sale.html +++ b/docs/source-class-Sale.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
       1:    2:    3:    4:    5:    6:    7:    8:    9:   10:   11:   12:   13:   14:   15:   16:   17:   18:   19:   20:   21:   22:   23:   24:   25:   26:   27:   28:   29:   30:   31:   32:   33:   34:   35:   36:   37:   38:   39:   40:   41:   42:   43:   44:   45:   46:   47:   48:   49:   50:   51:   52:   53:   54:   55:   56:   57:   58:   59:   60:   61:   62:   63:   64:   65:   66:   67:   68:   69:   70:   71:   72:   73:   74:   75:   76:   77:   78:   79:   80:   81:   82:   83:   84:   85:   86:   87:   88:   89:   90:   91:   92:   93:   94:   95:   96:   97:   98:   99:  100:  101:  102:  103:  104:  105:  106:  107:  108:  109:  110:  111:  112:  113:  114:  115:  116:  117:  118:  119:  120:  121:  122:  123:  124:  125:  126:  127:  128:  129:  130:  131:  132:  133:  134:  135:  136:  137:  138:  139:  140:  141:  142:  143:  144:  145:  146:  147:  148:  149:  150:  151:  152:  153:  154:  155:  156:  157:  158:  159:  160:  161:  162:  163:  164:  165:  166:  167:  168:  169:  170:  171:  172:  173:  174:  175:  176:  177:  178:  179:  180:  181:  182:  183:  184:  185:  186:  187:  188:  189:  190:  191:  192:  193:  194:  195:  196:  197:  198:  199:  200:  201:  202:  203:  204:  205:  206:  207:  208:  209:  210:  211:  212:  213:  214:  215:  216:  217:  218:  219:  220:  221:  222:  223:  224:  225:  226:  227:  228:  229:  230:  231:  232:  233:  234:  235:  236:  237:  238:  239:  240:  241:  242:  243:  244:  245:  246:  247:  248:  249:  250:  251:  252:  253:  254:  255:  256:  257:  258:  259:  260:  261:  262:  263:  264:  265:  266:  267:  268:  269:  270:  271:  272:  273:  274:  275:  276:  277:  278:  279:  280:  281:  282:  283:  284:  285:  286:  287:  288:  289:  290:  291:  292:  293:  294:  295:  296:  297:  298:  299:  300:  301:  302:  303:  304:  305:  306:  307:  308:  309:  310:  311:  312:  313:  314:  315:  316:  317:  318:  319:  320:  321:  322:  323:  324:  325:  326:  327:  328:  329:  330:  331:  332:  333:  334:  335:  336:  337:  338:  339:  340:  341:  342:  343:  344:  345:  346:  347:  348:  349:  350:  351:  352:  353:  354:  355:  356:  357:  358:  359:  360:  361:  362:  363:  364:  365:  366:  367:  368:  369:  370:  371:  372:  373:  374:  375:  376:  377:  378:  379:  380:  381:  382:  383:  384:  385:  386:  387:  388:  389:  390:  391:  392:  393:  394:  395:  396:  397:  398:  399:  400:  401:  402:  403:  404:  405:  406:  407:  408:  409:  410:  411:  412:  413:  414:  415:  416:  417:  418:  419:  420:  421:  422:  423:  424:  425:  426:  427:  428:  429:  430:  431:  432:  433:  434:  435:  436:  437:  438:  439:  440:  441:  442:  443:  444:  445:  446:  447:  448:  449:  450:  451:  452:  453:  454:  455:  456:  457:  458:  459:  460:  461:  462:  463:  464:  465:  466:  467:  468:  469:  470:  471:  472:  473:  474:  475:  476:  477:  478:  479:  480:  481:  482:  483:  484:  485:  486:  487:  488:  489:  490:  491:  492:  493:  494:  495:  496:  497:  498:  499:  500:  501:  502:  503:  504:  505:  506:  507:  508:  509:  510:  511:  512:  513:  514:  515:  516:  517:  518:  519:  520:  521:  522:  523:  524:  525:  526:  527:  528:  529:  530:  531:  532:  533:  534:  535:  536:  537:  538:  539:  540:  541:  542:  543:  544:  545:  546:  547:  548:  549:  550:  551:  552:  553:  554:  555:  556:  557:  558:  559:  560:  561:  562:  563:  564:  565:  566:  567:  568:  569:  570:  571:  572:  573:  574:  575:  576:  577:  578:  579:  580:  581:  582:  583:  584:  585:  586:  587:  588:  589:  590:  591:  592:  593:  594:  595:  596:  597:  598:  599:  600:  601:  602:  603:  604:  605:  606:  607:  608:  609:  610:  611:  612:  613:  614:  615:  616:  617:  618:  619:  620:  621:  622:  623:  624:  625:  626:  627:  628:  629:  630:  631:  632:  633:  634:  635:  636:  637:  638:  639:  640:  641:  642:  643:  644:  645:  646:  647:  648:  649:  650:  651:  652:  653:  654:  655:  656:  657:  658:  659:  660:  661:  662:  663:  664:  665:  666:  667:  668:  669:  670:  671:  672:  673:  674:  675:  676:  677:  678:  679:  680:  681:  682:  683:  684:  685:  686:  687:  688:  689:  690:  691:  692:  693:  694:  695:  696:  697:  698:  699:  700:  701:  702:  703:  704:  705:  706:  707:  708:  709:  710:  711:  712:  713:  714:  715:  716:  717:  718:  719:  720:  721:  722:  723:  724:  725:  726:  727:  728:  729:  730:  731:  732:  733:  734:  735:  736:  737:  738:  739:  740:  741:  742:  743:  744:  745:  746:  747:  748:  749:  750:  751:  752:  753:  754:  755:  756:  757:  758:  759:  760:  761:  762:  763:  764:  765:  766:  767:  768:  769:  770:  771:  772:  773:  774:  775:  776:  777:  778:  779:  780:  781:  782:  783:  784:  785:  786:  787:  788:  789:  790:  791:  792:  793:  794:  795:  796:  797:  798:  799:  800:  801:  802:  803:  804:  805:  806:  807:  808:  809:  810:  811:  812:  813:  814:  815:  816:  817:  818:  819:  820:  821:  822:  823:  824:  825:  826:  827:  828:  829:  830:  831:  832:  833:  834:  835:  836:  837:  838:  839:  840:  841:  842:  843:  844:  845:  846:  847:  848:  849:  850:  851:  852:  853:  854:  855:  856:  857:  858:  859:  860:  861:  862:  863:  864:  865:  866:  867:  868:  869:  870:  871:  872:  873:  874:  875:  876:  877:  878:  879:  880:  881:  882:  883:  884:  885:  886:  887:  888:  889:  890:  891:  892:  893:  894:  895:  896:  897:  898:  899:  900:  901:  902:  903:  904:  905:  906:  907:  908:  909:  910:  911:  912:  913:  914:  915:  916:  917:  918:  919:  920:  921:  922:  923:  924:  925:  926:  927:  928:  929:  930:  931:  932:  933:  934:  935:  936:  937:  938:  939:  940:  941:  942:  943:  944:  945:  946:  947:  948:  949:  950:  951:  952:  953:  954:  955:  956:  957:  958:  959:  960:  961:  962:  963:  964:  965:  966:  967:  968:  969:  970:  971:  972:  973:  974:  975:  976:  977:  978:  979:  980:  981:  982:  983:  984:  985:  986:  987:  988:  989:  990:  991:  992:  993:  994:  995:  996:  997:  998:  999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 1130: 1131: 1132: 1133: 1134: 1135: 1136: 1137: 1138: 1139: 1140: 1141: 1142: 1143: 1144: 1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164: 1165: 1166: 1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174: 1175: 1176: 1177: 1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185: 1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199: 1200: 1201: 1202: 1203: 1204: 1205: 1206: 1207: 1208: 1209: 1210: 1211: 1212: 1213: 1214: 1215: 1216: 1217: 1218: 1219: 1220: 1221: 1222: 1223: 1224: 1225: 1226: 1227: 1228: 1229: 1230: 1231: 1232: 1233: 1234: 1235: 1236: 1237: 1238: 1239: 1240: 1241: 1242: 1243: 1244: 1245: 1246: 1247: 1248: 1249: 1250: 1251: 1252: 1253: 1254: 1255: 1256: 1257: 1258: 1259: 1260: 1261: 1262: 1263: 1264: 1265: 1266: 1267: 1268: 1269: 1270: 1271: 1272: 1273: 1274: 1275: 1276: 1277: 1278: 1279: 1280: 1281: 1282: 1283: 1284: 1285: 1286: 1287: 1288: 1289: 1290: 1291: 1292: 1293: 1294: 1295: 1296: 1297: 1298: 1299: 1300: 1301: 1302: 1303: 1304: 1305: 1306: 1307: 1308: 1309: 1310: 1311: 1312: 1313: 1314: 1315: 1316: 1317: 1318: 1319: 1320: 1321: 1322: 1323: 1324: 1325: 1326: 1327: 1328: 1329: 1330: 
    +
       1:    2:    3:    4:    5:    6:    7:    8:    9:   10:   11:   12:   13:   14:   15:   16:   17:   18:   19:   20:   21:   22:   23:   24:   25:   26:   27:   28:   29:   30:   31:   32:   33:   34:   35:   36:   37:   38:   39:   40:   41:   42:   43:   44:   45:   46:   47:   48:   49:   50:   51:   52:   53:   54:   55:   56:   57:   58:   59:   60:   61:   62:   63:   64:   65:   66:   67:   68:   69:   70:   71:   72:   73:   74:   75:   76:   77:   78:   79:   80:   81:   82:   83:   84:   85:   86:   87:   88:   89:   90:   91:   92:   93:   94:   95:   96:   97:   98:   99:  100:  101:  102:  103:  104:  105:  106:  107:  108:  109:  110:  111:  112:  113:  114:  115:  116:  117:  118:  119:  120:  121:  122:  123:  124:  125:  126:  127:  128:  129:  130:  131:  132:  133:  134:  135:  136:  137:  138:  139:  140:  141:  142:  143:  144:  145:  146:  147:  148:  149:  150:  151:  152:  153:  154:  155:  156:  157:  158:  159:  160:  161:  162:  163:  164:  165:  166:  167:  168:  169:  170:  171:  172:  173:  174:  175:  176:  177:  178:  179:  180:  181:  182:  183:  184:  185:  186:  187:  188:  189:  190:  191:  192:  193:  194:  195:  196:  197:  198:  199:  200:  201:  202:  203:  204:  205:  206:  207:  208:  209:  210:  211:  212:  213:  214:  215:  216:  217:  218:  219:  220:  221:  222:  223:  224:  225:  226:  227:  228:  229:  230:  231:  232:  233:  234:  235:  236:  237:  238:  239:  240:  241:  242:  243:  244:  245:  246:  247:  248:  249:  250:  251:  252:  253:  254:  255:  256:  257:  258:  259:  260:  261:  262:  263:  264:  265:  266:  267:  268:  269:  270:  271:  272:  273:  274:  275:  276:  277:  278:  279:  280:  281:  282:  283:  284:  285:  286:  287:  288:  289:  290:  291:  292:  293:  294:  295:  296:  297:  298:  299:  300:  301:  302:  303:  304:  305:  306:  307:  308:  309:  310:  311:  312:  313:  314:  315:  316:  317:  318:  319:  320:  321:  322:  323:  324:  325:  326:  327:  328:  329:  330:  331:  332:  333:  334:  335:  336:  337:  338:  339:  340:  341:  342:  343:  344:  345:  346:  347:  348:  349:  350:  351:  352:  353:  354:  355:  356:  357:  358:  359:  360:  361:  362:  363:  364:  365:  366:  367:  368:  369:  370:  371:  372:  373:  374:  375:  376:  377:  378:  379:  380:  381:  382:  383:  384:  385:  386:  387:  388:  389:  390:  391:  392:  393:  394:  395:  396:  397:  398:  399:  400:  401:  402:  403:  404:  405:  406:  407:  408:  409:  410:  411:  412:  413:  414:  415:  416:  417:  418:  419:  420:  421:  422:  423:  424:  425:  426:  427:  428:  429:  430:  431:  432:  433:  434:  435:  436:  437:  438:  439:  440:  441:  442:  443:  444:  445:  446:  447:  448:  449:  450:  451:  452:  453:  454:  455:  456:  457:  458:  459:  460:  461:  462:  463:  464:  465:  466:  467:  468:  469:  470:  471:  472:  473:  474:  475:  476:  477:  478:  479:  480:  481:  482:  483:  484:  485:  486:  487:  488:  489:  490:  491:  492:  493:  494:  495:  496:  497:  498:  499:  500:  501:  502:  503:  504:  505:  506:  507:  508:  509:  510:  511:  512:  513:  514:  515:  516:  517:  518:  519:  520:  521:  522:  523:  524:  525:  526:  527:  528:  529:  530:  531:  532:  533:  534:  535:  536:  537:  538:  539:  540:  541:  542:  543:  544:  545:  546:  547:  548:  549:  550:  551:  552:  553:  554:  555:  556:  557:  558:  559:  560:  561:  562:  563:  564:  565:  566:  567:  568:  569:  570:  571:  572:  573:  574:  575:  576:  577:  578:  579:  580:  581:  582:  583:  584:  585:  586:  587:  588:  589:  590:  591:  592:  593:  594:  595:  596:  597:  598:  599:  600:  601:  602:  603:  604:  605:  606:  607:  608:  609:  610:  611:  612:  613:  614:  615:  616:  617:  618:  619:  620:  621:  622:  623:  624:  625:  626:  627:  628:  629:  630:  631:  632:  633:  634:  635:  636:  637:  638:  639:  640:  641:  642:  643:  644:  645:  646:  647:  648:  649:  650:  651:  652:  653:  654:  655:  656:  657:  658:  659:  660:  661:  662:  663:  664:  665:  666:  667:  668:  669:  670:  671:  672:  673:  674:  675:  676:  677:  678:  679:  680:  681:  682:  683:  684:  685:  686:  687:  688:  689:  690:  691:  692:  693:  694:  695:  696:  697:  698:  699:  700:  701:  702:  703:  704:  705:  706:  707:  708:  709:  710:  711:  712:  713:  714:  715:  716:  717:  718:  719:  720:  721:  722:  723:  724:  725:  726:  727:  728:  729:  730:  731:  732:  733:  734:  735:  736:  737:  738:  739:  740:  741:  742:  743:  744:  745:  746:  747:  748:  749:  750:  751:  752:  753:  754:  755:  756:  757:  758:  759:  760:  761:  762:  763:  764:  765:  766:  767:  768:  769:  770:  771:  772:  773:  774:  775:  776:  777:  778:  779:  780:  781:  782:  783:  784:  785:  786:  787:  788:  789:  790:  791:  792:  793:  794:  795:  796:  797:  798:  799:  800:  801:  802:  803:  804:  805:  806:  807:  808:  809:  810:  811:  812:  813:  814:  815:  816:  817:  818:  819:  820:  821:  822:  823:  824:  825:  826:  827:  828:  829:  830:  831:  832:  833:  834:  835:  836:  837:  838:  839:  840:  841:  842:  843:  844:  845:  846:  847:  848:  849:  850:  851:  852:  853:  854:  855:  856:  857:  858:  859:  860:  861:  862:  863:  864:  865:  866:  867:  868:  869:  870:  871:  872:  873:  874:  875:  876:  877:  878:  879:  880:  881:  882:  883:  884:  885:  886:  887:  888:  889:  890:  891:  892:  893:  894:  895:  896:  897:  898:  899:  900:  901:  902:  903:  904:  905:  906:  907:  908:  909:  910:  911:  912:  913:  914:  915:  916:  917:  918:  919:  920:  921:  922:  923:  924:  925:  926:  927:  928:  929:  930:  931:  932:  933:  934:  935:  936:  937:  938:  939:  940:  941:  942:  943:  944:  945:  946:  947:  948:  949:  950:  951:  952:  953:  954:  955:  956:  957:  958:  959:  960:  961:  962:  963:  964:  965:  966:  967:  968:  969:  970:  971:  972:  973:  974:  975:  976:  977:  978:  979:  980:  981:  982:  983:  984:  985:  986:  987:  988:  989:  990:  991:  992:  993:  994:  995:  996:  997:  998:  999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 1130: 1131: 1132: 1133: 1134: 1135: 1136: 1137: 1138: 1139: 1140: 1141: 1142: 1143: 1144: 1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164: 1165: 1166: 1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174: 1175: 1176: 1177: 1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185: 1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199: 1200: 1201: 1202: 1203: 1204: 1205: 1206: 1207: 1208: 1209: 1210: 1211: 1212: 1213: 1214: 1215: 1216: 1217: 1218: 1219: 1220: 1221: 1222: 1223: 1224: 1225: 1226: 1227: 1228: 1229: 1230: 1231: 1232: 1233: 1234: 1235: 1236: 1237: 1238: 1239: 1240: 1241: 1242: 1243: 1244: 1245: 1246: 1247: 1248: 1249: 1250: 1251: 1252: 1253: 1254: 1255: 1256: 1257: 1258: 1259: 1260: 1261: 1262: 1263: 1264: 1265: 1266: 1267: 1268: 1269: 1270: 1271: 1272: 1273: 1274: 1275: 1276: 1277: 1278: 1279: 1280: 1281: 1282: 1283: 1284: 1285: 1286: 1287: 1288: 1289: 1290: 1291: 1292: 1293: 1294: 1295: 1296: 1297: 1298: 1299: 1300: 1301: 1302: 1303: 1304: 1305: 1306: 1307: 1308: 1309: 1310: 1311: 1312: 1313: 1314: 1315: 1316: 1317: 1318: 1319: 1320: 1321: 1322: 1323: 1324: 1325: 1326: 1327: 1328: 1329: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -240,1304 +241,1303 @@
                 )'
             );
     
    -        $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)';
    +        $decimals = totals_decimals();
     
    -        if($this->config->item('tax_included'))
    -        {
    -            $sale_total = 'SUM(' . $sale_price . ')';
    -            $sale_subtotal = 'SUM(' . $sale_price . ' - sales_items_taxes.tax)';
    -        }
    -        else
    -        {
    -            $sale_total = 'SUM(' . $sale_price . ' + sales_items_taxes.tax)';
    -            $sale_subtotal = 'SUM(' . $sale_price . ')';
    -        }
    -
    -        $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)';
    -
    -        $decimals = totals_decimals();
    -
    -        // create a temporary table to contain all the sum of taxes per sale item
    -        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') .
    -            '(
    -                SELECT sales_items_taxes.sale_id AS sale_id,
    -                    sales_items_taxes.item_id AS item_id,
    -                    sales_items_taxes.line AS line,
    -                    SUM(sales_items_taxes.item_tax_amount) AS tax
    -                FROM ' . $this->db->dbprefix('sales_items_taxes') . ' AS sales_items_taxes
    -                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    -                    ON sales.sale_id = sales_items_taxes.sale_id
    -                INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items
    -                    ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.line = sales_items_taxes.line
    -                WHERE sales.sale_id = ' . $this->db->escape($sale_id) . '
    -                GROUP BY sale_id, item_id, line
    -            )'
    -        );
    -
    -        $this->db->select('
    -                sales.sale_id AS sale_id,
    -                MAX(DATE(sales.sale_time)) AS sale_date,
    -                MAX(sales.sale_time) AS sale_time,
    -                MAX(sales.comment) AS comment,
    -                MAX(sales.sale_status) AS sale_status,
    -                MAX(sales.invoice_number) AS invoice_number,
    -                MAX(sales.quote_number) AS quote_number,
    -                MAX(sales.employee_id) AS employee_id,
    -                MAX(sales.customer_id) AS customer_id,
    -                MAX(CONCAT(customer_p.first_name, " ", customer_p.last_name)) AS customer_name,
    -                MAX(customer_p.first_name) AS first_name,
    -                MAX(customer_p.last_name) AS last_name,
    -                MAX(customer_p.email) AS email,
    -                MAX(customer_p.comments) AS comments,
    -                ' . "
    -                IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS amount_due,
    -                MAX(payments.sale_payment_amount) AS amount_tendered,
    -                (MAX(payments.sale_payment_amount) - IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals))) AS change_due,
    -                " . '
    -                MAX(payments.payment_type) AS payment_type
    -        ');
    -
    -        $this->db->from('sales_items AS sales_items');
    -        $this->db->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner');
    -        $this->db->join('people AS customer_p', 'sales.customer_id = customer_p.person_id', 'left');
    -        $this->db->join('customers AS customer', 'sales.customer_id = customer.person_id', 'left');
    -        $this->db->join('sales_payments_temp AS payments', 'sales.sale_id = payments.sale_id', 'left outer');
    -        $this->db->join('sales_items_taxes_temp AS sales_items_taxes',
    -            'sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line',
    -            'left outer');
    -
    -        $this->db->where('sales.sale_id', $sale_id);
    -
    -        $this->db->group_by('sale_id');
    -        $this->db->order_by('sale_time', 'asc');
    -
    -        return $this->db->get();
    -    }
    -
    -    /**
    -     * Get number of rows for the takings (sales/manage) view
    -     */
    -    public function get_found_rows($search, $filters)
    -    {
    -        return $this->search($search, $filters)->num_rows();
    -    }
    -
    -    /**
    -     * Get the sales data for the takings (sales/manage) view
    -     */
    -    public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = 'sale_time', $order = 'desc')
    -    {
    -        $where = '';
    -
    -        if(empty($this->config->item('date_or_time_format')))
    -        {
    -            $where .= 'DATE(sales.sale_time) BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']) . ' AND sales.sale_status = 0 ';
    -        }
    -        else
    -        {
    -            $where .= 'sales.sale_time BETWEEN ' . $this->db->escape(rawurldecode($filters['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($filters['end_date'])) . ' AND sales.sale_status = 0 ';
    -        }
    -
    -        // NOTE: temporary tables are created to speed up searches due to the fact that they are ortogonal to the main query
    -        // create a temporary table to contain all the payments per sale item
    -        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_payments_temp') .
    -            ' (PRIMARY KEY(sale_id), INDEX(sale_id))
    -            (
    -                SELECT payments.sale_id AS sale_id,
    -                    IFNULL(SUM(payments.payment_amount), 0) AS sale_payment_amount,
    -                    GROUP_CONCAT(CONCAT(payments.payment_type, " ", payments.payment_amount) SEPARATOR ", ") AS payment_type
    -                FROM ' . $this->db->dbprefix('sales_payments') . ' AS payments
    -                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    -                    ON sales.sale_id = payments.sale_id
    -                WHERE ' . $where . '
    -                GROUP BY sale_id
    -            )'
    -        );
    -
    -        $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)';
    -
    -        if($this->config->item('tax_included'))
    -        {
    -            $sale_total = 'SUM(' . $sale_price . ')';
    -            $sale_subtotal = 'SUM(' . $sale_price . ' - sales_items_taxes.tax)';
    -        }
    -        else
    -        {
    -            $sale_total = 'SUM(' . $sale_price . ' + sales_items_taxes.tax)';
    -            $sale_subtotal = 'SUM(' . $sale_price . ')';
    -        }
    -
    -        $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)';
    -
    -        $decimals = totals_decimals();
    -
    -        // create a temporary table to contain all the sum of taxes per sale item
    -        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') .
    -            ' (INDEX(sale_id), INDEX(item_id))
    -            (
    -                SELECT sales_items_taxes.sale_id AS sale_id,
    -                    sales_items_taxes.item_id AS item_id,
    -                    sales_items_taxes.line AS line,
    -                    SUM(sales_items_taxes.item_tax_amount) as tax
    -                FROM ' . $this->db->dbprefix('sales_items_taxes') . ' AS sales_items_taxes
    -                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    -                    ON sales.sale_id = sales_items_taxes.sale_id
    -                INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items
    -                    ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.line = sales_items_taxes.line
    -                WHERE ' . $where . '
    -                GROUP BY sale_id, item_id, line
    -            )'
    -        );
    -
    -        $this->db->select('
    -                sales.sale_id AS sale_id,
    -                MAX(DATE(sales.sale_time)) AS sale_date,
    -                MAX(sales.sale_time) AS sale_time,
    -                MAX(sales.invoice_number) AS invoice_number,
    -                MAX(sales.quote_number) AS quote_number,
    -                SUM(sales_items.quantity_purchased) AS items_purchased,
    -                MAX(CONCAT(customer_p.first_name, " ", customer_p.last_name)) AS customer_name,
    -                MAX(customer.company_name) AS company_name,
    -                ' . "
    -                IFNULL(ROUND($sale_subtotal, $decimals), ROUND($sale_total - IFNULL(SUM(sales_items_taxes.tax), 0), $decimals)) AS subtotal,
    -                IFNULL(ROUND(SUM(sales_items_taxes.tax), $decimals), 0) AS tax,
    -                IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total,
    -                IFNULL(ROUND($sale_cost, $decimals), 0) AS cost,
    -                IFNULL(ROUND($sale_total - IFNULL(SUM(sales_items_taxes.tax), 0) - $sale_cost, $decimals), ROUND($sale_subtotal - $sale_cost, $decimals)) AS profit,
    -                IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS amount_due,
    -                MAX(payments.sale_payment_amount) AS amount_tendered,
    -                (MAX(payments.sale_payment_amount) - IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals))) AS change_due,
    -                " . '
    -                MAX(payments.payment_type) AS payment_type
    -        ');
    -
    -        $this->db->from('sales_items AS sales_items');
    -        $this->db->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner');
    -        $this->db->join('people AS customer_p', 'sales.customer_id = customer_p.person_id', 'left');
    -        $this->db->join('customers AS customer', 'sales.customer_id = customer.person_id', 'left');
    -        $this->db->join('sales_payments_temp AS payments', 'sales.sale_id = payments.sale_id', 'left outer');
    -        $this->db->join('sales_items_taxes_temp AS sales_items_taxes',
    -            'sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line',
    -            'left outer');
    -
    -        $this->db->where($where);
    -
    -        if(!empty($search))
    -        {
    -            if($filters['is_valid_receipt'] != FALSE)
    -            {
    -                $pieces = explode(' ', $search);
    -                $this->db->where('sales.sale_id', $pieces[1]);
    -            }
    -            else
    -            {
    -                $this->db->group_start();
    -                    // customer last name
    -                    $this->db->like('customer_p.last_name', $search);
    -                    // customer first name
    -                    $this->db->or_like('customer_p.first_name', $search);
    -                    // customer first and last name
    -                    $this->db->or_like('CONCAT(customer_p.first_name, " ", customer_p.last_name)', $search);
    -                    // customer company name
    -                    $this->db->or_like('customer.company_name', $search);
    -                $this->db->group_end();
    -            }
    -        }
    -
    -        if($filters['location_id'] != 'all')
    -        {
    -            $this->db->where('sales_items.item_location', $filters['location_id']);
    -        }
    -
    -        if($filters['sale_type'] == 'sales')
    -        {
    -            $this->db->where('sales_items.quantity_purchased > 0');
    -        }
    -        elseif($filters['sale_type'] == 'returns')
    -        {
    -            $this->db->where('sales_items.quantity_purchased < 0');
    -        }
    -
    -        if($filters['only_invoices'] != FALSE)
    -        {
    -            $this->db->where('sales.invoice_number IS NOT NULL');
    -        }
    -
    -        if($filters['only_cash'] != FALSE)
    -        {
    -            $this->db->group_start();
    -                $this->db->like('payments.payment_type', $this->lang->line('sales_cash'));
    -                $this->db->or_where('payments.payment_type IS NULL');
    -            $this->db->group_end();
    -        }
    -
    -        if($filters['only_check'] != FALSE)
    -        {
    -            $this->db->like('payments.payment_type', $this->lang->line('sales_check'));
    -        }
    -
    -        $this->db->group_by('sale_id');
    -        $this->db->order_by($sort, $order);
    -
    -        if($rows > 0)
    -        {
    -            $this->db->limit($rows, $limit_from);
    -        }
    -
    -        return $this->db->get();
    -    }
    -
    -    /**
    -     * Get the payment summary for the takings (sales/manage) view
    -     */
    -    public function get_payments_summary($search, $filters)
    -    {
    -        // get payment summary
    -        $this->db->select('payment_type, count(*) AS count, SUM(payment_amount) AS payment_amount');
    -        $this->db->from('sales AS sales');
    -        $this->db->join('sales_payments', 'sales_payments.sale_id = sales.sale_id');
    -        $this->db->join('people AS customer_p', 'sales.customer_id = customer_p.person_id', 'left');
    -        $this->db->join('customers AS customer', 'sales.customer_id = customer.person_id', 'left');
    -
    -        if(empty($this->config->item('date_or_time_format')))
    -        {
    -            $this->db->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']));
    -        }
    -        else
    -        {
    -            $this->db->where('sales.sale_time BETWEEN ' . $this->db->escape(rawurldecode($filters['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($filters['end_date'])));
    -        }
    -
    -        if(!empty($search))
    -        {
    -            if($filters['is_valid_receipt'] != FALSE)
    -            {
    -                $pieces = explode(' ',$search);
    -                $this->db->where('sales.sale_id', $pieces[1]);
    -            }
    -            else
    -            {
    -                $this->db->group_start();
    -                    // customer last name
    -                    $this->db->like('customer_p.last_name', $search);
    -                    // customer first name
    -                    $this->db->or_like('customer_p.first_name', $search);
    -                    // customer first and last name
    -                    $this->db->or_like('CONCAT(customer_p.first_name, " ", customer_p.last_name)', $search);
    -                    // customer company name
    -                    $this->db->or_like('customer.company_name', $search);
    -                $this->db->group_end();
    -            }
    -        }
    -
    -        if($filters['sale_type'] == 'sales')
    -        {
    -            $this->db->where('payment_amount > 0');
    -        }
    -        elseif($filters['sale_type'] == 'returns')
    -        {
    -            $this->db->where('payment_amount < 0');
    -        }
    -
    -        if($filters['only_invoices'] != FALSE)
    -        {
    -            $this->db->where('invoice_number IS NOT NULL');
    -        }
    -
    -        if($filters['only_cash'] != FALSE)
    -        {
    -            $this->db->like('payment_type', $this->lang->line('sales_cash'));
    -        }
    -
    -        if($filters['only_check'] != FALSE)
    -        {
    -            $this->db->like('payment_type', $this->lang->line('sales_check'));
    -        }
    -
    -        $this->db->group_by('payment_type');
    -
    -        $payments = $this->db->get()->result_array();
    -
    -        // consider Gift Card as only one type of payment and do not show "Gift Card: 1, Gift Card: 2, etc." in the total
    -        $gift_card_count = 0;
    -        $gift_card_amount = 0;
    -        foreach($payments as $key=>$payment)
    -        {
    -            if( strstr($payment['payment_type'], $this->lang->line('sales_giftcard')) != FALSE )
    -            {
    -                $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)
    -        {
    -            $payments[] = array('payment_type' => $this->lang->line('sales_giftcard'), 'count' => $gift_card_count, 'payment_amount' => $gift_card_amount);
    -        }
    -
    -        return $payments;
    -    }
    -
    -    /**
    -     * Gets total of rows
    -     */
    -    public function get_total_rows()
    -    {
    -        $this->db->from('sales');
    -
    -        return $this->db->count_all_results();
    -    }
    -
    -    /**
    -     * Gets search suggestions
    -     */
    -    public function get_search_suggestions($search, $limit = 25)
    -    {
    -        $suggestions = array();
    -
    -        if(!$this->is_valid_receipt($search))
    -        {
    -            $this->db->distinct();
    -            $this->db->select('first_name, last_name');
    -            $this->db->from('sales');
    -            $this->db->join('people', 'people.person_id = sales.customer_id');
    -            $this->db->like('last_name', $search);
    -            $this->db->or_like('first_name', $search);
    -            $this->db->or_like('CONCAT(first_name, " ", last_name)', $search);
    -            $this->db->or_like('company_name', $search);
    -            $this->db->order_by('last_name', 'asc');
    -
    -            foreach($this->db->get()->result_array() as $result)
    -            {
    -                $suggestions[] = array('label' => $result['first_name'] . ' ' . $result['last_name']);
    -            }
    -        }
    -        else
    -        {
    -            $suggestions[] = array('label' => $search);
    -        }
    -
    -        return $suggestions;
    -    }
    -
    -    /**
    -     * Gets total of invoice rows
    -     */
    -    public function get_invoice_count()
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('invoice_number IS NOT NULL');
    -
    -        return $this->db->count_all_results();
    -    }
    -
    -    /**
    -     * Gets sale by invoice number
    -     */
    -    public function get_sale_by_invoice_number($invoice_number)
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('invoice_number', $invoice_number);
    -
    -        return $this->db->get();
    -    }
    -
    -    /**
    -     * Gets invoice number by year
    -     */
    -    public function get_invoice_number_for_year($year = '', $start_from = 0)
    -    {
    -        $year = $year == '' ? date('Y') : $year;
    -        $this->db->select('COUNT( 1 ) AS invoice_number_year');
    -        $this->db->from('sales');
    -        $this->db->where('DATE_FORMAT(sale_time, "%Y" ) = ', $year);
    -        $this->db->where('invoice_number IS NOT NULL');
    -        $result = $this->db->get()->row_array();
    -
    -        return ($start_from + $result['invoice_number_year']);
    -    }
    -
    -    /**
    -     * Checks if valid receipt
    -     */
    -    public function is_valid_receipt(&$receipt_sale_id)
    -    {
    -        if(!empty($receipt_sale_id))
    -        {
    -            //POS #
    -            $pieces = explode(' ', $receipt_sale_id);
    -
    -            if(count($pieces) == 2 && preg_match('/(POS)/i', $pieces[0]))
    -            {
    -                return $this->exists($pieces[1]);
    -            }
    -            elseif($this->config->item('invoice_enable') == TRUE)
    -            {
    -                $sale_info = $this->get_sale_by_invoice_number($receipt_sale_id);
    -                if($sale_info->num_rows() > 0)
    -                {
    -                    $receipt_sale_id = 'POS ' . $sale_info->row()->sale_id;
    -
    -                    return TRUE;
    -                }
    -            }
    -        }
    -
    -        return FALSE;
    -    }
    -
    -    /**
    -     * Checks if sale exists
    -     */
    -    public function exists($sale_id)
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        return ($this->db->get()->num_rows()==1);
    -    }
    -
    -    /**
    -     * Update sale
    -     */
    -    public function update($sale_id, $sale_data, $payments)
    -    {
    -        $this->db->where('sale_id', $sale_id);
    -        $success = $this->db->update('sales', $sale_data);
    -
    -        // touch payment only if update sale is successful and there is a payments object otherwise the result would be to delete all the payments associated to the sale
    -        if($success && !empty($payments))
    -        {
    -            //Run these queries as a transaction, we want to make sure we do all or nothing
    -            $this->db->trans_start();
    -
    -            // first delete all payments
    -            $this->db->delete('sales_payments', array('sale_id' => $sale_id));
    -
    -            // add new payments
    -            foreach($payments as $payment)
    -            {
    -                $sales_payments_data = array(
    -                    'sale_id' => $sale_id,
    -                    'payment_type' => $payment['payment_type'],
    -                    'payment_amount' => $payment['payment_amount']
    -                );
    -
    -                $success = $this->db->insert('sales_payments', $sales_payments_data);
    -            }
    -
    -            $this->db->trans_complete();
    -
    -            $success &= $this->db->trans_status();
    -        }
    -
    -        return $success;
    -    }
    +        $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)';
    +        $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')';
    +
    +        if($this->config->item('tax_included'))
    +        {
    +            $sale_total = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')';
    +            $sale_subtotal = $sale_total . ' - ' . $tax;
    +        }
    +        else
    +        {
    +            $sale_subtotal = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')';
    +            $sale_total = $sale_subtotal . ' + ' . $tax;
    +        }
    +
    +        // create a temporary table to contain all the sum of taxes per sale item
    +        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') .
    +            '(
    +                SELECT sales_items_taxes.sale_id AS sale_id,
    +                    sales_items_taxes.item_id AS item_id,
    +                    sales_items_taxes.line AS line,
    +                    SUM(sales_items_taxes.item_tax_amount) AS tax
    +                FROM ' . $this->db->dbprefix('sales_items_taxes') . ' AS sales_items_taxes
    +                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    +                    ON sales.sale_id = sales_items_taxes.sale_id
    +                INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items
    +                    ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.line = sales_items_taxes.line
    +                WHERE sales.sale_id = ' . $this->db->escape($sale_id) . '
    +                GROUP BY sale_id, item_id, line
    +            )'
    +        );
    +
    +        $this->db->select('
    +                sales.sale_id AS sale_id,
    +                MAX(DATE(sales.sale_time)) AS sale_date,
    +                MAX(sales.sale_time) AS sale_time,
    +                MAX(sales.comment) AS comment,
    +                MAX(sales.sale_status) AS sale_status,
    +                MAX(sales.invoice_number) AS invoice_number,
    +                MAX(sales.quote_number) AS quote_number,
    +                MAX(sales.employee_id) AS employee_id,
    +                MAX(sales.customer_id) AS customer_id,
    +                MAX(CONCAT(customer_p.first_name, " ", customer_p.last_name)) AS customer_name,
    +                MAX(customer_p.first_name) AS first_name,
    +                MAX(customer_p.last_name) AS last_name,
    +                MAX(customer_p.email) AS email,
    +                MAX(customer_p.comments) AS comments,
    +                ' . "
    +                IFNULL($sale_total, $sale_subtotal) AS amount_due,
    +                MAX(payments.sale_payment_amount) AS amount_tendered,
    +                (MAX(payments.sale_payment_amount) - IFNULL($sale_total, $sale_subtotal)) AS change_due,
    +                " . '
    +                MAX(payments.payment_type) AS payment_type
    +        ');
    +
    +        $this->db->from('sales_items AS sales_items');
    +        $this->db->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner');
    +        $this->db->join('people AS customer_p', 'sales.customer_id = customer_p.person_id', 'left');
    +        $this->db->join('customers AS customer', 'sales.customer_id = customer.person_id', 'left');
    +        $this->db->join('sales_payments_temp AS payments', 'sales.sale_id = payments.sale_id', 'left outer');
    +        $this->db->join('sales_items_taxes_temp AS sales_items_taxes',
    +            'sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line',
    +            'left outer');
    +
    +        $this->db->where('sales.sale_id', $sale_id);
    +
    +        $this->db->group_by('sale_id');
    +        $this->db->order_by('sale_time', 'asc');
    +
    +        return $this->db->get();
    +    }
    +
    +    /**
    +     * Get number of rows for the takings (sales/manage) view
    +     */
    +    public function get_found_rows($search, $filters)
    +    {
    +        return $this->search($search, $filters)->num_rows();
    +    }
    +
    +    /**
    +     * Get the sales data for the takings (sales/manage) view
    +     */
    +    public function search($search, $filters, $rows = 0, $limit_from = 0, $sort = 'sale_time', $order = 'desc')
    +    {
    +        $where = '';
    +
    +        if(empty($this->config->item('date_or_time_format')))
    +        {
    +            $where .= 'DATE(sales.sale_time) BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']) . ' AND sales.sale_status = 0 ';
    +        }
    +        else
    +        {
    +            $where .= 'sales.sale_time BETWEEN ' . $this->db->escape(rawurldecode($filters['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($filters['end_date'])) . ' AND sales.sale_status = 0 ';
    +        }
    +
    +        // NOTE: temporary tables are created to speed up searches due to the fact that they are ortogonal to the main query
    +        // create a temporary table to contain all the payments per sale item
    +        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_payments_temp') .
    +            ' (PRIMARY KEY(sale_id), INDEX(sale_id))
    +            (
    +                SELECT payments.sale_id AS sale_id,
    +                    IFNULL(SUM(payments.payment_amount), 0) AS sale_payment_amount,
    +                    GROUP_CONCAT(CONCAT(payments.payment_type, " ", payments.payment_amount) SEPARATOR ", ") AS payment_type
    +                FROM ' . $this->db->dbprefix('sales_payments') . ' AS payments
    +                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    +                    ON sales.sale_id = payments.sale_id
    +                WHERE ' . $where . '
    +                GROUP BY sale_id
    +            )'
    +        );
    +
    +        $decimals = totals_decimals();
    +
    +        $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)';
    +        $sale_cost = 'ROUND(SUM(sales_items.item_cost_price * sales_items.quantity_purchased), ' . $decimals . ')';
    +        $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')';
    +
    +        if($this->config->item('tax_included'))
    +        {
    +            $sale_total = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')';
    +            $sale_subtotal = $sale_total . ' - ' . $tax;
    +        }
    +        else
    +        {
    +            $sale_subtotal = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')';
    +            $sale_total = $sale_subtotal . ' + ' . $tax;
    +        }
    +
    +        // create a temporary table to contain all the sum of taxes per sale item
    +        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') .
    +            ' (INDEX(sale_id), INDEX(item_id))
    +            (
    +                SELECT sales_items_taxes.sale_id AS sale_id,
    +                    sales_items_taxes.item_id AS item_id,
    +                    sales_items_taxes.line AS line,
    +                    SUM(sales_items_taxes.item_tax_amount) as tax
    +                FROM ' . $this->db->dbprefix('sales_items_taxes') . ' AS sales_items_taxes
    +                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    +                    ON sales.sale_id = sales_items_taxes.sale_id
    +                INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items
    +                    ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.line = sales_items_taxes.line
    +                WHERE ' . $where . '
    +                GROUP BY sale_id, item_id, line
    +            )'
    +        );
    +
    +        $this->db->select('
    +                sales.sale_id AS sale_id,
    +                MAX(DATE(sales.sale_time)) AS sale_date,
    +                MAX(sales.sale_time) AS sale_time,
    +                MAX(sales.invoice_number) AS invoice_number,
    +                MAX(sales.quote_number) AS quote_number,
    +                SUM(sales_items.quantity_purchased) AS items_purchased,
    +                MAX(CONCAT(customer_p.first_name, " ", customer_p.last_name)) AS customer_name,
    +                MAX(customer.company_name) AS company_name,
    +                ' . "
    +                IFNULL($sale_subtotal, $sale_total) AS subtotal,
    +                $tax AS tax,
    +                IFNULL($sale_total, $sale_subtotal) AS total,
    +                $sale_cost AS cost,
    +                (IFNULL($sale_subtotal, $sale_total) - $sale_cost) AS profit,
    +                IFNULL($sale_total, $sale_subtotal) AS amount_due,
    +                MAX(payments.sale_payment_amount) AS amount_tendered,
    +                (MAX(payments.sale_payment_amount) - IFNULL($sale_total, $sale_subtotal)) AS change_due,
    +                " . '
    +                MAX(payments.payment_type) AS payment_type
    +        ');
    +
    +        $this->db->from('sales_items AS sales_items');
    +        $this->db->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner');
    +        $this->db->join('people AS customer_p', 'sales.customer_id = customer_p.person_id', 'left');
    +        $this->db->join('customers AS customer', 'sales.customer_id = customer.person_id', 'left');
    +        $this->db->join('sales_payments_temp AS payments', 'sales.sale_id = payments.sale_id', 'left outer');
    +        $this->db->join('sales_items_taxes_temp AS sales_items_taxes',
    +            'sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line',
    +            'left outer');
    +
    +        $this->db->where($where);
    +
    +        if(!empty($search))
    +        {
    +            if($filters['is_valid_receipt'] != FALSE)
    +            {
    +                $pieces = explode(' ', $search);
    +                $this->db->where('sales.sale_id', $pieces[1]);
    +            }
    +            else
    +            {
    +                $this->db->group_start();
    +                    // customer last name
    +                    $this->db->like('customer_p.last_name', $search);
    +                    // customer first name
    +                    $this->db->or_like('customer_p.first_name', $search);
    +                    // customer first and last name
    +                    $this->db->or_like('CONCAT(customer_p.first_name, " ", customer_p.last_name)', $search);
    +                    // customer company name
    +                    $this->db->or_like('customer.company_name', $search);
    +                $this->db->group_end();
    +            }
    +        }
    +
    +        if($filters['location_id'] != 'all')
    +        {
    +            $this->db->where('sales_items.item_location', $filters['location_id']);
    +        }
    +
    +        if($filters['sale_type'] == 'sales')
    +        {
    +            $this->db->where('sales_items.quantity_purchased > 0');
    +        }
    +        elseif($filters['sale_type'] == 'returns')
    +        {
    +            $this->db->where('sales_items.quantity_purchased < 0');
    +        }
    +
    +        if($filters['only_invoices'] != FALSE)
    +        {
    +            $this->db->where('sales.invoice_number IS NOT NULL');
    +        }
    +
    +        if($filters['only_cash'] != FALSE)
    +        {
    +            $this->db->group_start();
    +                $this->db->like('payments.payment_type', $this->lang->line('sales_cash'));
    +                $this->db->or_where('payments.payment_type IS NULL');
    +            $this->db->group_end();
    +        }
    +
    +        if($filters['only_check'] != FALSE)
    +        {
    +            $this->db->like('payments.payment_type', $this->lang->line('sales_check'));
    +        }
    +
    +        $this->db->group_by('sale_id');
    +        $this->db->order_by($sort, $order);
    +
    +        if($rows > 0)
    +        {
    +            $this->db->limit($rows, $limit_from);
    +        }
    +
    +        return $this->db->get();
    +    }
    +
    +    /**
    +     * Get the payment summary for the takings (sales/manage) view
    +     */
    +    public function get_payments_summary($search, $filters)
    +    {
    +        // get payment summary
    +        $this->db->select('payment_type, count(*) AS count, SUM(payment_amount) AS payment_amount');
    +        $this->db->from('sales AS sales');
    +        $this->db->join('sales_payments', 'sales_payments.sale_id = sales.sale_id');
    +        $this->db->join('people AS customer_p', 'sales.customer_id = customer_p.person_id', 'left');
    +        $this->db->join('customers AS customer', 'sales.customer_id = customer.person_id', 'left');
    +
    +        if(empty($this->config->item('date_or_time_format')))
    +        {
    +            $this->db->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']));
    +        }
    +        else
    +        {
    +            $this->db->where('sales.sale_time BETWEEN ' . $this->db->escape(rawurldecode($filters['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($filters['end_date'])));
    +        }
    +
    +        if(!empty($search))
    +        {
    +            if($filters['is_valid_receipt'] != FALSE)
    +            {
    +                $pieces = explode(' ',$search);
    +                $this->db->where('sales.sale_id', $pieces[1]);
    +            }
    +            else
    +            {
    +                $this->db->group_start();
    +                    // customer last name
    +                    $this->db->like('customer_p.last_name', $search);
    +                    // customer first name
    +                    $this->db->or_like('customer_p.first_name', $search);
    +                    // customer first and last name
    +                    $this->db->or_like('CONCAT(customer_p.first_name, " ", customer_p.last_name)', $search);
    +                    // customer company name
    +                    $this->db->or_like('customer.company_name', $search);
    +                $this->db->group_end();
    +            }
    +        }
    +
    +        if($filters['sale_type'] == 'sales')
    +        {
    +            $this->db->where('payment_amount > 0');
    +        }
    +        elseif($filters['sale_type'] == 'returns')
    +        {
    +            $this->db->where('payment_amount < 0');
    +        }
    +
    +        if($filters['only_invoices'] != FALSE)
    +        {
    +            $this->db->where('invoice_number IS NOT NULL');
    +        }
    +
    +        if($filters['only_cash'] != FALSE)
    +        {
    +            $this->db->like('payment_type', $this->lang->line('sales_cash'));
    +        }
    +
    +        if($filters['only_check'] != FALSE)
    +        {
    +            $this->db->like('payment_type', $this->lang->line('sales_check'));
    +        }
    +
    +        $this->db->group_by('payment_type');
    +
    +        $payments = $this->db->get()->result_array();
    +
    +        // consider Gift Card as only one type of payment and do not show "Gift Card: 1, Gift Card: 2, etc." in the total
    +        $gift_card_count = 0;
    +        $gift_card_amount = 0;
    +        foreach($payments as $key=>$payment)
    +        {
    +            if( strstr($payment['payment_type'], $this->lang->line('sales_giftcard')) != FALSE )
    +            {
    +                $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)
    +        {
    +            $payments[] = array('payment_type' => $this->lang->line('sales_giftcard'), 'count' => $gift_card_count, 'payment_amount' => $gift_card_amount);
    +        }
    +
    +        return $payments;
    +    }
    +
    +    /**
    +     * Gets total of rows
    +     */
    +    public function get_total_rows()
    +    {
    +        $this->db->from('sales');
    +
    +        return $this->db->count_all_results();
    +    }
    +
    +    /**
    +     * Gets search suggestions
    +     */
    +    public function get_search_suggestions($search, $limit = 25)
    +    {
    +        $suggestions = array();
    +
    +        if(!$this->is_valid_receipt($search))
    +        {
    +            $this->db->distinct();
    +            $this->db->select('first_name, last_name');
    +            $this->db->from('sales');
    +            $this->db->join('people', 'people.person_id = sales.customer_id');
    +            $this->db->like('last_name', $search);
    +            $this->db->or_like('first_name', $search);
    +            $this->db->or_like('CONCAT(first_name, " ", last_name)', $search);
    +            $this->db->or_like('company_name', $search);
    +            $this->db->order_by('last_name', 'asc');
    +
    +            foreach($this->db->get()->result_array() as $result)
    +            {
    +                $suggestions[] = array('label' => $result['first_name'] . ' ' . $result['last_name']);
    +            }
    +        }
    +        else
    +        {
    +            $suggestions[] = array('label' => $search);
    +        }
    +
    +        return $suggestions;
    +    }
    +
    +    /**
    +     * Gets total of invoice rows
    +     */
    +    public function get_invoice_count()
    +    {
    +        $this->db->from('sales');
    +        $this->db->where('invoice_number IS NOT NULL');
    +
    +        return $this->db->count_all_results();
    +    }
    +
    +    /**
    +     * Gets sale by invoice number
    +     */
    +    public function get_sale_by_invoice_number($invoice_number)
    +    {
    +        $this->db->from('sales');
    +        $this->db->where('invoice_number', $invoice_number);
    +
    +        return $this->db->get();
    +    }
    +
    +    /**
    +     * Gets invoice number by year
    +     */
    +    public function get_invoice_number_for_year($year = '', $start_from = 0)
    +    {
    +        $year = $year == '' ? date('Y') : $year;
    +        $this->db->select('COUNT( 1 ) AS invoice_number_year');
    +        $this->db->from('sales');
    +        $this->db->where('DATE_FORMAT(sale_time, "%Y" ) = ', $year);
    +        $this->db->where('invoice_number IS NOT NULL');
    +        $result = $this->db->get()->row_array();
    +
    +        return ($start_from + $result['invoice_number_year']);
    +    }
    +
    +    /**
    +     * Checks if valid receipt
    +     */
    +    public function is_valid_receipt(&$receipt_sale_id)
    +    {
    +        if(!empty($receipt_sale_id))
    +        {
    +            //POS #
    +            $pieces = explode(' ', $receipt_sale_id);
    +
    +            if(count($pieces) == 2 && preg_match('/(POS)/i', $pieces[0]))
    +            {
    +                return $this->exists($pieces[1]);
    +            }
    +            elseif($this->config->item('invoice_enable') == TRUE)
    +            {
    +                $sale_info = $this->get_sale_by_invoice_number($receipt_sale_id);
    +                if($sale_info->num_rows() > 0)
    +                {
    +                    $receipt_sale_id = 'POS ' . $sale_info->row()->sale_id;
    +
    +                    return TRUE;
    +                }
    +            }
    +        }
    +
    +        return FALSE;
    +    }
    +
    +    /**
    +     * Checks if sale exists
    +     */
    +    public function exists($sale_id)
    +    {
    +        $this->db->from('sales');
    +        $this->db->where('sale_id', $sale_id);
    +
    +        return ($this->db->get()->num_rows()==1);
    +    }
    +
    +    /**
    +     * Update sale
    +     */
    +    public function update($sale_id, $sale_data, $payments)
    +    {
    +        $this->db->where('sale_id', $sale_id);
    +        $success = $this->db->update('sales', $sale_data);
    +
    +        // touch payment only if update sale is successful and there is a payments object otherwise the result would be to delete all the payments associated to the sale
    +        if($success && !empty($payments))
    +        {
    +            //Run these queries as a transaction, we want to make sure we do all or nothing
    +            $this->db->trans_start();
    +
    +            // first delete all payments
    +            $this->db->delete('sales_payments', array('sale_id' => $sale_id));
    +
    +            // add new payments
    +            foreach($payments as $payment)
    +            {
    +                $sales_payments_data = array(
    +                    'sale_id' => $sale_id,
    +                    'payment_type' => $payment['payment_type'],
    +                    'payment_amount' => $payment['payment_amount']
    +                );
    +
    +                $success = $this->db->insert('sales_payments', $sales_payments_data);
    +            }
    +
    +            $this->db->trans_complete();
    +
    +            $success &= $this->db->trans_status();
    +        }
    +
    +        return $success;
    +    }
    +
     
    -
    -    /**
    -     * Save the sale information after the sales is complete but before the final document is printed
    -     * The sales_taxes variable needs to be initialized to an empty array before calling
    -     */
    -    public function save(&$sale_status, &$items, $customer_id, $employee_id, $comment, $invoice_number, $quote_number, $payments, $dinner_table, &$sales_taxes, $sale_id = FALSE)
    -    {
    -        $tax_decimals = $this->config->item('tax_decimals');
    -
    -        if(count($items) == 0)
    -        {
    -            return -1;
    -        }
    -
    -        if($sale_status == '1') //suspend sales
    -        {
    -            if($dinner_table > 2)   //not delivery or take away
    -            {
    -                $table_status = 1;
    -            }
    -            else
    -            {
    -                $table_status = 0;
    -            }
    -        }
    -        else
    -        {
    -            $table_status = 0;
    -        }
    -
    -        $sales_data = array(
    -            'sale_time'      => date('Y-m-d H:i:s'),
    -            'customer_id'    => $this->Customer->exists($customer_id) ? $customer_id : null,
    -            'employee_id'    => $employee_id,
    -            'comment'        => $comment,
    -            'invoice_number' => $invoice_number,
    -            'quote_number' => $quote_number,
    -            'dinner_table_id'=> $dinner_table,
    -            'sale_status'    => $sale_status
    -        );
    -
    -        // Run these queries as a transaction, we want to make sure we do all or nothing
    -        $this->db->trans_start();
    -
    -        $this->db->insert('sales', $sales_data);
    -        $sale_id = $this->db->insert_id();
    -        $total_amount = 0;
    -        $total_amount_used = 0;
    -        foreach($payments as $payment_id=>$payment)
    -        {
    -            if( substr( $payment['payment_type'], 0, strlen( $this->lang->line('sales_giftcard') ) ) == $this->lang->line('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'] );
    -            }
    -
    -            if( substr( $payment['payment_type'], 0, strlen( $this->lang->line('sales_rewards') ) ) == $this->lang->line('sales_rewards') )
    -            {
    -
    -                $cur_rewards_value = $this->Customer->get_info($customer_id)->points;
    -                $this->Customer->update_reward_points_value($customer_id, $cur_rewards_value - $payment['payment_amount'] );
    -                $total_amount_used = floatval($total_amount_used) + floatval($payment['payment_amount']);
    -            }
    -
    -            $sales_payments_data = array(
    -                'sale_id'        => $sale_id,
    -                'payment_type'   => $payment['payment_type'],
    -                'payment_amount' => $payment['payment_amount']
    -            );
    -            $this->db->insert('sales_payments', $sales_payments_data);
    -            $total_amount = floatval($total_amount) + floatval($payment['payment_amount']);
    -        }
    -
    -        if(!empty($customer_id) && $this->config->item('customer_reward_enable') == TRUE)
    -        {
    -            $package_id = $this->Customer->get_info($customer_id)->package_id;
    -
    -            if(!empty($package_id))
    -            {
    -                $points_percent = $this->Customer_rewards->get_points_percent($package_id);
    -                $points = $this->Customer->get_info($customer_id)->points;
    -                $points = ($points==NULL ? 0 : $points);
    -                $points_percent = ($points_percent==NULL ? 0 : $points_percent);
    -                $total_amount_earned = ($total_amount*$points_percent/100);
    -                $points = $points + $total_amount_earned;
    -                $this->Customer->update_reward_points_value($customer_id, $points);
    -                $rewards_data = array('sale_id'=>$sale_id, 'earned'=>$total_amount_earned, 'used'=>$total_amount_used);
    -                $this->Rewards->save($rewards_data);
    -            }
    -        }
    -
    -        $customer = $this->Customer->get_info($customer_id);
    -
    -        $sales_taxes = array();
    -
    -        foreach($items as $line=>$item)
    -        {
    -            $cur_item_info = $this->Item->get_info($item['item_id']);
    -
    -            $sales_items_data = array(
    -                'sale_id'           => $sale_id,
    -                'item_id'           => $item['item_id'],
    -                'line'              => $item['line'],
    -                'description'       => character_limiter($item['description'], 30),
    -                'serialnumber'      => character_limiter($item['serialnumber'], 30),
    -                'quantity_purchased'=> $item['quantity'],
    -                'discount_percent'  => $item['discount'],
    -                'item_cost_price'   => $cur_item_info->cost_price,
    -                'item_unit_price'   => $item['price'],
    -                'item_location'     => $item['item_location'],
    -                'print_option'      => $item['print_option']
    -            );
    -
    -            $this->db->insert('sales_items', $sales_items_data);
    -
    -            if($cur_item_info->stock_type === '0' && $sale_status === '0')
    -            {
    -                // Update stock quantity if item type is a standard stock item and the sale is a standard sale
    -                $item_quantity = $this->Item_quantity->get_item_quantity($item['item_id'], $item['item_location']);
    -                $this->Item_quantity->save(array('quantity'     => $item_quantity->quantity - $item['quantity'],
    -                    'item_id'       => $item['item_id'],
    -                    'location_id'   => $item['item_location']), $item['item_id'], $item['item_location']);
    -
    -                // if an items was deleted but later returned it's restored with this rule
    -
    -                if($item['quantity'] < 0)
    -                {
    -                    $this->Item->undelete($item['item_id']);
    -                }
    -
    -                // Inventory Count Details
    -                $sale_remarks = 'POS '.$sale_id;
    -                $inv_data = array(
    -                    'trans_date'        => date('Y-m-d H:i:s'),
    -                    'trans_items'       => $item['item_id'],
    -                    'trans_user'        => $employee_id,
    -                    'trans_location'    => $item['item_location'],
    -                    'trans_comment'     => $sale_remarks,
    -                    'trans_inventory'   => -$item['quantity']
    -                );
    -                $this->Inventory->insert($inv_data);
    -            }
    -
    -            // Calculate taxes and save the tax information for the sale.  Return the result for printing
    -
    -            if($customer_id == -1 || $customer->taxable)
    -            {
    -                if($this->config->item('tax_included'))
    -                {
    -                    $tax_type = Tax_lib::TAX_TYPE_VAT;
    -                }
    -                else
    -                {
    -                    $tax_type = Tax_lib::TAX_TYPE_SALES;
    -                }
    -                $rounding_code = Rounding_code::HALF_UP; // half adjust
    -                $tax_group_sequence = 0;
    -                $item_total = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], TRUE);
    -                $tax_basis = $item_total;
    -                $item_tax_amount = 0;
    -
    -                foreach($this->Item_taxes->get_info($item['item_id']) as $row)
    -                {
    -
    -                    $sales_items_taxes = array(
    -                        'sale_id'           => $sale_id,
    -                        'item_id'           => $item['item_id'],
    -                        'line'              => $item['line'],
    -                        'name'              => character_limiter($row['name'], 255),
    -                        'percent'           => $row['percent'],
    -                        'tax_type'          => $tax_type,
    -                        'rounding_code'     => $rounding_code,
    -                        'cascade_tax'       => 0,
    -                        'cascade_sequence'  => 0,
    -                        'item_tax_amount'   => 0
    -                    );
    -
    -                    // This computes tax for each line item and adds it to the tax type total
    -                    $tax_group = (float)$row['percent'] . '% ' . $row['name'];
    -                    $tax_basis = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], TRUE);
    -
    -                    if($this->config->item('tax_included'))
    -                    {
    -                        $tax_type = Tax_lib::TAX_TYPE_VAT;
    -                        $item_tax_amount = $this->sale_lib->get_item_tax($item['quantity'], $item['price'], $item['discount'],$row['percent']);
    -                    }
    -                    elseif($this->config->item('customer_sales_tax_support') == '0')
    -                    {
    -                        $tax_type = Tax_lib::TAX_TYPE_SALES;
    -                        $item_tax_amount = $this->tax_lib->get_sales_tax_for_amount($tax_basis, $row['percent'], '0', $tax_decimals);
    -                    }
    -                    else
    -                    {
    -                        $tax_type = Tax_lib::TAX_TYPE_SALES;
    -                    }
    -
    -                    $sales_items_taxes['item_tax_amount'] = $item_tax_amount;
    -                    if($item_tax_amount != 0)
    -                    {
    -                        $this->db->insert('sales_items_taxes', $sales_items_taxes);
    -                        $this->tax_lib->update_sales_taxes($sales_taxes, $tax_type, $tax_group, $row['percent'], $tax_basis, $item_tax_amount, $tax_group_sequence, $rounding_code, $sale_id,  $row['name'], '');
    -                        $tax_group_sequence += 1;
    -                    }
    -
    -                }
    -
    -                if($this->config->item('customer_sales_tax_support') == '1')
    -                {
    -                    $this->save_sales_item_tax($customer, $sale_id, $item, $item_total, $sales_taxes, $sequence, $cur_item_info->tax_category_id);
    -                }
    -            }
    -        }
    -
    -        if($customer_id == -1 || $customer->taxable)
    -        {
    -            $this->tax_lib->round_sales_taxes($sales_taxes);
    -            $this->save_sales_tax($sales_taxes);
    -        }
    -
    -        $dinner_table_data = array(
    -            'status' => $table_status
    -        );
    -
    -        $this->db->where('dinner_table_id',$dinner_table);
    -        $this->db->update('dinner_tables', $dinner_table_data);
    -
    -        $this->db->trans_complete();
    -
    -        if($this->db->trans_status() === FALSE)
    -        {
    -            return -1;
    -        }
    -
    -        return $sale_id;
    -    }
    -
    -    /**
    -     * Apply customer sales tax if the customer sales tax is enabledl
    -     * The original tax is still supported if the user configures it,
    -     * but it won't make sense unless it's used exclusively for the purpose
    -     * of VAT tax which becomes a price component.  VAT taxes must still be reported
    -     * as a separate tax entry on the invoice.
    -     */
    -    public function save_sales_item_tax(&$customer, &$sale_id, &$item, $tax_basis, &$sales_taxes, &$sequence, $tax_category_id)
    -    {
    -        // if customer sales tax is enabled then update  sales_items_taxes with the
    -        if($this->config->item('customer_sales_tax_support') == '1')
    -        {
    -            $register_mode = $this->config->item('default_register_mode');
    -            $tax_details = $this->tax_lib->apply_sales_tax($item, $customer->city, $customer->state, $customer->sales_tax_code, $register_mode, $sale_id, $sales_taxes);
    -
    -            $sales_items_taxes = array(
    -                'sale_id'           => $sale_id,
    -                'item_id'           => $item['item_id'],
    -                'line'              => $item['line'],
    -                'name'              => $tax_details['tax_name'],
    -                'percent'           => $tax_details['tax_rate'],
    -                'tax_type'          => Tax_lib::TAX_TYPE_SALES,
    -                'rounding_code'     => $tax_details['rounding_code'],
    -                'cascade_tax'       => 0,
    -                'cascade_sequence'  => 0,
    -                'item_tax_amount'   => $tax_details['item_tax_amount']
    -            );
    -
    -            $this->db->insert('sales_items_taxes', $sales_items_taxes);
    -        }
    -    }
    -
    -    /**
    -     * Saves sale tax
    -     */
    -    public function save_sales_tax(&$sales_taxes)
    -    {
    -        foreach($sales_taxes as $line=>$sales_tax)
    -        {
    -            $this->db->insert('sales_taxes', $sales_tax);
    -        }
    -    }
    -
    -    /**
    -     * Deletes list of sales
    -     */
    -    public function delete_list($sale_ids, $employee_id, $update_inventory = TRUE)
    -    {
    -        $result = TRUE;
    -
    -        foreach($sale_ids as $sale_id)
    -        {
    -            $result &= $this->delete($sale_id, $employee_id, $update_inventory);
    -        }
    -
    -        return $result;
    -    }
    -
    -    /**
    -     * Delete sale
    -     */
    -    public function delete($sale_id, $employee_id, $update_inventory = TRUE)
    -    {
    -        // start a transaction to assure data integrity
    -        $this->db->trans_start();
    -
    -        // first delete all payments
    -        $this->db->delete('sales_payments', array('sale_id' => $sale_id));
    -        // then delete all taxes on items
    -        $this->db->delete('sales_items_taxes', array('sale_id' => $sale_id));
    -
    -        if($update_inventory)
    -        {
    -            // defect, not all item deletions will be undone??
    -            // get array with all the items involved in the sale to update the inventory tracking
    -            $items = $this->get_sale_items($sale_id)->result_array();
    -            foreach($items as $item)
    -            {
    -                $cur_item_info = $this->Item->get_info($item['item_id']);
    -
    -                if($cur_item_info->stock_type === '0') {
    -                    // create query to update inventory tracking
    -                    $inv_data = array(
    -                        'trans_date' => date('Y-m-d H:i:s'),
    -                        'trans_items' => $item['item_id'],
    -                        'trans_user' => $employee_id,
    -                        'trans_comment' => 'Deleting sale ' . $sale_id,
    -                        'trans_location' => $item['item_location'],
    -                        'trans_inventory' => $item['quantity_purchased']
    -                    );
    -                    // update inventory
    -                    $this->Inventory->insert($inv_data);
    -
    -                    // update quantities
    -                    $this->Item_quantity->change_quantity($item['item_id'], $item['item_location'], $item['quantity_purchased']);
    -                }
    -            }
    -        }
    -
    -        // delete all items
    -        $this->db->delete('sales_items', array('sale_id' => $sale_id));
    -        // delete sale itself
    -        $this->db->delete('sales', array('sale_id' => $sale_id));
    -
    -        // execute transaction
    -        $this->db->trans_complete();
    -
    -        return $this->db->trans_status();
    -    }
    -
    -    /**
    -     * Gets sale item
    -     */
    -    public function get_sale_items($sale_id)
    -    {
    -        $this->db->from('sales_items');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        return $this->db->get();
    -    }
    -
    -    /**
    -     * Used by the invoice and receipt programs
    -     */
    -    public function get_sale_items_ordered($sale_id)
    -    {
    -        $this->db->select('
    -            sale_id,
    -            sales_items.item_id,
    -            sales_items.description,
    -            serialnumber,
    -            line,
    -            quantity_purchased,
    -            item_cost_price,
    -            item_unit_price,
    -            discount_percent,
    -            item_location,
    -            print_option,
    -            items.name as name,
    -            category,
    -            item_type,
    -            stock_type');
    -        $this->db->from('sales_items as sales_items');
    -        $this->db->join('items as items', 'sales_items.item_id = items.item_id');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        // Entry sequence (this will render kits in the expected sequence)
    -        if($this->config->item('line_sequence') == '0')
    -        {
    -            $this->db->order_by('line', 'asc');
    -        }
    -        // Group by Stock Type (nonstock first - type 1, stock next - type 0)
    -        elseif($this->config->item('line_sequence') == '1')
    -        {
    -            $this->db->order_by('stock_type', 'desc');
    -            $this->db->order_by('sales_items.description', 'asc');
    -            $this->db->order_by('items.name', 'asc');
    -        }
    -        // Group by Item Category
    -        elseif($this->config->item('line_sequence') == '2')
    -        {
    -            $this->db->order_by('category', 'asc');
    -            $this->db->order_by('sales_items.description', 'asc');
    -            $this->db->order_by('items.name', 'asc');
    -        }
    -        // Group by entry sequence in descending sequence (the Standard)
    -        else
    -        {
    -            $this->db->order_by('line', 'desc');
    -        }
    -
    -        return $this->db->get();
    -    }
    -
    -    /**
    -     * Gets sale payments
    -     */
    -    public function get_sale_payments($sale_id)
    -    {
    -        $this->db->from('sales_payments');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        return $this->db->get();
    -    }
    -
    -    /**
    -     * Gets sale payment options
    -     */
    -    public function get_payment_options($giftcard = TRUE, $reward_points = FALSE)
    -    {
    -        $payments = array();
    -
    -        if($this->config->item('payment_options_order') == 'debitcreditcash')
    -        {
    -            $payments[$this->lang->line('sales_debit')] = $this->lang->line('sales_debit');
    -            $payments[$this->lang->line('sales_credit')] = $this->lang->line('sales_credit');
    -            $payments[$this->lang->line('sales_cash')] = $this->lang->line('sales_cash');
    -        }
    -        elseif($this->config->item('payment_options_order') == 'debitcashcredit')
    -        {
    -            $payments[$this->lang->line('sales_debit')] = $this->lang->line('sales_debit');
    -            $payments[$this->lang->line('sales_cash')] = $this->lang->line('sales_cash');
    -            $payments[$this->lang->line('sales_credit')] = $this->lang->line('sales_credit');
    -        }
    -        else // default: if($this->config->item('payment_options_order') == 'cashdebitcredit')
    -        {
    -            $payments[$this->lang->line('sales_cash')] = $this->lang->line('sales_cash');
    -            $payments[$this->lang->line('sales_debit')] = $this->lang->line('sales_debit');
    -            $payments[$this->lang->line('sales_credit')] = $this->lang->line('sales_credit');
    -        }
    -
    -        $payments[$this->lang->line('sales_check')] = $this->lang->line('sales_check');
    -
    -        if($giftcard)
    -        {
    -            $payments[$this->lang->line('sales_giftcard')] = $this->lang->line('sales_giftcard');
    -        }
    -
    -        if($reward_points)
    -        {
    -            $payments[$this->lang->line('sales_rewards')] = $this->lang->line('sales_rewards');
    -        }
    -
    -        return $payments;
    -    }
    -
    -    /**
    -     * Gets sale customer name
    -     */
    -    public function get_customer($sale_id)
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        return $this->Customer->get_info($this->db->get()->row()->customer_id);
    -    }
    -
    -    /**
    -     * Gets sale employee name
    -     */
    -    public function get_employee($sale_id)
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        return $this->Employee->get_info($this->db->get()->row()->employee_id);
    -    }
    -
    -    /**
    -     * Checks if quote number exists
    -     */
    -    // TODO change to use new quote_number field
    -    public function check_quote_number_exists($quote_number, $sale_id = '')
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('quote_number', $quote_number);
    -        if(!empty($sale_id))
    -        {
    -            $this->db->where('sale_id !=', $sale_id);
    -        }
    -
    -        return ($this->db->get()->num_rows() == 1);
    -    }
    -
    -    /**
    -     * Checks if invoice number exists
    -     */
    -    public function check_invoice_number_exists($invoice_number, $sale_id = '')
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('invoice_number', $invoice_number);
    -        if(!empty($sale_id))
    -        {
    -            $this->db->where('sale_id !=', $sale_id);
    -        }
    -
    -        return ($this->db->get()->num_rows() == 1);
    -    }
    -
    -    /**
    -     * Gets Giftcard value
    -     */
    -    public 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;
    -    }
    -
    -    /**
    -     * Creates sales temporary dimentional table
    -     * We create a temp table that allows us to do easy report/sales queries
    -     */
    -    public function create_temp_table(array $inputs)
    -    {
    -        if(empty($inputs['sale_id']))
    -        {
    -            if(empty($this->config->item('date_or_time_format')))
    -            {
    -                $where = 'DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']);
    -            }
    -            else
    -            {
    -                $where = 'sales.sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date']));
    -            }
    -        }
    -        else
    -        {
    -            $where = 'sales.sale_id = ' . $this->db->escape($inputs['sale_id']);
    -        }
    -
    -        $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)';
    -
    -        if($this->config->item('tax_included'))
    -        {
    -            $sale_total = 'SUM(' . $sale_price . ')';
    -            $sale_subtotal = 'SUM(' . $sale_price . ' - sales_items_taxes.tax)';
    -        }
    -        else
    -        {
    -            $sale_total = 'SUM(' . $sale_price . ' + sales_items_taxes.tax)';
    -            $sale_subtotal = 'SUM(' . $sale_price . ')';
    -        }
    -
    -        $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)';
    -
    -        $decimals = totals_decimals();
    -
    -        // create a temporary table to contain all the sum of taxes per sale item
    -        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') .
    -            ' (INDEX(sale_id), INDEX(item_id))
    -            (
    -                SELECT sales_items_taxes.sale_id AS sale_id,
    -                    sales_items_taxes.item_id AS item_id,
    -                    sales_items_taxes.line AS line,
    -                    SUM(sales_items_taxes.item_tax_amount) as tax
    -                FROM ' . $this->db->dbprefix('sales_items_taxes') . ' AS sales_items_taxes
    -                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    -                    ON sales.sale_id = sales_items_taxes.sale_id
    -                INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items
    -                    ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.line = sales_items_taxes.line
    -                WHERE sales.sale_status = 0 AND ' . $where . '
    -                GROUP BY sale_id, item_id, line
    -            )'
    -        );
    -
    -        // create a temporary table to contain all the payment types and amount
    -        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_payments_temp') .
    -            ' (PRIMARY KEY(sale_id), INDEX(sale_id))
    -            (
    -                SELECT payments.sale_id AS sale_id,
    -                    IFNULL(SUM(payments.payment_amount), 0) AS sale_payment_amount,
    -                    GROUP_CONCAT(CONCAT(payments.payment_type, " ", payments.payment_amount) SEPARATOR ", ") AS payment_type
    -                FROM ' . $this->db->dbprefix('sales_payments') . ' AS payments
    -                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    -                    ON sales.sale_id = payments.sale_id
    -                WHERE sales.sale_status = 0 AND ' . $where . '
    -                GROUP BY payments.sale_id
    -            )'
    -        );
    -
    -        $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_temp') .
    -            ' (INDEX(sale_date), INDEX(sale_time), INDEX(sale_id))
    -            (
    -                SELECT
    -                    MAX(DATE(sales.sale_time)) AS sale_date,
    -                    MAX(sales.sale_time) AS sale_time,
    -                    sales.sale_id AS sale_id,
    -                    MAX(sales.comment) AS comment,
    -                    MAX(sales.invoice_number) AS invoice_number,
    -                    MAX(sales.quote_number) AS quote_number,
    -                    MAX(sales.customer_id) AS customer_id,
    -                    MAX(CONCAT(customer_p.first_name, " ", customer_p.last_name)) AS customer_name,
    -                    MAX(customer_p.first_name) AS customer_first_name,
    -                    MAX(customer_p.last_name) AS customer_last_name,
    -                    MAX(customer_p.email) AS customer_email,
    -                    MAX(customer_p.comments) AS customer_comments,
    -                    MAX(customer.company_name) AS customer_company_name,
    -                    MAX(sales.employee_id) AS employee_id,
    -                    MAX(CONCAT(employee.first_name, " ", employee.last_name)) AS employee_name,
    -                    items.item_id AS item_id,
    -                    MAX(items.name) AS name,
    -                    MAX(items.category) AS category,
    -                    MAX(items.supplier_id) AS supplier_id,
    -                    MAX(sales_items.quantity_purchased) AS quantity_purchased,
    -                    MAX(sales_items.item_cost_price) AS item_cost_price,
    -                    MAX(sales_items.item_unit_price) AS item_unit_price,
    -                    MAX(sales_items.discount_percent) AS discount_percent,
    -                    sales_items.line AS line,
    -                    MAX(sales_items.serialnumber) AS serialnumber,
    -                    MAX(sales_items.item_location) AS item_location,
    -                    MAX(sales_items.description) AS description,
    -                    MAX(payments.payment_type) AS payment_type,
    -                    MAX(payments.sale_payment_amount) AS sale_payment_amount,
    -                    ' . "
    -                    IFNULL(ROUND($sale_subtotal, $decimals), ROUND($sale_total - IFNULL(SUM(sales_items_taxes.tax), 0), $decimals)) AS subtotal,
    -                    IFNULL(ROUND(SUM(sales_items_taxes.tax), $decimals), 0) AS tax,
    -                    IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total,
    -                    IFNULL(ROUND($sale_cost, $decimals), 0) AS cost,
    -                    IFNULL(ROUND($sale_total - IFNULL(SUM(sales_items_taxes.tax), 0) - $sale_cost, $decimals), ROUND($sale_subtotal - $sale_cost, $decimals)) AS profit
    -                    " . '
    -                FROM ' . $this->db->dbprefix('sales_items') . ' AS sales_items
    -                INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales
    -                    ON sales_items.sale_id = sales.sale_id
    -                INNER JOIN ' . $this->db->dbprefix('items') . ' AS items
    -                    ON sales_items.item_id = items.item_id
    -                LEFT OUTER JOIN ' . $this->db->dbprefix('sales_payments_temp') . ' AS payments
    -                    ON sales_items.sale_id = payments.sale_id
    -                LEFT OUTER JOIN ' . $this->db->dbprefix('suppliers') . ' AS supplier
    -                    ON items.supplier_id = supplier.person_id
    -                LEFT OUTER JOIN ' . $this->db->dbprefix('people') . ' AS customer_p
    -                    ON sales.customer_id = customer_p.person_id
    -                LEFT OUTER JOIN ' . $this->db->dbprefix('customers') . ' AS customer
    -                    ON sales.customer_id = customer.person_id
    -                LEFT OUTER JOIN ' . $this->db->dbprefix('people') . ' AS employee
    -                    ON sales.employee_id = employee.person_id
    -                LEFT OUTER JOIN ' . $this->db->dbprefix('sales_items_taxes_temp') . ' AS sales_items_taxes
    -                    ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line
    -                WHERE sales.sale_status = 0 AND ' . $where . '
    -                GROUP BY sale_id, item_id, line
    -            )'
    -        );
    -
    -        // drop the temporary table to contain memory consumption as it's no longer required
    -        $this->db->query('DROP TEMPORARY TABLE IF EXISTS ' . $this->db->dbprefix('sales_payments_temp'));
    -        $this->db->query('DROP TEMPORARY TABLE IF EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp'));
    -    }
    -
    -    /**
    -     * Retrieves all sales that are in a suspended state
    -     */
    -    public function get_all_suspended($customer_id = NULL)
    -    {
    -        if($customer_id == -1)
    -        {
    -            $query = $this->db->query('select sale_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from '
    -                . $this->db->dbprefix('sales') . ' where sale_status = 1 '
    -                . ' union select sale_id, sale_id*-1 as suspended_sale_id, 2 as sale_status, sale_time, dinner_table_id, customer_id, comment from '
    -                . $this->db->dbprefix('sales_suspended'));
    -        }
    -        else
    -        {
    -            $query = $this->db->query('select sale_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from '
    -                . $this->db->dbprefix('sales') . ' where sale_status = 1 and customer_id = ' . $customer_id
    -                . ' union select sale_id, sale_id*-1 as suspended_sale_id, 2 as sale_status, sale_time, dinner_table_id, customer_id, comment from '
    -                . $this->db->dbprefix('sales_suspended') . ' where customer_id = ' . $customer_id);
    -        }
    -
    -        return $query->result_array();
    -
    -    }
    -
    -    /**
    -     * Gets the dinner table for the selected sale
    -     */
    -    public function get_dinner_table($sale_id)
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        return $this->db->get()->row()->dinner_table_id;
    -    }
    -
    -    /**
    -     * Gets the quote_number for the selected sale
    -     */
    -    public function get_quote_number($sale_id)
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        $row = $this->db->get()->row();
    -
    -        if($row != NULL)
    -        {
    -            return $row->quote_number;
    -        }
    -        else
    -        {
    -            return NULL;
    -        }
    -    }
    -
    -    /**
    -     * Gets the quote_number for the selected sale
    -     */
    -    public function get_comment($sale_id)
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('sale_id', $sale_id);
    -
    -        $row = $this->db->get()->row();
    -
    -        if($row != NULL)
    -        {
    -            return $row->comment;
    -        }
    -        else
    -        {
    -            return NULL;
    -        }
    -    }
    -
    -    /**
    -     * Gets total of suspended invoices rows
    -     */
    -    public function get_suspended_invoice_count()
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('invoice_number IS NOT NULL');
    -        $this->db->where('sale_status', '1');
    -
    -        return $this->db->count_all_results();
    -    }
    -
    -    /**
    -     * Removes a selected sale from the sales table.
    -     * This function should only be called for suspended sales that are being restored to the current cart
    -     */
    -    public function delete_suspended_sale($sale_id)
    -    {
    -        //Run these queries as a transaction, we want to make sure we do all or nothing
    -        $this->db->trans_start();
    -
    -        $dinner_table = $this->get_dinner_table($sale_id);
    -        $dinner_table_data = array(
    -            'status' => 0
    -        );
    -
    -        $this->db->where('dinner_table_id',$dinner_table);
    -        $this->db->update('dinner_tables', $dinner_table_data);
    -
    -        $this->db->delete('sales_payments', array('sale_id' => $sale_id));
    -        $this->db->delete('sales_items_taxes', array('sale_id' => $sale_id));
    -        $this->db->delete('sales_items', array('sale_id' => $sale_id));
    -        $this->db->delete('sales_taxes', array('sale_id' => $sale_id));
    -        $this->db->delete('sales', array('sale_id' => $sale_id));
    -
    -        $this->db->trans_complete();
    -
    -        return $this->db->trans_status();
    -    }
    -
    -    /**
    -     * Gets suspended sale info
    -     */
    -    public function get_suspended_sale_info($sale_id)
    -    {
    -        $this->db->from('sales');
    -        $this->db->where('sale_id', $sale_id);
    -        $this->db->join('people', 'people.person_id = sales_suspended.customer_id', 'LEFT');
    -
    -        return $this->db->get();
    -    }
    -}
    -?>
    -
    + /** + * Save the sale information after the sales is complete but before the final document is printed + * The sales_taxes variable needs to be initialized to an empty array before calling + */ + public function save(&$sale_status, &$items, $customer_id, $employee_id, $comment, $invoice_number, $quote_number, $payments, $dinner_table, &$sales_taxes, $sale_id = FALSE) + { + $tax_decimals = $this->config->item('tax_decimals'); + + if(count($items) == 0) + { + return -1; + } + + if($sale_status == '1') //suspend sales + { + if($dinner_table > 2) //not delivery or take away + { + $table_status = 1; + } + else + { + $table_status = 0; + } + } + else + { + $table_status = 0; + } + + $sales_data = array( + 'sale_time' => date('Y-m-d H:i:s'), + 'customer_id' => $this->Customer->exists($customer_id) ? $customer_id : null, + 'employee_id' => $employee_id, + 'comment' => $comment, + 'invoice_number' => $invoice_number, + 'quote_number' => $quote_number, + 'dinner_table_id'=> $dinner_table, + 'sale_status' => $sale_status + ); + + // Run these queries as a transaction, we want to make sure we do all or nothing + $this->db->trans_start(); + + $this->db->insert('sales', $sales_data); + $sale_id = $this->db->insert_id(); + $total_amount = 0; + $total_amount_used = 0; + foreach($payments as $payment_id=>$payment) + { + if( substr( $payment['payment_type'], 0, strlen( $this->lang->line('sales_giftcard') ) ) == $this->lang->line('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'] ); + } + + if( substr( $payment['payment_type'], 0, strlen( $this->lang->line('sales_rewards') ) ) == $this->lang->line('sales_rewards') ) + { + + $cur_rewards_value = $this->Customer->get_info($customer_id)->points; + $this->Customer->update_reward_points_value($customer_id, $cur_rewards_value - $payment['payment_amount'] ); + $total_amount_used = floatval($total_amount_used) + floatval($payment['payment_amount']); + } + + $sales_payments_data = array( + 'sale_id' => $sale_id, + 'payment_type' => $payment['payment_type'], + 'payment_amount' => $payment['payment_amount'] + ); + $this->db->insert('sales_payments', $sales_payments_data); + $total_amount = floatval($total_amount) + floatval($payment['payment_amount']); + } + + if(!empty($customer_id) && $this->config->item('customer_reward_enable') == TRUE) + { + $package_id = $this->Customer->get_info($customer_id)->package_id; + + if(!empty($package_id)) + { + $points_percent = $this->Customer_rewards->get_points_percent($package_id); + $points = $this->Customer->get_info($customer_id)->points; + $points = ($points==NULL ? 0 : $points); + $points_percent = ($points_percent==NULL ? 0 : $points_percent); + $total_amount_earned = ($total_amount*$points_percent/100); + $points = $points + $total_amount_earned; + $this->Customer->update_reward_points_value($customer_id, $points); + $rewards_data = array('sale_id'=>$sale_id, 'earned'=>$total_amount_earned, 'used'=>$total_amount_used); + $this->Rewards->save($rewards_data); + } + } + + $customer = $this->Customer->get_info($customer_id); + + $sales_taxes = array(); + + foreach($items as $line=>$item) + { + $cur_item_info = $this->Item->get_info($item['item_id']); + + $sales_items_data = array( + 'sale_id' => $sale_id, + 'item_id' => $item['item_id'], + 'line' => $item['line'], + 'description' => character_limiter($item['description'], 30), + 'serialnumber' => character_limiter($item['serialnumber'], 30), + 'quantity_purchased'=> $item['quantity'], + 'discount_percent' => $item['discount'], + 'item_cost_price' => $cur_item_info->cost_price, + 'item_unit_price' => $item['price'], + 'item_location' => $item['item_location'], + 'print_option' => $item['print_option'] + ); + + $this->db->insert('sales_items', $sales_items_data); + + if($cur_item_info->stock_type === '0' && $sale_status === '0') + { + // Update stock quantity if item type is a standard stock item and the sale is a standard sale + $item_quantity = $this->Item_quantity->get_item_quantity($item['item_id'], $item['item_location']); + $this->Item_quantity->save(array('quantity' => $item_quantity->quantity - $item['quantity'], + 'item_id' => $item['item_id'], + 'location_id' => $item['item_location']), $item['item_id'], $item['item_location']); + + // if an items was deleted but later returned it's restored with this rule + + if($item['quantity'] < 0) + { + $this->Item->undelete($item['item_id']); + } + + // Inventory Count Details + $sale_remarks = 'POS '.$sale_id; + $inv_data = array( + 'trans_date' => date('Y-m-d H:i:s'), + 'trans_items' => $item['item_id'], + 'trans_user' => $employee_id, + 'trans_location' => $item['item_location'], + 'trans_comment' => $sale_remarks, + 'trans_inventory' => -$item['quantity'] + ); + $this->Inventory->insert($inv_data); + } + + // Calculate taxes and save the tax information for the sale. Return the result for printing + + if($customer_id == -1 || $customer->taxable) + { + if($this->config->item('tax_included')) + { + $tax_type = Tax_lib::TAX_TYPE_VAT; + } + else + { + $tax_type = Tax_lib::TAX_TYPE_SALES; + } + $rounding_code = Rounding_code::HALF_UP; // half adjust + $tax_group_sequence = 0; + $item_total = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], TRUE); + $tax_basis = $item_total; + $item_tax_amount = 0; + + foreach($this->Item_taxes->get_info($item['item_id']) as $row) + { + + $sales_items_taxes = array( + 'sale_id' => $sale_id, + 'item_id' => $item['item_id'], + 'line' => $item['line'], + 'name' => character_limiter($row['name'], 255), + 'percent' => $row['percent'], + 'tax_type' => $tax_type, + 'rounding_code' => $rounding_code, + 'cascade_tax' => 0, + 'cascade_sequence' => 0, + 'item_tax_amount' => 0 + ); + + // This computes tax for each line item and adds it to the tax type total + $tax_group = (float)$row['percent'] . '% ' . $row['name']; + $tax_basis = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], TRUE); + + if($this->config->item('tax_included')) + { + $tax_type = Tax_lib::TAX_TYPE_VAT; + $item_tax_amount = $this->sale_lib->get_item_tax($item['quantity'], $item['price'], $item['discount'],$row['percent']); + } + elseif($this->config->item('customer_sales_tax_support') == '0') + { + $tax_type = Tax_lib::TAX_TYPE_SALES; + $item_tax_amount = $this->tax_lib->get_sales_tax_for_amount($tax_basis, $row['percent'], '0', $tax_decimals); + } + else + { + $tax_type = Tax_lib::TAX_TYPE_SALES; + } + + $sales_items_taxes['item_tax_amount'] = $item_tax_amount; + if($item_tax_amount != 0) + { + $this->db->insert('sales_items_taxes', $sales_items_taxes); + $this->tax_lib->update_sales_taxes($sales_taxes, $tax_type, $tax_group, $row['percent'], $tax_basis, $item_tax_amount, $tax_group_sequence, $rounding_code, $sale_id, $row['name'], ''); + $tax_group_sequence += 1; + } + + } + + if($this->config->item('customer_sales_tax_support') == '1') + { + $this->save_sales_item_tax($customer, $sale_id, $item, $item_total, $sales_taxes, $sequence, $cur_item_info->tax_category_id); + } + } + } + + if($customer_id == -1 || $customer->taxable) + { + $this->tax_lib->round_sales_taxes($sales_taxes); + $this->save_sales_tax($sales_taxes); + } + + $dinner_table_data = array( + 'status' => $table_status + ); + + $this->db->where('dinner_table_id',$dinner_table); + $this->db->update('dinner_tables', $dinner_table_data); + + $this->db->trans_complete(); + + if($this->db->trans_status() === FALSE) + { + return -1; + } + + return $sale_id; + } + + /** + * Apply customer sales tax if the customer sales tax is enabledl + * The original tax is still supported if the user configures it, + * but it won't make sense unless it's used exclusively for the purpose + * of VAT tax which becomes a price component. VAT taxes must still be reported + * as a separate tax entry on the invoice. + */ + public function save_sales_item_tax(&$customer, &$sale_id, &$item, $tax_basis, &$sales_taxes, &$sequence, $tax_category_id) + { + // if customer sales tax is enabled then update sales_items_taxes with the + if($this->config->item('customer_sales_tax_support') == '1') + { + $register_mode = $this->config->item('default_register_mode'); + $tax_details = $this->tax_lib->apply_sales_tax($item, $customer->city, $customer->state, $customer->sales_tax_code, $register_mode, $sale_id, $sales_taxes); + + $sales_items_taxes = array( + 'sale_id' => $sale_id, + 'item_id' => $item['item_id'], + 'line' => $item['line'], + 'name' => $tax_details['tax_name'], + 'percent' => $tax_details['tax_rate'], + 'tax_type' => Tax_lib::TAX_TYPE_SALES, + 'rounding_code' => $tax_details['rounding_code'], + 'cascade_tax' => 0, + 'cascade_sequence' => 0, + 'item_tax_amount' => $tax_details['item_tax_amount'] + ); + + $this->db->insert('sales_items_taxes', $sales_items_taxes); + } + } + + /** + * Saves sale tax + */ + public function save_sales_tax(&$sales_taxes) + { + foreach($sales_taxes as $line=>$sales_tax) + { + $this->db->insert('sales_taxes', $sales_tax); + } + } + + /** + * Deletes list of sales + */ + public function delete_list($sale_ids, $employee_id, $update_inventory = TRUE) + { + $result = TRUE; + + foreach($sale_ids as $sale_id) + { + $result &= $this->delete($sale_id, $employee_id, $update_inventory); + } + + return $result; + } + + /** + * Delete sale + */ + public function delete($sale_id, $employee_id, $update_inventory = TRUE) + { + // start a transaction to assure data integrity + $this->db->trans_start(); + + // first delete all payments + $this->db->delete('sales_payments', array('sale_id' => $sale_id)); + // then delete all taxes on items + $this->db->delete('sales_items_taxes', array('sale_id' => $sale_id)); + + if($update_inventory) + { + // defect, not all item deletions will be undone?? + // get array with all the items involved in the sale to update the inventory tracking + $items = $this->get_sale_items($sale_id)->result_array(); + foreach($items as $item) + { + $cur_item_info = $this->Item->get_info($item['item_id']); + + if($cur_item_info->stock_type === '0') { + // create query to update inventory tracking + $inv_data = array( + 'trans_date' => date('Y-m-d H:i:s'), + 'trans_items' => $item['item_id'], + 'trans_user' => $employee_id, + 'trans_comment' => 'Deleting sale ' . $sale_id, + 'trans_location' => $item['item_location'], + 'trans_inventory' => $item['quantity_purchased'] + ); + // update inventory + $this->Inventory->insert($inv_data); + + // update quantities + $this->Item_quantity->change_quantity($item['item_id'], $item['item_location'], $item['quantity_purchased']); + } + } + } + + // delete all items + $this->db->delete('sales_items', array('sale_id' => $sale_id)); + // delete sale itself + $this->db->delete('sales', array('sale_id' => $sale_id)); + + // execute transaction + $this->db->trans_complete(); + + return $this->db->trans_status(); + } + + /** + * Gets sale item + */ + public function get_sale_items($sale_id) + { + $this->db->from('sales_items'); + $this->db->where('sale_id', $sale_id); + + return $this->db->get(); + } + + /** + * Used by the invoice and receipt programs + */ + public function get_sale_items_ordered($sale_id) + { + $this->db->select(' + sale_id, + sales_items.item_id, + sales_items.description, + serialnumber, + line, + quantity_purchased, + item_cost_price, + item_unit_price, + discount_percent, + item_location, + print_option, + items.name as name, + category, + item_type, + stock_type'); + $this->db->from('sales_items as sales_items'); + $this->db->join('items as items', 'sales_items.item_id = items.item_id'); + $this->db->where('sale_id', $sale_id); + + // Entry sequence (this will render kits in the expected sequence) + if($this->config->item('line_sequence') == '0') + { + $this->db->order_by('line', 'asc'); + } + // Group by Stock Type (nonstock first - type 1, stock next - type 0) + elseif($this->config->item('line_sequence') == '1') + { + $this->db->order_by('stock_type', 'desc'); + $this->db->order_by('sales_items.description', 'asc'); + $this->db->order_by('items.name', 'asc'); + } + // Group by Item Category + elseif($this->config->item('line_sequence') == '2') + { + $this->db->order_by('category', 'asc'); + $this->db->order_by('sales_items.description', 'asc'); + $this->db->order_by('items.name', 'asc'); + } + // Group by entry sequence in descending sequence (the Standard) + else + { + $this->db->order_by('line', 'desc'); + } + + return $this->db->get(); + } + + /** + * Gets sale payments + */ + public function get_sale_payments($sale_id) + { + $this->db->from('sales_payments'); + $this->db->where('sale_id', $sale_id); + + return $this->db->get(); + } + + /** + * Gets sale payment options + */ + public function get_payment_options($giftcard = TRUE, $reward_points = FALSE) + { + $payments = array(); + + if($this->config->item('payment_options_order') == 'debitcreditcash') + { + $payments[$this->lang->line('sales_debit')] = $this->lang->line('sales_debit'); + $payments[$this->lang->line('sales_credit')] = $this->lang->line('sales_credit'); + $payments[$this->lang->line('sales_cash')] = $this->lang->line('sales_cash'); + } + elseif($this->config->item('payment_options_order') == 'debitcashcredit') + { + $payments[$this->lang->line('sales_debit')] = $this->lang->line('sales_debit'); + $payments[$this->lang->line('sales_cash')] = $this->lang->line('sales_cash'); + $payments[$this->lang->line('sales_credit')] = $this->lang->line('sales_credit'); + } + else // default: if($this->config->item('payment_options_order') == 'cashdebitcredit') + { + $payments[$this->lang->line('sales_cash')] = $this->lang->line('sales_cash'); + $payments[$this->lang->line('sales_debit')] = $this->lang->line('sales_debit'); + $payments[$this->lang->line('sales_credit')] = $this->lang->line('sales_credit'); + } + + $payments[$this->lang->line('sales_check')] = $this->lang->line('sales_check'); + + if($giftcard) + { + $payments[$this->lang->line('sales_giftcard')] = $this->lang->line('sales_giftcard'); + } + + if($reward_points) + { + $payments[$this->lang->line('sales_rewards')] = $this->lang->line('sales_rewards'); + } + + return $payments; + } + + /** + * Gets sale customer name + */ + public function get_customer($sale_id) + { + $this->db->from('sales'); + $this->db->where('sale_id', $sale_id); + + return $this->Customer->get_info($this->db->get()->row()->customer_id); + } + + /** + * Gets sale employee name + */ + public function get_employee($sale_id) + { + $this->db->from('sales'); + $this->db->where('sale_id', $sale_id); + + return $this->Employee->get_info($this->db->get()->row()->employee_id); + } + + /** + * Checks if quote number exists + */ + // TODO change to use new quote_number field + public function check_quote_number_exists($quote_number, $sale_id = '') + { + $this->db->from('sales'); + $this->db->where('quote_number', $quote_number); + if(!empty($sale_id)) + { + $this->db->where('sale_id !=', $sale_id); + } + + return ($this->db->get()->num_rows() == 1); + } + + /** + * Checks if invoice number exists + */ + public function check_invoice_number_exists($invoice_number, $sale_id = '') + { + $this->db->from('sales'); + $this->db->where('invoice_number', $invoice_number); + if(!empty($sale_id)) + { + $this->db->where('sale_id !=', $sale_id); + } + + return ($this->db->get()->num_rows() == 1); + } + + /** + * Gets Giftcard value + */ + public 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; + } + + /** + * Creates sales temporary dimentional table + * We create a temp table that allows us to do easy report/sales queries + */ + public function create_temp_table(array $inputs) + { + if(empty($inputs['sale_id'])) + { + if(empty($this->config->item('date_or_time_format'))) + { + $where = 'DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); + } + else + { + $where = 'sales.sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date'])); + } + } + else + { + $where = 'sales.sale_id = ' . $this->db->escape($inputs['sale_id']); + } + + $decimals = totals_decimals(); + + $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)'; + $sale_cost = 'ROUND(IFNULL(SUM(sales_items.item_cost_price * sales_items.quantity_purchased), 0), ' . $decimals . ')'; + $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')'; + + if($this->config->item('tax_included')) + { + $sale_total = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')'; + $sale_subtotal = $sale_total . ' - ' . $tax; + } + else + { + $sale_subtotal = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')'; + $sale_total = $sale_subtotal . ' + ' . $tax; + } + + // create a temporary table to contain all the sum of taxes per sale item + $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') . + ' (INDEX(sale_id), INDEX(item_id)) + ( + SELECT sales_items_taxes.sale_id AS sale_id, + sales_items_taxes.item_id AS item_id, + sales_items_taxes.line AS line, + SUM(sales_items_taxes.item_tax_amount) as tax + FROM ' . $this->db->dbprefix('sales_items_taxes') . ' AS sales_items_taxes + INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales + ON sales.sale_id = sales_items_taxes.sale_id + INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items + ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.line = sales_items_taxes.line + WHERE sales.sale_status = 0 AND ' . $where . ' + GROUP BY sale_id, item_id, line + )' + ); + + // create a temporary table to contain all the payment types and amount + $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_payments_temp') . + ' (PRIMARY KEY(sale_id), INDEX(sale_id)) + ( + SELECT payments.sale_id AS sale_id, + IFNULL(SUM(payments.payment_amount), 0) AS sale_payment_amount, + GROUP_CONCAT(CONCAT(payments.payment_type, " ", payments.payment_amount) SEPARATOR ", ") AS payment_type + FROM ' . $this->db->dbprefix('sales_payments') . ' AS payments + INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales + ON sales.sale_id = payments.sale_id + WHERE sales.sale_status = 0 AND ' . $where . ' + GROUP BY payments.sale_id + )' + ); + + $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_temp') . + ' (INDEX(sale_date), INDEX(sale_time), INDEX(sale_id)) + ( + SELECT + MAX(DATE(sales.sale_time)) AS sale_date, + MAX(sales.sale_time) AS sale_time, + sales.sale_id AS sale_id, + MAX(sales.comment) AS comment, + MAX(sales.invoice_number) AS invoice_number, + MAX(sales.quote_number) AS quote_number, + MAX(sales.customer_id) AS customer_id, + MAX(CONCAT(customer_p.first_name, " ", customer_p.last_name)) AS customer_name, + MAX(customer_p.first_name) AS customer_first_name, + MAX(customer_p.last_name) AS customer_last_name, + MAX(customer_p.email) AS customer_email, + MAX(customer_p.comments) AS customer_comments, + MAX(customer.company_name) AS customer_company_name, + MAX(sales.employee_id) AS employee_id, + MAX(CONCAT(employee.first_name, " ", employee.last_name)) AS employee_name, + items.item_id AS item_id, + MAX(items.name) AS name, + MAX(items.category) AS category, + MAX(items.supplier_id) AS supplier_id, + MAX(sales_items.quantity_purchased) AS quantity_purchased, + MAX(sales_items.item_cost_price) AS item_cost_price, + MAX(sales_items.item_unit_price) AS item_unit_price, + MAX(sales_items.discount_percent) AS discount_percent, + sales_items.line AS line, + MAX(sales_items.serialnumber) AS serialnumber, + MAX(sales_items.item_location) AS item_location, + MAX(sales_items.description) AS description, + MAX(payments.payment_type) AS payment_type, + MAX(payments.sale_payment_amount) AS sale_payment_amount, + ' . " + IFNULL($sale_subtotal, $sale_total) AS subtotal, + $tax AS tax, + IFNULL($sale_total, $sale_subtotal) AS total, + $sale_cost AS cost, + (IFNULL($sale_subtotal, $sale_total) - $sale_cost) AS profit + " . ' + FROM ' . $this->db->dbprefix('sales_items') . ' AS sales_items + INNER JOIN ' . $this->db->dbprefix('sales') . ' AS sales + ON sales_items.sale_id = sales.sale_id + INNER JOIN ' . $this->db->dbprefix('items') . ' AS items + ON sales_items.item_id = items.item_id + LEFT OUTER JOIN ' . $this->db->dbprefix('sales_payments_temp') . ' AS payments + ON sales_items.sale_id = payments.sale_id + LEFT OUTER JOIN ' . $this->db->dbprefix('suppliers') . ' AS supplier + ON items.supplier_id = supplier.person_id + LEFT OUTER JOIN ' . $this->db->dbprefix('people') . ' AS customer_p + ON sales.customer_id = customer_p.person_id + LEFT OUTER JOIN ' . $this->db->dbprefix('customers') . ' AS customer + ON sales.customer_id = customer.person_id + LEFT OUTER JOIN ' . $this->db->dbprefix('people') . ' AS employee + ON sales.employee_id = employee.person_id + LEFT OUTER JOIN ' . $this->db->dbprefix('sales_items_taxes_temp') . ' AS sales_items_taxes + ON sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line + WHERE sales.sale_status = 0 AND ' . $where . ' + GROUP BY sale_id, item_id, line + )' + ); + + // drop the temporary table to contain memory consumption as it's no longer required + $this->db->query('DROP TEMPORARY TABLE IF EXISTS ' . $this->db->dbprefix('sales_payments_temp')); + $this->db->query('DROP TEMPORARY TABLE IF EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp')); + } + + /** + * Retrieves all sales that are in a suspended state + */ + public function get_all_suspended($customer_id = NULL) + { + if($customer_id == -1) + { + $query = $this->db->query('select sale_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from ' + . $this->db->dbprefix('sales') . ' where sale_status = 1 ' + . ' union select sale_id, sale_id*-1 as suspended_sale_id, 2 as sale_status, sale_time, dinner_table_id, customer_id, comment from ' + . $this->db->dbprefix('sales_suspended')); + } + else + { + $query = $this->db->query('select sale_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, comment from ' + . $this->db->dbprefix('sales') . ' where sale_status = 1 and customer_id = ' . $customer_id + . ' union select sale_id, sale_id*-1 as suspended_sale_id, 2 as sale_status, sale_time, dinner_table_id, customer_id, comment from ' + . $this->db->dbprefix('sales_suspended') . ' where customer_id = ' . $customer_id); + } + + return $query->result_array(); + + } + + /** + * Gets the dinner table for the selected sale + */ + public function get_dinner_table($sale_id) + { + $this->db->from('sales'); + $this->db->where('sale_id', $sale_id); + + return $this->db->get()->row()->dinner_table_id; + } + + /** + * Gets the quote_number for the selected sale + */ + public function get_quote_number($sale_id) + { + $this->db->from('sales'); + $this->db->where('sale_id', $sale_id); + + $row = $this->db->get()->row(); + + if($row != NULL) + { + return $row->quote_number; + } + else + { + return NULL; + } + } + + /** + * Gets the quote_number for the selected sale + */ + public function get_comment($sale_id) + { + $this->db->from('sales'); + $this->db->where('sale_id', $sale_id); + + $row = $this->db->get()->row(); + + if($row != NULL) + { + return $row->comment; + } + else + { + return NULL; + } + } + + /** + * Gets total of suspended invoices rows + */ + public function get_suspended_invoice_count() + { + $this->db->from('sales'); + $this->db->where('invoice_number IS NOT NULL'); + $this->db->where('sale_status', '1'); + + return $this->db->count_all_results(); + } + + /** + * Removes a selected sale from the sales table. + * This function should only be called for suspended sales that are being restored to the current cart + */ + public function delete_suspended_sale($sale_id) + { + //Run these queries as a transaction, we want to make sure we do all or nothing + $this->db->trans_start(); + + $dinner_table = $this->get_dinner_table($sale_id); + $dinner_table_data = array( + 'status' => 0 + ); + + $this->db->where('dinner_table_id',$dinner_table); + $this->db->update('dinner_tables', $dinner_table_data); + + $this->db->delete('sales_payments', array('sale_id' => $sale_id)); + $this->db->delete('sales_items_taxes', array('sale_id' => $sale_id)); + $this->db->delete('sales_items', array('sale_id' => $sale_id)); + $this->db->delete('sales_taxes', array('sale_id' => $sale_id)); + $this->db->delete('sales', array('sale_id' => $sale_id)); + + $this->db->trans_complete(); + + return $this->db->trans_status(); + } + + /** + * Gets suspended sale info + */ + public function get_suspended_sale_info($sale_id) + { + $this->db->from('sales'); + $this->db->where('sale_id', $sale_id); + $this->db->join('people', 'people.person_id = sales_suspended.customer_id', 'LEFT'); + + return $this->db->get(); + } +} +?> + - + diff --git a/docs/source-class-Sale_lib.html b/docs/source-class-Sale_lib.html index fd2ec940c..e67fe3d51 100644 --- a/docs/source-class-Sale_lib.html +++ b/docs/source-class-Sale_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
       1:    2:    3:    4:    5:    6:    7:    8:    9:   10:   11:   12:   13:   14:   15:   16:   17:   18:   19:   20:   21:   22:   23:   24:   25:   26:   27:   28:   29:   30:   31:   32:   33:   34:   35:   36:   37:   38:   39:   40:   41:   42:   43:   44:   45:   46:   47:   48:   49:   50:   51:   52:   53:   54:   55:   56:   57:   58:   59:   60:   61:   62:   63:   64:   65:   66:   67:   68:   69:   70:   71:   72:   73:   74:   75:   76:   77:   78:   79:   80:   81:   82:   83:   84:   85:   86:   87:   88:   89:   90:   91:   92:   93:   94:   95:   96:   97:   98:   99:  100:  101:  102:  103:  104:  105:  106:  107:  108:  109:  110:  111:  112:  113:  114:  115:  116:  117:  118:  119:  120:  121:  122:  123:  124:  125:  126:  127:  128:  129:  130:  131:  132:  133:  134:  135:  136:  137:  138:  139:  140:  141:  142:  143:  144:  145:  146:  147:  148:  149:  150:  151:  152:  153:  154:  155:  156:  157:  158:  159:  160:  161:  162:  163:  164:  165:  166:  167:  168:  169:  170:  171:  172:  173:  174:  175:  176:  177:  178:  179:  180:  181:  182:  183:  184:  185:  186:  187:  188:  189:  190:  191:  192:  193:  194:  195:  196:  197:  198:  199:  200:  201:  202:  203:  204:  205:  206:  207:  208:  209:  210:  211:  212:  213:  214:  215:  216:  217:  218:  219:  220:  221:  222:  223:  224:  225:  226:  227:  228:  229:  230:  231:  232:  233:  234:  235:  236:  237:  238:  239:  240:  241:  242:  243:  244:  245:  246:  247:  248:  249:  250:  251:  252:  253:  254:  255:  256:  257:  258:  259:  260:  261:  262:  263:  264:  265:  266:  267:  268:  269:  270:  271:  272:  273:  274:  275:  276:  277:  278:  279:  280:  281:  282:  283:  284:  285:  286:  287:  288:  289:  290:  291:  292:  293:  294:  295:  296:  297:  298:  299:  300:  301:  302:  303:  304:  305:  306:  307:  308:  309:  310:  311:  312:  313:  314:  315:  316:  317:  318:  319:  320:  321:  322:  323:  324:  325:  326:  327:  328:  329:  330:  331:  332:  333:  334:  335:  336:  337:  338:  339:  340:  341:  342:  343:  344:  345:  346:  347:  348:  349:  350:  351:  352:  353:  354:  355:  356:  357:  358:  359:  360:  361:  362:  363:  364:  365:  366:  367:  368:  369:  370:  371:  372:  373:  374:  375:  376:  377:  378:  379:  380:  381:  382:  383:  384:  385:  386:  387:  388:  389:  390:  391:  392:  393:  394:  395:  396:  397:  398:  399:  400:  401:  402:  403:  404:  405:  406:  407:  408:  409:  410:  411:  412:  413:  414:  415:  416:  417:  418:  419:  420:  421:  422:  423:  424:  425:  426:  427:  428:  429:  430:  431:  432:  433:  434:  435:  436:  437:  438:  439:  440:  441:  442:  443:  444:  445:  446:  447:  448:  449:  450:  451:  452:  453:  454:  455:  456:  457:  458:  459:  460:  461:  462:  463:  464:  465:  466:  467:  468:  469:  470:  471:  472:  473:  474:  475:  476:  477:  478:  479:  480:  481:  482:  483:  484:  485:  486:  487:  488:  489:  490:  491:  492:  493:  494:  495:  496:  497:  498:  499:  500:  501:  502:  503:  504:  505:  506:  507:  508:  509:  510:  511:  512:  513:  514:  515:  516:  517:  518:  519:  520:  521:  522:  523:  524:  525:  526:  527:  528:  529:  530:  531:  532:  533:  534:  535:  536:  537:  538:  539:  540:  541:  542:  543:  544:  545:  546:  547:  548:  549:  550:  551:  552:  553:  554:  555:  556:  557:  558:  559:  560:  561:  562:  563:  564:  565:  566:  567:  568:  569:  570:  571:  572:  573:  574:  575:  576:  577:  578:  579:  580:  581:  582:  583:  584:  585:  586:  587:  588:  589:  590:  591:  592:  593:  594:  595:  596:  597:  598:  599:  600:  601:  602:  603:  604:  605:  606:  607:  608:  609:  610:  611:  612:  613:  614:  615:  616:  617:  618:  619:  620:  621:  622:  623:  624:  625:  626:  627:  628:  629:  630:  631:  632:  633:  634:  635:  636:  637:  638:  639:  640:  641:  642:  643:  644:  645:  646:  647:  648:  649:  650:  651:  652:  653:  654:  655:  656:  657:  658:  659:  660:  661:  662:  663:  664:  665:  666:  667:  668:  669:  670:  671:  672:  673:  674:  675:  676:  677:  678:  679:  680:  681:  682:  683:  684:  685:  686:  687:  688:  689:  690:  691:  692:  693:  694:  695:  696:  697:  698:  699:  700:  701:  702:  703:  704:  705:  706:  707:  708:  709:  710:  711:  712:  713:  714:  715:  716:  717:  718:  719:  720:  721:  722:  723:  724:  725:  726:  727:  728:  729:  730:  731:  732:  733:  734:  735:  736:  737:  738:  739:  740:  741:  742:  743:  744:  745:  746:  747:  748:  749:  750:  751:  752:  753:  754:  755:  756:  757:  758:  759:  760:  761:  762:  763:  764:  765:  766:  767:  768:  769:  770:  771:  772:  773:  774:  775:  776:  777:  778:  779:  780:  781:  782:  783:  784:  785:  786:  787:  788:  789:  790:  791:  792:  793:  794:  795:  796:  797:  798:  799:  800:  801:  802:  803:  804:  805:  806:  807:  808:  809:  810:  811:  812:  813:  814:  815:  816:  817:  818:  819:  820:  821:  822:  823:  824:  825:  826:  827:  828:  829:  830:  831:  832:  833:  834:  835:  836:  837:  838:  839:  840:  841:  842:  843:  844:  845:  846:  847:  848:  849:  850:  851:  852:  853:  854:  855:  856:  857:  858:  859:  860:  861:  862:  863:  864:  865:  866:  867:  868:  869:  870:  871:  872:  873:  874:  875:  876:  877:  878:  879:  880:  881:  882:  883:  884:  885:  886:  887:  888:  889:  890:  891:  892:  893:  894:  895:  896:  897:  898:  899:  900:  901:  902:  903:  904:  905:  906:  907:  908:  909:  910:  911:  912:  913:  914:  915:  916:  917:  918:  919:  920:  921:  922:  923:  924:  925:  926:  927:  928:  929:  930:  931:  932:  933:  934:  935:  936:  937:  938:  939:  940:  941:  942:  943:  944:  945:  946:  947:  948:  949:  950:  951:  952:  953:  954:  955:  956:  957:  958:  959:  960:  961:  962:  963:  964:  965:  966:  967:  968:  969:  970:  971:  972:  973:  974:  975:  976:  977:  978:  979:  980:  981:  982:  983:  984:  985:  986:  987:  988:  989:  990:  991:  992:  993:  994:  995:  996:  997:  998:  999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 1130: 1131: 1132: 1133: 1134: 1135: 1136: 1137: 1138: 1139: 1140: 1141: 1142: 1143: 1144: 1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164: 1165: 1166: 1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174: 1175: 1176: 1177: 1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185: 1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199: 1200: 1201: 1202: 1203: 1204: 1205: 1206: 1207: 1208: 1209: 1210: 1211: 1212: 1213: 1214: 1215: 1216: 1217: 1218: 1219: 1220: 1221: 1222: 1223: 1224: 1225: 1226: 1227: 1228: 1229: 1230: 1231: 1232: 1233: 1234: 1235: 1236: 1237: 1238: 1239: 1240: 1241: 1242: 1243: 1244: 1245: 1246: 1247: 1248: 1249: 1250: 1251: 1252: 1253: 1254: 1255: 1256: 1257: 1258: 1259: 1260: 1261: 1262: 1263: 1264: 1265: 1266: 1267: 
    +
       1:    2:    3:    4:    5:    6:    7:    8:    9:   10:   11:   12:   13:   14:   15:   16:   17:   18:   19:   20:   21:   22:   23:   24:   25:   26:   27:   28:   29:   30:   31:   32:   33:   34:   35:   36:   37:   38:   39:   40:   41:   42:   43:   44:   45:   46:   47:   48:   49:   50:   51:   52:   53:   54:   55:   56:   57:   58:   59:   60:   61:   62:   63:   64:   65:   66:   67:   68:   69:   70:   71:   72:   73:   74:   75:   76:   77:   78:   79:   80:   81:   82:   83:   84:   85:   86:   87:   88:   89:   90:   91:   92:   93:   94:   95:   96:   97:   98:   99:  100:  101:  102:  103:  104:  105:  106:  107:  108:  109:  110:  111:  112:  113:  114:  115:  116:  117:  118:  119:  120:  121:  122:  123:  124:  125:  126:  127:  128:  129:  130:  131:  132:  133:  134:  135:  136:  137:  138:  139:  140:  141:  142:  143:  144:  145:  146:  147:  148:  149:  150:  151:  152:  153:  154:  155:  156:  157:  158:  159:  160:  161:  162:  163:  164:  165:  166:  167:  168:  169:  170:  171:  172:  173:  174:  175:  176:  177:  178:  179:  180:  181:  182:  183:  184:  185:  186:  187:  188:  189:  190:  191:  192:  193:  194:  195:  196:  197:  198:  199:  200:  201:  202:  203:  204:  205:  206:  207:  208:  209:  210:  211:  212:  213:  214:  215:  216:  217:  218:  219:  220:  221:  222:  223:  224:  225:  226:  227:  228:  229:  230:  231:  232:  233:  234:  235:  236:  237:  238:  239:  240:  241:  242:  243:  244:  245:  246:  247:  248:  249:  250:  251:  252:  253:  254:  255:  256:  257:  258:  259:  260:  261:  262:  263:  264:  265:  266:  267:  268:  269:  270:  271:  272:  273:  274:  275:  276:  277:  278:  279:  280:  281:  282:  283:  284:  285:  286:  287:  288:  289:  290:  291:  292:  293:  294:  295:  296:  297:  298:  299:  300:  301:  302:  303:  304:  305:  306:  307:  308:  309:  310:  311:  312:  313:  314:  315:  316:  317:  318:  319:  320:  321:  322:  323:  324:  325:  326:  327:  328:  329:  330:  331:  332:  333:  334:  335:  336:  337:  338:  339:  340:  341:  342:  343:  344:  345:  346:  347:  348:  349:  350:  351:  352:  353:  354:  355:  356:  357:  358:  359:  360:  361:  362:  363:  364:  365:  366:  367:  368:  369:  370:  371:  372:  373:  374:  375:  376:  377:  378:  379:  380:  381:  382:  383:  384:  385:  386:  387:  388:  389:  390:  391:  392:  393:  394:  395:  396:  397:  398:  399:  400:  401:  402:  403:  404:  405:  406:  407:  408:  409:  410:  411:  412:  413:  414:  415:  416:  417:  418:  419:  420:  421:  422:  423:  424:  425:  426:  427:  428:  429:  430:  431:  432:  433:  434:  435:  436:  437:  438:  439:  440:  441:  442:  443:  444:  445:  446:  447:  448:  449:  450:  451:  452:  453:  454:  455:  456:  457:  458:  459:  460:  461:  462:  463:  464:  465:  466:  467:  468:  469:  470:  471:  472:  473:  474:  475:  476:  477:  478:  479:  480:  481:  482:  483:  484:  485:  486:  487:  488:  489:  490:  491:  492:  493:  494:  495:  496:  497:  498:  499:  500:  501:  502:  503:  504:  505:  506:  507:  508:  509:  510:  511:  512:  513:  514:  515:  516:  517:  518:  519:  520:  521:  522:  523:  524:  525:  526:  527:  528:  529:  530:  531:  532:  533:  534:  535:  536:  537:  538:  539:  540:  541:  542:  543:  544:  545:  546:  547:  548:  549:  550:  551:  552:  553:  554:  555:  556:  557:  558:  559:  560:  561:  562:  563:  564:  565:  566:  567:  568:  569:  570:  571:  572:  573:  574:  575:  576:  577:  578:  579:  580:  581:  582:  583:  584:  585:  586:  587:  588:  589:  590:  591:  592:  593:  594:  595:  596:  597:  598:  599:  600:  601:  602:  603:  604:  605:  606:  607:  608:  609:  610:  611:  612:  613:  614:  615:  616:  617:  618:  619:  620:  621:  622:  623:  624:  625:  626:  627:  628:  629:  630:  631:  632:  633:  634:  635:  636:  637:  638:  639:  640:  641:  642:  643:  644:  645:  646:  647:  648:  649:  650:  651:  652:  653:  654:  655:  656:  657:  658:  659:  660:  661:  662:  663:  664:  665:  666:  667:  668:  669:  670:  671:  672:  673:  674:  675:  676:  677:  678:  679:  680:  681:  682:  683:  684:  685:  686:  687:  688:  689:  690:  691:  692:  693:  694:  695:  696:  697:  698:  699:  700:  701:  702:  703:  704:  705:  706:  707:  708:  709:  710:  711:  712:  713:  714:  715:  716:  717:  718:  719:  720:  721:  722:  723:  724:  725:  726:  727:  728:  729:  730:  731:  732:  733:  734:  735:  736:  737:  738:  739:  740:  741:  742:  743:  744:  745:  746:  747:  748:  749:  750:  751:  752:  753:  754:  755:  756:  757:  758:  759:  760:  761:  762:  763:  764:  765:  766:  767:  768:  769:  770:  771:  772:  773:  774:  775:  776:  777:  778:  779:  780:  781:  782:  783:  784:  785:  786:  787:  788:  789:  790:  791:  792:  793:  794:  795:  796:  797:  798:  799:  800:  801:  802:  803:  804:  805:  806:  807:  808:  809:  810:  811:  812:  813:  814:  815:  816:  817:  818:  819:  820:  821:  822:  823:  824:  825:  826:  827:  828:  829:  830:  831:  832:  833:  834:  835:  836:  837:  838:  839:  840:  841:  842:  843:  844:  845:  846:  847:  848:  849:  850:  851:  852:  853:  854:  855:  856:  857:  858:  859:  860:  861:  862:  863:  864:  865:  866:  867:  868:  869:  870:  871:  872:  873:  874:  875:  876:  877:  878:  879:  880:  881:  882:  883:  884:  885:  886:  887:  888:  889:  890:  891:  892:  893:  894:  895:  896:  897:  898:  899:  900:  901:  902:  903:  904:  905:  906:  907:  908:  909:  910:  911:  912:  913:  914:  915:  916:  917:  918:  919:  920:  921:  922:  923:  924:  925:  926:  927:  928:  929:  930:  931:  932:  933:  934:  935:  936:  937:  938:  939:  940:  941:  942:  943:  944:  945:  946:  947:  948:  949:  950:  951:  952:  953:  954:  955:  956:  957:  958:  959:  960:  961:  962:  963:  964:  965:  966:  967:  968:  969:  970:  971:  972:  973:  974:  975:  976:  977:  978:  979:  980:  981:  982:  983:  984:  985:  986:  987:  988:  989:  990:  991:  992:  993:  994:  995:  996:  997:  998:  999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 1014: 1015: 1016: 1017: 1018: 1019: 1020: 1021: 1022: 1023: 1024: 1025: 1026: 1027: 1028: 1029: 1030: 1031: 1032: 1033: 1034: 1035: 1036: 1037: 1038: 1039: 1040: 1041: 1042: 1043: 1044: 1045: 1046: 1047: 1048: 1049: 1050: 1051: 1052: 1053: 1054: 1055: 1056: 1057: 1058: 1059: 1060: 1061: 1062: 1063: 1064: 1065: 1066: 1067: 1068: 1069: 1070: 1071: 1072: 1073: 1074: 1075: 1076: 1077: 1078: 1079: 1080: 1081: 1082: 1083: 1084: 1085: 1086: 1087: 1088: 1089: 1090: 1091: 1092: 1093: 1094: 1095: 1096: 1097: 1098: 1099: 1100: 1101: 1102: 1103: 1104: 1105: 1106: 1107: 1108: 1109: 1110: 1111: 1112: 1113: 1114: 1115: 1116: 1117: 1118: 1119: 1120: 1121: 1122: 1123: 1124: 1125: 1126: 1127: 1128: 1129: 1130: 1131: 1132: 1133: 1134: 1135: 1136: 1137: 1138: 1139: 1140: 1141: 1142: 1143: 1144: 1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152: 1153: 1154: 1155: 1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163: 1164: 1165: 1166: 1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174: 1175: 1176: 1177: 1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185: 1186: 1187: 1188: 1189: 1190: 1191: 1192: 1193: 1194: 1195: 1196: 1197: 1198: 1199: 1200: 1201: 1202: 1203: 1204: 1205: 1206: 1207: 1208: 1209: 1210: 1211: 1212: 1213: 1214: 1215: 1216: 1217: 1218: 1219: 1220: 1221: 1222: 1223: 1224: 1225: 1226: 1227: 1228: 1229: 1230: 1231: 1232: 1233: 1234: 1235: 1236: 1237: 1238: 1239: 1240: 1241: 1242: 1243: 1244: 1245: 1246: 1247: 1248: 1249: 1250: 1251: 1252: 1253: 1254: 1255: 1256: 1257: 1258: 1259: 1260: 1261: 1262: 1263: 1264: 1265: 1266: 1267: 1268: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -538,7 +539,7 @@
     
         }
     
    -    /*
    +    /**
          * Returns 'subtotal', 'total', 'cash_total', 'payment_total', 'amount_due', 'cash_amount_due', 'paid_in_full'
          * 'subtotal', 'discounted_subtotal', 'tax_exclusive_subtotal'
          */
    @@ -569,7 +570,7 @@
                 }
                 else
                 {
    -                $subtotal =bcadd($subtotal, $extended_discounted_amount);
    +                $subtotal = bcadd($subtotal, $extended_discounted_amount);
                 }
             }
     
    @@ -577,7 +578,7 @@
             $totals['total_discount'] = $total_discount;
             $totals['subtotal'] = $subtotal;
     
    -        if ($this->CI->config->item('tax_included'))
    +        if($this->CI->config->item('tax_included'))
             {
                 $totals['total'] = $total;
             }
    @@ -1347,134 +1348,135 @@
     
             return $discounted_extended_amount;
         }
    -    public function get_item_total($quantity, $price, $discount_percentage, $include_discount = FALSE)
    -    {
    -        $total = bcmul($quantity, $price);
    -        if($include_discount)
    -        {
    -            $discount_amount = $this->get_item_discount($quantity, $price, $discount_percentage);
    -
    -            return bcsub($total, $discount_amount);
    -        }
    -
    -        return $total;
    -    }
    -
    -    public function get_extended_amount($quantity, $price, $discount_amount = 0)
    -    {
    -        $extended_amount = bcmul($quantity, $price);
    -        return bcsub($extended_amount, $discount_amount);
    -    }
    -
    -    public function get_item_discount($quantity, $price, $discount_percentage)
    -    {
    -        $total = bcmul($quantity, $price);
    -        $discount_fraction = bcdiv($discount_percentage, 100);
    -
    -        return bcmul($total, $discount_fraction);
    -    }
    -
    -    public function get_item_tax($quantity, $price, $discount_percentage, $tax_percentage)
    -    {
    -        $price = $this->get_item_total($quantity, $price, $discount_percentage, TRUE);
    -        if($this->CI->config->item('tax_included'))
    -        {
    -            $tax_fraction = bcadd(100, $tax_percentage);
    -            $tax_fraction = bcdiv($tax_fraction, 100);
    -            $price_tax_excl = bcdiv($price, $tax_fraction);
    -
    -            return bcsub($price, $price_tax_excl);
    -        }
    -        $tax_fraction = bcdiv($tax_percentage, 100);
    -
    -        return bcmul($price, $tax_fraction);
    -    }
    -
    -    public function calculate_subtotal($include_discount = FALSE, $exclude_tax = FALSE)
    -    {
    -        $subtotal = 0;
    -        foreach($this->get_cart() as $item)
    -        {
    -            if($exclude_tax && $this->CI->config->item('tax_included'))
    -            {
    -                $subtotal = bcadd($subtotal, $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount'], $include_discount));
    -            }
    -            else
    -            {
    -                $subtotal = bcadd($subtotal, $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $include_discount));
    -            }
    -        }
    -
    -        return $subtotal;
    -    }
    -
    -    public function get_total()
    -    {
    -        $total = $this->calculate_subtotal(TRUE);
    -
    -        $cash_rounding = $this->CI->session->userdata('cash_rounding');
    -
    -        foreach($this->get_taxes() as $sales_tax)
    -        {
    -            $total = bcadd($total, $sales_tax['sale_tax_amount']);
    -        }
    -
    -        if($cash_rounding)
    -        {
    -            $rounded_total = $this->check_for_cash_rounding($total);
    -            return $rounded_total;
    -        }
    -        return $total;
    -    }
    -
    -    public function get_empty_tables()
    -    {
    -        return $this->CI->Dinner_table->get_empty_tables();
    -    }
    -
    -    public function check_for_cash_rounding($total)
    -    {
    -        $cash_decimals = $this->CI->config->item('cash_decimals');
    -        $cash_rounding_code = $this->CI->config->item('cash_rounding_code');
    -        $rounded_total = $total;
    -
    -        if($cash_rounding_code == Rounding_code::HALF_UP)
    -        {
    -            $rounded_total = round ( $total, $cash_decimals, PHP_ROUND_HALF_UP);
    -        }
    -        elseif($cash_rounding_code == Rounding_code::HALF_DOWN)
    -        {
    -            $rounded_total = round ( $total, $cash_decimals, PHP_ROUND_HALF_DOWN);
    -        }
    -        elseif($cash_rounding_code == Rounding_code::HALF_EVEN)
    -        {
    -            $rounded_total = round ( $total, $cash_decimals, PHP_ROUND_HALF_EVEN);
    -        }
    -        elseif($cash_rounding_code == Rounding_code::HALF_ODD)
    -        {
    -            $rounded_total = round ( $total, $cash_decimals, PHP_ROUND_HALF_UP);
    -        }
    -        elseif($cash_rounding_code == Rounding_code::ROUND_UP)
    -        {
    -            $fig = (int) str_pad('1', $cash_decimals, '0');
    -            $rounded_total = (ceil($total * $fig) / $fig);
    -        }
    -        elseif($cash_rounding_code == Rounding_code::ROUND_DOWN)
    -        {
    -            $fig = (int) str_pad('1', $cash_decimals, '0');
    -            $rounded_total = (floor($total * $fig) / $fig);
    -        }
    -        elseif($cash_rounding_code == Rounding_code::HALF_FIVE)
    -        {
    -            $rounded_total = round($total / 5) * 5;
    -        }
    -
    -        return $rounded_total;
    -    }
    -}
    -
    -?>
    -
    + + public function get_item_total($quantity, $price, $discount_percentage, $include_discount = FALSE) + { + $total = bcmul($quantity, $price); + if($include_discount) + { + $discount_amount = $this->get_item_discount($quantity, $price, $discount_percentage); + + return bcsub($total, $discount_amount); + } + + return $total; + } + + public function get_extended_amount($quantity, $price, $discount_amount = 0) + { + $extended_amount = bcmul($quantity, $price); + return bcsub($extended_amount, $discount_amount); + } + + public function get_item_discount($quantity, $price, $discount_percentage) + { + $total = bcmul($quantity, $price); + $discount_fraction = bcdiv($discount_percentage, 100); + + return bcmul($total, $discount_fraction); + } + + public function get_item_tax($quantity, $price, $discount_percentage, $tax_percentage) + { + $price = $this->get_item_total($quantity, $price, $discount_percentage, TRUE); + if($this->CI->config->item('tax_included')) + { + $tax_fraction = bcadd(100, $tax_percentage); + $tax_fraction = bcdiv($tax_fraction, 100); + $price_tax_excl = bcdiv($price, $tax_fraction); + + return bcsub($price, $price_tax_excl); + } + $tax_fraction = bcdiv($tax_percentage, 100); + + return bcmul($price, $tax_fraction); + } + + public function calculate_subtotal($include_discount = FALSE, $exclude_tax = FALSE) + { + $subtotal = 0; + foreach($this->get_cart() as $item) + { + if($exclude_tax && $this->CI->config->item('tax_included')) + { + $subtotal = bcadd($subtotal, $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount'], $include_discount)); + } + else + { + $subtotal = bcadd($subtotal, $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $include_discount)); + } + } + + return $subtotal; + } + + public function get_total() + { + $total = $this->calculate_subtotal(TRUE); + + $cash_rounding = $this->CI->session->userdata('cash_rounding'); + + foreach($this->get_taxes() as $sales_tax) + { + $total = bcadd($total, $sales_tax['sale_tax_amount']); + } + + if($cash_rounding) + { + $rounded_total = $this->check_for_cash_rounding($total); + return $rounded_total; + } + return $total; + } + + public function get_empty_tables() + { + return $this->CI->Dinner_table->get_empty_tables(); + } + + public function check_for_cash_rounding($total) + { + $cash_decimals = $this->CI->config->item('cash_decimals'); + $cash_rounding_code = $this->CI->config->item('cash_rounding_code'); + $rounded_total = $total; + + if($cash_rounding_code == Rounding_code::HALF_UP) + { + $rounded_total = round ( $total, $cash_decimals, PHP_ROUND_HALF_UP); + } + elseif($cash_rounding_code == Rounding_code::HALF_DOWN) + { + $rounded_total = round ( $total, $cash_decimals, PHP_ROUND_HALF_DOWN); + } + elseif($cash_rounding_code == Rounding_code::HALF_EVEN) + { + $rounded_total = round ( $total, $cash_decimals, PHP_ROUND_HALF_EVEN); + } + elseif($cash_rounding_code == Rounding_code::HALF_ODD) + { + $rounded_total = round ( $total, $cash_decimals, PHP_ROUND_HALF_UP); + } + elseif($cash_rounding_code == Rounding_code::ROUND_UP) + { + $fig = (int) str_pad('1', $cash_decimals, '0'); + $rounded_total = (ceil($total * $fig) / $fig); + } + elseif($cash_rounding_code == Rounding_code::ROUND_DOWN) + { + $fig = (int) str_pad('1', $cash_decimals, '0'); + $rounded_total = (floor($total * $fig) / $fig); + } + elseif($cash_rounding_code == Rounding_code::HALF_FIVE) + { + $rounded_total = round($total / 5) * 5; + } + + return $rounded_total; + } +} + +?> + - + diff --git a/docs/source-class-Sale_suspended.html b/docs/source-class-Sale_suspended.html index ba53a2e47..4b5b7cfff 100644 --- a/docs/source-class-Sale_suspended.html +++ b/docs/source-class-Sale_suspended.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -446,6 +447,6 @@ - + diff --git a/docs/source-class-Sales.html b/docs/source-class-Sales.html index 52e724493..60f69d251 100644 --- a/docs/source-class-Sales.html +++ b/docs/source-class-Sales.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -1494,6 +1495,6 @@ - + diff --git a/docs/source-class-Secure_Controller.html b/docs/source-class-Secure_Controller.html index c8e0ed3b0..bd27c62b6 100644 --- a/docs/source-class-Secure_Controller.html +++ b/docs/source-class-Secure_Controller.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -324,6 +325,6 @@ - + diff --git a/docs/source-class-Sms_lib.html b/docs/source-class-Sms_lib.html index dbde79646..2ff9f959a 100644 --- a/docs/source-class-Sms_lib.html +++ b/docs/source-class-Sms_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -288,6 +289,6 @@ - + diff --git a/docs/source-class-Specific_customer.html b/docs/source-class-Specific_customer.html index 7b90b157d..06da3a56b 100644 --- a/docs/source-class-Specific_customer.html +++ b/docs/source-class-Specific_customer.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -328,6 +329,6 @@ - + diff --git a/docs/source-class-Specific_discount.html b/docs/source-class-Specific_discount.html index 090d63b1e..2b8795e3b 100644 --- a/docs/source-class-Specific_discount.html +++ b/docs/source-class-Specific_discount.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -326,6 +327,6 @@ - + diff --git a/docs/source-class-Specific_employee.html b/docs/source-class-Specific_employee.html index 43d2c532e..d72de2fd6 100644 --- a/docs/source-class-Specific_employee.html +++ b/docs/source-class-Specific_employee.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -328,6 +329,6 @@ - + diff --git a/docs/source-class-Stock_location.html b/docs/source-class-Stock_location.html index 5d8fd00e6..7251e858a 100644 --- a/docs/source-class-Stock_location.html +++ b/docs/source-class-Stock_location.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -385,6 +386,6 @@ - + diff --git a/docs/source-class-Summary_categories.html b/docs/source-class-Summary_categories.html index fe388e88c..ed0099f03 100644 --- a/docs/source-class-Summary_categories.html +++ b/docs/source-class-Summary_categories.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -258,6 +259,6 @@ - + diff --git a/docs/source-class-Summary_customers.html b/docs/source-class-Summary_customers.html index 5fdca6e82..559ce2245 100644 --- a/docs/source-class-Summary_customers.html +++ b/docs/source-class-Summary_customers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -258,6 +259,6 @@ - + diff --git a/docs/source-class-Summary_discounts.html b/docs/source-class-Summary_discounts.html index 7b13dd8d4..5394fee12 100644 --- a/docs/source-class-Summary_discounts.html +++ b/docs/source-class-Summary_discounts.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -246,6 +247,6 @@ - + diff --git a/docs/source-class-Summary_employees.html b/docs/source-class-Summary_employees.html index b497333d8..78f14fd04 100644 --- a/docs/source-class-Summary_employees.html +++ b/docs/source-class-Summary_employees.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -258,6 +259,6 @@ - + diff --git a/docs/source-class-Summary_items.html b/docs/source-class-Summary_items.html index 17a8e3eaa..57e8d03ba 100644 --- a/docs/source-class-Summary_items.html +++ b/docs/source-class-Summary_items.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -258,6 +259,6 @@ - + diff --git a/docs/source-class-Summary_payments.html b/docs/source-class-Summary_payments.html index 18fbc7763..095e5b9cd 100644 --- a/docs/source-class-Summary_payments.html +++ b/docs/source-class-Summary_payments.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -278,6 +279,6 @@ - + diff --git a/docs/source-class-Summary_report.html b/docs/source-class-Summary_report.html index 9e179408f..32bba1623 100644 --- a/docs/source-class-Summary_report.html +++ b/docs/source-class-Summary_report.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,16 +208,16 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
     
     require_once("Report.php");
     
     abstract class Summary_report extends Report
     {
    -    /*
    -    Private interface
    -    */
    +    /**
    +     * Private interface
    +     */
     
         private function _common_select(array $inputs)
         {
    @@ -231,22 +232,22 @@
                 $where .= 'sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date']));
             }
     
    -        $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)';
    +        $decimals = totals_decimals();
     
    -        if($this->config->item('tax_included'))
    -        {
    -            $sale_total = 'SUM(' . $sale_price . ')';
    -            $sale_subtotal = 'SUM(' . $sale_price . ' - sales_items_taxes.tax)';
    -        }
    -        else
    -        {
    -            $sale_total = 'SUM(' . $sale_price . ' + sales_items_taxes.tax)';
    -            $sale_subtotal = 'SUM(' . $sale_price . ')';
    -        }
    -
    -        $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)';
    -
    -        $decimals = totals_decimals();
    +        $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)';
    +        $sale_cost = 'ROUND(IFNULL(SUM(sales_items.item_cost_price * sales_items.quantity_purchased), 0), ' . $decimals . ')';
    +        $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')';
    +
    +        if($this->config->item('tax_included'))
    +        {
    +            $sale_total = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')';
    +            $sale_subtotal = $sale_total . ' - ' . $tax;
    +        }
    +        else
    +        {
    +            $sale_subtotal = 'ROUND(SUM(' . $sale_price . '),' . $decimals . ')';
    +            $sale_total = $sale_subtotal . ' + ' . $tax;
    +        }
     
             // create a temporary table to contain all the sum of taxes per sale item
             $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') .
    @@ -267,11 +268,11 @@
             );
     
             $this->db->select("
    -                IFNULL(ROUND($sale_subtotal, $decimals), ROUND($sale_total - IFNULL(SUM(sales_items_taxes.tax), 0), $decimals)) AS subtotal,
    -                IFNULL(ROUND(SUM(sales_items_taxes.tax), $decimals), 0) AS tax,
    -                IFNULL(ROUND($sale_total, $decimals), ROUND($sale_subtotal, $decimals)) AS total,
    -                IFNULL(ROUND($sale_cost, $decimals), 0) AS cost,
    -                IFNULL(ROUND($sale_total - IFNULL(SUM(sales_items_taxes.tax), 0) - $sale_cost, $decimals), ROUND($sale_subtotal - $sale_cost, $decimals)) AS profit
    +                IFNULL($sale_subtotal, $sale_total) AS subtotal,
    +                $tax AS tax,
    +                IFNULL($sale_total, $sale_subtotal) AS total,
    +                $sale_cost AS cost,
    +                (IFNULL($sale_subtotal, $sale_total) - $sale_cost) AS profit
             ");
         }
     
    @@ -310,56 +311,52 @@
             }
         }
     
    -    /*
    -
    -    Protected class interface implemented by derived classes
    -
    -    */
    +    /**
    +     * Protected class interface implemented by derived classes
    +     */
    +
    +    abstract protected function _get_data_columns();
     
    -    abstract protected function _get_data_columns();
    -
    -    protected function _select(array $inputs)   { $this->_common_select($inputs); }
    -    protected function _from()                  { $this->_common_from(); }
    -    protected function _where(array $inputs)    { $this->_common_where($inputs); }
    -    protected function _group_order()           {}
    -
    -    /*
    -
    -    Public interface implementing the base abstract class, in general it should not be extended unless there is a valid reason
    -
    -    */
    -
    -    public function getDataColumns()
    -    {
    -        return $this->_get_data_columns();
    -    }
    +    protected function _select(array $inputs)   { $this->_common_select($inputs); }
    +    protected function _from()                  { $this->_common_from(); }
    +    protected function _where(array $inputs)    { $this->_common_where($inputs); }
    +    protected function _group_order()           {}
    +
    +    /**
    +     * Public interface implementing the base abstract class, in general it should not be extended unless there is a valid reason
    +    */
    +
    +    public function getDataColumns()
    +    {
    +        return $this->_get_data_columns();
    +    }
    +
    +    public function getData(array $inputs)
    +    {
    +        $this->_select($inputs);
     
    -    public function getData(array $inputs)
    -    {
    -        $this->_select($inputs);
    +        $this->_from();
    +
    +        $this->_where($inputs);
     
    -        $this->_from();
    +        $this->_group_order();
     
    -        $this->_where($inputs);
    -
    -        $this->_group_order();
    -
    -        return $this->db->get()->result_array();
    -    }
    +        return $this->db->get()->result_array();
    +    }
    +
    +    public function getSummaryData(array $inputs)
    +    {
    +        $this->_common_select($inputs);
     
    -    public function getSummaryData(array $inputs)
    -    {
    -        $this->_common_select($inputs);
    +        $this->_common_from();
    +
    +        $this->_where($inputs);
     
    -        $this->_common_from();
    -
    -        $this->_where($inputs);
    -
    -        return $this->db->get()->row_array();
    -    }
    -}
    -?>
    -
    + return $this->db->get()->row_array(); + } +} +?> + - + diff --git a/docs/source-class-Summary_sales.html b/docs/source-class-Summary_sales.html index bdce1a2d8..c9a85ea68 100644 --- a/docs/source-class-Summary_sales.html +++ b/docs/source-class-Summary_sales.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -251,6 +252,6 @@ - + diff --git a/docs/source-class-Summary_suppliers.html b/docs/source-class-Summary_suppliers.html index bec559300..b6dc5feea 100644 --- a/docs/source-class-Summary_suppliers.html +++ b/docs/source-class-Summary_suppliers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -260,6 +261,6 @@ - + diff --git a/docs/source-class-Summary_taxes.html b/docs/source-class-Summary_taxes.html index 66088bed3..9099f831d 100644 --- a/docs/source-class-Summary_taxes.html +++ b/docs/source-class-Summary_taxes.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -291,6 +292,6 @@ - + diff --git a/docs/source-class-Supplier.html b/docs/source-class-Supplier.html index 85f58f54d..681c48189 100644 --- a/docs/source-class-Supplier.html +++ b/docs/source-class-Supplier.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -499,6 +500,6 @@ - + diff --git a/docs/source-class-Suppliers.html b/docs/source-class-Suppliers.html index e05acbb3e..91e4e1cd2 100644 --- a/docs/source-class-Suppliers.html +++ b/docs/source-class-Suppliers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -383,6 +384,6 @@ - + diff --git a/docs/source-class-Tax.html b/docs/source-class-Tax.html index a6a30573b..db8737025 100644 --- a/docs/source-class-Tax.html +++ b/docs/source-class-Tax.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -611,6 +612,6 @@ - + diff --git a/docs/source-class-Tax_lib.html b/docs/source-class-Tax_lib.html index 7c5358ce4..8df63739b 100644 --- a/docs/source-class-Tax_lib.html +++ b/docs/source-class-Tax_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -546,6 +547,6 @@ - + diff --git a/docs/source-class-Taxes.html b/docs/source-class-Taxes.html index 89f340925..6b55e2ce9 100644 --- a/docs/source-class-Taxes.html +++ b/docs/source-class-Taxes.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -442,6 +443,6 @@ - + diff --git a/docs/source-class-Token.html b/docs/source-class-Token.html index 4137e98e0..98618db4f 100644 --- a/docs/source-class-Token.html +++ b/docs/source-class-Token.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -282,6 +283,6 @@ - + diff --git a/docs/source-class-Token_customer.html b/docs/source-class-Token_customer.html index e9a11dcdf..c38fd39a5 100644 --- a/docs/source-class-Token_customer.html +++ b/docs/source-class-Token_customer.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -252,6 +253,6 @@ - + diff --git a/docs/source-class-Token_invoice_count.html b/docs/source-class-Token_invoice_count.html index 3de459135..f9d8ed71a 100644 --- a/docs/source-class-Token_invoice_count.html +++ b/docs/source-class-Token_invoice_count.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,6 +242,6 @@ - + diff --git a/docs/source-class-Token_invoice_sequence.html b/docs/source-class-Token_invoice_sequence.html index bc170daca..d8cac69e5 100644 --- a/docs/source-class-Token_invoice_sequence.html +++ b/docs/source-class-Token_invoice_sequence.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -234,6 +235,6 @@ - + diff --git a/docs/source-class-Token_lib.html b/docs/source-class-Token_lib.html index 21f74f34b..1190b7ae0 100644 --- a/docs/source-class-Token_lib.html +++ b/docs/source-class-Token_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -334,6 +335,6 @@ - + diff --git a/docs/source-class-Token_quote_sequence.html b/docs/source-class-Token_quote_sequence.html index 93c59944b..b508ad016 100644 --- a/docs/source-class-Token_quote_sequence.html +++ b/docs/source-class-Token_quote_sequence.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -234,6 +235,6 @@ - + diff --git a/docs/source-class-Token_suspended_invoice_count.html b/docs/source-class-Token_suspended_invoice_count.html index 329bd8018..519256e14 100644 --- a/docs/source-class-Token_suspended_invoice_count.html +++ b/docs/source-class-Token_suspended_invoice_count.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,6 +242,6 @@ - + diff --git a/docs/source-class-Token_year_invoice_count.html b/docs/source-class-Token_year_invoice_count.html index b7818e418..bb2026818 100644 --- a/docs/source-class-Token_year_invoice_count.html +++ b/docs/source-class-Token_year_invoice_count.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -241,6 +242,6 @@ - + diff --git a/docs/source-class-Tracking_lib.html b/docs/source-class-Tracking_lib.html index 004a84f52..eabbceb19 100644 --- a/docs/source-class-Tracking_lib.html +++ b/docs/source-class-Tracking_lib.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -322,6 +323,6 @@ - + diff --git a/docs/source-class-emberlabs.Barcode.BarcodeBase.html b/docs/source-class-emberlabs.Barcode.BarcodeBase.html index 8ffc1ca72..4e358006a 100644 --- a/docs/source-class-emberlabs.Barcode.BarcodeBase.html +++ b/docs/source-class-emberlabs.Barcode.BarcodeBase.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -432,6 +433,6 @@ - + diff --git a/docs/source-class-emberlabs.Barcode.Code128.html b/docs/source-class-emberlabs.Barcode.Code128.html index dad9f7371..c87e8fba1 100644 --- a/docs/source-class-emberlabs.Barcode.Code128.html +++ b/docs/source-class-emberlabs.Barcode.Code128.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -540,6 +541,6 @@ - + diff --git a/docs/source-class-emberlabs.Barcode.Code39.html b/docs/source-class-emberlabs.Barcode.Code39.html index 2f69adc8d..004f480d7 100644 --- a/docs/source-class-emberlabs.Barcode.Code39.html +++ b/docs/source-class-emberlabs.Barcode.Code39.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -399,6 +400,6 @@ - + diff --git a/docs/source-class-emberlabs.Barcode.Ean13.html b/docs/source-class-emberlabs.Barcode.Ean13.html index c8b8ee800..eaf154ca6 100644 --- a/docs/source-class-emberlabs.Barcode.Ean13.html +++ b/docs/source-class-emberlabs.Barcode.Ean13.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -585,6 +586,6 @@ - + diff --git a/docs/source-class-emberlabs.Barcode.Ean8.html b/docs/source-class-emberlabs.Barcode.Ean8.html index 3665291dc..8ebc90fd5 100644 --- a/docs/source-class-emberlabs.Barcode.Ean8.html +++ b/docs/source-class-emberlabs.Barcode.Ean8.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -584,6 +585,6 @@ - + diff --git a/docs/source-function-currency_side.html b/docs/source-function-currency_side.html index dda627123..9d41664c8 100644 --- a/docs/source-function-currency_side.html +++ b/docs/source-function-currency_side.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-current_language.html b/docs/source-function-current_language.html index dda627123..9d41664c8 100644 --- a/docs/source-function-current_language.html +++ b/docs/source-function-current_language.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-current_language_code.html b/docs/source-function-current_language_code.html index dda627123..9d41664c8 100644 --- a/docs/source-function-current_language_code.html +++ b/docs/source-function-current_language_code.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-dateformat_bootstrap.html b/docs/source-function-dateformat_bootstrap.html index dda627123..9d41664c8 100644 --- a/docs/source-function-dateformat_bootstrap.html +++ b/docs/source-function-dateformat_bootstrap.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-dateformat_momentjs.html b/docs/source-function-dateformat_momentjs.html index dda627123..9d41664c8 100644 --- a/docs/source-function-dateformat_momentjs.html +++ b/docs/source-function-dateformat_momentjs.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-db_log_queries.html b/docs/source-function-db_log_queries.html index ea53951f0..6608133b5 100644 --- a/docs/source-function-db_log_queries.html +++ b/docs/source-function-db_log_queries.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -244,6 +245,6 @@ - + diff --git a/docs/source-function-get_customer_data_row.html b/docs/source-function-get_customer_data_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_customer_data_row.html +++ b/docs/source-function-get_customer_data_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_customer_manage_table_headers.html b/docs/source-function-get_customer_manage_table_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_customer_manage_table_headers.html +++ b/docs/source-function-get_customer_manage_table_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_giftcard_data_row.html b/docs/source-function-get_giftcard_data_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_giftcard_data_row.html +++ b/docs/source-function-get_giftcard_data_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_giftcards_manage_table_headers.html b/docs/source-function-get_giftcards_manage_table_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_giftcards_manage_table_headers.html +++ b/docs/source-function-get_giftcards_manage_table_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_item_data_row.html b/docs/source-function-get_item_data_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_item_data_row.html +++ b/docs/source-function-get_item_data_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_item_kit_data_row.html b/docs/source-function-get_item_kit_data_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_item_kit_data_row.html +++ b/docs/source-function-get_item_kit_data_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_item_kits_manage_table_headers.html b/docs/source-function-get_item_kits_manage_table_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_item_kits_manage_table_headers.html +++ b/docs/source-function-get_item_kits_manage_table_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_items_manage_table_headers.html b/docs/source-function-get_items_manage_table_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_items_manage_table_headers.html +++ b/docs/source-function-get_items_manage_table_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_people_manage_table_headers.html b/docs/source-function-get_people_manage_table_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_people_manage_table_headers.html +++ b/docs/source-function-get_people_manage_table_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_person_data_row.html b/docs/source-function-get_person_data_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_person_data_row.html +++ b/docs/source-function-get_person_data_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_sale_data_last_row.html b/docs/source-function-get_sale_data_last_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_sale_data_last_row.html +++ b/docs/source-function-get_sale_data_last_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_sale_data_row.html b/docs/source-function-get_sale_data_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_sale_data_row.html +++ b/docs/source-function-get_sale_data_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_sales_manage_payments_summary.html b/docs/source-function-get_sales_manage_payments_summary.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_sales_manage_payments_summary.html +++ b/docs/source-function-get_sales_manage_payments_summary.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_sales_manage_table_headers.html b/docs/source-function-get_sales_manage_table_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_sales_manage_table_headers.html +++ b/docs/source-function-get_sales_manage_table_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_supplier_data_row.html b/docs/source-function-get_supplier_data_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_supplier_data_row.html +++ b/docs/source-function-get_supplier_data_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_suppliers_manage_table_headers.html b/docs/source-function-get_suppliers_manage_table_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_suppliers_manage_table_headers.html +++ b/docs/source-function-get_suppliers_manage_table_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_tax_data_row.html b/docs/source-function-get_tax_data_row.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_tax_data_row.html +++ b/docs/source-function-get_tax_data_row.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-get_taxes_manage_table_headers.html b/docs/source-function-get_taxes_manage_table_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-get_taxes_manage_table_headers.html +++ b/docs/source-function-get_taxes_manage_table_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-load_config.html b/docs/source-function-load_config.html index ab9487849..0a9292aca 100644 --- a/docs/source-function-load_config.html +++ b/docs/source-function-load_config.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -273,6 +274,6 @@ - + diff --git a/docs/source-function-load_language_files.html b/docs/source-function-load_language_files.html index ab9487849..0a9292aca 100644 --- a/docs/source-function-load_language_files.html +++ b/docs/source-function-load_language_files.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -273,6 +274,6 @@ - + diff --git a/docs/source-function-load_stats.html b/docs/source-function-load_stats.html index 2de622e74..5c655a064 100644 --- a/docs/source-function-load_stats.html +++ b/docs/source-function-load_stats.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -273,6 +274,6 @@ - + diff --git a/docs/source-function-parse_decimals.html b/docs/source-function-parse_decimals.html index dda627123..9d41664c8 100644 --- a/docs/source-function-parse_decimals.html +++ b/docs/source-function-parse_decimals.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-pdf_create.html b/docs/source-function-pdf_create.html index 57fa4d236..173f199c1 100644 --- a/docs/source-function-pdf_create.html +++ b/docs/source-function-pdf_create.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -247,6 +248,6 @@ - + diff --git a/docs/source-function-quantity_decimals.html b/docs/source-function-quantity_decimals.html index dda627123..9d41664c8 100644 --- a/docs/source-function-quantity_decimals.html +++ b/docs/source-function-quantity_decimals.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-show_report.html b/docs/source-function-show_report.html index 3b5300643..40ac9c9b1 100644 --- a/docs/source-function-show_report.html +++ b/docs/source-function-show_report.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -245,6 +246,6 @@ - + diff --git a/docs/source-function-show_report_if_allowed.html b/docs/source-function-show_report_if_allowed.html index 3b5300643..40ac9c9b1 100644 --- a/docs/source-function-show_report_if_allowed.html +++ b/docs/source-function-show_report_if_allowed.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -245,6 +246,6 @@ - + diff --git a/docs/source-function-tax_decimals.html b/docs/source-function-tax_decimals.html new file mode 100644 index 000000000..9d41664c8 --- /dev/null +++ b/docs/source-function-tax_decimals.html @@ -0,0 +1,427 @@ + + + + + + + File helpers/locale_helper.php + + + + + + +
    + +
    + +
    + + + + + + diff --git a/docs/source-function-to_currency.html b/docs/source-function-to_currency.html index dda627123..9d41664c8 100644 --- a/docs/source-function-to_currency.html +++ b/docs/source-function-to_currency.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-to_currency_no_money.html b/docs/source-function-to_currency_no_money.html index dda627123..9d41664c8 100644 --- a/docs/source-function-to_currency_no_money.html +++ b/docs/source-function-to_currency_no_money.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-to_decimals.html b/docs/source-function-to_decimals.html index dda627123..9d41664c8 100644 --- a/docs/source-function-to_decimals.html +++ b/docs/source-function-to_decimals.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-to_quantity_decimals.html b/docs/source-function-to_quantity_decimals.html index dda627123..9d41664c8 100644 --- a/docs/source-function-to_quantity_decimals.html +++ b/docs/source-function-to_quantity_decimals.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-to_tax_decimals.html b/docs/source-function-to_tax_decimals.html index dda627123..9d41664c8 100644 --- a/docs/source-function-to_tax_decimals.html +++ b/docs/source-function-to_tax_decimals.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-totals_decimals.html b/docs/source-function-totals_decimals.html index dda627123..9d41664c8 100644 --- a/docs/source-function-totals_decimals.html +++ b/docs/source-function-totals_decimals.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -207,7 +208,7 @@ -
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 
    +
      1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
     
     /**
    @@ -227,180 +228,193 @@
     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;
    -}
    +
    +    $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;
     
    -function totals_decimals()
    -{
    -    $config = get_instance()->config;
    -    return $config->item('currency_decimals') ? $config->item('currency_decimals') : 0;
    -}
    -
    -function to_currency($number)
    -{
    -    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    -}
    -
    -function to_currency_no_money($number)
    -{
    -    return to_decimals($number, 'currency_decimals');
    -}
    -
    -function to_tax_decimals($number)
    -{
    -    // taxes that are NULL, '' or 0 don't need to be displayed
    -    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    -    if(empty($number))
    -    {
    -        return $number;
    -    }
    -
    -    return to_decimals($number, 'tax_decimals');
    -}
    -
    -function to_quantity_decimals($number)
    -{
    -    return to_decimals($number, 'quantity_decimals');
    -}
    -
    -function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    -{
    -    // ignore empty strings and return
    -    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    -    if(!isset($number))
    -    {
    -        return $number;
    -    }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    -    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    -    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol'));
    -    return $fmt->format($number);
    -}
    -
    -function parse_decimals($number)
    -{
    -    // ignore empty strings and return
    -    if(empty($number))
    +    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 tax_decimals()
    +{
    +    $config = get_instance()->config;
    +
    +    return $config->item('tax_decimals') ? $config->item('tax_decimals') : 0;
    +}
    +
    +function to_currency($number)
    +{
    +    return to_decimals($number, 'currency_decimals', \NumberFormatter::CURRENCY);
    +}
    +
    +function to_currency_no_money($number)
    +{
    +    return to_decimals($number, 'currency_decimals');
    +}
    +
    +function to_tax_decimals($number)
    +{
    +    // taxes that are NULL, '' or 0 don't need to be displayed
    +    // NOTE: do not remove this line otherwise the items edit form will show a tax with 0 and it will save it
    +    if(empty($number))
    +    {
    +        return $number;
    +    }
    +
    +    return to_decimals($number, 'tax_decimals');
    +}
    +
    +function to_quantity_decimals($number)
    +{
    +    return to_decimals($number, 'quantity_decimals');
    +}
    +
    +function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
    +{
    +    // ignore empty strings and return
    +    // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
    +    if(!isset($number))
    +    {
    +        return $number;
    +    }
    +
    +    $config = get_instance()->config;
    +    $fmt = new \NumberFormatter($config->item('number_locale'), $type);
    +    $fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
    +    $fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
    +    if(empty($config->item('thousands_separator')))
         {
    -        return $number;
    +        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
         }
    -
    -    $config = get_instance()->config;
    -    $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
    -    if (empty($config->item('thousands_separator')))
    -    {
    -        $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
    -    }
    -    return $fmt->parse($number);
    -}
    -
    -/*
    - * Time locale conversion utility
    - */
    -
    -function dateformat_momentjs($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        'd' => 'DD',
    -        'D' => 'ddd',
    -        'j' => 'D',
    -        'l' => 'dddd',
    -        'N' => 'E',
    -        'S' => 'o',
    -        'w' => 'e',
    -        'z' => 'DDD',
    -        'W' => 'W',
    -        'F' => 'MMMM',
    -        'm' => 'MM',
    -        'M' => 'MMM',
    -        'n' => 'M',
    -        't' => '', // no equivalent
    -        'L' => '', // no equivalent
    -        'o' => 'YYYY',
    -        'Y' => 'YYYY',
    -        'y' => 'YY',
    -        'a' => 'a',
    -        'A' => 'A',
    -        'B' => '', // no equivalent
    -        'g' => 'h',
    -        'G' => 'H',
    -        'h' => 'hh',
    -        'H' => 'HH',
    -        'i' => 'mm',
    -        's' => 'ss',
    -        'u' => 'SSS',
    -        'e' => 'zz', // deprecated since version $1.6.0 of moment.js
    -        'I' => '', // no equivalent
    -        'O' => '', // no equivalent
    -        'P' => '', // no equivalent
    -        'T' => '', // no equivalent
    -        'Z' => '', // no equivalent
    -        'c' => '', // no equivalent
    -        'r' => '', // no equivalent
    -        'U' => 'X'
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -function dateformat_bootstrap($php_format)
    -{
    -    $SYMBOLS_MATCHING = array(
    -        // Day
    -        'd' => 'dd',
    -        'D' => 'd',
    -        'j' => 'd',
    -        'l' => 'dd',
    -        'N' => '',
    -        'S' => '',
    -        'w' => '',
    -        'z' => '',
    -        // Week
    -        'W' => '',
    -        // Month
    -        'F' => 'MM',
    -        'm' => 'mm',
    -        'M' => 'M',
    -        'n' => 'm',
    -        't' => '',
    -        // Year
    -        'L' => '',
    -        'o' => '',
    -        'Y' => 'yyyy',
    -        'y' => 'yy',
    -        // Time
    -        'a' => 'p',
    -        'A' => 'P',
    -        'B' => '',
    -        'g' => 'H',
    -        'G' => 'h',
    -        'h' => 'HH',
    -        'H' => 'hh',
    -        'i' => 'ii',
    -        's' => 'ss',
    -        'u' => ''
    -    );
    -
    -    return strtr($php_format, $SYMBOLS_MATCHING);
    -}
    -
    -?>
    -
    + $fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $config->item('currency_symbol')); + + return $fmt->format($number); +} + +function parse_decimals($number) +{ + // ignore empty strings and return + if(empty($number)) + { + return $number; + } + + $config = get_instance()->config; + $fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL ); + if (empty($config->item('thousands_separator'))) + { + $fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); + } + + return $fmt->parse($number); +} + +/* + * Time locale conversion utility + */ + +function dateformat_momentjs($php_format) +{ + $SYMBOLS_MATCHING = array( + 'd' => 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'o', + 'w' => 'e', + 'z' => 'DDD', + 'W' => 'W', + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', // no equivalent + 'L' => '', // no equivalent + 'o' => 'YYYY', + 'Y' => 'YYYY', + 'y' => 'YY', + 'a' => 'a', + 'A' => 'A', + 'B' => '', // no equivalent + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => 'SSS', + 'e' => 'zz', // deprecated since version $1.6.0 of moment.js + 'I' => '', // no equivalent + 'O' => '', // no equivalent + 'P' => '', // no equivalent + 'T' => '', // no equivalent + 'Z' => '', // no equivalent + 'c' => '', // no equivalent + 'r' => '', // no equivalent + 'U' => 'X' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +function dateformat_bootstrap($php_format) +{ + $SYMBOLS_MATCHING = array( + // Day + 'd' => 'dd', + 'D' => 'd', + 'j' => 'd', + 'l' => 'dd', + 'N' => '', + 'S' => '', + 'w' => '', + 'z' => '', + // Week + 'W' => '', + // Month + 'F' => 'MM', + 'm' => 'mm', + 'M' => 'M', + 'n' => 'm', + 't' => '', + // Year + 'L' => '', + 'o' => '', + 'Y' => 'yyyy', + 'y' => 'yy', + // Time + 'a' => 'p', + 'A' => 'P', + 'B' => '', + 'g' => 'H', + 'G' => 'h', + 'h' => 'HH', + 'H' => 'hh', + 'i' => 'ii', + 's' => 'ss', + 'u' => '' + ); + + return strtr($php_format, $SYMBOLS_MATCHING); +} + +?> + - + diff --git a/docs/source-function-transform_headers.html b/docs/source-function-transform_headers.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-transform_headers.html +++ b/docs/source-function-transform_headers.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - + diff --git a/docs/source-function-transform_headers_readonly.html b/docs/source-function-transform_headers_readonly.html index eb9fb0a7f..4a0b91434 100644 --- a/docs/source-function-transform_headers_readonly.html +++ b/docs/source-function-transform_headers_readonly.html @@ -168,6 +168,7 @@
  • quantity_decimals
  • show_report
  • show_report_if_allowed
  • +
  • tax_decimals
  • to_currency
  • to_currency_no_money
  • to_decimals
  • @@ -669,6 +670,6 @@ - +