Example #1
0
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            log.Info("doIt - M_InOut_ID=" + _M_InOut_ID + ", M_Shipper_ID=" + _M_Shipper_ID);
            if (_M_InOut_ID == 0)
            {
                throw new Exception("No Shipment");
            }
            if (_M_Shipper_ID == 0)
            {
                throw new Exception("No Shipper");
            }

            string sql            = "select M_Inout_ID from M_InoutConfirm where M_InoutConfirm_ID = " + _M_InOut_ID;
            int    _M_Shipment_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));

            MInOut shipment = new MInOut(GetCtx(), _M_Shipment_ID, null);

            if (shipment.Get_ID() != _M_Shipment_ID)
            {
                throw new Exception("Cannot find Shipment ID=" + _M_InOut_ID);
            }
            MShipper shipper = new MShipper(GetCtx(), _M_Shipper_ID, Get_TrxName());

            if (shipper.Get_ID() != _M_Shipper_ID)
            {
                throw new Exception("Cannot find Shipper ID=" + _M_InOut_ID);
            }

            MPackage pack = MPackage.Create(shipment, shipper, null);

            return(pack.GetDocumentNo());
        }
        private Boolean calculateFinalDiscount(CPrice p)
        {
            Boolean  matched    = false;
            MPackage pkg        = getPackage();
            String   pricingDef = pkg.DiscountDefinition;

            MIntervalConfig ivc = new MIntervalConfig(new CTable(""));

            ivc.DeserializeConfig(pricingDef);

            CPrice      o     = null;
            CBasketItem dummy = new CBasketItem("", null, p.Quantity, p.TotalAmount);

            if (ivc.SelectionType == 1)
            {
                //step
                o = getStepDiscount(ivc, dummy);
            }
            else
            {
                //Tier
                o = getTierDiscount(ivc, dummy);
            }

            if (o != null)
            {
                res.FinalDiscount = o.DiscountAmount;
                finalDiscount     = res.FinalDiscount;
                isFinalDiscount   = true;

                matched = true;
            }

            return(matched);
        }
Example #3
0
        private CBasketSet finalizeOutput(CBasketSet input, CBasket trackingBasket, CBasket used, CBasket free)
        {
            CBasketSet output = new CBasketSet();

            if ((used == null) && (free == null))
            {
                return(input);
            }

            //The original ones
            preserveOriginalGrouping(output, input);

            output.AddBasket(finalizeBasket(trackingBasket, BasketTypeEnum.Available));
            CBasket bundled = finalizeBasket(used, BasketTypeEnum.Bundled);

            output.AddBasket(bundled);

            int cnt = bundled.GetBasketItemCount();

            for (int i = 0; i < cnt; i++)
            {
                CBasketItem bi = bundled.GetBasketItem(i);
                bi.SetUnitPrice(0.00);
            }

            MPackage pkg = getPackage();

            bundled.SetAppliedPackage(getPackage());
            bundled.BundledAmount = triedCount * CUtil.StringToDouble(pkg.BundleAmount);

            return(output);
        }
        private CBasketSet finalizeOutput(CBasketSet input, Hashtable filterHash)
        {
            CBasketSet interim = new CBasketSet();
            MPackage   pkg     = getPackage();

            ArrayList types = input.GetBasketTypes();

            foreach (BasketTypeEnum bt in types)
            {
                ArrayList baskets = input.GetAllBasketByType(bt);

                foreach (CBasket bk in baskets)
                {
                    if (bt == BasketTypeEnum.Bundled)
                    {
                        if (isInBasketType(bt))
                        {
                            totalBundleAmt = totalBundleAmt + bk.BundledAmount;
                        }
                    }

                    CBasket nbk = new CBasket(bt);
                    nbk.CopyEntireFrom(bk);

                    if (isInBasketType(bk.BasketType))
                    {
                        updateBasketItem(nbk, filterHash);
                    }

                    interim.AddBasket(nbk);
                }
            }

            return(interim);
        }
        private void mnuContextMenu_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mnu  = (sender as MenuItem);
            string   name = mnu.Name;

            if (name.Equals("mnuEdit"))
            {
                showEditWindow();
            }
            else if (name.Equals("mnuCopy"))
            {
                CUtil.EnableForm(false, ParentControl);
                CTable newobj = OnixWebServiceAPI.CopyPackage(currentObj.GetDbObject());

                if (newobj != null)
                {
                    MPackage ivd = new MPackage(newobj);
                    ItemAddedEvent(ivd, e);
                }
                else
                {
                    //Error here
                    CHelper.ShowErorMessage(OnixWebServiceAPI.GetLastErrorDescription(), "ERROR_USER_ADD", null);
                }

                CUtil.EnableForm(true, ParentControl);
            }
        }
        private ArrayList sortBasketItem(CBasket trackingBasket, CPackageItemAdapter v)
        {
            int       cnt = trackingBasket.GetBasketItemCount();
            ArrayList arr = new ArrayList();

            for (int i = 0; i < cnt; i++)
            {
                CBasketItem bi = trackingBasket.GetBasketItem(i);
                arr.Add(bi);
            }

            MPackage pkg = getPackage();


            if (pkg.PackageType.Equals("5") || pkg.PackageType.Equals("10"))
            {
                //Bundle
                arr.Sort(new BasketItemComparatorHightestPriceFirst());
            }
            else if (v.QuantityType.Equals("1"))
            {
                //Used
                arr.Sort(new BasketItemComparatorLowestPriceFirst());
            }
            else
            {
                //2 - Free, cheapest come first
                arr.Sort(new BasketItemComparatorHightestPriceFirst());
            }

            return(arr);
        }
        private Hashtable getEligibleItemsHash(Hashtable accumHash)
        {
            Hashtable filterHash = new Hashtable();

            MPackage pkg = getPackage();

            if (pkg.IsProductSpecific == false)
            {
                //All item in the basket is eligible
                return(accumHash);
            }

            foreach (String key in accumHash.Keys)
            {
                CPrice p          = (CPrice)accumHash[key];
                bool   isEligible = isItemEligible(p, pkg, key);

                if (isEligible)
                {
                    filterHash.Add(key, p);
                }
            }

            //If all all item exist in pkg.PackageFinalDiscounts
            if (isAllExist(filterHash, pkg))
            {
                return(filterHash);
            }

            return(new Hashtable());
        }
        private double calculateRatio(CPrice p)
        {
            MPackage pkg        = getPackage();
            String   pricingDef = pkg.DiscountDefinition;

            MIntervalConfig ivc = new MIntervalConfig(new CTable(""));

            ivc.DeserializeConfig(pricingDef);

            CPrice      o     = null;
            CBasketItem dummy = new CBasketItem("", null, p.Quantity, p.TotalAmount);

            //Gui might not see correctly earlier
            pkg.DiscountMapType = "1";
            ivc.TierScopeType   = 0;

            if (ivc.SelectionType == 1)
            {
                //step
                o = getStepDiscount(ivc, dummy);
            }
            else
            {
                //Tier
                o = getTierDiscount(ivc, dummy);
            }

            if (o != null)
            {
                //Use DiscountAmount as a temp field
                return(o.DiscountAmount);
            }

            return(-9999);
        }
Example #9
0
        private static CPromotionProcessor getPromotionProcessor(MPackage pkg, MBaseModel bill)
        {
            String pkgType        = pkg.PackageType;
            CPromotionProcessor o = null;

            if (pkgType.Equals("1"))
            {
                o = new CPromotionProcessorPricing(pkg, CLanguage.getValue("pkg_group_pricing"), bill);
            }
            else if (pkgType.Equals("2"))
            {
                o = new CPromotionProcessorBonus(pkg, CLanguage.getValue("pkg_group_grouping"), bill);
            }
            else if (pkgType.Equals("3"))
            {
                o = new CPromotionProcessorItemDiscount(pkg, CLanguage.getValue("pkg_group_discount"), bill);
            }
            else if (pkgType.Equals("4"))
            {
                //Voucher/Gift
                o = new CPromotionProcessorGift(pkg, CLanguage.getValue("pkg_group_grouping"), bill);
            }
            else if (pkgType.Equals("5"))
            {
                //Bundle
                o = new CPromotionProcessorBundle(pkg, CLanguage.getValue("pkg_group_grouping"), bill);
            }
            else if (pkgType.Equals("6"))
            {
                //Final Discount
                o = new CPromotionProcessorFinalDiscount(pkg, CLanguage.getValue("pkg_group_final_discount"), bill);
            }
            else if (pkgType.Equals("7"))
            {
                //Post Gift
                o = new CPromotionProcessorPostGift(pkg, CLanguage.getValue("pkg_group_post_gift"), bill);
            }
            else if (pkgType.Equals("8"))
            {
                //Tray Price/Discount
                o = new CPromotionProcessorTrayPricing(pkg, CLanguage.getValue("tray_package_price"), bill);
            }
            else if (pkgType.Equals("9"))
            {
                //Tray Bonus
                o = new CPromotionProcessorTrayBonus(pkg, CLanguage.getValue("tray_package_group"), bill);
            }
            else if (pkgType.Equals("10"))
            {
                //Tray Bundle
                o = new CPromotionProcessorTrayBundle(pkg, CLanguage.getValue("tray_package_group"), bill);
            }

            return(o);
        }
Example #10
0
        private void loadAllPossibleUsedAndFree()
        {
            MPackage pkg = getPackage();

            pkg.InitPackageVoucherFilters();

            ObservableCollection <MPackageVoucher> useds = pkg.PackageVoucherBuy;

            //1 for Used, and 2 for Free
            populateHash(useds, 1);
        }
Example #11
0
        private void loadAllPossibleUsedAndFree()
        {
            MPackage pkg = getPackage();

            pkg.InitPackageBundles();

            ObservableCollection <MPackageBundle> useds = pkg.PackageBundles;

            //1 for Used, and 2 for Free
            populateHash(useds, 1);
        }
Example #12
0
        private void loadAllPossibleUsedAndFree()
        {
            MPackage pkg = getPackage();

            pkg.InitPackageBonusFilters();

            ObservableCollection <MPackageBonus> useds = pkg.PackageBonusBuy;
            ObservableCollection <MPackageBonus> frees = pkg.PackageBonusFree;

            //1 for Used, and 2 for Free
            populateHash(useds, 1);
            populateHash(frees, 2);
        }
        protected CPrice getTierDiscount(MIntervalConfig ivc, CBasketItem bi)
        {
            MPackage pkg = getPackage();

            double qty = 0.00;

            if (ivc.MappingType == 0)
            {
                //Map by quantity
                qty = bi.Quantity;
            }
            else
            {
                //Map by amount
                qty = bi.GetAmount();
            }

            foreach (MInterval iv in ivc.IntervalItems)
            {
                double from  = CUtil.StringToDouble(iv.FromValue);
                double to    = CUtil.StringToDouble(iv.ToValue);
                double value = CUtil.StringToDouble(iv.ConfigValue);

                if ((qty > from) && (qty <= to))
                {
                    CPrice p = new CPrice();

                    if (ivc.TierScopeType == 0)
                    {
                        //Fixed
                        p.DiscountAmount = value;
                    }
                    else if (ivc.TierScopeType == 1)
                    {
                        //Per unit
                        p.DiscountAmount = bi.Quantity * value;
                    }
                    else
                    {
                        //2 - Percent of amount
                        p.DiscountAmount = (value * bi.GetAmount()) / 100;
                    }

                    return(p);
                }
            }

            return(null);
        }
        public CPromotionProcessor(MBaseModel pkg, String grpName, MBaseModel bl)
        {
            procResults = new ArrayList();
            package     = (MPackage)pkg;
            bill        = bl;

            if (bl is MBillSimulate)
            {
                entity   = (MEntity)(bl as MBillSimulate).CustomerObj;
                billDate = (bl as MBillSimulate).DocumentDate;
                billTime = (bl as MBillSimulate).SimulateTime;
            }

            groupName = grpName;
        }
Example #15
0
 public static void UnloadPackage(MPackage pkg)
 {
     foreach (String pkgGrp in stdPackagesHash.Keys)
     {
         ArrayList arr = (ArrayList)stdPackagesHash[pkgGrp];
         foreach (MPackage p in arr)
         {
             if (p.PackageID.Equals(pkg.PackageID))
             {
                 arr.Remove(p);
                 return;
             }
         }
     }
 }
Example #16
0
        private void LoadData()
        {
            txtPackageCode.SetFocus();

            CTable t = new CTable("PACKAGE");

            vw = new MPackage(t);

            vw.PackageType = pg;
            DataContext    = vw;

            CUtil.EnableForm(false, this);

            if (Mode.Equals("E") || Mode.Equals("V"))
            {
                CTable m = OnixWebServiceAPI.GetPackageInfo(actualView.GetDbObject());
                if (m != null)
                {
                    vw.SetDbObject(m);
                }

                //cboDiscountMappingType.SelectedIndex = CUtil.StringToInt(vw.DiscountMapType);
            }
            else if (Mode.Equals("A"))
            {
                vw.EffectiveDate  = DateTime.Now;
                vw.ExpireDate     = DateTime.Now.Add(new TimeSpan(30, 0, 0, 0));
                vw.IsEnabled      = true;
                vw.IsTimeSpecific = false;
            }

            vw.InitPeriods();
            vw.InitItemsPrice();
            vw.InitPackageCustomers();
            vw.InitPackageDiscountFilters();
            vw.InitPackageBonusFilters();
            vw.InitPackageVoucherFilters();
            vw.InitPackageBundles();
            vw.InitPackageFinalDiscounts();
            vw.InitPackageBranches();
            vw.InitPackagePostFrees();
            vw.InitTrayPriceItem();

            vw.NotifyAllPropertiesChanged();

            vw.IsModified = false;
            CUtil.EnableForm(true, this);
        }
        private CBasketItem calculatePrice(CBasketItem bi)
        {
            MPackage pkg = getPackage();

            CBasketItem nbi = new CBasketItem(bi.Key, bi.Item, bi.Quantity);

            foreach (MPackagePrice pp in pkg.PackageItemPrices)
            {
                if (pp.EnabledFlag.Equals("N"))
                {
                    continue;
                }

                if (!isItemApplicable(pp, bi))
                {
                    continue;
                }

                MIntervalConfig ivc = new MIntervalConfig(new CTable(""));
                ivc.DeserializeConfig(pp.PricingDefination);

                CPrice o = null;
                if (ivc.SelectionType == 1)
                {
                    //step
                    o = getStepPrice(ivc, bi);
                }
                else
                {
                    //Tier
                    o = getTierPrice(ivc, bi);
                }

                if (o != null)
                {
                    nbi.SetAppliedPackage(pkg);
                    nbi.SetUnitPrice(o.UnitPrice);

                    return(nbi);
                }
            }

            return(null);
        }
Example #18
0
        private void mnuPackageView_Click(object sender, RoutedEventArgs e)
        {
            MPackage p = new MPackage(new CTable("PACKAGE"));

            p.CopyPackageInfo(currentViewObj);

            WinAddEditPackage c = new WinAddEditPackage(p.PackageGroup, "E");

            c.ViewData = p;
            c.Title    = CLanguage.getValue("edit") + " " + CUtil.PackageTypeToString(p.PackageType);
            c.ShowDialog();

            if (c.IsOK)
            {
                //Will be reloade later
                MPackage mp = new MPackage(p.GetDbObject());
                CPriceProcessor.UnloadPackage(mp);
            }
        }
Example #19
0
        private CBasketSet finalizeOutput(CBasketSet input, CBasket trackingBasket, CBasket used, CBasket free)
        {
            CBasketSet output = new CBasketSet();

            if ((used == null) && (free == null))
            {
                return(input);
            }

            //The original ones
            preserveOriginalGrouping(output, input);

            output.AddBasket(finalizeBasket(trackingBasket, BasketTypeEnum.Available));
            output.AddBasket(finalizeBasket(used, BasketTypeEnum.Used));

            if (triedCount > 0)
            {
                MPackage pkg = getPackage();
                ObservableCollection <MPackageVoucher> gifts = pkg.PackageVoucherFree;

                CBasket gbsk = new CBasket(BasketTypeEnum.FreeVoucher);

                foreach (MPackageVoucher g in gifts)
                {
                    if (g.EnabledFlag.Equals("N"))
                    {
                        continue;
                    }

                    MSelectedItem si = createSelectedItem(g);
                    CBasketItem   bi = new CBasketItem(si.Key, si, CUtil.StringToInt(g.Quantity) * triedCount);

                    gbsk.AddBasketItem(bi);
                }

                if (gbsk.GetBasketItemCount() > 0)
                {
                    output.AddBasket(gbsk);
                }
            }

            return(output);
        }
        private bool isAllExist(Hashtable hs, MPackage pkg)
        {
            ObservableCollection <MPackageFinalDiscount> arr = pkg.PackageFinalDiscounts;

            foreach (MPackageFinalDiscount pf in arr)
            {
                if (pf.EnabledFlag.Equals("N"))
                {
                    continue;
                }

                if (!hs.ContainsKey(pf.Key))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #21
0
        private CBasketItem calculateDiscount(CBasketItem bi)
        {
            MPackage      pkg = getPackage();
            MSelectedItem vi  = (MSelectedItem)bi.Item;

            CBasketItem nbi = new CBasketItem(bi.Key, bi.Item, bi.Quantity);

            nbi.SetUnitPrice(bi.GetUnitPrice());

            foreach (MPackageTrayPriceDiscount pp in pkg.PackageTrayByItems)
            {
                if (!isItemApplicable(pp, bi))
                {
                    continue;
                }

                MIntervalConfig ivc = new MIntervalConfig(new CTable(""));
                ivc.DeserializeConfig(pp.DiscountDefination);

                CPrice o = null;
                if (ivc.SelectionType == 1)
                {
                    //step
                    o = getStepDiscount(ivc, bi);
                }
                else
                {
                    //Tier
                    o = getTierDiscount(ivc, bi);
                }

                if (o != null)
                {
                    nbi.SetAppliedPackage(pkg);
                    nbi.SetDiscount(o.DiscountAmount);

                    return(nbi);
                }
            }

            return(null);
        }
        private Boolean isInBasketType(BasketTypeEnum bt)
        {
            MPackage          pkg = getPackage();
            MBasketTypeConfig cfg = new MBasketTypeConfig(new CTable(""));

            cfg.DeserializeConfig(pkg.DiscountBasketTypeConfig, pkg.BasketConfigType);

            foreach (MMasterRef vm in cfg.SelectedBaskets)
            {
                if (vm.EnabledFlag.Equals("Y"))
                {
                    if (bt.ToString().Equals(vm.Code))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private bool isAllExist(Hashtable hs, MPackage pkg)
        {
            //Different from Final Discount
            ObservableCollection <MPackageVoucher> arr = pkg.PackagePostGiftBuys;

            foreach (MPackageVoucher pf in arr)
            {
                if (pf.EnabledFlag.Equals("N"))
                {
                    continue;
                }

                if (!hs.ContainsKey(pf.Key))
                {
                    return(false);
                }
            }

            return(true);
        }
        public override Tuple <CTable, ObservableCollection <MBaseModel> > QueryData()
        {
            (model as MPackage).PackageGroup = groupID;
            items = OnixWebServiceAPI.GetPackageList(model.GetDbObject());
            lastObjectReturned = OnixWebServiceAPI.GetLastObjectReturned();

            itemSources.Clear();
            int idx = 0;

            foreach (CTable o in items)
            {
                MPackage v = new MPackage(o);

                v.RowIndex = idx;
                itemSources.Add(v);
                idx++;
            }

            Tuple <CTable, ObservableCollection <MBaseModel> > tuple = new Tuple <CTable, ObservableCollection <MBaseModel> >(lastObjectReturned, itemSources);

            return(tuple);
        }
Example #25
0
        private Boolean ValidateData()
        {
            Boolean result = false;

            result = CHelper.ValidateTextBox(lblPackageCode, txtPackageCode, false);
            if (!result)
            {
                return(result);
            }

            result = CHelper.ValidateTextBox(lblPackageName, txtPackageName, true);
            if (!result)
            {
                return(result);
            }

            result = validateItems();
            if (!result)
            {
                return(result);
            }

            CTable   ug = new CTable("PACKAGE");
            MPackage uv = new MPackage(ug);

            uv.PackageCode = vw.PackageCode;
            uv.PackageID   = vw.PackageID;

            CUtil.EnableForm(false, this);
            if (OnixWebServiceAPI.IsPackageExist(uv.GetDbObject()))
            {
                CUtil.EnableForm(true, this);
                CHelper.ShowKeyExist(lblPackageCode, txtPackageCode);
                return(false);
            }

            CUtil.EnableForm(true, this);
            return(result);
        }
Example #26
0
        private static void putNewPackages(ArrayList packages)
        {
            foreach (CTable o in packages)
            {
                MPackage  p   = new MPackage(o);
                ArrayList arr = (ArrayList)stdPackagesHash[p.PackageGroup];

                //arr should not null here
                p.InitPeriods();
                p.InitItemsPrice();
                p.InitPackageCustomers();
                p.InitPackageDiscountFilters();
                p.InitPackageBonusFilters();
                p.InitPackageVoucherFilters();
                p.InitPackageBundles();
                p.InitPackageFinalDiscounts();
                p.InitPackageBranches();
                p.InitPackagePostFrees();
                p.InitTrayPriceItem();

                arr.Add(p);
            }
        }
        private bool isItemEligible(CPrice item, MPackage pkg, String key)
        {
            ObservableCollection <MPackageFinalDiscount> arr = pkg.PackageFinalDiscounts;

            foreach (MPackageFinalDiscount pf in arr)
            {
                if (pf.EnabledFlag.Equals("N"))
                {
                    continue;
                }

                if (key.Equals(pf.Key))
                {
                    double minimumQty = CUtil.StringToDouble(pf.Quantity);
                    if (item.Quantity >= minimumQty)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
 public bool SetProductQty(int recordID, string keyColName, List <string> product, List <string> attribute, List <string> qty, List <string> qtybook, List <string> oline_ID, int ordID, List <string> locID, int lineID, VAdvantage.Utility.Ctx ctx)
 {
     if (keyColName.ToUpper().Trim() == "C_ORDER_ID")
     {
         MOrder ord = new MOrder(ctx, recordID, null);
         for (int i = 0; i < product.Count; i++)
         {
             MOrderLine oline = new MOrderLine(ctx, lineID, null);
             oline.SetAD_Client_ID(ord.GetAD_Client_ID());
             oline.SetAD_Org_ID(ord.GetAD_Org_ID());
             oline.SetM_Product_ID(Util.GetValueOfInt(product[i]));
             oline.SetQty(Util.GetValueOfDecimal(qty[i]));
             oline.SetC_Order_ID(recordID);
             if (Util.GetValueOfInt(attribute[i]) != 0)
             {
                 oline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i]));
             }
             if (!ord.IsSOTrx())
             {
                 MProduct pro    = new MProduct(ctx, oline.GetM_Product_ID(), null);
                 String   qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + oline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + ord.GetC_BPartner_ID();
                 int      uom    = Util.GetValueOfInt(DB.ExecuteScalar(qryUom));
                 if (pro.GetC_UOM_ID() != 0)
                 {
                     if (pro.GetC_UOM_ID() != uom && uom != 0)
                     {
                         decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + oline.GetM_Product_ID() + " AND IsActive='Y'"));
                         if (Res > 0)
                         {
                             oline.SetQtyEntered(oline.GetQtyEntered() * Res);
                             //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty);
                         }
                         else
                         {
                             decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'"));
                             if (res > 0)
                             {
                                 oline.SetQtyEntered(oline.GetQtyEntered() * res);
                                 //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty);
                             }
                         }
                         oline.SetC_UOM_ID(uom);
                     }
                     else
                     {
                         oline.SetC_UOM_ID(pro.GetC_UOM_ID());
                     }
                 }
             }
             if (!oline.Save())
             {
             }
         }
     }
     else if (keyColName.ToUpper().Trim() == "C_INVOICE_ID")
     {
         MInvoice inv = new MInvoice(ctx, recordID, null);
         for (int i = 0; i < product.Count; i++)
         {
             MInvoiceLine invline = new MInvoiceLine(ctx, lineID, null);
             invline.SetAD_Client_ID(inv.GetAD_Client_ID());
             invline.SetAD_Org_ID(inv.GetAD_Org_ID());
             invline.SetM_Product_ID(Util.GetValueOfInt(product[i]));
             invline.SetQty(Util.GetValueOfDecimal(qty[i]));
             invline.SetC_Invoice_ID(recordID);
             if (Util.GetValueOfInt(attribute[i]) != 0)
             {
                 invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i]));
             }
             if (!inv.IsSOTrx())
             {
                 MProduct pro    = new MProduct(ctx, invline.GetM_Product_ID(), null);
                 String   qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + invline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inv.GetC_BPartner_ID();
                 int      uom    = Util.GetValueOfInt(DB.ExecuteScalar(qryUom));
                 if (pro.GetC_UOM_ID() != 0)
                 {
                     if (pro.GetC_UOM_ID() != uom && uom != 0)
                     {
                         decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + invline.GetM_Product_ID() + " AND IsActive='Y'"));
                         if (Res > 0)
                         {
                             invline.SetQtyEntered(invline.GetQtyEntered() * Res);
                             //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty);
                         }
                         else
                         {
                             decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'"));
                             if (res > 0)
                             {
                                 invline.SetQtyEntered(invline.GetQtyEntered() * res);
                                 //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty);
                             }
                         }
                         invline.SetC_UOM_ID(uom);
                     }
                     else
                     {
                         invline.SetC_UOM_ID(pro.GetC_UOM_ID());
                     }
                 }
             }
             if (!invline.Save())
             {
             }
         }
     }
     else if (keyColName.ToUpper().Trim() == "M_INOUT_ID")
     {
         MInOut inv = new MInOut(ctx, recordID, null);
         if (ordID > 0)
         {
             inv.SetC_Order_ID(ordID);
         }
         if (inv.Save())
         {
             for (int i = 0; i < product.Count; i++)
             {
                 MInOutLine ioline = new MInOutLine(ctx, lineID, null);
                 ioline.SetAD_Client_ID(inv.GetAD_Client_ID());
                 ioline.SetAD_Org_ID(inv.GetAD_Org_ID());
                 ioline.SetM_Product_ID(Util.GetValueOfInt(product[i]));
                 ioline.SetQty(Util.GetValueOfDecimal(qty[i]));
                 ioline.SetM_InOut_ID(recordID);
                 ioline.SetC_OrderLine_ID(Util.GetValueOfInt(oline_ID[i]));
                 ioline.SetM_Locator_ID(Util.GetValueOfInt(locID[i]));
                 if (Util.GetValueOfInt(attribute[i]) != 0)
                 {
                     ioline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i]));
                 }
                 if (!inv.IsSOTrx())
                 {
                     MProduct pro    = new MProduct(ctx, ioline.GetM_Product_ID(), null);
                     String   qryUom = "SELECT vdr.C_UOM_ID FROM M_Product p LEFT JOIN M_Product_Po vdr ON p.M_Product_ID= vdr.M_Product_ID WHERE p.M_Product_ID=" + ioline.GetM_Product_ID() + " AND vdr.C_BPartner_ID = " + inv.GetC_BPartner_ID();
                     int      uom    = Util.GetValueOfInt(DB.ExecuteScalar(qryUom));
                     if (pro.GetC_UOM_ID() != 0)
                     {
                         if (pro.GetC_UOM_ID() != uom && uom != 0)
                         {
                             decimal?Res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND M_Product_ID= " + ioline.GetM_Product_ID() + " AND IsActive='Y'"));
                             if (Res > 0)
                             {
                                 ioline.SetQtyEntered(ioline.GetQtyEntered() * Res);
                                 //OrdQty = MUOMConversion.ConvertProductTo(GetCtx(), _M_Product_ID, UOM, OrdQty);
                             }
                             else
                             {
                                 decimal?res = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT trunc(multiplyrate,4) FROM C_UOM_Conversion WHERE C_UOM_ID = " + pro.GetC_UOM_ID() + " AND C_UOM_To_ID = " + uom + " AND IsActive='Y'"));
                                 if (res > 0)
                                 {
                                     ioline.SetQtyEntered(ioline.GetQtyEntered() * res);
                                     //OrdQty = MUOMConversion.Convert(GetCtx(), prdUOM, UOM, OrdQty);
                                 }
                             }
                             ioline.SetC_UOM_ID(uom);
                         }
                         else
                         {
                             ioline.SetC_UOM_ID(pro.GetC_UOM_ID());
                         }
                     }
                 }
                 if (!ioline.Save())
                 {
                 }
             }
         }
     }
     else if (keyColName.ToUpper().Trim() == "M_PACKAGE_ID")
     {
         MPackage pkg = new MPackage(ctx, recordID, null);
         for (int i = 0; i < product.Count; i++)
         {
             MPackageLine mline = new MPackageLine(ctx, lineID, null);
             mline.SetAD_Client_ID(pkg.GetAD_Client_ID());
             mline.SetAD_Org_ID(pkg.GetAD_Org_ID());
             mline.SetM_Product_ID(Util.GetValueOfInt(product[i]));
             mline.SetQty(Util.GetValueOfDecimal(qty[i]));
             if (Util.GetValueOfInt(oline_ID[i]) > 0)
             {
                 mline.SetM_MovementLine_ID(Util.GetValueOfInt(oline_ID[i]));
                 MMovementLine mov = new MMovementLine(ctx, Util.GetValueOfInt(oline_ID[i]), null);
                 mline.SetDTD001_TotalQty(mov.GetMovementQty());
             }
             if (Util.GetValueOfInt(attribute[i]) != 0)
             {
                 mline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i]));
             }
             mline.SetM_Package_ID(recordID);
             if (!mline.Save())
             {
             }
         }
     }
     else if (keyColName.ToUpper().Trim() == "M_INVENTORY_ID")
     {
         MInventory inv = new MInventory(ctx, recordID, null);
         for (int i = 0; i < product.Count; i++)
         {
             MInventoryLine invline = new MInventoryLine(ctx, lineID, null);
             invline.SetAD_Client_ID(inv.GetAD_Client_ID());
             invline.SetAD_Org_ID(inv.GetAD_Org_ID());
             invline.SetM_Locator_ID(Util.GetValueOfInt(locID[i]));
             invline.SetM_Product_ID(Util.GetValueOfInt(product[i]));
             invline.SetQtyCount(Util.GetValueOfDecimal(qty[i]));
             invline.SetQtyBook(Util.GetValueOfDecimal(qtybook[i]));
             invline.SetAsOnDateCount(Util.GetValueOfDecimal(qty[i]));
             invline.SetOpeningStock(Util.GetValueOfDecimal(qtybook[i]));
             invline.SetM_Inventory_ID(recordID);
             if (Util.GetValueOfInt(attribute[i]) != 0)
             {
                 invline.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(attribute[i]));
             }
             else
             {
                 invline.SetM_AttributeSetInstance_ID(0);
             }
             if (!invline.Save())
             {
             }
         }
     }
     return(true);
 }
Example #29
0
        public static void CreateDisplayView(CBasketSet basketSet, MBillSimulate bsim, ItemDisplayUpdate callback)
        {
            ArrayList sorted = new ArrayList();

            bsim.ResultItemsCTable.Clear();

            bsim.ClearPromotionItem("BILL_RESULT_ITEM");
            bsim.ClearPromotionItem("BILL_FREE_ITEM");
            bsim.ClearPromotionItem("BILL_VOUCHER_ITEM");
            bsim.ClearPromotionItem("BILL_POSTGIFT_ITEM");

            double total = 0.00;

            ArrayList bts = basketSet.GetBasketTypes();

            foreach (BasketTypeEnum bt in bts)
            {
                ArrayList arr = basketSet.GetAllBasketByType(bt);
                int       grp = 1;

                foreach (CBasket bk in arr)
                {
                    MPackage pkg = bk.GetAppliedPackage();

                    int cnt = bk.GetBasketItemCount();
                    int seq = 0;
                    for (int j = 0; j < cnt; j++)
                    {
                        CBasketItem bi = bk.GetBasketItem(j);

                        if (bi.Quantity > 0)
                        {
                            CBasketItemDisplay bid = new CBasketItemDisplay(bi, bt, grp, seq, bk);

                            seq++;

                            bid.SetPromotion(pkg);
                            if (bt.ToString().Contains("Tray"))
                            {
                                bid.IsTray = true;
                            }

                            if ((bt == BasketTypeEnum.FreeAnnonymous) || (bt == BasketTypeEnum.FreeAnnonymousTray))
                            {
                                //bsim.FreeItems.Add(bid);
                                bsim.AddPromotionItem(bid, "BILL_FREE_ITEM");
                            }
                            else if (bt == BasketTypeEnum.FreeVoucher)
                            {
                                //bsim.VoucherItems.Add(bid);
                                bsim.AddPromotionItem(bid, "BILL_VOUCHER_ITEM");
                            }
                            else if (bt == BasketTypeEnum.PostFree)
                            {
                                //bsim.PostGiftItems.Add(bid);
                                bsim.AddPromotionItem(bid, "BILL_POSTGIFT_ITEM");
                            }
                            else
                            {
                                sorted.Add(bid);
                            }
                        }
                    }
                    grp++;
                }
            }

            sorted.Sort(new SelectedItemComparator());
            total = populateResultItems(bsim, "BILL_RESULT_ITEM", sorted, callback);

            bsim.TotalAmount    = total.ToString();
            bsim.DiscountAmount = totalFinalDiscount.ToString();
            bsim.NetAmount      = (total - totalFinalDiscount).ToString();
        }
Example #30
0
        private static void loadPackagesByGroup(MCompanyPackage companyPackage)
        {
            ArrayList temp = new ArrayList();
            String    set  = "";
            int       cnt  = 0;

            for (int i = 1; i <= 7; i++)
            {
                ArrayList arr = (ArrayList)stdPackagesHash[i.ToString()];
                if (arr == null)
                {
                    arr = new ArrayList();
                    stdPackagesHash[i.ToString()] = arr;
                }

                ObservableCollection <MCompanyPackage> packages = companyPackage.GroupingPackage;
                if (i == 1)
                {
                    packages = companyPackage.GroupingPackage;
                }
                else if (i == 2)
                {
                    packages = companyPackage.PricingPackage;
                }
                else if (i == 3)
                {
                    packages = companyPackage.DiscountPackage;
                }
                else if (i == 4)
                {
                    packages = companyPackage.FinalDiscountPackage;
                }
                else if (i == 5)
                {
                    packages = companyPackage.PostGiftPackage;
                }
                else if (i == 6)
                {
                    packages = companyPackage.TrayPricePackage;
                }
                else if (i == 7)
                {
                    packages = companyPackage.TrayPackageGroup;
                }

                foreach (MCompanyPackage cp in packages)
                {
                    MPackage pkg = new MPackage(new CTable(""));
                    pkg.PackageID = cp.PackageID;

                    if (!hasLoaded(pkg.PackageID, arr))
                    {
                        if (cnt <= 0)
                        {
                            set = pkg.PackageID;
                        }
                        else
                        {
                            set = set + "," + pkg.PackageID;
                        }

                        cnt++;
                    }
                }
            }

            if (cnt > 0)
            {
                String incSet = String.Format("({0})", set);
                CTable o      = new CTable("");
                o.SetFieldValue("PACKAGE_ID_SET", incSet);
                //ArrayList pkgs = COnixWrapper.GetCompanyPackageAll(o);
                ArrayList pkgs = getCompanyPackageCallback(o);

                putNewPackages(pkgs);
            }
        }