Пример #1
0
 /// <summary>
 /// Function [GenerateInvoice]
 /// </summary>
 /// <param name="model"></param>
 /// <param name="msg"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public bool GenerateInvoice(string _hostXeroApi, GenerateInvoiceModels request, ref string msg)
 {
     try
     {
         NSLog.Logger.Info("GenerateInvoice_Request: ", request);
         var result = (ResponseApiModels)ApiResponseXero.Post <ResponseApiModels>(_hostXeroApi + "/" + Commons.XeroApi_Generate_Invoice, null, request);
         NSLog.Logger.Info("GenerateInvoice_Response: ", result);
         if (result.Success)
         {
             return(true);
         }
         else
         {
             msg = result.Message;
             msg = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(msg);
             return(false);
         }
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("GenerateInvoice|Error: ", ex);
         return(false);
     }
 }
Пример #2
0
        public ResultModels GenerateReceiptNoteAPI(GenerateReceiptNoteApiModels model)
        {
            NSLog.Logger.Info("Call_GenerateReceiptNoteAPI_Request: ", model);
            ResultModels result = new ResultModels();

            try
            {
                var xero = Commons.GetIntegrateInfo(model.StoreId);
                /* GENERAL INVOICE XERO */
                if (xero != null)
                {
                    /* find supplier name by supplier id */
                    SupplierXeroFactory xeroSup = new SupplierXeroFactory();
                    string msgSupplier          = string.Empty;
                    var    sup = xeroSup.GetSupplierXero(model.ApiURL, model.AppRegistrationId, model.StoreId, model.SupplierName, "", false, ref msgSupplier);
                    if (sup != null)
                    {
                    }
                    XeroFactory _facXero = new XeroFactory();
                    var         listItem = new List <InvoiceLineItemModels>();
                    if (model.ListItem != null && model.ListItem.Any())
                    {
                        string _AccountCode = Commons.AccountCode_Inventory;

                        using (var cxt = new NuWebContext())
                        {
                            var StockOnHand = (from _store in cxt.G_SettingOnStore
                                               from _setting in cxt.G_GeneralSetting
                                               where _store.SettingId == _setting.Id && _store.StoreId.Equals(model.StoreId) &&
                                               _store.Status && _setting.Status &&
                                               _setting.Code.Equals((byte)Commons.EGeneralSetting.StockOnHand)
                                               select _store).FirstOrDefault();
                            if (StockOnHand != null)
                            {
                                _AccountCode = StockOnHand.Value;
                            }
                        }

                        //get tax rate
                        string TaxType = "TAX002";
                        NuWebNCloud.Shared.Factory.Settings.TaxFactory _taxFactory = new NuWebNCloud.Shared.Factory.Settings.TaxFactory();
                        var lstTaxes = _taxFactory.GetListTaxV2(model.StoreId);
                        var tax      = lstTaxes.Where(w => w.IsActive && !string.IsNullOrEmpty(w.Rate)).FirstOrDefault();
                        if (tax != null)
                        {
                            TaxType = tax.Rate;
                        }

                        foreach (var _item in model.ListItem)
                        {
                            listItem.Add(new InvoiceLineItemModels
                            {
                                Description = _item.IngredientName,
                                ItemCode    = _item.IngredientCode,
                                Quantity    = Convert.ToDecimal(_item.Qty),
                                UnitAmount  = Convert.ToDecimal(_item.UnitPrice),
                                LineAmount  = Convert.ToDecimal(_item.Qty * _item.UnitPrice),
                                AccountCode = _AccountCode,
                                TaxType     = TaxType//(model.TaxType == (int)Commons.ETax.AddOn ? "OUTPUT" : "INPUT"),
                            });
                        }
                    }
                    var modelXero = new GenerateInvoiceModels
                    {
                        AppRegistrationId = model.AppRegistrationId,
                        StoreId           = model.StoreId,
                        CurrencyCode      = Commons._XeroCurrencyCode,
                        Reference         = model.Code,
                        Contact           = new InvoiceContactGRNModels
                        {
                            Name = model.SupplierName
                        },
                        DueDate         = model.DueDate,
                        ClosingDatetime = model.ClosingDatetime,

                        InvoiceType    = string.IsNullOrEmpty(model.InvoiceType.ToString()) ? (byte)Commons.EInvoiceType.AccountsPayable : model.InvoiceType,
                        LineAmountType = string.IsNullOrEmpty(model.LineAmountType.ToString()) ? (byte)Commons.ELineAmountType.Inclusive : model.LineAmountType,
                        InvoiceStatus  = string.IsNullOrEmpty(model.InvoiceStatus.ToString()) ? (byte)Commons.EInvoiceStatus.Authorised : model.InvoiceStatus,

                        Items = listItem
                    };
                    var msgXero    = string.Empty;
                    var data       = new GIResponseModels();
                    var resultXero = _facXero.GenerateInvoice(model.ApiURL, modelXero, ref msgXero);
                    result.IsOk    = true;
                    result.Message = msgXero;
                    //======
                    result.RawData = data;
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Call_GenerateReceiptNoteAPI|Error: ", ex);
                result.IsOk = false;
            }
            return(result);
        }