Remove invoice / sale format enable option

Add giftcards -> person_id foreign key constraint
Fix tax calculation for non taxable customers
Improve giftcard person autocompletion
This commit is contained in:
jekkos-t520
2014-12-16 08:49:49 +01:00
parent b546883d2a
commit 07a32a0deb
9 changed files with 65 additions and 52 deletions

View File

@@ -39,9 +39,7 @@ class Config extends Secure_area
'timezone'=>$this->input->post('timezone'),
'print_after_sale'=>$this->input->post('print_after_sale'),
'tax_included'=>$this->input->post('tax_included'),
'recv_invoice_enable'=>$this->input->post('recv_invoice_enable'),
'recv_invoice_format'=>$this->input->post('recv_invoice_format'),
'sales_invoice_enable'=>$this->input->post('sales_invoice_enable'),
'sales_invoice_format'=>$this->input->post('sales_invoice_format'),
'custom1_name'=>$this->input->post('custom1_name'),/**GARRISON ADDED 4/20/2013**/
'custom2_name'=>$this->input->post('custom2_name'),/**GARRISON ADDED 4/20/2013**/

View File

@@ -41,9 +41,9 @@ class Giftcards extends Secure_area implements iData_controller
/*
Gives search suggestions for person_id based on what is being searched for
*/
function suggest_person()
function person_search()
{
$suggestions = $this->Giftcard->get_person_search_suggestions($this->input->post('q'),$this->input->post('limit'));
$suggestions = $this->Customer->get_customer_search_suggestions($this->input->post('q'),$this->input->post('limit'));
echo implode("\n",$suggestions);
}
/** END GARRISON ADDED **/
@@ -56,8 +56,10 @@ class Giftcards extends Secure_area implements iData_controller
function view($giftcard_id=-1)
{
$data['giftcard_info']=$this->Giftcard->get_info($giftcard_id);
$giftcard_info=$this->Giftcard->get_info($giftcard_id);
$person_name=$giftcard_info->first_name . ' ' . $giftcard_info->last_name;
$data['selected_person'] = $giftcard_id > 0 ? $giftcard_info->person_id . "|" . $person_name : "";
$data['giftcard_info']=$giftcard_info;
$this->load->view("giftcards/form",$data);
}

View File

@@ -101,8 +101,7 @@ class Receiving_lib
function clear_invoice_number_enabled()
{
$enable = $this->CI->config->config['recv_invoice_enable'];
$this->set_invoice_number_enabled($enable);
$this->set_invoice_number_enabled(FALSE);
}
function set_stock_source($stock_source)

View File

@@ -80,8 +80,7 @@ class Sale_lib
function clear_invoice_number_enabled()
{
$enable = $this->CI->config->config['sales_invoice_enable'];
$this->set_invoice_number_enabled($enable);
$this->set_invoice_number_enabled(FALSE);
}
function get_email_receipt()
@@ -537,15 +536,15 @@ class Sale_lib
return to_currency_no_money($subtotal);
}
function get_item_total_tax_exclusive($quantity, $price, $discount_percentage)
function get_item_total_tax_exclusive($item_id, $quantity, $price, $discount_percentage)
{
$tax_info = $this->CI->Item_taxes->get_info($item['item_id']);
$tax_info = $this->CI->Item_taxes->get_info($item_id);
$item_price = $this->get_item_total($quantity, $price, $discount_percentage);
// only additive tax here
foreach($tax_info as $tax)
{
$tax_percentage = $tax_info[0]['percent'];
$item_price =- $this->get_item_tax($quantity, $price, $discount_percentage, $tax_percentage);
$item_price -= $this->get_item_tax($quantity, $price, $discount_percentage, $tax_percentage);
}
return $item_price;
@@ -585,13 +584,13 @@ class Sale_lib
}
else
{
if ($CI->config->config['tax_included'])
if ($this->CI->config->config['tax_included'])
{
$subtotal += $this->get_item_total($item['quantity'], $item['price'], $item['discount']);
}
else
{
$subtotal += $this->get_item_total_tax_exclusive($item['quantity'], $item['price'], $item['discount']);
$subtotal += $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount']);
}
}
}

View File

