Ejemplo n.º 1
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);
            }
        }