Ejemplo n.º 1
0
/**
 * transaction_results function main function for creating the purchase reports, transaction results page, and email receipts
 * @access public
 *
 * @since 3.7
 * @param $sessionid (string) unique session id
 * @param echo_to_screen (boolean) whether to output the results or return them (potentially redundant)
 * @param $transaction_id (int) the transaction id
 */
function transaction_results($sessionid, $display_to_screen = true, $transaction_id = null)
{
    global $message_html, $echo_to_screen, $purchase_log;
    // pre-3.8.9 variable
    $echo_to_screen = $display_to_screen;
    $purchase_log_object = new WPSC_Purchase_Log($sessionid, 'sessionid');
    // compatibility with pre-3.8.9 templates where they use a global
    // $purchase_log object which is simply just a database row
    $purchase_log = $purchase_log_object->get_data();
    // pre-3.8.9 templates also use this global variable
    $message_html = wpsc_get_transaction_html_output($purchase_log_object);
    do_action('wpsc_transaction_results_shutdown', $purchase_log_object, $sessionid, $display_to_screen);
    return $message_html;
}
Ejemplo n.º 2
0
function wpsc_purchlog_edit_status($purchlog_id = '', $purchlog_status = '')
{
    global $wpdb;
    if (empty($purchlog_id) && empty($purchlog_status)) {
        $purchlog_id = absint($_POST['id']);
        $purchlog_status = absint($_POST['new_status']);
    }
    $purchase_log = new WPSC_Purchase_Log($purchlog_id);
    //in the future when everyone is using the 2.0 merchant api, we should use the merchant class to update the staus,
    // then you can get rid of this hook and have each person overwrite the method that updates the status.
    do_action('wpsc_edit_order_status', array('purchlog_id' => $purchlog_id, 'purchlog_data' => $purchase_log->get_data(), 'new_status' => $purchlog_status));
    $result = wpsc_update_purchase_log_status($purchlog_id, $purchlog_status);
    wpsc_clear_stock_claims();
    return $result;
}
Ejemplo n.º 3
0
 /**
  * Pushes sales data back to Baikonur
  *
  * Only pushes once.  Accounts for annoying potential edge case of status-switching admins
  *
  * @param  WPSC_Purchase_Log object $purchase_log Purchase Log object
  * @return void
  */
 public static function push_sales_data($purchase_log_id, $current_status, $old_status, $purchase_log)
 {
     $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
     $id = absint($purchase_log->get('id'));
     //Also checking is_order_received, as that's what Manual Payments do.
     if ($purchase_log->is_transaction_completed() || $purchase_log->is_order_received()) {
         $pushed_to_sass = wpsc_get_meta($id, '_pushed_to_wpeconomy', 'purchase_log');
         if (empty($pushed_to_saas)) {
             $data = $purchase_log->get_data();
             $cart_contents = $purchase_log->get_cart_contents();
             //We want to push sales data - but naturally, IDs will differ, even names could potentially.
             //So we add the slug to the object we POST
             foreach ($cart_contents as $key => $cart_item) {
                 $slug = get_post_field('post_name', $cart_item->prodid);
                 $cart_contents[$key]->slug = $slug;
             }
             $args = array('body' => array('data' => json_encode($data), 'cart_contents' => json_encode($cart_contents)));
             $request = wp_remote_post('http://www.wpeconomy.org/?sales_data=true', $args);
             $response = wp_remote_retrieve_response_code($request);
             //For some reason, if the site is down, we want the ability to ensure we can grab the sale later.
             $success = 200 === $response;
             wpsc_update_meta($id, '_pushed_to_wpeconomy', $success, 'purchase_log');
         }
     }
 }
 function do_export_file()
 {
     global $wpdb;
     $trnsid = 1;
     $gateway_accounts = get_option('pbci_gateway_accounts', array());
     $export_accounts = get_option('pbci_export_accounts', array('sales_revenue' => 'Product Revenue', 'shipping' => 'Shipping', 'sales_tax_account' => 'Sales Tax Payable', 'sales_tax_payee' => 'Sales Tax'));
     $cust = array('NAME' => '', 'FIRSTNAME' => '', 'LASTNAME' => '', 'EMAIL' => '', 'PHONE1' => '', 'BADDR1' => '', 'BADDR2' => '', 'BADDR3' => '', 'BADDR4' => '', 'SADDR1' => '', 'SADDR2' => '', 'SADDR3' => '', 'SADDR4' => '');
     $trans = array('TRNSID' => '', 'TRNSTYPE' => '', 'DATE' => '', 'ACCNT' => '', 'AMOUNT' => '', 'NAME' => '', 'MEMO' => '', 'PAYMETH' => '');
     $spl = array('SPLID' => '', 'TRNSTYPE' => '', 'DATE' => '', 'ACCNT' => '', 'AMOUNT' => '', 'NAME' => '', 'MEMO' => '', 'INVITEM' => '', 'PRICE' => '', 'EXTRA' => '');
     $content = "";
     $cust_content = "";
     $headers = "";
     $headers .= "!CUST\tNAME\t\n";
     $headers .= "!ACCNT\tNAME\tACCNTTYPE\tEXTRA\tACCNUM\n";
     $content .= "ACCNT\t" . $export_accounts['sales_revenue'] . "\tINC\t\n";
     $content .= "ACCNT\t" . $export_accounts['shipping'] . "\tINC\t\n";
     $content .= "ACCNT\t" . $export_accounts['sales_tax_account'] . "\tOCLIAB\tSALESTAX\t2201\n";
     foreach ($gateway_accounts as $gateway => $account_name) {
         if (!empty($account_name)) {
             $content .= "ACCNT\t" . $account_name . "\tBANK\t\n";
         }
     }
     // !TRNS line
     $headers .= '!TRNS';
     foreach ($trans as $key => $value) {
         $headers .= "\t" . $key;
     }
     $headers .= "\n";
     // !SPL line
     $headers .= '!SPL';
     foreach ($spl as $key => $value) {
         $headers .= "\t" . $key;
     }
     $headers .= "\n";
     // !CUST line
     $headers .= '!CUST';
     foreach ($cust as $key => $value) {
         $headers .= "\t" . $key;
     }
     $headers .= "\n";
     // !ENDTRNS line
     //$content .= '!ENDTRNS' . "\n";
     $export_dates = array_keys($_POST['period']);
     foreach ($export_dates as $export_date) {
         $a = explode('-', $export_date);
         $year = $a[0];
         $month = $a[1];
         $sql = "SELECT ID FROM " . WPSC_TABLE_PURCHASE_LOGS . ' WHERE MONTH( FROM_UNIXTIME( date ) ) = ' . $month . ' AND YEAR( FROM_UNIXTIME( DATE ) ) = ' . $year . ' ORDER by date DESC';
         $result = $wpdb->get_col($sql, 0);
         $purchase_log_ids = array_map('intval', $result);
         $max_rows = 1;
         foreach ($purchase_log_ids as $purchase_log_id) {
             $purchase_log = new WPSC_Purchase_Log($purchase_log_id);
             $gateway_id = $purchase_log->get('gateway');
             $data = $purchase_log->get_data();
             if (empty($gateway_accounts[$gateway_id])) {
                 continue;
             }
             // reset the transaction array back to empty
             foreach ($trans as $key => $value) {
                 $trans[$key] = '';
             }
             // reset the customer array back to empty
             foreach ($cust as $key => $value) {
                 $cust[$key] = '';
             }
             if ($purchase_log->get('processed') != WPSC_Purchase_Log::ACCEPTED_PAYMENT && $purchase_log->get('processed') != WPSC_Purchase_Log::CLOSED_ORDER) {
                 continue;
             }
             $checkout_form_data = new WPSC_Checkout_Form_Data($purchase_log_id);
             $checkout = $checkout_form_data->get_data();
             if (!isset($checkout['billingstate'])) {
                 $checkout['billingstate'] = '';
             }
             if (!isset($checkout['shippingstate'])) {
                 $checkout['shippingstate'] = '';
             }
             $timestamp = $purchase_log->get('date');
             $thedate = date('m/d/Y', $timestamp);
             foreach ($trans as $key => $value) {
                 switch ($key) {
                     case 'TRNSID':
                         $trans[$key] = $trnsid++;
                         break;
                     case 'TIMESTAMP':
                         $trans[$key] = $purchase_log->get('date');
                         break;
                     case 'TRNSTYPE':
                         $trans[$key] = 'CASH SALE';
                         break;
                     case 'DATE':
                         $trans[$key] = $thedate;
                         break;
                     case 'ACCNT':
                         $trans[$key] = $gateway_accounts[$gateway_id];
                         break;
                     case 'NAME':
                         $trans[$key] = $checkout['billingfirstname'] . ' ' . $checkout['billinglastname'];
                         break;
                     case 'AMOUNT':
                         $trans[$key] = $purchase_log->get('totalprice');
                         break;
                     case 'CLEAR':
                         $trans[$key] = 'N';
                         break;
                     case 'SHIPDATE':
                         $trans[$key] = $thedate;
                         break;
                     case 'PAYMETH':
                         $trans[$key] = $purchase_log->get('gateway_name');
                         break;
                     case 'DOCNUM':
                         $trans[$key] = $purchase_log_id;
                         break;
                     case 'MEMO':
                         $trans[$key] = 'sparkle-gear.com purchase #' . $purchase_log_id;
                         break;
                     case 'ADDR1':
                         $trans[$key] = $checkout['billingfirstname'] . ' ' . $checkout['billinglastname'];
                         break;
                     case 'ADDR2':
                         $trans[$key] = $checkout['billingaddress'];
                         break;
                     case 'ADDR3':
                         $trans[$key] = $checkout['billingcity'] . ', ' . $checkout['billingstate'] . ' ' . $checkout['billingpostcode'];
                         break;
                     case 'ADDR4':
                         $trans[$key] = $checkout['billingcountry'];
                         break;
                     case 'SHIPVIA':
                         $trans[$key] = $purchase_log->get('shipping_method_name');
                         break;
                     case 'INVTITLE':
                         $trans[$key] = 'Sparkle Gear Web Store';
                         break;
                     case 'SADDR1':
                         $trans[$key] = $checkout['shippingfirstname'] . ' ' . $checkout['shippinglastname'];
                         break;
                     case 'SADDR2':
                         $trans[$key] = $checkout['shippingaddress'];
                         break;
                     case 'SADDR3':
                         $trans[$key] = $checkout['shippingcity'] . ', ' . $checkout['shippingstate'] . ' ' . $checkout['shippingpostcode'];
                         break;
                     case 'SADDR4':
                         $trans[$key] = $checkout['billingcountry'];
                         break;
                 }
             }
             foreach ($cust as $key => $value) {
                 switch ($key) {
                     case 'NAME':
                         $cust[$key] = $checkout['billingfirstname'] . ' ' . $checkout['billinglastname'];
                         break;
                     case 'FIRSTNAME':
                         $cust[$key] = $checkout['billingfirstname'];
                         break;
                     case 'LASTNAME':
                         $cust[$key] = $checkout['billinglastname'];
                         break;
                     case 'EMAIL':
                         $cust[$key] = $checkout['billingemail'];
                         break;
                     case 'PHONE1':
                         $cust[$key] = $checkout['billingphone'];
                         break;
                     case 'BADDR1':
                         $cust[$key] = $checkout['billingfirstname'] . ' ' . $checkout['billinglastname'];
                         break;
                     case 'BADDR2':
                         $cust[$key] = $checkout['billingaddress'];
                         break;
                     case 'BADDR3':
                         $cust[$key] = $checkout['billingcity'] . ', ' . $checkout['billingstate'] . ' ' . $checkout['billingpostcode'];
                         break;
                     case 'BADDR4':
                         $cust[$key] = $checkout['billingcountry'];
                         break;
                     case 'SADDR1':
                         $cust[$key] = $checkout['shippingfirstname'] . ' ' . $checkout['shippinglastname'];
                         break;
                     case 'SADDR2':
                         $cust[$key] = $checkout['shippingaddress'];
                         break;
                     case 'SADDR3':
                         $cust[$key] = $checkout['shippingcity'] . ', ' . $checkout['shippingstate'] . ' ' . $checkout['shippingpostcode'];
                         break;
                     case 'SADDR4':
                         $cust[$key] = $checkout['billingcountry'];
                         break;
                 }
             }
             foreach ($trans as $key => $value) {
                 $trans[$key] = trim(preg_replace('/\\s+/', ' ', $value));
             }
             foreach ($cust as $key => $value) {
                 $cust[$key] = trim(preg_replace('/\\s+/', ' ', $value));
             }
             $splid = 1;
             // TRNS line
             $content .= 'TRNS';
             foreach ($trans as $key => $value) {
                 $content .= "\t" . $value;
             }
             $content .= "\n";
             $cart_contents = $purchase_log->get_cart_contents();
             foreach ($cart_contents as $cart_item) {
                 $product_id = $cart_item->prodid;
                 if ($parent_product = get_post_field('post_parent', $product_id)) {
                     $product_id = $parent_product;
                 }
                 $terms = wp_get_post_terms($product_id, 'wpsc_product_category');
                 if (!empty($terms)) {
                     foreach ($terms as $term) {
                         $invitem = $term->name;
                         if ($term->parent != 0) {
                             break;
                         }
                     }
                 } else {
                     $invitem = '';
                 }
                 /*
                 $item_name = '';
                 
                 $article = new Bling_Article( $cart_item->prodid );
                 if ( $article->check() ) {
                 	$item_name = $article->name();
                 }
                 */
                 $spl_product = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['sales_revenue'], 'AMOUNT' => -($cart_item->price * $cart_item->quantity), 'QNTY' => -$cart_item->quantity, 'PRICE' => $cart_item->price, 'NAME' => '', 'DOCNUM' => $purchase_log_id, 'MEMO' => $cart_item->name);
                 // SPL line
                 $content .= 'SPL';
                 foreach ($spl as $key => $value) {
                     $content .= "\t";
                     if (!empty($spl_product[$key])) {
                         $content .= $spl_product[$key];
                     }
                 }
                 $content .= "\n";
             }
             $spl_shipping = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['shipping'], 'AMOUNT' => -$purchase_log->get('total_shipping'), 'PRICE' => $purchase_log->get('total_shipping'), 'NAME' => '', 'DOCNUM' => $purchase_log_id, 'MEMO' => 'customer paid shipping', 'EXTRA' => '', 'QNTY' => '');
             $splid = 2;
             $spl_discount = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['sales_revenue'], 'AMOUNT' => $purchase_log->get('discount_value'), 'PRICE' => -$purchase_log->get('discount_value'), 'NAME' => '', 'DOCNUM' => $purchase_log_id, 'MEMO' => 'discount', 'EXTRA' => '', 'QNTY' => '');
             $spl_tax = array('SPLID' => $trnsid++, 'TRNSTYPE' => 'PAYMENT', 'DATE' => $trans['DATE'], 'ACCNT' => $export_accounts['sales_tax_account'], 'AMOUNT' => -$purchase_log->get('wpec_taxes_total'), 'PRICE' => "6.25%", 'NAME' => $export_accounts['sales_tax_payee'], 'DOCNUM' => $purchase_log_id, 'MEMO' => 'sales tax', 'EXTRA' => 'AUTOSTAX', 'QNTY' => '', 'INVITEM' => 'MA Sales/Use Tax');
             $spl_end = array('SPLID' => $trnsid++, 'EXTRA' => 'ENDGRP');
             // SPL line
             $content .= 'SPL';
             foreach ($spl as $key => $value) {
                 $content .= "\t";
                 if (!empty($spl_shipping[$key])) {
                     $content .= $spl_shipping[$key];
                 }
             }
             $content .= "\n";
             // SPL line
             $content .= 'SPL';
             foreach ($spl as $key => $value) {
                 $content .= "\t";
                 if (!empty($spl_tax[$key])) {
                     $content .= $spl_tax[$key];
                 }
             }
             $content .= "\n";
             // SPL line
             $content .= 'SPL';
             foreach ($spl as $key => $value) {
                 $content .= "\t";
                 if (!empty($spl_discount[$key])) {
                     $content .= $spl_discount[$key];
                 }
             }
             $content .= "\n";
             $content .= 'SPL';
             foreach ($spl as $key => $value) {
                 $content .= "\t";
                 if (!empty($spl_end[$key])) {
                     $content .= $spl_end[$key];
                 }
             }
             $content .= "\n";
             $splid = 3;
             $content .= 'ENDTRNS';
             $content .= "\n";
             //if ( --$max_rows == 0 )
             //	break;
             $cust_content .= 'CUST';
             foreach ($cust as $key => $value) {
                 $cust_content .= "\t" . $value;
             }
             $cust_content .= "\n";
         }
     }
     $file_name = 'download.iif';
     header('Content-Type: text/csv');
     header('Content-Disposition: inline; filename="' . $file_name . '"');
     echo $headers;
     echo $cust_content;
     echo $content;
     exit;
 }