Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ($request->user()->can('purchaseorder.liststatuspo')) {
- $purchase = PurchaseOrder::select(
- 'transaction_purchase.id',
- 'transaction_purchase.dataorder',
- 'no_nota',
- 'kode_rpo',
- 'note',
- 'createdon',
- 'total',
- 'count_cetak',
- 'transaction_purchase.perusahaan_id',
- 'transaction_purchase.created_at',
- 'transaction_purchase.updated_at',
- 'member_id',
- 'sales_id',
- 'expedisi',
- 'expedisi_via',
- 'transaction_purchase.status',
- 'status_po',
- 'status_gudang',
- 'status_invoice',
- 'gudang_id',
- 'gudang.name as gudangnama',
- 'transaction_purchase_detail.transaction_purchase_id',
- DB::raw('(CASE
- WHEN transaction_purchase.status = 0 THEN 1
- WHEN transaction_purchase.status = 1 THEN 2
- WHEN transaction_purchase.status = 2 THEN 4
- WHEN transaction_purchase.status = 3 THEN 3
- ELSE 5 END ) AS ord')
- );
- $purchase->join('transaction_purchase_detail', 'transaction_purchase_detail.transaction_purchase_id', 'transaction_purchase.id');
- $purchase->join('gudang', 'transaction_purchase_detail.gudang_id', 'gudang.id');
- $purchase->where('flag_status', 0);
- // if($request->user()->can('purchaseorder.liststatuspobyuser')){
- // $purchase->where('createdon', auth()->user()->username);
- // }
- // if(session('type') ==''){
- // $purchase->where('transaction_purchase.type','!=',2);
- // }
- $purchase->groupBy('transaction_purchase_detail.transaction_purchase_id');
- $purchase->orderBy('ord', 'ASC');
- $purchase->orderBy('status_gudang', 'ASC');
- $purchase->orderBy('transaction_purchase.updated_at', 'DESC');
- } else if ($request->user()->can('purchaseorder.liststatusgudang')) {
- $purchase = PurchaseOrder::select(
- 'transaction_purchase.id',
- 'transaction_purchase.dataorder',
- 'no_nota',
- 'kode_rpo',
- 'note',
- 'createdon',
- 'total',
- 'count_cetak',
- 'transaction_purchase.perusahaan_id',
- 'transaction_purchase.created_at',
- 'transaction_purchase.updated_at',
- 'member_id',
- 'sales_id',
- 'expedisi',
- 'expedisi_via',
- 'transaction_purchase.status',
- 'status_po',
- 'status_gudang',
- 'status_invoice',
- 'gudang_id',
- 'gudang.name as gudangnama',
- 'transaction_purchase_detail.transaction_purchase_id',
- // DB::raw('(CASE
- // WHEN transaction_purchase.status = 1 AND status_gudang = 0 THEN 1
- // WHEN status_gudang = 1 AND transaction_purchase.status <> 3 THEN 2
- // WHEN transaction_purchase.status = 3 THEN 3
- // WHEN transaction_purchase.status = 2 THEN 4
- // ELSE 5 END ) AS ord'));
- DB::raw('(CASE
- WHEN transaction_purchase.status = 1 AND status_gudang = 0 AND status_invoice = 1 THEN 1
- WHEN transaction_purchase.status = 1 AND status_invoice= 0 THEN 2
- WHEN status_gudang = 1 AND transaction_purchase.status <> 3 THEN 3
- WHEN transaction_purchase.status = 3 THEN 4
- WHEN transaction_purchase.status = 2 THEN 5
- ELSE 6 END ) AS ord')
- );
- $purchase->join('transaction_purchase_detail', 'transaction_purchase_detail.transaction_purchase_id', 'transaction_purchase.id');
- $purchase->join('gudang', 'transaction_purchase_detail.gudang_id', 'gudang.id');
- $purchase->where('flag_status', 0);
- $purchase->groupBy('transaction_purchase_detail.transaction_purchase_id');
- $purchase->orderBy('ord', 'ASC');
- $purchase->orderBy('transaction_purchase.updated_at', 'DESC');
- } else if ($request->user()->can('purchaseorder.liststatusinvoice')) {
- $purchase = PurchaseOrder::select(
- 'transaction_purchase.id',
- 'transaction_purchase.dataorder',
- 'no_nota',
- 'kode_rpo',
- 'note',
- 'createdon',
- 'total',
- 'count_cetak',
- 'transaction_purchase.perusahaan_id',
- 'transaction_purchase.created_at',
- 'transaction_purchase.updated_at',
- 'member_id',
- 'sales_id',
- 'expedisi',
- 'expedisi_via',
- 'transaction_purchase.status',
- 'status_po',
- 'status_gudang',
- 'status_invoice',
- 'gudang_id',
- 'gudang.name as gudangnama',
- 'transaction_purchase_detail.transaction_purchase_id',
- DB::raw('(CASE
- WHEN transaction_purchase.status = 1 AND status_gudang = 0 THEN 2
- WHEN status_gudang = 1 AND transaction_purchase.status <> 3 THEN 1
- WHEN transaction_purchase.status = 3 THEN 3
- WHEN transaction_purchase.status = 2 THEN 4
- ELSE 5 END ) AS ord')
- );
- $purchase->join('transaction_purchase_detail', 'transaction_purchase_detail.transaction_purchase_id', 'transaction_purchase.id');
- $purchase->join('gudang', 'transaction_purchase_detail.gudang_id', 'gudang.id');
- $purchase->where('flag_status', 0);
- if (session('type') == '') {
- $purchase->whereIn('transaction_purchase.status_invoice', [1, 2]);
- }
- // $purchase->where('transaction_purchase.status_invoice','!=',0);
- $purchase->groupBy('transaction_purchase_detail.transaction_purchase_id');
- $purchase->orderBy('ord', 'ASC');
- $purchase->orderBy('transaction_purchase.updated_at', 'DESC');
- } else {
- $purchase = PurchaseOrder::select(
- 'transaction_purchase.id',
- 'transaction_purchase.dataorder',
- 'no_nota',
- 'kode_rpo',
- 'note',
- 'createdon',
- 'total',
- 'count_cetak',
- 'transaction_purchase.perusahaan_id',
- 'transaction_purchase.created_at',
- 'transaction_purchase.updated_at',
- 'member_id',
- 'sales_id',
- 'expedisi',
- 'expedisi_via',
- 'transaction_purchase.status',
- 'status_po',
- 'status_gudang',
- 'status_invoice',
- 'gudang_id',
- 'gudang.name as gudangnama',
- 'transaction_purchase_detail.transaction_purchase_id',
- );
- $purchase->join('transaction_purchase_detail', 'transaction_purchase_detail.transaction_purchase_id', 'transaction_purchase.id');
- $purchase->join('gudang', 'transaction_purchase_detail.gudang_id', 'gudang.id');
- $purchase->where('flag_status', 0);
- $purchase->groupBy('transaction_purchase_detail.transaction_purchase_id');
- $purchase->orderBy('transaction_purchase.status', 'ASC');
- $purchase->orderBy('status_gudang', 'ASC');
- $purchase->orderBy('transaction_purchase.updated_at', 'DESC');
- }
- if (array_key_exists($request->order[0]['column'], $this->original_column)) {
- $purchase->orderByRaw($this->original_column[$request->order[0]['column']] . ' ' . $request->order[0]['dir']);
- }
- if ($request->filter_perusahaan != "") {
- $purchase->where('transaction_purchase.perusahaan_id', $request->filter_perusahaan);
- }
- if ($request->filter_member != "") {
- $purchase->where('transaction_purchase.member_id', $request->filter_member);
- }
- if ($request->type != "") {
- if ($request->type == '0') {
- if ($request->user()->can('purchaseorder.liststatuspo')) {
- $purchase->where('transaction_purchase.flag_status', 0);
- } else if ($request->user()->can('purchaseorder.liststatusinvoiceawal')) {
- $purchase->whereIn('transaction_purchase.status_invoice', [1, 2]);
- $purchase->where('transaction_purchase.flag_status', 0);
- }
- }
- //LIST PO TOLAK : HARGA BISA DIUBAH
- if ($request->type == '1') {
- $purchase->where('transaction_purchase.status_invoice', 2);
- $purchase->where('transaction_purchase.status_gudang', 2);
- $purchase->where('transaction_purchase.flag_status', 0);
- $purchase->where('transaction_purchase.type', 2);
- }
- //VALIDASI HARGA
- if ($request->type == '2') {
- $purchase->where('transaction_purchase.status_invoice', 0);
- $purchase->where('transaction_purchase.status_gudang', 0);
- $purchase->where('transaction_purchase.flag_status', 0);
- $purchase->where('transaction_purchase.status', 1);
- }
- //UNTUK GUDANG
- if ($request->type == '3') {
- $purchase->where('transaction_purchase.flag_status', 0);
- $purchase->where('gudang_id', $request->type_gudang);
- }
- }
- if ($search) {
- $purchase->where(function ($query) use ($search) {
- $query->orWhere('no_nota', 'LIKE', "%{$search}%");
- $query->orWhere('kode_rpo', 'LIKE', "%{$search}%");
- });
- }
- $totalData = $purchase->get()->count();
- $totalFiltered = $purchase->get()->count();
- $purchase->limit($limit);
- $purchase->offset($start);
- $data = $purchase->get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement