public async Task <string> UploadBill(APIBill Bill, bool AutoBillCredit = true)
        {
            // in order this BILL to be refered as CREDIT, the total amount should be negative
            var isBillCredit = (Bill.Lines?.Sum(line => line.Amount) ?? 0) < 0;

            if (isBillCredit && AutoBillCredit)
            {
                return(await this.UploadBillCredit(Bill));
            }

            // fix negative amount

            /*
             * Bill.Lines?.ToList()?.ForEach(line => {
             *  line.Amount = Math.Abs(line.Amount);
             * });
             */

            var response = this.HttpService.POST <APIBill>($"{this.Config.BaseURL}company/{this.Config.CompanyId}/bill?minorversion=1", Bill, null, new Dictionary <string, string>
            {
                ["Accept"]        = "application/json",
                ["Content-Type"]  = "application/json",
                ["Authorization"] = $"Bearer {this.Config.AccessToken}"
            });

            // Unauthorized (401) - refresh token and try again
            if (!response.Success && response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                await this.RefreshToken();

                response = this.HttpService.POST <APIBill>($"{this.Config.BaseURL}company/{this.Config.CompanyId}/bill?minorversion=1", Bill, null, new Dictionary <string, string>
                {
                    ["Accept"]        = "application/json",
                    ["Content-Type"]  = "application/json",
                    ["Authorization"] = $"Bearer {this.Config.AccessToken}"
                });
            }

            if (!response.Success)
            {
                throw new APIException(this.ParseError(response.Content));
            }

            var modelSchema = new
            {
                Bill = new
                {
                    Id = string.Empty
                }
            };

            var responseData = JsonConvert.DeserializeAnonymousType(response.Content, modelSchema);

            return(responseData?.Bill?.Id);
        }
        public async Task <string> UploadBillCredit(APIBill Bill)
        {
            // fix negative amount - this is a CREDIT command - its negative by definition
            Bill.Lines?.ToList()?.ForEach(line => {
                line.Amount = Math.Abs(line.Amount);
            });

            var response = this.HttpService.POST <APIBill>($"{this.Config.BaseURL}company/{this.Config.CompanyId}/vendorcredit", Bill, null, new Dictionary <string, string>
            {
                ["Accept"]        = "application/json",
                ["Content-Type"]  = "application/json",
                ["Authorization"] = $"Bearer {this.Config.AccessToken}"
            });

            // Unauthorized (401) - refresh token and try again
            if (!response.Success && response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                await this.RefreshToken();

                response = this.HttpService.POST <APIBill>($"{this.Config.BaseURL}company/{this.Config.CompanyId}/vendorcredit", Bill, null, new Dictionary <string, string>
                {
                    ["Accept"]        = "application/json",
                    ["Content-Type"]  = "application/json",
                    ["Authorization"] = $"Bearer {this.Config.AccessToken}"
                });
            }

            if (!response.Success)
            {
                throw new APIException(this.ParseError(response.Content));
            }

            var modelSchema = new
            {
                VendorCredit = new
                {
                    Id = string.Empty
                }
            };

            var responseData = JsonConvert.DeserializeAnonymousType(response.Content, modelSchema);

            return(responseData?.VendorCredit?.Id);
        }