/**
  * Returns an singleton instance of this class
  *
  * @param object $config
  * @param object $args
  * @return
  */
 public static function getInstance($config, $args)
 {
     if (self::$instance == null) {
         self::$instance = new ItemWarrantiesManager($config, $args);
     }
     return self::$instance;
 }
 public function service()
 {
     //todo check if user have access to given company
     $customer = $this->sessionManager->getUser();
     $cId = $customer->getId();
     $companyId = $this->args[0];
     if ($companyId != $cId) {
         return false;
     }
     $companyManager = CompanyManager::getInstance($this->config, $this->args);
     $company = $companyManager->selectByPK($companyId);
     if (!$company) {
         return false;
     }
     $ex = new excel_xml();
     $header_style = array('bold' => 1, 'size' => '12', 'color' => '#FFFFFF', 'bgcolor' => '#4F81BD');
     $ex->add_style('header', $header_style);
     $ex->add_row(array('Serial Number', 'Category', 'Customer', 'Customer Warranty Period', 'Customer Purchase Date', 'Supplier', 'Purchase Date From Supplier', 'Supplier Warranty Period'), 'header');
     $itemWarrantiesManager = ItemWarrantiesManager::getInstance($this->config, $this->args);
     $allItemsWarrantiesDtos = $itemWarrantiesManager->getCompanyAllWarrantyItems($companyId);
     foreach ($allItemsWarrantiesDtos as $key => $itemWarrantyDto) {
         $c1 = $itemWarrantyDto->getSerialNumber();
         $c2 = $itemWarrantyDto->getItemCategory();
         $c3 = $itemWarrantyDto->getBuyer();
         $c4 = $itemWarrantyDto->getCustomerWarrantyPeriod();
         $c5 = $itemWarrantyDto->getCustomerWarrantyStartDate();
         $c6 = $itemWarrantyDto->getSupplier();
         $c7 = $itemWarrantyDto->getSupplierWarrantyStartDate();
         $c8 = $itemWarrantyDto->getSupplierWarrantyPeriod();
         $ex->add_row(array($c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8));
     }
     $ex->create_worksheet('Items Warranties');
     $ex->generate();
     $ex->download($this->args[1]);
 }
 public function service()
 {
     $itemWarrantiesManager = new ItemWarrantiesManager($this->config, $this->args);
     $action_type = $this->secure($_REQUEST["action_type"]);
     if (isset($_REQUEST["warranty_item_id"])) {
         $warranty_item_id = $this->secure($_REQUEST["warranty_item_id"]);
         $wDto = $itemWarrantiesManager->selectByPK($warranty_item_id);
         if ($wDto->getCompanyId() != $this->sessionManager->getUser()->getId()) {
             $jsonArr = array('status' => "err", "errText" => "System Error: Permission denied!");
             echo json_encode($jsonArr);
             return false;
         }
     }
     //todo check company id and item warranty company_id should be the same
     if ($action_type === "delete") {
         $warranty_item_id = $this->secure($_REQUEST["warranty_item_id"]);
         $itemWarrantiesManager->deleteByPK($warranty_item_id);
     } else {
         $serial_number = $this->secure($_REQUEST["serial_number"]);
         $item_buyer = $this->secure($_REQUEST["item_buyer"]);
         $customer_warranty_start_date = $this->secure($_REQUEST["customer_warranty_start_date"]);
         $item_category = $this->secure($_REQUEST["item_category"]);
         $warranty_period = $this->secure($_REQUEST["warranty_period"]);
         $supplier = $this->secure($_REQUEST["supplier"]);
         $supplier_warranty_start_date = $this->secure($_REQUEST["supplier_warranty_start_date"]);
         $supplier_warranty_period = $this->secure($_REQUEST["supplier_warranty_period"]);
         $companyId = $this->sessionManager->getUser()->getId();
         $valFields = $this->validateFields($serial_number, $item_buyer, $item_category, $warranty_period);
         if ($valFields !== 'ok') {
             $jsonArr = array('status' => "err", "errText" => $valFields);
             echo json_encode($jsonArr);
             return false;
         }
         if ($action_type === "add") {
             $itemWarrantiesManager->addItemWarranty($companyId, $serial_number, $item_buyer, $item_category, $warranty_period, $customer_warranty_start_date, $supplier, $supplier_warranty_start_date, $supplier_warranty_period);
         } elseif ($action_type === "edit") {
             $warranty_item_id = $this->secure($_REQUEST["warranty_item_id"]);
             $itemWarrantiesManager->editItemWarranty($warranty_item_id, $companyId, $serial_number, $item_buyer, $item_category, $warranty_period, $customer_warranty_start_date, $supplier, $supplier_warranty_start_date, $supplier_warranty_period);
         }
     }
     $jsonArr = array('status' => "ok");
     echo json_encode($jsonArr);
     return true;
 }
