Changeset 1796659
- Timestamp:
- 01/03/2018 08:07:25 PM (8 years ago)
- Location:
- smartaccounts/trunk
- Files:
-
- 6 edited
-
SmartAccountsArticle.php (modified) (1 diff)
-
SmartAccountsClass.php (modified) (4 diffs)
-
SmartAccountsClient.php (modified) (4 diffs)
-
SmartAccountsSalesInvoice.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
-
smartaccounts.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
smartaccounts/trunk/SmartAccountsArticle.php
r1786015 r1796659 21 21 $body->code = $row->code; 22 22 $body->description = $row->description; 23 $body->type = $row->code == "shipping"? "SERVICE" : "PRODUCT";23 $body->type = $row->code == get_option( 'sa_api_shipping_code' ) ? "SERVICE" : "PRODUCT"; 24 24 $body->activeSales = true; 25 25 $this->api->sendRequest( $body, $addApiUrl ); -
smartaccounts/trunk/SmartAccountsClass.php
r1786015 r1796659 10 10 class SmartAccountsClass { 11 11 12 public static function orderStatusProcessing( $orderId ) { 12 public static function orderStatusProcessing( $order_id ) { 13 13 14 //try catch makes sure your store will operate even if there are errors 14 15 try { 15 $order = new WC_Order( $orderId ); 16 $order = new WC_Order( $order_id ); 17 18 if ( strlen( get_post_meta( $order_id, 'smartaccounts_invoice_id', true ) ) > 0 ) { 19 return; //Smartaccounts order is already created 20 } 21 16 22 $saClient = new SmartAccountsClient( $order ); 17 23 $client = $saClient->getClient(); … … 21 27 $saPayment = new SmartAccountsPayment( $order, $invoice ); 22 28 $saPayment->createPayment(); 29 update_post_meta( $order_id, 'smartaccounts_invoice_id', $invoice['invoice']['invoiceNumber'] ); 23 30 } catch ( Exception $exception ) { 24 31 $handle = fopen( 'error.log', 'a' ); 32 if ( $handle ) { 33 fwrite( $handle, $exception->getMessage() ); 34 fwrite( $handle, $exception->getTraceAsString() ); 35 fclose( $handle ); 36 } 25 37 } 26 38 } … … 31 43 register_setting( 'smartaccounts_options', 'sa_api_sk' ); 32 44 register_setting( 'smartaccounts_options', 'sa_api_payment_account' ); 45 register_setting( 'smartaccounts_options', 'sa_api_shipping_code', [ 'default' => 'shipping' ] ); 33 46 } 34 47 … … 70 83 </tr> 71 84 85 <tr valign="top"> 86 <th>SmartAccounts shipping item name</th> 87 <td> 88 <input name="sa_api_shipping_code" size="50" 89 value="<?php echo esc_attr( get_option( 'sa_api_shipping_code' ) ); ?>"/> 90 </td> 91 </tr> 92 72 93 </table> 73 94 <?php -
smartaccounts/trunk/SmartAccountsClient.php
r1786015 r1796659 11 11 protected $name; 12 12 protected $country; 13 13 protected $isCompany; 14 14 protected $api; 15 15 … … 23 23 $this->country = $order->get_billing_country(); 24 24 $this->email = $order->get_billing_email(); 25 $this->isCompany = strlen( $order->get_billing_company() ) > 0; 25 26 $firstName = strlen( $order->get_shipping_first_name() ) == 0 ? $order->get_billing_first_name() : $order->get_shipping_first_name(); 26 27 $lastName = strlen( $order->get_shipping_last_name() ) == 0 ? $order->get_billing_last_name() : $order->get_shipping_last_name(); … … 29 30 if ( $this->isAnonymous ) { 30 31 $this->name = "WooCommerce User $this->country"; 32 } else if ( $this->isCompany ) { 33 $this->name = $order->get_billing_company(); 31 34 } else { 32 35 $this->name = "$firstName $lastName"; … … 114 117 115 118 foreach ( $clients as $client ) { 116 if ( $this->hasEmail( $client, $email ) && $this->name == $client["name"] ) { 119 //match client if name matches and is company or email also matches 120 if ( ( $this->isCompany || $this->hasEmail( $client, $email ) ) && strtolower( $this->name ) == strtolower( $client["name"] ) ) { 117 121 return $client; 118 122 } -
smartaccounts/trunk/SmartAccountsSalesInvoice.php
r1786015 r1796659 16 16 $apiUrl = "purchasesales/clientinvoices:add"; 17 17 18 $body = new stdClass(); 19 $body->clientId = $this->client["id"]; 20 $body->date = $this->order->get_date_created()->date( "d.m.Y" ); 21 $body->currency = $this->order->get_currency(); 22 $body->rows = $this->getOrderRows(); 18 $body = new stdClass(); 19 $body->clientId = $this->client["id"]; 20 $body->date = $this->order->get_date_created()->date( "d.m.Y" ); 21 $body->currency = $this->order->get_currency(); 22 $body->rows = $this->getOrderRows(); 23 $body->roundAmount = $this->getRoundingAmount( $body->rows ); 24 $body->amount = number_format( $this->getOrderTotal(), 2 ); 25 $body->invoiceNote = "WooCommerce order #" . $this->order->get_id(); 23 26 24 27 $saArticle = new SmartAccountsArticle(); … … 30 33 } 31 34 35 public function getRoundingAmount( $rows ) { 36 $rowsTotal = 0; 37 foreach ( $rows as $row ) { 38 $rowsTotal += $row->totalCents; 39 $rowsTotal += $row->taxCents; 40 } 41 42 $roundingAmount = number_format( ( $this->getOrderTotal() * 100 + $this->getTotalTax() * 100 - $rowsTotal ) / 100, 2 ); 43 44 return $roundingAmount; 45 } 46 47 public function getTotalTax() { 48 return floatval( $this->order->get_total_tax() ); 49 } 50 51 public function getOrderTotal() { 52 return $this->order->get_subtotal() + $this->order->get_shipping_total(); 53 } 32 54 33 55 private function getOrderRows() { 34 56 $rows = []; 35 $totalTax = floatval( $this->order->get_total_tax());36 $subTotal = $this-> order->get_subtotal() + $this->order->get_shipping_total();57 $totalTax = $this->getTotalTax(); 58 $subTotal = $this->getOrderTotal(); 37 59 $vatPc = round( $totalTax * 100 / $subTotal ); 38 60 foreach ( $this->order->get_items() as $item ) { 39 61 $row = new stdClass(); 40 62 $row->code = $item->get_product()->get_sku(); 41 $row->description = strlen( $item->get_product()->get_description() ) == 0 ? "Woocommerce product " . $item->get_product()->get_name() : $item->get_product()->get_description(); 42 $row->price = $item->get_product()->get_price(); 63 $row->description = strlen( $item->get_product()->get_description() ) == 0 ? $item->get_product()->get_name() : $item->get_product()->get_description(); 43 64 $row->quantity = $item->get_quantity(); 44 $row->vatPc = $vatPc; 45 $rows[] = $row; 65 66 $rowPrice = $item->get_total() / $item->get_quantity(); 67 68 $row->price = number_format( $rowPrice, 2 ); 69 $row->vatPc = $vatPc; 70 $row->totalCents = intval( round( floatval( $row->price ) * $row->quantity * 100 ) ); 71 $row->taxCents = intval( round( $row->totalCents * $vatPc / 100 ) ); 72 $rows[] = $row; 46 73 } 47 74 48 75 if ( $this->order->get_shipping_total() > 0 ) { 49 76 $row = new stdClass(); 50 $row->code = "shipping";77 $row->code = get_option( 'sa_api_shipping_code' ); 51 78 $row->description = "Woocommerce Shipping"; 52 79 $row->price = $this->order->get_shipping_total(); 53 80 $row->quantity = 1; 54 81 $row->vatPc = $vatPc; 82 $row->totalCents = intval( round( floatval( $row->price ) * $row->quantity * 100 ) ); 83 $row->taxCents = intval( round( $row->totalCents * $vatPc / 100 ) ); 55 84 $rows[] = $row; 56 85 } -
smartaccounts/trunk/readme.txt
r1786073 r1796659 10 10 == Description == 11 11 12 After woocommerce order goes to status "Processing" then this plugin:13 * Creates customer to SmartAccounts if no existing customer with same name and e-mail found12 After woocommerce order goes to status "Processing" or "Completed" then this plugin: 13 * Creates Customer to SmartAccounts if no existing customer with same name and e-mail found 14 14 * Creates Articles in Smartaccounts of Woocommerce product on the order if existing products are not found. 15 15 Woocommerce product SKU is compared with SmartAccounts article code. … … 19 19 == Installation == 20 20 21 Configuration is needed to make this plugin work. After act vating the plugin find its configuration page under Woocommerce menu item and:21 Configuration is needed to make this plugin work. After activating the plugin find its configuration page under Woocommerce menu item and: 22 22 23 23 * Make sure you have SmartAccounts package with API access 24 * Copy SmartAccounts API key and secret from SmartAccounts interface. 24 * Copy SmartAccounts API key and secret from SmartAccounts interface. If you don't have SmartAccounts API key (please check Settings - Connected Services) you can contact SmartAccounts support to enable API service for your account. Additional conditions and charges may apply to API service. 25 25 * Add bank account name you want to be used when making the invoices paid 26 * You can also change SmartAccounts code for shipping 26 27 27 28 == Frequently Asked Questions == 28 29 29 30 = What are the plugin limitations? = 30 This plugin creates sales invoice to SmartAccounts platform every time when order is changed into "Processing" status. 31 Duplicate invoices could be created if order is changed to Processing status many times. 31 * This plugin creates sales invoice to SmartAccounts platform only first time when order is changed into "Processing" or "Completed" status. 32 32 Invoice is always marked paid regardless if the payment is actually made or not yet. For example if Cash on Delivery payment method is used. 33 Order changes and cancelling is not handled automatically 34 Shipping item has code "shipping" 35 All items have one VAT percentage 36 SmartAccounts article code must be added to the Woocommerce product SKU if existing SmartAccounts article must be used 37 If product is not found then "Woocommerce product NAME" Article is created to SmartAccounts 38 Plugin does not handle errors which come from exceeding rate limits or unpaid SmartAccounts invoices. 39 If there are errors then invoices might be missing and rest of the Woocommerce functionality keeps on working 40 SmartAccounts API key, API secret and Payment account name must be configured before plugin will start working properly. 41 33 * Order changes and cancelling is not handled automatically 34 * All items have one VAT percentage 35 * SmartAccounts article code must be added to the Woocommerce product SKU if existing SmartAccounts article must be used 36 * If product is not found then "Woocommerce product NAME" Article is created to SmartAccounts 37 * Plugin does not handle errors which come from exceeding rate limits or unpaid SmartAccounts invoices. 38 * If there are errors then invoices might be missing and rest of the Woocommerce functionality keeps on working 39 * SmartAccounts API key, API secret and Payment account name must be configured before plugin will start working properly. 42 40 43 41 == Screenshots == … … 46 44 == Changelog == 47 45 48 = 0.9 = 46 = 1.1 = 47 Woo order number reference is added to SmartAccounts invoice note 48 If company name is filled then invoice is connected to the Billing company 49 Discounted prices are used on invoices 50 Rounding calculation is added 51 Shipping item code is configurable 52 error.log is created in case of SmartAccounts communication issues 53 54 = 1.0 = 49 55 * Plugin is ready for production testing -
smartaccounts/trunk/smartaccounts.php
r1786015 r1796659 4 4 * Plugin URI: https://github.com/smartman/woocommerce_smartaccounts 5 5 * Description: This plugin creates sales invoices in the smartaccounts.ee Online Accounting Software after Woocommerce order creation 6 * Version: 1. 06 * Version: 1.1 7 7 * Author: Margus Pala 8 8 * Author URI: http://marguspala.com … … 24 24 add_action( 'admin_init', 'SmartAccountsClass::registerSettings' ); 25 25 add_action( 'woocommerce_order_status_processing', 'SmartAccountsClass::orderStatusProcessing' ); 26 add_action( 'woocommerce_order_status_completed', 'SmartAccountsClass::orderStatusProcessing' ); 27 28 //add_action( 'init', 'SmartAccountsClass::orderStatusProcessing' );
Note: See TracChangeset
for help on using the changeset viewer.