Skip to content

Commit f37463d

Browse files
Made some methods publicly accessible to enable clients to post their own invoices and journals
1 parent 6072ef2 commit f37463d

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

class-thinking-logic-wc-sage.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function handleCreateSageInvoices( string $order_id ) {
125125
*
126126
* @return boolean true if the order is valid
127127
*/
128-
private function validateOrder( WC_Order $order ): bool {
128+
public function validateOrder( WC_Order $order ): bool {
129129
$result = true;
130130
foreach ( $order->get_items() as $item ) {
131131
if ( ! $this->getSalesLedgerId( $item ) ) {
@@ -525,14 +525,14 @@ private function mapInvoicesByDate( $invoices, string $reference ): array {
525525

526526
/**
527527
* Creates an invoice in SageOne.
528-
* See also: https://developer.columbus.sage.com/docs#/uki/sageone/accounts/v3/sales_invoices_sales_invoice
528+
* See also: https://developer.sage.com/api/accounting/api/invoicing-sales/#operation/postSalesInvoices
529529
*
530530
* @param WC_Order $order The order
531531
* @param object $customer The customer as a Sage contact. https://developer.sage.com/api/accounting/api/contacts/#tag/Contacts.
532-
* @param string $invoice_date The invoice date in the format ::DATE_FORMAT
532+
* @param string $invoice_date The invoice date in the format ::SAGE_DATE_FORMAT
533533
* @param number $invoice_amount The invoice amount
534534
*
535-
* @return object the response from sage, as a json object. https://developer.columbus.sage.com/docs#/uki/sageone/accounts/v3/sales_invoices_sales_invoice
535+
* @return object the response from sage, as a json object. https://developer.sage.com/api/accounting/api/invoicing-sales/#operation/postSalesInvoices
536536
*/
537537
private function createInvoice( WC_Order $order, $customer, string $invoice_date, $invoice_amount ) {
538538
$invoice_fraction = $this->calculateInvoiceFraction( $order, $invoice_amount );
@@ -565,7 +565,7 @@ private function createInvoice( WC_Order $order, $customer, string $invoice_date
565565
$sales_invoice = apply_filters( ThinkingLogicWCSage::FILTER_INVOICE, $sales_invoice, $order );
566566
Logger::log( "createInvoice: after filter: " . json_encode( $sales_invoice ) );
567567

568-
return $this->postData( '/sales_invoices', [ 'sales_invoice' => $sales_invoice ] )->getJSON();
568+
return $this->postInvoiceToSage( $sales_invoice );
569569
}
570570

571571
/**
@@ -586,9 +586,9 @@ private function calculateInvoiceFraction( $order, $invoice_amount ) {
586586
* @param WC_Order_Item $item The line item
587587
* @param float $invoice_fraction the fraction of the order value accounted for by this invoice.
588588
*
589-
* @return array the line item as defined by https://developer.columbus.sage.com/docs#/uki/sageone/accounts/v3/sales_invoices_sales_invoice_invoice_lines
589+
* @return array the line item as defined by https://developer.sage.com/api/accounting/api/invoicing-sales/#operation/postSalesInvoices
590590
*/
591-
private function getSalesInvoiceLineItem( WC_Order_Item $item, float $invoice_fraction ): array {
591+
public function getSalesInvoiceLineItem( WC_Order_Item $item, float $invoice_fraction ): array {
592592
$line_item_amount = $item->get_total() * $invoice_fraction;
593593
$line_item_tax = $item->get_total_tax() * $invoice_fraction;
594594
$description = $this->getLineItemDetail( $item );
@@ -616,16 +616,21 @@ private function getLineItemDetail( WC_Order_item $item ): string {
616616
$detail = $item->get_name();
617617
$meta_data = $item->get_meta_data();
618618
foreach ( $meta_data as $meta ) {
619-
// $key = $meta->key;
620-
// if ((substr($key, 0, 3) === 'pa_')) {
621-
// $key = substr($key, 3);
622-
// }
623-
$detail .= ', ' . $meta->value; //' ' . $key . '=' . $meta->value;
619+
$detail .= ', ' . $meta->value;
624620
}
625621

626622
return $detail;
627623
}
628624

625+
/**
626+
* @param $sales_invoice object see https://developer.sage.com/api/accounting/api/invoicing-sales/#operation/postSalesInvoices
627+
*
628+
* @return mixed the response body as parsed from json
629+
*/
630+
public function postInvoiceToSage( $sales_invoice ) {
631+
return $this->postData( '/sales_invoices', [ 'sales_invoice' => $sales_invoice ] )->getJSON();
632+
}
633+
629634
/**
630635
* Gets the paypal order prefix.
631636
*

0 commit comments

Comments
 (0)