This is my code. I fetch the data from same table for sales, and purchase. But the problem is, I cannot merge the two queries into one.
I want to make report date wise for both. First check the date for purchase and sales. If purchase has made then sale should subtract from purchase on same date.
Here is my code live link: https://mmimonir.xyz/vat_purchage_homepage
How i achieve this?
$purchage_data = Core::rightJoin('vehicles', 'vehicles.model_code', '=', 'cores.model_code')
->select(
'cores.id',
'cores.model_code',
'cores.vat_code',
'vehicles.model',
'cores.uml_mushak_no',
'cores.mushak_date',
'cores.vat_rebate',
DB::raw('MONTH(cores.mushak_date) as month'),
DB::raw('1 as quantity')
)
->where('cores.vat_code', "=", $vat_code)
->whereBetween('cores.mushak_date', [$start_date, $end_date])
->orderBy('cores.mushak_date', 'asc')
->get()
->groupBy(['model', 'month', 'uml_mushak_no']);
$sale_data = Core::rightJoin('vehicles', 'vehicles.model_code', '=', 'cores.model_code')
->select(
'cores.id',
'cores.customer_name',
'cores.nid_no',
'cores.model_code',
'cores.full_address',
'cores.vat_code',
'cores.five_chassis',
'cores.five_engine',
'cores.vat_sale_date',
'cores.sale_mushak_no',
'cores.basic_price_vat',
'cores.sale_vat',
'cores.unit_price_vat',
'vehicles.model',
'cores.uml_mushak_no',
'cores.mushak_date',
DB::raw('MONTH(cores.vat_sale_date) as month'),
DB::raw('1 as quantity')
)
->where('cores.vat_code', "=", $vat_code)
->whereBetween('cores.vat_sale_date', [$start_date, $end_date])
->orderBy('cores.sale_mushak_no', 'asc')
->get()
->groupBy(['model', 'month', 'vat_sale_date']);