예제 #1
0
 public ActionResult SearchPost(CSPRF cSPRF)
 {
     Session["SearchPRFRec"]  = cSPRF;
     Session["SearchPRFSort"] = Request.Params["SORTBY"] ?? "VDATE";
     return(Redirect("?page=1"));
     //return Index(1);
 }
예제 #2
0
        // GET: CSPRFs/Delete/5
        public ActionResult Delete(string id, int?page)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CSPRF cSPRF = db.CSPRFs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            if (cSPRF == null)
            {
                return(HttpNotFound());
            }

            int refcnt = cSPRF.refcnt;

            if (refcnt > 0)
            {
                ModelState.AddModelError(string.Empty, refcnt.ToString() + " Details has been touched. Cannot Delete record");
            }
            ViewBag.page         = page ?? 1;
            Session["CSPRFPage"] = ViewBag.page;

            ViewBag.CONO     = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSPRF.CONO);
            ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSPRF.ATTN);
            ViewBag.COADDR   = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { COADDR = x.CONO + "|" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSPRF.COADDR);
            ViewBag.DETAILS  = db.CSBILLs.Where(x => x.PRFNO == cSPRF.PRFNO);
            ViewBag.CONAME   = db.CSCOMSTRs.Where(x => x.CONO == cSPRF.CONO).Select(y => y.CONAME).FirstOrDefault();
            ViewBag.Title    = "Delete Proforma Bill " + cSPRF.PRFNO;
            return(View("Edit", cSPRF));
        }
예제 #3
0
        public ActionResult Proforma(string id)
        {
            string sid   = MyHtmlHelpers.ConvertByteStrToId(id);
            CSPRF  cSPRF = getProforma(sid);

            //string html = RenderViewToString(ControllerContext, "~/views/CSPRFs/Proforma.cshtml", cSPRF, true);

            //EmailFormModel model = new WebApplication1.EmailFormModel();
            //model.Message = html;
            //model.FromEmail = "*****@*****.**";
            //model.FromName = "my tester";

            //var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
            //var message = new MailMessage();
            //message.To.Add(new MailAddress("*****@*****.**")); //replace with valid value
            //message.Subject = "Your email subject";
            //message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
            //message.IsBodyHtml = true;
            //using (var smtp = new SmtpClient())
            //{
            //    smtp.Send(message);
            //
            //}

            return(View(cSPRF));
        }
예제 #4
0
        public ActionResult DeleteConfirmed(string id)
        {
            CSPRF cSPRF = db.CSPRFs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            db.CSPRFs.Remove(cSPRF);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #5
0
        public ActionResult Create([Bind(Include = "PRFNO,VDATE,DUEDAYS,DUEDATE,CONO,COADDRID,ATTN,REM,SEQNO,INVALLOC,INVNO,INVID,STAMP")] CSPRF cSPRF)
        {
            if (ModelState.IsValid)
            {
                db.CSPRFs.Add(cSPRF);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CONO = new SelectList(db.CSCOADDRs, "CONO", "MAILADDR", cSPRF.CONO);
            return(View(cSPRF));
        }
예제 #6
0
        // GET: CSPRFs/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CSPRF cSPRF = db.CSPRFs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            if (cSPRF == null)
            {
                return(HttpNotFound());
            }
            return(View(cSPRF));
        }
예제 #7
0
        public ActionResult Edit([Bind(Include = "PRFNO,VDATE,DUEDAYS,DUEDATE,CONO,COADDRID,ATTN,REM,SEQNO,INVALLOC,INVNO,INVID,STAMP")] CSPRF cSPRF)
        {
            if (ModelState.IsValid)
            {
                db.Entry(cSPRF).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.CONO     = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSPRF.CONO);
            ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSPRF.ATTN);
            ViewBag.COADDR   = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { COADDR = x.CONO + "-" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSPRF.COADDR);

            return(View(cSPRF));
        }
예제 #8
0
        public ActionResult EditCompany(CSPRF cSPRF)
        {
            //ModelState.Clear(); //apparent this has side-effects and using Remove is preferrable
            ModelState.Remove("CONO");
            ModelState.Remove("ATTN");
            ModelState.Remove("COADDR");

            cSPRF.COADDR = null;
            cSPRF.ATTN   = null;

            //ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSCODE = x.PRSCODE, PRSDESC= x.CSPR.PRSNAME + " | " + x.DESIG }).OrderBy(y => y.PRSDESC), "PRSCODE", "PRSDESC", cSPRF.ATTN);
            ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSPRF.ATTN);
            ViewBag.COADDR   = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { COADDR = x.CONO + "|" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSPRF.COADDR);
            return(PartialView("Partial/EditCompany", cSPRF));
        }
