<?php
namespace ApplicationBundle\Modules\MarketPlace\Controller;
use ApplicationBundle\Constants\EmployeeConstant;
use ApplicationBundle\Constants\GeneralConstant;
use ApplicationBundle\Controller\GenericController;
use ApplicationBundle\Modules\Authentication\Constants\UserConstants; use ApplicationBundle\Modules\Api\Constants\ApiConstants;
use ApplicationBundle\Modules\Buddybee\Buddybee;
use ApplicationBundle\Modules\System\MiscActions;
use ApplicationBundle\Modules\User\Company;
use ApplicationBundle\Modules\Inventory\Inventory;
use CompanyGroupBundle\Entity\EntityCreateTopic;
use CompanyGroupBundle\Entity\EntityInvoice;
use CompanyGroupBundle\Entity\EntityMeetingSession;
use Endroid\QrCode\Builder\BuilderInterface;
use Endroid\QrCodeBundle\Response\QrCodeResponse;
use Ps\PdfBundle\Annotation\Pdf;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use CompanyGroupBundle\Entity\EntityApplicantDetails;
use Symfony\Component\Routing\Generator\UrlGenerator;
class MarketPlacePublicController extends GenericController
{
// home
public function HomeViewAction(Request $request, $id = 0)
{
$em = $this->getDoctrine()->getManager();
$companyId = $this->getLoggedUserCompanyId($request);
$company_data = Company::getCompanyData($em, $companyId);
$products = $em->getRepository('ApplicationBundle\\Entity\\InvProducts')->findOneBy(
array(
'id' => $id
)
);
$dataArray = array(
'page_title' => 'Home',
'company_data' => $company_data,
'products' => $products,
'brandList' => Inventory::GetBrandList($em, $companyId),
'igList' => Inventory::ItemGroupList($em, $companyId)
);
return $this->render('@MarketPlace/pages/views/market_place_home_view.html.twig', $dataArray
);
}
public function CompareProductViewAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
if ($request->get('returnJson', 0) == 1) {
$pids = $request->get('pIds', []);
$tempProductData = $em->getRepository('ApplicationBundle\\Entity\\InvProducts')
->findBy(
array(
'id' => $pids
)
);
// For FIFO structure
$productDataObjects = [];
foreach ($pids as $pid) {
foreach ($tempProductData as $tempProduct) {
if ($tempProduct->getId() == $pid) {
$productDataObjects[] = $tempProduct;
break;
}
}
}
$data = [];
$specIds = [];
$specListById = [];
foreach ($productDataObjects as $productDataObject) {
$specData = [];
$tempSpecData = json_decode($productDataObject->getSpecData(), true);
if ($tempSpecData == null) $tempSpecData = [];
foreach ($tempSpecData as $indSpecData) {
$specData[$indSpecData['id']] = [
'id' => $indSpecData['id'],
'value' => $indSpecData['value']
];
if (!in_array($indSpecData['id'], $specIds))
$specIds[] = $indSpecData['id'];
}
$d = array(
'id' => $productDataObject->getId(),
'name' => $productDataObject->getName(),
'defaultImage' => $productDataObject->getDefaultImage(),
'specData' => $specData,
);
$data[] = $d;
}
$specList = $em->getRepository('ApplicationBundle\\Entity\\SpecType')
->findBy(
array(
'id' => $specIds
)
);
$specListById = [];
foreach ($specList as $specHere) {
$specListById[$specHere->getId()] = $specHere->getName();
}
return new JsonResponse(array('data' => $data, 'specListById' => $specListById, 'specIds' => $specIds));
// foreach ($specData as $specDatum){
// $finSpecData[]=[
// 'id' => $specDatum['id'],
// 'name' => isset($specListById[$specDatum['id']])?$specListById[$specDatum['id']]:'',
// 'value' => $specDatum['value']
// ];
// }
}
return $this->render('@MarketPlace/pages/views/market_place_compare_products.html.twig',
array(
'page_title' => 'Compare Products',
));
}
// about us
public function AboutUsViewAction()
{
return $this->render('@MarketPlace/pages/views/market_place_about_us.html.twig',
array(
'page_title' => 'About Us',
));
}
// our product
public function ProductListAction(Request $request, $id = 0)
{
$em = $this->getDoctrine()->getManager();
$companyId = $this->getLoggedUserCompanyId($request);
$company_data = Company::getCompanyData($em, $companyId);
$products = $em->getRepository('ApplicationBundle\\Entity\\InvProducts')->findOneBy(
array(
'id' => $id
)
);
$dataArray = array(
'page_title' => 'Our Product',
'company_data' => $company_data,
'products' => $products,
'brandList' => Inventory::GetBrandList($em, $companyId),
'igList' => Inventory::ItemGroupList($em, $companyId)
);
return $this->render('@MarketPlace/pages/list/market_place_product_list.html.twig', $dataArray
);
}
// our prpject
public function OurProjectAction()
{
return $this->render('@MarketPlace/pages/views/market_place_our_project.html.twig',
array(
'page_title' => 'Our Project',
)
);
}
// single project
public function SingleProjectAction()
{
return $this->render('@MarketPlace/pages/views/market_place_single_project.html.twig',
array(
'page_title' => 'Project Details',
)
);
}
// single product
public function ProductViewAction(Request $request, $id = 0)
{
$em = $this->getDoctrine()->getManager();
$companyId = $this->getLoggedUserCompanyId($request);
$company_data = Company::getCompanyData($em, $companyId);
$data = [];
$ex_id = $id;
$specData = [];
$specIds = [];
$productData = $em->getRepository('ApplicationBundle\\Entity\\InvProducts')
->findOneBy(
array(
'id' => $id,
)
);
if ($productData) {
$tempSpecData = json_decode($productData->getSpecData(), true);
if ($tempSpecData == null) {
$tempSpecData = [];
}
foreach ($tempSpecData as $indx) {
$specData[] = [
'id' => $indx['id'],
'value' => $indx['value'],
];
$specIds[] = $indx['id'];
}
}
$specList = $em->getRepository('ApplicationBundle\\Entity\\SpecType')->findBy(
array(
'id' => $specIds
)
);
$specListById = [];
foreach ($specList as $specDatum) {
$specListById[$specDatum->getId()] = $specDatum->getName();
}
$finSpecData = [];
foreach ($specData as $specDatum) {
$finSpecData[] = [
'id' => $specDatum['id'],
'name' => isset($specListById[$specDatum['id']]) ? $specListById[$specDatum['id']] : '',
'value' => $specDatum['value'],
];
}
$productFdm = $productData->getProductFdm();
preg_match('/SZ(\d+)/', $productFdm, $szMatch);
preg_match('/SO(\d+)/', $productFdm, $soMatch);
preg_match('/ST(\d+)/', $productFdm, $stMatch);
preg_match('/SH(\d+)/', $productFdm, $shMatch);
$subCategoryZeroId = $szMatch[1] ?? null;
$subCategoryOneId = $soMatch[1] ?? null;
$subCategoryTwoId = $stMatch[1] ?? null;
$subCategoryThreeId = $shMatch[1] ?? null;
// dump($subCategoryOneId);
$currInvList = $em->getRepository('ApplicationBundle\\Entity\\InventoryStorage')
->findBy(
array(
'productId' => $id
)
);
$trans_history = $em->getRepository('ApplicationBundle\\Entity\\InvItemTransaction')
->findBy(
array(
'productId' => $id
), array(
'transactionDate' => 'ASC',
'id' => 'ASC'
)
);
$igData = $em->getRepository('ApplicationBundle\\Entity\\InvItemGroup')
->findOneBy(array(
'id' => $productData->getIgId(),
));
$itemGroupList = [];
$categorizationData = json_decode($igData->getCategorizationData(), true) ??
[
["alias" => "Category", "en" => 1, "inc" => "1"],
["alias" => "Sub Category", "en" => 1, "inc" => "1"],
];
$subCategoryTypes = $em->getRepository('ApplicationBundle\\Entity\\InvProductSubCategories')
->findBy(array(
'id' => [$subCategoryZeroId, $subCategoryOneId, $subCategoryTwoId, $subCategoryThreeId],
));
$subCategoryTypeList = [];
foreach ($subCategoryTypes as $sc) {
$subCategoryTypeList[$sc->getId()] = $sc->getName();
}
$productDataObj = array();
if ($request->isMethod('POST') && $request->request->has('returnJson')) {
$getters = array_filter(get_class_methods($productData), function ($method) {
return 'get' === substr($method, 0, 3);
});
foreach ($getters as $getter) {
if ($getter == 'getGlobalId')
continue;
$Fieldname = str_replace('get', '', $getter);
$productDataObj[$Fieldname] = $productData->{$getter}(); // `foo!`
}
if ($request->request->has('genInfoOnly') && $request->request->get('genInfoOnly') == 1) {
$dataArray = array(
'success' => true,
'page_title' => 'Product Details',
'company_data' => $company_data,
'ex_id' => $ex_id,
'productData' => $productData,
'productDataObj' => $productDataObj,
'defaultImageAppendUrl' => '/uploads/Products/',
);
} else {
$dataArray = array(
'success' => true,
'page_title' => 'Product Details',
'og_title' => $productDataObj->getName(),
'og_image' => $productDataObj->getDefaultImage(),
'company_data' => $company_data,
'ex_id' => $ex_id,
'productData' => $productData,
'productDataObj' => $productDataObj,
'finSpecData' => $finSpecData,
'currInvList' => $currInvList,
'trans_history' => $trans_history,
'entityList' => GeneralConstant::$Entity_list_details,
'itemGroupList' => $itemGroupList,
'categorizationData' => $categorizationData,
'products' => Inventory::ProductList($this->getDoctrine()->getManager()),
'subCategoryList' => $subCategoryTypeList,
'categoryList' => Inventory::ProductCategoryList($em, $companyId),
'igList' => Inventory::ItemGroupList($em, $companyId),
'unitList' => Inventory::UnitTypeList($em),
'brandList' => Inventory::GetBrandList($em, $companyId),
'warehouse_action_list' => Inventory::warehouse_action_list($em, $this->getLoggedUserCompanyId($request), 'object'),
'warehouseList' => Inventory::WarehouseList($em),
'defaultImageAppendUrl' => '/uploads/Products/',
);
}
return new JsonResponse(
$dataArray
);
}
$dataArray = array(
'page_title' => 'Product Details',
'company_data' => $company_data,
'ex_id' => $ex_id,
'productData' => $productData,
'finSpecData' => $finSpecData,
'currInvList' => $currInvList,
'trans_history' => $trans_history,
'entityList' => GeneralConstant::$Entity_list_details,
'productList' => Inventory::ProductList($em, $companyId),
'itemGroupList' => $itemGroupList,
'categorizationData' => $categorizationData,
'subCategoryZeroId' => $subCategoryZeroId,
'subCategoryOneId' => $subCategoryOneId,
'subCategoryTwoId' => $subCategoryTwoId,
'subCategoryThreeId' => $subCategoryThreeId,
//'productList' => Inventory::ProductList($em, $companyId),
'products' => Inventory::ProductList($this->getDoctrine()->getManager()),
'subCategoryList' => $subCategoryTypeList,
'categoryList' => Inventory::ProductCategoryList($em, $companyId),
'igList' => Inventory::ItemGroupList($em, $companyId),
'unitList' => Inventory::UnitTypeList($em),
'spec_type' => Inventory::SpecTypeList($this->getDoctrine()->getManager()),
'brandList' => Inventory::GetBrandList($em, $companyId),
'warehouse_action_list' => Inventory::warehouse_action_list($em, $this->getLoggedUserCompanyId($request), 'object'),
'warehouseList' => Inventory::WarehouseList($em),
);
return $this->render('@MarketPlace/pages/views/market_place_product_view.html.twig', $dataArray
);
}
// ** list related page **
// customer plant
public function CustomerPlantViewAction()
{
return $this->render('@MarketPlace/pages/list/market_place_build_customer_plant_list.html.twig',
array(
'page_title' => 'Build Customer plant',
));
}
// *****sofia project started*****
// sign in page
public function SofiaSignIn()
{
return $this->render('@MarketPlace/pages/views/sofia_login.html.twig',
array(
'page_title' => 'Sofia Login',
));
}
// sign up page
public function SofiaSignUp()
{
return $this->render('@MarketPlace/pages/views/sofia_signup.html.twig',
array(
'page_title' => 'Sofia Signup',
));
}
// confirmation
public function SofiaConfirmation()
{
return $this->render('@MarketPlace/pages/views/sofia_confirmation.html.twig',
array(
'page_title' => 'Sofia Confirmation',
));
}
// create site
public function SofiaCreatesite()
{
return $this->render('@MarketPlace/pages/views/sofia_create_site.html.twig',
array(
'page_title' => 'Create Site',
));
}
// dashboard details
public function SofiaDashboardDetails()
{
return $this->render('@MarketPlace/pages/views/sofia_dashboard_details.html.twig',
array(
'page_title' => 'Create Site',
));
}
// dashboard admin
public function SofiaDashboardCheckSiteHeartbeat(Request $request, $id = 0)
{
$sitesQry = $this->getDoctrine()->getManager('company_group')
->getRepository("CompanyGroupBundle\\Entity\\EmsSite")
->findBy(array(
'id' => $request->get('site_ids')
));
$sites = [];
foreach ($sitesQry as $site) {
$siteDT = array(
'siteId' => $site->getId(),
'siteName' => $site->getSiteName(),
'siteNote' => $site->getSiteNote(),
'siteLocation' => $site->getSiteLocation(),
'address' => $site->getAddress(),
'siteActive' => 0,
'lastDataSince' => 0,
);
$siteDataQry = $this->getDoctrine()->getManager('company_group')
->getRepository("CompanyGroupBundle\\Entity\\DeviceSensorData")
->findOneBy(array(
'siteId' => $site->getId(),
), array(
'timestampTs' => 'DESC'
));
if ($siteDataQry) {
$siteDT['lastDataSince'] = $siteDataQry->getTimestampTs();
}
$sites[] = $siteDT;
}
return new JsonResponse(array(
'success' => true,
'sites' => $sites,
'siteIds' => $request->get('site_ids'),
));
}
public function SofiaDashboardAdmin()
{
$sitesQry = $this->getDoctrine()->getManager('company_group')
->getRepository("CompanyGroupBundle\\Entity\\EmsSite")
->findBy(array());
$sites = [];
$siteIds = [];
foreach ($sitesQry as $site) {
$siteDT = array(
'siteId' => $site->getId(),
'siteName' => $site->getSiteName(),
'siteNote' => $site->getSiteNote(),
'siteLocation' => $site->getSiteLocation(),
'address' => $site->getAddress(),
'siteActive' => 0,
'lastDataSince' => '',
);
$siteDataQry = $this->getDoctrine()->getManager('company_group')
->getRepository("CompanyGroupBundle\\Entity\\DeviceSensorData")
->findOneBy(array(
'siteId' => $site->getId(),
), array(
'timestampTs' => 'DESC'
));
if ($siteDataQry) {
$siteDT['lastDataSince'] = $siteDataQry->getTimestampTs();
}
$sites[$site->getId()] = $siteDT;
$siteIds[] = 1*$site->getId();
}
return $this->render('@MarketPlace/pages/views/sofia_dashboard_admin.html.twig',
array(
'page_title' => 'Dashboard Admin',
'sites' => $sites,
'siteIds' => $siteIds,
));
}
// dashboard graph
public function SofiaDashboardGraph(Request $request, $id = 0)
{
return $this->render('@MarketPlace/pages/views/sofia_dashboard_graph.html.twig',
array(
'page_title' => 'Dashboard Graph',
'siteId' => $id,
));
}
// dashboard profile
public function SofiaDashboardUserProfile()
{
return $this->render('@MarketPlace/pages/views/sofia_user_profile.html.twig',
array(
'page_title' => 'User Profile',
));
}
}