/
home
/
sjslayjy
/
public_html
/
assets
/
app
/
Http
/
Controllers
/
Upload File
HOME
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\HistoryOfStockInCircleStore; use App\LocalUserMapping; use App\Indent; use App\IndentItem; use App\StockTransferOrder; use App\StockTransferOrderItem; use App\StockTransferNote; use App\SparePartsInStock; use App\StockInCircleStore; use App\StockTransferReceipt; use App\StnItem; use App\WareHouse; use App\User; use Auth; use DB; class IndentController extends Controller { public $data; public function get_common(){ if(Auth::check()){ $user = Auth::user(); $this->data['userInfo'] = LocalUserMapping::where('LoginID',$user->loginId)->first(); } } public function get_spare_part_from_pant(Request $request){ $code = $request->code; $is_spare_part = DB::table('stock_in_circle_stores')->where('warehouse','SERPNT')->where('spare_code',$code)->count(); if($is_spare_part > 0){ $spare_part = DB::table('spare_parts_masters')->where('code',$code)->first(); return json_encode(['success'=>true,'spare_part'=>$spare_part]); }else{ return json_encode(['success'=>false,'msg'=> 'Spare Not at Plant Stock']); } } public function admin_request_indent_page($loginId){ $this->get_common(); $userInfo = LocalUserMapping::where('LoginID',$loginId)->first(); $user = User::where('loginId',$loginId)->first(); $fieldUserCodes = $userInfo->fieldUserCodes; $ware_house = 'SER'.$fieldUserCodes; $customers = DB::table('customer_circle_list')->where('Circle',$fieldUserCodes)->get(); $this->data = array_merge($this->data,['customers'=>$customers,'user_id'=>$user->id,'ware_house'=>$ware_house]); return view('admin.indent.place-indent',$this->data); } public function get_authorised_indents_page(){ $this->get_common(); $indents = DB::table('indents')->select('indents.*','users.name','local_user_mapping.StaffName as authorised_by_name')->join('users','users.id','indents.indent_placed_by')->join('local_user_mapping','local_user_mapping.LoginID','indents.authorised_by')->where('indents.status','authorized')->orWhere('indents.status','short_closed')->orderBy('indents.id','DESC')->get(); $this->data = array_merge($this->data,['indents'=>$indents]); return view('admin.indent.authorised-indents',$this->data); } public function get_requested_indents_page(){ $this->get_common(); $indents = DB::table('indents')->select('indents.*','users.name')->join('users','users.id','indents.indent_placed_by')->where('indents.status','request')->orderBy('indents.id','DESC')->get(); $this->data = array_merge($this->data,['indents'=>$indents]); return view('admin.indent.requestIndents',$this->data); } public function get_requested_indent_information_page($indent_id){ $this->get_common(); $indent = Indent::find($indent_id); if($indent != null){ if($indent->status == 'request'){ $this->data = array_merge($this->data,['indent'=>$indent]); return view('admin.indent.viewIndent',$this->data); }else{ return redirect('admin/requested-indents')->with('error','Indent already authorized!!'); } }else{ return redirect('admin/requested-indents')->with('error','Invalid Indent Number !!'); } } public function get_view_authorised_indent($indent_id){ $this->get_common(); $indent = Indent::find($indent_id); if($indent != null){ $this->data = array_merge($this->data,['indent'=>$indent]); return view('admin.indent.view-authorised-indent',$this->data); }else{ return redirect('admin/authorised-indents')->with('error','Invalid Indent Number !!'); } } public function admin_generate_sto($indent_id){ $this->get_common(); $indent = Indent::find($indent_id); if($indent != null){ $this->data = array_merge($this->data,['indent'=>$indent]); return view('admin.indent.generate-sto',$this->data); }else{ return redirect('admin/authorised-indents')->with('error','Invalid Indent Number !!'); } } public function generate_sto_now(Request $request){ $indent = Indent::where('id',$request->indent_id)->where('status','authorized')->first(); $loginId = Auth::user()->loginId; $userInfo = LocalUserMapping::where('LoginID',$loginId)->first(); $fieldUserCodes = $userInfo->fieldUserCodes; if($indent->business_type != 'PT'){ $warehouse = "SERPNT"; }else{ $warehouse = "SUPPNT"; } if($indent != ""){ $is_valid = true; $sp = ""; foreach ($request->indentItems as $val) { $ms = StockInCircleStore::where('spare_code',$val['code'])->where('warehouse',$warehouse)->first(); if($ms != null){ if($ms->fresh_qty < $val['final_qty']){ $is_valid = false; $sp = $val['code'].' Fresh'; break; } if($ms->repaired_qty < $val['rqty']){ $is_valid = false; $sp = $val['code'].' Repaired'; break; } }else{ $is_valid = false; $sp = $val['code']; break; } } if($is_valid == true){ $f_date = date('Y').'-03-31'; $curr_date = date('Y-m-d'); if (strtotime($curr_date) <= strtotime($f_date)) { $session = (date('y')-1).date('y'); } else { $session = date('y').(date('y')+1); } $last_value = StockTransferOrder::where('session',$session)->orderBy('id','desc')->first(); if($last_value != null){ $no = $last_value->series + 1; //$session = $last_value->session; }else{ $no = 1; //$session = date('y').date('y')+1; } $sto = new StockTransferOrder(); $sto->series = $no; $sto->sto_number = 'STO/'.$fieldUserCodes.'/00'.$no.'/'.$session; $sto->sto_date = date('Y-m-d'); $sto->session = $session; $sto->indent_no = $indent->indent_no; $sto->indent_id = $indent->id; $sto->authorise_by = $loginId; $sto->indent_by = $indent->indent_placed_by; $sto->status = 'stn'; if($sto->save()){ foreach ($request->indentItems as $value){ $stoitem = new StockTransferOrderItem(); $stoitem->sto_id = $sto->id; $stoitem->indent_id = $request->indent_id; $stoitem->spare_code = $value['code']; $stoitem->final_qty = $value['final_qty']; $stoitem->repaired_qty = $value['rqty']; $stoitem->final_rate = $value['rate']; $stoitem->gst = $value['gst_slab_rates']; $stoitem->save(); $indentItem = IndentItem::where('indent_id',$request->indent_id)->where('spare_code',$value['code'])->first(); $indentItem->sto_qty = $indentItem->sto_qty + ($value['final_qty']+$value['rqty']); $indentItem->save(); } } return json_encode(['success'=> true, 'msg'=>'STO Generated Successfully !!']); }else{ return json_encode(['success'=> false, 'msg'=> $sp.' Qty not in Plant Stock.']); } }else{ return json_encode(['success'=> false, 'msg'=>'Indent Not authorized yet !!']); } } public function short_close_indent(Request $request){ $indent_id = $request->indent_id; $indent = Indent::find($indent_id); if($indent != null){ $indent->status = 'short_closed'; $indent->save(); return json_encode(['success'=> true, 'msg'=>'Indent Has Short Closed Successfully !!']); }else{ return json_encode(['success'=> false, 'msg'=>'Sonthing went worng']); } } public function get_my_requested_indents_page(){ $this->get_common(); $user_id = Auth::user()->id; $indents = DB::table('indents')->select('indents.*','users.name')->join('users','users.id','indents.indent_placed_by')->where('indents.indent_placed_by',$user_id)->orderBy('id','DESC')->get(); $this->data = array_merge($this->data,['indents'=>$indents]); return view('circle-store.indent.requestedIndents',$this->data); } public function get_request_indent_admin(){ $this->get_common(); $loginId = Auth::user()->loginId; $assigned_warehouses = DB::table('local_user_mapping') ->select('local_user_mapping.warehouseCode') ->where('LoginID', $loginId) ->first(); $warehouses = explode(',', $assigned_warehouses->warehouseCode); //$ware_houses = DB::table('ware_houses')->whereIn('ware_house', $warehouses)->get(); $this->data = array_merge($this->data,['ware_houses'=>$warehouses]); return view('admin.indent.place-indent',$this->data); } public function get_po_customer(Request $request){ $fieldUserCodes = substr($request->ware_house, 3); $customers = DB::table('customer_circle_list')->where('Circle',$fieldUserCodes)->get(); return json_encode(['success'=> true , 'customers'=>$customers,'fieldUserCodes'=>$fieldUserCodes]); } public function get_request_indent_page(){ $this->get_common(); $userInfo = $this->data['userInfo']; $circleCodes = $userInfo->circleCodes; $loginId = $userInfo->LoginID; $assigned_warehouses = DB::table('local_user_mapping') ->select('local_user_mapping.warehouseCode') ->where('LoginID', $loginId) ->first(); $warehouses = explode(',', $assigned_warehouses->warehouseCode); $current_warehouse = $warehouses[0]; $customers = DB::table('customer_circle_list')->where('Circle',$circleCodes)->get(); $this->data = array_merge($this->data,['customers'=>$customers,'assigned_warehouses'=>$warehouses,'current_warehouse'=> $current_warehouse]); return view('circle-store.indent.request-indent',$this->data); } public function place_indent(Request $request){ $item_count = count($request->items); if($item_count > 0){ $user_id = Auth::user()->id ; $f_date = date('Y').'-03-31'; $curr_date = date('Y-m-d'); if (strtotime($curr_date) <= strtotime($f_date)) { $session = (date('y')-1).date('y'); } else { $session = date('y').(date('y')+1); } $last_indent = Indent::where('ware_house',$request->ware_house)->where('business_type',$request->business_type)->where('session',$session)->orderBy('id','desc')->first(); if($last_indent != null){ $no = $last_indent->series + 1 ; //$session = $last_indent->session; }else{ $no = 1 ; //$session = date('y').date('y')+1; } $indent = new Indent(); $indent->series = $no; $indent->indent_no = strtoupper($request->business_type).'/'.substr($request->ware_house,3).'/IND/00'.$no.'/'.$session; $indent->session = $session; $indent->indent_date = $request->indent_date; $indent->status = 'request'; $indent->indent_placed_by = $user_id; $indent->ware_house = $request->ware_house; if($request->customer_code_and_name != ""){ $cust_code_name = explode('--', $request->customer_code_and_name); $indent->customer_code = $cust_code_name[0]; $indent->customer_name = $cust_code_name[1]; } $indent->customer_po = $request->customer_po; $indent->cutomer_po_date = $request->cutomer_po_date; $indent->business_type = $request->business_type; $indent->remarks = $request->remarks; if($indent->save()){ foreach ($request->items as $key => $value) { $qty = $value['qty']; $indentItem = new IndentItem(); $indentItem->indent_id = $indent->id; $indentItem->spare_code = $value['code']; $indentItem->qty = $qty; $indentItem->save(); } return json_encode(['success'=>true,'msg'=>'Indent has been placed Successfully !!']); }else{ return json_encode(['success'=>false,'msg'=>'Somthing went wrong !!']); } }else{ return json_encode(['success'=>false,'msg'=>'Somthing went wrong !!']); } } public function get_requested_indent_page($indent_id){ $this->get_common(); $indent = Indent::find($indent_id); if($indent != null){ $this->data = array_merge($this->data,['indent'=>$indent]); return view('circle-store.indent.requested-indent',$this->data); }else{ return redirect('circle-store/my-requested-indents')->with('error','Invalid Indent Number !!'); } } public function authorised_the_indent(Request $request){ $indent = Indent::find($request->indent_id); $loginId = Auth::user()->loginId; if($indent != null){ foreach ($request->indentItems as $value){ $is_new_spare = $value['new_spare']; if($is_new_spare == 1){ $indentItem = new IndentItem(); $indentItem->indent_id = $request->indent_id; $indentItem->spare_code = $value['code']; $indentItem->qty = $value['final_qty']; }else{ $id = $value['indent_item_id']; $indentItem = IndentItem::find($id); $indentItem->qty = $value['final_qty']; } $indentItem->save(); } $indent->authorised_by = $loginId; $indent->status = 'authorized'; $indent->save(); return json_encode(['success'=>true,'item'=>$request->indentItems,'msg'=>'Indent has been authorized successfully !!']); }else{ return json_encode(['success'=>true,'msg'=>'Sonthing Went Wrong !!']); } } public function get_stock_transfer_orders_page(){ $this->get_common(); $stos = StockTransferOrder::orderBy('id','DESC')->get(); $this->data = array_merge($this->data,['stos'=>$stos]); return view('admin.indent.stock-transfer-orders',$this->data); } public function get_stock_transfer_notes_page(){ $this->get_common(); $stns = StockTransferNote::where('from_warehouse','SERPNT')->orderBy('id','DESC')->get(); $this->data = array_merge($this->data,['stns'=>$stns]); return view('admin.indent.stock-transfer-notes',$this->data); } public function get_view_sto($sto_id){ $this->get_common(); $sto = StockTransferOrder::find($sto_id); $items = DB::table('stock_transfer_order_items')->join('spare_parts_masters','spare_parts_masters.code','stock_transfer_order_items.spare_code')->where('stock_transfer_order_items.sto_id',$sto_id)->select('stock_transfer_order_items.*','spare_parts_masters.description')->get(); $this->data = array_merge($this->data,['sto'=>$sto,'items'=>$items]); return view('admin.indent.view-sto',$this->data); } public function get_view_stn($stn_id){ $this->get_common(); $stn = StockTransferNote::find($stn_id); $this->data = array_merge($this->data,['stn'=>$stn]); return view('admin.indent.view-stn',$this->data); } public function all_str(){ $this->get_common(); $allstr = StockTransferReceipt::get(); $this->data = array_merge($this->data,['all_str'=>$allstr]); return view('admin.all-str',$this->data); } public function get_all_sto_spare_part(Request $request){ $this->get_common(); $sto_id = $request->sto_id ; $sto = StockTransferOrder::find($sto_id); $userInfo = $this->data['userInfo']; $circleCodes = $userInfo->circleCodes; $indent = Indent::where('indent_no',$sto->indent_no)->first(); if($indent->business_type == 'PT'){ $warehouse = 'SUPPNT'; }else{ $warehouse = 'SER'.$circleCodes; } $items = DB::table('stock_transfer_order_items')->join('spare_parts_masters','spare_parts_masters.code','stock_transfer_order_items.spare_code')->where('stock_transfer_order_items.sto_id',$sto_id)->get(); $n=0; $data = array(); foreach ($items as $key => $item) { if($item->final_qty != 0){ $warehouse_inventory = DB::table('warehouse_inventory')->where('spare_code',$item->spare_code)->where('warehouse',$warehouse)->where('available_qty','>',0)->where('item_type','fresh')->get(); $total_adjust = 0; $required = $item->final_qty; foreach ($warehouse_inventory as $key => $value) { $total_adjust = $value->available_qty; if($total_adjust < $required && $required != 0){ $data[$n]['entry_id'] = $value->id; $data[$n]['spate_type'] = 'fresh'; $data[$n]['spate_qty'] = $value->available_qty; $data[$n]['spate_rate'] = $value->rate; $data[$n]['item'] = $item; $data[$n]['lot_no'] = $value->lot_no; $n++; } if($total_adjust > $required || $total_adjust == $required ){ $data[$n]['entry_id'] = $value->id; $data[$n]['spate_type'] = 'fresh'; $data[$n]['spate_qty'] = $required; $data[$n]['spate_rate'] = $value->rate; $data[$n]['item'] = $item; $data[$n]['lot_no'] = $value->lot_no; $n++; } $required = $required - $total_adjust; if( $required == 0 || $required < 0){ break 1; } } } if($item->repaired_qty != 0){ $warehouse_inventory = DB::table('warehouse_inventory')->where('spare_code',$item->spare_code)->where('warehouse',$warehouse)->where('available_qty','>',0)->where('item_type','repaired')->get(); $total_adjust = 0; $required = $item->repaired_qty; foreach ($warehouse_inventory as $key => $value) { $total_adjust = $value->available_qty; if($total_adjust < $required && $required != 0){ $data[$n]['entry_id'] = $value->id; $data[$n]['spate_type'] = 'repaired'; $data[$n]['spate_qty'] = $value->available_qty; $data[$n]['spate_rate'] = $value->rate; $data[$n]['item'] = $item; $data[$n]['lot_no'] = $value->lot_no; $n++; } if($total_adjust > $required || $total_adjust == $required ){ $data[$n]['entry_id'] = $value->id; $data[$n]['spate_type'] = 'repaired'; $data[$n]['spate_qty'] = $required; $data[$n]['spate_rate'] = $value->rate; $data[$n]['item'] = $item; $data[$n]['lot_no'] = $value->lot_no; $n++; } $required = $required - $total_adjust; if( $required == 0 || $required < 0){ break 1; } } } } return json_encode(['success'=>true, 'items'=>$data]); } public function generate_stn($sto_id){ $this->get_common(); $sto = StockTransferOrder::find($sto_id); if($sto->status == 'stn'){ $this->data = array_merge($this->data,['sto'=>$sto]); return view('admin.indent.generate-stn',$this->data); }else{ return redirect('/admin/stock-transfer-orders'); } } public function get_all_stn($sto_id){ $this->get_common(); $sto = StockTransferOrder::find($sto_id); $stns = StockTransferNote::where('sto_id',$sto_id)->get(); $this->data = array_merge($this->data,['sto'=>$sto,'stns'=>$stns]); return view('admin.indent.all-stn',$this->data); } public function generate_stn_now(Request $request){ $loginId = Auth::user()->loginId; $userInfo = LocalUserMapping::where('LoginID',$loginId)->first(); $data = json_decode($request->stnData, true); $sto_id = $data['sto_id']; $invoice_no = $data['invoice_no']; $consignee_address = $data['consignee_address']; $sto = StockTransferOrder::find($sto_id); $indent = Indent::find($sto->indent_id); $fieldUserCodes = $userInfo->fieldUserCodes; $warehouse = 'SER'.$fieldUserCodes; $to_warehouse = $indent->ware_house; if($indent->business_type == 'PT'){ $from_warehouse = 'SUPPNT'; }else{ $from_warehouse = 'SERPNT'; } $f_date = date('Y').'-03-31'; $curr_date = date('Y-m-d'); if (strtotime($curr_date) <= strtotime($f_date)) { $session = (date('y')-1).date('y'); } else { $session = date('y').(date('y')+1); } $last_value = \App\StockTransferNote::where('from_warehouse',$warehouse)->where('session',$session)->orderBy('id','desc')->first(); if($last_value != null){ $no = $last_value->series + 1; }else{ $no = 1; } //$session = date('y').date('y')+1; $stn = new StockTransferNote(); $stn->sto_id = $sto->id; $stn->series = $no; $stn->session = $session; $stn->stn_no = 'STN/'.substr($warehouse,3).'/'.$no.'/'.$session; $stn->stn_date = date('Y-m-d H:i:s'); $stn->status = 'stn_release'; $stn->from_warehouse = 'SERPNT'; $stn->to_warehouse = $indent->ware_house; $stn->invoice_no = $invoice_no; $stn->consignee_address = $consignee_address; if($stn->save()){ foreach ($data['indentItems'] as $value) { $code = $value['item']['code']; $entry_id = $value['entry_id']; $spare_qty = $value['spate_qty']; $spate_rate = $value['spate_rate']; $spate_type = $value['spate_type']; $stnItem = new StnItem(); $stnItem->stn_id = $stn->id; $stnItem->spare_code = $code; $stnItem->status = 'release'; if($spate_type == 'fresh'){ $stnItem->fresh_qty = $spare_qty; } if($spate_type == 'repaired'){ $stnItem->repaired_qty = $spare_qty; } $stnItem->rate = $spate_rate; $stnItem->gst = $value['item']['gst_slab_rates']; $stnItem->lot_no = $value['lot_no']; $stnItem->save(); $mainStock = StockInCircleStore::where('spare_code',$code)->where('warehouse',$from_warehouse)->first(); if($mainStock != null){ if($spate_type == 'fresh'){ $mainStock->fresh_qty = $mainStock->fresh_qty - $spare_qty; } if($spate_type == 'repaired'){ $mainStock->repaired_qty = $mainStock->repaired_qty - $spare_qty; } $mainStock->save(); } $warehouse_inventory = \App\WarehouseInventory::where('id',$entry_id)->first(); $warehouse_inventory->available_qty = $warehouse_inventory->available_qty - $spare_qty; $warehouse_inventory->save(); } $sto->status = 'stn_confirm'; $sto->save(); return json_encode(['success'=>true, 'msg'=>'STN Generated Successfully']); }else{ return json_encode(['success'=>false, 'msg'=>'Sonthing Went wrong !!']); } } public function print_stn($stn_id,$type){ $this->get_common(); if($type == 'Original'){ $paper_type = "Original"; }else{ $paper_type = "Duplicate"; } $stn = StockTransferNote::where('id',$stn_id)->first(); $sto = StockTransferOrder::where('id', $stn->sto_id)->first(); $stn_items = DB::table('stn_items')->join('spare_parts_masters','spare_parts_masters.code','stn_items.spare_code')->where('stn_id',$stn_id)->whereNotNull('spare_parts_masters.name')->select('stn_items.*','spare_parts_masters.description','spare_parts_masters.gst_slab_rates','spare_parts_masters.hsn','spare_parts_masters.repaired_rate')->get(); $get_from_warehouse = WareHouse::where('ware_house',$stn->from_warehouse)->first(); $get_to_warehouse = WareHouse::where('ware_house',$stn->to_warehouse)->first(); $sub_total = 0; $gst_total = 0; $grand_total = 0; foreach ($stn_items as $value) { $ftotal = $value->fresh_qty*$value->rate; $rtotal = $value->repaired_qty*$value->rate; $fltotal = $value->faulty_qty*$value->rate; $fgst = ($ftotal*$value->gst_slab_rates)/100; $rgst = ($rtotal*$value->gst_slab_rates)/100; $flgst = ($fltotal*$value->gst_slab_rates)/100; $sub_total = $sub_total + ($ftotal + $rtotal + $fltotal); $gst_total = $gst_total + ($fgst + $rgst + $flgst); } $grand_total = $grand_total + ($sub_total + $gst_total); $grand_total = round($grand_total,2); $amount_in_word = $this->convert_number_to_words($grand_total); $this->data = array_merge($this->data,['sto'=>$sto,'stn'=>$stn,'stn_items'=>$stn_items,'sub_total'=>$sub_total, 'gst_total'=>$gst_total, 'grand_total'=>$grand_total,'amount_in_word'=>$amount_in_word,'from_warehouse'=>$get_from_warehouse,'to_warehouse'=>$get_to_warehouse,'paper_type'=>$paper_type]); return view('admin.indent.print-stn',$this->data); } public function get_stn_verify(){ $this->get_common(); $ware_houses = DB::table('ware_houses')->where('ware_house','!=','SERPNT')->get(); $this->data = array_merge($this->data,['warehouses'=>$ware_houses]); return view('admin.stn-verify',$this->data); } public function received_stn_now(Request $request){ $user_id = Auth::user()->id; $stn_no = $request->stn_number; $warehouse = $request->warehouse; $is_stn_received = StockTransferNote::where('stn_no',$stn_no)->where('status','received')->count(); if($is_stn_received == 0){ $f_date = date('Y').'-03-31'; $curr_date = date('Y-m-d'); if (strtotime($curr_date) <= strtotime($f_date)) { $session = (date('y')-1).date('y'); } else { $session = date('y').(date('y')+1); } $last_value = \App\StockTransferReceipt::where('warehouse',$warehouse)->where('session',$session)->orderBy('id','desc')->first(); if($last_value != null){ $no = $last_value->series + 1; }else{ $no = 1; } $str = new StockTransferReceipt(); $str->str_no = 'STR/'.substr($warehouse,3).'/'.$stn_no.'/'.$session; $str->stn_no = $stn_no; $str->session = $session; $str->warehouse = $warehouse; $str->save(); foreach ($request->items as $value) { $is_stock = StockInCircleStore::where('spare_code',$value['spare_code'])->where('warehouse',$warehouse)->count(); if($is_stock > 0){ $stock = StockInCircleStore::where('spare_code',$value['spare_code'])->where('warehouse',$warehouse)->first(); $stock->user_id = $user_id; $stock->fresh_qty = $stock->fresh_qty + $value['fresh_qty']; $stock->repaired_qty = $stock->repaired_qty + $value['repaired_qty']; $stock->rate = $value['rate']; $stock->save(); }else{ $stock = new StockInCircleStore(); $stock->user_id = $user_id; $stock->warehouse = $warehouse; $stock->spare_id = $value['spare_id']; $stock->spare_code = $value['spare_code']; $stock->fresh_qty = $value['fresh_qty']; $stock->repaired_qty = $value['repaired_qty']; $stock->save(); } $history = new HistoryOfStockInCircleStore(); $history->spare_code = $value['spare_code']; $history->fresh_qty = $value['fresh_qty']; $history->repaired_qty = $value['repaired_qty']; $history->receiving_type = 'stn_receiving'; $history->receiving_date = date('Y-m-d H:i:s'); $history->stn_no = $stn_no; $history->added_by = $user_id; $history->save(); } $stn = StockTransferNote::where('stn_no',$stn_no)->first(); $stn->status = 'received'; $stn->save(); return json_encode(['success'=> true, 'msg' => 'STN has Recevied Successfully !!']); }else{ return json_encode(['success'=> false, 'msg' => 'STN already Recevied. try Another STN !!']); } } public function place_indent_admin(Request $request){ $item_count = count($request->items); if($item_count > 0){ $total_qty = 0; foreach ($request->items as $key => $value) { $qty = $value['qty']; $total_qty = $total_qty + $qty; } $user_id = $request->user_id ; $f_date = date('Y').'-03-31'; $curr_date = date('Y-m-d'); if (strtotime($curr_date) <= strtotime($f_date)) { $session = (date('y')-1).date('y'); } else { $session = date('y').(date('y')+1); } $last_indent = Indent::where('ware_house',$request->ware_house)->where('business_type',$request->business_type)->where('session',$session)->orderBy('id','desc')->first(); if($last_indent != null){ $no = $last_indent->series + 1 ; // $session = $last_indent->session; }else{ $no = 1 ; //$session = date('y').date('y')+1; } $indent = new Indent(); $indent->series = $no; $indent->indent_no = strtoupper($request->business_type).'/'.substr($request->ware_house,3).'/IND/00'.$no.'/'.$session; $indent->indent_date = $request->indent_date; $indent->total_qty = $total_qty; $indent->status = 'request'; $indent->session = $session; $indent->indent_placed_by = $user_id; $indent->ware_house = $request->ware_house; if($request->customer_code_and_name != ""){ $cust_code_name = explode('--', $request->customer_code_and_name); $indent->customer_code = $cust_code_name[0]; $indent->customer_name = $cust_code_name[1]; } $indent->customer_po = $request->customer_po; $indent->cutomer_po_date = $request->cutomer_po_date; $indent->business_type = $request->business_type; $indent->remarks = $request->remarks; if($indent->save()){ foreach ($request->items as $key => $value) { $qty = $value['qty']; $indentItem = new IndentItem(); $indentItem->indent_id = $indent->id; $indentItem->spare_code = $value['code']; $indentItem->qty = $qty; $indentItem->save(); } return json_encode(['success'=>true,'msg'=>'Indent has been placed Successfully !!']); }else{ return json_encode(['success'=>false,'msg'=>'Somthing went wrong !!']); } }else{ return json_encode(['success'=>false,'msg'=>'Somthing went wrong !!']); } } public function get_stn_details(Request $request){ $stn_no = $request->stn_number; $loginId = Auth::user()->loginId; $userInfo = LocalUserMapping::where('LoginID',$loginId)->first(); $warehouse = $request->warehouse; $is_stn_received = StockTransferNote::where('stn_no',$stn_no)->where('status','received')->count(); $is_my_stn = $stn = StockTransferNote::where('stn_no',$stn_no)->where('to_warehouse',$warehouse)->count(); if($is_stn_received == 1){ return json_encode(['success'=> false, 'msg' => 'STN already Recevied. try Another STN !!']); }elseif($is_my_stn == 0){ return json_encode(['success'=> false, 'msg' => 'This STN not for your warehouse . try Another STN !!']); }else{ $stn = StockTransferNote::where('stn_no',$stn_no)->where('to_warehouse',$warehouse)->first(); if($stn != null){ $stn_items = DB::table('stn_items')->join('spare_parts_masters','spare_parts_masters.code','stn_items.spare_code')->where('stn_id',$stn->id)->select('stn_items.*','spare_parts_masters.id as spare_id','spare_parts_masters.name','spare_parts_masters.description','spare_parts_masters.uom','spare_parts_masters.type')->get(); return json_encode(['success'=>true, 'items'=>$stn_items]); }else{ return json_encode(['success'=> false, 'msg' => 'Invalid STN !!']); } } } public function convert_number_to_words(float $number){ $decimal = round($number - ($no = floor($number)), 2) * 100; $hundred = null; $digits_length = strlen($no); $i = 0; $str = array(); $words = array(0 => '', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'forty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'ninety'); $digits = array('', 'hundred','thousand','lakh', 'crore'); while( $i < $digits_length ) { $divider = ($i == 2) ? 10 : 100; $number = floor($no % $divider); $no = floor($no / $divider); $i += $divider == 10 ? 1 : 2; if ($number) { $plural = (($counter = count($str)) && $number > 9) ? 's' : null; $hundred = ($counter == 1 && $str[0]) ? ' and ' : null; $str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred; } else $str[] = null; } $Rupees = implode('', array_reverse($str)); $paise = ($decimal) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : ''; return ($Rupees ? $Rupees . 'Rupees ' : '') . $paise; } public function view_str($str_id){ $this->get_common(); $str = StockTransferReceipt::where('id',$str_id)->first(); if($str != null){ $stn = StockTransferNote::where('stn_no',$str->stn_no)->first(); $stn_id = $stn->id; $stn_items = DB::table('stn_items')->join('spare_parts_masters','spare_parts_masters.code','stn_items.spare_code')->whereNotNull('spare_parts_masters.hsn')->where('stn_id',$stn_id)->select('stn_items.*','spare_parts_masters.description','spare_parts_masters.gst_slab_rates','spare_parts_masters.hsn','spare_parts_masters.repaired_rate')->get(); // $stn_items = DB::table('stn_items')->join('spare_parts_masters','spare_parts_masters.code','stn_items.spare_code')->where('stn_id',$stn_id)->select('stn_items.*','spare_parts_masters.description','spare_parts_masters.gst_slab_rates','spare_parts_masters.hsn','spare_parts_masters.repaired_rate')->get(); $this->data = array_merge($this->data,['str'=>$str,'stn_items'=>$stn_items,'stn'=>$stn]); return view('circle-store.view-str',$this->data); }else{ return redirect()->back()->with('error','Invalid STR No !'); } } }