예제 #9
0
        public async Task <ActionResult> Email(string id)
        {
            string sid   = MyHtmlHelpers.ConvertByteStrToId(id);
            CSPRF  cSPRF = getProforma(sid);


            string html = RenderViewToString(ControllerContext, "~/views/CSPRFs/Proforma.cshtml", cSPRF, true);

            EmailFormModel model = new WebApplication1.EmailFormModel();

            model.Message   = html;
            model.FromEmail = "*****@*****.**";
            model.FromName  = "ASI Secretary";

            var body    = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
            var message = new MailMessage();

            message.To.Add(new MailAddress(cSPRF.CSCOMSTR.WEB)); //replace with valid value
            message.Subject    = "Proforma Billing " + cSPRF.PRFNO;
            message.Body       = string.Format(body, model.FromName, model.FromEmail, model.Message);
            message.IsBodyHtml = true;
            using (var smtp = new SmtpClient())
            {
                await smtp.SendMailAsync(message);

                return(RedirectToAction("Sent", "Home"));
            }


            //var credential = new NetworkCredential
            //{
            //    UserName = "******",  // replace with valid value
            //    Password = "******"  // replace with valid value
            //};
            //smtp.Credentials = credential;
            //smtp.Host = "smtp-mail.outlook.com";
            //smtp.Port = 587;
            //smtp.EnableSsl = true;
            //await smtp.SendMailAsync(message);
            //return RedirectToAction("Sent");



            return(View("Proforma", cSPRF));
        }
예제 #10
0
        // GET: CSPRFs/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CSPRF cSPRF = db.CSPRFs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            if (cSPRF == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CONO     = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSPRF.CONO);
            ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSPRF.ATTN);
            ViewBag.COADDR   = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { COADDR = x.CONO + "-" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSPRF.COADDR);

            return(View(cSPRF));
        }
예제 #11
0
        // GET: CSPRFs/Create
        public ActionResult Create()
        {
            CSPRF cSPRF = new CSPRF();

            cSPRF.VDATE    = DateTime.Today;
            cSPRF.DUEDAYS  = 0;
            cSPRF.INVALLOC = "N";
            cSPRF.DUEDATE  = cSPRF.VDATE;
            cSPRF.CONO     = "750059-M"; // hack to show first company jobs

            ViewBag.page         = 1;
            Session["CSPRFPage"] = ViewBag.page;
            ViewBag.CONO         = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSPRF.CONO);
            ViewBag.ATTNDESC     = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSPRF.ATTN);
            ViewBag.COADDR       = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { COADDR = x.CONO + "|" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSPRF.COADDR);

            ViewBag.Title = "Create Proforma Bill";
            return(View("Edit", cSPRF));
        }
예제 #12
0
        public ActionResult DeleteConfirmed(string id)
        {
            CSPRF cSPRF = db.CSPRFs.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            if (cSPRF != null)
            {
                int refcnt = cSPRF.refcnt;
                if (refcnt > 0)
                {
                    ModelState.AddModelError(string.Empty, refcnt.ToString() + " Details has been touched. Cannot Delete record");
                }
                else
                {
                    // Remove CSTRANM
                    // Modify CSBILL to remove reference to PRFNO
                    try
                    {
                        List <CSBILL> ListBill = cSPRF.CSBILLs.ToList();
                        foreach (CSBILL item in ListBill)
                        {
                            CSTRANM cSTRANM = db.CSTRANMs.Find("CSPRF", item.PRFNO, item.PRFID);
                            db.CSTRANMs.Remove(cSTRANM);

                            CSBILL cSBill = db.CSBILLs.Find(item.BILLNO);
                            cSBill.STAMP           = cSBill.STAMP + 1;
                            cSBill.PRFALLOC        = "N";
                            cSBill.PRFNO           = null;
                            cSBill.PRFID           = null;
                            db.Entry(cSBill).State = EntityState.Modified;
                        }


                        db.CSPRFs.Remove(cSPRF);
                        db.SaveChanges();

                        int page = (int)Session["CSPRFPage"];
                        return(RedirectToAction("Index", new { page = page }));
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                //string message = string.Format("{0}:{1}",
                                //    validationErrors.Entry.Entity.ToString(),
                                //   validationError.ErrorMessage);
                                // raise a new exception nesting
                                // the current instance as InnerException
                                ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                            }
                        }
                    }
                    catch (DbUpdateException ex)
                    {
                        UpdateException updateException = (UpdateException)ex.InnerException;
                        if (updateException != null)
                        {
                            if (updateException.InnerException != null)
                            {
                                var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                                foreach (var error in sqlException.Errors)
                                {
                                    if (error.Message != null)
                                    {
                                        ModelState.AddModelError(string.Empty, error.Message);
                                    }
                                }
                            }
                            else
                            {
                                ModelState.AddModelError(string.Empty, updateException.Message);
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    catch (Exception e) { ModelState.AddModelError(String.Empty, e.Message); }
                }
            }

            ViewBag.page = Session["CSPRFPage"];

            ViewBag.CONO     = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSPRF.CONO);
            ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSPRF.ATTN);
            ViewBag.COADDR   = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { COADDR = x.CONO + "|" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSPRF.COADDR);
            ViewBag.DETAILS  = db.CSBILLs.Where(x => x.PRFNO == cSPRF.PRFNO);
            ViewBag.CONAME   = db.CSCOMSTRs.Where(x => x.CONO == cSPRF.CONO).Select(y => y.CONAME).FirstOrDefault();
            ViewBag.Title    = "Delete Proforma Bill " + cSPRF.PRFNO;
            return(View("Edit", cSPRF));
        }