@@ -41,6 +41,7 @@ class Giftcard extends CI_Model
function get_info($giftcard_id)
{
$this->db->from('giftcards');
$this->db->join('people', 'people.person_id = giftcards.person_id', 'LEFT');
$this->db->where('giftcard_id',$giftcard_id);
$this->db->where('deleted',0);

View File

@@ -268,17 +268,6 @@ echo form_open('config/save/',array('id'=>'config_form'));
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_sales_invoice_enable').':', 'sales_invoice_enable',array('class'=>'wide')); ?>
<div class='form_field'>
<?php echo form_checkbox(array(
'name'=>'sales_invoice_enable',
'id'=>'sales_invoice_enable',
'value'=>'sales_invoice_enable',
'checked'=>$this->config->item('sales_invoice_enable')));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_sales_invoice_format').':', 'sales_invoice_format',array('class'=>'wide')); ?>
<div class='form_field'>
@@ -289,17 +278,6 @@ echo form_open('config/save/',array('id'=>'config_form'));
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_recv_invoice_enable').':', 'recv_invoice_enable',array('class'=>'wide')); ?>
<div class='form_field'>
<?php echo form_checkbox(array(
'name'=>'recv_invoice_enable',
'id'=>'recv_invoice_enable',
'value'=>'recv_invoice_enable',
'checked'=>$this->config->item('recv_invoice_enable')));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('config_recv_invoice_format').':', 'recv_invoice_format',array('class'=>'wide')); ?>
<div class='form_field'>

View File

@@ -13,7 +13,7 @@ echo form_open('giftcards/save/'.$giftcard_info->giftcard_id,array('id'=>'giftca
<?php echo form_input(array(
'name'=>'person_id',
'id'=>'person_id',
'value'=>$giftcard_info->person_id)
'value'=>$selected_person)
);?>
</div>
</div>
@@ -58,22 +58,52 @@ echo form_close();
//validation and submit handling
$(document).ready(function()
{
$("#person_id").autocomplete("<?php echo site_url('giftcards/suggest_person');?>",{max:100,minChars:0,delay:10});
$("#person_id").result(function(event, data, formatted){});
$("#person_id").search();
$('#giftcard_form').validate({
submitHandler:function(form)
var format_item = function(row)
{
var result = [row[0], "|", row[1]].join("");
// if more than one occurence
if (row[2] > 1 && row[3] && row[3].toString().trim()) {
// display zip code
result += ' - ' + row[3];
}
return result;
};
var autocompleter = $("#person_id").autocomplete('<?php echo site_url("giftcards/person_search"); ?>',
{
minChars:0,
delay:15,
max:100,
cacheLength: 1,
formatItem: format_item,
formatResult : format_item
});
// declare submitHandler as an object.. will be reused
var submit_form = function(selected_person)
{
$(this).ajaxSubmit(
{
$(form).ajaxSubmit({
success:function(response)
{
tb_remove();
post_giftcard_form_submit(response);
},
error: function(jqXHR, textStatus, errorThrown)
{
selected_customer && autocompleter.val(selected_person);
post_giftcard_form_submit({message: errorThrown});
},
dataType:'json'
});
};
$('#giftcard_form').validate({
submitHandler:function(form)
{
var selected_person = autocompleter.val();
var selected_person_id = selected_person.replace(/(\w)\|.*/, "$1");
selected_person_id && autocompleter.val(selected_person_id);
submit_form.call(form, selected_person);
},
errorLabelContainer: "#error_message_box",
wrapper: "li",

View File

@@ -78,9 +78,7 @@ INSERT INTO `ospos_grants` (`permission_id`, `person_id`) VALUES
INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('tax_included', '0'),
('recv_invoice_format', '$CO'),
('sales_invoice_format', '$CO'),
('sales_invoice_enable', '0'),
('recv_invoice_enable', '0');
('sales_invoice_format', '$CO');
-- add invoice_number column to receivings table
ALTER TABLE `ospos_receivings`
@@ -101,3 +99,7 @@ ALTER TABLE `ospos_sales_suspended`
ALTER TABLE `ospos_items`
ADD COLUMN `receiving_quantity` int(11) DEFAULT '1',
DROP COLUMN `quantity`;
-- add foreign key to giftcards table
ALTER TABLE `ospos_giftcards`
ADD CONSTRAINT `ospos_giftcards_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);

View File

@@ -39,9 +39,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('website', ''),
('recv_invoice_format', '$CO'),
('sales_invoice_format', '$CO'),
('tax_included', '0'),
('recv_invoice_enable', '0'),
('sales_invoice_enable', '0');
('tax_included', '0');
-- --------------------------------------------------------
@@ -819,3 +817,9 @@ ALTER TABLE `ospos_item_quantities`
--
ALTER TABLE `ospos_suppliers`
ADD CONSTRAINT `ospos_suppliers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);
--
-- Constraints for table `ospos_giftcards`
--
ALTER TABLE `ospos_giftcards`
ADD CONSTRAINT `ospos_giftcards_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);