/**
  * Getting the JSon for PurchaseOrder
  *
  * @param PurchaseOrder $po
  *
  * @return Ambigous <multitype:, multitype:multitype:string  NULL >
  */
 private function _getPOJson(PurchaseOrder $po)
 {
     $array = $po->getJson();
     $array['totalProductCount'] = $po->getTotalProductCount();
     $array['totalReceivedValue'] = $po->getTotalRecievedValue();
     $array['purchaseOrderItem'] = array();
     foreach (PurchaseOrderItem::getAllByCriteria('po_item.purchaseOrderId = :purchaseOrderId', array('purchaseOrderId' => $po->getId())) as $purchaseOrderItem) {
         $product = $purchaseOrderItem->getProduct();
         $EANcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_EAN), true, 1, 1);
         $EANcodes = count($EANcodes) ? $EANcodes[0]->getCode() : '';
         $UPCcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_UPC), true, 1, 1);
         $UPCcodes = count($UPCcodes) ? $UPCcodes[0]->getCode() : '';
         $warehouseLocations = PreferredLocation::getAllByCriteria('productId = :productId and typeId = :typeId', array('productId' => $product->getId(), 'typeId' => PreferredLocationType::ID_WAREHOUSE), true, 1, 1);
         $warehouseLocation = count($warehouseLocations) > 0 && $warehouseLocations[0]->getLocation() instanceof Location ? $warehouseLocations[0]->getLocation()->getName() : '';
         $productArray = $product->getJson();
         $productArray['codes'] = array('EAN' => $EANcodes, 'UPC' => $UPCcodes);
         $productArray['warehouseLocation'] = $warehouseLocation;
         $array['purchaseOrderItem'][] = array('purchaseOrderItem' => $purchaseOrderItem->getJson(), 'product' => $productArray);
     }
     return $array;
 }