×

Payables/Receivables invoices

In the following you will find a few basic POST operations related to invoices.
 
Example Code
 
POST a payable invoice
POST a payable invoice with Topal. A POST request is also used for updating an existing invoice.
 
External references to methods used in examples
#Code reference - GET.party_by_name
#Code reference - GET.party_by_id
#Code reference - Create.payables_invoice
#Code reference - DELETE.payables_invoice
#Code reference - GET.payables_invoice_by_freeinvoicenum
    
    [TestMethod]
    public void REST_Payables_invoice_POST()
        {
        state = new ErrorState { passed = false };
        decimal payment_amount = 4000m;

        Party party = GET.party_by_name("Tamedia AG", manager);
        party = GET.party_by_id(party.id, manager);

        List postings = new List();
        postings.Add(payment_amount);

        Invoice_TO invoice_DTO = new Invoice_TO
        {
            party = party,
            manager = manager,
            date = DateTime.Today,
            posting_amounts = postings,
            payment_amount = payment_amount,

            free_inv_num = "",
            vat_code = "",
            hasDocument = 0,
            isDebit = true,
            text = ""
        };

        Invoice invoice = Create.payables_invoice(invoice_DTO);
        state.passed = POST.payables_invoice(invoice, manager);
        Assert.AreEqual(true, state.passed, state.message);

        invoice = GET.payables_invoice_by_freeinvoicenum(invoice.freeInvoiceNum, manager);

        if (invoice != null) {
            state.passed = DELETE.payables_invoice(invoice, manager);
            Assert.AreEqual(true, state.passed, state.message);
        }
    }

    class POST
    {
        public static bool payables_invoice(Invoice invoice, Manager manager)
        {
            ErrorState state = new ErrorState { passed = false };

            if (invoice != null)  {
                var invoiceContent = JsonConvert.SerializeObject(invoice);
                var content = new StringContent(invoiceContent, Encoding.UTF8, "application/json");

                string request = "clients/{0}/fiscalYears/{1}/payables/invoices";
                var response = manager.httpClient.PostAsync(string.Format(request, manager.getCurrentClient().id, manager.getCurrentFiscalYear().id), content).Result;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ResponseDetails details = new ResponseDetails(response);
                }
                state.passed = response.IsSuccessStatusCode;
            }
            return state.passed;
        }
    }
    
  
Save Payable invoice
    
class Save:
    # TODO Recheck
    @staticmethod
    def invoicePayables(manager, invoice):
        
        _currentClient = manager.getCurrentClient()
        _currentFiscalYear = manager.getCurrentFiscalYear()
        
        try:
            url = '{0}clients/{1}/fiscalYears/{2}/payables/invoices'.format(manager.baseURL(), _currentClient['id'], _currentFiscalYear['id'])
            response = requests.post(url, data = json.dumps(invoice), headers = manager.headers())
        
        except Exception as err:
                print("Error: {0}".format(err))
                print(response.headers)
                response.raise_for_status()

        if response.status_code == 200:
            return response.json()
        else: 
           return None
    
  
Save Payable invoice
    
    UNDER CONSTRUCTION
    
  
JSON representation of a payable invoice
    
    not available
    
  
 
POST a receivable invoice
POST a receivable invoice with Topal. A POST request is also used for updating an existing invoice.
 
External references to methods used in examples
#Code reference - GET.party_by_name
#Code reference - GET.party_by_id
#Code reference - Create.receivables_invoice
#Code reference - DELETE.receivables_invoice
#Code reference - GET.receivables_invoice_by_freeinvoicenum
    
   [TestMethod]
   public void REST_Receivables_invoice_POST()
   {
        state = new ErrorState { passed = false };
        decimal payment_amount = 1000.0m;

        Party party = GET.party_by_name("Bucherer AG", manager);
        party = GET.party_by_id(party.id, manager);

        List postings = new List();
        postings.Add(payment_amount);

        Invoice_TO invoice_to = new Invoice_TO
        {
            party = party,
            manager = manager,
            date = DateTime.Today,
            posting_amounts = postings,
            payment_amount = payment_amount,

            exchange_rate = 1,
            text = "New Recivables Invoice",
            free_inv_num = "receivable_1000",
            pay_method = "Method_1",
            contra_account = "3200",
            invoiceType = Convert.ToBoolean(InvoiceType.INCLUSIVE)
        };

        Invoice invoice = Create.receivables_invoice(invoice_to);
        state.passed = POST.receivables_invoice(invoice, manager);
        Assert.AreEqual(true, state.passed, state.message);
   
        invoice = GET.receivables_invoice_by_freeinvoicenum(invoice_to.free_inv_num, manager);

        if (invoice != null)
        {
            state.passed = DELETE.receivables_invoice(invoice, manager);
            Assert.AreEqual(true, state.passed, state.message);
        }
    }

    class POST
    {
        public static bool receivables_invoice(Invoice invoice, Manager manager)
        {
            ErrorState state = new ErrorState { passed = false };

            if (invoice != null)  {
                var invoiceContent = JsonConvert.SerializeObject(invoice);
                var content = new StringContent(invoiceContent, Encoding.UTF8, "application/json");

                string request = "clients/{0}/fiscalYears/{1}/receivables/invoices";
                var response = manager.httpClient.PostAsync(string.Format(request, manager.getCurrentClient().id, manager.getCurrentFiscalYear().id), content).Result;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ResponseDetails details = new ResponseDetails(response);
                }
                state.passed = response.IsSuccessStatusCode;
            }
            return state.passed;
        }
    }
    
  
    
class Save:
    # TODO Recheck
    @staticmethod
    def invoiceReceivables(manager, invoice):
        
        _currentClient = manager.getCurrentClient()
        _currentFiscalYear = manager.getCurrentFiscalYear()
        
        try:
            url = '{0}clients/{1}/fiscalYears/{2}/receivables/invoices'.format(manager.baseURL(), _currentClient['id'], _currentFiscalYear['id'])
            response = requests.post(url, data = json.dumps(invoice), headers = manager.headers())
        
        except Exception as err:
                print("Error: {0}".format(err))
                print(response.headers)
                response.raise_for_status()

        if response.status_code == 200:
            return response.json()
        else: 
           return None
    
  
    
    not available