/// <summary> /// Create simplified invoice /// </summary> /// <param name="client">Client identification</param> /// <param name="invoice">Purchase information</param> /// <param name="isToClose">Should the document be closed (true) in which case it cannot be later changed and a PDF and document number are generated or should the document be created as a draft (false) in which case no PDF or document number are generated.</param> /// <param name="sentTo">Upon closing the document an email can be sent with a notification of the document to an email address.</param> public APIDocumentCreateResponse InvoiceSimplifiedCreate(Models.Client client, SimplifiedInvoice invoice, bool isToClose, string sentTo) { Invoicing_v2.InvoicingSoapClient apiClient = GetAPIClient(); Invoicing_v2.Client invoiceClient = ToInvoicingClient(client); DocumentIn document = ToInvoicingDocument(invoice); var serviceResponse = apiClient.DocumentCreateAsync(GetAuthenticationCredentials(), invoiceClient, document, isToClose, sentTo).Result; return(new APIDocumentCreateResponse(serviceResponse)); }
public Response AddDocumentIn(DocumentIn docIn) { try { using (DGAMilDocEntities ctx = new DGAMilDocEntities()) { var doc = ctx.DocumentIn.Where(o => o.ProcessId == docIn.ProcessId).FirstOrDefault(); if (doc != null) { resp.ResponseObject = doc; } else { if (docIn.DocumentReference != null) { foreach (var item in docIn.DocumentReference) { item.State = "บันทึก"; item.Type = 2; } }; ctx.DocumentIn.Add(docIn); DocumentProcess docProcess = new DocumentProcess() { CreatedDate = DateTime.Now, DocumentInId = docIn.Id, ProcessId = docIn.ProcessId, Status = "รับหนังสือรอส่งหนังสือตอบรับ" }; ctx.DocumentProcess.Add(docProcess); ctx.SaveChanges(); resp.ResponseObject = docIn; } resp.Status = true; //resp.Description = "1"; } } catch (Exception ex) { resp.Status = false; resp.Description = ex.Message; } return resp; }
private DocumentIn ToInvoicingDocument(Document invoice) { var document = new DocumentIn() { Type = Convert.ToChar(invoice.Type).ToString(), Date = invoice.Date.ToString(Constants.Format.DateTime.ShortDate), DueDate = invoice.DueDate.ToString(Constants.Format.DateTime.ShortDate), Description = invoice.Description, Serie = invoice.Series, TaxExemptionReasonCode = invoice.TaxExemptionReasonCode, Currency = invoice.Currency, EuroRate = invoice.EuroRate, //Retention = invoice.Retention, ExternalId = invoice.ExternalId, Id = invoice.Id }; document.Lines = new System.Collections.Generic.List <Invoicing_v2.APIInvoicingProduct>(); #warning Retention missing from contract ??? document.Lines = invoice.Lines.Select(product => new Invoicing_v2.APIInvoicingProduct() { Code = product.Code, Description = product.Description, UnitPrice = product.UnitPrice, Quantity = product.Quantity, Unit = product.Unit, Type = product.Type.ToString(), TaxValue = product.TaxValue, ProductDiscount = product.ProductDiscount, CostCenter = product.CostCenter }) .ToList(); return(document); }