diff --git a/application/controllers/items.php b/application/controllers/items.php index 515d67c0d..c9ef537b5 100644 --- a/application/controllers/items.php +++ b/application/controllers/items.php @@ -617,9 +617,9 @@ class Items extends Secure_area implements iData_controller if ($this->Item->get_item_id($item_number) != FALSE) { $this->form_validation->set_message('item_number_check', $this->lang->line('items_item_number_exists')); - echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_adding')); + echo json_encode(array('success'=>false,'message'=>$this->lang->line('items_error_adding'))); } - echo json_encode(array('success'=>false,'message'=>$this->lang->line('items_error_adding')); + echo json_encode(array('success'=>true,'message'=>$this->lang->line('items_successful_adding'))); } } diff --git a/application/controllers/receivings.php b/application/controllers/receivings.php index 2c32b3d5c..047487ddb 100644 --- a/application/controllers/receivings.php +++ b/application/controllers/receivings.php @@ -193,18 +193,26 @@ class Receivings extends Secure_area $data['supplier']=$suppl_info->first_name.' '.$suppl_info->last_name; } $invoice_number=$this->_substitute_invoice_number($suppl_info); - $data['invoice_number']=$invoice_number; - $data['payment_type']=$this->input->post('payment_type'); - //SAVE receiving to database - $data['receiving_id']='RECV '.$this->Receiving->save($data['cart'], $supplier_id,$employee_id,$comment,$payment_type,$data['stock_location'],$invoice_number); - - if ($data['receiving_id'] == 'RECV -1') + if ($this->Receiving->invoice_number_exists($invoice_number)) { - $data['error_message'] = $this->lang->line('receivings_transaction_failed'); + $data['error']=$this->lang->line('recvs_invoice_number_constraint'); + $this->_reload($data); + } + else + { + $data['invoice_number']=$invoice_number; + $data['payment_type']=$this->input->post('payment_type'); + //SAVE receiving to database + $data['receiving_id']='RECV '.$this->Receiving->save($data['cart'], $supplier_id,$employee_id,$comment,$payment_type,$data['stock_location'],$invoice_number); + + if ($data['receiving_id'] == 'RECV -1') + { + $data['error_message'] = $this->lang->line('receivings_transaction_failed'); + } + + $this->load->view("receivings/receipt",$data); + $this->receiving_lib->clear_all(); } - - $this->load->view("receivings/receipt",$data); - $this->receiving_lib->clear_all(); $this->_remove_duplicate_cookies(); } @@ -356,6 +364,14 @@ class Receivings extends Secure_area $this->receiving_lib->clear_all(); $this->_reload(); } + + function check_invoice_number() + { + $receiving_id=$this->input->post('receiving_id'); + $invoice_number=$this->input->post('invoice_number'); + $exists=!empty($invoice_number) && $this->Receiving->invoice_number_exists($invoice_number,$receiving_id); + echo json_encode(array('success'=>!$exists,'message'=>$this->lang->line('recvs_invoice_number_duplicate'))); + } } ?> \ No newline at end of file diff --git a/application/controllers/secure_area.php b/application/controllers/secure_area.php index 3a05865bc..dff0bf988 100644 --- a/application/controllers/secure_area.php +++ b/application/controllers/secure_area.php @@ -24,6 +24,7 @@ class Secure_area extends CI_Controller $logged_in_employee_info=$this->Employee->get_logged_in_employee_info(); $data['allowed_modules']=$this->Module->get_allowed_modules($logged_in_employee_info->person_id); $data['user_info']=$logged_in_employee_info; + $data['controller_name']=$module_id; $this->load->vars($data); } diff --git a/application/language/en/receivings_lang.php b/application/language/en/receivings_lang.php index 24edd1cdc..0babf19b8 100644 --- a/application/language/en/receivings_lang.php +++ b/application/language/en/receivings_lang.php @@ -55,4 +55,5 @@ $lang['recvs_receipt']='Receivings Receipt'; $lang['recvs_date_required']='A correct date needs to be filled in'; $lang['recvs_date_type']='Date field is required'; $lang['recvs_delete_confirmation'] = 'Are you sure you want to delete this receiving, this action cannot be undone'; -?> +$lang['recvs_invoice_number_duplicate'] = 'Please enter an unique invoice number'; +?> \ No newline at end of file diff --git a/application/models/receiving.php b/application/models/receiving.php index 65996ea5b..e44db43a4 100644 --- a/application/models/receiving.php +++ b/application/models/receiving.php @@ -168,6 +168,18 @@ class Receiving extends CI_Model return $this->Supplier->get_info($this->db->get()->row()->supplier_id); } + function invoice_number_exists($invoice_number,$receiving_id='') + { + $this->db->from('receivings'); + $this->db->where('invoice_number', $invoice_number); + if (!empty($receiving_id)) + { + $this->db->where('receiving_id !=', $receiving_id); + } + $query=$this->db->get(); + return ($query->num_rows()==1); + } + //We create a temp table that allows us to do easy report/receiving queries public function create_receivings_items_temp_table() { diff --git a/application/views/receivings/form.php b/application/views/receivings/form.php index 92abbd1b2..0570c2ccf 100755 --- a/application/views/receivings/form.php +++ b/application/views/receivings/form.php @@ -74,6 +74,24 @@ $(document).ready(function() { + $.validator.addMethod("invoice_number", function(value, element) + { + var id = $("input[name='receiving_id']").val(); + + return JSON.parse($.ajax( + { + type: 'POST', + url: '', + data: {'receiving_id' : id, 'invoice_number' : $(element).val() }, + success: function(response) + { + success=response.success; + }, + async:false, + dataType: 'json' + }).response).success; + }, 'lang->line("recvs_invoice_number_duplicate"); ?>'); + $('#date').datePicker({startDate: ''}); $("#recvs_delete_form").submit(function() { @@ -83,7 +101,8 @@ $(document).ready(function() } }); - var format_item = function(row) { + 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()) { @@ -92,7 +111,8 @@ $(document).ready(function() } return result; }; - var autocompleter = $("#supplier_id").autocomplete('', { + var autocompleter = $("#supplier_id").autocomplete('', + { minChars:0, delay:15, max:100, @@ -102,7 +122,8 @@ $(document).ready(function() }); // declare submitHandler as an object.. will be reused - var submit_form = function(selected_supplier) { + var submit_form = function(selected_supplier) + { $(this).ajaxSubmit({ success:function(response) { @@ -110,13 +131,14 @@ $(document).ready(function() post_form_submit(response); }, error: function(jqXHR, textStatus, errorThrown) { - selected_customer && autocompleter.val(selected_supplier); + selected_supplier && autocompleter.val(selected_supplier); post_form_submit({message: errorThrown}); }, dataType:'json' }); }; - $('#recvs_edit_form').validate({ + $('#recvs_edit_form').validate( + { submitHandler : function(form) { var selected_supplier = autocompleter.val(); @@ -131,6 +153,9 @@ $(document).ready(function() date: { required:true, date:true + }, + invoice_number: { + invoice_number: true } }, messages: @@ -141,9 +166,11 @@ $(document).ready(function() } } }); - $('#recvs_delete_form').submit(function() { + $('#recvs_delete_form').submit(function() + { var id = $("input[name='receiving_id']").val(); - $(this).ajaxSubmit({ + $(this).ajaxSubmit( + { success:function(response) { tb_remove(); diff --git a/application/views/sales/form.php b/application/views/sales/form.php index 358436eef..7d8f659a2 100755 --- a/application/views/sales/form.php +++ b/application/views/sales/form.php @@ -76,7 +76,8 @@ $(document).ready(function() } }); - var format_item = function(row) { + 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()) { @@ -85,7 +86,8 @@ $(document).ready(function() } return result; }; - var autocompleter = $("#customer_id").autocomplete('', { + var autocompleter = $("#customer_id").autocomplete('', + { minChars:0, delay:15, max:100, @@ -95,21 +97,25 @@ $(document).ready(function() }); // declare submitHandler as an object.. will be reused - var submit_form = function(selected_customer) { - $(this).ajaxSubmit({ + var submit_form = function(selected_customer) + { + $(this).ajaxSubmit( + { success:function(response) { tb_remove(); post_form_submit(response); }, - error: function(jqXHR, textStatus, errorThrown) { + error: function(jqXHR, textStatus, errorThrown) + { selected_customer && autocompleter.val(selected_customer); post_form_submit({message: errorThrown}); }, dataType:'json' }); }; - $('#sales_edit_form').validate({ + $('#sales_edit_form').validate( + { submitHandler : function(form) { var selected_customer = autocompleter.val(); @@ -121,20 +127,23 @@ $(document).ready(function() wrapper: "li", rules: { - date: { + date: + { required:true, date:true } }, messages: { - date: { + date: + { required: "lang->line('sales_date_required'); ?>", date: "lang->line('sales_date_type'); ?>" } } }); - $('#sales_delete_form').submit(function() { + $('#sales_delete_form').submit(function() + { var id = $("input[name='sale_id']").val(); $(this).ajaxSubmit({ success:function(response)