<?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 App\Http\Model\BillModel;
	use App\Http\Model\SaleModel;
	use Validator;
	
	class salesController extends Controller
	{
		public function __construct()
		{
			$this->purshase= new PurchaseModel;
			$this->bills= new BillModel;
			$this->sale= new SaleModel;
		}		
		public function AddSales()
		{
			$bill['Add_Bill']=$this->bills->bill_no();
			$bill['ShedName']=$this->purshase->ShedNAmes();
			$bill['company']=$this->purshase->PurchaseCompany();
			$bill['itemCompany']=$this->purshase->itemCompany();
			$bill['taxanount']=$this->bills->TaxAmount();
			return view('sale',compact('bill'));
		}
		public function itemAmount(Request $request)
		{
			$itemId=$request->input('ItemId');
			$itemAmount=DB::table('itm_item')->where('itm_id',$itemId)->first();
			$data['itemAmount1']=$itemAmount->itm_salescost;
			return $data;
		}
		public function TaxAmount(Request $request)
		{
			$TaxId=$request->input('TaxId');
			$TaxAmount=DB::table('tax_tax')->where('tax_id',$TaxId)->first();
			$data['tax_amt']=$TaxAmount->tax_amt;
			return $data;
		}
		public function billgenerate(Request $request)
		{
			$sub['billtype']=$request->input('billtype');
			$sub['billno']=$request->input('billno');
			$sub['company']=$request->input('company');
			$sub['billdate']=$request->input('billdate');
			$sub['seller']=$request->input('seller');
			$sub['bil_note']=$request->input('bil_note');
			$sub['status']=$request->input('status');
			$sub['shd_id']=$request->input('shedName');
			$sub['bch_id']=$request->input('SubBatch');	
			$sub['billinggrandtotal']=$request->input('billinggrandtotal');	
			
			//itemname itemcost itemquantity
			$sub['itemname']=  $request->input('itemname');
			$sub['itemcost']=$request->input('itemcost');
			$sub['itemquantity']=$request->input('itemquantity');
			
			//Discount
			$sub['discounttype']=$request->input('discounttype');
			$sub['disamt']=$request->input('discountAmount');
			
			//Tax
			$sub['taxid']=$request->input('taxid');
			$sub['taxPercentage']=$request->input('taxPercentage');			 
			
			//Other charges			
			$sub['otherchargetitle']=$request->input('otherchargetitle');
			$sub['otherchargecost']=$request->input('otherchargecost');			 
			
			return $bill=$this->bills->billgenerate($sub);
		}
		public function SalesprintBill(Request $request)
		{
			$data['Billno']=$request->input('Billno');
			$data['ViewPurchase']=$this->bills->printCustomerDetails($data);
			$data['ViewPurchaseItem']=$this->bills->printBillItem($data);
			$data['Discount']=$this->bills->printDiscount($data);
			$data['Taxrecord']=$this->bills->printTax($data);
			$data['OtherCharges']=$this->bills->oth($data);
			$data['CompanyData']=$this->bills->CompanyData();
			return view('SalesPrint',compact('data'));
		}
		public function ViewSales()
		{
		    $data['url']='salesBillView';
		    $Mid=$this->bills->QPermission($data);
			$data['delete']= $Mid->Delete;
			$data['edit']= $Mid->Edit;
			$data['create']= $Mid->create;
			$data['billNo']=$this->bills->ViewQutationOrder();
			return view('SalesView',compact('data'));
		}		
		public function BatchshedNameDetail(Request $request)
		{
			$data['Batch']=$request->input('Batch');
			$BatchshedNameDetail=$this->sale->BatchshedNameDetail($data);
			return json_encode($BatchshedNameDetail);
		}
	}
