Esempio n. 1
0
        private void GetInvoiceDetails()
        {
            try
            {
                invoiceService = new InvoiceFormService();
                var invoiceData = invoiceService.GetInvoiceById(InvoiceId);

                comboAccount.SelectedValue = invoiceData.AccountId;
                var bank     = invoiceData.BankId;
                var custName = invoiceData.CustomerId;
                comboBank.SelectedValue    = invoiceData.BankId;
                comboCustomerName.Text     = invoiceData.CustomerName;
                txtSerialNumber.Text       = invoiceData.SerialNumber;
                txtReference.Text          = invoiceData.Reference;
                txtPlaceOfSupply.Text      = invoiceData.PlaceOfSupply;
                txtBillingAddress.Text     = invoiceData.BillingAddress;
                txtShippingAddress.Text    = invoiceData.ShippingAddress;
                txtCustomerNotes.Text      = invoiceData.CustomerNotes;
                txtTermsAndConditions.Text = invoiceData.TermsAndConditions;

                //Bind Transaction
                invoiceTransactionFormService     = new InvoiceTransactionService();
                invoiceTransData.invoiceTransData = invoiceTransactionFormService.GetInvoiceByInvoiceId(InvoiceId);
                lblTotal.Text = Convert.ToString(invoiceTransData.invoiceTransData.Sum(s => s.Total));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Comman.Product_Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        private void btnSaveInvoice_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateFields())
                {
                    Invoice invoiceData = new Invoice();
                    invoiceData.Id                 = InvoiceId;
                    invoiceData.AccountId          = int.Parse(Convert.ToString(comboAccount.SelectedValue));
                    invoiceData.BankId             = int.Parse(Convert.ToString(comboBank.SelectedValue));
                    invoiceData.CustomerId         = int.Parse(Convert.ToString(comboCustomerName.SelectedValue));
                    invoiceData.SerialNumber       = txtSerialNumber.Text;
                    invoiceData.InvoiceDate        = dtInvoiceDate.Value;
                    invoiceData.DueDate            = dtDueDate.Value;
                    invoiceData.CustomerName       = comboCustomerName.Text;
                    invoiceData.ShippingAddress    = txtShippingAddress.Text;
                    invoiceData.Reference          = txtReference.Text;
                    invoiceData.BillingAddress     = txtBillingAddress.Text;
                    invoiceData.GSTIN              = txtGSTIN.Text;
                    invoiceData.PlaceOfSupply      = txtPlaceOfSupply.Text;
                    invoiceData.CustomerNotes      = txtCustomerNotes.Text;
                    invoiceData.TermsAndConditions = txtTermsAndConditions.Text;
                    invoiceData.CreatDate          = DateTime.Now;
                    invoiceData.CreatBy            = Comman.UserId;

                    var Transaction = grdInvoiceData.DataSource as InvoiceDataModel[];
                    for (int i = 0; i < Transaction.Length; i++)
                    {
                        var Tran = Transaction[i];
                        if (Tran.Id < 0)
                        {
                            invoiceData.InvoiceTransactions.Add(new InvoiceTransaction
                            {
                                Id           = Tran.Id,
                                ItemId       = Tran.ItemId,
                                Qty          = Tran.Qty,
                                Rate         = Tran.Rate,
                                Discount     = Tran.Discount,
                                TaxableValue = Tran.TaxableValue,
                                TaxableRate  = decimal.Parse(Tran.TaxableRate),
                                TaxValue     = Tran.TaxValue,
                                Percentage   = Tran.Percentage,
                                Total        = Tran.Total,
                                InvoiceId    = Tran.InvoiceId,
                                CreatBy      = Comman.UserId,
                                CreatDate    = DateTime.Now
                            });
                        }
                    }
                    var TransactionData = Transaction.Where(w => w.Id > 0).Select(s => new InvoiceTransaction
                    {
                        Id           = s.Id,
                        ItemId       = s.ItemId,
                        InvoiceId    = s.InvoiceId,
                        Qty          = s.Qty,
                        Rate         = s.Rate,
                        Discount     = s.Discount,
                        TaxableValue = s.TaxableValue,
                        TaxableRate  = decimal.Parse(s.TaxableRate),
                        TaxValue     = s.TaxValue,
                        Percentage   = s.Percentage,
                        Total        = s.Total
                    }).ToList();
                    invoiceService = new InvoiceFormService();

                    // check invoiceId  if exixst than update elase save
                    bool isExits = invoiceService.IsInvoiceExits(InvoiceId);
                    if (isExits == true)
                    {
                        if (InvoiceId > 0)
                        {
                            DialogResult result = MessageBox.Show("Invoice already exists. Do you want to update it ?", "Confirm delete?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                            if (result.Equals(DialogResult.Yes))
                            {
                                invoiceService.SaveInvoice(invoiceData, TransactionData);
                                MessageBox.Show("Invoice Saved", Comman.Product_Name, MessageBoxButtons.OK, MessageBoxIcon.None);
                                ClearData();
                            }
                            else
                            {
                                MessageBox.Show("Invoice alredy exits");
                            }
                        }
                    }
                    else
                    {
                        invoiceService.SaveInvoice(invoiceData, TransactionData);
                        MessageBox.Show("Invoice Saved", Comman.Product_Name, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ClearData();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Comman.Product_Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }