Пример #1
0
        public List <BankTabApiModel> GetAccount(int businessId, int accountTypeId)
        {
            List <BankTabApiModel>           result        = new List <BankTabApiModel>();
            List <ReceiptandPaymentApiModel> list          = GetApiServices.Instance.getDescriptionListing(businessId, accountTypeId, (int)EntityTypeEnum.ReceiptsandPaymentsTypeEntity);
            List <Account> monetaryAccounts                = GetApiServices.Instance.getAccountForBusiness(businessId, accountTypeId);
            List <ReceiptandPaymentApiModel> processedList = new List <ReceiptandPaymentApiModel>();
            List <AccountApiModel>           orderedList   = new List <AccountApiModel>();

            foreach (var acc in monetaryAccounts)
            {
                List <AccountApiModel> accountList = new List <AccountApiModel>();
                decimal clearBal          = 0;
                decimal pendingDeposit    = 0;
                decimal pendingWithdrawal = 0;
                decimal ActualBalance     = 0;
                foreach (var item in list.Where(x => x.BankAccountKey == acc.AccountKey).OrderBy(x => x.ReceiptPaymentDate).ToList())
                {
                    AccountApiModel accountModel = new AccountApiModel();
                    accountModel.ReceiptPaymentID   = item.ReceiptPaymentID;
                    accountModel.ReceiptPaymentDate = item.ReceiptPaymentDate;
                    accountModel.Date        = item.ReceiptPaymentDate.ToString("dd/MM/yyyy");
                    accountModel.Account     = item.ChartAccountName;
                    accountModel.Description = string.Format("{0} — {1}", item.Name, item.Payee);
                    accountModel.Amount      = item.TransectionType == (int)TransectionTypeEnum.Payment ? string.Format("-{0}", item.Amount) : item.Amount.ToString();
                    if (item.IsBalanceClear && item.TransectionType == (int)TransectionTypeEnum.Receipt)
                    {
                        clearBal += item.Amount;
                    }
                    else if (item.IsBalanceClear && item.TransectionType == (int)TransectionTypeEnum.Payment)
                    {
                        clearBal -= item.Amount;
                    }
                    else if (!item.IsBalanceClear && item.TransectionType == (int)TransectionTypeEnum.Receipt)
                    {
                        pendingDeposit += item.Amount;
                    }
                    else if (!item.IsBalanceClear && item.TransectionType == (int)TransectionTypeEnum.Payment)
                    {
                        pendingWithdrawal += item.Amount;
                    }

                    accountModel.Balance = clearBal;
                    accountList.Add(accountModel);
                    ActualBalance = clearBal + pendingDeposit - pendingWithdrawal;
                }
                accountList.Reverse();
                result.Add(new BankTabApiModel()
                {
                    Name              = acc.AccountName,
                    ClearBalance      = clearBal,
                    PendingDeposit    = pendingDeposit,
                    PendingWithdrawal = pendingWithdrawal,
                    ActualBalance     = ActualBalance,
                    List              = accountList
                });
            }

            return(result);
        }
Пример #2
0
        public async Task <DeleteAccountResponse> DeleteAccount(int accountId)
        {
            var apiModel = new AccountApiModel
            {
                AccountID = accountId,
                Name      = string.Empty
            };
            var deleteProductResponse = await DeleteEncodedContentWithSimpleResponse <DeleteAccountResponse, AccountApiModel>(Constants.AccountUri, apiModel);

            return(deleteProductResponse);
        }
Пример #3
0
        // GET: api/Account/1
        public AccountApiModel Get(int id)
        {
            var result = new AccountApiModel();

            var account = _accountService.GetAccount(id);

            result.AccountID = account.AccountID;
            result.Name      = account.Name;

            return(result);
        }
Пример #4
0
        public async Task <UpdateAccountResponse> UpdateAccount(AccountViewModel account)
        {
            var apiModel = new AccountApiModel
            {
                AccountID     = account.AccountID,
                AccountTypeID = account.AccountTypeID,
                Name          = account.Name
            };
            var createProductResponse = await PutEncodedContentWithSimpleResponse <UpdateAccountResponse, AccountApiModel>(Constants.AccountUri, apiModel);

            return(createProductResponse);
        }
Пример #5
0
        // GET: api/Account
        public IEnumerable <AccountApiModel> Get()
        {
            var returnValue = new List <AccountApiModel>();
            var accounts    = _accountService.GetAccounts();

            foreach (var account in accounts)
            {
                var newAccount = new AccountApiModel();
                newAccount.AccountID = account.AccountID;
                newAccount.Name      = account.Name;
                returnValue.Add(newAccount);
            }

            return(returnValue);
        }
Пример #6
0
        public async Task <IActionResult> Register([FromBody] RegisterApiResource model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogWarning("User created a new account with password.");
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Wrappers.GetActionLink(Url, nameof(ConfirmEmail), user, code);
                    await _emailSender.SendEmailAsync(model.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    var userApi = new AccountApiModel
                    {
                        Id        = user.Id,
                        FirstName = user.FirstName,
                        LastName  = user.LastName,
                        Email     = user.Email
                    };

                    return(Ok(new
                    {
                        userApi,
                        Success = new { Message = "User created." }
                    }));
                }

                AddErrors(result);

                return(BadRequest(new
                {
                    Error = new { Message = "Something went wrong." },
                    result
                }));
            }

            return(BadRequest(ModelState));
        }
Пример #7
0
        public static AccountApiModel GetAccountFromApi(string apiurl, string username, string password)
        {
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
            ApiAuthModel apiAuth = new ApiAuthModel();
            string       url     = apiurl;

            apiAuth.Username = username;
            apiAuth.Password = password;
            JsonModel       stringJson = new JsonModel();
            AccountApiModel account    = new AccountApiModel();

            if (!GetJSONResponseForAccount(url, ref stringJson, ref account, apiAuth))
            {
                // errMsg = getErrorMsg(stringJson.Data);
            }

            return(account);
        }
Пример #8
0
        public static void InnerObjectSyncFromApi(List <ObjectModel> objectModel, List <Business> businessApiModel, ApiAuthModel apiAuth)
        {
            foreach (var item in businessApiModel)
            {
                List <ObjectAPIModel> innerObjApiModel = new List <ObjectAPIModel>();
                foreach (var obj in objectModel)
                {
                    string         url      = string.Format("{0}/{1}/{2}/{3}", Constants.Api_Url, item.BusinessKey, obj.ObjectKey, "index.json");
                    ObjectAPIModel objmodel = new ObjectAPIModel();
                    objmodel.ObjectID       = obj.ObjectID;
                    objmodel.ObjectKey      = obj.ObjectKey;
                    objmodel.ObjectName     = obj.ObjectName;
                    objmodel.innerObjApiUrl = url;
                    innerObjApiModel.Add(objmodel);
                }
                foreach (var api in innerObjApiModel)
                {
                    List <string> InnerObjectKeys = FetchApiHelper.GetInnerObjectsKeysFromApi(api.innerObjApiUrl, apiAuth.Username, apiAuth.Password);
                    if (InnerObjectKeys.Count > 0)
                    {
                        SyncApiService.Instance.InsertInnerObjects(InnerObjectKeys, api.ObjectName, api.ObjectID, api.ObjectKey, item.BusinessID, item.BusinessKey);

                        if (api.ObjectID == (int)ObjectEnum.BusinessLogo)
                        {
                            List <BusinessLogoApiModel> businessLogoApiList = new List <BusinessLogoApiModel>();
                            BusinessLogoApiModel        businessLogo        = new BusinessLogoApiModel();
                            foreach (var logo in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, logo, ".json");
                                businessLogo = FetchApiHelper.GetBusinessLogoFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (businessLogo != null)
                                {
                                    businessLogo.ApiKey      = logo;
                                    businessLogo.BusinessID  = item.BusinessID;
                                    businessLogo.BusinessKey = item.BusinessKey;
                                    businessLogo.IsActive    = true;
                                    businessLogoApiList.Add(businessLogo);
                                }
                            }
                            if (businessLogoApiList.Count > 0)
                            {
                                SyncApiService.Instance.InsertBusinessLogo(businessLogoApiList);
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.BusinessDetails)
                        {
                            List <BusinessDetailApiModel> businessDetailApiList = new List <BusinessDetailApiModel>();
                            BusinessDetailApiModel        businessDetail        = new BusinessDetailApiModel();
                            foreach (var detail in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, detail, ".json");
                                businessDetail = FetchApiHelper.GetBusinessDetailFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (businessDetail != null)
                                {
                                    businessDetail.ApiKey      = detail;
                                    businessDetail.BusinessID  = item.BusinessID;
                                    businessDetail.BusinessKey = item.BusinessKey;
                                    businessDetail.IsActive    = true;
                                    businessDetailApiList.Add(businessDetail);
                                }
                            }
                            if (businessDetailApiList.Count > 0)
                            {
                                SyncApiService.Instance.InsertBusinessDetail(businessDetailApiList);
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.BankAccount || api.ObjectID == (int)ObjectEnum.CashAccount)
                        {
                            List <AccountApiModel> accountApiList = new List <AccountApiModel>();
                            AccountApiModel        account        = new AccountApiModel();
                            foreach (var acc in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, acc, ".json");
                                account = FetchApiHelper.GetAccountFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (account != null)
                                {
                                    account.ApiKey      = acc;
                                    account.AccountType = api.ObjectID == (int)ObjectEnum.BankAccount ? (int)ObjectEnum.BankAccount : (int)ObjectEnum.CashAccount;
                                    account.BusinessID  = item.BusinessID;
                                    account.BusinessKey = item.BusinessKey;
                                    account.IsActive    = true;
                                    accountApiList.Add(account);
                                }
                            }
                            if (accountApiList.Count > 0)
                            {
                                SyncApiService.Instance.InsertAccount(accountApiList);
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.Customer || api.ObjectID == (int)ObjectEnum.Supplier)
                        {
                            List <PartyApiModel> partyApiList = new List <PartyApiModel>();
                            PartyApiModel        partyModel   = new PartyApiModel();
                            foreach (var party in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, party, ".json");
                                partyModel = FetchApiHelper.GetPartyFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (partyModel != null)
                                {
                                    partyModel.ApiKey      = party;
                                    partyModel.BusinessID  = item.BusinessID;
                                    partyModel.BusinessKey = item.BusinessKey;
                                    partyModel.IsActive    = true;
                                    partyModel.PartyTypeID = api.ObjectID == (int)ObjectEnum.Customer ? (int)PartyEnum.Customer : (int)PartyEnum.Supplier;
                                    partyApiList.Add(partyModel);
                                }
                            }
                            if (partyApiList.Count > 0)
                            {
                                SyncApiService.Instance.InsertParty(partyApiList, api.ObjectID);
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.Folder)
                        {
                            List <FolderApiModel> folderApiList = new List <FolderApiModel>();
                            FolderApiModel        folderModel   = new FolderApiModel();
                            foreach (var folder in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, folder, ".json");
                                folderModel = FetchApiHelper.GetFolderFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (folderModel != null)
                                {
                                    folderModel.ApiKey      = folder;
                                    folderModel.BusinessID  = item.BusinessID;
                                    folderModel.BusinessKey = item.BusinessKey;
                                    folderModel.IsActive    = true;
                                    folderApiList.Add(folderModel);
                                }
                            }
                            if (folderApiList.Count > 0)
                            {
                                SyncApiService.Instance.InsertFolder(folderApiList);
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.InventoryItem)
                        {
                            List <InventoryApiModel> inventoryApiList = new List <InventoryApiModel>();
                            InventoryApiModel        inventory        = new InventoryApiModel();
                            foreach (var inv in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, inv, ".json");
                                inventory = FetchApiHelper.GetInventoryFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (inventory != null)
                                {
                                    inventory.ApiKey      = inv;
                                    inventory.BusinessID  = item.BusinessID;
                                    inventory.BusinessKey = item.BusinessKey;
                                    inventory.IsActive    = true;
                                    inventoryApiList.Add(inventory);
                                }
                            }
                            if (inventoryApiList.Count > 0)
                            {
                                SyncApiService.Instance.InsertInventory(inventoryApiList);
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.ChartofAccountGroup || api.ObjectID == (int)ObjectEnum.ChartofAccount)
                        {
                            List <ChartofAccount>     parentAccount = new List <ChartofAccount>();
                            List <ChartofAccApiModel> chartApiList  = new List <ChartofAccApiModel>();
                            ChartofAccApiModel        chart         = new ChartofAccApiModel();
                            if (api.ObjectID == (int)ObjectEnum.ChartofAccount)
                            {
                                parentAccount = FetchApiService.Instance.getChartofAccountGroupModel(item.BusinessID, item.BusinessKey);
                            }
                            foreach (var acc in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, acc, ".json");
                                chart = FetchApiHelper.GetChartAccountFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (chart != null)
                                {
                                    if (api.ObjectID == (int)ObjectEnum.ChartofAccount)
                                    {
                                        chart.ParentAccountID = parentAccount.Where(x => x.AccountKey == chart.Group).FirstOrDefault().AccountID;
                                    }
                                    chart.ApiKey         = acc;
                                    chart.BusinessID     = item.BusinessID;
                                    chart.BusinessKey    = item.BusinessKey;
                                    chart.IsActive       = true;
                                    chart.IsAccountGroup = !string.IsNullOrEmpty(chart.Group) ? true : false;
                                    chartApiList.Add(chart);
                                }
                            }
                            if (chartApiList.Count > 0)
                            {
                                SyncApiService.Instance.InsertChartOfAccounts(chartApiList);
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.TaxCode)
                        {
                            List <TaxCodeApiModel> taxcodeList = new List <TaxCodeApiModel>();
                            TaxCodeApiModel        taxcode     = new TaxCodeApiModel();
                            foreach (var tax in InnerObjectKeys)
                            {
                                TaxCode taxModel  = new TaxCode();
                                int     taxcodeId = 0;
                                string  apiurl    = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, tax, ".json");
                                taxcode = FetchApiHelper.GetTaxcodeFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (taxcode != null)
                                {
                                    taxModel.ComponentKey            = tax;
                                    taxModel.TaxCodeName             = taxcode.Name;
                                    taxModel.TaxRate                 = taxcode.TaxRate;
                                    taxModel.TaxRateType             = taxcode.TaxRateType;
                                    taxModel.Account                 = taxcode.Account;
                                    taxModel.SalesInvoiceTitle       = taxcode.SalesInvoiceTitle;
                                    taxModel.CustomSalesInvoiceTitle = taxcode.CustomSalesInvoiceTitle;
                                    taxModel.BusinessID              = item.BusinessID;
                                    taxModel.BusinessKey             = item.BusinessKey;
                                    taxModel.IsActive                = true;
                                    taxcodeId = SyncApiService.Instance.insertTaxCodeKey(taxModel);

                                    foreach (var comp in taxcode.Components)
                                    {
                                        comp.TaxCodeID   = taxcodeId;
                                        comp.BusinessID  = item.BusinessID;
                                        comp.BusinessKey = item.BusinessKey;
                                        comp.IsActive    = true;
                                    }
                                    if (taxcode.Components.Count > 0)
                                    {
                                        SyncApiService.Instance.InsertComponents(taxcode.Components);
                                    }
                                }
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.PurchaseInvoice || api.ObjectID == (int)ObjectEnum.SalesInvoice || api.ObjectID == (int)ObjectEnum.SalesOrder || api.ObjectID == (int)ObjectEnum.SalesQuote)
                        {
                            Invoice         invoiceModel = new Invoice();
                            InvoiceApiModel invoice      = new InvoiceApiModel();
                            //InnerObjectKeys = new List<string>();
                            //InnerObjectKeys.Add("2758ccc2-e085-4677-b4f0-0db836bd2fb8");
                            foreach (var inv in InnerObjectKeys)
                            {
                                int    invoiceID = 0;
                                string apiurl    = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, inv, ".json");
                                invoice = FetchApiHelper.GetInvoiceFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                //code for ByPassing API with no Data that i.e not existing
                                if ((invoice != null) &&
                                    (!string.IsNullOrEmpty(invoice.IssueDate) || !string.IsNullOrEmpty(invoice.Date) || !string.IsNullOrEmpty(invoice.Reference) ||
                                     !string.IsNullOrEmpty(invoice.Customer) || !string.IsNullOrEmpty(invoice.From) || !string.IsNullOrEmpty(invoice.To) ||
                                     !string.IsNullOrEmpty(invoice.Description) || !string.IsNullOrEmpty(invoice.Summary) || !string.IsNullOrEmpty(invoice.QuoteSummary) || !string.IsNullOrEmpty(invoice.InvoiceSummary) ||
                                     !string.IsNullOrEmpty(invoice.BillingAddress) || invoice.Discount || !string.IsNullOrEmpty(invoice.DiscountType) ||
                                     invoice.Rounding || !string.IsNullOrEmpty(invoice.RoundingMethod) || !string.IsNullOrEmpty(invoice.PurchaseOrderNumber) || !string.IsNullOrEmpty(invoice.SalesQuoteNumber)
                                    ))
                                {
                                    invoiceModel.InvoiceKey    = inv;
                                    invoiceModel.InvoiceBillNo = invoice.Reference;
                                    if (string.IsNullOrEmpty(invoice.IssueDate) && string.IsNullOrEmpty(invoice.Date))
                                    {
                                        invoiceModel.IssueDate = null;
                                    }
                                    else
                                    {
                                        invoiceModel.IssueDate = !string.IsNullOrEmpty(invoice.IssueDate) ? Convert.ToDateTime(invoice.IssueDate) : Convert.ToDateTime(invoice.Date);
                                    }
                                    if (api.ObjectID == (int)ObjectEnum.PurchaseInvoice)
                                    {
                                        invoiceModel.PartyKey       = invoice.From;
                                        invoiceModel.InvoiceSummary = invoice.Description;
                                        invoiceModel.PartyType      = (int)PartyEnum.Supplier;
                                    }
                                    else if (api.ObjectID == (int)ObjectEnum.SalesInvoice)
                                    {
                                        invoiceModel.PartyKey       = invoice.Customer;
                                        invoiceModel.InvoiceSummary = invoice.InvoiceSummary;
                                        invoiceModel.PartyType      = (int)PartyEnum.Customer;
                                    }
                                    else
                                    {
                                        invoiceModel.PartyKey       = !string.IsNullOrEmpty(invoice.Customer) ? invoice.Customer : invoice.To;
                                        invoiceModel.InvoiceSummary = !string.IsNullOrEmpty(invoice.Summary) ? invoice.Summary : invoice.QuoteSummary;
                                        invoiceModel.PartyType      = (int)PartyEnum.Customer;
                                    }
                                    if (invoice.Rounding)
                                    {
                                        invoiceModel.IsRounding = invoice.Rounding;
                                        if (invoice.RoundingMethod == "RoundDown")
                                        {
                                            invoiceModel.RoundingMethod = (int)RoundingMethodEnum.RoundDown;
                                        }
                                        else
                                        {
                                            invoiceModel.RoundingMethod = (int)RoundingMethodEnum.RoundToNearest;
                                        }
                                    }
                                    if (invoice.Discount)
                                    {
                                        invoiceModel.IsDiscount   = invoice.Discount;
                                        invoiceModel.DiscountType = !string.IsNullOrEmpty(invoice.DiscountType) ? (int)DiscountTypeEnumcs.ExactAmount : (int)DiscountTypeEnumcs.Percentage;
                                    }
                                    invoiceModel.InvoiceType         = api.ObjectID;
                                    invoiceModel.BusinessID          = item.BusinessID;
                                    invoiceModel.BusinessKey         = item.BusinessKey;
                                    invoiceModel.IsActive            = true;
                                    invoiceModel.IsAmountsIncludeTax = invoice.AmountsIncludeTax;
                                    invoiceModel.PurchaseOrderNo     = invoice.PurchaseOrderNumber;
                                    invoiceModel.SalesQuoteNo        = invoice.SalesQuoteNumber;
                                    invoiceModel.Address             = invoice.BillingAddress;
                                    invoiceID = SyncApiService.Instance.insertInvoiceKey(invoiceModel);
                                    if (invoice.Lines != null && invoice.Lines.Count > 0)
                                    {
                                        int sequence = 0;
                                        foreach (var desc in invoice.Lines)
                                        {
                                            sequence++;
                                            desc.EntityID     = invoiceID;
                                            desc.EntityTypeID = (int)EntityTypeEnum.InvoiceTypeEntity;
                                            desc.Sequence     = sequence;
                                            desc.IsActive     = true;
                                            desc.DiscountType = desc.Discount > 0 ? (int)DiscountTypeEnumcs.Percentage : 0;
                                            desc.DiscountType = desc.DiscountAmount > 0 ? (int)DiscountTypeEnumcs.ExactAmount : 0;
                                            if (desc.DiscountType > 0)
                                            {
                                                desc.Discount = desc.Discount > 0 ? desc.Discount : desc.DiscountAmount;
                                            }
                                        }
                                        SyncApiService.Instance.InsertLineDescriptions(invoice.Lines);
                                        sequence = 0;
                                    }
                                }
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.ReceiptOrPayment)
                        {
                            ReceiptsPayment           model             = new ReceiptsPayment();
                            ReceiptAndPaymentApiModel receiptandpayment = new ReceiptAndPaymentApiModel();
                            foreach (var trans in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, trans, ".json");
                                receiptandpayment = FetchApiHelper.GetReceiptsPaymentsFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (receiptandpayment != null)
                                {
                                    int ReceiptPaymentID = 0;
                                    model.ReceiptPaymentKey = trans;
                                    if (!string.IsNullOrEmpty(receiptandpayment.Date))
                                    {
                                        model.ReceiptPaymentDate = Convert.ToDateTime(receiptandpayment.Date);
                                    }
                                    model.AccountKey = receiptandpayment.BankAccount;
                                    model.Name       = receiptandpayment.Description;
                                    model.Payee      = receiptandpayment.Contact;
                                    if (!string.IsNullOrEmpty(receiptandpayment.Type))
                                    {
                                        model.TransectionType = !string.IsNullOrEmpty(receiptandpayment.Type) ? (int)TransectionTypeEnum.Payment : (int)TransectionTypeEnum.Receipt;
                                    }
                                    else
                                    {
                                        model.TransectionType = (int)TransectionTypeEnum.Receipt;
                                    }
                                    model.BusinessID          = item.BusinessID;
                                    model.BusinessKey         = item.BusinessKey;
                                    model.IsActive            = true;
                                    model.IsAmountsIncludeTax = receiptandpayment.AmountsIncludeTax;
                                    model.Reference           = receiptandpayment.Reference;
                                    model.IsBalanceClear      = !string.IsNullOrEmpty(receiptandpayment.BankClearStatus) ? true : false;
                                    ReceiptPaymentID          = SyncApiService.Instance.insertReceiptPaymentKey(model);
                                    if (receiptandpayment.Lines != null && receiptandpayment.Lines.Count > 0)
                                    {
                                        int sequence = 0;
                                        foreach (var desc in receiptandpayment.Lines)
                                        {
                                            sequence++;
                                            desc.EntityID     = ReceiptPaymentID;
                                            desc.EntityTypeID = (int)EntityTypeEnum.ReceiptsandPaymentsTypeEntity;
                                            desc.Sequence     = sequence;
                                            desc.IsActive     = true;
                                            desc.DiscountType = desc.Discount > 0 ? (int)DiscountTypeEnumcs.Percentage : 0;
                                            desc.DiscountType = desc.DiscountAmount > 0 ? (int)DiscountTypeEnumcs.ExactAmount : 0;
                                            if (desc.DiscountType > 0)
                                            {
                                                desc.Discount = desc.Discount > 0 ? desc.Discount : desc.DiscountAmount;
                                            }
                                        }
                                        SyncApiService.Instance.InsertLineDescriptions(receiptandpayment.Lines);
                                        sequence = 0;
                                    }
                                }
                            }
                        }
                        else if (api.ObjectID == (int)ObjectEnum.Attachment)
                        {
                            //List<InnerObject> innerObj = new List<InnerObject>();
                            //innerObj = FetchApiService.Instance.getInnerObjectModel(item.BusinessID, item.BusinessKey);
                            List <AttachmentApiModel> attachmentApiList = new List <AttachmentApiModel>();
                            AttachmentApiModel        attachment        = new AttachmentApiModel();
                            foreach (var att in InnerObjectKeys)
                            {
                                string apiurl = string.Format("{0}/{1}/{2}{3}", Constants.Api_Url, item.BusinessKey, att, ".json");
                                attachment = FetchApiHelper.GetAttachmentFromApi(apiurl, apiAuth.Username, apiAuth.Password);
                                if (attachment != null)
                                {
                                    //attachment.InnerObjectID = innerObj.Where(x => x.InnerObjectKey == attachment.Object).FirstOrDefault().InnerObjectID;
                                    attachment.ApiKey        = att;
                                    attachment.BusinessID    = item.BusinessID;
                                    attachment.BusinessKey   = item.BusinessKey;
                                    attachment.AttachmentUrl = string.Format("{0}/view-attachment?Key={1}&FileID={2}", Constants.Base_Url, attachment.ApiKey, item.BusinessKey);
                                    attachment.IsActive      = true;
                                    attachmentApiList.Add(attachment);
                                }
                            }
                            if (attachmentApiList.Count > 0)
                            {
                                SyncApiService.Instance.InsertAttachment(attachmentApiList);
                            }
                        }
                    }
                }
            }
        }
Пример #9
0
        private static bool GetJSONResponseForAccount(string url, ref JsonModel stringJson, ref AccountApiModel account, ApiAuthModel apiAuth)
        {
            bool   isSuccess          = false;
            string responseFromServer = GetResponseFromServer(url, apiAuth);

            if (responseFromServer != string.Empty)
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();

                if (responseFromServer.Contains("##error##"))
                {
                    stringJson = serializer.Deserialize <JsonModel>(responseFromServer);
                }
                else
                {
                    isSuccess = true;
                    account   = serializer.Deserialize <AccountApiModel>(responseFromServer);
                    if (account == null)
                    {
                        isSuccess       = false;
                        stringJson.Data = "##error##Error";
                    }
                }
            }

            return(isSuccess);
        }