예제 #1
0
 public void Prefetch()
 {
     using (PXConnectionScope s = new PXConnectionScope())
     {
         using (PXDataRecord record = PXDatabase.SelectSingle<Contract>(
             new PXDataField<Contract.contractID>(),
             new PXDataFieldValue<Contract.nonProject>(1)))
         {
             ID = record.GetInt32(0) ?? 0;
         }
     }
 }
예제 #2
0
        public virtual void UpdateBasePrice(PX.Objects.IN.INUpdateBasePrice.UpdateBasePriceRecord item)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    DateTime updateTime     = DateTime.Now;
                    string   uom            = item.BaseUnit;
                    decimal? salesPrice     = item.PendingBasePrice;
                    decimal? lastSalesPrice = item.BasePrice;

                    //So that UI reflects the change:
                    item.BasePrice            = item.PendingBasePrice;
                    item.BasePriceDate        = item.PendingBasePriceDate;
                    item.PendingBasePrice     = 0;
                    item.PendingBasePriceDate = null;

                    PXDatabase.Update <InventoryItem>(
                        new PXDataFieldAssign("BasePrice", PXDbType.DirectExpression, "PendingBasePrice"),
                        new PXDataFieldAssign("BasePriceDate", PXDbType.DirectExpression, "PendingBasePriceDate"),
                        new PXDataFieldAssign("PendingBasePrice", PXDbType.Decimal, 0m),
                        new PXDataFieldAssign("PendingBasePriceDate", PXDbType.DateTime, null),
                        new PXDataFieldAssign("LastBasePrice", PXDbType.DirectExpression, "BasePrice"),
                        new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),
                        new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID)
                        );

                    if (SalesPriceUpdateUnit == SalesPriceUpdateUnitType.SalesUnit)
                    {
                        uom            = item.SalesUnit;
                        salesPrice     = INUnitAttribute.ConvertFromBase(this.Caches[typeof(PX.Objects.IN.INUpdateBasePrice.UpdateBasePriceRecord)], item.InventoryID, item.SalesUnit, item.PendingBasePrice.Value, INPrecision.UNITCOST);
                        lastSalesPrice = INUnitAttribute.ConvertFromBase(this.Caches[typeof(PX.Objects.IN.INUpdateBasePrice.UpdateBasePriceRecord)], item.InventoryID, item.SalesUnit, item.BasePrice.Value, INPrecision.UNITCOST);
                    }

                    PXDatabase.Update <ARSalesPrice>(
                        new PXDataFieldAssign("SalesPrice", PXDbType.Decimal, salesPrice),
                        new PXDataFieldAssign("LastDate", PXDbType.DirectExpression, "EffectiveDate"),
                        new PXDataFieldAssign("PendingPrice", PXDbType.Decimal, 0m),
                        new PXDataFieldAssign("EffectiveDate", PXDbType.DateTime, null),
                        new PXDataFieldAssign("LastPrice", PXDbType.Decimal, lastSalesPrice),
                        new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),
                        new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID),
                        new PXDataFieldRestrict("CustPriceClassID", PXDbType.VarChar, AR.ARPriceClass.EmptyPriceClass),
                        new PXDataFieldRestrict("CuryID", PXDbType.VarChar, Company.Current.BaseCuryID),
                        new PXDataFieldRestrict("UOM", PXDbType.VarChar, uom)
                        );


                    ts.Complete();
                }
            }
        }
예제 #3
0
        protected virtual void CCProcessingCenter_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
        {
            CCProcessingCenter row = e.Row as CCProcessingCenter;

            if (row == null)
            {
                return;
            }
            using (PXConnectionScope scope = new PXConnectionScope())
            {
                row.NeedsExpDateUpdate = CCProcessingHelper.CCProcessingCenterNeedsExpDateUpdate(this, row);
            }
        }
    protected void APAdjust_RowSelecting(PXCache sender, PXRowSelectingEventArgs e)
    {
        APAdjust row = e.Row as APAdjust;

        if (row == null)
        {
            return;
        }
        using (var connScope = new PXConnectionScope())
        {
            row.GetExtension <APAdjustExt>().InvoiceNbr = GetInvoiceNbr(row);
        }
    }
예제 #5
0
        public override void Persist()
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    CheckAndWarnTaxBoxNumbers();

                    base.Persist();
                    TaxBucketLine_Vendor_LineNbr.Cache.Persist(PXDBOperation.Delete);
                    TaxBucketLine_Vendor_LineNbr.Cache.Persisted(false);

                    ts.Complete();
                }
            }
        }
        public virtual void UpdatePrice(POVendorInventoryExt item)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    DateTime updateTime = DateTime.Now;
                    item.LastPrice    = item.EffPrice;
                    item.EffPrice     = item.PendingPrice;
                    item.EffDate      = item.PendingDate;
                    item.PendingPrice = 0m;
                    item.PendingDate  = null;

                    PXDatabase.Update <POVendorInventory>(
                        new PXDataFieldAssign(typeof(POVendorInventory.lastPrice).Name, PXDbType.Decimal, item.LastPrice),
                        new PXDataFieldAssign(typeof(POVendorInventory.effPrice).Name, PXDbType.Decimal, item.EffPrice),
                        new PXDataFieldAssign(typeof(POVendorInventory.effDate).Name, PXDbType.DateTime, item.EffDate),
                        new PXDataFieldAssign(typeof(POVendorInventory.pendingPrice).Name, PXDbType.Decimal, 0m),
                        new PXDataFieldAssign(typeof(POVendorInventory.pendingDate).Name, PXDbType.DateTime, null),
                        new PXDataFieldAssign(typeof(POVendorInventory.lastModifiedDateTime).Name, PXDbType.DateTime, updateTime),
                        new PXDataFieldRestrict(typeof(POVendorInventory.recordID).Name, PXDbType.Int, item.RecordID)
                        );

                    PXDatabase.Update <APSalesPrice>(
                        new PXDataFieldAssign(typeof(APSalesPrice.lastPrice).Name, PXDbType.Decimal, item.LastPrice),
                        new PXDataFieldAssign(typeof(APSalesPrice.salesPrice).Name, PXDbType.Decimal, item.EffPrice),
                        new PXDataFieldAssign(typeof(APSalesPrice.lastDate).Name, PXDbType.DateTime, item.EffDate),
                        new PXDataFieldAssign(typeof(APSalesPrice.pendingPrice).Name, PXDbType.Decimal, 0),
                        new PXDataFieldAssign(typeof(APSalesPrice.effectiveDate).Name, PXDbType.DateTime, null),
                        new PXDataFieldAssign(typeof(APSalesPrice.lastModifiedDateTime).Name, PXDbType.DateTime, updateTime),

                        new PXDataFieldRestrict(typeof(APSalesPrice.inventoryID).Name, PXDbType.Int, item.InventoryID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.vendorID).Name, PXDbType.Int, item.VendorID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.vendorLocationID).Name, PXDbType.Int, item.VendorLocationID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.curyID).Name, PXDbType.NVarChar, item.CuryID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.uOM).Name, PXDbType.NVarChar, item.PurchaseUnit),
                        new PXDataFieldRestrict(typeof(APSalesPrice.subItemID).Name, PXDbType.Int, item.SubItemID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.breakQty).Name, PXDbType.Decimal, 0),
                        new PXDataFieldRestrict(typeof(APSalesPrice.pendingBreakQty).Name, PXDbType.Decimal, 0),
                        new PXDataFieldRestrict(typeof(APSalesPrice.isPromotionalPrice).Name, PXDbType.Bit, false)
                        );

                    ts.Complete();
                }
            }
        }
