示例#1
0
        private void ConfirmationOKButton_Click(object sender, EventArgs e)
        {
            if (!CanSetDirectorDiscount && Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current)["AgreementStatusID"]) == 2)
            {
                Infinium.LightMessageBox.Show(ref TopForm, false,
                                              "Заказ согласован, пересчет запрещен. Звоните Директорату",
                                              "Пересчет заказа");
                FormEvent            = eClose;
                AnimateTimer.Enabled = true;
                return;
            }

            if (CurrencyTextBox.Text == "0")
            {
                MessageBox.Show("Курс валюты равен нулю, проверьте курс");
                return;
            }

            //if (rbCpt.Checked && Convert.ToDecimal(TransportCostTextEdit.Text) == 0)
            //{
            //    MessageBox.Show("Введите сумму транспорта");
            //    return;
            //}

            if (Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current)["AgreementStatusID"]) != 2)
            {
                OrdersManager.SetNotConfirmOrder();
            }

            if (FixedPaymentRate)
            {
                //if (rbCurrentFixedPaymentRate.Checked)
                //    Rate = Convert.ToDecimal(tbCurrentFixedPaymentRate.Text);
                //if (rbNewFixedPaymentRate.Checked)
                //{
                //    Rate = Convert.ToDecimal(tbNewFixedPaymentRate.Text);
                //    OrdersManager.SaveClientPaymentRate(Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current)["ClientID"]), Rate);
                //}
                OrdersManager.SetFixedPaymentRate(Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["MegaOrderID"]), true);
            }
            else
            {
                OrdersManager.SetFixedPaymentRate(Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["MegaOrderID"]), false);
            }

            int CurrencyTypeID = CurrencyTypeComboBox.SelectedIndex + 1;

            if (CurrencyTypeComboBox.SelectedIndex == 3)
            {
                CurrencyTypeID = 5;
            }
            int DelayOfPayment             = 0;
            int DiscountFactoringID        = 0;
            int DiscountPaymentConditionID = 1;

            if (rbHalfOfPayment.Checked)
            {
                DiscountPaymentConditionID = 2;
                DelayOfPayment             = 0;
            }
            if (rbFullPayment.Checked)
            {
                DiscountPaymentConditionID = 3;
                DelayOfPayment             = 0;
            }
            if (rbFullPayment.Checked)
            {
                DiscountPaymentConditionID = 3;
                DelayOfPayment             = 0;
            }
            if (kryptonRadioButton3.Checked)
            {
                DiscountPaymentConditionID = 5;
                DelayOfPayment             = 0;
            }
            if (kryptonRadioButton5.Checked)
            {
                DiscountPaymentConditionID = 6;
                DelayOfPayment             = 0;
            }
            if (rbFactoring.Checked)
            {
                DiscountPaymentConditionID = 4;
            }

            if (DiscountPaymentConditionID == 1)
            {
                DelayOfPayment = Convert.ToInt32(tbDelayOfPayment.Text);
            }

            decimal ProfilTotalSum = 0;
            decimal TPSTotalSum    = 0;

            OrdersCalculate.GetMainOrderTotalSum(Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["MegaOrderID"]), ref ProfilTotalSum, ref TPSTotalSum);

            if (ProfilTotalSum < Convert.ToDecimal(tbComplaintProfilCost.Text) || TPSTotalSum < Convert.ToDecimal(tbComplaintTPSCost.Text))
            {
                Infinium.LightMessageBox.Show(ref TopForm, false,
                                              "Сумма рекламации не может быть больше стоимости заказа",
                                              "Расчет заказа");
                return;
            }

            decimal DiscountPaymentCondition = OrdersManager.DiscountPaymentCondition(DiscountPaymentConditionID);
            string  FactoringName            = string.Empty;

            if (DiscountPaymentConditionID == 4)
            {
                if (kryptonRadioButton2.Checked)
                {
                    FactoringName = kryptonRadioButton2.Text;
                }
                if (kryptonRadioButton4.Checked)
                {
                    FactoringName = kryptonRadioButton4.Text;
                }
                if (kryptonRadioButton1.Checked)
                {
                    FactoringName = kryptonRadioButton1.Text;
                }
                int DaysCount = 0;
                DiscountPaymentCondition = OrdersManager.DiscountFactoring(ref DiscountFactoringID, ref DaysCount, CurrencyTypeID, FactoringName);
                DelayOfPayment           = DaysCount;
            }
            decimal ProfilDiscountOrderSum = OrdersManager.DiscountOrderSum(ProfilTotalSum);
            decimal TPSDiscountOrderSum    = OrdersManager.DiscountOrderSum(TPSTotalSum);
            decimal ProfilDiscountDirector = Convert.ToDecimal(tbProfilDiscountDirector.Text);
            decimal TPSDiscountDirector    = Convert.ToDecimal(tbTPSDiscountDirector.Text);
            decimal ProfilTotalDiscount    = 0;
            decimal TPSTotalDiscount       = 0;
            decimal OriginalRate           = Rate;
            decimal PaymentRate            = Rate;
            int     TransportType          = 0;
            object  ConfirmDateTime        = ((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["ConfirmDateTime"];

            if (ClientID != 145 && DiscountPaymentConditionID == 1 && (CurrencyTypeID == 3 || CurrencyTypeID == 5))
            {
                PaymentRate = OriginalRate * 1.05m;
            }

            if (DiscountPaymentConditionID == 1 || DiscountPaymentConditionID == 6)
            {
                ProfilDiscountOrderSum = 0;
                TPSDiscountOrderSum    = 0;
            }
            decimal TransportCost = Convert.ToDecimal(TransportCostTextEdit.Text);

            if (rbFCA.Checked)
            {
                TransportType = 1;
                TransportCost = 0;
            }
            ProfilTotalDiscount = DiscountPaymentCondition + ProfilDiscountOrderSum + ProfilDiscountDirector;
            TPSTotalDiscount    = DiscountPaymentCondition + TPSDiscountOrderSum + TPSDiscountDirector;

            OrdersCalculate.Recalculate(Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["MegaOrderID"]),
                                        Convert.ToDecimal(tbComplaintProfilCost.Text), Convert.ToDecimal(tbComplaintTPSCost.Text),
                                        TransportType, TransportCost, Convert.ToDecimal(AdditionalCostTextEdit.Text),
                                        ProfilDiscountDirector, TPSDiscountDirector,
                                        (DiscountPaymentCondition + ProfilDiscountOrderSum), (DiscountPaymentCondition + TPSDiscountOrderSum), DiscountPaymentCondition,
                                        CurrencyTypeID, PaymentRate, ConfirmDateTime);

            CurrencyTotalCost = DBFReport.CalcCurrencyCost(
                Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["MegaOrderID"]),
                Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["ClientID"]), PaymentRate);
            OrdersManager.SetCurrencyCost(Convert.ToDecimal(tbComplaintProfilCost.Text), Convert.ToDecimal(tbComplaintTPSCost.Text), tbComplaintNotes.Text, IsComplaintCheckBox.Checked, DelayOfPayment,
                                          TransportCost, Convert.ToDecimal(AdditionalCostTextEdit.Text),
                                          CurrencyTypeID, OriginalRate, PaymentRate,
                                          DiscountPaymentConditionID, DiscountFactoringID, ProfilDiscountOrderSum, TPSDiscountOrderSum, ProfilDiscountDirector, TPSDiscountDirector, CurrencyTotalCost);

            //change date
            string DesireDate = "";

            if (NoDateCheckBox.Checked == false)
            {
                DesireDate = DispatchDateTimePicker.Value.Date.ToString("yyyy-MM-dd");
            }

            OrdersManager.LastCalcDate(Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["MegaOrderID"]));
            OrdersManager.ChangeDate(DesireDate);

            if (CanSetDirectorDiscount || Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current)["AgreementStatusID"]) != 0)
            {
                OrdersManager.MoveOrdersTo(Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current)["MegaOrderID"]),
                                           Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current)["AgreementStatusID"]));
            }

            OrdersManager.FixOrderEvent(Convert.ToInt32(((DataRowView)OrdersManager.MegaOrdersBindingSource.Current).Row["MegaOrderID"]), "Заказ рассчитан");
            OrdersManager.SendReport = true;

            FormEvent            = eClose;
            AnimateTimer.Enabled = true;
        }