Пример #1
0
 public IHttpActionResult RemoteReplacePublish(RemoteAdjustInvoice data)
 {
     try
     {
         Company  currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         XElement elem           = XElement.Parse(data.InvData);
         IEnumerable <XElement>       listTemp = elem.Elements("Data");
         IDictionary <string, byte[]> dictInv  = new Dictionary <string, byte[]>();
         foreach (XElement e in listTemp)
         {
             string id     = e.Element("id").Value;
             string Signed = e.Element("Signed").Value;
             dictInv.Add(id, Convert.FromBase64String(Signed));
         }
         IInvoiceService invSrv = InvServiceFactory.GetService(data.OriPattern, currentCompany.id);
         IInvoice        OriInv = invSrv.GetByNo(currentCompany.id, data.OriPattern, data.OriSerial, data.OriNo);
         IInvoice        p      = EInvoice.Core.Launching.Launcher.Instance.ReplaceRemote(OriInv, data.OriPattern, data.OriSerial, dictInv);
         return(Ok(new DataUpdate()
         {
             Data = p.Data, No = p.No, Serial = p.Serial
         }));
     }
     catch (Exception ex)
     {
         return(Ok("ERROR"));
     }
 }
Пример #2
0
        public IHttpActionResult GetDigestForReplace(RemoteAdjustInvoice data)
        {
            ILog log = LogManager.GetLogger(typeof(RemoteLauncherController));
            XmlSchemaValidator validator = new XmlSchemaValidator();

            if (!validator.ValidXmlDoc(data.InvData, "", AppDomain.CurrentDomain.BaseDirectory + @"xmlvalidate\replacevatinvoice.xsd"))
            {
                log.Error("ERR:3-" + validator.ValidationError);
                return(Ok("ERR:3-" + validator.ValidationError));  //du lieu dau vao khong hop le
            }

            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return(Ok("ERR:4"));
            }
            IInvoiceService invSrv = InvServiceFactory.GetService(data.OriPattern, comID);
            IInvoice        OriInv = invSrv.GetByNo(comID, data.OriPattern, data.OriSerial, data.OriNo);

            if (!checkInvNumber(comID, OriInv.Pattern, OriInv.Serial))
            {
                log.Error("het so hoa don trong dai.");
                return(Ok <string>("ERR:6"));   //het so hoa don trong dai
            }
            IRegisterTempService regisSrv = IoC.Resolve <IRegisterTempService>();

            ICustomerService _cusSvr = IoC.Resolve <ICustomerService>();

            IInvoice inv  = (InvoiceBase)InvServiceFactory.NewInstance(OriInv.Pattern, comID);
            string   read = data.InvData;//string.Concat(invs.ElementAt(i));

            DataHelper.DeserializeEinvFromXML(read, inv);
            inv.No             = 0;
            inv.Name           = OriInv.Name;
            inv.Pattern        = OriInv.Pattern;
            inv.Serial         = OriInv.Serial;
            inv.CreateBy       = System.Web.HttpContext.Current.User.Identity.Name;
            inv.ProcessInvNote = "";
            string strReplace = (_currentCompany.Config.ContainsKey("ReplaceString")) ? _currentCompany.Config["ReplaceString"] : "Hóa đơn này thay thế hóa đơn số: @InvNo, Ký hiệu: @InvSerial, Gửi ngày @InvDay Tháng @InvMonth Năm @InvYear";

            strReplace         = strReplace.Replace("@InvNo", OriInv.No.ToString(Utils.MAX_NO_LENGTH)).Replace("@InvSerial", OriInv.Serial).Replace("@InvDay", OriInv.ArisingDate.Day.ToString()).Replace("@InvMonth", OriInv.ArisingDate.Month.ToString()).Replace("@InvYear", OriInv.ArisingDate.Year.ToString());
            inv.ProcessInvNote = strReplace;
            inv.Type           = InvoiceType.ForReplace;
            var Typecus = (from c in _cusSvr.Query where c.ComID == comID && c.Code == inv.CusCode && c.CusType == 1 select c.CusType).SingleOrDefault();

            if (Typecus == 0)
            {
                inv.CusSignStatus = cusSignStatus.NocusSignStatus;
            }
            else
            {
                inv.CusSignStatus = cusSignStatus.NoSignStatus;
            }
            if (OriInv.Status == InvoiceStatus.SignedInv || OriInv.Status == InvoiceStatus.AdjustedInv)
            {
                byte[]                       raw      = Convert.FromBase64String(data.CertBase64String);
                X509Certificate2             x509Cert = new X509Certificate2(raw);
                IDictionary <string, string> dict     = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(data.OriPattern, data.OriSerial, new IInvoice[] { inv }, x509Cert);
                return(Ok(dict));
            }
            return(NotFound());
        }