Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $dateStart = $_GET["dateStart"];
- $dateEnd = $_GET['dateEnd'];
- $sku_prefix = $_GET['sku'];
- $results_format = $_GET['format'];
- $comm = $_GET['comm'];
- function startsWith($haystack, $needle)
- {
- $length = strlen($needle);
- return (substr($haystack, 0, $length) === $needle);
- }
- if (!$dateStart) { $dateStart = "2013-07-01"; }
- if (!$dateEnd) { $dateEnd = "2013-10-01"; }
- if (!$comm) { $comm = 15; }
- /**
- * Compilation includes configuration file
- */
- $compilerConfig = 'includes/config.php';
- if (file_exists($compilerConfig)) {
- include($compilerConfig);
- }
- $mageFilename = 'app/Mage.php';
- require_once $mageFilename;
- umask(0);
- Mage::init();
- $collection = Mage::getModel('sales/order')->getCollection();
- $collection->addFieldToFilter(
- 'created_at',
- array('from' => $dateStart, 'to' => $dateEnd)
- );
- echo <<<END
- <h3>Artist Report</h3>
- <form action="#">
- Sku prefix<input type=text name="sku" value="$sku_prefix" size=5>
- Date Start: <input type=text name="dateStart" value="$dateStart" size=8>
- Date End: <input type=text name="dateEnd" value="$dateEnd" size=8>
- Commission %: <input type=text name="comm" value="$comm" size=3 maxlength=2>
- <input type=submit value="Search">
- </form>
- <div id="resultsTable" style="position:absolute">
- <a href="javascript:downloadCSV();">Show CSV data</a>
- <table border=1>
- <tr bgcolor="gray" align=center><td>Order Number</td><td>Order Date</td><td>Sku<td>Base Price</td><td>sq feet</td><td>Sub-total</td><td>Row Total</td><td bgcolor="white"><u>Order</u> base total</td><td bgcolor="white"><u>Order</u> base discount</td><td bgcolor="white" >Discount %</td><td bgcolor="yellow">Commission</td></tr>
- END;
- $csv_header = "order_id,date,sku,base_price,discount,commission %,commission\n";
- foreach ($collection as $order) {
- $sku_data;
- $csv_data;
- $_totalData =$order->getData();
- $order_id =$order->getRealOrderId();
- $oid =$order->getId();
- $oid_link = "<a href='/index.php/magic_admin/sales_order/view/order_id/$oid/' target='_blank'>$order_id</a>";
- # foreach($_totalData as $key => $one) { print $key . ' ' . $one . '<br>'; }
- $created_at = $_totalData['created_at'];
- $date = substr($created_at,0,10);
- $items = $order->getAllItems();
- $itemcount=count($items);
- $grand = $_totalData['base_grand_total'];
- $discount = $_totalData['base_discount_amount'];
- foreach ($items as $itemId => $item) {
- # $_totalData2 =$item->getData();
- # foreach($_totalData2 as $key => $one) { print $key . ' ' . $one . '<br>'; }
- $sku=$item->getSku();
- $row_total= $item->getData('row_total') - $item->getData('discount_amount');
- $base_price = $item->getPrice() * $item->getQtyInvoiced();
- $discountPercentage = $discount;
- $dp = $discountPercentage;
- $commission = $row_total * $comm/100;
- if ($discount == 0) {
- $dp = 0;
- } else if ($dp < 0) {
- $dp = $discount/ $base_price * -1;
- }
- $discountPercentage = number_format($dp*100,0);
- if ($discountPercentage == 100) {
- $commission = 0;
- }
- # FOO - Multiple items per order
- $csv = "$order_id,$date,$sku,$row_total,$commission,$itemcount\n";
- $row = "<tr><td>$oid_link</td>";
- $row .= "<td>$date </td>";
- $row .= "<td width=151>";
- $row .="$sku</td><td width=40 align=right>";
- $row .=number_format($item->getPrice(),2) . '</td><td width=40 align=right>';
- $row .=number_format($item->getQtyInvoiced(),2) . '</td><td with=40 align=right>';
- $row .=number_format($base_price,2) . '</td><td align=right>';
- $row .= number_format($row_total,2)."</td><td align=right>";
- $row .= number_format($grand,2)."</td><td align=right>";
- $row .= number_format($discount,2)."</td><td align=right>";
- $row .= $discountPercentage."</td><td align=right>";
- $row .=number_format($commission,2). '</td>';
- if ($sku_prefix) {
- if (startsWith($sku,$sku_prefix)) {
- $sku_data[$item->getSku()] .= $row;
- $csv_data[$item->getSku()] .= $csv;
- }
- } else {
- $sku_data[$item->getSku()] .= $row;
- $csv_data[$item->getSku()] .= $csv;
- }
- }
- }
- $keys = array_keys($sku_data);
- sort($keys);
- $csv_content = $csv_header;;
- foreach ($keys as $key){
- echo $sku_data{$key};
- $csv_content .= $csv_data{$key};
- }
- echo <<<END
- </table>
- </div>
- <div id="csv_content" style="position:relative;">
- <a href="javascript:showResults()">Show Results</a>
- <pre>
- $csv_content
- </div>
- </pre>
- <script>
- function downloadCSV() {
- document.getElementById('resultsTable').style.visibility='hidden';
- document.getElementById('csv_content').style.visibility='visible';
- alert('Please copy and paste the content below into a new text file. Name the file artist_report_date.csv');
- }
- function showResults() {
- document.getElementById('resultsTable').style.visibility='visible';
- document.getElementById('csv_content').style.visibility='hidden';
- }
- document.getElementById('csv_content').style.visibility='hidden';
- </script>
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement