Ejemplo n.º 1
0
 private void ShowTariff(object sender, EventArgs e)
 {
     if (lkpOrigin.Value != null)
     {
         if (lkpDestination.Value != null)
         {
             var ds = new TariffDataManager().GetTarif((int)lkpOrigin.Value, (int)lkpDestination.Value);
             tarifGrid.DataSource = ds;
             tarifView.RefreshData();
         }
     }
 }
Ejemplo n.º 2
0
        private void RefreshTariff()
        {
            if (_isPopulatingForm)
            {
                return;
            }

            if (CurrentModel == null)
            {
                return;
            }

            if (((ShipmentModel)CurrentModel).Posted || ((ShipmentModel)CurrentModel).Voided)
            {
                return;
            }

            tbxTariff.Value      = 0;
            tbxHandlingFee.Value = 0;
            cbxRa.Checked        = false;

            using (var dm = new DeliveryTariffDataManager())
            {
                DeliveryTariffModel dlvTariff = null;
                if (lkpPackage.Value != null)
                {
                    if (lkpDestination.Value != null)
                    {
                        dlvTariff = dm.GetByPackageTypeAndWeight((int)lkpPackage.Value, (int)lkpDestination.Value, tbxTtlGrossWeight.Value);
                    }
                }

                if (dlvTariff != null)
                {
                    ((ShipmentModel)CurrentModel).DeliveryFee = dlvTariff.Tariff;
                    DeliveryTariffMinimumWeight = dlvTariff.MinWeight;
                }
                else
                {
                    ((ShipmentModel)CurrentModel).DeliveryFee = 0;
                    DeliveryTariffMinimumWeight = 0;
                }
            }

            if (((ShipmentModel)CurrentModel).PricingPlanId != PRICING_PLAN_DOMESTIC)
            {
                using (var tariffInternationalDataManager = new TariffInternationalDataManager())
                {
                    var tariffIntModel = tariffInternationalDataManager.GetTariff(
                        ((ShipmentModel)CurrentModel).PricingPlanId ?? 0,
                        lkpPackage.Value ?? 0,
                        tbxTtlChargeable.Value
                        );

                    if (tariffIntModel != null)
                    {
                        tbxTariff.Value    = 0;
                        tbxTtlTariff.Value = tariffIntModel.Tariff;

                        tbxHandlingFee.Value = tariffIntModel.HandlingFee ?? 0;
                        ((ShipmentModel)CurrentModel).CurrencyId = tariffIntModel.CurrencyId;

                        using (var currencyDm = new CurrencyDataManager())
                        {
                            var currencyModel =
                                currencyDm.GetFirst <CurrencyModel>(WhereTerm.Default(tariffIntModel.CurrencyId, "id"));

                            if (currencyModel != null)
                            {
                                ((ShipmentModel)CurrentModel).Currency     = currencyModel.Name;
                                ((ShipmentModel)CurrentModel).CurrencyRate = currencyModel.Rate;
                            }
                        }

                        RefreshGrandTotal();
                        return;
                    }
                }
            }
            else
            {
                using (var currencyDm = new CurrencyDataManager())
                {
                    var currencyModel =
                        currencyDm.GetFirst <CurrencyModel>(WhereTerm.Default(CURRENCY_IDR, "code"));

                    if (currencyModel != null)
                    {
                        ((ShipmentModel)CurrentModel).CurrencyId   = currencyModel.Id;
                        ((ShipmentModel)CurrentModel).Currency     = currencyModel.Name;
                        ((ShipmentModel)CurrentModel).CurrencyRate = currencyModel.Rate;
                    }
                }
            }

            using (var customerTariffDataManager = new CustomerTariffDataManager())
            {
                if (lkpDestination.Value != null)
                {
                    var customerTariffModel = customerTariffDataManager.GetTariff(
                        BaseControl.CityId,
                        (int)lkpDestination.Value,
                        lkpService.Value ?? 0,
                        lkpPackage.Value ?? 0,
                        BaseControl.CorporateId,
                        tbxTtlChargeable.Value
                        );

                    if (customerTariffModel != null)
                    {
                        tbxTariff.Value      = customerTariffModel.Tariff;
                        tbxHandlingFee.Value = customerTariffModel.HandlingFee;

                        cbxRa.Checked = customerTariffModel.Ra ?? false;
                        MinWeight     = customerTariffModel.MinWeight;
                        if (MinWeight > 0 && tbxTtlGrossWeight.Value < MinWeight)
                        {
                            tbxTtlGrossWeight.Value = MinWeight;
                        }
                        RefreshGrandTotal();
                        return;
                    }
                }
            }

            using (var tariffDataManager = new TariffDataManager())
            {
                if (lkpDestination.Value != null)
                {
                    var tariffModel = tariffDataManager.GetTariff(
                        BaseControl.CityId,
                        (int)lkpDestination.Value,
                        lkpService.Value ?? 0,
                        lkpPackage.Value ?? 0,
                        tbxTtlChargeable.Value
                        );
                    if (tariffModel != null)
                    {
                        tbxTariff.Value      = tariffModel.Tariff;
                        tbxHandlingFee.Value = tariffModel.HandlingFee;

                        cbxRa.Checked = tariffModel.Ra ?? false;
                        MinWeight     = tariffModel.MinWeight;
                        if (MinWeight > 0 && tbxTtlGrossWeight.Value < MinWeight)
                        {
                            tbxTtlGrossWeight.Value = MinWeight;
                        }
                        RefreshGrandTotal();
                        return;
                    }
                }
            }

            tbxTariff.Text      = @"0";
            tbxHandlingFee.Text = @"0";

            MinWeight = 0;
            RefreshGrandTotal();
        }