billecta 1.14.0

Generated Billecta API
Documentation
//! # Self invoice
//!
//! Self invoices are supplier invoices that you create for you supplier to yourself. That is,
//! you are invoicing yourself on behalf of your supplier. Self invoices are widely used when
//! invoice for your customer on their behalf (where payment is made to your account) to their
//! customer. To automatize the payment flow you need to further promote the payment from your
//! account to you customer. In a sence a supplier invoice to you that you create yourself.
//!
use crate::{
    CommentAction, CommonActionEvents, Created, Date, DeliveryMethodType, EmptyResponse, Request,
    RequestBuilder, SelfInvoiceAction, SelfInvoiceActionEntry, SelfInvoiceActionSub,
    SelfInvoicePayment, Uuid,
};

///Returns a self invoice based on the ActionPublicId. All self invoices
///have a unique ActionPublicId that is generated on creation.
pub fn get_a_self_invoice(id: &str) -> Request<SelfInvoiceAction> {
    RequestBuilder::new(http::Method::GET, "/v1/selfinvoice/action/")
        .path_param(id)
        .build()
}
///Note that only non-attested self invoices can be updated. Once
///attested it is locked and update is not possible any more.
pub fn update_a_self_invoice(id: &str, body: &SelfInvoiceActionEntry) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::PUT, "/v1/selfinvoice/action/")
        .path_param(id)
        .body(body)
        .build()
}
///All created self invoices are saved as drafts. To make it permanent
///and bookkeep it, the self invoice action must be attested. See the
///Attest endpoint. BankgiroNo property is one of the approved bankgiro
///numbers in Creditor.CreditorBankInfo.CreditorOutgoingBankgiroes.
///Bankgiro numbers are approved by Billecta customer service after a
///security review.
pub fn create_a_self_invoice(body: &SelfInvoiceActionEntry) -> Request<Created> {
    RequestBuilder::new(http::Method::POST, "/v1/selfinvoice/action")
        .body(body)
        .build()
}
///Only non-attested self invoices can be deleted. Once attested it is
///locked and deletion is not allowed any more.
pub fn delete_a_self_invoice(id: &str) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::DELETE, "/v1/selfinvoice/action/")
        .path_param(id)
        .build()
}
///Returns self invoice(s) based on the external id. Self invoices can
///have an external id that is for instance generated in another system
///and later set in Billecta.
pub fn get_self_invoice_s_by_external_id(
    id: Uuid,
    externalid: &str,
) -> Request<Vec<SelfInvoiceAction>> {
    RequestBuilder::new(http::Method::GET, "/v1/selfinvoice/actionsbyexternalid/")
        .path_param(id)
        .query_param("externalid", externalid)
        .build()
}
///Attesting a self invoice means that is will be book kept and locked
///for editing. Invoice is automatically sent if any distribution is set.
pub fn attest_a_self_invoice(id: &str) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::PUT, "/v1/selfinvoice/attest/")
        .path_param(id)
        .build()
}
///Cancels a self invoice and 'reverts' the bookkeeping.
pub fn cancel_a_self_invoice(id: &str) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::PUT, "/v1/selfinvoice/cancel/")
        .path_param(id)
        .build()
}
///Retrieves all self invoices that have a closed/full payment date
///between the specified from and to dates
pub fn get_all_closed_self_invoices(
    id: Uuid,
    from: Date,
    to: Date,
    offset: Option<i32>,
    limit: Option<i32>,
    sortingfield: Option<&str>,
    asc: Option<bool>,
) -> Request<Vec<SelfInvoiceActionSub>> {
    RequestBuilder::new(http::Method::GET, "/v1/selfinvoice/closed/")
        .path_param(id)
        .query_param("from", from)
        .query_param("to", to)
        .query_param_opt("offset", offset)
        .query_param_opt("limit", limit)
        .query_param_opt("sortingfield", sortingfield)
        .query_param_opt("asc", asc)
        .build()
}
///Writes a comment to the self invoice events log.
pub fn comment_a_self_invoice(body: &CommentAction) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::POST, "/v1/selfinvoice/comment")
        .body(body)
        .build()
}
pub fn get_all_events_for_all_self_invoices(
    id: Uuid,
    from: Date,
    to: Date,
) -> Request<CommonActionEvents> {
    RequestBuilder::new(http::Method::GET, "/v1/selfinvoice/events/")
        .path_param(id)
        .query_param("from", from)
        .query_param("to", to)
        .build()
}
///Self invoice events gets archived after one year. This reloads
///archived events to enable the events to be retrieved again. Observe
///that these events will be archived again after one day.
pub fn load_archived_events(id: &str) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::PUT, "/v1/selfinvoice/loadarchivedevents/")
        .path_param(id)
        .build()
}
///Retrieves all drafts/attested and unpaid self invoices.
pub fn get_all_open_self_invoices(
    id: Uuid,
    offset: Option<i32>,
    limit: Option<i32>,
    sortingfield: Option<&str>,
    asc: Option<bool>,
) -> Request<Vec<SelfInvoiceActionSub>> {
    RequestBuilder::new(http::Method::GET, "/v1/selfinvoice/open/")
        .path_param(id)
        .query_param_opt("offset", offset)
        .query_param_opt("limit", limit)
        .query_param_opt("sortingfield", sortingfield)
        .query_param_opt("asc", asc)
        .build()
}
///Pauses the self invoice from any more automatic events.
pub fn pause_a_self_invoice(id: &str) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::PUT, "/v1/selfinvoice/pause/")
        .path_param(id)
        .build()
}
///Preview a self invoice to view how it will be generated. This endpoint
///previews data already stored in API/database. This endpoint returns a
///PDF data stream in the content
pub fn preview_a_self_invoice(id: &str) -> Request<Vec<u8>> {
    RequestBuilder::new(http::Method::GET, "/v1/selfinvoice/preview/")
        .path_param(id)
        .build()
}
///Preview a self invoice to view how it will be generated. This endpoint
///previews data sent in the request and ignores data stored in the API/
///database. This endpoint returns a PDF data stream in the content
pub fn preview_a_self_invoice_post(body: &SelfInvoiceActionEntry) -> Request<Vec<u8>> {
    RequestBuilder::new(http::Method::POST, "/v1/selfinvoice/preview")
        .body(body)
        .build()
}
///Resumes the self invoice to automatically process events.
pub fn resume_a_self_invoice(id: &str) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::PUT, "/v1/selfinvoice/resume/")
        .path_param(id)
        .build()
}
///Sends the invoice by email
pub fn send_invoice_for_a_self_invoice(
    id: &str,
    method: &DeliveryMethodType,
) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::PUT, "/v1/selfinvoice/sendinvoice/")
        .path_param(id)
        .query_param("method", *method)
        .build()
}
///Triggers a payment from specified bankgiro number on the self invoice.
///Amount and date is set in the request.
pub fn send_payment_for_a_self_invoice(body: &SelfInvoicePayment) -> Request<EmptyResponse> {
    RequestBuilder::new(http::Method::PUT, "/v1/selfinvoice/sendpayment")
        .body(body)
        .build()
}