예제 #13
0
        public PartialViewResult Search()
        {
            CSPRF searchRec = null;

            //searchRec.CONO = pSearchCode;
            //searchRec.CONAME = pSearchName;
            if (Session["SearchPRFRec"] != null)
            {
                searchRec = (CSPRF)Session["SearchPRFRec"];
            }
            else
            {
                searchRec         = new CSPRF();
                searchRec.VDATE   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                searchRec.DUEDATE = searchRec.VDATE.AddMonths(1);
                searchRec.DUEDATE = searchRec.DUEDATE.AddDays(-1);
            }
            if (Session["SearchPRFSort"] == null)
            {
                Session["SearchPRFSort"] = "PRFNO";
            }
            ;

            List <SelectListItem> listItems = new List <SelectListItem>();

            listItems.Add(new SelectListItem
            {
                Text     = "Company Name",
                Value    = "CONAME",
                Selected = (string)Session["SearchPRFSort"] == "CONAME"
            });

            listItems.Add(new SelectListItem
            {
                Text     = "proforma #",
                Value    = "PRFNO",
                Selected = (string)Session["SearchPRFSort"] == "PRFNO"
            });

            listItems.Add(new SelectListItem
            {
                Text     = "proforma # Latest",
                Value    = "PRFNOLAST",
                Selected = (string)Session["SearchPRFSort"] == "PRFNOLAST"
            });

            listItems.Add(new SelectListItem
            {
                Text     = "PRF Date",
                Value    = "VDATE",
                Selected = (string)Session["SearchPRFSort"] == "VDATE"
            });

            listItems.Add(new SelectListItem
            {
                Text     = "Archive",
                Value    = "ARCHIVE",
                Selected = (string)Session["SearchPRFSort"] == "ARCHIVE"
            });
            ViewBag.SORTBY = listItems;
            return(PartialView("Partial/Search", searchRec));
        }
예제 #14
0
        public ActionResult Edit([Bind(Include = "PRFNO,VDATE,DUEDAYS,DUEDATE,CONO,COADDR,COADDRID,ATTN,REM,SEQNO,INVALLOC,INVNO,INVID,STAMP")] CSPRF cSPRF)
        {
            if (ModelState.IsValid)
            {
                ASIDBConnection newdb = new ASIDBConnection();
                db.Entry(cSPRF).State = EntityState.Modified;
                try
                {
                    CSPRF curRec = newdb.CSPRFs.Find(cSPRF.PRFNO);
                    if (curRec.STAMP == cSPRF.STAMP)
                    {
                        cSPRF.STAMP = cSPRF.STAMP + 1;
                        db.SaveChanges();

                        int page = (int)Session["CSPRFPage"];
                        return(RedirectToAction("Index", new { page = page }));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Record is modified");
                    }
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
                finally
                {
                    newdb.Dispose();
                }
            }
            ViewBag.CONO     = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSPRF.CONO);
            ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSPRF.ATTN);
            ViewBag.COADDR   = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { COADDR = x.CONO + "|" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSPRF.COADDR);
            ViewBag.DETAILS  = db.CSBILLs.Where(x => x.PRFNO == cSPRF.PRFNO);
            ViewBag.CONAME   = db.CSCOMSTRs.Where(x => x.CONO == cSPRF.CONO).Select(y => y.CONAME).FirstOrDefault();
            ViewBag.Title    = "Edit Proforma Bill " + cSPRF.PRFNO;
            return(View(cSPRF));
        }
