Advertisement
rivasalmir

Untitled

Oct 9th, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.04 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Ysa\Core\Block;
  4.  
  5. use Magento\Framework\View\Element\Template as Template;
  6. use Ysa\Core\Model\Api as RequestApi;
  7. use Magento\Framework\View\Element\Template\Context;
  8. use Ysa\Core\Model\RentacarRules;
  9. use Ysa\Core\Helper\Data as Helper;
  10. use Ysa\Core\Model\RentacarLocationContentFactory;
  11.  
  12.  
  13. class BookingRules extends Template
  14. {
  15.     protected $requestApi;
  16.     protected $modelRentacar;
  17.     protected $_helper;
  18.     protected $_locationContent;
  19.     protected $_rentacarLocationContentFactory;
  20.  
  21.     public function __construct(
  22.         RequestApi $requestApi,
  23.         Context $context,
  24.         RentacarRules $modelRentacar,
  25.         Helper $helper,
  26.         RentacarLocationContentFactory $locationContent,
  27.         \Ysa\Core\Model\ResourceModel\RentacarLocationContent\CollectionFactory $rentacarLocationContentFactory,
  28.         array $data = []
  29.     )
  30.     {
  31.         $this->_helper          = $helper;
  32.         $this->requestApi       = $requestApi;
  33.         $this->modelRentacar    = $modelRentacar;
  34.         $this->_locationContent = $locationContent;
  35.         $this->_rentacarLocationContentFactory = $rentacarLocationContentFactory;
  36.  
  37.         parent::__construct($context,$data);
  38.     }
  39.  
  40.     public function getBookingRules()
  41.     {
  42.         $plateCode    = $this->getRequest()->getParam('plancode');
  43.         $responseXml = simplexml_load_string($this->modelRentacar->getRentaCarRules($plateCode));
  44.         $response = $responseXml->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children();
  45.         if($response->count())
  46.         {
  47.             return $response;
  48.         } else {
  49.             return false;
  50.         }
  51.     }
  52.  
  53.  
  54.     //Helper Acriss Code Completo
  55.     public function getAcriss($acriss)
  56.     {
  57.         return $this->_helper->getAcrrisCode($acriss);
  58.     }
  59.  
  60.     //Helper Descrição dos planos
  61.     public function getCarContractDescription($carContract)
  62.     {
  63.         return $this->_helper->getCarContractDescription($carContract);
  64.     }
  65.  
  66.  
  67.     public function getFinalPrice($value)
  68.     {
  69.         return $this->_helper->getFinalPrice($value);
  70.     }
  71.  
  72.     public function getPriceCost($value)
  73.     {
  74.         return $this->_helper->getCostPrice($value);
  75.     }
  76.  
  77.     public function getDaysQty(){
  78.       $start              = strtotime($this->getRequest()->getParam('arrival_date'));
  79.       $end                = strtotime($this->getRequest()->getParam('devolution_date'));
  80.       $days = ($end - $start) / 86400;
  81.       return $days;
  82.     }
  83.  
  84.     public function setPricePerPeriod($price){
  85.       $pricePerPeriod = (float) $price * $this->getDaysQty();
  86.       return number_format($pricePerPeriod, '2',',','.');
  87.     }
  88.  
  89.     public function setPricePerDay($nett){
  90.         $pricePerDay =  (float) $nett / $this->getDaysQty();
  91.         return $this->getFinalPrice($pricePerDay);
  92.     }
  93.  
  94.     public function getLocationContent($code)
  95.     {
  96.         $carContent = $this->_locationContent->create();
  97.         return $carContent->load($code, 'zone_code')->getData();
  98.     }
  99.  
  100.     public function getZoneCodeParam()
  101.     {
  102.         return $this->getRequest()->getParam('zone_code');
  103.     }
  104.  
  105.     public function getRentacarLocationByZoneCode($zoneCode){
  106.  
  107.         $rentacarLocationContentCollection = $this->_rentacarLocationContentFactory->create();
  108.         $rentacarLocationContentCollection->addFieldToFilter('zone_code', ['eq' => $zoneCode]);
  109.         $rentacarLocationContentCollection->setPageSize(10);
  110.         $rentacarLocationContentCollection->getSelect()->__toString();
  111.  
  112.         return $rentacarLocationContentCollection->toArray();
  113.     }
  114.  
  115.     public function getRentacarLocationByCode($rentacarLocationCode){
  116.  
  117.         $rentacarLocationContentCollection = $this->_rentacarLocationContentFactory->create();
  118.         $rentacarLocationContentCollection->addFieldToFilter('code', ['eq' => $rentacarLocationCode]);
  119.         $rentacarLocationContentCollection->setPageSize(10);
  120.         $rentacarLocationContentCollection->getSelect()->__toString();
  121.  
  122.         return $rentacarLocationContentCollection->toArray();
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement