373 lines
15 KiB
PHP
373 lines
15 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Interfaces\APIInterface;
|
|
use App\Interfaces\AuthApps;
|
|
use App\Interfaces\AppUtility;
|
|
use App;
|
|
use Illuminate\Http\Request;
|
|
use PDF;
|
|
use Excel;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Auth;
|
|
use App\Exports\ExcelExport;
|
|
use App\Exports\ExcelExportCSV;
|
|
|
|
use App\Exports\IcsExport;
|
|
use Hash;
|
|
use DB;
|
|
use File;
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\RequestOptions;
|
|
use GuzzleHttp\Exception\ClientException;
|
|
use GuzzleHttp\Exception\ServerException;
|
|
use Illuminate\Http\Response;
|
|
|
|
date_default_timezone_set('Asia/Jakarta');
|
|
|
|
class GlobalController extends Controller
|
|
{
|
|
|
|
public function export_any(Request $request, $typeExport,$id) {
|
|
|
|
switch ($id) {
|
|
|
|
case 'laporan_billing':
|
|
$view = 'export.'.$typeExport.'_billing';
|
|
$nameFile = 'billing-'.date('d-m-Y').'.'.$typeExport;
|
|
|
|
if ($request->startDate) {
|
|
|
|
$startDate = date('Y-m-d',strtotime($request->startDate)).' 00:00:00';
|
|
$endDate = date('Y-m-d',strtotime($request->endDate)).' 24:00:00';
|
|
}else{
|
|
$startDate = date('Y-m-d').' 00:00:00';
|
|
$endDate = date('Y-m-d').' 24:00:00';
|
|
|
|
}
|
|
$dtable = DB::table("bill")
|
|
->join("users", function($join){
|
|
$join->on("users.user_id", "=", "bill.user_id");
|
|
})
|
|
->leftJoin("merchant", function($join){
|
|
$join->on("merchant.mid", "=", "users.mid");
|
|
})
|
|
->leftJoin("promo_voucher", function($join){
|
|
$join->on("promo_voucher.promo_voucher_id", "=", "bill.promo_voucher_id");
|
|
})
|
|
->join("reff_payment_status", function($join){
|
|
$join->on("reff_payment_status.payment_status_id", "=", "bill.payment_status_id");
|
|
})
|
|
->select("bill.*", "promo_voucher.promo_code", "reff_payment_status.payment_status_nm", "users.user_nm", "users.outlet_id", "merchant_nm")
|
|
->where("bill.crtdt", ">=", $startDate)
|
|
->where("bill.crtdt", "<=", $endDate)
|
|
->when(request('merchant_filter') != null, function ($query) use ($request) {
|
|
if ($request->merchant_filter != 'all') {
|
|
$query->where('users.mid', $request->merchant_filter);
|
|
}
|
|
})
|
|
->when(Auth::guard('admin')->user()->role == 3, function ($query) use ($request) {
|
|
$query->where('merchant.city_id', Auth::guard('admin')->user()->id_kota);
|
|
})
|
|
->get();
|
|
|
|
$param['data'] = $dtable;
|
|
$param['view'] = $view;
|
|
|
|
break;
|
|
|
|
case 'laporan_order':
|
|
$view = 'export.'.$typeExport.'_order';
|
|
$nameFile = 'order-'.date('d-m-Y').'.'.$typeExport;
|
|
|
|
if ($request->startDate) {
|
|
|
|
$startDate = date('Y-m-d',strtotime($request->startDate)).' 00:00:00';
|
|
$endDate = date('Y-m-d',strtotime($request->endDate)).' 24:00:00';
|
|
}else{
|
|
$startDate = date('Y-m-d').' 00:00:00';
|
|
$endDate = date('Y-m-d').' 24:00:00';
|
|
|
|
}
|
|
$dtable = DB::table("orders")
|
|
->join("users", function($join){
|
|
$join->on("users.user_id", "=", "orders.user_id");
|
|
})
|
|
->leftJoin("merchant", function($join){
|
|
$join->on("merchant.mid", "=", "users.mid");
|
|
})
|
|
->leftJoin("outlet", function($join){
|
|
$join->on("outlet.outlet_id", "=", "orders.outlet_id");
|
|
})
|
|
->join("reff_order_type", function($join){
|
|
$join->on("reff_order_type.order_type_id", "=", "orders.order_type_id");
|
|
})
|
|
->join("reff_bill_type", function($join){
|
|
$join->on("reff_bill_type.bill_type_id", "=", "orders.bill_type_id");
|
|
})
|
|
->join("reff_payment_status", function($join){
|
|
$join->on("reff_payment_status.payment_status_id", "=", "orders.payment_status_id");
|
|
})
|
|
->select("orders.*", "reff_bill_type.*", "merchant_nm", "reff_payment_status.payment_status_nm", "users.user_nm", "orders.outlet_id", "reff_order_type.*")
|
|
->where("orders.crtdt", ">=", $startDate)
|
|
->where("orders.crtdt", "<=", $endDate)
|
|
->when(request('merchant_filter') != null, function ($query) use ($request) {
|
|
if ($request->merchant_filter != 'all') {
|
|
$query->where('users.mid', $request->merchant_filter);
|
|
}
|
|
})
|
|
->when(Auth::guard('admin')->user()->role == 3, function ($query) use ($request) {
|
|
$query->where('merchant.city_id', Auth::guard('admin')->user()->id_kota);
|
|
})
|
|
->get();
|
|
$param['data'] = $dtable;
|
|
$param['view'] = $view;
|
|
|
|
break;
|
|
|
|
case 'laporan_transaction':
|
|
$view = 'export.'.$typeExport.'_transaction';
|
|
$nameFile = 'transaction-'.date('d-m-Y').'.'.$typeExport;
|
|
|
|
if ($request->startDate) {
|
|
|
|
$startDate = date('Y-m-d',strtotime($request->startDate)).' 00:00:00';
|
|
$endDate = date('Y-m-d',strtotime($request->endDate)).' 24:00:00';
|
|
}else{
|
|
$startDate = date('Y-m-d').' 00:00:00';
|
|
$endDate = date('Y-m-d').' 24:00:00';
|
|
|
|
}
|
|
|
|
$dtable = DB::table("payment")
|
|
->leftJoin("users", function($join){
|
|
$join->on("users.user_id", "=", "payment.user_id");
|
|
})
|
|
->leftJoin("merchant", function($join){
|
|
$join->on("merchant.mid", "=", "users.mid");
|
|
})
|
|
->leftJoin("reff_payment_type", function($join){
|
|
$join->on("reff_payment_type.payment_type_id", "=", "payment.payment_type_id");
|
|
})
|
|
->leftJoin("customer", function($join){
|
|
$join->on("customer.customer_id", "=", "payment.customer_id");
|
|
})
|
|
->leftJoin("reff_payment_status", function($join){
|
|
$join->on("reff_payment_status.payment_status_id", "=", "payment.payment_status_id");
|
|
})
|
|
->select("payment.*", "reff_payment_type.*", "merchant_nm", "reff_payment_status.payment_status_nm", "users.user_nm", "payment.outlet_id", "customer.customer_nm")
|
|
->where("payment.crtdt", ">=", $startDate)
|
|
->where("payment.crtdt", "<=", $endDate)
|
|
->when(request('merchant_filter') != null, function ($query) use ($request) {
|
|
if ($request->merchant_filter != 'all') {
|
|
$query->where('users.mid', $request->merchant_filter);
|
|
}
|
|
})
|
|
->when(Auth::guard('admin')->user()->role == 3, function ($query) use ($request) {
|
|
$query->where('merchant.city_id', Auth::guard('admin')->user()->id_kota);
|
|
})
|
|
->get();
|
|
|
|
$param['data'] = $dtable;
|
|
$param['view'] = $view;
|
|
|
|
break;
|
|
|
|
case 'laporan_gross':
|
|
$view = 'export.'.$typeExport.'_gross';
|
|
$nameFile = 'gross-'.date('d-m-Y').'.'.$typeExport;
|
|
|
|
if ($request->startDate) {
|
|
|
|
$startDate = date('Y-m-d',strtotime($request->startDate)).' 00:00:00';
|
|
$endDate = date('Y-m-d',strtotime($request->endDate)).' 24:00:00';
|
|
}else{
|
|
$startDate = date('Y-m-d').' 00:00:00';
|
|
$endDate = date('Y-m-d').' 24:00:00';
|
|
|
|
}
|
|
|
|
$dtable = DB::table("payment")
|
|
->leftJoin("merchant", function($join){
|
|
$join->on("payment.mid", "=", "merchant.mid");
|
|
})
|
|
->leftJoin("outlet", function($join){
|
|
$join->on("outlet.outlet_id", "=", "payment.outlet_id");
|
|
})
|
|
->leftJoin("bill", function($join){
|
|
$join->on("bill.bill_id", "=", "payment.bill_id");
|
|
})
|
|
->leftJoin("orders_bill", function($join){
|
|
$join->on("orders_bill.bill_id", "=", "bill.bill_id");
|
|
})
|
|
->leftJoin("orders", function($join){
|
|
$join->on("orders.order_id", "=", "orders_bill.order_id");
|
|
})
|
|
->select("merchant.mid", "merchant.merchant_nm", "outlet.outlet_id", "outlet.outlet_nm",
|
|
DB::raw("payment.crtdt::date"), DB::raw("sum (payment.total_amount) as total_amount"),
|
|
DB::raw("sum (bill.tax_amount) as tax", "sum (bill.charge_amount) as charge"),
|
|
DB::raw("sum (bill.bill_amount) as gross_sales"),
|
|
DB::raw("sum (orders.total_amount_base) as cogs"),
|
|
DB::raw("sum (bill.bill_amount) - sum (distinct orders.total_amount_base) as gross_profit"),
|
|
DB::raw("count (payment.payment_id) as count_trx"),
|
|
DB::raw("count (orders.order_id) as count_order"))
|
|
->where("payment.payment_status_id", "=", 1)
|
|
->where("bill.crtdt", ">=", $startDate)
|
|
->where("bill.crtdt", "<=", $endDate)
|
|
->groupBy("merchant.mid","merchant.merchant_nm","outlet.outlet_id","outlet.outlet_nm",DB::raw("payment.crtdt::date"))
|
|
->orderByDesc(DB::raw("payment.crtdt::date"))
|
|
->when(request('merchant_filter') != null, function ($query) use ($request) {
|
|
if ($request->merchant_filter != 'all') {
|
|
$query->where('payment.mid', $request->merchant_filter);
|
|
}
|
|
})
|
|
->when(Auth::guard('admin')->user()->role == 3, function ($query) use ($request) {
|
|
$query->where('merchant.city_id', Auth::guard('admin')->user()->id_kota);
|
|
})
|
|
->get();
|
|
|
|
|
|
$param['data'] = $dtable;
|
|
$param['view'] = $view;
|
|
|
|
break;
|
|
|
|
case 'generate_qr_code' :
|
|
$path = public_path('qrcode');
|
|
File::cleanDirectory($path);
|
|
|
|
$view = 'export.'.$typeExport.'_qr_code';
|
|
$nameFile = 'toko-'.date('d-m-Y').'.'.$typeExport;
|
|
$customPaper = 'a4';
|
|
$paperType = 'potrait';
|
|
$param['data_toko'] = DB::table('toko')
|
|
->join('merchant','merchant.mid','toko.mid')
|
|
->where('toko_id',$request->toko_id)->first();
|
|
$param['data_qr'] = $this->generateQR($param['data_toko'], 0);
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($typeExport == 'pdf') {
|
|
$pdf = PDF::loadView($view,$param)->setPaper($customPaper, $paperType);
|
|
$pdf->getDomPDF()->set_option("enable_php", true)->set_option("enable_javascript", true);
|
|
// if($request->get('setAct') == 'download'){
|
|
// return $pdf->download($nameFile);
|
|
// }else{
|
|
return $pdf->stream($nameFile);
|
|
// }
|
|
}
|
|
elseif ($typeExport == 'xlsx') {
|
|
return Excel::download(new ExcelExport($param), $nameFile);
|
|
}
|
|
elseif ($typeExport == 'csv') {
|
|
return Excel::download(new ExcelExportCSV($param), $nameFile);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function ref_any(Request $request,$type)
|
|
{
|
|
switch($type){
|
|
case 'mst_agency':
|
|
|
|
if ($request->input('role') == 4) {
|
|
$datas = \DB::select("SELECT * FROM mst_agency WHERE is_active = 't' and usertypeid = ? and id = 11",[$request->input('src_by')]);
|
|
|
|
}else{
|
|
$datas = \DB::select("SELECT * FROM mst_agency WHERE is_active = 't' and usertypeid = ?",[$request->input('src_by')]);
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
case 'merchant' :
|
|
$check = DB::table('users')->select('mid')->where('role_id','MERCHANT_OPR')->get()->toArray();
|
|
$temp = [];
|
|
|
|
foreach ($check as $key => $value) {
|
|
array_push($temp,"'".$value->mid."'");
|
|
}
|
|
|
|
if($request->input('src_by')){
|
|
$src = "'".$request->input('src_by')."'";
|
|
$temp = \array_diff($temp, [$src]);
|
|
}
|
|
|
|
$arr_check = implode(",",$temp);
|
|
|
|
// if($temp){
|
|
// $datas = \DB::select("SELECT * FROM merchant WHERE mid not in (".$arr_check.")");
|
|
// }else{
|
|
$datas = \DB::select("SELECT * FROM merchant");
|
|
|
|
// }
|
|
|
|
break;
|
|
|
|
case 'jenis_user':
|
|
if ($request->input('src_by') == 4) {
|
|
$datas = \DB::select("SELECT * FROM usertype WHERE id in (1,2)");
|
|
}else{
|
|
$datas = \DB::select("SELECT * FROM usertype WHERE is_active = 't'");
|
|
}
|
|
|
|
break;
|
|
|
|
case 'tax' :
|
|
$datas = \DB::select("SELECT * from reff_tax");
|
|
break;
|
|
|
|
case 'outlet' :
|
|
$datas = \DB::select("SELECT * from outlet m where mid = ?",[$request->input('src_by')]);
|
|
|
|
break;
|
|
|
|
case 'tipe_toko' :
|
|
$datas = \DB::select("SELECT * from merchant_toko_type m
|
|
join reff_toko_type rt on rt.ttid = m.ttid
|
|
where mid = ?",[$request->input('src_by')]);
|
|
|
|
break;
|
|
|
|
case 'edc' :
|
|
$datas = \DB::select("SELECT * from device m
|
|
where outlet_id is null and brand = ?",[$request->input('src_by')]);
|
|
|
|
break;
|
|
|
|
case 'type_user':
|
|
$merchant = DB::table('merchant')->where('mid',$request->input('src_by'))->first();
|
|
|
|
$arr_type = [];
|
|
if($merchant->is_park_active == true){
|
|
array_push($arr_type,'1');
|
|
}
|
|
|
|
if($merchant->is_market_active == true){
|
|
array_push($arr_type,'2');
|
|
}
|
|
|
|
$type = implode(",",$arr_type);
|
|
|
|
$datas = \DB::select("SELECT * from reff_user_type m where type in (".$type.")");
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
return response()->json([
|
|
'rc' => 0,
|
|
'rm' => $datas
|
|
]);
|
|
}
|
|
|
|
}
|