<?php
 namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; use Session; use Validator; use Redirect; class Stock_reports extends Setup { public function __construct() { parent::__construct(); } public function stock_report(Request $request) { if(check_user_access('stock_report') === FALSE){ Redirect::to('/')->send(); } $branch_id = active_branch_id(); $client = $request->client; $invoice = $request->invoice; $currency = $request->currency; $this->data["pageData"] = get_stock_report($client,$invoice,$currency); $this->data["warehouse"] = set_array_keys(fetch_table_branch('warehouse'),'uid'); $this->data["clients"] = set_array_keys(fetch_table_where_branch('accounts','type','client'),'uid'); $this->data["currencies"] = set_array_keys(fetch_currencies(),'uid'); $this->data['stock_in_receipts'] = set_array_keys(fetch_table_where_branch('stock_in','client',$client),'uid'); $this->data["search_client"] = $request->client; $this->data["search_currency"] = $request->currency; $this->data["search_invoice"] = $request->invoice; $this->data["title"] = print_lang($this->data["app_lang"],'stock_report'); $this->data["pageToLoad"] = "reports/stock_report.php"; $this->data["activeLink"] = "stock"; $this->load_view($this->data); } public function stock_in_out_report(Request $request) { if(check_user_access('stock_in_out_report') === FALSE){ Redirect::to('/')->send(); } $branch_id = active_branch_id(); $stock_in = DB::table('stock_in')->where('branch',$branch_id); if(!empty($request->client)){ $stock_in->where('client',$request->client); } if(!empty($request->warehouse)){ $stock_in->where('warehouse',$request->warehouse); } if(!empty($request->from)){ $stock_in->where('created_at','>=',get_true_date($request->from).' 00:00:00'); } if(!empty($request->to)){ $stock_in->where('created_at','<=',get_true_date($request->to).' 23:59:59'); } $stock_in = $stock_in->get(); $stock_in = json_decode(json_encode($stock_in),true); $stock_out = DB::table("stock_out")->where('branch',$branch_id)->get(); $stock_out = DB::table('stock_out')->where('branch',$branch_id); if(!empty($request->client)){ $stock_out->where('client',$request->client); } if(!empty($request->warehouse)){ $stock_out->where('warehouse',$request->warehouse); } if(!empty($request->currency)){ $stock_out->where('currency',$request->currency); } if(!empty($request->from)){ $stock_out->where('created_at','>=',get_true_date($request->from).' 00:00:00'); } if(!empty($request->to)){ $stock_out->where('created_at','<=',get_true_date($request->to).' 23:59:59'); } $stock_out = $stock_out->get(); $stock_out = json_decode(json_encode($stock_out),true); $this->data["stock_in"] = $stock_in; $this->data["stock_out"] = $stock_out; $this->data["warehouses"] = set_array_keys(fetch_table_branch('warehouse'),'uid'); $this->data["clients"] = set_array_keys(fetch_table_where_branch('accounts','type','client'),'uid'); $this->data["currencies"] = set_array_keys(fetch_currencies(),'uid'); $this->data["client"] = $request->client; $this->data["warehouse"] = $request->warehouse; $this->data["currency"] = $request->currency; $this->data["from"] = $request->from; $this->data["to"] = $request->to; $this->data["title"] = print_lang($this->data["app_lang"],'stock_in_out_report'); $this->data["pageToLoad"] = "reports/stock_in_out_report.php"; $this->data["activeLink"] = "stock"; $this->load_view($this->data); } public function warehouse_report(Request $request) { if(check_user_access('warehouse_report') === FALSE){ Redirect::to('/')->send(); } $branch_id = active_branch_id(); $stock_in = DB::table('stock_in')->where('branch',$branch_id); if(!empty($request->client)){ $stock_in->where('client',$request->client); } if(!empty($request->from)){ $stock_in->where('created_at','>=',get_true_date($request->from).' 00:00:00'); } if(!empty($request->to)){ $stock_in->where('created_at','<=',get_true_date($request->to).' 23:59:59'); } $stock_in = $stock_in->get(); $stock_in = json_decode(json_encode($stock_in),true); $result = stock_warehouse_report($stock_in); $this->data["pageData"] = $result; $this->data["clients"] = set_array_keys(fetch_table_where_branch('accounts','type','client'),'uid'); $this->data["client"] = $request->client; $this->data["from"] = $request->from; $this->data["to"] = $request->to; $this->data["title"] = print_lang($this->data["app_lang"],'stock_warehouse_report'); $this->data["pageToLoad"] = "reports/stock_warehouse_report.php"; $this->data["activeLink"] = "stock"; $this->load_view($this->data); } }