示例#1
0
        public void AddOffer(string debtor, System.Guid offerid)
        {
            ICollection <Offers>           offers;
            ICollection <EstimateConnects> Connect;

            using (var context = new DataBaseContext())
            {
                offers = context.Offer
                         .Include(offermodel => offermodel.Estimate)
                         .Include(user => user.CreatedBy)
                         .Include(user => user.UpdatedBy)
                         .ToList();

                Connect = context.EstimateConnects
                          .Include(line => line.EstimateLines)
                          .ToList();
            }
            var offer      = offers.FirstOrDefault(x => x.Id.Equals(offerid));
            var guid       = offer.Estimate.Id;
            var estimateid = Guid.Parse(guid.ToString());
            var estimate   = EstimateRepository.Find(estimateid);
            var lines      = Connect.Where(x => x.Estimate.Id == estimate.Id).ToList();

            var debtornumber = Regex.Replace(debtor, "[^0-9.]", "");

            var client       = new RestClient(ApiUrl);
            var request      = new RestRequest("/apiv2/api.php", Method.POST);
            var InvoiceLines = new List <Dictionary <string, string> >();

            foreach (var item in lines)
            {
                var line = new Dictionary <string, string>
                {
                    { "Description", item.EstimateLines.Specification },
                    { "PriceExcl", item.EstimateLines.TotalCost.ToString() }
                };
                InvoiceLines.Add(line);
            }
            var invoice = new Invoice
            {
                api_key    = ApiKey,
                controller = "invoice",
                action     = "add",
                Debtor     = debtornumber.ToString(),

                Concept      = 0,
                InvoiceLines = InvoiceLines
            };

            request.RequestFormat = DataFormat.Json;
            request.AddJsonBody(invoice);

            var response = client.Execute <WeFactResponseModel>(request);
            var offerte  = OfferRepository.Find(offerid);

            OfferRepository.SaveChanges();
            EditWefactLines(response.Data.Invoice.InvoiceLines, offerid);
        }
示例#2
0
        public void EditInvoice(Guid offerid)
        {
            var client  = new RestClient(ApiUrl);
            var request = new RestRequest("/apiv2/api.php", Method.POST);

            var offer = OfferRepository.Find(offerid);

            request.AddParameter("api_key", ApiKey);
            request.AddParameter("action", "edit");
            request.AddParameter("controller", "invoice");
            request.AddParameter("Identifier", offer.DocumentCode);
        }