Changeset 2249413
- Timestamp:
- 02/24/2020 04:06:10 PM (6 years ago)
- Location:
- export-stripe-csv/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
stripe_csv_exports.php (modified) (41 diffs)
Legend:
- Unmodified
- Added
- Removed
-
export-stripe-csv/trunk/readme.txt
r1864017 r2249413 3 3 Tags: stripe, csv, custom, export 4 4 Requires at least: 4.0 5 Tested up to: 4.85 Tested up to: 5.3 6 6 7 7 Create CSV custom exports for accountancy needs (including VAT) … … 21 21 == Changelog == 22 22 23 1.2.2 24 23 25 1.2.1 - cumulated debt and served fixed 24 26 -
export-stripe-csv/trunk/stripe_csv_exports.php
r1910410 r2249413 1 1 <?php 2 3 2 /* 4 3 * Plugin Name: Stripe CSV Exports … … 6 5 * Description: Query Stripe API to create custom CSV exports for accountancy needs 7 6 * Author: Termel 8 * Version: 1.2. 17 * Version: 1.2.2 9 8 * Author URI: http://www.maxizone.fr/ 10 9 */ … … 15 14 // If you're using Composer, use Composer's autoload 16 15 $stripe_api_path = dirname( __FILE__ ) . '/vendor/autoload.php'; 17 // Logger::getLogger("default")->debug("File : " . $stripe_api_path);18 16 $stripe_api_path = realpath( $stripe_api_path ); 19 17 require_once $stripe_api_path; … … 54 52 function __construct() { 55 53 56 // $this->setUpLogger();57 54 add_action( 58 55 is_multisite() ? 'network_admin_menu' : 'admin_menu', … … 65 62 add_action( 'admin_init', array( $this, 'strcsvexp_email_report_now' ) ); 66 63 67 // Logger::getLogger("default")->debug("construct strcsvexp_stripe_source_plugin");68 64 self::getLogger()->trace( "Adding Module : " . __CLASS__ ); 69 65 add_filter( "strcsvexp_stripe_file_to_array", array( $this, "stripe_to_array" ), 10, 2 ); … … 149 145 static function getLogger() { 150 146 if ( self::$logger == null ) { 151 // gfchartreports_log ( "#################################" );152 147 strcsvexp_log( "########" ); 153 148 $dir = plugin_dir_path( __FILE__ ); … … 195 190 return $this; 196 191 } else { 197 // add_options_page( string $page_title, string $menu_title, string $capability, string $menu_slug, 198 // callable $function = '' ) 192 199 193 add_options_page( 200 194 $pageTitle, … … 355 349 $end = $current - 5; 356 350 while ( $year >= $end ) : 357 ?> 358 359 360 361 351 ?> 362 352 <option value="<?php echo $year; ?>"><?php echo $year; ?></option> 363 353 <?php … … 368 358 </select> <select name="strcsvexp-month" id="strcsvexp-month"> 369 359 <option value="0"><?php _e( 'All months', 'strcsvexp' ); ?> 370 <?php for( $i = 1; $i <= 12; $i++ ) : ?> 371 372 373 374 375 376 377 378 379 360 <?php for( $i = 1; $i <= 12; $i++ ) : ?> 380 361 <option value="<?php echo $i; ?>"><?php echo $this->strcsvexp_get_month_name( $i ); ?></option> 381 362 <?php endfor; ?> … … 400 381 value="<?php _e( 'Send report NOW', 'strcsvexp' ); ?>" /> <input 401 382 type="hidden" name="strcsvexp-action" value="send-report-email" /> 402 </p> 403 404 <?php /*wp_nonce_field('strcsvexp_nonce', 'strcsvexp_nonce');*/ ?> 405 <?php /*submit_button('Send Now');*/ ?> 406 383 </p> 407 384 </form> 408 385 <?php 409 386 } else 410 if ( $active_tab == 'encours_options' ) { 411 387 if ( $active_tab == 'encours_options' ) { 412 388 ?> 413 389 <!-- payments export --> … … 426 402 while ( $year >= $end ) : 427 403 ?> 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 <option value="<?php echo $year; ?>"><?php echo $year; ?></option> 404 <option value="<?php echo $year; ?>"><?php echo $year; ?></option> 443 405 <?php 444 406 $year--; … … 448 410 </select> <select name="strcsvexp-month" id="strcsvexp-month"> 449 411 <option value="0"><?php _e( 'All months', 'strcsvexp' ); ?> 450 <?php for( $i = 1; $i <= 12; $i++ ) : ?> 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 <option value="<?php echo $i; ?>"><?php echo $this->strcsvexp_get_month_name( $i ); ?></option> 412 <?php for( $i = 1; $i <= 12; $i++ ) : ?> <option value="<?php echo $i; ?>"><?php echo $this->strcsvexp_get_month_name( $i ); ?></option> 466 413 <?php endfor; ?> 467 414 </select> <select name="strcsvexp-groupby" id="strcsvexp-groupby"> … … 543 490 // add parameter to write the file for attachement 544 491 if ( $writeFile ) { 545 // $csv = Writer::createFromPath('/path/to/the/final.csv'); 546 547 /* 548 * $file = new SplTempFileObject (); 549 * $file->setFlags ( SplFileObject::READ_CSV ); 550 * $csv = Writer::createFromFileObject ( $file ); 551 */ 552 /* 553 * $upload_dir = wp_upload_dir(); // Array of key => value pairs 554 * $outputDir = $upload_dir['path']; 555 * self::getLogger ()->debug ('Writing to '.$outputDir); //=> 556 * C:\path\to\wordpress\wp-content\uploads\2010\05 557 * $csv = Writer::createFromPath($outputDir.$completeFilename); 558 */ 492 559 493 $upload_dir = wp_upload_dir(); // Array of key => value pairs 560 494 $outputDir = $upload_dir['path']; … … 590 524 591 525 function strcsvexp_export_payments() { 592 // Logger::getLogger("default")->debug($csv); 526 593 527 if ( isset( $_POST['strcsvexp-action'] ) ) { 594 528 … … 622 556 $shortcodeContent = '[strcsvexpStripe json="' . $jsonCharts . '"]'; 623 557 self::getLogger()->trace( $shortcodeContent ); 624 // echo do_shortcode($shortcodeContent);625 // die();626 558 } 627 559 } … … 719 651 "[$dataTypeKey][$yearKey] [$monthKey] [$weekKey] [$lineId]" ); 720 652 $data[$dataTypeKey][$yearKey][$monthKey][$weekKey][$lineId][] = $payoutLinked; 721 // self::getLogger ()->debug ($data [$dataTypeKey][$yearKey] [$monthKey] [$weekKey] 722 // [$lineId]); 653 723 654 } 724 655 } … … 728 659 } 729 660 730 // self::getLogger()->trace($data);731 732 661 return $data; 733 662 } … … 737 666 $result = array( ); 738 667 739 // $refund = $this->addRefundIfExists($allRefunds, $report, $csv, $this->dateFormat);740 668 $decimalAmont = $refund->amount / 100; 741 669 $creation_date = date( $this->dateFormat, $refund->created ); … … 798 726 '' // number_format ($to_be_served_CA, $this->nbOfDecimals,',', ' '), 799 727 ); 800 801 /* 802 * $report = array( 803 804 $id, 805 $description, 806 $chargeCreationDate, 807 $amount, 808 $export, 809 $vatValue, 810 $tvaAmount, 811 $HTamount, 812 $fee, 813 $finalGain, 814 $currency, 815 $plan_name, 816 $creation_date, 817 $start_date, 818 $end_subscription, 819 $cancelled_date, 820 $served_CA, 821 $to_be_served_CA ); 822 */ 823 728 824 729 self::getLogger()->debug($report); 825 730 $result = array( … … 871 776 } else { 872 777 self::getLogger()->error( "Cannot find balance transaction for charge " . $id ); 873 //self::getLogger()->error("### ". $bal_transaction);874 //self::getLogger()->error("No impact on FEE ???");875 876 778 return null; 877 779 } … … 883 785 return null; 884 786 } 885 // self::getLogger ()->debug ( "working on first subscription " );886 787 887 788 $tva = $firstSubs->tax_percent; … … 955 856 $chargesAndRefunds = array_merge( $allCharges, $allRefunds->data ); 956 857 957 //self::getLogger()->debug($chargesAndRefunds);958 858 // sort by date 959 859 … … 963 863 } 964 864 array_multisort( $dateArray, $this->dateSort, $chargesAndRefunds ); 965 966 //self::getLogger()->debug($chargesAndRefunds);967 968 969 970 /*971 * $dateArray = array();972 * foreach ($refunds as $key => $row) {973 * $dateArray[$key] = $row->created;974 * }975 * array_multisort($dateArray, $this->dateSort, $refunds);976 */977 865 978 866 // sort end … … 1030 918 $current_start_subscription->format( $this->dateFormat ) . ' #### Iterate from ' . 1031 919 $currentMonthDate->format( $this->dateFormat ) . ' -> ' . $endIteration->format( $this->dateFormat ) ); 1032 // $startOfTimeFrame = $currentMonthDate; 920 1033 921 if ( strval( $groupby ) == 'none' || strval( $groupby ) == 'month' || strval( $groupby ) == 'week') { 1034 922 … … 1043 931 while ( $currentMonthDate < $endIteration ) { 1044 932 $currentMonthDate = $currentMonthDate->add( $time_interval ); 1045 // strtotime('this week', time());1046 933 1047 934 if ( strval( $groupby ) == 'month' ) { … … 1062 949 self::getLogger()->debug( $current_period_start); 1063 950 self::getLogger()->debug( $current_period_end); 1064 1065 1066 // Logger::getLogger("default")->debug('Compute served for '.$description.' between 1067 // '.$current_period_start->format($this->dateFormat).' -> 1068 // '.$current_period_end->format($this->dateFormat)); 951 1069 952 if ( $current_period_start < $current_start_subscription && 1070 $current_start_subscription < $current_period_end ) { 1071 953 $current_start_subscription < $current_period_end ) { 1072 954 1073 // $debtArray = $this->getServed($subsNbOfDays, $day_price, $current_start_subscription,1074 // $current_period_end, $current_end_date);1075 955 $reportArray[$export][$currentYear][$currentMonth][$currentWeek][$timestamp] = $report; 1076 956 self::getLogger()->info( $idx.' / '.$totalOperations.' Inside timeframe'); 1077 957 self::getLogger()->debug('New report (charge) line : ' . implode( ' | ', $report ) ); 1078 /* 1079 * $refund = $this->addRefundIfExists($allRefunds, $report, $csv, $this->dateFormat); 1080 * if ($refund) { 1081 * $creation_date = $refund[2]; 1082 * // if ($current_period_start < $creation_date && $creation_date < $current_period_end) { 1083 * // $debtArray = $this->getServed($subsNbOfDays, $day_price, $current_start_subscription, $current_period_end, $current_end_date); 1084 * $reportArray[$export][$currentYear][$currentMonth][$currentWeek][] = $refund; 1085 * self::getLogger()->info('New report (refund) line : ' . implode(' - ', $report)); 1086 * // } 1087 * } 1088 */ 958 1089 959 } else { 1090 960 self::getLogger()->trace( … … 1094 964 } 1095 965 1096 // Logger::getLogger("default")->debug($current_start_subscription->format($this->dateFormat). ' / '.$current_period_start->format($this->dateFormat).' / '.$current_period_end->format($this->dateFormat).' - '.$debtArray['served'].' - '.$debtArray['debt']);1097 966 } 1098 967 } … … 1320 1189 1321 1190 if ($stripe_charge) { 1322 /* 1323 * if ($subscription->id== 'sub_Aj7K0GYCgaGmk1') { 1324 * Logger::getLogger("default")->debug($stripe_charge); 1325 * 1326 * } 1327 */ 1191 1328 1192 // $amount = $stripe_charge->amount / 100; 1329 1193 $tva = $subscription->tax_percent / 100; … … 1341 1205 1342 1206 $stripe_transaction = \Stripe\BalanceTransaction::retrieve ( $balId ); 1343 /* 1344 * if ($subscription->id== 'sub_Aj7K0GYCgaGmk1') { 1345 * Logger::getLogger("default")->debug($stripe_transaction); 1346 * } 1347 */ 1207 1348 1208 $fee = $stripe_transaction->fee / 100; // $subscription->application_fee_percent; 1349 1209 // self::getLogger()->debug("=> fee in transaction " . $fee); … … 1399 1259 } 1400 1260 1401 //Logger::getLogger ( "default" )->debug( 'Compute served for ' . $type . ' ' . $day_price . ' SERVED:' . $result ['served'] . ' DEBT:' . $result ['debt'] . ' AMOUNT:' . $pricesArray [$type] );1261 Logger::getLogger ( "default" )->trace ( 'Compute served for ' . $type . ' ' . $day_price . ' SERVED:' . $result ['served'] . ' DEBT:' . $result ['debt'] . ' AMOUNT:' . $pricesArray [$type] ); 1402 1262 1403 1263 return $result; … … 1414 1274 // Get the required charge information and assign to variables 1415 1275 $id = $subscription->id; 1416 /* 1417 * if ($id == 'sub_Aj7K0GYCgaGmk1') { 1418 * self::getLogger()->info($subscription); 1419 * } 1420 */ 1276 1421 1277 1422 1278 $creation_date = date ( $this->dateFormat, $subscription->created ); … … 1436 1292 $current_start_subscription = new DateTime ( $current_start_date ); 1437 1293 self::getLogger ()->info ( "######### Process sub : " . $id ); 1438 /* 1439 * if ($subscription->status != 'active') { 1440 * self::getLogger()->warn("skips " . $subscription->status . " subs " . $id); 1441 * continue; 1442 * } 1443 */ 1294 1444 1295 if ($current_start_subscription < $start_reference || $current_start_subscription > $reference_date) { 1445 1296 self::getLogger ()->warn ( $current_start_date ); 1446 1297 self::getLogger ()->warn ( "outside ref date range" ); 1447 /*self::getLogger ()->warn ( $start_reference ); 1448 self::getLogger ()->warn ( $reference_date );*/ 1298 1449 1299 continue; 1450 1300 } else { 1451 1301 self::getLogger ()->info ( $id . ' -- ' . $month_start . " < " . $creation_date . " (" . $current_start_date . ") " . ' < ' . $reportEndDate ); 1452 // Logger::getLogger("default")->debug($month_start." -> ".$reportEndDate);1302 Logger::getLogger("default")->trace($month_start." -> ".$reportEndDate); 1453 1303 } 1454 1304 … … 1472 1322 $subsNbOfDays = $this->getSubscriptionDayDuration ( $current_start_subscription, new DateTime ( $end_date ) ); 1473 1323 1474 /* 1475 * 1476 * $net_day_price = $finalGain / $subsNbOfDays; 1477 * $ttc_day_price = $pricesArray['TTC']/ $subsNbOfDays; 1478 * $ht_day_price = $pricesArray['HT']/ $subsNbOfDays; 1479 */ 1480 1481 // Logger::getLogger("default")->debug("Day Price : $day_price = $finalGain / $subsNbOfDays"); 1482 // served : CA SUR SERVICE 1483 1484 // Logger::getLogger("default")->debug($current_start_subscription->date); 1324 1485 1325 1486 1326 if (strval ( $groupby ) != 'none') { … … 1527 1367 $debtArray [$type] = $this->getServed ( $subsNbOfDays, $type, $pricesArray, $current_start_subscription, $current_month_end, $current_end_date ); 1528 1368 } else { 1529 /* 1530 * $debtArray[$type]['served'] = 0; 1531 * $debtArray[$type]['debt'] = 0; 1532 */ 1369 1533 1370 continue; 1534 1371 } … … 1577 1414 } 1578 1415 $debtArray [$type] = $this->getServed ( $subsNbOfDays, $type, $pricesArray, $current_start_subscription, new DateTime ( $current_month_end ), new DateTime ( $current_end_date ) ); 1579 /* 1580 * $globalDebt[$chargeType][$currentYear][$currentMonth][$type]['served'] += $debtArray[$type]['served']; 1581 * $globalDebt[$chargeType][$currentYear][$currentMonth][$type]['debt'] += $debtArray[$type]['debt']; 1582 */ 1416 1583 1417 self::getLogger ()->debug ("---- SERVED / DEBT ".$type." ----"); 1584 1418 self::getLogger ()->debug ($debtArray [$type]); … … 1613 1447 1614 1448 $globalDebt [$chargeType] [] = $report; 1615 /* 1616 * $sumReport [] = $report; 1617 * $formatted_export = $this->getFormattedArrayValues ( $report ); 1618 * // array_map(function($num){return !is_numeric($num) ? $num: number_format($num,$this->nbOfDecimals,',', ' ');}, $report); 1619 * 1620 * $csv->insertOne ( $formatted_export ); 1621 * 1622 */ 1449 1623 1450 } 1624 1451 } … … 1694 1521 $bigTotDebtNET += $sumTotDebt; 1695 1522 1696 /* 1697 * $sumCumulServed = array_sum ( array_column ( $allLines, 6 ) ); 1698 * //$bigTotCumulServed += $sumCumulServed; 1699 * $sumCumulDebt = array_sum ( array_column ( $allLines, 7 ) ); 1700 * //$bigTotCumulDebt += $sumCumulDebt; 1701 * $reportLine = array( 1702 * '', 1703 * '', 1704 * '', 1705 * __('Total'). ' '.$globalType, 1706 * $sumTotServed, 1707 * $sumTotDebt, 1708 * $sumCumulServed, 1709 * $sumCumulDebt 1710 * ); 1711 * $formatted_line = $this->getFormattedArrayValues($reportLine); 1712 */ 1523 1713 1524 $csv->insertOne (array()); 1714 /* 1715 * $csv->insertOne($formatted_line); 1716 * $csv->insertOne(); 1717 */ 1525 1718 1526 } 1719 1527 … … 1763 1571 $defaultValues = $defaultValues + $endOfLine; 1764 1572 $formatted_sums_line = $this->getAggregatedData ( $globalData, $defaultValues, $groupby ); 1765 /* 1766 * self::getLogger()->info($totalTitle); 1767 * self::getLogger()->info($formatted_sums_line); 1768 */ 1573 1769 1574 $csv->insertOne ( $formatted_sums_line ); 1770 1575 $csv->insertOne (array()); … … 2058 1863 if (is_readable ( $realPathFilename )) { 2059 1864 try { 2060 // $reader = Reader::createFromPath($realPathFilename); 2061 // load the CSV document 2062 /* 2063 * $csv = Reader::createFromPath($realPathFilename)->addStreamFilter('convert.iconv.ISO-8859-1/UTF-8')->setDelimiter(';')->setHeaderOffset(0); 2064 * $results = $csv->fetchAll(); 2065 */ 1865 2066 1866 $csv = Reader::createFromPath ( $realPathFilename ); 2067 1867 // get the first row, usually the CSV header … … 2200 2000 2201 2001 $numericValueToCatch = $this->tofloat ( $csvCell ); 2202 /* 2203 * $valueToCatch = $csvCell; 2204 * $trimed = $this->clean($valueToCatch); 2205 * Logger::getLogger("default")->trace($valueToCatch . ' => ' . $trimed); 2206 * if (is_numeric($trimed)) { 2207 * $valueToCatch = $trimed; // str_replace (' ','',$values [$yCol]); 2208 * } else { 2209 * $valueToCatch = '"' . $this->removeQuotesAndConvertHtml($valueToCatch) . '"'; 2210 * } 2211 */ 2002 2212 2003 self::getLogger ()->debug ( '*** Process ' . $csvRowKey . ' (' . $currentRowTitle . ') / ' . $csvColKey . ' (' . $colTitle . ') -> ' . $csvCell ); 2213 2004 2214 2005 $reportFields [0] ['datasets'] [$colTitle] ['data'] [$currentRowTitle] = $numericValueToCatch; 2215 // $reportFields [0] ['datasets'] ['label'] = $colTitle; 2216 2217 /* 2218 * $reportFields [$id] ['datasets'] [$datasetNameLabel] ['data'] [$datasetValLabel] = $scoreValue; 2219 * $reportFields [$id] ['labels'] [] = $datasetValLabel; 2220 */ 2006 2221 2007 } 2222 2008 $entriesProcessed ++; … … 2306 2092 $valueToCatch = $trimed; // str_replace (' ','',$values [$yCol]); 2307 2093 } else { 2308 /* 2309 * $idx ++; 2310 * continue; 2311 */ 2094 2312 2095 $valueToCatch = '"' . $this->removeQuotesAndConvertHtml ( $valueToCatch ) . '"'; 2313 2096 }
Note: See TracChangeset
for help on using the changeset viewer.