Example #1
0
        public ActionResult UpdatePayment(tbl_Payments paymentdata)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                try
                {
                    var payment = (from p in ctx.tbl_Payments where p.PaymentID == paymentdata.PaymentID select p).Single();

                    if (payment.DepositStatus == true)
                    {
                        return(Json("posted"));
                    }

                    payment.DepositStatus = false;
                    payment.PaymentAmount = paymentdata.PaymentAmount;
                    payment.PaymentDate   = paymentdata.PaymentDate;
                    payment.PaymentTypeID = paymentdata.PaymentTypeID;
                    payment.CheckNumber   = paymentdata.CheckNumber;
                    payment.DriversLicNUm = paymentdata.DriversLicNUm;
                    ctx.SaveChanges();

                    var CustomerID = ctx.tbl_Job.First(q => q.JobID == paymentdata.JobID).CustomerID;

                    InvoiceFinancialDetail finance = RecalcJobData(paymentdata.JobID, CustomerID);

                    return(Json(finance));
                }
                catch (Exception)
                {
                }

                return(Json("fail"));
            }
        }
Example #2
0
        public ActionResult InsertPayment(tbl_Payments paymentdata)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                try
                {
                    var job = (from j in ctx.tbl_Job
                               where j.JobID == paymentdata.JobID
                               select new
                    {
                        j.FranchiseID,
                        j.CustomerID
                    })
                              .First();

                    paymentdata.FranchiseID   = job.FranchiseID;
                    paymentdata.DepositStatus = false;
                    paymentdata.CreateDate    = DateTime.Now;
                    ctx.tbl_Payments.AddObject(paymentdata);
                    ctx.SaveChanges();

                    InvoiceFinancialDetail finance = RecalcJobData(paymentdata.JobID, job.CustomerID);

                    return(Json(finance));
                }
                catch (Exception)
                {
                }

                return(Json("fail"));
            }
        }
Example #3
0
        public ActionResult DeletePayment(tbl_Payments paymentdata)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var payment = (from p in ctx.tbl_Payments where p.PaymentID == paymentdata.PaymentID select p).Single();

                if (payment.DepositStatus == true)
                {
                    return(Json("posted"));
                }

                ctx.tbl_Payments.DeleteObject(payment);
                ctx.SaveChanges();

                var CustomerID = ctx.tbl_Job.First(q => q.JobID == paymentdata.JobID).CustomerID;

                InvoiceFinancialDetail finance = RecalcJobData(paymentdata.JobID, CustomerID);

                return(Json(finance));
            }
        }
        public void ApplyAdjustment(string franchiseid, string invoiceid, string amount, string accountid, string comments)
        {
            if (gbZeeAcctType == "QB")
            {
                Apply_Adjustment_ForQB(franchiseid, invoiceid, amount, accountid, comments);
            }
            else if (gbZeeAcctType == "PV")
            {
                //do nothing
            }
            else
            {
                //MSA system

                //adjust job payments
                try {
                    SBASuccess = false;
                    //SBAAppLoader.Main();

                    // set sbaObjects

                    // Initialize form
                    //adjust msa accounting
                    InitializeSBA_Adjustments(franchiseid, invoiceid, amount, accountid, comments);


                    if (SBASuccess == true)
                    {
                        tbl_Payments newpayment = new tbl_Payments();

                        newpayment.FranchiseID   = Convert.ToInt32(franchiseid);
                        newpayment.JobID         = Convert.ToInt32(invoiceid);
                        newpayment.PaymentAmount = Convert.ToDecimal(amount);
                        newpayment.PaymentDate   = DateTime.Now;
                        newpayment.DepositStatus = true;
                        newpayment.CreateDate    = DateTime.Now;
                        //posted
                        if (accountid == "65900 WriteOff")
                        {
                            newpayment.PaymentTypeID = -1;
                            //writeoff
                            newpayment.DepositID = -1;
                        }
                        else
                        {
                            newpayment.PaymentTypeID = -2;
                            //discount
                            newpayment.DepositID = -2;
                        }
                        DB.tbl_Payments.AddObject(newpayment);
                        DB.SaveChanges();

                        try {
                            int ijobid = Convert.ToInt32(invoiceid);

                            var Jobrec = (from J in DB.tbl_Job where J.JobID == ijobid select J).Single();
                            Jobrec.Balance = Jobrec.Balance - Convert.ToInt32(amount);
                            DB.SaveChanges();
                        } catch (Exception ex) {
                            ViewBag.lblmessage = "Unable to update job balance, but we will post the adjustment for you!  Error message is:" + ex.Message;
                        }
                    }
                } catch (Exception ex) {
                    ViewBag.lblmessage = "Adjustment was NOT posted since we are Unable to update job payments due to:" + ex.Message;
                }
            }
        }