예제 #15
0
        protected void UpdateCSTRANM(CSPRF cSPRF, CSBILL cSBILL, CSTRANM cSTRANM)
        {
            cSTRANM.SOURCE   = "CSPRF";
            cSTRANM.SOURCENO = cSPRF.PRFNO;
            cSTRANM.SOURCEID = cSBILL.PRFID ?? 0;
            cSTRANM.CONO     = cSPRF.CONO;
            cSTRANM.DUEDATE  = cSPRF.DUEDATE;
            cSTRANM.JOBNO    = cSBILL.JOBNO;
            cSTRANM.CASENO   = cSBILL.CASENO;
            cSTRANM.CASECODE = cSBILL.CASECODE;
            cSTRANM.ENTDATE  = cSBILL.ENTDATE;
            cSTRANM.TRTYPE   = cSBILL.ITEMTYPE;
            cSTRANM.TRDESC   = cSBILL.ITEMDESC;

            cSTRANM.TRITEM1 = cSBILL.ITEMAMT1;
            cSTRANM.TRITEM2 = cSBILL.ITEMAMT2;
            cSTRANM.TRITEM  = cSBILL.ITEMAMT1 + cSBILL.ITEMAMT2;

            cSTRANM.TRTAX1 = cSBILL.TAXAMT1;
            cSTRANM.TRTAX2 = cSBILL.TAXAMT2;
            cSTRANM.TRTAX  = cSBILL.TAXAMT1 + cSBILL.TAXAMT2;

            cSTRANM.TRAMT1 = cSBILL.NETAMT1;
            cSTRANM.TRAMT2 = cSBILL.NETAMT2;
            cSTRANM.TRAMT  = cSBILL.NETAMT1 + cSBILL.NETAMT2;


            cSTRANM.TRSIGN = "DB";

            cSTRANM.TRSITEM1 = cSBILL.ITEMAMT1;
            cSTRANM.TRSITEM2 = cSBILL.ITEMAMT2;
            cSTRANM.TRSITEM  = cSBILL.ITEMAMT1 + cSBILL.ITEMAMT2;

            cSTRANM.TRSTAX1 = cSBILL.TAXAMT1;
            cSTRANM.TRSTAX2 = cSBILL.TAXAMT2;
            cSTRANM.TRSTAX  = cSBILL.TAXAMT1 + cSBILL.TAXAMT2;

            cSTRANM.TRSAMT1 = cSBILL.NETAMT1;
            cSTRANM.TRSAMT2 = cSBILL.NETAMT2;
            cSTRANM.TRSAMT  = cSBILL.NETAMT1 + cSBILL.NETAMT2;

            cSTRANM.TRITEMOS1 = cSBILL.ITEMAMT1;
            cSTRANM.TRITEMOS2 = cSBILL.ITEMAMT2;
            cSTRANM.TRITEMOS  = cSBILL.ITEMAMT1 + cSBILL.ITEMAMT2;


            cSTRANM.TRTAXOS1 = cSBILL.TAXAMT1;
            cSTRANM.TRTAXOS2 = cSBILL.TAXAMT2;
            cSTRANM.TRTAXOS  = cSBILL.TAXAMT1 + cSBILL.TAXAMT2;


            cSTRANM.TROS1 = cSBILL.NETAMT1;
            cSTRANM.TROS2 = cSBILL.ITEMAMT2;
            cSTRANM.TROS  = cSBILL.NETAMT1 + cSBILL.NETAMT2;


            cSTRANM.APPITEM  = 0;
            cSTRANM.APPITEM1 = 0;
            cSTRANM.APPITEM2 = 0;
            cSTRANM.APPTAX   = 0;
            cSTRANM.APPTAX1  = 0;
            cSTRANM.APPTAX2  = 0;
            cSTRANM.APPAMT   = 0;
            cSTRANM.APPAMT1  = 0;
            cSTRANM.APPAMT2  = 0;

            cSTRANM.APPTYPE = null;
            cSTRANM.APPNO   = null;
            cSTRANM.APPID   = null;

            cSTRANM.COMPLETE  = "N";
            cSTRANM.COMPLETED = DateTime.Parse("01/01/3000");
            cSTRANM.SEQNO     = cSPRF.SEQNO;
            cSTRANM.REFCNT    = 0;
            cSTRANM.STAMP     = cSTRANM.STAMP + 1;
        }
예제 #16
0
        public ActionResult Create([Bind(Include = "PRFNO,VDATE,DUEDAYS,DUEDATE,CONO,COADDR,COADDRID,ATTN,REM,SEQNO,INVALLOC,INVNO,INVID,STAMP")] CSPRF cSPRF)
        {
            if (ModelState.IsValid)
            {
                SALASTNO serialTbl = db.SALASTNOes.Find("CSPRF");
                if (serialTbl != null)
                {
                    CSCOMSTR cSCOMSTR = db.CSCOMSTRs.Find(cSPRF.CONO);
                    if (cSCOMSTR != null)
                    {
                        try
                        {
                            string prefix  = serialTbl.LASTPFIX;
                            int    MaxNo   = serialTbl.LASTNOMAX;
                            bool   AutoGen = serialTbl.AUTOGEN == "Y";
                            serialTbl.LASTNO = serialTbl.LASTNO + 1;
                            cSPRF.PRFNO      = serialTbl.LASTNO.ToString("D10");
                            cSPRF.STAMP      = 1;

                            // increment company seqno count before using it in transaction
                            cSCOMSTR.SEQNO = cSCOMSTR.SEQNO + 1;
                            cSCOMSTR.STAMP = cSCOMSTR.STAMP + 1;

                            cSPRF.SEQNO = cSCOMSTR.SEQNO;
                            db.Entry(cSCOMSTR).State = EntityState.Modified;

                            serialTbl.STAMP           = serialTbl.STAMP + 1;
                            db.Entry(serialTbl).State = EntityState.Modified;
                            db.CSPRFs.Add(cSPRF);
                            db.SaveChanges();

                            //return Edit(MyHtmlHelpers.ConvertIdToByteStr(cSPRF.PRFNO), 1);
                            return(RedirectToAction("Edit", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSPRF.PRFNO), page = 1 }));
                        }
                        catch (DbEntityValidationException dbEx)
                        {
                            foreach (var validationErrors in dbEx.EntityValidationErrors)
                            {
                                foreach (var validationError in validationErrors.ValidationErrors)
                                {
                                    //string message = string.Format("{0}:{1}",
                                    //    validationErrors.Entry.Entity.ToString(),
                                    //   validationError.ErrorMessage);
                                    // raise a new exception nesting
                                    // the current instance as InnerException
                                    ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                                }
                            }
                        }
                        catch (DbUpdateException ex)
                        {
                            UpdateException updateException = (UpdateException)ex.InnerException;
                            if (updateException != null)
                            {
                                if (updateException.InnerException != null)
                                {
                                    var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                                    foreach (var error in sqlException.Errors)
                                    {
                                        if (error.Message != null)
                                        {
                                            ModelState.AddModelError(string.Empty, error.Message);
                                        }
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError(string.Empty, updateException.Message);
                                }
                            }
                            else
                            {
                                ModelState.AddModelError(string.Empty, updateException.Message);
                            }
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError(string.Empty, e.Message);
                        }
                        finally
                        {
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Unable to find company #");
                    }
                }
            }
            ViewBag.CONO     = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSPRF.CONO);
            ViewBag.ATTNDESC = new SelectList(db.CSCOPICs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { PRSNAME = x.CSPR.PRSNAME, PRSDESC = x.CSPR.PRSNAME }).OrderBy(y => y.PRSDESC), "PRSNAME", "PRSDESC", cSPRF.ATTN);
            ViewBag.COADDR   = new SelectList(db.CSCOADDRs.Where(x => x.CONO == cSPRF.CONO).Select(x => new { COADDR = x.CONO + "|" + x.ADDRID, COADDRDESC = x.ADDRTYPE + " | " + x.MAILADDR + " | " + x.ADDR1 + " " + x.ADDR2 + " " + x.ADDR3 }), "COADDR", "COADDRDESC", cSPRF.COADDR);

            ViewBag.Title = "Create Proforma Bill";
            return(View("Edit", cSPRF));
        }