예제 #7
0
        public virtual void IntegrityCheckProc(INItemSiteSummary itemsite, string minPeriod, bool replanBackorders)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (INItemPlan p in PXSelectReadonly2 <INItemPlan, LeftJoin <Note, On <Note.noteID, Equal <INItemPlan.refNoteID> > >, Where <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <Note.noteID, IsNull> > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, p.PlanID, PXComp.EQ));
                    }

                    foreach (INItemPlan p in PXSelectReadonly2 <INItemPlan,
                                                                InnerJoin <INRegister, On <INRegister.noteID, Equal <INItemPlan.refNoteID>, And <INRegister.siteID, Equal <INItemPlan.siteID> > > >,
                                                                Where <INRegister.docType, Equal <INDocType.transfer>,
                                                                       And <INRegister.released, Equal <boolTrue>,
                                                                            And <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >,
                                                                                 And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> > > > > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, p.PlanID, PXComp.EQ));
                    }

                    foreach (PXResult <INTranSplit, INRegister, INSite, INItemSite> res in PXSelectJoin <INTranSplit,
                                                                                                         InnerJoin <INRegister, On <INRegister.docType, Equal <INTranSplit.docType>, And <INRegister.refNbr, Equal <INTranSplit.refNbr> > >,
                                                                                                                    InnerJoin <INSite, On <INSite.siteID, Equal <INRegister.toSiteID> >,
                                                                                                                               LeftJoin <INItemSite, On <INItemSite.inventoryID, Equal <INTranSplit.inventoryID>, And <INItemSite.siteID, Equal <INRegister.toSiteID> > >,
                                                                                                                                         LeftJoin <INTran, On <INTran.origTranType, Equal <INTranSplit.tranType>, And <INTran.origRefNbr, Equal <INTranSplit.refNbr>, And <INTran.origLineNbr, Equal <INTranSplit.lineNbr> > > >,
                                                                                                                                                   LeftJoin <INItemPlan, On <INItemPlan.planID, Equal <INTranSplit.planID> > > > > > >,
                                                                                                         Where <INRegister.docType, Equal <INDocType.transfer>,
                                                                                                                And2 <Where <INRegister.released, Equal <boolTrue>, And <INTranSplit.released, Equal <boolTrue>,
                                                                                                                                                                         Or <INRegister.released, Equal <boolFalse> > > >,
                                                                                                                      And <INTranSplit.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >,
                                                                                                                           And <INTranSplit.siteID, Equal <Current <INItemSiteSummary.siteID> >,
                                                                                                                                And <INTranSplit.invtMult, Equal <shortMinus1>,
                                                                                                                                     And <INItemPlan.planID, IsNull,
                                                                                                                                          And <INTran.refNbr, IsNull> > > > > > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        INTranSplit split = res;
                        INRegister  doc   = res;

                        if (split.TransferType == INTransferType.OneStep && doc.Released == true)
                        {
                            if (doc.TransferType == INTransferType.OneStep)
                            {
                                doc.TransferType = INTransferType.TwoStep;
                                Caches[typeof(INRegister)].Update(doc);
                            }
                            split.TransferType = INTransferType.TwoStep;
                        }
                        INItemPlan plan = INItemPlanIDAttribute.DefaultValues(this.Caches[typeof(INTranSplit)], res);
                        if (plan.LocationID == null)
                        {
                            plan.LocationID = ((INItemSite)res).DfltReceiptLocationID ?? ((INSite)res).ReceiptLocationID;
                        }

                        plan = (INItemPlan)this.Caches[typeof(INItemPlan)].Insert(plan);

                        split.PlanID = plan.PlanID;
                        Caches[typeof(INTranSplit)].SetStatus(split, PXEntryStatus.Updated);
                    }


                    PXDatabase.Update <INSiteStatus>(
                        new PXDataFieldRestrict <INSiteStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldRestrict <INSiteStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                        new PXDataFieldAssign <INSiteStatus.qtyAvail>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyHardAvail>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyNotAvail>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINIssues>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyInTransit>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyINReplaned>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOBooked>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOShipped>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOShipping>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySOFixed>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtySODropShip>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INSiteStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m)
                        );

                    PXDatabase.Update <INLocationStatus>(
                        new PXDataFieldRestrict <INLocationStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldRestrict <INLocationStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                        new PXDataFieldAssign <INLocationStatus.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INLocationStatus.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INLocationStatus.qtyINIssues>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyINReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyInTransit>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOBooked>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOShipped>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOShipping>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySOFixed>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtySODropShip>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLocationStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m)
                        );

                    PXDatabase.Update <INLotSerialStatus>(
                        new PXDataFieldRestrict <INLotSerialStatus.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldRestrict <INLotSerialStatus.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                        new PXDataFieldAssign <INLotSerialStatus.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INLotSerialStatus.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INLotSerialStatus.qtyINIssues>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyINReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyInTransit>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyINAssemblySupply>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyINAssemblyDemand>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOBooked>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOShipped>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOShipping>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOBackOrdered>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySOFixed>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPOFixedReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtySODropShip>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipOrders>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipPrepared>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyPODropShipReceipts>(PXDbType.Decimal, 0m),
                        new PXDataFieldAssign <INLotSerialStatus.qtyInTransitToSO>(PXDbType.Decimal, 0m)

                        );

                    PXDatabase.Update <INItemLotSerial>(
                        new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldAssign("QtyAvail", PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign("QtyHardAvail", PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign("QtyINTransit", PXDbType.Decimal, 0m)
                        );

                    PXDatabase.Update <INSiteLotSerial>(
                        new PXDataFieldRestrict <INSiteLotSerial.inventoryID>(PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                        new PXDataFieldRestrict <INSiteLotSerial.siteID>(PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                        new PXDataFieldAssign <INSiteLotSerial.qtyAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INSiteLotSerial.qtyHardAvail>(PXDbType.DirectExpression, "QtyOnHand"),
                        new PXDataFieldAssign <INSiteLotSerial.qtyInTransit>(PXDbType.Decimal, 0m)
                        );


                    foreach (PXResult <ReadOnlyLocationStatus, INLocation> res in PXSelectJoinGroupBy <ReadOnlyLocationStatus, InnerJoin <INLocation, On <INLocation.locationID, Equal <ReadOnlyLocationStatus.locationID> > >, Where <ReadOnlyLocationStatus.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <ReadOnlyLocationStatus.siteID, Equal <Current <INItemSiteSummary.siteID> > > >, Aggregate <GroupBy <ReadOnlyLocationStatus.inventoryID, GroupBy <ReadOnlyLocationStatus.siteID, GroupBy <ReadOnlyLocationStatus.subItemID, GroupBy <INLocation.inclQtyAvail, Sum <ReadOnlyLocationStatus.qtyOnHand> > > > > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        SiteStatus status = new SiteStatus();
                        status.InventoryID = ((ReadOnlyLocationStatus)res).InventoryID;
                        status.SubItemID   = ((ReadOnlyLocationStatus)res).SubItemID;
                        status.SiteID      = ((ReadOnlyLocationStatus)res).SiteID;
                        status             = (SiteStatus)sitestatus.Cache.Insert(status);

                        if (((INLocation)res).InclQtyAvail == true)
                        {
                            status.QtyAvail     += ((ReadOnlyLocationStatus)res).QtyOnHand;
                            status.QtyHardAvail += ((ReadOnlyLocationStatus)res).QtyOnHand;
                        }
                        else
                        {
                            status.QtyNotAvail += ((ReadOnlyLocationStatus)res).QtyOnHand;
                        }
                    }

                    INPlanType plan60 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan60> > > .Select(this);

                    INPlanType plan61 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan61> > > .Select(this);

                    INPlanType plan70 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan70> > > .Select(this);

                    INPlanType plan74 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan74> > > .Select(this);

                    INPlanType plan76 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan76> > > .Select(this);

                    INPlanType plan42 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan42> > > .Select(this);

                    INPlanType plan44 = PXSelect <INPlanType, Where <INPlanType.planType, Equal <INPlanConstants.plan44> > > .Select(this);

                    foreach (PXResult <INItemPlan, INPlanType, SOShipLineSplit, POReceiptLineSplit> res in PXSelectJoin <INItemPlan,
                                                                                                                         InnerJoin <INPlanType, On <INPlanType.planType, Equal <INItemPlan.planType> >,
                                                                                                                                    LeftJoin <SOShipLineSplit, On <SOShipLineSplit.planID, Equal <INItemPlan.planID> >,
                                                                                                                                              LeftJoin <POReceiptLineSplit, On <POReceiptLineSplit.planID, Equal <INItemPlan.planID> > > > >,
                                                                                                                         Where <INItemPlan.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INItemPlan.siteID, Equal <Current <INItemSiteSummary.siteID> > > > > .SelectMultiBound(this, new object[] { itemsite }))
                    {
                        INItemPlan         plan     = (INItemPlan)res;
                        INPlanType         plantype = (INPlanType)res;
                        INPlanType         locplantype;
                        SOShipLineSplit    sosplit = (SOShipLineSplit)res;
                        POReceiptLineSplit posplit = (POReceiptLineSplit)res;

                        if (plan.InventoryID != null &&
                            plan.SubItemID != null &&
                            plan.SiteID != null)
                        {
                            switch (plan.PlanType)
                            {
                            case INPlanConstants.Plan61:
                            case INPlanConstants.Plan63:
                                locplantype = plantype;

                                if (sosplit.ShipmentNbr != null)
                                {
                                    SOOrderType ordetype = PXSelect <SOOrderType, Where <SOOrderType.orderType, Equal <Current <SOShipLineSplit.origOrderType> > > > .SelectSingleBound(this, new object[] { sosplit });

                                    if (plan.OrigPlanType == null)
                                    {
                                        plan.OrigPlanType = ordetype.OrderPlanType;
                                    }

                                    if (plan.OrigPlanType == INPlanConstants.Plan60 && sosplit.IsComponentItem != true)
                                    {
                                        plantype = plantype - plan60;
                                    }

                                    if ((plan.OrigPlanType == INPlanConstants.Plan61 || plan.OrigPlanType == INPlanConstants.Plan63) && sosplit.IsComponentItem != true)
                                    {
                                        plantype = plantype - plan61;
                                    }
                                }

                                break;

                            case INPlanConstants.Plan71:
                            case INPlanConstants.Plan72:
                                locplantype = plantype;
                                if (posplit.ReceiptNbr == null)
                                {
                                    PXDatabase.Delete <INItemPlan>(new PXDataFieldRestrict("PlanID", PXDbType.BigInt, 8, plan.PlanID, PXComp.EQ));
                                    continue;
                                }
                                if (posplit.PONbr != null)
                                {
                                    plantype = plantype - plan70;
                                }
                                break;

                            case INPlanConstants.Plan77:
                                locplantype = plantype;
                                if (posplit.ReceiptNbr != null && posplit.PONbr != null)
                                {
                                    plantype = plantype - plan76;
                                }

                                break;

                            case INPlanConstants.Plan75:
                                locplantype = plantype;
                                if (posplit.ReceiptNbr != null && posplit.PONbr != null)
                                {
                                    plantype = plantype - plan74;
                                }
                                break;

                            case INPlanConstants.Plan43:
                            case INPlanConstants.Plan45:
                                if (plan.OrigPlanType == INPlanConstants.Plan44)
                                {
                                    plantype = plantype - plan44;
                                }

                                if (plan.OrigPlanType == INPlanConstants.Plan42)
                                {
                                    plantype = plantype - plan42;
                                }
                                locplantype = plantype;
                                break;

                            default:
                                locplantype = plantype;
                                break;
                            }

                            if (plan.LocationID != null)
                            {
                                LocationStatus item = INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <LocationStatus>(this, plan, locplantype, true);
                                INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteStatus>(this, plan, plantype, (bool)item.InclQtyAvail);
                                if (!string.IsNullOrEmpty(plan.LotSerialNbr))
                                {
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <LotSerialStatus>(this, plan, locplantype, true);
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <ItemLotSerial>(this, plan, locplantype, true);
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteLotSerial>(this, plan, locplantype, true);
                                }
                            }
                            else
                            {
                                INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteStatus>(this, plan, plantype, true);
                                if (!string.IsNullOrEmpty(plan.LotSerialNbr))
                                {
                                    //TODO: check if LotSerialNbr was allocated on OrigPlanType
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <ItemLotSerial>(this, plan, plantype, true);
                                    INItemPlanIDAttribute.UpdateAllocatedQuantitiesBase <SiteLotSerial>(this, plan, plantype, true);
                                }
                            }
                        }
                    }
                    if (replanBackorders)
                    {
                        INReleaseProcess.ReplanBackOrders(this);
                        initemplan.Cache.Persist(PXDBOperation.Insert);
                        initemplan.Cache.Persist(PXDBOperation.Update);
                    }

                    Caches[typeof(INTranSplit)].Persist(PXDBOperation.Update);

                    sitestatus.Cache.Persist(PXDBOperation.Insert);
                    sitestatus.Cache.Persist(PXDBOperation.Update);

                    locationstatus.Cache.Persist(PXDBOperation.Insert);
                    locationstatus.Cache.Persist(PXDBOperation.Update);

                    lotserialstatus.Cache.Persist(PXDBOperation.Insert);
                    lotserialstatus.Cache.Persist(PXDBOperation.Update);

                    itemlotserial.Cache.Persist(PXDBOperation.Insert);
                    itemlotserial.Cache.Persist(PXDBOperation.Update);

                    sitelotserial.Cache.Persist(PXDBOperation.Insert);
                    sitelotserial.Cache.Persist(PXDBOperation.Update);

                    if (minPeriod != null)
                    {
                        FinPeriod period =
                            PXSelect <FinPeriod,
                                      Where <FinPeriod.finPeriodID, Equal <Required <FinPeriod.finPeriodID> > > >
                            .SelectWindowed(this, 0, 1, minPeriod);

                        if (period == null)
                        {
                            return;
                        }
                        DateTime startDate = (DateTime)period.StartDate;

                        PXDatabase.Delete <INItemCostHist>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("CostSiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE)
                            );

                        PXDatabase.Delete <INItemSalesHistD>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("QtyPlanSales", PXDbType.Decimal, 0m),
                            new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE)

                            );
                        PXDatabase.Delete <INItemCustSalesStats>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("LastDate", PXDbType.DateTime, 8, startDate, PXComp.GE));

                        PXDatabase.Update <INItemSalesHistD>(
                            new PXDataFieldAssign("QtyIssues", PXDbType.Decimal, 0m),
                            new PXDataFieldAssign("QtyExcluded", PXDbType.Decimal, 0m),
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE)
                            );

                        foreach (INLocation loc in PXSelectReadonly2 <INLocation, InnerJoin <INItemCostHist, On <INItemCostHist.costSiteID, Equal <INLocation.locationID> > >, Where <INLocation.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INItemCostHist.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> > > > > .SelectMultiBound(this, new object[] { itemsite }))
                        {
                            PXDatabase.Delete <INItemCostHist>(
                                new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                                new PXDataFieldRestrict("CostSiteID", PXDbType.Int, 4, loc.LocationID, PXComp.EQ),
                                new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE)
                                );
                        }

                        PXDatabase.Delete <INItemSiteHist>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("FinPeriodID", PXDbType.Char, 6, minPeriod, PXComp.GE)
                            );

                        PXDatabase.Delete <INItemSiteHistD>(
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, 4, itemsite.InventoryID, PXComp.EQ),
                            new PXDataFieldRestrict("SiteID", PXDbType.Int, 4, itemsite.SiteID, PXComp.EQ),
                            new PXDataFieldRestrict("SDate", PXDbType.DateTime, 8, startDate, PXComp.GE)
                            );

                        INTran prev_tran = null;
                        foreach (PXResult <INTran, INTranSplit> res in PXSelectReadonly2 <INTran, InnerJoin <INTranSplit, On <INTranSplit.tranType, Equal <INTran.tranType>, And <INTranSplit.refNbr, Equal <INTran.refNbr>, And <INTranSplit.lineNbr, Equal <INTran.lineNbr> > > > >, Where <INTran.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INTran.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INTran.finPeriodID, GreaterEqual <Required <INTran.finPeriodID> >, And <INTran.released, Equal <boolTrue> > > > >, OrderBy <Asc <INTran.tranType, Asc <INTran.refNbr, Asc <INTran.lineNbr> > > > > .SelectMultiBound(this, new object[] { itemsite }, minPeriod))
                        {
                            INTran      tran  = res;
                            INTranSplit split = res;

                            if (!Caches[typeof(INTran)].ObjectsEqual(prev_tran, tran))
                            {
                                INReleaseProcess.UpdateSalesHistD(this, tran);
                                INReleaseProcess.UpdateCustSalesStats(this, tran);

                                prev_tran = tran;
                            }

                            if (split.BaseQty != 0m)
                            {
                                INReleaseProcess.UpdateSiteHist(this, res, split);
                                INReleaseProcess.UpdateSiteHistD(this, split);
                            }
                        }

                        foreach (PXResult <INTran, INTranCost> res in PXSelectReadonly2 <INTran, InnerJoin <INTranCost, On <INTranCost.tranType, Equal <INTran.tranType>, And <INTranCost.refNbr, Equal <INTran.refNbr>, And <INTranCost.lineNbr, Equal <INTran.lineNbr> > > > >, Where <INTran.inventoryID, Equal <Current <INItemSiteSummary.inventoryID> >, And <INTran.siteID, Equal <Current <INItemSiteSummary.siteID> >, And <INTranCost.finPeriodID, GreaterEqual <Required <INTran.finPeriodID> >, And <INTran.released, Equal <boolTrue> > > > > > .SelectMultiBound(this, new object[] { itemsite }, minPeriod))
                        {
                            INReleaseProcess.UpdateCostHist(this, (INTranCost)res, (INTran)res);
                        }

                        itemcosthist.Cache.Persist(PXDBOperation.Insert);
                        itemcosthist.Cache.Persist(PXDBOperation.Update);

                        itemsitehist.Cache.Persist(PXDBOperation.Insert);
                        itemsitehist.Cache.Persist(PXDBOperation.Update);

                        itemsitehistd.Cache.Persist(PXDBOperation.Insert);
                        itemsitehistd.Cache.Persist(PXDBOperation.Update);

                        itemsalehistd.Cache.Persist(PXDBOperation.Insert);
                        itemsalehistd.Cache.Persist(PXDBOperation.Update);

                        itemcustsalesstats.Cache.Persist(PXDBOperation.Insert);
                        itemcustsalesstats.Cache.Persist(PXDBOperation.Update);
                    }

                    ts.Complete();
                }

                sitestatus.Cache.Persisted(false);
                locationstatus.Cache.Persisted(false);
                lotserialstatus.Cache.Persisted(false);

                itemcosthist.Cache.Persisted(false);
                itemsitehist.Cache.Persisted(false);
                itemsitehistd.Cache.Persisted(false);
            }
        }
예제 #8
0
        public virtual void ReleaseLCTrans(IEnumerable <LandedCostTran> aTranSet, DocumentList <INRegister> aINCreated, DocumentList <APInvoice> aAPCreated)
        {
            Dictionary <int, APInvoiceEntry>    apGraphs = new Dictionary <int, APInvoiceEntry>();
            Dictionary <int, INAdjustmentEntry> inGraphs = new Dictionary <int, INAdjustmentEntry>();
            Dictionary <int, int>    combinations        = new Dictionary <int, int>();
            List <APRegister>        forReleaseAP        = new List <APRegister>();
            List <INRegister>        forReleaseIN        = new List <INRegister>();
            DocumentList <APInvoice> apDocuments         = new DocumentList <APInvoice>(this);
            POSetup poSetupR              = this.poSetup.Select();
            bool    autoReleaseIN         = poSetupR.AutoReleaseLCIN.Value;
            bool    autoReleaseAP         = poSetupR.AutoReleaseAP.Value;
            bool    noApplicableItems     = false;
            bool    noApplicableTransfers = false;

            foreach (LandedCostTran iTran in aTranSet)
            {
                LandedCostCode lcCode = PXSelect <LandedCostCode, Where <LandedCostCode.landedCostCodeID, Equal <Required <LandedCostCode.landedCostCodeID> > > > .Select(this, iTran.LandedCostCodeID);

                if ((string.IsNullOrEmpty(iTran.APDocType) || string.IsNullOrEmpty(iTran.APRefNbr)) && iTran.PostponeAP == false)
                {
                    APInvoiceEntry apGraph = null;
                    foreach (KeyValuePair <int, APInvoiceEntry> iGraph in apGraphs)
                    {
                        APInvoice apDoc = iGraph.Value.Document.Current;
                        string    terms = String.IsNullOrEmpty(iTran.TermsID) ? lcCode.TermsID : iTran.TermsID;

                        if (apDoc.VendorID == iTran.VendorID &&
                            apDoc.VendorLocationID == iTran.VendorLocationID &&
                            apDoc.InvoiceNbr == iTran.InvoiceNbr &&
                            apDoc.CuryID == iTran.CuryID &&
                            apDoc.DocDate == iTran.InvoiceDate &&
                            apDoc.TermsID == terms &&
                            (apDoc.DocType == AP.APDocType.Invoice && iTran.CuryLCAmount > Decimal.Zero))
                        {
                            combinations.Add(iTran.LCTranID.Value, iGraph.Key);
                            apGraph = iGraph.Value;
                        }
                    }
                    if (apGraph == null)
                    {
                        apGraph = PXGraph.CreateInstance <APInvoiceEntry>();
                        if (autoReleaseAP)
                        {
                            apGraph.APSetup.Current.RequireControlTotal    = false;
                            apGraph.APSetup.Current.RequireControlTaxTotal = false;
                            apGraph.APSetup.Current.HoldEntry = false;
                        }
                        apGraphs[iTran.LCTranID.Value] = apGraph;
                    }
                    apGraph.InvoiceLandedCost(iTran, null, false);
                    apDocuments.Add(apGraph.Document.Current);
                }

                if (lcCode.AllocationMethod != LandedCostAllocationMethod.None)
                {
                    List <POReceiptLine>       receiptLines = new List <POReceiptLine>();
                    List <LandedCostTranSplit> lcTranSplits = new List <LandedCostTranSplit>();
                    GetReceiptLinesToAllocate(receiptLines, lcTranSplits, iTran);
                    var lch = new LandedCostHelper(this, false);
                    List <LandedCostHelper.POReceiptLineAdjustment> result = lch.AllocateLCOverRCTLines(receiptLines, lcCode, iTran, lcTranSplits);
                    if (result.Count > 0)
                    {
                        if (result.Count == 1 && !result[0].Item1.InventoryID.HasValue)
                        {
                            noApplicableTransfers = !lch.HasApplicableTransfers;
                            noApplicableItems     = true;                          //Skip Cost adjustment creation;
                        }
                        else
                        {
                            INAdjustmentEntry inGraph = PXGraph.CreateInstance <INAdjustmentEntry>();
                            if (autoReleaseIN)
                            {
                                inGraph.insetup.Current.RequireControlTotal = false;
                                inGraph.insetup.Current.HoldEntry           = false;
                            }
                            CreateCostAjustment(inGraph, lcCode, iTran, result);
                            inGraphs[iTran.LCTranID.Value] = inGraph;
                        }
                    }
                }
            }

            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (LandedCostTran iTran in aTranSet)
                    {
                        bool           needUpdate = false;
                        LandedCostTran tran       = this.landedCostTrans.Select(iTran.LCTranID);

                        if (apGraphs.ContainsKey(tran.LCTranID.Value))
                        {
                            APInvoiceEntry apGraph = apGraphs[iTran.LCTranID.Value];
                            apGraph.Save.Press();
                            tran.APDocType = apGraph.Document.Current.DocType;
                            tran.APRefNbr  = apGraph.Document.Current.RefNbr;
                            if (!tran.APCuryInfoID.HasValue)
                            {
                                tran.APCuryInfoID = apGraph.Document.Current.CuryInfoID;
                            }
                            tran.Processed = true;
                            if (apGraph.Document.Current.Hold != true)
                            {
                                forReleaseAP.Add(apGraph.Document.Current);
                            }
                            if (aAPCreated != null)
                            {
                                aAPCreated.Add(apGraph.Document.Current);
                            }
                            needUpdate = true;
                        }
                        else if (combinations.ContainsKey(tran.LCTranID.Value))
                        {
                            //Its already saved at this point
                            APInvoiceEntry apGraph = apGraphs[combinations[tran.LCTranID.Value]];
                            tran.APDocType = apGraph.Document.Current.DocType;
                            tran.APRefNbr  = apGraph.Document.Current.RefNbr;
                            if (!tran.APCuryInfoID.HasValue)
                            {
                                tran.APCuryInfoID = apGraph.Document.Current.CuryInfoID;
                            }
                            tran.Processed = true;
                            needUpdate     = true;
                        }

                        if (inGraphs.ContainsKey(tran.LCTranID.Value))
                        {
                            INAdjustmentEntry inGraph = inGraphs[iTran.LCTranID.Value];
                            inGraph.Save.Press();
                            tran.INDocType = inGraph.adjustment.Current.DocType;
                            tran.INRefNbr  = inGraph.adjustment.Current.RefNbr;
                            tran.Processed = true;
                            forReleaseIN.Add(inGraph.adjustment.Current);
                            if (aINCreated != null)
                            {
                                aINCreated.Add(inGraph.adjustment.Current);
                            }
                            needUpdate = true;
                        }
                        if (!needUpdate && tran.PostponeAP == true)
                        {
                            LandedCostCode lcCode = PXSelect <LandedCostCode, Where <LandedCostCode.landedCostCodeID, Equal <Required <LandedCostCode.landedCostCodeID> > > > .Select(this, iTran.LandedCostCodeID);

                            if (lcCode.AllocationMethod == LandedCostAllocationMethod.None)
                            {
                                tran.Processed = true;
                                needUpdate     = true;                             //This combination needs no processing here but must be updated
                            }
                        }
                        if (needUpdate)
                        {
                            LandedCostTran copy = (LandedCostTran)this.landedCostTrans.Cache.CreateCopy(tran);
                            tran = this.landedCostTrans.Update(copy);
                        }
                    }
                    this.Actions.PressSave();
                    ts.Complete();
                }
            }
            if (noApplicableTransfers == true)
            {
                throw new NoApplicableSourceException(Messages.LandedCostCannotBeDistributed);
            }
            if (noApplicableItems == true)
            {
                throw new NoApplicableSourceException(Messages.LandedCostAmountRemainderCannotBeDistributedMultyLines);
            }

            if (autoReleaseAP)
            {
                if (forReleaseAP.Count > 0)
                {
                    APDocumentRelease.ReleaseDoc(forReleaseAP, true);
                }
            }

            if (autoReleaseIN)
            {
                if (forReleaseIN.Count > 0)
                {
                    INDocumentRelease.ReleaseDoc(forReleaseIN, false);
                }
            }
        }
예제 #9
0
        public virtual void UpdateDiscount(string discountID, string discountSequenceID, DateTime?filterDate)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (DiscountSequenceDetail detail in PXSelect <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >,
                                                                                                       And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.isLast, Equal <False> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        if (detail.PendingDate != null && detail.PendingDate.Value <= filterDate.Value)
                        {
                            if (!PXDatabase.Update <DiscountSequenceDetail>(
                                    new PXDataFieldAssign("IsActive", PXDbType.Bit, detail.IsActive),
                                    new PXDataFieldAssign("Amount", PXDbType.Decimal, detail.Amount),
                                    new PXDataFieldAssign("AmountTo", PXDbType.Decimal, detail.AmountTo),
                                    new PXDataFieldAssign("Quantity", PXDbType.Decimal, detail.Quantity),
                                    new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, detail.QuantityTo),
                                    new PXDataFieldAssign("Discount", PXDbType.Decimal, detail.Discount),
                                    new PXDataFieldAssign("FreeItemQty", PXDbType.Decimal, detail.FreeItemQty),
                                    new PXDataFieldAssign("LastDate", PXDbType.DateTime, detail.PendingDate),
                                    new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null),
                                    new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m),
                                    new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null),
                                    new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m),
                                    new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null),
                                    new PXDataFieldRestrict("DiscountID", PXDbType.NVarChar, detail.DiscountID),
                                    new PXDataFieldRestrict("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID),
                                    new PXDataFieldRestrict("LineNbr", PXDbType.Int, detail.LineNbr),
                                    new PXDataFieldRestrict("IsLast", PXDbType.Bit, 1)
                                    ))
                            {
                                PXDatabase.Insert <DiscountSequenceDetail>(
                                    new PXDataFieldAssign("DiscountID", PXDbType.NVarChar, detail.DiscountID),
                                    new PXDataFieldAssign("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID),
                                    new PXDataFieldAssign("LineNbr", PXDbType.Int, detail.LineNbr),
                                    new PXDataFieldAssign("IsActive", PXDbType.Bit, detail.IsActive),
                                    new PXDataFieldAssign("IsLast", PXDbType.Bit, 1),
                                    new PXDataFieldAssign("Amount", PXDbType.Decimal, detail.Amount),
                                    new PXDataFieldAssign("AmountTo", PXDbType.Decimal, detail.AmountTo),
                                    new PXDataFieldAssign("Quantity", PXDbType.Decimal, detail.Quantity),
                                    new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, detail.QuantityTo),
                                    new PXDataFieldAssign("Discount", PXDbType.Decimal, detail.Discount),
                                    new PXDataFieldAssign("FreeItemQty", PXDbType.Decimal, detail.FreeItemQty),
                                    new PXDataFieldAssign("LastDate", PXDbType.DateTime, detail.PendingDate),
                                    new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null),
                                    new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m),
                                    new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null),
                                    new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m),
                                    new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null),
                                    new PXDataFieldAssign("CreatedByID", PXDbType.UniqueIdentifier, 16, detail.CreatedByID),
                                    new PXDataFieldAssign("CreatedByScreenID", PXDbType.Char, 8, detail.CreatedByScreenID),
                                    new PXDataFieldAssign("CreatedDateTime", PXDbType.DateTime, 8, detail.CreatedDateTime),
                                    new PXDataFieldAssign("LastModifiedByID", PXDbType.UniqueIdentifier, 16, detail.LastModifiedByID),
                                    new PXDataFieldAssign("LastModifiedByScreenID", PXDbType.Char, 8, detail.LastModifiedByScreenID),
                                    new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, 8, detail.LastModifiedDateTime)
                                    );
                            }



                            PXDatabase.Update <DiscountSequenceDetail>(
                                new PXDataFieldAssign("Amount", PXDbType.DirectExpression, "PendingAmount"),
                                new PXDataFieldAssign("Quantity", PXDbType.DirectExpression, "PendingQuantity"),
                                new PXDataFieldAssign("Discount", PXDbType.DirectExpression, "PendingDiscount"),
                                new PXDataFieldAssign("FreeItemQty", PXDbType.DirectExpression, "PendingFreeItemQty"),
                                new PXDataFieldAssign("LastDate", PXDbType.DirectExpression, "PendingDate"),
                                new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null),
                                new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m),
                                new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null),
                                new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, 0m),
                                new PXDataFieldAssign("PendingDate", PXDbType.DateTime, null),
                                new PXDataFieldRestrict("DiscountID", PXDbType.NVarChar, detail.DiscountID),
                                new PXDataFieldRestrict("DiscountSequenceID", PXDbType.NVarChar, detail.DiscountSequenceID),
                                new PXDataFieldRestrict("LineNbr", PXDbType.Int, detail.LineNbr),
                                new PXDataFieldRestrict("IsLast", PXDbType.Bit, 0)
                                );
                        }
                    }

                    foreach (DiscountSequenceDetail detail in PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >,
                                                                                                               And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        DiscountSequenceDetail amonextval = PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >,
                                                                                                             And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.amount, Greater <Required <DiscountSequenceDetail.amount> >, And <DiscountSequenceDetail.isLast, Equal <Required <DiscountSequenceDetail.isLast> >, And <DiscountSequenceDetail.isActive, Equal <True> > > > > >,
                                                                              OrderBy <Asc <DiscountSequenceDetail.amount> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Amount, detail.IsLast);

                        DiscountSequenceDetail qtynextval = PXSelectReadonly <DiscountSequenceDetail, Where <DiscountSequenceDetail.discountID, Equal <Required <DiscountSequenceDetail.discountID> >,
                                                                                                             And <DiscountSequenceDetail.discountSequenceID, Equal <Required <DiscountSequenceDetail.discountSequenceID> >, And <DiscountSequenceDetail.quantity, Greater <Required <DiscountSequenceDetail.quantity> >, And <DiscountSequenceDetail.isLast, Equal <Required <DiscountSequenceDetail.isLast> >, And <DiscountSequenceDetail.isActive, Equal <True> > > > > >,
                                                                              OrderBy <Asc <DiscountSequenceDetail.quantity> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Quantity, detail.IsLast);

                        PXDatabase.Update <DiscountSequenceDetail>(
                            new PXDataFieldAssign("AmountTo", PXDbType.Decimal, (amonextval == null ? null : amonextval.Amount)),
                            new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, (qtynextval == null ? null : qtynextval.Quantity)),
                            new PXDataFieldRestrict("DiscountDetailsID", PXDbType.Int, detail.DiscountDetailsID)
                            );
                    }


                    DiscountSequence sequence = PXSelect <DiscountSequence,
                                                          Where <DiscountSequence.discountID, Equal <Required <DiscountSequence.discountID> >,
                                                                 And <DiscountSequence.discountSequenceID, Equal <Required <DiscountSequence.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID);

                    if (sequence != null && sequence.StartDate != null && sequence.PendingFreeItemID != null)
                    {
                        PXDatabase.Update <DiscountSequence>(
                            new PXDataFieldAssign("LastFreeItemID", PXDbType.DirectExpression, "FreeItemID"),
                            new PXDataFieldAssign("FreeItemID", PXDbType.DirectExpression, "PendingFreeItemID"),
                            new PXDataFieldAssign("PendingFreeItemID", PXDbType.Int, null),
                            new PXDataFieldAssign("UpdateDate", PXDbType.DateTime, filterDate.Value),
                            //new PXDataFieldAssign("StartDate", PXDbType.DateTime, null),
                            new PXDataFieldRestrict("DiscountID", PXDbType.VarChar, discountID),
                            new PXDataFieldRestrict("DiscountSequenceID", PXDbType.VarChar, discountSequenceID)
                            );
                    }
                    else if (sequence != null && sequence.StartDate != null)
                    {
                        PXDatabase.Update <DiscountSequence>(
                            new PXDataFieldAssign("UpdateDate", PXDbType.DateTime, filterDate.Value),
                            new PXDataFieldRestrict("DiscountID", PXDbType.VarChar, discountID),
                            new PXDataFieldRestrict("DiscountSequenceID", PXDbType.VarChar, discountSequenceID)
                            );
                    }
                    ts.Complete();
                }
            }
        }
예제 #10
0
        public static void ReleaseDoc(EPExpenseClaim claim)
        {
            APInvoiceEntry    docgraph     = PXGraph.CreateInstance <APInvoiceEntry>();
            ExpenseClaimEntry expenseclaim = PXGraph.CreateInstance <ExpenseClaimEntry>();

            if (claim.FinPeriodID == null)
            {
                throw new PXException(Messages.ReleaseClaimWithoutFinPeriod);
            }
            //docgraph.FieldVerifying.AddHandler<APInvoice.vendorLocationID>(APInterceptor);

            EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPExpenseClaim.employeeID> > > > .Select(docgraph, claim.EmployeeID);

            Location emplocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <EPExpenseClaim.employeeID> >, And <Location.locationID, Equal <Required <EPExpenseClaim.locationID> > > > > .Select(docgraph, claim.EmployeeID, claim.LocationID);

            EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(docgraph);

            APSetup apsetup = PXSelectReadonly <APSetup> .Select(docgraph);

            docgraph.vendor.Current   = employee;
            docgraph.location.Current = emplocation;

            CurrencyInfo infoOriginal = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaim.curyInfoID> > > > .Select(docgraph, claim.CuryInfoID);

            CurrencyInfo info = PXCache <CurrencyInfo> .CreateCopy(infoOriginal);

            info.CuryInfoID = null;
            info            = docgraph.currencyinfo.Insert(info);
            APInvoice invoice = new APInvoice();

            invoice.CuryInfoID = info.CuryInfoID;

            invoice.Hold     = true;
            invoice.Released = false;
            invoice.Printed  = false;
            invoice.OpenDoc  = true;

            invoice.DocDate          = claim.DocDate;
            invoice.InvoiceNbr       = claim.RefNbr;
            invoice.DocDesc          = claim.DocDesc;
            invoice.VendorID         = claim.EmployeeID;
            invoice.CuryID           = info.CuryID;
            invoice.VendorLocationID = claim.LocationID;
            invoice.APAccountID      = emplocation != null ? emplocation.APAccountID : null;
            invoice.APSubID          = emplocation != null ? emplocation.APSubID : null;
            invoice.TaxZoneID        = claim.TaxZoneID;
            invoice = docgraph.Document.Insert(invoice);

            PXCache claimcache       = docgraph.Caches[typeof(EPExpenseClaim)];
            PXCache claimdetailcache = docgraph.Caches[typeof(EPExpenseClaimDetails)];

            if (epsetup.CopyNotesAP == true)
            {
                string note = PXNoteAttribute.GetNote(claimcache, claim);
                if (note != null)
                {
                    PXNoteAttribute.SetNote(docgraph.Document.Cache, invoice, note);
                }
            }
            if (epsetup.CopyFilesAP == true)
            {
                Guid[] files = PXNoteAttribute.GetFileNotes(claimcache, claim);
                if (files != null && files.Length > 0)
                {
                    PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, invoice, files);
                }
            }

            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc);

                    foreach (PXResult <EPExpenseClaimDetails, Contract> res in PXSelectJoin <EPExpenseClaimDetails,
                                                                                             LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID> > >,
                                                                                             Where <EPExpenseClaimDetails.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(docgraph, claim.RefNbr))
                    {
                        EPExpenseClaimDetails claimdetail = (EPExpenseClaimDetails)res;
                        Contract contract = (Contract)res;

                        if (claimdetail.TaskID != null)
                        {
                            PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(expenseclaim, claimdetail.TaskID);

                            if (task != null && !(bool)task.VisibleInAP)
                            {
                                throw new PXException(PM.Messages.TaskInvisibleInModule, task.TaskCD, BatchModule.AP);
                            }
                        }

                        APTran tran = new APTran();
                        tran.InventoryID  = claimdetail.InventoryID;
                        tran.TranDesc     = claimdetail.TranDesc;
                        tran.CuryUnitCost = claimdetail.CuryUnitCost;
                        tran.Qty          = claimdetail.Qty;
                        tran.UOM          = claimdetail.UOM;
                        tran.NonBillable  = claimdetail.Billable != true;
                        tran.CuryLineAmt  = claimdetail.CuryTranAmt;
                        tran.Date         = claimdetail.ExpenseDate;

                        if (contract.BaseType == PM.PMProject.ProjectBaseType.Project)
                        {
                            tran.ProjectID = claimdetail.ContractID;
                        }
                        else
                        {
                            tran.ProjectID = PM.ProjectDefaultAttribute.NonProject(docgraph);
                        }

                        tran.TaskID        = claimdetail.TaskID;
                        tran.AccountID     = claimdetail.ExpenseAccountID;
                        tran.SubID         = claimdetail.ExpenseSubID;
                        tran.TaxCategoryID = claimdetail.TaxCategoryID;
                        tran = docgraph.Transactions.Insert(tran);
                        if (epsetup.CopyNotesAP == true)
                        {
                            string note = PXNoteAttribute.GetNote(claimdetailcache, claimdetail);
                            if (note != null)
                            {
                                PXNoteAttribute.SetNote(docgraph.Transactions.Cache, tran, note);
                            }
                        }
                        if (epsetup.CopyFilesAP == true)
                        {
                            Guid[] files = PXNoteAttribute.GetFileNotes(claimdetailcache, claimdetail);
                            if (files != null && files.Length > 0)
                            {
                                PXNoteAttribute.SetFileNotes(docgraph.Transactions.Cache, tran, files);
                            }
                        }
                        claimdetail.Released = true;
                        expenseclaim.ExpenseClaimDetails.Update(claimdetail);
                    }

                    foreach (EPTaxTran tax in PXSelect <EPTaxTran, Where <EPTaxTran.refNbr, Equal <Required <EPTaxTran.refNbr> > > > .Select(docgraph, claim.RefNbr))
                    {
                        APTaxTran new_aptax = new APTaxTran();
                        new_aptax.TaxID = tax.TaxID;

                        new_aptax = docgraph.Taxes.Insert(new_aptax);

                        if (new_aptax != null)
                        {
                            new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax);

                            new_aptax.TaxRate        = tax.TaxRate;
                            new_aptax.CuryTaxableAmt = tax.CuryTaxableAmt;
                            new_aptax.CuryTaxAmt     = tax.CuryTaxAmt;
                            new_aptax = docgraph.Taxes.Update(new_aptax);
                        }
                    }

                    invoice.CuryOrigDocAmt = invoice.CuryDocBal;
                    invoice.Hold           = false;
                    docgraph.Document.Update(invoice);
                    docgraph.Save.Press();
                    claim.Status    = EPClaimStatus.Released;
                    claim.Released  = true;
                    claim.APRefNbr  = invoice.RefNbr;
                    claim.APDocType = invoice.DocType;
                    expenseclaim.ExpenseClaim.Update(claim);

                    #region EP History Update
                    EPHistory hist = new EPHistory();
                    hist.EmployeeID  = invoice.VendorID;
                    hist.FinPeriodID = invoice.FinPeriodID;
                    hist             = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(hist);

                    hist.FinPtdClaimed += invoice.DocBal;
                    hist.FinYtdClaimed += invoice.DocBal;
                    if (invoice.FinPeriodID == invoice.TranPeriodID)
                    {
                        hist.TranPtdClaimed += invoice.DocBal;
                        hist.TranYtdClaimed += invoice.DocBal;
                    }
                    else
                    {
                        EPHistory tranhist = new EPHistory();
                        tranhist.EmployeeID      = invoice.VendorID;
                        tranhist.FinPeriodID     = invoice.TranPeriodID;
                        tranhist                 = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(tranhist);
                        tranhist.TranPtdClaimed += invoice.DocBal;
                        tranhist.TranYtdClaimed += invoice.DocBal;
                    }
                    expenseclaim.Views.Caches.Add(typeof(EPHistory));
                    #endregion

                    expenseclaim.Save.Press();

                    ts.Complete();
                }
            }
            if ((bool)epsetup.AutomaticReleaseAP == true)
            {
                List <APRegister> doclist = new List <APRegister>();
                doclist.Add(docgraph.Document.Current);
                APDocumentRelease.ReleaseDoc(doclist, false);
            }
        }
예제 #11
0
        public virtual void UpdateSalesPrice(APSalesPrice item)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    DateTime updateTime = DateTime.Now;

                    //FOR UI:
                    item.LastPrice       = item.SalesPrice;
                    item.SalesPrice      = item.PendingPrice;
                    item.LastBreakQty    = item.BreakQty;
                    item.BreakQty        = item.PendingBreakQty;
                    item.LastDate        = item.EffectiveDate;
                    item.EffectiveDate   = null;
                    item.PendingPrice    = 0;
                    item.PendingBreakQty = 0;

                    PXDatabase.Update <APSalesPrice>(
                        new PXDataFieldAssign(typeof(APSalesPrice.lastPrice).Name, PXDbType.Decimal, item.LastPrice),
                        new PXDataFieldAssign(typeof(APSalesPrice.lastBreakQty).Name, PXDbType.Decimal, item.LastBreakQty),
                        new PXDataFieldAssign(typeof(APSalesPrice.salesPrice).Name, PXDbType.Decimal, item.SalesPrice),
                        new PXDataFieldAssign(typeof(APSalesPrice.breakQty).Name, PXDbType.Decimal, item.BreakQty),
                        new PXDataFieldAssign(typeof(APSalesPrice.lastDate).Name, PXDbType.DateTime, item.LastDate),
                        new PXDataFieldAssign(typeof(APSalesPrice.pendingPrice).Name, PXDbType.Decimal, 0),
                        new PXDataFieldAssign(typeof(APSalesPrice.effectiveDate).Name, PXDbType.DateTime, null),
                        new PXDataFieldAssign(typeof(APSalesPrice.pendingBreakQty).Name, PXDbType.Decimal, 0),
                        new PXDataFieldAssign(typeof(APSalesPrice.lastModifiedDateTime).Name, PXDbType.DateTime, updateTime),

                        new PXDataFieldRestrict(typeof(APSalesPrice.recordID).Name, PXDbType.Int, item.RecordID),
                        PXDataFieldRestrict.OperationSwitchAllowed
                        );

                    PXDatabase.Update <APSalesPrice>(
                        new PXDataFieldAssign(typeof(APSalesPrice.salesPrice).Name, PXDbType.Decimal, item.SalesPrice),
                        new PXDataFieldAssign(typeof(APSalesPrice.lastDate).Name, PXDbType.DateTime, item.LastDate),
                        new PXDataFieldAssign(typeof(APSalesPrice.lastModifiedDateTime).Name, PXDbType.DateTime, updateTime),

                        new PXDataFieldRestrict(typeof(APSalesPrice.inventoryID).Name, PXDbType.Int, item.InventoryID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.vendorID).Name, PXDbType.Int, item.VendorID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.vendorLocationID).Name, PXDbType.Int, item.VendorLocationID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.curyID).Name, PXDbType.NVarChar, item.CuryID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.uOM).Name, PXDbType.NVarChar, item.UOM),
                        new PXDataFieldRestrict(typeof(APSalesPrice.subItemID).Name, PXDbType.Int, item.SubItemID),
                        new PXDataFieldRestrict(typeof(APSalesPrice.breakQty).Name, PXDbType.Decimal, item.BreakQty),
                        new PXDataFieldRestrict(typeof(APSalesPrice.isPromotionalPrice).Name, PXDbType.Bit, false),
                        new PXDataFieldRestrict(typeof(APSalesPrice.recordID).Name, PXDbType.Int, 4, item.RecordID, PXComp.NE)
                        );

                    if (item.BreakQty == 0)
                    {
                        PXDatabase.Update <PO.POVendorInventory>(
                            new PXDataFieldAssign(typeof(PO.POVendorInventory.lastPrice).Name, PXDbType.Decimal, item.LastPrice),
                            new PXDataFieldAssign(typeof(PO.POVendorInventory.effPrice).Name, PXDbType.Decimal, item.SalesPrice),
                            new PXDataFieldAssign(typeof(PO.POVendorInventory.effDate).Name, PXDbType.DateTime, item.LastDate),
                            new PXDataFieldAssign(typeof(PO.POVendorInventory.pendingPrice).Name, PXDbType.Decimal, 0),
                            new PXDataFieldAssign(typeof(PO.POVendorInventory.pendingDate).Name, PXDbType.DateTime, null),
                            new PXDataFieldAssign(typeof(PO.POVendorInventory.lastModifiedDateTime).Name, PXDbType.DateTime, updateTime),

                            new PXDataFieldRestrict(typeof(PO.POVendorInventory.inventoryID).Name, PXDbType.Int, item.InventoryID),
                            new PXDataFieldRestrict(typeof(PO.POVendorInventory.vendorID).Name, PXDbType.Int, item.VendorID),
                            new PXDataFieldRestrict(typeof(PO.POVendorInventory.vendorLocationID).Name, PXDbType.Int, item.VendorLocationID),
                            new PXDataFieldRestrict(typeof(PO.POVendorInventory.curyID).Name, PXDbType.NVarChar, item.CuryID),
                            new PXDataFieldRestrict(typeof(PO.POVendorInventory.purchaseUnit).Name, PXDbType.NVarChar, item.UOM),
                            new PXDataFieldRestrict(typeof(PO.POVendorInventory.subItemID).Name, PXDbType.Int, item.SubItemID)
                            );
                    }


                    ts.Complete();
                }
            }
        }
예제 #12
0
        public virtual void UpdateDiscount(string discountID, string discountSequenceID, DateTime?filterDate)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    foreach (DiscountDetail detail in PXSelect <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                       And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        if (detail.StartDate != null && detail.StartDate.Value <= filterDate.Value)
                        {
                            PXDatabase.Update <DiscountDetail>(
                                new PXDataFieldAssign("LastAmount", PXDbType.DirectExpression, "Amount"),
                                new PXDataFieldAssign("LastAmountTo", PXDbType.DirectExpression, "AmountTo"),
                                new PXDataFieldAssign("LastQuantity", PXDbType.DirectExpression, "Quantity"),
                                new PXDataFieldAssign("LastQuantityTo", PXDbType.DirectExpression, "QuantityTo"),
                                new PXDataFieldAssign("LastDiscount", PXDbType.DirectExpression, "Discount"),
                                new PXDataFieldAssign("LastFreeItemQty", PXDbType.DirectExpression, "FreeItemQty"),
                                new PXDataFieldAssign("Amount", PXDbType.DirectExpression, "PendingAmount"),
                                new PXDataFieldAssign("Quantity", PXDbType.DirectExpression, "PendingQuantity"),
                                new PXDataFieldAssign("Discount", PXDbType.DirectExpression, "PendingDiscount"),
                                new PXDataFieldAssign("FreeItemQty", PXDbType.DirectExpression, "PendingFreeItemQty"),
                                new PXDataFieldAssign("LastDate", PXDbType.DirectExpression, "StartDate"),
                                new PXDataFieldAssign("PendingAmount", PXDbType.Decimal, null),
                                new PXDataFieldAssign("PendingQuantity", PXDbType.Decimal, 0m),
                                new PXDataFieldAssign("PendingDiscount", PXDbType.Decimal, null),
                                new PXDataFieldAssign("PendingFreeItemQty", PXDbType.Decimal, null),
                                new PXDataFieldAssign("StartDate", PXDbType.DateTime, null),
                                new PXDataFieldRestrict("DiscountDetailsID", PXDbType.Int, detail.DiscountDetailsID)
                                );
                        }
                    }
                    foreach (DiscountDetail detail in PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                               And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        DiscountDetail amonextval = PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                             And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> >, And <DiscountDetail.amount, Greater <Required <DiscountDetail.amount> > > > >,
                                                                      OrderBy <Asc <DiscountDetail.amount> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Amount);

                        DiscountDetail qtynextval = PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                             And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> >, And <DiscountDetail.quantity, Greater <Required <DiscountDetail.quantity> > > > >,
                                                                      OrderBy <Asc <DiscountDetail.quantity> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Quantity);

                        PXDatabase.Update <DiscountDetail>(
                            new PXDataFieldAssign("AmountTo", PXDbType.Decimal, (amonextval == null ? null : amonextval.Amount)),
                            new PXDataFieldAssign("QuantityTo", PXDbType.Decimal, (qtynextval == null ? null : qtynextval.Quantity)),
                            new PXDataFieldRestrict("DiscountDetailsID", PXDbType.Int, detail.DiscountDetailsID)
                            );
                    }

                    foreach (DiscountDetail detail in PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                               And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID))
                    {
                        DiscountDetail amonextval = PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                             And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> >, And <DiscountDetail.lastAmount, Greater <Required <DiscountDetail.lastAmount> > > > >,
                                                                      OrderBy <Asc <DiscountDetail.lastAmount> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Amount);

                        DiscountDetail qtynextval = PXSelectReadonly <DiscountDetail, Where <DiscountDetail.discountID, Equal <Required <DiscountDetail.discountID> >,
                                                                                             And <DiscountDetail.discountSequenceID, Equal <Required <DiscountDetail.discountSequenceID> >, And <DiscountDetail.lastQuantity, Greater <Required <DiscountDetail.lastQuantity> > > > >,
                                                                      OrderBy <Asc <DiscountDetail.lastQuantity> > > .SelectWindowed(this, 0, 1, discountID, discountSequenceID, detail.Quantity);

                        PXDatabase.Update <DiscountDetail>(
                            new PXDataFieldAssign("LastAmountTo", PXDbType.Decimal, (amonextval == null ? null : amonextval.LastAmount)),
                            new PXDataFieldAssign("LastQuantityTo", PXDbType.Decimal, (qtynextval == null ? null : qtynextval.LastQuantity)),
                            new PXDataFieldRestrict("DiscountDetailsID", PXDbType.Int, detail.DiscountDetailsID)
                            );
                    }

                    DiscountSequence sequence = PXSelect <DiscountSequence,
                                                          Where <DiscountSequence.discountID, Equal <Required <DiscountSequence.discountID> >,
                                                                 And <DiscountSequence.discountSequenceID, Equal <Required <DiscountSequence.discountSequenceID> > > > > .Select(this, discountID, discountSequenceID);

                    if (sequence != null && sequence.StartDate != null && sequence.StartDate.Value <= filterDate.Value && sequence.PendingFreeItemID != null)
                    {
                        PXDatabase.Update <DiscountSequence>(
                            new PXDataFieldAssign("LastFreeItemID", PXDbType.DirectExpression, "FreeItemID"),
                            new PXDataFieldAssign("FreeItemID", PXDbType.DirectExpression, "PendingFreeItemID"),
                            new PXDataFieldAssign("PendingFreeItemID", PXDbType.Int, null),
                            new PXDataFieldAssign("EndDate", PXDbType.DirectExpression, "StartDate"),
                            //new PXDataFieldAssign("StartDate", PXDbType.DateTime, null),
                            new PXDataFieldRestrict("DiscountID", PXDbType.VarChar, discountID),
                            new PXDataFieldRestrict("DiscountSequenceID", PXDbType.VarChar, discountSequenceID)
                            );
                    }

                    ts.Complete();
                }
            }
        }
예제 #13
0
        public virtual void UpdateSalesPrice(ARSalesPrice item)
        {
            using (PXConnectionScope cs = new PXConnectionScope())
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    DateTime updateTime = DateTime.Now;

                    //FOR UI:
                    item.LastPrice       = item.SalesPrice;
                    item.SalesPrice      = item.PendingPrice;
                    item.LastBreakQty    = item.BreakQty;
                    item.BreakQty        = item.PendingBreakQty;
                    item.LastDate        = item.EffectiveDate;
                    item.EffectiveDate   = null;
                    item.PendingPrice    = 0;
                    item.PendingBreakQty = 0;
                    item.LastTaxID       = item.TaxID;
                    item.TaxID           = item.PendingTaxID;
                    item.PendingTaxID    = null;


                    PXDatabase.Update <ARSalesPrice>(
                        new PXDataFieldAssign("LastPrice", PXDbType.Decimal, item.LastPrice),
                        new PXDataFieldAssign("LastTaxID", PXDbType.NVarChar, item.LastTaxID),
                        new PXDataFieldAssign("LastBreakQty", PXDbType.Decimal, item.LastBreakQty),
                        new PXDataFieldAssign("SalesPrice", PXDbType.Decimal, item.SalesPrice),
                        new PXDataFieldAssign("TaxID", PXDbType.NVarChar, item.TaxID),
                        new PXDataFieldAssign("BreakQty", PXDbType.Decimal, item.BreakQty),
                        new PXDataFieldAssign("LastDate", PXDbType.DateTime, item.LastDate),
                        new PXDataFieldAssign("PendingPrice", PXDbType.Decimal, 0m),
                        new PXDataFieldAssign("PendingTaxID", PXDbType.Decimal, null),
                        new PXDataFieldAssign("EffectiveDate", PXDbType.DateTime, null),
                        new PXDataFieldAssign("PendingBreakQty", PXDbType.Decimal, 0m),
                        new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),

                        new PXDataFieldRestrict("RecordID", PXDbType.Int, item.RecordID),
                        PXDataFieldRestrict.OperationSwitchAllowed
                        );

                    PXDatabase.Update <ARSalesPrice>(
                        new PXDataFieldAssign("SalesPrice", PXDbType.Decimal, item.SalesPrice),
                        new PXDataFieldAssign("LastDate", PXDbType.DateTime, item.LastDate),
                        new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),
                        new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID),
                        item.IsCustClassPrice == true
                                                                                ? new PXDataFieldRestrict("CustPriceClassID", PXDbType.NVarChar, item.CustPriceClassID)
                                                                                : new PXDataFieldRestrict("CustomerID", PXDbType.Int, item.CustomerID),
                        new PXDataFieldRestrict("CuryID", PXDbType.NVarChar, item.CuryID),
                        new PXDataFieldRestrict("UOM", PXDbType.NVarChar, item.UOM),
                        new PXDataFieldRestrict("IsPromotionalPrice", PXDbType.Bit, false),
                        new PXDataFieldRestrict("BreakQty", PXDbType.Decimal, item.BreakQty),
                        new PXDataFieldRestrict("RecordID", PXDbType.Int, 4, item.RecordID, PXComp.NE)
                        );

                    InventoryItem ii = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, item.InventoryID);

                    string uom = PXAccess.FeatureInstalled <FeaturesSet.distributionModule>() && sosetup.Current.SalesPriceUpdateUnit == SalesPriceUpdateUnitType.SalesUnit ? ii.SalesUnit : ii.BaseUnit;
                    if (item.UOM == uom && item.CuryID == Company.Current.BaseCuryID && item.CustPriceClassID == AR.ARPriceClass.EmptyPriceClass && item.BreakQty == 0 && item.PendingBreakQty == 0 && item.IsPromotionalPrice == false)
                    {
                        decimal price     = PXAccess.FeatureInstalled <FeaturesSet.distributionModule>() && sosetup.Current.SalesPriceUpdateUnit == SalesPriceUpdateUnitType.SalesUnit ? INUnitAttribute.ConvertFromBase(Inventory.Cache, ii.InventoryID, ii.SalesUnit, item.SalesPrice ?? 0m, INPrecision.UNITCOST) : item.SalesPrice ?? 0m;
                        decimal lastPrice = PXAccess.FeatureInstalled <FeaturesSet.distributionModule>() && sosetup.Current.SalesPriceUpdateUnit == SalesPriceUpdateUnitType.SalesUnit ? INUnitAttribute.ConvertFromBase(Inventory.Cache, ii.InventoryID, ii.SalesUnit, item.LastPrice ?? 0m, INPrecision.UNITCOST) : item.LastPrice ?? 0m;
                        PXDatabase.Update <InventoryItem>(
                            new PXDataFieldAssign("BasePrice", PXDbType.Decimal, price),
                            new PXDataFieldAssign("BasePriceDate", PXDbType.DateTime, item.LastDate),
                            new PXDataFieldAssign("PendingBasePrice", PXDbType.Decimal, 0m),
                            new PXDataFieldAssign("PendingBasePriceDate", PXDbType.DateTime, null),
                            new PXDataFieldAssign("LastBasePrice", PXDbType.Decimal, lastPrice),
                            new PXDataFieldAssign("LastModifiedDateTime", PXDbType.DateTime, updateTime),
                            new PXDataFieldRestrict("InventoryID", PXDbType.Int, item.InventoryID)
                            );
                    }


                    ts.Complete();
                }
            }
        }