예제 #4
0
 public function load()
 {
     $item_warranty_options = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 'Lifetime');
     $item_warranty_categories_options = array('Not Specified', 'Laptop', 'HDD', 'DVD/Blu-ray', 'Motherboard', 'Memory (RAM)', 'Processor (CPU)', 'Monitor', 'Graphics Card', 'UPS', 'Printer', 'Network', 'Other');
     $this->addParam('item_warranty_options', $item_warranty_options);
     $this->addParam('item_warranty_categories_options', $item_warranty_categories_options);
     $companyId = $this->sessionManager->getUser()->getId();
     $itemWarrantiesManager = ItemWarrantiesManager::getInstance($this->config, $this->args);
     $search_serial_number = null;
     if (isset($_REQUEST["search_serial_number"])) {
         $search_serial_number = $this->secure($_REQUEST["search_serial_number"]);
     }
     $ItemsWarranties = $itemWarrantiesManager->getCompanyWarrantyItems($companyId, $search_serial_number, 0, 500);
     $this->addParam('ItemsWarranties', $ItemsWarranties);
     $this->addParam('search_serial_number', $search_serial_number);
     if (isset($_REQUEST["warranty_item_id"])) {
         $warranty_item_id = $this->secure($_REQUEST["warranty_item_id"]);
         $itemWarrantyDto = $itemWarrantiesManager->selectByPK($warranty_item_id);
         $itemCategory = $itemWarrantyDto->getItemCategory();
         $serialNumber = $itemWarrantyDto->getSerialNumber();
         $buyer = $itemWarrantyDto->getBuyer();
         $customerWarrantyPeriod = $itemWarrantyDto->getCustomerWarrantyPeriod();
         $customerWarrantyStartDate = $itemWarrantyDto->getCustomerWarrantyStartDate();
         $supplier = $itemWarrantyDto->getSupplier();
         $supplierWarrantyStartDate = $itemWarrantyDto->getSupplierWarrantyStartDate();
         $supplierWarrantyPeriod = $itemWarrantyDto->getSupplierWarrantyPeriod();
         $this->addParam('item_warranty_categories_options_selected', $itemCategory);
         $this->addParam('item_warranty_options_selected', $customerWarrantyPeriod);
         $this->addParam('serial_number', $serialNumber);
         $this->addParam('buyer', $buyer);
         $this->addParam('customer_warranty_start_date', $customerWarrantyStartDate);
         $this->addParam('supplier', $supplier);
         $this->addParam('supplier_warranty_start_date', $supplierWarrantyStartDate);
         $this->addParam('supplier_warranty_period', $supplierWarrantyPeriod);
         $this->addParam('warranty_item_id', $warranty_item_id);
     } else {
         $this->addParam('item_warranty_categories_options_selected', $item_warranty_categories_options[0]);
         $this->addParam('item_warranty_options_selected', $item_warranty_options[12]);
         $this->addParam('supplier_warranty_period', $item_warranty_options[12]);
     }
     $this->addParam('company_id', $companyId);
 }