Example #5
0
        public ActionResult PaymentProcess(string jobsid, string paymentid, string Command, string paydate, string paytype, string Drivelic, string Checkno, string Amt)
        {
            int jobid = Convert.ToInt32(jobsid);
            int frid  = 0;

            if (jobid != 0)
            {
                frid = (from fid in DB.tbl_Job where fid.JobID == jobid select new { fid.JobID }).FirstOrDefault().JobID;
            }
            if (Command == "Save")
            {
                try
                {
                    tbl_Payments Payment = new tbl_Payments();
                    Payment.JobID         = jobid;
                    Payment.CheckNumber   = Checkno;
                    Payment.DepositStatus = false;
                    Payment.PaymentAmount = Convert.ToDecimal(Amt);
                    Payment.PaymentDate   = Convert.ToDateTime(paydate);
                    Payment.PaymentTypeID = Convert.ToInt32(paytype);
                    Payment.CreateDate    = DateTime.Now;
                    if (Drivelic != "")
                    {
                        Payment.DriversLicNUm = Drivelic;
                    }
                    //Payment.FranchiseID = 38;
                    Payment.FranchiseID = frid;
                    DB.tbl_Payments.AddObject(Payment);
                    DB.SaveChanges();
                    MyPaymentID        = Payment.PaymentID;
                    ViewBag.lblmessage = "Record Save Successfully.";
                }
                catch (Exception)
                {
                    throw;
                }
            }

            if (Command == "Update")
            {
                try
                {
                    if (paymentid != "")
                    {
                        MyPaymentID = Convert.ToInt32(paymentid);
                        if (Convert.ToInt32(paytype) != 0)
                        {
                            if (!string.IsNullOrEmpty(Amt))
                            {
                                var Payment = (from p in DB.tbl_Payments where p.PaymentID == MyPaymentID select p).Single();

                                if (Payment.DepositStatus == true)
                                {
                                    ViewBag.lblmessage = "This payment has been posted to accounting and may not be changed!";
                                    return(RedirectToAction("Index", "Employee"));
                                }

                                Payment.JobID = jobid;
                                if (Checkno != "")
                                {
                                    Payment.CheckNumber = Checkno;
                                }
                                Payment.DepositStatus = false;
                                Payment.PaymentAmount = Convert.ToDecimal(Amt);
                                Payment.PaymentDate   = Convert.ToDateTime(paydate);
                                Payment.PaymentTypeID = Convert.ToInt32(paytype);
                                if (Drivelic != "")
                                {
                                    Payment.DriversLicNUm = Drivelic;
                                }
                                //Payment.FranchiseID = 38;
                                Payment.FranchiseID = frid;
                                DB.SaveChanges();

                                ViewBag.lblmessage = "Record Update Successfully.";
                            }
                            else
                            {
                                ViewBag.lblmessage = "Please provide an amount before trying to update the selected payment.";
                            }
                        }
                        else
                        {
                            ViewBag.lblmessage = "Please select a Payment Type before trying to update the selected payment.";
                        }
                    }
                    else
                    {
                        ViewBag.lblmessage = "Please select an existing payment before clicking update.";
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }
            if (Command == "Delete")
            {
                try
                {
                    if (paymentid != "")
                    {
                        MyPaymentID = Convert.ToInt32(paymentid);


                        var payment = (from p in DB.tbl_Payments where p.PaymentID == MyPaymentID select p).Single();

                        if (payment.DepositStatus == true)
                        {
                            ViewBag.lblmessage = "This payment has been posted to accounting and may not be deleted!";
                            return(RedirectToAction("Index", "Employee"));
                        }

                        DB.tbl_Payments.DeleteObject(payment);
                        DB.SaveChanges();
                        ViewBag.lblmessage = "Record Delete Successfully.";
                        MyPaymentID        = 0;

                        //}
                    }
                    else
                    {
                        ViewBag.lblmessage = "Please select an existing payment before clicking delete.";
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }

            var objjob = (from j in DB.tbl_Job
                          where j.JobID == jobid
                          select j)
                         .FirstOrDefault();

            var objprice = (from j in DB.tbl_Job
                            join t in DB.tbl_Job_Tasks on j.JobID equals t.JobID
                            join tp in DB.tbl_Job_Task_Parts on t.JobTaskID equals tp.JobTaskID
                            where j.JobID == jobid
                            select new { t.Price, t.Quantity })
                           .Distinct();

            decimal total = 0;

            foreach (var item in objprice)
            {
                decimal dtotal = item.Price * item.Quantity;
                total = total + dtotal;
            }

            var     Paymentlist  = (from p in DB.tbl_Payments where p.JobID == objjob.JobID select p);
            decimal totalpayment = 0;

            foreach (var payment in Paymentlist)
            {
                totalpayment = (Convert.ToDecimal(totalpayment) + Convert.ToDecimal(payment.PaymentAmount));
            }

            objjob.SubTotal   = total;
            objjob.TotalSales = total + objjob.TaxAmount;
            objjob.Balance    = objjob.TotalSales - totalpayment;
            DB.SaveChanges();


            return(Json(""));
        }
Example #6
0
        public ActionResult Payment(int jobid, FormCollection frmcollection, string Command)
        {
            ViewBag.JobID = jobid.ToString();
            int frid = 0;

            if (frmcollection != null)
            {
                if (jobid != 0)
                {
                    frid = (from fid in DB.tbl_Job
                            where fid.JobID == jobid
                            select fid.JobID)
                           .FirstOrDefault();
                }
                if (Command == "Save")
                {
                    try
                    {
                        if (Convert.ToInt32(frmcollection["ddlpayment"]) != 0)
                        {
                            if (!string.IsNullOrEmpty(frmcollection["txtamount"]))
                            {
                                tbl_Payments Payment = new tbl_Payments();
                                Payment.JobID = jobid;
                                if (frmcollection["txtcheckno"] != "")
                                {
                                    Payment.CheckNumber = frmcollection["txtcheckno"];
                                }
                                Payment.DepositStatus = false;
                                Payment.PaymentAmount = Convert.ToDecimal(frmcollection["txtamount"]);
                                Payment.PaymentDate   = Convert.ToDateTime(frmcollection["txtdate"]);
                                Payment.PaymentTypeID = Convert.ToInt32(frmcollection["ddlpayment"]);
                                if (frmcollection["txtdriverlic"] != "")
                                {
                                    Payment.DriversLicNUm = frmcollection["txtdriverlic"];
                                }

                                Payment.FranchiseID = frid;
                                Payment.CreateDate  = DateTime.Now;
                                DB.tbl_Payments.AddObject(Payment);
                                DB.SaveChanges();

                                MyPaymentID        = Payment.PaymentID;
                                ViewBag.lblmessage = "Record Save Successfully.";
                            }
                            else
                            {
                                ViewBag.lblmessage = "Please provide an amount before trying to add a new payment.";
                            }
                        }
                        else
                        {
                            ViewBag.lblmessage = "Please select a Payment Type before trying to create a new payment.";
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                if (Command == "Update")
                {
                    try
                    {
                        if (frmcollection["hdnpaymentid"] != "")
                        {
                            MyPaymentID = Convert.ToInt32(frmcollection["hdnpaymentid"]);
                            if (Convert.ToInt32(frmcollection["ddlpayment"]) != 0)
                            {
                                if (!string.IsNullOrEmpty(frmcollection["txtamount"]))
                                {
                                    var Payment = (from p in DB.tbl_Payments where p.PaymentID == MyPaymentID select p).Single();

                                    if (Payment.DepositStatus == true)
                                    {
                                        ViewBag.lblmessage = "This payment has been posted to accounting and may not be changed!";
                                        return(RedirectToAction("Index", "Employee"));
                                    }

                                    Payment.JobID = jobid;
                                    if (frmcollection["txtcheckno"] != "")
                                    {
                                        Payment.CheckNumber = frmcollection["txtcheckno"];
                                    }
                                    Payment.DepositStatus = false;
                                    Payment.PaymentAmount = Convert.ToDecimal(frmcollection["txtamount"]);
                                    Payment.PaymentDate   = Convert.ToDateTime(frmcollection["txtdate"]);
                                    Payment.PaymentTypeID = Convert.ToInt32(frmcollection["ddlpayment"]);
                                    if (frmcollection["txtdriverlic"] != "")
                                    {
                                        Payment.DriversLicNUm = frmcollection["txtdriverlic"];
                                    }

                                    Payment.FranchiseID = frid;
                                    DB.SaveChanges();

                                    ViewBag.lblmessage = "Record Update Successfully.";
                                }
                                else
                                {
                                    ViewBag.lblmessage = "Please provide an amount before trying to update the selected payment.";
                                }
                            }
                            else
                            {
                                ViewBag.lblmessage = "Please select a Payment Type before trying to update the selected payment.";
                            }
                        }
                        else
                        {
                            ViewBag.lblmessage = "Please select an existing payment before clicking update.";
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                if (Command == "Delete")
                {
                    try
                    {
                        if (frmcollection["hdnpaymentid"] != "")
                        {
                            MyPaymentID = Convert.ToInt32(frmcollection["hdnpaymentid"]);
                            string tmpstr = null;

                            tmpstr = frmcollection["ddlpayment"] + " for " + Convert.ToDecimal(frmcollection["txtamount"]);

                            //if (Interaction.MsgBox("Are you sure you want to delete the selected payment of " + tmpstr + "?", MsgBoxStyle.YesNo, "Delete Payment") == MsgBoxResult.Yes)
                            //{
                            var payment = (from p in DB.tbl_Payments where p.PaymentID == MyPaymentID select p).Single();

                            if (payment.DepositStatus == true)
                            {
                                ViewBag.lblmessage = "This payment has been posted to accounting and may not be deleted!";
                                return(RedirectToAction("Index", "Employee"));
                            }

                            DB.tbl_Payments.DeleteObject(payment);
                            DB.SaveChanges();
                            ViewBag.lblmessage = "Record Delete Successfully.";
                            MyPaymentID        = 0;

                            //}
                        }
                        else
                        {
                            ViewBag.lblmessage = "Please select an existing payment before clicking delete.";
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                var objjob = (from j in DB.tbl_Job
                              where j.JobID == jobid
                              select j)
                             .FirstOrDefault();

                var objprice = (from j in DB.tbl_Job
                                join t in DB.tbl_Job_Tasks on j.JobID equals t.JobID
                                join tp in DB.tbl_Job_Task_Parts on t.JobTaskID equals tp.JobTaskID
                                where j.JobID == jobid
                                select new { t.Price, t.Quantity })
                               .Distinct();

                decimal total = 0;
                foreach (var item in objprice)
                {
                    decimal dtotal = item.Price * item.Quantity;
                    total = total + dtotal;
                }

                var     Paymentlist  = (from p in DB.tbl_Payments where p.JobID == objjob.JobID select p);
                decimal totalpayment = 0;
                foreach (var payment in Paymentlist)
                {
                    totalpayment = (Convert.ToDecimal(totalpayment) + Convert.ToDecimal(payment.PaymentAmount));
                }

                objjob.SubTotal   = total;
                objjob.TotalSales = total + objjob.TaxAmount;
                objjob.Balance    = objjob.TotalSales - totalpayment;
                DB.SaveChanges();
            }

            var lstPaymentType = (from pt in DB.tbl_Payment_Types select pt).ToList();

            ViewBag.PaymentTypeList = new SelectList(lstPaymentType, "PaymentTypeId", "PaymentType");
            ViewBag.jobsid          = jobid.ToString();
            ViewBag.statusid        = (from s in DB.tbl_Job where s.JobID == jobid select s.StatusID).FirstOrDefault();

            var paymentid = (from p in DB.tbl_Payments where p.JobID == jobid select p).FirstOrDefault();

            if (paymentid != null)
            {
                ViewBag.paymentid     = paymentid.PaymentID.ToString();
                ViewBag.PaymentTypeId = paymentid.PaymentTypeID;
            }
            else
            {
                ViewBag.paymentid     = "0";
                ViewBag.PaymentTypeId = "";
            }

            if (Command != null)
            {
                return(RedirectToAction("../../MyFinances/MyFinances/paymentmethod2"));
            }
            else
            {
                PaymentInfo modelPaymentInfo = new PaymentInfo();
                modelPaymentInfo.JobID = jobid;
                var paymenttypelist = (from pt in DB.tbl_Payment_Types select pt).ToList();
                modelPaymentInfo.PaymentTypeList = new SelectList(paymenttypelist, "PaymentTypeId", "PaymentType");

                return(View(modelPaymentInfo));
            }
        }