using IdokladSdk.Models.CreditNote; using IdokladSdk.Models.IssuedDocumentTemplate.Patch; using IdokladSdk.Models.IssuedDocumentTemplate.Post; using IdokladSdk.Models.IssuedTaxDocument.Patch; using IdokladSdk.Models.IssuedTaxDocument.Post; using IdokladSdk.Models.ProformaInvoice; using IdokladSdk.Models.RecurringInvoice; using IdokladSdk.Models.SalesOrder; using IdokladSdk.Models.SalesReceipt; using Microsoft.AspNetCore.Mvc; using Idoklad.Services; namespace Idoklad.Controllers; /// /// Sales-side documents. Requires iDoklad credentials (headers or environment defaults). /// [ApiController] [Produces("application/json")] [Tags("SalesDocuments")] public sealed class SalesDocumentsController : ControllerBase { private readonly SalesDocumentsService _service; public SalesDocumentsController(SalesDocumentsService service) => _service = service; // ---- Proforma invoices ---- /// List proforma invoices (paged). [HttpGet("proforma-invoices")] public async Task ListProforma(int page = 1, int pageSize = 20, CancellationToken ct = default) => Ok(await _service.ListProformaAsync(page, pageSize, ct)); /// Get a pre-filled default model for creating a new proforma invoice. [HttpGet("proforma-invoices/default")] public async Task ProformaDefault(CancellationToken ct) => Ok(await _service.ProformaDefaultAsync(ct)); /// Get a proforma invoice detail by id. [HttpGet("proforma-invoices/{id:int}")] public async Task ProformaDetail(int id, CancellationToken ct) => Ok(await _service.ProformaDetailAsync(id, ct)); /// Create a new proforma invoice. [HttpPost("proforma-invoices")] public async Task CreateProforma([FromBody] ProformaInvoicePostModel model, CancellationToken ct) => Ok(await _service.CreateProformaAsync(model, ct)); /// Update an existing proforma invoice (the model id identifies the document). [HttpPatch("proforma-invoices")] public async Task UpdateProforma([FromBody] ProformaInvoicePatchModel model, CancellationToken ct) => Ok(await _service.UpdateProformaAsync(model, ct)); /// Create a copy (draft) of an existing proforma invoice. [HttpPost("proforma-invoices/{id:int}/copy")] public async Task CopyProforma(int id, CancellationToken ct) => Ok(await _service.ProformaCopyAsync(id, ct)); /// Delete a proforma invoice by id. [HttpDelete("proforma-invoices/{id:int}")] public async Task DeleteProforma(int id, CancellationToken ct) => Ok(await _service.DeleteProformaAsync(id, ct)); // ---- Credit notes ---- /// List credit notes (paged). [HttpGet("credit-notes")] public async Task ListCreditNotes(int page = 1, int pageSize = 20, CancellationToken ct = default) => Ok(await _service.ListCreditNotesAsync(page, pageSize, ct)); /// Get a pre-filled default credit note model for the given (issued) invoice id. [HttpGet("credit-notes/default/{invoiceId:int}")] public async Task CreditNoteDefault(int invoiceId, CancellationToken ct) => Ok(await _service.CreditNoteDefaultAsync(invoiceId, ct)); /// Get a credit note detail by id. [HttpGet("credit-notes/{id:int}")] public async Task CreditNoteDetail(int id, CancellationToken ct) => Ok(await _service.CreditNoteDetailAsync(id, ct)); /// Create a new credit note. [HttpPost("credit-notes")] public async Task CreateCreditNote([FromBody] CreditNotePostModel model, CancellationToken ct) => Ok(await _service.CreateCreditNoteAsync(model, ct)); /// Update an existing credit note (the model id identifies the document). [HttpPatch("credit-notes")] public async Task UpdateCreditNote([FromBody] CreditNotePatchModel model, CancellationToken ct) => Ok(await _service.UpdateCreditNoteAsync(model, ct)); /// Delete a credit note by id. [HttpDelete("credit-notes/{id:int}")] public async Task DeleteCreditNote(int id, CancellationToken ct) => Ok(await _service.DeleteCreditNoteAsync(id, ct)); // ---- Sales receipts ---- /// List sales receipts (paged). [HttpGet("sales-receipts")] public async Task ListSalesReceipts(int page = 1, int pageSize = 20, CancellationToken ct = default) => Ok(await _service.ListSalesReceiptsAsync(page, pageSize, ct)); /// Get a pre-filled default model for creating a new sales receipt. [HttpGet("sales-receipts/default")] public async Task SalesReceiptDefault(CancellationToken ct) => Ok(await _service.SalesReceiptDefaultAsync(ct)); /// Get a sales receipt detail by id. [HttpGet("sales-receipts/{id:int}")] public async Task SalesReceiptDetail(int id, CancellationToken ct) => Ok(await _service.SalesReceiptDetailAsync(id, ct)); /// Create a new sales receipt. [HttpPost("sales-receipts")] public async Task CreateSalesReceipt([FromBody] SalesReceiptPostModel model, CancellationToken ct) => Ok(await _service.CreateSalesReceiptAsync(model, ct)); /// Update an existing sales receipt (the model id identifies the document). [HttpPatch("sales-receipts")] public async Task UpdateSalesReceipt([FromBody] SalesReceiptPatchModel model, CancellationToken ct) => Ok(await _service.UpdateSalesReceiptAsync(model, ct)); /// Create a copy (draft) of an existing sales receipt. [HttpPost("sales-receipts/{id:int}/copy")] public async Task CopySalesReceipt(int id, CancellationToken ct) => Ok(await _service.SalesReceiptCopyAsync(id, ct)); /// Delete a sales receipt by id. [HttpDelete("sales-receipts/{id:int}")] public async Task DeleteSalesReceipt(int id, CancellationToken ct) => Ok(await _service.DeleteSalesReceiptAsync(id, ct)); // ---- Sales orders ---- /// List sales orders (paged). [HttpGet("sales-orders")] public async Task ListSalesOrders(int page = 1, int pageSize = 20, CancellationToken ct = default) => Ok(await _service.ListSalesOrdersAsync(page, pageSize, ct)); /// Get a pre-filled default model for creating a new sales order. [HttpGet("sales-orders/default")] public async Task SalesOrderDefault(CancellationToken ct) => Ok(await _service.SalesOrderDefaultAsync(ct)); /// Get a sales order detail by id. [HttpGet("sales-orders/{id:int}")] public async Task SalesOrderDetail(int id, CancellationToken ct) => Ok(await _service.SalesOrderDetailAsync(id, ct)); /// Create a new sales order. [HttpPost("sales-orders")] public async Task CreateSalesOrder([FromBody] SalesOrderPostModel model, CancellationToken ct) => Ok(await _service.CreateSalesOrderAsync(model, ct)); /// Update an existing sales order (the model id identifies the document). [HttpPatch("sales-orders")] public async Task UpdateSalesOrder([FromBody] SalesOrderPatchModel model, CancellationToken ct) => Ok(await _service.UpdateSalesOrderAsync(model, ct)); /// Create a copy (draft) of an existing sales order. [HttpPost("sales-orders/{id:int}/copy")] public async Task CopySalesOrder(int id, CancellationToken ct) => Ok(await _service.SalesOrderCopyAsync(id, ct)); /// Delete a sales order by id. [HttpDelete("sales-orders/{id:int}")] public async Task DeleteSalesOrder(int id, CancellationToken ct) => Ok(await _service.DeleteSalesOrderAsync(id, ct)); // ---- Recurring invoices ---- /// List recurring invoices (paged). [HttpGet("recurring-invoices")] public async Task ListRecurring(int page = 1, int pageSize = 20, CancellationToken ct = default) => Ok(await _service.ListRecurringAsync(page, pageSize, ct)); /// Get a pre-filled default model for creating a new recurring invoice. [HttpGet("recurring-invoices/default")] public async Task RecurringDefault(CancellationToken ct) => Ok(await _service.RecurringDefaultAsync(ct)); /// Get a recurring invoice detail by id. [HttpGet("recurring-invoices/{id:int}")] public async Task RecurringDetail(int id, CancellationToken ct) => Ok(await _service.RecurringDetailAsync(id, ct)); /// Create a new recurring invoice template. [HttpPost("recurring-invoices")] public async Task CreateRecurring([FromBody] RecurringInvoicePostModel model, CancellationToken ct) => Ok(await _service.CreateRecurringAsync(model, ct)); /// Update an existing recurring invoice (the model id identifies the template). [HttpPatch("recurring-invoices")] public async Task UpdateRecurring([FromBody] RecurringInvoicePatchModel model, CancellationToken ct) => Ok(await _service.UpdateRecurringAsync(model, ct)); /// Create a copy (draft) of an existing recurring invoice. [HttpPost("recurring-invoices/{id:int}/copy")] public async Task CopyRecurring(int id, CancellationToken ct) => Ok(await _service.RecurringCopyAsync(id, ct)); /// Delete a recurring invoice by id. [HttpDelete("recurring-invoices/{id:int}")] public async Task DeleteRecurring(int id, CancellationToken ct) => Ok(await _service.DeleteRecurringAsync(id, ct)); // ---- Issued tax documents ---- /// List issued tax documents (paged). [HttpGet("issued-tax-documents")] public async Task ListTaxDocuments(int page = 1, int pageSize = 20, CancellationToken ct = default) => Ok(await _service.ListTaxDocumentsAsync(page, pageSize, ct)); /// Get a pre-filled default tax document model for the given advance (proforma) invoice id. [HttpGet("issued-tax-documents/default/{advanceInvoiceId:int}")] public async Task TaxDocumentDefault(int advanceInvoiceId, CancellationToken ct) => Ok(await _service.TaxDocumentDefaultAsync(advanceInvoiceId, ct)); /// Get an issued tax document detail by id. [HttpGet("issued-tax-documents/{id:int}")] public async Task TaxDocumentDetail(int id, CancellationToken ct) => Ok(await _service.TaxDocumentDetailAsync(id, ct)); /// Create a new issued tax document. [HttpPost("issued-tax-documents")] public async Task CreateTaxDocument([FromBody] IssuedTaxDocumentPostModel model, CancellationToken ct) => Ok(await _service.CreateTaxDocumentAsync(model, ct)); /// Update an existing issued tax document (the model id identifies the document). [HttpPatch("issued-tax-documents")] public async Task UpdateTaxDocument([FromBody] IssuedTaxDocumentPatchModel model, CancellationToken ct) => Ok(await _service.UpdateTaxDocumentAsync(model, ct)); /// Delete an issued tax document by id. [HttpDelete("issued-tax-documents/{id:int}")] public async Task DeleteTaxDocument(int id, CancellationToken ct) => Ok(await _service.DeleteTaxDocumentAsync(id, ct)); // ---- Issued document templates ---- /// List issued document templates (paged). [HttpGet("issued-document-templates")] public async Task ListTemplates(int page = 1, int pageSize = 20, CancellationToken ct = default) => Ok(await _service.ListTemplatesAsync(page, pageSize, ct)); /// Get a pre-filled default model for creating a new issued document template. [HttpGet("issued-document-templates/default")] public async Task TemplateDefault(CancellationToken ct) => Ok(await _service.TemplateDefaultAsync(ct)); /// Get an issued document template detail by id. [HttpGet("issued-document-templates/{id:int}")] public async Task TemplateDetail(int id, CancellationToken ct) => Ok(await _service.TemplateDetailAsync(id, ct)); /// Create a new issued document template. [HttpPost("issued-document-templates")] public async Task CreateTemplate([FromBody] IssuedDocumentTemplatePostModel model, CancellationToken ct) => Ok(await _service.CreateTemplateAsync(model, ct)); /// Update an existing issued document template (the model id identifies the template). [HttpPatch("issued-document-templates")] public async Task UpdateTemplate([FromBody] IssuedDocumentTemplatePatchModel model, CancellationToken ct) => Ok(await _service.UpdateTemplateAsync(model, ct)); /// Delete an issued document template by id. [HttpDelete("issued-document-templates/{id:int}")] public async Task DeleteTemplate(int id, CancellationToken ct) => Ok(await _service.DeleteTemplateAsync(id, ct)); }