<?php

namespace App\Http\Controllers\pos;

use App\Model\purchase_order\PurchaseOrderDetailModel;
use App\Model\purchase_order\PurchaseOrderModel;
use App\Model\pos\SaleDetailsModel;
use App\Model\pos\SaleModel;
use App\Http\Controllers\Controller;
use Auth;

class PosInvoiceController extends Controller
{
    function posinvoice($id){
        $master = SaleModel::find($id);
        $detail = SaleDetailsModel::selectRaw('nso007_sale_details.*,SUM(nso007_sale_details.qty) as sum_qty')->where('sale_id',$id)->where('status',1)->groupBy('product_id','sale_price')->get();
        return view('pos.invoice.pos-invoice',compact('master','detail'));
    }
    function get_wholesaleinvoice($id){
        $master = SaleModel::find($id);
        $detail = SaleDetailsModel::where('sale_id',$id)->get();
        return view('pos.invoice.wholesale-invoice',compact('master','detail'))->render();
    }
    function get_purchase_order($id){
        $master = PurchaseOrderModel::find($id);
        $detail = PurchaseOrderDetailModel::where('purchase_id',$id)->get();
        return view('pos.invoice.purchase-order-invoice',compact('master','detail'))->render();
    }
    public function find_sale_type($id){
        return response()->json(findSale($id)->sale_type);
    }
}
