public function checkForDuplicates() { // show warning if duplicate products found $tm = new TransactionsModel(); $duplicateTransactions = $tm->getAllDuplicateTransactions(); if (!empty($duplicateTransactions)) { // built message // $msg = '<p><b>Warning: '.__('There are duplicate transactions for','wplister').' '.join(', ',$duplicateTransactions).'</b>'; $msg = '<p><b>Warning: ' . __('There are duplicate transactions which should be removed.', 'wplister') . '</b>'; $msg .= '<br>'; // table header $msg .= '<table style="width:100%">'; $msg .= "<tr>"; $msg .= "<th style='text-align:left'>Date</th>"; $msg .= "<th style='text-align:left'>Transaction ID</th>"; $msg .= "<th style='text-align:left'>Order ID</th>"; $msg .= "<th style='text-align:left'>Last modified</th>"; $msg .= "<th style='text-align:left'>Qty</th>"; $msg .= "<th style='text-align:left'>eBay ID</th>"; $msg .= "<th style='text-align:left'>Stock red.</th>"; $msg .= "<th style='text-align:left'>New Stock</th>"; $msg .= "<th style='text-align:left'>Status</th>"; $msg .= "<th style='text-align:left'> </th>"; $msg .= "</tr>"; // table rows foreach ($duplicateTransactions as $transaction_id) { $transactions = $tm->getAllTransactionsByTransactionID($transaction_id); $last_transaction_id = false; foreach ($transactions as $txn) { // get column data $qty = $txn['quantity']; // $stock = $txn['stock'] . ' x '; // $title = $txn['auction_title']; // $post_id = $txn['post_id']; // $ebay_id = $txn['ebay_id']; // build links // $ebay_url = $txn['ViewItemURL'] ? $txn['ViewItemURL'] : $ebay_url = 'http://www.ebay.com/itm/'.$ebay_id; // $ebay_link = '<a href="'.$ebay_url.'" target="_blank">'.$ebay_id.'</a>'; // $edit_link = '<a href="post.php?action=edit&post='.$post_id.'" target="_blank">'.$title.'</a>'; // check if stock was reduced list($reduced_product_id, $new_stock_value) = $tm->checkIfStockWasReducedForItemID($txn, $txn['item_id']); // color results $color_id = 'silver'; if ($transaction_id != $last_transaction_id) { $color_id = 'black'; $last_transaction_id = $transaction_id; } $color_status = 'auto'; if ($txn['CompleteStatus'] == 'Completed') { $color_status = 'darkgreen'; } if ($txn['CompleteStatus'] == 'Cancelled') { $color_status = 'silver'; } // built buttons $actions = ''; if ($txn['status'] != 'reverted' && $txn['CompleteStatus'] != 'Completed') { $button_label = $reduced_product_id ? 'Restore stock' : 'Remove'; $url = 'admin.php?page=wplister-transactions&action=wpl_revert_transaction&id=' . $txn['id']; $actions = '<a href="' . $url . '" class="button button-small">' . $button_label . '</a>'; } // build table row $msg .= "<tr>"; $msg .= "<td>" . $txn['date_created'] . "</td>"; $msg .= "<td style='color:{$color_id}'>" . $txn['transaction_id'] . "</td>"; $msg .= "<td>" . $txn['order_id'] . "</td>"; $msg .= "<td>" . $txn['LastTimeModified'] . "</td>"; $msg .= "<td>" . $txn['quantity'] . "</td>"; $msg .= "<td>" . $txn['item_id'] . "</td>"; $msg .= "<td>" . $reduced_product_id . "</td>"; $msg .= "<td>" . $new_stock_value . "</td>"; $msg .= "<td style='color:{$color_status}'>" . $txn['CompleteStatus'] . "</td>"; $msg .= "<td>" . $actions . "</td>"; // $msg .= "<td>$edit_link (ID $post_id)</td>"; // $msg .= "<td>$qty x </td>"; // $msg .= "<td>$ebay_link</td>"; $msg .= "</tr>"; } } $msg .= '</table>'; $msg .= '<br>'; // $msg .= $table; // $msg .= '<br>'; // $msg .= 'This is caused by...'; // $msg .= '<br><br>'; // $msg .= 'To fix this... '; $msg .= '</p>'; $this->showMessage($msg, 1); } }