예제 #17
0
        public CSPRF getProforma(string sid)
        {
            CSPRF cSPRF = db.CSPRFs.Find(sid);

            SACOMP profileRec = db.SACOMPs.FirstOrDefault();

            ViewBag.Company = profileRec.CONAME.ToUpper() + " (" + profileRec.COREGNO + ") ";
            ViewBag.Address = profileRec.COADDR1 + " " + profileRec.COADDR2 + " " + profileRec.COADDR3 + " " + profileRec.COADDR4;
            ViewBag.Contact = "Tel: " + profileRec.COPHONE1 + " Fax: " + profileRec.COFAX1 + " E-Mail: " + profileRec.COWEB;

            var cSBILL = db.CSBILLs.Where(x => x.PRFNO == sid && x.JOBNO != "" && x.JOBNO != null).FirstOrDefault();

            if (cSBILL != null)
            {
                var cSJOB = db.CSJOBMs.Where(x => x.JOBNO == cSBILL.JOBNO).FirstOrDefault();
                ViewBag.StaffName = cSJOB.HKSTAFF.STAFFDESC;
            }
            else
            {
                ViewBag.StaffName = cSPRF.CSCOMSTR.HKSTAFF.STAFFDESC; // default to staff assigned to company
                //ViewBag.StaffName = "No Staff assigned";
            }
            ViewBag.Addr1 = "";
            ViewBag.Addr2 = "";
            if ((cSPRF.CSCOADDR != null) && (cSPRF.CSCOADDR.HKCITY != null))
            {
                ViewBag.Addr1 = cSPRF.CSCOADDR.ADDR1;
                ViewBag.Addr2 = cSPRF.CSCOADDR.ADDR2;
                ViewBag.Addr3 = cSPRF.CSCOADDR.ADDR3 + " " + cSPRF.CSCOADDR.HKCITY.CITYDESC + " " + cSPRF.CSCOADDR.POSTAL;
            }
            else
            {
                if (cSPRF.CSCOADDR != null)
                {
                    ViewBag.Addr1 = cSPRF.CSCOADDR.ADDR1;
                    ViewBag.Addr2 = cSPRF.CSCOADDR.ADDR2;
                    ViewBag.Addr3 = cSPRF.CSCOADDR.ADDR3 + " " + cSPRF.CSCOADDR.POSTAL;
                }
                else
                {
                    ViewBag.Addr3 = "";
                }
            }
            if ((cSPRF.ATTN == null) || (cSPRF.ATTN == string.Empty))
            {
                cSPRF.ATTN = "The Board of Directors";
            }

            decimal totalItem = 0;
            decimal totalTax  = 0;
            decimal reimbItem = 0;
            decimal reimbTax  = 0;

            int linecnt = 0;

            ViewBag.TaxCode    = "";
            ViewBag.TaxRate    = "";
            ViewBag.RTaxCode   = "";
            ViewBag.RTaxRate   = "";
            ViewBag.CSBILL_fee = db.CSBILLs.Where(x => x.PRFNO == sid && x.ITEMTYPE == "Fee").OrderBy(y => y.PRFID).ToList();
            foreach (CSBILL rec in ViewBag.CSBILL_fee)
            {
                totalItem = totalItem + rec.ITEMAMT;
                totalTax  = totalTax + rec.TAXAMT;
                if (rec.TAXTYPE != "")
                {
                    ViewBag.TaxCode = rec.TAXTYPE;
                }
                if (rec.TAXRATE != 0)
                {
                    ViewBag.TaxRate = rec.TAXRATE.ToString("N2") + "%";
                }
                linecnt++;
            }

            ViewBag.CSBILL_work = db.CSBILLs.Where(x => x.PRFNO == sid && x.ITEMTYPE == "Work").OrderBy(y => y.PRFID).ToList();
            foreach (CSBILL rec in ViewBag.CSBILL_work)
            {
                totalItem = totalItem + rec.ITEMAMT;
                totalTax  = totalTax + rec.TAXAMT;
                if (rec.TAXTYPE != "")
                {
                    ViewBag.TaxCode = rec.TAXTYPE;
                }
                if (rec.TAXRATE != 0)
                {
                    ViewBag.TaxRate = rec.TAXRATE.ToString("N2") + "%";
                }
                linecnt++;
            }
            ViewBag.CSBILL_disbursement = db.CSBILLs.Where(x => x.PRFNO == sid && x.ITEMTYPE == "Disbursement").OrderBy(y => y.PRFID).ToList();
            foreach (CSBILL rec in ViewBag.CSBILL_disbursement)
            {
                totalItem = totalItem + rec.ITEMAMT;
                totalTax  = totalTax + rec.TAXAMT;
                if (rec.TAXTYPE != "")
                {
                    ViewBag.TaxCode = rec.TAXTYPE;
                }
                if (rec.TAXRATE != 0)
                {
                    ViewBag.TaxRate = rec.TAXRATE.ToString("N2") + "%";
                }
                linecnt++;
            }
            ViewBag.CSBILL_reimbursement = db.CSBILLs.Where(x => x.PRFNO == sid && x.ITEMTYPE == "Reimbursement").OrderBy(y => y.PRFID).ToList();
            foreach (CSBILL rec in ViewBag.CSBILL_reimbursement)
            {
                reimbItem = reimbItem + rec.ITEMAMT;
                reimbTax  = reimbTax + rec.TAXAMT;
                if (rec.TAXTYPE != "")
                {
                    ViewBag.RTaxCode = rec.TAXTYPE;
                }
                if (rec.TAXRATE != 0)
                {
                    ViewBag.RTaxRate = rec.TAXRATE.ToString("N2") + "%";
                }
                linecnt++;
            }
            ViewBag.totalItem = totalItem.ToString("N2");
            ViewBag.totalTax  = totalTax.ToString("N2");
            ViewBag.TotalAmt  = (totalItem + totalTax).ToString("N2");
            ViewBag.reimbItem = reimbItem.ToString("N2");
            ViewBag.reimbTax  = reimbTax.ToString("N2");
            ViewBag.reimbAmt  = (reimbItem + reimbTax).ToString("N2");
            ViewBag.payable   = (totalItem + totalTax + reimbItem + reimbTax).ToString("N2");
            ViewBag.linecnt   = linecnt;
            return(cSPRF);
        }
