public function checkFBAStock($mode = 'in_stock_only')
 {
     // get all published listings
     $lm = new WPLA_ListingsModel();
     $out_of_sync_products = array();
     if ($mode == 'all_stock') {
         $listings = $lm->getAllItemsUsingFBA();
     } else {
         $listings = $lm->getAllItemsWithStockInFBA();
     }
     // process FBA listings
     foreach ($listings as $item) {
         // get wc product
         $item = (array) $item;
         $_product = $this->getProduct($item['post_id']);
         if (!$_product) {
             continue;
         }
         // checking parent variations makes no sense in WPLA, so skip them
         if ($_product->product_type == 'variable') {
             continue;
         }
         // check stock level
         $stock = WPLA_ProductWrapper::getStock($item['post_id']);
         if ($stock == $item['fba_quantity']) {
             continue;
         }
         // copy FBA qty to Woo
         if (isset($_REQUEST['wpla_copy_fba_qty_to_woo'])) {
             update_post_meta($item['post_id'], '_stock', $item['fba_quantity']);
             continue;
         }
         // add to list of out of stock products
         $item['stock'] = $stock;
         $item['parent_id'] = $_product->product_type == 'variation' ? $_product->parent->id : false;
         $out_of_sync_products[] = $item;
     }
     // return if empty
     if (empty($out_of_sync_products)) {
         WPLA()->showMessage('All FBA products are in sync with WooCommerce.', 0, 1);
         return;
     }
     $msg = '<p>';
     $msg .= sprintf('There are %s FBA products have a different stock level in WooCommerce.', sizeof($out_of_sync_products));
     $msg .= '</p>';
     // table header
     $msg .= '<table style="width:100%">';
     $msg .= "<tr>";
     $msg .= "<th style='text-align:left'>SKU</th>";
     $msg .= "<th style='text-align:left'>Product</th>";
     $msg .= "<th style='text-align:left'>FBA</th>";
     $msg .= "<th style='text-align:left'>WooCommerce</th>";
     $msg .= "<th style='text-align:left'>ASIN</th>";
     $msg .= "<th style='text-align:left'>Status</th>";
     $msg .= "</tr>";
     // table rows
     foreach ($out_of_sync_products as $item) {
         // get column data
         $sku = $item['sku'];
         $qty = $item['quantity'];
         $fba_qty = $item['fba_quantity'];
         $stock = $item['stock'];
         $title = $item['listing_title'];
         $post_id = $item['post_id'];
         $asin = $item['asin'];
         $status = $item['status'];
         // build links
         // $amazon_url  = $item['ViewItemURL'] ? $item['ViewItemURL'] : $amazon_url = 'http://www.amazon.com/itm/'.$asin;
         $amazon_url = 'admin.php?page=wpla&s=' . $asin;
         $amazon_link = '<a href="' . $amazon_url . '" target="_blank">' . $asin . '</a>';
         $edit_link = '<a href="post.php?action=edit&post=' . ($item['parent_id'] ? $item['parent_id'] : $post_id) . '" target="_blank">' . $title . '</a>';
         // build table row
         $msg .= "<tr>";
         $msg .= "<td>{$sku}</td>";
         $msg .= "<td>{$edit_link}</td>";
         $msg .= "<td>{$fba_qty}</td>";
         $msg .= "<td>{$stock}</td>";
         $msg .= "<td>{$amazon_link}</td>";
         $msg .= "<td>{$status}</td>";
         $msg .= "</tr>";
     }
     $msg .= '</table>';
     $msg .= '<p>';
     $url = 'admin.php?page=wpla-tools&tab=inventory&action=check_wc_fba_stock&wpla_copy_fba_qty_to_woo=yes&mode=' . $mode . '&_wpnonce=' . wp_create_nonce('wpla_tools_page');
     $msg .= '<a href="' . $url . '" class="button">' . __('Copy FBA quantity to WooCommerce', 'wpla') . '</a> &nbsp; ';
     $msg .= 'Click this button set the stock level in WooCommerce to the current FBA quantity for each found product.';
     $msg .= '</p>';
     WPLA()->showMessage($msg, 1, 1);
 }