public override void okBtn_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            base.okBtn_Click(sender, e);

            if (this.myUnPaidInvoices.Any() != true)
            {
                MessageBox.Show("Can not process receipt. This claimant have no unpaid invoices.");
                this.DialogResult = DialogResult.Retry;
                return;
            }

            if (this.DialogResult == DialogResult.OK)
            {
                applyReceipt();

                var paidlist = new List<int> { };
                var newConnection = new dbContextDataContext();
                foreach (var i in myUnPaidInvoices)
                {
                    if(!object.Equals(i.ReceiptAmount, default(decimal)))
                    {
                        var ir = new tblInvoiceReceipt();
                        ir.InvRecAmnt = i.ReceiptAmount;
                        ir.InvoiceNo = i.InvoiceNo;
                        ir.ReceiptNo = myReceipt.ReceiptNo;
                        newConnection.tblInvoiceReceipts.InsertOnSubmit(ir);
                    }
                    if ((i.ReceiptAmount + i.ReceiptTotal) == i.InvoiceTotal)
                    {
                        paidlist.Add(i.InvoiceNo);
                    }
                }

                foreach (var p in paidlist)
                {
                    var inv = newConnection.tblInvoices.Where(i => i.InvoiceNo == p).SingleOrDefault();
                    if(inv !=null)
                    inv.InvoicePaid = true;
                }

                if (myPayments.Sum(p => p.PayinAmnt).Value > myUnPaidInvoices.Sum(u => u.ReceiptAmount))
                {
                    var result = MessageBox.Show("Fund remaining, do you want to save this as a credit?", "OVERPAYMENT",
                             MessageBoxButtons.YesNoCancel,
                             MessageBoxIcon.Question);

                    if (result == DialogResult.Yes)
                    {
                        var newCredit = new Db.Credit();
                        newCredit.CreditComment = "Overpayment on Receipt #: " + myReceipt.ReceiptNo.ToString();
                        newCredit.CreditDate = System.DateTime.Today;
                        newCredit.CreditType = 3;
                        newCredit.ClaimantID = myClaimant.ClaimantID;
                        newCredit.CreditCancelled = false;
                        newCredit.CreditAmount = decimal.Subtract(myPayments.Sum(p => p.PayinAmnt).Value, myUnPaidInvoices.Sum(u => u.ReceiptAmount));
                        newConnection.Credits.InsertOnSubmit(newCredit);
                    }

                    if (result == DialogResult.No)
                    {
                        //proceed as normal.
                    }

                    if (result == DialogResult.Cancel)
                    {
                        this.DialogResult = DialogResult.Retry;
                        return;
                    }
                }

                newConnection.SubmitChanges();
            }
            Cursor.Current = Cursors.Default;
        }
Exemple #2
0
        private void cancelBtn_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            if (isOfficial == true)
            {
                if (Ex.staticProperties.userLevel.GetValueOrDefault(1) == 1)
                {
                    myInvoice = myConnection.tblInvoices.Where(i => i.InvoiceNo == myInvoice.InvoiceNo).SingleOrDefault();
                    myInvoice.InvoiceCancelled = true;
                    if (myReceipts.Any())
                    {
                        foreach (var r in myReceipts)
                        {
                            myConnection.tblReceipts.Attach(r);
                            if (r.IsMulti == true)
                            {
                                var newCredit = new Db.Credit();
                                newCredit.CreditDate = System.DateTime.Today;
                                newCredit.CreditComment = "Cancelled receipt from invoice: " + myInvoice.InvoiceNo;
                                newCredit.CreditType = 2;
                                newCredit.ClaimantID = myClaimant.ClaimantID;

                                tblInvoiceReceipt relation = myConnection.tblInvoiceReceipts.Where(i => i.InvoiceNo == myInvoice.InvoiceNo && i.ReceiptNo == r.ReceiptNo).FirstOrDefault();
                                newCredit.CreditAmount = relation.InvRecAmnt.GetValueOrDefault(0);
                                if (relation != null)
                                    myConnection.tblInvoiceReceipts.DeleteOnSubmit(relation);
                                myConnection.Credits.InsertOnSubmit(newCredit);
                            }
                            else
                            {
                                r.ReceiptCancelled = true;
                            }

                        }
                    }
                    myConnection.SubmitChanges();
                    cancelInvoice();
                }
                else
                {

                    if (DateTime.Compare(System.DateTime.Today, myTransaction.TranDate.Value) == 0)
                    {
                        myInvoice = myConnection.tblInvoices.Where(i => i.InvoiceNo == myInvoice.InvoiceNo).SingleOrDefault();
                        myInvoice.InvoiceCancelled = true;
                        if (myReceipts.Any())
                        {

                            foreach (var r in myReceipts)
                            {
                                myConnection.tblReceipts.Attach(r);
                                if (r.IsMulti == true)
                                {
                                    var newCredit = new Db.Credit();
                                    newCredit.CreditDate = System.DateTime.Today;
                                    newCredit.CreditComment = "Cancelled receipt from invoice: " + myInvoice.InvoiceNo;
                                    newCredit.CreditType = 2;
                                    newCredit.ClaimantID = myClaimant.ClaimantID;

                                    tblInvoiceReceipt relation = myConnection.tblInvoiceReceipts.Where(i => i.InvoiceNo == myInvoice.InvoiceNo && i.ReceiptNo == r.ReceiptNo).FirstOrDefault();
                                    newCredit.CreditAmount = relation.InvRecAmnt.GetValueOrDefault(0);
                                    if (relation != null)
                                        myConnection.tblInvoiceReceipts.DeleteOnSubmit(relation);
                                    myConnection.Credits.InsertOnSubmit(newCredit);
                                }
                                else
                                {
                                    r.ReceiptCancelled = true;
                                }
                            }
                        }
                        myConnection.SubmitChanges();
                        cancelInvoice();
                    }
                    else
                    {
                        MessageBox.Show("General user can not cancel invoices issued earlier than Today.");
                        return;
                    }
                }
            }
            else
            {
                this.myLines.Clear();
            }
            Cursor.Current = Cursors.Default;
        }