Ejemplo n.º 1
0
 //public static void SendVATReturnProc(VATMaint vatMaint, VATPeriodFilter p, bool finalised = false)
 public static void SendVATReturnProc(VATMaint vatMaint, bool finalised = false)
 {
     vatMaint.VATreturn.finalised = finalised;
     try
     {
         vatMaint.VATReturnResponse = vatMaint.VATProvider.SendReturn(vatMaint.VATreturn);
         Trace.WriteInformation(JsonConvert.SerializeObject(vatMaint.VATReturnResponse));
     }
     catch (Exceptions.VATAPIInvalidToken eToken)
     {
         Trace.WriteError(eToken);
         throw new Exception(Messages.PleaseAuthorize);
     }
     catch (Exceptions.VATAPIException eApi)
     {
         Trace.WriteError(eApi);
         if (eApi.Data.Contains("errorJson"))
         {
             Trace.WriteError(eApi.Data["errorJson"].ToString());
         }
         throw eApi;
     }
     catch (Exception e)
     {
         Trace.WriteError(e);
         throw e;
     }
     return;
     // throw new Exception(Messages.VATreturnIsAccepted);
 }
Ejemplo n.º 2
0
        public static void GetVATLiabilitiesProc(VATMaint vatMaint, DateTime from, DateTime to, string testScenario = null)
        {
            liabilityRequest req = new liabilityRequest()
            {
                from = from, to = to
            };
            liabilityResponse liabilityResponse = null;

            try
            {
                liabilityResponse = vatMaint.VATProvider.Liabilities(req, testScenario);
            }
            catch (Exceptions.VATAPIInvalidToken eToken)
            {
                Trace.WriteError(eToken);
                //         vatMaint.signInHMRC.SetEnabled(true);
                throw new Exception(Messages.PleaseAuthorize);
            }
            catch (Exceptions.VATAPIException eApi)
            {
                Trace.WriteError(eApi);
                if (eApi.Data.Contains("json"))
                {
                    Trace.WriteError(eApi.Data["json"].ToString());
                }
                if (eApi.Code != error.MATCHING_RESOURCE_NOT_FOUND)
                {
                    throw eApi;
                }
            }
            catch (Exception e)
            {
                Trace.WriteError(e);
                throw e;
            }
            vatMaint.Liabilities.Clear();
            if (liabilityResponse != null)
            {
                foreach (var o in liabilityResponse.liabilities)
                {
                    vatMaint.Liabilities.Add(new Liability()
                    {
                        due               = DateTime.ParseExact(o.due, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture),
                        originalAmount    = o.originalAmount,
                        outstandingAmount = o.outstandingAmount,
                        type              = o.type,
                        from              = DateTime.ParseExact(o.taxPeriod.from, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture),
                        to = DateTime.ParseExact(o.taxPeriod.to, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)
                    });
                }
            }
            return;
        }
Ejemplo n.º 3
0
        public static void GetVATObligationsProc(VATMaint vatMaint, DateTime from, DateTime to, string status = null, String testScenario = null)
        {
            obligationsRequest req = new obligationsRequest()
            {
                from = from, to = to, status = status
            };
            obligationResponse obligationResponse = null;

            try
            {
                obligationResponse = vatMaint.VATProvider.Obligations(req, testScenario);
            }
            catch (Exceptions.VATAPIInvalidToken eToken)
            {
                Trace.WriteError(eToken);
                //         vatMaint.signInHMRC.SetEnabled(true);
                throw new Exception(Messages.PleaseAuthorize);
            }
            catch (Exceptions.VATAPIException eApi)
            {
                Trace.WriteError(eApi);
                if (eApi.Data.Contains("json"))
                {
                    Trace.WriteError(eApi.Data["json"].ToString());
                }
                if (eApi.Code != error.MATCHING_RESOURCE_NOT_FOUND)
                {
                    throw eApi;
                }
            }
            catch (Exception e)
            {
                Trace.WriteError(e);
                throw e;
            }
            vatMaint.Obligations.Clear();
            if (obligationResponse != null)
            {
                foreach (var o in obligationResponse.obligations)
                {
                    vatMaint.Obligations.Add(new Obligation()
                    {
                        Start     = o.start,
                        End       = o.end,
                        Due       = o.due,
                        Status    = o.status,
                        PeriodKey = o.periodKey,
                        Received  = o.received
                    });
                }
            }
            return;
        }
Ejemplo n.º 4
0
        public static void GetVATPaymentsProc(VATMaint vatMaint, DateTime from, DateTime to, string testScenario = null)
        {
            paymentRequest req = new paymentRequest()
            {
                from = from, to = to
            };
            paymentResponse paymentResponse = null;

            try
            {
                paymentResponse = vatMaint.VATProvider.Payments(req, testScenario);
            }
            catch (Exceptions.VATAPIInvalidToken eToken)
            {
                Trace.WriteError(eToken);
                //         vatMaint.signInHMRC.SetEnabled(true);
                throw new Exception(Messages.PleaseAuthorize);
            }
            catch (Exceptions.VATAPIException eApi)
            {
                Trace.WriteError(eApi);
                if (eApi.Data.Contains("json"))
                {
                    Trace.WriteError(eApi.Data["json"].ToString());
                }
                if (eApi.Code != error.MATCHING_RESOURCE_NOT_FOUND)
                {
                    throw eApi;
                }
            }
            catch (Exception e)
            {
                Trace.WriteError(e);
                throw e;
            }
            vatMaint.Payments.Clear();
            if (paymentResponse != null)
            {
                foreach (var o in paymentResponse.payments)
                {
                    vatMaint.Payments.Add(new Payment()
                    {
                        amount   = o.amount,
                        received = (o.received == null) ? (DateTime?)null : DateTime.ParseExact(o.received, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)
                    });
                }
            }
            return;
        }
Ejemplo n.º 5
0
        public static void CheckVATReturnProc(VATMaint vatMaint, string periodKey)
        {
            if (String.IsNullOrWhiteSpace(periodKey))
            {
                return;
            }

            try
            {
                vatMaint.VATreturn = vatMaint.VATProvider.Returns(periodKey);
            }
            catch (Exceptions.VATAPIInvalidToken eToken)
            {
                Trace.WriteError(eToken);
                //  vatMaint.signInHMRC.SetEnabled(true);
                throw new Exception(Messages.PleaseAuthorize);
            }
            catch (Exceptions.VATAPIException eApi)
            {
                if (eApi.Code == error.NOT_FOUND)
                {
                    vatMaint.VATreturn = new VATreturn();
                }
                Trace.WriteError(eApi);
                if (eApi.Data.Contains("json"))
                {
                    Trace.WriteError(eApi.Data["json"].ToString());
                }
                throw eApi;
            }
            catch (Exception e)
            {
                Trace.WriteError(e);
                throw e;
            }
        }
Ejemplo n.º 6
0
 public static void GetVATObligationsForYearProc(VATMaint vatMaint, DateTime to)
 {
     GetVATObligationsProc(vatMaint, to.AddYears(-1), to);
 }
Ejemplo n.º 7
0
 public static void SignInHMRCProc(VATMaint vatMaint)
 {
     vatMaint.VATProvider.SignIn();
     throw new Exception("Please Refresh");
 }