/
home
/
sjslayjy
/
public_html
/
scm
/
app
/
Helpers
/
Upload File
HOME
<?php function getUserById($user_id){ $user = \App\User::find($user_id); return $user; } function getVendorByRate($rate) { $vendor = \App\PurchaseOrderItem::join('purchase_orders', 'purchase_orders.id', 'purchase_order_items.po_id')->join('vendors', 'vendors.id', 'purchase_orders.vendor_id')->where('purchase_order_items.rate', $rate)->select('vendor_name')->first(); if(!is_null($vendor)) { return $vendor; } else { return new \App\Vendor(); } } function getMRNStatus($po_id) { $status = ''; $po_items = \App\PurchaseOrderItem::select(DB::raw('round(sum(qty)) as qty'), DB::raw('round(sum(rqty)) as rqty'))->where('po_id', $po_id)->groupBy('po_id')->get(); foreach ($po_items as $key => $item) { if($item->qty == $item->rqty) { $status = 1; } elseif($item->rqty > 0) { $status = 2; } else { $status = 3; } } return $status; } if (!function_exists('getInvoiceMRNStatus')) { function getInvoiceMRNStatus($po_number) { $po = \App\PurchaseOrder::where('po_number', $po_number)->first(); if (!$po) return 3; // Not Done if PO not found $po_items = \App\PurchaseOrderItem::select(DB::raw('round(sum(qty)) as qty'), DB::raw('round(sum(rqty)) as rqty')) ->where('po_id', $po->id) ->groupBy('po_id') ->get(); foreach ($po_items as $item) { if ($item->qty == $item->rqty) { return 1; // Done } elseif ($item->rqty > 0) { return 2; // Partially Done } else { return 3; // Not Done } } return 3; // Default to Not Done } } function getPOShortCloseStatus($po_id) { $stc_qty = \App\PurchaseOrderItem::where('po_id', $po_id)->sum('stc_qty'); if($stc_qty == 0 ) { return ''; } else { return '/Short Closed'; } } function getPONumberByStcId($stc_id) { $po_numbers = DB::table('short_closed_po_items as scp')->join('purchase_orders as po', 'scp.po_id', 'po.id')->select('po.po_number')->where('scp.stc_id', $stc_id)->groupBy('po.po_number')->get(); return $po_numbers; } function getWarehouseDaywiseProducts($product_company_id,$warehouse_id,$product_id,$date){ $inward_inventory = \App\ProductLoading::where('product_company_id',$product_company_id) ->where('warehouse_id',$warehouse_id) ->where('product_id',$product_id) ->whereDate('created_at', '=', date('Y-m-d',strtotime($date))) ->sum('quantity'); $outward_inventory = \App\ProductLoading::where('product_company_id',$product_company_id) ->where('from_warehouse_id',$warehouse_id) ->where('product_id',$product_id) ->whereDate('created_at', '=', date('Y-m-d',strtotime($date))) ->sum('quantity'); $actual_inventory = $inward_inventory - $outward_inventory; return $actual_inventory; } function totalTokenLoading($token_id){ $total_loading = \App\ProductLoading::where('token_id',$token_id) ->sum('quantity'); return $total_loading; } function getInventory($product_brand_id,$warehouse_id,$product_id){ $inventory = \App\Inventory::where('product_brand_id',$product_brand_id) ->where('warehouse_id',$warehouse_id) ->where('product_id',$product_id) ->sum('quantity'); return $inventory; } function getOpeningInventory($product_brand_id,$warehouse_id,$product_id){ $inventory = \App\OpeningInventory::where('product_brand_id',$product_brand_id) ->where('warehouse_id',$warehouse_id) ->where('product_id',$product_id) ->sum('quantity'); return $inventory; } function getPartyOpeningInventoryByProductAndBrand($party_id,$product_id,$product_brand_id,$type){ $inventory = \App\OpeningInventory::where($type,$party_id) ->where('product_id',$product_id) ->where('product_brand_id',$product_brand_id) ->sum('quantity'); return $inventory; } function getPartyInventoryByProductAndBrand($party_id,$product_id,$product_brand_id,$type){ $inventory = \App\Inventory::where($type,$party_id) ->where('product_id',$product_id) ->where('product_brand_id',$product_brand_id) ->sum('quantity'); return $inventory; } function getOtherPartyInventoryByProductAndBrand($product_id,$product_brand_id){ $inventory_unique_dealers = \App\Inventory::select('dealer_id')->distinct()->where('dealer_id','!=', null)->get(); $total = 0; foreach ($inventory_unique_dealers as $inventory_unique_dealer) { $dealer = \App\Dealer::where('id',$inventory_unique_dealer->dealer_id)->first(); if(!$dealer->show_separate_report){ $inventory = \App\Inventory::where('product_id',$product_id) ->where('product_brand_id',$product_brand_id) ->where('dealer_id',$inventory_unique_dealer->dealer_id) ->sum('quantity'); $total = $total + $inventory; } } return $total; } function getOtherPartyOpeningInventoryByProductAndBrand($product_id,$product_brand_id){ $inventory_unique_dealers = \App\OpeningInventory::select('dealer_id')->distinct()->where('dealer_id','!=', null)->get(); $total = 0; foreach ($inventory_unique_dealers as $inventory_unique_dealer) { $dealer = \App\Dealer::where('id',$inventory_unique_dealer->dealer_id)->first(); if(!$dealer->show_separate_report){ $inventory = \App\OpeningInventory::where('product_id',$product_id) ->where('product_brand_id',$product_brand_id) ->where('dealer_id',$inventory_unique_dealer->dealer_id) ->sum('quantity'); $total = $total + $inventory; } } return $total; } function getInventoryProductQuantity($type,$party_id,$product_id,$product_brand_id){ $inventory = \App\Inventory::where($type,$party_id) ->where('product_id',$product_id) ->where('product_brand_id',$product_brand_id) ->sum('quantity'); return $inventory; } function getBufferInventoryProductQuantity($type,$party_id,$product_id,$product_brand_id){ $inventory = \App\Inventory::where($type,$party_id) ->where('product_id',$product_id) ->where('product_brand_id',$product_brand_id) ->where('warehouse_id',24) ->sum('quantity'); return $inventory; } function getDealerTotalLoadingQuantity($dealer_id,$master_rake_id,$product_id){ $product_loading = \App\ProductLoading::where('dealer_id',$dealer_id)->where('master_rake_id',$master_rake_id)->where('product_id',$product_id)->sum('quantity'); if(is_null($product_loading)){ return 0; }else{ return $product_loading; } } function monthlyAverageLabourRate($month,$year,$type){ if($type == "loading"){ $result = \App\LabourPayments::where('rate','>',0)->whereMonth('created_at','=',$month)->whereYear('created_at','=',$year)->avg('rate'); }else if($type == "unloading"){ $result = \App\UnloadingLabourPayment::where('rate','>',0)->whereMonth('created_at','=',$month)->whereYear('created_at','=',$year)->avg('rate'); }else{ $result = \App\WagonUnloading::where('wagon_rate','>',0)->whereMonth('created_at','=',$month)->whereYear('created_at','=',$year)->avg('wagon_rate'); } return $result; } function monthlyAverageFreight($month,$year){ $result = \App\ProductLoading::whereNotNull('freight')->where('freight','>',0)->whereMonth('created_at','=',$month)->whereYear('created_at','=',$year)->avg('freight'); return $result; } function monthlyAverageDemurrage($month,$year){ $result = \App\MasterRake::whereNotNull('demurrage')->where('demurrage','>',0)->whereMonth('created_at','=',$month)->whereYear('created_at','=',$year)->avg('demurrage'); return $result; } function monthlyAverageWharfage($month,$year){ $result = \App\MasterRake::whereNotNull('wharfage')->where('wharfage','>',0)->whereMonth('created_at','=',$month)->whereYear('created_at','=',$year)->avg('wharfage'); return $result; } function getModelById($modal,$id){ $modal = "\App\\".$modal; $result = $modal::find($id); if($result!=''){ return $result; }else{ return new $modal; } } function getTableById($table_name,$id){ $result = \DB::table($table_name)->where('id',$id)->first(); return $result; } function getdealer($id){ $result = \App\Dealer::where('unique_id',$id)->first(); return $result; } function getSubmoduleByModule($role_id,$module_id){ $sub_menus = \App\RoleModuleAssociation::with('sub_module') ->where('role_id',$role_id) ->where('module_id',$module_id) ->get(); return $sub_menus; } function getIndianCurrency(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; } function calculateTimeSpan($date){ $seconds = strtotime(date('Y-m-d H:i:s')) - strtotime($date); $months = floor($seconds / (3600*24*30)); $day = floor($seconds / (3600*24)); $hours = floor($seconds / 3600); $mins = floor(($seconds - ($hours*3600)) / 60); $secs = floor($seconds % 60); if($seconds < 60){ $time = $secs." sec ago"; } else if($seconds < 60*60 ){ $time = $mins." min ago"; } else if($seconds < 24*60*60){ $time = $hours." hrs ago"; } else if($seconds < 24*60*60*30){ $time = $day." day ago"; } else{ $time = $months." month ago"; } return $time; } function keyFromSlug($slug,$delimiter){ $tmp = explode($delimiter, $slug); return ucfirst(implode(' ', $tmp)); } function setOpen($path) { return Request::is($path) ? 'open' : ''; } function setActive($path) { return Request::is($path) ? 'active' : ''; } function getPRCurrentStatus($pr_id){ $total_pr = \DB::table('purchase_request_items')->where('pr_id',$pr_id)->get(); $total_pr_complete = \DB::table('purchase_request_items')->where(['pr_id'=>$pr_id,'status'=>"completed"])->get(); if(count($total_pr_complete)>0){ if(count($total_pr)==count($total_pr_complete)){ return "completed"; }else{ return "partially_completed"; } }else{ return "processig"; } } function getPRCurrentStatusNew($pr_id){ $prItemQty = \App\PurchaseRequestItem::where('pr_id', $pr_id)->selectRaw('sum(qty) as qty, sum(rqty) as rqty')->first(); $pr_status = ($prItemQty->qty == $prItemQty->rqty)?'processing':(($prItemQty->rqty > 0)?'partially_completed':'completed'); return $pr_status; } function getPRCurrentStatus1($pr_id) { $total_qty = \DB::table('purchase_request_items')->where('pr_id',$pr_id)->sum('qty'); $total_rqty = \DB::table('purchase_request_items')->where('pr_id',$pr_id)->sum('rqty'); if($total_qty == $total_rqty) { return true; } return false; } function getPOCurrentStatus($po_id){ $total_poItem = \DB::table('purchase_order_items') ->where('po_id',$po_id) ->get(); //dd($total_poItem); // if($total_poItem>0){ foreach ($total_poItem as $key => $item){ $qty=$item->qty; $rqty=$item->rqty; if($rqty>0.00){ if($qty==$rqty){ return "completed"; }else{ return "partially_completed"; } } else{ return "processig"; } } } function getPOCurrentStatus1($po_id) { $total_qty = \DB::table('purchase_order_items')->where('po_id',$po_id)->sum('qty'); $total_rqty = \DB::table('purchase_order_items')->where('po_id',$po_id)->sum('rqty'); if($total_qty != $total_rqty) { return true; } return false; } function getPRIdByPONumber($po_id){ $all_pr_number = \DB::table('purchase_order_items')->where('po_id',$po_id) ->join('purchase_requests','purchase_requests.id','purchase_order_items.pr_id') ->select('purchase_requests.pr_number') ->groupBy('purchase_requests.pr_number') ->get(); //return $all_pr_number; $all_pr_list=[]; foreach ($all_pr_number as $key => $value) { $all_pr_list[]=$value->pr_number; } $a=implode(',', $all_pr_list); return $a; } function getPOIdByIRNNumber($irn_id){ $all_po_number = \DB::table('irn_items')->where('irn_id',$irn_id) ->join('purchase_orders','purchase_orders.id','irn_items.po_id') ->select('purchase_orders.po_number') ->groupBy('purchase_orders.po_number') ->get(); //return $all_pr_number; $all_po_list=[]; foreach ($all_po_number as $key => $value) { $all_po_list[]=$value->po_number; } $a=implode(',', $all_po_list); return $a; } function getIrnModelById($modal,$id){ $modal = "\App\\".$modal; $result = $modal::find($id); if($result!=null){ return $result; }else{ return new $modal; } } function getRole($role_id){ $all = \DB::table('roles') ->where('id',$role_id) ->first(); $role=$all->role; return $role; } //send mail check conditions function checkMailCondition($creater_id){ //dd($creater_id); $data=\DB::table('users') ->select('users.id','users.name','users.business_head','users.functional_head') ->where('users.id',$creater_id) ->first(); //dd($data); if($data->business_head==null && $data->functional_head==null){ return 'requested'; }elseif($data->functional_head==null){ return 'reviewed'; }elseif($data->business_head==null){ return 'pending_approval'; } } function checkFhBhCondition($creater_id){ $pr_creater = \DB::table('users') ->select('users.id','users.name','users.business_head','users.functional_head') ->where('users.id',$creater_id) ->first(); if(!is_null($pr_creater)) { if($pr_creater->business_head == null && $pr_creater->functional_head == null){ return 'requested'; }elseif($pr_creater->business_head == null){ return 'reviewed'; }elseif($pr_creater->functional_head == null){ return 'Approved(BH)'; } else { return 'Approved(BH)'; } } else { return false; } } function checkFunctionHead($creater_id){ $pr_creater =\DB::table('users') ->select('users.id','users.name','users.functional_head') ->where('users.id',$creater_id) ->first(); if(!is_null($pr_creater)) { if($pr_creater->functional_head == NULL) { return 'requested'; } else { return 'reviewed'; } } else { return false; } } function checkMailConditionPo($creater_id){ $data=\DB::table('users') ->select('users.id','users.name','users.business_head','users.functional_head','users.director') ->where('users.id',$creater_id) ->first(); //dd($data); if($data->business_head==null){ return 'pending_approval'; }else{ return 'requested'; } } function PrStatusCreaterName($pr_id,$status){ //dd($pr_id); $data=\DB::table('purchase_request_logs') //->join('users','users.id','purchase_request_logs.user_id') // ->select('*') ->where('pr_id',$pr_id) ->where('message',$status) ->first(); if($data!=''){ return $data; }else{ return new \App\PurchaseRequestLog(); } } function PoStatusCreaterName($pr_id,$status){ //dd($pr_id); $data=\DB::table('purchase_order_logs') ->where('po_id',$pr_id) ->where('message',$status) ->first(); if($data!=''){ return $data; }else{ return new \App\PurchaseOrderLog(); } } function isFunHeadAvailable($creater_id){ $data=\DB::table('users') ->select('users.id','users.name','users.business_head','users.functional_head') ->where('users.id',$creater_id) ->first(); if($data->functional_head == null) { return 'requested'; } else { return 'reviewed(FH)'; } } function isFunBusAvailable($creater_id){ //dd($creater_id); $data=\DB::table('users') ->select('users.id','users.name','users.business_head','users.functional_head') ->where('users.id',$creater_id) ->first(); //dd($data); if($data->business_head== null){ if($data->functional_head == null) { return 'requested'; } else { return 'reviewed(FH)'; } } else { return 'reviewed(BH)'; } } ?>