paid invoices support
This commit is contained in:
@@ -10,79 +10,84 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace CebelcaAPI
|
namespace CebelcaAPI
|
||||||
{
|
{
|
||||||
public class CebelcaPartner
|
public class CebelcaPartner
|
||||||
|
{
|
||||||
|
public string Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
public class CebelcaAPISharp
|
||||||
|
{
|
||||||
|
private string _key = "";
|
||||||
|
public CebelcaAPISharp(string key)
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
_key = key;
|
||||||
public string Name { get; set; }
|
|
||||||
}
|
}
|
||||||
public class CebelcaAPISharp
|
private async Task<string> APICall(string region, string method, Dictionary<string, string> postvalues)
|
||||||
{
|
{
|
||||||
private string _key = "";
|
using (var client = new HttpClient())
|
||||||
public CebelcaAPISharp(string key)
|
{
|
||||||
{
|
var byteArray = Encoding.ASCII.GetBytes($"{_key}:x");
|
||||||
_key = key;
|
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
|
||||||
}
|
// var url = "https://www.cebelca.biz/API?_r=invoice-sent&_m=insert-into";
|
||||||
private async Task<string> APICall(string region, string method, Dictionary<string, string> postvalues)
|
var url = $"https://www.cebelca.biz/API?_r={region}&_m={method}";
|
||||||
{
|
var content = new FormUrlEncodedContent(postvalues);
|
||||||
using (var client = new HttpClient())
|
var response = await client.PostAsync(url, content);
|
||||||
{
|
|
||||||
var byteArray = Encoding.ASCII.GetBytes($"{_key}:x");
|
|
||||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
|
|
||||||
// var url = "https://www.cebelca.biz/API?_r=invoice-sent&_m=insert-into";
|
|
||||||
var url = $"https://www.cebelca.biz/API?_r={region}&_m={method}";
|
|
||||||
var content = new FormUrlEncodedContent(postvalues);
|
|
||||||
var response = await client.PostAsync(url, content);
|
|
||||||
|
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
var responseString = await response.Content.ReadAsStringAsync();
|
||||||
return responseString;
|
return responseString;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> AddInvoiceHead(string partnerId, string idDocumentExt, DateTime dateSent, DateTime dateServed, DateTime dateToPay)
|
public async Task<string> AddInvoiceHead(string partnerId, string idDocumentExt, DateTime dateSent, DateTime dateServed, DateTime dateToPay, bool paid = false)
|
||||||
{
|
{
|
||||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "date_sent",dateSent.ToShortDateString() },
|
{ "date_sent",dateSent.ToShortDateString() },
|
||||||
{ "date_served",dateServed.ToShortDateString() },
|
{ "date_served",dateServed.ToShortDateString() },
|
||||||
{ "date_to_pay",dateToPay.ToShortDateString() },
|
{ "date_to_pay", dateToPay.ToShortDateString() },
|
||||||
{ "id_partner", partnerId },
|
{ "id_partner", partnerId },
|
||||||
{ "id_document_ext", idDocumentExt }
|
{ "id_document_ext", idDocumentExt }
|
||||||
};
|
};
|
||||||
var ret = await APICall("invoice-sent", "insert-smart-2", values);
|
if (paid)
|
||||||
var json = JArray.Parse(ret);
|
{
|
||||||
var retname = (json[0][0] as JObject).Properties().First().Name;
|
values.Add("payment", "paid");
|
||||||
if (retname != "id")
|
values.Add("payment_act", "1");
|
||||||
throw new Exception("Error from api: "+ret);
|
}
|
||||||
var id = json[0][0]["id"].Value<string>();
|
var ret = await APICall("invoice-sent", "insert-smart-2", values);
|
||||||
return id;
|
var json = JArray.Parse(ret);
|
||||||
|
var retname = (json[0][0] as JObject).Properties().First().Name;
|
||||||
|
if (retname != "id")
|
||||||
|
throw new Exception("Error from api: " + ret);
|
||||||
|
var id = json[0][0]["id"].Value<string>();
|
||||||
|
return id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<CebelcaPartner>> GetPartners()
|
public async Task<IEnumerable<CebelcaPartner>> GetPartners()
|
||||||
{
|
{
|
||||||
var values = new Dictionary<string, string>();
|
var values = new Dictionary<string, string>();
|
||||||
var ret = await APICall("partner", "select-all", values);
|
var ret = await APICall("partner", "select-all", values);
|
||||||
|
|
||||||
var json = JArray.Parse(ret);
|
|
||||||
var retname = (json[0][0] as JObject).Properties().First().Name;
|
|
||||||
if (retname != "id")
|
|
||||||
throw new Exception("Error from api: " + ret);
|
|
||||||
var id = json[0][0]["id"].Value<string>();
|
|
||||||
//var l = new List<CebelcaPartner>();
|
|
||||||
var l = json[0].Select(x => new CebelcaPartner
|
|
||||||
{
|
|
||||||
Id = x["id"].Value<string>(),
|
|
||||||
Name = x["name"].Value<string>()
|
|
||||||
}).ToList();
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendInvoiceByEmail(string invoiceId, string to, string subject, string content)
|
var json = JArray.Parse(ret);
|
||||||
{
|
var retname = (json[0][0] as JObject).Properties().First().Name;
|
||||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
if (retname != "id")
|
||||||
var values = new Dictionary<string, string>
|
throw new Exception("Error from api: " + ret);
|
||||||
|
var id = json[0][0]["id"].Value<string>();
|
||||||
|
//var l = new List<CebelcaPartner>();
|
||||||
|
var l = json[0].Select(x => new CebelcaPartner
|
||||||
|
{
|
||||||
|
Id = x["id"].Value<string>(),
|
||||||
|
Name = x["name"].Value<string>()
|
||||||
|
}).ToList();
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SendInvoiceByEmail(string invoiceId, string to, string subject, string content)
|
||||||
|
{
|
||||||
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
||||||
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "id_invoice_sent", invoiceId},
|
{ "id_invoice_sent", invoiceId},
|
||||||
{ "mto", to},
|
{ "mto", to},
|
||||||
@@ -93,16 +98,16 @@ namespace CebelcaAPI
|
|||||||
{ "content", content},
|
{ "content", content},
|
||||||
{ "format", "pdf"}
|
{ "format", "pdf"}
|
||||||
};
|
};
|
||||||
var ret = await APICall("mailer", "push-invoice-sent-doc", values);
|
var ret = await APICall("mailer", "push-invoice-sent-doc", values);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<string> AddInvoiceLine(string invoiceId,string title, string measuringUnit, string qty, decimal price, string vat, string discount)
|
public async Task<string> AddInvoiceLine(string invoiceId, string title, string measuringUnit, string qty, decimal price, string vat, string discount)
|
||||||
{
|
{
|
||||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "title",title },
|
{ "title",title },
|
||||||
{ "mu",measuringUnit },
|
{ "mu",measuringUnit },
|
||||||
@@ -111,62 +116,62 @@ namespace CebelcaAPI
|
|||||||
{ "price", price.ToString() },
|
{ "price", price.ToString() },
|
||||||
{ "vat", vat }
|
{ "vat", vat }
|
||||||
};
|
};
|
||||||
var ret = await APICall("invoice-sent-b", "insert-into", values);
|
var ret = await APICall("invoice-sent-b", "insert-into", values);
|
||||||
var json = JArray.Parse(ret);
|
var json = JArray.Parse(ret);
|
||||||
var retname = (json[0][0] as JObject).Properties().First().Name;
|
var retname = (json[0][0] as JObject).Properties().First().Name;
|
||||||
if (retname != "id")
|
if (retname != "id")
|
||||||
throw new Exception("Error from api: " + ret);
|
throw new Exception("Error from api: " + ret);
|
||||||
var id = json[0][0]["id"].Value<string>();
|
var id = json[0][0]["id"].Value<string>();
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> AddPayment(string invoiceId, DateTime dateOfPayment, decimal amount, string paymentMethod )
|
public async Task<string> AddPayment(string invoiceId, DateTime dateOfPayment, decimal amount, string paymentMethod)
|
||||||
{
|
{
|
||||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "date_of",dateOfPayment.ToShortDateString() },
|
{ "date_of",dateOfPayment.ToShortDateString() },
|
||||||
{ "amount",amount.ToString() },
|
{ "amount",amount.ToString() },
|
||||||
|
|
||||||
{ "id_invoice_sent", invoiceId },
|
{ "id_invoice_sent", invoiceId },
|
||||||
{ "id_payment_method", paymentMethod},
|
{ "id_payment_method", paymentMethod},
|
||||||
|
|
||||||
};
|
};
|
||||||
var ret = await APICall("invoice-sent-p", "insert-into", values);
|
var ret = await APICall("invoice-sent-p", "insert-into", values);
|
||||||
var json = JArray.Parse(ret);
|
var json = JArray.Parse(ret);
|
||||||
var retname = (json[0][0] as JObject).Properties().First().Name;
|
var retname = (json[0][0] as JObject).Properties().First().Name;
|
||||||
if (retname != "id")
|
if (retname != "id")
|
||||||
throw new Exception("Error from api: " + ret);
|
throw new Exception("Error from api: " + ret);
|
||||||
var id = json[0][0]["id"].Value<string>();
|
var id = json[0][0]["id"].Value<string>();
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> IssueInvoiceNoFiscalization(string invoiceId, string docType="0")
|
public async Task<string> IssueInvoiceNoFiscalization(string invoiceId, string docType = "0")
|
||||||
{
|
{
|
||||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
|
|
||||||
{ "id", invoiceId },
|
{ "id", invoiceId },
|
||||||
{ "doctype", docType},
|
{ "doctype", docType},
|
||||||
|
|
||||||
};
|
};
|
||||||
var ret = await APICall("invoice-sent", "finalize-invoice-2015", values);
|
var ret = await APICall("invoice-sent", "finalize-invoice-2015", values);
|
||||||
var json = JArray.Parse(ret);
|
var json = JArray.Parse(ret);
|
||||||
var retname = (json[0][0] as JObject).Properties().First().Name;
|
var retname = (json[0][0] as JObject).Properties().First().Name;
|
||||||
if (retname != "new_title")
|
if (retname != "new_title")
|
||||||
throw new Exception("Error from api: " + ret);
|
throw new Exception("Error from api: " + ret);
|
||||||
var id = json[0][0]["new_title"].Value<string>();
|
var id = json[0][0]["new_title"].Value<string>();
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> IssueInvoiceFiscalization(string invoiceId, string idLocation, string opTaxId, string opName, bool test_mode = false )
|
public async Task<string> IssueInvoiceFiscalization(string invoiceId, string idLocation, string opTaxId, string opName, bool test_mode = false)
|
||||||
{
|
{
|
||||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
Thread.CurrentThread.CurrentCulture = new CultureInfo("sl-SI");
|
||||||
var values = new Dictionary<string, string>
|
var values = new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
|
|
||||||
{ "id", invoiceId },
|
{ "id", invoiceId },
|
||||||
@@ -177,16 +182,16 @@ namespace CebelcaAPI
|
|||||||
{ "test_mode", test_mode ? "1" : "0" },
|
{ "test_mode", test_mode ? "1" : "0" },
|
||||||
|
|
||||||
};
|
};
|
||||||
var ret = await APICall("invoice-sent", "finalize-invoice", values);
|
var ret = await APICall("invoice-sent", "finalize-invoice", values);
|
||||||
var json = JArray.Parse(ret);
|
var json = JArray.Parse(ret);
|
||||||
var retname = (json[0][0] as JObject).Properties().First().Name;
|
var retname = (json[0][0] as JObject).Properties().First().Name;
|
||||||
if (retname != "docnum")
|
if (retname != "docnum")
|
||||||
throw new Exception("Error from api: " + ret);
|
throw new Exception("Error from api: " + ret);
|
||||||
var id = json[0][0]["docnum"].Value<string>();
|
var id = json[0][0]["docnum"].Value<string>();
|
||||||
var eor = json[0][0]["eor"].Value<string>();
|
var eor = json[0][0]["eor"].Value<string>();
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user