Add edit form in detailed receivings report

Add language lines for detailed sale & receiving validation
Add permission for getting updated sale & receiving detail row
This commit is contained in:
jekkos-t520
2014-10-21 21:39:22 +02:00
parent 08dcd9e384
commit fe6820920b
12 changed files with 363 additions and 20 deletions

View File

@@ -612,10 +612,15 @@ class Items extends Secure_area implements iData_controller
return 360;
}
function is_sale_store_item($item_number)
{
echo $this->Item->is_sale_store_item_exist($item_number);
}
function item_number_check($item_number)
{
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'));
}
}
?>

View File

@@ -111,12 +111,52 @@ class Receivings extends Secure_area
$this->_reload($data);
}
function edit($receiving_id)
{
$data = array();
$data['suppliers'] = array('' => 'No Supplier');
foreach ($this->Supplier->get_all()->result() as $supplier)
{
$data['suppliers'][$supplier->person_id] = $supplier->first_name . ' ' . $supplier->last_name;
}
$data['employees'] = array();
foreach ($this->Employee->get_all()->result() as $employee)
{
$data['employees'][$employee->person_id] = $employee->first_name . ' '. $employee->last_name;
}
$receiving_info = $this->Receiving->get_info($receiving_id)->row_array();
$person_name = $receiving_info['first_name'] . " " . $receiving_info['last_name'];
$data['selected_supplier'] = !empty($receiving_info['supplier_id']) ? $receiving_info['supplier_id'] . "|" . $person_name : "";
$data['receiving_info'] = $receiving_info;
$this->load->view('receivings/form', $data);
}
function delete_item($item_number)
{
$this->receiving_lib->delete_item($item_number);
$this->_reload();
}
function delete($receiving_id = -1, $update_inventory=TRUE)
{
$employee_id=$this->Employee->get_logged_in_employee_info()->person_id;
$receiving_ids=$receiving_id == -1 ? $this->input->post('ids') : array($receiving_id);
if($this->Receiving->delete_list($receiving_ids, $employee_id, $update_inventory))
{
echo json_encode(array('success'=>true,'message'=>$this->lang->line('recvs_delete_successful').' '.
count($receiving_ids).' '.$this->lang->line('recvs_one_or_multiple'),'ids'=>$receiving_ids));
}
else
{
echo json_encode(array('success'=>false,'message'=>$this->lang->line('recvs_delete_unsuccessful')));
}
}
function delete_supplier()
{
@@ -282,6 +322,34 @@ class Receivings extends Secure_area
$this->load->view("receivings/receiving",$data);
$this->_remove_duplicate_cookies();
}
function save($receiving_id)
{
$receiving_data = array(
'receiving_time' => date('Y-m-d', strtotime($this->input->post('date'))),
'supplier_id' => $this->input->post('supplier_id') ? $this->input->post('supplier_id') : null,
'employee_id' => $this->input->post('employee_id'),
'comment' => $this->input->post('comment'),
'invoice_number' => $this->input->post('invoice_number')
);
if ($this->Receiving->update($receiving_data, $receiving_id))
{
echo json_encode(array(
'success'=>true,
'message'=>$this->lang->line('recvs_successfully_updated'),
'id'=>$receiving_id)
);
}
else
{
echo json_encode(array(
'success'=>false,
'message'=>$this->lang->line('recvs_unsuccessfully_updated'),
'id'=>$receiving_id)
);
}
}
function cancel_receiving()
{

View File

@@ -12,7 +12,7 @@ class Reports extends Secure_area
parent::__construct('reports');
$method_name = $this->uri->segment(2);
$exploder = explode('_', $method_name);
preg_match("/(?:inventory)|([^_.]*)(?:_graph)?$/", $method_name, $matches);
preg_match("/(?:inventory)|([^_.]*)(?:_graph|_row)?$/", $method_name, $matches);
preg_match("/^(.*?)([sy])?$/", array_pop($matches), $matches);
$submodule_id = $matches[1] . ((count($matches) > 2) ? $matches[2] : "s");
$employee_id=$this->Employee->get_logged_in_employee_info()->person_id;
@@ -72,7 +72,28 @@ class Reports extends Secure_area
to_currency($report_data['profit']),
$report_data['payment_type'],
$report_data['comment']);
echo get_detailed_sales_data_row($summary_data, $this);
echo get_detailed_data_row($summary_data, $this);
}
function get_detailed_receivings_row($receiving_id, $receiving_type=1)
{
$this->load->model('reports/Detailed_receivings');
$model = $this->Detailed_receivings;
$report_data = $model->getDataByReceivingId($receiving_id, $receiving_type);
$summary_data = array(anchor('receivings/edit/'.$report_data['receiving_id'] . '/width:'.FORM_WIDTH,
'RECV '.$report_data['receiving_id'],
array('class' => 'thickbox')),
$report_data['receiving_date'],
$report_data['items_purchased'],
$report_data['employee_name'],
$report_data['supplier_name'],
to_currency($report_data['total']),
$report_data['payment_type'],
$report_data['invoice_number'],
$report_data['comment']);
echo get_detailed_data_row($summary_data, $this);
}
function get_summary_data($start_date, $end_date = NULL, $sale_type=0)
@@ -845,7 +866,7 @@ class Reports extends Secure_area
"title" =>$this->lang->line('reports_detailed_sales_report'),
"subtitle" => date('m/d/Y', strtotime($start_date)) .'-'.date('m/d/Y', strtotime($end_date)),
"headers" => $model->getDataColumns(),
"editable" => true,
"editable" => "sales",
"summary_data" => $summary_data,
"details_data" => $details_data,
"header_width" => intval(100 / count($headers['summary'])),
@@ -862,14 +883,14 @@ class Reports extends Secure_area
$model = $this->Detailed_receivings;
$headers = $model->getDataColumns();
$report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'receiving_type' => $receiving_type));
$report_data = $model->getData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'receiving_type'=>$receiving_type));
$summary_data = array();
$details_data = array();
foreach($report_data['summary'] as $key=>$row)
{
$summary_data[] = array(anchor('receivings/receipt/'.$row['receiving_id'], 'RECV '.$row['receiving_id'], array('target' => '_blank')), $row['receiving_date'], $row['items_purchased'], $row['employee_name'], $row['supplier_name'], to_currency($row['total']), $row['payment_type'], $row['invoice_number'], $row['comment']);
$summary_data[] = array(anchor('receivings/edit/'.$row['receiving_id'].'/width:'.FORM_WIDTH, 'RECV '.$row['receiving_id'], array('class' => 'thickbox')), $row['receiving_date'], $row['items_purchased'], $row['employee_name'], $row['supplier_name'], to_currency($row['total']), $row['payment_type'], $row['invoice_number'], $row['comment']);
foreach($report_data['details'][$key] as $drow)
{
@@ -881,6 +902,7 @@ class Reports extends Secure_area
"title" =>$this->lang->line('reports_detailed_receivings_report'),
"subtitle" => date('m/d/Y', strtotime($start_date)) .'-'.date('m/d/Y', strtotime($end_date)),
"headers" => $model->getDataColumns(),
"editable" => "receivings",
"summary_data" => $summary_data,
"details_data" => $details_data,
"overall_summary_data" => $model->getSummaryData(array('start_date'=>$start_date, 'end_date'=>$end_date, 'receiving_type' => $receiving_type)),

View File

@@ -64,11 +64,11 @@ function get_person_data_row($person,$controller)
return $table_data_row;
}
function get_detailed_sales_data_row($sale, $controller)
function get_detailed_data_row($row, $controller)
{
$table_data_row='<tr>';
$table_data_row.='<td><a href="#" class="expand">+</a></td>';
foreach($sale as $cell)
foreach($row as $cell)
{
$table_data_row.='<td>';
$table_data_row.=$cell;

View File

@@ -39,4 +39,19 @@ $lang['recvs_stock_destination']='Stock destination';
$lang['recvs_stock_locaiton']='Stock location';
$lang['recvs_error_requisition']='Unable to move inventory from and to the same stock location';
$lang['recvs_invoice_number']='Invoice #';
$lang['recvs_receipt_number']='Receiving #';
$lang['recvs_date'] = 'Receiving Date';
$lang['recvs_successfully_updated'] = 'Receiving successfully updated';
$lang['recvs_unsuccessfully_updated'] = 'Receiving unsuccessfully updated';
$lang['recvs_edit_sale'] = 'Edit Receiving';
$lang['recvs_successfully_deleted'] = 'Receiving successfully deleted';
$lang['recvs_unsuccessfully_deleted'] = 'Receiving unsuccessfully deleted';
$lang['recvs_delete_entire_sale'] = 'Delete entire sale';
$lang['recvs_comments'] = 'Comments';
$lang['recvs_basic_information']='Receiving information';
$lang['recvs_employee']='Employee';
$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';
?>

View File

@@ -86,4 +86,7 @@ $lang['sales_basic_information']='Sale information';
$lang['sales_stock_location']='Stock location';
$lang['sales_sale']='Sale';
$lang['sales_receipt_number']='Sale #';
$lang['sales_date_required']='A correct date needs to be filled in';
$lang['sales_date_type']='Date field is required';
?>

View File

@@ -4,6 +4,7 @@ class Receiving extends CI_Model
function get_info($receiving_id)
{
$this->db->from('receivings');
$this->db->join('people', 'people.person_id = receivings.supplier_id', 'LEFT');
$this->db->where('receiving_id',$receiving_id);
return $this->db->get();
}
@@ -30,6 +31,14 @@ class Receiving extends CI_Model
return ($query->num_rows()==1);
}
function update($receiving_data, $receiving_id)
{
$this->db->where('receiving_id', $receiving_id);
$success = $this->db->update('receivings',$receiving_data);
return $success;
}
function save ($items,$supplier_id,$employee_id,$comment,$payment_type,$receiving_id=false,$invoice_number=null)
{
@@ -102,6 +111,48 @@ class Receiving extends CI_Model
return $receiving_id;
}
function delete_list($receiving_ids,$employee_id,$update_inventory=TRUE)
{
$result = TRUE;
foreach($receiving_ids as $receiving_id) {
$result &= $this->delete($receiving_id,$employee_id,$update_inventory);
}
return $result;
}
function delete($receiving_id,$employee_id,$update_inventory=TRUE)
{
// start a transaction to assure data integrity
$this->db->trans_start();
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_receiving_items($receiving_id)->result_array();
foreach($items as $item) {
// 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 ' . $receiving_id,
'trans_inventory'=>$item['quantity_purchased']
);
// update inventory
$this->Inventory->insert($inv_data);
}
}
// delete all items
$this->db->delete('receivings_items', array('receiving_id' => $receiving_id));
// delete sale itself
$this->db->delete('receivings', array('receiving_id' => $receiving_id));
// execute transaction
$this->db->trans_complete();
return $this->db->trans_status();
}
function get_receiving_items($receiving_id)
{

View File

@@ -14,6 +14,16 @@ class Detailed_receivings extends Report
);
}
public function getDataByReceivingId($receiving_id, $sale_type)
{
$this->db->select('receiving_id, DATE_FORMAT(receiving_date, "%d-%m-%Y") AS receiving_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, suppliers.company_name as supplier_name, sum(subtotal) as subtotal, sum(total) as total, sum(profit) as profit, payment_type, comment, invoice_number', false);
$this->db->from('receivings_items_temp');
$this->db->join('people as employee', 'receivings_items_temp.employee_id = employee.person_id');
$this->db->join('suppliers as suppliers', 'receivings_items_temp.supplier_id = suppliers.person_id', 'left');
$this->db->where('receiving_id', $receiving_id);
return $this->db->get()->row_array();
}
public function getData(array $inputs)
{
$this->db->select('receiving_id, receiving_date, sum(quantity_purchased) as items_purchased, CONCAT(employee.first_name," ",employee.last_name) as employee_name, CONCAT(supplier.first_name," ",supplier.last_name) as supplier_name, sum(total) as total, sum(profit) as profit, payment_type, comment, invoice_number', false);

View File

@@ -3,8 +3,6 @@ class Sale extends CI_Model
{
public function get_info($sale_id)
{
$this->db->select('sales.*', FALSE);
$this->db->select('people.*', FALSE);
$this->db->from('sales');
$this->db->join('people', 'people.person_id = sales.customer_id', 'LEFT');
$this->db->where('sale_id',$sale_id);
@@ -142,7 +140,8 @@ class Sale extends CI_Model
return $sale_id;
}
function delete_list($sale_ids, $employee_id,$update_inventory=TRUE) {
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);
@@ -150,7 +149,8 @@ class Sale extends CI_Model
return $result;
}
function delete($sale_id,$employee_id,$update_inventory=TRUE) {
function delete($sale_id,$employee_id,$update_inventory=TRUE)
{
// start a transaction to assure data integrity
$this->db->trans_start();
// first delete all payments

View File

@@ -0,0 +1,169 @@
<div id="edit_sale_wrapper">
<div id="required_fields_message"><?php echo $this->lang->line('common_fields_required_message'); ?></div>
<ul id="error_message_box"></ul>
<fieldset id="receiving_basic_info">
<?php echo form_open("receivings/save/".$receiving_info['receiving_id'],array('id'=>'recvs_edit_form')); ?>
<legend><?php echo $this->lang->line("recvs_basic_information"); ?></legend>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('recvs_receipt_number').':', 'supplier'); ?>
<div class='form_field'>
<?php echo anchor('receivings/receipt/'.$receiving_info['receiving_id'], $this->lang->line('recvs_receipt_number') .$receiving_info['receiving_id'], array('target' => '_blank'));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('recvs_date').':', 'date', array('class'=>'required')); ?>
<div class='form_field'>
<?php echo form_input(array('name'=>'date','value'=>date('m/d/Y', strtotime($receiving_info['receiving_time'])), 'id'=>'date'));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('recvs_supplier').':', 'supplier'); ?>
<div class='form_field'>
<?php echo form_input(array('name' => 'supplier_id', 'value' => $selected_supplier, 'id' => 'supplier_id'));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('recvs_invoice_number').':', 'invoice_number'); ?>
<div class='form_field'>
<?php echo form_input(array('name' => 'invoice_number', 'value' => $receiving_info['invoice_number'], 'id' => 'invoice_number'));?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('recvs_employee').':', 'employee'); ?>
<div class='form_field'>
<?php echo form_dropdown('employee_id', $employees, $receiving_info['employee_id'], 'id="employee_id"');?>
</div>
</div>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('recvs_comments').':', 'comment'); ?>
<div class='form_field'>
<?php echo form_textarea(array('name'=>'comment','value'=>$receiving_info['comment'],'rows'=>'4','cols'=>'23', 'id'=>'comment'));?>
</div>
</div>
<?php
echo form_submit(array(
'name'=>'submit',
'value'=>$this->lang->line('common_submit'),
'class'=> 'submit_button float_right')
);
?>
</form>
<?php echo form_open("receivings/delete/".$receiving_info['receiving_id'],array('id'=>'recvs_delete_form')); ?>
<?php echo form_hidden('receiving_id', $receiving_info['receiving_id']);?>
<?php
echo form_submit(array(
'name'=>'submit',
'value'=>$this->lang->line('recvs_delete_entire_sale'),
'class'=>'delete_button float_right')
);
?>
</form>
</fieldset>
</div>
<script type="text/javascript" language="javascript">
$(document).ready(function()
{
$('#date').datePicker({startDate: '<?php echo date("%Y/%M/%d");?>'});
$("#recvs_delete_form").submit(function()
{
if (!confirm('<?php echo $this->lang->line("recvs_delete_confirmation"); ?>'))
{
return false;
}
});
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 = $("#supplier_id").autocomplete('<?php echo site_url("receivings/supplier_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_supplier) {
$(this).ajaxSubmit({
success:function(response)
{
tb_remove();
post_form_submit(response);
},
error: function(jqXHR, textStatus, errorThrown) {
selected_customer && autocompleter.val(selected_supplier);
post_form_submit({message: errorThrown});
},
dataType:'json'
});
};
$('#recvs_edit_form').validate({
submitHandler : function(form)
{
var selected_supplier = autocompleter.val();
var selected_supplier_id = selected_supplier.replace(/(\w)\|.*/, "$1");
selected_supplier_id && autocompleter.val(selected_supplier_id);
submit_form.call(form, selected_supplier);
},
errorLabelContainer: "#error_message_box",
wrapper: "li",
rules:
{
date: {
required:true,
date:true
}
},
messages:
{
date: {
required: "<?= $this->lang->line('recvs_date_required'); ?>",
date: "<?= $this->lang->line('recvs_date_type'); ?>"
}
}
});
$('#recvs_delete_form').submit(function() {
var id = $("input[name='receiving_id']").val();
$(this).ajaxSubmit({
success:function(response)
{
tb_remove();
set_feedback(response.message,'success_message',false);
var $element = get_table_row(id).parent().parent();
$element.find("td").animate({backgroundColor:"green"},1200,"linear")
.end().animate({opacity:0},1200,"linear",function()
{
$element.next().remove();
$(this).remove();
//Re-init sortable table as we removed a row
update_sortable_table();
});
},
error: function(jqXHR, textStatus, errorThrown) {
set_feedback(textStatus,'error_message',true);
},
dataType:'json'
});
return false;
});
});
</script>