예제 #18
0
        public IQueryable <CSPRF> CurrentSelection()
        {
            string   pSearchCode  = "";
            string   pSearchName  = "";
            string   pSearchPRF   = "";
            DateTime pSearchVdate = DateTime.Parse("01/01/0001");
            DateTime pSearchDdate = DateTime.Parse("01/01/0001");

            if (Session["SearchPRFRec"] != null)
            {
                CSPRF searchRec = (CSPRF)(Session["SearchPRFRec"]);
                pSearchCode  = searchRec.CSCOMSTR.COREGNO ?? "";
                pSearchName  = searchRec.CSCOMSTR.CONAME ?? "";
                pSearchVdate = searchRec.VDATE;
                pSearchDdate = searchRec.DUEDATE;
                pSearchPRF   = searchRec.PRFNO ?? "";
            }
            else
            { // start with current month proforma bills instead of entire list
                pSearchVdate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
                pSearchDdate = pSearchVdate.AddMonths(1);
                pSearchDdate = pSearchDdate.AddDays(-1);
            }

            IQueryable <CSPRF> cSPRFs = db.CSPRFs;

            if ((string)Session["SearchPRFSort"] != "ARCHIVE")
            {
                cSPRFs = db.CSPRFs.Where(x => x.INVALLOC == "N");
            }
            else
            {
                cSPRFs = db.CSPRFs.Where(x => x.INVALLOC == "Y");
            }

            if (pSearchCode != "")
            {
                cSPRFs = cSPRFs.Where(x => x.CSCOMSTR.COREGNO.Contains(pSearchCode.ToUpper()));
            }
            ;
            if (pSearchName != "")
            {
                cSPRFs = cSPRFs.Where(x => x.CSCOMSTR.CONAME.Contains(pSearchName.ToUpper()));
            }
            ;
            if (pSearchVdate != DateTime.Parse("01/01/0001"))
            {
                cSPRFs = cSPRFs.Where(x => x.VDATE >= pSearchVdate);
            }
            ;
            if (pSearchDdate != DateTime.Parse("01/01/0001"))
            {
                cSPRFs = cSPRFs.Where(x => x.VDATE <= pSearchDdate);
            }
            ;
            if (pSearchPRF != "")
            {
                if (pSearchPRF.Length > 8)
                {
                    cSPRFs = cSPRFs.Where(x => x.PRFNO == pSearchPRF);
                }
                else
                {
                    cSPRFs = cSPRFs.Where(x => x.PRFNO.Contains(pSearchPRF));
                }
            }
            ;
            cSPRFs = cSPRFs.Include(d => d.CSCOADDR).Include(e => e.CSCOMSTR);

            if ((string)Session["SearchPRFSort"] == "CONAME")
            {
                cSPRFs = cSPRFs.OrderBy(n => n.CSCOMSTR.CONAME);
            }
            else if ((string)Session["SearchPRFSort"] == "VDATE")
            {
                cSPRFs = cSPRFs.OrderBy(n => n.VDATE);
            }
            else if ((string)Session["SearchPRFSort"] == "PRFNOLAST")
            {
                cSPRFs = cSPRFs.OrderByDescending(n => n.PRFNO);
            }
            else
            {
                cSPRFs = cSPRFs.OrderBy(n => n.PRFNO);
            }
            DateTime rptStart = pSearchVdate;
            DateTime rptEnd   = pSearchDdate;

            ViewBag.RPT_START = rptStart.ToString("dd/MM/yyyy");
            ViewBag.RPT_END   = rptEnd.ToString("dd/MM/yyyy");

            return(cSPRFs);
        }
