Skip to content

Commit

Permalink
GRN Edit
Browse files Browse the repository at this point in the history
Edit GRN
  • Loading branch information
Jibigopi committed Mar 23, 2014
1 parent 5b8f457 commit 64858dc
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,60 +92,7 @@ function data_table(){

echo json_encode($output1);
}
function annan(){
$this->load->model('core_model');
$name=$this->core_model->posnic_join_like('suppliers_x_items',$_SESSION['Bid']);
for($i=0;$i<count($name);$i++){
echo $name[$i]."<br>";
}
}
function set_seleted_item_suppier($suid){
$_SESSION['supplier_guid']=$suid;
}
function get_selected_supplier()
{
$q= addslashes($_REQUEST['term']);
$where=array('company_name'=>$q);
$name=$this->posnic->posnic_like('suppliers',$where,'company_name');
$dis= $this->posnic->posnic_like('suppliers',$where,'first_name');
$id= $this->posnic->posnic_like('suppliers',$where,'guid');
$j=0;
$data=array();
for($i=0;$i<count($name);$i++)
{
$data[$j] = array(
'label' =>$name[$i] ,
'company' =>$dis[$i],
'guid'=>$id[$i]

);
$j++;
}
echo json_encode($data);

}

function get_item_details(){
$q= addslashes($_REQUEST['term']);
$like=array('code'=>$q);
$where='suppliers_x_items.item_id=items.guid AND suppliers_x_items.active = 0 AND suppliers_x_items.item_active = 0 AND suppliers_x_items.supplier_id ="'.$_SESSION['supplier_guid'].'" AND items.active_status=0 AND items.active=0 ';
$data=$this->posnic-> posnic_join_like('suppliers_x_items','items',$like,$where);
echo json_encode($data);
}

function get_item_details_for_view($iid){
if ($iid=="pos") return;
$this->load->model('grn');
$id=urldecode($iid);
$where=array('code'=>$id);
$data=$this->posnic->posnic_one_array_module_where('items',$where);
foreach ($data as $value){
echo " <table> <tr><td >Name </td><td >Cost</td><td >Price</td><td > MRF</td></tr><tr><td ><input type=text style=width:150px disabled value =$value[description] ></td><td ><input type=text value =$value[cost_price] class=items_div disabled ></td><td ><input type=text value =$value[selling_price] class=items_div disabled ></td><td ><input type=text value= $value[mrp] class=items_div disabled ></td></tr></table>";
}
}



function save(){
if($_SESSION['purchase_order_per']['add']==1){
$this->form_validation->set_rules('goods_receiving_note_guid',$this->lang->line('goods_receiving_note_guid'), 'required');
Expand All @@ -161,8 +108,8 @@ function save(){



$value=array('grn_no'=>$grn_no,'date'=>$grn_date,'po'=>$po,'remark'=>$remark,'note'=>$note);
$guid= $this->posnic->posnic_add_record($value,'grn');
$value=array('grn_no'=>$grn_no,'date'=>$grn_date,'po'=>$po,'remark'=>$remark,'note'=>$note);
$guid= $this->posnic->posnic_add_record($value,'grn');

$quty= $this->input->post('receive_quty');
$free= $this->input->post('receive_free');
Expand All @@ -189,79 +136,37 @@ function save(){

}
function update(){
if(isset($_POST['purchase_order_guid'])){

if($_SESSION['purchase_order_per']['edit']==1){
$this->form_validation->set_rules('supplier_guid',$this->lang->line('supplier_guid'), 'required');
$this->form_validation->set_rules('expiry_date',$this->lang->line('expiry_date'), 'required');
$this->form_validation->set_rules('order_number', $this->lang->line('order_number'), 'required');
$this->form_validation->set_rules('order_date', $this->lang->line('order_date'), 'required');
$this->form_validation->set_rules('grand_total', $this->lang->line('grand_total'), 'required');
$this->form_validation->set_rules('total_amount', $this->lang->line('total_amount'), 'required');

$this->form_validation->set_rules('goods_receiving_note_guid',$this->lang->line('goods_receiving_note_guid'), 'required');
$this->form_validation->set_rules('grn_date',$this->lang->line('grn_date'), 'required');
//$this->form_validation->set_rules('grn_no', $this->lang->line('grn_no'), 'required');
$this->form_validation->set_rules('receive_quty[]', 'receive_quty', 'regex_match[/^[0-9]+$/]|xss_clean');
if ( $this->form_validation->run() !== false ) {
$supplier= $this->input->post('supplier_guid');
$expdate=strtotime($this->input->post('expiry_date'));
$pono= $this->input->post('order_number');
$podate= strtotime($this->input->post('order_date'));
$discount= $this->input->post('discount');
$discount_amount= $this->input->post('discount_amount');
$freight= $this->input->post('freight');
$round_amt= $this->input->post('round_off_amount');
$total_items=$this->input->post('index');
$po= $this->input->post('goods_receiving_note_guid');
$grn_date=strtotime($this->input->post('grn_date'));
// $grn_no= $this->input->post('grn_no');
$remark= $this->input->post('remark');
$note= $this->input->post('note');
$total_amount= $this->input->post('total_amount');
$grand_total= $this->input->post('grand_total');



$value=array('supplier_id'=>$supplier,'exp_date'=>$expdate,'po_date'=>$podate,'discount'=>$discount,'discount_amt'=>$discount_amount,'freight'=>$freight,'round_amt'=>$round_amt,'total_items'=>$total_items,'total_amt'=>$grand_total,'remark'=>$remark,'note'=>$note,'order_status'=>0,'total_item_amt'=>$total_amount);
$guid= $this->input->post('purchase_order_guid');
$update_where=array('guid'=>$guid);
$this->posnic->posnic_update_record($value,$update_where,'purchase_order');
$value=array('date'=>$grn_date,'remark'=>$remark,'note'=>$note);
$guid= $this->input->post('grn_guid');
$update_where=array('guid'=>$guid);
// $this->posnic->posnic_update_record($value,$update_where,'grn');

$item= $this->input->post('items_id');
$quty= $this->input->post('items_quty');
$cost= $this->input->post('items_cost');
$free= $this->input->post('items_free');
$sell= $this->input->post('items_price');
$mrp= $this->input->post('items_mrp');
$del_date= $this->input->post('items_date');
$net= $this->input->post('items_total');
$per= $this->input->post('items_discount_per');
$dis= $this->input->post('items_discount');
$tax= $this->input->post('items_tax');
for($i=0;$i<count($item);$i++){
$quty= $this->input->post('receive_quty');
$grn_item_guid= $this->input->post('grn_items_guid');
$free= $this->input->post('receive_free');
$items= $this->input->post('items');
$po_item= $this->input->post('order_items');

for($i=0;$i<count($items);$i++){

$where=array('order_id'=>$guid,'item'=>$item[$i]);
$item_value=array('order_id'=>$guid,'discount_per'=>$per[$i],'discount_amount'=>$dis[$i],'tax'=>$tax[$i],'item'=>$item[$i],'quty'=>$quty[$i],'free'=>$free[$i],'cost'=>$cost[$i],'sell'=>$sell[$i],'mrp'=>$mrp[$i],'amount'=>$net[$i],'date'=> strtotime($del_date[$i]));
$this->posnic->posnic_update_record($item_value,$where,'purchase_order_items');


}
$delete= $this->input->post('r_items');
for($j=0;$j<count($delete);$j++){
$this->load->model('purchase');

$this->purchase->delete_order_item($delete[$j]);
}

$new_item= $this->input->post('new_item_id');
$new_quty= $this->input->post('new_item_quty');
$new_cost= $this->input->post('new_item_cost');
$new_free= $this->input->post('new_item_free');
$new_sell= $this->input->post('new_item_price');
$new_mrp= $this->input->post('new_item_mrp');
$new_del_date= $this->input->post('new_item_date');
$new_net= $this->input->post('new_item_total');
$new_per= $this->input->post('new_item_discount_per');
$new_dis= $this->input->post('new_item_discount');
$new_tax= $this->input->post('new_item_tax');
for($i=0;$i<count($new_quty);$i++){
if($new_quty[$i]!=""){
$new_item_value=array('order_id'=>$guid,'discount_per'=>$new_per[$i],'discount_amount'=>$new_dis[$i],'tax'=>$new_tax[$i],'item'=>$new_item[$i],'quty'=>$new_quty[$i],'free'=>$new_free[$i],'cost'=>$new_cost[$i],'sell'=>$new_sell[$i],'mrp'=>$new_mrp[$i],'amount'=>$new_net[$i],'date'=> strtotime($new_del_date[$i]));
$this->posnic->posnic_add_record($new_item_value,'purchase_order_items');
}

$this->load->model('grn');
$this->grn->update_grn_items_quty($grn_item_guid[$i],$quty[$i],$free[$i],$items[$i],$po_item[$i]);
//$this->grn->add_stock($items[$i],$quty[$i]+$free[$i],$po_item[$i],$_SESSION['Bid']);
}


Expand All @@ -274,10 +179,8 @@ function update(){
}else{
echo 'Noop';
}
}


}

}


function convert_date($date){
Expand Down
42 changes: 41 additions & 1 deletion application/modules/goods_receiving_note/models/grn.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function get_purchase_order($guid){
return $data;
}
function get_goods_receiving_note($guid){
$this->db->select('grn.date as grn_date,grn.note as grn_note,grn.remark as grn_remark,grn.grn_no,grn_x_items.quty as rece_quty,grn_x_items.free as rece_free,items.tax_Inclusive ,grn.po,tax_types.type as tax_type_name,taxes.value as tax_value,taxes.type as tax_type,suppliers_x_items.quty as item_limit,suppliers.guid as s_guid,suppliers.first_name as s_name,suppliers.company_name as c_name,suppliers.address1 as address,purchase_order.*,purchase_order_items.discount_per as dis_per ,purchase_order_items.discount_amount as item_dis_amt ,purchase_order_items.tax as dis_amt ,purchase_order_items.tax as order_tax,purchase_order_items.item ,purchase_order_items.quty ,purchase_order_items.free,purchase_order_items.guid as o_i_guid ,purchase_order_items.received_quty ,purchase_order_items.received_free ,purchase_order_items.cost ,purchase_order_items.sell ,purchase_order_items.mrp,purchase_order_items.guid as o_i_guid ,purchase_order_items.amount ,purchase_order_items.date,items.guid as i_guid,items.name as items_name,items.code as i_code')->from('grn')->where('grn.guid',$guid)->where('grn.active',0);
$this->db->select('grn.date as grn_date,grn.note as grn_note,grn.remark as grn_remark,grn.grn_no,grn_x_items.guid as grn_items_guid,grn_x_items.quty as rece_quty,grn_x_items.free as rece_free,items.tax_Inclusive ,grn.po,tax_types.type as tax_type_name,taxes.value as tax_value,taxes.type as tax_type,suppliers_x_items.quty as item_limit,suppliers.guid as s_guid,suppliers.first_name as s_name,suppliers.company_name as c_name,suppliers.address1 as address,purchase_order.*,purchase_order_items.discount_per as dis_per ,purchase_order_items.discount_amount as item_dis_amt ,purchase_order_items.tax as dis_amt ,purchase_order_items.tax as order_tax,purchase_order_items.item ,purchase_order_items.quty ,purchase_order_items.free,purchase_order_items.guid as o_i_guid ,purchase_order_items.received_quty ,purchase_order_items.received_free ,purchase_order_items.cost ,purchase_order_items.sell ,purchase_order_items.mrp,purchase_order_items.guid as o_i_guid ,purchase_order_items.amount ,purchase_order_items.date,items.guid as i_guid,items.name as items_name,items.code as i_code')->from('grn')->where('grn.guid',$guid)->where('grn.active',0);
$this->db->join('purchase_order', 'grn.po=purchase_order.guid','left');
$this->db->join('grn_x_items', 'grn_x_items.grn=grn.guid','left');
$this->db->join('purchase_order_items', 'purchase_order_items.order_id = purchase_order.guid AND grn_x_items.item=purchase_order_items.item AND purchase_order_items.delete_status=0','left');
Expand Down Expand Up @@ -240,6 +240,46 @@ function add_stock($items,$quty,$po_item,$Bid){
$this->db->update('stock',array('guid'=> md5('stock'.$items.$id)));
}
}
function update_grn_items_quty($guid,$quty,$free,$items,$po_item){
$this->db->select()->from('grn_x_items')->where('guid',$guid);
$sql= $this->db->get();

$old_quty;
$old_free;
$oquty;
$ofree;
$rquty;
$rree;
foreach ($sql->result() as $row){
$old_free=$row->free;
$old_quty=$row->quty;
}

$this->db->select()->from('purchase_order_items')->where('guid',$po_item);
$po= $this->db->get();
foreach ($po->result() as $prow){
$ofree=$prow->free;
$oquty=$prow->quty;
$rfree=$prow->received_free;
$rquty=$prow->received_quty;
}
$old_received_quty=$rquty-$old_quty;

$old_received_free=$rfree-$old_free;
$current_quty=$quty+$old_received_quty;
$current_free=$free+$old_received_free;
if($current_quty>$oquty){
echo $quty=$oquty-$old_received_quty;
}
if($current_free>$ofree){
echo $free=$ofree-$old_received_free;
}
$this->db->where('guid',$guid);
$this->db->update('grn_x_items',array('quty'=>$quty,'free'=>$free));
$this->db->where('guid',$po_item);
$this->db->update('purchase_order_items',array('received_quty'=>$old_received_quty+$quty,'received_free'=>$free+$old_received_free));

}

}
?>
17 changes: 10 additions & 7 deletions application/modules/goods_receiving_note/views/header/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,23 @@ function edit_function(guid){
$('#demo_grand_total').val(num.toFixed(point));

$("#parsley_reg #supplier_guid").val(data[0]['s_guid']);
$("#parsley_reg #grn_guid").val(guid);
var tax;
var receive=0;
for(i=0;i<data.length;i++){

receive=1;
var name=data[i]['items_name'];
var rece_quty=data[i]['rece_quty'];
var rece_free=data[i]['rece_quty'];
var rece_free=data[i]['rece_free'];
var sku=data[i]['i_code'];
var quty=data[i]['quty'];
var quty=parseFloat(data[i]['quty']);
var limit=data[i]['item_limit'];
var tax_type=data[i]['tax_type_name'];
var tax_value=data[i]['tax_value'];
var tax_Inclusive=data[i]['tax_Inclusive'];

var free=data[i]['free'];
var free=parseFloat(data[i]['free']);
var received_quty=data[i]['received_quty'];
var received_free=data[i]['received_free'];

Expand Down Expand Up @@ -309,9 +310,11 @@ function edit_function(guid){
var num = parseFloat(total);
total=num.toFixed(point);
}
var grn_received_quty=parseFloat(received_quty-rece_quty);
console.log(grn_received_quty);
var grn_received_free=parseFloat(received_quty-rece_free);
var grn_received_quty=parseFloat(received_quty)-parseFloat(rece_quty);

var grn_received_free=parseFloat(received_free)-parseFloat(rece_free);
console.log(grn_received_free);
console.log(free);
var addId = $('#selected_item_table').dataTable().fnAddData( [
null,
name,
Expand All @@ -323,7 +326,7 @@ function edit_function(guid){
received_quty,
free,
received_free,
"<input type='hidden' id='grn_old_quantity_"+i+"' value='"+rece_quty+"' ><input type='hidden' name='items[]' value='"+data[i]['item']+"' ><input type='hidden' id='o_quty_id_"+i+"' value='"+parseFloat(quty-grn_received_quty)+"' ><input type='text' id='r_quty_id_"+i+"' name='receive_quty[]' value='"+rece_quty+"' onkeyup='receive_quty_items_update("+i+")' onKeyPress='receive_quty(event,"+i+");return numbersonly(event)' class='form-control' style='width:100px'>",
"<input type='hidden' name='grn_items_guid[]' value='"+data[i]['grn_items_guid']+"' ><input type='hidden' id='grn_old_quantity_"+i+"' value='"+rece_quty+"' ><input type='hidden' name='items[]' value='"+data[i]['item']+"' ><input type='hidden' id='o_quty_id_"+i+"' value='"+parseFloat(quty-grn_received_quty)+"' ><input type='text' id='r_quty_id_"+i+"' name='receive_quty[]' value='"+rece_quty+"' onkeyup='receive_quty_items_update("+i+")' onKeyPress='receive_quty(event,"+i+");return numbersonly(event)' class='form-control' style='width:100px'>",
"<input type='hidden' id='grn_old_free_"+i+"' value='"+rece_free+"' ><input type='hidden' name='order_items[]' value='"+data[i]['o_i_guid']+"' ><input type='hidden' id='o_free_id_"+i+"' value='"+parseFloat(free-grn_received_free)+"' ><input type='text' id='r_free_id_"+i+"' name='receive_free[]' value='"+rece_free+"' onkeyup='receive_free_items_update("+i+")' onKeyPress='receive_free(event,"+i+","+data.length+");return numbersonly(event)' class='form-control' style='width:90px'>",


Expand Down
3 changes: 2 additions & 1 deletion application/modules/goods_receiving_note/views/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function receive_free_items_update(i)
var old= $('#parsley_reg #grn_old_free_'+i).val();
if(parseFloat(good)>parseFloat(res)){
$('#parsley_reg #r_free_id_'+i).val(res);

}
}
}
Expand Down Expand Up @@ -757,6 +757,7 @@ function reload_update_user(){

<input type="hidden" name="dummy_discount" id="dummy_discount" >
<input type="hidden" name="dummy_discount_amount" id="dummy_discount_amount" >
<input type="text" name="grn_guid" id="grn_guid" >
<div class="row">
<div class="panel panel-default">
<div class="panel-heading" >
Expand Down
Loading

0 comments on commit 64858dc

Please sign in to comment.