<?php
	namespace App\Http\Controllers;
	use Illuminate\Foundation\Bus\DispatchesJobs;
	use Illuminate\Routing\Controller as BaseController;
	use Illuminate\Foundation\Validation\ValidatesRequests;
	use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
	use Illuminate\Foundation\Auth\Access\AuthorizesResources;
	use Illuminate\Http\Request;
	use DB;
	use App\Http\Model\PurchaseModel;
	
	use Validator;
	
	class SalesOrder extends Controller
	{
		public function __construct()
		{
			$this->purshase= new PurchaseModel;
		}
		public function AddSalesOrder()
		{
			$purchase['Add_purchase']=$this->purshase->AddNewPurchase();
			$purchase['company']=$this->purshase->PurchaseCompany();
			$purchase['itemCompany']=$this->purshase->itemCompany();
			return view('salesorder',compact('purchase'));
		} 
		public function SubCompanyDetail(Request $request)
		{
			$sub['compId']=$request->input('compId');
			$purchaseSub=$this->purshase->AddSubPurchase($sub);
			return json_encode($purchaseSub);
		}
		public function SalesBill(Request $request)
		{
			$sub['num']=$request->input('num');
			for($i=1;$i<=$sub['num'];$i++)
			{
				$sub['Schoolname'.$i]=$request->input('Schoolname'.$i);
				$sub['Major'.$i]=$request->input('Major'.$i);
				$sub['Degree'.$i]=$request->input('Degree'.$i);
			}
			$sub['description']=$request->input('description');
			$sub['itemcategory1']=$request->input('itemcategory1');
			$sub['itemcode']=$request->input('itemcode');
			$sub['saleorderdate']=$request->input('saleorderdate');
			$sub['itemcategory']=$request->input('itemcategory');
			$sub['status']=$request->input('status');
			return $purchaseSub=$this->purshase->PurchaseBillitem($sub);
		}
		public function ViewSalesOrder()
		{
		    $data['url']='salesOrderview';
		    $Mid=$this->purshase->QPermission($data);
			$data['delete']= $Mid->Delete;
			$data['edit']= $Mid->Edit;
			$data['create']= $Mid->create;
		    $data['ViewPurchase']=$this->purshase->ViewPurchaseOrder();
			return view('salesorderview',compact('data'));
		}
		public function printBill(Request $request)
		{
			$data['Billno']=$request->input('Billno');
			$data['ViewPurchase']=$this->purshase->printCustomerDetails($data);
			$data['ViewPurchaseItem']=$this->purshase->printBillItem($data);
			$data['CompanyData']=$this->purshase->CompanyData();
			return view('PrintPurchaseOrder',compact('data'));			
		}
		public function printBillNoCheck(Request $request)
		{
		    $data['Billno']=$request->input('Billno');
			$data['ViewPurchase']=$this->purshase->MaxprintCustomerDetails();
			$data['ViewPurchaseItem']=$this->purshase->MaxprintBillItem();
			$data['CompanyData']=$this->purshase->CompanyData();
			return view('purchaseOder',compact('data'));
		}
	}
