private SalesInvoice _createNewSalesInvoice(SalesInvoiceDocument document, SalesInvoice salesInvoice,
                                                    EntityReference <Customer> customerEntityReference)
        {
            try
            {
                salesInvoice.CustomerReference           = customerEntityReference;
                salesInvoice.CustomerPurchaseOrderNumber = document.PoNo;
                salesInvoice.CustomerNote                = document.NotesOrSpecialInstructions;
                salesInvoice.Date                        = document.PostingDate;
                salesInvoice.DateDue                     = document.DueDate;
                salesInvoice.DiscountAmount              = document.DiscountAmount;
                salesInvoice.ReferenceNumber             = document.Name;
                salesInvoice.ShipDate                    = document.ShipDate;
                salesInvoice.ShipVia                     = document.ShippingMethod;
                salesInvoice.TermsDescription            = document.PaymentTermsTemplate;
                salesInvoice.CustomerPurchaseOrderNumber = document.PoNo;
                AddSalesRep(salesInvoice, document);
                AddShipAddress(salesInvoice);
                AddSalesOrderData(document, salesInvoice);

                salesInvoice.Save();
                Logger.Information("Sales Invoice - {@Name} was saved successfully", document.Name);
            }
            catch (Sage.Peachtree.API.Exceptions.RecordInUseException)
            {
                // abort. The unsaved data will eventually be re-queued
                salesInvoice = null;
                Logger.Debug("Record is in use. {@Name} will be sent back to the queue", document.Name);
            }
            catch (ArgumentException e)
            {
                salesInvoice = null;
                Logger.Debug("There was a problem with creating {@Name}. It will be sent back to the queue", document.Name);
                Logger.Debug("There error is {@E}", e.Message);
            }
            catch (Sage.Peachtree.API.Exceptions.ValidationException e)
            {
                Logger.Debug("Validation failed.");
                Logger.Debug(e.Message);
                if (e.ProblemList.OfType <DuplicateValueProblem>().Any(item => item.PropertyName == "ReferenceNumber"))
                {
                    Logger.Debug("{@Name} is already in Sage so will notify ERPNext", document.Name);
                }
                else
                {
                    Logger.Debug("{@Name} will be sent back to the queue", document.Name);
                    salesInvoice = null;
                }
            }
            catch (Exception e)
            {
                salesInvoice = null;
                Logger.Debug(e, e.Message);
                Logger.Debug("{@E}", e);
            }

            return(salesInvoice);
        }
Ejemplo n.º 2
0
        protected void grdData_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            SalesInvoice salesInvoice = session.GetObjectByKey <SalesInvoice>(Guid.Parse(e.Values["BillId"].ToString()));

            if (salesInvoice.RowStatus > 1)
            {
                ((ASPxGridView)sender).JSProperties.Add("cpUndelete", "true");
            }
            else
            {
                salesInvoice.RowStatus = -1;
                salesInvoice.Save();
            }

            e.Cancel = true;
        }