Example #1
0
        private void GetSalesInvoice(IPosTransaction posTransaction, ref SalesInvoiceLineItem salesInvoiceLineItem, string salesInvoiceId)
        {
            try
            {
                bool   retval  = false;
                string comment = string.Empty;

                string   invoiceId          = salesInvoiceId;
                decimal  totalPaidAmount    = 0M;
                decimal  totalInvoiceAmount = 0M;
                string   customerAccount    = string.Empty;
                string   customerName       = string.Empty;
                DateTime creationDate       = new DateTime();

                // Begin by checking if there is a connection to the Transaction Service
                this.Application.TransactionServices.CheckConnection();

                this.Application.TransactionServices.GetSalesInvoice(ref retval, ref comment, ref invoiceId, ref totalPaidAmount, ref totalInvoiceAmount,
                                                                     ref customerAccount, ref customerName, ref creationDate);


                // Populate the salesInvoiceLineItem with the respective values...
                salesInvoiceLineItem.SalesInvoiceId = invoiceId;
                salesInvoiceLineItem.Description    = LSRetailPosis.ApplicationLocalizer.Language.Translate(57002); // Sales Invoice
                salesInvoiceLineItem.CreationDate   = creationDate;
                salesInvoiceLineItem.Amount         = totalInvoiceAmount - totalPaidAmount;                         // The balance/remainder of the sales invoice

                // Necessary property settings for the the sales invoice "item"...
                salesInvoiceLineItem.Price = salesInvoiceLineItem.Amount;
                salesInvoiceLineItem.StandardRetailPrice = salesInvoiceLineItem.Amount;
                salesInvoiceLineItem.Quantity            = 1;
                salesInvoiceLineItem.TaxRatePct          = 0;
                salesInvoiceLineItem.Comment             = salesInvoiceLineItem.SalesInvoiceId;
                salesInvoiceLineItem.NoDiscountAllowed   = true;
                salesInvoiceLineItem.Found = true;
            }
            catch (PosisException px)
            {
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), px);
                throw;
            }
            catch (Exception x)
            {
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                throw;
            }
        }
Example #2
0
        private void PaySalesInvoice(IPosTransaction posTransaction)
        {
            try
            {
                DataTable salesInvoices = new DataTable();
                GetSalesInvoicesForCustomer(ref salesInvoices, posTransaction);

                if (salesInvoices.Rows.Count == 0)
                {
                    // There are no sales invoices in the database for this customer....
                    using (LSRetailPosis.POSProcesses.frmMessage messageDialog = new LSRetailPosis.POSProcesses.frmMessage(57001, MessageBoxButtons.OK, MessageBoxIcon.Exclamation))
                    {
                        this.Application.ApplicationFramework.POSShowForm(messageDialog);

                        return;
                    }
                }

                // Show the available sales invoices for selection...
                using (WinFormsTouch.frmGetSalesInvoice salesInvoicesDialog = new global::Microsoft.Dynamics.Retail.Pos.SalesInvoice.WinFormsTouch.frmGetSalesInvoice())
                {
                    salesInvoicesDialog.SalesInvoices = salesInvoices;
                    this.Application.ApplicationFramework.POSShowForm(salesInvoicesDialog);

                    RetailTransaction retailTransaction = posTransaction as RetailTransaction;

                    if (salesInvoicesDialog.SelectedSalesInvoiceId != null && retailTransaction != null)
                    {
                        // Check if this Sales Invoice has already been added to the transaction
                        foreach (ISaleLineItem salesInvoiceInTrans in retailTransaction.SaleItems)
                        {
                            if (salesInvoiceInTrans is SalesInvoiceLineItem)
                            {
                                if (!salesInvoiceInTrans.Voided)
                                {
                                    if (((SalesInvoiceLineItem)salesInvoiceInTrans).SalesInvoiceId == salesInvoicesDialog.SelectedSalesInvoiceId)
                                    {
                                        using (LSRetailPosis.POSProcesses.frmMessage msgDialog = new LSRetailPosis.POSProcesses.frmMessage(57003, MessageBoxButtons.OK, MessageBoxIcon.Error))  // This sales invoice has already been added to the transaction
                                        {
                                            this.Application.ApplicationFramework.POSShowForm(msgDialog);
                                            return;
                                        }
                                    }
                                }
                            }
                        }

                        // There is a valid sales invoice selected and it's not been already added to the transaction. So let's get the details for it...
                        SalesInvoiceLineItem salesInvoiceLineItem = (SalesInvoiceLineItem)this.Application.BusinessLogic.Utility.CreateSalesInvoiceLineItem(
                            ApplicationSettings.Terminal.StoreCurrency,
                            this.Application.Services.Rounding, retailTransaction);

                        GetSalesInvoice(posTransaction, ref salesInvoiceLineItem, salesInvoicesDialog.SelectedSalesInvoiceId);

                        // And add it to the transaction
                        retailTransaction.Add(salesInvoiceLineItem);
                        retailTransaction.SalesInvoiceAmounts += salesInvoiceLineItem.Amount;
                    }
                }
            }
            catch (PosisException px)
            {
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), px);
                throw;
            }
            catch (Exception x)
            {
                LSRetailPosis.ApplicationExceptionHandler.HandleException(this.ToString(), x);
                throw;
            }
            finally
            {
                if (posTransaction is SalesInvoiceTransaction)
                {
                    ((SalesInvoiceTransaction)posTransaction).CalcTotals();
                }
            }
        }