794_The.Definitive.Guide.to.Magento.pdf

Deliminator invoice deliminator chapter 12 tips and

Info icon This preview shows pages 224–228. Sign up to view the full content.

$deliminator . "INVOICE" . $deliminator .
Image of page 224

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

CHAPTER 12 TIPS AND TRICKS 203 "ITEMS" . $deliminator . "-" . intval($orderInfoItem['qty_ordered']) . $deliminator . floatval($orderInfoItem['price']) . $deliminator . "-" . floatval(intval($orderInfoItem['qty_ordered']) * floatval($orderInfoItem['price'])) . $deliminator . $orderInfoItem['sku'] . $deliminator . $orderInfoItem['name'] . "\r\n"; } // ======================================= // Add discount section // ======================================= if (floatval($detailedInfo['discount_amount']) > 0) { $csvFile .= "SPL" . $deliminator . $deliminator . "INVOICE" . $deliminator . "ITEMS" . $deliminator . "-1" . $deliminator . floatval($detailedInfo['discount_amount']) . $deliminator . floatval($detailedInfo['discount_amount']) . $deliminator . "Discount" . $deliminator . "Discount" . "\r\n"; } // ======================================= // Add shipping section // ======================================= if (floatval($detailedInfo['shipping_amount']) > 0) { $csvFile .= "SPL" . $deliminator . $deliminator . "INVOICE" . $deliminator . "ITEMS" . $deliminator . "-1" . $deliminator . floatval($detailedInfo['shipping_amount']) . $deliminator . "-" . floatval($detailedInfo['shipping_amount']) . $deliminator . "SHIPPING" . $deliminator . "SHIPPING" . "\r\n"; } // ======================================= // Add tax section // ======================================= if (floatval($detailedInfo['tax_amount']) > 0) { $csvFile .= "SPL" . $deliminator .
Image of page 225
CHAPTER 12 TIPS AND TRICKS 204 $deliminator . "INVOICE" . $deliminator . "ITEMS" . $deliminator . "-1" . $deliminator . floatval($detailedInfo['tax_amount']) . $deliminator . "-" . floatval($detailedInfo['tax_amount']) . $deliminator . "TAX" . $deliminator . "TAX" . "\r\n"; } // ======================================= // End the TRNS section // ======================================= $csvFile .= "ENDTRNS\r\n"; } // ======================================= // STEP 5: create file and store it on server // ======================================= $fp = fopen($iif_file,'w'); echo "Creating local file: $iif_file ... "; $re = fputs($fp, $csvFile); if (!$re) die("FAILED! \n"); echo "Done! \n"; fclose($fp); } echo "======================== \n"; echo "End of IIF file creation \n"; There’s a lot going on in this script. It starts by grabbing all shipment orders dated from midnight yesterday to now. Assume that if a shipment order has been created, it’s safe to import into QuickBooks for invoice creation and recordkeeping. Once you have a list of order IDs, you can start extracting the detailed information such as the individual items ordered, shipping address, billing address, and when the sales transaction was completed. Next, purge all that info into QuickBooks’ IIF format. And you’re done. Figure 12-4 shows a sample output. Figure 12-4. Sample output of IIF file
Image of page 226

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

CHAPTER 12 TIPS AND TRICKS 205 You can also run this script through the command line, but we set up this script to run daily using the linux cron command. To find more information on cron, go to . From the preceding examples, you can see how to extract sales order information from Magento and customize the output into any format. QuickBooks’ IIF file format requires tab delineation, but you can easily change it to commas or even XML tags. All the customized scripts have been a variation of the preceding sample. XML creation isn’t discussed because each company has its own XML attributes, and there are plenty of examples online. But we hope you saw how the API can be used in the real world to extract useful information for your purposes.
Image of page 227
Image of page 228
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern