Plugin Directory

Changeset 3473105


Ignore:
Timestamp:
03/02/2026 09:42:43 PM (5 days ago)
Author:
shift8
Message:

WP-Cli updates, new testing regimen, documentation update

Location:
shift8-integration-for-gravity-forms-and-sap-business-one/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • shift8-integration-for-gravity-forms-and-sap-business-one/trunk/cli-test-submission.php

    r3454574 r3473105  
    15971597
    15981598WP_CLI::add_command('shift8-gravitysap-bp-lookup', 'Shift8_GravitySAP_BP_Lookup_Command');
     1599
     1600/**
     1601 * Streamlined SAP B1 query commands for manual verification and debugging.
     1602 *
     1603 * Provides direct querying of SAP B1 records by their unique identifiers.
     1604 * Designed for rapid manual testing: submit a form, grab the CardCode from
     1605 * the GF entry meta, then verify the full record in SAP B1.
     1606 *
     1607 * @since 1.4.9
     1608 */
     1609class Shift8_GravitySAP_SAP_Query_Command {
     1610
     1611    /**
     1612     * Look up a Business Partner in SAP B1 by CardCode.
     1613     *
     1614     * ## OPTIONS
     1615     *
     1616     * <card_code>
     1617     * : The SAP B1 CardCode (e.g., E00115)
     1618     *
     1619     * [--contacts]
     1620     * : Also display Contact Persons
     1621     *
     1622     * [--quotations]
     1623     * : Also display linked Sales Quotations
     1624     *
     1625     * [--json]
     1626     * : Output raw JSON response
     1627     *
     1628     * ## EXAMPLES
     1629     *
     1630     *     wp sap-query bp E00115
     1631     *     wp sap-query bp E00115 --contacts --quotations
     1632     *     wp sap-query bp E00115 --json
     1633     *
     1634     * @param array $args
     1635     * @param array $assoc_args
     1636     */
     1637    public function bp($args, $assoc_args) {
     1638        $card_code = isset($args[0]) ? sanitize_text_field($args[0]) : '';
     1639        $show_contacts = isset($assoc_args['contacts']);
     1640        $show_quotations = isset($assoc_args['quotations']);
     1641        $output_json = isset($assoc_args['json']);
     1642
     1643        if (empty($card_code)) {
     1644            WP_CLI::error('Please provide a CardCode: wp sap-query bp E00115');
     1645        }
     1646
     1647        $sap_service = $this->get_sap_service();
     1648        if (!$sap_service) {
     1649            return;
     1650        }
     1651
     1652        $reflection = new ReflectionClass($sap_service);
     1653        $method = $reflection->getMethod('make_request');
     1654        $method->setAccessible(true);
     1655
     1656        WP_CLI::line('');
     1657        WP_CLI::line('Querying SAP B1 for Business Partner: ' . $card_code);
     1658        WP_CLI::line(str_repeat('-', 60));
     1659
     1660        $response = $method->invoke($sap_service, 'GET', "/BusinessPartners('" . $card_code . "')");
     1661        $data = $this->parse_response($response);
     1662
     1663        if (!$data) {
     1664            WP_CLI::error("Business Partner '{$card_code}' not found in SAP B1");
     1665            return;
     1666        }
     1667
     1668        if ($output_json) {
     1669            WP_CLI::line(wp_json_encode($data, JSON_PRETTY_PRINT));
     1670            return;
     1671        }
     1672
     1673        WP_CLI::line('');
     1674        WP_CLI::line('  CardCode:     ' . ($data['CardCode'] ?? 'N/A'));
     1675        WP_CLI::line('  CardName:     ' . ($data['CardName'] ?? 'N/A'));
     1676        WP_CLI::line('  CardType:     ' . ($data['CardType'] ?? 'N/A'));
     1677        WP_CLI::line('  Series:       ' . ($data['Series'] ?? 'N/A'));
     1678        WP_CLI::line('  GroupCode:    ' . ($data['GroupCode'] ?? 'N/A'));
     1679        WP_CLI::line('  Email:        ' . ($data['EmailAddress'] ?? 'N/A'));
     1680        WP_CLI::line('  Phone:        ' . ($data['Phone1'] ?? 'N/A'));
     1681        WP_CLI::line('  Website:      ' . ($data['Website'] ?? 'N/A'));
     1682        WP_CLI::line('  Currency:     ' . ($data['Currency'] ?? 'N/A'));
     1683        WP_CLI::line('  PriceList:    ' . ($data['PriceListNum'] ?? 'N/A'));
     1684        WP_CLI::line('  FederalTaxID: ' . ($data['FederalTaxID'] ?? 'N/A'));
     1685        WP_CLI::line('  CreateDate:   ' . ($data['CreateDate'] ?? 'N/A'));
     1686        WP_CLI::line('  Valid:        ' . ($data['Valid'] ?? 'N/A'));
     1687
     1688        if (!empty($data['BPAddresses']) && is_array($data['BPAddresses'])) {
     1689            WP_CLI::line('');
     1690            WP_CLI::line('  Addresses:');
     1691            foreach ($data['BPAddresses'] as $addr) {
     1692                $type = ($addr['AddressType'] ?? '') === 'bo_BillTo' ? 'Bill-To' : 'Ship-To';
     1693                WP_CLI::line("    [{$type}] {$addr['Street']}, {$addr['City']}, {$addr['State']} {$addr['ZipCode']}, {$addr['Country']}");
     1694            }
     1695        }
     1696
     1697        if ($show_contacts && !empty($data['ContactEmployees']) && is_array($data['ContactEmployees'])) {
     1698            WP_CLI::line('');
     1699            WP_CLI::line('  Contact Persons:');
     1700            foreach ($data['ContactEmployees'] as $contact) {
     1701                $code = $contact['InternalCode'] ?? 'N/A';
     1702                $name = $contact['Name'] ?? 'N/A';
     1703                $email = $contact['E_Mail'] ?? '';
     1704                $phone = $contact['Phone1'] ?? '';
     1705                WP_CLI::line("    [{$code}] {$name} | {$email} | {$phone}");
     1706            }
     1707        }
     1708
     1709        if ($show_quotations) {
     1710            WP_CLI::line('');
     1711            WP_CLI::line('  Sales Quotations:');
     1712            $q_response = $method->invoke(
     1713                $sap_service,
     1714                'GET',
     1715                "/Quotations?\$filter=CardCode eq '{$card_code}'&\$select=DocEntry,DocNum,DocDate,DocTotal,DocCurrency,DocumentStatus&\$orderby=DocEntry desc&\$top=20"
     1716            );
     1717            $q_data = $this->parse_response($q_response);
     1718
     1719            if ($q_data && !empty($q_data['value'])) {
     1720                foreach ($q_data['value'] as $q) {
     1721                    $status = ($q['DocumentStatus'] ?? '') === 'bost_Open' ? 'Open' : ($q['DocumentStatus'] ?? 'N/A');
     1722                    WP_CLI::line(sprintf(
     1723                        '    DocNum: %-8s | DocEntry: %-8s | Date: %s | Total: %s %s | Status: %s',
     1724                        $q['DocNum'] ?? 'N/A',
     1725                        $q['DocEntry'] ?? 'N/A',
     1726                        $q['DocDate'] ?? 'N/A',
     1727                        $q['DocTotal'] ?? '0',
     1728                        $q['DocCurrency'] ?? '',
     1729                        $status
     1730                    ));
     1731                }
     1732            } else {
     1733                WP_CLI::line('    (none)');
     1734            }
     1735        }
     1736
     1737        WP_CLI::line('');
     1738    }
     1739
     1740    /**
     1741     * Look up a Sales Quotation in SAP B1 by DocEntry.
     1742     *
     1743     * ## OPTIONS
     1744     *
     1745     * <doc_entry>
     1746     * : The SAP B1 DocEntry (numeric ID)
     1747     *
     1748     * [--json]
     1749     * : Output raw JSON response
     1750     *
     1751     * ## EXAMPLES
     1752     *
     1753     *     wp sap-query quotation 285
     1754     *     wp sap-query quotation 285 --json
     1755     *
     1756     * @param array $args
     1757     * @param array $assoc_args
     1758     */
     1759    public function quotation($args, $assoc_args) {
     1760        $doc_entry = isset($args[0]) ? intval($args[0]) : 0;
     1761        $output_json = isset($assoc_args['json']);
     1762
     1763        if (empty($doc_entry)) {
     1764            WP_CLI::error('Please provide a DocEntry: wp sap-query quotation 285');
     1765        }
     1766
     1767        $sap_service = $this->get_sap_service();
     1768        if (!$sap_service) {
     1769            return;
     1770        }
     1771
     1772        $reflection = new ReflectionClass($sap_service);
     1773        $method = $reflection->getMethod('make_request');
     1774        $method->setAccessible(true);
     1775
     1776        WP_CLI::line('');
     1777        WP_CLI::line('Querying SAP B1 for Sales Quotation DocEntry: ' . $doc_entry);
     1778        WP_CLI::line(str_repeat('-', 60));
     1779
     1780        $response = $method->invoke($sap_service, 'GET', '/Quotations(' . $doc_entry . ')');
     1781        $data = $this->parse_response($response);
     1782
     1783        if (!$data) {
     1784            WP_CLI::error("Sales Quotation DocEntry '{$doc_entry}' not found in SAP B1");
     1785            return;
     1786        }
     1787
     1788        if ($output_json) {
     1789            WP_CLI::line(wp_json_encode($data, JSON_PRETTY_PRINT));
     1790            return;
     1791        }
     1792
     1793        WP_CLI::line('');
     1794        WP_CLI::line('  DocEntry:           ' . ($data['DocEntry'] ?? 'N/A'));
     1795        WP_CLI::line('  DocNum:             ' . ($data['DocNum'] ?? 'N/A'));
     1796        WP_CLI::line('  CardCode:           ' . ($data['CardCode'] ?? 'N/A'));
     1797        WP_CLI::line('  CardName:           ' . ($data['CardName'] ?? 'N/A'));
     1798        WP_CLI::line('  ContactPersonCode:  ' . ($data['ContactPersonCode'] ?? 'N/A'));
     1799        WP_CLI::line('  DocDate:            ' . ($data['DocDate'] ?? 'N/A'));
     1800        WP_CLI::line('  DocDueDate:         ' . ($data['DocDueDate'] ?? 'N/A'));
     1801        WP_CLI::line('  DocTotal:           ' . ($data['DocTotal'] ?? '0') . ' ' . ($data['DocCurrency'] ?? ''));
     1802        WP_CLI::line('  DocumentStatus:     ' . ($data['DocumentStatus'] ?? 'N/A'));
     1803        WP_CLI::line('  Comments:           ' . ($data['Comments'] ?? 'N/A'));
     1804
     1805        if (!empty($data['DocumentLines']) && is_array($data['DocumentLines'])) {
     1806            WP_CLI::line('');
     1807            WP_CLI::line('  Line Items (' . count($data['DocumentLines']) . '):');
     1808            foreach ($data['DocumentLines'] as $i => $line) {
     1809                $num = $i + 1;
     1810                WP_CLI::line("    Line {$num}:");
     1811                WP_CLI::line('      ItemCode:    ' . ($line['ItemCode'] ?? 'N/A'));
     1812                WP_CLI::line('      Description: ' . ($line['ItemDescription'] ?? 'N/A'));
     1813                WP_CLI::line('      Quantity:    ' . ($line['Quantity'] ?? 'N/A'));
     1814                WP_CLI::line('      UnitPrice:   ' . ($line['UnitPrice'] ?? 'N/A'));
     1815                WP_CLI::line('      LineTotal:   ' . ($line['LineTotal'] ?? 'N/A'));
     1816                if (!empty($line['WarehouseCode'])) {
     1817                    WP_CLI::line('      Warehouse:   ' . $line['WarehouseCode']);
     1818                }
     1819            }
     1820        }
     1821
     1822        WP_CLI::line('');
     1823    }
     1824
     1825    /**
     1826     * Look up a Gravity Forms entry and its linked SAP B1 records.
     1827     *
     1828     * Reads the SAP identifiers stored in entry meta and queries SAP B1
     1829     * to verify the records exist and display their details.
     1830     *
     1831     * ## OPTIONS
     1832     *
     1833     * [<entry_id>]
     1834     * : The Gravity Forms entry ID. Omit and use --form_id to get the latest entry.
     1835     *
     1836     * [--form_id=<form_id>]
     1837     * : Get the latest entry for this form ID (instead of specifying entry_id)
     1838     *
     1839     * [--verify]
     1840     * : Also query SAP B1 to verify the linked records exist
     1841     *
     1842     * [--json]
     1843     * : Output raw JSON of all SAP meta
     1844     *
     1845     * ## EXAMPLES
     1846     *
     1847     *     wp sap-query entry 132
     1848     *     wp sap-query entry 132 --verify
     1849     *     wp sap-query entry --form_id=3 --verify
     1850     *
     1851     * @param array $args
     1852     * @param array $assoc_args
     1853     */
     1854    public function entry($args, $assoc_args) {
     1855        $entry_id = isset($args[0]) ? intval($args[0]) : 0;
     1856        $form_id = isset($assoc_args['form_id']) ? absint($assoc_args['form_id']) : 0;
     1857        $verify = isset($assoc_args['verify']);
     1858        $output_json = isset($assoc_args['json']);
     1859
     1860        if (empty($entry_id) && !empty($form_id)) {
     1861            $search = GFAPI::get_entries($form_id, array('status' => 'active'), array('key' => 'date_created', 'direction' => 'DESC'), array('offset' => 0, 'page_size' => 1));
     1862            if (empty($search)) {
     1863                WP_CLI::error("No entries found for form #{$form_id}");
     1864                return;
     1865            }
     1866            $entry_id = intval($search[0]['id']);
     1867            WP_CLI::line("Using latest entry #{$entry_id} from form #{$form_id}");
     1868        }
     1869
     1870        if (empty($entry_id)) {
     1871            WP_CLI::error('Provide an entry ID or --form_id: wp sap-query entry 132 OR wp sap-query entry --form_id=3');
     1872        }
     1873
     1874        $entry = GFAPI::get_entry($entry_id);
     1875        if (is_wp_error($entry)) {
     1876            WP_CLI::error("Entry #{$entry_id} not found");
     1877            return;
     1878        }
     1879
     1880        $meta_keys = array(
     1881            'sap_b1_status',
     1882            'sap_b1_cardcode',
     1883            'sap_b1_bp_matched',
     1884            'sap_b1_contact_internal_code',
     1885            'sap_b1_contact_name',
     1886            'sap_b1_quotation_docentry',
     1887            'sap_b1_quotation_docnum',
     1888            'sap_b1_error',
     1889        );
     1890
     1891        $meta = array();
     1892        foreach ($meta_keys as $key) {
     1893            $val = gform_get_meta($entry_id, $key);
     1894            $meta[$key] = $val ? $val : '';
     1895        }
     1896
     1897        if ($output_json) {
     1898            WP_CLI::line(wp_json_encode($meta, JSON_PRETTY_PRINT));
     1899            return;
     1900        }
     1901
     1902        WP_CLI::line('');
     1903        WP_CLI::line('Gravity Forms Entry #' . $entry_id . ' - SAP B1 Integration Data');
     1904        WP_CLI::line(str_repeat('-', 60));
     1905        WP_CLI::line('');
     1906        WP_CLI::line('  Form ID:              ' . ($entry['form_id'] ?? 'N/A'));
     1907        WP_CLI::line('  Date Created:         ' . ($entry['date_created'] ?? 'N/A'));
     1908        WP_CLI::line('');
     1909        WP_CLI::line('  SAP Status:           ' . ($meta['sap_b1_status'] ?: '(not set)'));
     1910        WP_CLI::line('  CardCode:             ' . ($meta['sap_b1_cardcode'] ?: '(not set)'));
     1911        WP_CLI::line('  BP Matched (existing):' . ($meta['sap_b1_bp_matched'] ? 'Yes' : 'No (new BP created)'));
     1912        WP_CLI::line('  Contact Name:         ' . ($meta['sap_b1_contact_name'] ?: '(not set)'));
     1913        WP_CLI::line('  Contact InternalCode: ' . ($meta['sap_b1_contact_internal_code'] ?: '(not set)'));
     1914        WP_CLI::line('  Quotation DocEntry:   ' . ($meta['sap_b1_quotation_docentry'] ?: '(not set)'));
     1915        WP_CLI::line('  Quotation DocNum:     ' . ($meta['sap_b1_quotation_docnum'] ?: '(not set)'));
     1916
     1917        if (!empty($meta['sap_b1_error'])) {
     1918            WP_CLI::line('  Error:                ' . $meta['sap_b1_error']);
     1919        }
     1920
     1921        if ($verify && !empty($meta['sap_b1_cardcode'])) {
     1922            WP_CLI::line('');
     1923            WP_CLI::line('Verifying against SAP B1...');
     1924            WP_CLI::line(str_repeat('-', 60));
     1925
     1926            $sap_service = $this->get_sap_service();
     1927            if ($sap_service) {
     1928                $reflection = new ReflectionClass($sap_service);
     1929                $req = $reflection->getMethod('make_request');
     1930                $req->setAccessible(true);
     1931
     1932                $bp_response = $req->invoke($sap_service, 'GET', "/BusinessPartners('" . $meta['sap_b1_cardcode'] . "')");
     1933                $bp_data = $this->parse_response($bp_response);
     1934
     1935                if ($bp_data) {
     1936                    WP_CLI::success('Business Partner ' . $meta['sap_b1_cardcode'] . ' exists in SAP B1');
     1937                    WP_CLI::line('    CardName: ' . ($bp_data['CardName'] ?? 'N/A'));
     1938                    WP_CLI::line('    Email:    ' . ($bp_data['EmailAddress'] ?? 'N/A'));
     1939
     1940                    if (!empty($meta['sap_b1_contact_internal_code']) && !empty($bp_data['ContactEmployees'])) {
     1941                        $found = false;
     1942                        foreach ($bp_data['ContactEmployees'] as $c) {
     1943                            if (isset($c['InternalCode']) && (string) $c['InternalCode'] === (string) $meta['sap_b1_contact_internal_code']) {
     1944                                WP_CLI::success('Contact Person InternalCode ' . $meta['sap_b1_contact_internal_code'] . ' verified');
     1945                                WP_CLI::line('      Name:  ' . ($c['Name'] ?? 'N/A'));
     1946                                WP_CLI::line('      Email: ' . ($c['E_Mail'] ?? 'N/A'));
     1947                                $found = true;
     1948                                break;
     1949                            }
     1950                        }
     1951                        if (!$found) {
     1952                            WP_CLI::warning('Contact InternalCode ' . $meta['sap_b1_contact_internal_code'] . ' not found on BP');
     1953                        }
     1954                    }
     1955                } else {
     1956                    WP_CLI::warning('Business Partner ' . $meta['sap_b1_cardcode'] . ' NOT found in SAP B1');
     1957                }
     1958
     1959                if (!empty($meta['sap_b1_quotation_docentry'])) {
     1960                    $q_response = $req->invoke($sap_service, 'GET', '/Quotations(' . intval($meta['sap_b1_quotation_docentry']) . ')');
     1961                    $q_data = $this->parse_response($q_response);
     1962
     1963                    if ($q_data) {
     1964                        WP_CLI::success('Quotation DocEntry ' . $meta['sap_b1_quotation_docentry'] . ' exists in SAP B1');
     1965                        WP_CLI::line('    DocNum:   ' . ($q_data['DocNum'] ?? 'N/A'));
     1966                        WP_CLI::line('    CardCode: ' . ($q_data['CardCode'] ?? 'N/A'));
     1967                        WP_CLI::line('    DocTotal: ' . ($q_data['DocTotal'] ?? '0') . ' ' . ($q_data['DocCurrency'] ?? ''));
     1968                        WP_CLI::line('    Status:   ' . ($q_data['DocumentStatus'] ?? 'N/A'));
     1969                    } else {
     1970                        WP_CLI::warning('Quotation DocEntry ' . $meta['sap_b1_quotation_docentry'] . ' NOT found in SAP B1');
     1971                    }
     1972                }
     1973            }
     1974        }
     1975
     1976        WP_CLI::line('');
     1977    }
     1978
     1979    /**
     1980     * Search for Business Partners by name (case-insensitive contains).
     1981     *
     1982     * ## OPTIONS
     1983     *
     1984     * <name>
     1985     * : Partial name to search for
     1986     *
     1987     * [--limit=<num>]
     1988     * : Maximum results to return (default: 20)
     1989     *
     1990     * ## EXAMPLES
     1991     *
     1992     *     wp sap-query search "Emilie Cohen"
     1993     *     wp sap-query search "Marino" --limit=5
     1994     *
     1995     * @param array $args
     1996     * @param array $assoc_args
     1997     */
     1998    public function search($args, $assoc_args) {
     1999        $name = isset($args[0]) ? sanitize_text_field($args[0]) : '';
     2000        $limit = isset($assoc_args['limit']) ? absint($assoc_args['limit']) : 20;
     2001
     2002        if (empty($name)) {
     2003            WP_CLI::error('Please provide a search term: wp sap-query search "Company Name"');
     2004        }
     2005
     2006        $sap_service = $this->get_sap_service();
     2007        if (!$sap_service) {
     2008            return;
     2009        }
     2010
     2011        $reflection = new ReflectionClass($sap_service);
     2012        $method = $reflection->getMethod('make_request');
     2013        $method->setAccessible(true);
     2014
     2015        $escaped_name = str_replace("'", "''", $name);
     2016        $endpoint = "/BusinessPartners?\$filter=contains(CardName, '{$escaped_name}')&\$select=CardCode,CardName,CardType,EmailAddress,Phone1,Valid&\$top={$limit}&\$orderby=CardCode";
     2017
     2018        WP_CLI::line('');
     2019        WP_CLI::line('Searching SAP B1 for Business Partners matching: "' . $name . '"');
     2020        WP_CLI::line(str_repeat('-', 60));
     2021
     2022        $response = $method->invoke($sap_service, 'GET', $endpoint);
     2023        $data = $this->parse_response($response);
     2024
     2025        if (!$data || empty($data['value'])) {
     2026            WP_CLI::warning('No Business Partners found matching "' . $name . '"');
     2027            WP_CLI::line('');
     2028            return;
     2029        }
     2030
     2031        WP_CLI::line('');
     2032        WP_CLI::line(sprintf('  %-12s %-35s %-6s %-30s %s', 'CardCode', 'CardName', 'Type', 'Email', 'Valid'));
     2033        WP_CLI::line('  ' . str_repeat('-', 100));
     2034
     2035        foreach ($data['value'] as $bp) {
     2036            WP_CLI::line(sprintf(
     2037                '  %-12s %-35s %-6s %-30s %s',
     2038                $bp['CardCode'] ?? '',
     2039                mb_substr($bp['CardName'] ?? '', 0, 35),
     2040                $bp['CardType'] ?? '',
     2041                mb_substr($bp['EmailAddress'] ?? '', 0, 30),
     2042                $bp['Valid'] ?? ''
     2043            ));
     2044        }
     2045
     2046        WP_CLI::line('');
     2047        WP_CLI::line('Found ' . count($data['value']) . ' result(s). Use `wp sap-query bp <CardCode>` for full details.');
     2048        WP_CLI::line('');
     2049    }
     2050
     2051    /**
     2052     * Initialize and return an authenticated SAP service instance.
     2053     *
     2054     * @return Shift8_GravitySAP_SAP_Service|null
     2055     */
     2056    private function get_sap_service() {
     2057        $sap_settings = get_option('shift8_gravitysap_settings', array());
     2058
     2059        if (empty($sap_settings['sap_endpoint']) || empty($sap_settings['sap_username']) || empty($sap_settings['sap_password'])) {
     2060            WP_CLI::error('SAP connection settings not configured.');
     2061            return null;
     2062        }
     2063
     2064        $sap_settings['sap_password'] = shift8_gravitysap_decrypt_password($sap_settings['sap_password']);
     2065
     2066        require_once plugin_dir_path(__FILE__) . 'includes/class-shift8-gravitysap-sap-service.php';
     2067        $sap_service = new Shift8_GravitySAP_SAP_Service($sap_settings);
     2068
     2069        $reflection = new ReflectionClass($sap_service);
     2070        $auth = $reflection->getMethod('ensure_authenticated');
     2071        $auth->setAccessible(true);
     2072
     2073        if (!$auth->invoke($sap_service)) {
     2074            WP_CLI::error('Failed to authenticate with SAP B1');
     2075            return null;
     2076        }
     2077
     2078        return $sap_service;
     2079    }
     2080
     2081    /**
     2082     * Parse a SAP Service Layer response into an array.
     2083     *
     2084     * @param mixed $response wp_remote_post/get response
     2085     * @return array|null Parsed data or null on failure
     2086     */
     2087    private function parse_response($response) {
     2088        if (is_wp_error($response)) {
     2089            return null;
     2090        }
     2091
     2092        $code = wp_remote_retrieve_response_code($response);
     2093        if ($code !== 200) {
     2094            return null;
     2095        }
     2096
     2097        $body = wp_remote_retrieve_body($response);
     2098        $data = json_decode($body, true);
     2099
     2100        return $data ?: null;
     2101    }
     2102}
     2103
     2104WP_CLI::add_command('sap-query', 'Shift8_GravitySAP_SAP_Query_Command');
  • shift8-integration-for-gravity-forms-and-sap-business-one/trunk/readme.txt

    r3454796 r3473105  
    55* Requires at least: 5.0
    66* Tested up to: 6.8
    7 * Stable tag: 1.4.8
     7* Stable tag: 1.4.9
    88* Requires PHP: 7.4
    99* License: GPLv3
     
    131131
    132132== Changelog ==
     133
     134= 1.4.9 =
     135* **NEW**: WP-CLI `sap-query` command for direct SAP B1 record queries (bp, quotation, entry, search)
     136* **NEW**: SAP identifiers stored in GF entry meta for cross-referencing (bp_matched, contact_name, contact_internal_code)
     137* **IMPROVED**: Entry list SAP Status column shows BP match type, Quotation DocNum, and Contact name
     138* **IMPROVED**: Comprehensive WP-CLI documentation for manual testing and verification workflows
    133139
    134140= 1.4.8 =
  • shift8-integration-for-gravity-forms-and-sap-business-one/trunk/shift8-gravitysap.php

    r3454796 r3473105  
    44 * Plugin URI: https://github.com/stardothosting/shift8-gravitysap
    55 * Description: Integrates Gravity Forms with SAP Business One, automatically creating Business Partners from form submissions.
    6  * Version: 1.4.8
     6 * Version: 1.4.9
    77 * Author: Shift8 Web
    88 * Author URI: https://shift8web.ca
     
    2323
    2424// Plugin constants
    25 define('SHIFT8_GRAVITYSAP_VERSION', '1.4.8');
     25define('SHIFT8_GRAVITYSAP_VERSION', '1.4.9');
    2626define('SHIFT8_GRAVITYSAP_PLUGIN_FILE', __FILE__);
    2727define('SHIFT8_GRAVITYSAP_PLUGIN_DIR', plugin_dir_path(__FILE__));
     
    18821882               
    18831883                $this->update_entry_sap_status($entry['id'], 'success', $card_code, '');
     1884                gform_update_meta($entry['id'], 'sap_b1_bp_matched', '1');
     1885                if (!empty($contact_person_name)) {
     1886                    gform_update_meta($entry['id'], 'sap_b1_contact_name', $contact_person_name);
     1887                }
     1888                if (!empty($contact_person_code)) {
     1889                    gform_update_meta($entry['id'], 'sap_b1_contact_internal_code', (string) $contact_person_code);
     1890                }
    18841891               
    18851892                GFFormsModel::add_note(
     
    19311938               
    19321939                $this->update_entry_sap_status($entry['id'], 'success', $card_code, '');
     1940                gform_update_meta($entry['id'], 'sap_b1_bp_matched', '0');
     1941                if (!empty($contact_person_name)) {
     1942                    gform_update_meta($entry['id'], 'sap_b1_contact_name', $contact_person_name);
     1943                }
     1944                if (!empty($contact_person_code)) {
     1945                    gform_update_meta($entry['id'], 'sap_b1_contact_internal_code', (string) $contact_person_code);
     1946                }
    19331947               
    19341948                GFFormsModel::add_note(
     
    26092623                $entry['sap_b1_error'] = $error;
    26102624            }
     2625           
     2626            $quotation_docentry = gform_get_meta($entry['id'], 'sap_b1_quotation_docentry');
     2627            if ($quotation_docentry) {
     2628                $entry['sap_b1_quotation_docentry'] = $quotation_docentry;
     2629            }
     2630           
     2631            $quotation_docnum = gform_get_meta($entry['id'], 'sap_b1_quotation_docnum');
     2632            if ($quotation_docnum) {
     2633                $entry['sap_b1_quotation_docnum'] = $quotation_docnum;
     2634            }
     2635           
     2636            $bp_matched = gform_get_meta($entry['id'], 'sap_b1_bp_matched');
     2637            if ($bp_matched !== false && $bp_matched !== '') {
     2638                $entry['sap_b1_bp_matched'] = $bp_matched;
     2639            }
     2640           
     2641            $contact_name = gform_get_meta($entry['id'], 'sap_b1_contact_name');
     2642            if ($contact_name) {
     2643                $entry['sap_b1_contact_name'] = $contact_name;
     2644            }
     2645           
     2646            $contact_code = gform_get_meta($entry['id'], 'sap_b1_contact_internal_code');
     2647            if ($contact_code) {
     2648                $entry['sap_b1_contact_internal_code'] = $contact_code;
     2649            }
    26112650        }
    26122651       
     
    28042843       
    28052844        if (!empty($sap_cardcode)) {
    2806             return '<span style="color: green; font-weight: bold;">✅ SUCCESS</span><br><small>CardCode: ' . esc_html($sap_cardcode) . '</small>';
     2845            $bp_matched = rgar($entry, 'sap_b1_bp_matched', '');
     2846            $match_label = ($bp_matched === '1') ? 'Matched' : 'New';
     2847            $quotation_docnum = rgar($entry, 'sap_b1_quotation_docnum', '');
     2848            $contact_name = rgar($entry, 'sap_b1_contact_name', '');
     2849           
     2850            $html = '<span style="color: green; font-weight: bold;">✅ SUCCESS</span>';
     2851            $html .= '<br><small>BP: ' . esc_html($sap_cardcode) . ' (' . esc_html($match_label) . ')</small>';
     2852           
     2853            if (!empty($quotation_docnum)) {
     2854                $html .= '<br><small>Quote #' . esc_html($quotation_docnum) . '</small>';
     2855            }
     2856            if (!empty($contact_name)) {
     2857                $html .= '<br><small>Contact: ' . esc_html($contact_name) . '</small>';
     2858            }
     2859           
     2860            return $html;
    28072861        } elseif (!empty($sap_error)) {
    28082862            $retry_button = '<br><button type="button" class="button button-small retry-sap-submission" data-entry-id="' . esc_attr($entry_id) . '" style="margin-top: 5px;">🔄 Retry</button>';
Note: See TracChangeset for help on using the changeset viewer.