Пример #1
0
        public JsonpResult verify(int invNo, string pattern, string serial, int ck)
        {
            IInvSrv = InvServiceFactory.GetService(pattern, currentCom.id);
            iGen    = InvServiceFactory.GetGenerator(pattern, currentCom.id);
            IInvoice inv = IInvSrv.GetByNo(currentCom.id, pattern, serial, invNo);

            byte[] data = iRepo.GetData(inv);

            XmlDocument xd = new XmlDocument();

            xd.PreserveWhitespace = true;
            xd.LoadXml(System.Text.Encoding.UTF8.GetString(data));

            int  k = iGen.VerifyInvoice(Encoding.UTF8.GetBytes(xd.OuterXml));
            bool c = false;

            if (k == 0 || k == 1 || (k == 2 && ck == 0))
            {
                c = true;
            }
            return(new JsonpResult
            {
                Data = c,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Пример #2
0
        public ActionResult Edit(string Pattern, int id)
        {
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
            //khoi tao service
            IInvoiceService IInvSrv = InvServiceFactory.GetService(Pattern, currentCom.id);
            //lay ve mot ban ghi hoa don
            IInvoice model = IInvSrv.Getbykey <IInvoice>(id);

            if (model.Status != InvoiceStatus.NewInv)
            {
                Messages.AddErrorFlashMessage("Không thể sửa hóa đơn này.");
                return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
            }
            //lay va doi danh sach cac san pham thanh doi tuong json
            //nếu Unit=null thì mặc định hiển thị ""
            foreach (var item in model.Products)
            {
                if (item.Unit == null)
                {
                    item.Unit = "";
                }
            }
            //lay ra danh sach cac serial
            List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);

            ViewData["ser"] = ser;
            //lay thong tin ve don vi ban hang
            ViewData["company"] = currentCom;
            model.Note          = "";
            return(View(ViewName, model));
        }
Пример #3
0
 public ActionResult ajxPreview(int idInvoice, string pattern)
 {
     try
     {
         Company         currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         IInvoiceService IInvSrv    = InvServiceFactory.GetService(pattern, currentCom.id);
         logtest.Info("call: " + idInvoice + " pattern: " + pattern + " company: " + currentCom.id);
         IInvoice oInvoice = IInvSrv.Getbykey <IInvoice>(idInvoice);
         //IViewer _iViewerSrv = IoC.Resolve<IViewer>();
         IViewer _iViewerSrv = InvServiceFactory.GetViewer(pattern, currentCom.id);
         if (oInvoice.Status != InvoiceStatus.NewInv)
         {
             IRepositoryINV _iRepoSrv = IoC.Resolve <IRepositoryINV>();
             byte[]         data      = _iRepoSrv.GetData(oInvoice);
             return(Json(new { invData = _iViewerSrv.GetHtml(data), status = oInvoice.Status }));
         }
         else
         {
             return(Json(new { invData = _iViewerSrv.GetHtml(System.Text.Encoding.UTF8.GetBytes(oInvoice.GetXMLData())), status = 0 }));
         }
     }
     catch (Exception ex)
     {
         logtest.Error(ex);
         return(Json(new { invData = "Có lỗi xảy ra, vui lòng thực hiện lại.", status = 0 }));
     }
 }
Пример #4
0
        public ActionResult Delete(string Pattern, int id)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            log.Debug("Access - Delete");
            Company         currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IInvoiceService IInvSrv    = InvServiceFactory.GetService(Pattern, currentCom.id);
            IInvoice        model      = IInvSrv.Getbykey <IInvoice>(id);

            try
            {
                string ErrorMessage = "";
                if (IInvSrv.DeleteInvoice(model, out ErrorMessage) == true)
                {
                    log.Info("Delete EInvoice by: " + HttpContext.User.Identity.Name + " Info-- ID: " + model.id + "Pattern: " + model.Pattern + " Serial: " + model.Serial + " SoHoaDon: " + model.No.ToString() + " TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount);
                    Messages.AddFlashMessage("Xóa hóa đơn thành công.");
                    log.Info("Delete successfull id =" + id);
                }
                else
                {
                    Messages.AddErrorFlashMessage(ErrorMessage);
                }
            }
            catch (Exception ex)
            {
                log.Error(" Delete-" + ex.Message);
            }
            return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
        }
Пример #5
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"));
     }
 }
Пример #6
0
        /// <summary>
        /// Doi trang thai hoa don
        /// status=2 den status=4
        /// </summary>
        /// <param name="pat"></param>
        /// <param name="seri"></param>
        /// <param name="invNo"></param>
        /// <returns></returns>
        public ActionResult adInv(string pat, string seri, string invNo)
        {
            Company         currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IInvoiceService IInvSrv    = InvServiceFactory.GetService(pat, currentCom.id);

            try
            {
                //sua lai
                decimal No;
                decimal.TryParse(invNo, out No); if (No == 0)
                {
                    No = -1;
                }
                IInvoice inv = IInvSrv.GetByNo(currentCom.id, pat, seri, Convert.ToDecimal(No));
                if (inv.Status == InvoiceStatus.SignedInv)
                {
                    return(Json(new
                    {
                        inv.Pattern,
                        inv.Serial
                    }));
                }
                else
                {
                    return(Json(""));
                }
            }
            catch (Exception ex)
            {
                log.Error(" adInv -:" + ex.Message);
                Messages.AddErrorFlashMessage(Resources.Message.AdjReInv_MInvalidInv);
                return(RedirectToAction("SearchInvAdjust"));
            }
        }
Пример #7
0
        public ActionResult ConvertForStore(int id, string patt)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            Company         currentCom  = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            user            currentUser = ((EInvoiceContext)FXContext.Current).CurrentUser;
            string          err;
            IInvoiceService InvSrv = InvServiceFactory.GetService(patt, currentCom.id);
            IInvoice        inv    = InvSrv.GetByID(currentCom.id, patt, id);

            if (inv.Status == InvoiceStatus.CanceledInv || inv.Status == InvoiceStatus.ReplacedInv)
            {
                return(Json("nosuccess"));
            }

            IStaffService _staSrv = IoC.Resolve <IStaffService>();
            Staff         staff   = _staSrv.SearchByAccountName(currentUser.username, currentCom.id);
            string        name    = "";

            if (null != staff)
            {
                name = staff.FullName;
            }
            string HtmlRet = InvSrv.ConvertForStore(inv, name, out err);

            if (err == string.Empty)
            {
                log.Info("Convert Invoice (Luu tru) By : " + HttpContext.User.Identity.Name + " Info-- Pattern: " + inv.Pattern + "   Serial: " + inv.Serial + "   No: " + inv.No);
                return(Json(HtmlRet));
            }
            return(Json("nosuccess"));
        }
Пример #8
0
 public ActionResult ReportLaunch(ReportsLaunchModel model)
 {
     try
     {
         Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         IPublishInvoiceService PubInvSrv  = IoC.Resolve <IPublishInvoiceService>();
         IList <string>         lstPattern = PubInvSrv.LstByPattern(currentCom.id, 2);
         if (lstPattern.Count == 0)
         {
             Messages.AddErrorFlashMessage("Thông báo phát hành chưa được chấp nhận hoặc chưa có hóa đơn.");
             return(Redirect("/"));
         }
         if (lstPattern.Count > 0)
         {
             if (string.IsNullOrEmpty(model.Pattern))
             {
                 model.Pattern = lstPattern[0];
                 IInvoiceService IInvSrv = InvServiceFactory.GetService(model.Pattern, currentCom.id);
             }
         }
         List <string> lstSerial = (from p in PubInvSrv.Query where (p.ComId == currentCom.id) && (p.InvPattern == model.Pattern) && (p.Status > 1) select p.InvSerial).Distinct().ToList <string>();
         model.lstPattern = new SelectList(lstPattern);
         model.lstSerial  = new SelectList(lstSerial);
         return(View(model));
     }
     catch (Exception ex)
     {
         Messages.AddErrorFlashMessage(ex.Message);
         return(RedirectToAction("Index", "Home"));
     }
 }
Пример #9
0
 private bool uploadfile(HttpPostedFileBase FileUpload, string idInv, string Pattern, string SerialNo, string NoInv, Company currentCom, string resultLauncher, out string mess)
 {
     try
     {
         if (FileUpload != null)
         {
             bool check = false;
             //get adjustid
             string[]        listResultLaunchera = resultLauncher.Split(';');
             string[]        listResultLauncherb = listResultLaunchera[2].ToString().Split('_');
             IInvoiceService IInvSrv             = InvServiceFactory.GetService(Pattern, currentCom.id);
             IInvoice        invoiceNew          = IInvSrv.GetByNo(currentCom.id, Pattern, listResultLaunchera[1].ToString(), Convert.ToDecimal(Convert.ToInt32(listResultLauncherb[1].ToString().Replace(',', ' '))));
             int             idadjust            = (from a in IoC.Resolve <IAdjustInvService>().Query where a.InvId == Convert.ToInt32(idInv) && a.AdjustInvId == invoiceNew.id select a.id).SingleOrDefault();
             //end
             RecordsInv         tbRecordsInv   = IoC.Resolve <IRecordsInvService>().Query.Where(idAdjust => idAdjust.id == Convert.ToInt32(idadjust)).FirstOrDefault();
             IRecordsInvService _SvcRecordsInv = IoC.Resolve <IRecordsInvService>();
             string             strPath        = "";
             string             strFullPath    = "";
             string             fileext        = (Path.GetExtension(FileUpload.FileName).Length > 1) ? Path.GetExtension(FileUpload.FileName).Substring(1) : "";
             if (fileext.ToLower() != "docx" && fileext.ToLower() != "pdf" && fileext.ToLower() != "doc")
             {
                 mess = "File biên bản hủy đính kèm không đúng định dạng !";
                 return(check);
             }
             strPath     = @"\RecordsInv\" + currentCom.id + @"\" + Pattern.Replace("/", "") + @"\" + SerialNo.Replace("/", "") + "_" + NoInv + "." + fileext;
             strFullPath = GetFullPathRecordsCancel(strPath);
             if (!string.IsNullOrEmpty(strFullPath))
             {
                 tbRecordsInv.InvPattern = Pattern;
                 tbRecordsInv.Path       = strPath;
             }
             _SvcRecordsInv.Update(tbRecordsInv);
             _SvcRecordsInv.CommitTran();
             if (!string.IsNullOrEmpty(strFullPath))
             {
                 FileUpload.SaveAs(strFullPath);
                 mess = "Upload biên bản thành công";
             }
             else
             {
                 mess = "Không upload biên bản thành công!";
             }
             return(true);
         }
         else
         {
             mess = "Không tồn tại file update!";
             return(false);
         }
     }
     catch (Exception ex)
     {
         mess = string.Format("Attach file RecordCancel: Pattern={0}, Serial={1}, NoInv={2}, Exception:{3}", Pattern, SerialNo, NoInv, ex.ToString());
         return(false);
     }
 }
Пример #10
0
        public bool LaunchCollectInvoice(string FromDate, string ToDate, string pattern, string serial)
        {
            DateTime?DateFrom = null;
            DateTime?DateTo   = null;

            if (!string.IsNullOrWhiteSpace(FromDate))
            {
                DateFrom = DateTime.ParseExact(FromDate, "dd/MM/yyyy", null);
            }
            if (!string.IsNullOrWhiteSpace(ToDate))
            {
                DateTo = DateTime.ParseExact(ToDate, "dd/MM/yyyy", null);
            }
            try
            {
                Company         currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                IInvoiceService IInvSrv    = InvServiceFactory.GetService(pattern, currentCom.id);
                // chỉ tìm NewInv
                int totalRecords             = 0;
                IList <IInvoice> listInvoice = IInvSrv.SearchInvoice(currentCom.id, pattern, serial, DateFrom, DateTo, 0, 0, out totalRecords, InvoiceStatus.NewInv);
                if (listInvoice.Count > 0)
                {
                    //edit phat hanh hoa don 03/07/2014
                    int[]  ids           = listInvoice.Select(c => c.id).ToArray();
                    string resultMessage = "";
                    LaunchInvoices.Instance.Launch(ids, pattern, serial, out resultMessage);
                    log.Info("Publish EInvoice by: " + HttpContext.User.Identity.Name + " Info-- Pattern: " + pattern + " Serial: " + serial + " SoLuongPhatHanh: " + listInvoice.Count.ToString());
                    if (resultMessage.Contains("OK"))
                    {
                        Messages.AddFlashMessage(resultMessage);
                    }
                    else if (resultMessage.Contains("ERR:14"))
                    {
                        Messages.AddErrorFlashMessage("Có lô hóa đơn khác đang được phát hành, xin vui lòng thực hiện lại.");
                    }
                    else
                    {
                        Messages.AddErrorFlashMessage(resultMessage);
                    }
                    log.Info("Launch Result: " + resultMessage);
                }
                else
                {
                    Messages.AddErrorFlashMessage("Không có hóa đơn mới tạo.");
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Messages.AddErrorFlashMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                log.Error(" LaunchCollectInvoice -:" + ex);
                return(false);
            }
        }
Пример #11
0
        public string confirmPaymentFkey(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERlR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            List <IInvoice> invLst = new List <IInvoice>();

            string[] invTokens = lsInv.lsFkey.Split('_');
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
            string pattern = "";

            if (pubinv != null)
            {
                pattern = pubinv.InvPattern;
                _PubInvSrv.UnbindSession(pubinv);
            }
            IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID);

            try
            {
                invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                if (invTokens.Length != invLst.Count)
                {
                    return("ERR:6");
                }
                invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Paid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
            }
            catch (Exception ex)
            {
                log.Error("confirmPaymentFkey " + ex);
                return("ERR:6 " + ex.Message);
            }
            if (invLst.Count == 0)
            {
                return("ERR:13");            // hoa đơn đã gạch nợ/bỏ gạch nợ rồi
            }
            string strNote = "    ||    Thực hiện gạch nợ:   Người gạch nợ: " + HttpContext.Current.User.Identity.Name + "  Ngày gạch nợ: " + DateTime.Now.ToString();

            if (invSrv.ConfirmPayment(invLst, strNote))
            {
                //thuc hien deliveriy
                IDeliver _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null;
                if (_deliver != null)
                {
                    _deliver.Deliver(invLst.ToArray(), _currentCompany);
                }
                return("OK:");
            }
            return("ERR:7"); //sao lai khong thanh toán được ?
        }
Пример #12
0
        public string deliverInv(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            try
            {
                List <IInvoice> invLst = new List <IInvoice>();
                //List<decimal> invNos = new List<decimal>();
                Dictionary <string, List <decimal> > patternAndNo = new Dictionary <string, List <decimal> >();
                string[] invTokens = lsInv.lstInvToken.Split('_');
                foreach (string invToken in invTokens)
                {
                    string  pattern;
                    string  serial;
                    decimal invNo;
                    string  rv = DataHelper.parseInvToken(invToken, out pattern, out serial, out invNo);
                    if (!rv.Equals("OK"))
                    {
                        return(rv);
                    }
                    if (!patternAndNo.ContainsKey(pattern + ";" + serial))
                    {
                        patternAndNo[pattern + ";" + serial] = new List <decimal>();
                    }
                    patternAndNo[pattern + ";" + serial].Add(invNo);
                }
                foreach (KeyValuePair <string, List <decimal> > i in patternAndNo)
                {
                    string[]        key         = i.Key.Split(';');
                    IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(key[0], comID);
                    invLst.AddRange(_iInvoicSrv.GetByNo(comID, key[0], key[1], i.Value.ToArray()));
                }
                if (invLst.Count != invTokens.Length)
                {
                    return("ERR:6");                                  //khong tim thay hoa don
                }
                ICompanyService _comSrv  = IoC.Resolve <ICompanyService>();
                Company         com      = _comSrv.Getbykey(comID);
                IDeliver        _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null;
                if (_deliver != null)
                {
                    _deliver.Deliver(invLst.ToArray(), com);
                }
            }
            catch (Exception ex)
            {
                log.Error("deliver: " + ex);
            }
            return("OK:");
        }
Пример #13
0
        public string publishInv(ApiPublish publish)
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            ILog    log        = LogManager.GetLogger(typeof(PublishController));

            if (!LockTable.Contains(String.Format("{0}${1}", publish.pattern, currentCom.id)))
            {
                object lockobj = new object();
                LockTable.Add(String.Format("{0}${1}", publish.pattern, currentCom.id), lockobj);
            }
            lock (LockTable[String.Format("{0}${1}", publish.pattern, currentCom.id)])
            {
                IDeliver         _DeliverService = currentCom.Config.ContainsKey("IDeliver") ? InvServiceFactory.GetDeliver(currentCom.Config["IDeliver"]) : null;
                IInvoiceService  IInvSrv         = InvServiceFactory.GetService(publish.pattern, currentCom.id);
                IList <IInvoice> lst             = IInvSrv.GetByID(currentCom.id, publish.invIDs).OrderBy(p => p.CreateDate).ToList();
                try
                {
                    if (lst.Count() <= 50)
                    {
                        Launcher.Instance.Launch(publish.pattern, publish.serial, lst.ToArray());
                    }
                    else
                    {
                        for (int i = 0; i < lst.Count() / 50; i++)
                        {
                            Launcher.Instance.Launch(publish.pattern, publish.serial, lst.Skip(i * 50).Take(50).ToArray());
                        }
                    }
                    try
                    {
                        if (_DeliverService != null)
                        {
                            _DeliverService.PrepareDeliver(lst.ToArray(), currentCom);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                    return("OK");
                }
                catch (EInvoice.Core.Launching.NoFactory.OpenTranException ex)
                {
                    log.Error(ex);
                    return("ERR:14");
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    return("ERR:5 " + ex.Message);//loi phat hanh hoa don
                }
            }
        }
Пример #14
0
        public ActionResult CancelInvApprove(string[] cbeinv, string hdPattern, string Serial)
        {
            Company         currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IInvoiceService IInvSrv    = InvServiceFactory.GetService(hdPattern, currentCom.id);

            try
            {
                int[] invIds = (from s in cbeinv select Convert.ToInt32(s)).ToArray();
                if (invIds.Length < 0)
                {
                    Messages.AddErrorMessage("Bạn chưa chọn hóa đơn để hủy.");
                    return(RedirectToAction("CancelInvNotReIndex", new { Pattern = hdPattern, Serial = Serial }));
                }
                ILogSystemService businessLog = IoC.Resolve <ILogSystemService>();
                IList <IInvoice>  invLst      = IInvSrv.GetByID(currentCom.id, invIds);
                int succCount = 0;
                IInvSrv.BeginTran();
                var context = (EInvoiceContext)FXContext.Current;
                foreach (var item in invIds)
                {
                    IInvoice Oinvoice = IInvSrv.GetByID(currentCom.id, hdPattern, item);
                    if (Oinvoice.Status == InvoiceStatus.CanceledInv || Oinvoice.Status == InvoiceStatus.ReplacedInv || Oinvoice.Status == InvoiceStatus.AdjustedInv)
                    {
                        continue;
                    }
                    succCount++;
                    Oinvoice.Status = InvoiceStatus.CanceledInv;
                    Oinvoice.Note  += "  || Thực hiện hủy Hóa đơn (Không thay thế):   Người hủy:" + context.CurrentUser.username + "   Ngày hủy:" + DateTime.Now.ToString();
                    IInvSrv.Update(Oinvoice);
                    log.Info("INVCANCEL_" + context.CurrentUser.username + "_" + hdPattern + "_" + Oinvoice.Serial + "_" + Oinvoice.No + "_" + DateTime.Now);
                    businessLog.WriteLogCancel(currentCom.id, context.CurrentUser.username, Oinvoice.Pattern, Oinvoice.Serial, Oinvoice.No.ToString("0000000"), Oinvoice.ArisingDate, Oinvoice.Amount, Oinvoice.CusName, Oinvoice.CusAddress, Oinvoice.CusCode, Oinvoice.CusTaxCode, BusinessLogType.Cancel);
                }
                if (succCount == 0)
                {
                    Messages.AddErrorFlashMessage("Kiểm tra lại hóa đơn hủy, có thể đã được thanh toán hoặc sửa đổi.");
                }
                else
                {
                    IInvSrv.CommitTran();
                    Messages.AddFlashMessage("Tổng số hóa đơn hủy là:" + succCount);
                }
                return(RedirectToAction("CancelInvNotReIndex", new { Pattern = hdPattern, Serial = Serial }));
            }
            catch (Exception ex)
            {
                Messages.AddErrorFlashMessage("Có lỗi trong quá trình xử lý, vui lòng thực hiện lại!");
                log.Error(" CancelInvApprove -" + ex.Message);
                IInvSrv.RolbackTran();
                return(RedirectToAction("CancelInvNotReIndex", new { Pattern = hdPattern, Serial = Serial }));
            }
        }
Пример #15
0
 public ActionResult LaunchChoiceByPlugin(string cbid, string Pattern, string Serial, string certificate)
 {
     try
     {
         string[] idsStr = cbid.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
         int[]    ids    = (from s in idsStr select Convert.ToInt32(s)).ToArray();
         if (ids.Length < 0)
         {
             return(Json("ERROR:1"));
         }
         Company          currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         byte[]           raw            = Convert.FromBase64String(certificate);
         X509Certificate2 x509Cert       = new X509Certificate2(raw);
         KeyStores        _keyStore      = KeyStoresManagement.GetKeyStore(currentCompany.id);
         if (_keyStore == null)
         {
             log.Error("keyStores invalid");
             return(Json("ERROR:2"));
         }
         string serial4Keystore = _keyStore.SerialCert.TrimEnd().ToUpper();
         string serial4X509Cert = x509Cert.GetSerialNumberString().TrimEnd().ToUpper();
         if (serial4Keystore.CompareTo(serial4X509Cert) != 0)
         {
             log.Error("1|" + _keyStore.SerialCert.ToUpper());
             log.Error("2|" + x509Cert.GetSerialNumberString().ToUpper());
             return(Json("ERROR:2"));
         }
         if (DateTime.Parse(x509Cert.GetExpirationDateString()) < DateTime.Today)
         {
             return(Json("ERROR:3"));
         }
         IInvoiceService              IInvSrv       = InvServiceFactory.GetService(Pattern, currentCompany.id);
         IInvoice[]                   invoicesByIds = IInvSrv.GetByID(currentCompany.id, ids).OrderBy(p => p.id).ToArray();
         IList <InvoiceForPlugin>     data          = new List <InvoiceForPlugin>();
         IDictionary <string, string> dictHash      = EInvoice.Core.Launching.Launcher.Instance.GetDigestForRemote(Pattern, Serial, invoicesByIds, x509Cert);
         foreach (KeyValuePair <string, string> pair in dictHash)
         {
             data.Add(new InvoiceForPlugin()
             {
                 Key = pair.Key, Hash = pair.Value
             });
         }
         IInvSrv.UnbindSession();
         return(Json(new { hashdata = data }));
     }
     catch (Exception ex)
     {
         log.Error(ex);
         return(Json("ERROR:4"));
     }
 }
Пример #16
0
        //private void UpdateNode(IInvoice invoiceVat, IInvoiceService IInvSrv, int style)
        //{
        //    if (style == 0)
        //    {
        //        invoiceVat.Note += "||   Hóa đơn bị điều chỉnh:  bởi: " + HttpContext.User.Identity.Name + "    Thời gian điều chỉnh:" + DateTime.Now.ToString();
        //    }
        //    else
        //    {
        //        invoiceVat.Note += "||   Hóa đơn bị thay thế:  bởi: " + HttpContext.User.Identity.Name + " Thời gian thay thế: " + DateTime.Now.ToString();
        //    }
        //    IInvSrv.Update(invoiceVat);
        //    IInvSrv.CommitChanges();
        //}

        private void UpdateNode(int comid, string pattern, string serial, string no, int style)
        {
            IInvoiceService _IInvService = InvServiceFactory.GetService(pattern, comid);
            IInvoice        Oriinv       = _IInvService.GetByNo(comid, pattern, serial, Convert.ToDecimal(no));

            if (style == 0)
            {
                Oriinv.Note += "||   Hóa đơn bị điều chỉnh:  bởi: " + HttpContext.User.Identity.Name + "    Thời gian điều chỉnh:" + DateTime.Now.ToString();
            }
            else
            {
                Oriinv.Note += "||   Hóa đơn bị thay thế:  bởi: " + HttpContext.User.Identity.Name + " Thời gian thay thế: " + DateTime.Now.ToString();
            }
            _IInvService.Update(Oriinv);
            _IInvService.CommitChanges();
        }
Пример #17
0
        public ActionResult UpdateCoupon(string Pattern, int id)
        {
            if (id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            ICompanyService        comSrv     = IoC.Resolve <ICompanyService>();
            Company                currentCom = comSrv.Getbykey(((EInvoiceContext)FXContext.Current).CurrentCompany.id);
            IPublishInvoiceService _PubIn     = IoC.Resolve <IPublishInvoiceService>();
            IRegisterTempService   _ReTemSvc  = IoC.Resolve <IRegisterTempService>();
            IInvoiceService        IInvSrv    = InvServiceFactory.GetService(Pattern, currentCom.id);
            IInvoice               model      = IInvSrv.Getbykey <IInvoice>(id);
            string NoteOrder = model.Note;

            try
            {
                TryUpdateModelFromType(model.GetType(), model);
                model.Note = NoteOrder + " || " + model.Note;
                IInvSrv.Update(model);
                IInvSrv.CommitChanges();
                log.Info("Edit EInvoice by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + model.CusName + " MaKhachHang: " + model.CusCode + " SoTien: " + model.Amount);
                Messages.AddFlashMessage("Sửa phiếu thu thành công.");
                return(RedirectToAction("Index", new { Pattern = Pattern, Serial = model.Serial }));
            }
            catch (HttpRequestValidationException ex)
            {
                log.Error("ArgumentException: " + ex);
                Messages.AddErrorMessage("Dữ liệu không hợp lệ hoặc có chứa mã gây nguy hiểm tiềm tàng cho hệ thống!");
                model = IInvSrv.Getbykey <IInvoice>(id);
                List <string> ser = _PubIn.GetSerialByPatter(Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
            catch (Exception ex)
            {
                log.Error("Edit -", ex);
                model.Name = _ReTemSvc.SeachNameInv(Pattern, currentCom.id);
                List <string> ser = _PubIn.GetSerialByPatter(model.Pattern, currentCom.id);
                ViewData["ser"]     = ser;
                ViewData["company"] = currentCom;
                Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại.");
                string ViewName = InvServiceFactory.GetView(Pattern, currentCom.id) + "Edit";
                return(View(ViewName, model));
            }
        }
Пример #18
0
        public string UnConfirmPaymentFkey(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            List <IInvoice> invLst = new List <IInvoice>();

            string[] invTokens = lsInv.lsFkey.Split('_');
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
            PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
            string pattern = "";

            if (pubinv != null)
            {
                pattern = pubinv.InvPattern;
                _PubInvSrv.UnbindSession(pubinv);
            }
            IInvoiceService invSrv = InvServiceFactory.GetService(pattern, comID);

            try
            {
                invLst = (List <IInvoice>)invSrv.GetByFkey(comID, invTokens);
                if (invTokens.Length != invLst.Count)
                {
                    return("ERR:6");
                }
                invLst.RemoveAll(inv => inv.PaymentStatus == Payment.Unpaid || (inv.Status != InvoiceStatus.SignedInv && inv.Status != InvoiceStatus.AdjustedInv));
            }
            catch (Exception ex)
            {
                log.Error("UnConfirmPaymentFkey " + ex);
                return("ERR:6 " + ex.Message);
            }
            if (invLst.Count == 0)
            {
                return("ERR:13");            // hoa đơn đã gạch nợ/bỏ gạch nợ rồi
            }
            if (invSrv.UnConfirmPayment(invLst))
            {
                return("OK:");
            }
            return("ERR:7"); //sao lai khong bo thanh toán được ?
        }
Пример #19
0
        public IHttpActionResult convertForVerify(DataAPI portal)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return(Unauthorized());                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            string invPattern = null, invSerial = null;

            getPublishInvoice(portal.pattern, _currentCompany.id, out invPattern, out invSerial);
            if (string.IsNullOrWhiteSpace(invPattern))
            {
                return(Ok("ERR:20"));
            }
            IInvoiceService _iInvoicSrv  = InvServiceFactory.GetService(invPattern, comID);
            IInvoice        oInvoiceBase = InvServiceFactory.NewInstance(invPattern, comID);

            if (portal.invNo > 0)
            {
                oInvoiceBase = _iInvoicSrv.GetByNo(comID, invPattern, invSerial, portal.invNo);
            }
            else
            {
                oInvoiceBase = _iInvoicSrv.GetByFkey(comID, portal.fkey);
            }
            if (null == oInvoiceBase)
            {
                return(Ok <string>("ERR:6"));     //không tìm thấy hóa đơn
            }
            //lay html
            IRepositoryINV _repository = IoC.Resolve <IRepositoryINV>();

            byte[] invdata = _repository.GetData(oInvoiceBase);
            string err     = "";
            string rv      = _iInvoicSrv.ConvertForVerify(oInvoiceBase, "", out err);

            if (string.IsNullOrEmpty(rv) && !string.IsNullOrEmpty(err))
            {
                return(Ok <string>("ERR:8")); //hóa đơn đã convert rồi
            }
            return(Ok <string>(rv));
        }
Пример #20
0
        public void Launch(int[] invIds, string pattern, string Serial, out string Messages)
        {
            Company         currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IInvoiceService IInvSrv    = InvServiceFactory.GetService(pattern, currentCom.id);

            Messages = "";
            if (!LockTable.Contains(String.Format("{0}${1}", pattern, currentCom.id)))
            {
                object lockobj = new object();
                LockTable.Add(String.Format("{0}${1}", pattern, currentCom.id), lockobj);
            }
            lock (LockTable[String.Format("{0}${1}", pattern, currentCom.id)])
            {
                IList <IInvoice> lst       = IInvSrv.GetByID(currentCom.id, invIds).OrderBy(p => p.ArisingDate).ToList();
                ILauncherService _launcher = IoC.Resolve(Type.GetType(currentCom.Config["LauncherType"])) as ILauncherService;
                _launcher.PublishInv(pattern, Serial, lst.ToArray(), HttpContext.Current.User.Identity.Name);
                Messages = _launcher.Message;
            }
        }
Пример #21
0
        public string deliverInvFkey(ListInvoice lsInv)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            try
            {
                List <IInvoice>        invLst     = new List <IInvoice>();
                string[]               invTokens  = lsInv.lsFkey.Split('_');
                IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();
                PublishInvoice         pubinv     = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
                string pattern = "";
                if (pubinv != null)
                {
                    pattern = pubinv.InvPattern;
                    _PubInvSrv.UnbindSession(pubinv);
                }
                IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(pattern, comID);
                invLst = (List <IInvoice>)_iInvoicSrv.GetByFkey(comID, invTokens);

                if (invLst.Count != invTokens.Length)
                {
                    return("ERR:6");                                  //khong tim thay hoa don
                }
                ICompanyService _comSrv  = IoC.Resolve <ICompanyService>();
                Company         com      = _comSrv.Getbykey(comID);
                IDeliver        _deliver = _currentCompany.Config.Keys.Contains("IDeliver") ? IoC.Resolve(Type.GetType(_currentCompany.Config["IDeliver"])) as IDeliver : null;
                if (_deliver != null)
                {
                    _deliver.Deliver(invLst.ToArray(), com);
                }
            }
            catch (Exception ex)
            {
                log.Error("deliver: " + ex);
            }
            return("OK:");
        }
Пример #22
0
        public ActionResult WrapReplaceInvoices(string key, string signed, string pattern, string serial, string no)
        {
            try
            {
                Company currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                IDictionary <string, byte[]> dictInv = new Dictionary <string, byte[]>();
                dictInv.Add(key, Convert.FromBase64String(signed));

                IInvoiceService invSrv = InvServiceFactory.GetService(pattern, currentCompany.id);
                IInvoice        OriInv = invSrv.GetByNo(currentCompany.id, pattern, serial, decimal.Parse(no));
                IInvoice        p      = EInvoice.Core.Launching.Launcher.Instance.ReplaceRemote(OriInv, pattern, serial, dictInv);

                return(Json("OK"));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Json("Lỗi: Chưa  thay thế được hóa đơn, vui lòng thực hiện lại."));
            }
        }
Пример #23
0
        public ActionResult WriteNote(string Pattern, int id, string TypeView)
        {
            Company         currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IInvoiceService IInvSrv    = InvServiceFactory.GetService(Pattern, currentCom.id);
            IInvoice        Einv       = IInvSrv.Getbykey <IInvoice>(id);
            //thong tin view model
            WriteNoteModel model = new WriteNoteModel();

            model.id       = id;
            model.pattern  = Pattern;
            model.TypeView = TypeView;
            if (string.IsNullOrEmpty(Einv.Note))
            {
                model.Note = "";
            }
            else
            {
                model.Note = Einv.Note;
            }
            return(View(model));
        }
Пример #24
0
        public IHttpActionResult convertForStore(DataAPI portal)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return(Unauthorized());                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            string invPattern = null, invSerial = null;

            getPublishInvoice(portal.pattern, _currentCompany.id, out invPattern, out invSerial);
            if (string.IsNullOrWhiteSpace(invPattern))
            {
                return(Ok("ERR:20"));
            }
            IInvoiceService _iInvoicSrv = InvServiceFactory.GetService(invPattern, comID);
            IInvoice        currentInv  = InvServiceFactory.NewInstance(invPattern, comID);

            if (portal.invNo > 0)
            {
                currentInv = _iInvoicSrv.GetByNo(comID, invPattern, invSerial, portal.invNo);
            }
            else
            {
                currentInv = _iInvoicSrv.GetByFkey(comID, portal.fkey);
            }
            if (null == currentInv)
            {
                return(NotFound());
            }
            //lay html
            IRepositoryINV _repository = IoC.Resolve <IRepositoryINV>();

            byte[] invdata = _repository.GetData(currentInv);
            string err     = "";
            string rv      = _iInvoicSrv.ConvertForStore(currentInv, "", out err);

            return(Ok <string>(rv));
        }
Пример #25
0
 public IHttpActionResult RemoteCancel(RemoteInvoice data)
 {
     try
     {
         Company  currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
         XElement elem           = XElement.Parse(data.InvData);
         IEnumerable <XElement>       listTemp = elem.Elements("key");
         IDictionary <string, byte[]> dictInv  = new Dictionary <string, byte[]>();
         IInvoiceService   IInvSrv             = InvServiceFactory.GetService(data.InvPattern, currentCompany.id);
         var               context             = (EInvoiceContext)FXContext.Current;
         ILogSystemService businessLog         = IoC.Resolve <ILogSystemService>();
         int               succCount           = 0;
         foreach (var item in listTemp)
         {
             IInvoice Oinvoice = IInvSrv.GetByFkey(currentCompany.id, item.Value);
             if (Oinvoice == null || Oinvoice.Status == InvoiceStatus.CanceledInv || Oinvoice.Status == InvoiceStatus.ReplacedInv || Oinvoice.Status == InvoiceStatus.AdjustedInv)
             {
                 continue;
             }
             succCount++;
             Oinvoice.Status = InvoiceStatus.CanceledInv;
             Oinvoice.Note  += "  || Thực hiện hủy Hóa đơn (Không thay thế):   Người hủy:" + context.CurrentUser.username + "   Ngày hủy:" + DateTime.Now.ToString();
             IInvSrv.Update(Oinvoice);
             businessLog.WriteLogCancel(currentCompany.id, context.CurrentUser.username, Oinvoice.Pattern, Oinvoice.Serial, Oinvoice.No.ToString("0000000"), Oinvoice.ArisingDate, Oinvoice.Amount, Oinvoice.CusName, Oinvoice.CusAddress, Oinvoice.CusCode, Oinvoice.CusTaxCode, BusinessLogType.Cancel);
         }
         if (succCount == 0)
         {
             return(Ok <string>("ERROR:Kiểm tra lại hóa đơn hủy, có thể đã được thanh toán hoặc sửa đổi."));
         }
         else
         {
             IInvSrv.CommitTran();
             return(Ok <string>("OK:Tổng số hóa đơn hủy là:" + succCount));
         }
     }
     catch (Exception ex)
     {
         return(Ok("ERROR"));
     }
 }
Пример #26
0
        public ActionResult PaymentInvoice(string[] cbid, string hdPattern)
        {
            try
            {
                Company _currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                int[]   _IDs        = (from _s in cbid select Convert.ToInt32(_s)).ToArray();
                if (_IDs.Length <= 0)
                {
                    Messages.AddErrorFlashMessage("Chưa chọn hóa đơn thanh toán.");
                    return(RedirectToAction("Index"));
                }
                IInvoiceService  _IInSrv     = InvServiceFactory.GetService(hdPattern, _currentCom.id);
                IList <IInvoice> _lstInvoice = _IInSrv.GetByID(_currentCom.id, _IDs);

                _IInSrv.BeginTran();
                foreach (IInvoice item in _lstInvoice)
                {
                    if (item.PaymentStatus == Payment.Paid)
                    {
                        item.PaymentStatus = Payment.Unpaid;
                        item.Note         += " || Thực hiện bỏ gạch nợ: người thực hiện " + HttpContext.User.Identity.Name + " ngày thực hiện " + DateTime.Now;
                        _IInSrv.Save(item);
                    }
                }
                _IInSrv.CommitTran();
                log.Info("PaymentInvoice by: " + HttpContext.User.Identity.Name + " Info-- cbid: " + cbid);
                Messages.AddFlashMessage("Chuyển trạng thái thành công!");
                return(RedirectToAction("Index", new { Pattern = hdPattern }));
            }
            catch (Exception ex)
            {
                log.Error("PaymentInvoice-" + ex);
                Messages.AddErrorFlashMessage("Có lỗi trong quá trình xử lý, vui lòng thực hiện lại!");
                return(RedirectToAction("Index", new { Pattern = hdPattern }));
            }
        }
Пример #27
0
        public ActionResult PaymentInvoice(string[] cbid, string hdPattern)
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;

            int[] IDs = (from s in cbid select Convert.ToInt32(s)).ToArray();
            if (IDs.Length <= 0)
            {
                Messages.AddErrorFlashMessage("Chưa chọn hóa đơn thanh toán.");
                return(RedirectToAction("Index"));
            }
            IInvoiceService  IInvSrv    = InvServiceFactory.GetService(hdPattern, currentCom.id);
            string           strNote    = "Thực hiện gạch nợ:   Người gạch nợ: " + HttpContext.User.Identity.Name + "  Ngày gạch nợ: " + DateTime.Now.ToString();
            IList <IInvoice> lstInvoice = IInvSrv.GetByID(currentCom.id, IDs);

            if (IInvSrv.ConfirmPayment(lstInvoice, strNote))
            {
                Messages.AddFlashMessage(Resources.Message.Pay_MesSuccess);
                //if (currentCom.Config.Keys.Contains("PaymentToDeliver"))
                //    if (currentCom.Config["PaymentToDeliver"] == "1")
                //    {
                //        //IDeliver _deliver = IoC.Resolve<IDeliver>();
                //        if (currentCom.Config.Keys.Contains("IDeliver"))
                //            _deliver = InvServiceFactory.GetDeliver(currentCom.Config["IDeliver"]);
                //        else _deliver = IoC.Resolve<IDeliver>();
                //        _deliver.Deliver(lstInvoice.ToArray(), currentCom);
                //    }
                log.Info("Change Payment Status EInvoice by: " + HttpContext.User.Identity.Name + " Info-- ID: " + string.Join(";", IDs));
                return(RedirectToAction("Index"));
            }
            else
            {
                log.Error("Change Payment Status EInvoice error: " + Resources.Message.Pay_MesUnsuccess);
                Messages.AddErrorFlashMessage(Resources.Message.Pay_MesUnsuccess);
                return(RedirectToAction("Index"));
            }
        }
Пример #28
0
        public ActionResult WriteNote(WriteNoteModel model)
        {
            if (model.id <= 0)
            {
                throw new HttpRequestValidationException();
            }
            Company         currentCom       = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            IInvoiceService IInvSrv          = InvServiceFactory.GetService(model.pattern, currentCom.id);
            IInvoice        EInvoiceEditNote = IInvSrv.Getbykey <IInvoice>(model.id);

            try
            {
                EInvoiceEditNote.Note = model.Note;
                IInvSrv.Save(EInvoiceEditNote);
                IInvSrv.CommitChanges();
                log.Info("Writenote EInvoice by: " + HttpContext.User.Identity.Name);
                Messages.AddFlashMessage("Ghi chú thành công!");
            }
            catch (Exception ex)
            {
                log.Error(" WriteNote-" + ex.Message);
                Messages.AddErrorFlashMessage("Ghi chú không thành công!");
            }
            if (model.TypeView == "0")
            {
                return(RedirectToAction("Index", new { Pattern = model.pattern, Serial = EInvoiceEditNote.Serial }));
            }
            else if (model.TypeView == "1")
            {
                return(RedirectToAction("ReplaceInvIndex", "Adjust", new { pattern = model.pattern, Serial = EInvoiceEditNote.Serial }));
            }
            else
            {
                return(RedirectToAction("AdjustInvIndex", "Adjust", new { pattern = model.pattern, Serial = EInvoiceEditNote.Serial }));
            }
        }
Пример #29
0
        public ActionResult Certifies(string[] cbid, string cpattern, int ctype)
        {
            Company currentCom = ((EInvoiceContext)FXContext.Current).CurrentCompany;

            try
            {
                EInvoice.Core.Launching.ICertifyProvider certifySrv = new EInvoice.Core.Launching.TaxCertifyProvider();
                IInvoiceService IInvSrv = InvServiceFactory.GetService(cpattern, currentCom.id);
                int[]           ids     = (from s in cbid select Convert.ToInt32(s)).ToArray();
                if (ids.Length < 0)
                {
                    Messages.AddErrorFlashMessage("Bạn chưa chọn hóa đơn ký.");
                    return(RedirectToAction("Index", new { pattern = cpattern }));
                }
                IList <IInvoice> lst = IInvSrv.GetByID(currentCom.id, ids);
                var rl = certifySrv.Certify(cpattern, lst, currentCom);

                if (!string.IsNullOrWhiteSpace(rl))
                {
                    Messages.AddErrorFlashMessage("Có lỗi trong quá trình xác thực, vui lòng thực hiện lại.");
                }
                else
                {
                    log.Info("Certifies by:" + HttpContext.User.Identity.Name + ", Date: " + DateTime.Now);
                    Messages.AddFlashMessage("Xác thực thành công.");
                }

                return(RedirectToAction("Index", new { pattern = cpattern }));
            }
            catch (Exception ex)
            {
                Messages.AddErrorFlashMessage("Có lỗi trong quá trình xử lý, vui lòng thực hiện lại.");
                log.Error("Certifies", ex);
                return(RedirectToAction("Index", new { pattern = cpattern }));
            }
        }
Пример #30
0
        private string processCancelInv(string fkey, string pattern = null, string serial = null, decimal invNo = 0)
        {
            Company _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            int     comID           = _currentCompany.id;

            if (_currentCompany == null)
            {
                return("ERR:7");                        //username khong phu hop - ko tim thay company phu hop voi [username]
            }
            int isPattern = string.IsNullOrEmpty(pattern) ? 0 : 1;
            IPublishInvoiceService _PubInvSrv = IoC.Resolve <IPublishInvoiceService>();

            switch ((isPattern))
            {
            case 0:
                PublishInvoice pubinv = _PubInvSrv.GetFirst(comID, new int[] { 1, 2 });
                if (pubinv != null)
                {
                    pattern = pubinv.InvPattern;
                    serial  = pubinv.InvSerial;
                    _PubInvSrv.UnbindSession(pubinv);
                }
                else
                {
                    return("ERR:20");     //tham so pattern va serial khong hop le
                }
                break;

            case 1:
                PublishInvoice pubFirst = _PubInvSrv.GetbyPattern(comID, pattern, new int[] { 1, 2 }).FirstOrDefault();
                if (pubFirst == null)
                {
                    return("ERR:20");
                }
                else
                {
                    serial = !string.IsNullOrWhiteSpace(serial) ? serial : pubFirst.InvSerial;
                    _PubInvSrv.UnbindSession(pubFirst);
                }
                break;
            }
            IInvoiceService iinvSrc = InvServiceFactory.GetService(pattern, comID);

            try
            {
                IInvoice currentInv = InvServiceFactory.NewInstance(pattern, comID);
                if (invNo > 0)
                {
                    currentInv = iinvSrc.GetByNo(comID, pattern, serial, invNo);
                }
                else
                {
                    currentInv = iinvSrc.GetByFkey(comID, fkey);
                }
                if (null == currentInv)
                {
                    return("ERR:2");  //khong ton tai hoa don
                }
                Launcher t = Launcher.Instance;
                t.Cancel(new IInvoice[] { currentInv });
                ILogSystemService businessLog = IoC.Resolve <ILogSystemService>();
                businessLog.WriteLogCancel(comID, HttpContext.Current.User.Identity.Name, currentInv.Pattern, currentInv.Serial, currentInv.No.ToString("0000000"), currentInv.PublishDate, currentInv.Amount, currentInv.CusName, currentInv.CusAddress, currentInv.CusCode, currentInv.CusTaxCode, BusinessLogType.Cancel);
                businessLog.CommitChanges();
                return("OK:");
            }
            catch (Exception ex)
            {
                log.Error("cancelInv " + ex);
                return("ERR:6 " + ex.Message);
            }
        }