“columns”: [{
title: “ID”,
width: “1%”
},
{
data: “item”,
render: function(data, type, row) {
return row.item;
},
width: “10%”
},
{
data: “total_OS”,
width: “5%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_P”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_DLI”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_DLIR”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_CN”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_PRO”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_CV_production”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_SA_excess”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_PS_production”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: function ( data, type, row ) {
return (parseFloat(data.total_OS)) + (parseFloat(data.total_p))
},
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_S”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_DLO”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_DLOR”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_DN”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_CV_consumption”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_SA_short”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “qty_PS_consumption”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: “total_s”,
width: “10%”,
render: $.fn.dataTable.render.number(‘,’, ‘.’, $decimal_point, ”)
},
{
data: function ( data, type, row ) {
return ((parseInt(data.total_OS, 10) + parseInt(data.total_p, 10)) + (parseInt(data.total_s, 10)));
},
width: “10%”
},
], this is controller public function getStockCategoryToSalesReport(Request $request)
{
$invController = new invoiceController();
$is_permission = $invController->checkPermissions("stockcategory_to_sales", Role::LIST_PERMISSION);
if (!$is_permission) {
Flash::error('You have no permission.');
return redirect()->back();
}
$created_for = User::GetCreatedForID();
if ($request->get('user')) {
$dealerId = $request->get('user');
$dealer_det = Dealer::find($dealerId);
$created_for = $dealer_det->userid;
}
/*if ($request->get('category') == 'DL') {
$item_data = InvoiceDetails::join('invoices', 'invoices.id', '=', 'invoice_details.invoice_id')
->join('items', 'items.id', '=', 'invoice_details.item_id')
->where("invoices.voucher_type", Invoice::DELIVERY_NOTE)
->whereIn("invoices.delivery_type", [Invoice::INWARD, Invoice::OUTWARD])
->whereBetween("invoices.inv_date", [$request->get('fromdate'), $request->get('todate')])
->where("invoices.created_for", $created_for)
->where("invoices.status", Role::STATUS_ACTIVE)
->whereNull("invoices.deleted_at")
->selectRaw('
sum(case when invoice_details.qty > 0 then invoice_details.qty else 0 end) as qty_inward,
sum(case when invoice_details.qty < 0 then invoice_details.qty else 0 end) as qty_outward,
invoice_details.rate as rate,items.item_name as item_name,
sum(invoice_details.qty) as stock,
invoices.id as invoice_no')
->orderBy('items.item_name')
->groupBy('items.item_name')
->get();
}*/
// $item_name = $request->get('item_name');
// dd($request->item_id);
// dd($request);
// $item_data = InvoiceDetails::join(‘invoices’, ‘invoices.id’, ‘=’, ‘invoice_details.invoice_id’)
// ->join(‘items’, ‘items.id’, ‘=’, ‘invoice_details.item_id’)
// ->whereIn(“invoices.voucher_type”, [Invoice::DELIVERY_NOTE, Invoice::SALES, Invoice::PURCHASES, Invoice::DEBIT_CREDIT_NOTE, Invoice::POS, Invoice::OPENING_STOCK, Invoice::CONVERSION, Invoice::STOCK_ADJUSTMENT, Invoice::PRODUCTION_SHEET, Invoice::PRODUCTION_ORDER])
// //->whereIn(“invoices.delivery_type”, [Invoice::INWARD, Invoice::OUTWARD])
// ->whereBetween(“invoices.inv_date”, [$request->get(‘fromdate’), $request->get(‘todate’)])
// ->where(“items.id”,$request->item_id)
// //->where(“invoices.created_for”, $created_for)
// // ->where(“items.item_name”)
// ->where(“invoices.status”, Role::STATUS_ACTIVE)
// ->whereNull(“invoices.deleted_at”)
// ->selectRaw(‘ invoices.inv_date as date,
// sum(case when invoice_details.qty > 0 and invoices.voucher_type = “P” then invoice_details.qty else 0 end) as qty_P,
// sum(case when invoices.voucher_type = “DL” and invoices.delivery_type = “inward” then invoice_details.qty else 0 end) as qty_DLI,
// sum(case when invoices.voucher_type = “DL” and invoices.delivery_type = “IR” then invoice_details.qty else 0 end) as qty_DLIR,
// sum(case when invoices.voucher_type = “DC” and invoices.delivery_type = “CN” then invoice_details.qty else 0 end) as qty_CN,
// sum(case when invoice_details.qty > 0 and invoices.voucher_type = "PRO" then invoice_details.qty else 0 end) as qty_PRO,
// sum(case when invoices.voucher_type = "CV" and invoices.delivery_type = "production" then invoice_details.qty else 0 end) as qty_CV_production,
// sum(case when invoices.voucher_type = "SA" and invoices.delivery_type = "excess" then invoice_details.qty else 0 end) as qty_SA_excess,
// sum(case when invoices.voucher_type = "PS" and invoices.delivery_type = "production" then invoice_details.qty else 0 end) as qty_PS_production,
// sum(case when invoices.voucher_type = "POS" or invoices.voucher_type = "S" then invoice_details.qty else 0 end) as qty_S,
// sum(case when invoices.voucher_type = "DL" and invoices.delivery_type = "outward" then invoice_details.qty else 0 end) as qty_DLO,
// sum(case when invoices.voucher_type = "DL" and invoices.delivery_type = "OR" then invoice_details.qty else 0 end) as qty_DLOR,
// sum(case when invoices.voucher_type = "DC" and invoices.delivery_type = "DN" then invoice_details.qty else 0 end) as qty_DN,
// sum(case when invoices.voucher_type = "CV" and invoices.delivery_type = "consumption" then invoice_details.qty else 0 end) as qty_CV_consumption,
// sum(case when invoices.voucher_type = "SA" and invoices.delivery_type = "short" then invoice_details.qty else 0 end) as qty_SA_short,
// sum(case when invoices.voucher_type = "PS" and invoices.delivery_type = "consumption" then invoice_details.qty else 0 end) as qty_PS_consumption,
// sum(case when invoice_details.qty > 0 then invoice_details.qty else 0 end) as total_p,
// sum(case when invoice_details.qty < 0 then invoice_details.qty else 0 end) as total_s,
// sum(case when invoice_details.qty < 0 then invoice_details.qty else 0 end) as qty_outward,
// invoice_details.rate as rate,items.item_name as item_name,
// items.item_code as item_code,
// case when items.item_code != "" then items.item_code else items.item_name end as item,
// sum(invoice_details.qty) as stock,
// invoices.id as invoice_no, invoice_details.item_id as item_id')
// ->orderBy('items.item_name')
// ->groupBy('items.item_name');
$item_data = InvoiceDetails::join('invoices', 'invoices.id', '=', 'invoice_details.invoice_id')
->join('items', 'items.id', '=', 'invoice_details.item_id')
->join('stock_group','stock_group.id', '=', 'items.group_id')
->whereIn("invoices.voucher_type", [Invoice::DELIVERY_NOTE, Invoice::SALES, Invoice::PURCHASES, Invoice::DEBIT_CREDIT_NOTE, Invoice::POS, Invoice::OPENING_STOCK, Invoice::CONVERSION, Invoice::STOCK_ADJUSTMENT, Invoice::PRODUCTION_SHEET, Invoice::PRODUCTION_ORDER])
//->whereIn("invoices.delivery_type", [Invoice::INWARD, Invoice::OUTWARD])
->whereBetween("invoices.inv_date", [$request->get('fromdate'), $request->get('todate')])
->when($request->item_id !== null, function ($query) use ($request) {
$query->where("items.id", $request->item_id);
})
->where(“stock_group.id”, $request->group_id)
//->where("invoices.created_for", $created_for)
// ->where("items.item_name")
->where("invoices.status", Role::STATUS_ACTIVE)
->whereNull("invoices.deleted_at")
->selectRaw(' invoices.inv_date as date,
sum(case when invoice_details.qty > 0 and invoices.voucher_type = "P" then invoice_details.qty else 0 end) as qty_P,
sum(case when invoices.voucher_type = "DL" and invoices.delivery_type = "inward" then invoice_details.qty else 0 end) as qty_DLI,
sum(case when invoices.voucher_type = "DL" and invoices.delivery_type = "IR" then invoice_details.qty else 0 end) as qty_DLIR,
sum(case when invoices.voucher_type = "DC" and invoices.delivery_type = "CN" then invoice_details.qty else 0 end) as qty_CN,
sum(case when invoice_details.qty > 0 and invoices.voucher_type = "PRO" then invoice_details.qty else 0 end) as qty_PRO,
sum(case when invoices.voucher_type = "CV" and invoices.delivery_type = "production" then invoice_details.qty else 0 end) as qty_CV_production,
sum(case when invoices.voucher_type = "SA" and invoices.delivery_type = "excess" then invoice_details.qty else 0 end) as qty_SA_excess,
sum(case when invoices.voucher_type = "PS" and invoices.delivery_type = "production" then invoice_details.qty else 0 end) as qty_PS_production,
sum(case when invoices.voucher_type = "POS" or invoices.voucher_type = "S" then invoice_details.qty else 0 end) as qty_S,
sum(case when invoices.voucher_type = "DL" and invoices.delivery_type = "outward" then invoice_details.qty else 0 end) as qty_DLO,
sum(case when invoices.voucher_type = "DL" and invoices.delivery_type = "OR" then invoice_details.qty else 0 end) as qty_DLOR,
sum(case when invoices.voucher_type = "DC" and invoices.delivery_type = "DN" then invoice_details.qty else 0 end) as qty_DN,
sum(case when invoices.voucher_type = "CV" and invoices.delivery_type = "consumption" then invoice_details.qty else 0 end) as qty_CV_consumption,
sum(case when invoices.voucher_type = "SA" and invoices.delivery_type = "short" then invoice_details.qty else 0 end) as qty_SA_short,
sum(case when invoices.voucher_type = "PS" and invoices.delivery_type = "consumption" then invoice_details.qty else 0 end) as qty_PS_consumption,
sum(case when invoice_details.qty > 0 then invoice_details.qty else 0 end) as total_p,
sum(case when invoice_details.qty < 0 then invoice_details.qty else 0 end) as total_s,
sum(case when invoice_details.qty < 0 then invoice_details.qty else 0 end) as qty_outward,
invoice_details.rate as rate,items.item_name as item_name,
items.item_code as item_code,
case when items.item_code != "" then items.item_code else items.item_name end as item,
sum(invoice_details.qty) as stock,
invoices.id as invoice_no, invoice_details.item_id as item_id')
->orderBy('items.item_name')
->groupBy('items.item_name');
//->get();
//sum(case when invoices.voucher_type = "OS" then invoice_details.qty else 0 end) as total_OS,
if(Auth::user()->role_id == Role::ROLE_DEALER){
$item_data = $item_data->where("invoices.created_for", $created_for)->get();
} else if(Auth::user()->role_id == Role::ROLE_ADMIN) {
$users = User::where('created_id', $created_for)->pluck('id');
$item_data = $item_data->whereIn("invoices.created_for", $users)->get();
} else if(Auth::user()->role_id == Role::ROLE_MUlTI) {
$user = Auth::user()->parent_id;
$users = explode(',', $user);
$item_data = $item_data->whereIn("invoices.created_for", $users)->get();
}
/*$opening_stock = InvoiceDetails::join('invoices', 'invoices.id', '=', 'invoice_details.invoice_id')
->join('items', 'items.id', '=', 'invoice_details.item_id')
->where("invoices.voucher_type", Invoice::OPENING_STOCK)
->where("invoices.inv_date", "<",$request->get('fromdate'))
//->where("invoices.created_for", $created_for)
->where("invoices.status", Role::STATUS_ACTIVE)
->whereNull("invoices.deleted_at")
->selectRaw('
sum(case when invoices.voucher_type = "OS" then invoice_details.qty else 0 end) as total_OS,
items.item_name as item_name,
items.item_code as item_code,
case when items.item_code != "" then items.item_code else items.item_name end as item,
invoices.id as invoice_no, invoice_details.item_id as item_id')
->orderBy('items.item_name')
->groupBy('items.item_name');
//->get(); */
$opening_stock = InvoiceDetails::join('invoices', 'invoices.id', '=', 'invoice_details.invoice_id')
->join('items', 'items.id', '=', 'invoice_details.item_id')
//->where("invoices.voucher_type", Invoice::OPENING_STOCK)
//->whereNotIn("invoices.voucher_type", [Invoice::SALES_ORDER, Invoice::PURCHASES_ORDER])
->where("invoices.inv_date", "<",$request->get('fromdate'))
//->where("invoices.created_for", $created_for)
->where("invoices.status", Role::STATUS_ACTIVE)
->where("invoice_details.status", Role::STATUS_ACTIVE)
->whereNull("invoices.deleted_at")
->selectRaw('sum(invoice_details.qty) as total_OS,
items.item_name as item_name,
items.item_code as item_code,
case when items.item_code != "" then items.item_code else items.item_name end as item,
invoices.id as invoice_no, invoice_details.item_id as item_id')
->orderBy('items.item_name')
->groupBy('items.item_name');
//->get();
if(Auth::user()->role_id == Role::ROLE_DEALER){
$opening_stock = $opening_stock->where("invoices.created_for", $created_for)->get();
} else if(Auth::user()->role_id == Role::ROLE_ADMIN) {
$users = User::where('created_id', $created_for)->pluck('id');
$opening_stock = $opening_stock->whereIn("invoices.created_for", $users)->get();
} else if(Auth::user()->role_id == Role::ROLE_MUlTI) {
$user = Auth::user()->parent_id;
$users = explode(',', $user);
$opening_stock = $opening_stock->whereIn("invoices.created_for", $users)->get();
}
$array_data = [];
foreach($item_data as $item_data){
foreach($opening_stock as $stock){
if($item_data->item_id == $stock->item_id){
$data = array_merge($item_data->toArray(),$stock->toArray());
array_push($array_data, $data);
}
}
}
return $array_data;
//return Response::json($item_data);
}enter image description here
i am trying to solve the error that is arising…. i need to solve that error
Jancy Merin Samson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.