View File

@@ -94,14 +94,14 @@ function post_form_submit(response, row_id)
}
else
{
var sale_id = response.id
$.get('<?php echo site_url("reports/get_detailed_sales_row")?>/'+sale_id, function(response)
var row_id = response.id
$.get('<?php echo site_url("reports/get_detailed_" . $editable . "_row")?>/'+row_id, function(response)
{
//Replace previous row
var row = get_table_row(sale_id).parent().parent();
var row = get_table_row(row_id).parent().parent();
var sign = row.find("a.expand").text();
row.replaceWith(response);
row = get_table_row(sale_id).parent().parent();
row = get_table_row(row_id).parent().parent();
update_sortable_table();
animate_row(row);
row.find("a.expand").click(expand_handler).text(sign);

View File

@@ -7,7 +7,7 @@
<legend><?php echo $this->lang->line("sales_basic_information"); ?></legend>
<div class="field_row clearfix">
<?php echo form_label($this->lang->line('sales_receipt').':', 'customer'); ?>
<?php echo form_label($this->lang->line('sales_receipt_number').':', 'customer'); ?>
<div class='form_field'>
<?php echo anchor('sales/receipt/'.$sale_info['sale_id'], $this->lang->line('sales_receipt_number') .$sale_info['sale_id'], array('target' => '_blank'));?>
</div>