From b85b9d37a154376c8dc0a57f2444194c8279e616 Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 6 Apr 2015 15:15:34 +0200 Subject: [PATCH] Add company_name field to customers for invoicing purposes Total discount is now shown as one amount in receipt Conflicts: application/controllers/sales.php Conflicts: database/migrate_phppos.sql --- application/controllers/customers.php | 1 + application/controllers/items.php | 2 +- application/controllers/sales.php | 33 +++++++++++++++---- application/language/en/customers_lang.php | 1 + application/language/es/customers_lang.php | 1 + application/language/fr/customers_lang.php | 1 + application/language/id/customers_lang.php | 1 + application/language/nl-BE/customers_lang.php | 1 + application/language/ru/customers_lang.php | 1 + application/language/th/customers_lang.php | 1 + application/language/tr/customers_lang.php | 1 + application/language/zh/customers_lang.php | 1 + application/libraries/Sale_lib.php | 9 ++--- application/views/customers/form.php | 11 +++++++ application/views/items/form.php | 8 ++--- application/views/sales/receipt.php | 12 +++---- database/database.sql | 1 + 17 files changed, 64 insertions(+), 22 deletions(-) diff --git a/application/controllers/customers.php b/application/controllers/customers.php index d7ca3cc34..833f012ca 100644 --- a/application/controllers/customers.php +++ b/application/controllers/customers.php @@ -72,6 +72,7 @@ class Customers extends Person_controller ); $customer_data=array( 'account_number'=>$this->input->post('account_number')=='' ? null:$this->input->post('account_number'), + 'company_name'=>$this->input->post('company_name')=='' ? null:$this->input->post('company_name'), 'taxable'=>$this->input->post('taxable')=='' ? 0:1, ); if($this->Customer->save($person_data,$customer_data,$customer_id)) diff --git a/application/controllers/items.php b/application/controllers/items.php index 57d414cf2..80edcefa2 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -723,7 +723,7 @@ class Items extends Secure_area implements iData_controller */ function get_form_width() { - return 400; + return 450; } } diff --git a/application/controllers/sales.php b/application/controllers/sales.php index 966eed25e..4959af621 100644 --- a/application/controllers/sales.php +++ b/application/controllers/sales.php @@ -286,7 +286,7 @@ class Sales extends Secure_area $data['tax_exclusive_subtotal']=$this->sale_lib->get_subtotal(TRUE, TRUE); $data['taxes']=$this->sale_lib->get_taxes(); $data['total']=$this->sale_lib->get_total(); - $data['discounts']=$this->sale_lib->get_discounts(); + $data['discount']=$this->sale_lib->get_discount(); $data['receipt_title']=$this->lang->line('sales_receipt'); $data['transaction_time']= date('m/d/Y h:i:s a'); $data['transaction_date']= date('d/m/Y', strtotime($data['transaction_time'])); @@ -309,7 +309,14 @@ class Sales extends Secure_area if($customer_id!=-1) { $cust_info=$this->Customer->get_info($customer_id); - $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + if (isset($cust_info->company_name)) + { + $data['customer']=$cust_info->company_name; + } + else + { + $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + } $data['customer_address'] = $cust_info->address_1; $data['customer_location'] = $cust_info->zip . ' ' . $cust_info->city; $data['account_number'] = $cust_info->account_number; @@ -492,7 +499,7 @@ class Sales extends Secure_area $data['tax_exclusive_subtotal']=$this->sale_lib->get_subtotal(TRUE, TRUE); $data['taxes']=$this->sale_lib->get_taxes(); $data['total']=$this->sale_lib->get_total(); - $data['discounts']=$this->sale_lib->get_discounts(); + $data['discount']=$this->sale_lib->get_discount(); $data['receipt_title']=$this->lang->line('sales_receipt'); $data['transaction_time']= date('d/m/Y H:i:s', strtotime($sale_info['sale_time'])); $stock_locations=$this->Stock_locations->get_undeleted_all('sales')->result_array(); @@ -508,7 +515,14 @@ class Sales extends Secure_area if($customer_id!=-1) { $cust_info=$this->Customer->get_info($customer_id); - $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + if (isset($cust_info->company_name)) + { + $data['customer']=$cust_info->company_name; + } + else + { + $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + } $data['first_name']=$cust_info->first_name; $data['last_name']=$cust_info->last_name; $data['customer_address'] = $cust_info->address_1; @@ -647,7 +661,7 @@ class Sales extends Secure_area $data['subtotal']=$this->sale_lib->get_subtotal(TRUE); $data['taxes']=$this->sale_lib->get_taxes(); - $data['discounts']=$this->sale_lib->get_discounts(); + $data['discount']=$this->sale_lib->get_discount(); $data['total']=$this->sale_lib->get_total(); $data['items_module_allowed']=$this->Employee->has_grant('items', $person_info->person_id); $data['comment']=$this->sale_lib->get_comment(); @@ -715,7 +729,14 @@ class Sales extends Secure_area if($customer_id!=-1) { $cust_info=$this->Customer->get_info($customer_id); - $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + if (isset($cust_info->company_name)) + { + $data['customer']=$cust_info->company_name; + } + else + { + $data['customer']=$cust_info->first_name.' '.$cust_info->last_name; + } } $total_payments = 0; diff --git a/application/language/en/customers_lang.php b/application/language/en/customers_lang.php index 9dcaff553..7d2170062 100644 --- a/application/language/en/customers_lang.php +++ b/application/language/en/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "Account #"; $lang["customers_account_number_duplicate"] = "This account number is already present in the database"; $lang["customers_basic_information"] = "Customer Information"; $lang["customers_cannot_be_deleted"] = "Could not deleted selected customers, one or more of the selected customers has sales."; +$lang["customers_company_name"] = "Company Name"; $lang["customers_confirm_delete"] = "Are you sure you want to delete the selected customers?"; $lang["customers_customer"] = "Customer"; $lang["customers_error_adding_updating"] = "Error adding/updating customer"; diff --git a/application/language/es/customers_lang.php b/application/language/es/customers_lang.php index 203d65d81..0c200b1eb 100644 --- a/application/language/es/customers_lang.php +++ b/application/language/es/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "Cuenta #"; $lang["customers_account_number_duplicate"] = "This account number is already present in the database"; $lang["customers_basic_information"] = "Información de Clientes"; $lang["customers_cannot_be_deleted"] = "No se pudo borrar los clientes seleccionados. Uno o más de éstos tiene ventas."; +$lang["customers_company_name"] = "Company Name"; $lang["customers_confirm_delete"] = "¿Estás seguro(a) de que quieres borrar a los clientes seleccionados?"; $lang["customers_customer"] = "Cliente"; $lang["customers_error_adding_updating"] = "Error agregando/actualizando cliente"; diff --git a/application/language/fr/customers_lang.php b/application/language/fr/customers_lang.php index 12d5aa8e7..f485dfa56 100644 --- a/application/language/fr/customers_lang.php +++ b/application/language/fr/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "# Compte"; $lang["customers_account_number_duplicate"] = "This account number is already present in the database"; $lang["customers_basic_information"] = "Informations Client"; $lang["customers_cannot_be_deleted"] = "Impossible de supprimer. Un ou plusiers client(s) sélectionné(s) ont des ventes."; +$lang["customers_company_name"] = "Company Name"; $lang["customers_confirm_delete"] = "Etes vous sûr(e) de vouloir supprimer ces clients?"; $lang["customers_customer"] = "Client"; $lang["customers_error_adding_updating"] = "Érreur lors de l\'ajout/suppression de client"; diff --git a/application/language/id/customers_lang.php b/application/language/id/customers_lang.php index e433e6a07..6464a1d86 100644 --- a/application/language/id/customers_lang.php +++ b/application/language/id/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "No.Pelanggan"; $lang["customers_account_number_duplicate"] = "This account number is already present in the database"; $lang["customers_basic_information"] = "Informasi Pelanggan"; $lang["customers_cannot_be_deleted"] = "pelanggan terpilih tidak bisa dihapus; satu atau lebih dari pelanggan yang dipilih memiliki penjualan."; +$lang["customers_company_name"] = "Company Name"; $lang["customers_confirm_delete"] = "Apakah Anda yakin ingin menghapus pelanggan yang dipilih?"; $lang["customers_customer"] = "Pelanggan"; $lang["customers_error_adding_updating"] = "Menambah / Memperbarui Pelanggan Salah"; diff --git a/application/language/nl-BE/customers_lang.php b/application/language/nl-BE/customers_lang.php index cff4fcbdb..873a3eef3 100755 --- a/application/language/nl-BE/customers_lang.php +++ b/application/language/nl-BE/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "Btwnummer"; $lang["customers_account_number_duplicate"] = "Deze VAT nummer is reeds aanwezig in de database"; $lang["customers_basic_information"] = "Klantgegevens"; $lang["customers_cannot_be_deleted"] = "De geselecteerde klanten konden niet worden verwijderd. Eén of meerdere klanten hebben verkoopsgegevens in de database zitten."; +$lang["customers_company_name"] = "Bedrijfsnaam"; $lang["customers_confirm_delete"] = "Bent u zeker dat u de geselecteerde klanten wil verwijderen?"; $lang["customers_customer"] = "Klant"; $lang["customers_error_adding_updating"] = "Fout bij het toevoegen/bewerken van een klant"; diff --git a/application/language/ru/customers_lang.php b/application/language/ru/customers_lang.php index 8b9dabe66..af0f963f5 100644 --- a/application/language/ru/customers_lang.php +++ b/application/language/ru/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "Номер счота"; $lang["customers_account_number_duplicate"] = "This account number is already present in the database"; $lang["customers_basic_information"] = "Информация о клиенте"; $lang["customers_cannot_be_deleted"] = "Невозможно удалить выбранных клиентов, один или более из них имеет продаж."; +$lang["customers_company_name"] = "Company Name"; $lang["customers_confirm_delete"] = "Вы уверены, что хотите удалить выбранных клиентов?"; $lang["customers_customer"] = "Клиент"; $lang["customers_error_adding_updating"] = "Ошибка при добавлении/обновлении клиента"; diff --git a/application/language/th/customers_lang.php b/application/language/th/customers_lang.php index 81f007e17..7b2804d16 100644 --- a/application/language/th/customers_lang.php +++ b/application/language/th/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "บัญชี #"; $lang["customers_account_number_duplicate"] = "This account number is already present in the database"; $lang["customers_basic_information"] = "ข้อมูลลูกค้า"; $lang["customers_cannot_be_deleted"] = "ไม่สามารลบลูกค้าที่ถูกเลือก, ลูกค้าที่ถูกเลือกถูขายไปแล้ว."; +$lang["customers_company_name"] = "Company Name"; $lang["customers_confirm_delete"] = "ยืนยันลบข้อมูลลูกค้า?"; $lang["customers_customer"] = "ลูกค้า"; $lang["customers_error_adding_updating"] = "แก้ไขข้อมูลลูกค้าผิดพลาด"; diff --git a/application/language/tr/customers_lang.php b/application/language/tr/customers_lang.php index 207b3d326..e791b5c2b 100644 --- a/application/language/tr/customers_lang.php +++ b/application/language/tr/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "Hesap No"; $lang["customers_account_number_duplicate"] = "This account number is already present in the database"; $lang["customers_basic_information"] = "Müşteri bilgisi"; $lang["customers_cannot_be_deleted"] = "Seçili müşteriler silinemedi, müşterilerin satışları var."; +$lang["customers_company_name"] = "Company Name"; $lang["customers_confirm_delete"] = "Seçili müşteriyi silmek istediğinize emin misiniz?"; $lang["customers_customer"] = "Müşteri"; $lang["customers_error_adding_updating"] = "Müşteri ekleme/güncelleme hatası"; diff --git a/application/language/zh/customers_lang.php b/application/language/zh/customers_lang.php index 535eb00c7..94a3cf5f0 100755 --- a/application/language/zh/customers_lang.php +++ b/application/language/zh/customers_lang.php @@ -4,6 +4,7 @@ $lang["customers_account_number"] = "帳號 #"; $lang["customers_account_number_duplicate"] = "This account number is already present in the database"; $lang["customers_basic_information"] = "客戶資訊"; $lang["customers_cannot_be_deleted"] = "無法刪除選定的客戶,選定的客戶存有銷售紀錄。"; +$lang["customers_company_name"] = "Company Name"; $lang["customers_confirm_delete"] = "你確定要刪除選定的客戶?"; $lang["customers_customer"] = "客戶"; $lang["customers_error_adding_updating"] = "添加/更新客戶錯誤"; diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index cabdc4834..6b57f1db7 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -558,17 +558,18 @@ class Sale_lib return $taxes; } - function get_discounts() + function get_discount() { - $discounts = array(); + $discount = 0; foreach($this->get_cart() as $line=>$item) { if ($item['discount'] > 0) { - $discounts[] = $this->get_item_discount($item['quantity'], $item['price'], $item['discount']); + $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount']); + $discount = bcadd($discount, $item_discount, PRECISION); } } - return $discounts; + return $discount; } function get_subtotal($include_discount=FALSE, $exclude_tax=FALSE) diff --git a/application/views/customers/form.php b/application/views/customers/form.php index e7ebcc95a..2cfe397f3 100644 --- a/application/views/customers/form.php +++ b/application/views/customers/form.php @@ -6,6 +6,17 @@ echo form_open('customers/save/'.$person_info->person_id,array('id'=>'customer_f
lang->line("customers_basic_information"); ?> load->view("people/form_basic_info"); ?> + +
+lang->line('customers_company_name').':', 'company_name'); ?> +
+ 'company_name', + 'value'=>$person_info->company_name) + );?> +
+
+
lang->line('customers_account_number').':', 'account_number'); ?>
diff --git a/application/views/items/form.php b/application/views/items/form.php index f981185ea..26c9647e4 100644 --- a/application/views/items/form.php +++ b/application/views/items/form.php @@ -4,9 +4,9 @@ echo form_open('items/save/'.$item_info->item_id,array('id'=>'item_form', 'enctype'=>'multipart/form-data')); ?>
-lang->line("items_basic_information"); ?> + lang->line("items_basic_information"); ?> -
+
lang->line('items_item_number').':', 'item_number',array('class'=>'wide')); ?>
item_id,array('id'=>'item_form', 'encty 'value'=>$item_info->item_number) );?>
-
+
-
+
lang->line('items_name').':', 'name',array('class'=>'required wide')); ?>
- Appconfig->get('show_total_discount') && count($discounts) > 0): ?> + Appconfig->get('show_total_discount') && $discount > 0): ?> lang->line('sales_sub_total'); ?> - $value) { ?> - - lang->line('sales_discount'); ?>: - - - + + lang->line('sales_discount'); ?>: + + Appconfig->get('receipt_show_taxes')): ?> diff --git a/database/database.sql b/database/database.sql index 384249961..f488e5a72 100644 --- a/database/database.sql +++ b/database/database.sql @@ -77,6 +77,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES CREATE TABLE `ospos_customers` ( `person_id` int(10) NOT NULL, + `company_name` varchar(255) NOT NULL, `account_number` varchar(255) DEFAULT NULL, `taxable` int(1) NOT NULL DEFAULT '1', `deleted` int(1) NOT NULL DEFAULT '0',