<commit_before><?php

namespace Moneybird\Resource;

use Moneybird\Exception;
use Moneybird\Object\BaseObject;
use Moneybird\Object\Contact;
use Moneybird\Object\Payment;
use Moneybird\Object\SalesInvoice;

/**
 * Class SalesInvoices
 *
 * @package Moneybird\Resource
 * @method SalesInvoice create($data = NULL, array $filters = [])
 */
class SalesInvoices extends ResourceBase {

    /**
     * @var string
     * @example 2017-02-22
     */
    private $scheduleDate;

    private $emailMessage;

    /**
     * @var Contact
     */
    private $contact;

    /**
     * @var Payment
     */
    private $payment;

    /**
     * @var SalesInvoice
     */
    private $invoice;

    /**
     * @return SalesInvoice
     */
    protected function getResourceObject() {
        return new SalesInvoice;
    }

    /**
     * Set the contact to send the invoice to
     *
     * @param Contact $contact
     *
     * @return $this
     */
    public function setContact(Contact $contact) {
        $this->contact = $contact;

        return $this;
    }

    /**
     * Set a payment for the invoice
     *
     * @param Payment $payment
     *
     * @return $this
     */
    public function setPayment(Payment $payment) {
        $this->payment = $payment;

        return $this;
    }

    /**
     * Set the sales invoice to send
     *
     * @param SalesInvoice $invoice
     *
     * @return $this
     */
    public function setInvoice(SalesInvoice $invoice) {
        $this->invoice = $invoice;

        return $this;
    }

    public function setScheduleDate($scheduleDate) {
        $this->scheduleDate = $scheduleDate;
    }

    public function setMessage($message) {
        $this->emailMessage = $message;
    }

    /**
     * Send a invoice to the contact
     *
     * @param SalesInvoice|string $invoice
     *
     * @return bool|object
     * @throws Exception
     */
    public function send($invoice = NULL) {
        if (empty($invoice) && empty($this->invoice)) {
            throw new Exception("No valid sales invoice given!");
        }

        $this->with(empty($invoice) ? $this->invoice : $invoice);

        $body = [];
        if (!empty($this->contact)) {
            if (empty($this->contact->email))
                throw new Exception("Contact has no email address!");

            if (empty($this->contact->delivery_method))
                throw new Exception("Contact has no delivery method!");

            $body[ "email_address" ]   = $this->contact->email;
            $body[ "delivery_method" ] = $this->contact->delivery_method;
        }

        if (!empty($this->scheduleDate)) {
            $body[ "sending_scheduled" ] = TRUE;
            $body[ "invoice_date" ]      = $this->scheduleDate;
        }

        if (!empty($this->emailMessage)) {
            $body[ "email_message" ] = $this->emailMessage;
        }

        return $this->restUpdate($this->getResourcePath(), "send_invoice", [ "sales_invoice_sending" => $body ]);
    }

    /**
     * Registers a payment
     *
     * @param SalesInvoice|string $invoice
     *
     * @return bool|object
     * @throws Exception
     */
    public function registerPayment($invoice = NULL) {
        if (empty($invoice) && empty($this->invoice)) {
            throw new Exception("No valid sales invoice given!");
        }

        $this->with(empty($invoice) ? $this->invoice : $invoice);

        if (empty($this->payment)) {
            throw new Exception("No valid payment given!");
        }

        return $this->restUpdate($this->getResourcePath(), "register_payment", [ $this->payment->getKey() => $this->payment->toArray() ]);
    }

}<commit_msg>fix(SalesInvoices): Fixed that a empty body was send<commit_after><?php

namespace Moneybird\Resource;

use Moneybird\Exception;
use Moneybird\Object\BaseObject;
use Moneybird\Object\Contact;
use Moneybird\Object\Payment;
use Moneybird\Object\SalesInvoice;

/**
 * Class SalesInvoices
 *
 * @package Moneybird\Resource
 * @method SalesInvoice create($data = NULL, array $filters = [])
 */
class SalesInvoices extends ResourceBase {

    /**
     * @var string
     * @example 2017-02-22
     */
    private $scheduleDate;

    private $emailMessage;

    /**
     * @var Contact
     */
    private $contact;

    /**
     * @var Payment
     */
    private $payment;

    /**
     * @var SalesInvoice
     */
    private $invoice;

    /**
     * @return SalesInvoice
     */
    protected function getResourceObject() {
        return new SalesInvoice;
    }

    /**
     * Set the contact to send the invoice to
     *
     * @param Contact $contact
     *
     * @return $this
     */
    public function setContact(Contact $contact) {
        $this->contact = $contact;

        return $this;
    }

    /**
     * Set a payment for the invoice
     *
     * @param Payment $payment
     *
     * @return $this
     */
    public function setPayment(Payment $payment) {
        $this->payment = $payment;

        return $this;
    }

    /**
     * Set the sales invoice to send
     *
     * @param SalesInvoice $invoice
     *
     * @return $this
     */
    public function setInvoice(SalesInvoice $invoice) {
        $this->invoice = $invoice;

        return $this;
    }

    public function setScheduleDate($scheduleDate) {
        $this->scheduleDate = $scheduleDate;
    }

    public function setMessage($message) {
        $this->emailMessage = $message;
    }

    /**
     * Send a invoice to the contact
     *
     * @param SalesInvoice|string $invoice
     *
     * @return bool|object
     * @throws Exception
     */
    public function send($invoice = NULL) {
        if (empty($invoice) && empty($this->invoice)) {
            throw new Exception("No valid sales invoice given!");
        }

        $this->with(empty($invoice) ? $this->invoice : $invoice);

        $body = [];
        if (!empty($this->contact)) {
            if (empty($this->contact->email)) {
                throw new Exception("Contact has no email address!");
            }

            if (empty($this->contact->delivery_method)) {
                throw new Exception("Contact has no delivery method!");
            }

            $body[ "email_address" ]   = $this->contact->email;
            $body[ "delivery_method" ] = $this->contact->delivery_method;
        }

        if (!empty($this->scheduleDate)) {
            $body[ "sending_scheduled" ] = TRUE;
            $body[ "invoice_date" ]      = $this->scheduleDate;
        }

        if (!empty($this->emailMessage)) {
            $body[ "email_message" ] = $this->emailMessage;
        }

        if (count($body) > 0) {
            $body = [ "sales_invoice_sending" => $body ];

        } else {
            $body = NULL;
        }

        return $this->restUpdate($this->getResourcePath(), "send_invoice", $body);
    }

    /**
     * Registers a payment
     *
     * @param SalesInvoice|string $invoice
     *
     * @return bool|object
     * @throws Exception
     */
    public function registerPayment($invoice = NULL) {
        if (empty($invoice) && empty($this->invoice)) {
            throw new Exception("No valid sales invoice given!");
        }

        $this->with(empty($invoice) ? $this->invoice : $invoice);

        if (empty($this->payment)) {
            throw new Exception("No valid payment given!");
        }

        return $this->restUpdate($this->getResourcePath(), "register_payment", [ $this->payment->getKey() => $this->payment->toArray() ]);
    }

}
{'fraction_non_alphanumeric': 0.1370592149035263, 'fraction_numerical': 0.002262142381902861, 'mean_word_length': 2.079065956575174, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 74, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1355500', 'n_tokens_mistral': 2233, 'n_tokens_neox': 2144, 'n_words': 493}