src/Parcels/ParcelTransactions.php line 59

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: parcel
  5.  * Date: 10/19/18
  6.  * Time: 11:09 AM
  7.  */
  8. namespace App\Parcels;
  9. use App\Entity\DailyAccount;
  10. use App\Entity\Station;
  11. use App\Entity\Transaction;
  12. use App\Entity\WayBill;
  13. use JMS\Serializer\SerializationContext;
  14. use JMS\Serializer\SerializerBuilder;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  16. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. class ParcelTransactions extends AbstractController {
  22.     /**
  23.      * @Route("/transactions", name="daily_parcel_transactions")
  24.      */
  25.     public function dailyParcelTransactions() {
  26.         return $this->render('fos/parcels/daily_transaction.html.twig', []);
  27.     }
  28.     /**
  29.      * @Route("/transactions/transaction-list",methods={"POST", "GET"}, name="get_all_transactions")
  30.      */
  31.     public function dailyTransactions(Request $request) {
  32.         $em $this->getDoctrine()->getManager();
  33.         $context = new SerializationContext();
  34.         $context->setSerializeNull(true);
  35.         $serializer SerializerBuilder::create()->build();
  36.         if(!$request->getSession()->get('STATION')) {
  37.             $data = [
  38.                 'error' => 'User is not well registered'
  39.             ];
  40.             $data $serializer->serialize($data,'json'$context);
  41.             return new Response($dataResponse::HTTP_OK);
  42.         }
  43.         $user $this->getUser();
  44.         $station_id $request->getSession()->get('STATION');
  45.         $page $request->request->get('page') > $request->request->get('page'): 1;
  46.         $rows $request->request->get('rows') > $request->request->get('rows'): 20;
  47.         $offset = ($page 1)*$rows;
  48.         $filterRules $request->request->get('filterRules');
  49.         $parcels $em->getRepository(Transaction::class)->getTransactions($user->getId(),$station_id$filterRules$offset,$rows);
  50. //        dump($parcels);die;
  51.         /** @var integer $total */
  52.         $total $em->getRepository(Transaction::class)->getTotalTransactions($user->getId(),$station_id$filterRules);
  53.         $transactionDetails $em->getRepository(Transaction::class)->fosTotals($user->getId(),$station_id$filterRules);
  54. //        dump($total['rows']); die;
  55.         $dailyAccount = new DailyAccount();
  56.         $transaction = new Transaction();
  57.         $transaction->setAmount(number_format($transactionDetails['amount']));
  58.         $transaction->setTaxAmount(number_format($transactionDetails['tax_amount']));
  59.         $transaction->setDailyAccount($dailyAccount);
  60.         $transaction->setStationExpenses(number_format($transactionDetails['station_expenses']));
  61.         $transaction->setBalance(number_format($transactionDetails['balance']));
  62.         $wayBill = new WayBill();
  63.         $wayBill->setPercelCount(number_format($transactionDetails['parcel_count']));
  64.         $wayBill->setReceiverPhoneNumber('Total');
  65.         $wayBill->setFromStation(new Station());
  66.         $wayBill->setToStation(new Station());
  67.         $transaction->setWayBill($wayBill);
  68.         $footerTotals = array();
  69.         array_push($footerTotals$transaction);
  70.         $data = [
  71.             'total'  => $total['rows'],
  72.             'rows'   => $parcels,
  73.             'footer' => $footerTotals
  74.         ];
  75.         dump($footerTotals);
  76. //        $data = $serializer->serialize($data,'json', $context);
  77.         return new JsonResponse($dataResponse::HTTP_OK);
  78.     }
  79.     /**
  80.      * @Method("get")
  81.      * @Route("/transactions/details/{id}", name="one_transaction_detail_parcel")
  82.      */
  83.     public function getDetailParcel($id){
  84.         $em $this->getDoctrine()->getManager();
  85.         $transaction $em->getRepository(Transaction::class)->findOneBy([
  86.             'wayBill' => $id
  87.         ]);
  88.         return $this->render('fos/transactions/transaction_detail.html.twig',[
  89.             'transaction' => $transaction
  90.         ]);
  91.     }
  92. }