Version Notes
Plumrocket Auto Invoice
Download this release
Release Info
Developer | Plumrocket Team |
Extension | Plumrocket_Auto_Invoice |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- app/code/community/Plumrocket/AutoInvoice/Helper/Data.php +10 -2
- app/code/community/Plumrocket/AutoInvoice/Model/Observer.php +46 -51
- app/code/community/Plumrocket/AutoInvoice/Model/System/Config/Source/CaptureAmount.php +64 -0
- app/code/community/Plumrocket/AutoInvoice/etc/config.xml +9 -13
- app/code/community/Plumrocket/AutoInvoice/etc/system.xml +10 -0
- app/etc/modules/Plumrocket_AutoInvoice.xml +1 -1
- package.xml +4 -4
app/code/community/Plumrocket/AutoInvoice/Helper/Data.php
CHANGED
@@ -25,8 +25,16 @@ class Plumrocket_AutoInvoice_Helper_Data extends Mage_Core_Helper_Abstract
|
|
25 |
{
|
26 |
private $_configPrefix = 'autoinvoice/';
|
27 |
|
28 |
-
public function moduleEnabled(){
|
29 |
-
return Mage::getStoreConfig($this->_configPrefix.'general/enabled');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
31 |
}
|
32 |
|
25 |
{
|
26 |
private $_configPrefix = 'autoinvoice/';
|
27 |
|
28 |
+
public function moduleEnabled($storeId = null){
|
29 |
+
return Mage::getStoreConfig($this->_configPrefix.'general/enabled', $storeId);
|
30 |
+
}
|
31 |
+
|
32 |
+
public function getCaptureAmount($storeId = null){
|
33 |
+
$value = Mage::getStoreConfig($this->_configPrefix.'general/capture', $storeId);
|
34 |
+
if (!$value){
|
35 |
+
$value = Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE;
|
36 |
+
}
|
37 |
+
return $value;
|
38 |
}
|
39 |
}
|
40 |
|
app/code/community/Plumrocket/AutoInvoice/Model/Observer.php
CHANGED
@@ -23,64 +23,59 @@
|
|
23 |
|
24 |
class Plumrocket_AutoInvoice_Model_Observer
|
25 |
{
|
26 |
-
|
27 |
-
public function salesOrderSaveCommitAfter(Varien_Event_Observer $observer)
|
28 |
{
|
29 |
-
|
30 |
-
if (
|
31 |
return $this;
|
32 |
}
|
33 |
|
34 |
-
$
|
35 |
-
if ( ($order->getState() == Mage_Sales_Model_Order::STATE_NEW || $order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING) && !$order->getIsProcessedByMCornerOrdersObserver() )
|
36 |
-
{
|
37 |
-
$orders = Mage::getModel('sales/order_invoice')->getCollection()->addAttributeToFilter('order_id', array('eq'=>$order->getId()));
|
38 |
-
$orders->getSelect()->limit(1);
|
39 |
-
if ((int)$orders->count() !== 0) {
|
40 |
-
return $this;
|
41 |
-
}
|
42 |
-
|
43 |
-
try {
|
44 |
-
if(!$order->canInvoice()) {
|
45 |
-
$order->addStatusHistoryComment('Auto Invoice: Order cannot be invoiced.', false);
|
46 |
-
$order->save();
|
47 |
-
}
|
48 |
-
|
49 |
-
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
50 |
-
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
|
51 |
-
|
52 |
-
$incrementId = Mage::getModel('sales/order_invoice')->getCollection()
|
53 |
-
->addFieldToFilter('store_id', Mage::app()->getStore()->getId())
|
54 |
-
->setOrder('increment_id','DESC')
|
55 |
-
->setPageSize(1)
|
56 |
-
->setCurPage(1)
|
57 |
-
->getFirstItem()
|
58 |
-
->getIncrementId();
|
59 |
-
|
60 |
-
$invoice->setIncrementId($incrementId + 1);
|
61 |
-
$invoice->sendEmail('true','');
|
62 |
-
$invoice->setIncrementId(null);
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
79 |
}
|
80 |
-
|
81 |
-
return $this;
|
82 |
}
|
83 |
|
84 |
-
|
85 |
-
|
86 |
}
|
23 |
|
24 |
class Plumrocket_AutoInvoice_Model_Observer
|
25 |
{
|
26 |
+
public function run()
|
|
|
27 |
{
|
28 |
+
$_helper = Mage::helper('autoinvoice');
|
29 |
+
if (!$_helper->moduleEnabled()){
|
30 |
return $this;
|
31 |
}
|
32 |
|
33 |
+
$time = Mage::getModel('core/date')->timestamp() - 60 * 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
$collection = Mage::getModel('sales/order')->getCollection()
|
36 |
+
->addFieldToFilter('main_table.created_at', array('gt' => date('Y-m-d H:i:s', $time)))
|
37 |
+
->addFieldToFilter('main_table.state', array('in' => array(
|
38 |
+
Mage_Sales_Model_Order::STATE_NEW,
|
39 |
+
Mage_Sales_Model_Order::STATE_PROCESSING,
|
40 |
+
)));
|
41 |
+
|
42 |
+
$_resource = Mage::getSingleton('core/resource');
|
43 |
+
$collection->getSelect()
|
44 |
+
->joinLeft( array('invoice' => $_resource->getTableName('sales/invoice')), 'invoice.order_id = main_table.entity_id', array())
|
45 |
+
->where('order_id IS NULL');
|
46 |
+
|
47 |
+
foreach($collection as $order){
|
48 |
+
|
49 |
+
if (!$_helper->moduleEnabled($order->getStoreId())){
|
50 |
+
continue;
|
51 |
+
}
|
52 |
+
|
53 |
+
if (!$order->canInvoice()) {
|
54 |
+
continue;
|
55 |
+
}
|
56 |
+
|
57 |
+
try{
|
58 |
+
$invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
|
59 |
|
60 |
+
if ($invoice) {
|
61 |
+
$invoice->setRequestedCaptureCase($_helper->getCaptureAmount($order->getStoreId()));
|
62 |
+
$invoice->register();
|
63 |
+
$invoice->getOrder()->setCustomerNoteNotify(false);
|
64 |
+
$invoice->getOrder()->setIsInProcess(true);
|
65 |
+
|
66 |
+
$transactionSave = Mage::getModel('core/resource_transaction')
|
67 |
+
->addObject($invoice)
|
68 |
+
->addObject($invoice->getOrder())
|
69 |
+
->save();
|
70 |
+
|
71 |
+
$invoice->sendEmail(true);
|
72 |
+
|
73 |
+
$order->addStatusHistoryComment('Auto Invoice: Order invoiced.', false)->save();
|
74 |
+
}
|
75 |
+
} catch (Exception $e) {
|
76 |
+
//echo $e->getMessage();
|
77 |
}
|
78 |
+
}
|
|
|
79 |
}
|
80 |
|
|
|
|
|
81 |
}
|
app/code/community/Plumrocket/AutoInvoice/Model/System/Config/Source/CaptureAmount.php
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Mage
|
22 |
+
* @package Mage_Adminhtml
|
23 |
+
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
|
24 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Used in creating options for Yes|No config value selection
|
29 |
+
*
|
30 |
+
*/
|
31 |
+
class Plumrocket_AutoInvoice_Model_System_Config_Source_CaptureAmount
|
32 |
+
{
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Options getter
|
36 |
+
*
|
37 |
+
* @return array
|
38 |
+
*/
|
39 |
+
public function toOptionArray()
|
40 |
+
{
|
41 |
+
$_helper = Mage::helper('sales');
|
42 |
+
return array(
|
43 |
+
array('value' => Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE, 'label'=> $_helper->__('Capture Offline')),
|
44 |
+
array('value' => Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE, 'label'=> $_helper->__('Capture Online')),
|
45 |
+
array('value' => Mage_Sales_Model_Order_Invoice::NOT_CAPTURE, 'label'=> $_helper->__('Not Capture')),
|
46 |
+
);
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Get options in "key-value" format
|
51 |
+
*
|
52 |
+
* @return array
|
53 |
+
*/
|
54 |
+
public function toArray()
|
55 |
+
{
|
56 |
+
$values = array();
|
57 |
+
foreach($this->toOptionArray() as $data){
|
58 |
+
$values[$data['value']] = $data['label'];
|
59 |
+
}
|
60 |
+
|
61 |
+
return $values;
|
62 |
+
}
|
63 |
+
|
64 |
+
}
|
app/code/community/Plumrocket/AutoInvoice/etc/config.xml
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Plumrocket_AutoInvoice>
|
5 |
-
<version>1.0.
|
6 |
</Plumrocket_AutoInvoice>
|
7 |
</modules>
|
8 |
<global>
|
@@ -22,17 +22,13 @@
|
|
22 |
<resourceModel>autoinvoice_mysql4</resourceModel>
|
23 |
</autoinvoice>
|
24 |
</models>
|
25 |
-
<events>
|
26 |
-
<sales_order_save_commit_after>
|
27 |
-
<observers>
|
28 |
-
<sales_order_save_commit_after_handler>
|
29 |
-
<type>model</type>
|
30 |
-
<class>autoinvoice/observer</class>
|
31 |
-
<method>salesOrderSaveCommitAfter</method>
|
32 |
-
<args></args>
|
33 |
-
</sales_order_save_commit_after_handler>
|
34 |
-
</observers>
|
35 |
-
</sales_order_save_commit_after>
|
36 |
-
</events>
|
37 |
</global>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
</config>
|
2 |
<config>
|
3 |
<modules>
|
4 |
<Plumrocket_AutoInvoice>
|
5 |
+
<version>1.0.3</version>
|
6 |
</Plumrocket_AutoInvoice>
|
7 |
</modules>
|
8 |
<global>
|
22 |
<resourceModel>autoinvoice_mysql4</resourceModel>
|
23 |
</autoinvoice>
|
24 |
</models>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
</global>
|
26 |
+
<crontab>
|
27 |
+
<jobs>
|
28 |
+
<autoinvoice_job>
|
29 |
+
<schedule><cron_expr>0,5,10,15,20,25,30,35,40,45,50,55 * * * *</cron_expr></schedule>
|
30 |
+
<run><model>autoinvoice/observer::run</model></run>
|
31 |
+
</autoinvoice_job>
|
32 |
+
</jobs>
|
33 |
+
</crontab>
|
34 |
</config>
|
app/code/community/Plumrocket/AutoInvoice/etc/system.xml
CHANGED
@@ -46,6 +46,16 @@
|
|
46 |
<show_in_store>1</show_in_store>
|
47 |
<comment></comment>
|
48 |
</enabled>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
</fields>
|
50 |
</general>
|
51 |
</groups>
|
46 |
<show_in_store>1</show_in_store>
|
47 |
<comment></comment>
|
48 |
</enabled>
|
49 |
+
<capture translate="label">
|
50 |
+
<label>Capture Amount</label>
|
51 |
+
<frontend_type>select</frontend_type>
|
52 |
+
<source_model>autoinvoice/system_config_source_captureAmount</source_model>
|
53 |
+
<sort_order>1</sort_order>
|
54 |
+
<show_in_default>1</show_in_default>
|
55 |
+
<show_in_website>1</show_in_website>
|
56 |
+
<show_in_store>1</show_in_store>
|
57 |
+
<comment></comment>
|
58 |
+
</capture>
|
59 |
</fields>
|
60 |
</general>
|
61 |
</groups>
|
app/etc/modules/Plumrocket_AutoInvoice.xml
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
<Plumrocket_AutoInvoice>
|
5 |
<active>true</active>
|
6 |
<codePool>community</codePool>
|
7 |
-
<version>1.0.
|
8 |
<wiki>http://wiki.plumrocket.com/wiki/Magento_Auto_Invoice_v1.x_Extension</wiki>
|
9 |
</Plumrocket_AutoInvoice>
|
10 |
</modules>
|
4 |
<Plumrocket_AutoInvoice>
|
5 |
<active>true</active>
|
6 |
<codePool>community</codePool>
|
7 |
+
<version>1.0.3</version>
|
8 |
<wiki>http://wiki.plumrocket.com/wiki/Magento_Auto_Invoice_v1.x_Extension</wiki>
|
9 |
</Plumrocket_AutoInvoice>
|
10 |
</modules>
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Plumrocket_Auto_Invoice</name>
|
4 |
-
<version>1.0.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://wiki.plumrocket.net/wiki/EULA">End-user License Agreement</license>
|
7 |
<channel>community</channel>
|
@@ -10,9 +10,9 @@
|
|
10 |
<description>Plumrocket Auto Invoice is a convenient Magento payment processing module that was designed to generate invoice automatically. After a client confirms his order the system will send the invoice automatically thus allowing website admin to avoid manual processing of payment transactions.</description>
|
11 |
<notes>Plumrocket Auto Invoice</notes>
|
12 |
<authors><author><name>Plumrocket Team</name><user>plumrocket</user><email>support@plumrocket.com</email></author></authors>
|
13 |
-
<date>2013-
|
14 |
-
<time>
|
15 |
-
<contents><target name="mageetc"><dir name="modules"><file name="Plumrocket_AutoInvoice.xml" hash="
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Plumrocket_Auto_Invoice</name>
|
4 |
+
<version>1.0.3</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://wiki.plumrocket.net/wiki/EULA">End-user License Agreement</license>
|
7 |
<channel>community</channel>
|
10 |
<description>Plumrocket Auto Invoice is a convenient Magento payment processing module that was designed to generate invoice automatically. After a client confirms his order the system will send the invoice automatically thus allowing website admin to avoid manual processing of payment transactions.</description>
|
11 |
<notes>Plumrocket Auto Invoice</notes>
|
12 |
<authors><author><name>Plumrocket Team</name><user>plumrocket</user><email>support@plumrocket.com</email></author></authors>
|
13 |
+
<date>2013-12-11</date>
|
14 |
+
<time>09:35:11</time>
|
15 |
+
<contents><target name="mageetc"><dir name="modules"><file name="Plumrocket_AutoInvoice.xml" hash="ee0cb0a8fe25231eec7213f3ce3fa1fd"/></dir></target><target name="magecommunity"><dir name="Plumrocket"><dir name="AutoInvoice"><dir name="Block"><dir name="System"><dir name="Config"><file name="Version.php" hash="3adcf7698f60ef53547cb6259797668c"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="2442a8b87cb8d2b97f7418d0ce0a4287"/></dir><dir name="Model"><file name="Observer.php" hash="e64b52ee7135f4904c1fede040d331e1"/><dir name="System"><dir name="Config"><dir name="Source"><file name="CaptureAmount.php" hash="28a27588ddd56fbbab43f09e31a9bac8"/></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="e45a29110a7ea4ed9e26535cca2f47a4"/><file name="config.xml" hash="1e9c2bdb4169137fcab4d9462ebb569a"/><file name="system.xml" hash="38677f6b4a4ca2ecb55c9997c871159f"/></dir></dir></dir></target></contents>
|
16 |
<compatible/>
|
17 |
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
|
18 |
</package>
|