protected override void BillDetail_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity)
        {
            EntityValueField orderType      = targetEntity.Fields.SingleOrDefault(f => f.Name == "POOrderType") as EntityValueField;
            EntityValueField orderNbr       = targetEntity.Fields.SingleOrDefault(f => f.Name == "POOrderNbr") as EntityValueField;
            EntityValueField orderLineNbr   = targetEntity.Fields.SingleOrDefault(f => f.Name == "POLine") as EntityValueField;
            EntityValueField receiptNbr     = targetEntity.Fields.SingleOrDefault(f => f.Name == "POReceiptNbr") as EntityValueField;
            EntityValueField receiptLineNbr = targetEntity.Fields.SingleOrDefault(f => f.Name == "POReceiptLine") as EntityValueField;

            if (orderType != null && orderNbr != null)
            {
                if (orderLineNbr != null)
                {
                    AddPOOrderLineToBill(graph, (APInvoiceEntry)graph, orderType, orderNbr, orderLineNbr);
                }
                else
                {
                    AddPOOrderToBill(graph, (APInvoiceEntry)graph, orderType, orderNbr);
                }
            }
            else if (receiptNbr != null)
            {
                if (receiptLineNbr != null)
                {
                    AddPOReceiptLineToBill(graph, (APInvoiceEntry)graph, receiptNbr, receiptLineNbr);
                }
                else
                {
                    AddPOReceiptToBill(graph, (APInvoiceEntry)graph, receiptNbr);
                }
            }
            else
            {
                base.BillDetail_Insert(graph, entity, targetEntity);
            }
        }
    protected INUnit GetINUnit(InventoryItemMaint maint, EntityValueField fromUnit, EntityValueField toUnit)
    {
        var conversions = maint.itemunits.Select();

        return(conversions.Select(c => c[typeof(INUnit)] as INUnit)
               .FirstOrDefault(c => c != null &&
                               (toUnit == null || string.IsNullOrEmpty(toUnit.Value) || string.Equals(c.ToUnit, toUnit.Value)) &&
                               string.Equals(c.FromUnit, fromUnit.Value)));
    }
Ejemplo n.º 3
0
        private static void FillInvoiceRowFromEntiry(SOInvoiceEntry graph, EntityImpl targetEntity, ARTran row)
        {
            row.TranDesc           = GetEntityField(targetEntity, "TransactionDescr")?.Value;
            row.UnitPrice          = ConvertToNullableDecimal(GetEntityField(targetEntity, "UnitPrice"));
            row.LineNbr            = ConvertToNullableInt(GetEntityField(targetEntity, "LineNbr"));
            row.Qty                = ConvertToNullableDecimal(GetEntityField(targetEntity, "Qty"));
            row.CuryTranAmt        = ConvertToNullableDecimal(GetEntityField(targetEntity, "Amount"));
            row.UOM                = GetEntityField(targetEntity, "UOM")?.Value;
            row.DiscAmt            = ConvertToNullableDecimal(GetEntityField(targetEntity, "DiscountAmount"));
            row.DiscPct            = ConvertToNullableDecimal(GetEntityField(targetEntity, "DiscountPercent"));
            row.LotSerialNbr       = GetEntityField(targetEntity, "LotSerialNbr")?.Value;
            row.SOOrderLineNbr     = ConvertToNullableInt(GetEntityField(targetEntity, "OrderLineNbr"));
            row.TaxCategoryID      = GetEntityField(targetEntity, "TaxCategory")?.Value;
            row.OrigInvoiceType    = GetEntityField(targetEntity, "OrigInvType")?.Value;
            row.OrigInvoiceNbr     = GetEntityField(targetEntity, "OrigInvNbr")?.Value;
            row.OrigInvoiceLineNbr = ConvertToNullableInt(GetEntityField(targetEntity, "OrigInvLineNbr"));

            string           inventoryID         = GetEntityField(targetEntity, "InventoryID")?.Value;
            string           branchID            = GetEntityField(targetEntity, "BranchID")?.Value;
            EntityValueField fieldExpirationDate = GetEntityField(targetEntity, "ExpirationDate");
            DateTime         expirationDate      = fieldExpirationDate != null?Convert.ToDateTime(fieldExpirationDate.Value) : default(DateTime);

            string location    = GetEntityField(targetEntity, "Location")?.Value;
            string warehouseID = GetEntityField(targetEntity, "WarehouseID")?.Value;

            if (inventoryID != null)
            {
                row.InventoryID = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> > > > .Select(graph, inventoryID).FirstOrDefault()?.GetItem <InventoryItem>().InventoryID;
            }
            if (branchID != null)
            {
                row.BranchID = PXSelect <GL.Branch, Where <GL.Branch.branchCD, Equal <Required <GL.Branch.branchCD> > > > .Select(graph, branchID).FirstOrDefault()?.GetItem <GL.Branch>().BranchID;
            }
            if (expirationDate != default(DateTime))
            {
                row.ExpireDate = expirationDate;
            }
            if (warehouseID != null)
            {
                row.SiteID = PXSelect <INSite, Where <INSite.siteCD, Equal <Required <INSite.siteCD> > > > .Select(graph, warehouseID).FirstOrDefault()?.GetItem <INSite>().SiteID;

                if (location != null)
                {
                    row.LocationID = PXSelect <INLocation, Where <INLocation.siteID, Equal <Required <INLocation.siteID> >, And <INLocation.locationCD, Equal <Required <INLocation.locationCD> > > > > .Select(graph, row.SiteID, location).FirstOrDefault()?.GetItem <INLocation>().LocationID;
                }
            }
        }
        private static void AddPOReceiptLineToBill(PXGraph graph, APInvoiceEntry invoiceEntry, EntityValueField receiptNbr, EntityValueField receiptLineNbr)
        {
            if (receiptNbr == null || receiptLineNbr == null)
            {
                throw new PXException("Both POReceiptNbr and POReceiptLine must be provided to add a Purchase Receipt to details.");
            }

            APInvoiceEntry.POReceiptLineAdd line = PXSelect <APInvoiceEntry.POReceiptLineAdd,
                                                             Where <APInvoiceEntry.POReceiptLineAdd.receiptNbr, Equal <Required <POReceipt.receiptNbr> >,
                                                                    And <APInvoiceEntry.POReceiptLineAdd.lineNbr, Equal <Required <POReceiptLine.lineNbr> > > > > .Select(graph, receiptNbr.Value, receiptLineNbr.Value);

            if (line == null)
            {
                throw new PXException($"Receipt Line {receiptNbr.Value} - {receiptLineNbr.Value} not found.");
            }

            line.Selected = true;

            var receiptLineExtension = graph.GetExtension <PO.GraphExtensions.APInvoiceSmartPanel.AddPOReceiptLineExtension>();

            receiptLineExtension.poReceiptLinesSelection.Update(line);

            receiptLineExtension.addReceiptLine2.Press();
        }
Ejemplo n.º 5
0
        public static CBAPI_Insights.API.Entity ConvertImpl(EntityImpl entity, string nameSpace)
        {
            CBAPI_Insights.API.Entity ret = (CBAPI_Insights.API.Entity)Activator.CreateInstance(System.Web.Compilation.BuildManager.GetType(nameSpace + "." + entity.ObjectName, true));
            ret.Delete         = entity.Delete;
            ret.Id             = entity.ID;
            ret.ReturnBehavior = (CBAPI_Insights.API.ReturnBehavior)Enum.Parse(typeof(CBAPI_Insights.API.ReturnBehavior), entity.ReturnBehavior.ToString());
            ret.Custom         = entity?.CustomFields.Select(f => ConvertCustomField(f)).ToList();


            foreach (EntityField ef in entity.Fields)
            {
                PropertyInfo pi = ret.GetType().GetProperty(ef.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                if (pi == null)
                {
                    continue;
                }

                if (ef is EntityObjectField)
                {
                    EntityObjectField eof = (EntityObjectField)ef;
                    if (eof.Value is EntityImpl)
                    {
                        pi.SetValue(ret, ConvertImpl((EntityImpl)eof.Value, nameSpace));
                    }
                }
                else if (ef is EntityListField)
                {
                    EntityListField elf = (EntityListField)ef;
                    if (elf.Value != null && elf.Value.Length > 0)
                    {
                        Type  arrType = System.Web.Compilation.BuildManager.GetType(nameSpace + "." + elf.Value[0].ObjectName, true);
                        Array arr     = (Array)Activator.CreateInstance(arrType.MakeArrayType(1), new object[] { elf.Value.Length });
                        for (int i = 0; i < elf.Value.Length; i++)
                        {
                            arr.SetValue(ConvertImpl(elf.Value[i], nameSpace), i);
                        }

                        MethodInfo convertMethod = typeof(APIHelper).GetMethod("ConvertArray", BindingFlags.Public | BindingFlags.Static);
                        MethodInfo generic       = convertMethod.MakeGenericMethod(new[] { arrType });


                        pi.SetValue(ret, generic.Invoke(null, new object[] { arr }));
                    }
                }
                else if (ef is EntityValueField)
                {
                    EntityValueField evf = (EntityValueField)ef;
                    if (evf.Value != null)
                    {
                        Type t = pi.PropertyType;

                        object value = null;
                        object po    = Activator.CreateInstance(t);
                        switch (t.Name)
                        {
                        case "StringValue":
                            value = evf.Value;
                            break;

                        case "IntValue":
                            value = int.Parse(evf.Value, CultureInfo.InvariantCulture);
                            break;

                        case "DecimalValue":
                            value = decimal.Parse(evf.Value, CultureInfo.InvariantCulture);
                            break;

                        case "ShortValue":
                            value = short.Parse(evf.Value, CultureInfo.InvariantCulture);
                            break;

                        case "BooleanValue":
                            value = bool.Parse(evf.Value);
                            break;

                        case "ByteValue":
                            value = byte.Parse(evf.Value, CultureInfo.InvariantCulture);
                            break;

                        case "DoubleValue":
                            value = double.Parse(evf.Value, CultureInfo.InvariantCulture);
                            break;

                        case "DateTimeValue":
                            value = DateTime.Parse(evf.Value, CultureInfo.InvariantCulture);
                            break;

                        case "GuidValue":
                            value = Guid.Parse(evf.Value);
                            break;

                        case "LongValue":
                            value = long.Parse(evf.Value, CultureInfo.InvariantCulture);
                            break;
                        }
                        t.InvokeMember("Value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty, null, po, new object[] { value });

                        pi.SetValue(ret, po);
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 6
0
 private static bool?ConvertToNullableBool(EntityValueField field)
 {
     return(field != null ? (bool?)Convert.ToBoolean(field.Value) : null);
 }
Ejemplo n.º 7
0
 private static int?ConvertToNullableInt(EntityValueField field)
 {
     return(field != null ? (int?)Convert.ToInt32(field.Value) : null);
 }
Ejemplo n.º 8
0
 private static decimal?ConvertToNullableDecimal(EntityValueField field)
 {
     return(field != null ? (decimal?)Convert.ToDecimal(field.Value) : null);
 }
        private static void AddPOOrderToBill(PXGraph graph, APInvoiceEntry invoiceEntry, EntityValueField orderType, EntityValueField orderNbr)
        {
            var state = invoiceEntry.Transactions.Cache.GetStateExt <APTran.pOOrderType>(new APTran {
            }) as PXStringState;

            if (state != null && state.AllowedLabels.Contains(orderType.Value))
            {
                orderType.Value = state.ValueLabelDic.Single(p => p.Value == orderType.Value).Key;
            }

            if (orderType.Value == POOrderType.RegularSubcontract)
            {
                var       constructionExt = graph.GetExtension <CN.Subcontracts.AP.GraphExtensions.ApInvoiceEntryAddSubcontractsExtension>();
                POOrderRS line            = (POOrderRS)(constructionExt.Subcontracts.Select().Where(x => (((POOrderRS)x).OrderType == orderType.Value && ((POOrderRS)x).OrderNbr == orderNbr.Value)).FirstOrDefault());
                if (line == null)
                {
                    throw new PXException($"Subcontract {orderNbr.Value} was not found.");
                }

                line.Selected = true;
                constructionExt.Subcontracts.Update(line);
                constructionExt.AddSubcontract.Press();
            }
            else
            {
                var       orderExtension = graph.GetExtension <PO.GraphExtensions.APInvoiceSmartPanel.AddPOOrderExtension>();
                POOrderRS line           = (POOrderRS)(orderExtension.poorderslist.Select().Where(x => (((POOrderRS)x).OrderType == orderType.Value && ((POOrderRS)x).OrderNbr == orderNbr.Value)).FirstOrDefault());

                if (line == null)
                {
                    throw new PXException($"Purchase Order {orderType.Value} {orderNbr.Value} was not found.");
                }

                line.Selected = true;
                orderExtension.poorderslist.Update(line);
                orderExtension.addPOOrder2.Press();
            }
        }
        protected void Payments_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity)
        {
            EntityValueField docType = targetEntity.Fields.SingleOrDefault(f => f.Name == "DocType") as EntityValueField;
            EntityValueField appliedToOrderEntity = targetEntity.Fields.SingleOrDefault(f => f.Name == "AppliedToOrder") as EntityValueField;

            if (appliedToOrderEntity != null && appliedToOrderEntity.Value != null)
            {
                decimal appliedToOrder = decimal.Parse(appliedToOrderEntity.Value);

                SOOrderEntry orderEntry = (SOOrderEntry)graph;
                orderEntry.Save.Press();

                orderEntry.CheckTermsInstallmentType();

                if (docType != null)
                {
                    var state = graph.Caches[typeof(ARRegister)].GetStateExt(new ARRegister(), "DocType") as PXStringState;
                    if (state != null && state.ValueLabelDic != null)
                    {
                        bool keyFound = false;
                        foreach (var rec in state.ValueLabelDic)
                        {
                            if (rec.Value == docType.Value || rec.Key == docType.Value)
                            {
                                keyFound      = true;
                                docType.Value = rec.Key;
                                break;
                            }
                        }
                        if (!keyFound)
                        {
                            docType = null;
                        }
                    }
                }

                PXGraph target;

                orderEntry.CreatePaymentProc(orderEntry.Document.Current, out target, docType != null ? docType.Value : ARPaymentType.Payment);
                ARPaymentEntry paymentEntry = (ARPaymentEntry)target;

                var adjustment = paymentEntry.SOAdjustments.Current;
                adjustment.CuryAdjgAmt = appliedToOrder;
                paymentEntry.SOAdjustments.Update(adjustment);

                ARPayment document = (ARPayment)paymentEntry.Document.Cache.CreateCopy(paymentEntry.Document.Current);

                EntityValueField paymentMethodEntity = targetEntity.Fields.SingleOrDefault(f => f.Name == "PaymentMethod") as EntityValueField;
                if (paymentMethodEntity != null && paymentMethodEntity.Value != null)
                {
                    paymentEntry.Document.Cache.SetValueExt <ARPayment.paymentMethodID>(document, paymentMethodEntity.Value);
                }
                EntityValueField cashAccountEntity = targetEntity.Fields.SingleOrDefault(f => f.Name == "CashAccount") as EntityValueField;
                if (cashAccountEntity != null && cashAccountEntity.Value != null)
                {
                    paymentEntry.Document.Cache.SetValueExt <ARPayment.cashAccountID>(document, cashAccountEntity.Value);
                }
                EntityValueField paymentAmountEntity = targetEntity.Fields.SingleOrDefault(f => f.Name == "PaymentAmount") as EntityValueField;
                if (paymentAmountEntity != null && paymentAmountEntity.Value != null)
                {
                    decimal paymentAmount = decimal.Parse(paymentAmountEntity.Value);
                    paymentEntry.Document.Cache.SetValueExt <ARPayment.curyOrigDocAmt>(document, paymentAmount);
                }
                else
                {
                    paymentEntry.Document.Cache.SetValueExt <ARPayment.curyOrigDocAmt>(document, appliedToOrder);
                }
                paymentEntry.Document.Update(document);

                paymentEntry.Save.Press();
                orderEntry.Cancel.Press();
                try
                {
                    orderEntry.Adjustments.Current = orderEntry.Adjustments.Select().Where(x => (((SOAdjust)x).AdjgDocType == paymentEntry.Document.Current.DocType && ((SOAdjust)x).AdjgRefNbr == paymentEntry.Document.Current.RefNbr)).First();
                }
                catch
                {
                    throw new PXException($"Payment {paymentEntry.Document.Current.DocType} {paymentEntry.Document.Current.RefNbr} was not found in the list of payments applied to order.");
                }
            }
        }
        private static void AddPOReceiptLineToBill(PXGraph graph, APInvoiceEntry invoiceEntry, EntityValueField receiptNbr, EntityValueField receiptLineNbr)
        {
            var receiptLineExtension = graph.GetExtension <PO.GraphExtensions.APInvoiceSmartPanel.AddPOReceiptLineExtension>();

            POReceiptLineAdd line = receiptLineExtension.ReceipLineAdd.Select(receiptNbr.Value, receiptLineNbr.Value);

            if (line == null)
            {
                throw new PXException($"Receipt Line {receiptNbr.Value} - {receiptLineNbr.Value} not found.");
            }

            line.Selected = true;

            receiptLineExtension.poReceiptLinesSelection.Update(line);

            receiptLineExtension.addReceiptLine2.Press();
        }
        private static void AddPOReceiptToBill(PXGraph graph, APInvoiceEntry invoiceEntry, EntityValueField receiptNbr)
        {
            var receiptExtension = graph.GetExtension <PO.GraphExtensions.APInvoiceSmartPanel.AddPOReceiptExtension>();

            POReceipt line = (POReceipt)(receiptExtension.poreceiptslist.Select().Where(x => ((POReceipt)x).ReceiptNbr == receiptNbr.Value).FirstOrDefault());

            if (line == null)
            {
                throw new PXException($"Purchase Receipt {receiptNbr.Value} was not found.");
            }

            line.Selected = true;



            receiptExtension.poreceiptslist.Update(line);

            receiptExtension.addPOReceipt2.Press();
        }