예제 #19
0
        public PartialViewResult AddItem(string id, string prfno)
        {
            string sid    = MyHtmlHelpers.ConvertByteStrToId(id);
            CSBILL cSBILL = db.CSBILLs.Find(sid);
            CSPRF  cSPRF  = db.CSPRFs.Find(prfno);

            if (cSBILL.PRFALLOC == "Y")
            {
                Response.StatusCode        = (int)HttpStatusCode.NotAcceptable;
                Response.StatusDescription = "Bill has been Allocated";
            }
            else
            if (cSBILL.refcnt > 0)
            {
                Response.StatusCode        = (int)HttpStatusCode.NotAcceptable;
                Response.StatusDescription = "Bill has been touched";
                //throw new Exception("Bill has been touched");
            }
            else
            {
                int    prfId   = 0;
                string prfnoId = MyHtmlHelpers.ConvertIdToByteStr(prfno);

                ASIDBConnection newdb = new ASIDBConnection();
                try
                {
                    CSBILL curRec = newdb.CSBILLs.Find(sid);

                    var cSTRANMs = db.CSTRANMs.Where(x => x.SOURCE == "CSPRF" && x.SOURCENO == prfno);

                    prfId = 0;
                    if (cSTRANMs.Count() != 0)
                    {
                        prfId = cSTRANMs.Max(y => y.SOURCEID);
                    }
                    prfId++;

                    if (curRec.STAMP == cSBILL.STAMP)
                    {
                        cSBILL.STAMP    = cSBILL.STAMP + 1;
                        cSBILL.PRFALLOC = "Y";
                        cSBILL.PRFNO    = prfno;
                        cSBILL.PRFID    = prfId;

                        db.Entry(cSBILL).State = EntityState.Modified;

                        CSTRANM cSTRANM = new CSTRANM();
                        cSTRANM.STAMP = 0;
                        UpdateCSTRANM(cSPRF, cSBILL, cSTRANM);

                        db.CSTRANMs.Add(cSTRANM);
                        db.SaveChanges();
                    }
                    else
                    {
                        Response.StatusCode        = (int)HttpStatusCode.NotAcceptable;
                        Response.StatusDescription = "bill was modified";
                        throw new Exception("bill was modified");
                    }
                }
                catch (Exception e)
                {
                    Response.StatusCode        = (int)HttpStatusCode.NotAcceptable;
                    Response.StatusDescription = e.Message;
                }
                finally
                {
                    newdb.Dispose();
                }
            }
            return(BillOpen(MyHtmlHelpers.ConvertIdToByteStr(cSPRF.CONO), MyHtmlHelpers.ConvertIdToByteStr(prfno)));
            //return RedirectToAction("Edit/" + prfnoId);
        }
예제 #20
0
 public void BD_UpdateCSTRANM(CSPRF cSPRF, CSBILL cSBILL, CSTRANM cSTRANM)
 {
     UpdateCSTRANM(cSPRF, cSBILL, cSTRANM);
 }
예제 #21
0
        public ActionResult Post(string[] cono)
        {
            CSPRFsController CSPRFControl = new CSPRFsController();

            try
            {
                SALASTNO serialTbl0 = db.SALASTNOes.Find("CSBILL");
                if ((serialTbl0 != null))
                {
                    foreach (string item in cono)
                    {
                        var      conofee  = item.Split('|');
                        var      myCono   = conofee[0];
                        var      myFee    = conofee[1];
                        string   lastCono = "";
                        CSCOMSTR cSCOMSTR = null;
                        myCono = myCono.Trim();
                        myFee  = myFee.Trim();



                        var     csFees  = db.CSCOFEEs.Where(x => x.CONO == myCono && x.FEETYPE == myFee);
                        decimal taxrate = 0;
                        string  taxcode = "SSTN01";
                        CSPRF   cSPRF   = null;
                        int     prfId   = 0;
                        foreach (var feerec in csFees)
                        {
                            CSITEM cSITEM = db.CSITEMs.Find(feerec.FEETYPE);
                            if (cSITEM != null)
                            {
                                taxrate = cSITEM.GSTRATE ?? 0;
                            }

                            if (lastCono != feerec.CONO)
                            {
                                cSCOMSTR                 = db.CSCOMSTRs.Find(feerec.CONO);
                                cSCOMSTR.SEQNO           = cSCOMSTR.SEQNO + 1;
                                cSCOMSTR.STAMP           = cSCOMSTR.STAMP;
                                db.Entry(cSCOMSTR).State = EntityState.Modified;
                            }

                            var feedate = feerec.LASTTOUCH;


                            feerec.LASTTOUCH       = feedate.AddMonths(feerec.FEEMTH);
                            feerec.STAMP           = feerec.STAMP + 1;
                            db.Entry(feerec).State = EntityState.Modified;


                            SALASTNO serialTbl = db.SALASTNOes.Find("CSPRF");
                            if ((serialTbl != null) && (lastCono != feerec.CONO))
                            {
                                string prefix  = serialTbl.LASTPFIX;
                                int    MaxNo   = serialTbl.LASTNOMAX;
                                bool   AutoGen = serialTbl.AUTOGEN == "Y";
                                serialTbl.LASTNO = serialTbl.LASTNO + 1;


                                cSPRF         = new CSPRF();
                                cSPRF.STAMP   = 0;
                                cSPRF.VDATE   = feedate;
                                cSPRF.DUEDATE = feedate;
                                cSPRF.DUEDAYS = 0;
                                cSPRF.SEQNO   = cSCOMSTR.SEQNO;
                                cSPRF.CONO    = feerec.CONO;
                                short?coid = db.CSCOADDRs.Where(x => x.CONO == feerec.CONO && x.MAILADDR == "Y").Select(y => y.ADDRID).FirstOrDefault();
                                if (coid == 0)
                                {
                                    coid = db.CSCOADDRs.Where(x => x.CONO == feerec.CONO && x.MAILADDR == "N").Select(y => y.ADDRID).FirstOrDefault();
                                }
                                if (coid != 0)
                                {
                                    cSPRF.COADDRID = coid;
                                }

                                cSPRF.ATTN     = "The Board of Directors";
                                cSPRF.PRFNO    = serialTbl.LASTNO.ToString("D10");
                                cSPRF.INVALLOC = "N";

                                serialTbl.STAMP           = serialTbl.STAMP + 1;
                                db.Entry(serialTbl).State = EntityState.Modified;
                                db.CSPRFs.Add(cSPRF);
                                prfId = 0;
                            }

                            prfId++;
                            serialTbl0.LASTNO = serialTbl0.LASTNO + 1;
                            string prefix0  = serialTbl0.LASTPFIX;
                            int    MaxNo0   = serialTbl0.LASTNOMAX;
                            bool   AutoGen0 = serialTbl0.AUTOGEN == "Y";
                            CSBILL cSBILL   = new WebApplication1.CSBILL();
                            cSBILL.STAMP    = 0;
                            cSBILL.CONO     = feerec.CONO;
                            cSBILL.PRFALLOC = "Y";
                            cSBILL.SYSGEN   = "Y";
                            cSBILL.PRFNO    = cSPRF.PRFNO;
                            cSBILL.PRFID    = prfId;
                            cSBILL.BILLNO   = serialTbl0.LASTNO.ToString("D10");;
                            cSBILL.ENTDATE  = feedate;
                            cSBILL.CASECODE = feerec.FEECODE;
                            cSBILL.ITEMTYPE = feerec.FEETYPE;
                            cSBILL.ITEMDESC = feerec.CSCASE.CASEDESC;
                            cSBILL.ITEMSPEC = "- From " + feedate.ToString("dd/MM/yyyy") + " To " + feedate.AddMonths(feerec.FEEMTH).ToString("dd/MM/yyyy");

                            cSBILL.ITEMAMT = feerec.FEEAMT;
                            cSBILL.TAXAMT  = taxrate * feerec.FEEAMT / 100;
                            cSBILL.NETAMT  = cSBILL.ITEMAMT + cSBILL.TAXAMT;

                            cSBILL.ITEMAMT1 = feerec.FEEAMT;
                            cSBILL.TAXAMT1  = taxrate * feerec.FEEAMT / 100;
                            cSBILL.NETAMT1  = cSBILL.ITEMAMT1 + cSBILL.TAXAMT1;

                            cSBILL.ITEMAMT2 = 0;
                            cSBILL.TAXAMT2  = 0;
                            cSBILL.NETAMT2  = 0;
                            cSBILL.TAXRATE  = taxrate;

                            taxcode        = db.CSTAXTYPEs.Where(x => x.TAXRATE == taxrate && x.EFFECTIVE_START <= cSBILL.ENTDATE && x.EFFECTIVE_END >= cSBILL.ENTDATE).Select(y => y.TAXCODE).FirstOrDefault() ?? taxcode;
                            cSBILL.TAXCODE = taxcode;
                            db.CSBILLs.Add(cSBILL);


                            CSTRANM cSTRANM = new CSTRANM();
                            cSTRANM.STAMP = 0;
                            CSPRFControl.BD_UpdateCSTRANM(cSPRF, cSBILL, cSTRANM);

                            db.CSTRANMs.Add(cSTRANM);

                            lastCono = feerec.CONO;
                        }
                        //db.Entry(serialTbl0).State = EntityState.Modified;
                        //db.SaveChanges();
                    }
                    db.Entry(serialTbl0).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        //string message = string.Format("{0}:{1}",
                        //    validationErrors.Entry.Entity.ToString(),
                        //   validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
            catch (DbUpdateException ex)
            {
                UpdateException updateException = (UpdateException)ex.InnerException;
                if (updateException != null)
                {
                    if (updateException.InnerException != null)
                    {
                        var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                        foreach (var error in sqlException.Errors)
                        {
                            if (error.Message != null)
                            {
                                ModelState.AddModelError(string.Empty, error.Message);
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, updateException.Message);
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
            }
            finally
            {
                CSPRFControl.Dispose();
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }